summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/svl/style.hxx5
-rw-r--r--svl/source/items/style.cxx5
-rw-r--r--svx/source/styles/CommonStylePreviewRenderer.cxx36
-rw-r--r--svx/source/tbxctrls/tbcontrl.cxx35
-rw-r--r--sw/inc/docstyle.hxx7
-rw-r--r--sw/source/uibase/app/docstyle.cxx70
6 files changed, 121 insertions, 37 deletions
diff --git a/include/svl/style.hxx b/include/svl/style.hxx
index 5798b4936285..79eadf62cc7a 100644
--- a/include/svl/style.hxx
+++ b/include/svl/style.hxx
@@ -143,6 +143,11 @@ public:
virtual void SetHelpId( const OUString& r, sal_uLong nId );
virtual SfxItemSet& GetItemSet();
+ /// Due to writer's usual lack of sanity this is a separate function for
+ /// preview only; it shall not create the style in case it does not exist.
+ /// If the style has parents, it is _not_ required that the returned item
+ /// set has parents (i.e. use it for display purposes only).
+ virtual std::unique_ptr<SfxItemSet> GetItemSetForPreview();
};
/* Class to iterate and search on a SfxStyleSheetBasePool */
diff --git a/svl/source/items/style.cxx b/svl/source/items/style.cxx
index bbbd45ede5e2..01da088c0ed4 100644
--- a/svl/source/items/style.cxx
+++ b/svl/source/items/style.cxx
@@ -284,6 +284,11 @@ SfxItemSet& SfxStyleSheetBase::GetItemSet()
return *pSet;
}
+std::unique_ptr<SfxItemSet> SfxStyleSheetBase::GetItemSetForPreview()
+{
+ return std::unique_ptr<SfxItemSet>(new SfxItemSet(GetItemSet()));
+}
+
/**
* Set help file and ID and return it
*/
diff --git a/svx/source/styles/CommonStylePreviewRenderer.cxx b/svx/source/styles/CommonStylePreviewRenderer.cxx
index ab1271ac8fe0..67f9b89670a5 100644
--- a/svx/source/styles/CommonStylePreviewRenderer.cxx
+++ b/svx/source/styles/CommonStylePreviewRenderer.cxx
@@ -60,65 +60,67 @@ CommonStylePreviewRenderer::~CommonStylePreviewRenderer()
bool CommonStylePreviewRenderer::recalculate()
{
- const SfxItemSet& aItemSet = mpStyle->GetItemSet();
-
maFont = SvxFont();
+ std::unique_ptr<SfxItemSet> pItemSet(mpStyle->GetItemSetForPreview());
+
+ if (!pItemSet) return false;
+
const SfxPoolItem* pItem;
- if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_WEIGHT)) != nullptr)
+ if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_WEIGHT)) != nullptr)
{
maFont.SetWeight(static_cast<const SvxWeightItem*>(pItem)->GetWeight());
}
- if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_POSTURE)) != nullptr)
+ if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_POSTURE)) != nullptr)
{
maFont.SetItalic(static_cast<const SvxPostureItem*>(pItem)->GetPosture());
}
- if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_CONTOUR)) != nullptr)
+ if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_CONTOUR)) != nullptr)
{
maFont.SetOutline(static_cast< const SvxContourItem*>(pItem)->GetValue());
}
- if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_SHADOWED)) != nullptr)
+ if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_SHADOWED)) != nullptr)
{
maFont.SetShadow(static_cast<const SvxShadowedItem*>(pItem)->GetValue());
}
- if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_RELIEF)) != nullptr)
+ if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_RELIEF)) != nullptr)
{
maFont.SetRelief(static_cast<FontRelief>(static_cast<const SvxCharReliefItem*>(pItem)->GetValue()));
}
- if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_UNDERLINE)) != nullptr)
+ if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_UNDERLINE)) != nullptr)
{
maFont.SetUnderline(static_cast< const SvxUnderlineItem*>(pItem)->GetLineStyle());
}
- if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_OVERLINE)) != nullptr)
+ if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_OVERLINE)) != nullptr)
{
maFont.SetOverline(static_cast<FontUnderline>(static_cast<const SvxOverlineItem*>(pItem)->GetValue()));
}
- if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_STRIKEOUT)) != nullptr)
+ if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_STRIKEOUT)) != nullptr)
{
maFont.SetStrikeout(static_cast<const SvxCrossedOutItem*>(pItem)->GetStrikeout());
}
- if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_CASEMAP)) != nullptr)
+ if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_CASEMAP)) != nullptr)
{
maFont.SetCaseMap(static_cast<const SvxCaseMapItem*>(pItem)->GetCaseMap());
}
- if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_EMPHASISMARK)) != nullptr)
+ if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_EMPHASISMARK)) != nullptr)
{
maFont.SetEmphasisMark(static_cast<const SvxEmphasisMarkItem*>(pItem)->GetEmphasisMark());
}
- if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_COLOR)) != nullptr)
+ if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_COLOR)) != nullptr)
{
maFontColor = Color(static_cast<const SvxColorItem*>(pItem)->GetValue());
}
if (mpStyle->GetFamily() == SFX_STYLE_FAMILY_PARA)
{
- if ((pItem = aItemSet.GetItem(XATTR_FILLSTYLE)) != nullptr)
+ if ((pItem = pItemSet->GetItem(XATTR_FILLSTYLE)) != nullptr)
{
sal_uInt16 aFillStyle = static_cast<const XFillStyleItem*>(pItem)->GetValue();
if (aFillStyle == drawing::FillStyle_SOLID)
{
- if ((pItem = aItemSet.GetItem(XATTR_FILLCOLOR)) != nullptr)
+ if ((pItem = pItemSet->GetItem(XATTR_FILLCOLOR)) != nullptr)
{
maBackgroundColor = Color(static_cast<const XFillColorItem*>(pItem)->GetColorValue());
}
@@ -126,7 +128,7 @@ bool CommonStylePreviewRenderer::recalculate()
}
}
- if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_FONT)) != nullptr)
+ if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_FONT)) != nullptr)
{
const SvxFontItem* pFontItem = static_cast<const SvxFontItem*>(pItem);
maFont.SetName(pFontItem->GetFamilyName());
@@ -137,7 +139,7 @@ bool CommonStylePreviewRenderer::recalculate()
return false;
}
- if ((pItem = aItemSet.GetItem(SID_ATTR_CHAR_FONTHEIGHT)) != nullptr)
+ if ((pItem = pItemSet->GetItem(SID_ATTR_CHAR_FONTHEIGHT)) != nullptr)
{
const SvxFontHeightItem* pFontHeightItem = static_cast<const SvxFontHeightItem*>(pItem);
Size aFontSize(0, pFontHeightItem->GetHeight());
diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx
index e22c6c67aa98..5e15ccd61f25 100644
--- a/svx/source/tbxctrls/tbcontrl.cxx
+++ b/svx/source/tbxctrls/tbcontrl.cxx
@@ -639,10 +639,13 @@ void SvxStyleBox_Impl::SetupEntry(vcl::RenderContext& rRenderContext, vcl::Windo
if (pStyle )
{
- const SfxItemSet& aItemSet = pStyle->GetItemSet();
+ std::unique_ptr<const SfxItemSet> const pItemSet(pStyle->GetItemSetForPreview());
+ if (!pItemSet) return;
- const SvxFontItem *pFontItem = static_cast< const SvxFontItem* >( aItemSet.GetItem( SID_ATTR_CHAR_FONT ) );
- const SvxFontHeightItem *pFontHeightItem = static_cast< const SvxFontHeightItem* >( aItemSet.GetItem( SID_ATTR_CHAR_FONTHEIGHT ) );
+ const SvxFontItem * const pFontItem =
+ static_cast<const SvxFontItem*>(pItemSet->GetItem(SID_ATTR_CHAR_FONT));
+ const SvxFontHeightItem * const pFontHeightItem =
+ static_cast<const SvxFontHeightItem*>(pItemSet->GetItem(SID_ATTR_CHAR_FONTHEIGHT));
if ( pFontItem && pFontHeightItem )
{
@@ -655,43 +658,43 @@ void SvxStyleBox_Impl::SetupEntry(vcl::RenderContext& rRenderContext, vcl::Windo
aFont.SetStyleName(pFontItem->GetStyleName());
aFont.SetSize(aPixelSize);
- const SfxPoolItem *pItem = aItemSet.GetItem( SID_ATTR_CHAR_WEIGHT );
+ const SfxPoolItem *pItem = pItemSet->GetItem( SID_ATTR_CHAR_WEIGHT );
if ( pItem )
aFont.SetWeight( static_cast< const SvxWeightItem* >( pItem )->GetWeight() );
- pItem = aItemSet.GetItem( SID_ATTR_CHAR_POSTURE );
+ pItem = pItemSet->GetItem( SID_ATTR_CHAR_POSTURE );
if ( pItem )
aFont.SetItalic( static_cast< const SvxPostureItem* >( pItem )->GetPosture() );
- pItem = aItemSet.GetItem( SID_ATTR_CHAR_CONTOUR );
+ pItem = pItemSet->GetItem( SID_ATTR_CHAR_CONTOUR );
if ( pItem )
aFont.SetOutline( static_cast< const SvxContourItem* >( pItem )->GetValue() );
- pItem = aItemSet.GetItem( SID_ATTR_CHAR_SHADOWED );
+ pItem = pItemSet->GetItem( SID_ATTR_CHAR_SHADOWED );
if ( pItem )
aFont.SetShadow( static_cast< const SvxShadowedItem* >( pItem )->GetValue() );
- pItem = aItemSet.GetItem( SID_ATTR_CHAR_RELIEF );
+ pItem = pItemSet->GetItem( SID_ATTR_CHAR_RELIEF );
if ( pItem )
aFont.SetRelief( static_cast< FontRelief >( static_cast< const SvxCharReliefItem* >( pItem )->GetValue() ) );
- pItem = aItemSet.GetItem( SID_ATTR_CHAR_UNDERLINE );
+ pItem = pItemSet->GetItem( SID_ATTR_CHAR_UNDERLINE );
if ( pItem )
aFont.SetUnderline( static_cast< const SvxUnderlineItem* >( pItem )->GetLineStyle() );
- pItem = aItemSet.GetItem( SID_ATTR_CHAR_OVERLINE );
+ pItem = pItemSet->GetItem( SID_ATTR_CHAR_OVERLINE );
if ( pItem )
aFont.SetOverline( static_cast< FontUnderline >( static_cast< const SvxOverlineItem* >( pItem )->GetValue() ) );
- pItem = aItemSet.GetItem( SID_ATTR_CHAR_STRIKEOUT );
+ pItem = pItemSet->GetItem( SID_ATTR_CHAR_STRIKEOUT );
if ( pItem )
aFont.SetStrikeout( static_cast< const SvxCrossedOutItem* >( pItem )->GetStrikeout() );
- pItem = aItemSet.GetItem( SID_ATTR_CHAR_CASEMAP );
+ pItem = pItemSet->GetItem( SID_ATTR_CHAR_CASEMAP );
if ( pItem )
aFont.SetCaseMap(static_cast<const SvxCaseMapItem*>(pItem)->GetCaseMap());
- pItem = aItemSet.GetItem( SID_ATTR_CHAR_EMPHASISMARK );
+ pItem = pItemSet->GetItem( SID_ATTR_CHAR_EMPHASISMARK );
if ( pItem )
aFont.SetEmphasisMark( static_cast< const SvxEmphasisMarkItem* >( pItem )->GetEmphasisMark() );
@@ -702,14 +705,14 @@ void SvxStyleBox_Impl::SetupEntry(vcl::RenderContext& rRenderContext, vcl::Windo
rRenderContext.SetFont(aFont);
- pItem = aItemSet.GetItem( SID_ATTR_CHAR_COLOR );
+ pItem = pItemSet->GetItem( SID_ATTR_CHAR_COLOR );
// text color, when nothing is selected
if ( (NULL != pItem) && bIsNotSelected)
aFontCol = Color( static_cast< const SvxColorItem* >( pItem )->GetValue() );
sal_uInt16 style = drawing::FillStyle_NONE;
// which kind of Fill style is selected
- pItem = aItemSet.GetItem( XATTR_FILLSTYLE );
+ pItem = pItemSet->GetItem( XATTR_FILLSTYLE );
// only when ok and not selected
if ( (NULL != pItem) && bIsNotSelected)
style = static_cast< const XFillStyleItem* >( pItem )->GetValue();
@@ -719,7 +722,7 @@ void SvxStyleBox_Impl::SetupEntry(vcl::RenderContext& rRenderContext, vcl::Windo
case drawing::FillStyle_SOLID:
{
// set background color
- pItem = aItemSet.GetItem( XATTR_FILLCOLOR );
+ pItem = pItemSet->GetItem( XATTR_FILLCOLOR );
if ( NULL != pItem )
aBackCol = Color( static_cast< const XFillColorItem* >( pItem )->GetColorValue() );
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 );