Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

CtrlBrowseHeader.cpp

Go to the documentation of this file.
00001 //
00002 // CtrlBrowseHeader.cpp
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //
00021 
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Settings.h"
00025 #include "GProfile.h"
00026 #include "Hostbrowser.h"
00027 #include "SchemaCache.h"
00028 #include "Schema.h"
00029 #include "Skin.h"
00030 #include "XML.h"
00031 #include "ShellIcons.h"
00032 #include "CoolInterface.h"
00033 #include "CtrlBrowseHeader.h"
00034 
00035 #ifdef _DEBUG
00036 #define new DEBUG_NEW
00037 #undef THIS_FILE
00038 static char THIS_FILE[] = __FILE__;
00039 #endif
00040 
00041 BEGIN_MESSAGE_MAP(CBrowseHeaderCtrl, CCoolBarCtrl)
00042         //{{AFX_MSG_MAP(CBrowseHeaderCtrl)
00043         ON_WM_CREATE()
00044         ON_WM_SIZE()
00045         //}}AFX_MSG_MAP
00046 END_MESSAGE_MAP()
00047 
00048 
00050 // CBrowseHeaderCtrl construction
00051 
00052 CBrowseHeaderCtrl::CBrowseHeaderCtrl()
00053 {
00054         m_bBuffered = TRUE;
00055 }
00056 
00057 CBrowseHeaderCtrl::~CBrowseHeaderCtrl()
00058 {
00059 }
00060 
00062 // CBrowseHeaderCtrl operations
00063 
00064 BOOL CBrowseHeaderCtrl::Create(CWnd* pParentWnd)
00065 {
00066         CRect rect( 0, 0, 0, 0 );
00067         return CWnd::Create( NULL, NULL, WS_CHILD|WS_VISIBLE,
00068                 rect, pParentWnd, IDC_BROWSE_HEADER, NULL );
00069 }
00070 
00071 void CBrowseHeaderCtrl::Update(CHostBrowser* pBrowser)
00072 {
00073         CGProfile* pProfile = pBrowser->m_pProfile;
00074         CString strValue, strFormat, strItem;
00075 
00076         if ( pProfile->IsValid() )
00077         {
00078                 strItem = pProfile->GetNick();
00079                 LoadString( strFormat, IDS_BROWSE_TITLE_FORMAT );
00080                 strValue.Format( strFormat, (LPCTSTR)strItem );
00081         }
00082         else
00083         {
00084                 LoadString( strFormat, IDS_BROWSE_TITLE_FORMAT );
00085                 strValue.Format( strFormat, (LPCTSTR)CString( inet_ntoa( pBrowser->m_pAddress ) ) );
00086         }
00087 
00088         float nProgress = pBrowser->GetProgress();
00089 
00090         if ( nProgress > 0.0f && nProgress < 1.0f )
00091         {
00092                 nProgress *= 100.0f;
00093                 strItem.Format( _T(" (%.1f%%)"), double( nProgress ) );
00094                 strValue += strItem;
00095         }
00096 
00097         if ( strValue != m_sTitle )
00098         {
00099                 m_sTitle = strValue;
00100                 Invalidate();
00101         }
00102 
00103         strValue.Empty();
00104 
00105         if ( pBrowser->m_nHits > 0 )
00106         {
00107                 LoadString( strFormat, IDS_BROWSE_INTRO_FORMAT );
00108                 strValue.Format( strFormat, pBrowser->m_nHits, pProfile->IsValid()
00109                         ? (LPCTSTR)pProfile->GetNick() : (LPCTSTR)CString( inet_ntoa( pBrowser->m_pAddress ) ) );
00110         }
00111 
00112         if ( m_sIntro != strValue )
00113         {
00114                 m_sIntro = strValue;
00115                 Invalidate();
00116         }
00117 }
00118 
00120 // CBrowseHeaderCtrl message handlers
00121 
00122 int CBrowseHeaderCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
00123 {
00124         if ( CWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
00125 
00126         if ( CSchema* pSchema = SchemaCache.Get( CSchema::uriLibrary ) )
00127         {
00128                 m_nIcon32 = pSchema->m_nIcon32;
00129                 m_nIcon48 = pSchema->m_nIcon48;
00130         }
00131 
00132         OnSkinChange();
00133 
00134         return 0;
00135 }
00136 
00137 void CBrowseHeaderCtrl::OnSize(UINT nType, int cx, int cy)
00138 {
00139         CWnd::OnSize( nType, cx, cy );
00140         Invalidate();
00141 }
00142 
00143 void CBrowseHeaderCtrl::OnSkinChange()
00144 {
00145         Skin.CreateToolBar( _T("CBrowseHeaderCtrl"), this );
00146 
00147         if ( m_bmImage.m_hObject == NULL &&
00148                  Skin.m_crBannerBack == RGB( 122, 161, 230 ) )
00149         {
00150                 m_bmImage.LoadBitmap( IDB_BANNER_MARK );
00151         }
00152 }
00153 
00154 void CBrowseHeaderCtrl::PrepareRect(CRect* pRect) const
00155 {
00156         CCoolBarCtrl::PrepareRect( pRect );
00157         pRect->left -= 5;
00158         if ( m_czLast.cx < pRect->Width() ) pRect->left = pRect->right - m_czLast.cx;
00159         pRect->left += 5;
00160 
00161         pRect->top              = ( pRect->top + pRect->bottom ) / 2;
00162         pRect->bottom   = pRect->top + 14;
00163         pRect->top              = pRect->top - 14;
00164 }
00165 
00166 void CBrowseHeaderCtrl::DoPaint(CDC* pDC, CRect& rcClient, BOOL bTransparent)
00167 {
00168         if ( ! CoolInterface.DrawWatermark( pDC, &rcClient, &m_bmImage ) )
00169         {
00170                 pDC->FillSolidRect( rcClient.left, rcClient.top,
00171                         rcClient.Width(), rcClient.Height(), Skin.m_crBannerBack );
00172         }
00173 
00174         CRect rcBar;
00175 
00176         rcBar.top               = ( rcClient.top + rcClient.bottom ) / 2;
00177         rcBar.bottom    = rcBar.top + 14;
00178         rcBar.top               = rcBar.top - 14;
00179         rcBar.right             = rcClient.right;
00180         rcBar.left              = rcBar.right - m_czLast.cx;
00181 
00182         CCoolBarCtrl::DoPaint( pDC, rcBar, bTransparent );
00183 
00184         CFont* pOldFont = pDC->GetCurrentFont();
00185 
00186         CPoint ptIcon( 8, ( rcClient.top + rcClient.bottom ) / 2 - 24 );
00187 
00188         if ( m_nIcon48 >= 0 )
00189         {
00190                 ShellIcons.Draw( pDC, m_nIcon48, 48, ptIcon.x, ptIcon.y );
00191         }
00192         else if ( m_nIcon32 >= 0 )
00193         {
00194                 ptIcon.x += 8; ptIcon.y += 8;
00195                 ShellIcons.Draw( pDC, m_nIcon32, 32, ptIcon.x, ptIcon.y );
00196         }
00197 
00198         pDC->SetTextColor( Skin.m_crBannerText );
00199         pDC->SetBkMode( TRANSPARENT );
00200 
00201         CRect rcWork( &rcClient );
00202         rcWork.right -= m_czLast.cx;
00203         rcWork.DeflateRect( 8, 4 );
00204         rcWork.left += 48 + 16;
00205         rcWork.DeflateRect( 0, 4 );
00206 
00207         pDC->SelectObject( &CoolInterface.m_fntCaption );
00208         Skin.DrawWrappedText( pDC, &rcWork, m_sTitle, NULL, FALSE );
00209         pDC->SelectObject( &CoolInterface.m_fntNormal );
00210         Skin.DrawWrappedText( pDC, &rcWork, m_sIntro, NULL, FALSE );
00211 
00212         pDC->SelectObject( pOldFont );
00213 }
00214 

Generated on Thu Dec 15 10:39:34 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2