xref: /haiku/src/apps/cortex/ValControl/NumericValControl.h (revision 08a996b87ab7c358eb0b289cd406c6e61ed95ae3)
1a0795c6fSMarcus Overhagen // NumericValControl.h
2a0795c6fSMarcus Overhagen // * PURPOSE
3a0795c6fSMarcus Overhagen //   Extends ValControl to provide the basis for a variety
4a0795c6fSMarcus Overhagen //   of numeric UI controls.
5a0795c6fSMarcus Overhagen // * HISTORY
6a0795c6fSMarcus Overhagen //   e.moon			18sep99		General cleanup; values are now stored
7a0795c6fSMarcus Overhagen //												in fixed-point form only.
8a0795c6fSMarcus Overhagen //   e.moon			17jan99		Begun
9a0795c6fSMarcus Overhagen // +++++ 31jan99: negatives are still handled wrong...
10a0795c6fSMarcus Overhagen //
11a0795c6fSMarcus Overhagen // CLASS: NumericValControl
12*08a996b8SAxel Dörfler #ifndef NUMERIC_VAL_CONTROL_H
13*08a996b8SAxel Dörfler #define NUMERIC_VAL_CONTROL_H
14a0795c6fSMarcus Overhagen 
15a0795c6fSMarcus Overhagen #include "cortex_defs.h"
16*08a996b8SAxel Dörfler #include "ValControl.h"
17*08a996b8SAxel Dörfler 
18*08a996b8SAxel Dörfler #include <MediaDefs.h>
19*08a996b8SAxel Dörfler 
20*08a996b8SAxel Dörfler 
21*08a996b8SAxel Dörfler class BContinuousParameter;
22*08a996b8SAxel Dörfler 
23*08a996b8SAxel Dörfler 
24a0795c6fSMarcus Overhagen __BEGIN_CORTEX_NAMESPACE
25a0795c6fSMarcus Overhagen 
26a0795c6fSMarcus Overhagen class ValControlDigitSegment;
27a0795c6fSMarcus Overhagen 
28*08a996b8SAxel Dörfler 
29*08a996b8SAxel Dörfler class NumericValControl : public ValControl {
30*08a996b8SAxel Dörfler 	public:
31a0795c6fSMarcus Overhagen 		typedef ValControl _inherited;
32a0795c6fSMarcus Overhagen 
33*08a996b8SAxel Dörfler 	public:
34a0795c6fSMarcus Overhagen 
35a0795c6fSMarcus Overhagen 		// +++++ need control over number of segments +++++
36a0795c6fSMarcus Overhagen 
37a0795c6fSMarcus Overhagen 		// parameter-linked ctor
38*08a996b8SAxel Dörfler 		NumericValControl(BRect	frame, const char* name, BContinuousParameter* param,
39*08a996b8SAxel Dörfler 			uint16 wholeDigits, uint16 fractionalDigits = 0, align_mode alignMode = ALIGN_FLUSH_RIGHT,
40a0795c6fSMarcus Overhagen 			align_flags alignFlags = ALIGN_NONE);
41a0795c6fSMarcus Overhagen 
42a0795c6fSMarcus Overhagen 		// 'plain' ctor
43*08a996b8SAxel Dörfler 		NumericValControl(BRect frame, const char* name, BMessage* message, uint16 wholeDigits,
44*08a996b8SAxel Dörfler 			uint16 fractionalDigits = 0, bool negativeVisible = true,
45*08a996b8SAxel Dörfler 			align_mode alignMode = ALIGN_FLUSH_RIGHT, align_flags alignFlags = ALIGN_NONE);
46a0795c6fSMarcus Overhagen 
47a0795c6fSMarcus Overhagen 		~NumericValControl();
48a0795c6fSMarcus Overhagen 
49a0795c6fSMarcus Overhagen 		BContinuousParameter* param() const;
50*08a996b8SAxel Dörfler 			// bound parameter, or 0 if none
51a0795c6fSMarcus Overhagen 
52*08a996b8SAxel Dörfler 		void getConstraints(double* outMinValue, double* outMaxValue);
53a0795c6fSMarcus Overhagen 			// value constraints (by default, the min/max allowed by the ctor
54a0795c6fSMarcus Overhagen 			// settings: wholeDigits, fractionalDigits, and negativeVisible)
55a0795c6fSMarcus Overhagen 
56*08a996b8SAxel Dörfler 		status_t setConstraints(double minValue, double maxValue);
57*08a996b8SAxel Dörfler 			// the current value is not yet re-constrained by this call
58a0795c6fSMarcus Overhagen 
59*08a996b8SAxel Dörfler 		double value() const;
60a0795c6fSMarcus Overhagen 			// fetches the current value (calculated on the spot from each
61a0795c6fSMarcus Overhagen 			// segment.)
62a0795c6fSMarcus Overhagen 
63*08a996b8SAxel Dörfler 		void setValue(double value, bool setParam = false);
64a0795c6fSMarcus Overhagen 			// set the displayed value (and, if setParam is true, the
65a0795c6fSMarcus Overhagen 			// linked parameter.)  The value will be constrained if necessary.
66a0795c6fSMarcus Overhagen 
67a0795c6fSMarcus Overhagen 	public: // segment interface
68a0795c6fSMarcus Overhagen 		// 18sep99: old segment interface
69a0795c6fSMarcus Overhagen 		//	virtual void offsetValue(double dfDelta);
70a0795c6fSMarcus Overhagen 
71a0795c6fSMarcus Overhagen 		// 18sep99: new segment interface.  'offset' is given
72a0795c6fSMarcus Overhagen 		// in the segment's units.
73a0795c6fSMarcus Overhagen 
74*08a996b8SAxel Dörfler 		virtual void offsetSegmentValue(ValControlDigitSegment* segment, int64 offset);
75a0795c6fSMarcus Overhagen 
76*08a996b8SAxel Dörfler 	public:
77a0795c6fSMarcus Overhagen 		virtual void mediaParameterChanged();
78a0795c6fSMarcus Overhagen 
79*08a996b8SAxel Dörfler 		virtual void updateParameter(double value);
80a0795c6fSMarcus Overhagen 			// writes the stored value to the bound parameter
81a0795c6fSMarcus Overhagen 
82a0795c6fSMarcus Overhagen 		virtual void initSegments();
83a0795c6fSMarcus Overhagen 		virtual void initConstraintsFromParam();
84a0795c6fSMarcus Overhagen 
85a0795c6fSMarcus Overhagen 	public: // ValControl impl.
86*08a996b8SAxel Dörfler 		void setValue(const void* data, size_t size); //nyi
87a0795c6fSMarcus Overhagen 
88*08a996b8SAxel Dörfler 		void getValue(void* data, size_t* ioSize); //nyi
89a0795c6fSMarcus Overhagen 
90*08a996b8SAxel Dörfler 		// string value access
91*08a996b8SAxel Dörfler 		virtual status_t setValueFrom(const char* text);
92*08a996b8SAxel Dörfler 		virtual status_t getString(BString& buffer);
93a0795c6fSMarcus Overhagen 
94*08a996b8SAxel Dörfler 	public:
95*08a996b8SAxel Dörfler 		virtual void MessageReceived(BMessage* message);
96a0795c6fSMarcus Overhagen 
97a0795c6fSMarcus Overhagen 	protected: // internal operations
98*08a996b8SAxel Dörfler 		virtual void _SetDefaultConstraints(bool negativeVisible);
99a0795c6fSMarcus Overhagen 
100*08a996b8SAxel Dörfler 	private:
101*08a996b8SAxel Dörfler 		int64 _ValueFixed() const; //nyi
102a0795c6fSMarcus Overhagen 			// calculates the current value as an int64
103a0795c6fSMarcus Overhagen 
104*08a996b8SAxel Dörfler 		void _SetValueFixed(int64 fixed); //nyi
105a0795c6fSMarcus Overhagen 			// sets the value of each segment based on an int64 value;
106a0795c6fSMarcus Overhagen 			// does not constrain the value
107a0795c6fSMarcus Overhagen 
108*08a996b8SAxel Dörfler 	protected:
109a0795c6fSMarcus Overhagen 		//	double								m_dfValue; removed 18sep99
110a0795c6fSMarcus Overhagen 
111*08a996b8SAxel Dörfler 		BContinuousParameter*	fParam;
112*08a996b8SAxel Dörfler 			// bound parameter
113*08a996b8SAxel Dörfler 
114*08a996b8SAxel Dörfler 		uint16					fWholeDigits;
115*08a996b8SAxel Dörfler 		uint16					fFractionalDigits;
116a0795c6fSMarcus Overhagen 
117a0795c6fSMarcus Overhagen 		// constraints
118*08a996b8SAxel Dörfler 		int64					fMinFixed;
119*08a996b8SAxel Dörfler 		int64					fMaxFixed;
120a0795c6fSMarcus Overhagen 
121*08a996b8SAxel Dörfler 
122a0795c6fSMarcus Overhagen };
123a0795c6fSMarcus Overhagen 
124a0795c6fSMarcus Overhagen __END_CORTEX_NAMESPACE
125*08a996b8SAxel Dörfler #endif /* NUMERIC_VAL_CONTROL_H */
126