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::RelayEvent( wxWindow
*win
, wxMouseEvent
&event
)
151 if ( s_ShowToolTips
)
153 if ( event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
157 else if (event
.GetEventType() == wxEVT_ENTER_WINDOW
|| event
.GetEventType() == wxEVT_MOTION
)
159 wxPoint2DInt
where( event
.m_x
, event
.m_y
) ;
160 if ( s_LastWindowEntered
== win
&& s_ToolTipArea
.Contains( where
) )
166 s_ToolTipArea
= wxRect2DInt( event
.m_x
- 2 , event
.m_y
- 2 , 4 , 4 ) ;
167 s_LastWindowEntered
= win
;
169 WindowRef window
= MAC_WXHWND( win
->MacGetTopLevelWindowRef() ) ;
172 wxPoint
local( x
, y
) ;
173 win
->MacClientToRootWindow( &x
, &y
) ;
174 wxPoint
windowlocal( x
, y
) ;
175 s_ToolTip
.Setup( window
, win
->MacGetToolTipString( local
) , windowlocal
) ;
181 void wxToolTip::RemoveToolTips()
188 wxMacToolTipTimer::wxMacToolTipTimer( wxMacToolTip
*tip
, int msec
)
191 m_mark
= tip
->GetMark() ;
194 #endif // wxUSE_TIMER
196 wxMacToolTip::wxMacToolTip()
207 void wxMacToolTip::Setup( WindowRef win
, const wxString
& text
, const wxPoint
& localPosition
)
212 m_position
= localPosition
;
215 s_ToolTipWindowRef
= m_window
;
221 m_timer
= new wxMacToolTipTimer( this , s_ToolTipDelay
) ;
222 #endif // wxUSE_TIMER
225 wxMacToolTip::~wxMacToolTip()
233 #endif // wxUSE_TIMER
238 const short kTipBorder
= 2 ;
239 const short kTipOffset
= 5 ;
241 void wxMacToolTip::Draw()
243 if ( m_label
.empty() )
246 if ( m_window
== s_ToolTipWindowRef
)
250 HMHelpContentRec tag
;
251 tag
.version
= kMacHelpVersion
;
253 Point p
= { m_position
.y
, m_position
.x
};
254 wxMacLocalToGlobal( m_window
, &p
) ;
255 SetRect( &tag
.absHotRect
, p
.h
- 2 , p
.v
- 2 , p
.h
+ 2 , p
.v
+ 2 );
257 m_helpTextRef
.Assign( m_label
, wxFONTENCODING_DEFAULT
) ;
258 tag
.content
[kHMMinimumContentIndex
].contentType
= kHMCFStringContent
;
259 tag
.content
[kHMMinimumContentIndex
].u
.tagCFString
= m_helpTextRef
;
260 tag
.content
[kHMMaximumContentIndex
].contentType
= kHMCFStringContent
;
261 tag
.content
[kHMMaximumContentIndex
].u
.tagCFString
= m_helpTextRef
;
262 tag
.tagSide
= kHMDefaultSide
;
263 HMDisplayTag( &tag
);
267 void wxToolTip::NotifyWindowDelete( WXHWND win
)
269 if ( win
== s_ToolTipWindowRef
)
270 s_ToolTipWindowRef
= NULL
;
273 void wxMacToolTip::Clear()
282 #endif // wxUSE_TIMER
287 m_helpTextRef
.Release() ;
290 #endif // wxUSE_TOOLTIPS