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

CtrlLibraryHeaderBar.cpp

Go to the documentation of this file.
00001 //
00002 // CtrlLibraryHeaderBar.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 "Library.h"
00026 #include "CoolInterface.h"
00027 #include "ShellIcons.h"
00028 #include "Skin.h"
00029 #include "CtrlLibraryHeaderBar.h"
00030 #include "CtrlLibraryFrame.h"
00031 #include "CtrlLibraryView.h"
00032 
00033 #ifdef _DEBUG
00034 #define new DEBUG_NEW
00035 #undef THIS_FILE
00036 static char THIS_FILE[] = __FILE__;
00037 #endif
00038 
00039 IMPLEMENT_DYNAMIC(CLibraryHeaderBar, CCoolBarCtrl)
00040 
00041 BEGIN_MESSAGE_MAP(CLibraryHeaderBar, CCoolBarCtrl)
00042         //{{AFX_MSG_MAP(CLibraryHeaderBar)
00043         ON_COMMAND(ID_LIBRARY_VIEW, OnLibraryView)
00044         ON_WM_MEASUREITEM()
00045         ON_WM_DRAWITEM()
00046         ON_WM_MENUSELECT()
00047         ON_WM_ENTERIDLE()
00048         //}}AFX_MSG_MAP
00049 END_MESSAGE_MAP()
00050 
00051 
00053 // CLibraryHeaderBar construction
00054 
00055 CLibraryHeaderBar::CLibraryHeaderBar()
00056 {
00057         m_pLastView     = NULL;
00058         m_nImage        = NULL;
00059         m_pCoolMenu     = NULL;
00060 }
00061 
00062 CLibraryHeaderBar::~CLibraryHeaderBar()
00063 {
00064 }
00065 
00067 // CLibraryHeaderBar operations
00068 
00069 void CLibraryHeaderBar::Update(CLibraryView* pView)
00070 {
00071         CString strTitle;
00072         int nImage = SHI_FOLDER_CLOSED;
00073 
00074         if ( pView != NULL ) pView->GetHeaderContent( nImage, strTitle );
00075 
00076         if ( nImage != m_nImage || strTitle != m_sTitle )
00077         {
00078                 m_nImage        = nImage;
00079                 m_sTitle        = strTitle;
00080 
00081                 if (m_hWnd) Invalidate();
00082         }
00083 
00084         if ( pView != m_pLastView && ( m_pLastView = pView ) )
00085         {
00086                 if ( CCoolBarItem* pItem = GetID( ID_LIBRARY_VIEW ) )
00087                 {
00088                         CString strName;
00089                         Skin.LoadString( strName, pView->m_nCommandID );
00090                         LPCTSTR pszName = _tcschr( strName, '\n' );
00091                         pszName = ( pszName ) ? ( pszName + 1 ) : (LPCTSTR)strName;
00092                         pItem->SetImage( pView->m_nCommandID );
00093                         pItem->SetText( pszName );
00094                 }
00095 
00096                 OnUpdated();
00097         }
00098 }
00099 
00101 // CLibraryHeaderBar message handlers
00102 
00103 void CLibraryHeaderBar::PrepareRect(CRect* pRect) const
00104 {
00105         CCoolBarCtrl::PrepareRect( pRect );
00106         pRect->left -= 10;
00107         if ( m_czLast.cx < pRect->Width() ) pRect->left = pRect->right - m_czLast.cx;
00108         pRect->left += 10;
00109         pRect->bottom --;
00110 }
00111 
00112 void CLibraryHeaderBar::DoPaint(CDC* pDC, CRect& rcBar, BOOL bTransparent)
00113 {
00114         pDC->FillSolidRect( rcBar.left, rcBar.bottom - 1, rcBar.Width(), 1,
00115                 GetSysColor( COLOR_3DSHADOW ) );
00116         rcBar.bottom --;
00117 
00118         if ( m_czLast.cx < rcBar.Width() - 22 )
00119         {
00120                 CRect rcHeader( &rcBar );
00121                 rcHeader.right = rcBar.left = rcBar.right - m_czLast.cx;
00122                 PaintHeader( pDC, rcHeader, bTransparent );
00123         }
00124 
00125         CCoolBarCtrl::DoPaint( pDC, rcBar, bTransparent );
00126 }
00127 
00128 void CLibraryHeaderBar::PaintHeader(CDC* pDC, CRect& rcBar, BOOL bTransparent)
00129 {
00130         CFont* pOldFont = (CFont*)pDC->SelectObject( &CoolInterface.m_fntBold );
00131 
00132         CSize szText = pDC->GetTextExtent( m_sTitle );
00133 
00134         pDC->SetTextColor( CoolInterface.m_crCmdText );
00135         pDC->SetBkColor( CoolInterface.m_crMidtone );
00136 
00137         int nMiddle = ( rcBar.top + rcBar.bottom ) / 2;
00138 
00139         CString strText = m_sTitle;
00140 
00141         if ( pDC->GetTextExtent( strText ).cx > rcBar.Width() - 22 )
00142         {
00143                 while ( pDC->GetTextExtent( strText ).cx > rcBar.Width() - 30 && strText.GetLength() )
00144                 {
00145                         strText = strText.Left( strText.GetLength() - 1 );
00146                 }
00147 
00148                 strText += _T("...");
00149         }
00150 
00151         if ( bTransparent )
00152         {
00153                 if ( m_nImage )
00154                 {
00155                         ImageList_DrawEx( ShellIcons.GetHandle( 16 ), m_nImage, pDC->GetSafeHdc(),
00156                                 rcBar.left + 4, nMiddle - 8, 16, 16, CLR_NONE, CLR_NONE,
00157                                 ILD_NORMAL );
00158                 }
00159 
00160                 pDC->SetBkMode( TRANSPARENT );
00161                 pDC->ExtTextOut( rcBar.left + 22, nMiddle - szText.cy / 2,
00162                         ETO_CLIPPED, &rcBar, strText, NULL );
00163         }
00164         else
00165         {
00166                 pDC->SetBkMode( OPAQUE );
00167 
00168                 if ( m_nImage )
00169                 {
00170                         ImageList_DrawEx( ShellIcons.GetHandle( 16 ), m_nImage, pDC->GetSafeHdc(),
00171                                 rcBar.left + 4, nMiddle - 8, 16, 16, CoolInterface.m_crMidtone, CLR_NONE,
00172                                 ILD_NORMAL );
00173 
00174                         pDC->ExcludeClipRect( rcBar.left + 4, nMiddle - 8, rcBar.left + 20, nMiddle + 8 );
00175                 }
00176 
00177                 pDC->FillSolidRect( rcBar.left, rcBar.top, 20, rcBar.Height(),
00178                         CoolInterface.m_crMidtone );
00179 
00180                 rcBar.left += 20;
00181                 pDC->ExtTextOut( rcBar.left + 2, nMiddle - szText.cy / 2,
00182                         ETO_CLIPPED|ETO_OPAQUE, &rcBar, strText, NULL );
00183                 rcBar.left -= 20;
00184         }
00185 
00186         pDC->SelectObject( pOldFont );
00187 }
00188 
00190 // CLibraryHeaderBar view menu
00191 
00192 void CLibraryHeaderBar::OnLibraryView()
00193 {
00194         CMenu pMenu;
00195 
00196         pMenu.CreatePopupMenu();
00197 
00198         CLibraryFrame* pFrame   = (CLibraryFrame*)GetParent();
00199         CPtrList* pViews                = &pFrame->m_pViews;
00200 
00201         for ( POSITION pos = pViews->GetHeadPosition() ; pos ; )
00202         {
00203                 CLibraryView* pView = (CLibraryView*)pViews->GetNext( pos );
00204                 if ( ! pView->m_bAvailable ) continue;
00205 
00206                 CString strName;
00207                 Skin.LoadString( strName, pView->m_nCommandID );
00208                 LPCTSTR pszName = _tcschr( strName, '\n' );
00209                 pszName = ( pszName ) ? ( pszName + 1 ) : (LPCTSTR)strName;
00210 
00211                 pMenu.AppendMenu( MF_STRING | ( pView == m_pLastView ? MF_CHECKED : 0 ),
00212                         pView->m_nCommandID, pszName );
00213         }
00214 
00215         m_pCoolMenu = new CCoolMenu();
00216         m_pCoolMenu->AddMenu( &pMenu, TRUE );
00217         m_pCoolMenu->SetWatermark( Skin.GetWatermark( _T("CCoolMenu") ) );
00218 
00219         if ( UINT nCmd = ThrowMenu( ID_LIBRARY_VIEW, &pMenu, this, TRUE, TRUE ) )
00220         {
00221                 for ( POSITION pos = pViews->GetHeadPosition() ; pos ; )
00222                 {
00223                         CLibraryView* pView = (CLibraryView*)pViews->GetNext( pos );
00224 
00225                         if ( pView->m_nCommandID == nCmd )
00226                         {
00227                                 pFrame->SetView( pView );
00228                         }
00229                 }
00230         }
00231 
00232         delete m_pCoolMenu;
00233         m_pCoolMenu = NULL;
00234 }
00235 
00236 void CLibraryHeaderBar::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
00237 {
00238         if ( m_pCoolMenu ) m_pCoolMenu->OnMeasureItem( lpMeasureItemStruct );
00239 }
00240 
00241 void CLibraryHeaderBar::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
00242 {
00243         if ( m_pCoolMenu ) m_pCoolMenu->OnDrawItem( lpDrawItemStruct );
00244 }
00245 
00246 void CLibraryHeaderBar::OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu)
00247 {
00248         AfxGetMainWnd()->SendMessage( WM_MENUSELECT, MAKELONG( nItemID, nFlags ), (LPARAM)hSysMenu );
00249 }
00250 
00251 void CLibraryHeaderBar::OnEnterIdle(UINT nWhy, CWnd* pWho)
00252 {
00253         AfxGetMainWnd()->SendMessage( WM_ENTERIDLE, (WPARAM)nWhy, (LPARAM)pWho->GetSafeHwnd() );
00254 }

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