diff options
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtkseparatortoolitem.c | 74 | ||||
-rw-r--r-- | gtk/gtktoolbar.c | 75 | ||||
-rw-r--r-- | gtk/gtktoolbar.h | 10 |
3 files changed, 62 insertions, 97 deletions
diff --git a/gtk/gtkseparatortoolitem.c b/gtk/gtkseparatortoolitem.c index 4c37597ca..9986a3057 100644 --- a/gtk/gtkseparatortoolitem.c +++ b/gtk/gtkseparatortoolitem.c @@ -26,14 +26,6 @@ #include "gtkintl.h" #include "gtktoolbar.h" -/* note: keep in sync with DEFAULT_SPACE_SIZE and DEFAULT_SPACE_STYLE in gtktoolbar.c */ -#define DEFAULT_SPACE_SIZE 4 -#define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE - -#define SPACE_LINE_DIVISION 10 -#define SPACE_LINE_START 3 -#define SPACE_LINE_END 7 - #define MENU_ID "gtk-separator-tool-item-menu-id" enum { @@ -59,8 +51,7 @@ static gboolean gtk_separator_tool_item_expose (GtkWidget GdkEventExpose *event); static void gtk_separator_tool_item_add (GtkContainer *container, GtkWidget *child); -static GtkToolbarSpaceStyle get_space_style (GtkToolItem *tool_item); -static gint get_space_size (GtkToolItem *tool_item); +static gint get_space_size (GtkToolItem *tool_item); @@ -99,26 +90,10 @@ gtk_separator_tool_item_get_type (void) return type; } -static GtkToolbarSpaceStyle -get_space_style (GtkToolItem *tool_item) -{ - GtkToolbarSpaceStyle space_style = DEFAULT_SPACE_STYLE; - GtkWidget *parent = GTK_WIDGET (tool_item)->parent; - - if (GTK_IS_TOOLBAR (parent)) - { - gtk_widget_style_get (parent, - "space_style", &space_style, - NULL); - } - - return space_style; -} - static gint get_space_size (GtkToolItem *tool_item) { - gint space_size = DEFAULT_SPACE_SIZE; + gint space_size = _gtk_toolbar_get_default_space_size(); GtkWidget *parent = GTK_WIDGET (tool_item)->parent; if (GTK_IS_TOOLBAR (parent)) @@ -176,7 +151,7 @@ static void gtk_separator_tool_item_add (GtkContainer *container, GtkWidget *child) { - g_warning("attempt to add a child to an GtkSeparatorToolItem"); + g_warning ("attempt to add a child to an GtkSeparatorToolItem"); } static gboolean @@ -252,44 +227,13 @@ static gboolean gtk_separator_tool_item_expose (GtkWidget *widget, GdkEventExpose *event) { - GtkToolItem *tool_item = GTK_TOOL_ITEM (widget); - GtkSeparatorToolItem *separator_tool_item = GTK_SEPARATOR_TOOL_ITEM (widget); - gint space_size; - GtkAllocation *allocation; - GtkOrientation orientation; - GdkRectangle *area; + GtkToolbar *toolbar = NULL; - if (separator_tool_item->priv->draw && - get_space_style (tool_item) == GTK_TOOLBAR_SPACE_LINE) - { - space_size = get_space_size (tool_item); - allocation = &(widget->allocation); - orientation = gtk_tool_item_get_orientation (tool_item); - area = &(event->area); - - if (orientation == GTK_ORIENTATION_HORIZONTAL) - { - gtk_paint_vline (widget->style, widget->window, - GTK_WIDGET_STATE (widget), area, widget, - "separator_tool_item", - allocation->y + allocation->height * - SPACE_LINE_START / SPACE_LINE_DIVISION, - allocation->y + allocation->height * - SPACE_LINE_END / SPACE_LINE_DIVISION, - allocation->x + (space_size - widget->style->xthickness) / 2); - } - else if (orientation == GTK_ORIENTATION_VERTICAL) - { - gtk_paint_hline (widget->style, widget->window, - GTK_WIDGET_STATE (widget), area, widget, - "separator_tool_item", - allocation->x + allocation->width * - SPACE_LINE_START / SPACE_LINE_DIVISION, - allocation->x + allocation->width * - SPACE_LINE_END / SPACE_LINE_DIVISION, - allocation->y + (space_size - widget->style->ythickness) / 2); - } - } + if (widget->parent && GTK_IS_TOOLBAR (widget->parent)) + toolbar = GTK_TOOLBAR (widget->parent); + + _gtk_toolbar_paint_space_line (widget, toolbar, + &(event->area), &widget->allocation); return FALSE; } diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c index 689025fc3..39a4a0bb1 100644 --- a/gtk/gtktoolbar.c +++ b/gtk/gtktoolbar.c @@ -58,9 +58,9 @@ typedef struct _ToolbarContent ToolbarContent; /* note: keep in sync with DEFAULT_SPACE_SIZE and DEFAULT_SPACE_STYLE in gtkseparatortoolitem.c */ #define DEFAULT_SPACE_SIZE 4 #define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_LINE -#define SPACE_LINE_DIVISION 10 -#define SPACE_LINE_START 3 -#define SPACE_LINE_END 7 +#define SPACE_LINE_DIVISION 10.0 +#define SPACE_LINE_START 3.0 +#define SPACE_LINE_END 7.0 #define DEFAULT_ICON_SIZE GTK_ICON_SIZE_LARGE_TOOLBAR #define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH @@ -3631,7 +3631,13 @@ toolbar_content_new_tool_item (GtkToolbar *toolbar, priv->content = g_list_insert (priv->content, content, pos); if (!is_placeholder) - toolbar->num_children++; + { + toolbar->num_children++; + + gtk_toolbar_stop_sliding (toolbar); + } + + gtk_widget_queue_resize (GTK_WIDGET (toolbar)); return content; } @@ -3744,24 +3750,32 @@ calculate_max_homogeneous_pixels (GtkWidget *widget) return PANGO_PIXELS (MAX_HOMOGENEOUS_N_CHARS * char_width); } -static void -gtk_toolbar_paint_space_line (GtkWidget *widget, - GdkRectangle *area, - ToolbarContent *content) +gint +_gtk_toolbar_get_default_space_size (void) { - GtkToolbar *toolbar; - gint space_size; - GtkAllocation *allocation = &(content->u.compatibility.space_allocation); - double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION); - double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION); - - g_return_if_fail (GTK_IS_TOOLBAR (widget)); + return DEFAULT_SPACE_SIZE; +} + +void +_gtk_toolbar_paint_space_line (GtkWidget *widget, + GtkToolbar *toolbar, + GdkRectangle *area, + GtkAllocation *allocation) +{ + const double start_fraction = (SPACE_LINE_START / SPACE_LINE_DIVISION); + const double end_fraction = (SPACE_LINE_END / SPACE_LINE_DIVISION); - toolbar = GTK_TOOLBAR (widget); + gint space_size; + GtkToolbarSpaceStyle space_style; + GtkOrientation orientation; + + g_return_if_fail (GTK_IS_WIDGET (widget)); space_size = get_space_size (toolbar); - - if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL) + space_style = get_space_style (toolbar); + orientation = toolbar? toolbar->orientation : GTK_ORIENTATION_HORIZONTAL; + + if (orientation == GTK_ORIENTATION_HORIZONTAL) { gtk_paint_vline (widget->style, widget->window, GTK_WIDGET_STATE (widget), area, widget, @@ -3805,7 +3819,9 @@ toolbar_content_expose (ToolbarContent *content, if (get_space_style (toolbar) == GTK_TOOLBAR_SPACE_LINE && content->u.compatibility.space_visible) { - gtk_toolbar_paint_space_line (GTK_WIDGET (toolbar), &expose->area, content); + _gtk_toolbar_paint_space_line (GTK_WIDGET (toolbar), toolbar, + &expose->area, + &content->u.compatibility.space_allocation); } return; } @@ -4409,9 +4425,12 @@ get_space_size (GtkToolbar *toolbar) { gint space_size = DEFAULT_SPACE_SIZE; - gtk_widget_style_get (GTK_WIDGET (toolbar), - "space_size", &space_size, - NULL); + if (toolbar) + { + gtk_widget_style_get (GTK_WIDGET (toolbar), + "space_size", &space_size, + NULL); + } return space_size; } @@ -4420,11 +4439,13 @@ static GtkToolbarSpaceStyle get_space_style (GtkToolbar *toolbar) { GtkToolbarSpaceStyle space_style = DEFAULT_SPACE_STYLE; - - gtk_widget_style_get (GTK_WIDGET (toolbar), - "space_style", &space_style, - NULL); - + + if (toolbar) + { + gtk_widget_style_get (GTK_WIDGET (toolbar), + "space_style", &space_style, + NULL); + } return space_style; } diff --git a/gtk/gtktoolbar.h b/gtk/gtktoolbar.h index a7fa7bdc7..693d2a7af 100644 --- a/gtk/gtktoolbar.h +++ b/gtk/gtktoolbar.h @@ -167,11 +167,11 @@ void gtk_toolbar_set_drop_highlight_item (GtkToolbar *toolbar, /* internal functions */ gchar * _gtk_toolbar_elide_underscores (const gchar *original); -/* these two functions actually accept NULL for the toolbar, in which case - * you'll get a default value - */ -int _gtk_toolbar_get_space_size (GtkToolbar *toolbar); -GtkToolbarSpaceStyle _gtk_toolbar_get_space_style (GtkToolbar *toolbar); +void _gtk_toolbar_paint_space_line (GtkWidget *widget, + GtkToolbar *toolbar, + GdkRectangle *area, + GtkAllocation *allocation); +gint _gtk_toolbar_get_default_space_size (void); #ifndef GTK_DISABLE_DEPRECATED void gtk_toolbar_set_icon_size (GtkToolbar *toolbar, |