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