/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#define SFX_ITEMS_MAXREF 0xffffffff #define CONVERT_TWIPS 0x80 // Uno conversion for measurement (for MemberId)
// warning, if there is no boolean inside the any this will always return the value false inlinebool Any2Bool( const css::uno::Any&rValue )
{ bool bValue = false; if( !(rValue >>= bValue) )
{
sal_Int32 nNum = 0; if( rValue >>= nNum )
bValue = nNum != 0;
}
return bValue;
}
// Offer simple assert if Item is RefCounted (RefCnt > 1) and thus CANNOT be changed. // This should be used at *all* SfxPoolItem set* methods. Remember that SfxPoolItems // are by design intended to be create-one, read-only, shared data packages #define ASSERT_CHANGE_REFCOUNTED_ITEM \
assert(!GetRefCount() && "ERROR: RefCounted SfxPoolItem CANNOT be changed (!)")
/* * The values of this enum describe the degree of textual * representation of an item after calling the virtual * method <SfxPoolItem::GetPresentation()const>.
*/ enumclass SfxItemPresentation
{
Nameless,
Complete
};
/** * These values have to match the values in the * css::frame::status::ItemState IDL * to be found at offapi/com/sun/star/frame/status/ItemState.idl
*/ enumclass SfxItemState {
/** Specifies an unknown state. */
UNKNOWN = 0,
/** Specifies that the property is currently disabled. */
DISABLED = 0x0001,
/** Specifies that the property is currently in a don't care state * and thus invalid * <br/> * This is normally used if a selection provides more than one state * for a property at the same time, so the Item is over-defined and * has no valid state -> invalid
*/
INVALID = 0x0010,
/** Specifies that the property is currently in a default state. */ DEFAULT = 0x0020,
/** The property has been explicitly set to a given value hence we know * we are not taking the default value. * <br/> * For example, you may want to get the font color and it might either * be the default one or one that has been explicitly set.
*/
SET = 0x0040
};
#ifdef DBG_UTIL // for debugging add a serial number, will be set in the constructor // and count up from zero. If you have a deterministic error case and // see the Item involved in the debugger you can use that number in // the next run to see where that Item gets constructed and how it is // involved/ processed
sal_uInt32 m_nSerialNumber; #endif
// bitfield for Item attributes that are Item-Dependent
// Item is registered at some Pool as default. // m_bStaticDefault: direct Pool Item (CAUTION: // these are not really 'static', but should be) // m_bDynamicDefault: dynamic pool item, e.g. // SfxSetItems which are Pool dependent bool m_bStaticDefault : 1; bool m_bDynamicDefault : 1;
// Item is derived from SfxSetItem -> is Pool-dependent bool m_bIsSetItem : 1;
// Defines if the Item can be shared/RefCounted else it will be cloned. // Default is true - as it should be for all Items. It is needed by some // SW items, so protected to let them set it in constructor. If this could // be fixed at that Items we may remove this again. bool m_bShareable : 1;
// for speedup/buffering we need to identify NameOrIndex // Items quickly bool m_bNameOrIndex : 1;
protected: #ifdef DBG_UTIL // this flag will make debugging item stuff much simpler bool m_bDeleted : 1; #endif
// access ItemInstanceManager for this Item, default // is nullptr. If you overload this it is expected that // you return a ptr to a static, Item-local managed // instance that exists the whole office lifetime. This // usually means to have a static instance directly in the // implementation of the overloaded function (just grep // for examples) virtual ItemInstanceManager* getItemInstanceManager() const;
protected: // constructors are protected; SfxPoolItem is a base // class and ought bot to be constructed (also guaranteed // by pure virtual function ItemType now) explicit SfxPoolItem(sal_uInt16 nWhich);
SfxPoolItem(const SfxPoolItem& rCopy) : SfxPoolItem(rCopy.m_nWhich) {}
public: virtual ~SfxPoolItem();
void SetWhich( sal_uInt16 nId )
{ // can only change the Which before we are in a set
assert(m_nRefCount==0);
m_nWhich = nId;
}
sal_uInt16 Which() const { return m_nWhich; }
SAL_LOPLUGIN_ANNOTATE("mustoverride") virtual SfxItemType ItemType() const = 0;
// StaticWhichCast asserts if the TypedWhichId is not matching its type, otherwise it returns a reference. // You can use StaticWhichCast when you are sure about the type at compile time -- like a static_cast. template<class T> T& StaticWhichCast(TypedWhichId<T> nId)
{
(void)nId;
assert(nId == m_nWhich);
assert(dynamic_cast<T*>(this)); return *static_cast<T*>(this);
} template<class T> const T& StaticWhichCast(TypedWhichId<T> nId) const
{
(void)nId;
assert(nId == m_nWhich);
assert(dynamic_cast<const T*>(this)); return *static_cast<const T*>(this);
} // DynamicWhichCast returns nullptr if the TypedWhichId is not matching its type, otherwise it returns a typed pointer. // it asserts if the TypedWhichId matches its Which, but not the RTTI type. // You can use DynamicWhichCast when you are not sure about the type at compile time -- like a dynamic_cast. template<class T> T* DynamicWhichCast(TypedWhichId<T> nId)
{ if(m_nWhich != nId) return nullptr;
assert(dynamic_cast<T*>(this)); returnstatic_cast<T*>(this);
} template<class T> const T* DynamicWhichCast(TypedWhichId<T> nId) const
{ if(m_nWhich != nId) return nullptr;
assert(dynamic_cast<const T*>(this)); returnstatic_cast<const T*>(this);
} virtualbooloperator==( const SfxPoolItem& ) const = 0; booloperator!=( const SfxPoolItem& rItem ) const
{ return !(*this == rItem); } // Used by HashedItemInstanceManager virtualbool supportsHashCode() const; virtual size_t hashCode() const;
/** @return true if it has a valid string representation */ virtualbool GetPresentation( SfxItemPresentation ePresentation,
MapUnit eCoreMetric,
MapUnit ePresentationMetric,
OUString &rText, const IntlWrapper& rIntlWrapper ) const;
// offering a default implementation that can be use for // each SfxPoolItem (except when !isShareable()). It just // uses an unordered_set holding ptrs to SfxPoolItems added // and SfxPoolItem::operator== to linearly search for one. // Thus this is not the fastest, but as fast as old 'pooled' // stuff - better use an intelligent, pro-Item implementation // that does e.g. hashing or whatever might be feasible for // that specific Item (see other derivations) class SVL_DLLPUBLIC DefaultItemInstanceManager final : public ItemInstanceManager
{
std::unordered_map<sal_uInt16, std::unordered_set<const SfxPoolItem*>> maRegistered;
/** Utility template to reduce boilerplate code when creating item instance managers for specific PoolItem subclasses that can be hashed which is faster than using the linear search with operator== that DefaultItemInstanceManager has to do
*/ class HashedItemInstanceManager final : public ItemInstanceManager
{ struct ItemHash {
size_t operator()(const SfxPoolItem* p) const
{ return p->hashCode();
}
}; struct ItemEqual { booloperator()(const SfxPoolItem* lhs, const SfxPoolItem* rhs) const
{ return lhs->Which() == rhs->Which() && (*lhs) == (*rhs);
}
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.