]> asedeno.scripts.mit.edu Git - PuTTY.git/blobdiff - unix/gtkfont.c
Avoid deprecated gtk_misc_set_alignment().
[PuTTY.git] / unix / gtkfont.c
index 9503991033eebe368687b923644aba91d13efed8..54e412f68f2978a0790357820c89182dd3472051 100644 (file)
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
+
 #include <gtk/gtk.h>
 #if !GTK_CHECK_VERSION(3,0,0)
 #include <gdk/gdkkeysyms.h>
 #endif
+
+#define MAY_REFER_TO_GTK_IN_HEADERS
+
+#include "putty.h"
+#include "gtkfont.h"
+#include "gtkcompat.h"
+#include "tree234.h"
+
 #ifndef NOT_X_WINDOWS
 #include <gdk/gdkx.h>
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
 #endif
 
-#include "putty.h"
-#include "gtkfont.h"
-#include "gtkcompat.h"
-#include "tree234.h"
-
 /*
  * Future work:
  * 
@@ -1988,6 +1992,46 @@ static void multifont_draw_text(unifont_drawctx *ctx, unifont *font, int x,
     }
 }
 
+/* ----------------------------------------------------------------------
+ * Utility routine used by the code below, and also gtkdlg.c.
+ */
+
+void get_label_text_dimensions(const char *text, int *width, int *height)
+{
+    /*
+     * Determine the dimensions of a piece of text in the standard
+     * font used in GTK interface elements like labels. We do this by
+     * instantiating an actual GtkLabel, and then querying its size.
+     *
+     * But GTK2 and GTK3 require us to query the size completely
+     * differently. I'm sure there ought to be an easier approach than
+     * the way I'm doing this in GTK3, too!
+     */
+    GtkWidget *label = gtk_label_new(text);
+
+#if GTK_CHECK_VERSION(3,0,0)
+    PangoLayout *layout = gtk_label_get_layout(GTK_LABEL(label));
+    PangoRectangle logrect;
+    pango_layout_get_extents(layout, NULL, &logrect);
+    if (width)
+        *width = logrect.width / PANGO_SCALE;
+    if (height)
+        *height = logrect.height / PANGO_SCALE;
+#else
+    GtkRequisition req;
+    gtk_widget_size_request(label, &req);
+    if (width)
+        *width = req.width;
+    if (height)
+        *height = req.height;
+#endif
+
+    g_object_ref_sink(G_OBJECT(label));
+#if GTK_CHECK_VERSION(2,10,0)
+    g_object_unref(label);
+#endif
+}
+
 #if GTK_CHECK_VERSION(2,0,0)
 
 /* ----------------------------------------------------------------------
@@ -2958,39 +3002,6 @@ static gint unifontsel_configure_area(GtkWidget *widget,
     return TRUE;
 }
 
-static void get_label_text_dimensions(const char *text,
-                                      int *width, int *height)
-{
-    /*
-     * Determine the dimensions of a piece of text in the standard
-     * font used in GTK interface elements like labels. We do this by
-     * instantiating an actual GtkLabel, and then querying its size.
-     *
-     * But GTK2 and GTK3 require us to query the size completely
-     * differently. I'm sure there ought to be an easier approach than
-     * the way I'm doing this in GTK3, too!
-     */
-    GtkWidget *label = gtk_label_new(text);
-
-#if GTK_CHECK_VERSION(3,0,0)
-    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;
-#else
-    GtkRequisition req;
-    gtk_widget_size_request(label, &req);
-    *width = req.width;
-    *height = req.height;
-#endif
-
-    g_object_ref_sink(G_OBJECT(label));
-#if GTK_CHECK_VERSION(2,10,0)
-    g_object_unref(label);
-#endif
-}
-
 unifontsel *unifontsel_new(const char *wintitle)
 {
     unifontsel_internal *fs = snew(unifontsel_internal);
@@ -3062,7 +3073,7 @@ unifontsel *unifontsel_new(const char *wintitle)
 
     label = gtk_label_new_with_mnemonic("_Font:");
     gtk_widget_show(label);
-    gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
+    align_label_left(GTK_LABEL(label));
 #if GTK_CHECK_VERSION(3,0,0)
     gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1);
     g_object_set(G_OBJECT(label), "hexpand", TRUE, (const char *)NULL);
@@ -3110,7 +3121,7 @@ unifontsel *unifontsel_new(const char *wintitle)
 
     label = gtk_label_new_with_mnemonic("_Style:");
     gtk_widget_show(label);
-    gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
+    align_label_left(GTK_LABEL(label));
 #if GTK_CHECK_VERSION(3,0,0)
     gtk_grid_attach(GTK_GRID(table), label, 1, 0, 1, 1);
     g_object_set(G_OBJECT(label), "hexpand", TRUE, (const char *)NULL);
@@ -3157,7 +3168,7 @@ unifontsel *unifontsel_new(const char *wintitle)
 
     label = gtk_label_new_with_mnemonic("Si_ze:");
     gtk_widget_show(label);
-    gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
+    align_label_left(GTK_LABEL(label));
 #if GTK_CHECK_VERSION(3,0,0)
     gtk_grid_attach(GTK_GRID(table), label, 2, 0, 1, 1);
     g_object_set(G_OBJECT(label), "hexpand", TRUE, (const char *)NULL);
@@ -3383,7 +3394,7 @@ void unifontsel_set_name(unifontsel *fontsel, const char *fontname)
      * Provide a default if given an empty or null font name.
      */
     if (!fontname || !*fontname)
-       fontname = "server:fixed";
+       fontname = DEFAULT_GTK_FONT;
 
     /*
      * Call the canonify_fontname function.