Back to index

lightning-sunbird  0.9+nobinonly
AdditionsWin.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  *   Additions Window
00045  *-----------------------------------------------------------*/
00046 
00047 static int rowToComp[kMaxComponents];
00048 static int numRows = 0;                   
00049 static Boolean bFirstDraw = true;
00050 
00051 void
00052 ShowAdditionsWin(void)
00053 {
00054        Str255        next, back;
00055        Str255        compDescTitle;
00056        StringPtr     selCompMsg;
00057        Handle        listBoxRect;
00058        Rect          dataBounds, listBoxFrame, viewRect;
00059        short         reserr;
00060        int                  totalRows = 0, i, instChoice;
00061        Point         cSize;
00062        Boolean              bCellSelected;
00063        GrafPtr              oldPort;
00064        GetPort(&oldPort);
00065               
00066        SetPort(gWPtr);
00067        
00068        gCurrWin = kAdditionsID; 
00069        /* gControls->aw = (CompWin *) NewPtrClear(sizeof(CompWin)); */
00070        
00071        GetResourcedString(next, rInstList, sNextBtn);
00072        GetResourcedString(back, rInstList, sBackBtn);
00073 
00074        // get controls
00075        listBoxRect = Get1Resource('RECT', rCompListBox);
00076        reserr = ResError(); 
00077        if (reserr == noErr && listBoxRect != NULL)
00078        {
00079               HLock((Handle)listBoxRect);
00080               SetRect(&gControls->aw->compListBox,      ((Rect*)*listBoxRect)->left,
00081                                                                                     ((Rect*)*listBoxRect)->top,
00082                                                                                     ((Rect*)*listBoxRect)->right,
00083                                                                                     ((Rect*)*listBoxRect)->bottom);
00084               HUnlock((Handle)listBoxRect);
00085        }
00086        else
00087        {
00088               ErrorHandler(reserr, nil);
00089               return;
00090        }
00091        gControls->aw->compDescBox = NULL;
00092        gControls->aw->compDescBox = GetNewControl(rCompDescBox, gWPtr);
00093        if (!gControls->aw->compDescBox)
00094        {
00095               ErrorHandler(eMem, nil);
00096               return;
00097        }
00098 
00099        gControls->aw->compListBox.right -= kScrollBarWidth;
00100        instChoice = gControls->opt->instChoice-1;
00101        for (i=0; i<kMaxComponents; i++)
00102        {
00103               if (totalRows >= gControls->cfg->numComps)
00104                      break;
00105               if (!gControls->cfg->comp[i].invisible && gControls->cfg->comp[i].additional &&
00106                      (gControls->cfg->st[instChoice].comp[i] == kInSetupType))
00107                      totalRows++;
00108        }
00109               
00110        SetRect(&dataBounds, 0, 0, 1, totalRows);
00111        SetPt( &cSize, 0, 0);
00112        gControls->aw->compList = LNew((const Rect*)&gControls->aw->compListBox, (const Rect*)&dataBounds,
00113                                                                cSize, rCheckboxLDEF, gWPtr, true, false, false, true);
00114        (*gControls->aw->compList)->selFlags = lExtendDrag + lUseSense + lDoVAutoscroll;
00115        
00116        HLock((Handle)gControls->aw->compDescBox);
00117        SetRect(&viewRect, (*gControls->aw->compDescBox)->contrlRect.left,
00118                                       (*gControls->aw->compDescBox)->contrlRect.top,
00119                                       (*gControls->aw->compDescBox)->contrlRect.right,
00120                                       (*gControls->aw->compDescBox)->contrlRect.bottom);
00121        HUnlock((Handle)gControls->aw->compDescBox);
00122        viewRect.top += kInterWidgetPad;
00123        SetRect(&viewRect, viewRect.left + kTxtRectPad,
00124                                           viewRect.top + kTxtRectPad,
00125                                           viewRect.right - kTxtRectPad,
00126                                           viewRect.bottom - kTxtRectPad);
00127        TextFont(applFont);
00128        TextSize(9);
00129        gControls->aw->compDescTxt = TENew(&viewRect, &viewRect);
00130        TextFont(systemFont);
00131        TextSize(12);
00132        
00133        // populate controls
00134        bCellSelected = AddPopulateCompInfo();
00135        
00136        // show controls
00137        GetResourcedString(compDescTitle, rInstList, sCompDescTitle);
00138        SetControlTitle(gControls->aw->compDescBox, compDescTitle);
00139        
00140        MoveTo( gControls->aw->compListBox.left, gControls->aw->compListBox.top - kInterWidgetPad);
00141        HLock(gControls->cfg->selCompMsg);
00142        selCompMsg = CToPascal(*gControls->cfg->selAddMsg);
00143        if (selCompMsg)
00144               DrawString( selCompMsg );
00145        HUnlock(gControls->cfg->selCompMsg);
00146        SetRect(&listBoxFrame, gControls->aw->compListBox.left, 
00147                                            --gControls->aw->compListBox.top,
00148                                              gControls->aw->compListBox.right + kScrollBarWidth,
00149                                            ++gControls->aw->compListBox.bottom);
00150        FrameRect(&listBoxFrame);
00151        ShowNavButtons( back, next );
00152        if (bCellSelected)
00153               AddSetOptInfo(true);
00154        else
00155               DrawDiskSpaceMsgs( gControls->opt->vRefNum );
00156 
00157        // default highlight first row
00158        AddInitRowHighlight(0);
00159 
00160 #if 0      
00161        RGBColor backColorOld;
00162     Rect adjustedRect, *clRect = &gControls->aw->compListBox;
00163     SetRect(&adjustedRect, clRect->left, clRect->top+1, clRect->right, clRect->bottom-1);
00164     GetBackColor(&backColorOld);
00165     BackColor(whiteColor);
00166     EraseRect(&adjustedRect);
00167     RGBBackColor(&backColorOld);
00168 #endif
00169     
00170        SetPort(oldPort);
00171 }
00172 
00173 Boolean
00174 AddPopulateCompInfo()
00175 {
00176        int    i;
00177        char   *currDesc;
00178        Point  currCell;
00179        Boolean bCellSelected = false;
00180        int           nextRow = 0;
00181        
00182        for (i=0; i<gControls->cfg->numComps; i++)
00183        {
00184               if (!gControls->cfg->comp[i].invisible && gControls->cfg->comp[i].additional)
00185               {
00186                      HLock(gControls->cfg->comp[i].shortDesc);
00187                      currDesc = *gControls->cfg->comp[i].shortDesc;
00188                      SetPt(&currCell, 0, nextRow);
00189                      rowToComp[nextRow++] = i;
00190                      LSetCell( currDesc, strlen(currDesc), currCell, gControls->aw->compList);
00191                      HUnlock(gControls->cfg->comp[i].shortDesc);
00192                      if (gControls->cfg->comp[i].selected == true)
00193                      {
00194                             LSetSelect(true, currCell, gControls->aw->compList);
00195                             bCellSelected = true;
00196                      }
00197               }
00198        }
00199 
00200        numRows = nextRow;   
00201        return bCellSelected;
00202 }
00203 
00204 void 
00205 InAdditionsContent(EventRecord* evt, WindowPtr wCurrPtr)
00206 {
00207        Point                localPt;
00208        Rect                 r, currCellRect, checkbox;
00209        ControlPartCode      part;
00210        int                         i;
00211        Cell                 currCell;
00212        UInt8                hiliteVal;
00213        PixPatHandle  ppH;
00214        GrafPtr                     oldPort;
00215        GetPort(&oldPort);
00216        
00217        SetPort(wCurrPtr);
00218        localPt = evt->where;
00219        GlobalToLocal( &localPt);
00220        
00221        /* Mouse Up */
00222        
00223        /* scroll */
00224        SetRect(&r, gControls->aw->compListBox.right, gControls->aw->compListBox.top, 
00225                    gControls->aw->compListBox.right + kScrollBarWidth, gControls->aw->compListBox.bottom);
00226        if ((evt->what == mouseUp) && (PtInRect( localPt, &r)))
00227        {          
00228            LClick(localPt, evt->modifiers, gControls->aw->compList);
00229            
00230            SetRect(&r, gControls->aw->compListBox.left, gControls->aw->compListBox.top,
00231                        gControls->aw->compListBox.right + 1, gControls->aw->compListBox.bottom);
00232            FrameRect(&r);
00233        }
00234        
00235        /* or un/check components */
00236        if ((evt->what == mouseUp) && (PtInRect( localPt, &gControls->aw->compListBox)))
00237        {
00238               LClick(localPt, evt->modifiers, gControls->aw->compList);
00239               AddUpdateRowHighlight(localPt);
00240               
00241               /* invert the checkbox rect */
00242               for (i=0; i<numRows; i++)
00243               {
00244                      SetPt(&currCell, 0, i);
00245                      LRect(&currCellRect, currCell, gControls->aw->compList);
00246                      if (PtInRect(localPt, &currCellRect))
00247                      {
00248                             SetRect(&checkbox, currCellRect.left+4, currCellRect.top+2, 
00249                                                  currCellRect.left+16, currCellRect.top+14);             
00250                             INVERT_HIGHLIGHT(&checkbox);
00251                             break;
00252                      }
00253               }
00254               
00255               AddSetOptInfo(false);
00256        }
00257        
00258        /* Mouse Down */
00259        if ((evt->what == mouseDown) && (PtInRect( localPt, &gControls->aw->compListBox)))
00260        {
00261               /* show depressed button state */
00262            for (i=0; i<numRows; i++)
00263               {
00264                      SetPt(&currCell, 0, i);
00265                      LRect(&currCellRect, currCell, gControls->aw->compList);
00266                      if (PtInRect(localPt, &currCellRect))
00267                      {
00268                             SetRect(&checkbox, currCellRect.left+4, currCellRect.top+2, 
00269                                                  currCellRect.left+16, currCellRect.top+14);      
00270                             ppH = GetPixPat(rGrayPixPattern);
00271                             FillCRect(&checkbox, ppH);  
00272                             FrameRect(&checkbox);       
00273                             if (gControls->cfg->comp[rowToComp[i]].selected)
00274                             {
00275                                    /* draw check mark */
00276                                    MoveTo(checkbox.left+1, checkbox.top+1);
00277                                    LineTo(checkbox.right-2, checkbox.bottom-2);
00278                                    MoveTo(checkbox.right-2, checkbox.top+1);
00279                                    LineTo(checkbox.left+1, checkbox.bottom-2); 
00280                             }
00281                             /* create 3D depression */
00282                             
00283                             MoveTo(checkbox.left+1, checkbox.top+1);
00284                             LineTo(checkbox.left+1, checkbox.bottom-1);
00285                             MoveTo(checkbox.left+1, checkbox.top+1);
00286                             LineTo(checkbox.right-1, checkbox.top+1);
00287                             
00288                             ForeColor(whiteColor);
00289                             
00290                             MoveTo(checkbox.right-1, checkbox.top+1);
00291                             LineTo(checkbox.right-1, checkbox.bottom-1);
00292                             MoveTo(checkbox.left+1, checkbox.bottom-1);
00293                             LineTo(checkbox.right-1, checkbox.bottom-1);
00294                             
00295                             ForeColor(blackColor);
00296                      
00297                             if (ppH)
00298                                    DisposePixPat(ppH);
00299                             break;
00300                      }
00301               }
00302        }
00303                      
00304        HLock((Handle)gControls->backB);
00305        r = (**(gControls->backB)).contrlRect;
00306        HUnlock((Handle)gControls->backB);
00307        if (PtInRect( localPt, &r))
00308        {
00309               /* reset all rows to be not highlighted */
00310               for (i=1; i<numRows; i++)
00311                      gControls->cfg->comp[rowToComp[i]].highlighted = false;
00312               
00313               part = TrackControl(gControls->backB, evt->where, NULL);
00314               if (part)
00315               { 
00316                      /* extra handling since we used DrawString for static text msg 
00317                       * and framed our own listbox etc. 
00318                       */
00319                      gControls->aw->compListBox.top = 0;
00320                      EraseRect(&gControls->aw->compListBox);
00321                      ClearDiskSpaceMsgs();
00322                      
00323                      KillControls(gWPtr);
00324                      ShowComponentsWin();
00325                      return;
00326               }
00327        }
00328                      
00329        HLock((Handle)gControls->nextB);                 
00330        r = (**(gControls->nextB)).contrlRect;
00331        HUnlock((Handle)gControls->nextB);
00332        if (PtInRect( localPt, &r))
00333        {
00334               /* reset all rows to be not highlighted */
00335               for (i=0; i<numRows; i++)
00336                      gControls->cfg->comp[rowToComp[i]].highlighted = false;
00337                      
00338               part = TrackControl(gControls->nextB, evt->where, NULL);
00339               if (part)
00340               {      
00341                      if (!VerifyDiskSpace())
00342                          return;
00343                                    
00344                      gControls->aw->compListBox.top = 0;
00345                      EraseRect(&gControls->aw->compListBox);
00346                      ClearDiskSpaceMsgs();
00347                                           
00348                      KillControls(gWPtr);
00349                      ShowTerminalWin();
00350                      return;
00351               }
00352        }
00353        SetPort(oldPort);
00354 }
00355 
00356 void
00357 UpdateAdditionsWin(void)
00358 {
00359        Rect          r;
00360        Cell          c;
00361        int                  i;
00362        GrafPtr              oldPort;
00363        GetPort(&oldPort);
00364        
00365        SetPort(gWPtr);
00366        
00367        MoveTo( gControls->aw->compListBox.left, gControls->aw->compListBox.top - kInterWidgetPad + 1);
00368        HLock(gControls->cfg->selAddMsg);
00369        DrawString( CToPascal(*gControls->cfg->selAddMsg));
00370        HUnlock(gControls->cfg->selAddMsg);
00371        
00372 #if 0
00373        RGBColor backColorOld;
00374     Rect adjustedRect, *clRect = &gControls->aw->compListBox;
00375     SetRect(&adjustedRect, clRect->left, clRect->top+1, clRect->right, clRect->bottom-1);
00376     GetBackColor(&backColorOld);
00377     BackColor(whiteColor);
00378     EraseRect(&adjustedRect);
00379     RGBBackColor(&backColorOld);
00380 #endif
00381    
00382        LUpdate( (*gControls->aw->compList)->port->visRgn, gControls->aw->compList);
00383        SetRect(&r, gControls->aw->compListBox.left, gControls->aw->compListBox.top,
00384                    gControls->aw->compListBox.right + 1, gControls->aw->compListBox.bottom);
00385        FrameRect(&r);       
00386        
00387        SetPt(&c, 0, 0);
00388        if (LGetSelect(true, &c, gControls->aw->compList))
00389        {
00390               HLock((Handle)gControls->aw->compDescTxt);
00391               SetRect(&r, (*gControls->aw->compDescTxt)->viewRect.left,
00392                                    (*gControls->aw->compDescTxt)->viewRect.top,
00393                                    (*gControls->aw->compDescTxt)->viewRect.right,
00394                                    (*gControls->aw->compDescTxt)->viewRect.bottom);
00395               HUnlock((Handle)gControls->aw->compDescTxt);
00396               TEUpdate(&r, gControls->aw->compDescTxt); 
00397        }
00398        
00399        DrawDiskSpaceMsgs( gControls->opt->vRefNum );
00400        
00401        for (i = 0; i < numRows; i++)
00402        {
00403               if (gControls->cfg->comp[rowToComp[i]].highlighted)
00404               {
00405                      AddInitRowHighlight(i);
00406                      break;
00407               }
00408        }
00409        
00410        SetPort(oldPort);
00411 }
00412 
00413 short         
00414 AddGetCompRow(int compIdx)
00415 {
00416        short i = kInvalidCompIdx;
00417        
00418        for (i=0; i<numRows; i++)
00419        {
00420               if (rowToComp[i] == compIdx)
00421                      break;
00422        }
00423        
00424        return i;
00425 }
00426 
00427 void          
00428 AddSetOptInfo(Boolean bDrawingWindow)
00429 {
00430        Cell          currCell;
00431        int                  row, beingSelected;
00432        Boolean       setSelected;
00433        
00434        // so we must determine the row clicked and resolve its dependees
00435        // bumping up their ref counts if this row is selected
00436        // and down if this row is unselected
00437        if (!bDrawingWindow)
00438        {
00439               currCell = LLastClick(gControls->aw->compList);
00440               row = currCell.v;
00441               
00442               // toggle from on to off or vice versa
00443               if (gControls->cfg->comp[rowToComp[row]].selected)
00444                      beingSelected = kNotSelected;
00445               else
00446                      beingSelected = kSelected;
00447               ResolveDependees(rowToComp[row], beingSelected); 
00448        }
00449        
00450        // then update the UI
00451        for (row = 0; row < numRows; row++)
00452        {
00453               SetPt(&currCell, 0, row);
00454               if (gControls->cfg->comp[rowToComp[row]].selected == kSelected)
00455                      setSelected = true;
00456               else
00457                      setSelected = false;
00458               LSetSelect(setSelected, currCell, gControls->aw->compList);
00459        }
00460        
00461        ClearDiskSpaceMsgs();
00462        DrawDiskSpaceMsgs( gControls->opt->vRefNum );
00463 }
00464 
00465 void          
00466 AddInitRowHighlight(int row)
00467 {
00468        Cell hlCell;
00469        Rect hlCellRect;
00470        UInt8 hiliteVal;
00471        int i = 0;
00472        
00473        /* reset all highlighted markers */
00474        for (i=0; i<numRows; i++)
00475        {
00476               gControls->cfg->comp[rowToComp[i]].highlighted = false;
00477        }
00478        
00479        /* highlight and set marker for row to init */
00480        SetPt(&hlCell, 0, row);
00481        LRect(&hlCellRect, hlCell, gControls->aw->compList);
00482        INVERT_HIGHLIGHT(&hlCellRect);     
00483        AddUpdateLongDesc(row);
00484        gControls->cfg->comp[rowToComp[row]].highlighted = true; 
00485 }
00486 
00487 void          
00488 AddUpdateRowHighlight(Point localPt)
00489 {
00490        int i, j;
00491        Rect currCellRect, oldCellRect;
00492        Cell currCell, oldCell;
00493        UInt8                hiliteVal;
00494        
00495        for (i=0; i<numRows; i++) 
00496        {
00497               /* note: numComps above includes invisible components */
00498               SetPt(&currCell, 0, i);
00499               LRect(&currCellRect, currCell, gControls->aw->compList);
00500                      
00501               /* mouse move landed over this cell */
00502               if (PtInRect( localPt, &currCellRect ))
00503               {
00504                      if (!gControls->cfg->comp[rowToComp[i]].highlighted)
00505                      {      
00506                             /* highlight this cell */
00507                             INVERT_HIGHLIGHT(&currCellRect);   
00508                             AddUpdateLongDesc(i);
00509                                    
00510                             /* unhighlight old one */
00511                             for (j=0; j<numRows; j++)
00512                             {
00513                                    if (gControls->cfg->comp[rowToComp[j]].highlighted)
00514                                    {
00515                                           SetPt(&oldCell, 0, j);
00516                                           LRect(&oldCellRect, oldCell, gControls->aw->compList);
00517                                                  
00518                                           INVERT_HIGHLIGHT(&oldCellRect);
00519                                           gControls->cfg->comp[rowToComp[j]].highlighted = false;
00520                                    }
00521                             }
00522                                    
00523                             /* mark this row highlighted to prevent incorrect inversion */
00524                             gControls->cfg->comp[rowToComp[i]].highlighted = true; 
00525                      }
00526               }
00527        }
00528 }
00529 
00530 void          
00531 AddUpdateLongDesc(int row)
00532 {
00533        Rect          viewRect;
00534        
00535        HLock((Handle)gControls->aw->compDescBox);
00536        SetRect(&viewRect, (*gControls->aw->compDescBox)->contrlRect.left,
00537                                       (*gControls->aw->compDescBox)->contrlRect.top,
00538                                       (*gControls->aw->compDescBox)->contrlRect.right,
00539                                       (*gControls->aw->compDescBox)->contrlRect.bottom);
00540        HUnlock((Handle)gControls->aw->compDescBox);
00541        viewRect.top += kInterWidgetPad;
00542        SetRect(&viewRect, viewRect.left + kTxtRectPad,
00543                                           viewRect.top + kTxtRectPad,
00544                                           viewRect.right - kTxtRectPad,
00545                                           viewRect.bottom - kTxtRectPad);
00546        EraseRect(&viewRect);
00547        
00548        HLock(gControls->cfg->comp[rowToComp[row]].longDesc);
00549        TESetText( *gControls->cfg->comp[rowToComp[row]].longDesc, 
00550                             strlen(*gControls->cfg->comp[rowToComp[row]].longDesc), gControls->aw->compDescTxt );
00551        TEUpdate( &viewRect, gControls->aw->compDescTxt );
00552        HUnlock(gControls->cfg->comp[rowToComp[row]].longDesc);
00553 }
00554 
00555 void
00556 EnableAdditionsWin(void)
00557 {      
00558        EnableNavButtons();
00559        
00560        // TO DO
00561 }
00562 
00563 void
00564 DisableAdditionsWin(void)
00565 {
00566        DisableNavButtons();
00567        
00568        // TO DO
00569 }