xref: /trunk/main/reportdesign/source/core/api/Functions.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
19e0e4191SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
39e0e4191SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
49e0e4191SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
59e0e4191SAndrew Rist  * distributed with this work for additional information
69e0e4191SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
79e0e4191SAndrew Rist  * to you under the Apache License, Version 2.0 (the
89e0e4191SAndrew Rist  * "License"); you may not use this file except in compliance
99e0e4191SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
119e0e4191SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
139e0e4191SAndrew Rist  * Unless required by applicable law or agreed to in writing,
149e0e4191SAndrew Rist  * software distributed under the License is distributed on an
159e0e4191SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169e0e4191SAndrew Rist  * KIND, either express or implied.  See the License for the
179e0e4191SAndrew Rist  * specific language governing permissions and limitations
189e0e4191SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
209e0e4191SAndrew Rist  *************************************************************/
219e0e4191SAndrew Rist 
229e0e4191SAndrew Rist 
23*b63233d8Sdamjan #include "precompiled_reportdesign.hxx"
24cdf0e10cSrcweir #include "Functions.hxx"
25cdf0e10cSrcweir #include "Function.hxx"
26cdf0e10cSrcweir #include <tools/debug.hxx>
27cdf0e10cSrcweir #include "core_resource.hxx"
28cdf0e10cSrcweir #ifndef REPORTDESIGN_CORE_RESOURCE_HRC_
29cdf0e10cSrcweir #include "core_resource.hrc"
30cdf0e10cSrcweir #endif
31cdf0e10cSrcweir #include <comphelper/property.hxx>
32cdf0e10cSrcweir #include <boost/bind.hpp>
33cdf0e10cSrcweir #include <algorithm>
34cdf0e10cSrcweir // =============================================================================
35cdf0e10cSrcweir namespace reportdesign
36cdf0e10cSrcweir {
37cdf0e10cSrcweir // =============================================================================
38cdf0e10cSrcweir     using namespace com::sun::star;
DBG_NAME(rpt_OFunctions)39cdf0e10cSrcweir DBG_NAME( rpt_OFunctions )
40cdf0e10cSrcweir // -----------------------------------------------------------------------------
41cdf0e10cSrcweir OFunctions::OFunctions(const uno::Reference< report::XFunctionsSupplier >& _xParent,const uno::Reference< uno::XComponentContext >& context)
42cdf0e10cSrcweir :FunctionsBase(m_aMutex)
43cdf0e10cSrcweir ,m_aContainerListeners(m_aMutex)
44cdf0e10cSrcweir ,m_xContext(context)
45cdf0e10cSrcweir ,m_xParent(_xParent)
46cdf0e10cSrcweir {
47cdf0e10cSrcweir     DBG_CTOR( rpt_OFunctions,NULL);
48cdf0e10cSrcweir }
49cdf0e10cSrcweir //--------------------------------------------------------------------------
50cdf0e10cSrcweir // TODO: VirtualFunctionFinder: This is virtual function!
51cdf0e10cSrcweir //
~OFunctions()52cdf0e10cSrcweir OFunctions::~OFunctions()
53cdf0e10cSrcweir {
54cdf0e10cSrcweir     DBG_DTOR( rpt_OFunctions,NULL);
55cdf0e10cSrcweir }
56cdf0e10cSrcweir //--------------------------------------------------------------------------
dispose()57cdf0e10cSrcweir void SAL_CALL OFunctions::dispose() throw(uno::RuntimeException)
58cdf0e10cSrcweir {
59cdf0e10cSrcweir     cppu::WeakComponentImplHelperBase::dispose();
60cdf0e10cSrcweir }
61cdf0e10cSrcweir // -----------------------------------------------------------------------------
62cdf0e10cSrcweir // TODO: VirtualFunctionFinder: This is virtual function!
63cdf0e10cSrcweir //
disposing()64cdf0e10cSrcweir void SAL_CALL OFunctions::disposing()
65cdf0e10cSrcweir {
66cdf0e10cSrcweir     ::std::for_each(m_aFunctions.begin(),m_aFunctions.end(),::boost::mem_fn(&com::sun::star::report::XFunction::dispose));
67cdf0e10cSrcweir     m_aFunctions.clear();
68cdf0e10cSrcweir     lang::EventObject aDisposeEvent( static_cast< ::cppu::OWeakObject* >( this ) );
69cdf0e10cSrcweir     m_aContainerListeners.disposeAndClear( aDisposeEvent );
70cdf0e10cSrcweir     m_xContext.clear();
71cdf0e10cSrcweir }
72cdf0e10cSrcweir // -----------------------------------------------------------------------------
73cdf0e10cSrcweir // XFunctionsSupplier
74cdf0e10cSrcweir // -----------------------------------------------------------------------------
createFunction()75cdf0e10cSrcweir uno::Reference< report::XFunction > SAL_CALL OFunctions::createFunction(  ) throw (uno::RuntimeException)
76cdf0e10cSrcweir {
77cdf0e10cSrcweir     return new OFunction(m_xContext);
78cdf0e10cSrcweir }
79cdf0e10cSrcweir // -----------------------------------------------------------------------------
80cdf0e10cSrcweir // XIndexContainer
insertByIndex(::sal_Int32 Index,const uno::Any & aElement)81cdf0e10cSrcweir void SAL_CALL OFunctions::insertByIndex( ::sal_Int32 Index, const uno::Any& aElement ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
82cdf0e10cSrcweir {
83cdf0e10cSrcweir     {
84cdf0e10cSrcweir         ::osl::MutexGuard aGuard(m_aMutex);
85cdf0e10cSrcweir         sal_Bool bAdd = (Index == static_cast<sal_Int32>(m_aFunctions.size()));
86cdf0e10cSrcweir         if ( !bAdd )
87cdf0e10cSrcweir             checkIndex(Index);
88cdf0e10cSrcweir         uno::Reference< report::XFunction > xFunction(aElement,uno::UNO_QUERY);
89cdf0e10cSrcweir         if ( !xFunction.is() )
90cdf0e10cSrcweir             throw lang::IllegalArgumentException(RPT_RESSTRING(RID_STR_ARGUMENT_IS_NULL,m_xContext->getServiceManager()),*this,2);
91cdf0e10cSrcweir 
92cdf0e10cSrcweir         if ( bAdd )
93cdf0e10cSrcweir             m_aFunctions.push_back(xFunction);
94cdf0e10cSrcweir         else
95cdf0e10cSrcweir         {
96cdf0e10cSrcweir             TFunctions::iterator aPos = m_aFunctions.begin();
97cdf0e10cSrcweir             ::std::advance(aPos,Index);
98cdf0e10cSrcweir             m_aFunctions.insert(aPos, xFunction);
99cdf0e10cSrcweir         }
100cdf0e10cSrcweir         xFunction->setParent(*this);
101cdf0e10cSrcweir     }
102cdf0e10cSrcweir     // notify our container listeners
103cdf0e10cSrcweir     container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), aElement, uno::Any());
104cdf0e10cSrcweir     m_aContainerListeners.notifyEach(&container::XContainerListener::elementInserted,aEvent);
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir // -----------------------------------------------------------------------------
removeByIndex(::sal_Int32 Index)108cdf0e10cSrcweir void SAL_CALL OFunctions::removeByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
109cdf0e10cSrcweir {
110cdf0e10cSrcweir     uno::Reference< report::XFunction > xFunction;
111cdf0e10cSrcweir     {
112cdf0e10cSrcweir         ::osl::MutexGuard aGuard(m_aMutex);
113cdf0e10cSrcweir         checkIndex(Index);
114cdf0e10cSrcweir         TFunctions::iterator aPos = m_aFunctions.begin();
115cdf0e10cSrcweir         ::std::advance(aPos,Index);
116cdf0e10cSrcweir         xFunction = *aPos;
117cdf0e10cSrcweir         m_aFunctions.erase(aPos);
118cdf0e10cSrcweir         xFunction->setParent(NULL);
119cdf0e10cSrcweir     }
120cdf0e10cSrcweir     container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), uno::makeAny(xFunction), uno::Any());
121cdf0e10cSrcweir     m_aContainerListeners.notifyEach(&container::XContainerListener::elementRemoved,aEvent);
122cdf0e10cSrcweir }
123cdf0e10cSrcweir // -----------------------------------------------------------------------------
124cdf0e10cSrcweir // XIndexReplace
replaceByIndex(::sal_Int32 Index,const uno::Any & Element)125cdf0e10cSrcweir void SAL_CALL OFunctions::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
126cdf0e10cSrcweir {
127cdf0e10cSrcweir     uno::Any aOldElement;
128cdf0e10cSrcweir     {
129cdf0e10cSrcweir         ::osl::MutexGuard aGuard(m_aMutex);
130cdf0e10cSrcweir         checkIndex(Index);
131cdf0e10cSrcweir         uno::Reference< report::XFunction > xFunction(Element,uno::UNO_QUERY);
132cdf0e10cSrcweir         if ( !xFunction.is() )
133cdf0e10cSrcweir             throw lang::IllegalArgumentException(RPT_RESSTRING(RID_STR_ARGUMENT_IS_NULL,m_xContext->getServiceManager()),*this,2);
134cdf0e10cSrcweir         TFunctions::iterator aPos = m_aFunctions.begin();
135cdf0e10cSrcweir         ::std::advance(aPos,Index);
136cdf0e10cSrcweir         aOldElement <<= *aPos;
137cdf0e10cSrcweir         *aPos = xFunction;
138cdf0e10cSrcweir     }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir     container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), Element, aOldElement);
141cdf0e10cSrcweir     m_aContainerListeners.notifyEach(&container::XContainerListener::elementReplaced,aEvent);
142cdf0e10cSrcweir }
143cdf0e10cSrcweir // -----------------------------------------------------------------------------
144cdf0e10cSrcweir // XIndexAccess
getCount()145cdf0e10cSrcweir ::sal_Int32 SAL_CALL OFunctions::getCount(  ) throw (uno::RuntimeException)
146cdf0e10cSrcweir {
147cdf0e10cSrcweir     ::osl::MutexGuard aGuard(m_aMutex);
148cdf0e10cSrcweir     return m_aFunctions.size();
149cdf0e10cSrcweir }
150cdf0e10cSrcweir // -----------------------------------------------------------------------------
getByIndex(::sal_Int32 Index)151cdf0e10cSrcweir uno::Any SAL_CALL OFunctions::getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
152cdf0e10cSrcweir {
153cdf0e10cSrcweir     ::osl::MutexGuard aGuard(m_aMutex);
154cdf0e10cSrcweir     checkIndex(Index);
155cdf0e10cSrcweir     TFunctions::iterator aPos = m_aFunctions.begin();
156cdf0e10cSrcweir     ::std::advance(aPos,Index);
157cdf0e10cSrcweir     return uno::makeAny(*aPos);
158cdf0e10cSrcweir }
159cdf0e10cSrcweir // -----------------------------------------------------------------------------
160cdf0e10cSrcweir // XElementAccess
getElementType()161cdf0e10cSrcweir uno::Type SAL_CALL OFunctions::getElementType(  ) throw (uno::RuntimeException)
162cdf0e10cSrcweir {
163cdf0e10cSrcweir     return ::getCppuType(static_cast< uno::Reference<report::XFunction>*>(NULL));
164cdf0e10cSrcweir }
165cdf0e10cSrcweir // -----------------------------------------------------------------------------
hasElements()166cdf0e10cSrcweir ::sal_Bool SAL_CALL OFunctions::hasElements(  ) throw (uno::RuntimeException)
167cdf0e10cSrcweir {
168cdf0e10cSrcweir     ::osl::MutexGuard aGuard(m_aMutex);
169cdf0e10cSrcweir     return !m_aFunctions.empty();
170cdf0e10cSrcweir }
171cdf0e10cSrcweir // -----------------------------------------------------------------------------
172cdf0e10cSrcweir // XChild
getParent()173cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL OFunctions::getParent(  ) throw (uno::RuntimeException)
174cdf0e10cSrcweir {
175cdf0e10cSrcweir     return m_xParent;
176cdf0e10cSrcweir }
177cdf0e10cSrcweir // -----------------------------------------------------------------------------
setParent(const uno::Reference<uno::XInterface> &)178cdf0e10cSrcweir void SAL_CALL OFunctions::setParent( const uno::Reference< uno::XInterface >& /*Parent*/ ) throw (lang::NoSupportException, uno::RuntimeException)
179cdf0e10cSrcweir {
180cdf0e10cSrcweir     throw lang::NoSupportException();
181cdf0e10cSrcweir }
182cdf0e10cSrcweir // -----------------------------------------------------------------------------
183cdf0e10cSrcweir // XContainer
addContainerListener(const uno::Reference<container::XContainerListener> & xListener)184cdf0e10cSrcweir void SAL_CALL OFunctions::addContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
185cdf0e10cSrcweir {
186cdf0e10cSrcweir     m_aContainerListeners.addInterface(xListener);
187cdf0e10cSrcweir }
188cdf0e10cSrcweir // -----------------------------------------------------------------------------
removeContainerListener(const uno::Reference<container::XContainerListener> & xListener)189cdf0e10cSrcweir void SAL_CALL OFunctions::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
190cdf0e10cSrcweir {
191cdf0e10cSrcweir     m_aContainerListeners.removeInterface(xListener);
192cdf0e10cSrcweir }
193cdf0e10cSrcweir // -----------------------------------------------------------------------------
checkIndex(sal_Int32 _nIndex)194cdf0e10cSrcweir void OFunctions::checkIndex(sal_Int32 _nIndex)
195cdf0e10cSrcweir {
196cdf0e10cSrcweir     if ( _nIndex < 0 || static_cast<sal_Int32>(m_aFunctions.size()) <= _nIndex )
197cdf0e10cSrcweir         throw lang::IndexOutOfBoundsException();
198cdf0e10cSrcweir }
199cdf0e10cSrcweir // =============================================================================
200cdf0e10cSrcweir }
201cdf0e10cSrcweir // =============================================================================
202