High DPI optimizations
[TortoiseGit.git] / src / Utils / TreePropSheet / PropPageFrame.cpp
blobc716e26a304e88a14e31446b902c145988e34b4b
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.
10 * $Workfile:$
11 * $Revision:$
12 * $Modtime:$
13 * $Author:$
15 * Revision History:
16 * $History:$
18 *********************************************************************/
20 #include "stdafx.h"
21 #include "PropPageFrame.h"
23 #ifdef _DEBUG
24 #define new DEBUG_NEW
25 #undef THIS_FILE
26 static char THIS_FILE[] = __FILE__;
27 #endif
31 namespace TreePropSheet
35 //-------------------------------------------------------------------
36 // class CPropPageFrame
37 //-------------------------------------------------------------------
39 CPropPageFrame::CPropPageFrame()
40 : m_bShowCaption(FALSE),
41 m_nCaptionHeight(0),
42 m_hCaptionIcon(nullptr),
43 m_dwMsgFormat(DT_CENTER|DT_VCENTER|DT_NOPREFIX|DT_SINGLELINE),
44 m_uiFont(nullptr)
46 NONCLIENTMETRICS metrics = { 0 };
47 metrics.cbSize = sizeof(NONCLIENTMETRICS);
48 SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &metrics, FALSE);
49 m_uiFont = CreateFontIndirect(&metrics.lfMessageFont);
53 CPropPageFrame::~CPropPageFrame()
55 if (m_uiFont)
56 DeleteObject(m_uiFont);
60 /////////////////////////////////////////////////////////////////////
61 // Operations
64 void CPropPageFrame::ShowCaption(BOOL bEnable)
66 m_bShowCaption = bEnable;
67 SafeUpdateWindow(CalcCaptionArea());
71 BOOL CPropPageFrame::GetShowCaption() const
73 return m_bShowCaption;
77 void CPropPageFrame::SetCaption(LPCTSTR lpszCaption, HICON hIcon /*= nullptr*/)
79 m_strCaption = lpszCaption;
80 m_hCaptionIcon = hIcon;
81 SafeUpdateWindow(CalcCaptionArea());
85 CString CPropPageFrame::GetCaption(HICON* pIcon /* = nullptr */) const
87 if (pIcon)
88 *pIcon = m_hCaptionIcon;
89 return m_strCaption;
93 void CPropPageFrame::SetCaptionHeight(int nCaptionHeight)
95 m_nCaptionHeight = nCaptionHeight;
96 SafeUpdateWindow(CalcCaptionArea());
100 int CPropPageFrame::GetCaptionHeight() const
102 return m_nCaptionHeight;
106 void CPropPageFrame::SetMsgText(LPCTSTR lpszMsg)
108 m_strMsg = lpszMsg;
109 SafeUpdateWindow(CalcMsgArea());
113 CString CPropPageFrame::GetMsgText() const
115 return m_strMsg;
119 void CPropPageFrame::SetMsgFormat(DWORD dwFormat)
121 m_dwMsgFormat = dwFormat;
122 SafeUpdateWindow(CalcMsgArea());
126 DWORD CPropPageFrame::GetMsgFormat() const
128 return m_dwMsgFormat;
132 /////////////////////////////////////////////////////////////////////
133 // Overridable implementation helpers
135 void CPropPageFrame::Draw(CDC *pDc)
137 if (GetShowCaption())
138 DrawCaption(pDc, CalcCaptionArea(), m_strCaption, m_hCaptionIcon);
139 DrawMsg(pDc, CalcMsgArea(), m_strMsg, m_dwMsgFormat);
143 CRect CPropPageFrame::CalcMsgArea()
145 ASSERT(IsWindow(GetWnd()->GetSafeHwnd()));
147 CRect rectMsg;
148 GetWnd()->GetClientRect(rectMsg);
149 if (GetShowCaption())
150 rectMsg.top+= GetCaptionHeight();
152 return rectMsg;
156 void CPropPageFrame::DrawMsg(CDC *pDc, CRect rect, LPCTSTR /*lpszMsg*/, DWORD /*dwFormat*/)
158 auto hOldFont = pDc->SelectObject(m_uiFont);
159 int nPrevBkMode = pDc->SetBkMode(TRANSPARENT);
161 pDc->DrawText(GetMsgText(), rect, GetMsgFormat());
163 pDc->SetBkMode(nPrevBkMode);
164 pDc->SelectObject(hOldFont);
168 CRect CPropPageFrame::CalcCaptionArea()
170 ASSERT(IsWindow(GetWnd()->GetSafeHwnd()));
172 CRect rectCaption;
173 GetWnd()->GetClientRect(rectCaption);
174 if (!GetShowCaption())
175 rectCaption.bottom = rectCaption.top;
176 else
177 rectCaption.bottom = rectCaption.top+GetCaptionHeight();
179 return rectCaption;
183 void CPropPageFrame::DrawCaption(CDC * /*pDc*/, CRect /*rect*/, LPCTSTR /*lpszCaption*/, HICON /*hIcon*/)
185 // should be implemented by specialized classes
189 /////////////////////////////////////////////////////////////////////
190 // Implementation helpers
192 void CPropPageFrame::SafeUpdateWindow(LPCRECT lpRect /* = nullptr */)
194 if (!IsWindow(GetWnd()->GetSafeHwnd()))
195 return;
197 GetWnd()->InvalidateRect(lpRect, TRUE);
202 } //namespace TreePropSheet