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.
32 // MouseTrackingHelpers.h
35 // Some helper classes for mouse tracking, designed to make
36 // it easier to delegate drag operations to a parent class
37 // (especially useful for pane-separator bars & other operations
38 // in which a view is moved or resized as the user drags
42 // e.moon 11may99: fixed m_bTracking bug (not init'd in ctor)
43 // fixed mouseTrackingBegin() documentation
44 // (point is in view, not screen, coords)
46 #ifndef __MouseTrackingHelpers_H__
47 #define __MouseTrackingHelpers_H__
51 #include "cortex_defs.h"
52 __BEGIN_CORTEX_NAMESPACE
54 class MouseTrackingSourceView
;
56 // interface for a mouse-tracking destination
57 class IMouseTrackingDestination
{
59 IMouseTrackingDestination() { }
60 virtual ~IMouseTrackingDestination() { }
61 // a MouseTrackingSourceView has started tracking the mouse
62 // (point is in pSource view coordinates)
63 virtual void mouseTrackingBegin(
64 MouseTrackingSourceView
* pSource
,
68 // mouse-tracking update from child view
69 // (point is in screen coordinates)
70 virtual void mouseTrackingUpdate(
76 // mouse-tracking done
77 virtual void mouseTrackingEnd()=0;
80 // mouse-tracking 'source' view
81 // hands off to a destination view (by default its immediate
84 class MouseTrackingSourceView
: public BView
{
85 typedef BView _inherited
;
87 public: // types & constants
88 // these bits determine which mouse axes will be tracked
89 // (ie. if TRACK_HORIZONTAL isn't set, mouseTrackUpdate()
90 // will always be called with xDelta == 0.0)
91 enum mouse_tracking_flag_t
{
97 MouseTrackingSourceView(
100 uint32 resizeMode
=B_FOLLOW_LEFT
|B_FOLLOW_TOP
,
101 uint32 flags
=B_WILL_DRAW
|B_FRAME_EVENTS
,
102 uint32 trackingFlags
=TRACK_HORIZONTAL
|TRACK_VERTICAL
);
104 ~MouseTrackingSourceView();
106 bool isTracking() const { return m_bTracking
; }
108 // get mouse-down point in screen coordinates; returns
109 // B_OK on success, or B_ERROR if no longer tracking
111 status_t
getTrackingOrigin(BPoint
* poPoint
) const;
113 // fetch/set the destination handler
114 // (if not yet attached to a window, or if no parent
115 // implements IMouseTrackDestination, trackingDestination()
118 // setting the destination handler isn't allowed if a tracking
119 // operation is currently in progress
121 IMouseTrackingDestination
* trackingDestination() const {
124 status_t
setTrackingDestination(IMouseTrackingDestination
* pDest
);
126 public: // BView impl.
128 // handle mouse events
129 virtual void MouseDown(BPoint point
);
130 virtual void MouseMoved(BPoint point
, uint32 transit
,
131 const BMessage
* pMsg
);
132 virtual void MouseUp(BPoint point
);
134 // look for a default destination
135 virtual void AttachedToWindow();
138 // track current frame rectangle
139 virtual void FrameResized(float width, float height);
141 protected: // members
143 IMouseTrackingDestination
* m_pDest
;
144 uint32 m_trackingFlags
;
146 // mouse-tracking state
148 BPoint m_prevPoint
; // in screen coords
149 BPoint m_initPoint
; // in screen coords
151 // BRect m_prevFrame;
154 __END_CORTEX_NAMESPACE
155 #endif /* __MouseTrackingHelpers_H__ */