1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _TOOLKIT_CONTROLS_UNOCONTROLCONTAINER_HXX_
25 #define _TOOLKIT_CONTROLS_UNOCONTROLCONTAINER_HXX_
26 
27 
28 #include <com/sun/star/awt/XControlContainer.hpp>
29 #include <com/sun/star/awt/XUnoControlContainer.hpp>
30 #include <com/sun/star/container/XContainer.hpp>
31 #include <com/sun/star/container/XIdentifierContainer.hpp>
32 
33 #include <toolkit/controls/unocontrol.hxx>
34 #include <toolkit/controls/unocontrolbase.hxx>
35 #include <toolkit/helper/macros.hxx>
36 #include <toolkit/helper/servicenames.hxx>
37 
38 #include <cppuhelper/implbase4.hxx>
39 
40 class UnoControlHolderList;
41 
42 //	----------------------------------------------------
43 //	class UnoControlContainer
44 //	----------------------------------------------------
45 typedef ::cppu::AggImplInheritanceHelper4   <   UnoControlBase
46                                             ,   ::com::sun::star::awt::XUnoControlContainer
47                                             ,   ::com::sun::star::awt::XControlContainer
48                                             ,   ::com::sun::star::container::XContainer
49                                             ,   ::com::sun::star::container::XIdentifierContainer
50                                             >   UnoControlContainer_Base;
51 
52 class UnoControlContainer : public UnoControlContainer_Base
53 {
54 private:
55 	UnoControlHolderList*					mpControls;
56 	::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTabController > >	maTabControllers;
57 	ContainerListenerMultiplexer			maCListeners;
58 
59 protected:
60 	void									ImplActivateTabControllers();
61 
62 public:
63 				UnoControlContainer( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_factory );
64 				UnoControlContainer( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_factory,
65                                      const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& xPeer );
66 				~UnoControlContainer();
67 
68 
69 	// ::com::sun::star::lang::XComponent
70     void SAL_CALL dispose() throw(::com::sun::star::uno::RuntimeException);
71 
72 	// ::com::sun::star::lang::XEventListener
73     void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
74 
75 	// ::com::sun::star::container::XContainer
76     void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
77     void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
78 
79     // ::com::sun::star::container::XIdentifierContainer
80     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);
81 
82     // ::com::sun::star::container::XIdentifierReplace
83     virtual void SAL_CALL removeByIdentifier( ::sal_Int32 Identifier ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
84     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);
85 
86     // ::com::sun::star::container::XIdentifierAccess
87     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);
88     virtual ::com::sun::star::uno::Sequence< ::sal_Int32 > SAL_CALL getIdentifiers(  ) throw (::com::sun::star::uno::RuntimeException);
89 
90     // ::com::sun::star::container::XElementAccess
91     virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  ) throw (::com::sun::star::uno::RuntimeException);
92     virtual ::sal_Bool SAL_CALL hasElements(  ) throw (::com::sun::star::uno::RuntimeException);
93 
94     // ::com::sun::star::awt::XControlContainer
95     void SAL_CALL setStatusText( const ::rtl::OUString& StatusText ) throw(::com::sun::star::uno::RuntimeException);
96     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > > SAL_CALL getControls(  ) throw(::com::sun::star::uno::RuntimeException);
97     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > SAL_CALL getControl( const ::rtl::OUString& aName ) throw(::com::sun::star::uno::RuntimeException);
98     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);
99     void SAL_CALL removeControl( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& Control ) throw(::com::sun::star::uno::RuntimeException);
100 
101 	// ::com::sun::star::awt::XUnoControlContainer
102     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);
103     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTabController > > SAL_CALL getTabControllers(  ) throw(::com::sun::star::uno::RuntimeException);
104     void SAL_CALL addTabController( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTabController >& TabController ) throw(::com::sun::star::uno::RuntimeException);
105     void SAL_CALL removeTabController( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTabController >& TabController ) throw(::com::sun::star::uno::RuntimeException);
106 
107 	// ::com::sun::star::awt::XControl
108     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);
109 
110 	// ::com::sun::star::awt::XWindow
111     void SAL_CALL setVisible( sal_Bool Visible ) throw(::com::sun::star::uno::RuntimeException);
112 
113 	DECLIMPL_SERVICEINFO_DERIVED( UnoControlContainer, UnoControlBase, szServiceName2_UnoControlContainer )
114 
115 protected:
116 	virtual void removingControl( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl );
117 	virtual void addingControl( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl );
118 
119 private:
120     /** adds the control to the container, does necessary notifications, and the like
121         @param _rxControl
122             the control to add. Must not be <NULL/>
123         @param _pName
124             Pointer to a name for the control. Might be <NULL/>, in this case an auotmatic name is generated
125         @return
126             the ID of the newly added control
127     */
128     sal_Int32 impl_addControl(
129         const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl,
130         const ::rtl::OUString* _pName = NULL
131     );
132 
133     /** removes the given control from the container, including necessary notifications and the like
134         @param  _nId
135             the ID of the control to remove
136         @param  _rxControl
137             the control itself. Must be the one which is stored under the given ID. This parameter could also be
138             obtained inside the method, but callers usually have obtained it, anyway.
139         @param  _pNameAccessor
140             the name which the control was registered for. Might be <NULL/>, in this case
141             container event broadcasts use the ID as accessor.
142     */
143     void      impl_removeControl(
144         sal_Int32 _nId,
145         const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl,
146         const ::rtl::OUString* _pNameAccessor
147     );
148 
149     /** ensures that the given control has a peer, if necessary and possible
150         @param _rxControl
151             an ->XControl which has just been inserted into the container. Must not be <NULL/>.
152         @precond
153             our mutex is locked
154     */
155     void    impl_createControlPeerIfNecessary(
156         const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl
157     );
158 };
159 
160 
161 
162 #endif // _TOOLKIT_CONTROLS_UNOCONTROLCONTAINER_HXX_
163 
164