]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Make string_width() work in GTK3.
authorSimon Tatham <anakin@pobox.com>
Mon, 24 Aug 2015 18:31:44 +0000 (19:31 +0100)
committerSimon Tatham <anakin@pobox.com>
Mon, 24 Aug 2015 18:34:23 +0000 (19:34 +0100)
This was another piece of code that determined text size by
instantiating a GtkLabel and asking for its size, which I had to fix
in gtkfont.c recently because that strategy doesn't work in GTK3.

Replaced the implementation of string_width() with a call to the
function I added in gtkfont.c, and now dialog boxes which depend on
that for their width measurement (e.g. the one in reallyclose()) don't
come out in silly sizes on GTK3 any more.

unix/gtkdlg.c
unix/gtkfont.c
unix/unix.h

index 74b735fe84441ccc9fd716a0c841ed413c8957ef..a584501c963c493b672b71d58e7cf65ecd6d5f6e 100644 (file)
@@ -3428,11 +3428,9 @@ int messagebox(GtkWidget *parentwin, const char *title, const char *msg,
 
 int string_width(const char *text)
 {
-    GtkWidget *label = gtk_label_new(text);
-    GtkRequisition req;
-    gtk_widget_size_request(label, &req);
-    g_object_ref_sink(G_OBJECT(label));
-    return req.width;
+    int ret;
+    get_label_text_dimensions(text, &ret, NULL);
+    return ret;
 }
 
 int reallyclose(void *frontend)
index 9503991033eebe368687b923644aba91d13efed8..97983618e16cdea893a12035c3b027042d14107f 100644 (file)
@@ -2958,8 +2958,7 @@ static gint unifontsel_configure_area(GtkWidget *widget,
     return TRUE;
 }
 
-static void get_label_text_dimensions(const char *text,
-                                      int *width, int *height)
+void get_label_text_dimensions(const char *text, int *width, int *height)
 {
     /*
      * Determine the dimensions of a piece of text in the standard
@@ -2976,13 +2975,17 @@ static void get_label_text_dimensions(const char *text,
     PangoLayout *layout = gtk_label_get_layout(GTK_LABEL(label));
     PangoRectangle logrect;
     pango_layout_get_extents(layout, NULL, &logrect);
-    *width = logrect.width / PANGO_SCALE;
-    *height = logrect.height / PANGO_SCALE;
+    if (width)
+        *width = logrect.width / PANGO_SCALE;
+    if (height)
+        *height = logrect.height / PANGO_SCALE;
 #else
     GtkRequisition req;
     gtk_widget_size_request(label, &req);
-    *width = req.width;
-    *height = req.height;
+    if (width)
+        *width = req.width;
+    if (height)
+        *height = req.height;
 #endif
 
     g_object_ref_sink(G_OBJECT(label));
index 6359a2cd0211a45068dbfe61c383723d431423e7..fbe025ba656959363c5e55b7c5d02c4d39a49965 100644 (file)
@@ -137,6 +137,9 @@ void unix_setup_config_box(struct controlbox *b, int midsession, int protocol);
 /* gtkcfg.c */
 void gtk_setup_config_box(struct controlbox *b, int midsession, void *window);
 
+/* Helper function which happens to be in gtkfont.c at the moment */
+void get_label_text_dimensions(const char *text, int *width, int *height);
+
 /*
  * In the Unix Unicode layer, DEFAULT_CODEPAGE is a special value
  * which causes mb_to_wc and wc_to_mb to call _libc_ rather than