27#include <officecfg/Office/Common.hxx>
36#include <com/sun/star/ui/ItemType.hpp>
37#include <com/sun/star/frame/XDispatchProvider.hpp>
38#include <com/sun/star/beans/XPropertySet.hpp>
39#include <com/sun/star/awt/XDockableWindow.hpp>
40#include <com/sun/star/frame/XLayoutManager.hpp>
41#include <com/sun/star/ui/DockingArea.hpp>
42#include <com/sun/star/graphic/XGraphic.hpp>
43#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
44#include <com/sun/star/lang/XMultiServiceFactory.hpp>
45#include <com/sun/star/frame/ModuleManager.hpp>
46#include <com/sun/star/frame/theToolbarControllerFactory.hpp>
47#include <com/sun/star/ui/ItemStyle.hpp>
48#include <com/sun/star/ui/XUIElementSettings.hpp>
49#include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
50#include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
51#include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
52#include <com/sun/star/ui/ImageType.hpp>
53#include <com/sun/star/ui/UIElementType.hpp>
54#include <com/sun/star/lang/DisposedException.hpp>
55#include <com/sun/star/util/URLTransformer.hpp>
100 css::uno::Reference< css::frame::XFrame >
const & rFrame )
102 css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
104 Reference< XPropertySet > xPropSet( rFrame, UNO_QUERY );
109 xPropSet->getPropertyValue(
"LayoutManager") >>= xLayoutManager;
120 return xLayoutManager;
125sal_Int16 getCurrentImageType()
127 sal_Int16 nImageType = css::ui::ImageType::SIZE_DEFAULT;
129 if (nCurrentSymbolSize == SFX_SYMBOLS_SIZE_LARGE)
130 nImageType |= css::ui::ImageType::SIZE_LARGE;
131 else if (nCurrentSymbolSize == SFX_SYMBOLS_SIZE_32)
132 nImageType |= css::ui::ImageType::SIZE_32;
136class VclToolBarManager :
public ToolBarManagerImpl
152 virtual void Init()
override
162 virtual void Destroy()
override
178 for ( ToolBox::ImplToolItems::size_type i = 0;
i <
m_pToolBar->GetItemCount();
i++ )
182 delete static_cast< AddonsParams*
>(
m_pToolBar->GetItemData( nItemId ));
198 virtual css::uno::Reference<css::awt::XWindow> GetInterface()
override
203 virtual void ConnectCallbacks(ToolBarManager* pManager)
override
206 m_pToolBar->SetSelectHdl(
LINK( pManager, ToolBarManager, Select) );
207 m_pToolBar->SetClickHdl(
LINK(
this, VclToolBarManager, Click ) );
208 m_pToolBar->SetDropdownClickHdl(
LINK( pManager, ToolBarManager, DropdownClick ) );
209 m_pToolBar->SetDoubleClickHdl(
LINK( pManager, ToolBarManager, DoubleClick ) );
210 m_pToolBar->SetStateChangedHdl(
LINK( pManager, ToolBarManager, StateChanged ) );
211 m_pToolBar->SetDataChangedHdl(
LINK( pManager, ToolBarManager, DataChanged ) );
214 m_pToolBar->SetMenuExecuteHdl(
LINK( pManager, ToolBarManager, MenuPreExecute ) );
215 m_pToolBar->GetMenu()->SetSelectHdl(
LINK( pManager, ToolBarManager, MenuSelect ) );
219 const OUString& rCommandURL,
220 const OUString& rTooltip,
221 const OUString& rLabel,
224 m_pToolBar->InsertItem( nId, rLabel, rCommandURL, nItemBits );
227 m_pToolBar->SetItemState( nId, TRISTATE_FALSE );
230 virtual void InsertSeparator()
override
235 virtual void InsertSpace()
override
240 virtual void InsertBreak()
override
260 virtual sal_uInt16 GetItemCount()
override
270 virtual void HideItem(
ToolBoxItemId nId,
const OUString& )
override
275 virtual bool IsItemVisible(
ToolBoxItemId nId,
const OUString& )
override
280 virtual void Clear()
override
285 virtual void SetName(
const OUString& rName)
override
290 virtual void SetHelpId(
const OUString& rHelpId)
override
295 virtual bool WillUsePopupMode()
override
300 virtual bool IsReallyVisible()
override
320 virtual void MergeToolbar(
ToolBoxItemId & rItemId, sal_uInt16 nFirstItem,
321 const OUString& rModuleIdentifier,
323 MergeToolbarInstruction& rInstruction)
override
332 if ( aRefPoint.bResult )
339 rInstruction.aMergeCommand,
340 rInstruction.aMergeCommandParameter,
349 rInstruction.aMergeCommand,
350 rInstruction.aMergeFallback,
357 const Image& rImage)
override
362 virtual void UpdateSize()
override
370 m_pToolBar->SetItemWindow( nItemId, pNewWindow );
384class WeldToolBarManager :
public ToolBarManagerImpl
387 DECL_LINK(ToggleMenuHdl,
const OUString&,
void);
398 virtual void Init()
override {}
400 virtual void Destroy()
override {}
402 virtual css::uno::Reference<css::awt::XWindow> GetInterface()
override
407 virtual void ConnectCallbacks(ToolBarManager* pManager)
override
415 const OUString& rCommandURL,
416 const OUString& rTooltip,
417 const OUString& rLabel,
431 virtual void InsertSeparator()
override
436 virtual void InsertSpace()
override {}
438 virtual void InsertBreak()
override {}
455 virtual sal_uInt16 GetItemCount()
override
462 virtual void HideItem(
ToolBoxItemId ,
const OUString& rCommandURL)
override
467 virtual bool IsItemVisible(
ToolBoxItemId ,
const OUString& rCommandURL)
override
472 virtual void Clear()
override {}
474 virtual void SetName(
const OUString& )
override {}
476 virtual void SetHelpId(
const OUString& )
override {}
478 virtual bool WillUsePopupMode()
override {
return true; }
480 virtual bool IsReallyVisible()
override {
return true; }
495 MergeToolbarInstruction& )
override {}
498 const OUString& rCommandURL,
499 const Image& rImage)
override
504 virtual void UpdateSize()
override {}
518IMPL_LINK(WeldToolBarManager, Click,
const OUString&, rCommand,
void)
524IMPL_LINK(WeldToolBarManager, ToggleMenuHdl,
const OUString&, rCommand,
void)
535 const Reference< XFrame >& rFrame,
536 OUString aResourceName,
539 m_bFrameActionRegistered( false ),
540 m_bUpdateControllers( false ),
543 m_pImpl( new VclToolBarManager( pToolBar ) ),
546 m_aResourceName(
std::move( aResourceName )),
549 m_aAsyncUpdateControllersTimer(
"framework::ToolBarManager m_aAsyncUpdateControllersTimer" ),
555ToolBarManager::ToolBarManager(
const Reference< XComponentContext >& rxContext,
556 const Reference< XFrame >& rFrame,
557 OUString aResourceName,
561 m_bFrameActionRegistered( false ),
562 m_bUpdateControllers( false ),
565 m_pImpl( new WeldToolBarManager( pToolBar, pBuilder ) ),
567 m_aResourceName(
std::move( aResourceName )),
570 m_aAsyncUpdateControllersTimer(
"framework::ToolBarManager m_aAsyncUpdateControllersTimer" ),
576void ToolBarManager::Init()
582 m_xToolbarControllerFactory = frame::theToolbarControllerFactory::get(
m_xContext );
583 m_xURLTransformer = URLTransformer::create(
m_xContext );
585 m_pImpl->ConnectCallbacks(
this);
588 m_pImpl->SetIconSize(ToolBoxButtonSize::Large);
590 m_pImpl->SetIconSize(ToolBoxButtonSize::Size32);
592 m_pImpl->SetIconSize(ToolBoxButtonSize::Small);
598 nMenuType |= ToolBoxMenuType::Customize;
600 m_pImpl->SetMenuType( nMenuType );
603 sal_Int32
idx = m_aResourceName.lastIndexOf(
'/');
605 std::u16string_view aToolbarName = m_aResourceName.subView(
idx );
606 OUString aHelpIdAsString =
".HelpId:" + OUString::Concat(aToolbarName);
607 m_pImpl->SetHelpId( aHelpIdAsString );
609 m_aAsyncUpdateControllersTimer.SetTimeout( 50 );
610 m_aAsyncUpdateControllersTimer.SetInvokeHandler(
LINK(
this,
ToolBarManager, AsyncUpdateControllersHdl ) );
615ToolBarManager::~ToolBarManager()
617 assert(!m_aAsyncUpdateControllersTimer.IsActive());
621void ToolBarManager::Destroy()
634void ToolBarManager::CheckAndUpdateImages()
637 bool bRefreshImages =
false;
641 if (m_eSymbolSize != eNewSymbolSize )
643 bRefreshImages =
true;
644 m_eSymbolSize = eNewSymbolSize;
648 if ( m_sIconTheme != sCurrentIconTheme )
650 bRefreshImages =
true;
651 m_sIconTheme = sCurrentIconTheme;
655 if ( bRefreshImages )
659void ToolBarManager::RefreshImages()
664 m_pImpl->SetIconSize(ToolBoxButtonSize::Large);
666 m_pImpl->SetIconSize(ToolBoxButtonSize::Size32);
668 m_pImpl->SetIconSize(ToolBoxButtonSize::Small);
670 for (
auto const& it : m_aControllerMap )
672 Reference< XSubToolbarController >
xController( it.second, UNO_QUERY );
681 OUString aCommandURL =
m_pImpl->GetItemCommand( it.first );
688 aImage =
Image(framework::AddonsOptions().GetImageFromURL(aCommandURL, bBigImages));
689 m_pImpl->SetItemImage( it.first, aCommandURL, aImage );
696void ToolBarManager::UpdateControllers()
699 if( officecfg::Office::Common::Misc::DisableUICustomization::get() )
702 Reference< XLayoutManager > xLayoutManager;
703 Reference< XPropertySet > xFramePropSet(
m_xFrame, UNO_QUERY );
704 if ( xFramePropSet.is() )
705 a = xFramePropSet->getPropertyValue(
"LayoutManager");
706 a >>= xLayoutManager;
707 Reference< XDockableWindow > xDockable(
m_pImpl->GetInterface(), UNO_QUERY );
708 if ( xLayoutManager.is() && xDockable.is() )
710 css::awt::Point aPoint;
712 xLayoutManager->dockWindow( m_aResourceName, DockingArea_DOCKINGAREA_DEFAULT, aPoint );
713 xLayoutManager->lockWindow( m_aResourceName );
717 if ( !m_bUpdateControllers )
719 m_bUpdateControllers =
true;
720 for (
auto const& controller : m_aControllerMap)
724 Reference< XUpdatable > xUpdatable( controller.second, UNO_QUERY );
725 if ( xUpdatable.is() )
726 xUpdatable->update();
733 m_bUpdateControllers =
false;
737void ToolBarManager::UpdateController(
const css::uno::Reference< css::frame::XToolbarController >& xController)
740 if ( !m_bUpdateControllers )
742 m_bUpdateControllers =
true;
746 Reference< XUpdatable > xUpdatable(
xController, UNO_QUERY );
747 if ( xUpdatable.is() )
748 xUpdatable->update();
756 m_bUpdateControllers =
false;
759void ToolBarManager::frameAction(
const FrameActionEvent&
Action )
764 if (m_aImageController)
765 m_aImageController->update();
766 m_aAsyncUpdateControllersTimer.Start();
770void SAL_CALL ToolBarManager::disposing(
const EventObject& Source )
779 if ( m_xDocImageManager.is() )
783 m_xDocImageManager->removeConfigurationListener(
784 Reference< XUIConfigurationListener >(
this) );
791 if ( m_xModuleImageManager.is() )
795 m_xModuleImageManager->removeConfigurationListener(
796 Reference< XUIConfigurationListener >(
this) );
803 m_xDocImageManager.clear();
804 m_xModuleImageManager.clear();
806 if (
Source.Source == Reference< XInterface >(
m_xFrame, UNO_QUERY ))
813void SAL_CALL ToolBarManager::dispose()
815 Reference< XComponent > xThis(
this);
818 EventObject
aEvent( xThis );
819 std::unique_lock aGuard(
m_mutex);
820 m_aListenerContainer.disposeAndClear( aGuard,
aEvent );
832 if ( m_xDocImageManager.is() )
836 m_xDocImageManager->removeConfigurationListener(
837 Reference< XUIConfigurationListener >(
this) );
843 m_xDocImageManager.clear();
844 if ( m_xModuleImageManager.is() )
848 m_xModuleImageManager->removeConfigurationListener(
849 Reference< XUIConfigurationListener >(
this) );
855 m_xModuleImageManager.clear();
857 if ( m_aOverflowManager.is() )
859 m_aOverflowManager->dispose();
860 m_aOverflowManager.clear();
867 if ( m_bFrameActionRegistered &&
m_xFrame.is() )
871 m_xFrame->removeFrameActionListener( Reference< XFrameActionListener >(
this) );
883 m_aAsyncUpdateControllersTimer.Stop();
889void SAL_CALL ToolBarManager::addEventListener(
const Reference< XEventListener >& xListener )
895 throw DisposedException();
897 std::unique_lock aGuard(
m_mutex);
898 m_aListenerContainer.addInterface( aGuard, xListener );
901void SAL_CALL ToolBarManager::removeEventListener(
const Reference< XEventListener >& xListener )
903 std::unique_lock aGuard(
m_mutex);
904 m_aListenerContainer.removeInterface( aGuard, xListener );
908void SAL_CALL ToolBarManager::elementInserted(
const css::ui::ConfigurationEvent& Event )
910 impl_elementChanged(
false,Event);
913void SAL_CALL ToolBarManager::elementRemoved(
const css::ui::ConfigurationEvent& Event )
915 impl_elementChanged(
true,Event);
917void ToolBarManager::impl_elementChanged(
bool const isRemove,
918 const css::ui::ConfigurationEvent& Event)
926 Reference< XNameAccess > xNameAccess;
927 sal_Int16 nImageType = sal_Int16();
928 sal_Int16 nCurrentImageType = getCurrentImageType();
930 if (!(( Event.aInfo >>= nImageType ) &&
931 ( nImageType == nCurrentImageType ) &&
932 ( Event.Element >>= xNameAccess )))
935 sal_Int16 nImageInfo( 1 );
936 Reference< XInterface > xIfacDocImgMgr( m_xDocImageManager, UNO_QUERY );
937 if ( xIfacDocImgMgr == Event.Source )
940 const Sequence< OUString >
aSeq = xNameAccess->getElementNames();
941 for ( OUString
const & commandName :
aSeq )
943 CommandToInfoMap::iterator pIter = m_aCommandMap.find( commandName );
944 if ( pIter != m_aCommandMap.end() && ( pIter->second.nImageInfo >= nImageInfo ))
949 if (( pIter->second.nImageInfo == 0 ) && ( pIter->second.nImageInfo == nImageInfo ))
954 Sequence< OUString > aCmdURLSeq{ pIter->first };
955 Sequence< Reference< XGraphic > > aGraphicSeq;
956 aGraphicSeq = m_xModuleImageManager->getImages( nImageType, aCmdURLSeq );
957 aImage =
Image( aGraphicSeq[0] );
960 setToolBarImage(aImage,pIter);
964 Reference< XGraphic > xGraphic;
965 if ( xNameAccess->getByName( commandName ) >>= xGraphic )
967 Image aImage( xGraphic );
968 setToolBarImage(aImage,pIter);
970 pIter->second.nImageInfo = nImageInfo;
975void ToolBarManager::setToolBarImage(
const Image& rImage,
976 const CommandToInfoMap::const_iterator& rIter)
978 const ::std::vector<ToolBoxItemId>& rIDs = rIter->second.aIds;
979 m_pImpl->SetItemImage( rIter->second.nId, rIter->first, rImage );
980 for (
auto const& it : rIDs)
982 m_pImpl->SetItemImage(it, rIter->first, rImage);
986void SAL_CALL ToolBarManager::elementReplaced(
const css::ui::ConfigurationEvent& Event )
988 impl_elementChanged(
false,Event);
991void ToolBarManager::RemoveControllers()
996 m_aSubToolBarControllerMap.clear();
998 if (m_aImageController)
999 m_aImageController->dispose();
1000 m_aImageController.clear();
1007 for ( ToolBox::ImplToolItems::size_type
i = 0;
i <
m_pImpl->GetItemCount();
i++ )
1012 Reference< XComponent > xComponent( m_aControllerMap[ nItemId ], UNO_QUERY );
1013 if ( xComponent.is() )
1017 xComponent->dispose();
1023 m_pImpl->SetItemWindow(nItemId,
nullptr);
1026 m_aControllerMap.clear();
1029void ToolBarManager::CreateControllers()
1031 Reference< XWindow > xToolbarWindow =
m_pImpl->GetInterface();
1033 css::util::URL
aURL;
1037 for ( ToolBox::ImplToolItems::size_type
i = 0;
i <
m_pImpl->GetItemCount();
i++ )
1044 bool bCreate(
true );
1047 OUString aCommandURL(
m_pImpl->GetItemCommand(
nId ) );
1051 if ( !aRealCommandURL.isEmpty() )
1052 aCommandURL = aRealCommandURL;
1054 if ( bHasDisabledEntries )
1056 aURL.Complete = aCommandURL;
1057 m_xURLTransformer->parseStrict(
aURL );
1066 if ( m_xToolbarControllerFactory.is() &&
1067 m_xToolbarControllerFactory->hasController( aCommandURL, m_aModuleIdentifier ))
1069 Reference<XMultiServiceFactory> xMSF(
m_xContext->getServiceManager(), UNO_QUERY_THROW);
1071 {
"ModuleIdentifier",
Any(m_aModuleIdentifier) },
1073 {
"ServiceManager",
Any(xMSF) },
1074 {
"ParentWindow",
Any(xToolbarWindow) },
1075 {
"Identifier",
Any(sal_uInt16(
nId)) },
1077 xController.set( m_xToolbarControllerFactory->createInstanceWithArgumentsAndContext( aCommandURL, aArgs,
m_xContext ),
1082 if (( aCommandURL ==
".uno:OpenUrl" ) && ( !
m_pImpl->IsItemVisible(
nId, aCommandURL)))
1091 if ( aCommandURL.startsWith(
".uno:StyleApply?" ) )
1096 else if ( aCommandURL.startsWith(
"private:resource/" ) )
1099 "com.sun.star.comp.framework.GenericPopupToolbarController",
m_xContext ), UNO_QUERY );
1107 Reference< XStatusListener > xStatusListener(
1114 aControlType ).
get(), UNO_QUERY );
1138 Reference< XSubToolbarController > xSubToolBar(
xController, UNO_QUERY );
1139 if ( xSubToolBar.is() && xSubToolBar->opensSubToolbar() )
1141 OUString aSubToolBarName = xSubToolBar->getSubToolbarName();
1142 if ( !aSubToolBarName.isEmpty() )
1144 SubToolBarToSubToolBarControllerMap::iterator pIter =
1145 m_aSubToolBarControllerMap.find( aSubToolBarName );
1146 if ( pIter == m_aSubToolBarControllerMap.end() )
1149 aSubToolBarVector.push_back( xSubToolBar );
1150 m_aSubToolBarControllerMap.emplace(
1151 aSubToolBarName, aSubToolBarVector );
1154 pIter->second.push_back( xSubToolBar );
1158 Reference< XInitialization > xInit(
xController, UNO_QUERY );
1163 Reference<XMultiServiceFactory> xMSF(
m_xContext->getServiceManager(), UNO_QUERY_THROW);
1166 {
"CommandURL",
Any(aCommandURL) },
1167 {
"ServiceManager",
Any(xMSF) },
1168 {
"ParentWindow",
Any(xToolbarWindow) },
1169 {
"ModuleIdentifier",
Any(m_aModuleIdentifier) },
1170 {
"Identifier",
Any(sal_uInt16(
nId)) },
1173 xInit->initialize( aArgs );
1177 Reference< XToolbarController > xTbxController(
xController, UNO_QUERY );
1178 if ( xTbxController.is() && xToolbarWindow.is() )
1180 Reference< XWindow > xWindow = xTbxController->createItemWindow( xToolbarWindow );
1187 if (
m_pToolBar && (
nType == WindowType::LISTBOX ||
nType == WindowType::MULTILISTBOX ||
nType == WindowType::COMBOBOX) )
1188 pItemWin->SetAccessibleName(
m_pToolBar->GetItemText(
nId ) );
1196 Reference< XPropertySet > xPropSet(
xController, UNO_QUERY );
1197 if ( xPropSet.is() )
1201 bool bSupportVisible =
true;
1202 Any a( xPropSet->getPropertyValue(
"SupportsVisible") );
1203 a >>= bSupportVisible;
1204 if (bSupportVisible)
1206 Reference< XToolbarController > xTbxController(
xController, UNO_QUERY );
1207 UpdateController(xTbxController);
1220 AddFrameActionListener();
1223void ToolBarManager::AddFrameActionListener()
1225 if ( !m_bFrameActionRegistered &&
m_xFrame.is() )
1227 m_bFrameActionRegistered =
true;
1228 m_xFrame->addFrameActionListener( Reference< XFrameActionListener >(
this) );
1235 if ( nStyle & css::ui::ItemStyle::RADIO_CHECK )
1236 nItemBits |= ToolBoxItemBits::RADIOCHECK;
1237 if ( nStyle & css::ui::ItemStyle::ALIGN_LEFT )
1238 nItemBits |= ToolBoxItemBits::LEFT;
1239 if ( nStyle & css::ui::ItemStyle::AUTO_SIZE )
1240 nItemBits |= ToolBoxItemBits::AUTOSIZE;
1241 if ( nStyle & css::ui::ItemStyle::DROP_DOWN )
1242 nItemBits |= ToolBoxItemBits::DROPDOWN;
1243 if ( nStyle & css::ui::ItemStyle::REPEAT )
1244 nItemBits |= ToolBoxItemBits::REPEAT;
1245 if ( nStyle & css::ui::ItemStyle::DROPDOWN_ONLY )
1246 nItemBits |= ToolBoxItemBits::DROPDOWNONLY;
1247 if ( nStyle & css::ui::ItemStyle::TEXT )
1248 nItemBits |= ToolBoxItemBits::TEXT_ONLY;
1249 if ( nStyle & css::ui::ItemStyle::ICON )
1250 nItemBits |= ToolBoxItemBits::ICON_ONLY;
1255void ToolBarManager::InitImageManager()
1257 Reference< XModuleManager2 > xModuleManager = ModuleManager::create(
m_xContext );
1258 if ( !m_xDocImageManager.is() )
1260 Reference< XModel >
xModel( GetModelFromFrame() );
1263 Reference< XUIConfigurationManagerSupplier > xSupplier(
xModel, UNO_QUERY );
1264 if ( xSupplier.is() )
1266 Reference< XUIConfigurationManager > xDocUICfgMgr = xSupplier->getUIConfigurationManager();
1267 m_xDocImageManager.set( xDocUICfgMgr->getImageManager(), UNO_QUERY );
1268 m_xDocImageManager->addConfigurationListener(
1269 Reference< XUIConfigurationListener >(
this) );
1276 m_aModuleIdentifier = xModuleManager->identify( Reference< XInterface >(
m_xFrame, UNO_QUERY ) );
1282 if ( !m_xModuleImageManager.is() )
1284 Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier =
1285 theModuleUIConfigurationManagerSupplier::get(
m_xContext );
1286 Reference< XUIConfigurationManager > xUICfgMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( m_aModuleIdentifier );
1287 m_xModuleImageManager.set( xUICfgMgr->getImageManager(), UNO_QUERY );
1288 m_xModuleImageManager->addConfigurationListener( Reference< XUIConfigurationListener >(
this) );
1292void ToolBarManager::FillToolbar(
const Reference< XIndexAccess >& rItemContainer,
1293 const Reference< XIndexAccess >& rContextData,
1294 const OUString& rContextToolbarName )
1296 OString aTbxName =
OUStringToOString( m_aResourceName, RTL_TEXTENCODING_ASCII_US );
1297 SAL_INFO(
"fwk.uielement",
"framework (cd100003) ::ToolBarManager::FillToolbar " << aTbxName );
1306 RemoveControllers();
1310 m_aControllerMap.clear();
1311 m_aCommandMap.clear();
1314 FillToolbarFromContainer( rItemContainer, m_aResourceName,
nId, nAddonId );
1315 m_aContextResourceName = rContextToolbarName;
1316 if ( rContextData.is() )
1319 FillToolbarFromContainer( rContextData, m_aContextResourceName,
nId, nAddonId );
1328 CreateControllers();
1332 if(
m_pImpl->WillUsePopupMode() )
1333 UpdateControllers();
1334 else if (
m_pImpl->IsReallyVisible() )
1336 m_aAsyncUpdateControllersTimer.Start();
1341 Reference< XPropertySet > xPropSet( rItemContainer, UNO_QUERY );
1342 if ( !xPropSet.is() )
1348 xPropSet->getPropertyValue(
"UIName") >>=
aUIName;
1357void ToolBarManager::FillToolbarFromContainer(
const Reference< XIndexAccess >& rItemContainer,
1360 m_nContextMinPos =
m_pImpl->GetItemCount();
1362 for ( sal_Int32
n = 0;
n < rItemContainer->getCount();
n++ )
1364 Sequence< PropertyValue > aProps;
1365 OUString aCommandURL;
1368 sal_uInt16
nType( css::ui::ItemType::DEFAULT );
1369 sal_uInt32 nStyle( 0 );
1373 if ( rItemContainer->getByIndex(
n ) >>= aProps )
1375 bool bIsVisible(
true );
1376 for ( PropertyValue
const & prop : std::as_const(aProps) )
1379 prop.Value >>= aCommandURL;
1380 else if ( prop.Name ==
"Label" )
1382 else if ( prop.Name ==
"Tooltip" )
1383 prop.Value >>= aTooltip;
1384 else if ( prop.Name ==
"Type" )
1385 prop.Value >>=
nType;
1387 prop.Value >>= bIsVisible;
1388 else if ( prop.Name ==
"Style" )
1389 prop.Value >>= nStyle;
1393 !officecfg::Office::Common::Misc::ExperimentalMode::get())
1398 if ((
nType == css::ui::ItemType::DEFAULT ) && !aCommandURL.isEmpty() )
1406 if ( aTooltip.isEmpty() )
1417 auto pIter = m_aCommandMap.emplace( aCommandURL, aCmdInfo );
1421 pIter.first->second.nId =
nId;
1425 pIter.first->second.aIds.push_back(
nId );
1433 else if (
nType == css::ui::ItemType::SEPARATOR_LINE )
1437 else if (
nType == css::ui::ItemType::SEPARATOR_SPACE )
1441 else if (
nType == css::ui::ItemType::SEPARATOR_LINEBREAK )
1447 catch (
const css::lang::IndexOutOfBoundsException&)
1458 OUString aToolbarName( rResourceName );
1459 sal_Int32
nIndex = aToolbarName.lastIndexOf(
'/' );
1460 if ((
nIndex > 0 ) && (
nIndex < aToolbarName.getLength() ))
1461 aToolbarName = aToolbarName.copy(
nIndex+1 );
1463 AddonsOptions().GetMergeToolbarInstructions( aToolbarName, aMergeInstructionContainer );
1465 if ( !aMergeInstructionContainer.empty() )
1467 const sal_uInt32
nCount = aMergeInstructionContainer.size();
1473 m_pImpl->MergeToolbar(nAddonId, m_nContextMinPos, m_aModuleIdentifier, m_aCommandMap, rInstruction);
1479void ToolBarManager::FillAddonToolbar(
const Sequence< Sequence< PropertyValue > >& rAddonToolbar )
1491 RemoveControllers();
1495 m_aControllerMap.
clear();
1496 m_aCommandMap.clear();
1500 for (
const Sequence< PropertyValue >& rSeq : rAddonToolbar )
1506 OUString aControlType;
1507 sal_uInt16 nWidth( 0 );
1509 ToolBarMerger::ConvertSequenceToValues( rSeq,
aURL, aTitle, aTarget, aContext, aControlType, nWidth );
1513 if (
aURL ==
"private:separator" )
1524 if (!aShortcut.isEmpty())
1525 m_pToolBar->SetQuickHelpText(
nId, aTitle +
" (" + aShortcut +
")");
1530 pRuntimeItemData->
nWidth = nWidth;
1536 auto pIter = m_aCommandMap.emplace(
aURL, aCmdInfo );
1540 pIter.first->second.nId =
nId;
1544 pIter.first->second.aIds.push_back(
nId );
1553 CreateControllers();
1556 UpdateControllers();
1559void ToolBarManager::FillOverflowToolbar(
ToolBox const * pParent )
1565 bool bInsertSeparator =
false;
1566 for ( ToolBox::ImplToolItems::size_type
i = 0;
i < pParent->
GetItemCount(); ++
i )
1571 if ( bInsertSeparator )
1574 bInsertSeparator =
false;
1589 auto pIter = m_aCommandMap.emplace( aCommandURL, aCmdInfo );
1593 pIter.first->second.nId =
nId;
1597 pIter.first->second.aIds.push_back(
nId );
1604 (
eType == ToolBoxItemType::SEPARATOR ||
eType == ToolBoxItemType::BREAK ) )
1605 bInsertSeparator =
true;
1617 CreateControllers();
1621 UpdateControllers();
1624void ToolBarManager::RequestImages()
1629 Sequence< Reference< XGraphic > > aDocGraphicSeq;
1630 Sequence< Reference< XGraphic > > aModGraphicSeq;
1632 sal_Int16 nImageType = getCurrentImageType();
1634 if ( m_xDocImageManager.is() )
1635 aDocGraphicSeq = m_xDocImageManager->getImages(nImageType, aCmdURLSeq);
1636 aModGraphicSeq = m_xModuleImageManager->getImages(nImageType, aCmdURLSeq);
1639 CommandToInfoMap::iterator pIter = m_aCommandMap.begin();
1640 CommandToInfoMap::iterator pEnd = m_aCommandMap.end();
1641 while ( pIter != pEnd )
1644 if ( aDocGraphicSeq.hasElements() )
1645 aImage =
Image( aDocGraphicSeq[
i] );
1648 aImage =
Image( aModGraphicSeq[
i] );
1654 pIter->second.nImageInfo = 1;
1658 pIter->second.nImageInfo = 0;
1660 setToolBarImage(aImage,pIter);
1665 assert(!m_aImageController);
1667 m_aImageController->update();
1670void ToolBarManager::notifyRegisteredControllers(
const OUString& aUIElementName,
const OUString&
aCommand )
1673 if ( m_aSubToolBarControllerMap.empty() )
1676 SubToolBarToSubToolBarControllerMap::const_iterator pIter =
1677 m_aSubToolBarControllerMap.find( aUIElementName );
1679 if ( pIter == m_aSubToolBarControllerMap.end() )
1683 if ( rSubToolBarVector.empty() )
1689 const sal_uInt32
nCount = aNotifyVector.size();
1694 Reference< XSubToolbarController >
xController = aNotifyVector[
i];
1716 ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find(
nId );
1717 if ( pIter == m_aControllerMap.end() )
1720 Reference< XToolbarController >
xController( pIter->second, UNO_QUERY );
1724 switch (eClickAction)
1726 case ClickAction::Click:
1730 case ClickAction::DblClick:
1734 case ClickAction::Execute:
1741void ToolBarManager::OnClick(
bool bUseExecute)
1744 HandleClick(ClickAction::Execute);
1746 HandleClick(ClickAction::Click);
1751 OnDropdownClick(
true);
1754void ToolBarManager::OnDropdownClick(
bool bCreatePopupWindow)
1762 ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find(
nId );
1763 if ( pIter == m_aControllerMap.end() )
1766 Reference< XToolbarController >
xController( pIter->second, UNO_QUERY );
1770 if (bCreatePopupWindow)
1772 Reference< XWindow > xWin =
xController->createPopupWindow();
1785 HandleClick(ClickAction::DblClick);
1788Reference< XModel > ToolBarManager::GetModelFromFrame()
const
1791 Reference< XModel >
xModel;
1798bool ToolBarManager::IsPluginMode()
const
1800 bool bPluginMode(
false );
1804 Reference< XModel >
xModel = GetModelFromFrame();
1807 Sequence< PropertyValue >
aSeq =
xModel->getArgs();
1816void ToolBarManager::AddCustomizeMenuItems(
ToolBox const * pToolBar)
1822 Reference< XDispatch > xDisp;
1823 css::util::URL
aURL;
1826 Reference< XDispatchProvider > xProv(
m_xFrame, UNO_QUERY );
1827 aURL.Complete =
".uno:ConfigureDialog";
1828 m_xURLTransformer->parseStrict(
aURL );
1830 xDisp = xProv->queryDispatch(
aURL, OUString(), 0 );
1832 if ( !xDisp.is() || IsPluginMode() )
1837 bool bHideDisabledEntries = !officecfg::Office::Common::View::Menu::DontHideDisabledEntry::get();
1849 if (!m_aResourceName.startsWith(
"private:resource/toolbar/addon_"))
1881 bool bIsFloating(
false );
1891 if( xDockable.is() )
1897 if (officecfg::Office::Common::Misc::DisableUICustomization::get())
1911 std::map< OUString, Image > commandToImage;
1913 if (xVisibleItemsPopupMenu)
1926 commandToImage[aCommandURL] = aImage;
1933 xVisibleItemsPopupMenu->InsertSeparator();
1940 std::map< OUString, Image >::iterator it;
1945 it = commandToImage.find( cmdUrl );
1946 if (it != commandToImage.end()) {
1958 if ( bHideDisabledEntries )
1962void ToolBarManager::ToggleButton(
const OUString& rResourceName, std::u16string_view rCommand )
1965 if ( !xLayoutManager.is() )
1968 Reference< XUIElementSettings > xUIElementSettings( xLayoutManager->getElement( rResourceName ), UNO_QUERY );
1969 if ( !xUIElementSettings.is() )
1972 Reference< XIndexContainer > xItemContainer( xUIElementSettings->getSettings(
true ), UNO_QUERY );
1973 sal_Int32
nCount = xItemContainer->getCount();
1974 for ( sal_Int32
i = 0;
i <
nCount;
i++ )
1976 Sequence< PropertyValue > aProp;
1977 sal_Int32 nVisibleIndex( -1 );
1978 OUString aCommandURL;
1981 if ( xItemContainer->getByIndex(
i ) >>= aProp )
1983 for ( sal_Int32 j = 0; j < aProp.getLength(); j++ )
1987 aProp[j].Value >>= aCommandURL;
1996 if (( aCommandURL == rCommand ) && ( nVisibleIndex >= 0 ))
2000 aProp.getArray()[nVisibleIndex].Value <<= !
bVisible;
2003 xItemContainer->replaceByIndex(
i,
Any( aProp ));
2004 xUIElementSettings->setSettings( xItemContainer );
2005 Reference< XPropertySet > xPropSet( xUIElementSettings, UNO_QUERY );
2006 if ( xPropSet.is() )
2008 Reference< XUIConfigurationPersistence > xUICfgMgr;
2009 if (( xPropSet->getPropertyValue(
"ConfigurationSource") >>= xUICfgMgr ) && ( xUICfgMgr.is() ))
2029 assert( !m_aOverflowManager.is() );
2032 pOverflowToolBar->SetLineSpacing(
true);
2034 m_aOverflowManager->FillOverflowToolbar( pToolBar );
2036 ::Size aActSize( pOverflowToolBar->GetSizePixel() );
2037 ::Size aSize( pOverflowToolBar->CalcWindowSizePixel() );
2039 pOverflowToolBar->SetOutputSizePixel( aSize );
2041 aSize = pOverflowToolBar->CalcPopupWindowSizePixel();
2042 pOverflowToolBar->SetSizePixel( aSize );
2044 pOverflowToolBar->EnableDocking();
2045 pOverflowToolBar->AddEventListener(
LINK(
this,
ToolBarManager, OverflowEventListener ) );
2049 if(pToolBar->IsKeyEvent() )
2052 pOverflowToolBar->KeyInput(
aEvent);
2058 if ( rWindowEvent.GetId() != VclEventId::WindowEndPopupMode )
2061 if ( m_aOverflowManager.is() )
2063 m_aOverflowManager->dispose();
2064 m_aOverflowManager.clear();
2075 AddCustomizeMenuItems( pToolBar );
2082 Reference< XInterface > xKeepAlive(
static_cast< OWeakObject*
>(
this ), UNO_QUERY );
2092 switch ( pMenu->GetCurItemId() )
2096 Reference< XDispatch > xDisp;
2097 css::util::URL
aURL;
2100 Reference< XDispatchProvider > xProv(
m_xFrame, UNO_QUERY );
2101 aURL.Complete =
".uno:ConfigureDialog";
2102 m_xURLTransformer->parseStrict(
aURL );
2104 xDisp = xProv->queryDispatch(
aURL, OUString(), 0 );
2110 "ResourceURL", m_aResourceName) };
2112 xDisp->dispatch(
aURL, aPropSeq );
2119 ExecuteInfo* pExecuteInfo =
new ExecuteInfo;
2121 pExecuteInfo->aToolbarResName = m_aResourceName;
2122 pExecuteInfo->nCmd = EXEC_CMD_UNDOCKTOOLBAR;
2131 ExecuteInfo* pExecuteInfo =
new ExecuteInfo;
2133 pExecuteInfo->aToolbarResName = m_aResourceName;
2134 pExecuteInfo->nCmd = EXEC_CMD_DOCKTOOLBAR;
2143 ExecuteInfo* pExecuteInfo =
new ExecuteInfo;
2145 pExecuteInfo->aToolbarResName = m_aResourceName;
2146 pExecuteInfo->nCmd = EXEC_CMD_DOCKALLTOOLBARS;
2156 if ( xLayoutManager.is() )
2160 if( xDockable->isLocked() )
2161 xLayoutManager->unlockWindow( m_aResourceName );
2163 xLayoutManager->lockWindow( m_aResourceName );
2170 ExecuteInfo* pExecuteInfo =
new ExecuteInfo;
2172 pExecuteInfo->aToolbarResName = m_aResourceName;
2173 pExecuteInfo->nCmd = EXEC_CMD_CLOSETOOLBAR;
2183 sal_uInt16
nId = pMenu->GetCurItemId();
2189 if (m_aContextResourceName.isEmpty() ||
2191 ToggleButton(m_aResourceName,
aCommand);
2193 ToggleButton(m_aContextResourceName,
aCommand);
2208 sal_Int16 nKeyModifier(
static_cast<sal_Int16
>(
m_pToolBar->GetModifier()) );
2211 ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find(
nId );
2212 if ( pIter != m_aControllerMap.end() )
2214 Reference< XToolbarController >
xController( pIter->second, UNO_QUERY );
2226 if ( *pStateChangedType == StateChangedType::ControlBackground )
2228 CheckAndUpdateImages();
2230 else if ( *pStateChangedType == StateChangedType::Visible )
2234 m_aAsyncUpdateControllersTimer.Start();
2237 else if ( *pStateChangedType == StateChangedType::InitShow )
2239 m_aAsyncUpdateControllersTimer.Start();
2245 if ((( pDataChangedEvent->GetType() == DataChangedEventType::SETTINGS ) ||
2246 ( pDataChangedEvent->GetType() == DataChangedEventType::DISPLAY )) &&
2247 ( pDataChangedEvent->GetFlags() & AllSettingsFlags::STYLE ))
2249 CheckAndUpdateImages();
2275 CheckAndUpdateImages();
2282 Reference< XComponent > xThis(
this);
2290 m_aAsyncUpdateControllersTimer.Stop();
2291 UpdateControllers();
2296 ExecuteInfo* pExecuteInfo =
static_cast<ExecuteInfo*
>(
p);
2300 if (( pExecuteInfo->nCmd == EXEC_CMD_CLOSETOOLBAR ) &&
2301 ( pExecuteInfo->xLayoutManager.is() ) &&
2302 ( pExecuteInfo->xWindow.is() ))
2312 else if (( pExecuteInfo->nCmd == EXEC_CMD_UNDOCKTOOLBAR ) &&
2313 ( pExecuteInfo->xLayoutManager.is() ))
2315 pExecuteInfo->xLayoutManager->floatWindow( pExecuteInfo->aToolbarResName );
2317 else if (( pExecuteInfo->nCmd == EXEC_CMD_DOCKTOOLBAR ) &&
2318 ( pExecuteInfo->xLayoutManager.is() ))
2320 css::awt::Point aPoint;
2322 pExecuteInfo->xLayoutManager->dockWindow( pExecuteInfo->aToolbarResName,
2323 DockingArea_DOCKINGAREA_DEFAULT,
2326 else if (( pExecuteInfo->nCmd == EXEC_CMD_DOCKALLTOOLBARS ) &&
2327 ( pExecuteInfo->xLayoutManager.is() ))
2329 pExecuteInfo->xLayoutManager->dockAllWindows( UIElementType::TOOLBAR );
2336 delete pExecuteInfo;
PropertiesInfo aProperties
css::uno::Reference< css::lang::XComponent > m_xFrame
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
bool IsFloating(const vcl::Window *pWin)
void StartPopupMode(const vcl::Window *pWin, const tools::Rectangle &rRect, FloatWinPopupFlags nPopupModeFlags)
bool IsFloatingMode() const
virtual OUString GetText() const override
WinBits GetFloatStyle() const
void setWidth(tools::Long nWidth)
constexpr tools::Long Width() const
bool LookupDisabled(const OUString &aCommandURL) const
bool HasEntriesDisabled() const
static sal_Int16 GetCurrentSymbolsSize()
void RemoveListenerLink(const Link< LinkParamNone *, void > &rLink)
static bool AreCurrentSymbolsLarge()
void AddListenerLink(const Link< LinkParamNone *, void > &rLink)
static OUString GetIconTheme()
static css::uno::Reference< css::awt::XWindow > GetInterface(vcl::Window *pWindow)
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
void set(reference_type *pBody)
reference_type * get() const
static VclPtr< reference_type > Create(Arg &&... arg)
sal_uInt16 GetFullCode() const
vcl::Window * GetParent() const
static DockingManager * GetDockingManager()
bool IsSystemWindow() const
virtual void DataChanged(const DataChangedEvent &rDCEvt)
#define DBG_TESTSOLARMUTEX()
DECL_LINK(CheckNameHdl, SvxNameDialog &, bool)
virtual void SetHelpId(const OUString &) override
OUString FwkResId(TranslateId aId)
css::uno::Reference< css::uno::XComponentContext > m_xContext
constexpr sal_uInt16 KEY_HOME
constexpr sal_uInt16 KEY_F10
#define LINK(Instance, Class, Member)
Sequence< sal_Int8 > aSeq
#define SAL_INFO(area, stream)
constexpr OUStringLiteral ITEM_DESCRIPTOR_COMMANDURL
void Clear(EHistoryType eHistory)
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
css::uno::Sequence< typename M::key_type > mapKeysToSequence(M const &map)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
IMPL_LINK(ToolBarManager, DataChanged, DataChangedEvent const *, pDataChangedEvent, void)
::std::vector< MergeToolbarInstruction > MergeToolbarInstructionContainer
constexpr OUStringLiteral ITEM_DESCRIPTOR_COMMANDURL
IMPL_LINK_NOARG(ToolBarManager, AsyncUpdateControllersHdl, Timer *, void)
IMPL_LINK(WindowCommandDispatch, impl_notifyCommand, VclWindowEvent &, rEvent, void)
::std::vector< AddonToolbarItem > AddonToolbarItemContainer
const sal_uInt16 STARTID_CUSTOMIZE_POPUPMENU
std::unordered_map< OUString, CommandInfo > CommandToInfoMap
IMPL_LINK_NOARG(CloseDispatcher, impl_asyncCallback, LinkParamNone *, void)
asynchronous callback @descr We start all actions inside this object asynchronous (see comments there...
IMPL_STATIC_LINK(ToolBarManager, ExecuteHdl_Impl, void *, p, void)
constexpr OUStringLiteral ITEM_DESCRIPTOR_VISIBLE
rtl::Reference< svt::ToolboxController > CreateToolBoxController(const Reference< XFrame > &rFrame, ToolBox *pToolbox, ToolBoxItemId nID, const OUString &aCommandURL)
static css::uno::Reference< css::frame::XLayoutManager > getLayoutManagerFromFrame(css::uno::Reference< css::frame::XFrame > const &rFrame)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
Sequence< beans::PropertyValue > GetCommandProperties(const OUString &rsCommandName, const OUString &rsModuleName)
OUString GetTooltipForCommand(const OUString &rsCommandName, const css::uno::Sequence< css::beans::PropertyValue > &rProperties, const Reference< frame::XFrame > &rxFrame)
OUString GetRealCommandForCommand(const css::uno::Sequence< css::beans::PropertyValue > &rProperties)
OUString GetCommandShortcut(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame)
sal_Int32 GetPropertiesForCommand(const OUString &rsCommandName, const OUString &rsModuleName)
Image GetImageForCommand(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame, vcl::ImageType eImageType)
OUString GetLabelForCommand(const css::uno::Sequence< css::beans::PropertyValue > &rProperties)
bool IsExperimental(const OUString &rsCommandName, const OUString &rModuleName)
vcl::KeyCode GetCommandKeyCodeShortcut(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame)
#define UICOMMANDDESCRIPTION_PROPERTIES_TOGGLEBUTTON
#define MENUITEM_TOOLBAR_CLOSE
#define MENUITEM_TOOLBAR_LOCKTOOLBARPOSITION
#define MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR
#define MENUITEM_TOOLBAR_DOCKALLTOOLBAR
#define MENUITEM_TOOLBAR_UNDOCKTOOLBAR
#define MENUITEM_TOOLBAR_DOCKTOOLBAR
#define MENUITEM_TOOLBAR_VISIBLEBUTTON
Reference< XController > xController
Reference< XModel > xModel
WinBits const WB_CLOSEABLE