introduce XColorSetsManager interface

[ Miklos: rather go with a beans::PropertyValues-based interface to
allow extending this incrementally, without an API change. This allows
getting / setting a per-document theme via the UNO API, but the concept
from the original commit is unchanged. ]

(cherry picked from commit 3f1bca8b4f451fa30bf341116390738c456d651f,
from the feature/themesupport2 branch)

Change-Id: I24be34a5a7b68549b21a6cd55144901d4fe2c5f8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125436
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
This commit is contained in:
Sarper Akdemir 2021-09-07 10:14:52 +03:00 committed by Miklos Vajna
parent 75a49947c2
commit cd5c8e5a99
4 changed files with 62 additions and 0 deletions

View file

@ -85,6 +85,10 @@ public:
const OUString& GetName() const;
void dumpAsXml(xmlTextWriterPtr pWriter) const;
void ToAny(css::uno::Any& rVal) const;
static std::unique_ptr<Theme> FromAny(const css::uno::Any& rVal);
};
} // end of namespace svx

View file

@ -59,6 +59,7 @@ inline constexpr OUStringLiteral sUNO_Prop_BookmarkURL = u"BookmarkURL";
inline constexpr OUStringLiteral sUNO_Prop_RuntimeUID = u"RuntimeUID";
inline constexpr OUStringLiteral sUNO_Prop_HasValidSignatures = u"HasValidSignatures";
inline constexpr OUStringLiteral sUNO_Prop_InteropGrabBag = u"InteropGrabBag";
inline constexpr OUStringLiteral sUNO_Prop_Theme = u"Theme";
// view settings
inline constexpr OUStringLiteral sUNO_View_ViewId = u"ViewId";

View file

@ -125,6 +125,7 @@
#include <tools/diagnose_ex.h>
#include <tools/json_writer.hxx>
#include <tools/UnitConversion.hxx>
#include <svx/ColorSets.hxx>
using namespace ::cppu;
using namespace ::com::sun::star;
@ -197,6 +198,7 @@ const sal_uInt16 WID_MODEL_HASVALIDSIGNATURES = 11;
const sal_uInt16 WID_MODEL_DIALOGLIBS = 12;
const sal_uInt16 WID_MODEL_FONTS = 13;
const sal_uInt16 WID_MODEL_INTEROPGRABBAG = 14;
const sal_uInt16 WID_MODEL_THEME = 15;
static const SvxItemPropertySet* ImplGetDrawModelPropertySet()
{
@ -217,6 +219,7 @@ static const SvxItemPropertySet* ImplGetDrawModelPropertySet()
{ sUNO_Prop_HasValidSignatures, WID_MODEL_HASVALIDSIGNATURES, ::cppu::UnoType<sal_Bool>::get(), beans::PropertyAttribute::READONLY, 0},
{ u"Fonts", WID_MODEL_FONTS, cppu::UnoType<uno::Sequence<uno::Any>>::get(), beans::PropertyAttribute::READONLY, 0},
{ sUNO_Prop_InteropGrabBag, WID_MODEL_INTEROPGRABBAG, cppu::UnoType<uno::Sequence< beans::PropertyValue >>::get(), 0, 0},
{ sUNO_Prop_Theme, WID_MODEL_THEME, cppu::UnoType<uno::Sequence< beans::PropertyValue >>::get(), 0, 0},
{ u"", 0, css::uno::Type(), 0, 0 }
};
static SvxItemPropertySet aDrawModelPropertySet_Impl( aDrawModelPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() );
@ -1248,6 +1251,13 @@ void SAL_CALL SdXImpressDocument::setPropertyValue( const OUString& aPropertyNam
case WID_MODEL_INTEROPGRABBAG:
setGrabBagItem(aValue);
break;
case WID_MODEL_THEME:
{
SdrModel& rModel = getSdrModelFromUnoModel();
std::unique_ptr<svx::Theme> pTheme = svx::Theme::FromAny(aValue);
rModel.SetTheme(std::move(pTheme));
}
break;
default:
throw beans::UnknownPropertyException( aPropertyName, static_cast<cppu::OWeakObject*>(this));
}
@ -1368,6 +1378,21 @@ uno::Any SAL_CALL SdXImpressDocument::getPropertyValue( const OUString& Property
case WID_MODEL_INTEROPGRABBAG:
getGrabBagItem(aAny);
break;
case WID_MODEL_THEME:
{
SdrModel& rModel = getSdrModelFromUnoModel();
svx::Theme* pTheme = rModel.GetTheme();
if (pTheme)
{
pTheme->ToAny(aAny);
}
else
{
beans::PropertyValues aValues;
aAny <<= aValues;
}
break;
}
default:
throw beans::UnknownPropertyException( PropertyName, static_cast<cppu::OWeakObject*>(this));
}

View file

@ -14,6 +14,13 @@
#include <libxml/xmlwriter.h>
#include <com/sun/star/beans/PropertyValues.hpp>
#include <comphelper/propertyvalue.hxx>
#include <comphelper/sequenceashashmap.hxx>
using namespace com::sun::star;
namespace svx
{
@ -155,6 +162,31 @@ void Theme::dumpAsXml(xmlTextWriterPtr pWriter) const
(void)xmlTextWriterEndElement(pWriter);
}
void Theme::ToAny(css::uno::Any& rVal) const
{
beans::PropertyValues aValues = {
comphelper::makePropertyValue("Name", maName)
};
rVal <<= aValues;
}
std::unique_ptr<Theme> Theme::FromAny(const css::uno::Any& rVal)
{
comphelper::SequenceAsHashMap aMap(rVal);
std::unique_ptr<Theme> pTheme;
auto it = aMap.find("Name");
if (it != aMap.end())
{
OUString aName;
it->second >>= aName;
pTheme = std::make_unique<Theme>(aName);
}
return pTheme;
}
} // end of namespace svx
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */