Back to index

lightning-sunbird  0.9+nobinonly
WelcomeWin.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  *   Welcome Window
00045  *-----------------------------------------------------------*/
00046 
00047 void 
00048 ShowWelcomeWin(void)
00049 {
00050        Str255 next;
00051        Str255 back;
00052        
00053        GrafPtr       oldPort;
00054        GetPort(&oldPort);
00055        
00056        if (gWPtr != NULL)
00057        {
00058               SetPort(gWPtr);
00059 
00060               gCurrWin = kWelcomeID; 
00061        
00062               GetResourcedString(next, rInstList, sNextBtn);
00063               GetResourcedString(back, rInstList, sBackBtn);
00064 
00065         ShowWelcomeMsg();
00066               ShowNavButtons(back, next);
00067               if (gControls->cfg->bReadme)
00068                      ShowReadmeButton();
00069        }
00070        
00071        SetPort(oldPort);
00072 }
00073 
00074 void
00075 ShowWelcomeMsg(void)
00076 {    
00077     int welcStrLen, i;
00078     
00079     for (i = 0; i < kNumWelcMsgs; i++)
00080     {
00081         gControls->ww->welcMsgCntl[i] = GetNewControl(rWelcMsgTextbox+i, gWPtr);
00082        if (!gControls->ww->welcMsgCntl)
00083        {
00084               ErrorHandler(eMem, nil);
00085               return;
00086        }
00087        }
00088     
00089     ControlFontStyleRec fontStyle;
00090 
00091     fontStyle.flags =  kControlUseSizeMask | kControlUseFaceMask;
00092     fontStyle.size = 18;
00093     fontStyle.style = normal;
00094     SetControlFontStyle(gControls->ww->welcMsgCntl[0], &fontStyle);
00095 
00096     HLock(gControls->cfg->welcMsg[0]);
00097     welcStrLen = strlen(*gControls->cfg->welcMsg[0]);
00098     HUnlock(gControls->cfg->welcMsg[0]);
00099     SetControlData(gControls->ww->welcMsgCntl[0], kControlNoPart, 
00100         kControlStaticTextTextTag, welcStrLen, (Ptr)*gControls->cfg->welcMsg[0]); 
00101     
00102     fontStyle.flags =  kControlUseSizeMask;
00103     fontStyle.size = 12;
00104 
00105     for (i = 1; i < kNumWelcMsgs; i++)
00106     {
00107         SetControlFontStyle(gControls->ww->welcMsgCntl[i], &fontStyle);
00108 
00109         HLock(gControls->cfg->welcMsg[i]);
00110         welcStrLen = strlen(*gControls->cfg->welcMsg[i]);
00111         HUnlock(gControls->cfg->welcMsg[i]);
00112         SetControlData(gControls->ww->welcMsgCntl[i], kControlNoPart, 
00113             kControlStaticTextTextTag, welcStrLen, (Ptr)*gControls->cfg->welcMsg[i]); 
00114     }  
00115 
00116     for (i = 0; i < kNumWelcMsgs; i++)
00117     {
00118            ShowControl(gControls->ww->welcMsgCntl[i]);
00119        }
00120 }
00121 
00122 void 
00123 InWelcomeContent(EventRecord* evt, WindowPtr wCurrPtr)
00124 {      
00125        Point                localPt;
00126        Rect                 r;
00127        ControlPartCode      part;
00128        GrafPtr                     oldPort;
00129        
00130        GetPort(&oldPort);
00131        SetPort(wCurrPtr);
00132        localPt = evt->where;
00133        GlobalToLocal( &localPt);
00134                      
00135        HLock((Handle)gControls->nextB);                 
00136        r = (**(gControls->nextB)).contrlRect;
00137        HUnlock((Handle)gControls->nextB);
00138        if (PtInRect( localPt, &r))
00139        {
00140               part = TrackControl(gControls->nextB, evt->where, NULL);
00141               if (part)
00142               {
00143                      KillControls(gWPtr);
00144                      ShowLicenseWin();
00145                      return;
00146               }
00147        }
00148        
00149        HLock((Handle)gControls->ww->readmeButton);
00150        r = (**(gControls->ww->readmeButton)).contrlRect;
00151        HUnlock((Handle)gControls->ww->readmeButton);
00152        if (PtInRect(localPt, &r))
00153        {
00154               part = TrackControl(gControls->ww->readmeButton, evt->where, NULL);
00155               if (part)
00156               {
00157                      ShowReadme();
00158                      return;
00159               }
00160        }
00161        
00162        SetPort(oldPort);
00163 }
00164 
00165 void
00166 ShowCancelButton(void)
00167 {
00168        Str255 cancelStr;
00169        
00170        GetResourcedString(cancelStr, rInstList, sCancel);
00171        gControls->cancelB = GetNewControl(rCancelBtn, gWPtr);
00172        if (gControls->cancelB != NULL)
00173        {
00174               SetControlTitle(gControls->cancelB, cancelStr);
00175               ShowControl(gControls->cancelB);
00176        }
00177 }
00178 
00179 void 
00180 ShowReadmeButton(void)
00181 {
00182        Str255 readme;
00183        
00184        GetResourcedString(readme, rInstList, sReadme);
00185        gControls->ww->readmeButton = GetNewControl(rReadmeBtn, gWPtr);
00186        if (gControls->ww->readmeButton != NULL)
00187        {
00188               SetControlTitle(gControls->ww->readmeButton, readme);
00189               ShowControl(gControls->ww->readmeButton);
00190        }
00191 }
00192        
00193 void
00194 ShowReadme(void)
00195 {
00196        Ptr appSig;
00197        StringPtr file;
00198        OSErr err = noErr;
00199        FSSpec appSpec, docSpec;
00200        Boolean running = nil;
00201        ProcessSerialNumber psn;
00202        unsigned short launchFileFlags, launchControlFlags;
00203        unsigned long appSigULong;
00204        long currDirID;
00205        short currVRefNum;
00206        
00207        appSig = *gControls->cfg->readmeApp;
00208        appSigULong = 0x00000000;
00209        UNIFY_CHAR_CODE(appSigULong, *(appSig), *(appSig+1), *(appSig+2), *(appSig+3));
00210        err = FindAppUsingSig(appSigULong, &appSpec, &running, &psn);
00211        if (err != noErr)
00212        {
00213               SysBeep(10); // XXX  show error dialog
00214               goto au_revoir;
00215        }
00216        
00217        file = CToPascal(*gControls->cfg->readmeFile); 
00218        GetCWD(&currDirID, &currVRefNum);
00219        err = FSMakeFSSpec(currVRefNum, currDirID, file, &docSpec);
00220        if (err != noErr)
00221        {
00222               SysBeep(10); // XXX  show error dialog
00223               goto au_revoir;
00224        }
00225               
00226        launchFileFlags = NULL;
00227        launchControlFlags = launchContinue + launchNoFileFlags + launchUseMinimum;
00228        err = LaunchAppOpeningDoc(running, &appSpec, &psn, &docSpec, 
00229                                                  launchFileFlags, launchControlFlags);
00230        if (err != noErr)
00231        {
00232               SysBeep(10); // XXX  show error dialog
00233               goto au_revoir;
00234        }
00235 
00236 au_revoir:    
00237        if (file)
00238               DisposePtr((Ptr) file);
00239               
00240        return;
00241 }
00242 
00243 void
00244 EnableWelcomeWin(void)
00245 {
00246        EnableNavButtons();
00247        
00248        if (gControls->cfg->bReadme)
00249               if (gControls->ww->readmeButton)
00250                      HiliteControl(gControls->ww->readmeButton, kEnableControl);
00251 }
00252 
00253 void
00254 DisableWelcomeWin(void)
00255 {
00256        DisableNavButtons();
00257        
00258        if (gControls->cfg->bReadme)
00259               if (gControls->ww->readmeButton)
00260                      HiliteControl(gControls->ww->readmeButton, kDisableControl);
00261 }
00262 
00263 OSErr LaunchAppOpeningDoc (Boolean running, FSSpec *appSpec, ProcessSerialNumber *psn,
00264        FSSpec *docSpec, unsigned short launchFileFlags, unsigned short launchControlFlags)
00265 {
00266        ProcessSerialNumber thePSN;
00267        AEDesc               target = {0, nil};
00268        AEDesc               docDesc = {0, nil};
00269        AEDesc               launchDesc = {0, nil};
00270        AEDescList    docList = {0, nil};
00271        AppleEvent    theEvent = {0, nil};
00272        AppleEvent    theReply = {0, nil};
00273        OSErr         err = noErr;
00274        Boolean              autoParamValue = false;
00275 
00276        if (running) thePSN = *psn;
00277        err = AECreateDesc(typeProcessSerialNumber, &thePSN, sizeof(thePSN), &target); 
00278        if (err != noErr) goto exit;
00279        
00280        err = AECreateAppleEvent(kCoreEventClass, kAEOpenDocuments, &target,
00281               kAutoGenerateReturnID, kAnyTransactionID, &theEvent);
00282        if (err != noErr) goto exit;
00283        
00284        if (docSpec)
00285        {
00286               err = AECreateList(nil, 0, false, &docList);
00287               if (err != noErr) goto exit;
00288               
00289               err = AECreateDesc(typeFSS, docSpec, sizeof(FSSpec), &docDesc);
00290               if (err != noErr) goto exit;
00291               
00292               err = AEPutDesc(&docList, 0, &docDesc);
00293               if (err != noErr) goto exit;
00294               
00295               err = AEPutParamDesc(&theEvent, keyDirectObject, &docList);
00296               if (err != noErr) goto exit;
00297        }
00298        
00299        if (running)
00300        {
00301               err = AESend(&theEvent, &theReply, kAENoReply, kAENormalPriority, kNoTimeOut, nil, nil);
00302               if (err != noErr) goto exit;
00303               if ((launchControlFlags & launchDontSwitch) == 0) {
00304                      err = SetFrontProcess(psn);
00305                      if (err != noErr) goto exit;
00306               }
00307        }
00308        else
00309        {
00310               LaunchParamBlockRec  launchThis = {0};
00311               
00312               err = AECoerceDesc(&theEvent, typeAppParameters, &launchDesc);
00313               if (err != noErr) goto exit;
00314               HLock(theEvent.dataHandle);
00315               
00316               launchThis.launchAppSpec = appSpec;
00317               launchThis.launchAppParameters = (AppParametersPtr)*launchDesc.dataHandle;
00318               launchThis.launchBlockID = extendedBlock;
00319               launchThis.launchEPBLength = extendedBlockLen;
00320               launchThis.launchFileFlags = launchFileFlags;
00321               launchThis.launchControlFlags = launchControlFlags;
00322               err = LaunchApplication(&launchThis);
00323        }
00324        
00325 exit:
00326 
00327        if (target.dataHandle != nil) AEDisposeDesc(&target);
00328        if (docDesc.dataHandle != nil) AEDisposeDesc(&docDesc);
00329        if (launchDesc.dataHandle != nil) AEDisposeDesc(&launchDesc);
00330        if (docList.dataHandle != nil) AEDisposeDesc(&docList);
00331        if (theEvent.dataHandle != nil) AEDisposeDesc(&theEvent);
00332        if (theReply.dataHandle != nil) AEDisposeDesc(&theReply);
00333        return err;
00334 }
00335 
00336 OSErr FindAppUsingSig (OSType sig, FSSpec *fSpec, Boolean *running, ProcessSerialNumber *psn)
00337 {
00338        OSErr  err = noErr;
00339        short  sysVRefNum, vRefNum, index;
00340        Boolean       hasDesktopDB;
00341 
00342        if (running != nil) {
00343               err = FindRunningAppBySignature(sig, fSpec, psn);
00344               *running = true;
00345               if (err == noErr) return noErr;
00346               *running = false;
00347               if (err != procNotFound) return err;
00348        }
00349        err = GetSysVolume(&sysVRefNum);
00350        if (err != noErr) return err;
00351        vRefNum = sysVRefNum;
00352        index = 0;
00353        while (true) {
00354               if (index == 0 || vRefNum != sysVRefNum) {
00355                      err = VolHasDesktopDB(vRefNum, &hasDesktopDB);
00356                      if (err != noErr) return err;
00357                      if (hasDesktopDB) {
00358                             err = FindAppOnVolume(sig, vRefNum, fSpec);
00359                             if (err != afpItemNotFound) return err;
00360                      }
00361               }
00362               index++;
00363               err = GetIndVolume(index, &vRefNum);
00364               if (err == nsvErr) return fnfErr;
00365               if (err != noErr) return err;
00366        }
00367 }
00368 
00369 OSErr FindRunningAppBySignature (OSType sig, FSSpec *fSpec, ProcessSerialNumber *psn)
00370 {
00371        OSErr                err = noErr;
00372        ProcessInfoRec       info;
00373        FSSpec               tempFSSpec;
00374        
00375        psn->highLongOfPSN = 0;
00376        psn->lowLongOfPSN  = kNoProcess;
00377        while (true)
00378        {
00379               err = GetNextProcess(psn);
00380               if (err != noErr) return err;
00381               info.processInfoLength = sizeof(ProcessInfoRec);
00382               info.processName = nil;
00383               info.processAppSpec = &tempFSSpec;
00384               err = GetProcessInformation(psn, &info);
00385               if (err != noErr) return err;
00386               
00387               if (info.processSignature == sig)
00388               {
00389                      if (fSpec != nil)
00390                             *fSpec = tempFSSpec;
00391                      return noErr;
00392               }
00393        }
00394        
00395        return procNotFound;
00396 }
00397 
00398 static OSErr VolHasDesktopDB (short vRefNum, Boolean *hasDesktop)
00399 {
00400        HParamBlockRec              pb;
00401        GetVolParmsInfoBuffer       info;
00402        OSErr                       err = noErr;
00403        
00404        pb.ioParam.ioCompletion = nil;
00405        pb.ioParam.ioNamePtr = nil;
00406        pb.ioParam.ioVRefNum = vRefNum;
00407        pb.ioParam.ioBuffer = (Ptr)&info;
00408        pb.ioParam.ioReqCount = sizeof(info);
00409        err = PBHGetVolParmsSync(&pb);
00410        *hasDesktop = err == noErr && (info.vMAttrib & (1L << bHasDesktopMgr)) != 0;
00411        return err;
00412 }
00413 
00414 static OSErr FindAppOnVolume (OSType sig, short vRefNum, FSSpec *file)
00415 {
00416        DTPBRec pb;
00417        OSErr err = noErr;
00418        short ioDTRefNum, i;
00419        FInfo fInfo;
00420        FSSpec candidate;
00421        unsigned long lastModDateTime, maxLastModDateTime;
00422 
00423        memset(&pb, 0, sizeof(DTPBRec));
00424        pb.ioCompletion = nil;
00425        pb.ioVRefNum = vRefNum;
00426        pb.ioNamePtr = nil;
00427        err = PBDTGetPath(&pb);
00428        if (err != noErr) return err;
00429        ioDTRefNum = pb.ioDTRefNum;
00430 
00431        memset(&pb, 0, sizeof(DTPBRec));
00432        pb.ioCompletion = nil;
00433        pb.ioIndex = 0;
00434        pb.ioFileCreator = sig;
00435        pb.ioNamePtr = file->name;
00436        pb.ioDTRefNum = ioDTRefNum;
00437        err = PBDTGetAPPL(&pb, false);
00438        
00439        if (err == fnfErr || err == paramErr) return afpItemNotFound;
00440        if (err != noErr) return err;
00441 
00442        file->vRefNum = vRefNum;
00443        file->parID = pb.ioAPPLParID;
00444        
00445        err = FSpGetFInfo(file, &fInfo);
00446        if (err == noErr) return noErr;
00447        
00448        i = 1;
00449        maxLastModDateTime = 0;
00450        while (true) {
00451               memset(&pb, 0, sizeof(DTPBRec)); 
00452               pb.ioCompletion = nil;
00453               pb.ioIndex = i;
00454               pb.ioFileCreator = sig;
00455               pb.ioNamePtr = candidate.name;
00456               pb.ioDTRefNum = ioDTRefNum;
00457               err = PBDTGetAPPLSync(&pb);
00458               if (err != noErr) break;
00459               candidate.vRefNum = vRefNum;
00460               candidate.parID = pb.ioAPPLParID;
00461               err = GetLastModDateTime(&candidate, &lastModDateTime);
00462               if (err == noErr) {
00463                      if (lastModDateTime > maxLastModDateTime) {
00464                             maxLastModDateTime = lastModDateTime;
00465                             *file = candidate;
00466                      }
00467               }
00468               i++;
00469        }
00470        
00471        return maxLastModDateTime > 0 ? noErr : afpItemNotFound;
00472 }
00473 
00474 OSErr GetSysVolume (short *vRefNum)
00475 {
00476        long dir;
00477        
00478        return FindFolder(kOnSystemDisk, kSystemFolderType, false, vRefNum, &dir);
00479 }
00480 
00481 OSErr GetIndVolume (short index, short *vRefNum)
00482 {
00483        ParamBlockRec pb;
00484        OSErr err = noErr;
00485        
00486        pb.volumeParam.ioCompletion = nil;
00487        pb.volumeParam.ioNamePtr = nil;
00488        pb.volumeParam.ioVolIndex = index;
00489        
00490        err = PBGetVInfoSync(&pb);
00491        
00492        *vRefNum = pb.volumeParam.ioVRefNum;
00493        return err;
00494 }
00495 
00496 OSErr GetLastModDateTime(const FSSpec *fSpec, unsigned long *lastModDateTime)
00497 {
00498        CInfoPBRec    pBlock;
00499        OSErr         err = noErr;
00500        
00501        pBlock.hFileInfo.ioNamePtr = (StringPtr)fSpec->name;
00502        pBlock.hFileInfo.ioVRefNum = fSpec->vRefNum;
00503        pBlock.hFileInfo.ioFDirIndex = 0;
00504        pBlock.hFileInfo.ioDirID = fSpec->parID;
00505        err = PBGetCatInfoSync(&pBlock);
00506        if (err != noErr) return err;
00507        *lastModDateTime = pBlock.hFileInfo.ioFlMdDat;
00508        return noErr;
00509 }
00510