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

Generated by: LCOV version 1.10