ui/inputwidget.h

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //
00003 // $Id: inputwidget.h,v 1.5 2008-02-13 20:47:48 rafi Exp $
00004 //
00005 // YAPET -- Yet Another Password Encryption Tool
00006 // Copyright (C) 2008  Rafael Ostertag
00007 //
00008 // This program is free software: you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation, either version 3 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020 //
00021 
00022 #ifndef _INPUTWIDGET_H
00023 #define _INPUTWIDGET_H
00024 
00025 #ifdef HAVE_CONFIG_H
00026 # include <config.h>
00027 #endif
00028 
00029 #ifdef HAVE_NCURSES_H
00030 # include <ncurses.h>
00031 #else // HAVE_NCURSES_H
00032 # ifdef HAVE_CURSES_H
00033 #  include <curses.h>
00034 # else
00035 #  error "Neither curses.h nor ncurses.h available"
00036 # endif // HAVE_CURSES_H
00037 #endif // HAVE_NCURSES_H
00038 #include "curswa.h" // Leave this here. It depends on the above includes.
00039 
00040 #ifdef HAVE_STRING
00041 # include <string>
00042 #endif
00043 
00044 #include "uiexception.h"
00045 #include "secstring.h"
00046 
00047 namespace YAPETUI {
00060     class InputWidget {
00061     private:
00062         WINDOW* window;
00063         secstring buffer;
00064 
00065         int max_length;
00066         int start_pos;
00067         int pos;
00068         int width;
00069         bool text_changed;
00070 
00071         inline InputWidget(const InputWidget&) {}
00072         inline const InputWidget& operator=(const InputWidget&) { return *this; }
00073 
00074         void moveBackward() throw(UIException);
00075         void moveForward() throw(UIException);
00076         void moveHome() throw(UIException);
00077         void moveEnd() throw(UIException);
00078         void processBackspace() throw(UIException);
00079         void processDelete() throw(UIException);
00080         void processInput(int ch) throw(UIException);
00081 
00082     protected:
00083         void createWindow(int sx, int sy, int w) throw(UIException);
00084         inline const WINDOW* getWindow() const { return window; }
00085         inline WINDOW* getWindow() { return window; }
00086         inline int getStartPos() const { return start_pos; }
00087         inline int getPos() const { return pos; }
00088         inline int getWidth() const { return width; }
00089         inline secstring& getBuffer() { return buffer; }
00090         inline const secstring& getBuffer() const { return buffer; }
00091 
00092     public:
00093         InputWidget(int sx, int sy, int w, int ml = 512) throw(UIException);
00094         virtual ~InputWidget();
00095 
00096         int focus() throw(UIException);
00097         virtual void refresh() throw(UIException);
00098         void resize(int sx, int sy, int w) throw(UIException);
00099         void setText(secstring t) throw(UIException);
00100         inline secstring getText() const { return buffer; }
00101         void clearText();
00102         bool isTextChanged() const { return text_changed; }
00103     };
00104 
00105 }
00106 
00107 #endif // _INPUTWIDGET_H

Generated on Wed Feb 27 16:15:41 2008 for YAPET by  doxygen 1.5.4