home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / statbar.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  32.2 KB  |  1,122 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. ///
  20. //
  21. // STATBAR.CPP
  22. //
  23. // DESCRIPTION:
  24. //        This file contains the implementation of the CNetscapeStatusBar
  25. //        class.
  26. //
  27. // CREATED:    03/01/96, 12:18:16        AUTHOR: Scott Jones
  28. //
  29. ///
  30.  
  31.  
  32. /**    INCLUDE    **/
  33. #include "stdafx.h"
  34. #include "statbar.h"
  35. #include "ssl.h"
  36. #include "tooltip.h"
  37. #include "secnav.h"
  38.  
  39. #ifdef _DEBUG
  40. #undef THIS_FILE
  41. static char    BASED_CODE THIS_FILE[] = __FILE__;
  42. #endif
  43.  
  44.  
  45. #ifndef DYNAMIC_DOWNCAST
  46. #define DYNAMIC_DOWNCAST( classname, ptr ) (classname *)(ptr)
  47. #endif
  48.  
  49. //------------------------------------------------------------------------------
  50. //    CONSTANTS
  51.  
  52. static const int nSEC_KEY_WIDTH = 34;
  53.  
  54. #ifdef _WIN32
  55.  static const char szNSStatusProp[] = "NSStatusProp";
  56. #else
  57.  static const char szNSStatusProp1[] = "NSStatusProp1";
  58.  static const char szNSStatusProp2[] = "NSStatusProp2"; 
  59. #endif
  60.  
  61. #define IDT_PULSE       1966  // Pulsing vapor trails timer id
  62. #define PULSE_INTERVAL   100  // Pulse interval for timer (ms)
  63.  
  64. #define IDT_STATBARMONITOR 1968
  65. #define MONITOR_INTERVAL   50
  66.  
  67. // status bar format
  68. static const UINT BASED_CODE pPaneIndicators[] =
  69. {
  70.     IDS_SECURITY_STATUS,
  71.     IDS_TRANSFER_STATUS,
  72.     ID_SEPARATOR
  73. #ifdef MOZ_TASKBAR
  74.     ,IDS_TASKBAR
  75. #endif /* MOZ_TASKBAR */
  76. };
  77.  
  78. static const UINT BASED_CODE pSimpleIndicators[] =
  79. {
  80.     ID_SEPARATOR
  81. };
  82.  
  83.  
  84.  
  85. BEGIN_MESSAGE_MAP(CNetscapeStatusBar, CNetscapeStatusBarBase)
  86.     //{{AFX_MSG_MAP(CNetscapeStatusBar)
  87.     ON_WM_PAINT()
  88.     ON_WM_DESTROY()
  89.     ON_WM_SIZE()
  90.     ON_WM_LBUTTONDOWN()
  91.     //}}AFX_MSG_MAP
  92. END_MESSAGE_MAP()
  93.  
  94. HBITMAP CNetscapeStatusBar::sm_hbmpSecure    = NULL;
  95. SIZE    CNetscapeStatusBar::sm_sizeSecure = {0,0};
  96. int        CNetscapeStatusBar::sm_iRefCount = 0;
  97.  
  98. //------------------------------------------------------------------------------
  99. CNetscapeStatusBar::CNetscapeStatusBar()
  100. {
  101.     m_nDone     = 0L;
  102.     
  103.     m_uTimerId  = 0;
  104.     m_uVaporPos = 0;
  105.     
  106.     m_iStatBarPaneWidth = 0;
  107.     m_pTaskBar = NULL;
  108.     
  109.     m_anIDSaved = NULL;
  110.     m_iSavedCount = 0;
  111.  
  112.     m_enStatBarMode = eSBM_Panes;
  113.  
  114.     m_iAnimRef = 0;
  115.     
  116.     pParentSubclass = NULL;    
  117.  
  118.     m_pTooltip = NULL;
  119.  
  120.     m_pProxy2Frame = NULL;
  121.     
  122.     if( !sm_hbmpSecure )
  123.     { 
  124.         VERIFY( sm_hbmpSecure = ::LoadBitmap( AfxGetResourceHandle(), MAKEINTRESOURCE( IDB_SECURE_STATUS ) ));
  125.         
  126.         BITMAP bm;
  127.         ::GetObject( sm_hbmpSecure, sizeof(bm), &bm );
  128.         sm_sizeSecure.cx = bm.bmWidth / 3;
  129.         sm_sizeSecure.cy = bm.bmHeight;
  130.     }
  131.     sm_iRefCount++;
  132.  
  133. //------------------------------------------------------------------------------
  134. CNetscapeStatusBar::~CNetscapeStatusBar()
  135. {
  136.     delete pParentSubclass;
  137.     
  138.     if( m_pTooltip )
  139.     {
  140.         delete m_pTooltip;
  141.     }
  142.     
  143.     delete [] m_anIDSaved;
  144.  
  145.     if (!--sm_iRefCount) {
  146.         VERIFY(::DeleteObject(sm_hbmpSecure));
  147.         sm_hbmpSecure = NULL;
  148.     }
  149. }
  150.  
  151. //------------------------------------------------------------------------------
  152. BOOL CNetscapeStatusBar::Create( CWnd *pParent, BOOL bSecurityStatus /*=TRUE*/, BOOL bTaskbar /*=TRUE*/ )
  153. {
  154.     m_bTaskbar = bTaskbar;
  155.     m_bSecurityStatus = bSecurityStatus;
  156.     
  157.     if( !CNetscapeStatusBarBase::Create( pParent ) )
  158.         return FALSE;
  159.  
  160.     if( m_bSecurityStatus )
  161.     {
  162.         m_pTooltip = new CNSToolTip2;
  163.         if( !m_pTooltip )
  164.         {
  165.             return FALSE;
  166.         }
  167.         
  168.         m_pTooltip->Create( this );
  169.         m_pTooltip->AddTool( this, IDS_STATBAR_SECURITY, CRect(0,0,0,0), IDS_SECURITY_STATUS );
  170.         m_pTooltip->AddTool( this, IDS_STATBAR_SECURITY, CRect(0,0,0,0), IDS_SIGNED_STATUS );
  171.     }
  172.  
  173.     if (!CreateDefaultPanes())
  174.         return FALSE;
  175.  
  176.     pParentSubclass = new CNetscapeStatusBar::CParentSubclass( pParent, this );
  177.     ASSERT( pParentSubclass );
  178.     
  179. #ifdef MOZ_TASKBAR
  180.     if( m_bTaskbar )
  181.     {    
  182.         //
  183.            // Tell the Task Bar manager about us so it can be docked on our status bar.
  184.         //
  185.            ((CNetscapeApp *)AfxGetApp())->GetTaskBarMgr().RegisterStatusBar( this );
  186.         SaveModeState();
  187.     }
  188. #endif /* MOZ_TASKBAR */
  189.         
  190.     return TRUE;
  191. }
  192.  
  193. #ifdef _WIN32
  194. //------------------------------------------------------------------------------
  195. CWnd *CNetscapeStatusBar::SetParent( CWnd *pWndNewParent )
  196. {
  197.     ASSERT( ::IsWindow( m_hWnd ) );
  198.  
  199.     if( m_pDockSite )
  200.     {
  201.         m_pDockSite->RemoveControlBar( this );
  202.         m_pDockSite = NULL;
  203.     }
  204.     
  205.     CWnd *pOld = CWnd::FromHandle( ::SetParent( m_hWnd, pWndNewParent->GetSafeHwnd() ) );
  206.  
  207.     return pOld;
  208. }
  209. #endif
  210.  
  211. //------------------------------------------------------------------------------
  212. BOOL CNetscapeStatusBar::CreateDefaultPanes() 
  213. {
  214.     if( m_bSecurityStatus ) {
  215.         if( !SetIndicators( pPaneIndicators, sizeof(pPaneIndicators)/sizeof(UINT) ) )
  216.            return FALSE;
  217.     } else {
  218.         if( !SetIndicators( pPaneIndicators + 1, sizeof(pPaneIndicators)/sizeof(UINT) - 1 ) )            
  219.            return FALSE;
  220.     }
  221.     return TRUE;
  222. }
  223.  
  224. //------------------------------------------------------------------------------
  225. BOOL CNetscapeStatusBar::SetIndicators(const UINT* lpIDArray, int nIDCount)
  226. {
  227.     BOOL res = CNetscapeStatusBarBase::SetIndicators(lpIDArray, nIDCount);
  228.     if (res) {
  229.         m_iSavedCount = nIDCount;
  230.         delete [] m_anIDSaved;
  231.         if (m_iSavedCount) {
  232.             m_anIDSaved = new UINT[m_iSavedCount];
  233.             for (int i = 0; i < m_iSavedCount; i++) {
  234.                 m_anIDSaved[i] = lpIDArray[i];
  235.             }
  236.         } else {
  237.             m_anIDSaved = NULL;
  238.         }
  239.         SetupMode();
  240. #ifdef MOZ_TASKBAR
  241.         ((CNetscapeApp *)AfxGetApp())->GetTaskBarMgr().OnSizeStatusBar( this );
  242. #endif /* MOZ_TASKBAR */
  243.         SaveModeState();
  244.     }
  245.     return res;
  246. }
  247.  
  248. //------------------------------------------------------------------------------
  249. BOOL CNetscapeStatusBar::ResetPanes( EStatBarMode enStatBarMode, BOOL bForce /*=FALSE*/ )
  250. {
  251.     if( !bForce && (m_enStatBarMode == enStatBarMode) )
  252.     {
  253.         return TRUE;
  254.     }
  255.  
  256.     if( m_enStatBarMode != enStatBarMode )
  257.     {
  258.         // Save state info of the current pane mode
  259.         SaveModeState();
  260.     }
  261.     
  262.     //
  263.     // Set new panes/indicators
  264.     //
  265.     m_enStatBarMode = enStatBarMode;
  266.     
  267.     if( enStatBarMode != eSBM_Simple )
  268.     {
  269.         // The previous mode shall never be eSBM_Simple (eSBM_Simple is for menu help text)
  270.  
  271.         pParentSubclass->SetPrevMode( enStatBarMode );
  272.     }
  273.     
  274.     SetupMode();
  275.     
  276.     return TRUE;
  277. }
  278.  
  279. //------------------------------------------------------------------------------
  280. void CNetscapeStatusBar::SaveModeState()
  281. {
  282.     switch( m_enStatBarMode )
  283.     {
  284.         case eSBM_Panes:
  285.         {
  286. #ifdef MOZ_TASKBAR
  287.             if( m_bTaskbar ) 
  288.             {
  289.                 // Save the IDS_TASKBAR pane width
  290.                 
  291.                 UINT u;
  292.                 GetPaneInfo( CommandToIndex( IDS_TASKBAR ), u, u, m_iStatBarPaneWidth );
  293.             }
  294. #endif /* MOZ_TASKBAR */
  295.             break;
  296.         }
  297.         
  298.         case eSBM_Simple:
  299.         {
  300.             // Don't care to save anything
  301.             break;
  302.         }
  303.         
  304.         default:
  305.         {
  306.            break;
  307.         }
  308.     }
  309. }
  310.  
  311. //------------------------------------------------------------------------------
  312. void CNetscapeStatusBar::SetupMode()
  313. {
  314.     switch( m_enStatBarMode )
  315.     {
  316.         case eSBM_Simple:
  317.         {
  318.             if (!CNetscapeStatusBarBase::SetIndicators(pSimpleIndicators, 1))
  319.                 return;
  320.  
  321.             SetPaneInfo( 0, ID_SEPARATOR, SBPS_STRETCH | SBPS_NOBORDERS, 0 );
  322.             
  323.             // Hide the task bar window (if docked)
  324.             
  325. #ifdef MOZ_TASKBAR
  326.             ShowTaskBar( SW_HIDE );
  327. #endif /* MOZ_TASKBAR */
  328.             
  329.             break;
  330.         }
  331.         
  332.         case eSBM_Panes:
  333.         {
  334.             if (!m_anIDSaved)
  335.                 return;
  336.  
  337.             if (!CNetscapeStatusBarBase::SetIndicators(m_anIDSaved, m_iSavedCount))
  338.                 return;
  339.  
  340. #ifdef _WIN32                
  341.             int iFudge = 4;
  342. #else
  343.             int iFudge = 2;
  344. #endif
  345.             
  346.             RECT rcTool;
  347.  
  348.             int idx = CommandToIndex(IDS_SECURITY_STATUS);
  349.             if (idx > -1) {
  350.                 SetPaneInfo(idx, IDS_SECURITY_STATUS, SBPS_DISABLED, sm_sizeSecure.cx - iFudge);
  351.  
  352.                 if (m_pTooltip) {
  353.                     GetItemRect(idx, &rcTool);
  354.                     m_pTooltip->SetToolRect(this, IDS_SECURITY_STATUS, &rcTool);
  355.                 }
  356.             }
  357.             idx = CommandToIndex(IDS_SIGNED_STATUS);
  358.             if (idx > -1) {
  359.                 SetPaneInfo(idx, IDS_SIGNED_STATUS, SBPS_DISABLED, sm_sizeSecure.cx - iFudge);       
  360.  
  361.                 if (m_pTooltip) {
  362.                     GetItemRect(idx, &rcTool);
  363.                     m_pTooltip->SetToolRect(this, IDS_SIGNED_STATUS, &rcTool);
  364.                 }
  365.             }    
  366.             
  367.             //
  368.             // Set common pane info (size, style, etc).
  369.             // WHS -- I'm assuming we'll always have these, probably not good in the long term
  370.             //
  371.  
  372.             SetPaneInfo( CommandToIndex( ID_SEPARATOR ),        ID_SEPARATOR,        SBPS_STRETCH, 0 );
  373.             SetPaneInfo( CommandToIndex( IDS_TRANSFER_STATUS ), IDS_TRANSFER_STATUS, SBPS_NORMAL,  90 );
  374.                 
  375.             // Note the taskbar mgr sets the width of the taskbar pane
  376.             // Also note we must call these SetPaneXXX methods even if m_bTaskbar is FALSE because
  377.             // pPaneIndicators specifies the IDS_TASKBAR.  If we don't, the default CStatusBar
  378.             // implementation is to display the IDS_TASKBAR string resource in the status - not good.
  379. #ifdef MOZ_TASKBAR
  380.             idx = CommandToIndex( IDS_TASKBAR );
  381.             if (idx > -1) 
  382.             {
  383.                 SetPaneInfo( idx, IDS_TASKBAR, SBPS_NOBORDERS, m_iStatBarPaneWidth );
  384.                 SetPaneText( idx, "", FALSE );
  385.  
  386.                 // Show the task bar window (if docked)
  387.  
  388.                 if( m_iStatBarPaneWidth )
  389.                     ShowTaskBar( SW_SHOWNA );
  390.                  
  391.                 if( m_pTaskBar )
  392.                 {   
  393.                     CRect rc;
  394.                     GetItemRect( CommandToIndex( IDS_TASKBAR ), &rc );
  395.                     //Get Item Rect is returning us the wrong dimensions.  It's off by 6 pixels
  396.                     //Eventually figure out what's going wrong
  397.                     rc.right -= 6;
  398.                     m_pTaskBar->MoveWindow( &rc );
  399.                     m_pTaskBar = NULL;
  400.                 }    
  401.             }
  402. #endif /* MOZ_TASKBAR */
  403.  
  404.             break;
  405.         }
  406.         
  407.         default:
  408.         {
  409.            break;
  410.         }
  411.     }
  412. }
  413.  
  414. //------------------------------------------------------------------------------
  415. void CNetscapeStatusBar::ShowTaskBar( int iCmdShow )
  416. {
  417. #ifdef MOZ_TASKBAR
  418.     if( !m_bTaskbar )
  419.     {    
  420.         return;
  421.     }
  422.     
  423.     CWnd *pChild = GetWindow( GW_CHILD );
  424.     while( pChild )
  425.     {
  426.         pChild->ShowWindow( iCmdShow );
  427.         pChild = pChild->GetWindow( GW_HWNDNEXT );
  428.     }
  429. #endif
  430. }
  431.  
  432. //------------------------------------------------------------------------------
  433. BOOL CNetscapeStatusBar::SetTaskBarPaneWidth( int iWidth )
  434. {
  435. #ifdef MOZ_TASKBAR
  436.     if( !m_bTaskbar || (iWidth < 0) )
  437.     {
  438.         return FALSE;
  439.     }
  440.     
  441.     int nIndex = CommandToIndex( IDS_TASKBAR );
  442.     if( nIndex != -1 )
  443.     {
  444.         UINT nID, nStyle; 
  445.         int nWidth;
  446.         GetPaneInfo( nIndex, nID, nStyle, nWidth );
  447.         SetPaneInfo( nIndex, nID, nStyle, iWidth );
  448.     }
  449.     else
  450.     {
  451.         // The pane is not available right now.  We'll resize the pane later.
  452.         m_iStatBarPaneWidth = iWidth;
  453.     }
  454. #endif /* MOZ_TASKBAR */
  455.     return TRUE;
  456. }
  457.  
  458. //------------------------------------------------------------------------------
  459. BOOL CNetscapeStatusBar::SetTaskBarSize( CDockedTaskBar *pTaskBar )
  460. {
  461. #ifdef MOZ_TASKBAR
  462.     if( !m_bTaskbar || !pTaskBar )
  463.     {
  464.         return FALSE;
  465.     }
  466.     
  467.     CRect rc;
  468.     int iIndex = CommandToIndex( IDS_TASKBAR );
  469.     if( iIndex != -1 )
  470.     {
  471.         GetItemRect( iIndex, &rc );
  472.         //Get Item Rect is returning us the wrong dimensions.  It's off by 6 pixels
  473.         //Eventually figure out what's going wrong
  474.         rc.right -= 6;
  475.         pTaskBar->MoveWindow( &rc );
  476.     }
  477.     else
  478.     {
  479.         // The pane is not available right now.  We'll resize the task bar later.
  480.         m_pTaskBar = pTaskBar;
  481.     }
  482.     
  483. #endif /* MOZ_TASKBAR */
  484.     return TRUE;
  485. }
  486.  
  487. //------------------------------------------------------------------------------
  488. void CNetscapeStatusBar::StartAnimation()
  489. {
  490.     m_iAnimRef = TRUE;
  491.     
  492.     SetPercentDone( -1 );
  493. }
  494.  
  495. //------------------------------------------------------------------------------
  496. void CNetscapeStatusBar::StopAnimation()
  497. {
  498.     if( m_iAnimRef )
  499.     {
  500.         m_iAnimRef = FALSE;
  501.     }
  502.     
  503.     if( !m_iAnimRef )
  504.     {
  505.         SetPercentDone( 0 );
  506.     }
  507. }
  508.  
  509. //------------------------------------------------------------------------------
  510. void CNetscapeStatusBar::SetPercentDone(const int32 nPercent)
  511. {
  512.     // Destroying the context in response to the window being destroyed
  513.     // sometimes calls this, so we need to check that the window
  514.     // still exists or we die.
  515.  
  516.     if (!m_hWnd)
  517.         return;
  518.  
  519.     if( m_nDone != nPercent )
  520.     {
  521.         if( m_iAnimRef && (nPercent == 0) )
  522.         {
  523.             m_nDone = -1;
  524.         }
  525.         else
  526.         {
  527.             m_nDone = nPercent;
  528.         }
  529.         
  530.         DrawProgressBar();
  531.         
  532.         if( m_nDone >= 100 )
  533.         {
  534.             //
  535.             // Ensure progress never sits on 100% i.e., the back end might never
  536.             // reset progress to 0 after specifying 100. 
  537.             //
  538.             m_nDone = m_iAnimRef ? -1 : 0;
  539.             DrawProgressBar();            
  540.         }
  541.     }
  542. }
  543.  
  544. //------------------------------------------------------------------------------
  545. void CNetscapeStatusBar::OnDestroy()
  546. {
  547. #ifdef MOZ_TASKBAR
  548.     if( m_bTaskbar )
  549.     {    
  550.         // Tell the Task Bar manager not to worry about us anymore
  551.         
  552.         ((CNetscapeApp *)AfxGetApp())->GetTaskBarMgr().UnRegisterStatusBar( this );
  553.     }
  554. #endif /* MOZ_TASKBAR */
  555.     
  556.     CNetscapeStatusBarBase::OnDestroy();
  557. }
  558.  
  559. //------------------------------------------------------------------------------
  560. void CNetscapeStatusBar::OnLButtonDown( UINT nFlags, CPoint point )
  561. {
  562.     if( m_bSecurityStatus )
  563.     {
  564.         RECT rc;
  565.         GetItemRect( CommandToIndex( IDS_SECURITY_STATUS ), &rc );
  566.  
  567.         if( PtInRect( &rc, point ) ) 
  568.         {
  569.             CGenericFrame *pGenFrame = DYNAMIC_DOWNCAST( CGenericFrame, GetParentFrame() );
  570.             if( pGenFrame )
  571.             {
  572.                 MWContext *pContext = pGenFrame->GetMainContext()->GetContext();  
  573.  
  574.                 if( pContext )
  575.                 {
  576.                     CAbstractCX *pCX = ABSTRACTCX(pContext);   
  577.  
  578.                     if( pCX )
  579.                     {      
  580.                         URL_Struct *pURL = pCX->CreateUrlFromHist( TRUE ); 
  581.  
  582.                         SECNAV_SecurityAdvisor( pContext, pURL );
  583.                     }  
  584.                 }  
  585.                 
  586.             }
  587.         }
  588.     }
  589.     
  590.     CNetscapeStatusBarBase::OnLButtonDown( nFlags, point );
  591. }
  592.  
  593. //------------------------------------------------------------------------------
  594. // We process the WM_SIZE message just to notify the Task Bar manager
  595. // that we've changed, so it can do what it needs with any task bars
  596. // docked on top of us.
  597. //
  598. void CNetscapeStatusBar::OnSize( UINT nType, int cx, int cy )
  599. {
  600.     CNetscapeStatusBarBase::OnSize( nType, cx, cy );
  601.     if ( nType != SIZE_MINIMIZED && cx && cy) {
  602. #ifdef MOZ_TASKBAR
  603.         if( m_bTaskbar ) 
  604.         {
  605.             // Tell the Task Bar manager
  606.             ((CNetscapeApp *)AfxGetApp())->GetTaskBarMgr().OnSizeStatusBar( this );
  607.         }
  608. #endif /* MOZ_TASKBAR */
  609.         RECT rcTool;
  610.  
  611.         int idx = CommandToIndex(IDS_SECURITY_STATUS);
  612.         if (idx > -1) {
  613.             if (m_pTooltip) {
  614.                 GetItemRect(idx, &rcTool);
  615.                 m_pTooltip->SetToolRect(this, IDS_SECURITY_STATUS, &rcTool);
  616.             }
  617.         }
  618.         idx = CommandToIndex(IDS_SIGNED_STATUS);
  619.         if (idx > -1) {
  620.             if (m_pTooltip) {
  621.                 GetItemRect(idx, &rcTool);
  622.                 m_pTooltip->SetToolRect(this, IDS_SIGNED_STATUS, &rcTool);
  623.             }
  624.         }    
  625.     }
  626. }
  627.  
  628. //------------------------------------------------------------------------------
  629. void CNetscapeStatusBar::OnPaint()
  630. {
  631. #if defined(MSVC4)
  632.     CStatusBar::OnPaint();
  633.     CClientDC dc(this);
  634. #else
  635.     CPaintDC dc(this);
  636.     // Do not call CStatusBar::OnPaint()!
  637.     CNetscapeStatusBarBase::DoPaint( &dc );
  638. #endif    // MSVC4
  639.  
  640.     //
  641.     // Special per mode painting
  642.     //
  643.     switch( m_enStatBarMode )
  644.     {
  645.         case eSBM_Panes:
  646.         {
  647.            // Nothing to do
  648.             break;
  649.         }
  650.         
  651.         case eSBM_Simple:
  652.         default:
  653.         {
  654.            // Nothing to do
  655.            break;
  656.         }
  657.     }
  658.     
  659.     DrawSecureStatus(dc.m_hDC);
  660.     DrawSignedStatus(dc.m_hDC);
  661.        DrawProgressBar();
  662. }
  663.  
  664. //------------------------------------------------------------------------------
  665. BOOL CNetscapeStatusBar::PreTranslateMessage( MSG *pMsg )
  666. {
  667.     if( m_pTooltip && (m_enStatBarMode != eSBM_Simple) )
  668.     {
  669.         if (pMsg->message >= WM_MOUSEFIRST && pMsg->message <= WM_MOUSELAST)
  670.             m_pTooltip->RelayEvent( pMsg );
  671.     }
  672.     
  673.     return CNetscapeStatusBarBase::PreTranslateMessage( pMsg );
  674. }
  675.  
  676. //------------------------------------------------------------------------------
  677. void CNetscapeStatusBar::DrawSecureStatus(HDC hdc)
  678. {
  679.      int idx = CommandToIndex( IDS_SECURITY_STATUS );
  680.      if (idx < 0) 
  681.         return;
  682.  
  683.     UINT nID, nStyle;
  684.     int cxWidth;
  685.     GetPaneInfo(idx, nID, nStyle, cxWidth);
  686.     BOOL bSecure = !(nStyle & SBPS_DISABLED);
  687.     
  688.       RECT rect; 
  689.       GetItemRect( idx, &rect );
  690.  
  691.       HDC hdcBitmap = ::CreateCompatibleDC( hdc );
  692.       HBITMAP hbmOld = (HBITMAP)::SelectObject( hdcBitmap, sm_hbmpSecure );
  693.  
  694.       FEU_TransBlt( hdc, rect.left+1, rect.top+1, sm_sizeSecure.cx, sm_sizeSecure.cy, hdcBitmap, bSecure ? sm_sizeSecure.cx : 0, 0,WFE_GetUIPalette(GetParentFrame()) );
  695.  
  696.       ::SelectObject( hdcBitmap, hbmOld );
  697.       VERIFY( ::DeleteDC( hdcBitmap ));
  698. }
  699.  
  700. //------------------------------------------------------------------------------
  701. void CNetscapeStatusBar::DrawSignedStatus(HDC hdc)
  702. {
  703.      int idx = CommandToIndex( IDS_SIGNED_STATUS );
  704.      if (idx < 0) 
  705.         return;
  706.  
  707.     UINT nID, nStyle;
  708.     int cxWidth;
  709.     GetPaneInfo(idx, nID, nStyle, cxWidth);
  710.     BOOL bSigned = !(nStyle & SBPS_DISABLED);
  711.     
  712.     if (bSigned) {
  713.           RECT rect; 
  714.           GetItemRect( idx, &rect );
  715.  
  716.           HDC hdcBitmap = ::CreateCompatibleDC( hdc );
  717.  
  718.           HBITMAP hbmOld = (HBITMAP)::SelectObject( hdcBitmap, sm_hbmpSecure );
  719.  
  720.           FEU_TransBlt( hdc, rect.left+1, rect.top+1, sm_sizeSecure.cx, sm_sizeSecure.cy, hdcBitmap, sm_sizeSecure.cx * 2, 0 ,WFE_GetUIPalette(GetParentFrame()));
  721.  
  722.           ::SelectObject( hdcBitmap, hbmOld );
  723.           VERIFY( ::DeleteDC( hdcBitmap ));
  724.     }
  725. }
  726.  
  727. //------------------------------------------------------------------------------
  728. void CNetscapeStatusBar::DrawProgressBar()
  729. {
  730.     int idx = CommandToIndex( IDS_TRANSFER_STATUS );
  731.     if (idx < 0)
  732.         return;
  733.  
  734.     RECT rcBarArea;
  735.     GetItemRect( idx, &rcBarArea );
  736.  
  737.     CClientDC dc( this );
  738.     
  739.     if( m_nDone == 0 )    
  740.     {
  741.         StopPulse();
  742.         
  743.         ::InflateRect( &rcBarArea, -1, -1 );
  744.         dc.FillRect( &rcBarArea, CBrush::FromHandle( sysInfo.m_hbrBtnFace ) );
  745.         
  746.         return;
  747.     } 
  748.     
  749.     if( m_nDone == -1 )
  750.     {
  751.         if( !m_uTimerId )
  752.         {
  753.            StartPulse();
  754.         }
  755.         
  756.         return;
  757.     }
  758.     
  759.     // Decide the correct size of the thermo.
  760.     InflateRect( &rcBarArea, -5, -2 );
  761.  
  762.     CDC dcMem;
  763.     dcMem.CreateCompatibleDC( &dc );
  764.     
  765.     // Create a bitmap big enough for progress bar area
  766.     CBitmap bmMem;
  767.     bmMem.CreateCompatibleBitmap( &dc, rcBarArea.right-rcBarArea.left, rcBarArea.bottom-rcBarArea.top );
  768.     CBitmap *pbmOld = dcMem.SelectObject( &bmMem );
  769.  
  770.     // Select the font
  771.     CFont *pOldFont = NULL;
  772.     if( GetFont() ) 
  773.     {
  774.         pOldFont = dcMem.SelectObject( GetFont() );
  775.     }
  776.  
  777.     char szPercent[8];
  778.     wsprintf( szPercent, "%u%%", m_nDone );
  779.     dcMem.SetBkMode( TRANSPARENT );
  780.  
  781.     RECT rcBm = { 0, 0, rcBarArea.right-rcBarArea.left, rcBarArea.bottom-rcBarArea.top };
  782.  
  783.     int iNumColors = dc.GetDeviceCaps( NUMCOLORS );
  784.     
  785.     if( iNumColors == -1 || iNumColors > 256 )
  786.     {
  787.         // Render the image into the mem DC
  788.         dcMem.FillRect( &rcBm, CBrush::FromHandle( sysInfo.m_hbrBtnFace ) );
  789.  
  790.         dcMem.SetTextColor( GetSysColor( COLOR_BTNTEXT ) );
  791.         dcMem.DrawText( szPercent, -1, &rcBm, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
  792.         
  793.         RECT rcBar = { 0, 0, CASTINT(rcBm.right * m_nDone / 100), CASTINT(rcBm.bottom) };
  794.         dcMem.InvertRect( &rcBar );
  795.     }
  796.     else
  797.     {
  798.         // There's reasonable probability that the inverse color of btnface and btnshadow could be the same
  799.         // when we are dealing with a palette of 256 colors or less.  So instead of using the invertrect
  800.         // algorithm above, we'll just ensure the text is legible by painting a white background for it.
  801.  
  802.         // Render the image into the mem DC
  803.         dcMem.FillRect( &rcBm, CBrush::FromHandle( (HBRUSH)GetStockObject( WHITE_BRUSH ) ) );
  804.         
  805.         dcMem.SetTextColor( RGB(0,0,0) );
  806.         dcMem.DrawText( szPercent, -1, &rcBm, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
  807.         
  808.         RECT rcBar = { 0, 0, CASTINT(rcBm.right * m_nDone / 100), CASTINT(rcBm.bottom) };
  809.         dcMem.InvertRect( &rcBar );
  810.     }
  811.         
  812.     dc.BitBlt( rcBarArea.left, rcBarArea.top, rcBarArea.right-rcBarArea.left, rcBarArea.bottom-rcBarArea.top, &dcMem, 0, 0, SRCCOPY );
  813.  
  814.     // Tidy up
  815.     
  816.     if( pOldFont ) 
  817.     {
  818.         dcMem.SelectObject( pOldFont );
  819.     }
  820.     dcMem.SelectObject( pbmOld );
  821. }
  822.  
  823. //------------------------------------------------------------------------------
  824. #define VAPOR_PERIOD 40 // Note, must be divisible by 2
  825.  
  826. void CNetscapeStatusBar::PulsingVaporTrails()
  827. {
  828.     RECT rcBarArea;
  829.     GetItemRect( CommandToIndex( IDS_TRANSFER_STATUS ), &rcBarArea );
  830.  
  831.     CClientDC dc( this );
  832.     
  833.     InflateRect( &rcBarArea, -5, -2 );
  834.  
  835.     CDC dcMem;
  836.     dcMem.CreateCompatibleDC( &dc );
  837.     
  838.     // Create a bitmap big enough for progress bar area
  839.     CBitmap bmMem;
  840.     bmMem.CreateCompatibleBitmap( &dc, rcBarArea.right-rcBarArea.left, rcBarArea.bottom-rcBarArea.top );
  841.     CBitmap *pbmOld = dcMem.SelectObject( &bmMem );
  842.  
  843.     // Render the image into the mem DC
  844.     
  845.     RECT rcBm = { 0, 0, rcBarArea.right-rcBarArea.left, rcBarArea.bottom-rcBarArea.top };
  846.     dcMem.FillRect( &rcBm, CBrush::FromHandle( sysInfo.m_hbrBtnFace ) );
  847.  
  848.     COLORREF crTrail = GetSysColor( COLOR_BTNSHADOW );
  849.     COLORREF crFade  = GetSysColor( COLOR_BTNFACE );
  850.     
  851.     int iTrailR = (int)GetRValue( crTrail );
  852.     int iTrailG = (int)GetGValue( crTrail );
  853.     int iTrailB = (int)GetBValue( crTrail );        
  854.  
  855.     int iFadeR = (int)GetRValue( crFade );
  856.     int iFadeG = (int)GetGValue( crFade );
  857.     int iFadeB = (int)GetBValue( crFade );
  858.  
  859.     int iTrailLen = rcBm.right/2;
  860.  
  861.     UINT uHalfPeriod = m_uVaporPos;
  862.  
  863.     int iNumColors = dc.GetDeviceCaps( NUMCOLORS );
  864.         
  865.     if( m_uVaporPos <= VAPOR_PERIOD/2 )
  866.     {
  867.        for( int u = 0; u < iTrailLen; u++ )
  868.        {
  869.            COLORREF crVapor = RGB( (BYTE)(iTrailR - ((float)(iTrailR - iFadeR)/(float)iTrailLen * (float)u)), 
  870.                                    (BYTE)(iTrailG - ((float)(iTrailG - iFadeG)/(float)iTrailLen * (float)u)), 
  871.                                    (BYTE)(iTrailB - ((float)(iTrailB - iFadeB)/(float)iTrailLen * (float)u)) );
  872.            RECT rcVapor = rcBm;
  873.            rcVapor.right = -u + (rcBm.right / (VAPOR_PERIOD/2))*uHalfPeriod+1;
  874.            rcVapor.left = rcVapor.right - (iTrailLen-u);
  875.            CBrush br( crVapor );           
  876.            dcMem.FillRect( &rcVapor, &br );
  877.            
  878.            if( (iNumColors != -1) && (iNumColors <= 256) )
  879.            {
  880.               // Just paint a solid bouncing block for 8-bit (or less) color
  881.               break;
  882.            }
  883.        }
  884.     }
  885.     else
  886.     {
  887.        uHalfPeriod = m_uVaporPos - VAPOR_PERIOD/2;
  888.        
  889.        for( int u = 0; u < iTrailLen; u++ )
  890.        {
  891.            COLORREF crVapor = RGB( (BYTE)(iTrailR - ((float)(iTrailR - iFadeR)/(float)iTrailLen * (float)u)), 
  892.                                    (BYTE)(iTrailG - ((float)(iTrailG - iFadeG)/(float)iTrailLen * (float)u)), 
  893.                                    (BYTE)(iTrailB - ((float)(iTrailB - iFadeB)/(float)iTrailLen * (float)u)) );
  894.            RECT rcVapor = rcBm;           
  895.            rcVapor.left = (rcVapor.right + u) - ((rcBm.right / (VAPOR_PERIOD/2))*uHalfPeriod-1);
  896.            rcVapor.right = rcVapor.left + (iTrailLen-u);
  897.            CBrush br( crVapor );           
  898.            dcMem.FillRect( &rcVapor, &br );           
  899.            
  900.            if( (iNumColors != -1) && (iNumColors <= 256) )
  901.            {
  902.               // Just paint a solid bouncing block for 8-bit (or less) color           
  903.               break;
  904.            }
  905.        }
  906.     }
  907.  
  908.     if( m_uVaporPos == VAPOR_PERIOD )
  909.     {
  910.        m_uVaporPos = 0;
  911.     }
  912.     else
  913.     {
  914.        m_uVaporPos++;
  915.     }
  916.         
  917.     dc.BitBlt( rcBarArea.left, rcBarArea.top, rcBarArea.right-rcBarArea.left, rcBarArea.bottom-rcBarArea.top, &dcMem, 0, 0, SRCCOPY );
  918.  
  919.     // Tidy up
  920.     dcMem.SelectObject( pbmOld );
  921. }
  922.  
  923. //------------------------------------------------------------------------------
  924. void CNetscapeStatusBar::StartPulse()
  925. {
  926.    m_uVaporPos = 0;
  927.    
  928.    m_uTimerId = SetTimer( IDT_PULSE, PULSE_INTERVAL, CNetscapeStatusBar::PulseTimerProc );
  929.    
  930.    if( !m_uTimerId )
  931.    {
  932.       return;
  933.    }
  934. }
  935.  
  936. //------------------------------------------------------------------------------
  937. void CNetscapeStatusBar::StopPulse()
  938. {
  939.    if( !m_uTimerId )
  940.    {
  941.       return;
  942.    }
  943.    
  944.    KillTimer( IDT_PULSE );
  945.    
  946.    m_uTimerId = 0;
  947. }
  948.  
  949. //------------------------------------------------------------------------------
  950. void CALLBACK EXPORT 
  951. CNetscapeStatusBar::PulseTimerProc( HWND hwnd, UINT uMsg, UINT uTimerId, DWORD dwTime )
  952. {
  953.    CNetscapeStatusBar *pBar = (CNetscapeStatusBar *)CWnd::FromHandle( hwnd );
  954.  
  955.    if( (pBar->m_nDone == -1) && (pBar->GetStatBarMode() == eSBM_Panes) )
  956.    {
  957.       pBar->PulsingVaporTrails();
  958.    }
  959. }
  960.  
  961. //------------------------------------------------------------------------------
  962. //------------------------------------------------------------------------------
  963.  
  964. //------------------------------------------------------------------------------
  965. CNetscapeStatusBar::CParentSubclass::CParentSubclass( CWnd *pParent, CNetscapeStatusBar *pStatusBar )
  966. {
  967.     VERIFY( m_pStatusBar = pStatusBar );
  968.     VERIFY( m_pParent    = pParent );
  969.  
  970.     ASSERT( IsWindow( m_pParent->m_hWnd ) );
  971.     
  972.     //
  973.     // Subclass the parent window so we can process the WM_MENUSELECT msg i.e., so we
  974.     // can switch modes from Simple/Panes without client intervention.
  975.     //
  976.     
  977.    #ifdef _WIN32
  978.     VERIFY( SetProp( pParent->m_hWnd, szNSStatusProp, this ) );
  979.    #else
  980.     VERIFY( SetProp( pParent->m_hWnd, szNSStatusProp1, (HANDLE)LOWORD((DWORD)this) ) );
  981.     VERIFY( SetProp( pParent->m_hWnd, szNSStatusProp2, (HANDLE)HIWORD((DWORD)this) ) );
  982.    #endif
  983.    
  984.     m_pfOldWndProc = (WNDPROC)SetWindowLong( m_pParent->m_hWnd, GWL_WNDPROC, 
  985.                                              (LONG)CNetscapeStatusBar::CParentSubclass::ParentSubclassProc );
  986. }
  987.     
  988. //------------------------------------------------------------------------------
  989. CNetscapeStatusBar::CParentSubclass::~CParentSubclass()
  990. {
  991.     if( IsWindow( m_pParent->m_hWnd ) && 
  992.         GetWindowLong( m_pParent->m_hWnd, GWL_WNDPROC ) == (LONG)CNetscapeStatusBar::CParentSubclass::ParentSubclassProc )
  993.     {
  994.         //
  995.         // Unsubclass the parent window
  996.         //
  997.         
  998.        #ifdef _WIN32
  999.         VERIFY( RemoveProp( m_pParent->m_hWnd, szNSStatusProp ) );
  1000.        #else
  1001.         VERIFY( RemoveProp( m_pParent->m_hWnd, szNSStatusProp1 ) );
  1002.         VERIFY( RemoveProp( m_pParent->m_hWnd, szNSStatusProp2 ) );
  1003.        #endif
  1004.        
  1005.         SetWindowLong( m_pParent->m_hWnd, GWL_WNDPROC, (LONG)m_pfOldWndProc );
  1006.     }
  1007. }
  1008.  
  1009. //------------------------------------------------------------------------------
  1010. LRESULT CALLBACK EXPORT
  1011. CNetscapeStatusBar::CParentSubclass::ParentSubclassProc( HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam )
  1012. {
  1013.     CNetscapeStatusBar::CParentSubclass *pThis = NULL;
  1014.     
  1015.    #ifdef _WIN32
  1016.     pThis = (CNetscapeStatusBar::CParentSubclass *)GetProp( hWnd, szNSStatusProp );
  1017.    #else
  1018.     pThis = (CNetscapeStatusBar::CParentSubclass *)MAKELONG( GetProp( hWnd, szNSStatusProp1 ),
  1019.                                                              GetProp( hWnd, szNSStatusProp2 ) );
  1020.    #endif
  1021.     ASSERT( pThis );   
  1022.     
  1023.     LRESULT lRet = 0L;
  1024.     
  1025.     switch( uMessage )
  1026.     {
  1027.         case WM_MENUSELECT:
  1028.         {
  1029.            #ifdef _WIN32
  1030.             UINT uFlags = (UINT)HIWORD(wParam);
  1031.             HMENU hMenu = (HMENU)lParam;
  1032.            #else
  1033.             UINT uFlags = (UINT)LOWORD(lParam);
  1034.             HMENU hMenu = (HMENU)HIWORD(lParam);
  1035.            #endif
  1036.            
  1037.             //
  1038.             // Put the status bar into the correct mode for either:
  1039.             // 1.) Menu help text (aka Simple Text)
  1040.             // 2.) Multiple panes of info for progress etc.
  1041.             //
  1042.             
  1043.             BOOL bMenuClosed = (uFlags & 0xffff) && !hMenu;
  1044.             
  1045.             if( !bMenuClosed )
  1046.             {
  1047.                 if( eSBM_Simple != pThis->m_pStatusBar->GetStatBarMode() )
  1048.                 {
  1049.                     pThis->SetPrevMode( pThis->m_pStatusBar->GetStatBarMode() );
  1050.                     pThis->m_pStatusBar->ResetPanes( eSBM_Simple ); 
  1051.                     
  1052.                     // Start the timer for monitoring when the menu closes
  1053.                     pThis->StartMonitor();                    
  1054.                 }
  1055.             }
  1056.           //## We have to reset on a timer notification because Windows doesn't
  1057.           //## always send the WM_MENUSELECT when menus close.  Typical.
  1058.           //  else
  1059.           //  {
  1060.           //      pThis->m_pStatusBar->ResetPanes( pThis->GetPrevMode() );
  1061.           //  }
  1062.             
  1063.             lRet = CallWindowProc( (WNDPROC)pThis->m_pfOldWndProc, hWnd, uMessage, wParam, lParam );
  1064.             break;
  1065.         }
  1066.  
  1067.         case WM_DESTROY:
  1068.         {
  1069.             pThis->StopMonitor();
  1070.             lRet = CallWindowProc( (WNDPROC)pThis->m_pfOldWndProc, hWnd, uMessage, wParam, lParam );
  1071.             
  1072.             break;
  1073.         }
  1074.                 
  1075.         default:
  1076.            lRet = CallWindowProc( (WNDPROC)pThis->m_pfOldWndProc, hWnd, uMessage, wParam, lParam );
  1077.     }
  1078.     
  1079.     return lRet;
  1080. }
  1081.  
  1082. //------------------------------------------------------------------------------
  1083. void CNetscapeStatusBar::CParentSubclass::StartMonitor()
  1084. {
  1085.     m_uTimerId = ::SetTimer( m_pStatusBar->m_hWnd, IDT_STATBARMONITOR, MONITOR_INTERVAL, CNetscapeStatusBar::CParentSubclass::MonitorTimerProc );
  1086. }
  1087.  
  1088. //------------------------------------------------------------------------------
  1089. void CNetscapeStatusBar::CParentSubclass::StopMonitor()
  1090. {
  1091.     if( !m_uTimerId )
  1092.     {
  1093.         return;
  1094.     }
  1095.    
  1096.     ::KillTimer( m_pStatusBar->m_hWnd, IDT_STATBARMONITOR );
  1097.     
  1098.     m_uTimerId = 0;
  1099. }
  1100.  
  1101. //------------------------------------------------------------------------------
  1102. void CALLBACK EXPORT 
  1103. CNetscapeStatusBar::CParentSubclass::MonitorTimerProc( HWND hwnd, UINT uMsg, UINT uTimerId, DWORD dwTime )
  1104. {
  1105.     CNetscapeStatusBar *pBar = (CNetscapeStatusBar *)CWnd::FromHandlePermanent( hwnd );
  1106.     if( !pBar )
  1107.     {
  1108.         return;
  1109.     }
  1110.     
  1111.     CNetscapeStatusBar::CParentSubclass *pThis = pBar->pParentSubclass;
  1112.   
  1113.     if( !GetCapture() && (eSBM_Simple == pThis->m_pStatusBar->GetStatBarMode()) )
  1114.     {
  1115.         pThis->m_pStatusBar->ResetPanes( pThis->GetPrevMode() );
  1116.         pThis->StopMonitor();
  1117.     }
  1118. }
  1119.  
  1120. IMPLEMENT_DYNAMIC(CNetscapeStatusBar, CNetscapeStatusBarBase)
  1121.