btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / cortex / support / MouseTrackingHelpers.cpp
blob1b71eb513ee8c2e2122caccb2557d8c806b44cc8
1 /*
2 * Copyright (c) 1999-2000, Eric Moon.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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
33 // e.moon 8mar99
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),
45 m_pDest(0),
46 m_trackingFlags(trackingFlags),
47 m_bTracking(false)
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
60 // the mouse.
61 status_t MouseTrackingSourceView::getTrackingOrigin(
62 BPoint* poPoint) const {
63 if(!m_bTracking)
64 return B_ERROR;
65 *poPoint = m_initPoint;
66 return B_OK;
69 // fetch/set the destination handler
71 status_t MouseTrackingSourceView::setTrackingDestination(
72 IMouseTrackingDestination* pDest) {
73 if(m_bTracking)
74 return B_ERROR;
76 m_pDest = pDest;
77 return B_OK;
80 // ---------------------------------------------------------------- //
81 // BView impl.
82 // ---------------------------------------------------------------- //
84 // handle mouse events
85 void MouseTrackingSourceView::MouseDown(BPoint point) {
86 if(!m_trackingFlags)
87 return;
89 // get mouse state & initial point
90 uint32 buttons;
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);
98 m_bTracking = true;
100 // notify destination
101 if(m_pDest)
102 m_pDest->mouseTrackingBegin(this, buttons, point);
105 void MouseTrackingSourceView::MouseMoved(BPoint point, uint32 transit,
106 const BMessage* pMsg) {
108 if(m_bTracking) {
110 // mouse-tracking update: figure number of pixels moved
111 // (along the axes I care about)
112 uint32 buttons;
113 GetMouse(&point, &buttons, false);
114 ConvertToScreen(&point);
116 if(point == m_prevPoint) // no motion?
117 return;
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
125 if(m_pDest)
126 m_pDest->mouseTrackingUpdate(buttons, xDelta, yDelta, point);
128 // store point for future delta calculations
129 m_prevPoint = point;
133 void MouseTrackingSourceView::MouseUp(BPoint point) {
134 if(m_bTracking) {
135 // PRINT(( "MouseTrackingSourceView::MouseUp()\n"));
137 // +++++ handle final update
139 // clean up
140 m_bTracking = false;
141 if(m_pDest)
142 m_pDest->mouseTrackingEnd();
146 // look for a default destination
147 void MouseTrackingSourceView::AttachedToWindow() {
148 if(m_pDest) // already have a destination
149 return;
151 for(BView* pParent = Parent(); pParent; pParent = pParent->Parent()) {
152 IMouseTrackingDestination* pFound =
153 dynamic_cast<IMouseTrackingDestination*>(pParent);
154 if(pFound) // found a valid destination
155 m_pDest = pFound;
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 --