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
24 #include <gtk/gtkmain.h>
25 #include <gtk/gtkalignment.h>
26 #include <gtk/gtkhbox.h>
27 #include <gtk/gtkvbox.h>
28 #include <gtk/gtkradiobutton.h>
29 #include <gtk/gtkframe.h>
30 #include <gtk/gtktable.h>
31 #include <gtk/gtkentry.h>
32 #include <gtk/gtkbutton.h>
33 #include <gtk/gtklabel.h>
38 GtkVBox* create_dialog_vbox( int spacing, int border ){
39 GtkVBox* vbox = ui::VBox( FALSE, spacing );
40 gtk_widget_show( GTK_WIDGET( vbox ) );
41 gtk_container_set_border_width( GTK_CONTAINER( vbox ), border );
45 GtkHBox* create_dialog_hbox( int spacing, int border ){
46 GtkHBox* hbox = ui::HBox( FALSE, spacing );
47 gtk_widget_show( GTK_WIDGET( hbox ) );
48 gtk_container_set_border_width( GTK_CONTAINER( hbox ), border );
52 GtkFrame* create_dialog_frame( const char* label, GtkShadowType shadow ){
53 GtkFrame* frame = GTK_FRAME( gtk_frame_new( label ) );
54 gtk_widget_show( GTK_WIDGET( frame ) );
55 gtk_frame_set_shadow_type( frame, shadow );
59 GtkTable* create_dialog_table( unsigned int rows, unsigned int columns, unsigned int row_spacing, unsigned int col_spacing, int border ){
60 GtkTable* table = ui::Table( rows, columns, FALSE );
61 gtk_widget_show( GTK_WIDGET( table ) );
62 gtk_table_set_row_spacings( table, row_spacing );
63 gtk_table_set_col_spacings( table, col_spacing );
64 gtk_container_set_border_width( GTK_CONTAINER( table ), border );
68 GtkButton* create_dialog_button( const char* label, GCallback func, gpointer data ){
69 GtkButton* button = ui::Button( label );
70 gtk_widget_set_size_request( GTK_WIDGET( button ), 64, -1 );
71 gtk_widget_show( GTK_WIDGET( button ) );
72 g_signal_connect( G_OBJECT( button ), "clicked", func, data );
76 GtkWindow* create_dialog_window( GtkWindow* parent, const char* title, GCallback func, gpointer data, int default_w, int default_h ){
77 GtkWindow* window = create_floating_window( title, parent );
78 gtk_window_set_default_size( window, default_w, default_h );
79 gtk_window_set_position( window, GTK_WIN_POS_CENTER_ON_PARENT );
80 g_signal_connect( G_OBJECT( window ), "delete_event", func, data );
85 gboolean modal_dialog_button_clicked( GtkWidget *widget, ModalDialogButton* button ){
86 button->m_dialog.loop = false;
87 button->m_dialog.ret = button->m_value;
91 gboolean modal_dialog_delete( GtkWidget *widget, GdkEvent* event, ModalDialog* dialog ){
93 dialog->ret = eIDCANCEL;
97 EMessageBoxReturn modal_dialog_show( GtkWindow* window, ModalDialog& dialog ){
98 gtk_grab_add( GTK_WIDGET( window ) );
99 gtk_widget_show( GTK_WIDGET( window ) );
102 while ( dialog.loop )
104 gtk_main_iteration();
107 gtk_widget_hide( GTK_WIDGET( window ) );
108 gtk_grab_remove( GTK_WIDGET( window ) );
113 GtkButton* create_modal_dialog_button( const char* label, ModalDialogButton& button ){
114 return create_dialog_button( label, G_CALLBACK( modal_dialog_button_clicked ), &button );
117 GtkWindow* create_modal_dialog_window( GtkWindow* parent, const char* title, ModalDialog& dialog, int default_w, int default_h ){
118 return create_dialog_window( parent, title, G_CALLBACK( modal_dialog_delete ), &dialog, default_w, default_h );
121 GtkWindow* create_fixedsize_modal_dialog_window( GtkWindow* parent, const char* title, ModalDialog& dialog, int width, int height ){
122 GtkWindow* window = create_modal_dialog_window( parent, title, dialog, width, height );
124 gtk_window_set_resizable( window, FALSE );
125 gtk_window_set_modal( window, TRUE );
126 gtk_window_set_position( window, GTK_WIN_POS_CENTER );
128 window_remove_minmax( window );
130 //gtk_widget_set_size_request(GTK_WIDGET(window), width, height);
131 //gtk_window_set_default_size(window, width, height);
132 //gtk_window_resize(window, width, height);
133 //GdkGeometry geometry = { width, height, -1, -1, width, height, -1, -1, -1, -1, GDK_GRAVITY_STATIC, };
134 //gtk_window_set_geometry_hints(window, GTK_WIDGET(window), &geometry, (GdkWindowHints)(GDK_HINT_POS|GDK_HINT_MIN_SIZE|GDK_HINT_BASE_SIZE));
139 gboolean dialog_button_ok( GtkWidget *widget, ModalDialog* data ){
145 gboolean dialog_button_cancel( GtkWidget *widget, ModalDialog* data ){
147 data->ret = eIDCANCEL;
151 gboolean dialog_button_yes( GtkWidget *widget, ModalDialog* data ){
157 gboolean dialog_button_no( GtkWidget *widget, ModalDialog* data ){
163 gboolean dialog_delete_callback( GtkWidget *widget, GdkEventAny* event, ModalDialog* data ){
164 gtk_widget_hide( widget );
169 GtkWindow* create_simple_modal_dialog_window( const char* title, ModalDialog& dialog, GtkWidget* contents ){
170 GtkWindow* window = create_fixedsize_modal_dialog_window( 0, title, dialog );
172 GtkVBox* vbox1 = create_dialog_vbox( 8, 4 );
173 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( vbox1 ) );
175 gtk_container_add( GTK_CONTAINER( vbox1 ), contents );
177 ui::Alignment alignment = ui::Alignment( 0.5, 0.0, 0.0, 0.0 );
178 gtk_widget_show( GTK_WIDGET( alignment ) );
179 gtk_box_pack_start( GTK_BOX( vbox1 ), GTK_WIDGET( alignment ), FALSE, FALSE, 0 );
181 GtkButton* button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
182 gtk_container_add( GTK_CONTAINER( alignment ), GTK_WIDGET( button ) );
187 RadioHBox RadioHBox_new( StringArrayRange names ){
188 GtkHBox* hbox = ui::HBox( TRUE, 4 );
189 gtk_widget_show( GTK_WIDGET( hbox ) );
192 GtkRadioButton* radio = 0;
193 for ( StringArrayRange::Iterator i = names.first; i != names.last; ++i )
195 radio = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( group, *i ) );
196 gtk_widget_show( GTK_WIDGET( radio ) );
197 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( radio ), FALSE, FALSE, 0 );
199 group = gtk_radio_button_get_group( radio );
202 return RadioHBox( hbox, radio );
206 PathEntry PathEntry_new(){
207 GtkFrame* frame = GTK_FRAME( gtk_frame_new( NULL ) );
208 gtk_widget_show( GTK_WIDGET( frame ) );
209 gtk_frame_set_shadow_type( frame, GTK_SHADOW_IN );
212 GtkHBox* hbox = ui::HBox( FALSE, 0 );
213 gtk_widget_show( GTK_WIDGET( hbox ) );
215 GtkEntry* entry = ui::Entry();
216 gtk_entry_set_has_frame( entry, FALSE );
217 gtk_widget_show( GTK_WIDGET( entry ) );
218 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( entry ), TRUE, TRUE, 0 );
221 GtkButton* button = ui::Button();
222 button_set_icon( button, "ellipsis.bmp" );
223 gtk_widget_show( GTK_WIDGET( button ) );
224 gtk_box_pack_end( GTK_BOX( hbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
226 gtk_container_add( GTK_CONTAINER( frame ), GTK_WIDGET( hbox ) );
228 return PathEntry( frame, entry, button );
231 void PathEntry_setPath( PathEntry& self, const char* path ){
232 gtk_entry_set_text( self.m_entry, path );
234 typedef ReferenceCaller1<PathEntry, const char*, PathEntry_setPath> PathEntrySetPathCaller;
236 void BrowsedPathEntry_clicked( GtkWidget* widget, BrowsedPathEntry* self ){
237 self->m_browse( PathEntrySetPathCaller( self->m_entry ) );
240 BrowsedPathEntry::BrowsedPathEntry( const BrowseCallback& browse ) :
241 m_entry( PathEntry_new() ),
243 g_signal_connect( G_OBJECT( m_entry.m_button ), "clicked", G_CALLBACK( BrowsedPathEntry_clicked ), this );
247 GtkLabel* DialogLabel_new( const char* name ){
248 ui::Label label = ui::Label( name );
249 gtk_widget_show(label);
250 gtk_misc_set_alignment( GTK_MISC( label ), 1, 0.5 );
251 gtk_label_set_justify( label, GTK_JUSTIFY_LEFT );
256 GtkTable* DialogRow_new( const char* name, GtkWidget* widget ){
257 GtkTable* table = ui::Table( 1, 3, TRUE );
258 gtk_widget_show( GTK_WIDGET( table ) );
260 gtk_table_set_col_spacings( table, 4 );
261 gtk_table_set_row_spacings( table, 0 );
263 gtk_table_attach( table, GTK_WIDGET( DialogLabel_new( name ) ), 0, 1, 0, 1,
264 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
265 (GtkAttachOptions) ( 0 ), 0, 0 );
267 gtk_table_attach( table, widget, 1, 3, 0, 1,
268 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
269 (GtkAttachOptions) ( 0 ), 0, 0 );
274 void DialogVBox_packRow( GtkVBox* vbox, GtkWidget* row ){
275 gtk_box_pack_start( GTK_BOX( vbox ), row, FALSE, FALSE, 0 );