From: Kevin Ollivier <kevino@theolliviers.com>
Date: Sat, 13 Feb 2010 06:30:06 +0000 (+0000)
Subject: Basic support for tooltips under OS X Cocoa.
X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/a7b9865d30b4e74f5a879901c47b45c108578caf

Basic support for tooltips under OS X Cocoa.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63477 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---

diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h
index 709a39dbbe..dd52324ea9 100644
--- a/include/wx/osx/cocoa/private.h
+++ b/include/wx/osx/cocoa/private.h
@@ -145,6 +145,7 @@ public :
     void                SetScrollThumb( wxInt32 value, wxInt32 thumbSize );
 
     void                SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack = true );
+    void                SetToolTip( wxToolTip* tooltip );
 
     void                InstallEventHandler( WXWidget control = NULL );
 
diff --git a/include/wx/osx/core/private.h b/include/wx/osx/core/private.h
index 79b6524098..49b2f13417 100644
--- a/include/wx/osx/core/private.h
+++ b/include/wx/osx/core/private.h
@@ -268,6 +268,8 @@ public :
     virtual void        SetScrollThumb( wxInt32 value, wxInt32 thumbSize ) = 0;
 
     virtual void        SetFont( const wxFont & font , const wxColour& foreground , long windowStyle, bool ignoreBlack = true ) = 0;
+    
+    virtual void        SetToolTip(wxToolTip* WXUNUSED(tooltip)) { }
 
     // is the clicked event sent AFTER the state already changed, so no additional
     // state changing logic is required from the outside
diff --git a/src/osx/cocoa/tooltip.mm b/src/osx/cocoa/tooltip.mm
index 16ecda0f5b..d0b73a59ce 100644
--- a/src/osx/cocoa/tooltip.mm
+++ b/src/osx/cocoa/tooltip.mm
@@ -47,6 +47,8 @@ wxToolTip::~wxToolTip()
 void wxToolTip::SetTip( const wxString &tip )
 {
     m_text = tip;
+    if (m_window)
+        m_window->SetToolTip(this);
 }
 
 void wxToolTip::SetWindow( wxWindow *win )
diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm
index 8ab72ea342..a2aea90d23 100644
--- a/src/osx/cocoa/window.mm
+++ b/src/osx/cocoa/window.mm
@@ -32,6 +32,10 @@
     #include "wx/dnd.h"
 #endif
 
+#if wxUSE_TOOLTIPS
+    #include "wx/tooltip.h"
+#endif
+
 #include <objc/objc-runtime.h>
 
 // Get the window with the focus
@@ -1890,6 +1894,18 @@ void wxWidgetCocoaImpl::SetFont(wxFont const& font, wxColour const&, long, bool)
         [m_osxView setFont: font.OSXGetNSFont()];
 }
 
+void wxWidgetCocoaImpl::SetToolTip(wxToolTip* tooltip)
+{
+    if (tooltip)
+    {
+        wxCFStringRef cf( tooltip->GetTip() , m_wxPeer->GetFont().GetEncoding() );
+        [m_osxView setToolTip: cf.AsNSString()];
+    }
+    else 
+        [m_osxView setToolTip: nil];
+
+}
+
 void wxWidgetCocoaImpl::InstallEventHandler( WXWidget control )
 {
     WXWidget c =  control ? control : (WXWidget) m_osxView;
diff --git a/src/osx/window_osx.cpp b/src/osx/window_osx.cpp
index 041c9d952e..b091cbcab5 100644
--- a/src/osx/window_osx.cpp
+++ b/src/osx/window_osx.cpp
@@ -752,6 +752,9 @@ void wxWindowMac::DoSetToolTip(wxToolTip *tooltip)
 
     if ( m_tooltip )
         m_tooltip->SetWindow(this);
+        
+    if (m_peer)
+        m_peer->SetToolTip(tooltip);
 }
 
 #endif