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 <com/sun/star/style/XStyleFamiliesSupplier.hpp>
23 using namespace ::ooo::vba
;
24 using namespace ::com::sun::star
;
26 static const char DISPLAYNAME
[] = "DisplayName";
28 uno::Reference
< container::XNameAccess
>
29 ScVbaStyle::getStylesNameContainer( const uno::Reference
< frame::XModel
>& xModel
) throw ( uno::RuntimeException
)
31 uno::Reference
< style::XStyleFamiliesSupplier
> xStyleSupplier( xModel
, uno::UNO_QUERY_THROW
);
32 uno::Reference
< container::XNameAccess
> xStylesAccess( xStyleSupplier
->getStyleFamilies()->getByName("CellStyles"), uno::UNO_QUERY_THROW
);
36 static uno::Reference
< beans::XPropertySet
>
37 lcl_getStyleProps( const OUString
& sStyleName
, const uno::Reference
< frame::XModel
>& xModel
) throw ( script::BasicErrorException
, uno::RuntimeException
)
40 uno::Reference
< beans::XPropertySet
> xStyleProps( ScVbaStyle::getStylesNameContainer( xModel
)->getByName( sStyleName
), uno::UNO_QUERY_THROW
);
44 void ScVbaStyle::initialise() throw ( uno::RuntimeException
, script::BasicErrorException
)
47 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString( "XModel Interface could not be retrieved") );
48 uno::Reference
< lang::XServiceInfo
> xServiceInfo( mxPropertySet
, uno::UNO_QUERY_THROW
);
49 if ( !xServiceInfo
->supportsService("com.sun.star.style.CellStyle") )
51 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString() );
53 mxStyle
.set( mxPropertySet
, uno::UNO_QUERY_THROW
);
55 uno::Reference
< style::XStyleFamiliesSupplier
> xStyleSupplier( mxModel
, uno::UNO_QUERY_THROW
);
56 mxStyleFamilyNameContainer
.set( ScVbaStyle::getStylesNameContainer( mxModel
), uno::UNO_QUERY_THROW
);
60 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
)
66 catch (const uno::Exception
& )
68 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
72 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
)
78 catch (const uno::Exception
& )
80 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
85 ScVbaStyle::BuiltIn() throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
87 return !mxStyle
->isUserDefined();
91 ScVbaStyle::setName( const OUString
& Name
) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
93 mxStyle
->setName(Name
);
97 ScVbaStyle::getName() throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
99 return mxStyle
->getName();
103 ScVbaStyle::setNameLocal( const OUString
& NameLocal
) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
107 mxPropertySet
->setPropertyValue(DISPLAYNAME
, uno::makeAny( NameLocal
) );
109 catch (const uno::Exception
& e
)
111 DebugHelper::basicexception(e
);
116 ScVbaStyle::getNameLocal() throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
121 mxPropertySet
->getPropertyValue(DISPLAYNAME
) >>= sName
;
123 catch (const uno::Exception
& )
125 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString() );
131 ScVbaStyle::Delete() throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
135 mxStyleFamilyNameContainer
->removeByName(mxStyle
->getName());
137 catch (const uno::Exception
& )
139 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString());
144 ScVbaStyle::setMergeCells( const uno::Any
& /*MergeCells*/ ) throw (script::BasicErrorException
, uno::RuntimeException
)
146 DebugHelper::basicexception(SbERR_NOT_IMPLEMENTED
, OUString());
150 ScVbaStyle::getMergeCells( ) throw (script::BasicErrorException
, uno::RuntimeException
)
152 DebugHelper::basicexception(SbERR_NOT_IMPLEMENTED
, OUString());
157 ScVbaStyle::getServiceImplName()
159 return OUString("ScVbaStyle");
162 uno::Sequence
< OUString
>
163 ScVbaStyle::getServiceNames()
165 static uno::Sequence
< OUString
> aServiceNames
;
166 if ( aServiceNames
.getLength() == 0 )
168 aServiceNames
.realloc( 1 );
169 aServiceNames
[ 0 ] = "ooo.vba.excel.XStyle";
171 return aServiceNames
;
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */