hot.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. //////////////////////////////////////////////////////////////////////////////
  19. //
  20. // Hot.h
  21. //
  22. // History:
  23. // 01/18/97 JMI Started tracking history of this file.
  24. // Added version of Do() that takes an RInputEvent*.
  25. //
  26. // 01/21/97 JMI The main Do() now returns the priority of the RHot that
  27. // got the event. Now, Do(RInputEvent* pie) can set
  28. // pie->sUsed = TRUE discriminantly.
  29. //
  30. // 01/22/97 JMI Added DoChildren() to process an event for this hotbox's
  31. // children with two overloads (sPosX,sPosY,sEvent & pie).
  32. //
  33. // 01/23/97 JMI Got rid of the whole implied root with the static lists.
  34. // Now each hotbox can service its children via a Do() call.
  35. // More of a typical child-parent relationship. Note that
  36. // this got rid of the Do(short sUseQueue) static that
  37. // dequeued or polled events, but it was getting stale any-
  38. // ways.
  39. //
  40. // 01/26/97 JMI Changed callbacks' first parms to RHot* instead of ULONG.
  41. //
  42. // 03/19/97 JMI Added InputEventCall and made Do(pie) the main RHot
  43. // interface.
  44. // Also, added new constructor overload to handle new call-
  45. // back type.
  46. //
  47. //////////////////////////////////////////////////////////////////////////////
  48. //
  49. // See CPP for description.
  50. //
  51. //////////////////////////////////////////////////////////////////////////////
  52. #ifndef HOT_H
  53. #define HOT_H
  54. // Orange /////////////////////////////////////////////////////////////////////
  55. // If PATHS_IN_INCLUDES macro is defined, we can utilize relative
  56. // paths to a header file. In this case we generally go off of our
  57. // RSPiX root directory. System.h MUST be included before this macro
  58. // is evaluated. System.h is the header that, based on the current
  59. // platform (or more so in this case on the compiler), defines
  60. // PATHS_IN_INCLUDES. Blue.h includes system.h so you can include that
  61. // instead.
  62. #ifdef PATHS_IN_INCLUDES
  63. #include "GREEN/InputEvent/InputEvent.h"
  64. #include "ORANGE/CDT/slist.h"
  65. #include "ORANGE/CDT/List.h"
  66. #else
  67. #include "slist.h"
  68. #include "List.h"
  69. #include "InputEvent.h"
  70. #endif // PATHS_IN_INCLUDES
  71. ///////////////////////////////////////////////////////////////////////////////
  72. // Macros.
  73. ///////////////////////////////////////////////////////////////////////////////
  74. // This, when used in place of a priority, indicates that the item has no
  75. // priority (i.e., it is to be considered non-prioritized).
  76. #define RHOT_NO_PRIORITY ( (short)0x8000)
  77. ///////////////////////////////////////////////////////////////////////////////
  78. // Types.
  79. ///////////////////////////////////////////////////////////////////////////////
  80. class RHot
  81. {
  82. public: // Typedefs.
  83. typedef void (*REventCall)( // Returns nothing.
  84. RHot* phot, // Ptr to the RHot that generated the
  85. // callback.
  86. short sEvent); // Event that occurred.
  87. // Uses blue.h macros (RSP_MB?_*).
  88. typedef void (*REventPosCall)( // Returns nothing.
  89. RHot* phot, // Ptr to the RHot that generated the
  90. // callback.
  91. short sEvent, // Event that occurred.
  92. // Uses blue.h macros (RSP_MB?_*).
  93. short sPosX, // Mouse x position at button event
  94. // relative to hotbox's upper, left
  95. // corner.
  96. short sPosY); // Mouse y position at button event
  97. // relative to hotbox's upper, left
  98. // corner.
  99. typedef void (*InputEventCall)( // Returns nothing.
  100. RHot* phot, // In: Ptr to RHot that generated the
  101. // callback.
  102. RInputEvent* pie); // In: Ptr to input event that generated
  103. // the callback. Note that the coordinates
  104. // of this event are relative to hotbox's
  105. // upper, left corner.
  106. // Out: Set members as you see fit. Note
  107. // that changes to pie->sPosX,sPosY should
  108. // be made relative to this RHot's upper,
  109. // left corner. This can affect further
  110. // RHot callbacks and will certainly affect
  111. // the RInputEvent passed to RHot::Do().
  112. typedef RSList <RHot, short> SListHots; // Sorted list of RHots.
  113. typedef RList <RHot> ListHots; // List of RHots.
  114. public:
  115. // Default constructor.
  116. RHot();
  117. // Constructura Especial that sets some intial values.
  118. RHot(
  119. short sX, // X position of new hotbox.
  120. short sY, // Y position of new hotbox.
  121. short sW, // Width of new hotbox.
  122. short sH, // Height of new hotbox.
  123. REventCall fnEventCall = NULL, // Callback on mouse event.
  124. short sActive = FALSE, // Initially active, if TRUE.
  125. ULONG ulUser = 0, // User value.
  126. short sPriority = RHOT_NO_PRIORITY);// Priority. Default == non-prioritized.
  127. // Constructura Especial el Segundario or something that sets some
  128. // intial values.
  129. RHot(
  130. short sX, // X position of new hotbox.
  131. short sY, // Y position of new hotbox.
  132. short sW, // Width of new hotbox.
  133. short sH, // Height of new hotbox.
  134. REventPosCall fnEventPosCall, // Callback on mouse event.
  135. short sActive = FALSE, // Initially active, if TRUE.
  136. ULONG ulUser = 0, // User value.
  137. short sPriority = RHOT_NO_PRIORITY);// Priority. Default == non-prioritized.
  138. // Constructura Especial el Tres or something that sets some
  139. // intial values.
  140. RHot(
  141. short sX, // X position of new hotbox.
  142. short sY, // Y position of new hotbox.
  143. short sW, // Width of new hotbox.
  144. short sH, // Height of new hotbox.
  145. InputEventCall fnInputEventCall, // Callback on mouse event.
  146. short sActive = FALSE, // Initially active, if TRUE.
  147. ULONG ulUser = 0, // User value.
  148. short sPriority = RHOT_NO_PRIORITY);// Priority. Default == non-prioritized.
  149. // Destructor.
  150. ~RHot();
  151. public: // Manipulations.
  152. // Activates/Deactivates hotbox. When active, the hotbox
  153. // calls the callback(s) when mouse events occur within its
  154. // area.
  155. void SetActive( // Returns nothing.
  156. short sActive); // TRUE to activate, FALSE otherwise.
  157. // Sets the priority of this hotbox.
  158. // If hotbox is already active, it is repositioned in the prioritized
  159. // list so that the new priorty is recognized.
  160. // See CPP comment header in regards to specifics of this value.
  161. void SetPriority( // Returns nothing.
  162. short sPriority); // New priority for hotbox. Lower value
  163. // equals higher priority.
  164. // RHOT_NO_PRIORITY(default) indicates non-prioritized.
  165. // Sets this hotbox's parent to the specified hotbox.
  166. // This has the effect of having the hotbox scanned relative to the
  167. // parent and only within the area of the parent.
  168. void SetParent( // Returns nothing.
  169. RHot* photParent); // Hotbox to be parent of this hotbox or NULL
  170. // for none.
  171. // Activates/Deactivates capturing for this hotbox.
  172. // When capturing is active, this hotbox always receives
  173. // events. Sort of a cursor event capture mode.
  174. void SetCapture( // Returns nothing.
  175. short sActive); // TRUE to activate, FALSE otherwise.
  176. // Processes a single event for all child hotboxes.
  177. // Non mouse events are ignored.
  178. // It is now up to the callback to check whether the input event
  179. // is used and decide whether to utilize the event.
  180. // Recurses on children.
  181. // This is called by the other Do().
  182. short Do( // Returns priority of item that used event
  183. // or RHOT_NO_PRIORITY if none.
  184. RInputEvent* pie); // In: Most recent user input event.
  185. // Out: Depends on callbacks. Generally,
  186. // pie->sUsed = TRUE, if used.
  187. // Processes a single event for all child hotboxes.
  188. // Interface to above function that simply accepts Blue mouse event data.
  189. // NOTE: If you use this Do() the RInputEvent passed to callbacks that
  190. // take such input, will have its lTime, sButtons, and sUsed set to 0.
  191. // If you do not use that type of callback, then there's no problem.
  192. // This is purely provided for backward compatibility.
  193. short Do( // Returns priority of item that used event
  194. // or RHOT_NO_PRIORITY if none.
  195. short sPosX, // In: X position for event.
  196. short sPosY, // In: Y position for event.
  197. short sEvent) // In: A RSPiX Blue mouse button event
  198. // (see <Mac/Win/Etc>Blue.h).
  199. {
  200. // Create an event.
  201. RInputEvent ie;
  202. ie.type = RInputEvent::Mouse;
  203. ie.sPosX = sPosX;
  204. ie.sPosY = sPosY;
  205. ie.sButtons = 0;
  206. ie.sEvent = sEvent;
  207. ie.lTime = 0;
  208. ie.sUsed = FALSE;
  209. return Do(&ie);
  210. }
  211. public: // Querries.
  212. short IsActive(void) // Returns TRUE if active, FALSE otherwise.
  213. {
  214. return m_sActive;
  215. }
  216. short IsCapturing(void) // Returns TRUE if capturing events, FALSE
  217. // otherwise.
  218. {
  219. return m_sCapture;
  220. }
  221. // Get the child position equivalent coordinates.
  222. void GetChildPos( // Returns nothing.
  223. short* psX, // In: Top-level position.
  224. // Out: Child position.
  225. short* psY); // In: Top-level position.
  226. // Out: Child position.
  227. // Get the top position equivalent coordinates.
  228. void GetTopPos( // Returns nothing.
  229. short* psX, // In: Child position.
  230. // Out: Top-level position.
  231. short* psY); // In: Child position.
  232. // Out: Top-level position.
  233. RHot* GetParent(void) // Returns ptr to RHot that is parent to this Rhot.
  234. {
  235. return m_photParent;
  236. }
  237. public: // Static functions.
  238. public: // Internal public functions.
  239. protected: // Internal functions.
  240. // Resets all members of this RHot.
  241. // Returns nothing.
  242. void Init(void);
  243. // Gets the list appropriate for this hotbox.
  244. ListHots* GetCaptureList(void); // Returns Capture list appropriate for this hotbox.
  245. public: // Static members.
  246. protected: // Instantiable members.
  247. short m_sActive; // TRUE if active, FALSE otherwise.
  248. short m_sCapture; // TRUE, if capturing events.
  249. short m_sPriority; // Priority for hotbox. Lower value
  250. // equals closer to front (higher priority).
  251. // RHOT_NO_PRIORITY(default) indicates non-prioritized.
  252. // See CPP comment header in regards to specifics
  253. // of this value.
  254. RHot* m_photParent; // Pointer to parent RHot or NULL, if none.
  255. public: // To be modified by the User.
  256. short m_sX; // The x-coordinate of this hotbox relative to
  257. // its parent.
  258. short m_sY; // The y-coordinate of this hotbox relative to
  259. // its parent.
  260. short m_sW; // The width of this hotbox.
  261. short m_sH; // The height of this hotbox.
  262. REventCall m_ecUser; // User callback on button events.
  263. // All callbacks can be used simultaneously.
  264. REventPosCall m_epcUser; // User callback on button events. Includes
  265. // mouse position.
  266. // All callbacks can be used simultaneously.
  267. InputEventCall m_iecUser; // User callback on input events. Includes
  268. // a full RInputEvent.
  269. // All callbacks can be used simultaneously.
  270. ULONG m_ulUser; // User value passed to callbacks.
  271. SListHots m_slistActiveChildren; // List of active child RHots.
  272. ListHots m_listChildren; // List of all child RHots.
  273. // List of hots that always receive events.
  274. ListHots m_listCapturing; // List of all capturing child RHots
  275. // and self, if capturing.
  276. public: // Static members.
  277. };
  278. #endif // HOT_H
  279. //////////////////////////////////////////////////////////////////////////////
  280. // EOF
  281. //////////////////////////////////////////////////////////////////////////////