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 "shadwhdl.hxx"
21 #include <com/sun/star/uno/Any.hxx>
22 #include <rtl/ustrbuf.hxx>
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()
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 );
57 while( aTokenEnum
.getNextToken( aToken
) )
59 if( IsXMLToken( aToken
, XML_NONE
) )
61 aShadow
.Location
= table::ShadowLocation_NONE
;
65 else if( !bColorFound
&& aToken
.startsWith("#") )
68 bRet
= ::sax::Converter::convertColor( nColor
, aToken
);
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
);
88 aShadow
.Location
= table::ShadowLocation_TOP_LEFT
;
90 aShadow
.Location
= table::ShadowLocation_BOTTOM_LEFT
;
95 aShadow
.Location
= table::ShadowLocation_TOP_RIGHT
;
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
>(
109 if( bRet
&& ( bColorFound
|| bOffsetFound
) )
111 aShadow
.IsTransparent
= aColor
.GetTransparency() > 0;
112 aShadow
.Color
= aColor
.GetColor();
121 sal_Bool
XMLShadowPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& rUnitConverter
) const
123 sal_Bool bRet
= sal_False
;
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
:
137 case table::ShadowLocation_TOP_RIGHT
:
140 case table::ShadowLocation_BOTTOM_LEFT
:
143 case table::ShadowLocation_BOTTOM_RIGHT
:
145 case table::ShadowLocation_NONE
:
147 rStrExpValue
= GetXMLToken(XML_NONE
);
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();
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */