00001 // -*- c++ -*- 00002 // 00003 // $Id: messagebox.h 2359 2009-06-11 15:06:07Z rafi $ 00004 // 00005 // Copyright (C) 2008, 2009 Rafael Ostertag 00006 // 00007 // This file is part of YAPET. 00008 // 00009 // YAPET is free software: you can redistribute it and/or modify it under the 00010 // terms of the GNU General Public License as published by the Free Software 00011 // Foundation, either version 3 of the License, or (at your option) any later 00012 // version. 00013 // 00014 // YAPET is distributed in the hope that it will be useful, but WITHOUT ANY 00015 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00016 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00017 // details. 00018 // 00019 // You should have received a copy of the GNU General Public License along with 00020 // YAPET. If not, see <http://www.gnu.org/licenses/>. 00021 // 00022 00023 #ifndef _MESSAGEBOX_H 00024 #define _MESSAGEBOX_H 00025 00026 #ifdef HAVE_CONFIG_H 00027 # include <config.h> 00028 #endif 00029 00030 #ifdef HAVE_NCURSES_H 00031 # include <ncurses.h> 00032 #else // HAVE_NCURSES_H 00033 # ifdef HAVE_CURSES_H 00034 # include <curses.h> 00035 # else 00036 # error "Neither curses.h nor ncurses.h available" 00037 # endif // HAVE_CURSES_H 00038 #endif // HAVE_NCURSES_H 00039 #include "curswa.h" // Leave this here. It depends on the above includes. 00040 00041 #ifdef HAVE_STRING 00042 # include <string> 00043 #endif 00044 00045 #include "uiexception.h" 00046 #include "basewindow.h" 00047 #include "button.h" 00048 00049 namespace YAPETUI { 00059 class MessageBox : protected BaseWindow { 00060 private: 00061 enum { 00062 BASE_HEIGHT=6, 00063 BASE_WIDTH=4 00064 }; 00065 WINDOW* window; 00066 Button* okbutton; 00067 00068 std::string title; 00069 std::string message; 00070 00071 void createWindow() throw(UIException); 00072 00073 protected: 00074 inline int getBaseHeight() const { return BASE_HEIGHT; } 00075 00076 inline int getWidth() const { 00077 return BASE_WIDTH + message.length(); 00078 } 00079 00080 inline int getStartX() const { 00081 return maxX()/2 - getWidth()/2; 00082 } 00083 00084 inline int getStartY() const { 00085 return maxY()/2 - BASE_HEIGHT/2; 00086 } 00087 00088 inline int getOkButtonLength() const { 00089 if (okbutton == NULL) return -1; 00090 return okbutton->getLength(); 00091 } 00092 00093 public: 00094 MessageBox(std::string t, std::string m) throw(UIException); 00095 virtual ~MessageBox(); 00096 00097 virtual int run() throw(UIException) ; 00098 virtual void resize() throw(UIException); 00099 virtual void refresh() throw(UIException); 00100 }; 00101 00102 } 00103 00104 #endif // _MESSAGEBOX_H