nxbe_setvisibility.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /****************************************************************************
  2. * graphics/nxbe/nxbe_setvisibility.c
  3. *
  4. * Copyright (C) 2019 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. /****************************************************************************
  36. * Included Files
  37. ****************************************************************************/
  38. #include <nuttx/config.h>
  39. #include <assert.h>
  40. #include <nuttx/nx/nxglib.h>
  41. #include "nxbe.h"
  42. #include "nxmu.h"
  43. /****************************************************************************
  44. * Public Functions
  45. ****************************************************************************/
  46. /****************************************************************************
  47. * Name: nxbe_show_window
  48. *
  49. * Description:
  50. * Make a hidden window visible.
  51. *
  52. * Input Parameters:
  53. * wnd - The window to be shown
  54. *
  55. * Returned Value:
  56. * None
  57. *
  58. ****************************************************************************/
  59. void nxbe_show_window(FAR struct nxbe_window_s *wnd)
  60. {
  61. FAR struct nxbe_state_s *be = wnd->be;
  62. /* Mark the window no longer hidden */
  63. NXBE_CLRHIDDEN(wnd);
  64. /* Restore the window to the top of the hierarchy. Exception: If the top
  65. * window is a modal window, then only raise it to second highest.
  66. */
  67. if (NXBE_STATE_ISMODAL(be) && be->topwnd->below != NULL)
  68. {
  69. /* We are in a modal state. The topwnd is not the background and it
  70. * has focus.
  71. */
  72. wnd->above = be->topwnd;
  73. wnd->below = be->topwnd->below;
  74. be->topwnd->below = wnd;
  75. /* Redraw this window and the other that are below us */
  76. nxbe_redrawbelow(be, wnd, &wnd->bounds);
  77. }
  78. else
  79. {
  80. /* Otherwise re-insert the window at the top on the display. */
  81. wnd->above = NULL;
  82. wnd->below = be->topwnd;
  83. be->topwnd->above = wnd;
  84. be->topwnd = wnd;
  85. /* This window is now at the top of the display, we know, therefore,
  86. * that it is not obscured by another window. Just redraw it.
  87. */
  88. nxmu_redraw(wnd, &wnd->bounds);
  89. }
  90. }
  91. /****************************************************************************
  92. * Name: nxbe_hide_window
  93. *
  94. * Description:
  95. * Hide a visible window.
  96. *
  97. * Input Parameters:
  98. * wnd - The window to be modified
  99. * hide - True: Window will be hidden; false: Window will be visible
  100. *
  101. * Returned Value:
  102. * None
  103. *
  104. ****************************************************************************/
  105. void nxbe_hide_window(FAR struct nxbe_window_s *wnd)
  106. {
  107. FAR struct nxbe_state_s *be = wnd->be;
  108. /* The background window should never be hidden */
  109. DEBUGASSERT(wnd != &be->bkgd);
  110. /* Remove this window from the hiearachy */
  111. /* Is there a window above the one being hidden? */
  112. if (wnd->above != NULL)
  113. {
  114. /* Yes, now the window below that one is the window below
  115. * the one being hidden.
  116. */
  117. wnd->above->below = wnd->below;
  118. }
  119. else
  120. {
  121. /* No, then the top window is the one below this (which
  122. * can never be NULL because the background window is
  123. * always at the true bottom of the list
  124. */
  125. be->topwnd = wnd->below;
  126. }
  127. /* There is always a window below the one being closed (because
  128. * the background is never closed. Now, the window above that
  129. * is the window above the one that is being closed.
  130. */
  131. wnd->below->above = wnd->above;
  132. /* Redraw the windows that were below us (and may now be exposed) */
  133. nxbe_redrawbelow(be, wnd->below, &wnd->bounds);
  134. /* And mark the window as hidden */
  135. NXBE_SETHIDDEN(wnd);
  136. }
  137. /****************************************************************************
  138. * Public Functions
  139. ****************************************************************************/
  140. /****************************************************************************
  141. * Name: nxbe_setvisibility
  142. *
  143. * Description:
  144. * Select if the window is visible or hidden. A hidden window is still
  145. * present will will update normally, but will be on the visiable on the
  146. * display until it is unhidden.
  147. *
  148. * Input Parameters:
  149. * wnd - The window to be modified
  150. * hide - True: Window will be hidden; false: Window will be visible
  151. *
  152. * Returned Value:
  153. * None
  154. *
  155. ****************************************************************************/
  156. void nxbe_setvisibility(FAR struct nxbe_window_s *wnd, bool hide)
  157. {
  158. /* Are we showing the window? Or hiding it? */
  159. if (hide && !NXBE_ISHIDDEN(wnd))
  160. {
  161. nxbe_hide_window(wnd);
  162. }
  163. else if (!hide && NXBE_ISHIDDEN(wnd))
  164. {
  165. nxbe_show_window(wnd);
  166. }
  167. }