hi, javmss.
Currently, I don't have much time to help you, but I can give you the direction: the source code of cbeditor.cpp, which is located in:
svn\src\sdk\cbeditor.cpp
the related code was located from line 1924-2024. So, you can simply add some modification to these code, and do the folding function as you wanted.
void cbEditor::DoFoldAll(int fold)
{
cbAssert(m_pControl);
if (m_SplitType != stNoSplit)
cbAssert(m_pControl2);
cbStyledTextCtrl* ctrl = GetControl();
ctrl->Colourise(0, -1); // the *most* important part!
int count = ctrl->GetLineCount();
for (int i = 0; i <= count; ++i)
DoFoldLine(i, fold);
}
void cbEditor::DoFoldBlockFromLine(int line, int fold)
{
cbAssert(m_pControl);
if (m_SplitType != stNoSplit)
cbAssert(m_pControl2);
cbStyledTextCtrl* ctrl = GetControl();
ctrl->Colourise(0, -1); // the *most* important part!
int i, parent, maxLine, level, UnfoldUpto = line;
bool FoldedInside = false;
parent = ctrl->GetFoldParent(line);
level = ctrl->GetFoldLevel(parent);
/* The following code will check if the child is hidden
* under parent before unfolding it
*/
if (fold == 0)
{
do
{
if (!ctrl->GetFoldExpanded(parent))
{
FoldedInside = true;
UnfoldUpto = parent;
}
if (wxSCI_FOLDLEVELBASE == (level & wxSCI_FOLDLEVELNUMBERMASK))
break;
parent = ctrl->GetFoldParent(parent);
level = ctrl->GetFoldLevel(parent);
}
while (parent != -1);
}
maxLine = ctrl->GetLastChild(line, -1);
for (i = UnfoldUpto; i <= maxLine; ++i)
DoFoldLine(i, fold);
}
bool cbEditor::DoFoldLine(int line, int fold)
{
cbAssert(m_pControl);
if (m_SplitType != stNoSplit)
cbAssert(m_pControl2);
cbStyledTextCtrl* ctrl = GetControl();
int level = ctrl->GetFoldLevel(line);
// The fold parameter is the type of folding action requested
// 0 = Unfold; 1 = Fold; 2 = Toggle folding.
// Check if the line is a header (fold point).
if (level & wxSCI_FOLDLEVELHEADERFLAG)
{
bool IsExpanded = ctrl->GetFoldExpanded(line);
// If a fold/unfold request is issued when the block is already
// folded/unfolded, ignore the request.
if (fold == 0 && IsExpanded) return true;
if (fold == 1 && !IsExpanded) return true;
// Apply the folding level limit only if the current block will be
// folded (that means it's currently expanded), folding level limiter
// must be enabled of course. Unfolding will not be affected.
if (m_pData->mFoldingLimit && IsExpanded)
{
if ((level & wxSCI_FOLDLEVELNUMBERMASK) > (wxSCI_FOLDLEVELBASE + m_pData->mFoldingLimitLevel-1))
return false;
}
ctrl->ToggleFold(line);
return true;
}
return false;
}
void cbEditor::FoldAll()
{
DoFoldAll(1);
}
void cbEditor::UnfoldAll()
{
DoFoldAll(0);
}
void cbEditor::ToggleAllFolds()
{
DoFoldAll(2);
}