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

ui/passwordwidget.cc

Go to the documentation of this file.
00001 // $Id: passwordwidget.cc 3342 2010-09-17 18:32:00Z java $
00002 //
00003 // Copyright (C) 2008-2010  Rafael Ostertag
00004 //
00005 // This file is part of YAPET.
00006 //
00007 // YAPET is free software: you can redistribute it and/or modify it under the
00008 // terms of the GNU General Public License as published by the Free Software
00009 // Foundation, either version 3 of the License, or (at your option) any later
00010 // version.
00011 //
00012 // YAPET is distributed in the hope that it will be useful, but WITHOUT ANY
00013 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014 // FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00015 // details.
00016 //
00017 // You should have received a copy of the GNU General Public License along with
00018 // YAPET.  If not, see <http://www.gnu.org/licenses/>.
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                 // Bailout keys
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                 // Motion and other keys
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 }

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