SetSelection on wxTextCtrl is intermittent

Ron Burkey rburkey2005 at earthlink.net
Thu Mar 27 06:04:19 PDT 2008


WX      : 2.8.7
OS      : Fedora Core 5
COMPILER: gcc 4.1.1

(I've experienced the same problem I'm going to describe with WX 2.6.3
on Fedora Core 5, as well as on SuSE 10.0 though I don't know what
version of WX I was using with SuSE.  I have not been able to reproduce
it with WX 2.4.2 on Fedora Core 1.)

The problem is basically that SetSelection with wxTextCtrl works
sometimes, and at other times it does nothing.  The problem can be
seen using one of the wxWidgets sample programs, text.cpp.  Simply make
the following modification:

void MyPanel::DoReplaceText()
{
    long start, end;
    // The following line is the only one ORIGINALLY in text.cpp.
    GetFocusedText()->Replace(3, 8, _T("ABC"));
    GetFocusedText()->SetSelection (3, 8);
    GetFocusedText()->GetSelection (&start, &end);
    printf ("start=%ld end=%ld\n", start, end);
}

Run the sample program, focus any of the text areas, and hit Ctrl-R
repeatedly.  The normal function of the sample program when you do this
is to replace the 3rd through 8th characters within the focused area by
"ABC", and with my change it should then select characters 3-8. 
Sometimes it does, sometimes it doesn't. Here's a cut-and-paste of some
of the console messages printed after the GetSelection when I do this:

...
start=3 end=8
start=3 end=8
start=8 end=8
start=3 end=8
start=8 end=8
start=3 end=8
start=3 end=8
start=3 end=8
start=8 end=8
start=3 end=8
start=8 end=8
start=3 end=8
start=8 end=8
...

I've spent a lot of time googling and looking at the mailing-list
archives without success, but haven't a clue as to how to work 
around this.

Thanks!
Ron Burkey





More information about the wx-users mailing list