xref: /haiku/src/apps/cortex/ValControl/ValControlSegment.h (revision 0e50eab75e25d0d82090e22dbff766dfaa6f5e86)
1 // ValControlSegment.h
2 // +++++ cortex integration 23aug99:
3 //       - allow adjustment of dragScaleFactor
4 //
5 // e.moon 17jan99
6 //
7 // ABSTRACT CLASS: ValControlSegment
8 // Represents a single manipulable (manipulatable?) segment of
9 // a ValControl interface element.
10 //
11 // CLASS: ValControlDigitSegment
12 // Extends ValControlSegment to provide a single or multi-digit
13 // numeric segment.
14 //
15 // CLASS: ValControlStringSegment
16 // Extends ValControlSegment to provide a string-selection
17 // segment.  [+++++ driven by BMenu?]
18 
19 #ifndef __ValControlSegment_H__
20 #define __ValControlSegment_H__
21 
22 #include <View.h>
23 
24 // possibly 'fed' by a BMenu?
25 class BMenu;
26 
27 #include "cortex_defs.h"
28 __BEGIN_CORTEX_NAMESPACE
29 
30 // forward declarations
31 class ValControl;
32 class ValCtrlLayoutEntry;
33 
34 // ---------------------------------------------------------------- //
35 // +++++ base 'manipulatable segment' class
36 
37 // Might have some functionality:
38 // - underline (overridable)
39 // - chaining: segments need to inform segments to their left
40 //             when they 'roll around', using the M_INCREMENT and
41 //             M_DECREMENT messages.
42 
43 class ValControlSegment : public BView {
44 	typedef BView _inherited;
45 
46 	friend class ValControl;
47 
48 public:													// constants
49 
50 	enum underline_style {
51 		NO_UNDERLINE,
52 		DOTTED_UNDERLINE,
53 		SOLID_UNDERLINE
54 	};
55 
56 	// mouse-tracking
57 	enum track_flags {
58 		TRACK_HORIZONTAL		=1,
59 		TRACK_VERTICAL			=2
60 	};
61 
62 protected:											// pure virtuals
63 	// fetch layout entry (called by ValControl)
64 	virtual ValCtrlLayoutEntry makeLayoutEntry()=0;
65 
66 public:													// hooks
67 
68 	// * mouse-tracking callbacks
69 
70 	// do any font-related layout work
71 	virtual void fontChanged(
72 		const BFont*								font) {}
73 
74 	// return 'unused pixels' (if value updates are triggered
75 	// at less than one per pixel)
76 	virtual float handleDragUpdate(
77 		float												distance) { return 0; }
78 
79 	virtual void mouseReleased() {}
80 
81 	// underline size (tweak if you must)
82 	// +++++ 18sep99: 'ewww.'
83 	virtual void sizeUnderline(
84 		float*											outLeft,
85 		float*											outRight);
86 
87 public:													// ctor/dtor/accessors
88 	virtual ~ValControlSegment();
89 
90 protected:											// ctor/internal operations
91 	ValControlSegment(
92 		underline_style							underlineStyle);
93 
94 	// get parent
95 	ValControl* parent() const;
96 
97 	// init mouse tracking: must be called from MouseDown()
98 	void trackMouse(
99 		BPoint											point,
100 		track_flags									flags);
101 
102 	void setTracking(
103 		bool												tracking);
104 	bool isTracking() const;
105 
106 	// fetch pixel:unit ratio for dragging
107 	double dragScaleFactor() const;
108 
109 public:													// BView impl.
110 	// calls sizeUnderline()
111 	virtual void AttachedToWindow();
112 
113 	virtual void Draw(
114 		BRect												updateRect);
115 
116 	// calls sizeUnderline() after bounds changed
117 	virtual void FrameResized(
118 		float												width,
119 		float												height);
120 
121 	// calls trackMouse(TRACK_VERTICAL) if left button down
122 	virtual void MouseDown(
123 		BPoint											point);
124 
125 	// feeds trackUpdate()
126 	virtual void MouseMoved(
127 		BPoint											point,
128 		uint32											transit,
129 		const BMessage*							dragMessage);
130 
131 	// triggers mouseReleased()
132 	virtual void MouseUp(
133 		BPoint											point);
134 
135 public:						// BHandler impl.
136 	virtual void MessageReceived(
137 		BMessage*										message); //nyi
138 
139 public:						// archiving/instantiation
140 	ValControlSegment(
141 		BMessage*										archive);
142 	virtual status_t Archive(
143 		BMessage*										archive,
144 		bool												deep=true) const;
145 
146 private:						// guts
147 	// ctor helper
148 	void init();
149 
150 //	// left segment (ValControl)
151 //	ValControlSegment*		m_pLeft;
152 //
153 	// mouse-tracking machinery
154 	track_flags										m_trackFlags;
155 	bool													m_tracking;
156 	BPoint												m_prevPoint;
157 	double												m_dragScaleFactor;
158 
159 	bigtime_t											m_lastClickTime;
160 
161 	// look'n'feel parameters
162 	underline_style								m_underlineStyle;
163 	float													m_xUnderlineLeft, m_xUnderlineRight;
164 
165 	// constants
166 	static const double						s_defDragScaleFactor;
167 };
168 
169 __END_CORTEX_NAMESPACE
170 #endif /* __ValControlSegment_H__ */
171