Page 1 of 1
wxSTC looses previous Selection...
Posted: Wed Mar 16, 2016 5:27 pm
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.
Re: wxSTC looses previous Selection...
Posted: Wed Mar 16, 2016 9:02 pm
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);
Re: wxSTC looses previous Selection...
Posted: Thu Mar 17, 2016 5:43 am
by dode
Actually the second piece of code did the job.
No i wonder how do i change the selection color ?
Kind Regards
Dode
Re: wxSTC looses previous Selection...
Posted: Thu Mar 17, 2016 1:23 pm
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