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"
19 #include "wx/window.h"
20 #include "wx/tooltip.h"
22 #include "wx/geometry.h"
23 #include "wx/mac/aga.h"
24 #include "wx/mac/uma.h"
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
36 void Setup( WindowRef window
, wxString text
, wxPoint localPosition
) ;
37 long GetMark() { return m_mark
; }
40 bool IsShown() { return m_shown
; }
47 PicHandle m_backpict
;
52 class wxMacToolTipTimer
: wxTimer
55 wxMacToolTipTimer(wxMacToolTip
* tip
, int iMilliseconds
) ;
59 if ( m_mark
== m_tip
->GetMark() )
70 //-----------------------------------------------------------------------------
72 //-----------------------------------------------------------------------------
73 static long s_ToolTipDelay
= 500 ;
74 static bool s_ShowToolTips
= true ;
75 static wxMacToolTip s_ToolTip
;
76 static wxWindow
* s_LastWindowEntered
= NULL
;
77 static wxRect2DInt s_ToolTipArea
;
78 static WindowRef s_ToolTipWindowRef
= NULL
;
79 wxToolTip::wxToolTip( const wxString
&tip
)
82 m_window
= (wxWindow
*) NULL
;
85 wxToolTip::~wxToolTip()
89 void wxToolTip::SetTip( const wxString
&tip
)
96 // update it immediately
97 wxToolInfo ti(GetHwndOf(m_window));
98 ti.lpszText = (wxChar *)m_text.c_str();
100 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_UPDATETIPTEXT, 0, &ti);
105 void wxToolTip::SetWindow( wxWindow
*win
)
110 void wxToolTip::Enable( bool flag
)
112 if ( s_ShowToolTips
!= flag
)
114 s_ShowToolTips
= flag
;
115 if ( s_ShowToolTips
)
125 void wxToolTip::SetDelay( long msecs
)
127 s_ToolTipDelay
= msecs
;
130 void wxToolTip::RelayEvent( wxWindow
*win
, wxMouseEvent
&event
)
132 if ( s_ShowToolTips
)
134 if ( event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
138 else if (event
.GetEventType() == wxEVT_ENTER_WINDOW
|| event
.GetEventType() == wxEVT_MOTION
)
140 wxPoint2DInt
where( event
.m_x
, event
.m_y
) ;
141 if ( s_LastWindowEntered
== win
&& s_ToolTipArea
.Contains( where
) )
147 s_ToolTipArea
= wxRect2DInt( event
.m_x
- 2 , event
.m_y
- 2 , 4 , 4 ) ;
148 s_LastWindowEntered
= win
;
150 WindowRef window
= win
->GetMacRootWindow() ;
153 wxPoint
local( x
, y
) ;
154 win
->MacClientToRootWindow( &x
, &y
) ;
155 wxPoint
windowlocal( x
, y
) ;
156 s_ToolTip
.Setup( window
, win
->MacGetToolTipString( local
) , windowlocal
) ;
162 void wxToolTip::RemoveToolTips()
168 wxMacToolTipTimer::wxMacToolTipTimer( wxMacToolTip
*tip
, int msec
)
171 m_mark
= tip
->GetMark() ;
175 wxMacToolTip::wxMacToolTip()
183 void wxMacToolTip::Setup( WindowRef window
, wxString text
, wxPoint localPosition
)
187 m_position
= localPosition
;
188 m_label
= wxMacMakeMacStringFromPC( text
) ;
190 s_ToolTipWindowRef
= window
;
192 new wxMacToolTipTimer( this , s_ToolTipDelay
) ;
195 wxMacToolTip::~wxMacToolTip()
201 const short kTipBorder
= 2 ;
202 const short kTipOffset
= 5 ;
204 void wxMacToolTip::Draw()
206 if ( m_label
.Length() == 0 )
209 if ( m_window
== s_ToolTipWindowRef
)
212 AGAPortHelper
help( GetWindowPort( m_window
) );
214 AGAPortHelper
help( ( m_window
) );
219 TextFont( kFontIDGeneva
) ;
223 ::GetFontInfo(&fontInfo
);
224 short lineh
= fontInfo
.ascent
+ fontInfo
.descent
+ fontInfo
.leading
;
226 // short width = TextWidth( m_label , 0 ,m_label.Length() ) ;
229 int length
= m_label
.Length() ;
233 const char *text
= m_label
;
236 if( text
[i
] == 13 || text
[i
] == 10)
238 thiswidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
239 if ( thiswidth
> width
)
247 if ( i
- laststop
> 0 )
249 thiswidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
250 if ( thiswidth
> width
)
256 m_rect
.left
= m_position
.x
+ kTipOffset
;
257 m_rect
.top
= m_position
.y
+ kTipOffset
;
258 m_rect
.right
= m_rect
.left
+ width
+ 2 * kTipBorder
;
259 m_rect
.bottom
= m_rect
.top
+ height
+ 2 * kTipBorder
;
260 ClipRect( &m_rect
) ;
261 BackColor( whiteColor
) ;
262 ForeColor(blackColor
) ;
263 m_backpict
= OpenPicture(&m_rect
);
265 CopyBits(GetPortBitMapForCopyBits(GetWindowPort(m_window
)),
266 GetPortBitMapForCopyBits(GetWindowPort(m_window
)),
273 RGBColor yellow
= { 0xFFFF , 0xFFFF , (153<<8)+153 } ;
274 RGBBackColor( &yellow
) ;
275 EraseRect( &m_rect
) ;
276 FrameRect( &m_rect
) ;
277 BackColor( whiteColor
) ;
278 ForeColor(blackColor
) ;
279 ::MoveTo( m_rect
.left
+ kTipBorder
, m_rect
.top
+ fontInfo
.ascent
+ kTipBorder
);
286 if( text
[i
] == 13 || text
[i
] == 10)
288 ::DrawText( text
, laststop
, i
- laststop
) ;
290 ::MoveTo( m_rect
.left
+ kTipBorder
, m_rect
.top
+ fontInfo
.ascent
+ kTipBorder
+ height
);
296 ::DrawText( text
, laststop
, i
- laststop
) ;
297 ::TextMode( srcOr
) ;
298 wxDC::MacInvalidateSetup() ;
300 // DrawText( m_label , 0 , m_label.Length() ) ;
304 void wxToolTip::NotifyWindowDelete( WindowRef win
)
306 if ( win
== s_ToolTipWindowRef
)
308 s_ToolTipWindowRef
= NULL
;
312 void wxMacToolTip::Clear()
318 if ( m_window
== s_ToolTipWindowRef
&& m_backpict
)
321 AGAPortHelper
help( GetWindowPort(m_window
) ) ;
323 AGAPortHelper
help( (m_window
) ) ;
328 BackColor( whiteColor
) ;
329 ForeColor(blackColor
) ;
330 DrawPicture(m_backpict
, &m_rect
);
331 KillPicture(m_backpict
);
333 wxDC::MacInvalidateSetup() ;