ArduinoLibs
Field.cpp
00001 /*
00002  * Copyright (C) 2012 Southern Storm Software, Pty Ltd.
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a
00005  * copy of this software and associated documentation files (the "Software"),
00006  * to deal in the Software without restriction, including without limitation
00007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008  * and/or sell copies of the Software, and to permit persons to whom the
00009  * Software is furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included
00012  * in all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00019  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00020  * DEALINGS IN THE SOFTWARE.
00021  */
00022 
00023 #include "Field.h"
00024 
00040 Field::Field(const String &label)
00041     : _label(label)
00042     , _form(0)
00043     , next(0)
00044     , prev(0)
00045 {
00046 }
00047 
00052 Field::Field(Form &form, const String &label)
00053     : _label(label)
00054     , _form(0)
00055     , next(0)
00056     , prev(0)
00057 {
00058     form.addField(this);
00059 }
00060 
00066 Field::~Field()
00067 {
00068     if (_form)
00069         _form->removeField(this);
00070 }
00071 
00096 int Field::dispatch(int event)
00097 {
00098     // Nothing to do here.
00099     return -1;
00100 }
00101 
00116 void Field::enterField(bool reverse)
00117 {
00118     lcd()->print(_label);
00119 }
00120 
00129 void Field::exitField()
00130 {
00131     // Nothing to do here.
00132 }
00133 
00146 void Field::setLabel(const String &label)
00147 {
00148     if (isCurrent()) {
00149         unsigned int prevLen = _label.length();
00150         unsigned int newLen = label.length();
00151         _label = label;
00152         lcd()->setCursor(0, 0);
00153         lcd()->print(label);
00154         while (newLen++ < prevLen)
00155             lcd()->write(' ');
00156         updateCursor();
00157     } else {
00158         _label = label;
00159     }
00160 }
00161 
00169 bool Field::isCurrent() const
00170 {
00171     if (!_form->isVisible())
00172         return false;
00173     return _form->currentField() == this;
00174 }
00175 
00191 void Field::updateCursor()
00192 {
00193     // Nothing to do here.
00194 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator