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 __SVTOOLS_POPUPMENUCONTROLLERBASE_HXX_
25 #define __SVTOOLS_POPUPMENUCONTROLLERBASE_HXX_
26 
27 #include "svtools/svtdllapi.h"
28 
29 //_________________________________________________________________________________________________________________
30 //	interface includes
31 //_________________________________________________________________________________________________________________
32 #include <com/sun/star/lang/XServiceInfo.hpp>
33 #include <com/sun/star/lang/XTypeProvider.hpp>
34 #include <com/sun/star/lang/XInitialization.hpp>
35 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36 #include <com/sun/star/frame/XFrame.hpp>
37 #include <com/sun/star/frame/XDispatchProvider.hpp>
38 #include <com/sun/star/frame/XDispatch.hpp>
39 #include <com/sun/star/frame/XStatusListener.hpp>
40 #include <com/sun/star/frame/XPopupMenuController.hpp>
41 #include <com/sun/star/uri/XUriReferenceFactory.hpp>
42 #include <com/sun/star/uri/XUriReference.hpp>
43 #include <com/sun/star/util/XURLTransformer.hpp>
44 //_________________________________________________________________________________________________________________
45 //	includes of other projects
46 //_________________________________________________________________________________________________________________
47 #include <toolkit/awt/vclxmenu.hxx>
48 #include <cppuhelper/compbase7.hxx>
49 #include <comphelper/broadcasthelper.hxx>
50 #include <cppuhelper/weak.hxx>
51 #include <rtl/ustring.hxx>
52 
53 namespace svt
54 {
55 	struct PopupMenuControllerBaseDispatchInfo;
56 
57 	typedef ::cppu::WeakComponentImplHelper7<
58 						com::sun::star::lang::XServiceInfo		      ,
59 						com::sun::star::frame::XPopupMenuController ,
60 						com::sun::star::lang::XInitialization         ,
61 						com::sun::star::frame::XStatusListener        ,
62 						com::sun::star::awt::XMenuListener            ,
63 						com::sun::star::frame::XDispatchProvider      ,
64 						com::sun::star::frame::XDispatch > PopupMenuControllerBaseType;
65 
66     class SVT_DLLPUBLIC PopupMenuControllerBase : protected ::comphelper::OBaseMutex,	// Struct for right initalization of mutex member! Must be first of baseclasses.
67 												  public PopupMenuControllerBaseType
68     {
69 		public:
70 		    PopupMenuControllerBase( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager );
71 		    virtual ~PopupMenuControllerBase();
72 
73 		    // XServiceInfo
74             virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException) = 0;
75             virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
76             virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw (::com::sun::star::uno::RuntimeException) = 0;
77 
78             // XPopupMenuController
79             virtual void SAL_CALL setPopupMenu( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu >& PopupMenu ) throw (::com::sun::star::uno::RuntimeException);
80 		    virtual void SAL_CALL updatePopupMenu() throw (::com::sun::star::uno::RuntimeException);
81 
82             // XInitialization
83             virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
84 
85 		    // XStatusListener
86 		    virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException ) = 0;
87 
88             // XMenuListener
89             virtual void SAL_CALL itemHighlighted( const ::com::sun::star::awt::MenuEvent& rEvent ) throw (::com::sun::star::uno::RuntimeException);
90             virtual void SAL_CALL itemSelected( const ::com::sun::star::awt::MenuEvent& rEvent ) throw (::com::sun::star::uno::RuntimeException);
91             virtual void SAL_CALL itemActivated( const ::com::sun::star::awt::MenuEvent& rEvent ) throw (::com::sun::star::uno::RuntimeException);
92             virtual void SAL_CALL itemDeactivated( const ::com::sun::star::awt::MenuEvent& rEvent ) throw (::com::sun::star::uno::RuntimeException);
93 
94             // XDispatchProvider
95             virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > SAL_CALL queryDispatch( const ::com::sun::star::util::URL& aURL, const ::rtl::OUString& sTarget, sal_Int32 nFlags ) throw( ::com::sun::star::uno::RuntimeException );
96             virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > > SAL_CALL queryDispatches( const ::com::sun::star::uno::Sequence< ::com::sun::star::frame::DispatchDescriptor >& lDescriptor ) throw( ::com::sun::star::uno::RuntimeException );
97 
98             // XDispatch
99 		    virtual void SAL_CALL dispatch(	const ::com::sun::star::util::URL& aURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& seqProperties ) throw( ::com::sun::star::uno::RuntimeException );
100 		    virtual void SAL_CALL addStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& xControl, const ::com::sun::star::util::URL& aURL ) throw( ::com::sun::star::uno::RuntimeException );
101     	    virtual void SAL_CALL removeStatusListener(	const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& xControl, const ::com::sun::star::util::URL& aURL ) throw( ::com::sun::star::uno::RuntimeException );
102 
103             // XEventListener
104 		    virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& Source ) throw ( ::com::sun::star::uno::RuntimeException );
105 
106 			void dispatchCommand( const ::rtl::OUString& sCommandURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rArgs );
107 
108 	protected:
109 			void throwIfDisposed() throw ( ::com::sun::star::uno::RuntimeException );
110 
111 			/** helper method to cause statusChanged is called once for the given command url */
112 			void SAL_CALL updateCommand( const rtl::OUString& rCommandURL );
113 
114 			/** this function is called upon disposing the component
115 			*/
116 			virtual void SAL_CALL disposing();
117 
118             virtual void resetPopupMenu( com::sun::star::uno::Reference< com::sun::star::awt::XPopupMenu >& rPopupMenu );
119             virtual void impl_setPopupMenu();
120             virtual void impl_select(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >& _xDispatch,const ::com::sun::star::util::URL& aURL);
121             ::rtl::OUString determineBaseURL( const ::rtl::OUString& aURL );
122 
123 			DECL_STATIC_LINK( PopupMenuControllerBase, ExecuteHdl_Impl, PopupMenuControllerBaseDispatchInfo* );
124 
125 
126             bool                                                                             m_bInitialized;
127             rtl::OUString                                                                    m_aCommandURL;
128             rtl::OUString                                                                    m_aBaseURL;
129             ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >           m_xDispatch;
130             ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >              m_xFrame;
131             ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager;
132             ::com::sun::star::uno::Reference< ::com::sun::star::util::XURLTransformer >      m_xURLTransformer;
133             ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu >            m_xPopupMenu;
134     };
135 }
136 
137 #endif // __SVTOOLS_POPUPMENUCONTROLLERBASE_HXX_
138