Author Topic: Strange cursor position with wx3.0.2 (scintilla)  (Read 8395 times)

Offline headkase

  • Almost regular
  • **
  • Posts: 159
Strange cursor position with wx3.0.2 (scintilla)
« on: December 20, 2015, 02:58:07 am »
Edit: Posts in this thread were split from: This thread.

The cursor issues are not new however, I have tried to build with 3.0.2 previously, as in months previously, ever so often and the issue has been present each time.  I always assumed that it was attributable to 3.0.2 not being "baked" enough.  However, I guess I should have reported it a long whiles back.  If the issue is in the Code::Blocks source then it has been present for a good while.

If you have any patches I can test apply to any specified SVN build then feel free to post them.  I will gladly recompile away if it helps to stomp out a bug or few.

Edit: I just rebuilt wxWidgets 3.0.2 64-bit without CFG=64 so I did not have to modify that variable in the SVN 10625 project.  Same error as given above.  I am, as stated in the first post, using MinGW-Builds 5.2.0 64 bit and I also have the 32 bit version as well.

Let's try a different tack.  You tell me exactly which compiler to use and either 32 or 64 bit or both and I will build the wxWidgets 3.0.2 versions with that toolchain.  That way we can also rule out MinGW-Builds as the compiler.
« Last Edit: December 21, 2015, 03:45:52 pm by headkase »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #1 on: December 20, 2015, 06:00:09 am »
What happens on my system, I can compile wxWidgets 3.0.2 64 bit with no errors.  Then I can build codeblocks wx 30 64 also with no errors.  Run it, it loads fine.  However, open a text window the cursor caret does not behave properly.  If you go up or down a line it may leave an old cursor bar graphic there, or up or down, left or right, all the arrow keys: it either leaves a artifact or does not update.  Either graphical garbage or an invisible caret.  No errors are thrown at all that I am aware of.  It just doesn't work like it's supposed to.

I am not a technical expert so I do not know where to begin troubleshooting that.  If you provide a concrete list of steps to try and report the results of then I would gladly do them.
I have 32 bit cb build myself with against wx3.0.2 under Windows XP.
I see some similar issue, see screen shot:

sometimes, I see two cursors in the previous locations, see screen shot:

Here is the steps to reproduce:
When I first put the cursor after the "main()", and I hit the arrow down key. I see the cursor is still there. After that, I hit the arrow down key again, I see the cursor is still there after the "{", and now the cursor is located after the "vector".
I guess it is related to highlight of the "()" or "{}".
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12129
    • Travis build status
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #2 on: December 20, 2015, 02:30:52 pm »
It works fine on linux when using wx3.0, so it might be windows only issue.

@Morten: Are you able to reproduce the problem?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #3 on: December 20, 2015, 03:22:30 pm »
It works fine on linux when using wx3.0, so it might be windows only issue.
It looks like it's an issue related to the "indicator" of the scintilla. I have download the latest wscite, but I don't know how to enable the brace indicator in it.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12129
    • Travis build status
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #4 on: December 20, 2015, 03:59:31 pm »
Matching brace highlighting works fine on linux. No visual artefacts observed.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9508
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #5 on: December 20, 2015, 05:38:05 pm »
@Morten: Are you able to reproduce the problem?
Works fine here, on windows with wx2.8.12 and trunk.

What are the editor options related to highlighting for you?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12129
    • Travis build status
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #6 on: December 20, 2015, 05:45:27 pm »
Morten: Please try wx3.0 or wx-master branch, if possible. The reported problem is with wx3.0.2.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #7 on: December 20, 2015, 07:37:55 pm »
Morten: Please try wx3.0 or wx-master branch, if possible. The reported problem is with wx3.0.2.
The thread-title is soewhat misleading in this case.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12129
    • Travis build status
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #8 on: December 20, 2015, 07:42:21 pm »
Jens: Yep...  ::)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9508
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #9 on: December 20, 2015, 08:25:02 pm »
Morten: Please try wx3.0 or wx-master branch, if possible. The reported problem is with wx3.0.2.
Yes, on wx3.0.2 it shows the effect. However, we should not seriously try to fix it in trunk. Instead, we should focus and fix the scintilla branch. I am still trying to get it working but so far I didn't have enough time to finish. We lack behind many versions already and there have been massive fundamental changes in the architecture of scintilla. So give it a try, if you like:
https://svn.code.sf.net/p/codeblocks/code/branches/scintilla_3_6_x
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12129
    • Travis build status
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #10 on: December 20, 2015, 09:31:58 pm »
No time at the moment. I'm concentrated on fixing all the asserts that come up with wx30.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline headkase

  • Almost regular
  • **
  • Posts: 159
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #11 on: December 20, 2015, 10:27:06 pm »
Morten: Please try wx3.0 or wx-master branch, if possible. The reported problem is with wx3.0.2.
The thread-title is soewhat misleading in this case.

Please feel free to split the thread - a simple observation on my part spawned an entire new branch.  ;)

Offline mageia

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #12 on: December 21, 2015, 05:01:42 am »
yes,wx3.02 the cursor is weird,select text hilight area is not what i select,also is because get the wrong cursor position?

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #13 on: December 21, 2015, 04:06:25 pm »
Morten: Please try wx3.0 or wx-master branch, if possible. The reported problem is with wx3.0.2.
Yes, on wx3.0.2 it shows the effect. However, we should not seriously try to fix it in trunk. Instead, we should focus and fix the scintilla branch. I am still trying to get it working but so far I didn't have enough time to finish. We lack behind many versions already and there have been massive fundamental changes in the architecture of scintilla. So give it a try, if you like:
https://svn.code.sf.net/p/codeblocks/code/branches/scintilla_3_6_x
A patch to fix the build error:
Code: [Select]
src/CodeBlocks_wx30.cbp | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/CodeBlocks_wx30.cbp b/src/CodeBlocks_wx30.cbp
index 263249e..d98b603 100644
--- a/src/CodeBlocks_wx30.cbp
+++ b/src/CodeBlocks_wx30.cbp
@@ -3416,6 +3416,9 @@
  <Unit filename="sdk/wxscintilla/src/scintilla/lexers/LexBasic.cxx">
  <Option target="scintilla" />
  </Unit>
+ <Unit filename="sdk/wxscintilla/src/scintilla/lexers/LexBatch.cxx">
+ <Option target="scintilla" />
+ </Unit>
  <Unit filename="sdk/wxscintilla/src/scintilla/lexers/LexBibTeX.cxx">
  <Option target="scintilla" />
  </Unit>
@@ -3461,6 +3464,9 @@
  <Unit filename="sdk/wxscintilla/src/scintilla/lexers/LexDMIS.cxx">
  <Option target="scintilla" />
  </Unit>
+ <Unit filename="sdk/wxscintilla/src/scintilla/lexers/LexDiff.cxx">
+ <Option target="scintilla" />
+ </Unit>
  <Unit filename="sdk/wxscintilla/src/scintilla/lexers/LexECL.cxx">
  <Option target="scintilla" />
  </Unit>
@@ -3473,6 +3479,9 @@
  <Unit filename="sdk/wxscintilla/src/scintilla/lexers/LexErlang.cxx">
  <Option target="scintilla" />
  </Unit>
+ <Unit filename="sdk/wxscintilla/src/scintilla/lexers/LexErrorList.cxx">
+ <Option target="scintilla" />
+ </Unit>
  <Unit filename="sdk/wxscintilla/src/scintilla/lexers/LexFlagship.cxx">
  <Option target="scintilla" />
  </Unit>
@@ -3530,6 +3539,9 @@
  <Unit filename="sdk/wxscintilla/src/scintilla/lexers/LexMagik.cxx">
  <Option target="scintilla" />
  </Unit>
+ <Unit filename="sdk/wxscintilla/src/scintilla/lexers/LexMake.cxx">
+ <Option target="scintilla" />
+ </Unit>
  <Unit filename="sdk/wxscintilla/src/scintilla/lexers/LexMarkdown.cxx">
  <Option target="scintilla" />
  </Unit>
@@ -3551,13 +3563,13 @@
  <Unit filename="sdk/wxscintilla/src/scintilla/lexers/LexNsis.cxx">
  <Option target="scintilla" />
  </Unit>
- <Unit filename="sdk/wxscintilla/src/scintilla/lexers/LexOScript.cxx">
+ <Unit filename="sdk/wxscintilla/src/scintilla/lexers/LexNull.cxx">
  <Option target="scintilla" />
  </Unit>
- <Unit filename="sdk/wxscintilla/src/scintilla/lexers/LexOpal.cxx">
+ <Unit filename="sdk/wxscintilla/src/scintilla/lexers/LexOScript.cxx">
  <Option target="scintilla" />
  </Unit>
- <Unit filename="sdk/wxscintilla/src/scintilla/lexers/LexOthers.cxx">
+ <Unit filename="sdk/wxscintilla/src/scintilla/lexers/LexOpal.cxx">
  <Option target="scintilla" />
  </Unit>
  <Unit filename="sdk/wxscintilla/src/scintilla/lexers/LexPB.cxx">
@@ -3590,6 +3602,9 @@
  <Unit filename="sdk/wxscintilla/src/scintilla/lexers/LexProgress.cxx">
  <Option target="scintilla" />
  </Unit>
+ <Unit filename="sdk/wxscintilla/src/scintilla/lexers/LexProps.cxx">
+ <Option target="scintilla" />
+ </Unit>
  <Unit filename="sdk/wxscintilla/src/scintilla/lexers/LexPython.cxx">
  <Option target="scintilla" />
  </Unit>
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #14 on: December 23, 2015, 04:04:36 pm »
When debug the scintilla branch with wx 3.02 under windows, I noticed that when an editor opened by the statement:

Code: [Select]
m_pControl->InsertText(0, enc.GetWxStr());

Code: [Select]
case SCI_INSERTTEXT: {
if (lParam == 0)
return 0;
int insertPos = static_cast<int>(wParam);
if (static_cast<int>(wParam) == -1)
insertPos = CurrentPosition();
int newCurrent = CurrentPosition();
char *sz = CharPtrFromSPtr(lParam);
const int lengthInserted = pdoc->InsertString(insertPos, sz, istrlen(sz));
if (newCurrent > insertPos)
newCurrent += lengthInserted;
SetEmptySelection(newCurrent);
return 0;
}
And I see that the null terminated string is needed, but when debugging, I see we pass a string with out the null at the end.
This gives the screen shot:
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #15 on: December 23, 2015, 04:13:10 pm »
Code: [Select]
void UTF8FromUTF16(const wchar_t *uptr, unsigned int tlen, char *putf, unsigned int len) {
unsigned int k = 0;
for (unsigned int i = 0; i < tlen && uptr[i];) {
unsigned int uch = uptr[i];
if (uch < 0x80) {
putf[k++] = static_cast<char>(uch);
} else if (uch < 0x800) {
putf[k++] = static_cast<char>(0xC0 | (uch >> 6));
putf[k++] = static_cast<char>(0x80 | (uch & 0x3f));
} else if ((uch >= SURROGATE_LEAD_FIRST) &&
(uch <= SURROGATE_TRAIL_LAST)) {
// Half a surrogate pair
i++;
unsigned int xch = 0x10000 + ((uch & 0x3ff) << 10) + (uptr[i] & 0x3ff);
putf[k++] = static_cast<char>(0xF0 | (xch >> 18));
putf[k++] = static_cast<char>(0x80 | ((xch >> 12) & 0x3f));
putf[k++] = static_cast<char>(0x80 | ((xch >> 6) & 0x3f));
putf[k++] = static_cast<char>(0x80 | (xch & 0x3f));
} else {
putf[k++] = static_cast<char>(0xE0 | (uch >> 12));
putf[k++] = static_cast<char>(0x80 | ((uch >> 6) & 0x3f));
putf[k++] = static_cast<char>(0x80 | (uch & 0x3f));
}
i++;
}
if (k < len)
putf[k] = '\0';
}
Now, the last two line, I have k == len, and I see there is NO chances to set the null terminator.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #16 on: December 24, 2015, 12:57:19 am »
Code: [Select]
void UTF8FromUTF16(const wchar_t *uptr, unsigned int tlen, char *putf, unsigned int len) {
unsigned int k = 0;
for (unsigned int i = 0; i < tlen && uptr[i];) {
unsigned int uch = uptr[i];
if (uch < 0x80) {
putf[k++] = static_cast<char>(uch);
} else if (uch < 0x800) {
putf[k++] = static_cast<char>(0xC0 | (uch >> 6));
putf[k++] = static_cast<char>(0x80 | (uch & 0x3f));
} else if ((uch >= SURROGATE_LEAD_FIRST) &&
(uch <= SURROGATE_TRAIL_LAST)) {
// Half a surrogate pair
i++;
unsigned int xch = 0x10000 + ((uch & 0x3ff) << 10) + (uptr[i] & 0x3ff);
putf[k++] = static_cast<char>(0xF0 | (xch >> 18));
putf[k++] = static_cast<char>(0x80 | ((xch >> 12) & 0x3f));
putf[k++] = static_cast<char>(0x80 | ((xch >> 6) & 0x3f));
putf[k++] = static_cast<char>(0x80 | (xch & 0x3f));
} else {
putf[k++] = static_cast<char>(0xE0 | (uch >> 12));
putf[k++] = static_cast<char>(0x80 | ((uch >> 6) & 0x3f));
putf[k++] = static_cast<char>(0x80 | (uch & 0x3f));
}
i++;
}
if (k < len)
putf[k] = '\0';
}
Now, the last two line, I have k == len, and I see there is NO chances to set the null terminator.
OK, the following patch should fix the issue:
Code: [Select]
src/sdk/wxscintilla/src/scintilla/src/UniConversion.cxx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/sdk/wxscintilla/src/scintilla/src/UniConversion.cxx b/src/sdk/wxscintilla/src/scintilla/src/UniConversion.cxx
index c12ca34..e987963 100644
--- a/src/sdk/wxscintilla/src/scintilla/src/UniConversion.cxx
+++ b/src/sdk/wxscintilla/src/scintilla/src/UniConversion.cxx
@@ -68,7 +68,7 @@ void UTF8FromUTF16(const wchar_t *uptr, unsigned int tlen, char *putf, unsigned
  }
  i++;
  }
- if (k < len)
+ if (k <= len)
  putf[k] = '\0';
 }
 
This not only fix the issue about the extra bytes in the content of the cbEditor, it also fix the wrong line number margin width issue. Also, before using this patch, the font is totally wrong, and with this patch, the font in the editor is OK now.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #17 on: December 24, 2015, 01:12:35 am »
I have 32 bit cb build myself with against wx3.0.2 under Windows XP.
I see some similar issue, see screen shot:

sometimes, I see two cursors in the previous locations, see screen shot:

Here is the steps to reproduce:
When I first put the cursor after the "main()", and I hit the arrow down key. I see the cursor is still there. After that, I hit the arrow down key again, I see the cursor is still there after the "{", and now the cursor is located after the "vector".
I guess it is related to highlight of the "()" or "{}".
The above issue still exists in the scintilla branch(which is scintilla 3.6.2) with wx 3.0.2.
There are two issues:
1, the blinking cursor is not removed when another brace highlight is added(by click on the other brace pair)
2, from the image shot above, it looks like when I hit after the "{", the closing "}" (the end of the main() function body) is not highlighted.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #18 on: December 25, 2015, 05:27:02 am »
If you click from top to bottom as pointed by the screen shot, you get many brace highlight...
See image shot below:

It looks like the old brace highlight does not get clean up.

EDIT: I just tested the SciTE 2.6.2 release, it dose not have such issue. So, it is related to wx 3.0.2's platform support for scintilla.

EDIT2: make the whole editor window refresh(such as minimize the C::B window, and restore it) will totally remove the old high light.
« Last Edit: December 25, 2015, 05:30:28 am by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #19 on: December 25, 2015, 07:33:06 am »
Debugged for a while, I found that, when I click on a brace(if there are some braces already highlighted)
I get to those code:
Code: [Select]
void Editor::SetBraceHighlight(Position pos0, Position pos1, int matchStyle) {
if ((pos0 != braces[0]) || (pos1 != braces[1]) || (matchStyle != bracesMatchStyle)) {
if ((braces[0] != pos0) || (matchStyle != bracesMatchStyle)) {
CheckForChangeOutsidePaint(Range(braces[0]));
CheckForChangeOutsidePaint(Range(pos0));
braces[0] = pos0;
}
if ((braces[1] != pos1) || (matchStyle != bracesMatchStyle)) {
CheckForChangeOutsidePaint(Range(braces[1]));
CheckForChangeOutsidePaint(Range(pos1));
braces[1] = pos1;
}
bracesMatchStyle = matchStyle;
if (paintState == notPainting) {
Redraw();
}
}
}
This function is called inside the function call "Paint(surfaceWindow, rcPaint);" inside the below function.
Code: [Select]
void ScintillaWX::DoPaint(wxDC* dc, wxRect rect) {

    paintState = painting;
    AutoSurface surfaceWindow(dc, this);
    if (surfaceWindow) {
        rcPaint = PRectangleFromwxRect(rect);
        PRectangle rcClient = GetClientRectangle();
        paintingAllText = rcPaint.Contains(rcClient);

        ClipChildren(*dc, rcPaint);
        Paint(surfaceWindow, rcPaint);
        surfaceWindow->Release();
    }

    if (paintState == paintAbandoned) {
        // Painting area was insufficient to cover new styling or brace
        // highlight positions.  So trigger a new paint event that will
        // repaint the whole window.
        sci->Refresh(false);

#if defined(__WXOSX__)
        // On Mac we also need to finish the current paint to make sure that
        // everything is on the screen that needs to be there between now and
        // when the next paint event arrives.
        FullPaintDC(dc);
#endif
    }
    paintState = notPainting;
}

Then, we will get into the condition that satisfy this condition "if (!PaintContains(rcRange))", so that "paintAbandonedByStyling = true;" is reached.
Code: [Select]
void Editor::CheckForChangeOutsidePaint(Range r) {
if (paintState == painting && !paintingAllText) {
//Platform::DebugPrintf("Checking range in paint %d-%d\n", r.start, r.end);
if (!r.Valid())
return;

PRectangle rcRange = RectangleFromRange(r, 0);
PRectangle rcText = GetTextRectangle();
if (rcRange.top < rcText.top) {
rcRange.top = rcText.top;
}
if (rcRange.bottom > rcText.bottom) {
rcRange.bottom = rcText.bottom;
}

if (!PaintContains(rcRange)) {
AbandonPaint();
paintAbandonedByStyling = true;
}
}
}
Back to the function "void ScintillaWX::DoPaint(wxDC* dc, wxRect rect)", you will see the Refresh() call is reached.
Code: [Select]
    if (paintState == paintAbandoned) {
        // Painting area was insufficient to cover new styling or brace
        // highlight positions.  So trigger a new paint event that will
        // repaint the whole window.
        sci->Refresh(false);
Now, you get a repaint:

Code: [Select]
void wxScintilla::OnPaint(wxPaintEvent& WXUNUSED(evt))
{
#ifdef __WXGTK__
    wxBufferedPaintDC dc(this);
#else
    wxPaintDC dc(this);
#endif
    m_swx->DoPaint(&dc, GetUpdateRegion().GetBox());
}

But here comes the bug!
I see that "GetUpdateRegion().GetBox()" only gives the area around the current line. This not cover the old brace highlight, so that the old brace highlight is not removed. Also, if you click on the "{", while the associated "}" is on the other line(which means the "}" is not in the area of the "GetUpdateRegion().GetBox()"), so the "}" is not highlighted.

What's wrong with the "GetUpdateRegion().GetBox()", It should at least be a rectangle area which covers the current braces and the old braces.


If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #20 on: December 26, 2015, 07:11:36 am »
I just tested the buildin stc control inside the wx 3.0.2. It does not show such issue.
Here are the steps:
1, build the sample/stc project. (I use Tim's wx c::b project, see: stahta01/cb_projects_for_wxWidgets GitHub, also, you can build the stc project with traditional makefile)

2, make some changes to edit.cpp:
Code: [Select]
void Edit::OnUpdate(wxStyledTextEvent &WXUNUSED(event))
{
    int min = GetCurrentPos ();
    int max = BraceMatch (min);
    if (max > (min+1)) {
        BraceHighlight (min, max);
    }else{
        BraceBadLight (min);
    }
}
And add one prototype:
Code: [Select]
    void OnUpdate  (wxStyledTextEvent &event);
Also, one entry to the message map:
Code: [Select]
    EVT_STC_UPDATEUI(wxID_ANY,         Edit::OnUpdate)

3, Here is the test code:
Code: [Select]
void main(hhhh)

{

}


{

}

EDIT:
wx 3.0.2's buildin scintilla version is 3.21, which is quite old.
Also, the above brace high light only works you put the cursor before the beginning brace.

« Last Edit: December 26, 2015, 08:39:19 am by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #21 on: December 26, 2015, 03:16:27 pm »
OK, I found this issue is really strange, I just test the wxScintilla in our C::B's svn repo. We have a cctest project, which use this wxScintilla. Here is the patch to enable the brace highlight feature in cctest's editor:
Code: [Select]
ff0cf37bef56645539ebf000d2ddf7d98fcf2dac
 src/plugins/codecompletion/cctest/cctest_frame.cpp | 14 ++++++++++++++
 src/plugins/codecompletion/cctest/cctest_frame.h   |  1 +
 2 files changed, 15 insertions(+)

diff --git a/src/plugins/codecompletion/cctest/cctest_frame.cpp b/src/plugins/codecompletion/cctest/cctest_frame.cpp
index e8a0626..cbbcae2 100644
--- a/src/plugins/codecompletion/cctest/cctest_frame.cpp
+++ b/src/plugins/codecompletion/cctest/cctest_frame.cpp
@@ -474,6 +474,9 @@ void CCTestFrame::InitControl()
     Connect(m_Control->GetId(), -1, wxEVT_SCI_MARGINCLICK,
             (wxObjectEventFunction) (wxEventFunction) (wxScintillaEventFunction)
             &CCTestFrame::OnMarginClick);
+    Connect(m_Control->GetId(), -1, wxEVT_SCI_UPDATEUI,
+            (wxObjectEventFunction) (wxEventFunction) (wxScintillaEventFunction)
+            &CCTestFrame::OnUpdate);
 }
 
 void CCTestFrame::SetMarkerStyle(int marker, int markerType, wxColor fore, wxColor back)
@@ -590,6 +593,17 @@ void CCTestFrame::OnMarginClick(wxScintillaEvent& event)
     }
 }
 
+void CCTestFrame::OnUpdate(wxScintillaEvent &WXUNUSED(event))
+{
+    int min = m_Control->GetCurrentPos ();
+    int max = m_Control->BraceMatch (min);
+    if (max > (min+1)) {
+        m_Control->BraceHighlight (min, max);
+    }else{
+        m_Control->BraceBadLight (min);
+    }
+}
+
 void CCTestFrame::OnFindDialog(wxFindDialogEvent& event)
 {
     wxEventType type = event.GetEventType();
diff --git a/src/plugins/codecompletion/cctest/cctest_frame.h b/src/plugins/codecompletion/cctest/cctest_frame.h
index d41538f..6f86ebe 100644
--- a/src/plugins/codecompletion/cctest/cctest_frame.h
+++ b/src/plugins/codecompletion/cctest/cctest_frame.h
@@ -73,6 +73,7 @@ private:
     void OnFindDialog(wxFindDialogEvent& event);
     void OnCCLogger(wxCommandEvent& event);
     void OnCCAddToken(wxCommandEvent& event);
+    void OnUpdate(wxScintillaEvent &event);
 
 
     //(*Declarations(CCTestFrame)

While, the result is: It works just fine!
So, here comes the question: maybe the issue is NOT inside the wxScintilla, maybe our C::B core(SDK) has some code which destroy the feature.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #22 on: December 26, 2015, 03:52:11 pm »
OK, I did some test. I see that if I comment the line:
Code: [Select]
NotifyPlugins(cbEVT_EDITOR_UPDATE_UI);inside the function: void cbEditor::OnEditorUpdateUI(wxScintillaEvent& event), then the brace highlight works just fine in C::B.

So, what is the client of this cbEVT_EDITOR_UPDATE_UI? In my tests, I have disable all the plugins, so it looks like the only client which use cbEVT_EDITOR_UPDATE_UI is inside the src target, which locates below:
Code: [Select]
void MainFrame::OnEditorUpdateUI(CodeBlocksEvent& event)
{
    if (Manager::IsAppShuttingDown())
    {
        event.Skip();
        return;
    }

    if (Manager::Get()->GetEditorManager() && event.GetEditor() == Manager::Get()->GetEditorManager()->GetActiveEditor())
        DoUpdateStatusBar();

    event.Skip();
}
Does DoUpdateStatusBar cause the issue?

EDIT: I can confirm that DoUpdateStatusBar does cause this issue. If I comment out the line:
Code: [Select]
DoUpdateStatusBar();, I see brace high light works fine.
« Last Edit: December 26, 2015, 03:58:45 pm by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #23 on: December 26, 2015, 04:26:05 pm »
If I comment out the two lines:
Code: [Select]
        msg.Printf(_("Line %d, Column %d"), ed->GetControl()->GetCurrentLine() + 1, ed->GetControl()->GetColumn(pos) + 1);
        SetStatusText(msg, panel++);
From the function: void MainFrame::DoUpdateStatusBar(), then the brace high light works fine!
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #24 on: December 27, 2015, 03:03:20 am »
I just did more test:
1, I try to minimize the issue, so I add such code in our cctest w30 project.
Here is the modified function:
Code: [Select]
void CCTestFrame::OnUpdate(wxScintillaEvent &WXUNUSED(event))
{
    int min = m_Control->GetCurrentPos ();
    int max = m_Control->BraceMatch (min);
    if (max > (min+1)) {
        m_Control->BraceHighlight (min, max);
        int pos = m_Control->GetCurrentLine();
        wxString msg;
        msg.Printf(_("Line %d, Column %d"), m_Control->GetCurrentLine() + 1, m_Control->GetColumn(pos) + 1);
        SetStatusText(msg, 0);
    }else{
        m_Control->BraceBadLight (min);
    }
}
You see here, I have both set the BraceHighlight and the Status Bar.
Now, the issue happens.


2, I did a quite similar test on the wx 3.0.2's build in stc sample:
Add a status bar in the frame's constructor(a member variable wxStatusBar* m_StatuBar; is need also)
Code: [Select]
    m_StatuBar = new wxStatusBar(this, wxID_ANY, 0, _T("wxID_ANY"));
    int __wxStatusBarWidths_1[1] = { -10 };
    int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
    m_StatuBar->SetFieldsCount(1,__wxStatusBarWidths_1);
    m_StatuBar->SetStatusStyles(1,__wxStatusBarStyles_1);
    SetStatusBar(m_StatuBar);
Then, bind the event to the frame, not the Edit control.
Code: [Select]
void AppFrame::OnUpdate(wxStyledTextEvent &WXUNUSED(event))
{
    int min = m_edit->GetCurrentPos ();
    int max = m_edit->BraceMatch (min);
    if (max > (min+1)) {
        m_edit->BraceHighlight (min, max);
        int pos = m_edit->GetCurrentLine();
        wxString msg;
        msg.Printf(_("Line %d, Column %d"), m_edit->GetCurrentLine() + 1, m_edit->GetColumn(pos) + 1);
        SetStatusText(msg, 0);

    }else{
        m_edit->BraceBadLight (min);
    }
}
The macro is like below:
Code: [Select]
    // handle the update event
    EVT_STC_UPDATEUI(wxID_ANY,         AppFrame::OnUpdate)

Note, that you need to comment out the EVT_STC_UPDATEUI macro inside the edit.cpp.
The result is: It works OK without the issue.
EDIT: I see that this issue also happens!!

I really don't know why SetStatusText() call cause such issue. Is it caused by the local variable msg?
EDIT: Now, I see all the above cases will cause the issue!
« Last Edit: December 27, 2015, 03:38:23 am by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #25 on: December 27, 2015, 10:20:56 pm »
The bug also happens inside the wx trunk's stc control, I reported a detailed message here in wx-user maillist wxStyledTextCtrl: SetStatusText() function call destroys the brace highlight feature under Windows - Google Groups, so that they can help.  :)
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #26 on: December 28, 2015, 08:41:47 am »
The bug also happens inside the wx trunk's stc control, I reported a detailed message here in wx-user maillist wxStyledTextCtrl: SetStatusText() function call destroys the brace highlight feature under Windows - Google Groups, so that they can help.  :)
Thanks Eran, the author of CodeLite IDE give a solution to this issue, great! See: https://groups.google.com/d/msg/wx-users/CewSBr6J5xk/KIkZiYAzBgAJ

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #27 on: December 28, 2015, 11:17:22 pm »
The following patch fix the issue!

Code: [Select]
src/src/main.cpp | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/src/main.cpp b/src/src/main.cpp
index d94083d..8b6f848 100644
--- a/src/src/main.cpp
+++ b/src/src/main.cpp
@@ -4240,7 +4240,15 @@ void MainFrame::OnEditorUpdateUI(CodeBlocksEvent& event)
     }
 
     if (Manager::Get()->GetEditorManager() && event.GetEditor() == Manager::Get()->GetEditorManager()->GetActiveEditor())
-        DoUpdateStatusBar();
+    {
+        #if wxCHECK_VERSION(2,9,5)
+            // try to avoid an issue when set status bar inside the editor update ui event breaks
+            // the brace high light, see: http://forums.codeblocks.org/index.php/topic,20795.0.html
+            CallAfter(&MainFrame::DoUpdateStatusBar);
+        #else
+            DoUpdateStatusBar();
+        #endif
+    }
 
     event.Skip();
 }
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline headkase

  • Almost regular
  • **
  • Posts: 159
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #28 on: December 28, 2015, 11:32:11 pm »
Right bleepin' on.  ;)  I await it being pushed to SVN and then I will build wxWidgets 3.0.2 and C::B wx30_64.  Finally, 64-bit.  That's all I want - is it too much to ask!? ;)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12129
    • Travis build status
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #29 on: December 28, 2015, 11:39:33 pm »
There are many more problems in wx3.0 builds that needs to be fixed.
At the moment it is best to stick to the wx2.8 builds.

wx3.0 builds are for people that are not afraid of crashes/asserts/bugs and they're willing to report them.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline headkase

  • Almost regular
  • **
  • Posts: 159
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #30 on: December 28, 2015, 11:41:07 pm »
There are many more problems in wx3.0 builds that needs to be fixed.
At the moment it is best to stick to the wx2.8 builds.

wx3.0 builds are for people that are not afraid of crashes/asserts/bugs and they're willing to report them.
Ah, thanks oBFusCATed, I don't actually need a 64-bit build of C::B, it's more of a vanity thing.  Under Linux a wx 2.8.12 64-bit build is trivial, but under Windows where I am one is not.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12129
    • Travis build status
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #31 on: December 28, 2015, 11:41:41 pm »
@ollydbg:
I don't like the fix. We have to know the reason for this change in behaviour.
Also the check should be against 3.0 and not 2.9.5. wx2.9.x is not supported in any way, only wx3.x, thus the code should not be misleading.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #32 on: December 29, 2015, 12:06:17 am »
@ollydbg:
I don't like the fix. We have to know the reason for this change in behaviour.
I don't know the reason, I have debugged this bug for several days, until I asked in the wx-user maillist.
Eran just told me this is an workaround, this also get better performance as he said. see his wx-user maillist(in my previous posts)

Quote
Also the check should be against 3.0 and not 2.9.5. wx2.9.x is not supported in any way, only wx3.x, thus the code should not be misleading.
I see the CallAfter's document is said this function is from 2.9.5, so I changed my first idea which is 3.0.0 to 2.9.5.  :)

Right bleepin' on.  ;)  I await it being pushed to SVN and then I will build wxWidgets 3.0.2 and C::B wx30_64.  Finally, 64-bit.  That's all I want - is it too much to ask!? ;)
I need more comments about those patches, especially Morten, because he is the maintainer of that scintilla branch. You can apply those patches locally in your computer, and test those changes too.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline headkase

  • Almost regular
  • **
  • Posts: 159
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #33 on: December 29, 2015, 01:01:56 am »
I need more comments about those patches, especially Morten, because he is the maintainer of that scintilla branch. You can apply those patches locally in your computer, and test those changes too.

I tested the patch.  Built wxWidgets 3.0.2 64-bit, applied your patch to SVN 10630, compiled C::B wx30_64.  Resulting build: opened main.cpp from the C::B project, scrolled around, removed and added text, over the course of five minutes testing everything worked.  Compiler used was TDM-GCC 5.1.0 64-bit.

Offline headkase

  • Almost regular
  • **
  • Posts: 159
Re: Strange cursor position with wx3.0.2 (scintilla)
« Reply #34 on: December 29, 2015, 03:57:33 am »
Ok, I did a sanity test.  I know that using MinGW-Builds GCC 5.2.0 / posix threads / seh exceptions / Revision 1 / 64-bit I had the cursor errors.  So, I recompiled wxWidgets 3.0.2 and Code::Blocks SVN 10630 with the patch with that toolchain just to make sure the issue was also fixed using that.  It is.  The patch corrects the errors.

If anyone would like to try the binaries I built in a different environment, their machine, you can find them: Here.