GtkEntry selection color when not focused



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.

Here is a patch that makes unfocused selected areas of GtkEntry be a 
different color:

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/28 19:23:46
@@ -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->text_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);

/ Alex






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