1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-04 21:12:47 -05:00

Move more functions into the new gtkmisc.c.

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!
This commit is contained in:
Simon Tatham
2015-08-31 15:44:24 +01:00
parent dc11417aee
commit 49ff9f480e
6 changed files with 59 additions and 64 deletions

View 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)
/* ----------------------------------------------------------------------