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 <tools/diagnose_ex.h>
22 #include <ooo/vba/word/WdListApplyTo.hpp>
23 #include <ooo/vba/word/WdDefaultListBehavior.hpp>
24 #include <com/sun/star/container/XEnumerationAccess.hpp>
25 #include <com/sun/star/container/XEnumeration.hpp>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include "vbalisttemplate.hxx"
28 
29 using namespace ::ooo::vba;
30 using namespace ::com::sun::star;
31 
32 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 )
33 {
34 }
35 
37 {
38 }
39 
40 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 )
41 {
42  bool bContinuePreviousList = true;
43  if( ContinuePreviousList.hasValue() )
44  ContinuePreviousList >>= bContinuePreviousList;
45 
46  // "applyto" must be current selection
47  sal_Int32 bApplyTo = word::WdListApplyTo::wdListApplyToSelection;
48  if( ApplyTo.hasValue() )
49  ApplyTo >>= bApplyTo;
50  if( bApplyTo != word::WdListApplyTo::wdListApplyToSelection )
51  throw uno::RuntimeException();
52 
53  // default behaviour must be wdWord8ListBehavior
54  sal_Int32 nDefaultListBehavior = word::WdDefaultListBehavior::wdWord8ListBehavior;
55  if( DefaultListBehavior.hasValue() )
56  DefaultListBehavior >>= nDefaultListBehavior;
57  if( nDefaultListBehavior != word::WdDefaultListBehavior::wdWord8ListBehavior )
58  throw uno::RuntimeException();
59 
60  uno::Reference< container::XEnumerationAccess > xEnumAccess( mxTextRange, uno::UNO_QUERY_THROW );
61  uno::Reference< container::XEnumeration > xEnum = xEnumAccess->createEnumeration();
62  if (!xEnum->hasMoreElements())
63  return;
64 
65  SwVbaListTemplate& rListTemplate = dynamic_cast<SwVbaListTemplate&>(*ListTemplate);
66 
67  bool isFirstElement = true;
68  do
69  {
70  uno::Reference< beans::XPropertySet > xProps( xEnum->nextElement(), uno::UNO_QUERY_THROW );
71  if( isFirstElement )
72  {
73  bool isNumberingRestart = !bContinuePreviousList;
74  xProps->setPropertyValue("ParaIsNumberingRestart", uno::makeAny( isNumberingRestart ) );
75  if( isNumberingRestart )
76  {
77  xProps->setPropertyValue("NumberingStartValue", uno::makeAny( sal_Int16(1) ) );
78  }
79  isFirstElement = false;
80  }
81  else
82  {
83  xProps->setPropertyValue("ParaIsNumberingRestart", uno::makeAny( false ) );
84  }
85  rListTemplate.applyListTemplate( xProps );
86  }
87  while( xEnum->hasMoreElements() );
88 }
89 
91 {
92  throw uno::RuntimeException("Not implemented" );
93 }
94 
95 OUString
97 {
98  return "SwVbaListFormat";
99 }
100 
101 uno::Sequence< OUString >
103 {
104  static uno::Sequence< OUString > const aServiceNames
105  {
106  "ooo.vba.word.ListFormat"
107  };
108  return aServiceNames;
109 }
110 
111 /* 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
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