24#include <com/sun/star/lang/XServiceInfo.hpp>
25#include <com/sun/star/container/XNameContainer.hpp>
26#include <com/sun/star/drawing/PointSequence.hpp>
27#include <com/sun/star/util/XCancellable.hpp>
49using namespace ::
cppu;
55class SvxUnoMarkerTable
56 :
public WeakImplHelper<
58 container::XNameContainer,
69 explicit SvxUnoMarkerTable(
SdrModel* pModel )
noexcept;
70 virtual ~SvxUnoMarkerTable()
noexcept override;
77 void ImplInsertByName(
const OUString&
aName,
const uno::Any& aElement );
85 virtual void SAL_CALL cancel()
override;
88 virtual void SAL_CALL insertByName(
const OUString&
aName,
const uno::Any& aElement )
override;
89 virtual void SAL_CALL removeByName(
const OUString&
Name )
override;
92 virtual void SAL_CALL replaceByName(
const OUString&
aName,
const uno::Any& aElement )
override;
95 virtual uno::Any SAL_CALL getByName(
const OUString&
aName )
override;
96 virtual uno::Sequence< OUString > SAL_CALL getElementNames( )
override;
97 virtual sal_Bool SAL_CALL hasByName(
const OUString&
aName )
override;
100 virtual uno::Type SAL_CALL getElementType( )
override;
101 virtual sal_Bool SAL_CALL hasElements( )
override;
106SvxUnoMarkerTable::SvxUnoMarkerTable(
SdrModel* pModel ) noexcept
108 mpModelPool( pModel ? &pModel->GetItemPool() :
nullptr )
114SvxUnoMarkerTable::~SvxUnoMarkerTable() noexcept
119 EndListening( *mpModel );
123void SvxUnoMarkerTable::dispose()
125 maItemSetVector.clear();
131 if (rHint.GetId() == SfxHintId::ThisIsAnSdrHint)
139sal_Bool SAL_CALL SvxUnoMarkerTable::supportsService(
const OUString& ServiceName )
144OUString SAL_CALL SvxUnoMarkerTable::getImplementationName()
146 return "SvxUnoMarkerTable";
149uno::Sequence< OUString > SAL_CALL SvxUnoMarkerTable::getSupportedServiceNames( )
151 uno::Sequence<OUString> aSNS {
"com.sun.star.drawing.MarkerTable" };
155void SvxUnoMarkerTable::ImplInsertByName(
const OUString& aName,
const uno::Any& aElement )
157 maItemSetVector.push_back(
159 auto pInSet = maItemSetVector.back().get();
162 aEndMarker.SetName( aName );
163 aEndMarker.PutValue( aElement, 0 );
165 pInSet->Put( aEndMarker );
168 aStartMarker.SetName( aName );
169 aStartMarker.PutValue( aElement, 0 );
171 pInSet->Put( aStartMarker );
175void SAL_CALL SvxUnoMarkerTable::insertByName(
const OUString& aApiName,
const uno::Any& aElement )
179 if( hasByName( aApiName ) )
180 throw container::ElementExistException();
184 ImplInsertByName( aName, aElement );
187void SAL_CALL SvxUnoMarkerTable::cancel()
195void SAL_CALL SvxUnoMarkerTable::removeByName(
const OUString& aApiName )
201 auto aIter = std::find_if(maItemSetVector.begin(), maItemSetVector.end(),
202 [&aName](
const std::unique_ptr<SfxItemSet>& rpItem) {
203 const NameOrIndex *pItem = &(rpItem->Get( XATTR_LINEEND ) );
204 return pItem->GetName() == aName;
206 if (aIter != maItemSetVector.end())
208 maItemSetVector.erase( aIter );
212 if( !hasByName( aName ) )
213 throw container::NoSuchElementException();
217void SAL_CALL SvxUnoMarkerTable::replaceByName(
const OUString& aApiName,
const uno::Any& aElement )
223 auto aIter = std::find_if(maItemSetVector.begin(), maItemSetVector.end(),
224 [&aName](
const std::unique_ptr<SfxItemSet>& rpItem) {
225 const NameOrIndex *pItem = &(rpItem->Get( XATTR_LINEEND ) );
226 return pItem->GetName() == aName;
228 if (aIter != maItemSetVector.end())
231 aEndMarker.SetName( aName );
232 if( !aEndMarker.PutValue( aElement, 0 ) )
233 throw lang::IllegalArgumentException();
235 (*aIter)->Put( aEndMarker );
238 aStartMarker.SetName( aName );
239 aStartMarker.PutValue( aElement, 0 );
241 (*aIter)->Put( aStartMarker );
273 throw container::NoSuchElementException();
275 ImplInsertByName( aName, aElement );
285 if( pItem && pItem->
GetName() == rSearchName )
296uno::Any SAL_CALL SvxUnoMarkerTable::getByName(
const OUString& aApiName )
304 if (mpModelPool && !
aName.isEmpty())
314 throw container::NoSuchElementException();
328 if( pItem ==
nullptr || pItem->
GetName().isEmpty() )
332 rNameSet.insert(
aName );
336uno::Sequence< OUString > SAL_CALL SvxUnoMarkerTable::getElementNames()
340 std::set< OUString > aNameSet;
351sal_Bool SAL_CALL SvxUnoMarkerTable::hasByName(
const OUString& aName )
355 if(
aName.isEmpty() )
358 OUString aSearchName;
367 if( pItem && pItem->
GetName() == aSearchName )
376 if( pItem && pItem->
GetName() == aSearchName )
384uno::Type SAL_CALL SvxUnoMarkerTable::getElementType( )
389sal_Bool SAL_CALL SvxUnoMarkerTable::hasElements( )
399 if( pItem && !pItem->
GetName().isEmpty() )
407 if( pItem && !pItem->
GetName().isEmpty() )
419 return *
new SvxUnoMarkerTable(pModel);
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
OUString const & GetName() const
SdrHintKind GetKind() const
Item2Range GetItemSurrogates(sal_uInt16 nWhich) const
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint)
css::uno::Type const & get()
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
std::vector< std::unique_ptr< SfxItemSet > > ItemPoolVector
static void createNamesForPool(SfxItemPool const *pPool, sal_uInt16 nWhich, std::set< OUString > &rNameSet)
uno::Reference< uno::XInterface > SvxUnoMarkerTable_createInstance(SdrModel *pModel)
Create a hatchtable.
static bool getByNameFromPool(std::u16string_view rSearchName, SfxItemPool const *pPool, sal_uInt16 nWhich, uno::Any &rAny)
OUString SvxUnogetApiNameForItem(const sal_uInt16 nWhich, const OUString &rInternalName)
if the given name is a predefined name for the current language it is replaced by the corresponding a...
OUString SvxUnogetInternalNameForItem(const sal_uInt16 nWhich, const OUString &rApiName)
if the given name is a predefined api name it is replaced by the predefined name for the current lang...
constexpr TypedWhichId< XLineEndItem > XATTR_LINEEND(XATTR_LINE_FIRST+5)
constexpr TypedWhichId< XLineStartItem > XATTR_LINESTART(XATTR_LINE_FIRST+4)