1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: windowcommanddispatch.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef __FRAMEWORK_DISPATCH_WINDOWCOMMANDDISPATCH_HXX_
32 #define __FRAMEWORK_DISPATCH_WINDOWCOMMANDDISPATCH_HXX_
34 //_______________________________________________
37 #include <threadhelp/threadhelpbase.hxx>
39 //_______________________________________________
42 #include <com/sun/star/awt/XWindow.hpp>
43 #include <com/sun/star/frame/XFrame.hpp>
44 #include <com/sun/star/lang/XEventListener.hpp>
45 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
47 //_______________________________________________
50 #include <cppuhelper/implbase1.hxx>
51 #include <tools/link.hxx>
53 //_______________________________________________
58 namespace css
= ::com::sun::star
;
60 //_______________________________________________
63 //_______________________________________________
64 // exported definitions
66 /** @short internal helper to bind e.g. MAC-Menu events to our internal dispatch API.
68 @descr On e.g. MAC platform system menus are merged together with some fix entries as
69 e.g. "Pereferences" or "About". These menu entries trigger hard coded commands.
70 Here we map these commands to the right URLs and dispatch them.
72 This helper knows a frame and it's container window (where VCL provide the hard coded
73 commands). We hold those objects weak ... so there is no need to react for complex dispose/ing()
74 scenarios. On the other side VCL does not hold us alive (because it doesn't know our UNO reference).
75 So we register us at the XWindow as event listener also to be sure to live as long the XWindow/VCLWindow lives.
77 class WindowCommandDispatch
: private ThreadHelpBase
78 , public ::cppu::WeakImplHelper1
< css::lang::XEventListener
>
80 //___________________________________________
85 /// dispatch URL to trigger our "Tools->Options" dialog
86 static const ::rtl::OUString COMMAND_PREFERENCES
;
88 /// dispatch URL to trigger our About box
89 static const ::rtl::OUString COMMAND_ABOUTBOX
;
91 //___________________________________________
96 /// can be used to create own needed services on demand.
97 css::uno::Reference
< css::lang::XMultiServiceFactory
> m_xSMGR
;
99 /// knows the frame, where we dispatch our commands as weak reference
100 css::uno::WeakReference
< css::frame::XFrame
> m_xFrame
;
102 /// knows the VCL window (where the hard coded commands occured) as weak XWindow reference
103 css::uno::WeakReference
< css::awt::XWindow
> m_xWindow
;
105 //___________________________________________
110 //_______________________________________
112 /** @short creates a new instance and initialize it with all necessary parameters.
114 @descr Every instance of such MACDispatch can be used for the specified context only.
115 Means: 1 MACDispatch object is bound to 1 Frame/Window pair in which context
116 the detected commands will be executed.
119 will be used to create own needed services on demand.
122 used as for new detected commands.
124 WindowCommandDispatch(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xSMGR
,
125 const css::uno::Reference
< css::frame::XFrame
>& xFrame
);
127 //_______________________________________
129 /** @short used to free internal resources.
131 virtual ~WindowCommandDispatch();
133 //___________________________________________
139 virtual void SAL_CALL
disposing(const css::lang::EventObject
& aSource
)
140 throw (css::uno::RuntimeException
);
142 //___________________________________________
147 //_______________________________________
149 /** @short establish all listener connections we need.
151 @descr Those listener connections will be created one times only (see ctor).
152 Afterwards we listen for incoming events till our referred frame/window pair
153 will be closed. All objects die by refcount automatically. Because we hold
156 void impl_startListening();
158 //_______________________________________
160 /** @short callback from VCL to notify new commands
162 DECL_LINK( impl_notifyCommand
, void* );
164 //_______________________________________
166 /** @short dispatch right command URLs into our frame context.
169 the command for dispatch
171 void impl_dispatchCommand(const ::rtl::OUString
& sCommand
);
173 }; // class MACDispatch
175 } // namespace framework
177 #endif // #ifndef __FRAMEWORK_DISPATCH_MACDISPATCH_HXX_