LCOV - code coverage report
Current view: top level - sfx2/source/sidebar - SidebarPanelBase.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 54 67 80.6 %
Date: 2015-06-13 12:38:46 Functions: 13 17 76.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             : #include <sfx2/sidebar/SidebarPanelBase.hxx>
      20             : #include <sfx2/sidebar/Theme.hxx>
      21             : #include <sfx2/sidebar/ILayoutableWindow.hxx>
      22             : #include <sfx2/sidebar/IContextChangeReceiver.hxx>
      23             : #include <sfx2/imagemgr.hxx>
      24             : #include <vcl/ctrl.hxx>
      25             : #include <vcl/layout.hxx>
      26             : #include <comphelper/processfactory.hxx>
      27             : 
      28             : #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp>
      29             : #include <com/sun/star/ui/UIElementType.hpp>
      30             : 
      31             : using namespace css;
      32             : using namespace css::uno;
      33             : 
      34             : namespace sfx2 { namespace sidebar {
      35             : 
      36        4248 : Reference<ui::XUIElement> SidebarPanelBase::Create (
      37             :     const ::rtl::OUString& rsResourceURL,
      38             :     const css::uno::Reference<css::frame::XFrame>& rxFrame,
      39             :     vcl::Window* pWindow,
      40             :     const css::ui::LayoutSize& rLayoutSize)
      41             : {
      42             :     Reference<ui::XUIElement> xUIElement (
      43             :         new SidebarPanelBase(
      44             :             rsResourceURL,
      45             :             rxFrame,
      46             :             pWindow,
      47        4248 :             rLayoutSize));
      48        4248 :     return xUIElement;
      49             : }
      50             : 
      51        4248 : SidebarPanelBase::SidebarPanelBase (
      52             :     const ::rtl::OUString& rsResourceURL,
      53             :     const css::uno::Reference<css::frame::XFrame>& rxFrame,
      54             :     vcl::Window* pWindow,
      55             :     const css::ui::LayoutSize& rLayoutSize)
      56             :     : SidebarPanelBaseInterfaceBase(m_aMutex),
      57             :       mxFrame(rxFrame),
      58             :       mpControl(pWindow),
      59             :       msResourceURL(rsResourceURL),
      60        4248 :       maLayoutSize(rLayoutSize)
      61             : {
      62        4248 :     if (mxFrame.is())
      63             :     {
      64             :         css::uno::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
      65             :             css::ui::ContextChangeEventMultiplexer::get(
      66        4248 :                 ::comphelper::getProcessComponentContext()));
      67        4248 :         if (xMultiplexer.is())
      68        4248 :             xMultiplexer->addContextChangeEventListener(this, mxFrame->getController());
      69             :     }
      70        4248 :     if (mpControl != nullptr)
      71             :     {
      72        4248 :         mpControl->SetBackground(Theme::GetWallpaper(Theme::Paint_PanelBackground));
      73        4248 :         mpControl->Show();
      74             :     }
      75        4248 : }
      76             : 
      77        8496 : SidebarPanelBase::~SidebarPanelBase()
      78             : {
      79        8496 : }
      80             : 
      81        4248 : void SAL_CALL SidebarPanelBase::disposing()
      82             :     throw (css::uno::RuntimeException)
      83             : {
      84        4248 :     mpControl.disposeAndClear();
      85             : 
      86        4248 :     if (mxFrame.is())
      87             :     {
      88             :         css::uno::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
      89             :             css::ui::ContextChangeEventMultiplexer::get(
      90        4248 :                 ::comphelper::getProcessComponentContext()));
      91        4248 :         if (xMultiplexer.is())
      92        4248 :             xMultiplexer->removeAllContextChangeEventListeners(this);
      93        4248 :         mxFrame = NULL;
      94             :     }
      95        4248 : }
      96             : 
      97             : // XContextChangeEventListener
      98        7789 : void SAL_CALL SidebarPanelBase::notifyContextChangeEvent (
      99             :     const ui::ContextChangeEventObject& rEvent)
     100             :     throw (css::uno::RuntimeException, std::exception)
     101             : {
     102             :     IContextChangeReceiver* pContextChangeReceiver
     103        7789 :         = dynamic_cast<IContextChangeReceiver*>(mpControl.get());
     104        7789 :     if (pContextChangeReceiver != NULL)
     105             :     {
     106             :         const EnumContext aContext(
     107             :             EnumContext::GetApplicationEnum(rEvent.ApplicationName),
     108        1356 :             EnumContext::GetContextEnum(rEvent.ContextName));
     109        1356 :         pContextChangeReceiver->HandleContextChange(aContext);
     110             :     }
     111        7789 : }
     112             : 
     113           1 : void SAL_CALL SidebarPanelBase::disposing (
     114             :     const css::lang::EventObject& rEvent)
     115             :     throw (css::uno::RuntimeException, std::exception)
     116             : {
     117             :     (void)rEvent;
     118             : 
     119           1 :     mxFrame = NULL;
     120           1 :     mpControl = NULL;
     121           1 : }
     122             : 
     123           0 : css::uno::Reference<css::frame::XFrame> SAL_CALL SidebarPanelBase::getFrame()
     124             :     throw(css::uno::RuntimeException, std::exception)
     125             : {
     126           0 :     return mxFrame;
     127             : }
     128             : 
     129           0 : ::rtl::OUString SAL_CALL SidebarPanelBase::getResourceURL()
     130             :     throw(css::uno::RuntimeException, std::exception)
     131             : {
     132           0 :     return msResourceURL;
     133             : }
     134             : 
     135           0 : sal_Int16 SAL_CALL SidebarPanelBase::getType()
     136             :     throw(css::uno::RuntimeException, std::exception)
     137             : {
     138           0 :     return ui::UIElementType::TOOLPANEL;
     139             : }
     140             : 
     141        7430 : Reference<XInterface> SAL_CALL SidebarPanelBase::getRealInterface()
     142             :     throw(css::uno::RuntimeException, std::exception)
     143             : {
     144        7430 :     return Reference<XInterface>(static_cast<XWeak*>(this));
     145             : }
     146             : 
     147           0 : Reference<accessibility::XAccessible> SAL_CALL SidebarPanelBase::createAccessible (
     148             :     const Reference<accessibility::XAccessible>& rxParentAccessible)
     149             :     throw(css::uno::RuntimeException, std::exception)
     150             : {
     151             :     (void)rxParentAccessible;
     152             : 
     153             :     // Not yet implemented.
     154           0 :     return NULL;
     155             : }
     156             : 
     157        3182 : Reference<awt::XWindow> SAL_CALL SidebarPanelBase::getWindow()
     158             :     throw(css::uno::RuntimeException, std::exception)
     159             : {
     160        3182 :     if (mpControl != nullptr)
     161             :         return Reference<awt::XWindow>(
     162        3182 :             mpControl->GetComponentInterface(),
     163        3182 :             UNO_QUERY);
     164             :     else
     165           0 :         return NULL;
     166             : }
     167             : 
     168        4636 : ui::LayoutSize SAL_CALL SidebarPanelBase::getHeightForWidth (const sal_Int32 nWidth)
     169             :     throw(css::uno::RuntimeException, std::exception)
     170             : {
     171        4636 :     if (maLayoutSize.Minimum >= 0)
     172        2144 :         return maLayoutSize;
     173             :     else
     174             :     {
     175        2492 :         ILayoutableWindow* pLayoutableWindow = dynamic_cast<ILayoutableWindow*>(mpControl.get());
     176             : 
     177        2492 :         if (isLayoutEnabled(mpControl))
     178             :         {
     179             :             // widget layout-based sidebar
     180        2428 :             Size aSize(mpControl->get_preferred_size());
     181        2428 :             return ui::LayoutSize(aSize.Height(), aSize.Height(), aSize.Height());
     182             :         }
     183          64 :         else if (pLayoutableWindow != NULL)
     184          64 :             return pLayoutableWindow->GetHeightForWidth(nWidth);
     185           0 :         else if (mpControl != nullptr)
     186             :         {
     187           0 :             const sal_Int32 nHeight (mpControl->GetSizePixel().Height());
     188           0 :             return ui::LayoutSize(nHeight,nHeight,nHeight);
     189             :         }
     190             :     }
     191             : 
     192           0 :     return ui::LayoutSize(0,0,0);
     193             : }
     194             : 
     195        4636 : sal_Int32 SAL_CALL SidebarPanelBase::getMinimalWidth () throw(css::uno::RuntimeException, std::exception)
     196             : {
     197        4636 :     if (isLayoutEnabled(mpControl))
     198             :     {
     199             :         // widget layout-based sidebar
     200        2428 :         Size aSize(mpControl->get_preferred_size());
     201        2428 :         return aSize.Width();
     202             :     }
     203        2208 :     return 0;
     204             : }
     205             : 
     206         648 : } } // end of namespace sfx2::sidebar
     207             : 
     208             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11