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 : : #include "vbaborders.hxx"
29 : : #include <ooo/vba/word/XBorder.hpp>
30 : : #include <ooo/vba/word/WdBorderType.hpp>
31 : : #include <ooo/vba/word/WdLineStyle.hpp>
32 : : #include <sal/macros.h>
33 : : #include <cppuhelper/implbase3.hxx>
34 : : #include <com/sun/star/beans/XPropertySet.hpp>
35 : : #include <com/sun/star/table/TableBorder.hpp>
36 : : #include <com/sun/star/table/ShadowFormat.hpp>
37 : : #include <com/sun/star/table/ShadowLocation.hpp>
38 : : #include "vbapalette.hxx"
39 : :
40 : : using namespace ::com::sun::star;
41 : : using namespace ::ooo::vba;
42 : :
43 : :
44 : : typedef ::cppu::WeakImplHelper1<container::XIndexAccess > RangeBorders_Base;
45 : : typedef InheritedHelperInterfaceImpl1<word::XBorder > SwVbaBorder_Base;
46 : :
47 : : // #TODO sort these indexes to match the order in which Word iterates over the
48 : : // borders, the enumeration will match the order in this list
49 : : static const sal_Int16 supportedIndexTable[] = { word::WdBorderType::wdBorderBottom, word::WdBorderType::wdBorderDiagonalDown, word::WdBorderType::wdBorderDiagonalUp, word::WdBorderType::wdBorderHorizontal, word::WdBorderType::wdBorderLeft, word::WdBorderType::wdBorderRight, word::WdBorderType::wdBorderTop, word::WdBorderType::wdBorderVertical };
50 : :
51 : 3 : const static rtl::OUString sTableBorder( RTL_CONSTASCII_USTRINGPARAM("TableBorder") );
52 : :
53 : : // Equiv widths in in 1/100 mm
54 : : const static sal_Int32 OOLineThin = 35;
55 : : const static sal_Int32 OOLineMedium = 88;
56 : : const static sal_Int32 OOLineThick = 141;
57 : : const static sal_Int32 OOLineHairline = 2;
58 : :
59 [ # # ][ # # ]: 0 : class SwVbaBorder : public SwVbaBorder_Base
60 : : {
61 : : private:
62 : : uno::Reference< beans::XPropertySet > m_xProps;
63 : : sal_Int32 m_LineType;
64 : : VbaPalette m_Palette;
65 : 0 : bool setBorderLine( table::BorderLine& rBorderLine )
66 : : {
67 : 0 : table::TableBorder aTableBorder;
68 [ # # ][ # # ]: 0 : m_xProps->getPropertyValue( sTableBorder ) >>= aTableBorder;
[ # # ]
69 : :
70 [ # # # # : 0 : switch ( m_LineType )
# # # # ]
71 : : {
72 : : case word::WdBorderType::wdBorderLeft:
73 : 0 : aTableBorder.IsLeftLineValid = sal_True;
74 : 0 : aTableBorder.LeftLine= rBorderLine;
75 : 0 : break;
76 : : case word::WdBorderType::wdBorderTop:
77 : 0 : aTableBorder.IsTopLineValid = sal_True;
78 : 0 : aTableBorder.TopLine = rBorderLine;
79 : 0 : break;
80 : :
81 : : case word::WdBorderType::wdBorderBottom:
82 : 0 : aTableBorder.IsBottomLineValid = sal_True;
83 : 0 : aTableBorder.BottomLine = rBorderLine;
84 : 0 : break;
85 : : case word::WdBorderType::wdBorderRight:
86 : 0 : aTableBorder.IsRightLineValid = sal_True;
87 : 0 : aTableBorder.RightLine = rBorderLine;
88 : 0 : break;
89 : : case word::WdBorderType::wdBorderVertical:
90 : 0 : aTableBorder.IsVerticalLineValid = sal_True;
91 : 0 : aTableBorder.VerticalLine = rBorderLine;
92 : 0 : break;
93 : : case word::WdBorderType::wdBorderHorizontal:
94 : 0 : aTableBorder.IsHorizontalLineValid = sal_True;
95 : 0 : aTableBorder.HorizontalLine = rBorderLine;
96 : 0 : break;
97 : : case word::WdBorderType::wdBorderDiagonalDown:
98 : : case word::WdBorderType::wdBorderDiagonalUp:
99 : : // #TODO have to ignore at the momement, would be
100 : : // nice to investigate what we can do here
101 : 0 : break;
102 : : default:
103 : 0 : return false;
104 : : }
105 [ # # ][ # # ]: 0 : m_xProps->setPropertyValue( sTableBorder, uno::makeAny(aTableBorder) );
[ # # ]
106 : 0 : return true;
107 : : }
108 : :
109 : 0 : bool getBorderLine( table::BorderLine& rBorderLine )
110 : : {
111 : 0 : table::TableBorder aTableBorder;
112 [ # # ][ # # ]: 0 : m_xProps->getPropertyValue( sTableBorder ) >>= aTableBorder;
[ # # ]
113 [ # # # # : 0 : switch ( m_LineType )
# # # # ]
114 : : {
115 : : case word::WdBorderType::wdBorderLeft:
116 [ # # ]: 0 : if ( aTableBorder.IsLeftLineValid )
117 : 0 : rBorderLine = aTableBorder.LeftLine;
118 : 0 : break;
119 : : case word::WdBorderType::wdBorderTop:
120 [ # # ]: 0 : if ( aTableBorder.IsTopLineValid )
121 : 0 : rBorderLine = aTableBorder.TopLine;
122 : 0 : break;
123 : : case word::WdBorderType::wdBorderBottom:
124 [ # # ]: 0 : if ( aTableBorder.IsBottomLineValid )
125 : 0 : rBorderLine = aTableBorder.BottomLine;
126 : 0 : break;
127 : : case word::WdBorderType::wdBorderRight:
128 [ # # ]: 0 : if ( aTableBorder.IsRightLineValid )
129 : 0 : rBorderLine = aTableBorder.RightLine;
130 : 0 : break;
131 : : case word::WdBorderType::wdBorderVertical:
132 [ # # ]: 0 : if ( aTableBorder.IsVerticalLineValid )
133 : 0 : rBorderLine = aTableBorder.VerticalLine;
134 : 0 : break;
135 : : case word::WdBorderType::wdBorderHorizontal:
136 [ # # ]: 0 : if ( aTableBorder.IsHorizontalLineValid )
137 : 0 : rBorderLine = aTableBorder.HorizontalLine;
138 : 0 : break;
139 : :
140 : : case word::WdBorderType::wdBorderDiagonalDown:
141 : : case word::WdBorderType::wdBorderDiagonalUp:
142 : : // #TODO have to ignore at the momement, would be
143 : : // nice to investigate what we can do here
144 : 0 : break;
145 : : default:
146 : 0 : return false;
147 : : }
148 : 0 : return true;
149 : : }
150 : : SwVbaBorder(); // no impl
151 : : protected:
152 : 0 : virtual rtl::OUString getServiceImplName()
153 : : {
154 : 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaBorder"));
155 : : }
156 : :
157 : 0 : virtual css::uno::Sequence<rtl::OUString> getServiceNames()
158 : : {
159 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > aServiceNames;
[ # # ][ # # ]
160 [ # # ]: 0 : if ( aServiceNames.getLength() == 0 )
161 : : {
162 : 0 : aServiceNames.realloc( 1 );
163 [ # # ]: 0 : aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Border" ) );
164 : : }
165 : 0 : return aServiceNames;
166 : : }
167 : : public:
168 [ # # ][ # # ]: 0 : SwVbaBorder( const uno::Reference< beans::XPropertySet > & xProps, const uno::Reference< uno::XComponentContext >& xContext, sal_Int32 lineType, VbaPalette& rPalette) : SwVbaBorder_Base( uno::Reference< XHelperInterface >( xProps, uno::UNO_QUERY ), xContext ), m_xProps( xProps ), m_LineType( lineType ), m_Palette( rPalette ) {}
169 : :
170 : 0 : uno::Any SAL_CALL getLineStyle() throw (uno::RuntimeException)
171 : : {
172 : 0 : sal_Int32 nLineStyle = word::WdLineStyle::wdLineStyleNone;
173 : 0 : table::BorderLine aBorderLine;
174 [ # # ][ # # ]: 0 : if ( getBorderLine( aBorderLine ) )
175 : : {
176 [ # # ][ # # ]: 0 : if( aBorderLine.InnerLineWidth !=0 && aBorderLine.OuterLineWidth !=0 )
177 : : {
178 : 0 : nLineStyle = word::WdLineStyle::wdLineStyleDouble;
179 : : }
180 [ # # ][ # # ]: 0 : else if( aBorderLine.InnerLineWidth !=0 || aBorderLine.OuterLineWidth !=0 )
181 : : {
182 : 0 : nLineStyle = word::WdLineStyle::wdLineStyleSingle;
183 : : }
184 : : else
185 : : {
186 : 0 : nLineStyle = word::WdLineStyle::wdLineStyleNone;
187 : : }
188 : : }
189 [ # # ]: 0 : return uno::makeAny( nLineStyle );
190 : : }
191 : 0 : void SAL_CALL setLineStyle( const uno::Any& _linestyle ) throw (uno::RuntimeException)
192 : : {
193 : : // Urk no choice but to silently ignore we don't support this attribute
194 : : // #TODO would be nice to support the word line styles
195 : 0 : sal_Int32 nLineStyle = 0;
196 : 0 : _linestyle >>= nLineStyle;
197 : 0 : table::BorderLine aBorderLine;
198 [ # # ][ # # ]: 0 : if ( getBorderLine( aBorderLine ) )
199 : : {
200 [ # # # ]: 0 : switch ( nLineStyle )
201 : : {
202 : : case word::WdLineStyle::wdLineStyleNone:
203 : : {
204 : 0 : aBorderLine.InnerLineWidth = 0;
205 : 0 : aBorderLine.OuterLineWidth = 0;
206 : 0 : break;
207 : : }
208 : : case word::WdLineStyle::wdLineStyleDashDot:
209 : : case word::WdLineStyle::wdLineStyleDashDotDot:
210 : : case word::WdLineStyle::wdLineStyleDashDotStroked:
211 : : case word::WdLineStyle::wdLineStyleDashLargeGap:
212 : : case word::WdLineStyle::wdLineStyleDashSmallGap:
213 : : case word::WdLineStyle::wdLineStyleDot:
214 : : case word::WdLineStyle::wdLineStyleDouble:
215 : : case word::WdLineStyle::wdLineStyleDoubleWavy:
216 : : case word::WdLineStyle::wdLineStyleEmboss3D:
217 : : case word::WdLineStyle::wdLineStyleEngrave3D:
218 : : case word::WdLineStyle::wdLineStyleInset:
219 : : case word::WdLineStyle::wdLineStyleOutset:
220 : : case word::WdLineStyle::wdLineStyleSingle:
221 : : case word::WdLineStyle::wdLineStyleSingleWavy:
222 : : case word::WdLineStyle::wdLineStyleThickThinLargeGap:
223 : : case word::WdLineStyle::wdLineStyleThickThinMedGap:
224 : : case word::WdLineStyle::wdLineStyleThickThinSmallGap:
225 : : case word::WdLineStyle::wdLineStyleThinThickLargeGap:
226 : : case word::WdLineStyle::wdLineStyleThinThickMedGap:
227 : : case word::WdLineStyle::wdLineStyleThinThickSmallGap:
228 : : case word::WdLineStyle::wdLineStyleThinThickThinLargeGap:
229 : : case word::WdLineStyle::wdLineStyleThinThickThinMedGap:
230 : : case word::WdLineStyle::wdLineStyleThinThickThinSmallGap:
231 : : case word::WdLineStyle::wdLineStyleTriple:
232 : : {
233 : 0 : aBorderLine.InnerLineWidth = 0;
234 : 0 : aBorderLine.OuterLineWidth = OOLineHairline;
235 : 0 : break;
236 : : }
237 : : default:
238 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Bad param" ) ), uno::Reference< uno::XInterface >() );
239 : : }
240 [ # # ]: 0 : setBorderLine( aBorderLine );
241 : : }
242 : : else
243 [ # # ][ # # ]: 0 : throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Method failed" ) ), uno::Reference< uno::XInterface >() );
244 : 0 : }
245 : : };
246 : :
247 [ # # ][ # # ]: 0 : class RangeBorders : public RangeBorders_Base
248 : : {
249 : : private:
250 : : uno::Reference< table::XCellRange > m_xRange;
251 : : uno::Reference< uno::XComponentContext > m_xContext;
252 : : VbaPalette m_Palette;
253 : 0 : sal_Int32 getTableIndex( sal_Int32 nConst )
254 : : {
255 : : // hokay return position of the index in the table
256 : 0 : sal_Int32 nIndexes = getCount();
257 : 0 : sal_Int32 realIndex = 0;
258 : 0 : const sal_Int16* pTableEntry = supportedIndexTable;
259 [ # # ]: 0 : for ( ; realIndex < nIndexes; ++realIndex, ++pTableEntry )
260 : : {
261 [ # # ]: 0 : if ( *pTableEntry == nConst )
262 : 0 : return realIndex;
263 : : }
264 : 0 : return getCount(); // error condition
265 : : }
266 : : public:
267 [ # # ]: 0 : RangeBorders( const uno::Reference< table::XCellRange >& xRange, const uno::Reference< uno::XComponentContext > & xContext, VbaPalette& rPalette ) : m_xRange( xRange ), m_xContext( xContext ), m_Palette( rPalette )
268 : : {
269 : 0 : }
270 : : // XIndexAccess
271 : 0 : virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException)
272 : : {
273 : 0 : return SAL_N_ELEMENTS( supportedIndexTable );
274 : : }
275 : 0 : virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
276 : : {
277 : :
278 : 0 : sal_Int32 nIndex = getTableIndex( Index );
279 [ # # ][ # # ]: 0 : if ( nIndex >= 0 && nIndex < getCount() )
[ # # ]
280 : : {
281 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xProps( m_xRange, uno::UNO_QUERY_THROW );
282 [ # # ][ # # ]: 0 : return uno::makeAny( uno::Reference< word::XBorder >( new SwVbaBorder( xProps, m_xContext, supportedIndexTable[ nIndex ], m_Palette )) );
[ # # ][ # # ]
283 : : }
284 [ # # ]: 0 : throw lang::IndexOutOfBoundsException();
285 : : }
286 : 0 : virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException)
287 : : {
288 : 0 : return word::XBorder::static_type(0);
289 : : }
290 : 0 : virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException)
291 : : {
292 : 0 : return sal_True;
293 : : }
294 : : };
295 : :
296 : : uno::Reference< container::XIndexAccess >
297 : 0 : rangeToBorderIndexAccess( const uno::Reference< table::XCellRange >& xRange, const uno::Reference< uno::XComponentContext > & xContext, VbaPalette& rPalette )
298 : : {
299 [ # # ][ # # ]: 0 : return new RangeBorders( xRange, xContext, rPalette );
300 : : }
301 : :
302 [ # # ]: 0 : class RangeBorderEnumWrapper : public EnumerationHelper_BASE
303 : : {
304 : : uno::Reference<container::XIndexAccess > m_xIndexAccess;
305 : : sal_Int32 nIndex;
306 : : public:
307 : 0 : RangeBorderEnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess ) : m_xIndexAccess( xIndexAccess ), nIndex( 0 ) {}
308 : 0 : virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException)
309 : : {
310 : 0 : return ( nIndex < m_xIndexAccess->getCount() );
311 : : }
312 : :
313 : 0 : virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
314 : : {
315 [ # # ]: 0 : if ( nIndex < m_xIndexAccess->getCount() )
316 : 0 : return m_xIndexAccess->getByIndex( nIndex++ );
317 [ # # ]: 0 : throw container::NoSuchElementException();
318 : : }
319 : : };
320 : :
321 : : // for Table borders
322 [ # # ]: 0 : SwVbaBorders::SwVbaBorders( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< table::XCellRange >& xRange, VbaPalette& rPalette ): SwVbaBorders_BASE( xParent, xContext, rangeToBorderIndexAccess( xRange ,xContext, rPalette ) )
323 : : {
324 [ # # ]: 0 : m_xProps.set( xRange, uno::UNO_QUERY_THROW );
325 : 0 : }
326 : :
327 : : uno::Reference< container::XEnumeration >
328 : 0 : SwVbaBorders::createEnumeration() throw (uno::RuntimeException)
329 : : {
330 [ # # ][ # # ]: 0 : return new RangeBorderEnumWrapper( m_xIndexAccess );
331 : : }
332 : :
333 : : uno::Any
334 : 0 : SwVbaBorders::createCollectionObject( const css::uno::Any& aSource )
335 : : {
336 : 0 : return aSource; // its already a Border object
337 : : }
338 : :
339 : : uno::Type
340 : 0 : SwVbaBorders::getElementType() throw (uno::RuntimeException)
341 : : {
342 : 0 : return word::XBorders::static_type(0);
343 : : }
344 : :
345 : : uno::Any
346 : 0 : SwVbaBorders::getItemByIntIndex( const sal_Int32 nIndex ) throw (uno::RuntimeException)
347 : : {
348 [ # # ]: 0 : return createCollectionObject( m_xIndexAccess->getByIndex( nIndex ) );
349 : : }
350 : :
351 : 0 : sal_Bool SAL_CALL SwVbaBorders::getShadow() throw (uno::RuntimeException)
352 : : {
353 : : // always return False for table border in MS Word
354 : 0 : return sal_False;
355 : : }
356 : :
357 : 0 : void SAL_CALL SwVbaBorders::setShadow( sal_Bool /*_shadow*/ ) throw (uno::RuntimeException)
358 : : {
359 : : // not support in Table border in Word
360 : : // TODO:
361 : 0 : }
362 : :
363 : : rtl::OUString
364 : 0 : SwVbaBorders::getServiceImplName()
365 : : {
366 : 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaBorders"));
367 : : }
368 : :
369 : : uno::Sequence< rtl::OUString >
370 : 0 : SwVbaBorders::getServiceNames()
371 : : {
372 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > aServiceNames;
[ # # ][ # # ]
373 [ # # ]: 0 : if ( aServiceNames.getLength() == 0 )
374 : : {
375 : 0 : aServiceNames.realloc( 1 );
376 [ # # ]: 0 : aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Borders" ) );
377 : : }
378 : 0 : return aServiceNames;
379 [ + - ][ + - ]: 9 : }
380 : :
381 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|