cwindowfactory.hxx 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /////////////////////////////////////////////////////////////////////////////
  2. // apps/include/graphics/twm4nx/cwindowfactory.hxx
  3. //
  4. // Licensed to the Apache Software Foundation (ASF) under one or more
  5. // contributor license agreements. See the NOTICE file distributed with
  6. // this work for additional information regarding copyright ownership. The
  7. // ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. // "License"); you may not use this file except in compliance with the
  9. // License. You may obtain a copy of the License at
  10. //
  11. // http://www.apache.org/licenses/LICENSE-2.0
  12. //
  13. // Unless required by applicable law or agreed to in writing, software
  14. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. // License for the specific language governing permissions and limitations
  17. // under the License.
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. // Largely an original work but derives from TWM 1.0.10 in many ways:
  21. //
  22. // Copyright 1989,1998 The Open Group
  23. // Copyright 1988 by Evans & Sutherland Computer Corporation,
  24. //
  25. // Please refer to apps/twm4nx/COPYING for detailed copyright information.
  26. // Although not listed as a copyright holder, thanks and recognition need
  27. // to go to Tom LaStrange, the original author of TWM.
  28. #ifndef __APPS_INCLUDE_GRAPHICS_TWM4NX_CWINDOWFACTORY_HXX
  29. #define __APPS_INCLUDE_GRAPHICS_TWM4NX_CWINDOWFACTORY_HXX
  30. /////////////////////////////////////////////////////////////////////////////
  31. // Included Files
  32. /////////////////////////////////////////////////////////////////////////////
  33. #include <cstdbool>
  34. #include "graphics/twm4nx/cwindow.hxx"
  35. #include "graphics/twm4nx/ctwm4nxevent.hxx"
  36. #include "graphics/twm4nx/iapplication.hxx"
  37. /////////////////////////////////////////////////////////////////////////////
  38. // Implementation Classes
  39. /////////////////////////////////////////////////////////////////////////////
  40. namespace NXWidgets
  41. {
  42. struct SRlePaletteBitmap; // Forward reference
  43. }
  44. namespace Twm4Nx
  45. {
  46. class CWindow; // Forward reference
  47. class CIconMgr; // Forward reference
  48. struct SWindowEntry; // Forward reference
  49. // For each window that is on the display, one of these structures
  50. // is allocated and linked into a list. It is essentially just a
  51. // container for a window.
  52. struct SWindow
  53. {
  54. FAR struct SWindow *flink; /**< Forward link tonext window */
  55. FAR struct SWindow *blink; /**< Backward link to previous window */
  56. FAR struct SWindowEntry *wentry; /**< Icon manager list entry (for list removal) */
  57. FAR CWindow *cwin; /**< Window object payload */
  58. };
  59. /**
  60. * This class is a simple implement of the interface to the Main Menu that
  61. * provides the Desktop Main Menu entry.
  62. */
  63. class CDesktopItem : public IApplication
  64. {
  65. public:
  66. /**
  67. * Return the Main Menu item string. This overrides the method from
  68. * IApplication
  69. *
  70. * @param name The name of the application.
  71. */
  72. inline NXWidgets::CNxString getName(void)
  73. {
  74. return NXWidgets::CNxString("Desktop");
  75. }
  76. /**
  77. * There is no sub-menu for this Main Menu item. This overrides
  78. * the method from IApplication.
  79. *
  80. * @return This implementation will always return a null value.
  81. */
  82. inline FAR CMenus *getSubMenu(void)
  83. {
  84. return (FAR CMenus *)0;
  85. }
  86. /**
  87. * There is no custom event handler. We use the common event handler.
  88. *
  89. * @return. null is always returned in this implementation.
  90. */
  91. inline FAR CTwm4NxEvent *getEventHandler(void)
  92. {
  93. return (FAR CTwm4NxEvent *)0;
  94. }
  95. /**
  96. * Return the Twm4Nx event that will be generated when the Main Menu
  97. * item is selected.
  98. *
  99. * @return. This function always returns EVENT_WINDOW_DESKTOP.
  100. */
  101. inline uint16_t getEvent(void)
  102. {
  103. return EVENT_WINDOW_DESKTOP;
  104. }
  105. };
  106. /**
  107. * The CWindowFactory class creates new window instances and manages some
  108. * things that are common to all windows.
  109. */
  110. class CWindowFactory: public CTwm4NxEvent
  111. {
  112. private:
  113. CTwm4Nx *m_twm4nx; /**< Cached Twm4Nx session */
  114. struct nxgl_point_s m_winpos; /**< Position of next window created */
  115. FAR struct SWindow *m_windowHead; /**< List of windows on the display */
  116. CDesktopItem m_desktopItem; /**< For the "Desktop" Main Menu item */
  117. /**
  118. * Add a window container to the window list.
  119. *
  120. * @param win. The window container to be added to the list.
  121. */
  122. void addWindowContainer(FAR struct SWindow *win);
  123. /**
  124. * Remove a window container from the window list.
  125. *
  126. * @param win. The window container to be removed from the list.
  127. */
  128. void removeWindowContainer(FAR struct SWindow *win);
  129. /**
  130. * Find the window container that contains the specified window.
  131. *
  132. * @param cwin. The window whose container is needed.
  133. * @return On success, the container of the specific window is returned;
  134. * NULL is returned on failure.
  135. */
  136. FAR struct SWindow *findWindow(FAR CWindow *cwin);
  137. /**
  138. * This is the function that responds to the EVENT_WINDOW_DESKTOP. It
  139. * iconifies all windows so that the desktop is visible.
  140. *
  141. * @return True is returned if the operation was successful.
  142. */
  143. bool showDesktop(void);
  144. public:
  145. /**
  146. * CWindowFactory Constructor
  147. *
  148. * @param twm4nx. Twm4Nx session
  149. */
  150. CWindowFactory(CTwm4Nx *twm4nx);
  151. /**
  152. * CWindowFactory Destructor
  153. */
  154. ~CWindowFactory(void);
  155. /**
  156. * Add Icon Manager menu items to the Main menu. This is really part
  157. * of the instance initialization, but cannot be executed until the
  158. * Main Menu logic is ready.
  159. *
  160. * @return True on success
  161. */
  162. bool addMenuItems(void);
  163. /**
  164. * Create a new window and add it to the window list.
  165. *
  166. * The window is initialized with all application events disabled.
  167. * The CWindows::configureEvents() method may be called as a second
  168. * initialization step in order to enable application events.
  169. *
  170. * @param name The window name
  171. * @param sbitmap The Icon bitmap
  172. * @param iconMgr Pointer to icon manager instance
  173. * @param flags Toolbar customizations see WFLAGS_NO_* definitions
  174. * @return Reference to the allocated CWindow instance
  175. */
  176. FAR CWindow *
  177. createWindow(FAR NXWidgets::CNxString &name,
  178. FAR const struct NXWidgets::SRlePaletteBitmap *sbitmap,
  179. FAR CIconMgr *iconMgr, uint8_t flags);
  180. /**
  181. * Handle the EVENT_WINDOW_DELETE event. The logic sequence is as
  182. * follows:
  183. *
  184. * 1. The TERMINATE button in pressed in the Window Toolbar and
  185. * CWindow::handleActionEvent() catches the button event on the
  186. * event listener thread and generates the EVENT_WINDOW_TERMINATE
  187. * 2. CWindows::event receives the widget event, EVENT_WINDOW_TERMINATE,
  188. * on the Twm4NX manin threadand requests to halt the NX Server
  189. * messages queues.
  190. * 3. when server responds, the CwindowsEvent::handleBlockedEvent
  191. * generates the EVENT_WINDOW_DELETE which is caught by
  192. * CWindows::event() and which, in turn calls this function.
  193. *
  194. * @param cwin The CWindow instance. This will be deleted and its
  195. * associated container will be freed.
  196. */
  197. void destroyWindow(FAR CWindow *cwin);
  198. /**
  199. * Pick a position for a new Icon on the desktop. Tries to avoid
  200. * collisions with other Icons and reserved areas on the background
  201. *
  202. * @param cwin The window being iconified.
  203. * @param defPos The default position to use if there is no free
  204. * region on the desktop.
  205. * @param iconPos The selected Icon position. Might be the same as
  206. * the default position.
  207. * @return True is returned on success
  208. */
  209. bool placeIcon(FAR CWindow *cwin,
  210. FAR const struct nxgl_point_s &defPos,
  211. FAR struct nxgl_point_s &iconPos);
  212. /**
  213. * Redraw icons. The icons are drawn on the background window. When
  214. * the background window receives a redraw request, it will call this
  215. * method in order to redraw any effected icons drawn in the
  216. * background.
  217. *
  218. * @param nxRect The region in the background to be redrawn
  219. */
  220. void redrawIcons(FAR const nxgl_rect_s *nxRect);
  221. /**
  222. * Check if the icon within iconBounds collides with any other icon on
  223. * the desktop.
  224. *
  225. * @param cwin The window containing the Icon of interest
  226. * @param iconBounds The candidate Icon bounding box
  227. * @param collision The bounding box of the icon that the candidate
  228. * collides with
  229. * @return Returns true if there is a collision
  230. */
  231. bool checkCollision(FAR CWindow *cwin,
  232. FAR const struct nxgl_rect_s &iconBounds,
  233. FAR struct nxgl_rect_s &collision);
  234. /**
  235. * Handle WINDOW events.
  236. *
  237. * @param msg. The received NxWidget WINDOW event message.
  238. * @return True if the message was properly handled. false is
  239. * return on any failure.
  240. */
  241. bool event(FAR struct SEventMsg *msg);
  242. };
  243. }
  244. #endif // __APPS_INCLUDE_GRAPHICS_TWM4NX_CWINDOWFACTORY_HXX