--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gui/ctrl_dlg.c Tue Oct 16 12:36:29 2007 +0000 @@ -0,0 +1,156 @@ +/** + * $Id: ctrl_dlg.c,v 1.1 2007-10-16 12:36:29 nkeynes Exp $ + * + * Define the main (emu) GTK window, along with its menubars, + * toolbars, etc. + * + * Copyright (c) 2005 Nathan Keynes. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include + +#include "dream.h" +#include "gui/gtkui.h" +#include "maple/maple.h" + +#define MAX_DEVICES 4 + +typedef struct maple_slot_data { + maple_device_t old_device; + maple_device_t new_device; + GtkWidget *button; + GtkWidget *combo; +} *maple_slot_data_t; + +static struct maple_slot_data maple_data[MAX_DEVICES]; + + +gboolean controller_properties_activated( GtkButton *button, gpointer user_data ) +{ + maple_slot_data_t data = (maple_slot_data_t)user_data; +} + +gboolean controller_device_changed( GtkComboBox *combo, gpointer user_data ) +{ + maple_slot_data_t data = (maple_slot_data_t)user_data; + int active = gtk_combo_box_get_active(combo); + gtk_widget_set_sensitive(data->button, active != 0); + if( active != 0 ) { + gchar *devname = gtk_combo_box_get_active_text(combo); + const maple_device_class_t devclz = maple_get_device_class(devname); + assert(devclz != NULL); + if( data->new_device != NULL ) { + if( data->new_device->device_class != devclz ) { + data->new_device->destroy(data->new_device); + data->new_device = maple_new_device(devname); + } + } else { + data->new_device = maple_new_device(devname); + } + } else { + if( data->new_device != NULL && data->new_device != data->old_device ) { + data->new_device->destroy(data->new_device); + } + data->new_device = NULL; + } +} + +void controller_commit_changes( ) +{ + int i; + for( i=0; idestroy(maple_data[i].new_device); + } + } +} + +GtkWidget *controller_pane_new() +{ + GtkWidget *table = gtk_table_new(4, 3, TRUE); + GtkTreeIter iter; + int i,j; + const struct maple_device_class **devices = maple_get_device_classes(); + + for( i=0; i< MAX_DEVICES; i++ ) { + char buf[12]; + GtkWidget *combo, *button; + int active = 0; + maple_device_t device = maple_get_device(i,0); + sprintf( buf, "Slot %d.", i ); + gtk_table_attach_defaults( GTK_TABLE(table), gtk_label_new(buf), 0, 1, i, i+1 ); + combo = gtk_combo_box_new_text(); + gtk_combo_box_append_text( GTK_COMBO_BOX(combo), "" ); + for( j=0; devices[j] != NULL; j++ ) { + gtk_combo_box_append_text(GTK_COMBO_BOX(combo), devices[j]->name); + if( device != NULL && device->device_class == devices[j] ) { + active = j+1; + } + } + gtk_combo_box_set_active(GTK_COMBO_BOX(combo), active); + gtk_table_attach_defaults( GTK_TABLE(table), combo, 1, 2, i, i+1 ); + button = gtk_button_new_from_stock( GTK_STOCK_PROPERTIES ); + gtk_widget_set_sensitive(button, active != 0); + gtk_table_attach_defaults( GTK_TABLE(table), button, 2, 3, i, i+1 ); + + maple_data[i].old_device = device; + maple_data[i].new_device = device; + maple_data[i].combo = combo; + maple_data[i].button = button; + g_signal_connect( button, "activate", + G_CALLBACK( controller_properties_activated ), &maple_data[i] ); + g_signal_connect( combo, "changed", + G_CALLBACK( controller_device_changed ), &maple_data[i] ); + + } + return table; +} + +void controller_dialog_run( GtkWindow *parent ) +{ + GtkWidget *dialog = + gtk_dialog_new_with_buttons("Controller Settings", parent, + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, + NULL); + GtkWidget *panel = controller_pane_new(); + gint result; + gtk_widget_show_all(panel); + gtk_container_add( GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), panel ); + result = gtk_dialog_run( GTK_DIALOG(dialog) ); + gtk_widget_destroy( dialog ); + if( result == GTK_RESPONSE_ACCEPT ) { + controller_commit_changes(); + } else { + controller_cancel_changes(); + } +}