1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Functions.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "Functions.hxx"
31 #include "Function.hxx"
32 #include <tools/debug.hxx>
33 #include "core_resource.hxx"
34 #ifndef REPORTDESIGN_CORE_RESOURCE_HRC_
35 #include "core_resource.hrc"
37 #include <comphelper/property.hxx>
38 #include <boost/bind.hpp>
40 // =============================================================================
41 namespace reportdesign
43 // =============================================================================
44 using namespace com::sun::star
;
45 DBG_NAME( rpt_OFunctions
)
46 // -----------------------------------------------------------------------------
47 OFunctions::OFunctions(const uno::Reference
< report::XFunctionsSupplier
>& _xParent
,const uno::Reference
< uno::XComponentContext
>& context
)
48 :FunctionsBase(m_aMutex
)
49 ,m_aContainerListeners(m_aMutex
)
53 DBG_CTOR( rpt_OFunctions
,NULL
);
55 //--------------------------------------------------------------------------
56 // TODO: VirtualFunctionFinder: This is virtual function!
58 OFunctions::~OFunctions()
60 DBG_DTOR( rpt_OFunctions
,NULL
);
62 //--------------------------------------------------------------------------
63 void SAL_CALL
OFunctions::dispose() throw(uno::RuntimeException
)
65 cppu::WeakComponentImplHelperBase::dispose();
67 // -----------------------------------------------------------------------------
68 // TODO: VirtualFunctionFinder: This is virtual function!
70 void SAL_CALL
OFunctions::disposing()
72 ::std::for_each(m_aFunctions
.begin(),m_aFunctions
.end(),::boost::mem_fn(&com::sun::star::report::XFunction::dispose
));
74 lang::EventObject
aDisposeEvent( static_cast< ::cppu::OWeakObject
* >( this ) );
75 m_aContainerListeners
.disposeAndClear( aDisposeEvent
);
78 // -----------------------------------------------------------------------------
80 // -----------------------------------------------------------------------------
81 uno::Reference
< report::XFunction
> SAL_CALL
OFunctions::createFunction( ) throw (uno::RuntimeException
)
83 return new OFunction(m_xContext
);
85 // -----------------------------------------------------------------------------
87 void SAL_CALL
OFunctions::insertByIndex( ::sal_Int32 Index
, const uno::Any
& aElement
) throw (lang::IllegalArgumentException
, lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
)
90 ::osl::MutexGuard
aGuard(m_aMutex
);
91 sal_Bool bAdd
= (Index
== static_cast<sal_Int32
>(m_aFunctions
.size()));
94 uno::Reference
< report::XFunction
> xFunction(aElement
,uno::UNO_QUERY
);
95 if ( !xFunction
.is() )
96 throw lang::IllegalArgumentException(RPT_RESSTRING(RID_STR_ARGUMENT_IS_NULL
,m_xContext
->getServiceManager()),*this,2);
99 m_aFunctions
.push_back(xFunction
);
102 TFunctions::iterator aPos
= m_aFunctions
.begin();
103 ::std::advance(aPos
,Index
);
104 m_aFunctions
.insert(aPos
, xFunction
);
106 xFunction
->setParent(*this);
108 // notify our container listeners
109 container::ContainerEvent
aEvent(static_cast<container::XContainer
*>(this), uno::makeAny(Index
), aElement
, uno::Any());
110 m_aContainerListeners
.notifyEach(&container::XContainerListener::elementInserted
,aEvent
);
113 // -----------------------------------------------------------------------------
114 void SAL_CALL
OFunctions::removeByIndex( ::sal_Int32 Index
) throw (lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
)
116 uno::Reference
< report::XFunction
> xFunction
;
118 ::osl::MutexGuard
aGuard(m_aMutex
);
120 TFunctions::iterator aPos
= m_aFunctions
.begin();
121 ::std::advance(aPos
,Index
);
123 m_aFunctions
.erase(aPos
);
124 xFunction
->setParent(NULL
);
126 container::ContainerEvent
aEvent(static_cast<container::XContainer
*>(this), uno::makeAny(Index
), uno::makeAny(xFunction
), uno::Any());
127 m_aContainerListeners
.notifyEach(&container::XContainerListener::elementRemoved
,aEvent
);
129 // -----------------------------------------------------------------------------
131 void SAL_CALL
OFunctions::replaceByIndex( ::sal_Int32 Index
, const uno::Any
& Element
) throw (lang::IllegalArgumentException
, lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
)
133 uno::Any aOldElement
;
135 ::osl::MutexGuard
aGuard(m_aMutex
);
137 uno::Reference
< report::XFunction
> xFunction(Element
,uno::UNO_QUERY
);
138 if ( !xFunction
.is() )
139 throw lang::IllegalArgumentException(RPT_RESSTRING(RID_STR_ARGUMENT_IS_NULL
,m_xContext
->getServiceManager()),*this,2);
140 TFunctions::iterator aPos
= m_aFunctions
.begin();
141 ::std::advance(aPos
,Index
);
142 aOldElement
<<= *aPos
;
146 container::ContainerEvent
aEvent(static_cast<container::XContainer
*>(this), uno::makeAny(Index
), Element
, aOldElement
);
147 m_aContainerListeners
.notifyEach(&container::XContainerListener::elementReplaced
,aEvent
);
149 // -----------------------------------------------------------------------------
151 ::sal_Int32 SAL_CALL
OFunctions::getCount( ) throw (uno::RuntimeException
)
153 ::osl::MutexGuard
aGuard(m_aMutex
);
154 return m_aFunctions
.size();
156 // -----------------------------------------------------------------------------
157 uno::Any SAL_CALL
OFunctions::getByIndex( ::sal_Int32 Index
) throw (lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
)
159 ::osl::MutexGuard
aGuard(m_aMutex
);
161 TFunctions::iterator aPos
= m_aFunctions
.begin();
162 ::std::advance(aPos
,Index
);
163 return uno::makeAny(*aPos
);
165 // -----------------------------------------------------------------------------
167 uno::Type SAL_CALL
OFunctions::getElementType( ) throw (uno::RuntimeException
)
169 return ::getCppuType(static_cast< uno::Reference
<report::XFunction
>*>(NULL
));
171 // -----------------------------------------------------------------------------
172 ::sal_Bool SAL_CALL
OFunctions::hasElements( ) throw (uno::RuntimeException
)
174 ::osl::MutexGuard
aGuard(m_aMutex
);
175 return !m_aFunctions
.empty();
177 // -----------------------------------------------------------------------------
179 uno::Reference
< uno::XInterface
> SAL_CALL
OFunctions::getParent( ) throw (uno::RuntimeException
)
183 // -----------------------------------------------------------------------------
184 void SAL_CALL
OFunctions::setParent( const uno::Reference
< uno::XInterface
>& /*Parent*/ ) throw (lang::NoSupportException
, uno::RuntimeException
)
186 throw lang::NoSupportException();
188 // -----------------------------------------------------------------------------
190 void SAL_CALL
OFunctions::addContainerListener( const uno::Reference
< container::XContainerListener
>& xListener
) throw (uno::RuntimeException
)
192 m_aContainerListeners
.addInterface(xListener
);
194 // -----------------------------------------------------------------------------
195 void SAL_CALL
OFunctions::removeContainerListener( const uno::Reference
< container::XContainerListener
>& xListener
) throw (uno::RuntimeException
)
197 m_aContainerListeners
.removeInterface(xListener
);
199 // -----------------------------------------------------------------------------
200 void OFunctions::checkIndex(sal_Int32 _nIndex
)
202 if ( _nIndex
< 0 || static_cast<sal_Int32
>(m_aFunctions
.size()) <= _nIndex
)
203 throw lang::IndexOutOfBoundsException();
205 // =============================================================================
207 // =============================================================================