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