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 "CtrlIconButton.h"
00025 #include "CoolInterface.h"
00026
00027 #ifdef _DEBUG
00028 #define new DEBUG_NEW
00029 #undef THIS_FILE
00030 static char THIS_FILE[] = __FILE__;
00031 #endif
00032
00033 BEGIN_MESSAGE_MAP(CIconButtonCtrl, CWnd)
00034
00035 ON_WM_MOUSEMOVE()
00036 ON_WM_LBUTTONDOWN()
00037 ON_WM_LBUTTONUP()
00038 ON_WM_LBUTTONDBLCLK()
00039 ON_WM_RBUTTONDOWN()
00040 ON_WM_RBUTTONUP()
00041 ON_WM_PAINT()
00042 ON_WM_ERASEBKGND()
00043 ON_WM_ENABLE()
00044
00045 END_MESSAGE_MAP()
00046
00047
00049
00050
00051 CIconButtonCtrl::CIconButtonCtrl()
00052 {
00053 m_pImageList.Create( 16, 16, ILC_COLOR32|ILC_MASK, 1, 0 );
00054
00055 m_bCapture = FALSE;
00056 m_bDown = FALSE;
00057 m_bCursor = FALSE;
00058 }
00059
00060 CIconButtonCtrl::~CIconButtonCtrl()
00061 {
00062 }
00063
00065
00066
00067 BOOL CIconButtonCtrl::Create(const RECT& rect, CWnd* pParentWnd, UINT nControlID)
00068 {
00069 return CWnd::Create( NULL, NULL, WS_CHILD|WS_VISIBLE, rect, pParentWnd, nControlID );
00070 }
00071
00072 void CIconButtonCtrl::SetText(LPCTSTR pszText)
00073 {
00074 CString strText;
00075 GetWindowText( strText );
00076 if ( strText == pszText ) return;
00077 SetWindowText( pszText );
00078 Invalidate();
00079 }
00080
00081 void CIconButtonCtrl::SetIcon(UINT nIconID)
00082 {
00083 SetIcon( AfxGetApp()->LoadIcon( nIconID ) );
00084 }
00085
00086 void CIconButtonCtrl::SetIcon(HICON hIcon)
00087 {
00088 m_pImageList.Add( hIcon );
00089 RemoveStyle();
00090 }
00091
00092 void CIconButtonCtrl::SetHandCursor(BOOL bCursor)
00093 {
00094 m_bCursor = bCursor;
00095 }
00096
00097 BOOL CIconButtonCtrl::RemoveStyle()
00098 {
00099 HINSTANCE hLibrary = LoadLibrary( _T("uxtheme") );
00100 if ( !hLibrary ) return FALSE;
00101
00102 HRESULT (WINAPI *pfnSetWindowTheme)(HWND, LPCWSTR, LPCWSTR);
00103
00104 (FARPROC&)pfnSetWindowTheme = GetProcAddress( hLibrary, "SetWindowTheme" );
00105 BOOL bSuccess = SUCCEEDED( (*pfnSetWindowTheme)( GetSafeHwnd(), L" ", L" " ) );
00106
00107 FreeLibrary( hLibrary );
00108
00109 return bSuccess;
00110 }
00111
00113
00114
00115 void CIconButtonCtrl::OnMouseMove(UINT nFlags, CPoint point)
00116 {
00117 if ( ! IsWindowEnabled() ) return;
00118
00119 CRect rc;
00120 GetClientRect( &rc );
00121
00122 if ( m_bDown )
00123 {
00124 BOOL bInside = rc.PtInRect( point );
00125 if ( bInside == m_bCapture ) return;
00126
00127 m_bCapture = bInside;
00128 }
00129 else if ( m_bCapture )
00130 {
00131 if ( rc.PtInRect( point ) ) return;
00132
00133 ReleaseCapture();
00134 m_bCapture = FALSE;
00135 }
00136 else
00137 {
00138 SetCapture();
00139 if ( m_bCursor ) ::SetCursor( theApp.LoadCursor( IDC_HAND ) );
00140 m_bCapture = TRUE;
00141 }
00142
00143 Invalidate();
00144 }
00145
00146 void CIconButtonCtrl::OnLButtonDown(UINT nFlags, CPoint point)
00147 {
00148 if ( ! IsWindowEnabled() ) return;
00149
00150 SetFocus();
00151 SetCapture();
00152 m_bDown = TRUE;
00153
00154 Invalidate();
00155 }
00156
00157 void CIconButtonCtrl::OnLButtonUp(UINT nFlags, CPoint point)
00158 {
00159 if ( m_bDown )
00160 {
00161 ReleaseCapture();
00162 m_bDown = FALSE;
00163
00164 if ( m_bCapture )
00165 {
00166 RedrawWindow();
00167
00168 GetParent()->SendMessage( WM_COMMAND, MAKELONG( GetDlgCtrlID(), 0 ),
00169 (LPARAM)GetSafeHwnd() );
00170 }
00171
00172 m_bCapture = FALSE;
00173
00174 Invalidate();
00175 }
00176 }
00177
00178 void CIconButtonCtrl::OnLButtonDblClk(UINT nFlags, CPoint point)
00179 {
00180 OnLButtonDown( nFlags, point );
00181 }
00182
00183 void CIconButtonCtrl::OnRButtonDown(UINT nFlags, CPoint point)
00184 {
00185
00186 }
00187
00188 void CIconButtonCtrl::OnRButtonUp(UINT nFlags, CPoint point)
00189 {
00190
00191 }
00192
00194
00195
00196 BOOL CIconButtonCtrl::OnEraseBkgnd(CDC* pDC)
00197 {
00198 return TRUE;
00199 }
00200
00201 void CIconButtonCtrl::OnPaint()
00202 {
00203 CPaintDC dc( this );
00204 COLORREF crBack;
00205 CString strText;
00206 CPoint ptIcon;
00207 CRect rc;
00208
00209 GetClientRect( &rc );
00210 GetWindowText( strText );
00211
00212 if ( strText.GetLength() )
00213 {
00214 ptIcon.x = rc.left + 3;
00215 }
00216 else
00217 {
00218 ptIcon.x = ( rc.left + rc.right ) / 2 - 8;
00219 }
00220
00221 ptIcon.y = ( rc.top + rc.bottom ) / 2 - 8;
00222
00223 if ( m_bDown && m_bCapture )
00224 {
00225 crBack = CoolInterface.m_crBackCheckSel;
00226 dc.Draw3dRect( &rc, CoolInterface.m_crBorder, CoolInterface.m_crBorder );
00227 rc.DeflateRect( 1, 1 );
00228
00229 ImageList_DrawEx( m_pImageList.m_hImageList, 0, dc.GetSafeHdc(),
00230 ptIcon.x, ptIcon.y, 0, 0, crBack, CLR_NONE, ILD_NORMAL );
00231 dc.ExcludeClipRect( ptIcon.x, ptIcon.y, ptIcon.x + 16, ptIcon.y + 16 );
00232 }
00233 else if ( m_bDown != m_bCapture )
00234 {
00235 crBack = CoolInterface.m_crBackSel;
00236 dc.Draw3dRect( &rc, CoolInterface.m_crBorder, CoolInterface.m_crBorder );
00237 rc.DeflateRect( 1, 1 );
00238
00239 ptIcon.Offset( -1, -1 );
00240 dc.FillSolidRect( ptIcon.x, ptIcon.y, 18, 2, crBack );
00241 dc.FillSolidRect( ptIcon.x, ptIcon.y + 2, 2, 16, crBack );
00242
00243 ptIcon.Offset( 2, 2 );
00244 dc.SetTextColor( CoolInterface.m_crShadow );
00245 ImageList_DrawEx( m_pImageList.m_hImageList, 0, dc.GetSafeHdc(),
00246 ptIcon.x, ptIcon.y, 0, 0, crBack, CLR_NONE, ILD_MASK );
00247
00248 ptIcon.Offset( -2, -2 );
00249 ImageList_DrawEx( m_pImageList.m_hImageList, 0, dc.GetSafeHdc(),
00250 ptIcon.x, ptIcon.y, 0, 0, CLR_NONE, CLR_NONE, ILD_NORMAL );
00251
00252 dc.ExcludeClipRect( ptIcon.x, ptIcon.y, ptIcon.x + 18, ptIcon.y + 18 );
00253 ptIcon.Offset( 1, 1 );
00254 }
00255 else if ( GetFocus() == this && IsWindowEnabled() )
00256 {
00257 crBack = CoolInterface.m_crBackNormal;
00258 dc.Draw3dRect( &rc, CoolInterface.m_crBorder, CoolInterface.m_crBorder );
00259 rc.DeflateRect( 1, 1 );
00260
00261 ImageList_DrawEx( m_pImageList.m_hImageList, 0, dc.GetSafeHdc(),
00262 ptIcon.x, ptIcon.y, 0, 0, crBack, CLR_NONE, ILD_NORMAL );
00263 dc.ExcludeClipRect( ptIcon.x, ptIcon.y, ptIcon.x + 16, ptIcon.y + 16 );
00264 }
00265 else if ( IsWindowEnabled() )
00266 {
00267 crBack = CoolInterface.m_crBackNormal;
00268 dc.Draw3dRect( &rc, CoolInterface.m_crShadow, CoolInterface.m_crShadow );
00269 rc.DeflateRect( 1, 1 );
00270
00271 ImageList_DrawEx( m_pImageList.m_hImageList, 0, dc.GetSafeHdc(),
00272 ptIcon.x, ptIcon.y, 0, 0, crBack, CoolInterface.m_crShadow, ILD_BLEND50 );
00273 dc.ExcludeClipRect( ptIcon.x, ptIcon.y, ptIcon.x + 16, ptIcon.y + 16 );
00274 }
00275 else
00276 {
00277 crBack = CoolInterface.m_crMidtone;
00278 dc.Draw3dRect( &rc, CoolInterface.m_crShadow, CoolInterface.m_crShadow );
00279 rc.DeflateRect( 1, 1 );
00280
00281 dc.SetTextColor( CoolInterface.m_crDisabled );
00282 dc.SetBkColor( crBack );
00283
00284
00285
00286
00287 ImageList_DrawEx( m_pImageList.m_hImageList, 0, dc.GetSafeHdc(),
00288 ptIcon.x, ptIcon.y, 0, 0, crBack, CoolInterface.m_crDisabled, ILD_BLEND50 );
00289
00290 dc.ExcludeClipRect( ptIcon.x, ptIcon.y, ptIcon.x + 16, ptIcon.y + 16 );
00291 }
00292
00293 if ( strText.GetLength() )
00294 {
00295 rc.left += 21;
00296
00297 CFont* pOldFont = (CFont*)dc.SelectObject( &theApp.m_gdiFont );
00298
00299 dc.SetBkColor( crBack );
00300 dc.SetTextColor( IsWindowEnabled() ? CoolInterface.m_crCmdText : CoolInterface.m_crDisabled );
00301 dc.ExtTextOut( rc.left + 2, ptIcon.y + 1, ETO_CLIPPED|ETO_OPAQUE, &rc, strText, NULL );
00302 dc.SelectObject( pOldFont );
00303
00304 rc.right = rc.left;
00305 rc.left -= 21;
00306 }
00307
00308 dc.FillSolidRect( &rc, crBack );
00309 }
00310
00311 void CIconButtonCtrl::OnEnable(BOOL bEnable)
00312 {
00313 CWnd::OnEnable( bEnable );
00314 Invalidate();
00315 }