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 / FWEventU.cpp < prev   
Encoding:
Text File  |  1995-11-08  |  4.0 KB  |  164 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWEventU.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 FWEVENTU_H
  13. #include "FWEventU.h"
  14. #endif
  15.  
  16. #ifndef FWGC_H
  17. #include "FWGC.h"
  18. #endif
  19.  
  20. #ifndef FWPOINT_H
  21. #include "FWPoint.h"
  22. #endif
  23.  
  24. #ifndef FWACQUIR_H
  25. #include "FWAcquir.h"
  26. #endif
  27.  
  28. #ifndef SOM_ODWindow_xh
  29. #include <Window.xh>
  30. #endif
  31.  
  32. #ifndef SOM_ODFacet_xh
  33. #include <Facet.xh>
  34. #endif
  35.  
  36. #if defined(FW_BUILD_MAC) && !defined(__EVENTS__)
  37. #include <Events.h>
  38. #endif
  39.  
  40. #if defined(FW_BUILD_WIN) && !defined(_INC_WINDOWS)
  41. #include <windows.h>
  42. #endif
  43.  
  44. #if FW_LIB_EXPORT_PRAGMAS
  45. #pragma lib_export on
  46. #endif
  47.  
  48. #pragma segment fwevents
  49.  
  50. //----------------------------------------------------------------------------------------
  51. // ::FW_IsKeyPressed
  52. //----------------------------------------------------------------------------------------
  53.  
  54. FW_Boolean FW_FUNC_ATTR FW_IsKeyPressed(unsigned short theKey)
  55. {
  56. #ifdef FW_BUILD_MAC
  57.     KeyMap theKeyMap;
  58.     ::GetKeys(theKeyMap);
  59.     const unsigned char *theKeys = (const unsigned char *) theKeyMap;
  60.     return ((theKeys[theKey >> 3] >> (theKey & 7)) & 1);
  61. #endif
  62.  
  63. #ifdef FW_BUILD_WIN
  64.     return ((::GetKeyState(theKey) & 0x8000) != 0);
  65. #endif
  66. }
  67.  
  68. //----------------------------------------------------------------------------------------
  69. // ::FW_GetMouseLocation
  70. //----------------------------------------------------------------------------------------
  71. //    return value in frame coordinate
  72.  
  73. FW_CPoint FW_FUNC_ATTR FW_GetMouseLocation(Environment* ev, ODFacet* facet)
  74. {
  75.     FW_SPlatformPoint windowLoc;
  76.     
  77.     ODWindow* window = facet->GetWindow(ev);
  78.     ODPlatformWindow plfmWindow = window->GetPlatformWindow(ev);
  79.     
  80. #ifdef FW_BUILD_MAC
  81.     GrafPtr curPort;
  82.     ::GetPort(&curPort);
  83.     ::SetPort(plfmWindow);
  84.     ::GetMouse(&windowLoc);
  85.     ::SetPort(curPort);
  86. #endif
  87.  
  88. #ifdef FW_BUILD_WIN
  89.     ::GetCursorPos(&windowLoc);
  90.     ::ScreenToClient(plfmWindow, &windowLoc); 
  91. #endif
  92.  
  93.     FW_CAcquiredODTransform aqTransform = facet->
  94. #if FW_OPENDOC_VERSION >= FW_OPENDOC_DR3
  95.         AcquireWindowFrameTransform(ev, NULL);
  96. #else
  97.         GetWindowFrameTransform(ev, NULL);
  98. #endif
  99.  
  100.     FW_CPoint point(windowLoc);
  101.     point.InverseTransform(ev, aqTransform);
  102.     return point;
  103. }
  104.  
  105. //----------------------------------------------------------------------------------------
  106. // ::FW_GetMouseLocation
  107. //----------------------------------------------------------------------------------------
  108. //    return value in content coordinate
  109.  
  110. FW_CPoint FW_FUNC_ATTR FW_GetMouseLocation(ODWindow* theODWindow, FW_CGraphicContext& theGC)
  111. {
  112.     FW_SPlatformPoint plformLoc;
  113.     
  114. #ifdef FW_BUILD_MAC
  115.     ::GetMouse(&plformLoc);
  116. #endif
  117.  
  118. #ifdef FW_BUILD_WIN
  119.     ::GetCursorPos(&plformLoc);
  120.     ODPlatformWindow plfmWindow = theODWindow->GetPlatformWindow(::somGetGlobalEnvironment());
  121.     ::ScreenToClient(plfmWindow, &plformLoc); 
  122. #endif
  123.  
  124.     return theGC.DeviceToLogical(plformLoc);
  125. }
  126.  
  127. //----------------------------------------------------------------------------------------
  128. // ::FW_WaitMouseUp
  129. //----------------------------------------------------------------------------------------
  130.  
  131. FW_Boolean FW_FUNC_ATTR FW_WaitMouseUp()
  132. {
  133. #ifdef FW_BUILD_MAC
  134.     return ::WaitMouseUp();
  135. #endif
  136. #ifdef FW_BUILD_WIN
  137.     MSG event;
  138.     if (::PeekMessage(&event, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE))
  139.     {
  140.         return event.message != WM_LBUTTONUP && 
  141.                 event.message != WM_RBUTTONUP &&
  142.                  event.message != WM_LBUTTONDOWN &&
  143.                 event.message != WM_RBUTTONDOWN;
  144.     }
  145.     return TRUE;
  146. #endif
  147. }
  148.  
  149. //----------------------------------------------------------------------------------------
  150. // ::FW_WaitFor
  151. //----------------------------------------------------------------------------------------
  152.  
  153. void FW_WaitFor(long tickCount)
  154. {
  155. #ifdef FW_BUILD_MAC
  156.     long targetTick = ::TickCount() + tickCount;
  157.     while (::TickCount() <= targetTick) {}
  158. #endif
  159. #ifdef FW_BUILD_WIN
  160.     FW_DEBUG_MESSAGE("Not Yet Implemented");
  161. #endif
  162. }
  163.  
  164.