LCOV - code coverage report
Current view: top level - svx/source/sidebar/insert - InsertPropertyPanel.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 62 1.6 %
Date: 2015-06-13 12:38:46 Functions: 2 8 25.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             : #include "InsertPropertyPanel.hxx"
      20             : #include "sfx2/sidebar/CommandInfoProvider.hxx"
      21             : 
      22             : #include <sfx2/sidebar/Theme.hxx>
      23             : #include <sfx2/sidebar/Tools.hxx>
      24             : #include <sfx2/sidebar/ControlFactory.hxx>
      25             : #include <sfx2/sidebar/ControllerFactory.hxx>
      26             : 
      27             : #include <svx/dialmgr.hxx>
      28             : #include <svtools/miscopt.hxx>
      29             : #include <svtools/generictoolboxcontroller.hxx>
      30             : #include <vcl/toolbox.hxx>
      31             : #include <sfx2/tbxctrl.hxx>
      32             : #include <framework/sfxhelperfunctions.hxx>
      33             : #include <framework/imageproducer.hxx>
      34             : #include <comphelper/processfactory.hxx>
      35             : #include <cppuhelper/compbase1.hxx>
      36             : #include <cppuhelper/basemutex.hxx>
      37             : 
      38             : #include <com/sun/star/frame/XStatusListener.hpp>
      39             : 
      40             : using namespace css;
      41             : using namespace css::uno;
      42             : using ::rtl::OUString;
      43             : using ::sfx2::sidebar::SidebarToolBox;
      44             : 
      45             : namespace svx { namespace sidebar {
      46             : 
      47             : 
      48           0 : InsertPropertyPanel::InsertPropertyPanel (
      49             :     vcl::Window* pParent,
      50             :     const css::uno::Reference<css::frame::XFrame>& rxFrame)
      51             :     :   PanelLayout(pParent, "InsertPropertyPanel", "svx/ui/sidebarinsert.ui", rxFrame),
      52           0 :         mxFrame(rxFrame)
      53             : {
      54           0 :     get(mpStandardShapesToolBox, "standardshapes");
      55           0 :     get(mpCustomShapesToolBox,   "customshapes");
      56             : 
      57           0 :     mpStandardShapesToolBox->Show();
      58           0 :     mpCustomShapesToolBox->Show();
      59             : 
      60             :     // Listen to all tool box selection events.
      61             :     // FIXME: This is an incredibly ugly hack that we should kill at some
      62             :     // stage.  It is needed because the mpCustomShapesToolBox somehow does not
      63             :     // get the right controller, and so the images there are not updated when
      64             :     // the user selects eg. a callout.  But using the help id's to get/update
      65             :     // it (that is what functionSelected() does) is not the way to go in
      66             :     // general ;-)
      67             :     // In other words, we should find the underlying problem, and remove the
      68             :     // WindowEventListener for good.
      69           0 :     vcl::Window* pTopWindow = pParent;
      70           0 :     while (pTopWindow->GetParent() != NULL)
      71           0 :         pTopWindow = pTopWindow->GetParent();
      72           0 :     pTopWindow->AddChildEventListener(LINK(this, InsertPropertyPanel, WindowEventListener));
      73           0 : }
      74             : 
      75           0 : InsertPropertyPanel::~InsertPropertyPanel()
      76             : {
      77           0 :     disposeOnce();
      78           0 : }
      79             : 
      80           0 : void InsertPropertyPanel::dispose()
      81             : {
      82             :     // Remove window child listener.
      83           0 :     vcl::Window* pTopWindow = this;
      84           0 :     while (pTopWindow->GetParent() != NULL)
      85           0 :         pTopWindow = pTopWindow->GetParent();
      86           0 :     pTopWindow->RemoveChildEventListener(LINK(this, InsertPropertyPanel, WindowEventListener));
      87           0 :     mpStandardShapesToolBox.clear();
      88           0 :     mpCustomShapesToolBox.clear();
      89           0 :     PanelLayout::dispose();
      90           0 : }
      91             : 
      92             : 
      93             : 
      94             : 
      95           0 : IMPL_LINK(InsertPropertyPanel, WindowEventListener, VclSimpleEvent*, pEvent)
      96             : {
      97             :     // We will be getting a lot of window events (well, basically all
      98             :     // of them), so reject early everything that is not connected to
      99             :     // toolbox selection.
     100           0 :     if (pEvent == NULL)
     101           0 :         return 1;
     102           0 :     if ( ! pEvent->ISA(VclWindowEvent))
     103           0 :         return 1;
     104           0 :     if (pEvent->GetId() != VCLEVENT_TOOLBOX_SELECT)
     105           0 :         return 1;
     106             : 
     107           0 :     VclWindowEvent* pWindowEvent = dynamic_cast<VclWindowEvent*>(pEvent);
     108           0 :     vcl::Window* pWindow = pWindowEvent ? pWindowEvent->GetWindow() : NULL;
     109           0 :     ToolBox* pToolBox = dynamic_cast<ToolBox*>(pWindow);
     110           0 :     if (pToolBox == NULL)
     111           0 :         return 1;
     112             : 
     113             :     // Extract name of (sub)toolbar from help id.
     114           0 :     OUString sToolbarName (rtl::OStringToOUString(pToolBox->GetHelpId(), RTL_TEXTENCODING_UTF8));
     115           0 :     if (sToolbarName.getLength() == 0)
     116           0 :         return 1;
     117           0 :     const util::URL aURL (sfx2::sidebar::Tools::GetURL(sToolbarName));
     118           0 :     if (aURL.Path.getLength() == 0)
     119           0 :         return 1;
     120             : 
     121             :     // Get item id.
     122           0 :     sal_uInt16 nId = pToolBox->GetCurItemId();
     123           0 :     if (nId == 0)
     124           0 :         return 1;
     125             : 
     126           0 :     SidebarToolBox* pSidebarToolBox = dynamic_cast<SidebarToolBox*>(mpStandardShapesToolBox.get());
     127           0 :     if (pSidebarToolBox == NULL)
     128           0 :         return 1;
     129           0 :     sal_uInt16 nItemId (pSidebarToolBox->GetItemIdForSubToolbarName(aURL.Path));
     130           0 :     if (nItemId == 0)
     131             :     {
     132           0 :         pSidebarToolBox = dynamic_cast<SidebarToolBox*>(mpCustomShapesToolBox.get());
     133           0 :         if (pSidebarToolBox == NULL)
     134           0 :             return 1;
     135           0 :         nItemId = pSidebarToolBox->GetItemIdForSubToolbarName(aURL.Path);
     136           0 :         if (nItemId == 0)
     137           0 :             return 1;
     138             :     }
     139             : 
     140           0 :     Reference<frame::XSubToolbarController> xController (pSidebarToolBox->GetControllerForItemId(nItemId), UNO_QUERY);
     141           0 :     if ( ! xController.is() )
     142           0 :         return 1;
     143             : 
     144           0 :     const OUString sCommand (pToolBox->GetItemCommand(nId));
     145           0 :     xController->functionSelected(sCommand);
     146             : 
     147           0 :     return 1;
     148             : }
     149             : 
     150             : 
     151         390 : } } // end of namespace svx::sidebar
     152             : 
     153             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11