21#include <com/sun/star/container/XNameContainer.hpp>
22#include <com/sun/star/lang/XMultiServiceFactory.hpp>
24#include <osl/diagnose.h>
35using ::com::sun::star::uno::Any;
36using ::com::sun::star::uno::Reference;
40struct lcl_EqualsElement
42 explicit lcl_EqualsElement( Any rValue,
const Reference< container::XNameAccess > & xAccess )
43 : m_aValue(
std::move( rValue )), m_xAccess( xAccess )
45 OSL_ASSERT( m_xAccess.is());
48 bool operator() (
const OUString & rName )
52 return (m_xAccess->getByName( rName ) == m_aValue);
54 catch(
const uno::Exception & )
63 Reference< container::XNameAccess > m_xAccess;
66struct lcl_StringMatches
68 explicit lcl_StringMatches( OUString aCmpStr ) :
69 m_aCmpStr(
std::move( aCmpStr ))
72 bool operator() ( std::u16string_view rStr )
81struct lcl_OUStringRestToInt32
83 explicit lcl_OUStringRestToInt32( sal_Int32 nPrefixLength ) :
84 m_nPrefixLength( nPrefixLength )
86 sal_Int32 operator() ( std::u16string_view rStr )
88 if( m_nPrefixLength >
static_cast<sal_Int32
>(rStr.size()) )
93 sal_Int32 m_nPrefixLength;
109OUString lcl_addNamedPropertyUniqueNameToTable(
111 const Reference< container::XNameContainer > & xNameContainer,
112 const OUString & rPrefix,
113 const OUString & rPreferredName )
115 if( ! xNameContainer.is() ||
116 ! rValue.hasValue() ||
117 ( rValue.getValueType() != xNameContainer->getElementType()))
118 return rPreferredName;
122 Reference< container::XNameAccess > xNameAccess( xNameContainer, uno::UNO_QUERY_THROW );
123 const uno::Sequence<OUString> aElementNames = xNameAccess->getElementNames();
124 auto it = std::find_if( aElementNames.begin(), aElementNames.end(), lcl_EqualsElement( rValue, xNameAccess ));
127 if( it != aElementNames.end())
131 OUString aUniqueName;
134 if( !rPreferredName.isEmpty())
136 auto aIt = std::find( aElementNames.begin(), aElementNames.end(), rPreferredName );
137 if( aIt == aElementNames.end())
138 aUniqueName = rPreferredName;
141 if( aUniqueName.isEmpty())
145 std::vector< sal_Int32 > aNumbers;
146 std::vector< OUString >::iterator aNonConstIt(
147 std::partition( aNames.begin(), aNames.end(), lcl_StringMatches( rPrefix )));
148 std::transform( aNames.begin(), aNonConstIt,
149 back_inserter( aNumbers ),
150 lcl_OUStringRestToInt32( rPrefix.getLength() ));
151 std::vector< sal_Int32 >::const_iterator aMaxIt(
152 std::max_element( aNumbers.begin(), aNumbers.end()));
155 if( aMaxIt != aNumbers.end())
158 aUniqueName = rPrefix + OUString::number( nIndex );
161 OSL_ASSERT( !aUniqueName.isEmpty());
162 xNameContainer->insertByName( aUniqueName, rValue );
165 catch(
const uno::Exception & )
170 return rPreferredName;
181 const OUString & rPreferredName )
186 xFact->createInstance(
"com.sun.star.drawing.DashTable"),
189 return lcl_addNamedPropertyUniqueNameToTable(
190 rValue, xNameCnt,
"ChartDash ", rPreferredName );
198 const OUString & rPreferredName )
203 xFact->createInstance(
"com.sun.star.drawing.GradientTable"),
206 return lcl_addNamedPropertyUniqueNameToTable(
207 rValue, xNameCnt,
"ChartGradient ", rPreferredName );
215 const OUString & rPreferredName )
220 xFact->createInstance(
"com.sun.star.drawing.TransparencyGradientTable"),
223 return lcl_addNamedPropertyUniqueNameToTable(
224 rValue, xNameCnt,
"ChartTransparencyGradient ", rPreferredName );
232 const OUString & rPreferredName )
237 xFact->createInstance(
"com.sun.star.drawing.HatchTable"),
240 return lcl_addNamedPropertyUniqueNameToTable(
241 rValue, xNameCnt,
"ChartHatch ", rPreferredName );
249 const OUString & rPreferredName )
254 xFact->createInstance(
"com.sun.star.drawing.BitmapTable"),
257 return lcl_addNamedPropertyUniqueNameToTable(
258 rValue, xNameCnt,
"ChartBitmap ", rPreferredName );
265 tPropertyValueMap::iterator aIt( rOutMap.find( key ));
266 if( aIt == rOutMap.end())
267 rOutMap.emplace( key, rAny );
269 (*aIt).second = rAny;
280 OSL_ENSURE( rOutMap.end() == rOutMap.find( key ),
"Default already exists for property" );
#define DBG_UNHANDLED_EXCEPTION(...)
OOO_DLLPUBLIC_CHARTTOOLS OUString addGradientUniqueNameToTable(const css::uno::Any &rValue, const css::uno::Reference< css::lang::XMultiServiceFactory > &xFact, const OUString &rPreferredName)
adds a gradient with a unique name to the gradient obtained by the given factory.
void setPropertyValue< css::uno::Any >(tPropertyValueMap &rOutMap, tPropertyValueMapKey key, const css::uno::Any &rAny)
OOO_DLLPUBLIC_CHARTTOOLS OUString addLineDashUniqueNameToTable(const css::uno::Any &rValue, const css::uno::Reference< css::lang::XMultiServiceFactory > &xFact, const OUString &rPreferredName)
adds a line dash with a unique name to the gradient obtained by the given factory.
OOO_DLLPUBLIC_CHARTTOOLS void setPropertyValueDefaultAny(tPropertyValueMap &rOutMap, tPropertyValueMapKey key, const css::uno::Any &rAny)
OOO_DLLPUBLIC_CHARTTOOLS void setPropertyValueAny(tPropertyValueMap &rOutMap, tPropertyValueMapKey key, const css::uno::Any &rAny)
Set a property to a certain value in the given map.
OOO_DLLPUBLIC_CHARTTOOLS OUString addBitmapUniqueNameToTable(const css::uno::Any &rValue, const css::uno::Reference< css::lang::XMultiServiceFactory > &xFact, const OUString &rPreferredName)
adds a bitmap with a unique name to the gradient obtained by the given factory.
OOO_DLLPUBLIC_CHARTTOOLS OUString addTransparencyGradientUniqueNameToTable(const css::uno::Any &rValue, const css::uno::Reference< css::lang::XMultiServiceFactory > &xFact, const OUString &rPreferredName)
adds a transparency gradient with a unique name to the gradient obtained by the given factory.
void setPropertyValueDefault< css::uno::Any >(tPropertyValueMap &rOutMap, tPropertyValueMapKey key, const css::uno::Any &rAny)
Calls setPropertyValue() but asserts that the given property hasn't been set before.
void setPropertyValueDefault(tPropertyValueMap &rOutMap, tPropertyValueMapKey key, const Value &value)
Calls setPropertyValue() but asserts that the given property hasn't been set before.
OOO_DLLPUBLIC_CHARTTOOLS void setEmptyPropertyValueDefault(tPropertyValueMap &rOutMap, tPropertyValueMapKey key)
Calls setPropertyValueDefault() with an empty Any as value.
void setPropertyValue(tPropertyValueMap &rOutMap, tPropertyValueMapKey key, const Value &value)
Set a property to a certain value in the given map.
OOO_DLLPUBLIC_CHARTTOOLS OUString addHatchUniqueNameToTable(const css::uno::Any &rValue, const css::uno::Reference< css::lang::XMultiServiceFactory > &xFact, const OUString &rPreferredName)
adds a hatch with a unique name to the gradient obtained by the given factory.
std::unordered_map< tPropertyValueMapKey, css::uno::Any > tPropertyValueMap
DstType sequenceToContainer(const css::uno::Sequence< SrcType > &i_Sequence)
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept