[Libreoffice-commits] core.git: Branch 'private/jmux/layout-fixes' - 3 commits - sw/inc sw/source

Jan-Marek Glogowski glogow at fbihome.de
Tue Jul 15 07:54:29 PDT 2014


Rebased ref, commits from common ancestor:
commit 523cc64a0ff6f054e954af2f92b705a8bdbd088a
Author: Jan-Marek Glogowski <glogow at fbihome.de>
Date:   Sun Jul 13 20:18:56 2014 +0200

    Refactor a tiny bit of SwLayAction::IsShortCut
    
    Change-Id: I13d4fbebec02bddaa27e8929188d497dde715730

diff --git a/sw/source/core/layout/layact.cxx b/sw/source/core/layout/layact.cxx
index 023f64f..0fcbf8d 100644
--- a/sw/source/core/layout/layact.cxx
+++ b/sw/source/core/layout/layact.cxx
@@ -1173,15 +1173,13 @@ bool SwLayAction::IsShortCut( SwPageFrm *&prPage )
                 }
                 // #121980# - no shortcut, if at previous page
                 // an anchored object is registered, whose anchor is <pCntnt>.
-                else if ( prPage->GetPrev() &&
-                          static_cast<SwPageFrm*>(prPage->GetPrev())->GetSortedObjs() )
+                else if ( prPage->GetPrev() )
                 {
                     SwSortedObjs* pObjs =
                         static_cast<SwPageFrm*>(prPage->GetPrev())->GetSortedObjs();
                     if ( pObjs )
                     {
-                        sal_uInt32 i = 0;
-                        for ( ; i < pObjs->Count(); ++i )
+                        for ( sal_uInt32 i = 0; i < pObjs->Count(); ++i )
                         {
                             SwAnchoredObject* pObj = (*pObjs)[i];
                             if ( pObj->GetAnchorFrmContainingAnchPos() == pCntnt )
commit 1812509d77b5fccd499bc87019e33d1a77db7a0b
Author: Jan-Marek Glogowski <glogow at fbihome.de>
Date:   Sun Jul 13 20:15:55 2014 +0200

    fdo#80926 Don't move anchors of invalid pages
    
    If the anchor is valid, check if its page is valid too,
    before moving anchors on view change.
    
    Change-Id: Idffdfdb786cb29a105c06d652e6ad7315abfb4c5

diff --git a/sw/source/core/view/vdraw.cxx b/sw/source/core/view/vdraw.cxx
index db32944..143169f 100644
--- a/sw/source/core/view/vdraw.cxx
+++ b/sw/source/core/view/vdraw.cxx
@@ -228,6 +228,17 @@ void SwViewImp::NotifySizeChg( const Size &rNewSz )
             {
                 continue;
             }
+            else
+            {
+                // Actually this should never happen but currently layouting
+                // is broken. So don't move anchors, if the page is invalid.
+                // This should be turned into an DBG_ASSERT, once layouting is fixed!
+                const SwPageFrm *pPageFrm = pAnchor->FindPageFrm();
+                if (!pPageFrm || pPageFrm->IsInvalid() ) {
+                    SAL_WARN( "sw.resizeview", "Trying to move anchor from invalid page - fix layouting!" );
+                    continue;
+                }
+            }
 
             // no move for drawing objects in header/footer
             if ( pAnchor->FindFooterOrHeader() )
commit 3de4591ae774160334a6c36ab9089c3ab6c2f0ec
Author: Jan-Marek Glogowski <glogow at fbihome.de>
Date:   Sat Jul 12 23:17:31 2014 +0200

    fdo#70346 MM: add mail merge data to condition dict
    
    Currently hidden section conditions are just evaluated based on
    other field data.
    
    For mail merge this adds the current dataset to the condition
    dictionary, so this can be evaluated too.
    
    Change-Id: I82a5f9f6962628a76c836e8e2a7c9e264fdc16e0

diff --git a/sw/inc/dbfld.hxx b/sw/inc/dbfld.hxx
index 8677265..d9d92f0 100644
--- a/sw/inc/dbfld.hxx
+++ b/sw/inc/dbfld.hxx
@@ -109,6 +109,9 @@ public:
     inline const SwDBData&  GetDBData() const { return ((SwDBFieldType*)GetTyp())->GetDBData(); }
     virtual bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const SAL_OVERRIDE;
     virtual bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) SAL_OVERRIDE;
+
+    static bool FormatValue( SvNumberFormatter* pDocFormatter, OUString &aString, sal_uInt32 nFmt,
+                             double &aNumber, sal_Int32 nColumnType, SwDBField *pField = NULL );
 };
 
 inline  void SwDBField::SetExpansion(const OUString& rStr)
diff --git a/sw/inc/dbmgr.hxx b/sw/inc/dbmgr.hxx
index 4eb8721..1a07cdf 100644
--- a/sw/inc/dbmgr.hxx
+++ b/sw/inc/dbmgr.hxx
@@ -29,6 +29,8 @@
 #include <com/sun/star/lang/Locale.hpp>
 #include <com/sun/star/beans/PropertyValue.hpp>
 #include <boost/ptr_container/ptr_vector.hpp>
+#include <calc.hxx>
+
 namespace com{namespace sun{namespace star{
     namespace sdbc{
         class XConnection;
@@ -299,7 +301,9 @@ public:
     void            CloseAll(bool bIncludingMerge = true);
 
     bool            GetMergeColumnCnt(const OUString& rColumnName, sal_uInt16 nLanguage,
-                                OUString &rResult, double *pNumber, sal_uInt32 *pFormat);
+                                      OUString &rResult, double *pNumber, sal_uInt32 *pFormat);
+    bool            FillCalcWithMergeData(SvNumberFormatter *pDocFormatter,
+                                          sal_uInt16 nLanguage, bool asString, SwCalc &aCalc);
     bool            ToNextMergeRecord();
     bool            ToNextRecord(const OUString& rDataSource, const OUString& rTableOrQuery, sal_Int32 nCommandType = -1);
 
diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx
index df6bc19..426b04e 100644
--- a/sw/source/core/doc/docfld.cxx
+++ b/sw/source/core/doc/docfld.cxx
@@ -1281,7 +1281,10 @@ void SwDoc::UpdateExpFlds( SwTxtFld* pUpdtFld, bool bUpdRefFlds )
 
     // already set the current record number
     SwDBManager* pMgr = GetDBManager();
-    pMgr->CloseAll(false);
+    pMgr->CloseAll( false );
+
+    // FIXME: GetLanguage() instead of LANGUAGE_SYSTEM
+    bool bCanFill = pMgr->FillCalcWithMergeData( GetNumberFormatter(), LANGUAGE_SYSTEM, true, aCalc );
 #endif
 
     // Make sure we don't hide all sections, which would lead to a crash. First, count how many of them do we have.
@@ -1376,6 +1379,8 @@ void SwDoc::UpdateExpFlds( SwTxtFld* pUpdtFld, bool bUpdRefFlds )
 #if HAVE_FEATURE_DBCONNECTIVITY
         {
             UpdateDBNumFlds( *(SwDBNameInfField*)pFld, aCalc );
+            if( bCanFill )
+                bCanFill = pMgr->FillCalcWithMergeData( GetNumberFormatter(), LANGUAGE_SYSTEM, true, aCalc );
         }
 #endif
         break;
diff --git a/sw/source/core/fields/dbfld.cxx b/sw/source/core/fields/dbfld.cxx
index 0a1d8a6..b34f450 100644
--- a/sw/source/core/fields/dbfld.cxx
+++ b/sw/source/core/fields/dbfld.cxx
@@ -262,6 +262,52 @@ SwFieldType* SwDBField::ChgTyp( SwFieldType* pNewType )
     return pOld;
 }
 
+bool SwDBField::FormatValue( SvNumberFormatter* pDocFormatter, OUString &aString, sal_uInt32 nFmt,
+                             double &aNumber, sal_Int32 nColumnType, SwDBField *pField )
+{
+    bool bValidValue = false;
+
+    if( DBL_MAX != aNumber )
+    {
+        if( DataType::DATE == nColumnType || DataType::TIME == nColumnType ||
+            DataType::TIMESTAMP  == nColumnType )
+        {
+            Date aStandard( 1, 1, 1900 );
+            if( *pDocFormatter->GetNullDate() != aStandard )
+                aNumber += (aStandard - *pDocFormatter->GetNullDate());
+        }
+        bValidValue = true;
+        if( pField )
+            pField->SetValue( aNumber );
+    }
+    else
+    {
+        SwSbxValue aVal;
+        aVal.PutString( aString );
+
+        if (aVal.IsNumeric())
+        {
+            if( pField )
+                pField->SetValue(aVal.GetDouble());
+            else
+                aNumber = aVal.GetDouble();
+
+            if (nFmt && nFmt != SAL_MAX_UINT32 && !pDocFormatter->IsTextFormat(nFmt))
+                bValidValue = true; // because of bug #60339 not for all strings
+        }
+        else
+        {
+            // if string length > 0 then true, else false
+            if( pField )
+                pField->SetValue(aString.isEmpty() ? 0 : 1);
+            else
+                aNumber = aString.isEmpty() ? 0 : 1;
+        }
+    }
+
+    return bValidValue;
+}
+
 /// get current field value and cache it
 void SwDBField::Evaluate()
 {
@@ -286,40 +332,15 @@ void SwDBField::Evaluate()
         SetFormat( nFmt = pMgr->GetColumnFmt( aTmpData.sDataSource, aTmpData.sCommand,
                                         aColNm, pDocFormatter, GetLanguage() ));
 
+    sal_Int32 nColumnType;
     if( DBL_MAX != nValue )
-    {
-        sal_Int32 nColumnType = pMgr->GetColumnType(aTmpData.sDataSource, aTmpData.sCommand, aColNm);
-        if( DataType::DATE == nColumnType  || DataType::TIME == nColumnType  ||
-                 DataType::TIMESTAMP  == nColumnType)
+        nColumnType = pMgr->GetColumnType(aTmpData.sDataSource, aTmpData.sCommand, aColNm);
 
-        {
-            Date aStandard(1,1,1900);
-            if (*pDocFormatter->GetNullDate() != aStandard)
-                nValue += (aStandard - *pDocFormatter->GetNullDate());
-        }
-        bValidValue = true;
-        SetValue(nValue);
-        aContent = ((SwValueFieldType*)GetTyp())->ExpandValue(nValue, GetFormat(), GetLanguage());
-    }
-    else
-    {
-        SwSbxValue aVal;
-        aVal.PutString( aContent );
+    bValidValue = FormatValue( pDocFormatter, aContent, nFmt, nValue, nColumnType, this );
 
-        if (aVal.IsNumeric())
-        {
-            SetValue(aVal.GetDouble());
+    if( DBL_MAX != nValue )
+        aContent = ((SwValueFieldType*)GetTyp())->ExpandValue(nValue, GetFormat(), GetLanguage());
 
-            SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
-            if (nFmt && nFmt != SAL_MAX_UINT32 && !pFormatter->IsTextFormat(nFmt))
-                bValidValue = true; // because of bug #60339 not for all strings
-        }
-        else
-        {
-            // if string length > 0 then true, else false
-            SetValue(aContent.isEmpty() ? 0 : 1);
-        }
-    }
     bInitialized = true;
 }
 
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index 0601873..84e2d90 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -127,6 +127,8 @@
 #include <rootfrm.hxx>
 #include <fmtpdsc.hxx>
 #include <ndtxt.hxx>
+#include <calc.hxx>
+#include <dbfld.hxx>
 
 #include <boost/scoped_ptr.hpp>
 
@@ -1059,7 +1061,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
                             pWorkDoc->SetDBManager( this );
                             pWorkDoc->EmbedAllLinks();
 
-                            // #i69485# lock fields to prevent access to the result set while calculating layout
+                            // #i69458# lock fields to prevent access to the result set while calculating layout
                             rWorkShell.LockExpFlds();
                             rWorkShell.CalcLayout();
                             rWorkShell.UnlockExpFlds();
@@ -1849,6 +1851,74 @@ bool SwDBManager::ToNextMergeRecord()
     return ToNextRecord(pImpl->pMergeData);
 }
 
+bool SwDBManager::FillCalcWithMergeData( SvNumberFormatter *pDocFormatter,
+                                         sal_uInt16 nLanguage, bool asString, SwCalc &aCalc )
+{
+    if (!(pImpl->pMergeData && pImpl->pMergeData->xResultSet.is()))
+        return false;
+
+    uno::Reference< XColumnsSupplier > xColsSupp( pImpl->pMergeData->xResultSet, UNO_QUERY );
+    if(xColsSupp.is())
+    {
+        uno::Reference<XNameAccess> xCols = xColsSupp->getColumns();
+        const Sequence<OUString> aColNames = xCols->getElementNames();
+        const OUString* pColNames = aColNames.getConstArray();
+        OUString aString;
+
+        const bool bExistsNextRecord = ExistsNextRecord();
+
+        for( int nCol = 0; nCol < aColNames.getLength(); nCol++ )
+        {
+            const OUString &rColName = pColNames[nCol];
+
+            // empty variables, if no more records;
+            if( !bExistsNextRecord ) {
+                aCalc.VarChange( rColName, 0 );
+                continue;
+            }
+
+            double aNumber = DBL_MAX;
+            if( lcl_GetColumnCnt(pImpl->pMergeData, rColName, nLanguage, aString, &aNumber) ) {
+                // get the column type
+                sal_Int32 nColumnType;
+                Any aCol = xCols->getByName( pColNames[nCol] );
+                uno::Reference<XPropertySet> xCol;
+                aCol >>= xCol;
+                Any aType = xCol->getPropertyValue( "Type" );
+                aType >>= nColumnType;
+
+                sal_uInt32 nFmt;
+                if( !GetMergeColumnCnt(pColNames[nCol], nLanguage, aString, &aNumber, &nFmt) )
+                    continue;
+
+                // aNumber is overwritten by SwDBField::FormatValue, so store initial status
+                bool colIsNumber = aNumber != DBL_MAX;
+                bool bValidValue = SwDBField::FormatValue( pDocFormatter, aString, nFmt,
+                                                           aNumber, nColumnType, NULL );
+                if( colIsNumber ) {
+                    if( bValidValue ) {
+                        SwSbxValue aValue;
+                        if( !asString )
+                            aValue.PutDouble( aNumber );
+                        else
+                            aValue.PutString( aString );
+                        SAL_INFO( "sw.dbmgr", "'" << pColNames[nCol] << "': " << aNumber << " / " << aString );
+                        aCalc.VarChange( pColNames[nCol], aValue );
+                    }
+                }
+                else {
+                    SwSbxValue aValue;
+                    aValue.PutString( aString );
+                    SAL_INFO( "sw.dbmgr", "'" << pColNames[nCol] << "': " << aString );
+                    aCalc.VarChange( pColNames[nCol], aValue );
+                }
+            }
+        }
+        return bExistsNextRecord;
+    }
+    return false;
+}
+
 bool SwDBManager::ToNextRecord(
     const OUString& rDataSource, const OUString& rCommand, sal_Int32 /*nCommandType*/)
 {
@@ -2829,7 +2899,7 @@ sal_Int32 SwDBManager::MergeDocuments( SwMailMergeConfigItem& rMMConfig,
                     }
                 }
 
-                // #i69485# lock fields to prevent access to the result set while calculating layout
+                // #i69458# lock fields to prevent access to the result set while calculating layout
                 rWorkShell.LockExpFlds();
                 // create a layout
                 rWorkShell.CalcLayout();


More information about the Libreoffice-commits mailing list