]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/tooltip.cpp
non owned window implementation
[wxWidgets.git] / src / mac / carbon / tooltip.cpp
CommitLineData
ee6b1d97 1/////////////////////////////////////////////////////////////////////////////
670f9935 2// Name: src/mac/carbon/tooltip.cpp
ee6b1d97 3// Purpose: wxToolTip implementation
92e6d869 4// Author: Stefan Csomor
ee6b1d97 5// Id: $Id$
92e6d869 6// Copyright: (c) Stefan Csomor
65571936 7// Licence: wxWindows licence
ee6b1d97
SC
8/////////////////////////////////////////////////////////////////////////////
9
3d1a4878 10#include "wx/wxprec.h"
ee6b1d97
SC
11
12#if wxUSE_TOOLTIPS
13
85855db1
WS
14#include "wx/tooltip.h"
15
670f9935
WS
16#ifndef WX_PRECOMP
17 #include "wx/app.h"
cdccdfab 18 #include "wx/window.h"
da80ae71 19 #include "wx/dc.h"
c0badb70 20 #include "wx/timer.h"
670f9935
WS
21#endif // WX_PRECOMP
22
ee6b1d97 23#include "wx/geometry.h"
ee6b1d97
SC
24#include "wx/mac/uma.h"
25
26//-----------------------------------------------------------------------------
27// global data
28//-----------------------------------------------------------------------------
29
72c1ba98 30#if wxUSE_TIMER
853e3ce9 31class wxMacToolTipTimer : public wxTimer
ee6b1d97
SC
32{
33public:
853e3ce9 34 wxMacToolTipTimer(wxMacToolTip* tip, int iMilliseconds) ;
991f71dc 35 wxMacToolTipTimer() {} ;
12cd5f34 36 virtual ~wxMacToolTipTimer() {} ;
991f71dc 37
853e3ce9
GD
38 void Notify()
39 {
40 if ( m_mark == m_tip->GetMark() )
670f9935 41 m_tip->Draw() ;
853e3ce9 42 }
991f71dc 43
ee6b1d97 44protected:
e40298d5
JS
45 wxMacToolTip* m_tip;
46 long m_mark ;
ee6b1d97 47};
72c1ba98 48#endif // wxUSE_TIMER
ee6b1d97
SC
49
50//-----------------------------------------------------------------------------
51// wxToolTip
52//-----------------------------------------------------------------------------
53static long s_ToolTipDelay = 500 ;
54static bool s_ShowToolTips = true ;
55static wxMacToolTip s_ToolTip ;
56static wxWindow* s_LastWindowEntered = NULL ;
57static wxRect2DInt s_ToolTipArea ;
58static WindowRef s_ToolTipWindowRef = NULL ;
f5ebf253
SC
59
60IMPLEMENT_ABSTRACT_CLASS(wxToolTip, wxObject)
61
991f71dc 62
ee6b1d97
SC
63wxToolTip::wxToolTip( const wxString &tip )
64{
65 m_text = tip;
66 m_window = (wxWindow*) NULL;
67}
68
69wxToolTip::~wxToolTip()
70{
71}
72
73void wxToolTip::SetTip( const wxString &tip )
74{
e40298d5 75 m_text = tip;
670f9935 76
ee6b1d97
SC
77 if ( m_window )
78 {
991f71dc 79#if 0
e40298d5
JS
80 // update it immediately
81 wxToolInfo ti(GetHwndOf(m_window));
82 ti.lpszText = (wxChar *)m_text.c_str();
670f9935
WS
83
84 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_UPDATETIPTEXT, 0, &ti);
991f71dc 85#endif
ee6b1d97
SC
86 }
87}
88
89void wxToolTip::SetWindow( wxWindow *win )
90{
7eb67c00 91 m_window = win ;
ee6b1d97
SC
92}
93
94void wxToolTip::Enable( bool flag )
95{
e40298d5
JS
96 if ( s_ShowToolTips != flag )
97 {
98 s_ShowToolTips = flag ;
670f9935 99
e40298d5
JS
100 if ( s_ShowToolTips )
101 {
102 }
103 else
104 {
105 s_ToolTip.Clear() ;
106 }
107 }
ee6b1d97
SC
108}
109
110void wxToolTip::SetDelay( long msecs )
111{
e40298d5 112 s_ToolTipDelay = msecs ;
ee6b1d97
SC
113}
114
becac1ef
VZ
115void wxToolTip::SetAutoPop( long WXUNUSED(msecs) )
116{
117}
118
119void wxToolTip::SetReshow( long WXUNUSED(msecs) )
120{
121}
122
ee6b1d97
SC
123void wxToolTip::RelayEvent( wxWindow *win , wxMouseEvent &event )
124{
e40298d5
JS
125 if ( s_ShowToolTips )
126 {
127 if ( event.GetEventType() == wxEVT_LEAVE_WINDOW )
128 {
129 s_ToolTip.Clear() ;
130 }
131 else if (event.GetEventType() == wxEVT_ENTER_WINDOW || event.GetEventType() == wxEVT_MOTION )
132 {
133 wxPoint2DInt where( event.m_x , event.m_y ) ;
134 if ( s_LastWindowEntered == win && s_ToolTipArea.Contains( where ) )
135 {
136 }
137 else
138 {
139 s_ToolTip.Clear() ;
140 s_ToolTipArea = wxRect2DInt( event.m_x - 2 , event.m_y - 2 , 4 , 4 ) ;
141 s_LastWindowEntered = win ;
670f9935 142
facd6764 143 WindowRef window = MAC_WXHWND( win->MacGetTopLevelWindowRef() ) ;
e40298d5
JS
144 int x = event.m_x ;
145 int y = event.m_y ;
146 wxPoint local( x , y ) ;
147 win->MacClientToRootWindow( &x, &y ) ;
148 wxPoint windowlocal( x , y ) ;
149 s_ToolTip.Setup( window , win->MacGetToolTipString( local ) , windowlocal ) ;
150 }
151 }
152 }
ee6b1d97
SC
153}
154
155void wxToolTip::RemoveToolTips()
156{
e40298d5 157 s_ToolTip.Clear() ;
ee6b1d97 158}
991f71dc 159
ee6b1d97 160// --- mac specific
72c1ba98 161#if wxUSE_TIMER
ee6b1d97
SC
162wxMacToolTipTimer::wxMacToolTipTimer( wxMacToolTip *tip , int msec )
163{
e40298d5
JS
164 m_tip = tip;
165 m_mark = tip->GetMark() ;
166 Start(msec, true);
ee6b1d97 167}
72c1ba98 168#endif // wxUSE_TIMER
ee6b1d97
SC
169
170wxMacToolTip::wxMacToolTip()
171{
e40298d5
JS
172 m_window = NULL ;
173 m_backpict = NULL ;
72c1ba98 174#if wxUSE_TIMER
991f71dc 175 m_timer = NULL ;
72c1ba98 176#endif
e40298d5
JS
177 m_mark = 0 ;
178 m_shown = false ;
ee6b1d97
SC
179}
180
670f9935 181void wxMacToolTip::Setup( WindowRef win , const wxString& text , const wxPoint& localPosition )
ee6b1d97 182{
e40298d5 183 m_mark++ ;
991f71dc 184
e40298d5
JS
185 Clear() ;
186 m_position = localPosition ;
427ff662 187 m_label = text ;
7eb67c00 188 m_window =win;
e40298d5
JS
189 s_ToolTipWindowRef = m_window ;
190 m_backpict = NULL ;
72c1ba98 191#if wxUSE_TIMER
e40298d5
JS
192 if ( m_timer )
193 delete m_timer ;
991f71dc 194
e40298d5 195 m_timer = new wxMacToolTipTimer( this , s_ToolTipDelay ) ;
72c1ba98 196#endif // wxUSE_TIMER
ee6b1d97
SC
197}
198
670f9935 199wxMacToolTip::~wxMacToolTip()
ee6b1d97 200{
72c1ba98 201#if wxUSE_TIMER
991f71dc
DS
202 if ( m_timer )
203 {
76a5e5d2 204 delete m_timer ;
f5bb2251
GD
205 m_timer = NULL;
206 }
72c1ba98 207#endif // wxUSE_TIMER
670f9935 208 if ( m_backpict )
f5bb2251 209 Clear() ;
ee6b1d97
SC
210}
211
212const short kTipBorder = 2 ;
213const short kTipOffset = 5 ;
214
215void wxMacToolTip::Draw()
216{
670f9935 217 if ( m_label.empty() )
e40298d5 218 return ;
670f9935 219
e40298d5
JS
220 if ( m_window == s_ToolTipWindowRef )
221 {
222 m_shown = true ;
991f71dc 223
427ff662
SC
224 HMHelpContentRec tag ;
225 tag.version = kMacHelpVersion;
a9de2608 226
fb743cab
SC
227 Point p = { m_position.y , m_position.x };
228 wxMacLocalToGlobal( m_window , &p ) ;
229 SetRect( &tag.absHotRect , p.h - 2 , p.v - 2 , p.h + 2 , p.v + 2 );
a9de2608 230
dbe4a80c 231 m_helpTextRef = wxCFStringRef( m_label , wxFONTENCODING_DEFAULT ) ;
427ff662
SC
232 tag.content[kHMMinimumContentIndex].contentType = kHMCFStringContent ;
233 tag.content[kHMMinimumContentIndex].u.tagCFString = m_helpTextRef ;
234 tag.content[kHMMaximumContentIndex].contentType = kHMCFStringContent ;
235 tag.content[kHMMaximumContentIndex].u.tagCFString = m_helpTextRef ;
236 tag.tagSide = kHMDefaultSide;
237 HMDisplayTag( &tag );
e40298d5 238 }
ee6b1d97
SC
239}
240
670f9935 241void wxToolTip::NotifyWindowDelete( WXHWND win )
ee6b1d97 242{
e40298d5 243 if ( win == s_ToolTipWindowRef )
e40298d5 244 s_ToolTipWindowRef = NULL ;
ee6b1d97
SC
245}
246
247void wxMacToolTip::Clear()
248{
e40298d5 249 m_mark++ ;
72c1ba98 250#if wxUSE_TIMER
e40298d5
JS
251 if ( m_timer )
252 {
253 delete m_timer ;
254 m_timer = NULL ;
255 }
72c1ba98 256#endif // wxUSE_TIMER
e40298d5
JS
257 if ( !m_shown )
258 return ;
670f9935 259
e40298d5 260 HMHideTag() ;
ee6b1d97
SC
261}
262
c0badb70 263#endif // wxUSE_TOOLTIPS