home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / mainfrm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  21.3 KB  |  794 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. // mainfrm.cpp : implementation of the CMainFrame class
  20. //
  21.  
  22. #include "stdafx.h"
  23.  
  24. #include "dialog.h"
  25. #include "winclose.h"
  26. #include "cntritem.h"
  27. #include "timer.h"
  28. #include "cxsave.h"
  29. #include "edt.h"
  30. #include "mainfrm.h"
  31. #include "edframe.h"
  32. #include "netsvw.h"
  33. #include "hiddenfr.h"
  34. #include "intlwin.h"
  35. #include "msgcom.h"
  36. #include "custom.h"
  37. #include "statbar.h"
  38. #include "histbld.h"
  39. #include "nethelp.h"
  40. #include "mnwizard.h"
  41. #include "ssl.h"
  42. #include "prefapi.h"
  43. #include "prefInfo.h"
  44. #include "medit.h"
  45.  
  46. #include "np.h"
  47. #include "npapi.h"            // for NPWindow
  48.  
  49. #ifdef JAVA
  50. #include "java.h"
  51. #endif
  52.  
  53. #ifdef _DEBUG
  54. #undef THIS_FILE
  55. static char BASED_CODE THIS_FILE[] = __FILE__;
  56. #endif
  57.  
  58. #ifndef _AFXDLL
  59. #define new DEBUG_NEW  // MSVC Debugging new...goes to regular new in release mode
  60. #endif
  61.  
  62. #define SECURE_BITMAP_INDEX 10
  63. #define MIDSECURE_BITMAP_INDEX 9
  64. #define UNSECURE_BITMAP_INDEX 8
  65. //
  66. // If we are already calling NET_ProcessNet() cuz of a socket ready message
  67. //   do not call it again via a timer interrupt
  68. //        
  69. MODULE_PRIVATE int winfeInProcessNet = FALSE;
  70. static int calledProcessNet = FALSE;
  71.  
  72. // remember a socket which got a network event while we were thinking
  73. static long m_nSocketToDealWith = 0;         
  74.  
  75. extern CMapStringToOb DNSCacheMap;
  76.  
  77. static CHistoryMenuBuilder histBuilder;
  78.  
  79. #include "toolbar.cpp"
  80.  
  81. /////////////////////////////////////////////////////////////////////////////
  82. // CMainFrame diagnostics
  83.  
  84. #ifdef _DEBUG
  85. void CMainFrame::AssertValid() const
  86. {
  87.     CGenericFrame::AssertValid();
  88. }
  89.  
  90. void CMainFrame::Dump(CDumpContext& dc) const
  91. {
  92.     CGenericFrame::Dump(dc);
  93. }
  94.  
  95. #endif //_DEBUG
  96.  
  97. //
  98. // Pop up an alert box for the user
  99. //
  100. void CMainFrame::Alert(char * Msg)
  101. {
  102.     MessageBox(Msg, szLoadString(AFX_IDS_APP_TITLE), MB_ICONEXCLAMATION | MB_OK);
  103. }
  104.  
  105. //
  106. // Pop up a message to the user.
  107. // Return TRUE if the user clicks on the "OK" button else FALSE
  108. //
  109. int CMainFrame::Confirm(char * Msg)
  110. {
  111.     int res = GetActiveWindow()->MessageBox(Msg, szLoadString(AFX_IDS_APP_TITLE), MB_ICONQUESTION | MB_OKCANCEL);
  112.     return(res == IDOK);
  113. }
  114.  
  115. char * CMainFrame::Prompt(const char * Msg, const char * Dflt)
  116. {
  117.     // CDialogPRMT foo(this->GetActiveWindow());
  118.     // Must always use ActiveWindow so preference dialogs are the parent,
  119.     //   else user can move focus to preference dialog and loose prompt dialog
  120.     CDialogPRMT foo(this->GetActiveWindow());
  121.     return(foo.DoModal(Msg, Dflt));
  122. }
  123.  
  124.  
  125. char * CMainFrame::PromptPassword(char * Msg)
  126. {
  127.     // CDialogPASS foo(this);
  128.     CDialogPASS foo(this->GetActiveWindow());
  129.     return(foo.DoModal(Msg));
  130. }
  131.  
  132. #define IS_IN_WINDOW(hParent,hChild)\
  133.     (((hParent) == (hChild)) || ::IsChild(hParent, hChild))
  134.  
  135. BOOL CMainFrame::setNextTabFocus( int forward )
  136. {
  137.     CWinCX *pWinCX = GetMainWinContext();
  138.     if( pWinCX ) {
  139.         // setTabFocusNext will search siblings
  140.         BOOL ret = pWinCX->setTabFocusNext( forward );
  141.         if( ret ) 
  142.             return( TRUE );
  143.     }
  144.  
  145.     return( FALSE );
  146. }
  147.  
  148. BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
  149. {
  150.  
  151.     BOOL    bTranslated = CGenericFrame::PreTranslateMessage(pMsg);
  152.  
  153.     if (bTranslated)
  154.         return TRUE;  // msg handled
  155.  
  156.     if (pMsg->message != WM_KEYDOWN)
  157.         return FALSE;  // we're not interested in translating this message
  158.  
  159.     // Do not continue with tab processing if in an editor
  160.     if(    (pMsg->wParam != VK_TAB && pMsg->wParam != VK_SPACE    && pMsg->wParam != VK_RETURN)
  161.       ||  EDT_IS_EDITOR(GetMainContext()->GetContext()) )
  162.       return( FALSE );
  163.  
  164.     // if a plugin has the focus, we don't touch the any (TAB,SAPCE,CR) key.
  165.     if(    GetActiveWinContext() && GetActiveWinContext()->GetContext() ) {
  166.         // get the plugin list
  167.         NPEmbeddedApp * pPlugin = GetActiveWinContext()->GetContext()->pluginList;
  168.         // check each plugin in the list, to see if a plugin is the parent
  169.         // of the focus window.
  170.         while( pPlugin != NULL ) {
  171.             NPWindow* npWindow = pPlugin->wdata;
  172.             if( npWindow && npWindow->type == NPWindowTypeWindow ) {
  173.                 // check relation of parent(plugin) - child(msg window)  
  174.                 if( npWindow->window && IS_IN_WINDOW( (HWND)npWindow->window, pMsg->hwnd) )
  175.                     return(FALSE);        // plugin has focus, dont touch TAB key
  176.             }
  177.             pPlugin = pPlugin->next;
  178.         }
  179.     }
  180.  
  181.     /*
  182.     The windows messaging systems such as CWnd::WalkPreTranslateTree(), only
  183.     walk from leaf to root of the window tree.
  184.  
  185.     To navigate in frames(grids), Tab navigation needs to go from one window(view)
  186.     to its sibling. Therefor, we need to walk the tree.
  187.     */
  188.     CGenericView    *pView;
  189.     UINT            forward = GetKeyState(VK_SHIFT)<0 ? 0 : 1 ;    // 1 is forward
  190.     UINT            controlKey = GetKeyState(VK_CONTROL)<0 ? 1 : 0 ;    // 1 controlKey, go to next group
  191.     int                ii;
  192.  
  193.     // IF child A reached the end of tabable elements, and child B
  194.     // has no tabable elements, we need go back to child A to set
  195.     // tab focus. That is the "for" loop for.
  196.     for( ii = 0; ii < 2  && !bTranslated; ii ++ ) {
  197.  
  198.         // the chrome(location and starter bar) get Tab focus first
  199.         if( GetChrome() != NULL ) {
  200.             if( m_tabFocusInMainFrm == TAB_FOCUS_IN_NULL ) {
  201.     
  202.                 // first time, 
  203.                 if( pMsg->wParam != VK_TAB )     // #49928 only handle Tab key in Chrome
  204.                     return( FALSE );
  205.  
  206.                 // set focus to the location box.
  207.                 bTranslated  = GetChrome()->procTabNavigation( pMsg->wParam, 1, controlKey ); 
  208.                 if( bTranslated ) {
  209.                     m_tabFocusInMainFrm = TAB_FOCUS_IN_CHROME;
  210.                     return( TRUE );
  211.                 }   // else, do nothing, fall to setting focus in views.
  212.             } else if( m_tabFocusInMainFrm == TAB_FOCUS_IN_CHROME ) {
  213.  
  214.                 if( pMsg->wParam != VK_TAB )     // #49928 only handle Tab key in Chrome 
  215.                     return( FALSE );
  216.  
  217.                 bTranslated  = GetChrome()->procTabNavigation( pMsg->wParam, 0, controlKey );
  218.                 if( bTranslated ) {
  219.                     // chrome consummed the Tab key
  220.                     m_tabFocusInMainFrm = TAB_FOCUS_IN_CHROME;
  221.                     return( TRUE );
  222.                 } else {
  223.                     m_tabFocusInMainFrm = TAB_FOCUS_IN_NULL;
  224.                     // fall to setting focus in views.
  225.                 }
  226.  
  227.             }
  228.         } else { // no chrome, user may just close the chrom
  229.             if( m_tabFocusInMainFrm == TAB_FOCUS_IN_CHROME ) 
  230.                 m_tabFocusInMainFrm = TAB_FOCUS_IN_NULL;
  231.                 // fall to setting focus in views.
  232.         }
  233.         
  234.         if( bTranslated ) 
  235.             return(TRUE);
  236.  
  237. #ifdef DEBUG_aliu
  238.         // we should have returned, if focus was set in chrome.
  239.         ASSERT(  m_tabFocusInMainFrm != TAB_FOCUS_IN_CHROME  ); 
  240. #endif
  241.         if( ! GetActiveView() ) {        // #55453 something wrong, try my best.
  242.             bTranslated = setNextTabFocus(forward); // setNextTabableFrame( NULL, forward );        //NULL start with the first frame
  243.         } else {
  244.             if( ! GetActiveView()->IsKindOf(RUNTIME_CLASS( CGenericView ) ) )
  245.                 return(FALSE);             // not html, maybe print-preview #44362
  246.  
  247.             // now try to set tab focus to the views(grids)
  248.             if( m_tabFocusInMainFrm == TAB_FOCUS_IN_GRID ) {
  249.                 // Starting with the active view, procTabNavigation() will 
  250.                 // search siblings in this frame window.
  251.                 pView = (CGenericView *) GetActiveView( );
  252.                 
  253.                 if( pView == NULL )
  254.                     return(FALSE);
  255.  
  256.                 // TODO control key is for Tab-group(Form, table) or for Frame???
  257.                 if( ! controlKey ) {
  258.                     // try active view first
  259.                     bTranslated = pView->procTabNavigation( pMsg->wParam, forward, controlKey );    // for Tab, or SpaceBar
  260.                     if ( bTranslated ) {
  261.                         m_tabFocusInMainFrm = TAB_FOCUS_IN_GRID ;
  262.                         return( TRUE );        // msg handled
  263.                     }
  264.                 }
  265.  
  266.                 if( pMsg->wParam != VK_TAB )
  267.                     return( FALSE );
  268.  
  269.                 // active frame has nothing to tab to.
  270.                 m_tabFocusInMainFrm = TAB_FOCUS_IN_NULL;
  271.  
  272.                 // try other frames(if any), starting from this 
  273.                 // bTranslated = setNextTabableFrame( this, forward );
  274.             }   else {    // TAB_FOCUS_IN_NULL,
  275.                 //  start with the first frame
  276.                 bTranslated = setNextTabFocus(forward);    // setNextTabableFrame( NULL, forward );
  277.             }
  278.         }   // if( ! GetActiveView() )
  279.  
  280.         if ( bTranslated ) {
  281.             m_tabFocusInMainFrm = TAB_FOCUS_IN_GRID ;
  282.             return( TRUE );        // msg handled
  283.         }
  284.     
  285.     }    // for( ii = 0; ii < 2; ii ++ )
  286.     return(FALSE);
  287. }    // BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
  288.  
  289.  
  290. void CMainFrame::OnToggleFancyFtp()
  291. {
  292.     if(GetMainContext())    {
  293.         GetMainContext()->GetContext()->fancyFTP = !GetMainContext()->GetContext()->fancyFTP;
  294.     }
  295. }
  296.  
  297. void CMainFrame::OnUpdateToggleFancyFtp(CCmdUI* pCmdUI)
  298. {   
  299.     if(GetMainContext())    {
  300.         pCmdUI->SetCheck(GetMainContext()->GetContext()->fancyFTP);
  301.     }
  302. }
  303.  
  304. void CMainFrame::RefreshNewEncoding(int16 csid, BOOL bIgnore)
  305. {
  306.   if (m_iCSID != csid)
  307.   {
  308.     if(GetMainContext())    {
  309.       int iOldCSID = m_iCSID;
  310.  
  311.       // Must set before EDT_SetEncoding.
  312.       m_iCSID = csid;
  313. #ifdef EDITOR      
  314.       if( EDT_IS_EDITOR(GetMainContext()->GetContext()) )
  315.             {
  316.         // EDT_SetEncoding takes care of reloading.
  317.         if ( ! EDT_SetEncoding(GetMainContext()->GetContext(), csid) ) {
  318.             // revert m_iCSID
  319.             m_iCSID = iOldCSID;
  320.             return;
  321.         }
  322.             }
  323.       else 
  324. #endif /* EDITOR */      
  325.       {
  326.         GetMainContext()->NiceReload();
  327.       }
  328.     }
  329.   }
  330. }
  331.  
  332. //
  333. // Toggle the showing of the location bar
  334. //
  335. void CMainFrame::OnOptionsTitlelocationBar()
  336. {
  337.     if(GetChrome()->GetToolbarVisible(ID_LOCATION_TOOLBAR)) {
  338.         GetChrome()->ShowToolbar(ID_LOCATION_TOOLBAR, FALSE);
  339.         m_bLocationBar= FALSE;
  340.     } else {
  341.         GetChrome()->ShowToolbar(ID_LOCATION_TOOLBAR, TRUE);
  342.         m_bLocationBar= TRUE;
  343.     }
  344. }
  345.  
  346. void CMainFrame::OnUpdateOptionsTitlelocationBar(CCmdUI* pCmdUI)
  347. {
  348.     pCmdUI->SetCheck(GetChrome()->GetToolbarVisible(ID_LOCATION_TOOLBAR));
  349. }
  350.  
  351. XP_BEGIN_PROTOS
  352.   extern char * NET_PrintNetlibStatus();
  353. XP_END_PROTOS
  354.  
  355. void CMainFrame::OnOptionsTogglenetdebug()
  356. {
  357.     if(GetActiveContext() != NULL)  {
  358.         char *rv =  NET_PrintNetlibStatus();
  359.         FE_Alert(GetActiveContext()->GetContext(), rv);
  360.         XP_FREE(rv);
  361.         NET_ToggleTrace();
  362.     }
  363. }
  364.  
  365.  
  366. void CMainFrame::OnToggleImageLoad()
  367. {
  368.     CWinCX *pWinCX;
  369.     if( pWinCX = GetMainWinContext())    {
  370.         if( prefInfo.m_bAutoLoadImages) {
  371.             prefInfo.m_bAutoLoadImages = FALSE; 
  372.             GetChrome()->ImagesButton(TRUE);
  373.         } else {
  374.             prefInfo.m_bAutoLoadImages = TRUE;; 
  375.             GetChrome()->ImagesButton(FALSE);
  376.         }
  377.     }
  378. }
  379.  
  380. void CMainFrame::OnUpdateToggleImageLoad(CCmdUI* pCmdUI)
  381. {
  382.     CWinCX *pWinCX;
  383.     if(    pWinCX = GetMainWinContext())    {
  384.         pCmdUI->SetCheck(prefInfo.m_bAutoLoadImages);
  385.     }
  386. }
  387.  
  388. void CMainFrame::OnNetSearch()
  389. {
  390.     char * url = NULL;
  391.     PREF_CopyConfigString("internal_url.net_search.url",&url);
  392.     
  393.     if(GetMainContext() && url)
  394.     {
  395.         GetMainContext()->NormalGetUrl(url);
  396.         XP_FREE(url);
  397.     }
  398. }
  399.  
  400. void CMainFrame::OnUpdateNetSearch(CCmdUI *pCmdUI)
  401. {
  402.     pCmdUI->Enable(TRUE);
  403. }
  404.  
  405.  
  406. void CMainFrame::OnUpdateSecurity(CCmdUI *pCmdUI)
  407. {
  408.     
  409.     MWContext *pContext = GetMainContext()->GetContext();
  410.  
  411.     if(EDT_IS_EDITOR(pContext))
  412.         CGenericFrame::OnUpdateSecurity(pCmdUI);
  413.     else
  414.     {
  415.         int status = XP_GetSecurityStatus(pContext);    
  416.     
  417.         BOOL bHasSecurity = status == SSL_SECURITY_STATUS_ON_LOW || status == SSL_SECURITY_STATUS_ON_HIGH;
  418.  
  419.         if(m_pCommandToolbar)
  420.         {
  421.             switch(status)
  422.             {
  423.                 case SSL_SECURITY_STATUS_ON_LOW:
  424.                             m_pCommandToolbar->ReplaceButtonBitmapIndex(ID_SECURITY, SECURE_BITMAP_INDEX);
  425.                             break;
  426.                 case SSL_SECURITY_STATUS_ON_HIGH:
  427.                             m_pCommandToolbar->ReplaceButtonBitmapIndex(ID_SECURITY, SECURE_BITMAP_INDEX);
  428.                             break;
  429.                 default:
  430.                     m_pCommandToolbar->ReplaceButtonBitmapIndex(ID_SECURITY, UNSECURE_BITMAP_INDEX);
  431.                     break;
  432.             }
  433.             pCmdUI->Enable(TRUE);
  434.         }
  435.         else
  436.             pCmdUI->Enable(FALSE);
  437.     }
  438.  
  439. }
  440.  
  441. void CMainFrame::OnUpdateSecurityStatus(CCmdUI *pCmdUI)
  442. {
  443.     int status = XP_GetSecurityStatus(GetMainContext()->GetContext());    
  444.     pCmdUI->Enable(status == SSL_SECURITY_STATUS_ON_LOW || status == SSL_SECURITY_STATUS_ON_HIGH);
  445. }
  446.  
  447. void CMainFrame::OnUpdateViewCommandToolbar(CCmdUI *pCmdUI)
  448. {
  449.     CGenericFrame::OnUpdateViewCommandToolbar(pCmdUI);
  450.  
  451.     if(!IsEditFrame() && PREF_PrefIsLocked("browser.chrome.show_toolbar"))
  452.         pCmdUI->Enable(FALSE);
  453. }
  454.  
  455.  
  456. void CMainFrame::OnUpdateViewLocationToolbar(CCmdUI *pCmdUI)
  457. {
  458.     CGenericFrame::OnUpdateViewLocationToolbar(pCmdUI);
  459.  
  460.     if(!IsEditFrame() && PREF_PrefIsLocked("browser.chrome.show_url_bar"))
  461.         pCmdUI->Enable(FALSE);
  462. }
  463.  
  464. void CMainFrame::OnUpdateViewCustomToolbar(CCmdUI *pCmdUI)
  465. {
  466.     CGenericFrame::OnUpdateViewCustomToolbar(pCmdUI);
  467.  
  468.     if(!IsEditFrame() && PREF_PrefIsLocked("browser.chrome.show_directory_buttons"))
  469.         pCmdUI->Enable(FALSE);
  470. }
  471.  
  472. BOOL CMainFrame::OnCommand(UINT wParam,LONG lParam)
  473. {
  474.     if(CGenericFrame::OnCommand(wParam, lParam))
  475.     return TRUE;
  476.  
  477.     // Extract the command ID
  478.     UINT nID = LOWORD(wParam);
  479.     
  480.     // IS it a command or a menu?
  481.     if ((nID == 0) || (LOWORD(lParam) != 0)) {
  482.         // Menu IDs cannot be 0
  483.         // For menus, the low-order word of lParam is zero
  484.         return FALSE;
  485.     }
  486.       
  487.     // See if it was one of the items in the history list  
  488.     if (IS_HISTORY_ID(nID) && GetMainContext()) {
  489.         // Make sure the command ID is consistent with the last
  490.         // selected menu item
  491.         histBuilder.Execute(nID);
  492.  
  493.         return TRUE;
  494.     }
  495.     if (IS_SHORTCUT_ID(nID) && GetMainContext()) {
  496.         LoadShortcut(nID-FIRST_SHORTCUT_ID);
  497.     }
  498.                    
  499.     return FALSE;  // no obe wanted it
  500. }
  501.  
  502. void CMainFrame::OnInitMenuPopup(CMenu* pPopup, UINT nIndex, BOOL bSysMenu) 
  503. {
  504.     AfxLockTempMaps();
  505.  
  506.     CGenericFrame::OnInitMenuPopup(pPopup,nIndex,bSysMenu);
  507.       
  508.     if (!bSysMenu && pPopup) {
  509.         // if it contains Back has the first item and nIndex is not 0 then
  510.         // fill in the menu.  nIndex would be 0 if it's a popup or if
  511.         // it's the first menu in the system 
  512.         if (pPopup->GetMenuItemID(0) == ID_NAVIGATE_BACK && nIndex != 0){
  513.         // We need to check whether we have already built the menu.
  514.         // Even though we destroy the menu items each time the menus go away,
  515.         // this only happens when the user is all done with the menu bar and
  516.         // not when each individual pop-up menu is dismissed
  517.             if (pPopup->GetMenuState(FIRST_HISTORY_MENU_ID, MF_BYCOMMAND) == (UINT)-1)
  518.                 BuildHistoryMenu(pPopup);
  519.         }
  520.     }
  521.  
  522.     // This function must always be executed, so please, do NOT put any
  523.     // return statements in the above code!
  524.     AfxUnlockTempMaps();
  525. }
  526.  
  527. void CMainFrame::GetMessageString( UINT nID, CString& rMessage ) const
  528. {
  529.     // See if it's a history entry
  530.     if (nID >= FIRST_HISTORY_MENU_ID && nID <= LAST_HISTORY_MENU_ID) {
  531.         rMessage = histBuilder.GetURL(nID);
  532.         if (rMessage.IsEmpty())
  533.         {
  534.             ASSERT(FALSE);
  535.         }
  536.     } else {
  537.         CGenericFrame::GetMessageString( nID, rMessage );
  538.     }
  539. }
  540.  
  541. void CMainFrame::OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu)
  542. {
  543.     if (nFlags == 0xFFFF) {
  544.         HMENU hMenu = ::GetMenu(m_hWnd);
  545.  
  546.         // Not all top-level windows have a menu bar (e.g. the chromeless ones)
  547.         // Also, Editor frame doesn't have these submenus
  548.         if (hMenu && !IsEditFrame() ) {
  549.             int     nCount;
  550.             UINT    nCmdID;
  551.  
  552.             // Menu is going away so destroy all the menu items we 
  553.     
  554.             // Now cleanup the history menu. We don't need to make any assumptions
  555.             // about the number of menu items, because there are no separators or
  556.             // pull-right sub-menus so we can tell by looking at the command IDs
  557.             HMENU   hPopupMenu = FEU_FindSubmenu(hMenu, ID_NAVIGATE_BACK);
  558.     
  559.             if (hPopupMenu) {                
  560.                 ASSERT(hPopupMenu);
  561.                 nCount = ::GetMenuItemCount(hPopupMenu);
  562.         
  563.                 // It's easiest to do this by walking backwards over the menu items
  564.                 for (int i = nCount - 1; i >= 0; i--) {
  565.                     nCmdID = ::GetMenuItemID(hPopupMenu, i);
  566.         
  567.                     if (IS_HISTORY_ID(nCmdID))
  568.                         VERIFY(::DeleteMenu(hPopupMenu, i, MF_BYPOSITION));
  569.                 }
  570.             }
  571.         }
  572.     }
  573.  
  574.     CGenericFrame::OnMenuSelect(nItemID, nFlags, hSysMenu);
  575. }
  576.  
  577. void CMainFrame::BuildHistoryMenu(CMenu * pMenu) 
  578. {
  579.     ASSERT_VALID(pMenu);
  580.     if (!pMenu)
  581.         return;
  582.  
  583.     histBuilder.Fill(pMenu->m_hMenu, MAX_MENU_ITEM_LENGTH, eFILLALL);
  584. }
  585.  
  586. LRESULT CMainFrame::OnButtonMenuOpen(WPARAM wParam, LPARAM lParam)
  587. {
  588.     HMENU hMenu = (HMENU) lParam;
  589.     UINT nCommand = (UINT) LOWORD(wParam);
  590.  
  591.     if(nCommand == ID_NAVIGATE_BACK) 
  592.     {
  593.         histBuilder.Fill(hMenu, MAX_MENU_ITEM_LENGTH, eFILLBACKWARD);
  594.     }
  595.     else if(nCommand == ID_NAVIGATE_FORWARD)
  596.     {
  597.  
  598.         histBuilder.Fill(hMenu, MAX_MENU_ITEM_LENGTH, eFILLFORWARD);
  599.     }
  600.     else if(nCommand == ID_PLACES)
  601.     {
  602.         FillPlacesMenu(hMenu);
  603.     }
  604.  
  605.     return 1;
  606. }
  607.  
  608. void CMainFrame::FillPlacesMenu(HMENU hMenu)
  609. {
  610.     CString str;
  611.     int bOK = PREF_NOERROR;
  612.     char * label;
  613.  
  614.     for(int i = 0; bOK == PREF_NOERROR ; i++)
  615.     {
  616.         bOK = PREF_CopyIndexConfigString("toolbar.places.item",i,"label",&label);
  617.         if (bOK == PREF_NOERROR && label && label[0]) {
  618.             if (!strcmp(label,"-"))
  619.                 AppendMenu(hMenu, MF_SEPARATOR, FIRST_SHORTCUT_ID+i, "");
  620.             else
  621.                 AppendMenu(hMenu, MF_STRING, FIRST_SHORTCUT_ID+i, label);
  622.             XP_FREE(label);
  623.         }
  624.     }
  625.  
  626. }
  627.  
  628. //lpttt->szText can only hold 80 characters
  629. #define MAX_TOOLTIP_CHARS 79
  630. //status can only hold 1000 characters 
  631. #define MAX_STATUS_CHARS 999
  632.  
  633. LRESULT CMainFrame::OnFillInToolTip(WPARAM wParam, LPARAM lParam)
  634. {
  635.     HWND hwnd = (HWND)wParam;
  636.     LPTOOLTIPTEXT lpttt = (LPTOOLTIPTEXT) lParam;
  637.  
  638.     CToolbarButton *pButton = (CToolbarButton *)CWnd::FromHandle(hwnd);
  639.     UINT nCommand = pButton->GetButtonCommand();
  640.     const char * pTipText = pButton->GetToolTipText();
  641.     const char * pText = NULL;
  642.     if(nCommand == ID_NAVIGATE_BACK || nCommand == ID_NAVIGATE_FORWARD) 
  643.     {
  644.         pText = FindHistoryToolTipText(nCommand);
  645.     }
  646.     else if(nCommand == ID_GO_HOME)
  647.     {
  648.         pText = theApp.m_pHomePage;
  649.     }
  650.     else if(nCommand == ID_FILE_PRINT)
  651.     {
  652.         if(GetActiveWinContext() && GetActiveWinContext()->IsGridCell())
  653.             pText = szLoadString(ID_PRINT_FRAME_SELECTED);
  654.         else if(GetMainContext() && GetMainContext()->IsGridParent())
  655.             pText = szLoadString(ID_PRINT_FRAME_NOSELECTION);
  656.         else
  657.             pText = szLoadString(ID_PRINT_PAGE);
  658.  
  659.     }
  660.     if(pText == NULL || XP_STRCMP(pText, "") == 0)
  661.         strncpy(lpttt->szText, pTipText, MAX_TOOLTIP_CHARS);
  662.     else
  663.         strncpy(lpttt->szText, pText, MAX_TOOLTIP_CHARS);
  664.  
  665.     return 1;
  666. }
  667.  
  668. LRESULT CMainFrame::OnFillInToolbarButtonStatus(WPARAM wParam, LPARAM lParam)
  669. {
  670.     UINT nCommand = LOWORD(wParam);
  671.     char *pStatus = (char*)lParam;
  672.  
  673.     if(nCommand == ID_FILE_PRINT)
  674.     {
  675.         if(GetActiveWinContext() && GetActiveWinContext()->IsGridCell())
  676.             strncpy(pStatus, szLoadString(ID_PRINT_FRAME_SELECTED), MAX_STATUS_CHARS);
  677.         else if(GetMainContext() && GetMainContext()->IsGridParent())
  678.             strncpy(pStatus, szLoadString(ID_PRINT_FRAME_NOSELECTION), MAX_STATUS_CHARS);
  679.         else
  680.             strncpy(pStatus, szLoadString(ID_PRINT_PAGE), MAX_STATUS_CHARS);
  681.     }
  682.     return 1;
  683. }
  684.  
  685. void CMainFrame::OnIncreaseFont()
  686. {
  687.     CGenericFrame::OnIncreaseFont();
  688. }
  689.  
  690. void CMainFrame::OnDecreaseFont()
  691. {
  692.     CGenericFrame::OnDecreaseFont();
  693. }
  694.  
  695. const char *CMainFrame::FindHistoryToolTipText(UINT nCommand)
  696. {
  697.  
  698.         CGenericFrame * pFrame = (CGenericFrame * )FEU_GetLastActiveFrame();
  699.  
  700.         if(!pFrame)
  701.             return NULL;
  702.  
  703.         CAbstractCX * pCX = pFrame->GetMainContext();
  704.         
  705.         if (!pCX)
  706.             return NULL;
  707.  
  708.  
  709.         // Get the session history list
  710.         XP_List* pList = SHIST_GetList(pCX->GetContext());
  711.  
  712.         // Get the pointer to the current history entry
  713.         History_entry*  pCurrentDoc = pCX->GetContext()->hist.cur_doc_ptr;
  714.  
  715.         XP_List *pCurrentNode = XP_ListFindObject(pList, pCurrentDoc);
  716.  
  717.         if (!pCurrentNode)
  718.             return NULL;
  719.         
  720.         XP_List *pNode = NULL;
  721.  
  722.         if(nCommand == ID_NAVIGATE_FORWARD)
  723.         {
  724.             pNode = pCurrentNode->next;
  725.         }
  726.         else if(nCommand == ID_NAVIGATE_BACK)
  727.         {
  728.             pNode = pCurrentNode->prev;
  729.         }
  730.         
  731.         if(pNode == NULL)
  732.             return NULL;
  733.  
  734.         History_entry * pEntry = (History_entry*)pNode->object;
  735.         //if the page has no title, then the url is in the title field
  736.         return pEntry->title;
  737. }
  738.  
  739. void CMainFrame::OnFlushCache()
  740. {
  741.   FE_FlushCache();
  742. }
  743.  
  744. void CMainFrame::OnOptionsViewToolBar()
  745. {
  746.     LPNSTOOLBAR pIToolBar = NULL;
  747.     GetChrome()->QueryInterface(IID_INSToolBar, (LPVOID *) &pIToolBar );
  748.     if ( pIToolBar && pIToolBar->GetHWnd() ) {
  749.         if (::IsWindowVisible( pIToolBar->GetHWnd()) ) {
  750.            m_bShowToolbar = FALSE;
  751.         } else {
  752.            m_bShowToolbar = TRUE;
  753.         }
  754.         pIToolBar->Show( m_bShowToolbar );
  755.         pIToolBar->Release();
  756.     }
  757. }
  758.  
  759. void CMainFrame::OnHelpMenu()
  760. {
  761.     CGenericFrame::OnHelpMenu();
  762. }
  763.  
  764. //
  765. // Toggle the starter bar
  766. //
  767. void CMainFrame::OnOptionsShowstarterbuttons()
  768. {
  769. }
  770.  
  771. void CMainFrame::OnUpdateOptionsShowstarterbuttons(CCmdUI* pCmdUI)
  772. {
  773. }
  774.  
  775. //  Post a close message on the approprate system command, can't let
  776. //    it handle or we GPF when closing the minimized main window.
  777. void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)  
  778. {
  779.     if(nID == SC_CLOSE) {
  780.         PostMessage(WM_CLOSE);
  781.         return;
  782.     }
  783.       
  784.     CGenericFrame::OnSysCommand(nID, lParam);
  785. }
  786.  
  787.  
  788. // No meaning in generic frame windows?
  789. // The only possible thing to undo is typing in the URL/Location edit field
  790. void CMainFrame::OnUpdateEditUndo(CCmdUI* pCmdUI) 
  791. {
  792.     pCmdUI->Enable(FALSE);
  793. }
  794.