LCOV - code coverage report
Current view: top level - toolkit/source/controls - tkscrollbar.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 58 143 40.6 %
Date: 2015-06-13 12:38:46 Functions: 16 34 47.1 %
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 "toolkit/controls/tkscrollbar.hxx"
      21             : #include "toolkit/helper/property.hxx"
      22             : #include <com/sun/star/uno/XComponentContext.hpp>
      23             : #include <cppuhelper/typeprovider.hxx>
      24             : #include <cppuhelper/queryinterface.hxx>
      25             : 
      26             : #include <toolkit/awt/vclxwindows.hxx>
      27             : 
      28             : #include "helper/unopropertyarrayhelper.hxx"
      29             : 
      30             : namespace toolkit
      31             : {
      32             : 
      33             : 
      34             :     using namespace ::com::sun::star;
      35             : 
      36             : 
      37             :     //= UnoControlScrollBarModel
      38             : 
      39             : 
      40          11 :     UnoControlScrollBarModel::UnoControlScrollBarModel( const uno::Reference< uno::XComponentContext >& i_factory )
      41          11 :         :UnoControlModel( i_factory )
      42             :     {
      43          11 :         UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXScrollBar );
      44          11 :     }
      45             : 
      46             : 
      47           1 :     OUString UnoControlScrollBarModel::getServiceName( ) throw(::com::sun::star::uno::RuntimeException, std::exception)
      48             :     {
      49           1 :         return OUString::createFromAscii( szServiceName_UnoControlScrollBarModel );
      50             :     }
      51             : 
      52           5 :     OUString UnoControlScrollBarModel::getImplementationName()
      53             :         throw (css::uno::RuntimeException, std::exception)
      54             :     {
      55           5 :         return OUString("stardiv.Toolkit.UnoControlScrollBarModel");
      56             :     }
      57             : 
      58             :     css::uno::Sequence<OUString>
      59           9 :     UnoControlScrollBarModel::getSupportedServiceNames()
      60             :         throw (css::uno::RuntimeException, std::exception)
      61             :     {
      62           9 :         auto s(UnoControlModel::getSupportedServiceNames());
      63           9 :         s.realloc(s.getLength() + 2);
      64           9 :         s[s.getLength() - 2] = "com.sun.star.awt.UnoControlScrollBarModel";
      65           9 :         s[s.getLength() - 1] = "stardiv.vcl.controlmodel.ScrollBar";
      66           9 :         return s;
      67             :     }
      68             : 
      69         288 :     uno::Any UnoControlScrollBarModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
      70             :     {
      71         288 :         switch ( nPropId )
      72             :         {
      73             :         case BASEPROPERTY_LIVE_SCROLL:
      74          13 :             return uno::makeAny( false );
      75             :         case BASEPROPERTY_DEFAULTCONTROL:
      76          13 :             return uno::makeAny( OUString::createFromAscii( szServiceName_UnoControlScrollBar ) );
      77             : 
      78             :         default:
      79         262 :             return UnoControlModel::ImplGetDefaultValue( nPropId );
      80             :         }
      81             :     }
      82             : 
      83             : 
      84        1859 :     ::cppu::IPropertyArrayHelper& UnoControlScrollBarModel::getInfoHelper()
      85             :     {
      86             :         static UnoPropertyArrayHelper* pHelper = NULL;
      87        1859 :         if ( !pHelper )
      88             :         {
      89           3 :             uno::Sequence<sal_Int32>    aIDs = ImplGetPropertyIds();
      90           3 :             pHelper = new UnoPropertyArrayHelper( aIDs );
      91             :         }
      92        1859 :         return *pHelper;
      93             :     }
      94             : 
      95             : 
      96          30 :     uno::Reference< beans::XPropertySetInfo > UnoControlScrollBarModel::getPropertySetInfo(  ) throw(uno::RuntimeException, std::exception)
      97             :     {
      98          30 :         static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
      99          30 :         return xInfo;
     100             :     }
     101             : 
     102             : 
     103             : 
     104             :     //= UnoControlScrollBarModel
     105             : 
     106           2 :     UnoScrollBarControl::UnoScrollBarControl()
     107             :         :UnoControlBase()
     108           2 :         ,maAdjustmentListeners( *this )
     109             :     {
     110           2 :     }
     111             : 
     112           1 :     OUString UnoScrollBarControl::GetComponentServiceName()
     113             :     {
     114           1 :         return OUString("ScrollBar");
     115             :     }
     116             : 
     117             :     // ::com::sun::star::uno::XInterface
     118          35 :     uno::Any UnoScrollBarControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException, std::exception)
     119             :     {
     120             :         uno::Any aRet = ::cppu::queryInterface( rType,
     121             :                                             (static_cast< awt::XAdjustmentListener* >(this)),
     122          35 :                                             (static_cast< awt::XScrollBar* >(this)) );
     123          35 :         return (aRet.hasValue() ? aRet : UnoControlBase::queryAggregation( rType ));
     124             :     }
     125             : 
     126             :     // ::com::sun::star::lang::XTypeProvider
     127           0 :     IMPL_XTYPEPROVIDER_START( UnoScrollBarControl )
     128           0 :         cppu::UnoType<awt::XAdjustmentListener>::get(),
     129           0 :         cppu::UnoType<awt::XScrollBar>::get(),
     130             :         UnoControlBase::getTypes()
     131           0 :     IMPL_XTYPEPROVIDER_END
     132             : 
     133           2 :     void UnoScrollBarControl::dispose() throw(uno::RuntimeException, std::exception)
     134             :     {
     135           2 :         lang::EventObject aEvt;
     136           2 :         aEvt.Source = static_cast<cppu::OWeakObject*>(this);
     137           2 :         maAdjustmentListeners.disposeAndClear( aEvt );
     138           2 :         UnoControl::dispose();
     139           2 :     }
     140             : 
     141           2 :     void UnoScrollBarControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer >  & rParentPeer ) throw(uno::RuntimeException, std::exception)
     142             :     {
     143           2 :         UnoControl::createPeer( rxToolkit, rParentPeer );
     144             : 
     145           2 :         uno::Reference < awt::XScrollBar >  xScrollBar( getPeer(), uno::UNO_QUERY );
     146           2 :         xScrollBar->addAdjustmentListener( this );
     147           2 :     }
     148             : 
     149             :     // ::com::sun::star::awt::XAdjustmentListener
     150           0 :     void UnoScrollBarControl::adjustmentValueChanged( const ::com::sun::star::awt::AdjustmentEvent& rEvent ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     151             :     {
     152           0 :         switch ( rEvent.Type )
     153             :         {
     154             :             case ::com::sun::star::awt::AdjustmentType_ADJUST_LINE:
     155             :             case ::com::sun::star::awt::AdjustmentType_ADJUST_PAGE:
     156             :             case ::com::sun::star::awt::AdjustmentType_ADJUST_ABS:
     157             :             {
     158           0 :                 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
     159             : 
     160           0 :                 if ( xScrollBar.is() )
     161             :                 {
     162           0 :                     uno::Any aAny;
     163           0 :                     aAny <<= xScrollBar->getValue();
     164           0 :                     ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), aAny, false );
     165           0 :                 }
     166             :             }
     167           0 :             break;
     168             :             default:
     169             :             {
     170             :                 OSL_FAIL( "UnoScrollBarControl::adjustmentValueChanged - unknown Type" );
     171             : 
     172             :             }
     173             :         }
     174             : 
     175           0 :         if ( maAdjustmentListeners.getLength() )
     176           0 :             maAdjustmentListeners.adjustmentValueChanged( rEvent );
     177           0 :     }
     178             : 
     179             :     // ::com::sun::star::awt::XScrollBar
     180           0 :     void UnoScrollBarControl::addAdjustmentListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XAdjustmentListener > & l ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     181             :     {
     182           0 :         maAdjustmentListeners.addInterface( l );
     183           0 :     }
     184             : 
     185           0 :     void UnoScrollBarControl::removeAdjustmentListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XAdjustmentListener > & l ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     186             :     {
     187           0 :         maAdjustmentListeners.removeInterface( l );
     188           0 :     }
     189             : 
     190           0 :     void UnoScrollBarControl::setValue( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     191             :     {
     192           0 :         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), uno::makeAny( n ), true );
     193           0 :     }
     194             : 
     195           0 :     void UnoScrollBarControl::setValues( sal_Int32 nValue, sal_Int32 nVisible, sal_Int32 nMax ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     196             :     {
     197           0 :         uno::Any aAny;
     198           0 :         aAny <<= nValue;
     199           0 :         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), aAny, true );
     200           0 :         aAny <<= nVisible;
     201           0 :         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE ), aAny, true );
     202           0 :         aAny <<= nMax;
     203           0 :         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX ), aAny, true );
     204           0 :     }
     205             : 
     206           0 :     sal_Int32 UnoScrollBarControl::getValue() throw(::com::sun::star::uno::RuntimeException, std::exception)
     207             :     {
     208           0 :         sal_Int32 n = 0;
     209           0 :         if ( getPeer().is() )
     210             :         {
     211           0 :             uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
     212           0 :             n = xScrollBar->getValue();
     213             :         }
     214           0 :         return n;
     215             :     }
     216             : 
     217           0 :     void UnoScrollBarControl::setMaximum( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     218             :     {
     219           0 :         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX ), uno::makeAny( n ), true );
     220           0 :     }
     221             : 
     222           0 :     sal_Int32 UnoScrollBarControl::getMaximum() throw(::com::sun::star::uno::RuntimeException, std::exception)
     223             :     {
     224           0 :         sal_Int32 n = 0;
     225           0 :         if ( getPeer().is() )
     226             :         {
     227           0 :             uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
     228           0 :             n = xScrollBar->getMaximum();
     229             :         }
     230           0 :         return n;
     231             :     }
     232             : 
     233           0 :     void UnoScrollBarControl::setLineIncrement( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     234             :     {
     235           0 :         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LINEINCREMENT ), uno::makeAny( n ), true );
     236           0 :     }
     237             : 
     238           0 :     sal_Int32 UnoScrollBarControl::getLineIncrement() throw(::com::sun::star::uno::RuntimeException, std::exception)
     239             :     {
     240           0 :         sal_Int32 n = 0;
     241           0 :         if ( getPeer().is() )
     242             :         {
     243           0 :             uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
     244           0 :             n = xScrollBar->getLineIncrement();
     245             :         }
     246           0 :         return n;
     247             :     }
     248             : 
     249           0 :     void UnoScrollBarControl::setBlockIncrement( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     250             :     {
     251           0 :         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_BLOCKINCREMENT ), uno::makeAny( n ), true );
     252           0 :     }
     253             : 
     254           0 :     sal_Int32 UnoScrollBarControl::getBlockIncrement() throw(::com::sun::star::uno::RuntimeException, std::exception)
     255             :     {
     256           0 :         sal_Int32 n = 0;
     257           0 :         if ( getPeer().is() )
     258             :         {
     259           0 :             uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
     260           0 :             n = xScrollBar->getBlockIncrement();
     261             :         }
     262           0 :         return n;
     263             :     }
     264             : 
     265           0 :     void UnoScrollBarControl::setVisibleSize( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     266             :     {
     267           0 :         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE ), uno::makeAny( n ), true );
     268           0 :     }
     269             : 
     270           0 :     sal_Int32 UnoScrollBarControl::getVisibleSize() throw(::com::sun::star::uno::RuntimeException, std::exception)
     271             :     {
     272           0 :         sal_Int32 n = 0;
     273           0 :         if ( getPeer().is() )
     274             :         {
     275           0 :             uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
     276           0 :             n = xScrollBar->getVisibleSize();
     277             :         }
     278           0 :         return n;
     279             :     }
     280             : 
     281           0 :     void UnoScrollBarControl::setOrientation( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     282             :     {
     283           0 :         ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ORIENTATION ), uno::makeAny( n ), true );
     284           0 :     }
     285             : 
     286           0 :     sal_Int32 UnoScrollBarControl::getOrientation() throw(::com::sun::star::uno::RuntimeException, std::exception)
     287             :     {
     288           0 :         sal_Int32 n = 0;
     289           0 :         if ( getPeer().is() )
     290             :         {
     291           0 :             uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY );
     292           0 :             n = xScrollBar->getOrientation();
     293             :         }
     294           0 :         return n;
     295             :     }
     296             : 
     297           2 :     OUString UnoScrollBarControl::getImplementationName()
     298             :         throw (css::uno::RuntimeException, std::exception)
     299             :     {
     300           2 :         return OUString("stardiv.Toolkit.UnoScrollBarControl");
     301             :     }
     302             : 
     303           1 :     css::uno::Sequence<OUString> UnoScrollBarControl::getSupportedServiceNames()
     304             :         throw (css::uno::RuntimeException, std::exception)
     305             :     {
     306           1 :         auto s(UnoControlBase::getSupportedServiceNames());
     307           1 :         s.realloc(s.getLength() + 2);
     308           1 :         s[s.getLength() - 2] = "com.sun.star.awt.UnoControlScrollBar";
     309           1 :         s[s.getLength() - 1] = "stardiv.vcl.control.ScrollBar";
     310           1 :         return s;
     311             :     }
     312             : 
     313             : }  // namespace toolkit
     314             : 
     315             : 
     316             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     317          11 : stardiv_Toolkit_UnoControlScrollBarModel_get_implementation(
     318             :     css::uno::XComponentContext *context,
     319             :     css::uno::Sequence<css::uno::Any> const &)
     320             : {
     321          11 :     return cppu::acquire(new toolkit::UnoControlScrollBarModel(context));
     322             : }
     323             : 
     324             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     325           2 : stardiv_Toolkit_UnoScrollBarControl_get_implementation(
     326             :     css::uno::XComponentContext *,
     327             :     css::uno::Sequence<css::uno::Any> const &)
     328             : {
     329           2 :     return cppu::acquire(new toolkit::UnoScrollBarControl());
     330             : }
     331             : 
     332             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11