Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

wxWidgets 3.1.2 Released

<< < (6/11) > >>

eranif:

--- Quote from: oBFusCATed on December 18, 2018, 08:41:51 pm ---Interesting why codelite is not affected...

--- End quote ---
This is because CodeLite does not use the builtin wxSTC popup window, I created my own (for other reasons) couple of years ago.
https://github.com/eranif/codelite/blob/master/Plugin/wxCodeCompletionBox.cpp

ollydbg:

--- Quote from: New Pagodi on December 18, 2018, 11:55:06 pm ---I don't know if this is helpful or not, but here's a patch to add a very rudimentary type of autocompletion to the wxWidgets stc sample.  It doesn't show the crash under discussion, so it might not be helpful at all.


--- Code: ---diff --git a/samples/stc/edit.cpp b/samples/stc/edit.cpp
index 7e7f412ec2..c16b1aae2b 100644
--- a/samples/stc/edit.cpp
+++ b/samples/stc/edit.cpp
@@ -60,6 +60,21 @@ const int ANNOTATION_STYLE = wxSTC_STYLE_LASTPREDEFINED + 1;
 // Edit
 //----------------------------------------------------------------------------
 
+static char * pound_xpm[] = {
+"10 10 2 1",
+" c None",
+". c #BD08F9",
+"  ..  ..  ",
+"  ..  ..  ",
+"..........",
+"..........",
+"  ..  ..  ",
+"  ..  ..  ",
+"..........",
+"..........",
+"  ..  ..  ",
+"  ..  ..  "};
+
 wxBEGIN_EVENT_TABLE (Edit, wxStyledTextCtrl)
     // common
     EVT_SIZE (                         Edit::OnSize)
@@ -177,6 +192,10 @@ Edit::Edit (wxWindow *parent, wxWindowID id,
     CmdKeyClear (wxSTC_KEY_TAB, 0); // this is done by the menu accelerator key
     SetLayoutCache (wxSTC_CACHE_PAGE);
     UsePopUp(wxSTC_POPUP_ALL);
+   
+    wxImage::AddHandler(new wxXPMHandler);
+    wxBitmap b(pound_xpm);
+    RegisterImage(0, b);
 }
 
 Edit::~Edit () {}
@@ -483,6 +502,13 @@ void Edit::OnCharAdded (wxStyledTextEvent &event) {
         SetLineIndentation (currentLine, lineInd);
         GotoPos(PositionFromLine (currentLine) + lineInd);
     }
+    else if (chr == '#') {
+        wxString s = "define?0 elif?0 elifdef?0 elifndef?0 else?0 endif?0 "
+                      "error?0 if?0 ifdef?0 ifndef?0 include?0 line?0 line?0 "
+                      "pragma?0 undef?0";
+       
+        AutoCompShow(0,s);
+    }
 }
 
 

--- End code ---

--- End quote ---
Hi, thanks for the contribution, I just test the stc sample with your patch.
The auto suggestion(auto completion) window shows correctly after I hit the "#", and I can keep typing in the editor, while the correct item is selected.
The issue I see is that if I "deactivate" the stcsample's main frame, the auto completion list is still active, which covers every active application's window. :(

The same effect can be achieved when we comment out the line:

--- Code: ---void cbStyledTextCtrl::OnKillFocus(wxFocusEvent& event)
{
    // cancel auto-completion list when losing focus
    //if ( AutoCompActive() )
    //    AutoCompCancel();

    if ( CallTipActive() )
        CallTipCancel();

    event.Skip();
}

--- End code ---
With the above changes in sdk\cbstyledtextctrl.cpp, we can avoid the crash issue, but we get the same issue as the stc sample with your patch. :)

ollydbg:
When debugging, I found the reason comes from this code flow:


--- Code: ---void AutoComplete::Show(bool show) {
lb->Show(show);     // set bp1 here
if (show)
lb->Select(0); // set bp2 here
}

--- End code ---

When you try to show a autocompletion window, you first hit the bp1, then I see that a lose focus event happens before I hit the bp2, so the function

--- Code: ---void cbStyledTextCtrl::OnKillFocus(wxFocusEvent& event)
{
    // cancel auto-completion list when losing focus
    if ( AutoCompActive() )
        AutoCompCancel();

    if ( CallTipActive() )
        CallTipCancel();

    event.Skip();
}

--- End code ---
is called between bp1 and bp2.

Finally, when we goes to bp2, the window is already destroyed (wid==0).  :(

oBFusCATed:
@New Pagodi:

You can use this patch to reproduce the problem:

--- Code: ---diff --git a/samples/stc/edit.cpp b/samples/stc/edit.cpp
index 855c18f..6a1c428 100644
--- a/samples/stc/edit.cpp
+++ b/samples/stc/edit.cpp
@@ -117,6 +117,7 @@ wxBEGIN_EVENT_TABLE (Edit, wxStyledTextCtrl)
     EVT_STC_CHARADDED (wxID_ANY,       Edit::OnCharAdded)

     EVT_KEY_DOWN( Edit::OnKeyDown )
+    EVT_KILL_FOCUS(Edit::OnKillFocus)
 wxEND_EVENT_TABLE()

 Edit::Edit (wxWindow *parent, wxWindowID id,
@@ -472,6 +473,17 @@ void Edit::OnMarginClick (wxStyledTextEvent &event) {
     }
 }

+void Edit::OnKillFocus(wxFocusEvent& event)
+{
+    if ( AutoCompActive() )
+        AutoCompCancel();
+
+    if ( CallTipActive() )
+        CallTipCancel();
+
+    event.Skip();
+}
+
 void Edit::OnCharAdded (wxStyledTextEvent &event) {
     char chr = (char)event.GetKey();
     int currentLine = GetCurrentLine();
@@ -485,6 +497,21 @@ void Edit::OnCharAdded (wxStyledTextEvent &event) {
         SetLineIndentation (currentLine, lineInd);
         GotoPos(PositionFromLine (currentLine) + lineInd);
     }
+    else
+    {
+        wxString items;
+        items += "test1\r";
+        items += "test2\r";
+        items += "test3\r";
+        items += "test4\r";
+        items += "test5\r";
+
+        AutoCompSetIgnoreCase(true);
+        AutoCompSetMaxHeight(14);
+        AutoCompSetTypeSeparator(wxT('\n'));
+        AutoCompSetSeparator(wxT('\r'));
+        AutoCompShow(0, items);
+    }
 }


diff --git a/samples/stc/edit.h b/samples/stc/edit.h
index 703ebae..2762a85 100644
--- a/samples/stc/edit.h
+++ b/samples/stc/edit.h
@@ -107,6 +107,7 @@ public:
     void OnCharAdded  (wxStyledTextEvent &event);

     void OnKeyDown(wxKeyEvent &event);
+    void OnKillFocus(wxFocusEvent& event);

     //! language/lexer
     wxString DeterminePrefs (const wxString &filename);

--- End code ---

New Pagodi:
I've found that the issue was that this commit changed the style of window used for popups on MSW.  I've got a proposal for a fix that restores the old behavior if the popup is created with a certain style.

While working on this, I discovered several other issues with auto completion.  I've got a work in progress here.  It needs quite a bit of clean up and has some problems compiling on GTK.  As soon as I get everything presentable, I was going to start a thread on the wxWidgets developers list asking if those fixes are acceptable.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version