22#include <com/sun/star/frame/UntitledNumbersConst.hpp>
23#include <com/sun/star/lang/IllegalArgumentException.hpp>
67 if ( ! xComponent.is ())
70 sal_IntPtr pComponent =
reinterpret_cast<sal_IntPtr
>( xComponent.get() );
71 TNumberedItemHash::const_iterator pIt =
m_lComponents.find (pComponent);
75 return pIt->second.nNumber;
82 if (nFreeNumber == css::frame::UntitledNumbersConst::INVALID_NUMBER)
83 return css::frame::UntitledNumbersConst::INVALID_NUMBER;
87 aItem.
xItem = css::uno::WeakReference< css::uno::XInterface >(xComponent);
102 if (nNumber == css::frame::UntitledNumbersConst::INVALID_NUMBER)
103 throw css::lang::IllegalArgumentException (
"Special value INVALID_NUMBER not allowed as input parameter.",
m_xOwner.get(), 1);
106 TNumberedItemHash::iterator pComponent;
113 const css::uno::Reference< css::uno::XInterface > xItem = rItem.
xItem.get();
117 lDeadItems.push_back(pComponent->first);
139 if ( ! xComponent.is ())
142 sal_IntPtr pComponent =
reinterpret_cast<sal_IntPtr
>( xComponent.get() );
143 TNumberedItemHash::iterator pIt =
m_lComponents.find (pComponent);
182 std::vector<bool> aUsedNumbers((
m_lComponents.size() * 2) + 1,
false);
187 sal_Int32
pos = rPair.second.nNumber - 1;
188 if (
pos >=
static_cast<sal_Int32
>(aUsedNumbers.size()))
189 aUsedNumbers.resize(
pos * 2,
false);
190 aUsedNumbers[
pos] =
true;
194 auto it =
std::find(aUsedNumbers.begin(), aUsedNumbers.end(),
false);
195 if (it == aUsedNumbers.end())
196 return css::frame::UntitledNumbersConst::INVALID_NUMBER;
199 return it - aUsedNumbers.begin() + 1;
205 for (
const sal_IntPtr& rDeadItem : lDeadItems)
207 lItems.erase(rDeadItem);
OUString m_sUntitledPrefix
localized string to be used for untitled components
void setOwner(const css::uno::Reference< css::uno::XInterface > &xOwner)
set an outside component which uses this container and must be set as source of all broadcasted messa...
TNumberedItemHash m_lComponents
cache of all "leased numbers" and its bound components
::sal_Int32 impl_searchFreeNumber()
tries to find a unique number not already used within this collection.
NumberedCollection()
lightweight constructor.
virtual ~NumberedCollection() override
free all internally used resources.
css::uno::WeakReference< css::uno::XInterface > m_xOwner
used as source of broadcasted messages or exceptions (can be null !)
std::unordered_map< sal_IntPtr, TNumberedItem > TNumberedItemHash
virtual void SAL_CALL releaseNumber(::sal_Int32 nNumber) override
::std::vector< sal_IntPtr > TDeadItemList
static void impl_cleanUpDeadItems(TNumberedItemHash &lItems, const TDeadItemList &lDeadItems)
virtual OUString SAL_CALL getUntitledPrefix() override
virtual void SAL_CALL releaseNumberForComponent(const css::uno::Reference< css::uno::XInterface > &xComponent) override
void setUntitledPrefix(const OUString &sPrefix)
set the localized prefix to be used for untitled components.
virtual ::sal_Int32 SAL_CALL leaseNumber(const css::uno::Reference< css::uno::XInterface > &xComponent) override
constexpr OUStringLiteral ERRMSG_INVALID_COMPONENT_PARAM
static PropertyMapEntry const * find(const rtl::Reference< PropertySetInfo > &mxInfo, const OUString &aName) noexcept
css::uno::WeakReference< css::uno::XInterface > xItem