home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / genchrom.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  27.8 KB  |  1,163 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. #include "stdafx.h"
  20. #include "widgetry.h"
  21. #include "genchrom.h"
  22. #include "toolbar.cpp"
  23. #include "prefapi.h"
  24. #include "navfram.h"
  25.  
  26. #include "wfedde.h" //JOKI
  27.  
  28. #define MAIN_PICT_HEIGHT   21
  29. #define MAIN_PICT_WIDTH    23
  30.  
  31. static SIZE sizeBitmapDefault = { 23, 21 };
  32.  
  33. // these button sizes INCLUDE HIGHLIGHT_WIDTH on each edge
  34. static SIZE sizeNoviceButton = { 50, 40 };
  35. // according to CToolBar::SetSizes(): "button must be big enough
  36. // to hold image + 3 pixels on each side"
  37. static SIZE sizeAdvancedButton = { 30, 27 };
  38.  
  39. /////////////////////////////////////////////////////////////////////
  40. // CGenericToolBar
  41.  
  42. CGenericToolBar::CGenericToolBar( LPUNKNOWN pOuterUnk )
  43. {
  44.     m_ulRefCount = 0;
  45.     m_pOuterUnk = pOuterUnk;
  46.     m_nBitmapID = 0;
  47.     m_pCommandToolbar = NULL;
  48. }
  49.  
  50. CGenericToolBar::~CGenericToolBar()
  51. {
  52.     if(m_pCommandToolbar)
  53.         delete m_pCommandToolbar;
  54. }
  55.  
  56. STDMETHODIMP CGenericToolBar::QueryInterface(REFIID refiid, LPVOID * ppv)
  57. {
  58.     if ( m_pOuterUnk )
  59.         return m_pOuterUnk->QueryInterface(refiid, ppv);
  60.     else {
  61.         *ppv = NULL;
  62.         if (IsEqualIID(refiid,IID_IUnknown))
  63.                *ppv = (LPUNKNOWN) (LPNSTOOLBAR) this;
  64.         else if (IsEqualIID(refiid, IID_INSToolBar))
  65.             *ppv = (LPNSTOOLBAR) this;
  66.         else if (IsEqualIID(refiid, IID_INSAnimation))
  67.             *ppv = (LPNSANIMATION) this;
  68.  
  69.         if (*ppv != NULL) {
  70.                AddRef();
  71.             return NOERROR;
  72.         }
  73.             
  74.         return ResultFromScode(E_NOINTERFACE);
  75.     }
  76. }
  77.  
  78. STDMETHODIMP_(ULONG) CGenericToolBar::AddRef(void)
  79. {
  80.     if ( m_pOuterUnk )
  81.         return m_pOuterUnk->AddRef();
  82.     else
  83.         return ++m_ulRefCount;
  84. }
  85.  
  86. STDMETHODIMP_(ULONG) CGenericToolBar::Release(void)
  87. {
  88.     if ( m_pOuterUnk )
  89.         return m_pOuterUnk->Release();
  90.     else {
  91.         ULONG ulRef = --m_ulRefCount;
  92.         if (m_ulRefCount == 0) {
  93.             delete this;       
  94.         }
  95.         return ulRef;
  96.     }
  97. }
  98.  
  99. int CGenericToolBar::Create( CFrameWnd *pParent, 
  100.                              DWORD dwStyle, 
  101.                              UINT nID )
  102. {
  103. #ifdef WIN32
  104.     dwStyle |= CBRS_TOOLTIPS | CBRS_FLYBY;
  105. #endif
  106.  
  107. //    int res =  m_barTool.Create( pParent, dwStyle, nID );
  108. //    if ( res == -1 ) {
  109. //        return res;
  110. //    }
  111.  
  112.     m_pCommandToolbar = new CCommandToolbar(20, theApp.m_pToolbarStyle, 43, 27, 27);
  113.  
  114.     int res = m_pCommandToolbar->Create(pParent);
  115.     
  116.  
  117.     if(res)
  118.     {
  119.         m_pCommandToolbar->ShowWindow(SW_SHOW);
  120.         //m_barTool.SetToolbar(m_pCommandToolbar);
  121.     }
  122.     pParent->RecalcLayout();
  123.     return res;
  124. }
  125.  
  126. void CGenericToolBar::SetSizes( SIZE sizeButton, 
  127.                                 SIZE sizeImage )
  128. {
  129.         m_pCommandToolbar->SetBitmapSize(sizeImage.cx, sizeImage.cy);
  130. }
  131.  
  132. void CGenericToolBar::SetButtons( const UINT *lpIDArray,
  133.                                   int nIDCount, UINT nBitmapID )
  134. {
  135.     m_pCommandToolbar->RemoveAllButtons();
  136.  
  137.     if(nBitmapID != 0)
  138.     {
  139.         m_nBitmapID = nBitmapID;
  140.         m_pCommandToolbar->SetBitmap(nBitmapID);
  141.     }
  142.  
  143.     HBITMAP hBitmap = m_pCommandToolbar->GetBitmap();
  144.  
  145.     for(int i = 0; i < nIDCount; i++)
  146.     {
  147.         CCommandToolbarButton *pButton = new CCommandToolbarButton;
  148.  
  149.         CString statusStr, toolTipStr, textStr;
  150.  
  151.         WFE_ParseButtonString(lpIDArray[i], statusStr, toolTipStr, textStr);
  152.  
  153.         pButton->Create(m_pCommandToolbar, theApp.m_pToolbarStyle,
  154.                         CSize(sizeNoviceButton.cx , sizeNoviceButton.cy), 
  155.                         CSize(sizeAdvancedButton.cx, sizeAdvancedButton.cy),(const char*)textStr,
  156.                         (const char *)toolTipStr, (const char *)statusStr, m_nBitmapID, i,
  157.                         CSize(sizeBitmapDefault.cx , sizeBitmapDefault.cy), lpIDArray[i], SHOW_ALL_CHARACTERS);
  158.  
  159.  
  160.         if(hBitmap != NULL)
  161.             pButton->SetBitmap(hBitmap, TRUE);
  162.  
  163.         m_pCommandToolbar->AddButton(pButton);
  164.     }
  165. //    m_barTool.PlaceToolbar();
  166. }
  167.     
  168. void CGenericToolBar::SetButtonStyle( UINT nIDButtonCommand, DWORD dwButtonStyle )
  169. {
  170.     CToolbarButton * pButton = m_pCommandToolbar->GetButton(nIDButtonCommand);
  171.     if( pButton ){
  172.         pButton->SetStyle(dwButtonStyle);
  173.     }
  174. }
  175.  
  176. void CGenericToolBar::GetButtonRect( UINT nIDButtonCommand, RECT * pRect)
  177. {
  178.     CToolbarButton * pButton = m_pCommandToolbar->GetButton(nIDButtonCommand);
  179.     if( pButton ){
  180.         pButton->GetWindowRect(pRect);
  181.     }
  182. }
  183.  
  184. void CGenericToolBar::AddButton( CToolbarButton *pButton, int index )
  185. {
  186.     m_pCommandToolbar->AddButton( pButton, index );
  187. }
  188.  
  189. void CGenericToolBar::RemoveAllButtons()
  190. {
  191.     m_pCommandToolbar->RemoveAllButtons( );
  192. }
  193.  
  194. CToolbarButton *CGenericToolBar::RemoveButton( int index )
  195. {
  196.     return m_pCommandToolbar->RemoveButton( index );
  197. }
  198.  
  199. BOOL CGenericToolBar::LoadBitmap( LPCSTR lpszResourceName )
  200. {
  201. //    return m_barTool.LoadBitmap( lpszResourceName );
  202.     m_nBitmapID = (UINT) LOWORD(lpszResourceName);
  203.  
  204.     m_pCommandToolbar->SetBitmap(m_nBitmapID);
  205.  
  206.     int nCount = m_pCommandToolbar->GetNumButtons();
  207.  
  208.     for(int i = 0; i < nCount; i++)
  209.     {
  210.         m_pCommandToolbar->GetNthButton(i)->ReplaceBitmap(m_pCommandToolbar->GetBitmap(), i, TRUE);
  211.     }
  212.  
  213.     return 1;
  214. }
  215.  
  216. void CGenericToolBar::SetToolbarStyle( int nToolbarStyle )
  217. {
  218.     if(m_pCommandToolbar)
  219.     {
  220.         m_pCommandToolbar->SetToolbarStyle(nToolbarStyle);
  221.         m_pCommandToolbar->GetParentFrame()->RecalcLayout();
  222.     //    m_barTool.RedrawWindow();
  223.     }
  224. }
  225.  
  226. void CGenericToolBar::Show( BOOL bShow )
  227. {
  228.     if(m_pCommandToolbar)
  229.         m_pCommandToolbar->ShowWindow( bShow ? SW_SHOW : SW_HIDE );
  230. }
  231.  
  232. void CGenericToolBar::SetButtonsSameWidth(BOOL bSameWidth)
  233. {
  234.     if(m_pCommandToolbar)
  235.         m_pCommandToolbar->SetButtonsSameWidth(bSameWidth);
  236. }
  237.  
  238. HWND CGenericToolBar::GetHWnd()
  239. {
  240.     if(m_pCommandToolbar){
  241.         return m_pCommandToolbar->m_hWnd;
  242.     }
  243.     return (HWND)0;
  244. }
  245.  
  246. void CGenericToolBar::StartAnimation( )
  247. {
  248. //    m_barTool.StartAnimation( );
  249. }
  250.  
  251. void CGenericToolBar::StopAnimation( )
  252. {
  253. //    m_barTool.StopAnimation( );
  254. }
  255.  
  256. /////////////////////////////////////////////////////////////////////
  257. // CGenericStatusBar
  258.  
  259. class CModalStatus: public CDialog {
  260. protected:
  261.  
  262.     CProgressMeter m_progressMeter;
  263.     UINT m_idTimer;
  264.     BOOL m_bInModal;
  265.  
  266.     enum { IDD = IDD_NEWMAIL };
  267.  
  268.     virtual BOOL OnInitDialog();
  269.     virtual void OnCancel( );
  270.  
  271.     afx_msg void OnTimer( UINT nIDEvent );
  272.     afx_msg void OnDestroy();
  273.     DECLARE_MESSAGE_MAP()
  274.  
  275. public:
  276.     CModalStatus();
  277.     ~CModalStatus( );
  278.  
  279.     BOOL Create( CWnd *pParentWnd, UINT uDelay );
  280.  
  281.     void SetPercentDone( int iPercent );
  282.     void SetStatusText( LPCTSTR lpszStatus );
  283.     void ProgressComplete();
  284. };
  285.  
  286. CModalStatus::CModalStatus()
  287. {
  288.     m_idTimer = 0;
  289.     m_bInModal = FALSE;
  290. }
  291.  
  292. CModalStatus::~CModalStatus( )
  293. {
  294. }
  295.  
  296. BOOL CModalStatus::Create( CWnd *pParentWnd, UINT uDelay )
  297. {
  298.     BOOL res = CDialog::Create( IDD, pParentWnd );
  299.  
  300.     if ( res ) {
  301.         m_idTimer = SetTimer( 1, uDelay, NULL );
  302.     }
  303.     return res;
  304. }
  305.  
  306. BOOL CModalStatus::OnInitDialog( )
  307. {
  308.     CDialog::OnInitDialog();
  309.  
  310.     SetWindowText(szLoadString(IDS_PROGRESS));
  311.  
  312.     m_progressMeter.SubclassDlgItem( IDC_PROGRESS, this );
  313.  
  314.     return FALSE;
  315. }
  316.  
  317. void CModalStatus::OnCancel()
  318. {
  319.     GetParentFrame()->PostMessage( WM_COMMAND, (WPARAM) ID_NAVIGATE_INTERRUPT, (LPARAM) 0 );
  320. }
  321.  
  322. BEGIN_MESSAGE_MAP(CModalStatus, CDialog)
  323.     ON_WM_TIMER()
  324.     ON_WM_DESTROY()
  325. END_MESSAGE_MAP()
  326.  
  327. void CModalStatus::OnTimer( UINT nIDEvent )
  328. {
  329.     KillTimer( m_idTimer );
  330.     m_idTimer = 0;
  331.  
  332.     m_bInModal = TRUE;
  333.     CWnd* pParentWnd = GetParentFrame();
  334.     pParentWnd->EnableWindow(FALSE);
  335.     ShowWindow(SW_SHOW);
  336.     EnableWindow(TRUE);
  337.     UpdateWindow();
  338. }
  339.  
  340. void CModalStatus::OnDestroy()
  341. {
  342.     if (m_idTimer) {
  343.         KillTimer( m_idTimer );
  344.         m_idTimer = 0;
  345.     }
  346. }
  347.  
  348. void CModalStatus::SetStatusText( LPCTSTR lpszStatus )
  349. {
  350.     CWnd *widget = GetDlgItem( IDC_STATIC1 );
  351.     widget->SetWindowText( lpszStatus );
  352. }
  353.  
  354. void CModalStatus::SetPercentDone( int iPercent )
  355. {
  356.     CWnd *widget = GetDlgItem( IDC_STATIC2 );
  357.     CString cs;
  358.     cs.Format("%d%%", iPercent);
  359.     widget->SetWindowText(cs);
  360.  
  361.     m_progressMeter.StepItTo( iPercent );
  362. }
  363.  
  364. void CModalStatus::ProgressComplete()
  365. {
  366.     if (m_bInModal) {
  367.          CWnd* pParentWnd = GetParentFrame();
  368.         pParentWnd->EnableWindow(TRUE);
  369.         if (::GetActiveWindow() == m_hWnd)
  370.             pParentWnd->SetActiveWindow();
  371.         m_bInModal = FALSE;
  372.         DestroyWindow();
  373.     } else {
  374.         DestroyWindow();
  375.     }
  376. }
  377.  
  378. CGenericStatusBar::CGenericStatusBar( LPUNKNOWN pOuterUnk )
  379. {
  380.     m_ulRefCount = 0;
  381.     
  382.     m_pOuterUnk = pOuterUnk;
  383.     m_pStatusBar = NULL;
  384.     m_pCreatedBar = NULL;
  385.     
  386.     m_bModal = FALSE;
  387.     m_pModalStatus = NULL;
  388.  
  389.     m_iProg = 0;
  390. }
  391.  
  392. CGenericStatusBar::~CGenericStatusBar()
  393. {
  394.     //## NOTE: If we instantiate the status bar on the heap (via new), it is auto-deleted.
  395. }
  396.  
  397. STDMETHODIMP CGenericStatusBar::QueryInterface(REFIID refiid, LPVOID * ppv)
  398. {
  399.     if ( m_pOuterUnk )
  400.         return m_pOuterUnk->QueryInterface(refiid, ppv);
  401.     else {
  402.         *ppv = NULL;
  403.         if (IsEqualIID(refiid,IID_IUnknown))
  404.                *ppv = (LPUNKNOWN) this;
  405.         else if (IsEqualIID(refiid, IID_INSStatusBar))
  406.             *ppv = (LPNSSTATUSBAR) this;
  407.  
  408.         if (*ppv != NULL) {
  409.                AddRef();
  410.             return NOERROR;
  411.         }
  412.             
  413.         return ResultFromScode(E_NOINTERFACE);
  414.     }
  415. }
  416.  
  417. STDMETHODIMP_(ULONG) CGenericStatusBar::AddRef(void)
  418. {
  419.     if ( m_pOuterUnk )
  420.         return m_pOuterUnk->AddRef();
  421.     else
  422.         return ++m_ulRefCount;
  423. }
  424.  
  425. STDMETHODIMP_(ULONG) CGenericStatusBar::Release(void)
  426. {
  427.     if ( m_pOuterUnk )
  428.         return m_pOuterUnk->Release();
  429.     else {
  430.         ULONG ulRef = --m_ulRefCount;
  431.         if (m_ulRefCount == 0) {
  432.             delete this;       
  433.         }
  434.         return ulRef;
  435.     }
  436. }
  437.  
  438. CNetscapeStatusBar *CGenericStatusBar::GetNetscapeStatusBar()
  439. {
  440.     return m_pStatusBar;
  441. }
  442.  
  443. BOOL CGenericStatusBar::Create( CWnd* pParentWnd, DWORD dwStyle, UINT nID, BOOL bSecurityStatus /*=TRUE*/, BOOL bTaskbar /*=TRUE*/ )
  444. {
  445.     m_pCreatedBar = new CNetscapeStatusBar;
  446.  
  447.     if( !m_pCreatedBar->Create( pParentWnd, bSecurityStatus, bTaskbar ) )
  448.     {
  449.         delete m_pCreatedBar;
  450.         m_pCreatedBar = NULL;
  451.  
  452.         TRACE("Failed to create status bar\n");
  453.  
  454.         return FALSE;      // fail to create
  455.     }
  456.  
  457.     m_pStatusBar = m_pCreatedBar;
  458.     m_pStatusBar->m_bAutoDelete = TRUE;
  459.  
  460.     m_pStatusBar->GetParentFrame()->RecalcLayout();
  461.  
  462.     return TRUE;
  463. }
  464.  
  465. void CGenericStatusBar::Attach( CNetscapeStatusBar *pBar )
  466. {
  467.     m_pStatusBar = pBar;
  468. }
  469.  
  470. void CGenericStatusBar::Show(BOOL bShow)
  471. {
  472.     if ( m_pStatusBar ) {
  473.         m_pStatusBar->ShowWindow( bShow ? SW_SHOW : SW_HIDE);
  474.         m_pStatusBar->GetParentFrame()->RecalcLayout();
  475.     }
  476. }
  477.  
  478. void CGenericStatusBar::ModalStatus( BOOL bModal, UINT uDelay, char * pszTitle )
  479. {
  480.     if ( bModal != m_bModal ) {
  481.         m_bModal = bModal;
  482.         if ( bModal ) {
  483.             if (!m_pModalStatus && m_pStatusBar ) {
  484.                 m_pModalStatus = new CModalStatus;
  485.                 m_pModalStatus->Create( m_pStatusBar->GetParentFrame(), uDelay );
  486.             if (pszTitle)
  487.                m_pModalStatus->SetWindowText(pszTitle);
  488.             }
  489.         } else {
  490.             if ( m_pModalStatus ) {
  491.                 m_pModalStatus->ProgressComplete();
  492.                 m_pModalStatus = NULL;
  493.             }
  494.         }
  495.         SetStatusText( m_csStatus );
  496.         SetProgress( m_iProg );
  497.     }
  498. }
  499.  
  500. void CGenericStatusBar::SetStatusText(const char * lpszText)
  501. {
  502.     m_csStatus = lpszText ? lpszText : "";
  503.  
  504.     if ( m_bModal ) {
  505.         if ( m_pModalStatus ) {
  506.             m_pModalStatus->SetStatusText( m_csStatus );
  507.         }
  508.     }
  509.     if ( m_pStatusBar ) {
  510.         m_pStatusBar->SetPaneText(m_pStatusBar->CommandToIndex(ID_SEPARATOR), m_csStatus);
  511.         // WHS - if we're showing status for a foreground operation,
  512.         // we need to manually repaint
  513.         m_pStatusBar->UpdateWindow();
  514.  
  515.         //    Tell ncapi people window is changing position. //JOKI
  516.         if( m_pStatusBar->m_pProxy2Frame) {
  517.             CFrameGlue *pFrame = m_pStatusBar->m_pProxy2Frame;
  518.             if(pFrame->GetMainContext() && pFrame->GetMainContext()->GetContext()->type == MWContextBrowser){
  519.                  CStatusBarChangeItem::Changing(pFrame->GetMainContext()->GetContextID(), lpszText);
  520.             }
  521.         }
  522.  
  523.     }
  524. }
  525.  
  526. const char *CGenericStatusBar::GetStatusText()
  527. {
  528.     return m_csStatus;
  529. }
  530.  
  531. void CGenericStatusBar::SetProgress(int iProg)
  532. {
  533.     m_iProg = iProg < -1 ? 0 : (iProg > 100 ? 100 : iProg);
  534.  
  535.     if ( m_bModal ) {
  536.         if ( m_pModalStatus ) {
  537.             m_pModalStatus->SetPercentDone(m_iProg);
  538.         }
  539.     }
  540.     if ( m_pStatusBar ) {
  541.         m_pStatusBar->SetPercentDone(m_iProg);    
  542.     }
  543. }
  544.  
  545. int CGenericStatusBar::GetProgress()
  546. {
  547.     return m_iProg;
  548. }
  549.  
  550. void CGenericStatusBar::ProgressComplete()
  551. {
  552.     ModalStatus( FALSE, 0, NULL );
  553. }
  554.  
  555. HWND CGenericStatusBar::GetHWnd()
  556. {
  557.     if (m_pStatusBar)
  558.         return m_pStatusBar->m_hWnd;
  559.  
  560.     return NULL;
  561. }
  562.  
  563. void CGenericStatusBar::StartAnimation()
  564. {
  565.     //
  566.     // It uses this notification as a cue to be in "Cylon" mode when progress is unspecified.
  567.     //
  568.     if( m_pStatusBar )    
  569.     {
  570.        m_pStatusBar->StartAnimation();
  571.     }
  572. }
  573.  
  574. void CGenericStatusBar::StopAnimation()
  575. {
  576.     //
  577.     // It uses this notification as a cue to end "Cylon" mode.
  578.     //
  579.     if( m_pStatusBar )    
  580.     {
  581.        m_pStatusBar->StopAnimation();
  582.     }
  583. }
  584. /////////////////////////////////////////////////////////////////////////////
  585. // CStatusBarChangeItem
  586.  
  587. //Begin JOKI
  588. CPtrList CStatusBarChangeRegistry::m_Registry;
  589.  
  590. void CStatusBarChangeItem::Changing(DWORD dwWindowID, LPCSTR lpStatusMsg)    
  591. {
  592.     POSITION rIndex = m_Registry.GetHeadPosition();
  593.     CStatusBarChangeItem *pChange;
  594.     while(rIndex != NULL)    {
  595.         pChange = (CStatusBarChangeItem *)m_Registry.GetNext(rIndex);
  596.         if(pChange->GetWindowID() == dwWindowID)    {
  597.             pChange->StatusChanging(lpStatusMsg);
  598.         }
  599.     }
  600. }
  601.  
  602. void CDDEStatusBarChangeItem::StatusChanging(LPCSTR lpStatusMsg)    
  603. {
  604.     //TRACE("----------------"); TRACE(lpStatusMsg); TRACE("\r\n");
  605.  
  606.     //    Just call the DDE implementation, it will handle the details.
  607.     if(*lpStatusMsg && *lpStatusMsg != ' ' && !IsSameAsLastMsgSent(lpStatusMsg))
  608.         CDDEWrapper::StatusBarChange(this, lpStatusMsg);
  609. }
  610.  
  611. BOOL CDDEStatusBarChangeItem::IsSameAsLastMsgSent(LPCSTR lpCurMsg)
  612. {
  613.  
  614.     if(m_csLastMsgSent.CompareNoCase(lpCurMsg) == 0)
  615.         return TRUE;
  616.     else
  617.     {
  618.         m_csLastMsgSent = lpCurMsg;
  619.         return FALSE;
  620.     }
  621. }
  622.  
  623. BOOL CDDEStatusBarChangeItem::DDERegister(CString& csServiceName, DWORD dwWindowID)    
  624. {
  625.     //    Purpose:    Register a server to monitor when a status bar msg changes
  626.  
  627.     //  Don't allow the mimimized window to be monitored.
  628.     if(dwWindowID == 0) {
  629.         return(FALSE);
  630.     }
  631.  
  632.     //    Make sure such a window exists.
  633.     CAbstractCX *pCX = CAbstractCX::FindContextByID(dwWindowID);
  634.     if(NULL == pCX)    {
  635.         return(FALSE);
  636.     }
  637.     if(pCX->GetContext()->type != MWContextBrowser)    {
  638.         return(FALSE);
  639.     }
  640.  
  641.     //    Looks like it will work.
  642.     CDDEStatusBarChangeItem *pDontCare = new CDDEStatusBarChangeItem(csServiceName, dwWindowID);
  643.     return(TRUE);
  644. }
  645.  
  646. BOOL CDDEStatusBarChangeItem::DDEUnRegister(CString& csServiceName, DWORD dwWindowID)    
  647. {
  648.     //    Purpose:    UnRegister a server to monitor when a status bar msg changes
  649.  
  650.     //    Allright, we need to go through ever entry in our registry.
  651.     POSITION rIndex = m_Registry.GetHeadPosition();
  652.     CStatusBarChangeItem *pCmp;
  653.     CDDEStatusBarChangeItem *pDelme = NULL;
  654.     while(rIndex != NULL)    {
  655.         pCmp = (CStatusBarChangeItem *)m_Registry.GetNext(rIndex);
  656.         pDelme = (CDDEStatusBarChangeItem *)pCmp;
  657.         
  658.         if(pDelme->GetServiceName() == csServiceName && pDelme->GetWindowID() == dwWindowID)    {
  659.             break;
  660.         }
  661.         pDelme = NULL;
  662.     }
  663.     
  664.     if(pDelme == NULL)    {
  665.         return(FALSE);
  666.     }
  667.     else    {
  668.         delete(pDelme);
  669.         return(TRUE);
  670.     }
  671. }
  672. //End JOKI
  673.  
  674. /////////////////////////////////////////////////////////////////////
  675. // CGenericChrome
  676.  
  677. STDMETHODIMP CGenericChrome::QueryInterface(REFIID refiid, LPVOID * ppv)
  678. {
  679.     *ppv = NULL;
  680.     if (IsEqualIID(refiid,IID_IUnknown))
  681.            *ppv = (LPUNKNOWN) this;
  682.     else if (IsEqualIID(refiid,IID_IChrome))
  683.            *ppv = (LPCHROME) this;
  684.     else if (IsEqualIID(refiid, IID_INSToolBar))
  685.         *ppv = (LPNSTOOLBAR) m_pToolBar;
  686.     else if (IsEqualIID(refiid, IID_INSAnimation))
  687.         *ppv = (LPNSANIMATION) m_pToolBar;
  688.     else if (IsEqualIID(refiid, IID_INSStatusBar))
  689.         *ppv = (LPNSSTATUSBAR) m_pStatusBar;
  690.     else if (m_pOuterUnk)
  691.         return m_pOuterUnk->QueryInterface(refiid, ppv);
  692.  
  693.     if (*ppv != NULL) {
  694.            AddRef();
  695.         return NOERROR;
  696.     }
  697.             
  698.     return ResultFromScode(E_NOINTERFACE);
  699. }
  700.  
  701. STDMETHODIMP_(ULONG) CGenericChrome::AddRef(void)
  702. {
  703.     if (m_pOuterUnk)
  704.         m_pOuterUnk->AddRef();
  705.     return ++m_ulRefCount;
  706. }
  707.  
  708. STDMETHODIMP_(ULONG) CGenericChrome::Release(void)
  709. {
  710.     ULONG ulRef;
  711. // Can't do this yet since contexts are not true
  712. // COM objectects.
  713. //    if (m_pOuterUnk)
  714. //        m_pOuterUnk->Release();
  715.  
  716.     ulRef = --m_ulRefCount;
  717.     if (m_ulRefCount == 0) {
  718.         delete this;       
  719.     }
  720.     return ulRef;       
  721. }
  722. // Menu bar stuff
  723.  
  724. void CGenericChrome::SetMenu( UINT nIDResource )
  725. {
  726.     HMENU hMenuOld = ::GetMenu(m_pParent->m_hWnd);
  727.     HMENU hMenuNew = ::LoadMenu( AfxGetResourceHandle(), 
  728.                                  MAKEINTRESOURCE(nIDResource) );
  729.     if ( hMenuNew ) {
  730.         m_pParent->m_hMenuDefault = hMenuNew;
  731.         if ( hMenuOld ) {
  732.             ::DestroyMenu( hMenuOld );
  733.         }
  734.         ::SetMenu(m_pParent->m_hWnd, hMenuNew);
  735.         ::DrawMenuBar(m_pParent->m_hWnd);
  736.     }
  737.  
  738.     HACCEL hAccelOld = m_pParent->m_hAccelTable;
  739.     HACCEL hAccelNew = ::LoadAccelerators( AfxGetResourceHandle(), 
  740.                                            MAKEINTRESOURCE(nIDResource) );
  741.     if( hAccelNew ) {
  742.         if ( hAccelOld ) {
  743.             ::FreeResource((HGLOBAL) hAccelOld);
  744.         }
  745.         m_pParent->m_hAccelTable = hAccelNew;
  746.     }
  747.  
  748. }
  749.  
  750. //#ifndef    NO_TAB_NAVIGATION 
  751. BOOL CGenericChrome::procTabNavigation( UINT nChar, UINT firstTime, UINT controlKey )
  752. {
  753.     // spaceBar will be received by child who has focus.
  754.     if( nChar != VK_TAB )
  755.         return( FALSE );
  756.  
  757.     
  758.     if( ( firstTime || m_tabFocusInChrom == TAB_FOCUS_IN_NULL)
  759.         && GetToolbarVisible(ID_LOCATION_TOOLBAR) ) {
  760.         // location bar is the first child to get the focus.
  761.         SetToolbarFocus(ID_LOCATION_TOOLBAR);
  762.         m_tabFocusInChrom = TAB_FOCUS_IN_LOCATION_BAR ;
  763.         return TRUE;
  764.     }
  765.  
  766.     // I have nothing to tab to.
  767.     m_tabFocusInChrom = TAB_FOCUS_IN_NULL;
  768.     return( FALSE );
  769. }
  770. //#endif    /* NO_TAB_NAVIGATION */
  771.  
  772. // General Toolbar functionality
  773. void CGenericChrome::ShowToolbar(UINT nToolbarID, BOOL bShow)
  774. {
  775.     if(m_pCustToolbar)
  776.         m_pCustToolbar->ShowToolbar(nToolbarID, bShow);
  777.  
  778.     if (nToolbarID == ID_PERSONAL_TOOLBAR) // Hack. Show Aurora if and only if a personal toolbar is shown.
  779.     {
  780.         if (m_pParent->IsKindOf(RUNTIME_CLASS(CGenericFrame)))
  781.         {
  782.             CGenericFrame* genFrame = (CGenericFrame*)m_pParent;
  783.             
  784.             // Create NavCenter unless bShow is FALSE... then we hide it.  HACK!
  785.             // THIS CODE WILL BE REMOVED! JUST TEMPORARILY HACKED TO PREVENT NAVCENTER
  786.             // FROM SHOWING UP EVERYWHERE!
  787.             if (!theApp.m_bInGetCriticalFiles && genFrame->AllowDocking() && 
  788.                 !theApp.m_ParentAppWindow && !theApp.m_bKioskMode)
  789.             {
  790.                 // Show the selector if the pref says we should.
  791.                 BOOL bSelVisible;
  792.                 PREF_GetBoolPref(gPrefSelectorVisible, &bSelVisible);
  793.                 if (bSelVisible && bShow)
  794.                     theApp.CreateNewNavCenter(genFrame);
  795.             }
  796.  
  797.             CNSNavFrame* navFrame = genFrame->GetDockedNavCenter();
  798.             if (navFrame && !bShow)
  799.             {
  800.                 // Destroy the Nav Center.
  801.                 navFrame->DeleteNavCenter();
  802.             }
  803.         }
  804.     }
  805. }
  806.  
  807. BOOL CGenericChrome::GetToolbarVisible(UINT nToolbarID)
  808. {
  809.     if(m_pCustToolbar)
  810.         return m_pCustToolbar->IsWindowShowing(nToolbarID);
  811.     else
  812.         return FALSE;
  813. }
  814.  
  815. CWnd *CGenericChrome::GetToolbar(UINT nToolbarID)
  816. {
  817.     if(m_pCustToolbar)
  818.         return m_pCustToolbar->GetToolbar(nToolbarID);
  819.     else
  820.         return NULL;
  821. }
  822.  
  823. void CGenericChrome::SetToolbarFocus(UINT nToolbarID)
  824. {
  825.     if(m_pCustToolbar)
  826.     {
  827.         CWnd *pToolbar = m_pCustToolbar->GetToolbar(nToolbarID);
  828.         if(pToolbar && pToolbar->IsWindowVisible())
  829.             pToolbar->SetFocus();
  830.     }
  831. }
  832.  
  833. // nPos, bOpen, and bShowing are IN/OUT parameters. Values going in are default values and values
  834. // coming out are the values from the registry or default if not in the registry.  Or if there's
  835. // another window open of the same type, the values are taken from that window.
  836. void CGenericChrome::LoadToolbarConfiguration(UINT nToolbarID, CString &csToolbarName, int32 & nPos, BOOL & bOpen, BOOL & bShowing)
  837. {
  838.  
  839.     if(m_pCustToolbar)
  840.     {
  841.         CFrameWnd *pFrame = FEU_GetLastActiveFrameByCustToolbarType(m_toolbarName, m_pParent, TRUE);
  842.  
  843.         // if there's another window of this type, copy its settings
  844.         if(pFrame && pFrame != m_pParent && pFrame->IsKindOf(RUNTIME_CLASS(CGenericFrame)))
  845.         {
  846.             CGenericFrame *pGenFrame = (CGenericFrame *)pFrame;
  847.     
  848.             CWnd *pToolbar = pGenFrame->GetChrome()->GetCustomizableToolbar()->GetToolbar(nToolbarID);
  849.  
  850.             if(pToolbar)
  851.             {
  852.                 nPos = pGenFrame->GetChrome()->GetCustomizableToolbar()->GetWindowPosition(pToolbar);
  853.                 bShowing = pGenFrame->GetChrome()->GetCustomizableToolbar()->IsWindowShowing(pToolbar);
  854.                 bOpen = !pGenFrame->GetChrome()->GetCustomizableToolbar()->IsWindowIconized(pToolbar);
  855.             }
  856.         }
  857.         // otherwise use the settings from the registry.
  858.         else
  859.         {
  860.             CString prefName = CString("custtoolbar.") + m_toolbarName;
  861.  
  862.             prefName = prefName + ".";
  863.             prefName = prefName + csToolbarName;
  864.  
  865.             int nSize = 100;
  866.             LPTSTR pBuffer = prefName.GetBuffer(nSize);
  867.             FEU_ReplaceChar(pBuffer, ' ', '_');
  868.             prefName.ReleaseBuffer();
  869.  
  870.             PREF_GetBoolPref(prefName + ".open", &bOpen);
  871.             PREF_GetIntPref(prefName + ".position", &nPos);
  872.             PREF_GetBoolPref(prefName + ".showing", &bShowing);
  873.         }
  874.     }
  875.  
  876.  
  877. }
  878.  
  879. void CGenericChrome::SaveToolbarConfiguration(UINT nToolbarID, CString &csToolbarName)
  880. {
  881.     if(m_pCustToolbar)
  882.     {
  883.         // if we aren't supposed to save, then return
  884.         if(!m_pCustToolbar->GetSaveToolbarInfo()) return;
  885.  
  886.         CString prefName = CString("custtoolbar.") + m_toolbarName;
  887.         CWnd *pToolbar = m_pCustToolbar->GetToolbar(nToolbarID);
  888.         
  889.         if(pToolbar != NULL)
  890.         {
  891.             int nPos = m_pCustToolbar->GetWindowPosition(pToolbar);
  892.             BOOL bShowing = m_pCustToolbar->IsWindowShowing(pToolbar);
  893.             BOOL bOpen = !m_pCustToolbar->IsWindowIconized(pToolbar);
  894.  
  895.             prefName = prefName + ".";
  896.             prefName = prefName + csToolbarName;
  897.  
  898.             int nSize = 100;
  899.             LPTSTR pBuffer = prefName.GetBuffer(nSize);
  900.             FEU_ReplaceChar(pBuffer, ' ', '_');
  901.             prefName.ReleaseBuffer();
  902.  
  903.             PREF_SetIntPref(prefName + ".position", nPos);
  904.             PREF_SetBoolPref(prefName + ".showing", bShowing);
  905.             PREF_SetBoolPref(prefName + ".open", bOpen);
  906.         }
  907.     }
  908. }
  909.  
  910. void CGenericChrome::SetSaveToolbarInfo(BOOL bSaveToolbarInfo)
  911. {
  912.     if(m_pCustToolbar)
  913.         m_pCustToolbar->SetSaveToolbarInfo(bSaveToolbarInfo);
  914.  
  915. }
  916.  
  917. // Animation Stuff
  918. void CGenericChrome::StartAnimation()
  919. {
  920.     LPNSANIMATION pIAnimation = NULL;
  921.     QueryInterface( IID_INSAnimation, (LPVOID *) &pIAnimation );
  922.     if (pIAnimation) {
  923.         pIAnimation->StartAnimation();
  924.         pIAnimation->Release();
  925.     }
  926.     LPNSSTATUSBAR pIStatusBar = NULL;
  927.     QueryInterface( IID_INSStatusBar, (LPVOID *) &pIStatusBar );
  928.     if ( pIStatusBar ) {
  929.         pIStatusBar->StartAnimation();
  930.         pIStatusBar->Release();
  931.     }
  932.     if(m_pCustToolbar)
  933.     {
  934.     //    CCommandToolbar * pCommandToolbar =(CCommandToolbar*)GetToolbar(ID_NAVIGATION_TOOLBAR);
  935.  
  936.     //    if(pCommandToolbar)
  937.     //        pCommandToolbar->ReplaceButton(ID_NAVIGATE_RELOAD, ID_NAVIGATE_INTERRUPT);
  938.         m_pCustToolbar->StartAnimation();
  939.     }
  940. }
  941.  
  942. void CGenericChrome::StopAnimation()
  943. {
  944.     LPNSANIMATION pIAnimation = NULL;
  945.     QueryInterface( IID_INSAnimation, (LPVOID *) &pIAnimation );
  946.     if (pIAnimation) {
  947.         pIAnimation->StopAnimation();
  948.         pIAnimation->Release();
  949.     } 
  950.  
  951.     LPNSSTATUSBAR pIStatusBar = NULL;
  952.     QueryInterface( IID_INSStatusBar, (LPVOID *) &pIStatusBar );
  953.     if ( pIStatusBar ) {
  954.         pIStatusBar->ProgressComplete();
  955.         pIStatusBar->StopAnimation();        
  956.         pIStatusBar->Release();
  957.     }
  958.  
  959.     if(m_pCustToolbar)
  960.     {
  961.     //    CCommandToolbar * pCommandToolbar =(CCommandToolbar*)GetToolbar(ID_NAVIGATION_TOOLBAR);
  962.  
  963.     //    if(pCommandToolbar)
  964.     //        pCommandToolbar->ReplaceButton(ID_NAVIGATE_INTERRUPT, ID_NAVIGATE_RELOAD);
  965.         m_pCustToolbar->StopAnimation();
  966.     }
  967. }
  968.  
  969. int CGenericChrome::CreateCustomizableToolbar(CString toolbarName, int nMaxToolbars, BOOL bHasAnimation)
  970. {
  971.     m_pCustToolbar=new CCustToolbar(nMaxToolbars);
  972.  
  973.     if(! m_pCustToolbar->Create(m_pParent, bHasAnimation))
  974.         return FALSE;
  975.  
  976.     m_pParent->RecalcLayout();
  977.     m_toolbarName = toolbarName;
  978.     return TRUE;
  979.  
  980. }
  981.  
  982. int CGenericChrome::CreateCustomizableToolbar(UINT nStringID, int nMaxToolbars, BOOL bHasAnimation)
  983. {
  984.     CString str;
  985.  
  986.     str.LoadString(nStringID);
  987.  
  988.     return CreateCustomizableToolbar(str, nMaxToolbars, bHasAnimation);
  989.  
  990. }
  991.  
  992. CString CGenericChrome::GetCustToolbarString()
  993. {
  994.     return m_toolbarName;
  995. }
  996.  
  997. void CGenericChrome::RenameCustomizableToolbar(UINT nStringID)
  998. {
  999.     m_toolbarName.LoadString(nStringID);
  1000. }
  1001.  
  1002. void CGenericChrome::FinishedAddingBrowserToolbars(void)
  1003. {
  1004.     m_pCustToolbar->FinishedAddingNewWindows();
  1005.  
  1006. }
  1007.  
  1008. void CGenericChrome::SetToolbarStyle( int nToolbarStyle )
  1009. {
  1010.     if(m_pCustToolbar != NULL)
  1011.     {
  1012.         m_pCustToolbar->SetToolbarStyle(nToolbarStyle);
  1013.     }
  1014. }
  1015.  
  1016. BOOL CGenericChrome::CustToolbarShowing(void)
  1017. {
  1018.     return m_pCustToolbar->IsWindowVisible();
  1019. }
  1020.  
  1021. void CGenericChrome::ViewCustToolbar(BOOL bShow)
  1022. {
  1023.     if( m_pCustToolbar ){
  1024.         if(bShow)
  1025.             m_pCustToolbar->ShowWindow(SW_SHOWNA);
  1026.         else
  1027.             m_pCustToolbar->ShowWindow(SW_HIDE);
  1028.  
  1029.         m_pCustToolbar->GetParentFrame()->RecalcLayout();
  1030.     }
  1031. }
  1032.  
  1033. void CGenericChrome::Customize(void)
  1034. {
  1035.  
  1036. }
  1037.  
  1038.  
  1039. CCustToolbar * CGenericChrome::GetCustomizableToolbar(void)
  1040. {
  1041.     return m_pCustToolbar;
  1042. }
  1043.  
  1044.  
  1045. void CGenericChrome::ImagesButton(BOOL bShowImagesButton)
  1046. {
  1047.  
  1048.     CCommandToolbar * pCommandToolbar =(CCommandToolbar*)GetToolbar(ID_NAVIGATION_TOOLBAR);
  1049.  
  1050.     if(pCommandToolbar)
  1051.     {
  1052.         if(bShowImagesButton)
  1053.         {
  1054.             pCommandToolbar->ShowButtonByCommand(ID_VIEW_LOADIMAGES, 5);
  1055.         }
  1056.         else
  1057.         {
  1058.             pCommandToolbar->HideButtonByCommand(ID_VIEW_LOADIMAGES);
  1059.         }
  1060.     }
  1061. }
  1062.  
  1063. //    Window Title Stuff
  1064. void CGenericChrome::SetWindowTitle(const char *lpszText)
  1065. {
  1066.     m_csWindowTitle = lpszText;
  1067.  
  1068.     CString cs;
  1069.     cs = m_csDocTitle;
  1070.     if (!m_csDocTitle.IsEmpty()) {
  1071.         cs += " - ";
  1072.     }
  1073.     cs += m_csWindowTitle;
  1074.     m_pParent->SetWindowText(cs);
  1075. }
  1076.  
  1077. void CGenericChrome::SetDocumentTitle(const char *lpszText)
  1078. {
  1079.     m_csDocTitle = lpszText;
  1080.  
  1081.     CString cs;
  1082.     cs = m_csDocTitle;
  1083.     if (!m_csDocTitle.IsEmpty()) {
  1084.         cs += " - ";
  1085.     }
  1086.     cs += m_csWindowTitle;
  1087.     m_pParent->SetWindowText(cs);
  1088. }    
  1089.  
  1090. // Constructor and Destructor
  1091. CGenericChrome::CGenericChrome( LPUNKNOWN pOuterUnk )
  1092. {
  1093.     // XXX WHS Remove this when you make sure that
  1094.     // SetWindowTitle is called in all the right
  1095.     // places.
  1096.     m_csWindowTitle = XP_AppName;
  1097.  
  1098.     m_bHasStatus = FALSE;
  1099.     m_pParent = NULL;
  1100.     m_pOuterUnk = pOuterUnk;
  1101.     m_ulRefCount = 0;
  1102.     m_pToolBar = new CGenericToolBar( (LPUNKNOWN ) this );
  1103.     m_pStatusBar = new CGenericStatusBar( (LPUNKNOWN) this );
  1104.     m_pCustToolbar = NULL;
  1105.  
  1106. //#ifndef     NO_TAB_NAVIGATION
  1107.     m_tabFocusInChrom = TAB_FOCUS_IN_NULL;        // I don't have tab focus
  1108. //#endif    /* NO_TAB_NAVIGATION */
  1109.  
  1110. }
  1111.  
  1112. CGenericChrome::~CGenericChrome()
  1113. {
  1114.     ApiApiPtr(api);
  1115.     api->RemoveInstance(this);
  1116.  
  1117.     if(m_pCustToolbar != NULL)
  1118.         delete m_pCustToolbar;
  1119.  
  1120.     delete m_pToolBar;
  1121.     
  1122.     delete m_pStatusBar;
  1123. }
  1124.  
  1125. void CGenericChrome::Initialize(CFrameWnd * pParent) 
  1126. {
  1127.     ASSERT(pParent);
  1128.     m_pParent = pParent;
  1129. }
  1130.  
  1131. //
  1132. // Class Factory
  1133.  
  1134. class CGenericChromeFactory :    public CGenericFactory
  1135. {
  1136. public:
  1137.     CGenericChromeFactory();
  1138.     ~CGenericChromeFactory();
  1139.     // IClassFactory Interface
  1140.     STDMETHODIMP            CreateInstance(LPUNKNOWN,REFIID,LPVOID*);
  1141. };
  1142.  
  1143. STDMETHODIMP CGenericChromeFactory::CreateInstance(
  1144.     LPUNKNOWN pUnkOuter,REFIID refiid, LPVOID * ppvObj)
  1145. {
  1146.     *ppvObj = NULL;
  1147.     CGenericChrome * pChrome = new CGenericChrome( pUnkOuter );
  1148.     return pChrome->QueryInterface(refiid,ppvObj);   
  1149. }
  1150.  
  1151.  
  1152. CGenericChromeFactory::CGenericChromeFactory()
  1153. {
  1154.     ApiApiPtr(api);
  1155.     api->RegisterClassFactory(APICLASS_CHROME,(LPCLASSFACTORY)this);
  1156. }
  1157.  
  1158. CGenericChromeFactory::~CGenericChromeFactory()
  1159. {
  1160. }
  1161.  
  1162. DECLARE_FACTORY(CGenericChromeFactory);
  1163.