Using folding in scintilla
scintilla is a script editing component http://www.scintilla.org for more information.
static const int MARGIN_SCRIPT_FOLD_INDEX = 1;
static const int WINDOW_ID = 900; BEGIN_MESSAGE_MAP(CDocumentWindow, CDocumentWindowsBaseClass) ON_NOTIFY(SCN_MARGINCLICK, WINDOW_ID, OnMarginClicked) END_MESSAGE_MAP()
SendEditor(SCI_SETLEXER, SCLEX_CPP); SendEditor(SCI_SETSTYLEBITS, 5);
SendEditor(SCI_SETPROPERTY, (WPARAM)"fold", (LPARAM)"1"); SendEditor(SCI_SETPROPERTY, (WPARAM)"fold.compact", (LPARAM)"0");
SendEditor(SCI_SETPROPERTY, (WPARAM)"fold.comment", (LPARAM)"1"); SendEditor(SCI_SETPROPERTY, (WPARAM)"fold.preprocessor", (LPARAM)"1");
SendEditor(SCI_SETMARGINWIDTHN, MARGIN_SCRIPT_FOLD_INDEX, 0);
SendEditor(SCI_SETMARGINTYPEN, MARGIN_SCRIPT_FOLD_INDEX, SC_MARGIN_SYMBOL); SendEditor(SCI_SETMARGINMASKN, MARGIN_SCRIPT_FOLD_INDEX, SC_MASK_FOLDERS); SendEditor(SCI_SETMARGINWIDTHN, MARGIN_SCRIPT_FOLD_INDEX, 20);
SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDER, SC_MARK_PLUS); SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPEN, SC_MARK_MINUS); SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEREND, SC_MARK_EMPTY); SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERMIDTAIL, SC_MARK_EMPTY); SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPENMID, SC_MARK_EMPTY); SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERSUB, SC_MARK_EMPTY); SendEditor(SCI_MARKERDEFINE, SC_MARKNUM_FOLDERTAIL, SC_MARK_EMPTY); SendEditor(SCI_SETFOLDFLAGS, 16, 0); // 16 Draw line below if not expanded
SendEditor(SCI_SETMARGINSENSITIVEN, MARGIN_SCRIPT_FOLD_INDEX, 1);
afx_msg void
CDocumentWindow::OnMarginClick(NMHDR* nmhdr, LRESULT* result)
{
SCNotification* notify = (SCNotification*)nmhdr;
const int modifiers = notify->modifiers;
const int position = notify->position;
const int margin = notify->margin;
const int line_number = SendEditor(SCI_LINEFROMPOSITION, position, 0);
switch (margin) {
case MARGIN_SCRIPT_FOLD_INDEX:
{
SendEditor(SCI_TOGGLEFOLD, line_number, 0);
}
break;
}
}
SendEditor(SCI_TOGGLEFOLD, line_number, 0);
To:
MarginClick(position, modifiers);
bool MarginClick(int position, int modifiers);
void Expand(int &line, bool doExpand,
bool force = false, int visLevels = 0, int level = -1);
void FoldAll();
SendEditor(SCI_ENSUREVISIBLEENFORCEPOLICY, line_number); SendEditor(SCI_GOTOLINE, line_number);