LCOV - code coverage report
Current view: top level - sfx2/source/sidebar - ControllerFactory.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 75 0.0 %
Date: 2014-04-11 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <sfx2/sidebar/ControllerFactory.hxx>
      21             : #include <sfx2/sidebar/CommandInfoProvider.hxx>
      22             : #include <sfx2/sidebar/Tools.hxx>
      23             : 
      24             : #include <com/sun/star/frame/XToolbarController.hpp>
      25             : #include <com/sun/star/frame/XFrame.hpp>
      26             : #include <com/sun/star/frame/theToolbarControllerFactory.hpp>
      27             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      28             : 
      29             : #include <framework/sfxhelperfunctions.hxx>
      30             : #include <svtools/generictoolboxcontroller.hxx>
      31             : #include <comphelper/processfactory.hxx>
      32             : #include <toolkit/helper/vclunohelper.hxx>
      33             : 
      34             : 
      35             : using namespace css;
      36             : using namespace cssu;
      37             : using ::rtl::OUString;
      38             : 
      39             : 
      40             : namespace sfx2 { namespace sidebar {
      41             : 
      42           0 : Reference<frame::XToolbarController> ControllerFactory::CreateToolBoxController(
      43             :     ToolBox* pToolBox,
      44             :     const sal_uInt16 nItemId,
      45             :     const OUString& rsCommandName,
      46             :     const Reference<frame::XFrame>& rxFrame,
      47             :     const Reference<awt::XWindow>& rxParentWindow,
      48             :     const sal_Int32 nWidth)
      49             : {
      50             :     Reference<frame::XToolbarController> xController (
      51             :         CreateToolBarController(
      52             :             pToolBox,
      53             :             rsCommandName,
      54             :             rxFrame,
      55           0 :             nWidth));
      56             : 
      57             :     // Create a controller for the new item.
      58           0 :     if ( ! xController.is())
      59             :     {
      60             :         xController.set(
      61             :             static_cast<XWeak*>(::framework::CreateToolBoxController(
      62             :                     rxFrame,
      63             :                     pToolBox,
      64             :                     nItemId,
      65           0 :                     rsCommandName)),
      66           0 :             UNO_QUERY);
      67             :     }
      68           0 :     if ( ! xController.is())
      69             :     {
      70             :         xController.set(
      71             :             static_cast<XWeak*>(new svt::GenericToolboxController(
      72             :                     ::comphelper::getProcessComponentContext(),
      73             :                     rxFrame,
      74             :                     pToolBox,
      75             :                     nItemId,
      76           0 :                     rsCommandName)),
      77           0 :             UNO_QUERY);
      78             :     }
      79             : 
      80             :     // Initialize the controller with eg a service factory.
      81           0 :     Reference<lang::XInitialization> xInitialization (xController, UNO_QUERY);
      82           0 :     if (xInitialization.is())
      83             :     {
      84           0 :         beans::PropertyValue aPropValue;
      85           0 :         std::vector<Any> aPropertyVector;
      86             : 
      87           0 :         aPropValue.Name = "Frame";
      88           0 :         aPropValue.Value <<= rxFrame;
      89           0 :         aPropertyVector.push_back(makeAny(aPropValue));
      90             : 
      91           0 :         aPropValue.Name = "ServiceManager";
      92           0 :         aPropValue.Value <<= ::comphelper::getProcessServiceFactory();
      93           0 :         aPropertyVector.push_back(makeAny(aPropValue));
      94             : 
      95           0 :         aPropValue.Name = "CommandURL";
      96           0 :         aPropValue.Value <<= rsCommandName;
      97           0 :         aPropertyVector.push_back(makeAny(aPropValue));
      98             : 
      99           0 :         Sequence<Any> aArgs (comphelper::containerToSequence(aPropertyVector));
     100           0 :         xInitialization->initialize(aArgs);
     101             :     }
     102             : 
     103           0 :     if (xController.is())
     104             :     {
     105           0 :         if (rxParentWindow.is())
     106             :         {
     107           0 :             Reference<awt::XWindow> xItemWindow (xController->createItemWindow(rxParentWindow));
     108           0 :             Window* pItemWindow = VCLUnoHelper::GetWindow(xItemWindow);
     109           0 :             if (pItemWindow != NULL)
     110             :             {
     111           0 :                 WindowType nType = pItemWindow->GetType();
     112           0 :                 if (nType == WINDOW_LISTBOX || nType == WINDOW_MULTILISTBOX || nType == WINDOW_COMBOBOX)
     113           0 :                     pItemWindow->SetAccessibleName(pToolBox->GetItemText(nItemId));
     114           0 :                 if (nWidth > 0)
     115           0 :                     pItemWindow->SetSizePixel(Size(nWidth, pItemWindow->GetSizePixel().Height()));
     116           0 :                 pToolBox->SetItemWindow(nItemId, pItemWindow);
     117           0 :             }
     118             :         }
     119             : 
     120           0 :         Reference<util::XUpdatable> xUpdatable (xController, UNO_QUERY);
     121           0 :         if (xUpdatable.is())
     122           0 :             xUpdatable->update();
     123             : 
     124             :         // Add label.
     125           0 :         if (xController.is())
     126             :         {
     127           0 :             const OUString sLabel (sfx2::sidebar::CommandInfoProvider::Instance().GetLabelForCommand(
     128             :                     rsCommandName,
     129           0 :                     rxFrame));
     130           0 :             pToolBox->SetQuickHelpText(nItemId, sLabel);
     131           0 :             pToolBox->EnableItem(nItemId);
     132           0 :         }
     133             :     }
     134             : 
     135           0 :     return xController;
     136             : }
     137             : 
     138             : 
     139             : 
     140             : 
     141           0 : Reference<frame::XToolbarController> ControllerFactory::CreateToolBarController(
     142             :     ToolBox* pToolBox,
     143             :     const OUString& rsCommandName,
     144             :     const Reference<frame::XFrame>& rxFrame,
     145             :     const sal_Int32 nWidth)
     146             : {
     147             :     try
     148             :     {
     149           0 :         Reference<XComponentContext> xContext = comphelper::getProcessComponentContext();
     150           0 :         Reference<frame::XUIControllerFactory> xFactory = frame::theToolbarControllerFactory::get( xContext );
     151           0 :         OUString sModuleName (Tools::GetModuleName(rxFrame));
     152             : 
     153           0 :         if (xFactory.is() && xFactory->hasController(rsCommandName,  sModuleName))
     154             :         {
     155           0 :             beans::PropertyValue aPropValue;
     156           0 :             std::vector<Any> aPropertyVector;
     157             : 
     158           0 :             aPropValue.Name = "ModuleIdentifier";
     159           0 :             aPropValue.Value <<= sModuleName;
     160           0 :             aPropertyVector.push_back( makeAny( aPropValue ));
     161             : 
     162           0 :             aPropValue.Name = "Frame";
     163           0 :             aPropValue.Value <<= rxFrame;
     164           0 :             aPropertyVector.push_back( makeAny( aPropValue ));
     165             : 
     166           0 :             aPropValue.Name = "ServiceManager";
     167           0 :             aPropValue.Value <<= comphelper::getProcessServiceFactory();
     168           0 :             aPropertyVector.push_back( makeAny( aPropValue ));
     169             : 
     170           0 :             aPropValue.Name = "ParentWindow";
     171           0 :             aPropValue.Value <<= VCLUnoHelper::GetInterface(pToolBox);
     172           0 :             aPropertyVector.push_back( makeAny( aPropValue ));
     173             : 
     174           0 :             if (nWidth > 0)
     175             :             {
     176           0 :                 aPropValue.Name = "Width";
     177           0 :                 aPropValue.Value <<= nWidth;
     178           0 :                 aPropertyVector.push_back( makeAny( aPropValue ));
     179             :             }
     180             : 
     181           0 :             Sequence<Any> aArgs (comphelper::containerToSequence(aPropertyVector));
     182             :             return Reference<frame::XToolbarController>(
     183           0 :                 xFactory->createInstanceWithArgumentsAndContext(
     184             :                     rsCommandName,
     185             :                     aArgs,
     186           0 :                     xContext),
     187           0 :                 UNO_QUERY);
     188           0 :         }
     189             :     }
     190           0 :     catch (Exception&)
     191             :     {
     192             :         // Ignore exception.
     193             :     }
     194           0 :     return NULL;
     195             : }
     196             : 
     197             : } } // end of namespace sfx2::sidebar
     198             : 
     199             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10