lok: Don't attempt to select the exact text after a failed search.
[LibreOffice.git] / xmloff / source / style / shadwhdl.cxx
blob139e60835b9061a63729e7ec83e329550fd56636
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>
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>
31 using namespace ::com::sun::star;
32 using namespace ::xmloff::token;
35 // class XMLMeasurePropHdl
38 XMLShadowPropHdl::~XMLShadowPropHdl()
40 // nothing to do
43 bool XMLShadowPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
45 bool bRet = false;
46 table::ShadowFormat aShadow;
47 aShadow.Location = table::ShadowLocation_BOTTOM_RIGHT;
49 bool bColorFound = false;
50 bool bOffsetFound = false;
51 SvXMLTokenEnumerator aTokenEnum( rStrImpValue );
52 Color aColor( 128,128, 128 );
53 OUString aToken;
55 while( aTokenEnum.getNextToken( aToken ) )
57 if( IsXMLToken( aToken, XML_NONE ) )
59 aShadow.Location = table::ShadowLocation_NONE;
60 bRet = true;
61 break;
63 else if( !bColorFound && aToken.startsWith("#") )
65 sal_Int32 nColor(0);
66 bRet = ::sax::Converter::convertColor( nColor, aToken );
67 if( !bRet )
68 return false;
70 aColor.SetColor(nColor);
71 bColorFound = true;
73 else if( !bOffsetFound )
75 sal_Int32 nX = 0, nY = 0;
77 bRet = rUnitConverter.convertMeasureToCore( nX, aToken );
78 if( bRet && aTokenEnum.getNextToken( aToken ) )
79 bRet = rUnitConverter.convertMeasureToCore( nY, aToken );
81 if( bRet )
83 if( nX < 0 )
85 if( nY < 0 )
86 aShadow.Location = table::ShadowLocation_TOP_LEFT;
87 else
88 aShadow.Location = table::ShadowLocation_BOTTOM_LEFT;
90 else
92 if( nY < 0 )
93 aShadow.Location = table::ShadowLocation_TOP_RIGHT;
94 else
95 aShadow.Location = table::ShadowLocation_BOTTOM_RIGHT;
98 if( nX < 0 ) nX *= -1;
99 if( nY < 0 ) nY *= -1;
101 aShadow.ShadowWidth = sal::static_int_cast< sal_Int16 >(
102 (nX + nY) >> 1);
107 if( bRet && ( bColorFound || bOffsetFound ) )
109 aShadow.IsTransparent = aColor.GetTransparency() > 0;
110 aShadow.Color = aColor.GetColor();
111 bRet = true;
114 rValue <<= aShadow;
116 return bRet;
119 bool XMLShadowPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
121 bool bRet = false;
122 OUStringBuffer aOut;
123 table::ShadowFormat aShadow;
125 if( rValue >>= aShadow )
127 sal_Int32 nX = 1, nY = 1;
129 switch( aShadow.Location )
131 case table::ShadowLocation_TOP_LEFT:
132 nX = -1;
133 nY = -1;
134 break;
135 case table::ShadowLocation_TOP_RIGHT:
136 nY = -1;
137 break;
138 case table::ShadowLocation_BOTTOM_LEFT:
139 nX = -1;
140 break;
141 case table::ShadowLocation_BOTTOM_RIGHT:
142 break;
143 case table::ShadowLocation_NONE:
144 default:
145 rStrExpValue = GetXMLToken(XML_NONE);
146 return true;
149 nX *= aShadow.ShadowWidth;
150 nY *= aShadow.ShadowWidth;
152 ::sax::Converter::convertColor( aOut, aShadow.Color );
154 aOut.append( ' ' );
155 rUnitConverter.convertMeasureToXML( aOut, nX );
156 aOut.append( ' ' );
157 rUnitConverter.convertMeasureToXML( aOut, nY );
159 rStrExpValue = aOut.makeStringAndClear();
161 bRet = true;
164 return bRet;
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */