LCOV - code coverage report
Current view: top level - extensions/source/propctrlr - editpropertyhandler.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 14 135 10.4 %
Date: 2015-06-13 12:38:46 Functions: 6 14 42.9 %
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 "editpropertyhandler.hxx"
      21             : #include "formstrings.hxx"
      22             : #include "formmetadata.hxx"
      23             : #include "pcrservices.hxx"
      24             : 
      25             : #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
      26             : 
      27             : #define TEXTTYPE_SINGLELINE     0
      28             : #define TEXTTYPE_MULTILINE      1
      29             : #define TEXTTYPE_RICHTEXT       2
      30             : 
      31             : 
      32           2 : extern "C" void SAL_CALL createRegistryInfo_EditPropertyHandler()
      33             : {
      34           2 :     ::pcr::EditPropertyHandler::registerImplementation();
      35           2 : }
      36             : 
      37             : 
      38             : namespace pcr
      39             : {
      40             : 
      41             : 
      42             :     using namespace ::com::sun::star::uno;
      43             :     using namespace ::com::sun::star::lang;
      44             :     using namespace ::com::sun::star::beans;
      45             :     using namespace ::com::sun::star::script;
      46             :     using namespace ::com::sun::star::frame;
      47             :     using namespace ::com::sun::star::inspection;
      48             : 
      49             : 
      50             :     //= EditPropertyHandler
      51             : 
      52             : 
      53           1 :     EditPropertyHandler::EditPropertyHandler( const Reference< XComponentContext >& _rxContext )
      54           1 :         :EditPropertyHandler_Base( _rxContext )
      55             :     {
      56           1 :     }
      57             : 
      58             : 
      59           2 :     EditPropertyHandler::~EditPropertyHandler( )
      60             :     {
      61           2 :     }
      62             : 
      63             : 
      64           3 :     OUString SAL_CALL EditPropertyHandler::getImplementationName_static(  ) throw (RuntimeException)
      65             :     {
      66           3 :         return OUString( "com.sun.star.comp.extensions.EditPropertyHandler" );
      67             :     }
      68             : 
      69             : 
      70           3 :     Sequence< OUString > SAL_CALL EditPropertyHandler::getSupportedServiceNames_static(  ) throw (RuntimeException)
      71             :     {
      72           3 :         Sequence< OUString > aSupported( 1 );
      73           3 :         aSupported[0] = "com.sun.star.form.inspection.EditPropertyHandler";
      74           3 :         return aSupported;
      75             :     }
      76             : 
      77             : 
      78           0 :     Any SAL_CALL EditPropertyHandler::getPropertyValue( const OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException, std::exception)
      79             :     {
      80           0 :         ::osl::MutexGuard aGuard( m_aMutex );
      81           0 :         PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
      82             : 
      83           0 :         Any aReturn;
      84             :         try
      85             :         {
      86           0 :             switch ( nPropId )
      87             :             {
      88             :             case PROPERTY_ID_SHOW_SCROLLBARS:
      89             :             {
      90           0 :                 bool bHasVScroll = false;
      91           0 :                 m_xComponent->getPropertyValue( PROPERTY_VSCROLL ) >>= bHasVScroll;
      92           0 :                 bool bHasHScroll = false;
      93           0 :                 m_xComponent->getPropertyValue( PROPERTY_HSCROLL ) >>= bHasHScroll;
      94             : 
      95           0 :                 aReturn <<= (sal_Int32)( ( bHasVScroll ? 2 : 0 ) + ( bHasHScroll ? 1 : 0 ) );
      96             :             }
      97           0 :             break;
      98             : 
      99             :             case PROPERTY_ID_TEXTTYPE:
     100             :             {
     101           0 :                 sal_Int32 nTextType = TEXTTYPE_SINGLELINE;
     102           0 :                 bool bRichText = false;
     103           0 :                 OSL_VERIFY( m_xComponent->getPropertyValue( PROPERTY_RICHTEXT ) >>= bRichText );
     104           0 :                 if ( bRichText )
     105           0 :                     nTextType = TEXTTYPE_RICHTEXT;
     106             :                 else
     107             :                 {
     108           0 :                     bool bMultiLine = false;
     109           0 :                     OSL_VERIFY( m_xComponent->getPropertyValue( PROPERTY_MULTILINE ) >>= bMultiLine );
     110           0 :                     if ( bMultiLine )
     111           0 :                         nTextType = TEXTTYPE_MULTILINE;
     112             :                     else
     113           0 :                         nTextType = TEXTTYPE_SINGLELINE;
     114             :                 }
     115           0 :                 aReturn <<= nTextType;
     116             :             }
     117           0 :             break;
     118             : 
     119             : 
     120             :             default:
     121             :                 OSL_FAIL( "EditPropertyHandler::getPropertyValue: cannot handle this property!" );
     122           0 :                 break;
     123             :             }
     124             :         }
     125           0 :         catch( const Exception& )
     126             :         {
     127             :             OSL_FAIL( "EditPropertyHandler::getPropertyValue: caught an exception!" );
     128             :         }
     129             : 
     130           0 :         return aReturn;
     131             :     }
     132             : 
     133             : 
     134           0 :     void SAL_CALL EditPropertyHandler::setPropertyValue( const OUString& _rPropertyName, const Any& _rValue ) throw (UnknownPropertyException, RuntimeException, std::exception)
     135             :     {
     136           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     137           0 :         PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
     138             : 
     139             :         try
     140             :         {
     141           0 :             switch ( nPropId )
     142             :             {
     143             :             case PROPERTY_ID_SHOW_SCROLLBARS:
     144             :             {
     145           0 :                 sal_Int32 nScrollbars = 0;
     146           0 :                 _rValue >>= nScrollbars;
     147             : 
     148           0 :                 bool bHasVScroll = 0 != ( nScrollbars & 2 );
     149           0 :                 bool bHasHScroll = 0 != ( nScrollbars & 1 );
     150             : 
     151           0 :                 m_xComponent->setPropertyValue( PROPERTY_VSCROLL, makeAny( bHasVScroll ) );
     152           0 :                 m_xComponent->setPropertyValue( PROPERTY_HSCROLL, makeAny( bHasHScroll ) );
     153             :             }
     154           0 :             break;
     155             : 
     156             :             case PROPERTY_ID_TEXTTYPE:
     157             :             {
     158           0 :                 bool bMultiLine = false;
     159           0 :                 bool bRichText = false;
     160           0 :                 sal_Int32 nTextType = TEXTTYPE_SINGLELINE;
     161           0 :                 OSL_VERIFY( _rValue >>= nTextType );
     162           0 :                 switch ( nTextType )
     163             :                 {
     164           0 :                 case TEXTTYPE_SINGLELINE: bMultiLine = bRichText = false; break;
     165           0 :                 case TEXTTYPE_MULTILINE:  bMultiLine = true; bRichText = false; break;
     166           0 :                 case TEXTTYPE_RICHTEXT:   bMultiLine = true; bRichText = true; break;
     167             :                 default:
     168             :                     OSL_FAIL( "EditPropertyHandler::setPropertyValue: invalid text type!" );
     169             :                 }
     170             : 
     171           0 :                 m_xComponent->setPropertyValue( PROPERTY_MULTILINE, makeAny( bMultiLine ) );
     172           0 :                 m_xComponent->setPropertyValue( PROPERTY_RICHTEXT, makeAny( bRichText ) );
     173             :             }
     174           0 :             break;
     175             : 
     176             :             default:
     177             :                 OSL_FAIL( "EditPropertyHandler::setPropertyValue: cannot handle this id!" );
     178             :             }
     179             :         }
     180           0 :         catch( const Exception& )
     181             :         {
     182             :             OSL_FAIL( "EditPropertyHandler::setPropertyValue: caught an exception!" );
     183           0 :         }
     184           0 :     }
     185             : 
     186             : 
     187           0 :     bool EditPropertyHandler::implHaveBothScrollBarProperties() const
     188             :     {
     189             :         // have a "Scrollbars" property if the object supports both "HScroll" and "VScroll"
     190           0 :         Reference< XPropertySetInfo > xPSI;
     191           0 :         if ( m_xComponent.is() )
     192           0 :             xPSI = m_xComponent->getPropertySetInfo();
     193             : 
     194           0 :         return xPSI.is()
     195           0 :             && xPSI->hasPropertyByName( PROPERTY_HSCROLL )
     196           0 :             && xPSI->hasPropertyByName( PROPERTY_VSCROLL );
     197             :     }
     198             : 
     199             : 
     200           0 :     bool EditPropertyHandler::implHaveTextTypeProperty() const
     201             :     {
     202             :         // have a "Scrollbars" property if the object supports both "HScroll" and "VScroll"
     203           0 :         Reference< XPropertySetInfo > xPSI;
     204           0 :         if ( m_xComponent.is() )
     205           0 :             xPSI = m_xComponent->getPropertySetInfo();
     206             : 
     207           0 :         return xPSI.is()
     208           0 :             && xPSI->hasPropertyByName( PROPERTY_RICHTEXT )
     209           0 :             && xPSI->hasPropertyByName( PROPERTY_MULTILINE );
     210             :     }
     211             : 
     212             : 
     213           0 :     Sequence< Property > SAL_CALL EditPropertyHandler::doDescribeSupportedProperties() const
     214             :     {
     215           0 :         ::std::vector< Property > aProperties;
     216             : 
     217           0 :         if ( implHaveBothScrollBarProperties() )
     218           0 :             addInt32PropertyDescription( aProperties, PROPERTY_SHOW_SCROLLBARS );
     219             : 
     220           0 :         if ( implHaveTextTypeProperty() )
     221           0 :             addInt32PropertyDescription( aProperties, PROPERTY_TEXTTYPE );
     222             : 
     223           0 :         if ( aProperties.empty() )
     224           0 :             return Sequence< Property >();
     225           0 :         return Sequence< Property >( &(*aProperties.begin()), aProperties.size() );
     226             :     }
     227             : 
     228             : 
     229           0 :     Sequence< OUString > SAL_CALL EditPropertyHandler::getSupersededProperties( ) throw (RuntimeException, std::exception)
     230             :     {
     231           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     232           0 :         ::std::vector< OUString > aSuperseded;
     233           0 :         if ( implHaveBothScrollBarProperties() )
     234             :         {
     235           0 :             aSuperseded.push_back( static_cast<const OUString&>(PROPERTY_HSCROLL) );
     236           0 :             aSuperseded.push_back( static_cast<const OUString&>(PROPERTY_VSCROLL) );
     237             :         }
     238           0 :         if ( implHaveTextTypeProperty() )
     239             :         {
     240           0 :             aSuperseded.push_back(  static_cast<const OUString&>(PROPERTY_RICHTEXT) );
     241           0 :             aSuperseded.push_back(  static_cast<const OUString&>(PROPERTY_MULTILINE) );
     242             :         }
     243           0 :         if ( aSuperseded.empty() )
     244           0 :             return Sequence< OUString >();
     245           0 :         return Sequence< OUString >( &(*aSuperseded.begin()), aSuperseded.size() );
     246             :     }
     247             : 
     248             : 
     249           0 :     Sequence< OUString > SAL_CALL EditPropertyHandler::getActuatingProperties( ) throw (RuntimeException, std::exception)
     250             :     {
     251           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     252           0 :         ::std::vector< OUString > aInterestingActuatingProps;
     253           0 :         if ( implHaveTextTypeProperty() )
     254           0 :             aInterestingActuatingProps.push_back(  static_cast<const OUString&>(PROPERTY_TEXTTYPE) );
     255           0 :         aInterestingActuatingProps.push_back( static_cast<const OUString&>(PROPERTY_MULTILINE) );
     256           0 :         return Sequence< OUString >( &(*aInterestingActuatingProps.begin()), aInterestingActuatingProps.size() );
     257             :     }
     258             : 
     259             : 
     260           0 :     void SAL_CALL EditPropertyHandler::actuatingPropertyChanged( const OUString& _rActuatingPropertyName, const Any& _rNewValue, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& _rxInspectorUI, sal_Bool ) throw (NullPointerException, RuntimeException, std::exception)
     261             :     {
     262           0 :         if ( !_rxInspectorUI.is() )
     263           0 :             throw NullPointerException();
     264             : 
     265           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     266           0 :         PropertyId nActuatingPropId( impl_getPropertyId_throwRuntime( _rActuatingPropertyName ) );
     267           0 :         switch ( nActuatingPropId )
     268             :         {
     269             :         case PROPERTY_ID_TEXTTYPE:
     270             :         {
     271           0 :             sal_Int32 nTextType = TEXTTYPE_SINGLELINE;
     272           0 :             getPropertyValue( PROPERTY_TEXTTYPE ) >>= nTextType;
     273             : 
     274           0 :             if ( impl_isSupportedProperty_nothrow( PROPERTY_ID_WORDBREAK ) )
     275           0 :                 _rxInspectorUI->enablePropertyUI( PROPERTY_WORDBREAK,   nTextType == TEXTTYPE_RICHTEXT );
     276           0 :             _rxInspectorUI->enablePropertyUI( PROPERTY_MAXTEXTLEN,      nTextType != TEXTTYPE_RICHTEXT );
     277           0 :             _rxInspectorUI->enablePropertyUI( PROPERTY_ECHO_CHAR,       nTextType == TEXTTYPE_SINGLELINE );
     278           0 :             _rxInspectorUI->enablePropertyUI( PROPERTY_FONT,            nTextType != TEXTTYPE_RICHTEXT );
     279           0 :             _rxInspectorUI->enablePropertyUI( PROPERTY_ALIGN,           nTextType != TEXTTYPE_RICHTEXT );
     280           0 :             _rxInspectorUI->enablePropertyUI( PROPERTY_DEFAULT_TEXT,    nTextType != TEXTTYPE_RICHTEXT );
     281           0 :             _rxInspectorUI->enablePropertyUI( PROPERTY_SHOW_SCROLLBARS, nTextType != TEXTTYPE_SINGLELINE );
     282           0 :             _rxInspectorUI->enablePropertyUI( PROPERTY_LINEEND_FORMAT,  nTextType != TEXTTYPE_SINGLELINE );
     283           0 :             _rxInspectorUI->enablePropertyUI( PROPERTY_VERTICAL_ALIGN,  nTextType == TEXTTYPE_SINGLELINE );
     284             : 
     285           0 :             _rxInspectorUI->showCategory( OUString( "Data" ), nTextType != TEXTTYPE_RICHTEXT );
     286             :         }
     287           0 :         break;
     288             : 
     289             :         case PROPERTY_ID_MULTILINE:
     290             :         {
     291           0 :             bool bIsMultiline = false;
     292           0 :             _rNewValue >>= bIsMultiline;
     293             : 
     294           0 :             _rxInspectorUI->enablePropertyUI( PROPERTY_SHOW_SCROLLBARS, bIsMultiline );
     295           0 :             _rxInspectorUI->enablePropertyUI( PROPERTY_ECHO_CHAR, !bIsMultiline );
     296           0 :             _rxInspectorUI->enablePropertyUI( PROPERTY_LINEEND_FORMAT, bIsMultiline );
     297             :         }
     298           0 :         break;
     299             : 
     300             :         default:
     301             :             OSL_FAIL( "EditPropertyHandler::actuatingPropertyChanged: cannot handle this id!" );
     302           0 :         }
     303           0 :     }
     304             : 
     305             : 
     306             : }   // namespace pcr
     307             : 
     308             : 
     309             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11