00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Settings.h"
00025 #include "GProfile.h"
00026 #include "ImageServices.h"
00027 #include "PageProfileAvatar.h"
00028 #include "XML.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(CAvatarProfilePage, CSettingsPage)
00037
00038 BEGIN_MESSAGE_MAP(CAvatarProfilePage, CSettingsPage)
00039
00040 ON_WM_PAINT()
00041 ON_BN_CLICKED(IDC_AVATAR_BROWSE, OnAvatarBrowse)
00042 ON_BN_CLICKED(IDC_AVATAR_REMOVE, OnAvatarRemove)
00043
00044 END_MESSAGE_MAP()
00045
00046
00048
00049
00050 CAvatarProfilePage::CAvatarProfilePage() : CSettingsPage( CAvatarProfilePage::IDD )
00051 {
00052
00053
00054 }
00055
00056 CAvatarProfilePage::~CAvatarProfilePage()
00057 {
00058 }
00059
00060 void CAvatarProfilePage::DoDataExchange(CDataExchange* pDX)
00061 {
00062 CSettingsPage::DoDataExchange(pDX);
00063
00064 DDX_Control(pDX, IDC_AVATAR_REMOVE, m_wndRemove);
00065 DDX_Control(pDX, IDC_PREVIEW, m_wndPreview);
00066
00067 }
00068
00070
00071
00072 BOOL CAvatarProfilePage::OnInitDialog()
00073 {
00074 CSettingsPage::OnInitDialog();
00075
00076 if ( CXMLElement* pAvatar = MyProfile.GetXML( _T("avatar") ) )
00077 {
00078 m_sAvatar = pAvatar->GetAttributeValue( _T("path") );
00079 PrepareImage();
00080 }
00081
00082 return TRUE;
00083 }
00084
00085 void CAvatarProfilePage::OnOK()
00086 {
00087 if ( CXMLElement* pAvatar = MyProfile.GetXML( _T("avatar"), TRUE ) )
00088 {
00089 pAvatar->AddAttribute( _T("path"), m_sAvatar );
00090 }
00091
00092 CSettingsPage::OnOK();
00093 }
00094
00095 void CAvatarProfilePage::OnPaint()
00096 {
00097 CPaintDC dc( this );
00098 CRect rc;
00099
00100 m_wndPreview.GetWindowRect( &rc );
00101 ScreenToClient( &rc );
00102
00103 rc.right = rc.left + 128;
00104 rc.bottom = rc.top + 128;
00105
00106 if ( m_bmAvatar.m_hObject != NULL )
00107 {
00108 CDC dcMem;
00109 dcMem.CreateCompatibleDC( &dc );
00110 CBitmap* pOld = (CBitmap*)dcMem.SelectObject( &m_bmAvatar );
00111 dc.BitBlt( rc.left, rc.top, rc.Width(), rc.Height(), &dcMem, 0, 0, SRCCOPY );
00112 dcMem.SelectObject( pOld );
00113 }
00114 else
00115 {
00116 rc.InflateRect( 1, 1 );
00117 dc.Draw3dRect( &rc, GetSysColor( COLOR_ACTIVECAPTION ), GetSysColor( COLOR_ACTIVECAPTION ) );
00118 }
00119 }
00120
00121 void CAvatarProfilePage::OnAvatarBrowse()
00122 {
00123 CFileDialog dlg( TRUE, _T("png"), m_sAvatar, OFN_HIDEREADONLY,
00124 _T("Image Files|*.jpg;*.jpeg;*.png;*.bmp|All Files|*.*||"), this );
00125
00126 if ( dlg.DoModal() == IDOK )
00127 {
00128 m_sAvatar = dlg.GetPathName();
00129 PrepareImage();
00130 Invalidate();
00131 }
00132 }
00133
00134 void CAvatarProfilePage::OnAvatarRemove()
00135 {
00136 m_sAvatar.Empty();
00137 if ( m_bmAvatar.m_hObject != NULL ) m_bmAvatar.DeleteObject();
00138 Invalidate();
00139 }
00140
00141 void CAvatarProfilePage::PrepareImage()
00142 {
00143 if ( m_bmAvatar.m_hObject != NULL ) m_bmAvatar.DeleteObject();
00144 if ( m_sAvatar.IsEmpty() ) return;
00145
00146 CImageServices pService;
00147 CImageFile pFile( &pService );
00148
00149 CClientDC dc( this );
00150 SendMessage( WM_CTLCOLORSTATIC, (WPARAM)dc.GetSafeHdc(), (LPARAM)m_wndPreview.GetSafeHwnd() );
00151
00152 if ( pFile.LoadFromFile( m_sAvatar ) && pFile.EnsureRGB( dc.GetBkColor() ) )
00153 {
00154 pFile.Resample( 128, 128 );
00155 m_bmAvatar.Attach( pFile.CreateBitmap() );
00156 }
00157 }