home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / genframe.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  96.0 KB  |  3,345 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. // genframe.cpp : implementation file
  20. //
  21.  
  22. #include "stdafx.h"
  23. #include "confhook.h"
  24. #ifdef MOZ_MAIL_NEWS
  25. #include "mailfrm.h"
  26. #endif
  27. #ifdef EDITOR
  28. #include "edt.h"
  29. #endif
  30. #include "winclose.h"
  31. #include "prefapi.h"
  32. #ifdef MOZ_OFFLINE
  33. #include "dlgdwnld.h"
  34. #endif
  35. #include "genchrom.h"
  36. #include "intl_csi.h"
  37. #include "quickfil.h"
  38. #ifndef XP_WIN16
  39. #include "navFram.h"
  40. #endif
  41.  
  42. #include "property.h"
  43.  
  44. #ifdef _WIN32
  45. #include "intelli.h"
  46. #endif
  47.  
  48. #ifdef JAVA
  49. #include "java.h"
  50. #endif
  51.  
  52. // for whitebox testing
  53. //#define DEBUG_WHITEBOX
  54. #ifdef DEBUG_WHITEBOX
  55. #include "TestcaseDlg.h"
  56. #endif
  57.  
  58. extern void wfe_Progress(MWContext *pContext, const char *pMessage);
  59.  
  60. #ifdef _DEBUG
  61. #undef THIS_FILE
  62. static char BASED_CODE THIS_FILE[] = __FILE__;
  63. #endif
  64.  
  65. //CLM: Global in TEMPLATE.CPP - saves last frame location
  66. //     for new window postioning - cleared in ::OnClose method here
  67. extern CGenericFrame *wfe_pLastFrame;
  68.  
  69. //
  70. // Bookmark stuff
  71. // 
  72.  
  73. // This is used to remember the number of existing menu items on the
  74. // bookmark menu before we add the bookmark items. We need this so we
  75. // know how many menu items to delete when the menu goes away
  76. static int      nExistingBookmarkMenuItems;
  77.  
  78. // We destroy the menu items we added when we receive the WM_MENUSELECT.
  79. // Because Windows sends the WM_MENUSELECT that the menu is going away
  80. // before they send the WM_COMMAND, we need to remember the last menu item
  81. // selected and its data (i.e. URL address or History_entry*)
  82. static UINT     nLastSelectedCmdID;
  83. static void*    nLastSelectedData;
  84.  
  85. // Macro to use for graying toolbar and menu items
  86. //  when we don't have a context or it is in "waiting" mode
  87. // This is used by both Navigator and Composer frames,
  88. //  so we check if Editor is blocked
  89. #define CAN_INTERACT_IF_EDITOR  (GetMainContext() != NULL && GetMainContext()->GetContext() != NULL \
  90.                        && !GetMainContext()->GetContext()->waitingMode  \
  91.                        && (!EDT_IS_EDITOR(GetMainContext()->GetContext()) \
  92.                            || !EDT_IsBlocked(GetMainContext()->GetContext())))
  93.  
  94. #ifndef _AFXDLL
  95. #undef new
  96. #endif
  97. IMPLEMENT_DYNCREATE(CNSGenFrame, CFrameWnd)
  98. #ifndef _AFXDLL
  99. #define new DEBUG_NEW
  100. #endif
  101. /////////////////////////////////////////////////////////////////////////////
  102. // CGenericFrame
  103.  
  104. #ifndef _AFXDLL
  105. #undef new
  106. #endif
  107. IMPLEMENT_DYNCREATE(CGenericFrame, CNSGenFrame)
  108. #ifndef _AFXDLL
  109. #define new DEBUG_NEW
  110. #endif
  111.  
  112. // The Event Handler
  113. static void qfNotifyProcedure (HT_Notification ns, HT_Resource n, HT_Event whatHappened) 
  114. {
  115.     if (whatHappened == HT_EVENT_NODE_OPENCLOSE_CHANGED)
  116.     {
  117.         // The node was opened.
  118.         PRBool openState;
  119.         HT_GetOpenState(n, &openState);
  120.         if (openState)
  121.         {
  122.             CGenericFrame* pFrame = (CGenericFrame*)ns->data;
  123.             pFrame->FinishMenuExpansion(n);
  124.         }
  125.     }
  126. }
  127.  
  128. CGenericFrame::CGenericFrame()
  129. {
  130.     // Construct the notification struct used by HT
  131.     HT_Notification ns = new HT_NotificationStruct;
  132.     ns->notifyProc = qfNotifyProcedure;
  133.     ns->data = this;
  134.  
  135.     m_BookmarkMenuPane = theApp.m_bInGetCriticalFiles ? NULL : HT_NewQuickFilePane(ns);
  136.     m_nBookmarkItems = 0;
  137.     m_nFileBookmarkItems = 0;
  138.     m_pHotlistMenuMap = new CMapWordToPtr();
  139.     m_isClosing = FALSE;
  140. #ifdef XP_WIN32
  141.     m_pSubmenuMap = new CMapPtrToPtr();
  142. #else
  143.     m_pSubmenuMap = new CMapWordToPtr();
  144. #endif
  145.  
  146. #ifdef XP_WIN32
  147.     m_pFileSubmenuMap = new CMapPtrToPtr();
  148. #else
  149.     m_pFileSubmenuMap = new CMapWordToPtr();
  150. #endif
  151.  
  152.     m_pBookmarkBitmap = NULL;
  153.     m_pBookmarkFolderBitmap = NULL;
  154.     m_pBookmarkFolderOpenBitmap = NULL;
  155.     m_pBookmarksMenu = NULL;
  156.     m_BookmarksGarbageList = NULL;
  157.     m_OriginalBookmarksGarbageList = NULL;
  158.  
  159. #ifdef _WIN32
  160.     m_pMenuMap = new CMapPtrToPtr();
  161. #else
  162.     m_pMenuMap = new CMapWordToPtr();
  163. #endif
  164.  
  165. #ifdef EDITOR
  166.     extern void FED_SetupStrings(void);
  167.     FED_SetupStrings();
  168.     m_bCloseFrame = FALSE;
  169.     m_bSkipSaveEditChanges = FALSE;
  170. #endif
  171.  
  172.     //    Initially we'll be allowing the frame to resize.
  173.     m_bCanResize = TRUE;
  174.     m_bDisableHotkeys = FALSE;
  175.     m_bPreCreated = FALSE;
  176.     m_bZOrderLocked = FALSE;
  177.     m_bBottommost = FALSE;
  178.  
  179.     m_pChrome = NULL;
  180.     m_wAddedExStyles = 0L;
  181.     m_wRemovedExStyles = 0L;
  182.  
  183.     m_hPopupParent = NULL;
  184.     m_bConference = FALSE;
  185.  
  186. #ifdef XP_WIN32
  187.     // jliu added the following to support CJK caption print
  188.     m_bActive = FALSE;
  189.     m_csid    = CIntlWin::GetSystemLocaleCsid();
  190.     SetupCapFont( m_csid );        // setup the default font first
  191.     DWORD dwVersion = ::GetVersion();
  192.     if( LOBYTE(dwVersion) < 4 )
  193.         capStyle = DT_CENTER;    // for NT 3.51
  194.     else
  195.         capStyle = DT_LEFT;        // for NT 4.0 and Win95
  196. #endif
  197. }
  198.  
  199.  
  200.  
  201. #ifdef XP_WIN32
  202. // jliu added the following to support CJK caption print
  203. int16 CGenericFrame::GetTitleWinCSID()
  204. {
  205.     CWinCX *pContext = GetMainWinContext();
  206.     MWContext* pMWContext = NULL;
  207.     if( pContext == NULL || ( pMWContext = pContext->GetContext() ) == NULL ){
  208.         return -1;
  209.     }
  210.     INTL_CharSetInfo csi = LO_GetDocumentCharacterSetInfo(pMWContext);
  211.     
  212.     return INTL_GetCSIWinCSID(csi);
  213. }
  214.  
  215. ////////////////////////////////////////////////////////////////////
  216. // this function is called outside to get the wincsid
  217. // and then setup the Caption Font.
  218. //
  219. void CGenericFrame::SetupCapFont( int16 csid, BOOL force )
  220. {
  221.     if( !force && ( m_csid == csid ) && ( hCapFont.m_hObject != NULL ) )
  222.         return;
  223.  
  224.     // set the wincsid
  225.     if( csid <= 0 )
  226.         m_csid = CIntlWin::GetSystemLocaleCsid();
  227.     else
  228.         m_csid = csid;
  229.  
  230.     // set the caption print font
  231.     if( hCapFont.m_hObject != NULL )
  232.         hCapFont.DeleteObject();
  233.  
  234.     // get the system caption print font first
  235.     NONCLIENTMETRICS nc;
  236.     nc.cbSize = sizeof(NONCLIENTMETRICS);
  237.     BOOL b = SystemParametersInfo( SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &nc, 0 );
  238.     XP_ASSERT( b );
  239.  
  240.     LOGFONT lf = nc.lfCaptionFont;    // get the logic font used to paint the caption
  241.     csid = CIntlWin::GetSystemLocaleCsid();
  242.     if( force || ( m_csid !=  csid ) ){        // in case user changes system font
  243.         lf.lfCharSet = IntlGetLfCharset( m_csid );
  244.          _tcscpy( lf.lfFaceName, IntlGetUIPropFaceName( m_csid ) );
  245.         hCapFont.CreateFontIndirect( &lf );
  246.     }
  247.  
  248.     // create the default font if the above step failure
  249.     if( hCapFont.m_hObject == NULL ){
  250.         hCapFont.CreateFontIndirect( &nc.lfCaptionFont );
  251.         m_csid = csid;
  252.     }
  253. }
  254.  
  255. //////////////////
  256. // User changed system settings, such  as font. Or changed
  257. // encoding method, coming from compfrm.cpp
  258. // Invalidate everything to generate anew.
  259. // 
  260. LRESULT CGenericFrame::OnSettingChange( WPARAM, LPARAM )
  261. {
  262.     SetupCapFont( GetTitleWinCSID(), TRUE );
  263.     SendMessage(WM_NCPAINT);
  264.     return 0;
  265. }
  266.  
  267.  
  268. //////////////////
  269. // Someone called SetWindowText: paint new text.
  270. //
  271. LRESULT CGenericFrame::OnSetText(WPARAM wParam, LPARAM lParam)
  272. {
  273.     SetupCapFont( GetTitleWinCSID() );
  274.  
  275.     // Turn WS_VISIBLE style off before calling Windows to
  276.     // set the text, then turn it back on again after.
  277.     //
  278.     DWORD dwStyle = GetStyle();
  279.     if( dwStyle & WS_VISIBLE )
  280.         SetWindowLong( m_hWnd, GWL_STYLE, dwStyle & ~WS_VISIBLE );
  281.     LRESULT lRet = DefWindowProc(WM_SETTEXT, wParam, lParam); 
  282.     if( dwStyle & WS_VISIBLE )
  283.         SetWindowLong( m_hWnd, GWL_STYLE, dwStyle );
  284.  
  285.     SendMessage(WM_NCPAINT);    // paint non-client area (frame too)
  286.  
  287.     return lRet;
  288. }
  289.  
  290. //////////////////
  291. // Non-client area (de)activated: paint it
  292. //
  293. BOOL CGenericFrame::OnNcActivate(BOOL bActive)
  294. {
  295.     if( m_nFlags & WF_STAYACTIVE )
  296.         bActive = TRUE;
  297.     if( !IsWindowEnabled() )
  298.         bActive = FALSE;
  299.     if( bActive == m_bActive )    
  300.         return TRUE;
  301.  
  302.     MSG& msg = AfxGetThreadState()->m_lastSentMsg;
  303.     if( msg.wParam > 1 )
  304.         msg.wParam = TRUE;
  305.     m_bActive = bActive = msg.wParam;
  306.  
  307.     // Turn WS_VISIBLE off before calling DefWindowProc,
  308.     // so DefWindowProc won't paint and thereby cause flicker.
  309.     //
  310.     DWORD dwStyle = GetStyle();
  311.     if( dwStyle & WS_VISIBLE )
  312.         ::SetWindowLong(m_hWnd, GWL_STYLE, (dwStyle & ~WS_VISIBLE));
  313.     DefWindowProc(WM_NCACTIVATE, bActive, 0L);    // don't call CFrameWnd::OnNcActivate()
  314.     if( dwStyle & WS_VISIBLE )
  315.         ::SetWindowLong(m_hWnd, GWL_STYLE, dwStyle);
  316.  
  317.     SendMessage( WM_NCPAINT );    // paint non-client area and frame
  318.  
  319.     return TRUE;
  320. }
  321.  
  322.  
  323. void CGenericFrame::OnNcPaint()
  324. {
  325.     DWORD dwStyle = GetStyle();
  326.     if( !( dwStyle & WS_CAPTION )  ){
  327.         CFrameWnd::OnNcPaint();            // do the default one first
  328.         return;
  329.     }
  330.  
  331.     CSize szFrame = (dwStyle & WS_THICKFRAME) ?
  332.         CSize(GetSystemMetrics(SM_CXSIZEFRAME),
  333.                GetSystemMetrics(SM_CYSIZEFRAME)) :
  334.         CSize(GetSystemMetrics(SM_CXFIXEDFRAME),
  335.                 GetSystemMetrics(SM_CYFIXEDFRAME));
  336.  
  337.     int dxIcon = GetSystemMetrics(SM_CXSIZE); // width of caption icon/button
  338.  
  339.     // Compute rectangle
  340.     CRect rc;        // window rect in screen coords
  341.     GetWindowRect( &rc );
  342.     rc.left  += szFrame.cx;                // frame
  343.     rc.right -= szFrame.cx;                // frame
  344.     rc.top   += szFrame.cy;                // top = end of frame
  345.     rc.bottom = rc.top + GetSystemMetrics(SM_CYCAPTION)  // height of caption
  346.         - GetSystemMetrics(SM_CYBORDER);                  // minus gray shadow border
  347.  
  348.  
  349.     MSG& msg = AfxGetThreadState()->m_lastSentMsg;
  350.  
  351.     // Don't paint if the caption doesn't lie within the region.
  352.     //
  353.     if (msg.wParam > 1 && !::RectInRegion((HRGN)msg.wParam, &rc)) {
  354.         CFrameWnd::OnNcPaint();            // do the default one first
  355.         return;                            // quit
  356.     }
  357.  
  358.  
  359.     // setup the update region, include the title text region
  360.  
  361.     CRect rectCaption;
  362.     GetWindowRect( &rectCaption );
  363.  
  364.     CWindowDC dc(this);
  365.     CFont* hFontOld = dc.SelectObject( &hCapFont );
  366.  
  367.     HRGN hRgnCaption = ::CreateRectRgnIndirect(&rc);
  368.     HRGN hRgnNew     = ::CreateRectRgnIndirect(&rc);
  369.     if( msg.wParam > 1 ){
  370.         // wParam is a valid region: subtract caption from it
  371.         ::CombineRgn( hRgnNew, (HRGN)msg.wParam, hRgnCaption, RGN_OR );
  372.     } else {
  373.         // wParam is not a valid region: create one that's the whole window
  374.         DeleteObject( hRgnNew );
  375.         hRgnNew = ::CreateRectRgnIndirect(&rectCaption);
  376.     }
  377.  
  378.     // call the default NcPaint
  379.  
  380.     WPARAM savewp = msg.wParam;        // save original wParam
  381.     msg.wParam = (WPARAM)hRgnNew;    // set new region for DefWindowProc
  382.     CFrameWnd::OnNcPaint();            // paint the caption bar except title text
  383.     DeleteObject( hRgnCaption );    // clean up
  384.     DeleteObject( hRgnNew );        // clean up
  385.     msg.wParam = savewp;            // restore original wParam
  386.  
  387.  
  388.     // Compute rectangle
  389.     // Within the basic button rectangle, Windows 95 uses a 1 or 2 pixel border
  390.     // Icon has 2 pixel border on left, 1 pixel on top/bottom, 0 right
  391.     // Close box has a 2 pixel border on all sides but left, which is zero
  392.     // Minimize button has 2 pixel border on all sides but right.
  393.  
  394.     rectCaption -= rectCaption.TopLeft(); // convert caption rectangle origin to (0,0)
  395.     rectCaption.left  += (szFrame.cx + 2 + dxIcon);
  396.     rectCaption.right -= (szFrame.cx + 2 + dxIcon);
  397.     rectCaption.top   += szFrame.cy;                // top = end of frame
  398.     rectCaption.bottom = rectCaption.top + GetSystemMetrics(SM_CYCAPTION)    // height of caption
  399.         - GetSystemMetrics(SM_CYBORDER);            // minus gray shadow border
  400.  
  401.  
  402.     // i don't know why MS supports this feature ...
  403.     if( ( dwStyle & WS_MAXIMIZEBOX ) || ( dwStyle & WS_MINIMIZEBOX ) ){
  404.         rectCaption.right -= ( dxIcon + 2 + dxIcon );
  405.         if( capStyle != DT_LEFT )    // for NT 3.51
  406.             rectCaption.right += dxIcon + 4;
  407.     }
  408.  
  409.     // create a brush for caption background
  410.     CBrush brCaption;
  411.     brCaption.CreateSolidBrush(    
  412.         ::GetSysColor( m_bActive ? COLOR_ACTIVECAPTION : COLOR_INACTIVECAPTION ) );
  413.  
  414.     CString strTitle;
  415.     GetWindowText( strTitle );
  416.  
  417.     dc.FillRect(&rectCaption, &brCaption);
  418.     dc.SetTextColor(::GetSysColor(m_bActive ? COLOR_CAPTIONTEXT : COLOR_INACTIVECAPTIONTEXT));
  419.     dc.SetBkMode(TRANSPARENT);
  420.  
  421.     int titleLen = _tcslen( strTitle );
  422.     UINT cs = capStyle;
  423.     if( cs != DT_LEFT ){    // it is NT 3.51
  424.         CSize size = dc.GetTextExtent( strTitle, titleLen );
  425.         if( size.cx >= rectCaption.Width() )
  426.             cs = DT_LEFT;
  427.     }
  428.     CIntlWin::DrawText( m_csid, (HDC)dc, strTitle.GetBuffer( titleLen ), titleLen,
  429.         &rectCaption, cs|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS );
  430.  
  431.     dc.SelectObject(hFontOld);
  432. }
  433.  
  434. #endif    // #ifdef XP_WIN32
  435.  
  436.  
  437. CGenericFrame::~CGenericFrame()
  438. {
  439.     if (m_BookmarkMenuPane)
  440.     {
  441.         HT_DeletePane(m_BookmarkMenuPane);
  442.         m_BookmarkMenuPane = NULL;
  443.     }
  444.  
  445. #ifdef XP_WIN32
  446.     if( hCapFont.m_hObject != NULL )
  447.         hCapFont.DeleteObject();
  448. #endif
  449.  
  450.     if (m_pHotlistMenuMap) {
  451.         delete m_pHotlistMenuMap;
  452.         m_pHotlistMenuMap = NULL;
  453.     }
  454.  
  455.     if (m_pSubmenuMap) {
  456.         delete m_pSubmenuMap;
  457.         m_pSubmenuMap = NULL;
  458.     }
  459.  
  460.     if (m_pFileSubmenuMap) {
  461.         delete m_pFileSubmenuMap;
  462.         m_pFileSubmenuMap = NULL;
  463.     }
  464.  
  465.     if (m_pMenuMap)
  466.     {
  467.         DeleteMenuMapIDs();
  468.         delete m_pMenuMap;
  469.         m_pMenuMap = NULL;
  470.     }
  471.  
  472.     if (m_pChrome) {
  473.         m_pChrome->Release();
  474.     }
  475.  
  476.     // Remove it from the list of frames kept by theApp
  477.     //  Done here as was done in OnClose, but needed here since
  478.     //      hidden frame when in place never remove's itself from the
  479.     //      list as OnClose never gets called if not active when
  480.     //      deleted.
  481.     if(theApp.m_pFrameList == this) {
  482.         // first one
  483.         theApp.m_pFrameList = m_pNext;
  484.  
  485.         // Reset the global last frame
  486.         //  (this is unlikely unless we are only frame left)
  487.         if( wfe_pLastFrame == this )
  488.             wfe_pLastFrame = NULL;
  489.     } else {
  490.         // loop through for the one pointing to me
  491.         for(CGenericFrame * f = theApp.m_pFrameList; f; f = f->m_pNext)
  492.             if(f->m_pNext == this){
  493.                 // Change the "last frame" to the one before
  494.                 if( wfe_pLastFrame == this )
  495.                     wfe_pLastFrame = f;    
  496.                 f->m_pNext = m_pNext;
  497.             }
  498.     }
  499. }
  500.  
  501. #define SEPARATORS_BEFORE_BOOKMARKS_START 2
  502. #define ITEMS_BEFORE_BOOKMARKS_START 6
  503. #define ITEMS_AFTER_BOOKMARKS_END 0
  504.  
  505. void CGenericFrame::BuildDirectoryMenu(CMenu * pMenu) 
  506. {
  507.     if (!pMenu) return; 
  508.     if(GetMainContext() == NULL)    {
  509.         return;
  510.     }
  511.  
  512.     int idx =0, idx2=0;
  513.     int iItems = pMenu->GetMenuItemCount();    
  514.     char *label;
  515.     int bOK = PREF_NOERROR;
  516.   
  517.     for (idx=0; bOK==PREF_NOERROR; idx++) {
  518.         bOK = PREF_CopyIndexConfigString("menu.places.item",idx,"label",&label);
  519.  
  520.         // if the label is blank, truncate the menu here.
  521.         if (!label || !label[0])
  522.             bOK = PREF_ERROR;
  523.  
  524.         if (bOK == PREF_NOERROR) {
  525.             if (idx < iItems) {
  526.                 if (!strcmpi("SEPARATOR",label) || !strcmpi("-",label))
  527.                     pMenu->ModifyMenu(CASTUINT(idx),CASTUINT(MF_BYPOSITION | MF_SEPARATOR),NULL,"");
  528.                 else
  529.                     pMenu->ModifyMenu(CASTUINT(idx),CASTUINT(MF_BYPOSITION | MF_STRING),CASTUINT(FIRST_PLACES_MENU_ID + idx),label);
  530.             } else {
  531.                 if (!strcmpi("SEPARATOR",label) || !strcmpi("-",label))
  532.                     pMenu->InsertMenu(CASTUINT(idx),CASTUINT(MF_BYPOSITION | MF_SEPARATOR),NULL,"");
  533.                 else
  534.                     pMenu->InsertMenu(CASTUINT(idx),CASTUINT(MF_BYPOSITION | MF_STRING),CASTUINT(FIRST_PLACES_MENU_ID + idx),label);
  535.             }
  536.         }
  537.         if (label) {
  538.             XP_FREE(label);
  539.             label = NULL;
  540.         }
  541.     }
  542. }            
  543.  
  544. void CGenericFrame::BuildFileBookmarkMenu(CTreeMenu* pMenu, HT_Resource pRoot) 
  545. {
  546.     char *entryName;
  547.  
  548.     entryName = HT_GetNodeName(pRoot);
  549.  
  550.     if(strcmp(entryName, "") == 0)
  551.         entryName = szLoadString(IDS_UNTITLED_FOLDER);
  552.  
  553.     CTreeItem *item= new CTreeItem(NULL, NULL, FIRST_FILE_BOOKMARK_MENU_ID + m_nFileBookmarkItems, CString(entryName));
  554.  
  555.     pMenu->AddItem(item, 0, NULL);
  556.     m_pHotlistMenuMap->SetAt(FIRST_FILE_BOOKMARK_MENU_ID + m_nFileBookmarkItems++,    pRoot);
  557.  
  558.     pMenu->InsertMenu(FIRST_FILE_BOOKMARK_MENU_ID + m_nFileBookmarkItems++, MF_BYPOSITION | MF_SEPARATOR);
  559.  
  560.     m_BookmarksGarbageList->Add(item);
  561.     CTreeItem *pItem;
  562.  
  563.     HT_Cursor theCursor = HT_NewCursor(pRoot);
  564.     HT_Resource pEntry = NULL;
  565.     while (pEntry = HT_GetNextItem(theCursor))
  566.     {
  567.         if(HT_IsContainer(pEntry))
  568.         {
  569.             entryName = HT_GetNodeName(pEntry);
  570.             
  571.             if(strcmp(entryName, "") == 0)
  572.                 entryName = szLoadString(IDS_UNTITLED_FOLDER);
  573.  
  574.             pItem= new CTreeItem(NULL, NULL, FIRST_FILE_BOOKMARK_MENU_ID + m_nFileBookmarkItems, FEU_EscapeAmpersand(CString(entryName)));
  575.             pMenu->AddItem(pItem, FIRST_FILE_BOOKMARK_MENU_ID + m_nFileBookmarkItems, NULL);
  576.             m_pHotlistMenuMap->SetAt(FIRST_FILE_BOOKMARK_MENU_ID + m_nFileBookmarkItems++, pEntry);
  577.             m_BookmarksGarbageList->Add(pItem);
  578.         }
  579.     }
  580.  
  581. }
  582.  
  583. // Append menu items for each of the bookmark entries in pRoot. Uses
  584. // member data m_nBookmarkItems
  585. void CGenericFrame::BuildBookmarkMenu(CTreeMenu* pMenu, HT_Resource pRoot, int nStart) 
  586. {
  587.     ASSERT(pMenu && pRoot);
  588.     if (!pMenu || !pRoot)
  589.         return;
  590.  
  591.     m_pCachedTreeMenu = pMenu;
  592.     m_nCachedStartPoint = nStart;
  593.  
  594.     // Send the open/close event.
  595.     PRBool isOpen;
  596.     HT_GetOpenState(pRoot, &isOpen);
  597.     if (!isOpen)
  598.     {
  599.         HT_SetOpenState(pRoot, PR_TRUE);
  600.     }
  601.     else FinishMenuExpansion(pRoot);
  602. }
  603.  
  604. void CGenericFrame::FinishMenuExpansion(HT_Resource pRoot)
  605. {
  606.     CTreeMenu* pMenu = m_pCachedTreeMenu;
  607.     int nStart = m_nCachedStartPoint;
  608.  
  609.     // See how big the menu can be. Menus taller than the screen cause GPFs and hangs
  610.     // Do we want this static?  In Win95, menu font can change and this may no longer
  611.     // be valid after the first time through
  612.     //static int nItemHeight = GetSystemMetrics(SM_CYMENU);
  613.     int nItemHeight = GetSystemMetrics(SM_CYMENU);
  614.     static int nScreenHeight = GetSystemMetrics(SM_CYSCREEN);
  615.  
  616.     // While we have more items in the list and we haven't run out of screen
  617.     // real-estate continue to add items
  618.     BOOL        bStillRoom = TRUE;
  619.     int         nItemsAdded = pMenu->GetMenuItemCount(); // remember the constant items
  620.  
  621.     HT_Cursor theCursor = HT_NewCursor(pRoot);
  622.     HT_Resource pEntry = NULL;
  623.     while (theCursor && (pEntry = HT_GetNextItem(theCursor)) && bStillRoom)
  624.     {
  625.         char*   lpszShortName = NULL;
  626.         CString    csAmpersandName;
  627.     
  628.         // Don't add more menu items than we can handle
  629.         if((FIRST_BOOKMARK_MENU_ID + m_nBookmarkItems) > LAST_BOOKMARK_MENU_ID) 
  630.             break;
  631.  
  632.         // fe_MiddleCutString() doesn't like NULL pointers
  633.         if (HT_GetNodeName(pEntry)){
  634.             lpszShortName = fe_MiddleCutString(HT_GetNodeName(pEntry), MAX_MENU_ITEM_LENGTH);
  635.             csAmpersandName = FEU_EscapeAmpersand(CString(lpszShortName));
  636.         }
  637.  
  638.         // If this is a nested list or an item we must have a name
  639.         if ( !lpszShortName && !HT_IsSeparator(pEntry)) 
  640.             continue;
  641.  
  642.         if (HT_IsSeparator(pEntry)) 
  643.         {
  644.             // Handle separators
  645.             pMenu->InsertMenu(nStart, MF_BYPOSITION | MF_SEPARATOR);
  646.         } 
  647.         else if (HT_IsContainer(pEntry))
  648.         {
  649.             // Append a nested pop-up menu. We add an empty menu now, and when
  650.             // the user displays the sub-menu we dynamically add the menu items.
  651.             // This is faster, and it uses fewer USER resources (big deal for
  652.             // Win16)
  653.  
  654.             CTreeMenu *pSubMenu=new CTreeMenu;
  655.             pSubMenu->CreatePopupMenu();
  656.  
  657.             IconType nIconType = DetermineIconType(pEntry, FALSE);
  658.             void* pCustomIcon = NULL;
  659.             if (nIconType == LOCAL_FILE)
  660.                 pCustomIcon = FetchLocalFileIcon(pEntry);
  661.             else if (nIconType == ARBITRARY_URL)
  662.                 pCustomIcon = FetchCustomIcon(pEntry, pMenu, FALSE);
  663.             CTreeItem *item= new CTreeItem(m_pBookmarkFolderBitmap, m_pBookmarkFolderOpenBitmap,
  664.                                            (UINT)pSubMenu->GetSafeHmenu(),csAmpersandName, pSubMenu);
  665.  
  666.             pSubMenu->SetParent(this);
  667.             pMenu->AddItem(item, nStart, pSubMenu, pCustomIcon, nIconType);
  668.             m_BookmarksGarbageList->Add(item);
  669.         
  670.             // Add the HMENU to the map. We need to do this because Windows doesn't
  671.             // allow any client data to be associated with menu items. We can't use
  672.             // the same map as we use for menu items, because sub-menus don't have
  673.             // command IDs
  674.             m_pSubmenuMap->SetAt(pSubMenu->GetSafeHmenu(), pEntry);
  675.         }
  676.         else
  677.         {
  678.             // We're an URL
  679.             IconType nIconType = DetermineIconType(pEntry, FALSE);
  680.             void* pCustomIcon = NULL;
  681.             if (nIconType == LOCAL_FILE)
  682.                 pCustomIcon = FetchLocalFileIcon(pEntry);
  683.             else if (nIconType == ARBITRARY_URL)
  684.                 pCustomIcon = FetchCustomIcon(pEntry, pMenu, FALSE);
  685.             CTreeItem *item= new CTreeItem(m_pBookmarkBitmap, m_pBookmarkBitmap, 
  686.                 FIRST_BOOKMARK_MENU_ID + m_nBookmarkItems, csAmpersandName);
  687.  
  688.             pMenu->AddItem(item, nStart, NULL, pCustomIcon, nIconType);
  689.             m_BookmarksGarbageList->Add(item);
  690.         
  691.             // Add the URL to the map. We need to do this because Windows doesn't
  692.             // allow any client data to be associated with menu items. Note that
  693.             // we aren't making a copy of the string
  694.             m_pHotlistMenuMap->SetAt(FIRST_BOOKMARK_MENU_ID + m_nBookmarkItems,
  695.                 HT_GetNodeURL(pEntry));
  696.         }     
  697.  
  698.         // Even though separators and pull-right sub-menus don't have command IDs,
  699.         // increment the count of bookmark items for all three, because we rely
  700.         // on this being greater than zero to indicate that we have already built
  701.         // the bookmark menu
  702.         m_nBookmarkItems++;
  703.  
  704.         // In all three cases we added a new menu item
  705.         nItemsAdded++;
  706.  
  707.         nStart++;
  708.  
  709.         // Make sure we haven't grown too much -- allow to fill 4/5 of the
  710.         // screen
  711.         if ((nItemsAdded * nItemHeight > nScreenHeight * 4 / 5)) 
  712.         {
  713.             // Stop adding new ones
  714.             bStillRoom = FALSE;
  715.  
  716.             // Let the user know we have truncated the list
  717.             CTreeItem *item= new CTreeItem(NULL, NULL, ID_HOTLIST_VIEW, szLoadString(IDS_MORE_BOOKMARKS));
  718.  
  719.             pMenu->AddItem(item, nStart, NULL);
  720.             m_BookmarksGarbageList->Add(item);
  721.         }
  722.  
  723.         if (lpszShortName)
  724.             XP_FREE(lpszShortName);
  725.     }
  726. }
  727.  
  728.  
  729. BEGIN_MESSAGE_MAP(CGenericFrame, CFrameWnd)
  730.     ON_WM_TIMER()
  731.     ON_WM_ENTERIDLE()
  732.     ON_WM_CLOSE()
  733.     ON_WM_DESTROY()
  734.     ON_WM_CREATE()
  735.     ON_WM_SYSCOLORCHANGE()
  736.     ON_WM_QUERYNEWPALETTE()
  737.     ON_WM_PALETTECHANGED()
  738.     ON_WM_INITMENUPOPUP()
  739.     ON_WM_MENUSELECT()
  740.     ON_WM_MEASUREITEM()
  741.     ON_WM_MENUCHAR()
  742.     ON_MESSAGE(WM_SETMESSAGESTRING, OnSetMessageString)
  743.     ON_WM_SETFOCUS()
  744.     ON_WM_WINDOWPOSCHANGED()
  745.     ON_WM_WINDOWPOSCHANGING()
  746.     ON_WM_SIZE()
  747.     ON_WM_MOVE()
  748.     ON_WM_GETMINMAXINFO()
  749.     ON_WM_SETFOCUS()
  750.     ON_WM_WINDOWPOSCHANGED()
  751.     ON_WM_ACTIVATE()
  752.  
  753.     ON_COMMAND(ID_FILE_CLOSE, OnFrameExit)
  754.     ON_COMMAND(ID_FILE_PAGE_SETUP, OnFilePageSetup)
  755.     ON_COMMAND(ID_OPEN_MAIL_WINDOW, OnOpenMailWindow)
  756.     ON_COMMAND(ID_OPEN_NEWS_WINDOW, OnOpenNewsWindow)
  757.     ON_COMMAND(ID_WINDOW_BOOKMARKWINDOW, OnShowBookmarkWindow)
  758.     ON_COMMAND(ID_WINDOW_ADDRESSBOOK, OnShowAddressBookWindow)
  759. #ifdef JAVA
  760.     ON_COMMAND(ID_OPTIONS_SHOWJAVACONSOLE, OnToggleJavaConsole)
  761.     ON_UPDATE_COMMAND_UI(ID_OPTIONS_SHOWJAVACONSOLE, OnUpdateJavaConsole)
  762. #endif
  763.     ON_COMMAND(ID_FILE_MAILNEW, OnFileMailNew) 
  764. #ifdef MOZ_TASKBAR
  765.     ON_COMMAND(ID_WINDOW_TASKBAR, OnTaskbar)
  766. #endif /* MOZ_TASKBAR */
  767.     ON_COMMAND(ID_WINDOW_LIVECALL, OnLiveCall)
  768.     ON_UPDATE_COMMAND_UI(ID_WINDOW_LIVECALL, OnUpdateLiveCall)
  769.     ON_COMMAND(ID_WINDOW_CALENDAR, OnCalendar)
  770.     ON_COMMAND(ID_WINDOW_IBMHOSTONDEMAND, OnIBMHostOnDemand)
  771.     ON_COMMAND(ID_WINDOW_NETCASTER, OnNetcaster)
  772.     ON_COMMAND(ID_WINDOW_AIM, OnAim)
  773.     ON_COMMAND(ID_COMMAND_ABOUT, OnAbout)
  774.     ON_COMMAND(ID_APP_ABOUT, OnAbout)
  775.     ON_COMMAND(ID_DOCUMENT_TOP, OnDocumentTop)
  776.     ON_COMMAND(ID_DOCUMENT_BOTTOM, OnDocumentBottom)
  777.     ON_COMMAND(ID_HOTLIST_FISHCAM, OnFishCam)
  778.     ON_COMMAND(ID_OPTIONS_PREFERENCES, OnDisplayPreferences)
  779.     ON_COMMAND(ID_OPTIONS_MAILANDNEWS, OnPrefsMailNews)
  780.     ON_COMMAND(ID_BIG_SWITCH, OnGoOffline)
  781.     ON_UPDATE_COMMAND_UI(ID_BIG_SWITCH, OnUpdateGoOffline)
  782.     ON_COMMAND(ID_DONEGOINGOFFLINE, OnDoneGoingOffline)
  783. #ifdef FORTEZZA
  784.     ON_COMMAND(ID_FORTEZZA_CARD, OnStartFortezzaCard)
  785.     ON_COMMAND(ID_FORTEZZA_CHANGE, OnStartFortezzaChange)
  786.     ON_COMMAND(ID_FORTEZZA_VIEW, OnStartFortezzaView)
  787.     ON_COMMAND(ID_FORTEZZA_INFO, OnDoFortezzaInfo)
  788.     ON_COMMAND(ID_FORTEZZA_LOG, OnDoFortezzaLog)
  789. #endif
  790.     ON_COMMAND(ID_FILE_CLOSE, OnFrameExit)
  791.  
  792.     ON_UPDATE_COMMAND_UI(ID_VIEW_COMMANDTOOLBAR, OnUpdateViewCommandToolbar)
  793.     ON_COMMAND(ID_VIEW_COMMANDTOOLBAR, OnViewCommandToolbar)
  794.     ON_UPDATE_COMMAND_UI(ID_VIEW_LOCATIONTOOLBAR, OnUpdateViewLocationToolbar)
  795.     ON_COMMAND(ID_VIEW_LOCATIONTOOLBAR, OnViewLocationToolbar)
  796.     ON_UPDATE_COMMAND_UI(ID_VIEW_CUSTOMTOOLBAR, OnUpdateViewCustomToolbar)
  797.     ON_COMMAND(ID_VIEW_CUSTOMTOOLBAR, OnViewCustomToolbar)
  798.     ON_UPDATE_COMMAND_UI(ID_VIEW_NAVCENTER, OnUpdateViewNavCenter)
  799.     ON_COMMAND(ID_VIEW_NAVCENTER, OnViewNavCenter)
  800.     ON_UPDATE_COMMAND_UI(ID_CUSTOMIZE_TOOLBAR, OnUpdateCustomizeToolbar)
  801.     ON_COMMAND(ID_CUSTOMIZE_TOOLBAR, OnCustomizeToolbar)
  802.     ON_UPDATE_COMMAND_UI(ID_PLACES, OnUpdatePlaces)
  803.     ON_UPDATE_COMMAND_UI(ID_SECURITY, OnUpdateSecurity)
  804.     ON_COMMAND(ID_SECURITY, OnSecurity)
  805.     ON_COMMAND(ID_GO_HISTORY, OnGoHistory)
  806.  
  807.     ON_COMMAND(ID_VIEW_INCREASEFONT, OnIncreaseFont)
  808.     ON_COMMAND(ID_VIEW_DECREASEFONT, OnDecreaseFont)
  809.  
  810.     ON_COMMAND(ID_ANIMATION_BONK, OnAnimationBonk )
  811.  
  812.     ON_COMMAND(ID_NEW_FRAME, OnNewFrame)
  813.     ON_UPDATE_COMMAND_UI(ID_NEW_FRAME, OnUpdateNewFrame)
  814.     ON_COMMAND(ID_FILE_OPENURL, OnFileOpenurl)
  815.     ON_UPDATE_COMMAND_UI(ID_FILE_OPENURL, OnUpdateFileOpenurl)
  816.  
  817.     ON_COMMAND(ID_NEXT_WINDOW, OnNextWindow)
  818.     ON_COMMAND(ID_SAVE_OPTIONS, OnSaveOptions)
  819.     ON_COMMAND(ID_HOTLIST_VIEW,OnShowBookmarkWindow) 
  820.     ON_COMMAND(ID_HOTLIST_ADDCURRENTTOHOTLIST, OnHotlistAddcurrenttohotlist)
  821.     ON_UPDATE_COMMAND_UI(ID_HOTLIST_ADDCURRENTTOHOTLIST, OnUpdateHotlistAddcurrenttohotlist)
  822.     ON_COMMAND(ID_HOTLIST_TOOLBAR, OnHotlistAddcurrenttotoolbar)
  823.     ON_UPDATE_COMMAND_UI(ID_HOTLIST_TOOLBAR, OnUpdateHotlistAddcurrenttotoolbar)
  824. #ifdef MOZ_TASKBAR
  825.     ON_UPDATE_COMMAND_UI(ID_WINDOW_TASKBAR, OnUpdateTaskbar)
  826. #endif /* MOZ_TASKBAR */   
  827.     ON_COMMAND(ID_TOOLS_MAIL, OnOpenMailWindow)
  828.     ON_COMMAND(ID_TOOLS_INBOX, OnOpenInboxWindow)
  829.     ON_COMMAND(ID_TOOLS_NEWS, OnOpenNewsWindow)
  830.     ON_COMMAND(ID_TOOLS_WEB, OnToolsWeb)
  831. #ifdef EDITOR
  832.     ON_COMMAND(ID_TOOLS_EDITOR, OnOpenComposerWindow)
  833. #endif
  834. #ifdef MOZ_MAIL_NEWS   
  835.     ON_COMMAND(ID_TOOLS_ADDRESSBOOK, OnShowAddressBookWindow)
  836. #endif /* MOZ_MAIL_NEWS */  
  837.     ON_COMMAND(ID_TOOLS_BOOKMARKS, OnShowBookmarkWindow)
  838.     ON_COMMAND(ID_VIEW_ADVANCEDTOOLBARS, OnShowAdvanced)
  839.     ON_COMMAND(ID_EDIT_LDAPSEARCH, OnLDAPSearch)
  840.     ON_UPDATE_COMMAND_UI(ID_VIEW_ADVANCEDTOOLBARS, OnUpdateShowAdvanced)
  841.     ON_REGISTERED_MESSAGE(WM_FINDREPLACE, OnFindReplace)
  842.     ON_COMMAND(IDM_SEARCHADDRESSES, OnLDAPSearch)
  843.     ON_COMMAND(ID_COMMAND_PAGE_FROM_WIZARD, OnPageFromWizard)
  844.     ON_REGISTERED_MESSAGE(WM_HELPMSG, OnHelpMsg)
  845.  
  846.  
  847. #ifdef ON_COMMAND_RANGE
  848.         ON_COMMAND_RANGE(ID_OPTIONS_ENCODING_1, ID_OPTIONS_ENCODING_70, OnToggleEncoding)
  849.         ON_UPDATE_COMMAND_UI_RANGE(ID_OPTIONS_ENCODING_1, ID_OPTIONS_ENCODING_70, OnUpdateEncoding)
  850. #endif
  851.  
  852. #ifdef EDITOR
  853.     ON_COMMAND(ID_EDT_NEW_DOC_BLANK, OnEditNewBlankDocument)
  854.       ON_UPDATE_COMMAND_UI(ID_EDT_NEW_DOC_BLANK, OnUpdateCanInteract)
  855.     ON_COMMAND(ID_ACTIVATE_SITE_MANAGER, OnActivateSiteManager)
  856.     ON_UPDATE_COMMAND_UI(ID_ACTIVATE_SITE_MANAGER, OnUpdateActivateSiteManager)
  857.     ON_COMMAND(ID_EDIT_DOCUMENT, OnNavigateToEdit)
  858.     ON_COMMAND(ID_EDIT_FRAME, OnEditFrame)
  859.     ON_UPDATE_COMMAND_UI(ID_EDIT_DOCUMENT, OnUpdateCanInteract)
  860.     ON_UPDATE_COMMAND_UI(ID_EDIT_FRAME, OnUpdateEditFrame)
  861.     ON_COMMAND(ID_EDT_NEW_DOC_FROM_TEMPLATE, OnEditNewDocFromTemplate)
  862.       ON_UPDATE_COMMAND_UI(ID_EDT_NEW_DOC_FROM_TEMPLATE, OnUpdateCanInteract)
  863. #ifdef XP_WIN32
  864.     ON_REGISTERED_MESSAGE(WM_SITE_MANAGER, OnSiteMgrMessage)
  865.     // jliu added the following to support CJK caption print
  866.     ON_WM_NCPAINT()
  867.     ON_MESSAGE(WM_SETTEXT, OnSetText)
  868.     ON_WM_NCACTIVATE()
  869.     ON_MESSAGE(WM_SETTINGCHANGE, OnSettingChange)
  870. #endif
  871.     ON_REGISTERED_MESSAGE(WM_NG_IS_ACTIVE, OnNetscapeGoldIsActive)
  872.     ON_REGISTERED_MESSAGE(WM_OPEN_EDITOR, OnOpenEditor)
  873.     ON_REGISTERED_MESSAGE(WM_OPEN_NAVIGATOR, OnOpenNavigator)
  874. #endif // EDITOR
  875.     ON_COMMAND(ID_COMMAND_HELPINDEX, OnHelpMenu)
  876.     ON_UPDATE_COMMAND_UI(ID_BOOKMARKS_FILEROOT, OnUpdateFileRoot)
  877.  
  878. //  Conditionally compile these if supported.
  879. #ifdef WM_DEVICECHANGE
  880.     ON_WM_DEVICECHANGE()
  881. #endif
  882. #ifdef WM_SIZING
  883.     ON_WM_SIZING()
  884. #endif
  885.  
  886. #ifdef _WIN32
  887.     ON_REGISTERED_MESSAGE(msg_MouseWheel, OnHackedMouseWheel)
  888. #endif
  889.  
  890. #ifdef DEBUG_WHITEBOX
  891.     ON_COMMAND(IDS_WHITEBOX_MENU, OnWhiteBox)
  892. #endif
  893. END_MESSAGE_MAP()
  894.  
  895. /////////////////////////////////////////////////////////////////////////////
  896. // CGenericFrame message handlers
  897.  
  898. void CGenericFrame::RecalcLayout ( BOOL bNotify )
  899. {
  900.     for(CGenericFrame * f = theApp.m_pFrameList; f; f = f->m_pNext)
  901.         f->CFrameWnd::RecalcLayout ( );
  902. }
  903.  
  904. void CGenericFrame::GetMessageString( UINT nID, CString& rMessage ) const
  905. {
  906.     LPTSTR lpsz = NULL;
  907.     if (nID >= FIRST_BOOKMARK_MENU_ID && nID <= LAST_BOOKMARK_MENU_ID) {
  908.         m_pHotlistMenuMap->Lookup(nID, (void*&)lpsz);
  909.         if (lpsz) {
  910.             rMessage = lpsz;
  911.         }
  912.     } else if (IS_PLACESMENU_ID(nID)  || IS_HELPMENU_ID(nID)) {
  913.         rMessage = "";  // for now -- jonm
  914.     } else if (nID==ID_COMMAND_HELPINDEX) {
  915.         rMessage = szLoadString(IDS_COMMAND_HELPINDEX);
  916.     } else if (nID==ID_COMMAND_ABOUT) {
  917.         rMessage = szLoadString(IDS_COMMAND_ABOUT);
  918.     } else {
  919. #ifdef _WIN32
  920.         if ( nID ) {
  921.             CFrameWnd::GetMessageString( nID, rMessage );
  922.         }
  923. #else
  924.         // Use the wParam as a string ID
  925.         lpsz = szLoadString(nID);
  926.         // If we got an empty string, punt
  927.         if (lpsz && lpsz[0]) {
  928.             // Only display until the newline so we don't get the tool tip string
  929.             AfxExtractSubString( rMessage, lpsz, 0 );
  930.         }
  931. #endif
  932.     }
  933. }
  934.  
  935. // Read the initial sizes out of preferences file
  936. //
  937. BOOL CGenericFrame::PreCreateWindow(CREATESTRUCT& cs)
  938. {
  939.     BOOL retval;
  940.  
  941.     if(m_hPopupParent)
  942.         cs.style |= WS_POPUP;
  943.  
  944.     m_bPreCreated = TRUE;
  945.  
  946.     // Let's sanity check those values, kiddies
  947.  
  948.     if ( cs.x > ( GetSystemMetrics(SM_CXFULLSCREEN) - 100 ) ) {
  949.         cs.x = GetSystemMetrics(SM_CXFULLSCREEN) - 100;
  950.     }
  951.     if ( cs.y > ( GetSystemMetrics(SM_CYFULLSCREEN) - 100 ) ) {
  952.         cs.y = GetSystemMetrics(SM_CYFULLSCREEN) - 100;
  953.     }
  954.        
  955.     retval = CFrameWnd::PreCreateWindow(cs);
  956.  
  957.  
  958. #ifdef WIN32
  959.     // Modify Ex_Styles set by MFC.
  960.     cs.dwExStyle |= m_wAddedExStyles;
  961.         cs.dwExStyle &= ~m_wRemovedExStyles;
  962. #endif
  963.  
  964.         return(retval);
  965. }
  966.  
  967. //
  968. // Create widgets used by all frame windows 
  969. //
  970. static void CopyMenu(CMenu *srcMenu, CTreeMenu *destMenu, CTreeItemList *pGarbageList)
  971. {
  972.     if (!srcMenu)
  973.         return;
  974.  
  975.     int nCount = srcMenu->GetMenuItemCount();
  976.     for(int dstPos = 0, srcPos = 0; dstPos< nCount; dstPos++, srcPos++)
  977.     {
  978.         UINT nID = srcMenu->GetMenuItemID(srcPos);
  979.         
  980.         if(nID == 0)
  981.         {
  982.             destMenu->InsertMenu(dstPos, MF_BYPOSITION | MF_SEPARATOR);
  983.         }
  984.         else
  985.         {
  986.             char lpszMenuString[64];
  987.             
  988.             srcMenu->GetMenuString(srcPos, lpszMenuString, 64, MF_BYPOSITION);
  989.             CString menuString(lpszMenuString);
  990.             int nMnemonicPos;
  991.             TCHAR cMnemonicChar = 0;
  992.  
  993.             if((nMnemonicPos = menuString.Find('&')) != -1)
  994.                 if(nMnemonicPos + 1 < menuString.GetLength())
  995.                     cMnemonicChar = menuString[nMnemonicPos + 1];
  996.  
  997.             if(nID == (UINT) -1)
  998.             {
  999.                 CMenu *pSubMenu = srcMenu->GetSubMenu(srcPos);
  1000.                 CTreeMenu *pTreeSubMenu=new CTreeMenu;
  1001.  
  1002.                 pTreeSubMenu->CreatePopupMenu();
  1003.                 
  1004.                 CopyMenu(pSubMenu, pTreeSubMenu, pGarbageList);
  1005.  
  1006.                 srcMenu->RemoveMenu(srcPos, MF_BYPOSITION);
  1007.                 CTreeItem *pItem= new CTreeItem(NULL, NULL,(UINT)pTreeSubMenu->GetSafeHmenu(), menuString, pTreeSubMenu);
  1008.                 ((CTreeMenu*)destMenu)->AddItem(pItem, dstPos,pTreeSubMenu );
  1009.  
  1010.                 if(cMnemonicChar != 0)
  1011.                     destMenu->AddMnemonic(cMnemonicChar, 0, dstPos);
  1012.  
  1013.                 pGarbageList->Add(pItem);
  1014.                 //since we removed a menu we want to use the same position next time
  1015.                 //and there is one less item in the menu we are copying.
  1016.                 srcPos--;
  1017.             }
  1018.             else if(nID > 0)
  1019.             {
  1020.                 CTreeItem *pItem= new CTreeItem(NULL, NULL, nID, lpszMenuString);
  1021.                 ((CTreeMenu*)destMenu)->AddItem(pItem, dstPos);
  1022.  
  1023.                 if(cMnemonicChar != 0)
  1024.                     destMenu->AddMnemonic(cMnemonicChar, nID, dstPos);
  1025.  
  1026.                 pGarbageList->Add(pItem);
  1027.                 //destMenu->InsertMenu(i, MF_BYPOSITION | MF_STRING, nID, (const char*)menuString);
  1028.             }
  1029.         }
  1030.     }
  1031.     ((CTreeMenu*)destMenu)->CalculateItemDimensions();
  1032.  
  1033. }
  1034.  
  1035.  
  1036. void CGenericFrame::InitFileBookmarkMenu(void)
  1037. {
  1038.     int nCount = m_pFileBookmarkMenu->GetMenuItemCount();
  1039.  
  1040.     for(int i = nCount - 1; i >=0; i--)
  1041.         m_pFileBookmarkMenu->DeleteMenu(i, MF_BYPOSITION);
  1042.     m_pFileBookmarkMenu->ClearItems(0, 0);
  1043.     m_pFileSubmenuMap->RemoveAll();
  1044.  
  1045.     HT_View pView = HT_GetSelectedView(m_BookmarkMenuPane);
  1046.  
  1047.     m_pFileSubmenuMap->SetAt(m_pFileBookmarkMenu->GetSafeHmenu(), HT_TopNode(pView));
  1048. }
  1049.  
  1050. void CGenericFrame::LoadBookmarkMenuBitmaps(void)
  1051. {
  1052.     HDC hDC = ::GetDC(m_hWnd);
  1053.  
  1054.     WFE_InitializeUIPalette(hDC);
  1055.     HPALETTE hPalette = WFE_GetUIPalette(this);
  1056.     m_pBookmarksMenu->SetParent(this);
  1057.     HPALETTE hOldPalette = ::SelectPalette(hDC, hPalette, FALSE);
  1058.     m_pBookmarkBitmap=new CBitmap;
  1059.     m_pBookmarkBitmap->Attach(wfe_LoadBitmap(AfxGetResourceHandle(), hDC, MAKEINTRESOURCE(IDB_BOOKMARK_ITEM)));
  1060.  
  1061.     m_pBookmarkFolderBitmap=new CBitmap;
  1062.     m_pBookmarkFolderBitmap->Attach(wfe_LoadBitmap(AfxGetResourceHandle(), hDC, MAKEINTRESOURCE(IDB_BOOKMARK_FOLDER2)));
  1063.  
  1064.     m_pBookmarkFolderOpenBitmap=new CBitmap;
  1065.     m_pBookmarkFolderOpenBitmap->Attach(wfe_LoadBitmap(AfxGetResourceHandle(), hDC, MAKEINTRESOURCE(IDB_BOOKMARK_FOLDER_OPEN)));
  1066.  
  1067.     ::SelectPalette(hDC, hOldPalette, TRUE);
  1068.     ::ReleaseDC(m_hWnd, hDC);
  1069. }
  1070.  
  1071. void CGenericFrame::AddToMenuMap(int nIndex, UINT nID)
  1072. {
  1073.     HMENU hMainMenu = ::GetMenu(m_hWnd);
  1074.     
  1075.     if(hMainMenu)
  1076.     {
  1077.         HMENU hSubMenu = ::GetSubMenu(hMainMenu, nIndex);
  1078.  
  1079.         if(hSubMenu && m_pMenuMap)
  1080.         {
  1081.             UINT * pID = new UINT;
  1082.             
  1083.             if(pID)
  1084.             {
  1085.                 *pID = nID;
  1086. #ifdef _WIN32
  1087.                 m_pMenuMap->SetAt(hSubMenu, pID);
  1088. #else
  1089.                 m_pMenuMap->SetAt((WORD)hSubMenu, pID);
  1090. #endif
  1091.             }
  1092.         }
  1093.  
  1094.     }
  1095.  
  1096. }
  1097.  
  1098. void CGenericFrame::OnDestroy()
  1099. {
  1100.     ASSERT(!m_pHotlistMenuMap || m_pHotlistMenuMap->IsEmpty());
  1101.     ASSERT(!m_pSubmenuMap || m_pSubmenuMap->IsEmpty());
  1102. //    ASSERT(!m_pFileSubmenuMap || m_pFileSubmenuMap->IsEmpty());
  1103.  
  1104.     // Unload the bookmark bitmaps and delete them
  1105.     if ( m_pBookmarkBitmap ) {
  1106.         m_pBookmarkBitmap->DeleteObject();
  1107.         m_pBookmarkFolderBitmap->DeleteObject();
  1108.         m_pBookmarkFolderOpenBitmap->DeleteObject();
  1109.     }
  1110.     delete m_pBookmarkBitmap;
  1111.     delete m_pBookmarkFolderBitmap;
  1112.     delete m_pBookmarkFolderOpenBitmap;
  1113.     if ( m_pBookmarksMenu ) {
  1114.         HMENU hBookmarkMenu=m_pBookmarksMenu->m_hMenu;
  1115.         ASSERT(hBookmarkMenu);
  1116.         int nCount;
  1117.         if ((nCount = ::GetMenuItemCount(hBookmarkMenu)) > 0) {
  1118.  
  1119.  
  1120.             // Because the bookmark menu has separators and pull-right sub-menus,
  1121.             // neither of which have command IDs, we can't tell just by looking
  1122.             // at the menu items whether they should be deleted. So instead we
  1123.             // delete everything
  1124.             for (int i = nCount - 1;
  1125.                  i >= 0; i--) {
  1126.                 // This will delete any sub-menus as well (recursively)
  1127.                 if(m_pBookmarksMenu->GetSubMenu(i) != NULL)
  1128.                     m_pBookmarksMenu->GetSubMenu(i)->DestroyMenu();
  1129.                 VERIFY(::DeleteMenu(hBookmarkMenu, i, MF_BYPOSITION));
  1130.             }
  1131.             //don't care about separator before bookmarks
  1132.             m_pBookmarksMenu->ClearItems(0, 0);
  1133.             m_nBookmarkItems = 0;  // reset the number of current bookmark menu items
  1134.             delete m_OriginalBookmarksGarbageList;
  1135.         }
  1136.  
  1137.         m_pBookmarksMenu->DestroyMenu();
  1138.     }
  1139.     delete m_pBookmarksMenu;
  1140.     
  1141.     //
  1142.     // Explicitly destroy the status bar window.  Normally the status bar is a child of this
  1143.     // frame and receives a WM_DESTROY as a result of this window destroying.  However, when 
  1144.     // this frame is serving an OLE container the status bar's parent is the container, hence
  1145.     // we need to destroy the window now.  Note the status bar is an auto-delete CWnd object.
  1146.     //
  1147.      LPNSSTATUSBAR pIStatusBar = NULL;
  1148.      if( GetChrome() && 
  1149.         SUCCEEDED(GetChrome()->QueryInterface( IID_INSStatusBar, (LPVOID *)&pIStatusBar )) && 
  1150.         pIStatusBar ) 
  1151.      {
  1152.         CNetscapeStatusBar *pStatusBar = ((CGenericStatusBar *)pIStatusBar)->GetNetscapeStatusBar();
  1153.         
  1154.         if( pStatusBar )
  1155.         {
  1156.             pStatusBar->DestroyWindow();
  1157.         }
  1158.          pIStatusBar->Release();
  1159.      }
  1160.     
  1161.     // we no longer need a taskbar.
  1162. #ifdef MOZ_TASKBAR
  1163.     theApp.GetTaskBarMgr().Reference(FALSE);
  1164. #endif /* MOZ_TASKBAR */   
  1165.  
  1166. }
  1167.  
  1168. BOOL CGenericFrame::OnQueryNewPalette() 
  1169. {
  1170.     // Have the main context in this window realize its palette.
  1171.     CWinCX *pWinCX = GetMainWinContext();
  1172.     CView* focusWnd = GetActiveView();
  1173.     BOOL retval = FALSE;
  1174.     HPALETTE hPal = WFE_GetUIPalette(this);    
  1175.     if (pWinCX) {
  1176.         if (!pWinCX->IsDestroyed()) {
  1177.         //    Make sure this is needed.
  1178.             if(pWinCX->GetPalette() != NULL) {
  1179.                 //    Realize the palette.
  1180.                 retval = CFrameGlue::GetFrameGlue(this)->RealizePalette(this, pWinCX->GetPane(), FALSE);
  1181.             }
  1182.         }
  1183.     }
  1184.     else  {
  1185.         CDC* pDC = GetDC();
  1186.         if (pDC) {
  1187.             ::SelectPalette(pDC->GetSafeHdc(), hPal, FALSE);
  1188.             retval = ::RealizePalette(pDC->GetSafeHdc());
  1189.             Invalidate();
  1190.             SendMessageToDescendants(WM_PALETTECHANGED, (WPARAM)GetSafeHwnd());
  1191. #ifdef MOZ_TASKBAR
  1192.             if(theApp.GetTaskBarMgr().IsInitialized() && theApp.GetTaskBarMgr().IsFloating())
  1193.                 theApp.GetTaskBarMgr().ChangeTaskBarsPalette(GetSafeHwnd());
  1194. #endif /* MOZ_TASKBAR */
  1195.             ReleaseDC(pDC);
  1196.         }
  1197.  
  1198.     }
  1199.     return retval;    
  1200. }
  1201.  
  1202. // Only top-level windows will receive this message
  1203. void CGenericFrame::OnPaletteChanged(CWnd* pFocusWnd) 
  1204. {
  1205.  
  1206. //    CFrameWnd::OnPaletteChanged(pFocusWnd);
  1207.     
  1208.     //    Don't do this if we caused it to happen.
  1209.     if(pFocusWnd == (CWnd *)this)    {
  1210.         return;
  1211.     }
  1212.  
  1213.     TRACE("CGenericFrame::OnPaletteChanged(%p)\n", pFocusWnd);
  1214.     // Tell the main context to realize the palette and redraw.           f
  1215.     CWinCX *pWinCX = GetActiveWinContext();
  1216.     if(pWinCX && !pWinCX->IsDestroyed())    {
  1217.         HPALETTE pPal = pWinCX->GetPalette();
  1218.         //    Make sure this is needed.
  1219.         if( pPal )    {
  1220.             //    Realize the palette.
  1221.             //    Detect if it's a child view, and don't do anything.     If we cause a
  1222.             //  palette change.
  1223.  
  1224.             if ((IsChild(pFocusWnd) == TRUE) && FEU_IsNetscapeFrame(pFocusWnd)) {
  1225.                     TRACE("Blocking child view palette change\n");
  1226.             }
  1227.             else {
  1228.                 // Either a plug-in or a Java child window realized its
  1229.                 // palette, or a different top-level window realized
  1230.                 // its palette.  Realize the Navigator's palette in
  1231.                 // the background.
  1232.                     CFrameGlue::GetFrameGlue(this)->RealizePalette(this, pFocusWnd->GetSafeHwnd(), TRUE);
  1233.             }
  1234.         }
  1235.     }
  1236. }
  1237. extern void FE_PokeLibSecOnIdle();
  1238.  
  1239. BOOL CGenericFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
  1240. {
  1241.  
  1242.    if( nID >= ID_OPTIONS_ENCODING_1 && nID <= ID_OPTIONS_ENCODING_70 && 
  1243.        (nCode == CN_UPDATE_COMMAND_UI))  
  1244.    {
  1245.           OnUpdateEncoding( (CCmdUI*) pExtra );
  1246.           return TRUE;
  1247.    }
  1248.     // give me extra randomness for the first couple of messages
  1249.     static int s_nLibSecCount = 0;
  1250.     if(s_nLibSecCount < 300) {
  1251.         FE_PokeLibSecOnIdle();
  1252.         s_nLibSecCount++;
  1253.     }
  1254.         
  1255.  
  1256.     //    Pump through any active child first.
  1257.     //    This will catch active control bars, etc.
  1258.     CWnd *pFocus = GetFocus();
  1259.     if( pFocus )    {
  1260.         //    Make sure it's a child of us, and not a CGenericView (we handle those below).
  1261.         //    Also make sure it's not a child of our main view.
  1262.         //        Those are handled by the view, not us.
  1263.         BOOL bFrameChild = IsChild(pFocus);
  1264.         BOOL bGenericView = pFocus->IsKindOf(RUNTIME_CLASS(CGenericView));
  1265.         BOOL bViewChild = FALSE;
  1266.         if(GetMainWinContext() && GetMainWinContext()->GetPane())    {
  1267.             bViewChild = ::IsChild(GetMainWinContext()->GetPane(), pFocus->m_hWnd);
  1268.         }
  1269.  
  1270.         if(bFrameChild == TRUE && bGenericView == FALSE && bViewChild == FALSE)    {
  1271.             //    Try an OnCmdMessage, probably a URL bar, or message list.
  1272.             //    Walk up the list of parents until we reach ourselves.
  1273.             CWnd *pTarget = pFocus;
  1274.             while(pTarget != NULL && pTarget != (CWnd *)this)    {
  1275.                 if(pTarget->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))    {
  1276.                     return(TRUE);
  1277.                 }
  1278.                 pTarget = pTarget->GetParent();
  1279.                 
  1280.                 //  There are cases now where a child is actually a CGenericView
  1281.                 //      such as the NavCenter HTML pane.  Do not allow it to
  1282.                 //      receive these messages.
  1283.                 if(pTarget->IsKindOf(RUNTIME_CLASS(CGenericView))) {
  1284.                     pTarget = NULL;
  1285.                 }
  1286.             }
  1287.         }
  1288.     }
  1289.  
  1290.     //    Pump the message through our active context first.
  1291.     CWinCX *pActiveCX = GetActiveWinContext();
  1292.     CGenericView *pGenView = pActiveCX ? pActiveCX->GetView() : NULL;
  1293.     if(pGenView)    {
  1294.         if(pGenView->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))  {
  1295.             return(TRUE);
  1296.         }
  1297.     }
  1298.  
  1299.     //    Next, pump the message through our main context.
  1300.     pActiveCX = GetMainWinContext();
  1301.     pGenView = pActiveCX ? pActiveCX->GetView() : NULL;
  1302.     if(pGenView)    {
  1303.         if(pGenView->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))  {
  1304.             return(TRUE);
  1305.         }
  1306.     }
  1307.  
  1308.     // always enable bookmark entries
  1309.     if((nID >= FIRST_BOOKMARK_MENU_ID) && (nID < LAST_BOOKMARK_MENU_ID) && (nCode == CN_UPDATE_COMMAND_UI))  {
  1310.         ASSERT(pExtra);
  1311.         CCmdUI* pCmdUI = (CCmdUI*)pExtra;
  1312.         pCmdUI->Enable();
  1313.         return(TRUE);
  1314.     }
  1315.  
  1316.     // always enable windows menu entries
  1317.     if((nID >= ID_WINDOW_WINDOW_0) && (nID < ID_WINDOW_WINDOW_0 + 10) && (nCode == CN_UPDATE_COMMAND_UI))  {
  1318.         ASSERT(pExtra);
  1319.         CCmdUI* pCmdUI = (CCmdUI*)pExtra;
  1320.         pCmdUI->Enable();
  1321.         return(TRUE);
  1322.     }
  1323.  
  1324.     // was this a windows menu selection ?
  1325.     if((nID >= ID_WINDOW_WINDOW_0) && (nID < ID_WINDOW_WINDOW_0 + 10) && (nCode == CN_COMMAND))  {
  1326.         CGenericFrame * pFrame = theApp.m_pFrameList;
  1327.         BOOL bDone = FALSE;
  1328.         // walk down frame list till we get to the one we wanted
  1329.         int iToGo = CASTINT(nID - ID_WINDOW_WINDOW_0);
  1330.         while( pFrame && !bDone ) {
  1331.             if (iToGo == 0) {
  1332.                 bDone = TRUE;
  1333.                 break;
  1334.             } else {
  1335.                 iToGo--;
  1336.                 // Fall through to default to move to next frame.
  1337.             }
  1338.             pFrame = pFrame->m_pNext;
  1339.         }
  1340.  
  1341.         // if we got something un-minimize it and pop it to the front
  1342.         if(pFrame) {
  1343.             if(pFrame->IsIconic())  {
  1344.                 pFrame->ShowWindow(SW_RESTORE);
  1345.             }
  1346.             pFrame->BringWindowToTop();
  1347.         }
  1348.  
  1349.         // assume we got something or at least the message was for us
  1350.         return(TRUE);
  1351.     }
  1352.  
  1353.     // then pump through frame  
  1354.     return(CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo));
  1355. }
  1356.  
  1357.  
  1358. #ifdef EDITOR
  1359. // Used to gray menu/toolbar commands depending on presence of
  1360. //   context and its loading and blocked states
  1361. void CGenericFrame::OnUpdateCanInteract(CCmdUI* pCmdUI)
  1362. {
  1363.     pCmdUI->Enable(GetMainWinContext() && GetMainWinContext()->GetContext());
  1364. }
  1365.  
  1366. void CGenericFrame::OnUpdateEditFrame(CCmdUI *pCmdUI)
  1367. {
  1368.     // enable EditFrame menu only if a frame in a frameset is selected.
  1369.     pCmdUI->Enable(GetActiveWinContext() && GetActiveWinContext()->GetContext() && GetActiveWinContext()->IsGridCell());
  1370. }
  1371.  
  1372.  
  1373. //
  1374. // NOTE: Editor-related methods of CGenericFrame are in EDFRAME.CPP
  1375. //
  1376. #endif // EDITOR
  1377.  
  1378. void CGenericFrame::BuildHelpMenu(CMenu * pMenu) 
  1379. {
  1380.     if (!pMenu) return; 
  1381.     if(GetMainContext() == NULL)    {
  1382.         return;
  1383.     }
  1384.     //static bChanged = TRUE;
  1385.     
  1386.     //if (!bChanged) return;
  1387.  
  1388.     int idx =0, idx2=0;
  1389.     int iItems = pMenu->GetMenuItemCount();    
  1390.     char *label;
  1391.     int bOK = PREF_NOERROR;
  1392.  
  1393.     CString helpContents;
  1394.     helpContents.LoadString(IDS_HELPCONTENTS);
  1395.     if (idx < iItems) 
  1396.         pMenu->ModifyMenu(idx,MF_BYPOSITION | MF_STRING,ID_COMMAND_HELPINDEX, helpContents);
  1397.     else
  1398.         pMenu->InsertMenu(idx,MF_BYPOSITION | MF_STRING,ID_COMMAND_HELPINDEX, helpContents);
  1399.  
  1400.     for (idx=1; bOK==PREF_NOERROR; idx++) {
  1401.         bOK = PREF_CopyIndexConfigString("menu.help.item",idx,"label",&label);
  1402.         
  1403.         // if the label is blank, truncate the menu here.
  1404.         if (!label || !label[0])
  1405.             bOK = PREF_ERROR;
  1406.  
  1407.         if (bOK == PREF_NOERROR) {
  1408.             if (idx < iItems) {
  1409.                 if (!strcmpi("SEPARATOR",label) || !strcmpi("-",label))
  1410.                     pMenu->ModifyMenu(idx,MF_BYPOSITION | MF_SEPARATOR,NULL,"");
  1411.                 else
  1412.                     pMenu->ModifyMenu(CASTUINT(idx),CASTUINT(MF_BYPOSITION | MF_STRING),CASTUINT(FIRST_HELP_MENU_ID + idx),label);
  1413.             } else {
  1414.                 if (!strcmpi("SEPARATOR",label) || !strcmpi("-",label))
  1415.                     pMenu->InsertMenu(idx,MF_BYPOSITION | MF_SEPARATOR,NULL,"");
  1416.                 else
  1417.                     pMenu->InsertMenu(CASTUINT(idx),CASTUINT(MF_BYPOSITION | MF_STRING),CASTUINT(FIRST_HELP_MENU_ID + idx),label);
  1418.             }
  1419.         }
  1420.         if (label) {
  1421.             XP_FREE(label);
  1422.             label = NULL;
  1423.         }
  1424.     }
  1425.  
  1426.     //  Add about page item
  1427.     //  Must be done here, such that choice is always
  1428.     //      available.
  1429.     CString aboutCommunicator;
  1430.     aboutCommunicator.LoadString(IDS_ABOUTNETSCAPE);
  1431.  
  1432.     if (idx < iItems) 
  1433.         pMenu->ModifyMenu(idx,MF_BYPOSITION | MF_STRING,ID_COMMAND_ABOUT, aboutCommunicator);
  1434.     else
  1435.         pMenu->InsertMenu(idx,MF_BYPOSITION | MF_STRING,ID_COMMAND_ABOUT, aboutCommunicator);
  1436. }
  1437.  
  1438. /****************************************************************************
  1439. *
  1440. *    CGenericFrame::OnToolsWeb
  1441. *
  1442. *    PARAMETERS:
  1443. *        None
  1444. *
  1445. *    RETURNS:
  1446. *        void
  1447. *
  1448. *    DESCRIPTION:
  1449. *        Handles the Tools->Web menu item, and can be called by anyone else
  1450. *        (such as the task bar) that wants to perform the trick of getting the
  1451. *        proper browser window up.
  1452. *
  1453. ****************************************************************************/
  1454.  
  1455. void CGenericFrame::OnToolsWeb()
  1456. {
  1457.     // TODO - not exactly to spec yet...
  1458.     
  1459.     // Single click on web icon means bring forth the browser window
  1460.     CAbstractCX * pCX = GetMainContext();
  1461.     if (pCX != NULL)
  1462.     {
  1463.         int nCount = FEU_GetNumActiveFrames(MWContextBrowser);
  1464.         
  1465.         if((nCount == 1 && pCX->GetContext()->type == MWContextBrowser && !EDT_IS_EDITOR(pCX->GetContext())) || nCount == 0)
  1466.             pCX->NewWindow();
  1467.         else if(nCount > 1 || !(pCX->GetContext()->type == MWContextBrowser && !EDT_IS_EDITOR(pCX->GetContext())))
  1468.         {
  1469.             CFrameWnd *pFrame;
  1470.  
  1471.             //if we are a browser then get the bottom most browser
  1472.             if(pCX->GetContext()->type == MWContextBrowser)
  1473.             {
  1474.                 pFrame = FEU_GetBottomFrame(MWContextBrowser);
  1475.             }
  1476.             else
  1477.             // if we are not a browser, then get the last active browser
  1478.                 pFrame = FEU_GetLastActiveFrame(MWContextBrowser);
  1479.  
  1480.             if(pFrame)
  1481.             {
  1482.                 if(pFrame->IsIconic())
  1483.                     pFrame->ShowWindow(SW_RESTORE);
  1484.  
  1485. #ifdef _WIN32
  1486.                 pFrame->SetForegroundWindow();
  1487. #else
  1488.                 pFrame->SetActiveWindow();
  1489. #endif
  1490.             }
  1491.         }
  1492.     }
  1493.             
  1494. } // END OF    FUNCTION CGenericFrame::OnToolsWeb()
  1495.  
  1496. //
  1497. // Build the "Window" menu 
  1498. //
  1499. void CGenericFrame::OnConstructWindowMenu(CMenu * pPopup)
  1500. {
  1501.     UINT nFlags = MF_STRING | MF_ENABLED; 
  1502.  
  1503.     ASSERT(pPopup);
  1504.     if(!pPopup)
  1505.         return;
  1506.  
  1507.     if(theApp.m_hPostalLib)
  1508.         FEU_AltMail_SetAltMailMenus(pPopup); 
  1509.  
  1510.     // delete the old menu items
  1511.     int index = 0;
  1512.     UINT nID = 0;
  1513.     int iCount = pPopup->GetMenuItemCount();
  1514.  
  1515.     while ( index < iCount && nID != ID_WINDOW_WINDOW_0 ) {
  1516.         nID = pPopup->GetMenuItemID(index);
  1517.         if (nID != ID_WINDOW_WINDOW_0)
  1518.             index++;
  1519.     }
  1520.  
  1521.     while ( iCount > index ) {
  1522.         pPopup->RemoveMenu(index, MF_BYPOSITION);
  1523.         iCount--;
  1524.     }
  1525.     
  1526.     // list windows here
  1527.  
  1528.     CGenericFrame * pFrame = NULL;
  1529.     int nItemCount = 0;
  1530.  
  1531.     // We can't have more than 10 window menu items because we only reserved 10 IDs. Sigh.
  1532.     for(pFrame = theApp.m_pFrameList; pFrame && nItemCount < 10; pFrame = pFrame->m_pNext) {
  1533.         CAbstractCX * pContext = pFrame->GetMainContext();
  1534.  
  1535.         // all better be enabled
  1536.         nFlags = MF_STRING | MF_ENABLED;
  1537.         if(!pContext)
  1538.             continue;
  1539.  
  1540.         MWContext * pXPContext = pContext->GetContext();
  1541.         if(!pXPContext)
  1542.             continue;
  1543.  
  1544.         if(pFrame == this)
  1545.             nFlags |= MF_CHECKED;
  1546.  
  1547.           CString csContext = "";
  1548.         CString csTitle;
  1549.  
  1550.         csContext.Format(_T("&%d "), nItemCount);
  1551.         csTitle.LoadString(IDS_TITLE_NOTITLE);
  1552.  
  1553.         switch (pXPContext->type) {
  1554.         case MWContextBrowser:
  1555.             if( EDT_IS_EDITOR(pXPContext) ){
  1556.                 csContext += szLoadString(IDS_TITLE_COMPOSE_PAGE);
  1557.             } else {
  1558.                 csContext += szLoadString(IDS_TITLE_WEB);
  1559.             }
  1560.             break;
  1561. #ifdef MOZ_MAIL_NEWS         
  1562.         case MWContextMessageComposition:
  1563.             csContext += szLoadString(IDS_TITLE_COMPOSE_MESSAGE);
  1564.             csTitle.LoadString(IDS_TITLE_NOSUBJECT);
  1565.             break;
  1566.         case MWContextMail:
  1567.         case MWContextMailMsg:
  1568.             if ( pFrame->IsKindOf( RUNTIME_CLASS( CMailNewsFrame ) ) ) {
  1569.                 csContext += ((CMailNewsFrame *) pFrame)->GetWindowMenuTitle();
  1570.             }
  1571.             break;
  1572.         case MWContextAddressBook:
  1573.             csContext += szLoadString( IDS_TITLE_ADDRESSBOOK );
  1574.             break;
  1575. #endif /* MOZ_MAIL_NEWS */        
  1576.         case MWContextBookmarks:
  1577.             csContext += szLoadString( IDS_TITLE_BOOKMARKS );
  1578.             break;
  1579.         default:
  1580.             continue;
  1581.         }
  1582.  
  1583.         switch (pXPContext->type) {
  1584.         case MWContextMessageComposition:
  1585.         case MWContextBrowser:
  1586.             if(pXPContext->title) {
  1587.                 csContext += fe_MiddleCutString(pXPContext->title, 40);
  1588.             } else {
  1589.                 csContext += csTitle;
  1590.             }
  1591.             break;
  1592.         }
  1593.  
  1594.         if(pFrame == this)
  1595.             nFlags |= MF_CHECKED;
  1596.         pPopup->AppendMenu( nFlags, CASTUINT(ID_WINDOW_WINDOW_0 + nItemCount), csContext);
  1597.  
  1598.         // we added an item
  1599.         nItemCount++;
  1600.     }
  1601.  
  1602.     // keep windows happy
  1603.     DrawMenuBar();
  1604. }
  1605.  
  1606. // this deletes all of the UINT * nIDs stored in the menu map.
  1607. void CGenericFrame::DeleteMenuMapIDs(void)
  1608. {
  1609.     if(!m_pMenuMap)
  1610.         return;
  1611.  
  1612.     POSITION pos = m_pMenuMap->GetStartPosition();
  1613.     HMENU hMenu;
  1614.     UINT * pID;
  1615.  
  1616.     while(pos != NULL)
  1617.     {
  1618.         pID = NULL;
  1619. #ifdef _WIN32
  1620.         m_pMenuMap->GetNextAssoc( pos, (void*&)hMenu, (void*&)pID );
  1621. #else
  1622.         m_pMenuMap->GetNextAssoc( pos, (WORD&)hMenu, (void*&)pID );
  1623. #endif
  1624.         if(pID)
  1625.         {
  1626.             delete pID;
  1627.         }
  1628.  
  1629.     }
  1630.  
  1631.  
  1632. }
  1633.  
  1634. // This copies src into dest.
  1635. static void CopyMenu(CMenu *srcMenu, CMenu *destMenu)
  1636. {
  1637.     if (!srcMenu)
  1638.         return;
  1639.  
  1640.     int nCount = srcMenu->GetMenuItemCount();
  1641.     for(int dstPos = 0, srcPos = 0; dstPos< nCount; dstPos++, srcPos++)
  1642.     {
  1643.         UINT nID = srcMenu->GetMenuItemID(srcPos);
  1644.         
  1645.         // it's a separator
  1646.         if(nID == 0)
  1647.         {
  1648.             destMenu->InsertMenu(dstPos, MF_BYPOSITION | MF_SEPARATOR);
  1649.         }
  1650.         else
  1651.         {
  1652.             char lpszMenuString[64];
  1653.             
  1654.             srcMenu->GetMenuString(srcPos, lpszMenuString, 63, MF_BYPOSITION);
  1655.             CString menuString(lpszMenuString);
  1656.  
  1657.             // it's a submenu
  1658.             if(nID == (UINT) -1)
  1659.             {
  1660.                 CMenu *pSubMenu = srcMenu->GetSubMenu(srcPos);
  1661.                 CMenu *pNewSubMenu=new CMenu;
  1662.         
  1663.                 if(pNewSubMenu)
  1664.                 {
  1665.                     pNewSubMenu->CreatePopupMenu();
  1666.                     
  1667.                     CopyMenu(pSubMenu, pNewSubMenu);
  1668.                     destMenu->InsertMenu(dstPos, MF_STRING | MF_BYPOSITION | MF_POPUP, (UINT)pNewSubMenu->m_hMenu, menuString);
  1669.                     // detach and delete the submenu created above.
  1670.                     pNewSubMenu->Detach();
  1671.                     delete pNewSubMenu;
  1672.                 }
  1673.  
  1674.             }
  1675.             // it's a regular menu item.
  1676.             else if(nID > 0)
  1677.             {
  1678.                 destMenu->InsertMenu(dstPos, MF_BYPOSITION | MF_STRING, nID, menuString);
  1679.             }
  1680.         }
  1681.     }
  1682.  
  1683. }
  1684.  
  1685. //  This loads a menu from the menubar dynamically
  1686. void CGenericFrame::LoadFrameMenu(CMenu *pPopup, UINT nIndex)
  1687. {
  1688.     
  1689.     CMenu *pMenu = GetMenu();
  1690.  
  1691.     if(pMenu)
  1692.     {
  1693.         CMenu *pSubMenu = pMenu->GetSubMenu(nIndex);
  1694.         // verify that this menu is on the main menubar.
  1695.         if(pSubMenu && (pSubMenu == pPopup))
  1696.         {
  1697.             UINT * pID;
  1698.             // find the resource id associated with the menu
  1699. #ifdef _WIN32
  1700.             if(m_pMenuMap && m_pMenuMap->Lookup(pPopup->m_hMenu, (void*&)pID))
  1701. #else
  1702.             if(m_pMenuMap && m_pMenuMap->Lookup((WORD)pPopup->m_hMenu, (void*&)pID))
  1703. #endif
  1704.             {
  1705.                 // clear everything out
  1706.                 int nCount = pPopup->GetMenuItemCount();
  1707.                 for(int i = nCount - 1; i >= 0; i--)
  1708.                 {
  1709.                     pPopup->DeleteMenu(i, MF_BYPOSITION);
  1710.                 }
  1711.  
  1712.                 CMenu *pSrcPopup = new CMenu();
  1713.                 if(pSrcPopup && pID)
  1714.                 {
  1715.                     // load the menu and copy it into pPopup.
  1716.                     if(pSrcPopup->LoadMenu(*pID));    
  1717.                         CopyMenu(pSrcPopup, pPopup);
  1718.                     delete pSrcPopup;
  1719.                 }
  1720.             }
  1721.         }
  1722.     }
  1723.  
  1724. }
  1725.  
  1726. // Delete the menu items in the menus in m_pMenuMap
  1727. void CGenericFrame::DeleteMenuMapMenus(void)
  1728. {
  1729.     if(!m_pMenuMap)
  1730.         return;
  1731.  
  1732.     POSITION pos = m_pMenuMap->GetStartPosition();
  1733.     HMENU hMenu;
  1734.     UINT * pID;
  1735.  
  1736.     while(pos != NULL)
  1737.     {
  1738.         hMenu = NULL;
  1739. #ifdef _WIN32
  1740.         m_pMenuMap->GetNextAssoc( pos, (void*&)hMenu, (void*&)pID );
  1741. #else
  1742.         m_pMenuMap->GetNextAssoc( pos, (WORD&)hMenu, (void*&)pID );
  1743. #endif
  1744.         if(hMenu)
  1745.         {
  1746.             DeleteFrameMenu(hMenu);
  1747.         }
  1748.  
  1749.     }
  1750.  
  1751.  
  1752. }
  1753.  
  1754. void CGenericFrame::DeleteFrameMenu(HMENU hMenu)
  1755. {
  1756.     if(hMenu)
  1757.     {
  1758.         int nCount = ::GetMenuItemCount(hMenu);
  1759.  
  1760.         // It's easiest to do this by walking backwards over the menu items
  1761.         for (int i = nCount - 1; i >= 0; i--) {
  1762.             VERIFY(::DeleteMenu(hMenu, i, MF_BYPOSITION));
  1763.         }
  1764.     }
  1765.  
  1766. }
  1767.  
  1768.  
  1769.  
  1770. void CGenericFrame::OnInitMenuPopup(CMenu * pPopup, UINT nIndex, BOOL bSysMenu) 
  1771. {
  1772.     AfxLockTempMaps();
  1773.     // load this menu if it needs to be loaded dynamically.
  1774.     LoadFrameMenu(pPopup, nIndex);
  1775.     CFrameWnd::OnInitMenuPopup(pPopup, nIndex, bSysMenu);
  1776.     if (!bSysMenu)
  1777.     {
  1778.         if( m_pBookmarksMenu && pPopup->m_hMenu == m_pBookmarksMenu->m_hMenu)
  1779.         {
  1780.             m_BookmarksGarbageList = new CTreeItemList;
  1781.  
  1782.             // We need to check whether we have already built the menu.
  1783.             // Even though we destroy the menu items each time the menus go away,
  1784.             // this only happens when the user is all done with the menu bar and
  1785.             // not when each individual pop-up menu is dismissed
  1786.             //
  1787.             // Note: we use a different check to tell whether the menu has been
  1788.             // built. We do this because the bookmark menu can have pull-right
  1789.             // sub-menus and separators, neither of which have command IDs. That
  1790.             // means the check we use for history elements won't work
  1791.             if (m_nBookmarkItems == 0) {
  1792.                 // Before we add the menu items, get the number of existing
  1793.                 // menu items. We need to know this so we can remove the items
  1794.                 // we have added
  1795.                 nExistingBookmarkMenuItems = pPopup->GetMenuItemCount();
  1796.         
  1797.                 // Now go ahead and add the bookmark items
  1798.                 BuildBookmarkMenu((CTreeMenu*)pPopup,
  1799.                               HT_TopNode(HT_GetSelectedView(m_BookmarkMenuPane)),
  1800.                               ITEMS_BEFORE_BOOKMARKS_START);
  1801.  
  1802.                 // if there were any bookmarks, add a separator after them
  1803.                 int nCount = pPopup->GetMenuItemCount();
  1804.                 if(nCount > nExistingBookmarkMenuItems && ITEMS_AFTER_BOOKMARKS_END > 0)
  1805.                     pPopup->InsertMenu(nCount - ITEMS_AFTER_BOOKMARKS_END, MF_SEPARATOR | MF_BYPOSITION);
  1806.             }
  1807.  
  1808.             ((CTreeMenu*)pPopup)->CalculateItemDimensions();        
  1809.         }  
  1810.         else if (pPopup->GetMenuItemID(0) == IDC_FIRST_PLACES_MENU_ID) 
  1811.         {
  1812.             BuildDirectoryMenu(pPopup);
  1813.         }  
  1814.         else if (pPopup->GetMenuItemID(0) == IDC_FIRST_HELP_MENU_ID) 
  1815.         {
  1816.             BuildHelpMenu(pPopup);
  1817.         } 
  1818.         else 
  1819.         {
  1820.             HT_Resource      pEntry;
  1821.  
  1822.             // See if this is a bookmark sub-menu
  1823.             ASSERT(m_pSubmenuMap);
  1824.             if (m_pSubmenuMap->Lookup(pPopup->GetSafeHmenu(), (void*&)pEntry)) 
  1825.             {
  1826.                 // If the menu isn't empty then we've already added the bookmark
  1827.                 // items
  1828.                 if (pPopup->GetMenuItemCount() == 0) 
  1829.                 {
  1830.                     // Haven't yet added the bookmark menu items for this sub-menu.
  1831.                     // Do it now
  1832.                     BuildBookmarkMenu((CTreeMenu*)pPopup, pEntry);
  1833.                     ((CTreeMenu*)pPopup)->CalculateItemDimensions();
  1834.                 }
  1835.             }
  1836.  
  1837.             //see if this is a file bookmark sub-menu
  1838.             if(pPopup == m_pFileBookmarkMenu)
  1839.                 InitFileBookmarkMenu();
  1840.  
  1841.             if (m_pFileSubmenuMap->Lookup(pPopup->GetSafeHmenu(), (void*&)pEntry)) 
  1842.             {
  1843.  
  1844.                 if(pPopup->GetMenuItemCount()==0)
  1845.                 {
  1846.                     BuildFileBookmarkMenu((CTreeMenu*)pPopup, pEntry);
  1847.                     ((CTreeMenu*)pPopup)->CalculateItemDimensions();
  1848.                 }
  1849.  
  1850.             }
  1851.             CMenu * pFrameMenu = GetMenu();
  1852.             if (pFrameMenu != NULL)
  1853.             {
  1854.                 if ((pPopup != NULL) &&
  1855.                     (pPopup->GetMenuItemID(0) == ID_TOOLS_WEB))
  1856.                 {
  1857.                     OnConstructWindowMenu(pPopup);
  1858.                 }
  1859.                 if ((pPopup != NULL) &&
  1860.                     (pPopup->GetMenuItemID(0) == IDC_FIRST_HELP_MENU_ID))
  1861.                 {
  1862.                     BuildHelpMenu(pPopup);
  1863.                 }
  1864.             }
  1865.         }
  1866.     }
  1867.     // This function must always be executed, so please, do NOT put any
  1868.     // return statements in the above code!
  1869.     AfxUnlockTempMaps();
  1870. }
  1871.  
  1872. //
  1873. // Over-ride this cuz something is writing the status message into
  1874. //   pane 0 instead of actually looking up what the correct pane to write into
  1875. //   was.
  1876. //
  1877. LRESULT CGenericFrame::OnSetMessageString(WPARAM wParam, LPARAM lParam)
  1878. {
  1879.     CString csStatus = _T("");
  1880.  
  1881.     // set the message bar text
  1882.     if (lParam != NULL)
  1883.     {
  1884.         ASSERT(wParam == 0);    // can't have both an ID and a string
  1885.         // set an explicit string
  1886.         csStatus = (LPCSTR)lParam;
  1887.     } else {
  1888.         GetMessageString( (UINT) wParam, csStatus );
  1889.     }
  1890.  
  1891.     if( csStatus.IsEmpty() ) {
  1892.         CAbstractCX *pContext = GetMainContext();
  1893.  
  1894.         if( pContext ) {
  1895.             wfe_Progress( pContext->GetContext(), NULL );
  1896.         }
  1897.     }
  1898.     else {
  1899.         CStatusBar* pMessageBar = (CStatusBar *) GetMessageBar();
  1900.         if ( pMessageBar ) {
  1901.             int nIndex = pMessageBar->CommandToIndex( ID_SEPARATOR );
  1902.             if ( nIndex >= 0 ) {
  1903.                 pMessageBar->SetPaneText( nIndex, csStatus );
  1904.             }
  1905.         }
  1906.     }
  1907.     UINT nIDLast = m_nIDLastMessage;
  1908.     m_nIDLastMessage = (UINT)wParam;    // new ID (or 0)
  1909.     m_nIDTracking = (UINT)wParam;       // so F1 on toolbar buttons work
  1910.     return nIDLast;
  1911. }
  1912.  
  1913. void CGenericFrame::OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu)
  1914. {
  1915.     if ( nFlags == 0xffff ) {
  1916.         
  1917.          DeleteMenuMapMenus();
  1918.  
  1919.         HMENU hMenu = ::GetMenu(m_hWnd);
  1920.  
  1921.         // Not all top-level windows have a menu bar (e.g. the chromeless ones)
  1922.         // Also, Editor frame doesn't have these submenus
  1923.         if (hMenu && m_pBookmarksMenu ) {
  1924.             int nCount;
  1925.             // Menu is going away so destroy all the menu items we added (both
  1926.             // bookmark and history). Cleanup the bookmark menu first.
  1927.             HMENU hBookmarkMenu=m_pBookmarksMenu->m_hMenu;
  1928.             ASSERT(hBookmarkMenu);
  1929.  
  1930.             if ((nCount = ::GetMenuItemCount(hBookmarkMenu)) > 
  1931.                  ITEMS_BEFORE_BOOKMARKS_START + ITEMS_AFTER_BOOKMARKS_END) {
  1932.     
  1933.                 //FileBookMark is always the first popup menu in the Bookmark menu loop through to find it.
  1934.                 UINT nfileBookmarksPosition = 0; 
  1935.                 while(!m_pBookmarksMenu->GetSubMenu(nfileBookmarksPosition) && nfileBookmarksPosition < m_pBookmarksMenu->GetMenuItemCount())
  1936.                     nfileBookmarksPosition++;
  1937.                 CTreeMenu *pFileBookmarkMenu = (CTreeMenu*)m_pBookmarksMenu->GetSubMenu(nfileBookmarksPosition);
  1938.  
  1939.                 // Because the bookmark menu has separators and pull-right sub-menus,
  1940.                 // neither of which have command IDs, we can't tell just by looking
  1941.                 // at the menu items whether they should be deleted. So instead we
  1942.                 // delete everything
  1943.                 for (int i = nCount - 1 - ITEMS_AFTER_BOOKMARKS_END;
  1944.                      i >= ITEMS_BEFORE_BOOKMARKS_START; i--) {
  1945.                     // This will delete any sub-menus as well (recursively)
  1946.                     if(m_pBookmarksMenu->GetSubMenu(i) != NULL)
  1947.                         m_pBookmarksMenu->GetSubMenu(i)->DestroyMenu();
  1948.                     VERIFY(::DeleteMenu(hBookmarkMenu, i, MF_BYPOSITION));
  1949.                 }
  1950.                 //don't care about separator before bookmarks
  1951.                 m_pBookmarksMenu->ClearItems(ITEMS_BEFORE_BOOKMARKS_START - SEPARATORS_BEFORE_BOOKMARKS_START, 
  1952.                                              ITEMS_AFTER_BOOKMARKS_END);
  1953.  
  1954.                 // we also need to delete items added to file bookmarks
  1955.     
  1956.                 nCount = pFileBookmarkMenu->GetMenuItemCount();
  1957.  
  1958.                 for(i = nCount - 1; i >= 0 ; i--)
  1959.                 {
  1960.                     // This will delete any sub-menus as well (recursively)
  1961.                     if(pFileBookmarkMenu->GetSubMenu(i) != NULL)
  1962.                         pFileBookmarkMenu->GetSubMenu(i)->DestroyMenu();
  1963.                     VERIFY(pFileBookmarkMenu->DeleteMenu(i, MF_BYPOSITION));
  1964.                 }
  1965.  
  1966.                 pFileBookmarkMenu->ClearItems(0, 0);
  1967.  
  1968.                 delete m_BookmarksGarbageList;
  1969.                 m_nBookmarkItems = 0;  // reset the number of current bookmark menu items
  1970.                 m_nFileBookmarkItems = 0;
  1971.             }
  1972.  
  1973.             // The maps are no longer needed
  1974.             if (m_pHotlistMenuMap)
  1975.                 m_pHotlistMenuMap->RemoveAll();
  1976.  
  1977.             if (m_pSubmenuMap)
  1978.                 m_pSubmenuMap->RemoveAll();
  1979.  
  1980.             if (m_pFileSubmenuMap)
  1981.             {
  1982.                 m_pFileSubmenuMap->RemoveAll();
  1983.                 // but we need to make sure that the file menu is still in the map.
  1984.                 //FileBookMark is always the first popup menu in the Bookmark menu loop through to find it.
  1985.                 UINT nfileBookmarksPosition = 0; 
  1986.                 while(!m_pBookmarksMenu->GetSubMenu(nfileBookmarksPosition) && nfileBookmarksPosition < m_pBookmarksMenu->GetMenuItemCount())
  1987.                     nfileBookmarksPosition++;
  1988.                 CTreeMenu *pFileBookmarkMenu = (CTreeMenu*)m_pBookmarksMenu->GetSubMenu(nfileBookmarksPosition);
  1989.  
  1990.                 if(pFileBookmarkMenu != NULL)
  1991.                 {
  1992.                     m_pFileSubmenuMap->SetAt(pFileBookmarkMenu->GetSafeHmenu(), 
  1993.                         HT_TopNode(HT_GetSelectedView(m_BookmarkMenuPane)));
  1994.                 }
  1995.             }
  1996.  
  1997.         }
  1998.     } else if (!(nItemID == 0 || nFlags & (MF_SEPARATOR|MF_POPUP|MF_MENUBREAK|MF_MENUBARBREAK))) {
  1999.         // If the menu item is for a bookmark item or history entry, save
  2000.         // away the client data for later. We need to do this because Windows
  2001.         // sends the WM_COMMAND for a selected menu item after sending the
  2002.         // WM_MENUSELECT to indicate the menu has been taken down. Alternatively
  2003.         // we could wait to purge the map until later, but Win32 allows client
  2004.         // data to be associated with a menu item and there would be no map in that
  2005.         // case anyway
  2006.         if (IS_BOOKMARK_ID(nItemID) || IS_HISTORY_ID(nItemID)) {
  2007.             ASSERT(m_pHotlistMenuMap);
  2008.  
  2009.             if (m_pHotlistMenuMap->Lookup(nItemID, nLastSelectedData))
  2010.                 nLastSelectedCmdID = nItemID;
  2011.         }
  2012.  
  2013.         if (IS_FILE_BOOKMARK_ID(nItemID)) {
  2014.             if(m_pHotlistMenuMap->Lookup(nItemID, nLastSelectedData))
  2015.                 nLastSelectedCmdID = nItemID;
  2016.         }
  2017.     } 
  2018.  
  2019. #ifdef EDITOR
  2020.     // Do Composer stuff
  2021.     OnMenuSelectComposer(nItemID, nFlags, hSysMenu);
  2022. #endif // EDITOR
  2023.  
  2024.     CFrameWnd::OnMenuSelect(nItemID, nFlags, hSysMenu);
  2025. }
  2026.  
  2027.  
  2028. // Because CTreeMenu's are owner draw, they don't handle mnemonics.  Therefore
  2029. // we have to handle them ourselves.
  2030. LRESULT CGenericFrame::OnMenuChar( UINT nChar, UINT nFlags, CMenu* pMenu )
  2031. {
  2032.  
  2033.     LRESULT result = 0;
  2034.  
  2035.  
  2036.     if(pMenu == m_pBookmarksMenu)
  2037.     {
  2038.         int nPosition;
  2039.         UINT nCommand;
  2040.  
  2041.         if(m_pBookmarksMenu->GetMnemonic(nChar, nCommand, nPosition))
  2042.         {
  2043.             if(nCommand == 0)
  2044.                 return MAKELRESULT(nPosition, 2);
  2045.             else
  2046.             {
  2047.                 SendMessage(WM_COMMAND, nCommand);
  2048.                 return MAKELRESULT(0, 1);
  2049.             }
  2050.  
  2051.         }
  2052.     }
  2053.     return CFrameWnd::OnMenuChar(nChar, nFlags, pMenu);
  2054. }
  2055.  
  2056. // Find a popup menu matching the given ID,
  2057. //   including searching into submenus
  2058. // This is necessary in order to act upon MeasureItem
  2059. //  messages in the OnMeasureItem function.  
  2060. // Userdata will always be of type CTreeItem *
  2061. static CMenu* FindPopupMenu(CMenu* pMenu, UINT nID, DWORD userData)
  2062. {
  2063.     if( pMenu )
  2064.     {
  2065.         int iCount= pMenu->GetMenuItemCount();
  2066.  
  2067.         for( int i = 0; i < iCount; i++ )
  2068.         {
  2069.             CMenu* pPopup = pMenu->GetSubMenu(i);
  2070.             //if it's a submenu then see if it is or if it contains the submenu we want 
  2071.             if( pPopup )
  2072.             {
  2073.                 //if the submenu and the menu we are looking for are the same then return this
  2074.                 if( (UINT)pPopup->m_hMenu == ((CTreeItem*)userData)->GetID() )
  2075.                 {
  2076.                     return pMenu;
  2077.                 }
  2078.                 // otherwise recurse to child popup
  2079.                 pPopup = FindPopupMenu( pPopup, nID, userData );
  2080.  
  2081.                 // check popups on this popup
  2082.                 if( pPopup )
  2083.                     return pPopup;
  2084.             }
  2085.             // otherwise check to see if it is the menu item that we want
  2086.             else if( nID == pMenu->GetMenuItemID(i) )
  2087.             {
  2088.                 return pMenu;
  2089.             }
  2090.         }
  2091.     }
  2092.     return NULL;
  2093. }
  2094.  
  2095. /****************************************************************************
  2096. *
  2097. *    CGenericFrame::OnMeasureItem
  2098. *
  2099. *    PARAMETERS:
  2100. *        nIDCtl    - control ID
  2101. *        lpMI    - pointer to MEASUREITEMSTRUCT
  2102. *
  2103. *    RETURNS:
  2104. *        void
  2105. *
  2106. *    DESCRIPTION:
  2107. *        We must override this handler because MFC has a bug that prevents
  2108. *        the CMenu::MeasureItem() from being called for owner draw sub-menus.
  2109. *
  2110. ****************************************************************************/
  2111.  
  2112. void CGenericFrame::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMI) 
  2113. {
  2114.     if (lpMI->CtlType == ODT_MENU)
  2115.     {
  2116.         ASSERT(lpMI->CtlID == 0);
  2117.         CMenu * pMenu = NULL;
  2118.         
  2119. #if defined(WIN32)
  2120.         _AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
  2121.         if (pThreadState->m_hTrackingWindow == m_hWnd)
  2122.         {
  2123.             // start from popup
  2124.             pMenu = CMenu::FromHandle(pThreadState->m_hTrackingMenu);
  2125.         }
  2126.         else
  2127.         {
  2128.             // start from menubar
  2129.             pMenu = GetMenu();
  2130.         }
  2131. #else    // WIN16
  2132.         // start from menubar
  2133.         pMenu = GetMenu();
  2134. #endif    // WIN32
  2135.             
  2136.         ASSERT(pMenu != NULL);
  2137.         pMenu = FindPopupMenu(pMenu, lpMI->itemID, lpMI->itemData);
  2138.         if (pMenu != NULL)
  2139.         {
  2140.             pMenu->MeasureItem(lpMI);
  2141.         }
  2142.     }
  2143.     else
  2144.     {
  2145.         // Pass off to base class if not a menu
  2146.         CFrameWnd::OnMeasureItem(nIDCtl, lpMI);
  2147.     }
  2148.  
  2149. } // END OF    FUNCTION CGenericFrame::OnMeasureItem()
  2150.  
  2151. //  Scroll to the top of the document
  2152. //
  2153. void CGenericFrame::OnDocumentTop()  
  2154. {
  2155.        MWContext *pContext = GetActiveWinContext() != NULL ? GetActiveWinContext()->GetContext() : NULL;
  2156.     if (pContext)
  2157. #ifdef EDITOR
  2158.         if (EDT_IS_EDITOR(pContext))
  2159.             EDT_BeginOfDocument(pContext, FALSE);
  2160.         else
  2161. #endif // EDITOR
  2162.             FE_SetDocPosition(GetActiveWinContext()->GetContext(), FE_VIEW, 0, 0);
  2163. }
  2164.  
  2165. //  Scroll to the bottom of the document
  2166. //
  2167. void CGenericFrame::OnDocumentBottom() 
  2168. {
  2169.        MWContext *pContext = GetActiveWinContext() != NULL ? GetActiveWinContext()->GetContext() : NULL;
  2170.     if (pContext)
  2171. #ifdef EDITOR
  2172.         if (EDT_IS_EDITOR(pContext))
  2173.             EDT_EndOfDocument(pContext, FALSE);
  2174.         else
  2175. #endif // EDITOR
  2176.             FE_SetDocPosition(pContext, FE_VIEW, 0, GetActiveWinContext()->GetDocumentHeight());
  2177. }
  2178.  
  2179. void CGenericFrame::OnAbout()
  2180. {
  2181.     CAbstractCX * pContext = GetMainContext();
  2182.     if(pContext)    {
  2183.         if (pContext->GetContext()->type != MWContextBrowser ||
  2184.             EDT_IS_EDITOR(pContext->GetContext()))
  2185.             pContext->NormalGetUrl(szLoadString(IDS_ABOUT_PAGE),NULL,NULL,TRUE);
  2186.         else
  2187.             pContext->NormalGetUrl(szLoadString(IDS_ABOUT_PAGE));
  2188.     }
  2189. }
  2190.  
  2191. ///////////////////////////////////////////////////////////////////////////////
  2192.  
  2193. void CGenericFrame::OnShowBookmarkWindow()
  2194. {   
  2195.     theApp.CreateNewNavCenter(NULL, TRUE, HT_VIEW_BOOKMARK);
  2196. }
  2197.  
  2198. ///////////////////////////////////////////////////////////////////////////////
  2199. #ifdef JAVA
  2200. void CGenericFrame::OnToggleJavaConsole()
  2201. {
  2202.     if( LJ_IsConsoleShowing() ) {
  2203.     LJ_HideConsole();
  2204.     } else {
  2205.     LJ_ShowConsole();
  2206.     }
  2207. }
  2208.  
  2209. void CGenericFrame::OnUpdateJavaConsole(CCmdUI* pCmdUI)
  2210. {   
  2211.     if (LJJavaStatus_Failed != LJ_GetJavaStatus()) {
  2212.         pCmdUI->SetCheck( LJ_IsConsoleShowing() );
  2213.     } else {
  2214.         pCmdUI->Enable(FALSE);
  2215.     }
  2216. }
  2217. #endif  /* JAVA */
  2218.  
  2219. void CGenericFrame::OnTaskbar()
  2220. {
  2221. #ifdef MOZ_TASKBAR
  2222.     if(theApp.GetTaskBarMgr().IsFloating())
  2223.         theApp.GetTaskBarMgr().OnDockTaskBar();
  2224.     else
  2225.         theApp.GetTaskBarMgr().OnUnDockTaskBar();
  2226. #endif  /* MOZ_TASKBAR */
  2227. }
  2228.  
  2229. void CGenericFrame::OnUpdateTaskbar(CCmdUI *pCmdUI)
  2230. {
  2231. #ifdef MOZ_TASKBAR
  2232.     BOOL bUndocked = theApp.GetTaskBarMgr().IsFloating();
  2233.     if( pCmdUI->m_pMenu ){
  2234.         pCmdUI->m_pMenu->ModifyMenu(CASTUINT(ID_WINDOW_TASKBAR), CASTUINT(MF_BYCOMMAND | MF_STRING), CASTUINT(ID_WINDOW_TASKBAR),
  2235.                                     szLoadString(CASTUINT(bUndocked ? IDS_DOCK_TASKBAR : IDS_SHOW_TASKBAR)) );
  2236.     } else {
  2237.         pCmdUI->SetCheck(bUndocked);
  2238.     }
  2239. #endif /* MOZ_TASKBAR */
  2240.  
  2241.  
  2242. }
  2243.  
  2244. void CGenericFrame::OnUpdateLiveCall(CCmdUI* pCmdUI)
  2245. {   
  2246.     pCmdUI->Enable(m_bConference);
  2247. }
  2248.  
  2249. void CGenericFrame::OnIBMHostOnDemand()
  2250. {
  2251.  
  2252.     CString installDirectory, executable;
  2253.     
  2254.     if(!FEU_IsIBMHostOnDemandAvailable)
  2255.         return;
  2256.  
  2257. #ifdef WIN32
  2258.     CString ibmHostRegistry;
  2259.  
  2260.     ibmHostRegistry.LoadString(IDS_3270_REGISTRY);
  2261.  
  2262.     ibmHostRegistry = FEU_GetCurrentRegistry(ibmHostRegistry);
  2263.     if(ibmHostRegistry.IsEmpty())
  2264.         return;
  2265.  
  2266.     installDirectory = FEU_GetInstallationDirectory(ibmHostRegistry, szLoadString(IDS_INSTALL_DIRECTORY));
  2267. #else ifdef XP_WIN16
  2268.     installDirectory = FEU_GetInstallationDirectory(szLoadString(IDS_3270), szLoadString(IDS_INSTALL_DIRECTORY));
  2269. #endif
  2270.     if(!installDirectory.IsEmpty())
  2271.  
  2272.     {
  2273.         executable = installDirectory + szLoadString(IDS_3270HTML);
  2274.  
  2275.         if(((CDocTemplate *)theApp.m_ViewTmplate)->OpenDocumentFile( executable ))
  2276.         {
  2277.                 return;
  2278.         }
  2279.     }
  2280.     MessageBox(szLoadString(IDS_CANT3270), szLoadString(IDS_IBMHOSTONDEMAND), MB_OK);
  2281.  
  2282.  
  2283.  }
  2284.  
  2285.  
  2286. void CGenericFrame::OnNetcaster()
  2287. {
  2288.     FEU_OpenNetcaster() ;
  2289. }
  2290.  
  2291. void CGenericFrame::OnAim()
  2292. {
  2293.     FEU_OpenAim();
  2294. }
  2295.  
  2296. void CGenericFrame::OnCalendar()
  2297. {
  2298.  
  2299.     if(!FEU_IsCalendarAvailable())
  2300.         return;
  2301.  
  2302.     CString installDirectory, executable;
  2303.  
  2304. #ifdef WIN32
  2305.     CString calRegistry;
  2306.  
  2307.     calRegistry.LoadString(IDS_CALENDAR_REGISTRY);
  2308.  
  2309.     calRegistry = FEU_GetCurrentRegistry(calRegistry);
  2310.     if(calRegistry.IsEmpty())
  2311.         return;
  2312.  
  2313.     installDirectory = FEU_GetInstallationDirectory(calRegistry, szLoadString(IDS_INSTALL_DIRECTORY));
  2314.     executable = szLoadString(IDS_CALENDAR32EXE);
  2315. #else ifdef XP_WIN16
  2316.     installDirectory = FEU_GetInstallationDirectory(szLoadString(IDS_CALENDAR),szLoadString(IDS_INSTALL_DIRECTORY));
  2317.     executable = szLoadString(IDS_CALENDAR16EXE);
  2318. #endif
  2319.     if(!installDirectory.IsEmpty())
  2320.     {
  2321.         executable = installDirectory + executable;
  2322.  
  2323.         if(    WinExec(executable, SW_SHOW) >= 31)
  2324.             return;
  2325.     }
  2326.     MessageBox(szLoadString(IDS_CANTCALENDAR), szLoadString(IDS_CALENDAR), MB_OK);
  2327.  
  2328.  
  2329. }
  2330. void CGenericFrame::OnShowAdvanced()
  2331. {
  2332.     int32 prefInt;
  2333.     PREF_GetIntPref("browser.chrome.button_style",&prefInt);
  2334.     
  2335.     prefInt = (prefInt + 1) % 3;  // reverse it!
  2336.     PREF_SetIntPref("browser.chrome.button_style",prefInt);
  2337.     theApp.m_pToolbarStyle = CASTINT(prefInt);
  2338.  
  2339.     //theApp.m_pAdvancedToolbar = theApp.m_pAdvancedToolbar->IsYes() ? "No" : "Yes";
  2340.  
  2341.     CGenericFrame *pGenFrame;
  2342.     for(pGenFrame = theApp.m_pFrameList; pGenFrame; pGenFrame = pGenFrame->m_pNext) {
  2343.         LPNSTOOLBAR pIToolBar = NULL;
  2344.         pGenFrame->GetChrome()->QueryInterface( IID_INSToolBar, (LPVOID *) &pIToolBar );
  2345.         if (pIToolBar) {
  2346.            pIToolBar->SetToolbarStyle(theApp.m_pToolbarStyle);
  2347.            pIToolBar->Release();
  2348.            pGenFrame->RecalcLayout();
  2349.         }
  2350.     }
  2351. }
  2352.  
  2353. void CGenericFrame::OnUpdateShowAdvanced( CCmdUI *pCmdUI )
  2354. {
  2355.     pCmdUI->SetCheck(theApp.m_pToolbarStyle);
  2356.     pCmdUI->Enable(TRUE);
  2357. }
  2358.  
  2359. void CGenericFrame::OnViewCommandToolbar()
  2360. {
  2361.     GetChrome()->ShowToolbar(ID_NAVIGATION_TOOLBAR, !GetChrome()->GetToolbarVisible(ID_NAVIGATION_TOOLBAR));
  2362. }
  2363.  
  2364. void CGenericFrame::OnUpdateViewCommandToolbar(CCmdUI *pCmdUI)
  2365. {
  2366.     BOOL bShow = GetChrome()->GetToolbarVisible(ID_NAVIGATION_TOOLBAR);
  2367.     if( pCmdUI->m_pMenu ){
  2368.         pCmdUI->m_pMenu->ModifyMenu(CASTUINT(ID_VIEW_COMMANDTOOLBAR), CASTUINT(MF_BYCOMMAND | MF_STRING), CASTUINT(ID_VIEW_COMMANDTOOLBAR),
  2369.                                     szLoadString(CASTUINT(bShow ? IDS_HIDE_COMMANDTOOLBAR : IDS_SHOW_COMMANDTOOLBAR)) );
  2370.     } else {
  2371.         pCmdUI->SetCheck(bShow);
  2372.     }
  2373. }
  2374.  
  2375. void CGenericFrame::OnViewNavCenter()
  2376. {
  2377.     CNSNavFrame* pFrame = GetDockedNavCenter();
  2378.     if (pFrame)
  2379.         pFrame->DeleteNavCenter();
  2380.     else theApp.CreateNewNavCenter(this);
  2381. }
  2382.  
  2383. void CGenericFrame::OnUpdateViewNavCenter(CCmdUI *pCmdUI)
  2384. {
  2385.     CNSNavFrame* pFrame = GetDockedNavCenter();
  2386.     BOOL bShow = (pFrame != NULL);
  2387.  
  2388.     if( pCmdUI->m_pMenu )
  2389.     {
  2390.         pCmdUI->m_pMenu->ModifyMenu(CASTUINT(ID_VIEW_NAVCENTER), CASTUINT(MF_BYCOMMAND | MF_STRING), CASTUINT(ID_VIEW_NAVCENTER),
  2391.                                     szLoadString(CASTUINT(bShow ? IDS_HIDE_NAVCENTER : IDS_SHOW_NAVCENTER)) );
  2392.     } 
  2393.     else 
  2394.     {
  2395.         pCmdUI->SetCheck(bShow);
  2396.     }
  2397. }
  2398.  
  2399. void CGenericFrame::OnViewLocationToolbar()
  2400. {
  2401.     GetChrome()->ShowToolbar(ID_LOCATION_TOOLBAR, !GetChrome()->GetToolbarVisible(ID_LOCATION_TOOLBAR));
  2402. }
  2403.  
  2404. void CGenericFrame::OnUpdateViewLocationToolbar(CCmdUI *pCmdUI)
  2405. {
  2406.     BOOL bShow = GetChrome()->GetToolbarVisible(ID_LOCATION_TOOLBAR);
  2407.     if( pCmdUI->m_pMenu ){
  2408.         pCmdUI->m_pMenu->ModifyMenu(CASTUINT(ID_VIEW_LOCATIONTOOLBAR), CASTUINT(MF_BYCOMMAND | MF_STRING), CASTUINT(ID_VIEW_LOCATIONTOOLBAR),
  2409.                                     szLoadString(CASTUINT(bShow ? IDS_HIDE_LOCATIONTOOLBAR : IDS_SHOW_LOCATIONTOOLBAR)) );
  2410.     } else {
  2411.         pCmdUI->SetCheck(bShow);
  2412.     }
  2413. }
  2414.  
  2415. static void
  2416. NiceReloadAllWindows()
  2417. {
  2418.     for(CGenericFrame *f = theApp.m_pFrameList; f; f= f->m_pNext){
  2419.         CWinCX *pContext = f->GetMainWinContext();
  2420.         if(pContext && pContext->GetContext()) {
  2421. #ifdef EDITOR
  2422.             if( EDT_IS_EDITOR(pContext->GetContext())) 
  2423.                 EDT_RefreshLayout(pContext->GetContext());
  2424.             else
  2425. #endif // EDITOR
  2426.                 pContext->NiceReload();
  2427.         }
  2428.     }
  2429. }
  2430.  
  2431. void CGenericFrame::OnIncreaseFont()
  2432. {
  2433.     CWinCX *pWinCX = GetActiveWinContext();
  2434.  
  2435.     if(!pWinCX)
  2436.         pWinCX = GetMainWinContext();
  2437.  
  2438.     if(pWinCX)
  2439.         pWinCX->ChangeFontOffset(1);
  2440.  
  2441. }
  2442.  
  2443. int CGenericFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  2444. {
  2445.     if(CFrameWnd::OnCreate(lpCreateStruct) == -1)
  2446.         return(-1);
  2447.  
  2448.     ApiApiPtr(api);
  2449.     LPUNKNOWN pUnk = api->CreateClassInstance(APICLASS_CHROME, NULL);
  2450.     if (pUnk) {
  2451.         HRESULT hRes = pUnk->QueryInterface(IID_IChrome,(LPVOID*)&m_pChrome);
  2452.         ASSERT(hRes==NOERROR);
  2453.         pUnk->Release();
  2454.         m_pChrome->Initialize(this);
  2455.     }
  2456.  
  2457.     // guess we made it
  2458.  
  2459.     m_bConference = FEU_IsConfAppAvailable();
  2460.  
  2461.     CMenu *pMenu=GetMenu();
  2462.  
  2463.     #ifdef DEBUG_WHITEBOX
  2464.         pMenu->AppendMenu(MF_STRING,IDS_WHITEBOX_MENU,"&WhiteBox");
  2465.     #endif
  2466.  
  2467.     CString communicatorStr, bookmarksStr, fileBookmarkStr;
  2468.  
  2469.     //Communicator is always the second to last menu popup so adjust accordingly
  2470.     int nWindowPosition = pMenu->GetMenuItemCount() - 2;
  2471.  
  2472.     if(nWindowPosition != -1)
  2473.     {
  2474.         CMenu *pWindowMenu = pMenu->GetSubMenu(nWindowPosition);
  2475.  
  2476.         // Check if we need to add the Calendar menu item
  2477.  
  2478.         if(FEU_IsCalendarAvailable())
  2479.         {
  2480.             int nTaskBarPosition = WFE_FindMenuItem(pWindowMenu, ID_WINDOW_TASKBAR);
  2481.  
  2482.             if(nTaskBarPosition != -1)
  2483.                 pWindowMenu->InsertMenu(nTaskBarPosition - 1, MF_BYPOSITION, ID_WINDOW_CALENDAR, szLoadString(IDS_CALENDAR_MENU));
  2484.         }
  2485.  
  2486.         if(FEU_IsIBMHostOnDemandAvailable())
  2487.         {
  2488.             int nTaskBarPosition = WFE_FindMenuItem(pWindowMenu, ID_WINDOW_TASKBAR);
  2489.  
  2490.             if(nTaskBarPosition != -1)
  2491.                 pWindowMenu->InsertMenu(nTaskBarPosition - 1, MF_BYPOSITION, ID_WINDOW_IBMHOSTONDEMAND, szLoadString(IDS_IBMHOSTONDEMAND_MENU));
  2492.         }
  2493.  
  2494.          if(FEU_IsNetcasterAvailable())
  2495.          {
  2496.              int nTaskBarPosition = WFE_FindMenuItem(pWindowMenu, ID_WINDOW_TASKBAR);
  2497.  
  2498. #ifndef MOZ_TASKBAR
  2499.             if (nTaskBarPosition == -1)
  2500.                 nTaskBarPosition = 2 ;  // Right below &Navigator on Lite version
  2501. #endif
  2502.  
  2503.              if(nTaskBarPosition != -1)
  2504.                  pWindowMenu->InsertMenu(nTaskBarPosition - 1, MF_BYPOSITION, ID_WINDOW_NETCASTER, szLoadString(IDS_NETCASTER_MENU));
  2505.          }
  2506.  
  2507.         if(FEU_IsAimAvailable())
  2508.          {
  2509.              int nTaskBarPosition = WFE_FindMenuItem(pWindowMenu, ID_WINDOW_TASKBAR);
  2510.  
  2511.              if(nTaskBarPosition != -1)
  2512.                  pWindowMenu->InsertMenu(nTaskBarPosition - 1, MF_BYPOSITION, ID_WINDOW_AIM, szLoadString(IDS_AIM_MENU));
  2513.          }
  2514.  
  2515. #ifdef XP_WIN32
  2516.         // We can start or activate LiveWire SiteManager
  2517.         //  if we have a registration handle
  2518.         if( bSiteMgrIsRegistered ){
  2519.             int nTaskBarPosition = WFE_FindMenuItem(pWindowMenu, ID_WINDOW_TASKBAR);
  2520.  
  2521.             if(nTaskBarPosition != -1)
  2522.                 pWindowMenu->InsertMenu(nTaskBarPosition - 1, MF_BYPOSITION, ID_ACTIVATE_SITE_MANAGER, szLoadString(IDS_SITE_MANAGER));
  2523.         }
  2524. #endif
  2525.  
  2526.  
  2527.         // Replace the bookmark menu with a new menu that can have ON_DRAWITEM overridden
  2528.         //BookMark is the First Popup in the Communicator Menu so loop through to find it.
  2529.         UINT nBookmarksPosition = 0;
  2530.         while(!pWindowMenu->GetSubMenu(nBookmarksPosition) && nBookmarksPosition < pWindowMenu->GetMenuItemCount())
  2531.             nBookmarksPosition++;
  2532.  
  2533.         if(nBookmarksPosition < pWindowMenu->GetMenuItemCount())
  2534.         {
  2535.             CMenu *pOldBookmarksMenu = pWindowMenu->GetSubMenu(nBookmarksPosition);
  2536.             char bookmarksStr[30];
  2537.  
  2538.             if(pOldBookmarksMenu)
  2539.             {
  2540.                 m_pBookmarksMenu=new CTreeMenu;
  2541.  
  2542.                 m_pBookmarksMenu->CreatePopupMenu();
  2543.                 
  2544.                 m_OriginalBookmarksGarbageList = new CTreeItemList;
  2545.  
  2546.                 CopyMenu(pOldBookmarksMenu, m_pBookmarksMenu, m_OriginalBookmarksGarbageList);
  2547.                 pWindowMenu->GetMenuString(nBookmarksPosition, bookmarksStr, 30, MF_BYPOSITION);
  2548.                 pWindowMenu->DeleteMenu(nBookmarksPosition, MF_BYPOSITION);
  2549.                 pWindowMenu->InsertMenu(nBookmarksPosition, MF_BYPOSITION|MF_STRING|MF_POPUP, (UINT)m_pBookmarksMenu->GetSafeHmenu(), bookmarksStr);
  2550.  
  2551.                 //FileBookmark is the First Popup in the BookMarks Menu so loop through to find it.
  2552.                 UINT nfileBookmarksPosition = 0;
  2553.                 while(!m_pBookmarksMenu->GetSubMenu(nfileBookmarksPosition) && nfileBookmarksPosition < m_pBookmarksMenu->GetMenuItemCount())
  2554.                     nfileBookmarksPosition++;
  2555.                 m_pFileBookmarkMenu = (CTreeMenu*)m_pBookmarksMenu->GetSubMenu(nfileBookmarksPosition);
  2556.  
  2557.                 LoadBookmarkMenuBitmaps();
  2558.             }
  2559.         }
  2560.  
  2561.     }
  2562.  
  2563. #ifdef MOZ_TASKBAR
  2564.     // We use a taskbar
  2565.     theApp.GetTaskBarMgr().Reference(TRUE);
  2566. #endif // MOZ_TASKBAR
  2567.     return 0;
  2568. }
  2569.  
  2570.  
  2571. void CGenericFrame::OnDecreaseFont()
  2572. {
  2573.     CWinCX *pWinCX = GetActiveWinContext();
  2574.  
  2575.     if(!pWinCX)
  2576.         pWinCX = GetMainWinContext();
  2577.  
  2578.     if(pWinCX)
  2579.         pWinCX->ChangeFontOffset(-1);
  2580. }
  2581.  
  2582. void CGenericFrame::OnUpdateViewCustomToolbar(CCmdUI *pCmdUI)
  2583. {
  2584.     BOOL bShow = GetChrome()->GetToolbarVisible(ID_PERSONAL_TOOLBAR);
  2585.     if( pCmdUI->m_pMenu ){
  2586.         pCmdUI->m_pMenu->ModifyMenu(CASTUINT(ID_VIEW_CUSTOMTOOLBAR), CASTUINT(MF_BYCOMMAND | MF_STRING), CASTUINT(ID_VIEW_CUSTOMTOOLBAR),
  2587.                                     szLoadString(CASTUINT(bShow ? IDS_HIDE_CUSTOMTOOLBAR : IDS_SHOW_CUSTOMTOOLBAR)) );
  2588.     } else {
  2589.         pCmdUI->SetCheck(bShow);
  2590.     }
  2591. }
  2592.  
  2593. void CGenericFrame::OnViewCustomToolbar()
  2594. {
  2595.     GetChrome()->ShowToolbar(ID_PERSONAL_TOOLBAR, !GetChrome()->GetToolbarVisible(ID_PERSONAL_TOOLBAR));
  2596. }
  2597.  
  2598. void CGenericFrame::OnCustomizeToolbar()
  2599. {
  2600.     GetChrome()->Customize();
  2601. }
  2602.  
  2603. void CGenericFrame::OnUpdateCustomizeToolbar(CCmdUI *pCmdUI)
  2604. {
  2605.     pCmdUI->Enable(TRUE);
  2606. }
  2607.  
  2608. void CGenericFrame::OnUpdatePlaces(CCmdUI *pCmdUI)
  2609. {
  2610.     pCmdUI->Enable(TRUE);
  2611. }
  2612.  
  2613. void CGenericFrame::OnSaveConfiguration()
  2614. {
  2615.     // Save out the preferences that might have changed
  2616.     PREF_SavePrefFile();
  2617.  
  2618.   // Save global configuration stuff
  2619.   theApp.WriteProfileString("Main", "Temp Directory", theApp.m_pTempDir); 
  2620.     
  2621.   // security
  2622.   if(theApp.m_nSecurityCheck[SD_ENTERING_SECURE_SPACE])
  2623.     theApp.WriteProfileString("Security", "Warn Entering", "yes");
  2624.   else 
  2625.     theApp.WriteProfileString("Security", "Warn Entering", "no");
  2626.  
  2627.   if(theApp.m_nSecurityCheck[SD_LEAVING_SECURE_SPACE])
  2628.     theApp.WriteProfileString("Security", "Warn Leaving", "yes");
  2629.   else 
  2630.     theApp.WriteProfileString("Security", "Warn Leaving", "no");
  2631.  
  2632.   if(theApp.m_nSecurityCheck[SD_INSECURE_DOCS_WITHIN_SECURE_DOCS_NOT_SHOWN])
  2633.     theApp.WriteProfileString("Security", "Warn Mixed", "yes");
  2634.   else 
  2635.     theApp.WriteProfileString("Security", "Warn Mixed", "no");
  2636.     
  2637.   if(theApp.m_nSecurityCheck[SD_INSECURE_POST_FROM_INSECURE_DOC])
  2638.     theApp.WriteProfileString("Security", "Warn Insecure Forms", "yes");
  2639.   else 
  2640.     theApp.WriteProfileString("Security", "Warn Insecure Forms", "no");
  2641. }
  2642.  
  2643. // For Whitebox testing
  2644. #ifdef DEBUG_WHITEBOX
  2645. void CGenericFrame::OnWhiteBox() 
  2646. {
  2647.      CWhiteBoxDlg WhiteBoxDlg;
  2648.     WhiteBoxDlg.DoModal();
  2649.  
  2650. }
  2651. #endif
  2652.  
  2653. /////////////////////////////////////////////////////////////////////////////
  2654. // CNetscapePropertySheet dialog
  2655.  
  2656. BEGIN_MESSAGE_MAP(CNetscapePropertySheet, CPropertySheet)
  2657.     ON_COMMAND(IDOK, OnOK)
  2658.     ON_COMMAND(ID_HELP, OnHelp)
  2659.     ON_WM_CREATE()
  2660.     ON_WM_DESTROY()
  2661. #ifdef XP_WIN32
  2662.     ON_WM_HELPINFO()
  2663. #endif //XP_WIN32
  2664. END_MESSAGE_MAP()
  2665.  
  2666. CNetscapePropertySheet::CNetscapePropertySheet(const char * pName, CWnd * pParent, UINT nStart,
  2667.                                                MWContext *pMWContext, BOOL bUseApplyButton)
  2668.     : CPropertySheet(pName, pParent, nStart),
  2669.       m_pMWContext(pMWContext),
  2670.       m_bUseApplyButton(bUseApplyButton)
  2671. {
  2672. #if defined(MSVC4) 
  2673.     // CLM: For preferences dialogs, ommitting the Apply button is good,
  2674.     //  but in the Editor, Apply is very useful, so I added this param
  2675.     //  Default behavior is to not use apply button
  2676.     if( !bUseApplyButton )
  2677.         m_psh.dwFlags |= PSH_NOAPPLYNOW;
  2678.  
  2679. #endif
  2680. }
  2681.  
  2682. void CNetscapePropertySheet::SetPageTitle (int nPage, LPCTSTR pszText)
  2683. {
  2684.     //TODO: How can we do this in Win16???
  2685.  
  2686. #ifndef XP_WIN16
  2687.     CTabCtrl* pTab = GetTabControl();
  2688.     ASSERT (pTab);
  2689.  
  2690.     TC_ITEM ti;
  2691.     ti.mask = TCIF_TEXT;
  2692.     ti.pszText = (char*)pszText;
  2693.     VERIFY (pTab->SetItem (nPage, &ti));
  2694. #endif
  2695.  
  2696. }
  2697.  
  2698.  
  2699.  
  2700. //
  2701. // Pass the help message along to the active page cuz that is the only
  2702. //   place we have easy access to the dialog ID
  2703. //
  2704. void CNetscapePropertySheet::OnHelp()
  2705. {
  2706.     CNetscapePropertyPage * pPage = (CNetscapePropertyPage *) GetActivePage();
  2707.     if(pPage)
  2708.         pPage->OnHelp();
  2709. }
  2710.                           
  2711.  
  2712. #ifdef XP_WIN32
  2713. BOOL CNetscapePropertySheet::OnHelpInfo(HELPINFO *)//32bit messagemapping.
  2714. {
  2715.     OnHelp();
  2716.     return TRUE;
  2717. }
  2718. #endif//XP_WIN32
  2719.  
  2720. //
  2721. // MFC's OnOK() only calls for current page, we want to do all pages
  2722. //
  2723. void CNetscapePropertySheet::OnOK()
  2724. {
  2725.  
  2726.     ASSERT_VALID(this);
  2727.  
  2728. #if defined(MSVC4)
  2729.     // Save active page to pass out after we close down
  2730.     m_nCurrentPage = GetActiveIndex();
  2731. #endif
  2732.  
  2733.     if (GetActivePage()->OnKillActive())
  2734.     {
  2735.         // call OnOK for everyone
  2736.         int count = m_pages.GetSize();
  2737.         for(int i = 0; i < count; i++)
  2738.             ((CPropertyPage *) m_pages[i])->OnOK();
  2739.  
  2740.         if (!m_bModeless)
  2741.             EndDialog(IDOK);
  2742.     }
  2743.  
  2744. }
  2745.  
  2746. #if defined(MSVC4)
  2747. //
  2748. // Make sure the starting page is actually a page that exists
  2749. //
  2750. BOOL CNetscapePropertySheet::SetCurrentPage(int iPage)
  2751. {
  2752.     int nCurPage = 0;
  2753.  
  2754.     if(iPage < m_pages.GetSize())
  2755.         nCurPage = iPage;
  2756.  
  2757.     m_nCurrentPage = nCurPage;
  2758.     return(SetActivePage(nCurPage));
  2759.             
  2760. }
  2761. #else    
  2762. //
  2763. // Make sure the starting page is actually a page that exists
  2764. //
  2765. int CNetscapePropertySheet::SetCurrentPage(int iPage)
  2766. {
  2767.     if(iPage < m_pages.GetSize())
  2768.         m_nCurPage = iPage;
  2769.     else
  2770.         m_nCurPage = 0;
  2771.  
  2772.     return(m_nCurPage);
  2773.             
  2774. }
  2775. #endif    // MSVC4
  2776.  
  2777. #if defined(MSVC4)
  2778. // A change to MFC broke this -- it doesn't return last page
  2779. //     once the dialog is closed, which is how we always use it!
  2780. int CNetscapePropertySheet::GetCurrentPage()
  2781. {
  2782.     if( m_hWnd ){
  2783.         m_nCurrentPage = GetActiveIndex();
  2784.     }
  2785.     // We will set this in OnOK so it reflects
  2786.     //  correct page just before exiting dialog
  2787.     return m_nCurrentPage;
  2788. }
  2789. #endif
  2790.  
  2791. int CNetscapePropertySheet::OnCreate(LPCREATESTRUCT lpCreateStruct)
  2792. {
  2793.     if( CPropertySheet::OnCreate(lpCreateStruct) == -1 ){
  2794.         return -1;
  2795.     }
  2796.  
  2797. #ifdef XP_WIN16    
  2798.     // Since we can't remove Apply button using PSH_NOAPPLYNOW
  2799.     //   in MFC 1.52, let's do it ourselves
  2800.     if( !m_bUseApplyButton ){
  2801.         CWnd *pButton = GetDlgItem(ID_APPLY_NOW);
  2802.         CRect crRectApply;
  2803.         CRect crRectCancel;
  2804.  
  2805.         if( pButton ){
  2806.             pButton->GetWindowRect(&crRectApply);
  2807.             ScreenToClient(&crRectApply);
  2808.             // Hide Apply button
  2809.             GetDlgItem(ID_APPLY_NOW)->ShowWindow(SW_HIDE);
  2810.  
  2811.             // Move the Cancel button to the Apply position
  2812.             pButton = GetDlgItem(IDCANCEL);
  2813.             if( pButton ){
  2814.                 pButton->GetWindowRect(&crRectCancel);
  2815.                 ScreenToClient(&crRectCancel);
  2816.                 pButton->SetWindowPos(NULL, crRectApply.left, crRectApply.top, 0,0,
  2817.                                       SWP_NOACTIVATE | SWP_NOSIZE);
  2818.  
  2819.                 // Move the OK button to the Cancel position
  2820.                 pButton = GetDlgItem(IDOK);
  2821.                 if( pButton ){
  2822.                     pButton->SetWindowPos(NULL, crRectCancel.left, crRectCancel.top, 0,0, 
  2823.                                           SWP_NOACTIVATE | SWP_NOSIZE);
  2824.                 }
  2825.             }
  2826.         }
  2827.     }
  2828. #endif
  2829.     return 0;
  2830. }
  2831.  
  2832. void CNetscapePropertySheet::OnDestroy()
  2833. {
  2834.     CPropertySheet::OnDestroy();
  2835. }
  2836.  
  2837. extern int32 wfe_iFontSizeMode;
  2838.  
  2839. // Toggle Go offline, Go online menu item
  2840. //
  2841. void CGenericFrame::OnGoOffline()
  2842. {
  2843. #ifdef MOZ_OFFLINE
  2844.     BOOL bOnline;
  2845.     CDownLoadDlg rDlg(this);
  2846.     PREF_GetBoolPref("network.online", &bOnline);
  2847.     rDlg.InitDialog(!bOnline);
  2848.     rDlg.DoModal();
  2849.     // don't set the offline preference here! GoOffline won't work if we're offline!
  2850. #endif /* MOZ_OFFLINE */   
  2851. }        
  2852.  
  2853. void CGenericFrame::OnUpdateGoOffline(CCmdUI* pCmdUI)
  2854. {
  2855. #ifdef MOZ_OFFLINE
  2856.     BOOL bOnline;
  2857.     CString menuText;
  2858.  
  2859.     PREF_GetBoolPref("network.online", &bOnline);
  2860.     if (bOnline)
  2861.     {    //online now, set to offline
  2862.         menuText.LoadString(IDS_GO_OFFLINE);
  2863.     }
  2864.     else
  2865.     {    //offline now, set to online
  2866.         menuText.LoadString(IDS_GO_ONLINE);
  2867.     }
  2868.     pCmdUI->SetText(LPCTSTR(menuText));
  2869. #endif /* MOZ_OFFLINE */
  2870. }         
  2871.  
  2872. void CGenericFrame::OnDoneGoingOffline()
  2873. {
  2874. #ifdef MOZ_OFFLINE
  2875.     // I'm sure this could happen at the worst possible time
  2876.     if (!GetMainContext() || !GetMainContext()->GetContext())
  2877.         return;
  2878.  
  2879.     MWContext *pContext = GetMainContext()->GetContext();
  2880.     if (NET_IsOffline() && !XP_IsContextBusy(pContext)) {
  2881.         FE_Progress(pContext, szLoadString(IDS_STATUS_OFFLINE));
  2882.     } else {
  2883.         FE_Progress(pContext, szLoadString(IDS_DOC_DONE));
  2884.     }
  2885. #endif // MOZ_OFFLINE
  2886. }
  2887.  
  2888. #ifdef FORTEZZA
  2889. /*
  2890.  * It would be nice to replace the following code with a single routine
  2891.  * that switches off the Resource ID.  (do this in CGenericFrame::OnCmdMsg)
  2892.  */
  2893. void CGenericFrame::OnStartFortezzaCard()
  2894. {
  2895.     MWContext *pContext = GetMainContext() != NULL ? 
  2896.                     GetMainContext()->GetContext() : NULL;
  2897.     SSL_FortezzaMenu(pContext,SSL_FORTEZZA_CARD_SELECT);
  2898. }
  2899. void CGenericFrame::OnStartFortezzaChange()
  2900. {
  2901.     MWContext *pContext = GetMainContext() != NULL ? 
  2902.                     GetMainContext()->GetContext() : NULL;
  2903.     SSL_FortezzaMenu(pContext,SSL_FORTEZZA_CHANGE_PERSONALITY);
  2904. }
  2905. void CGenericFrame::OnStartFortezzaView()
  2906. {
  2907.     MWContext *pContext = GetMainContext() != NULL ? 
  2908.                     GetMainContext()->GetContext() : NULL;
  2909.     SSL_FortezzaMenu(pContext,SSL_FORTEZZA_VIEW_PERSONALITY);
  2910. }
  2911. void CGenericFrame::OnDoFortezzaInfo()
  2912. {
  2913.     MWContext *pContext = GetMainContext() != NULL ? 
  2914.                     GetMainContext()->GetContext() : NULL;
  2915.     SSL_FortezzaMenu(pContext,SSL_FORTEZZA_CARD_INFO);        
  2916. }
  2917. void CGenericFrame::OnDoFortezzaLog()
  2918. {
  2919.     MWContext *pContext = GetMainContext() != NULL ? 
  2920.                     GetMainContext()->GetContext() : NULL;
  2921.     SSL_FortezzaMenu(pContext,SSL_FORTEZZA_LOGOUT);
  2922. }
  2923. #endif
  2924.  
  2925. //
  2926. // Just call OnClose
  2927. //
  2928. void CGenericFrame::OnFrameExit()
  2929. {
  2930.     PostMessage(WM_CLOSE);
  2931. }
  2932.  
  2933. void CGenericFrame::OnSetFocus(CWnd* pOldWnd) 
  2934. {
  2935.     CFrameWnd::OnSetFocus(pOldWnd);
  2936.  
  2937.     //    Put us on the active stack.
  2938.     SetAsActiveFrame();
  2939. }
  2940.  
  2941. void CGenericFrame::OnWindowPosChanged(WINDOWPOS *lpWndPos)
  2942. {
  2943.     //    Call the base.
  2944.     CFrameWnd::OnWindowPosChanged(lpWndPos);
  2945.  
  2946.     //    Tell ncapi people window is changing position.
  2947.     if(GetMainContext() && GetMainContext()->GetContext()->type == MWContextBrowser)    {
  2948.         CWindowChangeItem::Sizing(GetMainContext()->GetContextID(), lpWndPos->x, lpWndPos->y, lpWndPos->cx, lpWndPos->cy);
  2949.     }
  2950. }
  2951.  
  2952. void CGenericFrame::OnWindowPosChanging(WINDOWPOS *lpWndPos)
  2953. {
  2954.     if (m_bZOrderLocked){
  2955.         lpWndPos->flags = lpWndPos->flags | SWP_NOZORDER | SWP_NOOWNERZORDER;
  2956.     }
  2957.               
  2958.     //  Call the base
  2959.     CFrameWnd::OnWindowPosChanging( lpWndPos);
  2960. }
  2961.  
  2962. void CGenericFrame::OnSize(UINT nType, int cx, int cy) 
  2963. {
  2964.     CFrameWnd::OnSize(nType, cx, cy);
  2965.     
  2966.     //  See what type of information we're going to be sending to our window tracking service.
  2967.     //    ncapi
  2968.     if(GetMainContext() != NULL && GetMainContext()->GetContext()->type == MWContextBrowser)    {
  2969.         switch(nType)   {
  2970.             case SIZE_MAXIMIZED:
  2971.                 CWindowChangeItem::Maximizing(GetMainContext()->GetContextID());
  2972.                 break;
  2973.             case SIZE_MINIMIZED:
  2974.                 CWindowChangeItem::Minimizing(GetMainContext()->GetContextID());
  2975.                 break;
  2976.             case SIZE_RESTORED:
  2977.                 CWindowChangeItem::Normalizing(GetMainContext()->GetContextID());
  2978.                 break;
  2979.         }
  2980.     }
  2981. }
  2982.  
  2983.  
  2984. BOOL CGenericFrame::OnCommand(UINT wParam,LONG lParam)
  2985. {               
  2986. #ifdef WIN32
  2987.     int nCode = HIWORD(wParam);
  2988. #else
  2989.     int nCode = HIWORD(lParam);
  2990. #endif
  2991.  
  2992.     UINT nID = LOWORD(wParam);
  2993.     if( nID >= ID_OPTIONS_ENCODING_1 && nID <= ID_OPTIONS_ENCODING_70)
  2994.     {
  2995.           OnToggleEncoding( nID );
  2996.           return TRUE;
  2997.     }
  2998.     if (m_bDisableHotkeys && nCode==1) {
  2999.     switch (LOWORD(wParam)) {
  3000.         case ID_SECURITY:
  3001.         case ID_APP_EXIT:
  3002.         case ID_EDIT_PASTE:
  3003.         case ID_EDIT_COPY:
  3004.         case ID_EDIT_CUT:
  3005.         break;
  3006.         default:
  3007.         return(TRUE);
  3008.     }
  3009.     }
  3010.     
  3011.     if(CFrameWnd::OnCommand(wParam, lParam))    {
  3012.         return(TRUE);
  3013.     }
  3014.  
  3015.  
  3016.     // See if it was a bookmark item
  3017.     if (IS_BOOKMARK_ID(nID) && GetMainContext()) {
  3018.         // Make sure the command ID is consistent with the last
  3019.         // selected menu item
  3020.         ASSERT(nLastSelectedCmdID == nID && nLastSelectedData);
  3021.         if (nLastSelectedCmdID != nID || !nLastSelectedData)
  3022.             return FALSE;
  3023. #ifdef EDITOR        
  3024.         // It is much safer to go through Composer's LoadUrl routine
  3025.         if(EDT_IS_EDITOR(GetMainContext()->GetContext()))
  3026.             FE_LoadUrl((char*)nLastSelectedData, TRUE);
  3027.         else
  3028. #endif
  3029.              GetMainContext()->NormalGetUrl((char*)nLastSelectedData);
  3030.         return TRUE;
  3031.     }
  3032.  
  3033.     if(IS_FILE_BOOKMARK_ID(nID) && GetMainContext()) {
  3034.         if(nLastSelectedCmdID != nID || !nLastSelectedData)
  3035.             return FALSE;
  3036.  
  3037.         if(GetMainContext()) 
  3038.         {
  3039.             FileBookmark((HT_Resource)nLastSelectedData);
  3040.         }
  3041.  
  3042.         return TRUE;
  3043.  
  3044.     }
  3045.  
  3046.     return CommonCommand(wParam, lParam);
  3047. }
  3048.  
  3049. // returns TRUE if something was added to the folder, false otherwise
  3050. BOOL CGenericFrame::FileBookmark(HT_Resource pFolder)
  3051. {
  3052.     return FALSE;
  3053. }
  3054.  
  3055. void CGenericFrame::OnAnimationBonk()
  3056. {
  3057.     if ( GetMainContext() ) {
  3058.         GetMainContext()->NormalGetUrl( szLoadString( IDS_DIRECT_HOME ) );
  3059.     }
  3060. }
  3061.  
  3062. void CGenericFrame::OnUpdateFileRoot(CCmdUI* pCmdUI)
  3063. {
  3064.     if( pCmdUI->m_pMenu ){
  3065.         pCmdUI->m_pMenu->ModifyMenu(ID_BOOKMARKS_FILEROOT, MF_BYCOMMAND | MF_STRING, ID_BOOKMARKS_FILEROOT,
  3066.                                     HT_GetNodeName(HT_TopNode(HT_GetSelectedView(m_BookmarkMenuPane))));
  3067.     }
  3068.  
  3069. }
  3070.  
  3071. void CGenericFrame::OnNewFrame() 
  3072. {
  3073.     //      Pass it off to the context for handling.
  3074.     if(GetMainContext())        {
  3075.         GetMainContext()->NewWindow();
  3076.     }
  3077. }
  3078.  
  3079. void CGenericFrame::OnUpdateNewFrame(CCmdUI* pCmdUI) 
  3080. {
  3081.     //      Defer to the context's wisdom.
  3082.     if(GetMainContext())        {
  3083.         pCmdUI->Enable(GetMainContext()->CanNewWindow());
  3084.     }
  3085.     else    {
  3086.         pCmdUI->Enable(FALSE);
  3087.     }
  3088. }
  3089.  
  3090. // This is used by browser or editor
  3091. //   to open a URL into either a browser 
  3092. //   or editor window (Radio buttons 
  3093. //   added to dialog to choose destination)
  3094. // If destination is a Browser and calling from Browser, 
  3095. //  open in same window (same as current behavior), 
  3096. //  for all other cases, open in new window
  3097. void CGenericFrame::OnFileOpenurl() 
  3098. {
  3099.     if(GetMainContext())        {
  3100.         GetMainContext()->OpenUrl();
  3101.     }
  3102. }
  3103.  
  3104. void CGenericFrame::OnUpdateFileOpenurl(CCmdUI* pCmdUI) 
  3105. {
  3106.     if(GetMainContext())        {
  3107.         pCmdUI->Enable(GetMainContext()->CanOpenUrl());
  3108.     }
  3109.     else    {
  3110.         pCmdUI->Enable(FALSE);
  3111.     }
  3112. }
  3113.  
  3114. void CGenericFrame::OnHotlistAddcurrenttohotlist() 
  3115. {
  3116.     if(GetMainContext())        {
  3117.         GetMainContext()->AddToBookmarks();
  3118.     }
  3119. }
  3120.  
  3121. void CGenericFrame::OnUpdateHotlistAddcurrenttohotlist(CCmdUI* pCmdUI) 
  3122. {
  3123.     if(GetMainContext())        {
  3124.         pCmdUI->Enable(GetMainContext()->CanAddToBookmarks());
  3125.     }
  3126.     else    {
  3127.         pCmdUI->Enable(FALSE);
  3128.     }
  3129. }
  3130.  
  3131. void CGenericFrame::OnHotlistAddcurrenttotoolbar() 
  3132. {
  3133. /* PERSONAL
  3134.     if(GetMainContext())        {
  3135.         History_entry *pHistEnt = SHIST_GetCurrent( &(GetMainContext()->GetContext()->hist) );
  3136.         ASSERT(pHistEnt);
  3137.  
  3138.         BM_Entry *pEntry = BM_NewUrl( GetMainContext()->GetContext()->title, pHistEnt->address, NULL, 
  3139.                                       pHistEnt->last_access );
  3140.         ASSERT(pEntry);
  3141.  
  3142.         BM_AppendToHeader( theApp.m_pBmContext, theApp.GetLinkToolbarManager().GetToolbarHeader(), 
  3143.                            pEntry );
  3144.  
  3145.         theApp.GetLinkToolbarManager().ToolbarHeaderChanged();
  3146.  
  3147.     }
  3148. */
  3149. }
  3150.  
  3151. void CGenericFrame::OnUpdateHotlistAddcurrenttotoolbar(CCmdUI* pCmdUI) 
  3152. {
  3153.     if(GetMainContext())        {
  3154.         pCmdUI->Enable(GetMainContext()->CanAddToBookmarks());
  3155.     }
  3156.     else    {
  3157.         pCmdUI->Enable(FALSE);
  3158.     }
  3159. }
  3160.  
  3161. // Give the focus to the next top-level window
  3162. // 
  3163. void CGenericFrame::OnNextWindow()
  3164. {
  3165.     // User has pressed ctrl-tab to switch windows
  3166.       
  3167.     if (this->m_pNext) {// goto next if exists
  3168.         this->m_pNext->SetActiveWindow(); 
  3169.     } else { // else start at beginning
  3170.         if(theApp.m_pFrameList)
  3171.             theApp.m_pFrameList->SetActiveWindow();
  3172.     }   
  3173. }
  3174.  
  3175.  
  3176. void CGenericFrame::OnSaveOptions()
  3177. {
  3178.     // Save Encoding Info
  3179.     theApp.m_iCSID = m_iCSID ;    // Change Global default CSID
  3180.     PREF_SetIntPref("intl.character_set",m_iCSID);
  3181. }
  3182.  
  3183. LRESULT CGenericFrame::OnFindReplace(WPARAM wParam, LPARAM lParam) 
  3184. {
  3185.  
  3186.     CWinCX *pContext = GetActiveWinContext();
  3187.  
  3188.     if(!pContext)
  3189.         pContext = GetMainWinContext();
  3190.  
  3191.     if(pContext && pContext->GetPane())
  3192.         return(pContext->GetView()->OnFindReplace(wParam, lParam));
  3193.  
  3194.     return(FALSE);
  3195.  
  3196. }
  3197.  
  3198. void CGenericFrame::OnMove(int x, int y) 
  3199. {
  3200.     CFrameWnd::OnMove(x, y);
  3201.     
  3202.     //    Tell our main context that we've moved.
  3203.     if(GetMainWinContext())    {
  3204.         GetMainWinContext()->OnMoveCX();
  3205.     }
  3206. }
  3207.  
  3208. void CGenericFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) 
  3209. {
  3210.     //    Do the default first.
  3211.     CFrameWnd::OnGetMinMaxInfo(lpMMI);
  3212.  
  3213.     //    If we're not allowing resize, be sure and set the min max tracking information
  3214.     //        which effectively blocks the user from resizing the window.
  3215.     if(m_bCanResize == FALSE && IsIconic() == FALSE && IsZoomed() == FALSE)    {
  3216.         //    Set up the min and max tracking info to be the same to block resize.
  3217.         lpMMI->ptMinTrackSize.x = lpMMI->ptMaxTrackSize.x = m_crMinMaxRect.Width();
  3218.         lpMMI->ptMinTrackSize.y = lpMMI->ptMaxTrackSize.y = m_crMinMaxRect.Height();
  3219.     }
  3220. }
  3221.  
  3222. // Sets a flag determining wether or now we'll let the user resize the window.
  3223. void CGenericFrame::EnableResize(BOOL bEnable)
  3224. {
  3225.     long lStyles = 0;
  3226.     
  3227.     // Set the flag.
  3228.     m_bCanResize = bEnable;
  3229.     GetWindowRect(m_crMinMaxRect);
  3230.  
  3231.     lStyles = GetWindowLong(GetSafeHwnd(), GWL_STYLE);
  3232.     if (lStyles & WS_POPUP)
  3233.     return;
  3234.     if (bEnable) { 
  3235.     // We need to make sure the windows maximize buttons come back if we killed them.
  3236.     if (lStyles & WS_MAXIMIZEBOX)
  3237.         return;
  3238.     lStyles |= WS_MAXIMIZEBOX;
  3239.     SetWindowLong(GetSafeHwnd(), GWL_STYLE, lStyles);
  3240.     }
  3241.     else { //The window is being set non-resizable.  Kill the windows maximize button as well.
  3242.     if (!(lStyles & WS_MAXIMIZEBOX))
  3243.         return;
  3244.     lStyles &= ~WS_MAXIMIZEBOX;
  3245.     SetWindowLong(GetSafeHwnd(), GWL_STYLE, lStyles);
  3246.     }
  3247. }
  3248.  
  3249. void CGenericFrame::DisableHotkeys(BOOL bDisable)
  3250. {
  3251.     // Set the flag.
  3252.     m_bDisableHotkeys = bDisable;
  3253. }
  3254.  
  3255. void CGenericFrame::SetZOrder(BOOL bZLock, BOOL bBottommost)
  3256. {
  3257.     // Set the flag.
  3258.     m_bZOrderLocked = bZLock;
  3259.     m_bBottommost = bBottommost;
  3260.  
  3261.     if (m_bBottommost)
  3262.     m_bZOrderLocked = TRUE;
  3263. }
  3264.  
  3265. #ifdef WIN32
  3266. //These functions don't do anything on Win16.
  3267. void CGenericFrame::SetExStyles(DWORD wAddedExStyles, DWORD wRemovedExStyles)
  3268. {
  3269.     // Set any ws_ex_styles for the window
  3270.     m_wAddedExStyles |= wAddedExStyles;
  3271.     m_wRemovedExStyles |= wRemovedExStyles;
  3272. }
  3273.  
  3274. DWORD CGenericFrame::GetRemovedExStyles()
  3275. {
  3276.     // Set any ws_ex_styles we are setting for the window
  3277.     return (m_wRemovedExStyles);
  3278. }
  3279. #endif 
  3280.  
  3281. void CGenericFrame::SetAsPopup(HWND hPopupParent)
  3282. {
  3283.  
  3284.     m_hPopupParent = hPopupParent;
  3285. }
  3286.  
  3287. #ifdef WM_SIZING
  3288. void CGenericFrame::OnSizing(UINT nSide, LPRECT lpRect)
  3289. {
  3290.     //  User is resizing window.
  3291.     //  Save the current size of the window (used in get min max info)
  3292.     //      in case we have to hold us to that.
  3293.     GetWindowRect(m_crMinMaxRect);
  3294. }
  3295. #endif
  3296.  
  3297. #ifdef _WIN32
  3298. LONG CGenericFrame::OnHackedMouseWheel(WPARAM wParam, LPARAM lParam)
  3299. {
  3300.     //  Determine if we're the destination.
  3301.     BOOL bUs = TRUE;
  3302.     HWND hFocus = ::GetFocus();
  3303.     if(hFocus)  {
  3304.         //  Is the focus window our child?
  3305.         BOOL bChild = ::IsChild(m_hWnd, hFocus);
  3306.         if(bChild)    {
  3307.             //  Pass along.
  3308.             bUs = FALSE;
  3309.         }
  3310.     }
  3311.  
  3312.     //  Either call ourselves or pass along.
  3313.     if(bUs == TRUE) {
  3314.         //  Zero means not handled.
  3315.         return(0);
  3316.     }
  3317.     else    {
  3318.         return(::SendMessage(hFocus, msg_MouseWheel, wParam, lParam));
  3319.     }
  3320. }
  3321. #endif
  3322.  
  3323. // Call to start a new Browser window with supplied URL
  3324. //  or load homepage if none supplied
  3325.  
  3326. MWContext * wfe_CreateNavigator(char * pUrl)
  3327. {
  3328.     URL_Struct *pUrlStruct = NULL;
  3329.     
  3330.     if ( pUrl != NULL && XP_STRLEN(pUrl) > 0 )
  3331.     {
  3332.         // Create a new URL structure and copy URL string to it
  3333.         pUrlStruct = NET_CreateURLStruct(pUrl, NET_DONT_RELOAD);
  3334.         // Must clear this to correctly load URL
  3335.         if ( pUrlStruct ) {
  3336.             pUrlStruct->fe_data = NULL;
  3337.         }
  3338.     }
  3339.  
  3340.     // Always create a new context 
  3341.     return CFE_CreateNewDocWindow(NULL, pUrlStruct );
  3342. }
  3343.  
  3344.  
  3345.