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

CtrlLibraryHeaderPanel.cpp

Go to the documentation of this file.
00001 //
00002 // CtrlLibraryHeaderPanel.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 "AlbumFolder.h"
00027 #include "Schema.h"
00028 #include "XML.h"
00029 
00030 #include "ShellIcons.h"
00031 #include "CoolInterface.h"
00032 #include "Skin.h"
00033 
00034 #include "CtrlLibraryFrame.h"
00035 #include "CtrlLibraryTree.h"
00036 #include "CtrlLibraryHeaderPanel.h"
00037 
00038 #ifdef _DEBUG
00039 #define new DEBUG_NEW
00040 #undef THIS_FILE
00041 static char THIS_FILE[] = __FILE__;
00042 #endif
00043 
00044 BEGIN_MESSAGE_MAP(CLibraryHeaderPanel, CWnd)
00045         //{{AFX_MSG_MAP(CLibraryHeaderPanel)
00046         ON_WM_SIZE()
00047         ON_WM_PAINT()
00048         ON_WM_SETCURSOR()
00049         ON_WM_LBUTTONUP()
00050         ON_WM_CREATE()
00051         ON_WM_DESTROY()
00052         //}}AFX_MSG_MAP
00053 END_MESSAGE_MAP()
00054 
00055 
00057 // CLibraryHeaderPanel construction
00058 
00059 CLibraryHeaderPanel::CLibraryHeaderPanel()
00060 {
00061 }
00062 
00063 CLibraryHeaderPanel::~CLibraryHeaderPanel()
00064 {
00065 }
00066 
00068 // CLibraryHeaderPanel operations
00069 
00070 BOOL CLibraryHeaderPanel::Create(CWnd* pParentWnd)
00071 {
00072         CRect rect( 0, 0, 0, 0 );
00073         return CWnd::Create( NULL, _T("CLibraryHeaderPanel"), WS_CHILD, rect,
00074                 pParentWnd, ID_LIBRARY_HEADER, NULL );
00075 }
00076 
00077 int CLibraryHeaderPanel::Update()
00078 {
00079         CAlbumFolder* pFolder = GetSelectedAlbum();
00080         if ( pFolder == NULL || pFolder->m_pSchema == NULL ) return 0;
00081 
00082         m_nIcon32       = pFolder->m_pSchema->m_nIcon32;
00083         m_nIcon48       = pFolder->m_pSchema->m_nIcon48;
00084 
00085         m_sTitle        = pFolder->m_pSchema->m_sHeaderTitle;
00086         m_sSubtitle     = pFolder->m_pSchema->m_sHeaderSubtitle;
00087 
00088         if ( pFolder->m_pParent == NULL )
00089         {
00090                 QWORD nTotalVolume;
00091                 DWORD nTotalFiles;
00092                 CString str;
00093 
00094                 LibraryMaps.GetStatistics( &nTotalFiles, &nTotalVolume );
00095                 str.Format( _T("%lu"), nTotalFiles );
00096                 Replace( m_sSubtitle, _T("{totalFiles}"), str );
00097                 str = Settings.SmartVolume( nTotalVolume, TRUE );
00098                 Replace( m_sSubtitle, _T("{totalVolume}"), str );
00099         }
00100 
00101         pFolder->m_pSchema->ResolveTokens( m_sTitle, pFolder->m_pXML );
00102         pFolder->m_pSchema->ResolveTokens( m_sSubtitle, pFolder->m_pXML );
00103 
00104         if ( m_sTitle.IsEmpty() ) m_sTitle = pFolder->m_sName;
00105 
00106         m_pMetadata.Setup( pFolder->m_pSchema );
00107         m_pMetadata.Remove( pFolder->m_pSchema->GetFirstMemberName() );
00108 
00109         m_pMetadata.Combine( pFolder->m_pXML );
00110 
00111         m_pMetadata.CreateLinks();
00112         m_pMetadata.Clean( 54 );
00113 
00114         if ( m_pMetadata.GetCount() )
00115         {
00116                 CClientDC dc( this );
00117                 CFont* pFont = (CFont*)dc.SelectObject( &CoolInterface.m_fntNormal );
00118                 m_nKeyWidth = m_nMetaWidth = 0;
00119                 m_pMetadata.ComputeWidth( &dc, m_nKeyWidth, m_nMetaWidth );
00120                 if ( m_nKeyWidth ) m_nKeyWidth += 8;
00121                 m_nMetaWidth += m_nKeyWidth;
00122                 dc.SelectObject( pFont );
00123         }
00124 
00125         if (m_hWnd) Invalidate();
00126 
00127         int nHeight = m_pMetadata.GetCount() * 12 + 8;
00128 
00129         if ( pFolder->m_pParent != NULL )
00130         {
00131                 nHeight = max( 64, nHeight );
00132         }
00133         else
00134         {
00135                 nHeight = max( 56, nHeight );
00136         }
00137 
00138         return min( 80, nHeight );
00139 }
00140 
00141 void CLibraryHeaderPanel::OnSkinChange()
00142 {
00143         if ( m_bmWatermark.m_hObject != NULL ) m_bmWatermark.DeleteObject();
00144 
00145         if ( HBITMAP hMark = Skin.GetWatermark( _T("CLibraryHeaderPanel") ) )
00146         {
00147                 m_bmWatermark.Attach( hMark );
00148         }
00149         else if ( Skin.m_crBannerBack == RGB( 122, 161, 230 ) )
00150         {
00151                 m_bmWatermark.LoadBitmap( IDB_BANNER_MARK );
00152         }
00153 }
00154 
00155 CAlbumFolder* CLibraryHeaderPanel::GetSelectedAlbum() const
00156 {
00157         if (!m_hWnd) return Library.GetAlbumRoot();
00158         CLibraryFrame* pFrame = (CLibraryFrame*)GetOwner();
00159         ASSERT_KINDOF(CLibraryFrame, pFrame );
00160 
00161         CLibraryTreeItem* pItem = pFrame->m_pFolderSelection;
00162         if ( pItem == NULL ) return Library.GetAlbumRoot();
00163         if ( pItem->m_pSelNext != NULL ) return NULL;
00164 
00165         return pItem->m_pVirtual;
00166 }
00167 
00169 // CLibraryHeaderPanel message handlers
00170 
00171 int CLibraryHeaderPanel::OnCreate(LPCREATESTRUCT lpCreateStruct)
00172 {
00173         if ( CWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
00174 
00175         m_szBuffer = CSize( 0, 0 );
00176         OnSkinChange();
00177 
00178         return 0;
00179 }
00180 
00181 void CLibraryHeaderPanel::OnDestroy()
00182 {
00183         CWnd::OnDestroy();
00184 
00185         if ( m_bmBuffer.m_hObject != NULL )
00186         {
00187                 m_dcBuffer.SelectObject( m_hBuffer );
00188                 m_dcBuffer.DeleteDC();
00189                 m_bmBuffer.DeleteObject();
00190         }
00191 }
00192 
00193 void CLibraryHeaderPanel::OnSize(UINT nType, int cx, int cy)
00194 {
00195         CWnd::OnSize( nType, cx, cy );
00196         Invalidate();
00197 }
00198 
00199 void CLibraryHeaderPanel::OnPaint()
00200 {
00201         CPaintDC dc( this );
00202         CRect rcClient;
00203 
00204         GetClientRect( &rcClient );
00205         if ( rcClient.IsRectEmpty() ) return;
00206 
00207         if ( rcClient.Width() > m_szBuffer.cx || rcClient.Height() > m_szBuffer.cy )
00208         {
00209                 if ( m_bmBuffer.m_hObject != NULL )
00210                 {
00211                         m_dcBuffer.SelectObject( m_hBuffer );
00212                         m_dcBuffer.DeleteDC();
00213                         m_bmBuffer.DeleteObject();
00214                 }
00215 
00216                 m_szBuffer = rcClient.Size();
00217                 m_bmBuffer.CreateCompatibleBitmap( &dc, m_szBuffer.cx, m_szBuffer.cy );
00218                 m_dcBuffer.CreateCompatibleDC( &dc );
00219                 m_hBuffer = (HBITMAP)m_dcBuffer.SelectObject( &m_bmBuffer )->m_hObject;
00220         }
00221 
00222         if ( ! CoolInterface.DrawWatermark( &m_dcBuffer, &rcClient, &m_bmWatermark, 0, 0 ) )
00223         {
00224                 m_dcBuffer.FillSolidRect( &rcClient, Skin.m_crBannerBack );
00225         }
00226 
00227         DoPaint( &m_dcBuffer, rcClient );
00228 
00229         dc.BitBlt( rcClient.left, rcClient.top, rcClient.Width(),
00230                 rcClient.Height(), &m_dcBuffer, 0, 0, SRCCOPY );
00231 }
00232 
00233 void CLibraryHeaderPanel::DoPaint(CDC* pDC, CRect& rcClient)
00234 {
00235         CFont* pOldFont = pDC->GetCurrentFont();
00236 
00237         CPoint ptIcon( 8, ( rcClient.top + rcClient.bottom ) / 2 - 24 );
00238 
00239         if ( m_nIcon48 >= 0 )
00240         {
00241                 ShellIcons.Draw( pDC, m_nIcon48, 48, ptIcon.x, ptIcon.y );
00242         }
00243         else if ( m_nIcon32 >= 0 )
00244         {
00245                 ptIcon.x += 8; ptIcon.y += 8;
00246                 ShellIcons.Draw( pDC, m_nIcon32, 32, ptIcon.x, ptIcon.y );
00247         }
00248 
00249         pDC->SetTextColor( Skin.m_crBannerText );
00250         pDC->SetBkMode( TRANSPARENT );
00251 
00252         CRect rcWork( &rcClient );
00253         rcWork.DeflateRect( 8, 4 );
00254         rcWork.left += 48 + 16;
00255 
00256         if ( m_pMetadata.GetCount() )
00257         {
00258                 CRect rcMeta( &rcWork );
00259                 rcMeta.left             = rcWork.right - m_nMetaWidth;
00260                 rcWork.right    = rcMeta.left - 8;
00261 
00262                 int nY = rcMeta.top;
00263 
00264                 for ( POSITION pos = m_pMetadata.GetIterator() ; pos && nY + 12 < rcMeta.bottom ; nY += 12 )
00265                 {
00266                         CMetaItem* pItem = m_pMetadata.GetNext( pos );
00267 
00268                         pDC->SelectObject( &CoolInterface.m_fntNormal );
00269                         DrawText( pDC, rcMeta.left, nY, theApp.m_bRTL ? ':' + pItem->m_sKey : pItem->m_sKey + ':' );
00270 
00271                         if ( pItem->m_bLink ) pDC->SelectObject( &CoolInterface.m_fntUnder );
00272                         DrawText( pDC, rcMeta.left + m_nKeyWidth, nY, pItem->m_sValue );
00273 
00274                         pItem->SetRect( rcMeta.left + m_nKeyWidth, nY, rcMeta.right, nY + 12 );
00275                 }
00276         }
00277 
00278         rcWork.DeflateRect( 0, 4 );
00279 
00280         pDC->SelectObject( &CoolInterface.m_fntCaption );
00281         Skin.DrawWrappedText( pDC, &rcWork, m_sTitle, NULL, FALSE );
00282         pDC->SelectObject( &CoolInterface.m_fntNormal );
00283         Skin.DrawWrappedText( pDC, &rcWork, m_sSubtitle, NULL, FALSE );
00284 
00285         pDC->SelectObject( pOldFont );
00286 }
00287 
00288 void CLibraryHeaderPanel::DrawText(CDC* pDC, int nX, int nY, LPCTSTR pszText)
00289 {
00290         CSize sz = pDC->GetTextExtent( pszText, _tcslen( pszText ) );
00291 
00292         CRect rc( nX - 2, nY - 2, nX + sz.cx + 2, nY + sz.cy + 2 );
00293 
00294         UINT nOptions = ETO_CLIPPED | ( theApp.m_bRTL ? ETO_RTLREADING : 0 );
00295         pDC->ExtTextOut( nX, nY, nOptions, &rc, pszText, _tcslen( pszText ), NULL );
00296 }
00297 
00298 BOOL CLibraryHeaderPanel::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
00299 {
00300         if ( m_pMetadata.OnSetCursor( this ) ) return TRUE;
00301 
00302         return CWnd::OnSetCursor( pWnd, nHitTest, message );
00303 }
00304 
00305 void CLibraryHeaderPanel::OnLButtonUp(UINT nFlags, CPoint point)
00306 {
00307         if ( CMetaItem* pItem = m_pMetadata.HitTest( point, TRUE ) )
00308         {
00309                 if ( CAlbumFolder* pFolder = pItem->GetLinkTarget() )
00310                 {
00311                         CLibraryFrame* pFrame = (CLibraryFrame*)GetOwner();
00312                         ASSERT_KINDOF(CLibraryFrame, pFrame );
00313                         pFrame->Display( pFolder );
00314                 }
00315         }
00316 
00317         CWnd::OnLButtonUp( nFlags, point );
00318 }

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