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 / Sample Code / CALib & You… / Source / CALib / Implementation / ProxyPart / PartUtils.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-07  |  3.1 KB  |  143 lines  |  [TEXT/MPS ]

  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/19/95    RB        Mods for b1c18 compliance.
  11.          <3+>     2/18/95    SJF        Place code in CAProxyPart segment unconditionally
  12.          <3>     2/13/95    SJF        Interim checkin to update project database
  13.          <0>    11/16/94    SJF        first written
  14.          
  15.     To Do:
  16.         implement
  17. */
  18.  
  19. #ifndef _ALTPOINT_
  20. #include <AltPoint.h>        /* Must come before other OpenDoc includes */
  21. #endif
  22.  
  23. #ifndef _EXCEPT_
  24. #include <Except.h>
  25. #endif
  26.  
  27. #ifndef _ODTYPES_
  28. #include <ODTypes.h>        // MUST BE BEFORE TOOLBOX INCLUDES
  29. #endif
  30.  
  31. #ifndef _CAPROXYPART_
  32. #include "CAProxyPart.h"
  33. #endif
  34.  
  35. #ifndef __RESOURCES__
  36. #include <Resources.h>
  37. #endif
  38.  
  39. #ifndef __TOOLUTILS__
  40. #include <ToolUtils.h>
  41. #endif
  42.  
  43. #ifndef __DIALOGS__
  44. #include <Dialogs.h>
  45. #endif
  46.  
  47. #ifndef SOM_ODWindow_xh
  48. #include <Window.xh>
  49. #endif
  50.  
  51. #ifndef SOM_ODSession_xh
  52. #include <ODSessn.xh>
  53. #endif
  54.  
  55. #ifndef SOM_ODDispatcher_xh
  56. #include <Disptch.xh>
  57. #endif
  58.  
  59. #ifndef _PARTUTILS_
  60. #include "PartUtils.h"
  61. #endif
  62.  
  63. #ifndef __CONTROLS__
  64. #include <Controls.h>
  65. #endif
  66.  
  67. //#ifdef applec
  68. #pragma segment CAProxyPart
  69. //#endif
  70.  
  71.  
  72. //--------------------------------------------------------------------
  73. // MyDialogFilter
  74. //--------------------------------------------------------------------
  75.  
  76. pascal Boolean
  77. MyDialogFilter(DialogPtr dialog, EventRecord* event, short* itemHit)
  78. {
  79.     ODBoolean handled = kODFalse;
  80.     
  81.     if (event->what == nullEvent ||
  82.         event->what == updateEvt && (WindowPtr) event->message != dialog ||
  83.         event->what == activateEvt && (WindowPtr) event->message != dialog)
  84.     {
  85.         Environment *ev = somGetGlobalEnvironment();
  86.         gSession->GetDispatcher(ev)->Dispatch(ev,(ODEventData*)event);
  87.     }
  88.     else if ((event->what == keyDown) || (event->what == autoKey))
  89.     {
  90.         #define kMyButtonDelay 8
  91.         long    waitTicks;
  92.         short    itemKind;
  93.         Handle    itemHandle;
  94.         Rect    itemRect;
  95.         char key = (char)(event->message & charCodeMask);
  96.         const char kReturnKey = 13;
  97.         const char kEnterKey = 3;
  98.         const char kEscKey = 27;
  99.         
  100.         switch(key)
  101.         {
  102.             case kReturnKey:
  103.             case kEnterKey:
  104.                 *itemHit = ok;
  105.                 GetDialogItem(dialog,ok,&itemKind,&itemHandle,&itemRect);
  106.                 HiliteControl((ControlHandle)itemHandle,kControlButtonPart);
  107.                 Delay(kMyButtonDelay,&waitTicks);/* wait about 8 ticks */
  108.                 HiliteControl((ControlHandle)itemHandle,kODFalse);
  109.                 handled = kODTrue;
  110.                 break;
  111.             case kEscKey:
  112.                 *itemHit = cancel;
  113.                 GetDialogItem(dialog,cancel,&itemKind,&itemHandle,&itemRect);
  114.                 HiliteControl((ControlHandle)itemHandle,kControlButtonPart);
  115.                 Delay(kMyButtonDelay,&waitTicks);
  116.                 HiliteControl((ControlHandle)itemHandle,kODFalse);
  117.                 handled = kODTrue;
  118.                 break;
  119.         }
  120.     }
  121.  
  122.     return handled;
  123. }
  124.  
  125.  
  126. //-------------------------------------------------------------------------------------
  127. // GetWindowPoint
  128. //-------------------------------------------------------------------------------------
  129.  
  130. void
  131. GetWindowPoint(ODWindow *w, Environment *ev,
  132.                         Point globalPoint,
  133.                         ODPoint *localPoint)
  134. {
  135.     GrafPtr curPort;
  136.     GetPort(&curPort);
  137.     SetPort(w->GetPlatformWindow(ev));
  138.     SetOrigin(0,0);
  139.     GlobalToLocal(&globalPoint);
  140.     SetPort(curPort);
  141.     *localPoint = globalPoint;
  142. }
  143.