Update rebase documentation
[TortoiseGit.git] / src / Utils / MiscUI / ScrollTool.cpp
blobd8134c24a3772dc27dd219d2c7a655c6d327ccda
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2006,2009-2010, 2012 - 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 #include "stdafx.h"
20 #include "ScrollTool.h"
23 CScrollTool::CScrollTool()
24 : m_bInitCalled(false)
25 , m_bRightAligned(false)
27 SecureZeroMemory(&ti, sizeof(ti));
30 CScrollTool::~CScrollTool()
35 BEGIN_MESSAGE_MAP(CScrollTool, CWnd)
36 END_MESSAGE_MAP()
39 bool CScrollTool::Init(LPPOINT pos, bool bRightAligned /* = false */)
41 if (!m_bInitCalled)
43 // create the tooltip window
44 if (!CreateEx(WS_EX_TOPMOST,
45 TOOLTIPS_CLASS,
46 NULL,
47 TTS_NOPREFIX | TTS_ALWAYSTIP,
48 CW_USEDEFAULT,
49 CW_USEDEFAULT,
50 CW_USEDEFAULT,
51 CW_USEDEFAULT,
52 NULL,
53 NULL,
54 NULL))
56 return false;
59 ti.cbSize = sizeof(TOOLINFO);
60 ti.uFlags = TTF_TRACK;
61 ti.hwnd = NULL;
62 ti.hinst = NULL;
63 ti.uId = 0;
64 ti.lpszText = _T(" ");
66 // ToolTip control will cover the whole window
67 ti.rect.left = 0;
68 ti.rect.top = 0;
69 ti.rect.right = 0;
70 ti.rect.bottom = 0;
72 CPoint point;
73 ::GetCursorPos(&point);
75 SendMessage(TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
77 SendMessage(TTM_TRACKPOSITION, 0, (LPARAM)(DWORD) MAKELONG(point.x, point.y));
78 SendMessage(TTM_TRACKACTIVATE, true, (LPARAM)(LPTOOLINFO) &ti);
79 SendMessage(TTM_TRACKPOSITION, 0, MAKELONG(pos->x, pos->y));
80 m_bRightAligned = bRightAligned;
81 m_bInitCalled = true;
83 return true;
86 void CScrollTool::SetText(LPPOINT pos, const TCHAR * fmt, ...)
88 CString s;
89 va_list marker;
91 va_start( marker, fmt );
92 s.FormatV(fmt, marker);
93 va_end( marker );
95 CSize textsize(0);
96 if (m_bRightAligned)
98 CDC *pDC = GetDC();
99 textsize = pDC->GetTextExtent(s);
100 ReleaseDC(pDC);
103 ti.lpszText = s.GetBuffer();
104 SendMessage(TTM_UPDATETIPTEXT, 0, (LPARAM)(LPTOOLINFO) &ti);
105 SendMessage(TTM_TRACKPOSITION, 0, MAKELONG(pos->x-textsize.cx, pos->y));
106 s.ReleaseBuffer();
109 void CScrollTool::Clear()
111 if (m_bInitCalled)
113 SendMessage(TTM_DELTOOL, 0, (LPARAM)(LPTOOLINFO) &ti);
114 DestroyWindow();
116 m_bInitCalled = false;
119 LONG CScrollTool::GetTextWidth(LPCTSTR szText)
121 CDC *pDC = GetDC();
122 CSize textsize = pDC->GetTextExtent(szText, (int)_tcslen(szText));
123 ReleaseDC(pDC);
124 return textsize.cx;