SetSelection on wxTextCtrl is intermittent

Ron Burkey rburkey2005 at earthlink.net
Fri Mar 28 13:24:00 PDT 2008


On Fri, 2008-03-28 at 08:20 -0500, Ron Burkey wrote:
> On Fri, 2008-03-28 at 00:48 +0100, Vadim Zeitlin wrote:
> > ...
> > RB> 
> > RB> And here's what it shows when the selection fails:
> > RB> 
> > RB> Raw:  From=3 To=8
> > RB> Iterators:  From=3 To=8
> > RB> start=8 end=8
> > RB> 
> > RB> So at least the iterators are working properly.
> > 
> >  And the functions called later are simply not supposed to fail in this
> > case so I have no idea about what's going on, sorry. I can only think of a
> > bug in your GTK+ version but it probably doesn't help much...
> > 
> >  You could also try printf()ing the result of gtk_text_buffer_get_insert()
> > after gtk_text_buffer_place_cursor() call and the result of
> > gtk_text_buffer_get_selection_bound() after the move_mark one.
> > 
> 
> I think you're probably right, and it must be a bug in GTK+.  I'll try
> pursuing it in that direction.
> 

Hi Vadim,

Actually, I'm *not* sure any longer that it's a bug in gtk+.  I upgraded
from gtk+ 2.8.20 to 2.10.14, expecting it to solve the problem, but it
didn't, so I've been poking around further.

What appears to happen is this:  As you know, wxTextCtrl::SetSelection()
calls gtk_text_buffer_place_cursor() to set the insertion point at the
end of the selection (position 8 in the wxWidgets text.cpp sample
program, as quoted above).  This always works.

Then, also as you know,  wxTextCtrl:SetSelection() calls
gtk_text_buffer_move_mark_by_name() to place the beginning point of the
selection (3 in this example).  This also always works.

But *sometimes* gtk_text_buffer_move_mark() --- not
gtk_text_buffer_move_mark_by_name() --- is then somehow called and extra
time, and it moves the selection back to (8,8)!  

Here are some messages that I've gotten by adding printf()s to
samples/text.cpp, wxTextCtrl::SetSelection(),
gtk_text_buffer_move_mark(), and gtk_text_buffer_move_mark_by_name().
My commentary is preceded by pound signs.

------- printf() messages when the selection works: --------
# The following message is from gtk_text_buffer_move_mark_by_name.
Move mark by name
# ... and from when it calls gtk_text_buffer_move_mark.
gtk_text_buffer_move_mark where=3 (buffer=0x87c9358)
# According to SetSelection, it worked!
wxTextCtrl::SetSelection:  From=3 To=8
# According to GetSelection, it worked!
text:  actual start=3 end=8

---- printf() messages when the selection doesn't work: ----
Move mark by name
gtk_text_buffer_move_mark where=3 (buffer=0x87c9358)
# An extra call to gtk_text_buffer_move_mark somehow!
gtk_text_buffer_move_mark where=8 (buffer=0x87c9358)
wxTextCtrl::SetSelection:  No selection!
text:  actual start=8 end=8
	or sometimes
Move mark by name
gtk_text_buffer_move_mark where=3 (buffer=0x87c9358)
wxTextCtrl::SetSelection:  From=3 To=8
text:  actual start=3 end=8
# And extra call to gtk_text_buffer_move_mark somehow!
gtk_text_buffer_move_mark where=8 (buffer=0x87c9358)

I'll keep poking around, but if you have any further suggestions they'd
be welcomed.

Thanks,
Ron




More information about the wx-users mailing list