/* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// convert the sequence< sequence< propertyvalue > > structure to // something we can better handle. A vector with item data
AddonToolbarItemContainer aItems;
ToolBarMerger::ConvertSeqSeqToVector( rInstruction.aMergeToolbarItems, aItems );
// enables a menu for clipped items and customization
SvtCommandOptions aCmdOptions;
ToolBoxMenuType nMenuType = ToolBoxMenuType::ClippedItems; if ( !aCmdOptions.LookupDisabled( u"CreateDialog"_ustr))
nMenuType |= ToolBoxMenuType::Customize;
m_pImpl->SetMenuType( nMenuType );
// set name for testtool, the useful part is after the last '/'
sal_Int32 idx = m_aResourceName.lastIndexOf('/');
idx++; // will become 0 if '/' not found: use full string
std::u16string_view aToolbarName = m_aResourceName.subView( idx );
OUString aHelpIdAsString = ".HelpId:" + OUString::Concat(aToolbarName);
m_pImpl->SetHelpId( aHelpIdAsString );
ToolBarManager::~ToolBarManager()
{
assert(!m_aAsyncUpdateControllersTimer.IsActive());
assert(!m_pToolBar); // must be disposed by ToolbarLayoutManager
}
for ( autoconst& it : m_aControllerMap )
{
Reference< XSubToolbarController > xController( it.second, UNO_QUERY ); if ( xController.is() && xController->opensSubToolbar() )
{ // The button should show the last function that was selected from the // dropdown. The controller should know better than us what it was.
xController->updateImage();
} else
{
OUString aCommandURL = m_pImpl->GetItemCommand( it.first );
vcl::ImageType eImageType = m_pImpl->GetImageSize();
Image aImage = vcl::CommandInfoProvider::GetImageForCommand(aCommandURL, m_xFrame, eImageType); // Try also to query for add-on images before giving up and use an // empty image. bool bBigImages = eImageType != vcl::ImageType::Size16; if ( !aImage )
aImage = Image(framework::AddonsOptions().GetImageFromURL(aCommandURL, bBigImages));
m_pImpl->SetItemImage( it.first, aCommandURL, aImage );
}
}
// stop timer to prevent timer events after dispose // do it last because other calls could restart timer in StateChanged()
m_aAsyncUpdateControllersTimer.Stop();
const Sequence< OUString > aSeq = xNameAccess->getElementNames(); for ( OUString const & commandName : aSeq )
{
CommandToInfoMap::iterator pIter = m_aCommandMap.find( commandName ); if ( pIter != m_aCommandMap.end() && ( pIter->second.nImageInfo >= nImageInfo ))
{ if (isRemove)
{
Image aImage; if (( pIter->second.nImageInfo == 0 ) && ( pIter->second.nImageInfo == nImageInfo ))
{ // Special case: An image from the document image manager has been removed. // It is possible that we have an image at our module image manager. Before // we can remove our image we have to ask our module image manager.
Sequence< OUString > aCmdURLSeq{ pIter->first };
Sequence< Reference< XGraphic > > aGraphicSeq;
aGraphicSeq = m_xModuleImageManager->getImages( nImageType, aCmdURLSeq );
aImage = Image( aGraphicSeq[0] );
}
if (m_aImageController)
m_aImageController->dispose();
m_aImageController.clear();
// i90033 // Remove item window pointers from the toolbar. They were // destroyed by the dispose() at the XComponent. This is needed // as VCL code later tries to access the item window data in certain // dtors where the item window is already invalid! for ( ToolBox::ImplToolItems::size_type i = 0; i < m_pImpl->GetItemCount(); i++ )
{
ToolBoxItemId nItemId = m_pImpl->GetItemId( i ); if ( nItemId > ToolBoxItemId(0) )
{
Reference< XComponent > xComponent( m_aControllerMap[ nItemId ], UNO_QUERY ); if ( xComponent.is() )
{ try
{
xComponent->dispose();
} catch (const Exception&)
{
}
}
m_pImpl->SetItemWindow(nItemId, nullptr);
}
}
m_aControllerMap.clear();
}
for ( ToolBox::ImplToolItems::size_type i = 0; i < m_pImpl->GetItemCount(); i++ )
{
ToolBoxItemId nId = m_pImpl->GetItemId( i ); if ( nId == ToolBoxItemId(0) ) continue;
OUString aCommandURL( m_pImpl->GetItemCommand( nId ) ); // Command can be just an alias to another command. auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(aCommandURL, m_aModuleIdentifier);
OUString aRealCommandURL( vcl::CommandInfoProvider::GetRealCommandForCommand(aProperties) ); if ( !aRealCommandURL.isEmpty() )
aCommandURL = aRealCommandURL;
if ( bHasDisabledEntries )
{
aURL.Complete = aCommandURL;
m_xURLTransformer->parseStrict( aURL ); if ( aCmdOptions.LookupDisabled( aURL.Path ))
{
m_aControllerMap[ nId ] = xController;
m_pImpl->HideItem( nId, aCommandURL ); continue;
}
}
if ( m_xToolbarControllerFactory.is() &&
m_xToolbarControllerFactory->hasController( aCommandURL, m_aModuleIdentifier ))
{
Reference<XMultiServiceFactory> xMSF(m_xContext->getServiceManager(), UNO_QUERY_THROW);
Sequence< Any > aArgs( comphelper::InitAnyPropertySequence( {
{ "ModuleIdentifier", Any(m_aModuleIdentifier) },
{ "Frame", Any(m_xFrame) },
{ "ServiceManager", Any(xMSF) },
{ "ParentWindow", Any(xToolbarWindow) },
{ "Identifier", Any(sal_uInt16(nId)) },
} ));
xController.set( m_xToolbarControllerFactory->createInstanceWithArgumentsAndContext( aCommandURL, aArgs, m_xContext ),
UNO_QUERY );
bInit = false; // Initialization is done through the factory service
}
} else
{ if ( m_pToolBar )
xController.set( new GenericToolbarController( m_xContext, m_xFrame, m_pToolBar, nId, aCommandURL )); else
xController.set( new GenericToolbarController( m_xContext, m_xFrame, *m_pWeldedToolBar, aCommandURL ));
}
}
}
// Accessibility support: Set toggle button role for specific commands const sal_Int32 nProps = vcl::CommandInfoProvider::GetPropertiesForCommand(aCommandURL, m_aModuleIdentifier); if (nProps & UICOMMANDDESCRIPTION_PROPERTIES_TOGGLEBUTTON)
m_pImpl->SetItemCheckable(nId);
// Associate ID and controller to be able to retrieve // the controller from the ID later.
m_aControllerMap[ nId ] = xController;
// Fill sub-toolbars into our hash-map
Reference< XSubToolbarController > xSubToolBar( xController, UNO_QUERY ); if ( xSubToolBar.is() && xSubToolBar->opensSubToolbar() )
{
OUString aSubToolBarName = xSubToolBar->getSubToolbarName(); if ( !aSubToolBarName.isEmpty() )
{
SubToolBarToSubToolBarControllerMap::iterator pIter =
m_aSubToolBarControllerMap.find( aSubToolBarName ); if ( pIter == m_aSubToolBarControllerMap.end() )
{
SubToolBarControllerVector aSubToolBarVector;
aSubToolBarVector.push_back( xSubToolBar );
m_aSubToolBarControllerMap.emplace(
aSubToolBarName, aSubToolBarVector );
} else
pIter->second.push_back( xSubToolBar );
}
}
// Request images for all toolbar items. Must be done before CreateControllers as // some controllers need access to the image.
RequestImages();
// Create controllers after we set the images. There are controllers which needs // an image at the toolbar at creation time!
CreateControllers();
// Notify controllers that they are now correctly initialized and can start listening // toolbars that will open in popup mode will be updated immediately to avoid flickering if( m_pImpl->WillUsePopupMode() )
UpdateControllers(); elseif ( m_pImpl->IsReallyVisible() )
{
m_aAsyncUpdateControllersTimer.Start();
}
// Try to retrieve UIName from the container property set and set it as the title // if it is not empty.
Reference< XPropertySet > xPropSet( rItemContainer, UNO_QUERY ); if ( !xPropSet.is() ) return;
// Fill command map. It stores all our commands and from what // image manager we got our image. So we can decide if we have to use an // image from a notification message. auto pIter = m_aCommandMap.emplace( aCommandURL, aCmdInfo ); if ( pIter.second )
{
aCmdInfo.nId = nId;
pIter.first->second.nId = nId;
} else
{
pIter.first->second.aIds.push_back( nId );
}
if ( !bIsVisible )
m_pImpl->HideItem( nId, aCommandURL );
// Support add-on toolbar merging here. Working directly on the toolbar object is much // simpler and faster.
MergeToolbarInstructionContainer aMergeInstructionContainer;
// Retrieve the toolbar name from the resource name
OUString aToolbarName( rResourceName );
sal_Int32 nIndex = aToolbarName.lastIndexOf( '/' ); if (( nIndex > 0 ) && ( nIndex < aToolbarName.getLength() ))
aToolbarName = aToolbarName.copy( nIndex+1 );
// Create AddonsParams to hold additional information we will need in the future
AddonsParams* pRuntimeItemData = new AddonsParams;
pRuntimeItemData->aControlType = aControlType;
pRuntimeItemData->nWidth = nWidth;
m_pToolBar->SetItemData( nId, pRuntimeItemData );
// Fill command map. It stores all our commands and from what // image manager we got our image. So we can decide if we have to use an // image from a notification message. auto pIter = m_aCommandMap.emplace( aURL, aCmdInfo ); if ( pIter.second )
{
aCmdInfo.nId = nId;
pIter.first->second.nId = nId;
} else
{
pIter.first->second.aIds.push_back( nId );
}
++nId;
}
}
}
// Don't setup images yet, AddonsToolbarWrapper::populateImages does that. // (But some controllers might need an image at the toolbar at creation time!)
CreateControllers();
// Notify controllers that they are now correctly initialized and can start listening.
UpdateControllers();
}
CommandInfo aCmdInfo; bool bInsertSeparator = false; for ( ToolBox::ImplToolItems::size_type i = 0; i < pParent->GetItemCount(); ++i )
{
ToolBoxItemId nId = pParent->GetItemId( i ); if ( pParent->IsItemClipped( nId ) )
{ if ( bInsertSeparator )
{
m_pToolBar->InsertSeparator();
bInsertSeparator = false;
}
const OUString aCommandURL( pParent->GetItemCommand( nId ) );
m_pToolBar->InsertItem( nId, pParent->GetItemText( nId ), aCommandURL );
m_pToolBar->SetQuickHelpText( nId, pParent->GetQuickHelpText( nId ) );
// Handle possible add-on controls.
AddonsParams* pAddonParams = static_cast< AddonsParams* >( pParent->GetItemData( nId ) ); if ( pAddonParams )
m_pToolBar->SetItemData( nId, new AddonsParams( *pAddonParams ) );
// Fill command map. It stores all our commands and from what // image manager we got our image. So we can decide if we have to use an // image from a notification message. auto pIter = m_aCommandMap.emplace( aCommandURL, aCmdInfo ); if ( pIter.second )
{
aCmdInfo.nId = nId;
pIter.first->second.nId = nId;
} else
{
pIter.first->second.aIds.push_back( nId );
}
} else
{
ToolBoxItemType eType = pParent->GetItemType( i ); if ( m_pToolBar->GetItemCount() &&
( eType == ToolBoxItemType::SEPARATOR || eType == ToolBoxItemType::BREAK ) )
bInsertSeparator = true;
}
}
InitImageManager();
// Request images for all toolbar items. Must be done before CreateControllers as // some controllers need access to the image.
RequestImages();
// Create controllers after we set the images. There are controllers which needs // an image at the toolbar at creation time!
CreateControllers();
// Notify controllers that they are now correctly initialized and can start listening // toolbars that will open in popup mode will be updated immediately to avoid flickering
UpdateControllers();
}
sal_uInt32 i = 0;
CommandToInfoMap::iterator pIter = m_aCommandMap.begin();
CommandToInfoMap::iterator pEnd = m_aCommandMap.end(); while ( pIter != pEnd )
{
Image aImage; if ( aDocGraphicSeq.hasElements() )
aImage = Image( aDocGraphicSeq[i] ); if ( !aImage )
{
aImage = Image( aModGraphicSeq[i] ); // Try also to query for add-on images before giving up and use an // empty image. if ( !aImage )
aImage = Image(framework::AddonsOptions().GetImageFromURL(aCmdURLSeq[i], SvtMiscOptions::AreCurrentSymbolsLarge()));
pIter->second.nImageInfo = 1; // mark image as module based
} else
{
pIter->second.nImageInfo = 0; // mark image as document based
}
setToolBarImage(aImage,pIter);
++pIter;
++i;
}
assert(!m_aImageController); // an existing one isn't disposed here
m_aImageController = new ImageOrientationController(m_xContext, m_xFrame, m_pImpl->GetInterface(), m_aModuleIdentifier);
m_aImageController->update();
}
ToolBoxItemId nId( m_pImpl->GetCurItemId() );
ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find( nId ); if ( pIter == m_aControllerMap.end() ) return;
ToolBoxItemId nId( m_pImpl->GetCurItemId() );
ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find( nId ); if ( pIter == m_aControllerMap.end() ) return;
void ToolBarManager::AddCustomizeMenuItems(ToolBox const * pToolBar)
{ if (!m_pToolBar) return;
// No config menu entries if command ".uno:ConfigureDialog" is not enabled
Reference< XDispatch > xDisp;
css::util::URL aURL; if ( m_xFrame.is() )
{
Reference< XDispatchProvider > xProv( m_xFrame, UNO_QUERY );
aURL.Complete = ".uno:ConfigureDialog";
m_xURLTransformer->parseStrict( aURL ); if ( xProv.is() )
xDisp = xProv->queryDispatch( aURL, OUString(), 0 );
if ( !xDisp.is() || IsPluginMode() ) return;
}
// popup menu for quick customization bool bHideDisabledEntries = !officecfg::Office::Common::View::Menu::DontHideDisabledEntry::get();
::PopupMenu *pMenu = pToolBar->GetMenu();
// copy all menu items 'Visible buttons, Customize toolbar, Dock toolbar, // Dock all Toolbars) from the loaded resource into the toolbar menu
sal_uInt16 nGroupLen = pMenu->GetItemCount(); if (nGroupLen)
pMenu->InsertSeparator();
VclPtr<PopupMenu> xVisibleItemsPopupMenu;
if (!m_aResourceName.startsWith("private:resource/toolbar/addon_"))
{
pMenu->InsertItem(MENUITEM_TOOLBAR_VISIBLEBUTTON, FwkResId(STR_TOOLBAR_VISIBLE_BUTTONS));
xVisibleItemsPopupMenu = VclPtr<PopupMenu>::Create();
pMenu->SetPopupMenu(MENUITEM_TOOLBAR_VISIBLEBUTTON, xVisibleItemsPopupMenu);
if (m_pToolBar->IsCustomize())
{
pMenu->InsertItem(MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR, FwkResId(STR_TOOLBAR_CUSTOMIZE_TOOLBAR));
pMenu->SetItemCommand(MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR, u".uno:ConfigureToolboxVisible"_ustr);
}
pMenu->InsertSeparator();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.