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

MetaPanel.cpp

Go to the documentation of this file.
00001 //
00002 // MetaPanel.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 "MetaPanel.h"
00025 #include "CoolInterface.h"
00026 #include "Skin.h"
00027 
00028 #include "Library.h"
00029 #include "WndMain.h"
00030 #include "WndLibrary.h"
00031 #include "CtrlLibraryFrame.h"
00032 
00033 #ifdef _DEBUG
00034 #undef THIS_FILE
00035 static char THIS_FILE[]=__FILE__;
00036 #define new DEBUG_NEW
00037 #endif
00038 
00039 
00041 // CMetaPanel construction
00042 
00043 CMetaPanel::CMetaPanel()
00044 {
00045         m_nHeight = 0;
00046 }
00047 
00048 CMetaPanel::~CMetaPanel()
00049 {
00050 }
00051 
00053 // CMetaPanel layout
00054 
00055 int CMetaPanel::Layout(CDC* pDC, int nWidth)
00056 {
00057         int nSmall      = ( nWidth >= 400 ) ? nWidth / 2 - 100 - 3 : 0;
00058         int nLarge      = nWidth - 100 - 3;
00059         
00060         m_nHeight = 0;
00061         
00062         CFont* pOld = (CFont*)pDC->SelectObject( &CoolInterface.m_fntNormal );
00063         
00064         for ( POSITION pos = GetIterator() ; pos ; )
00065         {
00066                 CMetaItem* pItem = GetNext( pos );
00067                 CSize sz = pDC->GetTextExtent( pItem->m_sValue );
00068                 
00069                 if ( sz.cx <= nSmall )
00070                 {
00071                         pItem->m_bFullWidth     = FALSE;
00072                         pItem->m_nHeight        = 18;
00073                         
00074                         if ( CMetaItem* pNext = GetNext( pos ) )
00075                         {
00076                                 sz = pDC->GetTextExtent( pNext->m_sValue );
00077                                 
00078                                 if ( sz.cx <= nSmall )
00079                                 {
00080                                         pNext->m_bFullWidth     = FALSE;
00081                                         pNext->m_nHeight        = 18;
00082                                 }
00083                                 else if ( pos )
00084                                 {
00085                                         pItem->m_bFullWidth = TRUE;
00086                                         m_pItems.GetPrev( pos );
00087                                 }
00088                                 else
00089                                 {
00090                                         pItem->m_bFullWidth = TRUE;
00091                                         pos = m_pItems.GetTailPosition();
00092                                 }
00093                         }
00094                         else
00095                         {
00096                                 pItem->m_bFullWidth = TRUE;
00097                         }
00098                         
00099                         m_nHeight += 20;
00100                 }
00101                 else
00102                 {
00103                         if ( sz.cx > nLarge )
00104                         {
00105                                 CRect rcText( 0, 0, nLarge, 0xFFFF );
00106                                 Skin.DrawWrappedText( pDC, &rcText, pItem->m_sValue, NULL, FALSE );
00107                                 pItem->m_bFullWidth     = TRUE+TRUE;
00108                                 pItem->m_nHeight        = rcText.top + 4;
00109                                 m_nHeight += pItem->m_nHeight + 2;
00110                         }
00111                         else
00112                         {
00113                                 pItem->m_bFullWidth = TRUE;
00114                                 pItem->m_nHeight        = 18;
00115                                 m_nHeight += 20;
00116                         }
00117                 }
00118         }
00119         
00120         pDC->SelectObject( pOld );
00121         
00122         return m_nHeight;
00123 }
00124 
00126 // CMetaPanel paint
00127 
00128 void CMetaPanel::Paint(CDC* pDC, const CRect* prcArea)
00129 {
00130         POSITION pos = GetIterator();
00131         CRect rcWork( prcArea );
00132         DWORD dwFlags = ( theApp.m_bRTL ? ETO_RTLREADING : 0 );
00133         
00134         for ( int nRow = 0 ; pos ; nRow++ )
00135         {
00136                 pDC->SetBkColor( Skin.m_crSchemaRow[ nRow & 1 ] );
00137                 int nHeight = 0;
00138                 
00139                 for ( int nColumn = 0 ; nColumn < 2 && pos ; nColumn++ )
00140                 {
00141                         CMetaItem* pItem = GetNext( pos );
00142                                                 
00143                         CRect rcValue( rcWork.left, rcWork.top, rcWork.left, rcWork.top + pItem->m_nHeight );
00144                         
00145                         if ( pItem->m_bFullWidth )
00146                         {
00147                                 if ( nColumn > 0 )
00148                                 {
00149                                         if ( pos ) m_pItems.GetPrev( pos ); else pos = m_pItems.GetTailPosition();
00150                                         break;
00151                                 }
00152                                 
00153                                 rcValue.right   = rcWork.right;
00154                         }
00155                         else
00156                         {
00157                                 rcValue.left    += nColumn * rcWork.Width() / 2 + 1;
00158                                 rcValue.right   += ( nColumn + 1 ) * rcWork.Width() / 2 - 1;
00159                         }
00160                         
00161                         CRect rcKey( rcValue.left, rcValue.top, rcValue.left + 100, rcValue.bottom );
00162                         rcValue.left = rcKey.right;
00163                         
00164                         pDC->SetTextColor( CoolInterface.m_crText );
00165                         pDC->SelectObject( &CoolInterface.m_fntBold );
00166                         
00167                         pDC->ExtTextOut( rcKey.left + 3, rcKey.top + 2, ETO_CLIPPED|ETO_OPAQUE,
00168                                 &rcKey, pItem->m_sKey + ':', NULL );
00169                         
00170                         if ( pItem->m_bLink )
00171                         {
00172                                 pDC->SetTextColor( RGB( 0, 0, 255 ) );
00173                                 pDC->SelectObject( &CoolInterface.m_fntUnder );
00174                         }
00175                         else
00176                         {
00177                                 pDC->SelectObject( &CoolInterface.m_fntNormal );
00178                         }
00179                         
00180                         if ( pItem->m_bFullWidth == 2 )
00181                         {
00182                                 CRect rcText( &rcValue );
00183                                 rcText.DeflateRect( 3, 2 );
00184                                 Skin.DrawWrappedText( pDC, &rcText, pItem->m_sValue, NULL, TRUE );
00185                                 pDC->ExtTextOut( rcValue.left, rcValue.top, ETO_OPAQUE|dwFlags, &rcValue, NULL, 0, NULL );
00186                                 pItem->m_rect.CopyRect( &rcValue );
00187                         }
00188                         else
00189                         {
00190                                 pDC->ExtTextOut( rcValue.left + 3, rcValue.top + 2, ETO_CLIPPED|ETO_OPAQUE|dwFlags,
00191                                         &rcValue, pItem->m_sValue, NULL );
00192                                 
00193                                 pItem->m_rect.CopyRect( &rcValue );
00194                                 
00195                                 pItem->m_rect.right = pItem->m_rect.left + 6 +
00196                                         pDC->GetTextExtent( pItem->m_sValue ).cx;
00197                         }
00198                         
00199                         pDC->ExcludeClipRect( &rcKey );
00200                         pDC->ExcludeClipRect( &rcValue );
00201                         
00202                         nHeight = pItem->m_nHeight;
00203                         if ( pItem->m_bFullWidth ) break;
00204                 }
00205                 
00206                 rcWork.top += nHeight + 2;
00207         }
00208 }
00209 
00211 // CMetaPanel click handler
00212 
00213 BOOL CMetaPanel::OnClick(const CPoint& point)
00214 {
00215         if ( CMetaItem* pItem = HitTest( point, TRUE ) )
00216         {
00217                 if ( CAlbumFolder* pFolder = pItem->GetLinkTarget() )
00218                 {
00219                         CMainWnd* pMainWnd = (CMainWnd*)AfxGetMainWnd();
00220                         if ( CLibraryWnd* pLibraryWnd = (CLibraryWnd*)pMainWnd->m_pWindows.Open( RUNTIME_CLASS(CLibraryWnd) ) )
00221                         {
00222                                 CLibraryFrame* pFrame = &pLibraryWnd->m_wndFrame;
00223                                 ASSERT_KINDOF(CLibraryFrame, pFrame );
00224                                 pFrame->Display( pFolder );
00225                                 return TRUE;
00226                         }
00227                 }
00228         }
00229         
00230         return FALSE;
00231 }

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