]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - tools/src/tools/configtool/common/win32/TTListCtrl.cpp
Initial revision
[karo-tx-redboot.git] / tools / src / tools / configtool / common / win32 / TTListCtrl.cpp
1 //####COPYRIGHTBEGIN####
2 //                                                                          
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
5 //
6 // This program is part of the eCos host tools.
7 //
8 // This program is free software; you can redistribute it and/or modify it 
9 // under the terms of the GNU General Public License as published by the Free 
10 // Software Foundation; either version 2 of the License, or (at your option) 
11 // any later version.
12 // 
13 // This program is distributed in the hope that it will be useful, but WITHOUT 
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
15 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
16 // more details.
17 // 
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc., 
20 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21 //
22 // ----------------------------------------------------------------------------
23 //                                                                          
24 //####COPYRIGHTEND####
25 // ttlistctrl.cpp : implementation file
26 //
27
28 #include "stdafx.h"
29 #include "ttlistctrl.h"
30
31 #ifdef _DEBUG
32 #define new DEBUG_NEW
33 #undef THIS_FILE
34 static char THIS_FILE[] = __FILE__;
35 #endif
36
37 /////////////////////////////////////////////////////////////////////////////
38 // CTTListCtrl
39
40 CTTListCtrl::CTTListCtrl()
41 {
42 }
43
44 CTTListCtrl::~CTTListCtrl()
45 {
46 }
47
48
49 BEGIN_MESSAGE_MAP(CTTListCtrl, CListCtrl)
50         //{{AFX_MSG_MAP(CTTListCtrl)
51         //}}AFX_MSG_MAP
52   ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
53         ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
54 END_MESSAGE_MAP()
55
56 /////////////////////////////////////////////////////////////////////////////
57 // CTTListCtrl message handlers
58
59 int CTTListCtrl::OnToolHitTest(CPoint point, TOOLINFO * pTI) const
60 {
61   CTTListCtrl &l=(CTTListCtrl &)*this;
62   LVHITTESTINFO info;
63   info.pt=point;
64   if(-1!=l.SubItemHitTest(&info)){
65     CRect rect;
66     l.GetSubItemRect(info.iItem,info.iSubItem,LVIR_LABEL,rect);
67
68     CDC *pDC=l.GetDC();
69     CFont *pOldFont=pDC->SelectObject(GetFont());
70     int cx=pDC->GetTextExtent(GetItemText(info.iItem,info.iSubItem)).cx;
71     pDC->SelectObject(pOldFont);
72     l.ReleaseDC(pDC);
73     if(cx>GetColumnWidth(info.iSubItem)-10){
74
75       pTI->hwnd = m_hWnd;
76             pTI->uId = 1+MAKELONG(info.iItem,info.iSubItem);
77             pTI->lpszText = LPSTR_TEXTCALLBACK;
78             pTI->rect = rect;
79
80             return pTI->uId;
81     }
82   }
83   return -1;
84 }
85
86 BOOL CTTListCtrl::OnToolTipText( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
87 {
88         // need to handle both ANSI and UNICODE versions of the message
89         TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
90         TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
91         id=pNMHDR->idFrom;
92
93   if(0==id--){          // Notification in NT from automatically
94                 return FALSE;           // created tooltip
95   } else {
96           const CString strTipText(GetItemText(LOWORD(id),HIWORD(id)));
97 #ifndef _UNICODE
98           if (pNMHDR->code == TTN_NEEDTEXTA)
99                   lstrcpyn(pTTTA->szText, strTipText, sizeof pTTTA->szText/sizeof TCHAR - 1);
100           else
101                   _mbstowcsz(pTTTW->szText, strTipText, sizeof pTTTW->szText/sizeof TCHAR - 1);
102 #else
103           if (pNMHDR->code == TTN_NEEDTEXTA)
104                   _wcstombsz(pTTTA->szText, strTipText, sizeof pTTTA->szText/sizeof TCHAR - 1);
105           else
106                   lstrcpyn(pTTTW->szText, strTipText, sizeof pTTTW->szText/sizeof TCHAR - 1);
107 #endif
108     CRect rect;
109     GetSubItemRect(LOWORD(id),HIWORD(id),LVIR_LABEL,rect);
110     ClientToScreen(rect);
111     //::SetWindowPos(pNMHDR->hwndFrom,NULL,rect.left,rect.top,0,0,SWP_NOZORDER|SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSENDCHANGING);
112     *pResult = 0;
113
114           return TRUE;    // message was handled
115   }
116 }
117
118 void CTTListCtrl::PreSubclassWindow() 
119 {
120         CListCtrl::PreSubclassWindow();
121   EnableToolTips(TRUE);
122 }