Re: GtkWidget::set_style proposal (was: [bug, v0.99.3] frame->label_width)




At Tim's request, here is a summary of the "style_set" issues:


Current situation
=================

Currently, when a widget is created, it gets a default style.
Between the creation of the widget, and the point where the
widget is realized, the application may set a new "user" style
for the widget using gtk_widget_set_style().

When the widget is realized, if no user style has been set,
the style for the widget will be looked up according to the
rc file, and a new style set for the widget, if necessary.
Then the style is attached to the window. 

This means, that the style is looked up in a cache indexed by the
colors and font of the style and the (now present) colormap and
visual of widget=>window. A new style is created if none already
exists for that combination, the colors are allocated and the
gc's are created.

Current problems
================

1) The requested size depends on the font of the widget, however,
   the size may be requested before the widget is realized,
   at which point the style of the widget may not have its final
   value.

2) The style of a widget cannot be changed after the widget is
   created, because some things set in the "realize" handler,
   like the background color of the widget's windows, will
   not change with the style.

3) An application cannot make small changes to a widget's style,
   because the correct style will not be set until the widget
   is realized. But after the widget is realized, it is too
   late to change the style. (See 2))

Proposal
========

* A new flag, GTK_STYLE_SET will be added. This indicates
  that the widgets style has been looked up according to
  the RC file. It does not imply that the widgets style is
  attached.

* A new "style_set" signal will be added. This signal will
  be of the RUN_FIRST and have a single parameter, which
  is the previous style, if there was one, or NULL.

* A function gtk_widget_set_default_style() will be added
  that, if GTK_STYLE_SET is not set:
   
   a) Checks if a user style has been set, and if not:

      b) looks up the correct style according to the RC file

   c) Sets GTK_STYLE_SET

   d) emits "style_set" (the parameter is NULL, if 
      GTK_STYLE_SET was not previously set)

* gtk_widget_set_style will set GTK_STYLE_SET if not set,
  and always emit "style_set". (The parameter is NULL if
  GTK_STYLE_SET was not previously set)

* gtk_widget_size_request() will call gtk_widget_set_default_style()
  if !GTK_STYLE_SET.

* gtk_widget_realize() will call gtk_widget_set_default_style()
  if !GTK_STYLE_SET. The widgets "realize" handler is then
  responsible for attaching the style.

* A new function gtk_style_copy() will be added, which creates
  a new (unattached) style using the "key" portions of an
  existing style.

* The default "style_set" handler will look like:

  if (GTK_WIDGET_REALIZED(widget)) {
    if (!GTK_WIDGET_NO_WINDOW (widget)
      gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);

    gtk_widget_queue_redraw (widget);
  }

  [ Should that be widget->state ??? ]

  Widgets must override this if:

   - their size requisition depends on the current font
  
   - they set the background of widget->window to something other 
     than style->bg. (e.g., ListItem)

   - they have windows other than widget->window

   - they have any other stored dependencies on the style
 
 If the previous_style parameter is not set, the widget can
 assume that it hasnot been size_requested yet, and does not
 need to queue a resize. If the widget is not realized,
 it will not be necessary (or possible) to set the background
 of the widget's windows, and it is not necessary to queue
 a redraw.

=======

I believe the above provides an efficient solution to
problems 1), 2) and 3). It is, of course, merely an expansion
of what Tim was proposing.
                                        Owen



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