1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef __FRAMEWORK_DISPATCH_WINDOWCOMMANDDISPATCH_HXX_ 29*cdf0e10cSrcweir #define __FRAMEWORK_DISPATCH_WINDOWCOMMANDDISPATCH_HXX_ 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir //_______________________________________________ 32*cdf0e10cSrcweir // my own includes 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #include <threadhelp/threadhelpbase.hxx> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir //_______________________________________________ 37*cdf0e10cSrcweir // interface includes 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/lang/XEventListener.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir //_______________________________________________ 45*cdf0e10cSrcweir // other includes 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 48*cdf0e10cSrcweir #include <tools/link.hxx> 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir //_______________________________________________ 51*cdf0e10cSrcweir // namespace 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir namespace framework{ 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir namespace css = ::com::sun::star; 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir //_______________________________________________ 58*cdf0e10cSrcweir // exported const 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir //_______________________________________________ 61*cdf0e10cSrcweir // exported definitions 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir /** @short internal helper to bind e.g. MAC-Menu events to our internal dispatch API. 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir @descr On e.g. MAC platform system menus are merged together with some fix entries as 66*cdf0e10cSrcweir e.g. "Pereferences" or "About". These menu entries trigger hard coded commands. 67*cdf0e10cSrcweir Here we map these commands to the right URLs and dispatch them. 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir This helper knows a frame and it's container window (where VCL provide the hard coded 70*cdf0e10cSrcweir commands). We hold those objects weak ... so there is no need to react for complex dispose/ing() 71*cdf0e10cSrcweir scenarios. On the other side VCL does not hold us alive (because it doesn't know our UNO reference). 72*cdf0e10cSrcweir So we register us at the XWindow as event listener also to be sure to live as long the XWindow/VCLWindow lives. 73*cdf0e10cSrcweir */ 74*cdf0e10cSrcweir class WindowCommandDispatch : private ThreadHelpBase 75*cdf0e10cSrcweir , public ::cppu::WeakImplHelper1< css::lang::XEventListener > 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir //___________________________________________ 78*cdf0e10cSrcweir // const 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir private: 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir /// dispatch URL to trigger our "Tools->Options" dialog 83*cdf0e10cSrcweir static const ::rtl::OUString COMMAND_PREFERENCES; 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir /// dispatch URL to trigger our About box 86*cdf0e10cSrcweir static const ::rtl::OUString COMMAND_ABOUTBOX; 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir //___________________________________________ 89*cdf0e10cSrcweir // member 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir private: 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir /// can be used to create own needed services on demand. 94*cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR; 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir /// knows the frame, where we dispatch our commands as weak reference 97*cdf0e10cSrcweir css::uno::WeakReference< css::frame::XFrame > m_xFrame; 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir /// knows the VCL window (where the hard coded commands occured) as weak XWindow reference 100*cdf0e10cSrcweir css::uno::WeakReference< css::awt::XWindow > m_xWindow; 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir //___________________________________________ 103*cdf0e10cSrcweir // native interface 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir public: 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir //_______________________________________ 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir /** @short creates a new instance and initialize it with all necessary parameters. 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir @descr Every instance of such MACDispatch can be used for the specified context only. 112*cdf0e10cSrcweir Means: 1 MACDispatch object is bound to 1 Frame/Window pair in which context 113*cdf0e10cSrcweir the detected commands will be executed. 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir @param xSMGR 116*cdf0e10cSrcweir will be used to create own needed services on demand. 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir @param xFrame 119*cdf0e10cSrcweir used as for new detected commands. 120*cdf0e10cSrcweir */ 121*cdf0e10cSrcweir WindowCommandDispatch(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR , 122*cdf0e10cSrcweir const css::uno::Reference< css::frame::XFrame >& xFrame); 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir //_______________________________________ 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir /** @short used to free internal resources. 127*cdf0e10cSrcweir */ 128*cdf0e10cSrcweir virtual ~WindowCommandDispatch(); 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir //___________________________________________ 131*cdf0e10cSrcweir // uno interface 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir public: 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir // XEventListener 136*cdf0e10cSrcweir virtual void SAL_CALL disposing(const css::lang::EventObject& aSource) 137*cdf0e10cSrcweir throw (css::uno::RuntimeException); 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir //___________________________________________ 140*cdf0e10cSrcweir // implementation 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir private: 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir //_______________________________________ 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir /** @short establish all listener connections we need. 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir @descr Those listener connections will be created one times only (see ctor). 149*cdf0e10cSrcweir Afterwards we listen for incoming events till our referred frame/window pair 150*cdf0e10cSrcweir will be closed. All objects die by refcount automatically. Because we hold 151*cdf0e10cSrcweir it weak ... 152*cdf0e10cSrcweir */ 153*cdf0e10cSrcweir void impl_startListening(); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir //_______________________________________ 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir /** @short callback from VCL to notify new commands 158*cdf0e10cSrcweir */ 159*cdf0e10cSrcweir DECL_LINK( impl_notifyCommand, void* ); 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir //_______________________________________ 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir /** @short dispatch right command URLs into our frame context. 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir @param sCommand 166*cdf0e10cSrcweir the command for dispatch 167*cdf0e10cSrcweir */ 168*cdf0e10cSrcweir void impl_dispatchCommand(const ::rtl::OUString& sCommand); 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir }; // class MACDispatch 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir } // namespace framework 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir #endif // #ifndef __FRAMEWORK_DISPATCH_MACDISPATCH_HXX_ 175