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 "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
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 }