diff options
author | Owen Taylor <otaylor@redhat.com> | 2001-12-04 03:27:30 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2001-12-04 03:27:30 +0000 |
commit | 7537825b34bee7094b6bf2e4f3f1e551114ed022 (patch) | |
tree | fb77377ab8aeb2e537f2177554e1d2ec9d390ee2 /gtk/gtkhsv.c | |
parent | cac3ad31314da1c2b0a5c35f54f7328da5ed51a3 (diff) | |
download | gtk+-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/gtkhsv.c')
-rw-r--r-- | gtk/gtkhsv.c | 100 |
1 files changed, 67 insertions, 33 deletions
diff --git a/gtk/gtkhsv.c b/gtk/gtkhsv.c index db030e63b3..cc041c589d 100644 --- a/gtk/gtkhsv.c +++ b/gtk/gtkhsv.c @@ -23,6 +23,7 @@ */ #include <math.h> +#include <string.h> #include "gtksignal.h" #include "gtkhsv.h" #include "gdk/gdkkeysyms.h" @@ -85,30 +86,31 @@ enum { LAST_SIGNAL }; -static void gtk_hsv_class_init (GtkHSVClass *class); -static void gtk_hsv_init (GtkHSV *hsv); -static void gtk_hsv_destroy (GtkObject *object); -static void gtk_hsv_map (GtkWidget *widget); -static void gtk_hsv_unmap (GtkWidget *widget); -static void gtk_hsv_realize (GtkWidget *widget); -static void gtk_hsv_unrealize (GtkWidget *widget); -static void gtk_hsv_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void gtk_hsv_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static gint gtk_hsv_button_press (GtkWidget *widget, - GdkEventButton *event); -static gint gtk_hsv_button_release (GtkWidget *widget, - GdkEventButton *event); -static gint gtk_hsv_motion (GtkWidget *widget, - GdkEventMotion *event); -static gint gtk_hsv_expose (GtkWidget *widget, - GdkEventExpose *event); -static gboolean gtk_hsv_focus (GtkWidget *widget, - GtkDirectionType direction); - -static void gtk_hsv_move (GtkHSV *hsv, - GtkDirectionType dir); +static void gtk_hsv_class_init (GtkHSVClass *class); +static void gtk_hsv_init (GtkHSV *hsv); +static void gtk_hsv_destroy (GtkObject *object); +static void gtk_hsv_map (GtkWidget *widget); +static void gtk_hsv_unmap (GtkWidget *widget); +static void gtk_hsv_realize (GtkWidget *widget); +static void gtk_hsv_unrealize (GtkWidget *widget); +static void gtk_hsv_size_request (GtkWidget *widget, + GtkRequisition *requisition); +static void gtk_hsv_size_allocate (GtkWidget *widget, + GtkAllocation *allocation); +static gint gtk_hsv_button_press (GtkWidget *widget, + GdkEventButton *event); +static gint gtk_hsv_button_release (GtkWidget *widget, + GdkEventButton *event); +static gint gtk_hsv_motion (GtkWidget *widget, + GdkEventMotion *event); +static gint gtk_hsv_expose (GtkWidget *widget, + GdkEventExpose *event); +static gboolean gtk_hsv_focus (GtkWidget *widget, + GtkDirectionType direction); +static void gtk_hsv_move (GtkHSV *hsv, + GtkDirectionType dir); +static GdkGC * gtk_hsv_get_focus_gc (GtkHSV *hsv, + gint *line_width); static guint hsv_signals[LAST_SIGNAL]; static GtkWidgetClass *parent_class; @@ -1040,16 +1042,22 @@ paint_ring (GtkHSV *hsv, if (GTK_WIDGET_HAS_FOCUS (hsv) && priv->focus_on_ring) { - gdk_rgb_gc_set_foreground (priv->gc, 0x000000); + gint focus_width; + gint focus_halfwidth; + GdkGC *gc = gtk_hsv_get_focus_gc (hsv, &focus_width); + focus_halfwidth = (focus_width + 1) / 2; - gdk_draw_arc (drawable, priv->gc, FALSE, - -x, -y, - priv->size - 1, priv->size - 1, + gdk_draw_arc (drawable, gc, FALSE, + -x + focus_width/2, -y + focus_width/2, + priv->size - focus_width, priv->size - focus_width, 0, 360 * 64); - gdk_draw_arc (drawable, priv->gc, FALSE, - -x + priv->ring_width - 1, -y + priv->ring_width - 1, - priv->size - 2 * priv->ring_width + 1, priv->size - 2 * priv->ring_width + 1, + gdk_draw_arc (drawable, gc, FALSE, + -x + priv->ring_width - focus_halfwidth, -y + priv->ring_width - focus_halfwidth, + priv->size - 2 * priv->ring_width + focus_width, + priv->size - 2 * priv->ring_width + focus_width, 0, 360 * 64); + + g_object_unref (gc); } } @@ -1253,9 +1261,11 @@ paint_triangle (GtkHSV *hsv, if (GTK_WIDGET_HAS_FOCUS (hsv) && !priv->focus_on_ring) { - gdk_rgb_gc_set_foreground (priv->gc, 0x000000); + gint focus_width = 1; + GdkGC *gc = gtk_hsv_get_focus_gc (hsv, &focus_width); - gdk_draw_polygon (drawable, priv->gc, FALSE, points, 3); + gdk_draw_polygon (drawable, gc, FALSE, points, 3); + g_object_unref (gc); } /* Draw value marker */ @@ -1723,3 +1733,27 @@ gtk_hsv_move (GtkHSV *hsv, gtk_hsv_set_color (hsv, hue, sat, val); } +static GdkGC * +gtk_hsv_get_focus_gc (GtkHSV *hsv, + gint *line_width) +{ + GdkGC *focus_gc; + GtkWidget *widget = GTK_WIDGET (hsv); + gint8 *dash_list; + + focus_gc = gdk_gc_new (widget->window); + gdk_gc_copy (focus_gc, widget->style->fg_gc[GTK_WIDGET_STATE (widget)]); + + gtk_widget_style_get (widget, + "focus-line-width", line_width, + "focus-line-pattern", (gchar *)&dash_list, + NULL); + + gdk_gc_set_line_attributes (focus_gc, *line_width, + dash_list[0] ? GDK_LINE_ON_OFF_DASH : GDK_LINE_SOLID, + GDK_CAP_BUTT, GDK_JOIN_MITER); + if (dash_list[0]) + gdk_gc_set_dashes (focus_gc, 0, dash_list, strlen (dash_list)); + + return focus_gc; +} |