xref: /trunk/main/toolkit/inc/toolkit/controls/eventcontainer.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 
25 #include <osl/diagnose.h>
26 #ifndef _COM_SUN_STAR_XNAMECONTAINER_HPP_
27 #include <com/sun/star/container/XNameContainer.hpp>
28 #endif
29 #ifndef _COM_SUN_STAR_XCONTAINER_HPP_
30 #include <com/sun/star/container/XContainer.hpp>
31 #endif
32 
33 #include <toolkit/helper/listenermultiplexer.hxx>
34 
35 #include <hash_map>
36 #include <cppuhelper/implbase2.hxx>
37 typedef ::cppu::WeakImplHelper2< ::com::sun::star::container::XNameContainer,
38                                  ::com::sun::star::container::XContainer > NameContainerHelper;
39 
40 
41 namespace toolkit
42 {
43 
44 // Hashtable to optimize
45 struct hashName_Impl
46 {
operator ()toolkit::hashName_Impl47     size_t operator()(const ::rtl::OUString Str) const
48     {
49         return (size_t)Str.hashCode();
50     }
51 };
52 
53 struct eqName_Impl
54 {
operator ()toolkit::eqName_Impl55     sal_Bool operator()(const ::rtl::OUString Str1, const ::rtl::OUString Str2) const
56     {
57         return ( Str1 == Str2 );
58     }
59 };
60 
61 typedef std::hash_map
62 <
63     ::rtl::OUString,
64     sal_Int32,
65     hashName_Impl,
66     eqName_Impl
67 >
68 NameContainerNameMap;
69 
70 
71 class NameContainer_Impl : public NameContainerHelper
72 {
73     NameContainerNameMap mHashMap;
74     ::com::sun::star::uno::Sequence< ::rtl::OUString > mNames;
75     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > mValues;
76     sal_Int32 mnElementCount;
77     ::com::sun::star::uno::Type mType;
78 
79     ContainerListenerMultiplexer maContainerListeners;
80 
81 public:
NameContainer_Impl(::com::sun::star::uno::Type const & aType)82     NameContainer_Impl( ::com::sun::star::uno::Type const & aType )
83         : mnElementCount( 0 ),
84           mType( aType ),
85           maContainerListeners( *this )
86     {
87     }
88 
89     // Methods XElementAccess
90     virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  );
91     virtual sal_Bool SAL_CALL hasElements(  );
92 
93     // Methods XNameAccess
94     virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName );
95     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(  );
96     virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName );
97 
98     // Methods XNameReplace
99     virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement );
100 
101     // Methods XNameContainer
102     virtual void SAL_CALL insertByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement );
103     virtual void SAL_CALL removeByName( const ::rtl::OUString& Name );
104 
105     // Methods XContainer
106     void SAL_CALL addContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener );
107     void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener >& xListener );
108 };
109 
110 class ScriptEventContainer : public NameContainer_Impl
111 {
112 public:
113     ScriptEventContainer( void );
114 };
115 
116 
117 }   // namespace toolkit_namecontainer
118