[Libreoffice-commits] .: Branch 'libreoffice-3-6' - sw/source

Petr Mladek pmladek at kemper.freedesktop.org
Tue Aug 14 02:52:07 PDT 2012


 sw/source/core/doc/docfld.cxx |   30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

New commits:
commit b5edfe152737650772504dc6464dbbb2f607f453
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
    
    (cherry picked from commit bb6bd1ff9cd3eecec7eb2cd7bd0a4dcef584c903)
    
    Change-Id: I9b7a61f18f987214708195a89f6e346c865c7f9f
    
    Signed-off-by: Petr Mladek <pmladek at suse.cz>

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


More information about the Libreoffice-commits mailing list