ui/messagebox.cc

Go to the documentation of this file.
00001 // $Id: messagebox.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 "messagebox.h"
00021 #include "colors.h"
00022 
00023 using namespace YAPETUI;
00024 
00025 void
00026 MessageBox::createWindow() throw(UIException) {
00027     if (window != NULL)
00028     throw UIException("May you consider deleting the window before reallocating");
00029     if (okbutton != NULL)
00030     throw UIException("May you consider deleting the button before reallocating");
00031 
00032     window = newwin(BASE_HEIGHT,
00033             getWidth(),
00034             getStartY(),
00035             getStartX());
00036     if (window == NULL)
00037     throw UIException("Error creating message window");
00038 
00039     okbutton = new Button("Ok", getStartX() + 1, getStartY() + BASE_HEIGHT -2);
00040 }
00041 
00042 MessageBox::MessageBox(std::string t, std::string m) throw(UIException) : window(NULL),
00043                                       okbutton(NULL),
00044                                       title(t),
00045                                       message(m) {
00046     createWindow();
00047 }
00048 
00049 MessageBox::~MessageBox() {
00050     delete okbutton;
00051     wclear(window);
00052     delwin(window);
00053 }
00054 
00055 int
00056 MessageBox::run() throw(UIException) {
00057     refresh();
00058     int ch;
00059     while ( (ch = okbutton->focus()) == KEY_REFRESH )
00060     BaseWindow::refreshAll();
00061     return ch;
00062 }
00063 
00064 void
00065 MessageBox::resize() throw(UIException) {
00066     delete okbutton;
00067 
00068     int retval = delwin(window);
00069     if (retval == ERR)
00070     throw UIException("Error deleting message box");
00071 
00072     okbutton = NULL;
00073     window = NULL;
00074 
00075     createWindow();
00076 }
00077 
00078 void
00079 MessageBox::refresh() throw(UIException) {
00080     Colors::setcolor(window, MESSAGEBOX);
00081 
00082     int retval = werase(window);
00083     if (retval == ERR)
00084     throw UIException("Error erasing window");
00085 
00086     retval = box(window, 0, 0);
00087     if (retval == ERR)
00088     throw UIException("Error creating box around message window");
00089 
00090     Colors::setcolor(window, MESSAGEBOX);
00091     retval = mymvwaddstr(window, 2, 2, message.c_str());
00092     if (retval == ERR)
00093     throw UIException("Error printing message");
00094 
00095     // Title
00096     Colors::setcolor(window, MESSAGEBOX_TITLE);
00097     retval = mymvwaddstr(window, 0, 2, title.c_str());
00098     if (retval == ERR)
00099     throw UIException("Error printing title");
00100 
00101     Colors::setcolor(window, MESSAGEBOX);
00102     retval = wrefresh(window);
00103     if (retval == ERR)
00104     throw UIException("Error refreshing message box");
00105 
00106     okbutton->refresh();
00107 }

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