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