[Glade-users] Accessing the window inside the widget



On Fri, Jan 27, 2012 at 10:33 PM, Manuel Ferrero <mferrero at reer.it> wrote:
A simple program:

---SNIP---
GtkWidget *my_window;
GtkBuilder *builder_handler;


builder_handler = gtk_builder_new();
gtk_builder_add_from_file(builder_handler, GUI_XML_FILENAME, NULL);

my_window = GTK_WIDGET(gtk_builder_get_object(builder_handler, "window"));
---PINS---


Now my_window is a GtkWidget and its class hierarchy tree is the following:

+GtkWidget
|+GtkContainer
?|+GtkBin
?|+GtkWindow

Almost every function to manipulate windows requires a GtkWindow pointer,
i.e.:
void gtk_window_set_resizable(GtkWindow *window, gboolean resizable);

How do I get the GtkWindow pointer from the GtkWidget I get after the
builder?

With the standard type casting macros:

GtkWidget *widget;
GtkWindow *window;

widget = gtk_builder_get_object (builder, "window");
window = GTK_WINDOW (widget);

gtk_window_do_something_from_the_window_api (window, argument);

Likewise, you can simply cast the pointer in the function argument like so:

gtk_window_do_something_from_the_window_api (GTK_WINDOW (widget), argument);

Usually we hold all widgets in a GtkWidget pointer regardless of the type, just
because chances are you will be accessing GtkWidget apis more regularly
than other apis.

If you are concerned with performance, and you will call multiple apis from
the GtkWindow api, then it's (slightly) worthwhile to create a GtkWindow pointer
and use that pointer instead.

This is because the standard type casting macros fire runtime assertions for
type mismatches (i.e. the macros include run-time type checking).

Cheers,
            -Tristan


Thanks in advance.
--
Regards,
Manuel Ferrero
R&D department

Reer SpA
Tel. ?+39 011 2482215
Fax. +39 011 859867

L'utilizzo non autorizzato del presente messaggio e' vietato e potrebbe
costituire reato.
Se il presente messaggio non e' a Lei indirizzato, il suo contenuto non deve
essere considerato
come trasmesso o autorizzato dalla Reer SpA; in tale caso Le saremmo grati
se, via e-mail,
ce ne comunicasse l'errata ricezione.

The unauthorized use of this e-mail is prohibited and could constitute an
offence.
If you are not the intended recipient of this message its contents shall be
understood as neither
given nor endorsed by Reer SpA. Please notify Reer SpA by e-mail immediately
in that case.

_______________________________________________
Glade-users maillist ?- ?Glade-users at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/glade-users




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]