• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ui/inputwidget.h

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //
00003 // $Id: inputwidget.h 3342 2010-09-17 18:32:00Z java $
00004 //
00005 // Copyright (C) 2008-2010  Rafael Ostertag
00006 //
00007 // This file is part of YAPET.
00008 //
00009 // YAPET is free software: you can redistribute it and/or modify it under the
00010 // terms of the GNU General Public License as published by the Free Software
00011 // Foundation, either version 3 of the License, or (at your option) any later
00012 // version.
00013 //
00014 // YAPET is distributed in the hope that it will be useful, but WITHOUT ANY
00015 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00016 // FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00017 // details.
00018 //
00019 // You should have received a copy of the GNU General Public License along with
00020 // YAPET.  If not, see <http://www.gnu.org/licenses/>.
00021 //
00022 
00023 #ifndef _INPUTWIDGET_H
00024 #define _INPUTWIDGET_H
00025 
00026 #ifdef HAVE_CONFIG_H
00027 # include <config.h>
00028 #endif
00029 
00030 #ifdef HAVE_NCURSES_H
00031 # include <ncurses.h>
00032 #else // HAVE_NCURSES_H
00033 # ifdef HAVE_CURSES_H
00034 #  include <curses.h>
00035 # else
00036 #  error "Neither curses.h nor ncurses.h available"
00037 # endif // HAVE_CURSES_H
00038 #endif // HAVE_NCURSES_H
00039 #include "curswa.h" // Leave this here. It depends on the above includes.
00040 
00041 #ifdef HAVE_STRING
00042 # include <string>
00043 #endif
00044 
00045 #ifdef HAVE_STDEXCEPT
00046 # include <stdexcept>
00047 #endif
00048 
00049 #include "uiexception.h"
00050 #include "secstring.h"
00051 
00052 namespace YAPET {
00053     namespace UI {
00066         class InputWidget {
00067             private:
00068                 WINDOW* window;
00069                 secstring buffer;
00070 
00071                 int max_length;
00072                 int start_pos;
00073                 int pos;
00074                 int width;
00075                 bool text_changed;
00076         bool readonly;
00077 
00085         inline InputWidget() throw (std::runtime_error) {
00086             throw std::runtime_error(_("Default constructor must not be used!"));
00087         }
00088 
00089                 inline InputWidget (const InputWidget&) {}
00090                 inline const InputWidget& operator= (const InputWidget&) {
00091                     return *this;
00092                 }
00093 
00094                 void moveBackward() throw (UIException);
00095                 void moveForward() throw (UIException);
00096                 void moveHome() throw (UIException);
00097                 void moveEnd() throw (UIException);
00098 
00099         enum {
00100             DEFAULT_TEXT_LEN=512
00101         };
00102 
00103             protected:
00104                 virtual void processBackspace() throw (UIException);
00105                 virtual void processDelete() throw (UIException);
00106                 virtual void processInput (int ch) throw (UIException);
00107                 virtual void createWindow (int sx, int sy, int w) throw (UIException);
00108                 virtual inline const WINDOW* getWindow() const {
00109                     return window;
00110                 }
00111                 virtual inline WINDOW* getWindow() {
00112                     return window;
00113                 }
00114                 virtual inline int getStartPos() const {
00115                     return start_pos;
00116                 }
00117                 virtual inline int getPos() const {
00118                     return pos;
00119                 }
00120                 virtual inline int getWidth() const {
00121                     return width;
00122                 }
00123                 virtual inline secstring& getBuffer() {
00124                     return buffer;
00125                 }
00126                 virtual inline const secstring& getBuffer() const {
00127                     return buffer;
00128                 }
00129 
00130             public:
00131                 InputWidget (int sx, int sy, int w, int ml = DEFAULT_TEXT_LEN, bool ro = false) throw (UIException);
00132                 InputWidget (int sx, int sy, int w, bool ro) throw (UIException);
00133 
00134                 virtual ~InputWidget();
00135 
00136                 virtual int focus() throw (UIException);
00137                 virtual void refresh() throw (UIException);
00138                 virtual void resize (int sx, int sy, int w) throw (UIException);
00139                 virtual void setText (secstring t) throw (UIException);
00140                 virtual inline secstring getText() const {
00141                     return buffer;
00142                 }
00143                 virtual void clearText();
00149                 inline void setTextChanged (bool b) {
00150                     text_changed = b;
00151                 }
00152                 inline bool isTextChanged() const {
00153                     return text_changed;
00154                 }
00155                 inline bool hasText() const {
00156                     return !buffer.empty();
00157                 }
00158         inline void setReadonly(bool ro) {
00159             readonly = ro;
00160         }
00161         inline bool getReadonly() const {
00162             return readonly;
00163         }
00164         };
00165 
00166     }
00167 }
00168 #endif // _INPUTWIDGET_H

Generated on Sun Sep 19 2010 15:37:13 for YAPET by  doxygen 1.7.1