[gnome-panel] panel: Use horizontal/vertical padding for button widgets



commit 2fd32f37ff6cfb4772292ffb38329741c0f54c20
Author: Peter Hurley <peter hurleysoftware com>
Date:   Wed Jan 18 23:44:37 2012 -0500

    panel: Use horizontal/vertical padding for button widgets
    
    This avoids launcher being too close to each other.
    
    In addition, the "horizontal"/"vertical" class styles can be used to
    express the padding in a natural way:
    
         ButtonWidget.button.horizontal {
             padding : 0px 3px 0px 3px;
         }
    
    https://bugzilla.gnome.org/show_bug.cgi?id=668586

 gnome-panel/button-widget.c |   45 +++++++++++++++++++++++++++++++++++++-----
 1 files changed, 39 insertions(+), 6 deletions(-)
---
diff --git a/gnome-panel/button-widget.c b/gnome-panel/button-widget.c
index e61cec6..b21ccee 100644
--- a/gnome-panel/button-widget.c
+++ b/gnome-panel/button-widget.c
@@ -442,9 +442,17 @@ button_widget_get_preferred_width (GtkWidget *widget,
 
 	parent = gtk_widget_get_parent (widget);
 
-	if (button_widget->priv->orientation & PANEL_HORIZONTAL_MASK)
-		size = gtk_widget_get_allocated_height (parent);
-	else
+	if (button_widget->priv->orientation & PANEL_HORIZONTAL_MASK) {
+		GtkStyleContext *context;
+		GtkStateFlags    state;
+		GtkBorder        padding;
+
+		state = gtk_widget_get_state_flags (widget);
+		context = gtk_widget_get_style_context (widget);
+		gtk_style_context_get_padding (context, state, &padding);
+
+		size = gtk_widget_get_allocated_height (parent) + padding.left + padding.right;
+	} else
 		size = gtk_widget_get_allocated_width (parent);
 
 	*minimal_width = *natural_width = size;
@@ -463,8 +471,18 @@ button_widget_get_preferred_height (GtkWidget *widget,
 
 	if (button_widget->priv->orientation & PANEL_HORIZONTAL_MASK)
 		size = gtk_widget_get_allocated_height (parent);
-	else
-		size = gtk_widget_get_allocated_width (parent);
+	else {
+		GtkStyleContext *context;
+		GtkStateFlags    state;
+		GtkBorder        padding;
+
+		state = gtk_widget_get_state_flags (widget);
+		context = gtk_widget_get_style_context (widget);
+		gtk_style_context_get_padding (context, state, &padding);
+
+		size = gtk_widget_get_allocated_width (parent) + padding.top + padding.bottom;
+	}
+
 
 	*minimal_height = *natural_height = size;
 }
@@ -580,6 +598,8 @@ button_widget_leave_notify (GtkWidget *widget, GdkEventCrossing *event)
 static void
 button_widget_init (ButtonWidget *button)
 {
+	GtkStyleContext *context;
+
 	button->priv = BUTTON_WIDGET_GET_PRIVATE (button);
 
 	button->priv->icon_theme = NULL;
@@ -589,6 +609,8 @@ button_widget_init (ButtonWidget *button)
 	button->priv->filename   = NULL;
 	
 	button->priv->orientation = PANEL_ORIENTATION_TOP;
+	context = gtk_widget_get_style_context (GTK_WIDGET (button));
+	gtk_style_context_add_class (context, GTK_STYLE_CLASS_HORIZONTAL);
 
 	button->priv->size = 0;
 	
@@ -685,7 +707,6 @@ button_widget_class_init (ButtonWidgetClass *klass)
 					      "Whether to highlight the button on mouse over",
 					      TRUE,
 					      G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
-
 }
 
 GtkWidget *
@@ -762,6 +783,8 @@ void
 button_widget_set_orientation (ButtonWidget     *button,
 			       PanelOrientation  orientation)
 {
+	GtkStyleContext *context;
+
 	g_return_if_fail (BUTTON_IS_WIDGET (button));
 
 	if (button->priv->orientation == orientation)
@@ -769,6 +792,16 @@ button_widget_set_orientation (ButtonWidget     *button,
 
 	button->priv->orientation = orientation;
 
+	/* Use css class "horizontal"/"vertical" for theming */
+	context = gtk_widget_get_style_context (GTK_WIDGET (button));
+	if (orientation & PANEL_HORIZONTAL_MASK) {
+		gtk_style_context_remove_class (context, GTK_STYLE_CLASS_VERTICAL);
+		gtk_style_context_add_class (context, GTK_STYLE_CLASS_HORIZONTAL);
+	} else {
+		gtk_style_context_remove_class (context, GTK_STYLE_CLASS_HORIZONTAL);
+		gtk_style_context_add_class (context, GTK_STYLE_CLASS_VERTICAL);
+	}
+
 	/* Force a re-scale */
 	button->priv->size = -1;
 



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