nss: upgrade to release 3.73
[LibreOffice.git] / xmloff / source / style / backhdl.cxx
blob63c74306104a506bfcbc28d32d4c5f6aaace9fd0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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()
51 // Nothing to do
54 bool XMLBackGraphicPositionPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
56 bool bRet = true;
57 style::GraphicLocation ePos = style::GraphicLocation_NONE, eTmp;
58 style::GraphicLocation nTmpGraphicLocation;
59 SvXMLTokenEnumerator aTokenEnum( rStrImpValue );
60 OUString aToken;
61 bool bHori = false, bVert = false;
63 while( bRet && aTokenEnum.getNextToken( aToken ) )
65 if( bHori && bVert )
67 bRet = false;
69 else if( -1 != aToken.indexOf( '%' ) )
71 sal_Int32 nPrc = 50;
72 if (::sax::Converter::convertPercent( nPrc, aToken ))
74 if( !bHori )
76 ePos = nPrc < 25 ? style::GraphicLocation_LEFT_TOP :
77 (nPrc < 75 ? style::GraphicLocation_MIDDLE_MIDDLE :
78 style::GraphicLocation_RIGHT_BOTTOM);
79 bHori = true;
81 else
83 eTmp = nPrc < 25 ? style::GraphicLocation_LEFT_TOP:
84 (nPrc < 75 ? style::GraphicLocation_LEFT_MIDDLE :
85 style::GraphicLocation_LEFT_BOTTOM);
86 MergeXMLVertPos( ePos, eTmp );
87 bVert = true;
90 else
92 // wrong percentage
93 bRet = false;
96 else if( IsXMLToken( aToken, XML_CENTER ) )
98 if( bHori )
99 MergeXMLVertPos( ePos, style::GraphicLocation_MIDDLE_MIDDLE );
100 else if ( bVert )
101 MergeXMLHoriPos( ePos, style::GraphicLocation_MIDDLE_MIDDLE );
102 else
103 ePos = style::GraphicLocation_MIDDLE_MIDDLE;
105 else if( SvXMLUnitConverter::convertEnum( nTmpGraphicLocation, aToken, pXML_BrushHorizontalPos ) )
107 if( bVert )
108 MergeXMLHoriPos( ePos, nTmpGraphicLocation );
109 else if( !bHori )
110 ePos = nTmpGraphicLocation;
111 else
112 bRet = false;
114 bHori = true;
116 else if( SvXMLUnitConverter::convertEnum( nTmpGraphicLocation, aToken, pXML_BrushVerticalPos ) )
118 if( bHori )
119 MergeXMLVertPos( ePos, nTmpGraphicLocation );
120 else if( !bVert )
121 ePos = nTmpGraphicLocation;
122 else
123 bRet = false;
124 bVert = true;
126 else
128 bRet = false;
132 bRet &= style::GraphicLocation_NONE != ePos;
133 if( bRet )
134 rValue <<= static_cast<style::GraphicLocation>(static_cast<sal_uInt16>(ePos));
136 return bRet;
139 bool XMLBackGraphicPositionPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
141 bool bRet = true;
142 OUStringBuffer aOut;
144 style::GraphicLocation eLocation;
145 if( !( rValue >>= eLocation ) )
147 sal_Int32 nValue = 0;
148 if( rValue >>= nValue )
149 eLocation = static_cast<style::GraphicLocation>(nValue);
150 else
151 bRet = false;
154 if( bRet )
156 bRet = false;
158 switch( eLocation )
160 case style::GraphicLocation_LEFT_TOP:
161 case style::GraphicLocation_MIDDLE_TOP:
162 case style::GraphicLocation_RIGHT_TOP:
163 aOut.append( GetXMLToken(XML_TOP) );
164 bRet = true;
165 break;
166 case style::GraphicLocation_LEFT_MIDDLE:
167 case style::GraphicLocation_MIDDLE_MIDDLE:
168 case style::GraphicLocation_RIGHT_MIDDLE:
169 aOut.append( GetXMLToken(XML_CENTER) );
170 bRet = true;
171 break;
172 case style::GraphicLocation_LEFT_BOTTOM:
173 case style::GraphicLocation_MIDDLE_BOTTOM:
174 case style::GraphicLocation_RIGHT_BOTTOM:
175 aOut.append( GetXMLToken(XML_BOTTOM) );
176 bRet = true;
177 break;
178 default:
179 break;
182 if( bRet )
184 aOut.append( ' ' );
186 switch( eLocation )
188 case style::GraphicLocation_LEFT_TOP:
189 case style::GraphicLocation_LEFT_BOTTOM:
190 case style::GraphicLocation_LEFT_MIDDLE:
191 aOut.append( GetXMLToken(XML_LEFT) );
192 break;
193 case style::GraphicLocation_MIDDLE_TOP:
194 case style::GraphicLocation_MIDDLE_MIDDLE:
195 case style::GraphicLocation_MIDDLE_BOTTOM:
196 aOut.append( GetXMLToken(XML_CENTER) );
197 break;
198 case style::GraphicLocation_RIGHT_MIDDLE:
199 case style::GraphicLocation_RIGHT_TOP:
200 case style::GraphicLocation_RIGHT_BOTTOM:
201 aOut.append( GetXMLToken(XML_RIGHT) );
202 break;
203 default:
204 break;
209 rStrExpValue = aOut.makeStringAndClear();
211 return bRet;
214 void XMLBackGraphicPositionPropHdl::MergeXMLVertPos( style::GraphicLocation& ePos, style::GraphicLocation eVert )
216 switch( ePos )
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);
226 break;
228 case style::GraphicLocation_MIDDLE_TOP:
229 case style::GraphicLocation_MIDDLE_MIDDLE:
230 case style::GraphicLocation_MIDDLE_BOTTOM:
231 ePos = eVert;
232 break;
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);
242 break;
243 default:
244 break;
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" );
253 switch( ePos )
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);
263 break;
265 case style::GraphicLocation_LEFT_MIDDLE:
266 case style::GraphicLocation_MIDDLE_MIDDLE:
267 case style::GraphicLocation_RIGHT_MIDDLE:
268 ePos = eHori;
269 break;
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);
279 break;
280 default:
281 break;
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */