update emoji autocorrect entries from po-files
[LibreOffice.git] / include / comphelper / proxyaggregation.hxx
blob426ce3efcc8ba8c43371bf8eb5cb4541ac6b605c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #ifndef INCLUDED_COMPHELPER_PROXYAGGREGATION_HXX
21 #define INCLUDED_COMPHELPER_PROXYAGGREGATION_HXX
23 #include <com/sun/star/uno/XAggregation.hpp>
24 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 #include <com/sun/star/lang/XComponent.hpp>
26 #include <cppuhelper/implbase1.hxx>
27 #include <cppuhelper/interfacecontainer.hxx>
28 #include <comphelper/uno3.hxx>
29 #include <comphelper/broadcasthelper.hxx>
30 #include <cppuhelper/compbase_ex.hxx>
31 #include <comphelper/comphelperdllapi.h>
33 namespace com { namespace sun { namespace star { namespace uno {
34 class XComponentContext;
35 } } } }
37 /* class hierarchy herein:
39 +-------------------+ helper class for aggregating the proxy to another object
40 | OProxyAggregation | - not ref counted
41 +-------------------+ - no UNO implementation, i.e. not derived from XInterface
42 ^ (neither direct nor indirect)
45 +----------------------------------+ helper class for aggregating a proxy to an XComponent
46 | OComponentProxyAggregationHelper | - life time coupling: if the inner component (the "aggregate")
47 +----------------------------------+ is disposed, the outer (the delegator) is disposed, too, and
48 ^ vice versa
49 | - UNO based, implementing XEventListener
51 +----------------------------+ component aggregating another XComponent
52 | OComponentProxyAggregation | - life time coupling as above
53 +----------------------------+ - ref-counted
54 - implements an XComponent itself
56 If you need to
58 - wrap a foreign object which is a XComponent
59 => use OComponentProxyAggregation
60 - call componentAggregateProxyFor in your ctor
61 - call implEnsureDisposeInDtor in your dtor
63 - wrap a foreign object which is a XComponent, but already have ref-counting mechanisms
64 inherited from somewhere else
65 => use OComponentProxyAggregationHelper
66 - override dispose - don't forget to call the base class' dispose!
67 - call componentAggregateProxyFor in your ctor
69 - wrap a foreign object which is no XComponent
70 => use OProxyAggregation
71 - call baseAggregateProxyFor in your ctor
75 namespace comphelper
80 //= OProxyAggregation
82 /** helper class for aggregating a proxy for a foreign object
84 class OProxyAggregation
86 private:
87 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XAggregation > m_xProxyAggregate;
88 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XTypeProvider > m_xProxyTypeAccess;
89 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
91 protected:
92 inline const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& getComponentContext()
94 return m_xContext;
97 protected:
98 OProxyAggregation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext );
99 ~OProxyAggregation();
101 /// to be called from within your ctor
102 void baseAggregateProxyFor(
103 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxComponent,
104 oslInterlockedCount& _rRefCount,
105 ::cppu::OWeakObject& _rDelegator
108 // XInterface and XTypeProvider
109 ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException);
110 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw (::com::sun::star::uno::RuntimeException);
112 private:
113 OProxyAggregation( const OProxyAggregation& ) SAL_DELETED_FUNCTION;
114 OProxyAggregation& operator=( const OProxyAggregation& ) SAL_DELETED_FUNCTION;
118 //= OComponentProxyAggregationHelper
120 /** a helper class for aggregating a proxy to an XComponent
122 <p>The object couples the life time of itself and the component: if one of the both
123 dies (in a sense of being disposed), the other one dies, too.</p>
125 <p>The class itself does not implement XComponent so you need to forward any XComponent::dispose
126 calls which your derived class gets to the dispose method of this class.</p>
129 class COMPHELPER_DLLPUBLIC OComponentProxyAggregationHelper :public ::cppu::ImplHelper1 < com::sun::star::lang::XEventListener
131 ,private OProxyAggregation
133 private:
134 typedef ::cppu::ImplHelper1 < ::com::sun::star::lang::XEventListener
135 > BASE; // prevents some MSVC problems
137 protected:
138 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >
139 m_xInner;
140 ::cppu::OBroadcastHelper& m_rBHelper;
142 protected:
143 // OProxyAggregation
144 using OProxyAggregation::getComponentContext;
146 // XInterface
147 ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
149 // XTypeProvider
150 DECLARE_XTYPEPROVIDER( )
152 protected:
153 OComponentProxyAggregationHelper(
154 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
155 ::cppu::OBroadcastHelper& _rBHelper
157 virtual ~OComponentProxyAggregationHelper( );
159 /// to be called from within your ctor
160 void componentAggregateProxyFor(
161 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _rxComponent,
162 oslInterlockedCount& _rRefCount,
163 ::cppu::OWeakObject& _rDelegator
166 // XEventListener
167 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
169 // XComponent
170 virtual void SAL_CALL dispose() throw( ::com::sun::star::uno::RuntimeException, std::exception ) = 0;
172 private:
173 OComponentProxyAggregationHelper( const OComponentProxyAggregationHelper& ) SAL_DELETED_FUNCTION;
174 OComponentProxyAggregationHelper& operator=( const OComponentProxyAggregationHelper& ) SAL_DELETED_FUNCTION;
178 //= OComponentProxyAggregation
180 class COMPHELPER_DLLPUBLIC OComponentProxyAggregation :public OBaseMutex
181 ,public cppu::WeakComponentImplHelperBase
182 ,public OComponentProxyAggregationHelper
184 protected:
185 OComponentProxyAggregation(
186 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
187 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _rxComponent
190 virtual ~OComponentProxyAggregation();
192 // XInterface
193 DECLARE_XINTERFACE()
194 // XTypeProvider
195 DECLARE_XTYPEPROVIDER()
197 // OComponentHelper
198 virtual void SAL_CALL disposing() throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
200 // XEventListener
201 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& _rSource ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
203 // XComponent/OComponentProxyAggregationHelper
204 virtual void SAL_CALL dispose() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
206 protected:
207 // be called from within the dtor of derived classes
208 void implEnsureDisposeInDtor( );
210 private:
211 OComponentProxyAggregation( const OComponentProxyAggregation& ) SAL_DELETED_FUNCTION;
212 OComponentProxyAggregation& operator=( const OComponentProxyAggregation& ) SAL_DELETED_FUNCTION;
216 } // namespace comphelper
220 #endif // INCLUDED_COMPHELPER_PROXYAGGREGATION_HXX
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */