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 #include "../intl.h"
00022 #include "passwordwidget.h"
00023 #include "basewindow.h"
00024 #include "colors.h"
00025
00026 #ifdef HAVE_STDLIB_H
00027 # include <stdlib.h>
00028 #endif
00029
00030 using namespace YAPET::UI;
00031
00032 PasswordWidget::PasswordWidget (int sx, int sy, int w, int ml)
00033 throw (UIException) : InputWidget (sx, sy, w, ml) {}
00034
00035 PasswordWidget::~PasswordWidget() {
00036 }
00037
00038 int
00039 PasswordWidget::focus() throw (UIException) {
00040 Colors::setcolor (getWindow(), INPUTWIDGET_FOCUS);
00041 int retval = wrefresh (getWindow());
00042
00043 if (retval == ERR)
00044 throw UIException (_ ("Error refreshing the widget") );
00045
00046 retval = wmove (getWindow(), 0, getPos());
00047
00048 if (retval == ERR)
00049 throw UIException (_ ("Error moving cursor for widget") );
00050
00051 visibleCursor (true);
00052 int ch;
00053
00054 while (true) {
00055 ch = wgetch (getWindow());
00056
00057 switch (ch) {
00058
00059 #ifdef HAVE_WRESIZE
00060 case KEY_RESIZE:
00061 #endif // HAVE_WRESIZE
00062 case '\n':
00063 case KEY_TAB:
00064 case KEY_ESC:
00065 case KEY_CTRL_E:
00066 goto BAILOUT;
00067
00068 case KEY_UP:
00069 case KEY_LEFT:
00070 case KEY_DOWN:
00071 case KEY_RIGHT:
00072 case KEY_END:
00073 case KEY_A1:
00074 case KEY_HOME:
00075 case KEY_C1:
00076 break;
00077 case KEY_ENTER:
00078 ungetch ('\n');
00079 break;
00080 case KEY_DC:
00081 processDelete();
00082 break;
00083 case KEY_BACKSPACE:
00084 case 127:
00085 processBackspace();
00086 break;
00087 case KEY_REFRESH:
00088 BaseWindow::refreshAll();
00089 break;
00090 default:
00091 processInput (ch);
00092 break;
00093 }
00094 }
00095
00096 BAILOUT:
00097 visibleCursor (false);
00098 Colors::setcolor (getWindow(), INPUTWIDGET_NOFOCUS);
00099 retval = wrefresh (getWindow());
00100
00101 if (retval == ERR)
00102 throw UIException (_ ("Error refreshing the widget") );
00103
00104 return ch;
00105 }
00106
00107 void
00108 PasswordWidget::refresh() throw (UIException) {
00109 int retval = wclear (getWindow() );
00110
00111 if (retval == ERR)
00112 throw UIException (_ ("Error clearing input widget") );
00113
00114 if (getPos() > 0) {
00115 char* tmp = (char*) malloc (getPos() + 1);
00116 memset (tmp, '*', getPos() );
00117 tmp[getPos() ] = '\0';
00118 retval = mymvwaddnstr (getWindow(),
00119 0,
00120 0,
00121 tmp,
00122 getWidth() - 1);
00123 free (tmp);
00124
00125 if (retval == ERR)
00126 throw UIException (_ ("Error adding text to window") );
00127
00128 if (getPos() >= getWidth() - 1)
00129 retval = wmove (getWindow(), 0, getWidth() - 1);
00130 else
00131 retval = wmove (getWindow(), 0, getPos() );
00132
00133 if (retval == ERR)
00134 throw UIException (_ ("Error moving cursor") );
00135 }
00136
00137 retval = wrefresh (getWindow() );
00138
00139 if (retval == ERR)
00140 throw UIException (_ ("Error refreshing input widget") );
00141 }