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