wxSTC looses previous Selection...

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
dode
Earned a small fee
Earned a small fee
Posts: 23
Joined: Sun Mar 06, 2016 10:22 am

wxSTC looses previous Selection...

Post by dode »

wxSTC looses previous Selection...

void wxSearchInFilesFrame::selectLine(uint iLine)
{
m_scintilla->GotoLine(iLine - 1);
int lineStart = m_scintilla->PositionFromLine(m_scintilla->GetCurrentLine());
int lineEnd = m_scintilla->PositionFromLine(m_scintilla->GetCurrentLine() + 1);
m_scintilla->SetSelection(lineStart, lineEnd);
}

Any Idea how to make it persistent.
New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 466
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Re: wxSTC looses previous Selection...

Post by New Pagodi »

I'm not sure what you're asking. Do you want to extend the selection from the old selection to iLine? If so, you could do something like

Code: Select all

int s = m_scintilla->GetSelectionStart();
int e = m_scintilla->GetSelectionEnd();
m_scintilla->GotoLine(iLine - 1);
int lineStart = m_scintilla->PositionFromLine(m_scintilla->GetCurrentLine());
int lineEnd = m_scintilla->PositionFromLine(m_scintilla->GetCurrentLine() + 1);
if(s<lineStart)
    m_scintilla->SetSelection(s, lineEnd);
else if(e<lineEnd)
    m_scintilla->SetSelection(lineStart, lineEnd);
else
    m_scintilla->SetSelection(lineStart, e);
Or if you want true multiple selections, you could do:

Code: Select all

int selections = m_scintilla->GetSelections();
std::vector<int> carets,anchors;

for(int i=0;i<selections;i++)
{
    carets.push_back(m_scintilla->GetSelectionNCaret(i));
    anchors.push_back(m_scintilla->GetSelectionNAnchor(i));
}

m_scintilla->GotoLine(iLine - 1);
int lineStart = m_scintilla->PositionFromLine(m_scintilla->GetCurrentLine());
int lineEnd = m_scintilla->PositionFromLine(m_scintilla->GetCurrentLine() + 1);

for(int i=0;i<selections;i++)
{
    m_scintilla->AddSelection(carets[i],anchors[i]);
}

m_scintilla->AddSelection(lineStart,lineEnd);
dode
Earned a small fee
Earned a small fee
Posts: 23
Joined: Sun Mar 06, 2016 10:22 am

Re: wxSTC looses previous Selection...

Post by dode »

Actually the second piece of code did the job.

No i wonder how do i change the selection color ?

Kind Regards
Dode
New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 466
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Re: wxSTC looses previous Selection...

Post by New Pagodi »

You can set the colors for the main selection with lines like:

Code: Select all

m_scintilla->SetSelForeground( true, wxColour(<red>,<green>,<blue>) );
m_scintilla->SetSelBackground( true, wxColour(<red>,<green>,<blue>) );
Setting colors for the additional selections is slightly different:

Code: Select all

m_scintilla->SetAdditionalSelBackground( wxColour(<red>,<green>,<blue>) );
m_scintilla->SetAdditionalSelForeground( wxColour(<red>,<green>,<blue>) );
You can also set a transparency level for selections with:

Code: Select all

m_scintilla->SetSelAlpha( <n> );
m_scintilla->SetAdditionalSelAlpha( <n> );
where <n> is an integer between 0 and 256 (256=no alpha). I've never been able to make anything look good using transparency though.

Incidentally, since STC has so many methods, I wrote a program that breaks the methods into categories and lets you try them out with a styled text control. If you're going to be doing a lot of work with that control, you might find it helpful.

wxStyledTextCtrl Method and Event Explorer
Post Reply