summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sw/source/core/doc/docfld.cxx27
1 files changed, 26 insertions, 1 deletions
diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx
index aa5156e39ff8..b70ddccea06f 100644
--- a/sw/source/core/doc/docfld.cxx
+++ b/sw/source/core/doc/docfld.cxx
@@ -1288,6 +1288,15 @@ void SwDoc::UpdateExpFlds( SwTxtFld* pUpdtFld, bool bUpdRefFlds )
SwNewDBMgr* pMgr = GetNewDBMgr();
pMgr->CloseAll(sal_False);
+ // Make sure we don't hide all sections, which would lead to a crash. First, count how many of them do we have.
+ int nShownSections = 0;
+ for( _SetGetExpFlds::const_iterator it = pUpdtFlds->GetSortLst()->begin(); it != pUpdtFlds->GetSortLst()->end(); ++it )
+ {
+ SwSection* pSect = (SwSection*)(*it)->GetSection();
+ if ( pSect && !pSect->IsCondHidden())
+ nShownSections++;
+ }
+
String aNew;
for( _SetGetExpFlds::const_iterator it = pUpdtFlds->GetSortLst()->begin(); it != pUpdtFlds->GetSortLst()->end(); ++it )
{
@@ -1298,7 +1307,23 @@ void SwDoc::UpdateExpFlds( SwTxtFld* pUpdtFld, bool bUpdRefFlds )
SwSbxValue aValue = aCalc.Calculate(
pSect->GetCondition() );
if(!aValue.IsVoidValue())
- pSect->SetCondHidden( aValue.GetBool() );
+ {
+ // Do we want to hide this one?
+ bool bHide = aValue.GetBool();
+ if (bHide && !pSect->IsCondHidden())
+ {
+ // This section will be hidden, but it wasn't before
+ if (nShownSections == 1)
+ {
+ // This would be the last section, so set its condition to false, and avoid hiding it.
+ OUString aCond("0");
+ pSect->SetCondition(aCond);
+ bHide = false;
+ }
+ nShownSections--;
+ }
+ pSect->SetCondHidden( bHide );
+ }
continue;
}