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