]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/tooltip.mm
declare GetGDKWindow() in wxDC to fix compilation of wxRendererNative
[wxWidgets.git] / src / cocoa / tooltip.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/tooltip.mm
3 // Purpose: Cocoa tooltips
4 // Author: Ryan Norton
5 // Modified by:
6 // Created: 2004-10-03
7 // RCS-ID: $Id$
8 // Copyright: (c) Ryan Norton
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 // ===========================================================================
15 // declarations
16 // ===========================================================================
17
18 // ---------------------------------------------------------------------------
19 // headers
20 // ---------------------------------------------------------------------------
21
22 #if wxUSE_TOOLTIPS
23
24 #ifndef WX_PRECOMP
25 #include "wx/window.h"
26 #endif
27
28 #include "wx/tooltip.h"
29
30 #include "wx/cocoa/autorelease.h"
31 #include "wx/cocoa/string.h"
32
33 #import <AppKit/NSView.h>
34
35 //
36 // Private object in AppKit - exists in 10.2 at least -
37 // most likely exists earlier too
38 //
39 @interface NSToolTipManager : NSObject
40 {
41 /*
42 NSWindow *toolTipWindow;
43 NSMutableArray *toolTips;
44 double toolTipDelay;
45 NSDate *timeToolTipRemovedFromScreen;
46 struct __CFRunLoopTimer *toolTipDisplayTimer;
47 NSToolTip *currentDisplayedToolTip;
48 NSToolTip *currentFadingToolTip;
49 float currentFadeValue;
50 NSTimer *fadeTimer;
51 NSWindow *lastToolTipWindow;
52 */
53 }
54
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;
62 - (void)abortToolTip;
63 - (void)addTrackingRectForToolTip:(id)fp12;
64 - (void)dealloc;
65 - (void)displayToolTip:(id)fp12;
66 - (void)fadeToolTip:(id)fp12;
67 - (id)init;
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;
82 - (void)stopTimer;
83 - (id)toolTipForView:(id)fp12 cell:(id)fp16;
84 - (BOOL)viewHasToolTips:(id)fp12;
85
86 @end
87
88 //-----------------------------------------------------------------------------
89 // wxToolTip
90 //-----------------------------------------------------------------------------
91
92 IMPLEMENT_ABSTRACT_CLASS(wxToolTip, wxObject)
93
94 wxToolTip::wxToolTip(const wxString &tip) :
95 m_text(tip), m_window(0)
96 {
97 }
98
99 wxToolTip::~wxToolTip()
100 {
101 }
102
103 void wxToolTip::SetTip(const wxString& tip)
104 {
105 m_text = tip;
106 }
107
108 const wxString& wxToolTip::GetTip() const
109 {
110 return m_text;
111 }
112
113 // the window we're associated with
114 wxWindow *wxToolTip::GetWindow() const
115 {
116 return m_window;
117 }
118
119 // enable or disable the tooltips globally
120 //static
121 void wxToolTip::Enable(bool flag)
122 {
123 //TODO
124 wxFAIL_MSG(wxT("Not implemented"));
125 }
126
127 // set the delay after which the tooltip appears
128 //static
129 void wxToolTip::SetDelay(long milliseconds)
130 {
131 [[NSToolTipManager sharedToolTipManager] setInitialToolTipDelay: ((double)milliseconds) / 1000.0];
132 }
133
134 void wxToolTip::SetWindow(wxWindow* window)
135 {
136 wxAutoNSAutoreleasePool pool;
137
138 m_window = window;
139
140 //set the tooltip - empty string means remove
141 if (m_text.empty())
142 [m_window->GetNSView() setToolTip:nil];
143 else
144 [m_window->GetNSView() setToolTip:wxNSStringWithWxString(m_text)];
145 }
146
147 #endif //wxUSE_TOOLTIPS