update dev300-m58
[ooovba.git] / sc / source / ui / vba / vbastyle.cxx
blobdeabbced704edda5cb29f574d36acb0eb6f38df8
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: vbastyle.cxx,v $
10 * $Revision: 1.3 $
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 <com/sun/star/style/XStyleFamiliesSupplier.hpp>
34 using namespace ::ooo::vba;
35 using namespace ::com::sun::star;
37 static rtl::OUString DISPLAYNAME( RTL_CONSTASCII_USTRINGPARAM("DisplayName") );
41 uno::Reference< container::XNameAccess >
42 ScVbaStyle::getStylesNameContainer( const uno::Reference< frame::XModel >& xModel ) throw ( uno::RuntimeException )
44 uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( xModel, uno::UNO_QUERY_THROW);
45 uno::Reference< container::XNameAccess > xStylesAccess( xStyleSupplier->getStyleFamilies()->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CellStyles" ) ) ), uno::UNO_QUERY_THROW );
46 return xStylesAccess;
49 uno::Reference< beans::XPropertySet >
50 lcl_getStyleProps( const rtl::OUString& sStyleName, const uno::Reference< frame::XModel >& xModel ) throw ( script::BasicErrorException, uno::RuntimeException )
53 uno::Reference< beans::XPropertySet > xStyleProps( ScVbaStyle::getStylesNameContainer( xModel )->getByName( sStyleName ), uno::UNO_QUERY_THROW );
54 return xStyleProps;
58 void ScVbaStyle::initialise() throw ( uno::RuntimeException )
60 if (!mxModel.is() )
61 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XModel Interface could not be retrieved")) );
62 uno::Reference< lang::XServiceInfo > xServiceInfo( mxPropertySet, uno::UNO_QUERY_THROW );
63 if ( !xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.CellStyle" ) ) ) )
65 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() );
67 mxStyle.set( mxPropertySet, uno::UNO_QUERY_THROW );
69 uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( mxModel, uno::UNO_QUERY_THROW );
70 mxStyleFamilyNameContainer.set( ScVbaStyle::getStylesNameContainer( mxModel ), uno::UNO_QUERY_THROW );
74 ScVbaStyle::ScVbaStyle( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const rtl::OUString& sStyleName, const uno::Reference< frame::XModel >& _xModel ) throw ( script::BasicErrorException, uno::RuntimeException ) : ScVbaStyle_BASE( xParent, xContext, lcl_getStyleProps( sStyleName, _xModel ), _xModel, false ), mxModel( _xModel )
76 try
78 initialise();
80 catch (uno::Exception& )
82 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
86 ScVbaStyle::ScVbaStyle( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< beans::XPropertySet >& _xPropertySet, const uno::Reference< frame::XModel >& _xModel ) throw ( script::BasicErrorException, uno::RuntimeException ) : ScVbaStyle_BASE( xParent, xContext, _xPropertySet, _xModel, false ), mxModel( _xModel )
88 try
90 initialise();
92 catch (uno::Exception& )
94 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
99 ::sal_Bool SAL_CALL
100 ScVbaStyle::BuiltIn() throw (script::BasicErrorException, uno::RuntimeException)
102 return !mxStyle->isUserDefined();
105 void SAL_CALL
106 ScVbaStyle::setName( const ::rtl::OUString& Name ) throw (script::BasicErrorException, uno::RuntimeException)
108 mxStyle->setName(Name);
111 ::rtl::OUString SAL_CALL
112 ScVbaStyle::getName() throw (script::BasicErrorException, uno::RuntimeException)
114 return mxStyle->getName();
117 void SAL_CALL
118 ScVbaStyle::setNameLocal( const ::rtl::OUString& NameLocal ) throw (script::BasicErrorException, uno::RuntimeException)
122 mxPropertySet->setPropertyValue(DISPLAYNAME, uno::makeAny( NameLocal ) );
124 catch (uno::Exception& e)
126 DebugHelper::exception(e);
130 ::rtl::OUString SAL_CALL
131 ScVbaStyle::getNameLocal() throw (script::BasicErrorException, uno::RuntimeException)
133 rtl::OUString sName;
136 mxPropertySet->getPropertyValue(DISPLAYNAME) >>= sName;
138 catch (uno::Exception e)
140 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() );
142 return sName;
145 void SAL_CALL
146 ScVbaStyle::Delete() throw (script::BasicErrorException, uno::RuntimeException)
150 mxStyleFamilyNameContainer->removeByName(mxStyle->getName());
152 catch (uno::Exception& )
154 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
158 void SAL_CALL
159 ScVbaStyle::setMergeCells( const uno::Any& /*MergeCells*/ ) throw (script::BasicErrorException, uno::RuntimeException)
161 DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString());
164 uno::Any SAL_CALL
165 ScVbaStyle::getMergeCells( ) throw (script::BasicErrorException, uno::RuntimeException)
167 DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString());
168 return uno::Any();
172 rtl::OUString&
173 ScVbaStyle::getServiceImplName()
175 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaStyle") );
176 return sImplName;
179 uno::Sequence< rtl::OUString >
180 ScVbaStyle::getServiceNames()
182 static uno::Sequence< rtl::OUString > aServiceNames;
183 if ( aServiceNames.getLength() == 0 )
185 aServiceNames.realloc( 1 );
186 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.XStyle" ) );
188 return aServiceNames;