home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 …ember: Reference Library / Apple Developer Reference Library (December 1999) (Disk 1).iso / pc / technical documentation / develop / develop issue 26 / develop issue 26 code / truffles - display mgr. / superfly source / superfly.cp < prev    next >
Encoding:
Text File  |  1996-02-22  |  4.7 KB  |  265 lines

  1. /*
  2.     File:        BigBrains.cp
  3.  
  4.     Contains:    Application-specific code for BigBrains.
  5.                 
  6.     Written by: Kent Miller
  7.  
  8.     Copyright:    © 1995-1996 by Kent Miller, all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.      
  12.  */
  13.  
  14. #include <Displays.h>
  15.  
  16. //Sprocket Includes
  17. #include "Sprocket.h"
  18.  
  19. //App specific includes
  20. #include "SuperFly.h"
  21. #include "SuperFlyAppleEventHandler.h"
  22. #include "GDeviceUtilities.h"
  23. #include "GDeviceWindow.h"
  24. #include "SuperFlyToolWindow.h"
  25.  
  26. //Application specific globals
  27. TLinkedList                *gMyWindowList;  //One for every active GDevice
  28. TSuperFlyToolWindow     *gMyToolWindow = nil;
  29. Boolean                    gMirroringWasOn;  //Was mirroring on when I started?
  30. Boolean                    gHasTranslucentDrag;
  31.  
  32. OSErr
  33. SetupApplication(void)
  34.     {    
  35.     OSErr    err = noErr;
  36.     SInt32    result;
  37.     
  38.     if (!gHasDisplayManager)
  39.         {
  40.         ErrorAlert(kErrorList, kNoDisplayManager);
  41.         gDone = true;
  42.         return -1;
  43.         }
  44.  
  45.     if (!gHasColorQuickdraw)
  46.         {
  47.         ErrorAlert(kErrorList, kNoColorQD);
  48.         gDone = true;
  49.         return -1;
  50.         }
  51.  
  52.     err = InstallDisplayManagerEventHandler();
  53.     DMIsMirroringOn(&gMirroringWasOn);
  54.     
  55.     gMyToolWindow = new TSuperFlyToolWindow();
  56.     
  57.     if ((gHasDragManager) && (noErr == Gestalt(gestaltDragMgrAttr, &result)) )
  58.         gHasTranslucentDrag = result & 0x08;         
  59.  
  60.     InitCursor();
  61.     return err;
  62.     }
  63.  
  64.  
  65. void
  66. TearDownApplication(void)
  67.     {
  68.     Boolean     mirroringOnNow;
  69.     
  70.     SuperFlyTearDownMyWindows();
  71.     
  72.     DMIsMirroringOn(&mirroringOnNow);
  73.     if (gMirroringWasOn != mirroringOnNow)
  74.         MirrorAllDisplays(gMirroringWasOn); //Toggle state of mirroring
  75.     }
  76.  
  77. void
  78. HandleMenuCommand(MenuCommandID theCommand)
  79.     {
  80.     switch (theCommand)
  81.         {
  82.         case    cAbout:
  83.             AboutBox();
  84.             break;
  85.             
  86.         case    cMirroring:
  87.             Boolean mirroringOnNow;
  88.  
  89.             DMIsMirroringOn(&mirroringOnNow);
  90.             MirrorAllDisplays(!mirroringOnNow); //Toggle state of mirroring
  91.             break;
  92.     
  93.         case    cOpen:
  94.             break;
  95.     
  96.         case    cPageSetup:
  97.             break;
  98.         
  99.         case    cPrint:
  100.             break;
  101.             
  102.         case    cQuit:
  103.             gDone = true;
  104.             break;
  105.             
  106.         case    cCopy:
  107.         case    cCut:
  108.         case    cPaste:
  109.         case    cClear:
  110.             break;
  111.  
  112.         default:
  113.             break;
  114.         }
  115.     }
  116.  
  117. void
  118. HandleMenuSelection(MenuID /* theMenu */,MenuItemID /* theItem */)
  119.     {
  120.     }
  121.  
  122.  
  123. void
  124. WriteLocalClipboardToScrap(void)
  125.     {
  126.     TEToScrap();
  127.     }
  128.  
  129. void
  130. ReadLocalClipboardFromScrap(void)
  131.     {
  132.     TEFromScrap();
  133.     }
  134.  
  135.  
  136. OSErr
  137. CreateNewDocument(void)
  138.     {
  139.     if (!gMyWindowList)
  140.         SuperFlySetUpWindows();
  141.  
  142.     return noErr;
  143.     }
  144.  
  145.  
  146. OSErr
  147. OpenDocument(LetterDescriptor * /* theDocument */, void * /*unused*/)
  148.     {
  149.     return errAEEventNotHandled;
  150.     }
  151.  
  152.  
  153. OSErr
  154. PrintDocument(LetterDescriptor * /* theDocument */, void * /*unused*/)
  155.     {
  156.     return errAEEventNotHandled;
  157.     }
  158.  
  159.  
  160. Boolean
  161. QuitApplication(void)
  162.     {
  163.     return true;
  164.     }
  165.  
  166.  
  167.  
  168. /**********************
  169. Above this line are functions required by Sprocket.  Below this line is
  170. support routines for those routines. 
  171. ***********************/
  172.  
  173. void AboutBox(void)
  174. {
  175.     EventRecord e;
  176.     Boolean     wasVisible;
  177.  
  178.     if (gMyToolWindow)
  179.         {
  180.         wasVisible = gMyToolWindow->IsVisible();
  181.         if (wasVisible)
  182.             gMyToolWindow->ShowHide(false);
  183.         }
  184.     gSplashWindow = new TSplashWindow;    
  185.     HiliteMenu(0);
  186.     do {
  187.         WaitNextEvent(everyEvent,&e,60,gMouseRegion);
  188.         }while (( e.what != mouseDown) && (e.what != keyDown));
  189.     delete gSplashWindow;    //    get rid of the splash screen
  190.  
  191.     if (gMyToolWindow)
  192.         {
  193.         if (wasVisible)
  194.             gMyToolWindow->ShowHide(true);
  195.         }
  196. }
  197.  
  198.  
  199. void
  200. SuperFlyTearDownMyWindows(void)
  201. {
  202.     TGDeviceWindow *theWin;
  203.  
  204.     theWin = (TGDeviceWindow *)gMyWindowList->GetFirstListElem();
  205.     while (theWin)
  206.         {
  207.         gMyWindowList->RemoveFromList(theWin);
  208.         theWin->Close();
  209.         theWin = (TGDeviceWindow *)gMyWindowList->GetFirstListElem();
  210.         }
  211.     delete gMyWindowList;
  212. }
  213.  
  214. OSErr
  215. SuperFlySetUpWindows(void)
  216. {
  217.     GDHandle             theGD;
  218.     TGDeviceWindow         *newWin;
  219.     TLinkedList            *myGDList;
  220.     
  221.     if (gMyWindowList)
  222.         SuperFlyTearDownMyWindows();
  223.  
  224.     myGDList = BuildAListOfUniqueDevices();
  225.  
  226.     gMyWindowList = new TLinkedList;
  227.     
  228.     theGD = (GDHandle) myGDList->GetFirstListElem();
  229.     while (theGD)
  230.         {
  231.         newWin = new TGDeviceWindow;
  232.         gMyWindowList->AddToList( newWin );
  233.         newWin->SetUpData( theGD );
  234.         theGD = (GDHandle) myGDList->GetNextListElem( theGD );
  235.         }    
  236.  
  237.     delete    myGDList;
  238.  
  239.     return noErr;    
  240. }
  241.  
  242. void    
  243. SuperFlyHandleGDevicesMoved(void)
  244. //This function is called by the Display Manager Apple Event handler in AppleEventHandling.cp.
  245. //It's purpose is to loop through the currently active windows and ensure that each window is still
  246. //completely on it's device.  If it isn't, it will center the window on it's device.
  247. //
  248. //If your application doesn't set the Display Manager Aware bit in it's size resource,
  249. //the Display Manager will move the windows for you.  You just can't be sure where they will
  250. //end up.
  251. {
  252.     TGDeviceWindow        *theWin;
  253.  
  254.     theWin = (TGDeviceWindow *) gMyWindowList->GetFirstListElem();
  255.     
  256.     while (theWin)
  257.         {
  258.         theWin->WindowOnDevice();
  259.         theWin = (TGDeviceWindow *) gMyWindowList->GetNextListElem(theWin);
  260.         }
  261.         
  262.     if (gMyToolWindow)
  263.         gMyToolWindow->MoveToRelativePosition();
  264. }
  265.