Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
Show Movie.c
/* |
File: Show Movie.c |
Contains: main and event loop |
Allows you to open and display movies |
in a window. |
Written by: Jason Hodges-Harris & Don Swatman |
Copyright: Copyright © 1995-1999 by Apple Computer, Inc., All Rights Reserved. |
You may incorporate this Apple sample source code into your program(s) without |
restriction. This Apple sample source code has been provided "AS IS" and the |
responsibility for its operation is yours. You are not permitted to redistribute |
this Apple sample source code as "Apple sample source code" after having made |
changes. If you're going to re-distribute the source, we require that you make |
it clear in the source that the code was descended from Apple sample source |
code, but that you've made changes. |
Change History (most recent first): |
8/17/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1 |
*/ |
#include <Types.h> |
#include <Memory.h> |
#include <Quickdraw.h> |
#include <Fonts.h> |
#include <Events.h> |
#include <Menus.h> |
#include <Windows.h> |
#include <TextEdit.h> |
#include <Dialogs.h> |
#include <OSUtils.h> |
#include <ToolUtils.h> |
#include <SegLoad.h> |
#include <Movies.h> |
#include <DiskInit.h> |
// Show Movie Headers |
#include "MenuStuff.h" |
#include "WindStuff.h" |
#include "MovieStuff.h" |
#include "MoviePrefs.h" |
//---------------------------------------------- |
// Prototypes |
//---------------------------------------------- |
// Inititalization |
OSErr InitMacStuff(void); |
void InitGlobals(void); |
void KillGlobals(void); |
// Events |
void EventLoop (void); |
//============================================== |
// main |
//============================================== |
void main(void) |
{ |
OSErr theErr; |
theErr = InitMacStuff(); |
if (!theErr) |
{ |
InitGlobals(); // initialise globals |
EventLoop(); // Call the main event loop. |
KillGlobals(); // Tear down any globals |
ExitToShell(); // Quit the application. |
} |
} |
//============================================== |
// Initialisation Stuff |
//============================================== |
//---------------------------------------------- |
// InitMacStuff |
// |
// Initialise the Mac Tool Box and set up the memory |
//---------------------------------------------- |
OSErr InitMacStuff(void) |
{ |
long *appSize; |
OSErr theErr = noErr; |
// This decreases the application heap by 16k |
// (which increases the stack by 16k.) |
appSize = (long*)(GetApplLimit()); |
SetApplLimit (appSize -16384); |
// Expand the heap so code segments load at the top. |
MaxApplZone(); |
// allocate more master pointers |
MoreMasters(); |
MoreMasters(); |
// ****** Init Mac toolbox ****** |
InitGraf (&qd.thePort); |
InitFonts(); |
InitWindows(); |
InitMenus(); |
TEInit(); |
InitDialogs(0L); |
InitCursor(); |
// initialise movie toolbox |
theErr = EnterMovies(); |
if (theErr) |
{ |
DebugStr("\pError in initialising movie toolbox."); |
} |
return(theErr); |
} |
//---------------------------------------------- |
// InitGlobals |
// |
// Initialise all "Show Movie" globals |
//---------------------------------------------- |
void InitGlobals(void) |
{ |
short windCount; |
// init the windows list |
for (windCount = 0; windCount < kMaxWindows; windCount++) |
gTheWinds[windCount] = nil; |
gDone = false; // Set the done flag |
InitMovieGlobals(); // init the movie globals |
InitMoviePrefs(); // init the movie prefs |
MenuBarInit(); // init menubar |
} |
//---------------------------------------------- |
// KillGlobals |
// |
// Kills all "Show Window" Globals and closes the windows |
//---------------------------------------------- |
void KillGlobals(void) |
{ |
CloseAllWindows(); |
KillMovieGlobals(); |
KillMoviePrefs(); |
} |
//============================================== |
// Event Loop and event handling |
//============================================== |
//---------------------------------------------- |
// HandleMouseDown |
// |
// This looks after a mouse down. It works out where |
// the mouse has clicked and then deals with it |
// apropriately |
//---------------------------------------------- |
void HandleMouseDown(EventRecord *eventPtr); |
void HandleMouseDown(EventRecord *eventPtr) |
{ |
WindowPtr window; |
short thePart; |
long menuChoice; |
// Find out where the user has clicked |
thePart=FindWindow (eventPtr->where,&window); |
switch (thePart) |
{ |
// Handle a click in the menu bar |
case inMenuBar: |
menuChoice = MenuSelect (eventPtr->where); // Displays menus and returns a selection |
DoMenuCommand(menuChoice); // Respond to the menu choice |
break; |
// In a desk accesory window, so let the system deal with it |
case inSysWindow: |
SystemClick(eventPtr,window); |
break; |
// In the title bar (drag region) |
// so drag the window around |
case inDrag: |
DragSelWind(window,eventPtr->where); |
// In the go away button |
// need to tracks the mouse and close the window if released in go away button |
case inGoAway: |
DoGoAwayWind(window,eventPtr->where); |
break; |
// In the windows content area |
case inContent: |
{ |
// If this is not the front window, then bring the window to the front |
if (window!=FrontWindow()) |
{ |
SelectWindow(window); |
break; |
} |
} |
break; |
} |
} |
//---------------------------------------------- |
// DoDiskEvt |
// |
// Handle disk inserted event |
//---------------------------------------------- |
void DoDiskEvt(EventRecord *eventPtr); |
void DoDiskEvt(EventRecord *eventPtr) |
{ |
short errResult; |
Point errPoint; |
if((HiWord(eventPtr->message)!=noErr)) |
{ |
SetPt(&errPoint,100,100); |
errResult=DIBadMount(errPoint,eventPtr->message); |
} |
} |
//---------------------------------------------- |
// Event Loop |
//---------------------------------------------- |
void EventLoop (void) |
{ |
EventRecord event; // The event returned |
char theChar; // what character the user pressed |
long menuChoice; // Menu & item the user selected |
DoAdjustMenus(); // Adjust appropriately |
// Keep going until the user decides to quit (i.e. gDone = true) |
while (!gDone) |
{ |
// Change the cursor to an arrow |
SetCursor( &(qd.arrow)); |
// Receive every event from the system |
WaitNextEvent (everyEvent,&event,0,nil); |
// Do anything that the movies needs to do, including clicking |
// in the movie control |
if (!ServiceMovieTasks( FrontWindow(), &event )) |
{ |
// If event still needs to handled then do switch |
switch (event.what) |
{ |
// null event, do nothing |
case nullEvent: |
break; |
// user has clicked so deal with it |
case mouseDown: |
HandleMouseDown(&event); |
break; |
// user has pressed a key |
case keyDown: |
case autoKey: |
// Extract the key pressed |
theChar=event.message & charCodeMask; |
// If the Command key was down then compare it pass it |
if (event.modifiers & cmdKey) |
{ |
menuChoice = MenuKey (theChar); // Find out what menu was selected by the keypress |
DoMenuCommand( menuChoice ); // Respond to the menu choice |
} |
break; |
// window needs to be updated, or redrawn |
case updateEvt: |
DoWindUpdate((WindowPtr)(event.message)); |
break; |
// disk inserted event |
case diskEvt: |
DoDiskEvt(&event); |
break; |
// Operating system event |
case osEvt: |
break; |
} |
} |
} |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-01-14