twm4nx_events.hxx 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /////////////////////////////////////////////////////////////////////////////
  2. // apps/include/graphics/twm4nx/twm4nx_events.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_TWM4NX_TWM4NX_EVENTS_HXX
  21. #define __APPS_INCLUDE_GRAPHICS_TWM4NX_TWM4NX_EVENTS_HXX
  22. /////////////////////////////////////////////////////////////////////////////
  23. // Included Files
  24. /////////////////////////////////////////////////////////////////////////////
  25. #include <nuttx/config.h>
  26. #include <cstdint>
  27. #include <cstdbool>
  28. #include <nuttx/nx/nxglib.h>
  29. /////////////////////////////////////////////////////////////////////////////
  30. // Preprocessor Definitions
  31. /////////////////////////////////////////////////////////////////////////////
  32. // struct SRedrawEventMsg is the largest message as of this writing
  33. #define MAX_EVENT_MSGSIZE sizeof(struct SRedrawEventMsg)
  34. #define MAX_EVENT_PAYLOAD (MAX_EVENT_MSGSIZE - sizeof(uint16_t))
  35. #define EVENT_CRITICAL 0x0800
  36. #define EVENT_RECIPIENT(id) ((id) & EVENT_RECIPIENT_MASK)
  37. #define EVENT_ISCRITICAL(id) (((id) & EVENT_CRITICAL) != 0)
  38. /////////////////////////////////////////////////////////////////////////////
  39. // WidgetEvent
  40. /////////////////////////////////////////////////////////////////////////////
  41. namespace NXWidgets
  42. {
  43. class CNxTkWindow; // Forward reference
  44. }
  45. namespace Twm4Nx
  46. {
  47. class CWindow; // Forward reference
  48. class CWindowEvent; // Forward reference
  49. class CTwm4NxEvent; // Forward reference
  50. class CTwm4Nx; // Forward reference
  51. ///////////////////////////////////////////////////////////////////////////
  52. // Public Types
  53. ///////////////////////////////////////////////////////////////////////////
  54. /**
  55. * Event ID format:
  56. *
  57. * rrrr nooo oooo oooo
  58. *
  59. * Bits 0-10: Opcode
  60. * Bit 11: Critical event (cannot be discarded*)
  61. * Bits 12-15: Recipient of the event
  62. *
  63. * * During a window resize operation, all events are ignored except for
  64. * those that are marked critical.
  65. */
  66. /**
  67. * This enumeration identifies the recipient of the event
  68. */
  69. enum EEventRecipient
  70. {
  71. EVENT_RECIPIENT_SYSTEM = 0x0000, /**< Twm4Nx system event */
  72. EVENT_RECIPIENT_BACKGROUND = 0x1000, /**< Background window event */
  73. EVENT_RECIPIENT_ICONWIDGET = 0x2000, /**< Icon Widget event */
  74. EVENT_RECIPIENT_ICONMGR = 0x3000, /**< Icon Manager event */
  75. EVENT_RECIPIENT_MENU = 0x4000, /**< Menu related event */
  76. EVENT_RECIPIENT_MAINMENU = 0x5000, /**< Menu related event */
  77. EVENT_RECIPIENT_WINDOW = 0x6000, /**< Window related event */
  78. EVENT_RECIPIENT_TOOLBAR = 0x7000, /**< Toolbar related event */
  79. EVENT_RECIPIENT_BORDER = 0x8000, /**< Window border related event */
  80. EVENT_RECIPIENT_RESIZE = 0x9000, /**< Window resize event */
  81. EVENT_RECIPIENT_APP = 0xa000, /**< App received event via CTwn4NxEvent */
  82. EVENT_RECIPIENT_MASK = 0xf000, /**< Used to isolate recipient */
  83. };
  84. /**
  85. * Specific events include the recipient as part of the event ID encoding.
  86. */
  87. enum EEventID
  88. {
  89. // Recipient == SYSTEM
  90. EVENT_SYSTEM_NOP = 0x0000, /**< Null event */
  91. EVENT_SYSTEM_ERROR = 0x0801, /**< Report system error */
  92. EVENT_SYSTEM_EXIT = 0x0802, /**< Terminate the Twm4Nx session */
  93. EVENT_SYSTEM_STARTUP = 0x0003, /**< Start an application */
  94. // Recipient == BACKGROUND
  95. EVENT_BACKGROUND_XYINPUT = 0x1000, /**< Poll for widget mouse/touch events */
  96. EVENT_BACKGROUND_REDRAW = 0x1801, /**< Redraw the background */
  97. // Recipient == ICONWIDGET
  98. EVENT_ICONWIDGET_GRAB = 0x2000, /**< Click on toolbar title */
  99. EVENT_ICONWIDGET_DRAG = 0x2001, /**< Drag window */
  100. EVENT_ICONWIDGET_UNGRAB = 0x2002, /**< Release click on toolbar */
  101. // Recipient == ICONMGR
  102. EVENT_ICONMGR_XYINPUT = 0x3000, /**< Poll for widget mouse/touch events */
  103. EVENT_ICONMGR_DEICONIFY = 0x3001, /**< De-iconify or raise the Icon Manager */
  104. // Recipient == MENU
  105. EVENT_MENU_XYINPUT = 0x4000, /**< Poll for widget mouse/touch events */
  106. EVENT_MENU_COMPLETE = 0x4001, /**< Menu selection complete */
  107. EVENT_MENU_SUBMENU = 0x4002, /**< Sub-menu selected */
  108. // Recipient == MAINMENU
  109. EVENT_MAINMENU_SELECT = 0x5000, /**< Main menu item selection */
  110. // Recipient == WINDOW
  111. EVENT_WINDOW_RAISE = 0x6000, /**< Raise window to the top of the hierarchy */
  112. EVENT_WINDOW_LOWER = 0x6001, /**< Lower window to the bottom of the hierarchy */
  113. EVENT_WINDOW_DEICONIFY = 0x6002, /**< De-iconify and raise window */
  114. EVENT_WINDOW_DRAG = 0x6003, /**< Drag window */
  115. EVENT_WINDOW_DELETE = 0x6804, /**< Delete window */
  116. EVENT_WINDOW_DESKTOP = 0x6005, /**< Show the desktop */
  117. // Recipient == TOOLBAR
  118. EVENT_TOOLBAR_XYINPUT = 0x7800, /**< Poll for widget mouse/touch events */
  119. EVENT_TOOLBAR_GRAB = 0x7001, /**< Click on title widget */
  120. EVENT_TOOLBAR_UNGRAB = 0x7002, /**< Release click on title widget */
  121. EVENT_TOOLBAR_MENU = 0x7003, /**< Toolbar menu button released */
  122. EVENT_TOOLBAR_MINIMIZE = 0x7004, /**< Toolbar minimize button released */
  123. EVENT_TOOLBAR_TERMINATE = 0x7005, /**< Toolbar delete button released */
  124. // Recipient == BORDER
  125. // Recipient == RESIZE
  126. EVENT_RESIZE_XYINPUT = 0x9800, /**< Poll for widget mouse/touch events */
  127. EVENT_RESIZE_BUTTON = 0x9801, /**< Start or stop a resize sequence */
  128. EVENT_RESIZE_MOVE = 0x9802, /**< Mouse movement during a resize sequence */
  129. EVENT_RESIZE_PAUSE = 0x9803, /**< Pause resize operation when unclicked */
  130. EVENT_RESIZE_RESUME = 0x9804, /**< Resume resize operation when re-clicked */
  131. EVENT_RESIZE_STOP = 0x9805, /**< End a resize sequence on second press */
  132. // Recipient == APP
  133. // All application defined events must (1) use recipient == EVENT_RECIPIENT_APP,
  134. // and (2) provide an instance of CTwm4NxEvent in the SEventMsg structure.
  135. };
  136. // Contexts for events. These basically identify the source of the event
  137. // message.
  138. enum EEventContext
  139. {
  140. EVENT_CONTEXT_WINDOW = 0,
  141. EVENT_CONTEXT_TOOLBAR,
  142. EVENT_CONTEXT_BACKGROUND,
  143. EVENT_CONTEXT_ICONWIDGET,
  144. EVENT_CONTEXT_ICONMGR,
  145. EVENT_CONTEXT_MENU,
  146. EVENT_CONTEXT_RESIZE,
  147. NUM_CONTEXTS
  148. };
  149. /**
  150. * This type represents a generic messages, particularly button press
  151. * or release events.
  152. */
  153. struct SEventMsg
  154. {
  155. // Common fields
  156. uint16_t eventID; /**< Encoded event ID */
  157. FAR void *obj; /**< Context specific reference */
  158. FAR void *handler; /**< Context specific handler */
  159. // Event-specific fields
  160. struct nxgl_point_s pos; /**< X/Y position */
  161. uint8_t context; /**< Button press context */
  162. };
  163. /**
  164. * This message form is used with CWindowEvent redraw commands
  165. */
  166. struct SRedrawEventMsg
  167. {
  168. // Common fields
  169. uint16_t eventID; /**< Encoded event ID */
  170. FAR void *obj; /**< Context specific reference */
  171. FAR void *handler; /**< Context specific handler */
  172. // Event-specific fields
  173. struct nxgl_rect_s rect; /**< Region to be redrawn */
  174. bool more; /**< True: More redraw requests will follow */
  175. };
  176. /**
  177. * This message form is used with CWindowEVent mouse/touchscreen
  178. * input events
  179. */
  180. struct SXyInputEventMsg
  181. {
  182. // Common fields
  183. uint16_t eventID; /**< Encoded event ID */
  184. FAR void *obj; /**< Context specific reference */
  185. FAR void *handler; /**< Context specific handler */
  186. // Event-specific fields
  187. struct nxgl_point_s pos; /**< X/Y position */
  188. uint8_t buttons; /**< Bit set of button presses */
  189. };
  190. /**
  191. * This message form of the message used by CWindowEvent for blocked and
  192. * keyboard input messages
  193. */
  194. struct SNxEventMsg
  195. {
  196. // Common fields
  197. uint16_t eventID; /**< Encoded event ID */
  198. FAR void *obj; /**< Context specific reference */
  199. FAR void *handler; /**< Context specific handler */
  200. // Event-specific fields
  201. FAR CWindowEvent *instance; /**< X/Y position */
  202. };
  203. }
  204. #endif // __APPS_INCLUDE_GRAPHICS_TWM4NX_TWM4NX_EVENTS_HXX