home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-08-11 | 13.9 KB | 437 lines | [TEXT/KAHL] |
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- // //
- // //
- // Copyright PennyWise Software, 1994. //
- // //
- // Part of the PennyWise Software Application Framework //
- // //
- // //
- // MovieWindow.c Written by Peter Kaplan //
- // //
- // //
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- //
- // This is a template for a PennyWise Software Application Framework window
- //
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- #include "PWFramework.h"
- #include "PWWindowList.h"
- #include "WindowID.h"
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- #include "DefaultHandlers.h"
- #include "HandleMenus.h"
- #include "MovieWindow.h"
- #include <Movies.h>
- #include <PWPrefsMgr.h>
- #include <PWWindowUtils.h>
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- // These procedures are static. They will only be called by name from here
- // outside refrences will use our window proc list.
- static void ThisWindowCreate (EventRecord* theEvent, WindowPtr theWindow);
- static short ThisWindowDispose (EventRecord* theEvent, WindowPtr theWindow);
- static void ThisWindowResize (EventRecord* theEvent, WindowPtr theWindow);
- static void ThisWindowUpdate (EventRecord* theEvent, WindowPtr theWindow);
- static void ThisWindowIdle (EventRecord* theEvent, WindowPtr theWindow);
- static void ThisWindowCursor (EventRecord* theEvent, WindowPtr theWindow);
- static void ThisWindowPreMenu (EventRecord* theEvent, WindowPtr theWindow);
- static void ThisWindowPostMenu (EventRecord* theEvent, WindowPtr theWindow);
- static short ThisWindowDoMenu (EventRecord* theEvent, WindowPtr theWindow, short theMenu, short theItem, short theWindowID);
- static void ThisWindowGrowRect (EventRecord* theEvent, WindowPtr theWindow, Rect* theRect);
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- // This record holds all the information about this window
- // You can add fields to this record.
- // NOTE:ALL WINDOW RECORDS MUST START WITH THIS
- // HEADER OR ELSE THE FRAMEWORK WILL NOT
- // FUNCTION PROPERLY. YOU'VE BEEN WARNED!
- typedef struct OurWinRecord {
- WindowParamHeader theHeader;
- short isDirty;
- MovieController theController;
- }OurWinRecord, *OurWinPtr, **OurWinHandle;
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- // Macros for accessing the header data
- // you can add your own as you add fields
- // to the OurWinRecord.
- // NOTE:THESE MACROS ASSUME theData HOLDS
- // A VALID COPY OF OurWinHandle.
- #define THE_ID (*theData)->theHeader.theID
- #define IS_DIRTY (*theData)->isDirty
- #define CONTROLLER (*theData)->theController
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- void InitMovieWindowHandlers()
- {
- PWInstallWindowType (kWINDOW_ID_MovieWindow, kWINDOW_TYPE_APPLICATION);
- PWInstallCreate (kWINDOW_ID_MovieWindow, ThisWindowCreate);
- PWInstallDispose (kWINDOW_ID_MovieWindow, ThisWindowDispose);
- PWInstallZoomIn (kWINDOW_ID_MovieWindow, ThisWindowIdle);
- PWInstallZoomOut (kWINDOW_ID_MovieWindow, ThisWindowIdle);
- PWInstallResize (kWINDOW_ID_MovieWindow, ThisWindowResize);
- PWInstallClick (kWINDOW_ID_MovieWindow, ThisWindowIdle);
- PWInstallUpdate (kWINDOW_ID_MovieWindow, ThisWindowUpdate);
- PWInstallActivate (kWINDOW_ID_MovieWindow, ThisWindowIdle);
- PWInstallDeactivate (kWINDOW_ID_MovieWindow, ThisWindowIdle);
- PWInstallIdle (kWINDOW_ID_MovieWindow, ThisWindowIdle);
- PWInstallCursor (kWINDOW_ID_MovieWindow, ThisWindowCursor);
- PWInstallKeyDown (kWINDOW_ID_MovieWindow, ThisWindowIdle);
- PWInstallDrag (kWINDOW_ID_MovieWindow, ThisWindowIdle);
- PWInstallPreMenu (kWINDOW_ID_MovieWindow, ThisWindowPreMenu);
- PWInstallMenu (kWINDOW_ID_MovieWindow, ThisWindowDoMenu);
- PWInstallPostMenu (kWINDOW_ID_MovieWindow, ThisWindowPostMenu);
- PWInstallGrowRect (kWINDOW_ID_MovieWindow, ThisWindowGrowRect);
- PWInstallBackground (kWINDOW_ID_MovieWindow, ThisWindowIdle);
- PWInstallScrap2Appl (kWINDOW_ID_MovieWindow, defaultWindowNothing);
- PWInstallAppl2Scrap (kWINDOW_ID_MovieWindow, defaultWindowNothing);
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowCreate (EventRecord* theEvent, WindowPtr theWindow)
- {
- // This routine will very rarely contain anything worthwhile
- // You will make custom routines for most windows that will be exported
- // via the include file
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- // Since we will be exporting this we don't have to conform to any particular input format
- void MovieWindowOpen(FSSpecPtr theSpec)
- {
- WindowPtr theWindow;
- OurWinHandle theData;
- Rect windowBounds;
- Movie theMovie;
- MovieController theController;
- OSErr theErr;
- short movieResFile;
- Str63 movieName;
- short movieResID;
- Boolean wasChanged;
- WStateData *wsdp;
-
- SetRect(&windowBounds, 4, 42, 800,800);
- theWindow = NewCWindow(NULL,&windowBounds,theSpec->name,FALSE,zoomDocProc,(WindowPtr)-1,TRUE,0);
- if (theWindow) {
- // We sucessfully got the window
-
- // Now we have to allocate our storage
- theData = (OurWinHandle) NewHandle(sizeof(OurWinRecord));
- if (theData) {
- // We sucessfully allocated storage
-
- // So Lets set the port to our new window
- SetPort(theWindow);
-
- // Here we would do any screen/size manipulations
- // before we show the window
- theMovie = NULL;
- theErr = OpenMovieFile(theSpec, &movieResFile, fsRdPerm);
- if (theErr == noErr) {
- movieResID = 0;
- theErr = NewMovieFromFile( &theMovie, movieResFile, &movieResID, movieName, newMovieActive, &wasChanged);
- CloseMovieFile(movieResFile);
- }
-
- if (theMovie) {
- // Here we would allocate any other
- // objects that we need. (Controls, etc.)
-
- // Make this real big. NewController will make it right
- SetRect(&windowBounds, 0, 0, 800, 800);
-
- theController = NewMovieController(theMovie, &windowBounds, mcTopLeftMovie);
- if (theController) {
- MCGetControllerBoundsRect(theController, &windowBounds);
- SizeWindow(theWindow, windowBounds.right, windowBounds.bottom, TRUE);
- MCDoAction(theController, mcActionSetKeysEnabled, (Ptr) TRUE);
- MCDoAction(theController, mcActionSetGrowBoxBounds, &screenBits.bounds);
-
- MCEnableEditing(theController, TRUE);
-
-
- // Now lets set the id
- THE_ID = kWINDOW_ID_MovieWindow;
- IS_DIRTY = FALSE;
- CONTROLLER = theController;
-
- // Install our routines
- SetWRefCon(theWindow, (long) theData);
-
- CascadePosition(theWindow);
-
- // Now lets make the standard size this one
- wsdp = (WStateData*) *(((WindowPeek)theWindow)->dataHandle);
- LocalToGlobalRect(&windowBounds);
- wsdp->stdState = windowBounds;
-
- // Show it & select it before we leave
- ShowWindow(theWindow);
- SelectWindow(theWindow);
- }
- else {
- // We could not allocate memory for our window's data
- // So lets get rid of the data
- DisposeWindow(theWindow);
- theWindow = NULL;
- DisposeHandle((Handle)theData);
- DisposeMovie(theMovie);
- }
- }
- else {
- // We could not allocate memory for our window's data
- // So lets get rid of the data
- DisposeWindow(theWindow);
- theWindow = NULL;
- DisposeHandle((Handle)theData);
- }
- }
- else {
- // We could not allocate memory for our window's data
- // So lets get rid of the data
- DisposeWindow(theWindow);
- theWindow = NULL;
- }
- }
-
- if (!theWindow) {
- SysBeep(1);
- // We did not create the window
- // You will probably want to put up a dialog here to explain why
- }
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static short ThisWindowDispose (EventRecord* theEvent, WindowPtr theWindow)
- {
- OurWinHandle theData;
- short theResults;
- MovieController theController;
- Movie theMovie;
-
- theData = (OurWinHandle) GetWRefCon(theWindow);
-
- // Want to save it
- theResults = TRUE;
-
- if (IS_DIRTY) {
- // Data has been changed we would probably want to put up
- // a “Save Changes to x” dialog here
- // But I'm just going to reset IS_DIRTY
- IS_DIRTY = FALSE;
- }
-
- // Do whatever saving you need to do here
- theController = CONTROLLER;
- theMovie = MCGetMovie(theController);
-
- DisposeMovieController(theController);
- DisposeMovie(theMovie);
-
- // Now lets break it down
- HideWindow(theWindow);
- DisposeHandle((Handle)theData);
- DisposeWindow(theWindow);
-
- return theResults; // True if we closed it, false if we did not [ex. pressed cancel in save dialog]
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowResize (EventRecord* theEvent, WindowPtr theWindow)
- {
- OurWinHandle theData;
- GrafPtr oldPort;
- MovieController theController;
-
-
- GetPort(&oldPort);
- SetPort(theWindow);
-
- theData = (OurWinHandle) GetWRefCon(theWindow);
-
- EraseRect(&theWindow->portRect);
-
- // Do any control moving here
- //•••••••••••••••••••••••••••
- theController = CONTROLLER;
- MCSetControllerBoundsRect(theController, &theWindow->portRect);
-
- InvalRect(&theWindow->portRect);
-
- SetPort(oldPort);
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowUpdate (EventRecord* theEvent, WindowPtr theWindow)
- {
- OurWinHandle theData;
- GrafPtr oldPort;
- MovieController theController;
-
-
- GetPort(&oldPort);
- SetPort(theWindow);
-
- theData = (OurWinHandle) GetWRefCon(theWindow);
-
- // Draw the window here
- //•••••••••••••••••••••••••••
- theController = CONTROLLER;
- ThisWindowIdle(theEvent, theWindow);
- MCDraw(theController, theWindow);
-
- SetPort(oldPort);
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowIdle (EventRecord* theEvent, WindowPtr theWindow)
- {
- OurWinHandle theData;
- GrafPtr oldPort;
- MovieController theController;
-
-
- GetPort(&oldPort);
- SetPort(theWindow);
-
- theData = (OurWinHandle) GetWRefCon(theWindow);
-
- // do your idle tasks here
- //•••••••••••••••••••••••••••
- theController = CONTROLLER;
- MCIsPlayerEvent(theController, theEvent);
-
- SetPort(oldPort);
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowCursor (EventRecord* theEvent, WindowPtr theWindow)
- {
- SetRectRgn(gMouseMovedRgn, -32768, -32768, 32767, 32767);
- SetCursor(&qd.arrow);
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowPreMenu (EventRecord* theEvent, WindowPtr theWindow)
- {
- OurWinHandle theData;
- GrafPtr oldPort;
- MovieController theController;
-
-
- GetPort(&oldPort);
- SetPort(theWindow);
-
- theData = (OurWinHandle) GetWRefCon(theWindow);
-
- // Enable and disable items
- // change item names etc.
- DisableItem( gMenuFile, kFILE_PRINT);
- DisableItem( gMenuFile, kFILE_PONE);
- DisableItem( gMenuFile, kFILE_SAVE);
- DisableItem( gMenuFile, kFILE_SAVEAS);
-
- theController = CONTROLLER;
- MCSetUpEditMenu(theController, theEvent->modifiers, gMenuEdit);
-
- SetPort(oldPort);
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowPostMenu (EventRecord* theEvent, WindowPtr theWindow)
- {
- OurWinHandle theData;
- GrafPtr oldPort;
-
-
- GetPort(&oldPort);
- SetPort(theWindow);
-
- theData = (OurWinHandle) GetWRefCon(theWindow);
-
- // Enable and disable items
- // change item names etc.
- EnableItem( gMenuFile, kFILE_PRINT);
- EnableItem( gMenuFile, kFILE_PONE);
- EnableItem( gMenuFile, kFILE_SAVE);
- EnableItem( gMenuFile, kFILE_SAVEAS);
-
- EnableItem( gMenuEdit, kEDIT_UNDO);
- EnableItem( gMenuEdit, kEDIT_CUT);
- EnableItem( gMenuEdit, kEDIT_COPY);
- EnableItem( gMenuEdit, kEDIT_PASTE);
- EnableItem( gMenuEdit, kEDIT_CLEAR);
-
- SetPort(oldPort);
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static short ThisWindowDoMenu (EventRecord* theEvent, WindowPtr theWindow, short theMenu, short theItem, short theWindowID)
- {
- short theResult;
- OurWinHandle theData;
- GrafPtr oldPort;
- MovieController theController;
- Movie theMovie;
- Rect theRect;
-
-
- theData = (OurWinHandle) GetWRefCon(theWindow);
- theController = CONTROLLER;
-
- theResult = TRUE;
- theMovie = NULL;
-
- // if we don't handle it return false so the defaults will pick it up
- switch (theMenu) {
- case kMENU_ID_EDIT:
- switch (theItem) {
- case kEDIT_UNDO:
- MCUndo(theController);
- break;
- case kEDIT_CUT:
- theMovie = MCCut(theController);
- PutMovieOnScrap(theMovie, 0);
- break;
- case kEDIT_COPY:
- theMovie = MCCopy(theController);
- PutMovieOnScrap(theMovie, 0);
- break;
- case kEDIT_PASTE:
- theMovie = NewMovieFromScrap(0);
- MCPaste(theController, theMovie);
- break;
- case kEDIT_CLEAR:
- MCClear(theController);
- break;
- default:
- theResult = FALSE;
- }
- EraseRect(&theWindow->portRect);
- MCGetControllerBoundsRect(theController, &theRect);
- SizeWindow(theWindow, theRect.right, theRect.bottom, TRUE);
- SetPort(theWindow);
- InvalRect(&theWindow->portRect);
- if (theMovie) DisposeMovie(theMovie);
- break;
- default:
- theResult = FALSE;
- }
-
- return theResult;
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowGrowRect (EventRecord* theEvent, WindowPtr theWindow, Rect* theRect)
- {
- OurWinHandle theData;
- GrafPtr oldPort;
- MovieController theController;
-
-
- GetPort(&oldPort);
- SetPort(theWindow);
-
- theData = (OurWinHandle) GetWRefCon(theWindow);
-
- ThisWindowIdle(theEvent, theWindow);
-
- // Set the rect
- theController = CONTROLLER;
- MCGetControllerBoundsRect(theController, theRect);
- SizeWindow( theWindow, theRect->right, theRect->bottom, TRUE);
-
- // Tell the framework that we are handling it.
- SetRect(theRect, 0, 0, 0, 0);
-
- SetPort(oldPort);
- }
-