Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "shadwhdl.hxx"
30 : : #include <com/sun/star/uno/Any.hxx>
31 : : #include <rtl/ustrbuf.hxx>
32 : :
33 : : // --
34 : : #include <com/sun/star/table/ShadowFormat.hpp>
35 : : #include <tools/color.hxx>
36 : : #include <sax/tools/converter.hxx>
37 : : #include <xmloff/xmluconv.hxx>
38 : : #include <xmloff/xmltoken.hxx>
39 : :
40 : : using ::rtl::OUString;
41 : : using ::rtl::OUStringBuffer;
42 : :
43 : : using namespace ::com::sun::star;
44 : : using namespace ::xmloff::token;
45 : :
46 : : ///////////////////////////////////////////////////////////////////////////////
47 : : //
48 : : // class XMLMeasurePropHdl
49 : : //
50 : :
51 : 3071 : XMLShadowPropHdl::~XMLShadowPropHdl()
52 : : {
53 : : // nothing to do
54 [ - + ]: 6142 : }
55 : :
56 : 24 : sal_Bool XMLShadowPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
57 : : {
58 : 24 : sal_Bool bRet = sal_False;
59 : 24 : table::ShadowFormat aShadow;
60 : 24 : aShadow.Location = table::ShadowLocation_BOTTOM_RIGHT;
61 : :
62 : 24 : sal_Bool bColorFound = sal_False;
63 : 24 : sal_Bool bOffsetFound = sal_False;
64 [ + - ]: 24 : SvXMLTokenEnumerator aTokenEnum( rStrImpValue );
65 : 24 : Color aColor( 128,128, 128 );
66 : 24 : OUString aToken;
67 : :
68 [ + - ][ + - ]: 24 : while( aTokenEnum.getNextToken( aToken ) )
69 : : {
70 [ + - ][ + - ]: 24 : if( IsXMLToken( aToken, XML_NONE ) )
71 : : {
72 : 24 : aShadow.Location = table::ShadowLocation_NONE;
73 : 24 : bRet = sal_True;
74 : 24 : break;
75 : : }
76 [ # # ][ # # ]: 0 : else if( !bColorFound && aToken.compareToAscii( "#", 1 ) == 0 )
[ # # ]
77 : : {
78 : 0 : sal_Int32 nColor(0);
79 [ # # ]: 0 : bRet = ::sax::Converter::convertColor( nColor, aToken );
80 [ # # ]: 0 : if( !bRet )
81 : 0 : return sal_False;
82 : :
83 : 0 : aColor.SetColor(nColor);
84 : 0 : bColorFound = sal_True;
85 : : }
86 [ # # ]: 0 : else if( !bOffsetFound )
87 : : {
88 : 0 : sal_Int32 nX = 0, nY = 0;
89 : :
90 [ # # ]: 0 : bRet = rUnitConverter.convertMeasureToCore( nX, aToken );
91 [ # # ][ # # ]: 0 : if( bRet && aTokenEnum.getNextToken( aToken ) )
[ # # ][ # # ]
92 [ # # ]: 0 : bRet = rUnitConverter.convertMeasureToCore( nY, aToken );
93 : :
94 [ # # ]: 0 : if( bRet )
95 : : {
96 [ # # ]: 0 : if( nX < 0 )
97 : : {
98 [ # # ]: 0 : if( nY < 0 )
99 : 0 : aShadow.Location = table::ShadowLocation_TOP_LEFT;
100 : : else
101 : 0 : aShadow.Location = table::ShadowLocation_BOTTOM_LEFT;
102 : : }
103 : : else
104 : : {
105 [ # # ]: 0 : if( nY < 0 )
106 : 0 : aShadow.Location = table::ShadowLocation_TOP_RIGHT;
107 : : else
108 : 0 : aShadow.Location = table::ShadowLocation_BOTTOM_RIGHT;
109 : : }
110 : :
111 [ # # ]: 0 : if( nX < 0 ) nX *= -1;
112 [ # # ]: 0 : if( nY < 0 ) nY *= -1;
113 : :
114 : : aShadow.ShadowWidth = sal::static_int_cast< sal_Int16 >(
115 : 0 : (nX + nY) >> 1);
116 : : }
117 : : }
118 : : }
119 : :
120 [ + - ][ + - ]: 24 : if( bRet && ( bColorFound || bOffsetFound ) )
[ - + ]
121 : : {
122 : 0 : aShadow.IsTransparent = aColor.GetTransparency() > 0;
123 : 0 : aShadow.Color = aColor.GetColor();
124 : 0 : bRet = sal_True;
125 : : }
126 : :
127 [ + - ]: 24 : rValue <<= aShadow;
128 : :
129 : 24 : return bRet;
130 : : }
131 : :
132 : 0 : sal_Bool XMLShadowPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
133 : : {
134 : 0 : sal_Bool bRet = sal_False;
135 : 0 : OUStringBuffer aOut;
136 : 0 : table::ShadowFormat aShadow;
137 : :
138 [ # # ][ # # ]: 0 : if( rValue >>= aShadow )
139 : : {
140 : 0 : sal_Int32 nX = 1, nY = 1;
141 : :
142 [ # # # # : 0 : switch( aShadow.Location )
# ]
143 : : {
144 : : case table::ShadowLocation_TOP_LEFT:
145 : 0 : nX = -1;
146 : 0 : nY = -1;
147 : 0 : break;
148 : : case table::ShadowLocation_TOP_RIGHT:
149 : 0 : nY = -1;
150 : 0 : break;
151 : : case table::ShadowLocation_BOTTOM_LEFT:
152 : 0 : nX = -1;
153 : 0 : break;
154 : : case table::ShadowLocation_BOTTOM_RIGHT:
155 : 0 : break;
156 : : case table::ShadowLocation_NONE:
157 : : default:
158 [ # # ]: 0 : rStrExpValue = GetXMLToken(XML_NONE);
159 : 0 : return sal_True;
160 : : }
161 : :
162 : 0 : nX *= aShadow.ShadowWidth;
163 : 0 : nY *= aShadow.ShadowWidth;
164 : :
165 [ # # ]: 0 : ::sax::Converter::convertColor( aOut, aShadow.Color );
166 : :
167 [ # # ]: 0 : aOut.append( sal_Unicode(' ') );
168 [ # # ]: 0 : rUnitConverter.convertMeasureToXML( aOut, nX );
169 [ # # ]: 0 : aOut.append( sal_Unicode(' ') );
170 [ # # ]: 0 : rUnitConverter.convertMeasureToXML( aOut, nY );
171 : :
172 [ # # ]: 0 : rStrExpValue = aOut.makeStringAndClear();
173 : :
174 : 0 : bRet = sal_True;
175 : : }
176 : :
177 : 0 : return bRet;
178 : : }
179 : :
180 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|