home *** CD-ROM | disk | FTP | other *** search
- #define BASE_RES_ID 400
- #define NIL_POINTER 0L
- #define MOVE_TO_FRONT -1L
- #define REMOVE_ALL_EVENTS 0
-
- #define LEAVE_WHERE_IT_IS FALSE
- #define NORMAL_UPDATES TRUE
-
- #define SLEEP 0L
- #define NIL_MOUSE_REGION 0L
- #define WNE_TRAP_NUM 0x60
- #define UNIMPL_TRAP_NUM 0x9F
- #define SUSPEND_RESUME_BIT 0x0001
- #define ACTIVATING 1
- #define RESUMING 1
-
- #define TEXT_FONT_SIZE 12
-
- #define DRAG_THRESHOLD 30
- #define MIN_WINDOW_HEIGHT 50
- #define MIN_WINDOW_WIDTH 50
- #define SCROLL_BAR_PIXELS 16
-
- #define ROWHEIGHT 15
- #define LEFTMARGIN 10
- #define STARTROW 0
- #define HORIZONTAL_OFFSET 0
-
- PicHandle gPictureHandle;
- WindowPtr gPictWindow, gEventWindow;
- Boolean gDone, gWNEImplemented;
- EventRecord gTheEvent;
- int gCurRow, gMaxRow;
- Rect gDragRect, gSizeRect;
-
- /******************************** main *********/
-
- main()
- {
- ToolBoxInit();
- WindowInit();
- LoadPicture();
- SetUpDragRect();
- SetUpSizeRect();
-
- MainLoop();
- }
-
- /*********************************** ToolBoxInit */
-
- ToolBoxInit()
- {
- InitGraf( &thePort );
- InitFonts();
- FlushEvents( everyEvent, REMOVE_ALL_EVENTS );
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs( NIL_POINTER );
- InitCursor();
- }
-
- /******************************** WindowInit *********/
-
- WindowInit()
- {
- gPictWindow = GetNewWindow( BASE_RES_ID, NIL_POINTER, MOVE_TO_FRONT );
- gEventWindow = GetNewWindow( BASE_RES_ID+1, NIL_POINTER, MOVE_TO_FRONT );
-
- SetPort( gEventWindow );
- SetupEventWindow();
-
- ShowWindow( gEventWindow );
- ShowWindow( gPictWindow );
-
- SelectWindow( gEventWindow );
- }
-
- /******************************** SetupEventWindow *********/
-
- SetupEventWindow()
- {
- Rect eventRect;
-
- eventRect = gEventWindow->portRect;
- gMaxRow = eventRect.bottom - eventRect.top - ROWHEIGHT;
- gCurRow = STARTROW;
-
- TextFont( monaco );
- TextSize( TEXT_FONT_SIZE );
- }
-
- /******************************** LoadPicture *********/
-
- LoadPicture()
- {
- gPictureHandle = GetPicture( BASE_RES_ID );
- }
-
- /******************************** SetUpDragRect *********/
-
- SetUpDragRect()
- {
- gDragRect = screenBits.bounds;
- gDragRect.left += DRAG_THRESHOLD;
- gDragRect.right -= DRAG_THRESHOLD;
- gDragRect.bottom -= DRAG_THRESHOLD;
- }
-
- /******************************** SetUpSizeRect *********/
-
- SetUpSizeRect()
- {
- gSizeRect.top = MIN_WINDOW_HEIGHT;
- gSizeRect.left = MIN_WINDOW_WIDTH;
-
- gSizeRect.bottom = screenBits.bounds.bottom - screenBits.bounds.top;
- gSizeRect.right = screenBits.bounds.right - screenBits.bounds.left;
- }
-
- /******************************** MainLoop *********/
-
- MainLoop()
- {
- gDone = FALSE;
- gWNEImplemented = ( NGetTrapAddress( WNE_TRAP_NUM, ToolTrap ) != NGetTrapAddress( UNIMPL_TRAP_NUM, ToolTrap ) );
- while ( gDone == FALSE )
- {
- HandleEvent();
- }
- }
-
- /************************************* HandleEvent */
-
- HandleEvent()
- {
- if ( gWNEImplemented )
- WaitNextEvent( everyEvent, &gTheEvent, SLEEP, NIL_MOUSE_REGION );
- else
- {
- SystemTask();
- GetNextEvent( everyEvent, &gTheEvent );
- }
-
- switch ( gTheEvent.what )
- {
- case nullEvent:
- /*DrawEventString( "\pnullEvent" );*/
- /* Uncomment the previous line for a burst of flavor! */
- break;
- case mouseDown:
- DrawEventString( "\pmouseDown" );
- HandleMouseDown();
- break;
- case mouseUp:
- DrawEventString( "\pmouseUp" );
- break;
- case keyDown:
- DrawEventString( "\pkeyDown" );
- break;
- case keyUp:
- DrawEventString( "\pkeyUp" );
- case autoKey:
- DrawEventString( "\pautoKey" );
- case updateEvt:
- if ( (WindowPtr)gTheEvent.message == gPictWindow )
- {
- DrawEventString( "\pupdateEvt: gPictWindow" );
- BeginUpdate( gTheEvent.message );
- DrawMyPicture( gTheEvent.message, gPictureHandle );
- EndUpdate( gTheEvent.message );
- }
- else
- {
- DrawEventString( "\pupdateEvt: gEventWindow" );
- BeginUpdate( gTheEvent.message );
- /*
- * We won't handle updates to gEventWindow,
- * but we still need to empty the gEventWindow
- * Update Region so the Window Manager will stop
- * queueing UpdateEvts.
- * We do this with calls to BeginUpdate()
- * and EndUpdate().
- */
- EndUpdate( gTheEvent.message );
- }
- break;
- case diskEvt:
- DrawEventString( "\pdiskEvt" );
- break;
- case activateEvt:
- if ( (WindowPtr)gTheEvent.message == gPictWindow )
- {
- DrawGrowIcon( gTheEvent.message );
- if ( ( gTheEvent.modifiers & activeFlag ) == ACTIVATING )
- DrawEventString("\pactivateEvt: activating gPictWindow" );
- else
- DrawEventString("\pactivateEvt: deactivating gPictWindow" );
- }
- else
- {
- if ( ( gTheEvent.modifiers & activeFlag ) == ACTIVATING )
- DrawEventString( "\pactivateEvt: activating gEventWindow" );
- else
- DrawEventString( "\pactivateEvt: deactivating gEventWindow" );
- }
- break;
- case networkEvt:
- DrawEventString( "\pnetworkEvt" );
- break;
- case driverEvt:
- DrawEventString( "\pdriverEvt" );
- break;
- case app1Evt:
- DrawEventString( "\papp1Evt" );
- break;
- case app2Evt:
- DrawEventString( "\papp2Evt" );
- break;
- case app3Evt:
- DrawEventString( "\papp3Evt" );
- break;
- case app4Evt:
- if ( (gTheEvent.message & SUSPEND_RESUME_BIT) == RESUMING )
- DrawEventString( "\pResume event" );
- else
- DrawEventString( "\pSuspend event" );
- break;
- }
- }
-
- /********************************** DrawEventString *******/
-
- DrawEventString( s )
-
- Str255 s;
-
- {
- if ( gCurRow > gMaxRow )
- ScrollWindow();
- else
- gCurRow += ROWHEIGHT;
-
- MoveTo( LEFTMARGIN, gCurRow );
- DrawString(s);
- }
-
- /********************************** ScrollWindow *******/
-
- ScrollWindow()
- {
- RgnHandle tempRgn;
-
- tempRgn = NewRgn();
- ScrollRect( &gEventWindow->portRect, HORIZONTAL_OFFSET, -ROWHEIGHT, tempRgn );
- DisposeRgn( tempRgn );
- }
-
- /************************************* HandleMouseDown */
-
- HandleMouseDown()
- {
- WindowPtr whichWindow;
- short int thePart;
- long windSize;
- GrafPtr oldPort;
-
- thePart = FindWindow( gTheEvent.where, &whichWindow );
- switch ( thePart )
- {
- case inSysWindow :
- SystemClick( &gTheEvent, whichWindow );
- break;
- case inDrag :
- DragWindow( whichWindow, gTheEvent.where, &gDragRect );
- break;
- case inContent:
- SelectWindow( whichWindow );
- break;
- case inGrow:
- windSize = GrowWindow( whichWindow, gTheEvent.where, &gSizeRect );
- if ( windSize != 0 )
- {
- GetPort( &oldPort );
- SetPort( whichWindow );
- EraseRect( &whichWindow->portRect );
- SizeWindow( whichWindow, LoWord( windSize ), HiWord( windSize ), NORMAL_UPDATES );
- InvalRect( &whichWindow->portRect );
- SetPort( oldPort );
- }
- break;
- case inGoAway :
- gDone = TRUE;
- break;
- case inZoomIn:
- case inZoomOut:
- if ( TrackBox( whichWindow, gTheEvent.where, thePart ) )
- {
- GetPort( &oldPort );
- SetPort( whichWindow );
- EraseRect( &whichWindow->portRect );
- ZoomWindow( whichWindow, thePart, LEAVE_WHERE_IT_IS );
- InvalRect( &whichWindow->portRect );
- SetPort( oldPort );
- }
- break;
- }
- }
-
- /******************************** DrawMyPicture *********/
-
- DrawMyPicture( drawingWindow, thePicture )
-
- WindowPtr drawingWindow;
- PicHandle thePicture;
-
- {
- Rect drawingClipRect, myRect;
- GrafPtr oldPort;
- RgnHandle tempRgn;
-
- GetPort( &oldPort );
- SetPort( drawingWindow );
- tempRgn = NewRgn();
- GetClip( tempRgn );
- EraseRect( &drawingWindow->portRect );
- DrawGrowIcon( drawingWindow );
- drawingClipRect = drawingWindow->portRect;
- drawingClipRect.right -= SCROLL_BAR_PIXELS;
- drawingClipRect.bottom -= SCROLL_BAR_PIXELS;
-
- myRect = drawingWindow->portRect;
- CenterPict( thePicture, &myRect );
- ClipRect( &drawingClipRect );
- DrawPicture( thePicture, &myRect );
-
- SetClip( tempRgn );
- DisposeRgn( tempRgn );
- SetPort( oldPort );
- }
-
- /******************************** CenterPict *********/
-
- CenterPict( thePicture, myRectPtr )
-
- PicHandle thePicture;
- Rect *myRectPtr;
-
- {
- Rect windRect, pictureRect;
-
- windRect = *myRectPtr;
- pictureRect = (**( thePicture )).picFrame;
- myRectPtr->top = (windRect.bottom - windRect.top - (pictureRect.bottom - pictureRect.top)) / 2 + windRect.top;
- myRectPtr->bottom = myRectPtr->top + (pictureRect.bottom - pictureRect.top);
- myRectPtr->left = (windRect.right - windRect.left - (pictureRect.right - pictureRect.left)) / 2 + windRect.left;
- myRectPtr->right = myRectPtr->left + (pictureRect.right - pictureRect.left);
- }