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

PageFileComments.cpp

Go to the documentation of this file.
00001 //
00002 // PageFileComments.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 "SharedFile.h"
00027 #include "ShellIcons.h"
00028 #include "PageFileComments.h"
00029 
00030 #ifdef _DEBUG
00031 #define new DEBUG_NEW
00032 #undef THIS_FILE
00033 static char THIS_FILE[] = __FILE__;
00034 #endif
00035 
00036 IMPLEMENT_DYNCREATE(CFileCommentsPage, CFilePropertiesPage)
00037 
00038 BEGIN_MESSAGE_MAP(CFileCommentsPage, CFilePropertiesPage)
00039         //{{AFX_MSG_MAP(CFileCommentsPage)
00040         ON_WM_MEASUREITEM()
00041         ON_WM_DRAWITEM()
00042         //}}AFX_MSG_MAP
00043 END_MESSAGE_MAP()
00044 
00045 
00047 // CFileCommentsPage property page
00048 
00049 CFileCommentsPage::CFileCommentsPage() : CFilePropertiesPage( CFileCommentsPage::IDD )
00050 {
00051         //{{AFX_DATA_INIT(CFileCommentsPage)
00052         m_sComments = _T("");
00053         m_nRating = -1;
00054         //}}AFX_DATA_INIT
00055 }
00056 
00057 CFileCommentsPage::~CFileCommentsPage()
00058 {
00059 }
00060 
00061 void CFileCommentsPage::DoDataExchange(CDataExchange* pDX)
00062 {
00063         CPropertyPage::DoDataExchange(pDX);
00064         //{{AFX_DATA_MAP(CFileCommentsPage)
00065         DDX_Control(pDX, IDC_FILE_COMMENTS, m_wndComments);
00066         DDX_Control(pDX, IDC_FILE_RATING, m_wndRating);
00067         DDX_Text(pDX, IDC_FILE_COMMENTS, m_sComments);
00068         DDX_CBIndex(pDX, IDC_FILE_RATING, m_nRating);
00069         //}}AFX_DATA_MAP
00070 }
00071 
00073 // CFileCommentsPage message handlers
00074 
00075 BOOL CFileCommentsPage::OnInitDialog()
00076 {
00077         CFilePropertiesPage::OnInitDialog();
00078 
00079         CLibraryList* pFiles = GetList();
00080         if ( pFiles == NULL ) return TRUE;
00081 
00082         if ( pFiles->GetCount() == 1 )
00083         {
00084                 CQuickLock oLock( Library.m_pSection );
00085                 CLibraryFile* pFile = GetFile();
00086                 if ( pFile == NULL ) return TRUE;
00087 
00088                 m_nRating       = pFile->m_nRating;
00089                 m_sComments     = pFile->m_sComments;
00090         }
00091         else
00092         {
00093                 m_wndComments.EnableWindow( FALSE );
00094 
00095                 CQuickLock oLock( Library.m_pSection );
00096 
00097                 for ( POSITION pos = pFiles->GetIterator() ; pos ; )
00098                 {
00099                         if ( CLibraryFile* pFile = pFiles->GetNextFile( pos ) )
00100                         {
00101                                 m_nRating = pFile->m_nRating;
00102                         }
00103                 }
00104 
00105         }
00106 
00107         UpdateData( FALSE );
00108 
00109         return TRUE;
00110 }
00111 
00112 void CFileCommentsPage::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
00113 {
00114         lpMeasureItemStruct->itemWidth  = 1024;
00115         lpMeasureItemStruct->itemHeight = 18;
00116 }
00117 
00118 void CFileCommentsPage::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
00119 {
00120         if ( lpDrawItemStruct->itemID == (UINT)-1 ) return;
00121         if ( ( lpDrawItemStruct->itemAction & ODA_SELECT ) == 0 &&
00122                  ( lpDrawItemStruct->itemAction & ODA_DRAWENTIRE ) == 0 ) return;
00123 
00124         CRect rcItem( &lpDrawItemStruct->rcItem );
00125         CPoint pt( rcItem.left + 1, rcItem.top + 1 );
00126         CDC dc;
00127 
00128         dc.Attach( lpDrawItemStruct->hDC );
00129         if ( theApp.m_bRTL ) theApp.m_pfnSetLayout( dc.m_hDC, LAYOUT_RTL );
00130 
00131         int nRating = lpDrawItemStruct->itemID;
00132 
00133         CFont* pOldFont = (CFont*)dc.SelectObject( nRating > 0 ? &theApp.m_gdiFontBold : &theApp.m_gdiFont );
00134         dc.SetTextColor( GetSysColor( ( lpDrawItemStruct->itemState & ODS_SELECTED )
00135                 ? COLOR_HIGHLIGHTTEXT : COLOR_MENUTEXT ) );
00136 
00137         dc.FillSolidRect( &rcItem,
00138                 GetSysColor( ( lpDrawItemStruct->itemState & ODS_SELECTED )
00139                 ? COLOR_HIGHLIGHT : COLOR_WINDOW ) );
00140         dc.SetBkMode( TRANSPARENT );
00141 
00142         rcItem.DeflateRect( 4, 1 );
00143 
00144         if ( nRating > 1 )
00145         {
00146                 for ( int nStar = nRating - 1 ; nStar ; nStar-- )
00147                 {
00148                         rcItem.right -= 16;
00149                         ShellIcons.Draw( &dc, SHI_STAR, 16, rcItem.right, rcItem.top, CLR_NONE,
00150                                 ( lpDrawItemStruct->itemState & ODS_SELECTED ) );
00151                         rcItem.right -= 2;
00152                 }
00153         }
00154         else if ( nRating == 1 )
00155         {
00156                 rcItem.right -= 16;
00157                 ShellIcons.Draw( &dc, SHI_FAKE, 16, rcItem.right, rcItem.top, CLR_NONE,
00158                         ( lpDrawItemStruct->itemState & ODS_SELECTED ) );
00159         }
00160 
00161         if ( ( lpDrawItemStruct->itemState & ODS_SELECTED ) == 0 )
00162         {
00163                 static COLORREF crRating[7] =
00164                 {
00165                         RGB( 0, 0, 0 ),                 // Unrated
00166                         RGB( 255, 0, 0 ),               // 0 - Fake
00167                         RGB( 128, 128, 128 ),   // 1 - Poor
00168                         RGB( 0, 0, 0 ),                 // 2 - Average
00169                         RGB( 128, 128, 128 ),   // 3 - Good
00170                         RGB( 0, 128, 0 ),               // 4 - Very good
00171                         RGB( 0, 0, 255 ),               // 5 - Excellent
00172                 };
00173 
00174                 dc.SetTextColor( crRating[ nRating ] );
00175         }
00176 
00177         CString str;
00178         m_wndRating.GetLBText( nRating, str );
00179         dc.DrawText( str, &rcItem, DT_SINGLELINE|DT_LEFT|DT_VCENTER|DT_NOPREFIX );
00180 
00181         dc.SelectObject( pOldFont );
00182         dc.Detach();
00183 }
00184 
00185 void CFileCommentsPage::OnOK()
00186 {
00187         UpdateData();
00188         m_sComments.TrimLeft();
00189         m_sComments.TrimRight();
00190 
00191         CLibraryList* pFiles = GetList();
00192 
00193         if ( pFiles == NULL || pFiles->GetCount() == 1 )
00194         {
00195                 CQuickLock oLock( Library.m_pSection );
00196                 if ( CLibraryFile* pFile = GetFile() )
00197                 {
00198                         pFile->m_nRating        = m_nRating;
00199                         pFile->m_sComments      = m_sComments;
00200 
00201                         pFile->SaveMetadata();
00202                         Library.Update();
00203                 }
00204         }
00205         else
00206         {
00207                 CQuickLock oLock( Library.m_pSection );
00208 
00209                 for ( POSITION pos = pFiles->GetIterator() ; pos ; )
00210                 {
00211                         if ( CLibraryFile* pFile = pFiles->GetNextFile( pos ) )
00212                         {
00213                                 pFile->m_nRating = m_nRating;
00214                         }
00215                 }
00216 
00217                 Library.Update();
00218         }
00219 
00220         CFilePropertiesPage::OnOK();
00221 }

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