home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool.zip / OOL / source / xhandler.cpp < prev    next >
C/C++ Source or Header  |  1997-04-07  |  8KB  |  272 lines

  1. #include "XDragHdl.h"
  2. #include "XDragEvn.h"
  3. #include "XMousHdl.h"
  4. #include "XMousevn.h"
  5. #include "XWindow.h"
  6. #include "XContHdl.h"
  7. #include "XItmDHdl.h"
  8. #include "XBackHdl.h"
  9. #include "XStylHdl.h"
  10. #include "XTimer.h"
  11.  
  12. #include <stdlib.h>
  13.  
  14.  
  15. /*@
  16. @class XHandler
  17. @type overview
  18. @symbol _
  19. @remarks Events like mouse-moving, keyboard input) are typicaly send in the OOL in the form 
  20. of XEvent and derived classes. Except XControlEvent (see XWindow::DoControl()) this events
  21. must be caught with classes derived from XHandler, each of this handlers is corresponding
  22. to a special event-class, eg. to catch a XKeyboardEvent you need a XKeyboardHandler. <P>
  23. To catch these event you must attach the needed handler to the window from which the
  24. events should be caught (see the constructors of the handlers for details). Therefor you have
  25. to derive a class from the needed handler and override the member-function HandleEvent(). With
  26. your overridden function you catch the events and handle it.<P>
  27. Usualy the method HandleEvent() must return a boolean value. The return value indicates if the
  28. event can be processed by the operating system (return TRUE) or if the event should not be
  29. processed (return FALSE).
  30. You can install:
  31. <UL>
  32. <LI>XBackgroundDrawHandler
  33. <LI>XContainerHandler
  34. <LI>XDragHandler
  35. <LI>XKeyboardHandler
  36. <LI>XItemDrawHandler
  37. <LI>XMouseHandler
  38. <LI>XStyleHandler
  39. <LI>XTimer
  40. </UL>
  41. */
  42.  
  43.  
  44. /*@ XHandler :: HandleEvent(XEvent*)
  45. @remarks    Constructor of XItemDrawHandler
  46. @parameters XEvent * event    the event-class, in derived classes of XHandler there will be usualy caught 
  47. events derived from XEvent.
  48. @returns BOOL TRUE=let the OS handle the event, FALSE=dont let the OS handle the event
  49. */
  50.  
  51. XHandler :: XHandler(const USHORT ide, const XWindow * handleWindow)
  52. {
  53.     id = ide;
  54.     handleFor = (XWindow *) handleWindow;
  55.  
  56.     handleFor->handlers += 1;
  57.     handleFor->regHandlers = (XHandler **) realloc(handleFor->regHandlers, handleFor->handlers * sizeof(XHandler *));
  58.     handleFor->regHandlers[handleFor->handlers - 1] = this;
  59. }
  60.  
  61.  
  62. XHandler :: ~XHandler()
  63. {
  64.     if (handleFor)
  65.     {
  66.         BOOL swap = FALSE;
  67.  
  68.         for (int i = 0; i < handleFor->handlers - 1; i++)
  69.         {
  70.             if (handleFor->regHandlers[i] == this)
  71.                 swap = TRUE;
  72.             if (swap)
  73.                 handleFor->regHandlers[i] = handleFor->regHandlers[i + 1];
  74.         }
  75.         handleFor->handlers -= 1;
  76.         handleFor->regHandlers = (XHandler **) realloc(handleFor->regHandlers, handleFor->handlers * sizeof(XHandler *));
  77.     }
  78. }
  79.  
  80.  
  81. /*@
  82. @class XItemDrawHandler
  83. @parent XHandler
  84. @type overview
  85. @symbol _
  86. @remarks XItemDrawHandler is used for controls which can draw the items itself, eg. menus or listboxes
  87. with the style OWNERDRAW. To do so derive a class from XItemDrawHandler and override the method HandleEvent().
  88. If you catch a XItemDrawEvent you can draw the item by calling XItemDrawEvent::DrawItem(). 
  89. */
  90.  
  91. /*@ XItemDrawHandler :: XItemDrawHandler(const XWindow * w, const SHORT itemWidth, const SHORT itemHeight)
  92. @remarks    Constructor of XItemDrawHandler
  93. @parameters
  94. <t '°' c=2>
  95. °XWindow * w                °the window
  96. °SHORT itemWidth        °the width of the items
  97. °SHORT itemHeight        °the height of the items
  98. </t>
  99. */
  100. XItemDrawHandler :: XItemDrawHandler(const XWindow * w, const SHORT itemWidth, const SHORT itemHeight):XHandler(OOL_ITMDRAWHANDLER, w)
  101. {
  102.     width = itemWidth;
  103.     height = itemHeight;
  104.  
  105.     char str[5];
  106.  
  107.     WinQueryClassName(w->GetHandle(), 5, (PCH) str);
  108.     str[0] = ' ';
  109.     type = atol(str);
  110.  
  111.     if (type == 2 || type == 7)
  112.     {
  113.         WinSendMsg(w->GetHandle(), LM_SETITEMWIDTH, MPFROMSHORT(width), 0);
  114.         WinSendMsg(w->GetHandle(), LM_SETITEMHEIGHT, MPFROMSHORT(height), 0);
  115.     }
  116. }
  117.  
  118.  
  119. int tid = 0;
  120.  
  121. /*@ 
  122. @class XTimer
  123. @parent XHandler
  124. @type overview
  125. @symbol _
  126. @remarks XTimer is a timer which is activated in time-intervals given in XTimer::Start().
  127. Time-intervals shouldnt be smaller than 1/18 second. To handle time-events derive a class from XTimer
  128. and override TimeEvent().
  129. */
  130.  
  131.  
  132. /*@ XTimer::TimeEvent()
  133. @group misc
  134. @remarks The timer got a timeout. Override this function to handle timer-events.
  135. */
  136.  
  137.  
  138. /*@ XTimer::XTimer(XWindow*)
  139. @group constructors/destructors
  140. @remarks Constructs a timer.
  141. @parameters XWindow * owner   the owner window
  142. */
  143. XTimer :: XTimer(const XWindow * w):XHandler(OOL_TIMER, w)
  144. {
  145.     timerID = tid;
  146.     tid++;
  147. }
  148.  
  149.  
  150. /*@ XTimer::Start()
  151. @group misc
  152. @remarks Start the timer.
  153. @parameters ULONG time  time-interval in milli-seconds.
  154. */
  155. BOOL XTimer::Start(const ULONG time)
  156. {
  157.     timeOut = time;
  158.     HWND hwnd = GetWindow()->GetHandle();
  159.  
  160.     if (WinStartTimer(WinQueryAnchorBlock(hwnd), hwnd, timerID, time) == 0)
  161.         return FALSE;
  162.     else
  163.         return TRUE;
  164. }
  165.  
  166.  
  167. /*@ XTimer::Stop(void)
  168. @group misc
  169. @remarks Stop the timer.
  170. */
  171. BOOL XTimer::Stop(void)
  172. {
  173.     HWND hwnd = GetWindow()->GetHandle();
  174.  
  175.     return WinStopTimer(WinQueryAnchorBlock(hwnd), hwnd, timerID);
  176. }
  177.  
  178.  
  179. /*@ XTimer::QueryTimeOut()
  180. @group misc
  181. @remarks Query the time-interval
  182. @returns ULONG time-interval in milliseconds
  183. */
  184.  
  185.  
  186. /*@ 
  187. @class XContainerHandler
  188. @parent XHandler
  189. @type overview
  190. @symbol _
  191. @remarks To catch events from a container you need to derive a class from XContainerHandler
  192. and override the method HandleEvent where you will get the events.<P>
  193. In the case of drag-events XContainerDragEvent is posted, in the case of edit-events XContainerEditEvent is posted, in the method HandleEvent
  194. you can typecast in this case, see XContainerEvent for details.
  195. */
  196.  
  197.  
  198. /*@ XContainerHandler::XContainerHandler(XContainerControl*)
  199. @parameters XContainerControl * window       The window to handle the events for.
  200. */
  201.  
  202.  
  203. /*@ 
  204. @class XDragHandler
  205. @parent XHandler
  206. @type overview
  207. @symbol _
  208. @remarks To catch drag-events you need to derive a class from XDragHandler
  209. and override the method HandleEvent() where you will get the events (XDragEvent).
  210. */
  211.  
  212.  
  213. /*@ XDragHandler::XDragHandler(XWindow*)
  214. @parameters XWindow * window       The window to handle the events for.
  215. */
  216.  
  217.  
  218. /*@ 
  219. @class XMouseHandler
  220. @parent XHandler
  221. @type overview
  222. @symbol _
  223. @remarks To catch events from the mouse like moving using mouse-buttons etc you must
  224. register a XMouseHandler. Therefor you derive a class from XMouseHandler
  225. and override the method HandleEvent() where you will get events (XMouseEvent) posted
  226. from the mouse.
  227. */
  228.  
  229.  
  230. /*@ 
  231. @class XKeyboardHandler
  232. @parent XHandler
  233. @type overview
  234. @symbol _
  235. @remarks To catch events from the keyboard  you must
  236. register a XKeyboardHandler. Therefor you derive a class from XKeyboardHandler
  237. and override the method HandleEvent() where you will get events (XKeyboardEvent) posted
  238. from the mouse.
  239. */
  240.  
  241.  
  242. /*@ XKeyboardHandler::XKeyboardHandler(XWindow*)
  243. @parameters XWindow * window       The window to handle the keyboard-events for.
  244. */
  245.  
  246.  
  247. /*@ XMouseHandler::XMouseHandler(XWindow*)
  248. @parameters XWindow * window       The window to handle the mouseevents for.
  249. */
  250.  
  251.  
  252. /*@ 
  253. @class XStyleHandler
  254. @parent XHandler
  255. @type overview
  256. @symbol _
  257. @remarks XStyleHandler catch events when the style of a window has changed (e.g. if the user
  258. droped a font or color on a window). If you want to catch these events derive a class of 
  259. XStyleHandler and override HandleEvent(). In HandleEvent you get a XEvent where you can 
  260. get the ID of the event. Valid values are:
  261. <t '°' 2>
  262.    °STY_FONT                      °font changed
  263.    °STY_FOREGROUNDCOLOR           °foreground-color changed
  264.    °STY_BACKGROUNDCOLOR           °background-color changed
  265. </t>
  266. */
  267.  
  268. /*@ XStyleHandler::XStyleHandler(XWindow*)
  269. @parameters XWindow * window       The window to handle the events for.
  270. */
  271.  
  272.