2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-12 17:21:24 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
#include "shadwhdl.hxx"
|
|
|
|
#include <com/sun/star/uno/Any.hxx>
|
|
|
|
#include <rtl/ustrbuf.hxx>
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
#include <com/sun/star/table/ShadowFormat.hpp>
|
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
|
|
|
#include <tools/color.hxx>
|
|
|
|
#include <sax/tools/converter.hxx>
|
2007-06-27 14:43:27 +00:00
|
|
|
#include <xmloff/xmluconv.hxx>
|
|
|
|
#include <xmloff/xmltoken.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
2001-06-29 20:07:26 +00:00
|
|
|
using namespace ::xmloff::token;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2014-02-25 23:15:32 +01:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
// class XMLMeasurePropHdl
|
2014-02-25 23:15:32 +01:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
XMLShadowPropHdl::~XMLShadowPropHdl()
|
|
|
|
{
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
|
2013-09-16 15:06:48 +02:00
|
|
|
bool XMLShadowPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2013-09-16 15:06:48 +02:00
|
|
|
bool bRet = false;
|
2000-09-18 16:07:07 +00:00
|
|
|
table::ShadowFormat aShadow;
|
|
|
|
aShadow.Location = table::ShadowLocation_BOTTOM_RIGHT;
|
|
|
|
|
2013-09-16 15:06:48 +02:00
|
|
|
bool bColorFound = false;
|
|
|
|
bool bOffsetFound = false;
|
2000-09-18 16:07:07 +00:00
|
|
|
SvXMLTokenEnumerator aTokenEnum( rStrImpValue );
|
|
|
|
Color aColor( 128,128, 128 );
|
|
|
|
OUString aToken;
|
|
|
|
|
|
|
|
while( aTokenEnum.getNextToken( aToken ) )
|
|
|
|
{
|
2001-06-29 20:07:26 +00:00
|
|
|
if( IsXMLToken( aToken, XML_NONE ) )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
aShadow.Location = table::ShadowLocation_NONE;
|
2013-09-16 15:06:48 +02:00
|
|
|
bRet = true;
|
2000-09-18 16:07:07 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-03-09 22:47:20 +01:00
|
|
|
else if( !bColorFound && aToken.startsWith("#") )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
|
|
|
sal_Int32 nColor(0);
|
|
|
|
bRet = ::sax::Converter::convertColor( nColor, aToken );
|
2000-09-18 16:07:07 +00:00
|
|
|
if( !bRet )
|
2013-09-16 15:06:48 +02:00
|
|
|
return false;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
|
|
|
aColor.SetColor(nColor);
|
2013-09-16 15:06:48 +02:00
|
|
|
bColorFound = true;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
else if( !bOffsetFound )
|
|
|
|
{
|
|
|
|
sal_Int32 nX = 0, nY = 0;
|
|
|
|
|
2011-10-11 14:19:09 +02:00
|
|
|
bRet = rUnitConverter.convertMeasureToCore( nX, aToken );
|
2000-09-18 16:07:07 +00:00
|
|
|
if( bRet && aTokenEnum.getNextToken( aToken ) )
|
2011-10-11 14:19:09 +02:00
|
|
|
bRet = rUnitConverter.convertMeasureToCore( nY, aToken );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
if( bRet )
|
|
|
|
{
|
|
|
|
if( nX < 0 )
|
|
|
|
{
|
|
|
|
if( nY < 0 )
|
|
|
|
aShadow.Location = table::ShadowLocation_TOP_LEFT;
|
|
|
|
else
|
|
|
|
aShadow.Location = table::ShadowLocation_BOTTOM_LEFT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( nY < 0 )
|
|
|
|
aShadow.Location = table::ShadowLocation_TOP_RIGHT;
|
|
|
|
else
|
|
|
|
aShadow.Location = table::ShadowLocation_BOTTOM_RIGHT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( nX < 0 ) nX *= -1;
|
|
|
|
if( nY < 0 ) nY *= -1;
|
|
|
|
|
2006-10-12 13:50:52 +00:00
|
|
|
aShadow.ShadowWidth = sal::static_int_cast< sal_Int16 >(
|
|
|
|
(nX + nY) >> 1);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( bRet && ( bColorFound || bOffsetFound ) )
|
|
|
|
{
|
|
|
|
aShadow.IsTransparent = aColor.GetTransparency() > 0;
|
|
|
|
aShadow.Color = aColor.GetColor();
|
2013-09-16 15:06:48 +02:00
|
|
|
bRet = true;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rValue <<= aShadow;
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2013-09-16 15:06:48 +02:00
|
|
|
bool XMLShadowPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2013-09-16 15:06:48 +02:00
|
|
|
bool bRet = false;
|
2000-09-18 16:07:07 +00:00
|
|
|
OUStringBuffer aOut;
|
|
|
|
table::ShadowFormat aShadow;
|
|
|
|
|
|
|
|
if( rValue >>= aShadow )
|
|
|
|
{
|
|
|
|
sal_Int32 nX = 1, nY = 1;
|
|
|
|
|
|
|
|
switch( aShadow.Location )
|
|
|
|
{
|
|
|
|
case table::ShadowLocation_TOP_LEFT:
|
|
|
|
nX = -1;
|
|
|
|
nY = -1;
|
|
|
|
break;
|
|
|
|
case table::ShadowLocation_TOP_RIGHT:
|
|
|
|
nY = -1;
|
|
|
|
break;
|
|
|
|
case table::ShadowLocation_BOTTOM_LEFT:
|
|
|
|
nX = -1;
|
|
|
|
break;
|
|
|
|
case table::ShadowLocation_BOTTOM_RIGHT:
|
|
|
|
break;
|
|
|
|
case table::ShadowLocation_NONE:
|
|
|
|
default:
|
2001-06-29 20:07:26 +00:00
|
|
|
rStrExpValue = GetXMLToken(XML_NONE);
|
2013-09-16 15:06:48 +02:00
|
|
|
return true;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nX *= aShadow.ShadowWidth;
|
|
|
|
nY *= aShadow.ShadowWidth;
|
|
|
|
|
#i108468#: clean up xmluconv code duplication, part 1:
move convertNumber64 from SvXMLUnitConverter to sax::converter.
remove duplicate methods from SvXMLUnitConverter:
convertBool, convertPercent, convertColor, convertNumber, convertDouble,
indexOfComma, encodeBase64, decodeBase64, decodeBase64SomeChars,
clearUndefinedChars
2011-10-11 14:19:00 +02:00
|
|
|
::sax::Converter::convertColor( aOut, aShadow.Color );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2013-11-13 12:10:31 +02:00
|
|
|
aOut.append( ' ' );
|
2011-10-11 14:19:09 +02:00
|
|
|
rUnitConverter.convertMeasureToXML( aOut, nX );
|
2013-11-13 12:10:31 +02:00
|
|
|
aOut.append( ' ' );
|
2011-10-11 14:19:09 +02:00
|
|
|
rUnitConverter.convertMeasureToXML( aOut, nY );
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
rStrExpValue = aOut.makeStringAndClear();
|
|
|
|
|
2013-09-16 15:06:48 +02:00
|
|
|
bRet = true;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
2010-10-12 15:53:47 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|