LCOV - code coverage report
Current view: top level - framework/source/uielement - genericstatusbarcontroller.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 53 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 6 0.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             : 
      20             : #include <uielement/genericstatusbarcontroller.hxx>
      21             : #include <uielement/statusbarmerger.hxx>
      22             : 
      23             : #include <vcl/svapp.hxx>
      24             : #include <vcl/status.hxx>
      25             : #include <vcl/image.hxx>
      26             : #include <toolkit/helper/vclunohelper.hxx>
      27             : #include <toolkit/helper/convert.hxx>
      28             : 
      29             : #include <com/sun/star/ui/ItemStyle.hpp>
      30             : #include <com/sun/star/beans/XPropertySet.hpp>
      31             : #include <com/sun/star/awt/ImageDrawMode.hpp>
      32             : #include <com/sun/star/awt/XGraphics2.hpp>
      33             : #include <com/sun/star/graphic/GraphicType.hpp>
      34             : 
      35             : using ::rtl::OUString;
      36             : 
      37             : using namespace ::cppu;
      38             : using namespace ::com::sun::star;
      39             : using namespace ::com::sun::star::uno;
      40             : using namespace ::com::sun::star::lang;
      41             : using namespace ::com::sun::star::frame;
      42             : 
      43             : namespace framework
      44             : {
      45             : 
      46           0 : GenericStatusbarController::GenericStatusbarController(
      47             :     const Reference< XComponentContext >& rxContext,
      48             :     const Reference< XFrame >& rxFrame,
      49             :     const Reference< ui::XStatusbarItem >& rxItem,
      50             :     AddonStatusbarItemData *pItemData )
      51             :     : svt::StatusbarController( rxContext, rxFrame, OUString(), 0 )
      52             :     , m_bEnabled( false )
      53             :     , m_bOwnerDraw( false )
      54             :     , m_pItemData( pItemData )
      55           0 :     , m_xGraphic()
      56             : {
      57           0 :     m_xStatusbarItem = rxItem;
      58           0 :     if ( m_xStatusbarItem.is() )
      59             :     {
      60           0 :         m_aCommandURL = m_xStatusbarItem->getCommand();
      61           0 :         m_nID = m_xStatusbarItem->getItemId();
      62           0 :         m_bOwnerDraw = ( m_xStatusbarItem->getStyle() & ui::ItemStyle::OWNER_DRAW ) == ui::ItemStyle::OWNER_DRAW;
      63           0 :         if ( !m_bOwnerDraw && m_pItemData && m_pItemData->aLabel.getLength() )
      64           0 :             m_xStatusbarItem->setText( m_pItemData->aLabel );
      65             :     }
      66           0 : }
      67             : 
      68           0 : GenericStatusbarController::~GenericStatusbarController()
      69             : {
      70           0 : }
      71             : 
      72           0 : void SAL_CALL GenericStatusbarController::dispose()
      73             : throw ( RuntimeException, std::exception )
      74             : {
      75           0 :     svt::StatusbarController::dispose();
      76             : 
      77           0 :     SolarMutexGuard aGuard;
      78           0 :     m_pItemData = NULL;
      79           0 :     m_xGraphic.clear();
      80           0 :     m_xStatusbarItem.clear();
      81             : 
      82           0 : }
      83             : 
      84           0 : void SAL_CALL GenericStatusbarController::statusChanged(
      85             :     const FeatureStateEvent& rEvent)
      86             : throw ( RuntimeException, std::exception )
      87             : {
      88           0 :     SolarMutexGuard aGuard;
      89             : 
      90           0 :     if ( m_bDisposed || !m_xStatusbarItem.is() )
      91           0 :         return;
      92             : 
      93           0 :     m_bEnabled = rEvent.IsEnabled;
      94             : 
      95           0 :     rtl::OUString aStrValue;
      96           0 :     Reference< graphic::XGraphic > aGraphic;
      97             : 
      98           0 :     if ( rEvent.State >>= aStrValue )
      99             :     {
     100           0 :         if ( !m_bOwnerDraw )
     101           0 :             m_xStatusbarItem->setText( aStrValue );
     102             :         else
     103             :         {
     104           0 :             if ( aStrValue.getLength() )
     105             :             {
     106           0 :                 m_xStatusbarItem->setQuickHelpText( aStrValue );
     107             :             }
     108             :         }
     109             :     }
     110           0 :     else if ( ( rEvent.State >>= aGraphic ) && m_bOwnerDraw )
     111             :     {
     112           0 :         m_xGraphic = aGraphic;
     113             :     }
     114             : 
     115             :     // when the status is updated, and the controller is responsible for
     116             :     // painting the statusbar item content, we must trigger a repaint
     117           0 :     if ( m_bOwnerDraw && m_xStatusbarItem->getVisible() )
     118             :     {
     119           0 :         m_xStatusbarItem->repaint();
     120           0 :     }
     121             : }
     122             : 
     123           0 : void SAL_CALL GenericStatusbarController::paint(
     124             :     const Reference< awt::XGraphics >& xGraphics,
     125             :     const awt::Rectangle& rOutputRectangle,
     126             :     ::sal_Int32 /*nStyle*/ )
     127             : throw ( RuntimeException, std::exception )
     128             : {
     129             :     OSL_TRACE("framework::GenericStatusbarController::paint");
     130           0 :     SolarMutexGuard aGuard;
     131             : 
     132           0 :     const Reference< awt::XGraphics2 > xGraphics2(xGraphics, UNO_QUERY);
     133             : 
     134           0 :     if ( !m_xStatusbarItem.is() || !xGraphics2.is() )
     135           0 :         return;
     136             : 
     137           0 :     Reference< beans::XPropertySet > xGraphicProps( m_xGraphic, UNO_QUERY );
     138             : 
     139           0 :     if ( xGraphicProps.is() && m_xGraphic->getType() != graphic::GraphicType::EMPTY )
     140             :     {
     141           0 :         awt::Size aGraphicSize;
     142           0 :         xGraphicProps->getPropertyValue( OUString( "SizePixel" ) ) >>= aGraphicSize;
     143             :         OSL_ENSURE( aGraphicSize.Height > 0 && aGraphicSize.Width > 0, "Empty status bar graphic!" );
     144             : 
     145           0 :         sal_Int32 nOffset = m_xStatusbarItem->getOffset( );
     146           0 :         awt::Point aPos;
     147           0 :         aPos.X = ( rOutputRectangle.Width + nOffset ) / 2 - aGraphicSize.Width / 2;
     148           0 :         aPos.Y = rOutputRectangle.Height / 2 - aGraphicSize.Height / 2;
     149             : 
     150           0 :         xGraphics2->drawImage( rOutputRectangle.X + aPos.X,
     151             :                               rOutputRectangle.Y + aPos.Y,
     152             :                               aGraphicSize.Width,
     153             :                               aGraphicSize.Height,
     154             :                               m_bEnabled ? awt::ImageDrawMode::NONE : awt::ImageDrawMode::DISABLE,
     155           0 :                               m_xGraphic );
     156             :     }
     157             :     else
     158             :     {
     159           0 :         xGraphics2->clear( rOutputRectangle );
     160           0 :     }
     161             : }
     162             : 
     163             : }
     164             : 
     165             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11