00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "stdafx.h"
00021 #include "PropPageFrameDefault.h"
00022
00023
00024 namespace TreePropSheet
00025 {
00026
00027
00028
00029
00030 #define XPSUPPORT
00031
00032 #ifdef XPSUPPORT
00033 #include <uxtheme.h>
00034 #include <tmschema.h>
00035 #endif
00036
00037 #ifdef _DEBUG
00038 #define new DEBUG_NEW
00039 #undef THIS_FILE
00040 static char THIS_FILE[] = __FILE__;
00041 #endif
00042
00043
00044
00045
00046
00047 #define THEMEAPITYPE(f) typedef HRESULT (__stdcall *_##f)
00048 #define THEMEAPITYPE_(t, f) typedef t (__stdcall *_##f)
00049 #define THEMEAPIPTR(f) _##f m_p##f
00050
00051 #ifdef XPSUPPORT
00052 #define THEMECALL(f) return (*m_p##f)
00053 #define GETTHEMECALL(f) m_p##f = (_##f)GetProcAddress(m_hThemeLib, #f)
00054 #else
00055 void ThemeDummy(...) {ASSERT(FALSE);}
00056 #define HTHEME void*
00057 #define TABP_PANE 0
00058 #define THEMECALL(f) return 0; ThemeDummy
00059 #define GETTHEMECALL(f) m_p##f = NULL
00060 #endif
00061
00062
00071 class CThemeLib
00072 {
00073
00074 public:
00075 CThemeLib();
00076 ~CThemeLib();
00077
00078
00079 public:
00083 BOOL IsAvailable() const;
00084
00085
00086 public:
00087 BOOL IsThemeActive()
00088 {THEMECALL(IsThemeActive)();}
00089
00090 HTHEME OpenThemeData(HWND hwnd, LPCWSTR pszClassList)
00091 {THEMECALL(OpenThemeData)(hwnd, pszClassList);}
00092
00093 HRESULT CloseThemeData(HTHEME hTheme)
00094 {THEMECALL(CloseThemeData)(hTheme);}
00095
00096 HRESULT GetThemeBackgroundContentRect(HTHEME hTheme, OPTIONAL HDC hdc, int iPartId, int iStateId, const RECT *pBoundingRect, OUT RECT *pContentRect)
00097 {THEMECALL(GetThemeBackgroundContentRect)(hTheme, hdc, iPartId, iStateId, pBoundingRect, pContentRect);}
00098
00099 HRESULT DrawThemeBackground(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, OPTIONAL const RECT *pClipRect)
00100 {THEMECALL(DrawThemeBackground)(hTheme, hdc, iPartId, iStateId, pRect, pClipRect);}
00101
00102
00103 private:
00104 #ifdef XPSUPPORT
00105 THEMEAPITYPE_(BOOL, IsThemeActive)();
00106 THEMEAPIPTR(IsThemeActive);
00107
00108 THEMEAPITYPE_(HTHEME, OpenThemeData)(HWND hwnd, LPCWSTR pszClassList);
00109 THEMEAPIPTR(OpenThemeData);
00110
00111 THEMEAPITYPE(CloseThemeData)(HTHEME hTheme);
00112 THEMEAPIPTR(CloseThemeData);
00113
00114 THEMEAPITYPE(GetThemeBackgroundContentRect)(HTHEME hTheme, OPTIONAL HDC hdc, int iPartId, int iStateId, const RECT *pBoundingRect, OUT RECT *pContentRect);
00115 THEMEAPIPTR(GetThemeBackgroundContentRect);
00116
00117 THEMEAPITYPE(DrawThemeBackground)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, OPTIONAL const RECT *pClipRect);
00118 THEMEAPIPTR(DrawThemeBackground);
00119 #endif
00120
00121
00122 private:
00124 HINSTANCE m_hThemeLib;
00125 };
00126
00130 static CThemeLib g_ThemeLib;
00131
00132
00133 CThemeLib::CThemeLib()
00134 : m_hThemeLib(NULL)
00135 {
00136 #ifdef XPSUPPORT
00137 m_hThemeLib = LoadLibrary(_T("uxtheme.dll"));
00138 if (!m_hThemeLib)
00139 return;
00140
00141 GETTHEMECALL(IsThemeActive);
00142 GETTHEMECALL(OpenThemeData);
00143 GETTHEMECALL(CloseThemeData);
00144 GETTHEMECALL(GetThemeBackgroundContentRect);
00145 GETTHEMECALL(DrawThemeBackground);
00146 #endif
00147 }
00148
00149
00150 CThemeLib::~CThemeLib()
00151 {
00152 if (m_hThemeLib)
00153 FreeLibrary(m_hThemeLib);
00154 }
00155
00156
00157 BOOL CThemeLib::IsAvailable() const
00158 {
00159 return m_hThemeLib!=NULL;
00160 }
00161
00162
00163
00164
00165
00166
00167 BEGIN_MESSAGE_MAP(CPropPageFrameDefault, CWnd)
00168
00169 ON_WM_PAINT()
00170 ON_WM_ERASEBKGND()
00171
00172 END_MESSAGE_MAP()
00173
00174
00175 CPropPageFrameDefault::CPropPageFrameDefault()
00176 {
00177 }
00178
00179
00180 CPropPageFrameDefault::~CPropPageFrameDefault()
00181 {
00182 if (m_Images.GetSafeHandle())
00183 m_Images.DeleteImageList();
00184 }
00185
00186
00188
00189
00190 BOOL CPropPageFrameDefault::Create(DWORD dwWindowStyle, const RECT &rect, CWnd *pwndParent, UINT nID)
00191 {
00192 return CWnd::Create(
00193 AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW, AfxGetApp()->LoadStandardCursor(IDC_ARROW), GetSysColorBrush(COLOR_3DFACE)),
00194 _T("Page Frame"),
00195 dwWindowStyle, rect, pwndParent, nID);
00196 }
00197
00198 CWnd* CPropPageFrameDefault::GetWnd()
00199 {
00200 return static_cast<CWnd*>(this);
00201 }
00202
00203 void CPropPageFrameDefault::SetCaption(LPCTSTR lpszCaption, HICON hIcon )
00204 {
00205 CPropPageFrame::SetCaption(lpszCaption, hIcon);
00206
00207
00208 if (m_Images.GetSafeHandle())
00209 m_Images.DeleteImageList();
00210 if (hIcon)
00211 {
00212 ICONINFO ii;
00213 if (!GetIconInfo(hIcon, &ii))
00214 return;
00215
00216 CBitmap bmMask;
00217 bmMask.Attach(ii.hbmMask);
00218 if (ii.hbmColor) DeleteObject(ii.hbmColor);
00219
00220 BITMAP bm;
00221 bmMask.GetBitmap(&bm);
00222
00223 if (!m_Images.Create(bm.bmWidth, bm.bmHeight, ILC_COLOR32|ILC_MASK, 0, 1))
00224 return;
00225
00226 if (m_Images.Add(hIcon) == -1)
00227 m_Images.DeleteImageList();
00228 }
00229 }
00230
00231 CRect CPropPageFrameDefault::CalcMsgArea()
00232 {
00233 CRect rect;
00234 GetClientRect(rect);
00235 if (g_ThemeLib.IsAvailable() && g_ThemeLib.IsThemeActive())
00236 {
00237 HTHEME hTheme = g_ThemeLib.OpenThemeData(m_hWnd, L"Tab");
00238 if (hTheme)
00239 {
00240 CRect rectContent;
00241 CDC *pDc = GetDC();
00242 g_ThemeLib.GetThemeBackgroundContentRect(hTheme, pDc->m_hDC, TABP_PANE, 0, rect, rectContent);
00243 ReleaseDC(pDc);
00244 g_ThemeLib.CloseThemeData(hTheme);
00245
00246 if (GetShowCaption())
00247 rectContent.top = rect.top+GetCaptionHeight()+1;
00248 rect = rectContent;
00249 }
00250 }
00251 else if (GetShowCaption())
00252 rect.top+= GetCaptionHeight()+1;
00253
00254 return rect;
00255 }
00256
00257
00258 CRect CPropPageFrameDefault::CalcCaptionArea()
00259 {
00260 CRect rect;
00261 GetClientRect(rect);
00262 if (g_ThemeLib.IsAvailable() && g_ThemeLib.IsThemeActive())
00263 {
00264 HTHEME hTheme = g_ThemeLib.OpenThemeData(m_hWnd, L"Tab");
00265 if (hTheme)
00266 {
00267 CRect rectContent;
00268 CDC *pDc = GetDC();
00269 g_ThemeLib.GetThemeBackgroundContentRect(hTheme, pDc->m_hDC, TABP_PANE, 0, rect, rectContent);
00270 ReleaseDC(pDc);
00271 g_ThemeLib.CloseThemeData(hTheme);
00272
00273 if (GetShowCaption())
00274 rectContent.bottom = rect.top+GetCaptionHeight();
00275 else
00276 rectContent.bottom = rectContent.top;
00277
00278 rect = rectContent;
00279 }
00280 }
00281 else
00282 {
00283 if (GetShowCaption())
00284 rect.bottom = rect.top+GetCaptionHeight();
00285 else
00286 rect.bottom = rect.top;
00287 }
00288
00289 return rect;
00290 }
00291
00292 void CPropPageFrameDefault::DrawCaption(CDC *pDc, CRect rect, LPCTSTR lpszCaption, HICON hIcon)
00293 {
00294 COLORREF clrLeft = GetSysColor(COLOR_INACTIVECAPTION);
00295 COLORREF clrRight = pDc->GetPixel(rect.right-1, rect.top);
00296 FillGradientRectH(pDc, rect, clrLeft, clrRight);
00297
00298
00299 if (hIcon && m_Images.GetSafeHandle() && m_Images.GetImageCount() == 1)
00300 {
00301 IMAGEINFO ii;
00302 m_Images.GetImageInfo(0, &ii);
00303 CPoint pt(3, rect.CenterPoint().y - (ii.rcImage.bottom-ii.rcImage.top)/2);
00304 m_Images.Draw(pDc, 0, pt, ILD_TRANSPARENT);
00305 rect.left+= (ii.rcImage.right-ii.rcImage.left) + 3;
00306 }
00307
00308
00309 rect.left+= 2;
00310
00311 COLORREF clrPrev = pDc->SetTextColor(GetSysColor(COLOR_CAPTIONTEXT));
00312 int nBkStyle = pDc->SetBkMode(TRANSPARENT);
00313 CFont *pFont = (CFont*)pDc->SelectStockObject(SYSTEM_FONT);
00314
00315 CFont* pSysFont = pDc->GetCurrentFont();
00316 LOGFONT lf;
00317 pSysFont->GetLogFont(&lf);
00318 lf.lfHeight = rect.Height();
00319 lf.lfWidth = 0;
00320 _tcscpy(lf.lfFaceName, _T("Arial"));
00321 CFont f;
00322 f.CreateFontIndirect(&lf);
00323 pDc->SelectObject(&f);
00324
00325 pDc->DrawText(lpszCaption, rect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS);
00326
00327 pDc->SetTextColor(clrPrev);
00328 pDc->SetBkMode(nBkStyle);
00329 pDc->SelectObject(pFont);
00330 }
00331
00332
00334
00335
00336 void CPropPageFrameDefault::FillGradientRectH(CDC *pDc, const RECT &rect, COLORREF clrLeft, COLORREF clrRight)
00337 {
00338
00339 int nSteps = rect.right-rect.left;
00340 int nRRange = GetRValue(clrRight)-GetRValue(clrLeft);
00341 int nGRange = GetGValue(clrRight)-GetGValue(clrLeft);
00342 int nBRange = GetBValue(clrRight)-GetBValue(clrLeft);
00343
00344 double dRStep = (double)nRRange/(double)nSteps;
00345 double dGStep = (double)nGRange/(double)nSteps;
00346 double dBStep = (double)nBRange/(double)nSteps;
00347
00348 double dR = (double)GetRValue(clrLeft);
00349 double dG = (double)GetGValue(clrLeft);
00350 double dB = (double)GetBValue(clrLeft);
00351
00352 CPen *pPrevPen = NULL;
00353 for (int x = rect.left; x <= rect.right; ++x)
00354 {
00355 CPen Pen(PS_SOLID, 1, RGB((BYTE)dR, (BYTE)dG, (BYTE)dB));
00356 pPrevPen = pDc->SelectObject(&Pen);
00357 pDc->MoveTo(x, rect.top);
00358 pDc->LineTo(x, rect.bottom);
00359 pDc->SelectObject(pPrevPen);
00360
00361 dR+= dRStep;
00362 dG+= dGStep;
00363 dB+= dBStep;
00364 }
00365 }
00366
00367
00369
00370
00371 void CPropPageFrameDefault::OnPaint()
00372 {
00373 CPaintDC dc(this);
00374 Draw(&dc);
00375 }
00376
00377
00378 BOOL CPropPageFrameDefault::OnEraseBkgnd(CDC* pDC)
00379 {
00380 if (g_ThemeLib.IsAvailable() && g_ThemeLib.IsThemeActive())
00381 {
00382 HTHEME hTheme = g_ThemeLib.OpenThemeData(m_hWnd, L"Tab");
00383 if (hTheme)
00384 {
00385 CRect rect;
00386 GetClientRect(rect);
00387 g_ThemeLib.DrawThemeBackground(hTheme, pDC->m_hDC, TABP_PANE, 0, rect, NULL);
00388
00389 g_ThemeLib.CloseThemeData(hTheme);
00390 }
00391 return TRUE;
00392 }
00393 else
00394 {
00395 return CWnd::OnEraseBkgnd(pDC);
00396 }
00397 }
00398
00399 }