/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * 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 . */ #include #include #include #include #include #include #include #include #include #include #include using namespace css; using namespace css::uno; using ::rtl::OUString; namespace sfx2 { namespace sidebar { Reference ControllerFactory::CreateToolBoxController( ToolBox* pToolBox, const sal_uInt16 nItemId, const OUString& rsCommandName, const Reference& rxFrame, const Reference& rxController, const Reference& rxParentWindow, const sal_Int32 nWidth) { Reference xController ( CreateToolBarController( pToolBox, rsCommandName, rxFrame, rxController, nWidth)); bool bFactoryHasController( xController.is() ); // Create a controller for the new item. if ( !bFactoryHasController ) { xController.set( static_cast(::framework::CreateToolBoxController( rxFrame, pToolBox, nItemId, rsCommandName)), UNO_QUERY); } if ( ! xController.is()) { xController.set( static_cast(new svt::GenericToolboxController( ::comphelper::getProcessComponentContext(), rxFrame, pToolBox, nItemId, rsCommandName)), UNO_QUERY); } // Initialize the controller with eg a service factory. Reference xInitialization (xController, UNO_QUERY); if (!bFactoryHasController && xInitialization.is()) { beans::PropertyValue aPropValue; std::vector aPropertyVector; aPropValue.Name = "Frame"; aPropValue.Value <<= rxFrame; aPropertyVector.push_back(makeAny(aPropValue)); aPropValue.Name = "ServiceManager"; aPropValue.Value <<= ::comphelper::getProcessServiceFactory(); aPropertyVector.push_back(makeAny(aPropValue)); aPropValue.Name = "CommandURL"; aPropValue.Value <<= rsCommandName; aPropertyVector.push_back(makeAny(aPropValue)); Sequence aArgs (comphelper::containerToSequence(aPropertyVector)); xInitialization->initialize(aArgs); } if (xController.is()) { if (rxParentWindow.is()) { Reference xItemWindow (xController->createItemWindow(rxParentWindow)); vcl::Window* pItemWindow = VCLUnoHelper::GetWindow(xItemWindow); if (pItemWindow != nullptr) { WindowType nType = pItemWindow->GetType(); if (nType == WINDOW_LISTBOX || nType == WINDOW_MULTILISTBOX || nType == WINDOW_COMBOBOX) pItemWindow->SetAccessibleName(pToolBox->GetItemText(nItemId)); if (nWidth > 0) pItemWindow->SetSizePixel(Size(nWidth, pItemWindow->GetSizePixel().Height())); pToolBox->SetItemWindow(nItemId, pItemWindow); } } Reference xUpdatable (xController, UNO_QUERY); if (xUpdatable.is()) xUpdatable->update(); // Add tooltip. if (xController.is()) { const OUString sTooltip (vcl::CommandInfoProvider::Instance().GetTooltipForCommand( rsCommandName, rxFrame)); pToolBox->SetQuickHelpText(nItemId, sTooltip); pToolBox->EnableItem(nItemId); } } return xController; } Reference ControllerFactory::CreateToolBarController( ToolBox* pToolBox, const OUString& rsCommandName, const Reference& rxFrame, const Reference& rxController, const sal_Int32 nWidth) { try { Reference xContext = comphelper::getProcessComponentContext(); Reference xFactory = frame::theToolbarControllerFactory::get( xContext ); OUString sModuleName (Tools::GetModuleName(rxController)); if (xFactory.is() && xFactory->hasController(rsCommandName, sModuleName)) { beans::PropertyValue aPropValue; std::vector aPropertyVector; aPropValue.Name = "ModuleIdentifier"; aPropValue.Value <<= sModuleName; aPropertyVector.push_back( makeAny( aPropValue )); aPropValue.Name = "Frame"; aPropValue.Value <<= rxFrame; aPropertyVector.push_back( makeAny( aPropValue )); aPropValue.Name = "ServiceManager"; aPropValue.Value <<= comphelper::getProcessServiceFactory(); aPropertyVector.push_back( makeAny( aPropValue )); aPropValue.Name = "ParentWindow"; aPropValue.Value <<= VCLUnoHelper::GetInterface(pToolBox); aPropertyVector.push_back( makeAny( aPropValue )); if (nWidth > 0) { aPropValue.Name = "Width"; aPropValue.Value <<= nWidth; aPropertyVector.push_back( makeAny( aPropValue )); } Sequence aArgs (comphelper::containerToSequence(aPropertyVector)); return Reference( xFactory->createInstanceWithArgumentsAndContext( rsCommandName, aArgs, xContext), UNO_QUERY); } } catch (Exception&) { // Ignore exception. } return nullptr; } } } // end of namespace sfx2::sidebar /* vim:set shiftwidth=4 softtabstop=4 expandtab: */