1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/tooltip.mm
3 // Purpose: Cocoa tooltips
8 // Copyright: (c) Ryan Norton
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 // ===========================================================================
16 // ===========================================================================
18 // ---------------------------------------------------------------------------
20 // ---------------------------------------------------------------------------
25 #include "wx/window.h"
28 #include "wx/tooltip.h"
30 #include "wx/cocoa/autorelease.h"
31 #include "wx/cocoa/string.h"
33 #import <AppKit/NSView.h>
36 // Private object in AppKit - exists in 10.2 at least -
37 // most likely exists earlier too
39 @interface NSToolTipManager : NSObject
42 NSWindow *toolTipWindow;
43 NSMutableArray *toolTips;
45 NSDate *timeToolTipRemovedFromScreen;
46 struct __CFRunLoopTimer *toolTipDisplayTimer;
47 NSToolTip *currentDisplayedToolTip;
48 NSToolTip *currentFadingToolTip;
49 float currentFadeValue;
51 NSWindow *lastToolTipWindow;
55 + (id)sharedToolTipManager;
56 - (int)_addTrackingRect:(struct _NSRect)fp12 andStartToolTipIfNecessary:(BOOL)fp28 view:(id)fp32 owner:(id)fp32 toolTip:(id)fp36;
57 - (void)_checkToolTipDelay;
58 - (void)_removeToolTip:(id)fp12 stopTimerIfNecessary:(BOOL)fp16;
59 - (void)_removeTrackingRectForToolTip:(id)fp12 stopTimerIfNecessary:(BOOL)fp16;
60 - (int)_setToolTip:(id)fp12 forView:(id)fp16 cell:(id)fp20 rect:(struct _NSRect)fp20 owner:(id)fp36 ownerIsDisplayDelegate:(BOOL)fp43 userData:(void *)fp44;
61 - (void)_stopTimerIfRunningForToolTip:(id)fp12;
63 - (void)addTrackingRectForToolTip:(id)fp12;
65 - (void)displayToolTip:(id)fp12;
66 - (void)fadeToolTip:(id)fp12;
68 - (void)mouseEntered:(id)fp12;
69 - (void)mouseEnteredToolTip:(id)fp12 inWindow:(id)fp16 withEvent:(id)fp20;
70 - (void)mouseExited:(id)fp12;
71 - (void)orderOutToolTip;
72 - (void)orderOutToolTipImmediately:(BOOL)fp12;
73 - (void)recomputeToolTipsForView:(id)fp12 remove:(BOOL)fp16 add:(BOOL)fp20;
74 - (void)removeAllToolTipsForView:(id)fp12;
75 - (void)removeToolTipForView:(id)fp12 tag:(int)fp16;
76 - (void)setInitialToolTipDelay:(double)fp40;
77 - (void)setToolTip:(id)fp12 forView:(id)fp16 cell:(id)fp20;
78 - (int)setToolTipForView:(id)fp12 rect:(struct _NSRect)fp16 displayDelegate:(id)fp32 userData:(void *)fp32;
79 - (int)setToolTipForView:(id)fp12 rect:(struct _NSRect)fp16 owner:(id)fp32 userData:(void *)fp32;
80 - (void)setToolTipWithOwner:(id)fp12 forView:(id)fp16 cell:(id)fp20;
81 - (void)startTimer:(float)fp40 userInfo:(id)fp16;
83 - (id)toolTipForView:(id)fp12 cell:(id)fp16;
84 - (BOOL)viewHasToolTips:(id)fp12;
88 //-----------------------------------------------------------------------------
90 //-----------------------------------------------------------------------------
92 IMPLEMENT_ABSTRACT_CLASS(wxToolTip, wxObject)
94 wxToolTip::wxToolTip(const wxString &tip) :
95 m_text(tip), m_window(0)
99 wxToolTip::~wxToolTip()
103 void wxToolTip::SetTip(const wxString& tip)
108 const wxString& wxToolTip::GetTip() const
113 // the window we're associated with
114 wxWindow *wxToolTip::GetWindow() const
119 // enable or disable the tooltips globally
121 void wxToolTip::Enable(bool flag)
124 wxFAIL_MSG(wxT("Not implemented"));
127 // set the delay after which the tooltip appears
129 void wxToolTip::SetDelay(long milliseconds)
131 [[NSToolTipManager sharedToolTipManager] setInitialToolTipDelay: ((double)milliseconds) / 1000.0];
134 void wxToolTip::SetWindow(wxWindow* window)
136 wxAutoNSAutoreleasePool pool;
140 //set the tooltip - empty string means remove
142 [m_window->GetNSView() setToolTip:nil];
144 [m_window->GetNSView() setToolTip:wxNSStringWithWxString(m_text)];
147 #endif //wxUSE_TOOLTIPS