Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
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>
26 : #include <algorithm>
27 :
28 : namespace reportdesign
29 : {
30 :
31 : using namespace com::sun::star;
32 :
33 0 : OFunctions::OFunctions(const uno::Reference< report::XFunctionsSupplier >& _xParent,const uno::Reference< uno::XComponentContext >& context)
34 : :FunctionsBase(m_aMutex)
35 : ,m_aContainerListeners(m_aMutex)
36 : ,m_xContext(context)
37 0 : ,m_xParent(_xParent)
38 : {
39 0 : }
40 :
41 : // TODO: VirtualFunctionFinder: This is virtual function!
42 :
43 0 : OFunctions::~OFunctions()
44 : {
45 0 : }
46 :
47 0 : void SAL_CALL OFunctions::dispose() throw(uno::RuntimeException, std::exception)
48 : {
49 0 : cppu::WeakComponentImplHelperBase::dispose();
50 0 : }
51 :
52 : // TODO: VirtualFunctionFinder: This is virtual function!
53 :
54 0 : void SAL_CALL OFunctions::disposing()
55 : {
56 0 : ::std::for_each(m_aFunctions.begin(),m_aFunctions.end(),::boost::mem_fn(&com::sun::star::report::XFunction::dispose));
57 0 : m_aFunctions.clear();
58 0 : lang::EventObject aDisposeEvent( static_cast< ::cppu::OWeakObject* >( this ) );
59 0 : m_aContainerListeners.disposeAndClear( aDisposeEvent );
60 0 : m_xContext.clear();
61 0 : }
62 :
63 : // XFunctionsSupplier
64 :
65 0 : uno::Reference< report::XFunction > SAL_CALL OFunctions::createFunction( ) throw (uno::RuntimeException, std::exception)
66 : {
67 0 : return new OFunction(m_xContext);
68 : }
69 :
70 : // XIndexContainer
71 0 : void SAL_CALL OFunctions::insertByIndex( ::sal_Int32 Index, const uno::Any& aElement ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
72 : {
73 : {
74 0 : ::osl::MutexGuard aGuard(m_aMutex);
75 0 : sal_Bool bAdd = (Index == static_cast<sal_Int32>(m_aFunctions.size()));
76 0 : if ( !bAdd )
77 0 : checkIndex(Index);
78 0 : uno::Reference< report::XFunction > xFunction(aElement,uno::UNO_QUERY);
79 0 : if ( !xFunction.is() )
80 0 : throw lang::IllegalArgumentException(RPT_RESSTRING(RID_STR_ARGUMENT_IS_NULL,m_xContext->getServiceManager()),*this,2);
81 :
82 0 : if ( bAdd )
83 0 : m_aFunctions.push_back(xFunction);
84 : else
85 : {
86 0 : TFunctions::iterator aPos = m_aFunctions.begin();
87 0 : ::std::advance(aPos,Index);
88 0 : m_aFunctions.insert(aPos, xFunction);
89 : }
90 0 : xFunction->setParent(*this);
91 : }
92 : // notify our container listeners
93 0 : container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), aElement, uno::Any());
94 0 : m_aContainerListeners.notifyEach(&container::XContainerListener::elementInserted,aEvent);
95 0 : }
96 :
97 :
98 0 : void SAL_CALL OFunctions::removeByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
99 : {
100 0 : uno::Reference< report::XFunction > xFunction;
101 : {
102 0 : ::osl::MutexGuard aGuard(m_aMutex);
103 0 : checkIndex(Index);
104 0 : TFunctions::iterator aPos = m_aFunctions.begin();
105 0 : ::std::advance(aPos,Index);
106 0 : xFunction = *aPos;
107 0 : m_aFunctions.erase(aPos);
108 0 : xFunction->setParent(NULL);
109 : }
110 0 : container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), uno::makeAny(xFunction), uno::Any());
111 0 : m_aContainerListeners.notifyEach(&container::XContainerListener::elementRemoved,aEvent);
112 0 : }
113 :
114 : // XIndexReplace
115 0 : void SAL_CALL OFunctions::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
116 : {
117 0 : uno::Any aOldElement;
118 : {
119 0 : ::osl::MutexGuard aGuard(m_aMutex);
120 0 : checkIndex(Index);
121 0 : uno::Reference< report::XFunction > xFunction(Element,uno::UNO_QUERY);
122 0 : if ( !xFunction.is() )
123 0 : throw lang::IllegalArgumentException(RPT_RESSTRING(RID_STR_ARGUMENT_IS_NULL,m_xContext->getServiceManager()),*this,2);
124 0 : TFunctions::iterator aPos = m_aFunctions.begin();
125 0 : ::std::advance(aPos,Index);
126 0 : aOldElement <<= *aPos;
127 0 : *aPos = xFunction;
128 : }
129 :
130 0 : container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::makeAny(Index), Element, aOldElement);
131 0 : m_aContainerListeners.notifyEach(&container::XContainerListener::elementReplaced,aEvent);
132 0 : }
133 :
134 : // XIndexAccess
135 0 : ::sal_Int32 SAL_CALL OFunctions::getCount( ) throw (uno::RuntimeException, std::exception)
136 : {
137 0 : ::osl::MutexGuard aGuard(m_aMutex);
138 0 : return m_aFunctions.size();
139 : }
140 :
141 0 : uno::Any SAL_CALL OFunctions::getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
142 : {
143 0 : ::osl::MutexGuard aGuard(m_aMutex);
144 0 : checkIndex(Index);
145 0 : TFunctions::iterator aPos = m_aFunctions.begin();
146 0 : ::std::advance(aPos,Index);
147 0 : return uno::makeAny(*aPos);
148 : }
149 :
150 : // XElementAccess
151 0 : uno::Type SAL_CALL OFunctions::getElementType( ) throw (uno::RuntimeException, std::exception)
152 : {
153 0 : return ::getCppuType(static_cast< uno::Reference<report::XFunction>*>(NULL));
154 : }
155 :
156 0 : sal_Bool SAL_CALL OFunctions::hasElements( ) throw (uno::RuntimeException, std::exception)
157 : {
158 0 : ::osl::MutexGuard aGuard(m_aMutex);
159 0 : return !m_aFunctions.empty();
160 : }
161 :
162 : // XChild
163 0 : uno::Reference< uno::XInterface > SAL_CALL OFunctions::getParent( ) throw (uno::RuntimeException, std::exception)
164 : {
165 0 : return m_xParent;
166 : }
167 :
168 0 : void SAL_CALL OFunctions::setParent( const uno::Reference< uno::XInterface >& /*Parent*/ ) throw (lang::NoSupportException, uno::RuntimeException, std::exception)
169 : {
170 0 : throw lang::NoSupportException();
171 : }
172 :
173 : // XContainer
174 0 : void SAL_CALL OFunctions::addContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException, std::exception)
175 : {
176 0 : m_aContainerListeners.addInterface(xListener);
177 0 : }
178 :
179 0 : void SAL_CALL OFunctions::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException, std::exception)
180 : {
181 0 : m_aContainerListeners.removeInterface(xListener);
182 0 : }
183 :
184 0 : void OFunctions::checkIndex(sal_Int32 _nIndex)
185 : {
186 0 : if ( _nIndex < 0 || static_cast<sal_Int32>(m_aFunctions.size()) <= _nIndex )
187 0 : throw lang::IndexOutOfBoundsException();
188 0 : }
189 :
190 : }
191 :
192 :
193 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|