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 
: wxTimer
 
  58         wxMacToolTipTimer() {} ; 
  59         wxMacToolTipTimer(wxMacToolTip
* tip
, int iMilliseconds
) ; 
  60     virtual ~wxMacToolTipTimer() {} ; 
  63                 if ( m_mark 
== m_tip
->GetMark() ) 
  72 //----------------------------------------------------------------------------- 
  74 //----------------------------------------------------------------------------- 
  75 static long s_ToolTipDelay 
= 500 ; 
  76 static bool s_ShowToolTips 
= true ; 
  77 static wxMacToolTip s_ToolTip 
; 
  78 static wxWindow
* s_LastWindowEntered 
= NULL 
; 
  79 static wxRect2DInt s_ToolTipArea 
; 
  80 static WindowRef s_ToolTipWindowRef 
= NULL 
; 
  81 wxToolTip::wxToolTip( const wxString 
&tip 
) 
  84     m_window 
= (wxWindow
*) NULL
; 
  87 wxToolTip::~wxToolTip() 
  91 void wxToolTip::SetTip( const wxString 
&tip 
) 
  98         // update it immediately 
  99         wxToolInfo ti(GetHwndOf(m_window)); 
 100         ti.lpszText = (wxChar *)m_text.c_str(); 
 102         (void)SendTooltipMessage(GetToolTipCtrl(), TTM_UPDATETIPTEXT, 0, &ti); 
 107 void wxToolTip::SetWindow( wxWindow 
*win 
) 
 112 void wxToolTip::Enable( bool flag 
) 
 114         if ( s_ShowToolTips 
!= flag 
) 
 116                 s_ShowToolTips 
= flag 
; 
 117                 if ( s_ShowToolTips 
) 
 127 void wxToolTip::SetDelay( long msecs 
) 
 129         s_ToolTipDelay 
= msecs 
; 
 132 void wxToolTip::RelayEvent( wxWindow 
*win 
, wxMouseEvent 
&event 
) 
 134         if ( s_ShowToolTips 
) 
 136                 if ( event
.GetEventType() == wxEVT_LEAVE_WINDOW 
) 
 140                 else if (event
.GetEventType() == wxEVT_ENTER_WINDOW 
|| event
.GetEventType() == wxEVT_MOTION 
) 
 142                         wxPoint2DInt 
where( event
.m_x 
, event
.m_y 
) ; 
 143                         if ( s_LastWindowEntered 
== win 
&& s_ToolTipArea
.Contains( where 
) ) 
 149                                 s_ToolTipArea 
= wxRect2DInt( event
.m_x 
- 2 , event
.m_y 
- 2 , 4 , 4 ) ; 
 150                                 s_LastWindowEntered 
= win 
; 
 152                                 WindowRef window 
= MAC_WXHWND( win
->MacGetRootWindow() ) ; 
 155                                 wxPoint 
local( x 
, y 
) ; 
 156                                 win
->MacClientToRootWindow( &x
, &y 
) ; 
 157                                 wxPoint 
windowlocal( x 
, y 
) ; 
 158                                 s_ToolTip
.Setup( window 
, win
->MacGetToolTipString( local 
) , windowlocal 
) ; 
 164 void wxToolTip::RemoveToolTips() 
 170 wxMacToolTipTimer::wxMacToolTipTimer( wxMacToolTip 
*tip 
, int msec 
) 
 173         m_mark 
= tip
->GetMark() ; 
 177 wxMacToolTip::wxMacToolTip() 
 186 void wxMacToolTip::Setup( WindowRef window  
, wxString text 
, wxPoint localPosition 
)  
 190         m_position 
= localPosition 
; 
 191         m_label 
= wxMacMakeMacStringFromPC( text 
) ; 
 193         s_ToolTipWindowRef 
= window 
; 
 197         m_timer 
= new wxMacToolTipTimer( this , s_ToolTipDelay 
) ; 
 200 wxMacToolTip::~wxMacToolTip()  
 208 const short kTipBorder 
= 2 ; 
 209 const short kTipOffset 
= 5 ; 
 211 void wxMacToolTip::Draw() 
 213         if ( m_label
.Length() == 0 ) 
 216         if ( m_window 
== s_ToolTipWindowRef 
) 
 220           if ( HMDisplayTag != (void*) kUnresolvedCFragSymbolAddress ) 
 228                 wxMacPortStateHelper 
help( (GrafPtr
) GetWindowPort( m_window 
) ); 
 232                 TextFont( kFontIDGeneva 
) ; 
 236                 ::GetFontInfo(&fontInfo
); 
 237                 short lineh 
= fontInfo
.ascent 
+ fontInfo
.descent 
+ fontInfo
.leading
; 
 239         //      short width = TextWidth( m_label , 0 ,m_label.Length() ) ; 
 242                 int length 
= m_label
.Length() ; 
 246                 const char *text 
= m_label 
; 
 249                         if( text
[i
] == 13 || text
[i
] == 10) 
 251                                 thiswidth 
= ::TextWidth( text 
, laststop 
, i 
- laststop 
) ; 
 252                                 if ( thiswidth 
> width 
) 
 260                 if ( i 
- laststop 
> 0 ) 
 262                         thiswidth 
= ::TextWidth( text 
, laststop 
, i 
- laststop 
) ; 
 263                         if ( thiswidth 
> width 
) 
 269                 m_rect
.left 
= m_position
.x 
+ kTipOffset
; 
 270                 m_rect
.top 
= m_position
.y 
+ kTipOffset
; 
 271                 m_rect
.right 
= m_rect
.left 
+ width 
+ 2 * kTipBorder
; 
 272                 m_rect
.bottom 
= m_rect
.top 
+ height 
+ 2 * kTipBorder
; 
 273                 ClipRect( &m_rect 
) ; 
 274                 BackColor( whiteColor 
) ; 
 275                 ForeColor(blackColor 
) ; 
 276                 m_backpict 
= OpenPicture(&m_rect
); 
 278                 CopyBits(GetPortBitMapForCopyBits(GetWindowPort(m_window
)),  
 279                                    GetPortBitMapForCopyBits(GetWindowPort(m_window
)),  
 287                 SetThemeBackground(kThemeBrushNotificationWindowBackground
,32,true) ; 
 288                 SetThemeTextColor(kThemeTextColorNotification
,32,true) ; 
 289                 EraseRect( &m_rect 
) ; 
 290                 FrameRect( &m_rect 
) ; 
 291                 ::MoveTo( m_rect
.left 
+ kTipBorder 
, m_rect
.top 
+ fontInfo
.ascent 
+ kTipBorder
); 
 298                         if( text
[i
] == 13 || text
[i
] == 10) 
 300                                 ::DrawText( text 
, laststop 
, i 
- laststop 
) ; 
 302                                 ::MoveTo( m_rect
.left 
+ kTipBorder 
, m_rect
.top 
+ fontInfo
.ascent 
+ kTipBorder 
+ height 
); 
 308                 ::DrawText( text 
, laststop 
, i 
- laststop 
) ; 
 309                 ::TextMode( srcOr 
) ;            
 310         //      DrawText( m_label , 0 , m_label.Length() ) ; 
 315 void wxToolTip::NotifyWindowDelete( WXHWND win 
)  
 317         if ( win 
== s_ToolTipWindowRef 
) 
 319                 s_ToolTipWindowRef 
= NULL 
; 
 323 void wxMacToolTip::Clear() 
 334         if ( m_window 
== s_ToolTipWindowRef 
&& m_backpict 
) 
 336                 wxMacPortStateHelper 
help( (GrafPtr
) GetWindowPort(m_window
) ) ; 
 340                 BackColor( whiteColor 
) ; 
 341                 ForeColor(blackColor 
) ; 
 342                 DrawPicture(m_backpict
, &m_rect
); 
 343                 KillPicture(m_backpict
);