sw/inc/IDocumentSettingAccess.hxx | 3 +- sw/inc/doc.hxx | 1 sw/source/core/doc/doc.cxx | 4 ++ sw/source/core/doc/docnew.cxx | 1 sw/source/core/layout/frmtool.cxx | 39 +++++++++++++++++++++++++++- sw/source/ui/uno/SwXDocumentSettings.cxx | 16 ++++++++++- writerfilter/source/filter/ImportFilter.cxx | 2 + 7 files changed, 63 insertions(+), 3 deletions(-)
New commits: commit 50a1df360c907d8419ce49f098b6bc87a37a9956 Author: Miklos Vajna <vmik...@suse.cz> Date: Thu Aug 23 12:11:08 2012 +0200 n#775899 sw: add FloattableNomargins compat flag The DOCX filter imports floating tables as frames containing a table. Word ignores the margins of paragraphs next to such a table, Writer does not. Add a compatibility flag the import filter can set that triggers this weird behaviour. Change-Id: Iaaa1d2a2e2f9d0eaea17832b2e418f9a845efffd diff --git a/sw/inc/IDocumentSettingAccess.hxx b/sw/inc/IDocumentSettingAccess.hxx index dd907f2..8263ca6 100644 --- a/sw/inc/IDocumentSettingAccess.hxx +++ b/sw/inc/IDocumentSettingAccess.hxx @@ -94,7 +94,8 @@ namespace com { namespace sun { namespace star { namespace i18n { struct Forbidd PURGE_OLE, KERN_ASIAN_PUNCTUATION, MATH_BASELINE_ALIGNMENT, - STYLES_NODEFAULT + STYLES_NODEFAULT, + FLOATTABLE_NOMARGINS }; public: diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx index c18635e..2702d1c 100644 --- a/sw/inc/doc.hxx +++ b/sw/inc/doc.hxx @@ -567,6 +567,7 @@ private: // attribute 'WrapInfluenceOnObjPos'. bool mbMathBaselineAlignment : 1; // TL 2010-10-29 #i972# bool mbStylesNoDefault : 1; + bool mbFloattableNomargins : 1; ///< If paragraph margins next to a floating table should be ignored. // non-ui-compatibility flags: bool mbOldNumbering : 1; diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx index 834bc96..45749b4 100644 --- a/sw/source/core/doc/doc.cxx +++ b/sw/source/core/doc/doc.cxx @@ -210,6 +210,7 @@ bool SwDoc::get(/*[in]*/ DocumentSettingId id) const case DO_NOT_RESET_PARA_ATTRS_FOR_NUM_FONT: return mbDoNotResetParaAttrsForNumFont; case MATH_BASELINE_ALIGNMENT: return mbMathBaselineAlignment; case STYLES_NODEFAULT: return mbStylesNoDefault; + case FLOATTABLE_NOMARGINS: return mbFloattableNomargins; default: OSL_FAIL("Invalid setting id"); } @@ -381,6 +382,9 @@ void SwDoc::set(/*[in]*/ DocumentSettingId id, /*[in]*/ bool value) case STYLES_NODEFAULT: mbStylesNoDefault = value; break; + case FLOATTABLE_NOMARGINS: + mbFloattableNomargins = value; + break; default: OSL_FAIL("Invalid setting id"); } diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx index 878223c..1a89837 100644 --- a/sw/source/core/doc/docnew.cxx +++ b/sw/source/core/doc/docnew.cxx @@ -356,6 +356,7 @@ SwDoc::SwDoc() mbSmallCapsPercentage66 = false; // hidden mbTabOverflow = true; mbUnbreakableNumberings = false; + mbFloattableNomargins = false; // // COMPATIBILITY FLAGS END diff --git a/sw/source/core/layout/frmtool.cxx b/sw/source/core/layout/frmtool.cxx index 4d2e231..1f190aa 100644 --- a/sw/source/core/layout/frmtool.cxx +++ b/sw/source/core/layout/frmtool.cxx @@ -1928,6 +1928,26 @@ long SwBorderAttrs::CalcRight( const SwFrm* pCaller ) const return nRight; } +/// Tries to detect if this paragraph has a floating table attached. +bool lcl_hasTabFrm(const SwTxtFrm* pTxtFrm) +{ + if (pTxtFrm->GetDrawObjs()) + { + const SwSortedObjs* pSortedObjs = pTxtFrm->GetDrawObjs(); + if (pSortedObjs->Count() > 0) + { + SwAnchoredObject* pObject = (*pSortedObjs)[0]; + if (pObject->IsA(TYPE(SwFlyFrm))) + { + SwFlyFrm* pFly = (SwFlyFrm*)pObject; + if (pFly->Lower()->IsTabFrm()) + return true; + } + } + } + return false; +} + long SwBorderAttrs::CalcLeft( const SwFrm *pCaller ) const { long nLeft=0; @@ -1945,7 +1965,24 @@ long SwBorderAttrs::CalcLeft( const SwFrm *pCaller ) const if ( pCaller->IsTxtFrm() && pCaller->IsRightToLeft() ) nLeft += rLR.GetRight(); else - nLeft += rLR.GetLeft(); + { + bool bIgnoreMargin = false; + if (pCaller->IsTxtFrm()) + { + const SwTxtFrm* pTxtFrm = (const SwTxtFrm*)pCaller; + if (pTxtFrm->GetTxtNode()->GetDoc()->get(IDocumentSettingAccess::FLOATTABLE_NOMARGINS)) + { + // If this is explicitly requested, ignore the margins next to the floating table. + if (lcl_hasTabFrm(pTxtFrm)) + bIgnoreMargin = true; + // TODO here we only handle the first two paragraphs, would be nice to generalize this. + else if (pTxtFrm->FindPrev() && pTxtFrm->FindPrev()->IsTxtFrm() && lcl_hasTabFrm((const SwTxtFrm*)pTxtFrm->FindPrev())) + bIgnoreMargin = true; + } + } + if (!bIgnoreMargin) + nLeft += rLR.GetLeft(); + } // correction: do not retrieve left margin for numbering in R2L-layout diff --git a/sw/source/ui/uno/SwXDocumentSettings.cxx b/sw/source/ui/uno/SwXDocumentSettings.cxx index 69e44a6..f77aefc 100644 --- a/sw/source/ui/uno/SwXDocumentSettings.cxx +++ b/sw/source/ui/uno/SwXDocumentSettings.cxx @@ -126,7 +126,8 @@ enum SwDocumentSettingsPropertyHandles HANDLE_SMALL_CAPS_PERCENTAGE_66, HANDLE_TAB_OVERFLOW, HANDLE_UNBREAKABLE_NUMBERINGS, - HANDLE_STYLES_NODEFAULT + HANDLE_STYLES_NODEFAULT, + HANDLE_FLOATTABLE_NOMARGINS }; MasterPropertySetInfo * lcl_createSettingsInfo() @@ -190,6 +191,7 @@ MasterPropertySetInfo * lcl_createSettingsInfo() { RTL_CONSTASCII_STRINGPARAM("TabOverflow"), HANDLE_TAB_OVERFLOW, CPPUTYPE_BOOLEAN, 0, 0}, { RTL_CONSTASCII_STRINGPARAM("UnbreakableNumberings"), HANDLE_UNBREAKABLE_NUMBERINGS, CPPUTYPE_BOOLEAN, 0, 0}, { RTL_CONSTASCII_STRINGPARAM("StylesNoDefault"), HANDLE_STYLES_NODEFAULT, CPPUTYPE_BOOLEAN, 0, 0}, + { RTL_CONSTASCII_STRINGPARAM("FloattableNomargins"), HANDLE_FLOATTABLE_NOMARGINS, CPPUTYPE_BOOLEAN, 0, 0}, /* * As OS said, we don't have a view when we need to set this, so I have to * find another solution before adding them to this property set - MTG @@ -755,6 +757,12 @@ void SwXDocumentSettings::_setSingleValue( const comphelper::PropertyInfo & rInf mpDoc->set(IDocumentSettingAccess::STYLES_NODEFAULT, bTmp); } break; + case HANDLE_FLOATTABLE_NOMARGINS: + { + sal_Bool bTmp = *(sal_Bool*)rValue.getValue(); + mpDoc->set(IDocumentSettingAccess::FLOATTABLE_NOMARGINS, bTmp); + } + break; default: throw UnknownPropertyException(); } @@ -1133,6 +1141,12 @@ void SwXDocumentSettings::_getSingleValue( const comphelper::PropertyInfo & rInf rValue.setValue( &bTmp, ::getBooleanCppuType() ); } break; + case HANDLE_FLOATTABLE_NOMARGINS: + { + sal_Bool bTmp = mpDoc->get( IDocumentSettingAccess::FLOATTABLE_NOMARGINS ); + rValue.setValue( &bTmp, ::getBooleanCppuType() ); + } + break; default: throw UnknownPropertyException(); } diff --git a/writerfilter/source/filter/ImportFilter.cxx b/writerfilter/source/filter/ImportFilter.cxx index 8952703..8e60b56 100644 --- a/writerfilter/source/filter/ImportFilter.cxx +++ b/writerfilter/source/filter/ImportFilter.cxx @@ -176,6 +176,8 @@ void WriterFilter::setTargetDocument( const uno::Reference< lang::XComponent >& // Don't load the default style definitions to avoid weird mix xSettings->setPropertyValue( "StylesNoDefault", uno::makeAny( sal_True ) ); + + xSettings->setPropertyValue("FloattableNomargins", uno::makeAny( sal_True )); } void WriterFilter::setSourceDocument( const uno::Reference< lang::XComponent >& xDoc ) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits