m_maxLineLenght is, for this exemple, 28
#define LINEERROR_MASK 1
The marker was created with a 16x16 wxBitmap
1 - Create an inline function with this code and call this function in the OnStyleNeeded:
Code: Select all
int line = stc->GetCurrentLine();
int lenght = stc->GetLineLength(line);
if (lenght > m_maxLineLenght) {
if (!(stc->MarkerGet(line) & LINEERROR_MASK)) //Verify if the line already has that marker
stc->MarkerAdd(line, 0);
}
else {
if (stc->MarkerGet(line) & LINEERROR_MASK)
stc->MarkerDelete(line, 0);
}
Code: Select all
statusBar->SetStatusText(wxString("Ln: ") << stc->GetCurrentLine() + 1, 2);
//statusBar->SetStatusText(wxString("Col: ") << stc->GetColumn(stc->GetCurrentPos()), 4);
statusBar->SetStatusText(wxString("Sel: ") << stc->GetSelectionEnd() - stc->GetSelectionStart(), 3);
The application runs fine, when the line lenght is greater than 28, the marker is shown in that line.
4 - Remove the "//" in the second line of the EVT_STC_UPDATEUI and compile
Now the application starts, but when the line is greater than 28, the marker not show up, it only show the marker when the STC updates, don`t care how many char I type. e.g: scroll the scroll bar or breaking the line. And the STC looks pretty slow when I`m writing on the first line, and the line is lengt is > 28. If I write > 28 and break the line for the marker show, and delete chars, the marker don`t is removed.
This only happens when I call GetCurrentPos(), and looks like the marker don`t work well in the first line only.
STC construction:
Code: Select all
stc = new wxStyledTextCtrl(this, wxID_ANY);
stc->MarkerDefineBitmap(0, errorIcon);
stc->SetMarginType(0, wxSTC_MARGIN_NUMBER);
stc->SetMarginWidth(0, 16);
stc->StyleSetFont(NormalStyle, GetDefaultFont());
stc->StyleSetFont(VarStyle, GetDefaultFont());
stc->StyleSetFont(SimbolStyle, GetDefaultFont());
stc->StyleSetForeground(VarStyle, wxColor(0, 255, 0));
stc->StyleSetForeground(SimbolStyle, wxColor(0, 0, 255));
stc->SetLexer(wxSTC_LEX_CONTAINER);
stc->Bind(wxEVT_STC_STYLENEEDED, &MyFrame::stcOnStyleNeeded, this);
stc->Bind(wxEVT_STC_CHANGE, &MyFrame::stcOnModified, this);
stc->Bind(wxEVT_STC_UPDATEUI, &MyFrame::stcOnUi, this);