00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #define Uses_TEvent
00037 #define Uses_TKeys
00038
00039 #include <stdio.h>
00040 #include <stdlib.h>
00041
00042 #include <mytrace.h>
00043
00044 #include "fltstpr.h"
00045
00046
00047 using namespace Monitor::Utility;
00048
00049
00050
00051 FloatStepper::FloatStepper(const TRect& newBounds,
00052 int newMaxLen,
00053 const char* newFormat,
00054 const float newDisplayScaler)
00055 :
00056 Watchable(),
00057 TInputLine(newBounds, newMaxLen),
00058 displayScaler(newDisplayScaler)
00059 {
00060 _USEMYTRACE_("FloatStepper::FloatStepper"
00061 "(newBounds, newMaxLen, newFormat, newDisplayScaler)")
00062
00063
00064 format = strdup(newFormat);
00065 setValue(0);
00066 }
00067
00068
00069
00070 FloatStepper::~FloatStepper()
00071 {
00072 _USEMYTRACE_("FloatStepper::~FloatStepper()")
00073
00074
00075 free(const_cast< char* >(format)), format = 0;
00076 }
00077
00078
00079
00080 void
00081 FloatStepper::setState(ushort aState, Boolean enable)
00082 {
00083 if ((True != enable) && (sfFocused & aState))
00084 {
00085 displayValue();
00086 }
00087
00088 TInputLine::setState(aState, enable);
00089 }
00090
00091
00092
00093 void
00094 FloatStepper::handleEvent(TEvent& event)
00095 {
00096 if (getState(sfFocused) && (evKeyDown == event.what))
00097 {
00098 switch (event.keyDown.keyCode)
00099 {
00100 case kbUp:
00101 case kbPlus:
00102 case kbGrayPlus:
00103 changeValue(value + 1.0);
00104 clearEvent(event);
00105 return;
00106 case kbDown:
00107 case kbMinus:
00108 case kbGrayMinus:
00109 changeValue(value - 1.0);
00110 clearEvent(event);
00111 return;
00112 case kbPgDn:
00113 changeValue(value - 10.0);
00114 clearEvent(event);
00115 return;
00116 case kbEnter:
00117 readValue();
00118 clearEvent(event);
00119 return;
00120 case kbEsc:
00121 *data = '\0';
00122 draw();
00123 selectAll(True);
00124 clearEvent(event);
00125 return;
00126 default:
00127 break;
00128 }
00129 }
00130
00131 TInputLine::handleEvent(event);
00132 }
00133
00134
00135
00136 void
00137 FloatStepper::setScaler(const float newDisplayScaler)
00138 {
00139 _USEMYTRACE_("FloatStepper::setScaler(newDisplayScaler))")
00140
00141
00142 displayScaler = newDisplayScaler;
00143 displayValue();
00144 }
00145
00146
00147
00148 void
00149 FloatStepper::displayValue()
00150 {
00151 _USEMYTRACE_("FloatStepper::displayValue()")
00152
00153
00154 float scaledValue = value * displayScaler;
00155
00156
00157 sprintf(data, format, scaledValue);
00158 draw();
00159
00160 selectAll(False);
00161 }
00162
00163
00164
00165 void
00166 FloatStepper::getData(void *rec)
00167 {
00168 _USEMYTRACE_("FloatStepper::getData(rec)")
00169
00170
00171 *(static_cast< float* >(rec)) = value;
00172 }
00173
00174
00175
00176 void
00177 FloatStepper::setData(void *rec)
00178 {
00179 _USEMYTRACE_("FloatStepper::setData(rec)")
00180
00181
00182 changeValue(*(static_cast< float* >(rec)));
00183 }
00184
00185
00186
00187 int
00188 FloatStepper::setValue(float newValue)
00189 {
00190 _USEMYTRACE_("FloatStepper::setValue(newValue))")
00191
00192
00193 int valueSet = 0;
00194
00195
00196 if (newValue != value)
00197 {
00198 value = newValue;
00199 valueSet = !0;
00200 }
00201
00202 displayValue();
00203
00204 return valueSet;
00205 }
00206
00207
00208
00209 void
00210 FloatStepper::changeValue(float newValue)
00211 {
00212 _USEMYTRACE_("FloatStepper::changeValue(newValue))")
00213
00214
00215 if (setValue(newValue))
00216 {
00217 updated();
00218 }
00219 }
00220
00221
00222
00223 void
00224 FloatStepper::readValue()
00225 {
00226 _USEMYTRACE_("FloatStepper::readValue()")
00227
00228
00229 float scaledValue = atof(data);
00230
00231
00232 scaledValue /= displayScaler;
00233
00234 changeValue(scaledValue);
00235 }
00236