1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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 <i18nlangtag/languagetag.hxx>
26 #include "vbafont.hxx"
27 #include "vbapalette.hxx"
28 #include "vbaparagraphformat.hxx"
29 #include "vbastyles.hxx"
31 using namespace ::ooo::vba
;
32 using namespace ::com::sun::star
;
34 SwVbaStyle::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
)
36 mxStyle
.set( _xPropertySet
, uno::UNO_QUERY_THROW
);
40 SwVbaStyle::setName( const OUString
& Name
)
42 mxStyle
->setName(Name
);
48 return mxStyle
->getName();
51 LanguageType
SwVbaStyle::getLanguageID( const uno::Reference
< beans::XPropertySet
>& xTCProps
)
54 xTCProps
->getPropertyValue("CharLocale") >>= aLocale
;
55 return LanguageTag::convertToLanguageType( aLocale
, false);
58 void SwVbaStyle::setLanguageID( const uno::Reference
< beans::XPropertySet
>& xTCProps
, LanguageType _languageid
)
60 lang::Locale aLocale
= LanguageTag( _languageid
).getLocale();
61 xTCProps
->setPropertyValue("CharLocale", uno::Any( aLocale
) ) ;
64 ::sal_Int32 SAL_CALL
SwVbaStyle::getLanguageID()
66 return static_cast<sal_uInt16
>(getLanguageID( mxStyleProps
));
69 void SAL_CALL
SwVbaStyle::setLanguageID( ::sal_Int32 _languageid
)
71 setLanguageID( mxStyleProps
, LanguageType(_languageid
) );
74 ::sal_Int32 SAL_CALL
SwVbaStyle::getType()
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
;
83 nType
= word::WdStyleType::wdStyleTypeList
;
87 uno::Reference
< word::XFont
> SAL_CALL
91 return new SwVbaFont( mxParent
, mxContext
, aColors
.getPalette(), mxStyleProps
);
94 void SwVbaStyle::setStyle( const uno::Reference
< beans::XPropertySet
>& xParaProps
, const uno::Any
& rStyle
)
97 uno::Reference
< word::XStyle
> xStyle
;
98 if( rStyle
>>= xStyle
)
100 sStyle
= xStyle
->getName();
107 if( !sStyle
.isEmpty() )
109 xParaProps
->setPropertyValue("ParaStyleName", uno::Any( sStyle
) );
113 throw uno::RuntimeException();
116 OUString SAL_CALL
SwVbaStyle::getNameLocal()
119 mxStyleProps
->getPropertyValue("DisplayName") >>= sNameLocal
;
123 void SAL_CALL
SwVbaStyle::setNameLocal( const OUString
& _namelocal
)
125 mxStyleProps
->setPropertyValue("DisplayName", uno::Any( _namelocal
) );
128 uno::Reference
< word::XParagraphFormat
> SAL_CALL
SwVbaStyle::getParagraphFormat()
130 if( word::WdStyleType::wdStyleTypeParagraph
!= getType() )
132 throw uno::RuntimeException();
135 uno::Reference
< text::XTextDocument
> xTextDocument( mxModel
, uno::UNO_QUERY_THROW
);
136 return uno::Reference
< word::XParagraphFormat
>( new SwVbaParagraphFormat( this, mxContext
, mxStyleProps
) );
139 sal_Bool SAL_CALL
SwVbaStyle::getAutomaticallyUpdate()
141 bool isAutoUpdate
= false;
142 mxStyleProps
->getPropertyValue("IsAutoUpdate") >>= isAutoUpdate
;
146 void SAL_CALL
SwVbaStyle::setAutomaticallyUpdate( sal_Bool _automaticallyupdate
)
148 mxStyleProps
->setPropertyValue("IsAutoUpdate", uno::Any( _automaticallyupdate
) );
151 uno::Any SAL_CALL
SwVbaStyle::getBaseStyle()
155 mxStyleProps
->getPropertyValue("ParentStyle") >>= sBaseStyle
;
156 if( sBaseStyle
.isEmpty() )
158 throw uno::RuntimeException();
161 uno::Reference
< XCollection
> xCol( new SwVbaStyles( this, mxContext
, mxModel
) );
162 return xCol
->Item( uno::Any( sBaseStyle
), uno::Any() );
165 void SAL_CALL
SwVbaStyle::setBaseStyle( const uno::Any
& _basestyle
)
167 uno::Reference
< word::XStyle
> xStyle
;
168 _basestyle
>>= xStyle
;
171 throw uno::RuntimeException();
174 OUString sBaseStyle
= xStyle
->getName();
175 mxStyleProps
->setPropertyValue("ParentStyle", uno::Any( sBaseStyle
) );
178 uno::Any SAL_CALL
SwVbaStyle::getNextParagraphStyle()
181 OUString sFollowStyle
;
182 mxStyleProps
->getPropertyValue("FollowStyle") >>= sFollowStyle
;
183 if( sFollowStyle
.isEmpty() )
185 throw uno::RuntimeException();
188 uno::Reference
< XCollection
> xCol( new SwVbaStyles( this, mxContext
, mxModel
) );
189 return xCol
->Item( uno::Any( sFollowStyle
), uno::Any() );
192 void SAL_CALL
SwVbaStyle::setNextParagraphStyle( const uno::Any
& _nextparagraphstyle
)
194 uno::Reference
< word::XStyle
> xStyle
;
195 _nextparagraphstyle
>>= xStyle
;
198 throw uno::RuntimeException();
201 OUString sFollowStyle
= xStyle
->getName();
202 mxStyleProps
->setPropertyValue("FollowStyle", uno::Any( sFollowStyle
) );
205 ::sal_Int32 SAL_CALL
SwVbaStyle::getListLevelNumber()
207 sal_Int16 nNumberingLevel
= 0;
208 mxStyleProps
->getPropertyValue("NumberingLevel") >>= nNumberingLevel
;
209 return nNumberingLevel
;
213 SwVbaStyle::getServiceImplName()
218 uno::Sequence
< OUString
>
219 SwVbaStyle::getServiceNames()
221 static uno::Sequence
< OUString
> const aServiceNames
223 "ooo.vba.word.XStyle"
225 return aServiceNames
;
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */