1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2011, 2013, 2015 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * Allows to show a hint text on a control, basically hiding the control
25 * content. Can be used for example during lengthy operations (showing "please wait")
26 * or to indicate why the control is empty (showing "no data available").
28 template <typename BaseType
> class CHintCtrl
: public BaseType
31 CHintCtrl() : BaseType() {}
34 void ShowText(const CString
& sText
, bool forceupdate
= false)
48 bool HasText() const {return !m_sText
.IsEmpty();}
53 afx_msg
void CHintCtrl::OnPaint()
55 LRESULT defres
= Default();
56 if (!m_sText
.IsEmpty())
58 COLORREF clrText
= ::GetSysColor(COLOR_WINDOWTEXT
);
60 if (IsWindowEnabled())
61 clrTextBk
= ::GetSysColor(COLOR_WINDOW
);
63 clrTextBk
= ::GetSysColor(COLOR_3DFACE
);
67 bool bIsEmpty
= false;
68 CListCtrl
* pListCtrl
= dynamic_cast<CListCtrl
*>(this);
72 pHC
= pListCtrl
->GetHeaderCtrl();
77 pHC
->GetItemRect(0, &rcH
);
80 bIsEmpty
= pListCtrl
->GetItemCount() == 0;
84 CMyMemDC
memDC(pDC
, &rc
);
86 memDC
.SetTextColor(clrText
);
87 memDC
.SetBkColor(clrTextBk
);
89 memDC
.BitBlt(rc
.left
, rc
.top
, rc
.Width(), rc
.Height(), pDC
, rc
.left
, rc
.top
, SRCCOPY
);
91 memDC
.FillSolidRect(rc
, clrTextBk
);
93 CGdiObject
* oldfont
= memDC
.SelectStockObject(DEFAULT_GUI_FONT
);
94 memDC
.DrawText(m_sText
, rc
, DT_CENTER
| DT_VCENTER
|
95 DT_WORDBREAK
| DT_NOPREFIX
| DT_NOCLIP
);
96 memDC
.SelectObject(oldfont
);
102 // the Default() call did not process the WM_PAINT message!
103 // Validate the update region ourselves to avoid
104 // an endless loop repainting
106 GetUpdateRect(&rc
, FALSE
);
107 if (!rc
.IsRectEmpty())
116 BEGIN_TEMPLATE_MESSAGE_MAP(CHintCtrl
, BaseType
, BaseType
)