fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / xmloff / source / style / backhdl.cxx
blob53cc76470408781e6c35765c7afae88bbbc95341
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 <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()
53 // Nothing to do
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;
60 sal_uInt16 nTmp;
61 SvXMLTokenEnumerator aTokenEnum( rStrImpValue );
62 OUString aToken;
63 sal_Bool bHori = sal_False, bVert = sal_False;
65 while( bRet && aTokenEnum.getNextToken( aToken ) )
67 if( bHori && bVert )
69 bRet = sal_False;
71 else if( -1 != aToken.indexOf( sal_Unicode('%') ) )
73 sal_Int32 nPrc = 50;
74 if (::sax::Converter::convertPercent( nPrc, aToken ))
76 if( !bHori )
78 ePos = nPrc < 25 ? style::GraphicLocation_LEFT_TOP :
79 (nPrc < 75 ? style::GraphicLocation_MIDDLE_MIDDLE :
80 style::GraphicLocation_RIGHT_BOTTOM);
81 bHori = sal_True;
83 else
85 eTmp = nPrc < 25 ? style::GraphicLocation_LEFT_TOP:
86 (nPrc < 75 ? style::GraphicLocation_LEFT_MIDDLE :
87 style::GraphicLocation_LEFT_BOTTOM);
88 MergeXMLVertPos( ePos, eTmp );
89 bVert = sal_True;
92 else
94 // wrong percentage
95 bRet = sal_False;
98 else if( IsXMLToken( aToken, XML_CENTER ) )
100 if( bHori )
101 MergeXMLVertPos( ePos, style::GraphicLocation_MIDDLE_MIDDLE );
102 else if ( bVert )
103 MergeXMLHoriPos( ePos, style::GraphicLocation_MIDDLE_MIDDLE );
104 else
105 ePos = style::GraphicLocation_MIDDLE_MIDDLE;
107 else if( SvXMLUnitConverter::convertEnum( nTmp, aToken, pXML_BrushHorizontalPos ) )
109 if( bVert )
110 MergeXMLHoriPos( ePos, (style::GraphicLocation)nTmp );
111 else if( !bHori )
112 ePos = (style::GraphicLocation)nTmp;
113 else
114 bRet = sal_False;
116 bHori = sal_True;
118 else if( SvXMLUnitConverter::convertEnum( nTmp, aToken, pXML_BrushVerticalPos ) )
120 if( bHori )
121 MergeXMLVertPos( ePos, (style::GraphicLocation)nTmp );
122 else if( !bVert )
123 ePos = (style::GraphicLocation)nTmp;
124 else
125 bRet = sal_False;
126 bVert = sal_True;
128 else
130 bRet = sal_False;
134 bRet &= style::GraphicLocation_NONE != ePos;
135 if( bRet )
136 rValue <<= (style::GraphicLocation)(sal_uInt16)ePos;
138 return bRet;
141 sal_Bool XMLBackGraphicPositionPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
143 sal_Bool bRet = sal_True;
144 OUStringBuffer aOut;
146 style::GraphicLocation eLocation;
147 if( !( rValue >>= eLocation ) )
149 sal_Int32 nValue = 0;
150 if( rValue >>= nValue )
151 eLocation = (style::GraphicLocation)nValue;
152 else
153 bRet = sal_False;
156 if( bRet )
158 bRet = sal_False;
160 switch( eLocation )
162 case style::GraphicLocation_LEFT_TOP:
163 case style::GraphicLocation_MIDDLE_TOP:
164 case style::GraphicLocation_RIGHT_TOP:
165 aOut.append( GetXMLToken(XML_TOP) );
166 bRet = sal_True;
167 break;
168 case style::GraphicLocation_LEFT_MIDDLE:
169 case style::GraphicLocation_MIDDLE_MIDDLE:
170 case style::GraphicLocation_RIGHT_MIDDLE:
171 aOut.append( GetXMLToken(XML_CENTER) );
172 bRet = sal_True;
173 break;
174 case style::GraphicLocation_LEFT_BOTTOM:
175 case style::GraphicLocation_MIDDLE_BOTTOM:
176 case style::GraphicLocation_RIGHT_BOTTOM:
177 aOut.append( GetXMLToken(XML_BOTTOM) );
178 bRet = sal_True;
179 break;
180 default:
181 break;
184 if( bRet )
186 aOut.append( sal_Unicode( ' ' ) );
188 switch( eLocation )
190 case style::GraphicLocation_LEFT_TOP:
191 case style::GraphicLocation_LEFT_BOTTOM:
192 case style::GraphicLocation_LEFT_MIDDLE:
193 aOut.append( GetXMLToken(XML_LEFT) );
194 break;
195 case style::GraphicLocation_MIDDLE_TOP:
196 case style::GraphicLocation_MIDDLE_MIDDLE:
197 case style::GraphicLocation_MIDDLE_BOTTOM:
198 aOut.append( GetXMLToken(XML_CENTER) );
199 break;
200 case style::GraphicLocation_RIGHT_MIDDLE:
201 case style::GraphicLocation_RIGHT_TOP:
202 case style::GraphicLocation_RIGHT_BOTTOM:
203 aOut.append( GetXMLToken(XML_RIGHT) );
204 break;
205 default:
206 break;
211 rStrExpValue = aOut.makeStringAndClear();
213 return bRet;
216 void XMLBackGraphicPositionPropHdl::MergeXMLVertPos( style::GraphicLocation& ePos, style::GraphicLocation eVert ) const
218 switch( ePos )
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);
228 break;
230 case style::GraphicLocation_MIDDLE_TOP:
231 case style::GraphicLocation_MIDDLE_MIDDLE:
232 case style::GraphicLocation_MIDDLE_BOTTOM:
233 ePos = eVert;
234 break;
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);
244 break;
245 default:
246 break;
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" );
255 switch( ePos )
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);
265 break;
267 case style::GraphicLocation_LEFT_MIDDLE:
268 case style::GraphicLocation_MIDDLE_MIDDLE:
269 case style::GraphicLocation_RIGHT_MIDDLE:
270 ePos = eHori;
271 break;
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);
281 break;
282 default:
283 break;
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */