User forums > General (but related to Code::Blocks)

Strange cursor position with wx3.0.2 (scintilla)

<< < (5/7) > >>

ollydbg:
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: ---void Edit::OnUpdate(wxStyledTextEvent &WXUNUSED(event))
{
    int min = GetCurrentPos ();
    int max = BraceMatch (min);
    if (max > (min+1)) {
        BraceHighlight (min, max);
    }else{
        BraceBadLight (min);
    }
}

--- End code ---
And add one prototype:

--- Code: ---    void OnUpdate  (wxStyledTextEvent &event);

--- End code ---
Also, one entry to the message map:

--- Code: ---    EVT_STC_UPDATEUI(wxID_ANY,         Edit::OnUpdate)

--- End code ---

3, Here is the test code:

--- Code: ---void main(hhhh)

{

}


{

}

--- End code ---

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.

ollydbg:
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: ---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)


--- End code ---
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.

ollydbg:
OK, I did some test. I see that if I comment the line:

--- Code: ---NotifyPlugins(cbEVT_EDITOR_UPDATE_UI);
--- End code ---
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: ---void MainFrame::OnEditorUpdateUI(CodeBlocksEvent& event)
{
    if (Manager::IsAppShuttingDown())
    {
        event.Skip();
        return;
    }

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

    event.Skip();
}

--- End code ---
Does DoUpdateStatusBar cause the issue?

EDIT: I can confirm that DoUpdateStatusBar does cause this issue. If I comment out the line:

--- Code: ---DoUpdateStatusBar();
--- End code ---
, I see brace high light works fine.

ollydbg:
If I comment out the two lines:

--- Code: ---        msg.Printf(_("Line %d, Column %d"), ed->GetControl()->GetCurrentLine() + 1, ed->GetControl()->GetColumn(pos) + 1);
        SetStatusText(msg, panel++);
--- End code ---
From the function: void MainFrame::DoUpdateStatusBar(), then the brace high light works fine!

ollydbg:
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: ---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);
    }
}

--- End code ---
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: ---    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);

--- End code ---
Then, bind the event to the frame, not the Edit control.

--- Code: ---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);
    }
}

--- End code ---
The macro is like below:

--- Code: ---    // handle the update event
    EVT_STC_UPDATEUI(wxID_ANY,         AppFrame::OnUpdate)

--- End code ---

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!

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version