cnxtoolbar.hxx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. /****************************************************************************
  2. * apps/include/graphics/nxwidgets/cnxtoolbar.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. #ifndef __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CNXTOOLBAR_HXX
  21. #define __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CNXTOOLBAR_HXX
  22. /****************************************************************************
  23. * Included Files
  24. ****************************************************************************/
  25. #include <nuttx/config.h>
  26. #include <stdint.h>
  27. #include <stdbool.h>
  28. #include <nuttx/nx/nxglib.h>
  29. #include <nuttx/nx/nx.h>
  30. #include <nuttx/nx/nxtk.h>
  31. #include "graphics/nxwidgets/ccallback.hxx"
  32. #include "graphics/nxwidgets/inxwindow.hxx"
  33. #include "graphics/nxwidgets/cnxtkwindow.hxx"
  34. /****************************************************************************
  35. * Pre-Processor Definitions
  36. ****************************************************************************/
  37. /****************************************************************************
  38. * Implementation Classes
  39. ****************************************************************************/
  40. #if defined(__cplusplus)
  41. namespace NXWidgets
  42. {
  43. class CWidgetControl;
  44. struct SBitmap;
  45. /**
  46. * This class defines operations on a the toolbar in a framed NX window.
  47. * There are three instances that represent an NX window from the
  48. * perspective of NXWidgets.
  49. *
  50. * - There is one widget control instance per NX window,
  51. * - One CCallback instance per window,
  52. * - One window instance.
  53. *
  54. * There a various kinds of of window instances, but each inherits
  55. * (1) CCallback and dispatches the Windows callbacks and (2) INxWindow
  56. * that describes the common window behavior.
  57. */
  58. class CNxToolbar : protected CCallback, public INxWindow
  59. {
  60. private:
  61. CNxTkWindow *m_nxTkWindow; /**< Parent framed window instance. */
  62. NXTKWINDOW m_hNxTkWindow; /**< Parent framed window handle. */
  63. CWidgetControl *m_widgetControl; /**< Controlling widget for the toolbar */
  64. nxgl_coord_t m_height; /**< The toolbar height */
  65. public:
  66. /**
  67. * Constructor. Creates an uninitialized instance of the CNxToolbar
  68. * object. The open() method must be called to initialize the instance.
  69. *
  70. * @param pNxTkWindow Parent framed window instance
  71. * @param hNxTkWindow Parent framed window NX handler
  72. * @param widgetControl Controlling widget for this toolbar.
  73. * @param height The height of the toolbar.
  74. */
  75. CNxToolbar(CNxTkWindow *pNxTkWindow, NXTKWINDOW hNxTkWindow,
  76. CWidgetControl *pWidgetControl, nxgl_coord_t height);
  77. /**
  78. * Destructor.
  79. */
  80. ~CNxToolbar(void);
  81. /**
  82. * Creates a new toolbar. Toolbar creation is separate from
  83. * object instantiation so that failures can be reported.
  84. *
  85. * @return True if the toolbar was successfully created.
  86. */
  87. bool open(void);
  88. /**
  89. * Each implementation of INxWindow must provide a method to recover
  90. * the contained CWidgetControl instance.
  91. *
  92. * @return The contained CWidgetControl instance
  93. */
  94. CWidgetControl *getWidgetControl(void) const;
  95. /**
  96. * Synchronize the window with the NX server. This function will delay
  97. * until the the NX server has caught up with all of the queued requests.
  98. * When this function returns, the state of the NX server will be the
  99. * same as the state of the application.
  100. */
  101. inline void synchronize(void)
  102. {
  103. CCallback::synchronize(m_hNxTkWindow, CCallback::NXTK_FRAMEDWINDOW);
  104. }
  105. /**
  106. * Request the position and size information of the toolbar. The values
  107. * will be returned asynchronously through the client callback method.
  108. * The GetPosition() method may than be called to obtain the positional
  109. * data as provided by the callback.
  110. *
  111. * @return True on success, false on any failure.
  112. */
  113. bool requestPosition(void);
  114. /**
  115. * Get the position of the toolbar (as reported by the NX callback).
  116. *
  117. * @return The position.
  118. */
  119. bool getPosition(FAR struct nxgl_point_s *pPos);
  120. /**
  121. * Get the size of the toolbar (as reported by the NX callback).
  122. *
  123. * @return The size.
  124. */
  125. bool getSize(FAR struct nxgl_size_s *pSize);
  126. /**
  127. * Set the position and size of the toolbar. The position of
  128. * the toolbar is fixed at the top of the parent framed window.
  129. *
  130. * @param pPos The new position of the toolbar.
  131. * @return Always returns false.
  132. */
  133. inline bool setPosition(FAR const struct nxgl_point_s *pPos)
  134. {
  135. return false;
  136. }
  137. /**
  138. * Set the size of the selected toolbar. The only variable dimension
  139. * is the height of the toolbar, but that cannot be changed once
  140. * it is created.
  141. *
  142. * @param pSize The new size of the toolbar.
  143. * @return Always returns false.
  144. */
  145. inline bool setSize(FAR const struct nxgl_size_s *pSize)
  146. {
  147. return false;
  148. }
  149. /**
  150. * Bring the toolbar to the top of the display. The toolbar is
  151. * a component of the containing, parent, framed window. It
  152. * cannot be raised separately.
  153. *
  154. * @return Always returns false.
  155. */
  156. inline bool raise(void)
  157. {
  158. return false;
  159. }
  160. /**
  161. * Lower the toolbar to the bottom of the display. The toolbar is
  162. * a component of the containing, parent, framed window. It
  163. * cannot be raised separately.
  164. *
  165. * @return Always returns false.
  166. */
  167. inline bool lower(void)
  168. {
  169. return false;
  170. }
  171. /**
  172. * Return true if the toolbar is currently being displayed
  173. *
  174. * @return True if the window is visible
  175. */
  176. inline bool isVisible(void)
  177. {
  178. return !nxtk_ishidden(m_hNxTkWindow);
  179. }
  180. /**
  181. * Show a hidden toolbar. The toolbar is a component of the containing,
  182. * parent, framed window. It cannot be shown separately.
  183. *
  184. * @return True on success, false on any failure.
  185. */
  186. inline bool show(void)
  187. {
  188. return nxtk_setvisibility(m_hNxTkWindow, false) == OK;
  189. }
  190. /**
  191. * Hide a visible window. The toolbar is a component of the containing,
  192. * parent, framed window. It cannot be hidden separately.
  193. *
  194. * @return True on success, false on any failure.
  195. */
  196. inline bool hide(void)
  197. {
  198. return nxtk_setvisibility(m_hNxTkWindow, true) == OK;
  199. }
  200. /**
  201. * May be used to either (1) raise a window to the top of the display and
  202. * select modal behavior, or (2) disable modal behavior. The toolbar is
  203. * a component of the containing, parent, framed window. It cannot
  204. * be placed in the modal state separately.
  205. *
  206. * @param enable True: enter modal state; False: leave modal state
  207. * @return Always returns false.
  208. */
  209. inline bool modal(bool enable)
  210. {
  211. return false;
  212. }
  213. /**
  214. * Each window implementation also inherits from CCallback. CCallback,
  215. * by default, forwards NX keyboard input to the various widgets residing
  216. * in the window. But NxTerm is a different usage model; In this case,
  217. * keyboard input needs to be directed to the NxTerm character driver.
  218. * This method can be used to enable (or disable) redirection of NX
  219. * keyboard input from the window widgets to the NxTerm
  220. *
  221. * @param handle. The NXTERM handle. If non-NULL, NX keyboard
  222. * input will be directed to the NxTerm driver using this
  223. * handle; If NULL (the default), NX keyboard input will be
  224. * directed to the widgets within the window.
  225. */
  226. #ifdef CONFIG_NXTERM_NXKBDIN
  227. inline void redirectNxTerm(NXTERM handle)
  228. {
  229. setNxTerm(handle);
  230. }
  231. #endif
  232. /**
  233. * Set an individual pixel in the toolbar with the specified color.
  234. *
  235. * @param pPos The location of the pixel to be filled.
  236. * @param color The color to use in the fill.
  237. *
  238. * @return True on success; false on failure.
  239. */
  240. bool setPixel(FAR const struct nxgl_point_s *pPos,
  241. nxgl_mxpixel_t color);
  242. /**
  243. * Fill the specified rectangle in the toolbar with the specified color.
  244. *
  245. * @param pRect The location to be filled.
  246. * @param color The color to use in the fill.
  247. *
  248. * @return True on success; false on failure.
  249. */
  250. bool fill(FAR const struct nxgl_rect_s *pRect,
  251. nxgl_mxpixel_t color);
  252. /**
  253. * Get the raw contents of graphic memory within a rectangular region. NOTE:
  254. * Since raw graphic memory is returned, the returned memory content may be
  255. * the memory of windows above this one and may not necessarily belong to
  256. * this window unless you assure that this is the top window.
  257. *
  258. * @param rect The location to be copied
  259. * @param dest - The describes the destination bitmap to receive the
  260. * graphics data.
  261. */
  262. void getRectangle(FAR const struct nxgl_rect_s *rect, struct SBitmap *dest);
  263. /**
  264. * Fill the specified trapezoidal region in the toolbar with the specified
  265. * color.
  266. *
  267. * @param pClip Clipping rectangle relative to toolbar (may be null).
  268. * @param pTrap The trapezoidal region to be filled.
  269. * @param color The color to use in the fill.
  270. *
  271. * @return True on success; false on failure.
  272. */
  273. bool fillTrapezoid(FAR const struct nxgl_rect_s *pClip,
  274. FAR const struct nxgl_trapezoid_s *pTrap,
  275. nxgl_mxpixel_t color);
  276. /**
  277. * Fill the specified line in the toolbar with the specified color.
  278. *
  279. * @param vector - Describes the line to be drawn
  280. * @param width - The width of the line
  281. * @param color - The color to use to fill the line
  282. * @param caps - Draw a circular cap on the ends of the line to support
  283. * better line joins
  284. *
  285. * @return True on success; false on failure.
  286. */
  287. bool drawLine(FAR struct nxgl_vector_s *vector,
  288. nxgl_coord_t width, nxgl_mxpixel_t color,
  289. enum ELineCaps caps);
  290. /**
  291. * Draw a filled circle at the specified position, size, and color.
  292. *
  293. * @param center The window-relative coordinates of the circle center.
  294. * @param radius The radius of the rectangle in pixels.
  295. * @param color The color of the rectangle.
  296. */
  297. bool drawFilledCircle(struct nxgl_point_s *center, nxgl_coord_t radius,
  298. nxgl_mxpixel_t color);
  299. /**
  300. * Move a rectangular region within the toolbar.
  301. *
  302. * @param pRect Describes the rectangular region to move.
  303. * @param pOffset The offset to move the region.
  304. *
  305. * @return True on success; false on failure.
  306. */
  307. bool move(FAR const struct nxgl_rect_s *pRect,
  308. FAR const struct nxgl_point_s *pOffset);
  309. /**
  310. * Copy a rectangular region of a larger image into the rectangle in the
  311. * specified toolbar.
  312. *
  313. * @param pDest Describes the rectangular on the display that will receive
  314. * the bitmap.
  315. * @param pSrc The start of the source image.
  316. * @param pOrigin the pOrigin of the upper, left-most corner of the full
  317. * bitmap. Both pDest and pOrigin are in toolbar coordinates, however,
  318. * pOrigin may lie outside of the display.
  319. * @param stride The width of the full source image in bytes.
  320. *
  321. * @return True on success; false on failure.
  322. */
  323. bool bitmap(FAR const struct nxgl_rect_s *pDest,
  324. FAR const void *pSrc,
  325. FAR const struct nxgl_point_s *pOrigin,
  326. unsigned int stride);
  327. };
  328. }
  329. #endif // __cplusplus
  330. #endif // __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CNXTOOLBAR_HXX