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

Generated by: LCOV version 1.10