LCOV - code coverage report
Current view: top level - extensions/source/propctrlr - submissionhandler.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 10 171 5.8 %
Date: 2014-11-03 Functions: 5 21 23.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 <sal/config.h>
      21             : 
      22             : #include "pcrservices.hxx"
      23             : #include "submissionhandler.hxx"
      24             : #include "formmetadata.hxx"
      25             : #include "formstrings.hxx"
      26             : #include "handlerhelper.hxx"
      27             : 
      28             : #include <com/sun/star/form/FormButtonType.hpp>
      29             : #include <com/sun/star/container/XNamed.hpp>
      30             : #include <com/sun/star/container/XIndexAccess.hpp>
      31             : #include <com/sun/star/form/submission/XSubmissionSupplier.hpp>
      32             : #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
      33             : #include <tools/debug.hxx>
      34             : #include <rtl/ustrbuf.hxx>
      35             : 
      36             : 
      37           4 : extern "C" void SAL_CALL createRegistryInfo_SubmissionPropertyHandler()
      38             : {
      39           4 :     ::pcr::SubmissionPropertyHandler::registerImplementation();
      40           4 : }
      41             : 
      42             : 
      43             : namespace pcr
      44             : {
      45             : 
      46             : 
      47             :     using namespace ::comphelper;
      48             :     using namespace ::com::sun::star;
      49             :     using namespace ::com::sun::star::uno;
      50             :     using namespace ::com::sun::star::lang;
      51             :     using namespace ::com::sun::star::beans;
      52             :     using namespace ::com::sun::star::script;
      53             :     using namespace ::com::sun::star::form;
      54             :     using namespace ::com::sun::star::xforms;
      55             :     using namespace ::com::sun::star::container;
      56             :     using namespace ::com::sun::star::inspection;
      57             : 
      58             : 
      59             :     //= SubmissionHelper
      60             : 
      61             : 
      62           0 :     SubmissionHelper::SubmissionHelper( ::osl::Mutex& _rMutex, const Reference< XPropertySet >& _rxIntrospectee, const Reference< frame::XModel >& _rxContextDocument )
      63           0 :         :EFormsHelper( _rMutex, _rxIntrospectee, _rxContextDocument )
      64             :     {
      65             :         OSL_ENSURE( canTriggerSubmissions( _rxIntrospectee, _rxContextDocument ),
      66             :             "SubmissionHelper::SubmissionHelper: you should not have instantiated me!" );
      67           0 :     }
      68             : 
      69             : 
      70           0 :     bool SubmissionHelper::canTriggerSubmissions( const Reference< XPropertySet >& _rxControlModel,
      71             :         const Reference< frame::XModel >& _rxContextDocument )
      72             :     {
      73           0 :         if ( !EFormsHelper::isEForm( _rxContextDocument ) )
      74           0 :             return false;
      75             : 
      76             :         try
      77             :         {
      78           0 :             Reference< submission::XSubmissionSupplier > xSubmissionSupp( _rxControlModel, UNO_QUERY );
      79           0 :             if ( xSubmissionSupp.is() )
      80           0 :                 return true;
      81             :         }
      82           0 :         catch( const Exception& )
      83             :         {
      84             :             OSL_FAIL( "SubmissionHelper::canTriggerSubmissions: caught an exception!" );
      85             :         }
      86           0 :         return false;
      87             :     }
      88             : 
      89             : 
      90             :     //= SubmissionPropertyHandler
      91             : 
      92             : 
      93           0 :     SubmissionPropertyHandler::SubmissionPropertyHandler( const Reference< XComponentContext >& _rxContext )
      94             :         :EditPropertyHandler_Base( _rxContext )
      95             :         ,OPropertyChangeListener( m_aMutex )
      96           0 :         ,m_pPropChangeMultiplexer( NULL )
      97             :     {
      98           0 :     }
      99             : 
     100             : 
     101           0 :     SubmissionPropertyHandler::~SubmissionPropertyHandler( )
     102             :     {
     103           0 :         disposeAdapter();
     104           0 :     }
     105             : 
     106             : 
     107           4 :     OUString SAL_CALL SubmissionPropertyHandler::getImplementationName_static(  ) throw (RuntimeException)
     108             :     {
     109           4 :         return OUString( "com.sun.star.comp.extensions.SubmissionPropertyHandler" );
     110             :     }
     111             : 
     112             : 
     113           4 :     Sequence< OUString > SAL_CALL SubmissionPropertyHandler::getSupportedServiceNames_static(  ) throw (RuntimeException)
     114             :     {
     115           4 :         Sequence< OUString > aSupported( 1 );
     116           4 :         aSupported[0] = "com.sun.star.form.inspection.SubmissionPropertyHandler";
     117           4 :         return aSupported;
     118             :     }
     119             : 
     120             : 
     121           0 :     Any SAL_CALL SubmissionPropertyHandler::getPropertyValue( const OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException, std::exception)
     122             :     {
     123           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     124           0 :         PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
     125             : 
     126             :         OSL_ENSURE( m_pHelper.get(), "SubmissionPropertyHandler::getPropertyValue: inconsistency!" );
     127             :             // if we survived impl_getPropertyId_throwUnknownProperty, we should have a helper, since no helper implies no properties
     128             : 
     129           0 :         Any aReturn;
     130             :         try
     131             :         {
     132           0 :             switch ( nPropId )
     133             :             {
     134             :             case PROPERTY_ID_SUBMISSION_ID:
     135             :             {
     136           0 :                 Reference< submission::XSubmissionSupplier > xSubmissionSupp( m_xComponent, UNO_QUERY );
     137             :                 OSL_ENSURE( xSubmissionSupp.is(), "SubmissionPropertyHandler::getPropertyValue: this should never happen ..." );
     138             :                     // this handler is not intended for components which are no XSubmissionSupplier
     139           0 :                 Reference< submission::XSubmission > xSubmission;
     140           0 :                 if ( xSubmissionSupp.is() )
     141           0 :                     xSubmission = xSubmissionSupp->getSubmission( );
     142           0 :                 aReturn <<= xSubmission;
     143             :             }
     144           0 :             break;
     145             : 
     146             :             case PROPERTY_ID_XFORMS_BUTTONTYPE:
     147             :             {
     148           0 :                 FormButtonType eType = FormButtonType_PUSH;
     149           0 :                 OSL_VERIFY( m_xComponent->getPropertyValue( PROPERTY_BUTTONTYPE ) >>= eType );
     150           0 :                 if ( ( eType != FormButtonType_PUSH ) && ( eType != FormButtonType_SUBMIT ) )
     151           0 :                     eType = FormButtonType_PUSH;
     152           0 :                 aReturn <<= eType;
     153             :             }
     154           0 :             break;
     155             : 
     156             :             default:
     157             :                 OSL_FAIL( "SubmissionPropertyHandler::getPropertyValue: cannot handle this property!" );
     158           0 :                 break;
     159             :             }
     160             :         }
     161           0 :         catch( const Exception& )
     162             :         {
     163             :             OSL_FAIL( "SubmissionPropertyHandler::getPropertyValue: caught an exception!" );
     164             :         }
     165             : 
     166           0 :         return aReturn;
     167             :     }
     168             : 
     169             : 
     170           0 :     void SAL_CALL SubmissionPropertyHandler::setPropertyValue( const OUString& _rPropertyName, const Any& _rValue ) throw (UnknownPropertyException, RuntimeException, std::exception)
     171             :     {
     172           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     173           0 :         PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
     174             : 
     175             :         OSL_ENSURE( m_pHelper.get(), "SubmissionPropertyHandler::setPropertyValue: inconsistency!" );
     176             :             // if we survived impl_getPropertyId_throwUnknownProperty, we should have a helper, since no helper implies no properties
     177             : 
     178             :         try
     179             :         {
     180           0 :             switch ( nPropId )
     181             :             {
     182             :             case PROPERTY_ID_SUBMISSION_ID:
     183             :             {
     184           0 :                 Reference< submission::XSubmission > xSubmission;
     185           0 :                 OSL_VERIFY( _rValue >>= xSubmission );
     186             : 
     187           0 :                 Reference< submission::XSubmissionSupplier > xSubmissionSupp( m_xComponent, UNO_QUERY );
     188             :                 OSL_ENSURE( xSubmissionSupp.is(), "SubmissionPropertyHandler::setPropertyValue: this should never happen ..." );
     189             :                     // this handler is not intended for components which are no XSubmissionSupplier
     190           0 :                 if ( xSubmissionSupp.is() )
     191             :                 {
     192           0 :                     xSubmissionSupp->setSubmission( xSubmission );
     193           0 :                     impl_setContextDocumentModified_nothrow();
     194           0 :                 }
     195             :             }
     196           0 :             break;
     197             : 
     198             :             case PROPERTY_ID_XFORMS_BUTTONTYPE:
     199           0 :                 m_xComponent->setPropertyValue( PROPERTY_BUTTONTYPE, _rValue );
     200           0 :                 break;
     201             : 
     202             :             default:
     203             :                 OSL_FAIL( "SubmissionPropertyHandler::setPropertyValue: cannot handle this id!" );
     204             :             }
     205             :         }
     206           0 :         catch( const Exception& )
     207             :         {
     208             :             OSL_FAIL( "SubmissionPropertyHandler::setPropertyValue: caught an exception!" );
     209           0 :         }
     210           0 :     }
     211             : 
     212             : 
     213           0 :     Sequence< OUString > SAL_CALL SubmissionPropertyHandler::getActuatingProperties( ) throw (RuntimeException, std::exception)
     214             :     {
     215           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     216           0 :         if ( !m_pHelper.get() )
     217           0 :             return Sequence< OUString >();
     218             : 
     219           0 :         Sequence< OUString > aReturn( 1 );
     220           0 :         aReturn[ 0 ] = PROPERTY_XFORMS_BUTTONTYPE;
     221           0 :         return aReturn;
     222             :     }
     223             : 
     224             : 
     225           0 :     Sequence< OUString > SAL_CALL SubmissionPropertyHandler::getSupersededProperties( ) throw (RuntimeException, std::exception)
     226             :     {
     227           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     228           0 :         if ( !m_pHelper.get() )
     229           0 :             return Sequence< OUString >();
     230             : 
     231           0 :         Sequence< OUString > aReturn( 3 );
     232           0 :         aReturn[ 0 ] = PROPERTY_TARGET_URL;
     233           0 :         aReturn[ 1 ] = PROPERTY_TARGET_FRAME;
     234           0 :         aReturn[ 2 ] = PROPERTY_BUTTONTYPE;
     235           0 :         return aReturn;
     236             :     }
     237             : 
     238             : 
     239           0 :     void SubmissionPropertyHandler::onNewComponent()
     240             :     {
     241           0 :         if ( m_pPropChangeMultiplexer )
     242             :         {
     243           0 :             m_pPropChangeMultiplexer->dispose();
     244           0 :             m_pPropChangeMultiplexer->release();
     245           0 :             m_pPropChangeMultiplexer = NULL;
     246             :         }
     247             : 
     248           0 :         EditPropertyHandler_Base::onNewComponent();
     249             : 
     250           0 :         Reference< frame::XModel > xDocument( impl_getContextDocument_nothrow() );
     251             :         DBG_ASSERT( xDocument.is(), "SubmissionPropertyHandler::onNewComponent: no document!" );
     252             : 
     253           0 :         m_pHelper.reset();
     254             : 
     255           0 :         if ( SubmissionHelper::canTriggerSubmissions( m_xComponent, xDocument ) )
     256             :         {
     257           0 :             m_pHelper.reset( new SubmissionHelper( m_aMutex, m_xComponent, xDocument ) );
     258             : 
     259           0 :             m_pPropChangeMultiplexer = new OPropertyChangeMultiplexer( this, m_xComponent );
     260           0 :             m_pPropChangeMultiplexer->acquire();
     261           0 :             m_pPropChangeMultiplexer->addProperty( PROPERTY_BUTTONTYPE );
     262           0 :         }
     263           0 :     }
     264             : 
     265             : 
     266           0 :     Sequence< Property > SAL_CALL SubmissionPropertyHandler::doDescribeSupportedProperties() const
     267             :     {
     268           0 :         ::std::vector< Property > aProperties;
     269           0 :         if ( m_pHelper.get() )
     270             :         {
     271           0 :             implAddPropertyDescription( aProperties, PROPERTY_SUBMISSION_ID, cppu::UnoType<submission::XSubmission>::get() );
     272           0 :             implAddPropertyDescription( aProperties, PROPERTY_XFORMS_BUTTONTYPE, ::cppu::UnoType<FormButtonType>::get() );
     273             :         }
     274           0 :         if ( aProperties.empty() )
     275           0 :             return Sequence< Property >();
     276           0 :         return Sequence< Property >( &(*aProperties.begin()), aProperties.size() );
     277             :     }
     278             : 
     279             : 
     280           0 :     LineDescriptor SAL_CALL SubmissionPropertyHandler::describePropertyLine( const OUString& _rPropertyName,
     281             :         const Reference< XPropertyControlFactory >& _rxControlFactory )
     282             :         throw (UnknownPropertyException, NullPointerException, RuntimeException, std::exception)
     283             :     {
     284           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     285           0 :         if ( !_rxControlFactory.is() )
     286           0 :             throw NullPointerException();
     287           0 :         if ( !m_pHelper.get() )
     288           0 :             RuntimeException();
     289             : 
     290           0 :         ::std::vector< OUString > aListEntries;
     291           0 :         PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
     292           0 :         switch ( nPropId )
     293             :         {
     294             :         case PROPERTY_ID_SUBMISSION_ID:
     295           0 :             const_cast< SubmissionHelper* >( m_pHelper.get() )->getAllElementUINames( EFormsHelper::Submission, aListEntries, false );
     296           0 :             break;
     297             : 
     298             :         case PROPERTY_ID_XFORMS_BUTTONTYPE:
     299             :         {
     300             :             // available options are nearly the same as for the "normal" button type, but only the
     301             :             // first two options
     302           0 :             aListEntries = m_pInfoService->getPropertyEnumRepresentations( PROPERTY_ID_BUTTONTYPE );
     303           0 :             aListEntries.resize( 2 );
     304             :         }
     305           0 :         break;
     306             : 
     307             :         default:
     308             :             OSL_FAIL( "SubmissionPropertyHandler::describePropertyLine: cannot handle this id!" );
     309           0 :             return LineDescriptor();
     310             :         }
     311             : 
     312           0 :         LineDescriptor aDescriptor;
     313           0 :         aDescriptor.Control = PropertyHandlerHelper::createListBoxControl( _rxControlFactory, aListEntries, false, true );
     314           0 :         aDescriptor.DisplayName = m_pInfoService->getPropertyTranslation( nPropId );
     315           0 :         aDescriptor.Category = "General";
     316           0 :         aDescriptor.HelpURL = HelpIdUrl::getHelpURL( m_pInfoService->getPropertyHelpId( nPropId ) );
     317           0 :         return aDescriptor;
     318             :     }
     319             : 
     320             : 
     321           0 :     void SAL_CALL SubmissionPropertyHandler::actuatingPropertyChanged( const OUString& _rActuatingPropertyName, const Any& _rNewValue, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& _rxInspectorUI, sal_Bool ) throw (NullPointerException, RuntimeException, std::exception)
     322             :     {
     323           0 :         if ( !_rxInspectorUI.is() )
     324           0 :             throw NullPointerException();
     325             : 
     326           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     327           0 :         PropertyId nActuatingPropId( impl_getPropertyId_throwRuntime( _rActuatingPropertyName ) );
     328             :         OSL_PRECOND( m_pHelper.get(), "SubmissionPropertyHandler::actuatingPropertyChanged: inconsistentcy!" );
     329             :             // if we survived impl_getPropertyId_throwRuntime, we should have a helper, since no helper implies no properties
     330             : 
     331           0 :         switch ( nActuatingPropId )
     332             :         {
     333             :         case PROPERTY_ID_XFORMS_BUTTONTYPE:
     334             :         {
     335           0 :             FormButtonType eType = FormButtonType_PUSH;
     336           0 :             OSL_VERIFY( _rNewValue >>= eType );
     337           0 :             _rxInspectorUI->enablePropertyUI( PROPERTY_SUBMISSION_ID, eType == FormButtonType_SUBMIT );
     338             :         }
     339           0 :         break;
     340             : 
     341             :         default:
     342             :             OSL_FAIL( "SubmissionPropertyHandler::actuatingPropertyChanged: cannot handle this id!" );
     343           0 :         }
     344           0 :     }
     345             : 
     346             : 
     347           0 :     Any SAL_CALL SubmissionPropertyHandler::convertToPropertyValue( const OUString& _rPropertyName, const Any& _rControlValue ) throw (UnknownPropertyException, RuntimeException, std::exception)
     348             :     {
     349           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     350           0 :         Any aPropertyValue;
     351             : 
     352             :         OSL_ENSURE( m_pHelper.get(), "SubmissionPropertyHandler::convertToPropertyValue: we have no SupportedProperties!" );
     353           0 :         if ( !m_pHelper.get() )
     354           0 :             return aPropertyValue;
     355             : 
     356           0 :         OUString sControlValue;
     357           0 :         OSL_VERIFY( _rControlValue >>= sControlValue );
     358             : 
     359           0 :         PropertyId nPropId( m_pInfoService->getPropertyId( _rPropertyName ) );
     360           0 :         switch ( nPropId )
     361             :         {
     362             :         case PROPERTY_ID_SUBMISSION_ID:
     363             :         {
     364           0 :             Reference< XSubmission > xSubmission( m_pHelper->getModelElementFromUIName( EFormsHelper::Submission, sControlValue ), UNO_QUERY );
     365           0 :             aPropertyValue <<= xSubmission;
     366             :         }
     367           0 :         break;
     368             : 
     369             :         case PROPERTY_ID_XFORMS_BUTTONTYPE:
     370             :         {
     371             :             ::rtl::Reference< IPropertyEnumRepresentation > aEnumConversion(
     372           0 :                 new DefaultEnumRepresentation( *m_pInfoService, ::cppu::UnoType<FormButtonType>::get(), PROPERTY_ID_BUTTONTYPE ) );
     373             :             // TODO/UNOize: make aEnumConversion a member?
     374           0 :             aEnumConversion->getValueFromDescription( sControlValue, aPropertyValue );
     375             :         }
     376           0 :         break;
     377             : 
     378             :         default:
     379             :             OSL_FAIL( "SubmissionPropertyHandler::convertToPropertyValue: cannot handle this id!" );
     380             :         }
     381             : 
     382           0 :         return aPropertyValue;
     383             :     }
     384             : 
     385             : 
     386           0 :     Any SAL_CALL SubmissionPropertyHandler::convertToControlValue( const OUString& _rPropertyName, const Any& _rPropertyValue, const Type& _rControlValueType ) throw (UnknownPropertyException, RuntimeException, std::exception)
     387             :     {
     388           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     389           0 :         Any aControlValue;
     390             : 
     391             :         OSL_ENSURE( m_pHelper.get(), "SubmissionPropertyHandler::convertToControlValue: we have no SupportedProperties!" );
     392           0 :         if ( !m_pHelper.get() )
     393           0 :             return aControlValue;
     394             : 
     395             :         OSL_ENSURE( _rControlValueType.getTypeClass() == TypeClass_STRING,
     396             :             "SubmissionPropertyHandler::convertToControlValue: all our controls should use strings for value exchange!" );
     397             :         (void)_rControlValueType;
     398             : 
     399           0 :         PropertyId nPropId( m_pInfoService->getPropertyId( _rPropertyName ) );
     400           0 :         switch ( nPropId )
     401             :         {
     402             :         case PROPERTY_ID_SUBMISSION_ID:
     403             :         {
     404           0 :             Reference< XPropertySet > xSubmission( _rPropertyValue, UNO_QUERY );
     405           0 :             if ( xSubmission.is() )
     406           0 :                 aControlValue <<= m_pHelper->getModelElementUIName( EFormsHelper::Submission, xSubmission );
     407             :         }
     408           0 :         break;
     409             : 
     410             :         case PROPERTY_ID_XFORMS_BUTTONTYPE:
     411             :         {
     412             :             ::rtl::Reference< IPropertyEnumRepresentation > aEnumConversion(
     413           0 :                 new DefaultEnumRepresentation( *m_pInfoService, _rPropertyValue.getValueType(), PROPERTY_ID_BUTTONTYPE ) );
     414             :             // TODO/UNOize: make aEnumConversion a member?
     415           0 :             aControlValue <<= aEnumConversion->getDescriptionForValue( _rPropertyValue );
     416             :         }
     417           0 :         break;
     418             : 
     419             :         default:
     420             :             OSL_FAIL( "SubmissionPropertyHandler::convertToControlValue: cannot handle this id!" );
     421             :         }
     422             : 
     423           0 :         return aControlValue;
     424             :     }
     425             : 
     426             : 
     427           0 :     void SubmissionPropertyHandler::_propertyChanged( const PropertyChangeEvent& _rEvent ) throw(RuntimeException)
     428             :     {
     429           0 :         if ( _rEvent.PropertyName == PROPERTY_BUTTONTYPE )
     430           0 :             firePropertyChange( PROPERTY_XFORMS_BUTTONTYPE, PROPERTY_ID_XFORMS_BUTTONTYPE, _rEvent.OldValue, _rEvent.NewValue );
     431           0 :     }
     432             : 
     433             : 
     434          12 : } // namespace pcr
     435             : 
     436             : 
     437             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10