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 
25 using namespace ::ooo::vba;
26 using namespace ::com::sun::star;
27 
28 constexpr OUStringLiteral DISPLAYNAME = u"DisplayName";
29 
30 uno::Reference< container::XNameAccess >
31 ScVbaStyle::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 
40 static uno::Reference< beans::XPropertySet >
41 lcl_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 
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 )
68 {
69  try
70  {
71  initialise();
72  }
73  catch (const uno::Exception& )
74  {
75  DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
76  }
77 }
78 
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 )
84 {
85  try
86  {
87  initialise();
88  }
89  catch (const uno::Exception& )
90  {
91  DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {});
92  }
93 }
94 
95 sal_Bool SAL_CALL
97 {
98  return !mxStyle->isUserDefined();
99 
100 }
101 void SAL_CALL
102 ScVbaStyle::setName( const OUString& Name )
103 {
104  mxStyle->setName(Name);
105 }
106 
107 OUString SAL_CALL
109 {
110  return mxStyle->getName();
111 }
112 
113 void SAL_CALL
114 ScVbaStyle::setNameLocal( const OUString& NameLocal )
115 {
116  try
117  {
118  mxPropertySet->setPropertyValue(DISPLAYNAME, uno::makeAny( NameLocal ) );
119  }
120  catch (const uno::Exception& e)
121  {
122  DebugHelper::basicexception(e);
123  }
124 }
125 
126 OUString 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 
141 void 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 
154 void SAL_CALL
155 ScVbaStyle::setMergeCells( const uno::Any& /*MergeCells*/ )
156 {
157  DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED, {});
158 }
159 
160 uno::Any SAL_CALL
162 {
163  DebugHelper::basicexception(ERRCODE_BASIC_NOT_IMPLEMENTED, {});
164  return uno::Any();
165 }
166 
167 OUString
169 {
170  return "ScVbaStyle";
171 }
172 
173 uno::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: */
void initialise()
Definition: vbastyle.cxx:48
virtual OUString SAL_CALL getNameLocal() override
Definition: vbastyle.cxx:127
virtual void SAL_CALL Delete() override
Definition: vbastyle.cxx:142
virtual css::uno::Any SAL_CALL getMergeCells() override
Definition: vbastyle.cxx:161
static css::uno::Reference< css::container::XNameAccess > getStylesNameContainer(const css::uno::Reference< css::frame::XModel > &xModel)
Definition: vbastyle.cxx:31
virtual sal_Bool SAL_CALL BuiltIn() override
Definition: vbastyle.cxx:96
Sequence< OUString > aServiceNames
constexpr OUStringLiteral DISPLAYNAME
Definition: vbastyle.cxx:28
#define ERRCODE_BASIC_NOT_IMPLEMENTED
css::uno::Reference< css::frame::XModel > mxModel
Definition: vbaformat.hxx:46
const char * sName
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)
css::uno::Reference< css::beans::XPropertySet > mxPropertySet
Definition: vbaformat.hxx:42
virtual void SAL_CALL setNameLocal(const OUString &NameLocal) override
Definition: vbastyle.cxx:114
float u
unsigned char sal_Bool
css::uno::Reference< css::style::XStyle > mxStyle
Definition: vbastyle.hxx:32
static uno::Reference< beans::XPropertySet > lcl_getStyleProps(const OUString &sStyleName, const uno::Reference< frame::XModel > &xModel)
Definition: vbastyle.cxx:41
virtual void SAL_CALL setMergeCells(const css::uno::Any &MergeCells) override
Definition: vbastyle.cxx:155
virtual void SAL_CALL setName(const OUString &Name) override
Definition: vbastyle.cxx:102
#define ERRCODE_BASIC_METHOD_FAILED
css::uno::Reference< css::container::XNameContainer > mxStyleFamilyNameContainer
Definition: vbastyle.hxx:33
virtual OUString getServiceImplName() override
Definition: vbastyle.cxx:168
virtual OUString SAL_CALL getName() override
Definition: vbastyle.cxx:108
virtual css::uno::Sequence< OUString > getServiceNames() override
Definition: vbastyle.cxx:174