OSDN Git Service

Add Stash Save Command Handle.
[tortoisegit/TortoiseGitJp.git] / src / Utils / MiscUI / Tooltip.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2008 - TortoiseSVN\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 \r
20 #include "stdafx.h"\r
21 #include "Tooltip.h"\r
22 \r
23 \r
24 BEGIN_MESSAGE_MAP(CToolTips, CToolTipCtrl)\r
25         ON_NOTIFY_REFLECT_EX( TTN_NEEDTEXT, &CToolTips::OnTtnNeedText )\r
26 END_MESSAGE_MAP()\r
27 \r
28 \r
29 \r
30 BOOL CToolTips::OnTtnNeedText(NMHDR *pNMHDR, LRESULT *pResult)\r
31 {\r
32         if (pNMHDR->code == TTN_NEEDTEXTW)\r
33         {\r
34                 LPNMTTDISPINFO lpnmtdi = (LPNMTTDISPINFO)pNMHDR;\r
35                 UINT_PTR nID = pNMHDR->idFrom;\r
36 \r
37                 if (lpnmtdi->uFlags & TTF_IDISHWND)\r
38                 {\r
39                         // idFrom is actually the HWND of the tool \r
40                         nID = ::GetDlgCtrlID((HWND)nID);\r
41                 }\r
42                 if (toolTextMap.find(nID) != toolTextMap.end())\r
43                 {\r
44                         lpnmtdi->lpszText = (LPTSTR)(LPCTSTR)(CString)toolTextMap[nID];\r
45                         lpnmtdi->hinst = AfxGetResourceHandle();\r
46                         *pResult = 0;\r
47                         return TRUE;\r
48                 }\r
49         }\r
50         return FALSE;\r
51 }\r
52 \r
53 BOOL CToolTips::AddTool(CWnd* pWnd, UINT nIDText, LPCRECT lpRectTool /* = NULL */, UINT_PTR nIDTool /* = 0 */)\r
54 {\r
55         CString sTemp;\r
56         sTemp.LoadString(nIDText);\r
57         // tooltips can't handle \t and single \n, only spaces and \r\n\r
58         sTemp.Replace('\t', ' ');\r
59         sTemp.Replace(_T("\r\n"), _T("\n"));\r
60         sTemp.Replace(_T("\n"), _T("\r\n"));\r
61         toolTextMap[::GetDlgCtrlID(pWnd->GetSafeHwnd())] = sTemp;\r
62         return CToolTipCtrl::AddTool(pWnd, LPSTR_TEXTCALLBACK, lpRectTool, nIDTool);\r
63 }\r
64 \r
65 BOOL CToolTips::AddTool(CWnd* pWnd, LPCTSTR lpszText /* = LPSTR_TEXTCALLBACK */, LPCRECT lpRectTool /* = NULL */, UINT_PTR nIDTool /* = 0 */)\r
66 {\r
67         if (lpszText != LPSTR_TEXTCALLBACK)\r
68                 toolTextMap[::GetDlgCtrlID(pWnd->GetSafeHwnd())] = CString(lpszText);\r
69         return CToolTipCtrl::AddTool(pWnd, lpszText, lpRectTool, nIDTool);\r
70 }\r
71 \r
72 void CToolTips::AddTool(int nIdWnd, UINT nIdText, LPCRECT lpRectTool /* = NULL */, UINT_PTR nIDTool /* = 0 */)\r
73 {\r
74         AddTool(((CDialog*)m_pParentWnd)->GetDlgItem(nIdWnd), nIdText, lpRectTool, nIDTool);\r
75 }\r
76 \r
77 void CToolTips::AddTool(int nIdWnd, CString sBalloonTipText, LPCRECT lpRectTool /* = NULL */, UINT_PTR nIDTool /* = 0 */)\r
78 {\r
79         AddTool(((CDialog*)m_pParentWnd)->GetDlgItem(nIdWnd), sBalloonTipText, lpRectTool, nIDTool);\r
80 }\r
81 \r
82 \r