00001 // $Id: dialogbox.cc 3342 2010-09-17 18:32:00Z java $ 00002 // 00003 // Copyright (C) 2008-2010 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 YAPET::UI; 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 00043 while (true) { 00044 #ifdef HAVE_WRESIZE 00045 int ch; 00046 00047 while ( (ch = MessageBox::run() ) == KEY_RESIZE ) 00048 BaseWindow::resizeAll(); 00049 00050 #else // HAVE_RESIZE 00051 int ch = MessageBox::run(); 00052 #endif // HAVE_RESIZE 00053 00054 switch (ch) { 00055 case '\n': 00056 answer = ANSWER_OK; 00057 return ch; 00058 case KEY_ESC: 00059 answer = ANSWER_CANCEL; 00060 return ch; 00061 } 00062 00063 #ifdef HAVE_WRESIZE 00064 00065 while ( (ch = cancelbutton->focus() ) == KEY_RESIZE ) 00066 BaseWindow::resizeAll(); 00067 00068 #else // HAVE_RESIZE 00069 ch = cancelbutton->focus(); 00070 #endif // HAVE_RESIZE 00071 00072 if (ch == '\n' || ch == KEY_ESC) { 00073 answer = ANSWER_CANCEL; 00074 return ch; 00075 } 00076 } 00077 } 00078 00079 void 00080 DialogBox::resize() throw (UIException) { 00081 MessageBox::resize(); 00082 delete cancelbutton; 00083 cancelbutton = new Button (_ ("Cancel"), getStartX() + 2 + getOkButtonLength(), getStartY() + getBaseHeight() - 2); 00084 } 00085 00086 void 00087 DialogBox::refresh() throw (UIException) { 00088 MessageBox::refresh(); 00089 cancelbutton->refresh(); 00090 }
1.7.1