2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "messagebox.h"
24 #include <gdk/gdkkeysyms.h>
30 ui::Widget create_padding( int width, int height ){
31 ui::Alignment widget = ui::Alignment( 0.0, 0.0, 0.0, 0.0 );
33 widget.dimensions(width, height);
37 const char* messagebox_stock_icon( EMessageBoxIcon type ){
42 return GTK_STOCK_DIALOG_INFO;
44 return GTK_STOCK_DIALOG_ERROR;
46 return GTK_STOCK_DIALOG_WARNING;
47 case eMB_ICONQUESTION:
48 return GTK_STOCK_DIALOG_QUESTION;
49 case eMB_ICONASTERISK:
50 return GTK_STOCK_DIALOG_INFO;
54 EMessageBoxReturn gtk_MessageBox( ui::Window parentWindow, const char* text, const char* title, EMessageBoxType type, EMessageBoxIcon icon ){
56 ModalDialogButton ok_button( dialog, eIDOK );
57 ModalDialogButton cancel_button( dialog, eIDCANCEL );
58 ModalDialogButton yes_button( dialog, eIDYES );
59 ModalDialogButton no_button( dialog, eIDNO );
61 ui::Window window = create_fixedsize_modal_dialog_window( parentWindow, title, dialog, 400, 100 );
64 //window.connect( "delete_event", G_CALLBACK(floating_window_delete_present), parent);
65 gtk_window_deiconify( parentWindow );
68 auto accel = ui::AccelGroup(ui::New);
69 window.add_accel_group( accel );
71 auto vbox = create_dialog_vbox( 8, 8 );
75 auto hboxDummy = create_dialog_hbox( 0, 0 );
76 vbox.pack_start( hboxDummy, FALSE, FALSE, 0 );
78 hboxDummy.pack_start( create_padding( 0, 50 ), FALSE, FALSE, 0 ); // HACK to force minimum height
80 auto iconBox = create_dialog_hbox( 16, 0 );
81 hboxDummy.pack_start( iconBox, FALSE, FALSE, 0 );
83 auto image = ui::Image::from( gtk_image_new_from_stock( messagebox_stock_icon( icon ), GTK_ICON_SIZE_DIALOG ) );
85 iconBox.pack_start( image, FALSE, FALSE, 0 );
87 auto label = ui::Label( text );
89 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
90 gtk_label_set_justify( label, GTK_JUSTIFY_LEFT );
91 gtk_label_set_line_wrap( label, TRUE );
92 iconBox.pack_start( label, TRUE, TRUE, 0 );
95 auto vboxDummy = create_dialog_vbox( 0, 0 );
96 vbox.pack_start( vboxDummy, FALSE, FALSE, 0 );
98 auto alignment = ui::Alignment( 0.5, 0.0, 0.0, 0.0 );
100 vboxDummy.pack_start( alignment, FALSE, FALSE, 0 );
102 auto hbox = create_dialog_hbox( 8, 0 );
105 vboxDummy.pack_start( create_padding( 400, 0 ), FALSE, FALSE, 0 ); // HACK to force minimum width
108 if ( type == eMB_OK ) {
109 auto button = create_modal_dialog_button( "OK", ok_button );
110 hbox.pack_start( button, TRUE, FALSE, 0 );
111 gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
112 gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
113 widget_make_default( button );
118 else if ( type == eMB_OKCANCEL ) {
120 auto button = create_modal_dialog_button( "OK", ok_button );
121 hbox.pack_start( button, TRUE, FALSE, 0 );
122 gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
123 widget_make_default( button );
128 auto button = create_modal_dialog_button( "OK", cancel_button );
129 hbox.pack_start( button, TRUE, FALSE, 0 );
130 gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
134 dialog.ret = eIDCANCEL;
136 else if ( type == eMB_YESNOCANCEL ) {
138 auto button = create_modal_dialog_button( "Yes", yes_button );
139 hbox.pack_start( button, TRUE, FALSE, 0 );
140 widget_make_default( button );
145 auto button = create_modal_dialog_button( "No", no_button );
146 hbox.pack_start( button, TRUE, FALSE, 0 );
150 auto button = create_modal_dialog_button( "Cancel", cancel_button );
151 hbox.pack_start( button, TRUE, FALSE, 0 );
155 dialog.ret = eIDCANCEL;
157 else if ( type == eMB_NOYES ) {
159 auto button = create_modal_dialog_button( "No", no_button );
160 hbox.pack_start( button, TRUE, FALSE, 0 );
161 widget_make_default( button );
165 auto button = create_modal_dialog_button( "Yes", yes_button );
166 hbox.pack_start( button, TRUE, FALSE, 0 );
172 else /* if (type == eMB_YESNO) */
175 auto button = create_modal_dialog_button( "Yes", yes_button );
176 hbox.pack_start( button, TRUE, FALSE, 0 );
177 widget_make_default( button );
182 auto button = create_modal_dialog_button( "No", no_button );
183 hbox.pack_start( button, TRUE, FALSE, 0 );
189 modal_dialog_show( window, dialog );