home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / central / RandomFrontEndCrap.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  40.4 KB  |  1,476 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. // RandomFrontEndCrap.cp
  20.  
  21.  
  22. #include "fe_proto.h"
  23. #include "RandomFrontEndCrap.h"
  24. #include "CNSContext.h"
  25. #include "CBrowserContext.h"
  26. #include "nppg.h"
  27. #include "libimg.h"
  28. #include "libi18n.h"
  29. #include "uprefd.h"
  30. #include "mimages.h"
  31. #include "earlmgr.h"
  32. #include "UStdDialogs.h"
  33. #include "macutil.h"
  34. #include "CHTMLView.h"
  35. #include "CHyperScroller.h" // for FE_QueryChrome
  36. #include "resgui.h" // for 'neverAgain'
  37. #include "ufilemgr.h"
  38. #include "prefwutil.h" // for CFilePicker
  39. #include "mime.h" // for FE_UsersOrganization proto
  40. #include "msgcom.h" // for FE_GetTempFileFor proto
  41. #include "StBlockingDialogHandler.h"
  42.  
  43.     // stuff added by deeje for the chromeless window hack
  44. #include "CWindowMediator.h"
  45. #include "CURLDispatcher.h"
  46. #include "CBrowserWindow.h"
  47. #ifdef MOZ_MAIL_NEWS
  48. #include "CMessageWindow.h"
  49. #include "CThreadWindow.h"
  50. #endif
  51.  
  52. #include "CMochaHacks.h" // for managing dependent windows in javascript - 1997-02-22 mjc
  53. #include "findw.h" // to set up find with CFindWindow statics -1997-02-27 mjc
  54.  
  55. #include "uapp.h"        /* for GetApplication - EA */
  56. #include "VerReg.h"     /* for Netcaster installed checks - EA*/
  57. #include "xpgetstr.h"    /* for Netcaster error message - EA */
  58. #include "uerrmgr.h"    /* for Netcaster error message - EA */
  59. #include "libmocha.h"    /* Netcaster checks if mocha is enabled */
  60. #include "java.h"    /* Netcaster checks if java is enabled. */
  61.  
  62. #include "uprefd.h"
  63. #include "InternetConfig.h"
  64. GDHandle DeviceForWindow(LWindow* inWindow);
  65.  
  66. #define WANT_ENUM_STRING_IDS 
  67. #include "allxpstr.h"         /* preferred mechanism for Netcaster error message - EA */
  68. #undef WANT_ENUM_STRING_IDS 
  69.  
  70. NSPR_BEGIN_EXTERN_C
  71. MWContext * FE_GetRDFContext();
  72. NSPR_END_EXTERN_C
  73.  
  74. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  75. //
  76. #pragma mark --- CONTEXT CALLBACKS ---
  77. //
  78. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  79.  
  80. //    This is called when there's a chance that the state of the
  81. //    Stop button (and corresponding menu item) has changed.
  82. //    The FE should use XP_IsContextStoppable to determine the
  83. //    new state.
  84.  
  85. void FE_UpdateStopState( MWContext*  )
  86. {
  87. // FIX ME!!! we should broadcast from the context
  88. //    NETSCAPECONTEXT(context)->UpdateStopState();    
  89.     // this had an empty NetscapeContext implementation.
  90.     // CHyperWin had an implementation that adjusted the buttons
  91. }
  92.  
  93. // FE_ScrollDocTo needed for javascript window.scrollTo() function - mjc 1/30/97
  94. void FE_ScrollDocTo(MWContext *inContext, int /*inLocation*/, Int32 inX, Int32 inY)
  95. {    
  96.     CHTMLView* theHTMLView = ExtractHyperView(inContext);
  97.     if (theHTMLView != nil) theHTMLView->SetDocPosition(0, inX, inY, true);
  98. }
  99.  
  100. // FE_ScrollDocBy needed for javascript window.scrollBy() function - mjc 1/30/97
  101. void FE_ScrollDocBy(MWContext *inContext, int /*inLocation*/, Int32 inX, Int32 inY)
  102. {
  103.     CHTMLView* theHTMLView = ExtractHyperView(inContext);
  104.     if (theHTMLView != nil)
  105.     {
  106.         SPoint32 theScrollPosition;
  107.         theHTMLView->GetScrollPosition(theScrollPosition);
  108.         if (theHTMLView != nil) theHTMLView->SetDocPosition(0, theScrollPosition.h + inX, theScrollPosition.v + inY, true);
  109.     }
  110. }
  111.  
  112. PRBool FE_HandleLayerEvent(
  113.     MWContext*                inContext,
  114.     CL_Layer*                inLayer, 
  115.     CL_Event*                inEvent)
  116. {
  117.     PRBool result = PR_FALSE;
  118.     CBrowserContext* theBrowserContext = ExtractBrowserContext(inContext);
  119.     if (theBrowserContext != NULL)
  120.         result = theBrowserContext->HandleLayerEvent(inLayer, inEvent);
  121.     return result;
  122. }
  123.  
  124. PRBool FE_HandleEmbedEvent(
  125.     MWContext*                inContext, 
  126.     LO_EmbedStruct*            inEmbed, 
  127.     CL_Event*                inEvent)
  128. {
  129.     CBrowserContext* theBrowserContext = ExtractBrowserContext(inContext);
  130.     Assert_(theBrowserContext != NULL);
  131.     return theBrowserContext->HandleEmbedEvent(inEmbed, inEvent);
  132. }
  133.  
  134. MWContext* FE_MakeGridWindow(
  135.     MWContext*                 inParentContext,
  136.     void*                     inHistList,
  137.     void*                     inHistEntry,
  138.     int32                    inX,
  139.     int32                     inY,
  140.     int32                    inWidth,
  141.     int32                    inHeight,
  142.     char*                     inURLString,
  143.     char*                     inWindowTarget,
  144.     int8                    inScrollMode,
  145.     NET_ReloadMethod         inForceReload,
  146.     Bool                     inNoEdge)
  147. {
  148.     CBrowserContext* theBrowserContext = ExtractBrowserContext(inParentContext);
  149.     Assert_(theBrowserContext != NULL);
  150.     return theBrowserContext->CreateGridContext(inHistList, inHistEntry, inX, inY, inWidth, inHeight, inURLString,
  151.                                                 inWindowTarget, inScrollMode, inForceReload, inNoEdge);
  152. }
  153.  
  154. void* FE_FreeGridWindow(
  155.     MWContext*                 inContext,
  156.     XP_Bool                 inSaveHistory)
  157. {
  158.     CBrowserContext* theBrowserContext = ExtractBrowserContext(inContext);
  159.     Assert_(theBrowserContext != NULL);
  160.     return theBrowserContext->DisposeGridContext(inSaveHistory);
  161. }
  162.  
  163. void FE_RestructureGridWindow(
  164.     MWContext*             inContext,
  165.     int32                 inX,
  166.     int32                 inY,
  167.     int32                 inWidth,
  168.     int32                 inHeight)
  169. {
  170.     CBrowserContext* theBrowserContext = ExtractBrowserContext(inContext);
  171.     Assert_(theBrowserContext != NULL);
  172.     theBrowserContext->RestructureGridContext(inX, inY, inWidth, inHeight);
  173. }
  174.  
  175. void FE_GetFullWindowSize(
  176.     MWContext*             inContext,
  177.     int32*                 outWidth,
  178.     int32*                 outHeight)
  179. {
  180.     CBrowserContext* theBrowserContext = ExtractBrowserContext(inContext);
  181.     Assert_(theBrowserContext != NULL);
  182.     theBrowserContext->GetFullGridSize(*outWidth, *outHeight);
  183. }
  184.  
  185. void FE_GetEdgeMinSize(MWContext */*context*/, int32 *size)
  186. {
  187.     *size = 5;
  188. }
  189.  
  190.  
  191. void FE_LoadGridCellFromHistory(
  192.     MWContext*             inContext,
  193.     void*                 inHistEntry,
  194.     NET_ReloadMethod     inReload)
  195. {
  196.     CBrowserContext* theBrowserContext = ExtractBrowserContext(inContext);
  197.     Assert_(theBrowserContext != NULL);
  198.     theBrowserContext->ReloadGridFromHistory(inHistEntry, inReload);
  199. }
  200.  
  201.  
  202.  
  203.  
  204. void FE_SetRefreshURLTimer(
  205.     MWContext*                context,
  206.     uint32                     seconds,
  207.     char*                    refresh_url)
  208. {
  209.     if (ExtractHyperView(context))
  210.         ExtractHyperView(context)->SetTimerURL(seconds, refresh_url);
  211. }
  212.  
  213. void FE_ShowScrollBars(MWContext *context, XP_Bool show)
  214. {
  215. //Assert_(false);
  216.     if (show)
  217.         ExtractHyperView(context)->SetScrollMode(LO_SCROLL_YES);
  218.     else
  219.         ExtractHyperView(context)->SetScrollMode(LO_SCROLL_NO);
  220. }
  221.  
  222. int FE_GetURL( MWContext* context, URL_Struct* url )
  223. {
  224.     CNSContext* theContext = ExtractNSContext(context);
  225.     Assert_(theContext != NULL);
  226. #if defined(MOZ_MAIL_NEWS) || defined (MOZ_LDAP)
  227.     // 97-06-04 pkc -- check to see if we have correct context
  228.     char *address = NET_URLStruct_Address(url);
  229.     // 97-06-09 pkc -- for some reason, "search-libmsg:" isn't caught by
  230.     // MSG_RequiresBrowserWindow
  231.     if (strcasecomp(address, "search-libmsg:") &&
  232.         strncasecomp(address, "ldap:", 5) &&
  233.         MSG_RequiresBrowserWindow(address))
  234.     {
  235.         CBrowserContext* browserContext = ExtractBrowserContext(context);
  236.         if (context->type != MWContextBrowser || !browserContext)
  237.         {
  238.             // We have a URL that requires a browser window, but we don't have a
  239.             // browser context. Dispatch URL to new window
  240. //            CURLDispatcher::GetURLDispatcher()->DispatchToView(NULL, url, FO_CACHE_AND_PRESENT, true);
  241.             CURLDispatcher::DispatchURL(url, NULL, false, true);
  242.             return 0;
  243.         }
  244.         else
  245.         {
  246.             theContext->SwitchLoadURL(url, FO_CACHE_AND_PRESENT);
  247.             return 0;
  248.         }
  249.     }
  250.     else
  251. #endif // MOZ_MAIL_NEWS || MOZ_LDAP
  252.     {
  253.         if (theContext)
  254.         {
  255.             theContext->SwitchLoadURL(url, FO_CACHE_AND_PRESENT);
  256.             return 0;
  257.         }
  258.     }
  259.     return -1;
  260. }
  261.  
  262. MWContext*
  263. FE_MakeBlankWindow( MWContext* /*old_context*/, URL_Struct*, char* /*window_name*/ )
  264. {
  265. Assert_(false);
  266.     return NULL;
  267. }
  268.  
  269. void FE_SetWindowLoading(MWContext *, URL_Struct *,
  270.         Net_GetUrlExitFunc **exit_func)
  271. {
  272. //    We should probably to the corresponding thing in the new world
  273. //    NETSCAPECONTEXT(context)->StartSpinIcon(url, FALSE);
  274.     // This is safe for now...
  275.     *exit_func = EarlManager::DispatchFinishLoadURL;
  276. }
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285. MWContext* FE_MakeNewWindow(MWContext* old_context,
  286.                             URL_Struct* url,
  287.                             char* window_name,
  288.                             Chrome* chrome)
  289. {
  290.     
  291.         // I have no idea what I'm doing, so bear with me
  292.         // 1997-01-07 deeje
  293.     
  294.     MWContext*        theContext = nil;
  295.     
  296.     try
  297.     {
  298.         ResIDT                    whichLayout = CBrowserWindow::res_ID;
  299.         CBrowserContext*        theBrowserContext = nil;
  300.         MWContext*                theTargetContext = XP_FindNamedContextInList(old_context, window_name);
  301.         if (theTargetContext != nil)
  302.         {
  303.             theBrowserContext = ExtractBrowserContext(theTargetContext);
  304.         }
  305.         
  306.         Boolean isDocInfoWindow = IsDocInfoWindow(window_name);
  307.         
  308.         short docInfoWindowWidth = qd.screenBits.bounds.right - 100;
  309.         const short maxDocInfoWindowWidth = 600;
  310.         
  311.         if (docInfoWindowWidth > maxDocInfoWindowWidth)
  312.             docInfoWindowWidth = maxDocInfoWindowWidth;
  313.         
  314.         short docInfoWindowHeight = qd.screenBits.bounds.bottom - 200;
  315.         const short maxDocInfoWindowHeight = 900;
  316.         
  317.         if (docInfoWindowHeight > maxDocInfoWindowHeight)
  318.             docInfoWindowHeight = maxDocInfoWindowHeight;
  319.         
  320.         // mjc select layout based on chrome. Relevant fields are titlebar, topmost, and z-lock.
  321.         if (chrome != nil)
  322.         {
  323.             const ResIDT floatingHelpWindowResID = 1015;
  324.             
  325.             if (chrome->type == MWContextDialog)
  326.             {
  327.                 if (isDocInfoWindow)
  328.                 {
  329. //                    chrome->topmost = true;
  330.                     chrome->location_is_chrome = true;
  331.                     chrome->w_hint = docInfoWindowWidth;
  332.                     chrome->h_hint = docInfoWindowHeight;
  333. //                    whichLayout = floatingHelpWindowResID;
  334.                 }
  335. //                else if (chrome->allow_resize && chrome->allow_close)
  336.                 if (chrome->allow_resize && chrome->allow_close)
  337.                 {
  338.                     whichLayout = CBrowserWindow::res_ID;            // DOH!  it can be a MWContextDialog and still have non-dialog window bits!
  339.                 }
  340.                 else
  341.                 {
  342.                     whichLayout = CBrowserWindow::dialog_res_ID;
  343.                 }
  344.             }
  345.             else if ( chrome->type == MWContextHTMLHelp )
  346.                 whichLayout = floatingHelpWindowResID;
  347.             else if (chrome->hide_title_bar == true)
  348.                 whichLayout = CBrowserWindow::titlebarless_res_ID; // titlebar-less browser window
  349.             else if (chrome->topmost == true && chrome->hide_title_bar == false) // removed z-lock == true test - 2/11/97 mjc
  350.                 whichLayout = CBrowserWindow::floating_res_ID;
  351.             else whichLayout = CBrowserWindow::res_ID;
  352.         }
  353.  
  354.             // ÑÑÑ also, there are places in the code (ie CURLDispatcher) which check the res_ID of a window
  355.             // to determine a course of action.  So far, most of the code assumes only two ID values,
  356.             // which is obviously not true anymore.  This needs to be addressed as well.   deeje 1997-01-16
  357.             
  358.             // A browser window now has a family of res ids. URLs are dispatched to windows by
  359.             // finding the window corresponding to the context passed in. The type of window searched
  360.             // for (browser or editor), depends on the res id passed in. There is no mapping of res ids
  361.             // to type, and there should be. This works as is because the DispatchToView defaults the
  362.             // res id to CBrowserWindow::res_id, so all the variations map to the browser window type.
  363.             // 1997-02-28 mjc
  364.             
  365.             // make the window
  366.         CURLDispatcher::DispatchURL(url, theBrowserContext, false, true, whichLayout, false);
  367.         
  368.         CBrowserWindow* theWindow = CURLDispatcher::GetLastBrowserWindowCreated();
  369.                 
  370.         if (theWindow != nil)
  371.         {
  372.             theBrowserContext = (CBrowserContext*)theWindow->GetWindowContext();
  373.             theContext = *theBrowserContext;
  374.             if ((theContext != nil) && (window_name != nil))
  375.             {
  376.                 theContext->name = XP_STRDUP(window_name);
  377.                 // 97-05-08 pkc -- set restricted target flag for "special" browser windows,
  378.                 // e.g. view source and doc info windows
  379.                 if (IsSpecialBrowserWindow(window_name))
  380.                     theBrowserContext->SetRestrictedTarget(true);
  381.             }
  382.             if (chrome != nil) 
  383.             {
  384.                 theWindow->SetCanSaveStatus(false);
  385.                 if (chrome->dependent)
  386.                     CMochaHacks::AddDependent(old_context, theContext);
  387.                 if (chrome->hide_title_bar) theWindow->ClearAttribute(windAttr_TitleBar); // work around Constructor bug which sets this by default for non-standard windows
  388.                 if (chrome->restricted_target) theBrowserContext->SetRestrictedTarget(true);
  389.                 theWindow->SetChromeInfo(chrome, false, true);
  390.             }
  391.             if (isDocInfoWindow)
  392.             {
  393.                 Point globalTopLeft =
  394.                 {
  395.                     qd.screenBits.bounds.bottom - docInfoWindowHeight - 50,
  396.                     qd.screenBits.bounds.right - docInfoWindowWidth - 50
  397.                 };
  398.                 
  399.                 CSaveWindowStatus::MoveWindowTo(theWindow, globalTopLeft);
  400.             }
  401.             /* jpm changes: get Shift_JIS & MacRoman 8bit to display correctly in security dialogs */
  402.             if ((chrome != nil) && (theContext != nil))
  403.             {
  404.                 if (chrome->type == MWContextDialog)
  405.                 {
  406.                     CNSContext* theNSContext = ExtractNSContext(theContext);
  407.                     Assert_(theNSContext != NULL);
  408.                     if (isDocInfoWindow)
  409.                     {
  410.                         /* Doc Info gets the user-selectable default encoding */
  411.                         theNSContext->SetDefaultCSID(INTL_DefaultWinCharSetID(NULL));
  412.                     } else {
  413.                         if (!IsViewSourceWindow(window_name))
  414.                         {
  415.                             /* all other HTML dialogs get the localised clients default encoding */
  416.                             theNSContext->SetDefaultCSID(INTL_CharSetNameToID(INTL_ResourceCharSet()));
  417.                         }
  418.                     }
  419.                     /* what about View Source? It inherits the encoding of the page being viewed */
  420.                 }
  421.             }
  422.             /* jpm end changes */
  423.             theWindow->Show();
  424.         }
  425.     }
  426.     catch(...)
  427.     {
  428.     }
  429.     
  430.     return theContext;
  431. }
  432.  
  433.  
  434.  
  435. void FE_UpdateChrome(MWContext *inContext, Chrome *inChrome)
  436. {
  437.     CBrowserWindow* theWindow = CBrowserWindow::WindowForContext(ExtractBrowserContext(inContext));
  438.     
  439.     if (theWindow != nil)
  440.     {
  441.         theWindow->SetChromeInfo(inChrome);
  442.     }
  443. }
  444.  
  445. void FE_QueryChrome(MWContext *inContext, Chrome *inChrome)
  446. {
  447.     CBrowserWindow* theWindow = CBrowserWindow::WindowForContext(ExtractBrowserContext(inContext));
  448.  
  449.     if (theWindow != nil)
  450.     {
  451.         theWindow->GetChromeInfo(inChrome);
  452.     }
  453.     /* special case for inner width and height which are frame inner width and height if we
  454.      * are handed a frame, and window inner width and height if we are handed a window.
  455.      */
  456.     if (inContext->grid_parent != NULL)
  457.     {
  458.          CHTMLView* theView = ExtractHyperView(inContext);
  459.          if (theView)
  460.          {
  461.             CHyperScroller* theScroller = dynamic_cast<CHyperScroller*>(theView->GetSuperView());
  462.             SDimension16    theInnerSize;
  463.             if (theScroller) theScroller->GetFrameSize(theInnerSize);
  464.             else theView->GetFrameSize(theInnerSize);
  465.             inChrome->w_hint                    = theInnerSize.width;
  466.             inChrome->h_hint                    = theInnerSize.height;
  467.          }
  468.     }
  469.          
  470. }
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477. void FE_DestroyWindow( MWContext* context )
  478. {
  479.     LView* view = ExtractHyperView(context);
  480.     if (view)
  481.     {
  482.         while( view != NULL )
  483.         {
  484.             view = view->GetSuperView();
  485.             if (view)
  486.             {
  487.                 LWindow* window = dynamic_cast<LWindow*>(view);
  488.                 if (window)
  489.                 {
  490.                     window->ObeyCommand(cmd_Close, NULL);
  491.                     break;
  492.                 }
  493.             }
  494.         }
  495.         CMochaHacks::ClearSelectionForContext( context );
  496.     }
  497. }
  498.  
  499. void FE_Message(MWContext* context, const char* msg)
  500. {
  501.     if (context && context->type == MWContextBiff)
  502.         return;
  503.     
  504.     CStr255 pmessage( msg );
  505.     StripDoubleCRs( pmessage );
  506.  
  507.     LCommander* inSuper = LCommander::GetTopCommander();
  508.     StBlockingDialogHandler theHandler( WIND_MessageDialog, inSuper);
  509.     LWindow* theDialog = theHandler.GetDialog();
  510.  
  511.     // set the message
  512.     LCaption* theCaption = (LCaption*)theDialog->FindPaneByID( PaneID_AlertCaption );
  513.     Assert_( theCaption != NULL );
  514.     theCaption->SetDescriptor( pmessage );
  515.  
  516.     if (UStdDialogs::TryToInteract())
  517.     {
  518.         theDialog->Show();
  519.         MessageT theMessage = msg_Nothing;
  520.         while(theMessage == msg_Nothing)
  521.             theMessage = theHandler.DoDialog();
  522.     }
  523. }
  524.  
  525. void FE_Alert( MWContext* context, const char* msg )
  526. {
  527.     if ( context )
  528.     {
  529.         if (context->type == MWContextBiff)
  530.             return;
  531.         CNSContext* theContext = ExtractNSContext(context);
  532.         Assert_(theContext != NULL);
  533.         if (theContext)
  534.             theContext->Alert(msg);
  535.     }
  536.     else
  537.     {
  538.         CStr255     pmessage( msg );
  539.         StripDoubleCRs( pmessage );
  540.         UStdDialogs::Alert(pmessage, eAlertTypeCaution);
  541.     }
  542. }
  543.  
  544. char* FE_URLToLocalName( char *inURL )
  545. {
  546.     if( inURL == NULL )
  547.         return NULL;
  548.  
  549.     char *  url = XP_STRDUP( inURL ); // Get our own copy
  550.     if ( url == NULL )
  551.         return NULL;
  552.     
  553.     // chop off everything after the first '?'
  554.     char *end = XP_STRCHR(url, '?');
  555.     if ( end )
  556.         *end = '\0';
  557.     
  558.     // chop off everything after the first '#'
  559.     end = XP_STRCHR( url, '#' );
  560.     if ( end )
  561.         *end = '\0';
  562.     
  563.     // Keep only what is to the right of the last slash
  564.     char *front = XP_STRRCHR(url, '/');
  565.     if ( front )
  566.         strcpy( url, front + 1 );        // (or the whole string if there is no slash)
  567.     
  568.     if ( XP_STRLEN( url ) == 0 )
  569.     {                                    // Is this really neccesary?
  570.         XP_FREE(url);
  571.         url = NULL;
  572.     }
  573.         
  574.     return( url );
  575. }
  576.  
  577.  
  578. #define SECURITY_ALERT_RESID        1999
  579. Bool FE_SecurityDialog( MWContext* /*context*/, int message, XP_Bool *retpref )
  580. {
  581.     short        result;
  582.     
  583.     result = CautionAlert( SECURITY_ALERT_RESID + message, NULL );
  584.     
  585.     if ( ( result == neverAgain ) && ( retpref != NULL ) )
  586.     {
  587.         *retpref = FALSE;
  588.         result = ok;
  589.     }
  590.     else if ( message == SD_INSECURE_POST_FROM_SECURE_DOC )
  591.     {
  592.         if ( result == 1 )
  593.             result = cancel;
  594.         else if ( result == 2 )
  595.             result = ok;
  596.     }
  597.     
  598.     if ( result == cancel )
  599.         return FALSE;
  600.     else
  601.         return TRUE;
  602. }    
  603.     
  604. int32 FE_GetContextID( MWContext* window_id )
  605. {
  606.     return (int) window_id;
  607. }
  608.  
  609. const char* FE_UsersMailAddress()
  610. {
  611.     return CPrefs::GetCharPtr( CPrefs::UserEmail );
  612. }
  613.  
  614. const char* FE_UsersFullName()
  615. {
  616.     return CPrefs::GetCharPtr( CPrefs::UserName );
  617. }
  618.  
  619. const char* FE_UsersSignature(void)
  620. {
  621.     static char*    signature = NULL;
  622.     XP_File            file;
  623.     
  624.     if (!CPrefs::GetBoolean(CPrefs::UseSigFile))
  625.         return NULL;
  626.  
  627.     if ( signature )
  628.         XP_FREE( signature );
  629.     if ( CPrefs::GetBoolean( CPrefs::UseInternetConfig ) )
  630.     {
  631.         Str255 sigString;
  632.         memset( sigString, '\0', 256 );
  633.         CInternetConfigInterface::GetInternetConfigString( kICSignature, sigString);
  634.         signature = XP_STRDUP( (char*) sigString );
  635.     }
  636.     else
  637.     {    
  638.         file = XP_FileOpen( CStr255::sEmptyString, xpSignature, XP_FILE_READ );
  639.         
  640.         if ( file )
  641.         {    
  642.             char        buf[ 1024 ];
  643.             char*        s = buf;
  644.             
  645.             int left = sizeof( buf ) - 2;
  646.             int size;
  647.             *s = 0;
  648.  
  649.             while ( ((size = XP_FileRead( s, left, file ) )!=0) && left > 0 )
  650.             {
  651.                 left -= size;
  652.                 s += size;
  653.             }
  654.  
  655.             *s = 0;
  656.  
  657.             /* take off all trailing whitespace */
  658.             s--;
  659.             while ( s >= buf && isspace (*s) )
  660.                 *s-- = 0;
  661.             /* terminate with a single newline. */
  662.             s++;
  663.             *s++ = '\r';
  664.             *s++ = 0;
  665.             XP_FileClose( file );
  666.             if ( !strcmp( buf, "\r" ) )
  667.                 signature = NULL;
  668.             else
  669.                 signature = strdup( buf );
  670.         }
  671.         else
  672.             signature = NULL;
  673.     }        
  674.     return signature;
  675. }
  676.  
  677. void    FE_FileType(char * path, 
  678.                     Bool * useDefault, 
  679.                     char ** fileType, 
  680.                     char ** encoding)
  681. {
  682.     FSSpec spec;
  683.     if ((path == NULL) || (fileType == NULL) || (encoding == NULL))
  684.         return;
  685.  
  686.     *useDefault = TRUE;
  687.     *fileType = NULL;
  688.     *encoding = NULL;
  689.  
  690.     char *pathPart = NET_ParseURL( path, GET_PATH_PART);
  691.     if (pathPart == NULL)
  692.         return;
  693.  
  694.     OSErr err = CFileMgr::FSSpecFromLocalUnixPath(pathPart, &spec);    // Skip file://
  695.     XP_FREE(pathPart);
  696.  
  697.     CMimeMapper * mapper = CPrefs::sMimeTypes.FindMimeType(spec);
  698.     if (mapper != NULL)
  699.     {
  700.         *useDefault = FALSE;
  701.         *fileType = XP_STRDUP(mapper->GetMimeName());
  702.     }
  703.     else
  704.     {
  705.         FInfo        fndrInfo;
  706.         OSErr err = FSpGetFInfo( &spec, &fndrInfo );
  707.         if ( (err != noErr) || (fndrInfo.fdType == 'TEXT') )
  708.             *fileType = XP_STRDUP(APPLICATION_OCTET_STREAM);
  709.         else
  710.         {
  711.             // Time to call IC to see if it knows anything
  712.             ICMapEntry ICMapper;
  713.             
  714.             ICError  error = 0;
  715.             CStr255 fileName( spec.name );
  716.             error = CInternetConfigInterface::GetInternetConfigFileMapping(
  717.                     fndrInfo.fdType, fndrInfo.fdCreator,  fileName ,  &ICMapper );    
  718.             if( error != icPrefNotFoundErr && StrLength(ICMapper.MIME_type) )
  719.             {
  720.                 *useDefault = FALSE;
  721.                 CStr255 mimeName( ICMapper.MIME_type );
  722.                 *fileType = XP_STRDUP( mimeName );
  723.             }
  724.             else
  725.             {
  726.                 // That failed try using the creator type        
  727.                 mapper = CPrefs::sMimeTypes.FindCreator(fndrInfo.fdCreator);
  728.                 if( mapper)
  729.                 {
  730.                     *useDefault = FALSE;
  731.                     *fileType = XP_STRDUP(mapper->GetMimeName());
  732.                 }
  733.                 else
  734.                 {
  735.                     // don't have a mime mapper
  736.                     *fileType = XP_STRDUP(APPLICATION_OCTET_STREAM);
  737.                 }
  738.             }
  739.         }
  740.     }
  741. }
  742.  
  743. const char*
  744. FE_UsersOrganization( void )
  745. {
  746.     return CPrefs::GetCharPtr( CPrefs::Organization );
  747. }
  748.  
  749. char* FE_GetTempFileFor( MWContext* /*cx*/, const char* filename, 
  750.                         XP_FileType ftype, XP_FileType* rettype )
  751. {
  752.     *rettype = ftype; // Required, if the stuff is to work!
  753.     char * s = WH_TempName(ftype, filename);
  754.     return s;
  755. }
  756.  
  757. /* The semantics of this routine are badly broken */
  758. /* We'll mimic Window's implementation for sanity */
  759. int FE_PromptForFileName(    MWContext* context,
  760.                             const char* prompt_string,
  761.                             const char* default_path,
  762.                             XP_Bool file_must_exist_p,
  763.                             XP_Bool directories_allowed_p,
  764.                             ReadFileNameCallbackFunction fn,    // This function will free the file name
  765.                             void* closure )
  766. {
  767.     StandardFileReply        reply;
  768.     XP_MEMSET(&reply, 0, sizeof(StandardFileReply));
  769.     OSErr                    err = -1;
  770.     CFilePicker::PickEnum    pickType;
  771.     
  772.     if ( file_must_exist_p )
  773.     {
  774.         if ( directories_allowed_p )
  775.             pickType = CFilePicker::Folders;
  776.         else
  777.             pickType = CFilePicker::AnyFile;
  778.         
  779.         if ( default_path )
  780.             err = CFileMgr::FSSpecFromLocalUnixPath( default_path, &reply.sfFile );
  781.             
  782.         if ( CFilePicker::DoCustomGetFile( reply, pickType, err == noErr ) )
  783.             goto copy;
  784.         else
  785.             return -1;
  786.     }
  787.     else
  788.     {
  789.         if ( !directories_allowed_p )
  790.         {
  791.             CStr255                    prompt;
  792.             CStr31                    filename;
  793.         
  794.             if ( default_path )
  795.             {
  796.                 filename = CFileMgr::FileNameFromURL( default_path );
  797.                 err = CFileMgr::FSSpecFromLocalUnixPath( default_path, &reply.sfFile );
  798.                 LString::CopyPStr( filename, reply.sfFile.name, 31 );
  799.             }
  800.             
  801.             prompt = prompt_string;
  802.             if ( CFilePicker::DoCustomPutFile( reply, prompt, err == noErr ) )
  803.                 goto copy;
  804.             else
  805.                 return -1;
  806.         }
  807.         else    /* Directories , they are asking for a new folder, we give 'em existing for window's compatibility */
  808.         {
  809.             pickType = CFilePicker::Folders;
  810.             if ( default_path )
  811.                 err = CFileMgr::FSSpecFromLocalUnixPath( default_path, &reply.sfFile );
  812.                 
  813.             if ( CFilePicker::DoCustomGetFile( reply, pickType, err == noErr ) )
  814.                 goto copy;
  815.             else
  816.                 return -1;
  817.         }
  818.     }
  819.  
  820. copy:
  821.     FSSpec                    smReply;
  822.     char*                    path;
  823.     
  824.     smReply = reply.sfFile;
  825.     path = CFileMgr::EncodedPathNameFromFSSpec( smReply, TRUE );
  826.     if ( fn )
  827.         (*fn) ( context, path, closure );
  828.     return noErr;
  829. }
  830.  
  831. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  832. //
  833. #pragma mark --- JAVASCRIPT ---
  834. //
  835. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  836.  
  837. void FE_BackCommand (MWContext *inContext)
  838. {
  839.     CBrowserContext* theContext = ExtractBrowserContext(inContext);
  840.     CBrowserWindow* theWindow = CBrowserWindow::WindowForContext(theContext);
  841.     
  842.     if (theWindow != nil && theContext->CanGoBack())
  843.         theWindow->ObeyCommand(cmd_GoBack);
  844. }
  845.  
  846. void FE_ForwardCommand (MWContext *inContext)
  847. {
  848.     CBrowserContext* theContext = ExtractBrowserContext(inContext);    
  849.     CBrowserWindow* theWindow = CBrowserWindow::WindowForContext(theContext);
  850.     
  851.     if (theWindow != nil && theContext->CanGoForward())
  852.         theWindow->ObeyCommand(cmd_GoForward);
  853. }
  854.  
  855. void FE_HomeCommand (MWContext *inContext)
  856. {
  857.     CBrowserWindow* theWindow = CBrowserWindow::WindowForContext(ExtractBrowserContext(inContext));
  858.     
  859.     if (theWindow != nil)
  860.     {
  861.         theWindow->ObeyCommand(cmd_Home); // we can always go home
  862.     }
  863. }
  864.  
  865. void FE_PrintCommand (MWContext *inContext)
  866. {
  867.     CHTMLView* theHTMLView = ExtractHyperView(inContext);
  868.     
  869.     if (theHTMLView != nil)
  870.     {
  871.         Boolean                outEnabled;
  872.         Boolean                outUsesMark;
  873.         Char16                outMark;
  874.         Str255                outName;
  875.         // can we print?
  876.         theHTMLView->FindCommandStatus(cmd_Print, outEnabled, outUsesMark, outMark, outName);
  877.         if (outEnabled)
  878.             theHTMLView->ObeyCommand(cmd_Print, NULL);
  879.     }
  880. }
  881.  
  882. // Searches for a string in the html view.
  883. // ALERT: inWrap disabled because it is always false in backend - 1997-03-06 mjc
  884. XP_Bool FE_FindCommand(
  885.     MWContext *inContext, char* inSearchString,
  886.     XP_Bool inCaseSensitive, XP_Bool inBackward, XP_Bool /*inWrap*/)
  887. {
  888.     CHTMLView* theView = ExtractHyperView(inContext);
  889.     if (theView != nil)
  890.     {
  891.         Boolean                outEnabled;
  892.         Boolean                outUsesMark;
  893.         Char16                outMark;
  894.         Str255                outName;
  895.         // can we find?
  896.         theView->FindCommandStatus(cmd_Find, outEnabled, outUsesMark, outMark, outName);
  897.         if (outEnabled)
  898.         {
  899.             if (inSearchString != NULL)
  900.             {
  901.                 if (strlen(inSearchString) == 0) return FALSE;
  902.                 // use CFindWindow statics to setup and do the find without creating a window
  903.                 // save and restore settings
  904.                 Boolean saveCaseSensitive = CFindWindow::sCaseless;
  905.                 Boolean saveBackward = CFindWindow::sBackward;
  906.                 //Boolean saveWrap = CFindWindow::sWrap;
  907.                 CFindWindow::sLastSearch = inSearchString;
  908.                 CFindWindow::sCaseless = !inCaseSensitive;
  909.                 CFindWindow::sBackward = inBackward;
  910.                 //CFindWindow::sWrap = inWrap;
  911.                 Boolean result = theView->DoFind();
  912.                 CFindWindow::sCaseless = saveCaseSensitive;
  913.                 CFindWindow::sBackward = saveBackward;
  914.                 //CFindWindow::sWrap = saveWrap;
  915.                 return result;
  916.             }
  917.             else 
  918.             {
  919.                 CFindWindow::DoFind(theView); // create a find window
  920.                 return FALSE;
  921.             }
  922.         }
  923.     }
  924.     return FALSE;
  925. }
  926.  
  927. // Returns in global coordinates the offset of the html view from the screen origin.
  928. // The vertical component of the screen origin for javascript on the mac is the
  929. // bottom of the menubar.
  930. void FE_GetWindowOffset (MWContext *inContext, int32 *sx, int32 *sy)
  931. {
  932.     CHTMLView* theView = ExtractHyperView(inContext);
  933.     if (theView != nil)
  934.     {
  935.         Point htmlOrigin = { 0, 0};
  936.         theView->LocalToPortPoint(htmlOrigin);
  937.         theView->PortToGlobalPoint(htmlOrigin);
  938.         htmlOrigin.v -= ::GetMBarHeight();
  939.         *sx = htmlOrigin.h;
  940.         *sy = htmlOrigin.v;
  941.     }
  942. }
  943.  
  944. // Returns the device which contains the largest portion of
  945. // the window's rectangle, or the main device if inWindow is null.
  946. GDHandle DeviceForWindow(LWindow* inWindow)
  947. {
  948.     GDHandle    dominantDevice = nil;
  949.     
  950.     if (inWindow != nil)
  951.     {
  952.         Rect            windowFrame;
  953.         
  954.         inWindow->CalcPortFrameRect( windowFrame );
  955.         windowFrame = PortToGlobalRect( inWindow, windowFrame );
  956.  
  957.         dominantDevice = UWindows::FindDominantDevice(windowFrame);
  958.     }
  959.     else dominantDevice = ::GetMainDevice();
  960.     
  961.     return ((dominantDevice == nil) ? ::GetMainDevice() : dominantDevice);
  962. }
  963.  
  964. // Returns the screen size for the screen which contains the largest
  965. // portion of the rectangle. If the context does not correspond to a browser window,
  966. // returns the values for the main screen.
  967. void FE_GetScreenSize (MWContext *inContext, int32 *sx, int32 *sy)
  968. {
  969.     GDHandle device;
  970.     CBrowserWindow* theWindow = CBrowserWindow::WindowForContext(ExtractBrowserContext(inContext));
  971.     
  972.     device = DeviceForWindow(theWindow);
  973.  
  974.     *sx = (**device).gdRect.right;
  975.     *sy = (**device).gdRect.bottom;
  976. }
  977.  
  978. // Returns the top, left, width, and height of the available screen area, that is,
  979. // on the Mac, the screen area minus the menubar. The screen which contains the
  980. // largest portion of the window's rectangle is chosen, or the main screen if the
  981. // context does not correspond to a browser window.
  982. void FE_GetAvailScreenRect (MWContext *inContext, int32 *sx, int32 *sy, 
  983.                             int32 *left, int32 *top)
  984. {
  985.     GDHandle device;
  986.     CBrowserWindow* theWindow = CBrowserWindow::WindowForContext(ExtractBrowserContext(inContext));
  987.     
  988.     device = DeviceForWindow(theWindow);
  989.  
  990.     *sx = (**device).gdRect.right;
  991.     *sy = (**device).gdRect.bottom - ::GetMBarHeight();
  992.     // left and top represent the origin in terms of window positioning so will always be 0, 0 on mac
  993.     *left = 0; /* (**device).gdRect.left; */
  994.     *top = 0; /* (**device).gdRect.top + ::GetMBarHeight();    */
  995. }
  996.  
  997. // Returns the pixel and color depth for the screen which contains the largest
  998. // portion of the rectangle. If the context does not correspond to a browser window,
  999. // returns the values for the main screen.
  1000. void FE_GetPixelAndColorDepth (MWContext *inContext, int32 *pixelDepth, 
  1001.                       int32 *colorDepth)
  1002. {
  1003.     GDHandle device;
  1004.     CBrowserWindow* theWindow = CBrowserWindow::WindowForContext(ExtractBrowserContext(inContext));
  1005.     
  1006.     device = DeviceForWindow(theWindow);
  1007.     
  1008.     *pixelDepth = (**(**device).gdPMap).pixelSize;
  1009.     *colorDepth = (**(**device).gdPMap).pixelSize; // ALERT: implement me!
  1010. }
  1011.  
  1012.  
  1013. // This function returns a context suitable for throwing up a dialog
  1014. // at init time. This dialog must be an FE_PromptPassword. If other dialogs
  1015. // are needed, we need to check all the FE's to make sure that their returned
  1016. // context can handle them. (rjr).
  1017. MWContext *FE_GetInitContext(void) {
  1018.     static CNSContext *rootContext = NULL;
  1019.  
  1020.     if (!rootContext) {
  1021.         rootContext = new CNSContext(MWContextDialog);
  1022.         if (rootContext) {
  1023.             // don't leave this context lieing around the XP list.
  1024.             XP_RemoveContextFromList((MWContext *)*rootContext);
  1025.         }
  1026.     }
  1027.     if (!rootContext) return NULL;
  1028.     return (MWContext *)*rootContext;
  1029. }
  1030.  
  1031. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  1032. //
  1033. #pragma mark --- PREFS CRAP ---
  1034. //
  1035. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  1036.  
  1037. // This class only works for now with the old prefs (CPrefs::SubscribeToPrefChanges /
  1038. // CPrefs::UnsubscribeToPrefChanges). It can be extended for the new style prefs
  1039. // (PREF_RegisterCallback / PREF_UnregisterCallback)
  1040.  
  1041. class PrefsChangeListener : public LListener
  1042. {
  1043. public:
  1044.                         PrefsChangeListener(CPrefs::PrefEnum inID);
  1045.     virtual             ~PrefsChangeListener();
  1046.     virtual void        ListenToMessage(MessageT inMessage, void *ioParam);
  1047.     virtual Boolean        PrefHasChanged();
  1048. protected:
  1049.     CPrefs::PrefEnum    mID;
  1050.     Boolean                mPrefHasChanged;
  1051. };
  1052.  
  1053. PrefsChangeListener::PrefsChangeListener(CPrefs::PrefEnum inID)
  1054. {
  1055.     mID = inID;
  1056.     mPrefHasChanged = true;        // default to true: must load pref the first time
  1057.     CPrefs::SubscribeToPrefChanges(this);
  1058. }
  1059.  
  1060. PrefsChangeListener::~PrefsChangeListener()
  1061. {
  1062.     CPrefs::UnsubscribeToPrefChanges(this);
  1063. }
  1064.  
  1065. void PrefsChangeListener::ListenToMessage(MessageT inMessage, void *ioParam)
  1066. {
  1067.     if (inMessage == CPrefs::msg_PrefsChanged)
  1068.     {
  1069.         if (*(CPrefs::PrefEnum *)ioParam == mID)
  1070.             mPrefHasChanged = true;
  1071.     }
  1072. }
  1073.  
  1074. Boolean PrefsChangeListener::PrefHasChanged()
  1075. {
  1076.     Boolean    value = mPrefHasChanged;
  1077.     mPrefHasChanged = false;
  1078.     return(value);
  1079. }
  1080.  
  1081. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  1082. //
  1083. #pragma mark --- INTERNATIONAL CALLBACKS ---
  1084. //
  1085. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  1086.  
  1087. void INTL_Relayout(MWContext* inContext)
  1088. {
  1089.     CBrowserContext* theBrowserContext = ExtractBrowserContext(inContext);
  1090.     
  1091.     // this can be called when quoting HTML on a plain text email; then we
  1092.     // have a CPlainTextConverterContext, not a CBrowserContext
  1093.     if (theBrowserContext != NULL)
  1094.         theBrowserContext->Repaginate();
  1095. }
  1096.  
  1097. static Int16 DefaultDocCharSetIDFromContext(MWContext* inContext);
  1098. static Int16 DefaultDocCharSetIDFromPref();
  1099. Int16 DefaultDocCharSetIDFromFrontWindow();
  1100.  
  1101. static Int16 DefaultDocCharSetIDFromContext(MWContext* inContext)
  1102. {
  1103.     Assert_(inContext != NULL);
  1104.     CNSContext* theNSContext = ExtractNSContext(inContext);
  1105.     Assert_(theNSContext != NULL);
  1106.     return theNSContext->GetDefaultCSID();
  1107. }
  1108.  
  1109. static PrefsChangeListener *    gCharSetIDPrefsListener = nil;
  1110.  
  1111. static Int16 DefaultDocCharSetIDFromPref()
  1112. {    
  1113.     static Int16 prefDefaultID;
  1114.  
  1115.     if (gCharSetIDPrefsListener == nil)
  1116.         gCharSetIDPrefsListener = new PrefsChangeListener(CPrefs::DefaultCharSetID);
  1117.  
  1118.     if (gCharSetIDPrefsListener->PrefHasChanged())
  1119.     {
  1120.         prefDefaultID = CPrefs::GetLong(CPrefs::DefaultCharSetID);
  1121.         if(0 == prefDefaultID)    // to fix John McMullen's old preference problem (bug 63052)
  1122.             prefDefaultID = CS_LATIN1;
  1123.     }
  1124.       if (INTL_CanAutoSelect(prefDefaultID))
  1125.         prefDefaultID |= CS_AUTO;
  1126.     return prefDefaultID;
  1127. }
  1128.  
  1129. Int16 DefaultDocCharSetIDFromFrontWindow()
  1130. {
  1131.     CWindowIterator iter(WindowType_Any);
  1132.     CMediatedWindow* window;
  1133.     Int16 csid = 0;
  1134.     for (iter.Next(window); window; iter.Next(window))
  1135.     {    
  1136.         csid = window->DefaultCSIDForNewWindow();
  1137.         if(0 != csid)
  1138.             return csid;
  1139.     }
  1140.     return 0;
  1141. }
  1142.  
  1143. int16 INTL_DefaultDocCharSetID(MWContext* inContext)
  1144. {
  1145.     if (inContext != NULL)
  1146.         return DefaultDocCharSetIDFromContext(inContext);
  1147.     return DefaultDocCharSetIDFromPref();
  1148. }
  1149.  
  1150.  
  1151.  
  1152. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  1153. //
  1154. #pragma mark --- IMAGE LIB STUFF---
  1155. //
  1156. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  1157.  
  1158.  
  1159. void FE_ShiftImage(
  1160.     MWContext*            ,
  1161.     LO_ImageStruct*        )
  1162. {
  1163. }
  1164.  
  1165.  
  1166.  
  1167.  
  1168.  
  1169.  
  1170.  
  1171.  
  1172.  
  1173.  
  1174.  
  1175.  
  1176.  
  1177.  
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  1189. //
  1190. #pragma mark --- HELP STUFF ---
  1191. //
  1192. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  1193.  
  1194. MWContext *FE_GetNetHelpContext()
  1195. {
  1196.     MWContext            *pActiveContext = NULL;
  1197.     CNSContext            *pWindowContext = NULL;
  1198.     CWindowIterator     *iter;
  1199.     CMediatedWindow        *window;
  1200.     
  1201.     iter = new CWindowIterator(WindowType_Browser);
  1202.     iter->Next(window);
  1203.  
  1204.     if (window) {
  1205.         CBrowserWindow    *result;
  1206.         
  1207.         result = dynamic_cast<CBrowserWindow*>(window);
  1208.         pWindowContext = result->GetWindowContext();
  1209.     } else {
  1210.         delete iter;
  1211.         
  1212.         iter = new CWindowIterator(WindowType_MailNews);
  1213.         iter->Next(window);
  1214.  
  1215. #ifdef MOZ_MAIL_NEWS
  1216.         if (window) {
  1217.             CMailNewsWindow    *result;
  1218.             
  1219.             result = dynamic_cast<CMailNewsWindow*>(window);
  1220.             pWindowContext = result->GetWindowContext();
  1221.         }
  1222. #endif // MOZ_MAIL_NEWS
  1223.     }
  1224.     
  1225.     if (pWindowContext) {
  1226.         pActiveContext = (MWContext *) pWindowContext;
  1227.     }
  1228.     
  1229.     if (!pActiveContext) {
  1230.     
  1231.         /* Borrow a cheat from the AppleEvents code that did this.  The comment there was:
  1232.            "Will using the bookmark context as a dummy work?"
  1233.         */
  1234.         DebugStr("\pNot Implemented");
  1235. //ÑÑÑ        CBookmarksContext::Initialize();
  1236. //ÑÑÑ        pActiveContext = (MWContext *) ((CNSContext *) CBookmarksContext::GetInstance());
  1237.     }
  1238.     
  1239.     return pActiveContext;
  1240. }
  1241.  
  1242.  
  1243. //
  1244. // ShowHelp
  1245. //
  1246. // Displays the NetHelp window, given the appropriate help topic.
  1247. //
  1248.  
  1249. void
  1250. ShowHelp ( const char* inHelpTopic )
  1251. {
  1252.     const char    * const netHelpPrefix = "nethelp:netscape/";
  1253.     char        *fullURL = (char *)XP_ALLOC(strlen(inHelpTopic) +
  1254.                                             strlen(netHelpPrefix) + 1);
  1255.     if (fullURL)
  1256.     {
  1257.         strcpy(fullURL, netHelpPrefix);
  1258.         strcat(fullURL, inHelpTopic);
  1259.         CFrontApp::DoGetURL(fullURL);
  1260.         XP_FREE(fullURL);
  1261.     }
  1262. } // DoHelp
  1263.  
  1264.  
  1265. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  1266. //
  1267. #pragma mark --- NETCASTER STUFF ---
  1268. //
  1269. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  1270.  
  1271. /* Check if Netcaster is in the registry, and if a specific component is there
  1272.  * (the user may have deleted the files)
  1273.  */
  1274. XP_Bool FE_IsNetcasterInstalled()
  1275. {
  1276.     XP_Bool bInstalled = ((VR_InRegistry("Netcaster") == REGERR_OK) && (VR_ValidateComponent("Netcaster/tab.htm") == REGERR_OK));
  1277.     VR_Close();
  1278.     return bInstalled;
  1279. }
  1280.  
  1281. /* Runs Netcaster by finding an html component and opening it in a 
  1282.  * new browser window, or bringing the window to the front if Netcaster
  1283.  * is already launched.
  1284.  */
  1285. void FE_RunNetcaster(MWContext *)
  1286. {
  1287.     CFrontApp    *theApp = CFrontApp::GetApplication();
  1288.     MWContext    *pNetcasterContext = NULL;
  1289.     char *contextName = "Netcaster_SelectorTab";
  1290.     
  1291.     // The Mac function ignores the pContext parameter
  1292.  
  1293.     if (theApp != NULL) {
  1294.         pNetcasterContext = theApp->GetNetcasterContext();
  1295.         if (pNetcasterContext != NULL) {
  1296.             // we've already launched.  Just bring it to front.
  1297.             FE_RaiseWindow(pNetcasterContext);
  1298.         } else {
  1299.             // we haven't launched yet.  Do that now.
  1300.  
  1301.              Chrome          netcasterChrome;
  1302.              URL_Struct*     URL_s;
  1303.             REGERR            regErr;
  1304.             char            netcasterPath[1024];
  1305.  
  1306.             // get the native path to the component.
  1307.             regErr = VR_GetPath("Netcaster/tab.htm", 1024, netcasterPath);
  1308.             VR_Close();
  1309.             
  1310.             if (regErr == REGERR_OK) {
  1311.             
  1312.                 FSSpec netcasterFile;
  1313.                 char *netcasterURL;
  1314.                 // translate the native path to a local file URL.
  1315.                 CFileMgr::FSSpecFromPathname(netcasterPath, &netcasterFile);
  1316.                 netcasterURL = CFileMgr::GetURLFromFileSpec(netcasterFile);
  1317.             
  1318.                 if (netcasterURL != NULL)
  1319.                 {
  1320.                     // javascript and java must be enabled for Netcaster to run.
  1321.                     if (!LM_GetMochaEnabled() || !LJ_GetJavaEnabled())
  1322.                     {
  1323.                         char    *errString = XP_GetString(XP_ALERT_NETCASTER_NO_JS);
  1324.                         
  1325.                         ErrorManager::PlainAlert(errString, "", "", "");
  1326.                         XP_FREE(netcasterURL);
  1327.                         return;
  1328.                     }
  1329.                      memset(&netcasterChrome, 0, sizeof(Chrome));
  1330.  
  1331.                      netcasterChrome.w_hint = 22;
  1332.                      netcasterChrome.h_hint = 59;
  1333.                      netcasterChrome.l_hint = -300;
  1334.                      netcasterChrome.t_hint = 0;
  1335.                      netcasterChrome.topmost = TRUE;
  1336.                      netcasterChrome.z_lock = TRUE;
  1337.                      netcasterChrome.location_is_chrome = TRUE;
  1338.                      netcasterChrome.disable_commands = TRUE;
  1339.                      netcasterChrome.hide_title_bar = TRUE;
  1340.                      netcasterChrome.restricted_target = TRUE;
  1341.                      netcasterChrome.allow_close = TRUE;
  1342.                  
  1343.                     URL_s = NET_CreateURLStruct(netcasterURL, NET_DONT_RELOAD);
  1344.                  
  1345.                     pNetcasterContext = FE_MakeNewWindow(NULL, 
  1346.                                                          URL_s, 
  1347.                                                           contextName, 
  1348.                                                           &netcasterChrome);
  1349.                                                           
  1350.                      theApp->SetNetcasterContext(pNetcasterContext);
  1351.                      XP_FREE(netcasterURL);
  1352.                  }
  1353.              } else {
  1354.                 char    *errString = XP_GetString(XP_ALERT_CANT_RUN_NETCASTER);
  1355.                 
  1356.                 ErrorManager::PlainAlert(errString, "", "", "");
  1357.              }
  1358.         }
  1359.     } else {
  1360.         XP_ASSERT(0);
  1361.     }
  1362. }
  1363.  
  1364. MWContext * FE_IsNetcasterRunning(void)
  1365. {
  1366.     CFrontApp    *theApp = CFrontApp::GetApplication();
  1367.     
  1368.     if (theApp != NULL)
  1369.         return theApp->GetNetcasterContext();
  1370.     else return NULL;
  1371. }
  1372.  
  1373. MWContext * FE_GetRDFContext()
  1374. {
  1375.     try
  1376.     {
  1377.         if (!CFrontApp::sRDFContext.get())
  1378.         {
  1379.             CFrontApp::sRDFContext.reset(new CNSContext(MWContextRDFSlave));
  1380.         }
  1381.         return *CFrontApp::sRDFContext.get();
  1382.     }
  1383.     catch (...)
  1384.     {
  1385.         return NULL;
  1386.     }
  1387. }
  1388.  
  1389. // stub this for now
  1390. void FE_SetPasswordEnabled( MWContext*, PRBool )
  1391. {
  1392. }
  1393.  
  1394.  
  1395. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  1396. //
  1397. #pragma mark --- SPURIOUS CRAP ---
  1398. //
  1399. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  1400.  
  1401. char reconnectHack[] = "internal-external-reconnect";
  1402. char mailNewsReconnect[] = "internal-external-reconnect:";
  1403.  
  1404. const char* cDocInfoWindowContextName = "%DocInfoWindow";
  1405. const char* cViewSourceWindowContextName1 = "%ViewSourceWindow";
  1406. const char* cViewSourceWindowContextName2 = "view-source";
  1407. const size_t cViewSourceWindowString1Length = 17;
  1408. const size_t cViewSourceWindowString2Length = 11;
  1409.  
  1410. Boolean IsMailToLink( const char* url )
  1411. {
  1412.     if ( !XP_STRNCMP( url, "mailto", 6 ) )
  1413.         return TRUE;
  1414.     return FALSE;
  1415. }
  1416.  
  1417. Boolean IsInternalImage( const char* url )
  1418. {
  1419.     if ( !XP_STRNCMP( url, reconnectHack, XP_STRLEN( reconnectHack ) ) )
  1420.         return TRUE;
  1421.     return FALSE;
  1422. }
  1423.  
  1424. Boolean IsMailNewsReconnect( const char* url )
  1425. {
  1426.     if ( !XP_STRNCMP( url, mailNewsReconnect, XP_STRLEN( mailNewsReconnect ) ) )
  1427.         return TRUE;
  1428.     return FALSE;
  1429. }
  1430.  
  1431. Boolean IsInternalTypeLink( const char* url )
  1432. {
  1433.     if ( !XP_STRNCMP( url, "internal-", 9 ) )
  1434.         return TRUE;
  1435.     return FALSE;
  1436. }
  1437.  
  1438. Boolean IsDocInfoWindow(const char* inName)
  1439. {
  1440.     if (inName)
  1441.         return (XP_STRCMP(inName, cDocInfoWindowContextName) == 0);
  1442.     else
  1443.         return false;
  1444. }
  1445.  
  1446. Boolean IsViewSourceWindow(const char* inName)
  1447. {
  1448.     Boolean result = false;
  1449.     if (inName && (XP_STRLEN(inName) >= cViewSourceWindowString2Length))
  1450.     {
  1451.         result = (XP_STRNCMP(inName,
  1452.                              cViewSourceWindowContextName1,
  1453.                              cViewSourceWindowString1Length) == 0);
  1454.         if (!result)
  1455.         {
  1456.             result = (XP_STRCASECMP(inName, cViewSourceWindowContextName2) == 0);
  1457.         }
  1458.     }
  1459.     return result;
  1460. }
  1461.  
  1462. Boolean IsSpecialBrowserWindow(const char* inName)
  1463. {
  1464.     Boolean result = false;
  1465.     if (inName)
  1466.     {
  1467.         if (IsDocInfoWindow(inName))
  1468.             result = true;
  1469.         if (IsViewSourceWindow(inName))
  1470.             result = true;
  1471.         if (XP_STRCMP(inName, XP_GetString(XP_SECURITY_ADVISOR_TITLE_STRING)) == 0)
  1472.             result = true;
  1473.     }
  1474.     return result;
  1475. }
  1476.