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