home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / OpenDoc / ProcessMap / $Utilities / PartUtils.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-23  |  3.6 KB  |  155 lines  |  [TEXT/MPCC]

  1. /*
  2.     File:        PartUtils.cpp
  3.     Contains:    Part utility functions & classes
  4.     Written by:    PartMaker
  5.  
  6.     Change History (most recent first):
  7.  
  8.     <2>      3/8/95    JS        Updated to b1c13/c14
  9.     <1>      2/2/95    RA        first checked in
  10.     <0>      PartMaker source by Eric Soldan, Tantek Ã‡elik, Jens Alfke, Reggie Adkins
  11. */
  12.  
  13. #ifndef _ALTPOINT_
  14. #include <AltPoint.h>        /* Must come before other OpenDoc includes */
  15. #endif
  16.  
  17. #ifndef _EXCEPT_
  18. #include <Except.h>
  19. #endif
  20.  
  21. #ifndef _ODTYPES_
  22. #include <ODTypes.h>        // MUST BE BEFORE TOOLBOX INCLUDES
  23. #endif
  24.  
  25. #ifndef _CPPROCESSMAP_
  26. #include "CPProcessMap.h"
  27. #endif
  28.  
  29. #ifndef __RESOURCES__
  30. #include <Resources.h>
  31. #endif
  32.  
  33. #ifndef __TOOLUTILS__
  34. #include <ToolUtils.h>
  35. #endif
  36.  
  37. #ifndef __DIALOGS__
  38. #include <Dialogs.h>
  39. #endif
  40.  
  41. #ifndef __EVENTS__
  42. #include <Events.h>
  43. #endif
  44.  
  45. #ifndef SOM_ODWindow_xh
  46. #include <Window.xh>
  47. #endif
  48.  
  49. #ifndef SOM_ODSession_xh
  50. #include <ODSessn.xh>
  51. #endif
  52.  
  53. #ifndef SOM_ODDispatcher_xh
  54. #include <Disptch.xh>
  55. #endif
  56.  
  57. #ifndef _PARTUTILS_
  58. #include "PartUtils.h"
  59. #endif
  60.  
  61.  
  62. #ifdef applec
  63. #pragma segment ProcessMap
  64. #endif
  65.  
  66.  
  67. //----------------------------------------------------------------------------------------
  68. // MyDialogFilter
  69. //----------------------------------------------------------------------------------------
  70.  
  71. pascal Boolean MyDialogFilter(DialogPtr dialog, EventRecord* event, short* itemHit)
  72. {
  73.     ODBoolean handled = kODFalse;
  74.     
  75.     if (event->what == nullEvent ||
  76.         event->what == updateEvt && (WindowPtr) event->message != dialog ||
  77.         event->what == activateEvt && (WindowPtr) event->message != dialog)
  78.     {
  79.         Environment *ev = somGetGlobalEnvironment();
  80.         gSession->GetDispatcher(ev)->Dispatch(ev, (ODEventData*)event);
  81.     }
  82.     else if ((event->what == keyDown) || (event->what == autoKey))
  83.     {
  84.         #define kMyButtonDelay 8
  85.         long    waitTicks;
  86.         short    itemKind;
  87.         Handle    itemHandle;
  88.         Rect    itemRect;
  89.         char key = (char)(event->message & charCodeMask);
  90.         const char kReturnKey = 13;
  91.         const char kEnterKey = 3;
  92.         const char kEscKey = 27;
  93.         
  94.         switch(key)
  95.         {
  96.         case kReturnKey:
  97.         case kEnterKey:
  98.             *itemHit = ok;
  99.             ::GetDialogItem(dialog, ok, &itemKind, &itemHandle, &itemRect);
  100.             ::HiliteControl((ControlHandle)itemHandle, kInButtonControlPart);
  101.             ::Delay(kMyButtonDelay, &waitTicks);/* wait about 8 ticks */
  102.             HiliteControl((ControlHandle)itemHandle, kODFalse);
  103.             handled = kODTrue;
  104.             break;
  105.         case kEscKey:
  106.             *itemHit = cancel;
  107.             ::GetDialogItem(dialog, cancel, &itemKind, &itemHandle, &itemRect);
  108.             ::HiliteControl((ControlHandle)itemHandle, kInButtonControlPart);
  109.             ::Delay(kMyButtonDelay, &waitTicks);
  110.             HiliteControl((ControlHandle)itemHandle, kODFalse);
  111.             handled = kODTrue;
  112.             break;
  113.         }
  114.     }
  115.  
  116.     return handled;
  117. }
  118.  
  119. //----------------------------------------------------------------------------------------
  120. // GetWindowPoint
  121. //----------------------------------------------------------------------------------------
  122.  
  123. void GetWindowPoint(ODWindow *w, Environment *ev,
  124.                     Point globalPoint,
  125.                     ODPoint *localPoint)
  126. {
  127.     GrafPtr curPort;
  128.     ::GetPort(&curPort);
  129.     ::SetPort(w->GetPlatformWindow(ev));
  130.     ::SetOrigin(0,0);
  131.     ::GlobalToLocal(&globalPoint);
  132.     ::SetPort(curPort);
  133.     *localPoint = globalPoint;
  134. }
  135.  
  136. //----------------------------------------------------------------------------------------
  137. // AreTraceKeysDown
  138. //----------------------------------------------------------------------------------------
  139.  
  140. Boolean AreTraceKeysDown()
  141. {
  142.     // test if Control and Option key are both down. Used for toggling EnteringMethod()
  143.     union
  144.     {
  145.         KeyMap asMap;
  146.         Byte asBytes[16];
  147.     };
  148.     
  149.     const short kOptionKey = 58;
  150.     const short kControlKey = 0x3B;
  151.     ::GetKeys(asMap);
  152.     return (asBytes[kOptionKey >> 3] & (1 << (kOptionKey & 0x07))) &&
  153.            (asBytes[kControlKey >> 3] & (1 << (kControlKey & 0x07)));
  154. }
  155.