Re: Computing border size of GtkFrame
- Date: Wed, 23 Mar 2016 11:52:02 -0400
- From: Igor Korot <ikorot01@xxxxxxxxx>
- Subject: Re: Computing border size of GtkFrame
On Wed, Mar 23, 2016 at 11:34 AM, Andreas Falkenhahn
> 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:
What is it that you are trying to accomplish/achieve?
Maybe this is possible in some other way?
> 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);
> gtk_frame_set_label_widget(GTK_FRAME(framewidget), labelwidget);
> GtkWidget *btn = gtk_button_new();
> gtk_container_add(GTK_CONTAINER(framewidget), btn);
> gtk_container_add(GTK_CONTAINER(wnd), framewidget);
> // !!! THIS CALL IS NECESSARY TO GET CORRECT VALUES !!!
> GtkAllocation alloc, child_alloc;
> gtk_widget_get_allocation(framewidget, &alloc);
> GTK_FRAME_GET_CLASS(framewidget)->compute_child_allocation(GTK_FRAME(framewidget), &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!
> Best regards,
> Andreas Falkenhahn mailto:andreas@xxxxxxxxxxxxxx
> gtk-list mailing list
gtk-list mailing list