merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / style / XMLConstantsPropertyHandler.cxx
blob34a92ce6737fc31905d70c0ac015fe2410fc7c85
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLConstantsPropertyHandler.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <tools/debug.hxx>
34 #include <xmloff/xmluconv.hxx>
35 #include <rtl/ustrbuf.hxx>
36 #include <com/sun/star/uno/Any.hxx>
37 #include <xmloff/XMLConstantsPropertyHandler.hxx>
39 using namespace ::com::sun::star::uno;
40 using ::rtl::OUString;
41 using ::rtl::OUStringBuffer;
43 using ::xmloff::token::XMLTokenEnum;
45 XMLConstantsPropertyHandler::XMLConstantsPropertyHandler(
46 const SvXMLEnumMapEntry *pM,
47 enum XMLTokenEnum eDflt ) :
48 pMap( pM ),
49 eDefault( eDflt )
53 XMLConstantsPropertyHandler::~XMLConstantsPropertyHandler()
57 sal_Bool XMLConstantsPropertyHandler::importXML(
58 const OUString& rStrImpValue,
59 Any& rValue,
60 const SvXMLUnitConverter& ) const
62 sal_uInt16 nEnum;
63 sal_Bool bRet = SvXMLUnitConverter::convertEnum(
64 nEnum, rStrImpValue, pMap );
66 if( bRet )
67 rValue <<= (sal_Int16)nEnum;
69 return bRet;
72 sal_Bool XMLConstantsPropertyHandler::exportXML(
73 OUString& rStrExpValue,
74 const Any& rValue,
75 const SvXMLUnitConverter& ) const
77 OUStringBuffer aOut;
79 sal_Bool bRet = false;
81 sal_Int32 nEnum = 0;
83 if( rValue.hasValue() && (rValue.getValueTypeClass() == TypeClass_ENUM))
85 nEnum = *((sal_Int32*)rValue.getValue());
86 bRet = true;
88 else
90 bRet = (rValue >>= nEnum );
93 if( bRet )
95 if( (nEnum >= 0) && (nEnum <= 0xffff) )
97 sal_uInt16 nConst = static_cast<sal_uInt16>( nEnum );
99 bRet = SvXMLUnitConverter::convertEnum(
100 aOut, nConst, pMap, eDefault );
102 rStrExpValue = aOut.makeStringAndClear();
104 else
106 DBG_ERROR("XMLConstantsPropertyHandler::exportXML() constant is out of range for implementation using sal_uInt16");
109 else
111 DBG_ERROR("XMLConstantsPropertyHandler::exportXML() could not convert any to sal_Int32");
114 return bRet;