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