LCOV - code coverage report
Current view: top level - libreoffice/extensions/source/propctrlr - usercontrol.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 147 0.0 %
Date: 2012-12-27 Functions: 0 27 0.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 "usercontrol.hxx"
      21             : 
      22             : #include <com/sun/star/inspection/PropertyControlType.hpp>
      23             : #include <svl/numuno.hxx>
      24             : #include <rtl/math.hxx>
      25             : #include <tools/debug.hxx>
      26             : #include <svl/zformat.hxx>
      27             : #include <connectivity/dbconversion.hxx>
      28             : #include <com/sun/star/util/Time.hpp>
      29             : #include "modulepcr.hxx"
      30             : #include "propresid.hrc"
      31             : 
      32             : //............................................................................
      33             : namespace pcr
      34             : {
      35             : //............................................................................
      36             : 
      37             :     /** === begin UNO using === **/
      38             :     using ::com::sun::star::uno::Any;
      39             :     using ::com::sun::star::uno::Type;
      40             :     using ::com::sun::star::beans::IllegalTypeException;
      41             :     using ::com::sun::star::uno::RuntimeException;
      42             :     /** === end UNO using === **/
      43             :     namespace PropertyControlType = ::com::sun::star::inspection::PropertyControlType;
      44             : 
      45             :     //==================================================================
      46             :     // NumberFormatSampleField
      47             :     //==================================================================
      48             :     //------------------------------------------------------------------
      49           0 :     long NumberFormatSampleField::PreNotify( NotifyEvent& rNEvt )
      50             :     {
      51             :         // want to handle two keys myself : Del/Backspace should empty the window (setting my prop to "standard" this way)
      52           0 :         if (EVENT_KEYINPUT == rNEvt.GetType())
      53             :         {
      54           0 :             sal_uInt16 nKey = rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
      55             : 
      56           0 :             if ((KEY_DELETE == nKey) || (KEY_BACKSPACE == nKey))
      57             :             {
      58           0 :                 SetText( String() );
      59           0 :                 if ( m_pHelper )
      60           0 :                     m_pHelper->ModifiedHdl( this );
      61           0 :                 return 1;
      62             :             }
      63             :         }
      64             : 
      65           0 :         return BaseClass::PreNotify( rNEvt );
      66             :     }
      67             : 
      68             :     //------------------------------------------------------------------
      69           0 :     void NumberFormatSampleField::SetFormatSupplier( const SvNumberFormatsSupplierObj* pSupplier )
      70             :     {
      71           0 :         if ( pSupplier )
      72             :         {
      73           0 :             TreatAsNumber( sal_True );
      74             : 
      75           0 :             SvNumberFormatter* pFormatter = pSupplier->GetNumberFormatter();
      76           0 :             SetFormatter( pFormatter, sal_True );
      77           0 :             SetValue( 1234.56789 );
      78             :         }
      79             :         else
      80             :         {
      81           0 :             TreatAsNumber( sal_False );
      82           0 :             SetFormatter( NULL, sal_True );
      83           0 :             SetText( String() );
      84             :         }
      85           0 :     }
      86             : 
      87             :     //==================================================================
      88             :     // OFormatSampleControl
      89             :     //==================================================================
      90             :     //------------------------------------------------------------------
      91           0 :     OFormatSampleControl::OFormatSampleControl( Window* pParent, WinBits nWinStyle )
      92           0 :         :OFormatSampleControl_Base( PropertyControlType::Unknown, pParent, nWinStyle )
      93             :     {
      94           0 :     }
      95             : 
      96             :     //------------------------------------------------------------------
      97           0 :     void SAL_CALL OFormatSampleControl::setValue( const Any& _rValue ) throw (IllegalTypeException, RuntimeException)
      98             :     {
      99           0 :         sal_Int32 nFormatKey = 0;
     100           0 :         if ( _rValue >>= nFormatKey )
     101             :         {
     102             :             // else set the new format key, the text will be reformatted
     103           0 :             getTypedControlWindow()->SetFormatKey( nFormatKey );
     104             : 
     105           0 :             SvNumberFormatter* pNF = getTypedControlWindow()->GetFormatter();
     106           0 :             const SvNumberformat* pEntry = pNF->GetEntry( nFormatKey );
     107             :             OSL_ENSURE( pEntry, "OFormatSampleControl::setValue: invalid format entry!" );
     108             : 
     109           0 :             const bool bIsTextFormat = ( pEntry && pEntry->IsTextFormat() );
     110           0 :             if ( bIsTextFormat )
     111           0 :                 getTypedControlWindow()->SetText( String( PcrRes( RID_STR_TEXT_FORMAT ) ) );
     112             :             else
     113           0 :                 getTypedControlWindow()->SetValue( pEntry ? getPreviewValue( *pEntry ) : 1234.56789 );
     114             :         }
     115             :         else
     116           0 :             getTypedControlWindow()->SetText( String() );
     117           0 :     }
     118             :     //------------------------------------------------------------------
     119           0 :     double OFormatSampleControl::getPreviewValue( const SvNumberformat& i_rEntry )
     120             :     {
     121           0 :         double nValue = 1234.56789;
     122           0 :         switch ( i_rEntry.GetType() & ~NUMBERFORMAT_DEFINED )
     123             :         {
     124             :             case NUMBERFORMAT_DATE:
     125             :                 {
     126           0 :                     Date aCurrentDate( Date::SYSTEM );
     127           0 :                     static ::com::sun::star::util::Date STANDARD_DB_DATE(30,12,1899);
     128           0 :                     nValue = ::dbtools::DBTypeConversion::toDouble(::dbtools::DBTypeConversion::toDate(static_cast<sal_Int32>(aCurrentDate.GetDate())),STANDARD_DB_DATE);
     129             :                 }
     130           0 :                 break;
     131             :             case NUMBERFORMAT_TIME:
     132             :             case NUMBERFORMAT_DATETIME:
     133             :                 {
     134           0 :                     Time aCurrentTime( Time::SYSTEM );
     135           0 :                     nValue = ::dbtools::DBTypeConversion::toDouble(::dbtools::DBTypeConversion::toTime(aCurrentTime.GetTime()));
     136             :                 }
     137           0 :                 break;
     138             :             default:
     139           0 :                 break;
     140             :         }
     141           0 :         return nValue;
     142             :     }
     143             : 
     144             :     //------------------------------------------------------------------
     145           0 :     double OFormatSampleControl::getPreviewValue(SvNumberFormatter* _pNF,sal_Int32 _nFormatKey)
     146             :     {
     147           0 :         const SvNumberformat* pEntry = _pNF->GetEntry(_nFormatKey);
     148             :         DBG_ASSERT( pEntry, "OFormattedNumericControl::SetFormatDescription: invalid format key!" );
     149           0 :         double nValue = 1234.56789;
     150           0 :         if ( pEntry )
     151           0 :             nValue = getPreviewValue( *pEntry );
     152           0 :         return nValue;
     153             :     }
     154             :     //------------------------------------------------------------------
     155           0 :     Any SAL_CALL OFormatSampleControl::getValue() throw (RuntimeException)
     156             :     {
     157           0 :         Any aPropValue;
     158           0 :         if ( getTypedControlWindow()->GetText().Len() )
     159           0 :             aPropValue <<= (sal_Int32)getTypedControlWindow()->GetFormatKey();
     160           0 :         return aPropValue;
     161             :     }
     162             : 
     163             :     //------------------------------------------------------------------
     164           0 :     Type SAL_CALL OFormatSampleControl::getValueType() throw (RuntimeException)
     165             :     {
     166           0 :         return ::getCppuType( static_cast< sal_Int32* >( NULL ) );
     167             :     }
     168             : 
     169             :     //==================================================================
     170             :     // class OFormattedNumericControl
     171             :     //==================================================================
     172             :     DBG_NAME(OFormattedNumericControl);
     173             :     //------------------------------------------------------------------
     174           0 :     OFormattedNumericControl::OFormattedNumericControl( Window* pParent, WinBits nWinStyle )
     175           0 :         :OFormattedNumericControl_Base( PropertyControlType::Unknown, pParent, nWinStyle )
     176             :     {
     177             :         DBG_CTOR(OFormattedNumericControl,NULL);
     178             : 
     179           0 :         getTypedControlWindow()->TreatAsNumber(sal_True);
     180             : 
     181           0 :         m_nLastDecimalDigits = getTypedControlWindow()->GetDecimalDigits();
     182           0 :     }
     183             : 
     184             :     //------------------------------------------------------------------
     185           0 :     OFormattedNumericControl::~OFormattedNumericControl()
     186             :     {
     187             :         DBG_DTOR(OFormattedNumericControl,NULL);
     188           0 :     }
     189             : 
     190             :     //------------------------------------------------------------------
     191           0 :     void SAL_CALL OFormattedNumericControl::setValue( const Any& _rValue ) throw (IllegalTypeException, RuntimeException)
     192             :     {
     193           0 :         double nValue( 0 );
     194           0 :         if ( _rValue >>= nValue )
     195           0 :             getTypedControlWindow()->SetValue( nValue );
     196             :         else
     197           0 :             getTypedControlWindow()->SetText(String());
     198           0 :     }
     199             : 
     200             :     //------------------------------------------------------------------
     201           0 :     Any SAL_CALL OFormattedNumericControl::getValue() throw (RuntimeException)
     202             :     {
     203           0 :         Any aPropValue;
     204           0 :         if ( getTypedControlWindow()->GetText().Len() )
     205           0 :             aPropValue <<= (double)getTypedControlWindow()->GetValue();
     206           0 :         return aPropValue;
     207             :     }
     208             : 
     209             :     //------------------------------------------------------------------
     210           0 :     Type SAL_CALL OFormattedNumericControl::getValueType() throw (RuntimeException)
     211             :     {
     212           0 :         return ::getCppuType( static_cast< double* >( NULL ) );
     213             :     }
     214             : 
     215             :     //------------------------------------------------------------------
     216           0 :     void OFormattedNumericControl::SetFormatDescription(const FormatDescription& rDesc)
     217             :     {
     218           0 :         sal_Bool bFallback = sal_True;
     219             : 
     220           0 :         if (rDesc.pSupplier)
     221             :         {
     222           0 :             getTypedControlWindow()->TreatAsNumber(sal_True);
     223             : 
     224           0 :             SvNumberFormatter* pFormatter = rDesc.pSupplier->GetNumberFormatter();
     225           0 :             if (pFormatter != getTypedControlWindow()->GetFormatter())
     226           0 :                 getTypedControlWindow()->SetFormatter(pFormatter, sal_True);
     227           0 :             getTypedControlWindow()->SetFormatKey(rDesc.nKey);
     228             : 
     229           0 :             const SvNumberformat* pEntry = getTypedControlWindow()->GetFormatter()->GetEntry(getTypedControlWindow()->GetFormatKey());
     230             :             DBG_ASSERT( pEntry, "OFormattedNumericControl::SetFormatDescription: invalid format key!" );
     231           0 :             if ( pEntry )
     232             :             {
     233           0 :                 switch (pEntry->GetType() & ~NUMBERFORMAT_DEFINED)
     234             :                 {
     235             :                     case NUMBERFORMAT_NUMBER:
     236             :                     case NUMBERFORMAT_CURRENCY:
     237             :                     case NUMBERFORMAT_SCIENTIFIC:
     238             :                     case NUMBERFORMAT_FRACTION:
     239             :                     case NUMBERFORMAT_PERCENT:
     240           0 :                         m_nLastDecimalDigits = getTypedControlWindow()->GetDecimalDigits();
     241           0 :                         break;
     242             :                     case NUMBERFORMAT_DATETIME:
     243             :                     case NUMBERFORMAT_DATE:
     244             :                     case NUMBERFORMAT_TIME:
     245           0 :                         m_nLastDecimalDigits = 7;
     246           0 :                         break;
     247             :                     default:
     248           0 :                         m_nLastDecimalDigits = 0;
     249           0 :                         break;
     250             :                 }
     251           0 :                 bFallback = sal_False;
     252             :             }
     253             : 
     254             :         }
     255             : 
     256           0 :         if ( bFallback )
     257             :         {
     258           0 :             getTypedControlWindow()->TreatAsNumber(sal_False);
     259           0 :             getTypedControlWindow()->SetFormatter(NULL, sal_True);
     260           0 :             getTypedControlWindow()->SetText(String());
     261           0 :             m_nLastDecimalDigits = 0;
     262             :         }
     263           0 :     }
     264             : 
     265             :     //========================================================================
     266             :     //= OFileUrlControl
     267             :     //========================================================================
     268             :     //------------------------------------------------------------------
     269           0 :     OFileUrlControl::OFileUrlControl( Window* pParent, WinBits nWinStyle )
     270           0 :         :OFileUrlControl_Base( PropertyControlType::Unknown, pParent, nWinStyle | WB_DROPDOWN )
     271             :     {
     272           0 :         getTypedControlWindow()->SetDropDownLineCount( 10 );
     273           0 :         getTypedControlWindow()->SetPlaceHolder( String( PcrRes( RID_EMBED_IMAGE_PLACEHOLDER ) ) ) ;
     274           0 :     }
     275             : 
     276             :     //------------------------------------------------------------------
     277           0 :     OFileUrlControl::~OFileUrlControl()
     278             :     {
     279           0 :     }
     280             : 
     281             :     //------------------------------------------------------------------
     282           0 :     void SAL_CALL OFileUrlControl::setValue( const Any& _rValue ) throw (IllegalTypeException, RuntimeException)
     283             :     {
     284           0 :         ::rtl::OUString sURL;
     285           0 :         if ( ( _rValue >>= sURL ) )
     286             :         {
     287           0 :             if ( sURL.indexOf( "vnd.sun.star.GraphicObject:" ) == 0 )
     288           0 :                 getTypedControlWindow()->DisplayURL( getTypedControlWindow()->GetPlaceHolder() );
     289             :             else
     290           0 :                 getTypedControlWindow()->DisplayURL( sURL );
     291             :         }
     292             :         else
     293           0 :             getTypedControlWindow()->SetText( String() );
     294           0 :     }
     295             : 
     296             :     //------------------------------------------------------------------
     297           0 :     Any SAL_CALL OFileUrlControl::getValue() throw (RuntimeException)
     298             :     {
     299           0 :         Any aPropValue;
     300           0 :         if ( getTypedControlWindow()->GetText().Len() )
     301           0 :                 aPropValue <<= (::rtl::OUString)getTypedControlWindow()->GetURL();
     302           0 :         return aPropValue;
     303             :     }
     304             : 
     305             :     //------------------------------------------------------------------
     306           0 :     Type SAL_CALL OFileUrlControl::getValueType() throw (RuntimeException)
     307             :     {
     308           0 :         return ::getCppuType( static_cast< ::rtl::OUString* >( NULL ) );
     309             :     }
     310             : 
     311             :     //========================================================================
     312             :     //= OTimeDurationControl
     313             :     //========================================================================
     314             :     //------------------------------------------------------------------
     315           0 :     OTimeDurationControl::OTimeDurationControl( ::Window* pParent, WinBits nWinStyle )
     316           0 :         :ONumericControl( pParent, nWinStyle )
     317             :     {
     318           0 :         getTypedControlWindow()->SetUnit( FUNIT_CUSTOM );
     319           0 :         getTypedControlWindow()->SetCustomUnitText(rtl::OUString(" ms"));
     320           0 :         getTypedControlWindow()->SetCustomConvertHdl( LINK( this, OTimeDurationControl, OnCustomConvert ) );
     321           0 :     }
     322             : 
     323             :     //------------------------------------------------------------------
     324           0 :     OTimeDurationControl::~OTimeDurationControl()
     325             :     {
     326           0 :     }
     327             : 
     328             :     //------------------------------------------------------------------
     329           0 :     ::sal_Int16 SAL_CALL OTimeDurationControl::getControlType() throw (::com::sun::star::uno::RuntimeException)
     330             :     {
     331             :         // don't use the base class'es method, it would claim we're a standard control, which
     332             :         // we in fact aren't
     333           0 :         return PropertyControlType::Unknown;
     334             :     }
     335             : 
     336             :     //------------------------------------------------------------------
     337           0 :     IMPL_LINK( OTimeDurationControl, OnCustomConvert, MetricField*, /*pField*/ )
     338             :     {
     339           0 :         long nMultiplier = 1;
     340           0 :         if ( getTypedControlWindow()->GetCurUnitText().EqualsIgnoreCaseAscii( "ms" ) )
     341           0 :             nMultiplier = 1;
     342           0 :         if ( getTypedControlWindow()->GetCurUnitText().EqualsIgnoreCaseAscii( "s" ) )
     343           0 :             nMultiplier = 1000;
     344           0 :         else if ( getTypedControlWindow()->GetCurUnitText().EqualsIgnoreCaseAscii( "m" ) )
     345           0 :             nMultiplier = 1000 * 60;
     346           0 :         else if ( getTypedControlWindow()->GetCurUnitText().EqualsIgnoreCaseAscii( "h" ) )
     347           0 :             nMultiplier = 1000 * 60 * 60;
     348             : 
     349           0 :         getTypedControlWindow()->SetValue( getTypedControlWindow()->GetLastValue() * nMultiplier );
     350             : 
     351           0 :         return 0L;
     352             :     }
     353             : 
     354             : //............................................................................
     355             : } // namespace pcr
     356             : //............................................................................
     357             : 
     358             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10