1/*
2 * Copyright (c) 1999-2000, Eric Moon.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions, and the following disclaimer.
11 *
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.
15 *
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.
18 *
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.
29 */
30
31
32// ValControlSegment.h
33// +++++ cortex integration 23aug99:
34//       - allow adjustment of dragScaleFactor
35//
36// e.moon 17jan99
37//
38// ABSTRACT CLASS: ValControlSegment
39// Represents a single manipulable (manipulatable?) segment of
40// a ValControl interface element.
41//
42// CLASS: ValControlDigitSegment
43// Extends ValControlSegment to provide a single or multi-digit
44// numeric segment.
45//
46// CLASS: ValControlStringSegment
47// Extends ValControlSegment to provide a string-selection
48// segment.  [+++++ driven by BMenu?]
49#ifndef VAL_CONTROL_SEGMENT_H
50#define VAL_CONTROL_SEGMENT_H
51
52
53#include <View.h>
54
55// possibly 'fed' by a BMenu?
56class BMenu;
57
58#include "cortex_defs.h"
59__BEGIN_CORTEX_NAMESPACE
60
61// forward declarations
62class ValControl;
63class ValCtrlLayoutEntry;
64
65// ---------------------------------------------------------------- //
66// +++++ base 'manipulatable segment' class
67
68// Might have some functionality:
69// - underline (overridable)
70// - chaining: segments need to inform segments to their left
71//             when they 'roll around', using the M_INCREMENT and
72//             M_DECREMENT messages.
73
74class ValControlSegment : public BView {
75	public:
76		typedef BView _Inherited;
77
78		friend class ValControl;
79
80	public:
81
82		enum underline_style {
83			NO_UNDERLINE,
84			DOTTED_UNDERLINE,
85			SOLID_UNDERLINE
86		};
87
88		// mouse-tracking
89		enum track_flags {
90			TRACK_HORIZONTAL = 1,
91			TRACK_VERTICAL = 2
92		};
93
94	protected:											// pure virtuals
95		// fetch layout entry (called by ValControl)
96		virtual ValCtrlLayoutEntry makeLayoutEntry() = 0;
97
98	public:													// hooks
99
100		// * mouse-tracking callbacks
101
102		// do any font-related layout work
103		virtual void fontChanged(const BFont* font) {}
104
105		// return 'unused pixels' (if value updates are triggered
106		// at less than one per pixel)
107		virtual float handleDragUpdate(float distance) { return 0; }
108
109		virtual void mouseReleased() {}
110
111		// underline size (tweak if you must)
112		// +++++ 18sep99: 'ewww.'
113		virtual void sizeUnderline(float* outLeft, float* outRight);
114
115	public:
116		virtual ~ValControlSegment();
117
118	protected: // ctor/internal operations
119		ValControlSegment(underline_style underlineStyle);
120
121		// get parent
122		ValControl* parent() const;
123
124		// init mouse tracking: must be called from MouseDown()
125		void trackMouse(BPoint point, track_flags flags);
126
127		void setTracking(bool tracking);
128		bool isTracking() const;
129
130		// fetch pixel:unit ratio for dragging
131		double dragScaleFactor() const;
132
133	public:// BView impl.
134		// calls sizeUnderline()
135		virtual void AttachedToWindow();
136
137		virtual void Draw(BRect updateRect);
138
139		// calls sizeUnderline() after bounds changed
140		virtual void FrameResized(float width, float height);
141
142		// calls trackMouse(TRACK_VERTICAL) if left button down
143		virtual void MouseDown(BPoint point);
144
145		// feeds trackUpdate()
146		virtual void MouseMoved(BPoint point, uint32 transit,
147			const BMessage* dragMessage);
148
149		// triggers mouseReleased()
150		virtual void MouseUp(BPoint point);
151
152	public:
153		virtual void MessageReceived(BMessage* message); //nyi
154
155	public:
156		ValControlSegment(BMessage* archive);
157		virtual status_t Archive(BMessage* archive, bool deep = true) const;
158
159	private:
160		void _Init();
161
162		// left segment (ValControl)
163		// ValControlSegment*		m_pLeft;
164
165		// mouse-tracking machinery
166		track_flags				fTrackFlags;
167		bool					fTracking;
168		BPoint					fPrevPoint;
169		double					fDragScaleFactor;
170
171		bigtime_t				fLastClickTime;
172
173		// look'n'feel parameters
174		underline_style			fUnderlineStyle;
175		float					fXUnderlineLeft;
176		float					fXUnderlineRight;
177
178		// constants
179		static const double		fDefDragScaleFactor;
180};
181
182__END_CORTEX_NAMESPACE
183#endif	// VAL_CONTROL_SEGMENT_H
184