1 /***************************************************************************
2 messagebox.c - description
4 begin : Tue Nov 12 2002
5 copyright : (C) 2002 by blight
6 email : blight@Ashitaka
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
18 #include "messagebox.h"
27 #include "icons/messagebox-error.xpm"
28 #include "icons/messagebox-info.xpm"
29 #include "icons/messagebox-quest.xpm"
30 #include "icons/messagebox-warn.xpm"
32 static gint
delete_question_event(GtkWidget
*widget
, GdkEvent
*event
, gpointer data
)
34 return TRUE
; // undeleteable
38 button1_clicked( GtkWidget
*widget
, gpointer data
)
40 int *ret
= (int *)data
;
46 button2_clicked( GtkWidget
*widget
, gpointer data
)
48 int *ret
= (int *)data
;
54 button3_clicked( GtkWidget
*widget
, gpointer data
)
56 int *ret
= (int *)data
;
62 messagebox( const char *title
, int flags
, const char *fmt
, ... )
70 GtkWidget
*icon
= NULL
;
72 GtkWidget
*button1
, *button2
= NULL
, *button3
= NULL
;
75 vsnprintf( buf
, 2048, fmt
, ap
);
79 switch( flags
& 0x000000FF )
81 case MB_ABORTRETRYIGNORE
:
82 button1
= gtk_button_new_with_label( "Abort" );
83 button2
= gtk_button_new_with_label( "Retry" );
84 button3
= gtk_button_new_with_label( "Ignore" );
87 case MB_CANCELTRYCONTINUE
:
88 button1
= gtk_button_new_with_label( "Cancel" );
89 button2
= gtk_button_new_with_label( "Retry" );
90 button3
= gtk_button_new_with_label( "Continue" );
94 button1
= gtk_button_new_with_label( "Ok" );
95 button2
= gtk_button_new_with_label( "Cancel" );
99 button1
= gtk_button_new_with_label( "Retry" );
100 button2
= gtk_button_new_with_label( "Cancel" );
104 button1
= gtk_button_new_with_label( "Yes" );
105 button2
= gtk_button_new_with_label( "No" );
109 button1
= gtk_button_new_with_label( "Yes" );
110 button2
= gtk_button_new_with_label( "No" );
111 button3
= gtk_button_new_with_label( "Cancel" );
116 button1
= gtk_button_new_with_label( "Ok" );
119 dialog
= gtk_dialog_new();
120 gtk_container_set_border_width( GTK_CONTAINER(dialog
), 10 );
121 gtk_window_set_title( GTK_WINDOW(dialog
), title
);
122 gtk_window_set_policy( GTK_WINDOW(dialog
), 0, 0, 0 );
123 gtk_signal_connect(GTK_OBJECT(dialog
), "delete_event",
124 GTK_SIGNAL_FUNC(delete_question_event
), (gpointer
)NULL
);
126 hbox
= gtk_hbox_new( FALSE
, 5 );
127 gtk_box_pack_start( GTK_BOX(GTK_DIALOG(dialog
)->vbox
), hbox
, TRUE
, TRUE
, 0 );
128 gtk_widget_show( hbox
);
131 switch( flags
& 0x00000F00 )
134 icon
= create_pixmap_d( dialog
, messagebox_warn_xpm
);
137 case MB_ICONINFORMATION
:
138 icon
= create_pixmap_d( dialog
, messagebox_info_xpm
);
141 case MB_ICONQUESTION
:
142 icon
= create_pixmap_d( dialog
, messagebox_quest_xpm
);
146 icon
= create_pixmap_d( dialog
, messagebox_error_xpm
);
152 gtk_box_pack_start( GTK_BOX(hbox
), icon
, FALSE
, FALSE
, 0 );
153 gtk_widget_show( icon
);
156 label
= gtk_label_new( buf
);
157 gtk_box_pack_start( GTK_BOX(hbox
), label
, TRUE
, TRUE
, 0 );
158 gtk_widget_show( label
);
162 gtk_box_pack_start( GTK_BOX(GTK_DIALOG(dialog
)->action_area
), button1
, TRUE
, TRUE
, 0 );
163 gtk_widget_show( button1
);
164 gtk_signal_connect( GTK_OBJECT(button1
), "clicked",
165 GTK_SIGNAL_FUNC(button1_clicked
), (gpointer
)&ret
);
170 gtk_box_pack_start( GTK_BOX(GTK_DIALOG(dialog
)->action_area
), button2
, TRUE
, TRUE
, 0 );
171 gtk_widget_show( button2
);
172 gtk_signal_connect( GTK_OBJECT(button2
), "clicked",
173 GTK_SIGNAL_FUNC(button2_clicked
), (gpointer
)&ret
);
177 gtk_box_pack_start( GTK_BOX(GTK_DIALOG(dialog
)->action_area
), button3
, TRUE
, TRUE
, 0 );
178 gtk_widget_show( button3
);
179 gtk_signal_connect( GTK_OBJECT(button3
), "clicked",
180 GTK_SIGNAL_FUNC(button3_clicked
), (gpointer
)&ret
);
183 gtk_widget_show( dialog
);
186 if( gtk_main_iteration() )
189 gtk_widget_destroy( dialog
);