From 43cb6010cc65870b2a715fc0fe0baee4dce69b5c Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Fri, 3 Mar 2006 12:38:42 +0000 Subject: [PATCH] Applied modified patch from maemo-gtk which makes separators more 2006-03-03 Michael Natterer Applied modified patch from maemo-gtk which makes separators more themeable. Fixes bug #332022. * gtk/gtkwidget.c: added style properties "wide-separators", "separator-width" and "separator-height". * gtk/gtkhseparator.c * gtk/gtkvseparator.c * gtk/gtkmenuitem.c * gtk/gtktoolbar.c: honor the new settings and paint separators using gtk_paint_box() if wide-separators is true. --- ChangeLog | 14 +++++++++++ ChangeLog.pre-2-10 | 14 +++++++++++ gtk/gtkhseparator.c | 61 +++++++++++++++++++++++++++++++++++++-------- gtk/gtkmenuitem.c | 52 ++++++++++++++++++++++++++++---------- gtk/gtktoolbar.c | 58 +++++++++++++++++++++++++++++++++--------- gtk/gtkvseparator.c | 61 +++++++++++++++++++++++++++++++++++++-------- gtk/gtkwidget.c | 23 ++++++++++++++++- 7 files changed, 237 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6f808f240..bac6b6b83 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2006-03-03 Michael Natterer + + Applied modified patch from maemo-gtk which makes separators more + themeable. Fixes bug #332022. + + * gtk/gtkwidget.c: added style properties "wide-separators", + "separator-width" and "separator-height". + + * gtk/gtkhseparator.c + * gtk/gtkvseparator.c + * gtk/gtkmenuitem.c + * gtk/gtktoolbar.c: honor the new settings and paint separators + using gtk_paint_box() if wide-separators is true. + 2006-03-02 Dom Lachowicz * modules/engines/ms-windows/msw_style.c: Fix combobox theming diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 6f808f240..bac6b6b83 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,17 @@ +2006-03-03 Michael Natterer + + Applied modified patch from maemo-gtk which makes separators more + themeable. Fixes bug #332022. + + * gtk/gtkwidget.c: added style properties "wide-separators", + "separator-width" and "separator-height". + + * gtk/gtkhseparator.c + * gtk/gtkvseparator.c + * gtk/gtkmenuitem.c + * gtk/gtktoolbar.c: honor the new settings and paint separators + using gtk_paint_box() if wide-separators is true. + 2006-03-02 Dom Lachowicz * modules/engines/ms-windows/msw_style.c: Fix combobox theming diff --git a/gtk/gtkhseparator.c b/gtk/gtkhseparator.c index 80b6a991f..cc6c4f8a1 100644 --- a/gtk/gtkhseparator.c +++ b/gtk/gtkhseparator.c @@ -30,10 +30,12 @@ #include "gtkalias.h" -static void gtk_hseparator_class_init (GtkHSeparatorClass *klass); -static void gtk_hseparator_init (GtkHSeparator *hseparator); -static gint gtk_hseparator_expose (GtkWidget *widget, - GdkEventExpose *event); +static void gtk_hseparator_class_init (GtkHSeparatorClass *klass); +static void gtk_hseparator_init (GtkHSeparator *hseparator); +static void gtk_hseparator_size_request (GtkWidget *widget, + GtkRequisition *requisition); +static gint gtk_hseparator_expose (GtkWidget *widget, + GdkEventExpose *event); GType @@ -71,6 +73,7 @@ gtk_hseparator_class_init (GtkHSeparatorClass *class) widget_class = (GtkWidgetClass*) class; + widget_class->size_request = gtk_hseparator_size_request; widget_class->expose_event = gtk_hseparator_expose; } @@ -87,18 +90,56 @@ gtk_hseparator_new (void) return g_object_new (GTK_TYPE_HSEPARATOR, NULL); } +static void +gtk_hseparator_size_request (GtkWidget *widget, + GtkRequisition *requisition) +{ + gboolean wide_separators; + gint separator_height; + + gtk_widget_style_get (widget, + "wide-separators", &wide_separators, + "separator-height", &separator_height, + NULL); + + if (wide_separators) + requisition->height = separator_height; + else + requisition->height = widget->style->ythickness; +} static gint gtk_hseparator_expose (GtkWidget *widget, GdkEventExpose *event) { if (GTK_WIDGET_DRAWABLE (widget)) - gtk_paint_hline (widget->style, widget->window, GTK_WIDGET_STATE (widget), - &event->area, widget, "hseparator", - widget->allocation.x, - widget->allocation.x + widget->allocation.width - 1, - widget->allocation.y + (widget->allocation.height - - widget->style->ythickness) / 2); + { + gboolean wide_separators; + gint separator_height; + + gtk_widget_style_get (widget, + "wide-separators", &wide_separators, + "separator-height", &separator_height, + NULL); + + if (wide_separators) + gtk_paint_box (widget->style, widget->window, + GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT, + &event->area, widget, "hseparator", + widget->allocation.x, + widget->allocation.y + (widget->allocation.height - + separator_height) / 2, + widget->allocation.width, + separator_height); + else + gtk_paint_hline (widget->style, widget->window, + GTK_WIDGET_STATE (widget), + &event->area, widget, "hseparator", + widget->allocation.x, + widget->allocation.x + widget->allocation.width - 1, + widget->allocation.y + (widget->allocation.height - + widget->style->ythickness) / 2); + } return FALSE; } diff --git a/gtk/gtkmenuitem.c b/gtk/gtkmenuitem.c index 28e8db634..b58e13612 100644 --- a/gtk/gtkmenuitem.c +++ b/gtk/gtkmenuitem.c @@ -559,10 +559,20 @@ gtk_menu_item_size_request (GtkWidget *widget, requisition->width = MAX (requisition->width, get_minimum_width (widget)); } } - else + else /* separator item */ { - /* separator item */ - requisition->height += 4; + gboolean wide_separators; + gint separator_height; + + gtk_widget_style_get (widget, + "wide-separators", &wide_separators, + "separator-height", &separator_height, + NULL); + + if (wide_separators) + requisition->height += separator_height + widget->style->ythickness; + else + requisition->height += widget->style->ythickness * 2; } accel_width = 0; @@ -824,18 +834,34 @@ gtk_menu_item_paint (GtkWidget *widget, } else if (!GTK_BIN (menu_item)->child) { - guint horizontal_padding; + gboolean wide_separators; + gint separator_height; + guint horizontal_padding; gtk_widget_style_get (widget, - "horizontal-padding", &horizontal_padding, - NULL); - - gtk_paint_hline (widget->style, widget->window, GTK_STATE_NORMAL, - area, widget, "menuitem", - widget->allocation.x + horizontal_padding + widget->style->xthickness, - widget->allocation.x + widget->allocation.width - horizontal_padding - widget->style->xthickness - 1, - widget->allocation.y + (widget->allocation.height - - widget->style->ythickness) / 2); + "wide-separators", &wide_separators, + "separator-height", &separator_height, + "horizontal-padding", &horizontal_padding, + NULL); + + if (wide_separators) + gtk_paint_box (widget->style, widget->window, + GTK_STATE_NORMAL, GTK_SHADOW_ETCHED_OUT, + area, widget, "hseparator", + widget->allocation.x + horizontal_padding + widget->style->xthickness, + widget->allocation.y + (widget->allocation.height - + separator_height - + widget->style->ythickness) / 2, + widget->allocation.width - + 2 * (horizontal_padding + widget->style->xthickness), + separator_height); + else + gtk_paint_hline (widget->style, widget->window, + GTK_STATE_NORMAL, area, widget, "menuitem", + widget->allocation.x + horizontal_padding + widget->style->xthickness, + widget->allocation.x + widget->allocation.width - horizontal_padding - widget->style->xthickness - 1, + widget->allocation.y + (widget->allocation.height - + widget->style->ythickness) / 2); } } } diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c index 29196215e..09146a445 100644 --- a/gtk/gtktoolbar.c +++ b/gtk/gtktoolbar.c @@ -4852,21 +4852,55 @@ _gtk_toolbar_paint_space_line (GtkWidget *widget, if (orientation == GTK_ORIENTATION_HORIZONTAL) { - gtk_paint_vline (widget->style, widget->window, - GTK_WIDGET_STATE (widget), area, widget, - "toolbar", - allocation->y + allocation->height * start_fraction, - allocation->y + allocation->height * end_fraction, - allocation->x + (allocation->width - widget->style->xthickness) / 2); + gboolean wide_separators; + gint separator_width; + + gtk_widget_style_get (widget, + "wide-separators", &wide_separators, + "separator-width", &separator_width, + NULL); + + if (wide_separators) + gtk_paint_box (widget->style, widget->window, + GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT, + area, widget, "vseparator", + allocation->x + (allocation->width - separator_width) / 2, + allocation->y + allocation->height * start_fraction, + separator_width, + allocation->height * (end_fraction - start_fraction)); + else + gtk_paint_vline (widget->style, widget->window, + GTK_WIDGET_STATE (widget), area, widget, + "toolbar", + allocation->y + allocation->height * start_fraction, + allocation->y + allocation->height * end_fraction, + allocation->x + (allocation->width - widget->style->xthickness) / 2); } else { - gtk_paint_hline (widget->style, widget->window, - GTK_WIDGET_STATE (widget), area, widget, - "toolbar", - allocation->x + allocation->width * start_fraction, - allocation->x + allocation->width * end_fraction, - allocation->y + (allocation->height - widget->style->ythickness) / 2); + gboolean wide_separators; + gint separator_height; + + gtk_widget_style_get (widget, + "wide-separators", &wide_separators, + "separator-height", &separator_height, + NULL); + + if (wide_separators) + gtk_paint_box (widget->style, widget->window, + GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT, + area, widget, "hseparator", + allocation->x + allocation->width * start_fraction, + allocation->y + (allocation->height - separator_height) / 2, + allocation->width * (end_fraction - start_fraction), + separator_height); + else + gtk_paint_hline (widget->style, widget->window, + GTK_WIDGET_STATE (widget), area, widget, + "toolbar", + allocation->x + allocation->width * start_fraction, + allocation->x + allocation->width * end_fraction, + allocation->y + (allocation->height - widget->style->ythickness) / 2); } } diff --git a/gtk/gtkvseparator.c b/gtk/gtkvseparator.c index bbf517780..eca00ef48 100644 --- a/gtk/gtkvseparator.c +++ b/gtk/gtkvseparator.c @@ -30,10 +30,12 @@ #include "gtkalias.h" -static void gtk_vseparator_class_init (GtkVSeparatorClass *klass); -static void gtk_vseparator_init (GtkVSeparator *vseparator); -static gint gtk_vseparator_expose (GtkWidget *widget, - GdkEventExpose *event); +static void gtk_vseparator_class_init (GtkVSeparatorClass *klass); +static void gtk_vseparator_init (GtkVSeparator *vseparator); +static void gtk_vseparator_size_request (GtkWidget *widget, + GtkRequisition *requisition); +static gint gtk_vseparator_expose (GtkWidget *widget, + GdkEventExpose *event); GType @@ -71,6 +73,7 @@ gtk_vseparator_class_init (GtkVSeparatorClass *klass) widget_class = (GtkWidgetClass*) klass; + widget_class->size_request = gtk_vseparator_size_request; widget_class->expose_event = gtk_vseparator_expose; } @@ -87,18 +90,56 @@ gtk_vseparator_new (void) return g_object_new (GTK_TYPE_VSEPARATOR, NULL); } +static void +gtk_vseparator_size_request (GtkWidget *widget, + GtkRequisition *requisition) +{ + gboolean wide_separators; + gint separator_width; + + gtk_widget_style_get (widget, + "wide-separators", &wide_separators, + "separator-width", &separator_width, + NULL); + + if (wide_separators) + requisition->height = separator_width; + else + requisition->height = widget->style->xthickness; +} static gint gtk_vseparator_expose (GtkWidget *widget, GdkEventExpose *event) { if (GTK_WIDGET_DRAWABLE (widget)) - gtk_paint_vline (widget->style, widget->window, GTK_WIDGET_STATE (widget), - &event->area, widget, "vseparator", - widget->allocation.y, - widget->allocation.y + widget->allocation.height - 1, - widget->allocation.x + (widget->allocation.width - - widget->style->xthickness) / 2); + { + gboolean wide_separators; + gint separator_width; + + gtk_widget_style_get (widget, + "wide-separators", &wide_separators, + "separator-width", &separator_width, + NULL); + + if (wide_separators) + gtk_paint_box (widget->style, widget->window, + GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT, + &event->area, widget, "vseparator", + widget->allocation.x + (widget->allocation.width - + separator_width) / 2, + widget->allocation.y, + separator_width, + widget->allocation.height); + else + gtk_paint_vline (widget->style, widget->window, + GTK_WIDGET_STATE (widget), + &event->area, widget, "vseparator", + widget->allocation.y, + widget->allocation.y + widget->allocation.height - 1, + widget->allocation.x + (widget->allocation.width - + widget->style->xthickness) / 2); + } return FALSE; } diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 187028af1..2872df932 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -1515,7 +1515,28 @@ gtk_widget_class_init (GtkWidgetClass *klass) P_("Visited Link Color"), P_("Color of visited links"), GDK_TYPE_COLOR, - GTK_PARAM_READABLE)); + GTK_PARAM_READABLE)); + + gtk_widget_class_install_style_property (klass, + g_param_spec_boolean ("wide-separators", + P_("Wide Separators"), + P_("Whether separators have configurable width and should be drawn using a box instead of a line"), + FALSE, + GTK_PARAM_READABLE)); + + gtk_widget_class_install_style_property (klass, + g_param_spec_int ("separator-width", + P_("Separator Width"), + P_("The width of separators if wide-separators is TRUE"), + 0, 64, 0, + GTK_PARAM_READABLE)); + + gtk_widget_class_install_style_property (klass, + g_param_spec_int ("separator-height", + P_("Separator Height"), + P_("The height of separators if wide-separators is TRUE"), + 0, 64, 0, + GTK_PARAM_READABLE)); } static void