summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2015-09-07 16:36:24 +0200
committerMichael Stahl <mstahl@redhat.com>2015-09-07 16:49:58 +0200
commit93067f37cf22aa119db5878c4345fea500cbbb42 (patch)
treef8660673667e6addc9b08b2e76350cbac469ddee /sw
parent110dc43d97d559b6369bca308f9dd39fd02e751e (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) Change-Id: Id6ee30ea467fc24c991547a4c23a9ce14fdd86c7
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/docstyle.hxx7
-rw-r--r--sw/source/uibase/app/docstyle.cxx66
2 files changed, 69 insertions, 4 deletions
diff --git a/sw/inc/docstyle.hxx b/sw/inc/docstyle.hxx
index f874ac57c457..e50c3c01b5c2 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 9f4dbdc0be04..0f824c8de827 100644
--- a/sw/source/uibase/app/docstyle.cxx
+++ b/sw/source/uibase/app/docstyle.cxx
@@ -1163,6 +1163,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:
+ assert(false);
+ }
+ }
+}
+
// extract ItemSet to Name and Family, Mask
SfxItemSet& SwDocStyleSheet::GetItemSet()
@@ -1703,7 +1758,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;
@@ -1711,7 +1767,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)
@@ -1879,6 +1935,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 );