-
Notifications
You must be signed in to change notification settings - Fork 3
/
listing1.html
executable file
·760 lines (611 loc) · 22.6 KB
/
listing1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<!-- BEGIN META TAG INFO -->
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="home" href="http://developer.apple.com/">
<link rel="find" href="http://developer.apple.com/search/">
<link rel="stylesheet" type="text/css" href="../../documentation/css/adcstyle.css" title="fonts">
<script language="JavaScript" src="../../documentation/js/adc.js" type="text/javascript"></script>
<!-- END META TAG INFO -->
<!-- BEGIN TITLE -->
<title>MovieSprites - /Application Files/ComApplication.c</title>
<!-- END TITLE -->
<script language="JavaScript">
function JumpToNewPage() {
window.location=document.scpopupmenu.gotop.value;
return true;
}
</script>
</head>
<!-- BEGIN BODY OPEN -->
<body>
<!--END BODY OPEN -->
<!-- START CENTER OPEN -->
<center>
<!-- END CENTER OPEN -->
<!-- BEGIN LOGO AND SEARCH -->
<!--#include virtual="/includes/adcnavbar"-->
<!-- END LOGO AND SEARCH -->
<!-- START BREADCRUMB -->
<div id="breadcrumb">
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr>
<td scope="row"><img width="340" height="10" src="images/1dot.gif" alt=""></td>
<td><img width="340" height="10" src="images/1dot.gif" alt=""></td>
</tr>
<tr valign="middle">
<td align="left" colspan="2">
<a href="http://developer.apple.com/">ADC Home</a> > <a href="../../referencelibrary/index.html">Reference Library</a> > <a href="../../samplecode/index.html">Sample Code</a> > <a href="../../samplecode/QuickTime/index.html">QuickTime</a> > <a href="../../samplecode/QuickTime/idxWiredMoviesandSprites-date.html">Wired Movies and Sprites</a> > <A HREF="javascript:location.replace('index.html');">MovieSprites</A> >
</td>
</tr>
<tr>
<td colspan="2" scope="row"><img width="680" height="35" src="images/1dot.gif" alt=""></td>
</tr>
</table>
</div>
<!-- END BREADCRUMB -->
<!-- START MAIN CONTENT -->
<!-- START TITLE GRAPHIC AND INTRO-->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td><h1><div id="pagehead">MovieSprites</div></h1></td>
</tr>
</table>
<!-- END TITLE GRAPHIC AND INTRO -->
<!-- START WIDE COLUMN -->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td id="scdetails">
<h2>/Application Files/ComApplication.c</h2>
<form name="scpopupmenu" onSubmit="return false;" method=post>
<p><strong>View Source Code:</strong>
<select name="gotop" onChange="JumpToNewPage();" style="width:340px"><option selected value="ingnore">Select File</option>
<option value="listing1.html">/Application Files/ComApplication.c</option>
<option value="listing2.html">/Application Files/ComApplication.h</option>
<option value="listing3.html">/Application Files/ComResource.h</option>
<option value="listing4.html">/Clippings/AddKeyFrameSampleMedia.txt</option>
<option value="listing5.html">/Clippings/AddMovieResource.txt</option>
<option value="listing6.html">/Clippings/AddOverrideSamples.txt</option>
<option value="listing7.html">/Clippings/AddSpritesToKeyFrameSample.txt</option>
<option value="listing8.html">/Clippings/CreateKeyFrameSample.txt</option>
<option value="listing9.html">/Clippings/CreateSpriteMovie.txt</option>
<option value="listing10.html">/Clippings/CreateSpriteTrackAndMedia.txt</option>
<option value="listing11.html">/Common Files/ComFramework.c</option>
<option value="listing12.html">/Common Files/ComFramework.h</option>
<option value="listing13.html">/Common Files/EndianUtilities.c</option>
<option value="listing14.html">/Common Files/EndianUtilities.h</option>
<option value="listing15.html">/Common Files/ImageCompressionUtilities.c</option>
<option value="listing16.html">/Common Files/ImageCompressionUtilities.h</option>
<option value="listing17.html">/Common Files/MacFramework.c</option>
<option value="listing18.html">/Common Files/MacFramework.h</option>
<option value="listing19.html">/Common Files/MacPrefix.h</option>
<option value="listing20.html">/Common Files/QTUtilities.c</option>
<option value="listing21.html">/Common Files/QTUtilities.h</option>
<option value="listing22.html">/Common Files/SpriteUtilities.c</option>
<option value="listing23.html">/Common Files/SpriteUtilities.h</option>
<option value="listing24.html">/Common Files/WinPrefix.h</option>
<option value="listing25.html">/Completed Lab/QTSprites.c</option>
<option value="listing26.html">/Completed Lab/QTSprites.h</option>
<option value="listing27.html">/Completed Lab/QTSprites.r</option>
<option value="listing28.html">/Start Code/QTSprites.c</option>
<option value="listing29.html">/Start Code/QTSprites.h</option></select>
</p>
</form>
<p><strong><a href="MovieSprites.zip">Download Sample</a></strong> (“MovieSprites.zip”, 2.08M)<BR>
<strong><a href="MovieSprites.dmg">Download Sample</a></strong> (“MovieSprites.dmg”, 2.72M)</p>
<!--
<p><strong><a href="#">Download Sample</a></strong> (“filename.sit”, 500K)</p>
-->
</td>
</tr>
<tr>
<td scope="row"><img width="680" height="10" src="images/1dot.gif" alt=""><br>
<img height="1" width="680" src="images/1dot_919699.gif" alt=""><br>
<img width="680" height="20" src="images/1dot.gif" alt=""></td>
</tr>
<tr>
<td scope="row">
<!--googleon: index -->
<pre class="sourcecodebox">////////////// File: ComApplication.c//// Contains: Application-specific code for basic QuickTime movie display and control.//// Written by: Tim Monroe// Based on the QTShell code written by Tim Monroe, which in turn was based on the MovieShell// code written by Kent Sandvik (Apple DTS). This current version is now very far removed from// MovieShell.//// Copyright: © 1999 by Apple Computer, Inc., all rights reserved.//// Change History (most recent first):// // <2> 03/17/00 rtm made changes to get things running under CarbonLib// <1> 11/05/99 rtm first file////////////////////////// header files////////////#ifndef __COMAPPLICATION__#include "ComApplication.h"#endif#include "QTSprites.h"////////////// global variables////////////extern Boolean gUseBackgroundPicture;#if TARGET_OS_MACAEEventHandlerUPP gHandleOpenAppAEUPP; // UPPs for our Apple event handlersAEEventHandlerUPP gHandleOpenDocAEUPP;AEEventHandlerUPP gHandlePrintDocAEUPP;AEEventHandlerUPP gHandleQuitAppAEUPP;extern Boolean gAppInForeground; // is our application in the foreground? #endif#if TARGET_OS_WIN32extern HWND ghWnd; // the MDI frame window; this window has the menu bar#endif////////////// QTApp_Init// Do any application-specific initialization.//// The theStartPhase parameter determines which "phase" of application start-up is executed,// *before* the MDI frame window is created or *after*. This distinction is relevant only on// Windows, so on MacOS, you should always use kInitAppPhase_BothPhases.////////////void QTApp_Init (UInt32 theStartPhase){ // do any start-up activities that should occur before the MDI frame window is created if (theStartPhase & kInitAppPhase_BeforeCreateFrameWindow) { // check to make sure that QuickTime wired sprites are available; // we depend on these features if (!QTUtils_HasWiredSprites()) QTFrame_QuitFramework();#if TARGET_OS_MAC // make sure that the Apple Event Manager is available; install handlers for required Apple events QTApp_InstallAppleEventHandlers();#endif } // do any start-up activities that should occur after the MDI frame window is created if (theStartPhase & kInitAppPhase_AfterCreateFrameWindow) {#if TARGET_OS_WIN32 // on Windows, open as movie documents any files specified on the command line SendMessage(ghWnd, WM_OPENDROPPEDFILES, 0L, 0L);#endif }}////////////// QTApp_Stop// Do any application-specific shut-down.//// The theStopPhase parameter determines which "phase" of application shut-down is executed,// *before* any open movie windows are destroyed or *after*.////////////void QTApp_Stop (UInt32 theStopPhase){ // do any shut-down activities that should occur before the movie windows are destroyed if (theStopPhase & kStopAppPhase_BeforeDestroyWindows) { } // do any shut-down activities that should occur after the movie windows are destroyed if (theStopPhase & kStopAppPhase_AfterDestroyWindows) {#if TARGET_OS_MAC // dispose of routine descriptors for Apple event handlers DisposeAEEventHandlerUPP(gHandleOpenAppAEUPP); DisposeAEEventHandlerUPP(gHandleOpenDocAEUPP); DisposeAEEventHandlerUPP(gHandlePrintDocAEUPP); DisposeAEEventHandlerUPP(gHandleQuitAppAEUPP);#endif }}////////////// QTApp_Idle// Do any processing that can/should occur at idle time.////////////void QTApp_Idle (WindowReference theWindow){ WindowObject myWindowObject = NULL; GrafPtr mySavedPort; //Cursor myArrow; GetPort(&mySavedPort); MacSetPort(QTFrame_GetPortFromWindowReference(theWindow)); myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow); if (myWindowObject != NULL) { MovieController myMC = NULL; myMC = (**myWindowObject).fController; if (myMC != NULL) { // run any idle-time tasks for the movie #if TARGET_OS_MAC // restore the cursor to the arrow // if it's outside the front movie window or outside the window's visible region if (theWindow == QTFrame_GetFrontMovieWindow()) { Rect myRect; Point myPoint; RgnHandle myVisRegion; Cursor myArrow; GetMouse(&myPoint); myVisRegion = NewRgn(); GetPortVisibleRegion(QTFrame_GetPortFromWindowReference(theWindow), myVisRegion); GetWindowPortBounds(theWindow, &myRect); if (!MacPtInRect(myPoint, &myRect) || !PtInRgn(myPoint, myVisRegion)) MacSetCursor(GetQDGlobalsArrow(&myArrow)); DisposeRgn(myVisRegion); }#endif // TARGET_OS_MAC } } // ***insert application-specific idle-time processing here*** MacSetPort(mySavedPort);}////////////// QTApp_Draw// Update the specified window.////////////void QTApp_Draw (WindowReference theWindow, Rect *theRefreshArea){#pragma unused(theRefreshArea) GrafPtr mySavedPort; GetPort(&mySavedPort); MacSetPort(QTFrame_GetPortFromWindowReference(theWindow)); BeginUpdate(QTFrame_GetWindowFromWindowReference(theWindow)); //EraseRect(theRefreshArea); // this is important only for non-rectangular movies // ***insert application-specific drawing here*** // draw the movie controller and its movie MCDoAction(QTFrame_GetMCFromWindow(theWindow), mcActionDraw, theWindow); EndUpdate(QTFrame_GetWindowFromWindowReference(theWindow)); MacSetPort(mySavedPort);}////////////// QTApp_HandleContentClick// Handle mouse button clicks in the specified window.////////////void QTApp_HandleContentClick (WindowReference theWindow, EventRecord *theEvent){#pragma unused(theEvent) GrafPtr mySavedPort; GetPort(&mySavedPort); MacSetPort(QTFrame_GetPortFromWindowReference(theWindow)); // ***insert application-specific content-click processing here*** MacSetPort(mySavedPort);}////////////// QTApp_HandleKeyPress// Handle application-specific key presses.// Returns true if the key press was handled, false otherwise.////////////Boolean QTApp_HandleKeyPress (char theCharCode){ Boolean isHandled = true; switch (theCharCode) { // ***insert application-specific key-press processing here*** default: isHandled = false; break; } return(isHandled);}////////////// QTApp_HandleMenu// Handle selections in the application's menus.//// The theMenuItem parameter is a UInt16 version of the Windows "menu item identifier". // When called from Windows, theMenuItem is simply the menu item identifier passed to the window procedure.// When called from MacOS, theMenuItem is constructed like this:// *high-order 8 bits == the Macintosh menu ID (1 thru 256)// *low-order 8 bits == the Macintosh menu item (sequential from 1 to ordinal of last menu item in menu)// In this way, we can simplify the menu-handling code. There are, however, some limitations, mainly that// the menu item identifiers on Windows must be derived from the Mac values. ////////////Boolean QTApp_HandleMenu (UInt16 theMenuItem){ Boolean myIsHandled = false; // false => allow caller to process the menu item switch (theMenuItem) { case IDM_MAKE_SPRITE_MOVIE: QTSprites_CreateSpritesMovie(); myIsHandled = true; break; case IDM_USE_BACKGROUND_IMAGE: gUseBackgroundPicture = !gUseBackgroundPicture; myIsHandled = true; break; default: break; } // switch (theMenuItem) return(myIsHandled);}////////////// QTApp_AdjustMenus// Adjust state of items in the application's menus.//// Currently, the Mac application has only one app-specific menu ("Test"); you could change that.////////////void QTApp_AdjustMenus (WindowReference theWindow, MenuReference theMenu){#if TARGET_OS_MAC#pragma unused(theMenu)#endif MenuReference myMenu; #if TARGET_OS_WIN32 myMenu = theMenu;#endif#if TARGET_OS_MAC myMenu = GetMenuHandle(kTestMenuResID);#endif QTFrame_SetMenuItemCheck(myMenu, IDM_USE_BACKGROUND_IMAGE, gUseBackgroundPicture);}////////////// QTApp_HandleEvent// Perform any application-specific event loop actions.//// Return true to indicate that we've completely handled the event here, false otherwise.////////////Boolean QTApp_HandleEvent (EventRecord *theEvent){#pragma unused(theEvent) // ***insert application-specific event handling here*** return(false); // no-op for now}////////////// QTApp_SetupController// Configure the movie controller.////////////void QTApp_SetupController (MovieController theMC){ long myControllerFlags; // CLUT table use MCDoAction(theMC, mcActionGetFlags, &myControllerFlags); MCDoAction(theMC, mcActionSetFlags, (void *)(myControllerFlags | mcFlagsUseWindowPalette)); // enable keyboard event handling MCDoAction(theMC, mcActionSetKeysEnabled, (void *)true); // disable drag support MCDoAction(theMC, mcActionSetDragEnabled, (void *)false);}////////////// QTApp_SetupWindowObject// Do any application-specific initialization of the window object.////////////void QTApp_SetupWindowObject (WindowObject theWindowObject){ ApplicationDataHdl myAppData = NULL; if (theWindowObject == NULL) return; myAppData = QTSprites_InitWindowData(theWindowObject); (**theWindowObject).fAppData = (Handle)myAppData;}////////////// QTApp_RemoveWindowObject// Do any application-specific clean-up of the window object.////////////void QTApp_RemoveWindowObject (WindowObject theWindowObject){#pragma unused(theWindowObject) if (theWindowObject != NULL) QTSprites_DumpWindowData(theWindowObject); // QTFrame_DestroyMovieWindow in MacFramework.c or QTFrame_MovieWndProc in WinFramework.c // releases the window object itself}////////////// QTApp_MCActionFilterProc // Intercept some actions for the movie controller.//// NOTE: The theRefCon parameter is a handle to a window object record.////////////PASCAL_RTN Boolean QTApp_MCActionFilterProc (MovieController theMC, short theAction, void *theParams, long theRefCon){#pragma unused(theMC, theParams) Boolean isHandled = false; // false => allow controller to process the action WindowObject myWindowObject = NULL; myWindowObject = (WindowObject)theRefCon; if (myWindowObject == NULL) return(isHandled); switch (theAction) { // handle window resizing case mcActionControllerSizeChanged: if (MCIsControllerAttached(theMC) == 1) QTFrame_SizeWindowToMovie(myWindowObject); break; // handle idle events case mcActionIdle: QTApp_Idle((**myWindowObject).fWindow); break; // handle mouse-down events case mcActionMouseDown: isHandled = QTSprites_HitTestSprites(myWindowObject, (EventRecord *)theParams); break; default: break; } // switch (theAction) return(isHandled); }#if TARGET_OS_MAC/////////////////////////////////////////////////////////////////////////////////////////////////////////////// Apple Event functions.//// Use these functions to install handlers for Apple Events and to handle those events./////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// QTApp_InstallAppleEventHandlers // Install handlers for Apple Events.////////////void QTApp_InstallAppleEventHandlers (void){ long myAttrs; OSErr myErr = noErr; // see whether the Apple Event Manager is available in the present operating environment; // if it is, install handlers for the four required Apple Events myErr = Gestalt(gestaltAppleEventsAttr, &myAttrs); if (myErr == noErr) { if (myAttrs & (1L << gestaltAppleEventsPresent)) { // create routine descriptors for the Apple event handlers gHandleOpenAppAEUPP = NewAEEventHandlerUPP((AEEventHandlerProcPtr)QTApp_HandleOpenApplicationAppleEvent); gHandleOpenDocAEUPP = NewAEEventHandlerUPP((AEEventHandlerProcPtr)QTApp_HandleOpenDocumentAppleEvent); gHandlePrintDocAEUPP = NewAEEventHandlerUPP((AEEventHandlerProcPtr)QTApp_HandlePrintDocumentAppleEvent); gHandleQuitAppAEUPP = NewAEEventHandlerUPP((AEEventHandlerProcPtr)QTApp_HandleQuitApplicationAppleEvent); // install the handlers AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, gHandleOpenAppAEUPP, 0L, false); AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, gHandleOpenDocAEUPP, 0L, false); AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, gHandlePrintDocAEUPP, 0L, false); AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, gHandleQuitAppAEUPP, 0L, false); } }} ////////////// QTApp_HandleOpenApplicationAppleEvent // Handle the open-application Apple Events.////////////PASCAL_RTN OSErr QTApp_HandleOpenApplicationAppleEvent (const AppleEvent *theMessage, AppleEvent *theReply, unsigned long theRefcon) {#pragma unused(theMessage, theReply, theRefcon) // we don't need to do anything special when opening the application return(noErr);}////////////// QTApp_HandleOpenDocumentAppleEvent // Handle the open-document Apple Events. This is based on Inside Macintosh: IAC, pp. 4-15f.//// Here we process an Open Documents AE only for files of type MovieFileType.////////////PASCAL_RTN OSErr QTApp_HandleOpenDocumentAppleEvent (const AppleEvent *theMessage, AppleEvent *theReply, unsigned long theRefcon) {#pragma unused(theReply, theRefcon) long myIndex; long myItemsInList; AEKeyword myKeyWd; AEDescList myDocList; long myActualSize; DescType myTypeCode; FSSpec myFSSpec; OSErr myIgnoreErr = noErr; OSErr myErr = noErr; // get the direct parameter and put it into myDocList myDocList.dataHandle = NULL; myErr = AEGetParamDesc(theMessage, keyDirectObject, typeAEList, &myDocList); // count the descriptor records in the list if (myErr == noErr) myErr = AECountItems(&myDocList, &myItemsInList); else myItemsInList = 0; // open each specified file for (myIndex = 1; myIndex <= myItemsInList; myIndex++) if (myErr == noErr) { myErr = AEGetNthPtr(&myDocList, myIndex, typeFSS, &myKeyWd, &myTypeCode, (Ptr)&myFSSpec, sizeof(myFSSpec), &myActualSize); if (myErr == noErr) { FInfo myFinderInfo; // verify that the file type is MovieFileType; to do this, get the Finder information myErr = FSpGetFInfo(&myFSSpec, &myFinderInfo); if (myErr == noErr) { if (myFinderInfo.fdType == MovieFileType) // we've got a movie file; just open it QTFrame_OpenMovieInWindow(NULL, &myFSSpec); } } } if (myDocList.dataHandle) myIgnoreErr = AEDisposeDesc(&myDocList); // make sure we open the document in the foreground gAppInForeground = true; return(myErr);}////////////// QTApp_HandlePrintDocumentAppleEvent // Handle the print-document Apple Events.//// NOT YET IMPLEMENTED.////////////PASCAL_RTN OSErr QTApp_HandlePrintDocumentAppleEvent (const AppleEvent *theMessage, AppleEvent *theReply, unsigned long theRefcon) {#pragma unused(theMessage, theReply, theRefcon) return(errAEEventNotHandled);}////////////// QTApp_HandleQuitApplicationAppleEvent // Handle the quit-application Apple Events.////////////PASCAL_RTN OSErr QTApp_HandleQuitApplicationAppleEvent (const AppleEvent *theMessage, AppleEvent *theReply, unsigned long theRefcon) {#pragma unused(theMessage, theReply, theRefcon) // close down the entire framework and application QTFrame_QuitFramework(); return(noErr);}#endif // TARGET_OS_MAC</pre>
<!--googleoff: index -->
</td>
</tr>
</table>
<!-- END WIDE COLUMN -->
<!-- END MAIN CONTENT -->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><div style="width: 100%; height: 1px; background-color: #919699; margin-top: 5px; margin-bottom: 15px"></div></td>
</tr>
<tr>
<td align="center"><br/>
<table border="0" cellpadding="0" cellspacing="0" class="graybox">
<tr>
<th>Did this document help you?</th>
</tr>
<tr>
<td>
<div style="margin-bottom: 8px"><a href="http://developer.apple.com/feedback/?v=1&url=/samplecode/MovieSprites/listing1.html%3Fid%3DDTS10001040-1.0&media=dvd" target=_new>Yes</a>: Tell us what works for you.</div>
<div style="margin-bottom: 8px"><a href="http://developer.apple.com/feedback/?v=2&url=/samplecode/MovieSprites/listing1.html%3Fid%3DDTS10001040-1.0&media=dvd" target=_new>It’s good, but:</a> Report typos, inaccuracies, and so forth.</div>
<div><a href="http://developer.apple.com/feedback/?v=3&url=/samplecode/MovieSprites/listing1.html%3Fid%3DDTS10001040-1.0&media=dvd" target=_new>It wasn’t helpful</a>: Tell us what would have helped.</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- START BOTTOM APPLE NAVIGATION -->
<!--#include virtual="/includes/footer"-->
<!-- END BOTTOM APPLE NAVIGATION -->
<!-- START CENTER CLOSE -->
</center>
<!-- END CENTER CLOSE -->
</body>
</html>