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