Line data Source code
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 <com/sun/star/style/XStyleFamiliesSupplier.hpp>
22 :
23 : using namespace ::ooo::vba;
24 : using namespace ::com::sun::star;
25 :
26 0 : static OUString DISPLAYNAME("DisplayName");
27 :
28 : uno::Reference< container::XNameAccess >
29 0 : ScVbaStyle::getStylesNameContainer( const uno::Reference< frame::XModel >& xModel ) throw ( uno::RuntimeException )
30 : {
31 0 : uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( xModel, uno::UNO_QUERY_THROW);
32 0 : uno::Reference< container::XNameAccess > xStylesAccess( xStyleSupplier->getStyleFamilies()->getByName("CellStyles"), uno::UNO_QUERY_THROW );
33 0 : return xStylesAccess;
34 : }
35 :
36 : static uno::Reference< beans::XPropertySet >
37 0 : lcl_getStyleProps( const OUString& sStyleName, const uno::Reference< frame::XModel >& xModel ) throw ( script::BasicErrorException, uno::RuntimeException )
38 : {
39 :
40 0 : uno::Reference< beans::XPropertySet > xStyleProps( ScVbaStyle::getStylesNameContainer( xModel )->getByName( sStyleName ), uno::UNO_QUERY_THROW );
41 0 : return xStyleProps;
42 : }
43 :
44 :
45 0 : void ScVbaStyle::initialise() throw ( uno::RuntimeException )
46 : {
47 0 : if (!mxModel.is() )
48 0 : DebugHelper::exception(SbERR_METHOD_FAILED, OUString( "XModel Interface could not be retrieved") );
49 0 : uno::Reference< lang::XServiceInfo > xServiceInfo( mxPropertySet, uno::UNO_QUERY_THROW );
50 0 : if ( !xServiceInfo->supportsService("com.sun.star.style.CellStyle") )
51 : {
52 0 : DebugHelper::exception(SbERR_METHOD_FAILED, OUString() );
53 : }
54 0 : mxStyle.set( mxPropertySet, uno::UNO_QUERY_THROW );
55 :
56 0 : uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( mxModel, uno::UNO_QUERY_THROW );
57 0 : mxStyleFamilyNameContainer.set( ScVbaStyle::getStylesNameContainer( mxModel ), uno::UNO_QUERY_THROW );
58 :
59 0 : }
60 :
61 0 : ScVbaStyle::ScVbaStyle( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const 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 )
62 : {
63 : try
64 : {
65 0 : initialise();
66 : }
67 0 : catch (const uno::Exception& )
68 : {
69 0 : DebugHelper::exception(SbERR_METHOD_FAILED, OUString());
70 : }
71 0 : }
72 :
73 0 : 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 )
74 : {
75 : try
76 : {
77 0 : initialise();
78 : }
79 0 : catch (const uno::Exception& )
80 : {
81 0 : DebugHelper::exception(SbERR_METHOD_FAILED, OUString());
82 : }
83 0 : }
84 :
85 :
86 : sal_Bool SAL_CALL
87 0 : ScVbaStyle::BuiltIn() throw (script::BasicErrorException, uno::RuntimeException, std::exception)
88 : {
89 0 : return !mxStyle->isUserDefined();
90 :
91 : }
92 : void SAL_CALL
93 0 : ScVbaStyle::setName( const OUString& Name ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
94 : {
95 0 : mxStyle->setName(Name);
96 0 : }
97 :
98 : OUString SAL_CALL
99 0 : ScVbaStyle::getName() throw (script::BasicErrorException, uno::RuntimeException, std::exception)
100 : {
101 0 : return mxStyle->getName();
102 : }
103 :
104 : void SAL_CALL
105 0 : ScVbaStyle::setNameLocal( const OUString& NameLocal ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
106 : {
107 : try
108 : {
109 0 : mxPropertySet->setPropertyValue(DISPLAYNAME, uno::makeAny( NameLocal ) );
110 : }
111 0 : catch (const uno::Exception& e)
112 : {
113 0 : DebugHelper::exception(e);
114 : }
115 0 : }
116 :
117 : OUString SAL_CALL
118 0 : ScVbaStyle::getNameLocal() throw (script::BasicErrorException, uno::RuntimeException, std::exception)
119 : {
120 0 : OUString sName;
121 : try
122 : {
123 0 : mxPropertySet->getPropertyValue(DISPLAYNAME) >>= sName;
124 : }
125 0 : catch (const uno::Exception& )
126 : {
127 0 : DebugHelper::exception(SbERR_METHOD_FAILED, OUString() );
128 : }
129 0 : return sName;
130 : }
131 :
132 : void SAL_CALL
133 0 : ScVbaStyle::Delete() throw (script::BasicErrorException, uno::RuntimeException, std::exception)
134 : {
135 : try
136 : {
137 0 : mxStyleFamilyNameContainer->removeByName(mxStyle->getName());
138 : }
139 0 : catch (const uno::Exception& )
140 : {
141 0 : DebugHelper::exception(SbERR_METHOD_FAILED, OUString());
142 : }
143 0 : }
144 :
145 : void SAL_CALL
146 0 : ScVbaStyle::setMergeCells( const uno::Any& /*MergeCells*/ ) throw (script::BasicErrorException, uno::RuntimeException)
147 : {
148 0 : DebugHelper::exception(SbERR_NOT_IMPLEMENTED, OUString());
149 0 : }
150 :
151 : uno::Any SAL_CALL
152 0 : ScVbaStyle::getMergeCells( ) throw (script::BasicErrorException, uno::RuntimeException)
153 : {
154 0 : DebugHelper::exception(SbERR_NOT_IMPLEMENTED, OUString());
155 0 : return uno::Any();
156 : }
157 :
158 : OUString
159 0 : ScVbaStyle::getServiceImplName()
160 : {
161 0 : return OUString("ScVbaStyle");
162 : }
163 :
164 : uno::Sequence< OUString >
165 0 : ScVbaStyle::getServiceNames()
166 : {
167 0 : static uno::Sequence< OUString > aServiceNames;
168 0 : if ( aServiceNames.getLength() == 0 )
169 : {
170 0 : aServiceNames.realloc( 1 );
171 0 : aServiceNames[ 0 ] = "ooo.vba.excel.XStyle";
172 : }
173 0 : return aServiceNames;
174 0 : }
175 :
176 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|