1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tools/debug.hxx>
21 #include <backhdl.hxx>
22 #include <xmloff/xmltoken.hxx>
23 #include <xmloff/xmluconv.hxx>
24 #include <sax/tools/converter.hxx>
25 #include <com/sun/star/uno/Any.hxx>
26 #include <rtl/ustrbuf.hxx>
29 using namespace ::com::sun::star
;
30 using namespace ::xmloff::token
;
32 SvXMLEnumMapEntry pXML_BrushHorizontalPos
[] =
34 { XML_LEFT
, style::GraphicLocation_LEFT_MIDDLE
},
35 { XML_RIGHT
, style::GraphicLocation_RIGHT_MIDDLE
},
36 { XML_TOKEN_INVALID
, 0 }
39 SvXMLEnumMapEntry pXML_BrushVerticalPos
[] =
41 { XML_TOP
, style::GraphicLocation_MIDDLE_TOP
},
42 { XML_BOTTOM
, style::GraphicLocation_MIDDLE_BOTTOM
},
43 { XML_TOKEN_INVALID
, 0 }
46 ///////////////////////////////////////////////////////////////////////////////
48 // class XMLBackGraphicPositionPropHdl
51 XMLBackGraphicPositionPropHdl::~XMLBackGraphicPositionPropHdl()
56 sal_Bool
XMLBackGraphicPositionPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
58 sal_Bool bRet
= sal_True
;
59 style::GraphicLocation ePos
= style::GraphicLocation_NONE
, eTmp
;
61 SvXMLTokenEnumerator
aTokenEnum( rStrImpValue
);
63 sal_Bool bHori
= sal_False
, bVert
= sal_False
;
65 while( bRet
&& aTokenEnum
.getNextToken( aToken
) )
71 else if( -1 != aToken
.indexOf( sal_Unicode('%') ) )
74 if (::sax::Converter::convertPercent( nPrc
, aToken
))
78 ePos
= nPrc
< 25 ? style::GraphicLocation_LEFT_TOP
:
79 (nPrc
< 75 ? style::GraphicLocation_MIDDLE_MIDDLE
:
80 style::GraphicLocation_RIGHT_BOTTOM
);
85 eTmp
= nPrc
< 25 ? style::GraphicLocation_LEFT_TOP
:
86 (nPrc
< 75 ? style::GraphicLocation_LEFT_MIDDLE
:
87 style::GraphicLocation_LEFT_BOTTOM
);
88 MergeXMLVertPos( ePos
, eTmp
);
98 else if( IsXMLToken( aToken
, XML_CENTER
) )
101 MergeXMLVertPos( ePos
, style::GraphicLocation_MIDDLE_MIDDLE
);
103 MergeXMLHoriPos( ePos
, style::GraphicLocation_MIDDLE_MIDDLE
);
105 ePos
= style::GraphicLocation_MIDDLE_MIDDLE
;
107 else if( SvXMLUnitConverter::convertEnum( nTmp
, aToken
, pXML_BrushHorizontalPos
) )
110 MergeXMLHoriPos( ePos
, (style::GraphicLocation
)nTmp
);
112 ePos
= (style::GraphicLocation
)nTmp
;
118 else if( SvXMLUnitConverter::convertEnum( nTmp
, aToken
, pXML_BrushVerticalPos
) )
121 MergeXMLVertPos( ePos
, (style::GraphicLocation
)nTmp
);
123 ePos
= (style::GraphicLocation
)nTmp
;
134 bRet
&= style::GraphicLocation_NONE
!= ePos
;
136 rValue
<<= (style::GraphicLocation
)(sal_uInt16
)ePos
;
141 sal_Bool
XMLBackGraphicPositionPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
143 sal_Bool bRet
= sal_True
;
146 style::GraphicLocation eLocation
;
147 if( !( rValue
>>= eLocation
) )
149 sal_Int32 nValue
= 0;
150 if( rValue
>>= nValue
)
151 eLocation
= (style::GraphicLocation
)nValue
;
162 case style::GraphicLocation_LEFT_TOP
:
163 case style::GraphicLocation_MIDDLE_TOP
:
164 case style::GraphicLocation_RIGHT_TOP
:
165 aOut
.append( GetXMLToken(XML_TOP
) );
168 case style::GraphicLocation_LEFT_MIDDLE
:
169 case style::GraphicLocation_MIDDLE_MIDDLE
:
170 case style::GraphicLocation_RIGHT_MIDDLE
:
171 aOut
.append( GetXMLToken(XML_CENTER
) );
174 case style::GraphicLocation_LEFT_BOTTOM
:
175 case style::GraphicLocation_MIDDLE_BOTTOM
:
176 case style::GraphicLocation_RIGHT_BOTTOM
:
177 aOut
.append( GetXMLToken(XML_BOTTOM
) );
186 aOut
.append( sal_Unicode( ' ' ) );
190 case style::GraphicLocation_LEFT_TOP
:
191 case style::GraphicLocation_LEFT_BOTTOM
:
192 case style::GraphicLocation_LEFT_MIDDLE
:
193 aOut
.append( GetXMLToken(XML_LEFT
) );
195 case style::GraphicLocation_MIDDLE_TOP
:
196 case style::GraphicLocation_MIDDLE_MIDDLE
:
197 case style::GraphicLocation_MIDDLE_BOTTOM
:
198 aOut
.append( GetXMLToken(XML_CENTER
) );
200 case style::GraphicLocation_RIGHT_MIDDLE
:
201 case style::GraphicLocation_RIGHT_TOP
:
202 case style::GraphicLocation_RIGHT_BOTTOM
:
203 aOut
.append( GetXMLToken(XML_RIGHT
) );
211 rStrExpValue
= aOut
.makeStringAndClear();
216 void XMLBackGraphicPositionPropHdl::MergeXMLVertPos( style::GraphicLocation
& ePos
, style::GraphicLocation eVert
) const
220 case style::GraphicLocation_LEFT_TOP
:
221 case style::GraphicLocation_LEFT_MIDDLE
:
222 case style::GraphicLocation_LEFT_BOTTOM
:
223 ePos
= style::GraphicLocation_MIDDLE_TOP
==eVert
?
224 style::GraphicLocation_LEFT_TOP
:
225 (style::GraphicLocation_MIDDLE_MIDDLE
==eVert
?
226 style::GraphicLocation_LEFT_MIDDLE
:
227 style::GraphicLocation_LEFT_BOTTOM
);
230 case style::GraphicLocation_MIDDLE_TOP
:
231 case style::GraphicLocation_MIDDLE_MIDDLE
:
232 case style::GraphicLocation_MIDDLE_BOTTOM
:
236 case style::GraphicLocation_RIGHT_TOP
:
237 case style::GraphicLocation_RIGHT_MIDDLE
:
238 case style::GraphicLocation_RIGHT_BOTTOM
:
239 ePos
= style::GraphicLocation_MIDDLE_TOP
==eVert
?
240 style::GraphicLocation_RIGHT_TOP
:
241 (style::GraphicLocation_MIDDLE_MIDDLE
==eVert
?
242 style::GraphicLocation_RIGHT_MIDDLE
:
243 style::GraphicLocation_RIGHT_BOTTOM
);
250 void XMLBackGraphicPositionPropHdl::MergeXMLHoriPos( style::GraphicLocation
& ePos
, style::GraphicLocation eHori
) const
252 DBG_ASSERT( style::GraphicLocation_LEFT_MIDDLE
==eHori
|| style::GraphicLocation_MIDDLE_MIDDLE
==eHori
|| style::GraphicLocation_RIGHT_MIDDLE
==eHori
,
253 "lcl_frmitems_MergeXMLHoriPos: vertical pos must be middle" );
257 case style::GraphicLocation_LEFT_TOP
:
258 case style::GraphicLocation_MIDDLE_TOP
:
259 case style::GraphicLocation_RIGHT_TOP
:
260 ePos
= style::GraphicLocation_LEFT_MIDDLE
==eHori
?
261 style::GraphicLocation_LEFT_TOP
:
262 (style::GraphicLocation_MIDDLE_MIDDLE
==eHori
?
263 style::GraphicLocation_MIDDLE_TOP
:
264 style::GraphicLocation_RIGHT_TOP
);
267 case style::GraphicLocation_LEFT_MIDDLE
:
268 case style::GraphicLocation_MIDDLE_MIDDLE
:
269 case style::GraphicLocation_RIGHT_MIDDLE
:
273 case style::GraphicLocation_LEFT_BOTTOM
:
274 case style::GraphicLocation_MIDDLE_BOTTOM
:
275 case style::GraphicLocation_RIGHT_BOTTOM
:
276 ePos
= style::GraphicLocation_LEFT_MIDDLE
==eHori
?
277 style::GraphicLocation_LEFT_BOTTOM
:
278 (style::GraphicLocation_MIDDLE_MIDDLE
==eHori
?
279 style::GraphicLocation_MIDDLE_BOTTOM
:
280 style::GraphicLocation_RIGHT_BOTTOM
);
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */