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 .
19 #include "Functions.hxx"
20 #include "Function.hxx"
21 #include <tools/debug.hxx>
22 #include "core_resource.hxx"
23 #include "core_resource.hrc"
24 #include <comphelper/property.hxx>
25 #include <boost/mem_fn.hpp>
28 namespace reportdesign
31 using namespace com::sun::star
;
33 OFunctions::OFunctions(const uno::Reference
< report::XFunctionsSupplier
>& _xParent
,const uno::Reference
< uno::XComponentContext
>& context
)
34 :FunctionsBase(m_aMutex
)
35 ,m_aContainerListeners(m_aMutex
)
41 // TODO: VirtualFunctionFinder: This is virtual function!
43 OFunctions::~OFunctions()
47 void SAL_CALL
OFunctions::dispose() throw(uno::RuntimeException
, std::exception
)
49 cppu::WeakComponentImplHelperBase::dispose();
52 // TODO: VirtualFunctionFinder: This is virtual function!
54 void SAL_CALL
OFunctions::disposing()
56 ::std::for_each(m_aFunctions
.begin(),m_aFunctions
.end(),::boost::mem_fn(&com::sun::star::report::XFunction::dispose
));
58 lang::EventObject
aDisposeEvent( static_cast< ::cppu::OWeakObject
* >( this ) );
59 m_aContainerListeners
.disposeAndClear( aDisposeEvent
);
65 uno::Reference
< report::XFunction
> SAL_CALL
OFunctions::createFunction( ) throw (uno::RuntimeException
, std::exception
)
67 return new OFunction(m_xContext
);
71 void SAL_CALL
OFunctions::insertByIndex( ::sal_Int32 Index
, const uno::Any
& aElement
) throw (lang::IllegalArgumentException
, lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
74 ::osl::MutexGuard
aGuard(m_aMutex
);
75 bool bAdd
= (Index
== static_cast<sal_Int32
>(m_aFunctions
.size()));
78 uno::Reference
< report::XFunction
> xFunction(aElement
,uno::UNO_QUERY
);
79 if ( !xFunction
.is() )
80 throw lang::IllegalArgumentException(RPT_RESSTRING(RID_STR_ARGUMENT_IS_NULL
,m_xContext
->getServiceManager()),*this,2);
83 m_aFunctions
.push_back(xFunction
);
86 TFunctions::iterator aPos
= m_aFunctions
.begin();
87 ::std::advance(aPos
,Index
);
88 m_aFunctions
.insert(aPos
, xFunction
);
90 xFunction
->setParent(*this);
92 // notify our container listeners
93 container::ContainerEvent
aEvent(static_cast<container::XContainer
*>(this), uno::makeAny(Index
), aElement
, uno::Any());
94 m_aContainerListeners
.notifyEach(&container::XContainerListener::elementInserted
,aEvent
);
98 void SAL_CALL
OFunctions::removeByIndex( ::sal_Int32 Index
) throw (lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
100 uno::Reference
< report::XFunction
> xFunction
;
102 ::osl::MutexGuard
aGuard(m_aMutex
);
104 TFunctions::iterator aPos
= m_aFunctions
.begin();
105 ::std::advance(aPos
,Index
);
107 m_aFunctions
.erase(aPos
);
108 xFunction
->setParent(NULL
);
110 container::ContainerEvent
aEvent(static_cast<container::XContainer
*>(this), uno::makeAny(Index
), uno::makeAny(xFunction
), uno::Any());
111 m_aContainerListeners
.notifyEach(&container::XContainerListener::elementRemoved
,aEvent
);
115 void SAL_CALL
OFunctions::replaceByIndex( ::sal_Int32 Index
, const uno::Any
& Element
) throw (lang::IllegalArgumentException
, lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
117 uno::Any aOldElement
;
119 ::osl::MutexGuard
aGuard(m_aMutex
);
121 uno::Reference
< report::XFunction
> xFunction(Element
,uno::UNO_QUERY
);
122 if ( !xFunction
.is() )
123 throw lang::IllegalArgumentException(RPT_RESSTRING(RID_STR_ARGUMENT_IS_NULL
,m_xContext
->getServiceManager()),*this,2);
124 TFunctions::iterator aPos
= m_aFunctions
.begin();
125 ::std::advance(aPos
,Index
);
126 aOldElement
<<= *aPos
;
130 container::ContainerEvent
aEvent(static_cast<container::XContainer
*>(this), uno::makeAny(Index
), Element
, aOldElement
);
131 m_aContainerListeners
.notifyEach(&container::XContainerListener::elementReplaced
,aEvent
);
135 ::sal_Int32 SAL_CALL
OFunctions::getCount( ) throw (uno::RuntimeException
, std::exception
)
137 ::osl::MutexGuard
aGuard(m_aMutex
);
138 return m_aFunctions
.size();
141 uno::Any SAL_CALL
OFunctions::getByIndex( ::sal_Int32 Index
) throw (lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
143 ::osl::MutexGuard
aGuard(m_aMutex
);
145 TFunctions::iterator aPos
= m_aFunctions
.begin();
146 ::std::advance(aPos
,Index
);
147 return uno::makeAny(*aPos
);
151 uno::Type SAL_CALL
OFunctions::getElementType( ) throw (uno::RuntimeException
, std::exception
)
153 return cppu::UnoType
<report::XFunction
>::get();
156 sal_Bool SAL_CALL
OFunctions::hasElements( ) throw (uno::RuntimeException
, std::exception
)
158 ::osl::MutexGuard
aGuard(m_aMutex
);
159 return !m_aFunctions
.empty();
163 uno::Reference
< uno::XInterface
> SAL_CALL
OFunctions::getParent( ) throw (uno::RuntimeException
, std::exception
)
168 void SAL_CALL
OFunctions::setParent( const uno::Reference
< uno::XInterface
>& /*Parent*/ ) throw (lang::NoSupportException
, uno::RuntimeException
, std::exception
)
170 throw lang::NoSupportException();
174 void SAL_CALL
OFunctions::addContainerListener( const uno::Reference
< container::XContainerListener
>& xListener
) throw (uno::RuntimeException
, std::exception
)
176 m_aContainerListeners
.addInterface(xListener
);
179 void SAL_CALL
OFunctions::removeContainerListener( const uno::Reference
< container::XContainerListener
>& xListener
) throw (uno::RuntimeException
, std::exception
)
181 m_aContainerListeners
.removeInterface(xListener
);
184 void OFunctions::checkIndex(sal_Int32 _nIndex
)
186 if ( _nIndex
< 0 || static_cast<sal_Int32
>(m_aFunctions
.size()) <= _nIndex
)
187 throw lang::IndexOutOfBoundsException();
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */