home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / URLBar.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  23.3 KB  |  901 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.    URLBar.cpp -- The text field chrome above an HTMLView, used in
  20.                BrowserFrames.
  21.    Created: Chris Toshok <toshok@netscape.com>, 1-Nov-96.
  22.    */
  23.  
  24.  
  25. #include "mozilla.h"
  26. #include "xfe.h"
  27. #include "hk_funcs.h"
  28. #include "URLBar.h"
  29.  
  30. #include "Button.h"
  31. #include "ProxyIcon.h"
  32. #include "BookmarkMenu.h"      // Need for bookmark context.
  33. #include "MozillaApp.h"
  34. #include "Logo.h"
  35. #include "prefapi.h"
  36. #include "felocale.h"
  37.  
  38. #include <Xm/Form.h>
  39. #include <Xm/Label.h>
  40. #include <Xm/TextF.h>
  41.  
  42. #include "DtWidgets/ComboBox.h"
  43.  
  44. #include <Xfe/ToolItem.h>
  45. #include <Xfe/FrameShell.h>
  46.  
  47. #include "libmocha.h"   // For LM_StripWysiwygURLPrefix().
  48.  
  49. #include <xpgetstr.h>
  50.  
  51. #ifdef URLBAR_POPUP
  52. #include "View.h"
  53. #endif /* URLBAR_POPUP */
  54.  
  55. extern int XFE_URLBAR_FILE_HEADER;
  56.  
  57. extern "C" void fe_NeutralizeFocus(MWContext *context);
  58.  
  59. #define BOOKMARK_BUTTON_NAME        "bookmarkQuickfile"
  60. #define LOCATION_LABEL_NAME            "urlLocationLabel"
  61. #define LOCATION_PROXY_ICON_NAME    "urlLocationProxyIcon"
  62. #define URL_COMBO_BOX_NAME            "urlComboBox"
  63. #define URL_BAR_NAME                "urlBarItem"
  64. #define MAIN_FORM_NAME                "urlBarMainForm"
  65. #define LOGO_NAME                    "logo"
  66.  
  67. const char *XFE_URLBar::navigateToURL = "XFE_URLBar::navigateToURL";
  68.  
  69. // Quickfile Menu Spec
  70. /* static */ MenuSpec
  71. XFE_URLBar::quickfile_menu_spec[] = 
  72. {
  73.     {
  74.         xfeCmdAddBookmark,        
  75.         PUSHBUTTON 
  76.     },
  77.     { 
  78.         "fileBookmarksSubmenu",     
  79.         DYNA_FANCY_CASCADEBUTTON, 
  80.         NULL, 
  81.         NULL, 
  82.         False, 
  83.         (void *) True,                    // Only headers 
  84.         XFE_BookmarkMenu::generate
  85.     },
  86.     {
  87.         xfeCmdOpenBookmarks,    
  88.         PUSHBUTTON 
  89.     },
  90.     MENU_SEPARATOR,
  91.     { 
  92.         "bookmarkPlaceHolder",
  93.         DYNA_MENUITEMS,
  94.         NULL,
  95.         NULL,
  96.         False,
  97.         (void *) False,                    // Only headers
  98.         XFE_BookmarkMenu::generateQuickfile
  99.     },
  100.     {
  101.         NULL 
  102.     }
  103. };
  104.  
  105.  
  106. #ifdef URLBAR_POPUP
  107. MenuSpec XFE_URLBar::ccp_popup_spec[] = {
  108.   //  { xfeCmdUndo,  PUSHBUTTON },
  109.   //  { xfeCmdRedo,  PUSHBUTTON },
  110.   //  MENU_SEPARATOR,
  111.   { xfeCmdCut,   PUSHBUTTON },
  112.   { xfeCmdCopy,  PUSHBUTTON },
  113.   { xfeCmdPaste, PUSHBUTTON },
  114.   //  { xfeCmdDeleteItem, PUSHBUTTON },
  115.   MENU_SEPARATOR,
  116.   { xfeCmdSelectAll, PUSHBUTTON },
  117.   { NULL },
  118. };
  119. #endif /* URLBAR_POPUP */
  120.  
  121. XFE_URLBar::XFE_URLBar(XFE_Frame *        parent_frame,
  122.                        XFE_Toolbox *    parent_toolbox,
  123.                        History_entry *    first_entry) :
  124.     XFE_ToolboxItem(parent_frame,parent_toolbox),
  125.     
  126.     m_editedLabelString(NULL),
  127.     m_uneditedLabelString(NULL),
  128.     m_netsiteLabelString(NULL),
  129.     
  130.     m_parentFrame(parent_frame),
  131.     
  132.     m_bookmarkButton(NULL),
  133.     m_locationProxyIcon(NULL),
  134.     m_locationLabel(NULL),
  135.     m_urlComboBox(NULL),
  136.     
  137.     m_labelBeingFrobbed(False),
  138.     
  139.     m_proxyIconDragSite(NULL),
  140.  
  141.     m_bookmarkDropSite(NULL)
  142.     
  143. #ifdef URLBAR_POPUP
  144.     ,m_popup(NULL)
  145. #endif /* URLBAR_POPUP */
  146. {
  147.     Widget main_form;
  148.  
  149.     // Create the base widget - a tool item
  150.     m_widget = XtVaCreateWidget(URL_BAR_NAME,
  151.                                 xfeToolItemWidgetClass,
  152.                                 parent_toolbox->getBaseWidget(),
  153.                                 XmNuserData,            this,
  154.                                 NULL);
  155.  
  156.     // Create the main form
  157.     main_form = XtVaCreateManagedWidget(MAIN_FORM_NAME,
  158.                                         xmFormWidgetClass,
  159.                                         m_widget,
  160.                                         NULL);
  161.     
  162.     // Create the bookmark button
  163.     createBookmarkButton(main_form);
  164.     
  165.     XP_ASSERT( m_bookmarkButton != NULL );
  166.  
  167.     // Show the bookmark button
  168.     m_bookmarkButton->show();
  169.     
  170.     // Create the proxy icon
  171.     createProxyIcon(main_form);
  172.     
  173.     XP_ASSERT( m_locationProxyIcon != NULL );
  174.     XP_ASSERT( XfeIsAlive(m_locationLabel) );
  175.  
  176.     // Show the proxy icon and label
  177.     m_locationProxyIcon->show();
  178.     
  179.     XtManageChild(m_locationLabel);
  180.  
  181.     // Create the url text combo box
  182.     createUrlComboBox(main_form,first_entry);
  183.     
  184.     XP_ASSERT( XfeIsAlive(m_urlComboBox) );
  185.  
  186.     // Create the logo
  187.     // Create the logo
  188.     m_logo = new XFE_Logo(m_parentFrame,m_widget,LOGO_NAME);
  189.  
  190.     m_logo->setSize(XFE_ANIMATION_SMALL);
  191.  
  192.     // Show the url text
  193.     XtManageChild(m_urlComboBox);
  194.  
  195.     // Attach and configure the logo
  196.     configureLogo();
  197.  
  198.     // Show the main form
  199.     XtManageChild(main_form);
  200.  
  201.     // Register url bar widgets for dragging
  202.     addDragWidget(getFormWidget());
  203.     addDragWidget(getUrlLabel());
  204.  
  205.     installDestroyHandler();
  206.  
  207. #ifdef URLBAR_POPUP
  208.     Widget text_field;
  209.     XtVaGetValues(m_urlComboBox, XmNtextField, &text_field, 0);
  210.  
  211.     // Add popup menu post event handler to floating task bar items
  212.     XtAddEventHandler(
  213.                       text_field,
  214.                       ButtonPressMask,
  215.                       True,
  216.                       &XFE_URLBar::comboBoxButtonPressEH,
  217.                       (XtPointer *)this
  218.                       );
  219. #endif /* URLBAR_POPUP */
  220. }
  221. //////////////////////////////////////////////////////////////////////////
  222. void
  223. XFE_URLBar::createBookmarkButton(Widget parent)
  224. {
  225.     XP_ASSERT( XfeIsAlive(parent) );
  226.     XP_ASSERT( m_bookmarkButton == NULL );
  227.  
  228.     // Bookmark quickfile button.
  229.     m_bookmarkButton = new XFE_Button(m_parentFrame,
  230.                                       parent,
  231.                                       BOOKMARK_BUTTON_NAME,
  232.                                       XFE_URLBar::quickfile_menu_spec,
  233.                                       &BM_QFile_group);
  234.     
  235.     // Configure the bookmark button
  236.     m_bookmarkButton->setPretendSensitive(True);
  237.  
  238.     // Place the bookmark quickfile to the far left
  239.     XtVaSetValues(m_bookmarkButton->getBaseWidget(),
  240.                   XmNleftAttachment,        XmATTACH_FORM,
  241.                   XmNrightAttachment,        XmATTACH_NONE,
  242.                   XmNtopAttachment,            XmATTACH_FORM,
  243.                   XmNbottomAttachment,        XmATTACH_NONE,
  244.                   NULL);
  245.  
  246.     // Add the submenu torn callbacks
  247.     XtAddCallback(m_bookmarkButton->getBaseWidget(),
  248.                   XmNsubmenuTearCallback,
  249.                   &XFE_URLBar::bookmarkCascadeTearCB,
  250.                   (XtPointer) this);
  251.  
  252.     // Keep track of changes in the top level shell title
  253.     Widget frame_shell = m_parentFrame->getBaseWidget();
  254.  
  255.     if (XfeIsAlive(frame_shell) && XfeIsFrameShell(frame_shell))
  256.     {
  257.         Boolean allow_tear;
  258.  
  259.         XtVaGetValues(m_bookmarkButton->getBaseWidget(),
  260.                       XmNallowTearOff,&allow_tear,
  261.                       NULL);
  262.  
  263.         if (allow_tear)
  264.         {
  265.             XtAddCallback(frame_shell,
  266.                           XmNtitleChangedCallback,
  267.                           &XFE_URLBar::frameTitleChangedCB,
  268.                           (XtPointer) this);
  269.         }
  270.     }
  271.     
  272.     // The XFE_BookmarkMenu class overrides the XmNinstancePointer which was
  273.     // originally set in XFE_Button.  This is really horrible.
  274.     XFE_BookmarkMenu * quickfileMenu = 
  275.         (XFE_BookmarkMenu *) XfeInstancePointer(m_bookmarkButton->getBaseWidget());
  276.  
  277.     XP_ASSERT( quickfileMenu != NULL );
  278.  
  279.     // Create and enable the quickfile drop site
  280.     m_bookmarkDropSite = new 
  281.         XFE_QuickfileDrop(m_bookmarkButton->getBaseWidget(),quickfileMenu);
  282.  
  283.     m_bookmarkDropSite->enable();
  284. }
  285. //////////////////////////////////////////////////////////////////////////
  286.  
  287. // URL Label string resources ( for Location: Netsite: etc )
  288. /* static */ XtResource
  289. XFE_URLBar::_urlLabelResources[] = 
  290. {
  291.     {
  292.         "editedLabelString",
  293.         XmCXmString,
  294.         XmRXmString,
  295.         sizeof(XmString),
  296.         XtOffset(XFE_URLBar *, m_editedLabelString),
  297.         XtRString,
  298.         "Error!"
  299.     },
  300.     {
  301.         "uneditedLabelString",
  302.         XmCXmString,
  303.         XmRXmString,
  304.         sizeof(XmString),
  305.         XtOffset(XFE_URLBar *, m_uneditedLabelString),
  306.         XtRString,
  307.         "Error!" 
  308.     },
  309.     {
  310.         "netsiteLabelString",
  311.         XmCXmString,
  312.         XmRXmString,
  313.         sizeof(XmString),
  314.         XtOffset(XFE_URLBar *, m_netsiteLabelString),
  315.         XtRString,
  316.         "Error!" 
  317.     }
  318. };
  319.  
  320. void
  321. XFE_URLBar::createProxyIcon(Widget parent)
  322. {
  323.     XP_ASSERT( XfeIsAlive(parent) );
  324.     XP_ASSERT( m_locationProxyIcon == NULL );
  325.     XP_ASSERT( m_locationLabel == NULL );
  326.  
  327.     // Proxy icon
  328.     m_locationProxyIcon = new XFE_Button(m_parentFrame,
  329.                                          parent,
  330.                                          LOCATION_PROXY_ICON_NAME,
  331.                                          &LocationProxy_group);
  332.     
  333.     // Configure the bookmark button
  334.     m_locationProxyIcon->setPretendSensitive(True);
  335.  
  336.     // Location label
  337.     m_locationLabel = 
  338.         XtVaCreateManagedWidget(LOCATION_LABEL_NAME, 
  339.                                 xmLabelWidgetClass, 
  340.                                 parent,
  341.                                 NULL);
  342.  
  343.     // Load the url label strings
  344.     XtGetApplicationResources(m_locationLabel,
  345.                               (XtPointer) this,
  346.                               XFE_URLBar::_urlLabelResources,
  347.                               XtNumber(XFE_URLBar::_urlLabelResources),
  348.                               0,
  349.                               0);
  350.     
  351.  
  352.     // Place the proxy icon right after the bookmark quickfile
  353.     XtVaSetValues(m_locationProxyIcon->getBaseWidget(),
  354.                   XmNleftAttachment,        XmATTACH_WIDGET,
  355.                   XmNrightAttachment,        XmATTACH_NONE,
  356.                   XmNtopAttachment,            XmATTACH_FORM,
  357.                   XmNbottomAttachment,        XmATTACH_NONE,
  358.                   XmNleftWidget,            m_bookmarkButton->getBaseWidget(),
  359.                   NULL);
  360.  
  361.     // Place the location label right after the proxy icon
  362.     XtVaSetValues(m_locationLabel,
  363.                   XmNleftAttachment,        XmATTACH_WIDGET,
  364.                   XmNleftWidget,        m_locationProxyIcon->getBaseWidget(),
  365.                   XmNrightAttachment,        XmATTACH_NONE,
  366.                   XmNtopAttachment,            XmATTACH_FORM,
  367.                   XmNbottomAttachment,        XmATTACH_FORM,
  368.                   NULL);
  369.  
  370.     m_proxyIconDragSite = new XFE_LocationDrag(m_locationProxyIcon->getBaseWidget());
  371.     
  372.     // Register proxy icon to have a tooltip.
  373.     fe_WidgetAddToolTips(m_locationProxyIcon->getBaseWidget());
  374. }
  375. //////////////////////////////////////////////////////////////////////////
  376. void
  377. XFE_URLBar::createUrlComboBox(Widget parent,History_entry * first_entry)
  378. {
  379.     XP_ASSERT( XfeIsAlive(parent) );
  380.     XP_ASSERT( m_urlComboBox == NULL );
  381.  
  382.     Arg            av[22];
  383.     Cardinal    ac = 0;
  384.     Visual *    visual = 0;
  385.     Colormap    cmap = 0;
  386.     Cardinal    depth = 0;
  387.     Widget        text_field;
  388.     
  389.     XtVaGetValues(m_parentFrame->getBaseWidget(),
  390.                   XtNvisual,    &visual, 
  391.                   XtNcolormap,    &cmap,
  392.                   XtNdepth,        &depth,
  393.                   NULL);
  394.           
  395.     ac = 0;
  396.     XtSetArg(av[ac],XmNmoveSelectedItemUp,    True);                    ac++;
  397.     XtSetArg(av[ac],XmNarrowType,            XmMOTIF);                 ac++;
  398.     XtSetArg(av[ac],XmNtype,                XmDROP_DOWN_COMBO_BOX); ac++;
  399.     XtSetArg(av[ac],XmNvisibleItemCount,    10 );                    ac++;
  400.     XtSetArg(av[ac],XmNvisual,                visual);                ac++;
  401.     XtSetArg(av[ac],XmNcolormap,            cmap);                    ac++;
  402.     XtSetArg(av[ac],XmNdepth,                depth);                    ac++;
  403.     XtSetArg(av[ac],XmNmarginHeight,        0);                        ac++;
  404.     XtSetArg(av[ac],XmNleftAttachment,        XmATTACH_WIDGET);        ac++;
  405.     XtSetArg(av[ac],XmNleftWidget,            m_locationLabel);        ac++;
  406.     XtSetArg(av[ac],XmNtopAttachment,        XmATTACH_FORM);            ac++;
  407.     XtSetArg(av[ac],XmNbottomAttachment,    XmATTACH_FORM);            ac++;
  408.     XtSetArg(av[ac],XmNrightAttachment,        XmATTACH_FORM);            ac++;
  409.     XtSetArg(av[ac],XmNrightOffset,            0);                        ac++;
  410.  
  411.     // The combo box calls XmNactivateCallback for both its text and
  412.     // arrow.  This is very confusing since clicking on the arrow does
  413.     // not really "activate" the combo box...so i added a combo box
  414.     // boolean resource to avoid calling this callback.  This fixes bug
  415.     // 71097 (browser reload by just posting the url combo box).
  416.     XtSetArg(av[ac],XmNnoCallbackForArrow,    True);                    ac++;
  417.  
  418.     /* Create a combobox for storing typed in url history */
  419.     /* This replaces the old text field */
  420.     /* Combobox is only for MWContextBrowser */
  421.     m_urlComboBox = DtCreateComboBox(parent, URL_COMBO_BOX_NAME, av,ac);
  422.     
  423.     XtVaGetValues(m_urlComboBox, XmNtextField, &text_field, 0);
  424.           
  425.     /* Loads the previous session history list from a 
  426.        designated file ("~/.netscape/history.list") */
  427.     readUserHistory();
  428.           
  429.     XtAddCallback(text_field, 
  430.                   XmNmodifyVerifyCallback, 
  431.                   url_text_modify_cb,
  432.                   (XtPointer) this);
  433.  
  434.     String value = "";
  435.  
  436.     if (first_entry && first_entry->address)
  437.     {
  438.         value = first_entry->address;
  439.     }
  440.           
  441.     XtVaSetValues (text_field,
  442.                    XmNcursorPosition,    0,
  443.                    0);
  444.     fe_SetTextField (text_field, value);
  445.           
  446.     XtAddCallback(m_urlComboBox, 
  447.                   XmNselectionCallback,
  448.                   url_text_selection_cb,
  449.                   (XtPointer) this);
  450.     
  451.     XtAddCallback(m_urlComboBox,
  452.                   XmNactivateCallback,
  453.                   url_text_cb,
  454.                   (XtPointer) this);
  455. }
  456. //////////////////////////////////////////////////////////////////////////
  457. XFE_URLBar::~XFE_URLBar()
  458. {
  459. #ifdef URLBAR_POPUP
  460.     if (m_popup)
  461.     {
  462.         delete m_popup;
  463.         m_popup = NULL;
  464.     }
  465. #endif /* URLBAR_POPUP */
  466.  
  467.     if (m_proxyIconDragSite) 
  468.     {
  469.         delete m_proxyIconDragSite;
  470.  
  471.         m_proxyIconDragSite = NULL;
  472.     }
  473.  
  474.     if (m_bookmarkDropSite)
  475.     {
  476.         delete m_bookmarkDropSite;
  477.  
  478.         m_bookmarkDropSite = NULL;
  479.     }
  480. }
  481. //////////////////////////////////////////////////////////////////////////
  482. Widget
  483. XFE_URLBar::getBookMarkButton()
  484. {
  485.     return m_bookmarkButton->getBaseWidget();
  486. }
  487. //////////////////////////////////////////////////////////////////////////
  488. Widget
  489. XFE_URLBar::getProxyIcon()
  490. {
  491.     return m_locationProxyIcon->getBaseWidget();
  492. }
  493. //////////////////////////////////////////////////////////////////////////
  494. Widget
  495. XFE_URLBar::getUrlLabel()
  496. {
  497.     return m_locationLabel;
  498. }
  499. //////////////////////////////////////////////////////////////////////////
  500. Widget
  501. XFE_URLBar::getFormWidget()
  502. {
  503.     return XtParent(m_locationLabel);
  504. }
  505. //////////////////////////////////////////////////////////////////////////
  506. void
  507. XFE_URLBar::recordURL(URL_Struct *url)
  508. {
  509.   XmString str;
  510.   int itemCount = 0;
  511.   Widget list;
  512.   int *posList;
  513.   int poscnt;
  514.   Boolean found = False;
  515.  
  516.   if ( !url->address ) return;
  517.   str = XmStringCreateLtoR(url->address, XmSTRING_DEFAULT_CHARSET);
  518.   XtVaGetValues(m_urlComboBox, XmNlist, &list, 0);
  519.  
  520.   found = XmListGetMatchPos(list, str, &posList, &poscnt);
  521.  
  522.   if ( found )
  523.   {
  524.       XmListDeletePos(list,posList[0]);
  525.   }
  526.   {
  527.     XtVaGetValues(list, XmNitemCount, &itemCount, 0 );
  528.         if ( itemCount >= 10 )
  529.         {
  530.       XmListDeleteItemsPos(list,1,10);
  531.         }
  532.     XmListAddItem(list,str, 1);
  533.     XmListSelectPos(list, 1, False);
  534.         XmListSetPos(list, 1); /* Scroll to top */
  535.   }
  536.   
  537.   /* Save to history */
  538.   saveUserHistory();
  539. }
  540.  
  541. void
  542. XFE_URLBar::setURLString(URL_Struct *url)
  543. {
  544.   /* Fixing a bug in motif that sends junk values
  545.      if SetValues is done on a widget that has
  546.      modifyVerifyCallback
  547.      And I really hate the way XtCallbackList is being
  548.      handled. There is no way to easily copy one. I prefer
  549.      to use explicitly XtCallbackRec * instead of hiding this
  550.      and using XtCallbackList. Makes this code more readable.
  551.      */
  552.  
  553.   /* update ProxyIcon drag object with new URL */
  554.   if (m_proxyIconDragSite)
  555.         m_proxyIconDragSite->setDragData(url);
  556.  
  557.   XtCallbackRec *cblist, *text_cb;
  558.   int i;
  559.   Widget text;
  560.   
  561.   XtVaGetValues(m_urlComboBox, XmNtextField, &text, 0);
  562.   if (!text ) return;
  563.   
  564.   if (!url || (sploosh && url && !strcmp (url->address, sploosh))
  565.       || (url && !strcmp (url->address, "about:blank")))
  566.     url = 0;
  567.  
  568.   XP_ASSERT(!m_labelBeingFrobbed);
  569.   /* Inhibit fe_url_text_modify_cb() for this call. */
  570.   m_labelBeingFrobbed = True;
  571.   XtVaSetValues (text, XmNcursorPosition, 0, 0);
  572.   
  573.   /* Get and save the modifyVerifyCallbacklist */
  574.   XtVaGetValues (text, XmNmodifyVerifyCallback, &text_cb, 0);
  575.   for(i=0; text_cb[i].callback != NULL; i++);
  576.   i++;
  577.   cblist = (XtCallbackRec *) malloc(sizeof(XtCallbackRec)*i);
  578.   for(i=0; text_cb[i].callback != NULL; i++)
  579.     cblist[i] = text_cb[i];
  580.   cblist[i] = text_cb[i];
  581.   
  582.   /* NULL the modifyVerifyCallback before doing setvalues */
  583.   XtVaSetValues (text, XmNmodifyVerifyCallback, NULL, 0);
  584.   
  585.   fe_SetTextField (text, 
  586.                  (url && url->address ? 
  587.                             // Check for JavaScript wysiwyg mangling
  588.                             // Fixes bug 28035.
  589.                             (LM_StripWysiwygURLPrefix(url->address) ?
  590.                              LM_StripWysiwygURLPrefix(url->address) : 
  591.                              url->address) : 
  592.                             ""));
  593.   
  594.   /* Setback the modifyVerifyCallback List from our saved List */
  595.   XtVaSetValues (text, XmNmodifyVerifyCallback, cblist, 0);
  596.   XP_FREE(cblist);
  597.  
  598.   m_labelBeingFrobbed = False;
  599.   frob_label (False, url && url->is_netsite);  
  600.  
  601. #ifdef notyet
  602.   fe_store_url_prop(context, url);
  603. #endif /* notyet */
  604. }
  605.  
  606.  
  607. XP_Bool
  608. XFE_URLBar::readUserHistory()
  609. {
  610.  XmString xmstr;
  611.  char *value;
  612.  char buffer[1024];
  613.  FILE *fp = fopen(fe_globalPrefs.user_history_file,"r");
  614.  
  615.  if ( !fp )
  616.     return FALSE;
  617.  
  618.  if ( !fgets(buffer, 1024, fp) )
  619.     *buffer = 0;
  620.  
  621.  while ( fgets(buffer, 1024, fp ) )
  622.  {
  623.     value = XP_StripLine(buffer);
  624.  
  625.         if (strlen(value)==0 || *value == '#')
  626.        continue;
  627.     xmstr = XmStringCreateLtoR(value, XmSTRING_DEFAULT_CHARSET);
  628.     DtComboBoxAddItem( m_urlComboBox, xmstr,0, True );
  629.         XmStringFree(xmstr);
  630.  }
  631.  fclose(fp);
  632.  return TRUE;
  633. }
  634.  
  635. /* For saving out the user typed in url history list to a file*/
  636. XP_Bool
  637. XFE_URLBar::saveUserHistory()
  638. {
  639.  int i,itemCount;
  640.  XmStringTable itemList;
  641.  char *urlStr;
  642.  char *filename = fe_globalPrefs.user_history_file;
  643.  FILE *fp = fopen(filename,"w");
  644.  
  645.  if ( !fp )
  646.     return FALSE;
  647.  
  648.  fprintf (fp,
  649.           XP_GetString(XFE_URLBAR_FILE_HEADER),
  650.           fe_version);
  651.  
  652.  XtVaGetValues(m_urlComboBox, XmNitemCount, &itemCount, XmNitems, &itemList, NULL);
  653.  for ( i = 0; i < itemCount; i++ )
  654.  {
  655.     XmStringGetLtoR( itemList[i], XmSTRING_DEFAULT_CHARSET, &urlStr);
  656.     fputs(urlStr, fp);
  657.     fputc('\n', fp);
  658.  }
  659.  fclose(fp);
  660.  return TRUE;
  661. }
  662.  
  663. void
  664. XFE_URLBar::frob_label(XP_Bool edited_p,
  665.                        XP_Bool netsite_p)
  666. {
  667. //    MWContext *context = m_parentFrame->getContext();
  668.     XmString old_string = 0;
  669.     XmString new_string = (edited_p
  670.                            ? m_editedLabelString
  671.                            : (netsite_p
  672.                               ? m_netsiteLabelString
  673.                               : m_uneditedLabelString));
  674.  
  675.     XP_ASSERT(new_string);
  676.  
  677.     XtVaGetValues (m_locationLabel, XmNlabelString, &old_string, 0);
  678.     if (!XmStringByteCompare (old_string, new_string))
  679.         XtVaSetValues (m_locationLabel, XmNlabelString, new_string, 0);
  680.     XmStringFree (old_string);
  681. }
  682.  
  683. void
  684. XFE_URLBar::url_text(XtPointer callData)
  685. {
  686.   URL_Struct *url_struct;
  687.   XmAnyCallbackStruct *cb = (XmAnyCallbackStruct *) callData;
  688.   Widget text_field;
  689.   char *text = 0;
  690.  
  691.   if (cb->reason != XmCR_ACTIVATE) abort ();
  692.  
  693.   XtVaGetValues (m_urlComboBox, XmNtextField, &text_field, 0);
  694.   text = fe_GetTextField(text_field); /* return via XtMalloc */
  695.  
  696.   if (*text)
  697.     {
  698.       char *old_text = 0;
  699.       char *new_text;
  700.       int32 id;
  701.  
  702.       if (m_parentFrame->getContext() != NULL)
  703.         {
  704.           id = XP_CONTEXTID(m_parentFrame->getContext());
  705.         }
  706.       else
  707.         {
  708.           id = 0;
  709.         }
  710.       if (HK_CallHook(HK_LOCATION, NULL, id, text, &new_text))
  711.         {
  712.           if (new_text != NULL)
  713.             {
  714.               old_text = text;
  715.               text = new_text;
  716.             }
  717.         }
  718.  
  719.       url_struct = NET_CreateURLStruct (text, NET_DONT_RELOAD);
  720.  
  721.       notifyInterested(XFE_URLBar::navigateToURL, (void*)url_struct);
  722.  
  723.       if (old_text)
  724.         {
  725.           XP_FREE(text);
  726.           text = old_text;
  727.         }
  728.     }      
  729.  
  730.   fe_NeutralizeFocus(m_parentFrame->getContext());
  731.  
  732.   if ( text ) XtFree(text);  
  733. }
  734.  
  735. void
  736. XFE_URLBar::url_text_modify()
  737. {
  738.   if (!m_labelBeingFrobbed)
  739.     frob_label (True, False);
  740. }
  741.  
  742. void
  743. XFE_URLBar::url_text_selection(XtPointer callData)
  744. {
  745.   XmString str;
  746.   char* text = 0;
  747.   URL_Struct *url_struct;
  748.   DtComboBoxCallbackStruct *cbData = (DtComboBoxCallbackStruct *)callData;
  749.   Widget list;
  750.   
  751.   if (cbData->reason == XmCR_SELECT )
  752.     {
  753.       str= cbData->item_or_text;
  754.       XmStringGetLtoR( str, XmSTRING_DEFAULT_CHARSET, &text);
  755.       XtVaGetValues(m_urlComboBox, XmNlist, &list, 0);
  756.       if ( *text )
  757.     {
  758.       url_struct = NET_CreateURLStruct (text, NET_DONT_RELOAD);
  759.       
  760.       notifyInterested(XFE_URLBar::navigateToURL, (void*)url_struct);
  761.     } 
  762.       
  763.       XtFree(text);
  764.     }
  765. }
  766.  
  767. void
  768. XFE_URLBar::url_text_cb(Widget, XtPointer closure, XtPointer callData)
  769. {
  770.   XFE_URLBar *obj = (XFE_URLBar*)closure;
  771.  
  772.   obj->url_text(callData);
  773. }
  774.  
  775. void
  776. XFE_URLBar::url_text_modify_cb (Widget, XtPointer closure, XtPointer)
  777. {
  778.   XFE_URLBar *obj = (XFE_URLBar*)closure;
  779.  
  780.   obj->url_text_modify();
  781. }
  782.  
  783. void
  784. XFE_URLBar::url_text_selection_cb(Widget, XtPointer closure, XtPointer callData)
  785. {
  786.   XFE_URLBar *obj = (XFE_URLBar*)closure;
  787.  
  788.   obj->url_text_selection(callData);
  789. }
  790.  
  791. //////////////////////////////////////////////////////////////////////////
  792. #ifdef URLBAR_POPUP
  793. void
  794. XFE_URLBar::doPopup(XEvent *event)
  795. {
  796.   int x, y, clickrow;
  797.   BM_Entry *entryUnderMouse;
  798.  
  799.   Widget widget = XtWindowToWidget(event->xany.display, event->xany.window);
  800.  
  801.   /* Posting the popup puts focus on the URLBar (needed for paste) */
  802.   XmProcessTraversal (widget, XmTRAVERSE_CURRENT);
  803.  
  804.   if (widget == NULL)
  805.     widget = m_widget;
  806.         
  807.   if (!m_popup)
  808.     {
  809.       m_popup = new XFE_PopupMenu("popup",(XFE_Frame*)m_toplevel, widget, NULL);
  810.       m_popup->addMenuSpec(ccp_popup_spec);
  811.     }
  812.   m_popup->position(event);
  813.   m_popup->show();
  814. }
  815. //////////////////////////////////////////////////////////////////////////
  816. /* static */ void
  817. XFE_URLBar::comboBoxButtonPressEH(Widget        /* w */,
  818.                                   XtPointer    clientData,
  819.                                   XEvent *    event,
  820.                                   Boolean *    cont)
  821. {
  822.   XFE_URLBar *obj = (XFE_URLBar*)clientData;
  823.  
  824.   // Make sure Button3 was pressed
  825.   if (event->type == ButtonPress && event->xbutton.button == Button3)
  826.     {
  827.       obj->doPopup(event);
  828.     }
  829.   *cont = True;
  830. }
  831. #endif /* URLBAR_POPUP */
  832.  
  833.  
  834. //////////////////////////////////////////////////////////////////////////
  835. /* static */ void
  836. XFE_URLBar::bookmarkCascadeTearCB(Widget    /* cascade */,
  837.                                   XtPointer    clientData,
  838.                                   XtPointer callData)
  839. {
  840.     XFE_URLBar *                    obj = (XFE_URLBar *) clientData;
  841.     XfeSubmenuTearCallbackStruct *    data = 
  842.         (XfeSubmenuTearCallbackStruct *) callData;
  843.  
  844.     obj->handleBookmarkCascadeTear(data->torn);
  845. }
  846. //////////////////////////////////////////////////////////////////////////
  847. /* static */ void
  848. XFE_URLBar::frameTitleChangedCB(Widget        frame_shell,
  849.                                 XtPointer    clientData,
  850.                                 XtPointer    callData)
  851. {
  852.     XFE_URLBar *    obj = (XFE_URLBar *) clientData;
  853.     String            title;
  854.  
  855.     XtVaGetValues(frame_shell,XmNtitle,&title,NULL);
  856.     
  857.     XtVaGetValues(frame_shell,XmNtitle,&title,NULL);
  858.  
  859.     obj->handleFrameTitleChanged(title);
  860.  
  861.     // Dont free the title, cause it returns a private pointer
  862. }
  863. //////////////////////////////////////////////////////////////////////////
  864. void
  865. XFE_URLBar::handleBookmarkCascadeTear(XP_Bool torn)
  866. {
  867.     if (m_bookmarkButton && m_bookmarkButton->isAlive())
  868.     {
  869.         // While the bookmarks submenu is posted, the button cant be used
  870.         m_bookmarkButton->setSensitive(!torn);
  871.  
  872.         // Make the torn shell's title the same as the frame
  873.         if (torn && m_parentFrame && m_parentFrame->isAlive())
  874.         {
  875.             XtVaSetValues(m_bookmarkButton->getBaseWidget(),
  876.                           XmNtornShellTitle,    m_parentFrame->getTitle(),
  877.                           NULL);
  878.         }
  879.     }
  880. }
  881. //////////////////////////////////////////////////////////////////////////
  882. void
  883. XFE_URLBar::handleFrameTitleChanged(String title)
  884. {
  885.  
  886.     if (m_bookmarkButton && m_bookmarkButton->isAlive())
  887.     {
  888.         Boolean torn;
  889.  
  890.         XtVaGetValues(m_bookmarkButton->getBaseWidget(),XmNtorn,&torn,NULL);
  891.  
  892.         if (torn)
  893.         {
  894.             XtVaSetValues(m_bookmarkButton->getBaseWidget(),
  895.                           XmNtornShellTitle,    title,
  896.                           NULL);
  897.         }
  898.     }
  899. }
  900. //////////////////////////////////////////////////////////////////////////
  901.