1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
31 #include <vcl/svapp.hxx>
32 #include <tools/wintypes.hxx>
34 #include <connectivity/dbtools.hxx>
35 #include <connectivity/formattedcolumnvalue.hxx>
36 #include <connectivity/dbconversion.hxx>
38 #include <tools/diagnose_ex.h>
39 #include <tools/debug.hxx>
41 #include <comphelper/container.hxx>
42 #include <comphelper/numbers.hxx>
44 using namespace dbtools
;
46 //.........................................................................
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
;
62 //------------------------------------------------------------------
63 InterfaceRef SAL_CALL
OEditControl_CreateInstance(const Reference
< XMultiServiceFactory
> & _rxFactory
)
65 return *(new OEditControl(_rxFactory
));
68 //------------------------------------------------------------------------------
69 Sequence
<Type
> OEditControl::_getTypes()
71 static Sequence
<Type
> aTypes
;
72 if (!aTypes
.getLength())
74 // my two base classes
75 aTypes
= concatSequences(OBoundControl::_getTypes(), OEditControl_BASE::getTypes());
80 //------------------------------------------------------------------------------
81 Any SAL_CALL
OEditControl::queryAggregation(const Type
& _rType
) throw (RuntimeException
)
83 Any aReturn
= OBoundControl::queryAggregation(_rType
);
84 if (!aReturn
.hasValue())
85 aReturn
= OEditControl_BASE::queryInterface(_rType
);
90 DBG_NAME(OEditControl
);
91 //------------------------------------------------------------------------------
92 OEditControl::OEditControl(const Reference
<XMultiServiceFactory
>& _rxFactory
)
93 :OBoundControl( _rxFactory
, FRM_SUN_CONTROL_RICHTEXTCONTROL
)
94 ,m_aChangeListeners(m_aMutex
)
97 DBG_CTOR(OEditControl
,NULL
);
99 increment(m_refCount
);
101 Reference
<XWindow
> xComp
;
102 if (query_aggregation(m_xAggregate
, xComp
))
104 xComp
->addFocusListener(this);
105 xComp
->addKeyListener(this);
108 decrement(m_refCount
);
111 //------------------------------------------------------------------------------
112 OEditControl::~OEditControl()
115 Application::RemoveUserEvent( m_nKeyEvent
);
117 if (!OComponentHelper::rBHelper
.bDisposed
)
123 DBG_DTOR(OEditControl
,NULL
);
126 // XChangeBroadcaster
127 //------------------------------------------------------------------------------
128 void OEditControl::addChangeListener(const Reference
<XChangeListener
>& l
) throw ( ::com::sun::star::uno::RuntimeException
)
130 m_aChangeListeners
.addInterface( l
);
133 //------------------------------------------------------------------------------
134 void OEditControl::removeChangeListener(const Reference
<XChangeListener
>& l
) throw ( ::com::sun::star::uno::RuntimeException
)
136 m_aChangeListeners
.removeInterface( l
);
140 //------------------------------------------------------------------------------
141 void OEditControl::disposing()
143 OBoundControl::disposing();
145 EventObject
aEvt(static_cast<XWeak
*>(this));
146 m_aChangeListeners
.disposeAndClear(aEvt
);
150 //------------------------------------------------------------------------------
151 StringSequence
OEditControl::getSupportedServiceNames() throw()
153 StringSequence aSupported
= OBoundControl::getSupportedServiceNames();
154 aSupported
.realloc(aSupported
.getLength() + 1);
156 OUString
*pArray
= aSupported
.getArray();
157 pArray
[aSupported
.getLength()-1] = FRM_SUN_CONTROL_TEXTFIELD
;
162 //------------------------------------------------------------------------------
163 void OEditControl::disposing(const EventObject
& Source
) throw( RuntimeException
)
165 OBoundControl::disposing(Source
);
169 //------------------------------------------------------------------------------
170 void OEditControl::focusGained( const FocusEvent
& /*e*/ ) throw ( ::com::sun::star::uno::RuntimeException
)
172 Reference
<XPropertySet
> xSet(getModel(), UNO_QUERY
);
174 xSet
->getPropertyValue( PROPERTY_TEXT
) >>= m_aHtmlChangeValue
;
177 //------------------------------------------------------------------------------
178 void OEditControl::focusLost( const FocusEvent
& /*e*/ ) throw ( ::com::sun::star::uno::RuntimeException
)
180 Reference
<XPropertySet
> xSet(getModel(), UNO_QUERY
);
183 OUString sNewHtmlChangeValue
;
184 xSet
->getPropertyValue( PROPERTY_TEXT
) >>= sNewHtmlChangeValue
;
185 if( sNewHtmlChangeValue
!= m_aHtmlChangeValue
)
187 EventObject
aEvt( *this );
188 m_aChangeListeners
.notifyEach( &XChangeListener::changed
, aEvt
);
194 //------------------------------------------------------------------------------
195 void OEditControl::keyPressed(const ::com::sun::star::awt::KeyEvent
& e
) throw ( ::com::sun::star::uno::RuntimeException
)
197 if( e
.KeyCode
!= KEY_RETURN
|| e
.Modifiers
!= 0 )
200 // Is the Control in a form with a submit URL?
201 Reference
<XPropertySet
> xSet(getModel(), UNO_QUERY
);
205 // Not for multiline edits
206 Any
aTmp( xSet
->getPropertyValue(PROPERTY_MULTILINE
));
207 if ((aTmp
.getValueType().equals(::getBooleanCppuType())) && getBOOL(aTmp
))
210 Reference
<XFormComponent
> xFComp(xSet
, UNO_QUERY
);
211 InterfaceRef xParent
= xFComp
->getParent();
215 Reference
<XPropertySet
> xFormSet(xParent
, UNO_QUERY
);
219 aTmp
= xFormSet
->getPropertyValue( PROPERTY_TARGET_URL
);
220 if (!aTmp
.getValueType().equals(::getCppuType((const OUString
*)NULL
)) ||
221 getString(aTmp
).isEmpty() )
224 Reference
<XIndexAccess
> xElements(xParent
, UNO_QUERY
);
225 sal_Int32 nCount
= xElements
->getCount();
228 Reference
<XPropertySet
> xFCSet
;
229 for( sal_Int32 nIndex
=0; nIndex
< nCount
; nIndex
++ )
231 // Any aElement(xElements->getByIndex(nIndex));
232 xElements
->getByIndex(nIndex
) >>= xFCSet
;
233 OSL_ENSURE(xFCSet
.is(),"OEditControl::keyPressed: No XPropertySet!");
235 if (hasProperty(PROPERTY_CLASSID
, xFCSet
) &&
236 getINT16(xFCSet
->getPropertyValue(PROPERTY_CLASSID
)) == FormComponentType::TEXTFIELD
)
238 // Found another Edit -> then do not submit!
245 // Because we're still in the header, trigger submit asynchronously
247 Application::RemoveUserEvent( m_nKeyEvent
);
248 m_nKeyEvent
= Application::PostUserEvent( LINK(this, OEditControl
,OnKeyPressed
) );
251 //------------------------------------------------------------------------------
252 void OEditControl::keyReleased(const ::com::sun::star::awt::KeyEvent
& /*e*/) throw ( ::com::sun::star::uno::RuntimeException
)
256 //------------------------------------------------------------------------------
257 IMPL_LINK(OEditControl
, OnKeyPressed
, void*, /*EMPTYARG*/)
261 Reference
<XFormComponent
> xFComp(getModel(), UNO_QUERY
);
262 InterfaceRef xParent
= xFComp
->getParent();
263 Reference
<XSubmit
> xSubmit(xParent
, UNO_QUERY
);
265 xSubmit
->submit( Reference
<XControl
>(), ::com::sun::star::awt::MouseEvent() );
269 //------------------------------------------------------------------
270 void SAL_CALL
OEditControl::createPeer( const Reference
< XToolkit
>& _rxToolkit
, const Reference
< XWindowPeer
>& _rxParent
) throw ( RuntimeException
)
272 OBoundControl::createPeer(_rxToolkit
, _rxParent
);
275 /*************************************************************************/
276 //------------------------------------------------------------------
277 InterfaceRef SAL_CALL
OEditModel_CreateInstance(const Reference
<XMultiServiceFactory
>& _rxFactory
)
279 return *(new OEditModel(_rxFactory
));
282 //------------------------------------------------------------------------------
283 Sequence
<Type
> OEditModel::_getTypes()
285 return OEditBaseModel::_getTypes();
289 DBG_NAME(OEditModel
);
290 //------------------------------------------------------------------
291 OEditModel::OEditModel(const Reference
<XMultiServiceFactory
>& _rxFactory
)
292 :OEditBaseModel( _rxFactory
, FRM_SUN_COMPONENT_RICHTEXTCONTROL
, FRM_SUN_CONTROL_TEXTFIELD
, sal_True
, sal_True
)
293 ,m_bMaxTextLenModified(sal_False
)
294 ,m_bWritingFormattedFake(sal_False
)
296 DBG_CTOR(OEditModel
,NULL
);
298 m_nClassId
= FormComponentType::TEXTFIELD
;
299 initValueProperty( PROPERTY_TEXT
, PROPERTY_ID_TEXT
);
302 //------------------------------------------------------------------
303 OEditModel::OEditModel( const OEditModel
* _pOriginal
, const Reference
<XMultiServiceFactory
>& _rxFactory
)
304 :OEditBaseModel( _pOriginal
, _rxFactory
)
305 ,m_bMaxTextLenModified(sal_False
)
306 ,m_bWritingFormattedFake(sal_False
)
308 DBG_CTOR( OEditModel
, NULL
);
310 // Note that most of the properties are not clone from the original object:
311 // Things as the format key, it's type, and such, depend on the field being part of a loaded form
312 // (they're initialized in onConnectedDbColumn). Even if the original object _is_ part of such a form, we ourself
313 // certainly aren't, so these members are defaulted. If we're inserted into a form which is already loaded,
314 // they will be set to new values, anyway ....
317 //------------------------------------------------------------------
318 OEditModel::~OEditModel()
320 if (!OComponentHelper::rBHelper
.bDisposed
)
326 DBG_DTOR(OEditModel
,NULL
);
329 //------------------------------------------------------------------------------
330 IMPLEMENT_DEFAULT_CLONING( OEditModel
)
332 //------------------------------------------------------------------------------
333 void OEditModel::disposing()
335 OEditBaseModel::disposing();
336 m_pValueFormatter
.reset();
340 //------------------------------------------------------------------------------
341 OUString SAL_CALL
OEditModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException
)
343 return OUString(FRM_COMPONENT_EDIT
); // old (non-sun) name for compatibility !
347 //------------------------------------------------------------------------------
348 StringSequence SAL_CALL
OEditModel::getSupportedServiceNames() throw()
350 StringSequence aSupported
= OBoundControlModel::getSupportedServiceNames();
352 sal_Int32 nOldLen
= aSupported
.getLength();
353 aSupported
.realloc( nOldLen
+ 8 );
354 OUString
* pStoreTo
= aSupported
.getArray() + nOldLen
;
356 *pStoreTo
++ = BINDABLE_CONTROL_MODEL
;
357 *pStoreTo
++ = DATA_AWARE_CONTROL_MODEL
;
358 *pStoreTo
++ = VALIDATABLE_CONTROL_MODEL
;
360 *pStoreTo
++ = BINDABLE_DATA_AWARE_CONTROL_MODEL
;
361 *pStoreTo
++ = VALIDATABLE_BINDABLE_CONTROL_MODEL
;
363 *pStoreTo
++ = FRM_SUN_COMPONENT_TEXTFIELD
;
364 *pStoreTo
++ = FRM_SUN_COMPONENT_DATABASE_TEXTFIELD
;
365 *pStoreTo
++ = BINDABLE_DATABASE_TEXT_FIELD
;
371 void SAL_CALL
OEditModel::getFastPropertyValue(Any
& rValue
, sal_Int32 nHandle
) const
373 if ( PROPERTY_ID_PERSISTENCE_MAXTEXTLENGTH
== nHandle
)
375 if ( m_bMaxTextLenModified
)
376 rValue
<<= sal_Int16(0);
377 else if ( m_xAggregateSet
.is() )
378 rValue
= m_xAggregateSet
->getPropertyValue(PROPERTY_MAXTEXTLEN
);
382 OEditBaseModel::getFastPropertyValue(rValue
, nHandle
);
386 //------------------------------------------------------------------------------
387 void OEditModel::describeFixedProperties( Sequence
< Property
>& _rProps
) const
389 BEGIN_DESCRIBE_PROPERTIES( 5, OEditBaseModel
)
390 DECL_PROP2(PERSISTENCE_MAXTEXTLENGTH
,sal_Int16
, READONLY
, TRANSIENT
);
391 DECL_PROP2(DEFAULT_TEXT
, OUString
, BOUND
, MAYBEDEFAULT
);
392 DECL_BOOL_PROP1(EMPTY_IS_NULL
, BOUND
);
393 DECL_PROP1(TABINDEX
, sal_Int16
, BOUND
);
394 DECL_BOOL_PROP2(FILTERPROPOSAL
, BOUND
, MAYBEDEFAULT
);
395 END_DESCRIBE_PROPERTIES();
398 //------------------------------------------------------------------------------
399 void OEditModel::describeAggregateProperties( Sequence
< Property
>& _rAggregateProps
) const
401 OEditBaseModel::describeAggregateProperties( _rAggregateProps
);
403 // our aggregate is a rich text model, which also derives from OControlModel, as
404 // do we, so we need to remove some duplicate properties
405 RemoveProperty( _rAggregateProps
, PROPERTY_TABINDEX
);
406 RemoveProperty( _rAggregateProps
, PROPERTY_CLASSID
);
407 RemoveProperty( _rAggregateProps
, PROPERTY_NAME
);
408 RemoveProperty( _rAggregateProps
, PROPERTY_TAG
);
409 RemoveProperty( _rAggregateProps
, PROPERTY_NATIVE_LOOK
);
413 //------------------------------------------------------------------------------
414 bool OEditModel::implActsAsRichText( ) const
416 sal_Bool bActAsRichText
= sal_False
;
417 if ( m_xAggregateSet
.is() )
419 OSL_VERIFY( m_xAggregateSet
->getPropertyValue( PROPERTY_RICH_TEXT
) >>= bActAsRichText
);
421 return bActAsRichText
;
424 //------------------------------------------------------------------------------
425 void SAL_CALL
OEditModel::reset( ) throw(RuntimeException
)
427 // no reset if we currently act as rich text control
428 if ( implActsAsRichText() )
431 OEditBaseModel::reset();
434 //------------------------------------------------------------------------------
437 void lcl_transferProperties( const Reference
< XPropertySet
>& _rxSource
, const Reference
< XPropertySet
>& _rxDest
)
441 Reference
< XPropertySetInfo
> xSourceInfo
;
442 if ( _rxSource
.is() )
443 xSourceInfo
= _rxSource
->getPropertySetInfo();
445 Reference
< XPropertySetInfo
> xDestInfo
;
447 xDestInfo
= _rxDest
->getPropertySetInfo();
449 if ( !xSourceInfo
.is() || !xDestInfo
.is() )
451 OSL_FAIL( "lcl_transferProperties: invalid property set(s)!" );
455 Sequence
< Property
> aSourceProps( xSourceInfo
->getProperties() );
456 const Property
* pSourceProps
= aSourceProps
.getConstArray();
457 const Property
* pSourcePropsEnd
= aSourceProps
.getConstArray() + aSourceProps
.getLength();
458 while ( pSourceProps
!= pSourcePropsEnd
)
460 if ( !xDestInfo
->hasPropertyByName( pSourceProps
->Name
) )
466 Property
aDestProp( xDestInfo
->getPropertyByName( pSourceProps
->Name
) );
467 if ( 0 != ( aDestProp
.Attributes
& PropertyAttribute::READONLY
) )
475 _rxDest
->setPropertyValue( pSourceProps
->Name
, _rxSource
->getPropertyValue( pSourceProps
->Name
) );
477 catch(const IllegalArgumentException
& e
)
479 #if OSL_DEBUG_LEVEL > 0
480 OString
sMessage( "could not transfer the property named '" );
481 sMessage
+= OString( pSourceProps
->Name
.getStr(), pSourceProps
->Name
.getLength(), RTL_TEXTENCODING_ASCII_US
);
482 sMessage
+= OString( "'." );
483 if ( !e
.Message
.isEmpty() )
485 sMessage
+= OString( "\n\nMessage:\n" );
486 sMessage
+= OString( e
.Message
.getStr(), e
.Message
.getLength(), RTL_TEXTENCODING_ASCII_US
);
488 OSL_FAIL( sMessage
.getStr() );
497 catch( const Exception
& )
499 DBG_UNHANDLED_EXCEPTION();
504 //------------------------------------------------------------------------------
505 void OEditModel::writeAggregate( const Reference
< XObjectOutputStream
>& _rxOutStream
) const
507 // we need to fake the writing of our aggregate. Since #i24387#, we have another aggregate,
508 // but for compatibility, we need to use an "old" aggregate for writing and reading
510 Reference
< XPropertySet
> xFakedAggregate(
511 getContext().createComponent( (OUString
)VCL_CONTROLMODEL_EDIT
),
514 OSL_ENSURE( xFakedAggregate
.is(), "OEditModel::writeAggregate: could not create an old EditControlModel!" );
515 if ( !xFakedAggregate
.is() )
518 lcl_transferProperties( m_xAggregateSet
, xFakedAggregate
);
520 Reference
< XPersistObject
> xFakedPersist( xFakedAggregate
, UNO_QUERY
);
521 OSL_ENSURE( xFakedPersist
.is(), "OEditModel::writeAggregate: no XPersistObject!" );
522 if ( xFakedPersist
.is() )
523 xFakedPersist
->write( _rxOutStream
);
526 //------------------------------------------------------------------------------
527 void OEditModel::readAggregate( const Reference
< XObjectInputStream
>& _rxInStream
)
529 // we need to fake the reading of our aggregate. Since #i24387#, we have another aggregate,
530 // but for compatibility, we need to use an "old" aggregate for writing and reading
532 Reference
< XPropertySet
> xFakedAggregate(
533 getContext().createComponent( (OUString
)VCL_CONTROLMODEL_EDIT
),
536 Reference
< XPersistObject
> xFakedPersist( xFakedAggregate
, UNO_QUERY
);
537 OSL_ENSURE( xFakedPersist
.is(), "OEditModel::readAggregate: no XPersistObject, or no faked aggregate at all!" );
538 if ( xFakedPersist
.is() )
540 xFakedPersist
->read( _rxInStream
);
541 lcl_transferProperties( xFakedAggregate
, m_xAggregateSet
);
545 //------------------------------------------------------------------------------
546 void OEditModel::write(const Reference
<XObjectOutputStream
>& _rxOutStream
) throw ( ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
)
549 sal_Int16 nOldTextLen
= 0;
550 // Am I loaded at the moment and did I switch MaxTextLen temporarily?
551 if ( m_bMaxTextLenModified
)
552 { // -> for the duration of saving, make my aggregated model believe the old TextLen
554 // before doing this we have to save the current text value of the aggregate, as this may be affected by resetting the text len
555 aCurrentText
= m_xAggregateSet
->getPropertyValue(PROPERTY_TEXT
);
557 m_xAggregateSet
->getPropertyValue(PROPERTY_MAXTEXTLEN
) >>= nOldTextLen
;
558 m_xAggregateSet
->setPropertyValue(PROPERTY_MAXTEXTLEN
, makeAny((sal_Int16
)0));
561 OEditBaseModel::write(_rxOutStream
);
563 if ( m_bMaxTextLenModified
)
565 m_xAggregateSet
->setPropertyValue(PROPERTY_MAXTEXTLEN
, makeAny(nOldTextLen
));
566 // and reset the text
567 // First we set it to an empty string : Without this the second setPropertyValue would not do anything as it thinks
568 // we aren't changing the prop (it didn't notify the - implicite - change of the text prop while setting the max text len)
569 // This seems to be a bug with in toolkit's EditControl-implementation.
570 m_xAggregateSet
->setPropertyValue(PROPERTY_TEXT
, makeAny(OUString()));
571 m_xAggregateSet
->setPropertyValue(PROPERTY_TEXT
, aCurrentText
);
575 //------------------------------------------------------------------------------
576 void OEditModel::read(const Reference
<XObjectInputStream
>& _rxInStream
) throw ( ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
)
578 OEditBaseModel::read(_rxInStream
);
580 // Some versions (5.1 'til about 552) wrote a wrong DefaultControl-property value which is unknown
581 // to older versions (5.0).
583 if (m_xAggregateSet
.is())
585 Any aDefaultControl
= m_xAggregateSet
->getPropertyValue(PROPERTY_DEFAULTCONTROL
);
586 if ( (aDefaultControl
.getValueType().getTypeClass() == TypeClass_STRING
)
587 && (getString(aDefaultControl
) == STARDIV_ONE_FORM_CONTROL_TEXTFIELD
)
590 m_xAggregateSet
->setPropertyValue( PROPERTY_DEFAULTCONTROL
, makeAny( (OUString
)STARDIV_ONE_FORM_CONTROL_EDIT
) );
591 // Older as well as current versions should understand this : the former knew only the STARDIV_ONE_FORM_CONTROL_EDIT,
592 // the latter are registered for both STARDIV_ONE_FORM_CONTROL_EDIT and STARDIV_ONE_FORM_CONTROL_TEXTFIELD.
597 //------------------------------------------------------------------------------
598 sal_uInt16
OEditModel::getPersistenceFlags() const
600 sal_uInt16 nFlags
= OEditBaseModel::getPersistenceFlags();
602 if (m_bWritingFormattedFake
)
603 nFlags
|= PF_FAKE_FORMATTED_FIELD
;
608 //------------------------------------------------------------------------------
609 void OEditModel::onConnectedDbColumn( const Reference
< XInterface
>& _rxForm
)
611 Reference
< XPropertySet
> xField
= getField();
614 m_pValueFormatter
.reset( new ::dbtools::FormattedColumnValue( getContext(), Reference
< XRowSet
>( _rxForm
, UNO_QUERY
), xField
) );
616 if ( m_pValueFormatter
->getKeyType() != NumberFormat::SCIENTIFIC
)
618 m_bMaxTextLenModified
= getINT16(m_xAggregateSet
->getPropertyValue(PROPERTY_MAXTEXTLEN
)) != 0;
619 if ( !m_bMaxTextLenModified
)
621 sal_Int32 nFieldLen
= 0;
622 xField
->getPropertyValue(OUString("Precision") ) >>= nFieldLen
;
624 if (nFieldLen
&& nFieldLen
<= USHRT_MAX
)
627 aVal
<<= (sal_Int16
)nFieldLen
;
628 m_xAggregateSet
->setPropertyValue(PROPERTY_MAXTEXTLEN
, aVal
);
630 m_bMaxTextLenModified
= sal_True
;
634 m_bMaxTextLenModified
= sal_False
; // to get sure that the text len won't be set in unloaded
639 //------------------------------------------------------------------------------
640 void OEditModel::onDisconnectedDbColumn()
642 OEditBaseModel::onDisconnectedDbColumn();
644 m_pValueFormatter
.reset();
646 if ( hasField() && m_bMaxTextLenModified
)
649 aVal
<<= (sal_Int16
)0; // Only if it was 0, I switched it in onConnectedDbColumn
650 m_xAggregateSet
->setPropertyValue(PROPERTY_MAXTEXTLEN
, aVal
);
651 m_bMaxTextLenModified
= sal_False
;
655 //------------------------------------------------------------------------------
656 sal_Bool
OEditModel::approveDbColumnType( sal_Int32 _nColumnType
)
658 // if we act as rich text currently, we do not allow binding to a database column
659 if ( implActsAsRichText() )
662 return OEditBaseModel::approveDbColumnType( _nColumnType
);
665 //------------------------------------------------------------------------------
666 void OEditModel::resetNoBroadcast()
668 OEditBaseModel::resetNoBroadcast();
671 //------------------------------------------------------------------------------
672 sal_Bool
OEditModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
674 Any
aNewValue( m_xAggregateFastSet
->getFastPropertyValue( getValuePropertyAggHandle() ) );
677 aNewValue
>>= sNewValue
;
679 if ( !aNewValue
.hasValue()
680 || ( sNewValue
.isEmpty() // an empty string
681 && m_bEmptyIsNull
// which should be interpreted as NULL
685 m_xColumnUpdate
->updateNull();
689 OSL_PRECOND( m_pValueFormatter
.get(), "OEditModel::commitControlValueToDbColumn: no value formatter!" );
692 if ( m_pValueFormatter
.get() )
694 if ( !m_pValueFormatter
->setFormattedValue( sNewValue
) )
698 m_xColumnUpdate
->updateString( sNewValue
);
700 catch ( const Exception
& )
709 //------------------------------------------------------------------------------
710 Any
OEditModel::translateDbColumnToControlValue()
712 OSL_PRECOND( m_pValueFormatter
.get(), "OEditModel::translateDbColumnToControlValue: no value formatter!" );
714 if ( m_pValueFormatter
.get() )
716 OUString
sValue( m_pValueFormatter
->getFormattedValue() );
717 if ( sValue
.isEmpty()
718 && m_pValueFormatter
->getColumn().is()
719 && m_pValueFormatter
->getColumn()->wasNull()
726 sal_uInt16 nMaxTextLen
= getINT16( m_xAggregateSet
->getPropertyValue( PROPERTY_MAXTEXTLEN
) );
727 if ( nMaxTextLen
&& sValue
.getLength() > nMaxTextLen
)
729 sal_Int32 nDiff
= sValue
.getLength() - nMaxTextLen
;
730 sValue
= sValue
.replaceAt( nMaxTextLen
, nDiff
, OUString() );
737 return aRet
.hasValue() ? aRet
: makeAny( OUString() );
740 //------------------------------------------------------------------------------
741 Any
OEditModel::getDefaultForReset() const
743 return makeAny( m_aDefaultText
);
746 //.........................................................................
748 //.........................................................................
750 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */