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