1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2006,2009-2010 - 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)
29 CScrollTool::~CScrollTool()
34 BEGIN_MESSAGE_MAP(CScrollTool
, CWnd
)
38 bool CScrollTool::Init(LPPOINT pos
, bool bRightAligned
/* = false */)
42 // create the tooltip window
43 if (!CreateEx(WS_EX_TOPMOST
,
46 TTS_NOPREFIX
| TTS_ALWAYSTIP
,
58 ti
.cbSize
= sizeof(TOOLINFO
);
59 ti
.uFlags
= TTF_TRACK
;
63 ti
.lpszText
= _T(" ");
65 // ToolTip control will cover the whole window
72 ::GetCursorPos(&point
);
74 SendMessage(TTM_ADDTOOL
, 0, (LPARAM
) (LPTOOLINFO
) &ti
);
76 SendMessage(TTM_TRACKPOSITION
, 0, (LPARAM
)(DWORD
) MAKELONG(point
.x
, point
.y
));
77 SendMessage(TTM_TRACKACTIVATE
, true, (LPARAM
)(LPTOOLINFO
) &ti
);
78 SendMessage(TTM_TRACKPOSITION
, 0, MAKELONG(pos
->x
, pos
->y
));
79 m_bRightAligned
= bRightAligned
;
85 void CScrollTool::SetText(LPPOINT pos
, const TCHAR
* fmt
, ...)
90 va_start( marker
, fmt
);
91 s
.FormatV(fmt
, marker
);
98 textsize
= pDC
->GetTextExtent(s
);
102 ti
.lpszText
= s
.GetBuffer();
103 SendMessage(TTM_UPDATETIPTEXT
, 0, (LPARAM
)(LPTOOLINFO
) &ti
);
104 SendMessage(TTM_TRACKPOSITION
, 0, MAKELONG(pos
->x
-textsize
.cx
, pos
->y
));
108 void CScrollTool::Clear()
112 SendMessage(TTM_DELTOOL
, 0, (LPARAM
)(LPTOOLINFO
) &ti
);
115 m_bInitCalled
= false;
118 LONG
CScrollTool::GetTextWidth(LPCTSTR szText
)
121 CSize textsize
= pDC
->GetTextExtent(szText
, _tcslen(szText
));