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
;
56 wxMacToolTipTimer
* m_timer
;
59 wxMacCFStringHolder m_helpTextRef
;
63 class wxMacToolTipTimer
: public wxTimer
66 wxMacToolTipTimer(wxMacToolTip
* tip
, int iMilliseconds
) ;
67 wxMacToolTipTimer() {} ;
68 virtual ~wxMacToolTipTimer() {} ;
72 if ( m_mark
== m_tip
->GetMark() )
81 //-----------------------------------------------------------------------------
83 //-----------------------------------------------------------------------------
84 static long s_ToolTipDelay
= 500 ;
85 static bool s_ShowToolTips
= true ;
86 static wxMacToolTip s_ToolTip
;
87 static wxWindow
* s_LastWindowEntered
= NULL
;
88 static wxRect2DInt s_ToolTipArea
;
89 static WindowRef s_ToolTipWindowRef
= NULL
;
91 IMPLEMENT_ABSTRACT_CLASS(wxToolTip
, wxObject
)
94 wxToolTip::wxToolTip( const wxString
&tip
)
97 m_window
= (wxWindow
*) NULL
;
100 wxToolTip::~wxToolTip()
104 void wxToolTip::SetTip( const wxString
&tip
)
111 // update it immediately
112 wxToolInfo
ti(GetHwndOf(m_window
));
113 ti
.lpszText
= (wxChar
*)m_text
.c_str();
115 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_UPDATETIPTEXT
, 0, &ti
);
120 void wxToolTip::SetWindow( wxWindow
*win
)
125 void wxToolTip::Enable( bool flag
)
127 if ( s_ShowToolTips
!= flag
)
129 s_ShowToolTips
= flag
;
131 if ( s_ShowToolTips
)
141 void wxToolTip::SetDelay( long msecs
)
143 s_ToolTipDelay
= msecs
;
146 void wxToolTip::RelayEvent( wxWindow
*win
, wxMouseEvent
&event
)
148 if ( s_ShowToolTips
)
150 if ( event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
154 else if (event
.GetEventType() == wxEVT_ENTER_WINDOW
|| event
.GetEventType() == wxEVT_MOTION
)
156 wxPoint2DInt
where( event
.m_x
, event
.m_y
) ;
157 if ( s_LastWindowEntered
== win
&& s_ToolTipArea
.Contains( where
) )
163 s_ToolTipArea
= wxRect2DInt( event
.m_x
- 2 , event
.m_y
- 2 , 4 , 4 ) ;
164 s_LastWindowEntered
= win
;
166 WindowRef window
= MAC_WXHWND( win
->MacGetTopLevelWindowRef() ) ;
169 wxPoint
local( x
, y
) ;
170 win
->MacClientToRootWindow( &x
, &y
) ;
171 wxPoint
windowlocal( x
, y
) ;
172 s_ToolTip
.Setup( window
, win
->MacGetToolTipString( local
) , windowlocal
) ;
178 void wxToolTip::RemoveToolTips()
185 wxMacToolTipTimer::wxMacToolTipTimer( wxMacToolTip
*tip
, int msec
)
188 m_mark
= tip
->GetMark() ;
192 wxMacToolTip::wxMacToolTip()
201 void wxMacToolTip::Setup( WindowRef win
, const wxString
& text
, const wxPoint
& localPosition
)
206 m_position
= localPosition
;
209 s_ToolTipWindowRef
= m_window
;
215 m_timer
= new wxMacToolTipTimer( this , s_ToolTipDelay
) ;
218 wxMacToolTip::~wxMacToolTip()
230 const short kTipBorder
= 2 ;
231 const short kTipOffset
= 5 ;
233 void wxMacToolTip::Draw()
235 if ( m_label
.empty() )
238 if ( m_window
== s_ToolTipWindowRef
)
242 HMHelpContentRec tag
;
243 tag
.version
= kMacHelpVersion
;
245 Point p
= { m_position
.y
, m_position
.x
};
246 wxMacLocalToGlobal( m_window
, &p
) ;
247 SetRect( &tag
.absHotRect
, p
.h
- 2 , p
.v
- 2 , p
.h
+ 2 , p
.v
+ 2 );
249 m_helpTextRef
.Assign( m_label
, wxFONTENCODING_DEFAULT
) ;
250 tag
.content
[kHMMinimumContentIndex
].contentType
= kHMCFStringContent
;
251 tag
.content
[kHMMinimumContentIndex
].u
.tagCFString
= m_helpTextRef
;
252 tag
.content
[kHMMaximumContentIndex
].contentType
= kHMCFStringContent
;
253 tag
.content
[kHMMaximumContentIndex
].u
.tagCFString
= m_helpTextRef
;
254 tag
.tagSide
= kHMDefaultSide
;
255 HMDisplayTag( &tag
);
259 void wxToolTip::NotifyWindowDelete( WXHWND win
)
261 if ( win
== s_ToolTipWindowRef
)
262 s_ToolTipWindowRef
= NULL
;
265 void wxMacToolTip::Clear()
279 m_helpTextRef
.Release() ;
282 #endif // wxUSE_TOOLTIPS