xref: /aoo42x/main/sw/source/ui/vba/vbastyle.cxx (revision efeef26f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "vbastyle.hxx"
25 #include <ooo/vba/word/WdStyleType.hpp>
26 #include <com/sun/star/lang/Locale.hpp>
27 #include <i18npool/mslangid.hxx>
28 #include "vbafont.hxx"
29 #include "vbapalette.hxx"
30 
31 using namespace ::ooo::vba;
32 using namespace ::com::sun::star;
33 
34 
SwVbaStyle(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext,const uno::Reference<beans::XPropertySet> & _xPropertySet)35 SwVbaStyle::SwVbaStyle( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< beans::XPropertySet >& _xPropertySet ) throw ( script::BasicErrorException, uno::RuntimeException ) : SwVbaStyle_BASE( xParent, xContext ) , mxStyleProps( _xPropertySet )
36 {
37     mxStyle.set( _xPropertySet, uno::UNO_QUERY_THROW );
38 }
39 
40 void SAL_CALL
setName(const::rtl::OUString & Name)41 SwVbaStyle::setName( const ::rtl::OUString& Name ) throw (uno::RuntimeException)
42 {
43 	mxStyle->setName(Name);
44 }
45 
46 ::rtl::OUString SAL_CALL
getName()47 SwVbaStyle::getName() throw (uno::RuntimeException)
48 {
49 	return mxStyle->getName();
50 }
51 
getLanguageID(const uno::Reference<beans::XPropertySet> & xTCProps)52 sal_Int32 SwVbaStyle::getLanguageID( const uno::Reference< beans::XPropertySet >& xTCProps ) throw (uno::RuntimeException)
53 {
54     lang::Locale aLocale;
55     xTCProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CharLocale") ) ) >>= aLocale;
56     return MsLangId::convertLocaleToLanguage( aLocale );
57 }
58 
setLanguageID(const uno::Reference<beans::XPropertySet> & xTCProps,sal_Int32 _languageid)59 void SwVbaStyle::setLanguageID( const uno::Reference< beans::XPropertySet >& xTCProps, sal_Int32 _languageid ) throw (uno::RuntimeException)
60 {
61     lang::Locale aLocale = MsLangId::convertLanguageToLocale( static_cast<LanguageType>(_languageid) );
62     xTCProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CharLocale") ), uno::makeAny( aLocale ) ) ;
63 }
64 
getLanguageID()65 ::sal_Int32 SAL_CALL SwVbaStyle::getLanguageID() throw (uno::RuntimeException)
66 {
67     return getLanguageID( mxStyleProps );
68 }
69 
setLanguageID(::sal_Int32 _languageid)70 void SAL_CALL SwVbaStyle::setLanguageID( ::sal_Int32 _languageid ) throw (uno::RuntimeException)
71 {
72     setLanguageID( mxStyleProps, _languageid );
73 }
74 
getType()75 ::sal_Int32 SAL_CALL SwVbaStyle::getType() throw (uno::RuntimeException)
76 {
77     sal_Int32 nType = word::WdStyleType::wdStyleTypeParagraph;
78     uno::Reference< lang::XServiceInfo > xServiceInfo( mxStyle, uno::UNO_QUERY_THROW );
79     if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.style.ParagraphStyle") ) ) )
80         nType = word::WdStyleType::wdStyleTypeParagraph;
81     else if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.style.CharacterStyle") ) ) )
82         nType = word::WdStyleType::wdStyleTypeCharacter;
83     else // if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.NumberingStyle") ) ) )
84         nType = word::WdStyleType::wdStyleTypeList;
85     return nType;
86 }
87 
88 uno::Reference< word::XFont > SAL_CALL
getFont()89 SwVbaStyle::getFont() throw ( uno::RuntimeException )
90 {
91     VbaPalette aColors;
92     return new SwVbaFont( mxParent, mxContext, aColors.getPalette(), mxStyleProps );
93 }
94 
setStyle(const uno::Reference<beans::XPropertySet> & xTCProps,const uno::Reference<ooo::vba::word::XStyle> & xStyle)95 void SwVbaStyle::setStyle( const uno::Reference< beans::XPropertySet >& xTCProps, const uno::Reference< ooo::vba::word::XStyle >& xStyle )throw (uno::RuntimeException)
96 {
97     rtl::OUString aStyleType = getOOoStyleTypeFromMSWord( xStyle->getType() );
98     xTCProps->setPropertyValue( aStyleType, uno::makeAny( xStyle->getName() ) );
99 }
100 
getOOoStyleTypeFromMSWord(sal_Int32 _wdStyleType)101 rtl::OUString SwVbaStyle::getOOoStyleTypeFromMSWord( sal_Int32 _wdStyleType )
102 {
103     rtl::OUString aStyleType;
104     switch( _wdStyleType )
105     {
106         case word::WdStyleType::wdStyleTypeParagraph:
107         case word::WdStyleType::wdStyleTypeTable:
108         {
109             aStyleType = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaStyleName") );
110             break;
111         }
112         case word::WdStyleType::wdStyleTypeCharacter:
113         {
114             aStyleType = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CharStyleName") );
115             break;
116         }
117         case word::WdStyleType::wdStyleTypeList:
118         {
119             aStyleType = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NumberingStyleName") );
120             break;
121         }
122         default:
123             DebugHelper::exception( SbERR_INTERNAL_ERROR, rtl::OUString() );
124     }
125     return aStyleType;
126 }
127 
128 rtl::OUString&
getServiceImplName()129 SwVbaStyle::getServiceImplName()
130 {
131     static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaStyle") );
132     return sImplName;
133 }
134 
135 uno::Sequence< rtl::OUString >
getServiceNames()136 SwVbaStyle::getServiceNames()
137 {
138     static uno::Sequence< rtl::OUString > aServiceNames;
139     if ( aServiceNames.getLength() == 0 )
140     {
141         aServiceNames.realloc( 1 );
142         aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.XStyle" ) );
143     }
144     return aServiceNames;
145 }
146