1*d119d52dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*d119d52dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*d119d52dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*d119d52dSAndrew Rist * distributed with this work for additional information 6*d119d52dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*d119d52dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*d119d52dSAndrew Rist * "License"); you may not use this file except in compliance 9*d119d52dSAndrew Rist * with the License. You may obtain a copy of the License at 10*d119d52dSAndrew Rist * 11*d119d52dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*d119d52dSAndrew Rist * 13*d119d52dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*d119d52dSAndrew Rist * software distributed under the License is distributed on an 15*d119d52dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*d119d52dSAndrew Rist * KIND, either express or implied. See the License for the 17*d119d52dSAndrew Rist * specific language governing permissions and limitations 18*d119d52dSAndrew Rist * under the License. 19*d119d52dSAndrew Rist * 20*d119d52dSAndrew Rist *************************************************************/ 21*d119d52dSAndrew Rist 22*d119d52dSAndrew 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(); 294cdf0e10cSrcweir } 295cdf0e10cSrcweir else if ( pState->ISA(SfxEnumItemInterface) && 296cdf0e10cSrcweir ((SfxEnumItemInterface *)pState)->HasBoolValue() ) 297cdf0e10cSrcweir { 298cdf0e10cSrcweir // EnumItem wie Bool behandeln 299cdf0e10cSrcweir DBG_ASSERT( GetId() < SID_OBJECTMENU0 || GetId() > SID_OBJECTMENU_LAST, 300cdf0e10cSrcweir "SfxEnumItem not allowed for SID_OBJECTMENUx" ); 301cdf0e10cSrcweir bCheck = ((SfxEnumItemInterface *)pState)->GetBoolValue(); 302cdf0e10cSrcweir } 303cdf0e10cSrcweir else if ( ( b_ShowStrings || bIsObjMenu ) && pState->ISA(SfxStringItem) ) 304cdf0e10cSrcweir { 305cdf0e10cSrcweir // MenuText aus SfxStringItem holen 306cdf0e10cSrcweir String aStr( ((const SfxStringItem*)pState)->GetValue() ); 307cdf0e10cSrcweir if ( aStr.CompareToAscii("($1)",4) == COMPARE_EQUAL ) 308cdf0e10cSrcweir { 309cdf0e10cSrcweir String aEntry(SfxResId(STR_UPDATEDOC)); 310cdf0e10cSrcweir aEntry += ' '; 311cdf0e10cSrcweir aEntry += aStr.Copy(4); 312cdf0e10cSrcweir aStr = aEntry; 313cdf0e10cSrcweir } 314cdf0e10cSrcweir else if ( aStr.CompareToAscii("($2)",4) == COMPARE_EQUAL ) 315cdf0e10cSrcweir { 316cdf0e10cSrcweir String aEntry(SfxResId(STR_CLOSEDOC_ANDRETURN)); 317cdf0e10cSrcweir aEntry += aStr.Copy(4); 318cdf0e10cSrcweir aStr = aEntry; 319cdf0e10cSrcweir } 320cdf0e10cSrcweir 321cdf0e10cSrcweir pOwnMenu->SetItemText( GetId(), aStr ); 322cdf0e10cSrcweir } 323cdf0e10cSrcweir 324cdf0e10cSrcweir #ifdef enum_item_menu_ok 325cdf0e10cSrcweir else if ( aType == TYPE(SfxEnumItem) ) 326cdf0e10cSrcweir { 327cdf0e10cSrcweir DBG_ASSERT( GetId() < SID_OBJECTMENU0 || GetId() > SID_OBJECTMENU_LAST, 328cdf0e10cSrcweir "SfxEnumItem not allowed for SID_OBJECTMENUx" ); 329cdf0e10cSrcweir pOwnMenu->GetMenu().ChangePopupMenu( GetId(), &GetBindings(), 330cdf0e10cSrcweir new SfxEnumMenu( GetId(), *(const SfxEnumItem*)pState ) ); 331cdf0e10cSrcweir } 332cdf0e10cSrcweir #endif 333cdf0e10cSrcweir 334cdf0e10cSrcweir pOwnMenu->CheckItem( GetId(), bCheck ); 335cdf0e10cSrcweir } 336cdf0e10cSrcweir 337cdf0e10cSrcweir //-------------------------------------------------------------------- 338cdf0e10cSrcweir 339cdf0e10cSrcweir SfxMenuControl* SfxMenuControl::CreateImpl( sal_uInt16 /*nId*/, Menu& /*rMenu*/, SfxBindings& /*rBindings*/ ) 340cdf0e10cSrcweir { 341cdf0e10cSrcweir return new SfxMenuControl( sal_True ); 342cdf0e10cSrcweir } 343cdf0e10cSrcweir 344cdf0e10cSrcweir //-------------------------------------------------------------------- 345cdf0e10cSrcweir 346cdf0e10cSrcweir void SfxMenuControl::RegisterControl( sal_uInt16 nSlotId, SfxModule *pMod ) 347cdf0e10cSrcweir { 348cdf0e10cSrcweir RegisterMenuControl( pMod, new SfxMenuCtrlFactory( 349cdf0e10cSrcweir SfxMenuControl::CreateImpl, TYPE(SfxStringItem), nSlotId ) ); 350cdf0e10cSrcweir } 351cdf0e10cSrcweir 352cdf0e10cSrcweir //-------------------------------------------------------------------- 353cdf0e10cSrcweir void SfxMenuControl::RegisterMenuControl(SfxModule* pMod, SfxMenuCtrlFactory* pFact) 354cdf0e10cSrcweir { 355cdf0e10cSrcweir SFX_APP()->RegisterMenuControl_Impl( pMod, pFact ); 356cdf0e10cSrcweir } 357cdf0e10cSrcweir 358cdf0e10cSrcweir SfxMenuControl* SfxMenuControl::CreateControl( sal_uInt16 nId, Menu &rMenu, SfxBindings &rBindings ) 359cdf0e10cSrcweir { 360cdf0e10cSrcweir TypeId aSlotType = SFX_SLOTPOOL().GetSlotType(nId); 361cdf0e10cSrcweir if ( aSlotType ) 362cdf0e10cSrcweir { 363cdf0e10cSrcweir SfxApplication *pApp = SFX_APP(); 364cdf0e10cSrcweir SfxDispatcher *pDisp = rBindings.GetDispatcher_Impl(); 365cdf0e10cSrcweir SfxModule *pMod = pDisp ? SfxModule::GetActiveModule( pDisp->GetFrame() ) :0; 366cdf0e10cSrcweir if ( pMod ) 367cdf0e10cSrcweir { 368cdf0e10cSrcweir SfxMenuCtrlFactArr_Impl *pFactories = pMod->GetMenuCtrlFactories_Impl(); 369cdf0e10cSrcweir if ( pFactories ) 370cdf0e10cSrcweir { 371cdf0e10cSrcweir SfxMenuCtrlFactArr_Impl &rFactories = *pFactories; 372cdf0e10cSrcweir for ( sal_uInt16 nFactory = 0; nFactory < rFactories.Count(); ++nFactory ) 373cdf0e10cSrcweir if ( rFactories[nFactory]->nTypeId == aSlotType && 374cdf0e10cSrcweir ( ( rFactories[nFactory]->nSlotId == 0 ) || 375cdf0e10cSrcweir ( rFactories[nFactory]->nSlotId == nId) ) ) 376cdf0e10cSrcweir return rFactories[nFactory]->pCtor( nId, rMenu, rBindings ); 377cdf0e10cSrcweir } 378cdf0e10cSrcweir } 379cdf0e10cSrcweir 380cdf0e10cSrcweir SfxMenuCtrlFactArr_Impl &rFactories = pApp->GetMenuCtrlFactories_Impl(); 381cdf0e10cSrcweir 382cdf0e10cSrcweir for ( sal_uInt16 nFactory = 0; nFactory < rFactories.Count(); ++nFactory ) 383cdf0e10cSrcweir if ( rFactories[nFactory]->nTypeId == aSlotType && 384cdf0e10cSrcweir ( ( rFactories[nFactory]->nSlotId == 0 ) || 385cdf0e10cSrcweir ( rFactories[nFactory]->nSlotId == nId) ) ) 386cdf0e10cSrcweir return rFactories[nFactory]->pCtor( nId, rMenu, rBindings ); 387cdf0e10cSrcweir } 388cdf0e10cSrcweir return 0; 389cdf0e10cSrcweir } 390cdf0e10cSrcweir 391cdf0e10cSrcweir sal_Bool SfxMenuControl::IsSpecialControl( sal_uInt16 nId, SfxModule* pMod ) 392cdf0e10cSrcweir { 393cdf0e10cSrcweir TypeId aSlotType = SFX_SLOTPOOL().GetSlotType( nId ); 394cdf0e10cSrcweir if ( aSlotType ) 395cdf0e10cSrcweir { 396cdf0e10cSrcweir if ( pMod ) 397cdf0e10cSrcweir { 398cdf0e10cSrcweir SfxMenuCtrlFactArr_Impl *pFactories = pMod->GetMenuCtrlFactories_Impl(); 399cdf0e10cSrcweir if ( pFactories ) 400cdf0e10cSrcweir { 401cdf0e10cSrcweir SfxMenuCtrlFactArr_Impl &rFactories = *pFactories; 402cdf0e10cSrcweir for ( sal_uInt16 nFactory = 0; nFactory < rFactories.Count(); ++nFactory ) 403cdf0e10cSrcweir if ( rFactories[nFactory]->nTypeId == aSlotType && 404cdf0e10cSrcweir ( ( rFactories[nFactory]->nSlotId == 0 ) || 405cdf0e10cSrcweir ( rFactories[nFactory]->nSlotId == nId) ) ) 406cdf0e10cSrcweir return sal_True; 407cdf0e10cSrcweir } 408cdf0e10cSrcweir } 409cdf0e10cSrcweir 410cdf0e10cSrcweir SfxMenuCtrlFactArr_Impl &rFactories = SFX_APP()->GetMenuCtrlFactories_Impl(); 411cdf0e10cSrcweir 412cdf0e10cSrcweir for ( sal_uInt16 nFactory = 0; nFactory < rFactories.Count(); ++nFactory ) 413cdf0e10cSrcweir if ( rFactories[nFactory]->nTypeId == aSlotType && 414cdf0e10cSrcweir ( ( rFactories[nFactory]->nSlotId == 0 ) || 415cdf0e10cSrcweir ( rFactories[nFactory]->nSlotId == nId) ) ) 416cdf0e10cSrcweir return sal_True; 417cdf0e10cSrcweir } 418cdf0e10cSrcweir return 0; 419cdf0e10cSrcweir } 420cdf0e10cSrcweir 421cdf0e10cSrcweir //-------------------------------------------------------------------- 422cdf0e10cSrcweir 423cdf0e10cSrcweir PopupMenu* SfxMenuControl::GetPopup () const 424cdf0e10cSrcweir { 425cdf0e10cSrcweir if (GetPopupMenu()) 426cdf0e10cSrcweir return (PopupMenu*)GetPopupMenu()->GetSVMenu(); 427cdf0e10cSrcweir else 428cdf0e10cSrcweir return 0; 429cdf0e10cSrcweir } 430cdf0e10cSrcweir 431cdf0e10cSrcweir long Select_Impl( void* pHdl, void* pVoid ); 432cdf0e10cSrcweir 433cdf0e10cSrcweir SFX_IMPL_MENU_CONTROL( SfxAppMenuControl_Impl, SfxStringItem ); 434cdf0e10cSrcweir 435cdf0e10cSrcweir SfxAppMenuControl_Impl::SfxAppMenuControl_Impl( 436cdf0e10cSrcweir sal_uInt16 nPos, Menu& rMenu, SfxBindings& rBindings ) 437cdf0e10cSrcweir : SfxMenuControl( nPos, rBindings ), pMenu(0) 438cdf0e10cSrcweir { 439cdf0e10cSrcweir String aText = rMenu.GetItemText( nPos ); 440cdf0e10cSrcweir 441cdf0e10cSrcweir // Determine the current background color setting for menus 442cdf0e10cSrcweir const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings(); 443cdf0e10cSrcweir m_nSymbolsStyle = rSettings.GetSymbolsStyle(); 444cdf0e10cSrcweir m_bWasHiContrastMode = rSettings.GetHighContrastMode(); 445cdf0e10cSrcweir m_bShowMenuImages = rSettings.GetUseImagesInMenus(); 446cdf0e10cSrcweir 447cdf0e10cSrcweir Reference<com::sun::star::lang::XMultiServiceFactory> aXMultiServiceFactory(::comphelper::getProcessServiceFactory()); 448cdf0e10cSrcweir ::framework::MenuConfiguration aConf( aXMultiServiceFactory ); 449cdf0e10cSrcweir Reference<com::sun::star::frame::XFrame> aXFrame( GetBindings().GetDispatcher_Impl()->GetFrame()->GetFrame().GetFrameInterface() ); 450cdf0e10cSrcweir pMenu = aConf.CreateBookmarkMenu( aXFrame, GetId() == SID_NEWDOCDIRECT ? BOOKMARK_NEWMENU : BOOKMARK_WIZARDMENU ); 451cdf0e10cSrcweir if( pMenu ) 452cdf0e10cSrcweir { 453cdf0e10cSrcweir pMenu->SetSelectHdl( Link( &(this->GetBindings()), Select_Impl ) ); 454cdf0e10cSrcweir pMenu->SetActivateHdl( LINK(this, SfxAppMenuControl_Impl, Activate) ); 455cdf0e10cSrcweir rMenu.SetPopupMenu( nPos, pMenu ); 456cdf0e10cSrcweir } 457cdf0e10cSrcweir } 458cdf0e10cSrcweir 459cdf0e10cSrcweir SfxAppMenuControl_Impl::~SfxAppMenuControl_Impl() 460cdf0e10cSrcweir { 461cdf0e10cSrcweir delete pMenu; 462cdf0e10cSrcweir } 463cdf0e10cSrcweir 464cdf0e10cSrcweir IMPL_LINK( SfxAppMenuControl_Impl, Activate, Menu *, pActMenu ) 465cdf0e10cSrcweir { 466cdf0e10cSrcweir if ( pActMenu ) 467cdf0e10cSrcweir { 468cdf0e10cSrcweir const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings(); 469cdf0e10cSrcweir sal_uIntPtr nSymbolsStyle = rSettings.GetSymbolsStyle(); 470cdf0e10cSrcweir sal_Bool bIsHiContrastMode = rSettings.GetHighContrastMode(); 471cdf0e10cSrcweir sal_Bool bShowMenuImages = rSettings.GetUseImagesInMenus(); 472cdf0e10cSrcweir 473cdf0e10cSrcweir if (( nSymbolsStyle != m_nSymbolsStyle ) || 474cdf0e10cSrcweir ( bIsHiContrastMode != m_bWasHiContrastMode ) || 475cdf0e10cSrcweir ( bShowMenuImages != m_bShowMenuImages )) 476cdf0e10cSrcweir { 477cdf0e10cSrcweir m_nSymbolsStyle = nSymbolsStyle; 478cdf0e10cSrcweir m_bWasHiContrastMode = bIsHiContrastMode; 479cdf0e10cSrcweir m_bShowMenuImages = bShowMenuImages; 480cdf0e10cSrcweir 481cdf0e10cSrcweir sal_uInt16 nCount = pActMenu->GetItemCount(); 482cdf0e10cSrcweir for ( sal_uInt16 nSVPos = 0; nSVPos < nCount; nSVPos++ ) 483cdf0e10cSrcweir { 484cdf0e10cSrcweir sal_uInt16 nItemId = pActMenu->GetItemId( nSVPos ); 485cdf0e10cSrcweir if ( pActMenu->GetItemType( nSVPos ) != MENUITEM_SEPARATOR ) 486cdf0e10cSrcweir { 487cdf0e10cSrcweir if ( bShowMenuImages ) 488cdf0e10cSrcweir { 489cdf0e10cSrcweir sal_Bool bImageSet = sal_False; 490cdf0e10cSrcweir ::rtl::OUString aImageId; 491cdf0e10cSrcweir ::framework::MenuConfiguration::Attributes* pMenuAttributes = 492cdf0e10cSrcweir (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( nItemId ); 493cdf0e10cSrcweir 494cdf0e10cSrcweir if ( pMenuAttributes ) 495cdf0e10cSrcweir aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes 496cdf0e10cSrcweir 497cdf0e10cSrcweir if ( aImageId.getLength() > 0 ) 498cdf0e10cSrcweir { 499cdf0e10cSrcweir Reference< ::com::sun::star::frame::XFrame > xFrame; 500cdf0e10cSrcweir Image aImage = GetImage( xFrame, aImageId, sal_False, bIsHiContrastMode ); 501cdf0e10cSrcweir if ( !!aImage ) 502cdf0e10cSrcweir { 503cdf0e10cSrcweir bImageSet = sal_True; 504cdf0e10cSrcweir pActMenu->SetItemImage( nItemId, aImage ); 505cdf0e10cSrcweir } 506cdf0e10cSrcweir } 507cdf0e10cSrcweir 508cdf0e10cSrcweir String aCmd( pActMenu->GetItemCommand( nItemId ) ); 509cdf0e10cSrcweir if ( !bImageSet && aCmd.Len() ) 510cdf0e10cSrcweir { 511cdf0e10cSrcweir Image aImage = SvFileInformationManager::GetImage( 512cdf0e10cSrcweir INetURLObject(aCmd), sal_False, bIsHiContrastMode ); 513cdf0e10cSrcweir if ( !!aImage ) 514cdf0e10cSrcweir pActMenu->SetItemImage( nItemId, aImage ); 515cdf0e10cSrcweir } 516cdf0e10cSrcweir } 517cdf0e10cSrcweir else 518cdf0e10cSrcweir pActMenu->SetItemImage( nItemId, Image() ); 519cdf0e10cSrcweir } 520cdf0e10cSrcweir } 521cdf0e10cSrcweir } 522cdf0e10cSrcweir 523cdf0e10cSrcweir return sal_True; 524cdf0e10cSrcweir } 525cdf0e10cSrcweir 526cdf0e10cSrcweir return sal_False; 527cdf0e10cSrcweir } 528cdf0e10cSrcweir 529cdf0e10cSrcweir SfxUnoMenuControl* SfxMenuControl::CreateControl( const String& rCmd, 530cdf0e10cSrcweir sal_uInt16 nId, Menu& rMenu, SfxBindings &rBindings, SfxVirtualMenu* pVirt ) 531cdf0e10cSrcweir { 532cdf0e10cSrcweir return new SfxUnoMenuControl( rCmd, nId, rMenu, rBindings, pVirt ); 533cdf0e10cSrcweir } 534cdf0e10cSrcweir 535cdf0e10cSrcweir SfxUnoMenuControl* SfxMenuControl::CreateControl( const String& rCmd, 536cdf0e10cSrcweir sal_uInt16 nId, Menu& rMenu, const String& sItemText, const String& sHelpText, 537cdf0e10cSrcweir SfxBindings& rBindings, SfxVirtualMenu* pVirt) 538cdf0e10cSrcweir { 539cdf0e10cSrcweir return new SfxUnoMenuControl( rCmd, nId, rMenu, sItemText, sHelpText, rBindings, pVirt); 540cdf0e10cSrcweir } 541cdf0e10cSrcweir 542cdf0e10cSrcweir SfxUnoMenuControl::SfxUnoMenuControl( const String& rCmd, sal_uInt16 nSlotId, 543cdf0e10cSrcweir Menu& rMenu, SfxBindings& rBindings, SfxVirtualMenu* pVirt ) 544cdf0e10cSrcweir : SfxMenuControl( nSlotId, rBindings ) 545cdf0e10cSrcweir { 546cdf0e10cSrcweir Bind( pVirt, nSlotId, rMenu.GetItemText(nSlotId), 547cdf0e10cSrcweir rMenu.GetHelpText(nSlotId), rBindings); 548cdf0e10cSrcweir UnBind(); 549cdf0e10cSrcweir pUnoCtrl = new SfxUnoControllerItem( this, rBindings, rCmd ); 550cdf0e10cSrcweir pUnoCtrl->acquire(); 551cdf0e10cSrcweir pUnoCtrl->GetNewDispatch(); 552cdf0e10cSrcweir } 553cdf0e10cSrcweir 554cdf0e10cSrcweir SfxUnoMenuControl::SfxUnoMenuControl( 555cdf0e10cSrcweir const String& rCmd, sal_uInt16 nSlotId, Menu& /*rMenu*/, 556cdf0e10cSrcweir const String& rItemText, const String& rHelpText, 557cdf0e10cSrcweir SfxBindings& rBindings, SfxVirtualMenu* pVirt) 558cdf0e10cSrcweir : SfxMenuControl( nSlotId, rBindings ) 559cdf0e10cSrcweir { 560cdf0e10cSrcweir Bind( pVirt, nSlotId, rItemText, rHelpText, rBindings); 561cdf0e10cSrcweir UnBind(); 562cdf0e10cSrcweir pUnoCtrl = new SfxUnoControllerItem( this, rBindings, rCmd ); 563cdf0e10cSrcweir pUnoCtrl->acquire(); 564cdf0e10cSrcweir pUnoCtrl->GetNewDispatch(); 565cdf0e10cSrcweir } 566cdf0e10cSrcweir 567cdf0e10cSrcweir SfxUnoMenuControl::~SfxUnoMenuControl() 568cdf0e10cSrcweir { 569cdf0e10cSrcweir pUnoCtrl->UnBind(); 570cdf0e10cSrcweir pUnoCtrl->release(); 571cdf0e10cSrcweir } 572cdf0e10cSrcweir 573cdf0e10cSrcweir void SfxUnoMenuControl::Select() 574cdf0e10cSrcweir { 575cdf0e10cSrcweir pUnoCtrl->Execute(); 576cdf0e10cSrcweir } 577