home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / Sample Code / AppsToGo / DTS.Draw / DoEvent.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-24  |  4.8 KB  |  202 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        DoEvent.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19.  
  20.  
  21. /*****************************************************************************/
  22.  
  23.  
  24.  
  25. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  26. #include "App.protos.h"        /* Get the prototypes for application.            */
  27.  
  28. #ifndef __CTLHANDLER__
  29. #include "CtlHandler.h"
  30. #endif
  31.  
  32. #ifndef __DESK__
  33. #include <Desk.h>
  34. #endif
  35.  
  36. #ifndef __DISKINIT__
  37. #include <DiskInit.h>
  38. #endif
  39.  
  40. #ifndef __ERRORS__
  41. #include <Errors.h>
  42. #endif
  43.  
  44. #ifndef __MENUS__
  45. #include <Menus.h>
  46. #endif
  47.  
  48. #ifndef __TEXTEDITCONTROL__
  49. #include "TextEditControl.h"
  50. #endif
  51.  
  52. #ifndef __TOOLUTILS__
  53. #include <ToolUtils.h>
  54. #endif
  55.  
  56. #ifndef __UTILITIES__
  57. #include "Utilities.h"
  58. #endif
  59.  
  60.  
  61.  
  62. /*****************************************************************************/
  63.  
  64.  
  65.  
  66. extern Cursor    *gCursorPtr;    /* See the file Window.c for comments about this global. */
  67.  
  68.  
  69.  
  70. /*****************************************************************************/
  71. /*****************************************************************************/
  72.  
  73.  
  74.  
  75. /* Do the right thing for an event.  Determine what kind of event it is, and
  76. ** call the appropriate routines. */
  77.  
  78. #pragma segment Main
  79. void    DoEvent(EventRecord *event)
  80. {
  81.     WindowPtr    window;
  82.     Point        pt;
  83.     OSErr        err;
  84.     TEHandle    teHndl;
  85.     Rect        rct;
  86.  
  87.     switch(event->what) {
  88.  
  89.         case nullEvent:
  90.             DoIdleTasks(event);
  91.             break;
  92.  
  93.         case mouseDown:
  94.             DoMouseDown(event);            /* Let framework handle mouse downs. */
  95.             break;
  96.  
  97.         case autoKey:
  98.         case keyDown:
  99.             DoKeyDown(event);            /* Let framework handle key events. */
  100.             break;
  101.  
  102.         case activateEvt:
  103.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  104.             DoActivate((WindowPtr)event->message);
  105.             break;
  106.  
  107.         case updateEvt:
  108.             DoUpdate((WindowPtr)event->message);
  109.             break;
  110.  
  111.         case kHighLevelEvent:
  112.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  113.             DoHighLevelEvent(event);
  114.             break;
  115.  
  116.         case osEvt:
  117.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  118.             switch ((event->message >> 24) & 0xFF) {
  119.                     /* Must logical and with 0xFF to get only low byte. */
  120.                     /* High byte of message. */
  121.  
  122.                 case mouseMovedMessage:
  123.                     DoIdleTasks(event);        /* Treat mouseMoved events like NULL events. */
  124.                     break;
  125.  
  126.                 case suspendResumeMessage:
  127.                         /* Suspend/resume is also an activate/deactivate. */
  128.                     gInBackground = !((event->message) & resumeFlag);
  129.                     CTEConvertClipboard((event->message) & convertClipboardFlag, !gInBackground);
  130.                     DoActivate(FrontWindow());
  131.                     HiliteWindows();
  132.                     break;
  133.             }
  134.             break;
  135.  
  136.         case diskEvt:
  137.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  138.             if (HiWord(event->message) != noErr) {
  139.                 SetPt(&pt, kDILeft, kDITop);
  140.                 err = DIBadMount(pt, event->message);
  141.             }        /* It is not a bad idea to at least call DIBadMount in response to */
  142.             break;    /* a diskEvt, so that the user can format a floppy. */
  143.     }
  144.  
  145.     DoCursor();
  146.     DoAdjustMenus();
  147.  
  148.     window = CTETargetInfo(&teHndl, &rct);
  149.     if (window) {
  150.         if (rct.left < -8192)        /* If TextEdit control is in the frame...  */
  151.             BeginFrame(window);        /* Set clipping to the frame area.           */
  152.         else
  153.             BeginContent(window);    /* Else set clipping to the document area. */
  154.         CTEIdle();
  155.         EndContent(window);            /* EndContent can be used to close a BeginFrame. */
  156.     }
  157. }
  158.  
  159.  
  160.  
  161. /*****************************************************************************/
  162.  
  163.  
  164.  
  165. /* •• Called by DTS.Lib..framework. •• */
  166.  
  167. /* This is called when a window is activated or deactivated. */
  168.  
  169. #pragma segment Main
  170. void    DoActivate(WindowPtr window)
  171. {
  172.     RgnHandle    rgn, oldClip;
  173.     Point        pt;
  174.  
  175.     NotifyCancel();
  176.  
  177.     if (IsAppWindow(window)) {
  178.         SetPort(window);
  179.         DoCtlActivate(window);
  180.         DoDrawFrame(window, true);            /* Redraw frame for new activate state. */
  181.         CopyRgn(((WindowPeek)window)->contRgn, rgn = NewRgn());
  182.         DiffRgn(rgn, ((WindowPeek)window)->contRgn, rgn);
  183.             /* Don't draw any part that's already destined to draw due to an update event.
  184.             ** This prevents part of an exposed window from drawing twice, and thus avoids
  185.             ** flickering. */
  186.         BeginContent(window);
  187.         pt.h = pt.v = 0;
  188.         GlobalToLocal(&pt);
  189.         OffsetRgn(rgn, pt.h, pt.v);
  190.         GetClip(oldClip = NewRgn());
  191.         SetClip(rgn);
  192.         DoDrawControls(window, true);        /* Redraw content scrollbars for new activate state. */
  193.         SetClip(oldClip);
  194.         DisposeRgn(oldClip);
  195.         DisposeRgn(rgn);
  196.         EndContent(window);
  197.     }
  198. }
  199.  
  200.  
  201.  
  202.