<URL: http://bugs.freeciv.org/Ticket/Display.html?id=39620 >

Marko Lindqvist wrote:
>  That's why I don't like GTK's generic APIs. You don't have type checking with
> them.
> 
Yeah, and I'm not a gui expert enough to catch them.  Here's a slightly better
version of the patch, telling the interface a pointer is passed.  Presumably,
the code actually worked because ints and pointers are the same size.

Index: client/gui-gtk-2.0/citydlg.c
===================================================================
--- client/gui-gtk-2.0/citydlg.c        (revision 14338)
+++ client/gui-gtk-2.0/citydlg.c        (working copy)
@@ -253,7 +253,7 @@
 static void buy_callback(GtkWidget * w, gpointer data);
 static void change_production_callback(GtkWidget* w, struct city_dialog*);
 
-static void sell_callback(Impr_type_id id, gpointer data);
+static void sell_callback(struct impr_type *pimprove, gpointer data);
 static void sell_callback_response(GtkWidget *w, gint response, gpointer data);
 
 static void impr_callback(GtkTreeView *view, GtkTreePath *path,
@@ -759,7 +759,7 @@
   gtk_box_pack_start(GTK_BOX(top), vbox, TRUE, TRUE, 0);
 
   /* improvements */
-  store = gtk_list_store_new(4, G_TYPE_INT, GDK_TYPE_PIXBUF, G_TYPE_STRING,
+  store = gtk_list_store_new(4, G_TYPE_POINTER, GDK_TYPE_PIXBUF, G_TYPE_STRING,
                             G_TYPE_INT);
 
   view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
@@ -1618,7 +1618,7 @@
 
     gtk_list_store_append(store, &it);
     gtk_list_store_set(store, &it,
-                      0, target.value,
+                      0, target.value.building,
                       1, sprite_get_pixbuf(sprite),
        2, items[item].descr,
        3, upkeep,
@@ -2484,11 +2484,11 @@
 /****************************************************************
 ...
 *****************************************************************/
-static void sell_callback(Impr_type_id id, gpointer data)
+static void sell_callback(struct impr_type *pimprove, gpointer data)
 {
-  struct impr_type *pimprove = improvement_by_number(id);
-  struct city_dialog *pdialog = (struct city_dialog *) data;
   GtkWidget *shl;
+  struct city_dialog *pdialog = (struct city_dialog *) data;
+  pdialog->sell_id = improvement_number(pimprove);
   
   if (!can_client_issue_orders()) {
     return;
@@ -2502,8 +2502,6 @@
     return;
   }
 
-  pdialog->sell_id = id;
-
   shl = gtk_message_dialog_new(NULL,
     GTK_DIALOG_DESTROY_WITH_PARENT,
     GTK_MESSAGE_QUESTION,
@@ -2547,7 +2545,7 @@
   GtkTreeModel *model;
   GtkTreeIter it;
   GdkModifierType mask;
-  int id;
+  struct impr_type *pimprove;
 
   model = gtk_tree_view_get_model(view);
 
@@ -2555,13 +2553,12 @@
     return;
   }
 
-  gtk_tree_model_get(model, &it, 0, &id, -1);
+  gtk_tree_model_get(model, &it, 0, &pimprove, -1);
   gdk_window_get_pointer(NULL, NULL, NULL, &mask);
 
   if (!(mask & GDK_CONTROL_MASK)) {
-    sell_callback(id, data);
+    sell_callback(pimprove, data);
   } else {
-    struct impr_type *pimprove = improvement_by_number(id);
     if (is_great_wonder(pimprove)) {
       popup_help_dialog_typed(improvement_name_translation(pimprove), 
HELP_WONDER);
     } else {
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to