home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / Frame.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  131.6 KB  |  4,994 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.    Frame.cpp -- class for toplevel XFE windows.
  20.    Created: Chris Toshok <toshok@netscape.com>, 7-Aug-96.
  21.  */
  22.  
  23.  
  24.  
  25. #include "Frame.h"
  26.  
  27. #include "layers.h"
  28.  
  29. #include "mozjava.h"
  30.  
  31. #include "libmocha.h"
  32. #include "libevent.h"
  33.  
  34. #include <libi18n.h>        /* for the document encoding stuff. */
  35. #include <intl_csi.h>        /* to get/set doc_csid/win_csid */
  36. #include "libimg.h"             /* Image Library public API. */
  37. #include "il_util.h"            /* Colormap/colorspace utilities. */
  38.  
  39. #include "DisplayFactory.h"
  40. #include "MozillaApp.h"
  41. #include "xfe2_extern.h"
  42. #include "View.h"
  43. #include "MenuBar.h"
  44. #include "BookmarkMenu.h"
  45. #include "BrowserFrame.h"
  46. #include "HistoryFrame.h"
  47. #include "NavCenterFrame.h"
  48. #include "FrameListMenu.h"
  49. #include "Minibuffer.h"
  50. #include "Toolbox.h"
  51. #include "Dashboard.h"
  52. #include "Logo.h"
  53. #include "Netcaster.h"
  54. #include "ViewGlue.h"
  55. #ifdef MOZ_MAIL_NEWS
  56. #include "MNView.h" /* for MNView::getBiffState() */
  57. #endif
  58. #include "xpassert.h"
  59. #include "xpgetstr.h"
  60. #include "prefapi.h"
  61. #include "e_kit.h"
  62.  
  63. #include <X11/IntrinsicP.h>
  64. #include <X11/ShellP.h>
  65.  
  66. #include <Xm/Protocols.h>
  67. #include <Xfe/ToolBox.h>
  68. #include <Xfe/FrameShell.h>
  69. #include <Xm/MwmUtil.h>      // For MWM_DECOR_XXX
  70.  
  71. #include "XmL/Grid.h"
  72.  
  73. #include <Xfe/Xfe.h>
  74.  
  75. #ifndef NO_SECURITY
  76. #include "ssl.h" // For Security Status defines: SSL_SECURITY_STATUS_*
  77. #endif /* ! NO_SECURITY */
  78.  
  79. #ifdef EDITOR
  80. #include "xeditor.h"
  81. #endif /*EDITOR*/
  82.  
  83. #ifndef __sgi
  84. #include <X11/Xmu/Editres.h>    /* For editres to work on anything but Irix */
  85. #endif
  86.  
  87. // For mozilla wm extensions
  88. #include "MozillaWm.h"
  89.  
  90. #ifdef MOZILLA_GPROF
  91. #include "gmon.h"
  92. #endif /*MOZILLA_GPROF*/
  93.  
  94. #define MM_PER_INCH      (25.4)
  95. #define POINTS_PER_INCH  (72.0)
  96.  
  97. #if DEBUG_toshok
  98. #define D(x) x
  99. #else
  100. #define D(x)
  101. #endif
  102.  
  103. extern char *fe_calendar_path;
  104. extern char *fe_host_on_demand_path;
  105.  
  106. // baggage
  107. extern "C" {
  108.     MWContext* fe_WidgetToMWContext(Widget);
  109.     void fe_ProtectContext(MWContext *context);
  110.     void fe_UnProtectContext(MWContext *context);
  111.     XP_Bool fe_IsContextDestroyed(MWContext *context);
  112.     void fe_fixFocusAndGrab(MWContext *context);
  113.     void fe_load_default_font (MWContext *context);
  114.     void fe_find_scrollbar_sizes (MWContext *context);
  115.     void fe_get_final_context_resources (MWContext *context);
  116.     Colormap fe_getColormap(fe_colormap *colormap);
  117.     void fe_cleanup_tooltips(MWContext *context);
  118. #ifdef JAVA
  119.     void fe_new_show_java_console_cb (Widget widget, XtPointer closure,
  120.                                       XtPointer call_data);
  121. #endif /* JAVA */
  122.     void fe_NetscapeCallback(Widget, XtPointer, XtPointer);
  123.  
  124.     XP_Bool fe_IsCalendarInstalled();
  125.     XP_Bool fe_IsHostOnDemandInstalled();
  126.     XP_Bool fe_IsPolarisInstalled();
  127.     XP_Bool fe_IsConferenceInstalled();
  128.     URL_Struct *fe_GetBrowserStartupUrlStruct();
  129. };
  130.  
  131. extern MWContext *last_documented_xref_context;
  132. extern LO_Element *last_documented_xref;
  133. extern LO_AnchorData *last_documented_anchor_data;
  134.  
  135.  
  136. // - Shared Menu Spec - These specs are defined here because they are the same
  137. // menu spec(definition) for each different frame type
  138.  
  139. MenuSpec XFE_Frame::new_menu_spec[] = {
  140.   { xfeCmdOpenBrowser,        PUSHBUTTON },
  141.   { xfeCmdComposeMessage,    PUSHBUTTON },
  142. #ifdef EDITOR
  143.   MENU_SEPARATOR,
  144.   MENU_PUSHBUTTON(xfeCmdNewBlank),
  145.   MENU_PUSHBUTTON(xfeCmdNewTemplate),
  146.   MENU_PUSHBUTTON(xfeCmdNewWizard),
  147. #endif
  148.   { NULL }
  149. };
  150.  
  151. MenuSpec XFE_Frame::bookmark_submenu_spec[] = {
  152.     { xfeCmdAddBookmark,        PUSHBUTTON },
  153.     { "fileBookmarksSubmenu",     DYNA_FANCY_CASCADEBUTTON, NULL, NULL, False, (void*)True, XFE_BookmarkMenu::generate },
  154.     { xfeCmdOpenBookmarks,    PUSHBUTTON },
  155.     MENU_SEPARATOR,
  156.     { "placesSubmenu",            CASCADEBUTTON, XFE_Frame::places_menu_spec},
  157.     MENU_SEPARATOR,
  158.     { "bookmarkPlaceHolder",    DYNA_MENUITEMS, NULL, NULL, False, (void*)False, XFE_BookmarkMenu::generate },
  159.     { NULL }
  160. };
  161.  
  162. MenuSpec XFE_Frame::window_menu_spec[] = {
  163.     { xfeCmdOpenNavCenter,  PUSHBUTTON },
  164.     { xfeCmdOpenOrBringUpBrowser,    PUSHBUTTON },
  165. #ifdef MOZ_MAIL_NEWS
  166.     { xfeCmdOpenInbox,        PUSHBUTTON },
  167.     { xfeCmdOpenNewsgroups,    PUSHBUTTON },
  168. #endif
  169. #ifdef EDITOR
  170.     { xfeCmdOpenEditor,        PUSHBUTTON },
  171. #endif
  172. #ifdef MOZ_MAIL_NEWS
  173.     { xfeCmdOpenConference,       PUSHBUTTON },
  174.     { xfeCmdOpenCalendar,         PUSHBUTTON },
  175.     { xfeCmdOpenHostOnDemand,     PUSHBUTTON },
  176. #endif
  177. #ifdef MOZ_NETCAST
  178.     { xfeCmdOpenNetcaster,        PUSHBUTTON },
  179. #endif
  180. #ifdef MOZ_TASKBAR
  181.     MENU_SEPARATOR,
  182.     { xfeCmdToggleTaskbarShowing,    PUSHBUTTON },
  183. #endif
  184. #ifdef MOZ_MAIL_NEWS
  185.     { xfeCmdOpenFolders,            PUSHBUTTON },
  186.     { xfeCmdOpenAddressBook,        PUSHBUTTON },
  187. #endif
  188.     { "bookmarksSubmenu",    CASCADEBUTTON, bookmark_submenu_spec },
  189.     { xfeCmdOpenHistory,        PUSHBUTTON },
  190. #if JAVA
  191.     { xfeCmdJavaConsole,        PUSHBUTTON },
  192. #endif
  193. #ifndef NO_SECURITY
  194.     { xfeCmdViewSecurity,        PUSHBUTTON },
  195. #endif
  196.     MENU_SEPARATOR,
  197.      { "frameListPlaceHolder",    DYNA_MENUITEMS, NULL, NULL, False, NULL, XFE_FrameListMenu::generate },
  198.     { NULL }
  199. };
  200.  
  201. // Shared between Mail folder/thread/msg
  202. // Is there is a reason why this is here? It's the same as new_menu_spec
  203. MenuSpec XFE_Frame::new_submenu_spec[] = {
  204.   { xfeCmdOpenBrowser,        PUSHBUTTON },
  205. #ifdef MOZ_MAIL_NEWS
  206.   { xfeCmdComposeMessage,    PUSHBUTTON },
  207. #endif
  208. #ifdef EDITOR
  209.   MENU_SEPARATOR,
  210.   MENU_PUSHBUTTON(xfeCmdNewBlank),
  211.   MENU_PUSHBUTTON(xfeCmdNewTemplate),
  212.   MENU_PUSHBUTTON(xfeCmdNewWizard),
  213. #endif
  214.   { NULL }
  215. };
  216.  
  217. #ifdef MOZ_MAIL_NEWS
  218. MenuSpec XFE_Frame::newMsg_submenu_spec[] = {
  219.   { xfeCmdGetNewMessages,    PUSHBUTTON },
  220.   { xfeCmdGetNextNNewMsgs,    PUSHBUTTON },
  221.   MENU_SEPARATOR,
  222.   { xfeCmdSynchWithServer,    PUSHBUTTON },
  223.   // Offline stuff is only happening for Windows
  224.   //MENU_SEPARATOR,
  225.   //{ xfeCmdGetSelectedMessagesForOffline,PUSHBUTTON },
  226.   //{ xfeCmdGetFlaggedMessagesForOffline,    PUSHBUTTON },
  227.   //{ xfeCmdChooseMessagesForOffline,    PUSHBUTTON },
  228.   { NULL }
  229. };
  230. #endif  // MOZ_MAIL_NEWS
  231.  
  232. MenuSpec XFE_Frame::mark_submenu_spec[] = {
  233.     { xfeCmdMarkMessageUnread,    PUSHBUTTON },
  234.     { xfeCmdMarkMessageRead,    PUSHBUTTON },
  235.     { xfeCmdMarkThreadRead,    PUSHBUTTON },
  236.     { xfeCmdMarkAllMessagesRead,    PUSHBUTTON },
  237.     { xfeCmdMarkMessageByDate,    PUSHBUTTON },
  238.     { xfeCmdMarkMessageForLater,    PUSHBUTTON },
  239.     { NULL }
  240. };
  241.  
  242. MenuSpec XFE_Frame::addrbk_submenu_spec[] = {
  243.     { xfeCmdAddSenderToAddressBook,    PUSHBUTTON },
  244.     { xfeCmdAddAllToAddressBook,        PUSHBUTTON },
  245.     //  { xfeCmdAddCardToAddressBook,        PUSHBUTTON } ?
  246.     { NULL }
  247. };
  248.  
  249. MenuSpec XFE_Frame::attachments_submenu_spec[] = {
  250.     { xfeCmdViewAttachmentsInline,    
  251.       TOGGLEBUTTON, NULL, "ThreadViewAttachmentsGroup" },
  252.     { xfeCmdViewAttachmentsAsLinks,    
  253.       TOGGLEBUTTON, NULL, "ThreadViewAttachmentsGroup" },
  254.     { NULL }
  255. };
  256.  
  257. MenuSpec XFE_Frame::sort_submenu_spec[] = {
  258.     { xfeCmdSortByDate,
  259.       TOGGLEBUTTON, NULL, "ThreadViewSortGroup" },
  260.     { xfeCmdSortByFlag,
  261.       TOGGLEBUTTON, NULL, "ThreadViewSortGroup" },
  262.     { xfeCmdSortByPriority,
  263.       TOGGLEBUTTON, NULL, "ThreadViewSortGroup" },
  264.     { xfeCmdSortBySender,
  265.       TOGGLEBUTTON, NULL, "ThreadViewSortGroup" },
  266.     { xfeCmdSortBySize,
  267.       TOGGLEBUTTON, NULL, "ThreadViewSortGroup" },
  268.     { xfeCmdSortByStatus,
  269.       TOGGLEBUTTON, NULL, "ThreadViewSortGroup" },
  270.     { xfeCmdSortBySubject,
  271.       TOGGLEBUTTON, NULL, "ThreadViewSortGroup" },
  272.     { xfeCmdSortByThread,
  273.       TOGGLEBUTTON, NULL, "ThreadViewSortGroup" },
  274.     { xfeCmdSortByUnread,
  275.       TOGGLEBUTTON, NULL, "ThreadViewSortGroup" },
  276.     { xfeCmdSortByMessageNumber,
  277.       TOGGLEBUTTON, NULL, "ThreadViewSortGroup" },
  278.     MENU_SEPARATOR,
  279.     { xfeCmdSortAscending,
  280.       TOGGLEBUTTON, NULL, "ThreadViewSortOrderGroup" },
  281.     { xfeCmdSortDescending,
  282.       TOGGLEBUTTON, NULL, "ThreadViewSortOrderGroup" },
  283.     { NULL }
  284. };
  285.  
  286. MenuSpec XFE_Frame::threads_submenu_spec[] = {
  287.     { xfeCmdViewNew,        
  288.       TOGGLEBUTTON, NULL, "ThreadViewThreadGroup" },
  289.     { xfeCmdViewThreadsWithNew,    
  290.       TOGGLEBUTTON, NULL, "ThreadViewThreadGroup" },
  291.     { xfeCmdViewWatchedThreadsWithNew,    
  292.       TOGGLEBUTTON, NULL, "ThreadViewThreadGroup" },
  293.     { xfeCmdViewAllThreads,        
  294.       TOGGLEBUTTON, NULL, "ThreadViewThreadGroup" },
  295.     MENU_SEPARATOR,
  296.     { xfeCmdToggleKilledThreads, TOGGLEBUTTON },
  297.     { NULL }
  298. };
  299.  
  300. MenuSpec XFE_Frame::headers_submenu_spec[] = {
  301.     { xfeCmdShowAllHeaders,    
  302.       TOGGLEBUTTON, NULL, "ThreadViewHeaderGroup" },
  303.     { xfeCmdShowNormalHeaders,    
  304.       TOGGLEBUTTON, NULL, "ThreadViewHeaderGroup" },
  305.     { xfeCmdShowBriefHeaders,    
  306.       TOGGLEBUTTON, NULL, "ThreadViewHeaderGroup" },
  307.     { NULL }
  308. };
  309.  
  310. MenuSpec XFE_Frame::expand_collapse_submenu_spec[] = {
  311.   { xfeCmdExpand,        PUSHBUTTON },
  312.   { xfeCmdExpandAll,    PUSHBUTTON },
  313.   MENU_SEPARATOR,
  314.   { xfeCmdCollapse,        PUSHBUTTON },
  315.   { xfeCmdCollapseAll,    PUSHBUTTON },
  316.   { NULL }
  317. };
  318.  
  319. // subMenu for edit_
  320. MenuSpec XFE_Frame::select_submenu_spec[] = {
  321.     { xfeCmdSelectThread,            PUSHBUTTON },
  322.     { xfeCmdSelectFlaggedMessages,    PUSHBUTTON },
  323. //    { xfeCmdSelectAllMessages,    PUSHBUTTON },
  324.     { xfeCmdSelectAll,            PUSHBUTTON },
  325.     { NULL }
  326. };
  327.  
  328. MenuSpec XFE_Frame::reply_submenu_spec[] = {
  329.     { xfeCmdReplyToSender,        PUSHBUTTON },
  330.     { xfeCmdReplyToAll,            PUSHBUTTON },
  331.     { xfeCmdReplyToNewsgroup,        PUSHBUTTON },
  332.     { xfeCmdReplyToSenderAndNewsgroup,    PUSHBUTTON },
  333.     { NULL }
  334. };
  335.  
  336. MenuSpec XFE_Frame::compose_message_submenu_spec[] = {
  337.     { xfeCmdComposeMessagePlain,        PUSHBUTTON },
  338.     { xfeCmdComposeMessageHTML,        PUSHBUTTON },
  339.     { NULL }
  340. };
  341.  
  342. MenuSpec XFE_Frame::compose_article_submenu_spec[] = {
  343.     { xfeCmdComposeArticlePlain,        PUSHBUTTON },
  344.     { xfeCmdComposeArticleHTML,        PUSHBUTTON },
  345.     { NULL }
  346. };
  347.  
  348. MenuSpec XFE_Frame::next_submenu_spec[] = {
  349.     { xfeCmdNextMessage,            PUSHBUTTON },
  350.     { xfeCmdNextUnreadMessage,        PUSHBUTTON },
  351.     { xfeCmdNextFlaggedMessage,        PUSHBUTTON },
  352.     { xfeCmdNextUnreadThread,        PUSHBUTTON },
  353.     { xfeCmdNextCollection,            PUSHBUTTON },
  354.     { xfeCmdNextUnreadCollection,     PUSHBUTTON },
  355.     { NULL }
  356. };
  357.  
  358. // Encoding Menu Spec - shared between Browsers, and Mail/News
  359. MenuSpec XFE_Frame::encoding_menu_spec[] = {
  360.     { xfeCmdChangeDocumentEncoding,    TOGGLEBUTTON, NULL, "EncodingRadioGroup", False, (void*)CS_LATIN1 },
  361.     MENU_SEPARATOR,
  362.     { xfeCmdChangeDocumentEncoding,    TOGGLEBUTTON, NULL, "EncodingRadioGroup", False, (void*)CS_LATIN2 },
  363.     { xfeCmdChangeDocumentEncoding,    TOGGLEBUTTON, NULL, "EncodingRadioGroup", False, (void*)CS_CP_1250 },
  364.     MENU_SEPARATOR,
  365.     { xfeCmdChangeDocumentEncoding,    TOGGLEBUTTON, NULL, "EncodingRadioGroup", False, (void*)CS_EUCJP_AUTO },
  366.     { xfeCmdChangeDocumentEncoding,    TOGGLEBUTTON, NULL, "EncodingRadioGroup", False, (void*)CS_SJIS },
  367.     { xfeCmdChangeDocumentEncoding,    TOGGLEBUTTON, NULL, "EncodingRadioGroup", False, (void*)CS_EUCJP },
  368.     MENU_SEPARATOR,
  369.     { xfeCmdChangeDocumentEncoding,    TOGGLEBUTTON, NULL, "EncodingRadioGroup", False, (void*)CS_BIG5 },
  370.     { xfeCmdChangeDocumentEncoding,    TOGGLEBUTTON, NULL, "EncodingRadioGroup", False, (void*)CS_CNS_8BIT },
  371.     MENU_SEPARATOR,
  372.     { xfeCmdChangeDocumentEncoding,    TOGGLEBUTTON, NULL, "EncodingRadioGroup", False, (void*)CS_GB_8BIT },
  373.     MENU_SEPARATOR,
  374.     { xfeCmdChangeDocumentEncoding,    TOGGLEBUTTON, NULL, "EncodingRadioGroup", False, (void*)CS_KSC_8BIT_AUTO },
  375.     MENU_SEPARATOR,
  376.     { xfeCmdChangeDocumentEncoding,    TOGGLEBUTTON, NULL, "EncodingRadioGroup", False, (void*)CS_8859_5 },
  377.     { xfeCmdChangeDocumentEncoding,    TOGGLEBUTTON, NULL, "EncodingRadioGroup", False, (void*)CS_KOI8_R },
  378.     { xfeCmdChangeDocumentEncoding,    TOGGLEBUTTON, NULL, "EncodingRadioGroup", False, (void*)CS_CP_1251 },
  379.     MENU_SEPARATOR,
  380.     { xfeCmdChangeDocumentEncoding,    TOGGLEBUTTON, NULL, "EncodingRadioGroup", False, (void*)CS_8859_7 },
  381.     { xfeCmdChangeDocumentEncoding,    TOGGLEBUTTON, NULL, "EncodingRadioGroup", False, (void*)CS_CP_1253 },
  382.     MENU_SEPARATOR,
  383.     { xfeCmdChangeDocumentEncoding,    TOGGLEBUTTON, NULL, "EncodingRadioGroup", False, (void*)CS_8859_9 },
  384.     MENU_SEPARATOR,
  385.     { xfeCmdChangeDocumentEncoding,    TOGGLEBUTTON, NULL, "EncodingRadioGroup", False, (void*)CS_UTF8 },
  386.     { xfeCmdChangeDocumentEncoding,    TOGGLEBUTTON, NULL, "EncodingRadioGroup", False, (void*)CS_UTF7 },
  387.     MENU_SEPARATOR,
  388.     { xfeCmdChangeDocumentEncoding,    TOGGLEBUTTON, NULL, "EncodingRadioGroup", False, (void*)CS_USRDEF2 },
  389.     MENU_SEPARATOR,
  390.     { xfeCmdSetDefaultDocumentEncoding,    PUSHBUTTON },
  391.     { NULL }
  392. };
  393.  
  394. #define STR_GEN(n) "menu.help.item_" # n
  395.  
  396. MenuSpec XFE_Frame::help_menu_spec[] = {
  397.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(0)},
  398.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(1)},
  399.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(2)},
  400.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(3)},
  401.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(4)},
  402.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(5)},
  403.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(6)},
  404.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(7)},
  405.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(8)},
  406.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(9)},
  407.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(10)},
  408.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(11)},
  409.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(12)},
  410.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(13)},
  411.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(14)},
  412.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(15)},
  413.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(16)},
  414.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(17)},
  415.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(18)},
  416.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(19)},
  417.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(20)},
  418.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(21)},
  419.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(22)},
  420.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(23)},
  421.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(24)},
  422. #ifdef MOZ_COMMUNICATOR_ABOUT
  423.     MENU_PUSHBUTTON(xfeCmdAboutNetscape),
  424. #else
  425.     MENU_PUSHBUTTON(xfeCmdAboutMozilla),
  426. #endif
  427. #ifdef MOZILLA_GPROF
  428.     MENU_SEPARATOR,
  429.     { xfeCmdProfileStatus,     LABEL },
  430.     MENU_SEPARATOR,
  431.     { xfeCmdProfileStart,      PUSHBUTTON },
  432.     { xfeCmdProfileStop,       PUSHBUTTON },
  433.     { xfeCmdProfileReset,      PUSHBUTTON },
  434.     MENU_SEPARATOR,
  435.     { xfeCmdProfileOrder,  TOGGLEBUTTON, NULL, "profileRadio", 0, 0, 0,
  436.       xfeCmdProfileOrder, { "flatFirst" } },
  437.     { xfeCmdProfileOrder,  TOGGLEBUTTON, NULL, "profileRadio", 0, 0, 0,
  438.       xfeCmdProfileOrder, { "graphFirst" } },
  439.     MENU_SEPARATOR,
  440.     { xfeCmdProfileSize,  TOGGLEBUTTON, NULL, "profileRadio", 0, 0, 0,
  441.       xfeCmdProfileSize, { "10" } },
  442.     { xfeCmdProfileSize,  TOGGLEBUTTON, NULL, "profileRadio", 0, 0, 0,
  443.       xfeCmdProfileSize, { "100" } },
  444.     { xfeCmdProfileSize,  TOGGLEBUTTON, NULL, "profileRadio", 0, 0, 0,
  445.       xfeCmdProfileSize, { "0" } },
  446.     MENU_SEPARATOR,
  447.     { xfeCmdProfileHtmlReport, PUSHBUTTON },
  448. #endif /*MOZILLA_GPROF*/
  449.     { NULL }
  450. };
  451.  
  452. #undef STR_GEN
  453. #define STR_GEN(n) "menu.places.item_" # n
  454.  
  455. MenuSpec XFE_Frame::places_menu_spec[] = {
  456.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(0)},
  457.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(1)},
  458.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(2)},
  459.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(3)},
  460.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(4)},
  461.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(5)},
  462.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(6)},
  463.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(7)},
  464.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(8)},
  465.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(9)},
  466.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(10)},
  467.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(11)},
  468.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(12)},
  469.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(13)},
  470.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(14)},
  471.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(15)},
  472.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(16)},
  473.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(17)},
  474.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(18)},
  475.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(19)},
  476.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(20)},
  477.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(21)},
  478.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(22)},
  479.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(23)},
  480.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(24)},
  481.     { NULL }
  482. };
  483.  
  484. #undef STR_GEN
  485. #define STR_GEN(n) "toolbar.places.item_" # n
  486.  
  487. MenuSpec XFE_Frame::tb_places_menu_spec[] = {
  488.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(0)},
  489.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(1)},
  490.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(2)},
  491.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(3)},
  492.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(4)},
  493.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(5)},
  494.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(6)},
  495.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(7)},
  496.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(8)},
  497.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(9)},
  498.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(10)},
  499.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(11)},
  500.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(12)},
  501.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(13)},
  502.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(14)},
  503.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(15)},
  504.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(16)},
  505.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(17)},
  506.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(18)},
  507.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(19)},
  508.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(20)},
  509.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(21)},
  510.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(22)},
  511.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(23)},
  512.     {xfeCmdOpenCustomUrl, CUSTOMBUTTON, NULL, NULL, False, STR_GEN(24)},
  513.     { NULL }
  514. };
  515.  
  516. // - End of Shared MenuSpec
  517.  
  518. const char *XFE_Frame::beforeDestroyCallback = "XFE_Frame::beforeDestroyCallback";
  519. const char *XFE_Frame::userActivityHere = "XFE_Frame::userActivityHere";
  520. const char *XFE_Frame::encodingChanged = "XFE_Frame::encodingChanged";
  521. const char *XFE_Frame::allConnectionsCompleteCallback = "XFE_Frame::allConnectionsCompleteCallback";
  522.  
  523. // Progress bar cylon notifications
  524. const char * XFE_Frame::progressBarCylonStart = "XFE_Frame::progressBarCylonStart";
  525. const char * XFE_Frame::progressBarCylonStop = "XFE_Frame::progressBarCylonStop";
  526. const char * XFE_Frame::progressBarCylonTick = "XFE_Frame::progressBarCylonTick";
  527.  
  528. // Progress bar percentage notifications
  529. const char * XFE_Frame::progressBarUpdatePercent = "XFE_Frame::progressBarUpdatePercent";
  530. const char * XFE_Frame::progressBarUpdateText = "XFE_Frame::progressBarUpdateText";
  531.  
  532. // Logo animation notifications
  533. const char * XFE_Frame::logoStartAnimation = "XFE_Frame::logoStartAnimation";
  534. const char * XFE_Frame::logoStopAnimation = "XFE_Frame::logoStopAnimation";
  535.  
  536. const char* XFE_Frame::frameBusyCallback = "XFE_Frame::frameBusyCallback";
  537. const char* XFE_Frame::frameNotBusyCallback = "XFE_Frame::frameNotBusyCallback";
  538.  
  539. // Forward decl:
  540. static void resizeHandler(Widget, XtPointer, XEvent *, Boolean *);
  541.  
  542. static XFE_CommandList* my_commands;
  543.  
  544. XFE_Command*
  545. XFE_Frame::getCommand(CommandType cmd)
  546. {
  547.     return findCommand(my_commands, cmd);
  548. }
  549.  
  550. #ifdef MOZILLA_GPROF
  551. //
  552. //    I18N people: please don't bug me about hard coded string in here,
  553. //    it's all for internal profiling use. ...djw 05/25/1997
  554. //
  555. class ProfileStatusCommand : public XFE_FrameCommand
  556. {
  557. public:
  558.     ProfileStatusCommand() : XFE_FrameCommand(xfeCmdProfileStatus) {};
  559.  
  560.     char*   getLabel(XFE_Frame*, XFE_CommandInfo*) {
  561.         if (gmon_is_running())
  562.             return "Profile monitor running";
  563.         else
  564.             return "Profile monitor stopped";
  565.     }
  566.     void    doCommand(XFE_Frame*, XFE_CommandInfo*) {}
  567. };
  568.  
  569. class ProfileStartCommand : public XFE_FrameCommand
  570. {
  571. public:
  572.     ProfileStartCommand() : XFE_FrameCommand(xfeCmdProfileStart) {};
  573.  
  574.     char*   getLabel(XFE_Frame*, XFE_CommandInfo*) {
  575.         if (gmon_is_running())
  576.             return "Restart profile monitor";
  577.         else
  578.             return "Start profile monitor";
  579.     }
  580.     void    doCommand(XFE_Frame*, XFE_CommandInfo*) {
  581.         gmon_start();
  582.     }
  583. };
  584.  
  585. class ProfileStopCommand : public XFE_FrameCommand
  586. {
  587. public:
  588.     ProfileStopCommand() : XFE_FrameCommand(xfeCmdProfileStop) {};
  589.  
  590.     XP_Bool isEnabled(XFE_Frame*, XFE_CommandInfo*) {
  591.         return gmon_is_running();
  592.     }
  593.     char*   getLabel(XFE_Frame*, XFE_CommandInfo*) {
  594.         return "Stop profile monitor";
  595.     }
  596.     void    doCommand(XFE_Frame*, XFE_CommandInfo*) {
  597.         gmon_stop();
  598.     }
  599. };
  600.  
  601. class ProfileResetCommand : public XFE_FrameCommand
  602. {
  603. public:
  604.     ProfileResetCommand() : XFE_FrameCommand(xfeCmdProfileReset) {};
  605.  
  606.     char*   getLabel(XFE_Frame*, XFE_CommandInfo*) {
  607.         return "Reset profile data";
  608.     }
  609.     void    doCommand(XFE_Frame*, XFE_CommandInfo*) {
  610.         if (gmon_is_running())
  611.             gmon_stop();
  612.         gmon_reset();
  613.     }
  614. };
  615.  
  616. class ProfileOrderCommand : public XFE_FrameCommand
  617. {
  618. public:
  619.     ProfileOrderCommand() : XFE_FrameCommand(xfeCmdProfileOrder) {};
  620.  
  621.     XP_Bool isSelected(XFE_Frame*, XFE_CommandInfo* info) {
  622.         unsigned match = False;
  623.         if (info != NULL &&    *info->nparams > 0
  624.             &&
  625.             XP_STRCMP(info->params[0], "flatFirst") == 0) {
  626.             match = True;
  627.         }
  628.         return (gmon_report_get_reverse() == match);
  629.     }
  630.     char*   getLabel(XFE_Frame*, XFE_CommandInfo* info) {
  631.         if (info != NULL &&    *info->nparams > 0
  632.             &&
  633.             XP_STRCMP(info->params[0], "flatFirst") == 0) {
  634.             return "Flat Data then Graph Data";
  635.         } else {
  636.             return "Graph Data then Flat Data";
  637.         }
  638.     }
  639.     void    doCommand(XFE_Frame*, XFE_CommandInfo* info) {
  640.         XP_Bool match = False;
  641.         if (info != NULL &&    *info->nparams > 0
  642.             &&
  643.             XP_STRCMP(info->params[0], "flatFirst") == 0) {
  644.             match = True;
  645.         }
  646.         gmon_report_set_reverse(match);
  647.     }
  648. };
  649.  
  650. static char profile_size_label_buf[256];
  651.  
  652. class ProfileSizeCommand : public XFE_FrameCommand
  653. {
  654. public:
  655.     ProfileSizeCommand() : XFE_FrameCommand(xfeCmdProfileSize) {};
  656.  
  657.     XP_Bool isSelected(XFE_Frame*, XFE_CommandInfo* info) {
  658.         unsigned state = gmon_report_get_size();
  659.         unsigned match = 0;
  660.         if (info != NULL &&    *info->nparams > 0) {
  661.             match = atoi(info->params[0]);
  662.         }
  663.  
  664.         return (state == match);
  665.     }
  666.     char*   getLabel(XFE_Frame*, XFE_CommandInfo* info) {
  667.         unsigned match = 0;
  668.         if (info != NULL &&    *info->nparams > 0) {
  669.             match = atoi(info->params[0]);
  670.         }
  671.  
  672.         if (match == 0)
  673.             XP_STRCPY(profile_size_label_buf, "Report All Functions");
  674.         else 
  675.             sprintf(profile_size_label_buf, "Report Top %d Functions", match);
  676.  
  677.         return profile_size_label_buf;
  678.     }
  679.     void    doCommand(XFE_Frame*, XFE_CommandInfo* info) {
  680.         unsigned match = 0;
  681.         if (info != NULL &&    *info->nparams > 0) {
  682.             match = atoi(info->params[0]);
  683.         }
  684.         gmon_report_set_size(match);
  685.     }
  686. };
  687.  
  688. static int
  689. gmon_do_html_report(XFE_Frame* frame)
  690. {
  691.     char* gmon_out = NULL;
  692.     char* gprof_out = NULL;
  693.     char* html_out = NULL;
  694.     int rv = 0;
  695.     MWContext* context = frame->getContext();
  696.     Widget     widget = frame->getBaseWidget();
  697.  
  698.     if (gmon_is_running())
  699.         gmon_stop();
  700.  
  701.     if ((gmon_out = tempnam(NULL, "gmon")) == NULL) {
  702.         fprintf(stderr, "could not create tmp file: ");
  703.         perror(NULL);
  704.         return -1;
  705.     }
  706.  
  707.     if ((gprof_out = tempnam(NULL, "gprof")) == NULL) {
  708.         fprintf(stderr, "could not create tmp file: ");
  709.         perror(NULL);
  710.         rv = -1;
  711.         goto return_point;
  712.     }
  713.  
  714.     if ((html_out = (char*)malloc(strlen(gprof_out) + 6)) == NULL) {
  715.         fprintf(stderr, "out of memory: ");
  716.         perror(NULL);
  717.         rv = -1;
  718.         goto return_point;
  719.     }
  720.     strcpy(html_out, gprof_out);
  721.     strcat(html_out, ".html");
  722.  
  723.     /*
  724.      *    Dump gmon.out
  725.      */
  726.     XFE_Progress(context, "dumping profile monitor data..");
  727.     XmUpdateDisplay(widget);
  728.     gmon_dump_to(gmon_out);
  729.  
  730.     XFE_Progress(context, "running gprof..");
  731.     XmUpdateDisplay(widget);
  732.     if (gmon_gprof_to(gmon_out, gprof_out, gmon_report_get_size()) == -1) {
  733.         rv = -1;
  734.         goto return_point;
  735.     }
  736.     unlink(gmon_out);
  737.  
  738.     XFE_Progress(context, "building html output..");
  739.     XmUpdateDisplay(widget);
  740.     if (gmon_html_filter_to(gprof_out, html_out,
  741.                             gmon_report_get_reverse()) == -1) {
  742.         rv = -1;
  743.         goto return_point;
  744.     }
  745.     unlink(gprof_out);
  746.  
  747.     XFE_Progress(context, "loading html report..");
  748.     XmUpdateDisplay(widget);
  749.     FE_GetURL(context, NET_CreateURLStruct(html_out, NET_DONT_RELOAD));
  750.  
  751. return_point:
  752.     if (gmon_out != NULL) {
  753.         unlink(gmon_out);
  754.         free(gmon_out);
  755.     }
  756.     if (gprof_out != NULL) {
  757.         unlink(gprof_out);
  758.         free(gprof_out);
  759.     }
  760.  
  761.     if (html_out != NULL) {
  762.         if (rv != 0)
  763.             unlink(html_out);
  764.         free(html_out);
  765.     }
  766.  
  767.     return rv;
  768. }
  769.  
  770. class ProfileHtmlReportCommand : public XFE_FrameCommand
  771. {
  772. public:
  773.     ProfileHtmlReportCommand() : XFE_FrameCommand(xfeCmdProfileHtmlReport) {};
  774.  
  775.     char*   getLabel(XFE_Frame*, XFE_CommandInfo*) {
  776.         return "Make Html Report";
  777.     }
  778.     void    doCommand(XFE_Frame* frame, XFE_CommandInfo*) {
  779.  
  780.         gmon_do_html_report(frame);
  781.     }
  782. };
  783.  
  784. #endif /*MOZILLA_GPROF*/
  785.  
  786. XFE_Frame::XFE_Frame(char *name,
  787.                      Widget toplevel,
  788.                      XFE_Frame *parent_frame,
  789.                      EFrameType frametype,
  790.                      Chrome *chromespec,
  791.                      XP_Bool haveHTMLDisplay,
  792.                      XP_Bool haveMenuBar,
  793.                      XP_Bool haveToolbars,
  794.                      XP_Bool haveDashboard,
  795.                      XP_Bool destroyOnClose) : XFE_Component()
  796. {
  797.         D(      printf ("in XFE_Frame::XFEFrame()\n");)
  798.  
  799.     // as good a place as any to get the colormap machinery going.
  800.     fe_startDisplayFactory(toplevel);
  801.     
  802.     m_toplevelWidget    = toplevel;
  803.     m_frametype            = frametype;
  804.     m_destroyOnClose    = destroyOnClose;
  805.     m_context            = NULL;
  806.     m_toolbar            = NULL;
  807.     m_toolbox            = NULL;
  808.     m_activeLogo        = NULL;
  809.  
  810. #ifdef NETCASTER_ZAXIS_HACKERY
  811.     m_zaxis_BelowHandlerInstalled = False;
  812.     m_zaxis_AboveHandlerInstalled = False;
  813. #endif
  814.  
  815.     // Remember if a chromespec is provided to the constructor so that we 
  816.     // can later ignore the user's toolbox and geometry preferences.
  817.     m_chromespec_provided = (chromespec != NULL);
  818.     m_first_showing = True;
  819.  
  820.     m_parentframe = parent_frame;
  821.  
  822.     if (!chromespec) {
  823.       //
  824.       // default values for chromespec-related members
  825.       //
  826.       m_allowresize = True;
  827.       m_hotkeysdisabled = False;
  828.       m_iswmclosable = True;
  829.       m_ismodal     = False;
  830.       m_topmost     = False;
  831.       m_bottommost  = False;
  832.       m_zlock       = False;
  833.       m_lhint        = 0;
  834.       m_thint        = 0;
  835.     }
  836.     else {
  837.       m_allowresize = chromespec->allow_resize;
  838.       m_iswmclosable = chromespec->allow_close;
  839.       if (chromespec->is_modal && m_parentframe)
  840.         m_ismodal = True;
  841.       else
  842.         m_ismodal = False;
  843.       m_topmost     = chromespec->topmost;
  844.       m_bottommost  = chromespec->bottommost;
  845.       m_zlock       = chromespec->z_lock;
  846.       m_hotkeysdisabled = chromespec->disable_commands;
  847.  
  848.       D(printf ("lhint = %d, thint = %d\n", chromespec->l_hint, chromespec->t_hint);)
  849.       m_lhint        = chromespec->l_hint;
  850.       m_thint        = chromespec->t_hint;
  851.  
  852.       D(printf ("Hot keys are %s.\n", m_hotkeysdisabled ? "disabled" : "enabled");)
  853.     }
  854.  
  855.     geometryPrefName = 0;
  856.  
  857.     m_haveHTMLDisplay = haveHTMLDisplay;
  858.  
  859.     createShellAndChromeParent(name, toplevel);
  860.  
  861.     // XXXX
  862.     // now we do all the funky MWContext stuff.
  863.     initializeMWContext(m_frametype);
  864.     ViewGlue_addMapping(this, m_context);
  865.  
  866.     // Initialize this after the context
  867.     // This is used by fe_FindNonCustomBrowserContext()
  868.     CONTEXT_DATA(m_context)->hasCustomChrome = m_chromespec_provided;
  869.     if (m_chromespec_provided)
  870.       m_context->restricted_target=chromespec->restricted_target;
  871.  
  872.     if (haveDashboard)
  873.         {
  874.             m_dashboard = new XFE_Dashboard(this, getChromeParent(), this);
  875.  
  876.             if (!chromespec || (chromespec && chromespec->show_bottom_status_bar))
  877.                 m_dashboard->show();
  878.  
  879.         }
  880.     else
  881.         m_dashboard = NULL;
  882.  
  883.     // The main form holds the toolbox, m_viewparent and possibly 
  884.     // the above_view component.  This new component is necessary to
  885.     // avoid all the annoying problems with toolbars dissapearing.
  886.     m_mainform = XtVaCreateManagedWidget("mainForm",
  887.                                          xmFormWidgetClass,
  888.                                          m_chromeparent, 
  889.                                          XmNleftAttachment, XmATTACH_FORM,
  890.                                          XmNrightAttachment, XmATTACH_FORM,
  891.                                          NULL);
  892.     
  893.     m_viewparent = XtVaCreateManagedWidget("viewParent",
  894.                                            xmFormWidgetClass,
  895.                                            m_mainform,
  896.                                             XmNleftAttachment, XmATTACH_FORM,
  897.                                             XmNrightAttachment, XmATTACH_FORM,
  898.                                             XmNtopAttachment, XmATTACH_FORM,
  899.                                             XmNbottomAttachment, XmATTACH_FORM,
  900.                                            NULL);
  901.     
  902.     if (chromespec)
  903.         {
  904.             m_chrome_close_callback = chromespec->close_callback;
  905.             m_chrome_close_arg = chromespec->close_arg;
  906.         }
  907.     else
  908.         {
  909.             m_chrome_close_callback = NULL;
  910.         }
  911.  
  912.     if (haveMenuBar)
  913.         {
  914.             m_menubar = new XFE_MenuBar(this, NULL);
  915.             
  916.             if (!chromespec || (chromespec && chromespec->show_menu))
  917.                 m_menubar->show();
  918.         }
  919.     else
  920.         {
  921.             m_menubar = NULL;
  922.         }
  923.  
  924.     XP_Bool needNavigationToolbar = False;
  925.     XP_Bool needToolbox = False;
  926.  
  927.     // Determine if we need navigation toolbars
  928.     if (chromespec && chromespec->show_button_bar)
  929.     {
  930.         needNavigationToolbar = True;
  931.     }
  932.     else
  933.     {
  934.         needNavigationToolbar = haveToolbars;
  935.     }
  936.  
  937.     //
  938.     // show_url_bar and show_directory_buttons determine whether the url bar
  939.     // and personal toolbar are shown.  These components will be created in
  940.     // the XFE_BrowserFrame class.  Since the toolbox is created here
  941.     // we need to take these into account even though (in theory) this class
  942.     // should know nothing about its subclasses...
  943.     //
  944.  
  945.     // Determine if we need a toolbox
  946.     if (chromespec && (chromespec->show_url_bar || 
  947.                        chromespec->show_directory_buttons))
  948.     {
  949.         needToolbox = True;
  950.     }
  951.     else
  952.     {
  953.         needToolbox = needNavigationToolbar;
  954.     }
  955.  
  956.     // Create the toolbox if needed
  957.     if (needToolbox)
  958.     {
  959.         // Create the toolbox as a child of the main form
  960.         m_toolbox = new XFE_Toolbox(this,m_mainform);
  961.  
  962.         // I was having trouble with the frame geomtry because of the
  963.         // dynamic nature of the toolbox (ie, collapsing toolbars) so
  964.         // i had to add this function which takes care of all the 
  965.         // layout for the main form, toolbox and possibly the above_view
  966.         // component.
  967.         //
  968.         // This function installs the event handers and callbacks needed
  969.         // to support the this.  There is probably a more sane way of 
  970.         // accomplishing this, bug we ran out of time for 4.x and
  971.         // this works.
  972.         XfeToolBoxAddLayoutSupport(m_mainform,m_toolbox->getBaseWidget());
  973.         
  974.         // Notify when a toolbox item is snapped in place
  975.         m_toolbox->registerInterest(
  976.             XFE_Toolbox::toolbarSnap,
  977.             this,
  978.             (XFE_FunctionNotification)toolboxSnapNotice_cb);
  979.         
  980.         // Notify when a toolbox item is swapped in place
  981.         m_toolbox->registerInterest(
  982.             XFE_Toolbox::toolbarSwap,
  983.             this,
  984.             (XFE_FunctionNotification)toolboxSwapNotice_cb);
  985.  
  986.         // Notify when a toolbox item is closed
  987.         m_toolbox->registerInterest(
  988.             XFE_Toolbox::toolbarClose,
  989.             this,
  990.             (XFE_FunctionNotification)toolboxCloseNotice_cb);
  991.         
  992.         // Notify when a toolbox item is opened
  993.         m_toolbox->registerInterest(
  994.             XFE_Toolbox::toolbarOpen,
  995.             this,
  996.             (XFE_FunctionNotification)toolboxOpenNotice_cb);
  997.         
  998.         // Always show the toolbox
  999.         m_toolbox->show();
  1000.     }    
  1001.     else
  1002.     {
  1003.         m_toolbox = NULL;
  1004.     }
  1005.  
  1006.     // Create the navigation toolbox if needed
  1007.     if (needNavigationToolbar)
  1008.     {
  1009.         // Create the toolbar 
  1010.         m_toolbar = new XFE_Toolbar(this,m_toolbox,NULL);
  1011.  
  1012.         // chromespec takes precedence over prefs
  1013.         if (chromespec && chromespec->show_button_bar)
  1014.         {
  1015.             m_toolbar->show();
  1016.         }
  1017.     }
  1018.     else
  1019.     {
  1020.         m_toolbar = NULL;
  1021.     }
  1022.  
  1023.     // If a chromespec is given and all 3 toolbars are off, then we need
  1024.     // to unmanage the toolbox.  Otherwise the Frame's expect geometry 
  1025.     // will be wrong.
  1026.     if (chromespec)
  1027.     {
  1028.         if (!chromespec->show_button_bar && 
  1029.             !chromespec->show_url_bar && 
  1030.             !chromespec->show_directory_buttons)
  1031.         {
  1032.             if (m_toolbox)
  1033.                 m_toolbox->hide();
  1034.         }
  1035.     }
  1036.  
  1037.     m_aboveview = NULL;
  1038.     m_view = NULL;
  1039.     m_belowview = NULL;
  1040.  
  1041.     m_attachmentsNeeded = True;
  1042.     
  1043.     if (needNavigationToolbar) 
  1044.     {
  1045.         m_toolbar->registerInterest(Command::doCommandCallback,
  1046.                                     this,
  1047.                                     doCommandCallback_cb);
  1048.         
  1049.         // Register the logo animation notifications with ourselves
  1050.         registerInterest(XFE_Frame::logoStartAnimation,
  1051.                          this,
  1052.                          logoAnimationStartNotice_cb);
  1053.         
  1054.         registerInterest(XFE_Frame::logoStopAnimation,
  1055.                          this,
  1056.                          logoAnimationStopNotice_cb);
  1057.     }
  1058.     
  1059.     XFE_MozillaApp::theApp()->registerInterest(XFE_MozillaApp::changeInToplevelFrames,
  1060.                                                this,
  1061.                                                (XFE_FunctionNotification)toplevelWindowChangeOccured_cb);
  1062.  
  1063.     XFE_MozillaApp::theApp()->registerFrame(this);
  1064.     
  1065.     /* XXXM12N Create and initialize the Image Library JMC callback
  1066.        interface.  Also create a new IL_GroupContext for this window.*/
  1067.     if (!fe_init_image_callbacks(m_context))
  1068.         {
  1069.             return; // XXXX how do we deal with errors here?
  1070.         }
  1071.     
  1072.     fe_InitColormap (m_context);
  1073.  
  1074.     // Reset the delete handler, and add a WM callback
  1075.     XtVaSetValues(m_widget,
  1076.                   XmNdeleteResponse, XmDO_NOTHING,
  1077.                   NULL);
  1078.  
  1079.     XmAddWMProtocolCallback(m_widget,
  1080.                             XmInternAtom(XtDisplay(m_widget), "WM_DELETE_WINDOW", False),
  1081.                             delete_response, this);
  1082.  
  1083.     if (!my_commands) {
  1084. #ifdef MOZILLA_GPROF
  1085.         registerCommand(my_commands, new ProfileStatusCommand);
  1086.         registerCommand(my_commands, new ProfileStartCommand);
  1087.         registerCommand(my_commands, new ProfileStopCommand);
  1088.         registerCommand(my_commands, new ProfileResetCommand);
  1089.         registerCommand(my_commands, new ProfileOrderCommand);
  1090.         registerCommand(my_commands, new ProfileSizeCommand);
  1091.         registerCommand(my_commands, new ProfileHtmlReportCommand);
  1092. #endif /*MOZILLA_GPROF*/
  1093.     }
  1094.  
  1095.     D(    printf ("leaving XFE_Frame::XFEFrame()\n");)
  1096. }
  1097.  
  1098. XFE_Frame::~XFE_Frame()
  1099. {
  1100.     D(    printf ("in XFE_Frame::~XFEFrame()\n");)
  1101.  
  1102.     if (m_ismodal 
  1103.         && m_parentframe 
  1104.         && fe_IsContextProtected(m_parentframe->getContext()))
  1105.       {
  1106.         fe_UnProtectContext(m_parentframe->getContext());
  1107.         if (fe_IsContextDestroyed(m_parentframe->getContext()))
  1108.           {
  1109.             D(printf ("The parent frame's context 0x%x was marked deleted,"
  1110.                       " so I'm deleting it now.\n",
  1111.                       m_parentframe->getContext());)
  1112.              m_parentframe->delete_response();
  1113.              m_parentframe = NULL;
  1114.           }
  1115.         else
  1116.           {
  1117.             D(printf ("The parent frame's context 0x%x wasn't marked deleted,"
  1118.                       " so I'm letting it hang around.\n",
  1119.                       m_parentframe->getContext());)
  1120.           }
  1121.       }
  1122.  
  1123.     // delete our menubar.
  1124.     if (m_menubar)
  1125.         {
  1126.             delete m_menubar;
  1127.             m_menubar = NULL;
  1128.         }
  1129.     
  1130.     // delete the above view area.
  1131.     if (m_aboveview)
  1132.         {
  1133.             delete m_aboveview;
  1134.             m_aboveview = NULL;
  1135.         }
  1136.     
  1137.     // delete the below view area.
  1138.     if (m_belowview)
  1139.         {
  1140.             delete m_belowview;
  1141.             m_belowview = NULL;
  1142.         }
  1143.     
  1144.     // delete the view itself.
  1145.     if (m_view)
  1146.         {
  1147.             delete m_view;
  1148.             
  1149.             m_view = NULL;
  1150.         }
  1151.     
  1152.     if (m_context)
  1153.         {
  1154.             PRBool observer_removed_p;
  1155.  
  1156.             if (m_context->color_space) {
  1157.                 IL_ReleaseColorSpace(m_context->color_space);
  1158.                 m_context->color_space = NULL;
  1159.             }
  1160.  
  1161.             /* Destroy the image group context after removing the image
  1162.                group observer. */
  1163.             observer_removed_p =
  1164.                 IL_RemoveGroupObserver(m_context->img_cx,
  1165.                                        fe_ImageGroupObserver,
  1166.                                        (void *)m_context);
  1167.  
  1168.             IL_DestroyGroupContext(m_context->img_cx);
  1169.             m_context->img_cx = NULL;
  1170.             
  1171.             if (m_haveHTMLDisplay)
  1172.                 SHIST_EndSession (m_context);
  1173.             
  1174.             /* Destroy the compositor associated with the context. */
  1175.             if (m_context->compositor)
  1176.                 {
  1177.                     CL_DestroyCompositor(m_context->compositor);
  1178.                     m_context->compositor = NULL;
  1179.                 }
  1180.             
  1181. #ifdef MOZ_MAIL_NEWS
  1182.             MimeDestroyContextData(m_context);
  1183. #endif
  1184.  
  1185.             if (m_context->title) free (m_context->title);
  1186.             m_context->title = 0;
  1187.  
  1188.  
  1189.             free (CONTEXT_DATA (m_context));
  1190.             free (m_context);
  1191.         }
  1192.  
  1193.     //
  1194.     //    This must be called last, as it may start the exit sequence,
  1195.     //    and never return.
  1196.     //
  1197.     XFE_MozillaApp::theApp()->unregisterFrame(this);
  1198. }
  1199.  
  1200. void
  1201. XFE_Frame::createShellAndChromeParent(char *name, Widget parent)
  1202. {
  1203.     Arg av[20];
  1204.     int ac;
  1205.     Widget shell;
  1206.  
  1207.     ac = 0;
  1208.     
  1209.     XtSetArg (av[ac], XmNvisual, XFE_DisplayFactory::theFactory()->getVisual()); ac++;
  1210.     XtSetArg (av[ac], XmNdepth, XFE_DisplayFactory::theFactory()->getVisualDepth()); ac++;
  1211.     
  1212.     if (m_haveHTMLDisplay)
  1213.         {
  1214.             /* we only need our own colormap if we're displaying html */
  1215.             m_cmap = XFE_DisplayFactory::theFactory()->getPrivateColormap();
  1216.             
  1217.             XtSetArg (av[ac], XmNcolormap, fe_getColormap(m_cmap)); ac++;
  1218.         }
  1219.     else
  1220.         {
  1221.             m_cmap = XFE_DisplayFactory::theFactory()->getSharedColormap();
  1222.             
  1223.             XtSetArg (av[ac], XmNcolormap, fe_getColormap(m_cmap)); ac++;
  1224.         }
  1225.     
  1226.     XtSetArg (av[ac], XmNallowShellResize, False); ac++;
  1227.  
  1228.  
  1229.     if (m_ismodal && m_parentframe)
  1230.         {
  1231.             XtSetArg (av[ac], XmNdialogType, XmDIALOG_PROMPT); ac++;
  1232.             XtSetArg (av[ac], XmNautoUnmanage, False); ac++;
  1233.             XtSetArg (av[ac], XmNborderWidth, 0); ac++;
  1234.  
  1235.             XtSetArg (av[ac], XmNautoUnmanage, False); ac++;
  1236.             XtSetArg (av[ac], XmNmarginWidth, 0); ac++;
  1237.             XtSetArg (av[ac], XmNmarginHeight, 0); ac++;
  1238.             XtSetArg (av[ac], XmNdialogStyle, XmDIALOG_PRIMARY_APPLICATION_MODAL); ac++;
  1239.  
  1240.             XtSetArg (av[ac], XmNnoResize, !m_allowresize); ac++;
  1241.             XtSetArg (av[ac], XmNresizePolicy, XmRESIZE_ANY); ac++;
  1242.             
  1243.             m_chromeparent = XmCreateFormDialog(m_parentframe->getDialogParent(),
  1244.                                                 "form", av, ac);
  1245.             
  1246.             shell = XtParent(m_chromeparent);
  1247.  
  1248.             MWContext *fooContext = fe_WidgetToMWContext(m_parentframe->getDialogParent());
  1249.  
  1250.             if (fooContext && ViewGlue_getFrame(fooContext) != NULL)
  1251.                 {
  1252.                     m_parentframe = ViewGlue_getFrame(fooContext);
  1253.                     
  1254.                     fe_ProtectContext(m_parentframe->getContext());
  1255.                 }
  1256.         }
  1257.     else
  1258.         {
  1259.             m_ismodal = False;
  1260.  
  1261.             // Make sure the iconic state is set before the shell gets 
  1262.             // created or else it does not work
  1263.             if (!fe_GetCommandLineDone() && 
  1264.                 fe_globalData.startup_iconic &&
  1265.                 !m_chromespec_provided)
  1266.             {
  1267.                 XtSetArg (av[ac], XmNinitialState, IconicState); ac++;
  1268.                 XtSetArg (av[ac], XmNiconic, True); ac++;
  1269.             }
  1270.  
  1271.             shell = XfeCreateFrameShell(parent,name,av,ac);
  1272.  
  1273.             m_chromeparent = XtCreateManagedWidget("form",
  1274.                                                    xmFormWidgetClass,
  1275.                                                    shell,
  1276.                                                    NULL, 0);
  1277.  
  1278.             XtAddEventHandler(shell, StructureNotifyMask,
  1279.                               True, (XtEventHandler)resizeHandler,
  1280.                               (XtPointer)this);
  1281.  
  1282.             if (!m_allowresize)
  1283.               {
  1284.                 XtVaSetValues(shell,
  1285.                               XmNmwmFunctions,
  1286.                               MWM_FUNC_ALL|MWM_FUNC_RESIZE|MWM_FUNC_MAXIMIZE,
  1287.                               NULL);
  1288.               }
  1289.         }
  1290.  
  1291.  
  1292. #ifndef __sgi
  1293.     XtAddEventHandler(shell, (EventMask)0, True,
  1294.                       (XtEventHandler)_XEditResCheckMessages, 0);
  1295. #endif
  1296.  
  1297.     setBaseWidget(shell);
  1298.     installDestroyHandler();
  1299. }
  1300.  
  1301. static void resizeHandler(Widget, XtPointer p, XEvent *event, Boolean *)
  1302. {
  1303.     if (event->type == ConfigureNotify && p != 0)
  1304.     {
  1305.         XFE_Frame* frame = (XFE_Frame*)p;
  1306.  
  1307.         frame->frameResizeHandler(event->xconfigure.width,
  1308.                                   event->xconfigure.height);
  1309.     }
  1310. }
  1311.  
  1312. void
  1313. XFE_Frame::frameResizeHandler(int width, int height)
  1314. {        
  1315.     //
  1316.     // The forcing and saving of prefs should only happen if a chromespec
  1317.     // was not specified in the constructor. -re
  1318.     //
  1319.     if (m_chromespec_provided)
  1320.     {
  1321.         return;
  1322.     }
  1323.  
  1324.     //
  1325.     // Sometimes the user might not want the client too save the current
  1326.     // frame geometry
  1327.     //
  1328.     if (fe_globalData.dont_save_geom_prefs)
  1329.     {
  1330.         return;
  1331.     }
  1332.  
  1333.     if (geometryPrefName != NULL)
  1334.     {
  1335.         PREF_SetIntPref(getWidthPrefString(), (int32)width);
  1336.         PREF_SetIntPref(getHeightPrefString(), (int32)height);
  1337.     }
  1338. }
  1339.  
  1340. // If you want to add special behavior to your frame when the user tries to
  1341. // close it, override this function.  It should return TRUE if the window
  1342. // should actually close, and FALSE if it should remain on the screen.  This
  1343. // means that any dialog that is popped up to prompt the user whether they
  1344. // want to save a file, send a message, etc, needs to be done synchronously,
  1345. // but you already knew that.
  1346. XP_Bool
  1347. XFE_Frame::isOkToClose()
  1348. {
  1349.     return TRUE;
  1350. }
  1351.  
  1352. static void
  1353. fe_focus_notify_eh (Widget /*w*/, XtPointer closure, XEvent *ev, Boolean * /*cont*/)
  1354. {
  1355.   MWContext *context = (MWContext *) closure;
  1356.   JSEvent *event;
  1357.  
  1358.   TRACEMSG (("fe_focus_notify_eh\n"));
  1359.   switch (ev->type) {
  1360.   case FocusIn:
  1361.     TRACEMSG (("focus in\n"));
  1362.       event = XP_NEW_ZAP(JSEvent);
  1363.       event->type = EVENT_FOCUS;
  1364.     ET_SendEvent (context, NULL, event, NULL, NULL);
  1365.     break;
  1366.   case FocusOut:
  1367.     TRACEMSG (("focus out\n"));
  1368.       event = XP_NEW_ZAP(JSEvent);
  1369.       event->type = EVENT_BLUR;
  1370.     ET_SendEvent (context, NULL, event, NULL, NULL);
  1371.     break;
  1372.   }
  1373. }
  1374.  
  1375. #ifdef NOBODY_IS_USING_THIS_AND_IAM_SICK_OF_SEEING_A_WARNING_MSG_ABOUT_IT
  1376. static void
  1377. fe_map_notify_eh (Widget /*w*/, XtPointer closure, XEvent *ev, Boolean * /*cont*/)
  1378. {
  1379. #ifdef JAVA
  1380.     MWContext *context = (MWContext *) closure;
  1381.     switch (ev->type) {
  1382.     case MapNotify:
  1383.     LJ_UniconifyApplets(context);
  1384.     break;
  1385.     case UnmapNotify:
  1386.     LJ_IconifyApplets(context);
  1387.     break;
  1388.     }
  1389. #endif /* JAVA */
  1390. }
  1391. #endif
  1392.  
  1393. void
  1394. XFE_Frame::doClose()
  1395. {
  1396.     XP_InterruptContext (m_context);
  1397.     
  1398.     if (m_chrome_close_callback)
  1399.     {
  1400.     (*m_chrome_close_callback)(m_chrome_close_arg);
  1401.     }
  1402.  
  1403.     if (m_destroyOnClose)
  1404.     {
  1405.     hide();
  1406.     // here we remove the context from all our lists, and
  1407.     // then voice our contempt with the current situation
  1408.     // by telling mocha we have no interest in this context
  1409.     // any longer.  We didn't like it anyway.  It was broken,
  1410.     // and stupid.  but then, we end up doing _more_ things
  1411.     // with the context after mocha says it doesn't want
  1412.     // it anymore.  amazing what a sad existence these
  1413.     // MWContexts lead... destined to be scorned not once,
  1414.     // but twice before destruction...
  1415.  
  1416.     // do this before notifying about beforeDestroyCallback,
  1417.         XFE_MozillaApp::theApp()->unregisterInterest(
  1418.             XFE_MozillaApp::changeInToplevelFrames, this,
  1419.             (XFE_FunctionNotification)toplevelWindowChangeOccured_cb);
  1420.                     
  1421.         XFE_MozillaApp::theApp()->unregisterInterest(XFE_MozillaApp::appBusyCallback,
  1422.                              this,
  1423.                              (XFE_FunctionNotification)updateBusyState_cb,
  1424.                              (void*)True);
  1425.  
  1426.         XFE_MozillaApp::theApp()->unregisterInterest(XFE_MozillaApp::appNotBusyCallback,
  1427.                              this,
  1428.                              (XFE_FunctionNotification)updateBusyState_cb,
  1429.                              (void*)False);
  1430.         
  1431.         unregisterInterest(frameBusyCallback,
  1432.                            this,
  1433.                            (XFE_FunctionNotification)updateBusyState_cb,
  1434.                            (void*)True);
  1435.  
  1436.         unregisterInterest(frameNotBusyCallback,
  1437.                            this,
  1438.                            (XFE_FunctionNotification)updateBusyState_cb,
  1439.                            (void*)False);
  1440.  
  1441.     notifyInterested(XFE_Frame::beforeDestroyCallback);
  1442.  
  1443.     if (m_context)
  1444.     {
  1445.         fe_ContextData* d = CONTEXT_DATA(m_context);
  1446.         Widget w = CONTEXT_WIDGET (m_context);
  1447.  
  1448.         /* Fix for bug #29631 */
  1449.         if (m_context == last_documented_xref_context)
  1450.         {
  1451.             last_documented_xref_context = 0;
  1452.             last_documented_xref = 0;
  1453.             last_documented_anchor_data = 0;
  1454.         }
  1455.         /* This is a hack. If the mailcompose window is going away and 
  1456.          * a tooltip was still there (or) was armed (a timer was set for it)
  1457.          * for a widget in the mailcompose window, then the destroying
  1458.          * mailcompose context would cause a core dump when the tooltip
  1459.          * timer hits. This could happen to a javascript window with toolbars
  1460.          * too if it is being closed on a timer.
  1461.          *
  1462.          * In this critical time of 3.x ship, we are fixing this by
  1463.          * always killing any tooltip that was present anywhere and
  1464.          * remove the timer for any armed tooltop anywhere in the
  1465.          * navigator when any context is going away.
  1466.          *----
  1467.          * The proper thing to do would be
  1468.          *  - to check if the fe_tool_tips_widget is a child of the
  1469.          *    CONTEXT_WIDGET(context) and if it is, then cleanup the tooltip.
  1470.          */
  1471.         fe_cleanup_tooltips(m_context);
  1472.                             
  1473.          if (m_context->is_grid_cell)
  1474.             CONTEXT_DATA (m_context)->being_destroyed = True;
  1475. #ifdef notyet
  1476.         if (context->type == MWContextSaveToDisk) {
  1477.             /* We might be in an extend text selection on the text widgets.
  1478.                If we destroy this now, we will dump core. So before destroying
  1479.                we will disable extend of the selection. */
  1480.             XtCallActionProc(CONTEXT_DATA (context)->url_label, "extend-end",
  1481.                 NULL, NULL, 0);
  1482.             XtCallActionProc(CONTEXT_DATA (context)->url_text, "extend-end",
  1483.                 NULL, NULL, 0);
  1484.         }
  1485. #endif
  1486.         if (m_context->is_grid_cell)
  1487.             w = d->main_pane;
  1488.                             
  1489.         if (d->refresh_url_timer)
  1490.             XtRemoveTimeOut (d->refresh_url_timer);
  1491.         if (d->refresh_url_timer_url)
  1492.             free (d->refresh_url_timer_url);
  1493.         fe_DisposeColormap(m_context);
  1494.                             
  1495.                             
  1496.         /*
  1497.         ** We have to destroy the layout before calling XtUnmanageChild so that
  1498.         ** we have a chance to reparent the applet windows to a safe
  1499.         ** place. Otherwise they'll get destroyed.
  1500.         */
  1501.         fe_DestroyLayoutData (m_context);
  1502.  
  1503.         XtUnmanageChild (w);
  1504.                             
  1505.         fe_StopProgressGraph (m_context);
  1506.         fe_FindReset (m_context);
  1507.                             
  1508.         fe_DisownSelection (m_context, 0, True);
  1509.         fe_DisownSelection (m_context, 0, False);
  1510.                             
  1511.  
  1512.         if (m_haveHTMLDisplay) {
  1513. #if notyet /* invoking this causes a crash in LJ_UniconifyApplets */
  1514.             XtRemoveEventHandler(w, StructureNotifyMask, False, fe_map_notify_eh, m_context);
  1515. #endif
  1516.             XtRemoveEventHandler (w, FocusChangeMask, False, fe_focus_notify_eh, m_context);
  1517.         }
  1518.                             
  1519.         if (CONTEXT_DATA (m_context)->ftd) free (CONTEXT_DATA (m_context)->ftd);
  1520.         if (CONTEXT_DATA (m_context)->sd) free (CONTEXT_DATA (m_context)->sd);
  1521.                             
  1522. #ifdef EDITOR
  1523.         /*
  1524.          *  NOTE:  is_editor is set for both PageCompose & MailCompose...
  1525.          */
  1526.         if (m_context->is_editor) 
  1527.         {
  1528.             fe_EditorCleanup(m_context);
  1529.         }
  1530. #endif /*EDITOR*/
  1531.     }
  1532.  
  1533.     {
  1534.         struct fe_MWContext_cons *rest, *prev;
  1535.         for (prev = 0, rest = fe_all_MWContexts;
  1536.             rest; prev = rest, rest = rest->next)
  1537.           if (rest->context == m_context)
  1538.             break;
  1539.  
  1540. #ifdef DEBUG_username
  1541.  
  1542.     if (!rest)
  1543.     {
  1544.     XFE_Frame *dbgframe = ViewGlue_getFrame(m_context);
  1545.     
  1546.     if ( dbgframe ) 
  1547.         printf("Frame::doClose()... cannot find m_context(%s) in context list\n", 
  1548.         XtName(dbgframe->getBaseWidget()));
  1549.     else printf("Frame::doClose()... no frame for m_context (0x%x)\n",
  1550.             m_context);
  1551.     }
  1552.      
  1553. #endif
  1554.         XP_ASSERT(rest!=NULL);
  1555.         if (rest)
  1556.         {
  1557.            if (prev)
  1558.             prev->next = rest->next;
  1559.            else 
  1560.             fe_all_MWContexts = rest->next;
  1561.  
  1562.            free (rest);
  1563.         }
  1564.         else return;
  1565.     }
  1566.                     
  1567. #ifdef JAVA
  1568.     if (m_haveHTMLDisplay)
  1569.         LJ_DiscardEventsForContext(m_context);
  1570. #endif /* JAVA */
  1571.  
  1572.     XP_RemoveContextFromList(m_context);
  1573.     ET_RemoveWindowContext(m_context, really_delete, this);
  1574.  
  1575.     }
  1576.     else
  1577.     {
  1578.         D(printf("m_destroyOnClose == False, postponing destroy.\n");)
  1579.         hide();
  1580.     }
  1581. }
  1582.  
  1583.  
  1584. void
  1585. XFE_Frame::delete_response()
  1586. {
  1587.     if (fe_IsContextProtected(m_context))
  1588.         {
  1589.             D(printf ("Context 0x%x is protected.  I'm not deleting it, but marking it deleted\n", m_context);)
  1590.  
  1591.             CONTEXT_DATA(m_context)->destroyed = 1;
  1592.             return;
  1593.         }
  1594.  
  1595.     if (isOkToClose())
  1596.         doClose();
  1597. }
  1598.  
  1599. static void
  1600. child_destruction_callback(Widget /* w */, XtPointer closure, XtPointer)
  1601. {
  1602.   XFE_Frame *    frame = (XFE_Frame*)closure;
  1603.   Widget        shell = frame->getBaseWidget();
  1604.  
  1605.   /* Move forward in destruction process only if no live popups exist. */
  1606.   if (XfePopupListCountAlive(shell) == 0)
  1607.   {
  1608.       frame->doClose();
  1609.   }
  1610. }
  1611.  
  1612. void
  1613. XFE_Frame::app_delete_response()
  1614. {
  1615.   if (fe_IsContextProtected(m_context))
  1616.     {
  1617.             D(printf ("Context 0x%x is protected.  I'm not deleting it, but marking it deleted\n", m_context);)
  1618.  
  1619.             CONTEXT_DATA(m_context)->destroyed = 1;
  1620.             return;
  1621.     }
  1622.  
  1623.   if (isOkToClose())
  1624.   {
  1625.       // here things are a bit more complicated than in the
  1626.       // "user deleted me" case, since we want to hang around if
  1627.       // there are any popup shells.
  1628.       Cardinal number_of_live_popups = XfePopupListCountAlive(m_widget);
  1629.       Cardinal i = 0;
  1630.       
  1631.       if (number_of_live_popups > 0)
  1632.       {
  1633.           D(printf ("Context 0x%x has some popups above it.  we're hanging out until they all are destroyed\n");)
  1634.  
  1635.               for (i = 0; i < XfeNumPopups(m_widget); i ++)
  1636.               {
  1637.                   if (XfeIsAlive(XfePopupListIndex(m_widget,i)))
  1638.                   {
  1639.                       XtAddCallback(XfePopupListIndex(m_widget,i),
  1640.                                     XmNdestroyCallback,
  1641.                                     child_destruction_callback,
  1642.                                     this);
  1643.                   }
  1644.               }
  1645.       }
  1646.       else
  1647.       {
  1648.           doClose();
  1649.       }
  1650.   }
  1651. }
  1652.  
  1653. void
  1654. XFE_Frame::delete_response(Widget /*widget*/, XtPointer closure, XtPointer /*call_data*/)
  1655. {
  1656.     XFE_Frame *obj = (XFE_Frame*)closure;
  1657.  
  1658.     if (obj->isWMClosable()) 
  1659.     {
  1660.         if (XFE_MozillaApp::theApp()->toplevelWindowCount() == 1) 
  1661.         {
  1662.             // If we are closing either the bookmark or history frames, we
  1663.             // dont need to exit after closing them, since they are singletons
  1664.             // and are only shown/hidden instead of created/destroyed.
  1665.             if ((obj->getType() == FRAME_HISTORY) ||
  1666.                 (obj->getType() == FRAME_BOOKMARK))
  1667.             {
  1668.                 obj->doCommand(xfeCmdClose);
  1669.             }
  1670.             else
  1671.             {
  1672.                 obj->doCommand(xfeCmdExit);
  1673.             }
  1674.         }
  1675.         else 
  1676.         {
  1677.             obj->doCommand(xfeCmdClose);
  1678.         }
  1679.     }
  1680. }
  1681.  
  1682. void
  1683. XFE_Frame::really_delete(void *data)
  1684. {
  1685.     XFE_Frame *frame = (XFE_Frame*)data;
  1686.  
  1687.     Widget w = (Widget)frame->getBaseWidget();
  1688.  
  1689.     D(printf("really_delete ... %s\n", XtName(w));)
  1690.  
  1691.     XtDestroyWidget(w);
  1692. }
  1693.  
  1694. void
  1695. XFE_Frame::storeProperty (MWContext *context, 
  1696.               char *property,
  1697.               const unsigned char *data)
  1698. {
  1699.   Widget widget = CONTEXT_WIDGET (context);
  1700.   Display *dpy = XtDisplay (widget);
  1701.   Window window = XtWindow (widget);
  1702.   Atom atom = 0;
  1703.  
  1704.   // eventually we'll check to see if the atom is already present
  1705.   // if (! atom)
  1706.   
  1707.   atom = XInternAtom (dpy, property, False);
  1708.   XChangeProperty (dpy, window, atom, XA_STRING, 8,
  1709.            PropModeReplace, (const unsigned char *) data, 
  1710.            strlen ((const char *)data));
  1711. }
  1712.  
  1713. XP_Bool
  1714. XFE_Frame::isWMClosable()
  1715. {
  1716.     return m_iswmclosable;
  1717. }
  1718.  
  1719. void
  1720. XFE_Frame::initializeMWContext(EFrameType frame_type,
  1721.                                MWContext */*context_to_copy*/)
  1722. {
  1723.     fe_ContextData *fec;
  1724.     struct fe_MWContext_cons *cons;
  1725.     MWContextType type = MWContextAny;
  1726.  
  1727.     if (m_context) return;  
  1728.  
  1729.     switch (frame_type)
  1730.         {
  1731.         case FRAME_BROWSER:             type = MWContextBrowser; break;
  1732.         case FRAME_EDITOR:                 type = MWContextEditor; break;
  1733.         case FRAME_MAILNEWS_COMPOSE:     type = MWContextMessageComposition; break;
  1734.         case FRAME_MAILNEWS_MSG:        type = MWContextMailMsg; break;
  1735.         case FRAME_MAILNEWS_THREAD:        type = MWContextMail; break;
  1736.         case FRAME_MAILNEWS_FOLDER:        type = MWContextMail; break;
  1737.         case FRAME_MAILNEWS_DOWNLOAD:   type = MWContextMail; break;
  1738.         case FRAME_ADDRESSBOOK:            type = MWContextAddressBook; break;
  1739.         case FRAME_BOOKMARK:            type = MWContextBookmarks; break;
  1740.         case FRAME_MAILNEWS_SEARCH:        type = MWContextSearch; break;
  1741.         case FRAME_LDAP_SEARCH:            type = MWContextSearchLdap; break;
  1742.         case FRAME_DOWNLOAD:            type = MWContextSaveToDisk; break;
  1743.         case FRAME_HTML_DIALOG:            type = MWContextDialog; break;
  1744.         case FRAME_HISTORY:             type = MWContextHistory; break;
  1745.         case FRAME_NAVCENTER:           type = MWContextHistory; break; //??
  1746.         default:
  1747.             XP_ASSERT(0);
  1748.             break;
  1749.         }
  1750.  
  1751.     m_context     = XP_NewContext();
  1752.     if (m_context == NULL) return;
  1753.     cons        = XP_NEW_ZAP(struct fe_MWContext_cons);
  1754.     if (cons == NULL) return;
  1755.     fec        = XP_NEW_ZAP (fe_ContextData);
  1756.     if (fec == NULL) return;
  1757.  
  1758.     m_context->type = type;
  1759.     switch (type)
  1760.         {
  1761.         case MWContextEditor:
  1762.         case MWContextMessageComposition:
  1763.             m_context->is_editor = True;
  1764.             break;
  1765.         default:
  1766.             m_context->is_editor = False;
  1767.             break;
  1768.         }
  1769.  
  1770.     CONTEXT_DATA (m_context) = fec;
  1771.     CONTEXT_DATA (m_context)->colormap = m_cmap;
  1772.     CONTEXT_WIDGET (m_context) = m_widget;
  1773.  
  1774.     fe_InitRemoteServer (XtDisplay (m_widget));
  1775.  
  1776.     /* add the layout function pointers */
  1777.     m_context->funcs = fe_BuildDisplayFunctionTable();
  1778.     m_context->convertPixX = m_context->convertPixY = 1;
  1779.     m_context->is_grid_cell = FALSE;
  1780.     m_context->grid_parent = NULL;
  1781.  
  1782.     /* set the XFE default Document Character set */
  1783.     CONTEXT_DATA(m_context)->xfe_doc_csid = fe_globalPrefs.doc_csid;
  1784.  
  1785.     cons->context = m_context;
  1786.     cons->next = fe_all_MWContexts;
  1787.     fe_all_MWContexts = cons;
  1788.     XP_AddContextToList (m_context);
  1789.  
  1790.     fe_InitIconColors(m_context);
  1791.  
  1792.     if (m_frametype != FRAME_BOOKMARK)
  1793.       fe_createBookmarks(XtParent(m_widget), NULL, NULL);
  1794.  
  1795. //    fe_LicenseDialog (m_context);
  1796.  
  1797.     XtGetApplicationResources (m_widget,
  1798.                                (XtPointer) CONTEXT_DATA (m_context),
  1799.                                fe_Resources, fe_ResourcesSize,
  1800.                                0, 0);
  1801.  
  1802.     // Use colors from prefs
  1803.  
  1804.     LO_Color *color;
  1805.  
  1806.     color = &fe_globalPrefs.links_color;
  1807.     CONTEXT_DATA(m_context)->link_pixel = 
  1808.         fe_GetPixel(m_context, color->red, color->green, color->blue);
  1809.  
  1810.     color = &fe_globalPrefs.vlinks_color;
  1811.     CONTEXT_DATA(m_context)->vlink_pixel = 
  1812.         fe_GetPixel(m_context, color->red, color->green, color->blue);
  1813.  
  1814.     color = &fe_globalPrefs.text_color;
  1815.     CONTEXT_DATA(m_context)->default_fg_pixel = 
  1816.         fe_GetPixel(m_context, color->red, color->green, color->blue);
  1817.  
  1818.     color = &fe_globalPrefs.background_color;
  1819.     CONTEXT_DATA(m_context)->default_bg_pixel = 
  1820.         fe_GetPixel(m_context, color->red, color->green, color->blue);
  1821.  
  1822.     if (m_haveHTMLDisplay) {
  1823.         Display * dpy;
  1824.         int screen;
  1825.         double pixels;
  1826.         double millimeters;
  1827.  
  1828.         /* Determine pixels per point for back end font size calculations. */
  1829.  
  1830.         dpy = XtDisplay(m_widget);
  1831.         screen = XScreenNumberOfScreen(XtScreen(m_widget));
  1832.  
  1833.         /* N pixels    25.4 mm    1 inch
  1834.          * -------- *  ------- *  ------
  1835.          *   M mm       1 inch    72 pts
  1836.          */
  1837.  
  1838.         pixels      = DisplayWidth(dpy, screen);
  1839.         millimeters = DisplayWidthMM(dpy, screen);
  1840.         m_context->XpixelsPerPoint =
  1841.             ((pixels * MM_PER_INCH) / millimeters) / POINTS_PER_INCH;
  1842.  
  1843.         pixels      = DisplayHeight(dpy,screen);
  1844.         millimeters = DisplayHeightMM(dpy, screen);
  1845.         m_context->YpixelsPerPoint =
  1846.             ((pixels * MM_PER_INCH) / millimeters) / POINTS_PER_INCH;
  1847.  
  1848.  
  1849.         SHIST_InitSession (m_context);
  1850.     
  1851.         fe_load_default_font(m_context);
  1852.  
  1853. #if notyet /* invoking this causes a crash in LJ_UniconifyApplets */
  1854.         XtAddEventHandler(m_widget, StructureNotifyMask,
  1855.                               FALSE, (XtEventHandler)fe_map_notify_eh, m_context);
  1856. #endif
  1857.         XtAddEventHandler(m_widget, FocusChangeMask,
  1858.                               FALSE, (XtEventHandler)fe_focus_notify_eh, m_context);
  1859.         }
  1860.  
  1861.     /*
  1862.      * set the default coloring correctly into the new context.
  1863.      */
  1864.     {
  1865.         Pixel unused_select_pixel;
  1866.         XmGetColors (XtScreen (m_widget),
  1867.                      fe_cmap(m_context),
  1868.                      CONTEXT_DATA (m_context)->default_bg_pixel,
  1869.                      &(CONTEXT_DATA (m_context)->fg_pixel),
  1870.                      &(CONTEXT_DATA (m_context)->top_shadow_pixel),
  1871.                      &(CONTEXT_DATA (m_context)->bottom_shadow_pixel),
  1872.                      &unused_select_pixel);
  1873.     }
  1874.  
  1875.     // New field added by putterman for increase/decrease font
  1876.     m_context->fontScalingPercentage = 1.0;
  1877. }
  1878.  
  1879. void
  1880. XFE_Frame::allConnectionsComplete()
  1881. {
  1882.     /* Tao_17dec96
  1883.      * Notify whoever interested in "allConnectionsComplete" event
  1884.      */
  1885.     notifyInterested(XFE_Frame::allConnectionsCompleteCallback);
  1886.     notifyInterested(XFE_View::chromeNeedsUpdating);
  1887. }
  1888.  
  1889. XFE_Frame*
  1890. XFE_Frame::getActiveFrame()
  1891. {
  1892.     XFE_Frame *frame = NULL;
  1893.  
  1894.     if (fe_all_MWContexts->next)
  1895.         frame = ViewGlue_getFrame(fe_all_MWContexts->next->context);
  1896.  
  1897.     return frame;
  1898. }
  1899.  
  1900. void
  1901. XFE_Frame::hackTranslations(Widget widget)
  1902. {
  1903.     XtTranslations global_translations = 0;
  1904.     XtTranslations secondary_translations = 0;
  1905.   
  1906.     if (XmIsGadget (widget))
  1907.         return;
  1908.  
  1909.     /* To prevent focus problems, dont enable translations on the menubar
  1910.        and its children. The problem was that when we had the translations
  1911.        in the menubar too, we could do a translation and popup a modal
  1912.        dialog when one of the menu's from the menubar was pulleddown. Now
  1913.        motif gets too confused about who holds pointer and keyboard focus.
  1914.        */
  1915.  
  1916.     if (XmIsRowColumn(widget)) {
  1917.         unsigned char type;
  1918.         XtVaGetValues(widget, XmNrowColumnType, &type, 0);
  1919.         if (type == XmMENU_BAR)
  1920.             return;
  1921.     }
  1922.  
  1923.     switch (m_frametype)
  1924.         {
  1925.         case FRAME_EDITOR:
  1926.             global_translations = fe_globalData.global_translations;
  1927.             secondary_translations = fe_globalData.editor_global_translations;
  1928.             break;
  1929.  
  1930.         case FRAME_BROWSER:
  1931.             global_translations = fe_globalData.global_translations;
  1932.             secondary_translations = fe_globalData.browser_global_translations;
  1933.             break;
  1934.  
  1935.         case FRAME_MAILNEWS_FOLDER:
  1936.             global_translations = fe_globalData.global_translations;
  1937.             secondary_translations = fe_globalData.mailnews_global_translations;
  1938.             break;
  1939.  
  1940.         case FRAME_MAILNEWS_THREAD:
  1941.         case FRAME_MAILNEWS_MSG:
  1942.             global_translations = fe_globalData.global_translations;
  1943.             secondary_translations = fe_globalData.messagewin_global_translations;
  1944.             break;
  1945.  
  1946.         case FRAME_MAILNEWS_SEARCH:
  1947.             global_translations = fe_globalData.mnsearch_global_translations;
  1948.             break;
  1949.  
  1950.         case FRAME_MAILNEWS_COMPOSE:
  1951.             global_translations = fe_globalData.global_translations;
  1952.             secondary_translations = fe_globalData.mailcompose_global_translations;
  1953.             break;
  1954.  
  1955.         case FRAME_BOOKMARK:
  1956.             global_translations = fe_globalData.global_translations;
  1957.             secondary_translations = fe_globalData.bm_global_translations;
  1958.             break;
  1959.  
  1960.         case FRAME_ADDRESSBOOK:
  1961.             global_translations = fe_globalData.global_translations;
  1962.             secondary_translations = fe_globalData.ab_global_translations;
  1963.             break;
  1964.  
  1965.         case FRAME_HISTORY:
  1966.             global_translations = fe_globalData.global_translations;
  1967.             secondary_translations = fe_globalData.gh_global_translations;
  1968.  
  1969.         default:
  1970.             break;
  1971.         }
  1972.  
  1973.     if (!XP_STRCMP( XtName(widget), "editorDrawingArea" )) {
  1974.         XtOverrideTranslations (widget, fe_globalData.global_translations);
  1975.         XtOverrideTranslations (widget, fe_globalData.editor_global_translations);
  1976.     }
  1977.     else {
  1978.         if (global_translations)
  1979.             XtOverrideTranslations (widget, global_translations);
  1980.         if (secondary_translations)
  1981.             XtOverrideTranslations (widget, secondary_translations);
  1982.     }
  1983.  
  1984.     if (XmIsTextField (widget) || XmIsText (widget) || XmIsList(widget))
  1985.         {
  1986.             /* Set up the editing translations (all text fields, everywhere.) */
  1987.             if (XmIsTextField (widget) || XmIsText (widget))
  1988.                 hackTextTranslations (widget);
  1989.  
  1990.             /* Install globalTextFieldTranslations on single-line text fields in
  1991.                windows which have an HTML display area (browser, mail, news) but
  1992.                not in windows which don't have one (compose, download, bookmarks,
  1993.                address book...)
  1994.                */
  1995.             if (m_haveHTMLDisplay &&
  1996.                 XmIsTextField (widget) &&
  1997.                 fe_globalData.global_text_field_translations)
  1998.                 XtOverrideTranslations (widget,
  1999.                                         fe_globalData.global_text_field_translations);
  2000.         }
  2001.     else
  2002.         {
  2003.             Widget *kids = 0;
  2004.             Cardinal nkids = 0;
  2005.  
  2006.             /* Not a Text or TextField.
  2007.              */
  2008.             /* Install globalNonTextTranslations on non-text widgets in windows which
  2009.                have an HTML display area (browser, mail, news, view source) but not
  2010.                in windows which don't have one (compose, download, bookmarks,
  2011.                address book...)
  2012.                */
  2013.  
  2014.             /* Install globalNonTextTranslations on non-text widgets in windows 
  2015.                which have an HTML display area (browser, mail, news, view source)
  2016.                but not in windows which either don't have one (download, 
  2017.                bookmarks, address book...) or have one that is editable.
  2018.                */
  2019.             if (m_haveHTMLDisplay
  2020.                 && m_frametype != FRAME_EDITOR
  2021.                 && m_frametype != FRAME_MAILNEWS_COMPOSE
  2022.                 && fe_globalData.global_nontext_translations)
  2023.                 XtOverrideTranslations (widget,
  2024.                                         fe_globalData.global_nontext_translations);
  2025.  
  2026.             /* Now recurse on the children.
  2027.              */
  2028.             XtVaGetValues (widget, XmNchildren, &kids, XmNnumChildren, &nkids, 0);
  2029.             while (nkids--)
  2030.                 hackTranslations (kids [nkids]);
  2031.         }
  2032. }
  2033.  
  2034. void
  2035. XFE_Frame::hackTextTranslations(Widget widget)
  2036. {
  2037.     Widget parent = widget;
  2038.  
  2039.     for (parent=widget; parent && !XtIsWMShell (parent); parent=XtParent(parent))
  2040.         if (XmLIsGrid(parent))
  2041.             /* We shouldn't be messing with Grid widget and its children */
  2042.             return;
  2043.  
  2044.     if (XmIsTextField(widget))
  2045.         {
  2046.             if (fe_globalData.editing_translations)
  2047.                 XtOverrideTranslations (widget, fe_globalData.editing_translations);
  2048.             if (fe_globalData.single_line_editing_translations)
  2049.                 XtOverrideTranslations (widget,
  2050.                                         fe_globalData.single_line_editing_translations);
  2051.         }
  2052.     else if (XmIsText(widget))
  2053.         {
  2054.             if (fe_globalData.editing_translations)
  2055.                 XtOverrideTranslations (widget, fe_globalData.editing_translations);
  2056.             if (fe_globalData.multi_line_editing_translations)
  2057.                 XtOverrideTranslations (widget,
  2058.                                         fe_globalData.multi_line_editing_translations);
  2059.         }
  2060.     else
  2061.         {
  2062.             XP_ASSERT(0);
  2063.         }
  2064. }
  2065.  
  2066. EFrameType
  2067. XFE_Frame::getType()
  2068. {
  2069.     return m_frametype;
  2070. }
  2071.  
  2072. void
  2073. XFE_Frame::updateToolbar()
  2074. {
  2075.     if (!m_toolbar)
  2076.         return;
  2077.  
  2078.     m_toolbar->update();
  2079. }
  2080.  
  2081. void
  2082. XFE_Frame::updateMenuBar()
  2083. {
  2084.     XP_ASSERT(m_menubar);
  2085.  
  2086.     if (!m_menubar)
  2087.         return;
  2088.  
  2089.     m_menubar->update();
  2090. }
  2091.  
  2092. void
  2093. XFE_Frame::setMenubar(MenuSpec *menu_bar_spec)
  2094. {
  2095.     XP_ASSERT(m_menubar);
  2096.  
  2097.     // Decide if we need to hide Polaris menu item.
  2098.     // Hide menu items by setting do_not_manage in MenuSpec to TRUE
  2099.  
  2100.     static XP_Bool have_been_here_before = False;
  2101.  
  2102.     if (! have_been_here_before) {
  2103.         if (! fe_IsPolarisInstalled()) {
  2104.             MenuSpec *spec = XFE_Frame::window_menu_spec;
  2105.             while (spec->menuItemName) {
  2106.                 if ((XP_STRCMP(xfeCmdOpenCalendar, spec->menuItemName) == 0) ||
  2107.                     (XP_STRCMP(xfeCmdOpenHostOnDemand, spec->menuItemName) == 0))
  2108.                     spec->do_not_manage = True;
  2109.                 spec++;
  2110.             }
  2111.         }
  2112.         have_been_here_before = True;
  2113.     }
  2114.  
  2115.     m_menubar->setMenuSpec(menu_bar_spec);
  2116. }
  2117.  
  2118. void
  2119. XFE_Frame::setToolbar(ToolbarSpec *toolbar_spec)
  2120. {
  2121.     XP_ASSERT(m_toolbar);
  2122.  
  2123.     m_toolbar->setToolbarSpec(toolbar_spec);
  2124.  
  2125.     return;
  2126. }
  2127.  
  2128. void
  2129. XFE_Frame::doAttachments(XP_Bool force)
  2130. {
  2131.     Widget    topguy = NULL;
  2132.     Widget    bottomguy = NULL;
  2133.  
  2134.     if (!force && !isShown())
  2135.     {
  2136.         m_attachmentsNeeded = True;
  2137.         return;
  2138.     }
  2139.  
  2140.     // we lay things out from the top and bottom inward, since the view attaches
  2141.     // to widgets on top and below it.
  2142.     if (m_menubar && m_menubar->isShown())
  2143.     {
  2144.         XtVaSetValues(m_menubar->getBaseWidget(),
  2145.                       XmNleftAttachment, XmATTACH_FORM,
  2146.                       XmNrightAttachment, XmATTACH_FORM,
  2147.                       XmNtopAttachment, XmATTACH_FORM,
  2148.                       XmNbottomAttachment, XmATTACH_NONE,
  2149.                       NULL);
  2150.         topguy = m_menubar->getBaseWidget();
  2151.     }
  2152.  
  2153.     if (m_dashboard && m_dashboard->isShown())
  2154.     {
  2155.         XtVaSetValues(m_dashboard->getBaseWidget(),
  2156.                       XmNleftAttachment, XmATTACH_FORM,
  2157.                       XmNrightAttachment, XmATTACH_FORM,
  2158.                       XmNbottomAttachment, XmATTACH_FORM,
  2159.                       XmNtopAttachment, XmATTACH_NONE,
  2160.                       NULL);
  2161.         bottomguy = m_dashboard->getBaseWidget();
  2162.     }
  2163.  
  2164.     if (m_belowview && m_belowview->isShown())
  2165.     {
  2166.         XtVaSetValues(m_belowview->getBaseWidget(),
  2167.                       XmNleftAttachment, XmATTACH_FORM,
  2168.                       XmNrightAttachment, XmATTACH_FORM,
  2169.                       XmNtopAttachment, XmATTACH_NONE,
  2170.                       XmNbottomAttachment, (bottomguy ? XmATTACH_WIDGET : XmATTACH_FORM),
  2171.                       XmNbottomWidget, bottomguy,
  2172.                       NULL);
  2173.         bottomguy = m_belowview->getBaseWidget();
  2174.     }
  2175.  
  2176.     // The above view component does not need to be cnfigured, since
  2177.     // the mainform will take care of it.
  2178.  
  2179.     // Configure the main form
  2180.     XtVaSetValues(m_mainform,
  2181.                   XmNleftAttachment,    XmATTACH_FORM,
  2182.                   XmNrightAttachment,    XmATTACH_FORM,
  2183.                   XmNtopAttachment,        (topguy ? XmATTACH_WIDGET : XmATTACH_FORM),
  2184.                   XmNtopWidget,            topguy,
  2185.                   XmNbottomAttachment,    (bottomguy ? XmATTACH_WIDGET : XmATTACH_FORM),
  2186.                   XmNbottomWidget,        bottomguy,
  2187.                   NULL);
  2188.  
  2189.     // Attachments not needed anymore
  2190.     m_attachmentsNeeded = False;
  2191. }
  2192.  
  2193. int
  2194. XFE_Frame::getSecurityStatus()
  2195. {
  2196.   int rval = XFE_UNSECURE;
  2197.  
  2198. #ifndef NO_SECURITY
  2199.   switch (XP_GetSecurityStatus(m_context)) 
  2200.     {
  2201.     case SSL_SECURITY_STATUS_ON_HIGH: // us     
  2202.     case SSL_SECURITY_STATUS_ON_LOW:  // export
  2203.       rval = XFE_SECURE;
  2204.       break;
  2205.       /* rval =  XFE_SECURE_MIXED;
  2206.       break;*/
  2207.     case SSL_SECURITY_STATUS_NOOPT: // fall through
  2208.     case SSL_SECURITY_STATUS_OFF:   // fall through
  2209.     case SSL_SECURITY_STATUS_FORTEZZA:  // fall through  (is this be secure???)
  2210.     default:
  2211.       rval = XFE_UNSECURE;
  2212.       break;
  2213.     }
  2214. #endif /* ! NO_SECURITY */
  2215.  
  2216.   return rval;
  2217. }
  2218.  
  2219. // Next two routines return static data -- copy immediately
  2220. // if for some reason you want to keep them.
  2221. char* XFE_Frame::getWidthPrefString()
  2222. {
  2223.     if (geometryPrefName == 0)
  2224.         return 0;
  2225.     static char widthPref[80];
  2226.     XP_SPRINTF(widthPref, "%s.win_width", geometryPrefName);
  2227.     return widthPref;
  2228. }
  2229.  
  2230. char* XFE_Frame::getHeightPrefString()
  2231. {
  2232.     if (geometryPrefName == 0)
  2233.         return 0;
  2234.     static char heightPref[80];
  2235.     XP_SPRINTF(heightPref, "%s.win_height", geometryPrefName);
  2236.     return heightPref;
  2237. }
  2238.  
  2239. void
  2240. XFE_Frame::realize()
  2241. {
  2242.     Widget widget; /* the widget we want to realize */
  2243.  
  2244.     widget = m_ismodal ? m_chromeparent : m_widget;
  2245.  
  2246.     if (!XtIsRealized(widget))
  2247.     {
  2248.         Arg            av[20];
  2249.         Cardinal    ac = 0;
  2250.  
  2251.         // Configure the logo for the first time
  2252.         configureLogo();
  2253.         
  2254.         // Do attachments if needed
  2255.         if (m_attachmentsNeeded)
  2256.         {
  2257.             doAttachments(True);
  2258.         }
  2259.  
  2260.         //
  2261.         // The forcing and saving of prefs should only happen if a chromespec
  2262.         // was not specified in the constructor. -re
  2263.         //
  2264.         // Also, dont screw with modal shells.
  2265.         //
  2266.         if (!m_chromespec_provided && !m_ismodal)
  2267.         {
  2268.             int32 width = 0;
  2269.             int32 height = 0;
  2270.             int32 x = 10;
  2271.             int32 y = 10;
  2272.  
  2273.             // First, obtain the frame's geometry from prefs if any 
  2274.             // Also, ignore the prefs if the ignore_geom_prefs flag is false.
  2275.             if (geometryPrefName && !fe_globalData.ignore_geom_prefs)
  2276.             {
  2277.                 PREF_GetIntPref(getWidthPrefString(), &width);
  2278.                 PREF_GetIntPref(getHeightPrefString(), &height);
  2279.             }
  2280.  
  2281.             // Next, if we are still processing the command line, try
  2282.             // to obtain the frame geometry from the -geometry flag 
  2283.             // (-geometry overrides prefs)
  2284.             if (!fe_GetCommandLineDone())
  2285.             {
  2286.                 Widget        shell = XfeAncestorFindApplicationShell(m_widget);
  2287.                 int            mask;
  2288.                 Position    fx;
  2289.                 Position    fy;
  2290.                 Dimension    fwidth;
  2291.                 Dimension    fheight;
  2292.                     
  2293.                 // Get geometry from the app shell's XmNgeometry
  2294.                 mask = XfeShellGetGeometryFromResource(shell,&fx,&fy,
  2295.                                                        &fwidth,&fheight);
  2296.                     
  2297.                 if (mask & XValue)
  2298.                 {
  2299.                     x = fx;
  2300.                 }
  2301.                     
  2302.                 if (mask & YValue)
  2303.                 {
  2304.                     y = fy;
  2305.                 }
  2306.                 
  2307.                 if (mask & WidthValue)
  2308.                 {
  2309.                     width = fwidth;
  2310.                 }
  2311.                 
  2312.                 if (mask & HeightValue)
  2313.                 {
  2314.                     height = fheight;
  2315.                 }
  2316.             }                
  2317.  
  2318.             // At this point (x,y) should be valid
  2319.             XtSetArg(av[ac],XmNx,x); ac++;
  2320.             XtSetArg(av[ac],XmNy,y); ac++;
  2321.  
  2322.             // Use the width and height only if they are non zero
  2323.             if (width > 0)
  2324.             {
  2325.                 XtSetArg(av[ac],XmNwidth,width); ac++;
  2326.             }
  2327.  
  2328.             if (height > 0)
  2329.             {
  2330.                 XtSetArg(av[ac],XmNheight,height); ac++;
  2331.             }
  2332.         }        
  2333.  
  2334.         // Set the startup / pref values if needed
  2335.         if (ac)
  2336.         {
  2337.             XtSetValues(m_widget,av,ac);
  2338.         }
  2339.         
  2340.         XtRealizeWidget(widget);
  2341.  
  2342.         // Add z order support if needed
  2343.         if (XtIsTopLevelShell(m_widget) && m_chromespec_provided)
  2344.         {
  2345.             zaxis_AddSupport();
  2346.         }
  2347.  
  2348.         setCursor(XFE_MozillaApp::theApp()->getBusy());
  2349.  
  2350.         XFE_MozillaApp::theApp()->registerInterest(XFE_MozillaApp::appBusyCallback,
  2351.                                                    this,
  2352.                                                    (XFE_FunctionNotification)updateBusyState_cb,
  2353.                                                    (void*)True);
  2354.             
  2355.         XFE_MozillaApp::theApp()->registerInterest(XFE_MozillaApp::appNotBusyCallback,
  2356.                                                    this,
  2357.                                                    (XFE_FunctionNotification)updateBusyState_cb,
  2358.                                                    (void*)False);
  2359.  
  2360.         registerInterest(frameBusyCallback,
  2361.                          this,
  2362.                          (XFE_FunctionNotification)updateBusyState_cb,
  2363.                          (void*)True);
  2364.  
  2365.         registerInterest(frameNotBusyCallback,
  2366.                          this,
  2367.                          (XFE_FunctionNotification)updateBusyState_cb,
  2368.                          (void*)False);
  2369.  
  2370.         hackTranslations(m_chromeparent); // XX assumes that the m_chromparent is the child of the shell
  2371.             
  2372.         notifyInterested(XFE_Component::afterRealizeCallback);
  2373.  
  2374.         notifyInterested(XFE_View::chromeNeedsUpdating);
  2375.  
  2376.         /* we don't (for various reasons)  want to let these windows do remote stuff. */
  2377.         if (m_frametype != FRAME_DOWNLOAD &&
  2378.             m_frametype != FRAME_MAILNEWS_DOWNLOAD &&
  2379.             m_frametype != FRAME_HISTORY &&
  2380.             m_frametype != FRAME_BOOKMARK &&
  2381.             m_frametype != FRAME_HTML_DIALOG)
  2382.         fe_InitRemoteServerWindow (m_context);
  2383.             
  2384.         fe_get_final_context_resources (m_context);
  2385.             
  2386.         fe_find_scrollbar_sizes (m_context);
  2387.             
  2388.         fe_InitScrolling (m_context);
  2389.             
  2390. #ifdef MOZ_MAIL_NEWS
  2391.         fe_InitIcons (m_context, XFE_MNView::getBiffState());
  2392. #endif
  2393.  
  2394.         // Add session management support if needed */
  2395.         if (fe_globalData.session_management)
  2396.         {
  2397.             sm_addSaveYourselfCB();
  2398.         }
  2399.     }
  2400.     
  2401.     // where should this *really* go?
  2402.     fe_VerifyDiskCache (m_context);
  2403.     /* spider begin */
  2404.     fe_VerifySARDiskCache (m_context);
  2405.     /* spider end */
  2406. }
  2407.  
  2408. void
  2409. XFE_Frame::show()
  2410. {
  2411.     D(printf ("In XFE_Frame::show()\n");)
  2412.  
  2413.       if (!isShown())
  2414.     {
  2415.         D(printf("Calling realize()\n");)
  2416.  
  2417.         realize();
  2418.  
  2419.         if (m_ismodal)
  2420.         {
  2421.             struct fe_MWContext_cons *cons;
  2422.             
  2423.             for (cons = fe_all_MWContexts ; cons; cons = cons->next)
  2424.                 fe_fixFocusAndGrab(cons->context); // XXXX No looping over contexts!!!
  2425.             
  2426.             D(printf ("Managing chrome parent\n");)
  2427.                 
  2428.             XtManageChild(m_chromeparent);
  2429.         }
  2430.         else
  2431.         {
  2432.             // Do not XtPopup() an iconic shell the first time it is 
  2433.             // shown and the command line is still being processed.
  2434.             //
  2435.             // This is needed to support the -iconic flag properly
  2436.             if (XfeShellGetIconicState(m_widget) && 
  2437.                 m_first_showing && 
  2438.                 !fe_GetCommandLineDone())
  2439.             {
  2440.                 XtAddEventHandler(m_widget, 
  2441.                                   StructureNotifyMask,
  2442.                                   True,
  2443.                                   iconicFrameMappingEH,
  2444.                                   (XtPointer) this);
  2445.             }
  2446.             else
  2447.             {
  2448.               /* we return early from the show method if the specified chromespec
  2449.                  gave hints that the window should be offscreen.  This means the
  2450.                  window will not be mapped.  If at some point in the future 
  2451.                  UpdateChrome is called with positive coordinates for the window,
  2452.                  then it will be mapped. */
  2453.               if (m_lhint < 0
  2454.                   && m_thint < 0)
  2455.                 {
  2456.                   D(printf ("Not showing window, since the hints are offscreen\n");)
  2457.                   return;
  2458.                 }
  2459.               
  2460.                 XtPopup(m_widget, XtGrabNone);
  2461.             }
  2462.         }
  2463.     }
  2464.  
  2465.     map();
  2466.  
  2467. //    m_first_showing = False;
  2468. }
  2469.  
  2470. void
  2471. XFE_Frame::map()
  2472. {
  2473.     if (m_topmost) 
  2474.     {
  2475.         XMapRaised(XtDisplay(m_widget), XtWindow(m_widget));
  2476.     }
  2477.     else if (m_bottommost) 
  2478.     {
  2479.         XLowerWindow(XtDisplay(m_widget), XtWindow(m_widget));
  2480.         XMapWindow(XtDisplay(m_widget), XtWindow(m_widget));
  2481.     }
  2482.     else 
  2483.     {
  2484.         /* we need this or selecting a window from the communicator menu when
  2485.            that window is already on the screen won't do anything.  It should
  2486.            raise it to the top. */
  2487.         XMapRaised(XtDisplay(m_widget), XtWindow(m_widget));
  2488.     }
  2489. }
  2490.  
  2491. void
  2492. XFE_Frame::hide()
  2493. {
  2494.     if (m_ismodal)
  2495.         XtUnmanageChild(m_chromeparent);
  2496.     else
  2497.         XtPopdown(m_widget);
  2498. }
  2499.  
  2500. XP_Bool
  2501. XFE_Frame::isShown()
  2502. {
  2503.     if (!XfeIsAlive(m_widget))
  2504.     {
  2505.         return False;
  2506.     }
  2507.  
  2508.     // This is safer cause it checks for the window's viewable attribute.
  2509.     //return XfeIsViewable(m_widget);
  2510.  
  2511.     return XfeShellIsPoppedUp(m_widget);
  2512. }
  2513.  
  2514.  
  2515. ///////////////////////////////////////////
  2516. //
  2517.  
  2518. void XFE_Frame::showTitleBar()
  2519.  
  2520. //
  2521. // description:
  2522. //        Show the title bar and all other window manager decorations.
  2523. //
  2524. // reference:
  2525. //        Motif Reference Manual 1.2 p431
  2526. //
  2527. // returns:
  2528. //        n/a
  2529. //
  2530. ////
  2531. {
  2532.   int decoration;
  2533.  
  2534.   //
  2535.   // The following code works for the Motif Window Manager (mwm)
  2536.   //
  2537.  
  2538.   decoration = MWM_DECOR_BORDER
  2539.     | MWM_DECOR_RESIZEH
  2540.     | MWM_DECOR_TITLE
  2541.     | MWM_DECOR_MENU
  2542.     | MWM_DECOR_MINIMIZE
  2543.     | MWM_DECOR_MAXIMIZE;
  2544.  
  2545.   XtVaSetValues(m_widget, XmNmwmDecorations, decoration, NULL);
  2546. }
  2547.  
  2548.  
  2549.  
  2550. ///////////////////////////////////////////
  2551. //
  2552.  
  2553. void XFE_Frame::hideTitleBar()
  2554.  
  2555. //
  2556. // description:
  2557. //        Hide the title bar and all other window manager decorations.
  2558. //        Separate functions for showTitleBar and hideTitleBar are implemented
  2559. //        for uniformity with XFE_Frame::show() and XFE_Frame::hide().
  2560. //
  2561. // reference:
  2562. //        Motif Reference Manual 1.2 p431
  2563. //
  2564. // returns:
  2565. //        n/a
  2566. //
  2567. ////
  2568. {
  2569.   int decoration;
  2570.  
  2571.   //
  2572.   // The following code works for the Motif Window Manager (mwm)
  2573.   //
  2574.  
  2575.   decoration = MWM_DECOR_BORDER
  2576.     | MWM_DECOR_RESIZEH
  2577.     | MWM_DECOR_TITLE
  2578.     | MWM_DECOR_MENU
  2579.     | MWM_DECOR_MINIMIZE
  2580.     | MWM_DECOR_MAXIMIZE;
  2581.  
  2582.   decoration |= MWM_DECOR_ALL;  // add this flag to hide
  2583.  
  2584.   XtVaSetValues(m_widget, XmNmwmDecorations, decoration, NULL);
  2585. }
  2586.  
  2587.  
  2588. ///////////////////////////////////////////
  2589. // begin:
  2590.  
  2591. XP_Bool XFE_Frame::isTitleBarShown()
  2592.  
  2593. //
  2594. // description:
  2595. //        Determine if the title bar and other
  2596. //        window manager decorations are visible.
  2597. //
  2598. // returns:
  2599. //        TRUE or FALSE
  2600. //
  2601. ////
  2602. {
  2603.   XP_Bool result = TRUE;
  2604.   int     decoration;
  2605.  
  2606.   //
  2607.   // works for mwm only
  2608.   //
  2609.  
  2610.   decoration = 0;
  2611.   XtVaGetValues(m_widget, XmNmwmDecorations, &decoration, NULL);
  2612.  
  2613.   if (decoration & MWM_DECOR_ALL)
  2614.     result = FALSE;
  2615.  
  2616.   return result;
  2617. }
  2618.  
  2619.  
  2620.  
  2621. void
  2622. XFE_Frame::queryChrome(Chrome * chrome)
  2623. {
  2624.   fe_ContextData *  context_data;
  2625.   Dimension view_width;
  2626.   Dimension view_height;
  2627.   Widget widget;
  2628.  
  2629.   if (!chrome)
  2630.     return;
  2631.  
  2632.   memset(chrome, 0, sizeof (Chrome));
  2633.   context_data = CONTEXT_DATA(m_context);
  2634.  
  2635.   chrome->show_button_bar        = m_toolbar && m_toolbar->isShown();
  2636.   chrome->show_bottom_status_bar = m_dashboard && m_dashboard->isShown();
  2637.   chrome->show_menu              = m_menubar && m_menubar->isShown();
  2638. #ifndef NO_SECURITY
  2639.   chrome->show_security_bar      = context_data->show_security_bar_p;
  2640. #endif /* ! NO_SECURITY */
  2641.  
  2642.   if (isTitleBarShown())
  2643.     chrome->hide_title_bar = FALSE;
  2644.   else
  2645.     chrome->hide_title_bar = TRUE;
  2646.  
  2647.   chrome->l_hint             = getX();
  2648.   chrome->t_hint             = getY();
  2649.   chrome->location_is_chrome = TRUE;
  2650.   chrome->outw_hint          = getWidth();
  2651.   chrome->outh_hint          = getHeight();
  2652.  
  2653.   widget = m_view->getBaseWidget();
  2654.   XtVaGetValues(widget, XtNwidth, &view_width, XtNheight, &view_height, 0);
  2655.  
  2656.   chrome->w_hint             = (int32)view_width;
  2657.   chrome->h_hint             = (int32)view_height;
  2658.  
  2659.   //
  2660.   // 10-Mar-97.  The X Window System doesn't allow clients
  2661.   // to maintain fixed stacking order.  The values set here
  2662.   // may not reflect the actual state of the screen.
  2663.   //
  2664.   chrome->topmost        = m_topmost;
  2665.   chrome->bottommost     = m_bottommost;
  2666.   chrome->z_lock         = m_zlock;
  2667.   chrome->show_scrollbar = m_view->getScrollbarsActive();
  2668. }
  2669.  
  2670. void
  2671. XFE_Frame::respectChrome(Chrome * chrome)
  2672. {
  2673.   Widget widget;
  2674.  
  2675.   if (!chrome)
  2676.     return;
  2677.  
  2678.   widget = m_view->getBaseWidget();
  2679.  
  2680.   // Set width and height of view
  2681.   if (chrome->w_hint > 0 && chrome->h_hint > 0)    {
  2682.       XtVaSetValues(m_widget, XmNallowShellResize, TRUE, 0);
  2683.       XtVaSetValues(widget, XmNwidth, chrome->w_hint,
  2684.                     XmNheight, chrome->h_hint, 0);
  2685.       XtVaSetValues(m_widget, XmNallowShellResize, FALSE, 0);
  2686.   }
  2687.  
  2688.   m_view->setScrollbarsActive(chrome->show_scrollbar);
  2689.  
  2690.   if (chrome->hide_title_bar)
  2691.     hideTitleBar();
  2692.   else
  2693.     showTitleBar();
  2694.  
  2695.  
  2696.   // Respect the tool bar - aka button bar - chrome
  2697.   if (m_toolbar) {
  2698.     if (chrome->show_button_bar)
  2699.         m_toolbar->show();
  2700.     else
  2701.         m_toolbar->hide();
  2702.   }
  2703.  
  2704.   if (m_dashboard) {
  2705.     if (chrome->show_bottom_status_bar)
  2706.         m_dashboard->show();
  2707.     else
  2708.         m_dashboard->hide();
  2709.   }
  2710.  
  2711.   if (m_menubar) {
  2712.     if (chrome->show_menu)
  2713.         m_menubar->show();
  2714.     else
  2715.         m_menubar->hide();
  2716.   }
  2717.  
  2718.   if (chrome->location_is_chrome){
  2719.     position(chrome->l_hint, chrome->t_hint);
  2720.   }
  2721.  
  2722.   // Set width and height of whole frame
  2723.   if (chrome->outw_hint > 0 && chrome->outh_hint > 0)    {
  2724.       setWidth(chrome->outw_hint);
  2725.       setHeight(chrome->outh_hint);
  2726.     }
  2727.  
  2728.   m_hotkeysdisabled = chrome->disable_commands;
  2729.  
  2730.   // Add z order support if needed
  2731.   m_topmost     = chrome->topmost;
  2732.   m_bottommost  = chrome->bottommost;
  2733.   m_zlock       = chrome->z_lock;
  2734.  
  2735.   if (XtIsTopLevelShell(m_widget) && XtIsRealized(m_widget))
  2736.   {
  2737.       zaxis_AddSupport();
  2738.   }
  2739.   
  2740.   if (XtIsRealized(m_widget)) {
  2741.     if (m_topmost)
  2742.       XRaiseWindow(XtDisplay(m_widget), XtWindow(m_widget));
  2743.     else if (m_bottommost)
  2744.       XLowerWindow(XtDisplay(m_widget), XtWindow(m_widget));
  2745.   }
  2746.  
  2747.   // Do the attachments just in case
  2748.   doAttachments();
  2749. }
  2750.  
  2751. XFE_View *
  2752. XFE_Frame::getView()
  2753. {
  2754.     return m_view;
  2755. }
  2756.  
  2757. //////////////////////////////////////////////////////////////////////////
  2758. //
  2759. // Toolbox notices
  2760. //
  2761. //////////////////////////////////////////////////////////////////////////
  2762. XFE_CALLBACK_DEFN(XFE_Frame, toolboxSnapNotice)
  2763.     (XFE_NotificationCenter *    /* obj */, 
  2764.      void *                        /* clientData */, 
  2765.      void *                        callData)
  2766. {
  2767.     // If a the frame was constructed with a chromespec, then we ignore
  2768.     // all the preference magic.
  2769.     if (m_chromespec_provided)
  2770.     {
  2771.         return;
  2772.     }
  2773.  
  2774.     XFE_ToolboxItem * item = (XFE_ToolboxItem *) callData;
  2775.  
  2776.     XP_ASSERT( item != NULL );
  2777.  
  2778.     toolboxItemSnap(item);
  2779. }
  2780. //////////////////////////////////////////////////////////////////////////
  2781. XFE_CALLBACK_DEFN(XFE_Frame, toolboxSwapNotice)
  2782.     (XFE_NotificationCenter *    /* obj */, 
  2783.      void *                        /* clientData */, 
  2784.      void *                         callData)
  2785. {
  2786.     configureLogo();
  2787.  
  2788.     // If a the frame was constructed with a chromespec, then we ignore
  2789.     // all the preference magic.
  2790.     if (m_chromespec_provided)
  2791.     {
  2792.         return;
  2793.     }
  2794.  
  2795.     XFE_ToolboxItem * item = (XFE_ToolboxItem *) callData;
  2796.  
  2797.     XP_ASSERT( item != NULL );
  2798.  
  2799.     toolboxItemSwap(item);
  2800. }
  2801. //////////////////////////////////////////////////////////////////////////
  2802. XFE_CALLBACK_DEFN(XFE_Frame, toolboxCloseNotice)
  2803.     (XFE_NotificationCenter *    /* obj */, 
  2804.      void *                        /* clientData */, 
  2805.      void *                        callData)
  2806. {
  2807.     configureLogo();
  2808.  
  2809.     // If a the frame was constructed with a chromespec, then we ignore
  2810.     // all the preference magic.
  2811.     if (m_chromespec_provided)
  2812.     {
  2813.         return;
  2814.     }
  2815.  
  2816.     XFE_ToolboxItem * item = (XFE_ToolboxItem *) callData;
  2817.  
  2818.     XP_ASSERT( item != NULL );
  2819.  
  2820.     toolboxItemClose(item);
  2821. }
  2822. //////////////////////////////////////////////////////////////////////////
  2823. XFE_CALLBACK_DEFN(XFE_Frame, toolboxOpenNotice)
  2824.     (XFE_NotificationCenter *    /* obj */, 
  2825.      void *                        /* clientData */, 
  2826.      void *                        callData)
  2827. {
  2828.     configureLogo();
  2829.  
  2830.     // If a the frame was constructed with a chromespec, then we ignore
  2831.     // all the preference magic.
  2832.     if (m_chromespec_provided)
  2833.     {
  2834.         return;
  2835.     }
  2836.  
  2837.     XFE_ToolboxItem * item = (XFE_ToolboxItem *) callData;
  2838.  
  2839.     XP_ASSERT( item != NULL );
  2840.  
  2841.     toolboxItemOpen(item);
  2842. }
  2843. //////////////////////////////////////////////////////////////////////////
  2844.  
  2845. //////////////////////////////////////////////////////////////////////////
  2846. //
  2847. // Toolbox methods
  2848. //
  2849. //////////////////////////////////////////////////////////////////////////
  2850. void
  2851. XFE_Frame::toolboxItemSnap(XFE_ToolboxItem * item)
  2852. {
  2853.     XP_ASSERT( item != NULL );
  2854. }
  2855. //////////////////////////////////////////////////////////////////////////
  2856. void
  2857. XFE_Frame::toolboxItemSwap(XFE_ToolboxItem * item)
  2858. {
  2859.     XP_ASSERT( item != NULL );
  2860. }
  2861. //////////////////////////////////////////////////////////////////////////
  2862. void
  2863. XFE_Frame::toolboxItemClose(XFE_ToolboxItem * item)
  2864. {
  2865.     XP_ASSERT( item != NULL );
  2866. }
  2867. //////////////////////////////////////////////////////////////////////////
  2868. void
  2869. XFE_Frame::toolboxItemOpen(XFE_ToolboxItem * item)
  2870. {
  2871.     XP_ASSERT( item != NULL );
  2872. }
  2873. //////////////////////////////////////////////////////////////////////////
  2874. void
  2875. XFE_Frame::toolboxItemChangeShowing(XFE_ToolboxItem * item)
  2876. {
  2877.     XP_ASSERT( item != NULL );
  2878. }
  2879. //////////////////////////////////////////////////////////////////////////
  2880. void
  2881. XFE_Frame::configureLogo()
  2882. {
  2883.     if (!m_toolbox)
  2884.     {
  2885.         return;
  2886.     }
  2887.  
  2888.     XP_ASSERT( m_toolbox != NULL );
  2889.  
  2890.     XFE_Logo * old_logo = m_activeLogo;
  2891.     XFE_Logo * new_logo = getLogo();
  2892.  
  2893.     // Assign the new active logo
  2894.     m_activeLogo = new_logo;
  2895.  
  2896.     // Make sure the logo changed before reconfiguring it
  2897.     if (old_logo == new_logo)
  2898.     {
  2899.         return;
  2900.     }
  2901.  
  2902.     if (old_logo && new_logo)
  2903.     {
  2904.         // Make sure the new logo is the same type as the old one
  2905.         new_logo->setType(old_logo->getType());
  2906.  
  2907.         // If the old logo is running, stop it and continue on the new one
  2908.         if (old_logo->isRunning())
  2909.         {
  2910.             new_logo->setCurrentFrame(old_logo->getCurrentFrame());
  2911.  
  2912.             old_logo->stop();
  2913.  
  2914.             new_logo->start();
  2915.         }
  2916.     }
  2917.  
  2918.     Cardinal                i;
  2919.     XFE_ToolboxItem *    first;
  2920.  
  2921.     // Get the first item that is visible
  2922.     first = m_toolbox->firstOpenAndManagedItem();
  2923.  
  2924.     // Hide the logos of all the non-first items
  2925.     for(i = 0; i < m_toolbox->getNumItems(); i++)
  2926.     {
  2927.         XFE_ToolboxItem * item = m_toolbox->getItemAtIndex(i);
  2928.  
  2929.         if (item)
  2930.         {
  2931.             if (item != first)
  2932.             {
  2933.                 item->hideLogo();
  2934.             }
  2935.         }
  2936.     }
  2937.  
  2938.     // Show the logo of the first item
  2939.     if (first)
  2940.     {
  2941.         first->showLogo();
  2942.     }
  2943. }
  2944. //////////////////////////////////////////////////////////////////////////
  2945. XFE_Logo *
  2946. XFE_Frame::getLogo()
  2947. {
  2948.     if (!m_toolbox)
  2949.     {
  2950.         return NULL;
  2951.     }
  2952.  
  2953.     XP_ASSERT( m_toolbox != NULL );
  2954.  
  2955.     XFE_Logo *                logo = NULL;
  2956.     XFE_ToolboxItem *    item = m_toolbox->firstOpenAndManagedItem();
  2957.  
  2958.     if (item)
  2959.     {
  2960.         logo = item->getLogo();
  2961.     }
  2962.  
  2963.     return logo;
  2964. }
  2965. //////////////////////////////////////////////////////////////////////////
  2966. XFE_Dashboard *
  2967. XFE_Frame::getDashboard()
  2968. {
  2969.     return m_dashboard;
  2970. }
  2971. //////////////////////////////////////////////////////////////////////////
  2972. void
  2973. XFE_Frame::configureToolbox()
  2974. {
  2975.     XP_ASSERT( m_toolbox != NULL );
  2976. }
  2977. //////////////////////////////////////////////////////////////////////////
  2978.  
  2979. /* use this method to position a frame before it actually pops up.  Let's
  2980.    us bypass interactive placement in window managers that use it. */
  2981. void
  2982. XFE_Frame::position(int x, int y)
  2983. {
  2984.     WMShellWidget wmshell = (WMShellWidget) m_widget;
  2985.     XSizeHints    size_hints;
  2986.     Boolean       is_realized;
  2987.  
  2988.     XtVaSetValues (m_widget, XtNx, x, XtNy, y, 0);
  2989.  
  2990.     /* Horrific kludge because Xt is difficult */
  2991.     wmshell->wm.size_hints.flags &= (~PPosition);
  2992.     wmshell->wm.size_hints.flags |= USPosition;
  2993.  
  2994.     /*
  2995.      * Assigning the wm.size_hints above is
  2996.      * apparently sufficient if the widget
  2997.      * hasn't been realized.
  2998.      */
  2999.     is_realized = XtIsRealized(m_widget);
  3000.     if (is_realized) {
  3001.       Display *     display;
  3002.       Window        window;
  3003.       Status        status;
  3004.  
  3005.       display = XtDisplay(m_widget);
  3006.       window  = XtWindow(m_widget);
  3007.       status  = XGetNormalHints(display, window, &size_hints);
  3008.  
  3009.       if (status) {
  3010.         size_hints.x = wmshell->wm.size_hints.x;
  3011.         size_hints.y = wmshell->wm.size_hints.y;
  3012.         size_hints.flags &= (~PPosition);
  3013.         size_hints.flags |= USPosition;
  3014.  
  3015.         XSetNormalHints (display, window, &size_hints);
  3016.       }
  3017.  
  3018.       /* if we were initially created offscreen (we are not visible) and 
  3019.          positioned onscreen, and we aren't mapped, we need to actually map
  3020.          the window. */
  3021.       if (m_lhint < 0 &&
  3022.           m_thint < 0 &&
  3023.           !XfeIsViewable(m_widget) &&
  3024.           x + getWidth() > 0 &&
  3025.           y + getHeight() > 0)
  3026.         {
  3027.           D(printf ("Showing window, since the hints were offscreen and it's now on screen \n");)
  3028.           map();
  3029.         }
  3030.     }
  3031. }
  3032.  
  3033. void
  3034. XFE_Frame::resize(int width, int height)
  3035. {
  3036.     setWidth(width);
  3037.     setHeight(height);  
  3038. }
  3039.  
  3040. int
  3041. XFE_Frame::getX()
  3042. {
  3043.   return (int) XfeX(m_widget);
  3044. }
  3045.  
  3046. int
  3047. XFE_Frame::getY()
  3048. {
  3049.   return (int) XfeY(m_widget);
  3050. }
  3051.  
  3052. int
  3053. XFE_Frame::getWidth()
  3054. {
  3055.     return XfeWidth(m_widget);
  3056. }
  3057.  
  3058. int
  3059. XFE_Frame::getHeight()
  3060. {
  3061.     return XfeHeight(m_widget);
  3062. }
  3063.  
  3064. void
  3065. XFE_Frame::setWidth(int width)
  3066. {
  3067.     XtVaSetValues(m_widget,
  3068.                   XmNwidth, width,
  3069.                   NULL);
  3070. }
  3071.  
  3072. void
  3073. XFE_Frame::setHeight(int height)
  3074. {
  3075.     XtVaSetValues(m_widget,
  3076.                   XmNheight, height,
  3077.                   NULL);
  3078. }
  3079.  
  3080. Widget
  3081. XFE_Frame::getViewParent()
  3082. {
  3083.     return m_viewparent;
  3084. }
  3085.  
  3086. Widget
  3087. XFE_Frame::getMainForm()
  3088. {
  3089.     return m_mainform;
  3090. }
  3091.  
  3092. Widget
  3093. XFE_Frame::getChromeParent()
  3094. {
  3095.     return m_chromeparent;
  3096. }
  3097.  
  3098. Widget
  3099. XFE_Frame::getDialogParent()
  3100. {
  3101.     return XfeGetParentDialog(m_widget);
  3102. }
  3103.  
  3104. fe_colormap *
  3105. XFE_Frame::getColormap()
  3106. {
  3107.     return m_cmap;
  3108. }
  3109.  
  3110. MWContext *
  3111. XFE_Frame::getContext()
  3112. {
  3113.     return m_context;
  3114. }
  3115.  
  3116. void
  3117. XFE_Frame::setView(XFE_View *new_view)
  3118. {
  3119.     XP_ASSERT(m_view == NULL);
  3120.  
  3121.     m_view = new_view;
  3122.  
  3123.     doAttachments();
  3124. }
  3125.  
  3126. void
  3127. XFE_Frame::setAboveViewArea(XFE_Component *above_view)
  3128. {
  3129.     m_aboveview = above_view;
  3130.     doAttachments();
  3131. }
  3132.  
  3133. void
  3134. XFE_Frame::setBelowViewArea(XFE_Component *below_view)
  3135. {
  3136.     m_belowview = below_view;
  3137.     doAttachments();
  3138. }
  3139.  
  3140. void
  3141. XFE_Frame::setTitle(char *title)
  3142. {
  3143.   XFE_SetDocTitle(m_context, title);
  3144. }
  3145.  
  3146. const char *
  3147. XFE_Frame::getTitle()
  3148. {
  3149.     char * title;
  3150.  
  3151.     XtVaGetValues(m_widget,XmNtitle,&title,NULL);
  3152.  
  3153.     return (const char *) title;
  3154. }
  3155.  
  3156. void
  3157. XFE_Frame::setIconTitle(const char */*icon_title*/)
  3158. {
  3159. }
  3160.  
  3161. void
  3162. XFE_Frame::setIconPixmap(fe_icon */*icon*/)
  3163. {
  3164. }
  3165.  
  3166. XFE_View *
  3167. XFE_Frame::widgetToView(Widget w)
  3168. {
  3169.     return m_view->widgetToView(w);
  3170. }
  3171.  
  3172. XP_Bool
  3173. XFE_Frame::hotKeysDisabled()
  3174. {
  3175.     return m_hotkeysdisabled;
  3176. }
  3177.  
  3178. XP_Bool
  3179. XFE_Frame::isCommandSelected(CommandType cmd,
  3180.                              void *calldata, XFE_CommandInfo* info)
  3181. {
  3182.     XFE_Command* handler = getCommand(cmd);
  3183.  
  3184.     if (handler != NULL)
  3185.         return handler->isSelected(this, info);
  3186.  
  3187.     /* This method is designed for toggle button */
  3188.     /* We want to keep the toggle button to have the same state
  3189.      as its matched view */
  3190.     // special hack for the history menu.
  3191.     if (cmd == xfeCmdOpenUrl)
  3192.     {
  3193.         return True;
  3194.     }
  3195.     else if (cmd == xfeCmdFloatingTaskBarAlwaysOnTop)
  3196.     {
  3197.         return fe_globalPrefs.task_bar_ontop;
  3198.     }
  3199.  
  3200.     return (m_view && m_view->isCommandSelected(cmd, calldata, info));
  3201. }
  3202.  
  3203. XP_Bool
  3204. XFE_Frame::isCommandEnabled(CommandType cmd,
  3205.                             void *calldata, XFE_CommandInfo* info)
  3206. {
  3207.     XFE_Command* handler = getCommand(cmd);
  3208.  
  3209.     if (handler != NULL)
  3210.         return handler->isEnabled(this, info);
  3211.  
  3212.     /* first we handle the commands we know about.. */
  3213.     if (cmd == xfeCmdAboutMozilla
  3214.         || cmd == xfeCmdOpenTargetUrl
  3215.         || cmd == xfeCmdExit
  3216.         || cmd == xfeCmdOpenBookmarks
  3217.         || cmd == xfeCmdOpenBrowser
  3218.         || cmd == xfeCmdOpenCustomUrl
  3219.         || cmd == xfeCmdOpenOrBringUpBrowser
  3220.         || cmd == xfeCmdToggleMenubar
  3221.         || cmd == xfeCmdToggleNavigationToolbar
  3222.         || cmd == xfeCmdWindowListRaiseItem
  3223. #ifdef MOZ_MAIL_NEWS
  3224.         || cmd == xfeCmdComposeMessage
  3225.         || cmd == xfeCmdComposeMessageHTML
  3226.         || cmd == xfeCmdComposeMessagePlain
  3227.         || cmd == xfeCmdOpenAddressBook
  3228.         || cmd == xfeCmdOpenInbox
  3229.         || cmd == xfeCmdOpenInboxAndGetNewMessages
  3230.         || cmd == xfeCmdOpenFolders
  3231.         || cmd == xfeCmdOpenNewsgroups
  3232. #endif
  3233.         || cmd == xfeCmdOpenNavCenter
  3234.         )
  3235.         {
  3236.             return TRUE;
  3237.         }
  3238. #ifdef EDITOR
  3239.     else if (cmd == xfeCmdOpenEditor
  3240.              || cmd == xfeCmdNewBlank
  3241.              || cmd == xfeCmdEditPage
  3242.              || cmd == xfeCmdNewTemplate
  3243.              || cmd == xfeCmdNewWizard
  3244.              )
  3245.         {
  3246.             return ( !fe_IsEditorDisabled() );
  3247.         }
  3248.     else if (cmd == xfeCmdEditFrame)
  3249.         {
  3250.             return fe_IsGridParent(m_context) && !fe_IsEditorDisabled();
  3251.         }
  3252. #endif
  3253.     else if (cmd == xfeCmdJavaConsole)
  3254.         {
  3255. #ifdef JAVA
  3256.             return TRUE;
  3257. #else
  3258.             return FALSE;
  3259. #endif
  3260.         }
  3261.     else if (cmd == xfeCmdOpenConference)
  3262.         {
  3263.             return fe_IsConferenceInstalled();
  3264.         }
  3265.     else if (cmd == xfeCmdOpenNetcaster)
  3266.         {
  3267. #ifdef MOZ_NETCAST
  3268.             return fe_IsNetcasterInstalled();
  3269. #else
  3270.             return FALSE;
  3271. #endif
  3272.         }
  3273.     else if (cmd == xfeCmdOpenCalendar)
  3274.         {
  3275.             /* check if calendar is installed */
  3276.             return fe_IsCalendarInstalled();
  3277.         }
  3278.     else if (cmd == xfeCmdOpenHostOnDemand)
  3279.         {
  3280.             /* check if IBM Host On_Demand is installed */
  3281.             return fe_IsHostOnDemandInstalled();
  3282.         }
  3283. #ifdef MOZ_TASKBAR
  3284.     if (cmd == xfeCmdToggleTaskbarShowing ||
  3285.         cmd == xfeCmdFloatingTaskBarHorizontal ||
  3286.         cmd == xfeCmdFloatingTaskBarAlwaysOnTop ||
  3287.         cmd == xfeCmdFloatingTaskBarClose)
  3288.     {
  3289.         return XFE_Dashboard::floatingTaskBarIsAlive();
  3290.     }
  3291. #endif
  3292.     else if (cmd == xfeCmdClose)
  3293.         {
  3294.             // only enable this menu item if we're not the last window up.
  3295.             return (XFE_MozillaApp::theApp()->toplevelWindowCount() != 1);
  3296.         }
  3297.     else if (cmd == xfeCmdOpenHistory)
  3298.         {
  3299.             return !fe_globalData.all_databases_locked;
  3300.         }
  3301.     else
  3302.         {
  3303.             return (m_view && m_view->isCommandEnabled(cmd, calldata, info));
  3304.         }
  3305. }
  3306.  
  3307. //
  3308. //    Wrapper function that does accounting functions.
  3309. //
  3310. void
  3311. xfe_ExecuteCommand(XFE_Frame* frame,
  3312.                    CommandType cmd, void* cd, XFE_CommandInfo* info)
  3313. {
  3314.     XP_Bool slow = TRUE;
  3315.  
  3316.     XFE_Command* handler = frame->getCommand(cmd);
  3317.  
  3318.     if ((handler != NULL && handler->isSlow() != TRUE) ||
  3319.         //
  3320.         //    This is because ComposeFrame/ComposeView have this special
  3321.         //    handling of these commands (which have handlers, but don't
  3322.         //    want to admit it in open public.
  3323.         //
  3324.         cmd == xfeCmdCut        ||
  3325.         cmd == xfeCmdCopy       ||
  3326.         cmd == xfeCmdPaste      ||
  3327.         cmd == xfeCmdDeleteItem ||
  3328.         cmd == xfeCmdSelectAll  ||
  3329.         cmd == xfeCmdUndo) {
  3330.         slow = FALSE;
  3331.     }
  3332.  
  3333.     if (slow)
  3334.         XmUpdateDisplay(frame->getBaseWidget());
  3335.  
  3336.     //
  3337.     //    don't do notifies when exiting, they may be delivered to
  3338.     //    stuff that isn't there any more.
  3339.     //
  3340.     if (cmd == xfeCmdExit || cmd == xfeCmdClose)
  3341.         slow = FALSE;
  3342.  
  3343.     if (slow)
  3344.         frame->notifyInterested(XFE_Frame::frameBusyCallback);
  3345.  
  3346.     if (handler != NULL)
  3347.         handler->doCommand(frame, info);
  3348.     else
  3349.         frame->doCommand(cmd, cd, info);
  3350.  
  3351.     if (slow)
  3352.         frame->notifyInterested(XFE_Frame::frameNotBusyCallback);
  3353. }
  3354.  
  3355. void
  3356. XFE_Frame::doCommand(CommandType cmd, void *calldata, XFE_CommandInfo* info)
  3357. {
  3358.     XmUpdateDisplay(m_widget);
  3359.  
  3360.     /* first we handle the commands we know about. */
  3361.     D(    printf ("in XFE_Frame::doCommand()\n");)
  3362.  
  3363.     XFE_Command* handler = getCommand(cmd);
  3364.     if (handler != NULL) {
  3365.         handler->doCommand(this, info);
  3366.     } else if (cmd == xfeCmdToggleMenubar)
  3367.             {
  3368.                 if (m_menubar)
  3369.                     {
  3370.                         if (m_menubar->isShown())
  3371.                             m_menubar->hide();
  3372.                         else
  3373.                             m_menubar->show();
  3374.  
  3375.                         // there should probably another way to do this...  This seems fairly
  3376.                         // expensive.
  3377.                         doAttachments();
  3378.  
  3379.                         notifyInterested(XFE_View::chromeNeedsUpdating);
  3380.                     }
  3381.             }
  3382.         else if (cmd == xfeCmdToggleNavigationToolbar)
  3383.             {
  3384.                 if (m_toolbar)
  3385.                     {
  3386.                       m_toolbar->toggle();
  3387.                       
  3388.                       // Configure the logo
  3389.                       configureLogo();
  3390.                       
  3391.                       // Do the attachments
  3392.                       doAttachments();
  3393.  
  3394.                       // Update prefs
  3395.                       toolboxItemChangeShowing(m_toolbar);
  3396.                       
  3397.                       notifyInterested(XFE_View::chromeNeedsUpdating);
  3398.                     }
  3399.             }
  3400. #ifdef MOZ_TASKBAR
  3401.         else if (cmd == xfeCmdToggleTaskbarShowing)
  3402.         {
  3403.             XFE_Dashboard::toggleTaskBar();
  3404.         }
  3405.         else if (cmd == xfeCmdFloatingTaskBarHorizontal)
  3406.         {
  3407.             XFE_Dashboard::setFloatingTaskBarHorizontal(!fe_globalPrefs.task_bar_horizontal);
  3408.         }
  3409.         else if (cmd == xfeCmdFloatingTaskBarAlwaysOnTop)
  3410.         {
  3411.             XFE_Dashboard::setFloatingTaskBarOnTop(!fe_globalPrefs.task_bar_ontop);
  3412.         }
  3413.         else if (cmd == xfeCmdFloatingTaskBarClose)
  3414.         {
  3415.             XFE_Dashboard::dockTaskBar();
  3416.         }
  3417. #endif
  3418.         else if (cmd == xfeCmdExit)
  3419.             {
  3420.                 //
  3421.                 //    First check the confirmExit resource, maybe post a warning
  3422.                 //    alert. Allows the user to back out of exit.
  3423.                 //
  3424.                 MWContext* context = getContext();
  3425.                 if (!CONTEXT_DATA(context)->confirm_exit_p ||
  3426.                     FE_Confirm(context, fe_globalData.really_quit_message)) {
  3427.                     XFE_MozillaApp::theApp()->exit(0);
  3428.                 }
  3429.             }
  3430.         else if (cmd == xfeCmdClose)
  3431.             {
  3432.                 if (m_destroyOnClose)
  3433.                     delete_response();
  3434.                 else
  3435.                     hide();
  3436.             }
  3437. #ifdef MOZ_MAIL_NEWS
  3438.             else if ( cmd == xfeCmdComposeMessage)
  3439.             {
  3440.               if (info) {
  3441.                   CONTEXT_DATA(m_context)->stealth_cmd =
  3442.                       ((info->event->type == ButtonRelease) &&
  3443.                        (info->event->xkey.state & ShiftMask));
  3444.               }
  3445.  
  3446.               MSG_Mail(m_context);
  3447.                   }
  3448.         else if ( cmd == xfeCmdComposeMessageHTML)
  3449.                 {
  3450.                 CONTEXT_DATA(m_context)->stealth_cmd = (fe_globalPrefs.send_html_msg == False); 
  3451.                     MSG_Mail(m_context);
  3452.             }
  3453.         else if ( cmd == xfeCmdComposeMessagePlain)
  3454.             {
  3455.                 CONTEXT_DATA(m_context)->stealth_cmd = (fe_globalPrefs.send_html_msg == True) ; 
  3456.                 MSG_Mail(m_context);
  3457.             }        
  3458.         else if (cmd == xfeCmdOpenInbox)
  3459.             {
  3460.                 fe_showInbox(m_toplevelWidget, this, NULL, fe_globalPrefs.reuse_thread_window, False);
  3461.             }
  3462.         else if (cmd == xfeCmdOpenInboxAndGetNewMessages)
  3463.             {
  3464.                 fe_showInbox(m_toplevelWidget, this, NULL, fe_globalPrefs.reuse_thread_window, True);
  3465.             }
  3466.         else if (cmd == xfeCmdOpenFolders)
  3467.             {
  3468.                 fe_showFolders(m_toplevelWidget, this, NULL);
  3469.             }
  3470.         else if (cmd == xfeCmdOpenNewsgroups)
  3471.             {
  3472.                 fe_showNewsgroups(m_toplevelWidget, this, NULL);
  3473.             }
  3474. #endif  // MOZ_MAIL_NEWS
  3475.         else if (cmd == xfeCmdOpenBrowser)
  3476.             {
  3477.                 char*       address = NULL;
  3478.                 URL_Struct* url = NULL;
  3479.  
  3480.                 if (info != NULL && *info->nparams > 0)
  3481.                     address = info->params[0];
  3482.  
  3483.                 if (address != NULL)
  3484.                     url = NET_CreateURLStruct(address, NET_DONT_RELOAD);
  3485.                 else
  3486.                     url = fe_GetBrowserStartupUrlStruct();
  3487.                 
  3488.                 fe_showBrowser(m_toplevelWidget, this, NULL, url);
  3489.             }
  3490.         else if (cmd == xfeCmdOpenNavCenter)
  3491.             {
  3492.               fe_showNavCenter(m_toplevelWidget, this, NULL, NULL/*url*/);
  3493.             }
  3494.         else if (cmd == xfeCmdOpenOrBringUpBrowser)
  3495.             {
  3496.               XFE_BrowserFrame::bringToFrontOrMakeNew(m_toplevelWidget);
  3497.             }
  3498.         else if (cmd == xfeCmdOpenBookmarks)
  3499.             {
  3500.                 fe_showBookmarks(m_toplevelWidget, this, NULL);
  3501.             }
  3502.         else if (cmd == xfeCmdOpenHistory)
  3503.             {
  3504.                 XFE_HistoryFrame::showHistory(m_toplevelWidget, this, NULL);
  3505.             }
  3506. #ifdef MOZ_MAIL_NEWS
  3507.         else if (cmd == xfeCmdOpenAddressBook)
  3508.             {
  3509.                 fe_showAddrBook(m_toplevelWidget, this, NULL);
  3510.             }
  3511.         else if (cmd == xfeCmdOpenConference)
  3512.             {
  3513.                 fe_showConference(getBaseWidget(), 0 /* email */,
  3514.                                   0 /* use */, 0 /* coolAddr */);
  3515.  
  3516.             }
  3517. #endif  // MOZ_MAIL_NEWS
  3518.         else if (cmd == xfeCmdOpenNetcaster)
  3519.             {
  3520. #ifdef MOZ_NETSCAST
  3521.                 fe_showNetcaster(getBaseWidget());
  3522. #endif
  3523.             }
  3524.         else if (cmd == xfeCmdOpenCalendar)
  3525.             {
  3526.                 fe_showCalendar(getBaseWidget());
  3527.             }
  3528.         else if (cmd == xfeCmdOpenHostOnDemand)
  3529.             {
  3530.                 fe_showHostOnDemand();
  3531.             }
  3532.         else if (cmd == xfeCmdOpenMinibuffer)
  3533.             {
  3534.                 XFE_Minibuffer *minibuffer;
  3535.  
  3536.                 if (m_belowview)
  3537.                     delete m_belowview;
  3538.                 
  3539.                 minibuffer = new XFE_Minibuffer(this, getChromeParent());
  3540.                 minibuffer->show();
  3541.                 setBelowViewArea(minibuffer);
  3542.             }
  3543.         else if (cmd == xfeCmdJavaConsole)
  3544.             {
  3545. #ifdef JAVA
  3546.                 fe_new_show_java_console_cb (m_widget, m_context, NULL);
  3547. #endif
  3548.             }
  3549. #ifdef EDITOR 
  3550.         else if (cmd == xfeCmdOpenEditor)
  3551.             {
  3552.                 if (info != NULL && *info->nparams > 0)
  3553.                     fe_EditorNew(m_context, this, NULL, info->params[0]);
  3554.                 else
  3555.                     fe_EditorOpen(m_context, this, /*chromespec=*/NULL);
  3556.             }
  3557.         else if (cmd == xfeCmdNewBlank)
  3558.             {
  3559.                 char* address = NULL;
  3560.  
  3561.                 if (info != NULL && *info->nparams > 0)
  3562.                     address = info->params[0];
  3563.  
  3564.                 fe_EditorNew(m_context, this, /*chromespec=*/NULL, address);
  3565.             }
  3566.         else if (cmd == xfeCmdEditPage)
  3567.             {
  3568.                 char* address = NULL;
  3569.  
  3570.                 if (info != NULL && *info->nparams > 0)
  3571.                     address = info->params[0];
  3572.  
  3573.                 fe_EditorEdit(m_context, this, /*chromespec=*/NULL, address);
  3574.             }
  3575.         else if (cmd == xfeCmdEditFrame)
  3576.             {
  3577.                 MWContext* f_context = fe_GetFocusGridOfContext(m_context);
  3578.         
  3579.                 if (!f_context)
  3580.                     f_context = m_context;
  3581.  
  3582.                 fe_EditorEdit(f_context, this, /*chromespec=*/NULL, NULL);
  3583.             }
  3584.         /*
  3585.          *    Template and Wizard, though considered part of the editor,
  3586.          *    are just a browse to a hard coded url. The user can then choose
  3587.          *    to edit "this page".
  3588.          */
  3589.         else if (cmd == xfeCmdNewTemplate)
  3590.             {
  3591.                 char* address = fe_EditorGetTemplateURL(m_context);
  3592.  
  3593.                 if (address != NULL) {
  3594.                     URL_Struct* url;
  3595.                     url = NET_CreateURLStruct(address, NET_DONT_RELOAD);
  3596.  
  3597.                     fe_showBrowser(m_toplevelWidget, this, NULL, url);
  3598.                 }
  3599.             }
  3600.         else if (cmd == xfeCmdNewWizard)
  3601.             {
  3602.                 char* address = fe_EditorGetWizardURL(m_context);
  3603.  
  3604.                 if (address != NULL) {
  3605.                     URL_Struct* url;
  3606.                     url = NET_CreateURLStruct(address, NET_DONT_RELOAD);
  3607.  
  3608.                     fe_showBrowser(m_toplevelWidget, this, NULL, url);
  3609.                 }
  3610.             }
  3611. #endif
  3612.         else if (cmd == xfeCmdWindowListRaiseItem)
  3613.         {
  3614.             // Right now nothing
  3615.             return;
  3616.         }
  3617.         else if (cmd == xfeCmdAboutMozilla)
  3618.         {
  3619.             fe_about_cb(NULL, m_context, NULL);
  3620.         }
  3621.         else if (cmd == xfeCmdOpenCustomUrl)
  3622.         {
  3623.             MWContext * context = m_context;
  3624.  
  3625.             // We need to make sure the the ekit_LoadCustomUrl() call receives
  3626.             // a valid browser context or else layout will choke looking for 
  3627.             // a html drawing area on non browser contexts.  
  3628.             // (ie, AddressBook, MessageCenter)
  3629.             if (context->type != MWContextBrowser)
  3630.             {
  3631.                 context = fe_FindNonCustomBrowserContext(context);
  3632.             }
  3633.  
  3634.             // Find the top most frame context
  3635.             MWContext * top_context = XP_GetNonGridContext(context);
  3636.  
  3637.             // If a browser context is still not found, create one
  3638.             if (!top_context || (top_context->type != MWContextBrowser))
  3639.             {
  3640.                 top_context = fe_showBrowser(FE_GetToplevelWidget(), 
  3641.                                              NULL, NULL, NULL);
  3642.             }
  3643.  
  3644.             ekit_LoadCustomUrl((char*) calldata, top_context);
  3645.         }
  3646.     else if (cmd == xfeCmdOpenTargetUrl)
  3647.         {
  3648.             fe_openTargetUrl(m_context,(LO_AnchorData *) calldata);
  3649.         }
  3650.         /* if we don't recognize the command, send it along to the view. */
  3651.         else if (m_view 
  3652.                  && m_view->handlesCommand(cmd, calldata, info))
  3653.             {
  3654.                 m_view->doCommand(cmd, calldata, info);
  3655.             }
  3656.         else
  3657.             {
  3658. #if DEBUG
  3659.                 printf ("Command %s not recognized!\n", Command::getString(cmd));
  3660. #endif
  3661.                 
  3662.                 XBell(XtDisplay(m_widget), 100);
  3663.             }
  3664.  
  3665.         D(    printf ("leaving XFE_Frame::doCommand()\n");)
  3666. }
  3667.  
  3668. XP_Bool
  3669. XFE_Frame::handlesCommand(CommandType cmd,
  3670.                           void *calldata, XFE_CommandInfo* info)
  3671. {
  3672.     XFE_Command* handler = getCommand(cmd);
  3673.  
  3674.     if (handler != NULL)
  3675.         return TRUE;
  3676.     /* first we handle the commands we know about.. */
  3677.     if (cmd == xfeCmdAboutMozilla
  3678.         || cmd == xfeCmdClose
  3679.         || cmd == xfeCmdOpenTargetUrl
  3680.         || cmd == xfeCmdExit
  3681.         || cmd == xfeCmdJavaConsole
  3682.         || cmd == xfeCmdOpenBookmarks
  3683.         || cmd == xfeCmdOpenBrowser
  3684.         || cmd == xfeCmdOpenHistory
  3685.         || cmd == xfeCmdOpenOrBringUpBrowser
  3686.         || cmd == xfeCmdOpenCalendar
  3687.         || cmd == xfeCmdOpenConference
  3688.         || cmd == xfeCmdOpenCustomUrl
  3689.         || cmd == xfeCmdOpenHostOnDemand
  3690.         || cmd == xfeCmdOpenNetcaster
  3691.         || cmd == xfeCmdToggleMenubar
  3692.         || cmd == xfeCmdToggleNavigationToolbar
  3693.         || cmd == xfeCmdWindowListRaiseItem
  3694. #ifdef MOZ_TASKBAR
  3695.         || cmd == xfeCmdToggleTaskbarShowing
  3696.         || cmd == xfeCmdFloatingTaskBarHorizontal
  3697.         || cmd == xfeCmdFloatingTaskBarAlwaysOnTop
  3698.         || cmd == xfeCmdFloatingTaskBarClose
  3699. #endif
  3700. #ifdef MOZ_MAIL_NEWS
  3701.         || cmd == xfeCmdComposeMessage
  3702.         || cmd == xfeCmdComposeMessageHTML
  3703.         || cmd == xfeCmdComposeMessagePlain
  3704.         || cmd == xfeCmdEditMailFilterRules
  3705.         || cmd == xfeCmdOpenAddressBook
  3706.         || cmd == xfeCmdOpenFolders
  3707.         || cmd == xfeCmdOpenInbox
  3708.         || cmd == xfeCmdOpenInboxAndGetNewMessages
  3709.         || cmd == xfeCmdOpenNewsgroups
  3710. #endif
  3711.         || cmd == xfeCmdOpenNavCenter
  3712.         )
  3713.         {
  3714.             return TRUE;
  3715.         }
  3716. #ifdef EDITOR
  3717.     else if (cmd == xfeCmdOpenEditor
  3718.              || cmd == xfeCmdNewBlank
  3719.              || cmd == xfeCmdNewTemplate
  3720.              || cmd == xfeCmdNewWizard
  3721.              || cmd == xfeCmdEditPage
  3722.              || cmd == xfeCmdEditFrame
  3723.              )
  3724.         {
  3725.             return ( !fe_IsEditorDisabled() );
  3726.         }
  3727. #endif
  3728.     else
  3729.         {
  3730.             return (m_view && m_view->handlesCommand(cmd, calldata, info));
  3731.         }
  3732. }
  3733.  
  3734. char *
  3735. XFE_Frame::commandToString(CommandType cmd,
  3736.                            void *calldata, XFE_CommandInfo* info)
  3737. {
  3738.     XFE_Command* handler = getCommand(cmd);
  3739.  
  3740.     if (handler != NULL)
  3741.         return handler->getLabel(this, info);
  3742.  
  3743.     if (cmd == xfeCmdComposeMessage)
  3744.         {
  3745.             char *res;
  3746.             res = "composeMessage";
  3747.             return stringFromResource(res);
  3748.         }
  3749.     else if (cmd == xfeCmdToggleMenubar)
  3750.         {
  3751.             char *res = NULL;
  3752.  
  3753.             if (m_menubar->isShown())
  3754.                 res = "hideMenubarCmdString";
  3755.             else
  3756.                 res = "showMenubarCmdString";
  3757.  
  3758.             return stringFromResource(res);
  3759.         }
  3760.     else if (cmd == xfeCmdToggleNavigationToolbar)
  3761.         {
  3762.             char *res = NULL;
  3763.  
  3764.             if (m_toolbar->isShown())
  3765.                 res = "hideNavToolbarCmdString";
  3766.             else
  3767.                 res = "showNavToolbarCmdString";
  3768.  
  3769.             return stringFromResource(res);
  3770.         }
  3771. #ifdef MOZ_TASKBAR
  3772.     else if (cmd == xfeCmdToggleTaskbarShowing)
  3773.     {
  3774.         char *res = NULL;
  3775.         
  3776.         if (XFE_Dashboard::isTaskBarDocked())
  3777.         {
  3778.             res = "showTaskbarCmdString";
  3779.         }
  3780.         else
  3781.         {
  3782.             res = "dockTaskbarCmdString";
  3783.         }
  3784.         
  3785.         return stringFromResource(res);
  3786.     }
  3787.     else if (cmd == xfeCmdFloatingTaskBarHorizontal)
  3788.     {
  3789.         char *res = NULL;
  3790.  
  3791.         // Show the oposite label so that the user can toggle
  3792.         if (fe_globalPrefs.task_bar_horizontal)
  3793.         {
  3794.             res = "floatingTaskBarVerticalCmdString";
  3795.         }
  3796.         else
  3797.         {
  3798.             res = "floatingTaskBarHorizontalCmdString";
  3799.         }
  3800.  
  3801.         return stringFromResource(res);
  3802.     }
  3803. #endif
  3804.     else if (m_view)
  3805.         {
  3806.             return m_view->commandToString(cmd, calldata, info);
  3807.         }
  3808.     else
  3809.         {
  3810.             return NULL;
  3811.         }
  3812. }
  3813.  
  3814. void
  3815. XFE_Frame::setCursor(XP_Bool busy)
  3816. {
  3817.     Cursor c;
  3818.     
  3819.     if (busy)
  3820.         c = CONTEXT_DATA(m_context)->busy_cursor;
  3821.     else
  3822.         c = None;
  3823.     
  3824.     XDefineCursor(XtDisplay(m_widget), XtWindow(m_widget), c);
  3825. }
  3826.  
  3827. XFE_CALLBACK_DEFN(XFE_Frame, updateBusyState)(XFE_NotificationCenter */*obj*/,
  3828.                                               void *clientData,
  3829.                                               void */*callData*/)
  3830. {
  3831.     XP_Bool busy = (XP_Bool)(int)clientData;
  3832.  
  3833.     setCursor(busy);
  3834. }
  3835.  
  3836. XFE_CALLBACK_DEFN(XFE_Frame, doCommandCallback)(XFE_NotificationCenter */*obj*/,
  3837.                                                 void */*clientData*/,
  3838.                                                 void *callData)
  3839. {
  3840.     CommandType cmd = (CommandType)callData;
  3841.  
  3842.     doCommand(cmd);
  3843. }
  3844.  
  3845. XFE_CALLBACK_DEFN(XFE_Frame, toplevelWindowChangeOccured)(XFE_NotificationCenter */*obj*/,
  3846.                                                           void */*clientData*/,
  3847.                                                           void */*callData*/)
  3848. {
  3849.     notifyInterested(XFE_View::commandNeedsUpdating, (void*)xfeCmdClose);
  3850. }
  3851.  
  3852.  
  3853. //
  3854. // Logo animation notifications
  3855. //
  3856. XFE_CALLBACK_DEFN(XFE_Frame, logoAnimationStartNotice)
  3857.     (XFE_NotificationCenter *    /* obj */,
  3858.      void *                        /* clientData */,
  3859.      void *                        /* callData */)
  3860. {
  3861.     XFE_Logo * logo = getLogo();
  3862.  
  3863.     if (logo)
  3864.     {
  3865.         logo->start();
  3866.     }
  3867. }
  3868. //////////////////////////////////////////////////////////////////////////
  3869. XFE_CALLBACK_DEFN(XFE_Frame, logoAnimationStopNotice)
  3870.     (XFE_NotificationCenter *    /* obj */,
  3871.      void *                        /* clientData */,
  3872.      void *                        /* callData */)
  3873. {
  3874.     XFE_Logo * logo = getLogo();
  3875.  
  3876.     if (logo)
  3877.     {
  3878.         logo->stop();
  3879.     }
  3880. }
  3881. //////////////////////////////////////////////////////////////////////////
  3882.  
  3883. char *
  3884. XFE_Frame::prompt(const char *caption, const char *message, const char *deflt)
  3885. {
  3886.     return (char*)fe_prompt(m_context, m_widget, caption, message,
  3887.                             TRUE, (deflt ? deflt : ""), TRUE, FALSE, 0);
  3888. }
  3889.  
  3890. Pixel
  3891. XFE_Frame::getFGPixel()
  3892. {
  3893.     return CONTEXT_DATA(m_context)->fg_pixel;
  3894. }
  3895.  
  3896. Pixel
  3897. XFE_Frame::getBGPixel()
  3898. {
  3899.     return CONTEXT_DATA(m_context)->default_bg_pixel;
  3900. }
  3901.  
  3902. Pixel
  3903. XFE_Frame::getTopShadowPixel()
  3904. {
  3905.     return CONTEXT_DATA(m_context)->top_shadow_pixel;
  3906. }
  3907.  
  3908. Pixel
  3909. XFE_Frame::getBottomShadowPixel()
  3910. {
  3911.     return CONTEXT_DATA(m_context)->bottom_shadow_pixel;
  3912. }
  3913.  
  3914. char *XFE_Frame::getDocString(CommandType cmd)
  3915. {
  3916.     char*        doc_string = NULL;
  3917.     XFE_Command* handler = getCommand(cmd);
  3918.  
  3919.     //    For now impliment info = NULL, because only composer
  3920.     //    plugins are using this, but, really need info..
  3921.     if (handler != NULL)
  3922.         doc_string = handler->getDocString(this, NULL);
  3923.  
  3924.     if (doc_string == NULL) 
  3925.     {
  3926.         doc_string = XfeSubResourceGetStringValue(getBaseWidget(),
  3927.                                                   (char *) cmd,
  3928.                                                   "NSCommand",
  3929.                                                   "documentationString", 
  3930.                                                   "DocumentationString",
  3931.                                                   NULL);
  3932.     }
  3933.  
  3934.     return doc_string;
  3935. }
  3936.  
  3937. char *XFE_Frame::getTipString(CommandType /* cmd */)
  3938. {
  3939.     return NULL;
  3940. }
  3941.  
  3942. //////////////////////////////////////////////////////////////////////////
  3943. //
  3944. // Keep track of the frame shell mapping.  On the first MapNotify, we
  3945. // do a show() on the frame so that all the 
  3946. //
  3947. //////////////////////////////////////////////////////////////////////////
  3948. /* static */ void 
  3949. XFE_Frame::iconicFrameMappingEH(Widget        shell,
  3950.                                 XtPointer    clientData,
  3951.                                 XEvent *    event,
  3952.                                 Boolean *    cont)
  3953. {
  3954.     XFE_Frame * frame = (XFE_Frame *) clientData;
  3955.  
  3956.     if (!frame || (frame && !frame->isAlive()))
  3957.     {
  3958.         return;
  3959.     }
  3960.  
  3961.     if (event && (event->type == MapNotify))
  3962.     {
  3963.         // We only need this event handler to be called once
  3964.         XtRemoveEventHandler(shell,StructureNotifyMask,True,
  3965.                              iconicFrameMappingEH,clientData);
  3966.  
  3967.         frame->show();
  3968.  
  3969.         // show() will not call XtPopup() which is needed in order for 
  3970.         // the proper grab to be done on the shell
  3971.         XtPopup(frame->getBaseWidget(), XtGrabNone);
  3972.  
  3973.     }
  3974.  
  3975.     *cont = True;
  3976. }
  3977. //////////////////////////////////////////////////////////////////////////
  3978.  
  3979. // Display calendar
  3980. extern "C" void fe_showCalendar(Widget w)
  3981. {
  3982.     char execu[1024];
  3983.  
  3984.     // Return if we didn't find calendar.
  3985.     XP_ASSERT(fe_calendar_path);
  3986.     if(!fe_calendar_path) {
  3987.         return;
  3988.     }
  3989.  
  3990.     XP_STRCPY(execu, fe_calendar_path);
  3991.  
  3992. #if defined(IRIX)
  3993.     pid_t mypid = fork();
  3994. #else
  3995.     pid_t mypid = vfork();
  3996. #endif
  3997.     if (mypid == 0) {
  3998.  
  3999. #if defined(DEBUG_lwei)
  4000.         printf("\n Child : mypid=%d \n", mypid);
  4001.         printf("\n *** calendar=%s\n", execu);
  4002. #endif
  4003.         close (ConnectionNumber(XtDisplay(w)));
  4004.  
  4005.         /* 
  4006.          * int execlp (const char *file, const char *arg0, ..., 
  4007.          * int execvp (const char *file, char *const *argv);
  4008.          * const char *argn, (char *)0);
  4009.          */
  4010.         execlp(execu, execu, 0);
  4011.         execlp(execu, execu, 0);
  4012.  
  4013. #if defined(DEBUG_lwei)
  4014.         printf("\nExiting calendar \n");
  4015. #endif
  4016.         _exit(0);
  4017.     }/* if */
  4018. #if defined(DEBUG_lwei)
  4019.     else if (mypid > 0) {
  4020.         printf("\n Parent: child's mypid=%d \n", mypid);
  4021.     }/* else */
  4022. #endif
  4023.     else if (mypid < 0)
  4024.         printf("\n ERROR: can not fork! \n");
  4025.     
  4026. }/* fe_showCalendar() */
  4027.  
  4028.  
  4029. // Display Host On-Demand
  4030. extern "C" void fe_showHostOnDemand()
  4031. {
  4032.     MWContext *context = XP_GetNonGridContext(fe_all_MWContexts->context);
  4033.     char       buf[2048];
  4034.  
  4035.     // Return if we didn't find host on demand.
  4036.     XP_ASSERT(fe_host_on_demand_path);
  4037.     if(!fe_host_on_demand_path) {
  4038.         return;
  4039.     }
  4040.  
  4041.     PR_snprintf (buf, sizeof (buf), "file:%.900s", fe_host_on_demand_path);
  4042.     FE_GetURL(context, NET_CreateURLStruct(buf, NET_DONT_RELOAD));
  4043. }
  4044.  
  4045.  
  4046. //////////////////////////////////////////////////////////////////////////
  4047. //
  4048. // Session management functions
  4049. //
  4050. //////////////////////////////////////////////////////////////////////////
  4051.  
  4052. //////////////////////////////////////////////////////////////////////////
  4053. //
  4054. // The atoms for nuclear fission
  4055. //
  4056. //////////////////////////////////////////////////////////////////////////
  4057. /* static */ Atom XFE_Frame::sm_wm_command = None;
  4058. /* static */ Atom XFE_Frame::sm_wm_save_yourself = None;
  4059.  
  4060. //////////////////////////////////////////////////////////////////////////
  4061. //
  4062. // Return a list of all frames that are alive, top level shells & realzied.
  4063. //
  4064. //////////////////////////////////////////////////////////////////////////
  4065. /* static */ XP_List *
  4066. XFE_Frame::sm_getAliveShellFrames()
  4067. {
  4068.     XP_List *    frame_list = XFE_MozillaApp::theApp()->getAllFrameList();
  4069.     Cardinal    frame_count = XP_ListCount(frame_list);
  4070.  
  4071.     XP_List *    alive_frame_list = NULL;
  4072.     Cardinal    i;
  4073.  
  4074.     // Find the shown frames and add them to a list
  4075.     for (i = 0; i < frame_count; i++)
  4076.     {
  4077.         // Get the next frame
  4078.         XFE_Frame * frame = (XFE_Frame*) XP_ListNextObject(frame_list);
  4079.  
  4080.         // Add it to list if valid and shown
  4081.         if (frame && frame->isAlive())
  4082.         {
  4083.             Widget shell = frame->getBaseWidget();
  4084.  
  4085.             if (shell && XtIsRealized(shell) && XtIsWMShell(shell))
  4086.             {
  4087.                 // Create a new list as soon as we find the first shown item
  4088.                 if (!alive_frame_list)
  4089.                 {
  4090.                     alive_frame_list = XP_ListNew();
  4091.                 }
  4092.                 
  4093.                 XP_ListAddObject(alive_frame_list,frame);
  4094.             }
  4095.         }
  4096.     }
  4097.  
  4098.     return alive_frame_list;
  4099. }
  4100. //////////////////////////////////////////////////////////////////////////
  4101. //
  4102. // Return the shell that talks with the session manager
  4103. //
  4104. //////////////////////////////////////////////////////////////////////////
  4105. /* static */ Widget
  4106. XFE_Frame::sm_getSessionManagerShell()
  4107. {
  4108.     // For CDE, the shell that talks with the sm is always the app shell
  4109.     if (!fe_globalData.irix_session_management)
  4110.     {
  4111.         return FE_GetToplevelWidget();
  4112.     }
  4113.  
  4114.     // For IRIX and maybe other session managers, chose one of the top
  4115.     // level shells
  4116.     XP_List *    frame_list = XFE_MozillaApp::theApp()->getAllFrameList();
  4117.     Cardinal    frame_count = XP_ListCount(frame_list);
  4118.     Cardinal    i;
  4119.  
  4120.     // Find the shown frames and add them to a list
  4121.     for (i = 0; i < frame_count; i++)
  4122.     {
  4123.         // Get the next frame
  4124.         XFE_Frame * frame = (XFE_Frame*) XP_ListNextObject(frame_list);
  4125.  
  4126.         // Use this frame if its shown
  4127.         if (frame && frame->isAlive() && frame->isShown())
  4128.         {
  4129.             return frame->getBaseWidget();
  4130.         }
  4131.     }
  4132.  
  4133.     XFE_Frame * active_frame = XFE_Frame::getActiveFrame();
  4134.  
  4135.     // Use this frame if its shown
  4136.     if (active_frame && active_frame->isAlive() && active_frame->isShown())
  4137.     {
  4138.         return active_frame->getBaseWidget();
  4139.     }
  4140.     
  4141.     return NULL;
  4142. }
  4143. //////////////////////////////////////////////////////////////////////////
  4144. /* static */ void
  4145. XFE_Frame::sm_clearCommandProperties()
  4146. {
  4147.     // For CDE, clear WM_COMMAND on the app shell
  4148.     if (!fe_globalData.irix_session_management)
  4149.     {
  4150.         Widget top = FE_GetToplevelWidget();
  4151.         
  4152.         XP_ASSERT( XfeIsAlive(top) && XtIsRealized(top) );
  4153.         XP_ASSERT( XFE_Frame::sm_wm_command != None );
  4154.         
  4155.         XDeleteProperty(XtDisplay(top),XtWindow(top),XFE_Frame::sm_wm_command);
  4156.  
  4157.         return;
  4158.     }
  4159.  
  4160.     // For IRIX and other sms clear WM_COMMAND on all top level shells
  4161.     // that are valid
  4162.     XP_List *    frame_list = XFE_MozillaApp::theApp()->getAllFrameList();
  4163.     Cardinal    frame_count = XP_ListCount(frame_list);
  4164.     Cardinal    i;
  4165.  
  4166.     // Find the shown frames and add them to a list
  4167.     for (i = 0; i < frame_count; i++)
  4168.     {
  4169.         // Get the next frame
  4170.         XFE_Frame * frame = (XFE_Frame *) XP_ListNextObject(frame_list);
  4171.         
  4172.         Widget shell = frame->getBaseWidget();
  4173.         
  4174.         if (shell && XtIsRealized(shell) && XtIsWMShell(shell))
  4175.         {
  4176.             XP_ASSERT( XFE_Frame::sm_wm_command != None );
  4177.  
  4178.             XDeleteProperty(XtDisplay(shell),
  4179.                             XtWindow(shell),
  4180.                             XFE_Frame::sm_wm_command);
  4181.         }
  4182.     }
  4183. }
  4184. //////////////////////////////////////////////////////////////////////////
  4185. //
  4186. // Return the current address for the frame (what xfeCmdAddBookmark would use)
  4187. //
  4188. //////////////////////////////////////////////////////////////////////////
  4189. /* static */ char *
  4190. XFE_Frame::sm_getAddressForFrame(XFE_Frame * frame)
  4191. {
  4192.     char * address = NULL;
  4193.  
  4194.     if (frame)
  4195.     {
  4196.         MWContext *        context = frame->getContext();
  4197.          History_entry *    h = (History_entry *)
  4198.             (context ? SHIST_GetCurrent(&context->hist) : NULL);
  4199.  
  4200.         if (h && h->address)
  4201.         {
  4202.             address = h->address;
  4203.         }                        
  4204.     }
  4205.     
  4206.     return address;
  4207. }
  4208. //////////////////////////////////////////////////////////////////////////
  4209. //
  4210. // Allocate an argv from a XP_List of strings
  4211. //
  4212. //////////////////////////////////////////////////////////////////////////
  4213. /* static */ void
  4214. XFE_Frame::sm_allocArgvForStringList(XP_List *    list,
  4215.                                      char ***    argv_out,
  4216.                                      int *        argc_out,
  4217.                                      int        num_fixed)
  4218. {
  4219.     char **        argv = NULL;
  4220.     int            argc = 0;
  4221.  
  4222.     if (list)
  4223.     {
  4224.         int num_strings = XP_ListCount(list);
  4225.  
  4226.         argc = num_strings + num_fixed;
  4227.  
  4228.         if (argc > 0)
  4229.         {
  4230.             int i;
  4231.  
  4232.             argv = (char **) XtMalloc(sizeof(char *) * argc);
  4233.  
  4234.             for(i = 0; i < num_strings; i++)
  4235.             {
  4236.                 char * next = (char *) XP_ListNextObject(list);
  4237.  
  4238.                 if (next)
  4239.                 {
  4240.                     argv[i + num_fixed] = (char *) XtNewString(next);
  4241.                 }
  4242.                 else
  4243.                 {
  4244.                     argv[i + num_fixed] = NULL;
  4245.                 }
  4246.             }
  4247.         }
  4248.     }
  4249.  
  4250.     *argc_out = argc;
  4251.     *argv_out = argv;
  4252. }
  4253. //////////////////////////////////////////////////////////////////////////
  4254. //
  4255. // Free an argv
  4256. //
  4257. //////////////////////////////////////////////////////////////////////////
  4258. /* static */ void
  4259. XFE_Frame::sm_freeArgvForStringList(char ** argv,int argc)
  4260. {
  4261.     if (argc && argv)
  4262.     {
  4263.         int i;
  4264.         
  4265.         for(i = 0; i < argc; i++)
  4266.         {
  4267.             if (argv[i])
  4268.             {
  4269.                 XtFree(argv[i]);
  4270.  
  4271.                 argv[i] = NULL;
  4272.             }
  4273.         }
  4274.  
  4275.         XtFree((char *) argv);
  4276.     }
  4277. }
  4278. //////////////////////////////////////////////////////////////////////////
  4279. /* static */ void
  4280. XFE_Frame::sm_freeStringList(XP_List * list)
  4281. {
  4282.     if (list)
  4283.     {
  4284.         int count = XP_ListCount(list);
  4285.         
  4286.         if (count)
  4287.         {
  4288.             int i;
  4289.  
  4290.             for (i = 0; i < count; i++)
  4291.             {
  4292.                 char * str = (char *) XP_ListNextObject(list);
  4293.  
  4294.                 if (str)
  4295.                 {
  4296.                     XtFree(str);
  4297.                 }
  4298.             }
  4299.         }
  4300.     }
  4301. }
  4302. //////////////////////////////////////////////////////////////////////////
  4303. //
  4304. // Return an XP_List of the addresses of the frames that participate in 
  4305. // session management.
  4306. //
  4307. //////////////////////////////////////////////////////////////////////////
  4308. #define SM_DEBUG_SHOW_CURRENT(i,n,a,t) \
  4309. printf("session[%d of %d] address = '%s' , type = '%s' (%d)\n", \
  4310.        (i) , (num_frames) , ( (a) ? (a) : "NULL" ) , "Its_Gone", t );
  4311. //////////////////////////////////////////////////////////////////////////
  4312. /* static */ XP_List *
  4313. XFE_Frame::sm_getFrameAddressList(XP_List * frames)
  4314. {
  4315.     XP_List * urls = NULL;
  4316.  
  4317.     if (frames)
  4318.     {
  4319.         int    num_frames = XP_ListCount(frames);
  4320.         int    i;
  4321.  
  4322.         for(i = 0; i < num_frames; i++)
  4323.         {
  4324.             XFE_Frame * frame = (XFE_Frame *) XP_ListNextObject(frames);
  4325.  
  4326.             if (frame)
  4327.             {
  4328.                 char * address = NULL;
  4329.                 char * str = NULL;
  4330.  
  4331.                 //
  4332.                 // SESSION MANAGER:
  4333.                 //
  4334.                 // To add session manager support to a frame add a case 
  4335.                 // statement here.  Say you want to add support for a 
  4336.                 // new startup flag ( -bookmarks ) that brings up bookmarks
  4337.                 // on startup, add the following below:
  4338.                 //
  4339.                 // case FRAME_BOOKMARK:
  4340.                 //   str = (char *) XtNewString("-bookmarks");
  4341.                 //   break;
  4342.                 //
  4343.                 // Of course, the -bookmarks flag must be supported
  4344.                 // properly.  Look in mozilla.c for starup flag madness.
  4345.                 //
  4346.                 //
  4347.                 switch(frame->getType())
  4348.                 {
  4349.                       // Mailbox: or news:   If the user does not re-use the 
  4350.                     // Messenger frame, then multiple -mail or -news are
  4351.                     // possible.  These will be treated as one by the 
  4352.                     // command line parser in main() (look in mozilla.c)
  4353.                 case FRAME_MAILNEWS_THREAD:
  4354.  
  4355.                     address = XFE_Frame::sm_getAddressForFrame(frame);
  4356.  
  4357.                     if (address)
  4358.                     {
  4359.                         int length = XP_STRLEN("news:");
  4360.  
  4361.                         if (XP_STRNCMP(address,"news:",length) == 0)
  4362.                         {
  4363.                             str = (char *) XtNewString("-news");
  4364.                         }
  4365.                         else
  4366.                         {
  4367.                             str = (char *) XtNewString("-mail");
  4368.                         }
  4369.                     }
  4370.  
  4371.                     break;
  4372.  
  4373.                       // Message Center
  4374.                 case FRAME_MAILNEWS_FOLDER:
  4375.  
  4376.                     str = (char *) XtNewString("-news");
  4377.  
  4378.                     break;
  4379.  
  4380.                     // Browser urls are pasted as is on the command line.
  4381.                     // So are message windows.  Other things like nethelp:
  4382.                     // and ldap: could also go here since they are supported
  4383.                     // by mkgeturl.
  4384.                 case FRAME_BROWSER:
  4385.                 case FRAME_MAILNEWS_MSG:
  4386.  
  4387.  
  4388.                     address = XFE_Frame::sm_getAddressForFrame(frame);
  4389.  
  4390.                     if (address)
  4391.                     {
  4392.                         str = (char *) XtNewString(address);
  4393.                     }
  4394.  
  4395.                     break;
  4396.  
  4397.                  case FRAME_ADDRESSBOOK:
  4398.  
  4399.                     str = (char *) XtNewString("addrbk:");
  4400.  
  4401.                     break;
  4402.  
  4403.                   case FRAME_BOOKMARK:
  4404.  
  4405.                     if (frame->isShown())
  4406.                     {
  4407.                         str = (char *) XtNewString("-bookmarks");
  4408.                     }
  4409.  
  4410.                      break;
  4411.                     
  4412.                   case FRAME_HISTORY:
  4413.                     
  4414.                     if (frame->isShown())
  4415.                     {
  4416.                         str = (char *) XtNewString("-history");
  4417.                     }
  4418.  
  4419.                     break;
  4420.  
  4421.                 case FRAME_MAILFILTER:
  4422.                 case FRAME_LDAP_SEARCH:
  4423.                 case FRAME_MAILNEWS_DOWNLOAD:
  4424.                 case FRAME_MAILNEWS_SEARCH:
  4425.                 case FRAME_MAILNEWS_COMPOSE:
  4426.                 case FRAME_HTML_DIALOG:
  4427.                 case FRAME_EDITOR:
  4428.                 case FRAME_DOWNLOAD:
  4429.                 case FRAME_NAVCENTER:
  4430.  
  4431.                     // Dont do anything for these
  4432.     
  4433.                     break;
  4434.  
  4435.                 } // end switch
  4436.  
  4437.                 if (str)
  4438.                 {
  4439.                     // Create a new list as soon as we find a good str
  4440.                     if (!urls)
  4441.                     {
  4442.                         urls = XP_ListNew();
  4443.                     }
  4444.                     
  4445.                     XP_ListAddObject(urls,str);
  4446.                 }
  4447.  
  4448.             } // if (frame)
  4449.  
  4450.         } // for 
  4451.  
  4452.     } // if (frames)
  4453.     
  4454.     return urls;
  4455. }
  4456. //////////////////////////////////////////////////////////////////////////
  4457. //
  4458. // Add support for the WM_SAVE_YOURSELF protocol
  4459. //
  4460. //////////////////////////////////////////////////////////////////////////
  4461. void 
  4462. XFE_Frame::sm_addSaveYourselfCB()
  4463. {
  4464.     XP_ASSERT( XfeIsAlive(m_widget) && XtIsRealized(m_widget) );
  4465.  
  4466.     // Initialize the atoms
  4467.     if (sm_wm_save_yourself == None)
  4468.     {
  4469.         XFE_Frame::sm_wm_save_yourself =
  4470.             XmInternAtom(XtDisplay(m_widget),"WM_SAVE_YOURSELF",False);
  4471.     }
  4472.  
  4473.     if (sm_wm_command == None)
  4474.     {
  4475.         XFE_Frame::sm_wm_command = 
  4476.             XmInternAtom(XtDisplay(m_widget),"WM_COMMAND",False);
  4477.     }
  4478.  
  4479.     // For CDE install the WM_SAVE_YOURSELF protocol on the app shell (once)
  4480.     // and make sure that this shell is realized and not mapped.  Otherwise
  4481.     // the session manager will not speak to it.
  4482.     if (!fe_globalData.irix_session_management)
  4483.     {
  4484.         static XP_Bool handler_installed_on_top_level = False;
  4485.  
  4486.         // Install the handler on the top level widget only once
  4487.         if (!handler_installed_on_top_level)
  4488.         {
  4489.             Widget top = FE_GetToplevelWidget();
  4490.             
  4491.             XP_ASSERT( XfeIsAlive(top) );
  4492.             
  4493.             if (!XfeIsAlive(top))
  4494.             {
  4495.                 return;
  4496.             }
  4497.  
  4498.             // Make it invisible
  4499.             XtVaSetValues(top,XmNmappedWhenManaged,False,NULL);
  4500.  
  4501.             // Make sure its realized before doing any property stuff
  4502.             XtRealizeWidget(top);
  4503.             
  4504.             // Add the protocol
  4505.             XmAddWMProtocols(top,&XFE_Frame::sm_wm_save_yourself,1);
  4506.             
  4507.             // Add the protocol callback
  4508.             XmAddWMProtocolCallback(top,
  4509.                                     XFE_Frame::sm_wm_save_yourself,
  4510.                                     &XFE_Frame::sm_saveYourselfCB,
  4511.                                     (XtPointer) this);
  4512.             
  4513.             handler_installed_on_top_level = True;
  4514.         }
  4515.  
  4516.         return;
  4517.     }
  4518.  
  4519.  
  4520.     // For other sms add the WM_SAVE_YOURSELF protocol to every single
  4521.     // frame that is valid
  4522.  
  4523.     // Make sure m_widget is wm shell
  4524.     XP_ASSERT( XtIsWMShell(m_widget) );
  4525.  
  4526.     if (!XtIsWMShell(m_widget))
  4527.     {
  4528.         return;
  4529.     }
  4530.  
  4531.     // Add the protocol
  4532.     XmAddWMProtocols(m_widget,&XFE_Frame::sm_wm_save_yourself,1);
  4533.  
  4534.     // Add the protocol callback
  4535.     XmAddWMProtocolCallback(m_widget,
  4536.                             XFE_Frame::sm_wm_save_yourself,
  4537.                             &XFE_Frame::sm_saveYourselfCB,
  4538.                             (XtPointer) this);
  4539. }
  4540. //////////////////////////////////////////////////////////////////////////
  4541. //
  4542. // Handle the WM_SAVE_YOURSELF protocol.  This callback will be invoked
  4543. // by the session manager once for each frame.  We dont care which frame
  4544. // caused the callback to be invoked.  All we need is one window manager
  4545. // shell (the active frame shell) to hold the WM_COMMAND property.  
  4546. //
  4547. // If this callback is called more than once (for many frames), the 
  4548. // XSetCommand() function wlll be called more than once for the active
  4549. // frame shell.  This seems to be ok, even though it seems like a waste.
  4550. //
  4551. //////////////////////////////////////////////////////////////////////////
  4552. /* static */ void 
  4553. XFE_Frame::sm_saveYourselfCB(Widget        /* w */,
  4554.                              XtPointer    /* clientData */,
  4555.                              XtPointer    /* callData */)
  4556. {
  4557.     // Obtain the shell that talks with the session manager
  4558.     Widget session_shell = XFE_Frame::sm_getSessionManagerShell();
  4559.  
  4560.     // Make sure the session shell is good
  4561.     if (!XfeIsAlive(session_shell) || 
  4562.         !XtIsRealized(session_shell) || 
  4563.         !XtIsWMShell(session_shell))
  4564.     {
  4565.         return;
  4566.     }
  4567.  
  4568.     // Clear all the WM_COMMAND properties
  4569.     XFE_Frame::sm_clearCommandProperties();
  4570.  
  4571.     // Obtain the saved argv and argc ( done in main() in mozilla.c )
  4572.     int            saved_argc = fe_GetSavedArgc();
  4573.     char **        saved_argv = fe_GetSavedArgv();
  4574.  
  4575.     // Obtain a list of all the frames that are alive
  4576.      XP_List *    frames = XFE_Frame::sm_getAliveShellFrames();
  4577.  
  4578.     if (frames)
  4579.     {
  4580.         // If argc is 1, then it only contains the exe name.  This is the
  4581.         // case when the user starts the app simply as 'netscape' and then
  4582.         // creates new frames on the fly.  For this case we build the 
  4583.         // argv dynamically.
  4584.         if (saved_argc == 1)
  4585.         {
  4586.             // Obtain a list of current urls
  4587.             XP_List * urls = XFE_Frame::sm_getFrameAddressList(frames);
  4588.  
  4589.             if (urls)
  4590.             {
  4591.                 int            target_argc = 0;
  4592.                 char **        target_argv = NULL;
  4593.  
  4594.                 // Allocate the argv (skip argv[0] for the exe name)
  4595.                 XFE_Frame::sm_allocArgvForStringList(urls,
  4596.                                                      &target_argv,
  4597.                                                      &target_argc,
  4598.                                                      1);
  4599.  
  4600.                 if (target_argc && target_argv)
  4601.                 {
  4602.                     // Set argv[0] to be the exe name
  4603.                     target_argv[0] = (char *) XtNewString(saved_argv[0]);
  4604.  
  4605.                     // Set the WM_COMMAND property for the session shell
  4606.                     XSetCommand(XtDisplay(session_shell),
  4607.                                 XtWindow(session_shell), 
  4608.                                 target_argv,target_argc);
  4609.  
  4610.                     // Free the argv
  4611.                     XFE_Frame::sm_freeArgvForStringList(target_argv,
  4612.                                                         target_argc);
  4613.                 }
  4614.  
  4615.                 // Free the url strings
  4616.                 XFE_Frame::sm_freeStringList(urls);
  4617.  
  4618.                 // Free the url string list
  4619.                 XP_ListDestroy(urls);
  4620.             }
  4621.             
  4622.             // Free the frame list
  4623.             XP_ListDestroy(frames);
  4624.         }
  4625.         // If argc is anything other than 1, then the user invoked netscape
  4626.         // with flags.  We honor those flags and assume the user knows
  4627.         // what he/she is doing.
  4628.         //
  4629.         // This will also be the case if netscape was invoked by a session
  4630.         // manager with command line arguments.
  4631.         else
  4632.         {
  4633.             // Set the WM_COMMAND property for the shell
  4634.             XSetCommand(XtDisplay(session_shell),
  4635.                         XtWindow(session_shell), 
  4636.                         saved_argv,saved_argc);
  4637.         }
  4638.     }
  4639. }
  4640. //////////////////////////////////////////////////////////////////////////
  4641.  
  4642. //
  4643. // end of session management functions
  4644. //
  4645.  
  4646. //////////////////////////////////////////////////////////////////////////
  4647. //
  4648. // Z-Order support
  4649. //
  4650. // The files MozillaWm.[ch] define and implement a protocol by which a
  4651. // mozilla browser can provide a window manager hints to determine its
  4652. // z-order placement.  Window managers that support this protocol will 
  4653. // greatly improve the usability of z-locked windows such as netcaster
  4654. // webtop.
  4655. //
  4656. // If no such extension is detected on the root window, then we use 
  4657. // event tracking hackery instead.
  4658. //
  4659. //////////////////////////////////////////////////////////////////////////
  4660. void
  4661. XFE_Frame::zaxis_AddSupport()
  4662. {
  4663.     XP_ASSERT( XfeIsAlive(m_widget) );
  4664.     XP_ASSERT( XtIsRealized(m_widget) );
  4665.     XP_ASSERT( XtIsTopLevelShell(m_widget) );
  4666.         
  4667.     // Only browsers with a chromespec provided can use this stuff
  4668.     if ((m_frametype != FRAME_BROWSER) || !m_chromespec_provided)
  4669.     {
  4670.         return;
  4671.     }
  4672.  
  4673.     Screen *    screen = XtScreen(m_widget);
  4674.     Window        window = XtWindow(m_widget);
  4675.  
  4676.     // Check the window manager for Mozilla wm extension support
  4677.     long        version = MozillaWmGetWmVersion(screen);
  4678.  
  4679.     // If the version is valid, then add the mozilla wm hints to the shell
  4680.     if (version != MOZILLA_WM_VERSION_INVALID)
  4681.     {
  4682.         // Clear the old hints so that the next statement get a fresh mask
  4683.         MozillaWmSetHints(screen,window,MOZILLA_WM_NONE);
  4684.  
  4685.         // At least one of these must be true
  4686.         if (!m_topmost && !m_bottommost && !m_zlock)
  4687.         {
  4688.             return;
  4689.         }
  4690.  
  4691.         XP_ASSERT( ! (m_topmost && m_bottommost) );
  4692.                 
  4693.         // Set topmost if needed
  4694.         if (m_topmost)
  4695.             MozillaWmSetHints(screen,window,MOZILLA_WM_ALWAYS_TOP);
  4696.         
  4697.         // Set bottomost if needed
  4698.         if (m_bottommost)
  4699.             MozillaWmSetHints(screen,window,MOZILLA_WM_ALWAYS_BOTTOM);
  4700.         
  4701.         // Add zlock if needed
  4702.         if (m_zlock)
  4703.             MozillaWmAddHints(screen,window,MOZILLA_WM_ZORDER_LOCK);
  4704.     }
  4705. #ifdef NETCASTER_ZAXIS_HACKERY
  4706.     //
  4707.     // Otherwise resort to hackery
  4708.     //
  4709.     // This stuff is hackery that somewhat honors the topmost and bottommost
  4710.     // chrome members by tracking visiblity events on frame shells and
  4711.     // then forcing a re-stacking.  In order to avoid having two or more 
  4712.     // frames that set these chrome options fight each other, a count of
  4713.     // the number of times per second visiblity events cause a re-stacking
  4714.     // and if this exceeds a magic number, we ignore the request.
  4715.     //
  4716.     else
  4717.     {
  4718.         // This startup flag gives users of netcaster the ability to bypass the
  4719.         // fascist window stacking madness implemented here.
  4720.         if (fe_globalData.dont_force_window_stacking)
  4721.         {
  4722.             return;
  4723.         }
  4724.  
  4725.         // Clear the handlers in case they were added before
  4726.         if (m_zaxis_BelowHandlerInstalled)
  4727.             zaxis_RemoveHandler(m_widget,Below);
  4728.  
  4729.         if (m_zaxis_AboveHandlerInstalled)
  4730.             zaxis_RemoveHandler(m_widget,Above);
  4731.  
  4732.         // At least one of these must be true
  4733.         if (!m_topmost && !m_bottommost && !m_zlock)
  4734.         {
  4735.             return;
  4736.         }
  4737.         
  4738.         // Install topmost handler
  4739.         if (m_topmost)
  4740.         {
  4741.             zaxis_InstallHandler(m_widget,Above);
  4742.         }
  4743.         // Install bottommost handler
  4744.         else if (m_bottommost)
  4745.         {
  4746.             zaxis_InstallHandler(m_widget,Below);
  4747.         }
  4748.         // Ignore zlock
  4749.     }
  4750. #endif
  4751. }
  4752.  
  4753. #ifdef NETCASTER_ZAXIS_HACKERY
  4754. //////////////////////////////////////////////////////////////////////////
  4755. //
  4756. // Netscaster z-axis topmost and bottommost hackery
  4757. //
  4758. //////////////////////////////////////////////////////////////////////////
  4759.  
  4760. // Max number of times per second to either raaise or lower a frame
  4761. #define ZAXIS_FASCIST_LIMIT    4
  4762.  
  4763. //////////////////////////////////////////////////////////////////////////
  4764. //
  4765. // Install the raise/lower hackery.  mode is either Above or Below
  4766. //
  4767. //////////////////////////////////////////////////////////////////////////
  4768. #define ZAXIS_EVENTS_TO_TRACK                    \
  4769. (                                                \
  4770.     VisibilityChangeMask    |                     \
  4771.      FocusChangeMask            |                     \
  4772.     StructureNotifyMask                            \
  4773. )
  4774. //////////////////////////////////////////////////////////////////////////
  4775. #define ZAXIS_EVENT_IS_GOOD(event)                \
  4776. (                                                \
  4777.     (event->type == VisibilityNotify)    ||        \
  4778.     (event->type == FocusIn)            ||        \
  4779.     (event->type == ConfigureNotify)            \
  4780. )
  4781. //////////////////////////////////////////////////////////////////////////
  4782. //
  4783. // Add the event handler that keeps track of events related to stacking
  4784. //
  4785. //////////////////////////////////////////////////////////////////////////
  4786. void
  4787. XFE_Frame::zaxis_InstallHandler(Widget shell,int mode)
  4788. {
  4789.     XP_ASSERT( XtIsShell(shell) );
  4790.     XP_ASSERT( XfeIsAlive(shell) );
  4791.     XP_ASSERT( mode == Above || mode == Below );
  4792.  
  4793.     m_zaxis_LastStackingChangeTime = 0;
  4794.     m_zaxis_StackingChangesPerSecond = 0;
  4795.  
  4796.     // Add the appropiate visiblity event handler to the shell
  4797.     if (mode == Above)
  4798.     {
  4799.         XP_ASSERT( m_zaxis_AboveHandlerInstalled == False );
  4800.  
  4801.         if (m_zaxis_AboveHandlerInstalled)
  4802.             return;
  4803.  
  4804.         XtAddEventHandler(shell,
  4805.                           ZAXIS_EVENTS_TO_TRACK,
  4806.                           True,
  4807.                           &XFE_Frame::zaxis_AboveEH,
  4808.                           (XtPointer) this);
  4809.  
  4810.         m_zaxis_AboveHandlerInstalled = True;
  4811.     }
  4812.     else if (mode == Below)
  4813.     {
  4814.         XP_ASSERT( m_zaxis_BelowHandlerInstalled == False );
  4815.  
  4816.         if (m_zaxis_BelowHandlerInstalled)
  4817.         {
  4818.             return;
  4819.         }
  4820.  
  4821.         XtAddEventHandler(shell,
  4822.                           ZAXIS_EVENTS_TO_TRACK,
  4823.                           True,
  4824.                           &XFE_Frame::zaxis_BelowEH,
  4825.                           (XtPointer) this);
  4826.  
  4827.         m_zaxis_BelowHandlerInstalled = True;
  4828.     }
  4829. }
  4830. //////////////////////////////////////////////////////////////////////////
  4831. //
  4832. // Remove the event handler that keeps track of events related to stacking
  4833. //
  4834. //////////////////////////////////////////////////////////////////////////
  4835. void
  4836. XFE_Frame::zaxis_RemoveHandler(Widget shell,int mode)
  4837. {
  4838.     XP_ASSERT( XtIsShell(shell) );
  4839.     XP_ASSERT( XfeIsAlive(shell) );
  4840.     XP_ASSERT( mode == Above || mode == Below );
  4841.  
  4842.     // Add the appropiate visiblity event handler to the shell
  4843.     if (mode == Above)
  4844.     {
  4845.         XP_ASSERT( m_zaxis_AboveHandlerInstalled == True );
  4846.  
  4847.         if (!m_zaxis_AboveHandlerInstalled)
  4848.             return;
  4849.  
  4850.         XtRemoveEventHandler(shell,
  4851.                              ZAXIS_EVENTS_TO_TRACK,
  4852.                              True,
  4853.                              &XFE_Frame::zaxis_AboveEH,
  4854.                              (XtPointer) this);
  4855.  
  4856.         m_zaxis_AboveHandlerInstalled = False;
  4857.     }
  4858.     else if (mode == Below)
  4859.     {
  4860.         XP_ASSERT( m_zaxis_BelowHandlerInstalled == True );
  4861.  
  4862.         if (!m_zaxis_BelowHandlerInstalled)
  4863.             return;
  4864.  
  4865.         XtRemoveEventHandler(shell,
  4866.                              ZAXIS_EVENTS_TO_TRACK,
  4867.                              True,
  4868.                              &XFE_Frame::zaxis_BelowEH,
  4869.                              (XtPointer) this);
  4870.  
  4871.         m_zaxis_BelowHandlerInstalled = False;
  4872.     }
  4873. }
  4874. //////////////////////////////////////////////////////////////////////////
  4875. //
  4876. // Deal with a visiblity change in the frame's shell.  Keep track of the
  4877. // number of times per second that this operation is tried and only
  4878. // modify the shell stacking order of this count is less than a 
  4879. // magic number.  mode can be Above or Below.
  4880. //
  4881. //////////////////////////////////////////////////////////////////////////
  4882. void
  4883. XFE_Frame::zaxis_HandleEvent(Widget shell,int mode)
  4884. {
  4885.     XP_ASSERT( mode == Above || mode == Below );
  4886.  
  4887.     // The time 'now'
  4888.     time_t time_now = time(NULL);
  4889.     
  4890.     // The time difference between 'now' and the last time we were called
  4891.     time_t time_diff = time_now - m_zaxis_LastStackingChangeTime;
  4892.     
  4893.     // If the difference is 0, then we are being called more than once
  4894.     // in one second - increment the changes/sec counter.
  4895.     if (time_diff == 0)
  4896.     {
  4897.         m_zaxis_StackingChangesPerSecond++;
  4898.     }
  4899.     // Otherwise we are being called after a 'long' interval and we 
  4900.     // reset the changes/sec counter.
  4901.     else
  4902.     {
  4903.         m_zaxis_StackingChangesPerSecond = 0;
  4904.     }
  4905.  
  4906.     // If the times/sec counter is more than a magic number, then we
  4907.     // are being called too often and we are most likely in an infinite
  4908.     // loop fighting with another window that also wants to be always
  4909.     // on top.
  4910.     if (m_zaxis_StackingChangesPerSecond < ZAXIS_FASCIST_LIMIT)
  4911.     {
  4912.         // Place window on top
  4913.         XWindowChanges changes;
  4914.         
  4915.         changes.stack_mode = mode;
  4916.         
  4917.         XReconfigureWMWindow(XtDisplay(shell),
  4918.                              XtWindow(shell), 
  4919.                              XScreenNumberOfScreen(XtScreen(shell)),
  4920.                              CWStackMode,&changes);
  4921.  
  4922.         if (mode == Above)
  4923.         {
  4924.             m_topmost = True;
  4925.         }
  4926.         else if (mode == Below)
  4927.         {
  4928.             m_bottommost = True;
  4929.         }
  4930.  
  4931.         // Update the last last change time
  4932.         m_zaxis_LastStackingChangeTime = time_now;
  4933.     }
  4934. }
  4935. //////////////////////////////////////////////////////////////////////////
  4936. /* static */ void
  4937. XFE_Frame::zaxis_AboveEH(Widget            shell,
  4938.                          XtPointer        clientData,
  4939.                          XEvent *        event,
  4940.                          Boolean *        cont)
  4941. {
  4942. // Not sure if this needs to be checked ???
  4943. //
  4944. //        (event->xvisibility.state != VisibilityUnobscured) &&
  4945. //
  4946.  
  4947.     // Make sure the shell and event are valid, the Xm menu system or dnd
  4948.     // are not grabbed and tips are not showing.  Also make sure the zaxis
  4949.     // stacking system is not locked.
  4950.     if (event && XfeIsAlive(shell) &&
  4951.         !XfeDisplayIsUserGrabbed(shell) &&
  4952.         !fe_ToolTipIsShowing())
  4953.     {
  4954.         if (ZAXIS_EVENT_IS_GOOD(event))
  4955.         {
  4956.             XFE_Frame * frame = (XFE_Frame *) clientData;
  4957.  
  4958.             frame->zaxis_HandleEvent(shell,Above);
  4959.         }
  4960.     }
  4961.     
  4962.     *cont = True;
  4963. }
  4964. //////////////////////////////////////////////////////////////////////////
  4965. /* static */ void
  4966. XFE_Frame::zaxis_BelowEH(Widget            shell,
  4967.                          XtPointer        clientData,
  4968.                          XEvent *        event,
  4969.                          Boolean *        cont)
  4970. {
  4971.     // Make sure the shell and event are valid, the Xm menu system or dnd
  4972.     // are not grabbed and tips are not showing.  Also make sure the zaxis
  4973.     // stacking system is not locked.
  4974.     if (event && XfeIsAlive(shell) &&
  4975.         !XfeDisplayIsUserGrabbed(shell) &&
  4976.         !fe_ToolTipIsShowing())
  4977.     {
  4978.         if (ZAXIS_EVENT_IS_GOOD(event))
  4979.         {
  4980.             XFE_Frame * frame = (XFE_Frame *) clientData;
  4981.  
  4982.             frame->zaxis_HandleEvent(shell,Below);
  4983.         }
  4984.     }
  4985.     
  4986.     *cont = True;
  4987. }
  4988. //////////////////////////////////////////////////////////////////////////
  4989. #endif
  4990.  
  4991. //
  4992. // end of netcaster z axis hackery
  4993. //
  4994.