]>
Commit | Line | Data |
---|---|---|
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 | ||
76a5e5d2 SC |
30 | class wxMacToolTipTimer ; |
31 | ||
ee6b1d97 SC |
32 | class wxMacToolTip |
33 | { | |
991f71dc DS |
34 | public : |
35 | wxMacToolTip() ; | |
36 | ~wxMacToolTip() ; | |
670f9935 | 37 | |
991f71dc DS |
38 | void Setup( WindowRef window , const wxString& text , const wxPoint& localPosition ) ; |
39 | void Draw() ; | |
40 | void Clear() ; | |
41 | ||
42 | long GetMark() | |
43 | { return m_mark ; } | |
44 | ||
45 | bool IsShown() | |
46 | { return m_shown ; } | |
47 | ||
48 | private : | |
49 | wxString m_label ; | |
50 | wxPoint m_position ; | |
51 | Rect m_rect ; | |
670f9935 | 52 | WindowRef m_window ; |
991f71dc DS |
53 | PicHandle m_backpict ; |
54 | bool m_shown ; | |
55 | long m_mark ; | |
72c1ba98 | 56 | #if wxUSE_TIMER |
991f71dc | 57 | wxMacToolTipTimer* m_timer ; |
72c1ba98 | 58 | #endif |
427ff662 | 59 | #if TARGET_CARBON |
991f71dc | 60 | wxMacCFStringHolder m_helpTextRef ; |
6ef7c8e0 | 61 | #endif |
ee6b1d97 SC |
62 | } ; |
63 | ||
72c1ba98 | 64 | #if wxUSE_TIMER |
853e3ce9 | 65 | class wxMacToolTipTimer : public wxTimer |
ee6b1d97 SC |
66 | { |
67 | public: | |
853e3ce9 | 68 | wxMacToolTipTimer(wxMacToolTip* tip, int iMilliseconds) ; |
991f71dc | 69 | wxMacToolTipTimer() {} ; |
12cd5f34 | 70 | virtual ~wxMacToolTipTimer() {} ; |
991f71dc | 71 | |
853e3ce9 GD |
72 | void Notify() |
73 | { | |
74 | if ( m_mark == m_tip->GetMark() ) | |
670f9935 | 75 | m_tip->Draw() ; |
853e3ce9 | 76 | } |
991f71dc | 77 | |
ee6b1d97 | 78 | protected: |
e40298d5 JS |
79 | wxMacToolTip* m_tip; |
80 | long m_mark ; | |
ee6b1d97 | 81 | }; |
72c1ba98 | 82 | #endif // wxUSE_TIMER |
ee6b1d97 SC |
83 | |
84 | //----------------------------------------------------------------------------- | |
85 | // wxToolTip | |
86 | //----------------------------------------------------------------------------- | |
87 | static long s_ToolTipDelay = 500 ; | |
88 | static bool s_ShowToolTips = true ; | |
89 | static wxMacToolTip s_ToolTip ; | |
90 | static wxWindow* s_LastWindowEntered = NULL ; | |
91 | static wxRect2DInt s_ToolTipArea ; | |
92 | static WindowRef s_ToolTipWindowRef = NULL ; | |
f5ebf253 SC |
93 | |
94 | IMPLEMENT_ABSTRACT_CLASS(wxToolTip, wxObject) | |
95 | ||
991f71dc | 96 | |
ee6b1d97 SC |
97 | wxToolTip::wxToolTip( const wxString &tip ) |
98 | { | |
99 | m_text = tip; | |
100 | m_window = (wxWindow*) NULL; | |
101 | } | |
102 | ||
103 | wxToolTip::~wxToolTip() | |
104 | { | |
105 | } | |
106 | ||
107 | void wxToolTip::SetTip( const wxString &tip ) | |
108 | { | |
e40298d5 | 109 | m_text = tip; |
670f9935 | 110 | |
ee6b1d97 SC |
111 | if ( m_window ) |
112 | { | |
991f71dc | 113 | #if 0 |
e40298d5 JS |
114 | // update it immediately |
115 | wxToolInfo ti(GetHwndOf(m_window)); | |
116 | ti.lpszText = (wxChar *)m_text.c_str(); | |
670f9935 WS |
117 | |
118 | (void)SendTooltipMessage(GetToolTipCtrl(), TTM_UPDATETIPTEXT, 0, &ti); | |
991f71dc | 119 | #endif |
ee6b1d97 SC |
120 | } |
121 | } | |
122 | ||
123 | void wxToolTip::SetWindow( wxWindow *win ) | |
124 | { | |
7eb67c00 | 125 | m_window = win ; |
ee6b1d97 SC |
126 | } |
127 | ||
128 | void wxToolTip::Enable( bool flag ) | |
129 | { | |
e40298d5 JS |
130 | if ( s_ShowToolTips != flag ) |
131 | { | |
132 | s_ShowToolTips = flag ; | |
670f9935 | 133 | |
e40298d5 JS |
134 | if ( s_ShowToolTips ) |
135 | { | |
136 | } | |
137 | else | |
138 | { | |
139 | s_ToolTip.Clear() ; | |
140 | } | |
141 | } | |
ee6b1d97 SC |
142 | } |
143 | ||
144 | void wxToolTip::SetDelay( long msecs ) | |
145 | { | |
e40298d5 | 146 | s_ToolTipDelay = msecs ; |
ee6b1d97 SC |
147 | } |
148 | ||
becac1ef VZ |
149 | void wxToolTip::SetAutoPop( long WXUNUSED(msecs) ) |
150 | { | |
151 | } | |
152 | ||
153 | void wxToolTip::SetReshow( long WXUNUSED(msecs) ) | |
154 | { | |
155 | } | |
156 | ||
ee6b1d97 SC |
157 | void wxToolTip::RelayEvent( wxWindow *win , wxMouseEvent &event ) |
158 | { | |
e40298d5 JS |
159 | if ( s_ShowToolTips ) |
160 | { | |
161 | if ( event.GetEventType() == wxEVT_LEAVE_WINDOW ) | |
162 | { | |
163 | s_ToolTip.Clear() ; | |
164 | } | |
165 | else if (event.GetEventType() == wxEVT_ENTER_WINDOW || event.GetEventType() == wxEVT_MOTION ) | |
166 | { | |
167 | wxPoint2DInt where( event.m_x , event.m_y ) ; | |
168 | if ( s_LastWindowEntered == win && s_ToolTipArea.Contains( where ) ) | |
169 | { | |
170 | } | |
171 | else | |
172 | { | |
173 | s_ToolTip.Clear() ; | |
174 | s_ToolTipArea = wxRect2DInt( event.m_x - 2 , event.m_y - 2 , 4 , 4 ) ; | |
175 | s_LastWindowEntered = win ; | |
670f9935 | 176 | |
facd6764 | 177 | WindowRef window = MAC_WXHWND( win->MacGetTopLevelWindowRef() ) ; |
e40298d5 JS |
178 | int x = event.m_x ; |
179 | int y = event.m_y ; | |
180 | wxPoint local( x , y ) ; | |
181 | win->MacClientToRootWindow( &x, &y ) ; | |
182 | wxPoint windowlocal( x , y ) ; | |
183 | s_ToolTip.Setup( window , win->MacGetToolTipString( local ) , windowlocal ) ; | |
184 | } | |
185 | } | |
186 | } | |
ee6b1d97 SC |
187 | } |
188 | ||
189 | void wxToolTip::RemoveToolTips() | |
190 | { | |
e40298d5 | 191 | s_ToolTip.Clear() ; |
ee6b1d97 | 192 | } |
991f71dc | 193 | |
ee6b1d97 | 194 | // --- mac specific |
72c1ba98 | 195 | #if wxUSE_TIMER |
ee6b1d97 SC |
196 | wxMacToolTipTimer::wxMacToolTipTimer( wxMacToolTip *tip , int msec ) |
197 | { | |
e40298d5 JS |
198 | m_tip = tip; |
199 | m_mark = tip->GetMark() ; | |
200 | Start(msec, true); | |
ee6b1d97 | 201 | } |
72c1ba98 | 202 | #endif // wxUSE_TIMER |
ee6b1d97 SC |
203 | |
204 | wxMacToolTip::wxMacToolTip() | |
205 | { | |
e40298d5 JS |
206 | m_window = NULL ; |
207 | m_backpict = NULL ; | |
72c1ba98 | 208 | #if wxUSE_TIMER |
991f71dc | 209 | m_timer = NULL ; |
72c1ba98 | 210 | #endif |
e40298d5 JS |
211 | m_mark = 0 ; |
212 | m_shown = false ; | |
ee6b1d97 SC |
213 | } |
214 | ||
670f9935 | 215 | void wxMacToolTip::Setup( WindowRef win , const wxString& text , const wxPoint& localPosition ) |
ee6b1d97 | 216 | { |
e40298d5 | 217 | m_mark++ ; |
991f71dc | 218 | |
e40298d5 JS |
219 | Clear() ; |
220 | m_position = localPosition ; | |
427ff662 | 221 | m_label = text ; |
7eb67c00 | 222 | m_window =win; |
e40298d5 JS |
223 | s_ToolTipWindowRef = m_window ; |
224 | m_backpict = NULL ; | |
72c1ba98 | 225 | #if wxUSE_TIMER |
e40298d5 JS |
226 | if ( m_timer ) |
227 | delete m_timer ; | |
991f71dc | 228 | |
e40298d5 | 229 | m_timer = new wxMacToolTipTimer( this , s_ToolTipDelay ) ; |
72c1ba98 | 230 | #endif // wxUSE_TIMER |
ee6b1d97 SC |
231 | } |
232 | ||
670f9935 | 233 | wxMacToolTip::~wxMacToolTip() |
ee6b1d97 | 234 | { |
72c1ba98 | 235 | #if wxUSE_TIMER |
991f71dc DS |
236 | if ( m_timer ) |
237 | { | |
76a5e5d2 | 238 | delete m_timer ; |
f5bb2251 GD |
239 | m_timer = NULL; |
240 | } | |
72c1ba98 | 241 | #endif // wxUSE_TIMER |
670f9935 | 242 | if ( m_backpict ) |
f5bb2251 | 243 | Clear() ; |
ee6b1d97 SC |
244 | } |
245 | ||
246 | const short kTipBorder = 2 ; | |
247 | const short kTipOffset = 5 ; | |
248 | ||
249 | void wxMacToolTip::Draw() | |
250 | { | |
670f9935 | 251 | if ( m_label.empty() ) |
e40298d5 | 252 | return ; |
670f9935 | 253 | |
e40298d5 JS |
254 | if ( m_window == s_ToolTipWindowRef ) |
255 | { | |
256 | m_shown = true ; | |
991f71dc | 257 | |
427ff662 SC |
258 | HMHelpContentRec tag ; |
259 | tag.version = kMacHelpVersion; | |
a9de2608 | 260 | |
fb743cab SC |
261 | Point p = { m_position.y , m_position.x }; |
262 | wxMacLocalToGlobal( m_window , &p ) ; | |
263 | SetRect( &tag.absHotRect , p.h - 2 , p.v - 2 , p.h + 2 , p.v + 2 ); | |
a9de2608 | 264 | |
991f71dc | 265 | m_helpTextRef.Assign( m_label , wxFONTENCODING_DEFAULT ) ; |
427ff662 SC |
266 | tag.content[kHMMinimumContentIndex].contentType = kHMCFStringContent ; |
267 | tag.content[kHMMinimumContentIndex].u.tagCFString = m_helpTextRef ; | |
268 | tag.content[kHMMaximumContentIndex].contentType = kHMCFStringContent ; | |
269 | tag.content[kHMMaximumContentIndex].u.tagCFString = m_helpTextRef ; | |
270 | tag.tagSide = kHMDefaultSide; | |
271 | HMDisplayTag( &tag ); | |
e40298d5 | 272 | } |
ee6b1d97 SC |
273 | } |
274 | ||
670f9935 | 275 | void wxToolTip::NotifyWindowDelete( WXHWND win ) |
ee6b1d97 | 276 | { |
e40298d5 | 277 | if ( win == s_ToolTipWindowRef ) |
e40298d5 | 278 | s_ToolTipWindowRef = NULL ; |
ee6b1d97 SC |
279 | } |
280 | ||
281 | void wxMacToolTip::Clear() | |
282 | { | |
e40298d5 | 283 | m_mark++ ; |
72c1ba98 | 284 | #if wxUSE_TIMER |
e40298d5 JS |
285 | if ( m_timer ) |
286 | { | |
287 | delete m_timer ; | |
288 | m_timer = NULL ; | |
289 | } | |
72c1ba98 | 290 | #endif // wxUSE_TIMER |
e40298d5 JS |
291 | if ( !m_shown ) |
292 | return ; | |
670f9935 | 293 | |
e40298d5 | 294 | HMHideTag() ; |
427ff662 | 295 | m_helpTextRef.Release() ; |
ee6b1d97 SC |
296 | } |
297 | ||
c0badb70 | 298 | #endif // wxUSE_TOOLTIPS |