Fixed issue #2650: Empty ListViews drawing issue
[TortoiseGit.git] / src / Utils / MiscUI / HintListCtrl.cpp
blob75b7e744763d8b8d6746f140c5ce321ba8355af2
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008, 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.
20 #include "stdafx.h"
21 #include "MyMemDC.h"
22 #include "HintListCtrl.h"
24 CHintListCtrl::CHintListCtrl() : CListCtrl()
28 CHintListCtrl::~CHintListCtrl()
32 void CHintListCtrl::ShowText(const CString& sText, bool forceupdate /* = false*/)
34 m_sText = sText;
35 Invalidate();
36 if (forceupdate)
37 UpdateWindow();
40 void CHintListCtrl::ClearText()
42 m_sText.Empty();
43 Invalidate();
46 IMPLEMENT_DYNAMIC(CHintListCtrl, CListCtrl)
48 BEGIN_MESSAGE_MAP(CHintListCtrl, CListCtrl)
49 ON_WM_PAINT()
50 END_MESSAGE_MAP()
52 void CHintListCtrl::OnPaint()
54 LRESULT defres = Default();
55 if (!m_sText.IsEmpty())
57 COLORREF clrText = ::GetSysColor(COLOR_WINDOWTEXT);
58 COLORREF clrTextBk;
59 if (IsWindowEnabled())
60 clrTextBk = ::GetSysColor(COLOR_WINDOW);
61 else
62 clrTextBk = ::GetSysColor(COLOR_3DFACE);
64 CRect rc;
65 GetClientRect(&rc);
66 bool bIsEmpty = false;
67 CListCtrl * pListCtrl = dynamic_cast<CListCtrl*>(this);
68 if (pListCtrl)
70 CHeaderCtrl* pHC;
71 pHC = pListCtrl->GetHeaderCtrl();
72 if (pHC != NULL)
74 CRect rcH;
75 rcH.SetRectEmpty();
76 pHC->GetItemRect(0, &rcH);
77 rc.top += rcH.bottom;
79 bIsEmpty = pListCtrl->GetItemCount() == 0;
81 CDC* pDC = GetDC();
83 CMyMemDC memDC(pDC, &rc);
85 memDC.SetTextColor(clrText);
86 memDC.SetBkColor(clrTextBk);
87 if (bIsEmpty)
88 memDC.BitBlt(rc.left, rc.top, rc.Width(), rc.Height(), pDC, rc.left, rc.top, SRCCOPY);
89 else
90 memDC.FillSolidRect(rc, clrTextBk);
91 rc.top += 10;
92 CGdiObject * oldfont = memDC.SelectStockObject(DEFAULT_GUI_FONT);
93 memDC.DrawText(m_sText, rc, DT_CENTER | DT_VCENTER |
94 DT_WORDBREAK | DT_NOPREFIX | DT_NOCLIP);
95 memDC.SelectObject(oldfont);
97 ReleaseDC(pDC);
99 if (defres)
101 // the Default() call did not process the WM_PAINT message!
102 // Validate the update region ourselves to avoid
103 // an endless loop repainting
104 CRect rc;
105 GetUpdateRect(&rc, FALSE);
106 if (!rc.IsRectEmpty())
107 ValidateRect(rc);