1*d119d52dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*d119d52dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*d119d52dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*d119d52dSAndrew Rist * distributed with this work for additional information 6*d119d52dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*d119d52dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*d119d52dSAndrew Rist * "License"); you may not use this file except in compliance 9*d119d52dSAndrew Rist * with the License. You may obtain a copy of the License at 10*d119d52dSAndrew Rist * 11*d119d52dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*d119d52dSAndrew Rist * 13*d119d52dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*d119d52dSAndrew Rist * software distributed under the License is distributed on an 15*d119d52dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*d119d52dSAndrew Rist * KIND, either express or implied. See the License for the 17*d119d52dSAndrew Rist * specific language governing permissions and limitations 18*d119d52dSAndrew Rist * under the License. 19*d119d52dSAndrew Rist * 20*d119d52dSAndrew Rist *************************************************************/ 21*d119d52dSAndrew Rist 22*d119d52dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sfx2.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <com/sun/star/embed/VerbDescriptor.hpp> 28cdf0e10cSrcweir #include <com/sun/star/embed/VerbAttributes.hpp> 29cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #ifdef SOLARIS 32cdf0e10cSrcweir // HACK: prevent conflict between STLPORT and Workshop headers on Solaris 8 33cdf0e10cSrcweir #include <ctime> 34cdf0e10cSrcweir #endif 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include <string> // HACK: prevent conflict between STLPORT and Workshop headers 37cdf0e10cSrcweir #include <cstdarg> // std::va_list 38cdf0e10cSrcweir 39cdf0e10cSrcweir #ifndef _POINTR_HXX //autogen 40cdf0e10cSrcweir #include <vcl/pointr.hxx> 41cdf0e10cSrcweir #endif 42cdf0e10cSrcweir #ifndef GCC 43cdf0e10cSrcweir #endif 44cdf0e10cSrcweir 45cdf0e10cSrcweir #include <unotools/streamwrap.hxx> 46cdf0e10cSrcweir #include <sfx2/objsh.hxx> 47cdf0e10cSrcweir #include <framework/menuconfiguration.hxx> 48cdf0e10cSrcweir #include <framework/addonmenu.hxx> 49cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 50cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx> 51cdf0e10cSrcweir #include <unotools/lingucfg.hxx> 52cdf0e10cSrcweir #include <tools/urlobj.hxx> 53cdf0e10cSrcweir #include <unotools/pathoptions.hxx> 54cdf0e10cSrcweir #include <svl/stritem.hxx> 55cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 56cdf0e10cSrcweir #include <osl/file.hxx> 57cdf0e10cSrcweir #include <vcl/graph.hxx> 58cdf0e10cSrcweir #include <svtools/filter.hxx> 59cdf0e10cSrcweir #include <svl/lngmisc.hxx> 60cdf0e10cSrcweir 61cdf0e10cSrcweir #include <sfx2/mnumgr.hxx> 62cdf0e10cSrcweir 63cdf0e10cSrcweir #define _SVSTDARR_USHORTS 64cdf0e10cSrcweir #include <svl/svstdarr.hxx> 65cdf0e10cSrcweir #include <svtools/menuoptions.hxx> 66cdf0e10cSrcweir 67cdf0e10cSrcweir #include "virtmenu.hxx" 68cdf0e10cSrcweir #include <sfx2/msg.hxx> 69cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 70cdf0e10cSrcweir #include <sfx2/minstack.hxx> 71cdf0e10cSrcweir #include <sfx2/app.hxx> 72cdf0e10cSrcweir #include "sfxtypes.hxx" 73cdf0e10cSrcweir #include <sfx2/bindings.hxx> 74cdf0e10cSrcweir #include "mnucfga.hxx" 75cdf0e10cSrcweir #include "sfx2/sfxresid.hxx" 76cdf0e10cSrcweir #include <sfx2/msgpool.hxx> 77cdf0e10cSrcweir #include <sfx2/sfx.hrc> 78cdf0e10cSrcweir #include "menu.hrc" 79cdf0e10cSrcweir #include <sfx2/viewfrm.hxx> 80cdf0e10cSrcweir #include <sfx2/viewsh.hxx> 81cdf0e10cSrcweir #include <sfx2/objface.hxx> 82cdf0e10cSrcweir #include "thessubmenu.hxx" 83cdf0e10cSrcweir 84cdf0e10cSrcweir 85cdf0e10cSrcweir static const sal_uInt16 nCompatVersion = 4; 86cdf0e10cSrcweir static const sal_uInt16 nVersion = 5; 87cdf0e10cSrcweir 88cdf0e10cSrcweir // static member initialization 89cdf0e10cSrcweir PopupMenu * SfxPopupMenuManager::pStaticThesSubMenu = NULL; 90cdf0e10cSrcweir 91cdf0e10cSrcweir using namespace com::sun::star; 92cdf0e10cSrcweir 93cdf0e10cSrcweir //========================================================================= 94cdf0e10cSrcweir 95cdf0e10cSrcweir DECL_PTRSTACK(SfxMenuCfgItemArrStack, SfxMenuCfgItemArr*, 4, 4 ); 96cdf0e10cSrcweir 97cdf0e10cSrcweir //------------------------------------------------------------------------- 98cdf0e10cSrcweir 99cdf0e10cSrcweir void TryToHideDisabledEntries_Impl( Menu* pMenu ) 100cdf0e10cSrcweir { 101cdf0e10cSrcweir DBG_ASSERT( pMenu, "invalid menu" ); 102cdf0e10cSrcweir if( SvtMenuOptions().IsEntryHidingEnabled() == sal_False ) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir pMenu->SetMenuFlags( pMenu->GetMenuFlags() | MENU_FLAG_HIDEDISABLEDENTRIES ); 105cdf0e10cSrcweir } 106cdf0e10cSrcweir } 107cdf0e10cSrcweir 108cdf0e10cSrcweir //------------------------------------------------------------------------- 109cdf0e10cSrcweir 110cdf0e10cSrcweir SfxMenuManager::SfxMenuManager( const ResId& rResId, SfxBindings &rBindings ) 111cdf0e10cSrcweir : pMenu(0), 112cdf0e10cSrcweir pOldMenu(0), 113cdf0e10cSrcweir pBindings(&rBindings), 114cdf0e10cSrcweir pResMgr(rResId.GetResMgr()), 115cdf0e10cSrcweir nType( rResId.GetId() ) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir bAddClipboardFuncs = sal_False; 118cdf0e10cSrcweir DBG_MEMTEST(); 119cdf0e10cSrcweir } 120cdf0e10cSrcweir 121cdf0e10cSrcweir //-------------------------------------------------------------------- 122cdf0e10cSrcweir 123cdf0e10cSrcweir SfxMenuManager::~SfxMenuManager() 124cdf0e10cSrcweir { 125cdf0e10cSrcweir DBG_MEMTEST(); 126cdf0e10cSrcweir pBindings->ENTERREGISTRATIONS(); 127cdf0e10cSrcweir delete pMenu; 128cdf0e10cSrcweir pBindings->LEAVEREGISTRATIONS(); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir 131cdf0e10cSrcweir //-------------------------------------------------------------------- 132cdf0e10cSrcweir 133cdf0e10cSrcweir void SfxMenuManager::Construct( SfxVirtualMenu& rMenu ) 134cdf0e10cSrcweir { 135cdf0e10cSrcweir DBG_MEMTEST(); 136cdf0e10cSrcweir pMenu = &rMenu; 137cdf0e10cSrcweir 138cdf0e10cSrcweir // set the handlers 139cdf0e10cSrcweir Menu *pSvMenu = pMenu->GetSVMenu(); 140cdf0e10cSrcweir pSvMenu->SetSelectHdl( LINK(this, SfxMenuManager, Select) ); 141cdf0e10cSrcweir TryToHideDisabledEntries_Impl( pSvMenu ); 142cdf0e10cSrcweir } 143cdf0e10cSrcweir 144cdf0e10cSrcweir //------------------------------------------------------------------------- 145cdf0e10cSrcweir void InsertVerbs_Impl( SfxBindings* pBindings, const com::sun::star::uno::Sequence < com::sun::star::embed::VerbDescriptor >& aVerbs, Menu* pMenu ) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir SfxViewShell *pView = pBindings->GetDispatcher()->GetFrame()->GetViewShell(); 148cdf0e10cSrcweir if ( pView && aVerbs.getLength() ) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir SfxObjectShell* pDoc = pView->GetObjectShell(); 151cdf0e10cSrcweir pMenu->InsertSeparator(); 152cdf0e10cSrcweir sal_uInt16 nr=0; 153cdf0e10cSrcweir for ( sal_uInt16 n = 0; n < aVerbs.getLength(); ++n ) 154cdf0e10cSrcweir { 155cdf0e10cSrcweir // check for ReadOnly verbs 156cdf0e10cSrcweir if ( pDoc->IsReadOnly() && !(aVerbs[n].VerbAttributes & embed::VerbAttributes::MS_VERBATTR_NEVERDIRTIES) ) 157cdf0e10cSrcweir continue; 158cdf0e10cSrcweir 159cdf0e10cSrcweir // check for verbs that shouldn't appear in the menu 160cdf0e10cSrcweir if ( !(aVerbs[n].VerbAttributes & embed::VerbAttributes::MS_VERBATTR_ONCONTAINERMENU) ) 161cdf0e10cSrcweir continue; 162cdf0e10cSrcweir 163cdf0e10cSrcweir // neue Id vergeben 164cdf0e10cSrcweir sal_uInt16 nId = SID_VERB_START + nr++; 165cdf0e10cSrcweir DBG_ASSERT(nId <= SID_VERB_END, "Zuviele Verben!"); 166cdf0e10cSrcweir if ( nId > SID_VERB_END ) 167cdf0e10cSrcweir break; 168cdf0e10cSrcweir 169cdf0e10cSrcweir // einf"ugen 170cdf0e10cSrcweir pMenu->InsertItem( nId, aVerbs[n].VerbName ); 171cdf0e10cSrcweir } 172cdf0e10cSrcweir } 173cdf0e10cSrcweir } 174cdf0e10cSrcweir 175cdf0e10cSrcweir 176cdf0e10cSrcweir //-------------------------------------------------------------------- 177cdf0e10cSrcweir 178cdf0e10cSrcweir 179cdf0e10cSrcweir static Image lcl_GetImageFromPngUrl( const ::rtl::OUString &rFileUrl ) 180cdf0e10cSrcweir { 181cdf0e10cSrcweir Image aRes; 182cdf0e10cSrcweir 183cdf0e10cSrcweir ::rtl::OUString aTmp; 184cdf0e10cSrcweir osl::FileBase::getSystemPathFromFileURL( rFileUrl, aTmp ); 185cdf0e10cSrcweir 186cdf0e10cSrcweir Graphic aGraphic; 187cdf0e10cSrcweir const String aFilterName( RTL_CONSTASCII_USTRINGPARAM( IMP_PNG ) ); 188cdf0e10cSrcweir if( GRFILTER_OK == GraphicFilter::LoadGraphic( aTmp, aFilterName, aGraphic ) ) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir aRes = Image( aGraphic.GetBitmapEx() ); 191cdf0e10cSrcweir } 192cdf0e10cSrcweir return aRes; 193cdf0e10cSrcweir } 194cdf0e10cSrcweir 195cdf0e10cSrcweir 196cdf0e10cSrcweir PopupMenu* InsertThesaurusSubmenu_Impl( SfxBindings* pBindings, Menu* pSVMenu ) 197cdf0e10cSrcweir { 198cdf0e10cSrcweir // 199cdf0e10cSrcweir // build thesaurus sub menu if look-up string is available 200cdf0e10cSrcweir // 201cdf0e10cSrcweir PopupMenu* pThesSubMenu = 0; 202cdf0e10cSrcweir SfxPoolItem *pItem = 0; 203cdf0e10cSrcweir pBindings->QueryState( SID_THES, pItem ); 204cdf0e10cSrcweir String aThesLookUpStr; 205cdf0e10cSrcweir SfxStringItem *pStrItem = dynamic_cast< SfxStringItem * >(pItem); 206cdf0e10cSrcweir xub_StrLen nDelimPos = STRING_LEN; 207cdf0e10cSrcweir if (pStrItem) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir aThesLookUpStr = pStrItem->GetValue(); 210cdf0e10cSrcweir nDelimPos = aThesLookUpStr.SearchBackward( '#' ); 211cdf0e10cSrcweir } 212cdf0e10cSrcweir if (aThesLookUpStr.Len() > 0 && nDelimPos != STRING_NOTFOUND) 213cdf0e10cSrcweir { 214cdf0e10cSrcweir // get synonym list for sub menu 215cdf0e10cSrcweir std::vector< ::rtl::OUString > aSynonyms; 216cdf0e10cSrcweir SfxThesSubMenuHelper aHelper; 217cdf0e10cSrcweir ::rtl::OUString aText( aHelper.GetText( aThesLookUpStr, nDelimPos ) ); 218cdf0e10cSrcweir lang::Locale aLocale; 219cdf0e10cSrcweir aHelper.GetLocale( aLocale, aThesLookUpStr, nDelimPos ); 220cdf0e10cSrcweir const bool bHasMoreSynonyms = aHelper.GetMeanings( aSynonyms, aText, aLocale, 7 /*max number of synonyms to retrieve*/ ); 221cdf0e10cSrcweir (void) bHasMoreSynonyms; 222cdf0e10cSrcweir 223cdf0e10cSrcweir pThesSubMenu = new PopupMenu; 224cdf0e10cSrcweir pThesSubMenu->SetMenuFlags(MENU_FLAG_NOAUTOMNEMONICS); 225cdf0e10cSrcweir const size_t nNumSynonyms = aSynonyms.size(); 226cdf0e10cSrcweir if (nNumSynonyms > 0) 227cdf0e10cSrcweir { 228cdf0e10cSrcweir SvtLinguConfig aCfg; 229cdf0e10cSrcweir const bool bHC = Application::GetSettings().GetStyleSettings().GetHighContrastMode(); 230cdf0e10cSrcweir 231cdf0e10cSrcweir Image aImage; 232cdf0e10cSrcweir String sThesImplName( aHelper.GetThesImplName( aLocale ) ); 233cdf0e10cSrcweir ::rtl::OUString aSynonymsImageUrl( aCfg.GetSynonymsContextImage( sThesImplName, bHC ) ); 234cdf0e10cSrcweir if (sThesImplName.Len() > 0 && aSynonymsImageUrl.getLength() > 0) 235cdf0e10cSrcweir aImage = Image( lcl_GetImageFromPngUrl( aSynonymsImageUrl ) ); 236cdf0e10cSrcweir 237cdf0e10cSrcweir for (sal_uInt16 i = 0; (size_t)i < nNumSynonyms; ++i) 238cdf0e10cSrcweir { 239cdf0e10cSrcweir //! item ids should start with values > 0, since 0 has special meaning 240cdf0e10cSrcweir const sal_uInt16 nId = i + 1; 241cdf0e10cSrcweir 242cdf0e10cSrcweir String aItemText( linguistic::GetThesaurusReplaceText( aSynonyms[i] ) ); 243cdf0e10cSrcweir pThesSubMenu->InsertItem( nId, aItemText ); 244cdf0e10cSrcweir ::rtl::OUString aCmd( ::rtl::OUString::createFromAscii( ".uno:ThesaurusFromContext?WordReplace:string=" ) ); 245cdf0e10cSrcweir aCmd += aItemText; 246cdf0e10cSrcweir pThesSubMenu->SetItemCommand( nId, aCmd ); 247cdf0e10cSrcweir 248cdf0e10cSrcweir if (aSynonymsImageUrl.getLength() > 0) 249cdf0e10cSrcweir pThesSubMenu->SetItemImage( nId, aImage ); 250cdf0e10cSrcweir } 251cdf0e10cSrcweir } 252cdf0e10cSrcweir else // nNumSynonyms == 0 253cdf0e10cSrcweir { 254cdf0e10cSrcweir const String aItemText( SfxResId( STR_MENU_NO_SYNONYM_FOUND ) ); 255cdf0e10cSrcweir pThesSubMenu->InsertItem( 1, aItemText, MIB_NOSELECT ); 256cdf0e10cSrcweir } 257cdf0e10cSrcweir pThesSubMenu->InsertSeparator(); 258cdf0e10cSrcweir const String sThesaurus( SfxResId( STR_MENU_THESAURUS ) ); 259cdf0e10cSrcweir pThesSubMenu->InsertItem( 100, sThesaurus ); 260cdf0e10cSrcweir pThesSubMenu->SetItemCommand( 100, ::rtl::OUString::createFromAscii( ".uno:ThesaurusDialog" ) ); 261cdf0e10cSrcweir 262cdf0e10cSrcweir pSVMenu->InsertSeparator(); 263cdf0e10cSrcweir const String sSynonyms( SfxResId( STR_MENU_SYNONYMS ) ); 264cdf0e10cSrcweir pSVMenu->InsertItem( SID_THES, sSynonyms ); 265cdf0e10cSrcweir pSVMenu->SetPopupMenu( SID_THES, pThesSubMenu ); 266cdf0e10cSrcweir } 267cdf0e10cSrcweir 268cdf0e10cSrcweir return pThesSubMenu; 269cdf0e10cSrcweir } 270cdf0e10cSrcweir 271cdf0e10cSrcweir 272cdf0e10cSrcweir //-------------------------------------------------------------------- 273cdf0e10cSrcweir 274cdf0e10cSrcweir void SfxMenuManager::UseDefault() 275cdf0e10cSrcweir { 276cdf0e10cSrcweir DBG_MEMTEST(); 277cdf0e10cSrcweir 278cdf0e10cSrcweir SFX_APP(); 279cdf0e10cSrcweir SfxVirtualMenu *pOldVirtMenu=0; 280cdf0e10cSrcweir if (pMenu) 281cdf0e10cSrcweir { 282cdf0e10cSrcweir pOldVirtMenu = pMenu; 283cdf0e10cSrcweir pBindings->ENTERREGISTRATIONS(); 284cdf0e10cSrcweir } 285cdf0e10cSrcweir 286cdf0e10cSrcweir SfxVirtualMenu *pVMenu = 0; 287cdf0e10cSrcweir { 288cdf0e10cSrcweir ResId aResId(GetType(),*pResMgr); 289cdf0e10cSrcweir aResId.SetRT(RSC_MENU); 290cdf0e10cSrcweir Menu *pSVMenu = new PopupMenu( aResId ); 291cdf0e10cSrcweir //SfxMenuManager::EraseItemCmds( pSVMenu ); // Remove .uno cmds to be compatible with 6.0/src641 292cdf0e10cSrcweir 293cdf0e10cSrcweir if ( bAddClipboardFuncs ) 294cdf0e10cSrcweir { 295cdf0e10cSrcweir sal_uInt16 n, nCount = pSVMenu->GetItemCount(); 296cdf0e10cSrcweir for ( n=0; n<nCount; n++ ) 297cdf0e10cSrcweir { 298cdf0e10cSrcweir sal_uInt16 nId = pSVMenu->GetItemId( n ); 299cdf0e10cSrcweir if ( nId == SID_COPY || nId == SID_CUT || nId == SID_PASTE ) 300cdf0e10cSrcweir break; 301cdf0e10cSrcweir } 302cdf0e10cSrcweir 303cdf0e10cSrcweir if ( n == nCount ) 304cdf0e10cSrcweir { 305cdf0e10cSrcweir PopupMenu aPop( SfxResId( MN_CLIPBOARDFUNCS ) ); 306cdf0e10cSrcweir nCount = aPop.GetItemCount(); 307cdf0e10cSrcweir pSVMenu->InsertSeparator(); 308cdf0e10cSrcweir for ( n=0; n<nCount; n++ ) 309cdf0e10cSrcweir { 310cdf0e10cSrcweir sal_uInt16 nId = aPop.GetItemId( n ); 311cdf0e10cSrcweir pSVMenu->InsertItem( nId, aPop.GetItemText( nId ), aPop.GetItemBits( nId ) ); 312cdf0e10cSrcweir } 313cdf0e10cSrcweir } 314cdf0e10cSrcweir } 315cdf0e10cSrcweir 316cdf0e10cSrcweir pVMenu = new SfxVirtualMenu( pSVMenu, sal_False, *pBindings, sal_True, sal_True ); 317cdf0e10cSrcweir } 318cdf0e10cSrcweir 319cdf0e10cSrcweir Construct(*pVMenu); 320cdf0e10cSrcweir if (pOldVirtMenu) 321cdf0e10cSrcweir { 322cdf0e10cSrcweir delete pOldVirtMenu; 323cdf0e10cSrcweir pBindings->LEAVEREGISTRATIONS(); 324cdf0e10cSrcweir } 325cdf0e10cSrcweir } 326cdf0e10cSrcweir 327cdf0e10cSrcweir // ------------------------------------------------------------------------ 328cdf0e10cSrcweir 329cdf0e10cSrcweir // executes the function for the selected item 330cdf0e10cSrcweir IMPL_LINK( SfxMenuManager, Select, Menu *, pSelMenu ) 331cdf0e10cSrcweir { 332cdf0e10cSrcweir DBG_MEMTEST(); 333cdf0e10cSrcweir 334cdf0e10cSrcweir sal_uInt16 nId = (sal_uInt16) pSelMenu->GetCurItemId(); 335cdf0e10cSrcweir String aCommand = pSelMenu->GetItemCommand( nId ); 336cdf0e10cSrcweir if ( !aCommand.Len() && pBindings ) 337cdf0e10cSrcweir { 338cdf0e10cSrcweir const SfxSlot* pSlot = SfxSlotPool::GetSlotPool( pBindings->GetDispatcher()->GetFrame() ).GetSlot( nId ); 339cdf0e10cSrcweir if ( pSlot && pSlot->pUnoName ) 340cdf0e10cSrcweir { 341cdf0e10cSrcweir aCommand = DEFINE_CONST_UNICODE(".uno:"); 342cdf0e10cSrcweir aCommand += String::CreateFromAscii( pSlot->GetUnoName() ); 343cdf0e10cSrcweir } 344cdf0e10cSrcweir } 345cdf0e10cSrcweir 346cdf0e10cSrcweir if ( aCommand.Len() ) 347cdf0e10cSrcweir { 348cdf0e10cSrcweir pBindings->ExecuteCommand_Impl( aCommand ); 349cdf0e10cSrcweir } 350cdf0e10cSrcweir else if ( pBindings->IsBound(nId) ) 351cdf0e10cSrcweir // normal function 352cdf0e10cSrcweir pBindings->Execute( nId ); 353cdf0e10cSrcweir else 354cdf0e10cSrcweir // special menu function 355cdf0e10cSrcweir pBindings->GetDispatcher_Impl()->Execute( nId ); 356cdf0e10cSrcweir 357cdf0e10cSrcweir return sal_True; 358cdf0e10cSrcweir } 359cdf0e10cSrcweir 360cdf0e10cSrcweir //-------------------------------------------------------------------- 361cdf0e10cSrcweir 362cdf0e10cSrcweir void SfxMenuManager::Construct_Impl( Menu* pSVMenu, sal_Bool bWithHelp ) 363cdf0e10cSrcweir { 364cdf0e10cSrcweir SfxVirtualMenu *pOldVirtMenu=0; 365cdf0e10cSrcweir if ( pMenu ) 366cdf0e10cSrcweir { 367cdf0e10cSrcweir // Es wird umkonfiguriert 368cdf0e10cSrcweir pOldVirtMenu = pMenu; 369cdf0e10cSrcweir pBindings->ENTERREGISTRATIONS(); 370cdf0e10cSrcweir } 371cdf0e10cSrcweir 372cdf0e10cSrcweir TryToHideDisabledEntries_Impl( pSVMenu ); 373cdf0e10cSrcweir SfxVirtualMenu *pVMenu = new SfxVirtualMenu( pSVMenu, bWithHelp, *pBindings, sal_True ); 374cdf0e10cSrcweir Construct(*pVMenu); 375cdf0e10cSrcweir 376cdf0e10cSrcweir if ( pOldVirtMenu ) 377cdf0e10cSrcweir { 378cdf0e10cSrcweir delete pOldVirtMenu; 379cdf0e10cSrcweir pBindings->LEAVEREGISTRATIONS(); 380cdf0e10cSrcweir } 381cdf0e10cSrcweir } 382cdf0e10cSrcweir 383cdf0e10cSrcweir //-------------------------------------------------------------------- 384cdf0e10cSrcweir 385cdf0e10cSrcweir // don't insert Popups into ConfigManager, they are not configurable at the moment ! 386cdf0e10cSrcweir SfxPopupMenuManager::SfxPopupMenuManager(const ResId& rResId, SfxBindings &rBindings ) 387cdf0e10cSrcweir : SfxMenuManager( rResId, rBindings ) 388cdf0e10cSrcweir , pSVMenu( NULL ) 389cdf0e10cSrcweir { 390cdf0e10cSrcweir DBG_MEMTEST(); 391cdf0e10cSrcweir } 392cdf0e10cSrcweir 393cdf0e10cSrcweir SfxPopupMenuManager::~SfxPopupMenuManager() 394cdf0e10cSrcweir { 395cdf0e10cSrcweir } 396cdf0e10cSrcweir 397cdf0e10cSrcweir //------------------------------------------------------------------------- 398cdf0e10cSrcweir 399cdf0e10cSrcweir void SfxPopupMenuManager::RemoveDisabledEntries() 400cdf0e10cSrcweir { 401cdf0e10cSrcweir if ( pSVMenu ) 402cdf0e10cSrcweir TryToHideDisabledEntries_Impl( pSVMenu ); 403cdf0e10cSrcweir } 404cdf0e10cSrcweir 405cdf0e10cSrcweir //-------------------------------------------------------------------- 406cdf0e10cSrcweir 407cdf0e10cSrcweir sal_uInt16 SfxPopupMenuManager::Execute( const Point& rPos, Window* pWindow ) 408cdf0e10cSrcweir { 409cdf0e10cSrcweir DBG_MEMTEST(); 410cdf0e10cSrcweir sal_uInt16 nVal = ( (PopupMenu*) GetMenu()->GetSVMenu() )->Execute( pWindow, rPos ); 411cdf0e10cSrcweir delete pStaticThesSubMenu; pStaticThesSubMenu = NULL; 412cdf0e10cSrcweir return nVal; 413cdf0e10cSrcweir } 414cdf0e10cSrcweir 415cdf0e10cSrcweir //-------------------------------------------------------------------- 416cdf0e10cSrcweir 417cdf0e10cSrcweir IMPL_LINK_INLINE_START( SfxPopupMenuManager, SelectHdl, void *, EMPTYARG ) 418cdf0e10cSrcweir { 419cdf0e10cSrcweir return 1; 420cdf0e10cSrcweir } 421cdf0e10cSrcweir IMPL_LINK_INLINE_END( SfxPopupMenuManager, SelectHdl, void *, EMPTYARG ) 422cdf0e10cSrcweir 423cdf0e10cSrcweir 424cdf0e10cSrcweir //-------------------------------------------------------------------- 425cdf0e10cSrcweir 426cdf0e10cSrcweir sal_uInt16 SfxPopupMenuManager::Execute( const Point& rPoint, Window* pWindow, va_list pArgs, const SfxPoolItem *pArg1 ) 427cdf0e10cSrcweir { 428cdf0e10cSrcweir DBG_MEMTEST(); 429cdf0e10cSrcweir 430cdf0e10cSrcweir PopupMenu* pPopMenu = ( (PopupMenu*)GetMenu()->GetSVMenu() ); 431cdf0e10cSrcweir pPopMenu->SetSelectHdl( LINK( this, SfxPopupMenuManager, SelectHdl ) ); 432cdf0e10cSrcweir sal_uInt16 nId = pPopMenu->Execute( pWindow, rPoint ); 433cdf0e10cSrcweir pPopMenu->SetSelectHdl( Link() ); 434cdf0e10cSrcweir 435cdf0e10cSrcweir if ( nId ) 436cdf0e10cSrcweir GetBindings().GetDispatcher()->_Execute( nId, SFX_CALLMODE_RECORD, pArgs, pArg1 ); 437cdf0e10cSrcweir 438cdf0e10cSrcweir return nId; 439cdf0e10cSrcweir } 440cdf0e10cSrcweir 441cdf0e10cSrcweir //-------------------------------------------------------------------- 442cdf0e10cSrcweir 443cdf0e10cSrcweir sal_uInt16 SfxPopupMenuManager::Execute( const Point& rPoint, Window* pWindow, const SfxPoolItem *pArg1, ... ) 444cdf0e10cSrcweir { 445cdf0e10cSrcweir DBG_MEMTEST(); 446cdf0e10cSrcweir 447cdf0e10cSrcweir va_list pArgs; 448cdf0e10cSrcweir va_start(pArgs, pArg1); 449cdf0e10cSrcweir 450cdf0e10cSrcweir return (Execute( rPoint, pWindow, pArgs, pArg1 )); 451cdf0e10cSrcweir } 452cdf0e10cSrcweir 453cdf0e10cSrcweir //------------------------------------------------------------------------- 454cdf0e10cSrcweir 455cdf0e10cSrcweir void SfxPopupMenuManager::StartInsert() 456cdf0e10cSrcweir { 457cdf0e10cSrcweir ResId aResId(GetType(),*pResMgr); 458cdf0e10cSrcweir aResId.SetRT(RSC_MENU); 459cdf0e10cSrcweir pSVMenu = new PopupMenu( aResId ); 460cdf0e10cSrcweir TryToHideDisabledEntries_Impl( pSVMenu ); 461cdf0e10cSrcweir } 462cdf0e10cSrcweir 463cdf0e10cSrcweir //------------------------------------------------------------------------- 464cdf0e10cSrcweir 465cdf0e10cSrcweir void SfxPopupMenuManager::EndInsert() 466cdf0e10cSrcweir { 467cdf0e10cSrcweir pBindings->ENTERREGISTRATIONS(); 468cdf0e10cSrcweir pMenu = new SfxVirtualMenu( pSVMenu, sal_False, *pBindings, sal_True, sal_True ); 469cdf0e10cSrcweir Construct( *pMenu ); 470cdf0e10cSrcweir pBindings->LEAVEREGISTRATIONS(); 471cdf0e10cSrcweir } 472cdf0e10cSrcweir 473cdf0e10cSrcweir //------------------------------------------------------------------------- 474cdf0e10cSrcweir 475cdf0e10cSrcweir void SfxPopupMenuManager::InsertSeparator( sal_uInt16 nPos ) 476cdf0e10cSrcweir { 477cdf0e10cSrcweir pSVMenu->InsertSeparator( nPos ); 478cdf0e10cSrcweir } 479cdf0e10cSrcweir 480cdf0e10cSrcweir //------------------------------------------------------------------------- 481cdf0e10cSrcweir 482cdf0e10cSrcweir void SfxPopupMenuManager::InsertItem( sal_uInt16 nId, const String& rName, MenuItemBits nBits, const rtl::OString& rHelpId, sal_uInt16 nPos ) 483cdf0e10cSrcweir { 484cdf0e10cSrcweir pSVMenu->InsertItem( nId, rName, nBits,nPos ); 485cdf0e10cSrcweir pSVMenu->SetHelpId( nId, rHelpId ); 486cdf0e10cSrcweir } 487cdf0e10cSrcweir 488cdf0e10cSrcweir //------------------------------------------------------------------------- 489cdf0e10cSrcweir 490cdf0e10cSrcweir void SfxPopupMenuManager::RemoveItem( sal_uInt16 nId ) 491cdf0e10cSrcweir { 492cdf0e10cSrcweir pSVMenu->RemoveItem( nId ); 493cdf0e10cSrcweir } 494cdf0e10cSrcweir 495cdf0e10cSrcweir //------------------------------------------------------------------------- 496cdf0e10cSrcweir 497cdf0e10cSrcweir void SfxPopupMenuManager::CheckItem( sal_uInt16 nId, sal_Bool bCheck ) 498cdf0e10cSrcweir { 499cdf0e10cSrcweir pSVMenu->CheckItem( nId, bCheck ); 500cdf0e10cSrcweir } 501cdf0e10cSrcweir 502cdf0e10cSrcweir void SfxPopupMenuManager::AddClipboardFunctions() 503cdf0e10cSrcweir { 504cdf0e10cSrcweir bAddClipboardFuncs = sal_True; 505cdf0e10cSrcweir } 506cdf0e10cSrcweir 507cdf0e10cSrcweir SfxMenuManager::SfxMenuManager( Menu* pMenuArg, SfxBindings &rBindings ) 508cdf0e10cSrcweir : pMenu(0), 509cdf0e10cSrcweir pOldMenu(0), 510cdf0e10cSrcweir pBindings(&rBindings), 511cdf0e10cSrcweir pResMgr(NULL), 512cdf0e10cSrcweir nType(0) 513cdf0e10cSrcweir { 514cdf0e10cSrcweir bAddClipboardFuncs = sal_False; 515cdf0e10cSrcweir SfxVirtualMenu* pVMenu = new SfxVirtualMenu( pMenuArg, sal_False, rBindings, sal_True, sal_True ); 516cdf0e10cSrcweir Construct(*pVMenu); 517cdf0e10cSrcweir } 518cdf0e10cSrcweir 519cdf0e10cSrcweir SfxPopupMenuManager::SfxPopupMenuManager( PopupMenu* pMenuArg, SfxBindings& rBindings ) 520cdf0e10cSrcweir : SfxMenuManager( pMenuArg, rBindings ) 521cdf0e10cSrcweir , pSVMenu( pMenuArg ) 522cdf0e10cSrcweir { 523cdf0e10cSrcweir } 524cdf0e10cSrcweir 525cdf0e10cSrcweir SfxPopupMenuManager* SfxPopupMenuManager::Popup( const ResId& rResId, SfxViewFrame* pFrame,const Point& rPoint, Window* pWindow ) 526cdf0e10cSrcweir { 527cdf0e10cSrcweir PopupMenu *pSVMenu = new PopupMenu( rResId ); 528cdf0e10cSrcweir sal_uInt16 n, nCount = pSVMenu->GetItemCount(); 529cdf0e10cSrcweir for ( n=0; n<nCount; n++ ) 530cdf0e10cSrcweir { 531cdf0e10cSrcweir sal_uInt16 nId = pSVMenu->GetItemId( n ); 532cdf0e10cSrcweir if ( nId == SID_COPY || nId == SID_CUT || nId == SID_PASTE ) 533cdf0e10cSrcweir break; 534cdf0e10cSrcweir } 535cdf0e10cSrcweir 536cdf0e10cSrcweir PopupMenu* pThesSubMenu = InsertThesaurusSubmenu_Impl( &pFrame->GetBindings(), pSVMenu ); 537cdf0e10cSrcweir // #i107205# (see comment in header file) 538cdf0e10cSrcweir pStaticThesSubMenu = pThesSubMenu; 539cdf0e10cSrcweir 540cdf0e10cSrcweir if ( n == nCount ) 541cdf0e10cSrcweir { 542cdf0e10cSrcweir PopupMenu aPop( SfxResId( MN_CLIPBOARDFUNCS ) ); 543cdf0e10cSrcweir nCount = aPop.GetItemCount(); 544cdf0e10cSrcweir pSVMenu->InsertSeparator(); 545cdf0e10cSrcweir for ( n=0; n<nCount; n++ ) 546cdf0e10cSrcweir { 547cdf0e10cSrcweir sal_uInt16 nId = aPop.GetItemId( n ); 548cdf0e10cSrcweir pSVMenu->InsertItem( nId, aPop.GetItemText( nId ), aPop.GetItemBits( nId ) ); 549cdf0e10cSrcweir pSVMenu->SetHelpId( nId, aPop.GetHelpId( nId )); 550cdf0e10cSrcweir } 551cdf0e10cSrcweir } 552cdf0e10cSrcweir 553cdf0e10cSrcweir InsertVerbs_Impl( &pFrame->GetBindings(), pFrame->GetViewShell()->GetVerbs(), pSVMenu ); 554cdf0e10cSrcweir Menu* pMenu = NULL; 555cdf0e10cSrcweir ::com::sun::star::ui::ContextMenuExecuteEvent aEvent; 556cdf0e10cSrcweir aEvent.SourceWindow = VCLUnoHelper::GetInterface( pWindow ); 557cdf0e10cSrcweir aEvent.ExecutePosition.X = rPoint.X(); 558cdf0e10cSrcweir aEvent.ExecutePosition.Y = rPoint.Y(); 559cdf0e10cSrcweir ::rtl::OUString sDummyMenuName; 560cdf0e10cSrcweir if ( pFrame->GetViewShell()->TryContextMenuInterception( *pSVMenu, sDummyMenuName, pMenu, aEvent ) ) 561cdf0e10cSrcweir { 562cdf0e10cSrcweir if ( pMenu ) 563cdf0e10cSrcweir { 564cdf0e10cSrcweir delete pSVMenu; 565cdf0e10cSrcweir pSVMenu = (PopupMenu*) pMenu; 566cdf0e10cSrcweir } 567cdf0e10cSrcweir 568cdf0e10cSrcweir SfxPopupMenuManager* aMgr = new SfxPopupMenuManager( pSVMenu, pFrame->GetBindings()); 569cdf0e10cSrcweir aMgr->RemoveDisabledEntries(); 570cdf0e10cSrcweir return aMgr; 571cdf0e10cSrcweir } 572cdf0e10cSrcweir 573cdf0e10cSrcweir return 0; 574cdf0e10cSrcweir } 575cdf0e10cSrcweir 576cdf0e10cSrcweir 577cdf0e10cSrcweir void SfxPopupMenuManager::ExecutePopup( const ResId& rResId, SfxViewFrame* pFrame, const Point& rPoint, Window* pWindow ) 578cdf0e10cSrcweir { 579cdf0e10cSrcweir PopupMenu *pSVMenu = new PopupMenu( rResId ); 580cdf0e10cSrcweir sal_uInt16 n, nCount = pSVMenu->GetItemCount(); 581cdf0e10cSrcweir for ( n=0; n<nCount; n++ ) 582cdf0e10cSrcweir { 583cdf0e10cSrcweir sal_uInt16 nId = pSVMenu->GetItemId( n ); 584cdf0e10cSrcweir if ( nId == SID_COPY || nId == SID_CUT || nId == SID_PASTE ) 585cdf0e10cSrcweir break; 586cdf0e10cSrcweir } 587cdf0e10cSrcweir 588cdf0e10cSrcweir PopupMenu* pThesSubMenu = InsertThesaurusSubmenu_Impl( &pFrame->GetBindings(), pSVMenu ); 589cdf0e10cSrcweir 590cdf0e10cSrcweir if ( n == nCount ) 591cdf0e10cSrcweir { 592cdf0e10cSrcweir PopupMenu aPop( SfxResId( MN_CLIPBOARDFUNCS ) ); 593cdf0e10cSrcweir nCount = aPop.GetItemCount(); 594cdf0e10cSrcweir pSVMenu->InsertSeparator(); 595cdf0e10cSrcweir for ( n=0; n<nCount; n++ ) 596cdf0e10cSrcweir { 597cdf0e10cSrcweir sal_uInt16 nId = aPop.GetItemId( n ); 598cdf0e10cSrcweir pSVMenu->InsertItem( nId, aPop.GetItemText( nId ), aPop.GetItemBits( nId ) ); 599cdf0e10cSrcweir pSVMenu->SetHelpId( nId, aPop.GetHelpId( nId )); 600cdf0e10cSrcweir } 601cdf0e10cSrcweir } 602cdf0e10cSrcweir 603cdf0e10cSrcweir InsertVerbs_Impl( &pFrame->GetBindings(), pFrame->GetViewShell()->GetVerbs(), pSVMenu ); 604cdf0e10cSrcweir Menu* pMenu = NULL; 605cdf0e10cSrcweir ::com::sun::star::ui::ContextMenuExecuteEvent aEvent; 606cdf0e10cSrcweir aEvent.SourceWindow = VCLUnoHelper::GetInterface( pWindow ); 607cdf0e10cSrcweir aEvent.ExecutePosition.X = rPoint.X(); 608cdf0e10cSrcweir aEvent.ExecutePosition.Y = rPoint.Y(); 609cdf0e10cSrcweir ::rtl::OUString sDummyMenuName; 610cdf0e10cSrcweir if ( pFrame->GetViewShell()->TryContextMenuInterception( *pSVMenu, sDummyMenuName, pMenu, aEvent ) ) 611cdf0e10cSrcweir { 612cdf0e10cSrcweir if ( pMenu ) 613cdf0e10cSrcweir { 614cdf0e10cSrcweir delete pSVMenu; 615cdf0e10cSrcweir pSVMenu = (PopupMenu*) pMenu; 616cdf0e10cSrcweir } 617cdf0e10cSrcweir 618cdf0e10cSrcweir SfxPopupMenuManager aPop( pSVMenu, pFrame->GetBindings() ); 619cdf0e10cSrcweir aPop.RemoveDisabledEntries(); 620cdf0e10cSrcweir aPop.Execute( rPoint, pWindow ); 621cdf0e10cSrcweir 622cdf0e10cSrcweir // #i112646 avoid crash when context menu is closed. 623cdf0e10cSrcweir // the (manually inserted) sub-menu needs to be destroyed before 624cdf0e10cSrcweir // aPop gets destroyed. 625cdf0e10cSrcweir delete pThesSubMenu; 626cdf0e10cSrcweir pThesSubMenu = 0; 627cdf0e10cSrcweir } 628cdf0e10cSrcweir 629cdf0e10cSrcweir delete pThesSubMenu; 630cdf0e10cSrcweir } 631cdf0e10cSrcweir 632cdf0e10cSrcweir Menu* SfxPopupMenuManager::GetSVMenu() 633cdf0e10cSrcweir { 634cdf0e10cSrcweir return (Menu*) GetMenu()->GetSVMenu(); 635cdf0e10cSrcweir } 636cdf0e10cSrcweir 637