]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Move more functions into the new gtkmisc.c.
authorSimon Tatham <anakin@pobox.com>
Mon, 31 Aug 2015 14:44:24 +0000 (15:44 +0100)
committerSimon Tatham <anakin@pobox.com>
Mon, 31 Aug 2015 14:45:43 +0000 (15:45 +0100)
Several utility functions I've written over the last few weeks were in
rather random places because I didn't have a central gtkmisc.c to put
them in. Now I've got one, put them there!

unix/gtkdlg.c
unix/gtkfont.c
unix/gtkmisc.c
unix/gtkmisc.h
unix/gtkwin.c
unix/unix.h

index 47a8fae12edc7d219c7cde84b117bd755103ff85..e48c51b59e5d8fd45e79f4ed96e193f8133e9d44 100644 (file)
@@ -1077,15 +1077,6 @@ static void set_transient_window_pos(GtkWidget *parent, GtkWidget *child)
 #endif
 }
 
-void align_label_left(GtkLabel *label)
-{
-#if GTK_CHECK_VERSION(3,16,0)
-    gtk_label_set_xalign(label, 0.0);
-#else
-    gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
-#endif
-}
-
 void dlg_error_msg(void *dlg, const char *msg)
 {
     struct dlgparam *dp = (struct dlgparam *)dlg;
@@ -3413,13 +3404,6 @@ int messagebox(GtkWidget *parentwin, const char *title, const char *msg,
     return dp.retval;
 }
 
-int string_width(const char *text)
-{
-    int ret;
-    get_label_text_dimensions(text, &ret, NULL);
-    return ret;
-}
-
 int reallyclose(void *frontend)
 {
     char *title = dupcat(appname, " Exit Confirmation", NULL);
index 8302ac69c7f0b4db8e2d45ca03025c518b069368..2099c8332acd90e81904cc73a9f8444a43763f36 100644 (file)
@@ -23,6 +23,7 @@
 #include "putty.h"
 #include "gtkfont.h"
 #include "gtkcompat.h"
+#include "gtkmisc.h"
 #include "tree234.h"
 
 #ifndef NOT_X_WINDOWS
@@ -1992,46 +1993,6 @@ 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)
 
 /* ----------------------------------------------------------------------
index d6cfccc2959a989df239f22bf288fc5af80912a0..bf2647fd038045aff833835c3f6bf18d7bf13236 100644 (file)
 #include "putty.h"
 #include "gtkcompat.h"
 
+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
+}
+
+int string_width(const char *text)
+{
+    int ret;
+    get_label_text_dimensions(text, &ret, NULL);
+    return ret;
+}
+
+void align_label_left(GtkLabel *label)
+{
+#if GTK_CHECK_VERSION(3,16,0)
+    gtk_label_set_xalign(label, 0.0);
+#else
+    gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
+#endif
+}
+
 /* ----------------------------------------------------------------------
  * Functions to arrange controls in a basically dialog-like window.
  *
index 08daa85bec13f30cb7a1181b3f68c603714d01fb..e670d9d418da623ad556d25a40644fd95e98176d 100644 (file)
@@ -5,6 +5,11 @@
 #ifndef PUTTY_GTKMISC_H
 #define PUTTY_GTKMISC_H
 
+int string_width(const char *text);
+void get_label_text_dimensions(const char *text, int *width, int *height);
+
+void align_label_left(GtkLabel *label);
+
 GtkWidget *our_dialog_new(void);
 void our_dialog_add_to_content_area(GtkWindow *dlg, GtkWidget *w,
                                     gboolean expand, gboolean fill,
index 89b2787a45c8b5778c41486ed320655775b4ad23..f5320c9f3620f4c4b0c7bc1274afbdeb3037ad2a 100644 (file)
@@ -35,6 +35,7 @@
 #include "terminal.h"
 #include "gtkcompat.h"
 #include "gtkfont.h"
+#include "gtkmisc.h"
 
 #ifndef NOT_X_WINDOWS
 #include <gdk/gdkx.h>
index e0e771393e53cfdecf579f5581fadbe9fcd09432..271d3aa4099f3235178f6dd16c93fe12f666d207 100644 (file)
@@ -109,7 +109,6 @@ int reallyclose(void *frontend);
 #ifdef MAY_REFER_TO_GTK_IN_HEADERS
 int messagebox(GtkWidget *parentwin, const char *title,
                const char *msg, int minwid, ...);
-int string_width(const char *text);
 #endif
 
 /* Things pterm.c needs from {ptermm,uxputty}.c */
@@ -151,13 +150,6 @@ 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);
 
-/* General GTK helper functions, which could be in any source file and
- * it doesn't really matter */
-void get_label_text_dimensions(const char *text, int *width, int *height);
-#ifdef MAY_REFER_TO_GTK_IN_HEADERS
-void align_label_left(GtkLabel *label);
-#endif
-
 /*
  * 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