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 #include <vector>
23 #include <hash_map>
24 
25 #include <com/sun/star/frame/XFrame.hpp>
26 #include <com/sun/star/frame/XStatusListener.hpp>
27 #include <com/sun/star/frame/XDispatch.hpp>
28 
29 #include <rtl/ustring.hxx>
30 #include <cppuhelper/implbase1.hxx>
31 
32 
33 typedef std::vector < com::sun::star::uno::Reference < com::sun::star::frame::XStatusListener > > StatusListeners;
34 
35 typedef std::hash_map < rtl::OUString,
36                         StatusListeners,
37                         rtl::OUStringHash,
38                         std::equal_to< rtl::OUString > > ListenerMap;
39 
40 // For every frame there is *one* Dispatch object for all possible commands
41 // this struct contains an array of listeners for every supported command
42 // these arrays are accessed by a hash_map (with the command string as index)
43 struct ListenerItem
44 {
45 	ListenerMap	aContainer;
46 	::com::sun::star::uno::Reference< com::sun::star::frame::XDispatch > xDispatch;
47 	::com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame;
48 };
49 
50 typedef std::vector < ListenerItem > AllListeners;
51 
52 class ListenerHelper
53 {
54 public:
55 	void AddListener(
56 		const com::sun::star::uno::Reference < com::sun::star::frame::XFrame >& xFrame,
57 		const com::sun::star::uno::Reference < com::sun::star::frame::XStatusListener > xControl,
58 		const ::rtl::OUString& aCommand );
59 	void RemoveListener(
60 		const com::sun::star::uno::Reference < com::sun::star::frame::XFrame >& xFrame,
61 		const com::sun::star::uno::Reference < com::sun::star::frame::XStatusListener > xControl,
62 		const ::rtl::OUString& aCommand );
63 	void Notify(
64 		const com::sun::star::uno::Reference < com::sun::star::frame::XFrame >& xFrame,
65 		const ::rtl::OUString& aCommand,
66 		com::sun::star::frame::FeatureStateEvent& rEvent );
67 	com::sun::star::uno::Reference < com::sun::star::frame::XDispatch > GetDispatch(
68 		const com::sun::star::uno::Reference < com::sun::star::frame::XFrame >& xFrame,
69 		const ::rtl::OUString& aCommand );
70 	void AddDispatch(
71 		const com::sun::star::uno::Reference < com::sun::star::frame::XDispatch > xDispatch,
72 		const com::sun::star::uno::Reference < com::sun::star::frame::XFrame >& xFrame,
73 		const ::rtl::OUString& aCommand );
74 };
75 
76 class ListenerItemEventListener : public cppu::WeakImplHelper1 < ::com::sun::star::lang::XEventListener >
77 {
78 	::com::sun::star::uno::Reference< com::sun::star::frame::XFrame > mxFrame;
79 public:
ListenerItemEventListener(const com::sun::star::uno::Reference<com::sun::star::frame::XFrame> & xFrame)80 	ListenerItemEventListener( const com::sun::star::uno::Reference < com::sun::star::frame::XFrame >& xFrame)
81 		: mxFrame(xFrame)
82 	{}
83 	virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& aEvent ) throw (com::sun::star::uno::RuntimeException);
84 };
85