home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / HTMLView.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  74.9 KB  |  2,602 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.    HTMLView.cpp -- class definition for the HTML view class
  20.    Created: Spence Murray <spence@netscape.com>, 23-Oct-96.
  21.  */
  22.  
  23.  
  24.  
  25. #if DEBUG_slamm
  26. #define D(x) x
  27. #else
  28. #define D(x)
  29. #endif
  30.  
  31. #include "HTMLView.h"
  32. #include "BookmarkFrame.h"
  33. #include "MozillaApp.h"
  34. #ifdef EDITOR
  35. #include "EditorFrame.h"
  36. #endif
  37. #include "bkmks.h"
  38. #include "net.h"
  39. #include "layers.h"
  40. #include "ntypes.h"
  41. #include "libevent.h"
  42. #include "il_icons.h"
  43. #include "xpgetstr.h"
  44. #include "MozillaApp.h"
  45. #include "ViewGlue.h"
  46.  
  47. #include "fe_proto.h"
  48. #include "felocale.h"
  49. #include <libi18n.h>
  50. #include "intl_csi.h"
  51.  
  52. #include "prefs.h"
  53. #include "xfe2_extern.h"
  54. #include "prefapi.h"
  55. #include "selection.h"
  56.  
  57. #include <Xm/Label.h> 
  58. #include <Xfe/Xfe.h>
  59. #include "fonts.h"
  60.  
  61. #include <unistd.h>   // for getcwd()
  62.  
  63. extern int XFE_ERROR_SAVING_OPTIONS;
  64. extern int XFE_COMMANDS_OPEN_FILE_USAGE;
  65. #ifdef EDITOR
  66. extern int XFE_EDITOR_ALERT_ABOUT_DOCUMENT;
  67. extern int XFE_EDITOR_ALERT_FRAME_DOCUMENT;
  68. #endif
  69.  
  70. /* handle leave notify event
  71.  */
  72. #define HANDLE_LEAVE_WIN          1
  73.  
  74. // baggage from the old world.
  75. extern "C" {
  76.   void fe_upload_file_cb (Widget widget, XtPointer closure,
  77.                       XtPointer call_data);
  78.   void fe_SaveURL (MWContext *context, URL_Struct *url);
  79.   MWContext *fe_MakeWindow(Widget toplevel, MWContext *context_to_copy,
  80.                    URL_Struct *url, char *window_name, 
  81.                    MWContextType type, Boolean skip_get_url);
  82.   void fe_UserActivity (MWContext *context);
  83.   MWContext *fe_MotionWidgetToMWContext (Widget widget);
  84.   void fe_get_context_resources (MWContext *context);
  85.   void fe_load_default_font (MWContext *context);
  86.   void fe_find_scrollbar_sizes (MWContext *context);
  87.   void fe_get_final_context_resources (MWContext *context);
  88.   int fe_GetURL(MWContext *context, URL_Struct *url, Boolean skip_get_url);
  89.   CL_Compositor *fe_create_compositor(MWContext *context);
  90.   MWContext *fe_GetFocusGridOfContext (MWContext *context);
  91.   fe_back_cb (Widget widget, XtPointer closure, XtPointer call_data);
  92.   fe_forward_cb (Widget widget, XtPointer closure, XtPointer call_data);
  93.   fe_home_cb (Widget widget, XtPointer closure, XtPointer call_data);
  94.   fe_abort_cb (Widget widget, XtPointer closure, XtPointer call_data);
  95.   void fe_save_as_cb (Widget widget, XtPointer closure, XtPointer call_data);
  96.   void fe_save_top_frame_as_cb (Widget widget, XtPointer closure,
  97.                                 XtPointer call_data);
  98.   void fe_save_as_action (Widget widget, MWContext *context,
  99.                           String *av, Cardinal *ac);
  100.   void fe_open_file_action (Widget widget, MWContext *context,
  101.                             String *av, Cardinal *ac);
  102.   void fe_mailNew_cb (Widget widget, XtPointer closure, XtPointer call_data);
  103.   void fe_mailto_cb (Widget widget, XtPointer closure, XtPointer call_data);
  104.   void fe_print_cb (Widget widget, XtPointer closure, XtPointer call_data);
  105.   void fe_find_cb (Widget widget, XtPointer closure, XtPointer call_data);
  106.   void fe_find_again_cb (Widget widget, XtPointer closure, 
  107.                          XtPointer call_data);
  108. /*  void fe_reload_cb (Widget widget, XtPointer closure, XtPointer call_data);*/
  109.   void fe_load_images_cb (Widget widget, XtPointer closure, 
  110.                           XtPointer call_data);
  111.   void fe_refresh_cb (Widget widget, XtPointer closure, XtPointer call_data);
  112.   void fe_view_source_cb (Widget widget, XtPointer closure, 
  113.                           XtPointer call_data);
  114.   void fe_docinfo_cb (Widget widget, XtPointer closure, XtPointer call_data);
  115.   void fe_map_notify_eh (Widget w, XtPointer closure, XEvent *ev, Boolean *cont);
  116.   void fe_sec_logo_cb (Widget widget, XtPointer closure, XtPointer call_data);
  117. #ifdef EDITOR
  118.   fe_editor_edit_cb(Widget widget, XtPointer closure, XtPointer call_data);
  119. #endif
  120.   void fe_doc_enc_cb(Widget widget, XtPointer closure, XtPointer call_data);
  121.  
  122. #if HANDLE_LEAVE_WIN
  123.   /* Tooltips
  124.    */
  125.   void fe_Add_HTMLViewTooltips_eh(MWContext *context);
  126.   void fe_Remove_HTMLViewTooltips_eh(MWContext *context);
  127. #endif
  128. }
  129.  
  130. const char *XFE_HTMLView::newURLLoading = "XFE_HTMLView::newURLLoading";
  131. const char *XFE_HTMLView::spacebarAtPageBottom = "XFE_HTMLView::spacebarAtPageBottom";
  132. const char *XFE_HTMLView::popupNeedsShowing = "XFE_HTMLView::popupNeedsShowing";
  133.  
  134. MenuSpec XFE_HTMLView::separator_spec[] = {
  135.   MENU_SEPARATOR,
  136.   { NULL },
  137. };
  138. MenuSpec XFE_HTMLView::openLinkNew_spec[] = {
  139.   { xfeCmdOpenLinkNew , PUSHBUTTON },
  140.   { NULL },
  141. };
  142. MenuSpec XFE_HTMLView::openFrameNew_spec[] = {
  143.   { xfeCmdOpenFrameNew , PUSHBUTTON },
  144.   { xfeCmdOpenFrameInWindow , PUSHBUTTON },
  145.   { NULL },
  146. };
  147. MenuSpec XFE_HTMLView::openLinkEdit_spec[] = {
  148.   { xfeCmdOpenLinkEdit, PUSHBUTTON },
  149.   { NULL },
  150. };
  151. MenuSpec XFE_HTMLView::go_spec[] = {
  152.   { xfeCmdBack, PUSHBUTTON },
  153.   { xfeCmdForward, PUSHBUTTON },
  154.   { xfeCmdFrameReload     , PUSHBUTTON },
  155.   { NULL },
  156. };
  157. MenuSpec XFE_HTMLView::showImage_spec[] = {
  158.   { xfeCmdShowImage, PUSHBUTTON },
  159.   { NULL },
  160. };
  161. MenuSpec XFE_HTMLView::stopLoading_spec[] = {
  162.   { xfeCmdStopLoading, PUSHBUTTON },
  163.   { NULL },
  164. };
  165. MenuSpec XFE_HTMLView::page_details_spec[] = {
  166.   { xfeCmdViewFrameSource, PUSHBUTTON },
  167.   { xfeCmdViewFrameInfo, PUSHBUTTON },
  168.   { NULL },
  169. };
  170. MenuSpec XFE_HTMLView::openImage_spec[] = {
  171.   { xfeCmdOpenImage, PUSHBUTTON },
  172.   { NULL },
  173. };
  174. MenuSpec XFE_HTMLView::addLinkBookmark_spec[] = {
  175.   { xfeCmdAddLinkBookmark, PUSHBUTTON },
  176.   { NULL },
  177. };
  178. MenuSpec XFE_HTMLView::addFrameBookmark_spec[] = {
  179.   { xfeCmdAddFrameBookmark, PUSHBUTTON },
  180.   { NULL },
  181. };
  182. MenuSpec XFE_HTMLView::addBookmark_spec[] = {
  183.   { xfeCmdAddBookmark, PUSHBUTTON },
  184.   { NULL },
  185. };
  186. MenuSpec XFE_HTMLView::sendPage_spec[] = {
  187.   { xfeCmdSendPage, PUSHBUTTON },
  188.   { NULL },
  189. };
  190. MenuSpec XFE_HTMLView::saveLink_spec[] = {
  191.   { xfeCmdSaveLink, PUSHBUTTON },
  192.   { NULL },
  193. };
  194. MenuSpec XFE_HTMLView::saveImage_spec[] = {
  195.   { xfeCmdSaveImage, PUSHBUTTON },
  196.   { NULL },
  197. };
  198. MenuSpec XFE_HTMLView::saveBGImage_spec[] = {
  199.   { xfeCmdSaveBGImage, PUSHBUTTON },
  200.   { NULL },
  201. };
  202. MenuSpec XFE_HTMLView::copy_spec[] = {
  203.   { xfeCmdCopy, PUSHBUTTON },
  204.   { NULL },
  205. };
  206. MenuSpec XFE_HTMLView::copyLink_spec[] = {
  207.   { xfeCmdCopyLink, PUSHBUTTON },
  208.   { NULL },
  209. };
  210. MenuSpec XFE_HTMLView::copyImage_spec[] = {
  211.   { xfeCmdCopyImage, PUSHBUTTON },
  212.   { NULL },
  213. };
  214.  
  215. extern Boolean fe_IsPageLoaded (MWContext *context);
  216.  
  217. XFE_HTMLView::XFE_HTMLView(XFE_Component *toplevel_component,
  218.                Widget parent, XFE_View *parent_view,
  219.                MWContext *context) 
  220.   : XFE_View(toplevel_component, parent_view, context)
  221. {
  222.   makeScroller (parent);
  223.  
  224.   CONTEXT_DATA(m_contextData)->fancy_ftp_p = True;
  225.  
  226.   toplevel_component->registerInterest(XFE_Component::afterRealizeCallback,
  227.                        this,
  228.                        (XFE_FunctionNotification)beforeToplevelShow_cb);
  229.  
  230.   toplevel_component->registerInterest(XFE_Frame::encodingChanged,
  231.                        this,
  232.                        (XFE_FunctionNotification)DocEncoding_cb);
  233.  
  234.   XFE_MozillaApp::theApp()->registerInterest(XFE_MozillaApp::linksAttributeChanged,
  235.                                              this,
  236.                                              (XFE_FunctionNotification)ChangeLinksAttribute_cb);
  237.  
  238.   XFE_MozillaApp::theApp()->registerInterest(XFE_MozillaApp::defaultColorsChanged,
  239.                                              this,
  240.                                              (XFE_FunctionNotification)ChangeDefaultColors_cb);
  241.  
  242.   XFE_MozillaApp::theApp()->registerInterest(XFE_MozillaApp::defaultFontChanged,
  243.                                              this,
  244.                                              (XFE_FunctionNotification)ChangeDefaultFont_cb);
  245.  
  246.   m_popup = NULL;
  247.  
  248.   setBaseWidget(m_scrollerForm);
  249. }
  250.  
  251. XFE_HTMLView::~XFE_HTMLView()
  252. {
  253. #if HANDLE_LEAVE_WIN
  254.   /* Tooltips
  255.    */
  256.   fe_Remove_HTMLViewTooltips_eh(m_contextData);
  257. #endif /* HANDLE_LEAVE_WIN */
  258.  
  259.   if (m_popup) {
  260.     delete m_popup;
  261.     m_popup = NULL;
  262.   }
  263.  
  264.   XFE_MozillaApp::theApp()->unregisterInterest(XFE_MozillaApp::linksAttributeChanged,
  265.                                                this,
  266.                                                (XFE_FunctionNotification)ChangeLinksAttribute_cb);
  267.  
  268.   XFE_MozillaApp::theApp()->unregisterInterest(XFE_MozillaApp::defaultFontChanged,
  269.                                                this,
  270.                                                (XFE_FunctionNotification)ChangeDefaultFont_cb);
  271.  
  272.   XFE_MozillaApp::theApp()->unregisterInterest(XFE_MozillaApp::defaultColorsChanged,
  273.                                                this,
  274.                                                (XFE_FunctionNotification)ChangeDefaultColors_cb);
  275. }
  276.  
  277. void
  278. XFE_HTMLView::makeScroller(Widget parent)
  279. {
  280.   Widget pane;
  281. //  Widget line1;
  282. //  Widget line2;
  283.   Widget scroller;
  284.   Arg av[20];
  285.   int ac;
  286.  
  287.  
  288.   ac = 0;
  289.   m_scrollerForm = XmCreateForm (parent, "scrollerForm", av, ac);
  290.  
  291. //   ac = 0;
  292. //   XtSetArg (av[ac], XmNseparatorType, XmSHADOW_ETCHED_IN); ac++;
  293. //   XtSetArg (av[ac], XmNshadowThickness, 5); ac++;
  294. //   line1 = XmCreateSeparatorGadget (m_scrollerForm, "line1", av, ac);
  295.  
  296. //   XtVaSetValues (line1,
  297. //          XmNtopAttachment, XmATTACH_FORM,
  298. //          XmNbottomAttachment, XmATTACH_NONE,
  299. //          XmNleftAttachment, XmATTACH_FORM,
  300. //          XmNrightAttachment, XmATTACH_FORM,
  301. //          0);
  302.  
  303.  
  304. //   ac = 0;
  305. //   XtSetArg (av[ac], XmNseparatorType, XmSHADOW_ETCHED_IN); ac++;
  306. //   XtSetArg (av[ac], XmNshadowThickness, 5); ac++;
  307. //   line2 = XmCreateSeparatorGadget (m_scrollerForm, "line2", av, ac);
  308.  
  309. //   XtVaSetValues (line2,
  310. //          XmNtopAttachment, XmATTACH_NONE,
  311. //          XmNbottomAttachment, XmATTACH_FORM,
  312. //          XmNleftAttachment, XmATTACH_FORM,
  313. //          XmNrightAttachment, XmATTACH_FORM,
  314. //          0);
  315.  
  316.   ac = 0;
  317.   XtSetArg (av[ac], XmNborderWidth, 0); ac++;
  318.   XtSetArg (av[ac], XmNmarginWidth, 0); ac++;
  319.   XtSetArg (av[ac], XmNmarginHeight, 0); ac++;
  320.   XtSetArg (av[ac], XmNborderColor, 0); ac++;
  321.         // CONTEXT_DATA (m_contextData)->default_bg_pixel); ac++;
  322.   pane = XmCreatePanedWindow (m_scrollerForm, "pane", av, ac);
  323.   
  324.   XtVaSetValues(pane,
  325.                 XmNtopAttachment,        XmATTACH_FORM,
  326.                 XmNbottomAttachment,    XmATTACH_FORM,
  327.                 XmNleftAttachment,        XmATTACH_FORM,
  328.                 XmNrightAttachment,        XmATTACH_FORM,
  329.                 XmNtopOffset,            0,
  330.                 XmNbottomOffset,        0,
  331.                 XmNleftOffset,            0,
  332.                 XmNrightOffset,            0,
  333.  
  334. //          XmNtopAttachment, XmATTACH_WIDGET,
  335. //          XmNtopWidget, line1,
  336. //          XmNbottomAttachment, XmATTACH_WIDGET,
  337. //          XmNbottomWidget, line2,
  338. //          XmNleftAttachment, XmATTACH_FORM,
  339. //          XmNrightAttachment, XmATTACH_FORM,
  340.          0);
  341.  
  342.   /* The actual work area */
  343.   scroller = fe_MakeScrolledWindow (m_contextData, pane, "scroller");
  344.   XtVaSetValues (CONTEXT_DATA (m_contextData)->scrolled,
  345.                  XmNborderWidth, 0, 
  346. #if defined(__FreeBSD__)||defined(BSDI)||defined(LINUX)||defined(IRIX)
  347.                  // Allow for resolutions > 1000 pixels.
  348.                  // This causes the vertical scrollbar not to show
  349.                  // up on Solaris 2.4, bug in Motif (77998).  
  350.                  XmNpaneMaximum, 6000,
  351. #endif
  352.                  0);
  353.   
  354. //  XtManageChild (line1);
  355.   XtManageChild (scroller);
  356. //  XtManageChild (line2);
  357.   XtManageChild (pane);
  358.  
  359.   CONTEXT_DATA (m_contextData)->main_pane = m_scrollerForm;
  360.  
  361.   fe_load_default_font (m_contextData);
  362.   fe_get_context_resources (m_contextData);   /* Do other resource db hackery. */
  363.  
  364.   /* Figure out how much space the horizontal and vertical scrollbars take up.
  365.      It's basically impossible to determine this before creating them...
  366.    */
  367.   {
  368.     Dimension w1 = 0, w2 = 0, h1 = 0, h2 = 0;
  369.  
  370.     XtManageChild (CONTEXT_DATA (m_contextData)->hscroll);
  371.     XtManageChild (CONTEXT_DATA (m_contextData)->vscroll);
  372.     XtVaGetValues (CONTEXT_DATA (m_contextData)->drawing_area,
  373.                                  XmNwidth, &w1,
  374.                                  XmNheight, &h1,
  375.                                  0);
  376.  
  377.     XtUnmanageChild (CONTEXT_DATA (m_contextData)->hscroll);
  378.     XtUnmanageChild (CONTEXT_DATA (m_contextData)->vscroll);
  379.     XtVaGetValues (CONTEXT_DATA (m_contextData)->drawing_area,
  380.                                  XmNwidth, &w2,
  381.                                  XmNheight, &h2,
  382.                                  0);
  383.  
  384.     CONTEXT_DATA (m_contextData)->sb_w = w2 - w1;
  385.     CONTEXT_DATA (m_contextData)->sb_h = h2 - h1;
  386.  
  387.     /* Now that we know, we don't need to leave them managed. */
  388.   }
  389.  
  390.   XtVaSetValues (CONTEXT_DATA (m_contextData)->scrolled, XmNinitialFocus,
  391.                  CONTEXT_DATA (m_contextData)->drawing_area, 0);
  392.  
  393. #if HANDLE_LEAVE_WIN
  394.   /* add event handler
  395.    */
  396.   fe_Add_HTMLViewTooltips_eh(m_contextData);
  397. #endif
  398. }
  399.  
  400. XFE_CALLBACK_DEFN(XFE_HTMLView, beforeToplevelShow)(XFE_NotificationCenter *,
  401.                             void *, void*)
  402. {
  403.   m_contextData->compositor = fe_create_compositor(m_contextData);
  404.  
  405.   if (m_contextData->is_grid_cell)
  406.     fe_SetGridFocus (m_contextData);  /* Give this grid focus */
  407. }
  408.  
  409. int
  410. XFE_HTMLView::getURL(URL_Struct *url, Boolean skip_get_url)
  411. {
  412.   if (url)
  413.     {
  414.       XP_MEMSET (&url->savedData, 0, sizeof (SHIST_SavedData));
  415.       return fe_GetURL (m_contextData, url, skip_get_url);
  416.     }
  417.  
  418.   return 0; // ###ct ???  Is this what we want?
  419. }
  420.  
  421. void
  422. XFE_HTMLView::doCommand(CommandType cmd, void *callData, XFE_CommandInfo* info)
  423. {
  424. #define IS_CMD(command) (cmd == (command))
  425.   if (IS_CMD(xfeCmdBack))
  426.     {
  427.       fe_back_cb(NULL, m_contextData, NULL);
  428.  
  429.       getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  430.       return;
  431.     }
  432.   else if (IS_CMD(xfeCmdForward))
  433.     {
  434.       fe_forward_cb(NULL, m_contextData, NULL);
  435.  
  436.       getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  437.       return;
  438.     }
  439.   else if (IS_CMD(xfeCmdHome))
  440.     {
  441.       fe_home_cb(NULL, m_contextData, NULL);
  442.  
  443.       getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  444.       return;
  445.     }
  446.   else if (IS_CMD(xfeCmdDestinations))
  447.     {
  448.         fe_GuideCallback (CONTEXT_WIDGET (m_contextData), 
  449.                           (XtPointer) m_contextData, NULL);
  450.  
  451.         getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  452.       return;
  453.     }
  454.   else if (IS_CMD(xfeCmdFindInObject))
  455.     {
  456.       fe_find_cb(NULL, m_contextData, NULL);
  457.       return;
  458.     }
  459.   else if (IS_CMD(xfeCmdStopLoading))
  460.     {
  461.       //if (fe_IsContextStoppable(m_contextData)) {
  462.         fe_abort_cb(NULL, m_contextData, NULL);
  463.     /*} else {
  464.         XP_InterruptContext (m_contextData);
  465.  
  466.         CONTEXT_DATA(m_contextData)->looping_images_p = False;
  467.  
  468.       }
  469.       */
  470.       getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  471.       return;
  472.     }
  473.   else if (IS_CMD(xfeCmdStopAnimations))
  474.     {
  475.       XP_InterruptContext (m_contextData);
  476.       return;
  477.     }
  478.   else if (IS_CMD(xfeCmdOpenUrl))
  479.     {
  480.       URL_Struct *url = (URL_Struct*)callData;
  481.  
  482.       getURL(url, False);
  483.       
  484.       getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  485.       return;
  486.     }
  487.   else if (IS_CMD(xfeCmdOpenUrlFromSelection))
  488.     {
  489.         fe_PrimarySelectionFetchURL(m_contextData);
  490.  
  491.         return;
  492.     }
  493.   else if (IS_CMD(xfeCmdOpenPage))
  494.     {
  495.       fe_OpenURLDialog(m_contextData);
  496.  
  497.       getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  498.       return;
  499.     }
  500.   else if (IS_CMD(xfeCmdOpenPageChooseFile))
  501.     {
  502.       openFileAction(info->params, info->nparams);
  503.  
  504.       getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  505.       return;
  506.     }
  507.   else if (IS_CMD(xfeCmdSaveAs))
  508.     {
  509.       fe_save_as_action(CONTEXT_WIDGET(m_contextData), m_contextData,
  510.                         info->params, info->nparams);
  511.  
  512.       getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  513.       return;
  514.     }
  515.   else if (IS_CMD(xfeCmdSaveFrameAs))
  516.     {
  517.       fe_save_as_cb (CONTEXT_WIDGET (m_contextData), 
  518.               (XtPointer) m_contextData, NULL);
  519.  
  520.       getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  521.       return;
  522.     }
  523. #ifdef MOZ_MAIL_NEWS
  524.   else if (IS_CMD(xfeCmdSendPage))
  525.     {
  526.       fe_mailto_cb (CONTEXT_WIDGET (m_contextData), 
  527.               (XtPointer) m_contextData, NULL);
  528.  
  529.       getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  530.       return;
  531.     }
  532.   else if (IS_CMD(xfeCmdSendLink))
  533.     {
  534.       MSG_Pane *pane;
  535.       char *new_title = NULL;
  536.  
  537.       History_entry *h = SHIST_GetCurrent (&m_contextData->hist);
  538.  
  539.       if (!h) return;
  540.  
  541.       if (h->title && *h->title) 
  542.         new_title = h->title;
  543.       else 
  544.         new_title = h->address;
  545.  
  546.       MSG_CompositionFields *fields = 
  547.         MSG_CreateCompositionFields(NULL,      // from
  548.                                     NULL,      // reply_to
  549.                                     NULL,      // to
  550.                                     NULL,      // cc
  551.                                     NULL,      // bcc
  552.                                     NULL,      // fcc
  553.                                     NULL,      // newsgroups
  554.                                     NULL,      // followup_to
  555.                                     NULL,      // organization
  556.                                     new_title, // subject
  557.                                     NULL,      // references
  558.                                     NULL,      // other_random_headers
  559.                                     NULL,      // priority
  560.                                     NULL,      // attachment
  561.                                     NULL,      // newspost_url
  562.                                     FALSE,     // encrypt_p
  563.                                     FALSE);    // sign_p
  564.  
  565.       // Since they are only sending the link,
  566.       // I am guessing that they want a plaintext editor.
  567.       // Otherwise, why wouldn't they just send the page.  -slamm
  568.       pane = fe_showCompose(getBaseWidget(), NULL, m_contextData, fields, 
  569.                             h->address,   MSG_PLAINTEXT_EDITOR, False);
  570.  
  571.       getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  572.       return;
  573.     }
  574. #endif  // MOZ_MAIL_NEWS
  575.   else if (IS_CMD(xfeCmdCut))
  576.     {
  577.         MWContext *context = fe_GetFocusGridOfContext(m_contextData);
  578.         
  579.         if (!context) context = m_contextData;
  580.         
  581.         fe_cut_cb (CONTEXT_WIDGET (m_contextData), 
  582.                    (XtPointer) context, NULL);
  583.         
  584.         getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  585.         return;
  586.     }
  587.   else if (IS_CMD(xfeCmdCopy))
  588.     {
  589.         MWContext *context = fe_GetFocusGridOfContext(m_contextData);
  590.         
  591.         if (!context) context = m_contextData;
  592.  
  593.         fe_copy_cb (CONTEXT_WIDGET (m_contextData), 
  594.                     (XtPointer)context,
  595.                     NULL);
  596.         
  597.         getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  598.         return;
  599.     }
  600.   else if (IS_CMD(xfeCmdPaste))
  601.     {
  602.         MWContext *context = fe_GetFocusGridOfContext(m_contextData);
  603.         
  604.         if (!context) context = m_contextData;
  605.  
  606.         fe_paste_cb (CONTEXT_WIDGET (m_contextData), 
  607.                      (XtPointer) context, NULL);
  608.         
  609.         getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  610.         return;
  611.     }
  612.   else if (IS_CMD(xfeCmdFindInObject))
  613.     {
  614.       fe_find_cb (CONTEXT_WIDGET (m_contextData), 
  615.               (XtPointer) m_contextData, NULL);
  616.  
  617.       getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  618.       return;
  619.     }
  620.   else if (IS_CMD(xfeCmdFindAgain))
  621.     {
  622.       fe_find_again_cb (CONTEXT_WIDGET (m_contextData), 
  623.               (XtPointer) m_contextData, NULL);
  624.  
  625.       getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  626.       return;
  627.     }
  628.   else if (IS_CMD(xfeCmdEditPreferences))
  629.     {
  630.       fe_showPreferences(getToplevel(), getContext());
  631.       // fe_PrefsDialog (m_contextData);
  632.       
  633.  
  634.       getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  635.       return;
  636.     }
  637.   else if (IS_CMD(xfeCmdReload))
  638.     {
  639.       XP_ASSERT(info);
  640.       reload(info->widget, info->event);
  641.  
  642.       getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  643.       return;
  644.     }
  645.   else if (IS_CMD(xfeCmdFrameReload))
  646.     {
  647.       XP_ASSERT(info);
  648.  
  649.       // pass true to only reload frame
  650.       reload(info->widget, info->event, TRUE);
  651.  
  652.       getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  653.       return;
  654.     }
  655.   else if (IS_CMD(xfeCmdSearch)) 
  656.     {
  657.       fe_SearchCallback (CONTEXT_WIDGET (m_contextData), 
  658.               (XtPointer) m_contextData, NULL);
  659.  
  660.       getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  661.       return;
  662.     }
  663.   else if (IS_CMD(xfeCmdShowImages))
  664.     {
  665.       MWContext *context = fe_GetFocusGridOfContext(m_contextData);
  666.         
  667.       if (!context) context = m_contextData;
  668.  
  669.       fe_LoadDelayedImages (context);
  670.  
  671.       getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  672.       return;
  673.     }
  674.   else if (IS_CMD(xfeCmdShowImage))
  675.     {
  676.       if (m_imageUnderMouse) 
  677.         {
  678.           MWContext *context = fe_GetFocusGridOfContext(m_contextData);
  679.           
  680.           if (!context) context = m_contextData;
  681.  
  682.           fe_LoadDelayedImage (context, 
  683.                                m_imageUnderMouse->address);
  684.  
  685.           getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  686.       
  687.           m_imageUnderMouse = NULL;
  688.         }
  689.       return;
  690.     }
  691.   else if (IS_CMD(xfeCmdRefresh))
  692.     {
  693.       fe_refresh_cb (CONTEXT_WIDGET (m_contextData), 
  694.               (XtPointer) m_contextData, NULL);
  695.  
  696.       getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  697.       return;
  698.     }
  699.   else if (IS_CMD(xfeCmdViewPageSource))
  700.     {
  701.       fe_view_source_cb (CONTEXT_WIDGET (m_contextData), 
  702.               (XtPointer) m_contextData, NULL);
  703.  
  704.       getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  705.       return;
  706.     }
  707.   else if (IS_CMD(xfeCmdViewPageInfo))
  708.     {
  709.       fe_docinfo_cb (CONTEXT_WIDGET (m_contextData), 
  710.               (XtPointer) m_contextData, NULL);
  711.  
  712.       getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  713.       return;
  714.     }
  715.   else if (IS_CMD(xfeCmdViewFrameSource))
  716.     {
  717.       MWContext *context = fe_GetFocusGridOfContext(m_contextData);
  718.         
  719.       if (!context) context = m_contextData;
  720.  
  721.       fe_view_source_cb (CONTEXT_WIDGET (m_contextData), 
  722.                          (XtPointer) context, NULL);
  723.  
  724.       getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  725.       return;
  726.     }
  727.   else if (IS_CMD(xfeCmdViewFrameInfo))
  728.     {
  729.       MWContext *context = fe_GetFocusGridOfContext(m_contextData);
  730.       
  731.       if (!context) context = m_contextData;
  732.  
  733.       fe_docinfo_cb (CONTEXT_WIDGET (m_contextData), 
  734.                      (XtPointer) context, NULL);
  735.  
  736.       getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  737.       return;
  738.     }
  739.   else if (IS_CMD(xfeCmdViewSecurity))
  740.     {
  741.       fe_sec_logo_cb(NULL, m_contextData, NULL);
  742.       return;
  743.     }
  744.   else if (IS_CMD(xfeCmdAddBookmark))
  745.     {
  746.       History_entry *h = SHIST_GetCurrent (&m_contextData->hist);
  747.       BM_Entry *bm;
  748.       char *new_title;
  749.  
  750.       if (!h) return;
  751.       
  752.       if (!h->title || !*h->title) new_title = h->address;
  753.       else new_title = h->title;
  754.       bm = (BM_Entry*)BM_NewUrl( new_title, h->address, NULL, h->last_access);
  755.       
  756.       BM_AppendToHeader (XFE_BookmarkFrame::main_bm_context,
  757.              BM_GetAddHeader(XFE_BookmarkFrame::main_bm_context), bm);
  758.       return;
  759.     }
  760.   else if (IS_CMD(xfeCmdAddFrameBookmark))
  761.     {
  762.       fe_UserActivity (m_contextData);
  763.       
  764.       MWContext *context = fe_GetFocusGridOfContext(m_contextData);
  765.         
  766.       if (!context) context = m_contextData;
  767.  
  768.       History_entry *h = SHIST_GetCurrent (&context->hist);
  769.  
  770.       if (!h) return;
  771.       
  772.       BM_Entry *bm;
  773.       char *new_title;
  774.  
  775.       if (!h->title || !*h->title) new_title = h->address;
  776.       else new_title = h->title;
  777.  
  778.       bm = (BM_Entry*)BM_NewUrl( new_title, h->address, NULL, h->last_access);
  779.       
  780.       BM_AppendToHeader (XFE_BookmarkFrame::main_bm_context,
  781.              BM_GetAddHeader(XFE_BookmarkFrame::main_bm_context), bm);
  782.       return;
  783.     }
  784.   else if (IS_CMD(xfeCmdAddLinkBookmark))
  785.     {
  786.       if (!m_urlUnderMouse) return;
  787.       
  788.       BM_Entry *bm;
  789.       char *new_title;
  790.  
  791.       new_title = m_urlUnderMouse->address; /* Maybe we can do something
  792.                                                smart someday. -slamm */
  793.  
  794.       bm = (BM_Entry*)BM_NewUrl( new_title, m_urlUnderMouse->address,
  795.                                  NULL, 0);
  796.       
  797.       BM_AppendToHeader (XFE_BookmarkFrame::main_bm_context,
  798.              BM_GetAddHeader(XFE_BookmarkFrame::main_bm_context), bm);
  799.       return;
  800.     }
  801.   else if (IS_CMD(xfeCmdPrint))
  802.     {
  803.       fe_print_cb  (CONTEXT_WIDGET (m_contextData), 
  804.                     (XtPointer) m_contextData, NULL);
  805.  
  806.       getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  807.       return;
  808.     }
  809.   else if (IS_CMD(xfeCmdSpacebar))
  810.     {
  811.         MWContext *focus_context = fe_GetFocusGridOfContext(m_contextData);
  812.         if (!focus_context) focus_context = m_contextData;
  813.  
  814.         Widget sb = CONTEXT_DATA(focus_context)->vscroll;
  815.         XmScrollBarCallbackStruct cb;
  816.         int pi = 0, v = 0, max = 1, min = 0;
  817.         
  818.         XP_ASSERT(sb);
  819.         if (!sb) return;
  820.         
  821.         XtVaGetValues (sb, XmNpageIncrement, &pi, XmNvalue, &v,
  822.                        XmNmaximum, &max, XmNminimum, &min, 0);
  823.         cb.reason = XmCR_PAGE_INCREMENT;
  824.         cb.event = 0;
  825.         cb.pixel = 0;
  826.         cb.value = v + pi;
  827.         if (cb.value > max - pi) cb.value = max - pi;
  828.         if (cb.value < min) cb.value = min;
  829.         
  830.         if ((unsigned long)cb.value == CONTEXT_DATA (focus_context)->document_y)
  831.             {
  832.                 /* if we're staying at the same document_y, we must be at the bottom
  833.                    of the page. */
  834.                 notifyInterested(spacebarAtPageBottom);
  835.             }
  836.         else
  837.             {
  838.                 XtCallCallbacks (sb, XmNvalueChangedCallback, &cb);
  839.             }
  840.         return;
  841.     }
  842.   else if (IS_CMD (xfeCmdShowPopup))
  843.     {
  844.       D(printf("xfeCmdShowPopup - HTMLView\n");)
  845.       XEvent *event = (XEvent *) info->event;
  846.  
  847.       if (m_popup) {
  848.           delete m_popup;
  849.           m_popup = NULL;
  850.       }
  851.  
  852.       Widget w = XtWindowToWidget (event->xany.display, event->xany.window);
  853.       if (!w)
  854.     w = m_widget;
  855.  
  856.       findLayerForPopupMenu (w, event);
  857.       return;
  858.     }
  859.   else if (IS_CMD(xfeCmdOpenLinkNew))
  860.     {
  861.       fe_UserActivity (m_contextData);
  862.  
  863.       if (!m_urlUnderMouse)
  864.     return;
  865.  
  866.       if (
  867. #ifdef MOZ_MAIL_NEWS
  868.           MSG_RequiresComposeWindow(m_urlUnderMouse->address) ||
  869. #endif  // MOZ_MAIL_NEWS
  870.           ! XP_STRNCMP ("telnet:", m_urlUnderMouse->address, 7) ||
  871.           ! XP_STRNCMP ("tn3270:", m_urlUnderMouse->address, 7) ||
  872.           ! XP_STRNCMP ("rlogin:", m_urlUnderMouse->address, 7)
  873.          )
  874.     getURL (m_urlUnderMouse, FALSE);
  875.       else
  876.     fe_MakeWindow (XtParent (CONTEXT_WIDGET (m_contextData)),
  877.                m_contextData, m_urlUnderMouse, NULL, 
  878.                MWContextBrowser, FALSE);
  879.       m_urlUnderMouse = NULL; /* it will be freed in the exit routine. */
  880.       return;
  881.     }
  882.   else if (IS_CMD(xfeCmdOpenFrameNew))
  883.     {
  884.       fe_UserActivity (m_contextData);
  885.       
  886.       MWContext *context = fe_GetFocusGridOfContext(m_contextData);
  887.         
  888.       if (!context) context = m_contextData;
  889.  
  890.       History_entry *h = SHIST_GetCurrent (&context->hist);
  891.  
  892.       if (!h) return;
  893.       
  894.       URL_Struct *url_s = NET_CreateURLStruct (h->address,
  895.                                                NET_DONT_RELOAD);
  896.  
  897.       fe_MakeWindow (XtParent (CONTEXT_WIDGET (m_contextData)),
  898.                      m_contextData, url_s, NULL, 
  899.                      MWContextBrowser, FALSE);
  900.     }
  901.   else if (IS_CMD(xfeCmdOpenFrameInWindow))
  902.     {
  903.       fe_UserActivity (m_contextData);
  904.  
  905.       MWContext * grid_context = fe_GetFocusGridOfContext(m_contextData);
  906.  
  907.       History_entry * h = SHIST_GetCurrent (&grid_context->hist);
  908.  
  909.       if (!h) return;
  910.  
  911.       if (!grid_context) grid_context = m_contextData;
  912.       
  913.       MWContext * top_context = XP_GetNonGridContext(grid_context);
  914.  
  915.       URL_Struct * url = NET_CreateURLStruct(h->address,NET_DONT_RELOAD);
  916.  
  917.       fe_GetURL(top_context,url,False);
  918.     }
  919. #ifdef EDITOR
  920.   else if (IS_CMD(xfeCmdOpenLinkEdit))
  921.     {
  922.       fe_UserActivity (m_contextData);
  923.  
  924.       if (!m_urlUnderMouse)
  925.     return;
  926.  
  927.     /* If this is a grid doc, bail ... ...but we are editing the link, not this frame
  928.     if (m_contextData->is_grid_cell || fe_IsGridParent (m_contextData)) {
  929.         FE_Alert(m_contextData, 
  930.              XP_GetString(XFE_EDITOR_ALERT_FRAME_DOCUMENT));
  931.         return;
  932.     }
  933.     */
  934.  
  935.     if (strncmp(m_urlUnderMouse->address, "about:", 6) == 0) {
  936.         FE_Alert(m_contextData, 
  937.              XP_GetString(XFE_EDITOR_ALERT_ABOUT_DOCUMENT));
  938.         return;
  939.     }
  940. #ifdef MOZ_MAIL_NEWS
  941.       if (MSG_RequiresComposeWindow(m_urlUnderMouse->address))
  942.     getURL (m_urlUnderMouse, FALSE);
  943.       else
  944. #endif
  945.         fe_EditorNew(m_contextData, (XFE_Frame *)m_toplevel,
  946.                      NULL, m_urlUnderMouse->address);
  947.  
  948.       m_urlUnderMouse = NULL; /* it will be freed in the exit routine. */
  949.       return;
  950.     }
  951. #endif  // EDITOR
  952.   else if (IS_CMD(xfeCmdSaveLink))
  953.     {
  954.       fe_UserActivity (m_contextData);
  955.  
  956.       if (!m_urlUnderMouse)
  957.     FE_Alert (m_contextData, fe_globalData.not_over_link_message);
  958.       else
  959.     fe_SaveURL (m_contextData, m_urlUnderMouse);
  960.  
  961.       m_urlUnderMouse = NULL; /* it will be freed in the exit routine. */
  962.       return;
  963.     }
  964.   else if (IS_CMD(xfeCmdCopyLink))
  965.     {
  966.       if (!m_urlUnderMouse)
  967.         FE_Alert (m_contextData, fe_globalData.not_over_link_message);
  968.       else {
  969.           if (m_imageUnderMouse) {
  970.               fe_clipboard_image_link_cb (CONTEXT_WIDGET (m_contextData),
  971.                                           (XtPointer) m_contextData, NULL,
  972.                                           m_urlUnderMouse, m_imageUnderMouse);
  973.               m_imageUnderMouse = NULL;
  974.           }
  975.           else {
  976.               fe_clipboard_link_cb (CONTEXT_WIDGET (m_contextData),
  977.                                     (XtPointer) m_contextData, NULL,
  978.                                     m_urlUnderMouse);
  979.           }
  980.       }
  981.       m_urlUnderMouse = NULL;
  982.       return;
  983.     }
  984.   else if (IS_CMD(xfeCmdCopyImage))
  985.     {
  986.       if (!m_imageUnderMouse)
  987.         FE_Alert (m_contextData, fe_globalData.not_over_image_message);
  988.       else
  989.         fe_clipboard_image_cb (CONTEXT_WIDGET (m_contextData),
  990.                                (XtPointer) m_contextData, NULL,
  991.                                m_imageUnderMouse);
  992.       m_imageUnderMouse = NULL;
  993.       return;
  994.     }
  995.   else if (IS_CMD(xfeCmdSaveImage))
  996.     {
  997.       fe_UserActivity (m_contextData);
  998.  
  999.       if (!m_imageUnderMouse)
  1000.     FE_Alert (m_contextData, fe_globalData.not_over_image_message);
  1001.       else
  1002.     fe_SaveURL (m_contextData, m_imageUnderMouse);
  1003.  
  1004.       m_imageUnderMouse = NULL; /* it will be freed in the exit routine. */
  1005.       return;
  1006.     }
  1007.   else if (IS_CMD(xfeCmdSaveBGImage))
  1008.     {
  1009.       fe_UserActivity (m_contextData);
  1010.  
  1011.       if (!m_backgroundUnderMouse)
  1012.         FE_Alert (m_contextData, fe_globalData.not_over_image_message);
  1013.       else
  1014.         fe_SaveURL (m_contextData, m_backgroundUnderMouse);
  1015.  
  1016.       m_backgroundUnderMouse = NULL; /* it will be freed in the exit routine. */
  1017.       return;
  1018.     }
  1019.   else if (IS_CMD(xfeCmdOpenImage))
  1020.     {
  1021.       if (!m_imageUnderMouse)
  1022.         FE_Alert (m_contextData, fe_globalData.not_over_image_message);
  1023.       else
  1024.         getURL(m_imageUnderMouse, False);
  1025.  
  1026.       m_imageUnderMouse = NULL; /* it will be freed in the exit routine. */
  1027.     }
  1028.   else if (IS_CMD(xfeCmdSelectAll))
  1029.     {
  1030.       Widget focus = XmGetFocusWidget (CONTEXT_WIDGET (m_contextData));
  1031.  
  1032.       if (focus && XmIsTextField (focus) || XmIsTextField(focus)) {
  1033.         char *text = fe_GetTextField(focus);
  1034.  
  1035.         if (text == NULL) return;
  1036.  
  1037.         XmTextFieldSetSelection(focus, 0, XP_STRLEN(text), 0);
  1038.  
  1039.         XtFree(text);
  1040.  
  1041.       } else {
  1042.  
  1043.         MWContext *context = fe_GetFocusGridOfContext(m_contextData);
  1044.         XEvent *event = (XEvent *) info->event;
  1045.         Time time = XtLastTimestampProcessed(event->xany.display);
  1046.         
  1047.         if (!context) context = m_contextData;
  1048.         
  1049.         LO_SelectAll (context);
  1050.  
  1051.         fe_OwnSelection(context, time, False);
  1052.       }
  1053.       return;
  1054.     }
  1055.   else if (IS_CMD(xfeCmdUploadFile))
  1056.     {
  1057.       fe_upload_file_cb (CONTEXT_WIDGET (m_contextData), 
  1058.              (XtPointer) m_contextData, NULL);
  1059.       return;
  1060.     }
  1061.   else if (IS_CMD(xfeCmdPageServices))
  1062.     {
  1063.       if (SHIST_CurrentHandlesPageServices(m_contextData))
  1064.         {
  1065.           char *url = SHIST_GetCurrentPageServicesURL(m_contextData);
  1066.  
  1067.           if (url)
  1068.             {
  1069.               URL_Struct *url_s = NET_CreateURLStruct (url, NET_DONT_RELOAD);
  1070.               getURL(url_s, False);
  1071.             }
  1072.         }
  1073.       return;
  1074.     }
  1075.   else if (IS_CMD(xfeCmdChangeDocumentEncoding))
  1076.     {
  1077.       int/*16*/ new_doc_csid = (int/*16*/)callData;
  1078.       INTL_CharSetInfo c = LO_GetDocumentCharacterSetInfo(m_contextData);
  1079.       
  1080.       if (new_doc_csid != m_contextData->fe.data->xfe_doc_csid) 
  1081.         {
  1082.           m_contextData->fe.data->xfe_doc_csid = new_doc_csid;
  1083.           INTL_SetCSIWinCSID(c, INTL_DocToWinCharSetID(new_doc_csid));
  1084.           // now let our observers know that the encoding
  1085.           // for this window needs to be changed.
  1086.           getToplevel()->notifyInterested(XFE_Frame::encodingChanged, callData);
  1087.         }
  1088.     }
  1089.   else if (IS_CMD(xfeCmdSetDefaultDocumentEncoding))
  1090.     {
  1091.       fe_globalPrefs.doc_csid = m_contextData->fe.data->xfe_doc_csid;
  1092.       /* clumsy to save all prefs but ... */
  1093.       if (!XFE_SavePrefs((char *)fe_globalData.user_prefs_file,&fe_globalPrefs))
  1094.         {
  1095.           fe_perror(m_contextData,XP_GetString(XFE_ERROR_SAVING_OPTIONS));
  1096.         }
  1097.     }
  1098.   else
  1099.     {
  1100.       XFE_View::doCommand(cmd);
  1101.     }
  1102. #undef IS_CMD
  1103. }
  1104.  
  1105. XP_Bool
  1106. XFE_HTMLView::isCommandSelected(CommandType cmd,
  1107.                              void *calldata, XFE_CommandInfo* info)
  1108. {
  1109. #define IS_CMD(command) (cmd == (command))
  1110.     XFE_Command* handler = getCommand(cmd);
  1111.  
  1112.     if (handler != NULL)
  1113.         return handler->isSelected(this, info);
  1114.  
  1115.     /* This method is designed for toggle button */
  1116.     /* We want to keep the toggle button to have the same state
  1117.      as its matched view */
  1118.   if (IS_CMD(xfeCmdChangeDocumentEncoding))
  1119.     {
  1120.       int/*16*/ test_doc_csid = (int/*16*/)calldata;
  1121.       if (test_doc_csid == m_contextData->fe.data->xfe_doc_csid) 
  1122.         return True;
  1123.       else
  1124.         return False;
  1125.     }
  1126.   return (XFE_View::isCommandSelected(cmd, calldata, info));
  1127. #undef IS_CMD
  1128. }
  1129.  
  1130. Boolean
  1131. XFE_HTMLView::isCommandEnabled(CommandType cmd, void *calldata, XFE_CommandInfo*)
  1132. {
  1133. #define IS_CMD(command) (cmd == (command))
  1134.   //  Boolean framesArePresent = hasSubViews();
  1135.  
  1136.   if (IS_CMD(xfeCmdBack))
  1137.     {
  1138.       return SHIST_CanGoBack (m_contextData);
  1139.     }
  1140.   else if (IS_CMD(xfeCmdForward))
  1141.     {
  1142.       return SHIST_CanGoForward (m_contextData);
  1143.     }
  1144.   else if (IS_CMD(xfeCmdAddBookmark))
  1145.     {
  1146.       return (SHIST_GetCurrent(&m_contextData->hist) != NULL);
  1147.     }
  1148.   else if (IS_CMD(xfeCmdHome))
  1149.     {
  1150.       return (fe_globalPrefs.home_document && *fe_globalPrefs.home_document);
  1151.     }
  1152.   else if (IS_CMD(xfeCmdDestinations))
  1153.     {
  1154.       return True;
  1155.     }
  1156.   else if (IS_CMD(xfeCmdStopLoading))
  1157.     {
  1158.       return fe_IsContextStoppable(m_contextData)
  1159.         || CONTEXT_DATA (m_contextData)->active_url_count > 0;
  1160.     }
  1161.   else if (IS_CMD(xfeCmdStopAnimations))
  1162.     {
  1163.       return fe_IsContextLooping(m_contextData);
  1164.     }
  1165.   else if (IS_CMD(xfeCmdFindInObject))
  1166.     {
  1167.       return True; // should this always be enabled?
  1168.     }
  1169.   else if (IS_CMD(xfeCmdOpenPage)
  1170.            || IS_CMD(xfeCmdOpenPageChooseFile))
  1171.     {
  1172.       return True; // should this always be enabled?
  1173.     }
  1174.   else if (IS_CMD(xfeCmdSaveAs))
  1175.     {
  1176.       // Always save the topmost frame
  1177.       return True; //hasSubViews() == False;
  1178.     }
  1179.   else if (IS_CMD(xfeCmdSaveFrameAs))
  1180.     {
  1181.       // Save the frame with focus
  1182.       return hasSubViews() == True;
  1183.     }
  1184.   else if (IS_CMD(xfeCmdSendPage)
  1185.            || IS_CMD(xfeCmdSendLink))
  1186.     {
  1187.       return True; // should this always be enabled?
  1188.     }
  1189.   else if (IS_CMD(xfeCmdCut))
  1190.     {
  1191.       return fe_can_cut(m_contextData);
  1192.     }
  1193.   else if (IS_CMD(xfeCmdCopy))
  1194.     {
  1195.       return fe_can_copy(m_contextData);
  1196.     }
  1197.   else if (IS_CMD(xfeCmdPaste))
  1198.     {
  1199.       return fe_can_paste(m_contextData);
  1200.     }
  1201.   else if (IS_CMD(xfeCmdFindInObject))
  1202.     {
  1203.       return True; // should this always be enabled?
  1204.     }
  1205.   else if (IS_CMD(xfeCmdFindAgain))
  1206.     {
  1207.       fe_FindData *find_data = CONTEXT_DATA(m_contextData)->find_data;
  1208.       if (find_data && find_data->string && find_data->string[0] != '\0')
  1209.         return True;
  1210.       else
  1211.         return False;
  1212.     }
  1213.   else if (IS_CMD(xfeCmdEditPreferences))
  1214.     {
  1215.       return True; // should this always be enabled?
  1216.     }
  1217.   else if (IS_CMD(xfeCmdReload)
  1218.            || IS_CMD(xfeCmdFrameReload))
  1219.     {
  1220.       //return !fe_IsContextStoppable(m_contextData);
  1221.       return True;
  1222.     }
  1223.   else if (IS_CMD(xfeCmdSearch)) 
  1224.     {
  1225.       return True;
  1226.     }
  1227.   else if (IS_CMD(xfeCmdShowImages) 
  1228.            || IS_CMD(xfeCmdShowImage))
  1229.     {
  1230.       // Enable if autoload images is off or if there are delayed images.
  1231.       return (!fe_globalPrefs.autoload_images_p ||
  1232.               CONTEXT_DATA (m_contextData)->delayed_images_p);
  1233.     }
  1234.   else if (IS_CMD(xfeCmdRefresh))
  1235.     {
  1236.       return True; // should this always be enabled?
  1237.     }
  1238.   else if (IS_CMD(xfeCmdViewPageSource))
  1239.     {
  1240.       return fe_IsPageLoaded(m_contextData);
  1241.     }
  1242.   else if (IS_CMD(xfeCmdViewPageInfo))
  1243.     {
  1244.       return fe_IsPageLoaded(m_contextData);
  1245.     }
  1246.   else if (IS_CMD(xfeCmdViewFrameSource)
  1247.            ||IS_CMD(xfeCmdViewFrameInfo))
  1248.     {
  1249.       return True;
  1250.     }
  1251.   else if (IS_CMD(xfeCmdViewSecurity))
  1252.     {
  1253.       return True; // should this always be enabled?
  1254.     }
  1255.   else if (IS_CMD(xfeCmdOpenUrl))
  1256.     {
  1257.       return True; // should this always be enabled?
  1258.     }
  1259.   else if (IS_CMD(xfeCmdOpenUrlFromSelection))
  1260.     {
  1261.       return True; // should this always be enabled?
  1262.     }
  1263.   else if (IS_CMD(xfeCmdPrint))
  1264.     {
  1265.       return True; // should this always be enabled?
  1266.     }
  1267.   else if (IS_CMD(xfeCmdSpacebar))
  1268.     {
  1269.       return True; // should this always be enabled?
  1270.     }
  1271.   else if (IS_CMD(xfeCmdOpenLinkNew)
  1272.            || IS_CMD(xfeCmdOpenFrameNew)
  1273.            || IS_CMD(xfeCmdOpenFrameInWindow))
  1274.     {
  1275.       return True;
  1276.     }
  1277.   else if (IS_CMD(xfeCmdOpenLinkEdit))
  1278.     {
  1279.       return True;
  1280.     }
  1281.   else if (IS_CMD(xfeCmdSaveLink))
  1282.     {
  1283.       return True;
  1284.     }
  1285.   else if (IS_CMD(xfeCmdCopyLink)
  1286.            || IS_CMD(xfeCmdCopyImage))
  1287.     {
  1288.       return True;
  1289.     }
  1290.   else if (IS_CMD(xfeCmdSaveImage)
  1291.            || IS_CMD(xfeCmdSaveBGImage))
  1292.     {
  1293.       return True;
  1294.     } 
  1295.   else if (IS_CMD(xfeCmdSelectAll))
  1296.     {
  1297.       return True;
  1298.     }
  1299.   else if (IS_CMD(xfeCmdUploadFile))
  1300.     {
  1301.       History_entry *he = SHIST_GetCurrent (&m_contextData->hist);
  1302.       Boolean b = False;
  1303.  
  1304.       if (he && he->address && (XP_STRNCMP (he->address, "ftp://", 6) == 0)
  1305.       && (he->address[XP_STRLEN(he->address)-1] == '/'))
  1306.     {
  1307.       b = True;
  1308.     }
  1309.       return b;
  1310.     }
  1311.   else if (cmd == xfeCmdChangeDocumentEncoding)
  1312.     {
  1313.       /* bstell: need to check if there are fonts */
  1314.       int/*16*/ doc_csid = (int/*16*/)calldata;
  1315.       return fe_IsCharSetSupported((int16)doc_csid);
  1316.     }
  1317.   else if (IS_CMD(xfeCmdSetDefaultDocumentEncoding))
  1318.     {
  1319.       return True;
  1320.     }
  1321.   else if (IS_CMD(xfeCmdShowPopup)
  1322.            || IS_CMD(xfeCmdOpenImage)
  1323.            || IS_CMD(xfeCmdAddLinkBookmark)
  1324.            || IS_CMD(xfeCmdAddFrameBookmark))
  1325.     {
  1326.       return True;
  1327.     }
  1328.   else if (IS_CMD(xfeCmdPageServices))
  1329.     {
  1330.       return SHIST_CurrentHandlesPageServices(m_contextData);
  1331.     }
  1332.   else
  1333.     {
  1334.       return XFE_View::isCommandEnabled(cmd, calldata);
  1335.     }
  1336. #undef IS_CMD
  1337. }
  1338.  
  1339. Boolean
  1340. XFE_HTMLView::handlesCommand(CommandType cmd, void *calldata, XFE_CommandInfo*)
  1341. {
  1342. #define IS_CMD(command) (cmd == (command))
  1343.   if (IS_CMD(xfeCmdBack)
  1344.       || IS_CMD(xfeCmdForward)
  1345.       || IS_CMD(xfeCmdHome)
  1346.       || IS_CMD(xfeCmdDestinations)
  1347.       || IS_CMD(xfeCmdFindInObject)
  1348.       || IS_CMD(xfeCmdStopLoading)
  1349.       || IS_CMD(xfeCmdStopAnimations)
  1350.       || IS_CMD(xfeCmdOpenPage)
  1351.       || IS_CMD(xfeCmdOpenPageChooseFile)
  1352.       || IS_CMD(xfeCmdExit)
  1353.       || IS_CMD(xfeCmdSaveAs)
  1354.       || IS_CMD(xfeCmdSaveFrameAs)
  1355.       || IS_CMD(xfeCmdSendPage)
  1356.       || IS_CMD(xfeCmdSendLink)
  1357.       || IS_CMD(xfeCmdCut)
  1358.       || IS_CMD(xfeCmdCopy)
  1359.       || IS_CMD(xfeCmdPaste)
  1360.       || IS_CMD(xfeCmdFindInObject)
  1361.       || IS_CMD(xfeCmdFindAgain)
  1362.       || IS_CMD(xfeCmdEditPreferences)
  1363.       || IS_CMD(xfeCmdReload)
  1364.       || IS_CMD(xfeCmdFrameReload)
  1365.       || IS_CMD(xfeCmdShowImages)
  1366.       || IS_CMD(xfeCmdRefresh)
  1367.       || IS_CMD(xfeCmdViewPageSource)
  1368.       || IS_CMD(xfeCmdViewPageInfo)
  1369.       || IS_CMD(xfeCmdViewSecurity)
  1370.       || IS_CMD(xfeCmdAddBookmark)
  1371.       || IS_CMD(xfeCmdOpenUrl)
  1372.       || IS_CMD(xfeCmdOpenUrlFromSelection)
  1373.       || IS_CMD(xfeCmdPrint)
  1374.       || IS_CMD(xfeCmdSelectAll)
  1375.       || IS_CMD(xfeCmdUploadFile)
  1376.  
  1377.       || IS_CMD(xfeCmdChangeDocumentEncoding)
  1378.       || IS_CMD(xfeCmdSetDefaultDocumentEncoding)
  1379.  
  1380.       /* moving around the page */
  1381.       || IS_CMD(xfeCmdSpacebar)
  1382.       || IS_CMD(xfeCmdSearch)
  1383.       || IS_CMD(xfeCmdShowPopup)
  1384.  
  1385.       // context menu items
  1386.       || IS_CMD(xfeCmdOpenLinkNew)
  1387.       || IS_CMD(xfeCmdOpenFrameNew)
  1388.       || IS_CMD(xfeCmdOpenFrameInWindow)
  1389.       || IS_CMD(xfeCmdOpenLinkEdit)
  1390.       || IS_CMD(xfeCmdSaveLink)
  1391.       || IS_CMD(xfeCmdCopyLink)
  1392.       || IS_CMD(xfeCmdCopyImage)
  1393.       || IS_CMD(xfeCmdSaveImage)
  1394.       || IS_CMD(xfeCmdSaveBGImage)
  1395.       || IS_CMD(xfeCmdViewFrameSource)
  1396.       || IS_CMD(xfeCmdViewFrameInfo)
  1397.       || IS_CMD(xfeCmdOpenImage)
  1398.       || IS_CMD(xfeCmdAddLinkBookmark)
  1399.       || IS_CMD(xfeCmdAddFrameBookmark)
  1400.       || IS_CMD(xfeCmdShowImage)
  1401.       || IS_CMD(xfeCmdPageServices)
  1402.       )
  1403.     {
  1404.       return True;
  1405.     }
  1406.   else
  1407.     {
  1408.       return XFE_View::handlesCommand(cmd, calldata);
  1409.     }
  1410. #undef IS_CMD
  1411. }
  1412.  
  1413. char *
  1414. XFE_HTMLView::commandToString(CommandType cmd, void *calldata, XFE_CommandInfo*)
  1415. {
  1416. #define IS_CMD(command) (cmd == (command))
  1417.  
  1418.   Boolean framesArePresent = hasSubViews();
  1419.  
  1420.   if (IS_CMD(xfeCmdSaveAs)) {
  1421.     if (framesArePresent) 
  1422.       return stringFromResource("saveFramesetAsCmdString");
  1423.     else
  1424.       return stringFromResource("saveAsCmdString");
  1425.   } else if (IS_CMD(xfeCmdEditPage)) {
  1426.       char* name = cmd;
  1427.  
  1428.       if (framesArePresent) 
  1429.           name = "editFrameSet";
  1430.  
  1431.       return getLabelString(name);
  1432.   } else if (IS_CMD(xfeCmdPrint)) {
  1433.     if (framesArePresent) 
  1434.       return stringFromResource("printFrameCmdString");
  1435.     else
  1436.       return stringFromResource("printCmdString");
  1437. /* Don't use "Select All in Frame" because a textfield may have focus
  1438.   } else if (IS_CMD(xfeCmdSelectAll)) {
  1439.     if (framesArePresent) 
  1440.       return stringFromResource("selectAllInFrameCmdString");
  1441.     else
  1442.       return stringFromResource("selectAllCmdString");
  1443. */
  1444.   } else if (IS_CMD(xfeCmdFindInObject)) {
  1445.     if (framesArePresent) 
  1446.       return stringFromResource("findInFrameCmdString");
  1447.     else
  1448.       return stringFromResource("findInObjectCmdString");
  1449.   } else if (IS_CMD(xfeCmdStopLoading)) {
  1450.     if (fe_IsContextLooping(m_contextData))
  1451.       return stringFromResource("stopAnimationsCmdString");
  1452.     else
  1453.       return stringFromResource("stopLoadingCmdString");
  1454.   } else if (IS_CMD(xfeCmdFrameReload)) {
  1455.     if (framesArePresent)
  1456.       return stringFromResource("reloadWithFrameCmdString");
  1457.     else
  1458.       return stringFromResource("reloadNonFrameCmdString");
  1459.   } else if (IS_CMD(xfeCmdViewFrameSource)) {
  1460.     if (framesArePresent)
  1461.       return stringFromResource("pageSourceWithFrameCmdString");
  1462.     else
  1463.       return stringFromResource("pageSourceNonFrameCmdString");
  1464.   } else if (IS_CMD(xfeCmdViewFrameInfo)) {
  1465.     if (framesArePresent)
  1466.       return stringFromResource("pageInfoWithFrameCmdString");
  1467.     else
  1468.       return stringFromResource("pageInfoNonFrameCmdString");
  1469.   } else if (IS_CMD(xfeCmdOpenImage)) {
  1470.     if (m_imageUnderMouse && m_imageUnderMouse->address) {
  1471.  
  1472. #define BUFMAX 100
  1473. #define FILEBUFMAX 25
  1474.       static char buf[BUFMAX];
  1475.       static char filebuf[FILEBUFMAX];
  1476.       char *filename = XP_STRRCHR(m_imageUnderMouse->address, '/');
  1477.  
  1478.       if (filename) {
  1479.         filename++;
  1480.  
  1481.         if (*filename) {
  1482.           char *cmdLabel = stringFromResource("openImageCmdString");
  1483.           int cmdLength = XP_STRLEN(cmdLabel);
  1484.           int lengthLeft = BUFMAX - cmdLength - 3; //count " ()"
  1485.           int maxFileLength = FILEBUFMAX;
  1486.  
  1487.           if (lengthLeft <= 0) return cmdLabel;
  1488.  
  1489.           if (maxFileLength > lengthLeft)
  1490.             maxFileLength = lengthLeft;
  1491.  
  1492.           INTL_CharSetInfo c = LO_GetDocumentCharacterSetInfo(m_contextData);
  1493.           INTL_MidTruncateString(INTL_GetCSIWinCSID(c), filename, filebuf, maxFileLength);
  1494.           
  1495.           PR_snprintf(buf, sizeof(buf), "%s (%s)", 
  1496.                       stringFromResource("openImageCmdString"),
  1497.                       filebuf);
  1498.  
  1499.           return buf;
  1500.         }
  1501.       }
  1502.     }
  1503.     return stringFromResource("openImageCmdString");
  1504.   }
  1505.   else if (IS_CMD(xfeCmdChangeDocumentEncoding))
  1506.     {
  1507.       char *res = NULL;
  1508.       int doc_csid = (int)calldata;
  1509.  
  1510.       switch (doc_csid)
  1511.         {
  1512.           case CS_LATIN1:
  1513.             res = "latin1EncCmdString";
  1514.             break;
  1515.           case CS_LATIN2:
  1516.             res = "latin2EncCmdString";
  1517.             break;
  1518.           case CS_CP_1250:
  1519.             res = "Win1250EncCmdString";
  1520.             break;
  1521.           case CS_EUCJP_AUTO:
  1522.             res = "jaAutoEncCmdString";
  1523.             break;
  1524.           case CS_SJIS:
  1525.             res = "jaSJISEncCmdString";
  1526.             break;
  1527.           case CS_EUCJP:
  1528.             res = "jaEUCEncCmdString";
  1529.             break;
  1530.           case CS_BIG5:
  1531.             res = "twBig5EncCmdString";
  1532.             break;
  1533.           case CS_CNS_8BIT:
  1534.             res = "twEUCEncCmdString";
  1535.             break;
  1536.           case CS_GB_8BIT:
  1537.             res = "gbEUCEncCmdString";
  1538.             break;
  1539.           case CS_KSC_8BIT_AUTO:
  1540.             res = "krEUCEncCmdString";
  1541.             break;
  1542.           case CS_2022_KR:
  1543.             res = "2022krEncCmdString";
  1544.             break;
  1545.           case CS_KOI8_R:
  1546.             res = "koi8rEncCmdString";
  1547.             break;
  1548.           case CS_CP_1251:
  1549.             res = "Win1251EncCmdString";
  1550.             break;
  1551.           case CS_8859_5:
  1552.             res = "88595EncCmdString";
  1553.             break;
  1554.           case CS_8859_7:
  1555.             res = "greekEncCmdString";
  1556.             break;
  1557.           case CS_CP_1253:
  1558.             res = "Win1253EncCmdString";
  1559.             break;
  1560.           case CS_8859_9:
  1561.             res = "88599EncCmdString";
  1562.             break;
  1563.           case CS_UTF8:
  1564.             res = "unicode_utf8EncCmdString";
  1565.             break;
  1566.           case CS_UTF7:
  1567.             res = "unicode_utf7EncCmdString";
  1568.             break;
  1569.           case CS_USRDEF2:
  1570.             res = "otherEncCmdString";
  1571.             break;
  1572.           default:
  1573.             XP_ASSERT(0);
  1574.             break;
  1575.         }
  1576.       
  1577.       if (res)
  1578.         return stringFromResource(res);
  1579.       else
  1580.         return NULL;
  1581.     }
  1582.   else if (IS_CMD(xfeCmdSetDefaultDocumentEncoding))
  1583.     {
  1584.       char *res;
  1585.       res = "setDefaultDocCSID";
  1586.       return stringFromResource(res);
  1587.     }
  1588.   return NULL;
  1589. #undef IS_CMD
  1590. }
  1591.  
  1592. void XFE_HTMLView::setScrollbarsActive(XP_Bool b)
  1593. {
  1594.   unsigned long x;
  1595.   unsigned long y;
  1596.   XFE_View::setScrollbarsActive(b);
  1597.   if (m_contextData) {
  1598.     x = CONTEXT_DATA(m_contextData)->document_x;
  1599.     y = CONTEXT_DATA(m_contextData)->document_y;
  1600.     fe_SetDocPosition(m_contextData, x, y);
  1601.   }
  1602. }
  1603.  
  1604.  
  1605. XFE_CALLBACK_DEFN(XFE_HTMLView, DocEncoding)(XFE_NotificationCenter *,
  1606.                          void *, void */*callData*/)
  1607. {
  1608.   fe_ReLayout(m_contextData, NET_DONT_RELOAD);
  1609. }
  1610.  
  1611. XFE_CALLBACK_DEFN(XFE_HTMLView, ChangeLinksAttribute)(XFE_NotificationCenter *,
  1612.                                                       void *, void */*callData*/)
  1613. {
  1614.     Dimension w = 0, h = 0;
  1615.     XtVaGetValues(CONTEXT_DATA(m_contextData)->drawing_area,
  1616.                   XmNwidth, &w,
  1617.                   XmNheight, &h,
  1618.                   0);
  1619.  
  1620.     fe_RefreshArea(m_contextData,
  1621.                    CONTEXT_DATA(m_contextData)->document_x,
  1622.                    CONTEXT_DATA(m_contextData)->document_y,
  1623.                    w, h);
  1624. }
  1625.  
  1626. XFE_CALLBACK_DEFN(XFE_HTMLView, ChangeDefaultColors)(XFE_NotificationCenter *,
  1627.                                                      void *, void */*callData*/)
  1628. {
  1629.     LO_Color *color;
  1630.  
  1631.     color = &fe_globalPrefs.links_color;
  1632.     CONTEXT_DATA(m_contextData)->link_pixel = 
  1633.         fe_GetPixel(m_contextData, color->red, color->green, color->blue);
  1634.     LO_SetDefaultColor(LO_COLOR_LINK, color->red, color->green, color->blue);
  1635.  
  1636.     color = &fe_globalPrefs.vlinks_color;
  1637.     CONTEXT_DATA(m_contextData)->vlink_pixel = 
  1638.         fe_GetPixel(m_contextData, color->red, color->green, color->blue);
  1639.     LO_SetDefaultColor(LO_COLOR_VLINK, color->red, color->green, color->blue);
  1640.  
  1641.     color = &fe_globalPrefs.text_color;
  1642.     CONTEXT_DATA(m_contextData)->default_fg_pixel = 
  1643.         fe_GetPixel(m_contextData, color->red, color->green, color->blue);
  1644.     LO_SetDefaultColor(LO_COLOR_FG, color->red, color->green, color->blue);
  1645.  
  1646.     color = &fe_globalPrefs.background_color;
  1647.     CONTEXT_DATA(m_contextData)->default_bg_pixel = 
  1648.         fe_GetPixel(m_contextData, color->red, color->green, color->blue);
  1649.     LO_SetDefaultColor(LO_COLOR_BG, color->red, color->green, color->blue);
  1650.  
  1651.     fe_ReLayout(m_contextData, NET_RESIZE_RELOAD);
  1652. }
  1653.  
  1654. XFE_CALLBACK_DEFN(XFE_HTMLView, ChangeDefaultFont)(XFE_NotificationCenter *,
  1655.                                                    void *, void */*callData*/)
  1656. {
  1657.     LO_InvalidateFontData(m_contextData);
  1658.     fe_ReLayout(m_contextData, NET_RESIZE_RELOAD);
  1659. }
  1660.  
  1661. void
  1662. XFE_HTMLView::translateToDocCoords(int x, int y,
  1663.                    int *doc_x, int *doc_y)
  1664. {
  1665.   *doc_x = x + CONTEXT_DATA(m_contextData)->document_x;
  1666.   *doc_y = y + CONTEXT_DATA(m_contextData)->document_y;
  1667. }
  1668.  
  1669. /* caller must free the returned URL_Struct */
  1670. URL_Struct *
  1671. XFE_HTMLView::URLAtPosition(int x, int y, CL_Layer *layer)
  1672. {
  1673.   LO_Element *le = layoutElementAtPosition(x, y, layer);
  1674.   URL_Struct *url_s = NULL;
  1675.   History_entry *h;
  1676.  
  1677.   if (le)
  1678.     {
  1679.       h = SHIST_GetCurrent(&m_contextData->hist);
  1680.  
  1681.       switch (le->type)
  1682.     {
  1683.     case LO_TEXT:
  1684.       if (le->lo_text.anchor_href)
  1685.         url_s = NET_CreateURLStruct ((char *)le->lo_text.anchor_href->anchor, NET_DONT_RELOAD);
  1686.       break;
  1687.     case LO_IMAGE:
  1688.             // check for client-side image map
  1689.           if (le->lo_image.image_attr->usemap_name != NULL) {
  1690.               LO_AnchorData *anchor_href;
  1691.  
  1692.               long ix = le->lo_image.x + le->lo_image.x_offset;
  1693.               long iy = le->lo_image.y + le->lo_image.y_offset;
  1694.               long mx = x - ix - le->lo_image.border_width;
  1695.               long my = y - iy - le->lo_image.border_width;
  1696.  
  1697.               anchor_href = LO_MapXYToAreaAnchor(m_contextData, (LO_ImageStruct *)le,mx, my);
  1698.               url_s = NET_CreateURLStruct ((char *)anchor_href->anchor, NET_DONT_RELOAD);
  1699.           }
  1700.           // check for regular image map
  1701.           else if (le->lo_image.anchor_href) {
  1702.             url_s = NET_CreateURLStruct ((char *)le->lo_image.anchor_href->anchor, NET_DONT_RELOAD);
  1703.             /* if this is an image map (and not an about: link), add the coordinates to the URL */    
  1704.             if (strncmp (url_s->address, "about:", 6)!=0 &&
  1705.               le->lo_image.image_attr->attrmask & LO_ATTR_ISMAP) {
  1706.                 int doc_x, doc_y;
  1707.                 int ix = le->lo_image.x + le->lo_image.x_offset;
  1708.                 int iy = le->lo_image.y + le->lo_image.y_offset;
  1709.                 int x_coord, y_coord;
  1710.                 
  1711.                 translateToDocCoords(x, y, &doc_x, &doc_y);
  1712.           
  1713.                 x_coord = doc_x - ix - le->lo_image.border_width;
  1714.                 y_coord = doc_y - iy - le->lo_image.border_width;
  1715.                 NET_AddCoordinatesToURLStruct (url_s,
  1716.                                                ((x_coord < 0) ? 0 : x_coord),
  1717.                                                ((y_coord < 0) ? 0 : y_coord));
  1718.             }
  1719.           }
  1720.             
  1721.       break;
  1722.     }
  1723.  
  1724.       if (h && url_s)
  1725.           url_s->referer = fe_GetURLForReferral(h);
  1726.     }
  1727.  
  1728.   return url_s;
  1729. }
  1730.  
  1731. /* caller must free the returned URL_Struct */
  1732. URL_Struct *
  1733. XFE_HTMLView::imageURLAtPosition(int x, int y, CL_Layer *layer)
  1734. {
  1735.   LO_Element *le = layoutElementAtPosition(x, y, layer);
  1736.   URL_Struct *image_url_s = NULL;
  1737.   History_entry *h;
  1738.  
  1739.   if (le && le->type == LO_IMAGE)
  1740.     {
  1741.       h = SHIST_GetCurrent(&m_contextData->hist);
  1742.  
  1743.       /* if we're currently looking at an image, construct the URL out of the history entry */
  1744.       if (h && h->is_binary)
  1745.     {
  1746.       image_url_s = NET_CreateURLStruct(h->address, NET_DONT_RELOAD);
  1747.     }
  1748.       else /* otherwise, construct it out of the info that layout gives us. */
  1749.     {
  1750.       char *image_url = (char*)le->lo_image.image_url;;
  1751.       
  1752.       /* If this is an internal-external-reconnect image, then the *real* url
  1753.          follows the "internal-external-reconnect:" prefix. Gag gag gag. */
  1754.       if (image_url) 
  1755.         {
  1756.           if (!XP_STRNCMP (image_url, "internal-external-reconnect:", 28))
  1757.         image_url += 28;
  1758.           
  1759.           image_url_s = NET_CreateURLStruct (image_url, NET_DONT_RELOAD);
  1760.         }
  1761.       
  1762.       if (image_url_s)
  1763.         {
  1764.           /* if this is an image map (and not an about: link), add the coordinates to the URL */
  1765.           if (strncmp (image_url_s->address, "about:", 6) &&
  1766.           le->lo_image.image_attr->attrmask & LO_ATTR_ISMAP)
  1767.         {
  1768.           int doc_x, doc_y;
  1769.           int ix = le->lo_image.x + le->lo_image.x_offset;
  1770.           int iy = le->lo_image.y + le->lo_image.y_offset;
  1771.           int x_coord, y_coord;
  1772.           
  1773.           translateToDocCoords(x, y, &doc_x, &doc_y);
  1774.           
  1775.           x_coord = doc_x - ix - le->lo_image.border_width;
  1776.           y_coord = doc_y - iy - le->lo_image.border_width;
  1777.           NET_AddCoordinatesToURLStruct (image_url_s,
  1778.                          ((x_coord < 0) ? 0 : x_coord),
  1779.                          ((y_coord < 0) ? 0 : y_coord));
  1780.         }
  1781.         }
  1782.     }
  1783.  
  1784.       if (h && image_url_s)
  1785.           image_url_s->referer = 
  1786.               fe_GetURLForReferral((History_entry *)&m_contextData->hist);
  1787.     }
  1788.  
  1789.   return image_url_s;
  1790. }
  1791.  
  1792. LO_Element *
  1793. XFE_HTMLView::layoutElementAtPosition(int x, int y, CL_Layer *layer)
  1794. {
  1795.   int doc_x, doc_y;
  1796.   LO_Element *le;
  1797.  
  1798.   translateToDocCoords(x, y, &doc_x, &doc_y);
  1799.  
  1800.   le = LO_XYToElement (m_contextData, x, y, layer);
  1801.  
  1802.   return le;
  1803. }
  1804. //////////////////////////////////////////////////////////////////////////
  1805. void
  1806. XFE_HTMLView::reload(Widget, XEvent *event, XP_Bool onlyReloadFrame)
  1807. {
  1808.   fe_UserActivity (m_contextData);
  1809. /*  if (fe_hack_self_inserting_accelerator (widget, NULL, NULL))
  1810.     return; */
  1811.   
  1812.   MWContext *context = m_contextData;
  1813.  
  1814.   if (onlyReloadFrame) {
  1815.     context = fe_GetFocusGridOfContext(m_contextData);
  1816.     if (context == NULL)
  1817.       context = m_contextData;
  1818.   }
  1819.  
  1820.   if (event->xkey.state & ShiftMask)
  1821.     fe_ReLayout (context, NET_SUPER_RELOAD);
  1822.   else
  1823.     fe_ReLayout (context, NET_NORMAL_RELOAD);
  1824. }
  1825. //////////////////////////////////////////////////////////////////////////
  1826. void
  1827. XFE_HTMLView::findLayerForPopupMenu(Widget widget, XEvent *event)
  1828. {
  1829.   MWContext *context;
  1830.   CL_Event layer_event;
  1831.   fe_EventStruct fe_event;
  1832.  
  1833.   /* If this is a grid cell, set focus to it */
  1834.   context = fe_MotionWidgetToMWContext (widget);
  1835.   if (!context)
  1836.     return;
  1837.   if (context && context->is_grid_cell)
  1838.     fe_UserActivity (context);
  1839.  
  1840.   /* Now grab the toplevel context and go. */
  1841.   context = fe_WidgetToMWContext (widget);
  1842.   XP_ASSERT (context);
  1843.   if (! context) return;
  1844.  
  1845.   /* Popup menu not valid for MWContextDialog */
  1846.   if (context->type == MWContextDialog) return;
  1847.  
  1848.   /* Fill in FE part of layer_event. */
  1849. #ifdef LAYERS_FULL_FE_EVENT
  1850.   fe_event.event = event;
  1851.   // fe_event.av = cav;
  1852.   // fe_event.ac = cac;
  1853.   fe_event.mouse_action = FE_POPUP_MENU;
  1854. #else
  1855.   fe_event_stuff(context,&fe_event,event,0,0,FE_POPUP_MENU);
  1856.   layer_event.fe_event_size = sizeof(fe_event);
  1857. #endif
  1858.   fe_event.data = (void *) this;
  1859.  
  1860.   layer_event.fe_event = (void *)&fe_event;
  1861.  
  1862.   layer_event.type = CL_EVENT_MOUSE_BUTTON_DOWN;
  1863.   layer_event.which = event->xbutton.button;
  1864.   layer_event.modifiers = xfeToLayerModifiers(event->xbutton.state);
  1865.  
  1866.   if (context->compositor)
  1867.       {
  1868.           unsigned long x, y;
  1869.  
  1870.           fe_EventLOCoords (context, event, &x, &y);
  1871.           layer_event.x = x;
  1872.           layer_event.y = y;
  1873.           CL_DispatchEvent(context->compositor, &layer_event);
  1874.       }
  1875.   else
  1876.       {
  1877.           doPopup (context, NULL, &layer_event);
  1878.       }
  1879. }
  1880.  
  1881. URL_Struct*
  1882. XFE_HTMLView::URLUnderMouse()
  1883. {
  1884.     return m_urlUnderMouse;
  1885. }
  1886.  
  1887. URL_Struct*
  1888. XFE_HTMLView::ImageUnderMouse()
  1889. {
  1890.     return m_imageUnderMouse;
  1891. }
  1892.  
  1893. URL_Struct*
  1894. XFE_HTMLView::BackgroundUnderMouse()
  1895. {
  1896.     return m_backgroundUnderMouse;
  1897. }
  1898.  
  1899. void
  1900. XFE_HTMLView::doPopup(MWContext *context, CL_Layer *layer,
  1901.               CL_Event *layer_event)
  1902.   fe_EventStruct *fe_event = (fe_EventStruct *) layer_event->fe_event;
  1903. #ifdef LAYERS_FULL_FE_EVENT
  1904.   XEvent *event = fe_event->event;
  1905. #else
  1906.   XEvent *event = fe_event_extract(fe_event,NULL,NULL,NULL);
  1907. #endif
  1908.   Boolean image_delayed_p = False;
  1909.   History_entry *h = NULL;
  1910.   char *image_url;
  1911.   Widget w = CONTEXT_WIDGET (context);
  1912.  
  1913.   if (!w)
  1914.     w = m_widget;
  1915.  
  1916.   m_urlUnderMouse = NULL;
  1917.   m_imageUnderMouse = NULL;
  1918.   m_backgroundUnderMouse = NULL;
  1919.  
  1920.   // Add dynamic entries dependent on what's under the mouse
  1921.   int x = layer_event->x;
  1922.   int y = layer_event->y;
  1923.   LO_Element *le = LO_XYToElement (context, x, y, layer);
  1924.  
  1925.   if (le)
  1926.     switch (le->type)
  1927.       {
  1928.       case LO_TEXT:
  1929.         if (le->lo_text.anchor_href)
  1930.           m_urlUnderMouse =
  1931.             NET_CreateURLStruct ((char *) le->lo_text.anchor_href->anchor,
  1932.                                  NET_DONT_RELOAD);
  1933.         break;
  1934.       case LO_IMAGE:
  1935.         if (le->lo_image.anchor_href)
  1936.           m_urlUnderMouse =
  1937.             NET_CreateURLStruct ((char *) le->lo_image.anchor_href->anchor,
  1938.                                  NET_DONT_RELOAD);
  1939.  
  1940.         /* If this is an internal-external-reconnect image, then the *real*
  1941.            url follows the "internal-external-reconnect:" prefix. Gag gag.*/
  1942.         image_url = (char*)le->lo_image.image_url;
  1943.         if (image_url) {
  1944.           if (!XP_STRNCMP (image_url, "internal-external-reconnect:", 28))
  1945.             image_url += 28;
  1946.           m_imageUnderMouse =
  1947.             NET_CreateURLStruct (image_url, NET_DONT_RELOAD);
  1948.         }
  1949.         
  1950.         image_delayed_p = le->lo_image.is_icon &&
  1951.           le->lo_image.icon_number == IL_IMAGE_DELAYED;
  1952.         
  1953.         if (m_urlUnderMouse &&
  1954.             strncmp (m_urlUnderMouse->address, "about:", 6) &&
  1955.             le->lo_image.image_attr->attrmask & LO_ATTR_ISMAP)
  1956.           {
  1957.             /* cribbed from fe_activate_link_action() */
  1958.             long cx = layer_event->x + CONTEXT_DATA (context)->document_x;
  1959.             long cy = layer_event->y + CONTEXT_DATA (context)->document_y;
  1960.             long ix = le->lo_image.x + le->lo_image.x_offset;
  1961.             long iy = le->lo_image.y + le->lo_image.y_offset;
  1962.             long x = cx - ix - le->lo_image.border_width;
  1963.             long y = cy - iy - le->lo_image.border_width;
  1964.             NET_AddCoordinatesToURLStruct (m_urlUnderMouse,
  1965.                                            ((x < 0) ? 0 : x),
  1966.                                            ((y < 0) ? 0 : y));
  1967.           }
  1968.         break;
  1969.       default:
  1970.         // must be something we don't care about
  1971.         break;
  1972.       }
  1973.  
  1974.   if (m_imageUnderMouse == NULL)
  1975.     {
  1976.       const char *backgroundURL;
  1977.       CL_Layer *parent_layer;
  1978.       char *layer_name;
  1979.       layer_name = CL_GetLayerName(layer);
  1980.       if (layer_name && ((XP_STRCMP(layer_name, LO_BODY_LAYER_NAME) == 0) ||
  1981.                          (XP_STRCMP(layer_name, LO_BACKGROUND_LAYER_NAME) == 0)))
  1982.         {
  1983.           parent_layer = CL_GetLayerParent(layer);
  1984.           //pLOImage = LO_GetLayerBackdropImage(parent_layer);
  1985.           backgroundURL = LO_GetLayerBackdropURL(parent_layer);
  1986.         }
  1987.       else
  1988.         {
  1989.           //pLOImage = LO_GetLayerBackdropImage(layer);
  1990.           backgroundURL = LO_GetLayerBackdropURL(layer);
  1991.         }
  1992.  
  1993.       if (backgroundURL) 
  1994.         {
  1995.           m_backgroundUnderMouse =
  1996.             NET_CreateURLStruct (backgroundURL, NET_DONT_RELOAD);
  1997.         }
  1998.     }
  1999.  
  2000.   if (h && h->is_binary)
  2001.     {
  2002.       if (m_imageUnderMouse)
  2003.         NET_FreeURLStruct (m_imageUnderMouse);
  2004.       m_imageUnderMouse = NET_CreateURLStruct (h->address, NET_DONT_RELOAD);
  2005.     }
  2006.  
  2007.   /* Add the referer to the URLs. */
  2008.   /* Ahh! h is never set.  Fix on 5.0 tip, can't risk
  2009.      fixing this for 4.04. -mcafee */
  2010.   if (h && h->address)
  2011.     {
  2012.       if (m_urlUnderMouse)
  2013.         m_urlUnderMouse->referer = fe_GetURLForReferral(h);
  2014.       if (m_imageUnderMouse)
  2015.         m_imageUnderMouse->referer = fe_GetURLForReferral(h);
  2016.       if (m_backgroundUnderMouse)
  2017.         m_backgroundUnderMouse->referer = fe_GetURLForReferral(h);
  2018.     }
  2019.  
  2020.  
  2021.   if (hasInterested(XFE_HTMLView::popupNeedsShowing))
  2022.       {
  2023.           notifyInterested(XFE_HTMLView::popupNeedsShowing, event);
  2024.       }
  2025.   else
  2026.       {
  2027.           // Delete the old popup if needed
  2028.           if (m_popup != NULL)
  2029.           {
  2030.               delete m_popup;
  2031.           }
  2032.  
  2033.           // Create and initialize the popup
  2034.           m_popup = new XFE_PopupMenu ("popup",
  2035.                                        (XFE_Frame *) m_toplevel, 
  2036.                                        XfeAncestorFindApplicationShell(w));
  2037.           
  2038.           XP_Bool isBrowserLink = FALSE;
  2039.           
  2040.           if (m_urlUnderMouse != NULL
  2041.               && XP_STRNCMP ("mailto:", m_urlUnderMouse->address, 7) != 0
  2042.               && XP_STRNCMP ("telnet:", m_urlUnderMouse->address, 7) != 0
  2043.               && XP_STRNCMP ("tn3270:", m_urlUnderMouse->address, 7) != 0
  2044.               && XP_STRNCMP ("rlogin:", m_urlUnderMouse->address, 7) != 0)
  2045.               {
  2046.                   isBrowserLink = TRUE;
  2047.               }
  2048.           
  2049.           XP_Bool isLink = m_urlUnderMouse != NULL;
  2050.           XP_Bool isImage = m_imageUnderMouse != NULL;
  2051.           XP_Bool isFrame = hasSubViews();
  2052.           XP_Bool isBrowser = m_contextData->type == MWContextBrowser;
  2053.           XP_Bool isBackground = m_backgroundUnderMouse != NULL;
  2054.           
  2055.           XP_Bool needSeparator = FALSE;
  2056.           XP_Bool haveAddedItems = FALSE;
  2057.           
  2058. #define ADD_MENU_SEPARATOR {                     \
  2059.     if (haveAddedItems) {                        \
  2060.       needSeparator = TRUE;                      \
  2061.       haveAddedItems = FALSE;                    \
  2062.     }                                            \
  2063. }
  2064. #define ADD_SPEC(theSpec) {                      \
  2065.   if (needSeparator)                             \
  2066.     m_popup->addMenuSpec(separator_spec);        \
  2067.   m_popup->addMenuSpec(theSpec);                 \
  2068.   needSeparator = FALSE;                         \
  2069.   haveAddedItems = TRUE;                         \
  2070. }
  2071.  
  2072.           if (isBrowser)                           ADD_SPEC ( go_spec );
  2073.           if (isImage && image_delayed_p)          ADD_SPEC ( showImage_spec );
  2074.           if (isCommandEnabled(xfeCmdStopLoading)) ADD_SPEC ( stopLoading_spec );
  2075.           ADD_MENU_SEPARATOR;
  2076.           if (isBrowserLink)                       ADD_SPEC ( openLinkNew_spec );
  2077.           if (isFrame)                             ADD_SPEC ( openFrameNew_spec );
  2078. #ifdef EDITOR
  2079.           if (isBrowserLink)                       ADD_SPEC ( openLinkEdit_spec );
  2080. #endif
  2081.           ADD_MENU_SEPARATOR;
  2082.           if (isBrowser)                           ADD_SPEC ( page_details_spec );
  2083.           if (isImage)                             ADD_SPEC ( openImage_spec );
  2084.           ADD_MENU_SEPARATOR;
  2085.           if (isLink) {                            ADD_SPEC ( addLinkBookmark_spec );
  2086.           } else if (isFrame) {                    ADD_SPEC ( addFrameBookmark_spec );
  2087.           } else if (isBrowser) {                  ADD_SPEC ( addBookmark_spec );
  2088.           }
  2089.           if (isBrowser)                           ADD_SPEC ( sendPage_spec );
  2090.           ADD_MENU_SEPARATOR;
  2091.           if (isBrowserLink)                       ADD_SPEC ( saveLink_spec );
  2092.           if (isImage)                             ADD_SPEC ( saveImage_spec );
  2093.           if (isBackground)                        ADD_SPEC ( saveBGImage_spec );
  2094.           ADD_MENU_SEPARATOR;
  2095.           if (isCommandEnabled(xfeCmdCopy))        ADD_SPEC ( copy_spec );
  2096.           if (isLink)                              ADD_SPEC ( copyLink_spec );
  2097.           if (isImage)                             ADD_SPEC ( copyImage_spec );
  2098.           // Finish up the popup
  2099.           m_popup->position (event);
  2100.           m_popup->show();
  2101.       }
  2102. }
  2103. #if DO_NOT_PASS_LAYER_N_EVENT
  2104. void 
  2105. XFE_HTMLView::tipCB(MWContext *context, int x, int y, char* alt_text,
  2106.                     XtPointer cb_data)
  2107. {
  2108.     XFE_TipStringCallbackStruct* cbs = (XFE_TipStringCallbackStruct*)cb_data;
  2109.     Widget w = CONTEXT_WIDGET (context);
  2110.     
  2111.     if (!w)
  2112.         w = m_widget;
  2113.  
  2114.     // tip string
  2115.     if (alt_text) {
  2116.         /* to be free by the caller
  2117.          */
  2118.         *cbs->string = XP_STRDUP((char *)alt_text);
  2119.     }/* if */
  2120.  
  2121.     // positioning
  2122.     cbs->x = x;
  2123.     cbs->y = y+ 20;
  2124.  
  2125.     // correct offsets
  2126.     if (CONTEXT_DATA(context)->drawing_area &&
  2127.         CONTEXT_DATA(context)) {
  2128.         cbs->x -= CONTEXT_DATA (context)->document_x;
  2129.         cbs->y -= CONTEXT_DATA (context)->document_y;
  2130.     }/* if */
  2131. }
  2132. #else
  2133. void 
  2134. XFE_HTMLView::tipCB(MWContext *context, CL_Layer *layer,
  2135.                     CL_Event *layer_event,    XtPointer cb_data)
  2136. {
  2137.     XFE_TipStringCallbackStruct* cbs = (XFE_TipStringCallbackStruct*)cb_data;
  2138.     Widget w = CONTEXT_WIDGET (context);
  2139.     
  2140.     if (!w)
  2141.         w = m_widget;
  2142.  
  2143.     /*
  2144.      */
  2145.     int x = layer_event->x;
  2146.     int y = layer_event->y;
  2147.  
  2148.     /* Tao: fix BSR in XFE_HTMLView::tipCB; 
  2149.      * allocatedfrom fe_HTMLViewTooltipsEH
  2150.      */
  2151.     XP_FREEIF(layer_event);
  2152.  
  2153.     LO_Element *le = LO_XYToElement (context, x, y, layer);
  2154.  
  2155.     // tip string
  2156.     if (le && 
  2157.         le->type == LO_IMAGE &&
  2158.         le->lo_image.alt &&
  2159.         le->lo_image.alt_len ) {
  2160.  
  2161.         /* to be free by the caller
  2162.          */
  2163.         *cbs->string = XP_STRDUP((char *)le->lo_image.alt);
  2164.     }/* if */
  2165.  
  2166.     // positioning
  2167.     cbs->x = x;
  2168.     cbs->y = y+ 20;
  2169.  
  2170.     // correct offsets
  2171.     if (CONTEXT_DATA(context)->drawing_area &&
  2172.         CONTEXT_DATA(context)) {
  2173.         cbs->x -= CONTEXT_DATA (context)->document_x;
  2174.         cbs->y -= CONTEXT_DATA (context)->document_y;
  2175.     }/* if */
  2176. }
  2177. #endif
  2178.  
  2179. extern "C" void
  2180. fe_HTMLViewDoPopup (MWContext *context, CL_Layer *layer,
  2181.             CL_Event *layer_event)
  2182. {
  2183.   fe_EventStruct *fe_event = (fe_EventStruct *) layer_event->fe_event;
  2184.   XFE_HTMLView *htmlview = (XFE_HTMLView *) fe_event->data;
  2185.   if (htmlview)
  2186.     htmlview->doPopup (context, layer, layer_event);
  2187. #ifdef DEBUG
  2188.   else
  2189.     fprintf(stderr,"fe_HTMLViewDoPopup(): htmlview is NULL\n");
  2190. #endif
  2191. }
  2192.  
  2193. #if DO_NOT_PASS_LAYER_N_EVENT
  2194. extern "C" void
  2195. fe_HTMLViewTooltips(MWContext *context, 
  2196.                     int x, int y, char *alt_text, 
  2197.                     XFE_TipStringCallbackStruct *cb_info)
  2198. {
  2199.     /* let's get htmlview from context
  2200.      */
  2201.     Widget drawingArea = CONTEXT_DATA(context)->drawing_area;
  2202.     if (drawingArea) {
  2203.         /* Get view from widget
  2204.          */
  2205.         XFE_Frame *f = ViewGlue_getFrame(XP_GetNonGridContext(context));
  2206.         if (f) {
  2207.             XFE_View *view = f->widgetToView(drawingArea);
  2208.             if (view) {
  2209.                 if (f->getType() == FRAME_BROWSER) {
  2210.                     XFE_HTMLView *htmlview = (XFE_HTMLView *) view;
  2211.                     htmlview->tipCB(context, x, y, alt_text, 
  2212.                                     (XtPointer)cb_info);
  2213.                 }/* if */
  2214.             }/* if */
  2215.         }/* if f */
  2216.     }/* if drawingArea */
  2217. }/* fe_HTMLViewTooltips() */
  2218. #else
  2219. extern "C" void
  2220. fe_HTMLViewTooltips(MWContext *context, 
  2221.                     CL_Layer *layer,
  2222.                     CL_Event *layer_event, 
  2223.                     XFE_TipStringCallbackStruct *cb_info)
  2224. {
  2225.     /* let's get htmlview from context
  2226.      */
  2227.     Widget drawingArea = CONTEXT_DATA(context)->drawing_area;
  2228.     if (drawingArea) {
  2229.         /* Get view from widget
  2230.          */
  2231.         XFE_Frame *f = ViewGlue_getFrame(XP_GetNonGridContext(context));
  2232.         if (f) {
  2233. #if defined(DEBUG_tao)
  2234.             printf("\n fe_HTMLViewTooltips, type=%d\n", 
  2235.                        f->getType());
  2236. #endif
  2237.             XFE_View *view = f->widgetToView(drawingArea);
  2238.             if (view) {
  2239.                 if (f->getType() == FRAME_BROWSER) {
  2240. #if defined(DEBUG_tao)
  2241.                     printf("\n drawingArea=%x, viewWidget=%x\n", 
  2242.                            drawingArea, view->getBaseWidget());
  2243. #endif
  2244.                     XFE_HTMLView *htmlview = (XFE_HTMLView *) view;
  2245.                     htmlview->tipCB(context, layer, layer_event, 
  2246.                                     (XtPointer)cb_info);
  2247.                 }/* if */
  2248.             }/* if */
  2249. #ifdef DEBUG
  2250.             else
  2251.                 fprintf(stderr,"fe_HTMLViewTooltips(): htmlview is NULL\n");
  2252. #endif
  2253.         }/* if f */
  2254.     }/* if drawingArea */
  2255. }/* fe_HTMLViewTooltips() */
  2256. #endif
  2257.  
  2258. // Need to be able to access the popup menu from XFE_Command handlers.
  2259. // I've made HTML_View->m_popup visible to EditorView sub-class. These
  2260. // getter/setters will allow the XFE_Command handlers access...djw
  2261. XFE_PopupMenu*
  2262. XFE_HTMLView::getPopupMenu()
  2263. {
  2264.     return m_popup;
  2265. }
  2266.  
  2267. void
  2268. XFE_HTMLView::setPopupMenu(XFE_PopupMenu* popup)
  2269. {
  2270.     if (m_popup != NULL)
  2271.         delete m_popup;
  2272.     m_popup = popup;
  2273. }
  2274.  
  2275.  
  2276. static void fe_raise_frame(MWContext * context)
  2277. {
  2278.     if (!context)
  2279.     {
  2280.         return;
  2281.     }
  2282.  
  2283.     /* Find the frame from the context */
  2284.     XFE_Frame * frame = ViewGlue_getFrame(XP_GetNonGridContext(context));
  2285.  
  2286.     if (!frame)
  2287.     {
  2288.         return;
  2289.     }
  2290.         
  2291.     if (frame && frame->isAlive())
  2292.     {
  2293.         Widget w = frame->getBaseWidget();
  2294.         
  2295.         XMapRaised(XtDisplay(w),XtWindow(w));
  2296.         
  2297.         XtPopup(w,XtGrabNone);
  2298.     }
  2299. }
  2300.  
  2301. #define APP_SET_BUSY(busy)                            \
  2302. {                                                    \
  2303.     if (busy)                                        \
  2304.     {                                                \
  2305.         XFE_MozillaApp::theApp()->notifyInterested(    \
  2306.             XFE_MozillaApp::appBusyCallback);        \
  2307.     }                                                \
  2308.     else                                            \
  2309.     {                                                \
  2310.         XFE_MozillaApp::theApp()->notifyInterested(    \
  2311.             XFE_MozillaApp::appNotBusyCallback);    \
  2312.     }                                                \
  2313. }
  2314.  
  2315. /*
  2316.  * Open a target url.  
  2317.  * The context can be NULL, but anchor_data must be valid.
  2318.  * anchor_data->anchor can be anything understood by either browser or 
  2319.  * mail news frames.
  2320.  */
  2321. void
  2322. fe_openTargetUrl(MWContext * context,LO_AnchorData * anchor_data)
  2323. {
  2324.     URL_Struct *    url = NULL;
  2325.     int                url_type;
  2326.     XP_Bool            is_msg_url = False;
  2327.     XP_Bool            is_message_center = False;
  2328.     XFE_Frame *        parent_frame = NULL;
  2329.  
  2330.     XP_ASSERT( anchor_data != NULL );
  2331.  
  2332.     if (context)
  2333.     {
  2334.         parent_frame = ViewGlue_getFrame(context);
  2335.     }
  2336.  
  2337.     url = NET_CreateURLStruct((char *) anchor_data->anchor, NET_NORMAL_RELOAD);
  2338.  
  2339.     /* url type */
  2340.     url_type = NET_URL_Type(url->address);
  2341.  
  2342.     /* Is this a mail/news url ? */
  2343.     is_msg_url = (url_type == MAILBOX_TYPE_URL || url_type == NEWS_TYPE_URL || url_type == IMAP_TYPE_URL);
  2344.  
  2345.     /* Determine if this is the message center */
  2346.     is_message_center = 
  2347.         (parent_frame && parent_frame->getType() == FRAME_MAILNEWS_FOLDER);
  2348.  
  2349.     /*
  2350.      * In order for mail/news bookmarks to work, at least one messenger 
  2351.      * has to exist.
  2352.      */
  2353.     if (is_msg_url)
  2354.     {
  2355. #ifdef MOZ_MAIL_NEWS
  2356.         XP_List * messenger_list = 
  2357.             XFE_MozillaApp::theApp()->getFrameList(FRAME_MAILNEWS_MSG);
  2358.  
  2359.         /* Create a messenger if none exist */
  2360.         if (!XP_ListCount(messenger_list))
  2361.         {
  2362.             APP_SET_BUSY(True);
  2363.  
  2364.             fe_showInbox(FE_GetToplevelWidget(),
  2365.                          NULL,
  2366.                          NULL,
  2367.                          fe_globalPrefs.reuse_thread_window,
  2368.                          False);
  2369.  
  2370.             APP_SET_BUSY(False);
  2371.         }
  2372. #endif  /* MOZ_MAIL_NEWS */
  2373.     }
  2374.  
  2375.     /* A msg url being opened from either a message frame or the messenger */
  2376.     if (context &&
  2377.         (context->type == MWContextMailMsg) &&
  2378.         is_msg_url && 
  2379.         !is_message_center)
  2380.     {
  2381.         /* Nothing, fe_GetURL() below will deal with it */
  2382.     }
  2383.     /* A msg url being opened from any other frame (even message center) */
  2384.     else if (is_msg_url)
  2385.     {
  2386. #ifdef MOZ_MAIL_NEWS
  2387.         /*
  2388.          * Trying to be clever about re-using messages frames.  Needs more
  2389.          * work and maybe a better method so its out.
  2390.          */
  2391. #if 0
  2392.         XP_Bool found = False;
  2393.  
  2394.         /* Try to reuse a message frame */
  2395.         if (fe_globalPrefs.reuse_msg_window)
  2396.         {
  2397.             XP_List * msg_list = 
  2398.                 XFE_MozillaApp::theApp()->getFrameList(FRAME_MAILNEWS_MSG);
  2399.  
  2400.             if (XP_ListCount(msg_list))
  2401.             {
  2402.                 XFE_Frame * msg_frame = (XFE_Frame *) 
  2403.                     XP_ListGetObjectNum(msg_list,0);
  2404.                 
  2405.                 context = msg_frame->getContext();
  2406.  
  2407.                 found = True;
  2408.             }
  2409.         }
  2410. #endif
  2411.         APP_SET_BUSY(True);
  2412.         
  2413.         /* Get a mail message context */
  2414.         context = fe_showMsg(FE_GetToplevelWidget(),
  2415.                              parent_frame,
  2416.                              NULL,
  2417.                              NULL,
  2418.                              MSG_MESSAGEKEYNONE,
  2419.                              fe_globalPrefs.reuse_msg_window);
  2420.  
  2421.         APP_SET_BUSY(False);
  2422. #endif  /* MOZ_MAIL_NEWS */
  2423.     }
  2424.     /* URLS which fe_GetURL() can handle and which require no extra windows */
  2425.     else if (url_type == MAILTO_TYPE_URL ||
  2426.              url_type == RLOGIN_TYPE_URL ||
  2427.              url_type == TN3270_TYPE_URL ||
  2428.              url_type == TELNET_TYPE_URL)
  2429.     {
  2430.         fe_GetURL(context,url,False);
  2431.  
  2432.         return;
  2433.     }
  2434. #ifdef MOZ_MAIL_NEWS
  2435.     /* addbook: */
  2436.     else if (url_type == ADDRESS_BOOK_TYPE_URL)
  2437.     {
  2438.         APP_SET_BUSY(True);
  2439.  
  2440.         fe_showAddrBook(FE_GetToplevelWidget(),parent_frame,NULL);
  2441.  
  2442.         APP_SET_BUSY(False);
  2443.  
  2444.          return;
  2445.     }
  2446. #endif  /* MOZ_MAIL_NEWS */
  2447.     /* Anything else which probably requires a browser */
  2448.     else
  2449.     {
  2450.         /* Check for non-browser contexts */
  2451.         if (!context || (context->type != MWContextBrowser))
  2452.         {
  2453.             /* Reuse a browser if possible */
  2454.             MWContext * reuse_context=fe_FindNonCustomBrowserContext(context);
  2455.             
  2456.             if (reuse_context)
  2457.             {
  2458.                 context = reuse_context;
  2459.             }
  2460.             /* Otherwise create a new browser */
  2461.             else
  2462.             {
  2463.                 APP_SET_BUSY(True);
  2464.  
  2465.                 /* If the target window doesn't exist, create it. */
  2466.                 MWContext * new_context =
  2467.                     fe_MakeWindow(FE_GetToplevelWidget(),
  2468.                                   context,
  2469.                                   url,
  2470.                                   (char *) anchor_data->target,
  2471.                                   MWContextBrowser, 
  2472.                                   False);
  2473.  
  2474.                 /* Raise the frame */
  2475.                 fe_raise_frame(new_context);
  2476.                 
  2477.                 APP_SET_BUSY(False);
  2478.  
  2479.                 /*
  2480.                  * fe_MakeWindow() loads the url, so we are done.  We dont
  2481.                  * need the extra fe_GetURL() below.
  2482.                  */
  2483.                 return;
  2484.             }
  2485.             
  2486.             /* If there is a target window, deal with it. */
  2487.             if (anchor_data->target)
  2488.             {
  2489.                 MWContext * target_context;
  2490.                 
  2491.                 target_context = 
  2492.                     XP_FindNamedContextInList(context,
  2493.                                               (char *)anchor_data->target);
  2494.                 
  2495.                 /* This prevents the parser from double-guessing us. */
  2496.                 url->window_target = strdup ("");
  2497.                 
  2498.                 if (target_context)
  2499.                 {
  2500.                     context = target_context;
  2501.                 }
  2502.             }
  2503.         }
  2504.     }
  2505.  
  2506.     XP_ASSERT( context != NULL );
  2507.     XP_ASSERT( url != NULL );
  2508.  
  2509.     if (!context || !url)
  2510.     {
  2511.         return;
  2512.     }
  2513.  
  2514.     /* Raise the frame */
  2515.     fe_raise_frame(context);
  2516.  
  2517.     /* Do the magic */
  2518.     fe_GetURL(context,url,False);
  2519. }
  2520.  
  2521. void
  2522. XFE_HTMLView::openFileAction (String *av, Cardinal *ac)
  2523. {
  2524.   MWContext *context = m_contextData;
  2525.   MWContext *old_context = NULL;
  2526.  
  2527.   /* See also fe_open_url_action() */
  2528.   Boolean other_p = False;
  2529.  
  2530.   fe_UserActivity (context);
  2531.   if (*ac && av[*ac-1] && !strcmp (av[*ac-1], "<remote>"))
  2532.     (*ac)--;
  2533.  
  2534.   if (*ac > 1 && av[*ac-1] )
  2535.     {
  2536.       if ((!strcasecomp (av[*ac-1], "new-window") ||
  2537.            !strcasecomp (av[*ac-1], "new_window") ||
  2538.            !strcasecomp (av[*ac-1], "newWindow") ||
  2539.            !strcasecomp (av[*ac-1], "new")))
  2540.         {
  2541.           other_p = True;
  2542.           (*ac)--;
  2543.         }
  2544.       else if ((old_context = XP_FindNamedContextInList(context, av[*ac-1])))
  2545.         {
  2546.           context = old_context;
  2547.           other_p = False;
  2548.           (*ac)--;
  2549.         }
  2550.       else 
  2551.         {
  2552.           other_p = True;
  2553.           (*ac)--;
  2554.         }
  2555.     }
  2556.  
  2557.   if (*ac == 1 && av[0])
  2558.     {
  2559. #ifndef PATH_MAX
  2560. #define PATH_MAX 1024     
  2561. #endif
  2562.       char newURL [PATH_MAX];
  2563.       URL_Struct *url_struct;
  2564.       
  2565.       if (av[0][0] == '/')
  2566.         {
  2567.           PR_snprintf (newURL, sizeof (newURL), "file:%.900s", av[0]);
  2568.         }
  2569.       else
  2570.         {
  2571.           char cwd_buf[PATH_MAX];
  2572.           getcwd(cwd_buf, PATH_MAX);
  2573.  
  2574.           PR_snprintf (newURL, sizeof (newURL), "file:%s/%.900s",
  2575.                        cwd_buf, av[0]);
  2576.         }
  2577. #ifdef DEBUG_slamm
  2578.       fprintf(stderr,"%s",newURL);
  2579. #endif
  2580.       url_struct = NET_CreateURLStruct (newURL, NET_DONT_RELOAD);
  2581.       if (other_p) 
  2582.         {
  2583.           fe_MakeWindow (XtParent (CONTEXT_WIDGET (context)),
  2584.                          context, url_struct, NULL, 
  2585.                          MWContextBrowser, FALSE);
  2586.         }
  2587.       else
  2588.         fe_GetURL (context, url_struct, FALSE);
  2589.     }
  2590.   else if (*ac > 1)
  2591.     {
  2592.       fprintf (stderr,
  2593.            XP_GetString(XFE_COMMANDS_OPEN_FILE_USAGE),
  2594.            fe_progname);
  2595.     }
  2596.   else
  2597.     {
  2598.       fe_OpenURLChooseFileDialog (context);
  2599.     }
  2600. }
  2601.