GtkWIdget::style_set initial emission,

read up in docs/style.txt on this ;)
This commit is contained in:
Tim Janik 1998-02-27 22:09:20 +00:00
parent 693fa02b83
commit b2e6c9723a
5 changed files with 54 additions and 28 deletions

View File

@ -57,26 +57,31 @@ gtk_style_copy ()
GtkWidget::style_set GtkWidget::style_set
This signal will be emitted for a widget once its style changes with This signal will be emitted for a widget once its style changes with
the previous style supplied. an additional argument previous_style wich will hold the widget->style
the GtkWidgetClass implements a default handler for this signal that avlue from a previous emission.
will set the widget's window's background of widgets that provide their The initial emission of this signal is guaranteed to happen prior
own windows according to the new style. to any GtkWidget::size_request emission, and will have the previous_style
Derived widgets need to overide this default handler, if: argument set to NULL.
- their size requisition depends on the current style. The GtkWidgetClass implements a default handler for this signal that
will set the widget's window's background of widgets that provide their
own windows according to the new style.
Derived widgets need to overide this default handler, if:
- their size requisition depends on the current style.
(e.g., on the style's fonts) (e.g., on the style's fonts)
- they set the background of widget->window to something other than. - they set the background of widget->window to something other than.
style->bg. (e.g., GtkListItem) style->bg. (e.g., GtkListItem)
- the widget provides windows other than widget->window. - the widget provides windows other than widget->window.
- the widget has any other stored dependencies on the style. - the widget has any other stored dependencies on the style.
Flag indications: Flag indications:
!GTK_RC_STYLE && !GTK_USER_STYLE: !GTK_RC_STYLE && !GTK_USER_STYLE:
The widget has it's default style set, and no rc lookup has been The widget has it's default style set, no rc lookup has been
performed. performed, the widget has not been size requested yet and is
therefore not yet realized.
GTK_USER_STYLE: GTK_USER_STYLE:
GTK_RC_STYLE is not set. GTK_RC_STYLE is not set.
@ -86,9 +91,8 @@ GTK_USER_STYLE:
GTK_RC_STYLE: GTK_RC_STYLE:
GTK_USER_STYLE is not set. GTK_USER_STYLE is not set.
If the widget has a saved default style, it has been assigned an If the widget has a saved default style, it has been assigned an
rc style. rc style. If the widget does not have a saved default style, it still
If the widget does not have a saved default style, it still has its has its default style but an rc lookup has already been performed.
default style but an rc lookup has already been performed.
- Tim Janik <timj@gimp.org> - Tim Janik <timj@gimp.org>

View File

@ -67,9 +67,6 @@
#define LAST_INDEX(t, m) ((m).index == TEXT_LENGTH(t)) #define LAST_INDEX(t, m) ((m).index == TEXT_LENGTH(t))
#define CACHE_DATA(c) (*(LineParams*)(c)->data) #define CACHE_DATA(c) (*(LineParams*)(c)->data)
#define GTK_TEXT_INDEX(t, index) ((index) < (t)->gap_position ? (t)->text[index] : \
(t)->text[(index) + (t)->gap_size])
typedef struct _TextFont TextFont; typedef struct _TextFont TextFont;
typedef struct _TextProperty TextProperty; typedef struct _TextProperty TextProperty;
typedef struct _TabStopMark TabStopMark; typedef struct _TabStopMark TabStopMark;

View File

@ -200,7 +200,8 @@ static void gtk_widget_propagate_state (GtkWidget *widget,
static void gtk_widget_draw_children_recurse (GtkWidget *widget, static void gtk_widget_draw_children_recurse (GtkWidget *widget,
gpointer client_data); gpointer client_data);
static void gtk_widget_set_style_internal (GtkWidget *widget, static void gtk_widget_set_style_internal (GtkWidget *widget,
GtkStyle *style); GtkStyle *style,
gboolean initial_emission);
static void gtk_widget_set_style_recurse (GtkWidget *widget, static void gtk_widget_set_style_recurse (GtkWidget *widget,
gpointer client_data); gpointer client_data);
@ -1631,6 +1632,7 @@ gtk_widget_size_request (GtkWidget *widget,
g_return_if_fail (widget != NULL); g_return_if_fail (widget != NULL);
gtk_widget_ref (widget); gtk_widget_ref (widget);
gtk_widget_ensure_style (widget);
gtk_signal_emit (GTK_OBJECT (widget), widget_signals[SIZE_REQUEST], gtk_signal_emit (GTK_OBJECT (widget), widget_signals[SIZE_REQUEST],
requisition); requisition);
aux_info = gtk_object_get_data (GTK_OBJECT (widget), aux_info_key); aux_info = gtk_object_get_data (GTK_OBJECT (widget), aux_info_key);
@ -2337,10 +2339,13 @@ gtk_widget_set_style (GtkWidget *widget,
GtkStyle *style) GtkStyle *style)
{ {
GtkStyle *default_style; GtkStyle *default_style;
gboolean initial_emission;
g_return_if_fail (widget != NULL); g_return_if_fail (widget != NULL);
g_return_if_fail (style != NULL); g_return_if_fail (style != NULL);
initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE); GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE); GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
@ -2351,7 +2356,7 @@ gtk_widget_set_style (GtkWidget *widget,
gtk_object_set_data (GTK_OBJECT (widget), saved_default_style, widget->style); gtk_object_set_data (GTK_OBJECT (widget), saved_default_style, widget->style);
} }
gtk_widget_set_style_internal (widget, style); gtk_widget_set_style_internal (widget, style, initial_emission);
} }
void void
@ -2367,9 +2372,12 @@ gtk_widget_set_rc_style (GtkWidget *widget)
{ {
GtkStyle *saved_style; GtkStyle *saved_style;
GtkStyle *new_style; GtkStyle *new_style;
gboolean initial_emission;
g_return_if_fail (widget != NULL); g_return_if_fail (widget != NULL);
initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE); GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE); GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
@ -2382,16 +2390,24 @@ gtk_widget_set_rc_style (GtkWidget *widget)
gtk_style_ref (widget->style); gtk_style_ref (widget->style);
gtk_object_set_data (GTK_OBJECT (widget), saved_default_style, widget->style); gtk_object_set_data (GTK_OBJECT (widget), saved_default_style, widget->style);
} }
gtk_widget_set_style_internal (widget, new_style); gtk_widget_set_style_internal (widget, new_style, initial_emission);
} }
else else
{ {
if (saved_style) if (saved_style)
{ {
g_assert (initial_emission == FALSE); /* FIXME: remove this line */
gtk_object_remove_data (GTK_OBJECT (widget), saved_default_style); gtk_object_remove_data (GTK_OBJECT (widget), saved_default_style);
gtk_widget_set_style_internal (widget, saved_style); gtk_widget_set_style_internal (widget, saved_style, initial_emission);
gtk_style_unref (saved_style); gtk_style_unref (saved_style);
} }
else
{
g_assert (initial_emission == TRUE); /* FIXME: remove this line */
gtk_widget_set_style_internal (widget, new_style, TRUE);
}
} }
} }
@ -2414,7 +2430,8 @@ gtk_widget_style_set (GtkWidget *widget,
static void static void
gtk_widget_set_style_internal (GtkWidget *widget, gtk_widget_set_style_internal (GtkWidget *widget,
GtkStyle *style) GtkStyle *style,
gboolean initial_emission)
{ {
g_return_if_fail (widget != NULL); g_return_if_fail (widget != NULL);
g_return_if_fail (style != NULL); g_return_if_fail (style != NULL);
@ -2433,7 +2450,9 @@ gtk_widget_set_style_internal (GtkWidget *widget,
if (GTK_WIDGET_REALIZED (widget)) if (GTK_WIDGET_REALIZED (widget))
widget->style = gtk_style_attach (widget->style, widget->window); widget->style = gtk_style_attach (widget->style, widget->window);
gtk_signal_emit (GTK_OBJECT (widget), widget_signals[STYLE_SET], previous_style); gtk_signal_emit (GTK_OBJECT (widget),
widget_signals[STYLE_SET],
initial_emission ? NULL : previous_style);
gtk_style_unref (previous_style); gtk_style_unref (previous_style);
if (widget->parent) if (widget->parent)
@ -2450,6 +2469,12 @@ gtk_widget_set_style_internal (GtkWidget *widget,
gtk_widget_queue_draw (widget); gtk_widget_queue_draw (widget);
} }
} }
else if (initial_emission)
{
gtk_signal_emit (GTK_OBJECT (widget),
widget_signals[STYLE_SET],
NULL);
}
} }
static void static void

View File

@ -36,7 +36,7 @@ style "button"
style 'main_button' = 'button' style 'main_button' = 'button'
{ {
font = "-adobe-helvetica-medium-r-normal--*-100-*-*-*-*-*-*" font = "-adobe-helvetica-medium-r-normal--*-100-*-*-*-*-*-*"
bg[PRELIGHT] = { 0, 0x00, 0.75 } bg[PRELIGHT] = { 0, 0.75, 0x00 }
} }
style "toggle_button" = "button" style "toggle_button" = "button"

View File

@ -36,7 +36,7 @@ style "button"
style 'main_button' = 'button' style 'main_button' = 'button'
{ {
font = "-adobe-helvetica-medium-r-normal--*-100-*-*-*-*-*-*" font = "-adobe-helvetica-medium-r-normal--*-100-*-*-*-*-*-*"
bg[PRELIGHT] = { 0, 0x00, 0.75 } bg[PRELIGHT] = { 0, 0.75, 0x00 }
} }
style "toggle_button" = "button" style "toggle_button" = "button"