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