ui/button.cc

Go to the documentation of this file.
00001 // $Id: button.cc,v 1.7 2008-02-13 00:20:23 rafi Exp $
00002 //
00003 // YAPET -- Yet Another Password Encryption Tool
00004 // Copyright (C) 2008  Rafael Ostertag
00005 //
00006 // This program is free software: you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation, either version 3 of the License, or
00009 // (at your option) any later version.
00010 //
00011 // This program is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU General Public License
00017 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018 //
00019 
00020 #include "button.h"
00021 #include "colors.h"
00022 #include "basewindow.h"
00023 
00024 using namespace YAPETUI;
00025 
00026 void
00027 Button::createWindow() throw(UIException) {
00028     window = newwin (1, BASE_SIZE + label.length(), start_y, start_x);
00029     if (window == NULL)
00030     throw UIException ("Error creating button");
00031 
00032     //refresh();
00033 }
00034 
00035 Button::Button (std::string l, int x, int y) : window (NULL),
00036     label (l),
00037     start_x (x),
00038     start_y (y) {
00039     createWindow();
00040 }
00041 
00042 Button::~Button() {
00043     wclear(window);
00044     delwin (window);
00045 }
00046 
00047 
00048 void
00049 Button::setLabel (std::string l) throw (UIException) {
00050     label = l;
00051     int retval = wclear (window);
00052     if (retval == ERR)
00053     throw UIException ("Error clearing button");
00054     retval = wrefresh (window);
00055     if (retval == ERR)
00056     throw UIException ("Error refreshing button");
00057     retval = delwin (window);
00058     if (retval == ERR)
00059     throw UIException ("Error deleting button");
00060 
00061 
00062 }
00063 
00064 void
00065 Button::refresh() throw (UIException) {
00066     Colors::setcolor(window, BUTTON_NOFOCUS);
00067     int retval = werase(window);
00068     if (retval == ERR)
00069     throw UIException ("Error erasing button");
00070 
00071     mvwprintw (window, 0, 0, "[ %s ]", label.c_str());
00072 
00073     retval = wrefresh (window);
00074     if (retval == ERR)
00075     throw UIException ("Error refreshing button");
00076 }
00077 
00078 int
00079 Button::focus() throw (UIException) {
00080     Colors::setcolor(window, BUTTON_FOCUS);
00081     mvwprintw (window, 0, 0, "[ %s ]", label.c_str());
00082 
00083     int retval = touchwin (window);
00084     if (retval == ERR)
00085     throw UIException ("Erro touching window");
00086 
00087     retval = wrefresh (window);
00088     if (retval == ERR)
00089     throw UIException ("Error refreshing button");
00090 
00091     retval = keypad (window, TRUE);
00092     if (retval == ERR)
00093     throw UIException ("Error setting keypad");
00094 
00095     int ch;
00096     while (true) {
00097     ch = wgetch (window);
00098 
00099     switch (ch) {
00100     case '\n':
00101     case KEY_ENTER:
00102         ch = '\n';
00103         onClick();
00104         goto BAILOUT;
00105         break;
00106     case '\t':
00107     case KEY_LEFT:
00108     case KEY_RIGHT:
00109     case KEY_UP:
00110     case KEY_DOWN:
00111         ch = '\t';
00112         goto BAILOUT;
00113         break;
00114     case KEY_REFRESH:
00115         BaseWindow::refreshAll();
00116         break;
00117 #ifdef HAVE_WRESIZE
00118     case KEY_RESIZE:
00119         goto BAILOUT;
00120         break;
00121 #endif // HAVE_WRESIZE
00122     }
00123     }
00124 
00125  BAILOUT:
00126     Colors::setcolor(window, BUTTON_NOFOCUS);
00127 
00128     mvwprintw (window, 0, 0, "[ %s ]", label.c_str());
00129 
00130 
00131     retval = touchwin (window);
00132     if (retval == ERR)
00133     throw UIException ("Erro touching window");
00134 
00135     retval = wrefresh (window);
00136     if (retval == ERR)
00137     throw UIException ("Error refreshing button");
00138 
00139     return ch;
00140 }

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