1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_xmloff.hxx" 26 #include <tools/debug.hxx> 27 #include <xmloff/EnumPropertyHdl.hxx> 28 #include <xmloff/xmluconv.hxx> 29 #include <comphelper/extract.hxx> 30 #include <rtl/ustring.hxx> 31 #include <rtl/ustrbuf.hxx> 32 #include <com/sun/star/uno/Any.hxx> 33 34 using ::rtl::OUString; 35 using ::rtl::OUStringBuffer; 36 37 using namespace ::com::sun::star::uno; 38 39 /////////////////////////////////////////////////////////////////////////////// 40 // 41 // class XMLEnumPropertyHdl 42 // 43 44 XMLEnumPropertyHdl::~XMLEnumPropertyHdl() 45 { 46 // Nothing to do 47 } 48 49 sal_Bool XMLEnumPropertyHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const 50 { 51 sal_uInt16 nValue = 0; 52 53 if( SvXMLUnitConverter::convertEnum( nValue, rStrImpValue, mpEnumMap ) ) 54 { 55 switch( mrType.getTypeClass() ) 56 { 57 case TypeClass_ENUM: 58 rValue = ::cppu::int2enum( nValue, mrType ); 59 break; 60 case TypeClass_LONG: 61 rValue <<= (sal_Int32) nValue; 62 break; 63 case TypeClass_SHORT: 64 rValue <<= (sal_Int16) nValue; 65 break; 66 case TypeClass_BYTE: 67 rValue <<= (sal_Int8) nValue; 68 break; 69 default: 70 DBG_ERROR( "Wrong type for enum property handler!" ); 71 return sal_False; 72 } 73 return sal_True; 74 } 75 76 return sal_False; 77 } 78 79 sal_Bool XMLEnumPropertyHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const 80 { 81 sal_Int32 nValue = 0; 82 if(!(rValue >>= nValue )) 83 if(!::cppu::enum2int(nValue, rValue) ) 84 return sal_False; 85 86 OUStringBuffer aOut; 87 88 if(!SvXMLUnitConverter::convertEnum( aOut, nValue, mpEnumMap )) 89 return sal_False; 90 91 rStrExpValue = aOut.makeStringAndClear(); 92 return sal_True; 93 } 94 95