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.cpp
35 #include "MouseTrackingHelpers.h"
37 #include "debug_tools.h"
39 __USE_CORTEX_NAMESPACE
42 MouseTrackingSourceView::MouseTrackingSourceView(BRect frame
, const char* name
,
43 uint32 resizeMode
, uint32 flags
, uint32 trackingFlags
)
44 : BView(frame
, name
, resizeMode
, flags
),
46 m_trackingFlags(trackingFlags
),
49 //FrameResized(frame.Width(), frame.Height());
53 MouseTrackingSourceView::~MouseTrackingSourceView()
58 // get mouse-down point in screen coordinates; returns
59 // B_OK on success, or B_ERROR if no longer tracking
61 status_t
MouseTrackingSourceView::getTrackingOrigin(
62 BPoint
* poPoint
) const {
65 *poPoint
= m_initPoint
;
69 // fetch/set the destination handler
71 status_t
MouseTrackingSourceView::setTrackingDestination(
72 IMouseTrackingDestination
* pDest
) {
80 // ---------------------------------------------------------------- //
82 // ---------------------------------------------------------------- //
84 // handle mouse events
85 void MouseTrackingSourceView::MouseDown(BPoint point
) {
89 // get mouse state & initial point
91 GetMouse(&point
, &buttons
);
92 m_prevPoint
= ConvertToScreen(point
);
93 m_initPoint
= m_prevPoint
;
95 // start tracking the mouse
96 SetMouseEventMask(B_POINTER_EVENTS
,
97 B_LOCK_WINDOW_FOCUS
|B_NO_POINTER_HISTORY
);
100 // notify destination
102 m_pDest
->mouseTrackingBegin(this, buttons
, point
);
105 void MouseTrackingSourceView::MouseMoved(BPoint point
, uint32 transit
,
106 const BMessage
* pMsg
) {
110 // mouse-tracking update: figure number of pixels moved
111 // (along the axes I care about)
113 GetMouse(&point
, &buttons
, false);
114 ConvertToScreen(&point
);
116 if(point
== m_prevPoint
) // no motion?
119 float xDelta
= m_trackingFlags
& TRACK_HORIZONTAL
?
120 point
.x
- m_prevPoint
.x
: 0.0;
121 float yDelta
= m_trackingFlags
& TRACK_VERTICAL
?
122 point
.y
- m_prevPoint
.y
: 0.0;
124 // pass info to destination view
126 m_pDest
->mouseTrackingUpdate(buttons
, xDelta
, yDelta
, point
);
128 // store point for future delta calculations
133 void MouseTrackingSourceView::MouseUp(BPoint point
) {
135 // PRINT(( "MouseTrackingSourceView::MouseUp()\n"));
137 // +++++ handle final update
142 m_pDest
->mouseTrackingEnd();
146 // look for a default destination
147 void MouseTrackingSourceView::AttachedToWindow() {
148 if(m_pDest
) // already have a destination
151 for(BView
* pParent
= Parent(); pParent
; pParent
= pParent
->Parent()) {
152 IMouseTrackingDestination
* pFound
=
153 dynamic_cast<IMouseTrackingDestination
*>(pParent
);
154 if(pFound
) // found a valid destination
160 // track current frame rectangle
161 void MouseTrackingSourceView::FrameResized(float width, float height) {
162 _inherited::FrameResized(width, height);
163 m_prevFrame = Frame();
165 // +++++ adjust if currently tracking?
169 // END -- MouseTrackingHelpers.cpp --