LCOV - code coverage report
Current view: top level - toolkit/source/controls - unocontrolbase.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 104 120 86.7 %
Date: 2014-04-11 Functions: 22 24 91.7 %
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 <com/sun/star/awt/XLayoutConstrains.hpp>
      21             : #include <com/sun/star/awt/XTextLayoutConstrains.hpp>
      22             : 
      23             : #include <toolkit/controls/unocontrolbase.hxx>
      24             : #include <toolkit/helper/property.hxx>
      25             : #include <comphelper/processfactory.hxx>
      26             : 
      27             : #include <tools/debug.hxx>
      28             : 
      29             : using namespace com::sun::star;
      30             : 
      31             : 
      32             : //  class UnoControlBase
      33             : 
      34             : 
      35         333 : bool UnoControlBase::ImplHasProperty( sal_uInt16 nPropId )
      36             : {
      37         333 :     OUString aPropName( GetPropertyName( nPropId ) );
      38         333 :     return ImplHasProperty( aPropName );
      39             : }
      40             : 
      41         333 : bool UnoControlBase::ImplHasProperty( const OUString& aPropertyName )
      42             : {
      43         333 :     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >  xPSet( mxModel, ::com::sun::star::uno::UNO_QUERY );
      44         333 :     if ( !xPSet.is() )
      45         126 :         return false;
      46         414 :     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >  xInfo = xPSet->getPropertySetInfo();
      47         207 :     if ( !xInfo.is() )
      48           0 :         return false;
      49             : 
      50         540 :     return xInfo->hasPropertyByName( aPropertyName );
      51             : }
      52             : 
      53           8 : void UnoControlBase::ImplSetPropertyValues( const ::com::sun::star::uno::Sequence< OUString >& aPropertyNames, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aValues, bool bUpdateThis )
      54             : {
      55           8 :     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet > xMPS( mxModel, ::com::sun::star::uno::UNO_QUERY );
      56           8 :     if ( !mxModel.is() )
      57           8 :         return;
      58             : 
      59             :     DBG_ASSERT( xMPS.is(), "UnoControlBase::ImplSetPropertyValues: no multi property set interface!" );
      60           8 :     if ( xMPS.is() )
      61             :     {
      62           8 :         if ( !bUpdateThis )
      63           6 :             ImplLockPropertyChangeNotifications( aPropertyNames, true );
      64             : 
      65             :         try
      66             :         {
      67           8 :             xMPS->setPropertyValues( aPropertyNames, aValues );
      68             :         }
      69           0 :         catch( const ::com::sun::star::uno::Exception& )
      70             :         {
      71           0 :             if ( !bUpdateThis )
      72           0 :                 ImplLockPropertyChangeNotifications( aPropertyNames, false );
      73             :         }
      74           8 :         if ( !bUpdateThis )
      75           6 :             ImplLockPropertyChangeNotifications( aPropertyNames, false );
      76             :     }
      77             :     else
      78             :     {
      79           0 :         int dummy = 0;
      80             :         (void)dummy;
      81           8 :     }
      82             : }
      83             : 
      84         508 : void UnoControlBase::ImplSetPropertyValue( const OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue, bool bUpdateThis )
      85             : {
      86             :     // Model might be logged off already but an event still fires
      87         508 :     if ( mxModel.is() )
      88             :     {
      89         508 :         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >  xPSet( mxModel, ::com::sun::star::uno::UNO_QUERY );
      90         508 :         if ( !bUpdateThis )
      91         288 :             ImplLockPropertyChangeNotification( aPropertyName, true );
      92             : 
      93             :         try
      94             :         {
      95         508 :             xPSet->setPropertyValue( aPropertyName, aValue );
      96             :         }
      97           0 :         catch( const com::sun::star::uno::Exception& )
      98             :         {
      99           0 :             if ( !bUpdateThis )
     100           0 :                 ImplLockPropertyChangeNotification( aPropertyName, false );
     101           0 :             throw;
     102             :         }
     103         508 :         if ( !bUpdateThis )
     104         288 :             ImplLockPropertyChangeNotification( aPropertyName, false );
     105             :     }
     106         508 : }
     107             : 
     108         696 : ::com::sun::star::uno::Any UnoControlBase::ImplGetPropertyValue( const OUString& aPropertyName )
     109             : {
     110         696 :     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >  xPSet( mxModel, ::com::sun::star::uno::UNO_QUERY );
     111         696 :     if ( xPSet.is() )
     112         684 :         return xPSet->getPropertyValue( aPropertyName );
     113             :     else
     114          12 :         return ::com::sun::star::uno::Any();
     115             : }
     116             : 
     117         115 : template <typename T> T UnoControlBase::ImplGetPropertyValuePOD( sal_uInt16 nProp )
     118             : {
     119         115 :     T t(0);
     120         115 :     if ( mxModel.is() )
     121             :     {
     122         115 :         ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
     123         115 :         aVal >>= t;
     124             :     }
     125         115 :     return t;
     126             : }
     127             : 
     128         344 : template <typename T> T UnoControlBase::ImplGetPropertyValueClass( sal_uInt16 nProp )
     129             : {
     130         344 :     T t;
     131         344 :     if ( mxModel.is() )
     132             :     {
     133         344 :         ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
     134         344 :         aVal >>= t;
     135             :     }
     136         344 :     return t;
     137             : }
     138             : 
     139          50 : bool UnoControlBase::ImplGetPropertyValue_BOOL( sal_uInt16 nProp )
     140             : {
     141          50 :     return ImplGetPropertyValuePOD<sal_Bool>(nProp);
     142             : }
     143             : 
     144          33 : sal_Int16 UnoControlBase::ImplGetPropertyValue_INT16( sal_uInt16 nProp )
     145             : {
     146          33 :     return ImplGetPropertyValuePOD<sal_Int16>(nProp);
     147             : }
     148             : 
     149           0 : sal_Int32 UnoControlBase::ImplGetPropertyValue_INT32( sal_uInt16 nProp )
     150             : {
     151           0 :     return ImplGetPropertyValuePOD<sal_Int32>(nProp);
     152             : }
     153             : 
     154          32 : double UnoControlBase::ImplGetPropertyValue_DOUBLE( sal_uInt16 nProp )
     155             : {
     156          32 :     return ImplGetPropertyValuePOD<double>(nProp);
     157             : }
     158             : 
     159         320 : OUString UnoControlBase::ImplGetPropertyValue_UString( sal_uInt16 nProp )
     160             : {
     161         320 :     return ImplGetPropertyValueClass<OUString>(nProp);
     162             : }
     163             : 
     164          12 : util::Date UnoControlBase::ImplGetPropertyValue_Date( sal_uInt16 nProp )
     165             : {
     166          12 :     return ImplGetPropertyValueClass<util::Date>(nProp);
     167             : }
     168             : 
     169          12 : util::Time UnoControlBase::ImplGetPropertyValue_Time( sal_uInt16 nProp )
     170             : {
     171          12 :     return ImplGetPropertyValueClass<util::Time>(nProp);
     172             : }
     173             : 
     174          25 : ::com::sun::star::awt::Size UnoControlBase::Impl_getMinimumSize()
     175             : {
     176          25 :     ::com::sun::star::awt::Size aSz;
     177          25 :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >  xP = ImplGetCompatiblePeer( true );
     178             :     DBG_ASSERT( xP.is(), "Layout: No Peer!" );
     179          25 :     if ( xP.is() )
     180             :     {
     181          25 :         ::com::sun::star::uno::Reference< ::com::sun::star::awt::XLayoutConstrains >  xL( xP, ::com::sun::star::uno::UNO_QUERY );
     182          25 :         if ( xL.is() )
     183          25 :             aSz = xL->getMinimumSize();
     184             : 
     185          25 :         if ( !getPeer().is() || ( getPeer() != xP ) )
     186           0 :             xP->dispose();
     187             :     }
     188          25 :     return aSz;
     189             : }
     190             : 
     191          27 : ::com::sun::star::awt::Size UnoControlBase::Impl_getPreferredSize()
     192             : {
     193          27 :     ::com::sun::star::awt::Size aSz;
     194          27 :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >  xP = ImplGetCompatiblePeer( true );
     195             :     DBG_ASSERT( xP.is(), "Layout: No Peer!" );
     196          27 :     if ( xP.is() )
     197             :     {
     198          27 :         ::com::sun::star::uno::Reference< ::com::sun::star::awt::XLayoutConstrains >  xL( xP, ::com::sun::star::uno::UNO_QUERY );
     199          27 :         if ( xL.is() )
     200          27 :             aSz = xL->getPreferredSize();
     201             : 
     202          27 :         if ( !getPeer().is() || ( getPeer() != xP ) )
     203           0 :             xP->dispose();
     204             :     }
     205          27 :     return aSz;
     206             : }
     207             : 
     208          25 : ::com::sun::star::awt::Size UnoControlBase::Impl_calcAdjustedSize( const ::com::sun::star::awt::Size& rNewSize )
     209             : {
     210          25 :     ::com::sun::star::awt::Size aSz;
     211          25 :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >  xP = ImplGetCompatiblePeer( true );
     212             :     DBG_ASSERT( xP.is(), "Layout: No Peer!" );
     213          25 :     if ( xP.is() )
     214             :     {
     215          25 :         ::com::sun::star::uno::Reference< ::com::sun::star::awt::XLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY );
     216          25 :         if ( xL.is() )
     217          25 :             aSz = xL->calcAdjustedSize( rNewSize );
     218             : 
     219          25 :         if ( !getPeer().is() || ( getPeer() != xP ) )
     220           0 :             xP->dispose();
     221             :     }
     222          25 :     return aSz;
     223             : }
     224             : 
     225          16 : ::com::sun::star::awt::Size UnoControlBase::Impl_getMinimumSize( sal_Int16 nCols, sal_Int16 nLines )
     226             : {
     227          16 :     ::com::sun::star::awt::Size aSz;
     228          16 :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >  xP = ImplGetCompatiblePeer( true );
     229             :     DBG_ASSERT( xP.is(), "Layout: No Peer!" );
     230          16 :     if ( xP.is() )
     231             :     {
     232          16 :         ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextLayoutConstrains >  xL( xP, ::com::sun::star::uno::UNO_QUERY );
     233          16 :         if ( xL.is() )
     234          16 :             aSz = xL->getMinimumSize( nCols, nLines );
     235             : 
     236          16 :         if ( !getPeer().is() || ( getPeer() != xP ) )
     237           0 :             xP->dispose();
     238             :     }
     239          16 :     return aSz;
     240             : }
     241             : 
     242          15 : void UnoControlBase::Impl_getColumnsAndLines( sal_Int16& nCols, sal_Int16& nLines )
     243             : {
     244          15 :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >  xP = ImplGetCompatiblePeer( true );
     245             :     DBG_ASSERT( xP.is(), "Layout: No Peer!" );
     246          15 :     if ( xP.is() )
     247             :     {
     248          15 :         ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextLayoutConstrains >  xL( xP, ::com::sun::star::uno::UNO_QUERY );
     249          15 :         if ( xL.is() )
     250          15 :             xL->getColumnsAndLines( nCols, nLines );
     251             : 
     252          15 :         if ( !getPeer().is() || ( getPeer() != xP ) )
     253           0 :             xP->dispose();
     254          15 :     }
     255          15 : }
     256             : 
     257             : 
     258             : 
     259             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10