LCOV - code coverage report
Current view: top level - sfx2/source/sidebar - SidebarPanelBase.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 52 69 75.4 %
Date: 2014-11-03 Functions: 12 17 70.6 %
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             : 
      35             : namespace sfx2 { namespace sidebar {
      36             : 
      37        5922 : Reference<ui::XUIElement> SidebarPanelBase::Create (
      38             :     const ::rtl::OUString& rsResourceURL,
      39             :     const css::uno::Reference<css::frame::XFrame>& rxFrame,
      40             :     vcl::Window* pWindow,
      41             :     const css::ui::LayoutSize& rLayoutSize)
      42             : {
      43             :     Reference<ui::XUIElement> xUIElement (
      44             :         new SidebarPanelBase(
      45             :             rsResourceURL,
      46             :             rxFrame,
      47             :             pWindow,
      48        5922 :             rLayoutSize));
      49        5922 :     return xUIElement;
      50             : }
      51             : 
      52             : 
      53             : 
      54             : 
      55        5922 : SidebarPanelBase::SidebarPanelBase (
      56             :     const ::rtl::OUString& rsResourceURL,
      57             :     const css::uno::Reference<css::frame::XFrame>& rxFrame,
      58             :     vcl::Window* pWindow,
      59             :     const css::ui::LayoutSize& rLayoutSize)
      60             :     : SidebarPanelBaseInterfaceBase(m_aMutex),
      61             :       mxFrame(rxFrame),
      62             :       mpControl(pWindow),
      63             :       msResourceURL(rsResourceURL),
      64        5922 :       maLayoutSize(rLayoutSize)
      65             : {
      66        5922 :     if (mxFrame.is())
      67             :     {
      68             :         css::uno::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
      69             :             css::ui::ContextChangeEventMultiplexer::get(
      70        5922 :                 ::comphelper::getProcessComponentContext()));
      71        5922 :         if (xMultiplexer.is())
      72        5922 :             xMultiplexer->addContextChangeEventListener(this, mxFrame->getController());
      73             :     }
      74        5922 :     if (mpControl != NULL)
      75             :     {
      76        5922 :         mpControl->SetBackground(Theme::GetWallpaper(Theme::Paint_PanelBackground));
      77        5922 :         mpControl->Show();
      78             :     }
      79        5922 : }
      80             : 
      81             : 
      82             : 
      83             : 
      84       11844 : SidebarPanelBase::~SidebarPanelBase (void)
      85             : {
      86       11844 : }
      87             : 
      88             : 
      89             : 
      90             : 
      91        5922 : void SAL_CALL SidebarPanelBase::disposing (void)
      92             :     throw (css::uno::RuntimeException)
      93             : {
      94        5922 :     if (mpControl != NULL)
      95             :     {
      96        5922 :         delete mpControl;
      97        5922 :         mpControl = NULL;
      98             :     }
      99             : 
     100        5922 :     if (mxFrame.is())
     101             :     {
     102             :         css::uno::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
     103             :             css::ui::ContextChangeEventMultiplexer::get(
     104        5922 :                 ::comphelper::getProcessComponentContext()));
     105        5922 :         if (xMultiplexer.is())
     106        5922 :             xMultiplexer->removeAllContextChangeEventListeners(this);
     107        5922 :         mxFrame = NULL;
     108             :     }
     109        5922 : }
     110             : 
     111             : 
     112             : 
     113             : 
     114             : // XContextChangeEventListener
     115       10106 : void SAL_CALL SidebarPanelBase::notifyContextChangeEvent (
     116             :     const ui::ContextChangeEventObject& rEvent)
     117             :     throw (css::uno::RuntimeException, std::exception)
     118             : {
     119             :     IContextChangeReceiver* pContextChangeReceiver
     120       10106 :         = dynamic_cast<IContextChangeReceiver*>(mpControl);
     121       10106 :     if (pContextChangeReceiver != NULL)
     122             :     {
     123             :         const EnumContext aContext(
     124             :             EnumContext::GetApplicationEnum(rEvent.ApplicationName),
     125        1516 :             EnumContext::GetContextEnum(rEvent.ContextName));
     126        1516 :         pContextChangeReceiver->HandleContextChange(aContext);
     127             :     }
     128       10106 : }
     129             : 
     130             : 
     131             : 
     132             : 
     133           0 : void SAL_CALL SidebarPanelBase::disposing (
     134             :     const css::lang::EventObject& rEvent)
     135             :     throw (css::uno::RuntimeException, std::exception)
     136             : {
     137             :     (void)rEvent;
     138             : 
     139           0 :     mxFrame = NULL;
     140           0 :     mpControl = NULL;
     141           0 : }
     142             : 
     143             : 
     144             : 
     145             : 
     146           0 : css::uno::Reference<css::frame::XFrame> SAL_CALL SidebarPanelBase::getFrame (void)
     147             :     throw(css::uno::RuntimeException, std::exception)
     148             : {
     149           0 :     return mxFrame;
     150             : }
     151             : 
     152             : 
     153             : 
     154             : 
     155           0 : ::rtl::OUString SAL_CALL SidebarPanelBase::getResourceURL (void)
     156             :     throw(css::uno::RuntimeException, std::exception)
     157             : {
     158           0 :     return msResourceURL;
     159             : }
     160             : 
     161             : 
     162             : 
     163             : 
     164           0 : sal_Int16 SAL_CALL SidebarPanelBase::getType (void)
     165             :     throw(css::uno::RuntimeException, std::exception)
     166             : {
     167           0 :     return ui::UIElementType::TOOLPANEL;
     168             : }
     169             : 
     170             : 
     171             : 
     172             : 
     173       22178 : Reference<XInterface> SAL_CALL SidebarPanelBase::getRealInterface (void)
     174             :     throw(css::uno::RuntimeException, std::exception)
     175             : {
     176       22178 :     return Reference<XInterface>(static_cast<XWeak*>(this));
     177             : }
     178             : 
     179             : 
     180             : 
     181             : 
     182           0 : Reference<accessibility::XAccessible> SAL_CALL SidebarPanelBase::createAccessible (
     183             :     const Reference<accessibility::XAccessible>& rxParentAccessible)
     184             :     throw(css::uno::RuntimeException, std::exception)
     185             : {
     186             :     (void)rxParentAccessible;
     187             : 
     188             :     // Not yet implemented.
     189           0 :     return NULL;
     190             : }
     191             : 
     192             : 
     193             : 
     194             : 
     195       16256 : Reference<awt::XWindow> SAL_CALL SidebarPanelBase::getWindow (void)
     196             :     throw(css::uno::RuntimeException, std::exception)
     197             : {
     198       16256 :     if (mpControl != NULL)
     199             :         return Reference<awt::XWindow>(
     200       16256 :             mpControl->GetComponentInterface(),
     201       32512 :             UNO_QUERY);
     202             :     else
     203           0 :         return NULL;
     204             : }
     205             : 
     206             : 
     207             : 
     208             : 
     209       19219 : ui::LayoutSize SAL_CALL SidebarPanelBase::getHeightForWidth (const sal_Int32 nWidth)
     210             :     throw(css::uno::RuntimeException, std::exception)
     211             : {
     212       19219 :     if (maLayoutSize.Minimum >= 0)
     213       14813 :         return maLayoutSize;
     214             :     else
     215             :     {
     216        4406 :         ILayoutableWindow* pLayoutableWindow = dynamic_cast<ILayoutableWindow*>(mpControl);
     217             : 
     218        4406 :         if (isLayoutEnabled(mpControl))
     219             :         {
     220             :             // widget layout-based sidebar
     221        4258 :             Size aSize(mpControl->get_preferred_size());
     222        4258 :             return ui::LayoutSize(aSize.Height(), aSize.Height(), aSize.Height());
     223             :         }
     224         148 :         else if (pLayoutableWindow != NULL)
     225         148 :             return pLayoutableWindow->GetHeightForWidth(nWidth);
     226           0 :         else if (mpControl != NULL)
     227             :         {
     228           0 :             const sal_Int32 nHeight (mpControl->GetSizePixel().Height());
     229           0 :             return ui::LayoutSize(nHeight,nHeight,nHeight);
     230             :         }
     231             :     }
     232             : 
     233           0 :     return ui::LayoutSize(0,0,0);
     234             : }
     235             : 
     236       19219 : sal_Int32 SAL_CALL SidebarPanelBase::getMinimalWidth () throw(css::uno::RuntimeException, std::exception)
     237             : {
     238       19219 :     if (isLayoutEnabled(mpControl))
     239             :     {
     240             :         // widget layout-based sidebar
     241        4258 :         Size aSize(mpControl->get_preferred_size());
     242        4258 :         return aSize.Width();
     243             :     }
     244       14961 :     return 0;
     245             : }
     246             : 
     247         951 : } } // end of namespace sfx2::sidebar
     248             : 
     249             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10