1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/tooltip.mm
3 // Purpose: Cocoa tooltips
8 // Copyright: (c) Ryan Norton
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
24 #include "wx/window.h"
25 #include "wx/tooltip.h"
27 #include "wx/cocoa/autorelease.h"
28 #include "wx/cocoa/string.h"
30 #import <AppKit/NSView.h>
33 // Private object in AppKit - exists in 10.2 at least -
34 // most likely exists earlier too
36 @interface NSToolTipManager : NSObject
39 NSWindow *toolTipWindow;
40 NSMutableArray *toolTips;
42 NSDate *timeToolTipRemovedFromScreen;
43 struct __CFRunLoopTimer *toolTipDisplayTimer;
44 NSToolTip *currentDisplayedToolTip;
45 NSToolTip *currentFadingToolTip;
46 float currentFadeValue;
48 NSWindow *lastToolTipWindow;
52 + (id)sharedToolTipManager;
53 - (int)_addTrackingRect:(struct _NSRect)fp12 andStartToolTipIfNecessary:(BOOL)fp28 view:(id)fp32 owner:(id)fp32 toolTip:(id)fp36;
54 - (void)_checkToolTipDelay;
55 - (void)_removeToolTip:(id)fp12 stopTimerIfNecessary:(BOOL)fp16;
56 - (void)_removeTrackingRectForToolTip:(id)fp12 stopTimerIfNecessary:(BOOL)fp16;
57 - (int)_setToolTip:(id)fp12 forView:(id)fp16 cell:(id)fp20 rect:(struct _NSRect)fp20 owner:(id)fp36 ownerIsDisplayDelegate:(BOOL)fp43 userData:(void *)fp44;
58 - (void)_stopTimerIfRunningForToolTip:(id)fp12;
60 - (void)addTrackingRectForToolTip:(id)fp12;
62 - (void)displayToolTip:(id)fp12;
63 - (void)fadeToolTip:(id)fp12;
65 - (void)mouseEntered:(id)fp12;
66 - (void)mouseEnteredToolTip:(id)fp12 inWindow:(id)fp16 withEvent:(id)fp20;
67 - (void)mouseExited:(id)fp12;
68 - (void)orderOutToolTip;
69 - (void)orderOutToolTipImmediately:(BOOL)fp12;
70 - (void)recomputeToolTipsForView:(id)fp12 remove:(BOOL)fp16 add:(BOOL)fp20;
71 - (void)removeAllToolTipsForView:(id)fp12;
72 - (void)removeToolTipForView:(id)fp12 tag:(int)fp16;
73 - (void)setInitialToolTipDelay:(double)fp40;
74 - (void)setToolTip:(id)fp12 forView:(id)fp16 cell:(id)fp20;
75 - (int)setToolTipForView:(id)fp12 rect:(struct _NSRect)fp16 displayDelegate:(id)fp32 userData:(void *)fp32;
76 - (int)setToolTipForView:(id)fp12 rect:(struct _NSRect)fp16 owner:(id)fp32 userData:(void *)fp32;
77 - (void)setToolTipWithOwner:(id)fp12 forView:(id)fp16 cell:(id)fp20;
78 - (void)startTimer:(float)fp40 userInfo:(id)fp16;
80 - (id)toolTipForView:(id)fp12 cell:(id)fp16;
81 - (BOOL)viewHasToolTips:(id)fp12;
85 //-----------------------------------------------------------------------------
87 //-----------------------------------------------------------------------------
89 IMPLEMENT_ABSTRACT_CLASS(wxToolTip, wxObject)
91 wxToolTip::wxToolTip(const wxString &tip) :
92 m_text(tip), m_window(0)
96 wxToolTip::~wxToolTip()
100 void wxToolTip::SetTip(const wxString& tip)
105 const wxString& wxToolTip::GetTip() const
110 // the window we're associated with
111 wxWindow *wxToolTip::GetWindow() const
116 // enable or disable the tooltips globally
118 void wxToolTip::Enable(bool flag)
121 wxFAIL_MSG(wxT("Not implemented"));
124 // set the delay after which the tooltip appears
126 void wxToolTip::SetDelay(long milliseconds)
128 [[NSToolTipManager sharedToolTipManager] setInitialToolTipDelay: ((double)milliseconds) / 1000.0];
131 void wxToolTip::SetWindow(wxWindow* window)
133 wxAutoNSAutoreleasePool pool;
137 //set the tooltip - empty string means remove
138 if (m_text.IsEmpty())
139 [m_window->GetNSView() setToolTip:nil];
141 [m_window->GetNSView() setToolTip:wxNSStringWithWxString(m_text)];
144 #endif //wxUSE_TOOLTIPS