Files
libreoffice/xmloff/source/forms/propertyexport.cxx

727 lines
32 KiB
C++
Raw Normal View History

/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: propertyexport.cxx,v $
* $Revision: 1.37 $
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_xmloff.hxx"
2000-11-29 09:36:05 +00:00
#include <stdio.h>
#include "propertyexport.hxx"
#include <xmloff/xmlexp.hxx>
#include "strings.hxx"
#include "xmlnmspe.hxx"
#include <xmloff/xmluconv.hxx>
#include <xmloff/families.hxx>
#include <osl/diagnose.h>
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <com/sun/star/beans/XPropertyState.hpp>
#include <com/sun/star/util/Date.hpp>
#include <com/sun/star/util/Time.hpp>
#include <com/sun/star/util/DateTime.hpp>
#include <osl/diagnose.h>
#include <comphelper/extract.hxx>
#include <comphelper/sequence.hxx>
#include <comphelper/types.hxx>
#include "callbacks.hxx"
#include <unotools/datetime.hxx>
#include <tools/date.hxx>
#include <tools/time.hxx>
#include <tools/datetime.hxx>
//.........................................................................
namespace xmloff
{
//.........................................................................
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::beans;
2000-12-13 09:38:49 +00:00
// NO using namespace ...util !!!
// need a tools Date/Time/DateTime below, which would conflict with the uno types then
using namespace ::comphelper;
//=====================================================================
//= OPropertyExport
//=====================================================================
//---------------------------------------------------------------------
OPropertyExport::OPropertyExport(IFormsExportContext& _rContext, const Reference< XPropertySet >& _rxProps)
:m_rContext(_rContext)
,m_xProps(_rxProps)
{
// caching
::rtl::OUStringBuffer aBuffer;
m_rContext.getGlobalContext().GetMM100UnitConverter().convertBool(aBuffer, sal_True);
m_sValueTrue = aBuffer.makeStringAndClear();
m_rContext.getGlobalContext().GetMM100UnitConverter().convertBool(aBuffer, sal_False);
m_sValueFalse = aBuffer.makeStringAndClear();
m_xPropertyInfo = m_xProps->getPropertySetInfo();
OSL_ENSURE(m_xPropertyInfo.is(), "OPropertyExport::OPropertyExport: need an XPropertySetInfo!");
// collect the properties which need to be exported
examinePersistence();
}
//---------------------------------------------------------------------
void OPropertyExport::exportRemainingProperties()
{
// the properties tag (will be created if we have at least one no-default property)
SvXMLElementExport* pPropertiesTag = NULL;
try
{
Reference< XPropertyState > xPropertyState( m_xProps, UNO_QUERY );
Reference< XPropertySetInfo > xPSI( m_xProps->getPropertySetInfo() );
Any aValue;
::rtl::OUString sValue;
// loop through all the properties which are yet to be exported
for ( ConstStringSetIterator aProperty = m_aRemainingProps.begin();
aProperty != m_aRemainingProps.end();
++aProperty
)
{
DBG_CHECK_PROPERTY_NO_TYPE(*aProperty);
#if OSL_DEBUG_LEVEL > 0
const ::rtl::OUString sPropertyName = *aProperty; (void)sPropertyName;
#endif
// if the property state is DEFAULT, it does not need to be written - at least
// if it's a built-in property, and not a dynamically-added one.
bool bIsDefaultValue = xPropertyState.is()
&& ( PropertyState_DEFAULT_VALUE == xPropertyState->getPropertyState( *aProperty ) );
bool bIsDynamicProperty = xPSI.is()
&& ( ( xPSI->getPropertyByName( *aProperty ).Attributes & PropertyAttribute::REMOVEABLE ) != 0 );
if ( bIsDefaultValue && !bIsDynamicProperty )
continue;
// now that we have the first sub-tag we need the form:properties element
if (!pPropertiesTag)
pPropertiesTag = new SvXMLElementExport(m_rContext.getGlobalContext(), XML_NAMESPACE_FORM, token::XML_PROPERTIES, sal_True, sal_True);
// add the name attribute
AddAttribute(XML_NAMESPACE_FORM, token::XML_PROPERTY_NAME, *aProperty);
// get the value
aValue = m_xProps->getPropertyValue(*aProperty);
// the type to export
Type aExportType;
// is it a sequence
sal_Bool bIsSequence = TypeClass_SEQUENCE == aValue.getValueTypeClass();
// the type of the property, maybe reduced to the element type of a sequence
if (bIsSequence)
aExportType = getSequenceElementType( aValue.getValueType() );
else
aExportType = aValue.getValueType();
// the type attribute
// modified by BerryJia for Bug102407
bool bIsEmptyValue = TypeClass_VOID == aValue.getValueType().getTypeClass();
if ( bIsEmptyValue )
{
com::sun::star::beans::Property aPropDesc;
aPropDesc = m_xPropertyInfo->getPropertyByName( *aProperty );
aExportType = aPropDesc.Type;
}
token::XMLTokenEnum eValueType = implGetPropertyXMLType( aExportType );
if ( bIsEmptyValue )
AddAttribute( XML_NAMESPACE_OFFICE, token::XML_VALUE_TYPE, token::XML_VOID );
else
AddAttribute( XML_NAMESPACE_OFFICE, token::XML_VALUE_TYPE, eValueType );
token::XMLTokenEnum eValueAttName( token::XML_VALUE );
switch ( eValueType )
{
case token::XML_BOOLEAN: eValueAttName = token::XML_BOOLEAN_VALUE; break;
case token::XML_STRING: eValueAttName = token::XML_STRING_VALUE; break;
default: break;
}
if( !bIsSequence && !bIsEmptyValue )
{ // the simple case
//add by BerryJia for Bug102407
sValue = implConvertAny(aValue);
AddAttribute(XML_NAMESPACE_OFFICE, eValueAttName, sValue );
}
// start the property tag
SvXMLElementExport aValueTag1(m_rContext.getGlobalContext(),
XML_NAMESPACE_FORM,
bIsSequence ? token::XML_LIST_PROPERTY
: token::XML_PROPERTY, sal_True, sal_True);
if (!bIsSequence)
continue;
// the not-that-simple case, we need to iterate through the sequence elements
IIterator* pSequenceIterator = NULL;
switch ( aExportType.getTypeClass() )
{
case TypeClass_STRING:
pSequenceIterator = new OSequenceIterator< ::rtl::OUString >(aValue);
break;
case TypeClass_DOUBLE:
pSequenceIterator = new OSequenceIterator< double >(aValue);
break;
case TypeClass_BOOLEAN:
pSequenceIterator = new OSequenceIterator< sal_Bool >(aValue);
break;
case TypeClass_BYTE:
pSequenceIterator = new OSequenceIterator< sal_Int8 >(aValue);
break;
case TypeClass_SHORT:
pSequenceIterator = new OSequenceIterator< sal_Int16 >(aValue);
break;
case TypeClass_LONG:
pSequenceIterator = new OSequenceIterator< sal_Int32 >(aValue);
break;
case TypeClass_HYPER:
pSequenceIterator = new OSequenceIterator< sal_Int64 >(aValue);
break;
default:
OSL_ENSURE(sal_False, "OPropertyExport::exportRemainingProperties: unsupported sequence tyoe !");
break;
}
if (pSequenceIterator)
{
while (pSequenceIterator->hasMoreElements())
{
sValue =
implConvertAny(pSequenceIterator->nextElement());
AddAttribute(XML_NAMESPACE_OFFICE, eValueAttName, sValue );
SvXMLElementExport aValueTag(
m_rContext.getGlobalContext(),
XML_NAMESPACE_FORM, token::XML_LIST_VALUE,
sal_True, sal_False);
}
}
delete pSequenceIterator;
}
}
catch(...)
{
delete pPropertiesTag;
throw;
}
delete pPropertiesTag;
}
//---------------------------------------------------------------------
void OPropertyExport::examinePersistence()
{
m_aRemainingProps.clear();
Sequence< Property > aProperties = m_xPropertyInfo->getProperties();
const Property* pProperties = aProperties.getConstArray();
for (sal_Int32 i=0; i<aProperties.getLength(); ++i, ++pProperties)
{
// no transient props
if ( pProperties->Attributes & PropertyAttribute::TRANSIENT )
continue;
// no read-only props
if ( ( pProperties->Attributes & PropertyAttribute::READONLY ) != 0 )
// except they're dynamically added
if ( ( pProperties->Attributes & PropertyAttribute::REMOVEABLE ) == 0 )
continue;
m_aRemainingProps.insert(pProperties->Name);
}
}
//---------------------------------------------------------------------
void OPropertyExport::exportStringPropertyAttribute( const sal_uInt16 _nNamespaceKey, const sal_Char* _pAttributeName,
const ::rtl::OUString& _rPropertyName )
{
DBG_CHECK_PROPERTY( _rPropertyName, ::rtl::OUString );
// no try-catch here, this would be to expensive. The outer scope has to handle exceptions (which should not
// happen if we're used correctly :)
// this is way simple, as we don't need to convert anything (the property already is a string)
// get the string
::rtl::OUString sPropValue;
m_xProps->getPropertyValue( _rPropertyName ) >>= sPropValue;
// add the attribute
if ( sPropValue.getLength() )
AddAttribute( _nNamespaceKey, _pAttributeName, sPropValue );
// the property does not need to be handled anymore
exportedProperty( _rPropertyName );
}
//---------------------------------------------------------------------
void OPropertyExport::exportBooleanPropertyAttribute(const sal_uInt16 _nNamespaceKey, const sal_Char* _pAttributeName,
const ::rtl::OUString& _rPropertyName, const sal_Int8 _nBooleanAttributeFlags)
{
DBG_CHECK_PROPERTY_NO_TYPE( _rPropertyName );
// no check of the property value type: this method is allowed to be called with any interger properties
// (e.g. sal_Int32, sal_uInt16 etc)
sal_Bool bDefault = (BOOLATTR_DEFAULT_TRUE == (BOOLATTR_DEFAULT_MASK & _nBooleanAttributeFlags));
sal_Bool bDefaultVoid = (BOOLATTR_DEFAULT_VOID == (BOOLATTR_DEFAULT_MASK & _nBooleanAttributeFlags));
// get the value
sal_Bool bCurrentValue = bDefault;
Any aCurrentValue = m_xProps->getPropertyValue( _rPropertyName );
if (aCurrentValue.hasValue())
{
bCurrentValue = ::cppu::any2bool(aCurrentValue);
// this will extract a boolean value even if the Any contains a int or short or something like that ...
if (_nBooleanAttributeFlags & BOOLATTR_INVERSE_SEMANTICS)
bCurrentValue = !bCurrentValue;
// we have a non-void current value
if (bDefaultVoid || (bDefault != bCurrentValue))
// and (the default is void, or the non-void default does not equal the current value)
// -> write the attribute
AddAttribute(_nNamespaceKey, _pAttributeName, bCurrentValue ? m_sValueTrue : m_sValueFalse);
}
else
// we have a void current value
if (!bDefaultVoid)
// and we have a non-void default
// -> write the attribute
AddAttribute(_nNamespaceKey, _pAttributeName, bCurrentValue ? m_sValueTrue : m_sValueFalse);
// the property does not need to be handled anymore
exportedProperty( _rPropertyName );
}
//---------------------------------------------------------------------
void OPropertyExport::exportInt16PropertyAttribute(const sal_uInt16 _nNamespaceKey, const sal_Char* _pAttributeName,
const ::rtl::OUString& _rPropertyName, const sal_Int16 _nDefault)
{
DBG_CHECK_PROPERTY( _rPropertyName, sal_Int16 );
// get the value
sal_Int16 nCurrentValue(_nDefault);
m_xProps->getPropertyValue( _rPropertyName ) >>= nCurrentValue;
// add the attribute
if (_nDefault != nCurrentValue)
{
// let the formatter of the export context build a string
::rtl::OUStringBuffer sBuffer;
m_rContext.getGlobalContext().GetMM100UnitConverter().convertNumber(sBuffer, (sal_Int32)nCurrentValue);
AddAttribute(_nNamespaceKey, _pAttributeName, sBuffer.makeStringAndClear());
}
// the property does not need to be handled anymore
exportedProperty( _rPropertyName );
}
//---------------------------------------------------------------------
void OPropertyExport::exportInt32PropertyAttribute( const sal_uInt16 _nNamespaceKey, const sal_Char* _pAttributeName,
const ::rtl::OUString& _rPropertyName, const sal_Int32 _nDefault )
{
DBG_CHECK_PROPERTY( _rPropertyName, sal_Int32 );
// get the value
sal_Int32 nCurrentValue( _nDefault );
m_xProps->getPropertyValue( _rPropertyName ) >>= nCurrentValue;
// add the attribute
if ( _nDefault != nCurrentValue )
{
// let the formatter of the export context build a string
::rtl::OUStringBuffer sBuffer;
m_rContext.getGlobalContext().GetMM100UnitConverter().convertNumber( sBuffer, nCurrentValue );
AddAttribute( _nNamespaceKey, _pAttributeName, sBuffer.makeStringAndClear() );
}
// the property does not need to be handled anymore
exportedProperty( _rPropertyName );
}
//---------------------------------------------------------------------
void OPropertyExport::exportEnumPropertyAttribute(
const sal_uInt16 _nNamespaceKey, const sal_Char* _pAttributeName,
const sal_Char* _pPropertyName, const SvXMLEnumMapEntry* _pValueMap,
const sal_Int32 _nDefault, const sal_Bool _bVoidDefault)
{
// get the value
sal_Int32 nCurrentValue(_nDefault);
::rtl::OUString sPropertyName(::rtl::OUString::createFromAscii(_pPropertyName));
Any aValue = m_xProps->getPropertyValue(sPropertyName);
if (aValue.hasValue())
{ // we have a non-void current value
::cppu::enum2int(nCurrentValue, aValue);
// add the attribute
if ((_nDefault != nCurrentValue) || _bVoidDefault)
{ // the default does not equal the value, or the default is void and the value isn't
// let the formatter of the export context build a string
::rtl::OUStringBuffer sBuffer;
m_rContext.getGlobalContext().GetMM100UnitConverter().convertEnum(sBuffer, (sal_uInt16)nCurrentValue, _pValueMap);
AddAttribute(_nNamespaceKey, _pAttributeName, sBuffer.makeStringAndClear());
}
}
else
{
if (!_bVoidDefault)
AddAttributeASCII(_nNamespaceKey, _pAttributeName, "");
}
// the property does not need to be handled anymore
exportedProperty(sPropertyName);
}
//---------------------------------------------------------------------
void OPropertyExport::exportTargetFrameAttribute()
{
DBG_CHECK_PROPERTY( PROPERTY_TARGETFRAME, ::rtl::OUString );
::rtl::OUString sTargetFrame = comphelper::getString(m_xProps->getPropertyValue(PROPERTY_TARGETFRAME));
if (0 != sTargetFrame.compareToAscii("_blank"))
{ // an empty string and "_blank" have the same meaning and don't have to be written
AddAttribute(OAttributeMetaData::getCommonControlAttributeNamespace(CCA_TARGET_FRAME)
,OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_FRAME)
,sTargetFrame);
}
exportedProperty(PROPERTY_TARGETFRAME);
}
//---------------------------------------------------------------------
2002-08-22 06:36:10 +00:00
void OPropertyExport::exportRelativeTargetLocation(const ConstAsciiString& _sPropertyName,sal_Int32 _nProperty)
{
DBG_CHECK_PROPERTY( _sPropertyName, ::rtl::OUString );
2002-08-22 06:36:10 +00:00
::rtl::OUString sTargetLocation = comphelper::getString(m_xProps->getPropertyValue(_sPropertyName));
if ( sTargetLocation.getLength() )
CWS-TOOLING: integrate CWS dba31e 2008-11-19 12:36:23 +0100 msc r263980 : i96104 2008-11-19 12:31:19 +0100 msc r263979 : i96104 2008-11-19 12:21:55 +0100 msc r263977 : i96104 2008-11-19 12:18:53 +0100 msc r263976 : i96104 2008-11-18 09:09:45 +0100 oj r263746 : disable color entry when area is set 2008-11-18 08:37:52 +0100 oj r263741 : #remove sub report entry 2008-11-17 11:20:25 +0100 fs r263708 : #i10000# 2008-11-17 11:06:52 +0100 fs r263706 : minimal version now is 3.1 2008-11-12 22:25:59 +0100 fs r263621 : #i96150# 2008-11-12 22:20:02 +0100 fs r263620 : rebased to m34 2008-11-12 21:39:41 +0100 fs r263618 : MANUAL REBASE: rebase CWS dba31d to DEV300_m34 2008-11-12 13:54:58 +0100 fs r263597 : #i96134# MediaDescriptor.URL is to be preferred over MediaDescriptor.FileName. Nonetheless, ensure both are handled 2008-11-12 13:53:40 +0100 fs r263596 : #i96134# re-enabled the code for #i41897#, a better fix is to come 2008-11-12 12:48:21 +0100 fs r263585 : #i96134# disable saving URLs of file-base databases relatively 2008-11-11 16:11:11 +0100 msc r263566 : #i96104# 2008-11-05 09:09:47 +0100 oj r263342 : #i88727# color noe added 2008-11-05 08:41:43 +0100 oj r263341 : #i77916# zoom added 2008-11-04 21:24:15 +0100 fs r263339 : disposing: call disposeAndClear without own mutex locked - some of our listeners insist on locking the SolarMutex, which sometimes led to deadlocks on the complex test cases 2008-11-04 21:23:15 +0100 fs r263338 : remove SolarMutex locking - this happned in CWS dba31c (in the CVS version), which this CWS was created from, but seems to got lost during resync 2008-11-04 20:49:50 +0100 fs r263335 : docu formatting 2008-11-04 20:06:39 +0100 fs r263334 : #i95826# use m_aMutex, not a DocumentGuard (wrongly resolved merge conflicts) 2008-11-04 17:36:29 +0100 fs r263332 : #i92688# properly revoke as XEventListener from m_xActiveController when disposing 2008-11-04 14:49:34 +0100 fs r263324 : #i92322# enable Input Required if EmptyIsNULL does not exist at the control 2008-10-31 11:10:04 +0100 oj r262857 : merge from cvs to svn 2008-10-31 09:46:45 +0100 oj r262853 : merge from cvs to svn 2008-10-31 08:46:37 +0100 oj r262849 : merge from cvs to svn 2008-10-31 08:44:24 +0100 oj r262848 : merge from cvs to svn 2008-10-31 08:43:33 +0100 oj r262847 : merge from cvs to svn 2008-10-31 08:42:28 +0100 oj r262846 : merge from cvs to svn 2008-10-31 08:41:58 +0100 oj r262845 : merge from cvs to svn 2008-10-31 08:41:32 +0100 oj r262844 : merge from cvs to svn 2008-10-28 12:19:50 +0100 oj r262733 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:42 +0100 oj r262732 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:36 +0100 oj r262731 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:31 +0100 oj r262730 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:22 +0100 oj r262729 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:18 +0100 oj r262728 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:10 +0100 oj r262727 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:06 +0100 oj r262726 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:05 +0100 oj r262725 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:19:01 +0100 oj r262724 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:50 +0100 oj r262723 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:41 +0100 oj r262722 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:40 +0100 oj r262721 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:27 +0100 oj r262720 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:10 +0100 oj r262719 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:18:01 +0100 oj r262718 : #iXXXXX#: migrate CWS dba31e to SVN 2008-10-28 12:17:39 +0100 oj r262717 : #iXXXXX#: migrate CWS dba31e to SVN
2008-12-01 12:31:27 +00:00
// If this isn't a GraphicObject then GetRelativeReference
// will be called anyway ( in AddEmbeddedGraphic )
sTargetLocation = m_rContext.getGlobalContext().AddEmbeddedGraphicObject(sTargetLocation);
AddAttribute(OAttributeMetaData::getCommonControlAttributeNamespace(_nProperty)
,OAttributeMetaData::getCommonControlAttributeName(_nProperty)
, sTargetLocation);
2002-08-22 06:36:10 +00:00
exportedProperty(_sPropertyName);
}
//---------------------------------------------------------------------
void OPropertyExport::flagStyleProperties()
{
// flag all the properties which are part of the style as "handled"
UniReference< XMLPropertySetMapper > xStylePropertiesSupplier = m_rContext.getStylePropertyMapper()->getPropertySetMapper();
for (sal_Int32 i=0; i<xStylePropertiesSupplier->GetEntryCount(); ++i)
exportedProperty(xStylePropertiesSupplier->GetEntryAPIName(i));
// the font properties are exported as single properties, but there is a FontDescriptor property which
// collects them all-in-one, this has been exported implicitly
exportedProperty(PROPERTY_FONT);
// for the DateFormat and TimeFormat, there exist wrapper properties which has been exported as
// style, too
exportedProperty(PROPERTY_DATEFORMAT);
exportedProperty(PROPERTY_TIMEFORMAT);
// the "VerticalAlign" property should have been exported at the shape, too
exportedProperty( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VerticalAlign" ) ) );
CWS-TOOLING: integrate CWS rtlcontrols 2008-12-11 21:08:49 +0100 fs r265367 : CONTEXT_WRITING_MODE is transient 2008-12-11 21:08:00 +0100 fs r265365 : REGISTER_PROP_3 2008-12-11 20:53:44 +0100 fs r265362 : ContextWritingMode is not MAYBEVOID 2008-12-11 15:29:08 +0100 fs r265315 : prevent a deadlock during complex.dbaccess.DatabaseDocument test 2008-12-11 15:01:13 +0100 fs r265304 : manual RESYNC to m37 2008-12-10 20:04:38 +0100 pl r265230 : #i30631# fix a snafu in mirroring 2008-12-10 19:14:45 +0100 pl r265229 : #i30631# rework PaintToDevice for RTL controls 2008-12-05 10:19:13 +0100 fs r264893 : #i10000# ImplInitSettings => ImplInitWindow (ImplInitSettings clashed with base classes ImplInitSettings on unxsols4) 2008-12-03 12:55:24 +0100 fs r264768 : #i100000# 2008-12-03 07:11:48 +0100 fs r264741 : #i10000# 2008-12-02 10:37:51 +0100 fs r264670 : CWS-TOOLING: rebase CWS rtlcontrols to trunk@264325 (milestone: DEV300:m36) 2008-12-02 09:27:50 +0100 fs r264660 : merge from trunk 2008-11-25 10:28:36 +0100 ama r264277 : Fix #i94572# 2008-11-24 11:46:48 +0100 fs r264218 : #i30631# proper context writing mode 2008-11-24 09:38:04 +0100 fs r264204 : #i30631# (approved by PL) 2008-11-24 09:35:47 +0100 fs r264203 : #i30631# Context/WritingMode 2008-11-24 09:33:36 +0100 fs r264202 : #i30631# Context/WritingMode 2008-11-24 09:31:53 +0100 fs r264200 : #i30631# RTL 2008-11-19 08:51:48 +0100 fs r263963 : #i10000# 2008-11-18 20:58:11 +0100 fs r263878 : #i10000# 2008-11-18 15:30:44 +0100 fs r263778 : migrate the CWS from CVS to SVN the CVS changes contained in this change set are the ones between the following two CVS tags: CWS_DEV300_RTLCONTROLS_ANCHOR CWS_DEV300_RTLCONTROLS_PRE_MIGRATION 2008-11-18 12:29:04 +0100 ama r263762 : Fix #i94572#: Context direction for drawing objects 2008-11-18 12:25:50 +0100 ama r263761 : Fix #i94572#: Context direction for drawing objects 2008-11-18 12:02:30 +0100 ama r263759 : Fix #i94572#: Context direction for drawing objects
2008-12-16 13:30:53 +00:00
// ditto the TextWritingMode
exportedProperty( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "WritingMode" ) ) );
}
//---------------------------------------------------------------------
void OPropertyExport::exportGenericPropertyAttribute(
const sal_uInt16 _nAttributeNamespaceKey, const sal_Char* _pAttributeName, const sal_Char* _pPropertyName)
{
DBG_CHECK_PROPERTY_ASCII_NO_TYPE( _pPropertyName );
::rtl::OUString sPropertyName = ::rtl::OUString::createFromAscii(_pPropertyName);
exportedProperty(sPropertyName);
Any aCurrentValue = m_xProps->getPropertyValue(sPropertyName);
if (!aCurrentValue.hasValue())
// nothing to do without a concrete value
return;
::rtl::OUString sValue = implConvertAny(aCurrentValue);
if (!sValue.getLength() && (TypeClass_STRING == aCurrentValue.getValueTypeClass()))
{
// check whether or not the property is allowed to be VOID
Property aProperty = m_xPropertyInfo->getPropertyByName(sPropertyName);
if ((aProperty.Attributes & PropertyAttribute::MAYBEVOID) == 0)
// the string is empty, and the property is not allowed to be void
// -> don't need to write the attibute, 'cause missing it is unambiguous
return;
}
// finally add the attribuite to the context
AddAttribute(_nAttributeNamespaceKey, _pAttributeName, sValue);
}
//---------------------------------------------------------------------
void OPropertyExport::exportStringSequenceAttribute(const sal_uInt16 _nAttributeNamespaceKey, const sal_Char* _pAttributeName,
const ::rtl::OUString& _rPropertyName,
const sal_Unicode _aQuoteCharacter, const sal_Unicode _aListSeparator)
{
DBG_CHECK_PROPERTY( _rPropertyName, Sequence< ::rtl::OUString > );
OSL_ENSURE(_aListSeparator != 0, "OPropertyExport::exportStringSequenceAttribute: invalid separator character!");
Sequence< ::rtl::OUString > aItems;
m_xProps->getPropertyValue( _rPropertyName ) >>= aItems;
::rtl::OUString sFinalList;
// unfortunately the OUString can't append single sal_Unicode characters ...
const ::rtl::OUString sQuote(&_aQuoteCharacter, 1);
const ::rtl::OUString sSeparator(&_aListSeparator, 1);
const sal_Bool bQuote = 0 != sQuote.getLength();
// concatenate the string items
const ::rtl::OUString* pItems = aItems.getConstArray();
const ::rtl::OUString* pEnd = pItems + aItems.getLength();
const ::rtl::OUString* pLastElement = pEnd - 1;
for ( ;
pItems != pEnd;
++pItems
)
{
OSL_ENSURE(!_aQuoteCharacter || (-1 == pItems->indexOf(_aQuoteCharacter)),
"OPropertyExport::exportStringSequenceAttribute: there is an item which contains the quote character!");
OSL_ENSURE(_aQuoteCharacter || (-1 == pItems->indexOf(_aListSeparator)),
"OPropertyExport::exportStringSequenceAttribute: no quote character, but there is an item containing the separator character!");
if (bQuote)
sFinalList += sQuote;
sFinalList += *pItems;
if (bQuote)
sFinalList += sQuote;
if (pItems != pLastElement)
sFinalList += sSeparator;
}
if (sFinalList.getLength())
AddAttribute(_nAttributeNamespaceKey, _pAttributeName, sFinalList);
exportedProperty( _rPropertyName );
}
//---------------------------------------------------------------------
::rtl::OUString OPropertyExport::implConvertAny(const Any& _rValue)
{
::rtl::OUStringBuffer aBuffer;
switch (_rValue.getValueTypeClass())
{
case TypeClass_STRING:
{ // extract the string
::rtl::OUString sCurrentValue;
_rValue >>= sCurrentValue;
aBuffer.append(sCurrentValue);
}
break;
case TypeClass_DOUBLE:
// let the unit converter format is as string
m_rContext.getGlobalContext().GetMM100UnitConverter().convertDouble(aBuffer, getDouble(_rValue));
break;
case TypeClass_BOOLEAN:
aBuffer = getBOOL(_rValue) ? m_sValueTrue : m_sValueFalse;
break;
case TypeClass_BYTE:
case TypeClass_SHORT:
case TypeClass_LONG:
// let the unit converter format is as string
m_rContext.getGlobalContext().GetMM100UnitConverter().convertNumber(aBuffer, getINT32(_rValue));
break;
case TypeClass_HYPER:
// TODO
OSL_ENSURE(sal_False, "OPropertyExport::implConvertAny: missing implementation for sal_Int64!");
break;
case TypeClass_ENUM:
{
// convert it into an int32
sal_Int32 nValue = 0;
::cppu::enum2int(nValue, _rValue);
m_rContext.getGlobalContext().GetMM100UnitConverter().convertNumber(aBuffer, nValue);
}
break;
default:
{ // hmmm .... what else do we know?
double fValue = 0;
::com::sun::star::util::Date aDate;
::com::sun::star::util::Time aTime;
::com::sun::star::util::DateTime aDateTime;
if (_rValue >>= aDate)
{
Date aToolsDate;
::utl::typeConvert(aDate, aToolsDate);
fValue = aToolsDate.GetDate();
}
else if (_rValue >>= aTime)
{
fValue = ((aTime.Hours * 60 + aTime.Minutes) * 60 + aTime.Seconds) * 100 + aTime.HundredthSeconds;
fValue = fValue / 8640000.0;
}
else if (_rValue >>= aDateTime)
{
DateTime aToolsDateTime;
::utl::typeConvert(aDateTime, aToolsDateTime);
// the time part (the digits behind the comma)
fValue = ((aDateTime.Hours * 60 + aDateTime.Minutes) * 60 + aDateTime.Seconds) * 100 + aDateTime.HundredthSeconds;
fValue = fValue / 8640000.0;
// plus the data part (the digits in front of the comma)
fValue += aToolsDateTime.GetDate();
}
else
{
// if any other types are added here, please remember to adjust implGetPropertyXMLType accordingly
// no more options ...
OSL_ENSURE(sal_False, "OPropertyExport::implConvertAny: unsupported value type!");
break;
}
// let the unit converter format is as string
m_rContext.getGlobalContext().GetMM100UnitConverter().convertDouble(aBuffer, fValue);
}
break;
}
return aBuffer.makeStringAndClear();
}
//---------------------------------------------------------------------
token::XMLTokenEnum OPropertyExport::implGetPropertyXMLType(const ::com::sun::star::uno::Type& _rType)
{
// handle the type description
switch (_rType.getTypeClass())
{
case TypeClass_STRING:
return token::XML_STRING;
case TypeClass_DOUBLE:
case TypeClass_BYTE:
case TypeClass_SHORT:
case TypeClass_LONG:
case TypeClass_HYPER:
case TypeClass_ENUM:
return token::XML_FLOAT;
case TypeClass_BOOLEAN:
return token::XML_BOOLEAN;
default:
return token::XML_FLOAT;
}
}
#ifdef DBG_UTIL
//---------------------------------------------------------------------
void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix, const sal_Char* _pName, const ::rtl::OUString& _rValue)
{
OSL_ENSURE(0 == m_rContext.getGlobalContext().GetXAttrList()->getValueByName(::rtl::OUString::createFromAscii(_pName)).getLength(),
"OPropertyExport::AddAttribute: already have such an attribute");
m_rContext.getGlobalContext().AddAttribute(_nPrefix, _pName, _rValue);
}
//---------------------------------------------------------------------
void OPropertyExport::AddAttribute( sal_uInt16 _nPrefix, const ::rtl::OUString& _rName, const ::rtl::OUString& _rValue )
{
OSL_ENSURE(0 == m_rContext.getGlobalContext().GetXAttrList()->getValueByName( _rName ).getLength(),
"OPropertyExport::AddAttribute: already have such an attribute");
m_rContext.getGlobalContext().AddAttribute( _nPrefix, _rName, _rValue );
}
//---------------------------------------------------------------------
void OPropertyExport::AddAttributeASCII(sal_uInt16 _nPrefix, const sal_Char* _pName, const sal_Char *pValue)
{
OSL_ENSURE(0 == m_rContext.getGlobalContext().GetXAttrList()->getValueByName(::rtl::OUString::createFromAscii(_pName)).getLength(),
"OPropertyExport::AddAttributeASCII: already have such an attribute");
m_rContext.getGlobalContext().AddAttributeASCII(_nPrefix, _pName, pValue);
}
//---------------------------------------------------------------------
void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, const ::rtl::OUString& _rValue)
{
OSL_ENSURE(0 == m_rContext.getGlobalContext().GetXAttrList()->getValueByName(::xmloff::token::GetXMLToken(_eName)).getLength(),
"OPropertyExport::AddAttribute: already have such an attribute");
m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _rValue);
}
//---------------------------------------------------------------------
void OPropertyExport::AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, ::xmloff::token::XMLTokenEnum _eValue )
{
OSL_ENSURE(0 == m_rContext.getGlobalContext().GetXAttrList()->getValueByName(::xmloff::token::GetXMLToken(_eName)).getLength(),
"OPropertyExport::AddAttribute: already have such an attribute");
m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _eValue);
}
//---------------------------------------------------------------------
void OPropertyExport::dbg_implCheckProperty(const ::rtl::OUString& _rPropertyName, const Type* _pType)
{
try
{
// the property must exist
if (!m_xPropertyInfo->hasPropertyByName(_rPropertyName))
{
OSL_ENSURE(sal_False,
::rtl::OString("OPropertyExport::dbg_implCheckProperty: no property with the name ") +=
::rtl::OString(_rPropertyName.getStr(), _rPropertyName.getLength(), RTL_TEXTENCODING_ASCII_US) +=
::rtl::OString("!"));
return;
}
if (_pType)
{
// and it must have the correct type
Property aPropertyDescription = m_xPropertyInfo->getPropertyByName(_rPropertyName);
OSL_ENSURE(aPropertyDescription.Type.equals(*_pType), "OPropertyExport::dbg_implCheckProperty: invalid property type!");
}
}
catch(Exception&)
{
OSL_ENSURE(sal_False, "OPropertyExport::dbg_implCheckProperty: caught an exception, could not check the property!");
}
}
#endif // DBG_UTIL - dbg_implCheckProperty
//.........................................................................
} // namespace xmloff
//.........................................................................