1*ae13266dSAndre Fischer /************************************************************** 2*ae13266dSAndre Fischer * 3*ae13266dSAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one 4*ae13266dSAndre Fischer * or more contributor license agreements. See the NOTICE file 5*ae13266dSAndre Fischer * distributed with this work for additional information 6*ae13266dSAndre Fischer * regarding copyright ownership. The ASF licenses this file 7*ae13266dSAndre Fischer * to you under the Apache License, Version 2.0 (the 8*ae13266dSAndre Fischer * "License"); you may not use this file except in compliance 9*ae13266dSAndre Fischer * with the License. You may obtain a copy of the License at 10*ae13266dSAndre Fischer * 11*ae13266dSAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0 12*ae13266dSAndre Fischer * 13*ae13266dSAndre Fischer * Unless required by applicable law or agreed to in writing, 14*ae13266dSAndre Fischer * software distributed under the License is distributed on an 15*ae13266dSAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ae13266dSAndre Fischer * KIND, either express or implied. See the License for the 17*ae13266dSAndre Fischer * specific language governing permissions and limitations 18*ae13266dSAndre Fischer * under the License. 19*ae13266dSAndre Fischer * 20*ae13266dSAndre Fischer *************************************************************/ 21*ae13266dSAndre Fischer 22*ae13266dSAndre Fischer #include "precompiled_sfx2.hxx" 23*ae13266dSAndre Fischer 24*ae13266dSAndre Fischer #include "sfx2/sidebar/ControllerFactory.hxx" 25*ae13266dSAndre Fischer #include "sfx2/sidebar/CommandInfoProvider.hxx" 26*ae13266dSAndre Fischer #include "sfx2/sidebar/Tools.hxx" 27*ae13266dSAndre Fischer 28*ae13266dSAndre Fischer #include <com/sun/star/frame/XToolbarController.hpp> 29*ae13266dSAndre Fischer #include <com/sun/star/frame/XFrame.hpp> 30*ae13266dSAndre Fischer 31*ae13266dSAndre Fischer #include <framework/sfxhelperfunctions.hxx> 32*ae13266dSAndre Fischer #include <svtools/generictoolboxcontroller.hxx> 33*ae13266dSAndre Fischer #include <comphelper/processfactory.hxx> 34*ae13266dSAndre Fischer 35*ae13266dSAndre Fischer 36*ae13266dSAndre Fischer using namespace css; 37*ae13266dSAndre Fischer using namespace cssu; 38*ae13266dSAndre Fischer using ::rtl::OUString; 39*ae13266dSAndre Fischer 40*ae13266dSAndre Fischer 41*ae13266dSAndre Fischer namespace sfx2 { namespace sidebar { 42*ae13266dSAndre Fischer 43*ae13266dSAndre Fischer Reference<frame::XToolbarController> ControllerFactory::CreateToolBoxController( 44*ae13266dSAndre Fischer ToolBox* pToolBox, 45*ae13266dSAndre Fischer const sal_uInt16 nItemId, 46*ae13266dSAndre Fischer const OUString& rsCommandName, 47*ae13266dSAndre Fischer const Reference<frame::XFrame>& rxFrame) 48*ae13266dSAndre Fischer { 49*ae13266dSAndre Fischer // Create a controller for the new item. 50*ae13266dSAndre Fischer Reference<frame::XToolbarController> xController( 51*ae13266dSAndre Fischer static_cast<XWeak*>(::framework::CreateToolBoxController( 52*ae13266dSAndre Fischer rxFrame, 53*ae13266dSAndre Fischer pToolBox, 54*ae13266dSAndre Fischer nItemId, 55*ae13266dSAndre Fischer rsCommandName)), 56*ae13266dSAndre Fischer UNO_QUERY); 57*ae13266dSAndre Fischer if ( ! xController.is()) 58*ae13266dSAndre Fischer xController.set( 59*ae13266dSAndre Fischer static_cast<XWeak*>(new svt::GenericToolboxController( 60*ae13266dSAndre Fischer ::comphelper::getProcessServiceFactory(), 61*ae13266dSAndre Fischer rxFrame, 62*ae13266dSAndre Fischer pToolBox, 63*ae13266dSAndre Fischer nItemId, 64*ae13266dSAndre Fischer rsCommandName)), 65*ae13266dSAndre Fischer UNO_QUERY); 66*ae13266dSAndre Fischer 67*ae13266dSAndre Fischer // Initialize the controller with eg a service factory. 68*ae13266dSAndre Fischer Reference<lang::XInitialization> xInitialization (xController, UNO_QUERY); 69*ae13266dSAndre Fischer if (xInitialization.is()) 70*ae13266dSAndre Fischer { 71*ae13266dSAndre Fischer beans::PropertyValue aPropValue; 72*ae13266dSAndre Fischer std::vector<Any> aPropertyVector; 73*ae13266dSAndre Fischer 74*ae13266dSAndre Fischer aPropValue.Name = A2S("Frame"); 75*ae13266dSAndre Fischer aPropValue.Value <<= rxFrame; 76*ae13266dSAndre Fischer aPropertyVector.push_back(makeAny(aPropValue)); 77*ae13266dSAndre Fischer 78*ae13266dSAndre Fischer aPropValue.Name = A2S("ServiceManager"); 79*ae13266dSAndre Fischer aPropValue.Value <<= ::comphelper::getProcessServiceFactory(); 80*ae13266dSAndre Fischer aPropertyVector.push_back(makeAny(aPropValue)); 81*ae13266dSAndre Fischer 82*ae13266dSAndre Fischer aPropValue.Name = A2S("CommandURL"); 83*ae13266dSAndre Fischer aPropValue.Value <<= rsCommandName; 84*ae13266dSAndre Fischer aPropertyVector.push_back(makeAny(aPropValue)); 85*ae13266dSAndre Fischer 86*ae13266dSAndre Fischer Sequence<Any> aArgs (comphelper::containerToSequence(aPropertyVector)); 87*ae13266dSAndre Fischer xInitialization->initialize(aArgs); 88*ae13266dSAndre Fischer } 89*ae13266dSAndre Fischer 90*ae13266dSAndre Fischer Reference<util::XUpdatable> xUpdatable (xController, UNO_QUERY); 91*ae13266dSAndre Fischer if (xUpdatable.is()) 92*ae13266dSAndre Fischer xUpdatable->update(); 93*ae13266dSAndre Fischer 94*ae13266dSAndre Fischer // Add label. 95*ae13266dSAndre Fischer if (xController.is()) 96*ae13266dSAndre Fischer { 97*ae13266dSAndre Fischer const OUString sLabel (sfx2::sidebar::CommandInfoProvider::Instance().GetLabelForCommand( 98*ae13266dSAndre Fischer rsCommandName, 99*ae13266dSAndre Fischer rxFrame)); 100*ae13266dSAndre Fischer pToolBox->SetQuickHelpText(nItemId, sLabel); 101*ae13266dSAndre Fischer pToolBox->EnableItem(nItemId); 102*ae13266dSAndre Fischer } 103*ae13266dSAndre Fischer 104*ae13266dSAndre Fischer return xController; 105*ae13266dSAndre Fischer } 106*ae13266dSAndre Fischer 107*ae13266dSAndre Fischer 108*ae13266dSAndre Fischer } } // end of namespace sfx2::sidebar 109