Back to index

lightning-sunbird  0.9+nobinonly
CThrobber.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is the Mozilla browser.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications, Inc.
00020  * Portions created by the Initial Developer are Copyright (C) 1999
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Conrad Carlen <ccarlen@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include "CThrobber.h"
00041 
00042 #include <LString.h>
00043 #include <LStream.h>
00044 #include <UDrawingState.h>
00045 #include <UResourceMgr.h>
00046 
00047 #include <QuickTimeComponents.h>
00048 
00049 //*****************************************************************************
00050 //***    CThrobber: constructors/destructor
00051 //*****************************************************************************
00052 
00053 CThrobber::CThrobber() :
00054    mMovieResID(-1), mMovieHandle(nil),
00055    mMovie(nil), mMovieController(nil)
00056 {
00057 }
00058 
00059 
00060 CThrobber::CThrobber(LStream*      inStream) :
00061    LControl(inStream),
00062    mMovieResID(-1), mMovieHandle(nil),
00063    mMovie(nil), mMovieController(nil)
00064 {
00065    *inStream >> mMovieResID;
00066 }
00067 
00068 
00069 CThrobber::~CThrobber()
00070 {
00071     if (mMovieController)
00072         ::DisposeMovieController(mMovieController);
00073     if (mMovieHandle)
00074         ::DisposeHandle(mMovieHandle);   
00075 }
00076 
00077 
00078 void CThrobber::FinishCreateSelf()
00079 {
00080    CreateMovie();
00081 }
00082 
00083 
00084 void CThrobber::ShowSelf()
00085 {
00086     LControl::ShowSelf();
00087     
00088     if (!mMovieController)
00089         return;
00090     
00091     ::MCSetClip(mMovieController, NULL, NULL);
00092 }
00093 
00094 
00095 void CThrobber::HideSelf()
00096 {
00097     LControl::HideSelf();
00098     
00099     if (!mMovieController)
00100         return;    
00101     
00102     StRegion emptyRgn;
00103     ::MCSetClip(mMovieController, NULL, emptyRgn);
00104 }
00105 
00106 
00107 void CThrobber::DrawSelf()
00108 {
00109     if (mMovieController)
00110         ::MCDraw(mMovieController, GetMacWindow());
00111 }
00112 
00113 
00114 void CThrobber::ResizeFrameBy(SInt16             inWidthDelta,
00115                                                  SInt16        inHeightDelta,
00116                                                  Boolean          inRefresh)
00117 {
00118        LControl::ResizeFrameBy(inWidthDelta, inHeightDelta, inRefresh);
00119        
00120        if (!mMovieController)
00121            return;
00122            
00123        FocusDraw();
00124 
00125        Rect newFrame;
00126        ::MCGetControllerBoundsRect(mMovieController, &newFrame);
00127        newFrame.right += inWidthDelta;
00128        newFrame.bottom += inHeightDelta;
00129        ::MCSetControllerBoundsRect(mMovieController, &newFrame);
00130 }
00131 
00132 
00133 void CThrobber::MoveBy(SInt32             inHorizDelta,
00134                                        SInt32           inVertDelta,
00135                                                    Boolean     inRefresh)
00136 {
00137        LControl::MoveBy(inHorizDelta, inVertDelta, inRefresh);
00138 
00139        if (!mMovieController)
00140            return;
00141  
00142        FocusDraw();
00143  
00144        Rect newFrame;       
00145        ::MCGetControllerBoundsRect(mMovieController, &newFrame);
00146        ::OffsetRect(&newFrame, inHorizDelta, inVertDelta);
00147        ::MCSetControllerBoundsRect(mMovieController, &newFrame);
00148 }
00149 
00150 
00151 void CThrobber::SpendTime(const EventRecord      &inMacEvent)
00152 {
00153        FocusDraw();
00154        ::MCIsPlayerEvent(mMovieController, &inMacEvent);
00155 }
00156 
00157        
00158 void CThrobber::Start()
00159 {
00160        if (!mMovieController)
00161            return;
00162  
00163     ::StartMovie(mMovie);
00164     StartRepeating();
00165 }
00166 
00167 
00168 void CThrobber::Stop()
00169 {
00170        if (!mMovieController)
00171            return;
00172  
00173     StopRepeating();
00174     ::StopMovie(mMovie);
00175     ::GoToBeginningOfMovie(mMovie);
00176     Refresh();
00177 }
00178 
00179 
00180 void CThrobber::CreateMovie()
00181 {
00182     OSErr err;
00183     Handle dataRef = NULL;
00184         
00185     try {
00186         // Get the movie from our resource
00187         StApplicationContext appResContext;
00188         
00189         mMovieHandle = ::Get1Resource('GIF ', 128);
00190         ThrowIfResFail_(mMovieHandle);
00191         ::DetachResource(mMovieHandle);
00192         
00193         // Create a dataRef handle - from TN2018
00194        err = ::PtrToHand(&mMovieHandle, &dataRef, sizeof(Handle));
00195        ThrowIfError_(err);
00196        err = ::PtrAndHand("\p", dataRef, 1); 
00197        ThrowIfError_(err);
00198         long  fileTypeAtom[3];
00199        fileTypeAtom[0] = sizeof(long) * 3;
00200        fileTypeAtom[1] = kDataRefExtensionMacOSFileType;
00201        fileTypeAtom[2] = kQTFileTypeGIF;
00202        err = ::PtrAndHand(fileTypeAtom, dataRef, sizeof(long) * 3);
00203        ThrowIfError_(err);
00204        
00205        err = ::NewMovieFromDataRef(&mMovie, newMovieActive, NULL, dataRef, HandleDataHandlerSubType);
00206         ThrowIfError_(err);
00207        DisposeHandle(dataRef);
00208        dataRef = NULL;
00209        
00210        // Make a controller for the movie
00211        Rect   movieBounds;
00212        ::GetMovieBox(mMovie, &movieBounds);
00213        ::MacOffsetRect(&movieBounds, (SInt16) -movieBounds.left, (SInt16) -movieBounds.top);
00214        ::SetMovieBox(mMovie, &movieBounds);
00215 
00216        ::SetMovieGWorld(mMovie, (CGrafPtr) GetMacPort(), nil);
00217 
00218        Rect   frame;
00219        CalcLocalFrameRect(frame);
00220        mMovieController = ::NewMovieController(mMovie, &frame, mcTopLeftMovie + mcNotVisible);
00221         
00222        ::MCDoAction(mMovieController, mcActionSetLooping, (void *)1);
00223        ::MCMovieChanged(mMovieController, mMovie);
00224     }
00225     catch (...) {
00226         if (dataRef)
00227             DisposeHandle(dataRef);
00228         
00229         // Don't rethrow
00230     }
00231 }