home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWEvents / FWEvent.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  34.8 KB  |  1,043 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWEvent.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWEVENT_H
  13. #include "FWEvent.h"
  14. #endif
  15.  
  16. #ifndef FWACQUIR_H
  17. #include "FWAcquir.h"
  18. #endif
  19.  
  20. #ifndef FWMEMMGR_H
  21. #include "FWMemMgr.h"
  22. #endif
  23.  
  24. #ifndef FWPOINT_H
  25. #include "FWPoint.h"
  26. #endif
  27.  
  28. #ifndef FWMAPING_H
  29. #include "FWMaping.h"
  30. #endif
  31.  
  32. #ifndef FWFCTINF_H
  33. #include "FWFctInf.h"
  34. #endif
  35.  
  36. #ifndef FWUTIL_H
  37. #include "FWUtil.h"
  38. #endif
  39.  
  40. // ----- OpenDoc Includes -----
  41.  
  42. #ifndef SOM_ODWindow_xh
  43. #include <Window.xh>
  44. #endif
  45.  
  46. #ifndef SOM_ODFacet_xh
  47. #include <Facet.xh>
  48. #endif
  49.  
  50. //========================================================================================
  51. //    RunTime Info
  52. //========================================================================================
  53.  
  54. #ifdef FW_BUILD_MAC
  55. #pragma segment fwevents
  56. #endif
  57.  
  58. //========================================================================================
  59. //    Constants
  60. //========================================================================================
  61.  
  62. const short FW_CSystemEvent::kEmpty = 0;
  63. const short FW_CSystemEvent::kExtend = 1;    // Mac: shift Windows:
  64. const short FW_CSystemEvent::kItem = 2;        // Mac: shift Windows:
  65. const short FW_CSystemEvent::kCopy = 4;        // Mac: shift Windows:
  66. const short FW_CSystemEvent::kControl = 8;    // Mac: shift Windows:
  67.  
  68. //========================================================================================
  69. // CLASS FW_CSystemEvent
  70. //========================================================================================
  71.  
  72. //----------------------------------------------------------------------------------------
  73. //    FW_CSystemEvent::FW_CSystemEvent
  74. //----------------------------------------------------------------------------------------
  75. FW_CSystemEvent::FW_CSystemEvent(Environment* ev, ODPlatformWindow theWindow, FW_PlatformEventTime time)
  76. {
  77. FW_UNUSED(ev);
  78. #ifdef FW_BUILD_MAC
  79.     FW_CMemoryManager::SetMemory(&fEvent, sizeof(ODEventData), 0);
  80.     fEvent.when = time;
  81.     fPlatformWindow = theWindow;
  82. #endif
  83. #ifdef FW_BUILD_WIN
  84.     FW_CMemoryManager::SetMemory(&fEvent, sizeof(MSG), 0);
  85.     FW_ASSERT(theWindow != NULL);
  86.     fEvent.hwnd = theWindow;
  87.     fEvent.time = time;
  88.     fPlatformWindow = theWindow;
  89. #endif
  90.     fPropagated = FALSE;
  91. }
  92.  
  93. //----------------------------------------------------------------------------------------
  94. //    FW_CSystemEvent::FW_CSystemEvent
  95. //----------------------------------------------------------------------------------------
  96. FW_CSystemEvent::FW_CSystemEvent(Environment* ev, ODEventData* theEvent, FW_Boolean propagated)
  97. {
  98. FW_UNUSED(ev);
  99. #ifdef FW_BUILD_MAC
  100.     FW_CMemoryManager::CopyMemory(theEvent, &fEvent, sizeof(ODEventData));
  101.     fPlatformWindow = NULL;
  102. #endif
  103.  
  104. #ifdef FW_BUILD_WIN
  105.     FW_CMemoryManager::CopyMemory(theEvent, &fEvent, sizeof(MSG));
  106.     fPlatformWindow = (HWND)fEvent.hwnd;
  107. #endif
  108.     fPropagated = propagated;
  109. }
  110.  
  111. //----------------------------------------------------------------------------------------
  112. //    FW_CSystemEvent::FW_CSystemEvent
  113. //----------------------------------------------------------------------------------------
  114. FW_CSystemEvent::FW_CSystemEvent(Environment* ev, const FW_CSystemEvent& other)
  115. {
  116. FW_UNUSED(ev);
  117. #ifdef FW_BUILD_MAC
  118.     FW_CMemoryManager::CopyMemory(((FW_CSystemEvent&)other).GetPlatformEvent(), &fEvent, sizeof(ODEventData));
  119. #endif
  120.  
  121. #ifdef FW_BUILD_WIN
  122.     FW_CMemoryManager::CopyMemory(((FW_CSystemEvent&)other).GetPlatformEvent(), &fEvent, sizeof(MSG));
  123. #endif
  124.  
  125.     fPlatformWindow = other.GetPlatformWindow();
  126.     fPropagated = other.fPropagated;
  127. }
  128.  
  129. //----------------------------------------------------------------------------------------
  130. //    FW_CSystemEvent::~FW_CSystemEvent
  131. //----------------------------------------------------------------------------------------
  132. FW_CSystemEvent::~FW_CSystemEvent()
  133. {
  134. }
  135.  
  136. //----------------------------------------------------------------------------------------
  137. //    FW_CSystemEvent::GetModifiers
  138. //----------------------------------------------------------------------------------------
  139.  
  140. unsigned short FW_CSystemEvent::GetModifiers(Environment* ev) const
  141. {
  142.     unsigned short modifiers = kEmpty;
  143.     
  144.     if (this->IsExtendModifier(ev))
  145.         modifiers |= kExtend;
  146.     if (this->IsItemModifier(ev))
  147.         modifiers |= kItem;
  148.     if (this->IsCopyModifier(ev))
  149.         modifiers |= kCopy;
  150.     if (this->IsControlKeyModifier(ev))
  151.         modifiers |= kControl;
  152.     
  153.     return modifiers;
  154. }
  155.  
  156. //========================================================================================
  157. // CLASS FW_CNullEvent
  158. //========================================================================================
  159.  
  160. //----------------------------------------------------------------------------------------
  161. //    FW_CNullEvent::FW_CNullEvent
  162. //----------------------------------------------------------------------------------------
  163. FW_CNullEvent::FW_CNullEvent(Environment* ev, ODEventData* theEvent, FW_Boolean propagated) :
  164.     FW_CSystemEvent(ev, theEvent, propagated)
  165. {
  166. }
  167.  
  168. //----------------------------------------------------------------------------------------
  169. //    FW_CNullEvent::FW_CNullEvent
  170. //----------------------------------------------------------------------------------------
  171. FW_CNullEvent::FW_CNullEvent(Environment* ev, ODPlatformWindow theWindow, FW_PlatformEventTime time) :
  172.     FW_CSystemEvent(ev, theWindow, time)
  173. {
  174. }
  175.  
  176. //----------------------------------------------------------------------------------------
  177. //    FW_CNullEvent::FW_CNullEvent
  178. //----------------------------------------------------------------------------------------
  179. FW_CNullEvent::FW_CNullEvent(Environment* ev, const FW_CNullEvent& other) :
  180.     FW_CSystemEvent(ev, other)
  181. {
  182. #ifdef FW_BUILD_MAC
  183.     fEvent.what = nullEvent;
  184. #endif
  185. #ifdef FW_BUILD_WIN
  186.     fEvent.message = WM_NULL;
  187. #endif
  188. }
  189.  
  190. //----------------------------------------------------------------------------------------
  191. //    FW_CNullEvent::~FW_CNullEvent
  192. //----------------------------------------------------------------------------------------
  193. FW_CNullEvent::~FW_CNullEvent()
  194. {
  195. }
  196.  
  197. //========================================================================================
  198. // CLASS FW_CMacWindowEvent
  199. //========================================================================================
  200.  
  201. #ifdef FW_BUILD_MAC
  202. //----------------------------------------------------------------------------------------
  203. //    FW_CMacWindowEvent::FW_CMacWindowEvent
  204. //----------------------------------------------------------------------------------------
  205. FW_CMacWindowEvent::FW_CMacWindowEvent(Environment* ev, ODEventData* theEvent, FW_Boolean propagated) :
  206.     FW_CSystemEvent(ev, theEvent, propagated)
  207. {
  208. }
  209. #endif
  210.  
  211. #ifdef FW_BUILD_MAC
  212. //----------------------------------------------------------------------------------------
  213. //    FW_CMacWindowEvent::~FW_CMacWindowEvent
  214. //----------------------------------------------------------------------------------------
  215. FW_CMacWindowEvent::~FW_CMacWindowEvent()
  216. {
  217. }
  218. #endif
  219.  
  220. //========================================================================================
  221. // CLASS FW_CMouseEvent
  222. //========================================================================================
  223.  
  224. //----------------------------------------------------------------------------------------
  225. //    FW_CMouseEvent::FW_CMouseEvent
  226. //----------------------------------------------------------------------------------------
  227. FW_CMouseEvent::FW_CMouseEvent(Environment* ev, 
  228.                                 ODEventData* theEvent, 
  229.                                 ODFacet* theFacet, 
  230.                                 EButtonState theState, 
  231.                                 FW_Boolean propagated, 
  232.                                 short numOfClicks) :
  233.     FW_CSystemEvent(ev, theEvent, propagated),
  234.     fFacet(theFacet),
  235.     fButtonState(theState),
  236.     fNumberOfClicks(numOfClicks)
  237. {
  238. #ifdef FW_BUILD_MAC
  239.     fWhichButton = kLeftMouseButton;
  240. #endif
  241. #ifdef FW_BUILD_WIN
  242.     if (theEvent->message == WM_LBUTTONDOWN || theEvent->message == WM_LBUTTONUP)
  243.         fWhichButton = kLeftMouseButton;
  244.     else if (theEvent->message == WM_MBUTTONDOWN || theEvent->message == WM_RBUTTONUP)
  245.         fWhichButton = kMiddleMouseButton;
  246.     else
  247.         fWhichButton = kRightMouseButton;
  248. #endif
  249. }
  250.  
  251. //----------------------------------------------------------------------------------------
  252. //    FW_CMouseEvent::FW_CMouseEvent
  253. //----------------------------------------------------------------------------------------
  254. FW_CMouseEvent::FW_CMouseEvent(Environment* ev, 
  255.                             ODFacet* theFacet,
  256.                             EButtonState theState,
  257.                             EWhichButton initialButton,
  258.                             ODPlatformWindow theWindow,
  259.                             FW_PlatformEventTime when,
  260.                             const FW_CPoint& where,
  261.                             unsigned short modifiers,
  262.                             short numOfClicks) :
  263.     FW_CSystemEvent(ev, theWindow, when),
  264.     fFacet(theFacet),
  265.     fButtonState(theState),
  266.     fWhichButton(initialButton),
  267.     fNumberOfClicks(numOfClicks)
  268. {
  269. #ifdef FW_BUILD_MAC
  270.     if (theState == kMouseButtonDown)
  271.         fEvent.what = mouseDown;
  272.     else
  273.         fEvent.what = mouseUp;
  274.  
  275.     fEvent.where = where.AsPlatformPoint();
  276.     
  277.     if (modifiers & kExtend)
  278.         fEvent.modifiers += shiftKey;
  279.     if (modifiers & kItem)
  280.         fEvent.modifiers += cmdKey;
  281.     if (modifiers & kCopy)
  282.         fEvent.modifiers += optionKey;
  283.     if (modifiers & kControl)
  284.         fEvent.modifiers += controlKey;
  285. #endif
  286.  
  287. #ifdef FW_BUILD_WIN
  288.     if (theState == kMouseButtonDown)
  289.     {
  290.         if (initialButton == kLeftMouseButton)
  291.             fEvent.message = WM_LBUTTONDOWN;
  292.         else if (initialButton == kMiddleMouseButton)
  293.             fEvent.message = WM_MBUTTONDOWN;
  294.         else
  295.             fEvent.message = WM_RBUTTONDOWN;
  296.     }
  297.     else
  298.     {
  299.         if (initialButton == kLeftMouseButton)
  300.             fEvent.message = WM_LBUTTONUP;
  301.         else if (initialButton == kMiddleMouseButton)
  302.             fEvent.message = WM_MBUTTONUP;
  303.         else
  304.             fEvent.message = WM_RBUTTONUP;
  305.     }
  306.     
  307.     fEvent.pt = where.AsPlatformPoint();
  308.     fEvent.lParam = MAKELONG(fEvent.pt.x, fEvent.pt.y);
  309.  
  310.     if (modifiers & kExtend)
  311.         fEvent.wParam += MK_SHIFT;
  312.     if ((modifiers & kItem) || (modifiers & kCopy) || (modifiers & kControl))
  313.         fEvent.wParam += MK_CONTROL;
  314. #endif
  315. }
  316.  
  317. //----------------------------------------------------------------------------------------
  318. //    FW_CMouseEvent::FW_CMouseEvent
  319. //----------------------------------------------------------------------------------------
  320. FW_CMouseEvent::FW_CMouseEvent(Environment* ev, const FW_CEmbeddedMouseEvent& embeddedEvent) :
  321.     FW_CSystemEvent(ev, embeddedEvent)
  322. {
  323.     fFacet = embeddedEvent.GetFacet(ev);
  324.     fButtonState = embeddedEvent.GetButtonState(ev);
  325.     fWhichButton = embeddedEvent.GetInitialButtonPressed(ev);
  326.     fNumberOfClicks = embeddedEvent.GetNumberOfClicks(ev);
  327.  
  328. #ifdef FW_BUILD_MAC
  329.     if (fButtonState == kMouseButtonDown)
  330.         fEvent.what = mouseDown;
  331.     else
  332.         fEvent.what = mouseUp;
  333. #endif
  334.  
  335. #ifdef FW_BUILD_WIN
  336.     if (fButtonState == kMouseButtonDown)
  337.     {
  338.         if (fWhichButton == kLeftMouseButton)
  339.             fEvent.message = WM_LBUTTONDOWN;
  340.         else if (fWhichButton == kMiddleMouseButton)
  341.             fEvent.message = WM_MBUTTONDOWN;
  342.         else
  343.             fEvent.message = WM_RBUTTONDOWN;
  344.     }
  345.     else
  346.     {
  347.         if (fWhichButton == kLeftMouseButton)
  348.             fEvent.message = WM_LBUTTONUP;
  349.         else if (fWhichButton == kMiddleMouseButton)
  350.             fEvent.message = WM_MBUTTONUP;
  351.         else
  352.             fEvent.message = WM_RBUTTONUP;
  353.     }
  354. #endif
  355. }
  356.  
  357. //----------------------------------------------------------------------------------------
  358. //    FW_CMouseEvent::FW_CMouseEvent
  359. //----------------------------------------------------------------------------------------
  360. FW_CMouseEvent::FW_CMouseEvent(Environment* ev, const FW_CMouseEvent& other) :
  361.     FW_CSystemEvent(ev, other)
  362. {
  363.     fFacet = other.GetFacet(ev);
  364.     fButtonState = other.GetButtonState(ev);
  365.     fWhichButton = other.GetInitialButtonPressed(ev);
  366.     fNumberOfClicks = other.GetNumberOfClicks(ev);
  367. }
  368.  
  369. //----------------------------------------------------------------------------------------
  370. //    FW_CMouseEvent::~FW_CMouseEvent
  371. //----------------------------------------------------------------------------------------
  372. FW_CMouseEvent::~FW_CMouseEvent()
  373. {
  374. }
  375.  
  376. //----------------------------------------------------------------------------------------
  377. //    FW_CMouseEvent::GetLogicalMousePosition
  378. //----------------------------------------------------------------------------------------
  379.  
  380. FW_CPoint FW_CMouseEvent::GetLogicalMousePosition(Environment* ev, 
  381.                                             const FW_CMapping& mapping) const
  382. {
  383.     // [LSD] use kFrame for now: to fix later
  384.     FW_CPoint position = FW_CMouseEvent::GetMousePosition(ev, kFrame); 
  385.     
  386.     //     Note: I am calling DeviceToLogical and not LogicalToDevice because at this point position
  387.     //    is in "OpenDoc" coordinate (72 dpi on both platform) and I want it in logical coordinate
  388.     FW_CPlatformPoint plfmPoint = position;
  389.     mapping.DeviceToLogical(ev, plfmPoint, position, FW_GetFacetGraphicDevice(ev, fFacet), NULL);
  390.     
  391.     return position;
  392. }
  393.  
  394. //----------------------------------------------------------------------------------------
  395. //    FW_CMouseEvent::GetMousePosition
  396. //----------------------------------------------------------------------------------------
  397. // [LSD] This cannot return a position in Content coordinates because the ContentView may 
  398. // not be at the frame's origin.  Get Frame coordinates and convert to Content afterward.
  399.  
  400. FW_CPoint FW_CMouseEvent::GetMousePosition(Environment* ev, ECoordinates coordinate) const
  401. {
  402. #ifdef FW_BUILD_MAC
  403.         FW_CPlatformPoint mousePos(fEvent.where);
  404. #endif
  405. #ifdef FW_BUILD_WIN
  406.         FW_CPlatformPoint mousePos(fEvent.pt);
  407. #endif
  408.  
  409.     // ----- Convert into window coordinates -----
  410.     if (coordinate != kScreen)
  411.     {
  412. #ifdef FW_BUILD_MAC
  413.         ODWindow* aqWindow = fFacet->GetWindow(ev);        
  414.         GrafPtr svGrafPtr;
  415.         ::GetPort(&svGrafPtr);
  416.         GrafPtr grafPtr = aqWindow->GetPlatformWindow(ev);
  417.         ::SetPort(grafPtr);
  418.         FW_CPlatformPoint svOrigin(grafPtr->portRect.left, grafPtr->portRect.top);
  419.         ::SetOrigin(0,0);
  420.         ::GlobalToLocal(&mousePos);
  421.         ::SetOrigin(svOrigin.h, svOrigin.v);
  422.         ::SetPort(svGrafPtr);
  423. #endif
  424.  
  425. #ifdef FW_BUILD_WIN
  426.         // Use the global coordinate because the lParam field gets replaced if the event
  427.         // is an embedded mouse event
  428.         // !!! May need to worry about scrolling here
  429.         ::ScreenToClient((HWND)fEvent.hwnd, &mousePos);
  430.             // [WIN_PORT] fEvent.hwnd is a void* not an HWND!
  431. #endif
  432.     }
  433.     
  434.     FW_CPoint position = mousePos;
  435.     if (coordinate == kFrame)
  436.         FW_WindowToFrame(ev, fFacet, position);
  437.     
  438.     return position;
  439. }
  440.  
  441. //----------------------------------------------------------------------------------------
  442. //    FW_CMouseEvent::IsLeftButtonPressed
  443. //----------------------------------------------------------------------------------------
  444. FW_Boolean FW_CMouseEvent::IsLeftButtonPressed(Environment* ev) const
  445. {
  446. FW_UNUSED(ev);
  447. #ifdef FW_BUILD_MAC
  448.     return TRUE;
  449. #endif
  450. #ifdef FW_BUILD_WIN
  451.     return (fWhichButton == kLeftMouseButton) ? TRUE : (fEvent.wParam & MK_LBUTTON) != 0;
  452. #endif
  453. }
  454.  
  455. //----------------------------------------------------------------------------------------
  456. //    FW_CMouseEvent::IsMiddleButtonPressed
  457. //----------------------------------------------------------------------------------------
  458. FW_Boolean FW_CMouseEvent::IsMiddleButtonPressed(Environment* ev) const
  459. {
  460. FW_UNUSED(ev);
  461. #ifdef FW_BUILD_MAC
  462.     return FALSE;
  463. #endif
  464. #ifdef FW_BUILD_WIN
  465.     return (fWhichButton == kMiddleMouseButton) ? TRUE : (fEvent.wParam & MK_MBUTTON) != 0;
  466. #endif
  467. }
  468.  
  469. //----------------------------------------------------------------------------------------
  470. //    FW_CMouseEvent::IsRightButtonPressed
  471. //----------------------------------------------------------------------------------------
  472. FW_Boolean FW_CMouseEvent::IsRightButtonPressed(Environment* ev) const
  473. {
  474. FW_UNUSED(ev);
  475. #ifdef FW_BUILD_MAC
  476.     return FALSE;
  477. #endif
  478. #ifdef FW_BUILD_WIN
  479.     return (fWhichButton == kRightMouseButton) ? TRUE : (fEvent.wParam & MK_RBUTTON) != 0;
  480. #endif
  481. }
  482.  
  483. //----------------------------------------------------------------------------------------
  484. //    FW_CMouseEvent::WaitMouseMoved
  485. //----------------------------------------------------------------------------------------
  486. FW_Boolean FW_CMouseEvent::WaitUntilMouseMoved(Environment* ev) const
  487. {
  488. FW_UNUSED(ev);
  489. #ifdef FW_BUILD_MAC
  490.     return ::WaitMouseMoved(fEvent.where);
  491. #endif
  492. #ifdef FW_BUILD_WIN
  493.     MSG event;
  494.     BOOL bMoved = FALSE;
  495.     DWORD InitialTick = ::GetTickCount();
  496.     HWND hwnd = fFacet->GetWindow(ev)->GetPlatformWindow(ev);
  497.     /* Don't capture the mouse if we're minimized!
  498.      */
  499.     if(IsIconic(hwnd))
  500.         return FALSE;
  501.  
  502.     ::SetCapture(hwnd);
  503.     do
  504.     {
  505.         ::GetMessage(&event,NULL,NULL,NULL);
  506.         ::TranslateMessage(&event);    // Translates virtual key codes
  507.         ::DispatchMessage(&event);     // Dispatches message to window
  508.  
  509.         if (  (event.message == WM_LBUTTONUP)
  510.             || (event.message == WM_RBUTTONUP)
  511.             || (event.message == WM_LBUTTONDOWN)
  512.             || (event.message == WM_RBUTTONDOWN)
  513.             || (event.message == WM_CHAR)
  514.             || (::GetTickCount() < InitialTick)
  515.             || (::GetTickCount() > InitialTick+300)
  516.             )
  517.             break;
  518.         else if (event.message == WM_MOUSEMOVE)
  519.         {
  520.             int deltax = fEvent.pt.x - event.pt.x;
  521.             if (deltax<0) deltax *= -1;
  522.             int deltay = fEvent.pt.y - event.pt.y;
  523.             if (deltay<0) deltay *= -1;
  524.             bMoved = ((deltay >= 3) || (deltax >= 3));
  525.         }
  526.     } while(!bMoved);
  527.     ::ReleaseCapture();
  528.  
  529.     return  bMoved;
  530. #endif
  531.  
  532. }
  533.  
  534. //========================================================================================
  535. // CLASS FW_CEmbeddedMouseEvent
  536. //========================================================================================
  537.  
  538. //----------------------------------------------------------------------------------------
  539. //    FW_CEmbeddedMouseEvent::FW_CEmbeddedMouseEvent
  540. //----------------------------------------------------------------------------------------
  541. FW_CEmbeddedMouseEvent::FW_CEmbeddedMouseEvent(Environment* ev, ODEventData* theEvent,
  542.                                             ODFacet* theFacet,
  543.                                             ODFrame* theEmbeddedFrame,
  544.                                             ODFacet* theEmbeddedFacet,
  545.                                             EButtonState theState,
  546.                                             FW_Boolean propagated,
  547.                                             short numOfClicks) :
  548.     FW_CMouseEvent(ev, theEvent, theFacet, theState, propagated, numOfClicks),
  549.     fEmbeddedFrame(theEmbeddedFrame),
  550.     fEmbeddedFacet(theEmbeddedFacet)
  551. {
  552. }
  553.  
  554. //----------------------------------------------------------------------------------------
  555. //    FW_CEmbeddedMouseEvent::FW_CEmbeddedMouseEvent
  556. //----------------------------------------------------------------------------------------
  557. FW_CEmbeddedMouseEvent::FW_CEmbeddedMouseEvent(Environment* ev, ODFacet* theFacet,
  558.                                             ODFrame* theEmbeddedFrame,
  559.                                             ODFacet* theEmbeddedFacet,
  560.                                             EButtonState theState,
  561.                                             EWhichButton initialButton,
  562.                                             ODPlatformWindow theWindow,
  563.                                             FW_PlatformEventTime when,
  564.                                             const FW_CPoint& where,
  565.                                             unsigned short modifiers,
  566.                                             short numOfClicks) :
  567.     FW_CMouseEvent(ev, theFacet, theState, initialButton, theWindow, when, where, modifiers, numOfClicks),
  568.     fEmbeddedFrame(theEmbeddedFrame),
  569.     fEmbeddedFacet(theEmbeddedFacet)
  570. {
  571. #ifdef FW_BUILD_MAC
  572.     if (theState == kMouseButtonDown)
  573.         fEvent.what = kODEvtMouseDownEmbedded;
  574.     else
  575.         fEvent.what = kODEvtMouseUpEmbedded;
  576. #endif
  577. #ifdef FW_BUILD_WIN
  578.     if (theState == kMouseButtonDown)
  579.         fEvent.message = kODEvtMouseDownEmbedded;
  580.     else
  581.         fEvent.message = kODEvtMouseUpEmbedded;
  582. #endif
  583. }
  584.  
  585. //----------------------------------------------------------------------------------------
  586. //    FW_CEmbeddedMouseEvent::FW_CEmbeddedMouseEvent
  587. //----------------------------------------------------------------------------------------
  588. FW_CEmbeddedMouseEvent::FW_CEmbeddedMouseEvent(Environment* ev, const FW_CEmbeddedMouseEvent& other) :
  589.     FW_CMouseEvent(ev, other)
  590. {
  591. }
  592.  
  593. //----------------------------------------------------------------------------------------
  594. //    FW_CEmbeddedMouseEvent::~FW_CEmbeddedMouseEvent
  595. //----------------------------------------------------------------------------------------
  596. FW_CEmbeddedMouseEvent::~FW_CEmbeddedMouseEvent()
  597. {
  598. }
  599.  
  600. //----------------------------------------------------------------------------------------
  601. //    FW_CEmbeddedMouseEvent::GetEmbeddedFrame
  602. //----------------------------------------------------------------------------------------
  603. ODFrame* FW_CEmbeddedMouseEvent::GetEmbeddedFrame(Environment* ev) const
  604. {
  605. FW_UNUSED(ev);
  606.     return fEmbeddedFrame;
  607. }
  608.  
  609. //----------------------------------------------------------------------------------------
  610. //    FW_CEmbeddedMouseEvent::GetEmbeddedFacet
  611. //----------------------------------------------------------------------------------------
  612. ODFacet* FW_CEmbeddedMouseEvent::GetEmbeddedFacet(Environment* ev) const
  613. {
  614. FW_UNUSED(ev);
  615.     return fEmbeddedFacet;
  616. }
  617.  
  618. //========================================================================================
  619. // CLASS FW_CBorderMouseEvent
  620. //========================================================================================
  621.  
  622. //----------------------------------------------------------------------------------------
  623. //    FW_CBorderMouseEvent::FW_CBorderMouseEvent
  624. //----------------------------------------------------------------------------------------
  625. FW_CBorderMouseEvent::FW_CBorderMouseEvent(Environment* ev, 
  626.                                             ODEventData* theEvent,
  627.                                             ODFacet* theFacet,
  628.                                             ODFrame* theEmbeddedFrame,
  629.                                             ODFacet* theEmbeddedFacet,
  630.                                             EButtonState theState,
  631.                                             FW_Boolean propagated,
  632.                                             short numOfClicks) :
  633.     FW_CMouseEvent(ev, theEvent, theFacet, theState, propagated, numOfClicks),
  634.     fEmbeddedFrame(theEmbeddedFrame),
  635.     fEmbeddedFacet(theEmbeddedFacet)
  636. {
  637. }
  638.  
  639. //----------------------------------------------------------------------------------------
  640. //    FW_CBorderMouseEvent::FW_CBorderMouseEvent
  641. //----------------------------------------------------------------------------------------
  642. FW_CBorderMouseEvent::FW_CBorderMouseEvent(Environment* ev, ODFacet* theFacet,
  643.                                             ODFrame* theEmbeddedFrame,
  644.                                             ODFacet* theEmbeddedFacet,
  645.                                             EButtonState theState,
  646.                                             EWhichButton initialButton,
  647.                                             ODPlatformWindow theWindow,
  648.                                             FW_PlatformEventTime when,
  649.                                             const FW_CPoint& where,
  650.                                             unsigned short modifiers,
  651.                                             short numOfClicks) :
  652.     FW_CMouseEvent(ev, theFacet, theState, initialButton, theWindow, when, where, modifiers, numOfClicks),
  653.     fEmbeddedFrame(theEmbeddedFrame),
  654.     fEmbeddedFacet(theEmbeddedFacet)
  655. {
  656. #ifdef FW_BUILD_MAC
  657.     if (theState == kMouseButtonDown)
  658.         fEvent.what = kODEvtMouseDownBorder;
  659.     else
  660.         fEvent.what = kODEvtMouseUpBorder;
  661. #endif
  662. #ifdef FW_BUILD_WIN
  663.     if (theState == kMouseButtonDown)
  664.         fEvent.message = kODEvtMouseDownBorder;
  665.     else
  666.         fEvent.message = kODEvtMouseUpBorder;
  667. #endif
  668. }
  669.  
  670.  
  671. //----------------------------------------------------------------------------------------
  672. //    FW_CBorderMouseEvent::FW_CBorderMouseEvent
  673. //----------------------------------------------------------------------------------------
  674. FW_CBorderMouseEvent::FW_CBorderMouseEvent(Environment* ev, const FW_CBorderMouseEvent& other) :
  675.     FW_CMouseEvent(ev, other)
  676. {
  677. }
  678.  
  679. //----------------------------------------------------------------------------------------
  680. //    FW_CBorderMouseEvent::~FW_CBorderMouseEvent
  681. //----------------------------------------------------------------------------------------
  682. FW_CBorderMouseEvent::~FW_CBorderMouseEvent()
  683. {
  684. }
  685.  
  686. //----------------------------------------------------------------------------------------
  687. //    FW_CBorderMouseEvent::GetEmbeddedFrame
  688. //----------------------------------------------------------------------------------------
  689. ODFrame* FW_CBorderMouseEvent::GetEmbeddedFrame(Environment* ev) const
  690. {
  691. FW_UNUSED(ev);
  692.     return fEmbeddedFrame;
  693. }
  694.  
  695. //----------------------------------------------------------------------------------------
  696. //    FW_CBorderMouseEvent::GetEmbeddedFacet
  697. //----------------------------------------------------------------------------------------
  698. ODFacet* FW_CBorderMouseEvent::GetEmbeddedFacet(Environment* ev) const
  699. {
  700. FW_UNUSED(ev);
  701.     return fEmbeddedFacet;
  702. }
  703.  
  704.  
  705. //========================================================================================
  706. // CLASS FW_CVirtualKeyEvent
  707. //========================================================================================
  708.  
  709. //----------------------------------------------------------------------------------------
  710. //    FW_CVirtualKeyEvent::FW_CVirtualKeyEvent
  711. //----------------------------------------------------------------------------------------
  712. FW_CVirtualKeyEvent::FW_CVirtualKeyEvent(Environment* ev, 
  713.                                         ODEventData* theEvent,
  714.                                         KeyboardState theKeyboardState,
  715.                                         FW_Boolean propagated,
  716.                                         unsigned short repeatCount) :
  717.     FW_CSystemEvent(ev, theEvent, propagated),
  718.     fKeyboardState(theKeyboardState),
  719.     fRepeatCount(repeatCount)
  720. {
  721. }
  722.  
  723. //----------------------------------------------------------------------------------------
  724. //    FW_CVirtualKeyEvent::FW_CVirtualKeyEvent
  725. //----------------------------------------------------------------------------------------
  726. FW_CVirtualKeyEvent::FW_CVirtualKeyEvent(Environment* ev, 
  727.                                         KeyboardState theKeyboardState,
  728.                                         short keyCode,
  729.                                         ODPlatformWindow theWindow,
  730.                                         FW_PlatformEventTime when,
  731.                                         unsigned short repeatCount) :
  732.     FW_CSystemEvent(ev, theWindow, when),
  733.     fKeyboardState(theKeyboardState),
  734.     fRepeatCount(repeatCount)
  735. {
  736. #ifdef FW_BUILD_MAC
  737.     if (theKeyboardState == kKeyDown)
  738.     {
  739.         if (repeatCount > 0)
  740.             fEvent.what = autoKey;
  741.         else
  742.             fEvent.what = keyDown;
  743.     }
  744.     else
  745.         fEvent.what = keyUp;
  746.  
  747.     fEvent.message = keyCode << 8;
  748. #endif
  749.  
  750. #ifdef FW_BUILD_WIN
  751.     if (theKeyboardState == kKeyDown)
  752.             fEvent.message = WM_KEYDOWN;
  753.     else
  754.             fEvent.message = WM_KEYUP;
  755.  
  756.     fEvent.wParam = keyCode;
  757.     fEvent.lParam = repeatCount;
  758. #endif
  759. }
  760.  
  761. //----------------------------------------------------------------------------------------
  762. //    FW_CVirtualKeyEvent::FW_CVirtualKeyEvent
  763. //----------------------------------------------------------------------------------------
  764. FW_CVirtualKeyEvent::FW_CVirtualKeyEvent(Environment* ev, const FW_CVirtualKeyEvent& other) :
  765.     FW_CSystemEvent(ev, other)
  766. {
  767.     fKeyboardState = other.GetKeyboardState(ev);
  768.     fRepeatCount = other.GetRepeatCount(ev);
  769. }
  770.  
  771. //----------------------------------------------------------------------------------------
  772. //    FW_CVirtualKeyEvent::~FW_CVirtualKeyEvent
  773. //----------------------------------------------------------------------------------------
  774. FW_CVirtualKeyEvent::~FW_CVirtualKeyEvent()
  775. {
  776. }
  777.  
  778. //----------------------------------------------------------------------------------------
  779. //    FW_CVirtualKeyEvent::GetKeyCode
  780. //----------------------------------------------------------------------------------------
  781. short FW_CVirtualKeyEvent::GetKeyCode(Environment* ev) const
  782. {
  783. FW_UNUSED(ev);
  784. #ifdef FW_BUILD_MAC
  785.     return (fEvent.message & keyCodeMask) >> 8;
  786. #endif
  787. #ifdef FW_BUILD_WIN
  788.     return LOWORD(fEvent.wParam);
  789. #endif
  790. }
  791.  
  792.  
  793. //----------------------------------------------------------------------------------------
  794. //    FW_CVirtualKeyEvent::IsCommandPeriod
  795. //----------------------------------------------------------------------------------------
  796.  
  797. FW_Boolean FW_CVirtualKeyEvent::IsCommandPeriod(Environment* ev) const
  798. {
  799. FW_UNUSED(ev);
  800. #ifdef FW_BUILD_MAC
  801.     FW_Boolean    isCommandPeriod = FALSE;
  802.     
  803.     if (fEvent.modifiers & cmdKey) {    
  804.     
  805.         long    virtualKey = (fEvent.message & keyCodeMask) >> 8;
  806.         short    keyCode = (fEvent.modifiers & 0xFE00) | virtualKey;
  807.         
  808.         Ptr        theKCHR = (Ptr) ::GetScriptManagerVariable(smKCHRCache);
  809.         unsigned long state = 0;
  810.         long    keyInfo = ::KeyTranslate(theKCHR, keyCode, &state);        
  811.         long    char1 = keyInfo & 0x000000FF;            
  812.         long    char2 = (keyInfo & 0x00FF0000) >> 16;    
  813.     
  814.         isCommandPeriod = (char1 == 0x2E) || (char2 == 0x2E);
  815.     }
  816.     
  817.     return isCommandPeriod;
  818. #endif
  819.  
  820. #ifdef FW_BUILD_WIN
  821.     return FALSE;
  822. #endif
  823. }
  824.  
  825. //========================================================================================
  826. // CLASS FW_CCharKeyEvent
  827. //========================================================================================
  828.  
  829. //----------------------------------------------------------------------------------------
  830. //    FW_CCharKeyEvent::FW_CCharKeyEvent
  831. //----------------------------------------------------------------------------------------
  832. FW_CCharKeyEvent::FW_CCharKeyEvent(Environment* ev, ODEventData* theEvent, FW_Boolean propagated, unsigned short repeatCount) :
  833.     FW_CSystemEvent(ev, theEvent, propagated),
  834.     fRepeatCount(repeatCount)
  835. {
  836. }
  837.  
  838. //----------------------------------------------------------------------------------------
  839. //    FW_CCharKeyEvent::FW_CCharKeyEvent
  840. //----------------------------------------------------------------------------------------
  841. FW_CCharKeyEvent::FW_CCharKeyEvent(Environment* ev, 
  842.                                     char keyChar,
  843.                                     ODPlatformWindow theWindow,
  844.                                     FW_PlatformEventTime when,
  845.                                     unsigned short repeatCount) :
  846.     FW_CSystemEvent(ev, theWindow, when),
  847.     fRepeatCount(repeatCount)
  848. {
  849. #ifdef FW_BUILD_MAC
  850.     fEvent.what = keyDown;
  851.     fEvent.message = keyChar;
  852. #endif
  853.  
  854. #ifdef FW_BUILD_WIN
  855.     fEvent.message = WM_CHAR;
  856.     fEvent.wParam = keyChar;
  857.     fEvent.lParam = repeatCount;
  858. #endif
  859. }
  860.  
  861. //----------------------------------------------------------------------------------------
  862. //    FW_CCharKeyEvent::FW_CCharKeyEvent
  863. //----------------------------------------------------------------------------------------
  864. FW_CCharKeyEvent::FW_CCharKeyEvent(Environment* ev, const FW_CCharKeyEvent& other) :
  865.     FW_CSystemEvent(ev, other)
  866. {
  867.     fRepeatCount = other.GetRepeatCount(ev);
  868. }
  869.  
  870. //----------------------------------------------------------------------------------------
  871. //    FW_CCharKeyEvent::~FW_CCharKeyEvent
  872. //----------------------------------------------------------------------------------------
  873. FW_CCharKeyEvent::~FW_CCharKeyEvent()
  874. {
  875. }
  876.  
  877. //----------------------------------------------------------------------------------------
  878. //    FW_CCharKeyEvent::GetChar
  879. //----------------------------------------------------------------------------------------
  880. char FW_CCharKeyEvent::GetChar(Environment* ev) const
  881. {
  882. FW_UNUSED(ev);
  883. #ifdef FW_BUILD_MAC
  884.     return (char)fEvent.message & charCodeMask;
  885. #endif
  886. #ifdef FW_BUILD_WIN
  887.     return (char)fEvent.wParam;
  888. #endif
  889. }
  890.  
  891. //========================================================================================
  892. // CLASS FW_CActivateEvent
  893. //========================================================================================
  894.  
  895. //----------------------------------------------------------------------------------------
  896. //    FW_CActivateEvent::FW_CActivateEvent
  897. //----------------------------------------------------------------------------------------
  898. FW_CActivateEvent::FW_CActivateEvent(Environment* ev, 
  899.                                     ODEventData* theEvent, 
  900.                                     ODFacet* facet, 
  901.                                     FW_Boolean theState,
  902.                                     FW_Boolean propagated) :
  903.     FW_CSystemEvent(ev, theEvent, propagated),
  904.     fActivationState(theState),
  905.     fFacet(facet)
  906. {
  907. #ifdef FW_BUILD_MAC
  908.     fPlatformWindow = (ODPlatformWindow)fEvent.message;
  909. #endif
  910. #ifdef FW_BUILD_WIN
  911.     fPlatformWindow = (ODPlatformWindow)LOWORD(fEvent.lParam);
  912.         // [WIN_PORT] Messge param cracking for Win32/Win16 -- different!
  913. #endif
  914. }
  915.  
  916. //----------------------------------------------------------------------------------------
  917. //    FW_CActivateEvent::FW_CActivateEvent
  918. //----------------------------------------------------------------------------------------
  919. FW_CActivateEvent::FW_CActivateEvent(Environment* ev, 
  920.                                         ODFacet* facet,
  921.                                         FW_Boolean theState,
  922.                                         ODPlatformWindow theWindow,
  923.                                         FW_PlatformEventTime when) :
  924.     FW_CSystemEvent(ev, theWindow, when),
  925.     fActivationState(theState),
  926.     fFacet(facet)
  927. {
  928. #ifdef FW_BUILD_MAC
  929.     fEvent.what = activateEvt;
  930.     fEvent.message = (long)theWindow;
  931.     if (theState)
  932.         fEvent.modifiers = activeFlag;
  933. #endif
  934. #ifdef FW_BUILD_WIN
  935.     fEvent.message = WM_ACTIVATE;
  936.     if (theState)
  937.         fEvent.wParam = WA_ACTIVE;
  938.     else
  939.         fEvent.wParam = WA_INACTIVE;
  940.     fEvent.lParam = (LPARAM) theWindow;
  941. #endif
  942. }
  943.  
  944. //----------------------------------------------------------------------------------------
  945. //    FW_CActivateEvent::FW_CActivateEvent
  946. //----------------------------------------------------------------------------------------
  947. FW_CActivateEvent::FW_CActivateEvent(Environment* ev, const FW_CActivateEvent& other) :
  948.     FW_CSystemEvent(ev, other),
  949.     fActivationState(other.fActivationState),
  950.     fFacet(other.fFacet)
  951. {
  952. }
  953.  
  954. //----------------------------------------------------------------------------------------
  955. //    FW_CActivateEvent::~FW_CActivateEvent
  956. //----------------------------------------------------------------------------------------
  957. FW_CActivateEvent::~FW_CActivateEvent()
  958. {
  959. }
  960.  
  961. //========================================================================================
  962. // CLASS FW_CSuspendResumeEvent
  963. //========================================================================================
  964.  
  965. //----------------------------------------------------------------------------------------
  966. //    FW_CSuspendResumeEvent::FW_CSuspendResumeEvent
  967. //----------------------------------------------------------------------------------------
  968. FW_CSuspendResumeEvent::FW_CSuspendResumeEvent(Environment* ev, 
  969.                                                 ODEventData* theEvent, 
  970.                                                 ODFacet* facet, 
  971.                                                 FW_Boolean isGoingToBackground,
  972.                                                 FW_Boolean propagated) :
  973.     FW_CSystemEvent(ev, theEvent, propagated),
  974.     fIsGoingToBackground(isGoingToBackground),
  975.     fFacet(facet)
  976. {
  977. }
  978.  
  979. //----------------------------------------------------------------------------------------
  980. //    FW_CSuspendResumeEvent::FW_CSuspendResumeEvent
  981. //----------------------------------------------------------------------------------------
  982. FW_CSuspendResumeEvent::FW_CSuspendResumeEvent(Environment* ev, const FW_CSuspendResumeEvent& other) :
  983.     FW_CSystemEvent(ev, other),
  984.     fIsGoingToBackground(other.fIsGoingToBackground)
  985. {
  986. }
  987.  
  988. //----------------------------------------------------------------------------------------
  989. //    FW_CSuspendResumeEvent::~FW_CSuspendResumeEvent
  990. //----------------------------------------------------------------------------------------
  991. FW_CSuspendResumeEvent::~FW_CSuspendResumeEvent()
  992. {
  993. }
  994.  
  995. //========================================================================================
  996. // CLASS FW_CMenuEvent
  997. //========================================================================================
  998.  
  999. //----------------------------------------------------------------------------------------
  1000. //    FW_CMenuEvent::FW_CMenuEvent
  1001. //----------------------------------------------------------------------------------------
  1002. FW_CMenuEvent::FW_CMenuEvent(Environment* ev, ODEventData* theEvent, ODCommandID theCommandID, FW_Boolean propagated) :
  1003.     FW_CSystemEvent(ev, theEvent, propagated),
  1004.     fCommandID(theCommandID)
  1005. {
  1006. }
  1007.  
  1008. //----------------------------------------------------------------------------------------
  1009. //    FW_CMenuEvent::FW_CMenuEvent
  1010. //----------------------------------------------------------------------------------------
  1011. FW_CMenuEvent::FW_CMenuEvent(Environment* ev, 
  1012.                             ODCommandID theCommandID,
  1013.                             ODPlatformWindow theWindow,
  1014.                             FW_PlatformEventTime when) :
  1015.     FW_CSystemEvent(ev, theWindow, when),
  1016.     fCommandID(theCommandID)
  1017. {
  1018. #ifdef FW_BUILD_MAC
  1019.     fEvent.what = kODEvtMenu;
  1020.     fEvent.message = theCommandID;        // !!! this is wrong. should be menu item and id
  1021. #endif
  1022. #ifdef FW_BUILD_WIN
  1023.     fEvent.message = kODEvtMenu;
  1024.     fEvent.wParam = theCommandID;
  1025. #endif
  1026. }
  1027.  
  1028. //----------------------------------------------------------------------------------------
  1029. //    FW_CMenuEvent::FW_CMenuEvent
  1030. //----------------------------------------------------------------------------------------
  1031. FW_CMenuEvent::FW_CMenuEvent(Environment* ev, const FW_CMenuEvent& other) :
  1032.     FW_CSystemEvent(other)
  1033. {
  1034.     fCommandID = other.GetCommandID(ev);
  1035. }
  1036.  
  1037. //----------------------------------------------------------------------------------------
  1038. //    FW_CMenuEvent::~FW_CMenuEvent
  1039. //----------------------------------------------------------------------------------------
  1040. FW_CMenuEvent::~FW_CMenuEvent()
  1041. {
  1042. }
  1043.