xref: /haiku/src/apps/cortex/ValControl/ValControlDigitSegment.h (revision 16d5c24e533eb14b7b8a99ee9f3ec9ba66335b1e)
1 // ValControlDigitSegment.h
2 // * PURPOSE
3 //   Represents a fixed number of digits in a numeric value-
4 //   selection control.
5 // * HISTORY
6 //   e.moon			18sep99		moving to a fixed-point approach
7 //   e.moon			20jan99		Begun
8 
9 
10 #ifndef __VALCONTROLDIGITSEGMENT_H__
11 #define __VALCONTROLDIGITSEGMENT_H__
12 
13 #include "ValControlSegment.h"
14 
15 #include <Font.h>
16 
17 #include "cortex_defs.h"
18 __BEGIN_CORTEX_NAMESPACE
19 
20 class ValControl;
21 
22 class ValControlDigitSegment : /*extends*/ public ValControlSegment {
23 	typedef ValControlSegment _inherited;
24 
25 public:													// flags/types
26 	enum display_flags {
27 		NONE			=0,
28 		ZERO_FILL	=1
29 	};
30 
31 public:													// ctor/dtor/accessors
32 	// scaleFactor is the power of ten corresponding to the
33 	// rightmost digit: for a whole-number segment, this is 0;
34 	// for a 2-digit fractional segment, this would be -2.
35 	// +++++ is this still accurate? 18sep99
36 
37 	ValControlDigitSegment(
38 		uint16											digitCount,
39 		int16												scaleFactor,
40 		bool												negativeVisible,
41 		display_flags								flags=NONE);
42 	~ValControlDigitSegment();
43 
44 	uint16 digitCount() const;
45 	int16 scaleFactor() const;
46 	int64 value() const;
47 
48 	float prefWidth() const;
49 	float prefHeight() const;
50 
51 public:								// operations
52 	// revised setValue() 18sep99: now sets the
53 	// value of the displayed digits ONLY.
54 	void setValue(
55 		int64												value,
56 		bool												negative);
57 
58 //	// operates on a real value; based on scaling factor,
59 //	// retrieves the proper digits +++++nyi
60 //	void setValue(double dfValue);	// made public 30jan99
61 
62 public:						// ValControlSegment impl.
63 
64 	// do any font-related layout work
65 	virtual void fontChanged(
66 		const BFont*								font);
67 
68 	virtual ValCtrlLayoutEntry makeLayoutEntry();
69 
70 	virtual float handleDragUpdate(
71 		float												distance);
72 	virtual void mouseReleased(); //nyi
73 
74 public:						// BView impl.
75 	virtual void Draw(BRect updateRect);
76 	virtual void GetPreferredSize(float* pWidth, float* pHeight);
77 
78 public:						// BHandler impl.
79 	virtual void MessageReceived(BMessage* pMsg); //nyi
80 
81 public:						// archiving/instantiation
82 	ValControlDigitSegment(BMessage* pArchive);
83 	virtual status_t Archive(BMessage* pArchive, bool bDeep) const;
84 	_EXPORT static BArchivable* Instantiate(BMessage* pArchive);
85 
86 //private:					// impl. helpers
87 //	void initFont();
88 //
89 protected:					// members
90 	// * internal value representation
91 	uint16					m_digitCount;
92 	int64						m_value;
93 	bool						m_negative;
94 	int16						m_scaleFactor;
95 
96 	// * font
97 	const BFont*		m_font;
98 	font_height			m_fontHeight;
99 	float						m_yOffset;
100 	float						m_minusSignWidth;
101 
102 	float						m_digitPadding;
103 
104 	// * display settings
105 	display_flags		m_flags;
106 	bool						m_negativeVisible;
107 
108 public:						// constants
109 	static const float		s_widthTrim;
110 
111 protected:					// static stuff
112 	static float MaxDigitWidth(const BFont* pFont);
113 
114 	static const BFont*		s_cachedFont;
115 	static float					s_cachedDigitWidth;
116 };
117 
118 __END_CORTEX_NAMESPACE
119 #endif /* __VALCONTROLDIGITSEGMENT_H__ */
120