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 2008 by Sun Microsystems, Inc.
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 "vbatabstops.hxx"
29 : : #include "vbatabstop.hxx"
30 : : #include <com/sun/star/style/TabAlign.hpp>
31 : : #include <ooo/vba/word/WdTabLeader.hpp>
32 : : #include <ooo/vba/word/WdTabAlignment.hpp>
33 : :
34 : : using namespace ::ooo::vba;
35 : : using namespace ::com::sun::star;
36 : :
37 : 0 : uno::Sequence< style::TabStop > lcl_getTabStops( const uno::Reference< beans::XPropertySet >& xParaProps ) throw (uno::RuntimeException)
38 : : {
39 : 0 : uno::Sequence< style::TabStop > aSeq;
40 [ # # ][ # # ]: 0 : xParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaTabStops") ) ) >>= aSeq;
[ # # ][ # # ]
41 : 0 : return aSeq;
42 : : }
43 : :
44 : 0 : void lcl_setTabStops( const uno::Reference< beans::XPropertySet >& xParaProps, const uno::Sequence< style::TabStop >& aSeq ) throw (uno::RuntimeException)
45 : : {
46 [ # # ][ # # ]: 0 : xParaProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaTabStops") ), uno::makeAny( aSeq ) );
47 : 0 : }
48 : :
49 : : typedef ::cppu::WeakImplHelper2< container::XIndexAccess, container::XEnumerationAccess > TabStopCollectionHelper_Base;
50 : :
51 [ # # ]: 0 : class TabStopsEnumWrapper : public EnumerationHelper_BASE
52 : : {
53 : : uno::Reference< container::XIndexAccess > mxIndexAccess;
54 : : sal_Int32 nIndex;
55 : :
56 : : public:
57 : 0 : TabStopsEnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess ) : mxIndexAccess( xIndexAccess ), nIndex( 0 )
58 : : {
59 : 0 : }
60 : 0 : virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException)
61 : : {
62 : 0 : return ( nIndex < mxIndexAccess->getCount() );
63 : : }
64 : :
65 : 0 : virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
66 : : {
67 [ # # ]: 0 : if( nIndex < mxIndexAccess->getCount() )
68 : : {
69 : 0 : return mxIndexAccess->getByIndex( nIndex++ );
70 : : }
71 [ # # ]: 0 : throw container::NoSuchElementException();
72 : : }
73 : : };
74 : :
75 : : class TabStopCollectionHelper : public TabStopCollectionHelper_Base
76 : : {
77 : : private:
78 : : uno::Reference< XHelperInterface > mxParent;
79 : : uno::Reference< uno::XComponentContext > mxContext;
80 : : uno::Reference< beans::XPropertySet > mxParaProps;
81 : : uno::Sequence< style::TabStop > maTabStops;
82 : :
83 : : public:
84 [ # # ]: 0 : TabStopCollectionHelper( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::beans::XPropertySet >& xParaProps ) throw ( css::uno::RuntimeException ): mxParent( xParent ), mxContext( xContext ), mxParaProps( xParaProps )
85 : : {
86 [ # # ][ # # ]: 0 : maTabStops = lcl_getTabStops( xParaProps );
[ # # ]
87 : 0 : }
88 : :
89 [ # # ][ # # ]: 0 : virtual ~TabStopCollectionHelper() {}
90 : :
91 : 0 : virtual sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException)
92 : : {
93 : 0 : return maTabStops.getLength();
94 : : }
95 : 0 : virtual uno::Any SAL_CALL getByIndex( sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
96 : : {
97 [ # # ][ # # ]: 0 : if ( Index < 0 || Index >= getCount() )
[ # # ]
98 [ # # ]: 0 : throw css::lang::IndexOutOfBoundsException();
99 : :
100 : 0 : const style::TabStop* pTabs = maTabStops.getConstArray();
101 [ # # ][ # # ]: 0 : return uno::makeAny( uno::Reference< word::XTabStop >( new SwVbaTabStop( mxParent, mxContext, mxParaProps, pTabs[ Index ] ) ) );
[ # # ]
102 : : }
103 : 0 : virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException)
104 : : {
105 : 0 : return word::XTabStop::static_type(0);
106 : : }
107 : 0 : virtual sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException)
108 : : {
109 : 0 : return sal_True;
110 : : }
111 : : // XEnumerationAccess
112 : 0 : virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException)
113 : : {
114 [ # # ][ # # ]: 0 : return new TabStopsEnumWrapper( this );
[ # # ]
115 : : }
116 : : };
117 : :
118 [ # # ][ # # ]: 0 : SwVbaTabStops::SwVbaTabStops( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< beans::XPropertySet >& xParaProps ) throw (uno::RuntimeException) : SwVbaTabStops_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( new TabStopCollectionHelper( xParent, xContext, xParaProps ) ) ), mxParaProps( xParaProps )
[ # # ]
119 : : {
120 : 0 : }
121 : :
122 : 0 : uno::Reference< word::XTabStop > SAL_CALL SwVbaTabStops::Add( float Position, const uno::Any& Alignment, const uno::Any& Leader ) throw (uno::RuntimeException)
123 : : {
124 [ # # ]: 0 : sal_Int32 nPosition = Millimeter::getInHundredthsOfOneMillimeter( Position );
125 : :
126 : 0 : style::TabAlign nAlign = style::TabAlign_LEFT;
127 [ # # ]: 0 : if( Alignment.hasValue() )
128 : : {
129 : 0 : sal_Int32 wdAlign = word::WdTabAlignment::wdAlignTabLeft;
130 : 0 : Alignment >>= wdAlign;
131 [ # # # # : 0 : switch( wdAlign )
# # ]
132 : : {
133 : : case word::WdTabAlignment::wdAlignTabLeft:
134 : : {
135 : 0 : nAlign = style::TabAlign_LEFT;
136 : 0 : break;
137 : : }
138 : : case word::WdTabAlignment::wdAlignTabRight:
139 : : {
140 : 0 : nAlign = style::TabAlign_RIGHT;
141 : 0 : break;
142 : : }
143 : : case word::WdTabAlignment::wdAlignTabCenter:
144 : : {
145 : 0 : nAlign = style::TabAlign_CENTER;
146 : 0 : break;
147 : : }
148 : : case word::WdTabAlignment::wdAlignTabDecimal:
149 : : {
150 : 0 : nAlign = style::TabAlign_DECIMAL;
151 : 0 : break;
152 : : }
153 : : case word::WdTabAlignment::wdAlignTabBar:
154 : : case word::WdTabAlignment::wdAlignTabList:
155 : : {
156 [ # # ]: 0 : DebugHelper::exception( SbERR_NOT_IMPLEMENTED, rtl::OUString() );
157 : 0 : break;
158 : : }
159 : : default:
160 : : {
161 : : //left
162 : : }
163 : : }
164 : : }
165 : :
166 : 0 : sal_Unicode cLeader = ' '; // default is space
167 [ # # ]: 0 : if( Leader.hasValue() )
168 : : {
169 : 0 : sal_Int32 wdLeader = word::WdTabLeader::wdTabLeaderSpaces;
170 : 0 : Leader >>= wdLeader;
171 [ # # # # : 0 : switch( wdLeader )
# ]
172 : : {
173 : : case word::WdTabLeader::wdTabLeaderSpaces:
174 : : {
175 : 0 : cLeader = ' ';
176 : 0 : break;
177 : : }
178 : : case word::WdTabLeader::wdTabLeaderMiddleDot:
179 : : {
180 : 0 : cLeader = 183; // U+00B7 MIDDLE DOT
181 : 0 : break;
182 : : }
183 : : case word::WdTabLeader::wdTabLeaderDots:
184 : : {
185 : 0 : cLeader = '.';
186 : 0 : break;
187 : : }
188 : : case word::WdTabLeader::wdTabLeaderDashes:
189 : : case word::WdTabLeader::wdTabLeaderHeavy:
190 : : case word::WdTabLeader::wdTabLeaderLines:
191 : : {
192 : 0 : cLeader = '_';
193 : 0 : break;
194 : : }
195 : : default:
196 : : {
197 : : //left
198 : : }
199 : : }
200 : : }
201 : :
202 : 0 : sal_Char cDecimal = '.'; // default value
203 : :
204 : 0 : style::TabStop aTab;
205 : 0 : aTab.Position = nPosition;
206 : 0 : aTab.Alignment = nAlign;
207 : 0 : aTab.DecimalChar = cDecimal;
208 : 0 : aTab.FillChar = cLeader;
209 : :
210 [ # # ]: 0 : uno::Sequence< style::TabStop > aOldTabs = lcl_getTabStops( mxParaProps );
211 : 0 : sal_Bool bOverWriter = sal_False;
212 : :
213 : 0 : sal_Int32 nTabs = aOldTabs.getLength();
214 [ # # ]: 0 : uno::Sequence< style::TabStop > aNewTabs( nTabs + 1 );
215 : :
216 [ # # ]: 0 : style::TabStop* pOldTab = aOldTabs.getArray();
217 [ # # ]: 0 : style::TabStop* pNewTab = aNewTabs.getArray();
218 : 0 : pNewTab[0] = aTab;
219 [ # # ][ # # ]: 0 : for( sal_Int32 nIndex = 0; nIndex < nTabs && !bOverWriter; nIndex++ )
[ # # ]
220 : : {
221 [ # # ]: 0 : if( pOldTab[nIndex].Position == nPosition )
222 : : {
223 : 0 : bOverWriter = sal_True;
224 : 0 : pOldTab[nIndex] = aTab;
225 : 0 : break;
226 : : }
227 : 0 : pNewTab[ nIndex+1 ] = pOldTab[ nIndex ];
228 : : }
229 [ # # ]: 0 : if( bOverWriter )
230 [ # # ]: 0 : lcl_setTabStops( mxParaProps, aOldTabs );
231 : : else
232 [ # # ]: 0 : lcl_setTabStops( mxParaProps, aNewTabs );
233 : :
234 [ # # ][ # # ]: 0 : return uno::Reference< word::XTabStop >( new SwVbaTabStop( this, mxContext, mxParaProps, aTab ) );
[ # # ][ # # ]
[ # # ][ # # ]
235 : : }
236 : :
237 : 0 : void SAL_CALL SwVbaTabStops::ClearAll() throw (uno::RuntimeException)
238 : : {
239 [ # # ]: 0 : uno::Sequence< style::TabStop > aSeq;
240 [ # # ][ # # ]: 0 : lcl_setTabStops( mxParaProps, aSeq );
241 : 0 : }
242 : :
243 : : // XEnumerationAccess
244 : : uno::Type
245 : 0 : SwVbaTabStops::getElementType() throw (uno::RuntimeException)
246 : : {
247 : 0 : return word::XTabStop::static_type(0);
248 : : }
249 : : uno::Reference< container::XEnumeration >
250 : 0 : SwVbaTabStops::createEnumeration() throw (uno::RuntimeException)
251 : : {
252 [ # # ][ # # ]: 0 : return new TabStopsEnumWrapper( m_xIndexAccess );
253 : : }
254 : :
255 : : uno::Any
256 : 0 : SwVbaTabStops::createCollectionObject( const css::uno::Any& aSource )
257 : : {
258 : 0 : return aSource;
259 : : }
260 : :
261 : : rtl::OUString
262 : 0 : SwVbaTabStops::getServiceImplName()
263 : : {
264 : 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaTabStops"));
265 : : }
266 : :
267 : : css::uno::Sequence<rtl::OUString>
268 : 0 : SwVbaTabStops::getServiceNames()
269 : : {
270 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > sNames;
[ # # ][ # # ]
271 [ # # ]: 0 : if ( sNames.getLength() == 0 )
272 : : {
273 : 0 : sNames.realloc( 1 );
274 [ # # ]: 0 : sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.TabStops") );
275 : : }
276 : 0 : return sNames;
277 : : }
278 : :
279 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|