LCOV - code coverage report
Current view: top level - sfx2/source/sidebar - SidebarToolBox.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 17 133 12.8 %
Date: 2014-04-11 Functions: 3 24 12.5 %
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/SidebarToolBox.hxx>
      21             : #include <sfx2/sidebar/ControllerFactory.hxx>
      22             : #include <sfx2/sidebar/Theme.hxx>
      23             : #include <sfx2/sidebar/Tools.hxx>
      24             : 
      25             : #include <vcl/builder.hxx>
      26             : #include <vcl/gradient.hxx>
      27             : #include <toolkit/helper/vclunohelper.hxx>
      28             : #include <svtools/miscopt.hxx>
      29             : #include <framework/imageproducer.hxx>
      30             : #include <com/sun/star/frame/XSubToolbarController.hpp>
      31             : 
      32             : 
      33             : using namespace ::com::sun::star;
      34             : using namespace ::com::sun::star::uno;
      35             : using ::rtl::OUString;
      36             : 
      37             : 
      38             : namespace sfx2 { namespace sidebar {
      39             : 
      40             : 
      41          22 : SidebarToolBox::SidebarToolBox (Window* pParentWindow)
      42             :     : ToolBox(pParentWindow, 0),
      43             :       maItemSeparator(Theme::GetImage(Theme::Image_ToolBoxItemSeparator)),
      44             :       maControllers(),
      45          22 :       mbAreHandlersRegistered(false)
      46             : {
      47          22 :     SetBackground(Wallpaper());
      48          22 :     SetPaintTransparent(true);
      49          22 :     SetToolboxButtonSize( TOOLBOX_BUTTONSIZE_SMALL );
      50             : 
      51             : #ifdef DEBUG
      52             :     SetText(OUString("SidebarToolBox"));
      53             : #endif
      54          22 : }
      55             : 
      56           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSidebarToolBox(Window *pParent, VclBuilder::stringmap &)
      57             : {
      58           0 :     return new SidebarToolBox(pParent);
      59             : }
      60             : 
      61          44 : SidebarToolBox::~SidebarToolBox (void)
      62             : {
      63          22 :     ControllerContainer aControllers;
      64          22 :     aControllers.swap(maControllers);
      65          22 :     for (ControllerContainer::iterator iController(aControllers.begin()), iEnd(aControllers.end());
      66             :          iController!=iEnd;
      67             :          ++iController)
      68             :     {
      69           0 :         Reference<lang::XComponent> xComponent (iController->second.mxController, UNO_QUERY);
      70           0 :         if (xComponent.is())
      71           0 :             xComponent->dispose();
      72           0 :     }
      73             : 
      74          22 :     if (mbAreHandlersRegistered)
      75             :     {
      76           0 :         SetDropdownClickHdl(Link());
      77           0 :         SetClickHdl(Link());
      78           0 :         SetDoubleClickHdl(Link());
      79           0 :         SetSelectHdl(Link());
      80           0 :         SetActivateHdl(Link());
      81           0 :         SetDeactivateHdl(Link());
      82          22 :     }
      83          22 : }
      84             : 
      85           0 : void SidebarToolBox::InsertItem(const OUString& rCommand,
      86             :         const com::sun::star::uno::Reference<com::sun::star::frame::XFrame>& rFrame,
      87             :         ToolBoxItemBits nBits, const Size& rRequestedSize, sal_uInt16 nPos)
      88             : {
      89           0 :     ToolBox::InsertItem(rCommand, rFrame, nBits, rRequestedSize, nPos);
      90             : 
      91           0 :     CreateController(GetItemId(rCommand), rFrame, std::max(rRequestedSize.Width(), 0L));
      92           0 :     RegisterHandlers();
      93           0 : }
      94             : 
      95          21 : void SidebarToolBox::Paint (const Rectangle& rRect)
      96             : {
      97          21 :     ToolBox::Paint(rRect);
      98             : 
      99          21 :     if (Theme::GetBoolean(Theme::Bool_UseToolBoxItemSeparator))
     100             :     {
     101           0 :         const sal_Int32 nSeparatorY ((GetSizePixel().Height() - maItemSeparator.GetSizePixel().Height())/2);
     102           0 :         const sal_uInt16 nItemCount (GetItemCount());
     103           0 :         int nLastRight (-1);
     104           0 :         for (sal_uInt16 nIndex=0; nIndex<nItemCount; ++nIndex)
     105             :         {
     106           0 :             const Rectangle aItemBoundingBox (GetItemPosRect(nIndex));
     107           0 :             if (nLastRight >= 0)
     108             :             {
     109           0 :                 const int nSeparatorX ((nLastRight + aItemBoundingBox.Left() - 1) / 2);
     110           0 :                 DrawImage(Point(nSeparatorX,nSeparatorY), maItemSeparator);
     111             :             }
     112             : 
     113           0 :             nLastRight = aItemBoundingBox.Right();
     114             :         }
     115             :     }
     116          21 : }
     117             : 
     118             : 
     119             : 
     120             : 
     121           0 : bool SidebarToolBox::Notify (NotifyEvent& rEvent)
     122             : {
     123           0 :     if (rEvent.GetType() == EVENT_KEYINPUT)
     124             :     {
     125           0 :         if (rEvent.GetKeyEvent()->GetKeyCode().GetCode() == KEY_TAB)
     126             :         {
     127             :             // Special handling for transferring handling of KEY_TAB
     128             :             // that becomes necessary because of our parent that is
     129             :             // not the dialog but a background control.
     130           0 :             return DockingWindow::Notify(rEvent);
     131             :         }
     132             :     }
     133           0 :     return ToolBox::Notify(rEvent);
     134             : }
     135             : 
     136             : 
     137             : 
     138             : 
     139           0 : void SidebarToolBox::CreateController (
     140             :     const sal_uInt16 nItemId,
     141             :     const cssu::Reference<css::frame::XFrame>& rxFrame,
     142             :     const sal_Int32 nItemWidth)
     143             : {
     144           0 :     ItemDescriptor aDescriptor;
     145             : 
     146           0 :     const OUString sCommandName (GetItemCommand(nItemId));
     147             : 
     148           0 :     aDescriptor.mxController = sfx2::sidebar::ControllerFactory::CreateToolBoxController(
     149             :         this,
     150             :         nItemId,
     151             :         sCommandName,
     152             :         rxFrame,
     153             :         VCLUnoHelper::GetInterface(this),
     154           0 :         nItemWidth);
     155           0 :     if (aDescriptor.mxController.is())
     156             :     {
     157           0 :         aDescriptor.maURL = sfx2::sidebar::Tools::GetURL(sCommandName);
     158           0 :         aDescriptor.msCurrentCommand = sCommandName;
     159             : 
     160           0 :         maControllers.insert(::std::make_pair(nItemId, aDescriptor));
     161           0 :     }
     162           0 : }
     163             : 
     164             : 
     165             : 
     166             : 
     167           0 : Reference<frame::XToolbarController> SidebarToolBox::GetControllerForItemId (const sal_uInt16 nItemId) const
     168             : {
     169           0 :     ControllerContainer::const_iterator iController (maControllers.find(nItemId));
     170           0 :     if (iController != maControllers.end())
     171           0 :         return iController->second.mxController;
     172             :     else
     173           0 :         return NULL;
     174             : }
     175             : 
     176             : 
     177             : 
     178             : 
     179           0 : void SidebarToolBox::SetController(
     180             :     const sal_uInt16 nItemId,
     181             :     const cssu::Reference<css::frame::XToolbarController>& rxController,
     182             :     const ::rtl::OUString& rsCommandName)
     183             : {
     184           0 :     ItemDescriptor aDescriptor;
     185           0 :     aDescriptor.mxController = rxController;
     186           0 :     aDescriptor.maURL = sfx2::sidebar::Tools::GetURL(rsCommandName);
     187           0 :     aDescriptor.msCurrentCommand = rsCommandName;
     188             : 
     189           0 :     ControllerContainer::iterator iController (maControllers.find(nItemId));
     190           0 :     if (iController != maControllers.end())
     191             :     {
     192           0 :         Reference<lang::XComponent> xComponent (iController->second.mxController, UNO_QUERY);
     193           0 :         if (xComponent.is())
     194           0 :             xComponent->dispose();
     195             : 
     196           0 :         iController->second = aDescriptor;
     197             :     }
     198             :     else
     199             :     {
     200           0 :         maControllers[nItemId] = aDescriptor;
     201             :     }
     202             : 
     203           0 :     if (rxController.is())
     204           0 :         RegisterHandlers();
     205           0 : }
     206             : 
     207             : 
     208             : 
     209             : 
     210           0 : sal_uInt16 SidebarToolBox::GetItemIdForSubToolbarName (const OUString& rsSubToolbarName) const
     211             : {
     212           0 :     for (ControllerContainer::const_iterator iController(maControllers.begin()), iEnd(maControllers.end());
     213             :          iController!=iEnd;
     214             :          ++iController)
     215             :     {
     216           0 :         Reference<frame::XToolbarController> xController (iController->second.mxController);
     217           0 :         Reference<frame::XSubToolbarController> xSubToolbarController (xController, UNO_QUERY);
     218           0 :         if (xSubToolbarController.is())
     219             :         {
     220           0 :             const OUString sName (xSubToolbarController->getSubToolbarName());
     221           0 :             if (sName.equals(rsSubToolbarName))
     222           0 :                 return iController->first;
     223             :         }
     224           0 :     }
     225           0 :     return 0;
     226             : }
     227             : 
     228             : 
     229             : 
     230             : 
     231           0 : void SidebarToolBox::RegisterHandlers (void)
     232             : {
     233           0 :     if ( ! mbAreHandlersRegistered)
     234             :     {
     235           0 :         mbAreHandlersRegistered = true;
     236           0 :         SetDropdownClickHdl(LINK(this, SidebarToolBox, DropDownClickHandler));
     237           0 :         SetClickHdl(LINK(this, SidebarToolBox, ClickHandler));
     238           0 :         SetDoubleClickHdl(LINK(this, SidebarToolBox, DoubleClickHandler));
     239           0 :         SetSelectHdl(LINK(this, SidebarToolBox, SelectHandler));
     240           0 :         SetActivateHdl(LINK(this, SidebarToolBox, ActivateToolBox));
     241           0 :         SetDeactivateHdl(LINK(this, SidebarToolBox, DeactivateToolBox));
     242             :     }
     243           0 : }
     244             : 
     245             : 
     246             : 
     247             : 
     248           0 : IMPL_LINK(SidebarToolBox, DropDownClickHandler, ToolBox*, pToolBox)
     249             : {
     250           0 :     if (pToolBox != NULL)
     251             :     {
     252           0 :         Reference<frame::XToolbarController> xController (GetControllerForItemId(pToolBox->GetCurItemId()));
     253           0 :         if (xController.is())
     254             :         {
     255           0 :             Reference<awt::XWindow> xWindow = xController->createPopupWindow();
     256           0 :             if (xWindow.is() )
     257           0 :                 xWindow->setFocus();
     258           0 :         }
     259             :     }
     260           0 :     return 1;
     261             : }
     262             : 
     263             : 
     264             : 
     265             : 
     266           0 : IMPL_LINK(SidebarToolBox, ClickHandler, ToolBox*, pToolBox)
     267             : {
     268           0 :     if (pToolBox == NULL)
     269           0 :         return 0;
     270             : 
     271           0 :     Reference<frame::XToolbarController> xController (GetControllerForItemId(pToolBox->GetCurItemId()));
     272           0 :     if (xController.is())
     273           0 :         xController->click();
     274             : 
     275           0 :     return 1;
     276             : }
     277             : 
     278             : 
     279             : 
     280             : 
     281           0 : IMPL_LINK(SidebarToolBox, DoubleClickHandler, ToolBox*, pToolBox)
     282             : {
     283           0 :     if (pToolBox == NULL)
     284           0 :         return 0;
     285             : 
     286           0 :     Reference<frame::XToolbarController> xController (GetControllerForItemId(pToolBox->GetCurItemId()));
     287           0 :     if (xController.is())
     288           0 :         xController->doubleClick();
     289             : 
     290           0 :     return 1;
     291             : }
     292             : 
     293             : 
     294             : 
     295             : 
     296           0 : IMPL_LINK(SidebarToolBox, SelectHandler, ToolBox*, pToolBox)
     297             : {
     298           0 :     if (pToolBox == NULL)
     299           0 :         return 0;
     300             : 
     301           0 :     Reference<frame::XToolbarController> xController (GetControllerForItemId(pToolBox->GetCurItemId()));
     302           0 :     if (xController.is())
     303           0 :         xController->execute((sal_Int16)pToolBox->GetModifier());
     304             : 
     305           0 :     return 1;
     306             : }
     307             : 
     308             : 
     309             : 
     310             : 
     311           0 : IMPL_LINK(SidebarToolBox, ActivateToolBox, ToolBox*, EMPTYARG)
     312             : {
     313           0 :     return 1;
     314             : }
     315             : 
     316             : 
     317             : 
     318             : 
     319           0 : IMPL_LINK(SidebarToolBox, DeactivateToolBox, ToolBox*, EMPTYARG)
     320             : {
     321           0 :     return 1;
     322             : }
     323             : 
     324             : 
     325             : 
     326             : } } // end of namespace sfx2::sidebar
     327             : 
     328             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10