summaryrefslogtreecommitdiff
path: root/gtk/gtkbutton.c
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2001-12-04 03:27:30 +0000
committerOwen Taylor <otaylor@src.gnome.org>2001-12-04 03:27:30 +0000
commit7537825b34bee7094b6bf2e4f3f1e551114ed022 (patch)
treefb77377ab8aeb2e537f2177554e1d2ec9d390ee2 /gtk/gtkbutton.c
parentcac3ad31314da1c2b0a5c35f54f7328da5ed51a3 (diff)
downloadgtk+-7537825b34bee7094b6bf2e4f3f1e551114ed022.tar.gz
Patch from Bill Haneman (with many modifications) to make the focus color
Mon Dec 3 16:39:17 2001 Owen Taylor <otaylor@redhat.com> Patch from Bill Haneman (with many modifications) to make the focus color work on dark themes and to make the focus line width configurable. (#61079, #63074) * gtk/gtkwidget.c: Add style properties, ::focus-widget, ::focus-line-width, and ::focus-padding. * gtk/gtkstyle.[ch]: Make gtk_paint_focus() take a state argument as well so we can use fg[STATE] to draw instead of always drawing with black. Cange paint_focus() to respect GtkWidget::focus-width and GtkWidget::focus-line-pattern. Fix continuity problem where the default 1-1 stipple had a blob in one corner and a gap in the other. Change the interpretation of x/y/width/height to be the bounding box of the focus rect instead of the rectangle passed to gdk_draw_rectangle. * gtk/gtkcheckbutton.c gtk/gtklistitem.c gtk/gtknotebook.c gtk/gtkoptionmenu.c gtk/gtkradiobutton.c gtk/gtkspinbutton.c gtk/gtktextview.c gtk/gtktreeview.c: Handle ::focus-width and ::focus-line-padding. * gtk/gtkentry.c: Handle :;focus-width property; cleanup and remove duplicated code; fix drawing of focus rectangle when interior-focus = FALSE. (#63072, #63073) * gtk/gtkrange.c gtk/gtktext.c gtk/gtktreeitem.c gtk/gtktreeviewcolumn.c: Basic fixups to make compile; Range and TreeViewColumn will need more extensive fixing. * gtk/gtkcolorsel.c: Honor focus line attributes when drawing the focus on the color swatches. (#63071) * gtk/gtkhsv.c: Honor focus line attributes when drawing the focus for the ring and triangle. * docs/widget_geometry.txt: Start at documenting how various widgets are drawn. * gtk/gtkbutton.c (_gtk_button_paint): Export _gtk_button_paint() librarywide, so we don't have duplicate a bunch of code in gtktogglebutton.c. * gtk/gtktogglebutton.c: Use _gtk_button_paint().
Diffstat (limited to 'gtk/gtkbutton.c')
-rw-r--r--gtk/gtkbutton.c125
1 files changed, 54 insertions, 71 deletions
diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c
index e504d32f7f..c8958ed6cb 100644
--- a/gtk/gtkbutton.c
+++ b/gtk/gtkbutton.c
@@ -84,8 +84,6 @@ static void gtk_button_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void gtk_button_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
-static void gtk_button_paint (GtkWidget *widget,
- GdkRectangle *area);
static gint gtk_button_expose (GtkWidget *widget,
GdkEventExpose *event);
static gint gtk_button_button_press (GtkWidget *widget,
@@ -714,9 +712,15 @@ gtk_button_size_request (GtkWidget *widget,
GtkButton *button = GTK_BUTTON (widget);
GtkBorder default_border;
gboolean interior_focus;
+ gint focus_width;
+ gint focus_pad;
gtk_button_get_props (button, &default_border, NULL, &interior_focus);
-
+ gtk_widget_style_get (GTK_WIDGET (widget),
+ "focus-line-width", &focus_width,
+ "focus-padding", &focus_pad,
+ NULL);
+
requisition->width = (GTK_CONTAINER (widget)->border_width + CHILD_SPACING +
GTK_WIDGET (widget)->style->xthickness) * 2;
requisition->height = (GTK_CONTAINER (widget)->border_width + CHILD_SPACING +
@@ -737,12 +741,9 @@ gtk_button_size_request (GtkWidget *widget,
requisition->width += child_requisition.width;
requisition->height += child_requisition.height;
}
-
- if (interior_focus)
- {
- requisition->width += 2;
- requisition->height += 2;
- }
+
+ requisition->width += 2 * (focus_width + focus_pad);
+ requisition->height += 2 * (focus_width + focus_pad);
}
static void
@@ -758,7 +759,7 @@ gtk_button_size_allocate (GtkWidget *widget,
GtkBorder default_border;
gtk_button_get_props (button, &default_border, NULL, NULL);
-
+
widget->allocation = *allocation;
if (GTK_WIDGET_REALIZED (widget))
@@ -770,13 +771,13 @@ gtk_button_size_allocate (GtkWidget *widget,
if (GTK_BIN (button)->child && GTK_WIDGET_VISIBLE (GTK_BIN (button)->child))
{
- child_allocation.x = widget->allocation.x + border_width + (CHILD_SPACING + xthickness);
- child_allocation.y = widget->allocation.y + border_width + (CHILD_SPACING + ythickness);
-
- child_allocation.width = MAX (1, (gint)widget->allocation.width - (CHILD_SPACING + xthickness) * 2 -
- border_width * 2);
- child_allocation.height = MAX (1, (gint)widget->allocation.height - (CHILD_SPACING + ythickness) * 2 -
- border_width * 2);
+ child_allocation.x = widget->allocation.x + border_width + CHILD_SPACING + xthickness;
+ child_allocation.y = widget->allocation.y + border_width + CHILD_SPACING + ythickness;
+
+ child_allocation.width = MAX (1, widget->allocation.width - (CHILD_SPACING + xthickness) * 2 -
+ border_width * 2);
+ child_allocation.height = MAX (1, widget->allocation.height - (CHILD_SPACING + ythickness) * 2 -
+ border_width * 2);
if (GTK_WIDGET_CAN_DEFAULT (button))
{
@@ -803,51 +804,34 @@ gtk_button_size_allocate (GtkWidget *widget,
}
}
-/*
- * +------------------------------------------------+
- * | BORDER |
- * | +------------------------------------------+ |
- * | |\\\\\\\\\\\\\\\\DEFAULT\\\\\\\\\\\\\\\\\ | |
- * | |\\+------------------------------------+ | |
- * | |\\| | SPACING 3 | | | |
- * | |\\| +--------------------------------+ | | |
- * | |\\| |########## FOCUS ###############| | | |
- * | |\\| |#+----------------------------+#| | | |
- * | |\\| |#| RELIEF \|#| | | |
- * | |\\| |#| +-----------------------+\|#| | | |
- * | |\\|1|#| + THE TEXT +\|#|2| | |
- * | |\\| |#| +-----------------------+\|#| | | |
- * | |\\| |#| \\\\\ ythickness \\\\\\\\\\|#| | | |
- * | |\\| |#+----------------------------+#| | | |
- * | |\\| |########### 1 ##################| | | |
- * | |\\| +--------------------------------+ | | |
- * | |\\| | default spacing 4 | | | |
- * | |\\+------------------------------------+ | |
- * | |\ ythickness | |
- * | +------------------------------------------+ |
- * | border_width |
- * +------------------------------------------------+
- */
-
-static void
-gtk_button_paint (GtkWidget *widget,
- GdkRectangle *area)
+void
+_gtk_button_paint (GtkButton *button,
+ GdkRectangle *area,
+ GtkStateType state_type,
+ GtkShadowType shadow_type,
+ const gchar *main_detail,
+ const gchar *default_detail)
{
- GtkButton *button;
- GtkShadowType shadow_type;
+ GtkWidget *widget;
gint width, height;
gint x, y;
gint border_width;
GtkBorder default_border;
GtkBorder default_outside_border;
gboolean interior_focus;
+ gint focus_width;
+ gint focus_pad;
- if (GTK_WIDGET_DRAWABLE (widget))
+ if (GTK_WIDGET_DRAWABLE (button))
{
+ widget = GTK_WIDGET (button);
border_width = GTK_CONTAINER (widget)->border_width;
- button = GTK_BUTTON (widget);
gtk_button_get_props (button, &default_border, &default_outside_border, &interior_focus);
+ gtk_widget_style_get (GTK_WIDGET (widget),
+ "focus-line-width", &focus_width,
+ "focus-padding", &focus_pad,
+ NULL);
x = widget->allocation.x + border_width;
y = widget->allocation.y + border_width;
@@ -877,19 +861,17 @@ gtk_button_paint (GtkWidget *widget,
if (!interior_focus && GTK_WIDGET_HAS_FOCUS (widget))
{
- x += 1;
- y += 1;
- width -= 2;
- height -= 2;
+ x += focus_width + focus_pad;
+ y += focus_width + focus_pad;
+ width -= 2 * (focus_width + focus_pad);
+ height -= 2 * (focus_width + focus_pad);
}
- shadow_type = button->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT;
-
if ((button->relief != GTK_RELIEF_NONE) ||
((GTK_WIDGET_STATE(widget) != GTK_STATE_NORMAL) &&
(GTK_WIDGET_STATE(widget) != GTK_STATE_INSENSITIVE)))
gtk_paint_box (widget->style, widget->window,
- GTK_WIDGET_STATE (widget),
+ state_type,
shadow_type, area, widget, "button",
x, y, width, height);
@@ -897,22 +879,22 @@ gtk_button_paint (GtkWidget *widget,
{
if (interior_focus)
{
- x += widget->style->xthickness + 1;
- y += widget->style->ythickness + 1;
- width -= 2 * (widget->style->xthickness + 1);
- height -= 2 * (widget->style->xthickness + 1);
+ x += widget->style->xthickness + focus_pad;
+ y += widget->style->ythickness + focus_pad;
+ width -= 2 * (widget->style->xthickness + focus_pad);
+ height -= 2 * (widget->style->xthickness + focus_pad);
}
else
{
- x -= 1;
- y -= 1;
- width += 2;
- height += 2;
+ x -= focus_width + focus_pad;
+ y -= focus_width + focus_pad;
+ width += 2 * (focus_width + focus_pad);
+ height += 2 * (focus_width + focus_pad);
}
- gtk_paint_focus (widget->style, widget->window,
+ gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
area, widget, "button",
- x, y, width - 1, height - 1);
+ x, y, width, height);
}
}
}
@@ -921,17 +903,18 @@ static gboolean
gtk_button_expose (GtkWidget *widget,
GdkEventExpose *event)
{
- GtkBin *bin;
-
g_return_val_if_fail (widget != NULL, FALSE);
g_return_val_if_fail (GTK_IS_BUTTON (widget), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
if (GTK_WIDGET_DRAWABLE (widget))
{
- bin = GTK_BIN (widget);
+ GtkButton *button = GTK_BUTTON (widget);
- gtk_button_paint (widget, &event->area);
+ _gtk_button_paint (button, &event->area,
+ GTK_WIDGET_STATE (widget),
+ button->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT,
+ "button", "buttondefault");
(* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event);
}