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