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