1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/tooltip.cpp
3 // Purpose: wxToolTip implementation
4 // Author: Stefan Csomor
5 // Copyright: (c) Stefan Csomor
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
13 #include "wx/tooltip.h"
17 #include "wx/window.h"
20 #include "wx/nonownedwnd.h"
23 #include "wx/geometry.h"
24 #include "wx/osx/uma.h"
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
31 class wxMacToolTipTimer
: public wxTimer
34 wxMacToolTipTimer(wxMacToolTip
* tip
, int iMilliseconds
) ;
35 wxMacToolTipTimer() {} ;
36 virtual ~wxMacToolTipTimer() {} ;
40 if ( m_mark
== m_tip
->GetMark() )
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
53 static long s_ToolTipDelay
= 500 ;
54 static bool s_ShowToolTips
= true ;
55 static wxMacToolTip s_ToolTip
;
56 static wxWindow
* s_LastWindowEntered
= NULL
;
57 static wxRect2DInt s_ToolTipArea
;
58 static WindowRef s_ToolTipWindowRef
= NULL
;
60 IMPLEMENT_ABSTRACT_CLASS(wxToolTip
, wxObject
)
63 wxToolTip::wxToolTip( const wxString
&tip
)
69 wxToolTip::~wxToolTip()
73 void wxToolTip::SetTip( const wxString
&tip
)
80 // update it immediately
81 wxToolInfo
ti(GetHwndOf(m_window
));
82 ti
.lpszText
= (wxChar
*)m_text
.c_str();
84 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_UPDATETIPTEXT
, 0, &ti
);
89 void wxToolTip::SetWindow( wxWindow
*win
)
94 void wxToolTip::Enable( bool flag
)
96 if ( s_ShowToolTips
!= flag
)
98 s_ShowToolTips
= flag
;
100 if ( s_ShowToolTips
)
110 void wxToolTip::SetDelay( long msecs
)
112 s_ToolTipDelay
= msecs
;
115 void wxToolTip::SetAutoPop( long WXUNUSED(msecs
) )
119 void wxToolTip::SetReshow( long WXUNUSED(msecs
) )
123 void wxToolTip::RelayEvent( wxWindow
*win
, wxMouseEvent
&event
)
125 if ( s_ShowToolTips
)
127 if ( event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
131 else if (event
.GetEventType() == wxEVT_ENTER_WINDOW
|| event
.GetEventType() == wxEVT_MOTION
)
133 wxPoint2DInt
where( event
.m_x
, event
.m_y
) ;
134 if ( s_LastWindowEntered
== win
&& s_ToolTipArea
.Contains( where
) )
140 s_ToolTipArea
= wxRect2DInt( event
.m_x
- 2 , event
.m_y
- 2 , 4 , 4 ) ;
141 s_LastWindowEntered
= win
;
143 WindowRef window
= MAC_WXHWND( win
->MacGetTopLevelWindowRef() ) ;
146 wxPoint
local( x
, y
) ;
147 win
->MacClientToRootWindow( &x
, &y
) ;
148 wxPoint
windowlocal( x
, y
) ;
149 s_ToolTip
.Setup( window
, win
->MacGetToolTipString( local
) , windowlocal
) ;
155 void wxToolTip::RemoveToolTips()
162 wxMacToolTipTimer::wxMacToolTipTimer( wxMacToolTip
*tip
, int msec
)
165 m_mark
= tip
->GetMark() ;
168 #endif // wxUSE_TIMER
170 wxMacToolTip::wxMacToolTip()
181 void wxMacToolTip::Setup( WindowRef win
, const wxString
& text
, const wxPoint
& localPosition
)
186 m_position
= localPosition
;
189 s_ToolTipWindowRef
= m_window
;
194 m_timer
= new wxMacToolTipTimer( this , s_ToolTipDelay
) ;
195 #endif // wxUSE_TIMER
198 wxMacToolTip::~wxMacToolTip()
202 #endif // wxUSE_TIMER
207 const short kTipBorder
= 2 ;
208 const short kTipOffset
= 5 ;
210 void wxMacToolTip::Draw()
212 if ( m_label
.empty() )
215 if ( m_window
== s_ToolTipWindowRef
)
219 HMHelpContentRec tag
;
220 tag
.version
= kMacHelpVersion
;
222 int x
= m_position
.x
;
223 int y
= m_position
.y
;
224 wxNonOwnedWindow
* tlw
= wxNonOwnedWindow::GetFromWXWindow((WXWindow
) m_window
);
226 tlw
->GetNonOwnedPeer()->WindowToScreen( &x
, &y
);
227 SetRect( &tag
.absHotRect
, x
- 2 , y
- 2 , x
+ 2 , y
+ 2 );
229 m_helpTextRef
= wxCFStringRef( m_label
, wxFONTENCODING_DEFAULT
) ;
230 tag
.content
[kHMMinimumContentIndex
].contentType
= kHMCFStringContent
;
231 tag
.content
[kHMMinimumContentIndex
].u
.tagCFString
= m_helpTextRef
;
232 tag
.content
[kHMMaximumContentIndex
].contentType
= kHMCFStringContent
;
233 tag
.content
[kHMMaximumContentIndex
].u
.tagCFString
= m_helpTextRef
;
234 tag
.tagSide
= kHMDefaultSide
;
235 HMDisplayTag( &tag
);
239 void wxToolTip::NotifyWindowDelete( WXHWND win
)
241 if ( win
== s_ToolTipWindowRef
)
242 s_ToolTipWindowRef
= NULL
;
245 void wxMacToolTip::Clear()
250 #endif // wxUSE_TIMER
257 #endif // wxUSE_TOOLTIPS