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