From 518cdc57901a650b69d385b67f812a90a34fb5f4 Mon Sep 17 00:00:00 2001 From: New Pagodi Date: Mon, 11 Feb 2019 23:18:37 -0600 Subject: [PATCH] Demonstrate autocompletion in the stc sample This adds a demonstration of autocompletion for C preprocessor directives to the stc sample. It also shows how to register and use small images with the autocompletion popup. --- samples/stc/edit.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/samples/stc/edit.cpp b/samples/stc/edit.cpp index e9aeac9990..335cbeccae 100644 --- a/samples/stc/edit.cpp +++ b/samples/stc/edit.cpp @@ -52,6 +52,22 @@ // The (uniform) style used for the annotations. const int ANNOTATION_STYLE = wxSTC_STYLE_LASTPREDEFINED + 1; +// A small image of a hashtag symbol used in the autocompletion window. +const char* hashtag_xpm[] = { +"10 10 2 1", +" c None", +". c #BD08F9", +" .. .. ", +" .. .. ", +"..........", +"..........", +" .. .. ", +" .. .. ", +"..........", +"..........", +" .. .. ", +" .. .. "}; + //============================================================================ // implementation //============================================================================ @@ -169,6 +185,10 @@ Edit::Edit (wxWindow *parent, wxWindowID id, // annotations AnnotationSetVisible(wxSTC_ANNOTATION_BOXED); + // autocompletion + wxBitmap bmp(hashtag_xpm); + RegisterImage(0, bmp); + // miscellaneous m_LineNrMargin = TextWidth (wxSTC_STYLE_LINENUMBER, "_999999"); m_FoldingMargin = 16; @@ -481,6 +501,11 @@ void Edit::OnCharAdded (wxStyledTextEvent &event) { SetLineIndentation (currentLine, lineInd); GotoPos(PositionFromLine (currentLine) + lineInd); } + else if (chr == '#') { + wxString s = "define?0 elif?0 else?0 endif?0 error?0 if?0 ifdef?0 " + "ifndef?0 include?0 line?0 pragma?0 undef?0"; + AutoCompShow(0,s); + } }