[Libreoffice-commits] .: sw/source

Miklos Vajna vmiklos at kemper.freedesktop.org
Fri Aug 10 12:11:56 PDT 2012


 sw/source/core/doc/docfld.cxx |   27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

New commits:
commit bb6bd1ff9cd3eecec7eb2cd7bd0a4dcef584c903
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Fri Aug 10 21:09:40 2012 +0200

    fdo#53210 SwDoc::UpdateExpFlds don't crash when hiding all sections
    
    Change-Id: I9b7a61f18f987214708195a89f6e346c865c7f9f

diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx
index aa5156e..b70ddcc 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;
         }
 


More information about the Libreoffice-commits mailing list