merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / vba / vbastyle.cxx
blobf75c16b29d3e5efe3b10655787a4d6e517dace7c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile:
10 * $Revision:
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "vbastyle.hxx"
32 #include <ooo/vba/word/WdStyleType.hpp>
33 #include <com/sun/star/lang/Locale.hpp>
34 #include <i18npool/mslangid.hxx>
35 #include "vbafont.hxx"
36 #include "vbapalette.hxx"
38 using namespace ::ooo::vba;
39 using namespace ::com::sun::star;
42 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 )
44 mxStyle.set( _xPropertySet, uno::UNO_QUERY_THROW );
47 void SAL_CALL
48 SwVbaStyle::setName( const ::rtl::OUString& Name ) throw (uno::RuntimeException)
50 mxStyle->setName(Name);
53 ::rtl::OUString SAL_CALL
54 SwVbaStyle::getName() throw (uno::RuntimeException)
56 return mxStyle->getName();
59 sal_Int32 SwVbaStyle::getLanguageID( const uno::Reference< beans::XPropertySet >& xTCProps ) throw (uno::RuntimeException)
61 lang::Locale aLocale;
62 xTCProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CharLocale") ) ) >>= aLocale;
63 return MsLangId::convertLocaleToLanguage( aLocale );
66 void SwVbaStyle::setLanguageID( const uno::Reference< beans::XPropertySet >& xTCProps, sal_Int32 _languageid ) throw (uno::RuntimeException)
68 lang::Locale aLocale = MsLangId::convertLanguageToLocale( _languageid );
69 xTCProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CharLocale") ), uno::makeAny( aLocale ) ) ;
72 ::sal_Int32 SAL_CALL SwVbaStyle::getLanguageID() throw (uno::RuntimeException)
74 return getLanguageID( mxStyleProps );
77 void SAL_CALL SwVbaStyle::setLanguageID( ::sal_Int32 _languageid ) throw (uno::RuntimeException)
79 setLanguageID( mxStyleProps, _languageid );
82 ::sal_Int32 SAL_CALL SwVbaStyle::getType() throw (uno::RuntimeException)
84 sal_Int32 nType = word::WdStyleType::wdStyleTypeParagraph;
85 uno::Reference< lang::XServiceInfo > xServiceInfo( mxStyle, uno::UNO_QUERY_THROW );
86 if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.style.ParagraphStyle") ) ) )
87 nType = word::WdStyleType::wdStyleTypeParagraph;
88 else if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.style.CharacterStyle") ) ) )
89 nType = word::WdStyleType::wdStyleTypeCharacter;
90 else // if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.NumberingStyle") ) ) )
91 nType = word::WdStyleType::wdStyleTypeList;
92 return nType;
95 uno::Reference< word::XFont > SAL_CALL
96 SwVbaStyle::getFont() throw ( uno::RuntimeException )
98 VbaPalette aColors;
99 return new SwVbaFont( mxParent, mxContext, aColors.getPalette(), mxStyleProps );
102 void SwVbaStyle::setStyle( const uno::Reference< beans::XPropertySet >& xTCProps, const uno::Reference< ooo::vba::word::XStyle >& xStyle )throw (uno::RuntimeException)
104 rtl::OUString aStyleType = getOOoStyleTypeFromMSWord( xStyle->getType() );
105 xTCProps->setPropertyValue( aStyleType, uno::makeAny( xStyle->getName() ) );
108 rtl::OUString SwVbaStyle::getOOoStyleTypeFromMSWord( sal_Int32 _wdStyleType )
110 rtl::OUString aStyleType;
111 switch( _wdStyleType )
113 case word::WdStyleType::wdStyleTypeParagraph:
114 case word::WdStyleType::wdStyleTypeTable:
116 aStyleType = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaStyleName") );
117 break;
119 case word::WdStyleType::wdStyleTypeCharacter:
121 aStyleType = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CharStyleName") );
122 break;
124 case word::WdStyleType::wdStyleTypeList:
126 aStyleType = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NumberingStyleName") );
127 break;
129 default:
130 DebugHelper::exception( SbERR_INTERNAL_ERROR, rtl::OUString() );
132 return aStyleType;
135 rtl::OUString&
136 SwVbaStyle::getServiceImplName()
138 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaStyle") );
139 return sImplName;
142 uno::Sequence< rtl::OUString >
143 SwVbaStyle::getServiceNames()
145 static uno::Sequence< rtl::OUString > aServiceNames;
146 if ( aServiceNames.getLength() == 0 )
148 aServiceNames.realloc( 1 );
149 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.XStyle" ) );
151 return aServiceNames;