home *** CD-ROM | disk | FTP | other *** search
- /********************************************************************
- FLOATING WINDOWS 1.0
- Copyright 1990 Patrick Doane. All Rights Reserved
- ********************************************************************/
-
- #include "Floating.h"
- #include "main.h"
-
- #define TypeMask 0xFF000000
- #define SuspendResumeEvt 0x01000000
- #define SuspendResumeBit 0x00000001
-
- WindowPtr windowA,windowB,windowC;
- WindowPtr floatWindow,floatWindow2;
- Boolean running;
- Boolean WNEImplemented;
- Boolean inBackground;
-
- void main(void)
- {
- Initialize();
- MakeWindows();
-
- EventLoop();
- }
-
- void Initialize(void)
- {
- InitGraf(&thePort);
- InitFonts();
- InitWindows();
- InitCursor();
-
- WNEImplemented = (NGetTrapAddress(0x60,ToolTrap) !=
- NGetTrapAddress(0x9F,ToolTrap));
-
- inBackground = false;
-
- running = true;
-
- InitFloat();
- }
-
- void MakeWindows(void)
- {
- floatWindow = NewFloatingWindow(131,0L);
- floatWindow2 = NewFloatingWindow(132,0L);
-
- windowA = GetNewWindow(128,0L,0L);
- SelectTheWindow(windowA);
- windowB = GetNewWindow(129,0L,0L);
- SelectTheWindow(windowB);
- windowC = GetNewWindow(130,0L,0L);
- SelectTheWindow(windowC);
- }
-
- void EventLoop(void)
- {
- EventRecord theEvent;
-
- do
- { if (WNEImplemented)
- { WaitNextEvent(everyEvent,&theEvent,0,0L);
- DoEvent(&theEvent);
- }
- else
- { SystemTask();
- if (GetNextEvent(everyEvent,&theEvent))
- DoEvent(&theEvent);
- }
- }
- while (running);
- }
-
- void DoEvent(EventRecord *theEvent)
- {
- switch(theEvent->what)
- { case nullEvent:
- break;
- case mouseDown:
- DoMouseDown(theEvent);
- break;
- case activateEvt:
- if (theEvent->modifiers & activeFlag)
- DoActivate(theEvent);
- else
- DoDeactivate(theEvent);
- case updateEvt:
- DoUpdate(theEvent);
- break;
- case app4Evt:
- switch (theEvent->message & TypeMask)
- { case SuspendResumeEvt:
- if (theEvent->message & SuspendResumeBit)
- DoResume(theEvent);
- else
- DoSuspend(theEvent);
- break;
- }
- break;
- }
- }
-
- void DoMouseDown(EventRecord *theEvent)
- {
- WindowPtr whichWindow;
- short thePart;
-
- thePart = FindWindow(theEvent->where,&whichWindow);
-
- switch(thePart)
- { case inDesk:
- break;
- case inMenuBar:
- DoMenu(theEvent);
- HiliteMenu(0);
- break;
- case inSysWindow:
- SystemClick(theEvent,whichWindow);
- break;
- case inContent:
- SelectTheWindow(whichWindow);
- break;
- case inDrag:
- DragTheWindow(whichWindow,theEvent);
- break;
- case inGrow:
- GrowTheWindow(whichWindow,theEvent->where);
- break;
- case inGoAway:
- if (TrackGoAway(whichWindow,theEvent->where))
- CloseTheWindow(whichWindow);
- if (!FrontWindow())
- running = false;
- break;
- case inZoomIn:
- case inZoomOut:
- ZoomTheWindow(whichWindow,theEvent->where,thePart);
- break;
- }
- }
-
- void DoMenu(EventRecord *theEvent)
- {
- }
-
- void GrowTheWindow(WindowPtr whichWindow,Point where)
- {
- long newBounds;
- Rect growRect;
-
- growRect = (**GetGrayRgn()).rgnBBox;
- growRect.left = 64;
- growRect.top = 64;
-
- newBounds = GrowWindow(whichWindow,where,&growRect);
- if (newBounds)
- { EraseRect(&whichWindow->portRect);
- SizeWindow(whichWindow,LoWord(newBounds),HiWord(newBounds),true);
- EraseRect(&whichWindow->portRect);
- InvalRect(&whichWindow->portRect);
- }
- }
-
- void ZoomTheWindow(WindowPtr whichWindow,Point where,short inOrOut)
- {
- Rect portRect;
-
- if (TrackBox(whichWindow,where,inOrOut))
- { portRect = whichWindow->portRect;
-
- EraseRect(&portRect);
- ZoomWindow(whichWindow,inOrOut,false);
- portRect = whichWindow->portRect;
- InvalRect(&portRect);
- }
- }
-
- void DoActivate(EventRecord *theEvent)
- {
- WindowPtr whichWindow;
-
- whichWindow = (WindowPtr)theEvent->message;
- SetPort(whichWindow);
- DrawGrowIcon(whichWindow);
- }
-
- void DoDeactivate(EventRecord *theEvent)
- {
- WindowPtr whichWindow;
-
- whichWindow = (WindowPtr)theEvent->message;
- DrawGrowIcon(whichWindow);
- }
-
- void DoUpdate(EventRecord *theEvent)
- {
- WindowPtr whichWindow;
- GrafPtr savePort;
-
- whichWindow = (WindowPtr)theEvent->message;
-
- GetPort(&savePort);
- BeginUpdate(whichWindow);
- DrawGrowIcon(whichWindow);
- EndUpdate(whichWindow);
- SetPort(savePort);
- }
-
- void DoResume(EventRecord *theEvent)
- {
- register WindowPtr theWindow;
-
- inBackground = false;
- ShowFloats();
- }
-
- void DoSuspend(EventRecord *theEvent)
- {
- register WindowPtr theWindow;
-
- inBackground = true;
- HideFloats();
- }