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