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 "backhdl.hxx"
21 #include <xmloff/xmltoken.hxx>
22 #include <xmloff/xmluconv.hxx>
23 #include <xmloff/xmlement.hxx>
24 #include <sax/tools/converter.hxx>
25 #include <com/sun/star/uno/Any.hxx>
26 #include <rtl/ustrbuf.hxx>
27 #include <sal/log.hxx>
29 using namespace ::com::sun::star
;
30 using namespace ::xmloff::token
;
32 SvXMLEnumMapEntry
<style::GraphicLocation
> const pXML_BrushHorizontalPos
[] =
34 { XML_LEFT
, style::GraphicLocation_LEFT_MIDDLE
},
35 { XML_RIGHT
, style::GraphicLocation_RIGHT_MIDDLE
},
36 { XML_TOKEN_INVALID
, style::GraphicLocation(0) }
39 SvXMLEnumMapEntry
<style::GraphicLocation
> const pXML_BrushVerticalPos
[] =
41 { XML_TOP
, style::GraphicLocation_MIDDLE_TOP
},
42 { XML_BOTTOM
, style::GraphicLocation_MIDDLE_BOTTOM
},
43 { XML_TOKEN_INVALID
, style::GraphicLocation(0) }
49 XMLBackGraphicPositionPropHdl::~XMLBackGraphicPositionPropHdl()
54 bool XMLBackGraphicPositionPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
57 style::GraphicLocation ePos
= style::GraphicLocation_NONE
, eTmp
;
58 style::GraphicLocation nTmpGraphicLocation
;
59 SvXMLTokenEnumerator
aTokenEnum( rStrImpValue
);
61 bool bHori
= false, bVert
= false;
63 while( bRet
&& aTokenEnum
.getNextToken( aToken
) )
69 else if( -1 != aToken
.indexOf( '%' ) )
72 if (::sax::Converter::convertPercent( nPrc
, aToken
))
76 ePos
= nPrc
< 25 ? style::GraphicLocation_LEFT_TOP
:
77 (nPrc
< 75 ? style::GraphicLocation_MIDDLE_MIDDLE
:
78 style::GraphicLocation_RIGHT_BOTTOM
);
83 eTmp
= nPrc
< 25 ? style::GraphicLocation_LEFT_TOP
:
84 (nPrc
< 75 ? style::GraphicLocation_LEFT_MIDDLE
:
85 style::GraphicLocation_LEFT_BOTTOM
);
86 MergeXMLVertPos( ePos
, eTmp
);
96 else if( IsXMLToken( aToken
, XML_CENTER
) )
99 MergeXMLVertPos( ePos
, style::GraphicLocation_MIDDLE_MIDDLE
);
101 MergeXMLHoriPos( ePos
, style::GraphicLocation_MIDDLE_MIDDLE
);
103 ePos
= style::GraphicLocation_MIDDLE_MIDDLE
;
105 else if( SvXMLUnitConverter::convertEnum( nTmpGraphicLocation
, aToken
, pXML_BrushHorizontalPos
) )
108 MergeXMLHoriPos( ePos
, nTmpGraphicLocation
);
110 ePos
= nTmpGraphicLocation
;
116 else if( SvXMLUnitConverter::convertEnum( nTmpGraphicLocation
, aToken
, pXML_BrushVerticalPos
) )
119 MergeXMLVertPos( ePos
, nTmpGraphicLocation
);
121 ePos
= nTmpGraphicLocation
;
132 bRet
&= style::GraphicLocation_NONE
!= ePos
;
134 rValue
<<= static_cast<style::GraphicLocation
>(static_cast<sal_uInt16
>(ePos
));
139 bool XMLBackGraphicPositionPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
144 style::GraphicLocation eLocation
;
145 if( !( rValue
>>= eLocation
) )
147 sal_Int32 nValue
= 0;
148 if( rValue
>>= nValue
)
149 eLocation
= static_cast<style::GraphicLocation
>(nValue
);
160 case style::GraphicLocation_LEFT_TOP
:
161 case style::GraphicLocation_MIDDLE_TOP
:
162 case style::GraphicLocation_RIGHT_TOP
:
163 aOut
.append( GetXMLToken(XML_TOP
) );
166 case style::GraphicLocation_LEFT_MIDDLE
:
167 case style::GraphicLocation_MIDDLE_MIDDLE
:
168 case style::GraphicLocation_RIGHT_MIDDLE
:
169 aOut
.append( GetXMLToken(XML_CENTER
) );
172 case style::GraphicLocation_LEFT_BOTTOM
:
173 case style::GraphicLocation_MIDDLE_BOTTOM
:
174 case style::GraphicLocation_RIGHT_BOTTOM
:
175 aOut
.append( GetXMLToken(XML_BOTTOM
) );
188 case style::GraphicLocation_LEFT_TOP
:
189 case style::GraphicLocation_LEFT_BOTTOM
:
190 case style::GraphicLocation_LEFT_MIDDLE
:
191 aOut
.append( GetXMLToken(XML_LEFT
) );
193 case style::GraphicLocation_MIDDLE_TOP
:
194 case style::GraphicLocation_MIDDLE_MIDDLE
:
195 case style::GraphicLocation_MIDDLE_BOTTOM
:
196 aOut
.append( GetXMLToken(XML_CENTER
) );
198 case style::GraphicLocation_RIGHT_MIDDLE
:
199 case style::GraphicLocation_RIGHT_TOP
:
200 case style::GraphicLocation_RIGHT_BOTTOM
:
201 aOut
.append( GetXMLToken(XML_RIGHT
) );
209 rStrExpValue
= aOut
.makeStringAndClear();
214 void XMLBackGraphicPositionPropHdl::MergeXMLVertPos( style::GraphicLocation
& ePos
, style::GraphicLocation eVert
)
218 case style::GraphicLocation_LEFT_TOP
:
219 case style::GraphicLocation_LEFT_MIDDLE
:
220 case style::GraphicLocation_LEFT_BOTTOM
:
221 ePos
= style::GraphicLocation_MIDDLE_TOP
==eVert
?
222 style::GraphicLocation_LEFT_TOP
:
223 (style::GraphicLocation_MIDDLE_MIDDLE
==eVert
?
224 style::GraphicLocation_LEFT_MIDDLE
:
225 style::GraphicLocation_LEFT_BOTTOM
);
228 case style::GraphicLocation_MIDDLE_TOP
:
229 case style::GraphicLocation_MIDDLE_MIDDLE
:
230 case style::GraphicLocation_MIDDLE_BOTTOM
:
234 case style::GraphicLocation_RIGHT_TOP
:
235 case style::GraphicLocation_RIGHT_MIDDLE
:
236 case style::GraphicLocation_RIGHT_BOTTOM
:
237 ePos
= style::GraphicLocation_MIDDLE_TOP
==eVert
?
238 style::GraphicLocation_RIGHT_TOP
:
239 (style::GraphicLocation_MIDDLE_MIDDLE
==eVert
?
240 style::GraphicLocation_RIGHT_MIDDLE
:
241 style::GraphicLocation_RIGHT_BOTTOM
);
248 void XMLBackGraphicPositionPropHdl::MergeXMLHoriPos( style::GraphicLocation
& ePos
, style::GraphicLocation eHori
)
250 SAL_WARN_IF( !(style::GraphicLocation_LEFT_MIDDLE
==eHori
|| style::GraphicLocation_MIDDLE_MIDDLE
==eHori
|| style::GraphicLocation_RIGHT_MIDDLE
==eHori
), "xmloff",
251 "lcl_frmitems_MergeXMLHoriPos: vertical pos must be middle" );
255 case style::GraphicLocation_LEFT_TOP
:
256 case style::GraphicLocation_MIDDLE_TOP
:
257 case style::GraphicLocation_RIGHT_TOP
:
258 ePos
= style::GraphicLocation_LEFT_MIDDLE
==eHori
?
259 style::GraphicLocation_LEFT_TOP
:
260 (style::GraphicLocation_MIDDLE_MIDDLE
==eHori
?
261 style::GraphicLocation_MIDDLE_TOP
:
262 style::GraphicLocation_RIGHT_TOP
);
265 case style::GraphicLocation_LEFT_MIDDLE
:
266 case style::GraphicLocation_MIDDLE_MIDDLE
:
267 case style::GraphicLocation_RIGHT_MIDDLE
:
271 case style::GraphicLocation_LEFT_BOTTOM
:
272 case style::GraphicLocation_MIDDLE_BOTTOM
:
273 case style::GraphicLocation_RIGHT_BOTTOM
:
274 ePos
= style::GraphicLocation_LEFT_MIDDLE
==eHori
?
275 style::GraphicLocation_LEFT_BOTTOM
:
276 (style::GraphicLocation_MIDDLE_MIDDLE
==eHori
?
277 style::GraphicLocation_MIDDLE_BOTTOM
:
278 style::GraphicLocation_RIGHT_BOTTOM
);
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */