why do constructors return GtkWidget?



Hello,

I otherwise have a good understanding of GTK and can build relatively big programs, but I have a poor understanding of gobject. I use it to make my own gobjects in C but I don't understand all the implementation details.

In particular, I don't understand why is it normal for GTK widget "constructors" to return GtkWidget and not their real type.

    For instance I would expect:

gtk_menu_item_new ()

    To return GtkMenuItem*. But it doesn't, it returns GtkWidget*.

And then gtk_menu_shell_append() takes a GtkWidget*, not GtkMenuItem*. And it seems it's not because you could put any widget there, the documentation says "The GtkMenuItem to add".

It's annoying for me because I find that putting the real types in my code makes it easier to follow (rather than everything being a GtkWidget*), but if I go that route, I must constantly up and downcast...

From my limited understanding of gobject I would think those widgets could return and take the real type and all will work well? am I wrong? or are those historical reasons?

emmanuel



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