[Freeciv-Dev] Re: client string options: choosing from a list (v3) (PR#1
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Raimar Falke wrote:
Still missing is an implementation for the GTK client.
Here is an attempt at an implementation for the GTK client.
jason
? client/gui-gtk/diff
? client/gui-gtk/stAyRn8M
? client/gui-gtk/stDLL3Zv
? client/gui-gtk/stGvSbe8
? client/gui-gtk/stQIad5P
? client/gui-gtk/sttJNmSQ
Index: client/gui-gtk/gamedlgs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/gamedlgs.c,v
retrieving revision 1.25
diff -u -r1.25 gamedlgs.c
--- client/gui-gtk/gamedlgs.c 2002/07/23 02:47:33 1.25
+++ client/gui-gtk/gamedlgs.c 2002/08/11 16:45:46
@@ -369,13 +369,15 @@
static GtkWidget *option_dialog_shell;
+#define COT_STR_DATA_NAME "option_value"
+
/**************************************************************************
...
**************************************************************************/
static void option_ok_command_callback(GtkWidget *widget, gpointer data)
{
client_option *o;
- char *dp;
+ const char *dp;
for (o=options; o->name; ++o) {
switch (o->type) {
@@ -387,9 +389,16 @@
sscanf(dp, "%d", o->p_int_value);
break;
case COT_STR:
- mystrlcpy(o->p_string_value,
- gtk_entry_get_text(GTK_ENTRY(o->p_gui_data)),
- o->string_length);
+ if (!o->p_gui_data) {
+ break;
+ }
+ if (o->p_string_vals) {
+ GtkWidget *selection = gtk_menu_get_active(GTK_MENU(o->p_gui_data));
+ dp = gtk_object_get_data(GTK_OBJECT(selection), COT_STR_DATA_NAME);
+ } else {
+ dp = gtk_entry_get_text(GTK_ENTRY(o->p_gui_data));
+ }
+ mystrlcpy(o->p_string_value, dp, o->string_length);
break;
}
}
@@ -398,7 +407,6 @@
gtk_widget_destroy(option_dialog_shell);
}
-
/****************************************************************
...
*****************************************************************/
@@ -446,10 +454,67 @@
case COT_STR:
label = gtk_label_new(_(o->description));
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
- gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, i, i+1);
- o->p_gui_data = gtk_entry_new();
- gtk_widget_set_usize(o->p_gui_data, 150, 0);
- gtk_table_attach_defaults(GTK_TABLE(table), o->p_gui_data, 1, 2, i, i+1);
+ gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, i, i + 1);
+ if (o->p_string_vals) {
+ const char **vals = (*o->p_string_vals)();
+ GtkWidget* selection;
+
+ if (!vals[0]) {
+ selection = gtk_label_new(o->p_string_value);
+ o->p_gui_data = NULL;
+ } else {
+ GtkWidget* popupmenu;
+ int j;
+ bool active = FALSE;
+
+ selection = gtk_option_menu_new();
+ popupmenu = gtk_menu_new();
+
+ for (j = 0; vals[j]; j++) {
+ GtkWidget *item = gtk_menu_item_new_with_label(vals[j]);
+ gtk_menu_append(GTK_MENU(popupmenu), item);
+ if (!strcmp(vals[j], o->p_string_value)) {
+ /* This is also called in popup_option_dialog, but without
+ calling it here too things don't seem to get updated
+ properly. */
+ gtk_menu_set_active(GTK_MENU(popupmenu), j);
+ active = TRUE;
+ }
+
+ gtk_object_set_data(GTK_OBJECT(item),
+ COT_STR_DATA_NAME,
+ (char*)vals[j]);
+ }
+ if (!active) {
+ /* The current entry isn't anywhere on the list. Add it. */
+ GtkWidget *item = gtk_menu_item_new_with_label(o->p_string_value);
+ gtk_menu_append(GTK_MENU(popupmenu), item);
+ gtk_menu_set_active(GTK_MENU(popupmenu), j);
+ gtk_object_set_data(GTK_OBJECT(item),
+ COT_STR_DATA_NAME,
+ o->p_string_value);
+ }
+
+ gtk_widget_show_all(popupmenu);
+
+ gtk_option_menu_set_menu(GTK_OPTION_MENU(selection),
+ popupmenu);
+ gtk_object_set_data(GTK_OBJECT(popupmenu),
+ "parent",
+ selection);
+
+ o->p_gui_data = popupmenu;
+ }
+ gtk_widget_set_usize(selection, 150, 0);
+ gtk_table_attach_defaults(GTK_TABLE(table), selection,
+ 1, 2, i, i + 1);
+ gtk_widget_show_all(selection);
+ } else {
+ o->p_gui_data = gtk_entry_new();
+ gtk_widget_set_usize(o->p_gui_data, 150, 0);
+ gtk_table_attach_defaults(GTK_TABLE(table), o->p_gui_data,
+ 1, 2, i, i + 1);
+ }
break;
}
}
@@ -489,7 +554,24 @@
gtk_entry_set_text(GTK_ENTRY(o->p_gui_data), valstr);
break;
case COT_STR:
- gtk_entry_set_text(GTK_ENTRY(o->p_gui_data), o->p_string_value);
+ if (!o->p_gui_data) {
+ break;
+ }
+ if (o->p_string_vals) {
+ int i;
+ const char** vals = (o->p_string_vals)();
+ for (i = 0; vals[i]; i++) {
+ if (!strcmp(vals[i], o->p_string_value)) {
+ gtk_menu_set_active(GTK_MENU(o->p_gui_data), i);
+ break;
+ }
+ }
+ if (!vals[i]) {
+ gtk_menu_set_active(GTK_MENU(o->p_gui_data), i);
+ }
+ } else {
+ gtk_entry_set_text(GTK_ENTRY(o->p_gui_data), o->p_string_value);
+ }
break;
}
}
- [Freeciv-Dev] Re: client string options: choosing from a list (v3) (PR#1856),
Jason Short <=
|
|