cwidgetcontrol.hxx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. /****************************************************************************
  2. * apps/include/graphics/nxwidgets/cwidgetcontrol.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_CWIDGETCONTROLT_HXX
  21. #define __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CWIDGETCONTROLT_HXX
  22. /****************************************************************************
  23. * Included Files
  24. ****************************************************************************/
  25. #include <nuttx/config.h>
  26. #include <stdint.h>
  27. #include <stdbool.h>
  28. #include <stdlib.h>
  29. #include <semaphore.h>
  30. #include <time.h>
  31. #include "graphics/nxwidgets/nxconfig.hxx"
  32. #include "graphics/nxwidgets/cgraphicsport.hxx"
  33. #include "graphics/nxwidgets/cnxwidget.hxx"
  34. #include "graphics/nxwidgets/crect.hxx"
  35. #include "graphics/nxwidgets/cwidgetstyle.hxx"
  36. #include "graphics/nxwidgets/cwindoweventhandler.hxx"
  37. #include "graphics/nxwidgets/cwindoweventhandlerlist.hxx"
  38. #include "graphics/nxwidgets/tnxarray.hxx"
  39. /****************************************************************************
  40. * Implementation Classes
  41. ****************************************************************************/
  42. #if defined(__cplusplus)
  43. namespace NXWidgets
  44. {
  45. class INxWindow;
  46. class CNxWidget;
  47. /**
  48. * Class providing a top-level widget and an interface to the CWidgetControl
  49. * widget hierarchy.
  50. *
  51. * There are three instances that represent an NX window from the
  52. * perspective of NXWidgets.
  53. *
  54. * - There is one widget control instance per NX window,
  55. * - One CCallback instance per window,
  56. * - One window instance.
  57. *
  58. * There a various kinds of of window instances, but each inherits
  59. * (1) CCallback and dispatches the Windows callbacks and (2) INxWindow
  60. * that describes the common window behavior.
  61. */
  62. class CWidgetControl
  63. {
  64. protected:
  65. /**
  66. * Structure holding the status of the Mouse or Touchscreen. There must
  67. * be one instance of this structure per window instance. The
  68. * content of this structure is update by the CGraphicsPort on each
  69. * NX mouse callback
  70. */
  71. #ifdef CONFIG_NX_XYINPUT
  72. struct SXYInput
  73. {
  74. // A touchscreen has no buttons. However, the convention is that
  75. // touchscreen contacts are reported with the LEFT button pressed.
  76. // The loss of contct is reported with no buttons pressed.
  77. #if 0 // Center and right buttons are not used
  78. // But only a mouse has center and right buttons
  79. uint16_t leftPressed : 1; /**< Left button pressed (or
  80. touchscreen contact) */
  81. uint16_t centerPressed : 1; /**< Center button pressed (not
  82. used with touchscreen) */
  83. uint16_t rightPressed : 1; /**< Right button pressed (not
  84. used with touchscreen) */
  85. uint16_t leftHeld : 1; /**< Left button held down (or
  86. touchscreen contact) */
  87. uint16_t centerHeld : 1; /**< Center button held down
  88. (not used with touchscreen) */
  89. uint16_t rightHeld : 1; /**< Right button held down
  90. (not used with touchscreen) */
  91. uint16_t leftDrag : 1; /**< Left button held down (or
  92. touchscreen contact) */
  93. uint16_t centerDrag : 1; /**< Center button held down (or
  94. touchscreen contact) */
  95. uint16_t rightDrag : 1; /**< Right button held down (or
  96. touchscreen contact) */
  97. uint16_t leftReleased : 1; /**< Left button release (or
  98. loss of touchscreen contact) */
  99. uint16_t centerReleased : 1; /**< Center button release (or
  100. loss of touchscreen contact) */
  101. uint16_t rightReleased : 1; /**< Right button release (or
  102. loss of touchscreen contact) */
  103. uint16_t doubleClick : 1; /**< Left button double click */
  104. uint16_t unused : 3; /**< Padding bits */
  105. #else
  106. uint8_t leftPressed : 1; /**< Left button pressed (or
  107. touchscreen contact) */
  108. uint8_t leftHeld : 1; /**< Left button held down (or
  109. touchscreen contact) */
  110. uint8_t leftDrag : 1; /**< Left button held down (or
  111. touchscreen contact) */
  112. uint8_t leftReleased : 1; /**< Left button release (or
  113. loss of touchscreen contact) */
  114. uint8_t doubleClick : 1; /**< Left button double click */
  115. uint8_t unused : 3; /**< Padding bits */
  116. #endif
  117. // These are attributes common to both touchscreen and mouse input devices
  118. nxgl_coord_t x; /**< Current X coordinate of
  119. the mouse/touch */
  120. nxgl_coord_t y; /**< Current Y coordinate of
  121. the mouse/touch */
  122. nxgl_coord_t lastX; /**< X coordinate of the mouse
  123. at the previous poll */
  124. nxgl_coord_t lastY; /**< Y coordinate of the mouse
  125. at the previous poll */
  126. struct timespec leftPressTime; /**< Time the left button was
  127. pressed */
  128. struct timespec leftReleaseTime; /**< Time the left button was
  129. released */
  130. };
  131. #endif
  132. /**
  133. * State data
  134. */
  135. CGraphicsPort *m_port; /**< The graphics port
  136. that is used for
  137. drawing on this window */
  138. TNxArray<CNxWidget*> m_deleteQueue; /**< Array of widgets
  139. awaiting deletion. */
  140. TNxArray<CNxWidget*> m_widgets; /**< List of controlled
  141. widgets. */
  142. volatile bool m_haveGeometry; /**< True: indicates that we
  143. have valid geometry data. */
  144. #ifdef CONFIG_NXWIDGET_EVENTWAIT
  145. bool m_waiting; /**< True: External logic waiting for
  146. window event */
  147. sem_t m_waitSem; /**< External loops waits for
  148. events on this semaphore */
  149. #endif
  150. /**
  151. * I/O
  152. */
  153. #ifdef CONFIG_NX_XYINPUT
  154. struct SXYInput m_xyinput; /**< Current XY input
  155. device state */
  156. #endif
  157. CNxWidget *m_clickedWidget; /**< Pointer to the widget
  158. that is clicked. */
  159. CNxWidget *m_focusedWidget; /**< Pointer to the widget
  160. that received keyboard
  161. input. */
  162. uint8_t m_kbdbuf[CONFIG_NXWIDGETS_KBDBUFFER_SIZE];
  163. uint8_t m_nCh; /**< Number of buffered
  164. keyboard characters */
  165. uint8_t m_controls[CONFIG_NXWIDGETS_CURSORCONTROL_SIZE];
  166. uint8_t m_nCc; /**< Number of buffered
  167. cursor controls */
  168. /**
  169. * The following were picked off from the position callback.
  170. */
  171. NXHANDLE m_hWindow; /**< Handle to the NX window */
  172. struct nxgl_size_s m_size; /**< Size of the window */
  173. struct nxgl_point_s m_pos; /**< Position in display space */
  174. struct nxgl_rect_s m_bounds; /**< Size of the display */
  175. sem_t m_geoSem; /**< Posted when geometry is valid */
  176. sem_t m_boundsSem; /**< Posted when bounds are valid */
  177. CWindowEventHandlerList m_eventHandlers; /**< List of event handlers. */
  178. /**
  179. * Style
  180. */
  181. CWidgetStyle m_style; /**< Default style used by all
  182. widgets in the window. */
  183. /**
  184. * Copy a widget style
  185. *
  186. * @param dest The destination style
  187. * @param src The source to use
  188. */
  189. void copyWidgetStyle(CWidgetStyle *dest, const CWidgetStyle *src);
  190. /**
  191. * Return the elapsed time in millisconds
  192. *
  193. * @param startTime A time in the past from which to compute the elapsed time.
  194. * @return The elapsed time since startTime
  195. */
  196. uint32_t elapsedTime(FAR const struct timespec *startTime);
  197. /**
  198. * Pass clicks to the widget hierarchy. Closes the context menu if
  199. * the clicked widget is not the context menu. If a single widget
  200. * is supplied, only that widget is sent the click.
  201. *
  202. * @param x Click xcoordinate.
  203. * @param y Click ycoordinate.
  204. * @param widget. Specific widget to poll. Use NULL to run the
  205. * all widgets in the window.
  206. * @return True means an interesting mouse event occurred
  207. */
  208. bool handleLeftClick(nxgl_coord_t x, nxgl_coord_t y, CNxWidget *widget);
  209. /**
  210. * Get the index of the specified controlled widget.
  211. *
  212. * @param widget The widget to get the index of.
  213. * @return The index of the widget. -1 if the widget is not found.
  214. */
  215. const int getWidgetIndex(const CNxWidget *widget) const;
  216. /**
  217. * Delete any widgets in the deletion queue.
  218. */
  219. void processDeleteQueue(void);
  220. /**
  221. * Process mouse/touchscreen events and send throughout the hierarchy.
  222. *
  223. * @param widget. Specific widget to poll. Use NULL to run the
  224. * all widgets in the window.
  225. * @return True means a mouse event occurred
  226. */
  227. bool pollMouseEvents(CNxWidget* widget);
  228. /**
  229. * Process keypad events and send throughout the hierarchy.
  230. *
  231. * @return True means a keyboard event occurred
  232. */
  233. bool pollKeyboardEvents(void);
  234. /**
  235. * Process cursor control events and send throughout the hierarchy.
  236. *
  237. * @return True means a cursor control event was processes
  238. */
  239. bool pollCursorControlEvents(void);
  240. #ifdef CONFIG_NXWIDGET_EVENTWAIT
  241. /**
  242. * Wake up and external logic that is waiting for a window event.
  243. */
  244. void postWindowEvent(void);
  245. #endif
  246. /**
  247. * Take the geometry semaphore (handling signal interruptions)
  248. */
  249. void takeGeoSem(void);
  250. /**
  251. * Give the geometry semaphore
  252. */
  253. inline void giveGeoSem(void)
  254. {
  255. sem_post(&m_geoSem);
  256. }
  257. /**
  258. * Check if geometry data is available. If not, [re-]request the
  259. * geometry data and wait for it to become valid.
  260. * CAREFUL: This assumes that if we already have geometry data, then
  261. * it is valid. This might not be true if the size position was
  262. * recently changed.
  263. */
  264. void waitGeoData(void);
  265. /**
  266. * Take the bounds semaphore (handling signal interruptions)
  267. */
  268. void takeBoundsSem(void);
  269. /**
  270. * Give the bounds semaphore
  271. */
  272. inline void giveBoundsSem(void)
  273. {
  274. sem_post(&m_boundsSem);
  275. }
  276. /**
  277. * Wait for bounds data
  278. */
  279. inline void waitBoundsData(void)
  280. {
  281. takeBoundsSem();
  282. giveBoundsSem();
  283. }
  284. #ifdef CONFIG_NX_XYINPUT
  285. /**
  286. * Clear all mouse events
  287. */
  288. void clearMouseEvents(void);
  289. #endif
  290. public:
  291. /**
  292. * Constructor
  293. *
  294. * @param style The default style that all widgets on this display
  295. * should use. If this is not specified, the widget will use the
  296. * values stored in the defaultCWidgetStyle object.
  297. */
  298. CWidgetControl(FAR const CWidgetStyle *style = (const CWidgetStyle *)NULL);
  299. /**
  300. * Destructor.
  301. */
  302. virtual ~CWidgetControl(void);
  303. #ifdef CONFIG_NXWIDGET_EVENTWAIT
  304. /**
  305. * Wait for an interesting window event to occur (like a mouse or keyboard event)
  306. * Caller's should exercise care to assure that the test for waiting and this
  307. * call are "atomic" .. perhaps by locking the scheduler like:
  308. *
  309. * sched_lock();
  310. * <check for events>
  311. * if (<no interesting events>)
  312. * {
  313. * window->waitForWindowEvent();
  314. * }
  315. * sched_unlock();
  316. */
  317. void waitForWindowEvent(void);
  318. #endif
  319. #ifdef CONFIG_NXWIDGET_EVENTWAIT
  320. /**
  321. * Is external logic awaiting for a window event?
  322. *
  323. * @return True if the widget if external logic is waiting.
  324. */
  325. inline const bool isWaiting(void) const
  326. {
  327. return m_waiting;
  328. }
  329. #endif
  330. /**
  331. * Run all code that needs to take place on a periodic basis.
  332. * This method normally called externally... either periodically
  333. * or when a window event is detected. If CONFIG_NXWIDGET_EVENTWAIT
  334. * is defined, then external logic want call waitWindow event and
  335. * when awakened, they should call this function. As an example:
  336. *
  337. * for (;;)
  338. * {
  339. * sched_lock(); // Make the sequence atomic
  340. * if (!window->pollEvents(0))
  341. * {
  342. * window->waitWindowEvent();
  343. * }
  344. * sched_unlock();
  345. * }
  346. *
  347. * This method is just a wrapper simply calls the followi.
  348. *
  349. * processDeleteQueue()
  350. * pollMouseEvents(widget)
  351. * pollKeyboardEvents()
  352. * pollCursorControlEvents()
  353. *
  354. * @param widget. Specific widget to poll. Use NULL to run through
  355. * of the widgets in the window.
  356. * @return True means some interesting event occurred
  357. */
  358. bool pollEvents(CNxWidget *widget = (CNxWidget *)NULL);
  359. /**
  360. * Swaps the depth of the supplied widget.
  361. * This function presumes that all child widgets are screens.
  362. *
  363. * @param widget The widget to be depth-swapped.
  364. * @return True if the depth swap occurred.
  365. */
  366. bool swapWidgetDepth(CNxWidget *widget);
  367. /**
  368. * Add another widget to be managed by this control instance
  369. *
  370. * @param widget The widget to be controlled.
  371. */
  372. inline void addControlledWidget(CNxWidget* widget)
  373. {
  374. m_widgets.push_back(widget);
  375. }
  376. /**
  377. * Remove a controlled widget
  378. *
  379. * @param widget The widget to be removed
  380. */
  381. void removeControlledWidget(CNxWidget* widget);
  382. /**
  383. * Get the number of controlled widgets.
  384. *
  385. * @return The number of child widgets belonging to this widget.
  386. */
  387. inline const int getControlledWidgetCount(void) const
  388. {
  389. return m_widgets.size();
  390. }
  391. /**
  392. * Add a widget to the list of widgets to be deleted.
  393. * Must never be called by anything other than the framework itself.
  394. *
  395. * @param widget The widget to add to the delete queue.
  396. */
  397. void addToDeleteQueue(CNxWidget *widget);
  398. /**
  399. * Set the clicked widget pointer. Note that this should not be
  400. * called by code other than within the CWidgetControl library itself.
  401. *
  402. * @param widget The new clicked widget.
  403. */
  404. void setClickedWidget(CNxWidget *widget);
  405. /**
  406. * Get the clicked widget pointer.
  407. *
  408. * @return Pointer to the clicked widget.
  409. */
  410. inline CNxWidget *getClickedWidget(void)
  411. {
  412. return m_clickedWidget;
  413. }
  414. /**
  415. * Set the focused widget that will receive keyboard input.
  416. *
  417. * @param widget The new focused widget.
  418. */
  419. void setFocusedWidget(CNxWidget *widget);
  420. /**
  421. * Reset the focused widget so that it will no longer receive keyboard input.
  422. *
  423. * @param widget The new focused widget.
  424. */
  425. void clearFocusedWidget(CNxWidget *widget)
  426. {
  427. if (widget == m_focusedWidget)
  428. {
  429. m_focusedWidget = (CNxWidget *)NULL;
  430. }
  431. }
  432. /**
  433. * Get the focused widget pointer.
  434. *
  435. * @return Pointer to the focused widget.
  436. */
  437. inline CNxWidget *getFocusedWidget(void)
  438. {
  439. return m_focusedWidget;
  440. }
  441. /**
  442. * Check for the occurrence of a double click.
  443. *
  444. * @return Pointer to the clicked widget.
  445. */
  446. inline bool doubleClick(void)
  447. {
  448. #ifdef CONFIG_NX_XYINPUT
  449. return (bool)m_xyinput.doubleClick;
  450. #else
  451. return false;
  452. #endif
  453. }
  454. /**
  455. * Get the default widget style for this window.
  456. *
  457. * @param style. The location to return the widget's style
  458. */
  459. inline void getWidgetStyle(CWidgetStyle *style)
  460. {
  461. copyWidgetStyle(style, &m_style);
  462. }
  463. /**
  464. * Set the default widget style for this window.
  465. *
  466. * @param style. The new widget style to copy.
  467. */
  468. inline void setWidgetStyle(const CWidgetStyle *style)
  469. {
  470. copyWidgetStyle(&m_style, style);
  471. }
  472. /**
  473. * These remaining methods are used by the CCallback instance to
  474. * provide notifications of certain events.
  475. */
  476. /**
  477. * This event will occur when the position or size of the underlying
  478. * window occurs.
  479. *
  480. * @param hWindow The window handle that should be used to communicate
  481. * with the window
  482. * @param pos The position of the window in the physical device space.
  483. * @param size The size of the window.
  484. * @param bounds The size of the underlying display (pixels x rows)
  485. */
  486. void geometryEvent(NXHANDLE hWindow,
  487. const struct nxgl_size_s *size,
  488. const struct nxgl_point_s *pos,
  489. const struct nxgl_rect_s *bounds);
  490. /**
  491. * This event will occur when the a portion of the window that was
  492. * previously obscured is now exposed.
  493. *
  494. * @param nxRect The region in the window that must be redrawn.
  495. * @param more True means that more re-draw requests will follow
  496. */
  497. void redrawEvent(FAR const struct nxgl_rect_s *nxRect, bool more);
  498. /**
  499. * This event means that new mouse data is available for the window.
  500. *
  501. * @param pos The (x,y) position of the mouse.
  502. * @param buttons See NX_MOUSE_* definitions.
  503. */
  504. void newMouseEvent(FAR const struct nxgl_point_s *pos, uint8_t buttons);
  505. #ifdef CONFIG_NX_KBD
  506. /**
  507. * This event means that keyboard/keypad data is available for the window.
  508. *
  509. * @param nCh The number of characters that are available in pStr[].
  510. * @param pStr The array of characters.
  511. */
  512. void newKeyboardEvent(uint8_t nCh, FAR const uint8_t *pStr);
  513. #endif
  514. /**
  515. * This event is the response from nx_block (or nxtk_block). Those
  516. * blocking interfaces are used to assure that no further messages are
  517. * directed to the window. Receipt of the blocked callback signifies
  518. * that (1) there are no further pending events and (2) that the
  519. * window is now 'defunct' and will receive no further events.
  520. *
  521. * This event supports coordinated destruction of a window in multi-
  522. * user mode. In multi-use mode, the client window logic must stay
  523. * intact until all of the queued callbacks are processed. Then the
  524. * window may be safely closed. Closing the window prior with pending
  525. * callbacks can lead to bad behavior when the callback is executed.
  526. *
  527. * @param arg - User provided argument (see nx_block or nxtk_block)
  528. */
  529. inline void windowBlocked(FAR void *arg)
  530. {
  531. m_eventHandlers.raiseBlockedEvent(arg);
  532. }
  533. /**
  534. * This event means that cursor control data is available for the window.
  535. *
  536. * @param cursorControl The cursor control code received.
  537. */
  538. void newCursorControlEvent(ECursorControl cursorControl);
  539. /**
  540. * Get the window handle reported on the first position callback.
  541. *
  542. * @return This function returns the window handle.
  543. */
  544. inline NXHANDLE getWindowHandle(void)
  545. {
  546. // Verify that we have the window handle
  547. if (m_hWindow == (NXHANDLE)0)
  548. {
  549. // The window handle is saved at the same time as the bounds
  550. waitBoundsData();
  551. }
  552. return m_hWindow;
  553. }
  554. /**
  555. * Get the window bounding box in physical display coordinates. This
  556. * method may need to wait until bounds data is available.
  557. *
  558. * @return This function returns the window handle.
  559. */
  560. inline CRect getWindowBoundingBox(void)
  561. {
  562. waitBoundsData();
  563. return CRect(&m_bounds);
  564. }
  565. inline void getWindowBoundingBox(FAR struct nxgl_rect_s *bounds)
  566. {
  567. waitBoundsData();
  568. nxgl_rectcopy(bounds, &m_bounds);
  569. }
  570. /**
  571. * Get the position of the window (as reported by the last NX callback). This
  572. * method may need to wait until geometry data is available.
  573. *
  574. * @return The position.
  575. */
  576. inline bool getWindowPosition(FAR struct nxgl_point_s *pos)
  577. {
  578. // Check if we already have geometry data available. CAREFUL: This
  579. // might refer to OLD geometry data if the position was recently
  580. // changed!
  581. waitGeoData();
  582. pos->x = m_pos.x;
  583. pos->y = m_pos.y;
  584. return true;
  585. }
  586. /**
  587. * Get the size of the window (as reported by the last NX callback). This
  588. * method may need to wait until geometry data is available.
  589. *
  590. * @return The size.
  591. */
  592. inline bool getWindowSize(FAR struct nxgl_size_s *size)
  593. {
  594. // Check if we already have geometry data available. CAREFUL: This
  595. // might refer to OLD geometry data if the position was recently
  596. // changed!
  597. waitGeoData();
  598. size->h = m_size.h;
  599. size->w = m_size.w;
  600. return true;
  601. }
  602. /**
  603. * Get the width of the window (as reported by the last NX callback). This
  604. * method may need to wait until geometry data is available.
  605. *
  606. * @return The size.
  607. */
  608. inline nxgl_coord_t getWindowWidth(void)
  609. {
  610. // Check if we already have geometry data available. CAREFUL: This
  611. // might refer to OLD geometry data if the position was recently
  612. // changed!
  613. waitGeoData();
  614. return m_size.w;
  615. }
  616. /**
  617. * Get the height of the window (as reported by the last NX callback). This
  618. * method may need to wait until geometry data is available.
  619. *
  620. * @return The size.
  621. */
  622. inline nxgl_coord_t getWindowHeight(void)
  623. {
  624. // Check if we already have geometry data available. CAREFUL: This
  625. // might refer to OLD geometry data if the position was recently
  626. // changed!
  627. waitGeoData();
  628. return m_size.h;
  629. }
  630. /**
  631. * The creation sequence is:
  632. *
  633. * 1) Create a dumb CWigetControl instance
  634. * 2) Pass the dumb CWidgetControl instance to the window constructor
  635. * that inherits from INxWindow.
  636. * 3) The call this method with the static_cast to INxWindow to,
  637. * finally, create the CGraphicsPort for this window.
  638. * 4) After that, the fully smartend CWidgetControl instance can
  639. * be used to generate additional widgets.
  640. *
  641. * @param window The instance of INxWindow needed to construct the
  642. * CGraphicsPort instance
  643. */
  644. bool createGraphicsPort(INxWindow *window);
  645. /**
  646. * Get the CGraphicsPort instance for drawing on this window
  647. */
  648. inline CGraphicsPort *getGraphicsPort(void)
  649. {
  650. return m_port;
  651. }
  652. /**
  653. * Adds a window event handler. The window handler will receive
  654. * notification all NX events received by this window\.
  655. *
  656. * @param eventHandler A pointer to the event handler.
  657. */
  658. inline void addWindowEventHandler(CWindowEventHandler *eventHandler)
  659. {
  660. m_eventHandlers.addWindowEventHandler(eventHandler);
  661. }
  662. /**
  663. * Remove a window event handler.
  664. *
  665. * @param eventHandler A pointer to the event handler to remove.
  666. */
  667. inline void removeWindowEventHandler(CWindowEventHandler *eventHandler)
  668. {
  669. m_eventHandlers.removeWindowEventHandler(eventHandler);
  670. }
  671. };
  672. }
  673. #endif // __cplusplus
  674. #endif // __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CWIDGETCONTROLT_HXX