diff options
author | Miklos Vajna <vmiklos@suse.cz> | 2012-08-10 21:09:40 +0200 |
---|---|---|
committer | Petr Mladek <pmladek@suse.cz> | 2012-08-14 11:50:01 +0200 |
commit | b5edfe152737650772504dc6464dbbb2f607f453 (patch) | |
tree | 1d707e0a1a3678279516a0f3bb9c5ed63225e786 | |
parent | 53f23d99b0f5549ede0b5e868f884c7bce2e9746 (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.cxx | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx index 4d0aa7235eb8..a2a58fc52137 100644 --- a/sw/source/core/doc/docfld.cxx +++ b/sw/source/core/doc/docfld.cxx @@ -1296,18 +1296,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; } |