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