1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "vbastyle.hxx"
21 #include <basic/sberrors.hxx>
22 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
23 #include <com/sun/star/beans/XPropertySet.hpp>
25 using namespace ::ooo::vba
;
26 using namespace ::com::sun::star
;
28 constexpr OUString DISPLAYNAME
= u
"DisplayName"_ustr
;
30 uno::Reference
< container::XNameAccess
>
31 ScVbaStyle::getStylesNameContainer( const uno::Reference
< frame::XModel
>& xModel
)
33 uno::Reference
< style::XStyleFamiliesSupplier
> xStyleSupplier( xModel
, uno::UNO_QUERY_THROW
);
34 uno::Reference
< container::XNameAccess
> xStylesAccess( xStyleSupplier
->getStyleFamilies()->getByName(u
"CellStyles"_ustr
), uno::UNO_QUERY_THROW
);
38 /// @throws script::BasicErrorException
39 /// @throws uno::RuntimeException
40 static uno::Reference
< beans::XPropertySet
>
41 lcl_getStyleProps( const OUString
& sStyleName
, const uno::Reference
< frame::XModel
>& xModel
)
44 uno::Reference
< beans::XPropertySet
> xStyleProps( ScVbaStyle::getStylesNameContainer( xModel
)->getByName( sStyleName
), uno::UNO_QUERY_THROW
);
48 void ScVbaStyle::initialise()
51 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, u
"XModel Interface could not be retrieved" );
52 uno::Reference
< lang::XServiceInfo
> xServiceInfo( mxPropertySet
, uno::UNO_QUERY_THROW
);
53 if ( !xServiceInfo
->supportsService(u
"com.sun.star.style.CellStyle"_ustr
) )
55 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {} );
57 mxStyle
.set( mxPropertySet
, uno::UNO_QUERY_THROW
);
59 uno::Reference
< style::XStyleFamiliesSupplier
> xStyleSupplier( mxModel
, uno::UNO_QUERY_THROW
);
60 mxStyleFamilyNameContainer
.set( ScVbaStyle::getStylesNameContainer( mxModel
), uno::UNO_QUERY_THROW
);
64 ScVbaStyle::ScVbaStyle( const uno::Reference
< ov::XHelperInterface
>& xParent
,
65 const uno::Reference
< uno::XComponentContext
> & xContext
,
66 const OUString
& sStyleName
, const uno::Reference
< frame::XModel
>& _xModel
)
67 : ScVbaStyle_BASE( xParent
, xContext
, lcl_getStyleProps( sStyleName
, _xModel
), _xModel
, false )
73 catch (const uno::Exception
& )
75 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {});
79 ScVbaStyle::ScVbaStyle( const uno::Reference
< XHelperInterface
>& xParent
,
80 const uno::Reference
< uno::XComponentContext
> & xContext
,
81 const uno::Reference
< beans::XPropertySet
>& _xPropertySet
,
82 const uno::Reference
< frame::XModel
>& _xModel
)
83 : ScVbaStyle_BASE( xParent
, xContext
, _xPropertySet
, _xModel
, false )
89 catch (const uno::Exception
& )
91 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {});
98 return !mxStyle
->isUserDefined();
102 ScVbaStyle::setName( const OUString
& Name
)
104 mxStyle
->setName(Name
);
108 ScVbaStyle::getName()
110 return mxStyle
->getName();
114 ScVbaStyle::setNameLocal( const OUString
& NameLocal
)
118 mxPropertySet
->setPropertyValue(DISPLAYNAME
, uno::Any( NameLocal
) );
120 catch (const uno::Exception
& e
)
122 DebugHelper::basicexception(e
);
127 ScVbaStyle::getNameLocal()
132 mxPropertySet
->getPropertyValue(DISPLAYNAME
) >>= sName
;
134 catch (const uno::Exception
& )
136 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {} );
146 mxStyleFamilyNameContainer
->removeByName(mxStyle
->getName());
148 catch (const uno::Exception
& )
150 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {});
155 ScVbaStyle::setMergeCells( const uno::Any
& /*MergeCells*/ )
157 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED
, {});
161 ScVbaStyle::getMergeCells( )
163 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED
, {});
168 ScVbaStyle::getServiceImplName()
170 return u
"ScVbaStyle"_ustr
;
173 uno::Sequence
< OUString
>
174 ScVbaStyle::getServiceNames()
176 static uno::Sequence
< OUString
> const aServiceNames
178 u
"ooo.vba.excel.XStyle"_ustr
180 return aServiceNames
;
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */