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