1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef __FRAMEWORK_DISPATCH_MENUDISPATCHER_HXX_ 29 #define __FRAMEWORK_DISPATCH_MENUDISPATCHER_HXX_ 30 31 //_________________________________________________________________________________________________________________ 32 // my own includes 33 //_________________________________________________________________________________________________________________ 34 35 #include <classes/taskcreator.hxx> 36 #include <services/frame.hxx> 37 #include <macros/generic.hxx> 38 #include <macros/xinterface.hxx> 39 #include <macros/xtypeprovider.hxx> 40 #include <macros/debug.hxx> 41 #include <threadhelp/threadhelpbase.hxx> 42 #include <classes/menumanager.hxx> 43 #include <general.h> 44 #include <stdtypes.h> 45 46 //_________________________________________________________________________________________________________________ 47 // interface includes 48 //_________________________________________________________________________________________________________________ 49 #include <com/sun/star/lang/XTypeProvider.hpp> 50 #include <com/sun/star/frame/XDispatch.hpp> 51 #include <com/sun/star/util/URL.hpp> 52 #include <com/sun/star/frame/DispatchDescriptor.hpp> 53 #include <com/sun/star/beans/PropertyValue.hpp> 54 #include <com/sun/star/frame/XStatusListener.hpp> 55 #include <com/sun/star/frame/XFrameLoader.hpp> 56 #include <com/sun/star/frame/XLoadEventListener.hpp> 57 #include <com/sun/star/frame/XDesktop.hpp> 58 #include <com/sun/star/frame/FeatureStateEvent.hpp> 59 #include <com/sun/star/frame/XFrameActionListener.hpp> 60 61 //_________________________________________________________________________________________________________________ 62 // other includes 63 //_________________________________________________________________________________________________________________ 64 #include <cppuhelper/weak.hxx> 65 #include <cppuhelper/weakref.hxx> 66 #include <cppuhelper/interfacecontainer.h> 67 68 //_________________________________________________________________________________________________________________ 69 // namespace 70 //_________________________________________________________________________________________________________________ 71 72 namespace framework{ 73 74 75 //_________________________________________________________________________________________________________________ 76 // exported const 77 //_________________________________________________________________________________________________________________ 78 79 //_________________________________________________________________________________________________________________ 80 // exported definitions 81 //_________________________________________________________________________________________________________________ 82 83 /*-************************************************************************************************************//** 84 We must save informations about our listener and URL for listening. 85 We implement this as a hashtable for strings. 86 *//*-*************************************************************************************************************/ 87 88 typedef ::cppu::OMultiTypeInterfaceContainerHelperVar< ::rtl::OUString , 89 OUStringHashCode , 90 std::equal_to< ::rtl::OUString > > IMPL_ListenerHashContainer; 91 92 93 /*-************************************************************************************************************//** 94 @short helper for desktop only(!) to create new tasks on demand for dispatches 95 @descr Use this class as member only! Never use it as baseclass. 96 XInterface will be ambigous and we hold a weakcss::uno::Reference to ouer OWNER - not to ouer SUPERCLASS! 97 98 @implements XInterface 99 XDispatch 100 XLoadEventListener 101 XFrameActionListener 102 XEventListener 103 @base ThreadHelpBase 104 OWeakObject 105 106 @devstatus ready to use 107 *//*-*************************************************************************************************************/ 108 class MenuDispatcher : // interfaces 109 public css::lang::XTypeProvider , 110 public css::frame::XDispatch , 111 public css::frame::XFrameActionListener , 112 // baseclasses 113 // Order is neccessary for right initialization! 114 public ThreadHelpBase , 115 public cppu::OWeakObject 116 { 117 //------------------------------------------------------------------------------------------------------------- 118 // public methods 119 //------------------------------------------------------------------------------------------------------------- 120 121 public: 122 123 //--------------------------------------------------------------------------------------------------------- 124 // constructor / destructor 125 //--------------------------------------------------------------------------------------------------------- 126 127 /*-****************************************************************************************************//** 128 @short standard ctor 129 @descr These initialize a new instance of ths class with needed informations for work. 130 131 @seealso using at owner 132 133 @param "xFactory" , css::uno::Reference to servicemanager for creation of new services 134 @param "xOwner" , css::uno::Reference to our owner, the Desktop!!! 135 @return - 136 137 @onerror - 138 *//*-*****************************************************************************************************/ 139 140 MenuDispatcher( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory , 141 const css::uno::Reference< css::frame::XFrame >& xOwner ); 142 143 //--------------------------------------------------------------------------------------------------------- 144 // XInterface 145 //--------------------------------------------------------------------------------------------------------- 146 147 FWK_DECLARE_XINTERFACE 148 FWK_DECLARE_XTYPEPROVIDER 149 150 //--------------------------------------------------------------------------------------------------------- 151 // XDispatch 152 //--------------------------------------------------------------------------------------------------------- 153 154 /*-****************************************************************************************************//** 155 @short dispatch URL with arguments 156 @descr Every dispatch create a new task. If load of URL failed task will deleted automaticly! 157 158 @seealso - 159 160 @param "aURL" , URL to dispatch. 161 @param "seqArguments" , list of optional arguments. 162 @return - 163 164 @onerror - 165 *//*-*****************************************************************************************************/ 166 167 virtual void SAL_CALL dispatch( const css::util::URL& aURL , 168 const css::uno::Sequence< css::beans::PropertyValue >& seqProperties ) throw( css::uno::RuntimeException ); 169 170 /*-****************************************************************************************************//** 171 @short add listener for state events 172 @descr You can add a listener to get information about status of dispatch: OK or Failed. 173 174 @seealso method loadFinished() 175 @seealso method loadCancelled() 176 177 @param "xControl" , css::uno::Reference to a valid listener for state events. 178 @param "aURL" , URL about listener will be informed, if something occured. 179 @return - 180 181 @onerror - 182 *//*-*****************************************************************************************************/ 183 184 virtual void SAL_CALL addStatusListener( const css::uno::Reference< css::frame::XStatusListener >& xControl, 185 const css::util::URL& aURL ) throw( css::uno::RuntimeException ); 186 187 /*-****************************************************************************************************//** 188 @short remove listener for state events 189 @descr You can remove a listener if information of dispatch isn't important for you any longer. 190 191 @seealso method loadFinished() 192 @seealso method loadCancelled() 193 194 @param "xControl" , css::uno::Reference to a valid listener. 195 @param "aURL" , URL on which listener has registered. 196 @return - 197 198 @onerror - 199 *//*-*****************************************************************************************************/ 200 201 virtual void SAL_CALL removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >& xControl, 202 const css::util::URL& aURL ) throw( css::uno::RuntimeException ); 203 204 205 //--------------------------------------------------------------------------------------------------------- 206 // XFrameActionListener 207 //--------------------------------------------------------------------------------------------------------- 208 209 virtual void SAL_CALL frameAction( const css::frame::FrameActionEvent& aEvent ) throw ( css::uno::RuntimeException ); 210 211 //--------------------------------------------------------------------------------------------------------- 212 // XEventListener 213 //--------------------------------------------------------------------------------------------------------- 214 215 /*-****************************************************************************************************//** 216 @short dispose current instance 217 @descr If service helper isn't required any longer call this method to release all used ressources. 218 219 @seealso - 220 221 @param "aEvent", information about source of this event. 222 @return - 223 224 @onerror - 225 *//*-*****************************************************************************************************/ 226 227 void SAL_CALL disposing( const EVENTOBJECT& aEvent ) throw( css::uno::RuntimeException ); 228 229 //------------------------------------------------------------------------------------------------------------- 230 // protected methods 231 //------------------------------------------------------------------------------------------------------------- 232 233 protected: 234 235 /*-****************************************************************************************************//** 236 @short standard destructor 237 @descr This method destruct an instance of this class and clear some member. 238 This method is protected, because its not allowed to use an instance of this class as a member! 239 You MUST use a pointer. 240 241 @seealso - 242 243 @param - 244 @return - 245 246 @onerror - 247 *//*-*****************************************************************************************************/ 248 249 virtual ~MenuDispatcher(); 250 251 //------------------------------------------------------------------------------------------------------------- 252 // private methods 253 //------------------------------------------------------------------------------------------------------------- 254 255 private: 256 257 DECL_LINK( Close_Impl, void* ); 258 259 /*-****************************************************************************************************//** 260 @short - 261 @descr - 262 263 @seealso - 264 265 @param - 266 @return - 267 268 @onerror - 269 *//*-*****************************************************************************************************/ 270 271 sal_Bool impl_setMenuBar( MenuBar* pMenuBar, sal_Bool bMenuFromResource = sal_False ); 272 273 /*-****************************************************************************************************//** 274 @short - 275 @descr - 276 277 @seealso - 278 279 @param - 280 @return - 281 282 @onerror - 283 *//*-*****************************************************************************************************/ 284 285 void impl_setAccelerators( Menu* pMenu, const Accelerator& aAccel ); 286 287 //------------------------------------------------------------------------------------------------------------- 288 // debug methods 289 // (should be private everyway!) 290 //------------------------------------------------------------------------------------------------------------- 291 292 /*-****************************************************************************************************//** 293 @short debug-method to check incoming parameter of some other mehods of this class 294 @descr The following methods are used to check parameters for other methods 295 of this class. The return value is used directly for an ASSERT(...). 296 297 @seealso ASSERTs in implementation! 298 299 @param css::uno::References to checking variables 300 @return sal_False on invalid parameter<BR> 301 sal_True otherway 302 303 @onerror - 304 *//*-*****************************************************************************************************/ 305 306 #ifdef ENABLE_ASSERTIONS 307 308 private: 309 310 static sal_Bool impldbg_checkParameter_MenuDispatcher ( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory , 311 const css::uno::Reference< css::frame::XFrame >& xOwner ); 312 static sal_Bool impldbg_checkParameter_addStatusListener ( const css::uno::Reference< css::frame::XStatusListener >& xControl , 313 const css::util::URL& aURL ); 314 static sal_Bool impldbg_checkParameter_removeStatusListener ( const css::uno::Reference< css::frame::XStatusListener >& xControl , 315 const css::util::URL& aURL ); 316 #endif // #ifdef ENABLE_ASSERTIONS 317 318 //------------------------------------------------------------------------------------------------------------- 319 // variables 320 // (should be private everyway!) 321 //------------------------------------------------------------------------------------------------------------- 322 323 private: 324 325 css::uno::WeakReference< css::frame::XFrame > m_xOwnerWeak ; /// css::uno::WeakReference to owner (Don't use a hard css::uno::Reference. Owner can't delete us then!) 326 css::uno::Reference< css::lang::XMultiServiceFactory > m_xFactory ; /// factory shared with our owner to create new services! 327 IMPL_ListenerHashContainer m_aListenerContainer; /// hash table for listener at specified URLs 328 sal_Bool m_bAlreadyDisposed ; /// Protection against multiple disposing calls. 329 sal_Bool m_bActivateListener ; /// dispatcher is listener for frame activation 330 MenuManager* m_pMenuManager ; /// menu manager controlling menu dispatches 331 332 }; // class MenuDispatcher 333 334 } // namespace framework 335 336 #endif // #ifndef __FRAMEWORK_DISPATCH_MENUDISPATCHER_HXX_ 337