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

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