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.
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
)
39 bool CScrollTool::Init(LPPOINT pos
, bool bRightAligned
/* = false */)
43 // create the tooltip window
44 if (!CreateEx(WS_EX_TOPMOST
,
47 TTS_NOPREFIX
| TTS_ALWAYSTIP
,
59 ti
.cbSize
= sizeof(TOOLINFO
);
60 ti
.uFlags
= TTF_TRACK
;
64 ti
.lpszText
= _T(" ");
66 // ToolTip control will cover the whole window
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
;
86 void CScrollTool::SetText(LPPOINT pos
, const TCHAR
* fmt
, ...)
91 va_start( marker
, fmt
);
92 s
.FormatV(fmt
, marker
);
99 textsize
= pDC
->GetTextExtent(s
);
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
));
109 void CScrollTool::Clear()
113 SendMessage(TTM_DELTOOL
, 0, (LPARAM
)(LPTOOLINFO
) &ti
);
116 m_bInitCalled
= false;
119 LONG
CScrollTool::GetTextWidth(LPCTSTR szText
)
122 CSize textsize
= pDC
->GetTextExtent(szText
, (int)_tcslen(szText
));