wxTextCtrl Selected Text Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
miclus
Can't get richer than this
Can't get richer than this
Posts: 741
Joined: Tue Mar 31, 2009 2:11 am

wxTextCtrl Selected Text

Post by miclus » Thu Oct 22, 2009 6:50 am

Hi. How do you make it so text stays selected when the contents of a text control change? Every time the contents change, my selection gets unselected...

spectrum
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Sat Jul 21, 2007 12:17 pm

Post by spectrum » Thu Oct 22, 2009 10:55 am

i would try to reselect all, inside the "change" event.

See:
wxTextCtrl documentation,
EVT_TEXT(id, func),
wxTextCtrl samples.

regards,
spectrum

miclus
Can't get richer than this
Can't get richer than this
Posts: 741
Joined: Tue Mar 31, 2009 2:11 am

Post by miclus » Tue Nov 24, 2009 6:44 pm

Ok, I traced it to this function:

Code: Select all


void wxRichTextCtrl::DoWriteText(const wxString& value, int flags)
{
    wxString valueUnix = wxTextFile::Translate(value, wxTextFileType_Unix);

    GetBuffer().InsertTextWithUndo(m_caretPosition+1, valueUnix, this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE);

    if ( flags & SetValue_SendEvent )
        SendTextUpdatedEvent();
}

Since AppendText doesn't use the flags, it can only be that InsertTextWithUndo line.

Any ideas how to stop it from deselecting selected text?

User avatar
doublemax
Moderator
Moderator
Posts: 15262
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax » Tue Nov 24, 2009 7:42 pm

That the selection gets lots when changing/adding text is pretty much standard behavior in any textcontrol in know of. I guess your only chance is to store/restore the selection yourself after adding text, but you might get an ugly flicker.
Use the source, Luke!

miclus
Can't get richer than this
Can't get richer than this
Posts: 741
Joined: Tue Mar 31, 2009 2:11 am

Post by miclus » Tue Nov 24, 2009 8:48 pm

Yeah, that's what I did. Works out ok. Thanks.

Post Reply