Allow to move item past last item
[TortoiseGit.git] / src / Utils / MiscUI / HintCtrl.h
blob67f74cdb08e48017db40ba09c0806fbefbf89908
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.
19 #pragma once
20 #include "MyMemDC.h"
22 /**
23 * \ingroup Utils
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
30 public:
31 CHintCtrl() : BaseType() {}
32 ~CHintCtrl() {}
34 void ShowText(const CString& sText, bool forceupdate = false)
36 m_sText = sText;
37 Invalidate();
38 if (forceupdate)
39 UpdateWindow();
42 void ClearText()
44 m_sText.Empty();
45 Invalidate();
48 bool HasText() const {return !m_sText.IsEmpty();}
50 DECLARE_MESSAGE_MAP()
52 protected:
53 afx_msg void CHintCtrl::OnPaint()
55 LRESULT defres = Default();
56 if (!m_sText.IsEmpty())
58 COLORREF clrText = ::GetSysColor(COLOR_WINDOWTEXT);
59 COLORREF clrTextBk;
60 if (IsWindowEnabled())
61 clrTextBk = ::GetSysColor(COLOR_WINDOW);
62 else
63 clrTextBk = ::GetSysColor(COLOR_3DFACE);
65 CRect rc;
66 GetClientRect(&rc);
67 bool bIsEmpty = false;
68 CListCtrl * pListCtrl = dynamic_cast<CListCtrl*>(this);
69 if (pListCtrl)
71 CHeaderCtrl* pHC;
72 pHC = pListCtrl->GetHeaderCtrl();
73 if (pHC)
75 CRect rcH;
76 rcH.SetRectEmpty();
77 pHC->GetItemRect(0, &rcH);
78 rc.top += rcH.bottom;
80 bIsEmpty = pListCtrl->GetItemCount() == 0;
82 CDC* pDC = GetDC();
84 CMyMemDC memDC(pDC, &rc);
86 memDC.SetTextColor(clrText);
87 memDC.SetBkColor(clrTextBk);
88 if (bIsEmpty)
89 memDC.BitBlt(rc.left, rc.top, rc.Width(), rc.Height(), pDC, rc.left, rc.top, SRCCOPY);
90 else
91 memDC.FillSolidRect(rc, clrTextBk);
92 rc.top += 10;
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);
98 ReleaseDC(pDC);
100 if (defres)
102 // the Default() call did not process the WM_PAINT message!
103 // Validate the update region ourselves to avoid
104 // an endless loop repainting
105 CRect rc;
106 GetUpdateRect(&rc, FALSE);
107 if (!rc.IsRectEmpty())
108 ValidateRect(rc);
112 private:
113 CString m_sText;
116 BEGIN_TEMPLATE_MESSAGE_MAP(CHintCtrl, BaseType, BaseType)
117 ON_WM_PAINT()
118 END_MESSAGE_MAP()