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

ui/messagebox.cc

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

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