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

bytstpr.cpp

Go to the documentation of this file.
00001 // $Id$
00002 
00003 //**********************************************************************
00004 //                                                                     *
00005 //    Description:   TurboVision byte 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 "bytstpr.h"
00045 
00046 
00047 using namespace Monitor::Utility;
00048 
00049 
00050 
00051 ByteStepper::ByteStepper(const TRect&    newBounds,
00052                          int             newMaxLen,
00053                          const char*     newFormat,
00054                          const float     newDisplayScaler)
00055     :
00056     Watchable(),
00057     TInputLine(newBounds, newMaxLen), maxValue(255), minValue(0),
00058     displayScaler(newDisplayScaler)
00059 {
00060     _USEMYTRACE_("ByteStepper::ByteStepper"
00061                  "(newBounds, newMaxLen, newFormat, newDisplayScaler)")
00062 
00063     format = strdup(newFormat);
00064     setValue(0);
00065 }
00066 
00067 
00068 
00069 ByteStepper::~ByteStepper()
00070 {
00071     _USEMYTRACE_("ByteStepper::~ByteStepper()")
00072 
00073     free(const_cast< char* >(format)), format = 0;
00074 }
00075 
00076 
00077 
00078 void
00079 ByteStepper::setState(ushort    aState, Boolean    enable)
00080 {
00081     if ((True != enable) && (sfFocused & aState))
00082     {
00083         displayValue();
00084     }
00085 
00086     TInputLine::setState(aState, enable);
00087 }
00088 
00089 
00090 
00091 void
00092 ByteStepper::handleEvent(TEvent&    event)
00093 {
00094     if (getState(sfFocused) && (evKeyDown == event.what))
00095     {
00096         switch (event.keyDown.keyCode)
00097         {
00098         case kbCtrlHome:
00099             changeValue(0xFF);
00100             clearEvent(event);
00101             return;
00102         case kbPgUp:
00103             if (255 > value)
00104             {
00105                 changeValue(value + 16);
00106             }
00107             clearEvent(event);
00108             return;
00109         case kbUp:
00110         case kbPlus:
00111         case kbGrayPlus:
00112             if (255 > value)
00113             {
00114                 changeValue(value + 1);
00115             }
00116             clearEvent(event);
00117             return;
00118         case kbDown:
00119         case kbMinus:
00120         case kbGrayMinus:
00121             if (0 < value)
00122             {
00123                 changeValue(value - 1);
00124             }
00125             clearEvent(event);
00126             return;
00127         case kbPgDn:
00128             if (0 < value)
00129             {
00130                 changeValue(value - 16);
00131             }
00132             clearEvent(event);
00133             return;
00134         case kbCtrlEnd:
00135             changeValue(0);
00136             clearEvent(event);
00137             return;
00138         case kbEnter:
00139             readValue();
00140             clearEvent(event);
00141             return;
00142         case kbEsc:
00143             *data = '\0';
00144             draw();
00145             selectAll(True);
00146             clearEvent(event);
00147             return;
00148         default:
00149             break;
00150         }
00151     }
00152 
00153     TInputLine::handleEvent(event);
00154 }
00155 
00156 
00157 
00158 void
00159 ByteStepper::setScaler(const float     newDisplayScaler)
00160 {
00161     _USEMYTRACE_("ByteStepper::setScaler(newDisplayScaler))")
00162 
00163     displayScaler = newDisplayScaler;
00164     displayValue();
00165 }
00166 
00167 
00168 
00169 void
00170 ByteStepper::setMaxValue(const unsigned char    newMaxValue)
00171 {
00172     _USEMYTRACE_("ByteStepper::setMaxValue(newMaxValue))")
00173 
00174     maxValue = newMaxValue;
00175     changeValue(value);
00176 }
00177 
00178 
00179 
00180 void
00181 ByteStepper::setMinValue(const unsigned char    newMinValue)
00182 {
00183     _USEMYTRACE_("ByteStepper::setMinValue(newMinValue))")
00184 
00185     minValue = newMinValue;
00186     changeValue(value);
00187 }
00188 
00189 
00190 
00191 void
00192 ByteStepper::displayValue()
00193 {
00194     _USEMYTRACE_("ByteStepper::displayValue()")
00195 
00196     float    scaledValue = value;
00197 
00198     scaledValue *= displayScaler;
00199 
00200     sprintf(data, format, scaledValue);
00201     draw();
00202 
00203     selectAll(False);
00204 }
00205 
00206 
00207 
00208 void
00209 ByteStepper::getData(void    *rec)
00210 {
00211     _USEMYTRACE_("ByteStepper::getData(rec)")
00212 
00213     *(static_cast< int* >(rec)) = value;
00214 }
00215 
00216 
00217 
00218 void
00219 ByteStepper::setData(void    *rec)
00220 {
00221     _USEMYTRACE_("ByteStepper::setData(rec)")
00222 
00223     changeValue(*(static_cast< int* >(rec)));
00224 }
00225 
00226 
00227 
00228 int
00229 ByteStepper::setValue(int    newValue)
00230 {
00231     _USEMYTRACE_("ByteStepper::setValue(newValue))")
00232 
00233     if (minValue > newValue)
00234     {
00235         newValue = minValue;
00236     }
00237     if (maxValue < newValue)
00238     {
00239         newValue = maxValue;
00240     }
00241 
00242     int    valueSet = 0;
00243 
00244     if (newValue != value)
00245     {
00246         value = newValue;
00247         valueSet = !0;
00248     }
00249 
00250     displayValue();
00251 
00252     return valueSet;
00253 }
00254 
00255 
00256 
00257 void
00258 ByteStepper::changeValue(int    newValue)
00259 {
00260     _USEMYTRACE_("ByteStepper::changeValue(newValue))")
00261 
00262     if (setValue(newValue))
00263     {
00264         updated();
00265     }
00266 }
00267 
00268 
00269 
00270 void
00271 ByteStepper::readValue()
00272 {
00273     _USEMYTRACE_("ByteStepper::readValue()")
00274 
00275     float    scaledValue = atof(data);
00276 
00277     scaledValue /= displayScaler;
00278 
00279     int newValue = scaledValue;
00280 
00281     changeValue(newValue);
00282 }
00283 

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