LibreOffice Module sw (master)  1
vbalistformat.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 "vbalistformat.hxx"
20 #include <vbahelper/vbahelper.hxx>
21 #include <ooo/vba/word/WdListApplyTo.hpp>
22 #include <ooo/vba/word/WdDefaultListBehavior.hpp>
23 #include <com/sun/star/container/XEnumerationAccess.hpp>
24 #include <com/sun/star/container/XEnumeration.hpp>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include "vbalisttemplate.hxx"
27 
28 using namespace ::ooo::vba;
29 using namespace ::com::sun::star;
30 
31 SwVbaListFormat::SwVbaListFormat( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< text::XTextRange >& xTextRange ) : SwVbaListFormat_BASE( rParent, rContext ), mxTextRange( xTextRange )
32 {
33 }
34 
36 {
37 }
38 
39 void SAL_CALL SwVbaListFormat::ApplyListTemplate( const css::uno::Reference< word::XListTemplate >& ListTemplate, const css::uno::Any& ContinuePreviousList, const css::uno::Any& ApplyTo, const css::uno::Any& DefaultListBehavior )
40 {
41  bool bContinuePreviousList = true;
42  if( ContinuePreviousList.hasValue() )
43  ContinuePreviousList >>= bContinuePreviousList;
44 
45  // "applyto" must be current selection
46  sal_Int32 bApplyTo = word::WdListApplyTo::wdListApplyToSelection;
47  if( ApplyTo.hasValue() )
48  ApplyTo >>= bApplyTo;
49  if( bApplyTo != word::WdListApplyTo::wdListApplyToSelection )
50  throw uno::RuntimeException();
51 
52  // default behaviour must be wdWord8ListBehavior
53  sal_Int32 nDefaultListBehavior = word::WdDefaultListBehavior::wdWord8ListBehavior;
54  if( DefaultListBehavior.hasValue() )
55  DefaultListBehavior >>= nDefaultListBehavior;
56  if( nDefaultListBehavior != word::WdDefaultListBehavior::wdWord8ListBehavior )
57  throw uno::RuntimeException();
58 
59  uno::Reference< container::XEnumerationAccess > xEnumAccess( mxTextRange, uno::UNO_QUERY_THROW );
60  uno::Reference< container::XEnumeration > xEnum = xEnumAccess->createEnumeration();
61  if (!xEnum->hasMoreElements())
62  return;
63 
64  SwVbaListTemplate& rListTemplate = dynamic_cast<SwVbaListTemplate&>(*ListTemplate);
65 
66  bool isFirstElement = true;
67  do
68  {
69  uno::Reference< beans::XPropertySet > xProps( xEnum->nextElement(), uno::UNO_QUERY_THROW );
70  if( isFirstElement )
71  {
72  bool isNumberingRestart = !bContinuePreviousList;
73  xProps->setPropertyValue("ParaIsNumberingRestart", uno::makeAny( isNumberingRestart ) );
74  if( isNumberingRestart )
75  {
76  xProps->setPropertyValue("NumberingStartValue", uno::makeAny( sal_Int16(1) ) );
77  }
78  isFirstElement = false;
79  }
80  else
81  {
82  xProps->setPropertyValue("ParaIsNumberingRestart", uno::makeAny( false ) );
83  }
84  rListTemplate.applyListTemplate( xProps );
85  }
86  while( xEnum->hasMoreElements() );
87 }
88 
90 {
91  throw uno::RuntimeException("Not implemented" );
92 }
93 
94 OUString
96 {
97  return "SwVbaListFormat";
98 }
99 
100 uno::Sequence< OUString >
102 {
103  static uno::Sequence< OUString > const aServiceNames
104  {
105  "ooo.vba.word.ListFormat"
106  };
107  return aServiceNames;
108 }
109 
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL ApplyListTemplate(const css::uno::Reference< ::ooo::vba::word::XListTemplate > &ListTemplate, const css::uno::Any &ContinuePreviousList, const css::uno::Any &ApplyTo, const css::uno::Any &DefaultListBehavior) override
virtual OUString getServiceImplName() override
Sequence< OUString > aServiceNames
SwVbaListFormat(const css::uno::Reference< ooo::vba::XHelperInterface > &rParent, const css::uno::Reference< css::uno::XComponentContext > &rContext, const css::uno::Reference< css::text::XTextRange > &xTextRange)
void applyListTemplate(css::uno::Reference< css::beans::XPropertySet > const &xProps)
css::uno::Reference< css::text::XTextRange > mxTextRange
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual void SAL_CALL ConvertNumbersToText() override
virtual ~SwVbaListFormat() override