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

PageProfileAvatar.cpp

Go to the documentation of this file.
00001 //
00002 // PageProfileAvatar.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 "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         //{{AFX_MSG_MAP(CAvatarProfilePage)
00040         ON_WM_PAINT()
00041         ON_BN_CLICKED(IDC_AVATAR_BROWSE, OnAvatarBrowse)
00042         ON_BN_CLICKED(IDC_AVATAR_REMOVE, OnAvatarRemove)
00043         //}}AFX_MSG_MAP
00044 END_MESSAGE_MAP()
00045 
00046 
00048 // CAvatarProfilePage property page
00049 
00050 CAvatarProfilePage::CAvatarProfilePage() : CSettingsPage( CAvatarProfilePage::IDD )
00051 {
00052         //{{AFX_DATA_INIT(CAvatarProfilePage)
00053         //}}AFX_DATA_INIT
00054 }
00055 
00056 CAvatarProfilePage::~CAvatarProfilePage()
00057 {
00058 }
00059 
00060 void CAvatarProfilePage::DoDataExchange(CDataExchange* pDX)
00061 {
00062         CSettingsPage::DoDataExchange(pDX);
00063         //{{AFX_DATA_MAP(CAvatarProfilePage)
00064         DDX_Control(pDX, IDC_AVATAR_REMOVE, m_wndRemove);
00065         DDX_Control(pDX, IDC_PREVIEW, m_wndPreview);
00066         //}}AFX_DATA_MAP
00067 }
00068 
00070 // CAvatarProfilePage message handlers
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 }

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