LibreOffice Module sc (master) 1
vbastyle.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
24
25using namespace ::ooo::vba;
26using namespace ::com::sun::star;
27
28constexpr OUStringLiteral DISPLAYNAME = u"DisplayName";
29
30uno::Reference< container::XNameAccess >
31ScVbaStyle::getStylesNameContainer( const uno::Reference< frame::XModel >& xModel )
32{
33 uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( xModel, uno::UNO_QUERY_THROW);
34 uno::Reference< container::XNameAccess > xStylesAccess( xStyleSupplier->getStyleFamilies()->getByName("CellStyles"), uno::UNO_QUERY_THROW );
35 return xStylesAccess;
36}
37
40static uno::Reference< beans::XPropertySet >
41lcl_getStyleProps( const OUString& sStyleName, const uno::Reference< frame::XModel >& xModel )
42{
43
44 uno::Reference< beans::XPropertySet > xStyleProps( ScVbaStyle::getStylesNameContainer( xModel )->getByName( sStyleName ), uno::UNO_QUERY_THROW );
45 return xStyleProps;
46}
47
49{
50 if (!mxModel.is() )
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("com.sun.star.style.CellStyle") )
54 {
55 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {} );
56 }
57 mxStyle.set( mxPropertySet, uno::UNO_QUERY_THROW );
58
59 uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( mxModel, uno::UNO_QUERY_THROW );
61
62}
63
64ScVbaStyle::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 )
68{
69 try
70 {
71 initialise();
72 }
73 catch (const uno::Exception& )
74 {
75 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
76 }
77}
78
79ScVbaStyle::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 )
84{
85 try
86 {
87 initialise();
88 }
89 catch (const uno::Exception& )
90 {
91 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
92 }
93}
94
95sal_Bool SAL_CALL
97{
98 return !mxStyle->isUserDefined();
99
100}
101void SAL_CALL
102ScVbaStyle::setName( const OUString& Name )
103{
104 mxStyle->setName(Name);
105}
106
107OUString SAL_CALL
109{
110 return mxStyle->getName();
111}
112
113void SAL_CALL
114ScVbaStyle::setNameLocal( const OUString& NameLocal )
115{
116 try
117 {
118 mxPropertySet->setPropertyValue(DISPLAYNAME, uno::Any( NameLocal ) );
119 }
120 catch (const uno::Exception& e)
121 {
122 DebugHelper::basicexception(e);
123 }
124}
125
126OUString SAL_CALL
128{
129 OUString sName;
130 try
131 {
132 mxPropertySet->getPropertyValue(DISPLAYNAME) >>= sName;
133 }
134 catch (const uno::Exception& )
135 {
136 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {} );
137 }
138 return sName;
139}
140
141void SAL_CALL
143{
144 try
145 {
146 mxStyleFamilyNameContainer->removeByName(mxStyle->getName());
147 }
148 catch (const uno::Exception& )
149 {
150 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
151 }
152}
153
154void SAL_CALL
155ScVbaStyle::setMergeCells( const uno::Any& /*MergeCells*/ )
156{
157 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED, {});
158}
159
160uno::Any SAL_CALL
162{
163 DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED, {});
164 return uno::Any();
165}
166
167OUString
169{
170 return "ScVbaStyle";
171}
172
173uno::Sequence< OUString >
175{
176 static uno::Sequence< OUString > const aServiceNames
177 {
178 "ooo.vba.excel.XStyle"
179 };
180 return aServiceNames;
181}
182
183/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::frame::XModel > mxModel
Definition: vbaformat.hxx:46
css::uno::Reference< css::beans::XPropertySet > mxPropertySet
Definition: vbaformat.hxx:42
css::uno::Reference< css::container::XNameContainer > mxStyleFamilyNameContainer
Definition: vbastyle.hxx:33
ScVbaStyle(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const OUString &sStyleName, const css::uno::Reference< css::frame::XModel > &_xModel)
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbastyle.cxx:174
virtual OUString getServiceImplName() override
Definition: vbastyle.cxx:168
static css::uno::Reference< css::container::XNameAccess > getStylesNameContainer(const css::uno::Reference< css::frame::XModel > &xModel)
Definition: vbastyle.cxx:31
virtual void SAL_CALL setName(const OUString &Name) override
Definition: vbastyle.cxx:102
css::uno::Reference< css::style::XStyle > mxStyle
Definition: vbastyle.hxx:32
virtual void SAL_CALL Delete() override
Definition: vbastyle.cxx:142
virtual void SAL_CALL setNameLocal(const OUString &NameLocal) override
Definition: vbastyle.cxx:114
virtual css::uno::Any SAL_CALL getMergeCells() override
Definition: vbastyle.cxx:161
void initialise()
Definition: vbastyle.cxx:48
virtual sal_Bool SAL_CALL BuiltIn() override
Definition: vbastyle.cxx:96
virtual void SAL_CALL setMergeCells(const css::uno::Any &MergeCells) override
Definition: vbastyle.cxx:155
virtual OUString SAL_CALL getName() override
Definition: vbastyle.cxx:108
virtual OUString SAL_CALL getNameLocal() override
Definition: vbastyle.cxx:127
float u
Sequence< OUString > aServiceNames
OUString sName
Reference< XPropertySet > _xPropertySet
#define ERRCODE_BASIC_METHOD_FAILED
#define ERRCODE_BASIC_NOT_IMPLEMENTED
Reference< XModel > xModel
OUString Name
unsigned char sal_Bool
constexpr OUStringLiteral DISPLAYNAME
Definition: vbastyle.cxx:28
static uno::Reference< beans::XPropertySet > lcl_getStyleProps(const OUString &sStyleName, const uno::Reference< frame::XModel > &xModel)
Definition: vbastyle.cxx:41