xref: /trunk/main/sfx2/source/menu/mnuitem.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 #ifdef SOLARIS
32*cdf0e10cSrcweir // HACK: prevent conflict between STLPORT and Workshop headers on Solaris 8
33*cdf0e10cSrcweir #include <ctime>
34*cdf0e10cSrcweir #endif
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <string> // HACK: prevent conflict between STLPORT and Workshop includes
37*cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h>
38*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatch.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/util/URL.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
43*cdf0e10cSrcweir #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
44*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
45*cdf0e10cSrcweir #endif
46*cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
47*cdf0e10cSrcweir #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
48*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
49*cdf0e10cSrcweir #endif
50*cdf0e10cSrcweir #include <tools/urlobj.hxx>
51*cdf0e10cSrcweir #include <svl/eitem.hxx>
52*cdf0e10cSrcweir #include <svl/stritem.hxx>
53*cdf0e10cSrcweir #include <svtools/imagemgr.hxx>
54*cdf0e10cSrcweir #include <svtools/menuoptions.hxx>
55*cdf0e10cSrcweir #include <framework/menuconfiguration.hxx>
56*cdf0e10cSrcweir #ifndef GCC
57*cdf0e10cSrcweir #endif
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir #include <sfx2/app.hxx>
60*cdf0e10cSrcweir #include <sfx2/sfx.hrc>
61*cdf0e10cSrcweir #include <sfx2/msgpool.hxx>
62*cdf0e10cSrcweir #include <sfx2/msg.hxx>
63*cdf0e10cSrcweir #include <sfx2/bindings.hxx>
64*cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
65*cdf0e10cSrcweir #include "idpool.hxx"
66*cdf0e10cSrcweir #include "sfxtypes.hxx"
67*cdf0e10cSrcweir #include "virtmenu.hxx"
68*cdf0e10cSrcweir #include <sfx2/mnuitem.hxx>
69*cdf0e10cSrcweir #include <sfx2/tbxctrl.hxx>
70*cdf0e10cSrcweir #include "arrdecl.hxx"
71*cdf0e10cSrcweir #include <sfx2/module.hxx>
72*cdf0e10cSrcweir #include <sfx2/unoctitm.hxx>
73*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
74*cdf0e10cSrcweir #include "sfx2/imgmgr.hxx"
75*cdf0e10cSrcweir #include "sfx2/imagemgr.hxx"
76*cdf0e10cSrcweir #include "sfx2/sfxresid.hxx"
77*cdf0e10cSrcweir #include "../doc/doc.hrc"
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
80*cdf0e10cSrcweir using namespace ::com::sun::star::frame;
81*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
82*cdf0e10cSrcweir using namespace ::com::sun::star::util;
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir //====================================================================
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir class SfxEnumMenu: public PopupMenu
87*cdf0e10cSrcweir {
88*cdf0e10cSrcweir 	sal_uInt16			nSlot;
89*cdf0e10cSrcweir 	SfxEnumItem    *pItem;
90*cdf0e10cSrcweir     SfxBindings*    pBindings;
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir protected:
93*cdf0e10cSrcweir 	virtual void	Select();
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir public:
96*cdf0e10cSrcweir                     SfxEnumMenu( sal_uInt16 nSlot, SfxBindings* pBind, const SfxEnumItem &rItem );
97*cdf0e10cSrcweir 					~SfxEnumMenu();
98*cdf0e10cSrcweir };
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir //=========================================================================
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir SfxEnumMenu::SfxEnumMenu( sal_uInt16 nSlotId, SfxBindings* pBind, const SfxEnumItem &rItem ):
103*cdf0e10cSrcweir 	nSlot( nSlotId ),
104*cdf0e10cSrcweir     pItem( (SfxEnumItem*) rItem.Clone() ),
105*cdf0e10cSrcweir     pBindings( pBind )
106*cdf0e10cSrcweir {
107*cdf0e10cSrcweir 	for ( sal_uInt16 nVal = 0; nVal < pItem->GetValueCount(); ++nVal )
108*cdf0e10cSrcweir 		InsertItem( nVal+1, pItem->GetValueTextByPos(nVal) );
109*cdf0e10cSrcweir 	CheckItem( pItem->GetValue() + 1, sal_True );
110*cdf0e10cSrcweir }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir //-------------------------------------------------------------------------
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir SfxEnumMenu::~SfxEnumMenu()
115*cdf0e10cSrcweir {
116*cdf0e10cSrcweir 	delete pItem;
117*cdf0e10cSrcweir }
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir //-------------------------------------------------------------------------
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir void SfxEnumMenu::Select()
122*cdf0e10cSrcweir {
123*cdf0e10cSrcweir 	pItem->SetValue( GetCurItemId()-1 );
124*cdf0e10cSrcweir     pBindings->GetDispatcher()->Execute( nSlot,
125*cdf0e10cSrcweir 				SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD,
126*cdf0e10cSrcweir 				pItem, 0L, 0L );
127*cdf0e10cSrcweir }
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir //--------------------------------------------------------------------
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir void SfxMenuControl::SetOwnMenu( SfxVirtualMenu* pMenu )
132*cdf0e10cSrcweir {
133*cdf0e10cSrcweir 	pOwnMenu = pMenu;
134*cdf0e10cSrcweir 	if ( pSubMenu )
135*cdf0e10cSrcweir 		pSubMenu->SetParentMenu( pMenu );
136*cdf0e10cSrcweir }
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir //--------------------------------------------------------------------
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir // binds the instance to the specified id and assignes the title
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir void SfxMenuControl::Bind(
144*cdf0e10cSrcweir     SfxVirtualMenu* pOwn,
145*cdf0e10cSrcweir 	sal_uInt16 nSlotId,
146*cdf0e10cSrcweir     const String& rTitle,
147*cdf0e10cSrcweir     const String &rHelpText,
148*cdf0e10cSrcweir     SfxBindings &rBindings )
149*cdf0e10cSrcweir {
150*cdf0e10cSrcweir 	DBG_MEMTEST();
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 	aTitle = rTitle;
153*cdf0e10cSrcweir 	aHelpText = rHelpText;
154*cdf0e10cSrcweir 	pOwnMenu = pOwn;
155*cdf0e10cSrcweir 	pSubMenu = 0;
156*cdf0e10cSrcweir 	if ( pOwn )
157*cdf0e10cSrcweir 		SfxControllerItem::Bind(nSlotId, &rBindings);
158*cdf0e10cSrcweir 	else
159*cdf0e10cSrcweir 		SetId( nSlotId );
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 	DBG( CheckConfigure_Impl(SFX_SLOT_MENUCONFIG) );
162*cdf0e10cSrcweir }
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir //--------------------------------------------------------------------
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir // binds the item to the specified menu and assignes the title
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir void SfxMenuControl::Bind(
170*cdf0e10cSrcweir     SfxVirtualMenu* pOwn,
171*cdf0e10cSrcweir 	sal_uInt16 nSlotId,
172*cdf0e10cSrcweir     SfxVirtualMenu& rMenu,
173*cdf0e10cSrcweir 	const String& rTitle,
174*cdf0e10cSrcweir     const String &rHelpText,
175*cdf0e10cSrcweir 	SfxBindings &rBindings )
176*cdf0e10cSrcweir {
177*cdf0e10cSrcweir 	DBG_MEMTEST();
178*cdf0e10cSrcweir 	SetId( nSlotId );
179*cdf0e10cSrcweir 	SetBindings(rBindings);
180*cdf0e10cSrcweir 	pOwnMenu = pOwn;
181*cdf0e10cSrcweir 	pSubMenu = &rMenu;
182*cdf0e10cSrcweir 	aTitle = rTitle;
183*cdf0e10cSrcweir 	aHelpText = rHelpText;
184*cdf0e10cSrcweir }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir //--------------------------------------------------------------------
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir // ctor for explicit registration
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir SfxMenuControl::SfxMenuControl( sal_Bool bShowStrings )
191*cdf0e10cSrcweir :	pOwnMenu(0),
192*cdf0e10cSrcweir 	pSubMenu(0),
193*cdf0e10cSrcweir 	b_ShowStrings(bShowStrings)
194*cdf0e10cSrcweir {
195*cdf0e10cSrcweir 	DBG_MEMTEST();
196*cdf0e10cSrcweir }
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir //--------------------------------------------------------------------
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir // ctor for array
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir SfxMenuControl::SfxMenuControl():
203*cdf0e10cSrcweir 	pOwnMenu(0),
204*cdf0e10cSrcweir 	pSubMenu(0),
205*cdf0e10cSrcweir 	b_ShowStrings(sal_False)
206*cdf0e10cSrcweir {
207*cdf0e10cSrcweir 	DBG_MEMTEST();
208*cdf0e10cSrcweir }
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir //--------------------------------------------------------------------
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir SfxMenuControl::SfxMenuControl(sal_uInt16 nSlotId, SfxBindings& rBindings):
213*cdf0e10cSrcweir 	SfxControllerItem(nSlotId, rBindings),
214*cdf0e10cSrcweir 	pOwnMenu(0),
215*cdf0e10cSrcweir 	pSubMenu(0),
216*cdf0e10cSrcweir 	b_ShowStrings(sal_False)
217*cdf0e10cSrcweir {
218*cdf0e10cSrcweir 	DBG_MEMTEST();
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir 	// Dieser Ctor soll es erm"oglichen, w"ahrend der Konstruktion schon
221*cdf0e10cSrcweir 	// auf die Bindings zur"uckgreifen zu k"onnen, aber gebunden wird
222*cdf0e10cSrcweir 	// wie immer erst sp"ater. Anwendung z.B. wenn im ctor der abgeleiteten
223*cdf0e10cSrcweir 	// Klasse z.B. ein StatusForwarder erzeugt werden soll.
224*cdf0e10cSrcweir 	UnBind();
225*cdf0e10cSrcweir }
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir //--------------------------------------------------------------------
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir // dtor
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir SfxMenuControl::~SfxMenuControl()
233*cdf0e10cSrcweir {
234*cdf0e10cSrcweir 	delete pSubMenu;
235*cdf0e10cSrcweir }
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir void SfxMenuControl::RemovePopup()
238*cdf0e10cSrcweir {
239*cdf0e10cSrcweir 	DELETEZ( pSubMenu );
240*cdf0e10cSrcweir }
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir //--------------------------------------------------------------------
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir // changes the state in the virtual menu
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir void SfxMenuControl::StateChanged
247*cdf0e10cSrcweir (
248*cdf0e10cSrcweir 	sal_uInt16 				nSID,
249*cdf0e10cSrcweir 	SfxItemState		eState,
250*cdf0e10cSrcweir 	const SfxPoolItem* 	pState
251*cdf0e10cSrcweir )
252*cdf0e10cSrcweir {
253*cdf0e10cSrcweir     (void)nSID; //unused
254*cdf0e10cSrcweir     DBG_MEMTEST();
255*cdf0e10cSrcweir 	DBG_ASSERT( nSID == GetId(), "strange SID" );
256*cdf0e10cSrcweir 	DBG_ASSERT( pOwnMenu != 0, "setting state to dangling SfxMenuControl" );
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir 	bool bIsObjMenu =
259*cdf0e10cSrcweir 				GetId() >= SID_OBJECTMENU0 && GetId() < SID_OBJECTMENU_LAST;
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir 	// enabled/disabled-Flag pauschal korrigieren
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir #ifdef UNIX
264*cdf0e10cSrcweir 	if (nSID == SID_PASTE)
265*cdf0e10cSrcweir 		pOwnMenu->EnableItem( GetId(), sal_True );
266*cdf0e10cSrcweir 	else
267*cdf0e10cSrcweir #endif
268*cdf0e10cSrcweir 	pOwnMenu->EnableItem( GetId(), bIsObjMenu
269*cdf0e10cSrcweir 				? 0 != pOwnMenu->GetSVMenu()->GetPopupMenu( GetId() )
270*cdf0e10cSrcweir 				: eState != SFX_ITEM_DISABLED );
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir 	if ( eState != SFX_ITEM_AVAILABLE )
273*cdf0e10cSrcweir 	{
274*cdf0e10cSrcweir 		// checken nur bei nicht-Object-Menus
275*cdf0e10cSrcweir 		if ( !bIsObjMenu )
276*cdf0e10cSrcweir 			pOwnMenu->CheckItem( GetId(), sal_False );
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir 		// SetItemText flackert in MenuBar insbes. unter OS/2 (Bug #20658)
279*cdf0e10cSrcweir 		if ( // !bIsObjMenu && nicht wegen "Format/Datenbank"
280*cdf0e10cSrcweir 			 pOwnMenu->GetSVMenu()->GetItemText( GetId() ) != GetTitle() )
281*cdf0e10cSrcweir         {
282*cdf0e10cSrcweir 			 DBG_WARNING("Title of menu item changed - please check if this needs correction!");
283*cdf0e10cSrcweir 			// pOwnMenu->SetItemText( GetId(), GetTitle() );
284*cdf0e10cSrcweir         }
285*cdf0e10cSrcweir 		return;
286*cdf0e10cSrcweir 	}
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir 	// ggf. das alte Enum-Menu entfernen/loeschen
289*cdf0e10cSrcweir 	//! delete pOwnMenu->GetMenu().ChangePopupMenu( GetId(), 0 );
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir 	bool bCheck = false;
292*cdf0e10cSrcweir 	if ( pState->ISA(SfxBoolItem) )
293*cdf0e10cSrcweir 	{
294*cdf0e10cSrcweir 		// BoolItem fuer checken
295*cdf0e10cSrcweir 		DBG_ASSERT( GetId() < SID_OBJECTMENU0 || GetId() > SID_OBJECTMENU_LAST,
296*cdf0e10cSrcweir 					"SfxBoolItem not allowed for SID_OBJECTMENUx" );
297*cdf0e10cSrcweir 		bCheck = ((const SfxBoolItem*)pState)->GetValue();
298*cdf0e10cSrcweir 	}
299*cdf0e10cSrcweir 	else if ( pState->ISA(SfxEnumItemInterface) &&
300*cdf0e10cSrcweir 			  ((SfxEnumItemInterface *)pState)->HasBoolValue() )
301*cdf0e10cSrcweir 	{
302*cdf0e10cSrcweir 		// EnumItem wie Bool behandeln
303*cdf0e10cSrcweir 		DBG_ASSERT( GetId() < SID_OBJECTMENU0 || GetId() > SID_OBJECTMENU_LAST,
304*cdf0e10cSrcweir 					"SfxEnumItem not allowed for SID_OBJECTMENUx" );
305*cdf0e10cSrcweir 		bCheck = ((SfxEnumItemInterface *)pState)->GetBoolValue();
306*cdf0e10cSrcweir 	}
307*cdf0e10cSrcweir 	else if ( ( b_ShowStrings || bIsObjMenu ) && pState->ISA(SfxStringItem) )
308*cdf0e10cSrcweir 	{
309*cdf0e10cSrcweir 		// MenuText aus SfxStringItem holen
310*cdf0e10cSrcweir 		String aStr( ((const SfxStringItem*)pState)->GetValue() );
311*cdf0e10cSrcweir 		if ( aStr.CompareToAscii("($1)",4) == COMPARE_EQUAL )
312*cdf0e10cSrcweir 		{
313*cdf0e10cSrcweir 			String aEntry(SfxResId(STR_UPDATEDOC));
314*cdf0e10cSrcweir 			aEntry += ' ';
315*cdf0e10cSrcweir 			aEntry += aStr.Copy(4);
316*cdf0e10cSrcweir 			aStr = aEntry;
317*cdf0e10cSrcweir 		}
318*cdf0e10cSrcweir 		else if ( aStr.CompareToAscii("($2)",4) == COMPARE_EQUAL )
319*cdf0e10cSrcweir 		{
320*cdf0e10cSrcweir 			String aEntry(SfxResId(STR_CLOSEDOC_ANDRETURN));
321*cdf0e10cSrcweir 			aEntry += aStr.Copy(4);
322*cdf0e10cSrcweir 			aStr = aEntry;
323*cdf0e10cSrcweir 		}
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir 		pOwnMenu->SetItemText( GetId(), aStr );
326*cdf0e10cSrcweir 	}
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir #ifdef enum_item_menu_ok
329*cdf0e10cSrcweir 	else if ( aType == TYPE(SfxEnumItem) )
330*cdf0e10cSrcweir 	{
331*cdf0e10cSrcweir 		DBG_ASSERT( GetId() < SID_OBJECTMENU0 || GetId() > SID_OBJECTMENU_LAST,
332*cdf0e10cSrcweir 					"SfxEnumItem not allowed for SID_OBJECTMENUx" );
333*cdf0e10cSrcweir         pOwnMenu->GetMenu().ChangePopupMenu( GetId(), &GetBindings(),
334*cdf0e10cSrcweir 			new SfxEnumMenu( GetId(), *(const SfxEnumItem*)pState ) );
335*cdf0e10cSrcweir 	}
336*cdf0e10cSrcweir #endif
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir 	pOwnMenu->CheckItem( GetId(), bCheck );
339*cdf0e10cSrcweir }
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir //--------------------------------------------------------------------
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir SfxMenuControl* SfxMenuControl::CreateImpl( sal_uInt16 /*nId*/, Menu& /*rMenu*/, SfxBindings& /*rBindings*/ )
344*cdf0e10cSrcweir {
345*cdf0e10cSrcweir 	return new SfxMenuControl( sal_True );
346*cdf0e10cSrcweir }
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir //--------------------------------------------------------------------
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir void SfxMenuControl::RegisterControl( sal_uInt16 nSlotId, SfxModule *pMod )
351*cdf0e10cSrcweir {
352*cdf0e10cSrcweir     RegisterMenuControl( pMod, new SfxMenuCtrlFactory(
353*cdf0e10cSrcweir 				SfxMenuControl::CreateImpl, TYPE(SfxStringItem), nSlotId ) );
354*cdf0e10cSrcweir }
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir //--------------------------------------------------------------------
357*cdf0e10cSrcweir void SfxMenuControl::RegisterMenuControl(SfxModule* pMod, SfxMenuCtrlFactory* pFact)
358*cdf0e10cSrcweir {
359*cdf0e10cSrcweir     SFX_APP()->RegisterMenuControl_Impl( pMod, pFact );
360*cdf0e10cSrcweir }
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir SfxMenuControl* SfxMenuControl::CreateControl( sal_uInt16 nId, Menu &rMenu, SfxBindings &rBindings )
363*cdf0e10cSrcweir {
364*cdf0e10cSrcweir 	TypeId aSlotType = SFX_SLOTPOOL().GetSlotType(nId);
365*cdf0e10cSrcweir 	if ( aSlotType )
366*cdf0e10cSrcweir 	{
367*cdf0e10cSrcweir 		SfxApplication *pApp = SFX_APP();
368*cdf0e10cSrcweir 		SfxDispatcher *pDisp = rBindings.GetDispatcher_Impl();
369*cdf0e10cSrcweir         SfxModule *pMod = pDisp ? SfxModule::GetActiveModule( pDisp->GetFrame() ) :0;
370*cdf0e10cSrcweir 		if ( pMod )
371*cdf0e10cSrcweir 		{
372*cdf0e10cSrcweir 			SfxMenuCtrlFactArr_Impl *pFactories = pMod->GetMenuCtrlFactories_Impl();
373*cdf0e10cSrcweir 			if ( pFactories )
374*cdf0e10cSrcweir 			{
375*cdf0e10cSrcweir 				SfxMenuCtrlFactArr_Impl &rFactories = *pFactories;
376*cdf0e10cSrcweir 				for ( sal_uInt16 nFactory = 0; nFactory < rFactories.Count(); ++nFactory )
377*cdf0e10cSrcweir 					if ( rFactories[nFactory]->nTypeId == aSlotType &&
378*cdf0e10cSrcweir 						 ( ( rFactories[nFactory]->nSlotId == 0 ) ||
379*cdf0e10cSrcweir 						   ( rFactories[nFactory]->nSlotId == nId) ) )
380*cdf0e10cSrcweir 						return rFactories[nFactory]->pCtor( nId, rMenu, rBindings );
381*cdf0e10cSrcweir 			}
382*cdf0e10cSrcweir 		}
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir 		SfxMenuCtrlFactArr_Impl &rFactories = pApp->GetMenuCtrlFactories_Impl();
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir 		for ( sal_uInt16 nFactory = 0; nFactory < rFactories.Count(); ++nFactory )
387*cdf0e10cSrcweir 			if ( rFactories[nFactory]->nTypeId == aSlotType &&
388*cdf0e10cSrcweir 				 ( ( rFactories[nFactory]->nSlotId == 0 ) ||
389*cdf0e10cSrcweir 				   ( rFactories[nFactory]->nSlotId == nId) ) )
390*cdf0e10cSrcweir 				return rFactories[nFactory]->pCtor( nId, rMenu, rBindings );
391*cdf0e10cSrcweir 	}
392*cdf0e10cSrcweir 	return 0;
393*cdf0e10cSrcweir }
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir sal_Bool SfxMenuControl::IsSpecialControl( sal_uInt16 nId, SfxModule* pMod  )
396*cdf0e10cSrcweir {
397*cdf0e10cSrcweir 	TypeId aSlotType = SFX_SLOTPOOL().GetSlotType( nId );
398*cdf0e10cSrcweir 	if ( aSlotType )
399*cdf0e10cSrcweir 	{
400*cdf0e10cSrcweir 		if ( pMod )
401*cdf0e10cSrcweir 		{
402*cdf0e10cSrcweir 			SfxMenuCtrlFactArr_Impl *pFactories = pMod->GetMenuCtrlFactories_Impl();
403*cdf0e10cSrcweir 			if ( pFactories )
404*cdf0e10cSrcweir 			{
405*cdf0e10cSrcweir 				SfxMenuCtrlFactArr_Impl &rFactories = *pFactories;
406*cdf0e10cSrcweir 				for ( sal_uInt16 nFactory = 0; nFactory < rFactories.Count(); ++nFactory )
407*cdf0e10cSrcweir 					if ( rFactories[nFactory]->nTypeId == aSlotType &&
408*cdf0e10cSrcweir 						 ( ( rFactories[nFactory]->nSlotId == 0 ) ||
409*cdf0e10cSrcweir 						   ( rFactories[nFactory]->nSlotId == nId) ) )
410*cdf0e10cSrcweir 						return sal_True;
411*cdf0e10cSrcweir 			}
412*cdf0e10cSrcweir 		}
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir         SfxMenuCtrlFactArr_Impl &rFactories = SFX_APP()->GetMenuCtrlFactories_Impl();
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir 		for ( sal_uInt16 nFactory = 0; nFactory < rFactories.Count(); ++nFactory )
417*cdf0e10cSrcweir 			if ( rFactories[nFactory]->nTypeId == aSlotType &&
418*cdf0e10cSrcweir 				 ( ( rFactories[nFactory]->nSlotId == 0 ) ||
419*cdf0e10cSrcweir 				   ( rFactories[nFactory]->nSlotId == nId) ) )
420*cdf0e10cSrcweir 				return sal_True;
421*cdf0e10cSrcweir 	}
422*cdf0e10cSrcweir 	return 0;
423*cdf0e10cSrcweir }
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir //--------------------------------------------------------------------
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir PopupMenu* SfxMenuControl::GetPopup () const
428*cdf0e10cSrcweir {
429*cdf0e10cSrcweir 	if (GetPopupMenu())
430*cdf0e10cSrcweir 		return (PopupMenu*)GetPopupMenu()->GetSVMenu();
431*cdf0e10cSrcweir 	else
432*cdf0e10cSrcweir 		return 0;
433*cdf0e10cSrcweir }
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir long Select_Impl( void* pHdl, void* pVoid );
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir SFX_IMPL_MENU_CONTROL( SfxAppMenuControl_Impl, SfxStringItem );
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir SfxAppMenuControl_Impl::SfxAppMenuControl_Impl(
440*cdf0e10cSrcweir 	sal_uInt16 nPos, Menu& rMenu, SfxBindings& rBindings )
441*cdf0e10cSrcweir 	: SfxMenuControl( nPos, rBindings ), pMenu(0)
442*cdf0e10cSrcweir {
443*cdf0e10cSrcweir 	String aText = rMenu.GetItemText( nPos );
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir 	// Determine the current background color setting for menus
446*cdf0e10cSrcweir 	const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
447*cdf0e10cSrcweir     m_nSymbolsStyle         = rSettings.GetSymbolsStyle();
448*cdf0e10cSrcweir     m_bWasHiContrastMode    = rSettings.GetHighContrastMode();
449*cdf0e10cSrcweir 	m_bShowMenuImages		= rSettings.GetUseImagesInMenus();
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir     Reference<com::sun::star::lang::XMultiServiceFactory> aXMultiServiceFactory(::comphelper::getProcessServiceFactory());
452*cdf0e10cSrcweir     ::framework::MenuConfiguration aConf( aXMultiServiceFactory );
453*cdf0e10cSrcweir     Reference<com::sun::star::frame::XFrame> aXFrame( GetBindings().GetDispatcher_Impl()->GetFrame()->GetFrame().GetFrameInterface() );
454*cdf0e10cSrcweir     pMenu = aConf.CreateBookmarkMenu( aXFrame, GetId() == SID_NEWDOCDIRECT ? BOOKMARK_NEWMENU : BOOKMARK_WIZARDMENU );
455*cdf0e10cSrcweir 	if( pMenu )
456*cdf0e10cSrcweir     {
457*cdf0e10cSrcweir         pMenu->SetSelectHdl( Link( &(this->GetBindings()), Select_Impl ) );
458*cdf0e10cSrcweir 		pMenu->SetActivateHdl( LINK(this, SfxAppMenuControl_Impl, Activate) );
459*cdf0e10cSrcweir         rMenu.SetPopupMenu( nPos, pMenu );
460*cdf0e10cSrcweir     }
461*cdf0e10cSrcweir }
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir SfxAppMenuControl_Impl::~SfxAppMenuControl_Impl()
464*cdf0e10cSrcweir {
465*cdf0e10cSrcweir     delete pMenu;
466*cdf0e10cSrcweir }
467*cdf0e10cSrcweir 
468*cdf0e10cSrcweir IMPL_LINK( SfxAppMenuControl_Impl, Activate, Menu *, pActMenu )
469*cdf0e10cSrcweir {
470*cdf0e10cSrcweir 	if ( pActMenu )
471*cdf0e10cSrcweir 	{
472*cdf0e10cSrcweir 		const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
473*cdf0e10cSrcweir         sal_uIntPtr nSymbolsStyle = rSettings.GetSymbolsStyle();
474*cdf0e10cSrcweir 		sal_Bool bIsHiContrastMode = rSettings.GetHighContrastMode();
475*cdf0e10cSrcweir         sal_Bool bShowMenuImages = rSettings.GetUseImagesInMenus();
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir         if (( nSymbolsStyle != m_nSymbolsStyle ) ||
478*cdf0e10cSrcweir             ( bIsHiContrastMode != m_bWasHiContrastMode ) ||
479*cdf0e10cSrcweir             ( bShowMenuImages != m_bShowMenuImages ))
480*cdf0e10cSrcweir         {
481*cdf0e10cSrcweir             m_nSymbolsStyle         = nSymbolsStyle;
482*cdf0e10cSrcweir 			m_bWasHiContrastMode	= bIsHiContrastMode;
483*cdf0e10cSrcweir 			m_bShowMenuImages		= bShowMenuImages;
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir 			sal_uInt16 nCount = pActMenu->GetItemCount();
486*cdf0e10cSrcweir 			for ( sal_uInt16 nSVPos = 0; nSVPos < nCount; nSVPos++ )
487*cdf0e10cSrcweir 			{
488*cdf0e10cSrcweir 				sal_uInt16 nItemId = pActMenu->GetItemId( nSVPos );
489*cdf0e10cSrcweir 				if ( pActMenu->GetItemType( nSVPos ) != MENUITEM_SEPARATOR )
490*cdf0e10cSrcweir 				{
491*cdf0e10cSrcweir 					if ( bShowMenuImages )
492*cdf0e10cSrcweir 					{
493*cdf0e10cSrcweir 						sal_Bool		bImageSet = sal_False;
494*cdf0e10cSrcweir 						::rtl::OUString aImageId;
495*cdf0e10cSrcweir 						::framework::MenuConfiguration::Attributes* pMenuAttributes =
496*cdf0e10cSrcweir 							(::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( nItemId );
497*cdf0e10cSrcweir 
498*cdf0e10cSrcweir 						if ( pMenuAttributes )
499*cdf0e10cSrcweir 							aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes
500*cdf0e10cSrcweir 
501*cdf0e10cSrcweir                         if ( aImageId.getLength() > 0 )
502*cdf0e10cSrcweir 						{
503*cdf0e10cSrcweir                             Reference< ::com::sun::star::frame::XFrame > xFrame;
504*cdf0e10cSrcweir 							Image aImage = GetImage( xFrame, aImageId, sal_False, bIsHiContrastMode );
505*cdf0e10cSrcweir 							if ( !!aImage )
506*cdf0e10cSrcweir 							{
507*cdf0e10cSrcweir 								bImageSet = sal_True;
508*cdf0e10cSrcweir 								pActMenu->SetItemImage( nItemId, aImage );
509*cdf0e10cSrcweir 							}
510*cdf0e10cSrcweir 						}
511*cdf0e10cSrcweir 
512*cdf0e10cSrcweir 						String aCmd( pActMenu->GetItemCommand( nItemId ) );
513*cdf0e10cSrcweir 						if ( !bImageSet && aCmd.Len() )
514*cdf0e10cSrcweir 						{
515*cdf0e10cSrcweir 							Image aImage = SvFileInformationManager::GetImage(
516*cdf0e10cSrcweir 								INetURLObject(aCmd), sal_False, bIsHiContrastMode );
517*cdf0e10cSrcweir 							if ( !!aImage )
518*cdf0e10cSrcweir 								pActMenu->SetItemImage( nItemId, aImage );
519*cdf0e10cSrcweir 						}
520*cdf0e10cSrcweir 					}
521*cdf0e10cSrcweir 					else
522*cdf0e10cSrcweir 						pActMenu->SetItemImage( nItemId, Image() );
523*cdf0e10cSrcweir 				}
524*cdf0e10cSrcweir 			}
525*cdf0e10cSrcweir 		}
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir 		return sal_True;
528*cdf0e10cSrcweir 	}
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir 	return sal_False;
531*cdf0e10cSrcweir }
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir SfxUnoMenuControl* SfxMenuControl::CreateControl( const String& rCmd,
534*cdf0e10cSrcweir 		sal_uInt16 nId, Menu& rMenu, SfxBindings &rBindings, SfxVirtualMenu* pVirt )
535*cdf0e10cSrcweir {
536*cdf0e10cSrcweir 	return new SfxUnoMenuControl( rCmd, nId, rMenu, rBindings, pVirt );
537*cdf0e10cSrcweir }
538*cdf0e10cSrcweir 
539*cdf0e10cSrcweir SfxUnoMenuControl* SfxMenuControl::CreateControl( const String& rCmd,
540*cdf0e10cSrcweir         sal_uInt16 nId, Menu& rMenu, const String& sItemText, const String& sHelpText,
541*cdf0e10cSrcweir         SfxBindings& rBindings, SfxVirtualMenu* pVirt)
542*cdf0e10cSrcweir {
543*cdf0e10cSrcweir     return new SfxUnoMenuControl( rCmd, nId, rMenu, sItemText, sHelpText, rBindings, pVirt);
544*cdf0e10cSrcweir }
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir SfxUnoMenuControl::SfxUnoMenuControl( const String& rCmd, sal_uInt16 nSlotId,
547*cdf0e10cSrcweir 	Menu& rMenu, SfxBindings& rBindings, SfxVirtualMenu* pVirt )
548*cdf0e10cSrcweir 	: SfxMenuControl( nSlotId, rBindings )
549*cdf0e10cSrcweir {
550*cdf0e10cSrcweir 	Bind( pVirt, nSlotId, rMenu.GetItemText(nSlotId),
551*cdf0e10cSrcweir 						rMenu.GetHelpText(nSlotId), rBindings);
552*cdf0e10cSrcweir 	UnBind();
553*cdf0e10cSrcweir 	pUnoCtrl = new SfxUnoControllerItem( this, rBindings, rCmd );
554*cdf0e10cSrcweir 	pUnoCtrl->acquire();
555*cdf0e10cSrcweir 	pUnoCtrl->GetNewDispatch();
556*cdf0e10cSrcweir }
557*cdf0e10cSrcweir 
558*cdf0e10cSrcweir SfxUnoMenuControl::SfxUnoMenuControl(
559*cdf0e10cSrcweir     const String& rCmd, sal_uInt16 nSlotId, Menu& /*rMenu*/,
560*cdf0e10cSrcweir     const String& rItemText, const String& rHelpText,
561*cdf0e10cSrcweir     SfxBindings& rBindings, SfxVirtualMenu* pVirt)
562*cdf0e10cSrcweir 	: SfxMenuControl( nSlotId, rBindings )
563*cdf0e10cSrcweir {
564*cdf0e10cSrcweir 	Bind( pVirt, nSlotId, rItemText, rHelpText, rBindings);
565*cdf0e10cSrcweir 	UnBind();
566*cdf0e10cSrcweir 	pUnoCtrl = new SfxUnoControllerItem( this, rBindings, rCmd );
567*cdf0e10cSrcweir 	pUnoCtrl->acquire();
568*cdf0e10cSrcweir 	pUnoCtrl->GetNewDispatch();
569*cdf0e10cSrcweir }
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir SfxUnoMenuControl::~SfxUnoMenuControl()
572*cdf0e10cSrcweir {
573*cdf0e10cSrcweir 	pUnoCtrl->UnBind();
574*cdf0e10cSrcweir 	pUnoCtrl->release();
575*cdf0e10cSrcweir }
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir void SfxUnoMenuControl::Select()
578*cdf0e10cSrcweir {
579*cdf0e10cSrcweir 	pUnoCtrl->Execute();
580*cdf0e10cSrcweir }
581