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

WizardSheet.cpp

Go to the documentation of this file.
00001 //
00002 // WizardSheet.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 "Skin.h"
00026 #include "SkinWindow.h"
00027 #include "GProfile.h"
00028 
00029 #include "WizardSheet.h"
00030 #include "WizardWelcomePage.h"
00031 #include "WizardInterfacePage.h"
00032 #include "WizardConnectionPage.h"
00033 #include "WizardSharePage.h"
00034 #include "WizardProfilePage.h"
00035 #include "WizardNetworksPage.h"
00036 #include "WizardFinishedPage.h"
00037 
00038 #ifdef _DEBUG
00039 #define new DEBUG_NEW
00040 #undef THIS_FILE
00041 static char THIS_FILE[] = __FILE__;
00042 #endif
00043 
00044 
00046 // CWizardSheet
00047 
00048 BEGIN_MESSAGE_MAP(CWizardSheet, CPropertySheet)
00049         //{{AFX_MSG_MAP(CWizardSheet)
00050         ON_WM_PAINT()
00051         ON_WM_ERASEBKGND()
00052         ON_WM_SIZE()
00053         ON_WM_NCHITTEST()
00054         ON_WM_NCACTIVATE()
00055         ON_WM_NCPAINT()
00056         ON_WM_NCLBUTTONDOWN()
00057         ON_WM_NCLBUTTONUP()
00058         ON_WM_NCLBUTTONDBLCLK()
00059         ON_WM_NCMOUSEMOVE()
00060         //}}AFX_MSG_MAP
00061         ON_MESSAGE(WM_SETTEXT, OnSetText)
00062 END_MESSAGE_MAP()
00063 
00065 // CWizardSheet run wizard
00066 
00067 BOOL CWizardSheet::RunWizard(CWnd* pParent)
00068 {
00069         BOOL bSuccess = FALSE;
00070 
00071         for ( int nAttempt = 0 ; nAttempt < 2 ; nAttempt ++ )
00072         {
00073                 CWizardSheet pSheet( pParent, nAttempt ? 3 : 0 );
00074 
00075                 CWizardWelcomePage              pWelcome;
00076                 CWizardConnectionPage   pConnection;
00077                 CWizardSharePage                pShare;
00078                 CWizardProfilePage              pProfile;
00079                 CWizardInterfacePage    pInterface;
00080                 CWizardNetworksPage             pNetworks;
00081                 CWizardFinishedPage             pFinished;
00082 
00083                 pSheet.AddPage( &pWelcome );
00084                 pSheet.AddPage( &pConnection );
00085                 pSheet.AddPage( &pShare );
00086                 pSheet.AddPage( &pProfile );
00087                 pSheet.AddPage( &pInterface );
00088                 pSheet.AddPage( &pNetworks );
00089                 pSheet.AddPage( &pFinished );
00090 
00091                 bSuccess |= ( pSheet.DoModal() == IDOK );
00092                 Settings.Save();
00093 
00094                 if ( pProfile.m_pWorld != NULL ) break;
00095                 if ( MyProfile.GetNick().GetLength() && MyProfile.GetLocation().GetLength() ) break;
00096         }
00097 
00098         return bSuccess;
00099 }
00100 
00101 
00103 // CWizardSheet construction
00104 
00105 CWizardSheet::CWizardSheet(CWnd *pParentWnd, UINT iSelectPage)
00106 {
00107         m_pSkin = NULL;
00108         m_psh.dwFlags &= ~PSP_HASHELP;
00109 
00110         Construct( _T(""), pParentWnd, iSelectPage );
00111         SetWizardMode();
00112 }
00113 
00114 CWizardSheet::~CWizardSheet()
00115 {
00116 }
00117 
00119 // CWizardSheet message handlers
00120 
00121 BOOL CWizardSheet::OnInitDialog()
00122 {
00123         CPropertySheet::OnInitDialog();
00124         CRect rc;
00125 
00126         CString strMessage;
00127 
00128         SetIcon( theApp.LoadIcon( IDR_MAINFRAME ), TRUE );
00129         SetFont( &theApp.m_gdiFont );
00130 
00131         GetClientRect( &rc );
00132 
00133         /*
00134         if ( m_pSkin = Skin.GetWindowSkin( _T("CWizardSheet") ) )
00135         {
00136                 m_pSkin->CalcWindowRect( &rc );
00137                 SetWindowPos( NULL, 0, 0, rc.Width(), rc.Height(), SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE );
00138         }
00139         */
00140 
00141         GetDlgItem( 0x3023 )->GetWindowRect( &rc );
00142         ScreenToClient( &rc );
00143         rc.OffsetRect( 95 + 6 - rc.left, 0 );
00144         GetDlgItem( 0x3023 )->MoveWindow( &rc );
00145 
00146         GetDlgItem( 0x3024 )->GetWindowRect( &rc );
00147         ScreenToClient( &rc );
00148         rc.OffsetRect( 95 + 88 - rc.left, 0 );
00149         GetDlgItem( 0x3024 )->MoveWindow( &rc );
00150         GetDlgItem( 0x3025 )->MoveWindow( &rc );
00151 
00152         GetDlgItem( 2 )->GetWindowRect( &rc );
00153         ScreenToClient( &rc );
00154         rc.OffsetRect( 95 + 170 - rc.left, 0 );
00155         GetDlgItem( 2 )->MoveWindow( &rc );
00156         LoadString( strMessage, IDS_WIZARD_EXIT );
00157         GetDlgItem( 2 )->SetWindowText( strMessage );
00158 
00159         if ( GetDlgItem( 0x0009 ) ) GetDlgItem( 0x0009 )->ShowWindow( SW_HIDE );
00160         if ( GetDlgItem( 0x3026 ) ) GetDlgItem( 0x3026 )->ShowWindow( SW_HIDE );
00161 
00162         m_bmHeader.LoadBitmap( IDB_WIZARD );
00163 
00164         return TRUE;
00165 }
00166 
00167 BOOL CWizardSheet::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
00168 {
00169         CWnd* pWnd = GetActivePage();
00170 
00171         if ( pWnd != NULL )
00172         {
00173                 if ( GetWindowLong( pWnd->GetSafeHwnd(), GWL_USERDATA ) == TRUE )
00174                 {
00175                         pWnd = NULL;
00176                 }
00177                 else
00178                 {
00179                         SetWindowLong( pWnd->GetSafeHwnd(), GWL_USERDATA, TRUE );
00180                         pWnd->SetFont( &theApp.m_gdiFont, FALSE );
00181                         pWnd = pWnd->GetWindow( GW_CHILD );
00182                 }
00183         }
00184 
00185         while ( pWnd != NULL )
00186         {
00187                 TCHAR szName[32];
00188 
00189                 GetClassName( pWnd->GetSafeHwnd(), szName, 32 );
00190 
00191                 if ( !_tcscmp( szName, _T("Static") ) )
00192                 {
00193                         pWnd->SetFont( &theApp.m_gdiFont, FALSE );
00194 
00195                 }
00196                 else if ( _tcscmp( szName, _T("RICHEDIT") ) )
00197                 {
00198                         pWnd->SetFont( &theApp.m_gdiFont, TRUE );
00199                 }
00200 
00201                 pWnd = pWnd->GetNextWindow();
00202         }
00203 
00204         return CPropertySheet::OnChildNotify( message, wParam, lParam, pLResult );
00205 }
00206 
00207 void CWizardSheet::OnSize(UINT nType, int cx, int cy)
00208 {
00209         if ( m_pSkin ) m_pSkin->OnSize( this );
00210 
00211         CPropertySheet::OnSize( nType, cx, cy );
00212 
00213         if ( CWnd* pWnd = GetWindow( GW_CHILD ) )
00214         {
00215                 GetClientRect( &m_rcPage );
00216 
00217                 m_rcPage.top += 51;     // 50
00218                 m_rcPage.bottom -= 48;
00219 
00220                 pWnd->SetWindowPos( NULL, m_rcPage.left, m_rcPage.top, m_rcPage.Width(),
00221                         m_rcPage.Height(), SWP_NOSIZE );
00222         }
00223 }
00224 
00225 BOOL CWizardSheet::OnEraseBkgnd(CDC* pDC)
00226 {
00227         return TRUE;
00228 }
00229 
00230 void CWizardSheet::OnPaint()
00231 {
00232         CPaintDC dc( this );
00233         CRect rc;
00234 
00235         GetClientRect( &rc );
00236 
00237         CDC mdc;
00238         mdc.CreateCompatibleDC( &dc );
00239         CBitmap* pOldBitmap = (CBitmap*)mdc.SelectObject( &m_bmHeader );
00240         dc.BitBlt( 0, 0, 438, 50, &mdc, 0, 0, SRCCOPY );
00241         mdc.SelectObject( pOldBitmap );
00242         mdc.DeleteDC();
00243 
00244         dc.Draw3dRect( 0, 50, rc.Width() + 1, 1,
00245                 RGB( 128, 128, 128 ), RGB( 128, 128, 128 ) );
00246 
00247         dc.Draw3dRect( 0, rc.bottom - 48, rc.Width() + 1, 2,
00248                 RGB( 128, 128, 128 ), RGB( 255, 255, 255 ) );
00249 
00250         dc.FillSolidRect( rc.left, rc.bottom - 46, rc.Width(), 46, GetSysColor( COLOR_BTNFACE ) );
00251 }
00252 
00254 // CWizardSheet skin support
00255 
00256 void CWizardSheet::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
00257 {
00258         if ( m_pSkin )
00259                 m_pSkin->OnNcCalcSize( this, bCalcValidRects, lpncsp );
00260         else
00261                 CPropertySheet::OnNcCalcSize( bCalcValidRects, lpncsp );
00262 }
00263 
00264 UINT CWizardSheet::OnNcHitTest(CPoint point)
00265 {
00266         if ( m_pSkin )
00267                 return m_pSkin->OnNcHitTest( this, point, FALSE );
00268         else
00269                 return CPropertySheet::OnNcHitTest( point );
00270 }
00271 
00272 BOOL CWizardSheet::OnNcActivate(BOOL bActive)
00273 {
00274         if ( m_pSkin )
00275         {
00276                 BOOL bVisible = IsWindowVisible();
00277                 if ( bVisible ) ModifyStyle( WS_VISIBLE, 0 );
00278                 BOOL bResult = CPropertySheet::OnNcActivate( bActive );
00279                 if ( bVisible ) ModifyStyle( 0, WS_VISIBLE );
00280                 m_pSkin->OnNcActivate( this, bActive || ( m_nFlags & WF_STAYACTIVE ) );
00281                 return bResult;
00282         }
00283         else
00284         {
00285                 return CPropertySheet::OnNcActivate( bActive );
00286         }
00287 }
00288 
00289 void CWizardSheet::OnNcPaint()
00290 {
00291         if ( m_pSkin )
00292                 m_pSkin->OnNcPaint( this );
00293         else
00294                 CPropertySheet::OnNcPaint();
00295 }
00296 
00297 void CWizardSheet::OnNcLButtonDown(UINT nHitTest, CPoint point)
00298 {
00299         if ( m_pSkin && m_pSkin->OnNcLButtonDown( this, nHitTest, point ) ) return;
00300         CPropertySheet::OnNcLButtonDown(nHitTest, point);
00301 }
00302 
00303 void CWizardSheet::OnNcLButtonUp(UINT nHitTest, CPoint point)
00304 {
00305         if ( m_pSkin && m_pSkin->OnNcLButtonUp( this, nHitTest, point ) ) return;
00306         CPropertySheet::OnNcLButtonUp( nHitTest, point );
00307 }
00308 
00309 void CWizardSheet::OnNcLButtonDblClk(UINT nHitTest, CPoint point)
00310 {
00311         if ( m_pSkin && m_pSkin->OnNcLButtonDblClk( this, nHitTest, point ) ) return;
00312         CPropertySheet::OnNcLButtonDblClk( nHitTest, point );
00313 }
00314 
00315 void CWizardSheet::OnNcMouseMove(UINT nHitTest, CPoint point)
00316 {
00317         if ( m_pSkin ) m_pSkin->OnNcMouseMove( this, nHitTest, point );
00318         CPropertySheet::OnNcMouseMove( nHitTest, point );
00319 }
00320 
00321 LONG CWizardSheet::OnSetText(WPARAM wParam, LPARAM lParam)
00322 {
00323         if ( m_pSkin )
00324         {
00325                 BOOL bVisible = IsWindowVisible();
00326                 if ( bVisible ) ModifyStyle( WS_VISIBLE, 0 );
00327                 LONG lResult = Default();
00328                 if ( bVisible ) ModifyStyle( 0, WS_VISIBLE );
00329                 if ( m_pSkin ) m_pSkin->OnSetText( this );
00330                 return lResult;
00331         }
00332         else
00333         {
00334                 return Default();
00335         }
00336 }
00337 
00338 
00340 // CWizardPage
00341 
00342 IMPLEMENT_DYNCREATE(CWizardPage, CPropertyPage)
00343 
00344 BEGIN_MESSAGE_MAP(CWizardPage, CPropertyPage)
00345         //{{AFX_MSG_MAP(CWizardPage)
00346         ON_WM_SIZE()
00347         ON_WM_CTLCOLOR()
00348         //}}AFX_MSG_MAP
00349 END_MESSAGE_MAP()
00350 
00351 
00353 // CWizardPage construction
00354 
00355 CWizardPage::CWizardPage(UINT nID) : CPropertyPage( nID )
00356 {
00357         m_crWhite = RGB( 255, 255, 255 );
00358         m_brWhite.CreateSolidBrush( m_crWhite );
00359 }
00360 
00361 CWizardPage::~CWizardPage()
00362 {
00363 }
00364 
00366 // CWizardPage message handlers
00367 
00368 HBRUSH CWizardPage::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
00369 {
00370         pDC->SetBkColor( m_crWhite );
00371         return (HBRUSH)m_brWhite.GetSafeHandle();
00372 }
00373 
00374 void CWizardPage::OnSize(UINT nType, int cx, int cy)
00375 {
00376         CPropertyPage::OnSize(nType, cx, cy);
00377 
00378         CWizardSheet* pSheet = (CWizardSheet*)GetParent();
00379 
00380         if ( cx != pSheet->m_rcPage.Width() )
00381         {
00382                 MoveWindow( &pSheet->m_rcPage );
00383         }
00384 }
00385 
00387 // CWizardPage operations
00388 
00389 CWizardSheet* CWizardPage::GetSheet()
00390 {
00391         return (CWizardSheet*)GetParent();
00392 }
00393 
00394 void CWizardPage::SetWizardButtons(DWORD dwFlags)
00395 {
00396         GetSheet()->SetWizardButtons( dwFlags );
00397 }
00398 
00399 void CWizardPage::StaticReplace(LPCTSTR pszSearch, LPCTSTR pszReplace)
00400 {
00401         for ( CWnd* pChild = GetWindow( GW_CHILD ) ; pChild ; pChild = pChild->GetNextWindow() )
00402         {
00403                 TCHAR szName[32];
00404                 GetClassName( pChild->GetSafeHwnd(), szName, 32 );
00405 
00406                 if ( _tcscmp( szName, _T("Static") ) ) continue;
00407 
00408                 CString strText;
00409                 pChild->GetWindowText( strText );
00410 
00411                 while ( TRUE )
00412                 {
00413                         int nPos = strText.Find( pszSearch );
00414                         if ( nPos < 0 ) break;
00415                         strText = strText.Left( nPos ) + CString( pszReplace )
00416                                         + strText.Mid( nPos + _tcslen( pszSearch ) );
00417                 }
00418 
00419                 pChild->SetWindowText( strText );
00420         }
00421 }

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