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 // NumericValControl.h 33a0795c6fSMarcus Overhagen // * PURPOSE 34a0795c6fSMarcus Overhagen // Extends ValControl to provide the basis for a variety 35a0795c6fSMarcus Overhagen // of numeric UI controls. 36a0795c6fSMarcus Overhagen // * HISTORY 37a0795c6fSMarcus Overhagen // e.moon 18sep99 General cleanup; values are now stored 38a0795c6fSMarcus Overhagen // in fixed-point form only. 39a0795c6fSMarcus Overhagen // e.moon 17jan99 Begun 40a0795c6fSMarcus Overhagen // +++++ 31jan99: negatives are still handled wrong... 41a0795c6fSMarcus Overhagen // 42a0795c6fSMarcus Overhagen // CLASS: NumericValControl 4308a996b8SAxel Dörfler #ifndef NUMERIC_VAL_CONTROL_H 4408a996b8SAxel Dörfler #define NUMERIC_VAL_CONTROL_H 45a0795c6fSMarcus Overhagen 46a0795c6fSMarcus Overhagen #include "cortex_defs.h" 4708a996b8SAxel Dörfler #include "ValControl.h" 4808a996b8SAxel Dörfler 4908a996b8SAxel Dörfler #include <MediaDefs.h> 5008a996b8SAxel Dörfler 5108a996b8SAxel Dörfler 5208a996b8SAxel Dörfler class BContinuousParameter; 5308a996b8SAxel Dörfler 5408a996b8SAxel Dörfler 55a0795c6fSMarcus Overhagen __BEGIN_CORTEX_NAMESPACE 56a0795c6fSMarcus Overhagen 57a0795c6fSMarcus Overhagen class ValControlDigitSegment; 58a0795c6fSMarcus Overhagen 5908a996b8SAxel Dörfler 6008a996b8SAxel Dörfler class NumericValControl : public ValControl { 6108a996b8SAxel Dörfler public: 62a0795c6fSMarcus Overhagen typedef ValControl _inherited; 63a0795c6fSMarcus Overhagen 6408a996b8SAxel Dörfler public: 65a0795c6fSMarcus Overhagen 66a0795c6fSMarcus Overhagen // +++++ need control over number of segments +++++ 67a0795c6fSMarcus Overhagen 68a0795c6fSMarcus Overhagen // parameter-linked ctor 6908a996b8SAxel Dörfler NumericValControl(BRect frame, const char* name, BContinuousParameter* param, 7008a996b8SAxel Dörfler uint16 wholeDigits, uint16 fractionalDigits = 0, align_mode alignMode = ALIGN_FLUSH_RIGHT, 71a0795c6fSMarcus Overhagen align_flags alignFlags = ALIGN_NONE); 72a0795c6fSMarcus Overhagen 73a0795c6fSMarcus Overhagen // 'plain' ctor 7408a996b8SAxel Dörfler NumericValControl(BRect frame, const char* name, BMessage* message, uint16 wholeDigits, 7508a996b8SAxel Dörfler uint16 fractionalDigits = 0, bool negativeVisible = true, 7608a996b8SAxel Dörfler align_mode alignMode = ALIGN_FLUSH_RIGHT, align_flags alignFlags = ALIGN_NONE); 77a0795c6fSMarcus Overhagen 78a0795c6fSMarcus Overhagen ~NumericValControl(); 79a0795c6fSMarcus Overhagen 80a0795c6fSMarcus Overhagen BContinuousParameter* param() const; 8108a996b8SAxel Dörfler // bound parameter, or 0 if none 82a0795c6fSMarcus Overhagen 8308a996b8SAxel Dörfler void getConstraints(double* outMinValue, double* outMaxValue); 84a0795c6fSMarcus Overhagen // value constraints (by default, the min/max allowed by the ctor 85a0795c6fSMarcus Overhagen // settings: wholeDigits, fractionalDigits, and negativeVisible) 86a0795c6fSMarcus Overhagen 8708a996b8SAxel Dörfler status_t setConstraints(double minValue, double maxValue); 8808a996b8SAxel Dörfler // the current value is not yet re-constrained by this call 89a0795c6fSMarcus Overhagen 9008a996b8SAxel Dörfler double value() const; 91a0795c6fSMarcus Overhagen // fetches the current value (calculated on the spot from each 92a0795c6fSMarcus Overhagen // segment.) 93a0795c6fSMarcus Overhagen 9408a996b8SAxel Dörfler void setValue(double value, bool setParam = false); 95a0795c6fSMarcus Overhagen // set the displayed value (and, if setParam is true, the 96a0795c6fSMarcus Overhagen // linked parameter.) The value will be constrained if necessary. 97a0795c6fSMarcus Overhagen 98a0795c6fSMarcus Overhagen public: // segment interface 99a0795c6fSMarcus Overhagen // 18sep99: old segment interface 100a0795c6fSMarcus Overhagen // virtual void offsetValue(double dfDelta); 101a0795c6fSMarcus Overhagen 102a0795c6fSMarcus Overhagen // 18sep99: new segment interface. 'offset' is given 103a0795c6fSMarcus Overhagen // in the segment's units. 104a0795c6fSMarcus Overhagen 10508a996b8SAxel Dörfler virtual void offsetSegmentValue(ValControlDigitSegment* segment, int64 offset); 106a0795c6fSMarcus Overhagen 10708a996b8SAxel Dörfler public: 108a0795c6fSMarcus Overhagen virtual void mediaParameterChanged(); 109a0795c6fSMarcus Overhagen 11008a996b8SAxel Dörfler virtual void updateParameter(double value); 111a0795c6fSMarcus Overhagen // writes the stored value to the bound parameter 112a0795c6fSMarcus Overhagen 113a0795c6fSMarcus Overhagen virtual void initSegments(); 114a0795c6fSMarcus Overhagen virtual void initConstraintsFromParam(); 115a0795c6fSMarcus Overhagen 116a0795c6fSMarcus Overhagen public: // ValControl impl. 11708a996b8SAxel Dörfler void setValue(const void* data, size_t size); //nyi 118a0795c6fSMarcus Overhagen 11908a996b8SAxel Dörfler void getValue(void* data, size_t* ioSize); //nyi 120a0795c6fSMarcus Overhagen 12108a996b8SAxel Dörfler // string value access 12208a996b8SAxel Dörfler virtual status_t setValueFrom(const char* text); 12308a996b8SAxel Dörfler virtual status_t getString(BString& buffer); 124a0795c6fSMarcus Overhagen 12508a996b8SAxel Dörfler public: 12608a996b8SAxel Dörfler virtual void MessageReceived(BMessage* message); 127a0795c6fSMarcus Overhagen 128a0795c6fSMarcus Overhagen protected: // internal operations 12908a996b8SAxel Dörfler virtual void _SetDefaultConstraints(bool negativeVisible); 130a0795c6fSMarcus Overhagen 13108a996b8SAxel Dörfler private: 13208a996b8SAxel Dörfler int64 _ValueFixed() const; //nyi 133a0795c6fSMarcus Overhagen // calculates the current value as an int64 134a0795c6fSMarcus Overhagen 13508a996b8SAxel Dörfler void _SetValueFixed(int64 fixed); //nyi 136a0795c6fSMarcus Overhagen // sets the value of each segment based on an int64 value; 137a0795c6fSMarcus Overhagen // does not constrain the value 138a0795c6fSMarcus Overhagen 13908a996b8SAxel Dörfler protected: 140a0795c6fSMarcus Overhagen // double m_dfValue; removed 18sep99 141a0795c6fSMarcus Overhagen 14208a996b8SAxel Dörfler BContinuousParameter* fParam; 14308a996b8SAxel Dörfler // bound parameter 14408a996b8SAxel Dörfler 14508a996b8SAxel Dörfler uint16 fWholeDigits; 14608a996b8SAxel Dörfler uint16 fFractionalDigits; 147a0795c6fSMarcus Overhagen 148a0795c6fSMarcus Overhagen // constraints 14908a996b8SAxel Dörfler int64 fMinFixed; 15008a996b8SAxel Dörfler int64 fMaxFixed; 151a0795c6fSMarcus Overhagen 15208a996b8SAxel Dörfler 153a0795c6fSMarcus Overhagen }; 154a0795c6fSMarcus Overhagen 155a0795c6fSMarcus Overhagen __END_CORTEX_NAMESPACE 15608a996b8SAxel Dörfler #endif /* NUMERIC_VAL_CONTROL_H */ 157