Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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"
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