SetSelection on wxTextCtrl is intermittent
Ron Burkey
rburkey2005 at earthlink.net
Thu Mar 27 14:28:08 PDT 2008
On Thu, 2008-03-27 at 16:12 -0500, Ron Burkey wrote:
> On Thu, 2008-03-27 at 15:27 -0500, Ron Burkey wrote:
> > On Thu, 2008-03-27 at 20:07 +0100, Vadim Zeitlin wrote:
> > > Unfortunately I don't see the problem neither in the trunk nor with the
> > > latest 2.8 sources so I can't debug it. Moreover, looking at SetSelection()
> > > code I really don't see much scope for bugs in it (although I wonder why
> > > does it set selection from "to" to "from" rather than vice versa). If you
> > > can reproduce the problem more or less reliably, it would be nice if you
> > > could look at the iterators there when the bug occurs. Or maybe put some
> > > printf()s there too.
> > >
> >
> > I'm happy to try it, except that I don't understand what you mean. Is
> > there a "for dummies" version of that? (You could regard me as an
> > expert C programmer, but I've never exerted myself to learn more than
> > the minimum about C++ and my knowledge of the internals of wxWidgets is
> > pretty minimal.)
> >
> > -- Ron
> >
>
> Never mind, I see that you mean to put some printf()s into
> wxTextCtrl::SetSelection in gtk/textctrl.cpp. I'll check it out.
>
I added the following code and ran text.cpp again:
void wxTextCtrl::SetSelection( long from, long to )
{
wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
if (from == -1 && to == -1)
{
from = 0;
to = GetValue().length();
}
if ( IsMultiLine() )
{
GtkTextIter fromi, toi;
gtk_text_buffer_get_iter_at_offset( m_buffer, &fromi, from );
gtk_text_buffer_get_iter_at_offset( m_buffer, &toi, to );
// Here's what I added ************************************
printf ("Raw: From=%ld To=%ld\n", from, to);
printf ("Iterators: From=%d To=%d\n",
gtk_text_iter_get_offset (&fromi),
gtk_text_iter_get_offset (&toi));
// ********************************************************
gtk_text_buffer_place_cursor( m_buffer, &toi );
gtk_text_buffer_move_mark_by_name( m_buffer, "selection_bound",
&fromi );
}
else
{
gtk_editable_select_region( GTK_EDITABLE(m_text), (gint)from,
(gint)to );
}
}
And here's what it shows when the selection fails:
Raw: From=3 To=8
Iterators: From=3 To=8
start=8 end=8
So at least the iterators are working properly.
-- Ron
More information about the wx-users
mailing list