LibreOffice Module sw (master) 1
vbastyle.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
20#include "vbastyle.hxx"
21#include <ooo/vba/word/WdStyleType.hpp>
22#include <com/sun/star/lang/Locale.hpp>
23#include <com/sun/star/text/XTextDocument.hpp>
25#include <utility>
26#include "vbafont.hxx"
27#include "vbapalette.hxx"
29#include "vbastyles.hxx"
30
31using namespace ::ooo::vba;
32using namespace ::com::sun::star;
33
34SwVbaStyle::SwVbaStyle( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, uno::Reference< frame::XModel> xModel, const uno::Reference< beans::XPropertySet >& _xPropertySet ) : SwVbaStyle_BASE( xParent, xContext ) , mxModel(std::move( xModel )), mxStyleProps( _xPropertySet )
35{
36 mxStyle.set( _xPropertySet, uno::UNO_QUERY_THROW );
37}
38
39void SAL_CALL
40SwVbaStyle::setName( const OUString& Name )
41{
42 mxStyle->setName(Name);
43}
44
45OUString SAL_CALL
47{
48 return mxStyle->getName();
49}
50
51LanguageType SwVbaStyle::getLanguageID( const uno::Reference< beans::XPropertySet >& xTCProps )
52{
53 lang::Locale aLocale;
54 xTCProps->getPropertyValue("CharLocale") >>= aLocale;
55 return LanguageTag::convertToLanguageType( aLocale, false);
56}
57
58void SwVbaStyle::setLanguageID( const uno::Reference< beans::XPropertySet >& xTCProps, LanguageType _languageid )
59{
60 lang::Locale aLocale = LanguageTag( _languageid ).getLocale();
61 xTCProps->setPropertyValue("CharLocale", uno::Any( aLocale ) ) ;
62}
63
64::sal_Int32 SAL_CALL SwVbaStyle::getLanguageID()
65{
66 return static_cast<sal_uInt16>(getLanguageID( mxStyleProps ));
67}
68
69void SAL_CALL SwVbaStyle::setLanguageID( ::sal_Int32 _languageid )
70{
72}
73
74::sal_Int32 SAL_CALL SwVbaStyle::getType()
75{
76 sal_Int32 nType = word::WdStyleType::wdStyleTypeParagraph;
77 uno::Reference< lang::XServiceInfo > xServiceInfo( mxStyle, uno::UNO_QUERY_THROW );
78 if( xServiceInfo->supportsService("com.sun.star.style.ParagraphStyle") )
79 nType = word::WdStyleType::wdStyleTypeParagraph;
80 else if( xServiceInfo->supportsService("com.sun.star.style.CharacterStyle") )
81 nType = word::WdStyleType::wdStyleTypeCharacter;
82 else
83 nType = word::WdStyleType::wdStyleTypeList;
84 return nType;
85}
86
87uno::Reference< word::XFont > SAL_CALL
89{
90 VbaPalette aColors;
91 return new SwVbaFont( mxParent, mxContext, aColors.getPalette(), mxStyleProps );
92}
93
94void SwVbaStyle::setStyle( const uno::Reference< beans::XPropertySet >& xParaProps, const uno::Any& rStyle )
95{
96 OUString sStyle;
97 uno::Reference< word::XStyle > xStyle;
98 if( rStyle >>= xStyle )
99 {
100 sStyle = xStyle->getName();
101 }
102 else
103 {
104 rStyle >>= sStyle;
105 }
106
107 if( !sStyle.isEmpty() )
108 {
109 xParaProps->setPropertyValue("ParaStyleName", uno::Any( sStyle ) );
110 return;
111 }
112
113 throw uno::RuntimeException();
114}
115
116OUString SAL_CALL SwVbaStyle::getNameLocal()
117{
118 OUString sNameLocal;
119 mxStyleProps->getPropertyValue("DisplayName") >>= sNameLocal;
120 return sNameLocal;
121}
122
123void SAL_CALL SwVbaStyle::setNameLocal( const OUString& _namelocal )
124{
125 mxStyleProps->setPropertyValue("DisplayName", uno::Any( _namelocal ) );
126}
127
128uno::Reference< word::XParagraphFormat > SAL_CALL SwVbaStyle::getParagraphFormat()
129{
130 if( word::WdStyleType::wdStyleTypeParagraph != getType() )
131 {
132 throw uno::RuntimeException();
133 }
134
135 uno::Reference< text::XTextDocument > xTextDocument( mxModel, uno::UNO_QUERY_THROW );
136 return uno::Reference< word::XParagraphFormat >( new SwVbaParagraphFormat( this, mxContext, mxStyleProps ) );
137}
138
140{
141 bool isAutoUpdate = false;
142 mxStyleProps->getPropertyValue("IsAutoUpdate") >>= isAutoUpdate;
143 return isAutoUpdate;
144}
145
146void SAL_CALL SwVbaStyle::setAutomaticallyUpdate( sal_Bool _automaticallyupdate )
147{
148 mxStyleProps->setPropertyValue("IsAutoUpdate", uno::Any( _automaticallyupdate ) );
149}
150
152{
153 // ParentStyle
154 OUString sBaseStyle;
155 mxStyleProps->getPropertyValue("ParentStyle") >>= sBaseStyle;
156 if( sBaseStyle.isEmpty() )
157 {
158 throw uno::RuntimeException();
159 }
160
161 uno::Reference< XCollection > xCol( new SwVbaStyles( this, mxContext, mxModel ) );
162 return xCol->Item( uno::Any( sBaseStyle ), uno::Any() );
163}
164
165void SAL_CALL SwVbaStyle::setBaseStyle( const uno::Any& _basestyle )
166{
167 uno::Reference< word::XStyle > xStyle;
168 _basestyle >>= xStyle;
169 if( !xStyle.is() )
170 {
171 throw uno::RuntimeException();
172 }
173
174 OUString sBaseStyle = xStyle->getName();
175 mxStyleProps->setPropertyValue("ParentStyle", uno::Any( sBaseStyle ) );
176}
177
179{
180 //FollowStyle
181 OUString sFollowStyle;
182 mxStyleProps->getPropertyValue("FollowStyle") >>= sFollowStyle;
183 if( sFollowStyle.isEmpty() )
184 {
185 throw uno::RuntimeException();
186 }
187
188 uno::Reference< XCollection > xCol( new SwVbaStyles( this, mxContext, mxModel ) );
189 return xCol->Item( uno::Any( sFollowStyle ), uno::Any() );
190}
191
192void SAL_CALL SwVbaStyle::setNextParagraphStyle( const uno::Any& _nextparagraphstyle )
193{
194 uno::Reference< word::XStyle > xStyle;
195 _nextparagraphstyle >>= xStyle;
196 if( !xStyle.is() )
197 {
198 throw uno::RuntimeException();
199 }
200
201 OUString sFollowStyle = xStyle->getName();
202 mxStyleProps->setPropertyValue("FollowStyle", uno::Any( sFollowStyle ) );
203}
204
205::sal_Int32 SAL_CALL SwVbaStyle::getListLevelNumber()
206{
207 sal_Int16 nNumberingLevel = 0;
208 mxStyleProps->getPropertyValue("NumberingLevel") >>= nNumberingLevel;
209 return nNumberingLevel;
210}
211
212OUString
214{
215 return "SwVbaStyle";
216}
217
218uno::Sequence< OUString >
220{
221 static uno::Sequence< OUString > const aServiceNames
222 {
223 "ooo.vba.word.XStyle"
224 };
225 return aServiceNames;
226}
227
228/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::frame::XModel2 > mxModel
css::uno::Reference< css::uno::XComponentContext > mxContext
css::uno::WeakReference< ov::XHelperInterface > mxParent
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
static LanguageType convertToLanguageType(const css::lang::Locale &rLocale, bool bResolveSystem=true)
virtual ::sal_Int32 SAL_CALL getType() override
Definition: vbastyle.cxx:74
virtual ::sal_Int32 SAL_CALL getLanguageID() override
Definition: vbastyle.cxx:64
virtual ::sal_Int32 SAL_CALL getListLevelNumber() override
Definition: vbastyle.cxx:205
virtual OUString getServiceImplName() override
Definition: vbastyle.cxx:213
virtual css::uno::Any SAL_CALL getBaseStyle() override
Definition: vbastyle.cxx:151
css::uno::Reference< css::beans::XPropertySet > mxStyleProps
Definition: vbastyle.hxx:36
virtual void SAL_CALL setAutomaticallyUpdate(sal_Bool _automaticallyupdate) override
Definition: vbastyle.cxx:146
static void setStyle(const css::uno::Reference< css::beans::XPropertySet > &xParaProps, const css::uno::Any &xStyle)
Definition: vbastyle.cxx:94
css::uno::Reference< css::style::XStyle > mxStyle
Definition: vbastyle.hxx:37
virtual void SAL_CALL setBaseStyle(const css::uno::Any &_basestyle) override
Definition: vbastyle.cxx:165
virtual css::uno::Reference< ::ooo::vba::word::XParagraphFormat > SAL_CALL getParagraphFormat() override
Definition: vbastyle.cxx:128
virtual css::uno::Any SAL_CALL getNextParagraphStyle() override
Definition: vbastyle.cxx:178
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbastyle.cxx:219
virtual void SAL_CALL setName(const OUString &Name) override
Definition: vbastyle.cxx:40
css::uno::Reference< css::frame::XModel > mxModel
Definition: vbastyle.hxx:35
virtual OUString SAL_CALL getNameLocal() override
Definition: vbastyle.cxx:116
virtual void SAL_CALL setNextParagraphStyle(const css::uno::Any &_nextparagraphstyle) override
Definition: vbastyle.cxx:192
virtual css::uno::Reference< ooo::vba::word::XFont > SAL_CALL getFont() override
Definition: vbastyle.cxx:88
virtual void SAL_CALL setNameLocal(const OUString &_namelocal) override
Definition: vbastyle.cxx:123
SwVbaStyle(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, css::uno::Reference< css::frame::XModel > xModel, const css::uno::Reference< css::beans::XPropertySet > &_xPropertySet)
Definition: vbastyle.cxx:34
static void setLanguageID(const css::uno::Reference< css::beans::XPropertySet > &xTCProps, LanguageType _languageid)
virtual OUString SAL_CALL getName() override
Definition: vbastyle.cxx:46
virtual sal_Bool SAL_CALL getAutomaticallyUpdate() override
Definition: vbastyle.cxx:139
const css::uno::Reference< css::container::XIndexAccess > & getPalette() const
Definition: vbapalette.hxx:32
Sequence< OUString > aServiceNames
Reference< XPropertySet > _xPropertySet
QPRO_FUNC_TYPE nType
Reference< XModel > xModel
OUString Name
unsigned char sal_Bool