1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: backhdl.cxx,v $
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 <backhdl.hxx>
35 #include <xmloff/xmltoken.hxx>
36 #include <xmloff/xmluconv.hxx>
37 #include <com/sun/star/uno/Any.hxx>
38 #include <rtl/ustrbuf.hxx>
40 #ifndef _XMLOFF_XMLEMENT_HXX
41 #include <xmloff/xmlelement.hxx>
44 using ::rtl::OUString
;
45 using ::rtl::OUStringBuffer
;
47 using namespace ::com::sun::star
;
48 using namespace ::xmloff::token
;
50 SvXMLEnumMapEntry pXML_BrushHorizontalPos
[] =
52 { XML_LEFT
, style::GraphicLocation_LEFT_MIDDLE
},
53 { XML_RIGHT
, style::GraphicLocation_RIGHT_MIDDLE
},
54 { XML_TOKEN_INVALID
, 0 }
57 SvXMLEnumMapEntry pXML_BrushVerticalPos
[] =
59 { XML_TOP
, style::GraphicLocation_MIDDLE_TOP
},
60 { XML_BOTTOM
, style::GraphicLocation_MIDDLE_BOTTOM
},
61 { XML_TOKEN_INVALID
, 0 }
64 ///////////////////////////////////////////////////////////////////////////////
66 // class XMLBackGraphicPositionPropHdl
69 XMLBackGraphicPositionPropHdl::~XMLBackGraphicPositionPropHdl()
74 sal_Bool
XMLBackGraphicPositionPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
76 sal_Bool bRet
= sal_True
;
77 style::GraphicLocation ePos
= style::GraphicLocation_NONE
, eTmp
;
79 SvXMLTokenEnumerator
aTokenEnum( rStrImpValue
);
81 sal_Bool bHori
= sal_False
, bVert
= sal_False
;
83 while( bRet
&& aTokenEnum
.getNextToken( aToken
) )
89 else if( -1 != aToken
.indexOf( sal_Unicode('%') ) )
92 if( SvXMLUnitConverter::convertPercent( nPrc
, aToken
) )
96 ePos
= nPrc
< 25 ? style::GraphicLocation_LEFT_TOP
:
97 (nPrc
< 75 ? style::GraphicLocation_MIDDLE_MIDDLE
:
98 style::GraphicLocation_RIGHT_BOTTOM
);
103 eTmp
= nPrc
< 25 ? style::GraphicLocation_LEFT_TOP
:
104 (nPrc
< 75 ? style::GraphicLocation_LEFT_MIDDLE
:
105 style::GraphicLocation_LEFT_BOTTOM
);
106 MergeXMLVertPos( ePos
, eTmp
);
116 else if( IsXMLToken( aToken
, XML_CENTER
) )
119 MergeXMLVertPos( ePos
, style::GraphicLocation_MIDDLE_MIDDLE
);
121 MergeXMLHoriPos( ePos
, style::GraphicLocation_MIDDLE_MIDDLE
);
123 ePos
= style::GraphicLocation_MIDDLE_MIDDLE
;
125 else if( SvXMLUnitConverter::convertEnum( nTmp
, aToken
, pXML_BrushHorizontalPos
) )
128 MergeXMLHoriPos( ePos
, (style::GraphicLocation
)nTmp
);
130 ePos
= (style::GraphicLocation
)nTmp
;
136 else if( SvXMLUnitConverter::convertEnum( nTmp
, aToken
, pXML_BrushVerticalPos
) )
139 MergeXMLVertPos( ePos
, (style::GraphicLocation
)nTmp
);
141 ePos
= (style::GraphicLocation
)nTmp
;
152 bRet
&= style::GraphicLocation_NONE
!= ePos
;
154 rValue
<<= (style::GraphicLocation
)(sal_uInt16
)ePos
;
159 sal_Bool
XMLBackGraphicPositionPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
161 sal_Bool bRet
= sal_True
;
164 style::GraphicLocation eLocation
;
165 if( !( rValue
>>= eLocation
) )
167 sal_Int32 nValue
= 0;
168 if( rValue
>>= nValue
)
169 eLocation
= (style::GraphicLocation
)nValue
;
180 case style::GraphicLocation_LEFT_TOP
:
181 case style::GraphicLocation_MIDDLE_TOP
:
182 case style::GraphicLocation_RIGHT_TOP
:
183 aOut
.append( GetXMLToken(XML_TOP
) );
186 case style::GraphicLocation_LEFT_MIDDLE
:
187 case style::GraphicLocation_MIDDLE_MIDDLE
:
188 case style::GraphicLocation_RIGHT_MIDDLE
:
189 aOut
.append( GetXMLToken(XML_CENTER
) );
192 case style::GraphicLocation_LEFT_BOTTOM
:
193 case style::GraphicLocation_MIDDLE_BOTTOM
:
194 case style::GraphicLocation_RIGHT_BOTTOM
:
195 aOut
.append( GetXMLToken(XML_BOTTOM
) );
204 aOut
.append( sal_Unicode( ' ' ) );
208 case style::GraphicLocation_LEFT_TOP
:
209 case style::GraphicLocation_LEFT_BOTTOM
:
210 case style::GraphicLocation_LEFT_MIDDLE
:
211 aOut
.append( GetXMLToken(XML_LEFT
) );
213 case style::GraphicLocation_MIDDLE_TOP
:
214 case style::GraphicLocation_MIDDLE_MIDDLE
:
215 case style::GraphicLocation_MIDDLE_BOTTOM
:
216 aOut
.append( GetXMLToken(XML_CENTER
) );
218 case style::GraphicLocation_RIGHT_MIDDLE
:
219 case style::GraphicLocation_RIGHT_TOP
:
220 case style::GraphicLocation_RIGHT_BOTTOM
:
221 aOut
.append( GetXMLToken(XML_RIGHT
) );
229 rStrExpValue
= aOut
.makeStringAndClear();
234 void XMLBackGraphicPositionPropHdl::MergeXMLVertPos( style::GraphicLocation
& ePos
, style::GraphicLocation eVert
) const
238 case style::GraphicLocation_LEFT_TOP
:
239 case style::GraphicLocation_LEFT_MIDDLE
:
240 case style::GraphicLocation_LEFT_BOTTOM
:
241 ePos
= style::GraphicLocation_MIDDLE_TOP
==eVert
?
242 style::GraphicLocation_LEFT_TOP
:
243 (style::GraphicLocation_MIDDLE_MIDDLE
==eVert
?
244 style::GraphicLocation_LEFT_MIDDLE
:
245 style::GraphicLocation_LEFT_BOTTOM
);
249 case style::GraphicLocation_MIDDLE_TOP
:
250 case style::GraphicLocation_MIDDLE_MIDDLE
:
251 case style::GraphicLocation_MIDDLE_BOTTOM
:
255 case style::GraphicLocation_RIGHT_TOP
:
256 case style::GraphicLocation_RIGHT_MIDDLE
:
257 case style::GraphicLocation_RIGHT_BOTTOM
:
258 ePos
= style::GraphicLocation_MIDDLE_TOP
==eVert
?
259 style::GraphicLocation_RIGHT_TOP
:
260 (style::GraphicLocation_MIDDLE_MIDDLE
==eVert
?
261 style::GraphicLocation_RIGHT_MIDDLE
:
262 style::GraphicLocation_RIGHT_BOTTOM
);
269 void XMLBackGraphicPositionPropHdl::MergeXMLHoriPos( style::GraphicLocation
& ePos
, style::GraphicLocation eHori
) const
271 DBG_ASSERT( style::GraphicLocation_LEFT_MIDDLE
==eHori
|| style::GraphicLocation_MIDDLE_MIDDLE
==eHori
|| style::GraphicLocation_RIGHT_MIDDLE
==eHori
,
272 "lcl_frmitems_MergeXMLHoriPos: vertical pos must be middle" );
276 case style::GraphicLocation_LEFT_TOP
:
277 case style::GraphicLocation_MIDDLE_TOP
:
278 case style::GraphicLocation_RIGHT_TOP
:
279 ePos
= style::GraphicLocation_LEFT_MIDDLE
==eHori
?
280 style::GraphicLocation_LEFT_TOP
:
281 (style::GraphicLocation_MIDDLE_MIDDLE
==eHori
?
282 style::GraphicLocation_MIDDLE_TOP
:
283 style::GraphicLocation_RIGHT_TOP
);
286 case style::GraphicLocation_LEFT_MIDDLE
:
287 case style::GraphicLocation_MIDDLE_MIDDLE
:
288 case style::GraphicLocation_RIGHT_MIDDLE
:
292 case style::GraphicLocation_LEFT_BOTTOM
:
293 case style::GraphicLocation_MIDDLE_BOTTOM
:
294 case style::GraphicLocation_RIGHT_BOTTOM
:
295 ePos
= style::GraphicLocation_LEFT_MIDDLE
==eHori
?
296 style::GraphicLocation_LEFT_BOTTOM
:
297 (style::GraphicLocation_MIDDLE_MIDDLE
==eHori
?
298 style::GraphicLocation_MIDDLE_BOTTOM
:
299 style::GraphicLocation_RIGHT_BOTTOM
);