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.
This commit is contained in:
New Pagodi
2019-02-11 23:18:37 -06:00
parent 1cdc0acfbe
commit 518cdc5790

View File

@@ -52,6 +52,22 @@
// The (uniform) style used for the annotations. // The (uniform) style used for the annotations.
const int ANNOTATION_STYLE = wxSTC_STYLE_LASTPREDEFINED + 1; 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 // implementation
//============================================================================ //============================================================================
@@ -169,6 +185,10 @@ Edit::Edit (wxWindow *parent, wxWindowID id,
// annotations // annotations
AnnotationSetVisible(wxSTC_ANNOTATION_BOXED); AnnotationSetVisible(wxSTC_ANNOTATION_BOXED);
// autocompletion
wxBitmap bmp(hashtag_xpm);
RegisterImage(0, bmp);
// miscellaneous // miscellaneous
m_LineNrMargin = TextWidth (wxSTC_STYLE_LINENUMBER, "_999999"); m_LineNrMargin = TextWidth (wxSTC_STYLE_LINENUMBER, "_999999");
m_FoldingMargin = 16; m_FoldingMargin = 16;
@@ -481,6 +501,11 @@ void Edit::OnCharAdded (wxStyledTextEvent &event) {
SetLineIndentation (currentLine, lineInd); SetLineIndentation (currentLine, lineInd);
GotoPos(PositionFromLine (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);
}
} }