bump product version to 5.0.4.1
[LibreOffice.git] / forms / source / component / Edit.cxx
blobd52353dfbe505ee19b9ed8b50774906513b6d1a4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include "Edit.hxx"
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 <vcl/keycodes.hxx>
33 #include <tools/wintypes.hxx>
35 #include <connectivity/dbtools.hxx>
36 #include <connectivity/formattedcolumnvalue.hxx>
37 #include <connectivity/dbconversion.hxx>
39 #include <tools/diagnose_ex.h>
41 #include <comphelper/container.hxx>
42 #include <comphelper/numbers.hxx>
43 #include <comphelper/processfactory.hxx>
45 using namespace dbtools;
47 namespace frm
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;
63 Sequence<Type> OEditControl::_getTypes()
65 static Sequence<Type> aTypes;
66 if (!aTypes.getLength())
68 // my two base classes
69 aTypes = concatSequences(OBoundControl::_getTypes(), OEditControl_BASE::getTypes());
71 return aTypes;
75 Any SAL_CALL OEditControl::queryAggregation(const Type& _rType) throw (RuntimeException, std::exception)
77 Any aReturn = OBoundControl::queryAggregation(_rType);
78 if (!aReturn.hasValue())
79 aReturn = OEditControl_BASE::queryInterface(_rType);
81 return aReturn;
85 OEditControl::OEditControl(const Reference<XComponentContext>& _rxFactory)
86 :OBoundControl( _rxFactory, FRM_SUN_CONTROL_RICHTEXTCONTROL )
87 ,m_aChangeListeners(m_aMutex)
88 ,m_nKeyEvent( 0 )
91 osl_atomic_increment(&m_refCount);
93 Reference<XWindow> xComp;
94 if (query_aggregation(m_xAggregate, xComp))
96 xComp->addFocusListener(this);
97 xComp->addKeyListener(this);
100 osl_atomic_decrement(&m_refCount);
104 OEditControl::~OEditControl()
106 if( m_nKeyEvent )
107 Application::RemoveUserEvent( m_nKeyEvent );
109 if (!OComponentHelper::rBHelper.bDisposed)
111 acquire();
112 dispose();
117 // XChangeBroadcaster
119 void OEditControl::addChangeListener(const Reference<XChangeListener>& l) throw ( ::com::sun::star::uno::RuntimeException, std::exception)
121 m_aChangeListeners.addInterface( l );
125 void OEditControl::removeChangeListener(const Reference<XChangeListener>& l) throw ( ::com::sun::star::uno::RuntimeException, std::exception)
127 m_aChangeListeners.removeInterface( l );
130 // OComponentHelper
132 void OEditControl::disposing()
134 OBoundControl::disposing();
136 EventObject aEvt(static_cast<XWeak*>(this));
137 m_aChangeListeners.disposeAndClear(aEvt);
140 // XServiceInfo
142 StringSequence OEditControl::getSupportedServiceNames() throw(std::exception)
144 StringSequence aSupported = OBoundControl::getSupportedServiceNames();
145 aSupported.realloc(aSupported.getLength() + 3);
147 OUString*pArray = aSupported.getArray();
148 pArray[aSupported.getLength()-3] = FRM_SUN_CONTROL_TEXTFIELD;
149 pArray[aSupported.getLength()-2] = STARDIV_ONE_FORM_CONTROL_EDIT;
150 pArray[aSupported.getLength()-1] = STARDIV_ONE_FORM_CONTROL_TEXTFIELD;
151 return aSupported;
154 // XEventListener
156 void OEditControl::disposing(const EventObject& Source) throw( RuntimeException, std::exception )
158 OBoundControl::disposing(Source);
161 // XFocusListener
163 void OEditControl::focusGained( const FocusEvent& /*e*/ ) throw ( ::com::sun::star::uno::RuntimeException, std::exception)
165 Reference<XPropertySet> xSet(getModel(), UNO_QUERY);
166 if (xSet.is())
167 xSet->getPropertyValue( PROPERTY_TEXT ) >>= m_aHtmlChangeValue;
171 void OEditControl::focusLost( const FocusEvent& /*e*/ ) throw ( ::com::sun::star::uno::RuntimeException, std::exception)
173 Reference<XPropertySet> xSet(getModel(), UNO_QUERY);
174 if (xSet.is())
176 OUString sNewHtmlChangeValue;
177 xSet->getPropertyValue( PROPERTY_TEXT ) >>= sNewHtmlChangeValue;
178 if( sNewHtmlChangeValue != m_aHtmlChangeValue )
180 EventObject aEvt( *this );
181 m_aChangeListeners.notifyEach( &XChangeListener::changed, aEvt );
186 // XKeyListener
188 void OEditControl::keyPressed(const ::com::sun::star::awt::KeyEvent& e) throw ( ::com::sun::star::uno::RuntimeException, std::exception)
190 if( e.KeyCode != KEY_RETURN || e.Modifiers != 0 )
191 return;
193 // Is the Control in a form with a submit URL?
194 Reference<XPropertySet> xSet(getModel(), UNO_QUERY);
195 if( !xSet.is() )
196 return;
198 // Not for multiline edits
199 Any aTmp( xSet->getPropertyValue(PROPERTY_MULTILINE));
200 if ((aTmp.getValueType().equals(cppu::UnoType<bool>::get())) && getBOOL(aTmp))
201 return;
203 Reference<XFormComponent> xFComp(xSet, UNO_QUERY);
204 InterfaceRef xParent = xFComp->getParent();
205 if( !xParent.is() )
206 return;
208 Reference<XPropertySet> xFormSet(xParent, UNO_QUERY);
209 if( !xFormSet.is() )
210 return;
212 aTmp = xFormSet->getPropertyValue( PROPERTY_TARGET_URL );
213 if (!aTmp.getValueType().equals(cppu::UnoType<OUString>::get()) ||
214 getString(aTmp).isEmpty() )
215 return;
217 Reference<XIndexAccess> xElements(xParent, UNO_QUERY);
218 sal_Int32 nCount = xElements->getCount();
219 if( nCount > 1 )
221 Reference<XPropertySet> xFCSet;
222 for( sal_Int32 nIndex=0; nIndex < nCount; nIndex++ )
224 // Any aElement(xElements->getByIndex(nIndex));
225 xElements->getByIndex(nIndex) >>= xFCSet;
226 OSL_ENSURE(xFCSet.is(),"OEditControl::keyPressed: No XPropertySet!");
228 if (hasProperty(PROPERTY_CLASSID, xFCSet) &&
229 getINT16(xFCSet->getPropertyValue(PROPERTY_CLASSID)) == FormComponentType::TEXTFIELD)
231 // Found another Edit -> then do not submit!
232 if (xFCSet != xSet)
233 return;
238 // Because we're still in the header, trigger submit asynchronously
239 if( m_nKeyEvent )
240 Application::RemoveUserEvent( m_nKeyEvent );
241 m_nKeyEvent = Application::PostUserEvent( LINK(this, OEditControl,OnKeyPressed) );
245 void OEditControl::keyReleased(const ::com::sun::star::awt::KeyEvent& /*e*/) throw ( ::com::sun::star::uno::RuntimeException, std::exception)
250 IMPL_LINK_NOARG(OEditControl, OnKeyPressed)
252 m_nKeyEvent = 0;
254 Reference<XFormComponent> xFComp(getModel(), UNO_QUERY);
255 InterfaceRef xParent = xFComp->getParent();
256 Reference<XSubmit> xSubmit(xParent, UNO_QUERY);
257 if (xSubmit.is())
258 xSubmit->submit( Reference<XControl>(), ::com::sun::star::awt::MouseEvent() );
259 return 0L;
263 void SAL_CALL OEditControl::createPeer( const Reference< XToolkit>& _rxToolkit, const Reference< XWindowPeer>& _rxParent ) throw ( RuntimeException, std::exception )
265 OBoundControl::createPeer(_rxToolkit, _rxParent);
269 Sequence<Type> OEditModel::_getTypes()
271 return OEditBaseModel::_getTypes();
276 OEditModel::OEditModel(const Reference<XComponentContext>& _rxFactory)
277 :OEditBaseModel( _rxFactory, FRM_SUN_COMPONENT_RICHTEXTCONTROL, FRM_SUN_CONTROL_TEXTFIELD, true, true )
278 ,m_bMaxTextLenModified(false)
279 ,m_bWritingFormattedFake(false)
282 m_nClassId = FormComponentType::TEXTFIELD;
283 initValueProperty( PROPERTY_TEXT, PROPERTY_ID_TEXT );
287 OEditModel::OEditModel( const OEditModel* _pOriginal, const Reference<XComponentContext>& _rxFactory )
288 :OEditBaseModel( _pOriginal, _rxFactory )
289 ,m_bMaxTextLenModified(false)
290 ,m_bWritingFormattedFake(false)
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 ....
301 OEditModel::~OEditModel()
303 if (!OComponentHelper::rBHelper.bDisposed)
305 acquire();
306 dispose();
312 IMPLEMENT_DEFAULT_CLONING( OEditModel )
315 void OEditModel::disposing()
317 OEditBaseModel::disposing();
318 m_pValueFormatter.reset();
321 // XPersistObject
323 OUString SAL_CALL OEditModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException, std::exception)
325 return OUString(FRM_COMPONENT_EDIT); // old (non-sun) name for compatibility !
328 // XServiceInfo
330 StringSequence SAL_CALL OEditModel::getSupportedServiceNames() throw(std::exception)
332 StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
334 sal_Int32 nOldLen = aSupported.getLength();
335 aSupported.realloc( nOldLen + 9 );
336 OUString* pStoreTo = aSupported.getArray() + nOldLen;
338 *pStoreTo++ = BINDABLE_CONTROL_MODEL;
339 *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
340 *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
342 *pStoreTo++ = BINDABLE_DATA_AWARE_CONTROL_MODEL;
343 *pStoreTo++ = VALIDATABLE_BINDABLE_CONTROL_MODEL;
345 *pStoreTo++ = FRM_SUN_COMPONENT_TEXTFIELD;
346 *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_TEXTFIELD;
347 *pStoreTo++ = BINDABLE_DATABASE_TEXT_FIELD;
349 *pStoreTo++ = FRM_COMPONENT_TEXTFIELD;
351 return aSupported;
354 // XPropertySet
355 void SAL_CALL OEditModel::getFastPropertyValue(Any& rValue, sal_Int32 nHandle ) const
357 if ( PROPERTY_ID_PERSISTENCE_MAXTEXTLENGTH == nHandle )
359 if ( m_bMaxTextLenModified )
360 rValue <<= sal_Int16(0);
361 else if ( m_xAggregateSet.is() )
362 rValue = m_xAggregateSet->getPropertyValue(PROPERTY_MAXTEXTLEN);
364 else
366 OEditBaseModel::getFastPropertyValue(rValue, nHandle );
371 void OEditModel::describeFixedProperties( Sequence< Property >& _rProps ) const
373 BEGIN_DESCRIBE_PROPERTIES( 5, OEditBaseModel )
374 DECL_PROP2(PERSISTENCE_MAXTEXTLENGTH,sal_Int16, READONLY, TRANSIENT);
375 DECL_PROP2(DEFAULT_TEXT, OUString, BOUND, MAYBEDEFAULT);
376 DECL_BOOL_PROP1(EMPTY_IS_NULL, BOUND);
377 DECL_PROP1(TABINDEX, sal_Int16, BOUND);
378 DECL_BOOL_PROP2(FILTERPROPOSAL, BOUND, MAYBEDEFAULT);
379 END_DESCRIBE_PROPERTIES();
383 void OEditModel::describeAggregateProperties( Sequence< Property >& _rAggregateProps ) const
385 OEditBaseModel::describeAggregateProperties( _rAggregateProps );
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 RemoveProperty( _rAggregateProps, PROPERTY_TABINDEX );
390 RemoveProperty( _rAggregateProps, PROPERTY_CLASSID );
391 RemoveProperty( _rAggregateProps, PROPERTY_NAME );
392 RemoveProperty( _rAggregateProps, PROPERTY_TAG );
393 RemoveProperty( _rAggregateProps, PROPERTY_NATIVE_LOOK );
398 bool OEditModel::implActsAsRichText( ) const
400 bool bActAsRichText = false;
401 if ( m_xAggregateSet.is() )
403 OSL_VERIFY( m_xAggregateSet->getPropertyValue( PROPERTY_RICH_TEXT ) >>= bActAsRichText );
405 return bActAsRichText;
409 void SAL_CALL OEditModel::reset( ) throw(RuntimeException, std::exception)
411 // no reset if we currently act as rich text control
412 if ( implActsAsRichText() )
413 return;
415 OEditBaseModel::reset();
419 namespace
421 void lcl_transferProperties( const Reference< XPropertySet >& _rxSource, const Reference< XPropertySet >& _rxDest )
425 Reference< XPropertySetInfo > xSourceInfo;
426 if ( _rxSource.is() )
427 xSourceInfo = _rxSource->getPropertySetInfo();
429 Reference< XPropertySetInfo > xDestInfo;
430 if ( _rxDest.is() )
431 xDestInfo = _rxDest->getPropertySetInfo();
433 if ( !xSourceInfo.is() || !xDestInfo.is() )
435 OSL_FAIL( "lcl_transferProperties: invalid property set(s)!" );
436 return;
439 Sequence< Property > aSourceProps( xSourceInfo->getProperties() );
440 const Property* pSourceProps = aSourceProps.getConstArray();
441 const Property* pSourcePropsEnd = aSourceProps.getConstArray() + aSourceProps.getLength();
442 while ( pSourceProps != pSourcePropsEnd )
444 if ( !xDestInfo->hasPropertyByName( pSourceProps->Name ) )
446 ++pSourceProps;
447 continue;
450 Property aDestProp( xDestInfo->getPropertyByName( pSourceProps->Name ) );
451 if ( 0 != ( aDestProp.Attributes & PropertyAttribute::READONLY ) )
453 ++pSourceProps;
454 continue;
459 _rxDest->setPropertyValue( pSourceProps->Name, _rxSource->getPropertyValue( pSourceProps->Name ) );
461 catch(const IllegalArgumentException& e)
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() )
469 sMessage += OString( "\n\nMessage:\n" );
470 sMessage += OString( e.Message.getStr(), e.Message.getLength(), RTL_TEXTENCODING_ASCII_US );
472 OSL_FAIL( sMessage.getStr() );
473 #else
474 (void)e;
475 #endif
478 ++pSourceProps;
481 catch( const Exception& )
483 DBG_UNHANDLED_EXCEPTION();
489 void OEditModel::writeAggregate( const Reference< XObjectOutputStream >& _rxOutStream ) const
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
494 Reference< XPropertySet > xFakedAggregate(
495 getContext()->getServiceManager()->createInstanceWithContext( OUString(VCL_CONTROLMODEL_EDIT), getContext() ),
496 UNO_QUERY
498 OSL_ENSURE( xFakedAggregate.is(), "OEditModel::writeAggregate: could not create an old EditControlModel!" );
499 if ( !xFakedAggregate.is() )
500 return;
502 lcl_transferProperties( m_xAggregateSet, xFakedAggregate );
504 Reference< XPersistObject > xFakedPersist( xFakedAggregate, UNO_QUERY );
505 OSL_ENSURE( xFakedPersist.is(), "OEditModel::writeAggregate: no XPersistObject!" );
506 if ( xFakedPersist.is() )
507 xFakedPersist->write( _rxOutStream );
511 void OEditModel::readAggregate( const Reference< XObjectInputStream >& _rxInStream )
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
516 Reference< XPropertySet > xFakedAggregate(
517 getContext()->getServiceManager()->createInstanceWithContext( OUString(VCL_CONTROLMODEL_EDIT), getContext() ),
518 UNO_QUERY
520 Reference< XPersistObject > xFakedPersist( xFakedAggregate, UNO_QUERY );
521 OSL_ENSURE( xFakedPersist.is(), "OEditModel::readAggregate: no XPersistObject, or no faked aggregate at all!" );
522 if ( xFakedPersist.is() )
524 xFakedPersist->read( _rxInStream );
525 lcl_transferProperties( xFakedAggregate, m_xAggregateSet );
530 void OEditModel::write(const Reference<XObjectOutputStream>& _rxOutStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception)
532 Any aCurrentText;
533 sal_Int16 nOldTextLen = 0;
534 // Am I loaded at the moment and did I switch MaxTextLen temporarily?
535 if ( m_bMaxTextLenModified )
536 { // -> for the duration of saving, make my aggregated model believe the old TextLen
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 aCurrentText = m_xAggregateSet->getPropertyValue(PROPERTY_TEXT);
541 m_xAggregateSet->getPropertyValue(PROPERTY_MAXTEXTLEN) >>= nOldTextLen;
542 m_xAggregateSet->setPropertyValue(PROPERTY_MAXTEXTLEN, makeAny((sal_Int16)0));
545 OEditBaseModel::write(_rxOutStream);
547 if ( m_bMaxTextLenModified )
548 { // Reset again
549 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 m_xAggregateSet->setPropertyValue(PROPERTY_TEXT, makeAny(OUString()));
555 m_xAggregateSet->setPropertyValue(PROPERTY_TEXT, aCurrentText);
560 void OEditModel::read(const Reference<XObjectInputStream>& _rxInStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception)
562 OEditBaseModel::read(_rxInStream);
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 if (m_xAggregateSet.is())
569 Any aDefaultControl = m_xAggregateSet->getPropertyValue(PROPERTY_DEFAULTCONTROL);
570 if ( (aDefaultControl.getValueType().getTypeClass() == TypeClass_STRING)
571 && (getString(aDefaultControl) == STARDIV_ONE_FORM_CONTROL_TEXTFIELD )
574 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.
582 sal_uInt16 OEditModel::getPersistenceFlags() const
584 sal_uInt16 nFlags = OEditBaseModel::getPersistenceFlags();
586 if (m_bWritingFormattedFake)
587 nFlags |= PF_FAKE_FORMATTED_FIELD;
589 return nFlags;
593 void OEditModel::onConnectedDbColumn( const Reference< XInterface >& _rxForm )
595 Reference< XPropertySet > xField = getField();
596 if ( xField.is() )
598 m_pValueFormatter.reset( new ::dbtools::FormattedColumnValue( getContext(), Reference< XRowSet >( _rxForm, UNO_QUERY ), xField ) );
600 if ( m_pValueFormatter->getKeyType() != NumberFormat::SCIENTIFIC )
602 m_bMaxTextLenModified = getINT16(m_xAggregateSet->getPropertyValue(PROPERTY_MAXTEXTLEN)) != 0;
603 if ( !m_bMaxTextLenModified )
605 sal_Int32 nFieldLen = 0;
606 xField->getPropertyValue("Precision") >>= nFieldLen;
608 if (nFieldLen && nFieldLen <= USHRT_MAX)
610 Any aVal;
611 aVal <<= (sal_Int16)nFieldLen;
612 m_xAggregateSet->setPropertyValue(PROPERTY_MAXTEXTLEN, aVal);
614 m_bMaxTextLenModified = true;
617 else
618 m_bMaxTextLenModified = false; // to get sure that the text len won't be set in unloaded
624 void OEditModel::onDisconnectedDbColumn()
626 OEditBaseModel::onDisconnectedDbColumn();
628 m_pValueFormatter.reset();
630 if ( hasField() && m_bMaxTextLenModified )
632 Any aVal;
633 aVal <<= (sal_Int16)0; // Only if it was 0, I switched it in onConnectedDbColumn
634 m_xAggregateSet->setPropertyValue(PROPERTY_MAXTEXTLEN, aVal);
635 m_bMaxTextLenModified = false;
640 bool OEditModel::approveDbColumnType( sal_Int32 _nColumnType )
642 // if we act as rich text currently, we do not allow binding to a database column
643 if ( implActsAsRichText() )
644 return false;
646 return OEditBaseModel::approveDbColumnType( _nColumnType );
650 void OEditModel::resetNoBroadcast()
652 OEditBaseModel::resetNoBroadcast();
656 bool OEditModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
658 Any aNewValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
660 OUString sNewValue;
661 aNewValue >>= sNewValue;
663 if ( !aNewValue.hasValue()
664 || ( sNewValue.isEmpty() // an empty string
665 && m_bEmptyIsNull // which should be interpreted as NULL
669 m_xColumnUpdate->updateNull();
671 else
673 OSL_PRECOND( m_pValueFormatter.get(), "OEditModel::commitControlValueToDbColumn: no value formatter!" );
676 if ( m_pValueFormatter.get() )
678 if ( !m_pValueFormatter->setFormattedValue( sNewValue ) )
679 return false;
681 else
682 m_xColumnUpdate->updateString( sNewValue );
684 catch ( const Exception& )
686 return false;
690 return true;
694 Any OEditModel::translateDbColumnToControlValue()
696 OSL_PRECOND( m_pValueFormatter.get(), "OEditModel::translateDbColumnToControlValue: no value formatter!" );
697 Any aRet;
698 if ( m_pValueFormatter.get() )
700 OUString sValue( m_pValueFormatter->getFormattedValue() );
701 if ( sValue.isEmpty()
702 && m_pValueFormatter->getColumn().is()
703 && m_pValueFormatter->getColumn()->wasNull()
707 else
709 // #i2817# OJ
710 sal_uInt16 nMaxTextLen = getINT16( m_xAggregateSet->getPropertyValue( PROPERTY_MAXTEXTLEN ) );
711 if ( nMaxTextLen && sValue.getLength() > nMaxTextLen )
713 sal_Int32 nDiff = sValue.getLength() - nMaxTextLen;
714 sValue = sValue.replaceAt( nMaxTextLen, nDiff, OUString() );
717 aRet <<= sValue;
721 return aRet.hasValue() ? aRet : makeAny( OUString() );
725 Any OEditModel::getDefaultForReset() const
727 return makeAny( m_aDefaultText );
732 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
733 com_sun_star_form_OEditModel_get_implementation(::com::sun::star::uno::XComponentContext* component,
734 ::com::sun::star::uno::Sequence<css::uno::Any> const &)
736 return cppu::acquire(new frm::OEditModel(component));
739 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
740 com_sun_star_form_OEditControl_get_implementation(::com::sun::star::uno::XComponentContext* component,
741 ::com::sun::star::uno::Sequence<css::uno::Any> const &)
743 return cppu::acquire(new frm::OEditControl(component));
746 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */