home *** CD-ROM | disk | FTP | other *** search
- #include <Dialogs.h>
- #include "LayerManager.h"
- #include "QDContext.h"
- #include "WindowManager.h"
- #include "BaseWindow.h"
-
-
-
-
-
- extern SystemWindowEventHandlerUPP gSystemWindowEventHandlerProc;
- extern WindowManager *gWindowManager;
-
-
-
-
-
- // Do nothing constructor varient
- BaseWindow::BaseWindow(void)
- {
-
- }
-
-
-
-
-
- // Resource based window constructor varient
- BaseWindow::BaseWindow(UInt32 windowID)
- {
- fWindow = ::GetNewCWindow(windowID,NULL,(WindowPtr)-1L);
- if (fWindow != NULL)
- {
- fFlags = 0L;
- gWindowManager->DoAddWindow(this);
- }
- }
-
-
-
-
-
- // Runtime based window constructor varient
- BaseWindow::BaseWindow(Boolean isFloatingWindow,short procID,Boolean goAwayFlag)
- {
- Rect bounds;
-
-
- SetRect(&bounds,32,48,160,144);
- if (isFloatingWindow)
- {
- fWindow = NewSystemWindow( &bounds,
- "\p",
- false,
- procID,
- (WindowPtr)(-1L),
- goAwayFlag,
- 0L,
- (SystemWindowEventHandlerProcPtr)gSystemWindowEventHandlerProc,
- NULL);
-
- if (fWindow != NULL)
- {
- fFlags = kFloater;
- gWindowManager->DoAddWindow(this);
- }
- }
- else
- {
- fWindow = NewCWindow( NULL,
- &bounds,
- "\p",
- false,
- procID,
- (WindowPtr)(-1L),
- goAwayFlag,
- 0L);
-
- if (fWindow != NULL)
- {
- fFlags = 0L;
- gWindowManager->DoAddWindow(this);
- }
- }
- }
-
-
-
-
-
- BaseWindow::~BaseWindow(void)
- {
- if (fWindow != NULL)
- {
- gWindowManager->DoDeleteWindow(this);
- if (fFlags & kFloater)
- DisposeSystemWindow(fWindow);
- else
- DisposeWindow(fWindow);
- fWindow = NULL;
- }
- }
-
-
-
-
-
- Boolean BaseWindow::DoGetParam(OSType param,SInt32 *value)
- {
- return HandleGetParam(param,value);
- }
-
-
-
-
-
- Boolean BaseWindow::DoSetParam(OSType param,SInt32 value)
- {
- QDContext context(fWindow);
-
-
- return HandleSetParam(param,value);
- }
-
-
-
-
-
- void BaseWindow::DoDialogEvent(EventRecord *event)
- {
- DialogPtr dialog;
- short item;
-
-
- // Were really not a dialog...but
- // lets do the right thing anyway
- DialogSelect(event,&dialog,&item);
- }
-
-
-
-
-
- void BaseWindow::DoClose(void)
- {
- QDContext context(fWindow);
-
-
- HandleClose();
- }
-
-
-
-
-
- void BaseWindow::DoKey(UInt32 key,UInt32 modifiers)
- {
- QDContext context(fWindow);
-
-
- HandleKey(key,modifiers);
- }
-
-
-
-
-
- void BaseWindow::DoClick(Point where,UInt32 modifiers,SInt32 part)
- {
- QDContext context(fWindow);
-
-
- switch(part)
- {
- case inContent:
- if (!(fFlags & (kActive | kFloater)))
- SelectWindow(fWindow);
- else
- {
- GlobalToLocal(&where);
- HandleClick(where,modifiers);
- }
- break;
-
- case inDrag:
- HandleDrag(where);
- break;
-
- case inGrow:
- HandleGrow(where);
- break;
-
- case inGoAway:
- if (TrackGoAway(fWindow,where))
- HandleClose();
- break;
-
- case inZoomIn:
- if (TrackBox(fWindow,where,part))
- HandleZoomIn();
- break;
-
- case inZoomOut:
- if (TrackBox(fWindow,where,part))
- HandleZoomOut();
- break;
- }
- }
-
-
-
-
-
- void BaseWindow::DoUpdate(void)
- {
- QDContext context(fWindow);
-
-
- BeginUpdate((GrafPtr)fWindow);
- HandleDraw();
- EndUpdate((GrafPtr)fWindow);
- }
-
-
-
-
-
- void BaseWindow::DoUpdateCursor(Point mouse,UInt32 modifiers)
- {
- QDContext context(fWindow);
-
-
- GlobalToLocal(&mouse);
- HandleCursorUpdate(mouse,modifiers);
- }
-
-
-
-
-
- void BaseWindow::DoIdleTime(EventRecord *event,Point mouse,UInt32 modifiers)
- {
- QDContext context(fWindow);
-
-
- GlobalToLocal(&mouse);
- HandleIdleTime(mouse,modifiers);
-
- if ((fFlags & kDialog) && IsDialogEvent(event))
- DoDialogEvent(event);
- }
-
-
-
-
-
- void BaseWindow::DoSetActivationState(Boolean isActive)
- {
- QDContext context(fWindow);
-
-
- if (isActive)
- {
- fFlags |= kActive;
- HandleActivate();
- }
- else
- {
- fFlags &= ~kActive;
- HandleDeactivate();
- }
- }
-
-
-
-
-
- void BaseWindow::DoSetSuspensionState(EventRecord *event,Boolean isSuspended)
- {
- if (fFlags & kFloater)
- {
- if (isSuspended)
- {
- if (((WindowPeek)fWindow)->visible)
- {
- fFlags |= kSuspended;
- ::HideWindow(fWindow);
- }
- }
- else
- {
- if (fFlags & kSuspended)
- {
- fFlags &= ~kSuspended;
- ::ShowWindow(fWindow);
- }
- }
- }
- else
- {
- if (isSuspended)
- {
- if (fFlags & kActive)
- {
- fFlags |= kSuspended;
- DoSetActivationState(false);
- }
- }
- else
- {
- if (fFlags & kSuspended)
- {
- fFlags &= ~kSuspended;
- DoSetActivationState(true);
- }
- }
- }
- }
-
-
- #pragma mark -
-
-
- Boolean BaseWindow::HandleGetParam(OSType param,SInt32 *value)
- {
- switch(param)
- {
- case 'type':
- *value = 'base';
- return true;
- break;
-
- default:
- return false;
- break;
- }
- }
-
-
-
-
-
- Boolean BaseWindow::HandleSetParam(OSType param,SInt32 value)
- {
- switch(param)
- {
- default:
- return false;
- break;
- }
- }
-
-
-
-
-
- void BaseWindow::HandleClose(void)
- {
-
- }
-
-
-
-
-
- void BaseWindow::HandleZoomIn(void)
- {
-
- }
-
-
-
-
-
- void BaseWindow::HandleZoomOut(void)
- {
-
- }
-
-
-
-
-
- void BaseWindow::HandleDrag(Point start)
- {
- Point oldPos,newPos;
-
-
- oldPos.h = fWindow->portRect.left;
- oldPos.v = fWindow->portRect.top;
- LocalToGlobal(&oldPos);
-
- DragWindow(fWindow,start,&qd.screenBits.bounds);
-
- newPos.h = fWindow->portRect.left;
- newPos.v = fWindow->portRect.top;
- LocalToGlobal(&newPos);
-
- if ((oldPos.h != newPos.h) || (oldPos.v != newPos.v))
- HandleMove(newPos);
- }
-
-
-
-
-
- void BaseWindow::HandleMove(Point where)
- {
-
- }
-
-
-
-
-
- void BaseWindow::HandleGrow(Point start)
- {
- Rect limits;
- UInt32 dimensions;
-
-
- limits.top = 64;
- limits.left = 64;
- limits.right = qd.screenBits.bounds.right;
- limits.bottom = qd.screenBits.bounds.bottom;
-
- if (0 != (dimensions = GrowWindow(fWindow,start,&limits)))
- HandleResize((dimensions >> 16),(dimensions & 0xFFFF));
- }
-
-
-
-
-
- void BaseWindow::HandleResize(UInt32 height,UInt32 width)
- {
- SizeWindow(fWindow,width,height,false);
- InvalRect(&fWindow->portRect);
- }
-
-
-
-
-
- void BaseWindow::HandleKey(UInt32 key,UInt32 modifiers)
- {
-
- }
-
-
-
-
-
- void BaseWindow::HandleClick(Point where,UInt32 modifiers)
- {
-
- }
-
-
-
-
-
- void BaseWindow::HandleActivate(void)
- {
-
- }
-
-
-
-
-
- void BaseWindow::HandleDeactivate(void)
- {
-
- }
-
-
-
-
-
- void BaseWindow::HandleCursorUpdate(Point mouse,UInt32 modifiers)
- {
-
- }
-
-
-
-
-
- void BaseWindow::HandleIdleTime(Point mouse,UInt32 modifiers)
- {
-
- }
-
-
-
-
-
- void BaseWindow::HandleDraw(void)
- {
-
- }
-
-
- #pragma mark -
- #if GENERATINGPOWERPC
-
-
- #define RESULT_OFFSET(type) ((sizeof(type) == 1) ? 3 : ((sizeof(type) == 2) ? 1 : 0))
-
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=mac68k
- #endif
-
- typedef struct NewSystemWindowPB
- {
- Rect *boundsRect;
- StringPtr title;
- Boolean visible;
- short procID;
- WindowPtr behind;
- Boolean goAwayFlag;
- long refCon;
- SystemWindowEventHandlerProcPtr eventProc;
- RgnHandle mouseRgn;
- } NewSystemWindowPB;
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=reset
- #endif
-
-
- short gNewSystemWindowGlue[] = { 0x4E56, 0x0000, 0x2F0A, 0x246E, 0x0008, 0x594F,
- 0x2F12, 0x2F2A, 0x0004, 0x1F2A, 0x0008, 0x3F2A,
- 0x000A, 0x2F2A, 0x000C, 0x1F2A, 0x0010, 0x2F2A,
- 0x0012, 0x2F2A, 0x0016, 0x2F2A, 0x001A, 0x3F3C,
- 0x005A, 0xA88F, 0x205F, 0x2008, 0x245F, 0x4E5E,
- 0x4E75 };
-
-
-
-
-
- pascal WindowPtr NewSystemWindow(const Rect *boundsRect, ConstStr255Param title, Boolean visible, short procID, WindowPtr behind, Boolean goAwayFlag, long refCon, SystemWindowEventHandlerProcPtr eventProc, RgnHandle mouseRgn)
- {
- NewSystemWindowPB pb;
- long private_result;
-
-
- pb.boundsRect = (Rect*)boundsRect;
- pb.title = (StringPtr)title;
- pb.visible = visible;
- pb.procID = procID;
- pb.behind = behind;
- pb.goAwayFlag = goAwayFlag;
- pb.refCon = refCon;
- pb.eventProc = eventProc;
- pb.mouseRgn = mouseRgn;
-
- private_result = CallUniversalProc((UniversalProcPtr)gNewSystemWindowGlue,
- kCStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(WindowPtr)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NewSystemWindowPB*))),
- &pb);
-
- return *(((WindowPtr*)&private_result) + RESULT_OFFSET(WindowPtr));
- }
-
-
-
-
-
- pascal OSErr DisposeSystemWindow(WindowPtr theWindow)
- {
- long private_result;
-
-
- private_result = CallUniversalProc(NGetTrapAddress(0xA88F,ToolTrap),
- kPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(WindowPtr)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(UInt16))),
- theWindow,
- 0x005B);
-
- return *(((OSErr*)&private_result) + RESULT_OFFSET(OSErr));
- }
-
-
-
-
-
- pascal short FindSystemWindow(Point thePoint, WindowPtr *theWindow)
- {
- long private_result;
-
-
- private_result = CallUniversalProc(NGetTrapAddress(0xA88F,ToolTrap),
- kPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(short)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Point)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(WindowPtr*)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(UInt16))),
- thePoint,
- theWindow,
- 0x0064);
-
- return *(((short*)&private_result) + RESULT_OFFSET(short));
- }
-
-
- #endif
-