[gtk-list] realizing windows (was Re: Center a window)




csmall@scooter.o.i.net writes:

> > 
> > > BTW: What exactly do gtk_widget_map and gtk_widget_realize do ?
> > >     In which situations do I absolutely need them ?
> > 
> >   It's explained in the gtk tutorial (chapter creating a widget from
> > scratch). Excellent job btw.
> 
> "WIDGETNAME_realize() is responsible for creating an X window for the widget
> if it has one."
> Not exactly that helpful, unless it is mentioned in another place as well.

Well, the widget writing section is meant to be used by people who
are fairly experienced with GTK and is a bit terse in places. That
being said - I think the above is quite accurate and reasonably clear.
There is a bit more information about when a widget has/needs an X
window in the drawing/event-handling section I recently announced,
and in the EventBox section of the tutorial. I'm sure it
 
> For example, it doesn't explain to me why text boxes crash if you don't
> realize them first, Perhaps I should  realize them every time I freeze the
> text.

Unfortunately, the Text widget is still rough in many ways - there is
a definite need for an adoptive parent to take over maintenance /
enhancement. I wouldn't say it _crashes_ - it dies with a descriptive
message saying what you did wrong. (However, to be consistent with the
rest of GTK

  g_assert (GTK_WIDGET_REALIZED (text)) 
  
should probably be:

  g_return_if_fail (GTK_WIDGET_REALIZED (text))

Which would just print a warning. It could probably realize itself
however - or, probably, it should be able to insert text while
unrealized. (Since it it doesn't seem to actually need a window).

I think, as much as possible, the user _shouldn't_ have to 
realize a window, unless they need to access widget->window 
themselves to make calls to GDK. It should only be needed for
things like:

 gtk_widget_realize (event_box);
 gdk_window_set_cursor (event_box->window, gdk_cursor_new (GDK_HAND1));

-

A slighly better description of the function of gtk_widget_realize
from the user's point of view would be:

gtk_widget_realize(widget) fills in widget->window with a pointer to
the window in which the widget draws. If the widget has it's own
window, it is created, otherwise widget->window will point to the
widget's parent's window. (The parent is realized if necessary).  If
the widget has its own window, it will also receive events generated
for that window.

Regards,
                                        Owen
------- End of forwarded message -------



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