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