1 /********************************************************************
3 * Copyright (c) 2002 Sven Wiegand <mail@sven-wiegand.de>
5 * You can use this and modify this in any way you want,
6 * BUT LEAVE THIS HEADER INTACT.
8 * Redistribution is appreciated.
18 *********************************************************************/
21 #include "PropPageFrameDefault.h"
22 #include "ExtTextOutFL.h"
24 namespace TreePropSheet
31 static char THIS_FILE
[] = __FILE__
;
35 //-------------------------------------------------------------------
36 // class CPropPageFrameDefault
37 //-------------------------------------------------------------------
39 BEGIN_MESSAGE_MAP(CPropPageFrameDefault
, CWnd
)
40 //{{AFX_MSG_MAP(CPropPageFrameDefault)
47 CPropPageFrameDefault::CPropPageFrameDefault()
52 CPropPageFrameDefault::~CPropPageFrameDefault()
54 if (m_Images
.GetSafeHandle())
55 m_Images
.DeleteImageList();
59 /////////////////////////////////////////////////////////////////////
62 BOOL
CPropPageFrameDefault::Create(DWORD dwWindowStyle
, const RECT
&rect
, CWnd
*pwndParent
, UINT nID
)
65 AfxRegisterWndClass(CS_HREDRAW
|CS_VREDRAW
, AfxGetApp()->LoadStandardCursor(IDC_ARROW
), GetSysColorBrush(COLOR_3DFACE
)),
67 dwWindowStyle
, rect
, pwndParent
, nID
);
71 CWnd
* CPropPageFrameDefault::GetWnd()
73 return static_cast<CWnd
*>(this);
77 void CPropPageFrameDefault::SetCaption(LPCTSTR lpszCaption
, HICON hIcon
/*= NULL*/)
79 CPropPageFrame::SetCaption(lpszCaption
, hIcon
);
82 if (m_Images
.GetSafeHandle())
83 m_Images
.DeleteImageList();
87 if (!GetIconInfo(hIcon
, &ii
))
91 bmMask
.Attach(ii
.hbmMask
);
92 if (ii
.hbmColor
) DeleteObject(ii
.hbmColor
);
95 bmMask
.GetBitmap(&bm
);
97 if (!m_Images
.Create(bm
.bmWidth
, bm
.bmHeight
, ILC_COLOR32
|ILC_MASK
, 0, 1))
100 if (m_Images
.Add(hIcon
) == -1)
101 m_Images
.DeleteImageList();
106 CRect
CPropPageFrameDefault::CalcMsgArea()
112 HTHEME hTheme
= OpenThemeData(m_hWnd
, L
"Tab");
117 GetThemeBackgroundContentRect(hTheme
, pDc
->m_hDC
, TABP_PANE
, 0, rect
, rectContent
);
119 CloseThemeData(hTheme
);
121 if (GetShowCaption())
122 rectContent
.top
= rect
.top
+GetCaptionHeight()+1;
126 else if (GetShowCaption())
127 rect
.top
+= GetCaptionHeight()+1;
133 CRect
CPropPageFrameDefault::CalcCaptionArea()
139 HTHEME hTheme
= OpenThemeData(m_hWnd
, L
"Tab");
144 GetThemeBackgroundContentRect(hTheme
, pDc
->m_hDC
, TABP_PANE
, 0, rect
, rectContent
);
146 CloseThemeData(hTheme
);
148 if (GetShowCaption())
149 rectContent
.bottom
= rect
.top
+GetCaptionHeight();
151 rectContent
.bottom
= rectContent
.top
;
158 if (GetShowCaption())
159 rect
.bottom
= rect
.top
+GetCaptionHeight();
161 rect
.bottom
= rect
.top
;
167 void CPropPageFrameDefault::DrawCaption(CDC
*pDc
, CRect rect
, LPCTSTR lpszCaption
, HICON hIcon
)
169 COLORREF clrLeft
= GetSysColor(COLOR_INACTIVECAPTION
);
170 COLORREF clrRight
= pDc
->GetPixel(rect
.right
-1, rect
.top
);
171 FillGradientRectH(pDc
, rect
, clrLeft
, clrRight
);
174 if (hIcon
&& m_Images
.GetSafeHandle() && m_Images
.GetImageCount() == 1)
177 m_Images
.GetImageInfo(0, &ii
);
178 CPoint
pt(6, rect
.CenterPoint().y
- (ii
.rcImage
.bottom
-ii
.rcImage
.top
)/2);
179 m_Images
.Draw(pDc
, 0, pt
, ILD_TRANSPARENT
);
180 rect
.left
+= (ii
.rcImage
.right
-ii
.rcImage
.left
) + 6;
186 COLORREF clrPrev
= pDc
->SetTextColor(GetSysColor(COLOR_CAPTIONTEXT
));
187 int nBkStyle
= pDc
->SetBkMode(TRANSPARENT
);
188 CFont
*pFont
= (CFont
*)pDc
->SelectStockObject(SYSTEM_FONT
);
190 //pDc->DrawText(lpszCaption, rect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS);
192 TextOutTryFL(pDc
->GetSafeHdc(), rect
.left
, rect
.top
, lpszCaption
, (int)_tcslen(lpszCaption
));
194 pDc
->SetTextColor(clrPrev
);
195 pDc
->SetBkMode(nBkStyle
);
196 pDc
->SelectObject(pFont
);
200 /////////////////////////////////////////////////////////////////////
201 // Implementation helpers
203 void CPropPageFrameDefault::FillGradientRectH(CDC
*pDc
, const RECT
&rect
, COLORREF clrLeft
, COLORREF clrRight
)
206 int nSteps
= rect
.right
-rect
.left
;
207 int nRRange
= GetRValue(clrRight
)-GetRValue(clrLeft
);
208 int nGRange
= GetGValue(clrRight
)-GetGValue(clrLeft
);
209 int nBRange
= GetBValue(clrRight
)-GetBValue(clrLeft
);
211 double dRStep
= (double)nRRange
/(double)nSteps
;
212 double dGStep
= (double)nGRange
/(double)nSteps
;
213 double dBStep
= (double)nBRange
/(double)nSteps
;
215 double dR
= (double)GetRValue(clrLeft
);
216 double dG
= (double)GetGValue(clrLeft
);
217 double dB
= (double)GetBValue(clrLeft
);
219 CPen
*pPrevPen
= NULL
;
220 for (int x
= rect
.left
; x
<= rect
.right
; ++x
)
222 CPen
Pen(PS_SOLID
, 1, RGB((BYTE
)dR
, (BYTE
)dG
, (BYTE
)dB
));
223 pPrevPen
= pDc
->SelectObject(&Pen
);
224 pDc
->MoveTo(x
, rect
.top
);
225 pDc
->LineTo(x
, rect
.bottom
);
226 pDc
->SelectObject(pPrevPen
);
235 /////////////////////////////////////////////////////////////////////
238 void CPropPageFrameDefault::OnPaint()
245 BOOL
CPropPageFrameDefault::OnEraseBkgnd(CDC
* pDC
)
249 HTHEME hTheme
= OpenThemeData(m_hWnd
, L
"TREEVIEW");
254 DrawThemeBackground(hTheme
, pDC
->m_hDC
, 0, 0, rect
, NULL
);
255 CloseThemeData(hTheme
);
261 return CWnd::OnEraseBkgnd(pDC
);
267 } //namespace TreePropSheet