home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / BrowserFrame.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  22.7 KB  |  852 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.    BrowserFrame.cpp -- class definition for the browser frame class
  20.    Created: Spence Murray <spence@netscape.com>, 17-Oct-96.
  21.  */
  22.  
  23.  
  24.  
  25. #include "BrowserFrame.h"
  26. #include "HTMLView.h"
  27. #include "HistoryMenu.h"
  28. #include "BackForwardMenu.h"
  29. #include "BookmarkFrame.h"
  30. #include "Command.h"
  31. #include "MozillaApp.h"
  32. #include "ViewGlue.h"
  33. #include "Logo.h"
  34. #include "xpassert.h"
  35.  
  36. #include "DtWidgets/ComboBox.h"
  37.  
  38. #include <Xfe/Xfe.h>
  39.  
  40. #ifdef DEBUG_spence
  41. #define D(x) x
  42. #else
  43. #define D(x)
  44. #endif
  45.  
  46. extern "C" {
  47.   void fe_set_scrolled_default_size(MWContext *context);
  48.   void fe_home_cb (Widget widget, XtPointer closure, XtPointer call_data);
  49.   Boolean plonk (MWContext *context);
  50.   Boolean plonk_cancelled (void);
  51.   URL_Struct *fe_GetBrowserStartupUrlStruct();
  52. }
  53.  
  54. MenuSpec XFE_BrowserFrame::file_menu_spec[] = {
  55. #if (defined(MOZ_MAIL_NEWS) || defined(EDITOR))
  56.   { "newSubmenu",        CASCADEBUTTON,
  57.     (MenuSpec*)&XFE_Frame::new_menu_spec },
  58. #else
  59.   { xfeCmdOpenBrowser,    PUSHBUTTON },
  60. #endif
  61.   { xfeCmdOpenPage,        PUSHBUTTON },
  62.   MENU_SEPARATOR,
  63.   { xfeCmdSaveAs,        PUSHBUTTON },
  64.   { xfeCmdSaveFrameAs,  PUSHBUTTON },
  65.   MENU_SEPARATOR,
  66.   { xfeCmdSendPage,        PUSHBUTTON },
  67.   { xfeCmdSendLink,     PUSHBUTTON },
  68.   MENU_SEPARATOR,
  69. #ifdef EDITOR
  70.   { xfeCmdEditPage,        PUSHBUTTON },
  71.   { xfeCmdEditFrame,    PUSHBUTTON },
  72. #endif
  73.   { xfeCmdUploadFile,        PUSHBUTTON },
  74.   //MENU_SEPARATOR,
  75.   //{ xfeCmdGoOffline,            PUSHBUTTON },
  76.   MENU_SEPARATOR,
  77.   //{ xfeCmdPrintSetup,        PUSHBUTTON },
  78.   //{ xfeCmdPrintPreview,        PUSHBUTTON },
  79.   { xfeCmdPrint,        PUSHBUTTON },
  80.   MENU_SEPARATOR,
  81.   { xfeCmdClose,        PUSHBUTTON },
  82.   { xfeCmdExit,            PUSHBUTTON },
  83.   { NULL }
  84. };
  85.  
  86. MenuSpec XFE_BrowserFrame::edit_menu_spec[] = {
  87.   { xfeCmdUndo,            PUSHBUTTON },
  88.   { xfeCmdRedo,            PUSHBUTTON },
  89.   MENU_SEPARATOR,
  90.   { xfeCmdCut,            PUSHBUTTON },
  91.   { xfeCmdCopy,            PUSHBUTTON },
  92.   { xfeCmdPaste,        PUSHBUTTON },
  93.   //xxxDelete
  94.   { xfeCmdSelectAll,        PUSHBUTTON },
  95.   MENU_SEPARATOR,
  96.   { xfeCmdFindInObject,        PUSHBUTTON },
  97.   { xfeCmdFindAgain,        PUSHBUTTON },
  98.   { xfeCmdSearch,            PUSHBUTTON },
  99. #ifdef MOZ_MAIL_NEWS
  100.   { xfeCmdSearchAddress,    PUSHBUTTON },
  101.   MENU_SEPARATOR,
  102. #endif
  103.   { xfeCmdEditPreferences,    PUSHBUTTON },
  104.   { NULL }
  105. };
  106.  
  107. MenuSpec XFE_BrowserFrame::view_menu_spec[] = {
  108.   { xfeCmdToggleNavigationToolbar,PUSHBUTTON },
  109.   { xfeCmdToggleLocationToolbar,  PUSHBUTTON },
  110.   { xfeCmdTogglePersonalToolbar,  PUSHBUTTON },
  111.   MENU_SEPARATOR,
  112.   { xfeCmdIncreaseFont,        PUSHBUTTON },
  113.   { xfeCmdDecreaseFont,        PUSHBUTTON },
  114.   MENU_SEPARATOR,
  115.   { xfeCmdReload,           PUSHBUTTON },
  116.   { xfeCmdShowImages,        PUSHBUTTON },
  117.   { xfeCmdRefresh,          PUSHBUTTON },
  118.   { xfeCmdStopLoading,        PUSHBUTTON },
  119.   MENU_SEPARATOR,
  120.   { xfeCmdViewPageSource,    PUSHBUTTON },
  121.   { xfeCmdViewPageInfo,        PUSHBUTTON },
  122.   { xfeCmdPageServices,     PUSHBUTTON },
  123.   MENU_SEPARATOR,
  124.   { "encodingSubmenu",        CASCADEBUTTON,
  125.     (MenuSpec*)&XFE_Frame::encoding_menu_spec },
  126.   { NULL }
  127. };
  128.  
  129. MenuSpec XFE_BrowserFrame::go_menu_spec[] = {
  130.   { xfeCmdBack,            PUSHBUTTON },
  131.   { xfeCmdForward,        PUSHBUTTON },
  132.   { xfeCmdHome,            PUSHBUTTON },
  133.   MENU_SEPARATOR,
  134.   { "historyPlaceHolder",    DYNA_MENUITEMS, NULL, NULL, False, NULL, XFE_HistoryMenu::generate },
  135.   { NULL }
  136. };
  137.  
  138. MenuSpec XFE_BrowserFrame::menu_bar_spec[] = {
  139.   { xfeMenuFile,     CASCADEBUTTON, (MenuSpec*)&XFE_BrowserFrame::file_menu_spec },
  140.   { xfeMenuEdit,     CASCADEBUTTON, (MenuSpec*)&XFE_BrowserFrame::edit_menu_spec },
  141.   { xfeMenuView,     CASCADEBUTTON, (MenuSpec*)&XFE_BrowserFrame::view_menu_spec },
  142.   { xfeMenuGo,        CASCADEBUTTON, (MenuSpec*)&XFE_BrowserFrame::go_menu_spec },
  143.   { xfeMenuWindow,     CASCADEBUTTON, (MenuSpec*)&XFE_Frame::window_menu_spec },
  144.   { xfeMenuHelp,     CASCADEBUTTON, (MenuSpec*)&XFE_Frame::help_menu_spec },
  145.   { NULL }
  146. };
  147.  
  148. ToolbarSpec XFE_BrowserFrame::toolbar_spec[] = {
  149.     { 
  150.         xfeCmdBack,
  151.         DYNA_CASCADEBUTTON,
  152.         &TB_Back_group, NULL, NULL, NULL,                    // Icons
  153.         NULL,                                                // Submenu spec
  154.         XFE_BackForwardMenu::generate , (XtPointer) False,     // Generate proc/arg
  155.         XFE_TOOLBAR_DELAY_LONG                                // Popup delay
  156.     },
  157.     {
  158.         xfeCmdForward,
  159.         DYNA_CASCADEBUTTON,
  160.         &TB_Forward_group, NULL, NULL, NULL,                // Icons
  161.         NULL,                                                // Submenu spec
  162.         XFE_BackForwardMenu::generate , (XtPointer) True,    // Generate proc/arg
  163.         XFE_TOOLBAR_DELAY_LONG                                // Popup delay
  164.     },
  165.   { xfeCmdReload,       PUSHBUTTON, &TB_Reload_group },
  166.   TOOLBAR_SEPARATOR,
  167.   { xfeCmdHome,            PUSHBUTTON, &TB_Home_group },
  168.  
  169.   { xfeCmdSearch,       PUSHBUTTON, &TB_Search_group }, 
  170. #if 0
  171. //
  172. // I took the marketing crap out -ramiro
  173. //
  174.   { 
  175.       xfeCmdDestinations,
  176.       CASCADEBUTTON,
  177.       &TB_Places_group, NULL, NULL, NULL,    // Icons
  178.       (MenuSpec*) &XFE_Frame::tb_places_menu_spec,            // Submenu spec
  179.       NULL, NULL,    // Generate proc/arg
  180.       XFE_TOOLBAR_DELAY_LONG                // Popup delay
  181.   },
  182. #endif
  183.   TOOLBAR_SEPARATOR,
  184.  
  185. #ifdef EDITOR
  186.   { xfeCmdEditPage,   PUSHBUTTON, &TB_Edit_group },
  187.   TOOLBAR_SEPARATOR,
  188. #endif
  189.  
  190.   { xfeCmdShowImages,   PUSHBUTTON, &TB_LoadImages_group },
  191.   { xfeCmdPrint,        PUSHBUTTON, &TB_Print_group },
  192. #ifndef NO_SECURITY
  193.   { xfeCmdViewSecurity,    PUSHBUTTON, &TB_Unsecure_group, &TB_Secure_group, &TB_MixSecurity_group },
  194. #endif
  195.   TOOLBAR_SEPARATOR,
  196.   { xfeCmdStopLoading,    PUSHBUTTON, &TB_Stop_group },
  197.     { NULL }
  198. };
  199.  
  200. extern "C"  void fe_HackTranslations (MWContext *, Widget);
  201.  
  202. XFE_BrowserFrame::XFE_BrowserFrame(Widget toplevel,
  203.                                    XFE_Frame *parent_frame,
  204.                                    Chrome *chromespec) :
  205.     XFE_Frame("Navigator", 
  206.               toplevel, 
  207.               parent_frame, 
  208.               FRAME_BROWSER, 
  209.               chromespec, 
  210.               True)
  211. {
  212.   // create html view
  213.   XFE_HTMLView *htmlview;
  214.  
  215.   geometryPrefName = "browser";
  216.  
  217.   if (parent_frame)
  218.     fe_copy_context_settings(m_context, parent_frame->getContext());
  219. #ifdef notyet
  220.  
  221. #ifndef NO_SECURITY
  222.   /* Enable security bar for all browser windows. I had to do this
  223.      so that this would get focus whenever we set focus on the main
  224.      window. Thus all owr translations will work. Otherwise, if all
  225.      chrome is switched off, there will be no widget to set focus to
  226.      */
  227.   CONTEXT_DATA(context)->show_security_bar_p = True;
  228. #endif
  229.   
  230. #endif /* notyet */
  231.  
  232.   htmlview = new XFE_HTMLView(this, getViewParent(), NULL, m_context);
  233.  
  234.   // Create url bar
  235.   m_urlBar = new XFE_URLBar(this,m_toolbox);
  236.  
  237.   // Create the personal toolbar
  238.   m_personalToolbar = 
  239.      new XFE_PersonalToolbar(XFE_BookmarkFrame::main_bm_context,
  240.                              m_toolbox,
  241.                              "personalToolbarItem",
  242.                              this);
  243.  
  244.   // add notification now 'cuz frame->getURL might not get called and
  245.   // fe_SetURLString will break.
  246.   registerInterest(XFE_HTMLView::newURLLoading, 
  247.            this,
  248.            (XFE_FunctionNotification)newPageLoading_cb);
  249.   m_notification_added = True;
  250.  
  251.   m_urlBar->registerInterest(XFE_URLBar::navigateToURL,
  252.                  this,
  253.                  (XFE_FunctionNotification)navigateToURL_cb);
  254.  
  255.     XFE_MozillaApp::theApp()->registerInterest(XFE_MozillaApp::updateToolbarAppearance,
  256.                                                this,
  257.                                                (XFE_FunctionNotification)updateToolbarAppearance_cb);
  258.  
  259.   if (!chromespec || (chromespec && chromespec->show_url_bar))
  260.       m_urlBar->show();
  261.  
  262.   XtVaSetValues(htmlview->getBaseWidget(),
  263.         XmNleftAttachment, XmATTACH_FORM,
  264.         XmNtopAttachment, XmATTACH_FORM,
  265.         XmNrightAttachment, XmATTACH_FORM,
  266.         XmNbottomAttachment, XmATTACH_FORM,
  267.         NULL);
  268.                  
  269.   // register drop site on HTMLView
  270.   m_browserDropSite=new XFE_BrowserDrop(htmlview->getBaseWidget(),this);
  271.   m_browserDropSite->enable();
  272.   
  273.   setView(htmlview);
  274.   setMenubar(menu_bar_spec);
  275.   setToolbar(toolbar_spec);
  276.  
  277.   if (fe_globalPrefs.autoload_images_p) {
  278.     m_toolbar->hideButton(xfeCmdShowImages, PUSHBUTTON);
  279.   }
  280.  
  281.   fe_set_scrolled_default_size(m_context);
  282.  
  283.   htmlview->show();
  284.  
  285.   respectChrome(chromespec);
  286.  
  287. #ifndef NO_SECURITY
  288.   m_dashboard->setShowSecurityIcon(True);
  289. #endif
  290.   m_dashboard->setShowStatusBar(True);
  291.   m_dashboard->setShowProgressBar(True);
  292.  
  293.   // Configure the toolbox for the first time
  294.   configureToolbox();
  295. }
  296.  
  297. XFE_BrowserFrame::~XFE_BrowserFrame()
  298. {
  299.     if (m_browserDropSite)
  300.         delete m_browserDropSite;
  301.  
  302.     XFE_MozillaApp::theApp()->unregisterInterest(XFE_MozillaApp::updateToolbarAppearance,
  303.                                                  this,
  304.                                                  (XFE_FunctionNotification)updateToolbarAppearance_cb);
  305. }
  306.  
  307. void
  308. XFE_BrowserFrame::updateToolbar()
  309. {
  310.   if (!m_toolbar)
  311.     return;
  312.     
  313.   if (fe_globalPrefs.autoload_images_p) {
  314.     m_toolbar->hideButton(xfeCmdShowImages, PUSHBUTTON);
  315.   } else {
  316.     m_toolbar->showButton(xfeCmdShowImages, PUSHBUTTON);
  317.   }
  318.  
  319.     m_toolbar->update();
  320. }
  321.  
  322. XP_Bool
  323. XFE_BrowserFrame::isCommandEnabled(CommandType cmd,
  324.                                    void *calldata, XFE_CommandInfo*)
  325. {
  326.   if (cmd == xfeCmdToggleLocationToolbar
  327.       || cmd == xfeCmdTogglePersonalToolbar
  328.       )
  329.     return True;
  330.   else
  331.     return XFE_Frame::isCommandEnabled(cmd, calldata);
  332. }
  333.  
  334. void
  335. XFE_BrowserFrame::doCommand(CommandType cmd,
  336.                             void *calldata, XFE_CommandInfo* info)
  337. {
  338.   if (cmd == xfeCmdToggleLocationToolbar)
  339.     {
  340.       if (m_urlBar)
  341.         {
  342.           if (m_urlBar->isShown())
  343.             m_urlBar->hide();
  344.           else
  345.             m_urlBar->show();
  346.           
  347.           
  348.           // Configure the logo
  349.           configureLogo();
  350.           
  351.           // Do the attachments
  352.           doAttachments();
  353.  
  354.           // Update prefs
  355.           toolboxItemChangeShowing(m_urlBar);
  356.  
  357.           notifyInterested(XFE_View::chromeNeedsUpdating);
  358.         }
  359.       return;
  360.     }
  361.   else if (cmd == xfeCmdTogglePersonalToolbar)
  362.     {
  363.       if (m_personalToolbar)
  364.         {
  365.           if (m_personalToolbar->isShown())
  366.             m_personalToolbar->hide();
  367.           else
  368.             m_personalToolbar->show();
  369.  
  370.           // Configure the logo
  371.           configureLogo();
  372.           
  373.           // Do the attachments
  374.           doAttachments();
  375.  
  376.           // Update prefs
  377.           toolboxItemChangeShowing(m_personalToolbar);
  378.  
  379.           notifyInterested(XFE_View::chromeNeedsUpdating);
  380.         }
  381.  
  382.       // XXX not implemented
  383.       return;
  384.     }
  385.  
  386.   else
  387.     XFE_Frame::doCommand(cmd, calldata, info);
  388. }
  389.  
  390. XP_Bool
  391. XFE_BrowserFrame::handlesCommand(CommandType cmd,
  392.                  void *calldata, XFE_CommandInfo*)
  393. {
  394.   if (cmd == xfeCmdToggleLocationToolbar
  395.       || cmd == xfeCmdTogglePersonalToolbar
  396.       )
  397.  
  398.     return True;
  399.   else
  400.     return XFE_Frame::handlesCommand(cmd, calldata);
  401. }
  402.  
  403. char *
  404. XFE_BrowserFrame::commandToString(CommandType cmd,
  405.                                   void *calldata, XFE_CommandInfo* info)
  406. {
  407.     if (cmd == xfeCmdTogglePersonalToolbar)
  408.     {
  409.       char *res = NULL;
  410.       
  411.       if (m_personalToolbar->isShown())
  412.         res = "hidePersonalToolbarCmdString";
  413.       else
  414.         res = "showPersonalToolbarCmdString";
  415.       
  416.       return stringFromResource(res);
  417.     }
  418.     else if (cmd == xfeCmdToggleLocationToolbar)
  419.     {
  420.         char *res = NULL;
  421.  
  422.         if (m_urlBar->isShown())
  423.             res = "hideLocationToolbarCmdString";
  424.         else
  425.             res = "showLocationToolbarCmdString";
  426.  
  427.         return stringFromResource(res);
  428.     }
  429.  
  430.   else
  431.     {
  432.       return XFE_Frame::commandToString(cmd, calldata, info);
  433.     }
  434. }
  435.  
  436. int
  437. XFE_BrowserFrame::getURL(URL_Struct *url, Boolean skip_get_url)
  438. {
  439.   XFE_HTMLView *hview = (XFE_HTMLView*)m_view;
  440.  
  441.   // we can't conditionally register here - otherwise fe_SetURLString
  442.   // won't work. we now do it in the constructor.
  443.   //  if (!m_notification_added)
  444.   //      {
  445.   //          m_notification_added = True;
  446.   //
  447.   //          registerInterest(XFE_HTMLView::newURLLoading, 
  448.   //                           this,
  449.   //                           (XFE_FunctionNotification)newPageLoading_cb);
  450.   //      }
  451.  
  452.   // set the url property
  453.   storeProperty (m_context, "_MOZILLA_URL", 
  454.                  url ? (const unsigned char *) url->address : (const unsigned char *)"");
  455.  
  456.   m_urlBar->setURLString(url);
  457.  
  458.   return hview->getURL(url, skip_get_url);
  459. }
  460.  
  461. void
  462. XFE_BrowserFrame::queryChrome(Chrome * chrome)
  463. {
  464.   if (!chrome)
  465.     return;
  466.   XFE_Frame::queryChrome(chrome);
  467.   chrome->show_url_bar           = m_urlBar && m_urlBar->isShown();
  468.   chrome->show_directory_buttons = m_personalToolbar && m_personalToolbar->isShown();
  469. }
  470.  
  471. void
  472. XFE_BrowserFrame::respectChrome(Chrome * chrome)
  473. {
  474.   if (!chrome)
  475.     return;
  476.  
  477. //  XFE_Frame::respectChrome(chrome);
  478.   
  479.   // URL Bar - aka - alias - used-to-be - location bar
  480.   if (m_urlBar) {
  481.     if (chrome->show_url_bar)
  482.         m_urlBar->show();
  483.     else
  484.         m_urlBar->hide();
  485.   }
  486.  
  487.   // Personal Toolbar - aka - alias - used-to-be - directory buttons
  488.   if (m_personalToolbar) {
  489.     if (chrome->show_directory_buttons)
  490.         m_personalToolbar->show();
  491.     else
  492.         m_personalToolbar->hide();
  493.   }
  494.  
  495.   // Chain respectChrome() _AFTER_ doing urlbar and personal toolbar, 
  496.   // so that the toolbox can be properly configured by the super class.
  497.   XFE_Frame::respectChrome(chrome);
  498. }
  499.  
  500.  
  501. XFE_CALLBACK_DEFN(XFE_BrowserFrame, navigateToURL)(XFE_NotificationCenter*, void*, void* callData)
  502. {
  503.     int status;
  504.     URL_Struct *url_struct = (URL_Struct*)callData;
  505.     
  506.     // update _MOZILLA_URL property
  507.     if (url_struct->address) {
  508.       storeProperty (m_context, "_MOZILLA_URL", 
  509.                (const unsigned char *) url_struct->address);
  510.     }
  511.     status = getURL(url_struct, FALSE);
  512.     
  513.     if (status >= 0)
  514.     {
  515. #ifdef NETSCAPE_PRIV
  516.         // Do logo easter eggs
  517.         if (getLogo())
  518.         {
  519.             getLogo()->easterEgg(url_struct);
  520.         }
  521. #endif /* NETSCAPE_PRIV */
  522.  
  523.         if (url_struct && url_struct->address)
  524.         {
  525.             m_urlBar->recordURL(url_struct);
  526.         }
  527.     }
  528. }
  529.  
  530. XFE_CALLBACK_DEFN(XFE_BrowserFrame, newPageLoading)
  531.     (XFE_NotificationCenter*, void*, void* callData)
  532. {
  533.     URL_Struct *url = (URL_Struct*)callData;
  534.     
  535.     // update _MOZILLA_URL property
  536.     if (url->address) {
  537.       storeProperty (m_context, "_MOZILLA_URL", 
  538.                (const unsigned char *) url->address);
  539.     }
  540.     m_urlBar->setURLString(url);
  541.  
  542. #ifdef NETSCAPE_PRIV
  543.     // Do logo easter eggs
  544.     if (getLogo())
  545.     {
  546.         getLogo()->easterEgg(url);
  547.     }
  548. #endif /* NETSCAPE_PRIV */
  549. }
  550.  
  551. XFE_CALLBACK_DEFN(XFE_BrowserFrame, updateToolbarAppearance)(XFE_NotificationCenter */*obj*/, 
  552.                                        void */*clientData*/, 
  553.                                        void */*callData*/)
  554. {
  555.   updateToolbar();
  556. }
  557.  
  558. /*static*/
  559. void
  560. XFE_BrowserFrame::bringToFrontOrMakeNew(Widget toplevel)
  561. {
  562.   // This follows the "Do as I mean" Taskbar spec
  563.   //   if 0 browsers, make a new one.
  564.   //   if 1 browser and it is most recent, bring up new one
  565.   //      otherwise bring up the one that exists
  566.   //   if >1 browsers, cycle through them by
  567.   //      bringing the oldest to the front
  568.  
  569.   XP_List *browserList =
  570.     XFE_MozillaApp::theApp()->getFrameList(FRAME_BROWSER);
  571.  
  572.   int browserCount = XP_ListCount(browserList);
  573.  
  574.   struct fe_MWContext_cons *cons = fe_all_MWContexts;
  575.  
  576.   MWContext *leastRecentContext = NULL;
  577.  
  578.   if (browserCount == 0 ||
  579.       (browserCount == 1 &&
  580.        cons && cons->context->type == MWContextBrowser))
  581.     {
  582.       fe_showBrowser(toplevel, NULL, NULL,
  583.                      fe_GetBrowserStartupUrlStruct());
  584.     }
  585.   else
  586.     {
  587.       for (; cons; cons = cons->next)
  588.         {
  589.           if (cons->context->type == MWContextBrowser
  590.               && !cons->context->is_grid_cell)
  591.             leastRecentContext = cons->context;
  592.         }
  593.  
  594.       XFE_Frame *leastRecentFrame = ViewGlue_getFrame(leastRecentContext);
  595.  
  596.       if (leastRecentFrame)
  597.         {
  598.           leastRecentFrame->show();
  599.  
  600.           // Reorder fe_all_MWContexts to reflect the raise
  601.           fe_UserActivity (leastRecentContext);
  602.         }
  603.       else  // We shouldn't get here, but just in case...
  604.         {
  605.           fe_showBrowser(toplevel, NULL, NULL, 
  606.                          fe_GetBrowserStartupUrlStruct());
  607.         }
  608.     }
  609. }
  610.  
  611. extern "C" MWContext *
  612. fe_reuseBrowser(MWContext * context, URL_Struct *url)
  613. {
  614.     if (!context)
  615.     {
  616.         return fe_showBrowser(FE_GetToplevelWidget(), NULL, NULL, url);
  617.     }
  618.  
  619.     Widget toplevel = XtParent(CONTEXT_WIDGET(context));
  620.     
  621.     if (context->type != MWContextBrowser)
  622.     {
  623.         context = fe_FindNonCustomBrowserContext(context);
  624.     }
  625.  
  626.     MWContext * top_context = XP_GetNonGridContext(context);
  627.  
  628.     if (top_context && top_context->type == MWContextBrowser)
  629.     {
  630.         // NOTE:  if someone else is calling us make sure the browser
  631.         //        window get's raised to the front...
  632.         //
  633.  
  634.         // Popup the shell first, so that we gurantee its realized 
  635.         //
  636.         XtPopup(CONTEXT_WIDGET(top_context),XtGrabNone);
  637.         
  638.         // Force the window to the front and de-iconify if needed 
  639.         //
  640.         XMapRaised(XtDisplay(CONTEXT_WIDGET(top_context)),
  641.                    XtWindow(CONTEXT_WIDGET(top_context)));
  642.  
  643.         fe_GetURL (top_context, url, FALSE);
  644.  
  645.         return top_context;
  646.     }
  647.     else
  648.     {
  649.         return fe_showBrowser(toplevel, NULL, NULL, url);
  650.     }
  651. }
  652.  
  653. extern "C" MWContext *
  654. fe_showBrowser(Widget toplevel, XFE_Frame *parent_frame, Chrome *chromespec, URL_Struct *url)
  655. {
  656.   // not a static global, since we can have multiple browsers.
  657.     XFE_BrowserFrame *theFrame;
  658.     MWContext *theContext = NULL;
  659.     
  660.     D( printf("in showBrowser()\n"); );
  661.     
  662.     theFrame = new XFE_BrowserFrame(toplevel, parent_frame, chromespec);
  663.     
  664.     theFrame->show();
  665.     
  666.     theContext = theFrame->getContext();
  667.  
  668.     if ((!chromespec || chromespec->type != MWContextHTMLHelp)
  669.         && plonk(theContext))
  670.         {
  671.             url = 0;
  672.             
  673.             if (!fe_contextIsValid(theContext)) return NULL;
  674.         }
  675.  
  676.     if (!fe_VendorAnim)
  677.       if (NET_CheckForTimeBomb (theContext))
  678.         url = 0;
  679.  
  680.         if (url == NULL) {
  681.             if (!plonk_cancelled())
  682.                 theFrame->getURL(url, (url == NULL));
  683.             //fe_home_cb(toplevel, theFrame->getContext(), NULL);
  684.             //else
  685.             // do nothing - assume the plonk canceller is loading a page.
  686.             // (i.e. XFE_BrowserDrop after a desktop file was dropped.)
  687.         }
  688.         else {
  689.             theFrame->getURL(url, (url == NULL));
  690.         }
  691.         
  692.     // hang properties for the browser window
  693.   
  694.     theFrame->storeProperty (theContext,
  695.                (char *) "_MOZILLA_VERSION",
  696.                (const unsigned char *) fe_version);
  697.  
  698.     D( printf("leaving showBrowser()\n"); );
  699.  
  700.     return theContext;
  701. }
  702.  
  703. /* A wrapper of XFE_showBrowser() above
  704.  */
  705. extern "C" MWContext *
  706. XFE_showBrowser(Widget toplevel, URL_Struct *url)
  707. {
  708.     return fe_showBrowser(toplevel, NULL, NULL, url);
  709. }
  710.  
  711. //
  712. //    Yet another wrapper. Defined in xfe.h
  713. //
  714. extern "C" MWContext*
  715. fe_BrowserGetURL(MWContext* context, char* address)
  716. {
  717.     return fe_reuseBrowser(context,
  718.                            NET_CreateURLStruct(address, NET_DONT_RELOAD));
  719. }
  720.  
  721. //////////////////////////////////////////////////////////////////////////
  722. //
  723. // Toolbox methods
  724. //
  725. //////////////////////////////////////////////////////////////////////////
  726. void
  727. XFE_BrowserFrame::toolboxItemSnap(XFE_ToolboxItem * item)
  728. {
  729.     XP_ASSERT( item == m_toolbar || 
  730.                item == m_urlBar || 
  731.                item == m_personalToolbar );
  732.  
  733.     // Navigation
  734.     fe_globalPrefs.browser_navigation_toolbar_position = m_toolbar->getPosition();
  735.  
  736.     // Location
  737.     fe_globalPrefs.browser_location_toolbar_position = m_urlBar->getPosition();
  738.  
  739.     // Personal
  740.     fe_globalPrefs.browser_personal_toolbar_position = m_personalToolbar->getPosition();
  741. }
  742. //////////////////////////////////////////////////////////////////////////
  743. void
  744. XFE_BrowserFrame::toolboxItemClose(XFE_ToolboxItem * item)
  745. {
  746.     XP_ASSERT( item != NULL );
  747.  
  748.     // Navigation
  749.     if (item == m_toolbar)
  750.     {
  751.         fe_globalPrefs.browser_navigation_toolbar_open = False;
  752.     }
  753.     // Location
  754.     else if (item == m_urlBar)
  755.     {
  756.         fe_globalPrefs.browser_location_toolbar_open = False;
  757.     }
  758.     // Personal
  759.     else if (item == m_personalToolbar)
  760.     {
  761.         fe_globalPrefs.browser_personal_toolbar_open = False;
  762.     }
  763. }
  764. //////////////////////////////////////////////////////////////////////////
  765. void
  766. XFE_BrowserFrame::toolboxItemOpen(XFE_ToolboxItem * item)
  767. {
  768.     XP_ASSERT( item != NULL );
  769.  
  770.     // Navigation
  771.     if (item == m_toolbar)
  772.     {
  773.         fe_globalPrefs.browser_navigation_toolbar_open = True;
  774.     }
  775.     // Location
  776.     else if (item == m_urlBar)
  777.     {
  778.         fe_globalPrefs.browser_location_toolbar_open = True;
  779.     }
  780.     // Personal
  781.     else if (item == m_personalToolbar)
  782.     {
  783.         fe_globalPrefs.browser_personal_toolbar_open = True;
  784.     }
  785. }
  786. //////////////////////////////////////////////////////////////////////////
  787. void
  788. XFE_BrowserFrame::toolboxItemChangeShowing(XFE_ToolboxItem * item)
  789. {
  790.     XP_ASSERT( item != NULL );
  791.  
  792.     // Navigation
  793.     if (item == m_toolbar)
  794.     {
  795.         fe_globalPrefs.browser_navigation_toolbar_showing = item->isShown();
  796.     }
  797.     // Location
  798.     else if (item == m_urlBar)
  799.     {
  800.         fe_globalPrefs.browser_location_toolbar_showing = item->isShown();
  801.     }
  802.     // Personal
  803.     else if (item == m_personalToolbar)
  804.     {
  805.         fe_globalPrefs.browser_personal_toolbar_showing = item->isShown();
  806.     }
  807. }
  808. //////////////////////////////////////////////////////////////////////////
  809. void
  810. XFE_BrowserFrame::configureToolbox()
  811. {
  812.     // If a the frame was constructed with a chromespec, then we ignore
  813.     // all the preference magic.
  814.     if (m_chromespec_provided)
  815.     {
  816.         return;
  817.     }
  818.  
  819.     // Make sure the toolbox is alive
  820.     if (!m_toolbox || (m_toolbox && !m_toolbox->isAlive()))
  821.     {
  822.         return;
  823.     }
  824.  
  825. //    printf("configureToolbox(%s)\n",XtName(m_widget));
  826.  
  827.     // Navigation
  828.     if (m_toolbar)
  829.     {
  830.         m_toolbar->setShowing(fe_globalPrefs.browser_navigation_toolbar_showing);
  831.         m_toolbar->setOpen(fe_globalPrefs.browser_navigation_toolbar_open);
  832.         m_toolbar->setPosition(fe_globalPrefs.browser_navigation_toolbar_position);
  833.     }
  834.  
  835.     // Location
  836.     if (m_urlBar)
  837.     {
  838.         m_urlBar->setShowing(fe_globalPrefs.browser_location_toolbar_showing);
  839.         m_urlBar->setOpen(fe_globalPrefs.browser_location_toolbar_open);
  840.         m_urlBar->setPosition(fe_globalPrefs.browser_location_toolbar_position);
  841.     }
  842.  
  843.     // Personal
  844.     if (m_personalToolbar)
  845.     {
  846.         m_personalToolbar->setShowing(fe_globalPrefs.browser_personal_toolbar_showing);
  847.         m_personalToolbar->setOpen(fe_globalPrefs.browser_personal_toolbar_open);
  848.         m_personalToolbar->setPosition(fe_globalPrefs.browser_personal_toolbar_position);
  849.     }
  850. }
  851. //////////////////////////////////////////////////////////////////////////
  852.