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