1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/tooltip.cpp
3 // Purpose: wxToolTip implementation
4 // Author: Stefan Csomor
6 // Copyright: (c) Stefan Csomor
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #include "wx/wxprec.h"
14 #include "wx/tooltip.h"
18 #include "wx/window.h"
23 #include "wx/geometry.h"
24 #include "wx/mac/uma.h"
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
30 class wxMacToolTipTimer
;
38 void Setup( WindowRef window
, const wxString
& text
, const wxPoint
& localPosition
) ;
53 PicHandle m_backpict
;
57 wxMacToolTipTimer
* m_timer
;
60 wxMacCFStringHolder m_helpTextRef
;
65 class wxMacToolTipTimer
: public wxTimer
68 wxMacToolTipTimer(wxMacToolTip
* tip
, int iMilliseconds
) ;
69 wxMacToolTipTimer() {} ;
70 virtual ~wxMacToolTipTimer() {} ;
74 if ( m_mark
== m_tip
->GetMark() )
84 //-----------------------------------------------------------------------------
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
;
94 IMPLEMENT_ABSTRACT_CLASS(wxToolTip
, wxObject
)
97 wxToolTip::wxToolTip( const wxString
&tip
)
100 m_window
= (wxWindow
*) NULL
;
103 wxToolTip::~wxToolTip()
107 void wxToolTip::SetTip( const wxString
&tip
)
114 // update it immediately
115 wxToolInfo
ti(GetHwndOf(m_window
));
116 ti
.lpszText
= (wxChar
*)m_text
.c_str();
118 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_UPDATETIPTEXT
, 0, &ti
);
123 void wxToolTip::SetWindow( wxWindow
*win
)
128 void wxToolTip::Enable( bool flag
)
130 if ( s_ShowToolTips
!= flag
)
132 s_ShowToolTips
= flag
;
134 if ( s_ShowToolTips
)
144 void wxToolTip::SetDelay( long msecs
)
146 s_ToolTipDelay
= msecs
;
149 void wxToolTip::SetAutoPop( long WXUNUSED(msecs
) )
153 void wxToolTip::SetReshow( long WXUNUSED(msecs
) )
157 void wxToolTip::RelayEvent( wxWindow
*win
, wxMouseEvent
&event
)
159 if ( s_ShowToolTips
)
161 if ( event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
165 else if (event
.GetEventType() == wxEVT_ENTER_WINDOW
|| event
.GetEventType() == wxEVT_MOTION
)
167 wxPoint2DInt
where( event
.m_x
, event
.m_y
) ;
168 if ( s_LastWindowEntered
== win
&& s_ToolTipArea
.Contains( where
) )
174 s_ToolTipArea
= wxRect2DInt( event
.m_x
- 2 , event
.m_y
- 2 , 4 , 4 ) ;
175 s_LastWindowEntered
= win
;
177 WindowRef window
= MAC_WXHWND( win
->MacGetTopLevelWindowRef() ) ;
180 wxPoint
local( x
, y
) ;
181 win
->MacClientToRootWindow( &x
, &y
) ;
182 wxPoint
windowlocal( x
, y
) ;
183 s_ToolTip
.Setup( window
, win
->MacGetToolTipString( local
) , windowlocal
) ;
189 void wxToolTip::RemoveToolTips()
196 wxMacToolTipTimer::wxMacToolTipTimer( wxMacToolTip
*tip
, int msec
)
199 m_mark
= tip
->GetMark() ;
202 #endif // wxUSE_TIMER
204 wxMacToolTip::wxMacToolTip()
215 void wxMacToolTip::Setup( WindowRef win
, const wxString
& text
, const wxPoint
& localPosition
)
220 m_position
= localPosition
;
223 s_ToolTipWindowRef
= m_window
;
229 m_timer
= new wxMacToolTipTimer( this , s_ToolTipDelay
) ;
230 #endif // wxUSE_TIMER
233 wxMacToolTip::~wxMacToolTip()
241 #endif // wxUSE_TIMER
246 const short kTipBorder
= 2 ;
247 const short kTipOffset
= 5 ;
249 void wxMacToolTip::Draw()
251 if ( m_label
.empty() )
254 if ( m_window
== s_ToolTipWindowRef
)
258 HMHelpContentRec tag
;
259 tag
.version
= kMacHelpVersion
;
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 );
265 m_helpTextRef
.Assign( m_label
, wxFONTENCODING_DEFAULT
) ;
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
);
275 void wxToolTip::NotifyWindowDelete( WXHWND win
)
277 if ( win
== s_ToolTipWindowRef
)
278 s_ToolTipWindowRef
= NULL
;
281 void wxMacToolTip::Clear()
290 #endif // wxUSE_TIMER
295 m_helpTextRef
.Release() ;
298 #endif // wxUSE_TOOLTIPS