2 * Copyright (c) 1999-2000, Eric Moon.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions, and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 // 13may99 e.moon moved TipManager internals here
38 #ifndef __TIPMANAGERIMPL_H__
39 #define __TIPMANAGERIMPL_H__
46 #include <SupportDefs.h>
50 #include <GraphicsDefs.h>
57 #include "cortex_defs.h"
58 __BEGIN_CORTEX_NAMESPACE
60 // -------------------------------------------------------- //
62 // -------------------------------------------------------- //
65 public: // *** interface
66 // if rect is invalid, the entry represents the view's entire
71 TipManager::offset_mode_t _offsetMode
,
77 offsetMode(_offsetMode
),
81 // useful for comparisons
86 // give the compiler some slack:
89 void dump(int indent
) {
91 s
.SetTo('\t', indent
);
98 // +++++ copy ctors and other treats for lame compilers go here +++++
104 TipManager::offset_mode_t offsetMode
;
110 // ordering criteria: by top-left corner of the rect,
111 // invalid rects last (unsorted)
112 // [13may99: inverted -- which I suppose causes elements to
113 // be stored in increasing 'order', and therefore
116 // [e.moon 13oct99] tip_entry instances now stored and compared
119 class tip_entry_ptr_less_fn
{ public:
122 const tip_entry
* b
) const {
123 if(a
->rect
.IsValid())
124 if(b
->rect
.IsValid()) {
125 if(a
->rect
.left
== b
->rect
.left
)
126 return a
->rect
.top
> b
->rect
.top
;
127 return a
->rect
.left
> b
->rect
.left
;
136 typedef std::set
<tip_entry
*, tip_entry_ptr_less_fn
> tip_entry_set
;
138 // -------------------------------------------------------- //
140 // -------------------------------------------------------- //
143 public: // *** interface
145 virtual ~_ViewEntry();
149 _ViewEntry
* parent
) :
153 // +++++ copy ctors and other treats for lame compilers go here +++++
155 // add the given entry for the designated view
156 // (which may be the target view or a child.)
157 // returns B_OK on success, B_ERROR if:
158 // - the given view is NOT a child of the target view
159 // - or if tips can't be added to this view due to it,
160 // or one of its parents, having a full-frame tip.
164 const tip_entry
& entry
);
166 // remove tip matching the given rect's upper-left corner or
167 // all tips if rect is invalid.
168 // returns B_ERROR on failure -- if there are no entries for
169 // the given view -- or B_OK otherwise.
175 // match the given point (in target's view coordinates)
176 // against tips in this view and child views.
178 std::pair
<BView
*, const tip_entry
*> match(
182 // retrieve current frame rect (in parent view's coordinates)
185 BView
* target() const { return m_target
; }
186 _ViewEntry
* parent() const { return m_parent
; }
188 size_t countTips() const;
190 void dump(int indent
);
193 // returns pointer to sole entry in the set if it's
194 // a full-frame tip, or 0 if there's no full-frame tip
195 const tip_entry
* fullFrameTip() const;
199 _ViewEntry
* m_parent
;
201 // [e.moon 13oct99] child view list now stores pointers
202 std::list
<_ViewEntry
*> m_childViews
;
203 tip_entry_set m_tips
;
206 // -------------------------------------------------------- //
208 // -------------------------------------------------------- //
211 public: // *** interface
213 virtual ~_WindowEntry();
219 // add the given entry for the designated view (which must
220 // be attached to the target window)
221 // returns B_OK on success, B_ERROR if:
222 // - the given view is NOT attached to the target window, or
223 // - tips can't be added to this view due to it, or one of its
224 // parents, having a full-frame tip.
228 const tip_entry
& entry
);
230 // remove tip matching the given rect's upper-left corner or
231 // all tips if rect is invalid.
232 // returns B_ERROR on failure -- if there are no entries for
233 // the given view -- or B_OK otherwise.
239 // match the given point (in screen coordinates)
240 // against tips in this view and child views.
242 std::pair
<BView
*, const tip_entry
*> match(
245 BWindow
* target() const { return m_target
; }
247 size_t countViews() const { return m_views
.size(); }
249 void dump(int indent
);
255 // view subtrees with tip entries
256 std::list
<_ViewEntry
*> m_views
;
259 // -------------------------------------------------------- //
261 // -------------------------------------------------------- //
263 class _TipManagerView
:
265 typedef BView _inherited
;
267 public: // *** messages
273 public: // *** ctor/dtor
274 virtual ~_TipManagerView();
276 TipWindow
* tipWindow
,
278 bigtime_t updatePeriod
,
279 bigtime_t idlePeriod
);
281 public: // *** operations
283 // Prepare a 'one-off' tip: this interrupts normal mouse-watching
284 // behavior while the mouse remains in the given screen rectangle.
285 // If it idles long enough, the tip window is displayed.
288 const BRect
& screenRect
,
290 TipManager::offset_mode_t offsetMode
,
294 // Hide tip corresponding to the given screenRect, if any.
295 // [e.moon 29nov99] Cancel 'one-off' tip for the given rect if any.
298 const BRect
& screenRect
);
300 // Add/replace a tip in the window/view-entry tree
306 TipManager::offset_mode_t offsetMode
,
310 // Remove a given tip from a particular view in the entry tree
311 // (if the rect is invalid, removes all tips for that view.)
317 // Remove all tips for the given window from the entry tree.
324 void AttachedToWindow();
336 const BMessage
* dragMessage
);
338 public: // *** BHandler
340 void MessageReceived(
343 private: // implementation
345 // the tip window to be displayed
346 TipWindow
* m_tipWindow
;
349 TipManager
* m_manager
;
351 // set of window entries containing one or more bound tip rectangles
352 std::list
<_WindowEntry
*> m_windows
;
354 // update message source
355 BMessageRunner
* m_messageRunner
;
358 enum tip_window_state_t
{
363 tip_window_state_t m_tipWindowState
;
365 // how often to check for mouse idleness
366 bigtime_t m_updatePeriod
;
368 // how long it takes a tip to fire
369 bigtime_t m_idlePeriod
;
371 // mouse-watching state
372 BPoint m_lastMousePoint
;
373 bigtime_t m_lastEventTime
;
376 // once a tip has been shown, it remains visible while the
377 // mouse stays within this screen rect
378 BRect m_visibleTipRect
;
381 tip_entry
* m_armedTip
;
385 inline void _timePassed();
387 inline void _showTip(
388 const tip_entry
* entry
);
390 inline void _hideTip();
393 __END_CORTEX_NAMESPACE
394 #endif /* __TIPMANAGERIMPL_H__ */