merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / style / XMLClipPropertyHandler.cxx
blob016ce350cc2dde77439beba6527d43e70a86892f
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: XMLClipPropertyHandler.cxx,v $
10 * $Revision: 1.9 $
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 "XMLClipPropertyHandler.hxx"
34 #include <com/sun/star/uno/Any.hxx>
35 #include <rtl/ustrbuf.hxx>
36 #include <com/sun/star/text/GraphicCrop.hpp>
37 #include <xmloff/xmluconv.hxx>
38 #include <xmlkywd.hxx>
39 #include <xmloff/xmltoken.hxx>
41 using ::rtl::OUString;
42 using ::rtl::OUStringBuffer;
44 using namespace ::com::sun::star;
45 using namespace ::com::sun::star::uno;
46 using namespace ::com::sun::star::text;
47 using namespace ::xmloff::token;
49 ///////////////////////////////////////////////////////////////////////////////
51 // class XMLMeasurePropHdl
54 XMLClipPropertyHandler::XMLClipPropertyHandler( sal_Bool bODF11 ) :
55 m_bODF11( bODF11 )
59 XMLClipPropertyHandler::~XMLClipPropertyHandler()
61 // nothing to do
64 bool XMLClipPropertyHandler::equals(
65 const Any& r1,
66 const Any& r2 ) const
68 GraphicCrop aCrop1, aCrop2;
69 r1 >>= aCrop1;
70 r2 >>= aCrop2;
72 return aCrop1.Top == aCrop2.Top &&
73 aCrop1.Bottom == aCrop2.Bottom &&
74 aCrop1.Left == aCrop2.Left &&
75 aCrop1.Right == aCrop2.Right;
78 sal_Bool XMLClipPropertyHandler::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
80 sal_Bool bRet = sal_False;
81 sal_Int32 nLen = rStrImpValue.getLength();
82 if( nLen > 6 &&
83 0 == rStrImpValue.compareToAscii( sXML_rect, 4 ) &&
84 rStrImpValue[4] == '(' &&
85 rStrImpValue[nLen-1] == ')' )
87 GraphicCrop aCrop;
88 OUString sTmp( rStrImpValue.copy( 5, nLen-6 ) );
90 sal_Bool bHasComma = sTmp.indexOf( ',' ) != -1;
91 SvXMLTokenEnumerator aTokenEnum( sTmp, bHasComma ? ',' : ' ' );
93 sal_uInt16 nPos = 0;
94 OUString aToken;
95 while( aTokenEnum.getNextToken( aToken ) )
97 sal_Int32 nVal = 0;
98 if( !IsXMLToken(aToken, XML_AUTO) &&
99 !rUnitConverter.convertMeasure( nVal, aToken ) )
100 break;
102 switch( nPos )
104 case 0: aCrop.Top = nVal; break;
105 case 1: aCrop.Right = nVal; break;
106 case 2: aCrop.Bottom = nVal; break;
107 case 3: aCrop.Left = nVal; break;
109 nPos++;
112 bRet = (4 == nPos );
113 if( bRet )
114 rValue <<= aCrop;
117 return bRet;
120 sal_Bool XMLClipPropertyHandler::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
122 sal_Bool bRet = sal_False;
123 OUStringBuffer aOut(30);
124 GraphicCrop aCrop;
126 if( rValue >>= aCrop )
128 aOut.append( GetXMLToken(XML_RECT) );
129 aOut.append( (sal_Unicode)'(' );
130 rUnitConverter.convertMeasure( aOut, aCrop.Top );
131 if( !m_bODF11 )
132 aOut.append( (sal_Unicode)',' );
133 aOut.append( (sal_Unicode)' ' );
134 rUnitConverter.convertMeasure( aOut, aCrop.Right );
135 if( !m_bODF11 )
136 aOut.append( (sal_Unicode)',' );
137 aOut.append( (sal_Unicode)' ' );
138 rUnitConverter.convertMeasure( aOut, aCrop.Bottom );
139 if( !m_bODF11 )
140 aOut.append( (sal_Unicode)',' );
141 aOut.append( (sal_Unicode)' ' );
142 rUnitConverter.convertMeasure( aOut, aCrop.Left );
143 aOut.append( (sal_Unicode)')' );
144 rStrExpValue = aOut.makeStringAndClear();
146 bRet = sal_True;
149 return bRet;