Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

fltstpr.cpp

Go to the documentation of this file.
00001 // $Id: fltstpr.cpp,v 1.2 2003/10/29 19:54:14 whitecf Exp $
00002 
00003 //**********************************************************************
00004 //                                                                     *
00005 //    Description:   TurboVision float stepper class.                   *
00006 //                                                                     *
00007 //    Author:        Chris White (whitecf@bcs.org.uk)                  *
00008 //                                                                     *
00009 //    Copyright (C) 2003  Monitor Computing Services Ltd.              *
00010 //                                                                     *
00011 //    This program is free software; you can redistribute it and/or    *
00012 //    modify it under the terms of the GNU General Public License      *
00013 //    as published by the Free Software Foundation; either version 2   *
00014 //    of the License, or any later version.                            *
00015 //                                                                     *
00016 //    This program is distributed in the hope that it will be useful,  *
00017 //    but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00018 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00019 //    GNU General Public License for more details.                     *
00020 //                                                                     *
00021 //    You should have received a copy of the GNU General Public        *
00022 //    License (http://www.gnu.org/copyleft/gpl.html) along with this   *
00023 //    program; if not, write to:                                       *
00024 //       The Free Software Foundation Inc.,                            *
00025 //       59 Temple Place - Suite 330,                                  *
00026 //       Boston, MA  02111-1307,                                       *
00027 //       USA.                                                          *
00028 //                                                                     *
00029 //**********************************************************************
00030 //                                                                     *
00031 //    Notes:                                                           *
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 

Generated on Wed Oct 29 20:52:39 2003 for Utility BC Turbo Vision by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002