ciconmgr.hxx 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. /////////////////////////////////////////////////////////////////////////////
  2. // apps/include/graphics/twm4nx/ciconmgr.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. //
  24. // Please refer to apps/twm4nx/COPYING for detailed copyright information.
  25. // Although not listed as a copyright holder, thanks and recognition need
  26. // to go to Tom LaStrange, the original author of TWM.
  27. #ifndef __APPS_INCLUDE_GRAPHICS_TWM4NX_CICONMGR_HXX
  28. #define __APPS_INCLUDE_GRAPHICS_TWM4NX_CICONMGR_HXX
  29. /////////////////////////////////////////////////////////////////////////////
  30. // Included Files
  31. /////////////////////////////////////////////////////////////////////////////
  32. #include <fcntl.h>
  33. #include <mqueue.h>
  34. #include <nuttx/nx/nxglib.h>
  35. #include "graphics/twm4nx/cwindow.hxx"
  36. #include "graphics/twm4nx/cmainmenu.hxx"
  37. #include "graphics/twm4nx/iapplication.hxx"
  38. #include "graphics/twm4nx/twm4nx_events.hxx"
  39. /////////////////////////////////////////////////////////////////////////////
  40. // Implementation Classes
  41. /////////////////////////////////////////////////////////////////////////////
  42. namespace NXWidgets
  43. {
  44. class CNxTkWindow; // Forward reference
  45. class CButtonArray; // Forward reference
  46. class CWidgetEventHandler; // Forward reference
  47. class CWidgetEventArgs; // Forward reference
  48. struct SRlePaletteBitmap; // Forward reference
  49. }
  50. namespace Twm4Nx
  51. {
  52. struct SWindowEntry
  53. {
  54. FAR struct SWindowEntry *flink; /**< Forward link to next window entry */
  55. FAR struct SWindowEntry *blink; /**< Backward link to previous window entry */
  56. FAR CWindow *cwin; /**< The window payload */
  57. int row; /**< Y position in the button array */
  58. int column; /**< X position in the button array */
  59. };
  60. class CIconMgr : protected NXWidgets::CWidgetEventHandler,
  61. protected IApplication,
  62. public CTwm4NxEvent
  63. {
  64. private:
  65. FAR CTwm4Nx *m_twm4nx; /**< Cached Twm4Nx session */
  66. mqd_t m_eventq; /**< NxWidget event message queue */
  67. NXWidgets::CNxString m_name; /**< The Icon Manager name */
  68. FAR struct SWindowEntry *m_head; /**< Head of the window list */
  69. FAR struct SWindowEntry *m_tail; /**< Tail of the window list */
  70. FAR struct CWindow *m_window; /**< Parent window */
  71. FAR NXWidgets::CButtonArray *m_buttons; /**< The contained button array */
  72. uint16_t m_nWindows; /**< The number of windows in the icon mgr. */
  73. uint8_t m_nColumns; /**< Fixed number of columns per row */
  74. uint8_t m_nrows; /**< Number of rows in the button array */
  75. /**
  76. * Return the width of one button
  77. *
  78. * @return The width of one button
  79. */
  80. inline nxgl_coord_t getButtonWidth(void);
  81. /**
  82. * Return the height of one button
  83. *
  84. * @return The height of one button
  85. */
  86. inline nxgl_coord_t getButtonHeight(void);
  87. /**
  88. * Create and initialize the icon manager window
  89. *
  90. * @param name The prefix for this icon manager name
  91. */
  92. bool createIconManagerWindow(FAR const char *prefix);
  93. /**
  94. * Create the button array widget
  95. */
  96. bool createButtonArray(void);
  97. /**
  98. * Label each button with the window name
  99. */
  100. void labelButtons(void);
  101. /**
  102. * Put an allocated entry into an icon manager
  103. *
  104. * @param wentry the entry to insert
  105. */
  106. void insertEntry(FAR struct SWindowEntry *wentry,
  107. FAR CWindow *cwin);
  108. /**
  109. * Remove an entry from an icon manager
  110. *
  111. * @param wentry the entry to remove
  112. */
  113. void removeEntry(FAR struct SWindowEntry *wentry);
  114. /**
  115. * Find an entry in the icon manager
  116. *
  117. * @param cwin The window to find
  118. * @return The incon manager entry (unless an error occurred)
  119. */
  120. FAR struct SWindowEntry *findEntry(FAR CWindow *cwin);
  121. /**
  122. * Free window list entry.
  123. */
  124. void freeWEntry(FAR struct SWindowEntry *wentry);
  125. /**
  126. * Handle a widget action event, overriding the CWidgetEventHandler
  127. * method. This will indicate a button pre-release event.
  128. *
  129. * @param e The event data.
  130. */
  131. void handleActionEvent(const NXWidgets::CWidgetEventArgs &e);
  132. /**
  133. * Return the Main Menu item string. This overrides the method from
  134. * IApplication
  135. *
  136. * @param name The name of the application.
  137. */
  138. inline NXWidgets::CNxString getName(void)
  139. {
  140. return m_name;
  141. }
  142. /**
  143. * There is no sub-menu for this Main Menu item. This overrides
  144. * the method from IApplication.
  145. *
  146. * @return This implementation will always return a null value.
  147. */
  148. inline FAR CMenus *getSubMenu(void)
  149. {
  150. return (FAR CMenus *)0;
  151. }
  152. /**
  153. * There is no custom event handler. We use the common event handler.
  154. *
  155. * @return. null is always returned in this implementation.
  156. */
  157. inline FAR CTwm4NxEvent *getEventHandler(void)
  158. {
  159. return (FAR CTwm4NxEvent *)0;
  160. }
  161. /**
  162. * Return the Twm4Nx event that will be generated when the Main Menu
  163. * item is selected.
  164. *
  165. * @return. This function always returns EVENT_ICONMGR_DEICONIFY.
  166. */
  167. inline uint16_t getEvent(void)
  168. {
  169. return EVENT_ICONMGR_DEICONIFY;
  170. }
  171. public:
  172. /**
  173. * CIconMgr Constructor
  174. *
  175. * @param twm4nx The Twm4Nx session
  176. * @param ncolumns The number of columns this icon manager has
  177. */
  178. CIconMgr(CTwm4Nx *twm4nx, uint8_t ncolumns);
  179. /**
  180. * CIconMgr Destructor
  181. */
  182. ~CIconMgr(void);
  183. /**
  184. * Create and initialize the icon manager window.
  185. *
  186. * @param name The prefix for this icon manager name
  187. * @return True on success
  188. */
  189. bool initialize(FAR const char *prefix);
  190. /**
  191. * Add Icon Manager menu items to the Main menu. This is really a
  192. * part of the logic that belongs in initialize() but cannot be
  193. * executed in that context because it assumes that the Main Menu
  194. * logic is ready.
  195. *
  196. * @return True on success
  197. */
  198. bool addMenuItems(void);
  199. /**
  200. * Add a window to an the icon manager
  201. *
  202. * @param cwin the TWM window structure
  203. */
  204. bool addWindow(FAR CWindow *cwin);
  205. /**
  206. * Remove a window from the icon manager
  207. *
  208. * @param cwin the TWM window structure
  209. */
  210. void removeWindow(FAR CWindow *cwin);
  211. /**
  212. * Hide the icon manager
  213. */
  214. inline void hide(void)
  215. {
  216. if (m_window != (FAR CWindow *)0)
  217. {
  218. m_window->iconify();
  219. }
  220. }
  221. /**
  222. * Get the number of columns
  223. */
  224. inline unsigned int getNumberOfColumns(void)
  225. {
  226. return m_nColumns;
  227. }
  228. /**
  229. * Get the current size
  230. */
  231. inline bool getSize(FAR struct nxgl_size_s *size)
  232. {
  233. return m_window->getFrameSize(size);
  234. }
  235. /**
  236. * Resize the button array, possibly adjusting the window height
  237. *
  238. * @return True if the button array was resized successfully
  239. */
  240. bool resizeIconManager(void);
  241. /**
  242. * sort the windows
  243. */
  244. void sort(void);
  245. /**
  246. * Handle ICONMGR events.
  247. *
  248. * @param eventmsg. The received NxWidget ICONMGR event message.
  249. * @return True if the message was properly handled. false is
  250. * return on any failure.
  251. */
  252. bool event(FAR struct SEventMsg *eventmsg);
  253. };
  254. }
  255. /////////////////////////////////////////////////////////////////////////////
  256. // Public Function Prototypes
  257. /////////////////////////////////////////////////////////////////////////////
  258. #endif // __APPS_INCLUDE_GRAPHICS_TWM4NX_CICONMGR_HXX