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