16d739b60SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 36d739b60SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 46d739b60SAndrew Rist * or more contributor license agreements. See the NOTICE file 56d739b60SAndrew Rist * distributed with this work for additional information 66d739b60SAndrew Rist * regarding copyright ownership. The ASF licenses this file 76d739b60SAndrew Rist * to you under the Apache License, Version 2.0 (the 86d739b60SAndrew Rist * "License"); you may not use this file except in compliance 96d739b60SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 116d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 136d739b60SAndrew Rist * Unless required by applicable law or agreed to in writing, 146d739b60SAndrew Rist * software distributed under the License is distributed on an 156d739b60SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 166d739b60SAndrew Rist * KIND, either express or implied. See the License for the 176d739b60SAndrew Rist * specific language governing permissions and limitations 186d739b60SAndrew Rist * under the License. 19cdf0e10cSrcweir * 206d739b60SAndrew Rist *************************************************************/ 216d739b60SAndrew Rist 226d739b60SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_framework.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir 28cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 29cdf0e10cSrcweir // my own includes 30cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 31cdf0e10cSrcweir #include <classes/menumanager.hxx> 32cdf0e10cSrcweir #include <framework/menuconfiguration.hxx> 33cdf0e10cSrcweir #include <framework/bmkmenu.hxx> 34cdf0e10cSrcweir #include <framework/addonmenu.hxx> 35cdf0e10cSrcweir #include <framework/imageproducer.hxx> 36cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx> 37cdf0e10cSrcweir #include "framework/addonsoptions.hxx" 38cdf0e10cSrcweir #include <classes/fwkresid.hxx> 39cdf0e10cSrcweir #include <services.h> 40cdf0e10cSrcweir #include "classes/resource.hrc" 41cdf0e10cSrcweir 42cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 43cdf0e10cSrcweir // interface includes 44cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 45cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp> 46cdf0e10cSrcweir #include <com/sun/star/frame/XDispatch.hpp> 47cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp> 48cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 49cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 50cdf0e10cSrcweir #include <com/sun/star/frame/XFramesSupplier.hpp> 51cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp> 52cdf0e10cSrcweir #include <com/sun/star/container/XEnumeration.hpp> 53cdf0e10cSrcweir #include <com/sun/star/util/XStringWidth.hpp> 54cdf0e10cSrcweir 55cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 56cdf0e10cSrcweir // includes of other projects 57cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 58cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 59cdf0e10cSrcweir 60cdf0e10cSrcweir #include <comphelper/extract.hxx> 61cdf0e10cSrcweir #include <svtools/menuoptions.hxx> 62cdf0e10cSrcweir #include <unotools/historyoptions.hxx> 63cdf0e10cSrcweir #include <unotools/pathoptions.hxx> 64cdf0e10cSrcweir #include <unotools/localfilehelper.hxx> 65cdf0e10cSrcweir 66cdf0e10cSrcweir #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_ 67cdf0e10cSrcweir #include <toolkit/unohlp.hxx> 68cdf0e10cSrcweir #endif 69cdf0e10cSrcweir #include <tools/urlobj.hxx> 70cdf0e10cSrcweir 71cdf0e10cSrcweir #include <vcl/svapp.hxx> 72cdf0e10cSrcweir #include <vcl/window.hxx> 73cdf0e10cSrcweir #include <vos/mutex.hxx> 74cdf0e10cSrcweir #include <vcl/svapp.hxx> 75cdf0e10cSrcweir #include <osl/file.hxx> 76cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 77cdf0e10cSrcweir 78cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 79cdf0e10cSrcweir // namespace 80cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 81cdf0e10cSrcweir 82cdf0e10cSrcweir using namespace ::cppu; 83cdf0e10cSrcweir using namespace ::vos; 84cdf0e10cSrcweir using namespace ::com::sun::star::uno; 85cdf0e10cSrcweir using namespace ::com::sun::star::util; 86cdf0e10cSrcweir using namespace ::com::sun::star::beans; 87cdf0e10cSrcweir using namespace ::com::sun::star::frame; 88cdf0e10cSrcweir using namespace ::com::sun::star::lang; 89cdf0e10cSrcweir using namespace ::com::sun::star::container; 90cdf0e10cSrcweir 91cdf0e10cSrcweir 92cdf0e10cSrcweir class StringLength : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XStringWidth > 93cdf0e10cSrcweir { 94cdf0e10cSrcweir public: 95cdf0e10cSrcweir StringLength() {} 96cdf0e10cSrcweir virtual ~StringLength() {} 97cdf0e10cSrcweir 98cdf0e10cSrcweir // XStringWidth 99cdf0e10cSrcweir sal_Int32 SAL_CALL queryStringWidth( const ::rtl::OUString& aString ) 100cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir return aString.getLength(); 103cdf0e10cSrcweir } 104cdf0e10cSrcweir }; 105cdf0e10cSrcweir 106cdf0e10cSrcweir namespace framework 107cdf0e10cSrcweir { 108cdf0e10cSrcweir 109cdf0e10cSrcweir // special menu ids/command ids for dynamic popup menus 110cdf0e10cSrcweir #define SID_SFX_START 5000 111cdf0e10cSrcweir #define SID_NEWDOCDIRECT (SID_SFX_START + 537) 112cdf0e10cSrcweir #define SID_AUTOPILOTMENU (SID_SFX_START + 1381) 113cdf0e10cSrcweir #define SID_PICKLIST (SID_SFX_START + 510) 114cdf0e10cSrcweir #define SID_MDIWINDOWLIST (SID_SFX_START + 610) 115cdf0e10cSrcweir #define SID_ADDONLIST (SID_SFX_START + 1677) 116cdf0e10cSrcweir #define SID_HELPMENU (SID_SFX_START + 410) 117cdf0e10cSrcweir 118cdf0e10cSrcweir #define SFX_REFERER_USER "private:user" 119cdf0e10cSrcweir 120cdf0e10cSrcweir const ::rtl::OUString aSlotNewDocDirect( RTL_CONSTASCII_USTRINGPARAM( "slot:5537" )); 121cdf0e10cSrcweir const ::rtl::OUString aSlotAutoPilot( RTL_CONSTASCII_USTRINGPARAM( "slot:6381" )); 122cdf0e10cSrcweir 123cdf0e10cSrcweir const ::rtl::OUString aSpecialFileMenu( RTL_CONSTASCII_USTRINGPARAM( "file" )); 124cdf0e10cSrcweir const ::rtl::OUString aSpecialWindowMenu( RTL_CONSTASCII_USTRINGPARAM( "window" )); 125cdf0e10cSrcweir const ::rtl::OUString aSlotSpecialFileMenu( RTL_CONSTASCII_USTRINGPARAM( "slot:5510" )); 126cdf0e10cSrcweir const ::rtl::OUString aSlotSpecialWindowMenu( RTL_CONSTASCII_USTRINGPARAM( "slot:5610" )); 127cdf0e10cSrcweir const ::rtl::OUString aSlotSpecialToolsMenu( RTL_CONSTASCII_USTRINGPARAM( "slot:6677" )); 128cdf0e10cSrcweir 129cdf0e10cSrcweir // special uno commands for picklist and window list 130cdf0e10cSrcweir const ::rtl::OUString aSpecialFileCommand( RTL_CONSTASCII_USTRINGPARAM( "PickList" )); 131cdf0e10cSrcweir const ::rtl::OUString aSpecialWindowCommand( RTL_CONSTASCII_USTRINGPARAM( "WindowList" )); 132cdf0e10cSrcweir 133cdf0e10cSrcweir const ::rtl::OUString UNO_COMMAND( RTL_CONSTASCII_USTRINGPARAM( ".uno:" )); 134cdf0e10cSrcweir 135cdf0e10cSrcweir // #110897# 136cdf0e10cSrcweir MenuManager::MenuManager( 137cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory, 138cdf0e10cSrcweir REFERENCE< XFRAME >& rFrame, Menu* pMenu, sal_Bool bDelete, sal_Bool bDeleteChildren ) 139cdf0e10cSrcweir : // #110897# 140cdf0e10cSrcweir ThreadHelpBase( &Application::GetSolarMutex() ), 141cdf0e10cSrcweir mxServiceFactory(xServiceFactory) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir m_bActive = sal_False; 144cdf0e10cSrcweir m_bDeleteMenu = bDelete; 145cdf0e10cSrcweir m_bDeleteChildren = bDeleteChildren; 146cdf0e10cSrcweir m_pVCLMenu = pMenu; 147cdf0e10cSrcweir m_xFrame = rFrame; 148cdf0e10cSrcweir m_bInitialized = sal_False; 149cdf0e10cSrcweir m_bIsBookmarkMenu = sal_False; 150*32fcbcfdSHerbert Dürr 151*32fcbcfdSHerbert Dürr acquire(); 152cdf0e10cSrcweir 153cdf0e10cSrcweir const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings(); 154cdf0e10cSrcweir m_bWasHiContrast = rSettings.GetHighContrastMode(); 155cdf0e10cSrcweir m_bShowMenuImages = rSettings.GetUseImagesInMenus(); 156cdf0e10cSrcweir 157cdf0e10cSrcweir sal_Int32 nAddonsURLPrefixLength = ADDONSPOPUPMENU_URL_PREFIX.getLength(); 158cdf0e10cSrcweir #if 0 159cdf0e10cSrcweir ::std::vector< sal_uInt16 > aQueryLabelItemIdVector; 160cdf0e10cSrcweir #endif 161cdf0e10cSrcweir 162cdf0e10cSrcweir sal_uInt16 nItemCount = pMenu->GetItemCount(); 163cdf0e10cSrcweir m_aMenuItemHandlerVector.reserve(nItemCount); 164cdf0e10cSrcweir ::rtl::OUString aItemCommand; 165cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < nItemCount; i++ ) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir sal_uInt16 nItemId = FillItemCommand(aItemCommand,pMenu, i ); 168cdf0e10cSrcweir bool bShowMenuImages( m_bShowMenuImages ); 169cdf0e10cSrcweir MenuItemBits nBits = pMenu->GetItemBits( nItemId ); 170cdf0e10cSrcweir // overwrite the default? 171cdf0e10cSrcweir if ( nBits ) 172cdf0e10cSrcweir bShowMenuImages = ( ( nBits & MIB_ICON ) == MIB_ICON ); 173cdf0e10cSrcweir 174cdf0e10cSrcweir 175cdf0e10cSrcweir PopupMenu* pPopupMenu = pMenu->GetPopupMenu( nItemId ); 176cdf0e10cSrcweir if ( pPopupMenu ) 177cdf0e10cSrcweir { 178cdf0e10cSrcweir AddMenu(pPopupMenu,aItemCommand,nItemId,bDeleteChildren,bDeleteChildren); 179cdf0e10cSrcweir if (! (( aItemCommand.getLength() > nAddonsURLPrefixLength ) && 180cdf0e10cSrcweir ( aItemCommand.indexOf( ADDONSPOPUPMENU_URL_PREFIX ) == 0 )) ) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir // #110897# 183cdf0e10cSrcweir // MenuManager* pSubMenuManager = new MenuManager( rFrame, pPopupMenu, bDeleteChildren, bDeleteChildren ); 184cdf0e10cSrcweir #if 0 185cdf0e10cSrcweir if ( pMenu->GetItemText( nItemId ).Len() == 0 ) 186cdf0e10cSrcweir aQueryLabelItemIdVector.push_back( nItemId ); 187cdf0e10cSrcweir #endif 188cdf0e10cSrcweir 189cdf0e10cSrcweir // Create addon popup menu if there exist elements and this is the tools popup menu 190cdf0e10cSrcweir if (( nItemId == SID_ADDONLIST || 191cdf0e10cSrcweir aItemCommand == aSlotSpecialToolsMenu ) && 192cdf0e10cSrcweir AddonMenuManager::HasAddonMenuElements() ) 193cdf0e10cSrcweir { 194cdf0e10cSrcweir sal_uInt16 nCount = 0; 195cdf0e10cSrcweir AddonMenu* pSubMenu = AddonMenuManager::CreateAddonMenu( rFrame ); 196cdf0e10cSrcweir if ( pSubMenu && ( pSubMenu->GetItemCount() > 0 )) 197cdf0e10cSrcweir { 198cdf0e10cSrcweir if ( pPopupMenu->GetItemType( nCount-1 ) != MENUITEM_SEPARATOR ) 199cdf0e10cSrcweir pPopupMenu->InsertSeparator(); 200cdf0e10cSrcweir 201cdf0e10cSrcweir // Use resource to load popup menu title 202cdf0e10cSrcweir String aAddonsStrRes = String( FwkResId( STR_MENU_ADDONS )); 203cdf0e10cSrcweir pPopupMenu->InsertItem( ITEMID_ADDONLIST, aAddonsStrRes ); 204cdf0e10cSrcweir pPopupMenu->SetPopupMenu( ITEMID_ADDONLIST, pSubMenu ); 205cdf0e10cSrcweir 206cdf0e10cSrcweir // Set item command for popup menu to enable it for GetImageFromURL 207cdf0e10cSrcweir const static ::rtl::OUString aSlotString( RTL_CONSTASCII_USTRINGPARAM( "slot:" )); 208cdf0e10cSrcweir aItemCommand = aSlotString; 209cdf0e10cSrcweir aItemCommand += ::rtl::OUString::valueOf( (sal_Int32)ITEMID_ADDONLIST ); 210cdf0e10cSrcweir pPopupMenu->SetItemCommand( ITEMID_ADDONLIST, aItemCommand ); 211cdf0e10cSrcweir 212cdf0e10cSrcweir // #110897# 213cdf0e10cSrcweir // MenuManager* pSubMenuManager = new MenuManager( rFrame, pSubMenu, sal_True, sal_False ); 214cdf0e10cSrcweir AddMenu(pSubMenu,::rtl::OUString(),nItemId,sal_True,sal_False); 215cdf0e10cSrcweir #if 0 216cdf0e10cSrcweir if ( pMenu->GetItemText( nItemId ).Len() == 0 ) 217cdf0e10cSrcweir aQueryLabelItemIdVector.push_back( nItemId ); 218cdf0e10cSrcweir #endif 219cdf0e10cSrcweir // Set image for the addon popup menu item 220cdf0e10cSrcweir if ( bShowMenuImages && !pPopupMenu->GetItemImage( ITEMID_ADDONLIST )) 221cdf0e10cSrcweir { 222cdf0e10cSrcweir Image aImage = GetImageFromURL( rFrame, aItemCommand, sal_False, m_bWasHiContrast ); 223cdf0e10cSrcweir if ( !!aImage ) 224cdf0e10cSrcweir pPopupMenu->SetItemImage( ITEMID_ADDONLIST, aImage ); 225cdf0e10cSrcweir } 226cdf0e10cSrcweir } 227cdf0e10cSrcweir else 228cdf0e10cSrcweir delete pSubMenu; 229cdf0e10cSrcweir } 230cdf0e10cSrcweir } 231cdf0e10cSrcweir } 232cdf0e10cSrcweir else 233cdf0e10cSrcweir { 234cdf0e10cSrcweir if ( nItemId == SID_NEWDOCDIRECT || 235cdf0e10cSrcweir aItemCommand == aSlotNewDocDirect ) 236cdf0e10cSrcweir { 237cdf0e10cSrcweir // #110897# 238cdf0e10cSrcweir // Reference< ::com::sun::star::lang::XMultiServiceFactory > aMultiServiceFactory(::comphelper::getProcessServiceFactory()); 239cdf0e10cSrcweir // MenuConfiguration aMenuCfg( aMultiServiceFactory ); 240cdf0e10cSrcweir MenuConfiguration aMenuCfg( getServiceFactory() ); 241cdf0e10cSrcweir BmkMenu* pSubMenu = (BmkMenu*)aMenuCfg.CreateBookmarkMenu( rFrame, BOOKMARK_NEWMENU ); 242cdf0e10cSrcweir pMenu->SetPopupMenu( nItemId, pSubMenu ); 243cdf0e10cSrcweir 244cdf0e10cSrcweir // #110897# 245cdf0e10cSrcweir // MenuManager* pSubMenuManager = new MenuManager( rFrame, pSubMenu, sal_True, sal_False ); 246cdf0e10cSrcweir AddMenu(pSubMenu,::rtl::OUString(),nItemId,sal_True,sal_False); 247cdf0e10cSrcweir #if 0 248cdf0e10cSrcweir if ( pMenu->GetItemText( nItemId ).Len() == 0 ) 249cdf0e10cSrcweir aQueryLabelItemIdVector.push_back( nItemId ); 250cdf0e10cSrcweir #endif 251cdf0e10cSrcweir 252cdf0e10cSrcweir if ( bShowMenuImages && !pMenu->GetItemImage( nItemId )) 253cdf0e10cSrcweir { 254cdf0e10cSrcweir Image aImage = GetImageFromURL( rFrame, aItemCommand, sal_False, m_bWasHiContrast ); 255cdf0e10cSrcweir if ( !!aImage ) 256cdf0e10cSrcweir pMenu->SetItemImage( nItemId, aImage ); 257cdf0e10cSrcweir } 258cdf0e10cSrcweir } 259cdf0e10cSrcweir else if ( nItemId == SID_AUTOPILOTMENU || 260cdf0e10cSrcweir aItemCommand == aSlotAutoPilot ) 261cdf0e10cSrcweir { 262cdf0e10cSrcweir // #110897# 263cdf0e10cSrcweir // Reference< ::com::sun::star::lang::XMultiServiceFactory > aMultiServiceFactory(::comphelper::getProcessServiceFactory()); 264cdf0e10cSrcweir // MenuConfiguration aMenuCfg( aMultiServiceFactory ); 265cdf0e10cSrcweir MenuConfiguration aMenuCfg( getServiceFactory() ); 266cdf0e10cSrcweir BmkMenu* pSubMenu = (BmkMenu*)aMenuCfg.CreateBookmarkMenu( rFrame, BOOKMARK_WIZARDMENU ); 267cdf0e10cSrcweir pMenu->SetPopupMenu( nItemId, pSubMenu ); 268cdf0e10cSrcweir 269cdf0e10cSrcweir // #110897# 270cdf0e10cSrcweir // MenuManager* pSubMenuManager = new MenuManager( rFrame, pSubMenu, sal_True, sal_False ); 271cdf0e10cSrcweir AddMenu(pSubMenu,::rtl::OUString(),nItemId,sal_True,sal_False); 272cdf0e10cSrcweir #if 0 273cdf0e10cSrcweir if ( pMenu->GetItemText( nItemId ).Len() == 0 ) 274cdf0e10cSrcweir aQueryLabelItemIdVector.push_back( nItemId ); 275cdf0e10cSrcweir #endif 276cdf0e10cSrcweir 277cdf0e10cSrcweir if ( bShowMenuImages && !pMenu->GetItemImage( nItemId )) 278cdf0e10cSrcweir { 279cdf0e10cSrcweir Image aImage = GetImageFromURL( rFrame, aItemCommand, sal_False, m_bWasHiContrast ); 280cdf0e10cSrcweir if ( !!aImage ) 281cdf0e10cSrcweir pMenu->SetItemImage( nItemId, aImage ); 282cdf0e10cSrcweir } 283cdf0e10cSrcweir } 284cdf0e10cSrcweir else if ( pMenu->GetItemType( i ) != MENUITEM_SEPARATOR ) 285cdf0e10cSrcweir { 286cdf0e10cSrcweir if ( bShowMenuImages ) 287cdf0e10cSrcweir { 288cdf0e10cSrcweir if ( AddonMenuManager::IsAddonMenuId( nItemId )) 289cdf0e10cSrcweir { 290cdf0e10cSrcweir // Add-Ons uses a images from different places 291cdf0e10cSrcweir Image aImage; 292cdf0e10cSrcweir rtl::OUString aImageId; 293cdf0e10cSrcweir 294cdf0e10cSrcweir MenuConfiguration::Attributes* pMenuAttributes = 295cdf0e10cSrcweir (MenuConfiguration::Attributes*)pMenu->GetUserValue( nItemId ); 296cdf0e10cSrcweir 297cdf0e10cSrcweir if ( pMenuAttributes && pMenuAttributes->aImageId.getLength() > 0 ) 298cdf0e10cSrcweir { 299cdf0e10cSrcweir // Retrieve image id from menu attributes 300cdf0e10cSrcweir aImage = GetImageFromURL( rFrame, aImageId, sal_False, m_bWasHiContrast ); 301cdf0e10cSrcweir } 302cdf0e10cSrcweir 303cdf0e10cSrcweir if ( !aImage ) 304cdf0e10cSrcweir { 305cdf0e10cSrcweir aImage = GetImageFromURL( rFrame, aItemCommand, sal_False, m_bWasHiContrast ); 306cdf0e10cSrcweir if ( !aImage ) 307cdf0e10cSrcweir aImage = AddonsOptions().GetImageFromURL( aItemCommand, sal_False, m_bWasHiContrast ); 308cdf0e10cSrcweir } 309cdf0e10cSrcweir 310cdf0e10cSrcweir if ( !!aImage ) 311cdf0e10cSrcweir pMenu->SetItemImage( nItemId, aImage ); 312cdf0e10cSrcweir } 313cdf0e10cSrcweir else if ( !pMenu->GetItemImage( nItemId )) 314cdf0e10cSrcweir { 315cdf0e10cSrcweir Image aImage = GetImageFromURL( rFrame, aItemCommand, sal_False, m_bWasHiContrast ); 316cdf0e10cSrcweir if ( !!aImage ) 317cdf0e10cSrcweir pMenu->SetItemImage( nItemId, aImage ); 318cdf0e10cSrcweir } 319cdf0e10cSrcweir } 320cdf0e10cSrcweir 321cdf0e10cSrcweir REFERENCE< XDISPATCH > aXDispatchRef; 322cdf0e10cSrcweir m_aMenuItemHandlerVector.push_back( new MenuItemHandler( nItemId, NULL, aXDispatchRef )); 323cdf0e10cSrcweir #if 0 324cdf0e10cSrcweir if ( pMenu->GetItemText( nItemId ).Len() == 0 ) 325cdf0e10cSrcweir aQueryLabelItemIdVector.push_back( nItemId ); 326cdf0e10cSrcweir #endif 327cdf0e10cSrcweir } 328cdf0e10cSrcweir } 329cdf0e10cSrcweir } 330cdf0e10cSrcweir 331cdf0e10cSrcweir 332cdf0e10cSrcweir // retrieve label information for all menu items without item text 333cdf0e10cSrcweir #if 0 334cdf0e10cSrcweir if ( aQueryLabelItemIdVector.size() > 0 ) 335cdf0e10cSrcweir { 336cdf0e10cSrcweir Sequence< ::rtl::OUString > aURLSequence( aQueryLabelItemIdVector.size() ); 337cdf0e10cSrcweir Sequence< ::rtl::OUString > aLabelSequence( aQueryLabelItemIdVector.size() ); 338cdf0e10cSrcweir 339cdf0e10cSrcweir sal_uInt32 nPos = 0; 340cdf0e10cSrcweir ::std::vector< sal_uInt16 >::iterator p; 341cdf0e10cSrcweir for ( p = aQueryLabelItemIdVector.begin(); p != aQueryLabelItemIdVector.end(); p++ ) 342cdf0e10cSrcweir aURLSequence[nPos++] = pMenu->GetItemCommand( *p ); 343cdf0e10cSrcweir 344cdf0e10cSrcweir Reference< XDispatchInformationProvider > xDIP( xFrame, UNO_QUERY ); 345cdf0e10cSrcweir if ( xDIP.is() ) 346cdf0e10cSrcweir { 347cdf0e10cSrcweir nPos = 0; 348cdf0e10cSrcweir xDIP->queryDispatchInformations( aURLSequence, aLabelSequence ); 349cdf0e10cSrcweir for ( p = aQueryLabelItemIdVector.begin(); p != aQueryLabelItemIdVector.end(); p++ ) 350cdf0e10cSrcweir pMenu->SetItemText( *p, aLabelSequence( nPos++ )); 351cdf0e10cSrcweir } 352cdf0e10cSrcweir } 353cdf0e10cSrcweir #endif 354cdf0e10cSrcweir SetHdl(); 355cdf0e10cSrcweir } 356cdf0e10cSrcweir 357cdf0e10cSrcweir #if 0 358cdf0e10cSrcweir // #110897# 359cdf0e10cSrcweir MenuManager::MenuManager( 360cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory, 361cdf0e10cSrcweir REFERENCE< XFRAME >& rFrame, AddonMenu* pAddonMenu, sal_Bool bDelete, sal_Bool bDeleteChildren ) 362cdf0e10cSrcweir : // #110897# 363cdf0e10cSrcweir ThreadHelpBase( &Application::GetSolarMutex() ), 364cdf0e10cSrcweir mxServiceFactory(xServiceFactory) 365cdf0e10cSrcweir { 366cdf0e10cSrcweir m_bActive = sal_False; 367cdf0e10cSrcweir m_bDeleteMenu = bDelete; 368cdf0e10cSrcweir m_bDeleteChildren = bDeleteChildren; 369cdf0e10cSrcweir m_pVCLMenu = pAddonMenu; 370cdf0e10cSrcweir m_xFrame = rFrame; 371cdf0e10cSrcweir m_bInitialized = sal_False; 372cdf0e10cSrcweir m_bIsBookmarkMenu = sal_True; 373cdf0e10cSrcweir 374cdf0e10cSrcweir const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings(); 375cdf0e10cSrcweir m_bWasHiContrast = rSettings.GetHighContrastMode(); 376cdf0e10cSrcweir 377cdf0e10cSrcweir SAL_STATIC_CAST( ::com::sun::star::uno::XInterface*, (OWeakObject*)this )->acquire(); 378cdf0e10cSrcweir 379cdf0e10cSrcweir sal_uInt16 nItemCount = pAddonMenu->GetItemCount(); 380cdf0e10cSrcweir m_aMenuItemHandlerVector.reserve(nItemCount); 381cdf0e10cSrcweir ::rtl::OUString aItemCommand; 382cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < nItemCount; i++ ) 383cdf0e10cSrcweir { 384cdf0e10cSrcweir sal_uInt16 nItemId = FillItemCommand(aItemCommand,pAddonMenu, i ); 385cdf0e10cSrcweir 386cdf0e10cSrcweir PopupMenu* pPopupMenu = pAddonMenu->GetPopupMenu( nItemId ); 387cdf0e10cSrcweir if ( pPopupMenu ) 388cdf0e10cSrcweir { 389cdf0e10cSrcweir // #110897# 390cdf0e10cSrcweir // MenuManager* pSubMenuManager = new MenuManager( rFrame, pPopupMenu, bDeleteChildren, bDeleteChildren ); 391cdf0e10cSrcweir AddMenu(pPopupMenu,aItemCommand,nItemId,bDeleteChildren,bDeleteChildren); 392cdf0e10cSrcweir } 393cdf0e10cSrcweir else 394cdf0e10cSrcweir { 395cdf0e10cSrcweir if ( pAddonMenu->GetItemType( i ) != MENUITEM_SEPARATOR ) 396cdf0e10cSrcweir { 397cdf0e10cSrcweir MenuConfiguration::Attributes* pAddonAttributes = (MenuConfiguration::Attributes *)(pAddonMenu->GetUserValue( nItemId )); 398cdf0e10cSrcweir REFERENCE< XDISPATCH > aXDispatchRef; 399cdf0e10cSrcweir MenuItemHandler* pMenuItemHandler = new MenuItemHandler( nItemId, NULL, aXDispatchRef ); 400cdf0e10cSrcweir 401cdf0e10cSrcweir if ( pAddonAttributes ) 402cdf0e10cSrcweir { 403cdf0e10cSrcweir // read additional attributes from attributes struct and AddonMenu implementation will delete all attributes itself!! 404cdf0e10cSrcweir pMenuItemHandler->aTargetFrame = pAddonAttributes->aTargetFrame; 405cdf0e10cSrcweir } 406cdf0e10cSrcweir 407cdf0e10cSrcweir m_aMenuItemHandlerVector.push_back( pMenuItemHandler ); 408cdf0e10cSrcweir } 409cdf0e10cSrcweir } 410cdf0e10cSrcweir } 411cdf0e10cSrcweir 412cdf0e10cSrcweir SetHdl(); 413cdf0e10cSrcweir } 414cdf0e10cSrcweir #endif 415cdf0e10cSrcweir 416cdf0e10cSrcweir void MenuManager::SetHdl() 417cdf0e10cSrcweir { 418cdf0e10cSrcweir m_pVCLMenu->SetHighlightHdl( LINK( this, MenuManager, Highlight )); 419cdf0e10cSrcweir m_pVCLMenu->SetActivateHdl( LINK( this, MenuManager, Activate )); 420cdf0e10cSrcweir m_pVCLMenu->SetDeactivateHdl( LINK( this, MenuManager, Deactivate )); 421cdf0e10cSrcweir m_pVCLMenu->SetSelectHdl( LINK( this, MenuManager, Select )); 422cdf0e10cSrcweir 423cdf0e10cSrcweir if ( mxServiceFactory.is() ) 424cdf0e10cSrcweir m_xURLTransformer.set( mxServiceFactory->createInstance(SERVICENAME_URLTRANSFORMER),UNO_QUERY ); 425cdf0e10cSrcweir } 426cdf0e10cSrcweir 427cdf0e10cSrcweir MenuManager::~MenuManager() 428cdf0e10cSrcweir { 429cdf0e10cSrcweir std::vector< MenuItemHandler* >::iterator p; 430cdf0e10cSrcweir for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); p++ ) 431cdf0e10cSrcweir { 432cdf0e10cSrcweir MenuItemHandler* pItemHandler = *p; 433cdf0e10cSrcweir pItemHandler->xMenuItemDispatch.clear(); 434cdf0e10cSrcweir if ( pItemHandler->pSubMenuManager ) 435cdf0e10cSrcweir SAL_STATIC_CAST( ::com::sun::star::uno::XInterface*, (OWeakObject*)pItemHandler->pSubMenuManager )->release(); 436cdf0e10cSrcweir delete pItemHandler; 437cdf0e10cSrcweir } 438cdf0e10cSrcweir 439cdf0e10cSrcweir if ( m_bDeleteMenu ) 440cdf0e10cSrcweir delete m_pVCLMenu; 441cdf0e10cSrcweir } 442cdf0e10cSrcweir 443cdf0e10cSrcweir 444cdf0e10cSrcweir MenuManager::MenuItemHandler* MenuManager::GetMenuItemHandler( sal_uInt16 nItemId ) 445cdf0e10cSrcweir { 446cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 447cdf0e10cSrcweir 448cdf0e10cSrcweir std::vector< MenuItemHandler* >::iterator p; 449cdf0e10cSrcweir for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); p++ ) 450cdf0e10cSrcweir { 451cdf0e10cSrcweir MenuItemHandler* pItemHandler = *p; 452cdf0e10cSrcweir if ( pItemHandler->nItemId == nItemId ) 453cdf0e10cSrcweir return pItemHandler; 454cdf0e10cSrcweir } 455cdf0e10cSrcweir 456cdf0e10cSrcweir return 0; 457cdf0e10cSrcweir } 458cdf0e10cSrcweir 459cdf0e10cSrcweir 460cdf0e10cSrcweir void SAL_CALL MenuManager::statusChanged( const FEATURSTATEEVENT& Event ) 461cdf0e10cSrcweir throw ( RuntimeException ) 462cdf0e10cSrcweir { 463cdf0e10cSrcweir ::rtl::OUString aFeatureURL = Event.FeatureURL.Complete; 464cdf0e10cSrcweir MenuItemHandler* pStatusChangedMenu = NULL; 465cdf0e10cSrcweir 466cdf0e10cSrcweir { 467cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 468cdf0e10cSrcweir 469cdf0e10cSrcweir std::vector< MenuItemHandler* >::iterator p; 470cdf0e10cSrcweir for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); p++ ) 471cdf0e10cSrcweir { 472cdf0e10cSrcweir MenuItemHandler* pMenuItemHandler = *p; 473cdf0e10cSrcweir if ( pMenuItemHandler->aMenuItemURL == aFeatureURL ) 474cdf0e10cSrcweir { 475cdf0e10cSrcweir pStatusChangedMenu = pMenuItemHandler; 476cdf0e10cSrcweir break; 477cdf0e10cSrcweir } 478cdf0e10cSrcweir } 479cdf0e10cSrcweir } 480cdf0e10cSrcweir 481cdf0e10cSrcweir if ( pStatusChangedMenu ) 482cdf0e10cSrcweir { 483cdf0e10cSrcweir OGuard aSolarGuard( Application::GetSolarMutex() ); 484cdf0e10cSrcweir { 485cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 486cdf0e10cSrcweir 487cdf0e10cSrcweir sal_Bool bSetCheckmark = sal_False; 488cdf0e10cSrcweir sal_Bool bCheckmark = sal_False; 489cdf0e10cSrcweir sal_Bool bMenuItemEnabled = m_pVCLMenu->IsItemEnabled( pStatusChangedMenu->nItemId ); 490cdf0e10cSrcweir 491cdf0e10cSrcweir if ( Event.IsEnabled != bMenuItemEnabled ) 492cdf0e10cSrcweir m_pVCLMenu->EnableItem( pStatusChangedMenu->nItemId, Event.IsEnabled ); 493cdf0e10cSrcweir 494cdf0e10cSrcweir if ( Event.State >>= bCheckmark ) 495cdf0e10cSrcweir bSetCheckmark = sal_True; 496cdf0e10cSrcweir 497cdf0e10cSrcweir if ( bSetCheckmark ) 498cdf0e10cSrcweir m_pVCLMenu->CheckItem( pStatusChangedMenu->nItemId, bCheckmark ); 499cdf0e10cSrcweir } 500cdf0e10cSrcweir 501cdf0e10cSrcweir if ( Event.Requery ) 502cdf0e10cSrcweir { 503cdf0e10cSrcweir URL aTargetURL; 504cdf0e10cSrcweir aTargetURL.Complete = pStatusChangedMenu->aMenuItemURL; 505cdf0e10cSrcweir 506cdf0e10cSrcweir // #110897# 507cdf0e10cSrcweir m_xURLTransformer->parseStrict( aTargetURL ); 508cdf0e10cSrcweir 509cdf0e10cSrcweir REFERENCE< XDISPATCHPROVIDER > xDispatchProvider( m_xFrame, UNO_QUERY ); 510cdf0e10cSrcweir REFERENCE< XDISPATCH > xMenuItemDispatch = xDispatchProvider->queryDispatch( 511cdf0e10cSrcweir aTargetURL, ::rtl::OUString(), 0 ); 512cdf0e10cSrcweir 513cdf0e10cSrcweir if ( xMenuItemDispatch.is() ) 514cdf0e10cSrcweir { 515cdf0e10cSrcweir pStatusChangedMenu->xMenuItemDispatch = xMenuItemDispatch; 516cdf0e10cSrcweir pStatusChangedMenu->aMenuItemURL = aTargetURL.Complete; 517cdf0e10cSrcweir xMenuItemDispatch->addStatusListener( SAL_STATIC_CAST( XSTATUSLISTENER*, this ), aTargetURL ); 518cdf0e10cSrcweir } 519cdf0e10cSrcweir } 520cdf0e10cSrcweir } 521cdf0e10cSrcweir } 522cdf0e10cSrcweir 523cdf0e10cSrcweir 524cdf0e10cSrcweir void MenuManager::RemoveListener() 525cdf0e10cSrcweir { 526cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 527cdf0e10cSrcweir ClearMenuDispatch(); 528cdf0e10cSrcweir } 529cdf0e10cSrcweir 530cdf0e10cSrcweir void MenuManager::ClearMenuDispatch(const EVENTOBJECT& Source,bool _bRemoveOnly) 531cdf0e10cSrcweir { 532cdf0e10cSrcweir // disposing called from parent dispatcher 533cdf0e10cSrcweir // remove all listener to prepare shutdown 534cdf0e10cSrcweir 535cdf0e10cSrcweir // #110897# 536cdf0e10cSrcweir std::vector< MenuItemHandler* >::iterator p; 537cdf0e10cSrcweir for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); p++ ) 538cdf0e10cSrcweir { 539cdf0e10cSrcweir MenuItemHandler* pItemHandler = *p; 540cdf0e10cSrcweir if ( pItemHandler->xMenuItemDispatch.is() ) 541cdf0e10cSrcweir { 542cdf0e10cSrcweir URL aTargetURL; 543cdf0e10cSrcweir aTargetURL.Complete = pItemHandler->aMenuItemURL; 544cdf0e10cSrcweir m_xURLTransformer->parseStrict( aTargetURL ); 545cdf0e10cSrcweir 546cdf0e10cSrcweir pItemHandler->xMenuItemDispatch->removeStatusListener( 547cdf0e10cSrcweir SAL_STATIC_CAST( XSTATUSLISTENER*, this ), aTargetURL ); 548cdf0e10cSrcweir } 549cdf0e10cSrcweir 550cdf0e10cSrcweir pItemHandler->xMenuItemDispatch.clear(); 551cdf0e10cSrcweir if ( pItemHandler->pSubMenuManager ) 552cdf0e10cSrcweir { 553cdf0e10cSrcweir if ( _bRemoveOnly ) 554cdf0e10cSrcweir pItemHandler->pSubMenuManager->RemoveListener(); 555cdf0e10cSrcweir else 556cdf0e10cSrcweir pItemHandler->pSubMenuManager->disposing( Source ); 557cdf0e10cSrcweir } 558cdf0e10cSrcweir } 559cdf0e10cSrcweir } 560cdf0e10cSrcweir 561cdf0e10cSrcweir 562cdf0e10cSrcweir void SAL_CALL MenuManager::disposing( const EVENTOBJECT& Source ) throw ( RUNTIMEEXCEPTION ) 563cdf0e10cSrcweir { 564cdf0e10cSrcweir if ( Source.Source == m_xFrame ) 565cdf0e10cSrcweir { 566cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 567cdf0e10cSrcweir ClearMenuDispatch(Source,false); 568cdf0e10cSrcweir } 569cdf0e10cSrcweir else 570cdf0e10cSrcweir { 571cdf0e10cSrcweir // disposing called from menu item dispatcher, remove listener 572cdf0e10cSrcweir MenuItemHandler* pMenuItemDisposing = NULL; 573cdf0e10cSrcweir 574cdf0e10cSrcweir { 575cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 576cdf0e10cSrcweir 577cdf0e10cSrcweir std::vector< MenuItemHandler* >::iterator p; 578cdf0e10cSrcweir for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); p++ ) 579cdf0e10cSrcweir { 580cdf0e10cSrcweir MenuItemHandler* pMenuItemHandler = *p; 581cdf0e10cSrcweir if ( pMenuItemHandler->xMenuItemDispatch == Source.Source ) 582cdf0e10cSrcweir { 583cdf0e10cSrcweir pMenuItemDisposing = pMenuItemHandler; 584cdf0e10cSrcweir break; 585cdf0e10cSrcweir } 586cdf0e10cSrcweir } 587cdf0e10cSrcweir 588cdf0e10cSrcweir if ( pMenuItemDisposing ) 589cdf0e10cSrcweir { 590cdf0e10cSrcweir URL aTargetURL; 591cdf0e10cSrcweir aTargetURL.Complete = pMenuItemDisposing->aMenuItemURL; 592cdf0e10cSrcweir 593cdf0e10cSrcweir // #110897# 594cdf0e10cSrcweir m_xURLTransformer->parseStrict( aTargetURL ); 595cdf0e10cSrcweir 596cdf0e10cSrcweir pMenuItemDisposing->xMenuItemDispatch->removeStatusListener(SAL_STATIC_CAST( XSTATUSLISTENER*, this ), aTargetURL ); 597cdf0e10cSrcweir pMenuItemDisposing->xMenuItemDispatch.clear(); 598cdf0e10cSrcweir } 599cdf0e10cSrcweir } 600cdf0e10cSrcweir } 601cdf0e10cSrcweir } 602cdf0e10cSrcweir 603cdf0e10cSrcweir 604cdf0e10cSrcweir void MenuManager::UpdateSpecialFileMenu( Menu* pMenu ) 605cdf0e10cSrcweir { 606cdf0e10cSrcweir // update picklist 607cdf0e10cSrcweir Sequence< Sequence< PropertyValue > > aHistoryList = SvtHistoryOptions().GetList( ePICKLIST ); 608cdf0e10cSrcweir ::std::vector< MenuItemHandler* > aNewPickVector; 609cdf0e10cSrcweir Reference< XStringWidth > xStringLength( new StringLength ); 610cdf0e10cSrcweir 611cdf0e10cSrcweir sal_uInt16 nPickItemId = START_ITEMID_PICKLIST; 612cdf0e10cSrcweir int nPickListMenuItems = ( aHistoryList.getLength() > 99 ) ? 99 : aHistoryList.getLength(); 613cdf0e10cSrcweir 614cdf0e10cSrcweir aNewPickVector.reserve(nPickListMenuItems); 615cdf0e10cSrcweir for ( int i = 0; i < nPickListMenuItems; i++ ) 616cdf0e10cSrcweir { 617cdf0e10cSrcweir Sequence< PropertyValue > aPickListEntry = aHistoryList[i]; 618cdf0e10cSrcweir 619cdf0e10cSrcweir REFERENCE< XDISPATCH > aXDispatchRef; 620cdf0e10cSrcweir MenuItemHandler* pNewMenuItemHandler = new MenuItemHandler( 621cdf0e10cSrcweir nPickItemId++, 622cdf0e10cSrcweir NULL, 623cdf0e10cSrcweir aXDispatchRef ); 624cdf0e10cSrcweir 625cdf0e10cSrcweir for ( int j = 0; j < aPickListEntry.getLength(); j++ ) 626cdf0e10cSrcweir { 627cdf0e10cSrcweir Any a = aPickListEntry[j].Value; 628cdf0e10cSrcweir 629cdf0e10cSrcweir if ( aPickListEntry[j].Name == HISTORY_PROPERTYNAME_URL ) 630cdf0e10cSrcweir a >>= pNewMenuItemHandler->aMenuItemURL; 631cdf0e10cSrcweir else if ( aPickListEntry[j].Name == HISTORY_PROPERTYNAME_FILTER ) 632cdf0e10cSrcweir a >>= pNewMenuItemHandler->aFilter; 633cdf0e10cSrcweir else if ( aPickListEntry[j].Name == HISTORY_PROPERTYNAME_TITLE ) 634cdf0e10cSrcweir a >>= pNewMenuItemHandler->aTitle; 635cdf0e10cSrcweir else if ( aPickListEntry[j].Name == HISTORY_PROPERTYNAME_PASSWORD ) 636cdf0e10cSrcweir a >>= pNewMenuItemHandler->aPassword; 637cdf0e10cSrcweir } 638cdf0e10cSrcweir 639cdf0e10cSrcweir aNewPickVector.push_back( pNewMenuItemHandler ); 640cdf0e10cSrcweir } 641cdf0e10cSrcweir 642cdf0e10cSrcweir if ( !aNewPickVector.empty() ) 643cdf0e10cSrcweir { 644cdf0e10cSrcweir URL aTargetURL; 645cdf0e10cSrcweir REFERENCE< XDISPATCHPROVIDER > xDispatchProvider( m_xFrame, UNO_QUERY ); 646cdf0e10cSrcweir 647cdf0e10cSrcweir // #110897# 648cdf0e10cSrcweir REFERENCE< XDISPATCH > xMenuItemDispatch; 649cdf0e10cSrcweir 650cdf0e10cSrcweir static const ::rtl::OUString s_sDefault(RTL_CONSTASCII_USTRINGPARAM("_default")); 651cdf0e10cSrcweir // query for dispatcher 652cdf0e10cSrcweir std::vector< MenuItemHandler* >::iterator p; 653cdf0e10cSrcweir for ( p = aNewPickVector.begin(); p != aNewPickVector.end(); p++ ) 654cdf0e10cSrcweir { 655cdf0e10cSrcweir MenuItemHandler* pMenuItemHandler = *p; 656cdf0e10cSrcweir 657cdf0e10cSrcweir aTargetURL.Complete = pMenuItemHandler->aMenuItemURL; 658cdf0e10cSrcweir m_xURLTransformer->parseStrict( aTargetURL ); 659cdf0e10cSrcweir 660cdf0e10cSrcweir if ( !xMenuItemDispatch.is() ) 661cdf0e10cSrcweir { 662cdf0e10cSrcweir // attention: this code assume that "_blank" can only be consumed by desktop service 663cdf0e10cSrcweir xMenuItemDispatch = xDispatchProvider->queryDispatch( aTargetURL, s_sDefault, 0 ); 664cdf0e10cSrcweir } 665cdf0e10cSrcweir 666cdf0e10cSrcweir if ( xMenuItemDispatch.is() ) 667cdf0e10cSrcweir { 668cdf0e10cSrcweir pMenuItemHandler->xMenuItemDispatch = xMenuItemDispatch; 669cdf0e10cSrcweir pMenuItemHandler->aMenuItemURL = aTargetURL.Complete; 670cdf0e10cSrcweir } 671cdf0e10cSrcweir } 672cdf0e10cSrcweir 673cdf0e10cSrcweir { 674cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 675cdf0e10cSrcweir 676cdf0e10cSrcweir int nRemoveItemCount = 0; 677cdf0e10cSrcweir int nItemCount = pMenu->GetItemCount(); 678cdf0e10cSrcweir 679cdf0e10cSrcweir if ( nItemCount > 0 ) 680cdf0e10cSrcweir { 681cdf0e10cSrcweir // remove all old picklist entries from menu 682cdf0e10cSrcweir sal_uInt16 nPos = pMenu->GetItemPos( START_ITEMID_PICKLIST ); 683cdf0e10cSrcweir for ( sal_uInt16 n = nPos; n < pMenu->GetItemCount(); ) 684cdf0e10cSrcweir { 685cdf0e10cSrcweir pMenu->RemoveItem( n ); 686cdf0e10cSrcweir ++nRemoveItemCount; 687cdf0e10cSrcweir } 688cdf0e10cSrcweir 689cdf0e10cSrcweir if ( pMenu->GetItemType( pMenu->GetItemCount()-1 ) == MENUITEM_SEPARATOR ) 690cdf0e10cSrcweir pMenu->RemoveItem( pMenu->GetItemCount()-1 ); 691cdf0e10cSrcweir 692cdf0e10cSrcweir // remove all old picklist entries from menu handler 693cdf0e10cSrcweir if ( nRemoveItemCount > 0 ) 694cdf0e10cSrcweir { 695cdf0e10cSrcweir for( sal_uInt32 nIndex = m_aMenuItemHandlerVector.size() - nRemoveItemCount; 696cdf0e10cSrcweir nIndex < m_aMenuItemHandlerVector.size(); ) 697cdf0e10cSrcweir { 698cdf0e10cSrcweir delete m_aMenuItemHandlerVector.at( nIndex ); 699cdf0e10cSrcweir m_aMenuItemHandlerVector.erase( m_aMenuItemHandlerVector.begin() + nIndex ); 700cdf0e10cSrcweir } 701cdf0e10cSrcweir } 702cdf0e10cSrcweir } 703cdf0e10cSrcweir 704cdf0e10cSrcweir // append new picklist menu entries 705cdf0e10cSrcweir aNewPickVector.reserve(aNewPickVector.size()); 706cdf0e10cSrcweir pMenu->InsertSeparator(); 707cdf0e10cSrcweir const sal_uInt32 nCount = aNewPickVector.size(); 708cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < nCount; i++ ) 709cdf0e10cSrcweir { 710cdf0e10cSrcweir char menuShortCut[5] = "~n: "; 711cdf0e10cSrcweir 712cdf0e10cSrcweir ::rtl::OUString aMenuShortCut; 713cdf0e10cSrcweir if ( i <= 9 ) 714cdf0e10cSrcweir { 715cdf0e10cSrcweir if ( i == 9 ) 716cdf0e10cSrcweir aMenuShortCut = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "1~0: " )); 717cdf0e10cSrcweir else 718cdf0e10cSrcweir { 719cdf0e10cSrcweir menuShortCut[1] = (char)( '1' + i ); 720cdf0e10cSrcweir aMenuShortCut = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( menuShortCut )); 721cdf0e10cSrcweir } 722cdf0e10cSrcweir } 723cdf0e10cSrcweir else 724cdf0e10cSrcweir { 725cdf0e10cSrcweir aMenuShortCut = rtl::OUString::valueOf((sal_Int32)( i + 1 )); 726cdf0e10cSrcweir aMenuShortCut += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ": " )); 727cdf0e10cSrcweir } 728cdf0e10cSrcweir 729cdf0e10cSrcweir // Abbreviate URL 730cdf0e10cSrcweir rtl::OUString aURLString( aNewPickVector.at( i )->aMenuItemURL ); 731cdf0e10cSrcweir rtl::OUString aTipHelpText; 732cdf0e10cSrcweir rtl::OUString aMenuTitle; 733cdf0e10cSrcweir INetURLObject aURL( aURLString ); 734cdf0e10cSrcweir 735cdf0e10cSrcweir if ( aURL.GetProtocol() == INET_PROT_FILE ) 736cdf0e10cSrcweir { 737cdf0e10cSrcweir // Do handle file URL differently => convert it to a system 738cdf0e10cSrcweir // path and abbreviate it with a special function: 739cdf0e10cSrcweir String aFileSystemPath( aURL.getFSysPath( INetURLObject::FSYS_DETECT ) ); 740cdf0e10cSrcweir 741cdf0e10cSrcweir ::rtl::OUString aSystemPath( aFileSystemPath ); 742cdf0e10cSrcweir ::rtl::OUString aCompactedSystemPath; 743cdf0e10cSrcweir 744cdf0e10cSrcweir aTipHelpText = aSystemPath; 745cdf0e10cSrcweir oslFileError nError = osl_abbreviateSystemPath( aSystemPath.pData, &aCompactedSystemPath.pData, 46, NULL ); 746cdf0e10cSrcweir if ( !nError ) 747cdf0e10cSrcweir aMenuTitle = String( aCompactedSystemPath ); 748cdf0e10cSrcweir else 749cdf0e10cSrcweir aMenuTitle = aSystemPath; 750cdf0e10cSrcweir } 751cdf0e10cSrcweir else 752cdf0e10cSrcweir { 753cdf0e10cSrcweir // Use INetURLObject to abbreviate all other URLs 754cdf0e10cSrcweir String aShortURL; 755cdf0e10cSrcweir aShortURL = aURL.getAbbreviated( xStringLength, 46, INetURLObject::DECODE_UNAMBIGUOUS ); 756cdf0e10cSrcweir aMenuTitle += aShortURL; 757cdf0e10cSrcweir aTipHelpText = aURLString; 758cdf0e10cSrcweir } 759cdf0e10cSrcweir 760cdf0e10cSrcweir ::rtl::OUString aTitle( aMenuShortCut + aMenuTitle ); 761cdf0e10cSrcweir 762cdf0e10cSrcweir MenuItemHandler* pMenuItemHandler = aNewPickVector.at( i ); 763cdf0e10cSrcweir pMenu->InsertItem( pMenuItemHandler->nItemId, aTitle ); 764cdf0e10cSrcweir pMenu->SetTipHelpText( pMenuItemHandler->nItemId, aTipHelpText ); 765cdf0e10cSrcweir m_aMenuItemHandlerVector.push_back( pMenuItemHandler ); 766cdf0e10cSrcweir } 767cdf0e10cSrcweir } 768cdf0e10cSrcweir } 769cdf0e10cSrcweir } 770cdf0e10cSrcweir 771cdf0e10cSrcweir void MenuManager::UpdateSpecialWindowMenu( Menu* pMenu,const Reference< XMultiServiceFactory >& xServiceFactory,framework::IMutex& _rMutex ) 772cdf0e10cSrcweir { 773cdf0e10cSrcweir // update window list 774cdf0e10cSrcweir ::std::vector< ::rtl::OUString > aNewWindowListVector; 775cdf0e10cSrcweir 776cdf0e10cSrcweir // #110897# 777cdf0e10cSrcweir Reference< XDesktop > xDesktop( xServiceFactory->createInstance( SERVICENAME_DESKTOP ), UNO_QUERY ); 778cdf0e10cSrcweir 779cdf0e10cSrcweir sal_uInt16 nActiveItemId = 0; 780cdf0e10cSrcweir sal_uInt16 nItemId = START_ITEMID_WINDOWLIST; 781cdf0e10cSrcweir 782cdf0e10cSrcweir if ( xDesktop.is() ) 783cdf0e10cSrcweir { 784cdf0e10cSrcweir Reference< XFramesSupplier > xTasksSupplier( xDesktop, UNO_QUERY ); 785cdf0e10cSrcweir Reference< XFrame > xCurrentFrame = xDesktop->getCurrentFrame(); 786cdf0e10cSrcweir Reference< XIndexAccess > xList( xTasksSupplier->getFrames(), UNO_QUERY ); 787cdf0e10cSrcweir sal_Int32 nCount = xList->getCount(); 788cdf0e10cSrcweir aNewWindowListVector.reserve(nCount); 789cdf0e10cSrcweir for (sal_Int32 i=0; i<nCount; ++i ) 790cdf0e10cSrcweir { 791cdf0e10cSrcweir Reference< XFrame > xFrame; 792cdf0e10cSrcweir xList->getByIndex(i) >>= xFrame; 793cdf0e10cSrcweir 794cdf0e10cSrcweir if (xFrame.is()) 795cdf0e10cSrcweir { 796cdf0e10cSrcweir if ( xFrame == xCurrentFrame ) 797cdf0e10cSrcweir nActiveItemId = nItemId; 798cdf0e10cSrcweir 799cdf0e10cSrcweir Window* pWin = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() ); 800cdf0e10cSrcweir if ( pWin && pWin->IsVisible() ) 801cdf0e10cSrcweir { 802cdf0e10cSrcweir aNewWindowListVector.push_back( pWin->GetText() ); 803cdf0e10cSrcweir ++nItemId; 804cdf0e10cSrcweir } 805cdf0e10cSrcweir } 806cdf0e10cSrcweir } 807cdf0e10cSrcweir } 808cdf0e10cSrcweir 809cdf0e10cSrcweir { 810cdf0e10cSrcweir ResetableGuard aGuard( _rMutex ); 811cdf0e10cSrcweir 812cdf0e10cSrcweir int nItemCount = pMenu->GetItemCount(); 813cdf0e10cSrcweir 814cdf0e10cSrcweir if ( nItemCount > 0 ) 815cdf0e10cSrcweir { 816cdf0e10cSrcweir // remove all old window list entries from menu 817cdf0e10cSrcweir sal_uInt16 nPos = pMenu->GetItemPos( START_ITEMID_WINDOWLIST ); 818cdf0e10cSrcweir for ( sal_uInt16 n = nPos; n < pMenu->GetItemCount(); ) 819cdf0e10cSrcweir pMenu->RemoveItem( n ); 820cdf0e10cSrcweir 821cdf0e10cSrcweir if ( pMenu->GetItemType( pMenu->GetItemCount()-1 ) == MENUITEM_SEPARATOR ) 822cdf0e10cSrcweir pMenu->RemoveItem( pMenu->GetItemCount()-1 ); 823cdf0e10cSrcweir } 824cdf0e10cSrcweir 825cdf0e10cSrcweir if ( !aNewWindowListVector.empty() ) 826cdf0e10cSrcweir { 827cdf0e10cSrcweir // append new window list entries to menu 828cdf0e10cSrcweir pMenu->InsertSeparator(); 829cdf0e10cSrcweir nItemId = START_ITEMID_WINDOWLIST; 830cdf0e10cSrcweir const sal_uInt32 nCount = aNewWindowListVector.size(); 831cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < nCount; i++ ) 832cdf0e10cSrcweir { 833cdf0e10cSrcweir pMenu->InsertItem( nItemId, aNewWindowListVector.at( i ), MIB_RADIOCHECK ); 834cdf0e10cSrcweir if ( nItemId == nActiveItemId ) 835cdf0e10cSrcweir pMenu->CheckItem( nItemId ); 836cdf0e10cSrcweir ++nItemId; 837cdf0e10cSrcweir } 838cdf0e10cSrcweir } 839cdf0e10cSrcweir } 840cdf0e10cSrcweir } 841cdf0e10cSrcweir 842cdf0e10cSrcweir 843cdf0e10cSrcweir void MenuManager::CreatePicklistArguments( Sequence< PropertyValue >& aArgsList, const MenuItemHandler* pMenuItemHandler ) 844cdf0e10cSrcweir { 845cdf0e10cSrcweir int NUM_OF_PICKLIST_ARGS = 3; 846cdf0e10cSrcweir 847cdf0e10cSrcweir Any a; 848cdf0e10cSrcweir aArgsList.realloc( NUM_OF_PICKLIST_ARGS ); 849cdf0e10cSrcweir 850cdf0e10cSrcweir aArgsList[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FileName" )); 851cdf0e10cSrcweir a <<= pMenuItemHandler->aMenuItemURL; 852cdf0e10cSrcweir aArgsList[0].Value = a; 853cdf0e10cSrcweir 854cdf0e10cSrcweir aArgsList[1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Referer" )); 855cdf0e10cSrcweir a <<= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SFX_REFERER_USER )); 856cdf0e10cSrcweir aArgsList[1].Value = a; 857cdf0e10cSrcweir 858cdf0e10cSrcweir ::rtl::OUString aFilter( pMenuItemHandler->aFilter ); 859cdf0e10cSrcweir 860cdf0e10cSrcweir sal_Int32 nPos = aFilter.indexOf( '|' ); 861cdf0e10cSrcweir if ( nPos >= 0 ) 862cdf0e10cSrcweir { 863cdf0e10cSrcweir ::rtl::OUString aFilterOptions; 864cdf0e10cSrcweir 865cdf0e10cSrcweir if ( nPos < ( aFilter.getLength() - 1 ) ) 866cdf0e10cSrcweir aFilterOptions = aFilter.copy( nPos+1 ); 867cdf0e10cSrcweir 868cdf0e10cSrcweir aArgsList[2].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterOptions" )); 869cdf0e10cSrcweir a <<= aFilterOptions; 870cdf0e10cSrcweir aArgsList[2].Value = a; 871cdf0e10cSrcweir 872cdf0e10cSrcweir aFilter = aFilter.copy( 0, nPos-1 ); 873cdf0e10cSrcweir aArgsList.realloc( ++NUM_OF_PICKLIST_ARGS ); 874cdf0e10cSrcweir } 875cdf0e10cSrcweir 876cdf0e10cSrcweir aArgsList[NUM_OF_PICKLIST_ARGS-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" )); 877cdf0e10cSrcweir a <<= aFilter; 878cdf0e10cSrcweir aArgsList[NUM_OF_PICKLIST_ARGS-1].Value = a; 879cdf0e10cSrcweir } 880cdf0e10cSrcweir 881cdf0e10cSrcweir 882cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 883cdf0e10cSrcweir // vcl handler 884cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 885cdf0e10cSrcweir 886cdf0e10cSrcweir IMPL_LINK( MenuManager, Activate, Menu *, pMenu ) 887cdf0e10cSrcweir { 888cdf0e10cSrcweir if ( pMenu == m_pVCLMenu ) 889cdf0e10cSrcweir { 890cdf0e10cSrcweir // set/unset hiding disabled menu entries 891cdf0e10cSrcweir sal_Bool bDontHide = SvtMenuOptions().IsEntryHidingEnabled(); 892cdf0e10cSrcweir const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings(); 893cdf0e10cSrcweir sal_Bool bShowMenuImages = rSettings.GetUseImagesInMenus(); 894cdf0e10cSrcweir 895cdf0e10cSrcweir sal_uInt16 nFlag = pMenu->GetMenuFlags(); 896cdf0e10cSrcweir if ( bDontHide ) 897cdf0e10cSrcweir nFlag &= ~MENU_FLAG_HIDEDISABLEDENTRIES; 898cdf0e10cSrcweir else 899cdf0e10cSrcweir nFlag |= MENU_FLAG_HIDEDISABLEDENTRIES; 900cdf0e10cSrcweir pMenu->SetMenuFlags( nFlag ); 901cdf0e10cSrcweir 902cdf0e10cSrcweir if ( m_bActive ) 903cdf0e10cSrcweir return 0; 904cdf0e10cSrcweir 905cdf0e10cSrcweir m_bActive = sal_True; 906cdf0e10cSrcweir 907cdf0e10cSrcweir ::rtl::OUString aCommand( m_aMenuItemCommand ); 908cdf0e10cSrcweir if ( m_aMenuItemCommand.matchIgnoreAsciiCase( UNO_COMMAND, 0 )) 909cdf0e10cSrcweir { 910cdf0e10cSrcweir // Remove protocol part from command so we can use an easier comparision method 911cdf0e10cSrcweir aCommand = aCommand.copy( UNO_COMMAND.getLength() ); 912cdf0e10cSrcweir } 913cdf0e10cSrcweir 914cdf0e10cSrcweir if ( m_aMenuItemCommand == aSpecialFileMenu || 915cdf0e10cSrcweir m_aMenuItemCommand == aSlotSpecialFileMenu || 916cdf0e10cSrcweir aCommand == aSpecialFileCommand ) 917cdf0e10cSrcweir UpdateSpecialFileMenu( pMenu ); 918cdf0e10cSrcweir else if ( m_aMenuItemCommand == aSpecialWindowMenu || 919cdf0e10cSrcweir m_aMenuItemCommand == aSlotSpecialWindowMenu || 920cdf0e10cSrcweir aCommand == aSpecialWindowCommand ) 921cdf0e10cSrcweir UpdateSpecialWindowMenu( pMenu,getServiceFactory(),m_aLock ); 922cdf0e10cSrcweir 923cdf0e10cSrcweir // Check if some modes have changed so we have to update our menu images 924cdf0e10cSrcweir sal_Bool bIsHiContrast = rSettings.GetHighContrastMode(); 925cdf0e10cSrcweir 926cdf0e10cSrcweir if ( m_bWasHiContrast != bIsHiContrast || bShowMenuImages != m_bShowMenuImages ) 927cdf0e10cSrcweir { 928cdf0e10cSrcweir // The mode changed so we have to replace all images 929cdf0e10cSrcweir m_bWasHiContrast = bIsHiContrast; 930cdf0e10cSrcweir m_bShowMenuImages = bShowMenuImages; 931cdf0e10cSrcweir FillMenuImages(m_xFrame,pMenu,bIsHiContrast,bShowMenuImages); 932cdf0e10cSrcweir } 933cdf0e10cSrcweir 934cdf0e10cSrcweir if ( m_bInitialized ) 935cdf0e10cSrcweir return 0; 936cdf0e10cSrcweir else 937cdf0e10cSrcweir { 938cdf0e10cSrcweir URL aTargetURL; 939cdf0e10cSrcweir 940cdf0e10cSrcweir // #110897# 941cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 942cdf0e10cSrcweir 943cdf0e10cSrcweir REFERENCE< XDISPATCHPROVIDER > xDispatchProvider( m_xFrame, UNO_QUERY ); 944cdf0e10cSrcweir if ( xDispatchProvider.is() ) 945cdf0e10cSrcweir { 946cdf0e10cSrcweir std::vector< MenuItemHandler* >::iterator p; 947cdf0e10cSrcweir for ( p = m_aMenuItemHandlerVector.begin(); p != m_aMenuItemHandlerVector.end(); p++ ) 948cdf0e10cSrcweir { 949cdf0e10cSrcweir MenuItemHandler* pMenuItemHandler = *p; 950cdf0e10cSrcweir if ( pMenuItemHandler && 951cdf0e10cSrcweir pMenuItemHandler->pSubMenuManager == 0 && 952cdf0e10cSrcweir !pMenuItemHandler->xMenuItemDispatch.is() ) 953cdf0e10cSrcweir { 954cdf0e10cSrcweir // There is no dispatch mechanism for the special window list menu items, 955cdf0e10cSrcweir // because they are handled directly through XFrame->activate!!! 956cdf0e10cSrcweir if ( pMenuItemHandler->nItemId < START_ITEMID_WINDOWLIST || 957cdf0e10cSrcweir pMenuItemHandler->nItemId > END_ITEMID_WINDOWLIST ) 958cdf0e10cSrcweir { 959cdf0e10cSrcweir ::rtl::OUString aItemCommand = pMenu->GetItemCommand( pMenuItemHandler->nItemId ); 960cdf0e10cSrcweir if ( !aItemCommand.getLength() ) 961cdf0e10cSrcweir { 962cdf0e10cSrcweir const static ::rtl::OUString aSlotString( RTL_CONSTASCII_USTRINGPARAM( "slot:" )); 963cdf0e10cSrcweir aItemCommand = aSlotString; 964cdf0e10cSrcweir aItemCommand += ::rtl::OUString::valueOf( (sal_Int32)pMenuItemHandler->nItemId ); 965cdf0e10cSrcweir pMenu->SetItemCommand( pMenuItemHandler->nItemId, aItemCommand ); 966cdf0e10cSrcweir } 967cdf0e10cSrcweir 968cdf0e10cSrcweir aTargetURL.Complete = aItemCommand; 969cdf0e10cSrcweir 970cdf0e10cSrcweir m_xURLTransformer->parseStrict( aTargetURL ); 971cdf0e10cSrcweir 972cdf0e10cSrcweir REFERENCE< XDISPATCH > xMenuItemDispatch; 973cdf0e10cSrcweir if ( m_bIsBookmarkMenu ) 974cdf0e10cSrcweir xMenuItemDispatch = xDispatchProvider->queryDispatch( aTargetURL, pMenuItemHandler->aTargetFrame, 0 ); 975cdf0e10cSrcweir else 976cdf0e10cSrcweir xMenuItemDispatch = xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 ); 977cdf0e10cSrcweir 978cdf0e10cSrcweir if ( xMenuItemDispatch.is() ) 979cdf0e10cSrcweir { 980cdf0e10cSrcweir pMenuItemHandler->xMenuItemDispatch = xMenuItemDispatch; 981cdf0e10cSrcweir pMenuItemHandler->aMenuItemURL = aTargetURL.Complete; 982cdf0e10cSrcweir xMenuItemDispatch->addStatusListener( SAL_STATIC_CAST( XSTATUSLISTENER*, this ), aTargetURL ); 983cdf0e10cSrcweir } 984cdf0e10cSrcweir else 985cdf0e10cSrcweir pMenu->EnableItem( pMenuItemHandler->nItemId, sal_False ); 986cdf0e10cSrcweir } 987cdf0e10cSrcweir } 988cdf0e10cSrcweir } 989cdf0e10cSrcweir } 990cdf0e10cSrcweir } 991cdf0e10cSrcweir } 992cdf0e10cSrcweir 993cdf0e10cSrcweir return 1; 994cdf0e10cSrcweir } 995cdf0e10cSrcweir 996cdf0e10cSrcweir 997cdf0e10cSrcweir IMPL_LINK( MenuManager, Deactivate, Menu *, pMenu ) 998cdf0e10cSrcweir { 999cdf0e10cSrcweir if ( pMenu == m_pVCLMenu ) 1000cdf0e10cSrcweir m_bActive = sal_False; 1001cdf0e10cSrcweir 1002cdf0e10cSrcweir return 1; 1003cdf0e10cSrcweir } 1004cdf0e10cSrcweir 1005cdf0e10cSrcweir 1006cdf0e10cSrcweir IMPL_LINK( MenuManager, Select, Menu *, pMenu ) 1007cdf0e10cSrcweir { 1008cdf0e10cSrcweir URL aTargetURL; 1009cdf0e10cSrcweir Sequence<PropertyValue> aArgs; 1010cdf0e10cSrcweir REFERENCE< XDISPATCH > xDispatch; 1011cdf0e10cSrcweir 1012cdf0e10cSrcweir { 1013cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 1014cdf0e10cSrcweir 1015cdf0e10cSrcweir sal_uInt16 nCurItemId = pMenu->GetCurItemId(); 1016cdf0e10cSrcweir if ( pMenu == m_pVCLMenu && 1017cdf0e10cSrcweir pMenu->GetItemType( nCurItemId ) != MENUITEM_SEPARATOR ) 1018cdf0e10cSrcweir { 1019cdf0e10cSrcweir if ( nCurItemId >= START_ITEMID_WINDOWLIST && 1020cdf0e10cSrcweir nCurItemId <= END_ITEMID_WINDOWLIST ) 1021cdf0e10cSrcweir { 1022cdf0e10cSrcweir // window list menu item selected 1023cdf0e10cSrcweir 1024cdf0e10cSrcweir // #110897# 1025cdf0e10cSrcweir // Reference< XFramesSupplier > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance( 1026cdf0e10cSrcweir // DESKTOP_SERVICE ), UNO_QUERY ); 1027cdf0e10cSrcweir Reference< XFramesSupplier > xDesktop( getServiceFactory()->createInstance( SERVICENAME_DESKTOP ), UNO_QUERY ); 1028cdf0e10cSrcweir 1029cdf0e10cSrcweir if ( xDesktop.is() ) 1030cdf0e10cSrcweir { 1031cdf0e10cSrcweir sal_uInt16 nTaskId = START_ITEMID_WINDOWLIST; 1032cdf0e10cSrcweir Reference< XIndexAccess > xList( xDesktop->getFrames(), UNO_QUERY ); 1033cdf0e10cSrcweir sal_Int32 nCount = xList->getCount(); 1034cdf0e10cSrcweir for ( sal_Int32 i=0; i<nCount; ++i ) 1035cdf0e10cSrcweir { 1036cdf0e10cSrcweir Reference< XFrame > xFrame; 1037cdf0e10cSrcweir xList->getByIndex(i) >>= xFrame; 1038cdf0e10cSrcweir 1039cdf0e10cSrcweir if ( xFrame.is() && nTaskId == nCurItemId ) 1040cdf0e10cSrcweir { 1041cdf0e10cSrcweir Window* pWin = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() ); 1042cdf0e10cSrcweir pWin->GrabFocus(); 1043cdf0e10cSrcweir pWin->ToTop( TOTOP_RESTOREWHENMIN ); 1044cdf0e10cSrcweir break; 1045cdf0e10cSrcweir } 1046cdf0e10cSrcweir 1047cdf0e10cSrcweir nTaskId++; 1048cdf0e10cSrcweir } 1049cdf0e10cSrcweir } 1050cdf0e10cSrcweir } 1051cdf0e10cSrcweir else 1052cdf0e10cSrcweir { 1053cdf0e10cSrcweir MenuItemHandler* pMenuItemHandler = GetMenuItemHandler( nCurItemId ); 1054cdf0e10cSrcweir if ( pMenuItemHandler && pMenuItemHandler->xMenuItemDispatch.is() ) 1055cdf0e10cSrcweir { 1056cdf0e10cSrcweir aTargetURL.Complete = pMenuItemHandler->aMenuItemURL; 1057cdf0e10cSrcweir m_xURLTransformer->parseStrict( aTargetURL ); 1058cdf0e10cSrcweir 1059cdf0e10cSrcweir if ( nCurItemId >= START_ITEMID_PICKLIST && 1060cdf0e10cSrcweir nCurItemId < START_ITEMID_WINDOWLIST ) 1061cdf0e10cSrcweir { 1062cdf0e10cSrcweir // picklist menu item selected 1063cdf0e10cSrcweir CreatePicklistArguments( aArgs, pMenuItemHandler ); 1064cdf0e10cSrcweir } 1065cdf0e10cSrcweir else if ( m_bIsBookmarkMenu ) 1066cdf0e10cSrcweir { 1067cdf0e10cSrcweir // bookmark menu item selected 1068cdf0e10cSrcweir aArgs.realloc( 1 ); 1069cdf0e10cSrcweir aArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Referer" )); 1070cdf0e10cSrcweir aArgs[0].Value <<= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SFX_REFERER_USER )); 1071cdf0e10cSrcweir } 1072cdf0e10cSrcweir 1073cdf0e10cSrcweir xDispatch = pMenuItemHandler->xMenuItemDispatch; 1074cdf0e10cSrcweir } 1075cdf0e10cSrcweir } 1076cdf0e10cSrcweir } 1077cdf0e10cSrcweir } 1078cdf0e10cSrcweir 1079cdf0e10cSrcweir if ( xDispatch.is() ) 1080cdf0e10cSrcweir xDispatch->dispatch( aTargetURL, aArgs ); 1081cdf0e10cSrcweir 1082cdf0e10cSrcweir return 1; 1083cdf0e10cSrcweir } 1084cdf0e10cSrcweir 1085cdf0e10cSrcweir 1086cdf0e10cSrcweir IMPL_LINK( MenuManager, Highlight, Menu *, EMPTYARG ) 1087cdf0e10cSrcweir { 1088cdf0e10cSrcweir return 0; 1089cdf0e10cSrcweir } 1090cdf0e10cSrcweir 1091cdf0e10cSrcweir // #110897# 1092cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& MenuManager::getServiceFactory() 1093cdf0e10cSrcweir { 1094cdf0e10cSrcweir // #110897# 1095cdf0e10cSrcweir return mxServiceFactory; 1096cdf0e10cSrcweir } 1097cdf0e10cSrcweir 1098cdf0e10cSrcweir void MenuManager::AddMenu(PopupMenu* _pPopupMenu,const ::rtl::OUString& _sItemCommand,sal_uInt16 _nItemId,sal_Bool _bDelete,sal_Bool _bDeleteChildren) 1099cdf0e10cSrcweir { 1100cdf0e10cSrcweir MenuManager* pSubMenuManager = new MenuManager( getServiceFactory(), m_xFrame, _pPopupMenu, _bDelete, _bDeleteChildren ); 1101cdf0e10cSrcweir 1102cdf0e10cSrcweir // store menu item command as we later have to know which menu is active (see Activate handler) 1103cdf0e10cSrcweir pSubMenuManager->m_aMenuItemCommand = _sItemCommand; 1104cdf0e10cSrcweir 1105cdf0e10cSrcweir REFERENCE< XDISPATCH > aXDispatchRef; 1106cdf0e10cSrcweir MenuItemHandler* pMenuItemHandler = new MenuItemHandler( 1107cdf0e10cSrcweir _nItemId, 1108cdf0e10cSrcweir pSubMenuManager, 1109cdf0e10cSrcweir aXDispatchRef ); 1110cdf0e10cSrcweir m_aMenuItemHandlerVector.push_back( pMenuItemHandler ); 1111cdf0e10cSrcweir } 1112cdf0e10cSrcweir 1113cdf0e10cSrcweir sal_uInt16 MenuManager::FillItemCommand(::rtl::OUString& _rItemCommand,Menu* _pMenu,sal_uInt16 _nIndex) const 1114cdf0e10cSrcweir { 1115cdf0e10cSrcweir sal_uInt16 nItemId = _pMenu->GetItemId( _nIndex ); 1116cdf0e10cSrcweir 1117cdf0e10cSrcweir _rItemCommand = _pMenu->GetItemCommand( nItemId ); 1118cdf0e10cSrcweir if ( !_rItemCommand.getLength() ) 1119cdf0e10cSrcweir { 1120cdf0e10cSrcweir const static ::rtl::OUString aSlotString( RTL_CONSTASCII_USTRINGPARAM( "slot:" )); 1121cdf0e10cSrcweir _rItemCommand = aSlotString; 1122cdf0e10cSrcweir _rItemCommand += ::rtl::OUString::valueOf( (sal_Int32)nItemId ); 1123cdf0e10cSrcweir _pMenu->SetItemCommand( nItemId, _rItemCommand ); 1124cdf0e10cSrcweir } 1125cdf0e10cSrcweir return nItemId; 1126cdf0e10cSrcweir } 1127cdf0e10cSrcweir void MenuManager::FillMenuImages(Reference< XFrame >& _xFrame,Menu* _pMenu,sal_Bool bIsHiContrast,sal_Bool bShowMenuImages) 1128cdf0e10cSrcweir { 1129cdf0e10cSrcweir AddonsOptions aAddonOptions; 1130cdf0e10cSrcweir 1131cdf0e10cSrcweir for ( sal_uInt16 nPos = 0; nPos < _pMenu->GetItemCount(); nPos++ ) 1132cdf0e10cSrcweir { 1133cdf0e10cSrcweir sal_uInt16 nId = _pMenu->GetItemId( nPos ); 1134cdf0e10cSrcweir if ( _pMenu->GetItemType( nPos ) != MENUITEM_SEPARATOR ) 1135cdf0e10cSrcweir { 1136cdf0e10cSrcweir bool bTmpShowMenuImages( bShowMenuImages ); 1137cdf0e10cSrcweir MenuItemBits nBits = _pMenu->GetItemBits( nId ); 1138cdf0e10cSrcweir // overwrite the default? 1139cdf0e10cSrcweir if ( nBits ) 1140cdf0e10cSrcweir bTmpShowMenuImages = ( ( nBits & MIB_ICON ) == MIB_ICON ); 1141cdf0e10cSrcweir 1142cdf0e10cSrcweir if ( bTmpShowMenuImages ) 1143cdf0e10cSrcweir { 1144cdf0e10cSrcweir sal_Bool bImageSet = sal_False; 1145cdf0e10cSrcweir ::rtl::OUString aImageId; 1146cdf0e10cSrcweir 1147cdf0e10cSrcweir ::framework::MenuConfiguration::Attributes* pMenuAttributes = 1148cdf0e10cSrcweir (::framework::MenuConfiguration::Attributes*)_pMenu->GetUserValue( nId ); 1149cdf0e10cSrcweir 1150cdf0e10cSrcweir if ( pMenuAttributes ) 1151cdf0e10cSrcweir aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes 1152cdf0e10cSrcweir 1153cdf0e10cSrcweir if ( aImageId.getLength() > 0 ) 1154cdf0e10cSrcweir { 1155cdf0e10cSrcweir Image aImage = GetImageFromURL( _xFrame, aImageId, sal_False, bIsHiContrast ); 1156cdf0e10cSrcweir if ( !!aImage ) 1157cdf0e10cSrcweir { 1158cdf0e10cSrcweir bImageSet = sal_True; 1159cdf0e10cSrcweir _pMenu->SetItemImage( nId, aImage ); 1160cdf0e10cSrcweir } 1161cdf0e10cSrcweir } 1162cdf0e10cSrcweir 1163cdf0e10cSrcweir if ( !bImageSet ) 1164cdf0e10cSrcweir { 1165cdf0e10cSrcweir rtl::OUString aMenuItemCommand = _pMenu->GetItemCommand( nId ); 1166cdf0e10cSrcweir Image aImage = GetImageFromURL( _xFrame, aMenuItemCommand, sal_False, bIsHiContrast ); 1167cdf0e10cSrcweir if ( !aImage ) 1168cdf0e10cSrcweir aImage = aAddonOptions.GetImageFromURL( aMenuItemCommand, sal_False, bIsHiContrast ); 1169cdf0e10cSrcweir 1170cdf0e10cSrcweir _pMenu->SetItemImage( nId, aImage ); 1171cdf0e10cSrcweir } 1172cdf0e10cSrcweir } 1173cdf0e10cSrcweir else 1174cdf0e10cSrcweir _pMenu->SetItemImage( nId, Image() ); 1175cdf0e10cSrcweir } 1176cdf0e10cSrcweir } 1177cdf0e10cSrcweir } 1178cdf0e10cSrcweir } 1179