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