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>
27 // =============================================================================
28 namespace reportdesign
30 // =============================================================================
31 using namespace com::sun::star
;
32 DBG_NAME( rpt_OFunctions
)
33 // -----------------------------------------------------------------------------
34 OFunctions::OFunctions(const uno::Reference
< report::XFunctionsSupplier
>& _xParent
,const uno::Reference
< uno::XComponentContext
>& context
)
35 :FunctionsBase(m_aMutex
)
36 ,m_aContainerListeners(m_aMutex
)
40 DBG_CTOR( rpt_OFunctions
,NULL
);
42 //--------------------------------------------------------------------------
43 // TODO: VirtualFunctionFinder: This is virtual function!
45 OFunctions::~OFunctions()
47 DBG_DTOR( rpt_OFunctions
,NULL
);
49 //--------------------------------------------------------------------------
50 void SAL_CALL
OFunctions::dispose() throw(uno::RuntimeException
)
52 cppu::WeakComponentImplHelperBase::dispose();
54 // -----------------------------------------------------------------------------
55 // TODO: VirtualFunctionFinder: This is virtual function!
57 void SAL_CALL
OFunctions::disposing()
59 ::std::for_each(m_aFunctions
.begin(),m_aFunctions
.end(),::boost::mem_fn(&com::sun::star::report::XFunction::dispose
));
61 lang::EventObject
aDisposeEvent( static_cast< ::cppu::OWeakObject
* >( this ) );
62 m_aContainerListeners
.disposeAndClear( aDisposeEvent
);
65 // -----------------------------------------------------------------------------
67 // -----------------------------------------------------------------------------
68 uno::Reference
< report::XFunction
> SAL_CALL
OFunctions::createFunction( ) throw (uno::RuntimeException
)
70 return new OFunction(m_xContext
);
72 // -----------------------------------------------------------------------------
74 void SAL_CALL
OFunctions::insertByIndex( ::sal_Int32 Index
, const uno::Any
& aElement
) throw (lang::IllegalArgumentException
, lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
)
77 ::osl::MutexGuard
aGuard(m_aMutex
);
78 sal_Bool bAdd
= (Index
== static_cast<sal_Int32
>(m_aFunctions
.size()));
81 uno::Reference
< report::XFunction
> xFunction(aElement
,uno::UNO_QUERY
);
82 if ( !xFunction
.is() )
83 throw lang::IllegalArgumentException(RPT_RESSTRING(RID_STR_ARGUMENT_IS_NULL
,m_xContext
->getServiceManager()),*this,2);
86 m_aFunctions
.push_back(xFunction
);
89 TFunctions::iterator aPos
= m_aFunctions
.begin();
90 ::std::advance(aPos
,Index
);
91 m_aFunctions
.insert(aPos
, xFunction
);
93 xFunction
->setParent(*this);
95 // notify our container listeners
96 container::ContainerEvent
aEvent(static_cast<container::XContainer
*>(this), uno::makeAny(Index
), aElement
, uno::Any());
97 m_aContainerListeners
.notifyEach(&container::XContainerListener::elementInserted
,aEvent
);
100 // -----------------------------------------------------------------------------
101 void SAL_CALL
OFunctions::removeByIndex( ::sal_Int32 Index
) throw (lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
)
103 uno::Reference
< report::XFunction
> xFunction
;
105 ::osl::MutexGuard
aGuard(m_aMutex
);
107 TFunctions::iterator aPos
= m_aFunctions
.begin();
108 ::std::advance(aPos
,Index
);
110 m_aFunctions
.erase(aPos
);
111 xFunction
->setParent(NULL
);
113 container::ContainerEvent
aEvent(static_cast<container::XContainer
*>(this), uno::makeAny(Index
), uno::makeAny(xFunction
), uno::Any());
114 m_aContainerListeners
.notifyEach(&container::XContainerListener::elementRemoved
,aEvent
);
116 // -----------------------------------------------------------------------------
118 void SAL_CALL
OFunctions::replaceByIndex( ::sal_Int32 Index
, const uno::Any
& Element
) throw (lang::IllegalArgumentException
, lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
)
120 uno::Any aOldElement
;
122 ::osl::MutexGuard
aGuard(m_aMutex
);
124 uno::Reference
< report::XFunction
> xFunction(Element
,uno::UNO_QUERY
);
125 if ( !xFunction
.is() )
126 throw lang::IllegalArgumentException(RPT_RESSTRING(RID_STR_ARGUMENT_IS_NULL
,m_xContext
->getServiceManager()),*this,2);
127 TFunctions::iterator aPos
= m_aFunctions
.begin();
128 ::std::advance(aPos
,Index
);
129 aOldElement
<<= *aPos
;
133 container::ContainerEvent
aEvent(static_cast<container::XContainer
*>(this), uno::makeAny(Index
), Element
, aOldElement
);
134 m_aContainerListeners
.notifyEach(&container::XContainerListener::elementReplaced
,aEvent
);
136 // -----------------------------------------------------------------------------
138 ::sal_Int32 SAL_CALL
OFunctions::getCount( ) throw (uno::RuntimeException
)
140 ::osl::MutexGuard
aGuard(m_aMutex
);
141 return m_aFunctions
.size();
143 // -----------------------------------------------------------------------------
144 uno::Any SAL_CALL
OFunctions::getByIndex( ::sal_Int32 Index
) throw (lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
)
146 ::osl::MutexGuard
aGuard(m_aMutex
);
148 TFunctions::iterator aPos
= m_aFunctions
.begin();
149 ::std::advance(aPos
,Index
);
150 return uno::makeAny(*aPos
);
152 // -----------------------------------------------------------------------------
154 uno::Type SAL_CALL
OFunctions::getElementType( ) throw (uno::RuntimeException
)
156 return ::getCppuType(static_cast< uno::Reference
<report::XFunction
>*>(NULL
));
158 // -----------------------------------------------------------------------------
159 ::sal_Bool SAL_CALL
OFunctions::hasElements( ) throw (uno::RuntimeException
)
161 ::osl::MutexGuard
aGuard(m_aMutex
);
162 return !m_aFunctions
.empty();
164 // -----------------------------------------------------------------------------
166 uno::Reference
< uno::XInterface
> SAL_CALL
OFunctions::getParent( ) throw (uno::RuntimeException
)
170 // -----------------------------------------------------------------------------
171 void SAL_CALL
OFunctions::setParent( const uno::Reference
< uno::XInterface
>& /*Parent*/ ) throw (lang::NoSupportException
, uno::RuntimeException
)
173 throw lang::NoSupportException();
175 // -----------------------------------------------------------------------------
177 void SAL_CALL
OFunctions::addContainerListener( const uno::Reference
< container::XContainerListener
>& xListener
) throw (uno::RuntimeException
)
179 m_aContainerListeners
.addInterface(xListener
);
181 // -----------------------------------------------------------------------------
182 void SAL_CALL
OFunctions::removeContainerListener( const uno::Reference
< container::XContainerListener
>& xListener
) throw (uno::RuntimeException
)
184 m_aContainerListeners
.removeInterface(xListener
);
186 // -----------------------------------------------------------------------------
187 void OFunctions::checkIndex(sal_Int32 _nIndex
)
189 if ( _nIndex
< 0 || static_cast<sal_Int32
>(m_aFunctions
.size()) <= _nIndex
)
190 throw lang::IndexOutOfBoundsException();
192 // =============================================================================
194 // =============================================================================
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */