Re: gtk_sheet_show_active_cell() performance enhancement

"Adrian E. Feiguin" <[email protected]> Fri, 25 Mar 2005 15:06:48 -0800
Newsgroups gmane.comp.scigraphica.gtkextra
Message-ID <[email protected]>
Hi John.

It looks like you are not introducing any bugs, and you are improving 
some performance. I'll add your patch to the code. I appreciate it. 
Thanks a lot for the contribution!

Saludos,
<ADRIAN>

John Gotts wrote:

>We have been annoyed for some time by a bug where if you change any color or
>text value in any cell, the selection in the active cell disappears.  For
>example, if you are currently working on cell (0,0) and some part of its text
>is highlighted and the background color for cell (4,4) changes to green and
>then you enter new text intending to replace the highlighted text, you will
>get unexpected results.  Adrian helped me pinpoint the
>gtk_sheet_show_active_cell() function.  At first I rewrote the function to save
>the old selection but then I realized that gtk_entry_set_text() and
>gtk_item_entry_set_text() are completely redundant if the old text didn't
>change.  As an added bonus, there is no flashing anymore and a better
>interactive response if there are a lot of sheet changes going on.
>
>If anyone can come up with a situation where my change breaks something, let me
>know.
>
>A more elegant fix would be to make even more code in
>gtk_sheet_show_active_cell() conditional and the best fix would be to invoke
>gtk_sheet_show_active_cell() only when necessary.
>
>John
>
>--- gtk+extra-0.99.16/gtkextra/gtksheet.c.orig	2005-03-19 02:11:07.000000000 -0500
>+++ gtk+extra-0.99.16/gtkextra/gtksheet.c	2005-03-19 02:50:17.000000000 -0500
>@@ -3687,6 +3687,7 @@
>  GtkEntry *sheet_entry;
>  GtkSheetCellAttr attributes;
>  gchar *text = NULL;
>+ gchar *old_text;
>  GtkJustification justification;
>  gint row, col;
> 
>@@ -3727,10 +3728,13 @@
> 
>  if(!text) text = g_strdup("");
> 
>- if(!GTK_IS_ITEM_ENTRY(sheet_entry))
>-    gtk_entry_set_text(GTK_ENTRY(sheet_entry), text);
>- else
>-    gtk_item_entry_set_text(GTK_ITEM_ENTRY(sheet_entry), text, justification);
>+ old_text = gtk_entry_get_text(GTK_ENTRY(sheet_entry));
>+ if (strcmp(old_text, text) != 0) {
>+  if(!GTK_IS_ITEM_ENTRY(sheet_entry))
>+     gtk_entry_set_text(GTK_ENTRY(sheet_entry), text);
>+  else
>+     gtk_item_entry_set_text(GTK_ITEM_ENTRY(sheet_entry), text, justification);
>+ }
> 
>  if(GTK_SHEET_IS_LOCKED(sheet) || !attributes.is_editable) 
>             gtk_entry_set_editable(GTK_ENTRY(sheet_entry), FALSE);
>
>  
>



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click