00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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 }