implement tooltip delay
[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 // ===========================================================================
13 // declarations
14 // ===========================================================================
15
16 // ---------------------------------------------------------------------------
17 // headers
18 // ---------------------------------------------------------------------------
19
20 #include "wx/defs.h"
21
22 #if wxUSE_TOOLTIPS
23
24 #include "wx/window.h"
25 #include "wx/tooltip.h"
26
27 #include "wx/cocoa/autorelease.h"
28 #include "wx/cocoa/string.h"
29
30 #import <AppKit/NSView.h>
31
32 @interface NSToolTipManager : NSObject
33 {
34 /*
35     NSWindow *toolTipWindow;
36     NSMutableArray *toolTips;
37     double toolTipDelay;
38     NSDate *timeToolTipRemovedFromScreen;
39     struct __CFRunLoopTimer *toolTipDisplayTimer;
40     NSToolTip *currentDisplayedToolTip;
41     NSToolTip *currentFadingToolTip;
42     float currentFadeValue;
43     NSTimer *fadeTimer;
44     NSWindow *lastToolTipWindow;
45 */
46 }
47
48 + (id)sharedToolTipManager;
49 - (int)_addTrackingRect:(struct _NSRect)fp12 andStartToolTipIfNecessary:(BOOL)fp28 view:(id)fp32 owner:(id)fp32 toolTip:(id)fp36;
50 - (void)_checkToolTipDelay;
51 - (void)_removeToolTip:(id)fp12 stopTimerIfNecessary:(BOOL)fp16;
52 - (void)_removeTrackingRectForToolTip:(id)fp12 stopTimerIfNecessary:(BOOL)fp16;
53 - (int)_setToolTip:(id)fp12 forView:(id)fp16 cell:(id)fp20 rect:(struct _NSRect)fp20 owner:(id)fp36 ownerIsDisplayDelegate:(BOOL)fp43 userData:(void *)fp44;
54 - (void)_stopTimerIfRunningForToolTip:(id)fp12;
55 - (void)abortToolTip;
56 - (void)addTrackingRectForToolTip:(id)fp12;
57 - (void)dealloc;
58 - (void)displayToolTip:(id)fp12;
59 - (void)fadeToolTip:(id)fp12;
60 - (id)init;
61 - (void)mouseEntered:(id)fp12;
62 - (void)mouseEnteredToolTip:(id)fp12 inWindow:(id)fp16 withEvent:(id)fp20;
63 - (void)mouseExited:(id)fp12;
64 - (void)orderOutToolTip;
65 - (void)orderOutToolTipImmediately:(BOOL)fp12;
66 - (void)recomputeToolTipsForView:(id)fp12 remove:(BOOL)fp16 add:(BOOL)fp20;
67 - (void)removeAllToolTipsForView:(id)fp12;
68 - (void)removeToolTipForView:(id)fp12 tag:(int)fp16;
69 - (void)setInitialToolTipDelay:(double)fp40;
70 - (void)setToolTip:(id)fp12 forView:(id)fp16 cell:(id)fp20;
71 - (int)setToolTipForView:(id)fp12 rect:(struct _NSRect)fp16 displayDelegate:(id)fp32 userData:(void *)fp32;
72 - (int)setToolTipForView:(id)fp12 rect:(struct _NSRect)fp16 owner:(id)fp32 userData:(void *)fp32;
73 - (void)setToolTipWithOwner:(id)fp12 forView:(id)fp16 cell:(id)fp20;
74 - (void)startTimer:(float)fp40 userInfo:(id)fp16;
75 - (void)stopTimer;
76 - (id)toolTipForView:(id)fp12 cell:(id)fp16;
77 - (BOOL)viewHasToolTips:(id)fp12;
78
79 @end
80
81 //-----------------------------------------------------------------------------
82 // wxToolTip
83 //-----------------------------------------------------------------------------
84
85 IMPLEMENT_ABSTRACT_CLASS(wxToolTip, wxObject)
86
87 wxToolTip::wxToolTip(const wxString &tip) : 
88     m_text(tip), m_window(0) 
89 {
90 }
91
92 wxToolTip::~wxToolTip() 
93 {
94 }
95
96 void wxToolTip::SetTip(const wxString& tip)
97
98     m_text = tip; 
99 }
100
101 const wxString& wxToolTip::GetTip() const 
102
103     return m_text; 
104 }
105
106 // the window we're associated with
107 wxWindow *wxToolTip::GetWindow() const 
108
109     return m_window; 
110 }
111
112 // enable or disable the tooltips globally
113 //static 
114     void wxToolTip::Enable(bool flag) 
115 {
116     //TODO
117     wxFAIL_MSG(wxT("Not implemented"));
118 }
119
120 // set the delay after which the tooltip appears
121 //static
122     void wxToolTip::SetDelay(long milliseconds) 
123 {
124     [[NSToolTipManager sharedToolTipManager] setInitialToolTipDelay: ((double)milliseconds) / 1000.0];
125 }
126
127 void wxToolTip::SetWindow(wxWindow* window) 
128 {
129     wxAutoNSAutoreleasePool pool;
130
131     m_window = window;
132     
133     //set the tooltip - empty string means remove
134     if (m_text.IsEmpty())
135         [m_window->GetNSView() setToolTip:nil];        
136     else
137         [m_window->GetNSView() setToolTip:wxNSStringWithWxString(m_text)];    
138 }
139
140 #endif //wxUSE_TOOLTIPS