1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _TOOLKIT_CONTROLS_UNOCONTROLCONTAINER_HXX_
29 #define _TOOLKIT_CONTROLS_UNOCONTROLCONTAINER_HXX_
30 
31 
32 #include <com/sun/star/awt/XControlContainer.hpp>
33 #include <com/sun/star/awt/XUnoControlContainer.hpp>
34 #include <com/sun/star/container/XContainer.hpp>
35 #include <com/sun/star/container/XIdentifierContainer.hpp>
36 
37 #include <toolkit/controls/unocontrol.hxx>
38 #include <toolkit/controls/unocontrolbase.hxx>
39 #include <toolkit/helper/macros.hxx>
40 #include <toolkit/helper/servicenames.hxx>
41 
42 #include <cppuhelper/implbase4.hxx>
43 
44 class UnoControlHolderList;
45 
46 //	----------------------------------------------------
47 //	class UnoControlContainer
48 //	----------------------------------------------------
49 typedef ::cppu::AggImplInheritanceHelper4   <   UnoControlBase
50                                             ,   ::com::sun::star::awt::XUnoControlContainer
51                                             ,   ::com::sun::star::awt::XControlContainer
52                                             ,   ::com::sun::star::container::XContainer
53                                             ,   ::com::sun::star::container::XIdentifierContainer
54                                             >   UnoControlContainer_Base;
55 
56 class UnoControlContainer : public UnoControlContainer_Base
57 {
58 private:
59 	UnoControlHolderList*					mpControls;
60 	::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTabController > >	maTabControllers;
61 	ContainerListenerMultiplexer			maCListeners;
62 
63 protected:
64 	void									ImplActivateTabControllers();
65 
66 public:
67 				UnoControlContainer( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_factory );
68 				UnoControlContainer( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_factory,
69                                      const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& xPeer );
70 				~UnoControlContainer();
71 
72 
73 	// ::com::sun::star::lang::XComponent
74     void SAL_CALL dispose() throw(::com::sun::star::uno::RuntimeException);
75 
76 	// ::com::sun::star::lang::XEventListener
77     void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
78 
79 	// ::com::sun::star::container::XContainer
80     void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
81     void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
82 
83     // ::com::sun::star::container::XIdentifierContainer
84     virtual ::sal_Int32 SAL_CALL insert( const ::com::sun::star::uno::Any& aElement ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
85 
86     // ::com::sun::star::container::XIdentifierReplace
87     virtual void SAL_CALL removeByIdentifier( ::sal_Int32 Identifier ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
88     virtual void SAL_CALL replaceByIdentifer( ::sal_Int32 Identifier, const ::com::sun::star::uno::Any& aElement ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
89 
90     // ::com::sun::star::container::XIdentifierAccess
91     virtual ::com::sun::star::uno::Any SAL_CALL getByIdentifier( ::sal_Int32 Identifierr ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
92     virtual ::com::sun::star::uno::Sequence< ::sal_Int32 > SAL_CALL getIdentifiers(  ) throw (::com::sun::star::uno::RuntimeException);
93 
94     // ::com::sun::star::container::XElementAccess
95     virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  ) throw (::com::sun::star::uno::RuntimeException);
96     virtual ::sal_Bool SAL_CALL hasElements(  ) throw (::com::sun::star::uno::RuntimeException);
97 
98     // ::com::sun::star::awt::XControlContainer
99     void SAL_CALL setStatusText( const ::rtl::OUString& StatusText ) throw(::com::sun::star::uno::RuntimeException);
100     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > > SAL_CALL getControls(  ) throw(::com::sun::star::uno::RuntimeException);
101     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > SAL_CALL getControl( const ::rtl::OUString& aName ) throw(::com::sun::star::uno::RuntimeException);
102     void SAL_CALL addControl( const ::rtl::OUString& Name, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& Control ) throw(::com::sun::star::uno::RuntimeException);
103     void SAL_CALL removeControl( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& Control ) throw(::com::sun::star::uno::RuntimeException);
104 
105 	// ::com::sun::star::awt::XUnoControlContainer
106     void SAL_CALL setTabControllers( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTabController > >& TabControllers ) throw(::com::sun::star::uno::RuntimeException);
107     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTabController > > SAL_CALL getTabControllers(  ) throw(::com::sun::star::uno::RuntimeException);
108     void SAL_CALL addTabController( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTabController >& TabController ) throw(::com::sun::star::uno::RuntimeException);
109     void SAL_CALL removeTabController( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTabController >& TabController ) throw(::com::sun::star::uno::RuntimeException);
110 
111 	// ::com::sun::star::awt::XControl
112     void SAL_CALL createPeer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit >& Toolkit, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& Parent ) throw(::com::sun::star::uno::RuntimeException);
113 
114 	// ::com::sun::star::awt::XWindow
115     void SAL_CALL setVisible( sal_Bool Visible ) throw(::com::sun::star::uno::RuntimeException);
116 
117 	DECLIMPL_SERVICEINFO_DERIVED( UnoControlContainer, UnoControlBase, szServiceName2_UnoControlContainer )
118 
119 protected:
120 	virtual void removingControl( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl );
121 	virtual void addingControl( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl );
122 
123 private:
124     /** adds the control to the container, does necessary notifications, and the like
125         @param _rxControl
126             the control to add. Must not be <NULL/>
127         @param _pName
128             Pointer to a name for the control. Might be <NULL/>, in this case an auotmatic name is generated
129         @return
130             the ID of the newly added control
131     */
132     sal_Int32 impl_addControl(
133         const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl,
134         const ::rtl::OUString* _pName = NULL
135     );
136 
137     /** removes the given control from the container, including necessary notifications and the like
138         @param  _nId
139             the ID of the control to remove
140         @param  _rxControl
141             the control itself. Must be the one which is stored under the given ID. This parameter could also be
142             obtained inside the method, but callers usually have obtained it, anyway.
143         @param  _pNameAccessor
144             the name which the control was registered for. Might be <NULL/>, in this case
145             container event broadcasts use the ID as accessor.
146     */
147     void      impl_removeControl(
148         sal_Int32 _nId,
149         const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl,
150         const ::rtl::OUString* _pNameAccessor
151     );
152 
153     /** ensures that the given control has a peer, if necessary and possible
154         @param _rxControl
155             an ->XControl which has just been inserted into the container. Must not be <NULL/>.
156         @precond
157             our mutex is locked
158     */
159     void    impl_createControlPeerIfNecessary(
160         const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl
161     );
162 };
163 
164 
165 
166 #endif // _TOOLKIT_CONTROLS_UNOCONTROLCONTAINER_HXX_
167 
168