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