player.c

Go to the documentation of this file.
00001 
00002 /*  $Id: player.c 1254 2006-04-12 20:27:14Z sethdill $    */
00003 
00004 /******************************************************************************
00005 
00006     UserLand Frontier(tm) -- High performance Web content management,
00007     object database, system-level and Internet scripting environment,
00008     including source code editing and debugging.
00009 
00010     Copyright (C) 1992-2004 UserLand Software, Inc.
00011 
00012     This program is free software; you can redistribute it and/or modify
00013     it under the terms of the GNU General Public License as published by
00014     the Free Software Foundation; either version 2 of the License, or
00015     (at your option) any later version.
00016 
00017     This program is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020     GNU General Public License for more details.
00021 
00022     You should have received a copy of the GNU General Public License
00023     along with this program; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 
00026 ******************************************************************************/
00027 
00028 /*
00029 player.c -- This file handles the QuickTime player window.
00030 
00031 PBS 08/08/00
00032 */ 
00033 
00034 #ifdef MACVERSION /*This is a Mac-only feature.*/
00035 
00036 #include "frontier.h"
00037 #include "standard.h"
00038 
00039 #include "quickdraw.h"
00040 #include "strings.h"
00041 #include "bitmaps.h"
00042 #include "cursor.h"
00043 #include "dialogs.h"
00044 #include "icon.h"
00045 #include "file.h"
00046 #include "font.h"
00047 #include "kb.h"
00048 #include "memory.h"
00049 #include "mouse.h"
00050 #include "ops.h"
00051 #include "popup.h"
00052 #include "resources.h"
00053 #include "scrollbar.h"
00054 #include "smallicon.h"
00055 #include "textedit.h"
00056 #include "frontierwindows.h"
00057 #include "windowlayout.h"
00058 #include "zoom.h"
00059 #include "shell.h"
00060 #include "shellprivate.h"
00061 #include "shellhooks.h"
00062 #include "player.h"
00063 #include "tablestructure.h"
00064 #include "cancoon.h"
00065 #include "cancooninternal.h"
00066 #include "process.h"
00067 #include "processinternal.h"
00068 #include "lang.h"
00069 #include "langinternal.h"
00070 
00071 
00072 #define moviestasktime 30
00073 
00074 typedef struct typlayerrecord {
00075     
00076     long refcon;
00077     } typlayerrecord, *ptrplayerrecord, **hdlplayerrecord;
00078 
00079 
00080 static hdlplayerrecord playerdata = nil;
00081 
00082 static WindowPtr playerwindow = nil;
00083 
00084 static hdlwindowinfo playerwindowinfo;
00085 
00086 static hdlplayerrecord displayedplayerdata = nil;
00087 
00088 static WindowPtr playerport = nil;
00089 
00090 static Movie currentmovie = nil;
00091 
00092 static MovieController currentcontroller = nil;
00093 
00094 static Rect currentmovierect;
00095 
00096 static byte * playerstrings [] = {
00097 
00098     BIGSTRING ("\x06" "Player"),
00099 
00100     };
00101 
00102 
00103 enum { /*player window items*/
00104     
00105     titleitem
00106     };
00107 
00108 
00109 /*Prototypes*/
00110 
00111 static boolean newplayerwindow (void);
00112 
00113 static void playerwindowsetup (void);
00114 
00115 static boolean attachplayer (void);
00116 
00117 static boolean playerresetrects (hdlwindowinfo hinfo);
00118 
00119 static boolean findplayerwindow (hdlwindowinfo *hinfo);
00120 
00121 static void playersetconfigminimum (void);
00122 
00123 static void detachplayer (void);
00124 
00125 static void playerdisposecurrentmovie (void);
00126 
00127 pascal Boolean playermoviecontrollereventfilter (MovieController mc, short action, void *params, long refcon);
00128 
00129 
00130 /*Functions*/
00131 
00132 boolean playeropencommand (void) {
00133     
00134     /*
00135     Called to open the player window.
00136     */
00137     
00138     hdlwindowinfo hinfo;
00139     
00140     if (findplayerwindow (&hinfo)) {
00141         
00142         /*If the window is already open,
00143         bring it to the front.*/
00144         
00145         shellbringtofront (hinfo);
00146         
00147         return (true);
00148         } /*if*/
00149     
00150     /*Create and open a new player window.*/
00151     
00152     return (newplayerwindow ());
00153     } /*playeropencommand*/
00154 
00155 
00156 static boolean newplayerwindow (void) {
00157     
00158     WindowPtr w;
00159     hdlwindowinfo hw;
00160     bigstring bstitle;
00161     Rect rzoom, rwindow;
00162     hdlplayerrecord hdata;
00163     short ixplayerconfig;
00164     
00165     if (!newclearhandle (sizeof (typlayerrecord), (Handle *) &hdata))
00166         return (false);
00167     
00168     shellfindcallbacks (idplayerconfig, &ixplayerconfig);
00169         
00170     getsystemoriginrect (&rzoom);
00171     
00172     rwindow = rzoom;
00173     
00174     rwindow.top = 100;
00175     
00176     rwindow.left = 100;
00177     
00178     rwindow.right = 300;
00179     
00180     rwindow.bottom = 200;
00181         
00182     copystring (playerstrings [titleitem], bstitle);
00183     
00184     if (!newchildwindow (idplayerconfig, nil, &rwindow, &rzoom, bstitle, &w)) {
00185         
00186         disposehandle ((Handle) hdata);
00187         
00188         return (false);
00189         }
00190     
00191     getwindowinfo (w, &hw);
00192     
00193     (**hw).hdata = (Handle) hdata;
00194     
00195     shellpushglobals (w);
00196     
00197     playerwindowsetup ();
00198     
00199     playerresetrects (hw);
00200     
00201     playersetconfigminimum ();
00202 
00203     shellpopglobals ();
00204     
00205     windowzoom (w);
00206     
00207     return (true);  
00208     } /*newplayerwindow*/
00209 
00210 
00211 static void playerwindowsetup (void) {
00212             
00213     if (attachplayer ()) {
00214         
00215         shellpushrootglobals (playerwindow);
00216 
00217         shellpopglobals ();
00218 
00219         detachplayer ();
00220         }
00221     } /*playerwindowsetup*/
00222 
00223 
00224 static boolean attachplayer (void) {
00225     
00226     hdlwindowinfo hroot;
00227     
00228     if (playerdata == nil)
00229         return (false);
00230 
00231     if (!ccfindrootwindow (&hroot)) {
00232         
00233         (**playerwindowinfo).parentwindow = nil;
00234         
00235         return (false);
00236         }
00237     
00238     (**playerwindowinfo).parentwindow = hroot;
00239     
00240     return (true);
00241     } /*attachplayer*/
00242 
00243 
00244 static boolean playerresetrects (hdlwindowinfo hinfo) {
00245 #pragma unused (hinfo)
00246 
00247     return (true);
00248     } /*playerresetrects*/
00249 
00250 
00251 static boolean findplayerwindow (hdlwindowinfo *hinfo) {
00252 
00253     WindowPtr w;
00254     Handle hdata;
00255     
00256     return (shellfindwindow (idplayerconfig, &w, hinfo, &hdata));
00257     } /*findplayerwindow*/
00258 
00259 
00260 static void playersetconfigminimum (void) {
00261     
00262     short ixplayerconfig;
00263     Rect *rmin;
00264     
00265     if (shellfindcallbacks (idplayerconfig, &ixplayerconfig)) {
00266     
00267         rmin = &globalsarray [ixplayerconfig].config.rmin;
00268         
00269         (*rmin).bottom = 200;
00270     
00271         (*rmin).right = 200;
00272         
00273         (*rmin).left = 150;
00274         
00275         (*rmin).top = 150;
00276 
00277         }
00278     } /*playersetconfigminimum*/
00279 
00280 
00281 static void detachplayer (void) {
00282     
00283     (**playerwindowinfo).parentwindow = nil;
00284     } /*detachplayer*/
00285 
00286 
00287 #if 0
00288 
00289 static boolean playersave (ptrfilespec fs, hdlfilenum fnum, short rnum, boolean flsaveas, boolean flrunnable) {
00290 
00291     hdlwindowinfo hinfo;
00292     
00293     if (ccfindrootwindow (&hinfo)) {
00294         
00295         shellpushglobals ((**hinfo).macwindow);
00296         
00297         grayownedwindows (shellwindow);
00298         
00299         ccsavefile (fs, fnum, rnum, flsaveas, flrunnable);
00300         
00301         shellpopglobals ();
00302         }
00303     
00304     return (true);
00305     } /*playersave*/
00306 
00307 #endif
00308 
00309 
00310 static boolean playerdisposerecord (void) {
00311     
00312     disposehandle ((Handle) playerdata);
00313     
00314     playerdata = nil;
00315     
00316     displayedplayerdata = nil;
00317     
00318     playerport = nil;
00319     
00320     playerdisposecurrentmovie ();
00321 
00322     return (true);
00323     } /*playerdisposerecord*/
00324 
00325 
00326 static boolean playerclose (void) {
00327     
00328     playerdisposecurrentmovie ();
00329         
00330     detachplayer ();
00331     
00332     playerwindow = nil;
00333     
00334     return (true);
00335     } /*playerclose*/
00336 
00337 
00338 static boolean playergettargetdata (short id) {
00339     
00340     return (id == -1); /*true if target type is generic -- a shell verb*/
00341     } /*playergettargetdata*/
00342 
00343     
00344 #if 0
00345 
00346 static boolean playersetsuperglobals (void) {
00347     
00348     hdlwindowinfo hinfo;
00349     
00350     if (ccfindrootwindow (&hinfo)) {
00351         
00352         shellpushglobals ((**hinfo).macwindow);
00353         
00354         ccsetsuperglobals ();
00355         
00356         shellpopglobals ();
00357         }
00358     
00359     return (true);
00360     } /*playersetsuperglobals*/
00361 
00362 
00363 static void playerupdate (void) {
00364     
00365     /*
00366     */
00367     
00368     if (currentmovie == nil)
00369         return;
00370         
00371     BeginUpdate (playerwindow);
00372     
00373     UpdateMovie (currentmovie);
00374     
00375     EndUpdate (playerwindow);
00376     
00377     MoviesTask (nil, 0);
00378     
00379     MCIdle (currentcontroller);
00380     } /*playerupdate*/
00381 
00382 
00383 static void playerfitwindowtomovie (void) {
00384     
00385     /*
00386     7.0b4 PBS: resize the player window to fit the movie and its controller.
00387     */
00388     
00389     if (currentmovie == nil)
00390         
00391         return;
00392         
00393     if (currentcontroller == nil)
00394     
00395         return;
00396     
00397     SizeWindow (playerwindow, currentmovierect.right, currentmovierect.bottom, true);
00398     
00399     AlignWindow (playerwindow, false, nil, nil); /*position for optimal playback*/
00400     } /*playerfitwindowtomovie*/
00401 
00402 
00403 static boolean playeropenmoviefile (FSSpec *f) {
00404     
00405     /*
00406     7.0b4 PBS: open a movie from disk.
00407     */
00408     
00409     OSErr err;
00410     
00411     short movieresref;
00412     
00413     playerdisposecurrentmovie (); /*dispose the current movie*/
00414     
00415     err = OpenMovieFile (f, &movieresref, fsRdPerm);
00416     
00417     if (err != noErr)
00418         
00419         return (false);
00420     
00421     NewMovieFromFile (&currentmovie, movieresref, nil, nil, newMovieActive, nil);   
00422     
00423     CloseMovieFile (movieresref);
00424         
00425     return (true);
00426     } /*playeropenmoviefile*/
00427 
00428 #endif
00429 
00430 
00431 static void playerdisposecurrentmovie (void) {
00432     
00433     /*
00434     7.0b4 PBS: dispose the current movie and controller, if there is one.
00435     */
00436     
00437     if (currentcontroller != nil) {
00438         
00439         DisposeMovieController (currentcontroller);
00440         
00441         currentcontroller = nil;
00442         }
00443 
00444     if (currentmovie != nil) {
00445         
00446         DisposeMovie (currentmovie);
00447         
00448         currentmovie = nil; 
00449         }   
00450     } /*playerdisposecurrentmovie*/
00451 
00452 
00453 boolean isplayerevent (void) {
00454     
00455     /*
00456     7.0b4 PBS: called from the main event loop.
00457     QuickTime needs to catch some events.
00458     Return true if the event is consumed by QuickTime
00459     and should be ignored by the event loop.
00460     */
00461     
00462     boolean fl = false;
00463     
00464     if (currentmovie == nil) /*if no current movie, return right away*/
00465     
00466         return (fl);
00467     
00468     if (currentcontroller == nil) /*if no controller, return right away*/
00469         
00470         return (fl);
00471     
00472     if (MCIsPlayerEvent (currentcontroller, &shellevent))
00473         
00474         fl = true; /*the event was consumed by QuickTime*/
00475     
00476     MCIdle (currentcontroller);
00477     
00478     MoviesTask (nil, 0);
00479         
00480     return (fl);
00481     } /*isplayerevent*/
00482 
00483 
00484 pascal Boolean playermoviecontrollereventfilter (MovieController mc, short action, void *params, long refcon) {
00485 #pragma unused (mc, refcon, params)
00486 
00487     /*
00488     7.0b4 PBS: Handle movie controller events.
00489     Unused -- but there's a good chance it will be needed later.
00490     */
00491 
00492     if (action == mcActionControllerSizeChanged) {
00493     
00494         Rect bounds;
00495         
00496         MCGetControllerBoundsRect (currentcontroller, &bounds);
00497         
00498         SizeWindow (playerwindow, bounds.right, bounds.bottom, false);
00499         } /*if*/
00500 
00501     return (false); /*Further processing should occur.*/    
00502     } /*playermoviecontrollereventfilter*/
00503 
00504 
00505 boolean playeropenmovieinwindow (FSSpec *f) {
00506     
00507     /*
00508     7.0b4 PBS: open a movie in the QuickTime Player window and display it.
00509     If the window isn't already open, open it.
00510     */
00511     
00512     short movieresref;
00513     
00514     OSErr err;
00515     
00516     hdlwindowinfo hinfo;
00517     
00518     if (!findplayerwindow (&hinfo))
00519         
00520         playeropencommand (); /*If the Player window doesn't exist, create a new one.*/
00521         
00522     getwindowinfo (playerwindow, &playerwindowinfo);
00523         
00524     playerdisposecurrentmovie (); /*make sure the current movie has been disposed*/
00525     
00526     #if TARGET_API_MAC_CARBON == 1
00527     
00528         SetGWorld (GetWindowPort (playerwindow), nil);
00529     
00530     #else
00531     
00532         SetGWorld ((CGrafPtr) playerwindow, nil);
00533     
00534     #endif
00535             
00536     err = OpenMovieFile (f, &movieresref, fsRdPerm);
00537     
00538     if (err != noErr)
00539         
00540         return (false);
00541     
00542     NewMovieFromFile (&currentmovie, movieresref, nil, nil, newMovieActive, nil);
00543             
00544     CloseMovieFile (movieresref);
00545     
00546     #if TARGET_API_MAC_CARBON == 1
00547 
00548         SetMovieGWorld (currentmovie, GetWindowPort (playerwindow), nil);
00549     
00550     #else
00551     
00552         SetMovieGWorld (currentmovie, (CGrafPtr) playerwindow, nil);
00553         
00554     #endif
00555         
00556     GetMovieBox (currentmovie, &currentmovierect);
00557     
00558     OffsetRect (&currentmovierect, -currentmovierect.left, -currentmovierect.top);
00559     
00560     SetMovieBox (currentmovie, &currentmovierect);      
00561         
00562     currentcontroller = NewMovieController (currentmovie, &currentmovierect, mcTopLeftMovie);
00563     
00564     MCGetControllerBoundsRect (currentcontroller, &currentmovierect);
00565     
00566     //MCSetActionFilterWithRefCon (currentcontroller, NewMCActionFilterWithRefConProc(playermoviecontrollereventfilter), (long) playerwindow);
00567     
00568     SizeWindow (playerwindow, currentmovierect.right, currentmovierect.bottom, false);
00569     
00570     (**playerwindowinfo).contentrect = currentmovierect;
00571     
00572     AlignWindow (playerwindow, false, nil, nil); /*position for optimal playback*/
00573     
00574     //MCDoAction (currentcontroller, mcActionSetKeysEnabled, (void *) true); /*enable keyboard input*/ /*No!*/
00575     
00576     MoviesTask (nil, 0);
00577     
00578     MCIdle (currentcontroller);
00579         
00580     return (true);  
00581     } /*playeropenmovieinwindow*/
00582 
00583 
00584 boolean playerplaymovie (void) {
00585     
00586     /*
00587     7.0b4 PBS: play the movie that's loaded.
00588     */
00589     
00590     if (currentmovie == nil)
00591         
00592         return (false);
00593         
00594     GoToBeginningOfMovie (currentmovie);
00595     
00596     SetMovieActive (currentmovie, true);
00597     
00598     MCDoAction (currentcontroller, mcActionPlay, (void *) true); /*Start playing.*/
00599     
00600     MoviesTask (nil, 0);
00601     
00602     return (true);
00603     } /*playerplaymovie*/
00604 
00605 
00606 boolean playerstopmovie (void) {
00607     
00608     /*
00609     7.0b4 PBS: stop playing a movie.
00610     */
00611     
00612     if (currentmovie != nil)
00613 
00614         SetMovieActive (currentmovie, false);
00615     
00616     return (true);
00617     } /*playerstopmovie*/
00618 
00619 
00620 boolean playerisplaying (void) {
00621     
00622     /*
00623     7.0b4 PBS: return true if the player window is playing a movie.
00624     */
00625     
00626     if (currentmovie == nil)
00627         
00628         return (false);
00629     
00630     if (IsMovieDone (currentmovie))
00631     
00632         return (false);
00633     
00634     return (GetMovieActive (currentmovie));
00635     } /*playerisplaying*/
00636 
00637 
00638 static void playerquit (void) {
00639     
00640     /*
00641     7.0b4 PBS: quit routine.
00642     */
00643     
00644     playerdisposecurrentmovie ();
00645     } /*playerquit*/
00646 
00647 
00648 static void playeractivate (boolean fl) {
00649 
00650     #pragma unused (fl)
00651 
00652     return; 
00653     } /*playeractivate*/
00654 
00655 
00656 static void playeridle (void) {
00657     
00658     /*
00659     7.0b4 PBS: idle routine.
00660     */
00661     
00662     if (currentcontroller != nil) {
00663         
00664         MCIdle (currentcontroller); /*Give time to QuickTime.*/
00665         }
00666     } /*playeridle*/
00667 
00668 
00669 boolean playerstart (void) {
00670     
00671     /*
00672     7.0b4 PBS: Set up callback routines record, and link our data into the shell's 
00673     data structure.
00674     */
00675     
00676     ptrcallbacks playercallbacks;
00677     register ptrcallbacks cb;
00678     static boolean playerstarted = false;
00679     
00680     if (playerstarted)
00681         return (true);
00682     
00683     playerstarted = true;
00684     
00685     EnterMovies (); /*init QuickTime*/
00686             
00687     shellnewcallbacks (&playercallbacks);
00688     
00689     cb = playercallbacks; /*copy into register*/
00690     
00691     loadconfigresource (idplayerconfig, &(*cb).config);
00692     
00693     (*cb).configresnum = idplayerconfig;
00694         
00695     (*cb).windowholder = &playerwindow;
00696     
00697     (*cb).dataholder = (Handle *) &playerdata;
00698     
00699     (*cb).infoholder = &playerwindowinfo;
00700     
00701     (*cb).setglobalsroutine = &attachplayer;
00702     
00703     (*cb).quitroutine = &playerquit;
00704         
00705     (*cb).disposerecordroutine = &playerdisposerecord;
00706     
00707     (*cb).closeroutine = &playerclose;
00708     
00709     (*cb).gettargetdataroutine = &playergettargetdata;
00710         
00711     (*cb).activateroutine = &playeractivate;
00712     
00713     (*cb).idleroutine = &playeridle;
00714     
00715     return (true);
00716     } /*playerstart*/
00717 
00718 #endif /*MACVERSION -- Mac-only feature*/

Generated on Wed May 31 18:20:00 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6