summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/svl/style.hxx3
-rw-r--r--svl/source/items/style.cxx4
-rw-r--r--svx/source/styles/CommonStylePreviewRenderer.cxx2
-rw-r--r--svx/source/tbxctrls/StylesPreviewWindow.cxx13
-rw-r--r--svx/source/tbxctrls/tbcontrl.cxx2
-rw-r--r--sw/inc/docstyle.hxx5
-rw-r--r--sw/source/uibase/app/docstyle.cxx26
7 files changed, 30 insertions, 25 deletions
diff --git a/include/svl/style.hxx b/include/svl/style.hxx
index 735e3607242d..b3db632c4841 100644
--- a/include/svl/style.hxx
+++ b/include/svl/style.hxx
@@ -37,6 +37,7 @@
#include <tools/solar.h>
#include <memory>
+#include <optional>
// This is used as a flags enum in sw/, but only there,
// so I don't pull in o3tl::typed_flags here
@@ -178,7 +179,7 @@ public:
/// 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();
+ virtual std::optional<SfxItemSet> GetItemSetForPreview();
/// Fix for expensive dynamic_cast
virtual bool isScStyleSheet() const { return false; }
diff --git a/svl/source/items/style.cxx b/svl/source/items/style.cxx
index 8036c3ce4907..2e54c9f53439 100644
--- a/svl/source/items/style.cxx
+++ b/svl/source/items/style.cxx
@@ -262,9 +262,9 @@ SfxItemSet& SfxStyleSheetBase::GetItemSet()
return *pSet;
}
-std::unique_ptr<SfxItemSet> SfxStyleSheetBase::GetItemSetForPreview()
+std::optional<SfxItemSet> SfxStyleSheetBase::GetItemSetForPreview()
{
- return std::make_unique<SfxItemSet>(GetItemSet());
+ return GetItemSet();
}
/**
diff --git a/svx/source/styles/CommonStylePreviewRenderer.cxx b/svx/source/styles/CommonStylePreviewRenderer.cxx
index 65690bed792b..fbd03539fda5 100644
--- a/svx/source/styles/CommonStylePreviewRenderer.cxx
+++ b/svx/source/styles/CommonStylePreviewRenderer.cxx
@@ -62,7 +62,7 @@ bool CommonStylePreviewRenderer::recalculate()
{
m_pFont.reset();
- std::unique_ptr<SfxItemSet> pItemSet(mpStyle->GetItemSetForPreview());
+ std::optional<SfxItemSet> pItemSet(mpStyle->GetItemSetForPreview());
if (!pItemSet) return false;
diff --git a/svx/source/tbxctrls/StylesPreviewWindow.cxx b/svx/source/tbxctrls/StylesPreviewWindow.cxx
index 228fc3f05102..eef8bba791e5 100644
--- a/svx/source/tbxctrls/StylesPreviewWindow.cxx
+++ b/svx/source/tbxctrls/StylesPreviewWindow.cxx
@@ -143,7 +143,7 @@ bool StylesPreviewWindow_Base::Command(const CommandEvent& rEvent)
return false;
}
-static Color GetTextColorFromItemSet(std::unique_ptr<const SfxItemSet> const& pItemSet)
+static Color GetTextColorFromItemSet(std::optional<SfxItemSet> const& pItemSet)
{
const SfxPoolItem* pItem = pItemSet->GetItem(SID_ATTR_CHAR_COLOR);
if (pItem)
@@ -152,7 +152,7 @@ static Color GetTextColorFromItemSet(std::unique_ptr<const SfxItemSet> const& pI
return COL_AUTO;
}
-static Color GetHighlightColorFromItemSet(std::unique_ptr<const SfxItemSet> const& pItemSet)
+static Color GetHighlightColorFromItemSet(std::optional<SfxItemSet> const& pItemSet)
{
const SfxPoolItem* pItem = pItemSet->GetItem(SID_ATTR_BRUSH_CHAR);
if (pItem)
@@ -161,7 +161,7 @@ static Color GetHighlightColorFromItemSet(std::unique_ptr<const SfxItemSet> cons
return COL_AUTO;
}
-static Color GetBackgroundColorFromItemSet(std::unique_ptr<const SfxItemSet> const& pItemSet)
+static Color GetBackgroundColorFromItemSet(std::optional<SfxItemSet> const& pItemSet)
{
const SfxPoolItem* pItem = pItemSet->GetItem(XATTR_FILLCOLOR);
if (pItem)
@@ -170,8 +170,7 @@ static Color GetBackgroundColorFromItemSet(std::unique_ptr<const SfxItemSet> con
return COL_AUTO;
}
-static css::drawing::FillStyle
-GetFillStyleFromItemSet(std::unique_ptr<const SfxItemSet> const& pItemSet)
+static css::drawing::FillStyle GetFillStyleFromItemSet(std::optional<SfxItemSet> const& pItemSet)
{
const SfxPoolItem* pItem = pItemSet->GetItem(XATTR_FILLSTYLE);
if (pItem)
@@ -181,7 +180,7 @@ GetFillStyleFromItemSet(std::unique_ptr<const SfxItemSet> const& pItemSet)
}
static SvxFont GetFontFromItems(const SvxFontItem* pFontItem, Size aPixelFontSize,
- std::unique_ptr<const SfxItemSet> const& pItemSet)
+ std::optional<SfxItemSet> const& pItemSet)
{
SvxFont aFont;
@@ -261,7 +260,7 @@ void StyleItemController::DrawEntry(vcl::RenderContext& rRenderContext)
DrawContentBackground(rRenderContext, aContentRect, aOriginalColor);
- std::unique_ptr<const SfxItemSet> const pItemSet(pStyle->GetItemSetForPreview());
+ std::optional<SfxItemSet> const pItemSet(pStyle->GetItemSetForPreview());
if (!pItemSet)
return;
diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx
index 4521be0db733..1add34406833 100644
--- a/svx/source/tbxctrls/tbcontrl.cxx
+++ b/svx/source/tbxctrls/tbcontrl.cxx
@@ -1168,7 +1168,7 @@ void SvxStyleBox_Base::SetupEntry(vcl::RenderContext& rRenderContext, sal_Int32
if (!pStyle )
return;
- std::unique_ptr<const SfxItemSet> const pItemSet(pStyle->GetItemSetForPreview());
+ std::optional<SfxItemSet> const pItemSet(pStyle->GetItemSetForPreview());
if (!pItemSet) return;
const SvxFontItem * const pFontItem =
diff --git a/sw/inc/docstyle.hxx b/sw/inc/docstyle.hxx
index 049070da9c65..025bcc436413 100644
--- a/sw/inc/docstyle.hxx
+++ b/sw/inc/docstyle.hxx
@@ -28,6 +28,7 @@
#include <unordered_map>
#include <memory>
+#include <optional>
#include <string_view>
#include <vector>
@@ -72,7 +73,7 @@ class SW_DLLPUBLIC SwDocStyleSheet final : public SfxStyleSheetBase
};
SAL_DLLPRIVATE bool FillStyleSheet(FillStyleType eFType,
- std::unique_ptr<SfxItemSet> * o_ppFlatSet = nullptr);
+ std::optional<SfxItemSet> * o_ppFlatSet = nullptr);
virtual ~SwDocStyleSheet() override;
@@ -102,7 +103,7 @@ public:
const bool bResetIndentAttrsAtParagraphStyle = false );
virtual SfxItemSet& GetItemSet() override;
- virtual std::unique_ptr<SfxItemSet> GetItemSetForPreview() override;
+ virtual std::optional<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 b10570b348a2..9d441beedae7 100644
--- a/sw/source/uibase/app/docstyle.cxx
+++ b/sw/source/uibase/app/docstyle.cxx
@@ -1216,7 +1216,7 @@ bool SwDocStyleSheet::SetFollow( const OUString& rStr)
}
static
-std::unique_ptr<SfxItemSet> lcl_SwFormatToFlatItemSet(SwFormat const *const pFormat)
+void lcl_SwFormatToFlatItemSet(SwFormat const *const pFormat, std::optional<SfxItemSet>& pRet)
{
// note: we don't add the odd items that GetItemSet() would add
// because they don't seem relevant for preview
@@ -1227,21 +1227,20 @@ std::unique_ptr<SfxItemSet> lcl_SwFormatToFlatItemSet(SwFormat const *const pFor
sets.push_back(pParent);
}
// start by copying top-level parent set
- std::unique_ptr<SfxItemSet> pRet(new SfxItemSet(*sets.back()));
+ pRet.emplace(*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()
+std::optional<SfxItemSet> SwDocStyleSheet::GetItemSetForPreview()
{
if (SfxStyleFamily::Page == nFamily || SfxStyleFamily::Pseudo == nFamily || SfxStyleFamily::Table == nFamily)
{
SAL_WARN("sw.ui", "GetItemSetForPreview not implemented for page or number or table style");
- return std::unique_ptr<SfxItemSet>();
+ return std::optional<SfxItemSet>();
}
if (!m_bPhysical)
{
@@ -1249,7 +1248,7 @@ std::unique_ptr<SfxItemSet> SwDocStyleSheet::GetItemSetForPreview()
// (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;
+ std::optional<SfxItemSet> pRet;
bool bModifiedEnabled = m_rDoc.getIDocumentState().IsEnableSetModified();
m_rDoc.getIDocumentState().SetEnableSetModified(false);
@@ -1263,17 +1262,22 @@ std::unique_ptr<SfxItemSet> SwDocStyleSheet::GetItemSetForPreview()
}
else
{
+ std::optional<SfxItemSet> pRet;
switch (nFamily)
{
case SfxStyleFamily::Char:
- return lcl_SwFormatToFlatItemSet(m_pCharFormat);
+ lcl_SwFormatToFlatItemSet(m_pCharFormat, pRet);
+ break;
case SfxStyleFamily::Para:
- return lcl_SwFormatToFlatItemSet(m_pColl);
+ lcl_SwFormatToFlatItemSet(m_pColl, pRet);
+ break;
case SfxStyleFamily::Frame:
- return lcl_SwFormatToFlatItemSet(m_pFrameFormat);
+ lcl_SwFormatToFlatItemSet(m_pFrameFormat, pRet);
+ break;
default:
std::abort();
}
+ return pRet;
}
}
@@ -1818,7 +1822,7 @@ static void lcl_DeleteInfoStyles( SfxStyleFamily nFamily, std::vector<void*> con
// determine the format
bool SwDocStyleSheet::FillStyleSheet(
- FillStyleType const eFType, std::unique_ptr<SfxItemSet> *const o_ppFlatSet)
+ FillStyleType const eFType, std::optional<SfxItemSet> *const o_ppFlatSet)
{
bool bRet = false;
sal_uInt16 nPoolId = USHRT_MAX;
@@ -2016,7 +2020,7 @@ bool SwDocStyleSheet::FillStyleSheet(
if (FillPreview == eFType)
{
assert(o_ppFlatSet);
- *o_ppFlatSet = lcl_SwFormatToFlatItemSet(pFormat);
+ lcl_SwFormatToFlatItemSet(pFormat, *o_ppFlatSet);
}
}