LCOV - code coverage report
Current view: top level - extensions/source/propctrlr - handlerhelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 78 0.0 %
Date: 2012-08-25 Functions: 0 9 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "handlerhelper.hxx"
      30                 :            : #include "propresid.hrc"
      31                 :            : #include "formresid.hrc"
      32                 :            : #include <comphelper/extract.hxx>
      33                 :            : #include "modulepcr.hxx"
      34                 :            : #include "enumrepresentation.hxx"
      35                 :            : #include "formmetadata.hxx"
      36                 :            : #include "pcrcomponentcontext.hxx"
      37                 :            : 
      38                 :            : #include "com/sun/star/inspection/StringRepresentation.hpp"
      39                 :            : #include <com/sun/star/beans/PropertyAttribute.hpp>
      40                 :            : #include <com/sun/star/uno/XComponentContext.hpp>
      41                 :            : #include <com/sun/star/util/XModifiable.hpp>
      42                 :            : #include <com/sun/star/awt/XWindow.hpp>
      43                 :            : #include <com/sun/star/inspection/LineDescriptor.hpp>
      44                 :            : #include <com/sun/star/inspection/PropertyControlType.hpp>
      45                 :            : #include <com/sun/star/inspection/XStringListControl.hpp>
      46                 :            : #include <com/sun/star/inspection/XNumericControl.hpp>
      47                 :            : #include <tools/debug.hxx>
      48                 :            : #include <tools/diagnose_ex.h>
      49                 :            : #include <tools/StringListResource.hxx>
      50                 :            : #include <toolkit/helper/vclunohelper.hxx>
      51                 :            : 
      52                 :            : #include <algorithm>
      53                 :            : 
      54                 :            : //........................................................................
      55                 :            : namespace pcr
      56                 :            : {
      57                 :            : //........................................................................
      58                 :            : 
      59                 :            :     using namespace ::com::sun::star::uno;
      60                 :            :     using namespace ::com::sun::star::lang;
      61                 :            :     using namespace ::com::sun::star::awt;
      62                 :            :     using namespace ::com::sun::star::util;
      63                 :            :     using namespace ::com::sun::star::beans;
      64                 :            :     using namespace ::com::sun::star::script;
      65                 :            :     using namespace ::com::sun::star::inspection;
      66                 :            : 
      67                 :            :     //====================================================================
      68                 :            :     //= PropertyHandlerHelper
      69                 :            :     //====================================================================
      70                 :            :     //--------------------------------------------------------------------
      71                 :          0 :     void PropertyHandlerHelper::describePropertyLine( const Property& _rProperty,
      72                 :            :         LineDescriptor& /* [out] */ _out_rDescriptor, const Reference< XPropertyControlFactory >& _rxControlFactory )
      73                 :            :     {
      74                 :            :         // display the pure property name - no L10N
      75                 :          0 :         _out_rDescriptor.DisplayName = _rProperty.Name;
      76                 :            : 
      77                 :            :         OSL_PRECOND( _rxControlFactory.is(), "PropertyHandlerHelper::describePropertyLine: no factory -> no control!" );
      78                 :          0 :         if ( !_rxControlFactory.is() )
      79                 :          0 :             return;
      80                 :            : 
      81                 :          0 :         sal_Bool bReadOnlyControl = requiresReadOnlyControl( _rProperty.Attributes );
      82                 :            : 
      83                 :            :         // special handling for booleans (this will become a list)
      84                 :          0 :         if ( _rProperty.Type.getTypeClass() == TypeClass_BOOLEAN )
      85                 :            :         {
      86                 :          0 :             ::std::vector< ::rtl::OUString > aListEntries;
      87                 :          0 :             tools::StringListResource aRes(PcrRes(RID_RSC_ENUM_YESNO),aListEntries);
      88                 :          0 :             _out_rDescriptor.Control = createListBoxControl( _rxControlFactory, aListEntries, bReadOnlyControl, sal_False );
      89                 :          0 :             return;
      90                 :            :         }
      91                 :            : 
      92                 :          0 :         sal_Int16 nControlType = PropertyControlType::TextField;
      93                 :          0 :         switch ( _rProperty.Type.getTypeClass() )
      94                 :            :         {
      95                 :            :         case TypeClass_BYTE:
      96                 :            :         case TypeClass_SHORT:
      97                 :            :         case TypeClass_UNSIGNED_SHORT:
      98                 :            :         case TypeClass_LONG:
      99                 :            :         case TypeClass_UNSIGNED_LONG:
     100                 :            :         case TypeClass_HYPER:
     101                 :            :         case TypeClass_UNSIGNED_HYPER:
     102                 :            :         case TypeClass_FLOAT:
     103                 :            :         case TypeClass_DOUBLE:
     104                 :          0 :             nControlType = PropertyControlType::NumericField;
     105                 :          0 :             break;
     106                 :            : 
     107                 :            :         case TypeClass_SEQUENCE:
     108                 :          0 :             nControlType = PropertyControlType::StringListField;
     109                 :          0 :             break;
     110                 :            : 
     111                 :            :         default:
     112                 :            :             OSL_FAIL( "PropertyHandlerHelper::describePropertyLine: don't know how to represent this at the UI!" );
     113                 :            :             // NO break!
     114                 :            : 
     115                 :            :         case TypeClass_STRING:
     116                 :          0 :             nControlType = PropertyControlType::TextField;
     117                 :          0 :             break;
     118                 :            :         }
     119                 :            : 
     120                 :            :         // create a control
     121                 :          0 :         _out_rDescriptor.Control = _rxControlFactory->createPropertyControl( nControlType, bReadOnlyControl );
     122                 :            :     }
     123                 :            : 
     124                 :            :     //--------------------------------------------------------------------
     125                 :            :     namespace
     126                 :            :     {
     127                 :          0 :         Reference< XPropertyControl > lcl_implCreateListLikeControl(
     128                 :            :                 const Reference< XPropertyControlFactory >& _rxControlFactory,
     129                 :            :                 const ::std::vector< ::rtl::OUString >& _rInitialListEntries,
     130                 :            :                 sal_Bool _bReadOnlyControl,
     131                 :            :                 sal_Bool _bSorted,
     132                 :            :                 sal_Bool _bTrueIfListBoxFalseIfComboBox
     133                 :            :             )
     134                 :            :         {
     135                 :            :             Reference< XStringListControl > xListControl(
     136                 :          0 :                 _rxControlFactory->createPropertyControl(
     137                 :            :                     _bTrueIfListBoxFalseIfComboBox ? PropertyControlType::ListBox : PropertyControlType::ComboBox, _bReadOnlyControl
     138                 :          0 :                 ),
     139                 :            :                 UNO_QUERY_THROW
     140                 :          0 :             );
     141                 :            : 
     142                 :          0 :             ::std::vector< ::rtl::OUString > aInitialEntries( _rInitialListEntries );
     143                 :          0 :             if ( _bSorted )
     144                 :          0 :                 ::std::sort( aInitialEntries.begin(), aInitialEntries.end() );
     145                 :            : 
     146                 :          0 :             for (   ::std::vector< ::rtl::OUString >::const_iterator loop = aInitialEntries.begin();
     147                 :          0 :                     loop != aInitialEntries.end();
     148                 :            :                     ++loop
     149                 :            :                 )
     150                 :          0 :                 xListControl->appendListEntry( *loop );
     151                 :          0 :             return xListControl.get();
     152                 :            :         }
     153                 :            :     }
     154                 :            : 
     155                 :            :     //--------------------------------------------------------------------
     156                 :          0 :     Reference< XPropertyControl > PropertyHandlerHelper::createListBoxControl( const Reference< XPropertyControlFactory >& _rxControlFactory,
     157                 :            :                 const ::std::vector< ::rtl::OUString >& _rInitialListEntries, sal_Bool _bReadOnlyControl, sal_Bool _bSorted )
     158                 :            :     {
     159                 :          0 :         return lcl_implCreateListLikeControl( _rxControlFactory, _rInitialListEntries, _bReadOnlyControl, _bSorted, sal_True );
     160                 :            :     }
     161                 :            : 
     162                 :            :     //--------------------------------------------------------------------
     163                 :          0 :     Reference< XPropertyControl > PropertyHandlerHelper::createComboBoxControl( const Reference< XPropertyControlFactory >& _rxControlFactory,
     164                 :            :                 const ::std::vector< ::rtl::OUString >& _rInitialListEntries, sal_Bool _bReadOnlyControl, sal_Bool _bSorted )
     165                 :            :     {
     166                 :          0 :         return lcl_implCreateListLikeControl( _rxControlFactory, _rInitialListEntries, _bReadOnlyControl, _bSorted, sal_False );
     167                 :            :     }
     168                 :            : 
     169                 :            :     //--------------------------------------------------------------------
     170                 :          0 :     Reference< XPropertyControl > PropertyHandlerHelper::createNumericControl( const Reference< XPropertyControlFactory >& _rxControlFactory,
     171                 :            :             sal_Int16 _nDigits, const Optional< double >& _rMinValue, const Optional< double >& _rMaxValue, sal_Bool _bReadOnlyControl )
     172                 :            :     {
     173                 :            :         Reference< XNumericControl > xNumericControl(
     174                 :          0 :             _rxControlFactory->createPropertyControl( PropertyControlType::NumericField, _bReadOnlyControl ),
     175                 :            :             UNO_QUERY_THROW
     176                 :          0 :         );
     177                 :            : 
     178                 :          0 :         xNumericControl->setDecimalDigits( _nDigits );
     179                 :          0 :         xNumericControl->setMinValue( _rMinValue );
     180                 :          0 :         xNumericControl->setMaxValue( _rMaxValue );
     181                 :            : 
     182                 :          0 :         return xNumericControl.get();
     183                 :            :     }
     184                 :            : 
     185                 :            :     //--------------------------------------------------------------------
     186                 :          0 :     Any PropertyHandlerHelper::convertToPropertyValue( const Reference< XComponentContext >& _rxContext,const Reference< XTypeConverter >& _rxTypeConverter,
     187                 :            :         const Property& _rProperty, const Any& _rControlValue )
     188                 :            :     {
     189                 :          0 :         Any aPropertyValue( _rControlValue );
     190                 :          0 :         if ( !aPropertyValue.hasValue() )
     191                 :            :             // NULL is converted to NULL
     192                 :          0 :             return aPropertyValue;
     193                 :            : 
     194                 :          0 :         if ( aPropertyValue.getValueType().equals( _rProperty.Type ) )
     195                 :            :             // nothing to do, type is already as desired
     196                 :          0 :             return aPropertyValue;
     197                 :            : 
     198                 :          0 :         if ( _rControlValue.getValueType().getTypeClass() == TypeClass_STRING )
     199                 :            :         {
     200                 :          0 :             ::rtl::OUString sControlValue;
     201                 :          0 :             _rControlValue >>= sControlValue;
     202                 :            : 
     203                 :          0 :             Reference< XStringRepresentation > xConversionHelper = StringRepresentation::create( _rxContext,_rxTypeConverter );
     204                 :          0 :             aPropertyValue = xConversionHelper->convertToPropertyValue( sControlValue, _rProperty.Type );
     205                 :            :         }
     206                 :            :         else
     207                 :            :         {
     208                 :            :             try
     209                 :            :             {
     210                 :          0 :                 if ( _rxTypeConverter.is() )
     211                 :          0 :                     aPropertyValue = _rxTypeConverter->convertTo( _rControlValue, _rProperty.Type );
     212                 :            :             }
     213                 :          0 :             catch( const Exception& )
     214                 :            :             {
     215                 :            :                 OSL_FAIL( "PropertyHandlerHelper::convertToPropertyValue: caught an exception while converting via TypeConverter!" );
     216                 :            :             }
     217                 :            :         }
     218                 :            : 
     219                 :          0 :         return aPropertyValue;
     220                 :            :     }
     221                 :            : 
     222                 :            :     //--------------------------------------------------------------------
     223                 :          0 :     Any PropertyHandlerHelper::convertToControlValue( const Reference< XComponentContext >& _rxContext,const Reference< XTypeConverter >& _rxTypeConverter,
     224                 :            :         const Any& _rPropertyValue, const Type& _rControlValueType )
     225                 :            :     {
     226                 :          0 :         Any aControlValue( _rPropertyValue );
     227                 :          0 :         if ( !aControlValue.hasValue() )
     228                 :            :             // NULL is converted to NULL
     229                 :          0 :             return aControlValue;
     230                 :            : 
     231                 :          0 :         if ( _rControlValueType.getTypeClass() == TypeClass_STRING )
     232                 :            :         {
     233                 :          0 :             Reference< XStringRepresentation > xConversionHelper = StringRepresentation::create( _rxContext,_rxTypeConverter );
     234                 :          0 :             aControlValue <<= xConversionHelper->convertToControlValue( _rPropertyValue );
     235                 :            :         }
     236                 :            :         else
     237                 :            :         {
     238                 :            :             try
     239                 :            :             {
     240                 :          0 :                 if ( _rxTypeConverter.is() )
     241                 :          0 :                     aControlValue = _rxTypeConverter->convertTo( _rPropertyValue, _rControlValueType );
     242                 :            :             }
     243                 :          0 :             catch( const Exception& )
     244                 :            :             {
     245                 :            :                 OSL_FAIL( "PropertyHandlerHelper::convertToControlValue: caught an exception while converting via TypeConverter!" );
     246                 :            :             }
     247                 :            :         }
     248                 :            : 
     249                 :          0 :         return aControlValue;
     250                 :            :     }
     251                 :            : 
     252                 :            :     //--------------------------------------------------------------------
     253                 :          0 :     void PropertyHandlerHelper::setContextDocumentModified( const ComponentContext& _rContext )
     254                 :            :     {
     255                 :            :         try
     256                 :            :         {
     257                 :          0 :             Reference< XModifiable > xDocumentModifiable( _rContext.getContextValueByAsciiName( "ContextDocument" ), UNO_QUERY_THROW );
     258                 :          0 :             xDocumentModifiable->setModified( sal_True );
     259                 :            :         }
     260                 :          0 :         catch( const Exception& )
     261                 :            :         {
     262                 :            :             DBG_UNHANDLED_EXCEPTION();
     263                 :            :         }
     264                 :          0 :     }
     265                 :            : 
     266                 :            :     //--------------------------------------------------------------------
     267                 :          0 :     Window* PropertyHandlerHelper::getDialogParentWindow( const ComponentContext& _rContext )
     268                 :            :     {
     269                 :          0 :         Window* pInspectorWindow = NULL;
     270                 :            :         try
     271                 :            :         {
     272                 :          0 :             Reference< XWindow > xInspectorWindow( _rContext.getContextValueByAsciiName( "DialogParentWindow" ), UNO_QUERY_THROW );
     273                 :          0 :             pInspectorWindow = VCLUnoHelper::GetWindow( xInspectorWindow );
     274                 :            :         }
     275                 :          0 :         catch( const Exception& )
     276                 :            :         {
     277                 :            :             DBG_UNHANDLED_EXCEPTION();
     278                 :            :         }
     279                 :          0 :         return pInspectorWindow;
     280                 :            :     }
     281                 :            : 
     282                 :            : //........................................................................
     283                 :            : } // namespace pcr
     284                 :            : //........................................................................
     285                 :            : 
     286                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10