2008/4/29 Tomas Carnecky <tom@xxxxxxxxxxxxx>:
That still isn't the whole code! What does grid_class_init() do? AttachAlannY wrote:
> Hi there, my name is Alan and I have some troubles with GtkContainer.
>
> It's about 2 days, I already have spent trying to solve it, but I (i
> guess) can't.
>
> I'm writing a program, which looks like:
> +-----------------------------+
> | Main Window (GtkWindow) |
> | +-------------------------+ |
> | | My custom widget | |
> | | +---------------------+ | |
> | | | GtkButton | | |
> | | +---------------------+ | |
> | +-------------------------+ |
> +-----------------------------+
>
> I need some approach to place a GtkButton in my custom widget. I found
> (from GTK+ sources) that GtkTreeView, GtkNotebook (and others) inherits
> from GtkContainer . So, I decide to inherit my widget not from
> GtkWidget, but from GtkContainer.
>
> typedef struct _Grid Grid;
> typedef struct _GridClass GridClass;
>
> struct _Grid
> {
> GtkContainer parent;
> };
>
> struct _GridClass
> {
> GtkContainerClass parent_class;
> };
>
> And my _get_type function looks like:
>
> GtkType
> grid_get_type ()
> {
> static GtkType grid_type = 0;
>
> if (!grid_type)
> {
> const GTypeInfo object_info =
> {
> sizeof (GtkContainerClass),
> NULL,
> NULL,
> (GClassInitFunc) grid_class_init,
both the whole grid header and source file to the email.
And stop creating new threads... This is your third thread in
> NULL,
> NULL,
> sizeof (Grid),
> 0,
> (GInstanceInitFunc) grid_init,
> NULL,
> };
>
> grid_type = g_type_register_static (GTK_TYPE_CONTAINER,
> g_intern_static_string ("Grid"), &object_info, 0);
> }
>
> return grid_type;
> }
>
> The main feature of this function is GTK_TYPE_CONTAINER ;-) You see ;-)
>
> Next in my program, I'm creating my widget (grid) with that:
>
> [...]
> grid = grid_new ();
> gtk_container_add (GTK_CONTAINER (window), grid);
> [...]
>
> So, my problem starts here: at _new() function. I want to create
> GtkButton and place it in my widget.
>
> GtkWidget*
> grid_new ()
> {
> Grid *grid;
>
> grid = g_object_new (grid_get_type (), NULL);
>
> button = gtk_button_new_with_label ("Test");
> gtk_widget_set_parent (button, GTK_WIDGET (grid));
> gtk_widget_show (button);
>
> return GTK_WIDGET (grid);
> }
>
> Everything right and works without errors ;-) But nothing happens. I
> can't see a GtkButton ;-)
>
> How to solve it? I need some way for "draw" (expose) GtkButton in my
> custom widget ;-) How to do it?
>
> P.S. I extremely think, that I just forgot something. But there are no
> tutorials about it ;-) "Information vacuum", so I decide to ask in
> mailing-lists.
> P.P.S. Only information about custom widget creation is a GTK sources,
> but (even with it) I can't solve my problem. ;-)
> P.P.P.S. Also, I really want to understand how GtkBox works ;-)
gtk-app-devel where you ask the same question.
tom
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list
_______________________________________________ gtk-list mailing list gtk-list@xxxxxxxxx http://mail.gnome.org/mailman/listinfo/gtk-list