00001 // $Id: dialogbox.cc 2359 2009-06-11 15:06:07Z rafi $ 00002 // 00003 // Copyright (C) 2008, 2009 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 "dialogbox.h" 00023 00024 using namespace YAPETUI; 00025 00026 DialogBox::DialogBox(std::string t, std::string m) 00027 throw(UIException) : MessageBox(t, m), 00028 cancelbutton(NULL), 00029 answer(ANSWER_CANCEL) { 00030 cancelbutton = new Button(_("Cancel"), 00031 getStartX() + 2 + getOkButtonLength(), 00032 getStartY() + getBaseHeight() -2); 00033 } 00034 00035 DialogBox::~DialogBox() { 00036 delete cancelbutton; 00037 } 00038 00039 int 00040 DialogBox::run() throw(UIException) { 00041 refresh(); 00042 while (true) { 00043 #ifdef HAVE_WRESIZE 00044 int ch; 00045 while ( (ch = MessageBox::run()) == KEY_RESIZE ) 00046 BaseWindow::resizeAll(); 00047 #else // HAVE_RESIZE 00048 int ch = MessageBox::run(); 00049 #endif // HAVE_RESIZE 00050 if (ch == '\n') { 00051 answer = ANSWER_OK; 00052 return ch; 00053 } 00054 00055 #ifdef HAVE_WRESIZE 00056 while ( (ch = cancelbutton->focus()) == KEY_RESIZE ) 00057 BaseWindow::resizeAll(); 00058 #else // HAVE_RESIZE 00059 ch = cancelbutton->focus(); 00060 #endif // HAVE_RESIZE 00061 if (ch == '\n') { 00062 answer = ANSWER_CANCEL; 00063 return ch; 00064 } 00065 } 00066 } 00067 00068 void 00069 DialogBox::resize() throw(UIException) { 00070 MessageBox::resize(); 00071 delete cancelbutton; 00072 cancelbutton = new Button(_("Cancel"), getStartX() + 2 + getOkButtonLength(), getStartY() + getBaseHeight() -2); 00073 } 00074 00075 void 00076 DialogBox::refresh() throw(UIException) { 00077 MessageBox::refresh(); 00078 cancelbutton->refresh(); 00079 }