Files
libreoffice/xmloff/inc/MultiPropertySetHelper.hxx

188 lines
6.2 KiB
C++
Raw Normal View History

2010-10-27 13:11:31 +01:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: Patches contributed by: Armin Le Grand. #118558# Correcting OLE attributes of LO3.4 at load time by loading as OOo3.3, details see task. http://svn.apache.org/viewvc?view=revision&revision=1195906 #118485# - Styles for OLEs are not saved. http://svn.apache.org/viewvc?view=revision&revision=1182166 #118898# Adapted ImpGraphic::ImplGetBitmap to correctly convert metafiles http://svn.apache.org/viewvc?view=revision&revision=1293316 #119337# Solves the wrong get/setPropertyValue calls in SvxShapeText (and thus in SvxOle2Shape) http://svn.apache.org/viewvc?view=revision&revision=1344156 Patches contributed by Mathias Bauer (and others) gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 cws mba34issues01: #i117717#: remove wrong assertion http://svn.apache.org/viewvc?view=revision&revision=1172349 Patch contributed by Herbert Duerr goodbye Registration and License dialogs, don't let the door hit you http://svn.apache.org/viewvc?view=revision&revision=1172613 help gcc 4.6.0 on 32bit ubuntu 11.10" http://svn.apache.org/viewvc?view=revision&revision=1245357 Do not add targets for junit tests when junit is disabled. Patch contributed by Andre Fischer http://svn.apache.org/viewvc?view=revision&revision=1241508 Revert "sb140: #i117082# avoid unncessary static class data members commit 21d97438e2944861e26e4984195f959a0cce1e41. remove obsolete FreeBSD visibility special case. retain consolidated BSD bridge code, remove OS/2 pieces.
2012-11-12 17:21:24 +00:00
/*
* 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 .
*/
#ifndef INCLUDED_XMLOFF_INC_MULTIPROPERTYSETHELPER_HXX
#define INCLUDED_XMLOFF_INC_MULTIPROPERTYSETHELPER_HXX
2001-05-14 12:04:53 +00:00
#include <rtl/ustring.hxx>
#include <com/sun/star/uno/Sequence.hxx>
#include <tools/debug.hxx>
namespace com { namespace sun { namespace star {
namespace beans { class XMultiPropertySet; }
namespace beans { class XPropertySet; }
namespace beans { class XPropertySetInfo; }
} } }
/**
* The MultiPropertySetHelper performs the following functions:
2001-05-14 12:04:53 +00:00
*
* Given a list of property names (as sal_Char** or OUString*), it can
* query an XMultiPropertySet (or XPropertySet) which of these properties
* it supports (method hasProperties(...)). The properties *MUST* be
* sorted alphabetically.
2001-05-14 12:04:53 +00:00
*
* Then, the X(Multi)PropertySet can be queried for values, and only
* the supported properties are queried. (method getValues(...)) The
* values are stored in the helper itself.
*
* Finally, each property can be queried for existence
* (method hasProperty(...)) or its value (method (getValue(...))).
*
* After some initial preparation (hasProperties, getValues) the
2001-05-14 12:04:53 +00:00
* MultiPropertySetHelper can be used similarly to an
* XPropertySet in that you can query the values in the places where you
* need them. However, if an XMultiPropertySet is supplied, the queries
* are more efficient, often significantly so.
*/
class MultiPropertySetHelper
{
/// names of all properties
OUString* pPropertyNames;
2001-05-14 12:04:53 +00:00
/// length of pPropertyNames array
sal_Int16 nLength;
/// the sequence of property names that the current (multi)
/// property set implementation supports
css::uno::Sequence< OUString > aPropertySequence;
2001-05-14 12:04:53 +00:00
/// an array of indices that maps from pPropertyNames indices to
/// aPropertySequence indices
sal_Int16* pSequenceIndex;
/// the last set of values retrieved by getValues
css::uno::Sequence< css::uno::Any > aValues;
2001-05-14 12:04:53 +00:00
/// result of aValues.getConstArray()
const css::uno::Any* pValues;
2001-05-14 12:04:53 +00:00
/// an empty Any
css::uno::Any aEmptyAny;
2001-05-14 12:04:53 +00:00
public:
MultiPropertySetHelper( const sal_Char** pNames );
~MultiPropertySetHelper();
/**
* Call hasPropertiesByName for the provided XPropertySetInfo and build
* list of allowed properties.
*/
void hasProperties( const css::uno::Reference<css::beans::XPropertySetInfo> & );
2001-05-14 12:04:53 +00:00
/**
* Return whether hasProperties was called
* (i.e. if we are ready to call getValues)
2001-05-14 12:04:53 +00:00
*/
bool checkedProperties();
2001-05-14 12:04:53 +00:00
/**
* Get values from the XMultiPropertySet.
*
* May only be called after hasProperties() was called for the
* appropriate XPropertySetInfo.
*/
void getValues( const css::uno::Reference<css::beans::XMultiPropertySet> & );
2001-05-14 12:04:53 +00:00
/**
* Get values from the XPropertySet. This can be much slower than
* getValues( const Reference<XMultiPropertySet& ) and hence
* should be avoided.
*
* May only be called after hasProperties() was called for the
* appropriate XPropertySetInfo.
*/
void getValues( const css::uno::Reference<css::beans::XPropertySet> & );
2001-05-14 12:04:53 +00:00
/**
* Get a value from the values array.
*
* May only be called after getValues() was called.
*/
inline const css::uno::Any& getValue( sal_Int16 nIndex );
2001-05-14 12:04:53 +00:00
/**
* Find out if this property is supported.
*
* May only be called after hasProperties() was called.
*/
inline bool hasProperty( sal_Int16 nIndex );
2001-05-14 12:04:53 +00:00
/**
* Get a value from the XPropertySet on demand.
*
* If neither getValues nor getValueOnDemand has been called already
* after the last call to resetValues, the values are retrieved
* using getValues. Otherwise the value already retrieved is returned.
* In case XMultiPropertySet is supported by the XPropertySet and
* bTryMult is set, the XMultiPropertySet is used to get the values.
*
*/
const css::uno::Any& getValue( sal_Int16 nIndex,
const css::uno::Reference<css::beans::XPropertySet> &,
bool bTryMulti = false );
/**
* Get a value from the XMultiPropertySet on demand.
*
* If neither getValues nor getValueOnDemand has been called already
* after the last call to resetValues, the values are retrieved
* using getValues. Otherwise the value already retrieved is returned.
* In case XMultiPropertySet is supported by the XPropertySet,
* XMultiPropertySet is used to get the values.
*
*/
const css::uno::Any& getValue( sal_Int16 nIndex,
const css::uno::Reference<css::beans::XMultiPropertySet> & );
inline void resetValues() { pValues = nullptr; }
2001-05-14 12:04:53 +00:00
};
// inline implementations of the often-called methods getValue and hasProperty:
const css::uno::Any& MultiPropertySetHelper::getValue(
2001-05-14 12:04:53 +00:00
sal_Int16 nValueNo )
{
assert(pValues && "called getValue() without calling getValues()");
assert(pSequenceIndex && "called getValue() without calling hasProperties()");
assert(nValueNo < nLength);
2001-05-14 12:04:53 +00:00
sal_Int16 nIndex = pSequenceIndex[ nValueNo ];
return ( nIndex != -1 ) ? pValues[ nIndex ] : aEmptyAny;
}
bool MultiPropertySetHelper::hasProperty( sal_Int16 nValueNo )
2001-05-14 12:04:53 +00:00
{
assert(pSequenceIndex && "called hasProperty() without calling hasProperties()");
assert(nValueNo < nLength);
2001-05-14 12:04:53 +00:00
return pSequenceIndex[ nValueNo ] != -1;
}
#endif
2010-10-27 13:11:31 +01:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */