home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWEvents / Sources / FWEventD.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  23.4 KB  |  801 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWEventD.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWEVENTD_H
  13. #include "FWEventD.h"
  14. #endif
  15.  
  16. #ifndef FWEVENT_H
  17. #include "FWEvent.h"
  18. #endif
  19.  
  20. #ifndef FWEVENTH_H
  21. #include "FWEventH.h"
  22. #endif
  23.  
  24. #ifndef FWMNUBAR_H
  25. #include "FWMnuBar.h"
  26. #endif
  27.  
  28. #ifndef FWPOINT_H
  29. #include "FWPoint.h"
  30. #endif
  31.  
  32. #ifndef FWODMISS_H
  33. #include "FWODMiss.h"
  34. #endif
  35.  
  36. // ----- OpenDoc Includes -----
  37.  
  38. #ifndef SOM_ODWindow_xh
  39. #include <Window.xh>
  40. #endif
  41.  
  42. #ifndef SOM_ODFacet_xh
  43. #include <Facet.xh>
  44. #endif
  45.  
  46. // ----- Macintosh Includes -----
  47.  
  48. #if defined(FW_BUILD_MAC) && !defined(__TOOLUTILS__)
  49. #include <ToolUtils.h>
  50. #endif
  51.  
  52. #if FW_LIB_EXPORT_PRAGMAS
  53. #pragma lib_export on
  54. #endif
  55.  
  56. #pragma segment FWEvents
  57.  
  58. //========================================================================================
  59. //    globals
  60. //========================================================================================
  61.  
  62. unsigned short FW_CEventDispatcher::gAutoRepeatCount = 0;
  63.  
  64. unsigned long FW_CEventDispatcher::gLastMouseUp = 0;
  65. short FW_CEventDispatcher::gClickCount = 1;
  66.  
  67. //========================================================================================
  68. //    RunTime Info
  69. //========================================================================================
  70.  
  71. FW_DEFINE_CLASS_M0(FW_CEventDispatcher)
  72.  
  73. //========================================================================================
  74. //    class FW_CEventDispatcher
  75. //========================================================================================
  76.  
  77. //----------------------------------------------------------------------------------------
  78. //    FW_CEventDispatcher::FW_CEventDispatcher
  79. //----------------------------------------------------------------------------------------
  80.  
  81. FW_CEventDispatcher::FW_CEventDispatcher() :
  82.     fLastMouseDownTarget(NULL),
  83.     fLastMouseDownFrame(NULL),
  84.     fEventHandler(NULL),
  85.     fMenuBar(NULL)
  86. {
  87. }
  88.  
  89. //----------------------------------------------------------------------------------------
  90. //    FW_CEventDispatcher::FW_CEventDispatcher
  91. //----------------------------------------------------------------------------------------
  92.  
  93. FW_CEventDispatcher::FW_CEventDispatcher(FW_MEventHandler* theEventHandler, FW_CMenuBar* theMenuBar) :
  94.     fLastMouseDownTarget(NULL),
  95.     fLastMouseDownFrame(NULL),
  96.     fEventHandler(theEventHandler),
  97.     fMenuBar(theMenuBar)
  98. {
  99. }
  100.  
  101. //----------------------------------------------------------------------------------------
  102. //    FW_CEventDispatcher::~FW_CEventDispatcher
  103. //----------------------------------------------------------------------------------------
  104.  
  105. FW_CEventDispatcher::~FW_CEventDispatcher()
  106. {
  107. }
  108.  
  109. //----------------------------------------------------------------------------------------
  110. //    FW_CEventDispatcher::Dispatch
  111. //----------------------------------------------------------------------------------------
  112.  
  113. FW_Boolean FW_CEventDispatcher::Dispatch(Environment* ev, 
  114.                                         ODEventData* event, 
  115.                                         ODFrame* odFrame,  
  116.                                         ODFacet* odFacet, 
  117.                                         ODEventInfo* eventInfo)
  118. {
  119.     FW_Boolean handled = FALSE;
  120.     
  121. #ifdef FW_BUILD_MAC    
  122.     switch (event->what)
  123. #endif
  124. #ifdef FW_BUILD_WIN    
  125.     switch (event->message)
  126. #endif
  127.     {
  128.     
  129. #ifdef FW_BUILD_MAC    
  130.         case nullEvent:
  131. #endif
  132. #ifdef FW_BUILD_WIN    
  133.         case WM_NULL:
  134. #endif
  135.             handled = this->DispatchNullEvent(ev, event, odFrame);
  136.             break;
  137.  
  138. #ifdef FW_BUILD_MAC    
  139.         case mouseDown:
  140. #endif
  141. #ifdef FW_BUILD_WIN    
  142.         case WM_LBUTTONDOWN:
  143.         case WM_MBUTTONDOWN:
  144.         case WM_RBUTTONDOWN:
  145. #endif
  146. #if FW_OPENDOC_VERSION >= FW_OPENDOC_DR3
  147.         case kODEvtBGMouseDown:
  148. #ifdef FW_BUILD_MAC
  149.             handled = this->DispatchMouseDownEvent(ev, event, odFrame, odFacet, (event->what == kODEvtBGMouseDown));
  150. #endif
  151. #ifdef FW_BUILD_WIN
  152.             handled = this->DispatchMouseDownEvent(ev, event, odFrame, odFacet, (event->message == kODEvtBGMouseDown));
  153. #endif
  154.             break;
  155. #else
  156.             handled = this->DispatchMouseDownEvent(ev, event, odFrame, odFacet, FALSE);
  157.             break;
  158. #endif
  159.  
  160. #ifdef FW_BUILD_MAC    
  161.         case mouseUp:
  162. #endif
  163. #ifdef FW_BUILD_WIN    
  164.         case WM_LBUTTONUP:
  165.         case WM_MBUTTONUP:
  166.         case WM_RBUTTONUP:
  167. #endif
  168.             handled = this->DispatchMouseUpEvent(ev, event, odFrame, odFacet);
  169.             break;
  170.             
  171. #ifdef FW_BUILD_MAC
  172.         case keyDown:
  173.         case autoKey:
  174. #endif
  175. #ifdef FW_BUILD_WIN
  176.         case WM_KEYDOWN:
  177. #endif
  178.             handled = this->DispatchVirtualKeyDownEvent(ev, event, odFrame);
  179.             break;
  180.             
  181. #ifdef FW_BUILD_MAC
  182.         case keyUp:
  183. #endif
  184. #ifdef FW_BUILD_WIN
  185.         case WM_KEYUP:
  186. #endif
  187.             handled = this->DispatchVirtualKeyUpEvent(ev, event, odFrame);
  188.             break;
  189.                         
  190. #ifdef FW_BUILD_WIN
  191.         case WM_CHAR:
  192.             handled = this->DispatchCharKeyEvent(ev, event, odFrame);
  193.             break;
  194. #endif
  195.  
  196. #ifdef FW_BUILD_MAC
  197.         case activateEvt:
  198. #endif
  199. #ifdef FW_BUILD_WIN
  200.         case WM_ACTIVATE:
  201. #endif
  202.             handled = this->DispatchActivateEvent(ev, event, odFrame, odFacet);
  203.             break;
  204.         
  205.         case kODEvtMenu:
  206.             handled = this->DispatchMenuEvent(ev, event, odFrame);
  207.             break;
  208.             
  209. #ifdef FW_BUILD_MAC
  210.         case kODEvtWindow: 
  211.             handled = this->DispatchWindowEvent(ev, event, odFacet);
  212.             break;
  213.         case osEvt:
  214.             handled = this->DispatchOSEvent(ev, event, odFacet);
  215.             break;
  216. #endif
  217.  
  218.         case kODEvtMouseDownEmbedded:
  219. #if FW_OPENDOC_VERSION >= FW_OPENDOC_DR3
  220.         case kODEvtBGMouseDownEmbedded:
  221. #ifdef FW_BUILD_MAC
  222.             handled = this->DispatchEmbeddedMouseDownEvent(ev, event, odFrame, odFacet, eventInfo, (event->what == kODEvtBGMouseDownEmbedded));
  223. #endif
  224. #ifdef FW_BUILD_WIN
  225.             handled = this->DispatchEmbeddedMouseDownEvent(ev, event, odFrame, odFacet, eventInfo, (event->message == kODEvtBGMouseDownEmbedded));
  226. #endif
  227.             break;
  228. #else
  229.             handled = this->DispatchEmbeddedMouseDownEvent(ev, event, odFrame, odFacet, eventInfo, FALSE);
  230.             break;
  231. #endif
  232.             
  233.         case kODEvtMouseUpEmbedded:
  234.             handled = this->DispatchEmbeddedMouseUpEvent(ev, event, odFrame, odFacet, eventInfo);
  235.             break;
  236.             
  237.         case kODEvtMouseDownBorder:
  238.             handled = this->DispatchBorderMouseDownEvent(ev, event, odFrame, odFacet, eventInfo);
  239.             break;
  240.             
  241.         case kODEvtMouseEnter:
  242.             handled = this->DispatchMouseEnterEvent(ev, odFacet, eventInfo);
  243.             break;
  244.             
  245.         case kODEvtMouseWithin:
  246.             handled = this->DispatchMouseWithinEvent(ev, odFacet, eventInfo);
  247.             break;
  248.             
  249.         case kODEvtMouseLeave:
  250.             handled = this->DispatchMouseLeaveEvent(ev, odFacet, eventInfo);
  251.             break;
  252.     }
  253.  
  254.     return handled;
  255. }
  256.  
  257. //----------------------------------------------------------------------------------------
  258. //    FW_CEventDispatcher::DispatchNullEvent
  259. //----------------------------------------------------------------------------------------
  260.  
  261. FW_Boolean FW_CEventDispatcher::DispatchNullEvent(Environment* ev, ODEventData* event, ODFrame* odFrame)
  262. {
  263.     FW_CNullEvent theNullEvent(ev, event);    
  264.     FW_MEventHandler* target = fEventHandler;
  265.     
  266.     if (odFrame)
  267.     {    
  268.         FW_MEventHandler* fwFrame = FW_MEventHandler::ODFrameToEventHandler(ev, odFrame);
  269.         FW_ASSERT(fwFrame != NULL);
  270.         target = fwFrame->GetTarget(ev);
  271.         FW_ASSERT(target != NULL);
  272.     }
  273.     
  274.     return target->HandleIdle(ev, theNullEvent);
  275. }
  276.  
  277. //----------------------------------------------------------------------------------------
  278. //    FW_CEventDispatcher::DispatchMouseDownEvent
  279. //----------------------------------------------------------------------------------------
  280.  
  281. FW_Boolean FW_CEventDispatcher::DispatchMouseDownEvent(Environment* ev, ODEventData* event, ODFrame* odFrame,  ODFacet* odFacet, FW_Boolean inBackground)
  282. {
  283.     short numOfClicks = OnMouseDown(ev, event);
  284.     
  285.     FW_CMouseEvent theMouseEvent(ev, event, odFacet, FW_CMouseEvent::kMouseButtonDown, numOfClicks);
  286.     
  287.     FW_MEventHandler* fwFrame = FW_MEventHandler::ODFrameToEventHandler(ev, odFrame);
  288.     FW_ASSERT(fwFrame != NULL);
  289.  
  290.     FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  291.     FW_MEventHandler* target = fwFrame->PrivGetEventHandlerContaining(ev, odFacet, where);
  292.     FW_ASSERT(target);
  293.  
  294. //    FW_ASSERT(fLastMouseDownTarget == NULL);
  295. //    FW_ASSERT(fLastMouseDownFrame == NULL);
  296.     fLastMouseDownTarget = target;
  297.     fLastMouseDownFrame = fwFrame;
  298.     
  299.     FW_Boolean handled = FALSE;
  300.     while (target != NULL && handled == FALSE)
  301.     {
  302.         handled = inBackground ? target->DispatchBGMouseDown(ev, theMouseEvent)
  303.                               : target->DispatchMouseDown(ev, theMouseEvent);
  304.             
  305.         target = target->GetNextEventHandler(ev);
  306.     }
  307.     
  308.     return handled;
  309. }
  310.  
  311. //----------------------------------------------------------------------------------------
  312. //    FW_CEventDispatcher::DispatchMouseUpEvent
  313. //----------------------------------------------------------------------------------------
  314.  
  315. FW_Boolean FW_CEventDispatcher::DispatchMouseUpEvent(Environment* ev, ODEventData* event, ODFrame* odFrame,  ODFacet* odFacet)
  316. {
  317.     OnMouseUp(ev, event);
  318.     
  319.     FW_CMouseEvent theMouseEvent(ev, event, odFacet, FW_CMouseEvent::kMouseButtonUp);
  320.     
  321.     FW_MEventHandler* target = NULL;
  322.     
  323. //    FW_ASSERT(fLastMouseDownTarget != NULL);
  324. //    FW_ASSERT(fLastMouseDownFrame != NULL);
  325.  
  326.     FW_MEventHandler* fwFrame = FW_MEventHandler::ODFrameToEventHandler(ev, odFrame);
  327.     FW_ASSERT(fwFrame != NULL);
  328.  
  329.     if (fLastMouseDownFrame == fwFrame)
  330.         target = fLastMouseDownTarget;
  331.     else
  332.     {
  333.         FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  334.         target = fwFrame->PrivGetEventHandlerContaining(ev, odFacet, where);
  335.     }
  336.  
  337.     fLastMouseDownTarget = NULL;
  338.     fLastMouseDownFrame = NULL;
  339.  
  340.     FW_Boolean handled = FALSE;
  341.     while (target != NULL && handled == FALSE)
  342.     {
  343.         handled = target->DispatchMouseUp(ev, theMouseEvent);
  344.             
  345.         target = target->GetNextEventHandler(ev);
  346.     }
  347.     
  348.     return handled;
  349. }
  350.  
  351. //----------------------------------------------------------------------------------------
  352. //    FW_CEventDispatcher::DispatchEmbeddedMouseDownEvent
  353. //----------------------------------------------------------------------------------------
  354.  
  355. FW_Boolean FW_CEventDispatcher::DispatchEmbeddedMouseDownEvent(Environment* ev, 
  356.                                                                 ODEventData* event, 
  357.                                                                 ODFrame* odFrame,  
  358.                                                                 ODFacet* odFacet, 
  359.                                                                 ODEventInfo* eventInfo,
  360.                                                                 FW_Boolean inBackground)
  361. {
  362.     short numOfClicks = OnMouseDown(ev, event);
  363.     
  364.     FW_CEmbeddedMouseEvent theEmbeddedMouseEvent(ev, 
  365.                                                 event, 
  366.                                                 odFacet, 
  367.                                                 eventInfo->embeddedFrame, 
  368.                                                 eventInfo->embeddedFacet, 
  369.                                                 FW_CMouseEvent::kMouseButtonDown,
  370.                                                 numOfClicks);
  371.     
  372.     FW_MEventHandler* fwFrame = FW_MEventHandler::ODFrameToEventHandler(ev, odFrame);
  373.     FW_ASSERT(fwFrame != NULL);
  374.  
  375.     FW_CPoint where = theEmbeddedMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  376.     FW_MEventHandler* target = fwFrame->PrivGetEventHandlerContaining(ev, odFacet, where);
  377.     FW_ASSERT(target);
  378.  
  379. //    FW_ASSERT(fLastMouseDownTarget == NULL);
  380. //    FW_ASSERT(fLastMouseDownFrame == NULL);
  381.     fLastMouseDownTarget = target;
  382.     fLastMouseDownFrame = fwFrame;
  383.  
  384.     FW_Boolean handled = FALSE;
  385.     while (target != NULL && handled == FALSE)
  386.     {
  387.         handled = inBackground ? target->DispatchBGMouseDownInEmbeddedFrame(ev, theEmbeddedMouseEvent)
  388.                               : target->DispatchMouseDownInEmbeddedFrame(ev, theEmbeddedMouseEvent);
  389.             
  390.         target = target->GetNextEventHandler(ev);
  391.     }
  392.     
  393.     return handled;
  394. }
  395.  
  396. //----------------------------------------------------------------------------------------
  397. //    FW_CEventDispatcher::DispatchEmbeddedMouseUpEvent
  398. //----------------------------------------------------------------------------------------
  399.  
  400. FW_Boolean FW_CEventDispatcher::DispatchEmbeddedMouseUpEvent(Environment* ev, ODEventData* event, ODFrame* odFrame,  ODFacet* odFacet, ODEventInfo* eventInfo)
  401. {
  402.     OnMouseUp(ev, event);
  403.     
  404.     FW_CEmbeddedMouseEvent theEmbeddedMouseEvent(ev, 
  405.                                                 event, 
  406.                                                 odFacet, 
  407.                                                 eventInfo->embeddedFrame, 
  408.                                                 eventInfo->embeddedFacet, 
  409.                                                 FW_CMouseEvent::kMouseButtonUp);
  410.     
  411.     FW_MEventHandler* fwFrame = FW_MEventHandler::ODFrameToEventHandler(ev, odFrame);
  412.     FW_ASSERT(fwFrame != NULL);
  413.     
  414.     FW_MEventHandler* target = NULL;
  415.     
  416. //    FW_ASSERT(fLastMouseDownTarget != NULL);
  417. //    FW_ASSERT(fLastMouseDownFrame != NULL);
  418.  
  419.     if (fLastMouseDownFrame == fwFrame)
  420.         target = fLastMouseDownTarget;
  421.     else
  422.     {
  423.         FW_CPoint where = theEmbeddedMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  424.         target = fwFrame->PrivGetEventHandlerContaining(ev, odFacet, where);
  425.     }
  426.     
  427.     fLastMouseDownTarget = NULL;
  428.     fLastMouseDownFrame = NULL;
  429.  
  430.     FW_Boolean handled = FALSE;
  431.     while (target != NULL && handled == FALSE)
  432.     {
  433.         handled = target->DispatchMouseUpInEmbeddedFrame(ev, theEmbeddedMouseEvent);
  434.             
  435.         target = target->GetNextEventHandler(ev);
  436.     }
  437.     
  438.     return handled;
  439. }
  440.  
  441. //----------------------------------------------------------------------------------------
  442. //    FW_CEventDispatcher::DispatchBorderMouseDownEvent
  443. //----------------------------------------------------------------------------------------
  444.  
  445. FW_Boolean FW_CEventDispatcher::DispatchBorderMouseDownEvent(Environment* ev, ODEventData* event, ODFrame* odFrame,  ODFacet* odFacet, ODEventInfo* eventInfo)
  446. {
  447.     short numOfClicks = OnMouseDown(ev, event);
  448.     
  449.     FW_CBorderMouseEvent theBorderMouseEvent(ev, 
  450.                                             event, 
  451.                                             odFacet, 
  452.                                             eventInfo->embeddedFrame, 
  453.                                             eventInfo->embeddedFacet,
  454.                                             FW_CMouseEvent::kMouseButtonDown,
  455.                                             numOfClicks);
  456.     
  457.     FW_MEventHandler* fwFrame = FW_MEventHandler::ODFrameToEventHandler(ev, odFrame);
  458.     FW_ASSERT(fwFrame != NULL);
  459.  
  460.     FW_CPoint where = theBorderMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  461.     FW_MEventHandler* target = fwFrame->PrivGetEventHandlerContaining(ev, odFacet, where);
  462.     FW_ASSERT(target);
  463.  
  464. //    FW_ASSERT(fLastMouseDownTarget == NULL);
  465. //    FW_ASSERT(fLastMouseDownFrame == NULL);
  466.     fLastMouseDownTarget = target;
  467.     fLastMouseDownFrame = fwFrame;
  468.  
  469.     FW_Boolean handled = FALSE;
  470.     while (target != NULL && handled == FALSE)
  471.     {
  472.         handled = target->DispatchMouseDownInEmbeddedFrameBorder(ev, theBorderMouseEvent);
  473.             
  474.         target = target->GetNextEventHandler(ev);
  475.     }
  476.     
  477.     return handled;
  478. }
  479.  
  480. //----------------------------------------------------------------------------------------
  481. //    FW_CEventDispatcher::DispatchVirtualKeyDownEvent
  482. //----------------------------------------------------------------------------------------
  483.  
  484. FW_Boolean FW_CEventDispatcher::DispatchVirtualKeyDownEvent(Environment* ev, ODEventData* event, ODFrame* odFrame)
  485. {
  486.     FW_Boolean handled = FALSE;
  487.     
  488. #ifdef FW_BUILD_MAC
  489.     if (event->what == autoKey)
  490.         gAutoRepeatCount++;
  491.     else
  492.         gAutoRepeatCount = 0;
  493.         
  494.     FW_CVirtualKeyEvent theVirtualKeyEvent(ev, event, FW_CVirtualKeyEvent::kKeyDown, gAutoRepeatCount);
  495. #endif
  496.  
  497. #ifdef FW_BUILD_WIN
  498.     FW_CVirtualKeyEvent theVirtualKeyEvent(ev, event, FW_CVirtualKeyEvent::kKeyDown, LOWORD(event->lParam));
  499. #endif
  500.  
  501.     FW_MEventHandler* fwFrame = FW_MEventHandler::ODFrameToEventHandler(ev, odFrame);
  502.     FW_ASSERT(fwFrame != NULL);
  503.     FW_MEventHandler* target = fwFrame->GetTarget(ev);
  504.     FW_ASSERT(target != NULL);
  505.  
  506.     while (target != NULL && handled == FALSE)
  507.     {
  508.         handled = target->DispatchVirtualKey(ev, theVirtualKeyEvent);
  509.             
  510.         target = target->GetNextEventHandler(ev);
  511.     }
  512.     
  513. #ifdef FW_BUILD_MAC
  514.     // If the keycode isn't used try the char
  515.     if (!handled)
  516.         handled = this->DispatchCharKeyEvent(ev, event, odFrame);
  517. #endif
  518.  
  519.     return handled;
  520. }
  521.  
  522. //----------------------------------------------------------------------------------------
  523. //    FW_CEventDispatcher::DispatchVirtualKeyUpEvent
  524. //----------------------------------------------------------------------------------------
  525.  
  526. FW_Boolean FW_CEventDispatcher::DispatchVirtualKeyUpEvent(Environment* ev, ODEventData* event, ODFrame* odFrame)
  527. {
  528.     FW_CVirtualKeyEvent theVirtualKeyEvent(ev, event, FW_CVirtualKeyEvent::kKeyUp);
  529.     
  530.     FW_MEventHandler* fwFrame = FW_MEventHandler::ODFrameToEventHandler(ev, odFrame);
  531.     FW_ASSERT(fwFrame != NULL);
  532.     FW_MEventHandler* target = fwFrame->GetTarget(ev);
  533.     FW_ASSERT(target != NULL);
  534.     
  535.     FW_Boolean handled = FALSE;
  536.     while (target != NULL && handled == FALSE)
  537.     {
  538.         handled = target->DispatchVirtualKey(ev, theVirtualKeyEvent);
  539.             
  540.         target = target->GetNextEventHandler(ev);
  541.     }
  542.     
  543.     return handled;
  544. }
  545.  
  546. //----------------------------------------------------------------------------------------
  547. //    FW_CEventDispatcher::DispatchCharKeyEvent
  548. //----------------------------------------------------------------------------------------
  549.  
  550. FW_Boolean FW_CEventDispatcher::DispatchCharKeyEvent(Environment* ev, ODEventData* event, ODFrame* odFrame)
  551. {
  552. #ifdef FW_BUILD_MAC
  553.     FW_CCharKeyEvent theCharKeyEvent(ev, event, gAutoRepeatCount);
  554. #endif
  555. #ifdef FW_BUILD_WIN
  556.     FW_CCharKeyEvent theCharKeyEvent(ev, event, LOWORD(event->lParam));
  557. #endif
  558.     
  559.     FW_MEventHandler* fwFrame = FW_MEventHandler::ODFrameToEventHandler(ev, odFrame);
  560.     FW_ASSERT(fwFrame != NULL);
  561.     FW_MEventHandler* target = fwFrame->GetTarget(ev);
  562.     FW_ASSERT(target != NULL);
  563.     
  564.     FW_Boolean handled = FALSE;
  565.     while (target != NULL && handled == FALSE)
  566.     {
  567.         handled = target->DispatchCharKey(ev, theCharKeyEvent);
  568.             
  569.         target = target->GetNextEventHandler(ev);
  570.     }
  571.     
  572.     return handled;
  573. }
  574.  
  575. //----------------------------------------------------------------------------------------
  576. //    FW_CEventDispatcher::DispatchActivateEvent
  577. //----------------------------------------------------------------------------------------
  578.  
  579. FW_Boolean FW_CEventDispatcher::DispatchActivateEvent(Environment* ev, ODEventData* event, ODFrame* odFrame,  ODFacet* odFacet)
  580. {
  581.     FW_UNUSED(odFrame);
  582.     
  583. #ifdef FW_BUILD_MAC
  584.     FW_CActivateEvent theActivateEvent(ev, event, odFacet, (event->modifiers & activeFlag ) != 0);
  585. #endif
  586. #ifdef FW_BUILD_WIN
  587.     FW_CActivateEvent theActivateEvent(ev, event, odFacet, (event->wParam != WA_INACTIVE));
  588. #endif
  589.  
  590.     FW_MEventHandler* target = FW_MEventHandler::ODFrameToEventHandler(ev, odFrame);
  591.     FW_ASSERT(target != NULL);
  592.     
  593.     FW_Boolean handled = FALSE;
  594.     while (target != NULL && handled == FALSE)
  595.     {
  596.         handled = target->DispatchActivateEvent(ev, theActivateEvent);
  597.             
  598.         target = target->GetNextEventHandler(ev);
  599.     }
  600.     return handled;
  601. }
  602.  
  603. //----------------------------------------------------------------------------------------
  604. //    FW_CEventDispatcher::DispatchMenuEvent
  605. //----------------------------------------------------------------------------------------
  606.  
  607. FW_Boolean FW_CEventDispatcher::DispatchMenuEvent(Environment* ev, ODEventData* event, ODFrame* odFrame)
  608. {
  609.     ODCommandID theCommand;
  610.     
  611. #ifdef FW_BUILD_MAC
  612.     ODMenuID menu = HiWord(event->message);
  613.     ODMenuItemID item = LoWord(event->message);
  614.     theCommand = fMenuBar->PrivMacGetCommand(ev, menu, item);
  615. #endif
  616. #ifdef FW_BUILD_WIN
  617.     theCommand = event->wParam;
  618. #endif
  619.  
  620.     FW_CMenuEvent theMenuEvent(ev, event, theCommand);
  621.  
  622.     FW_MEventHandler* fwFrame = FW_MEventHandler::ODFrameToEventHandler(ev, odFrame);
  623.     FW_ASSERT(fwFrame != NULL);
  624.     FW_MEventHandler* target = fwFrame->GetTarget(ev);
  625.     FW_ASSERT(target != NULL);
  626.     
  627.     FW_Boolean handled = FALSE;
  628.     while (target != NULL && handled == FALSE)
  629.     {
  630.         handled = target->DispatchMenuEvent(ev, theMenuEvent);
  631.             
  632.         target = target->GetNextEventHandler(ev);
  633.     }
  634.  
  635. #ifdef FW_BUILD_MAC
  636.     ::HiliteMenu(0);
  637. #endif
  638.  
  639.     return handled;
  640. }
  641.  
  642. //----------------------------------------------------------------------------------------
  643. //    FW_CEventDispatcher::DispatchMouseEnterEvent
  644. //----------------------------------------------------------------------------------------
  645.  
  646. FW_Boolean FW_CEventDispatcher::DispatchMouseEnterEvent(Environment* ev, ODFacet* odFacet, ODEventInfo* eventInfo)
  647. {
  648.     FW_MEventHandler* fwFrame = FW_MEventHandler::ODFrameToEventHandler(ev, odFacet->GetFrame(ev));
  649.     FW_ASSERT(fwFrame != NULL);
  650.  
  651.     FW_CPoint point(eventInfo->where);    
  652.     FW_MEventHandler* target = fwFrame;
  653.     
  654.     FW_Boolean handled = FALSE;
  655.     while (target != NULL && handled == FALSE)
  656.     {
  657.         handled = target->DispatchMouseEnter(ev, odFacet, point);
  658.             
  659.         target = target->GetNextEventHandler(ev);
  660.     }
  661.     
  662.     return handled;
  663. }
  664.  
  665. //----------------------------------------------------------------------------------------
  666. //    FW_CEventDispatcher::DispatchMouseWithinEvent
  667. //----------------------------------------------------------------------------------------
  668.  
  669. FW_Boolean FW_CEventDispatcher::DispatchMouseWithinEvent(Environment* ev, ODFacet* odFacet, ODEventInfo* eventInfo)
  670. {
  671.     FW_MEventHandler* fwFrame = FW_MEventHandler::ODFrameToEventHandler(ev, odFacet->GetFrame(ev));
  672.     FW_ASSERT(fwFrame != NULL);
  673.  
  674.     FW_CPoint point(eventInfo->where);
  675.     
  676.     FW_MEventHandler* target = fwFrame;
  677.  
  678.     FW_Boolean handled = FALSE;
  679.     while (target != NULL && handled == FALSE)
  680.     {
  681.         handled = target->DispatchMouseWithin(ev, odFacet, point);
  682.             
  683.         target = target->GetNextEventHandler(ev);
  684.     }
  685.     
  686.     return handled;
  687. }
  688.  
  689. //----------------------------------------------------------------------------------------
  690. //    FW_CEventDispatcher::DispatchMouseLeaveEvent
  691. //----------------------------------------------------------------------------------------
  692.  
  693. FW_Boolean FW_CEventDispatcher::DispatchMouseLeaveEvent(Environment* ev, ODFacet* odFacet, ODEventInfo* eventInfo)
  694. {
  695.     FW_MEventHandler* fwFrame = FW_MEventHandler::ODFrameToEventHandler(ev, odFacet->GetFrame(ev));
  696.     FW_ASSERT(fwFrame != NULL);
  697.  
  698.     FW_CPoint point(eventInfo->where);
  699.     
  700.     FW_MEventHandler* target = fwFrame;
  701.  
  702.     FW_Boolean handled = FALSE;
  703.     while (target != NULL && handled == FALSE)
  704.     {
  705.         handled = target->DispatchMouseLeave(ev, odFacet);
  706.             
  707.         target = target->GetNextEventHandler(ev);
  708.     }
  709.     
  710.     return handled;
  711. }
  712.  
  713. #ifdef FW_BUILD_MAC
  714. //----------------------------------------------------------------------------------------
  715. //    FW_CEventDispatcher::DispatchWindowEvent
  716. //----------------------------------------------------------------------------------------
  717.  
  718. FW_Boolean FW_CEventDispatcher::DispatchWindowEvent(Environment* ev, ODEventData* event, ODFacet* odFacet)
  719. {
  720.     FW_CMacWindowEvent windowEvent(ev, event);
  721.  
  722.     FW_MEventHandler* target = FW_MEventHandler::ODFrameToEventHandler(ev, odFacet->GetFrame(ev));
  723.     FW_ASSERT(target != NULL);
  724.  
  725.     FW_Boolean handled = FALSE;
  726.     while (target != NULL && handled == FALSE)
  727.     {
  728.         handled = target->DispatchWindowEvent(ev, windowEvent);
  729.             
  730.         target = target->GetNextEventHandler(ev);
  731.     }
  732.     
  733.     return handled;
  734. }
  735. #endif
  736.  
  737. #ifdef FW_BUILD_MAC
  738. //----------------------------------------------------------------------------------------
  739. //    FW_CEventDispatcher::DispatchOSEvent
  740. //----------------------------------------------------------------------------------------
  741.  
  742. FW_Boolean FW_CEventDispatcher::DispatchOSEvent(Environment* ev, ODEventData* event, ODFacet* odFacet)
  743. {
  744.     FW_Boolean handled = FALSE;
  745.     
  746.     if (((unsigned char) ( event->message >> 24 ) & 0x00FF) == 0x01)
  747.     {
  748.         const short kResumeMask = 0x01;    // High byte suspend/resume event 
  749.     
  750.         FW_Boolean goingToBackground = (event->message & kResumeMask) == 0;
  751.         FW_CSuspendResumeEvent suspendResumeEvent(ev, event, odFacet, goingToBackground);
  752.         
  753.         FW_MEventHandler* target = FW_MEventHandler::ODFrameToEventHandler(ev, odFacet->GetFrame(ev));
  754.         FW_ASSERT(target != NULL);
  755.             
  756.         while (target != NULL && handled == FALSE)
  757.         {
  758.             handled = target->DispatchSuspendResumeEvent(ev, suspendResumeEvent);
  759.                 
  760.             target = target->GetNextEventHandler(ev);
  761.         }
  762.     }
  763.     
  764.     return handled;
  765. }
  766. #endif
  767.  
  768. //----------------------------------------------------------------------------------------
  769. //    FW_CEventDispatcher::OnMouseUp
  770. //----------------------------------------------------------------------------------------
  771.  
  772. void FW_CEventDispatcher::OnMouseUp(Environment* ev, ODEventData* event)
  773. {
  774. #ifdef FW_BUILD_MAC
  775.     gLastMouseUp = event->when;
  776. #endif
  777.  
  778. #ifdef FW_BUILD_WIN
  779.     gLastMouseUp = 0;
  780. #endif
  781. }
  782.  
  783. //----------------------------------------------------------------------------------------
  784. //    FW_CEventDispatcher::OnMouseDown
  785. //----------------------------------------------------------------------------------------
  786.  
  787. short FW_CEventDispatcher::OnMouseDown(Environment* ev, ODEventData* event)
  788. {
  789. #ifdef FW_BUILD_MAC
  790.     if (event->when - gLastMouseUp < ::GetDblTime())
  791.         gClickCount++;
  792.     else
  793.         gClickCount = 1;
  794. #endif
  795.  
  796. #ifdef FW_BUILD_WIN
  797.     gClickCount = 1;
  798. #endif
  799.  
  800.     return gClickCount;
  801. }