Computing border size of GtkFrame
- Date: Wed, 23 Mar 2016 16:34:14 +0100
- From: Andreas Falkenhahn <andreas@xxxxxxxxxxxxxx>
- Subject: Computing border size of GtkFrame
I need to compute the border sizes of a GtkFrame before the window containing
that GtkFrame has been realized. Precisely, I need the distances between the
GtkFrame container widget and its child. AFAICS, this isn't possible to get
before the GtkFrame has been realized. So I thought that I could use a workaround
that creates a top-level window, adds a GtkFrame with a GtkButton and computes
the size and destroys everything again. Here is the code:
void GTKFrameGetBorders(int *borderTop, int *borderOther)
GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
GtkWidget* labelwidget = gtk_label_new_with_mnemonic("Foo");
GtkWidget* framewidget = gtk_frame_new(NULL);
GtkWidget *btn = gtk_button_new();
// !!! THIS CALL IS NECESSARY TO GET CORRECT VALUES !!!
GtkAllocation alloc, child_alloc;
*borderTop = child_alloc.y - alloc.y;
*borderOther = child_alloc.x - alloc.x;
This seems to do the job and returns the correct values but of course it's a
really hackish solution. So I've got two questions:
1) Is there a better/cleaner solution? :)
2) Is it allowed to call gtk_widget_realize() on the "labelwidget" as done above? The
docs say that gtk_widget_realize() is propagated upwards so does this mean that
gtk_widget_realize() will end up being called on the top-level window which means
that the top-level window will be shown very briefly? That's of course something
I'd like to avoid...
I'm targetting GTK+ 2.
Thanks for any suggestions!
Andreas Falkenhahn mailto:andreas@xxxxxxxxxxxxxx
gtk-list mailing list