1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "vbastyle.hxx" 29 #include <ooo/vba/word/WdStyleType.hpp> 30 #include <com/sun/star/lang/Locale.hpp> 31 #include <i18npool/mslangid.hxx> 32 #include "vbafont.hxx" 33 #include "vbapalette.hxx" 34 35 using namespace ::ooo::vba; 36 using namespace ::com::sun::star; 37 38 39 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 ) 40 { 41 mxStyle.set( _xPropertySet, uno::UNO_QUERY_THROW ); 42 } 43 44 void SAL_CALL 45 SwVbaStyle::setName( const ::rtl::OUString& Name ) throw (uno::RuntimeException) 46 { 47 mxStyle->setName(Name); 48 } 49 50 ::rtl::OUString SAL_CALL 51 SwVbaStyle::getName() throw (uno::RuntimeException) 52 { 53 return mxStyle->getName(); 54 } 55 56 sal_Int32 SwVbaStyle::getLanguageID( const uno::Reference< beans::XPropertySet >& xTCProps ) throw (uno::RuntimeException) 57 { 58 lang::Locale aLocale; 59 xTCProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CharLocale") ) ) >>= aLocale; 60 return MsLangId::convertLocaleToLanguage( aLocale ); 61 } 62 63 void SwVbaStyle::setLanguageID( const uno::Reference< beans::XPropertySet >& xTCProps, sal_Int32 _languageid ) throw (uno::RuntimeException) 64 { 65 lang::Locale aLocale = MsLangId::convertLanguageToLocale( static_cast<LanguageType>(_languageid) ); 66 xTCProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CharLocale") ), uno::makeAny( aLocale ) ) ; 67 } 68 69 ::sal_Int32 SAL_CALL SwVbaStyle::getLanguageID() throw (uno::RuntimeException) 70 { 71 return getLanguageID( mxStyleProps ); 72 } 73 74 void SAL_CALL SwVbaStyle::setLanguageID( ::sal_Int32 _languageid ) throw (uno::RuntimeException) 75 { 76 setLanguageID( mxStyleProps, _languageid ); 77 } 78 79 ::sal_Int32 SAL_CALL SwVbaStyle::getType() throw (uno::RuntimeException) 80 { 81 sal_Int32 nType = word::WdStyleType::wdStyleTypeParagraph; 82 uno::Reference< lang::XServiceInfo > xServiceInfo( mxStyle, uno::UNO_QUERY_THROW ); 83 if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.style.ParagraphStyle") ) ) ) 84 nType = word::WdStyleType::wdStyleTypeParagraph; 85 else if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.style.CharacterStyle") ) ) ) 86 nType = word::WdStyleType::wdStyleTypeCharacter; 87 else // if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.NumberingStyle") ) ) ) 88 nType = word::WdStyleType::wdStyleTypeList; 89 return nType; 90 } 91 92 uno::Reference< word::XFont > SAL_CALL 93 SwVbaStyle::getFont() throw ( uno::RuntimeException ) 94 { 95 VbaPalette aColors; 96 return new SwVbaFont( mxParent, mxContext, aColors.getPalette(), mxStyleProps ); 97 } 98 99 void SwVbaStyle::setStyle( const uno::Reference< beans::XPropertySet >& xTCProps, const uno::Reference< ooo::vba::word::XStyle >& xStyle )throw (uno::RuntimeException) 100 { 101 rtl::OUString aStyleType = getOOoStyleTypeFromMSWord( xStyle->getType() ); 102 xTCProps->setPropertyValue( aStyleType, uno::makeAny( xStyle->getName() ) ); 103 } 104 105 rtl::OUString SwVbaStyle::getOOoStyleTypeFromMSWord( sal_Int32 _wdStyleType ) 106 { 107 rtl::OUString aStyleType; 108 switch( _wdStyleType ) 109 { 110 case word::WdStyleType::wdStyleTypeParagraph: 111 case word::WdStyleType::wdStyleTypeTable: 112 { 113 aStyleType = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaStyleName") ); 114 break; 115 } 116 case word::WdStyleType::wdStyleTypeCharacter: 117 { 118 aStyleType = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CharStyleName") ); 119 break; 120 } 121 case word::WdStyleType::wdStyleTypeList: 122 { 123 aStyleType = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NumberingStyleName") ); 124 break; 125 } 126 default: 127 DebugHelper::exception( SbERR_INTERNAL_ERROR, rtl::OUString() ); 128 } 129 return aStyleType; 130 } 131 132 rtl::OUString& 133 SwVbaStyle::getServiceImplName() 134 { 135 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaStyle") ); 136 return sImplName; 137 } 138 139 uno::Sequence< rtl::OUString > 140 SwVbaStyle::getServiceNames() 141 { 142 static uno::Sequence< rtl::OUString > aServiceNames; 143 if ( aServiceNames.getLength() == 0 ) 144 { 145 aServiceNames.realloc( 1 ); 146 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.XStyle" ) ); 147 } 148 return aServiceNames; 149 } 150