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

Generated by: LCOV version 1.10