Re: GtkEntry selection color when not focused
- From: Alex Larsson <alexl redhat com>
- To: <gtk-devel-list gnome org>
- Subject: Re: GtkEntry selection color when not focused
- Date: Wed, 29 Aug 2001 15:53:03 -0400 (EDT)
On Tue, 28 Aug 2001, Alex Larsson wrote:
> Having the color of the selection being the same when the widget is
> unfocused can be really confusing. I noticed this yesterday when testing
> the mnemonics in the color selector. Pressing alt-h toggles focus between
> the help button and the Hue entry, but the Hue entry never changes
> visually. Instead the "OK" button gets the default grab when the help
> button looses it, so it looks like focus is toggled between the ok and the
> help button.
Ok. Here is a new version that adds it to GtkEntry, GtkText and
GtkTextView. jrb is working on the corresponding GtkTreeView change.
I started doing the same for selectable labels, but it was a lot harder,
because selectable labels never get focus. What we need to do there is to
make selectable labels have cursor and keynav support. Then they need to
be made focusable, but not be in the tab focus chain.
But, in the meantime, can i check this in?
/ Alex
Index: gtk/gtkentry.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkentry.c,v
retrieving revision 1.146
diff -u -p -r1.146 gtkentry.c
--- gtk/gtkentry.c 2001/07/19 18:47:03 1.146
+++ gtk/gtkentry.c 2001/08/29 19:19:33
@@ -2500,6 +2500,8 @@ gtk_entry_draw_text (GtkEntry *entry)
gint start_index = g_utf8_offset_to_pointer (entry->text, start_pos) - entry->text;
gint end_index = g_utf8_offset_to_pointer (entry->text, end_pos) - entry->text;
GdkRegion *clip_region = gdk_region_new ();
+ GdkGC *text_gc;
+ GdkGC *selection_gc;
line = pango_layout_get_lines (layout)->data;
@@ -2507,6 +2509,17 @@ gtk_entry_draw_text (GtkEntry *entry)
pango_layout_get_extents (layout, NULL, &logical_rect);
+ if (GTK_WIDGET_HAS_FOCUS (entry))
+ {
+ selection_gc = widget->style->base_gc [GTK_STATE_SELECTED];
+ text_gc = widget->style->text_gc [GTK_STATE_SELECTED];
+ }
+ else
+ {
+ selection_gc = widget->style->bg_gc [GTK_STATE_ACTIVE];
+ text_gc = widget->style->fg_gc [GTK_STATE_ACTIVE];
+ }
+
for (i=0; i < n_ranges; i++)
{
GdkRectangle rect;
@@ -2515,18 +2528,18 @@ gtk_entry_draw_text (GtkEntry *entry)
rect.y = y;
rect.width = (ranges[2*i + 1] - ranges[2*i]) / PANGO_SCALE;
rect.height = logical_rect.height / PANGO_SCALE;
-
- gdk_draw_rectangle (entry->text_area, widget->style->base_gc [GTK_STATE_SELECTED], TRUE,
+
+ gdk_draw_rectangle (entry->text_area, selection_gc, TRUE,
rect.x, rect.y, rect.width, rect.height);
gdk_region_union_with_rect (clip_region, &rect);
}
- gdk_gc_set_clip_region (widget->style->text_gc [GTK_STATE_SELECTED], clip_region);
- gdk_draw_layout (entry->text_area, widget->style->text_gc [GTK_STATE_SELECTED],
+ gdk_gc_set_clip_region (text_gc, clip_region);
+ gdk_draw_layout (entry->text_area, text_gc,
x, y,
layout);
- gdk_gc_set_clip_region (widget->style->text_gc [GTK_STATE_SELECTED], NULL);
+ gdk_gc_set_clip_region (text_gc, NULL);
gdk_region_destroy (clip_region);
g_free (ranges);
Index: gtk/gtktext.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktext.c,v
retrieving revision 1.104
diff -u -p -r1.104 gtktext.c
--- gtk/gtktext.c 2001/07/18 23:39:23 1.104
+++ gtk/gtktext.c 2001/08/29 19:19:34
@@ -4750,7 +4750,7 @@ draw_bg_rect (GtkText* text, GtkProperty
mark->index < MAX(old_editable->selection_start_pos, old_editable->selection_end_pos)))
{
gtk_paint_flat_box(GTK_WIDGET(text)->style, text->text_area,
- old_editable->has_selection ?
+ old_editable->has_selection && GTK_WIDGET_HAS_FOCUS (text) ?
GTK_STATE_SELECTED : GTK_STATE_ACTIVE,
GTK_SHADOW_NONE,
NULL, GTK_WIDGET(text), "text",
@@ -4915,7 +4915,7 @@ draw_line (GtkText* text,
if ((mark.index >= selection_start_pos) &&
(mark.index < selection_end_pos))
{
- if (old_editable->has_selection)
+ if (old_editable->has_selection && GTK_WIDGET_HAS_FOCUS (text))
fg_gc = GTK_WIDGET(text)->style->text_gc[GTK_STATE_SELECTED];
else
fg_gc = GTK_WIDGET(text)->style->text_gc[GTK_STATE_ACTIVE];
Index: gtk/gtktextdisplay.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktextdisplay.c,v
retrieving revision 1.27
diff -u -p -r1.27 gtktextdisplay.c
--- gtk/gtktextdisplay.c 2001/08/07 20:56:48 1.27
+++ gtk/gtktextdisplay.c 2001/08/29 19:19:34
@@ -250,7 +250,10 @@ render_layout_line (GdkDrawable *
if (selected)
{
- fg_gc = render_state->widget->style->text_gc[GTK_STATE_SELECTED];
+ if (GTK_WIDGET_HAS_FOCUS (render_state->widget))
+ fg_gc = render_state->widget->style->text_gc[GTK_STATE_SELECTED];
+ else
+ fg_gc = render_state->widget->style->fg_gc [GTK_STATE_ACTIVE];
}
else
{
@@ -464,6 +467,7 @@ render_para (GdkDrawable *drawabl
PangoLayoutIter *iter;
PangoRectangle layout_logical;
int screen_width;
+ GdkGC *fg_gc, *bg_gc;
gboolean first = TRUE;
@@ -478,6 +482,17 @@ render_para (GdkDrawable *drawabl
screen_width = line_display->total_width;
+ if (GTK_WIDGET_HAS_FOCUS (render_state->widget))
+ {
+ fg_gc = render_state->widget->style->text_gc [GTK_STATE_SELECTED];
+ bg_gc = render_state->widget->style->base_gc [GTK_STATE_SELECTED];
+ }
+ else
+ {
+ fg_gc = render_state->widget->style->fg_gc [GTK_STATE_ACTIVE];
+ bg_gc = render_state->widget->style->bg_gc [GTK_STATE_ACTIVE];
+ }
+
do
{
PangoLayoutLine *line = pango_layout_iter_get_line (iter);
@@ -517,7 +532,7 @@ render_para (GdkDrawable *drawabl
selection_end_index > line->length + byte_offset) /* All selected */
{
gdk_draw_rectangle (drawable,
- render_state->widget->style->base_gc[GTK_STATE_SELECTED],
+ bg_gc,
TRUE,
x + line_display->left_margin,
selection_y,
@@ -547,12 +562,11 @@ render_para (GdkDrawable *drawabl
selection_y,
selection_height,
selection_start_index, selection_end_index);
-
- gdk_gc_set_clip_region (render_state->widget->style->text_gc [GTK_STATE_SELECTED], clip_region);
- gdk_gc_set_clip_region (render_state->widget->style->base_gc [GTK_STATE_SELECTED], clip_region);
+ gdk_gc_set_clip_region (fg_gc, clip_region);
+ gdk_gc_set_clip_region (bg_gc, clip_region);
gdk_draw_rectangle (drawable,
- render_state->widget->style->base_gc[GTK_STATE_SELECTED],
+ bg_gc,
TRUE,
x + PANGO_PIXELS (line_rect.x),
selection_y,
@@ -564,8 +578,8 @@ render_para (GdkDrawable *drawabl
y + PANGO_PIXELS (baseline),
TRUE);
- gdk_gc_set_clip_region (render_state->widget->style->text_gc [GTK_STATE_SELECTED], NULL);
- gdk_gc_set_clip_region (render_state->widget->style->base_gc [GTK_STATE_SELECTED], NULL);
+ gdk_gc_set_clip_region (fg_gc, NULL);
+ gdk_gc_set_clip_region (bg_gc, NULL);
gdk_region_destroy (clip_region);
@@ -575,7 +589,7 @@ render_para (GdkDrawable *drawabl
(line_display->direction == GTK_TEXT_DIR_RTL && selection_end_index > byte_offset + line->length)))
{
gdk_draw_rectangle (drawable,
- render_state->widget->style->base_gc[GTK_STATE_SELECTED],
+ bg_gc,
TRUE,
x + line_display->left_margin,
selection_y,
@@ -595,7 +609,7 @@ render_para (GdkDrawable *drawabl
PANGO_PIXELS (line_rect.x) - PANGO_PIXELS (line_rect.width);
gdk_draw_rectangle (drawable,
- render_state->widget->style->base_gc[GTK_STATE_SELECTED],
+ bg_gc,
TRUE,
x + PANGO_PIXELS (line_rect.x) + PANGO_PIXELS (line_rect.width),
selection_y,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]