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