Fixed issue #2507: Support keyboard shortcuts in yes/no prompts
[TortoiseGit.git] / src / Utils / MiscUI / HintListCtrl.cpp
blob2f38317204ad74280fee1a8e778923e79d6f4547
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008, 2013 - 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 CHeaderCtrl* pHC;
67 pHC = GetHeaderCtrl();
68 if (pHC != NULL)
70 CRect rcH;
71 rcH.SetRectEmpty();
72 pHC->GetItemRect(0, &rcH);
73 rc.top += rcH.bottom;
75 CDC* pDC = GetDC();
77 CMyMemDC memDC(pDC, &rc);
79 memDC.SetTextColor(clrText);
80 memDC.SetBkColor(clrTextBk);
81 memDC.FillSolidRect(rc, clrTextBk);
82 rc.top += 10;
83 CGdiObject * oldfont = memDC.SelectStockObject(DEFAULT_GUI_FONT);
84 memDC.DrawText(m_sText, rc, DT_CENTER | DT_VCENTER |
85 DT_WORDBREAK | DT_NOPREFIX | DT_NOCLIP);
86 memDC.SelectObject(oldfont);
88 ReleaseDC(pDC);
90 if (defres)
92 // the Default() call did not process the WM_PAINT message!
93 // Validate the update region ourselves to avoid
94 // an endless loop repainting
95 CRect rc;
96 GetUpdateRect(&rc, FALSE);
97 if (!rc.IsRectEmpty())
98 ValidateRect(rc);