shithub: puzzles

Download patch

ref: a94dbd27d0fbbbfbd90290647d3305ef6b6cce5b
parent: 2afbcdcc3c6d59aa03280df65ce6c690baa4273f
author: Simon Tatham <anakin@pobox.com>
date: Sun Oct 4 15:56:39 EDT 2015

GTK 3 cleanup: use GtkMessageDialog for message_box().

This is a lot easier than faffing about setting up a dialog box
ourself, and also avoids direct access to GtkDialog's action area
(deprecated in GTK 3.16).

--- a/gtk.c
+++ b/gtk.c
@@ -1372,18 +1372,6 @@
     gtk_main_quit();
 }
 
-static void msgbox_button_clicked(GtkButton *button, gpointer data)
-{
-    GtkWidget *window = GTK_WIDGET(data);
-    int v, *ip;
-
-    ip = (int *)g_object_get_data(G_OBJECT(window), "user-data");
-    v = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button), "user-data"));
-    *ip = v;
-
-    gtk_widget_destroy(GTK_WIDGET(data));
-}
-
 static int win_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data)
 {
     GObject *cancelbutton = G_OBJECT(data);
@@ -1411,9 +1399,40 @@
 #endif
 }
 
+#if GTK_CHECK_VERSION(3,0,0)
 int message_box(GtkWidget *parent, char *title, char *msg, int centre,
 		int type)
 {
+    GtkWidget *window;
+    gint ret;
+
+    window = gtk_message_dialog_new
+        (GTK_WINDOW(parent),
+         (GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
+         (type == MB_OK ? GTK_MESSAGE_INFO : GTK_MESSAGE_QUESTION),
+         (type == MB_OK ? GTK_BUTTONS_OK   : GTK_BUTTONS_YES_NO),
+         "%s", msg);
+    gtk_window_set_title(GTK_WINDOW(window), title);
+    ret = gtk_dialog_run(GTK_DIALOG(window));
+    gtk_widget_destroy(window);
+    return (type == MB_OK ? TRUE : (ret == GTK_RESPONSE_YES));
+}
+#else /* GTK_CHECK_VERSION(3,0,0) */
+static void msgbox_button_clicked(GtkButton *button, gpointer data)
+{
+    GtkWidget *window = GTK_WIDGET(data);
+    int v, *ip;
+
+    ip = (int *)g_object_get_data(G_OBJECT(window), "user-data");
+    v = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button), "user-data"));
+    *ip = v;
+
+    gtk_widget_destroy(GTK_WIDGET(data));
+}
+
+int message_box(GtkWidget *parent, char *title, char *msg, int centre,
+		int type)
+{
     GtkWidget *window, *hbox, *text, *button;
     char *titles;
     int i, def, cancel;
@@ -1474,6 +1493,7 @@
     gtk_main();
     return (type == MB_YESNO ? i == 1 : TRUE);
 }
+#endif /* GTK_CHECK_VERSION(3,0,0) */
 
 void error_box(GtkWidget *parent, char *msg)
 {