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

DlgSkinDialog.cpp

Go to the documentation of this file.
00001 //
00002 // DlgSkinDialog.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 "DlgSkinDialog.h"
00025 #include "CoolInterface.h"
00026 #include "Skin.h"
00027 #include "SkinWindow.h"
00028 
00029 #ifdef _DEBUG
00030 #define new DEBUG_NEW
00031 #undef THIS_FILE
00032 static char THIS_FILE[] = __FILE__;
00033 #endif
00034 
00035 IMPLEMENT_DYNAMIC(CSkinDialog, CDialog)
00036 
00037 BEGIN_MESSAGE_MAP(CSkinDialog, CDialog)
00038         //{{AFX_MSG_MAP(CSkinDialog)
00039         ON_WM_NCCALCSIZE()
00040         ON_WM_NCHITTEST()
00041         ON_WM_NCACTIVATE()
00042         ON_WM_NCPAINT()
00043         ON_WM_NCLBUTTONDOWN()
00044         ON_WM_NCLBUTTONUP()
00045         ON_WM_NCLBUTTONDBLCLK()
00046         ON_WM_NCMOUSEMOVE()
00047         ON_WM_SIZE()
00048         ON_WM_ERASEBKGND()
00049         ON_MESSAGE(WM_SETTEXT, OnSetText)
00050         ON_WM_CTLCOLOR()
00051         ON_WM_WINDOWPOSCHANGING()
00052         ON_WM_CREATE()
00053         //}}AFX_MSG_MAP
00054 END_MESSAGE_MAP()
00055 
00056 
00058 // CSkinDialog dialog
00059 
00060 CSkinDialog::CSkinDialog(UINT nResID, CWnd* pParent) : CDialog( nResID, pParent )
00061 {
00062         //{{AFX_DATA_INIT(CSkinDialog)
00063         //}}AFX_DATA_INIT
00064         m_pSkin = NULL;
00065 }
00066 
00067 void CSkinDialog::DoDataExchange(CDataExchange* pDX)
00068 {
00069         CDialog::DoDataExchange(pDX);
00070         //{{AFX_DATA_MAP(CSkinDialog)
00071         //}}AFX_DATA_MAP
00072 }
00073 
00075 // CSkinDialog operations
00076 
00077 BOOL CSkinDialog::SkinMe(LPCTSTR pszSkin, UINT nIcon, BOOL bLanguage)
00078 {
00079         BOOL bSuccess = FALSE;
00080         CString strSkin;
00081         CRect rc;
00082 
00083         GetClientRect( &rc );
00084 
00085         if ( pszSkin == NULL )
00086                 strSkin = GetRuntimeClass()->m_lpszClassName;
00087         else
00088                 strSkin = pszSkin;
00089 
00090         m_pSkin = ::Skin.GetWindowSkin( strSkin );
00091         if ( NULL == m_pSkin ) m_pSkin = ::Skin.GetWindowSkin( this );
00092 
00093         if ( bLanguage )
00094         {
00095                 bSuccess = ::Skin.Apply( strSkin, this, nIcon );
00096         }
00097         if ( nIcon || theApp.m_bRTL && nIcon )
00098         {
00099                 HICON hIcon = CoolInterface.ExtractIcon( nIcon );
00100                 
00101                 if ( ! hIcon ) hIcon = (HICON)LoadImage( AfxGetInstanceHandle(),
00102                         MAKEINTRESOURCE( nIcon ), IMAGE_ICON, 16, 16, 0 );
00103                 if ( theApp.m_bRTL )
00104                 {
00105                         // no idea why some dialogs get mirrored icons
00106                         if ( nIcon != ID_HELP_ABOUT )
00107                                 hIcon = CreateMirroredIcon( hIcon );
00108                 }
00109 
00110                 if ( hIcon ) SetIcon( hIcon, FALSE );
00111         }
00112 
00113         if ( m_pSkin != NULL )
00114         {
00115                 if ( GetStyle() & WS_CAPTION ) ModifyStyle( WS_CAPTION, 0 );
00116 
00117                 m_pSkin->CalcWindowRect( &rc );
00118 
00119                 SetWindowRgn( NULL, FALSE );
00120                 SetWindowPos( NULL, 0, 0, rc.Width(), rc.Height(),
00121                         SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_FRAMECHANGED );
00122 
00123                 m_pSkin->OnSize( this );
00124         }
00125         else
00126         {
00127                 if ( ( GetStyle() & WS_CAPTION ) == 0 ) ModifyStyle( 0, WS_CAPTION );
00128 
00129                 CalcWindowRect( &rc );
00130                 SetWindowRgn( NULL, FALSE );
00131                 SetWindowPos( NULL, 0, 0, rc.Width(), rc.Height(),
00132                         SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_FRAMECHANGED );
00133         }
00134 
00135         return bSuccess || m_pSkin != NULL;
00136 }
00137 
00138 BOOL CSkinDialog::SelectCaption(CWnd* pWnd, int nIndex)
00139 {
00140         return ::Skin.SelectCaption( pWnd, nIndex );
00141 }
00142 
00144 // CSkinDialog message handlers
00145 
00146 void CSkinDialog::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
00147 {
00148         if ( m_pSkin )
00149                 m_pSkin->OnNcCalcSize( this, bCalcValidRects, lpncsp );
00150         else
00151                 CDialog::OnNcCalcSize( bCalcValidRects, lpncsp );
00152 }
00153 
00154 UINT CSkinDialog::OnNcHitTest(CPoint point)
00155 {
00156         if ( m_pSkin )
00157                 return m_pSkin->OnNcHitTest( this, point, ( GetStyle() & WS_THICKFRAME ) ? TRUE : FALSE );
00158         else
00159                 return CDialog::OnNcHitTest( point );
00160 }
00161 
00162 BOOL CSkinDialog::OnNcActivate(BOOL bActive)
00163 {
00164         if ( m_pSkin )
00165         {
00166                 m_pSkin->OnNcActivate( this, IsWindowEnabled() && ( bActive || ( m_nFlags & WF_STAYACTIVE ) ) );
00167                 return TRUE;
00168         }
00169         else
00170         {
00171                 return CDialog::OnNcActivate( bActive );
00172         }
00173 }
00174 
00175 void CSkinDialog::OnNcPaint()
00176 {
00177         if ( m_pSkin )
00178                 m_pSkin->OnNcPaint( this );
00179         else
00180                 CDialog::OnNcPaint();
00181 }
00182 
00183 void CSkinDialog::OnNcLButtonDown(UINT nHitTest, CPoint point)
00184 {
00185         if ( m_pSkin && m_pSkin->OnNcLButtonDown( this, nHitTest, point ) ) return;
00186         CDialog::OnNcLButtonDown(nHitTest, point);
00187 }
00188 
00189 void CSkinDialog::OnNcLButtonUp(UINT nHitTest, CPoint point)
00190 {
00191         if ( m_pSkin && m_pSkin->OnNcLButtonUp( this, nHitTest, point ) ) return;
00192         CDialog::OnNcLButtonUp( nHitTest, point );
00193 }
00194 
00195 void CSkinDialog::OnNcLButtonDblClk(UINT nHitTest, CPoint point)
00196 {
00197         if ( m_pSkin && m_pSkin->OnNcLButtonDblClk( this, nHitTest, point ) ) return;
00198         CDialog::OnNcLButtonDblClk( nHitTest, point );
00199 }
00200 
00201 void CSkinDialog::OnNcMouseMove(UINT nHitTest, CPoint point)
00202 {
00203         if ( m_pSkin ) m_pSkin->OnNcMouseMove( this, nHitTest, point );
00204         CDialog::OnNcMouseMove( nHitTest, point );
00205 }
00206 
00207 void CSkinDialog::OnSize(UINT nType, int cx, int cy)
00208 {
00209         if ( m_pSkin ) m_pSkin->OnSize( this );
00210 
00211         CDialog::OnSize( nType, cx, cy );
00212 }
00213 
00214 LONG CSkinDialog::OnSetText(WPARAM wParam, LPARAM lParam)
00215 {
00216         if ( m_pSkin )
00217         {
00218                 BOOL bVisible = IsWindowVisible();
00219                 if ( bVisible ) ModifyStyle( WS_VISIBLE, 0 );
00220                 LONG lResult = Default();
00221                 if ( bVisible ) ModifyStyle( 0, WS_VISIBLE );
00222                 if ( m_pSkin ) m_pSkin->OnSetText( this );
00223                 return lResult;
00224         }
00225         else
00226         {
00227                 return Default();
00228         }
00229 }
00230 
00231 BOOL CSkinDialog::OnEraseBkgnd(CDC* pDC)
00232 {
00233         if ( m_pSkin && m_pSkin->OnEraseBkgnd( this, pDC ) ) return TRUE;
00234 
00235         CRect rc;
00236         GetClientRect( &rc );
00237         pDC->FillSolidRect( &rc, Skin.m_crDialog );
00238 
00239         return TRUE;
00240 }
00241 
00242 HBRUSH CSkinDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
00243 {
00244         HBRUSH hbr = CDialog::OnCtlColor( pDC, pWnd, nCtlColor );
00245 
00246         if ( nCtlColor == CTLCOLOR_DLG || nCtlColor == CTLCOLOR_STATIC )
00247         {
00248                 pDC->SetBkColor( Skin.m_crDialog );
00249                 hbr = Skin.m_brDialog;
00250         }
00251 
00252         return hbr;
00253 }
00254 
00255 #define SNAP_SIZE 6
00256 
00257 void CSkinDialog::OnWindowPosChanging(WINDOWPOS* lpwndpos)
00258 {
00259         CDialog::OnWindowPosChanging( lpwndpos );
00260 
00261         if ( theApp.m_pfnGetMonitorInfoA != NULL ) //If GetMonitorInfo() is available
00262         {
00263                 MONITORINFO oMonitor;
00264                 ZeroMemory( &oMonitor, sizeof(oMonitor) );
00265                 oMonitor.cbSize = sizeof(oMonitor);
00266                 theApp.m_pfnGetMonitorInfoA( theApp.m_pfnMonitorFromWindow( GetSafeHwnd(), MONITOR_DEFAULTTOPRIMARY ), &oMonitor );
00267 
00268                 if ( abs( lpwndpos->x - oMonitor.rcWork.left ) < SNAP_SIZE )
00269                         lpwndpos->x = oMonitor.rcWork.left;
00270                 if ( abs( lpwndpos->y - oMonitor.rcWork.top ) < SNAP_SIZE )
00271                         lpwndpos->y = oMonitor.rcWork.top;
00272                 if ( abs( lpwndpos->x + lpwndpos->cx - oMonitor.rcWork.right ) < SNAP_SIZE )
00273                         lpwndpos->x = oMonitor.rcWork.right - lpwndpos->cx;
00274                 if ( abs( lpwndpos->y + lpwndpos->cy - oMonitor.rcWork.bottom ) < SNAP_SIZE )
00275                         lpwndpos->y = oMonitor.rcWork.bottom - lpwndpos->cy;
00276         }
00277         else
00278         {
00279                 CRect rcWork;
00280                 SystemParametersInfo( SPI_GETWORKAREA, 0, &rcWork, 0 );
00281 
00282                 if ( abs( lpwndpos->x ) <= ( rcWork.left + SNAP_SIZE ) )
00283                 {
00284                         lpwndpos->x = rcWork.left;
00285                 }
00286                 else if (       ( lpwndpos->x + lpwndpos->cx ) >= ( rcWork.right - SNAP_SIZE ) &&
00287                                         ( lpwndpos->x + lpwndpos->cx ) <= ( rcWork.right + SNAP_SIZE ) )
00288                 {
00289                         lpwndpos->x = rcWork.right - lpwndpos->cx;
00290                 }
00291 
00292                 if ( abs( lpwndpos->y ) <= ( rcWork.top + SNAP_SIZE ) )
00293                 {
00294                         lpwndpos->y = rcWork.top;
00295                 }
00296                 else if (       ( lpwndpos->y + lpwndpos->cy ) >= ( rcWork.bottom - SNAP_SIZE ) &&
00297                                         ( lpwndpos->y + lpwndpos->cy ) <= ( rcWork.bottom + SNAP_SIZE ) )
00298                 {
00299                         lpwndpos->y = rcWork.bottom-lpwndpos->cy;
00300                 }
00301         }
00302 }
00303 
00304 int CSkinDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
00305 {
00306         if (CDialog::OnCreate(lpCreateStruct) == -1)
00307                 return -1;
00308 
00309         if ( theApp.m_bRTL ) ModifyStyleEx( 0, WS_EX_LAYOUTRTL|WS_EX_RTLREADING, 0 );
00310         return 0;
00311 }
00312 
00313 BOOL CSkinDialog::OnInitDialog()
00314 {
00315         CDialog::OnInitDialog();
00316         if ( theApp.m_bRTL )
00317         {
00318                 CStatic* pBanner = (CStatic*)GetDlgItem( IDC_BANNER );
00319                 if ( pBanner )
00320                 {
00321                         if ( pBanner->GetBitmap() == NULL ) return TRUE;
00322                         CRect rcClient, rc;
00323                         pBanner->GetWindowRect( &rc );
00324 
00325                         GetWindowRect( &rcClient );
00326                         ScreenToClient( &rcClient );
00327                         pBanner->SetWindowPos( NULL, rcClient.left + rcClient.Width() - rc.Width(), 
00328                                 0, 0, 0, SWP_NOSIZE|SWP_NOZORDER );
00329                 }
00330         }
00331         return TRUE; 
00332 }

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