Text Caret ("insertion cursor") theme patch



Hi Folks:

Attached is a new version of a patch submitted via bugzilla some time 
ago for themeing the aspect ratio of the text insertion cursor/caret.

For people with impaired vision (or poor laptop displays ;-) the 
existing Gtk text cursor can be difficult to see.  One solution is to 
allow the 'aspect ratio' (default 1:30) of the cursor line to be themed 
via a gtksettings property.

The attached patch does this.  It requires a change to the internal 
convenience method _gtk_draw_insertion_cursor (), namely the addition of 
a trailing GtkWidget parameter from which the gtksettings property can 
be obtained.

Regards,

Bill

------
Bill Haneman x19279
Gnome Accessibility / Batik SVG Toolkit
Sun Microsystems Ireland 
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtk+/ChangeLog,v
retrieving revision 1.2650
diff -u -r1.2650 ChangeLog
--- ChangeLog	2001/11/30 23:17:28	1.2650
+++ ChangeLog	2001/12/03 11:42:26
@@ -1,3 +1,21 @@
+2001-12-03  Bill Haneman <bill haneman sun com>
+
+	* gtk/gtkstyle.[hc]:
+	Changed signature of _gtk_draw_insertion_cursor to add a
+	trailing GtkWidget parameter, required for support of high
+	contrast accessibility gtkrc themes, and for correct general-case
+	drawing of focus indication lines.
+
+	* gtk/gtkentry.c:
+	* gtk/gtklabel.c:
+	* gtk/gtktextdisplay.c:
+	Modify calls to _gtk_draw_insertion_cursor to use above API.
+
+	* gtk/gtksettings.c:
+	Added property gtk-cursor-aspect-ratio, to allow the thickness of
+	the text insertion cursor to be themed/specified as a user
+	preference, for accessibility. 
+	
 2001-11-30  jacob berkman  <jacob ximian com>
 
 	* gtk/gtknotebook.c (gtk_notebook_remove_tab_label): set the
Index: gtk/gtkentry.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkentry.c,v
retrieving revision 1.166
diff -u -r1.166 gtkentry.c
--- gtk/gtkentry.c	2001/11/21 21:44:08	1.166
+++ gtk/gtkentry.c	2001/12/03 11:42:27
@@ -2754,13 +2754,13 @@
       cursor_location.height = text_area_height - 2 * INNER_BORDER ;
       
       _gtk_draw_insertion_cursor (entry->text_area, gc1,
-				  &cursor_location, dir1);
+				  &cursor_location, dir1, GTK_WIDGET (entry));
       
       if (gc2)
 	{
 	  cursor_location.x = xoffset + x2;
 	  _gtk_draw_insertion_cursor (entry->text_area, gc2,
-				      &cursor_location, dir2);
+				      &cursor_location, dir2, GTK_WIDGET (entry));
 	}
     }
 }
Index: gtk/gtklabel.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtklabel.c,v
retrieving revision 1.112
diff -u -r1.112 gtklabel.c
--- gtk/gtklabel.c	2001/11/19 19:20:21	1.112
+++ gtk/gtklabel.c	2001/12/03 11:42:27
@@ -1672,7 +1672,7 @@
       cursor_location.height = PANGO_PIXELS (cursor1->height);
       
       _gtk_draw_insertion_cursor (widget->window, gc1,
-				  &cursor_location, dir1);
+				  &cursor_location, dir1, GTK_WIDGET (label));
       
       if (gc2)
 	{
@@ -1682,7 +1682,7 @@
 	  cursor_location.height = PANGO_PIXELS (cursor2->height);
 	  
 	  _gtk_draw_insertion_cursor (widget->window, gc2,
-				      &cursor_location, dir2);
+				      &cursor_location, dir2, GTK_WIDGET (label));
 	}
     }
 }
Index: gtk/gtksettings.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtksettings.c,v
retrieving revision 1.20
diff -u -r1.20 gtksettings.c
--- gtk/gtksettings.c	2001/11/13 00:53:36	1.20
+++ gtk/gtksettings.c	2001/12/03 11:42:27
@@ -27,6 +27,7 @@
   PROP_CURSOR_BLINK,
   PROP_CURSOR_BLINK_TIME,
   PROP_SPLIT_CURSOR,
+  PROP_CURSOR_ASPECT_RATIO,
   PROP_THEME_NAME,
   PROP_KEY_THEME_NAME,
   PROP_MENU_BAR_ACCEL
@@ -173,6 +174,14 @@
 								   G_PARAM_READWRITE),
                                              NULL);
   g_assert (result == PROP_SPLIT_CURSOR);
+  result = settings_install_property_parser (class,
+                                             g_param_spec_float ("gtk-cursor-aspect-ratio",
+								   _("Cursor Aspect Ratio"),
+								   _("The aspect ratio (thickness-to-height) of the text insertion cursor"),
+								   0.0, 0.5, 0.033,
+								   G_PARAM_READWRITE),
+                                             NULL);
+  g_assert (result == PROP_CURSOR_ASPECT_RATIO);
   result = settings_install_property_parser (class,
                                              g_param_spec_string ("gtk-theme-name",
 								   _("Theme Name"),
Index: gtk/gtkstyle.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkstyle.c,v
retrieving revision 1.88
diff -u -r1.88 gtkstyle.c
--- gtk/gtkstyle.c	2001/11/16 15:20:27	1.88
+++ gtk/gtkstyle.c	2001/12/03 11:42:28
@@ -5064,24 +5064,37 @@
  * @drawable: a #GdkDrawable
  * @gc: a #GdkGC
  * @location: location where to draw the cursor (@location->width is ignored)
+ * @cursor_aspect_ratio: a float which indicates the width-to-height aspect ratio
+ *       for the insertion cursor line.
  * @dir: text direction for the cursor, used to decide whether to draw a
  *       directional arrow on the cursor and in what direction. Unless both
  *       strong and weak cursors are displayed, this should be %GTK_TEXT_DIR_NONE.
+ * @widget: the widget containing the text for which the insertion cursor is
+ *       being drawn.
  * 
  * Draws a text caret on @drawable at @location. This is not a style function
  * but merely a convenience function for drawing the standard cursor shape.
  **/
 void
 _gtk_draw_insertion_cursor (GdkDrawable      *drawable,
-			    GdkGC            *gc,
-			    GdkRectangle     *location,
-			    GtkTextDirection  dir)
+				GdkGC            *gc,
+				GdkRectangle     *location,
+				GtkTextDirection  dir,
+				GtkWidget        *widget)
 {
-  gint stem_width = location->height / 30 + 1;
-  gint arrow_width = stem_width + 1;
+  gint stem_width;
+  gint arrow_width;
+  gfloat cursor_aspect_ratio;
   gint x, y;
   gint i;
-
+  
+  g_object_get (gtk_widget_get_settings (widget),
+		"gtk-cursor-aspect-ratio", &cursor_aspect_ratio,
+		NULL);
+  
+  stem_width = location->height * cursor_aspect_ratio + 1;
+  arrow_width = stem_width + 1;
+  
   for (i = 0; i < stem_width; i++)
     gdk_draw_line (drawable, gc,
 		   location->x + i - stem_width / 2, location->y,
Index: gtk/gtkstyle.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkstyle.h,v
retrieving revision 1.33
diff -u -r1.33 gtkstyle.h
--- gtk/gtkstyle.h	2001/10/22 14:31:05	1.33
+++ gtk/gtkstyle.h	2001/12/03 11:42:28
@@ -872,7 +872,8 @@
 void _gtk_draw_insertion_cursor (GdkDrawable      *drawable,
 				 GdkGC            *gc,
 				 GdkRectangle     *location,
-				 GtkTextDirection  dir);
+				 GtkTextDirection  dir,
+				 GtkWidget        *widget);
 
 #ifdef __cplusplus
 }
Index: gtk/gtktextdisplay.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktextdisplay.c,v
retrieving revision 1.33
diff -u -r1.33 gtktextdisplay.c
--- gtk/gtktextdisplay.c	2001/11/13 23:56:11	1.33
+++ gtk/gtktextdisplay.c	2001/12/03 11:42:28
@@ -859,7 +859,8 @@
  	      cursor_location.height = cursor->height;
  
 	      gdk_gc_set_clip_rectangle(gc, &clip);
- 	      _gtk_draw_insertion_cursor (drawable, gc, &cursor_location, dir);
+ 	      _gtk_draw_insertion_cursor (drawable, gc, &cursor_location, dir,
+					  widget);
               gdk_gc_set_clip_rectangle (gc, NULL);
 
               cursor_list = cursor_list->next;


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