diff options
author | Michael Stahl <mstahl@redhat.com> | 2015-09-07 16:36:24 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2015-09-07 16:49:58 +0200 |
commit | 93067f37cf22aa119db5878c4345fea500cbbb42 (patch) | |
tree | f8660673667e6addc9b08b2e76350cbac469ddee /svx | |
parent | 110dc43d97d559b6369bca308f9dd39fd02e751e (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 'svx')
-rw-r--r-- | svx/source/styles/CommonStylePreviewRenderer.cxx | 36 | ||||
-rw-r--r-- | svx/source/tbxctrls/tbcontrl.cxx | 35 |
2 files changed, 38 insertions, 33 deletions
diff --git a/svx/source/styles/CommonStylePreviewRenderer.cxx b/svx/source/styles/CommonStylePreviewRenderer.cxx index 2d9ac3f5dd10..19bce5f5ef63 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 4bb0294f3409..81fad3205235 100644 --- a/svx/source/tbxctrls/tbcontrl.cxx +++ b/svx/source/tbxctrls/tbcontrl.cxx @@ -638,10 +638,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 ) { @@ -654,43 +657,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() ); @@ -701,14 +704,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(); @@ -718,7 +721,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() ); |