home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / central / uapp.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  119.4 KB  |  4,272 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /* Portions copyright Metrowerks Corporation. */
  20.  
  21. // ===========================================================================
  22. // UApp.cp
  23. // main and CFrontApp's methods
  24. // Created by atotic, June 6th, 1994
  25. // ===========================================================================
  26.  
  27. #include "fullsoft.h"
  28.  
  29. #include "uapp.h"
  30.  
  31. #include "CAppleEventHandler.h"
  32. //#include "shist.h"
  33.  
  34. //#include <QAP_Assist.h>
  35. #include <LGARadioButton.h>
  36. #include <LGACheckbox.h>
  37.  
  38.     // macfe
  39. //#include "NavigationServicesSupport.h"
  40. #include "earlmgr.h"
  41. #include "macutil.h"
  42. #include "macgui.h"    // HyperStyle
  43. #include "CBookmarksAttachment.h"
  44. #include "CToolsAttachment.h"
  45. #include "CFontMenuAttachment.h"
  46. #include "CRecentEditMenuAttachment.h"
  47. #include "BookmarksFile.h"
  48. #include "mprint.h"
  49. #include "mimages.h"
  50. #include "mplugin.h"
  51. #include "prpriv.h"
  52.  
  53. #if defined (JAVA)
  54. #include "mjava.h"
  55. #endif
  56.  
  57. #include "mregistr.h"
  58. #include "resae.h"
  59. #include "resgui.h"
  60. #include "uerrmgr.h"
  61. #include "ufilemgr.h"
  62. #include "msv2dsk.h"
  63. #include "mversion.h"
  64. #include "xp_sec.h"
  65. #include "xp_trace.h"
  66. #include "CTargetedUpdateMenuRegistry.h"
  67. #include "UDesktop.h"
  68. #include "CPersonalToolbarManager.h"
  69. #include "CNavCenterWindow.h"
  70. #include "URobustCreateWindow.h"
  71. #include "URDFUtilities.h"
  72. #ifdef MOZ_MAIL_NEWS
  73. #include "CMessageFolder.h"
  74. #include "UNewFolderDialog.h"
  75. #endif
  76.  
  77. #include "LMenuSharing.h"
  78. #define MENU_SHARING_FIRST 40
  79.  
  80. #ifndef NSPR20
  81. #include "CNetwork.h"
  82. #endif
  83. #include "CEnvironment.h"
  84.  
  85. #include "CWindowMenu.h"
  86. #include "CHistoryMenu.h"
  87. #include "CNSMenuBarManager.h"
  88. #ifdef MOZ_MAIL_NEWS
  89. #include "CThreadWindow.h"
  90. #include "UMailFolderMenus.h"
  91. #endif
  92.  
  93. #include "UTearOffPalette.h"
  94. #include "CPaneEnabler.h"
  95. #include "CApplicationEventAttachment.h"
  96. #include "CCloseAllAttachment.h"
  97.  
  98. #include "CNSContextCallbacks.h"
  99. #include "CBrowserContext.h"
  100.  
  101. #include "prgc.h"
  102. #include "java.h"
  103.  
  104. #include "secrng.h"
  105. #include "secnav.h"
  106. #include "mkutils.h" // only for  FREEIF() macro.  JRM 96/10/17
  107.  
  108. #include "CEditorWindow.h"
  109. #include "CEditView.h"
  110.  
  111. #ifdef MOZ_MAIL_NEWS
  112. #include "MailNewsSearch.h"
  113. #include "MailNewsFilters.h"
  114. #include "MailNewsAddressBook.h"
  115.  
  116. #include "CCheckMailContext.h"
  117. #endif // MOZ_MAIL_NEWS
  118.  
  119. #include "StBlockingDialogHandler.h"
  120. #include "CSecureAttachment.h"
  121. //#include "VTSMProxy.h"
  122.  
  123. #include "LTSMSupport.h"
  124.  
  125. #include "CMouseDispatcher.h"
  126. #include "CSuspenderResumer.h"
  127.  
  128. #if defined(MOZ_MAIL_COMPOSE) || defined(MOZ_MAIL_NEWS)
  129. #include "MailNewsClasses.h"
  130. #include "msgcom.h"
  131. #include "MailNewsgroupWindow_Defines.h"
  132. #endif
  133.  
  134. #include "BrowserClasses.h"
  135.  
  136. //#include "CBrowserView.h" // need for CFrontApp::EventKeyUp() 1997-02-24 mjc
  137. #include "CKeyUpReceiver.h" // need in CFrontApp::EventKeyUp()
  138.  
  139. #include "CToolbarModeManager.h"
  140. #include "CMozillaToolbarPrefsProxy.h"
  141. #include "CSharedPatternWorld.h"
  142.  
  143. #include "InternetConfig.h"
  144.  
  145. #ifdef MOCHA
  146. //#include "libmocha.h"
  147. #include "CMochaHacks.h"
  148. #endif
  149.  
  150. PRThread* mozilla_thread;
  151.  
  152. PREventQueue *mozilla_event_queue = NULL;
  153.  
  154. #if defined (JAVA)
  155. #include "MFramePeer.h"
  156. #endif
  157.  
  158. #include "CLibMsgPeriodical.h"
  159.  
  160.     // Netscape
  161. #ifndef GLHIST_H
  162. #include "glhist.h"
  163. #endif
  164.  
  165. #include "edtplug.h"
  166.  
  167. #include "m_cvstrm.h"
  168. #include "prefapi.h"
  169. #include "NSReg.h"
  170.  
  171. #include <Balloons.h>
  172.  
  173. // HERE ONLY UNTIL NAV SERVICES CODE MERGED INTO TIP
  174. Boolean SimpleOpenDlog ( short numTypes, const OSType typeList[], FSSpec* outFSSpec ) ;
  175.  
  176.  
  177. CAutoPtr<CNSContext> CFrontApp::sRDFContext;
  178. //======================================================================================
  179. //                                    PROFILE
  180. //======================================================================================
  181.  
  182. #ifdef PROFILE
  183. #include <profiler.h>
  184.  
  185.         // Define this if you want to start profiling when the Caps Lock
  186.         // key is pressed. Usually that's what you want: press Caps Lock,
  187.         // start the command you want to profile, release Caps Lock when
  188.         // the command is done. It works for all the major commands:
  189.         // display a page, send a mail, save an attachment, etc...
  190. #define PROFILE_ON_CAPSLOCK
  191.  
  192.         // Define this if you want to let the profiler run while you're
  193.         // spending time in other apps. Usually you don't.
  194. //#define PROFILE_WAITNEXTEVENT
  195.  
  196.  
  197.         // Legacy stuff: profiles CFrontApp::UpdateMenus().
  198.         // Don't use other profile methods at the same time.
  199. //#define PROFILE_UPDATE_MENUS
  200.  
  201.  
  202. //---------------------------------------------
  203. // Paste these in the file you want to profile
  204. // The code to be profiled must be in a project
  205. // with "Emit profiler calls" turned on.
  206. //
  207. //    Example:
  208. //        ProfileStart()
  209. //             ...
  210. //            ProfileSuspend()
  211. //                ...
  212. //            ProfileResume()
  213. //            ...
  214. //        ProfileStop()
  215. //
  216. // If you want to start the profile when Caps Lock
  217. // is pressed, you can use:
  218. //
  219. //        if (IsThisKeyDown(0x39)) // caps lock
  220. //            ProfileStart()
  221. //
  222. //---------------------------------------------
  223. extern void ProfileStart();
  224. extern void ProfileStop();
  225. extern void    ProfileSuspend();
  226. extern void ProfileResume();
  227. extern Boolean ProfileInProgress();
  228. //---------------------------------------------
  229.  
  230. static Boolean sProfileInProgress = false;
  231. void ProfileStart()
  232. {
  233.     if (! sProfileInProgress)
  234.     {
  235.         sProfileInProgress = true;
  236.         if (ProfilerInit(collectDetailed, microsecondsTimeBase, 2000, 100))
  237.             return;
  238.         ProfilerSetStatus(true);
  239.     }
  240. }
  241.  
  242. void ProfileStop()
  243. {
  244.     if (sProfileInProgress)
  245.     {
  246.         ProfilerDump("\pMozilla Profile");
  247.         ProfilerTerm();
  248.         sProfileInProgress = false;
  249.     }
  250. }
  251.  
  252. void ProfileSuspend()
  253. {
  254.     if (sProfileInProgress)
  255.         ProfilerSetStatus(false);
  256. }
  257.  
  258. void ProfileResume()
  259. {
  260.     if (sProfileInProgress)
  261.         ProfilerSetStatus(true);
  262. }
  263.  
  264. Boolean ProfileInProgress()
  265. {
  266.     return sProfileInProgress;
  267. }
  268.  
  269. #endif // PROFILE
  270. //======================================================================================
  271.  
  272. #ifdef FORTEZZA
  273. #include "ssl.h"
  274. #endif
  275.  
  276. #include <LArray.h>
  277.  
  278. #include "CPrefsDialog.h"
  279. #include "UProcessUtils.h"        // for LaunchApplication
  280.  
  281. #ifdef MOZ_OFFLINE
  282. #include "UOffline.h"
  283. #endif
  284.  
  285. #define        LICENSE_REVISION            7
  286.  
  287. extern NET_StreamClass *IL_NewStream(int, void *, URL_Struct *, MWContext *);
  288. extern void TrySetCursor( int whichCursor );
  289.  
  290. list<CommandT>    CFrontApp::sCommandsToUpdateBeforeSelectingMenu;
  291.  
  292. CFrontApp*        CFrontApp::sApplication = NULL;
  293. CAppleEventHandler*        CAppleEventHandler::sAppleEventHandler = NULL;
  294. short                    CFrontApp::sHelpMenuOrigLength = 4;
  295. short                    CFrontApp::sHelpMenuItemCount = 0;
  296. double            CFrontApp::sHRes = 1.0;
  297. double            CFrontApp::sVRes = 1.0;
  298. static PA_InitData        parser_initdata;
  299. CPersonalToolbarManager*    CFrontApp::sPersonalToolbarManager = NULL;        // created after prefs init'ed.
  300.  
  301. static void        InitDebugging();
  302. static void        ConfirmWeWillRun();
  303. static Boolean    NetscapeIsRunning(ProcessSerialNumber& psn);
  304. static Boolean    LicenseHasExpired();
  305. static void     CheckForOtherNetscapes();
  306. static void        Assert68020();
  307. static void        AssertSystem7();
  308.  
  309. static const OSType kConferenceAppSig = 'Ncq╣';
  310. static const OSType kCalendarAppSig = 'NScl';
  311.  
  312. #ifdef EDITOR
  313. static void OpenEditURL(const char* url){
  314.     if ( url != NULL ) {
  315.         URL_Struct * request = NET_CreateURLStruct ( url, NET_NORMAL_RELOAD );
  316.         if ( request )
  317.             CEditorWindow::MakeEditWindow( NULL, request );
  318.     }
  319. }
  320. #endif // EDITOR
  321.  
  322. //======================================
  323. class LTimerCallback: public LPeriodical
  324. // class that keeps track of xp timeout callbacks
  325. //======================================
  326. {
  327. public:
  328.                 LTimerCallback( TimeoutCallbackFunction func, void* closure, uint32 msecs );
  329.     void        SpendTime( const EventRecord& inMacEvent );
  330.  
  331.     static LArray*    sTimerList;
  332.  
  333. protected:
  334.     UInt32        fFireTime;
  335.     TimeoutCallbackFunction fFireFunc;
  336.     void*        fClosure;
  337. };
  338.  
  339. LArray* LTimerCallback::sTimerList = NULL;
  340.  
  341. //-----------------------------------
  342. LTimerCallback::LTimerCallback( TimeoutCallbackFunction func, void* closure, uint32 msecs )
  343. :    LPeriodical()
  344. //-----------------------------------
  345. {
  346.     UInt32 ticks = ::TickCount();
  347.     
  348.     // Ñ╩calculate the fire time in ticks from now
  349.     fFireTime = ticks + ceil(((double)msecs / 100.0) * 6.0);
  350.     fFireFunc = func;
  351.     fClosure = closure;
  352.     this->StartIdling();
  353. }
  354.     
  355. //-----------------------------------
  356. void LTimerCallback::SpendTime( const EventRecord& inMacEvent )
  357. //-----------------------------------
  358. {
  359.     UInt32 ticks = inMacEvent.when;
  360.     
  361.     if ( ticks >= fFireTime )
  362.     {
  363.         // 97-06-18 pkc -- Remove this from sTimerList first because when we call
  364.         // fFireFunc could possibly cause a call to FE_ClearTimeout on this
  365.         // remove from timer list before deleting
  366.         LTimerCallback::sTimerList->Remove(&this);
  367.     
  368.         // let's just say that the fFireFunc gives time to repeaters...
  369.         // We don't want this one going off again before it is deleted!
  370.         fFireTime = LONG_MAX;
  371.         
  372.         if ( fFireFunc )
  373.             (*fFireFunc)( fClosure );
  374.         delete this;
  375.     }
  376. }
  377.  
  378. //-----------------------------------
  379. void* FE_SetTimeout( TimeoutCallbackFunction func, void* closure, uint32 msecs )
  380. // this function should register a function that will
  381. // be called after the specified interval of time has
  382. // elapsed.  This function should return an id
  383. // that can be passed to FE_ClearTimer to cancel
  384. // the timer request.
  385. //
  386. // func:    The function to be invoked upon expiration of
  387. //          the timer interval
  388. // closure: Data to be passed as the only argument to "func"
  389. // msecs:   The number of milli-seconds in the interval
  390. //-----------------------------------
  391. {    
  392.     Try_
  393.     {
  394.         LTimerCallback* t = new LTimerCallback( func, closure, msecs );
  395.         // insert timer callback into list
  396.         try {
  397.             if (!LTimerCallback::sTimerList)
  398.                 LTimerCallback::sTimerList = new LArray(sizeof(LTimerCallback*));
  399.             LTimerCallback::sTimerList->InsertItemsAt(1, LArray::index_Last, &t);
  400.         } catch (...) {
  401.         }
  402.         return t;
  403.     }
  404.     Catch_( inErr )
  405.     {
  406.         return NULL;
  407.     }
  408.     EndCatch_
  409. }
  410.  
  411. //-----------------------------------
  412. void FE_ClearTimeout( void* timer_id )
  413. // This function cancels a timer that has previously been set.
  414. // Callers should not pass in NULL or a timer_id that has already expired.
  415. //-----------------------------------
  416. {
  417.     XP_ASSERT( timer_id );
  418.  
  419.     LTimerCallback* timer = (LTimerCallback*)timer_id;
  420.     if (LTimerCallback::sTimerList)
  421.     {
  422.         if (LTimerCallback::sTimerList->FetchIndexOf(&timer) > LArray::index_Bad)
  423.         {
  424.             // this LTimerCallback is in timer list
  425.             // remove from timer list before deleting
  426.             LTimerCallback::sTimerList->Remove(&timer);
  427.             delete timer;
  428.         }
  429.     }
  430. }
  431.  
  432. #pragma mark -
  433.  
  434. void Assert68020() 
  435. {
  436.     long response = 0;
  437.     OSErr err = ::Gestalt (gestaltQuickdrawVersion, &response);
  438.     if (err || response == gestaltOriginalQD) {
  439.         ::Alert (14000, NULL);
  440.         ::ExitToShell ();
  441.     }
  442. }
  443.  
  444. void AssertSystem7() 
  445. {
  446.     long response = 0;
  447.     OSErr err = ::Gestalt (gestaltSystemVersion, &response);
  448.     if (err || response < 0x700) {
  449.         ::Alert (14001, NULL);
  450.         ::ExitToShell ();
  451.     }
  452. }
  453.  
  454. static void RequiredGutsNotFoundAlert()
  455. {
  456.     Str255 gutsFolderName;
  457.     
  458.     GetIndString(gutsFolderName, 14000, 1);
  459.     ParamText(gutsFolderName, NULL, NULL, NULL);
  460.     Alert (14002, NULL);
  461.     ExitToShell();
  462. }
  463.  
  464. static void AssertRequiredGuts()
  465. {
  466.     //    Initialize the "CPrefs::NetscapeFolder" and "CPrefs::RequiredGutsFolder"
  467.     //    static variables early for use by the XP strings code in "errmgr.cp."
  468.     
  469.     short vRefNum;
  470.     long dirID;
  471.     
  472.     if (HGetVol(NULL, &vRefNum, &dirID) != noErr)
  473.         ExitToShell();
  474.     
  475.     FSSpec netscapeFolderSpec;
  476.     
  477.     if (CFileMgr::FolderSpecFromFolderID(vRefNum, dirID, netscapeFolderSpec) != noErr)
  478.         RequiredGutsNotFoundAlert();
  479.     
  480.     try
  481.     {
  482.         CPrefs::Initialize();
  483.     }
  484.     catch (...)
  485.     {
  486.         RequiredGutsNotFoundAlert();
  487.     }
  488.     CPrefs::SetFolderSpec(netscapeFolderSpec, CPrefs::NetscapeFolder);
  489.     
  490.     FSSpec gutsFolderSpec;
  491.  
  492.         // Build a partial path to the guts folder starting from a folder we know (the Netscape folder)
  493.     Str255 partialPath;
  494.  
  495.     {
  496.             // Get the name of the guts folder
  497.         Str255 gutsFolderName;
  498.         GetIndString(gutsFolderName, 14000, 1);    
  499.  
  500.             // partialPath = ":" + netscapeFolderSpec.name + ":" + gutsFolderName;
  501.             //    ( this may _look_ cumbersome, but it's really the most space and time efficient way to catentate 4 pstrings )
  502.         int dest=0;
  503.         partialPath[++dest] = ':';
  504.         for ( int src=0; src<netscapeFolderSpec.name[0]; )
  505.             partialPath[++dest] = netscapeFolderSpec.name[++src];
  506.         partialPath[++dest] = ':';
  507.         for ( int src=0; src<gutsFolderName[0]; )
  508.             partialPath[++dest] = gutsFolderName[++src];
  509.         partialPath[0] = dest;
  510.     }
  511.  
  512.         // Use the partial path to construct an FSSpec identifying the required guts folder
  513.     FSMakeFSSpec(netscapeFolderSpec.vRefNum, netscapeFolderSpec.parID, partialPath, &gutsFolderSpec);
  514.  
  515.     {    // Ensure that the folder exists (even if pointed to by an alias) and actually _is_ a folder
  516.         Boolean targetIsFolder, targetWasAliased;
  517.         if ( (ResolveAliasFile(&gutsFolderSpec, true, &targetIsFolder, &targetWasAliased) != noErr)
  518.             || !targetIsFolder )
  519.             RequiredGutsNotFoundAlert();
  520.     }
  521.  
  522.         // ...and finally, publish the found spec where other routines in the app can find it
  523.     CPrefs::SetFolderSpec(gutsFolderSpec, CPrefs::RequiredGutsFolder);
  524. }
  525.  
  526. static void DisableJavaIfNotAvailable ()
  527. {
  528.     short vRefNum;
  529.     long dirID;
  530.     
  531.     if (HGetVol(NULL, &vRefNum, &dirID) != noErr)
  532.         ExitToShell();
  533.     
  534.     FSSpec netscapeFolderSpec;
  535.     
  536.     // This can't fail because we already called AssertRequiredGuts
  537.     CFileMgr::FolderSpecFromFolderID(vRefNum, dirID, netscapeFolderSpec);
  538.         
  539.     FSSpec javaFolderSpec;
  540.  
  541.     // Build a partial path to the guts folder starting from a folder we know (the Netscape folder)
  542.     Str255 partialPath;
  543.  
  544.     {
  545.         // Get the name of the guts folder
  546.         Str255 gutsFolderName;
  547.         GetIndString(gutsFolderName, 14000, 1);    
  548.  
  549.         // jj confirmed it's OK to hard code the name of this folder
  550.         static unsigned char *javaFolderName = "\pJava";
  551.  
  552.         // partialPath = ":" + netscapeFolderSpec.name + ":" + gutsFolderName + ":" + javaFolderName
  553.         //    ( this may _look_ cumbersome, but it's really the most space and time efficient way to catentate 4 pstrings )
  554.         int dest=0;
  555.         partialPath[++dest] = ':';
  556.         for ( int src=0; src<netscapeFolderSpec.name[0]; )
  557.             partialPath[++dest] = netscapeFolderSpec.name[++src];
  558.         partialPath[++dest] = ':';
  559.         for ( int src=0; src<gutsFolderName[0]; )
  560.             partialPath[++dest] = gutsFolderName[++src];
  561.         partialPath[++dest] = ':';
  562.         for ( int src=0; src<javaFolderName[0]; )
  563.             partialPath[++dest] = javaFolderName[++src];
  564.         partialPath[0] = dest;
  565.     }
  566.  
  567.     // Use the partial path to construct an FSSpec identifying the required guts folder
  568.     OSErr err = FSMakeFSSpec(netscapeFolderSpec.vRefNum, netscapeFolderSpec.parID, partialPath, &javaFolderSpec);
  569.     if (
  570.         (FSMakeFSSpec(netscapeFolderSpec.vRefNum, netscapeFolderSpec.parID, partialPath, &javaFolderSpec) != noErr)
  571.         ||
  572.         !CFileMgr::IsFolder(javaFolderSpec)
  573.     )
  574.     {
  575.         static const char* inline_javascript_text ="lockPref(\"security.enable_java\", false)";
  576.         PREF_EvaluateJSBuffer(inline_javascript_text, strlen(inline_javascript_text));
  577.     }
  578.  
  579. }
  580.  
  581. static void DisplayErrorDialog ( OSErr err )
  582. {
  583.     if (::GetResource('ALRT', ALRT_ErrorOccurred) && ::GetResource('STR#', 7098))
  584.     {
  585.         short stringIndex;
  586.         switch (err)
  587.         {
  588.             case userCanceledErr:
  589.                 return; // no alert
  590.             case memFullErr:
  591.                 stringIndex = 1;  //"there was not enough memory."
  592.                 break;
  593.             case dskFulErr:
  594.                 stringIndex = 3;
  595.                 break;
  596.             case fnfErr:
  597.                 stringIndex = 4;
  598.                 break;
  599.             case dirNFErr:
  600.                 stringIndex = 5;
  601.                 break;
  602.             case nsvErr:
  603.                 stringIndex = 6;
  604.                 break;
  605.             case bdNamErr:
  606.                 stringIndex = 7;
  607.                 break;
  608.             case vLckdErr:
  609.                 stringIndex = 8;
  610.                 break;
  611.             case fBsyErr:
  612.                 stringIndex = 9;
  613.                 break;
  614.             case dupFNErr:
  615.                 stringIndex = 10;
  616.                 break;
  617.             case opWrErr:
  618.                 stringIndex = 11;
  619.                 break;
  620.             case permErr:
  621.                 stringIndex = 12;
  622.                 break;
  623.             // ADD OTHER CASES HERE
  624.             default:
  625.                 stringIndex = 2;  //"of an unknown error."
  626.                 break;
  627.         }
  628.         CStr255 p0, p1;
  629.         ::GetIndString(p0, 7098, stringIndex);
  630.         ::NumToString(err, p1);
  631.         ::ParamText(p0, p1, nil, nil);
  632.         ::CautionAlert(ALRT_ErrorOccurred, nil);
  633.     }
  634.     else
  635.         throw;
  636. }
  637.  
  638. static void DisplayExceptionCodeDialog ( ExceptionCode err )
  639. {
  640.     if (::GetResource('ALRT', ALRT_ErrorOccurred) && ::GetResource('STR#', 7098))
  641.     {
  642.         short stringIndex;
  643.         switch (err)
  644.         {
  645.             case memFullErr:
  646.                 err = err_NilPointer; // & fall through...
  647.             case err_NilPointer:
  648.                 stringIndex = 1;  //"there was not enough memory."
  649.                 break;
  650.             default:
  651.                 stringIndex = 2;  //"of an unknown error."
  652.                 break;
  653.         }
  654.         CStr255 p0, p1 = (long)err; // the "long" constructor prints the 4 character OSType.
  655.         ::GetIndString(p0, 7098, stringIndex);
  656.         ::ParamText(p0, p1, nil, nil);
  657.         ::CautionAlert(ALRT_ErrorOccurred, nil);
  658.     }
  659.     else
  660.         throw;
  661. }
  662.  
  663. #ifdef MOZ_MAIL_NEWS
  664. // TRUE if url *must* be loaded in this context type
  665. Boolean URLRequiresContextType( const URL_Struct* url, MWContextType & type)
  666. {
  667.     if ( url )
  668.     {
  669.         if ( MSG_RequiresMailWindow( url->address ) )
  670.             type = MWContextMail;
  671.         else if ( MSG_RequiresNewsWindow( url->address ) )
  672.             type = MWContextNews;
  673.         else if (MSG_RequiresBrowserWindow(url->address))
  674.             type = MWContextBrowser;
  675.         else
  676.             return FALSE;
  677.         return TRUE;
  678.     }
  679.     return FALSE;
  680. }
  681. #endif // MOZ_MAIL_NEWS
  682.  
  683. extern "C" {
  684. void InitializeASLM();
  685. void CleanupASLM();
  686. }
  687.  
  688. #pragma mark -
  689.  
  690. //======================================
  691. class CResumeEventAttachment : public LAttachment
  692. // This silly class fixes a weird bug where the app doesn╒t
  693. // get resume events after being sent a getURL AppleEvent.
  694. // This attachment will run whenever we get an event, so
  695. // we can check to see if the event is not a resume event,
  696. // target is nil (meaning we haven╒t received a resume 
  697. // event yet), and we╒re in the foreground (meaning we got
  698. // switched in without getting the event).  If all those
  699. // are true, we can resume ourselves so we won╒t crash 
  700. // because target is nil.
  701. //======================================
  702. {
  703.     public:
  704.                              CResumeEventAttachment(CFrontApp* app) : LAttachment(msg_Event), fApp(app) {}
  705.     protected:
  706.         virtual void         ExecuteSelf(MessageT inMessage, void* ioParam);
  707.     private:
  708.                 CFrontApp*    fApp;
  709. };
  710.  
  711. //-----------------------------------
  712. void CResumeEventAttachment::ExecuteSelf(MessageT inMessage, void* ioParam)
  713. //-----------------------------------
  714. {
  715.     EventRecord* event = (EventRecord*) ioParam;
  716.     
  717.     //
  718.     // Do quick tests first to see if we should
  719.     // go ahead and check if we╒re in the foreground.
  720.     //
  721.     if (inMessage == msg_Event && event->what != osEvt && LCommander::GetTarget() == nil)
  722.     {
  723.         ProcessSerialNumber frontProcess;
  724.         ProcessSerialNumber currentProcess;
  725.         GetFrontProcess(&frontProcess);
  726.         GetCurrentProcess(¤tProcess);
  727.         Boolean result = false;
  728.         SameProcess(&frontProcess, ¤tProcess, &result);
  729.         if (result)
  730.         {
  731.             // 
  732.             // We╒re in the foreground, so synthesize
  733.             // a resume event and process it.
  734.             //
  735.             EventRecord resumeEvent;
  736.             memset(&resumeEvent, 0, sizeof(EventRecord));
  737.             resumeEvent.what = osEvt;
  738.             resumeEvent.message = suspendResumeMessage << 24;
  739.             resumeEvent.message |= resumeFlag;
  740.             fApp->DispatchEvent(resumeEvent);
  741.         }
  742.     }
  743. }
  744.  
  745. #pragma mark -
  746.  
  747. //======================================
  748. class CSplashScreen : public LWindow
  749. //======================================
  750. {
  751.     public:
  752.         enum { class_ID = 'Spls' };
  753.                                 
  754.                             CSplashScreen(LStream* inStream);
  755.         virtual                ~CSplashScreen();
  756.         
  757.         virtual void        SetDescriptor(ConstStringPtr inDescriptor);
  758.         
  759.     protected:
  760.     
  761.         virtual void        FinishCreateSelf(void);
  762.     
  763.         LCaption*            mStatusCaption;
  764.         CResPicture*        mBackPicture;
  765.         LFile*                mPictureResourceFile;
  766. };
  767.  
  768. #pragma mark -
  769.  
  770. //======================================
  771. // CLASS CFrontApp
  772. //======================================
  773.  
  774. //-----------------------------------
  775. CFrontApp::CFrontApp()
  776. //-----------------------------------
  777. :    fCurrentMbar(cBrowserMenubar)
  778. ,    fWantedMbar(fCurrentMbar)
  779. ,    fStartupAborted(false)
  780. ,    fProperStartup(false)
  781. ,    mSplashScreen(NULL)
  782. #ifdef MOZ_MAIL_NEWS
  783. ,    mLibMsgPeriodical(NULL)
  784. #endif // MOZ_MAIL_NEWS
  785. ,    mConferenceApplicationExists(false)
  786. ,    mJavaEnabled(false)
  787. ,    mHasBookmarksMenu(false)
  788. ,    mHasFrontierMenuSharing(false)
  789. , mMouseRgnH( NewRgn() )
  790.     // Performance
  791.     // We really should be adjusting this dynamically
  792. {
  793.     // Set environment features
  794.     
  795.     CEnvironment::SetAllFeatures();
  796.  
  797.     // Static data members
  798.     
  799.     sApplication = this;
  800.     
  801.     // Add CApplicationEventAttachment
  802.     
  803.     AddAttachment(new CApplicationEventAttachment);
  804.     
  805.     // Add CCloseAllAttachment
  806.     
  807.     AddAttachment(new CCloseAllAttachment(CLOSE_WINDOW, CLOSE_ALL_WINDOWS));
  808.     
  809.     // Inherited data members
  810.     mSleepTime = 1;
  811.  
  812.     // Indicate we don't want to be able to quit yet
  813.     fSafeToQuit = false;
  814.     fUserWantsToQuit = false;
  815.     
  816.     // Toolbox
  817.     qd.randSeed  = TickCount();                    // Toolbox
  818.  
  819.     AddAttachment(new LClipboard());
  820.     AddAttachment(new CSecureAttachment);
  821.     AddAttachment(new CResumeEventAttachment(this));    
  822.     
  823. #ifdef MOZ_MAIL_NEWS
  824.     // create CLibMsgPeriodical
  825.     mLibMsgPeriodical = new CLibMsgPeriodical;
  826.     mLibMsgPeriodical->StartIdling();
  827. #endif // MOZ_MAIL_NEWS
  828.     
  829.     //
  830.     //    Initial inline support (TSM)
  831.     //
  832.     LTSMSupport::Initialize();
  833.  
  834.     UHTMLPrinting::InitCustomPageSetup();
  835.     
  836.     NR_StartupRegistry();
  837.     
  838.     // Ñ PowerPlant initialization
  839.     UScreenPort::Initialize();
  840.  
  841. #if defined(MOZ_MAIL_NEWS) || defined(MOZ_MAIL_COMPOSE)
  842.     RegisterAllMailNewsClasses();
  843. #endif // MOZ_MAIL_NEWS
  844.     RegisterAllBrowserClasses();
  845.  
  846.     ShowSplashScreen();
  847.     
  848.     InitUTearOffPalette(this);
  849.     CTearOffManager::GetDefaultManager()->AddListener(this);
  850.  
  851.     // Ñ╩network
  852. #ifndef NSPR20
  853.     CNetworkDriver::CreateNetworkDriver();
  854. #endif
  855.  
  856.     TheEarlManager.StartRepeating();
  857.  
  858. //    WTSMManager::Initialize();
  859. //    AddAttachment(new VTSMDoEvent(msg_Event));
  860.  
  861.     HyperStyle::InitHyperStyle();
  862.     
  863.     // Ñ parser
  864.     parser_initdata.output_func = LO_ProcessTag;
  865.  
  866.     // Ñ╩parsers
  867.     //        mime parsers
  868.     NET_RegisterMIMEDecoders();
  869.  
  870.     //        external objects go to disk
  871.     NET_RegisterContentTypeConverter ("*", FO_PRESENT, nil, NewFilePipe);
  872.     NET_RegisterContentTypeConverter ("*", FO_SAVE_AS, nil, NewFilePipe);
  873.  
  874.  
  875.     // Record whether the conference application exists. We do this once here
  876.     // instead of lots 'o times in FindCommandStatus so searching for an app
  877.     // doesn't slow us to a crawl (especially when searchin on network volumes).
  878.     // One drawback of course, is that when the app is installed or removed,
  879.     // the menu won't be enabled or disabled until the user quits and restarts
  880.     // the app. This behavior is different than the pref panel for controlling
  881.     // whether conference launches on startup or not (but that occurence of
  882.     // FindApplication isn't called many times/sec either).
  883.  
  884.     FSSpec spec;
  885.                 
  886.     mConferenceApplicationExists = (CFileMgr::FindApplication(kConferenceAppSig, spec) == noErr);
  887.     mNetcasterContext = NULL;
  888. }
  889.  
  890. //-----------------------------------
  891. CFrontApp::~CFrontApp()
  892. //-----------------------------------
  893. {
  894.     // Save the current visibility information
  895.     if ( CPrefs::GetLong( CPrefs::StartupAsWhat ) == STARTUP_VISIBLE)
  896.         {
  897.         long winRecord = 0;
  898.         
  899.         CMediatedWindow* theWindow;
  900.         CWindowIterator iter(WindowType_Any);
  901.         while (iter.Next(theWindow))
  902.             {
  903.             switch(theWindow->GetWindowType())
  904.                 {
  905.                 case WindowType_MailNews:
  906.                     winRecord |= (MAIL_STARTUP_ID | NEWS_STARTUP_ID);
  907.                     break;
  908.                 case WindowType_Browser:
  909.                     winRecord |= BROWSER_STARTUP_ID;
  910.                     break;
  911.                 case WindowType_NavCenter:
  912.                     winRecord |= NAVCENTER_STARTUP_ID;
  913.                     break;
  914.                 case WindowType_Address:
  915.                     winRecord |= ADDRESS_STARTUP_ID;
  916.                     break;
  917.                 default:
  918.                     break;
  919.                 }
  920.             }
  921.             
  922.         if (winRecord != 0)
  923.             CPrefs::SetLong(winRecord, CPrefs::StartupBitfield);
  924.         }
  925.  
  926.  
  927.     {
  928.         // This really comes from ~LCommander. This gets
  929.         // executed after our destructor, and deletes all the windows
  930.         // We need windows to be deleted before we are done,
  931.         // because window destruction callbacks reference the app!
  932.         // DO NOT DO THIS (IT CAUSES UNNECESSARY DEBUG BREAKS): SetTarget(this);
  933.         
  934.         // tj, 5/1/96
  935.         //
  936.         // We must close the windows explicitly, so that each window
  937.         // can interrupt its context (XP_InterruptContext) while the 
  938.         // window is still completely alive
  939.         //
  940.         
  941.         //    Hmmmmm ... better be a hair more careful about traversing that window list.
  942.         //    DDM 21-JUN-96
  943.         
  944.         WindowRef macWindow = LMGetWindowList();
  945.         
  946.         while (macWindow)
  947.         {
  948.             LWindow *ppWindow = LWindow::FetchWindowObject(macWindow);
  949.             
  950.             if (ppWindow)
  951.             {
  952.                 ppWindow->DoClose();
  953.                 
  954.                 //    Start over at the beginning of the list.
  955.                 //    This is possibly slow but definitely safe, i.e. we're not using
  956.                 //    a block of memory that's been deleted.
  957.                 macWindow = LMGetWindowList();
  958.             }
  959.             else
  960.                 //    Skip to the next window in the list.
  961.                 macWindow = GetNextWindow(macWindow);
  962.         }
  963.  
  964.         // Delete all SubCommanders
  965.         LArrayIterator iterator(mSubCommanders);
  966.         LCommander    *theSub;
  967.         while (iterator.Next(&theSub))
  968.             delete theSub;
  969.     }
  970.     
  971.     HyperStyle::FinishHyperStyle();
  972.     
  973.     LTSMSupport::DoQuit( 0 );
  974.     
  975. //    WTSMManager::Quit();    
  976.     
  977. //    UpdateMenus();
  978.     TrySetCursor( watchCursor );
  979.     // XP_Saves
  980.     GH_SaveGlobalHistory();
  981.     GH_FreeGlobalHistory();
  982.     NET_SaveNewsrcFileMappings();
  983.     
  984. #ifdef MOZ_MAIL_NEWS
  985.     CAddressBookManager::CloseAddressBookManager();
  986.     CCheckMailContext::Release(this);
  987. #endif // MOZ_MAIL_NEWS
  988.  
  989.     //-----
  990.     // We just closed all the windows but we now have to wait for the callbacks
  991.     // in order to really delete the different contexts. That's because
  992.     // CNSContext::NoMoreUsers() calls ET_RemoveWindowContext() which posts
  993.     // an event which calls MochaDone() asynchronously and deletes the context..
  994.     //
  995.     // NOTE: CCheckMailContext::Release() also posts an event in order to delete
  996.     // its context. So make sure that PR_ProcessPendingEvents() is always
  997.     // executed after window->DoClose(), CCheckMailContext::Release() or any
  998.     // other destructor function which deletes a context. A symptom of not
  999.     // deleting the context is that newsgroups which have been unsubscribed
  1000.     // in the Message Center reappear when launching the application again.
  1001.     PR_ProcessPendingEvents(mozilla_event_queue);
  1002.     //-----
  1003.  
  1004. #ifndef NSPR20
  1005.     if (gNetDriver && !fStartupAborted)
  1006.     {
  1007.         extern const char*    CacheFilePrefix;
  1008.         NET_CleanupCacheDirectory( "", CacheFilePrefix );
  1009.         NET_ShutdownNetLib(); 
  1010.         delete gNetDriver;
  1011.         gNetDriver = NULL;
  1012.     }
  1013. #else
  1014.     if (!fStartupAborted)
  1015.     {
  1016.         extern const char*    CacheFilePrefix;
  1017.         NET_CleanupCacheDirectory( "", CacheFilePrefix );
  1018.         NET_ShutdownNetLib(); 
  1019.     }
  1020. #endif
  1021.  
  1022.     if (!fStartupAborted)
  1023.         CPrefs::DoWrite();
  1024.         
  1025. #ifdef MOZ_MAIL_NEWS
  1026.         delete mLibMsgPeriodical;
  1027. #endif // MOZ_MAIL_NEWS
  1028.  
  1029.     SetCursor( &qd.arrow );
  1030.  
  1031.     NR_ShutdownRegistry();
  1032.  
  1033.     ET_FinishMocha();
  1034.  
  1035.     LJ_ShutdownJava();
  1036.  
  1037.     DisposeRgn(mMouseRgnH);
  1038.  
  1039.     // Un-init RDF
  1040.     URDFUtilities::ShutdownRDF();
  1041.  
  1042.     sApplication = NULL;
  1043. } // CFrontApp::~CFrontApp()
  1044.  
  1045. //-----------------------------------
  1046. void CFrontApp::Initialize()
  1047. //-----------------------------------
  1048. {
  1049.     // Insert commands to update before seleting menu into list
  1050.     
  1051.     sCommandsToUpdateBeforeSelectingMenu.push_front(cmd_Close);
  1052.     sCommandsToUpdateBeforeSelectingMenu.push_front(cmd_Undo);
  1053.     sCommandsToUpdateBeforeSelectingMenu.push_front(cmd_Cut);
  1054.     sCommandsToUpdateBeforeSelectingMenu.push_front(cmd_Copy);
  1055.     sCommandsToUpdateBeforeSelectingMenu.push_front(cmd_Paste);
  1056.     sCommandsToUpdateBeforeSelectingMenu.push_front(cmd_Clear);
  1057.     sCommandsToUpdateBeforeSelectingMenu.push_front(cmd_SelectAll);
  1058.  
  1059.     new CNSContextCallbacks;
  1060.     LDocApplication::Initialize();
  1061.     
  1062. #ifdef FCAPI
  1063.     // initialization for spiral stuff.....
  1064.     FCInitialize();
  1065. #endif
  1066.     
  1067.     CMouseDispatcher* md = new CMouseDispatcher;
  1068.     AddAttachment(md);
  1069.  
  1070.     // 97-09-11 pchen -- setup prefs proxy for CToolbarModeManager so that knows
  1071.     // how to get Communicator toolbar style pref
  1072.     CMozillaToolbarPrefsProxy* prefsProxy =
  1073.         new CMozillaToolbarPrefsProxy();
  1074.     CToolbarModeManager::SetPrefsProxy(prefsProxy);
  1075.  
  1076.     // Register callback function when browser.chrome.toolbar_style
  1077.     // pref changes
  1078.     PREF_RegisterCallback("browser.chrome.toolbar_style",
  1079.                           CToolbarModeManager::BroadcastToolbarModeChange,
  1080.                           (void*)NULL);
  1081.     // 97-05-12 pkc -- setup sHRes and sVRes data members
  1082.     CGrafPtr wMgrPort;
  1083.     GetCWMgrPort(&wMgrPort);
  1084.     sHRes = (**wMgrPort->portPixMap).hRes / 0x00010000; // convert from Fixed to floating point
  1085.     sVRes = (**wMgrPort->portPixMap).vRes / 0x00010000; // convert from Fixed to floating point
  1086.     
  1087.     // 97-08-23 pchen -- register us as listener to LGrowZone
  1088.     LGrowZone::GetGrowZone()->AddListener(this);
  1089.     
  1090. } // CFrontApp::Initialize()
  1091.         
  1092. void CFrontApp::RegisterMimeType(CMimeMapper * mapper)
  1093. {
  1094.     CMimeMapper::LoadAction loadAction = mapper->GetLoadAction();
  1095.     CStr255 mimeName = mapper->GetMimeName();
  1096.     CStr255 pluginName = mapper->GetPluginName();
  1097.     void* pdesc = nil;
  1098.     if (pluginName.Length() > 0)
  1099.         pdesc = GetPluginDesc(pluginName);
  1100.         
  1101.     switch (loadAction)
  1102.     {
  1103.         case CMimeMapper::Internal:
  1104.             // Disable the previous plug-in, if any
  1105.             if (pdesc)
  1106.                 NPL_EnablePluginType(mimeName, pdesc, false);
  1107. #ifdef OLD_IMAGE_LIB
  1108.             if (mimeName == IMAGE_GIF || mimeName == IMAGE_JPG || mimeName == IMAGE_XBM)
  1109.                 NET_RegisterContentTypeConverter(mimeName, FO_PRESENT, nil, IL_ViewStream);
  1110. #endif
  1111. #ifdef MOZ_MAIL_NEWS // BinHex decoder is in mail/news code, right?
  1112.             else if (mimeName == APPLICATION_BINHEX)
  1113.                 NET_RegisterContentTypeConverter(APPLICATION_BINHEX, FO_PRESENT, nil, fe_MakeBinHexDecodeStream);
  1114. #endif // MOZ_MAIL_NEWS
  1115.             break;
  1116.         
  1117.         case CMimeMapper::Plugin:
  1118.             //
  1119.             // pdesc can be nil when reading prefs on startup -- that's OK,
  1120.             // the plug-in code in mplugin.cp will take care of registration.
  1121.             // bing: Alternatively, we could call NPL_EnablePluginType(true)
  1122.             // here and set up the new description and extensions below.
  1123.             //
  1124.             if (pdesc)
  1125.                 NPL_RegisterPluginType(mimeName, mapper->GetExtensions(), mapper->GetDescription(), nil, pdesc, true);
  1126.             return;        // XP code will take care of the cdata
  1127.             
  1128.         default:
  1129.             // Disable the previous plug-in, if any
  1130.             if (pdesc)
  1131.                 NPL_EnablePluginType(mimeName, pdesc, false);
  1132.             //
  1133.             // NewFilePipe will look at the mapper list and
  1134.             // decide whether it should launch an app or save.
  1135.             //
  1136.             NET_RegisterContentTypeConverter(mimeName, FO_PRESENT,  nil, NewFilePipe);
  1137.             break;
  1138.     }
  1139.         
  1140.     CStr255 extensions = mapper->GetExtensions();
  1141.     CStr255 mimetype = mapper->GetMimeName();
  1142.     NET_cdataCommit(mimetype, extensions);
  1143.     
  1144.     // Special case for View Source
  1145.     // montulli knows why is this
  1146.     if (mimetype == HTML_VIEWER_APPLICATION_MIME_TYPE) {
  1147.         if (loadAction == CMimeMapper::Internal) {
  1148.             NET_RegisterContentTypeConverter (TEXT_HTML, FO_VIEW_SOURCE, NULL, INTL_ConvCharCode);
  1149.              NET_RegisterContentTypeConverter (INTERNAL_PARSER, FO_VIEW_SOURCE,TEXT_HTML, net_ColorHTMLStream);
  1150.             NET_RegisterContentTypeConverter ("*", FO_VIEW_SOURCE, TEXT_PLAIN, net_ColorHTMLStream);
  1151.             NET_RegisterContentTypeConverter (MESSAGE_RFC822, FO_VIEW_SOURCE, NULL, INTL_ConvCharCode);    // added by ftang. copy from libnet #ifdef UNIX
  1152.               NET_RegisterContentTypeConverter (MESSAGE_NEWS, FO_VIEW_SOURCE, NULL, INTL_ConvCharCode);    // added by ftang. copy from libnet #ifdef UNIX
  1153.         }
  1154.         else        // Pipe to disk for launching
  1155.         {
  1156.             NET_RegisterContentTypeConverter (INTERNAL_PARSER, FO_VIEW_SOURCE, nil, NewFilePipe);
  1157.             NET_RegisterContentTypeConverter (TEXT_HTML, FO_VIEW_SOURCE, nil, NewFilePipe);
  1158.             NET_RegisterContentTypeConverter ("*", FO_VIEW_SOURCE, nil, NewFilePipe);
  1159.         }
  1160.     }
  1161.     
  1162.     // We need to add the description, too, which unfortunately requires
  1163.     // looking the cinfo up AGAIN and setting the desc field...
  1164.     char* description = (char*) mapper->GetDescription();
  1165.     XP_ASSERT(description);
  1166.     if (description)
  1167.     {
  1168.         NET_cdataStruct temp;
  1169.         NET_cdataStruct* cdata;
  1170.         char* mimetype = (char*) mimeName;
  1171.         
  1172.         XP_BZERO(&temp, sizeof(temp));
  1173.         temp.ci.type = mimetype;
  1174.         cdata = NET_cdataExist(&temp);
  1175.         XP_ASSERT(cdata);
  1176.         if (cdata)
  1177.             StrAllocCopy(cdata->ci.desc, description);
  1178.     }
  1179. }
  1180.  
  1181.  
  1182. // NetLib Internals!
  1183. extern char * XP_AppName;
  1184. extern char * XP_AppVersion;
  1185. extern char * XP_AppCodeName;
  1186. extern char * XP_AppLanguage;
  1187. extern char * XP_AppPlatform;
  1188.  
  1189. // Creates a path suitable for use by XP_FILE_OPEN, and xpHotlist file spec
  1190.  
  1191. char* GetBookmarksPath( FSSpec& spec, Boolean useDefault )
  1192. {
  1193.     if ( useDefault )
  1194.     {
  1195.         spec = CPrefs::GetFilePrototype( CPrefs::MainFolder );
  1196.         ::GetIndString( spec.name, 300, bookmarkFile );
  1197.     }
  1198.     char* newPath = CFileMgr::GetURLFromFileSpec( spec );
  1199.     if ( newPath )
  1200.         ::BlockMoveData( newPath + 7, newPath, strlen( newPath )-6 );
  1201.     // Hack, gets rid of the file:///
  1202.     return newPath;
  1203. }
  1204.  
  1205. void CFrontApp::InitBookmarks()
  1206. {
  1207.     CBookmarksAttachment *attachment = new CBookmarksAttachment;
  1208.     AddAttachment( attachment ); // Bookmark commands
  1209.  
  1210.     UpdateMenus();
  1211. }
  1212.  
  1213.  
  1214. // static
  1215. int CFrontApp::SetBooleanWithPref(const char *prefName, void *boolPtr)
  1216. {
  1217.     XP_Bool    currentValue = *(Boolean *)boolPtr;
  1218.     PREF_GetBoolPref(prefName, ¤tValue);
  1219.     *(Boolean *)boolPtr = currentValue;
  1220.     return 0;
  1221. }
  1222.  
  1223. // This is called right after startup for us to do our initialization. If
  1224. // the user wants to open/print a document then this will be the file
  1225. // spec. Otherwise it's nil (normal startup)
  1226. void CFrontApp::ProperStartup( FSSpec* file, short fileType ) 
  1227. {
  1228.     LFile*        prefsFile = NULL;
  1229.     Boolean        gotPrefsFile = false;
  1230.     static        properStartup = FALSE;
  1231.     
  1232.     if ( fStartupAborted )
  1233.         return;
  1234.     
  1235.     if ( properStartup )
  1236.     {
  1237.         if ( fileType == FILE_TYPE_ODOC || fileType == FILE_TYPE_GETURL )
  1238.             DoOpenDoc( file, fileType );
  1239.         
  1240.         // Cannot open the Profile Manager while app is running
  1241.         if ( (fileType == FILE_TYPE_PROFILES ) 
  1242.             || (fileType == STARTUP_TYPE_NETPROFILE) )
  1243.             ErrorManager::PlainAlert(ERROR_OPEN_PROFILE_MANAGER);
  1244.  
  1245.         return;
  1246.     }
  1247.         
  1248.     properStartup = TRUE;
  1249.     
  1250.     // Initialize all the modules,
  1251.     // Read generic prefs (which will LoadState all the modules)
  1252.     // Then start the modules and managers
  1253.     
  1254.     NET_InitFileFormatTypes(NULL, NULL);    // Needs to be initialized before prefs are read in.
  1255.     SECNAV_InitConfigObject();                // ditto
  1256.  
  1257.     CPrefs::PrefErr abortStartup = CPrefs::eOK;
  1258.     SplashProgress( GetPString(MAC_PROGRESS_PREFS));
  1259.     
  1260.     if ((fileType == FILE_TYPE_PREFS) && file) {
  1261.         gotPrefsFile = true;
  1262.         prefsFile = new LFile(*file);
  1263.     }
  1264.  
  1265.     // Once we get to this point it's safe to quit
  1266.     fSafeToQuit = true;
  1267.  
  1268.     abortStartup = CPrefs::DoRead( prefsFile, fileType );
  1269.     
  1270.     if (( abortStartup == CPrefs::eAbort ) || fUserWantsToQuit)
  1271.     {
  1272.         fStartupAborted = true;
  1273.         DoQuit();
  1274.         return;
  1275.     }
  1276.  
  1277.     if ( fileType == FILE_TYPE_ASW && file )
  1278.         abortStartup = CPrefs::eRunAccountSetup;
  1279.         
  1280.     XP_Bool startupFlag;
  1281.     mHasFrontierMenuSharing = (!(PREF_GetBoolPref("browser.mac.no_menu_sharing", &startupFlag) == PREF_NOERROR && startupFlag));
  1282.     mHasBookmarksMenu = (!(PREF_GetBoolPref("browser.mac.no_bookmarks_menu", &startupFlag) == PREF_NOERROR && startupFlag));
  1283.  
  1284.     // do this after we read prefs
  1285. #ifdef MOZ_MAIL_NEWS
  1286.     // check to see what mail.server_type is and what mail.server_type_on_restart is
  1287.     // must be careful because our auto admin tool may have created a "Big Brother"
  1288.     // preference file that locks mail.server_type. if this is the case we must
  1289.     // discard whatever mail.server_type_on_restart is. if the admin hasn't
  1290.     // locked this preference then we use mail.server_type_on_restart (this is what
  1291.     // gets set in the preference dialog)
  1292.     int32    mailServerType, mailServerTypeOnRestart;
  1293.     PREF_GetIntPref("mail.server_type" , &mailServerType);
  1294.     PREF_GetIntPref("mail.server_type_on_restart" , &mailServerTypeOnRestart);
  1295.     
  1296.     if (-1 == mailServerTypeOnRestart)
  1297.         PREF_SetIntPref("mail.server_type_on_restart" , mailServerType);
  1298.     if (PREF_PrefIsLocked("mail.server_type"))
  1299.         PREF_SetIntPref("mail.server_type_on_restart" , mailServerType);
  1300.     else
  1301.         PREF_SetIntPref("mail.server_type" , mailServerTypeOnRestart);
  1302. #endif // MOZ_MAIL_NEWS
  1303.  
  1304.     // Set the state of network.online to match offline.startup_mode
  1305.     Int32 startupNetworkState;
  1306.     enum {kOnlineState, kOfflineState, kAskUserForState};
  1307.     PREF_GetIntPref("offline.startup_mode" , &startupNetworkState);
  1308.     switch (startupNetworkState)
  1309.     {
  1310.         case kOnlineState:
  1311.             PREF_SetBoolPref("network.online" , true);
  1312.             break;
  1313.         
  1314.         case kOfflineState:
  1315.             PREF_SetBoolPref("network.online" , false);
  1316.             break;
  1317.         
  1318.         case kAskUserForState:
  1319.                     {
  1320.                         XP_Bool    onlineLastTime;
  1321.                         PREF_GetBoolPref("network.online" , &onlineLastTime);
  1322.                         XP_Bool locked = PREF_PrefIsLocked("offline.startup_mode");
  1323.  
  1324.                         enum
  1325.                         {
  1326.                             eAskMeDialog = 12009,
  1327.                             eWorkOnline,
  1328.                             eWorkOffline,
  1329.                             eSetPref
  1330.                         };
  1331.  
  1332.                         StDialogHandler    handler(eAskMeDialog, nil);
  1333.                         LWindow            *dialog = handler.GetDialog();
  1334.                         LGARadioButton    *onRButton =
  1335.                             (LGARadioButton *)dialog->FindPaneByID(eWorkOnline);
  1336.                         XP_ASSERT(onRButton);
  1337.                         LGARadioButton    *offRButton =
  1338.                             (LGARadioButton *)dialog->FindPaneByID(eWorkOffline);
  1339.                         XP_ASSERT(offRButton);
  1340.                         if (onlineLastTime)
  1341.                         {
  1342.                             onRButton->SetValue(true);
  1343.                         }
  1344.                         else
  1345.                         {
  1346.                             offRButton->SetValue(true);
  1347.                         }
  1348.                         LGACheckbox *setPrefBox =
  1349.                             (LGACheckbox *)dialog->FindPaneByID(eSetPref);
  1350.                         XP_ASSERT(setPrefBox);
  1351.                         if (locked)
  1352.                         {
  1353.                             setPrefBox->Disable();
  1354.                         }
  1355.                         // Run the dialog
  1356.                         MessageT message = msg_Nothing;
  1357.                         do
  1358.                         {
  1359.                             message = handler.DoDialog();
  1360.                         } while (msg_OK != message);
  1361.                         XP_Bool    goOnline = onRButton->GetValue();
  1362.                         if (setPrefBox->GetValue())
  1363.                         {
  1364.                             int32    newPrefValue =    goOnline ?
  1365.                                                     kOnlineState:
  1366.                                                     kOfflineState;
  1367.                             PREF_SetIntPref("offline.startup_mode", newPrefValue);
  1368.                         }
  1369.                         if (goOnline)
  1370.                         {
  1371.                             PREF_SetBoolPref("network.online" , true);
  1372.                         }
  1373.                         else
  1374.                         {
  1375.                             PREF_SetBoolPref("network.online" , false);
  1376.                         }
  1377.                     }
  1378.             break;
  1379.     }
  1380.     
  1381.     SetBooleanWithPref("security.enable_java", &mJavaEnabled);
  1382.     PREF_RegisterCallback("security.enable_java",
  1383.                           SetBooleanWithPref,
  1384.                           (void*)&mJavaEnabled);
  1385.  
  1386.     // Set CSharedPatternWorld::sUseUtilityPattern from pref
  1387.     XP_Bool    useUtilityPattern;
  1388.     int    prefResult = PREF_GetBoolPref("browser.mac.use_utility_pattern", &useUtilityPattern);
  1389.     if (prefResult == PREF_NOERROR && useUtilityPattern)
  1390.     {
  1391.         // Just for grins, check to see if utility pattern exists
  1392.         PixPatHandle thePattern = NULL;
  1393.         thePattern = ::GetPixPat(cUtilityPatternResID);
  1394.         if (thePattern)
  1395.         {
  1396.             CSharedPatternWorld::sUseUtilityPattern = true;
  1397.             ::DisposePixPat(thePattern);
  1398.         }
  1399.     }
  1400.  
  1401.     // Install Help and Directory menus
  1402.     InstallMenus();
  1403.     
  1404.     // Polaris: remove Calendar/3270 items if they're not installed
  1405.     //    (?? maybe these are always available for Polaris (autoadmin lib)
  1406.     //    so users get helpful error messages if they try them..?)
  1407.     if (CWindowMenu::sWindowMenu)
  1408.     {
  1409.         FSSpec fspec;
  1410.             
  1411.         if ( CFileMgr::FindApplication(kCalendarAppSig, fspec) != noErr )
  1412.             (CWindowMenu::sWindowMenu)->RemoveCommand(cmd_LaunchCalendar);
  1413.             
  1414.         if ( ! Find3270Applet(fspec) )
  1415.             (CWindowMenu::sWindowMenu)->RemoveCommand(cmd_Launch3270);
  1416.  
  1417.         if ( ! FE_IsNetcasterInstalled() ) {
  1418.             (CWindowMenu::sWindowMenu)->RemoveCommand(cmd_LaunchNetcaster);
  1419.         }
  1420.  
  1421.     }
  1422.     
  1423.     // NETLIB wait until we've read prefs to determine what to set up
  1424.     CStr255        tmp;
  1425.     
  1426.     //    It is a good idea to allocate enough space for strings.  
  1427.     //    Before today, we were not doing so.  This was evil...
  1428.     //    So, XP_ALLOC now takes tmp.Length() + 1 as an argument
  1429.     //    instead of XP_ALLOC.
  1430.     //    dkc    1/25/96
  1431.     
  1432.     ::GetIndString( tmp, ID_STRINGS, APPNAME_STRING_INDEX );
  1433.     XP_AppName = (char*)XP_ALLOC( tmp.Length() + 1);
  1434.     sprintf( XP_AppName, tmp );
  1435.     
  1436.     ::GetIndString( tmp, ID_STRINGS, APPLANGUAGE_STRING_INDEX );
  1437.     XP_AppLanguage = (char*)XP_ALLOC( tmp.Length() + 1);
  1438.     sprintf( XP_AppLanguage, tmp );
  1439.     
  1440.     ::GetIndString( tmp, ID_STRINGS, APPVERSION_STRING_INDEX );
  1441.     // Admin Kit: support optional user-agent suffix
  1442.     {
  1443.         char* suffix;
  1444.         if ( PREF_CopyConfigString("user_agent", &suffix) == PREF_NOERROR )
  1445.         {
  1446.             tmp = tmp + "C-" + suffix;
  1447.             XP_FREE(suffix);
  1448.         }
  1449.     }
  1450.     
  1451.     CStr255        tmp2;
  1452. #ifdef powerc
  1453.     ::GetIndString( tmp2, ID_STRINGS, USERAGENT_PPC_STRING_INDEX );
  1454. #else
  1455.     ::GetIndString( tmp2, ID_STRINGS, USERAGENT_68K_STRING_INDEX );
  1456. #endif
  1457.     tmp = tmp + " ";
  1458.     tmp = tmp + tmp2;
  1459.     
  1460.     char*        securityText = "X";
  1461.     
  1462.     XP_AppVersion = (char*)XP_ALLOC( tmp.Length() + strlen( securityText )  + 1);
  1463.     sprintf( XP_AppVersion, tmp, securityText );
  1464.     
  1465.     ::GetIndString( tmp2, ID_STRINGS, APPCODENAME_STRING_INDEX );
  1466.     XP_AppCodeName = (char*)XP_ALLOC( tmp2.Length()  + 1);
  1467.     sprintf( XP_AppCodeName, tmp2 );
  1468.  
  1469. #ifdef powerc
  1470.     XP_AppPlatform = "MacPPC";
  1471. #else
  1472.     XP_AppPlatform = "Mac68k";
  1473. #endif
  1474.     
  1475.     SplashProgress( GetPString(MAC_PROGRESS_NET) );
  1476.     
  1477.     NET_InitNetLib (CPrefs::GetLong( CPrefs::BufferSize ), CPrefs::GetLong( CPrefs::Connections ) );
  1478.     NET_ChangeMaxNumberOfConnections(50);
  1479.     RNG_SystemInfoForRNG();
  1480.  
  1481.     // 1998.01.12 pchen and 1998.02.23 rjc
  1482.     // RDF now uses NetLib.  Netlib initializes history.  RDF reimplements
  1483.     // history.  Looks like History initialization has been changed to work
  1484.     // correctly. Also, GH_InitGlobalHistory() can be safely called twice. 
  1485.     URDFUtilities::StartupRDF(); 
  1486.  
  1487.     SECNAV_Init();
  1488.     SECNAV_RunInitialSecConfig();        // call after SECNAV_Init()
  1489.     
  1490.     // Must not call XP_SecurityVersion before SECNAV_Init().
  1491.     securityText = XP_SecurityVersion( 0 );
  1492.     XP_FREE(XP_AppVersion);
  1493.     XP_AppVersion = (char*)XP_ALLOC( tmp.Length() + strlen( securityText )  + 1);
  1494.     sprintf( XP_AppVersion, tmp, securityText );
  1495.     
  1496.     NET_ReadNewsrcFileMappings();
  1497.  
  1498.     SplashProgress(  GetPString(MAC_PROGRESS_BOOKMARK));
  1499.     InitBookmarks();
  1500.     // create the object that makes sure personal toolbars are in sync. This must be done after
  1501.     // prefs are loaded and after bookmarks are initialized.
  1502.     sPersonalToolbarManager = new CPersonalToolbarManager;
  1503.  
  1504.     
  1505.     //    Create the NSPR event queue
  1506.     
  1507.     mozilla_event_queue = PR_CreateEventQueue("Mozilla Event Queue", mozilla_thread);
  1508.  
  1509.     LM_InitMocha();        // mocha, mocha, mocha
  1510.     NPL_Init();            // plugins
  1511.  
  1512.     // The tools menus must be created after the plugins are read in.
  1513.     
  1514. #ifdef EDITOR
  1515.     CToolsAttachment *attachment = new CToolsAttachment;
  1516.     if ( attachment )
  1517.         AddAttachment( attachment ); // Tools menu
  1518.     CFontMenuAttachment *fontattachment = new CFontMenuAttachment;
  1519.     if ( fontattachment )
  1520.         AddAttachment( fontattachment ); // Font menu
  1521.     CRecentEditMenuAttachment *recentattachment = new CRecentEditMenuAttachment;
  1522.     if ( recentattachment )
  1523.         AddAttachment( recentattachment );
  1524. #endif // EDITOR
  1525.     UpdateMenus();
  1526.  
  1527. #if defined (JAVA)
  1528.     //    Initialize the java runtime, start the MToolkit thread running
  1529.     //    to keep the network alive.  For now, we have to temporarily
  1530.     //    enable java to make sure that the runtime bootstraps itself
  1531.     //    minimally.
  1532.     //    dkc 3-18-96
  1533.     
  1534.     this->SplashProgress(  GetPString(MAC_PROGRESS_JAVAINIT));
  1535.     
  1536.     LJ_SetJavaEnabled((PRBool)CPrefs::GetBoolean(CPrefs::EnableJava));
  1537. #endif /* defined (JAVA) */
  1538.  
  1539. #if defined(EDITOR) && defined(MOZ_JAVA)
  1540.     EDTPLUG_RegisterEditURLCallback(&OpenEditURL);
  1541. #endif // EDITOR && MOZ_JAVA
  1542.  
  1543.     /*    Okay, this is hacky, but necessary.  It is extremely
  1544.         important that the Macintosh reclaims memory.  So,
  1545.         we want the finalizer to be at as high a priority as
  1546.         possible. */    
  1547.  
  1548.     if ((PR_GetGCInfo() != NULL) && (PR_GetGCInfo()->finalizer != NULL))
  1549. #ifndef NSPR20
  1550.         PR_SetThreadPriority(PR_GetGCInfo()->finalizer, 31);
  1551. #else
  1552.         PR_SetThreadPriority(PR_GetGCInfo()->finalizer, PR_PRIORITY_URGENT);
  1553. #endif
  1554.  
  1555.     DestroySplashScreen();
  1556.     if ( abortStartup == CPrefs::eRunAccountSetup )
  1557.         file = NULL;
  1558.         
  1559.     Boolean agreedToLicense = AgreedToLicense( file, fileType );
  1560.     
  1561.     if ( abortStartup == CPrefs::eRunAccountSetup )
  1562.         LaunchAccountSetup();
  1563.  
  1564. #ifdef MOZ_MAIL_NEWS
  1565.     // This is for Biff notification.
  1566.     // It should come after menus and after prefs are read in and probably
  1567.     // after the online/offline determination is made.
  1568.     CCheckMailContext::Initialize(this); // we are the owner/user
  1569. #endif // MOZ_MAIL_NEWS
  1570. #ifdef MOZ_LOC_INDEP
  1571.     InitializeLocationIndependence();
  1572. #endif
  1573. #ifdef MOZ_MAIL_NEWS
  1574. //    SplashProgress( GetPString(MAC_PROGRESS_ADDRESS) );
  1575.     CAddressBookManager::OpenAddressBookManager();
  1576. #endif // MOZ_MAIL_NEWS
  1577.     if (agreedToLicense)
  1578.         CreateStartupEnvironment(! gotPrefsFile);
  1579.     
  1580.     fProperStartup = true;        
  1581. }    // CFrontApp::ProperStartup
  1582.  
  1583.  
  1584. Boolean CFrontApp::AgreedToLicense( FSSpec* fileSpec, short fileType )
  1585. {
  1586.     // ML License clicker moved to installer so just open
  1587.     DoOpenDoc( fileSpec, fileType );
  1588.         
  1589.     return true;
  1590. }
  1591.         
  1592.     
  1593.     
  1594. // Called when application starts up without any documents
  1595. // Reads in the default preferences doc, and then creates a default browser window
  1596. void CFrontApp::StartUp()
  1597. {
  1598.     ProperStartup( NULL, FILE_TYPE_NONE );
  1599. //    CMailNewsFolderWindow::FindAndShow(true);
  1600. }
  1601.  
  1602.  
  1603. pascal void colorPopupMDEFProc(short message, MenuHandle theMenu, 
  1604.         Rect *menuRect, Point hitPt, short *whichItem);
  1605.  
  1606. // openStartupWindows is only false if we started comm from a desktop icon
  1607. // and don't want the prefs-specified components to open up
  1608. void CFrontApp::CreateStartupEnvironment(Boolean openStartupWindows)
  1609. {
  1610. #ifdef EDITOR
  1611.     // Composer's color picker MDEF
  1612.     Handle        stubMDEFH;
  1613.     MenuDefUPP    colorMdefUPP;
  1614.  
  1615.     // load/lock (but DON'T detach) MDEF stub and set it to call appropriate routine
  1616.     if ( (stubMDEFH = Get1Resource( 'MDEF', 20000 )) != NULL)
  1617.     {
  1618.         HNoPurge((Handle)stubMDEFH);
  1619.         HUnlock((Handle)stubMDEFH);
  1620.         MoveHHi((Handle)stubMDEFH);
  1621.         HLock((Handle)stubMDEFH);
  1622.         if ( (colorMdefUPP = NewMenuDefProc(colorPopupMDEFProc)) != NULL)
  1623.         {
  1624.             *(ProcPtr *)(*stubMDEFH + 6L) = (ProcPtr)colorMdefUPP;
  1625.         }
  1626.     }
  1627. #endif
  1628.  
  1629.     XP_Bool startupFlag;
  1630.  
  1631.     // handle new startup preferences
  1632.     CommandT command = cmd_Nothing;
  1633.     // check to see if we need to bring up a new browser window at startup
  1634.     if (PREF_GetBoolPref("general.startup.browser", &startupFlag) == PREF_NOERROR)
  1635.     {
  1636.         if (startupFlag)
  1637.         {
  1638.             // Only create a new browser window if the startupFlag indicates
  1639.             // that we should and there are no delayed URLs (which could happen
  1640.             // if a 'GURL' or 'OURL' event is handled while the profile dialog
  1641.             // or license dialog is waiting to be dismissed) and there are no
  1642.             // open browser windows (which could happen if an 'odoc' event
  1643.             // was processed prior to CreateStartupEnvironment being called).
  1644.             // These guards will ensure that we don't open any unnecessary blank
  1645.             // browser windows at startup.
  1646.             
  1647.             CMediatedWindow* window = CWindowMediator::GetWindowMediator()->FetchTopWindow(
  1648.                                                                 WindowType_Browser,
  1649.                                                                 regularLayerType,
  1650.                                                                 true);
  1651.             UInt32 howMany = CURLDispatcher::CountDelayedURLs();
  1652.             if (openStartupWindows && !window && !CURLDispatcher::CountDelayedURLs())
  1653.                 MakeNewDocument();
  1654.         }
  1655.     }
  1656.     if (PREF_GetBoolPref("general.startup.netcaster", &startupFlag) == PREF_NOERROR)
  1657.     {
  1658.         if (openStartupWindows && startupFlag)
  1659.             ObeyCommand(cmd_LaunchNetcaster, NULL);
  1660.     }
  1661.     
  1662.     startupFlag = false;
  1663.     if (HasFrontierMenuSharing())
  1664.     {
  1665.         AddAttachment(new LMenuSharingAttachment( msg_AnyMessage, TRUE, MENU_SHARING_FIRST ) ); // Menu Sharing
  1666.     }
  1667.     
  1668. #ifdef MOZ_MAIL_NEWS
  1669.     // check to see if we need to bring up mail window at startup
  1670.     if (PREF_GetBoolPref("general.startup.mail", &startupFlag) == PREF_NOERROR)
  1671.     {
  1672.         if (openStartupWindows && startupFlag)
  1673.             ObeyCommand(cmd_Inbox, NULL);
  1674.     }
  1675.     // check to see if we need to bring up news window at startup
  1676.     if (PREF_GetBoolPref("general.startup.news", &startupFlag) == PREF_NOERROR)
  1677.     {
  1678.         if (openStartupWindows && startupFlag)
  1679.             ObeyCommand(cmd_NewsGroups, NULL);
  1680.     }
  1681. #endif // MOZ_MAIL_NEWS
  1682. #ifdef EDITOR
  1683.     // check to see if we need to bring up an editor window at startup
  1684.     if (PREF_GetBoolPref("general.startup.editor", &startupFlag) == PREF_NOERROR)
  1685.     {
  1686.         if (openStartupWindows && startupFlag)
  1687.             ObeyCommand(cmd_NewWindowEditor, NULL);
  1688.     }
  1689. #endif
  1690. #if !defined(MOZ_LITE) && !defined(MOZ_MEDIUM)
  1691.     // check to see if we need to launch conference at startup
  1692.     if (PREF_GetBoolPref("general.startup.conference", &startupFlag) == PREF_NOERROR)
  1693.     {
  1694.         if (openStartupWindows && startupFlag)
  1695.             ObeyCommand(cmd_LaunchConference, NULL);
  1696.     }
  1697.     // check to see if we need to launch calendar at startup
  1698.     if (PREF_GetBoolPref("general.startup.calendar", &startupFlag) == PREF_NOERROR)
  1699.     {
  1700.         if (openStartupWindows && startupFlag)
  1701.             ObeyCommand(cmd_LaunchCalendar, NULL);
  1702.     }
  1703. #endif // !MOZ_LITE && !MOZ_MEDIUM
  1704. #ifdef MOZ_TASKBAR
  1705.     if (PREF_GetBoolPref("taskbar.mac.is_open", &startupFlag) == PREF_NOERROR)
  1706.     {
  1707.         if (openStartupWindows && startupFlag)
  1708.             ObeyCommand(cmd_ToggleTaskBar, NULL);
  1709.     }
  1710. #endif // MOZ_TASKBAR
  1711. }
  1712.  
  1713. // OpenDocument asserts that there is a preference document read in,
  1714. // because we cannot do any document operations before preferences are
  1715. // initialized. Pref documents are read automatically in assertion
  1716. // Hyper document is read in here
  1717. void CFrontApp::OpenDocument( FSSpec* inFileSpec )
  1718. {
  1719.     FInfo        fndrInfo;
  1720.     short        fileType;
  1721.     
  1722.     OSErr err = ::FSpGetFInfo( inFileSpec, &fndrInfo );
  1723.     //what to do on error?
  1724.     
  1725.     // Ñ╩how silly is this?
  1726.     if ( emPrefsType == fndrInfo.fdType )
  1727.         fileType = FILE_TYPE_PREFS;
  1728.     else if ( emProfileType == fndrInfo.fdType )
  1729.         fileType = FILE_TYPE_PROFILES;
  1730.     else if ( 'ASWl' == fndrInfo.fdType )
  1731.         fileType = FILE_TYPE_ASW;
  1732.     else if (emNetprofileType == fndrInfo.fdType)
  1733.         fileType = STARTUP_TYPE_NETPROFILE;
  1734.     else
  1735.         fileType = FILE_TYPE_ODOC;
  1736.         
  1737.     ProperStartup( inFileSpec, fileType );
  1738. }
  1739.  
  1740. void CFrontApp::DoOpenDoc( FSSpec* inFileSpec, short fileType )
  1741. {
  1742.     switch ( fileType )
  1743.     {
  1744.         case FILE_TYPE_ODOC:
  1745.             if ( inFileSpec )
  1746.                 OpenLocalURL(inFileSpec );
  1747.             break;
  1748.         case FILE_TYPE_PREFS:
  1749.         case FILE_TYPE_PROFILES:
  1750.             break;
  1751.         case FILE_TYPE_GETURL:
  1752.         case FILE_TYPE_NONE:
  1753.             break;
  1754.     }
  1755. }
  1756.  
  1757. // Opens up a bookmark file
  1758. void CFrontApp::OpenBookmarksFile( FSSpec* inFileSpec, CBrowserWindow * /*win*/, Boolean /*delayed*/)
  1759. {
  1760.     Try_
  1761.     {
  1762.         vector<char> url(500);
  1763.         OSErr err = ReadBookmarksFile(url, *inFileSpec);
  1764.         ThrowIfOSErr_(err);
  1765.         
  1766.         URL_Struct * request = NET_CreateURLStruct( url.begin(), NET_DONT_RELOAD );
  1767.         CURLDispatcher::DispatchURL(request, NULL);    
  1768.     }
  1769.     Catch_(inErr)
  1770.     {}
  1771.     EndCatch_
  1772. }
  1773.  
  1774.  
  1775. // Opens a local file. If it is a bookmark, load the URL stored in it
  1776. void CFrontApp::OpenLocalURL( FSSpec* inFileSpec , 
  1777.                             CBrowserWindow * win, 
  1778.                             char * mime_type, 
  1779.                             Boolean delayed)
  1780. {
  1781.     if (inFileSpec == NULL)
  1782.         return;
  1783.     Boolean dummy, dummy2;
  1784.     
  1785. // Resolve the aliases
  1786.     OSErr err = ::ResolveAliasFile(inFileSpec,TRUE,&dummy,&dummy2);
  1787.     
  1788. // If we are a bookmark file, open a bookmark
  1789.     FInfo info;
  1790.     err = ::FSpGetFInfo (inFileSpec, &info);
  1791.     if ((info.fdType == emBookmarkFile) && (mime_type == NULL))
  1792.     {
  1793.         OpenBookmarksFile( inFileSpec, win, delayed);
  1794.         return;
  1795.     }
  1796.  
  1797. // If we are a help file, open a help document
  1798.     if ((info.fdType == emHelpType)  && (mime_type == NULL))
  1799.     {
  1800.         char * help_id = NULL;
  1801.         char * map_file_url = CFileMgr::GetURLFromFileSpec(*inFileSpec);
  1802.  
  1803.         DebugStr("\pNot implemented");
  1804. //ÑÑÑ        NET_GetHTMLHelpFileFromMapFile(*CBookmarksContext::GetInstance(),    // Will this work?
  1805. //ÑÑÑ                              map_file_url, help_id, NULL);
  1806.         FREEIF( help_id );
  1807.         FREEIF( map_file_url );
  1808.         return;
  1809.     }
  1810.     
  1811. // Open it by loading the URL into specified window
  1812.  
  1813.     char*        localURL;
  1814.     if (win == NULL)
  1815.         win = CBrowserWindow::FindAndPrepareEmpty(true);
  1816.     if (win != NULL)
  1817.     {
  1818.         localURL = CFileMgr::GetURLFromFileSpec(*inFileSpec);
  1819.         URL_Struct * request = NET_CreateURLStruct (localURL, NET_DONT_RELOAD);
  1820.         if (localURL)
  1821.             XP_FREE(localURL);
  1822.         ThrowIfNil_(request);
  1823.         request->content_type = mime_type;
  1824. //        if (delayed)
  1825. //            win->StartLatentLoading(request);
  1826. //        else
  1827. //            win->StartLoadingURL (request, FO_CACHE_AND_PRESENT);
  1828.         // FIX ME!!! Hook up latent loading!!!
  1829.         CBrowserContext* theContext = (CBrowserContext*)win->GetWindowContext();
  1830.         theContext->SwitchLoadURL(request, FO_CACHE_AND_PRESENT);
  1831.     }
  1832. }
  1833.     
  1834. void CFrontApp::PrintDocument(FSSpec* inFileSpec)
  1835. {
  1836.     ProperStartup( inFileSpec, FILE_TYPE_ODOC );
  1837.     PrintDocument( inFileSpec );
  1838. }
  1839.  
  1840. // ---------------------------------------------------------------------------
  1841. //        Ñ ClickMenuBar
  1842. // ---------------------------------------------------------------------------
  1843. //    Respond to a mouse click in the menu bar.
  1844. //
  1845. //    Also, we do a targeted update of menus before calling MenuSelect
  1846.  
  1847. void
  1848. CFrontApp::ClickMenuBar(
  1849.     const EventRecord&    inMacEvent)
  1850. {
  1851.     StUnhiliteMenu    unhiliter;            // Destructor unhilites menu title
  1852.     Int32            menuChoice;
  1853.  
  1854.     CTargetedUpdateMenuRegistry::SetCommands(sCommandsToUpdateBeforeSelectingMenu);
  1855.     CTargetedUpdateMenuRegistry::UpdateMenus();
  1856.  
  1857.     CommandT        menuCmd = LMenuBar::GetCurrentMenuBar()->
  1858.                                 MenuCommandSelection(inMacEvent, menuChoice);
  1859.     
  1860.     if (menuCmd != cmd_Nothing) {
  1861.         SignalIf_(LCommander::GetTarget() == nil);
  1862.         LCommander::SetUpdateCommandStatus(true);
  1863.         LCommander::GetTarget()->ProcessCommand(menuCmd, &menuChoice);
  1864.     }
  1865. }
  1866.  
  1867. // ---------------------------------------------------------------------------
  1868. //        Ñ UpdateMenus
  1869. // ---------------------------------------------------------------------------
  1870. //    Update the status of all menu items
  1871. //
  1872. //    General Strategy:
  1873. //    (1) Designate every Menu as "unused".
  1874. //    (2) Iterate through all menu commands, asking the Target chain for
  1875. //        the status of each one. Enable/Disable, mark, and adjust the
  1876. //        name of each menu accordingly. Enabling any item in a Menu
  1877. //        designates that Menu as "used".
  1878. //    (3)    Iterate through each menu, asking for the status of a special
  1879. //        synthetic command that indicates the entire menu. At this time,
  1880. //        Commanders can perform operations that affect the menu as a whole.
  1881. //        Menus that are desinated "used" are enabled; "unused" ones
  1882. //        are disabled.
  1883. //
  1884. //    Changes from LEventDispatcher::UpdateMenus():
  1885. //
  1886. //        - We maintain a list of commands to update and a bool to indicate
  1887. //          whether to update just those commands or all commands. This is 
  1888. //          useful for targeting specific commands to update without having
  1889. //          to pay the price for updating hundreds of commands. The registry
  1890. //          of commands is maintained separately from CFrontApp. The general
  1891. //          pattern is that the client which calls UpdateMenus will stuff
  1892. //          it's commands in the registry and then call UpdateMenus.
  1893. //
  1894. //          One limitation of this targeted updating is that it is possible
  1895. //          that a menu which should be disabled because there are no enabled
  1896. //          items might still be enabled. However, given that the typical
  1897. //
  1898. //        - We call UpdateMenusSelf() to get some more work done.
  1899. //
  1900. //        - We cache some stuff during UpdateMenus
  1901.  
  1902. void
  1903. CFrontApp::UpdateMenus()
  1904. {
  1905. #ifdef PROFILE_UPDATE_MENUS
  1906.     StProfileSection profileThis("\pprofile", 1000, 100);
  1907. #endif
  1908.  
  1909.     // UDesktop::StUseFrontWindowIsModalCache theFrontWindowIsModalCache;
  1910.  
  1911. #ifdef EDITOR
  1912.     CAutoPtr<CEditView::StUseCharFormattingCache> stCharCache;
  1913.  
  1914.     CEditView *editViewCommander = dynamic_cast<CEditView *>(LCommander::GetTarget());
  1915.     if ( editViewCommander )
  1916.         stCharCache.reset(new CEditView::StUseCharFormattingCache(*editViewCommander));
  1917. #endif
  1918.  
  1919.     LMenuBar    *theMenuBar = LMenuBar::GetCurrentMenuBar();
  1920.     Int16        menuItem;
  1921.     MenuHandle    macMenuH = nil;
  1922.     LMenu        *theMenu;
  1923.     CommandT    theCommand;
  1924.     Boolean        isEnabled;
  1925.     Boolean        usesMark;
  1926.     Char16        mark;
  1927.     Str255        itemName;    
  1928.     LCommander    *theTarget = LCommander::GetTarget();
  1929.     
  1930.     theMenu = nil;                    // Designate each menu as "unused"
  1931.     while (theMenuBar->FindNextMenu(theMenu)) {
  1932.         theMenu->SetUsed(false);
  1933.     }
  1934.         
  1935.                                     // Loop thru each menu item that has an
  1936.                                     //   associated command
  1937.     while (theMenuBar->FindNextCommand(menuItem, macMenuH,
  1938.                                         theMenu, theCommand)) {
  1939.                                         
  1940.                                     // Don't change menu item state for
  1941.                                     //   special commands (all negative
  1942.                                     //   values except cmd_UseMenuItem)
  1943.                                     //   or for commands which are not
  1944.                                     //   in the registry when we are
  1945.                                     //   supposed to only update commands
  1946.                                     //   which are in the registry.
  1947.         if ((theCommand > 0 || theCommand == cmd_UseMenuItem) &&
  1948.             (!CTargetedUpdateMenuRegistry::UseRegistryToUpdateMenus() ||
  1949.               CTargetedUpdateMenuRegistry::CommandInRegistry(theCommand)))
  1950.         {
  1951.         
  1952.                                     // For commands that depend on the menu
  1953.                                     //   item, get synthetic command number
  1954.             if (theCommand == cmd_UseMenuItem) {
  1955.                 theCommand = theMenu->SyntheticCommandFromIndex(menuItem);
  1956.             }
  1957.  
  1958.                                     // Ask Target if command is enabled,
  1959.                                     //   if the menu item should be marked,
  1960.                                     //   and if the name should be changed
  1961.             isEnabled = false;
  1962.             usesMark = false;
  1963.             itemName[0] = 0;
  1964.             
  1965.             if (theTarget != nil) {
  1966.                 theTarget->ProcessCommandStatus(theCommand, isEnabled,
  1967.                                         usesMark, mark, itemName);
  1968.             }
  1969.             
  1970.                 // Adjust the state of each menu item as needed.
  1971.                 // Also designate as "used" the Menu containing an
  1972.                 // enabled item.
  1973.             
  1974.             if (isEnabled) {
  1975.                 ::EnableItem(macMenuH, menuItem);
  1976.                 theMenu->SetUsed(true);
  1977.             } else {
  1978.                 ::DisableItem(macMenuH, menuItem);
  1979.             }
  1980.             
  1981.             if (usesMark) {
  1982.                 ::SetItemMark(macMenuH, menuItem, mark);
  1983.             }
  1984.             
  1985.             if (itemName[0] > 0) {
  1986.                 ::SetMenuItemText(macMenuH, menuItem, itemName);
  1987.             }
  1988.             
  1989.         } else if (theCommand < 0 || CTargetedUpdateMenuRegistry::UseRegistryToUpdateMenus()) {
  1990.                                     // Don't change state of items with
  1991.                                     //   negative command numbers or
  1992.                                     //   when the registry is in use.
  1993.             if (theMenu->ItemIsEnabled(menuItem)) {
  1994.                 theMenu->SetUsed(true);
  1995.             }
  1996.             
  1997.         } else {                    // Item has command number 0
  1998.             ::DisableItem(macMenuH, menuItem);
  1999.         }
  2000.             
  2001.     }
  2002.     
  2003.     if (theTarget != nil) {
  2004.                                     // Loop thru each menu
  2005.         theMenu = nil;
  2006.         while (theMenuBar->FindNextMenu(theMenu)) {
  2007.         
  2008.                 // The "command" for an entire Menu is the synthetic command
  2009.                 // number for item zero (negative number that has the Menu ID
  2010.                 // in the high word and 0 in the low word.
  2011.  
  2012.             theCommand = theMenu->SyntheticCommandFromIndex(0);
  2013.             
  2014.                 // The Target chain now has the opportunity to do something
  2015.                 // to the Menu as a whole, as a call for this special
  2016.                 // synthetic command is made only once for each menu.
  2017.                 // For example, a text handling Commander could put a check
  2018.                 // mark next to the current font in a Fonts menu.
  2019.                 //
  2020.                 // The isEnabled parameter [outEnabled as an argument to
  2021.                 // FindCommandStatus()] should be set to true to enable
  2022.                 // a menu that does not contain commands that have
  2023.                 // already been explicitly enabled. For example, a Fonts
  2024.                 // menu typically has no associated commands (the menu
  2025.                 // items all use synthetic commands), so a Commander
  2026.                 // must set outEnabled to true when asked the status
  2027.                 // of the synthetic command corresponding the Fonts menu.
  2028.                 //
  2029.                 // The mark information is ignored, as is the itemName.
  2030.                 // It would be possible to use the itemName to facilitate
  2031.                 // dynamic changing of menu titles. However, this is bad
  2032.                 // interface design which we don't want to encourage.
  2033.             
  2034.             isEnabled = false;
  2035.  
  2036.             theTarget->ProcessCommandStatus(theCommand, isEnabled,
  2037.                                             usesMark, mark, itemName);
  2038.                                             
  2039.                 // Menu is "used" if it contains commands that were
  2040.                 // explicity enabled in the loop above, or if this
  2041.                 // last call passes back "true" for isEnabled.
  2042.             
  2043.             if (isEnabled) {
  2044.                 theMenu->SetUsed(true);
  2045.             }
  2046.             
  2047.                 // Enable all "used" Menus and disable "unused" ones
  2048.                 // To avoid unnecessary redraws, we invalidate the menu
  2049.                 // bar only if a Menu's enableFlags changes (which means
  2050.                 // that its state has changed).
  2051.             
  2052.             macMenuH = theMenu->GetMacMenuH();
  2053.             Uint32 originalFlags = (**macMenuH).enableFlags;
  2054.                                     
  2055.             if (theMenu->IsUsed()) {
  2056.                 ::EnableItem(macMenuH, 0);
  2057.             } else {
  2058.                 if (!CTargetedUpdateMenuRegistry::UseRegistryToUpdateMenus())
  2059.                 {
  2060.                     // When we are using the registry, it is OK to enable
  2061.                     // menus that are now used, but it is inappropriate
  2062.                     // to disable menus, since we did not update the command
  2063.                     // status of all menu items and therefore we do not have
  2064.                     // enough information to disable the whole menu,
  2065.                     
  2066.                     ::DisableItem(macMenuH, 0);
  2067.                 }
  2068.             }
  2069.             
  2070.             if (originalFlags != (**macMenuH).enableFlags) {
  2071.                 ::InvalMenuBar();
  2072.             }
  2073.         }
  2074.     }
  2075.     
  2076.     UpdateMenusSelf();
  2077. }
  2078.  
  2079. void CFrontApp::UpdateMenusSelf()
  2080. {
  2081.     if (CWindowMenu::sWindowMenu)
  2082.         (CWindowMenu::sWindowMenu)->Update();
  2083.     if (CHistoryMenu::sHistoryMenu)
  2084.         (CHistoryMenu::sHistoryMenu)->Update();
  2085.  
  2086.     CBookmarksAttachment::UpdateMenu();
  2087.  
  2088. #ifdef EDITOR
  2089.     CToolsAttachment::UpdateMenu();
  2090.     CRecentEditMenuAttachment::UpdateMenu();
  2091. #endif // EDITOR
  2092.     
  2093.     UpdateHierarchicalMenus();
  2094.     
  2095.     CPaneEnabler::UpdatePanes();
  2096. #ifdef MOZ_MAIL_NEWS
  2097.     CMailFolderMixin::UpdateMailFolderMixinsNow();
  2098. #endif // MOZ_MAIL_NEWS
  2099.  
  2100. }
  2101.  
  2102. void CFrontApp::UpdateHierarchicalMenus()
  2103. // This is called after LEventDispatcher::UpdateMenus(), and enables parent
  2104. // items of any used submenu.
  2105. {
  2106.     if (!LCommander::GetTarget())
  2107.         return;
  2108.     Int16        menuItem;
  2109.     MenuHandle    macMenuH = nil;
  2110.     LMenu        *theMenu;
  2111.     CommandT    theCommand;
  2112.     LMenuBar    *theMenuBar = LMenuBar::GetCurrentMenuBar();
  2113.     while (theMenuBar->FindNextCommand(menuItem, macMenuH,
  2114.                                         theMenu, theCommand))
  2115.     {                                        
  2116.         short menuChar;
  2117.         ::GetItemCmd(macMenuH, menuItem, &menuChar);
  2118.         if (menuChar != hMenuCmd)
  2119.             continue;
  2120.         // We have an item item with the "hierarchical" flag.
  2121.  
  2122.         // If we have a hierarchal menu that HAS a command number (ie CommandFromIndex
  2123.         // returns something greater than zero) then we're going to trust that it
  2124.         // has been properly enabled already. If we don't give the root menu item the
  2125.         // benefit of the doubt then we could end up accidentally enabling it if it has
  2126.         // more than 31 items in its sub menu
  2127.         if (theMenu->CommandFromIndex(menuItem) < 0) {
  2128.         
  2129.             // Find the child menu, see if LEventDispatcher::UpdateMenus() has
  2130.             // marked it as "used", and if so, make sure we enable this item
  2131.             short childMenuID;
  2132.             ::GetItemMark(macMenuH, menuItem, &childMenuID);
  2133.             LMenu* childMenu = theMenuBar->FetchMenu(childMenuID);
  2134.             if (childMenu && childMenu->IsUsed())
  2135.             {
  2136.                 ::EnableItem(macMenuH, menuItem);
  2137.                 theMenu->SetUsed(true);
  2138.             }
  2139.         }
  2140.     }
  2141.     // Now make sure entire menus get enabled.
  2142.     while (theMenuBar->FindNextMenu(theMenu))
  2143.     {
  2144.         macMenuH = theMenu->GetMacMenuH();
  2145.         Uint32 originalFlags = (**macMenuH).enableFlags;
  2146.         if (theMenu->IsUsed())
  2147.             ::EnableItem(macMenuH, 0);
  2148.         else
  2149.             ::DisableItem(macMenuH, 0);
  2150.         if (originalFlags != (**macMenuH).enableFlags)
  2151.             ::InvalMenuBar();
  2152.     }
  2153. } // CFrontApp::UpdateHierarchicalMenus
  2154.  
  2155.  
  2156. /*
  2157.     App::::MakeNewDocument
  2158.     Called by PowerPlant when a user chooses "New"
  2159.     Returns a window (which is also a model object) in this case. Will change.
  2160.     Is recordable.
  2161. */
  2162. LModelObject* CFrontApp::MakeNewDocument()
  2163. {
  2164.  
  2165.     try
  2166.         {
  2167.         enum
  2168.         {
  2169.             kBlankPage,
  2170.             kHomePage,
  2171.             kLastPage
  2172.         };
  2173.         int32    prefValue = kHomePage;
  2174.         int    prefResult = PREF_GetIntPref("browser.startup.page", &prefValue);
  2175.         if (prefResult != PREF_NOERROR)
  2176.         {
  2177.             prefValue = kHomePage;
  2178.         }
  2179.         URL_Struct* theURL;
  2180.  
  2181.         switch (prefValue)
  2182.         {
  2183.             case kBlankPage:
  2184.                 theURL = nil;
  2185.                 break;
  2186.             case kLastPage:
  2187.                 char    urlBuffer[1024];
  2188.                 if (GH_GetMRUPage(urlBuffer, 1024))
  2189.                 {
  2190.                     theURL = NET_CreateURLStruct(urlBuffer, NET_DONT_RELOAD);
  2191.                 }
  2192.                 else
  2193.                 {
  2194.                     theURL = nil;
  2195.                     //theURL = NET_CreateURLStruct(urlBuffer, NET_DONT_RELOAD);
  2196.                 }
  2197.                 break;
  2198.             case kHomePage:
  2199.             default:
  2200.                 {
  2201.                     CStr255 url = CPrefs::GetString(CPrefs::HomePage);
  2202.                     if (url.Length() > 0)
  2203.                         theURL = NET_CreateURLStruct(url, NET_DONT_RELOAD);
  2204.                     else
  2205.                         theURL = nil;
  2206.                 }
  2207.                 break;
  2208.         }
  2209.  
  2210.         CURLDispatcher::DispatchURL(theURL, NULL, false, true);
  2211.         }
  2212.     catch (...)
  2213.         {
  2214.         
  2215.         
  2216.         }
  2217.         
  2218.     return NULL;    
  2219. }
  2220.  
  2221.  
  2222. //
  2223. // ChooseDocument
  2224. //
  2225. // Picks a document, and opens it in a window (uses existing window if one is open). This
  2226. // takes advantage of the new NavigationServices stuff if it is available.
  2227. //
  2228. void CFrontApp::ChooseDocument()
  2229. {
  2230.     static const OSType myTypes[] = { 'TEXT', 'JPEG', 'GIFf'};
  2231.     
  2232.     UDesktop::Deactivate();    // Always bracket this
  2233.     
  2234.     FSSpec fileSpec;
  2235.     Boolean fileSelected = SimpleOpenDlog ( 3, myTypes, &fileSpec );
  2236.  
  2237.     if ( fileSelected )
  2238.         OpenDocument(&fileSpec);
  2239.  
  2240.     UDesktop::Activate();
  2241.     
  2242. } // ChooseDocument
  2243.  
  2244.  
  2245. CFrontApp* CFrontApp::GetApplication()
  2246. {
  2247.     return sApplication;
  2248. }
  2249.  
  2250. // ÑÑ commands
  2251.  
  2252. void CFrontApp::ProcessCommandStatus(CommandT    inCommand,Boolean &outEnabled, Boolean &outUsesMark,
  2253.                                  Char16        &outMark, Str255        outName)
  2254. {
  2255.     if (GetState() == programState_Quitting)    
  2256.     // If we are quitting, all commands are disabled
  2257.     {
  2258.         outEnabled = FALSE;
  2259.         return;
  2260.     }
  2261.     else
  2262.         LApplication::ProcessCommandStatus(inCommand,outEnabled, outUsesMark,outMark, outName);
  2263. }
  2264.  
  2265. //-----------------------------------
  2266. void CFrontApp::FindCommandStatus( CommandT command, Boolean& enabled, 
  2267.     Boolean& usesMark, Char16& mark, Str255 outName )
  2268. //-----------------------------------
  2269. {
  2270.     // Allow only close and quit if memory is low.
  2271.     if (Memory_MemoryIsLow())
  2272.     {
  2273.         if (command != cmd_Quit) // cmd_Close and cmd_CloseAll will also be avail., from elsewhere.
  2274.             enabled = FALSE;
  2275.         else
  2276.             LDocApplication::FindCommandStatus (command, enabled, usesMark, mark, outName);
  2277.         return;
  2278.     }
  2279.     // Do not enable menus behind modal dialogs
  2280.     if (IsFrontWindowModal())    // Only enable quit when front window is modal
  2281.     {
  2282.         if (command != cmd_Quit)
  2283.             enabled = FALSE;
  2284.         else
  2285.             LDocApplication::FindCommandStatus (command, enabled, usesMark, mark, outName);
  2286.         return;
  2287.     }        
  2288.     usesMark = FALSE;
  2289.     switch ( command )
  2290.     {
  2291.         case cmd_GoForward:
  2292.             if (CApplicationEventAttachment::CurrentEventHasModifiers(optionKey))
  2293.             {
  2294.                 LString::CopyPStr(::GetPString(MENU_FORWARD_ONE_HOST), outName);
  2295.             }
  2296.             else
  2297.             {
  2298.                 LString::CopyPStr(::GetPString(MENU_FORWARD), outName);
  2299.             }
  2300.             break;
  2301.         case cmd_GoBack:
  2302.             if (CApplicationEventAttachment::CurrentEventHasModifiers(optionKey))
  2303.             {
  2304.                 LString::CopyPStr(::GetPString(MENU_BACK_ONE_HOST), outName);
  2305.             }
  2306.             else
  2307.             {
  2308.                 LString::CopyPStr(::GetPString(MENU_BACK), outName);
  2309.             }
  2310.             break;
  2311.  
  2312.         case cmd_ShowJavaConsole:
  2313. #if defined (JAVA)
  2314.             usesMark = true;
  2315.             mark = LJ_IsConsoleShowing() ? 0x12 : 0;
  2316.             enabled = mJavaEnabled;
  2317. #endif /* defined (JAVA) */
  2318.             break;
  2319.  
  2320. #ifdef EDITOR
  2321. //        case cmd_New_Document_Heirarchical_Menu:
  2322.         case cmd_NewWindowEditor:
  2323.         case cmd_NewWindowEditorIFF:
  2324.         case cmd_New_Document_Template:
  2325.         case cmd_New_Document_Wizard:        
  2326.         case cmd_OpenFileEditor:
  2327.         case cmd_EditEditor:
  2328. #endif // EDITOR
  2329. #ifdef MOZ_MAIL_NEWS
  2330.         case cmd_MailNewsFolderWindow:
  2331.         case cmd_NewsGroups:
  2332.         case cmd_GetNewMail:
  2333.         case cmd_Inbox:
  2334.         case cmd_MailNewsSearch:
  2335.         case cmd_MailFilters:
  2336.         case cmd_SearchAddresses:
  2337.         case cmd_AddressBookWindow:
  2338.         case cmd_NewFolder:
  2339. #endif // MOZ_MAIL_NEWS
  2340. #if defined(MOZ_MAIL_COMPOSE) || defined(MOZ_MAIL_NEWS)
  2341.         case cmd_NewMailMessage:
  2342. #endif // MOZ_MAIL_COMPOSE
  2343. #ifdef EDITOR
  2344.         case cmd_OpenURLEditor:
  2345. #endif // EDITOR
  2346.         case cmd_BrowserWindow:
  2347.         case cmd_Preferences:
  2348.         case 19896: /*cmd_NetToggle*/
  2349.         case cmd_OpenURL:
  2350. //        case cmd_EditGeneral:
  2351.         case cmd_EditNetwork:
  2352.         case cmd_EditSecurity:
  2353. // old mail/news stuff
  2354. //        case cmd_MailWindow:
  2355. //        case cmd_NewsWindow:
  2356. //        case cmd_MailTo:
  2357.         case cmd_CoBrandLogo:
  2358.         case cmd_AboutPlugins:
  2359.         case cmd_LaunchCalendar:
  2360.         case cmd_Launch3270:
  2361.         case cmd_LaunchNetcaster:
  2362. #ifdef FORTEZZA
  2363.         case cmd_FortezzaCard:
  2364.         case cmd_FortezzaChange:
  2365.         case cmd_FortezzaView:
  2366.         case cmd_FortezzaInfo:
  2367.         case cmd_FortezzaLogout:
  2368. #endif // FORTEZZA
  2369.             enabled = TRUE;
  2370.         break;            
  2371.         
  2372.         case cmd_LaunchConference:
  2373.             enabled = mConferenceApplicationExists;
  2374.             break;
  2375.         
  2376.         case cmd_BookmarksWindow:
  2377.         case cmd_HistoryWindow:
  2378.         case cmd_NCNewWindow:
  2379.             enabled = !Memory_MemoryIsLow();
  2380.             break;
  2381.             
  2382.         case cmd_New:
  2383.         case cmd_Open:
  2384.             enabled = !Memory_MemoryIsLow();
  2385.             break;
  2386. #ifdef MOZ_TASKBAR
  2387.         case cmd_ToggleTaskBar:
  2388.             enabled = TRUE;
  2389.             CTaskBarListener::GetToggleTaskBarWindowMenuItemName(outName);
  2390.             break;
  2391. #endif // MOZ_TASKBAR
  2392. #ifdef MOZ_OFFLINE
  2393.         // Online/Offline mode
  2394.         case cmd_ToggleOffline:
  2395.         case cmd_SynchronizeForOffline:
  2396.             enabled = TRUE;
  2397.             UOffline::FindOfflineCommandStatus(command, enabled, outName);
  2398.             break;
  2399. #endif // MOZ_OFFLINE
  2400.         default:
  2401.             ResIDT menuID;
  2402.             Int16 menuItem;
  2403.             if ( command >= DIR_BUTTON_BASE && command <= DIR_BUTTON_LAST )
  2404.                 enabled = TRUE;
  2405.             else if (IsSyntheticCommand(command, menuID, menuItem) && menuID == cWindowMenuID)
  2406.                 // --ML 4.0b2 Disable all Window menu items without a command number
  2407.                 // (i.e. Conference, Calendar, IBM, History)
  2408.                 enabled = FALSE;
  2409. // the code below was used ifndef MAILNEWS
  2410. //            else if ((command > cmd_WINDOW_MENU_BASE) && (command < cmd_WINDOW_MENU_BASE_LAST))
  2411. //                enabled = TRUE;
  2412.             else
  2413.                 LDocApplication::FindCommandStatus (command, enabled, usesMark, mark, outName);
  2414.     }
  2415. } // CFrontApp::FindCommandStatus
  2416.  
  2417. extern void NET_ToggleTrace();
  2418.  
  2419. //-----------------------------------
  2420. Boolean CFrontApp::ObeyCommand(CommandT inCommand, void* ioParam)
  2421. //-----------------------------------
  2422. {
  2423.     Boolean bCommandHandled = true;
  2424.     
  2425.     switch ( inCommand )
  2426.         {    
  2427.         case cmd_BrowserWindow:
  2428.         /*
  2429.             URL_Struct* theURL = NULL;
  2430.             CURLDispatcher* theDispatcher = CURLDispatcher::GetURLDispatcher();
  2431.             Assert_(theDispatcher != NULL);
  2432.             theDispatcher->DispatchToView(NULL, theURL, FO_CACHE_AND_PRESENT);
  2433.         */
  2434.                 // this code is stolen from the editor button, below!  Thanks Kathy!
  2435.                 // get the front window so we know if an browser window is already in the front
  2436.             CMediatedWindow *wp,  *browserwin;
  2437.             CWindowIterator iterAny(WindowType_Any);
  2438.             iterAny.Next(wp);
  2439.             CWindowIterator iter(WindowType_Browser);
  2440.             iter.Next(browserwin);
  2441.             if (browserwin && (wp == browserwin))
  2442.             {
  2443.                     // count the number of windows; stuff current browser window into browserwin
  2444.                     // put the window we want to be frontmost into wp (reuse)
  2445.                     // spec says to cycle through all windows of our type so we bring the
  2446.                     // backmost-window to the front and push the others down in the stack
  2447.                 int numWindows = 1;
  2448.                 while (iter.Next(wp))
  2449.                 {
  2450.                     numWindows++;
  2451.                     browserwin = wp;
  2452.                 }
  2453.                 
  2454.                 if (numWindows == 1)
  2455.                     browserwin = NULL;        // set to NULL so we create new window below
  2456.             }
  2457.             
  2458.                 // if no browser in front window bring the frontmost browser window to front
  2459.                 // if browser is in front select the window determined above and we're done!
  2460.             if (browserwin)
  2461.             {
  2462.                 browserwin->Show();
  2463.                 browserwin->Select();
  2464.                 break;
  2465.             }
  2466.             else        // let's make a new one
  2467.             {
  2468.                 MakeNewDocument();
  2469.             }
  2470.             break;
  2471.         case 19896: /*cmd_NetToggle*/
  2472.             NET_ToggleTrace();
  2473.         break;
  2474.         case cmd_ShowJavaConsole:
  2475. #if defined (JAVA)
  2476.             {
  2477.             if (LJ_IsConsoleShowing())
  2478.                 LJ_HideConsole();
  2479.             else
  2480.                 LJ_ShowConsole();
  2481.             }
  2482. #endif /* defined (JAVA) */
  2483.             break;
  2484.             
  2485.         case cmd_HistoryWindow:
  2486.         {
  2487.         
  2488.             CNavCenterWindow* navCenter = dynamic_cast<CNavCenterWindow*>(URobustCreateWindow::CreateWindow(CNavCenterWindow::res_ID, this));
  2489.             navCenter->BringPaneToFront ( HT_VIEW_HISTORY );
  2490.         }
  2491.             break;
  2492.             
  2493.         case cmd_BookmarksWindow:
  2494.         case cmd_NCNewWindow:
  2495.         {
  2496.             CNavCenterWindow* navCenter = dynamic_cast<CNavCenterWindow*>(URobustCreateWindow::CreateWindow(CNavCenterWindow::res_ID, this));
  2497.             navCenter->BringPaneToFront ( HT_VIEW_BOOKMARK );
  2498.         }
  2499.             break;
  2500.             
  2501. #if defined(MOZ_MAIL_COMPOSE) || defined(MOZ_MAIL_NEWS)
  2502.         case cmd_NewMailMessage:
  2503.             MSG_MailDocument(NULL);
  2504.             break;
  2505. #endif // MOZ_MAIL_COMPOSE || MOZ_MAIL_NEWS
  2506.  
  2507.         case cmd_OpenURL:
  2508.             DoOpenURLDialog();
  2509.             break;
  2510.                     
  2511. #ifdef EDITOR
  2512.         
  2513.         case cmd_OpenURLEditor:
  2514.             DoOpenURLDialogInEditor();
  2515.             break;
  2516.         
  2517.         case cmd_New_Document_Template:
  2518.             {
  2519.             CStr255 urlString = CPrefs::GetString(CPrefs::EditorNewDocTemplateLocation);
  2520.             if ( urlString != CStr255::sEmptyString )
  2521.                 {
  2522.                 URL_Struct* theURL = NET_CreateURLStruct(urlString, NET_DONT_RELOAD);
  2523.                 if (theURL)
  2524.                     CURLDispatcher::DispatchURL(theURL, NULL, false, true);
  2525.                 }
  2526.             }
  2527.             break;
  2528.             
  2529.         case cmd_New_Document_Wizard:
  2530.             char* url;
  2531.             if (PREF_CopyConfigString("internal_url.page_from_wizard.url", &url) == PREF_NOERROR)
  2532.                 {
  2533.                 URL_Struct* theURL = NET_CreateURLStruct(url, NET_DONT_RELOAD);
  2534.                 if (theURL)
  2535.                     CURLDispatcher::DispatchURL(theURL, NULL, false, true);
  2536.                 }
  2537.             break;
  2538.             
  2539.         case cmd_NewWindowEditorIFF:
  2540.         {
  2541.             // get the front window so we know if an editor window is already in the front
  2542.             CMediatedWindow *wp,  *editwin;
  2543.             CWindowIterator iterAny(WindowType_Any);
  2544.             iterAny.Next(wp);
  2545.             
  2546.             CWindowIterator iter(WindowType_Editor);
  2547.             iter.Next(editwin);
  2548.             
  2549.             if ( editwin && ( wp == editwin ) )
  2550.             {
  2551.                 // count the number of windows; stuff current editor window into editwin
  2552.                 // put the window we want to be frontmost into wp (reuse)
  2553.                 // spec says to cycle through all windows of our type so we bring the
  2554.                 // backmost-window to the front and push the others down in the stack
  2555.                 int numWindows = 1;
  2556.                 while ( iter.Next(wp) )
  2557.                 {
  2558.                     numWindows++;
  2559.                     editwin = wp;
  2560.                 }
  2561.                 
  2562.                 if ( numWindows == 1 )
  2563.                     editwin = NULL;        // set to NULL so we create new window below
  2564.             }
  2565.             
  2566.             // if no editor in front window bring the frontmost editor window to front
  2567.             // if editor is in front select the window determined above and we're done!
  2568.             if ( editwin )
  2569.             {
  2570.                 editwin->Show();
  2571.                 editwin->Select();
  2572.                 break;
  2573.             }
  2574.             // else continue below
  2575.         }
  2576.         case cmd_NewWindowEditor:
  2577.             CEditorWindow::MakeEditWindow( NULL, NULL );
  2578.             break;
  2579.  
  2580.         case cmd_OpenFileEditor:
  2581.             {
  2582.                 
  2583. //            StandardFileReply myReply;
  2584.         
  2585.             static const OSType myTypes[] = { 'TEXT'};
  2586.             
  2587.             UDesktop::Deactivate();    // Always bracket this
  2588.             
  2589.             FSSpec fileSpec;
  2590.             Boolean fileSelected = SimpleOpenDlog ( 1, myTypes, &fileSpec );
  2591.                 
  2592.             UDesktop::Activate();
  2593.             
  2594.             if (!fileSelected) return TRUE;            // we handled it... we just didn't do anything!
  2595.                     
  2596.             char* localURL = CFileMgr::GetURLFromFileSpec(fileSpec);
  2597.             if (localURL == NULL) return TRUE;        
  2598.             
  2599.             NET_cinfo *cinfo = NET_cinfo_find_type (localURL);
  2600.             if (cinfo && cinfo->type && (!strcasecomp (cinfo->type, TEXT_HTML) 
  2601.             || !strcasecomp (cinfo->type, UNKNOWN_CONTENT_TYPE) 
  2602.             || !strcasecomp (cinfo->type, TEXT_PLAIN)))
  2603.                 {
  2604.                 URL_Struct * request = NET_CreateURLStruct ( localURL, NET_NORMAL_RELOAD );
  2605.                 if ( request )
  2606.                     CEditorWindow::MakeEditWindow( NULL, request );
  2607.                 }
  2608.             else
  2609.                 {
  2610.                 ErrorManager::PlainAlert( NOT_HTML );
  2611.                 }
  2612.  
  2613.             XP_FREE(localURL);
  2614.             }
  2615.             break;
  2616.             
  2617.         case cmd_EditEditor:
  2618.             CPrefsDialog::EditPrefs(    CPrefsDialog::eExpandEditor, 
  2619.                         PrefPaneID::eEditor_Main, CPrefsDialog::eIgnore);
  2620.         break;
  2621.     
  2622. #endif
  2623.         
  2624.         case cmd_Preferences:
  2625.             CPrefsDialog::EditPrefs();
  2626.             break;
  2627.         
  2628. #ifdef MOZ_MAIL_NEWS
  2629.         case cmd_NewsGroups:
  2630.         case cmd_MailNewsFolderWindow:
  2631.         {
  2632.             CMailNewsFolderWindow::FindAndShow(true, inCommand);
  2633.             break;
  2634.         }
  2635.         case cmd_GetNewMail:
  2636.             // If it came here, we must assume there are no mail/news windows.
  2637.             // So open the inbox First.
  2638.             CThreadWindow* tw = CThreadWindow::ShowInbox(cmd_GetNewMail);
  2639.             break;
  2640.         case cmd_Inbox:
  2641.             CThreadWindow::ShowInbox(cmd_Nothing);
  2642.             break;
  2643.         case cmd_MailTo:
  2644.             {
  2645.             MSG_Mail(NULL);    // Crashes now, libmsg error
  2646.             }
  2647.             break;
  2648. #endif // MOZ_MAIL_NEWS
  2649.             
  2650.         case cmd_AboutPlugins:
  2651.             DoGetURL( "about:plugins" );
  2652.             break;
  2653.  
  2654.         case cmd_LaunchConference:
  2655.             LaunchExternalApp(kConferenceAppSig, CONFERENCE_APP_NAME);
  2656.             break;
  2657.  
  2658.         // --ML Polaris
  2659.         case cmd_LaunchCalendar:
  2660.             LaunchExternalApp(kCalendarAppSig, CALENDAR_APP_NAME);
  2661.             break;
  2662.         
  2663.         case cmd_Launch3270:
  2664.             Launch3270Applet();
  2665.             break;
  2666.  
  2667.         case cmd_LaunchNetcaster:
  2668.             LaunchNetcaster();
  2669.             break;
  2670.  
  2671.  
  2672. #ifdef FORTEZZA
  2673.         case cmd_FortezzaCard:
  2674.             SSL_FortezzaMenu(NULL,SSL_FORTEZZA_CARD_SELECT);
  2675.             break;
  2676.         case cmd_FortezzaChange:
  2677.             // er, excuse me, mr fortezza, but CHyperWin::Show() might return NULL....
  2678.             CHyperWin* win = GetFrontHyperWin();
  2679.             if (win)
  2680.                 SSL_FortezzaMenu(win->fHyperView->GetContext(),SSL_FORTEZZA_CHANGE_PERSONALITY);
  2681.             break;
  2682.         case cmd_FortezzaView:
  2683.             CHyperWin* win = GetFrontHyperWin();
  2684.             if (win)
  2685.                 SSL_FortezzaMenu(win->fHyperView->GetContext(),SSL_FORTEZZA_VIEW_PERSONALITY);
  2686.             break;
  2687.         case cmd_FortezzaInfo:
  2688.             SSL_FortezzaMenu(NULL,SSL_FORTEZZA_CARD_INFO);
  2689.             break;
  2690.         case cmd_FortezzaLogout:
  2691.             /* sBookMarkContext */
  2692.             SSL_FortezzaMenu(NULL,SSL_FORTEZZA_LOGOUT);
  2693.             break;
  2694. #endif
  2695.  
  2696. #ifdef MOZ_MAIL_NEWS
  2697.         // This really shouldn't be here, but since the mail/news windows are not up yet,
  2698.         // it's here for testing
  2699.         case cmd_MailNewsSearch:
  2700.             CSearchWindowManager::ShowSearchWindow();
  2701.             break;
  2702.         case cmd_MailFilters:
  2703.             CFiltersWindowManager::ShowFiltersWindow();
  2704.             break;
  2705.         case cmd_AddressBookWindow:
  2706.             CAddressBookManager::ShowAddressBookWindow();
  2707.             break;
  2708.         case cmd_NewFolder:
  2709.         {
  2710.             CMessageFolder folder(nil);
  2711.             UFolderDialogs::ConductNewFolderDialog(folder);
  2712.             break;
  2713.         }
  2714.     //    case cmd_SearchAddresses:
  2715.     //        CSearchWindowManager::ShowSearchAddressesWindow();
  2716.     //        break;
  2717. #endif // MOZ_MAIL_NEWS
  2718. #ifdef MOZ_TASKBAR
  2719.         case cmd_ToggleTaskBar:
  2720.             CTaskBarListener::ToggleTaskBarWindow();
  2721.             break;
  2722. #endif // MOZ_TASKBAR
  2723. #ifdef MOZ_OFFLINE
  2724.         // Online/Offline mode
  2725.         case cmd_ToggleOffline:
  2726.             UOffline::ObeyToggleOfflineCommand();
  2727.             break;
  2728.  
  2729.         case cmd_SynchronizeForOffline:
  2730.             UOffline::ObeySynchronizeCommand();
  2731.             break;
  2732. #endif // MOZ_OFFLINE
  2733.         default:
  2734.             {
  2735.             // Directory urls
  2736.             if ( inCommand >= DIR_BUTTON_BASE && inCommand <= DIR_BUTTON_LAST )
  2737.                 DoOpenDirectoryURL( inCommand );
  2738.  
  2739.             // Spinning icon
  2740.             else if ( inCommand == LOGO_BUTTON || inCommand == cmd_CoBrandLogo )
  2741.                 DoOpenLogoURL( inCommand );
  2742.  
  2743.             else if (!CWindowMenu::ObeyWindowCommand(inCommand))
  2744.             {
  2745.                 ResIDT menuID = ( HiWord( -inCommand ) );
  2746.                 Int16 itemNum = ( LoWord( -inCommand ) );
  2747.                 if ( menuID == kHMHelpMenuID )
  2748.                 {
  2749.                     itemNum -= sHelpMenuOrigLength;
  2750.                     DoHelpMenuItem( itemNum );
  2751.                 }
  2752.                 else
  2753.                     bCommandHandled = LDocApplication::ObeyCommand(inCommand, ioParam);
  2754.                 }
  2755.             break;
  2756.         }
  2757.     } // switch
  2758.     return bCommandHandled;
  2759. } // CFrontApp::ObeyCommand
  2760.  
  2761. #ifdef QAP_BUILD
  2762. //-----------------------------------
  2763. //void CFrontApp::PutOnDuty()
  2764. //-----------------------------------
  2765. //{
  2766. //    QAP_AssistHook (kQAPAppToForeground, 0, NULL, 0, 0);
  2767. //    LCommander::PutOnDuty ();
  2768. //}
  2769.  
  2770. //-----------------------------------
  2771. //void CFrontApp::TakeOffDuty()
  2772. //-----------------------------------
  2773. //{
  2774. //    LCommander::TakeOffDuty ();
  2775. //    QAP_AssistHook (kQAPAppToBackground, 0, NULL, 0, 0);
  2776. //}
  2777. #endif //QAP_BUILD
  2778.  
  2779. //-----------------------------------
  2780. void CFrontApp::DoOpenDirectoryURL( CommandT menuCommand )
  2781. //-----------------------------------
  2782. {
  2783.     CStr255        urlString;
  2784.     Boolean        isMenuCommand = (menuCommand >= DIR_MENU_BASE);
  2785.     short stringID = isMenuCommand ? DIR_MENU_BASE : DIR_BUTTON_BASE;
  2786.  
  2787.     char* url;
  2788.     if ( PREF_CopyIndexConfigString(
  2789.             isMenuCommand ? "menu.places.item" : "toolbar.places.item",
  2790.             menuCommand - stringID, "url", &url) == PREF_NOERROR )
  2791.     {
  2792.         DoGetURL(url);
  2793.         XP_FREE(url);
  2794.     }
  2795. }
  2796.  
  2797. void CFrontApp::DoOpenLogoURL( CommandT menuCommand )
  2798. {
  2799.     // Admin Kit: Handle co-brand button
  2800.     char* url;
  2801.     if ( menuCommand == LOGO_BUTTON &&
  2802.         PREF_CopyConfigString("toolbar.logo.url", &url) == PREF_NOERROR )
  2803.     {
  2804.         DoGetURL(url);
  2805.         XP_FREE(url);
  2806.     }
  2807.     else
  2808.     {
  2809.         StringHandle handle = GetString( LOGO_BUTTON_URL_RESID );
  2810.         CStr255 urlString = *((unsigned char**)handle);
  2811.         if ( urlString != CStr255::sEmptyString )
  2812.             DoGetURL( (unsigned char*)urlString );
  2813.     }
  2814. }
  2815.  
  2816. void CFrontApp::DoWindowsMenu(CommandT inCommand)
  2817. {
  2818.     Int32 index = inCommand - cmd_WINDOW_MENU_BASE;
  2819.     LWindow * win;
  2820.     if (fWindowsMenu.FetchItemAt(index, &win))
  2821.         win->Select();
  2822. }
  2823.  
  2824. // DoGetURL loads the given url into the frontmost window, or new one if there is no frontmost
  2825. // Provides a bottleneck for UI generated requests to load a URL
  2826. void CFrontApp::DoGetURL( const cstring& url )
  2827. {
  2828.     // Check for kiosk mode and bail if it's set so that the user can't manually
  2829.     // go to a different URL.  Note that this does NOT prevent dispatching to a different
  2830.     // URL from the content.
  2831.     if (CAppleEventHandler::GetKioskMode() == KioskOn)
  2832.         return;
  2833.     
  2834.     // Is this REALLY necessary?
  2835.     (CFrontApp::GetApplication())->ProperStartup( NULL, FILE_TYPE_NONE );    // Making sure that we have the prefs loaded
  2836.  
  2837.     URL_Struct* theURL = NET_CreateURLStruct(url, NET_DONT_RELOAD);
  2838.     if (theURL)
  2839.         CURLDispatcher::DispatchURL(theURL, NULL);
  2840. }
  2841.  
  2842. //-----------------------------------------------------------------------------
  2843. // Chenge of address
  2844. //        AppleEvents has moved to CAppleEventHandler.cp
  2845. //            C Hull
  2846. //-----------------------------------------------------------------------------
  2847.  
  2848. /*------------------------------------------------
  2849. AppleEvent Dispach Here
  2850.     In: & AppleEvent/ Evenc coming in
  2851.         & ReplyEvent/ Reply event back to sender
  2852.         & Descriptor/ Not sure why this was extracted, but OK.
  2853.           AppleEvent/ ID The event
  2854.     Out: Event Handled by the sAppleEvents entity
  2855. ------------------------------------------------*/
  2856. void CFrontApp::HandleAppleEvent(
  2857.     const AppleEvent&    inAppleEvent,
  2858.     AppleEvent&            outAEReply,
  2859.     AEDesc&                outResult,
  2860.     long                inAENumber)
  2861. {
  2862.     XP_TRACE(("Handling event %d", inAENumber));
  2863.     Try_
  2864.     {
  2865.         if ( CAppleEventHandler::sAppleEventHandler == NULL )
  2866.             new CAppleEventHandler;
  2867.  
  2868.         ThrowIfNil_(CAppleEventHandler::sAppleEventHandler);
  2869.         
  2870.         CAppleEventHandler::sAppleEventHandler->HandleAppleEvent(inAppleEvent, 
  2871.                     outAEReply, 
  2872.                     outResult, 
  2873.                     inAENumber);
  2874.                     
  2875.     }            
  2876.     Catch_( inErr )
  2877.     {}
  2878.     EndCatch_
  2879. }
  2880.  
  2881.  
  2882.  
  2883.  
  2884. void CFrontApp::GetAEProperty(DescType            inProperty,
  2885.                                 const AEDesc    &inRequestedType,
  2886.                                 AEDesc            &outPropertyDesc) const
  2887. {
  2888.     try
  2889.     {
  2890.         if (CAppleEventHandler::sAppleEventHandler == NULL)
  2891.             new CAppleEventHandler;
  2892.         ThrowIfNil_(CAppleEventHandler::sAppleEventHandler);
  2893.         
  2894.         CAppleEventHandler::sAppleEventHandler->GetAEProperty(inProperty, 
  2895.                                                                 inRequestedType, 
  2896.                                                                 outPropertyDesc);
  2897.     }            
  2898.     catch(...)
  2899.     {}
  2900. }
  2901.  
  2902.  
  2903.  
  2904.  
  2905.  
  2906.  
  2907. void CFrontApp::SetAEProperty(DescType             inProperty,
  2908.                                 const AEDesc    &inRequestedType,
  2909.                                 AEDesc            &outPropertyDesc)
  2910. {
  2911.     try
  2912.     {
  2913.         if (CAppleEventHandler::sAppleEventHandler == NULL)
  2914.             new CAppleEventHandler;
  2915.         ThrowIfNil_(CAppleEventHandler::sAppleEventHandler);
  2916.         
  2917.         CAppleEventHandler::sAppleEventHandler->SetAEProperty(inProperty, 
  2918.                                                                 inRequestedType, 
  2919.                                                                 outPropertyDesc);
  2920.     }            
  2921.     catch(...)
  2922.     {}
  2923. }
  2924.  
  2925.  
  2926.  
  2927.  
  2928.  
  2929.  
  2930. //-----------------------------------------------------------------------------
  2931. // Printing
  2932. //-----------------------------------------------------------------------------
  2933.  
  2934. //-----------------------------------
  2935. void CFrontApp::SetupPage()
  2936. //-----------------------------------
  2937. {
  2938.     THPrint        hPrintRec;
  2939.     Boolean        havePrinter;
  2940.     
  2941.     hPrintRec = CPrefs::GetPrintRecord();
  2942.     
  2943.     havePrinter = hPrintRec != 0;
  2944.  
  2945.     if (havePrinter)
  2946.     {
  2947.         UPrintingMgr::ValidatePrintRecord( hPrintRec );
  2948.         if ( UPrintingMgr::OpenPrinter() )
  2949.         {
  2950.             UDesktop::Deactivate();
  2951.             UHTMLPrinting::OpenPageSetup( hPrintRec );
  2952.             UDesktop::Activate();
  2953.  
  2954.             UPrintingMgr::ClosePrinter();
  2955.         } else
  2956.             havePrinter = false;
  2957.     }
  2958.     if ( !havePrinter )
  2959.         FE_Alert( NULL, GetPString ( NO_PRINTER_RESID ) );
  2960. } // CFrontApp::SetupPage
  2961.  
  2962.  
  2963. //-----------------------------------------------------------------------------
  2964. // Menubar management
  2965. //-----------------------------------------------------------------------------
  2966. void CFrontApp::SetMenubar( ResIDT mbar, Boolean inUpdateNow )
  2967. {
  2968.     fWantedMbar = mbar;
  2969.     
  2970.     if (inUpdateNow) {
  2971.         UpdateMenus();
  2972.     }
  2973. }
  2974.  
  2975. void CFrontApp::InstallMenus()
  2976. {
  2977.     // Menu creation must go here, because until now, the menu bar has not
  2978.     // been created. (see LApplication::Run())
  2979.     CHistoryMenu* historyMenu = new CHistoryMenu(cHistoryMenuID);
  2980.     CWindowMenu* windowMenu = new CWindowMenu(cWindowMenuID);
  2981.     // create CNSMenuBarManager
  2982.     new CNSMenuBarManager(CWindowMediator::GetWindowMediator());
  2983.     LMenuBar::GetCurrentMenuBar()->InstallMenu(historyMenu, InstallMenu_AtEnd);
  2984.     CBookmarksAttachment::InstallMenus();
  2985.     LMenuBar::GetCurrentMenuBar()->InstallMenu(windowMenu, InstallMenu_AtEnd);
  2986.     CWindowMediator::GetWindowMediator()->AddListener(windowMenu);
  2987.  
  2988.     // Admin Kit friendly Help and Places menus: labels and URLs are
  2989.     // initialized in config.js and may be overridden by config file.
  2990.     MenuHandle balloonMenuH;
  2991.     HMGetHelpMenuHandle( &balloonMenuH );
  2992.     if ( balloonMenuH )
  2993.     {
  2994.         sHelpMenuOrigLength = CountMItems(balloonMenuH);
  2995.         
  2996.         sHelpMenuItemCount = BuildConfigurableMenu( balloonMenuH,
  2997.             "menu.help.item", HELP_URLS_MENU_STRINGS );
  2998.     }
  2999.     
  3000.     /*    NOTE: Places menu is installed in CBookmarksAttachment::InstallMenus(),
  3001.         which calls back to BuildConfigurableMenu. */
  3002. }
  3003.  
  3004. int CFrontApp::BuildConfigurableMenu(MenuHandle menu, const char* xp_name, short stringsID)
  3005. {
  3006.     CStr255 entry;
  3007.     short i;
  3008.     
  3009.     // Append configurable items first
  3010.     for (i = 1; i <= 25; i++) {
  3011.         char*    label;
  3012.         if ( PREF_CopyIndexConfigString(xp_name, i - 1, "label", &label) == PREF_NOERROR )
  3013.         {
  3014.             entry = label;
  3015.             XP_FREE(label);
  3016.             
  3017.             if (entry.IsEmpty())    // blank entry marks end of menu
  3018.                 break;
  3019.             
  3020.             StripChar(entry, '&');    // strip ampersands from label
  3021.             
  3022.             AppendMenu(menu, entry);
  3023.         }
  3024.         else
  3025.             break;
  3026.     }
  3027.     
  3028.     // Then append fixed items, if any (i.e. About Netscape)
  3029.     if (stringsID > 0) {
  3030.         CStringListRsrc menuStrings( stringsID );
  3031.         for (short j = 1; j < menuStrings.CountStrings() + 1; j++) {
  3032.             menuStrings.GetString( j, entry );
  3033.             AppendMenu(menu, entry);
  3034.         }
  3035.     }
  3036.     
  3037.     return i - 1;
  3038. }
  3039.  
  3040. void CFrontApp::DoHelpMenuItem( short itemNum )
  3041. {
  3042.     // use configurable URL if defined, else use built-in URL
  3043.     char* url;
  3044.     if ( itemNum <= sHelpMenuItemCount && PREF_CopyIndexConfigString("menu.help.item",
  3045.         itemNum - 1, "url", &url) == PREF_NOERROR )
  3046.     {
  3047.         DoGetURL( url );
  3048.         XP_FREE(url);
  3049.     }
  3050.     else {
  3051.         CStr255        urlString;
  3052.     
  3053.         GetIndString( urlString, HELP_URLS_RESID, itemNum - sHelpMenuItemCount );
  3054.         
  3055.         if ( urlString != CStr255::sEmptyString )
  3056.             DoGetURL( (unsigned char*)urlString );
  3057.     }
  3058. }
  3059.  
  3060. extern pascal long MDEF_MenuKey( long theMessage, short theModifiers, MenuHandle hMenu );
  3061.  
  3062. //-----------------------------------
  3063. void CFrontApp::EventKeyDown( const EventRecord& inMacEvent )
  3064. // Ñ we override this to patch Mercutio in
  3065. //-----------------------------------
  3066. {
  3067.     CommandT keyCommand = cmd_Nothing;
  3068.     Int32 menuChoice = 0;
  3069.     // Remap function keys.  Is there a better way?  jrm 97/04/03
  3070.     switch ((inMacEvent.message & keyCodeMask) >> 8)
  3071.     {
  3072.         case vkey_F1:
  3073.             keyCommand = cmd_Undo;
  3074.             break;
  3075.         case vkey_F2:
  3076.             keyCommand = cmd_Cut;
  3077.             break;
  3078.         case vkey_F3:
  3079.             keyCommand = cmd_Copy;
  3080.             break;
  3081.         case vkey_F4:
  3082.             keyCommand = cmd_Paste;
  3083.             break;
  3084.         default:
  3085.             // Modal dialogs might have OK/cancel buttons, and handle their own keys.
  3086.             // So only convert to command when front window is not modal
  3087.             if ((inMacEvent.modifiers & cmdKey) && (inMacEvent.message & charCodeMask) == '.')
  3088.             {
  3089.                 if (!IsFrontWindowModal())
  3090.                     keyCommand = cmd_Stop;
  3091.             }
  3092.             // Check if the keystroke is a Menu Equivalent
  3093.             else if (LMenuBar::GetCurrentMenuBar()->CouldBeKeyCommand(inMacEvent))
  3094.             {
  3095.                 CTargetedUpdateMenuRegistry::SetCommands(CFrontApp::GetCommandsToUpdateBeforeSelectingMenu());
  3096.                 CTargetedUpdateMenuRegistry::UpdateMenus();
  3097.                 
  3098.                 menuChoice = MDEF_MenuKey(
  3099.                     inMacEvent.message,
  3100.                     inMacEvent.modifiers, ::GetMenu( 666 ) );
  3101.                             
  3102.                 // If menuChoice is 0, then a modifer key may have been held down that
  3103.                 //    didn't map to a known command-key equivalent (e.g. cmd-opt-n).
  3104.                 //    In this case, we will try again with just the cmdKey. Recall that
  3105.                 //    this is what the Finder does (with cmd-n for New Folder, for instance).
  3106.                 //    It makes especially good sense when you think about the fact that since
  3107.                 //    the command and option keys are close, users sometimes accidently hit both.
  3108.                 //    Without this "fix", cmd_Nothing would be returned.
  3109.                 if (menuChoice == 0)
  3110.                 {
  3111.                     EventModifiers modifiers = cmdKey;
  3112.                     
  3113.                     menuChoice = MDEF_MenuKey(inMacEvent.message, modifiers, ::GetMenu( 666 ));
  3114.                 }                
  3115.                                              
  3116.                 if ( HiWord( menuChoice ) != 0 )
  3117.                     keyCommand = LMenuBar::GetCurrentMenuBar()->FindCommand(
  3118.                                             HiWord(menuChoice),
  3119.                                             LoWord(menuChoice));
  3120.             }
  3121.     }
  3122.     SignalIf_(LCommander::GetTarget() == nil);
  3123.  
  3124.     // Don't allow quit events if it isn't safe to quit but remember the request
  3125.     if ((keyCommand == cmd_Quit) && !fSafeToQuit)
  3126.     {
  3127.         keyCommand = cmd_Nothing;
  3128.         fUserWantsToQuit = true;
  3129.     }
  3130.     if (keyCommand != cmd_Nothing)
  3131.     {
  3132.         LCommander::SetUpdateCommandStatus( true );
  3133.         LCommander::GetTarget()->ProcessCommand(keyCommand, &menuChoice);
  3134.         ::HiliteMenu( 0 );
  3135.     }
  3136.     else
  3137.         LCommander::GetTarget()->ProcessKeyPress(inMacEvent);
  3138. } // CFrontApp::EventKeyDown
  3139.  
  3140. //-----------------------------------------------------------------------------
  3141. // About Box & Splash Screen
  3142. //-----------------------------------------------------------------------------
  3143.  
  3144.  
  3145. void CFrontApp::ShowAboutBox()
  3146. {
  3147.     DoGetURL( "about:" );
  3148. }
  3149.  
  3150. void* FE_AboutData( const char* which, char** data_ret, int32* length_ret,
  3151. char** content_type_ret )
  3152. {
  3153.     char* ss = NULL; // security string, of course
  3154.     Handle          data = NULL;
  3155.  
  3156.     try {
  3157.         // Nuke the ismap portion so we can hide the url
  3158.         const char* ismap = strrchr( (char*)which, '?' );
  3159.         CStr255 dataName = which ? which : "";
  3160.         if ( ismap )
  3161.             {
  3162.             ismap++;
  3163.             for ( int i = 1; i <= dataName.Length(); i++ )
  3164.             if (dataName[i] == '?')
  3165.                 {
  3166.                 dataName[0] = i - 1;
  3167.                 break;
  3168.                 }
  3169.             }
  3170.         Boolean         doSprintf = FALSE;
  3171.  
  3172.         /*
  3173.                 about:                  128             text of about box, includes logo
  3174.                 about:logo              129             picture for about box
  3175.                 about:plugins   130             list of installed plug-ins
  3176.                 about:authors   131             text for authors box
  3177.                 about:authors?  132             text for team box
  3178.                 about:teamlogo  133             picture for team box
  3179.                 about:mailintro 134
  3180.                 about:rsalogo   135             picture for rsa logo
  3181.                 about:mozilla   136             mozilla easter egg
  3182.                 about:hype              137             hype sound
  3183.                 about:license   2890    license text
  3184.         */
  3185.         if ( dataName == "" )
  3186.             {
  3187.             data = ::GetResource( 'TEXT', ABOUT_ABOUTPAGE_TEXT );
  3188.             *content_type_ret = TEXT_MDL;
  3189.             doSprintf = true;
  3190.             }
  3191.         else if ( dataName == "logo" )
  3192.             {
  3193.             data = ::GetResource ( 'Tang', ABOUT_BIGLOGO_TANG );
  3194.             *content_type_ret = IMAGE_GIF;
  3195.             }
  3196.         else if ( dataName == "plugins" )
  3197.             {
  3198.             data = ::GetResource ( 'TEXT', ABOUT_PLUGINS_TEXT );
  3199.             *content_type_ret = TEXT_MDL;
  3200.             }
  3201.         else if ( dataName == "authors" )
  3202.             {
  3203.             data = ::GetResource ( 'TEXT', ABOUT_AUTHORS_TEXT );
  3204.             *content_type_ret = TEXT_MDL;
  3205.             }
  3206.         else if ( dataName == "mailintro" )
  3207.             {
  3208.             data = ::GetResource( 'TEXT', ABOUT_MAIL_TEXT );
  3209.             *content_type_ret = TEXT_MDL;
  3210.             }
  3211.         else if ( dataName == "rsalogo" )
  3212.             {
  3213.             data = ::GetResource ('Tang', ABOUT_RSALOGO_TANG);
  3214.             *content_type_ret = IMAGE_GIF;
  3215.             }
  3216.         else if ( dataName == "javalogo" )
  3217.             {
  3218.             data = ::GetResource ('Tang', ABOUT_JAVALOGO_TANG);
  3219.             *content_type_ret = IMAGE_GIF;
  3220.             }
  3221.         else if (dataName == "qtlogo")
  3222.             {
  3223.             data = ::GetResource ('Tang', ABOUT_QTLOGO_TANG);
  3224.             *content_type_ret = IMAGE_GIF;
  3225.             }
  3226.  
  3227.         else if (dataName == "insologo")
  3228.             {
  3229.             data = ::GetResource ('Tang', ABOUT_INSOLOGO_TANG);
  3230.             *content_type_ret = IMAGE_GIF;
  3231.             }
  3232.         else if (dataName == "litronic")
  3233.             {
  3234.             data = ::GetResource ('Tang', ABOUT_LITRONIC_TANG);
  3235.             *content_type_ret = IMAGE_GIF;
  3236.             }
  3237.  
  3238.         else if (dataName == "mclogo")
  3239.             {
  3240.             data = ::GetResource ('Tang', ABOUT_MCLOGO_TANG);
  3241.             *content_type_ret = IMAGE_GIF;
  3242.             }
  3243.  
  3244.         else if (dataName == "mmlogo")
  3245.             {
  3246.             data = ::GetResource ('Tang', ABOUT_MMLOGO_TANG);
  3247.             *content_type_ret = IMAGE_GIF;
  3248.             }
  3249.  
  3250.         else if (dataName == "ncclogo")
  3251.             {
  3252.             data = ::GetResource ('Tang', ABOUT_NCCLOGO_TANG);
  3253.             *content_type_ret = IMAGE_GIF;
  3254.             }
  3255.  
  3256.         else if (dataName == "odilogo")
  3257.             {
  3258.             data = ::GetResource ('Tang', ABOUT_ODILOGO_TANG);
  3259.             *content_type_ret = IMAGE_GIF;
  3260.             }
  3261.  
  3262.         else if (dataName == "symlogo")
  3263.             {
  3264.             data = ::GetResource ('Tang', ABOUT_SYMLOGO_TANG);
  3265.             *content_type_ret = IMAGE_GIF;
  3266.             }
  3267.  
  3268.         else if (dataName == "tdlogo")
  3269.             {
  3270.             data = ::GetResource ('Tang', ABOUT_TDLOGO_TANG);
  3271.             *content_type_ret = IMAGE_GIF;
  3272.             }
  3273.  
  3274.         else if (dataName == "visilogo")
  3275.             {
  3276.             data = ::GetResource ('Tang', ABOUT_VISILOGO_TANG);
  3277.             *content_type_ret = IMAGE_GIF;
  3278.             }
  3279.  
  3280.         else if (dataName == "visilogo")
  3281.             {
  3282.             data = ::GetResource ('Tang', ABOUT_VISILOGO_TANG);
  3283.             *content_type_ret = IMAGE_GIF;
  3284.             }
  3285.  
  3286.         else if (dataName == "coslogo")
  3287.             {
  3288.             data = ::GetResource ('Tang', ABOUT_COSLOGO_TANG);
  3289.             *content_type_ret = IMAGE_JPG;
  3290.             }
  3291.  
  3292.  
  3293.  
  3294. #ifdef FORTEZZA
  3295.         else if (dataName == "litronic")
  3296.             {
  3297.             data = ::GetResource ('Tang', ABOUT_LITRONIC_TANG);
  3298.             *content_type_ret = IMAGE_GIF;
  3299.             }
  3300. #endif
  3301.         else if (dataName == "mozilla")
  3302.             {
  3303.             data = ::GetResource ( 'TEXT', ABOUT_MOZILLA_TEXT );
  3304.             *content_type_ret = TEXT_MDL;
  3305.             }
  3306.         else if (dataName == "hype")
  3307.             {
  3308.             data = ::GetResource ( 'Tang', ABOUT_HYPE_TANG );
  3309.             *content_type_ret = AUDIO_BASIC;
  3310.             }
  3311.         else if ( dataName == "license" )
  3312.             {
  3313.             data = ::GetResource ('TEXT', ABOUT_LICENSE);
  3314.             *content_type_ret = TEXT_PLAIN;
  3315.             }
  3316.         else if ( dataName == "custom" )        // optional resource added by EKit
  3317.             {
  3318.             data = ::GetResource ( 'TEXT', ABOUT_CUSTOM_TEXT );
  3319.             *content_type_ret = TEXT_PLAIN;
  3320.             }
  3321.         #ifdef EDITOR
  3322.         else if ( dataName == "editfilenew" )
  3323.             {
  3324.             data = ::GetResource ( 'TEXT', ABOUT_NEW_DOCUMENT );
  3325.             *content_type_ret = TEXT_HTML;
  3326.             }
  3327.         #endif
  3328.         else if ( dataName == "flamer" )
  3329.             {
  3330.             data = ::GetResource ('Tang', ABOUT_MOZILLA_FLAME);
  3331.             *content_type_ret = IMAGE_GIF;
  3332.             }        
  3333.         else
  3334.             {
  3335.             data = ::GetResource ('TEXT', ABOUT_BLANK_TEXT);
  3336.             *content_type_ret = TEXT_MDL;
  3337.             }
  3338.  
  3339.         // prepare the arguments and return
  3340.         if ( data )
  3341.             {
  3342.             UInt32          dataSize;
  3343.  
  3344.             ::DetachResource( data );
  3345.             ::HNoPurge( data );
  3346.             ::MoveHHi( data );
  3347.  
  3348.             dataSize = GetHandleSize(data);
  3349.  
  3350.             if ( doSprintf )
  3351.                 {
  3352.                 // Security stuff ( 3 strings -> 1 )
  3353.                 char*           s0 = (char *)GetCString(SECURITY_LEVEL_RESID );
  3354.                 char*           s1 = XP_SecurityVersion( 1 );
  3355.                 char*           s2 = XP_SecurityCapabilities();
  3356.                 ThrowIfNil_(s0);
  3357.                 ThrowIfNil_(s1);
  3358.                 ThrowIfNil_(s2);
  3359.                 char * secStr = PR_smprintf( s0, s1, s2 );
  3360.                 ThrowIfNil_(secStr);
  3361.  
  3362.                 // Version
  3363.                 CStr255         vers;
  3364.                 ::GetIndString( vers, ID_STRINGS, APPVERSION_STRING_INDEX );
  3365.  
  3366.  
  3367.                 // Assure that data terminates with nul by appending the NULL string
  3368.                     {
  3369.                     dataSize += 1;
  3370.                     SetHandleSize( data, dataSize);
  3371.                     OSErr err = MemError();
  3372.                     ThrowIfOSErr_(err);
  3373.                     (*data)[dataSize-1] = '\0';
  3374.                     }
  3375.                 
  3376.                 // Create the final string
  3377.                 ::HLock(data);
  3378.                 char * finalStr = PR_smprintf((char*)*data, (char*)vers, (char*)vers, (char*)secStr);
  3379.                 ::HUnlock(data);
  3380.  
  3381.                 XP_FREE( secStr );
  3382.                 ThrowIfNil_(finalStr);
  3383.  
  3384.                 // Make handle out of final string
  3385.  
  3386.                 dataSize = strlen(finalStr) + 1;
  3387.                 Handle finalHandle = ::NewHandle( dataSize );
  3388.                 ThrowIfNil_(finalHandle);
  3389.                 ::BlockMoveData( finalStr, *finalHandle, dataSize );
  3390.                 XP_FREE( finalStr );
  3391.                 // Exchange
  3392.                 ::DisposeHandle(data);
  3393.                 data = finalHandle;
  3394.                 }
  3395.  
  3396.             *data_ret = *data;
  3397.             *length_ret = dataSize;
  3398.             }
  3399.         else
  3400.             {
  3401.             XP_ASSERT(0);
  3402.             *data_ret = NULL;
  3403.             *length_ret = 0;
  3404.             *content_type_ret = NULL;
  3405.             }
  3406.         }
  3407.     catch(...)
  3408.         {
  3409.         Assert_(false);
  3410.         if (data != NULL)
  3411.             {
  3412.             ::DisposeHandle(data);
  3413.             data = NULL;
  3414.             }
  3415.  
  3416.         if (ss != NULL)
  3417.             XP_FREE(ss);
  3418.  
  3419.         *data_ret = NULL;
  3420.         *length_ret = 0;
  3421.         *content_type_ret = NULL;
  3422.         }
  3423.         
  3424.     if (data)
  3425.         ::HLock(data);
  3426.         
  3427.     return data;
  3428. }
  3429.  
  3430. void FE_FreeAboutData( void* data, const char* /*which*/ )
  3431. {
  3432.     if ( !data )
  3433.         return;
  3434.     Handle h = (Handle)data;
  3435.     DisposeHandle( h );
  3436. }
  3437.  
  3438.         
  3439. // ===========================================================================
  3440. //        Ñ Main Program
  3441. // ===========================================================================
  3442.  
  3443. XP_BEGIN_PROTOS
  3444. OSErr    InitLibraryManager(size_t poolsize, int zoneType, int memType);
  3445. void    CleanupLibraryManager(void);
  3446. XP_END_PROTOS
  3447.  
  3448. extern void     Memory_DoneWithMemory();
  3449. extern UInt8    MemoryCacheFlusher(size_t size);
  3450. extern void         PreAllocationHook(void);
  3451.  
  3452. const Size cSystemHeapFudgeFactor = 96 * 1024;
  3453.  
  3454. void main( void )
  3455. {
  3456.     SetDebugThrow_(debugAction_Nothing);
  3457. #ifdef DEBUG
  3458.     //SetDebugSignal_(debugAction_SourceDebugger); // SysBreak broken in MetroNub 1.3.2
  3459.     SetDebugSignal_(debugAction_LowLevelDebugger);
  3460. #else
  3461.     SetDebugSignal_(debugAction_Nothing);
  3462. #endif
  3463.     CFrontApp*            app = NULL;
  3464.  
  3465.     // System Heap check hack
  3466.     Handle sysHandle = ::NewHandleSys(cSystemHeapFudgeFactor);
  3467.     if (sysHandle)
  3468.         ::DisposeHandle(sysHandle);
  3469.     Size maxBlockSize = ::FreeMemSys();
  3470.     if (maxBlockSize < cSystemHeapFudgeFactor)
  3471.         ::ExitToShell();
  3472.  
  3473.     // Initialize the tracing package if we're debugging
  3474. #ifdef DEBUG
  3475.     XP_TraceInit();
  3476. #endif
  3477.  
  3478.     // pkc -- instantiate main thread object.  As side effect, NSPR will create new
  3479.     // subheap if this is the first allocation call, ie, if no static initializers
  3480.     // did an allocation.
  3481.     
  3482.     //-----------------------------------
  3483.     // NOTE: SetApplLimit and MaxApplZone are called from NSPR!
  3484.     // in MacintoshInitializeMemory()
  3485.     //-----------------------------------
  3486.     
  3487.     // Ñ╩initialize QuickDraw
  3488.     UQDGlobals::InitializeToolbox( &qd );
  3489.  
  3490.     // Preference library needs to be initialized at this point because
  3491.     // the msglib thread constructor is making a prefapi call
  3492.     PREF_Init(NULL);
  3493.  
  3494. #if __MC68K__
  3495.     {
  3496.             // Bug #58086: this hack locks the "Enable Java" preference `off' and
  3497.             //    must be removed when Java works for 68K.
  3498.         static const char* inline_javascript_text ="lockPref(\"security.enable_java\", false)";
  3499.         PREF_EvaluateJSBuffer(inline_javascript_text, strlen(inline_javascript_text));
  3500.     }
  3501. #else
  3502.  
  3503.     // Ñ double check to make sure we have Java installed
  3504.     DisableJavaIfNotAvailable();
  3505.     
  3506. #endif
  3507.     
  3508.     // NSPR/MOCHA Initialization
  3509. #ifndef NSPR20
  3510.     PR_Init("Navigator", 0,0,0);
  3511. #endif
  3512.     mozilla_thread = PR_CurrentThread();
  3513. #ifdef NSPR20
  3514.     PR_SetThreadGCAble();
  3515. #endif
  3516.  
  3517.     // Ñ initialize the memory manager
  3518.     //        it's important that this is done VERY early
  3519.     Memory_InitializeMemory();
  3520.     
  3521.     // Ñ╩if we're not on a PowerPC, check that we're on an '020 or later
  3522.     //        and have System 7 installed
  3523.     ConfirmWeWillRun();
  3524.     RNG_RNGInit();        // This needs to be called before the main loop
  3525.     ProcessSerialNumber psn;
  3526.     if (NetscapeIsRunning(psn))
  3527.     {
  3528.         ErrorManager::PlainAlert(NO_TWO_NETSCAPES_RESID);
  3529.         SetFrontProcess(&psn);
  3530.     }
  3531.     else
  3532.     {
  3533.     //    NET_ToggleTrace();
  3534.         
  3535.         app = new CFrontApp;
  3536. #if defined(QAP_BUILD)        
  3537.         //QAPCheck();        
  3538.         QAP_AssistHook (kQAPAppToForeground, 0, NULL, 0, 0);
  3539. #endif
  3540.         app->Run();
  3541.  
  3542. #if defined(QAP_BUILD)        
  3543.         QAP_AssistHook (kQAPAppToBackground, 0, NULL, 0, 0);
  3544. #endif
  3545.  
  3546.         delete app;
  3547.     }
  3548.     
  3549.     Memory_DoneWithMemory();
  3550.  
  3551.     // do this at the very end, god knows who's fetching prefs during cleanup
  3552.     PREF_Cleanup();
  3553. }
  3554.  
  3555. static void InitDebugging()
  3556. {
  3557.     // Ñ╩debugging Setup
  3558. }
  3559.  
  3560. static void ConfirmWeWillRun()
  3561. {
  3562. #ifndef powerc
  3563.     Assert68020();
  3564.     AssertSystem7();
  3565. #endif
  3566.     AssertRequiredGuts();
  3567. }
  3568.  
  3569. //-----------------------------------
  3570. static Boolean NetscapeIsRunning(ProcessSerialNumber& psn)
  3571. // True if other versions of Netscape are running
  3572. //-----------------------------------
  3573. {
  3574.     OSErr err;
  3575.     ProcessInfoRec info;
  3576.     ProcessSerialNumber myPsn;
  3577.     ::GetCurrentProcess(&myPsn);
  3578.     
  3579.     psn.highLongOfPSN = 0;
  3580.     psn.lowLongOfPSN  = kNoProcess;
  3581.     do
  3582.     {
  3583.         err = GetNextProcess(&psn);
  3584.         if( err == noErr )
  3585.         {
  3586.  
  3587.             info.processInfoLength = sizeof(ProcessInfoRec);
  3588.             info.processName = NULL;
  3589.             info.processAppSpec = NULL;
  3590.  
  3591.             err= GetProcessInformation(&psn, &info);
  3592.         }
  3593.         if ((err == noErr) &&
  3594.             ((psn.highLongOfPSN != myPsn.highLongOfPSN) || (psn.lowLongOfPSN != myPsn.lowLongOfPSN)) &&
  3595.             (info.processSignature == emSignature || info.processSignature == 'MOSM'))
  3596.                 return TRUE;
  3597.     } while (err == noErr);
  3598.     return FALSE;
  3599. //-----------------------------------
  3600. void CFrontApp::DoQuit(
  3601.     Int32    inSaveOption)
  3602. //-----------------------------------
  3603. {
  3604.     LDocApplication::DoQuit(inSaveOption);
  3605.  
  3606. //    if(mState == programState_Quitting)
  3607. //        LTSMSupport::DoQuit(inSaveOption);
  3608. }
  3609.  
  3610. //-----------------------------------
  3611. void CFrontApp::DispatchEvent(
  3612.     const EventRecord&    inMacEvent)
  3613. //        From IM-Text 7-22
  3614. //-----------------------------------
  3615. {
  3616.  
  3617.     try
  3618.     {
  3619.         try
  3620.         {
  3621.             if(! LTSMSupport::TSMEvent(inMacEvent))
  3622.                 LDocApplication::DispatchEvent(inMacEvent);
  3623.         }
  3624.         catch (int err) // some people do throw-em!  Also "throw memFullErr" will come here.
  3625.         {
  3626.             throw (OSErr)err;
  3627.         }
  3628.     }
  3629.     // Here we catch anything thrown from anywhere. (OSErr and ExceptionCode).
  3630.     // STR# 7098 is reserved for just this purpose.  See ns/cmd/macfe/restext/macfe.r
  3631.     // These alerts all use ALRT_ErrorOccurred.  See ns/cmd/macfe/rsrc/MacDialogs.rsrc.
  3632.     // The value of ALRT_ErrorOccurred is in reserr.h
  3633.     // The alert says
  3634.     //        "Your last command could not be completed because <reason>"
  3635.     //        "(Error code <nnn>)"
  3636.     catch (OSErr err)
  3637.     {
  3638.         DisplayErrorDialog ( err );
  3639.     }
  3640.     catch (ExceptionCode err)
  3641.     {
  3642.         DisplayExceptionCodeDialog ( err );
  3643.     }
  3644. }
  3645. // ---------------------------------------------------------------------------
  3646. //        Ñ AdjustCursor
  3647. //        From IM-Text 7-22
  3648. // ---------------------------------------------------------------------------
  3649. void CFrontApp::AdjustCursor( const EventRecord& inMacEvent )
  3650. {
  3651. #if defined (JAVA)    
  3652.     if ( UsingCustomAWTFrameCursor() )
  3653.         return;
  3654. #endif /* defined (JAVA) */
  3655.                                     // Find out where the mouse is
  3656.     WindowPtr    macWindowP;
  3657.     Point        globalMouse = inMacEvent.where;
  3658.     Int16        thePart = ::FindWindow( globalMouse, &macWindowP );
  3659.  
  3660.     Boolean        useArrow = TRUE;    // Assume cursor will be the Arrow
  3661.     LWindow* theWindow = NULL;
  3662.  
  3663.     if ( macWindowP )
  3664.     {        // Mouse is inside a Window
  3665.         theWindow = LWindow::FetchWindowObject( macWindowP );
  3666.     }
  3667.     if (( theWindow ) &&
  3668.         (theWindow->IsActive() || theWindow->HasAttribute(windAttr_GetSelectClick)) && // adjust inactive window if one click away - mjc
  3669.         theWindow->IsEnabled() )
  3670.     {
  3671.                                 // Mouse is inside an active and enabled
  3672.                                 //   PowerPlant Window. Let the Window
  3673.                                 //   adjust the cursor shape.
  3674.                                 
  3675.                                 // Get mouse location in Port coords
  3676.         Point    portMouse = globalMouse;
  3677.         theWindow->GlobalToPortPoint( portMouse );
  3678.         
  3679.         theWindow->AdjustCursor( portMouse, inMacEvent );
  3680.         useArrow = FALSE;
  3681.     }
  3682.     if ( useArrow )
  3683.     {
  3684.         // Window didn't set the cursor
  3685.         // Default cursor is the arrow            
  3686.         ::SetCursor( &UQDGlobals::GetQDGlobals()->arrow );                
  3687.     }
  3688.  
  3689.     //
  3690.     // Rather than trying to calculate an accurate mouse region,
  3691.     // we define a region that contains just the one pixel where
  3692.     // the mouse is located. This is quick, and handles the common
  3693.     // case where this application is in the foreground but the user
  3694.     // isn't doing anything. However, any mouse movement will generate
  3695.     // a mouse-moved event.
  3696.     //        
  3697.     ::SetRectRgn( mMouseRgnH, globalMouse.h, globalMouse.v,
  3698.                              globalMouse.h + 1, globalMouse.v + 1 );
  3699. }
  3700.  
  3701.  
  3702.  
  3703. void
  3704. CFrontApp::EventSuspend    (const EventRecord &inMacEvent)
  3705. {
  3706.     CSuspenderResumer::Suspend();
  3707. #ifdef MOZ_MAIL_NEWS
  3708.     CCheckMailContext::SuspendResume();                    // Stop all current notification of mail
  3709. #endif // MOZ_MAIL_NEWS
  3710.     CPluginView::BroadcastPluginEvent(inMacEvent);            // Tell plug-ins about the suspend
  3711.     LDocApplication::EventSuspend(inMacEvent);                // Do the suspend
  3712.  
  3713. #if defined(QAP_BUILD)    
  3714.     QAP_AssistHook (kQAPAppToBackground, 0, NULL, 0, 0);
  3715. #endif
  3716. }
  3717.     
  3718. void
  3719. CFrontApp::EventResume(const EventRecord &inMacEvent)
  3720. {
  3721.     CSuspenderResumer::Resume();
  3722.     LDocApplication::EventResume(inMacEvent);                // Do the resume
  3723.     CPluginView::BroadcastPluginEvent(inMacEvent);            // Tell plug-ins about the resume
  3724. #ifdef MOZ_MAIL_NEWS
  3725.     CCheckMailContext::SuspendResume();                    // Reset mail notification
  3726. #endif // MOZ_MAIL_NEWS
  3727.     CInternetConfigInterface::ResumeEvent();            // check is InternetConfig changed
  3728.  
  3729. #if defined(QAP_BUILD)    
  3730.     QAP_AssistHook (kQAPAppToForeground, 0, NULL, 0, 0);
  3731. #endif
  3732. }
  3733.  
  3734.  
  3735. void
  3736. CFrontApp::EventKeyUp(const EventRecord    &inMacEvent)
  3737. {
  3738.     //
  3739.     // Pass key ups down to the target if it╒s a plug-in. The static variable
  3740.     // sPluginTarget is maintained by CPluginViews when they become or are no
  3741.     // longer the target.  (We know calling ProcessKeyPress for a key up is OK
  3742.     // because CPluginView overrides it.)
  3743.     //
  3744.     CPluginView* pluginTarget = CPluginView::sPluginTarget;
  3745.     if (pluginTarget != NULL && pluginTarget == sTarget)
  3746.         pluginTarget->ProcessKeyPress(inMacEvent);
  3747.     else
  3748.     {
  3749.         /* if it's a CKeyUpReceiver, send the key up. We used to send keyups to
  3750.          * targets if a browser view was on duty, which had two disadvantages: it required
  3751.          * any potential targets in a browser view to handle a key up, and sometimes
  3752.          * the commander chain would be incorrect so key ups were sent to a target in a 
  3753.          * view that was not on duty.
  3754.          */
  3755.         if (dynamic_cast<CKeyUpReceiver *>(sTarget))
  3756.             sTarget->ProcessKeyPress(inMacEvent);
  3757.         /*
  3758.         // Pass key ups down to the target if it has a super commander which is
  3759.         // a browser view. Key up events must be sent to mocha. 1997-02-24 mjc
  3760.         if (CBrowserView::sOnDutyBrowserView != NULL)
  3761.             sTarget->ProcessKeyPress(inMacEvent);        
  3762.         */
  3763.     }
  3764. }
  3765.  
  3766. void
  3767. CFrontApp::ProcessNextEvent()
  3768. {
  3769. #ifdef PROFILE
  3770. #ifdef PROFILE_ON_CAPSLOCK
  3771.     if (IsThisKeyDown(0x39)) // caps lock
  3772.         ProfileStart();
  3773.     else
  3774.         ProfileStop();
  3775. #endif // PROFILE_ON_CAPSLOCK
  3776. #endif // PROFILE
  3777.     try
  3778.     {
  3779.             // Handle all pending NSPR events
  3780.         PR_ProcessPendingEvents(mozilla_event_queue);
  3781.     }
  3782.  
  3783.     catch (OSErr err)
  3784.     {
  3785.         DisplayErrorDialog ( err );
  3786.     }
  3787.     catch (ExceptionCode err)
  3788.     {
  3789.         DisplayExceptionCodeDialog ( err );
  3790.     }
  3791.     
  3792.     //
  3793.     // Plug-ins and Java need key up events, which are masked by default
  3794.     // (the event mask lomem is set to everyEvent - keyUp).  To ensure
  3795.     // that it╒s always set to mask out nothing, reset it here every time
  3796.     // before we call WaitNextEvent.
  3797.     //
  3798.     SetEventMask(everyEvent);                
  3799.     
  3800.     // The block surrounded by *** ... from LApplication::ProcessNextEvent() ***
  3801.     // is identical to LApplication::ProcessNextEvent with one exception:
  3802.     // the EventRecord is declared static in order to persist across calls
  3803.     // to ProcessNextEvent to prevent dangling references to the event
  3804.     // recorded by CApplicationEventAttachment (read the usage notes for
  3805.     // CApplicationEventAttachment).
  3806.     
  3807.     // *** Begin block from LApplication::ProcessNextEvent() ***
  3808.     
  3809.     static EventRecord        macEvent;
  3810.  
  3811.         // When on duty (application is in the foreground), adjust the
  3812.         // cursor shape before waiting for the next event. Except for the
  3813.         // very first time, this is the same as adjusting the cursor
  3814.         // after every event.
  3815.     
  3816.     if (IsOnDuty()) {
  3817.             
  3818.             // Calling OSEventAvail with a zero event mask will always
  3819.             // pass back a null event. However, it fills the EventRecord
  3820.             // with the information we need to set the cursor shape--
  3821.             // the mouse location in global coordinates and the state
  3822.             // of the modifier keys.
  3823.             
  3824.         ::OSEventAvail(0, &macEvent);
  3825.         AdjustCursor(macEvent);
  3826.     }
  3827.     
  3828.         // Retrieve the next event. Context switch could happen here.
  3829.     
  3830.     SetUpdateCommandStatus(false);
  3831.  
  3832. #ifdef PROFILE
  3833. #ifndef PROFILE_WAITNEXTEVENT
  3834.     ProfileSuspend();
  3835. #endif // PROFILE_WAITNEXTEVENT
  3836. #endif // PROFILE
  3837.  
  3838.     Boolean    gotEvent = ::WaitNextEvent(everyEvent, &macEvent, mSleepTime,
  3839.                                         mMouseRgnH);
  3840.  
  3841. #ifdef PROFILE
  3842. #ifndef PROFILE_WAITNEXTEVENT
  3843.     ProfileResume();
  3844. #endif // PROFILE_WAITNEXTEVENT
  3845. #endif // PROFILE
  3846.         
  3847.         // Check if the event should go to a plugin window
  3848.         
  3849.     if (CPluginView::PluginWindowEvent(macEvent))
  3850.         return;
  3851.  
  3852.         // Let Attachments process the event. Continue with normal
  3853.         // event dispatching unless suppressed by an Attachment.
  3854.     
  3855.     if (LAttachable::ExecuteAttachments(msg_Event, &macEvent)) {
  3856.         if (gotEvent) {
  3857.             DispatchEvent(macEvent);
  3858.         } else {
  3859.             UseIdleTime(macEvent);
  3860.         }
  3861.     }
  3862.  
  3863.                                     // Repeaters get time after every event
  3864.     LPeriodical::DevoteTimeToRepeaters(macEvent);
  3865.     
  3866.                                     // Update status of menu items
  3867.     if (IsOnDuty() && GetUpdateCommandStatus()) {
  3868.         UpdateMenus();
  3869.     }
  3870.     
  3871.     // *** End block from LApplication::ProcessNextEvent() ***
  3872. }
  3873.  
  3874.  
  3875. void CFrontApp::DoOpenURLDialog(void)
  3876. {
  3877.     StBlockingDialogHandler    theHandler(liLoadItemWind, this);
  3878.     LWindow* theDialog = theHandler.GetDialog();
  3879.     LEditField* theEdit = (LEditField*)theDialog->FindPaneByID('edit');
  3880.     Assert_(theEdit != NULL);
  3881.     theDialog->SetLatentSub(theEdit);
  3882.     theDialog->Show();
  3883.  
  3884.     MessageT theMessage = msg_Nothing;    
  3885.     while ((theMessage != msg_Cancel) && (theMessage != msg_OK))
  3886.         theMessage = theHandler.DoDialog();
  3887.     
  3888.     if (theMessage == msg_OK)
  3889.         {
  3890.         cstring        curl;
  3891.         CStr255        purl;
  3892.         theEdit->GetDescriptor(purl);
  3893.         CleanUpLocationString (purl);
  3894.         curl = (unsigned char*)purl;
  3895.         DoGetURL(curl);
  3896.         }
  3897. }
  3898.  
  3899.  
  3900. #ifdef EDITOR
  3901. void CFrontApp::DoOpenURLDialogInEditor(void)
  3902. {
  3903.     StBlockingDialogHandler    theHandler(liLoadItemWind, this);
  3904.     LWindow* theDialog = theHandler.GetDialog();
  3905.     LEditField* theEdit = (LEditField*)theDialog->FindPaneByID('edit');
  3906.     Assert_(theEdit != NULL);
  3907.     theDialog->SetLatentSub(theEdit);
  3908.     theDialog->Show();
  3909.  
  3910.     MessageT theMessage = msg_Nothing;    
  3911.     while ((theMessage != msg_Cancel) && (theMessage != msg_OK))
  3912.         theMessage = theHandler.DoDialog();
  3913.     
  3914.     if (theMessage == msg_OK)
  3915.         {
  3916.         cstring        curl;
  3917.         CStr255        purl;
  3918.         // we really should try to do better parsing here
  3919.         theEdit->GetDescriptor( purl );
  3920.         CleanUpLocationString( purl );
  3921.         curl = (unsigned char*)purl;
  3922.  
  3923.         URL_Struct* theURL = NET_CreateURLStruct( curl, NET_DONT_RELOAD );
  3924.         if ( theURL )
  3925.             CEditorWindow::MakeEditWindow( NULL, theURL );
  3926.         }
  3927. }
  3928. #endif // EDITOR
  3929.  
  3930.  
  3931. void CFrontApp::ShowSplashScreen()
  3932. {
  3933.     // Register the splash screen first so that we can show it.
  3934.     RegisterClass_(CSplashScreen);
  3935.     RegisterClass_(CResPicture);
  3936.  
  3937.     mSplashScreen = (CSplashScreen*)LWindow::CreateWindow(2891, this);
  3938.     mSplashScreen->Show();
  3939.     mSplashScreen->UpdatePort();
  3940. }
  3941.  
  3942. void CFrontApp::DestroySplashScreen()
  3943. {
  3944.     delete mSplashScreen;
  3945.     mSplashScreen = NULL;
  3946. }
  3947.  
  3948. void CFrontApp::SplashProgress(CStr255 inMessage)
  3949. {
  3950.     if (sApplication->mSplashScreen != NULL)
  3951.         sApplication->mSplashScreen->SetDescriptor(inMessage);
  3952. }
  3953.  
  3954. //-----------------------------------
  3955. void CFrontApp::ListenToMessage(MessageT inMessage, void * ioParam)
  3956. //-----------------------------------
  3957. {
  3958.     switch (inMessage)
  3959.     {
  3960. #ifdef MOZ_MAIL_NEWS
  3961.         case cmd_GetNewMail:
  3962.         case cmd_NewsGroups:
  3963.         case cmd_MailNewsFolderWindow:
  3964. #endif // MOZ_MAIL_NEWS
  3965. #ifdef EDITOR
  3966.         case cmd_NewWindowEditorIFF:
  3967. //        case cmd_NewMailMessage:
  3968. #endif // EDITOR
  3969.         case cmd_BrowserWindow:
  3970.             ObeyCommand(inMessage);
  3971.             break;
  3972.         case msg_GrowZone:
  3973.             MemoryIsLow();
  3974.             // 1998.01.12 pchen -- replicate fix for bug #85275
  3975.             // We don't know how much memory was freed, so just set bytes freed to 0
  3976.             *((Int32 *)ioParam) = 0;
  3977.             break;
  3978.         default:
  3979.             break;
  3980.     }
  3981. }
  3982.  
  3983. void CFrontApp::LaunchExternalApp(OSType inAppSig, ResIDT inAppNameStringResourceID)
  3984. {
  3985.     Assert_(inAppNameStringResourceID);
  3986.  
  3987.     FSSpec    appSpec;
  3988.     OSErr    err = CFileMgr::FindApplication(inAppSig, appSpec);
  3989.     CStr255    theAppName(::GetCString(inAppNameStringResourceID));
  3990.     CStr255 theMessage;
  3991.     
  3992.     if (err == noErr)
  3993.     {
  3994.         ProcessSerialNumber psn;
  3995.         err = UProcessUtils::LaunchApplication(
  3996.             appSpec, launchContinue + launchNoFileFlags, psn);
  3997.     }
  3998.     
  3999.     switch (err)
  4000.     {
  4001.         case noErr:
  4002.             break;
  4003.             
  4004.         case memFullErr:
  4005.         case memFragErr:
  4006.             theMessage = ::GetCString(MEMORY_ERROR_LAUNCH);
  4007.             ::StringParamText(theMessage, theAppName);
  4008.             ErrorManager::PlainAlert(theMessage);
  4009.             break;
  4010.             
  4011.         case fnfErr:
  4012.             theMessage = ::GetCString(FNF_ERROR_LAUNCH);
  4013.             ::StringParamText(theMessage, theAppName);
  4014.             ErrorManager::PlainAlert(theMessage);
  4015.             break;
  4016.             
  4017.         default:
  4018.             theMessage = ::GetCString(MISC_ERROR_LAUNCH);
  4019.             ::StringParamText(theMessage, theAppName);
  4020.             ErrorManager::PlainAlert(theMessage);
  4021.             break;
  4022.     }
  4023. }
  4024.  
  4025. // Tries to find local file 3270/HE3270EN.HTM
  4026. Boolean CFrontApp::Find3270Applet(FSSpec& tn3270File)
  4027. {
  4028.     Boolean found = false;
  4029.     FSSpec appFolder = CPrefs::GetFilePrototype( CPrefs::NetscapeFolder );
  4030.     
  4031.     CStr255 folderName;    
  4032.     ::GetIndString( folderName, 300, ibm3270Folder );
  4033.     
  4034.     if ( CFileMgr::FindWFolderInFolder(appFolder.vRefNum, appFolder.parID,
  4035.          folderName, &tn3270File.vRefNum, &tn3270File.parID) == noErr )
  4036.     {
  4037.         ::GetIndString( tn3270File.name, 300, ibm3270File );
  4038.  
  4039.         found = CFileMgr::FileExists(tn3270File);
  4040.     }
  4041.     return found;
  4042. }
  4043.  
  4044. void CFrontApp::Launch3270Applet()
  4045. {
  4046.     Boolean ok = false;
  4047.     FSSpec tn3270File;
  4048.     if ( Find3270Applet(tn3270File) )
  4049.     {
  4050.         char* url = CFileMgr::GetURLFromFileSpec(tn3270File);
  4051.         if (url) {
  4052.             // Opens the URL in a new window (copied from DoGetURL)
  4053.             //  !! winfe opens a window with no toolbars, if we care.
  4054.             URL_Struct* theURL = NET_CreateURLStruct(url, NET_DONT_RELOAD);
  4055.             if (FE_MakeNewWindow(NULL, theURL, NULL, NULL) != NULL)
  4056.                 ok = true;
  4057.             free(url);
  4058.         }
  4059.     }
  4060.     if (!ok) {
  4061.         ErrorManager::PlainAlert(ERROR_LAUNCH_IBM3270);
  4062.     }
  4063. }
  4064.  
  4065. FSSpec CFrontApp::CreateAccountSetupSpec()
  4066. {
  4067.     FSSpec            asw;
  4068.  
  4069.     asw = CPrefs::GetFilePrototype( CPrefs::NetscapeFolder );
  4070.     ::GetIndString( asw.name, 300, aswName );
  4071.     return asw;
  4072. }
  4073.  
  4074. Boolean CFrontApp::LaunchAccountSetup()
  4075. {
  4076.     FSSpec            tmp = CreateAccountSetupSpec();
  4077.     
  4078.     LFile            aswFile( tmp );
  4079.     Handle            alias;
  4080.     OSErr            err;
  4081.     FSSpec            startAswFile;
  4082.     Boolean            wasChanged;
  4083.     
  4084. #ifdef DEBUG
  4085.     Try_
  4086.     {
  4087. #endif
  4088.  
  4089.         aswFile.OpenResourceFork( fsRdPerm );
  4090.  
  4091. #ifdef DEBUG
  4092.     }
  4093.     Catch_( inErr )
  4094.     {
  4095.         StandardFileReply        reply;
  4096.         AliasHandle                alias;
  4097.         SFTypeList                types;
  4098.         
  4099.         UDesktop::Deactivate();
  4100.         ::StandardGetFile( NULL, -1, types, &reply );
  4101.         UDesktop::Activate();
  4102.  
  4103.         if ( reply.sfGood )
  4104.         {
  4105.             LFile        startFile( reply.sfFile );
  4106.             
  4107.             aswFile.CreateNewFile( emSignature, 'ASWl', smSystemScript ); 
  4108.             aswFile.OpenResourceFork( fsWrPerm );
  4109.             alias = startFile.MakeAlias();
  4110.             if ( alias )
  4111.                 AddResource( (Handle)alias, 'alis', 1, reply.sfFile.name );
  4112.             aswFile.CloseResourceFork();
  4113.             aswFile.OpenResourceFork( fsRdPerm );
  4114.         }
  4115.     }
  4116.     EndCatch_
  4117.     
  4118. #endif DEBUG
  4119.  
  4120.     alias = ::Get1Resource( 'alis', 1 );
  4121.     if ( !alias )
  4122.         return FALSE;
  4123.  
  4124.     err = ::ResolveAlias( NULL, (AliasHandle)alias, &startAswFile, &wasChanged );
  4125.     if ( err == noErr )
  4126.     {
  4127.         CFrontApp::GetApplication()->SendAEOpenDoc( startAswFile );
  4128.         return TRUE;
  4129.     }
  4130.     return FALSE; 
  4131. }
  4132.  
  4133. static void launchNetcasterCallback(void* closure);
  4134.  
  4135. static void launchNetcasterCallback(void* /*closure*/)
  4136. {
  4137.     FE_RunNetcaster(NULL);
  4138. }
  4139.  
  4140. // Launch Netcaster on a timeout to avoid interfering with other components because
  4141. // it is slow to start up.
  4142. void CFrontApp::LaunchNetcaster()
  4143. {
  4144.      FE_SetTimeout(launchNetcasterCallback, NULL, 0);
  4145. }
  4146.  
  4147. // We keep track of the Netcaster context in the app so we can assure ourselves
  4148. // that only one Netcaster context will be open at any given time.  These calls
  4149. // are used by FE_RunNetcaster to either launch Netcaster (if the netcaster context
  4150. // is NULL) or to activate its window (if not).  The alternative would have been
  4151. // to use named contexts; the disadvantage is that the Netcaster window could be
  4152. // spoofed, and that we would have a performance hit whenever the Netcaster object
  4153. // were referenced (such as from JS). - EA
  4154.  
  4155. //-----------------------------------
  4156. MWContext *CFrontApp::GetNetcasterContext()
  4157. //-----------------------------------
  4158. {
  4159.     return mNetcasterContext;
  4160. }
  4161.  
  4162. //-----------------------------------
  4163. void CFrontApp::SetNetcasterContext(MWContext *context)
  4164. //-----------------------------------
  4165. {
  4166.     mNetcasterContext = context;    
  4167. }
  4168.  
  4169. // 97-08-23 pchen -- This method should be called when we're "low on memory."
  4170. // For now, we just call LJ_ShutdownJava().
  4171. //-----------------------------------
  4172. void CFrontApp::MemoryIsLow()
  4173. //-----------------------------------
  4174. {
  4175. #if defined (JAVA)
  4176.     // Call LJ_ShutdownJava() if Java is running
  4177.     if (LJ_GetJavaStatus() == LJJavaStatus_Running)
  4178.         LJ_ShutdownJava();
  4179. #endif /* defined (JAVA) */
  4180. }
  4181.  
  4182. #pragma mark -
  4183.  
  4184. //======================================
  4185. //        class CSplashScreen
  4186. //======================================
  4187.  
  4188. extern Boolean pref_FindAutoAdminLib(FSSpec& spec);
  4189.  
  4190. CSplashScreen::CSplashScreen(LStream* inStream)
  4191.     :    LWindow(inStream)
  4192. {
  4193.     mStatusCaption = NULL;
  4194.     mPictureResourceFile = NULL;
  4195. }
  4196.  
  4197. CSplashScreen::~CSplashScreen()
  4198. {
  4199.     ResIDT thePicID = mBackPicture->GetPictureID();
  4200.     
  4201.     // this returns the picture that has already been loaded by the picture pane
  4202.     PicHandle thePicHandle = ::GetPicture(thePicID);            
  4203.     if (thePicHandle != NULL)
  4204.         ::ReleaseResource((Handle)thePicHandle);
  4205.     
  4206.     if (mPictureResourceFile) {
  4207.         mPictureResourceFile->CloseResourceFork();
  4208.         delete mPictureResourceFile;
  4209.     }
  4210. }
  4211.  
  4212. void CSplashScreen::SetDescriptor(ConstStringPtr inDescriptor)
  4213. {
  4214.     mStatusCaption->SetDescriptor(inDescriptor);
  4215.     // we're relying on the fact that the splash window has erase on
  4216.     // update set so that the old caption gets erased in the window's
  4217.     // background color (which we're assuming to be black)
  4218.     mStatusCaption->UpdatePort();
  4219. }
  4220.  
  4221. void CSplashScreen::FinishCreateSelf(void)
  4222. {
  4223.     LWindow::FinishCreateSelf();
  4224.     
  4225.     mStatusCaption = (LCaption*)FindPaneByID(1);
  4226.     Assert_(mStatusCaption != NULL);
  4227.     
  4228.     mBackPicture = (CResPicture*)FindPaneByID(2);
  4229.     Assert_(mBackPicture != NULL);    
  4230.     
  4231.         // choose the b/w or color splash screen
  4232.     ResIDT thePicID = (GetDepth(GetDeepestDevice()) == 1) ? 129 : 128;
  4233.     
  4234.     // If AutoAdminLib is installed, then load the Communicator Pro
  4235.     // splash screen from the library's resource fork.
  4236.     // Otherwise, picture comes from app resource.
  4237.     try {
  4238.         FSSpec autoAdminLib;
  4239.         if ( pref_FindAutoAdminLib(autoAdminLib) ) {
  4240.             mPictureResourceFile = new LFile(autoAdminLib);
  4241.             mPictureResourceFile->OpenResourceFork(fsRdPerm);
  4242.             
  4243.             mBackPicture->SetResFileID( mPictureResourceFile->GetResourceForkRefNum() );
  4244.         }
  4245.     }
  4246.     catch (...) {
  4247.     }
  4248.     
  4249.     mBackPicture->SetPictureID(thePicID);
  4250. }
  4251.  
  4252.  
  4253. //
  4254. // THIS IS HERE ONLY AS A PLACEHOLDER UNTIL I PUT THE NAV-SERVICES CODE INTO THE SOURCE TREE....
  4255. // DO NOT RELY ON THIS IMPLEMENTATION OR EVEN THAT THIS ROUTINE USES THE SF PACKAGE
  4256. //
  4257. Boolean SimpleOpenDlog ( short numTypes, const OSType typeList[], FSSpec* outFSSpec )
  4258. {
  4259.     Boolean fileSelected = false;
  4260.     StandardFileReply myReply;
  4261.     if (CApplicationEventAttachment::CurrentEventHasModifiers(optionKey))
  4262.         ::StandardGetFile(NULL, numTypes, typeList, &myReply);
  4263.     else
  4264.         ::StandardGetFile(NULL, -1, NULL, &myReply);
  4265.     fileSelected = myReply.sfGood;
  4266.     *outFSSpec = myReply.sfFile;
  4267.  
  4268.     return fileSelected;
  4269.     
  4270. } // SimpleOpenDialog
  4271.