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

Generated by: LCOV version 1.10