Re: naive questions writes:

> Hi.  I'm trying to make sense of gtk.  I have a few questions:
> 1) the label widget has a size_request method, but no size_allocate.
> I guess that means that there's no one-time change needed when its
> size changes unlike e.g. a button.

More precisely, it is using the default widget size_allocate
handler (gtk_widget_real_size_allocate) which (for a NO_WINDOW
widget like a label):

 a) Clears the widget area if it is already drawn on the screen
 b) Stores the new allocation into widget->allocation

> 2) gtk_widget_size_request() increases the ref count while it signals
> the widget to resize itself.  Why?  Isn't the ref count already going
> to be non-zero?

Any code that needs to hold onto a widget across a signal handler
should ref the widget and then unref it.

Although it would be  strange, there is no reason a user couldn't
attach a signal handler to "size_request" which destroys the
widget. If that causes the ref count to go to zero, the next 

  aux_info = gtk_object_get_data (GTK_OBJECT (widget), aux_info_key);

would cause a segfault.
> 3) Looks to me like a menu consists of three pieces:
>    a) a menu bar container whose function is to send popup signals and 
>       locations to a menu.
>    b) a menu container whose function is to hold menuitems.
>    c) menuitems, a container which holds an item.
> I'm trying to figure out how to add pie menus to gtk.  Looks to me
> like I'm going to make something like a menu.  It's going to request
> sizes of its children, position them as needed, then communicate the
> positions by calling size_allocate.

That is essentially correct. I think you probably can profitably
even derive a Pie menu widget from the Menu widget itself.
(The other possibility would to be make the PieMenu and Menu sister
widgets from a common base)

What needs to be overriden?

- The size request function. (Way it works, is that your size
  request gets, called, you call size_request for your children,
  and figure out the size you need, then GTK decides on your
  size - which for a menu will probably be exactly what you
  requested and calls you size_allocate, in which you allocate
  your children.

- The size allocate function

- The draw and expose functions. (You _should_ be able to just
  override the "paint" function, but that isn't virtual)

The other thing you'll need to worry about is the positioning
of children.  Since this intelligence is encapsulated in
the MenuItem, you may want to create a special PieMenuItem

I suspect to really do things right some changes will be needed
to GTK itself in the long term. (Pie menus/ normal menus
should be the user's choice, not the programmer's, for one
thing). But I think you can probably get something working
to begin with, without doing that.


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