1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/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"
21 #include "wx/nonownedwnd.h"
24 #include "wx/geometry.h"
25 #include "wx/osx/uma.h"
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
32 class wxMacToolTipTimer
: public wxTimer
35 wxMacToolTipTimer(wxMacToolTip
* tip
, int iMilliseconds
) ;
36 wxMacToolTipTimer() {} ;
37 virtual ~wxMacToolTipTimer() {} ;
41 if ( m_mark
== m_tip
->GetMark() )
51 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
54 static long s_ToolTipDelay
= 500 ;
55 static bool s_ShowToolTips
= true ;
56 static wxMacToolTip s_ToolTip
;
57 static wxWindow
* s_LastWindowEntered
= NULL
;
58 static wxRect2DInt s_ToolTipArea
;
59 static WindowRef s_ToolTipWindowRef
= NULL
;
61 IMPLEMENT_ABSTRACT_CLASS(wxToolTip
, wxObject
)
64 wxToolTip::wxToolTip( const wxString
&tip
)
67 m_window
= (wxWindow
*) NULL
;
70 wxToolTip::~wxToolTip()
74 void wxToolTip::SetTip( const wxString
&tip
)
81 // update it immediately
82 wxToolInfo
ti(GetHwndOf(m_window
));
83 ti
.lpszText
= (wxChar
*)m_text
.c_str();
85 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_UPDATETIPTEXT
, 0, &ti
);
90 void wxToolTip::SetWindow( wxWindow
*win
)
95 void wxToolTip::Enable( bool flag
)
97 if ( s_ShowToolTips
!= flag
)
99 s_ShowToolTips
= flag
;
101 if ( s_ShowToolTips
)
111 void wxToolTip::SetDelay( long msecs
)
113 s_ToolTipDelay
= msecs
;
116 void wxToolTip::SetAutoPop( long WXUNUSED(msecs
) )
120 void wxToolTip::SetReshow( long WXUNUSED(msecs
) )
124 void wxToolTip::RelayEvent( wxWindow
*win
, wxMouseEvent
&event
)
126 if ( s_ShowToolTips
)
128 if ( event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
132 else if (event
.GetEventType() == wxEVT_ENTER_WINDOW
|| event
.GetEventType() == wxEVT_MOTION
)
134 wxPoint2DInt
where( event
.m_x
, event
.m_y
) ;
135 if ( s_LastWindowEntered
== win
&& s_ToolTipArea
.Contains( where
) )
141 s_ToolTipArea
= wxRect2DInt( event
.m_x
- 2 , event
.m_y
- 2 , 4 , 4 ) ;
142 s_LastWindowEntered
= win
;
144 WindowRef window
= MAC_WXHWND( win
->MacGetTopLevelWindowRef() ) ;
147 wxPoint
local( x
, y
) ;
148 win
->MacClientToRootWindow( &x
, &y
) ;
149 wxPoint
windowlocal( x
, y
) ;
150 s_ToolTip
.Setup( window
, win
->MacGetToolTipString( local
) , windowlocal
) ;
156 void wxToolTip::RemoveToolTips()
163 wxMacToolTipTimer::wxMacToolTipTimer( wxMacToolTip
*tip
, int msec
)
166 m_mark
= tip
->GetMark() ;
169 #endif // wxUSE_TIMER
171 wxMacToolTip::wxMacToolTip()
182 void wxMacToolTip::Setup( WindowRef win
, const wxString
& text
, const wxPoint
& localPosition
)
187 m_position
= localPosition
;
190 s_ToolTipWindowRef
= m_window
;
196 m_timer
= new wxMacToolTipTimer( this , s_ToolTipDelay
) ;
197 #endif // wxUSE_TIMER
200 wxMacToolTip::~wxMacToolTip()
208 #endif // wxUSE_TIMER
213 const short kTipBorder
= 2 ;
214 const short kTipOffset
= 5 ;
216 void wxMacToolTip::Draw()
218 if ( m_label
.empty() )
221 if ( m_window
== s_ToolTipWindowRef
)
225 HMHelpContentRec tag
;
226 tag
.version
= kMacHelpVersion
;
228 int x
= m_position
.x
;
229 int y
= m_position
.y
;
230 wxNonOwnedWindow
* tlw
= wxNonOwnedWindow::GetFromWXWindow((WXWindow
) m_window
);
232 tlw
->GetNonOwnedPeer()->WindowToScreen( &x
, &y
);
233 SetRect( &tag
.absHotRect
, x
- 2 , y
- 2 , x
+ 2 , y
+ 2 );
235 m_helpTextRef
= wxCFStringRef( m_label
, wxFONTENCODING_DEFAULT
) ;
236 tag
.content
[kHMMinimumContentIndex
].contentType
= kHMCFStringContent
;
237 tag
.content
[kHMMinimumContentIndex
].u
.tagCFString
= m_helpTextRef
;
238 tag
.content
[kHMMaximumContentIndex
].contentType
= kHMCFStringContent
;
239 tag
.content
[kHMMaximumContentIndex
].u
.tagCFString
= m_helpTextRef
;
240 tag
.tagSide
= kHMDefaultSide
;
241 HMDisplayTag( &tag
);
245 void wxToolTip::NotifyWindowDelete( WXHWND win
)
247 if ( win
== s_ToolTipWindowRef
)
248 s_ToolTipWindowRef
= NULL
;
251 void wxMacToolTip::Clear()
260 #endif // wxUSE_TIMER
267 #endif // wxUSE_TOOLTIPS