Caret thickness patch



HI All:

Attached is a patch which provides themeability for the text caret line
thickness, as an aspect ratio.  The previous aspect ratio was hard-wired
at 1:30, which makes for a very thin cursor which was too hard to see
for some users.

What it does:

(1) Adds a gtkwidget style param, "cursor-aspect-ratio"
(2) Adds a gtwidget param to the internal function
_gtk_draw_insertion_cursor
(3) Causes _gtk_draw_insertion_cursor to use the themed aspect ratio
when 
    rendering the text caret.

OK to commit?

Best regards,

-Bill
Index: gtk/gtkentry.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkentry.c,v
retrieving revision 1.177
diff -u -r1.177 gtkentry.c
--- gtk/gtkentry.c	2002/02/03 01:25:32	1.177
+++ gtk/gtkentry.c	2002/02/04 16:27:48
@@ -2789,13 +2789,13 @@
       cursor_location.width = 0;
       cursor_location.height = text_area_height - 2 * INNER_BORDER ;
       
-      _gtk_draw_insertion_cursor (entry->text_area, gc1,
+      _gtk_draw_insertion_cursor (widget, entry->text_area, gc1,
 				  &cursor_location, dir1);
       
       if (gc2)
 	{
 	  cursor_location.x = xoffset + x2;
-	  _gtk_draw_insertion_cursor (entry->text_area, gc2,
+	  _gtk_draw_insertion_cursor (widget, entry->text_area, gc2,
 				      &cursor_location, dir2);
 	}
     }
Index: gtk/gtklabel.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtklabel.c,v
retrieving revision 1.120
diff -u -r1.120 gtklabel.c
--- gtk/gtklabel.c	2002/01/28 18:52:46	1.120
+++ gtk/gtklabel.c	2002/02/04 16:27:52
@@ -1686,7 +1686,7 @@
       cursor_location.width = 0;
       cursor_location.height = PANGO_PIXELS (cursor1->height);
       
-      _gtk_draw_insertion_cursor (widget->window, gc1,
+      _gtk_draw_insertion_cursor (widget, widget->window, gc1,
 				  &cursor_location, dir1);
       
       if (gc2)
@@ -1696,7 +1696,7 @@
 	  cursor_location.width = 0;
 	  cursor_location.height = PANGO_PIXELS (cursor2->height);
 	  
-	  _gtk_draw_insertion_cursor (widget->window, gc2,
+	  _gtk_draw_insertion_cursor (widget, widget->window, gc2,
 				      &cursor_location, dir2);
 	}
     }
Index: gtk/gtkstyle.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkstyle.c,v
retrieving revision 1.104
diff -u -r1.104 gtkstyle.c
--- gtk/gtkstyle.c	2002/02/03 21:18:44	1.104
+++ gtk/gtkstyle.c	2002/02/04 16:27:55
@@ -5475,6 +5475,7 @@
 
 /**
  * _gtk_draw_insertion_cursor:
+ * @widget: a #GtkWidget
  * @drawable: a #GdkDrawable
  * @gc: a #GdkGC
  * @location: location where to draw the cursor (@location->width is ignored)
@@ -5486,16 +5487,23 @@
  * but merely a convenience function for drawing the standard cursor shape.
  **/
 void
-_gtk_draw_insertion_cursor (GdkDrawable      *drawable,
+_gtk_draw_insertion_cursor (GtkWidget        *widget,
+			    GdkDrawable      *drawable,
 			    GdkGC            *gc,
 			    GdkRectangle     *location,
 			    GtkTextDirection  dir)
 {
-  gint stem_width = location->height / 30 + 1;
-  gint arrow_width = stem_width + 1;
+  gint stem_width;
+  gint arrow_width;
   gint x, y;
   gint i;
+  gfloat cursor_aspect_ratio;
 
+  gtk_widget_style_get (widget, "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.36
diff -u -r1.36 gtkstyle.h
--- gtk/gtkstyle.h	2001/12/12 22:29:50	1.36
+++ gtk/gtkstyle.h	2002/02/04 16:27:56
@@ -866,7 +866,8 @@
 			   const gchar     *string);
 #endif /* GTK_DISABLE_DEPRECATED */
 
-void _gtk_draw_insertion_cursor (GdkDrawable      *drawable,
+void _gtk_draw_insertion_cursor (GtkWidget        *widget,
+				 GdkDrawable      *drawable,
 				 GdkGC            *gc,
 				 GdkRectangle     *location,
 				 GtkTextDirection  dir);
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	2002/02/04 16:27:56
@@ -859,7 +859,7 @@
  	      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 (widget, drawable, gc, &cursor_location, dir);
               gdk_gc_set_clip_rectangle (gc, NULL);
 
               cursor_list = cursor_list->next;
Index: gtk/gtktextview.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktextview.c,v
retrieving revision 1.166
diff -u -r1.166 gtktextview.c
--- gtk/gtktextview.c	2002/02/03 01:25:32	1.166
+++ gtk/gtktextview.c	2002/02/04 16:28:01
@@ -325,7 +325,7 @@
                                   GtkWidget    *child);
 static void gtk_text_view_forall (GtkContainer *container,
                                   gboolean      include_internals,
-                                  GtkCallback   callback,
+				  GtkCallback   callback,
                                   gpointer      callback_data);
 
 /* FIXME probably need the focus methods. */
@@ -642,8 +642,7 @@
 							       _("Color with which to draw insertion cursor"),
 							       GDK_TYPE_COLOR,
 							       G_PARAM_READABLE));
-
-
+  
   /*
    * Signals
    */
Index: gtk/gtkwidget.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwidget.c,v
retrieving revision 1.293
diff -u -r1.293 gtkwidget.c
--- gtk/gtkwidget.c	2002/01/30 03:32:13	1.293
+++ gtk/gtkwidget.c	2002/02/04 16:28:06
@@ -1072,6 +1072,12 @@
 							     _("Width, in pixels, between focus indicator and the widget 'box'."),
 							     0, G_MAXINT, 1,
 							     G_PARAM_READWRITE));
+  gtk_widget_class_install_style_property (klass,
+					   g_param_spec_float ("cursor_aspect_ratio",
+							       _("Cursor line aspect ratio"),
+							       _("Aspect ratio with which to draw insertion cursor"),
+							       0.0, 1.0, 0.033,
+							       G_PARAM_READABLE));
 
 }
 


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