cnxwidget.hxx 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337
  1. /****************************************************************************
  2. * apps/include/cnxwidget.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. /****************************************************************************
  21. *
  22. * Portions of this package derive from Woopsi (http://woopsi.org/) and
  23. * portions are original efforts. It is difficult to determine at this
  24. * point what parts are original efforts and which parts derive from Woopsi.
  25. * However, in any event, the work of Antony Dzeryn will be acknowledged
  26. * in most NxWidget files. Thanks Antony!
  27. *
  28. * Copyright (c) 2007-2011, Antony Dzeryn
  29. * All rights reserved.
  30. *
  31. * Redistribution and use in source and binary forms, with or without
  32. * modification, are permitted provided that the following conditions are met:
  33. *
  34. * * Redistributions of source code must retain the above copyright
  35. * notice, this list of conditions and the following disclaimer.
  36. * * Redistributions in binary form must reproduce the above copyright
  37. * notice, this list of conditions and the following disclaimer in the
  38. * documentation and/or other materials provided with the distribution.
  39. * * Neither the names "Woopsi", "Simian Zombie" nor the
  40. * names of its contributors may be used to endorse or promote products
  41. * derived from this software without specific prior written permission.
  42. *
  43. * THIS SOFTWARE IS PROVIDED BY Antony Dzeryn ``AS IS'' AND ANY
  44. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  45. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  46. * DISCLAIMED. IN NO EVENT SHALL Antony Dzeryn BE LIABLE FOR ANY
  47. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  48. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  49. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  50. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  51. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  52. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  53. *
  54. ****************************************************************************/
  55. #ifndef __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CNXWIDGET_HXX
  56. #define __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CNXWIDGET_HXX
  57. /****************************************************************************
  58. * Included Files
  59. ****************************************************************************/
  60. #include <nuttx/config.h>
  61. #include <stdint.h>
  62. #include <stdbool.h>
  63. #include <ctime>
  64. #include <nuttx/nx/nxglib.h>
  65. #include "graphics/nxwidgets/cnxstring.hxx"
  66. #include "graphics/nxwidgets/cnxfont.hxx"
  67. #include "graphics/nxwidgets/crect.hxx"
  68. #include "graphics/nxwidgets/cwidgetstyle.hxx"
  69. #include "graphics/nxwidgets/cwidgeteventargs.hxx"
  70. #include "graphics/nxwidgets/cwidgeteventhandler.hxx"
  71. #include "graphics/nxwidgets/cwidgeteventhandlerlist.hxx"
  72. #include "graphics/nxwidgets/tnxarray.hxx"
  73. /****************************************************************************
  74. * Implementation Classes
  75. ****************************************************************************/
  76. #if defined(__cplusplus)
  77. namespace NXWidgets
  78. {
  79. /**
  80. * Forward references
  81. */
  82. class CWidgetControl;
  83. class CGraphicsPort;
  84. class CNxFont;
  85. class CWidgetEventHandlerList;
  86. /**
  87. * Class providing all the basic functionality of a NxWidget. All other
  88. * widgets must must inherit from this class.
  89. */
  90. class CNxWidget
  91. {
  92. public:
  93. /**
  94. * Enum listing flags that can be set in the constructor's "flags" parameter.
  95. */
  96. enum WidgetFlagType
  97. {
  98. WIDGET_BORDERLESS = 0x0001, /**< Widget has no border */
  99. WIDGET_DRAGGABLE = 0x0002, /**< Widget can be dragged by the user */
  100. WIDGET_PERMEABLE = 0x0004, /**< Widget's children can exceed this widget's edges */
  101. WIDGET_DOUBLE_CLICKABLE = 0x0008, /**< Widget can be double-clicked */
  102. WIDGET_NO_RAISE_EVENTS = 0x0010, /**< Widget does not raise events */
  103. };
  104. /**
  105. * Struct describing some basic properties of a widget.
  106. */
  107. typedef struct
  108. {
  109. uint8_t clicked : 1; /**< True if the widget is currently clicked. */
  110. uint8_t hasFocus : 1; /**< True if the widget has focus. */
  111. uint8_t dragging : 1; /**< True if the widget is being dragged. */
  112. uint8_t deleted : 1; /**< True if the widget has been deleted. */
  113. uint8_t borderless : 1; /**< True if the widget is borderless. */
  114. uint8_t draggable : 1; /**< True if the widget can be dragged. */
  115. uint8_t drawingEnabled : 1; /**< True if the widget can be drawn. */
  116. uint8_t enabled : 1; /**< True if the widget is enabled. */
  117. uint8_t permeable : 1; /**< True if the widget's children can exceed its dimensions. */
  118. uint8_t erased : 1; /**< True if the widget is currently erased from the frame buffer. */
  119. uint8_t hidden : 1; /**< True if the widget is hidden. */
  120. uint8_t doubleClickable : 1; /**< True if the widget can be double-clicked. */
  121. } Flags;
  122. /**
  123. * Struct describing the size of all four borders of a widget.
  124. */
  125. typedef struct
  126. {
  127. uint8_t top; /**< Height of the top border. */
  128. uint8_t right; /**< Width of the right border. */
  129. uint8_t bottom; /**< Height of the bottom border. */
  130. uint8_t left; /**< Width of the left border. */
  131. } WidgetBorderSize;
  132. protected:
  133. CWidgetControl *m_widgetControl; /**< The controlling widget for the display */
  134. CRect m_rect; /**< Rectangle bounding the widget. */
  135. // Dragging variables
  136. nxgl_coord_t m_grabPointX; /**< Physical space x coordinate where dragging began. */
  137. nxgl_coord_t m_grabPointY; /**< Physical space y coordinate where dragging began. */
  138. nxgl_coord_t m_newX; /**< Physical x coordinate where widget is being dragged to. */
  139. nxgl_coord_t m_newY; /**< Physical y coordinate where widget is being dragged to. */
  140. // Style
  141. CWidgetStyle m_style; /**< All style information used by a widget. */
  142. // Status
  143. Flags m_flags; /**< Flags struct. */
  144. // Event handling
  145. CWidgetEventHandlerList *m_widgetEventHandlers; /**< List of event handlers. */
  146. // Double-clicking
  147. struct timespec m_lastClickTime; /**< System timer when last clicked. */
  148. nxgl_coord_t m_lastClickX; /**< X coordinate of last click. */
  149. nxgl_coord_t m_lastClickY; /**< Y coordinate of last click. */
  150. int m_doubleClickBounds; /**< Area in which a click is assumed to be a double-click. */
  151. // Hierarchy control
  152. CNxWidget *m_parent; /**< Pointer to the widget's parent. */
  153. CNxWidget *m_focusedChild; /**< Pointer to the child widget that has focus. */
  154. TNxArray<CNxWidget*> m_children; /**< List of child widgets. */
  155. // Borders
  156. WidgetBorderSize m_borderSize; /**< Size of the widget borders. */
  157. /**
  158. * Draw the area of this widget that falls within the clipping region.
  159. * Called by the redraw() function to draw all visible regions.
  160. *
  161. * @param port The CGraphicsPort to draw to.
  162. * @see redraw().
  163. */
  164. virtual void drawContents(CGraphicsPort* port);
  165. /**
  166. * Draw the area of this widget that falls within the clipping region.
  167. * Called by the redraw() function to draw all visible regions.
  168. *
  169. * @param port The CGraphicsPort to draw to.
  170. * @see redraw().
  171. */
  172. virtual void drawBorder(CGraphicsPort* port) { }
  173. /**
  174. * Draw all visible regions of this widget's children.
  175. */
  176. void drawChildren(void);
  177. /**
  178. * Erase and remove the supplied child widget from this widget and
  179. * send it to the deletion queue.
  180. *
  181. * @param widget The widget to close.
  182. * @see close().
  183. */
  184. void closeChild(CNxWidget *widget);
  185. /**
  186. * Notify this widget that it is being dragged, and set its drag point.
  187. *
  188. * @param x The x coordinate of the drag position relative to this widget.
  189. * @param y The y coordinate of the drag position relative to this widget.
  190. */
  191. void startDragging(nxgl_coord_t x, nxgl_coord_t y);
  192. /**
  193. * Notify this widget that it is no longer being dragged.
  194. */
  195. void stopDragging(nxgl_coord_t x, nxgl_coord_t y);
  196. /**
  197. * Copy constructor is protected to prevent usage.
  198. */
  199. inline CNxWidget(const CNxWidget &widget) { }
  200. /**
  201. * Called when the widget is clicked. Override this when creating new
  202. * widgets if the widget should exhibit additional behaviour when it is
  203. * clicked.
  204. *
  205. * @param x The x coordinate of the click.
  206. * @param y The y coordinate of the click.
  207. */
  208. virtual inline void onClick(nxgl_coord_t x, nxgl_coord_t y) { }
  209. /**
  210. * Called when the widget is double-clicked. Override this when
  211. * creating new widgets if the widget should exhibit additional
  212. * behaviour when it is double-clicked. To change the conditions that
  213. * apply in detecting a double-click, override the isDoubleClicked()
  214. * method.
  215. *
  216. * @param x The x coordinate of the click.
  217. * @param y The y coordinate of the click.
  218. */
  219. virtual inline void onDoubleClick(nxgl_coord_t x, nxgl_coord_t y) { }
  220. /**
  221. * Called just before the widget is released; the widget will be in the
  222. * clicked stated. Override this when creating new widgets if the
  223. * widget should exhibit additional behaviour when it is released.
  224. *
  225. * @param x The x coordinate of the mouse when released.
  226. * @param y The y coordinate of the mouse when released.
  227. */
  228. virtual inline void onPreRelease(nxgl_coord_t x, nxgl_coord_t y) { }
  229. /**
  230. * Called just after the widget is released; the widget will be in the
  231. * released stated. Override this when creating new widgets if the
  232. * widget should exhibit additional behaviour when it is released.
  233. *
  234. * @param x The x coordinate of the mouse when released.
  235. * @param y The y coordinate of the mouse when released.
  236. */
  237. virtual inline void onRelease(nxgl_coord_t x, nxgl_coord_t y) { }
  238. /**
  239. * Called when the widget is released outside of its boundaries.
  240. * Override this when creating new widgets if the widget should exhibit
  241. * additional behaviour when it is released outside of its boundaries.
  242. *
  243. * @param x The x coordinate of the mouse when released.
  244. * @param y The y coordinate of the mouse when released.
  245. */
  246. virtual inline void onReleaseOutside(nxgl_coord_t x, nxgl_coord_t y) { }
  247. /**
  248. * Called when the widget is dragged. Override this when creating new
  249. * widgets if the widget should exhibit additional behaviour when it is
  250. * dragged.
  251. *
  252. * @param x The x coordinate of the mouse.
  253. * @param y The y coordinate of the mouse.
  254. * @param vX X distance dragged.
  255. * @param vY Y distance dragged.
  256. */
  257. virtual inline void onDrag(nxgl_coord_t x, nxgl_coord_t y,
  258. nxgl_coord_t vX, nxgl_coord_t vY) { }
  259. /**
  260. * Called when the widget starts being dragged. Override this when
  261. * creating new widgets if the widget should exhibit additional
  262. * behaviour when dragging starts.
  263. */
  264. virtual inline void onDragStart(void) { }
  265. /**
  266. * Called when the widget stops being dragged. Override this when
  267. * creating new widgets if the widget should exhibit additional
  268. * behaviour when dragging stops.
  269. */
  270. virtual inline void onDragStop(void) { }
  271. /**
  272. * Called when the widget gains focus. Override this when creating new
  273. * widgets if the widget should exhibit additional behaviour when
  274. * gaining focus.
  275. */
  276. virtual inline void onFocus(void) { }
  277. /**
  278. * Called when the widget loses focus. Override this when creating new
  279. * widgets if the widget should exhibit additional behaviour when
  280. * losing focus.
  281. */
  282. virtual inline void onBlur(void) { }
  283. /**
  284. * Called when the widget is enabled. Override this when creating new
  285. * widgets if the widget should exhibit additional behaviour when
  286. * enabled.
  287. */
  288. virtual inline void onEnable(void) { }
  289. /**
  290. * Called when the widget is disabled. Override this when creating new
  291. * widgets if the widget should exhibit additional behaviour when
  292. * disabled.
  293. */
  294. virtual inline void onDisable(void) { }
  295. /**
  296. * Called when the widget is resized. Override this when creating new
  297. * widgets if the widget should exhibit additional behaviour when
  298. * resized.
  299. *
  300. * @param width The new width.
  301. * @param height The new height.
  302. */
  303. virtual inline void onResize(nxgl_coord_t width, nxgl_coord_t height) { }
  304. public:
  305. /**
  306. * CNxWidget constructor.
  307. *
  308. * @param pWidgetControl The controllwing widget for the display
  309. * @param x The x coordinate of the widget.
  310. * @param y The y coordinate of the widget.
  311. * @param width The width of the widget.
  312. * @param height The height of the widget.
  313. * @param flags Bitmask specifying some set-up values for the widget.
  314. * @param style The style that the button should use. If this is not
  315. * specified, the button will use the global default widget
  316. * style.
  317. * @see WidgetFlagType.
  318. */
  319. CNxWidget(CWidgetControl *pWidgetControl,
  320. nxgl_coord_t x, nxgl_coord_t y,
  321. nxgl_coord_t width, nxgl_coord_t height,
  322. uint32_t flags,
  323. FAR const CWidgetStyle *style = (FAR const CWidgetStyle *)NULL);
  324. /**
  325. * Destructor.
  326. */
  327. virtual ~CNxWidget(void);
  328. /**
  329. * Get the x coordinate of the widget in "Widget space".
  330. *
  331. * @return Widget space x coordinate.
  332. */
  333. nxgl_coord_t getX(void) const;
  334. /**
  335. * Get the y coordinate of the widget in "Widget space".
  336. *
  337. * @return Widget space y coordinate.
  338. */
  339. nxgl_coord_t getY(void) const;
  340. /**
  341. * Get the x coordinate of the widget relative to its parent.
  342. *
  343. * @return Parent-space x coordinate.
  344. */
  345. nxgl_coord_t getRelativeX(void) const;
  346. /**
  347. * Get the y coordinate of the widget relative to its parent.
  348. *
  349. * @return Parent-space y coordinate.
  350. */
  351. nxgl_coord_t getRelativeY(void) const;
  352. /**
  353. * Is the widget active?
  354. * A value of true indicates that this widget has focus or is an ancestor
  355. * of the widget with focus.
  356. *
  357. * @return True if active.
  358. */
  359. inline bool hasFocus(void) const
  360. {
  361. return m_flags.hasFocus;
  362. }
  363. /**
  364. * Has the widget been marked for deletion? This function recurses up the widget
  365. * hierarchy and only returns true if all of the widgets in the ancestor
  366. * chain are not deleted.
  367. *
  368. * Widgets marked for deletion are automatically deleted and should not be
  369. * interacted with.
  370. *
  371. * @return True if marked for deletion.
  372. */
  373. bool isDeleted(void) const;
  374. /**
  375. * Is the widget allowed to draw? This function recurses up the widget
  376. * hierarchy and only returns true if all of the widgets in the ancestor
  377. * chain are visible.
  378. *
  379. * @return True if drawing is enabled.
  380. */
  381. bool isDrawingEnabled(void) const;
  382. /**
  383. * Is the widget hidden? This function recurses up the widget
  384. * hierarchy and returns true if any of the widgets in the ancestor
  385. * chain are hidden.
  386. *
  387. * @return True if hidden.
  388. */
  389. bool isHidden(void) const;
  390. /**
  391. * Is the widget enabled? This function recurses up the widget
  392. * hierarchy and only returns true if all of the widgets in the ancestor
  393. * chain are enabled.
  394. *
  395. * @return True if enabled.
  396. */
  397. bool isEnabled(void) const;
  398. /**
  399. * Are the widget's edges permeable or solid?
  400. * Permeable widgets do not enforce their dimensions on the
  401. * coordinates and dimensions of child widgets.
  402. *
  403. * @return True if permeable.
  404. */
  405. inline bool isPermeable(void) const
  406. {
  407. return m_flags.permeable;
  408. }
  409. /**
  410. * IS the widget double-clickable?
  411. * @return True if the widget watches for double-clicks.
  412. */
  413. inline bool isDoubleClickable(void) const
  414. {
  415. return m_flags.doubleClickable;
  416. }
  417. /**
  418. * Does the widget have a border?
  419. *
  420. * @return True if the widget does not have a border.
  421. */
  422. inline bool isBorderless(void) const
  423. {
  424. return m_flags.borderless;
  425. }
  426. /**
  427. * Is the widget clicked?
  428. *
  429. * @return True if the widget is currently clicked.
  430. */
  431. inline bool isClicked(void) const
  432. {
  433. return m_flags.clicked;
  434. }
  435. /**
  436. * Is the widget being dragged?
  437. *
  438. * @return True if the widget is currently being dragged.
  439. */
  440. inline bool isBeingDragged(void) const
  441. {
  442. return m_flags.dragging;
  443. }
  444. /**
  445. * Get the width of the widget.
  446. *
  447. * @return The widget width.
  448. */
  449. inline nxgl_coord_t getWidth(void) const
  450. {
  451. return m_rect.getWidth();
  452. }
  453. /**
  454. * Get the height of the widget.
  455. *
  456. * @return The widget height.
  457. */
  458. inline nxgl_coord_t getHeight(void) const
  459. {
  460. return m_rect.getHeight();
  461. }
  462. /**
  463. * Get the size of the widget
  464. *
  465. * @return The widgets's size
  466. */
  467. inline void getSize(struct nxgl_size_s &size) const
  468. {
  469. size.h = m_rect.getHeight();
  470. size.w = m_rect.getWidth();
  471. }
  472. /**
  473. * Get the position of the widget
  474. *
  475. * @return The widgets's position
  476. */
  477. inline void getPos(struct nxgl_point_s &pos) const
  478. {
  479. pos.x = m_rect.getX();
  480. pos.y = m_rect.getY();
  481. }
  482. /**
  483. * Get the window bounding box in physical display coordinated.
  484. *
  485. * @return This function returns the window handle.
  486. */
  487. inline CRect getBoundingBox(void)
  488. {
  489. return CRect(m_rect);
  490. }
  491. /**
  492. * Get the dimensions of the border
  493. *
  494. */
  495. inline void getBorderSize(WidgetBorderSize &borderSize)
  496. {
  497. borderSize.top = m_borderSize.top;
  498. borderSize.left = m_borderSize.left;
  499. borderSize.bottom = m_borderSize.bottom;
  500. borderSize.right = m_borderSize.right;
  501. }
  502. /**
  503. * Get a pointer to this widget's parent.
  504. *
  505. * @return This widget's parent.
  506. */
  507. inline CNxWidget *getParent(void) const
  508. {
  509. return m_parent;
  510. }
  511. /**
  512. * Get a pointer to this widget's focused child.
  513. *
  514. * @return This widget's focused child.
  515. */
  516. inline CNxWidget *getFocusedWidget(void)
  517. {
  518. return m_focusedChild;
  519. }
  520. /**
  521. * Insert the dimensions that this widget wants to have into the rect
  522. * passed in as a parameter. All coordinates are relative to the widget's
  523. * parent.
  524. *
  525. * @param rect Reference to a rect to populate with data.
  526. */
  527. virtual void getPreferredDimensions(CRect &rect) const;
  528. /**
  529. * Insert the properties of the space within this widget that is
  530. * available for children into the rect passed in as a parameter.
  531. * All coordinates are relative to this widget.
  532. *
  533. * @param rect Reference to a rect to populate with data.
  534. */
  535. void getClientRect(CRect &rect) const;
  536. /**
  537. * Insert the properties of the space within this widget that is
  538. * available for children into the rect passed in as a parameter.
  539. * Identical to getClientRect() except that all coordinates are
  540. * absolute positions within the window.
  541. *
  542. * @param rect Reference to a rect to populate with data.
  543. */
  544. void getRect(CRect &rect) const;
  545. /**
  546. * Gets a pointer to the widget's font.
  547. *
  548. * @return A pointer to the widget's font.
  549. */
  550. inline CNxFont *getFont(void) const
  551. {
  552. return m_style.font;
  553. }
  554. /**
  555. * Gets the color used for the normal background fill.
  556. *
  557. * @return Background fill color.
  558. */
  559. inline nxgl_mxpixel_t getBackgroundColor(void) const
  560. {
  561. return m_style.colors.background;
  562. }
  563. /**
  564. * Gets the color used for the background fill when the widget is selected.
  565. *
  566. * @return Dark color.
  567. */
  568. inline nxgl_mxpixel_t getSelectedBackgroundColor(void) const
  569. {
  570. return m_style.colors.selectedBackground;
  571. }
  572. /**
  573. * Gets the color used as the light edge in bevelled boxes.
  574. *
  575. * @return Shine color.
  576. */
  577. inline nxgl_mxpixel_t getShineEdgeColor(void) const
  578. {
  579. return m_style.colors.shineEdge;
  580. }
  581. /**
  582. * Gets the color used as the dark edge in bevelled boxes.
  583. *
  584. * @return Shadow color.
  585. */
  586. inline nxgl_mxpixel_t getShadowEdgeColor(void) const
  587. {
  588. return m_style.colors.shadowEdge;
  589. }
  590. /**
  591. * Gets the color used as the fill in focused window borders.
  592. *
  593. * @return Highlight color.
  594. */
  595. inline nxgl_mxpixel_t getHighlightColor(void) const
  596. {
  597. return m_style.colors.highlight;
  598. }
  599. /**
  600. * Gets the color used for text in a disabled widget.
  601. *
  602. * @return Disabled text color.
  603. */
  604. inline nxgl_mxpixel_t getDisabledTextColor(void) const
  605. {
  606. return m_style.colors.disabledText;
  607. }
  608. /**
  609. * Gets the color used for text in a enabled widget.
  610. *
  611. * @return Enabled text color.
  612. */
  613. inline nxgl_mxpixel_t getEnabledTextColor(void) const
  614. {
  615. return m_style.colors.enabledText;
  616. }
  617. /**
  618. * Gets the color used for text in a clicked widget.
  619. *
  620. * @return Selected text color.
  621. */
  622. inline nxgl_mxpixel_t getSelectedTextColor(void) const
  623. {
  624. return m_style.colors.selectedText;
  625. }
  626. /**
  627. * Get the style used by this widget
  628. *
  629. * @return Const pointer to CWidgetStyle stored inside this widget.
  630. */
  631. inline const CWidgetStyle *getWidgetStyle() const { return &m_style; }
  632. /**
  633. * Use the provided widget style
  634. */
  635. void useWidgetStyle(const CWidgetStyle *style);
  636. /**
  637. * Sets this widget's border state.
  638. *
  639. * @param isBorderless The border state.
  640. */
  641. void setBorderless(bool isBorderless);
  642. /**
  643. * Sets whether or not this widget can be dragged.
  644. *
  645. * @param isDraggable The draggable state.
  646. */
  647. inline void setDraggable(bool isDraggable)
  648. {
  649. m_flags.draggable = isDraggable;
  650. }
  651. /**
  652. * Sets whether or not child widgets can exceed this widget's dimensions.
  653. *
  654. * @param permeable The permeable state.
  655. */
  656. inline void setPermeable(bool permeable)
  657. {
  658. m_flags.permeable = permeable;
  659. }
  660. /**
  661. * Sets whether or not the widgets processes double-clicks.
  662. *
  663. * @param doubleClickable The double-clickable state.
  664. */
  665. inline void setDoubleClickable(bool doubleClickable)
  666. {
  667. m_flags.doubleClickable = doubleClickable;
  668. }
  669. /**
  670. * Adds a widget event handler. The event handler will receive
  671. * all events raised by this widget.
  672. *
  673. * @param eventHandler A pointer to the event handler.
  674. */
  675. inline void addWidgetEventHandler(CWidgetEventHandler *eventHandler)
  676. {
  677. m_widgetEventHandlers->addWidgetEventHandler(eventHandler);
  678. }
  679. /**
  680. * Remove a widget event handler.
  681. *
  682. * @param eventHandler A pointer to the event handler to remove.
  683. */
  684. inline void removeWidgetEventHandler(CWidgetEventHandler* eventHandler)
  685. {
  686. m_widgetEventHandlers->removeWidgetEventHandler(eventHandler);
  687. }
  688. /**
  689. * Return the number of registered event handlers
  690. *
  691. * @return The number of registered event handlers
  692. */
  693. inline int nWidgetEventHandlers(void) const
  694. {
  695. return m_widgetEventHandlers->size();
  696. }
  697. /**
  698. * Enables or disables event firing for this widget.
  699. *
  700. * @param raises True to enable events, false to disable.
  701. */
  702. inline void setRaisesEvents(bool raises)
  703. {
  704. raises ? m_widgetEventHandlers->enable() : m_widgetEventHandlers->disable();
  705. }
  706. /**
  707. * Check if event handling is enabled for this widget.
  708. *
  709. * @return True is event handling is enabled.
  710. */
  711. inline bool raisesEvents(void) const
  712. {
  713. return m_widgetEventHandlers->isEnabled();
  714. }
  715. /**
  716. * Disabled drawing of this widget. Widgets hidden using this method will still
  717. * be processed.
  718. */
  719. inline void disableDrawing(void)
  720. {
  721. m_flags.drawingEnabled = false;
  722. }
  723. /**
  724. * Enables drawing of this widget.
  725. */
  726. inline void enableDrawing(void)
  727. {
  728. m_flags.drawingEnabled = true;
  729. }
  730. /**
  731. * Sets the normal background color.
  732. *
  733. * @param color The new background color.
  734. */
  735. inline void setBackgroundColor(nxgl_mxpixel_t color)
  736. {
  737. m_style.colors.background = color;
  738. }
  739. /**
  740. * Sets the background color for a selected widget.
  741. *
  742. * @param color The new selected background color.
  743. */
  744. inline void setSelectedBackgroundColor(nxgl_mxpixel_t color)
  745. {
  746. m_style.colors.selectedBackground = color;
  747. }
  748. /**
  749. * Sets the shiny edge color.
  750. *
  751. * @param color The new shine edge color.
  752. */
  753. inline void setShineEdgeColor(nxgl_mxpixel_t color)
  754. {
  755. m_style.colors.shineEdge = color;
  756. }
  757. /**
  758. * Sets the shadow edge color.
  759. *
  760. * @param color The new shadow edge color.
  761. */
  762. inline void setShadowEdgeColor(nxgl_mxpixel_t color)
  763. {
  764. m_style.colors.shadowEdge = color;
  765. }
  766. /**
  767. * Sets the highlight color.
  768. *
  769. * @param color The new highlight color.
  770. */
  771. inline void setHighlightColor(nxgl_mxpixel_t color)
  772. {
  773. m_style.colors.highlight = color;
  774. }
  775. /**
  776. * Sets the text color to use when the widget is disabled.
  777. *
  778. * @param color The new text color.
  779. */
  780. inline void setDisabledTextColor(nxgl_mxpixel_t color)
  781. {
  782. m_style.colors.disabledText = color;
  783. }
  784. /**
  785. * Sets the text color to use when the widget is enabled.
  786. *
  787. * @param color The new text color.
  788. */
  789. inline void setEnabledTextColor(nxgl_mxpixel_t color)
  790. {
  791. m_style.colors.enabledText = color;
  792. }
  793. /**
  794. * Sets the text color to use when the widget is highlighted or clicked.
  795. *
  796. * @param color The new selected text color.
  797. */
  798. inline void setSelectedTextColor(nxgl_mxpixel_t color)
  799. {
  800. m_style.colors.selectedText = color;
  801. }
  802. /**
  803. * Sets the font.
  804. *
  805. * @param font A pointer to the font to use.
  806. *
  807. * NOTE: This font is not deleted when the widget is destroyed!
  808. */
  809. virtual void setFont(CNxFont *font);
  810. /**
  811. * Draws the visible regions of the widget and the widget's child widgets.
  812. */
  813. void redraw(void);
  814. /**
  815. * Enables the widget.
  816. *
  817. * @return True if the widget was enabled.
  818. */
  819. bool enable(void);
  820. /**
  821. * Disabled the widget.
  822. *
  823. * @return True if the widget was disabled.
  824. */
  825. bool disable(void);
  826. /**
  827. * Erases the widget, marks it as deleted, and moves it to the CNxWidget
  828. * deletion queue. Widgets are automatically deleted by the framework and
  829. * should not be deleted externally.
  830. */
  831. void close(void);
  832. /**
  833. * Draws the widget and makes it visible.
  834. * Does not steal focus from other widgets.
  835. *
  836. * @return True if the widget was shown.
  837. * @see hide()
  838. */
  839. bool show(void);
  840. /**
  841. * Erases the widget and makes it invisible.
  842. * Does not re-assign focus to another widget.
  843. *
  844. * @return True if the widget was hidden.
  845. * @see show()
  846. */
  847. bool hide(void);
  848. /**
  849. * Click this widget at the supplied coordinates. This should only be
  850. * overridden in subclasses if the default click behaviour needs to be changed.
  851. * If the subclassed widget should just respond to a standard click,
  852. * the onClick() method should be overridden instead.
  853. *
  854. * @param x X coordinate of the click.
  855. * @param y Y coordinate of the click.
  856. * @return True if the click was successful.
  857. */
  858. virtual bool click(nxgl_coord_t x, nxgl_coord_t y);
  859. /**
  860. * Check if the click is a double-click.
  861. *
  862. * @param x X coordinate of the click.
  863. * @param y Y coordinate of the click.
  864. * @return True if the click is a double-click.
  865. */
  866. virtual bool isDoubleClick(nxgl_coord_t x, nxgl_coord_t y);
  867. /**
  868. * Double-click this widget at the supplied coordinates. This
  869. * should only be overridden in subclasses if the default
  870. * double-click behaviour needs to be changed. If the subclassed
  871. * widget should just respond to a standard double-click, the
  872. * onDoubleClick() method should be overridden instead.
  873. *
  874. * @param x X coordinate of the click.
  875. * @param y Y coordinate of the click.
  876. * @return True if the click was successful.
  877. */
  878. bool doubleClick(nxgl_coord_t x, nxgl_coord_t y);
  879. /**
  880. * Release this widget at the supplied coordinates. This
  881. * should only be overridden in subclasses if the default
  882. * release behaviour needs to be changed. If the subclassed
  883. * widget should just respond to a standard release, the
  884. * onRelease() method should be overridden instead.
  885. *
  886. * @param x X coordinate of the release.
  887. * @param y Y coordinate of the release.
  888. * @return True if the release was successful.
  889. */
  890. bool release(nxgl_coord_t x, nxgl_coord_t y);
  891. /**
  892. * Drag the widget to the supplied coordinates.
  893. *
  894. * @param x The x coordinate of the mouse.
  895. * @param y The y coordinate of the mouse.
  896. * @param vX The horizontal distance that the mouse was dragged.
  897. * @param vY The vertical distance that the mouse was dragged.
  898. * @return True if the drag was successful.
  899. */
  900. bool drag(nxgl_coord_t x, nxgl_coord_t y,
  901. nxgl_coord_t vX, nxgl_coord_t vY);
  902. /**
  903. * Send a keypress to the widget.
  904. *
  905. * @param key The keycode to send to the widget.
  906. * @return True if the keypress was processed.
  907. */
  908. bool keyPress(nxwidget_char_t key);
  909. /**
  910. * Send a cursor control event to the widget.
  911. *
  912. * @param control The cursor control code to send to the widget.
  913. * @return True if the cursor control was processed.
  914. */
  915. bool cursorControl(ECursorControl control);
  916. /**
  917. * Give the widget focus.
  918. *
  919. * @return True if the widget received focus correctly.
  920. */
  921. bool focus(void);
  922. /**
  923. * Remove focus from the widget.
  924. *
  925. * @return True if the widget lost focus correctly.
  926. */
  927. bool blur(void);
  928. /**
  929. * Move the widget to the new coordinates.
  930. * Coordinates are relative to the parent widget.
  931. *
  932. * @param x The new x coordinate.
  933. * @param y The new y coordinate.
  934. * @return True if the move was successful.
  935. */
  936. bool moveTo(nxgl_coord_t x, nxgl_coord_t y);
  937. /**
  938. * Resize the widget to the new dimensions.
  939. *
  940. * @param width The new width.
  941. * @param height The new height.
  942. * @return True if the resize was successful.
  943. */
  944. bool resize(nxgl_coord_t width, nxgl_coord_t height);
  945. /**
  946. * Resize and move the widget in one operation.
  947. * Only performs one redraw so it is faster than calling the
  948. * two separate functions.
  949. *
  950. * @param x The new x coordinate.
  951. * @param y The new y coordinate.
  952. * @param width The new width.
  953. * @param height The new height.
  954. * @return True if the widget was adjusted successfully.
  955. */
  956. bool changeDimensions(nxgl_coord_t x, nxgl_coord_t y,
  957. nxgl_coord_t width, nxgl_coord_t height);
  958. /**
  959. * Moves the supplied child widget to the deletion queue.
  960. * For framework use only.
  961. *
  962. * @param widget A pointer to the child widget.
  963. */
  964. void moveChildToDeleteQueue(CNxWidget *widget);
  965. /**
  966. * Sets the supplied widget as the focused child. The widget must
  967. * be a child of this widget.
  968. *
  969. * @param widget A pointer to the child widget.
  970. * @see getFocusedWidget()
  971. */
  972. void setFocusedWidget(CNxWidget *widget);
  973. /**
  974. * Checks if the supplied coordinates collide with this widget.
  975. *
  976. * @param x The x coordinate to check.
  977. * @param y The y coordinate to check.
  978. * @return True if a collision occurred.
  979. */
  980. virtual bool checkCollision(nxgl_coord_t x, nxgl_coord_t y) const;
  981. /**
  982. * Checks if the supplied rectangle definition collides with this widget.
  983. *
  984. * @param x The x coordinate of the rectangle to check.
  985. * @param y The y coordinate of the rectangle to check.
  986. * @param width The width of the rectangle to check.
  987. * @param height The height of the rectangle to check.
  988. * @return True if a collision occurred.
  989. */
  990. virtual bool checkCollision(nxgl_coord_t x, nxgl_coord_t y,
  991. nxgl_coord_t width, nxgl_coord_t height) const;
  992. /**
  993. * Checks if the supplied widget collides with this widget.
  994. *
  995. * @param widget A pointer to another widget to check for collisions with.
  996. * @return True if a collision occurred.
  997. */
  998. bool checkCollision(CNxWidget *widget) const;
  999. /**
  1000. * Adds a widget to this widget's child stack. The widget is added to the
  1001. * top of the stack. Note that the widget can only be added if it is not
  1002. * already a child of another widget.
  1003. *
  1004. * @param widget A pointer to the widget to add to the child list.
  1005. * @see insertWidget()
  1006. */
  1007. void addWidget(CNxWidget *widget);
  1008. /**
  1009. * Inserts a widget into this widget's child stack at the bottom of the
  1010. * stack. Note that the widget can only be added if it is not already
  1011. * a child of another widget.
  1012. *
  1013. * @param widget A pointer to the widget to add to the child list.
  1014. * @see addWidget()
  1015. */
  1016. void insertWidget(CNxWidget *widget);
  1017. /**
  1018. * Set the widget's parent to the widget passed in as a parameter.
  1019. * Called automatically when a widget is added as a child.
  1020. *
  1021. * @param parent A pointer to the parent widget.
  1022. */
  1023. inline void setParent(CNxWidget *parent)
  1024. {
  1025. m_parent = parent;
  1026. }
  1027. /**
  1028. * Delete this widget. This should never be called in user code; widget
  1029. * deletion is handled internally.
  1030. */
  1031. inline void destroy(void)
  1032. {
  1033. delete this;
  1034. }
  1035. /**
  1036. * Remove this widget from the widget hierarchy. Returns
  1037. * responsibility for deleting the widget back to the developer.
  1038. * Does not unregister the widget from the VBL system.
  1039. * Does not erase the widget from the display.
  1040. *
  1041. * @return True if the widget was successfully removed.
  1042. */
  1043. bool remove(void);
  1044. /**
  1045. * Remove a child widget from the widget hierarchy. Returns
  1046. * responsibility for deleting the widget back to the developer.
  1047. * Does not unregister the widget from the VBL system.
  1048. * Does not erase the widget from the display.
  1049. *
  1050. * @param widget Pointer to the widget to remove from the hierarchy.
  1051. * @return True if the widget was successfully removed.
  1052. */
  1053. bool removeChild(CNxWidget *widget);
  1054. /**
  1055. * Get the child widget at the specified index.
  1056. *
  1057. * @param index Index of the child to retrieve.
  1058. * @return Pointer to the child at the specified index.
  1059. */
  1060. const CNxWidget *getChild(int index) const;
  1061. /**
  1062. * Get the number of child widgets.
  1063. *
  1064. * @return The number of child widgets belonging to this widget.
  1065. */
  1066. int getChildCount(void) const
  1067. {
  1068. return m_children.size();
  1069. }
  1070. /**
  1071. * Sets the border size. The border cannot be drawn over in the
  1072. * drawContents() method.
  1073. *
  1074. * @param borderSize The new border size.
  1075. */
  1076. void setBorderSize(const WidgetBorderSize &borderSize);
  1077. };
  1078. }
  1079. #endif // __cplusplus
  1080. #endif // __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CNXWIDGET_HXX