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