fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / xmloff / source / style / shadwhdl.cxx
blob596694793860dd84b3a0cd77418d537ab7507a3a
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 "shadwhdl.hxx"
21 #include <com/sun/star/uno/Any.hxx>
22 #include <rtl/ustrbuf.hxx>
24 // --
25 #include <com/sun/star/table/ShadowFormat.hpp>
26 #include <tools/color.hxx>
27 #include <sax/tools/converter.hxx>
28 #include <xmloff/xmluconv.hxx>
29 #include <xmloff/xmltoken.hxx>
32 using namespace ::com::sun::star;
33 using namespace ::xmloff::token;
35 ///////////////////////////////////////////////////////////////////////////////
37 // class XMLMeasurePropHdl
40 XMLShadowPropHdl::~XMLShadowPropHdl()
42 // nothing to do
45 sal_Bool XMLShadowPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
47 sal_Bool bRet = sal_False;
48 table::ShadowFormat aShadow;
49 aShadow.Location = table::ShadowLocation_BOTTOM_RIGHT;
51 sal_Bool bColorFound = sal_False;
52 sal_Bool bOffsetFound = sal_False;
53 SvXMLTokenEnumerator aTokenEnum( rStrImpValue );
54 Color aColor( 128,128, 128 );
55 OUString aToken;
57 while( aTokenEnum.getNextToken( aToken ) )
59 if( IsXMLToken( aToken, XML_NONE ) )
61 aShadow.Location = table::ShadowLocation_NONE;
62 bRet = sal_True;
63 break;
65 else if( !bColorFound && aToken.startsWith("#") )
67 sal_Int32 nColor(0);
68 bRet = ::sax::Converter::convertColor( nColor, aToken );
69 if( !bRet )
70 return sal_False;
72 aColor.SetColor(nColor);
73 bColorFound = sal_True;
75 else if( !bOffsetFound )
77 sal_Int32 nX = 0, nY = 0;
79 bRet = rUnitConverter.convertMeasureToCore( nX, aToken );
80 if( bRet && aTokenEnum.getNextToken( aToken ) )
81 bRet = rUnitConverter.convertMeasureToCore( nY, aToken );
83 if( bRet )
85 if( nX < 0 )
87 if( nY < 0 )
88 aShadow.Location = table::ShadowLocation_TOP_LEFT;
89 else
90 aShadow.Location = table::ShadowLocation_BOTTOM_LEFT;
92 else
94 if( nY < 0 )
95 aShadow.Location = table::ShadowLocation_TOP_RIGHT;
96 else
97 aShadow.Location = table::ShadowLocation_BOTTOM_RIGHT;
100 if( nX < 0 ) nX *= -1;
101 if( nY < 0 ) nY *= -1;
103 aShadow.ShadowWidth = sal::static_int_cast< sal_Int16 >(
104 (nX + nY) >> 1);
109 if( bRet && ( bColorFound || bOffsetFound ) )
111 aShadow.IsTransparent = aColor.GetTransparency() > 0;
112 aShadow.Color = aColor.GetColor();
113 bRet = sal_True;
116 rValue <<= aShadow;
118 return bRet;
121 sal_Bool XMLShadowPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
123 sal_Bool bRet = sal_False;
124 OUStringBuffer aOut;
125 table::ShadowFormat aShadow;
127 if( rValue >>= aShadow )
129 sal_Int32 nX = 1, nY = 1;
131 switch( aShadow.Location )
133 case table::ShadowLocation_TOP_LEFT:
134 nX = -1;
135 nY = -1;
136 break;
137 case table::ShadowLocation_TOP_RIGHT:
138 nY = -1;
139 break;
140 case table::ShadowLocation_BOTTOM_LEFT:
141 nX = -1;
142 break;
143 case table::ShadowLocation_BOTTOM_RIGHT:
144 break;
145 case table::ShadowLocation_NONE:
146 default:
147 rStrExpValue = GetXMLToken(XML_NONE);
148 return sal_True;
151 nX *= aShadow.ShadowWidth;
152 nY *= aShadow.ShadowWidth;
154 ::sax::Converter::convertColor( aOut, aShadow.Color );
156 aOut.append( sal_Unicode(' ') );
157 rUnitConverter.convertMeasureToXML( aOut, nX );
158 aOut.append( sal_Unicode(' ') );
159 rUnitConverter.convertMeasureToXML( aOut, nY );
161 rStrExpValue = aOut.makeStringAndClear();
163 bRet = sal_True;
166 return bRet;
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */