summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2015-09-07 16:36:24 +0200
committerAndras Timar <andras.timar@collabora.com>2015-09-19 21:32:04 +0200
commitc7e4b92e17b4532b3b4fc0bbe40aa3c05a0568d9 (patch)
tree57407af5175739fb1b070893fd5fdb67ca8aca59 /sw
parentcb7bc699ccd30ee013b48fd9e45db06cf2cb8c9c (diff)
tdf#91383: sw: prevent style preview from actually creating styles
The dialog/sidebar should not actually create styles that don't exist yet, because it messes up Undo and the (unused) styles are then unnecessarily exported to documents. Due to Writer's ... unusual SwDocStyleSheet class this is a bit tricky. Add a new function GetItemSetForPreview() and use it from the style preview code. The implementation does not use FillPhysical so will temporarily create and then delete any non-existing styles. Skip page and numbering styles for now since they don't have a useful preview. (regression from ca95307638207db5d662059aa61594151a13e927) (cherry picked from commit 93067f37cf22aa119db5878c4345fea500cbbb42) -Werror,-Wreturn-type (cherry picked from commit 0ed64030f17849ea943800343003c5ec3f4f1388) Change-Id: Id6ee30ea467fc24c991547a4c23a9ce14fdd86c7 Reviewed-on: https://gerrit.libreoffice.org/18381 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/docstyle.hxx7
-rw-r--r--sw/source/uibase/app/docstyle.cxx70
2 files changed, 73 insertions, 4 deletions
diff --git a/sw/inc/docstyle.hxx b/sw/inc/docstyle.hxx
index 1298cc618467..275d5e2edc9d 100644
--- a/sw/inc/docstyle.hxx
+++ b/sw/inc/docstyle.hxx
@@ -61,10 +61,12 @@ class SW_DLLPUBLIC SwDocStyleSheet : public SfxStyleSheetBase
enum FillStyleType {
FillOnlyName,
FillAllInfo,
- FillPhysical
+ FillPhysical,
+ FillPreview,
};
- SAL_DLLPRIVATE bool FillStyleSheet( FillStyleType eFType );
+ SAL_DLLPRIVATE bool FillStyleSheet(FillStyleType eFType,
+ std::unique_ptr<SfxItemSet> * o_ppFlatSet = nullptr);
protected:
virtual ~SwDocStyleSheet();
@@ -99,6 +101,7 @@ public:
const bool bResetIndentAttrsAtParagraphStyle = false );
virtual SfxItemSet& GetItemSet() SAL_OVERRIDE;
+ virtual std::unique_ptr<SfxItemSet> GetItemSetForPreview() override;
/** new method for paragraph styles to merge indent attributes of applied list
style into the given item set, if the list style indent attributes are applicable. */
void MergeIndentAttrsOfListStyle( SfxItemSet& rSet );
diff --git a/sw/source/uibase/app/docstyle.cxx b/sw/source/uibase/app/docstyle.cxx
index 8c0c438ecfbf..6727cb8aa8a2 100644
--- a/sw/source/uibase/app/docstyle.cxx
+++ b/sw/source/uibase/app/docstyle.cxx
@@ -17,6 +17,10 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <cstdlib>
+
#include <svl/smplhint.hxx>
#include <hintids.hxx>
#include <svl/itemiter.hxx>
@@ -1169,6 +1173,61 @@ bool SwDocStyleSheet::SetFollow( const OUString& rStr)
return true;
}
+static
+std::unique_ptr<SfxItemSet> lcl_SwFormatToFlatItemSet(SwFormat *const pFormat)
+{
+ // note: we don't add the odd items that GetItemSet() would add
+ // because they don't seem relevant for preview
+ std::vector<SfxItemSet const*> sets;
+ sets.push_back(&pFormat->GetAttrSet());
+ while (SfxItemSet const*const pParent = sets.back()->GetParent())
+ {
+ sets.push_back(pParent);
+ }
+ // start by copying top-level parent set
+ std::unique_ptr<SfxItemSet> pRet(new SfxItemSet(*sets.back()));
+ sets.pop_back();
+ for (auto iter = sets.rbegin(); iter != sets.rend(); ++iter)
+ { // in reverse so child overrides parent
+ pRet->Put(**iter);
+ }
+ return pRet;
+}
+
+std::unique_ptr<SfxItemSet> SwDocStyleSheet::GetItemSetForPreview()
+{
+ if (SFX_STYLE_FAMILY_PAGE == nFamily || SFX_STYLE_FAMILY_PSEUDO == nFamily)
+ {
+ SAL_WARN("sw.ui", "GetItemSetForPreview not implemented for page or number style");
+ return std::unique_ptr<SfxItemSet>();
+ }
+ if (!bPhysical)
+ {
+ // because not only this style, but also any number of its parents
+ // (or follow style) may not actually exist in the document at this
+ // time, return one "flattened" item set that contains all items from
+ // all parents.
+ std::unique_ptr<SfxItemSet> pRet;
+ FillStyleSheet(FillPreview, &pRet);
+ assert(pRet);
+ return pRet;
+ }
+ else
+ {
+ switch (nFamily)
+ {
+ case SFX_STYLE_FAMILY_CHAR:
+ return lcl_SwFormatToFlatItemSet(pCharFormat);
+ case SFX_STYLE_FAMILY_PARA:
+ return lcl_SwFormatToFlatItemSet(pColl);
+ case SFX_STYLE_FAMILY_FRAME:
+ return lcl_SwFormatToFlatItemSet(pFrameFormat);
+ default:
+ std::abort();
+ }
+ }
+}
+
// extract ItemSet to Name and Family, Mask
SfxItemSet& SwDocStyleSheet::GetItemSet()
@@ -1709,7 +1768,8 @@ static void lcl_DeleteInfoStyles( sal_uInt16 nFamily, std::vector<void*>& rArr,
}
// determine the format
-bool SwDocStyleSheet::FillStyleSheet( FillStyleType eFType )
+bool SwDocStyleSheet::FillStyleSheet(
+ FillStyleType const eFType, std::unique_ptr<SfxItemSet> *const o_ppFlatSet)
{
bool bRet = false;
sal_uInt16 nPoolId = USHRT_MAX;
@@ -1717,7 +1777,7 @@ bool SwDocStyleSheet::FillStyleSheet( FillStyleType eFType )
bool bCreate = FillPhysical == eFType;
bool bDeleteInfo = false;
- bool bFillOnlyInfo = FillAllInfo == eFType;
+ bool bFillOnlyInfo = FillAllInfo == eFType || FillPreview == eFType;
std::vector<void*> aDelArr;
switch(nFamily)
@@ -1892,6 +1952,12 @@ bool SwDocStyleSheet::FillStyleSheet( FillStyleType eFType )
if( RES_CONDTXTFMTCOLL == pFormat->Which() )
_nMask |= SWSTYLEBIT_CONDCOLL;
+
+ if (FillPreview == eFType)
+ {
+ assert(o_ppFlatSet);
+ *o_ppFlatSet = lcl_SwFormatToFlatItemSet(pFormat);
+ }
}
SetMask( _nMask );