WxStyledTextCtrl code folding for PHP
I need to display PHP code using WxStyledTextCtrl. All is working fine except code folding.
I followed the examples in the wxWidgets page http://wiki.wxwidgets.org/WxStyledTextCtrl, they use a wxSTC_LEX_CPP 开发者_如何学Pythonlexer and it works. I adapted their code but when I change this:
text->SetLexer(wxSTC_LEX_CPP);
for this:
text->SetLexer(wxSTC_LEX_HTML);
the code folding stops working, I've tried everything but I can't make it work. I'm using the last release of wxWidgets compiled with VS2010. Any help will be appreciated.
The Scintilla code folding for PHP is a little different than the rest since it is handled by the HTML lexer. The code below will enable code folding in PHP. The folding will look like Visual Studio (a box with a plus sign inside of it)
wxStyledTextCtrl *ctrl = // from somewhere ....
wxColour backgroundColor = // the background color
wxColour color = // the foreground color
ctrl->SetProperty(wxT("fold"), wxT("1"));
ctrl->SetProperty(wxT("fold.comment"), wxT("1"));
ctrl->SetProperty(wxT("fold.html"), wxT("1"));
ctrl->SetFoldFlags(wxSTC_FOLDFLAG_LINEBEFORE_CONTRACTED | wxSTC_FOLDFLAG_LINEAFTER_CONTRACTED);
int marginNum = 1; // can be 0-5 I believe
ctrl->SetMarginType(marginNum, wxSTC_MARGIN_SYMBOL);
ctrl->SetMarginWidth(marginNum, 16);
ctrl->SetMarginSensitive(marginNum, true);
ctrl->SetMarginMask(1, wxSTC_MASK_FOLDERS);
ctrl->SetFoldMarginColour(true, backgroundColor);
ctrl->SetFoldMarginHiColour(true, backgroundColor);
ctrl->MarkerDefine(wxSTC_MARKNUM_FOLDEROPEN, wxSTC_MARK_BOXMINUS, backgroundColor, color);
ctrl->MarkerDefine(wxSTC_MARKNUM_FOLDER, wxSTC_MARK_BOXPLUS, backgroundColor, color);
ctrl->MarkerDefine(wxSTC_MARKNUM_FOLDERSUB, wxSTC_MARK_VLINE, backgroundColor, color);
ctrl->MarkerDefine(wxSTC_MARKNUM_FOLDERTAIL, wxSTC_MARK_LCORNER, backgroundColor, color);
ctrl->MarkerDefine(wxSTC_MARKNUM_FOLDEREND, wxSTC_MARK_BOXPLUSCONNECTED, backgroundColor, color);
ctrl->MarkerDefine(wxSTC_MARKNUM_FOLDEROPENMID, wxSTC_MARK_BOXMINUSCONNECTED, backgroundColor, color);
ctrl->MarkerDefine(wxSTC_MARKNUM_FOLDERMIDTAIL, wxSTC_MARK_TCORNER, backgroundColor, color);
精彩评论