LCOV - code coverage report
Current view: top level - forms/source/component - Edit.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 203 321 63.2 %
Date: 2015-06-13 12:38:46 Functions: 35 46 76.1 %
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             : 
      21             : #include "Edit.hxx"
      22             : 
      23             : #include <com/sun/star/uno/Type.hxx>
      24             : #include <com/sun/star/awt/XWindow.hpp>
      25             : #include <com/sun/star/container/XIndexAccess.hpp>
      26             : #include <com/sun/star/form/XSubmit.hpp>
      27             : #include <com/sun/star/util/NumberFormat.hpp>
      28             : #include <com/sun/star/sdbc/DataType.hpp>
      29             : #include <com/sun/star/awt/XVclWindowPeer.hpp>
      30             : 
      31             : #include <vcl/svapp.hxx>
      32             : #include <vcl/keycodes.hxx>
      33             : #include <tools/wintypes.hxx>
      34             : 
      35             : #include <connectivity/dbtools.hxx>
      36             : #include <connectivity/formattedcolumnvalue.hxx>
      37             : #include <connectivity/dbconversion.hxx>
      38             : 
      39             : #include <tools/diagnose_ex.h>
      40             : 
      41             : #include <comphelper/container.hxx>
      42             : #include <comphelper/numbers.hxx>
      43             : #include <comphelper/processfactory.hxx>
      44             : 
      45             : using namespace dbtools;
      46             : 
      47             : namespace frm
      48             : {
      49             : using namespace ::com::sun::star::uno;
      50             : using namespace ::com::sun::star::sdb;
      51             : using namespace ::com::sun::star::sdbc;
      52             : using namespace ::com::sun::star::sdbcx;
      53             : using namespace ::com::sun::star::beans;
      54             : using namespace ::com::sun::star::container;
      55             : using namespace ::com::sun::star::form;
      56             : using namespace ::com::sun::star::awt;
      57             : using namespace ::com::sun::star::io;
      58             : using namespace ::com::sun::star::lang;
      59             : using namespace ::com::sun::star::util;
      60             : using namespace ::com::sun::star::form::binding;
      61             : 
      62             : 
      63           0 : Sequence<Type> OEditControl::_getTypes()
      64             : {
      65           0 :     static Sequence<Type> aTypes;
      66           0 :     if (!aTypes.getLength())
      67             :     {
      68             :         // my two base classes
      69           0 :         aTypes = concatSequences(OBoundControl::_getTypes(), OEditControl_BASE::getTypes());
      70             :     }
      71           0 :     return aTypes;
      72             : }
      73             : 
      74             : 
      75        2783 : Any SAL_CALL OEditControl::queryAggregation(const Type& _rType) throw (RuntimeException, std::exception)
      76             : {
      77        2783 :     Any aReturn = OBoundControl::queryAggregation(_rType);
      78        2783 :     if (!aReturn.hasValue())
      79         115 :         aReturn = OEditControl_BASE::queryInterface(_rType);
      80             : 
      81        2783 :     return aReturn;
      82             : }
      83             : 
      84             : 
      85          59 : OEditControl::OEditControl(const Reference<XComponentContext>& _rxFactory)
      86             :                :OBoundControl( _rxFactory, FRM_SUN_CONTROL_RICHTEXTCONTROL )
      87             :                ,m_aChangeListeners(m_aMutex)
      88          59 :                ,m_nKeyEvent( 0 )
      89             : {
      90             : 
      91          59 :     osl_atomic_increment(&m_refCount);
      92             :     {
      93          59 :         Reference<XWindow>  xComp;
      94          59 :         if (query_aggregation(m_xAggregate, xComp))
      95             :         {
      96          59 :             xComp->addFocusListener(this);
      97          59 :             xComp->addKeyListener(this);
      98          59 :         }
      99             :     }
     100          59 :     osl_atomic_decrement(&m_refCount);
     101          59 : }
     102             : 
     103             : 
     104         126 : OEditControl::~OEditControl()
     105             : {
     106          42 :     if( m_nKeyEvent )
     107           0 :         Application::RemoveUserEvent( m_nKeyEvent );
     108             : 
     109          42 :     if (!OComponentHelper::rBHelper.bDisposed)
     110             :     {
     111           0 :         acquire();
     112           0 :         dispose();
     113             :     }
     114             : 
     115          84 : }
     116             : 
     117             : // XChangeBroadcaster
     118             : 
     119           0 : void OEditControl::addChangeListener(const Reference<XChangeListener>& l) throw ( ::com::sun::star::uno::RuntimeException, std::exception)
     120             : {
     121           0 :     m_aChangeListeners.addInterface( l );
     122           0 : }
     123             : 
     124             : 
     125           0 : void OEditControl::removeChangeListener(const Reference<XChangeListener>& l) throw ( ::com::sun::star::uno::RuntimeException, std::exception)
     126             : {
     127           0 :     m_aChangeListeners.removeInterface( l );
     128           0 : }
     129             : 
     130             : // OComponentHelper
     131             : 
     132          42 : void OEditControl::disposing()
     133             : {
     134          42 :     OBoundControl::disposing();
     135             : 
     136          42 :     EventObject aEvt(static_cast<XWeak*>(this));
     137          42 :     m_aChangeListeners.disposeAndClear(aEvt);
     138          42 : }
     139             : 
     140             : // XServiceInfo
     141             : 
     142           1 : StringSequence  OEditControl::getSupportedServiceNames() throw(std::exception)
     143             : {
     144           1 :     StringSequence aSupported = OBoundControl::getSupportedServiceNames();
     145           1 :     aSupported.realloc(aSupported.getLength() + 3);
     146             : 
     147           1 :     OUString*pArray = aSupported.getArray();
     148           1 :     pArray[aSupported.getLength()-3] = FRM_SUN_CONTROL_TEXTFIELD;
     149           1 :     pArray[aSupported.getLength()-2] = STARDIV_ONE_FORM_CONTROL_EDIT;
     150           1 :     pArray[aSupported.getLength()-1] = STARDIV_ONE_FORM_CONTROL_TEXTFIELD;
     151           1 :     return aSupported;
     152             : }
     153             : 
     154             : // XEventListener
     155             : 
     156         138 : void OEditControl::disposing(const EventObject& Source) throw( RuntimeException, std::exception )
     157             : {
     158         138 :     OBoundControl::disposing(Source);
     159         138 : }
     160             : 
     161             : // XFocusListener
     162             : 
     163           0 : void OEditControl::focusGained( const FocusEvent& /*e*/ ) throw ( ::com::sun::star::uno::RuntimeException, std::exception)
     164             : {
     165           0 :     Reference<XPropertySet>  xSet(getModel(), UNO_QUERY);
     166           0 :     if (xSet.is())
     167           0 :         xSet->getPropertyValue( PROPERTY_TEXT ) >>= m_aHtmlChangeValue;
     168           0 : }
     169             : 
     170             : 
     171           0 : void OEditControl::focusLost( const FocusEvent& /*e*/ ) throw ( ::com::sun::star::uno::RuntimeException, std::exception)
     172             : {
     173           0 :     Reference<XPropertySet>  xSet(getModel(), UNO_QUERY);
     174           0 :     if (xSet.is())
     175             :     {
     176           0 :         OUString sNewHtmlChangeValue;
     177           0 :         xSet->getPropertyValue( PROPERTY_TEXT ) >>= sNewHtmlChangeValue;
     178           0 :         if( sNewHtmlChangeValue != m_aHtmlChangeValue )
     179             :         {
     180           0 :             EventObject aEvt( *this );
     181           0 :             m_aChangeListeners.notifyEach( &XChangeListener::changed, aEvt );
     182           0 :         }
     183           0 :     }
     184           0 : }
     185             : 
     186             : // XKeyListener
     187             : 
     188           0 : void OEditControl::keyPressed(const ::com::sun::star::awt::KeyEvent& e) throw ( ::com::sun::star::uno::RuntimeException, std::exception)
     189             : {
     190           0 :     if( e.KeyCode != KEY_RETURN || e.Modifiers != 0 )
     191           0 :         return;
     192             : 
     193             :     // Is the Control in a form with a submit URL?
     194           0 :     Reference<XPropertySet>  xSet(getModel(), UNO_QUERY);
     195           0 :     if( !xSet.is() )
     196           0 :         return;
     197             : 
     198             :     // Not for multiline edits
     199           0 :     Any aTmp( xSet->getPropertyValue(PROPERTY_MULTILINE));
     200           0 :     if ((aTmp.getValueType().equals(cppu::UnoType<bool>::get())) && getBOOL(aTmp))
     201           0 :         return;
     202             : 
     203           0 :     Reference<XFormComponent>  xFComp(xSet, UNO_QUERY);
     204           0 :     InterfaceRef  xParent = xFComp->getParent();
     205           0 :     if( !xParent.is() )
     206           0 :         return;
     207             : 
     208           0 :     Reference<XPropertySet>  xFormSet(xParent, UNO_QUERY);
     209           0 :     if( !xFormSet.is() )
     210           0 :         return;
     211             : 
     212           0 :     aTmp = xFormSet->getPropertyValue( PROPERTY_TARGET_URL );
     213           0 :     if (!aTmp.getValueType().equals(cppu::UnoType<OUString>::get()) ||
     214           0 :         getString(aTmp).isEmpty() )
     215           0 :         return;
     216             : 
     217           0 :     Reference<XIndexAccess>  xElements(xParent, UNO_QUERY);
     218           0 :     sal_Int32 nCount = xElements->getCount();
     219           0 :     if( nCount > 1 )
     220             :     {
     221           0 :         Reference<XPropertySet>  xFCSet;
     222           0 :         for( sal_Int32 nIndex=0; nIndex < nCount; nIndex++ )
     223             :         {
     224             :             //  Any aElement(xElements->getByIndex(nIndex));
     225           0 :             xElements->getByIndex(nIndex) >>= xFCSet;
     226             :             OSL_ENSURE(xFCSet.is(),"OEditControl::keyPressed: No XPropertySet!");
     227             : 
     228           0 :             if (hasProperty(PROPERTY_CLASSID, xFCSet) &&
     229           0 :                 getINT16(xFCSet->getPropertyValue(PROPERTY_CLASSID)) == FormComponentType::TEXTFIELD)
     230             :             {
     231             :                 // Found another Edit -> then do not submit!
     232           0 :                 if (xFCSet != xSet)
     233           0 :                     return;
     234             :             }
     235           0 :         }
     236             :     }
     237             : 
     238             :     // Because we're still in the header, trigger submit asynchronously
     239           0 :     if( m_nKeyEvent )
     240           0 :         Application::RemoveUserEvent( m_nKeyEvent );
     241           0 :     m_nKeyEvent = Application::PostUserEvent( LINK(this, OEditControl,OnKeyPressed) );
     242             : }
     243             : 
     244             : 
     245           0 : void OEditControl::keyReleased(const ::com::sun::star::awt::KeyEvent& /*e*/) throw ( ::com::sun::star::uno::RuntimeException, std::exception)
     246             : {
     247           0 : }
     248             : 
     249             : 
     250           0 : IMPL_LINK_NOARG(OEditControl, OnKeyPressed)
     251             : {
     252           0 :     m_nKeyEvent = 0;
     253             : 
     254           0 :     Reference<XFormComponent>  xFComp(getModel(), UNO_QUERY);
     255           0 :     InterfaceRef  xParent = xFComp->getParent();
     256           0 :     Reference<XSubmit>  xSubmit(xParent, UNO_QUERY);
     257           0 :     if (xSubmit.is())
     258           0 :         xSubmit->submit( Reference<XControl>(), ::com::sun::star::awt::MouseEvent() );
     259           0 :     return 0L;
     260             : }
     261             : 
     262             : 
     263          84 : void SAL_CALL OEditControl::createPeer( const Reference< XToolkit>& _rxToolkit, const Reference< XWindowPeer>& _rxParent ) throw ( RuntimeException, std::exception )
     264             : {
     265          84 :     OBoundControl::createPeer(_rxToolkit, _rxParent);
     266          84 : }
     267             : 
     268             : 
     269           0 : Sequence<Type> OEditModel::_getTypes()
     270             : {
     271           0 :     return OEditBaseModel::_getTypes();
     272             : }
     273             : 
     274             : 
     275             : 
     276         106 : OEditModel::OEditModel(const Reference<XComponentContext>& _rxFactory)
     277             :     :OEditBaseModel( _rxFactory, FRM_SUN_COMPONENT_RICHTEXTCONTROL, FRM_SUN_CONTROL_TEXTFIELD, true, true )
     278             :     ,m_bMaxTextLenModified(false)
     279         106 :     ,m_bWritingFormattedFake(false)
     280             : {
     281             : 
     282         106 :     m_nClassId = FormComponentType::TEXTFIELD;
     283         106 :     initValueProperty( PROPERTY_TEXT, PROPERTY_ID_TEXT );
     284         106 : }
     285             : 
     286             : 
     287           2 : OEditModel::OEditModel( const OEditModel* _pOriginal, const Reference<XComponentContext>& _rxFactory )
     288             :     :OEditBaseModel( _pOriginal, _rxFactory )
     289             :     ,m_bMaxTextLenModified(false)
     290           2 :     ,m_bWritingFormattedFake(false)
     291             : {
     292             : 
     293             :     // Note that most of the properties are not clone from the original object:
     294             :     // Things as the format key, it's type, and such, depend on the field being part of a loaded form
     295             :     // (they're initialized in onConnectedDbColumn). Even if the original object _is_ part of such a form, we ourself
     296             :     // certainly aren't, so these members are defaulted. If we're inserted into a form which is already loaded,
     297             :     // they will be set to new values, anyway ....
     298           2 : }
     299             : 
     300             : 
     301         300 : OEditModel::~OEditModel()
     302             : {
     303         100 :     if (!OComponentHelper::rBHelper.bDisposed)
     304             :     {
     305           0 :         acquire();
     306           0 :         dispose();
     307             :     }
     308             : 
     309         200 : }
     310             : 
     311             : 
     312           2 : IMPLEMENT_DEFAULT_CLONING( OEditModel )
     313             : 
     314             : 
     315         100 : void OEditModel::disposing()
     316             : {
     317         100 :     OEditBaseModel::disposing();
     318         100 :     m_pValueFormatter.reset();
     319         100 : }
     320             : 
     321             : // XPersistObject
     322             : 
     323           1 : OUString SAL_CALL OEditModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException, std::exception)
     324             : {
     325           1 :     return OUString(FRM_COMPONENT_EDIT);  // old (non-sun) name for compatibility !
     326             : }
     327             : 
     328             : // XServiceInfo
     329             : 
     330          53 : StringSequence SAL_CALL OEditModel::getSupportedServiceNames() throw(std::exception)
     331             : {
     332          53 :     StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
     333             : 
     334          53 :     sal_Int32 nOldLen = aSupported.getLength();
     335          53 :     aSupported.realloc( nOldLen + 9 );
     336          53 :     OUString* pStoreTo = aSupported.getArray() + nOldLen;
     337             : 
     338          53 :     *pStoreTo++ = BINDABLE_CONTROL_MODEL;
     339          53 :     *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
     340          53 :     *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
     341             : 
     342          53 :     *pStoreTo++ = BINDABLE_DATA_AWARE_CONTROL_MODEL;
     343          53 :     *pStoreTo++ = VALIDATABLE_BINDABLE_CONTROL_MODEL;
     344             : 
     345          53 :     *pStoreTo++ = FRM_SUN_COMPONENT_TEXTFIELD;
     346          53 :     *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_TEXTFIELD;
     347          53 :     *pStoreTo++ = BINDABLE_DATABASE_TEXT_FIELD;
     348             : 
     349          53 :     *pStoreTo++ = FRM_COMPONENT_TEXTFIELD;
     350             : 
     351          53 :     return aSupported;
     352             : }
     353             : 
     354             : // XPropertySet
     355       13729 : void SAL_CALL OEditModel::getFastPropertyValue(Any& rValue, sal_Int32 nHandle ) const
     356             : {
     357       13729 :     if ( PROPERTY_ID_PERSISTENCE_MAXTEXTLENGTH == nHandle )
     358             :     {
     359          89 :         if ( m_bMaxTextLenModified )
     360           0 :             rValue <<= sal_Int16(0);
     361          89 :         else if ( m_xAggregateSet.is() )
     362          89 :             rValue = m_xAggregateSet->getPropertyValue(PROPERTY_MAXTEXTLEN);
     363             :     }
     364             :     else
     365             :     {
     366       13640 :         OEditBaseModel::getFastPropertyValue(rValue, nHandle );
     367             :     }
     368       13729 : }
     369             : 
     370             : 
     371         109 : void OEditModel::describeFixedProperties( Sequence< Property >& _rProps ) const
     372             : {
     373         109 :     BEGIN_DESCRIBE_PROPERTIES( 5, OEditBaseModel )
     374         109 :         DECL_PROP2(PERSISTENCE_MAXTEXTLENGTH,sal_Int16,         READONLY, TRANSIENT);
     375         109 :         DECL_PROP2(DEFAULT_TEXT,        OUString,        BOUND, MAYBEDEFAULT);
     376         109 :         DECL_BOOL_PROP1(EMPTY_IS_NULL,                          BOUND);
     377         109 :         DECL_PROP1(TABINDEX,            sal_Int16,              BOUND);
     378         109 :         DECL_BOOL_PROP2(FILTERPROPOSAL,                         BOUND, MAYBEDEFAULT);
     379             :     END_DESCRIBE_PROPERTIES();
     380         109 : }
     381             : 
     382             : 
     383         109 : void OEditModel::describeAggregateProperties( Sequence< Property >& _rAggregateProps ) const
     384             : {
     385         109 :     OEditBaseModel::describeAggregateProperties( _rAggregateProps );
     386             : 
     387             :     // our aggregate is a rich text model, which also derives from OControlModel, as
     388             :     // do we, so we need to remove some duplicate properties
     389         109 :     RemoveProperty( _rAggregateProps, PROPERTY_TABINDEX );
     390         109 :     RemoveProperty( _rAggregateProps, PROPERTY_CLASSID );
     391         109 :     RemoveProperty( _rAggregateProps, PROPERTY_NAME );
     392         109 :     RemoveProperty( _rAggregateProps, PROPERTY_TAG );
     393         109 :     RemoveProperty( _rAggregateProps, PROPERTY_NATIVE_LOOK );
     394             : 
     395         109 : }
     396             : 
     397             : 
     398          22 : bool OEditModel::implActsAsRichText( ) const
     399             : {
     400          22 :     bool bActAsRichText = false;
     401          22 :     if ( m_xAggregateSet.is() )
     402             :     {
     403          22 :         OSL_VERIFY( m_xAggregateSet->getPropertyValue( PROPERTY_RICH_TEXT ) >>= bActAsRichText );
     404             :     }
     405          22 :     return bActAsRichText;
     406             : }
     407             : 
     408             : 
     409           5 : void SAL_CALL OEditModel::reset(  ) throw(RuntimeException, std::exception)
     410             : {
     411             :     // no reset if we currently act as rich text control
     412           5 :     if ( implActsAsRichText() )
     413           5 :         return;
     414             : 
     415           5 :     OEditBaseModel::reset();
     416             : }
     417             : 
     418             : 
     419             : namespace
     420             : {
     421           4 :     void lcl_transferProperties( const Reference< XPropertySet >& _rxSource, const Reference< XPropertySet >& _rxDest )
     422             :     {
     423             :         try
     424             :         {
     425           4 :             Reference< XPropertySetInfo > xSourceInfo;
     426           4 :             if ( _rxSource.is() )
     427           4 :                 xSourceInfo = _rxSource->getPropertySetInfo();
     428             : 
     429           8 :             Reference< XPropertySetInfo > xDestInfo;
     430           4 :             if ( _rxDest.is() )
     431           4 :                 xDestInfo = _rxDest->getPropertySetInfo();
     432             : 
     433           4 :             if ( !xSourceInfo.is() || !xDestInfo.is() )
     434             :             {
     435             :                 OSL_FAIL( "lcl_transferProperties: invalid property set(s)!" );
     436           4 :                 return;
     437             :             }
     438             : 
     439           8 :             Sequence< Property > aSourceProps( xSourceInfo->getProperties() );
     440           4 :             const Property* pSourceProps = aSourceProps.getConstArray();
     441           4 :             const Property* pSourcePropsEnd = aSourceProps.getConstArray() + aSourceProps.getLength();
     442         344 :             while ( pSourceProps != pSourcePropsEnd )
     443             :             {
     444         336 :                 if ( !xDestInfo->hasPropertyByName( pSourceProps->Name ) )
     445             :                 {
     446         156 :                     ++pSourceProps;
     447         312 :                     continue;
     448             :                 }
     449             : 
     450         180 :                 Property aDestProp( xDestInfo->getPropertyByName( pSourceProps->Name ) );
     451         180 :                 if ( 0 != ( aDestProp.Attributes & PropertyAttribute::READONLY ) )
     452             :                 {
     453           0 :                     ++pSourceProps;
     454           0 :                     continue;
     455             :                 }
     456             : 
     457             :                 try
     458             :                 {
     459         180 :                     _rxDest->setPropertyValue( pSourceProps->Name, _rxSource->getPropertyValue( pSourceProps->Name ) );
     460             :                 }
     461           0 :                 catch(const IllegalArgumentException& e)
     462             :                 {
     463             : #if OSL_DEBUG_LEVEL > 0
     464             :                     OString sMessage( "could not transfer the property named '" );
     465             :                     sMessage += OString( pSourceProps->Name.getStr(), pSourceProps->Name.getLength(), RTL_TEXTENCODING_ASCII_US );
     466             :                     sMessage += OString( "'." );
     467             :                     if ( !e.Message.isEmpty() )
     468             :                     {
     469             :                         sMessage += OString( "\n\nMessage:\n" );
     470             :                         sMessage += OString( e.Message.getStr(), e.Message.getLength(), RTL_TEXTENCODING_ASCII_US );
     471             :                     }
     472             :                     OSL_FAIL( sMessage.getStr() );
     473             : #else
     474             :                     (void)e;
     475             : #endif
     476             :                 }
     477             : 
     478         180 :                 ++pSourceProps;
     479         184 :             }
     480             :         }
     481           0 :         catch( const Exception& )
     482             :         {
     483             :             DBG_UNHANDLED_EXCEPTION();
     484             :         }
     485             :     }
     486             : }
     487             : 
     488             : 
     489           2 : void OEditModel::writeAggregate( const Reference< XObjectOutputStream >& _rxOutStream ) const
     490             : {
     491             :     // we need to fake the writing of our aggregate. Since #i24387#, we have another aggregate,
     492             :     // but for compatibility, we need to use an "old" aggregate for writing and reading
     493             : 
     494             :     Reference< XPropertySet > xFakedAggregate(
     495           4 :         getContext()->getServiceManager()->createInstanceWithContext( OUString(VCL_CONTROLMODEL_EDIT), getContext() ),
     496             :         UNO_QUERY
     497           2 :     );
     498             :     OSL_ENSURE( xFakedAggregate.is(), "OEditModel::writeAggregate: could not create an old EditControlModel!" );
     499           2 :     if ( !xFakedAggregate.is() )
     500           2 :         return;
     501             : 
     502           2 :     lcl_transferProperties( m_xAggregateSet, xFakedAggregate );
     503             : 
     504           4 :     Reference< XPersistObject > xFakedPersist( xFakedAggregate, UNO_QUERY );
     505             :     OSL_ENSURE( xFakedPersist.is(), "OEditModel::writeAggregate: no XPersistObject!" );
     506           2 :     if ( xFakedPersist.is() )
     507           4 :         xFakedPersist->write( _rxOutStream );
     508             : }
     509             : 
     510             : 
     511           2 : void OEditModel::readAggregate( const Reference< XObjectInputStream >& _rxInStream )
     512             : {
     513             :     // we need to fake the reading of our aggregate. Since #i24387#, we have another aggregate,
     514             :     // but for compatibility, we need to use an "old" aggregate for writing and reading
     515             : 
     516             :     Reference< XPropertySet > xFakedAggregate(
     517           4 :         getContext()->getServiceManager()->createInstanceWithContext( OUString(VCL_CONTROLMODEL_EDIT), getContext() ),
     518             :         UNO_QUERY
     519           2 :     );
     520           4 :     Reference< XPersistObject > xFakedPersist( xFakedAggregate, UNO_QUERY );
     521             :     OSL_ENSURE( xFakedPersist.is(), "OEditModel::readAggregate: no XPersistObject, or no faked aggregate at all!" );
     522           2 :     if ( xFakedPersist.is() )
     523             :     {
     524           2 :         xFakedPersist->read( _rxInStream );
     525           2 :         lcl_transferProperties( xFakedAggregate, m_xAggregateSet );
     526           2 :     }
     527           2 : }
     528             : 
     529             : 
     530           2 : void OEditModel::write(const Reference<XObjectOutputStream>& _rxOutStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception)
     531             : {
     532           2 :     Any aCurrentText;
     533           2 :     sal_Int16 nOldTextLen = 0;
     534             :     // Am I loaded at the moment and did I switch MaxTextLen temporarily?
     535           2 :     if ( m_bMaxTextLenModified )
     536             :     {   // -> for the duration of saving, make my aggregated model believe the old TextLen
     537             : 
     538             :         // before doing this we have to save the current text value of the aggregate, as this may be affected by resetting the text len
     539           0 :         aCurrentText = m_xAggregateSet->getPropertyValue(PROPERTY_TEXT);
     540             : 
     541           0 :         m_xAggregateSet->getPropertyValue(PROPERTY_MAXTEXTLEN) >>= nOldTextLen;
     542           0 :         m_xAggregateSet->setPropertyValue(PROPERTY_MAXTEXTLEN, makeAny((sal_Int16)0));
     543             :     }
     544             : 
     545           2 :     OEditBaseModel::write(_rxOutStream);
     546             : 
     547           2 :     if ( m_bMaxTextLenModified )
     548             :     {   // Reset again
     549           0 :         m_xAggregateSet->setPropertyValue(PROPERTY_MAXTEXTLEN, makeAny(nOldTextLen));
     550             :         // and reset the text
     551             :         // First we set it to an empty string : Without this the second setPropertyValue would not do anything as it thinks
     552             :         // we aren't changing the prop (it didn't notify the - implicite - change of the text prop while setting the max text len)
     553             :         // This seems to be a bug with in toolkit's EditControl-implementation.
     554           0 :         m_xAggregateSet->setPropertyValue(PROPERTY_TEXT, makeAny(OUString()));
     555           0 :         m_xAggregateSet->setPropertyValue(PROPERTY_TEXT, aCurrentText);
     556           2 :     }
     557           2 : }
     558             : 
     559             : 
     560           2 : void OEditModel::read(const Reference<XObjectInputStream>& _rxInStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception)
     561             : {
     562           2 :     OEditBaseModel::read(_rxInStream);
     563             : 
     564             :     // Some versions (5.1 'til about 552) wrote a wrong DefaultControl-property value which is unknown
     565             :     // to older versions (5.0).
     566             :     // correct this ...
     567           2 :     if (m_xAggregateSet.is())
     568             :     {
     569           2 :         Any aDefaultControl = m_xAggregateSet->getPropertyValue(PROPERTY_DEFAULTCONTROL);
     570           6 :         if  (   (aDefaultControl.getValueType().getTypeClass() == TypeClass_STRING)
     571           8 :             &&  (getString(aDefaultControl) == STARDIV_ONE_FORM_CONTROL_TEXTFIELD )
     572             :             )
     573             :         {
     574           0 :             m_xAggregateSet->setPropertyValue( PROPERTY_DEFAULTCONTROL, makeAny( OUString(STARDIV_ONE_FORM_CONTROL_EDIT) ) );
     575             :             // Older as well as current versions should understand this : the former knew only the STARDIV_ONE_FORM_CONTROL_EDIT,
     576             :             // the latter are registered for both STARDIV_ONE_FORM_CONTROL_EDIT and STARDIV_ONE_FORM_CONTROL_TEXTFIELD.
     577           2 :         }
     578             :     }
     579           2 : }
     580             : 
     581             : 
     582           2 : sal_uInt16 OEditModel::getPersistenceFlags() const
     583             : {
     584           2 :     sal_uInt16 nFlags = OEditBaseModel::getPersistenceFlags();
     585             : 
     586           2 :     if (m_bWritingFormattedFake)
     587           0 :         nFlags |= PF_FAKE_FORMATTED_FIELD;
     588             : 
     589           2 :     return nFlags;
     590             : }
     591             : 
     592             : 
     593          17 : void OEditModel::onConnectedDbColumn( const Reference< XInterface >& _rxForm )
     594             : {
     595          17 :     Reference< XPropertySet > xField = getField();
     596          17 :     if ( xField.is() )
     597             :     {
     598          17 :         m_pValueFormatter.reset( new ::dbtools::FormattedColumnValue( getContext(), Reference< XRowSet >( _rxForm, UNO_QUERY ), xField ) );
     599             : 
     600          17 :         if ( m_pValueFormatter->getKeyType() != NumberFormat::SCIENTIFIC )
     601             :         {
     602          17 :             m_bMaxTextLenModified = getINT16(m_xAggregateSet->getPropertyValue(PROPERTY_MAXTEXTLEN)) != 0;
     603          17 :             if ( !m_bMaxTextLenModified )
     604             :             {
     605          17 :                 sal_Int32 nFieldLen = 0;
     606          17 :                 xField->getPropertyValue("Precision") >>= nFieldLen;
     607             : 
     608          17 :                 if (nFieldLen && nFieldLen <= USHRT_MAX)
     609             :                 {
     610           0 :                     Any aVal;
     611           0 :                     aVal <<= (sal_Int16)nFieldLen;
     612           0 :                     m_xAggregateSet->setPropertyValue(PROPERTY_MAXTEXTLEN, aVal);
     613             : 
     614           0 :                     m_bMaxTextLenModified = true;
     615             :                 }
     616             :             }
     617             :             else
     618           0 :                 m_bMaxTextLenModified = false; // to get sure that the text len won't be set in unloaded
     619             :         }
     620          17 :     }
     621          17 : }
     622             : 
     623             : 
     624          17 : void OEditModel::onDisconnectedDbColumn()
     625             : {
     626          17 :     OEditBaseModel::onDisconnectedDbColumn();
     627             : 
     628          17 :     m_pValueFormatter.reset();
     629             : 
     630          17 :     if ( hasField() && m_bMaxTextLenModified )
     631             :     {
     632           0 :         Any aVal;
     633           0 :         aVal <<= (sal_Int16)0;  // Only if it was 0, I switched it in onConnectedDbColumn
     634           0 :         m_xAggregateSet->setPropertyValue(PROPERTY_MAXTEXTLEN, aVal);
     635           0 :         m_bMaxTextLenModified = false;
     636             :     }
     637          17 : }
     638             : 
     639             : 
     640          17 : bool OEditModel::approveDbColumnType( sal_Int32 _nColumnType )
     641             : {
     642             :     // if we act as rich text currently, we do not allow binding to a database column
     643          17 :     if ( implActsAsRichText() )
     644           0 :         return false;
     645             : 
     646          17 :     return OEditBaseModel::approveDbColumnType( _nColumnType );
     647             : }
     648             : 
     649             : 
     650          15 : void OEditModel::resetNoBroadcast()
     651             : {
     652          15 :     OEditBaseModel::resetNoBroadcast();
     653          15 : }
     654             : 
     655             : 
     656           0 : bool OEditModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
     657             : {
     658           0 :     Any aNewValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
     659             : 
     660           0 :     OUString sNewValue;
     661           0 :     aNewValue >>= sNewValue;
     662             : 
     663           0 :     if  (   !aNewValue.hasValue()
     664           0 :         ||  (   sNewValue.isEmpty()         // an empty string
     665           0 :             &&  m_bEmptyIsNull              // which should be interpreted as NULL
     666             :             )
     667             :         )
     668             :     {
     669           0 :         m_xColumnUpdate->updateNull();
     670             :     }
     671             :     else
     672             :     {
     673             :         OSL_PRECOND( m_pValueFormatter.get(), "OEditModel::commitControlValueToDbColumn: no value formatter!" );
     674             :         try
     675             :         {
     676           0 :             if ( m_pValueFormatter.get() )
     677             :             {
     678           0 :                 if ( !m_pValueFormatter->setFormattedValue( sNewValue ) )
     679           0 :                     return false;
     680             :             }
     681             :             else
     682           0 :                 m_xColumnUpdate->updateString( sNewValue );
     683             :         }
     684           0 :         catch ( const Exception& )
     685             :         {
     686           0 :             return false;
     687             :         }
     688             :     }
     689             : 
     690           0 :     return true;
     691             : }
     692             : 
     693             : 
     694          17 : Any OEditModel::translateDbColumnToControlValue()
     695             : {
     696             :     OSL_PRECOND( m_pValueFormatter.get(), "OEditModel::translateDbColumnToControlValue: no value formatter!" );
     697          17 :     Any aRet;
     698          17 :     if ( m_pValueFormatter.get() )
     699             :     {
     700          17 :         OUString sValue( m_pValueFormatter->getFormattedValue() );
     701          34 :         if  (   sValue.isEmpty()
     702          13 :             &&  m_pValueFormatter->getColumn().is()
     703          30 :             &&  m_pValueFormatter->getColumn()->wasNull()
     704             :             )
     705             :         {
     706             :         }
     707             :         else
     708             :         {
     709             :             // #i2817# OJ
     710          17 :             sal_uInt16 nMaxTextLen = getINT16( m_xAggregateSet->getPropertyValue( PROPERTY_MAXTEXTLEN ) );
     711          17 :             if ( nMaxTextLen && sValue.getLength() > nMaxTextLen )
     712             :             {
     713           0 :                 sal_Int32 nDiff = sValue.getLength() - nMaxTextLen;
     714           0 :                 sValue = sValue.replaceAt( nMaxTextLen, nDiff, OUString() );
     715             :             }
     716             : 
     717          17 :             aRet <<= sValue;
     718          17 :         }
     719             :     }
     720             : 
     721          17 :     return aRet.hasValue() ? aRet : makeAny( OUString() );
     722             : }
     723             : 
     724             : 
     725          15 : Any OEditModel::getDefaultForReset() const
     726             : {
     727          15 :     return makeAny( m_aDefaultText );
     728             : }
     729             : 
     730             : }
     731             : 
     732             : extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
     733          89 : com_sun_star_form_OEditModel_get_implementation(::com::sun::star::uno::XComponentContext* component,
     734             :         ::com::sun::star::uno::Sequence<css::uno::Any> const &)
     735             : {
     736          89 :     return cppu::acquire(new frm::OEditModel(component));
     737             : }
     738             : 
     739             : extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
     740          59 : com_sun_star_form_OEditControl_get_implementation(::com::sun::star::uno::XComponentContext* component,
     741             :         ::com::sun::star::uno::Sequence<css::uno::Any> const &)
     742             : {
     743          59 :     return cppu::acquire(new frm::OEditControl(component));
     744             : }
     745             : 
     746             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11