1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxToolTip implementation
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "tooltip.h"
20 #include "wx/window.h"
21 #include "wx/tooltip.h"
23 #include "wx/geometry.h"
24 #include "wx/mac/uma.h"
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
30 class wxMacToolTipTimer
;
38 void Setup( WindowRef window
, wxString text
, wxPoint localPosition
) ;
39 long GetMark() { return m_mark
; }
42 bool IsShown() { return m_shown
; }
49 PicHandle m_backpict
;
52 wxMacToolTipTimer
* m_timer
;
55 class wxMacToolTipTimer
: public wxTimer
58 wxMacToolTipTimer() {} ;
59 wxMacToolTipTimer(wxMacToolTip
* tip
, int iMilliseconds
) ;
60 virtual ~wxMacToolTipTimer() {} ;
63 if ( m_mark
== m_tip
->GetMark() )
71 //-----------------------------------------------------------------------------
73 //-----------------------------------------------------------------------------
74 static long s_ToolTipDelay
= 500 ;
75 static bool s_ShowToolTips
= true ;
76 static wxMacToolTip s_ToolTip
;
77 static wxWindow
* s_LastWindowEntered
= NULL
;
78 static wxRect2DInt s_ToolTipArea
;
79 static WindowRef s_ToolTipWindowRef
= NULL
;
80 wxToolTip::wxToolTip( const wxString
&tip
)
83 m_window
= (wxWindow
*) NULL
;
86 wxToolTip::~wxToolTip()
90 void wxToolTip::SetTip( const wxString
&tip
)
97 // update it immediately
98 wxToolInfo ti(GetHwndOf(m_window));
99 ti.lpszText = (wxChar *)m_text.c_str();
101 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_UPDATETIPTEXT, 0, &ti);
106 void wxToolTip::SetWindow( wxWindow
*win
)
111 void wxToolTip::Enable( bool flag
)
113 if ( s_ShowToolTips
!= flag
)
115 s_ShowToolTips
= flag
;
116 if ( s_ShowToolTips
)
126 void wxToolTip::SetDelay( long msecs
)
128 s_ToolTipDelay
= msecs
;
131 void wxToolTip::RelayEvent( wxWindow
*win
, wxMouseEvent
&event
)
133 if ( s_ShowToolTips
)
135 if ( event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
139 else if (event
.GetEventType() == wxEVT_ENTER_WINDOW
|| event
.GetEventType() == wxEVT_MOTION
)
141 wxPoint2DInt
where( event
.m_x
, event
.m_y
) ;
142 if ( s_LastWindowEntered
== win
&& s_ToolTipArea
.Contains( where
) )
148 s_ToolTipArea
= wxRect2DInt( event
.m_x
- 2 , event
.m_y
- 2 , 4 , 4 ) ;
149 s_LastWindowEntered
= win
;
151 WindowRef window
= MAC_WXHWND( win
->MacGetRootWindow() ) ;
154 wxPoint
local( x
, y
) ;
155 win
->MacClientToRootWindow( &x
, &y
) ;
156 wxPoint
windowlocal( x
, y
) ;
157 s_ToolTip
.Setup( window
, win
->MacGetToolTipString( local
) , windowlocal
) ;
163 void wxToolTip::RemoveToolTips()
169 wxMacToolTipTimer::wxMacToolTipTimer( wxMacToolTip
*tip
, int msec
)
172 m_mark
= tip
->GetMark() ;
176 wxMacToolTip::wxMacToolTip()
185 void wxMacToolTip::Setup( WindowRef window
, wxString text
, wxPoint localPosition
)
189 m_position
= localPosition
;
190 m_label
= wxMacMakeMacStringFromPC( text
) ;
192 s_ToolTipWindowRef
= window
;
196 m_timer
= new wxMacToolTipTimer( this , s_ToolTipDelay
) ;
199 wxMacToolTip::~wxMacToolTip()
207 const short kTipBorder
= 2 ;
208 const short kTipOffset
= 5 ;
210 void wxMacToolTip::Draw()
212 if ( m_label
.Length() == 0 )
215 if ( m_window
== s_ToolTipWindowRef
)
219 if ( HMDisplayTag != (void*) kUnresolvedCFragSymbolAddress )
227 wxMacPortStateHelper
help( (GrafPtr
) GetWindowPort( m_window
) );
231 TextFont( kFontIDGeneva
) ;
235 ::GetFontInfo(&fontInfo
);
236 short lineh
= fontInfo
.ascent
+ fontInfo
.descent
+ fontInfo
.leading
;
238 // short width = TextWidth( m_label , 0 ,m_label.Length() ) ;
241 int length
= m_label
.Length() ;
245 const char *text
= m_label
;
248 if( text
[i
] == 13 || text
[i
] == 10)
250 thiswidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
251 if ( thiswidth
> width
)
259 if ( i
- laststop
> 0 )
261 thiswidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
262 if ( thiswidth
> width
)
268 m_rect
.left
= m_position
.x
+ kTipOffset
;
269 m_rect
.top
= m_position
.y
+ kTipOffset
;
270 m_rect
.right
= m_rect
.left
+ width
+ 2 * kTipBorder
;
271 m_rect
.bottom
= m_rect
.top
+ height
+ 2 * kTipBorder
;
272 ClipRect( &m_rect
) ;
273 BackColor( whiteColor
) ;
274 ForeColor(blackColor
) ;
275 m_backpict
= OpenPicture(&m_rect
);
277 CopyBits(GetPortBitMapForCopyBits(GetWindowPort(m_window
)),
278 GetPortBitMapForCopyBits(GetWindowPort(m_window
)),
286 SetThemeBackground(kThemeBrushNotificationWindowBackground
,32,true) ;
287 SetThemeTextColor(kThemeTextColorNotification
,32,true) ;
288 EraseRect( &m_rect
) ;
289 FrameRect( &m_rect
) ;
290 ::MoveTo( m_rect
.left
+ kTipBorder
, m_rect
.top
+ fontInfo
.ascent
+ kTipBorder
);
297 if( text
[i
] == 13 || text
[i
] == 10)
299 ::DrawText( text
, laststop
, i
- laststop
) ;
301 ::MoveTo( m_rect
.left
+ kTipBorder
, m_rect
.top
+ fontInfo
.ascent
+ kTipBorder
+ height
);
307 ::DrawText( text
, laststop
, i
- laststop
) ;
308 ::TextMode( srcOr
) ;
309 // DrawText( m_label , 0 , m_label.Length() ) ;
314 void wxToolTip::NotifyWindowDelete( WXHWND win
)
316 if ( win
== s_ToolTipWindowRef
)
318 s_ToolTipWindowRef
= NULL
;
322 void wxMacToolTip::Clear()
333 if ( m_window
== s_ToolTipWindowRef
&& m_backpict
)
335 wxMacPortStateHelper
help( (GrafPtr
) GetWindowPort(m_window
) ) ;
339 BackColor( whiteColor
) ;
340 ForeColor(blackColor
) ;
341 DrawPicture(m_backpict
, &m_rect
);
342 KillPicture(m_backpict
);