1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/tooltip.mm
3 // Purpose: Cocoa tooltips
7 // Copyright: (c) Ryan Norton
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
13 // ===========================================================================
15 // ===========================================================================
17 // ---------------------------------------------------------------------------
19 // ---------------------------------------------------------------------------
24 #include "wx/window.h"
27 #include "wx/tooltip.h"
29 #include "wx/cocoa/autorelease.h"
30 #include "wx/cocoa/string.h"
32 #import <AppKit/NSView.h>
35 // Private object in AppKit - exists in 10.2 at least -
36 // most likely exists earlier too
38 @interface NSToolTipManager : NSObject
41 NSWindow *toolTipWindow;
42 NSMutableArray *toolTips;
44 NSDate *timeToolTipRemovedFromScreen;
45 struct __CFRunLoopTimer *toolTipDisplayTimer;
46 NSToolTip *currentDisplayedToolTip;
47 NSToolTip *currentFadingToolTip;
48 float currentFadeValue;
50 NSWindow *lastToolTipWindow;
54 + (id)sharedToolTipManager;
55 - (int)_addTrackingRect:(struct _NSRect)fp12 andStartToolTipIfNecessary:(BOOL)fp28 view:(id)fp32 owner:(id)fp32 toolTip:(id)fp36;
56 - (void)_checkToolTipDelay;
57 - (void)_removeToolTip:(id)fp12 stopTimerIfNecessary:(BOOL)fp16;
58 - (void)_removeTrackingRectForToolTip:(id)fp12 stopTimerIfNecessary:(BOOL)fp16;
59 - (int)_setToolTip:(id)fp12 forView:(id)fp16 cell:(id)fp20 rect:(struct _NSRect)fp20 owner:(id)fp36 ownerIsDisplayDelegate:(BOOL)fp43 userData:(void *)fp44;
60 - (void)_stopTimerIfRunningForToolTip:(id)fp12;
62 - (void)addTrackingRectForToolTip:(id)fp12;
64 - (void)displayToolTip:(id)fp12;
65 - (void)fadeToolTip:(id)fp12;
67 - (void)mouseEntered:(id)fp12;
68 - (void)mouseEnteredToolTip:(id)fp12 inWindow:(id)fp16 withEvent:(id)fp20;
69 - (void)mouseExited:(id)fp12;
70 - (void)orderOutToolTip;
71 - (void)orderOutToolTipImmediately:(BOOL)fp12;
72 - (void)recomputeToolTipsForView:(id)fp12 remove:(BOOL)fp16 add:(BOOL)fp20;
73 - (void)removeAllToolTipsForView:(id)fp12;
74 - (void)removeToolTipForView:(id)fp12 tag:(int)fp16;
75 - (void)setInitialToolTipDelay:(double)fp40;
76 - (void)setToolTip:(id)fp12 forView:(id)fp16 cell:(id)fp20;
77 - (int)setToolTipForView:(id)fp12 rect:(struct _NSRect)fp16 displayDelegate:(id)fp32 userData:(void *)fp32;
78 - (int)setToolTipForView:(id)fp12 rect:(struct _NSRect)fp16 owner:(id)fp32 userData:(void *)fp32;
79 - (void)setToolTipWithOwner:(id)fp12 forView:(id)fp16 cell:(id)fp20;
80 - (void)startTimer:(float)fp40 userInfo:(id)fp16;
82 - (id)toolTipForView:(id)fp12 cell:(id)fp16;
83 - (BOOL)viewHasToolTips:(id)fp12;
87 //-----------------------------------------------------------------------------
89 //-----------------------------------------------------------------------------
91 IMPLEMENT_ABSTRACT_CLASS(wxToolTip, wxObject)
93 wxToolTip::wxToolTip(const wxString &tip) :
94 m_text(tip), m_window(0)
98 wxToolTip::~wxToolTip()
102 void wxToolTip::SetTip(const wxString& tip)
107 const wxString& wxToolTip::GetTip() const
112 // the window we're associated with
113 wxWindow *wxToolTip::GetWindow() const
118 // enable or disable the tooltips globally
120 void wxToolTip::Enable(bool flag)
123 wxFAIL_MSG(wxT("Not implemented"));
126 // set the delay after which the tooltip appears
128 void wxToolTip::SetDelay(long milliseconds)
130 [[NSToolTipManager sharedToolTipManager] setInitialToolTipDelay: ((double)milliseconds) / 1000.0];
133 void wxToolTip::SetWindow(wxWindow* window)
135 wxAutoNSAutoreleasePool pool;
139 //set the tooltip - empty string means remove
141 [m_window->GetNSView() setToolTip:nil];
143 [m_window->GetNSView() setToolTip:wxNSStringWithWxString(m_text)];
146 #endif //wxUSE_TOOLTIPS