00001 // -*- c++ -*- 00002 // 00003 // $Id: inputwidget.h 2359 2009-06-11 15:06:07Z rafi $ 00004 // 00005 // Copyright (C) 2008, 2009 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 #include "uiexception.h" 00046 #include "secstring.h" 00047 00048 namespace YAPETUI { 00061 class InputWidget { 00062 private: 00063 WINDOW* window; 00064 secstring buffer; 00065 00066 int max_length; 00067 int start_pos; 00068 int pos; 00069 int width; 00070 bool text_changed; 00071 00072 inline InputWidget(const InputWidget&) {} 00073 inline const InputWidget& operator=(const InputWidget&) { return *this; } 00074 00075 void moveBackward() throw(UIException); 00076 void moveForward() throw(UIException); 00077 void moveHome() throw(UIException); 00078 void moveEnd() throw(UIException); 00079 void processBackspace() throw(UIException); 00080 void processDelete() throw(UIException); 00081 void processInput(int ch) throw(UIException); 00082 00083 protected: 00084 void createWindow(int sx, int sy, int w) throw(UIException); 00085 void visibleCursor(bool v) const; 00086 inline const WINDOW* getWindow() const { return window; } 00087 inline WINDOW* getWindow() { return window; } 00088 inline int getStartPos() const { return start_pos; } 00089 inline int getPos() const { return pos; } 00090 inline int getWidth() const { return width; } 00091 inline secstring& getBuffer() { return buffer; } 00092 inline const secstring& getBuffer() const { return buffer; } 00093 00094 00095 public: 00096 InputWidget(int sx, int sy, int w, int ml = 512) throw(UIException); 00097 virtual ~InputWidget(); 00098 00099 int focus() throw(UIException); 00100 virtual void refresh() throw(UIException); 00101 void resize(int sx, int sy, int w) throw(UIException); 00102 void setText(secstring t) throw(UIException); 00103 inline secstring getText() const { return buffer; } 00104 void clearText(); 00105 bool isTextChanged() const { return text_changed; } 00106 }; 00107 00108 } 00109 00110 #endif // _INPUTWIDGET_H