Back to index

lightning-sunbird  0.9+nobinonly
LicenseWin.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  *   License Window
00045  *-----------------------------------------------------------*/
00046 
00047 void
00048 ShowLicenseWin(void)
00049 {
00050        Str255               accept;
00051        Str255               decline;
00052        Rect          sbRect;
00053        int           sbWidth;
00054        
00055        GrafPtr       oldPort;
00056        GetPort(&oldPort);
00057        
00058        SetPort(gWPtr);
00059 
00060        gCurrWin = kLicenseID; 
00061        /* gControls->lw = (LicWin *) NewPtrClear(sizeof(LicWin)); */
00062        
00063        GetResourcedString(accept, rInstList, sAcceptBtn);
00064        GetResourcedString(decline, rInstList, sDeclineBtn);
00065        
00066        gControls->lw->scrollBar = GetNewControl( rLicScrollBar, gWPtr);
00067        gControls->lw->licBox = GetNewControl( rLicBox, gWPtr);
00068 
00069        if(gControls->lw->scrollBar && gControls->lw->licBox)
00070        {
00071               HLock( (Handle) gControls->lw->scrollBar);
00072               sbRect = (*(gControls->lw->licBox))->contrlRect;
00073                             
00074               sbWidth = (*(gControls->lw->scrollBar))->contrlRect.right -
00075                               (*(gControls->lw->scrollBar))->contrlRect.left;
00076               
00077               (*(gControls->lw->scrollBar))->contrlRect.right = sbRect.right + kScrollBarPad;
00078               (*(gControls->lw->scrollBar))->contrlRect.left = sbRect.right + kScrollBarPad - 
00079                                                                                                    sbWidth;
00080               (*(gControls->lw->scrollBar))->contrlRect.top = sbRect.top - kScrollBarPad;
00081               (*(gControls->lw->scrollBar))->contrlRect.bottom = sbRect.bottom + kScrollBarPad;
00082               HUnlock( (Handle) gControls->lw->scrollBar);
00083        }
00084        else
00085        {
00086               ErrorHandler(eParam, nil);
00087               return;
00088        }
00089        InitLicTxt();
00090 
00091        ShowNavButtons( decline, accept);
00092        ShowControl( gControls->lw->scrollBar);
00093        ShowControl( gControls->lw->licBox);
00094        ShowTxt();
00095        InitScrollBar( gControls->lw->scrollBar);
00096        ShowLogo(false);
00097        
00098        SetPort(oldPort);
00099 }
00100 
00101 void
00102 InitLicTxt(void)
00103 {
00104        Rect   destRect, viewRect;
00105        FSSpec licFile;
00106        long   dirID, dataSize;
00107        short  vRefNum, dataRef, resRef;
00108        unsigned char*       cLicFName;
00109        Str255               pLicFName;
00110        OSErr  err;
00111        Handle        text, stylHdl;
00112        
00113        ERR_CHECK(GetCWD(&dirID, &vRefNum));
00114        
00115        /* open and read license file */
00116        HLock(gControls->cfg->licFileName);
00117        if(**gControls->cfg->licFileName != nil)
00118        {
00119               cLicFName = CToPascal(*gControls->cfg->licFileName);
00120               
00121               ERR_CHECK(FSMakeFSSpec(vRefNum, dirID, cLicFName, &licFile));
00122               if (cLicFName)
00123                      DisposePtr((char*)cLicFName);
00124        }
00125        else /* assume default license filename from str rsrc */
00126        {      
00127               GetResourcedString(pLicFName, rInstList, sLicenseFName);
00128               ERR_CHECK(FSMakeFSSpec(vRefNum, dirID, pLicFName, &licFile));
00129        }
00130        HUnlock(gControls->cfg->licFileName);
00131        
00132        /* read license text */
00133        ERR_CHECK(FSpOpenDF( &licFile, fsRdPerm, &dataRef));
00134        ERR_CHECK(GetEOF(dataRef, &dataSize));
00135 
00136        if (dataSize > 0)
00137        {
00138               if (!(text = NewHandle(dataSize)))
00139               {
00140                      ErrorHandler(eMem, nil);
00141                      return;
00142               }
00143               ERR_CHECK(FSRead(dataRef, &dataSize, *text));
00144        }
00145        else
00146               text = nil;
00147        ERR_CHECK(FSClose(dataRef));
00148 
00149        /* get 'styl' if license is multistyled */
00150        resRef = FSpOpenResFile( &licFile, fsRdPerm);
00151        ERR_CHECK(ResError());
00152 
00153        UseResFile(resRef);
00154        stylHdl = RGetResource('styl', 128);
00155        ERR_CHECK(ResError());
00156        
00157        if(stylHdl)
00158               DetachResource(stylHdl);
00159        else
00160               stylHdl = nil;
00161        CloseResFile(resRef);
00162        
00163        /* TE specific init */
00164        HLock( (Handle) gControls->lw->licBox);
00165        SetRect(&viewRect,   (*(gControls->lw->licBox))->contrlRect.left, 
00166                                           (*(gControls->lw->licBox))->contrlRect.top, 
00167                                           (*(gControls->lw->licBox))->contrlRect.right, 
00168                                           (*(gControls->lw->licBox))->contrlRect.bottom);
00169        HUnlock( (Handle) gControls->lw->licBox);
00170 
00171        destRect.left = viewRect.left;
00172               viewRect.right = (*(gControls->lw->scrollBar))->contrlRect.left; 
00173        destRect.right = viewRect.right;
00174        destRect.top = viewRect.top;
00175        destRect.bottom = viewRect.bottom * kNumLicScrns;
00176        
00177        // gControls->lw->licTxt = (TEHandle) NewPtrClear(sizeof(TEPtr));
00178        
00179        TextFont(applFont);
00180        TextFace(normal);
00181        TextSize(9);
00182        
00183        HLock(text);
00184        if (stylHdl)
00185        {
00186               gControls->lw->licTxt = TEStyleNew( &destRect, &viewRect );
00187               TEStyleInsert( *text, dataSize, (StScrpRec ** )stylHdl, 
00188                                           gControls->lw->licTxt);
00189        }
00190        else
00191        {
00192               gControls->lw->licTxt = TENew( &destRect, &viewRect);
00193               TEInsert( *text, dataSize, gControls->lw->licTxt);
00194        }
00195        HUnlock(text);
00196        
00197        TextFont(systemFont);
00198        TextSize(12);
00199        
00200        TESetAlignment(teFlushDefault, gControls->lw->licTxt);
00201 }
00202 
00203 void
00204 ShowTxt(void)
00205 {          
00206        switch (gCurrWin)
00207        {
00208               case kLicenseID:
00209                      if(gControls->lw->licTxt)
00210                      {
00211                          RGBColor backColorOld;
00212                          Rect     textRect;
00213                          
00214                          // get back color
00215                          GetBackColor(&backColorOld);
00216                          
00217                          // set to white
00218                          BackColor(whiteColor);
00219                          
00220                          // erase rect and update
00221                          textRect = (**(gControls->lw->licTxt)).viewRect;
00222                          EraseRect(&textRect);
00223                             TEUpdate(&textRect, gControls->lw->licTxt);
00224                             
00225                             // restore back color
00226                             RGBBackColor(&backColorOld);
00227                      }
00228                      break;
00229               default:
00230                      break;
00231        }             
00232 }
00233 
00234 void
00235 ShowLogo(Boolean bEraseRect)
00236 {
00237        short         reserr;
00238        Rect          derefd, logoRect;
00239        PicHandle     logoPicH;
00240        Handle        logoRectH; 
00241 
00242        /* draw the image well */
00243     ControlHandle imgWellH = GetNewControl(rLogoImgWell, gWPtr);
00244     if (!imgWellH)
00245     {
00246         ErrorHandler(eMem, nil);
00247         return;
00248        }
00249 
00250        /* initialize Netscape logo */
00251        logoPicH = GetPicture(rNSLogo);  
00252        reserr = ResError();
00253        
00254        if (reserr == noErr)
00255        {
00256               /* draw Netscape logo */
00257               if (logoPicH != nil)
00258               {             
00259                      logoRectH = GetResource('RECT', rNSLogoBox);
00260                      reserr = ResError();
00261                      if (reserr == noErr && logoRectH)
00262                      {
00263                             HLock(logoRectH);
00264                             derefd = (Rect) **((Rect**)logoRectH);
00265                             SetRect(&logoRect, derefd.left, derefd.top, derefd.right, derefd.bottom);
00266                             HUnlock(logoRectH);
00267                             reserr = ResError();
00268                             if (reserr == noErr)
00269                             {
00270                                    if (bEraseRect)
00271                                    {
00272                                           EraseRect(&logoRect);
00273                                           InvalRect(&logoRect);
00274                                    }
00275                                    DrawPicture(logoPicH, &logoRect);
00276                                    ReleaseResource((Handle)logoPicH);
00277                             }
00278                             
00279                             ReleaseResource((Handle)logoRectH);
00280                      }
00281               }
00282        }
00283        
00284        if (reserr != noErr)
00285               ErrorHandler(reserr, nil);
00286 }
00287 
00288 void
00289 InLicenseContent(EventRecord* evt, WindowPtr wCurrPtr)
00290 {
00291        Point                localPt;
00292        Rect                 r;
00293        ControlPartCode      part;
00294        short                code, value;
00295        ControlHandle scrollBar;
00296        ControlActionUPP     scrollActionFunctionUPP;
00297        GrafPtr                     oldPort;
00298        
00299        GetPort(&oldPort);
00300        SetPort(gWPtr);
00301        localPt = evt->where;
00302        GlobalToLocal( &localPt);
00303        
00304        code = FindControl(localPt, wCurrPtr, &scrollBar);
00305        switch (code)
00306        {
00307               case kControlUpButtonPart:
00308               case kControlDownButtonPart:
00309               case kControlPageUpPart:
00310               case kControlPageDownPart:
00311                      scrollActionFunctionUPP = NewControlActionUPP(DoScrollProc);
00312                      value = TrackControl(scrollBar, localPt, scrollActionFunctionUPP);
00313                      return;
00314                      
00315               case kControlIndicatorPart:
00316                      value = GetControlValue(scrollBar);
00317                      code = TrackControl(scrollBar, localPt, nil);
00318                      if (code) 
00319                      {
00320                             value -= GetControlValue(scrollBar);
00321                             if (value) 
00322                             {
00323                                    TEScroll(0, value * kScrollAmount, gControls->lw->licTxt);
00324                     ShowTxt();
00325                             }
00326                      }
00327                      return;
00328        }
00329        
00330        HLock((Handle)gControls->backB);
00331        r = (**(gControls->backB)).contrlRect;
00332        HUnlock((Handle)gControls->backB);
00333        if (PtInRect( localPt, &r))
00334        {
00335               part = TrackControl(gControls->backB, evt->where, NULL);
00336               if (part)
00337                      gDone = true;  /* Decline pressed */
00338        }
00339        
00340        HLock((Handle)gControls->nextB);                 
00341        r = (**(gControls->nextB)).contrlRect;
00342        HUnlock((Handle)gControls->nextB);
00343        if (PtInRect( localPt, &r))
00344        {
00345               part = TrackControl(gControls->nextB, evt->where, NULL);
00346               if (part)
00347               {
00348                      KillControls(gWPtr);
00349                      ShowSetupTypeWin();
00350                      return;
00351               }
00352        }
00353        
00354        ShowTxt();
00355        // TO DO
00356        SetPort(oldPort);
00357 }
00358 
00359 void
00360 EnableLicenseWin(void)
00361 {
00362        GrafPtr       oldPort;
00363        GetPort(&oldPort);
00364        
00365        SetPort(gWPtr);
00366        
00367        EnableNavButtons();
00368        
00369        if(gControls->lw->licBox)
00370               HiliteControl(gControls->lw->licBox, kEnableControl);   
00371        if(gControls->lw->scrollBar)
00372               HiliteControl(gControls->lw->scrollBar, kEnableControl);                     
00373        
00374        ShowTxt();
00375        SetPort(oldPort);
00376        
00377        // TO DO
00378 }
00379 
00380 void
00381 DisableLicenseWin(void)
00382 {
00383        DisableNavButtons();
00384        
00385        /*
00386        if(gControls->lw->licBox)          
00387               HiliteControl(gControls->lw->licBox, kDisableControl);
00388        */
00389        if(gControls->lw->scrollBar)
00390               HiliteControl(gControls->lw->scrollBar, kDisableControl);
00391        
00392 }
00393 
00394 void 
00395 InitScrollBar(ControlHandle sb)
00396 {
00397        short         lines;
00398        short         max;
00399        short         height;
00400        TEPtr         te;
00401        TEHandle      currTE;
00402        
00403        switch(gCurrWin)
00404        {
00405               case kLicenseID:
00406                      currTE = gControls->lw->licTxt;
00407                      break;
00408               default:
00409                      ErrorHandler(eUnknownDlgID, nil);
00410                      break;
00411        }
00412        
00413        lines = TEGetHeight((**currTE).nLines,0,currTE) / kScrollAmount;
00414        te = *currTE;                                           // point to TERec for convenience
00415 
00416        height = te->viewRect.bottom - te->viewRect.top;
00417        max = lines - (height / kScrollAmount);
00418        if (height % kScrollAmount) max++;
00419        if ( max < 0 ) max = 0;
00420 
00421        SetControlMaximum(sb, max);
00422 }
00423 
00424 pascal void 
00425 DoScrollProc(ControlHandle theControl, short part)
00426 {
00427        short         amount;
00428        TEPtr         te;
00429        
00430        if ( part != 0 ) {
00431               switch (gCurrWin)
00432               {
00433                      case kLicenseID:                          
00434                             te = *(gControls->lw->licTxt);
00435                             break;
00436                      default:
00437                             ErrorHandler(eUnknownDlgID, nil);
00438                             break;
00439               }
00440               
00441               switch ( part ) {
00442                      case kControlUpButtonPart:
00443                      case kControlDownButtonPart:              // one line
00444                             amount = 1;
00445                             break;
00446                      case kControlPageUpPart:                  // one page
00447                      case kControlPageDownPart:
00448                             amount = (te->viewRect.bottom - te->viewRect.top) / kScrollAmount;
00449                             break;
00450               }
00451               if ( (part == kControlDownButtonPart) || (part == kControlPageDownPart) )
00452                      amount = -amount;
00453               CalcChange(theControl, &amount);
00454               if (amount) {
00455                      TEScroll(0, amount * kScrollAmount, &te);
00456             ShowTxt();
00457               }
00458        }
00459 }
00460 
00461 void 
00462 CalcChange(ControlHandle theControl,      short *amount)
00463 {
00464        short         value, max;
00465        
00466        value = GetControlValue(theControl);      // get current value
00467        max = GetControlMaximum(theControl);             // and maximum value
00468        *amount = value - *amount;
00469        if (*amount < 0)
00470               *amount = 0;
00471        else if (*amount > max)
00472               *amount = max;
00473        SetControlValue(theControl, *amount);
00474        *amount = value - *amount;                // calculate the change
00475 }
00476 
00477 void
00478 ShowNavButtons(unsigned char* backTitle, unsigned char* nextTitle)
00479 {
00480     Boolean bDefault = true;
00481        
00482        gControls->backB = GetNewControl( rBackBtn, gWPtr);
00483        gControls->nextB = GetNewControl( rNextBtn, gWPtr);
00484 
00485        if( gControls->backB != NULL)
00486        {
00487               SetControlTitle( gControls->backB, backTitle); 
00488               ShowControl( gControls->backB);
00489 
00490               if (gCurrWin==kWelcomeID || gCurrWin==kSetupTypeID)
00491                      HiliteControl(gControls->backB, kDisableControl);
00492        }
00493        
00494        if ( gControls->nextB != NULL)
00495        {
00496               SetControlTitle( gControls->nextB, nextTitle);
00497               ShowControl( gControls->nextB);
00498 
00499         SetControlData(gControls->nextB, kControlNoPart, 
00500             kControlPushButtonDefaultTag, sizeof(bDefault),(Ptr) &bDefault);
00501        }
00502        
00503     ShowCancelButton();
00504 }
00505 
00506 void
00507 EnableNavButtons(void)
00508 {
00509        if (gControls->backB && gCurrWin!=kWelcomeID)
00510               HiliteControl(gControls->backB, kEnableControl);
00511        if (gControls->nextB)
00512               HiliteControl(gControls->nextB, kEnableControl);
00513 
00514     if (gControls->cancelB)
00515               HiliteControl(gControls->cancelB, kEnableControl);
00516 
00517 }
00518 
00519 void
00520 DisableNavButtons(void)
00521 {      
00522        if (gControls->backB)
00523               HiliteControl(gControls->backB, kDisableControl);
00524        if(gControls->nextB)
00525               HiliteControl(gControls->nextB, kDisableControl);
00526 
00527     if (gControls->cancelB)
00528               HiliteControl(gControls->cancelB, kDisableControl);
00529 }