[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: How to put widget in CUSTOM GtkContainer
- From: "Milosz Derezynski" <internalerror gmail com>
- To: "Tomas Carnecky" <tom dbservice com>
- Cc: AlannY <m alanny ru>, "gtk-app-devel-list gnome org" <gtk-app-devel-list gnome org>, gtk-list gnome org
- Subject: Re: How to put widget in CUSTOM GtkContainer
- Date: Tue, 29 Apr 2008 15:52:30 +0200
I don't believe that using set_parent() will actually place the widget
inside the container; try gtk_container_add(GTK_CONTAINER(grid), widget);
instead
2008/4/29 Tomas Carnecky <tom dbservice com>:
> AlannY 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,
>
> That still isn't the whole code! What does grid_class_init() do? Attach
> both the whole grid header and source file to the email.
>
> > 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 ;-)
>
> And stop creating new threads... This is your third thread in
> gtk-app-devel where you ask the same question.
>
> tom
>
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list
>
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]