1*c284bb0fSMatt Madia /* 2*c284bb0fSMatt Madia * Copyright (c) 1999-2000, Eric Moon. 3*c284bb0fSMatt Madia * All rights reserved. 4*c284bb0fSMatt Madia * 5*c284bb0fSMatt Madia * Redistribution and use in source and binary forms, with or without 6*c284bb0fSMatt Madia * modification, are permitted provided that the following conditions 7*c284bb0fSMatt Madia * are met: 8*c284bb0fSMatt Madia * 9*c284bb0fSMatt Madia * 1. Redistributions of source code must retain the above copyright 10*c284bb0fSMatt Madia * notice, this list of conditions, and the following disclaimer. 11*c284bb0fSMatt Madia * 12*c284bb0fSMatt Madia * 2. Redistributions in binary form must reproduce the above copyright 13*c284bb0fSMatt Madia * notice, this list of conditions, and the following disclaimer in the 14*c284bb0fSMatt Madia * documentation and/or other materials provided with the distribution. 15*c284bb0fSMatt Madia * 16*c284bb0fSMatt Madia * 3. The name of the author may not be used to endorse or promote products 17*c284bb0fSMatt Madia * derived from this software without specific prior written permission. 18*c284bb0fSMatt Madia * 19*c284bb0fSMatt Madia * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 20*c284bb0fSMatt Madia * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21*c284bb0fSMatt Madia * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22*c284bb0fSMatt Madia * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 23*c284bb0fSMatt Madia * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24*c284bb0fSMatt Madia * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25*c284bb0fSMatt Madia * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 26*c284bb0fSMatt Madia * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 27*c284bb0fSMatt Madia * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28*c284bb0fSMatt Madia * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29*c284bb0fSMatt Madia */ 30*c284bb0fSMatt Madia 31*c284bb0fSMatt Madia 32a0795c6fSMarcus Overhagen // ValControlDigitSegment.h 33a0795c6fSMarcus Overhagen // * PURPOSE 34a0795c6fSMarcus Overhagen // Represents a fixed number of digits in a numeric value- 35a0795c6fSMarcus Overhagen // selection control. 36a0795c6fSMarcus Overhagen // * HISTORY 37a0795c6fSMarcus Overhagen // e.moon 18sep99 moving to a fixed-point approach 38a0795c6fSMarcus Overhagen // e.moon 20jan99 Begun 39a0795c6fSMarcus Overhagen 40a0795c6fSMarcus Overhagen 41a0795c6fSMarcus Overhagen #ifndef __VALCONTROLDIGITSEGMENT_H__ 42a0795c6fSMarcus Overhagen #define __VALCONTROLDIGITSEGMENT_H__ 43a0795c6fSMarcus Overhagen 44a0795c6fSMarcus Overhagen #include "ValControlSegment.h" 45a0795c6fSMarcus Overhagen 46a0795c6fSMarcus Overhagen #include <Font.h> 47a0795c6fSMarcus Overhagen 48a0795c6fSMarcus Overhagen #include "cortex_defs.h" 49a0795c6fSMarcus Overhagen __BEGIN_CORTEX_NAMESPACE 50a0795c6fSMarcus Overhagen 51a0795c6fSMarcus Overhagen class ValControl; 52a0795c6fSMarcus Overhagen 53a0795c6fSMarcus Overhagen class ValControlDigitSegment : /*extends*/ public ValControlSegment { 54a0795c6fSMarcus Overhagen typedef ValControlSegment _inherited; 55a0795c6fSMarcus Overhagen 56a0795c6fSMarcus Overhagen public: // flags/types 57a0795c6fSMarcus Overhagen enum display_flags { 58a0795c6fSMarcus Overhagen NONE =0, 59a0795c6fSMarcus Overhagen ZERO_FILL =1 60a0795c6fSMarcus Overhagen }; 61a0795c6fSMarcus Overhagen 62a0795c6fSMarcus Overhagen public: // ctor/dtor/accessors 63a0795c6fSMarcus Overhagen // scaleFactor is the power of ten corresponding to the 64a0795c6fSMarcus Overhagen // rightmost digit: for a whole-number segment, this is 0; 65a0795c6fSMarcus Overhagen // for a 2-digit fractional segment, this would be -2. 66a0795c6fSMarcus Overhagen // +++++ is this still accurate? 18sep99 67a0795c6fSMarcus Overhagen 68a0795c6fSMarcus Overhagen ValControlDigitSegment( 69a0795c6fSMarcus Overhagen uint16 digitCount, 70a0795c6fSMarcus Overhagen int16 scaleFactor, 71a0795c6fSMarcus Overhagen bool negativeVisible, 72a0795c6fSMarcus Overhagen display_flags flags=NONE); 73a0795c6fSMarcus Overhagen ~ValControlDigitSegment(); 74a0795c6fSMarcus Overhagen 75a0795c6fSMarcus Overhagen uint16 digitCount() const; 76a0795c6fSMarcus Overhagen int16 scaleFactor() const; 77a0795c6fSMarcus Overhagen int64 value() const; 78a0795c6fSMarcus Overhagen 79a0795c6fSMarcus Overhagen float prefWidth() const; 80a0795c6fSMarcus Overhagen float prefHeight() const; 81a0795c6fSMarcus Overhagen 82a0795c6fSMarcus Overhagen public: // operations 83a0795c6fSMarcus Overhagen // revised setValue() 18sep99: now sets the 84a0795c6fSMarcus Overhagen // value of the displayed digits ONLY. 85a0795c6fSMarcus Overhagen void setValue( 86a0795c6fSMarcus Overhagen int64 value, 87a0795c6fSMarcus Overhagen bool negative); 88a0795c6fSMarcus Overhagen 89a0795c6fSMarcus Overhagen // // operates on a real value; based on scaling factor, 90a0795c6fSMarcus Overhagen // // retrieves the proper digits +++++nyi 91a0795c6fSMarcus Overhagen // void setValue(double dfValue); // made public 30jan99 92a0795c6fSMarcus Overhagen 93a0795c6fSMarcus Overhagen public: // ValControlSegment impl. 94a0795c6fSMarcus Overhagen 95a0795c6fSMarcus Overhagen // do any font-related layout work 96a0795c6fSMarcus Overhagen virtual void fontChanged( 97a0795c6fSMarcus Overhagen const BFont* font); 98a0795c6fSMarcus Overhagen 99a0795c6fSMarcus Overhagen virtual ValCtrlLayoutEntry makeLayoutEntry(); 100a0795c6fSMarcus Overhagen 101a0795c6fSMarcus Overhagen virtual float handleDragUpdate( 102a0795c6fSMarcus Overhagen float distance); 103a0795c6fSMarcus Overhagen virtual void mouseReleased(); //nyi 104a0795c6fSMarcus Overhagen 105a0795c6fSMarcus Overhagen public: // BView impl. 106a0795c6fSMarcus Overhagen virtual void Draw(BRect updateRect); 107a0795c6fSMarcus Overhagen virtual void GetPreferredSize(float* pWidth, float* pHeight); 108a0795c6fSMarcus Overhagen 109a0795c6fSMarcus Overhagen public: // BHandler impl. 110a0795c6fSMarcus Overhagen virtual void MessageReceived(BMessage* pMsg); //nyi 111a0795c6fSMarcus Overhagen 112a0795c6fSMarcus Overhagen public: // archiving/instantiation 113a0795c6fSMarcus Overhagen ValControlDigitSegment(BMessage* pArchive); 114a0795c6fSMarcus Overhagen virtual status_t Archive(BMessage* pArchive, bool bDeep) const; 115a0795c6fSMarcus Overhagen _EXPORT static BArchivable* Instantiate(BMessage* pArchive); 116a0795c6fSMarcus Overhagen 117a0795c6fSMarcus Overhagen //private: // impl. helpers 118a0795c6fSMarcus Overhagen // void initFont(); 119a0795c6fSMarcus Overhagen // 120a0795c6fSMarcus Overhagen protected: // members 121a0795c6fSMarcus Overhagen // * internal value representation 122a0795c6fSMarcus Overhagen uint16 m_digitCount; 123a0795c6fSMarcus Overhagen int64 m_value; 124a0795c6fSMarcus Overhagen bool m_negative; 125a0795c6fSMarcus Overhagen int16 m_scaleFactor; 126a0795c6fSMarcus Overhagen 127a0795c6fSMarcus Overhagen // * font 128a0795c6fSMarcus Overhagen const BFont* m_font; 129a0795c6fSMarcus Overhagen font_height m_fontHeight; 130a0795c6fSMarcus Overhagen float m_yOffset; 131a0795c6fSMarcus Overhagen float m_minusSignWidth; 132a0795c6fSMarcus Overhagen 133a0795c6fSMarcus Overhagen float m_digitPadding; 134a0795c6fSMarcus Overhagen 135a0795c6fSMarcus Overhagen // * display settings 136a0795c6fSMarcus Overhagen display_flags m_flags; 137a0795c6fSMarcus Overhagen bool m_negativeVisible; 138a0795c6fSMarcus Overhagen 139a0795c6fSMarcus Overhagen public: // constants 140a0795c6fSMarcus Overhagen static const float s_widthTrim; 141a0795c6fSMarcus Overhagen 142a0795c6fSMarcus Overhagen protected: // static stuff 143a0795c6fSMarcus Overhagen static float MaxDigitWidth(const BFont* pFont); 144a0795c6fSMarcus Overhagen 145a0795c6fSMarcus Overhagen static const BFont* s_cachedFont; 146a0795c6fSMarcus Overhagen static float s_cachedDigitWidth; 147a0795c6fSMarcus Overhagen }; 148a0795c6fSMarcus Overhagen 149a0795c6fSMarcus Overhagen __END_CORTEX_NAMESPACE 150a0795c6fSMarcus Overhagen #endif /* __VALCONTROLDIGITSEGMENT_H__ */ 151