Bug with wxStyledTextCtrl::GetCurrentPois in wxEVT_STC_UPDATEUI 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
Moonslate
Earned a small fee
Earned a small fee
Posts: 10
Joined: Sat Aug 24, 2019 10:09 am

Bug with wxStyledTextCtrl::GetCurrentPois in wxEVT_STC_UPDATEUI

Post by Moonslate » Sat Nov 23, 2019 6:32 pm

Steps to reproduce the error:

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);
	}
2 - Create an EVT_STC_UPDATEUI function and put this code inside:

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);
3 - Compile and run

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);
Sorry for the poor english.

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

Re: Bug with wxStyledTextCtrl::GetCurrentPois in wxEVT_STC_UPDATEUI

Post by doublemax » Sat Nov 23, 2019 9:43 pm

Thanks, but this is a user forum. Please use http://trac.wxwidgets.org to report bugs.
Use the source, Luke!

New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 352
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Re: Bug with wxStyledTextCtrl::GetCurrentPois in wxEVT_STC_UPDATEUI

Post by New Pagodi » Sat Nov 23, 2019 10:47 pm

This sounds like this issue. It was recently fixed. If you can, try using the latest version from git. If that's not an option, try using CallAfter as discussed in the first comment on that ticket.

If your issue still happens with the latest version from git, open a new ticket.

Moonslate
Earned a small fee
Earned a small fee
Posts: 10
Joined: Sat Aug 24, 2019 10:09 am

Re: Bug with wxStyledTextCtrl::GetCurrentPois in wxEVT_STC_UPDATEUI

Post by Moonslate » Tue Nov 26, 2019 8:21 pm

doublemax wrote:
Sat Nov 23, 2019 9:43 pm
Thanks, but this is a user forum. Please use http://trac.wxwidgets.org to report bugs.
Sorry, if I face any other problem, I`ll use that link.
New Pagodi wrote:
Sat Nov 23, 2019 10:47 pm
This sounds like this issue. It was recently fixed. If you can, try using the latest version from git. If that's not an option, try using CallAfter as discussed in the first comment on that ticket.

If your issue still happens with the latest version from git, open a new ticket.
The CallAfter method worked. Very thanks.

Post Reply