2 PrtView plugin for GtkRadiant
3 Copyright (C) 2001 Geoffrey Dewan, Loki software and qeradiant.com
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // LoadPortalFileDialog.cpp : implementation file
23 #include "LoadPortalFileDialog.h"
26 #include <gtkutil/pointer.h>
27 #include "stream/stringstream.h"
29 #include "gtkutil/pointer.h"
31 #include "qerplugin.h"
36 static void dialog_button_callback( GtkWidget *widget, gpointer data ){
40 parent = gtk_widget_get_toplevel( widget );
41 loop = (int*)g_object_get_data( G_OBJECT( parent ), "loop" );
42 ret = (int*)g_object_get_data( G_OBJECT( parent ), "ret" );
45 *ret = gpointer_to_int( data );
48 static gint dialog_delete_callback( GtkWidget *widget, GdkEvent* event, gpointer data ){
51 gtk_widget_hide( widget );
52 loop = (int*)g_object_get_data( G_OBJECT( widget ), "loop" );
58 static void file_sel_callback( GtkWidget *widget, gpointer data ){
63 parent = gtk_widget_get_toplevel( widget );
64 loop = (int*)g_object_get_data( G_OBJECT( parent ), "loop" );
65 filename = (char**)g_object_get_data( G_OBJECT( parent ), "filename" );
68 if ( gpointer_to_int( data ) == IDOK ) {
69 *filename = g_strdup( gtk_file_selection_get_filename( GTK_FILE_SELECTION( parent ) ) );
73 static void change_clicked( GtkWidget *widget, gpointer data ){
75 char* filename = NULL;
78 file_sel = gtk_file_selection_new( "Locate portal (.prt) file" );
79 gtk_signal_connect( GTK_OBJECT( GTK_FILE_SELECTION( file_sel )->ok_button ), "clicked",
80 GTK_SIGNAL_FUNC( file_sel_callback ), GINT_TO_POINTER( IDOK ) );
81 gtk_signal_connect( GTK_OBJECT( GTK_FILE_SELECTION( file_sel )->cancel_button ), "clicked",
82 GTK_SIGNAL_FUNC( file_sel_callback ), GINT_TO_POINTER( IDCANCEL ) );
83 gtk_signal_connect( GTK_OBJECT( file_sel ), "delete_event",
84 GTK_SIGNAL_FUNC( dialog_delete_callback ), NULL );
85 gtk_file_selection_hide_fileop_buttons( GTK_FILE_SELECTION( file_sel ) );
87 g_object_set_data( G_OBJECT( file_sel ), "loop", &loop );
88 g_object_set_data( G_OBJECT( file_sel ), "filename", &filename );
89 gtk_file_selection_set_filename( GTK_FILE_SELECTION( file_sel ), portals.fn );
91 gtk_grab_add( file_sel );
92 gtk_widget_show( file_sel );
97 gtk_grab_remove( file_sel );
98 gtk_widget_destroy( file_sel );
100 if ( filename != NULL ) {
101 strcpy( portals.fn, filename );
102 gtk_entry_set_text( GTK_ENTRY( data ), filename );
107 int DoLoadPortalFileDialog(){
108 GtkWidget *dlg, *vbox, *hbox, *button, *entry, *check2d, *check3d;
109 int loop = 1, ret = IDCANCEL;
111 dlg = gtk_window_new( GTK_WINDOW_TOPLEVEL );
112 gtk_window_set_title( GTK_WINDOW( dlg ), "Load .prt" );
113 gtk_signal_connect( GTK_OBJECT( dlg ), "delete_event",
114 GTK_SIGNAL_FUNC( dialog_delete_callback ), NULL );
115 gtk_signal_connect( GTK_OBJECT( dlg ), "destroy",
116 GTK_SIGNAL_FUNC( gtk_widget_destroy ), NULL );
117 g_object_set_data( G_OBJECT( dlg ), "loop", &loop );
118 g_object_set_data( G_OBJECT( dlg ), "ret", &ret );
120 vbox = gtk_vbox_new( FALSE, 5 );
121 gtk_widget_show( vbox );
122 gtk_container_add( GTK_CONTAINER( dlg ), vbox );
123 gtk_container_set_border_width( GTK_CONTAINER( vbox ), 5 );
125 entry = gtk_entry_new();
126 gtk_widget_show( entry );
127 gtk_entry_set_editable( GTK_ENTRY( entry ), FALSE );
128 gtk_box_pack_start( GTK_BOX( vbox ), entry, FALSE, FALSE, 0 );
130 hbox = gtk_hbox_new( FALSE, 5 );
131 gtk_widget_show( hbox );
132 gtk_box_pack_start( GTK_BOX( vbox ), hbox, FALSE, FALSE, 0 );
134 check3d = gtk_check_button_new_with_label( "Show 3D" );
135 gtk_widget_show( check3d );
136 gtk_box_pack_start( GTK_BOX( hbox ), check3d, FALSE, FALSE, 0 );
138 check2d = gtk_check_button_new_with_label( "Show 2D" );
139 gtk_widget_show( check2d );
140 gtk_box_pack_start( GTK_BOX( hbox ), check2d, FALSE, FALSE, 0 );
142 button = gtk_button_new_with_label( "Change" );
143 gtk_widget_show( button );
144 gtk_box_pack_end( GTK_BOX( hbox ), button, FALSE, FALSE, 0 );
145 gtk_signal_connect( GTK_OBJECT( button ), "clicked", GTK_SIGNAL_FUNC( change_clicked ), entry );
146 gtk_widget_set_usize( button, 60, -2 );
148 hbox = gtk_hbox_new( FALSE, 5 );
149 gtk_widget_show( hbox );
150 gtk_box_pack_start( GTK_BOX( vbox ), hbox, FALSE, FALSE, 0 );
152 button = gtk_button_new_with_label( "Cancel" );
153 gtk_widget_show( button );
154 gtk_box_pack_end( GTK_BOX( hbox ), button, FALSE, FALSE, 0 );
155 gtk_signal_connect( GTK_OBJECT( button ), "clicked",
156 GTK_SIGNAL_FUNC( dialog_button_callback ), GINT_TO_POINTER( IDCANCEL ) );
157 gtk_widget_set_usize( button, 60, -2 );
159 button = gtk_button_new_with_label( "OK" );
160 gtk_widget_show( button );
161 gtk_box_pack_end( GTK_BOX( hbox ), button, FALSE, FALSE, 0 );
162 gtk_signal_connect( GTK_OBJECT( button ), "clicked",
163 GTK_SIGNAL_FUNC( dialog_button_callback ), GINT_TO_POINTER( IDOK ) );
164 gtk_widget_set_usize( button, 60, -2 );
166 strcpy( portals.fn, GlobalRadiant().getMapName() );
167 char* fn = strrchr( portals.fn, '.' );
169 strcpy( fn, ".prt" );
172 StringOutputStream value( 256 );
174 gtk_entry_set_text( GTK_ENTRY( entry ), value.c_str() );
175 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( check2d ), portals.show_2d );
176 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( check3d ), portals.show_3d );
179 gtk_widget_show( dlg );
182 gtk_main_iteration();
187 portals.show_3d = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( check3d ) ) ? true : false;
188 portals.show_2d = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( check2d ) ) ? true : false;
191 gtk_grab_remove( dlg );
192 gtk_widget_destroy( dlg );