1 #ifndef _MyProtocolHandler_HXX
2 #define _MyProtocolHandler_HXX
3 
4 #include <com/sun/star/awt/XToolkit.hpp>
5 #include <com/sun/star/beans/NamedValue.hpp>
6 #include <com/sun/star/lang/XInitialization.hpp>
7 #include <com/sun/star/lang/XServiceInfo.hpp>
8 #include <com/sun/star/frame/XDispatchProvider.hpp>
9 #include <com/sun/star/frame/XControlNotificationListener.hpp>
10 #include <cppuhelper/implbase2.hxx>
11 #include <cppuhelper/implbase3.hxx>
12 
13 #define MYPROTOCOLHANDLER_IMPLEMENTATIONNAME   "vnd.demo.Impl.ProtocolHandler"
14 #define MYPROTOCOLHANDLER_SERVICENAME          "vnd.demo.ProtocolHandler"
15 
16 namespace com
17 {
18 	namespace sun
19 	{
20 		namespace star
21 		{
22 			namespace frame
23 			{
24 				class XModel;
25 				class XFrame;
26 			}
27 		}
28 	}
29 }
30 
31 
32 class MyProtocolHandler : public cppu::WeakImplHelper3
33 <
34 	com::sun::star::frame::XDispatchProvider,
35 	com::sun::star::lang::XInitialization,
36 	com::sun::star::lang::XServiceInfo
37 >
38 {
39 private:
40     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF;
41 	::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > mxFrame;
42 
43 public:
44 	MyProtocolHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > &rxMSF)
45         : mxMSF( rxMSF ) {}
46 
47 	// XDispatchProvider
48 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >
49 			SAL_CALL queryDispatch(	const ::com::sun::star::util::URL& aURL,
50 				const ::rtl::OUString& sTargetFrameName, sal_Int32 nSearchFlags )
51 				throw( ::com::sun::star::uno::RuntimeException );
52 	virtual ::com::sun::star::uno::Sequence < ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > >
53 		SAL_CALL queryDispatches(
54 			const ::com::sun::star::uno::Sequence < ::com::sun::star::frame::DispatchDescriptor >& seqDescriptor )
55 			throw( ::com::sun::star::uno::RuntimeException );
56 
57 	// XInitialization
58     virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
59 		throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
60 
61 	// XServiceInfo
62     virtual ::rtl::OUString SAL_CALL getImplementationName(  )
63 		throw (::com::sun::star::uno::RuntimeException);
64     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
65 		throw (::com::sun::star::uno::RuntimeException);
66     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  )
67 		throw (::com::sun::star::uno::RuntimeException);
68 };
69 
70 ::rtl::OUString MyProtocolHandler_getImplementationName()
71 	throw ( ::com::sun::star::uno::RuntimeException );
72 
73 sal_Bool SAL_CALL MyProtocolHandler_supportsService( const ::rtl::OUString& ServiceName )
74 	throw ( ::com::sun::star::uno::RuntimeException );
75 
76 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL MyProtocolHandler_getSupportedServiceNames(  )
77 	throw ( ::com::sun::star::uno::RuntimeException );
78 
79 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
80 SAL_CALL MyProtocolHandler_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr)
81 	throw ( ::com::sun::star::uno::Exception );
82 
83 class BaseDispatch : public cppu::WeakImplHelper2
84 <
85 	::com::sun::star::frame::XDispatch,
86     ::com::sun::star::frame::XControlNotificationListener
87 >
88 {
89 protected:
90 	::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > mxFrame;
91     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF;
92 	::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit > mxToolkit;
93     ::rtl::OUString msDocService;
94     ::rtl::OUString maComboBoxText;
95     sal_Bool        mbButtonEnabled;
96 
97 public:
98 	BaseDispatch( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > &rxMSF,
99         const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame, const ::rtl::OUString& rServiceName );
100 
101 	virtual ~BaseDispatch();
102 
103 	void ShowMessageBox( const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame, const ::rtl::OUString& aTitle, const ::rtl::OUString& aMsgText );
104     void SendCommand( const com::sun::star::util::URL& aURL, const ::rtl::OUString& rCommand, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rArgs, sal_Bool bEnabled );
105     void SendCommandTo( const com::sun::star::uno::Reference< com::sun::star::frame::XStatusListener >& xControl, const com::sun::star::util::URL& aURL, const ::rtl::OUString& rCommand, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rArgs, sal_Bool bEnabled );
106 
107 	// XDispatch
108     virtual void SAL_CALL dispatch( const ::com::sun::star::util::URL& aURL,
109 		const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArgs )
110 		throw (::com::sun::star::uno::RuntimeException);
111     virtual void SAL_CALL addStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& xControl,
112 		const ::com::sun::star::util::URL& aURL ) throw (::com::sun::star::uno::RuntimeException);
113     virtual void SAL_CALL removeStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& xControl,
114 		const ::com::sun::star::util::URL& aURL ) throw (::com::sun::star::uno::RuntimeException);
115 
116     // XControlNotificationListener
117     virtual void SAL_CALL controlEvent( const ::com::sun::star::frame::ControlEvent& Event )
118         throw (::com::sun::star::uno::RuntimeException);
119 };
120 
121 class WriterDispatch : public BaseDispatch
122 {
123 public:
124 	WriterDispatch( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > &rxMSF,
125 		const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame )
126         : BaseDispatch( rxMSF, xFrame, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextDocument" ) ) )
127 	{}
128 };
129 
130 class CalcDispatch : public BaseDispatch
131 {
132 public:
133 	CalcDispatch( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > &rxMSF,
134 		const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame )
135         : BaseDispatch( rxMSF, xFrame, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SpreadSheetDocument" ) ) )
136 	{}
137 };
138 
139 #endif
140