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