Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #include "vbalistlevel.hxx"
20 : #include <vbahelper/vbahelper.hxx>
21 : #include <tools/diagnose_ex.h>
22 : #include <com/sun/star/style/NumberingType.hpp>
23 : #include <ooo/vba/word/WdListNumberStyle.hpp>
24 : #include <ooo/vba/word/WdTrailingCharacter.hpp>
25 : #include <com/sun/star/text/HoriOrientation.hpp>
26 : #include <ooo/vba/word/WdListLevelAlignment.hpp>
27 :
28 : using namespace ::ooo::vba;
29 : using namespace ::com::sun::star;
30 :
31 0 : SwVbaListLevel::SwVbaListLevel( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, SwVbaListHelperRef pHelper, sal_Int32 nLevel ) throw ( uno::RuntimeException ) : SwVbaListLevel_BASE( rParent, rContext ), pListHelper( pHelper ), mnLevel( nLevel )
32 : {
33 0 : }
34 :
35 0 : SwVbaListLevel::~SwVbaListLevel()
36 : {
37 0 : }
38 :
39 0 : ::sal_Int32 SAL_CALL SwVbaListLevel::getAlignment() throw (uno::RuntimeException, std::exception)
40 : {
41 0 : sal_Int16 nAlignment = 0;
42 0 : pListHelper->getPropertyValueWithNameAndLevel( mnLevel, OUString("Adjust") ) >>= nAlignment;
43 0 : switch( nAlignment )
44 : {
45 : case text::HoriOrientation::LEFT:
46 : {
47 0 : nAlignment = word::WdListLevelAlignment::wdListLevelAlignLeft;
48 0 : break;
49 : }
50 : case text::HoriOrientation::RIGHT:
51 : {
52 0 : nAlignment = word::WdListLevelAlignment::wdListLevelAlignRight;
53 0 : break;
54 : }
55 : case text::HoriOrientation::CENTER:
56 : {
57 0 : nAlignment = word::WdListLevelAlignment::wdListLevelAlignCenter;
58 0 : break;
59 : }
60 : default:
61 : {
62 0 : throw uno::RuntimeException();
63 : }
64 : }
65 0 : return nAlignment;
66 : }
67 :
68 0 : void SAL_CALL SwVbaListLevel::setAlignment( ::sal_Int32 _alignment ) throw (uno::RuntimeException, std::exception)
69 : {
70 0 : sal_Int16 nAlignment = text::HoriOrientation::LEFT;
71 0 : switch( _alignment )
72 : {
73 : case word::WdListLevelAlignment::wdListLevelAlignLeft:
74 : {
75 0 : nAlignment = text::HoriOrientation::LEFT;
76 0 : break;
77 : }
78 : case word::WdListLevelAlignment::wdListLevelAlignRight:
79 : {
80 0 : nAlignment = text::HoriOrientation::RIGHT;
81 0 : break;
82 : }
83 : case word::WdListLevelAlignment::wdListLevelAlignCenter:
84 : {
85 0 : nAlignment = text::HoriOrientation::CENTER;
86 0 : break;
87 : }
88 : default:
89 : {
90 0 : throw uno::RuntimeException();
91 : }
92 : }
93 0 : pListHelper->setPropertyValueWithNameAndLevel( mnLevel, OUString("Adjust"), uno::makeAny( nAlignment ) );
94 0 : }
95 :
96 0 : uno::Reference< ::ooo::vba::word::XFont > SAL_CALL SwVbaListLevel::getFont() throw (uno::RuntimeException, std::exception)
97 : {
98 0 : throw uno::RuntimeException("Not implemented" );
99 : }
100 :
101 0 : void SAL_CALL SwVbaListLevel::setFont( const uno::Reference< ::ooo::vba::word::XFont >& /*_font*/ ) throw (uno::RuntimeException, std::exception)
102 : {
103 0 : throw uno::RuntimeException("Not implemented" );
104 : }
105 :
106 0 : ::sal_Int32 SAL_CALL SwVbaListLevel::getIndex() throw (uno::RuntimeException, std::exception)
107 : {
108 0 : return mnLevel + 1;
109 : }
110 :
111 0 : OUString SAL_CALL SwVbaListLevel::getLinkedStyle() throw (uno::RuntimeException, std::exception)
112 : {
113 : // TODO:
114 0 : return OUString();
115 : }
116 :
117 0 : void SAL_CALL SwVbaListLevel::setLinkedStyle( const OUString& /*_linkedstyle*/ ) throw (uno::RuntimeException, std::exception)
118 : {
119 : // TODO:
120 0 : }
121 :
122 0 : OUString SAL_CALL SwVbaListLevel::getNumberFormat() throw (uno::RuntimeException, std::exception)
123 : {
124 : // TODO::
125 0 : return OUString();
126 : }
127 :
128 0 : void SAL_CALL SwVbaListLevel::setNumberFormat( const OUString& /*_numberformat*/ ) throw (uno::RuntimeException, std::exception)
129 : {
130 : // TODO::
131 0 : }
132 :
133 0 : float SAL_CALL SwVbaListLevel::getNumberPosition() throw (uno::RuntimeException, std::exception)
134 : {
135 : // indentAt + firstlineindent
136 0 : sal_Int32 nIndentAt = 0;
137 0 : sal_Int32 nFirstLineIndent = 0;
138 0 : pListHelper->getPropertyValueWithNameAndLevel( mnLevel, OUString("IndentAt") ) >>= nIndentAt;
139 0 : pListHelper->getPropertyValueWithNameAndLevel( mnLevel, OUString("FirstLineIndent") ) >>= nFirstLineIndent;
140 :
141 0 : sal_Int32 nResult = nIndentAt + nFirstLineIndent;
142 :
143 0 : return static_cast< float >( Millimeter::getInPoints( nResult ) );
144 : }
145 :
146 0 : void SAL_CALL SwVbaListLevel::setNumberPosition( float _numberposition ) throw (uno::RuntimeException, std::exception)
147 : {
148 0 : sal_Int32 nNumberPosition = Millimeter::getInHundredthsOfOneMillimeter( _numberposition );
149 :
150 0 : sal_Int32 nIndentAt = 0;
151 0 : pListHelper->getPropertyValueWithNameAndLevel( mnLevel, OUString("IndentAt") ) >>= nIndentAt;
152 :
153 0 : sal_Int32 nFirstLineIndent = nNumberPosition - nIndentAt;
154 0 : pListHelper->setPropertyValueWithNameAndLevel( mnLevel, OUString("FirstLineIndent"), uno::makeAny( nFirstLineIndent ) );
155 0 : }
156 :
157 0 : ::sal_Int32 SAL_CALL SwVbaListLevel::getNumberStyle() throw (uno::RuntimeException, std::exception)
158 : {
159 0 : sal_Int16 nNumberingType = 0;
160 0 : pListHelper->getPropertyValueWithNameAndLevel( mnLevel, OUString("NumberingType") ) >>= nNumberingType;
161 0 : switch( nNumberingType )
162 : {
163 : case style::NumberingType::CHAR_SPECIAL:
164 : {
165 0 : nNumberingType = word::WdListNumberStyle::wdListNumberStyleBullet;
166 0 : break;
167 : }
168 : case style::NumberingType::CHARS_UPPER_LETTER:
169 : {
170 0 : nNumberingType = word::WdListNumberStyle::wdListNumberStyleUppercaseLetter;
171 0 : break;
172 : }
173 : case style::NumberingType::CHARS_LOWER_LETTER:
174 : {
175 0 : nNumberingType = word::WdListNumberStyle::wdListNumberStyleLowercaseLetter;
176 0 : break;
177 : }
178 : case style::NumberingType::ROMAN_UPPER:
179 : {
180 0 : nNumberingType = word::WdListNumberStyle::wdListNumberStyleUppercaseRoman;
181 0 : break;
182 : }
183 : case style::NumberingType::ROMAN_LOWER:
184 : {
185 0 : nNumberingType = word::WdListNumberStyle::wdListNumberStyleLowercaseRoman;
186 0 : break;
187 : }
188 : case style::NumberingType::ARABIC:
189 : {
190 0 : nNumberingType = word::WdListNumberStyle::wdListNumberStyleArabic;
191 0 : break;
192 : }
193 : case style::NumberingType::NUMBER_NONE:
194 : {
195 0 : nNumberingType = word::WdListNumberStyle::wdListNumberStyleNone;
196 0 : break;
197 : }
198 : case style::NumberingType::FULLWIDTH_ARABIC:
199 : {
200 0 : nNumberingType = word::WdListNumberStyle::wdListNumberStyleArabicFullWidth;
201 0 : break;
202 : }
203 : case style::NumberingType::CIRCLE_NUMBER:
204 : {
205 0 : nNumberingType = word::WdListNumberStyle::wdListNumberStyleNumberInCircle;
206 0 : break;
207 : }
208 : case style::NumberingType::CHARS_ARABIC:
209 : {
210 0 : nNumberingType = word::WdListNumberStyle::wdListNumberStyleCardinalText;
211 0 : break;
212 : }
213 : default:
214 : {
215 0 : throw uno::RuntimeException("Not implemented" );
216 : }
217 : }
218 0 : return nNumberingType;
219 : }
220 :
221 0 : void SAL_CALL SwVbaListLevel::setNumberStyle( ::sal_Int32 _numberstyle ) throw (uno::RuntimeException, std::exception)
222 : {
223 0 : sal_Int16 nNumberingType = 0;
224 0 : switch( _numberstyle )
225 : {
226 : case word::WdListNumberStyle::wdListNumberStyleBullet:
227 : {
228 0 : nNumberingType = style::NumberingType::CHAR_SPECIAL;
229 0 : break;
230 : }
231 : case word::WdListNumberStyle::wdListNumberStyleUppercaseLetter:
232 : {
233 0 : nNumberingType = style::NumberingType::CHARS_UPPER_LETTER_N;
234 0 : break;
235 : }
236 : case word::WdListNumberStyle::wdListNumberStyleLowercaseLetter:
237 : {
238 0 : nNumberingType = style::NumberingType::CHARS_LOWER_LETTER_N;
239 0 : break;
240 : }
241 : case word::WdListNumberStyle::wdListNumberStyleUppercaseRoman:
242 : {
243 0 : nNumberingType = style::NumberingType::ROMAN_UPPER;
244 0 : break;
245 : }
246 : case word::WdListNumberStyle::wdListNumberStyleLowercaseRoman:
247 : {
248 0 : nNumberingType = style::NumberingType::ROMAN_LOWER;
249 0 : break;
250 : }
251 : case word::WdListNumberStyle::wdListNumberStyleArabic:
252 : {
253 0 : nNumberingType = style::NumberingType::ARABIC;
254 0 : break;
255 : }
256 : case word::WdListNumberStyle::wdListNumberStyleNone:
257 : {
258 0 : nNumberingType = style::NumberingType::NUMBER_NONE;
259 0 : break;
260 : }
261 : case word::WdListNumberStyle::wdListNumberStyleArabicFullWidth:
262 : {
263 0 : nNumberingType = style::NumberingType::FULLWIDTH_ARABIC;
264 0 : break;
265 : }
266 : case word::WdListNumberStyle::wdListNumberStyleNumberInCircle:
267 : {
268 0 : nNumberingType = style::NumberingType::CIRCLE_NUMBER;
269 0 : break;
270 : }
271 : case word::WdListNumberStyle::wdListNumberStyleCardinalText:
272 : {
273 0 : nNumberingType = style::NumberingType::CHARS_ARABIC;
274 0 : break;
275 : }
276 : case word::WdListNumberStyle::wdListNumberStyleOrdinal:
277 : case word::WdListNumberStyle::wdListNumberStyleOrdinalText:
278 : case word::WdListNumberStyle::wdListNumberStyleKanji:
279 : case word::WdListNumberStyle::wdListNumberStyleKanjiDigit:
280 : case word::WdListNumberStyle::wdListNumberStyleAiueoHalfWidth:
281 : case word::WdListNumberStyle::wdListNumberStyleIrohaHalfWidth:
282 : {
283 0 : nNumberingType = style::NumberingType::ARABIC;
284 0 : break;
285 : }
286 : default:
287 : {
288 0 : throw uno::RuntimeException("Not implemented" );
289 : }
290 : }
291 :
292 0 : pListHelper->setPropertyValueWithNameAndLevel( mnLevel, OUString("NumberingType"), uno::makeAny( nNumberingType ) );
293 0 : }
294 :
295 0 : ::sal_Int32 SAL_CALL SwVbaListLevel::getResetOnHigher() throw (uno::RuntimeException, std::exception)
296 : {
297 : //seems not support?
298 0 : return 0;
299 : }
300 :
301 0 : void SAL_CALL SwVbaListLevel::setResetOnHigher( ::sal_Int32 /*_resetonhigher*/ ) throw (uno::RuntimeException, std::exception)
302 : {
303 : //seems not support?
304 0 : }
305 :
306 0 : ::sal_Int32 SAL_CALL SwVbaListLevel::getStartAt() throw (uno::RuntimeException, std::exception)
307 : {
308 0 : sal_Int16 nStartWith = 0;
309 0 : pListHelper->getPropertyValueWithNameAndLevel( mnLevel, OUString("StartWith") ) >>= nStartWith;
310 0 : return nStartWith;
311 : }
312 :
313 0 : void SAL_CALL SwVbaListLevel::setStartAt( ::sal_Int32 _startat ) throw (uno::RuntimeException, std::exception)
314 : {
315 0 : sal_Int16 nStartWith = (sal_Int16)_startat;
316 0 : pListHelper->setPropertyValueWithNameAndLevel( mnLevel, OUString("StartWith"), uno::makeAny( nStartWith ) );
317 0 : }
318 :
319 0 : float SAL_CALL SwVbaListLevel::getTabPosition() throw (uno::RuntimeException, std::exception)
320 : {
321 0 : sal_Int32 nTabPosition = 0;
322 0 : pListHelper->getPropertyValueWithNameAndLevel( mnLevel, OUString("ListtabStopPosition") ) >>= nTabPosition;
323 :
324 0 : return static_cast< float >( Millimeter::getInPoints( nTabPosition ) );
325 : }
326 :
327 0 : void SAL_CALL SwVbaListLevel::setTabPosition( float _tabposition ) throw (uno::RuntimeException, std::exception)
328 : {
329 0 : sal_Int32 nTabPosition = Millimeter::getInHundredthsOfOneMillimeter( _tabposition );
330 0 : pListHelper->setPropertyValueWithNameAndLevel( mnLevel, OUString("ListtabStopPosition"), uno::makeAny( nTabPosition ) );
331 0 : }
332 :
333 0 : float SAL_CALL SwVbaListLevel::getTextPosition() throw (uno::RuntimeException, std::exception)
334 : {
335 : // indentAt
336 0 : sal_Int32 nIndentAt = 0;
337 0 : pListHelper->getPropertyValueWithNameAndLevel( mnLevel, OUString("IndentAt") ) >>= nIndentAt;
338 :
339 0 : return static_cast< float >( Millimeter::getInPoints( nIndentAt ) );
340 : }
341 :
342 0 : void SAL_CALL SwVbaListLevel::setTextPosition( float _textposition ) throw (uno::RuntimeException, std::exception)
343 : {
344 0 : sal_Int32 nIndentAt = 0;
345 0 : sal_Int32 nFirstLineIndent = 0;
346 0 : pListHelper->getPropertyValueWithNameAndLevel( mnLevel, OUString("IndentAt") ) >>= nIndentAt;
347 0 : pListHelper->getPropertyValueWithNameAndLevel( mnLevel, OUString("FirstLineIndent") ) >>= nFirstLineIndent;
348 :
349 0 : sal_Int32 nAlignedAt = nIndentAt + nFirstLineIndent;
350 :
351 0 : nIndentAt = Millimeter::getInHundredthsOfOneMillimeter( _textposition );
352 0 : nFirstLineIndent = nAlignedAt - nIndentAt;
353 0 : pListHelper->setPropertyValueWithNameAndLevel( mnLevel, OUString("IndentAt"), uno::makeAny( nIndentAt ) );
354 0 : pListHelper->setPropertyValueWithNameAndLevel( mnLevel, OUString("FirstLineIndent"), uno::makeAny( nFirstLineIndent ) );
355 0 : }
356 :
357 0 : ::sal_Int32 SAL_CALL SwVbaListLevel::getTrailingCharacter() throw (uno::RuntimeException, std::exception)
358 : {
359 0 : sal_Int16 nLabelFollowedBy= 0;
360 0 : pListHelper->getPropertyValueWithNameAndLevel( mnLevel, OUString("LabelFollowedBy") ) >>= nLabelFollowedBy;
361 :
362 0 : return nLabelFollowedBy;
363 : }
364 :
365 0 : void SAL_CALL SwVbaListLevel::setTrailingCharacter( ::sal_Int32 _trailingcharacter ) throw (uno::RuntimeException, std::exception)
366 : {
367 0 : sal_Int16 nLabelFollowedBy = (sal_Int16)_trailingcharacter;
368 0 : pListHelper->setPropertyValueWithNameAndLevel( mnLevel, OUString("LabelFollowedBy"), uno::makeAny( nLabelFollowedBy ) );
369 0 : }
370 :
371 : OUString
372 0 : SwVbaListLevel::getServiceImplName()
373 : {
374 0 : return OUString("SwVbaListLevel");
375 : }
376 :
377 : uno::Sequence< OUString >
378 0 : SwVbaListLevel::getServiceNames()
379 : {
380 0 : static uno::Sequence< OUString > aServiceNames;
381 0 : if ( aServiceNames.getLength() == 0 )
382 : {
383 0 : aServiceNames.realloc( 1 );
384 0 : aServiceNames[ 0 ] = "ooo.vba.word.ListLevel";
385 : }
386 0 : return aServiceNames;
387 6 : }
388 :
389 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|