00001 // $Id: dialogbox.cc 2293 2009-04-11 16:01:50Z rafi $ 00002 // 00003 // YAPET -- Yet Another Password Encryption Tool 00004 // Copyright (C) 2008 Rafael Ostertag 00005 // 00006 // This program is free software: you can redistribute it and/or modify 00007 // it under the terms of the GNU General Public License as published by 00008 // the Free Software Foundation, either version 3 of the License, or 00009 // (at your option) any later version. 00010 // 00011 // This program is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU General Public License 00017 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 // 00019 00020 #include "../intl.h" 00021 #include "dialogbox.h" 00022 00023 using namespace YAPETUI; 00024 00025 DialogBox::DialogBox(std::string t, std::string m) 00026 throw(UIException) : MessageBox(t, m), 00027 cancelbutton(NULL), 00028 answer(ANSWER_CANCEL) { 00029 cancelbutton = new Button(_("Cancel"), 00030 getStartX() + 2 + getOkButtonLength(), 00031 getStartY() + getBaseHeight() -2); 00032 } 00033 00034 DialogBox::~DialogBox() { 00035 delete cancelbutton; 00036 } 00037 00038 int 00039 DialogBox::run() throw(UIException) { 00040 refresh(); 00041 while (true) { 00042 #ifdef HAVE_WRESIZE 00043 int ch; 00044 while ( (ch = MessageBox::run()) == KEY_RESIZE ) 00045 BaseWindow::resizeAll(); 00046 #else // HAVE_RESIZE 00047 int ch = MessageBox::run(); 00048 #endif // HAVE_RESIZE 00049 if (ch == '\n') { 00050 answer = ANSWER_OK; 00051 return ch; 00052 } 00053 00054 #ifdef HAVE_WRESIZE 00055 while ( (ch = cancelbutton->focus()) == KEY_RESIZE ) 00056 BaseWindow::resizeAll(); 00057 #else // HAVE_RESIZE 00058 ch = cancelbutton->focus(); 00059 #endif // HAVE_RESIZE 00060 if (ch == '\n') { 00061 answer = ANSWER_CANCEL; 00062 return ch; 00063 } 00064 } 00065 } 00066 00067 void 00068 DialogBox::resize() throw(UIException) { 00069 MessageBox::resize(); 00070 delete cancelbutton; 00071 cancelbutton = new Button(_("Cancel"), getStartX() + 2 + getOkButtonLength(), getStartY() + getBaseHeight() -2); 00072 } 00073 00074 void 00075 DialogBox::refresh() throw(UIException) { 00076 MessageBox::refresh(); 00077 cancelbutton->refresh(); 00078 }