xref: /aoo41x/main/sc/source/ui/vba/vbastyle.cxx (revision b3f79822)
1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b3f79822SAndrew Rist  * distributed with this work for additional information
6*b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b3f79822SAndrew Rist  *
11*b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist  *
13*b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b3f79822SAndrew Rist  * specific language governing permissions and limitations
18*b3f79822SAndrew Rist  * under the License.
19*b3f79822SAndrew Rist  *
20*b3f79822SAndrew Rist  *************************************************************/
21*b3f79822SAndrew Rist 
22*b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "vbastyle.hxx"
25cdf0e10cSrcweir #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
26cdf0e10cSrcweir 
27cdf0e10cSrcweir using namespace ::ooo::vba;
28cdf0e10cSrcweir using namespace ::com::sun::star;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir static rtl::OUString DISPLAYNAME( RTL_CONSTASCII_USTRINGPARAM("DisplayName") );
31cdf0e10cSrcweir 
32cdf0e10cSrcweir 
33cdf0e10cSrcweir 
34cdf0e10cSrcweir uno::Reference< container::XNameAccess >
getStylesNameContainer(const uno::Reference<frame::XModel> & xModel)35cdf0e10cSrcweir ScVbaStyle::getStylesNameContainer( const uno::Reference< frame::XModel >& xModel ) throw ( uno::RuntimeException )
36cdf0e10cSrcweir {
37cdf0e10cSrcweir 	uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( xModel, uno::UNO_QUERY_THROW);
38cdf0e10cSrcweir 	uno::Reference< container::XNameAccess > xStylesAccess( xStyleSupplier->getStyleFamilies()->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CellStyles" ) ) ), uno::UNO_QUERY_THROW );
39cdf0e10cSrcweir 	return xStylesAccess;
40cdf0e10cSrcweir }
41cdf0e10cSrcweir 
42cdf0e10cSrcweir uno::Reference< beans::XPropertySet >
lcl_getStyleProps(const rtl::OUString & sStyleName,const uno::Reference<frame::XModel> & xModel)43cdf0e10cSrcweir lcl_getStyleProps( const rtl::OUString& sStyleName, const uno::Reference< frame::XModel >& xModel ) throw ( script::BasicErrorException, uno::RuntimeException )
44cdf0e10cSrcweir {
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 	uno::Reference< beans::XPropertySet > xStyleProps( ScVbaStyle::getStylesNameContainer( xModel )->getByName( sStyleName ), uno::UNO_QUERY_THROW );
47cdf0e10cSrcweir 	return xStyleProps;
48cdf0e10cSrcweir }
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 
initialise()51cdf0e10cSrcweir void ScVbaStyle::initialise() throw ( uno::RuntimeException )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir 	if (!mxModel.is() )
54cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XModel Interface could not be retrieved")) );
55cdf0e10cSrcweir 	uno::Reference< lang::XServiceInfo > xServiceInfo( mxPropertySet, uno::UNO_QUERY_THROW );
56cdf0e10cSrcweir 	if ( !xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.CellStyle" ) ) ) )
57cdf0e10cSrcweir 	{
58cdf0e10cSrcweir 			DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() );
59cdf0e10cSrcweir 	}
60cdf0e10cSrcweir 	mxStyle.set( mxPropertySet, uno::UNO_QUERY_THROW );
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 	uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( mxModel, uno::UNO_QUERY_THROW );
63cdf0e10cSrcweir 	mxStyleFamilyNameContainer.set(  ScVbaStyle::getStylesNameContainer( mxModel ), uno::UNO_QUERY_THROW );
64cdf0e10cSrcweir 
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
ScVbaStyle(const uno::Reference<ov::XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext,const rtl::OUString & sStyleName,const uno::Reference<frame::XModel> & _xModel)67cdf0e10cSrcweir 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 )
68cdf0e10cSrcweir {
69cdf0e10cSrcweir 	try
70cdf0e10cSrcweir 	{
71cdf0e10cSrcweir 		initialise();
72cdf0e10cSrcweir 	}
73cdf0e10cSrcweir 	catch (uno::Exception& )
74cdf0e10cSrcweir 	{
75cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
76cdf0e10cSrcweir 	}
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
ScVbaStyle(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext,const uno::Reference<beans::XPropertySet> & _xPropertySet,const uno::Reference<frame::XModel> & _xModel)79cdf0e10cSrcweir 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 )
80cdf0e10cSrcweir {
81cdf0e10cSrcweir 	try
82cdf0e10cSrcweir 	{
83cdf0e10cSrcweir 		initialise();
84cdf0e10cSrcweir 	}
85cdf0e10cSrcweir 	catch (uno::Exception& )
86cdf0e10cSrcweir 	{
87cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
88cdf0e10cSrcweir 	}
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 
92cdf0e10cSrcweir ::sal_Bool SAL_CALL
BuiltIn()93cdf0e10cSrcweir ScVbaStyle::BuiltIn() throw (script::BasicErrorException, uno::RuntimeException)
94cdf0e10cSrcweir {
95cdf0e10cSrcweir 	return !mxStyle->isUserDefined();
96cdf0e10cSrcweir 
97cdf0e10cSrcweir }
98cdf0e10cSrcweir void SAL_CALL
setName(const::rtl::OUString & Name)99cdf0e10cSrcweir ScVbaStyle::setName( const ::rtl::OUString& Name ) throw (script::BasicErrorException, uno::RuntimeException)
100cdf0e10cSrcweir {
101cdf0e10cSrcweir 	mxStyle->setName(Name);
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir ::rtl::OUString SAL_CALL
getName()105cdf0e10cSrcweir ScVbaStyle::getName() throw (script::BasicErrorException, uno::RuntimeException)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir 	return mxStyle->getName();
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir void SAL_CALL
setNameLocal(const::rtl::OUString & NameLocal)111cdf0e10cSrcweir ScVbaStyle::setNameLocal( const ::rtl::OUString& NameLocal ) throw (script::BasicErrorException, uno::RuntimeException)
112cdf0e10cSrcweir {
113cdf0e10cSrcweir 	try
114cdf0e10cSrcweir 	{
115cdf0e10cSrcweir 		mxPropertySet->setPropertyValue(DISPLAYNAME, uno::makeAny( NameLocal ) );
116cdf0e10cSrcweir 	}
117cdf0e10cSrcweir 	catch (uno::Exception& e)
118cdf0e10cSrcweir 	{
119cdf0e10cSrcweir 		DebugHelper::exception(e);
120cdf0e10cSrcweir 	}
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir ::rtl::OUString SAL_CALL
getNameLocal()124cdf0e10cSrcweir ScVbaStyle::getNameLocal() throw (script::BasicErrorException, uno::RuntimeException)
125cdf0e10cSrcweir {
126cdf0e10cSrcweir 	rtl::OUString sName;
127cdf0e10cSrcweir 	try
128cdf0e10cSrcweir 	{
129cdf0e10cSrcweir 		mxPropertySet->getPropertyValue(DISPLAYNAME) >>= sName;
130cdf0e10cSrcweir 	}
131cdf0e10cSrcweir 	catch (uno::Exception e)
132cdf0e10cSrcweir 	{
133cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() );
134cdf0e10cSrcweir 	}
135cdf0e10cSrcweir 	return sName;
136cdf0e10cSrcweir }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir void SAL_CALL
Delete()139cdf0e10cSrcweir ScVbaStyle::Delete() throw (script::BasicErrorException, uno::RuntimeException)
140cdf0e10cSrcweir {
141cdf0e10cSrcweir 	try
142cdf0e10cSrcweir 	{
143cdf0e10cSrcweir 		mxStyleFamilyNameContainer->removeByName(mxStyle->getName());
144cdf0e10cSrcweir 	}
145cdf0e10cSrcweir 	catch (uno::Exception& )
146cdf0e10cSrcweir 	{
147cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
148cdf0e10cSrcweir 	}
149cdf0e10cSrcweir }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir void SAL_CALL
setMergeCells(const uno::Any &)152cdf0e10cSrcweir ScVbaStyle::setMergeCells( const uno::Any& /*MergeCells*/ ) throw (script::BasicErrorException, uno::RuntimeException)
153cdf0e10cSrcweir {
154cdf0e10cSrcweir 	DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString());
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir uno::Any SAL_CALL
getMergeCells()158cdf0e10cSrcweir ScVbaStyle::getMergeCells(  ) throw (script::BasicErrorException, uno::RuntimeException)
159cdf0e10cSrcweir {
160cdf0e10cSrcweir 	DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString());
161cdf0e10cSrcweir 	return uno::Any();
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 
165cdf0e10cSrcweir rtl::OUString&
getServiceImplName()166cdf0e10cSrcweir ScVbaStyle::getServiceImplName()
167cdf0e10cSrcweir {
168cdf0e10cSrcweir         static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaStyle") );
169cdf0e10cSrcweir         return sImplName;
170cdf0e10cSrcweir }
171cdf0e10cSrcweir 
172cdf0e10cSrcweir uno::Sequence< rtl::OUString >
getServiceNames()173cdf0e10cSrcweir ScVbaStyle::getServiceNames()
174cdf0e10cSrcweir {
175cdf0e10cSrcweir         static uno::Sequence< rtl::OUString > aServiceNames;
176cdf0e10cSrcweir         if ( aServiceNames.getLength() == 0 )
177cdf0e10cSrcweir         {
178cdf0e10cSrcweir                 aServiceNames.realloc( 1 );
179cdf0e10cSrcweir                 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.XStyle" ) );
180cdf0e10cSrcweir         }
181cdf0e10cSrcweir         return aServiceNames;
182cdf0e10cSrcweir }
183