Patch for blinking cursor in GtkEntry



Hi

Attached is a patch to allow the cursor in a GtkEntry to blink. It also
changes the cursor's shape so as to be more visually prominent (it now
looks and acts in a manner very similar to Qt). The patch has also been
uploaded to ftp.gtk.org/incoming as gtk-hovinen-991214-1.patch.gz.

I also uploaded the patch that I mentioned on gtk-devel-list yesterday
that changes the focus indicator for GtkButtons. It is uploaded as
gtk-hovinen-991213-1.patch.gz.

-Bradford Hovinen

"Prudence is a rich, ugly old maid courted by Incapacity."

        - William Blake, "Proverbs of Hell," 1793
Index: gtkentry.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkentry.c,v
retrieving revision 1.76
diff -r1.76 gtkentry.c
39a40
> #define CURSOR_TIMER_INT 750
157a159,161
> static void  gtk_entry_cursor_timer_reset (GtkEntry          *entry);
> static guint gtk_entry_cursor_timer_cb    (GtkWidget         *widget);
> 
359a364,366
>   
>   entry->cursor_timer = 0;
>   entry->cursor_visible = TRUE;
483a491,496
>   if (!editable && entry->cursor_timer)
>     {
>       gtk_timeout_remove (entry->cursor_timer);
>       entry->cursor_timer = 0;
>     }
> 
524a538,539
>   if (entry->cursor_timer)
>     gtk_timeout_remove (entry->cursor_timer);
742a758
> #if 0
749a766
> #endif
875c892,895
<   
---
> 
>   entry->cursor_visible = TRUE;
>   gtk_entry_cursor_timer_reset (entry);
> 
1036a1057,1059
>   entry->cursor_visible = TRUE;
>   gtk_entry_cursor_timer_reset (entry);
> 
1216a1240,1245
> 
>   if (GTK_EDITABLE (widget)->editable)
>     GTK_ENTRY (widget)->cursor_timer = 
>       gtk_timeout_add (CURSOR_TIMER_INT, 
>                        (GtkFunction) gtk_entry_cursor_timer_cb, widget);
> 
1234a1264,1269
>   if (GTK_ENTRY (widget)->cursor_timer)
>     {
>       gtk_timeout_remove (GTK_ENTRY (widget)->cursor_timer);
>       GTK_ENTRY (widget)->cursor_timer = 0;
>     }
> 
1235a1271
>   GTK_ENTRY (widget)->cursor_visible = TRUE;
1440c1476
<   gint xoffset;
---
>   gint xoffset, prev_char_offset;
1452a1489,1491
>       
>       prev_char_offset = INNER_BORDER + entry->char_offset[editable->current_pos - 1];
>       prev_char_offset -= entry->scroll_offset;
1457c1496,1497
< 	  (editable->selection_start_pos == editable->selection_end_pos))
---
> 	  (editable->selection_start_pos == editable->selection_end_pos) &&
>           entry->cursor_visible)
1461a1502,1507
>           gdk_draw_line (drawable, widget->style->fg_gc[GTK_STATE_NORMAL],
>                          xoffset - 3, INNER_BORDER - 1,
>                          xoffset + 3, INNER_BORDER - 1);
>           gdk_draw_line (drawable, widget->style->fg_gc[GTK_STATE_NORMAL],
>                          xoffset - 3, text_area_height - INNER_BORDER,
>                          xoffset + 3, text_area_height - INNER_BORDER);
1469,1474d1514
< 
< 	  gtk_paint_flat_box (widget->style, drawable,
< 			      GTK_WIDGET_STATE(widget), GTK_SHADOW_NONE,
< 			      NULL, widget, "entry_bg", 
< 			      xoffset, INNER_BORDER, 
< 			      1, text_area_height - INNER_BORDER);
1476c1516
< 	  /* Draw the character under the cursor again
---
> 	  /* Draw the character(s) under the cursor again
1478,1479c1518
< 	  if ((editable->current_pos < entry->text_length) &&
< 	      (editable->selection_start_pos == editable->selection_end_pos))
---
> 	  if (editable->selection_start_pos == editable->selection_end_pos)
1481,1483c1520,1539
< 	      GdkWChar c = editable->visible ?
< 		                 *(entry->text + editable->current_pos) :
< 		                 '*';
---
>               guint nchars = (editable->current_pos == 0) ? 1 : 2;
> 	      GdkWChar *s, c[2];
>               
>               gtk_paint_flat_box (widget->style, drawable,
>                                   GTK_WIDGET_STATE(widget), GTK_SHADOW_NONE,
> 			          NULL, widget, "entry_bg", 
> 			          xoffset - 3, INNER_BORDER - 1, 
> 			          7, text_area_height - INNER_BORDER);
> 
>               if (editable->visible)
>                 {
>                   s = entry->text + editable->current_pos - nchars + 1;
>                 }
>               else
>                 {
>                   c[0] = '*';
>                   c[1] = (editable->current_pos == entry->text_length) 
>                               ? ' ' : '*';
>                   s = c;
>                 }
1484a1541,1542
>               if (nchars == 1) prev_char_offset = xoffset;
>               
1487c1545
< 				xoffset, yoffset, &c, 1);
---
> 				prev_char_offset, yoffset, s, nchars);
2313a2372,2415
> 
> static void
> gtk_entry_cursor_timer_reset (GtkEntry *entry)
> {
>   g_return_if_fail (entry != NULL);
>   g_return_if_fail (GTK_IS_ENTRY (entry));
>   
>   if (entry->cursor_timer)
>     {
>       gtk_timeout_remove (entry->cursor_timer);
>       entry->cursor_timer = 
>         gtk_timeout_add (CURSOR_TIMER_INT, 
>                          (GtkFunction) gtk_entry_cursor_timer_cb,
>                          entry);
>     }
> }
> 
> static guint
> gtk_entry_cursor_timer_cb (GtkWidget *widget)
> {
>   GtkEntry *entry;
> 
>   g_return_val_if_fail (widget != NULL, FALSE);
>   g_return_val_if_fail (GTK_IS_ENTRY (widget), FALSE);
> 
>   entry = GTK_ENTRY (widget);
> 
>   if (!GTK_WIDGET_HAS_FOCUS (widget))
>     return FALSE;
> 
>   if (entry->cursor_visible)
>     {
>       entry->cursor_visible = FALSE;
>       gtk_entry_draw_cursor (entry);
>     }
>   else if (!entry->cursor_visible)
>     {
>       entry->cursor_visible = TRUE;
>       gtk_entry_draw_cursor (entry);
>     }
> 
>   return TRUE;
> }
> 
Index: gtkentry.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkentry.h,v
retrieving revision 1.27
diff -r1.27 gtkentry.h
65a66,68
>   
>   guint    cursor_timer;    /* ID of event source for cursor timer */
>   gboolean cursor_visible;  /* True if cursor is displayed this timer iter. */


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