diff options
author | Maxim Monastirsky <momonasmon@gmail.com> | 2016-03-10 15:45:09 +0200 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2016-03-10 15:23:31 +0000 |
commit | 21b92f386c32defa498284df752d909c9555c4c1 (patch) | |
tree | ccd58c0489e199374249df7c93886da20f444535 /framework | |
parent | 70c8d27892f811121a891ebd4742c97d19632f93 (diff) |
MenuDispatcher::m_pMenuManager is always nullptr
... as shown by 7da15debe39b50255cc08b3fef7ae38185a9174f.
Which means that MenuManager is unused, and MenuDispatcher
does nothing useful.
Change-Id: Ic85619531054a573d971d38b52609e1cbcaf780c
Reviewed-on: https://gerrit.libreoffice.org/23117
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'framework')
-rw-r--r-- | framework/Library_fwk.mk | 2 | ||||
-rw-r--r-- | framework/inc/classes/menumanager.hxx | 129 | ||||
-rw-r--r-- | framework/inc/dispatch/dispatchprovider.hxx | 3 | ||||
-rw-r--r-- | framework/inc/dispatch/menudispatcher.hxx | 189 | ||||
-rw-r--r-- | framework/inc/targets.h | 1 | ||||
-rw-r--r-- | framework/inc/uielement/menubarmanager.hxx | 2 | ||||
-rw-r--r-- | framework/source/classes/menumanager.cxx | 976 | ||||
-rw-r--r-- | framework/source/dispatch/dispatchprovider.cxx | 35 | ||||
-rw-r--r-- | framework/source/dispatch/menudispatcher.cxx | 252 | ||||
-rw-r--r-- | framework/source/inc/loadenv/targethelper.hxx | 1 | ||||
-rw-r--r-- | framework/source/loadenv/targethelper.cxx | 3 | ||||
-rw-r--r-- | framework/source/services/desktop.cxx | 1 | ||||
-rw-r--r-- | framework/source/services/frame.cxx | 7 | ||||
-rw-r--r-- | framework/source/uielement/menubarmanager.cxx | 125 |
14 files changed, 132 insertions, 1594 deletions
diff --git a/framework/Library_fwk.mk b/framework/Library_fwk.mk index 0c78fc460a2d..f4a2aed5fe36 100644 --- a/framework/Library_fwk.mk +++ b/framework/Library_fwk.mk @@ -68,14 +68,12 @@ $(eval $(call gb_Library_add_exception_objects,fwk,\ framework/source/accelerators/storageholder \ framework/source/classes/framecontainer \ framework/source/classes/fwktabwindow \ - framework/source/classes/menumanager \ framework/source/classes/taskcreator \ framework/source/dispatch/closedispatcher \ framework/source/dispatch/dispatchinformationprovider \ framework/source/dispatch/dispatchprovider \ framework/source/dispatch/interceptionhelper \ framework/source/dispatch/loaddispatcher \ - framework/source/dispatch/menudispatcher \ framework/source/dispatch/startmoduledispatcher \ framework/source/dispatch/windowcommanddispatch \ framework/source/helper/dockingareadefaultacceptor \ diff --git a/framework/inc/classes/menumanager.hxx b/framework/inc/classes/menumanager.hxx deleted file mode 100644 index 9bd2a8ae92b7..000000000000 --- a/framework/inc/classes/menumanager.hxx +++ /dev/null @@ -1,129 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_FRAMEWORK_INC_CLASSES_MENUMANAGER_HXX -#define INCLUDED_FRAMEWORK_INC_CLASSES_MENUMANAGER_HXX - -#include <vector> - -#include <com/sun/star/frame/XFrame.hpp> -#include <com/sun/star/frame/XDispatch.hpp> -#include <com/sun/star/frame/FeatureStateEvent.hpp> -#include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/util/XURLTransformer.hpp> - -#include <rtl/ustring.hxx> -#include <vcl/menu.hxx> -#include <vcl/accel.hxx> -#include <cppuhelper/implbase.hxx> - -namespace com { namespace sun { namespace star { namespace uno { - class XComponentContext; -} } } } - -namespace framework -{ - -class BmkMenu; -class AddonMenu; -class AddonPopupMenu; -class MenuManager : public ::cppu::WeakImplHelper< css::frame::XStatusListener > -{ - public: - MenuManager( - const css::uno::Reference< css::uno::XComponentContext >& rxContext, - css::uno::Reference< css::frame::XFrame >& rFrame, - Menu* pMenu, - bool bDelete, - bool bDeleteChildren ); - - virtual ~MenuManager(); - - // XStatusListener - virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& Event ) throw ( css::uno::RuntimeException, std::exception ) override; - - // XEventListener - virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) throw ( css::uno::RuntimeException, std::exception ) override; - - DECL_LINK_TYPED( Select, Menu *, bool ); - - Menu* GetMenu() const { return m_pVCLMenu; } - - void RemoveListener(); - - static void UpdateSpecialWindowMenu( Menu* pMenu ,const css::uno::Reference< css::uno::XComponentContext >& xContext); - static void FillMenuImages( - css::uno::Reference< css::frame::XFrame >& xFrame, - Menu* _pMenu, - bool bShowMenuImages - ); - - protected: - DECL_LINK_TYPED(Highlight, Menu *, bool); - DECL_LINK_TYPED( Activate, Menu *, bool ); - DECL_LINK_TYPED( Deactivate, Menu *, bool ); - - private: - void UpdateSpecialFileMenu( Menu* pMenu ); - void ClearMenuDispatch(const css::lang::EventObject& Source = css::lang::EventObject(),bool _bRemoveOnly = true); - void SetHdl(); - void AddMenu(PopupMenu* _pPopupMenu,const OUString& _sItemCommand,sal_uInt16 _nItemId,bool _bDelete,bool _bDeleteChildren); - sal_uInt16 FillItemCommand(OUString& _rItemCommand, Menu* _pMenu,sal_uInt16 _nIndex) const; - - struct MenuItemHandler - { - MenuItemHandler( sal_uInt16 aItemId, MenuManager* pManager, css::uno::Reference< css::frame::XDispatch >& rDispatch ) : - nItemId( aItemId ), pSubMenuManager( pManager ), xMenuItemDispatch( rDispatch ) {} - - sal_uInt16 nItemId; - OUString aTargetFrame; - OUString aMenuItemURL; - OUString aFilter; - OUString aPassword; - OUString aTitle; - MenuManager* pSubMenuManager; - css::uno::Reference< css::frame::XDispatch > xMenuItemDispatch; - }; - - void CreatePicklistArguments( - css::uno::Sequence< css::beans::PropertyValue >& aArgsList, - const MenuItemHandler* ); - - MenuItemHandler* GetMenuItemHandler( sal_uInt16 nItemId ); - - bool m_bInitialized; - bool m_bDeleteMenu; - bool m_bDeleteChildren; - bool m_bActive; - bool m_bIsBookmarkMenu; - bool m_bShowMenuImages; - OUString m_aMenuItemCommand; - Menu* m_pVCLMenu; - css::uno::Reference< css::frame::XFrame > m_xFrame; - ::std::vector< MenuItemHandler* > m_aMenuItemHandlerVector; - - css::uno::Reference< css::uno::XComponentContext > m_xContext; - css::uno::Reference< css::util::XURLTransformer > m_xURLTransformer; -}; - -} // namespace - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/framework/inc/dispatch/dispatchprovider.hxx b/framework/inc/dispatch/dispatchprovider.hxx index d5a20d2a5c93..bf44c6c66452 100644 --- a/framework/inc/dispatch/dispatchprovider.hxx +++ b/framework/inc/dispatch/dispatchprovider.hxx @@ -48,7 +48,6 @@ namespace framework{ enum EDispatchHelper { E_DEFAULTDISPATCHER , - E_MENUDISPATCHER , E_CREATEDISPATCHER , E_BLANKDISPATCHER , E_SELFDISPATCHER , @@ -83,8 +82,6 @@ class DispatchProvider : private TransactionBase , css::uno::Reference< css::uno::XComponentContext > m_xContext; /// weakreference to owner frame (Don't use a hard reference. Owner can't delete us then!) css::uno::WeakReference< css::frame::XFrame > m_xFrame; - /// different dispatcher to handle special dispatch calls, protocols or URLs (they will be created on demand.) - css::uno::Reference< css::frame::XDispatch > m_xMenuDispatcher; /// cache of some other dispatch provider which are registered inside configuration to handle special URL protocols HandlerCache m_aProtocolHandlerCache; diff --git a/framework/inc/dispatch/menudispatcher.hxx b/framework/inc/dispatch/menudispatcher.hxx deleted file mode 100644 index eab15e89618e..000000000000 --- a/framework/inc/dispatch/menudispatcher.hxx +++ /dev/null @@ -1,189 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_FRAMEWORK_INC_DISPATCH_MENUDISPATCHER_HXX -#define INCLUDED_FRAMEWORK_INC_DISPATCH_MENUDISPATCHER_HXX - -#include <classes/taskcreator.hxx> -#include <macros/xinterface.hxx> -#include <macros/xtypeprovider.hxx> -#include <classes/menumanager.hxx> -#include <general.h> -#include <stdtypes.h> - -#include <com/sun/star/lang/XTypeProvider.hpp> -#include <com/sun/star/frame/XDispatch.hpp> -#include <com/sun/star/util/URL.hpp> -#include <com/sun/star/frame/DispatchDescriptor.hpp> -#include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/frame/XStatusListener.hpp> -#include <com/sun/star/frame/XFrameLoader.hpp> -#include <com/sun/star/frame/XLoadEventListener.hpp> -#include <com/sun/star/frame/XDesktop.hpp> -#include <com/sun/star/frame/FeatureStateEvent.hpp> -#include <com/sun/star/frame/XFrame.hpp> -#include <com/sun/star/frame/XFrameActionListener.hpp> - -#include <cppuhelper/implbase.hxx> -#include <cppuhelper/weakref.hxx> -#include <cppuhelper/interfacecontainer.h> - -namespace framework{ - -typedef cppu::OMultiTypeInterfaceContainerHelperVar<OUString> - IMPL_ListenerHashContainer; - -/*-************************************************************************************************************ - @short helper for desktop only(!) to create new tasks on demand for dispatches - @descr Use this class as member only! Never use it as baseclass. - XInterface will be ambigous and we hold a weakcss::uno::Reference to our OWNER - not to our SUPERCLASS! - - @implements XInterface - XDispatch - XLoadEventListener - XFrameActionListener - XEventListener - @base OWeakObject - - @devstatus ready to use -*//*-*************************************************************************************************************/ -class MenuDispatcher : public ::cppu::WeakImplHelper< - css::frame::XDispatch , - css::frame::XFrameActionListener > -{ - - // public methods - - public: - - // constructor / destructor - - /*-**************************************************************************************************** - @short standard ctor - @descr This initializes a new instance of the class with needed information for work. - - @seealso using at owner - - @param "rxContext" , css::uno::Reference to servicemanager for creation of new services - @param "xOwner" , css::uno::Reference to our owner, the Desktop!!! - *//*-*****************************************************************************************************/ - - MenuDispatcher( const css::uno::Reference< css::uno::XComponentContext >& rxContext , - const css::uno::Reference< css::frame::XFrame >& xOwner ); - - // XDispatch - - /*-**************************************************************************************************** - @short dispatch URL with arguments - @descr Every dispatch create a new task. If load of URL failed task will deleted automatically! - @param "aURL" , URL to dispatch. - @param "seqArguments" , list of optional arguments. - *//*-*****************************************************************************************************/ - - virtual void SAL_CALL dispatch( const css::util::URL& aURL , - const css::uno::Sequence< css::beans::PropertyValue >& seqProperties ) throw( css::uno::RuntimeException, std::exception ) override; - - /*-**************************************************************************************************** - @short add listener for state events - @descr You can add a listener to get information about status of dispatch: OK or Failed. - - @seealso method loadFinished() - @seealso method loadCancelled() - - @param "xControl" , css::uno::Reference to a valid listener for state events. - @param "aURL" , URL about listener will be informed, if something occurred. - *//*-*****************************************************************************************************/ - - virtual void SAL_CALL addStatusListener( const css::uno::Reference< css::frame::XStatusListener >& xControl, - const css::util::URL& aURL ) throw( css::uno::RuntimeException, std::exception ) override; - - /*-**************************************************************************************************** - @short remove listener for state events - @descr You can remove a listener if information of dispatch isn't important for you any longer. - - @seealso method loadFinished() - @seealso method loadCancelled() - - @param "xControl" , css::uno::Reference to a valid listener. - @param "aURL" , URL on which listener has registered. - *//*-*****************************************************************************************************/ - - virtual void SAL_CALL removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >& xControl, - const css::util::URL& aURL ) throw( css::uno::RuntimeException, std::exception ) override; - - // XFrameActionListener - - virtual void SAL_CALL frameAction( const css::frame::FrameActionEvent& aEvent ) throw ( css::uno::RuntimeException, std::exception ) override; - - // XEventListener - - /*-**************************************************************************************************** - @short dispose current instance - @descr If service helper isn't required any longer call this method to release all used resources. - @param "aEvent", information about source of this event. - *//*-*****************************************************************************************************/ - - void SAL_CALL disposing( const css::lang::EventObject& aEvent ) throw( css::uno::RuntimeException, std::exception ) override; - - // protected methods - - protected: - - /*-**************************************************************************************************** - @short standard destructor - @descr This method destruct an instance of this class and clear some member. - This method is protected, because its not allowed to use an instance of this class as a member! - You MUST use a pointer. - *//*-*****************************************************************************************************/ - - virtual ~MenuDispatcher(); - - - private: - - /*-**************************************************************************************************** - *//*-*****************************************************************************************************/ - - bool impl_clearMenuBar(); - - /*-**************************************************************************************************** - *//*-*****************************************************************************************************/ - - void impl_setAccelerators( Menu* pMenu, const Accelerator& aAccel ); - - // variables - // (should be private everyway!) - - private: - - 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!) - css::uno::Reference< css::uno::XComponentContext > m_xContext; /// factory shared with our owner to create new services! - osl::Mutex m_mutex; - IMPL_ListenerHashContainer m_aListenerContainer; /// hash table for listener at specified URLs - bool m_bAlreadyDisposed; /// Protection against multiple disposing calls. - bool m_bActivateListener; /// dispatcher is listener for frame activation - MenuManager* m_pMenuManager; /// menu manager controlling menu dispatches - -}; // class MenuDispatcher - -} // namespace framework - -#endif // INCLUDED_FRAMEWORK_INC_DISPATCH_MENUDISPATCHER_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/framework/inc/targets.h b/framework/inc/targets.h index 09155f397ef8..a15db1e84851 100644 --- a/framework/inc/targets.h +++ b/framework/inc/targets.h @@ -30,7 +30,6 @@ namespace framework{ #define SPECIALTARGET_BLANK "_blank" // Create a new task. #define SPECIALTARGET_DEFAULT "_default" // Create a new task or recycle an existing one #define SPECIALTARGET_BEAMER "_beamer" // special frame in hierarchy -#define SPECIALTARGET_MENUBAR "_menubar" // special target for menubars #define SPECIALTARGET_HELPTASK "OFFICE_HELP_TASK" // special name for our help task } // namespace framework diff --git a/framework/inc/uielement/menubarmanager.hxx b/framework/inc/uielement/menubarmanager.hxx index 0374b3f26f2a..2a1a019fb8e3 100644 --- a/framework/inc/uielement/menubarmanager.hxx +++ b/framework/inc/uielement/menubarmanager.hxx @@ -188,6 +188,8 @@ class MenuBarManager : public css::frame::XStatusListener , void RetrieveShortcuts( std::vector< MenuItemHandler* >& aMenuShortCuts ); void CheckAndAddMenuExtension( Menu* pMenu ); + static void UpdateSpecialWindowMenu( Menu* pMenu, const css::uno::Reference< css::uno::XComponentContext >& xContext ); + static void FillMenuImages( css::uno::Reference< css::frame::XFrame >& xFrame, Menu* _pMenu, bool bShowMenuImages ); static void impl_RetrieveShortcutsFromConfiguration( const css::uno::Reference< css::ui::XAcceleratorConfiguration >& rAccelCfg, const css::uno::Sequence< OUString >& rCommands, std::vector< MenuItemHandler* >& aMenuShortCuts ); diff --git a/framework/source/classes/menumanager.cxx b/framework/source/classes/menumanager.cxx deleted file mode 100644 index 3e76f14f4e9f..000000000000 --- a/framework/source/classes/menumanager.cxx +++ /dev/null @@ -1,976 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <classes/menumanager.hxx> -#include <framework/menuconfiguration.hxx> -#include <framework/bmkmenu.hxx> -#include <framework/addonmenu.hxx> -#include <framework/addonsoptions.hxx> -#include <classes/fwkresid.hxx> -#include <services.h> -#include "classes/resource.hrc" - -#include <com/sun/star/frame/XDispatchProvider.hpp> -#include <com/sun/star/frame/XDispatch.hpp> -#include <com/sun/star/util/URLTransformer.hpp> -#include <com/sun/star/util/XURLTransformer.hpp> -#include <com/sun/star/beans/XPropertySet.hpp> -#include <com/sun/star/frame/XFramesSupplier.hpp> -#include <com/sun/star/frame/Desktop.hpp> -#include <com/sun/star/container/XEnumeration.hpp> -#include <com/sun/star/util/XStringWidth.hpp> - -#include <comphelper/processfactory.hxx> - -#include <comphelper/extract.hxx> -#include <svtools/menuoptions.hxx> -#include <unotools/historyoptions.hxx> -#include <unotools/pathoptions.hxx> -#include <unotools/localfilehelper.hxx> - -#include <toolkit/helper/vclunohelper.hxx> -#include <tools/urlobj.hxx> - -#include <vcl/svapp.hxx> -#include <vcl/window.hxx> -#include <vcl/settings.hxx> -#include <vcl/commandinfoprovider.hxx> - -#include <osl/mutex.hxx> -#include <osl/file.hxx> -#include <cppuhelper/implbase.hxx> - -using namespace ::cppu; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::util; -using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::frame; -using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::container; - -class StringLength : public ::cppu::WeakImplHelper< XStringWidth > -{ - public: - StringLength() {} - virtual ~StringLength() {} - - // XStringWidth - sal_Int32 SAL_CALL queryStringWidth( const OUString& aString ) - throw (RuntimeException, std::exception) override - { - return aString.getLength(); - } -}; - -namespace framework -{ - -// special menu ids/command ids for dynamic popup menus -#define SID_SFX_START 5000 -#define SID_NEWDOCDIRECT (SID_SFX_START + 537) -#define SID_AUTOPILOTMENU (SID_SFX_START + 1381) -#define SID_ADDONLIST (SID_SFX_START + 1677) - -#define aSlotNewDocDirect "slot:5537" -#define aSlotAutoPilot "slot:6381" - -#define aSpecialFileMenu "file" -#define aSpecialWindowMenu "window" -#define aSlotSpecialFileMenu "slot:5510" -#define aSlotSpecialWindowMenu "slot:5610" -#define aSlotSpecialToolsMenu "slot:6677" - -// special uno commands for picklist and window list -#define aSpecialFileCommand "PickList" -#define aSpecialWindowCommand "WindowList" - -const char UNO_COMMAND[] = ".uno:"; - -MenuManager::MenuManager( - const Reference< XComponentContext >& rxContext, - Reference< XFrame >& rFrame, Menu* pMenu, bool bDelete, bool bDeleteChildren ) -: - m_xContext(rxContext) -{ - m_bActive = false; - m_bDeleteMenu = bDelete; - m_bDeleteChildren = bDeleteChildren; - m_pVCLMenu = pMenu; - m_xFrame = rFrame; - m_bInitialized = false; - m_bIsBookmarkMenu = false; - acquire(); - const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings(); - m_bShowMenuImages = rSettings.GetUseImagesInMenus(); - - sal_uInt16 nItemCount = pMenu->GetItemCount(); - m_aMenuItemHandlerVector.reserve(nItemCount); - OUString aItemCommand; - for ( sal_uInt16 i = 0; i < nItemCount; i++ ) - { - sal_uInt16 nItemId = FillItemCommand(aItemCommand,pMenu, i ); - bool bShowMenuImages( m_bShowMenuImages ); - - // overwrite the show icons on menu option? - if (!bShowMenuImages) - { - MenuItemBits nBits = pMenu->GetItemBits( nItemId ); - bShowMenuImages = ( ( nBits & MenuItemBits::ICON ) == MenuItemBits::ICON ); - } - - PopupMenu* pPopupMenu = pMenu->GetPopupMenu( nItemId ); - if ( pPopupMenu ) - { - AddMenu(pPopupMenu,aItemCommand,nItemId,bDeleteChildren,bDeleteChildren); - if (! ( aItemCommand.startsWith( ADDONSPOPUPMENU_URL_PREFIX_STR ) ) ) - { - - // Create addon popup menu if there exist elements and this is the tools popup menu - if ( ( nItemId == SID_ADDONLIST || aItemCommand == aSlotSpecialToolsMenu ) - && AddonMenuManager::HasAddonMenuElements() ) - { - AddonMenu* pSubMenu = AddonMenuManager::CreateAddonMenu(rFrame, rxContext); - if ( pSubMenu && ( pSubMenu->GetItemCount() > 0 )) - { - sal_uInt16 nCount = 0; - if ( pPopupMenu->GetItemType( nCount-1 ) != MenuItemType::SEPARATOR ) - pPopupMenu->InsertSeparator(); - - // Use resource to load popup menu title - OUString aAddonsStrRes(FWK_RESSTR(STR_MENU_ADDONS)); - pPopupMenu->InsertItem( ITEMID_ADDONLIST, aAddonsStrRes ); - pPopupMenu->SetPopupMenu( ITEMID_ADDONLIST, pSubMenu ); - - // Set item command for popup menu to enable it for GetImageFromURL - aItemCommand = "slot:" + OUString::number( ITEMID_ADDONLIST ); - pPopupMenu->SetItemCommand( ITEMID_ADDONLIST, aItemCommand ); - - AddMenu(pSubMenu,OUString(),nItemId,true,false); - // Set image for the addon popup menu item - if ( bShowMenuImages && !pPopupMenu->GetItemImage( ITEMID_ADDONLIST )) - { - Image aImage = vcl::CommandInfoProvider::Instance().GetImageForCommand(aItemCommand, false, rFrame ); - if ( !!aImage ) - pPopupMenu->SetItemImage( ITEMID_ADDONLIST, aImage ); - } - } - else - delete pSubMenu; - } - } - } - else - { - bool isNewDoc = nItemId == SID_NEWDOCDIRECT || aItemCommand == aSlotNewDocDirect; - bool isAutoPilot = nItemId == SID_AUTOPILOTMENU || aItemCommand == aSlotAutoPilot; - if(isNewDoc || isAutoPilot) - { - Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY ); - URL aTargetURL; - aTargetURL.Complete = OUString::createFromAscii(isNewDoc ? aSlotNewDocDirect : aSlotAutoPilot); - m_xURLTransformer->parseStrict( aTargetURL ); - Reference< XDispatch > xMenuItemDispatch = xDispatchProvider->queryDispatch( - aTargetURL, OUString(), 0 ); - if(xMenuItemDispatch == nullptr) - { - m_pVCLMenu->EnableItem( nItemId, false ); - } - else - { - MenuConfiguration aMenuCfg( m_xContext ); - BmkMenu* pSubMenu = static_cast<BmkMenu*>(aMenuCfg.CreateBookmarkMenu( rFrame, - OUString::createFromAscii(isNewDoc ? BOOKMARK_NEWMENU : BOOKMARK_WIZARDMENU))); - pMenu->SetPopupMenu( nItemId, pSubMenu ); - AddMenu(pSubMenu,OUString(),nItemId,true,false); - if ( bShowMenuImages && !pMenu->GetItemImage( nItemId )) - { - Image aImage = vcl::CommandInfoProvider::Instance().GetImageForCommand(aItemCommand, false, rFrame ); - if ( !!aImage ) - pMenu->SetItemImage( nItemId, aImage ); - } - } - } - else if ( pMenu->GetItemType( i ) != MenuItemType::SEPARATOR ) - { - if ( bShowMenuImages ) - { - if ( AddonMenuManager::IsAddonMenuId( nItemId )) - { - // Add-Ons uses a images from different places - Image aImage; - OUString aImageId; - - MenuAttributes* pMenuAttributes = - reinterpret_cast<MenuAttributes*>(pMenu->GetUserValue( nItemId )); - - if ( pMenuAttributes && !pMenuAttributes->aImageId.isEmpty() ) - { - // Retrieve image id from menu attributes - aImage = vcl::CommandInfoProvider::Instance().GetImageForCommand(aImageId, false, rFrame ); - } - - if ( !aImage ) - { - aImage = vcl::CommandInfoProvider::Instance().GetImageForCommand(aItemCommand, false, rFrame ); - if ( !aImage ) - aImage = AddonsOptions().GetImageFromURL( aItemCommand, false ); - } - - if ( !!aImage ) - pMenu->SetItemImage( nItemId, aImage ); - } - else if ( !pMenu->GetItemImage( nItemId )) - { - Image aImage = vcl::CommandInfoProvider::Instance().GetImageForCommand(aItemCommand, false, rFrame ); - if ( !!aImage ) - pMenu->SetItemImage( nItemId, aImage ); - } - } - - Reference< XDispatch > aXDispatchRef; - m_aMenuItemHandlerVector.push_back( new MenuItemHandler( nItemId, nullptr, aXDispatchRef )); - - } - } - } - - // retrieve label information for all menu items without item text - - SetHdl(); -} - -void MenuManager::SetHdl() -{ - m_pVCLMenu->SetHighlightHdl( LINK( this, MenuManager, Highlight )); - m_pVCLMenu->SetActivateHdl( LINK( this, MenuManager, Activate )); - m_pVCLMenu->SetDeactivateHdl( LINK( this, MenuManager, Deactivate )); - m_pVCLMenu->SetSelectHdl( LINK( this, MenuManager, Select )); - - if ( m_xContext.is() ) - m_xURLTransformer.set( URLTransformer::create( m_xContext ) ); -} - -MenuManager::~MenuManager() -{ - std::vector< MenuItemHandler* >::iterator p; - for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p ) - { - MenuItemHandler* pItemHandler = *p; - pItemHandler->xMenuItemDispatch.clear(); - if ( pItemHandler->pSubMenuManager ) - (static_cast< XInterface* >(static_cast<OWeakObject*>(pItemHandler->pSubMenuManager)))->release(); - delete pItemHandler; - } - - if ( m_bDeleteMenu ) - delete m_pVCLMenu; -} - -MenuManager::MenuItemHandler* MenuManager::GetMenuItemHandler( sal_uInt16 nItemId ) -{ - SolarMutexGuard g; - - std::vector< MenuItemHandler* >::iterator p; - for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p ) - { - MenuItemHandler* pItemHandler = *p; - if ( pItemHandler->nItemId == nItemId ) - return pItemHandler; - } - - return nullptr; -} - -void SAL_CALL MenuManager::statusChanged( const FeatureStateEvent& Event ) -throw ( RuntimeException, std::exception ) -{ - OUString aFeatureURL = Event.FeatureURL.Complete; - MenuItemHandler* pStatusChangedMenu = nullptr; - - { - SolarMutexGuard g; - - std::vector< MenuItemHandler* >::iterator p; - for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p ) - { - MenuItemHandler* pMenuItemHandler = *p; - if ( pMenuItemHandler->aMenuItemURL == aFeatureURL ) - { - pStatusChangedMenu = pMenuItemHandler; - break; - } - } - } - - if ( pStatusChangedMenu ) - { - SolarMutexGuard aSolarGuard; - { - bool bSetCheckmark = false; - bool bCheckmark = false; - bool bMenuItemEnabled = m_pVCLMenu->IsItemEnabled( pStatusChangedMenu->nItemId ); - - if ( bool(Event.IsEnabled) != bMenuItemEnabled ) - m_pVCLMenu->EnableItem( pStatusChangedMenu->nItemId, Event.IsEnabled ); - - if ( Event.State >>= bCheckmark ) - bSetCheckmark = true; - - if ( bSetCheckmark ) - m_pVCLMenu->CheckItem( pStatusChangedMenu->nItemId, bCheckmark ); - } - - if ( Event.Requery ) - { - URL aTargetURL; - aTargetURL.Complete = pStatusChangedMenu->aMenuItemURL; - - m_xURLTransformer->parseStrict( aTargetURL ); - - Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY ); - Reference< XDispatch > xMenuItemDispatch = xDispatchProvider->queryDispatch( - aTargetURL, OUString(), 0 ); - - if ( xMenuItemDispatch.is() ) - { - pStatusChangedMenu->xMenuItemDispatch = xMenuItemDispatch; - pStatusChangedMenu->aMenuItemURL = aTargetURL.Complete; - xMenuItemDispatch->addStatusListener( (static_cast< XStatusListener* >(this)), aTargetURL ); - } - } - } -} - -void MenuManager::RemoveListener() -{ - SolarMutexGuard g; - ClearMenuDispatch(); -} - -void MenuManager::ClearMenuDispatch(const EventObject& Source,bool _bRemoveOnly) -{ - // disposing called from parent dispatcher - // remove all listener to prepare shutdown - - std::vector< MenuItemHandler* >::iterator p; - for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p ) - { - MenuItemHandler* pItemHandler = *p; - if ( pItemHandler->xMenuItemDispatch.is() ) - { - URL aTargetURL; - aTargetURL.Complete = pItemHandler->aMenuItemURL; - m_xURLTransformer->parseStrict( aTargetURL ); - - pItemHandler->xMenuItemDispatch->removeStatusListener( - (static_cast< XStatusListener* >(this)), aTargetURL ); - } - - pItemHandler->xMenuItemDispatch.clear(); - if ( pItemHandler->pSubMenuManager ) - { - if ( _bRemoveOnly ) - pItemHandler->pSubMenuManager->RemoveListener(); - else - pItemHandler->pSubMenuManager->disposing( Source ); - } - } -} - -void SAL_CALL MenuManager::disposing( const EventObject& Source ) throw ( RuntimeException, std::exception ) -{ - if ( Source.Source == m_xFrame ) - { - SolarMutexGuard g; - ClearMenuDispatch(Source,false); - } - else - { - // disposing called from menu item dispatcher, remove listener - MenuItemHandler* pMenuItemDisposing = nullptr; - - { - SolarMutexGuard g; - - std::vector< MenuItemHandler* >::iterator p; - for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p ) - { - MenuItemHandler* pMenuItemHandler = *p; - if ( pMenuItemHandler->xMenuItemDispatch == Source.Source ) - { - pMenuItemDisposing = pMenuItemHandler; - break; - } - } - - if ( pMenuItemDisposing ) - { - URL aTargetURL; - aTargetURL.Complete = pMenuItemDisposing->aMenuItemURL; - - m_xURLTransformer->parseStrict( aTargetURL ); - - pMenuItemDisposing->xMenuItemDispatch->removeStatusListener((static_cast< XStatusListener* >(this)), aTargetURL ); - pMenuItemDisposing->xMenuItemDispatch.clear(); - } - } - } -} - -void MenuManager::UpdateSpecialFileMenu( Menu* pMenu ) -{ - // update picklist - Sequence< Sequence< PropertyValue > > aHistoryList = SvtHistoryOptions().GetList( ePICKLIST ); - ::std::vector< MenuItemHandler* > aNewPickVector; - Reference< XStringWidth > xStringLength( new StringLength ); - - sal_uInt16 nPickItemId = START_ITEMID_PICKLIST; - int nPickListMenuItems = ( aHistoryList.getLength() > 99 ) ? 99 : aHistoryList.getLength(); - - aNewPickVector.reserve(nPickListMenuItems); - for ( int i = 0; i < nPickListMenuItems; i++ ) - { - Sequence< PropertyValue > aPickListEntry = aHistoryList[i]; - - Reference< XDispatch > aXDispatchRef; - MenuItemHandler* pNewMenuItemHandler = new MenuItemHandler( - nPickItemId++, - nullptr, - aXDispatchRef ); - - for ( int j = 0; j < aPickListEntry.getLength(); j++ ) - { - Any a = aPickListEntry[j].Value; - - if ( aPickListEntry[j].Name == HISTORY_PROPERTYNAME_URL ) - a >>= pNewMenuItemHandler->aMenuItemURL; - else if ( aPickListEntry[j].Name == HISTORY_PROPERTYNAME_FILTER ) - a >>= pNewMenuItemHandler->aFilter; - else if ( aPickListEntry[j].Name == HISTORY_PROPERTYNAME_TITLE ) - a >>= pNewMenuItemHandler->aTitle; - else if ( aPickListEntry[j].Name == HISTORY_PROPERTYNAME_PASSWORD ) - a >>= pNewMenuItemHandler->aPassword; - } - - aNewPickVector.push_back( pNewMenuItemHandler ); - } - - if ( !aNewPickVector.empty() ) - { - URL aTargetURL; - Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY ); - - Reference< XDispatch > xMenuItemDispatch; - - static const char s_sDefault[] = "_default"; - // query for dispatcher - std::vector< MenuItemHandler* >::iterator p; - for ( p = aNewPickVector.begin(); p != aNewPickVector.end(); ++p ) - { - MenuItemHandler* pMenuItemHandler = *p; - - aTargetURL.Complete = pMenuItemHandler->aMenuItemURL; - m_xURLTransformer->parseStrict( aTargetURL ); - - if ( !xMenuItemDispatch.is() ) - { - // attention: this code assume that "_blank" can only be consumed by desktop service - xMenuItemDispatch = xDispatchProvider->queryDispatch( aTargetURL, s_sDefault, 0 ); - } - - if ( xMenuItemDispatch.is() ) - { - pMenuItemHandler->xMenuItemDispatch = xMenuItemDispatch; - pMenuItemHandler->aMenuItemURL = aTargetURL.Complete; - } - } - - { - SolarMutexGuard g; - - int nItemCount = pMenu->GetItemCount(); - - if ( nItemCount > 0 ) - { - int nRemoveItemCount = 0; - - // remove all old picklist entries from menu - sal_uInt16 nPos = pMenu->GetItemPos( START_ITEMID_PICKLIST ); - for ( sal_uInt16 n = nPos; n < pMenu->GetItemCount(); ) - { - pMenu->RemoveItem( n ); - ++nRemoveItemCount; - } - - if ( pMenu->GetItemType( pMenu->GetItemCount()-1 ) == MenuItemType::SEPARATOR ) - pMenu->RemoveItem( pMenu->GetItemCount()-1 ); - - // remove all old picklist entries from menu handler - if ( nRemoveItemCount > 0 ) - { - for( size_t nIndex = m_aMenuItemHandlerVector.size() - nRemoveItemCount; - nIndex < m_aMenuItemHandlerVector.size(); ) - { - delete m_aMenuItemHandlerVector.at( nIndex ); - m_aMenuItemHandlerVector.erase( m_aMenuItemHandlerVector.begin() + nIndex ); - } - } - } - - // append new picklist menu entries - aNewPickVector.reserve(aNewPickVector.size()); - pMenu->InsertSeparator(); - const sal_uInt32 nCount = aNewPickVector.size(); - for ( sal_uInt32 i = 0; i < nCount; i++ ) - { - OUString aMenuShortCut; - if ( i <= 9 ) - { - if ( i == 9 ) - aMenuShortCut = "1~0: "; - else - { - char menuShortCut[5] = "~n: "; - menuShortCut[1] = (char)( '1' + i ); - aMenuShortCut = OUString::createFromAscii( menuShortCut ); - } - } - else - { - aMenuShortCut = OUString::number(( i + 1 )); - aMenuShortCut += ": "; - } - - // Abbreviate URL - OUString aURLString( aNewPickVector.at( i )->aMenuItemURL ); - OUString aTipHelpText; - OUString aMenuTitle; - INetURLObject aURL( aURLString ); - - if ( aURL.GetProtocol() == INetProtocol::File ) - { - // Do handle file URL differently => convert it to a system - // path and abbreviate it with a special function: - OUString aFileSystemPath( aURL.getFSysPath( INetURLObject::FSYS_DETECT ) ); - - OUString aSystemPath( aFileSystemPath ); - OUString aCompactedSystemPath; - - aTipHelpText = aSystemPath; - oslFileError nError = osl_abbreviateSystemPath( aSystemPath.pData, &aCompactedSystemPath.pData, 46, nullptr ); - if ( !nError ) - aMenuTitle = aCompactedSystemPath; - else - aMenuTitle = aSystemPath; - } - else - { - // Use INetURLObject to abbreviate all other URLs - OUString aShortURL; - aShortURL = aURL.getAbbreviated( xStringLength, 46, INetURLObject::DECODE_UNAMBIGUOUS ); - aMenuTitle += aShortURL; - aTipHelpText = aURLString; - } - - OUString aTitle( aMenuShortCut + aMenuTitle ); - - MenuItemHandler* pMenuItemHandler = aNewPickVector.at( i ); - pMenu->InsertItem( pMenuItemHandler->nItemId, aTitle ); - pMenu->SetTipHelpText( pMenuItemHandler->nItemId, aTipHelpText ); - m_aMenuItemHandlerVector.push_back( pMenuItemHandler ); - } - } - } -} - -void MenuManager::UpdateSpecialWindowMenu( Menu* pMenu,const Reference< XComponentContext >& xContext ) -{ - // update window list - ::std::vector< OUString > aNewWindowListVector; - - Reference< XDesktop2 > xDesktop = css::frame::Desktop::create( xContext ); - - sal_uInt16 nActiveItemId = 0; - sal_uInt16 nItemId = START_ITEMID_WINDOWLIST; - - Reference< XFrame > xCurrentFrame = xDesktop->getCurrentFrame(); - Reference< XIndexAccess > xList( xDesktop->getFrames(), UNO_QUERY ); - sal_Int32 nFrameCount = xList->getCount(); - aNewWindowListVector.reserve(nFrameCount); - for (sal_Int32 i=0; i<nFrameCount; ++i ) - { - Reference< XFrame > xFrame; - xList->getByIndex(i) >>= xFrame; - - if (xFrame.is()) - { - if ( xFrame == xCurrentFrame ) - nActiveItemId = nItemId; - - vcl::Window* pWin = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() ); - if ( pWin && pWin->IsVisible() ) - { - aNewWindowListVector.push_back( pWin->GetText() ); - ++nItemId; - } - } - } - - { - SolarMutexGuard g; - - int nItemCount = pMenu->GetItemCount(); - - if ( nItemCount > 0 ) - { - // remove all old window list entries from menu - sal_uInt16 nPos = pMenu->GetItemPos( START_ITEMID_WINDOWLIST ); - for ( sal_uInt16 n = nPos; n < pMenu->GetItemCount(); ) - pMenu->RemoveItem( n ); - - if ( pMenu->GetItemType( pMenu->GetItemCount()-1 ) == MenuItemType::SEPARATOR ) - pMenu->RemoveItem( pMenu->GetItemCount()-1 ); - } - - if ( !aNewWindowListVector.empty() ) - { - // append new window list entries to menu - pMenu->InsertSeparator(); - nItemId = START_ITEMID_WINDOWLIST; - const sal_uInt32 nCount = aNewWindowListVector.size(); - for ( sal_uInt32 i = 0; i < nCount; i++ ) - { - pMenu->InsertItem( nItemId, aNewWindowListVector.at( i ), MenuItemBits::RADIOCHECK ); - if ( nItemId == nActiveItemId ) - pMenu->CheckItem( nItemId ); - ++nItemId; - } - } - } -} - -void MenuManager::CreatePicklistArguments( Sequence< PropertyValue >& aArgsList, const MenuItemHandler* pMenuItemHandler ) -{ - int NUM_OF_PICKLIST_ARGS = 3; - - Any a; - aArgsList.realloc( NUM_OF_PICKLIST_ARGS ); - - aArgsList[0].Name = "FileName"; - a <<= pMenuItemHandler->aMenuItemURL; - aArgsList[0].Value = a; - - aArgsList[1].Name = "Referer"; - a <<= OUString( "private:user" ); - aArgsList[1].Value = a; - - OUString aFilter( pMenuItemHandler->aFilter ); - - sal_Int32 nPos = aFilter.indexOf( '|' ); - if ( nPos >= 0 ) - { - OUString aFilterOptions; - - if ( nPos < ( aFilter.getLength() - 1 ) ) - aFilterOptions = aFilter.copy( nPos+1 ); - - aArgsList[2].Name = "FilterOptions"; - a <<= aFilterOptions; - aArgsList[2].Value = a; - - aFilter = aFilter.copy( 0, nPos-1 ); - aArgsList.realloc( ++NUM_OF_PICKLIST_ARGS ); - } - - aArgsList[NUM_OF_PICKLIST_ARGS-1].Name = "FilterName"; - a <<= aFilter; - aArgsList[NUM_OF_PICKLIST_ARGS-1].Value = a; -} - -// vcl handler - -IMPL_LINK_TYPED( MenuManager, Activate, Menu *, pMenu, bool ) -{ - if ( pMenu == m_pVCLMenu ) - { - // set/unset hiding disabled menu entries - bool bDontHide = SvtMenuOptions().IsEntryHidingEnabled(); - const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings(); - bool bShowMenuImages = rSettings.GetUseImagesInMenus(); - - MenuFlags nFlag = pMenu->GetMenuFlags(); - if ( bDontHide ) - nFlag &= ~MenuFlags::HideDisabledEntries; - else - nFlag |= MenuFlags::HideDisabledEntries; - pMenu->SetMenuFlags( nFlag ); - - if ( m_bActive ) - return false; - - m_bActive = true; - - OUString aCommand( m_aMenuItemCommand ); - if (m_aMenuItemCommand.matchIgnoreAsciiCase(UNO_COMMAND)) - { - // Remove protocol part from command so we can use an easier comparison method - aCommand = aCommand.copy(RTL_CONSTASCII_LENGTH(UNO_COMMAND)); - } - - if ( m_aMenuItemCommand == aSpecialFileMenu || m_aMenuItemCommand == aSlotSpecialFileMenu || aCommand == aSpecialFileCommand ) - UpdateSpecialFileMenu( pMenu ); - else if ( m_aMenuItemCommand == aSpecialWindowMenu || m_aMenuItemCommand == aSlotSpecialWindowMenu || aCommand == aSpecialWindowCommand ) - UpdateSpecialWindowMenu( pMenu, m_xContext ); - - // Check if some modes have changed so we have to update our menu images - if ( bShowMenuImages != m_bShowMenuImages ) - { - // The mode changed so we have to replace all images - m_bShowMenuImages = bShowMenuImages; - FillMenuImages( m_xFrame, pMenu, bShowMenuImages ); - } - - if ( m_bInitialized ) - return false; - else - { - URL aTargetURL; - - SolarMutexGuard g; - - Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY ); - if ( xDispatchProvider.is() ) - { - std::vector< MenuItemHandler* >::iterator p; - for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); ++p ) - { - MenuItemHandler* pMenuItemHandler = *p; - if ( pMenuItemHandler && - pMenuItemHandler->pSubMenuManager == nullptr && - !pMenuItemHandler->xMenuItemDispatch.is() ) - { - // There is no dispatch mechanism for the special window list menu items, - // because they are handled directly through XFrame->activate!!! - if ( pMenuItemHandler->nItemId < START_ITEMID_WINDOWLIST || - pMenuItemHandler->nItemId > END_ITEMID_WINDOWLIST ) - { - OUString aItemCommand = pMenu->GetItemCommand( pMenuItemHandler->nItemId ); - if ( aItemCommand.isEmpty() ) - { - aItemCommand = "slot:" + OUString::number( pMenuItemHandler->nItemId ); - pMenu->SetItemCommand( pMenuItemHandler->nItemId, aItemCommand ); - } - - aTargetURL.Complete = aItemCommand; - - m_xURLTransformer->parseStrict( aTargetURL ); - - Reference< XDispatch > xMenuItemDispatch; - if ( m_bIsBookmarkMenu ) - xMenuItemDispatch = xDispatchProvider->queryDispatch( aTargetURL, pMenuItemHandler->aTargetFrame, 0 ); - else - xMenuItemDispatch = xDispatchProvider->queryDispatch( aTargetURL, OUString(), 0 ); - - if ( xMenuItemDispatch.is() ) - { - pMenuItemHandler->xMenuItemDispatch = xMenuItemDispatch; - pMenuItemHandler->aMenuItemURL = aTargetURL.Complete; - xMenuItemDispatch->addStatusListener( (static_cast< XStatusListener* >(this)), aTargetURL ); - } - else - pMenu->EnableItem( pMenuItemHandler->nItemId, false ); - } - } - } - } - } - } - - return true; -} - -IMPL_LINK_TYPED( MenuManager, Deactivate, Menu *, pMenu, bool ) -{ - if ( pMenu == m_pVCLMenu ) - m_bActive = false; - - return true; -} - -IMPL_LINK_TYPED( MenuManager, Select, Menu *, pMenu, bool ) -{ - URL aTargetURL; - Sequence<PropertyValue> aArgs; - Reference< XDispatch > xDispatch; - - { - SolarMutexGuard g; - - sal_uInt16 nCurItemId = pMenu->GetCurItemId(); - if ( pMenu == m_pVCLMenu && - pMenu->GetItemType( nCurItemId ) != MenuItemType::SEPARATOR ) - { - if ( nCurItemId >= START_ITEMID_WINDOWLIST && - nCurItemId <= END_ITEMID_WINDOWLIST ) - { - // window list menu item selected - - Reference< XDesktop2 > xDesktop = css::frame::Desktop::create( m_xContext ); - - sal_uInt16 nTaskId = START_ITEMID_WINDOWLIST; - Reference< XIndexAccess > xList( xDesktop->getFrames(), UNO_QUERY ); - sal_Int32 nCount = xList->getCount(); - for ( sal_Int32 i=0; i<nCount; ++i ) - { - Reference< XFrame > xFrame; - xList->getByIndex(i) >>= xFrame; - - if ( xFrame.is() && nTaskId == nCurItemId ) - { - vcl::Window* pWin = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() ); - pWin->GrabFocus(); - pWin->ToTop( ToTopFlags::RestoreWhenMin ); - break; - } - - nTaskId++; - } - } - else - { - MenuItemHandler* pMenuItemHandler = GetMenuItemHandler( nCurItemId ); - if ( pMenuItemHandler && pMenuItemHandler->xMenuItemDispatch.is() ) - { - aTargetURL.Complete = pMenuItemHandler->aMenuItemURL; - m_xURLTransformer->parseStrict( aTargetURL ); - - if ( nCurItemId >= START_ITEMID_PICKLIST && - nCurItemId < START_ITEMID_WINDOWLIST ) - { - // picklist menu item selected - CreatePicklistArguments( aArgs, pMenuItemHandler ); - } - else if ( m_bIsBookmarkMenu ) - { - // bookmark menu item selected - aArgs.realloc( 1 ); - aArgs[0].Name = "Referer"; - aArgs[0].Value <<= OUString( "private:user" ); - } - - xDispatch = pMenuItemHandler->xMenuItemDispatch; - } - } - } - } - - if ( xDispatch.is() ) - xDispatch->dispatch( aTargetURL, aArgs ); - - return true; -} - -IMPL_LINK_NOARG_TYPED(MenuManager, Highlight, Menu *, bool) -{ - return false; -} - -void MenuManager::AddMenu(PopupMenu* _pPopupMenu,const OUString& _sItemCommand,sal_uInt16 _nItemId,bool _bDelete,bool _bDeleteChildren) -{ - MenuManager* pSubMenuManager = new MenuManager( m_xContext, m_xFrame, _pPopupMenu, _bDelete, _bDeleteChildren ); - - // store menu item command as we later have to know which menu is active (see Activate handler) - pSubMenuManager->m_aMenuItemCommand = _sItemCommand; - - Reference< XDispatch > aXDispatchRef; - MenuItemHandler* pMenuItemHandler = new MenuItemHandler( - _nItemId, - pSubMenuManager, - aXDispatchRef ); - m_aMenuItemHandlerVector.push_back( pMenuItemHandler ); -} - -sal_uInt16 MenuManager::FillItemCommand(OUString& _rItemCommand, Menu* _pMenu,sal_uInt16 _nIndex) const -{ - sal_uInt16 nItemId = _pMenu->GetItemId( _nIndex ); - - _rItemCommand = _pMenu->GetItemCommand( nItemId ); - if ( _rItemCommand.isEmpty() ) - { - _rItemCommand = "slot:" + OUString::number( nItemId ); - _pMenu->SetItemCommand( nItemId, _rItemCommand ); - } - return nItemId; -} -void MenuManager::FillMenuImages(Reference< XFrame >& _xFrame, Menu* _pMenu,bool bShowMenuImages) -{ - AddonsOptions aAddonOptions; - - for ( sal_uInt16 nPos = 0; nPos < _pMenu->GetItemCount(); nPos++ ) - { - sal_uInt16 nId = _pMenu->GetItemId( nPos ); - if ( _pMenu->GetItemType( nPos ) != MenuItemType::SEPARATOR ) - { - bool bTmpShowMenuImages( bShowMenuImages ); - // overwrite the show icons on menu option? - if (!bTmpShowMenuImages) - { - MenuItemBits nBits = _pMenu->GetItemBits( nId ); - bTmpShowMenuImages = ( ( nBits & MenuItemBits::ICON ) == MenuItemBits::ICON ); - } - - if ( bTmpShowMenuImages ) - { - bool bImageSet = false; - OUString aImageId; - - ::framework::MenuAttributes* pMenuAttributes = - reinterpret_cast< ::framework::MenuAttributes*>(_pMenu->GetUserValue( nId )); - - if ( pMenuAttributes ) - aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes - - if ( !aImageId.isEmpty() ) - { - Image aImage = vcl::CommandInfoProvider::Instance().GetImageForCommand(aImageId, false, _xFrame ); - if ( !!aImage ) - { - bImageSet = true; - _pMenu->SetItemImage( nId, aImage ); - } - } - - if ( !bImageSet ) - { - OUString aMenuItemCommand = _pMenu->GetItemCommand( nId ); - Image aImage = vcl::CommandInfoProvider::Instance().GetImageForCommand(aMenuItemCommand, false, _xFrame ); - if ( !aImage ) - aImage = aAddonOptions.GetImageFromURL( aMenuItemCommand, false ); - - _pMenu->SetItemImage( nId, aImage ); - } - } - else - _pMenu->SetItemImage( nId, Image() ); - } - } -} -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/framework/source/dispatch/dispatchprovider.cxx b/framework/source/dispatch/dispatchprovider.cxx index c26328e02930..e9662cc946a0 100644 --- a/framework/source/dispatch/dispatchprovider.cxx +++ b/framework/source/dispatch/dispatchprovider.cxx @@ -22,7 +22,6 @@ #include <loadenv/loadenv.hxx> #include <dispatch/loaddispatcher.hxx> #include <dispatch/closedispatcher.hxx> -#include <dispatch/menudispatcher.hxx> #include <dispatch/startmoduledispatcher.hxx> #include <pattern/window.hxx> @@ -33,6 +32,7 @@ #include <targets.h> #include <general.h> +#include <com/sun/star/frame/XDesktop.hpp> #include <com/sun/star/frame/FrameSearchFlag.hpp> #include <com/sun/star/uno/Exception.hpp> #include <com/sun/star/ucb/XContentProviderManager.hpp> @@ -167,7 +167,6 @@ css::uno::Reference< css::frame::XDispatch > DispatchProvider::implts_queryDeskt // ignore wrong requests which are not supported if ( - (sTargetFrameName==SPECIALTARGET_MENUBAR ) || // valid for frame dispatches - not for desktop (sTargetFrameName==SPECIALTARGET_PARENT ) || // we have no parent by definition (sTargetFrameName==SPECIALTARGET_BEAMER ) // beamer frames are allowed as child of tasks only - // and they exist more than ones. We have no idea which our sub tasks is the right one @@ -271,15 +270,7 @@ css::uno::Reference< css::frame::XDispatch > DispatchProvider::implts_queryFrame xDispatcher = xParent->queryDispatch(aURL, sTargetName, 0); // it's a special target - ignore search flags } - // I.II) "_menubar" - // Special mode on frame or task to receive the local menu. Not supported by findFrame() - - else if (sTargetName==SPECIALTARGET_MENUBAR) - { - xDispatcher = implts_getOrCreateDispatchHelper( E_MENUDISPATCHER, xFrame ); - } - - // I.IV) "_beamer" + // I.II) "_beamer" // Special sub frame of a top frame only. Search or create it. ... OK it's currently a little bit HACKI. // Only the sfx (means the controller) can create it. @@ -300,7 +291,7 @@ css::uno::Reference< css::frame::XDispatch > DispatchProvider::implts_queryFrame } } - // I.V) "_parent" + // I.IV) "_parent" // Our parent frame (if it exist) should handle this URL. else if (sTargetName==SPECIALTARGET_PARENT) @@ -311,7 +302,7 @@ css::uno::Reference< css::frame::XDispatch > DispatchProvider::implts_queryFrame xDispatcher = xParent->queryDispatch(aURL, SPECIALTARGET_SELF, 0); } - // I.VI) "_top" + // I.V) "_top" // This request must be forwarded to any parent frame, till we reach a top frame. // If no parent exist, we can handle itself. @@ -334,7 +325,7 @@ css::uno::Reference< css::frame::XDispatch > DispatchProvider::implts_queryFrame } } - // I.VII) "_self", "" + // I.VI) "_self", "" // Our owner frame should handle this URL. But we can't do it for all of them. // So we ask the internal setted controller first. If he disagree we try to find a registered // protocol handler. If this failed too - we check for a loadable content and in case of true @@ -394,7 +385,7 @@ css::uno::Reference< css::frame::XDispatch > DispatchProvider::implts_queryFrame } } - // I.VI) no further special handlings exist + // I.VII) no further special handlings exist // Now we have to search for the right target frame by calling findFrame() - but should provide our code // against creation of a new task if no frame could be found. // I said it before - it's allowed for dispatch() only. @@ -535,20 +526,6 @@ css::uno::Reference< css::frame::XDispatch > DispatchProvider::implts_getOrCreat switch (eHelper) { - case E_MENUDISPATCHER : - { - // Attention: Such menue dispatcher must be a singleton for this frame - means our owner frame. - // Otherwhise he can make some trouble. - SolarMutexGuard g; - if ( ! m_xMenuDispatcher.is() ) - { - MenuDispatcher* pDispatcher = new MenuDispatcher( m_xContext, xOwner ); - m_xMenuDispatcher.set( static_cast< ::cppu::OWeakObject* >(pDispatcher), css::uno::UNO_QUERY ); - } - xDispatchHelper = m_xMenuDispatcher; - } - break; - case E_CREATEDISPATCHER : { LoadDispatcher* pDispatcher = new LoadDispatcher(m_xContext, xOwner, sTarget, nSearchFlags); diff --git a/framework/source/dispatch/menudispatcher.cxx b/framework/source/dispatch/menudispatcher.cxx deleted file mode 100644 index 882e482a4df2..000000000000 --- a/framework/source/dispatch/menudispatcher.cxx +++ /dev/null @@ -1,252 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <dispatch/menudispatcher.hxx> -#include <general.h> -#include <framework/menuconfiguration.hxx> -#include <framework/addonmenu.hxx> -#include <services.h> - -#include <com/sun/star/frame/FrameSearchFlag.hpp> -#include <com/sun/star/awt/WindowAttribute.hpp> -#include <com/sun/star/awt/WindowDescriptor.hpp> -#include <com/sun/star/awt/PosSize.hpp> -#include <com/sun/star/awt/XWindowPeer.hpp> -#include <com/sun/star/beans/UnknownPropertyException.hpp> -#include <com/sun/star/lang/WrappedTargetException.hpp> -#include <com/sun/star/beans/XPropertySet.hpp> -#include <com/sun/star/container/XEnumeration.hpp> -#include <com/sun/star/util/XURLTransformer.hpp> - -#include <vcl/window.hxx> -#include <vcl/syswin.hxx> -#include <vcl/menu.hxx> -#include <vcl/svapp.hxx> -#include <tools/rcid.h> -#include <osl/mutex.hxx> -#include <toolkit/helper/vclunohelper.hxx> - -#include <ucbhelper/content.hxx> - -namespace framework{ - -using namespace ::com::sun::star; -using namespace ::com::sun::star::awt; -using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::container; -using namespace ::com::sun::star::frame; -using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::util; -using namespace ::cppu; - -// constructor - -MenuDispatcher::MenuDispatcher( const uno::Reference< XComponentContext >& xContext , - const uno::Reference< XFrame >& xOwner ) - : m_xOwnerWeak ( xOwner ) - , m_xContext ( xContext ) - , m_aListenerContainer ( m_mutex ) - , m_bAlreadyDisposed ( false ) - , m_bActivateListener ( false ) - , m_pMenuManager ( nullptr ) -{ - // Safe impossible cases - // We need valid information about our owner for work. - SAL_WARN_IF( !( xContext.is() && xOwner.is() ), "fwk", "MenuDispatcher::MenuDispatcher()\nInvalid parameter detected!" ); - - m_bActivateListener = true; - xOwner->addFrameActionListener( uno::Reference< XFrameActionListener >( static_cast<OWeakObject *>(this), UNO_QUERY )); -} - -// destructor - -MenuDispatcher::~MenuDispatcher() -{ - // Warn programmer if he forgot to dispose this instance. - // We must release all our references ... - // and a dtor isn't the best place to do that! -} - -// XDispatch - -void SAL_CALL MenuDispatcher::dispatch( const URL& /*aURL*/ , - const Sequence< PropertyValue >& /*seqProperties*/ ) throw( RuntimeException, std::exception ) -{ -} - -// XDispatch - -void SAL_CALL MenuDispatcher::addStatusListener( const uno::Reference< XStatusListener >& xControl, - const URL& aURL ) throw( RuntimeException, std::exception ) -{ - SolarMutexGuard g; - // Safe impossible cases - // Method not defined for all incoming parameter - SAL_WARN_IF( !xControl.is() || aURL.Complete.isEmpty(), "fwk", "MenuDispatcher::addStatusListener(): Invalid parameter detected." ); - // Add listener to container. - m_aListenerContainer.addInterface( aURL.Complete, xControl ); -} - -// XDispatch - -void SAL_CALL MenuDispatcher::removeStatusListener( const uno::Reference< XStatusListener >& xControl, - const URL& aURL ) throw( RuntimeException, std::exception ) -{ - SolarMutexGuard g; - // Safe impossible cases - // Method not defined for all incoming parameter - SAL_WARN_IF( !xControl.is() || aURL.Complete.isEmpty(), "fwk", "MenuDispatcher::removeStatusListener(): Invalid parameter detected." ); - // Add listener to container. - m_aListenerContainer.removeInterface( aURL.Complete, xControl ); -} - -// XFrameActionListener - -void SAL_CALL MenuDispatcher::frameAction( const FrameActionEvent& aEvent ) throw ( RuntimeException, std::exception ) -{ - SolarMutexResettableGuard aGuard; - - if ( m_pMenuManager && aEvent.Action == FrameAction_FRAME_UI_ACTIVATED ) - { - MenuBar* pMenuBar = static_cast<MenuBar *>(m_pMenuManager->GetMenu()); - uno::Reference< XFrame > xFrame( m_xOwnerWeak.get(), UNO_QUERY ); - aGuard.clear(); - - if ( xFrame.is() && pMenuBar ) - { - uno::Reference< css::awt::XWindow >xContainerWindow = xFrame->getContainerWindow(); - - aGuard.reset(); - { - vcl::Window* pWindow = VCLUnoHelper::GetWindow( xContainerWindow ); - while ( pWindow && !pWindow->IsSystemWindow() ) - pWindow = pWindow->GetParent(); - - if ( pWindow ) - { - SystemWindow* pSysWindow = static_cast<SystemWindow *>(pWindow); - pSysWindow->SetMenuBar( pMenuBar ); - } - } - } - } - else if ( m_pMenuManager && aEvent.Action == css::frame::FrameAction_COMPONENT_DETACHING ) - { - if ( m_pMenuManager ) - impl_clearMenuBar(); - } -} - -// XEventListener -void SAL_CALL MenuDispatcher::disposing( const EventObject& ) throw( RuntimeException, std::exception ) -{ - SolarMutexGuard g; - // Safe impossible cases - SAL_WARN_IF( m_bAlreadyDisposed, "fwk", "MenuDispatcher::disposing(): Object already disposed .. don't call it again!" ); - - if( !m_bAlreadyDisposed ) - { - m_bAlreadyDisposed = true; - - if ( m_bActivateListener ) - { - uno::Reference< XFrame > xFrame( m_xOwnerWeak.get(), UNO_QUERY ); - if ( xFrame.is() ) - { - xFrame->removeFrameActionListener( uno::Reference< XFrameActionListener >( static_cast<OWeakObject *>(this), UNO_QUERY )); - m_bActivateListener = false; - if ( m_pMenuManager ) - { - EventObject aEventObj; - aEventObj.Source = xFrame; - m_pMenuManager->disposing( aEventObj ); - } - } - } - - // Forget our factory. - m_xContext.clear(); - - // Remove our menu from system window if it is still there! - if ( m_pMenuManager ) - impl_clearMenuBar(); - } -} - -void MenuDispatcher::impl_setAccelerators( Menu* pMenu, const Accelerator& aAccel ) -{ - for ( sal_uInt16 nPos = 0; nPos < pMenu->GetItemCount(); ++nPos ) - { - sal_uInt16 nId = pMenu->GetItemId(nPos); - ::PopupMenu* pPopup = pMenu->GetPopupMenu(nId); - if ( pPopup ) - impl_setAccelerators( static_cast<Menu *>(pPopup), aAccel ); - else if ( nId && !pMenu->GetPopupMenu(nId)) - { - vcl::KeyCode aCode = aAccel.GetKeyCode( nId ); - if ( aCode.GetCode() ) - pMenu->SetAccelKey( nId, aCode ); - } - } -} - -bool MenuDispatcher::impl_clearMenuBar() -{ - uno::Reference< XFrame > xFrame( m_xOwnerWeak.get(), UNO_QUERY ); - if ( xFrame.is() ) - { - uno::Reference< css::awt::XWindow >xContainerWindow = xFrame->getContainerWindow(); - vcl::Window* pWindow = nullptr; - - SolarMutexGuard aSolarGuard; - { - pWindow = VCLUnoHelper::GetWindow( xContainerWindow ); - while ( pWindow && !pWindow->IsSystemWindow() ) - pWindow = pWindow->GetParent(); - } - - if ( pWindow ) - { - SystemWindow* pSysWindow = static_cast<SystemWindow *>(pWindow); - - if ( m_pMenuManager ) - { - // remove old menu from our system window if it was set before - if ( m_pMenuManager->GetMenu() == static_cast<Menu *>(pSysWindow->GetMenuBar()) ) - pSysWindow->SetMenuBar( nullptr ); - - // remove listener before we destruct ourself, so we cannot be called back afterwards - m_pMenuManager->RemoveListener(); - - (static_cast< css::uno::XInterface* >(static_cast<OWeakObject*>(m_pMenuManager)))->release(); - - m_pMenuManager = nullptr; - } - - return true; - } - } - - return false; -} - -} // namespace framework - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/framework/source/inc/loadenv/targethelper.hxx b/framework/source/inc/loadenv/targethelper.hxx index f982d02df824..9317619d609c 100644 --- a/framework/source/inc/loadenv/targethelper.hxx +++ b/framework/source/inc/loadenv/targethelper.hxx @@ -48,7 +48,6 @@ class TargetHelper E_BLANK , E_DEFAULT , E_BEAMER , - E_MENUBAR , E_HELPAGENT , E_HELPTASK }; diff --git a/framework/source/loadenv/targethelper.cxx b/framework/source/loadenv/targethelper.cxx index 797da8071885..488b0525fa98 100644 --- a/framework/source/loadenv/targethelper.cxx +++ b/framework/source/loadenv/targethelper.cxx @@ -47,9 +47,6 @@ bool TargetHelper::matchSpecialTarget(const OUString& sCheckTarget , case E_BEAMER : return sCheckTarget == SPECIALTARGET_BEAMER; - case E_MENUBAR : - return sCheckTarget == SPECIALTARGET_MENUBAR; - case E_HELPTASK : return sCheckTarget == SPECIALTARGET_HELPTASK; default: diff --git a/framework/source/services/desktop.cxx b/framework/source/services/desktop.cxx index 50bf49c36219..d03bc0481154 100644 --- a/framework/source/services/desktop.cxx +++ b/framework/source/services/desktop.cxx @@ -907,7 +907,6 @@ css::uno::Reference< css::frame::XFrame > SAL_CALL Desktop::findFrame( const OUS if ( (sTargetFrameName==SPECIALTARGET_DEFAULT ) || // valid for dispatches - not for findFrame()! - (sTargetFrameName==SPECIALTARGET_MENUBAR ) || // valid for dispatches - not for findFrame()! (sTargetFrameName==SPECIALTARGET_PARENT ) || // we have no parent by definition (sTargetFrameName==SPECIALTARGET_BEAMER ) // beamer frames are allowed as child of tasks only - // and they exist more than ones. We have no idea which our sub tasks is the right one diff --git a/framework/source/services/frame.cxx b/framework/source/services/frame.cxx index 8f374a4ee4c1..249297587abb 100644 --- a/framework/source/services/frame.cxx +++ b/framework/source/services/frame.cxx @@ -945,7 +945,7 @@ OUString SAL_CALL Frame::getName() throw( css::uno::RuntimeException, std::excep @descr This name is used to find target of findFrame() or queryDispatch() calls. @attention Special names like "_blank", "_self" aren't allowed... - "_beamer" or "_menubar" excepts this rule! + "_beamer" excepts this rule! @seealso method getName() @@ -997,10 +997,7 @@ css::uno::Reference< css::frame::XFrame > SAL_CALL Frame::findFrame( const OUStr // in following code again and again. If we do not so -wrong // search results can occur! - if ( - (sTargetFrameName==SPECIALTARGET_DEFAULT ) || // valid for dispatches - not for findFrame()! - (sTargetFrameName==SPECIALTARGET_MENUBAR ) // valid for dispatches - not for findFrame()! - ) + if ( sTargetFrameName == SPECIALTARGET_DEFAULT ) // valid for dispatches - not for findFrame()! { return nullptr; } diff --git a/framework/source/uielement/menubarmanager.cxx b/framework/source/uielement/menubarmanager.cxx index a5ebea7dd2c5..77f5be659475 100644 --- a/framework/source/uielement/menubarmanager.cxx +++ b/framework/source/uielement/menubarmanager.cxx @@ -23,7 +23,6 @@ #include <framework/addonmenu.hxx> #include <framework/addonsoptions.hxx> #include <classes/fwkresid.hxx> -#include <classes/menumanager.hxx> #include <helper/mischelper.hxx> #include <framework/menuextensionsupplier.hxx> #include <classes/resource.hrc> @@ -764,7 +763,7 @@ IMPL_LINK_TYPED( MenuBarManager, Activate, Menu *, pMenu, bool ) OUString aMenuCommand( m_aMenuItemCommand ); if ( m_aMenuItemCommand == aSpecialWindowMenu || m_aMenuItemCommand == aSlotSpecialWindowMenu || aMenuCommand == aSpecialWindowCommand ) - MenuManager::UpdateSpecialWindowMenu( pMenu, m_xContext ); + UpdateSpecialWindowMenu( pMenu, m_xContext ); // Check if some modes have changed so we have to update our menu images OUString sIconTheme = SvtMiscOptions().GetIconTheme(); @@ -776,7 +775,7 @@ IMPL_LINK_TYPED( MenuBarManager, Activate, Menu *, pMenu, bool ) m_bShowMenuImages = bShowMenuImages; m_bRetrieveImages = false; m_sIconTheme = sIconTheme; - MenuManager::FillMenuImages( m_xFrame, pMenu, bShowMenuImages ); + FillMenuImages( m_xFrame, pMenu, bShowMenuImages ); } // Try to map commands to labels @@ -1981,6 +1980,126 @@ void MenuBarManager::SetHdl() m_xURLTransformer.set( URLTransformer::create( m_xContext) ); } +void MenuBarManager::UpdateSpecialWindowMenu( Menu* pMenu,const Reference< XComponentContext >& xContext ) +{ + // update window list + ::std::vector< OUString > aNewWindowListVector; + + Reference< XDesktop2 > xDesktop = css::frame::Desktop::create( xContext ); + + sal_uInt16 nActiveItemId = 0; + sal_uInt16 nItemId = START_ITEMID_WINDOWLIST; + + Reference< XFrame > xCurrentFrame = xDesktop->getCurrentFrame(); + Reference< XIndexAccess > xList( xDesktop->getFrames(), UNO_QUERY ); + sal_Int32 nFrameCount = xList->getCount(); + aNewWindowListVector.reserve(nFrameCount); + for (sal_Int32 i=0; i<nFrameCount; ++i ) + { + Reference< XFrame > xFrame; + xList->getByIndex(i) >>= xFrame; + + if (xFrame.is()) + { + if ( xFrame == xCurrentFrame ) + nActiveItemId = nItemId; + + vcl::Window* pWin = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() ); + if ( pWin && pWin->IsVisible() ) + { + aNewWindowListVector.push_back( pWin->GetText() ); + ++nItemId; + } + } + } + + { + SolarMutexGuard g; + + int nItemCount = pMenu->GetItemCount(); + + if ( nItemCount > 0 ) + { + // remove all old window list entries from menu + sal_uInt16 nPos = pMenu->GetItemPos( START_ITEMID_WINDOWLIST ); + for ( sal_uInt16 n = nPos; n < pMenu->GetItemCount(); ) + pMenu->RemoveItem( n ); + + if ( pMenu->GetItemType( pMenu->GetItemCount()-1 ) == MenuItemType::SEPARATOR ) + pMenu->RemoveItem( pMenu->GetItemCount()-1 ); + } + + if ( !aNewWindowListVector.empty() ) + { + // append new window list entries to menu + pMenu->InsertSeparator(); + nItemId = START_ITEMID_WINDOWLIST; + const sal_uInt32 nCount = aNewWindowListVector.size(); + for ( sal_uInt32 i = 0; i < nCount; i++ ) + { + pMenu->InsertItem( nItemId, aNewWindowListVector.at( i ), MenuItemBits::RADIOCHECK ); + if ( nItemId == nActiveItemId ) + pMenu->CheckItem( nItemId ); + ++nItemId; + } + } + } +} + +void MenuBarManager::FillMenuImages(Reference< XFrame >& _xFrame, Menu* _pMenu,bool bShowMenuImages) +{ + AddonsOptions aAddonOptions; + + for ( sal_uInt16 nPos = 0; nPos < _pMenu->GetItemCount(); nPos++ ) + { + sal_uInt16 nId = _pMenu->GetItemId( nPos ); + if ( _pMenu->GetItemType( nPos ) != MenuItemType::SEPARATOR ) + { + bool bTmpShowMenuImages( bShowMenuImages ); + // overwrite the show icons on menu option? + if (!bTmpShowMenuImages) + { + MenuItemBits nBits = _pMenu->GetItemBits( nId ); + bTmpShowMenuImages = ( ( nBits & MenuItemBits::ICON ) == MenuItemBits::ICON ); + } + + if ( bTmpShowMenuImages ) + { + bool bImageSet = false; + OUString aImageId; + + ::framework::MenuAttributes* pMenuAttributes = + reinterpret_cast< ::framework::MenuAttributes*>(_pMenu->GetUserValue( nId )); + + if ( pMenuAttributes ) + aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes + + if ( !aImageId.isEmpty() ) + { + Image aImage = vcl::CommandInfoProvider::Instance().GetImageForCommand(aImageId, false, _xFrame ); + if ( !!aImage ) + { + bImageSet = true; + _pMenu->SetItemImage( nId, aImage ); + } + } + + if ( !bImageSet ) + { + OUString aMenuItemCommand = _pMenu->GetItemCommand( nId ); + Image aImage = vcl::CommandInfoProvider::Instance().GetImageForCommand(aMenuItemCommand, false, _xFrame ); + if ( !aImage ) + aImage = aAddonOptions.GetImageFromURL( aMenuItemCommand, false ); + + _pMenu->SetItemImage( nId, aImage ); + } + } + else + _pMenu->SetItemImage( nId, Image() ); + } + } +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |