edelib  2.0.0
edelib/MessageBox.h
00001 /*
00002  * $Id: MessageBox.h 2839 2009-09-28 11:36:20Z karijes $
00003  *
00004  * Message dialog
00005  * Copyright (c) 2005-2007 edelib authors
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library. If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00021 #ifndef __EDELIB_MESSAGEBOX_H__
00022 #define __EDELIB_MESSAGEBOX_H__
00023 
00024 #include "edelib-global.h"
00025 
00026 #include <FL/Fl_Window.H>
00027 #include <FL/Fl_Button.H>
00028 #include <FL/Fl_Box.H>
00029 #include <FL/Fl_Input.H>
00030 #include <FL/Fl_Pixmap.H>
00031 
00032 #define MSGBOX_MAX_BUTTONS 4 // Max buttons in dialog
00033 
00034 #define MSGBOX_ICON_ERROR    "dialog-error"
00035 #define MSGBOX_ICON_INFO     "dialog-information"
00036 #define MSGBOX_ICON_PASSWORD "dialog-password"
00037 #define MSGBOX_ICON_WARNING  "dialog-warning"
00038 #define MSGBOX_ICON_QUESTION "dialog-question"
00039 
00040 EDELIB_NS_BEGIN
00041 
00047 enum MessageBoxType {
00048         MSGBOX_PLAIN = 0,             
00049         MSGBOX_INPUT,                 
00050         MSGBOX_INPUT_SECRET           
00051 };
00052 
00058 enum MessageBoxButtonType {
00059         MSGBOX_BUTTON_PLAIN = 0,      
00060         MSGBOX_BUTTON_RETURN          
00061 };
00062 
00068 enum MessageBoxIconType {
00069         MSGBOX_ICON_TYPE_INFO = 0,    
00070         MSGBOX_ICON_TYPE_ALERT,       
00071         MSGBOX_ICON_TYPE_QUESTION,    
00072         MSGBOX_ICON_TYPE_INPUT,       
00073         MSGBOX_ICON_TYPE_PASSWORD     
00074 };
00075 
00196 class EDELIB_API MessageBox : public Fl_Window {
00197 private:
00198         Fl_Box* img;
00199         Fl_Box* txt;
00200         Fl_Input* inpt;
00201         Fl_Group* gr;
00202         Fl_Pixmap* pix;
00203 
00204         MessageBoxType mbt;
00205 
00206         int nbuttons;
00207         int b_start;
00208         Fl_Button* buttons[MSGBOX_MAX_BUTTONS];
00209 
00210         void init(void);
00211         void fix_sizes(void);
00212 
00213         void add(Fl_Widget*) { } // in case someone tries to be too smart
00214 
00215 public:
00220         MessageBox(MessageBoxType t = MSGBOX_PLAIN);
00221 
00225         ~MessageBox();
00226 
00231         void set_text(const char* t);
00232 
00238         bool set_icon(const char* path);
00239 
00246         bool set_theme_icon(const char* name);
00247 
00251         void set_xpm_icon(const char* const* arr);
00252 
00257         void set_icon_from_type(MessageBoxIconType type);
00258 
00267         const char* get_input(void);
00268 
00272         void set_input(const char* txt);
00273 
00277         void focus_button(int b);
00278 
00284         void add_button(Fl_Button* b, MessageBoxButtonType bt = MSGBOX_BUTTON_PLAIN);
00285 
00293         void add_button(const char* l, MessageBoxButtonType bt = MSGBOX_BUTTON_PLAIN, Fl_Callback cb = 0, void* param = 0);
00294 
00299         void clear(MessageBoxType t = MSGBOX_PLAIN);
00300 
00305         void run_plain(bool center = true);
00306 
00314         int run(bool center = true);
00315 
00324         static void set_themed_icons(const char* msg, const char* alert = 0, const char* ask = 0, 
00325                         const char* input = 0, const char* password = 0);
00326 
00328         static void clear_themed_icons(void);
00329 };
00330 
00341 EDELIB_API void themed_dialog_icons(const char* msg, const char* alert = 0, 
00342         const char* ask = 0, const char* input = 0, const char* password = 0) EDELIB_DEPRECATED;
00343 
00349 EDELIB_API void clear_dialog_icons(void) EDELIB_DEPRECATED;
00350 
00355 EDELIB_API void message(const char* fmt, ...);
00356 
00361 EDELIB_API void alert(const char* fmt, ...);
00362 
00368 EDELIB_API int ask(const char* fmt, ...);
00369 
00380 EDELIB_API const char* input(const char* fmt, const char* deflt = 0, ...);
00381 
00386 EDELIB_API const char* password(const char* fmt, const char* deflt = 0, ...);
00387 
00388 #ifndef SKIP_DOCS
00389 /*
00390  * FLTK compatibility
00391  */
00392 extern void (*fl_message)(const char* fmt, ...);
00393 extern void (*fl_alert)(const char* fmt, ...);
00394 extern int  (*fl_ask)(const char* fmt, ...);
00395 extern const char* (*fl_input)(const char* fmt, const char* deflt, ...);
00396 extern const char* (*fl_password)(const char* fmt, const char* deflt, ...);
00397 #endif
00398 
00399 EDELIB_NS_END
00400 #endif