home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / ipframe.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  21.5 KB  |  709 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. // ipframe.cpp : implementation of the CInPlaceFrame class
  20. //
  21.  
  22. #include "stdafx.h"
  23.  
  24. #include "mainfrm.h"
  25. #include "ipframe.h"
  26. #include "ssl.h"
  27. #include "srvritem.h"
  28. #include "genchrom.h"
  29. #include "quickfil.h"
  30.  
  31. #ifdef _DEBUG
  32. #undef THIS_FILE
  33. static char BASED_CODE THIS_FILE[] = __FILE__;
  34. #endif
  35. #ifdef XP_WIN32
  36. HMENU AFXAPI AfxMergeMenus(HMENU hMenuShared, HMENU hMenuSource,
  37.     LONG* lpMenuWidths, int iWidthIndex, BOOL bMergeHelpMenus = FALSE);
  38. #else
  39. void AFXAPI _AfxMergeMenus(CMenu* pMenuShared, CMenu* pMenuSource,
  40.     LONG FAR* lpMenuWidths, int iWidthIndex);
  41. #endif
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CInPlaceFrame
  45.  
  46. #ifndef _AFXDLL
  47. #undef new
  48. #endif
  49. IMPLEMENT_DYNCREATE(CInPlaceFrame, COleIPFrameWnd)
  50. #ifndef _AFXDLL
  51. #define new DEBUG_NEW
  52. #endif
  53.  
  54. BEGIN_MESSAGE_MAP(CInPlaceFrame, COleIPFrameWnd)
  55.     //{{AFX_MSG_MAP(CInPlaceFrame)
  56.     ON_WM_CREATE()
  57.     ON_WM_SETFOCUS()
  58.     ON_COMMAND(ID_HOTLIST_VIEW, OnHotlistView)
  59.     ON_REGISTERED_MESSAGE(WM_FINDREPLACE, OnFindReplace)
  60.     ON_WM_INITMENUPOPUP()
  61.     ON_WM_MENUSELECT()
  62.     ON_WM_QUERYNEWPALETTE()
  63.     ON_WM_PALETTECHANGED()
  64.     ON_COMMAND(ID_TOOLS_WEB, OnToolsWeb)
  65.     //}}AFX_MSG_MAP
  66. END_MESSAGE_MAP()
  67.  
  68. #include "toolbar.cpp"
  69.  
  70. /////////////////////////////////////////////////////////////////////////////
  71. // CInPlaceFrame construction/destruction
  72.  
  73. CInPlaceFrame::CInPlaceFrame()
  74. {
  75.     TRACE("Creating IPFrame\n");
  76.     m_pProxy2Frame = NULL;
  77.     m_bCreatedControls = FALSE;
  78.     m_bUIActive = FALSE;
  79. }
  80.  
  81. CInPlaceFrame::~CInPlaceFrame()
  82. {
  83.     TRACE("Destroying IPFrame\n");
  84.     //    Give up being the frame.
  85.     if(m_pProxy2Frame)    {
  86.         GetMainWinContext()->m_pFrame = m_pProxy2Frame;
  87.         m_pProxy2Frame->SetMainContext(GetMainContext());
  88.         m_pProxy2Frame->SetActiveContext(GetActiveContext());
  89.         CMainFrame* pFrame = (CMainFrame* )m_pProxy2Frame->GetFrameWnd();  
  90.         pFrame->Release();
  91.  
  92.     }
  93.  
  94.     //    Clear our ideas of the currently active context and main context.
  95.     //    This keeps the CFrameGlue destructor from clearing the frame pointer
  96.     //        in the context which we just reset above.
  97.     SetMainContext(NULL);
  98.     SetActiveContext(NULL);
  99. }
  100.  
  101. int CInPlaceFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  102. {
  103.     TRACE("CInPlaceFrame::OnCreate called\n");
  104.     if (COleIPFrameWnd::OnCreate(lpCreateStruct) == -1)
  105.         return -1;
  106.  
  107.     // CResizeBar implements in-place resizing.
  108.     if (!m_wndResizeBar.Create(this))
  109.     {
  110.         TRACE0("Failed to create resize bar\n");
  111.         return -1;      // fail to create
  112.     }
  113.  
  114.     // By default, it is a good idea to register a drop-target that does
  115.     //  nothing with your frame window.  This prevents drops from
  116.     //  "falling through" to a container that supports drag-drop.
  117.     m_dropTarget.Register(this);
  118.  
  119.     TRACE("Success in OnCreate\n");
  120.     return 0;
  121. }
  122.  
  123. BOOL CInPlaceFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext)    {
  124.     TRACE("CInPlaceFrame::LoadFrame called\n");
  125.  
  126.     //    Let the view know that we're the frame for the time being.
  127.     //    We'll have to handle passing along every CFrameGlue call to
  128.     //        the real frame along with handling it ourselves,
  129.     //        except GetFrameWnd().
  130.     ASSERT(pContext);
  131.     CGenericDoc *pDoc;
  132.     if(pContext)    {
  133.         ASSERT(pContext->m_pCurrentDoc);
  134.         if(pContext->m_pCurrentDoc)    {
  135.             //    Must be a CGenericDoc.
  136.             ASSERT(pContext->m_pCurrentDoc->IsKindOf(RUNTIME_CLASS(CGenericDoc)));
  137.             pDoc = (CGenericDoc *)pContext->m_pCurrentDoc;
  138.  
  139.             //    Get the context.
  140.             ASSERT(pDoc->GetContext()->IsFrameContext());
  141.             CWinCX *pCX = (CWinCX *)pDoc->GetContext();
  142.  
  143.             //    Take over being the frame.
  144.             m_pProxy2Frame = pCX->m_pFrame;
  145.             CMainFrame* pFrame = (CMainFrame* )m_pProxy2Frame->GetFrameWnd();
  146.             pFrame->AddRef();
  147. //            pCX->m_pFrame = (CFrameGlue *)this;
  148.  
  149.             //    Set our current and active context.
  150.             SetMainContext(pCX);
  151.             SetActiveContext(pCX);
  152.  
  153.             //    We'll need to unhook ourselves when we close down.
  154.         }
  155.     }
  156.     BOOL bRetVal = COleIPFrameWnd::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext);
  157.     return bRetVal;
  158.  
  159. }
  160.  
  161. /////////////////////////////////////////////////////////////////////////////
  162. // CInPlaceFrame diagnostics
  163.  
  164. #ifdef _DEBUG
  165. void CInPlaceFrame::AssertValid() const
  166. {
  167.     COleIPFrameWnd::AssertValid();
  168. }
  169.  
  170. void CInPlaceFrame::Dump(CDumpContext& dc) const
  171. {
  172.     COleIPFrameWnd::Dump(dc);
  173. }
  174. #endif //_DEBUG
  175.  
  176. /////////////////////////////////////////////////////////////////////////////
  177. // CInPlaceFrame commands
  178.  
  179. CFrameWnd *CInPlaceFrame::GetFrameWnd()    {
  180.     return((CFrameWnd *)this);
  181. }
  182.  
  183. void CInPlaceFrame::UpdateHistoryDialog()    {
  184.     //    Pass it off.
  185.     if(m_pProxy2Frame)    {
  186.         m_pProxy2Frame->UpdateHistoryDialog();
  187.     }
  188. }
  189.  
  190. // OnCreateControlBars is called by the framework to create control bars on the
  191. //  container application's windows.  pWndFrame is the top level frame window of
  192. //  the container and is always non-NULL.  pWndDoc is the doc level frame window
  193. //  and will be NULL when the container is an SDI application.  A server
  194. //  application can place MFC control bars on either window.
  195. BOOL CInPlaceFrame::OnCreateControlBars(CWnd* pWndFrame, CWnd* pWndDoc) 
  196. {
  197.     TRACE("CInPlaceFrame::OnCreateControlBars called\n");
  198.     //    Set the toolbar style.
  199. //    BOOL bCreate = m_wndToolBar.Create(pWndFrame);
  200. //    ASSERT(bCreate);
  201.     CGenericDoc* pDoc = (CGenericDoc*)GetActiveDocument( );
  202.     CNetscapeSrvrItem *pItem = pDoc->GetEmbeddedItem();
  203.     if (pItem->IsShowUI()) {
  204.  
  205.         // Now that the application palette has been created (if 
  206.         //   appropriate) we can create the url bar.  The animation 
  207.         CCustToolbar *pCustToolbar = m_pProxy2Frame->GetChrome()->GetCustomizableToolbar();
  208.         pCustToolbar->SetNewParentFrame((CFrameWnd*)pWndFrame);
  209.         pCustToolbar->SetOwner(m_pProxy2Frame->GetFrameWnd());
  210. #ifdef XP_WIN32
  211.         // this is an undocumented function that adds a control bar
  212.         // to the parent frame's control bar list. SetParent doesn't do this and
  213.         // this only occurs when the control bar is created.  Since our control bar
  214.         // was created before we knew about this parent, we miss out on the only
  215.         // opportunity to do so. So this function is called.
  216.         // This now gets taken care of in CCustToolbar.
  217.         //((CFrameWnd*)pWndFrame)->AddControlBar(pCustToolbar);
  218. #endif
  219.     //    AddBookmarksMenu();
  220.  
  221.         //   might need custom colors so we need the palette to be around
  222.         m_iShowURLBar = TRUE;
  223.         m_iShowStarterBar = TRUE;
  224.         m_iCSID = INTL_DefaultDocCharSetID(0); // Set Global default.
  225.  
  226.     //    SetBarType(m_iShowStarterBar, m_iShowURLBar);
  227.  
  228.         //    Create the security bar.
  229.     //    m_barSecurityStatus.Create(pWndFrame);
  230.     //    m_barSecurityStatus.SetOwner(this);
  231.  
  232.  
  233.         ASSERT( m_pProxy2Frame );    
  234.         LPNSSTATUSBAR pIStatusBar = NULL;
  235.         m_pProxy2Frame->GetChrome()->QueryInterface( IID_INSStatusBar, (LPVOID *) &pIStatusBar );
  236.         if( pIStatusBar ) 
  237.         {
  238.             CNetscapeStatusBar *pStatusBar = ((CGenericStatusBar *)pIStatusBar)->GetNetscapeStatusBar();
  239.             
  240.             if( !pStatusBar )
  241.             {
  242.                 pIStatusBar->Create( pWndFrame, 0, 0, TRUE, FALSE ); // No task bar
  243.             }
  244.             else
  245.             {
  246.                 pStatusBar->m_pProxy2Frame = m_pProxy2Frame;            
  247.                 
  248.                 pStatusBar->SetParent( pWndFrame );
  249.               #ifdef XP_WIN32
  250.                 ((CFrameWnd *)pWndFrame)->AddControlBar( pStatusBar );
  251.               #endif
  252.                 
  253.             }
  254.          //   pIStatusBar->Show( TRUE );            
  255.             pIStatusBar->Release();
  256.         }
  257.     
  258.         RecalcLayout();
  259.  
  260.         //    We've created the controls.
  261.         m_bCreatedControls = TRUE;
  262.     }
  263.     //  Success so far.  Also, accept drag and drop files from
  264.     //      the file manager.
  265.     //
  266.     DragAcceptFiles();
  267.     return TRUE;
  268. }
  269.  
  270. void CInPlaceFrame::ShowControlBars(CFrameWnd* pFrameWnd, BOOL bShow)
  271. {
  272.  
  273.     CCustToolbar *pCustToolbar = m_pProxy2Frame->GetChrome()->GetCustomizableToolbar();
  274.  
  275.     if(pCustToolbar)
  276.     {
  277.         if(pFrameWnd == pCustToolbar->GetParentFrame())
  278.             pCustToolbar->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
  279.     }
  280.  
  281.     LPNSSTATUSBAR pIStatusBar = NULL;
  282.     m_pProxy2Frame->GetChrome()->QueryInterface( IID_INSStatusBar, (LPVOID *) &pIStatusBar );
  283.     if( pIStatusBar ) 
  284.     {
  285.         CNetscapeStatusBar *pStatusBar = ((CGenericStatusBar *)pIStatusBar)->GetNetscapeStatusBar();
  286.  
  287.         if(pStatusBar && pFrameWnd == pStatusBar->GetParentFrame())
  288.         {
  289.             pStatusBar->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
  290.         }
  291.  
  292.         pIStatusBar->Release();
  293.     }
  294.  
  295.  
  296. }
  297.  
  298. void CInPlaceFrame::ReparentControlBars(void)
  299. {
  300.     CCustToolbar *pCustToolbar = m_pProxy2Frame->GetChrome()->GetCustomizableToolbar();
  301.  
  302.     if(pCustToolbar)
  303.     {
  304.         pCustToolbar->SetNewParentFrame(m_pProxy2Frame->GetFrameWnd());
  305.         pCustToolbar->ShowWindow(SW_SHOW);
  306.     }
  307.  
  308.  
  309.     LPNSSTATUSBAR pIStatusBar = NULL;
  310.     m_pProxy2Frame->GetChrome()->QueryInterface( IID_INSStatusBar, (LPVOID *) &pIStatusBar );
  311.     if( pIStatusBar ) 
  312.     {
  313.         CNetscapeStatusBar *pStatusBar = ((CGenericStatusBar *)pIStatusBar)->GetNetscapeStatusBar();
  314.  
  315.         if(pStatusBar)
  316.         {
  317.             pStatusBar->SetParent( m_pProxy2Frame->GetFrameWnd() );
  318. #ifdef XP_WIN32
  319.             m_pProxy2Frame->GetFrameWnd()->AddControlBar( pStatusBar );
  320. #endif
  321.             pIStatusBar->Show(TRUE);
  322.  
  323.         }
  324.         pIStatusBar->Release();
  325.     }
  326.  
  327.  
  328. }
  329.  
  330.  
  331. //JOKI
  332. void CInPlaceFrame::DestroyResizeBar()
  333. {
  334.     //I had to resort to this rather than not creating m_wndResizeBar in ::OnCreate()
  335.     // Reason : I could not get hold of GetActiveDocument(in OnCreate) which is used to get 
  336.     //the pNetscapeSrvrItem in turn used to call Get_ShowInplaceUI()
  337.     if(::IsWindow(m_wndResizeBar.m_hWnd))
  338.             m_wndResizeBar.DestroyWindow();
  339.  
  340.     RecalcLayout();
  341. }
  342.  
  343. BOOL CInPlaceFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
  344. {
  345.     //    Pump through any active child first.
  346.     //    This will catch active control bars, etc.
  347.     CWinCX *pWinCX = NULL;
  348.     CWnd *pFocus = GetFocus();
  349.     BOOL bFrameChild;
  350.  
  351.     if(pFocus != NULL)    {
  352.         //    Make sure it's a child of us, and not a CGenericView (we handle those below).
  353.         //    Also make sure it's not a child of our main view.
  354.         //        Those are handled by the view, not us.
  355.         bFrameChild = IsChild(pFocus);
  356.         BOOL bGenericView = pFocus->IsKindOf(RUNTIME_CLASS(CGenericView));
  357.         BOOL bViewChild = FALSE;
  358.         pWinCX = GetMainWinContext();
  359.         if(pWinCX && pWinCX->GetPane())    {
  360.             bViewChild = ::IsChild(pWinCX->GetPane(), pFocus->m_hWnd);
  361.         }
  362.  
  363.         if(bFrameChild == TRUE && bGenericView == FALSE && bViewChild == FALSE)    {
  364.             //    Try an OnCmdMessage, probably a URL bar, or message list.
  365.             //    Walk up the list of parents until we reach ourselves.
  366.             CWnd *pTarget = pFocus;
  367.             while(pTarget != NULL && pTarget != (CWnd *)this)    {
  368.                 if(pTarget->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))    {
  369.                     TRACE("IPFr WM_CMD:%u through CWnd:%p (control bar%s?)\n", nID, pTarget, (nCode == CN_COMMAND ? "" : " ui"));
  370.                     return(TRUE);
  371.                 }
  372.                 pTarget = pTarget->GetParent();
  373.  
  374.                 //  There are cases now where a child is actually a CGenericView
  375.                 //      such as the NavCenter HTML pane.  Do not allow it to
  376.                 //      receive these messages.
  377.                 if(pTarget->IsKindOf(RUNTIME_CLASS(CGenericView))) {
  378.                     pTarget = NULL;
  379.                 }
  380.             }
  381.         }
  382.     }
  383.     if(m_pProxy2Frame->GetFrameWnd() != NULL && (nID != ID_TOOLS_WEB)) {
  384.         if(m_pProxy2Frame->GetFrameWnd()->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
  385.             return(TRUE);
  386.     }
  387.  
  388.     // always enable bookmark entries
  389.     if((nID >= FIRST_BOOKMARK_MENU_ID) && (nID < LAST_BOOKMARK_MENU_ID) && (nCode == CN_UPDATE_COMMAND_UI))  {
  390.         ASSERT(pExtra);
  391.         CCmdUI* pCmdUI = (CCmdUI*)pExtra;
  392.         pCmdUI->Enable();
  393.         return(TRUE);
  394.     }
  395.  
  396.     // always enable windows menu entries
  397.     if((nID >= ID_WINDOW_WINDOW_0) && (nID < ID_WINDOW_WINDOW_0 + 10) && (nCode == CN_UPDATE_COMMAND_UI))  {
  398.         ASSERT(pExtra);
  399.         CCmdUI* pCmdUI = (CCmdUI*)pExtra;
  400.         pCmdUI->Enable();
  401.         return(TRUE);
  402.     }
  403.  
  404.     // was this a windows menu selection ?
  405.     if((nID >= ID_WINDOW_WINDOW_0) && (nID < ID_WINDOW_WINDOW_0 + 10) && (nCode == CN_COMMAND))  {
  406.         CGenericFrame * pFrame = theApp.m_pFrameList;
  407.  
  408.         // walk down frame list till we get to the one we wanted
  409.         while((nID >= ID_WINDOW_WINDOW_0) && (pFrame)) {
  410.  
  411.             switch(pFrame->GetMainContext()->GetContext()->type) {
  412.             case MWContextMail:
  413.             case MWContextNews:
  414.                 // these don't get added to the list so they don't count
  415.                 break;
  416.             case MWContextMessageComposition:
  417.             case MWContextBrowser:
  418.                 nID--;
  419.                 break;
  420.             default:
  421.                 // by default windows aren't added to the list
  422.                 break;
  423.             }
  424.  
  425.             // whether this window counted or not we need to move to the next one
  426.             if(pFrame && nID >= ID_WINDOW_WINDOW_0) {
  427.                 pFrame = pFrame->m_pNext;
  428.             }
  429.         }
  430.  
  431.         // if we got something un-minimize it and pop it to the front
  432.         if(pFrame) {
  433.             if(pFrame->IsIconic())  {
  434.                 pFrame->ShowWindow(SW_RESTORE);
  435.             }
  436.             pFrame->BringWindowToTop();
  437.         }
  438.  
  439.         // assume we got something or at least the message was for us
  440.         return(TRUE);
  441.     }
  442.  
  443.     //    Call the base.
  444.     //    Redundant on the view, but can't risk different implementations
  445.     //        at this time.
  446.     return COleIPFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
  447. }
  448.  
  449.  
  450.  
  451. void CInPlaceFrame::OnSetFocus(CWnd* pOldWnd) 
  452. {
  453.     COleIPFrameWnd::OnSetFocus(pOldWnd);
  454.     
  455.     //    Set ourselves on the active frame stack.
  456.     SetAsActiveFrame();
  457. }
  458.  
  459. void CInPlaceFrame::OnHotlistView() 
  460. {
  461.     // Needs to have NavCenter pop up eventually.
  462. }
  463.  
  464. BOOL CInPlaceFrame::OnCommand(WPARAM wParam, LPARAM lParam) 
  465. {
  466.     if(COleIPFrameWnd::OnCommand(wParam, lParam))    {
  467.         return(TRUE);
  468.     }
  469.  
  470.     CMainFrame *pMainFrame = (CMainFrame*)m_pProxy2Frame->GetFrameWnd();
  471.  
  472.     if(pMainFrame)
  473.         if(pMainFrame->SendMessage(WM_COMMAND, wParam, lParam))
  474.             return(TRUE);
  475.  
  476.     return(CommonCommand(wParam, lParam));
  477. }
  478.  
  479. LRESULT CInPlaceFrame::OnFindReplace(WPARAM wParam, LPARAM lParam) 
  480. {
  481.     CWinCX *pContext = GetActiveWinContext();
  482.  
  483.     if(!pContext)
  484.         pContext = GetMainWinContext();
  485.  
  486.     if(pContext && pContext->GetPane())
  487.         return(pContext->GetView()->OnFindReplace(wParam, lParam));
  488.  
  489.     return(FALSE);
  490. }
  491.  
  492.  
  493. BOOL CInPlaceFrame::BuildSharedMenu()
  494. {
  495.     CGenericDoc* pDoc = (CGenericDoc*)GetActiveDocument( );
  496.     CNetscapeSrvrItem *pItem = pDoc->GetEmbeddedItem();
  497.  
  498.     if (pItem->IsShowUI()) {
  499. #ifdef XP_WIN32
  500.         HMENU hMenu = GetInPlaceMenu();
  501. #else
  502.         // get runtime class from the doc template
  503.         CDocTemplate* pTemplate = pDoc->GetDocTemplate();
  504.         ASSERT_VALID(pTemplate);
  505.         HMENU hMenu = pTemplate->m_hMenuInPlaceServer;
  506. #endif
  507.  
  508.         // create shared menu
  509.         ASSERT(m_hSharedMenu == NULL);
  510.         if ((m_hSharedMenu = ::CreateMenu()) == NULL)
  511.             return FALSE;
  512.  
  513.         // start out by getting menu from container
  514.         memset(&m_menuWidths, 0, sizeof m_menuWidths);
  515.         if (m_lpFrame->InsertMenus(m_hSharedMenu, &m_menuWidths) != S_OK)
  516.         {
  517.             ::DestroyMenu(m_hSharedMenu);
  518.             m_hSharedMenu = NULL;
  519.             return FALSE;
  520.         }
  521.         // container shouldn't touch these
  522.         ASSERT(m_menuWidths.width[1] == 0);
  523.         ASSERT(m_menuWidths.width[3] == 0);
  524.         ASSERT(m_menuWidths.width[5] == 0);
  525.  
  526.         // only copy the popups if there is a menu loaded
  527.         if (hMenu == NULL)
  528.             return TRUE;
  529. #ifdef XP_WIN32
  530.         // insert our menu popups amongst the container menus
  531.         AfxMergeMenus(m_hSharedMenu, hMenu, &m_menuWidths.width[0], 1);
  532. #else
  533.     // insert our menu popups amongst the container menus
  534.         _AfxMergeMenus(CMenu::FromHandle(m_hSharedMenu),
  535.         CMenu::FromHandle(hMenu), &m_menuWidths.width[0], 1);
  536. #endif
  537.         // finally create the special OLE menu descriptor
  538.         m_hOleMenu = ::OleCreateMenuDescriptor(m_hSharedMenu, &m_menuWidths);
  539.         return m_hOleMenu != NULL;
  540.     }
  541.     else
  542.         return TRUE;
  543. }
  544.  
  545. void CInPlaceFrame::OnInitMenuPopup(CMenu * pPopup, UINT nIndex, BOOL bSysMenu) 
  546. {
  547.     CMainFrame *pMainFrame = (CMainFrame*)m_pProxy2Frame->GetFrameWnd();
  548.  
  549.     pMainFrame->SendMessage(WM_INITMENUPOPUP, (WPARAM)pPopup->m_hMenu, MAKELPARAM(nIndex, bSysMenu));
  550.  
  551. }
  552.  
  553. void CInPlaceFrame::OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu)
  554. {
  555.     if (nFlags == 0xFFFF) {
  556.         HMENU hMenu = m_hSharedMenu;
  557.  
  558.         // Not all top-level windows have a menu bar (e.g. the chromeless ones)
  559.         // Also, Editor frame doesn't have these submenus
  560.         if (hMenu) {
  561.             int     nCount;
  562.             UINT    nCmdID;
  563.  
  564.             // Menu is going away so destroy all the menu items we 
  565.     
  566.             // Now cleanup the history menu. We don't need to make any assumptions
  567.             // about the number of menu items, because there are no separators or
  568.             // pull-right sub-menus so we can tell by looking at the command IDs
  569.             HMENU   hPopupMenu = FEU_FindSubmenu(hMenu, ID_NAVIGATE_BACK);
  570.     
  571.             if (hPopupMenu) {                
  572.                 ASSERT(hPopupMenu);
  573.                 nCount = ::GetMenuItemCount(hPopupMenu);
  574.         
  575.                 // It's easiest to do this by walking backwards over the menu items
  576.                 for (int i = nCount - 1; i >= 0; i--) {
  577.                     nCmdID = ::GetMenuItemID(hPopupMenu, i);
  578.         
  579.                     if (IS_HISTORY_ID(nCmdID))
  580.                         VERIFY(::DeleteMenu(hPopupMenu, i, MF_BYPOSITION));
  581.                 }
  582.             }
  583.         }
  584.     }
  585.  
  586.     COleIPFrameWnd::OnMenuSelect(nItemID, nFlags, hSysMenu);
  587. }
  588.  
  589. void CInPlaceFrame::OnToolsWeb()
  590. {
  591.     CAbstractCX *pCX = FEU_GetLastActiveFrameContext(MWContextAny);
  592.     
  593.     if(pCX)
  594.         pCX->NewWindow();
  595.  
  596. }
  597.  
  598. // Replace our current bookmarks menu with the mainframe's bookmarks menu and add
  599. // Calendar and 3270 menus
  600. void CInPlaceFrame::AddBookmarksMenu(void)
  601. {
  602.  
  603.     CMenu *pMenu=GetMenu();
  604.  
  605.     //Communicator is always the second to last menu popup so adjust accordingly
  606.     int nWindowPosition = pMenu->GetMenuItemCount() - 2;
  607.  
  608.     if(nWindowPosition != -1)
  609.     {
  610.         CMenu *pWindowMenu = pMenu->GetSubMenu(nWindowPosition);
  611.  
  612.         // Check if we need to add the Calendar menu item
  613.  
  614.         if(FEU_IsCalendarAvailable())
  615.         {
  616.             int nTaskBarPosition = WFE_FindMenuItem(pWindowMenu, ID_WINDOW_TASKBAR);
  617.  
  618.             if(nTaskBarPosition != -1)
  619.                 pWindowMenu->InsertMenu(nTaskBarPosition - 1, MF_BYPOSITION, ID_WINDOW_CALENDAR, szLoadString(IDS_CALENDAR_MENU));
  620.         }
  621.  
  622.         if(FEU_IsIBMHostOnDemandAvailable())
  623.         {
  624.             int nTaskBarPosition = WFE_FindMenuItem(pWindowMenu, ID_WINDOW_TASKBAR);
  625.  
  626.             if(nTaskBarPosition != -1)
  627.                 pWindowMenu->InsertMenu(nTaskBarPosition - 1, MF_BYPOSITION, ID_WINDOW_IBMHOSTONDEMAND, szLoadString(IDS_IBMHOSTONDEMAND_MENU));
  628.         }
  629.  
  630. #ifdef XP_WIN32
  631.         // We can start or activate LiveWire SiteManager
  632.         //  if we have a registration handle
  633.         if( bSiteMgrIsRegistered ){
  634.             int nTaskBarPosition = WFE_FindMenuItem(pWindowMenu, ID_WINDOW_TASKBAR);
  635.  
  636.             if(nTaskBarPosition != -1)
  637.                 pWindowMenu->InsertMenu(nTaskBarPosition - 1, MF_BYPOSITION, ID_ACTIVATE_SITE_MANAGER, szLoadString(IDS_SITE_MANAGER));
  638.         }
  639. #endif
  640.  
  641.  
  642.         // Replace the bookmark menu with a new menu that can have ON_DRAWITEM overridden
  643.         //Bookmark is the First Popup in the Communicator Menu so loop through to find it.
  644.         int nBookmarksPosition = 0;
  645.         while(!pWindowMenu->GetSubMenu(nBookmarksPosition) && nBookmarksPosition < pWindowMenu->GetMenuItemCount())
  646.             nBookmarksPosition++;
  647.  
  648.         if(nBookmarksPosition < pWindowMenu->GetMenuItemCount())
  649.         {
  650.             CMenu *pOldBookmarksMenu = pWindowMenu->GetSubMenu(nBookmarksPosition);
  651.             char bookmarksStr[30]; 
  652.  
  653.             if(pOldBookmarksMenu)
  654.             {
  655.                 // get the mainframe's bookmark menu
  656.                 CMainFrame *pMainFrame = (CMainFrame*)m_pProxy2Frame->GetFrameWnd();
  657.  
  658.                 CTreeMenu *pBookmarksMenu = pMainFrame->GetBookmarksMenu();
  659.  
  660.                 if(pBookmarksMenu)
  661.                 {
  662.                     pWindowMenu->DeleteMenu(nBookmarksPosition, MF_BYPOSITION);
  663.                     pWindowMenu->GetMenuString(nBookmarksPosition, bookmarksStr, 30, MF_BYPOSITION);
  664.                     pWindowMenu->InsertMenu(nBookmarksPosition, MF_BYPOSITION|MF_STRING|MF_POPUP, (UINT)pBookmarksMenu->GetSafeHmenu(), bookmarksStr);
  665.                 }
  666.  
  667.             }
  668.         }
  669.  
  670.     }
  671.  
  672.  
  673.  
  674. }
  675.  
  676. BOOL CInPlaceFrame::OnQueryNewPalette() 
  677. {
  678.     CCustToolbar *pCustToolbar = m_pProxy2Frame->GetChrome()->GetCustomizableToolbar();
  679.     CWnd* parent = pCustToolbar->GetParent( );
  680.  
  681.     pCustToolbar->SendMessageToDescendants(WM_PALETTECHANGED, (WPARAM)this->GetSafeHwnd());
  682.  
  683.     return COleIPFrameWnd::OnQueryNewPalette();
  684. }
  685.  
  686. void CInPlaceFrame::OnPaletteChanged(CWnd* pFocusWnd) 
  687. {
  688.     CCustToolbar *pCustToolbar = m_pProxy2Frame->GetChrome()->GetCustomizableToolbar();
  689.     CWnd* parent = pCustToolbar->GetParent( );
  690.     pCustToolbar->SendMessageToDescendants(WM_PALETTECHANGED, (WPARAM)pFocusWnd->GetSafeHwnd());
  691.     COleIPFrameWnd::OnPaletteChanged(pFocusWnd);
  692. }
  693.  
  694.  
  695.  
  696. HMENU CInPlaceFrame::GetInPlaceMenu()
  697. {
  698.     // get active document associated with this frame window
  699.     CDocument* pDoc = GetActiveDocument();
  700.     ASSERT_VALID(pDoc);
  701.  
  702.     // get in-place menu from the doc template
  703.     CDocTemplate* pTemplate = pDoc->GetDocTemplate();
  704.     if (pTemplate)
  705.         return pTemplate->m_hMenuInPlaceServer;
  706.     else
  707.         return NULL;
  708. }
  709.