LibreOffice Module sw (master) 1
vbalisthelper.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 "vbalisthelper.hxx"
20#include <utility>
22#include <sal/log.hxx>
23#include <ooo/vba/word/WdListGalleryType.hpp>
24#include <com/sun/star/beans/XPropertySet.hpp>
25#include <com/sun/star/lang/XMultiServiceFactory.hpp>
26#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
27#include <com/sun/star/style/NumberingType.hpp>
28#include <com/sun/star/container/XIndexReplace.hpp>
29
30using namespace ::ooo::vba;
31using namespace ::com::sun::star;
32
33const sal_Int32 LIST_LEVEL_COUNT = 9;
34
35constexpr OUStringLiteral UNO_NAME_PARENT_NUMBERING = u"ParentNumbering";
36constexpr OUStringLiteral UNO_NAME_PREFIX = u"Prefix";
37constexpr OUStringLiteral UNO_NAME_SUFFIX = u"Suffix";
38constexpr OUStringLiteral UNO_NAME_CHAR_STYLE_NAME = u"CharStyleName";
39constexpr OUStringLiteral UNO_NAME_NUMBERING_TYPE = u"NumberingType";
40constexpr OUStringLiteral UNO_NAME_BULLET_CHAR = u"BulletChar";
41
42constexpr OUStringLiteral CHAR_CLOSED_DOT = u"\u2022";
43constexpr OUStringLiteral CHAR_EMPTY_DOT = u"o";
44constexpr OUStringLiteral CHAR_SQUARE = u"\u2540";
45constexpr OUStringLiteral CHAR_STAR_SYMBOL = u"\u272A";
46constexpr OUStringLiteral CHAR_FOUR_DIAMONDS = u"\u2756";
47constexpr OUStringLiteral CHAR_DIAMOND = u"\u2726";
48constexpr OUStringLiteral CHAR_ARROW = u"\u27A2";
49constexpr OUStringLiteral CHAR_CHECK_MARK = u"\u2713";
50
51SwVbaListHelper::SwVbaListHelper( css::uno::Reference< css::text::XTextDocument > xTextDoc, sal_Int32 nGalleryType, sal_Int32 nTemplateType ) : mxTextDocument(std::move( xTextDoc )), mnGalleryType( nGalleryType ), mnTemplateType( nTemplateType )
52{
53 Init();
54}
55
57{
58 // set the numbering style name
59 switch( mnGalleryType )
60 {
61 case word::WdListGalleryType::wdBulletGallery:
62 {
63 msStyleName = "WdBullet";
64 break;
65 }
66 case word::WdListGalleryType::wdNumberGallery:
67 {
68 msStyleName = "WdNumber";
69 break;
70 }
71 case word::WdListGalleryType::wdOutlineNumberGallery:
72 {
73 msStyleName = "WdOutlineNumber";
74 break;
75 }
76 default:
77 {
78 throw uno::RuntimeException();
79 }
80 }
81 msStyleName += OUString::number( mnTemplateType );
82
83 // get the numbering style
84 uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( mxTextDocument, uno::UNO_QUERY_THROW );
85 mxStyleFamily.set( xStyleSupplier->getStyleFamilies()->getByName("NumberingStyles"), uno::UNO_QUERY_THROW );
86 SAL_INFO("sw.vba", "numbering style name: " << msStyleName );
87 if( mxStyleFamily->hasByName( msStyleName ) )
88 {
89 mxStyleProps.set( mxStyleFamily->getByName( msStyleName ), uno::UNO_QUERY_THROW );
90 mxNumberingRules.set( mxStyleProps->getPropertyValue("NumberingRules"), uno::UNO_QUERY_THROW );
91 }
92 else
93 {
94 // create new numbering style
95 uno::Reference< lang::XMultiServiceFactory > xDocMSF( mxTextDocument, uno::UNO_QUERY_THROW );
96 mxStyleProps.set( xDocMSF->createInstance("com.sun.star.style.NumberingStyle"), uno::UNO_QUERY_THROW );
97 // insert this style into style family, or the property NumberingRules doesn't exist.
99 mxStyleProps->getPropertyValue("NumberingRules") >>= mxNumberingRules;
100
102
103 mxStyleProps->setPropertyValue("NumberingRules", uno::Any( mxNumberingRules ) );
104 }
105}
106
108{
109 switch( mnGalleryType )
110 {
111 case word::WdListGalleryType::wdBulletGallery:
112 {
114 break;
115 }
116 case word::WdListGalleryType::wdNumberGallery:
117 {
119 break;
120 }
121 case word::WdListGalleryType::wdOutlineNumberGallery:
122 {
124 break;
125 }
126 default:
127 {
128 throw uno::RuntimeException();
129 }
130 }
131}
132
134{
135 // there is only 1 level for each bullet list in MSWord
136 sal_Int32 nLevel = 0;
137 uno::Sequence< beans::PropertyValue > aPropertyValues;
138 mxNumberingRules->getByIndex( nLevel ) >>= aPropertyValues;
140 setOrAppendPropertyValue( aPropertyValues, UNO_NAME_NUMBERING_TYPE, uno::Any( sal_Int16(style::NumberingType::CHAR_SPECIAL) ) );
141
142 OUString aBulletChar;
143 switch( mnTemplateType )
144 {
145 case 1:
146 {
147 aBulletChar = CHAR_CLOSED_DOT;
148 break;
149 }
150 case 2:
151 {
152 aBulletChar = CHAR_EMPTY_DOT;
153 break;
154 }
155 case 3:
156 {
157 aBulletChar = CHAR_SQUARE;
158 break;
159 }
160 case 4:
161 {
162 aBulletChar = CHAR_STAR_SYMBOL;
163 break;
164 }
165 case 5:
166 {
167 aBulletChar = CHAR_FOUR_DIAMONDS;
168 break;
169 }
170 case 6:
171 {
172 aBulletChar = CHAR_ARROW;
173 break;
174 }
175 case 7:
176 {
177 aBulletChar = CHAR_CHECK_MARK;
178 break;
179 }
180 default:
181 {
182 // we only support 7 types template now
183 throw css::uno::RuntimeException();
184 }
185 }
187
188 mxNumberingRules->replaceByIndex( nLevel, uno::Any( aPropertyValues ) );
189}
190
192{
193 // there is only 1 level for each bullet list in MSWord
194 sal_Int32 nLevel = 0;
195 uno::Sequence< beans::PropertyValue > aPropertyValues;
196 mxNumberingRules->getByIndex( nLevel ) >>= aPropertyValues;
197
198 sal_Int16 nNumberingType = 0;
199 OUString sSuffix;
200 switch( mnTemplateType )
201 {
202 case 1:
203 {
204 nNumberingType = style::NumberingType::ARABIC;
205 sSuffix = ".";
206 break;
207 }
208 case 2:
209 {
210 nNumberingType = style::NumberingType::ARABIC;
211 sSuffix = ")";
212 break;
213 }
214 case 3:
215 {
216 nNumberingType = style::NumberingType::ROMAN_UPPER;
217 sSuffix = ".";
218 break;
219 }
220 case 4:
221 {
222 nNumberingType = style::NumberingType::CHARS_UPPER_LETTER;
223 sSuffix = ".";
224 break;
225 }
226 case 5:
227 {
228 nNumberingType = style::NumberingType::CHARS_LOWER_LETTER;
229 sSuffix = ")";
230 break;
231 }
232 case 6:
233 {
234 nNumberingType = style::NumberingType::CHARS_LOWER_LETTER;
235 sSuffix = ".";
236 break;
237 }
238 case 7:
239 {
240 nNumberingType = style::NumberingType::ROMAN_LOWER;
241 sSuffix = ".";
242 break;
243 }
244 default:
245 {
246 // we only support 7 types template now
247 throw css::uno::RuntimeException();
248 }
249 }
252
253 mxNumberingRules->replaceByIndex( nLevel, uno::Any( aPropertyValues ) );
254}
255
257{
258 switch( mnTemplateType )
259 {
260 case 1:
261 {
263 break;
264 }
265 case 2:
266 {
268 break;
269 }
270 case 3:
271 {
273 break;
274 }
275 case 4:
276 {
278 break;
279 }
280 case 5:
281 {
283 break;
284 }
285 case 6:
286 {
288 break;
289 }
290 case 7:
291 {
293 break;
294 }
295 default:
296 {
297 // we only support 7 types template now
298 throw css::uno::RuntimeException();
299 }
300 }
301}
302
304{
305 sal_Int16 nNumberingType = 0;
306 OUString sPrefix;
307 OUString sSuffix;
308 uno::Sequence< beans::PropertyValue > aPropertyValues;
309
310 for( sal_Int32 nLevel = 0; nLevel < LIST_LEVEL_COUNT; nLevel++ )
311 {
312 mxNumberingRules->getByIndex( nLevel ) >>= aPropertyValues;
313 switch( nLevel )
314 {
315 case 0:
316 case 1:
317 {
318 nNumberingType = style::NumberingType::ARABIC;
319 sPrefix.clear();
320 sSuffix = ")";
321 break;
322 }
323 case 2:
324 {
325 nNumberingType = style::NumberingType::ROMAN_LOWER;
326 sPrefix.clear();
327 sSuffix = ")";
328 break;
329 }
330 case 3:
331 {
332 nNumberingType = style::NumberingType::ARABIC;
333 sPrefix = "(";
334 sSuffix = ")";
335 break;
336 }
337 case 4:
338 {
339 nNumberingType = style::NumberingType::CHARS_LOWER_LETTER;
340 sPrefix = "(";
341 sSuffix = ")";
342 break;
343 }
344 case 5:
345 {
346 nNumberingType = style::NumberingType::ROMAN_LOWER;
347 sPrefix = "(";
348 sSuffix = ")";
349 break;
350 }
351 case 6:
352 {
353 nNumberingType = style::NumberingType::ARABIC;
354 sPrefix.clear();
355 sSuffix = ".";
356 break;
357 }
358 case 7:
359 {
360 nNumberingType = style::NumberingType::CHARS_LOWER_LETTER;
361 sPrefix.clear();
362 sSuffix = ".";
363 break;
364 }
365 case 8:
366 {
367 nNumberingType = style::NumberingType::ROMAN_LOWER;
368 sPrefix.clear();
369 sSuffix = ".";
370 break;
371 }
372 }
376 mxNumberingRules->replaceByIndex( nLevel, uno::Any( aPropertyValues ) );
377 }
378}
379
381{
382 sal_Int16 nParentNumbering = 0;
383 OUString sSuffix( '.' );
384 uno::Sequence< beans::PropertyValue > aPropertyValues;
385
386 for( sal_Int32 nLevel = 0; nLevel < LIST_LEVEL_COUNT; nLevel++ )
387 {
388 mxNumberingRules->getByIndex( nLevel ) >>= aPropertyValues;
389 setOrAppendPropertyValue( aPropertyValues, UNO_NAME_NUMBERING_TYPE, uno::Any( sal_Int16(style::NumberingType::ARABIC) ) );
391 if( nLevel != 0 )
392 {
393 nParentNumbering = sal_Int16( nLevel - 1 );
395 }
396 mxNumberingRules->replaceByIndex( nLevel, uno::Any( aPropertyValues ) );
397 }
398}
399
401{
402 OUString aBulletChar;
403 uno::Sequence< beans::PropertyValue > aPropertyValues;
404
405 for( sal_Int32 nLevel = 0; nLevel < LIST_LEVEL_COUNT; nLevel++ )
406 {
407 mxNumberingRules->getByIndex( nLevel ) >>= aPropertyValues;
408 setOrAppendPropertyValue( aPropertyValues, UNO_NAME_NUMBERING_TYPE, uno::Any( sal_Int16(style::NumberingType::CHAR_SPECIAL) ) );
410 switch( nLevel )
411 {
412 case 0:
413 {
414 aBulletChar = CHAR_FOUR_DIAMONDS;
415 break;
416 }
417 case 1:
418 case 5:
419 {
420 aBulletChar = CHAR_ARROW;
421 break;
422 }
423 case 2:
424 case 6:
425 {
426 aBulletChar = CHAR_SQUARE;
427 break;
428 }
429 case 3:
430 case 7:
431 {
432 aBulletChar = CHAR_CLOSED_DOT;
433 break;
434 }
435 case 4:
436 case 8:
437 {
438 aBulletChar = CHAR_DIAMOND;
439 break;
440 }
441 }
443 mxNumberingRules->replaceByIndex( nLevel, uno::Any( aPropertyValues ) );
444 }
445}
446
448{
449 sal_Int16 nNumberingType = 0;
450 OUString sPrefix;
451 OUString sSuffix;
452 uno::Sequence< beans::PropertyValue > aPropertyValues;
453
454 for( sal_Int32 nLevel = 0; nLevel < LIST_LEVEL_COUNT; nLevel++ )
455 {
456 mxNumberingRules->getByIndex( nLevel ) >>= aPropertyValues;
457 switch( nLevel )
458 {
459 case 0:
460 {
461 nNumberingType = style::NumberingType::ROMAN_UPPER;
462 sPrefix.clear();
463 sSuffix = ".";
464 break;
465 }
466 case 1:
467 {
468 nNumberingType = style::NumberingType::ARABIC;
469 sPrefix.clear();
470 sSuffix = ".";
472 break;
473 }
474 case 2:
475 {
476 nNumberingType = style::NumberingType::CHARS_LOWER_LETTER;
477 sPrefix = "(";
478 sSuffix = ")";
479 break;
480 }
481 case 3:
482 {
483 nNumberingType = style::NumberingType::ROMAN_LOWER;
484 sPrefix = "(";
485 sSuffix = ")";
486 break;
487 }
488 case 4:
489 {
490 nNumberingType = style::NumberingType::ARABIC;
491 sPrefix.clear();
492 sSuffix = ")";
493 break;
494 }
495 case 5:
496 {
497 nNumberingType = style::NumberingType::CHARS_LOWER_LETTER;
498 sPrefix.clear();
499 sSuffix = ")";
500 break;
501 }
502 case 6:
503 {
504 nNumberingType = style::NumberingType::ROMAN_LOWER;
505 sPrefix.clear();
506 sSuffix = ")";
507 break;
508 }
509 case 7:
510 {
511 nNumberingType = style::NumberingType::CHARS_LOWER_LETTER;
512 sPrefix.clear();
513 sSuffix = ".";
514 break;
515 }
516 case 8:
517 {
518 nNumberingType = style::NumberingType::ROMAN_LOWER;
519 sPrefix.clear();
520 sSuffix = ".";
521 break;
522 }
523 }
527 mxNumberingRules->replaceByIndex( nLevel, uno::Any( aPropertyValues ) );
528 }
529}
530
532{
533 sal_Int16 nParentNumbering = 0;
534 uno::Sequence< beans::PropertyValue > aPropertyValues;
535
536 for( sal_Int32 nLevel = 0; nLevel < LIST_LEVEL_COUNT; nLevel++ )
537 {
538 mxNumberingRules->getByIndex( nLevel ) >>= aPropertyValues;
539 setOrAppendPropertyValue( aPropertyValues, UNO_NAME_NUMBERING_TYPE, uno::Any( sal_Int16(style::NumberingType::ARABIC) ) );
540 if( nLevel != 0 )
541 {
542 nParentNumbering = sal_Int16( nLevel - 1 );
544 }
545 mxNumberingRules->replaceByIndex( nLevel, uno::Any( aPropertyValues ) );
546 }
547}
548
550{
551 sal_Int16 nNumberingType = 0;
552 OUString sPrefix;
553 OUString sSuffix;
554 uno::Sequence< beans::PropertyValue > aPropertyValues;
555
556 for( sal_Int32 nLevel = 0; nLevel < LIST_LEVEL_COUNT; nLevel++ )
557 {
558 mxNumberingRules->getByIndex( nLevel ) >>= aPropertyValues;
559 switch( nLevel )
560 {
561 case 0:
562 {
563 nNumberingType = style::NumberingType::ROMAN_UPPER;
564 sPrefix.clear();
565 sSuffix = ".";
566 break;
567 }
568 case 1:
569 {
570 nNumberingType = style::NumberingType::CHARS_UPPER_LETTER;
571 sPrefix.clear();
572 sSuffix = ".";
573 break;
574 }
575 case 2:
576 {
577 nNumberingType = style::NumberingType::ARABIC;
578 sPrefix.clear();
579 sSuffix = ")";
580 break;
581 }
582 case 3:
583 {
584 nNumberingType = style::NumberingType::CHARS_LOWER_LETTER;
585 sPrefix.clear();
586 sSuffix = ")";
587 break;
588 }
589 case 4:
590 {
591 nNumberingType = style::NumberingType::ARABIC;
592 sPrefix = "(";
593 sSuffix = ")";
594 break;
595 }
596 case 5:
597 {
598 nNumberingType = style::NumberingType::CHARS_LOWER_LETTER;
599 sPrefix = "(";
600 sSuffix = ")";
601 break;
602 }
603 case 6:
604 {
605 nNumberingType = style::NumberingType::ROMAN_LOWER;
606 sPrefix = "(";
607 sSuffix = ")";
608 break;
609 }
610 case 7:
611 {
612 nNumberingType = style::NumberingType::CHARS_LOWER_LETTER;
613 sPrefix = "(";
614 sSuffix = ".";
615 break;
616 }
617 case 8:
618 {
619 nNumberingType = style::NumberingType::ROMAN_LOWER;
620 sPrefix = "(";
621 sSuffix = ".";
622 break;
623 }
624 }
628 mxNumberingRules->replaceByIndex( nLevel, uno::Any( aPropertyValues ) );
629 }
630}
631
633{
634 uno::Sequence< beans::PropertyValue > aPropertyValues;
635
636 for( sal_Int32 nLevel = 0; nLevel < LIST_LEVEL_COUNT; nLevel++ )
637 {
638 mxNumberingRules->getByIndex( nLevel ) >>= aPropertyValues;
639 setOrAppendPropertyValue( aPropertyValues, UNO_NAME_NUMBERING_TYPE, uno::Any( sal_Int16(style::NumberingType::ARABIC) ) );
641 mxNumberingRules->replaceByIndex( nLevel, uno::Any( aPropertyValues ) );
642 }
643}
644
645uno::Any SwVbaListHelper::getPropertyValueWithNameAndLevel( sal_Int32 nLevel, const OUString& sName )
646{
647 uno::Sequence< beans::PropertyValue > aPropertyValues;
648 mxNumberingRules->getByIndex( nLevel ) >>= aPropertyValues;
650}
651
652void SwVbaListHelper::setPropertyValueWithNameAndLevel( sal_Int32 nLevel, const OUString& sName, const css::uno::Any& aValue )
653{
654 uno::Sequence< beans::PropertyValue > aPropertyValues;
655 mxNumberingRules->getByIndex( nLevel ) >>= aPropertyValues;
657 mxNumberingRules->replaceByIndex( nLevel, uno::Any( aPropertyValues ) );
658 mxStyleProps->setPropertyValue("NumberingRules", uno::Any( mxNumberingRules ) );
659}
660
661/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
PropertyValueVector_t aPropertyValues
void CreateOutlineNumberForType3()
SwVbaListHelper(css::uno::Reference< css::text::XTextDocument > xTextDoc, sal_Int32 nGalleryType, sal_Int32 nTemplateType)
css::uno::Reference< css::beans::XPropertySet > mxStyleProps
css::uno::Reference< css::container::XIndexReplace > mxNumberingRules
sal_Int32 mnGalleryType
void CreateOutlineNumberForType5()
void CreateOutlineNumberForType7()
void CreateOutlineNumberListTemplate()
void CreateOutlineNumberForType4()
void CreateOutlineNumberForType1()
OUString msStyleName
void CreateBulletListTemplate()
sal_Int32 mnTemplateType
void CreateNumberListTemplate()
css::uno::Reference< css::container::XNameContainer > mxStyleFamily
void CreateOutlineNumberForType6()
void CreateOutlineNumberForType2()
void setPropertyValueWithNameAndLevel(sal_Int32 nLevel, const OUString &sName, const css::uno::Any &aValue)
css::uno::Reference< css::text::XTextDocument > mxTextDocument
css::uno::Any getPropertyValueWithNameAndLevel(sal_Int32 nLevel, const OUString &sName)
float u
OUString sName
OUString sSuffix
OUString sPrefix
sal_Int16 nParentNumbering
#define SAL_INFO(area, stream)
VBAHELPER_DLLPUBLIC void setOrAppendPropertyValue(css::uno::Sequence< css::beans::PropertyValue > &aProp, const OUString &aName, const css::uno::Any &aValue)
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
constexpr OUStringLiteral UNO_NAME_NUMBERING_TYPE
constexpr OUStringLiteral CHAR_CLOSED_DOT
constexpr OUStringLiteral CHAR_ARROW
constexpr OUStringLiteral UNO_NAME_SUFFIX
constexpr OUStringLiteral CHAR_CHECK_MARK
constexpr OUStringLiteral UNO_NAME_CHAR_STYLE_NAME
constexpr OUStringLiteral UNO_NAME_PARENT_NUMBERING
constexpr OUStringLiteral UNO_NAME_BULLET_CHAR
constexpr OUStringLiteral UNO_NAME_PREFIX
constexpr OUStringLiteral CHAR_EMPTY_DOT
const sal_Int32 LIST_LEVEL_COUNT
constexpr OUStringLiteral CHAR_FOUR_DIAMONDS
constexpr OUStringLiteral CHAR_DIAMOND
constexpr OUStringLiteral CHAR_SQUARE
constexpr OUStringLiteral CHAR_STAR_SYMBOL