calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / framework / source / uielement / toolbarsmenucontroller.cxx
blob73019024033498465b7c7937bdbeb13c6c5c5695
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <uielement/toolbarsmenucontroller.hxx>
22 #include <algorithm>
23 #include <string_view>
24 #include <unordered_map>
26 #include <services.h>
27 #include <strings.hrc>
28 #include <classes/fwkresid.hxx>
29 #include <framework/sfxhelperfunctions.hxx>
30 #include <uiconfiguration/windowstateproperties.hxx>
32 #include <com/sun/star/beans/PropertyValue.hpp>
33 #include <com/sun/star/awt/MenuItemStyle.hpp>
34 #include <com/sun/star/frame/ModuleManager.hpp>
35 #include <com/sun/star/frame/XDispatchProvider.hpp>
36 #include <com/sun/star/util/XURLTransformer.hpp>
37 #include <com/sun/star/beans/XPropertySet.hpp>
38 #include <com/sun/star/frame/XLayoutManager.hpp>
39 #include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
40 #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
41 #include <com/sun/star/ui/UIElementType.hpp>
42 #include <com/sun/star/ui/theWindowStateConfiguration.hpp>
44 #include <comphelper/propertyvalue.hxx>
45 #include <officecfg/Office/Common.hxx>
46 #include <vcl/svapp.hxx>
47 #include <vcl/settings.hxx>
48 #include <vcl/commandinfoprovider.hxx>
49 #include <rtl/ustrbuf.hxx>
50 #include <toolkit/helper/vclunohelper.hxx>
51 #include <vcl/window.hxx>
52 #include <unotools/cmdoptions.hxx>
53 #include <unotools/collatorwrapper.hxx>
54 #include <unotools/syslocale.hxx>
55 #include <cppuhelper/supportsservice.hxx>
57 // Defines
59 using namespace ::com::sun::star;
60 using namespace ::com::sun::star::uno;
61 using namespace ::com::sun::star::lang;
62 using namespace ::com::sun::star::frame;
63 using namespace ::com::sun::star::beans;
64 using namespace ::com::sun::star::util;
65 using namespace ::com::sun::star::container;
66 using namespace ::com::sun::star::ui;
68 constexpr OUStringLiteral CMD_RESTOREVISIBILITY = u".cmd:RestoreVisibility";
69 constexpr OUStringLiteral CMD_LOCKTOOLBARS = u".uno:ToolbarLock";
71 constexpr OUStringLiteral STATIC_CMD_PART = u".uno:AvailableToolbars?Toolbar:string=";
72 const char STATIC_INTERNAL_CMD_PART[] = ".cmd:";
74 namespace framework
77 typedef std::unordered_map< OUString, OUString > ToolbarHashMap;
79 namespace {
81 struct ToolBarEntry
83 OUString aUIName;
84 OUString aCommand;
85 bool bVisible;
86 const CollatorWrapper* pCollatorWrapper;
91 static bool CompareToolBarEntry( const ToolBarEntry& aOne, const ToolBarEntry& aTwo )
93 sal_Int32 nComp = aOne.pCollatorWrapper->compareString( aOne.aUIName, aTwo.aUIName );
95 return nComp < 0;
98 static Reference< XLayoutManager > getLayoutManagerFromFrame( const Reference< XFrame >& rFrame )
100 Reference< XPropertySet > xPropSet( rFrame, UNO_QUERY );
101 Reference< XLayoutManager > xLayoutManager;
105 xPropSet->getPropertyValue("LayoutManager") >>= xLayoutManager;
107 catch ( const UnknownPropertyException& )
111 return xLayoutManager;
114 namespace {
116 struct ToolBarInfo
118 OUString aToolBarResName;
119 OUString aToolBarUIName;
124 // XInterface, XTypeProvider, XServiceInfo
126 OUString SAL_CALL ToolbarsMenuController::getImplementationName()
128 return "com.sun.star.comp.framework.ToolBarsMenuController";
131 sal_Bool SAL_CALL ToolbarsMenuController::supportsService( const OUString& sServiceName )
133 return cppu::supportsService(this, sServiceName);
136 css::uno::Sequence< OUString > SAL_CALL ToolbarsMenuController::getSupportedServiceNames()
138 return { SERVICENAME_POPUPMENUCONTROLLER };
141 constexpr OUStringLiteral g_aPropUIName( u"UIName" );
142 constexpr OUStringLiteral g_aPropResourceURL( u"ResourceURL" );
144 ToolbarsMenuController::ToolbarsMenuController( const css::uno::Reference< css::uno::XComponentContext >& xContext ) :
145 svt::PopupMenuControllerBase( xContext ),
146 m_xContext( xContext ),
147 m_bResetActive( false ),
148 m_aIntlWrapper(SvtSysLocale().GetUILanguageTag())
152 ToolbarsMenuController::~ToolbarsMenuController()
156 void ToolbarsMenuController::addCommand(
157 Reference< css::awt::XPopupMenu > const & rPopupMenu, const OUString& rCommandURL, const OUString& rLabel )
159 sal_uInt16 nItemId = m_xPopupMenu->getItemCount()+1;
161 OUString aLabel;
162 if ( rLabel.isEmpty() )
164 auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(rCommandURL, m_aModuleName);
165 aLabel = vcl::CommandInfoProvider::GetMenuLabelForCommand(aProperties);
167 else
168 aLabel = rLabel;
170 rPopupMenu->insertItem( nItemId, aLabel, 0, nItemId );
171 rPopupMenu->setCommand( nItemId, rCommandURL );
173 bool bInternal = rCommandURL.startsWith( STATIC_INTERNAL_CMD_PART );
174 if ( !bInternal )
176 if ( !getDispatchFromCommandURL( rCommandURL ).is() )
177 m_xPopupMenu->enableItem( nItemId, false );
180 SolarMutexGuard aSolarMutexGuard;
182 css::uno::Reference<css::graphic::XGraphic> xGraphic;
183 const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
185 if ( rSettings.GetUseImagesInMenus() )
186 xGraphic = vcl::CommandInfoProvider::GetXGraphicForCommand(rCommandURL, m_xFrame);
188 if (xGraphic.is())
189 rPopupMenu->setItemImage(nItemId, xGraphic, false);
191 m_aCommandVector.push_back( rCommandURL );
194 Reference< XDispatch > ToolbarsMenuController::getDispatchFromCommandURL( const OUString& rCommandURL )
196 URL aTargetURL;
197 Reference< XURLTransformer > xURLTransformer;
198 Reference< XFrame > xFrame;
201 SolarMutexGuard aSolarMutexGuard;
202 xURLTransformer = m_xURLTransformer;
203 xFrame = m_xFrame;
206 aTargetURL.Complete = rCommandURL;
207 xURLTransformer->parseStrict( aTargetURL );
208 Reference< XDispatchProvider > xDispatchProvider( xFrame, UNO_QUERY );
209 if ( xDispatchProvider.is() )
210 return xDispatchProvider->queryDispatch( aTargetURL, OUString(), 0 );
211 else
212 return Reference< XDispatch >();
215 static void fillHashMap( const Sequence< Sequence< css::beans::PropertyValue > >& rSeqToolBars,
216 ToolbarHashMap& rHashMap )
218 for ( Sequence< css::beans::PropertyValue > const & props : rSeqToolBars )
220 OUString aResourceURL;
221 OUString aUIName;
222 for ( css::beans::PropertyValue const & prop : props )
224 if ( prop.Name == "ResourceURL" )
225 prop.Value >>= aResourceURL;
226 else if ( prop.Name == "UIName" )
227 prop.Value >>= aUIName;
230 if ( !aResourceURL.isEmpty() &&
231 rHashMap.find( aResourceURL ) == rHashMap.end() )
232 rHashMap.emplace( aResourceURL, aUIName );
236 // private function
237 Sequence< Sequence< css::beans::PropertyValue > > ToolbarsMenuController::getLayoutManagerToolbars( const Reference< css::frame::XLayoutManager >& rLayoutManager )
239 std::vector< ToolBarInfo > aToolBarArray;
240 const Sequence< Reference< XUIElement > > aUIElements = rLayoutManager->getElements();
241 for ( Reference< XUIElement > const & xUIElement : aUIElements )
243 Reference< XPropertySet > xPropSet( xUIElement, UNO_QUERY );
244 if ( xPropSet.is() && xUIElement.is() )
248 OUString aResName;
249 sal_Int16 nType( -1 );
250 xPropSet->getPropertyValue("Type") >>= nType;
251 xPropSet->getPropertyValue("ResourceURL") >>= aResName;
253 if (( nType == css::ui::UIElementType::TOOLBAR ) &&
254 !aResName.isEmpty() )
256 ToolBarInfo aToolBarInfo;
258 aToolBarInfo.aToolBarResName = aResName;
260 SolarMutexGuard aGuard;
261 Reference< css::awt::XWindow > xWindow( xUIElement->getRealInterface(), UNO_QUERY );
262 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
263 if ( pWindow )
264 aToolBarInfo.aToolBarUIName = pWindow->GetText();
266 aToolBarArray.push_back( aToolBarInfo );
269 catch ( const Exception& )
275 Sequence< Sequence< css::beans::PropertyValue > > aSeq( aToolBarArray.size() );
276 auto pSeq = aSeq.getArray();
277 const sal_uInt32 nCount = aToolBarArray.size();
278 for ( sal_uInt32 i = 0; i < nCount; i++ )
280 Sequence< css::beans::PropertyValue > aTbSeq{
281 comphelper::makePropertyValue(g_aPropUIName, aToolBarArray[i].aToolBarUIName),
282 comphelper::makePropertyValue(g_aPropResourceURL, aToolBarArray[i].aToolBarResName)
284 pSeq[i] = aTbSeq;
287 return aSeq;
291 void ToolbarsMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu > const & rPopupMenu )
293 if( officecfg::Office::Common::Misc::DisableUICustomization::get() )
294 return;
296 SolarMutexGuard aSolarMutexGuard;
297 resetPopupMenu( rPopupMenu );
299 m_aCommandVector.clear();
301 // Retrieve layout manager for additional information
302 Reference< XLayoutManager > xLayoutManager( getLayoutManagerFromFrame( m_xFrame ));
304 m_bResetActive = false;
305 if ( !xLayoutManager.is() )
306 return;
308 ToolbarHashMap aToolbarHashMap;
310 if ( m_xDocCfgMgr.is() )
312 Sequence< Sequence< css::beans::PropertyValue > > aSeqDocToolBars =
313 m_xDocCfgMgr->getUIElementsInfo( UIElementType::TOOLBAR );
314 fillHashMap( aSeqDocToolBars, aToolbarHashMap );
317 if ( m_xModuleCfgMgr.is() )
319 Sequence< Sequence< css::beans::PropertyValue > > aSeqToolBars =
320 m_xModuleCfgMgr->getUIElementsInfo( UIElementType::TOOLBAR );
321 fillHashMap( aSeqToolBars, aToolbarHashMap );
324 std::vector< ToolBarEntry > aSortedTbs;
325 OUString aStaticCmdPart( STATIC_CMD_PART );
327 Sequence< Sequence< css::beans::PropertyValue > > aSeqFrameToolBars = getLayoutManagerToolbars( xLayoutManager );
328 fillHashMap( aSeqFrameToolBars, aToolbarHashMap );
330 for (auto const& toolbar : aToolbarHashMap)
332 OUString aUIName = toolbar.second;
333 bool bHideFromMenu( false );
334 bool bContextSensitive( false );
335 if ( aUIName.isEmpty() &&
336 m_xPersistentWindowState.is() )
338 bool bVisible( false );
342 Sequence< PropertyValue > aWindowState;
343 Any a( m_xPersistentWindowState->getByName( toolbar.first ));
345 if ( a >>= aWindowState )
347 for ( PropertyValue const & prop : std::as_const(aWindowState) )
349 if ( prop.Name == WINDOWSTATE_PROPERTY_UINAME )
350 prop.Value >>= aUIName;
351 else if ( prop.Name == WINDOWSTATE_PROPERTY_HIDEFROMENU )
352 prop.Value >>= bHideFromMenu;
353 else if ( prop.Name == WINDOWSTATE_PROPERTY_CONTEXT )
354 prop.Value >>= bContextSensitive;
355 else if ( prop.Name == WINDOWSTATE_PROPERTY_VISIBLE )
356 prop.Value >>= bVisible;
360 catch ( const Exception& )
364 // Check if we have to enable/disable "Reset" menu item
365 if ( bContextSensitive && !bVisible )
366 m_bResetActive = true;
370 if ( !aUIName.isEmpty() && !bHideFromMenu )
372 ToolBarEntry aTbEntry;
373 aTbEntry.aUIName = aUIName;
374 aTbEntry.aCommand = toolbar.first;
375 aTbEntry.bVisible = xLayoutManager->isElementVisible( toolbar.first );
376 aTbEntry.pCollatorWrapper = m_aIntlWrapper.getCaseCollator();
377 aSortedTbs.push_back( aTbEntry );
381 // sort toolbars
382 std::sort( aSortedTbs.begin(), aSortedTbs.end(), CompareToolBarEntry );
384 sal_Int16 nIndex( 1 );
385 const sal_uInt32 nCount = aSortedTbs.size();
386 for ( sal_uInt32 i = 0; i < nCount; i++ )
388 sal_uInt16 nItemCount = m_xPopupMenu->getItemCount();
389 m_xPopupMenu->insertItem( nIndex, aSortedTbs[i].aUIName, css::awt::MenuItemStyle::CHECKABLE, nItemCount );
390 if ( aSortedTbs[i].bVisible )
391 m_xPopupMenu->checkItem( nIndex, true );
393 OUStringBuffer aStrBuf( aStaticCmdPart );
395 sal_Int32 n = aSortedTbs[i].aCommand.lastIndexOf( '/' );
396 if (( n > 0 ) && (( n+1 ) < aSortedTbs[i].aCommand.getLength() ))
397 aStrBuf.append( aSortedTbs[i].aCommand.subView(n+1) );
399 OUString aCmd( aStrBuf.makeStringAndClear() );
401 // Store complete uno-command so it can also be dispatched. This is necessary to support
402 // the test tool!
403 rPopupMenu->setCommand( nIndex, aCmd );
404 ++nIndex;
407 // Create commands for non-toolbars
409 bool bAddCommand( true );
410 SvtCommandOptions aCmdOptions;
412 if ( aCmdOptions.HasEntries( SvtCommandOptions::CMDOPTION_DISABLED ))
414 if ( aCmdOptions.Lookup( SvtCommandOptions::CMDOPTION_DISABLED,
415 "ConfigureDialog"))
416 bAddCommand = false;
419 if ( bAddCommand )
421 // Create command for configure
422 if ( m_xPopupMenu->getItemCount() > 0 )
424 sal_uInt16 nItemCount = m_xPopupMenu->getItemCount();
425 m_xPopupMenu->insertSeparator( nItemCount+1 );
428 addCommand( m_xPopupMenu, ".uno:ConfigureDialog", "" );
431 // Add separator if no configure has been added
432 if ( !bAddCommand )
434 // Create command for configure
435 if ( m_xPopupMenu->getItemCount() > 0 )
437 sal_uInt16 nItemCount = m_xPopupMenu->getItemCount();
438 m_xPopupMenu->insertSeparator( nItemCount+1 );
442 OUString aLabelStr(FwkResId(STR_RESTORE_TOOLBARS));
443 addCommand( m_xPopupMenu, CMD_RESTOREVISIBILITY, aLabelStr );
444 aLabelStr = FwkResId(STR_LOCK_TOOLBARS);
445 addCommand( m_xPopupMenu, CMD_LOCKTOOLBARS, aLabelStr );
448 // XEventListener
449 void SAL_CALL ToolbarsMenuController::disposing( const EventObject& )
451 Reference< css::awt::XMenuListener > xHolder(this);
453 osl::MutexGuard aLock( m_aMutex );
454 m_xFrame.clear();
455 m_xDispatch.clear();
456 m_xDocCfgMgr.clear();
457 m_xModuleCfgMgr.clear();
458 m_xContext.clear();
460 if ( m_xPopupMenu.is() )
461 m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(this) );
462 m_xPopupMenu.clear();
465 // XStatusListener
466 void SAL_CALL ToolbarsMenuController::statusChanged( const FeatureStateEvent& Event )
468 OUString aFeatureURL( Event.FeatureURL.Complete );
470 // All other status events will be processed here
471 osl::ClearableMutexGuard aLock( m_aMutex );
472 Reference< css::awt::XPopupMenu > xPopupMenu( m_xPopupMenu );
473 aLock.clear();
475 if ( !xPopupMenu.is() )
476 return;
478 SolarMutexGuard aGuard;
480 bool bSetCheckmark = false;
481 bool bCheckmark = false;
482 for (sal_Int16 i = 0, nCount = xPopupMenu->getItemCount(); i < nCount; ++i)
484 sal_Int16 nId = xPopupMenu->getItemId(i);
485 if ( nId == 0 )
486 continue;
488 OUString aCmd = xPopupMenu->getCommand(nId);
489 if ( aCmd == aFeatureURL )
491 // Enable/disable item
492 xPopupMenu->enableItem(nId, Event.IsEnabled);
494 // Checkmark
495 if ( Event.State >>= bCheckmark )
496 bSetCheckmark = true;
498 if ( bSetCheckmark )
499 xPopupMenu->checkItem(nId, bCheckmark);
500 else
502 OUString aItemText;
504 if ( Event.State >>= aItemText )
505 xPopupMenu->setItemText(nId, aItemText);
511 // XMenuListener
512 void SAL_CALL ToolbarsMenuController::itemSelected( const css::awt::MenuEvent& rEvent )
514 Reference< css::awt::XPopupMenu > xPopupMenu;
515 Reference< XComponentContext > xContext;
516 Reference< XURLTransformer > xURLTransformer;
517 Reference< XFrame > xFrame;
518 Reference< XNameAccess > xPersistentWindowState;
521 osl::MutexGuard aLock(m_aMutex);
522 xPopupMenu = m_xPopupMenu;
523 xContext = m_xContext;
524 xURLTransformer = m_xURLTransformer;
525 xFrame = m_xFrame;
526 xPersistentWindowState = m_xPersistentWindowState;
529 if ( !xPopupMenu.is() )
530 return;
532 SolarMutexGuard aSolarMutexGuard;
534 OUString aCmd(xPopupMenu->getCommand(rEvent.MenuId));
535 if ( aCmd.startsWith( STATIC_INTERNAL_CMD_PART ) )
537 // Command to restore the visibility of all context sensitive toolbars
538 Reference< XNameReplace > xNameReplace( xPersistentWindowState, UNO_QUERY );
539 if ( xPersistentWindowState.is() && xNameReplace.is() )
543 Sequence< OUString > aElementNames = xPersistentWindowState->getElementNames();
544 sal_Int32 nCount = aElementNames.getLength();
545 bool bRefreshToolbars( false );
547 for ( sal_Int32 i = 0; i < nCount; i++ )
551 OUString aElementName = aElementNames[i];
552 Sequence< PropertyValue > aWindowState;
554 if ( xPersistentWindowState->getByName( aElementName ) >>= aWindowState )
556 bool bVisible( false );
557 bool bContextSensitive( false );
558 sal_Int32 nVisibleIndex( -1 );
559 for ( sal_Int32 j = 0; j < aWindowState.getLength(); j++ )
561 if ( aWindowState[j].Name == WINDOWSTATE_PROPERTY_VISIBLE )
563 aWindowState[j].Value >>= bVisible;
564 nVisibleIndex = j;
566 else if ( aWindowState[j].Name == WINDOWSTATE_PROPERTY_CONTEXT )
567 aWindowState[j].Value >>= bContextSensitive;
570 if ( !bVisible && bContextSensitive && nVisibleIndex >= 0 )
572 // Default is: Every context sensitive toolbar is visible
573 aWindowState.getArray()[nVisibleIndex].Value <<= true;
574 xNameReplace->replaceByName( aElementName, Any( aWindowState ));
575 bRefreshToolbars = true;
579 catch ( const NoSuchElementException& )
584 if ( bRefreshToolbars )
586 Reference< XLayoutManager > xLayoutManager( getLayoutManagerFromFrame( xFrame ));
587 if ( xLayoutManager.is() )
589 Reference< XPropertySet > xPropSet( xLayoutManager, UNO_QUERY );
590 if ( xPropSet.is() )
594 xPropSet->setPropertyValue("RefreshContextToolbarVisibility", Any( true ));
596 catch ( const RuntimeException& )
599 catch ( const Exception& )
604 RefreshToolbars( xFrame );
607 catch ( const RuntimeException& )
609 throw;
611 catch ( const Exception& )
616 else if ( aCmd.indexOf( STATIC_CMD_PART ) < 0 )
618 URL aTargetURL;
619 Sequence<PropertyValue> aArgs;
621 aTargetURL.Complete = aCmd;
622 xURLTransformer->parseStrict( aTargetURL );
623 Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY );
624 if ( xDispatchProvider.is() )
626 Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch(
627 aTargetURL, OUString(), 0 );
629 ExecuteInfo* pExecuteInfo = new ExecuteInfo;
630 pExecuteInfo->xDispatch = xDispatch;
631 pExecuteInfo->aTargetURL = aTargetURL;
632 pExecuteInfo->aArgs = aArgs;
633 Application::PostUserEvent( LINK(nullptr, ToolbarsMenuController, ExecuteHdl_Impl), pExecuteInfo );
636 else
638 Reference< XLayoutManager > xLayoutManager( getLayoutManagerFromFrame( xFrame ));
639 if ( xLayoutManager.is() )
641 // Extract toolbar name from the combined uno-command.
642 sal_Int32 nIndex = aCmd.indexOf( '=' );
643 if (( nIndex > 0 ) && (( nIndex+1 ) < aCmd.getLength() ))
645 OUString aToolBarResName = OUString::Concat("private:resource/toolbar/") + aCmd.subView(nIndex+1);
647 const bool bShow(!xPopupMenu->isItemChecked(rEvent.MenuId));
648 if ( bShow )
650 xLayoutManager->createElement( aToolBarResName );
651 xLayoutManager->showElement( aToolBarResName );
653 else
655 // closing means:
656 // hide and destroy element
657 xLayoutManager->hideElement( aToolBarResName );
658 xLayoutManager->destroyElement( aToolBarResName );
665 void SAL_CALL ToolbarsMenuController::itemActivated( const css::awt::MenuEvent& )
667 std::vector< OUString > aCmdVector;
668 Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY );
669 Reference< XURLTransformer > xURLTransformer( m_xURLTransformer );
671 osl::MutexGuard aLock( m_aMutex );
672 fillPopupMenu( m_xPopupMenu );
673 aCmdVector = m_aCommandVector;
676 // Update status for all commands inside our toolbars popup menu
677 const sal_uInt32 nCount = aCmdVector.size();
678 for ( sal_uInt32 i = 0; i < nCount; i++ )
680 bool bInternal = aCmdVector[i].startsWith( STATIC_INTERNAL_CMD_PART );
682 if ( !bInternal )
684 URL aTargetURL;
685 aTargetURL.Complete = aCmdVector[i];
686 xURLTransformer->parseStrict( aTargetURL );
687 Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( aTargetURL, OUString(), 0 );
688 if ( xDispatch.is() )
690 xDispatch->addStatusListener( static_cast< XStatusListener* >(this), aTargetURL );
691 xDispatch->removeStatusListener( static_cast< XStatusListener* >(this), aTargetURL );
694 else if ( aCmdVector[i] == CMD_RESTOREVISIBILITY )
696 // Special code to determine the enable/disable state of this command
697 FeatureStateEvent aFeatureStateEvent;
698 aFeatureStateEvent.FeatureURL.Complete = aCmdVector[i];
699 aFeatureStateEvent.IsEnabled = m_bResetActive; // is context sensitive toolbar non visible
700 statusChanged( aFeatureStateEvent );
705 // XPopupMenuController
706 void SAL_CALL ToolbarsMenuController::setPopupMenu( const Reference< css::awt::XPopupMenu >& xPopupMenu )
708 osl::MutexGuard aLock( m_aMutex );
710 throwIfDisposed();
712 if ( m_xFrame.is() && !m_xPopupMenu.is() )
714 // Create popup menu on demand
715 SolarMutexGuard aSolarMutexGuard;
717 m_xPopupMenu = xPopupMenu;
718 m_xPopupMenu->addMenuListener( Reference< css::awt::XMenuListener >(this) );
719 fillPopupMenu( m_xPopupMenu );
723 // XInitialization
724 void SAL_CALL ToolbarsMenuController::initialize( const Sequence< Any >& aArguments )
726 osl::MutexGuard aLock( m_aMutex );
727 bool bInitialized( m_bInitialized );
728 if ( bInitialized )
729 return;
731 svt::PopupMenuControllerBase::initialize(aArguments);
733 if ( !m_bInitialized )
734 return;
736 Reference< XModuleManager2 > xModuleManager = ModuleManager::create( m_xContext );
737 Reference< XNameAccess > xPersistentWindowStateSupplier = css::ui::theWindowStateConfiguration::get( m_xContext );
739 // Retrieve persistent window state reference for our module
742 OUString aModuleIdentifier = xModuleManager->identify( m_xFrame );
743 xPersistentWindowStateSupplier->getByName( aModuleIdentifier ) >>= m_xPersistentWindowState;
745 Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgSupplier =
746 theModuleUIConfigurationManagerSupplier::get( m_xContext );
747 m_xModuleCfgMgr = xModuleCfgSupplier->getUIConfigurationManager( aModuleIdentifier );
749 Reference< XController > xController = m_xFrame->getController();
750 Reference< XModel > xModel;
751 if ( xController.is() )
752 xModel = xController->getModel();
753 if ( xModel.is() )
755 Reference< XUIConfigurationManagerSupplier > xUIConfigurationManagerSupplier( xModel, UNO_QUERY );
756 if ( xUIConfigurationManagerSupplier.is() )
757 m_xDocCfgMgr = xUIConfigurationManagerSupplier->getUIConfigurationManager();
760 catch ( const Exception& )
765 IMPL_STATIC_LINK( ToolbarsMenuController, ExecuteHdl_Impl, void*, p, void )
767 ExecuteInfo* pExecuteInfo = static_cast<ExecuteInfo*>(p);
770 // Asynchronous execution as this can lead to our own destruction!
771 // Framework can recycle our current frame and the layout manager disposes all user interface
772 // elements if a component gets detached from its frame!
773 if ( pExecuteInfo->xDispatch.is() )
775 pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
778 catch ( const Exception& )
782 delete pExecuteInfo;
787 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
788 framework_ToolbarsMenuController_get_implementation(
789 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& )
791 return cppu::acquire(new framework::ToolbarsMenuController(context));
794 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */