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"
18 #include "wx/window.h"
19 #include "wx/tooltip.h"
20 #include "wx/geometry.h"
21 #include "wx/mac/aga.h"
22 #include "wx/mac/uma.h"
24 //-----------------------------------------------------------------------------
26 //-----------------------------------------------------------------------------
34 void Setup( WindowRef window
, wxString text
, wxPoint localPosition
) ;
35 long GetMark() { return m_mark
; }
38 bool IsShown() { return m_shown
; }
45 PicHandle m_backpict
;
50 class wxMacToolTipTimer
: wxTimer
53 wxMacToolTipTimer(wxMacToolTip
* tip
, int iMilliseconds
) ;
57 if ( m_mark
== m_tip
->GetMark() )
68 //-----------------------------------------------------------------------------
70 //-----------------------------------------------------------------------------
71 static long s_ToolTipDelay
= 500 ;
72 static bool s_ShowToolTips
= true ;
73 static wxMacToolTip s_ToolTip
;
74 static wxWindow
* s_LastWindowEntered
= NULL
;
75 static wxRect2DInt s_ToolTipArea
;
76 static WindowRef s_ToolTipWindowRef
= NULL
;
77 wxToolTip::wxToolTip( const wxString
&tip
)
80 m_window
= (wxWindow
*) NULL
;
83 wxToolTip::~wxToolTip()
87 void wxToolTip::SetTip( const wxString
&tip
)
94 // update it immediately
95 wxToolInfo ti(GetHwndOf(m_window));
96 ti.lpszText = (wxChar *)m_text.c_str();
98 (void)SendTooltipMessage(GetToolTipCtrl(), TTM_UPDATETIPTEXT, 0, &ti);
103 void wxToolTip::SetWindow( wxWindow
*win
)
108 void wxToolTip::Enable( bool flag
)
110 if ( s_ShowToolTips
!= flag
)
112 s_ShowToolTips
= flag
;
113 if ( s_ShowToolTips
)
123 void wxToolTip::SetDelay( long msecs
)
125 s_ToolTipDelay
= msecs
;
128 void wxToolTip::RelayEvent( wxWindow
*win
, wxMouseEvent
&event
)
130 if ( s_ShowToolTips
)
132 if ( event
.GetEventType() == wxEVT_LEAVE_WINDOW
)
136 else if (event
.GetEventType() == wxEVT_ENTER_WINDOW
|| event
.GetEventType() == wxEVT_MOTION
)
138 wxPoint2DInt
where( event
.m_x
, event
.m_y
) ;
139 if ( s_LastWindowEntered
== win
&& s_ToolTipArea
.Contains( where
) )
145 s_ToolTipArea
= wxRect2DInt( event
.m_x
- 2 , event
.m_y
- 2 , 4 , 4 ) ;
146 s_LastWindowEntered
= win
;
148 WindowRef window
= win
->GetMacRootWindow() ;
151 wxPoint
local( x
, y
) ;
152 win
->MacClientToRootWindow( &x
, &y
) ;
153 wxPoint
windowlocal( x
, y
) ;
154 s_ToolTip
.Setup( window
, win
->MacGetToolTipString( local
) , windowlocal
) ;
160 void wxToolTip::RemoveToolTips()
166 wxMacToolTipTimer::wxMacToolTipTimer( wxMacToolTip
*tip
, int msec
)
169 m_mark
= tip
->GetMark() ;
173 wxMacToolTip::wxMacToolTip()
181 void wxMacToolTip::Setup( WindowRef window
, wxString text
, wxPoint localPosition
)
185 m_position
= localPosition
;
186 m_label
= wxMacMakeMacStringFromPC( text
) ;
188 s_ToolTipWindowRef
= window
;
190 new wxMacToolTipTimer( this , s_ToolTipDelay
) ;
193 wxMacToolTip::~wxMacToolTip()
199 const short kTipBorder
= 2 ;
200 const short kTipOffset
= 5 ;
202 void wxMacToolTip::Draw()
204 if ( m_label
.Length() == 0 )
207 if ( m_window
== s_ToolTipWindowRef
)
210 AGAPortHelper
help( GetWindowPort( m_window
) );
212 AGAPortHelper
help( ( m_window
) );
217 TextFont( kFontIDGeneva
) ;
221 ::GetFontInfo(&fontInfo
);
222 short lineh
= fontInfo
.ascent
+ fontInfo
.descent
+ fontInfo
.leading
;
224 // short width = TextWidth( m_label , 0 ,m_label.Length() ) ;
227 int length
= m_label
.Length() ;
231 const char *text
= m_label
;
234 if( text
[i
] == 13 || text
[i
] == 10)
236 thiswidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
237 if ( thiswidth
> width
)
245 if ( i
- laststop
> 0 )
247 thiswidth
= ::TextWidth( text
, laststop
, i
- laststop
) ;
248 if ( thiswidth
> width
)
254 m_rect
.left
= m_position
.x
+ kTipOffset
;
255 m_rect
.top
= m_position
.y
+ kTipOffset
;
256 m_rect
.right
= m_rect
.left
+ width
+ 2 * kTipBorder
;
257 m_rect
.bottom
= m_rect
.top
+ height
+ 2 * kTipBorder
;
258 ClipRect( &m_rect
) ;
259 BackColor( whiteColor
) ;
260 ForeColor(blackColor
) ;
261 m_backpict
= OpenPicture(&m_rect
);
263 CopyBits(GetPortBitMapForCopyBits(GetWindowPort(m_window
)),
264 GetPortBitMapForCopyBits(GetWindowPort(m_window
)),
271 RGBColor yellow
= { 0xFFFF , 0xFFFF , (153<<8)+153 } ;
272 RGBBackColor( &yellow
) ;
273 EraseRect( &m_rect
) ;
274 FrameRect( &m_rect
) ;
275 BackColor( whiteColor
) ;
276 ForeColor(blackColor
) ;
277 ::MoveTo( m_rect
.left
+ kTipBorder
, m_rect
.top
+ fontInfo
.ascent
+ kTipBorder
);
284 if( text
[i
] == 13 || text
[i
] == 10)
286 ::DrawText( text
, laststop
, i
- laststop
) ;
288 ::MoveTo( m_rect
.left
+ kTipBorder
, m_rect
.top
+ fontInfo
.ascent
+ kTipBorder
+ height
);
294 ::DrawText( text
, laststop
, i
- laststop
) ;
295 ::TextMode( srcOr
) ;
297 // DrawText( m_label , 0 , m_label.Length() ) ;
301 void wxToolTip::NotifyWindowDelete( WindowRef win
)
303 if ( win
== s_ToolTipWindowRef
)
305 s_ToolTipWindowRef
= NULL
;
309 void wxMacToolTip::Clear()
315 if ( m_window
== s_ToolTipWindowRef
&& m_backpict
)
318 AGAPortHelper
help( GetWindowPort(m_window
) ) ;
320 AGAPortHelper
help( (m_window
) ) ;
325 BackColor( whiteColor
) ;
326 ForeColor(blackColor
) ;
327 DrawPicture(m_backpict
, &m_rect
);
328 KillPicture(m_backpict
);