Back to index

lightning-sunbird  0.9+nobinonly
EvtHandlers.c
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code, released
00016  * March 31, 1998.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1999
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Samir Gehani <sgehani@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or 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 "MacInstallWizard.h"
00041 
00042 
00043 /*--------------------------------------------------------------*
00044  *   Event Handlers
00045  *--------------------------------------------------------------*/
00046 void HandleNextEvent(EventRecord* nextEvt)
00047 {
00048        switch(nextEvt->what)
00049        {
00050               case mouseDown:
00051                      HandleMouseDown(nextEvt);
00052                      break;
00053                      
00054               case mouseUp:
00055                      if (gCurrWin == kComponentsID)
00056                             InComponentsContent(nextEvt, gWPtr);
00057                      else if (gCurrWin == kAdditionsID)
00058                             InAdditionsContent(nextEvt, gWPtr);
00059                      break;
00060                      
00061 
00062               case keyDown:
00063                      HandleKeyDown(nextEvt);
00064                      break;
00065                      
00066               case updateEvt:
00067                      HandleUpdateEvt(nextEvt);
00068                      break;
00069                      
00070               case activateEvt:
00071                      HandleActivateEvt(nextEvt);
00072                      break;
00073                      
00074               case osEvt:
00075                      HandleOSEvt(nextEvt);
00076                      break;
00077               
00078               case nullEvent:
00079                      TEIdle(gControls->lw->licTxt);
00080                      break;
00081        }
00082 }
00083 
00084 void HandleMouseDown(EventRecord* evt)
00085 {
00086        WindowPtr                   wCurrPtr;
00087        SInt16                      cntlPartCode;
00088        SInt32                      menuChoice;
00089        
00090        cntlPartCode = FindWindow(evt->where, &wCurrPtr);
00091        
00092        switch(cntlPartCode)
00093        {
00094               case inMenuBar:
00095                      menuChoice = MenuSelect(evt->where);
00096                      HandleMenuChoice(menuChoice);
00097                      InvalMenuBar();
00098                      break;
00099               
00100               case inContent:
00101                      if (wCurrPtr != FrontWindow())
00102                      {
00103                             /* InvalRect(&qd.screenBits.bounds); */
00104                             SelectWindow(wCurrPtr);
00105                      }
00106                      else
00107                             React2InContent(evt, wCurrPtr);
00108                      break;
00109               
00110               case inDrag:
00111                      DragWindow(wCurrPtr, evt->where, &qd.screenBits.bounds);
00112                      InvalRect(&qd.screenBits.bounds);
00113                      break;
00114                      
00115               case inGoAway:
00116                      // TO DO
00117                      break;
00118        }
00119 }
00120 
00121 void HandleKeyDown(EventRecord* evt)
00122 {
00123        char                 keyPressed;
00124        unsigned long        finalTicks;
00125               
00126        keyPressed = evt->message & charCodeMask;
00127 #ifdef MIW_DEBUG
00128        if ( (keyPressed == 'z') || (keyPressed == 'Z'))
00129               gDone = true; // backdoor exit
00130 #endif
00131        switch(keyPressed)                   //dougt: what about tab, esc, arrows, doublebyte?
00132        {             
00133               case '\r':
00134               case '\3':
00135                      if (gControls->nextB && !gInstallStarted)
00136                      {
00137                             HiliteControl(gControls->nextB, 1);
00138                             Delay(8, &finalTicks);
00139                             HiliteControl(gControls->nextB, 0);
00140                      }
00141 
00142                      switch(gCurrWin)
00143                      {
00144                 case kWelcomeID:                        
00145                                    KillControls(gWPtr);
00146                                    ShowLicenseWin();
00147                                    return;
00148                             case kLicenseID:
00149                                    KillControls(gWPtr);
00150                                    ShowSetupTypeWin();
00151                                    return;
00152                             case kSetupTypeID:
00153                                    ClearDiskSpaceMsgs();
00154                                    KillControls(gWPtr); 
00155                                    /* treat last setup type selection as custom */
00156                                    if (gControls->opt->instChoice == gControls->cfg->numSetupTypes)
00157                                           ShowComponentsWin();
00158                                    else
00159                                           ShowTerminalWin();
00160                                    return;                            
00161                             case kComponentsID:         
00162                     gControls->cw->compListBox.top = 0;
00163                     EraseRect(&gControls->cw->compListBox);                  
00164                                    ClearDiskSpaceMsgs();
00165                                    KillControls(gWPtr);
00166                                    if (gControls->cfg->bAdditionsExist)
00167                                           ShowAdditionsWin();
00168                                    else
00169                                           ShowTerminalWin();
00170                                    return;
00171                             case kAdditionsID:
00172                                    KillControls(gWPtr);                             
00173                     gControls->aw->compListBox.top = 0;
00174                     EraseRect(&gControls->aw->compListBox);                                
00175                                    ClearDiskSpaceMsgs();
00176                                    ShowTerminalWin();
00177                                    return;
00178                             case kTerminalID:
00179                                    if (!gInstallStarted)
00180                                    {      
00181                         BeginInstall();
00182                                    }
00183                                    return;
00184                             default:
00185                                    break; // never reached
00186                      }
00187               break;
00188               
00189               default:
00190                      break; 
00191        }
00192        
00193        if ( (evt->modifiers & cmdKey) != 0 )
00194        {
00195               switch(keyPressed)
00196               {
00197                      case 'Q':
00198                      case 'q':
00199                      case '.':
00200                             gDone = true;
00201                             break;
00202                             
00203                      default:
00204                             break;
00205               }
00206        }
00207 }
00208 
00209 void HandleMenuChoice(SInt32 aChoice)
00210 {
00211        long menuID = HiWord(aChoice);
00212        long menuItem = LoWord(aChoice);
00213        
00214        switch(menuID)
00215        {
00216               case mApple:
00217                      if (menuItem == iAbout)
00218                      {
00219                             Alert(rAboutBox, nil);
00220                      }
00221                      break;
00222               
00223               case mFile:
00224                      if (menuItem == iQuit)
00225                             gDone = true;        
00226                      break;
00227                             
00228               default:
00229                      break;
00230        }
00231 }
00232 
00233 void HandleUpdateEvt(EventRecord* evt)
00234 {
00235     Boolean bDefault = true;
00236        
00237        GrafPtr       oldPort;
00238        GetPort(&oldPort);
00239        
00240        SetPort( gWPtr );
00241 
00242        if (gWPtr != NULL)
00243        {
00244               BeginUpdate( gWPtr );
00245               DrawControls( gWPtr );
00246               ShowLogo(false);
00247        
00248               switch(gCurrWin)
00249               {
00250                      case kWelcomeID:
00251                          break;
00252             case kLicenseID:
00253                             ShowTxt();
00254                             break;
00255                      case kSetupTypeID:
00256                             ShowSetupDescTxt();
00257                             break;
00258                      case kComponentsID:
00259                             UpdateCompWin();
00260                             break;
00261                      case kAdditionsID:
00262                             UpdateAdditionsWin();
00263                             break;
00264                      case kTerminalID:
00265                             UpdateTerminalWin();
00266                             break;
00267                      default:
00268                             break;
00269               }
00270               
00271               if (gControls->nextB)
00272               {
00273             SetControlData(gControls->nextB, kControlNoPart, 
00274                 kControlPushButtonDefaultTag, sizeof(bDefault),(Ptr) &bDefault);
00275               }
00276        
00277               EndUpdate( gWPtr );
00278        }
00279        
00280        SetPort(oldPort);
00281 }
00282 
00283 void HandleActivateEvt(EventRecord* evt)
00284 {
00285        // TO DO
00286 }
00287 
00288 void HandleOSEvt(EventRecord* evt)
00289 {
00290        HiliteMenu(0);
00291        
00292        switch ( (evt->message >> 24) & 0x000000FF)
00293        {
00294               case suspendResumeMessage:
00295                      if ((evt->message & resumeFlag) == 1)
00296                      {
00297                             switch(gCurrWin)
00298                             {
00299                                    case kLicenseID:
00300                                           EnableLicenseWin();
00301                                           break;
00302                                    case kWelcomeID:
00303                                           EnableWelcomeWin();
00304                                           break;
00305                                    case kSetupTypeID:
00306                                           EnableSetupTypeWin();
00307                                           break;
00308                                    case kComponentsID:
00309                                           EnableComponentsWin();
00310                                           break;
00311                                    case kAdditionsID:
00312                                           EnableAdditionsWin();
00313                                           break;
00314                                    case kTerminalID:
00315                                           EnableTerminalWin();
00316                                           break;
00317                             }
00318                             
00319                             InvalRect(&gWPtr->portRect);
00320                      }
00321                      else
00322                      {
00323                             switch(gCurrWin)
00324                             {
00325                                    case kLicenseID:
00326                                           DisableLicenseWin();
00327                                           break;
00328                                    case kWelcomeID:
00329                                           DisableWelcomeWin();
00330                                           break;
00331                                    case kSetupTypeID:
00332                                           DisableSetupTypeWin();
00333                                           break;
00334                                    case kComponentsID:
00335                                           DisableComponentsWin();
00336                                           break;
00337                                    case kAdditionsID:
00338                                           DisableAdditionsWin();
00339                                           break;
00340                                    case kTerminalID:
00341                                           DisableTerminalWin();
00342                                           break;
00343                             }
00344                             
00345                             InvalRect(&gWPtr->portRect);
00346                      }      
00347        
00348               default:
00349                      break;                             
00350        }
00351 }
00352 
00353 void React2InContent(EventRecord* evt, WindowPtr wCurrPtr)
00354 {      
00355     if (DidUserCancel(evt))
00356         return;
00357         
00358        switch (gCurrWin)
00359        {
00360               case kLicenseID:
00361                      InLicenseContent(evt, gWPtr);
00362                      break;
00363                      
00364               case kWelcomeID:
00365                      InWelcomeContent(evt, gWPtr);
00366                      break;
00367                      
00368               case kSetupTypeID:
00369                      InSetupTypeContent(evt, gWPtr);
00370                      break;
00371                      
00372               case kComponentsID:
00373                      InComponentsContent(evt, gWPtr);
00374                      break;
00375               
00376               case kAdditionsID:
00377                      InAdditionsContent(evt, gWPtr);
00378                      break;
00379                      
00380               case kTerminalID:
00381                      InTerminalContent(evt, gWPtr);
00382                      break;
00383                      
00384               default:
00385                      gDone = true;
00386                      break;
00387        }
00388 }
00389 
00390 Boolean
00391 DidUserCancel(EventRecord *evt)
00392 {
00393     GrafPtr oldPort;
00394     Boolean bUserCancelled = false;
00395     Point localPt;
00396     Rect r;
00397     ControlPartCode  part;
00398 
00399     GetPort(&oldPort);
00400        SetPort(gWPtr);
00401        localPt = evt->where;
00402        GlobalToLocal(&localPt);
00403        
00404     HLock((Handle)gControls->cancelB);
00405        r = (**(gControls->cancelB)).contrlRect;
00406        HUnlock((Handle)gControls->cancelB);
00407        if (PtInRect(localPt, &r))
00408        {
00409            if (gControls->state == eInstallNotStarted)
00410            {
00411               part = TrackControl(gControls->cancelB, evt->where, NULL);
00412               if (part)
00413               {
00414                   gDone = true;  
00415                 bUserCancelled = true;
00416            }
00417        }
00418        }
00419        
00420     SetPort(oldPort);
00421     return bUserCancelled;
00422 }