summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@suse.cz>2012-08-10 21:09:40 +0200
committerPetr Mladek <pmladek@suse.cz>2012-08-14 11:59:20 +0200
commitd2a5e4bb705673119b13c2e203562fecfd386be8 (patch)
tree7c66fc5b86e66f63d0bb8c21fd1f4c4739bd80ab
parent98e895db332446b3fe2fc901a6cf9cff64d2b1b8 (diff)
fdo#53210 SwDoc::UpdateExpFlds don't crash when hiding all sections
(cherry picked from commit bb6bd1ff9cd3eecec7eb2cd7bd0a4dcef584c903) Change-Id: I9b7a61f18f987214708195a89f6e346c865c7f9f Signed-off-by: Petr Mladek <pmladek@suse.cz>
-rw-r--r--sw/source/core/doc/docfld.cxx30
1 files changed, 28 insertions, 2 deletions
diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx
index b7c65498134a..9e3e564457f9 100644
--- a/sw/source/core/doc/docfld.cxx
+++ b/sw/source/core/doc/docfld.cxx
@@ -1300,18 +1300,44 @@ void SwDoc::UpdateExpFlds( SwTxtFld* pUpdtFld, bool bUpdRefFlds )
SwNewDBMgr* pMgr = GetNewDBMgr();
pMgr->CloseAll(sal_False);
- String aNew;
+ // 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;
const _SetGetExpFldPtr* ppSortLst = pUpdtFlds->GetSortLst()->GetData();
for( n = pUpdtFlds->GetSortLst()->Count(); n; --n, ++ppSortLst )
{
SwSection* pSect = (SwSection*)(*ppSortLst)->GetSection();
+ if ( pSect && !pSect->IsCondHidden())
+ nShownSections++;
+ }
+
+ String aNew;
+ ppSortLst = pUpdtFlds->GetSortLst()->GetData();
+ for( n = pUpdtFlds->GetSortLst()->Count(); n; --n, ++ppSortLst )
+ {
+ SwSection* pSect = (SwSection*)(*ppSortLst)->GetSection();
if( pSect )
{
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.
+ rtl::OUString aCond(RTL_CONSTASCII_USTRINGPARAM("0"));
+ pSect->SetCondition(aCond);
+ bHide = false;
+ }
+ nShownSections--;
+ }
+ pSect->SetCondHidden( bHide );
+ }
continue;
}