25#include <com/sun/star/beans/PropertyAttribute.hpp>
26#include <com/sun/star/form/FormComponentType.hpp>
27#include <com/sun/star/uno/Type.hxx>
28#include <com/sun/star/awt/XWindow.hpp>
29#include <com/sun/star/container/XIndexAccess.hpp>
30#include <com/sun/star/form/XSubmit.hpp>
31#include <com/sun/star/util/NumberFormat.hpp>
58using namespace ::com::sun::star::form::binding;
72 if (!aReturn.hasValue())
82 ,m_nKeyEvent( nullptr )
87 Reference<XWindow> xComp;
90 xComp->addFocusListener(
this);
91 xComp->addKeyListener(
this);
103 if (!OComponentHelper::rBHelper.bDisposed)
130 EventObject aEvt(
static_cast<XWeak*
>(
this));
139 aSupported.realloc(aSupported.getLength() + 3);
141 OUString*pArray = aSupported.getArray();
159 Reference<XPropertySet> xSet(
getModel(), UNO_QUERY);
167 Reference<XPropertySet> xSet(
getModel(), UNO_QUERY);
170 OUString sNewHtmlChangeValue;
171 xSet->getPropertyValue(
PROPERTY_TEXT ) >>= sNewHtmlChangeValue;
174 EventObject aEvt( *
this );
184 if( e.KeyCode !=
KEY_RETURN || e.Modifiers != 0 )
188 Reference<XPropertySet> xSet(
getModel(), UNO_QUERY);
197 Reference<XFormComponent> xFComp(xSet, UNO_QUERY);
198 css::uno::Reference<css::uno::XInterface> xParent = xFComp->getParent();
202 Reference<XPropertySet> xFormSet(xParent, UNO_QUERY);
211 Reference<XIndexAccess> xElements(xParent, UNO_QUERY);
212 sal_Int32
nCount = xElements->getCount();
215 Reference<XPropertySet> xFCSet;
219 xElements->getByIndex(
nIndex) >>= xFCSet;
220 OSL_ENSURE(xFCSet.is(),
"OEditControl::keyPressed: No XPropertySet!");
246 m_nKeyEvent =
nullptr;
248 Reference<XFormComponent> xFComp(getModel(), UNO_QUERY);
249 css::uno::Reference<css::uno::XInterface> xParent = xFComp->getParent();
250 Reference<XSubmit> xSubmit(xParent, UNO_QUERY);
252 xSubmit->submit( Reference<XControl>(), css::awt::MouseEvent() );
259 ,m_bMaxTextLenModified(false)
260 ,m_bWritingFormattedFake(false)
263 m_nClassId = FormComponentType::TEXTFIELD;
268OEditModel::OEditModel(
const OEditModel* _pOriginal,
const Reference<XComponentContext>& _rxFactory )
269 :OEditBaseModel( _pOriginal, _rxFactory )
270 ,m_bMaxTextLenModified(false)
271 ,m_bWritingFormattedFake(false)
282OEditModel::~OEditModel()
284 if (!OComponentHelper::rBHelper.bDisposed)
293css::uno::Reference< css::util::XCloneable > SAL_CALL OEditModel::createClone()
296 pClone->clonedFrom(
this);
301void OEditModel::disposing()
303 OEditBaseModel::disposing();
304 m_pValueFormatter.reset();
309OUString SAL_CALL OEditModel::getServiceName()
316css::uno::Sequence<OUString> SAL_CALL OEditModel::getSupportedServiceNames()
318 css::uno::Sequence<OUString> aSupported = OBoundControlModel::getSupportedServiceNames();
320 sal_Int32 nOldLen = aSupported.getLength();
321 aSupported.realloc( nOldLen + 9 );
322 OUString* pStoreTo = aSupported.getArray() + nOldLen;
341void SAL_CALL OEditModel::getFastPropertyValue(Any& rValue, sal_Int32 nHandle )
const
345 if ( m_bMaxTextLenModified )
346 rValue <<= sal_Int16(0);
347 else if ( m_xAggregateSet.is() )
352 OEditBaseModel::getFastPropertyValue(rValue,
nHandle );
357void OEditModel::describeFixedProperties( Sequence< Property >& _rProps )
const
359 OEditBaseModel::describeFixedProperties( _rProps );
360 sal_Int32 nOldCount = _rProps.getLength();
361 _rProps.realloc( nOldCount + 5);
362 css::beans::Property* pProperties = _rProps.getArray() + nOldCount;
366 css::beans::PropertyAttribute::BOUND);
369 css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::MAYBEDEFAULT);
370 DBG_ASSERT( pProperties == _rProps.getArray() + _rProps.getLength(),
"<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
374void OEditModel::describeAggregateProperties( Sequence< Property >& _rAggregateProps )
const
376 OEditBaseModel::describeAggregateProperties( _rAggregateProps );
390bool OEditModel::implActsAsRichText( )
const
392 bool bActAsRichText =
false;
393 if ( m_xAggregateSet.is() )
395 OSL_VERIFY( m_xAggregateSet->getPropertyValue(
PROPERTY_RICH_TEXT ) >>= bActAsRichText );
397 return bActAsRichText;
401void SAL_CALL OEditModel::reset( )
404 if ( implActsAsRichText() )
407 OEditBaseModel::reset();
413 void lcl_transferProperties(
const Reference< XPropertySet >& _rxSource,
const Reference< XPropertySet >& _rxDest )
417 Reference< XPropertySetInfo > xSourceInfo;
418 if ( _rxSource.is() )
419 xSourceInfo = _rxSource->getPropertySetInfo();
421 Reference< XPropertySetInfo > xDestInfo;
423 xDestInfo = _rxDest->getPropertySetInfo();
425 if ( !xSourceInfo.is() || !xDestInfo.is() )
427 OSL_FAIL(
"lcl_transferProperties: invalid property set(s)!" );
431 const Sequence< Property > aSourceProps( xSourceInfo->getProperties() );
432 for (
auto const & sourceprop : aSourceProps )
434 if ( !xDestInfo->hasPropertyByName( sourceprop.Name ) )
439 Property aDestProp( xDestInfo->getPropertyByName( sourceprop.Name ) );
440 if ( 0 != ( aDestProp.Attributes & PropertyAttribute::READONLY ) )
447 _rxDest->setPropertyValue( sourceprop.Name, _rxSource->getPropertyValue( sourceprop.Name ) );
449 catch(
const IllegalArgumentException&)
457 catch(
const Exception& )
465void OEditModel::writeAggregate(
const Reference< XObjectOutputStream >& _rxOutStream )
const
470 Reference< XPropertySet > xFakedAggregate(
474 OSL_ENSURE( xFakedAggregate.is(),
"OEditModel::writeAggregate: could not create an old EditControlModel!" );
475 if ( !xFakedAggregate.is() )
478 lcl_transferProperties( m_xAggregateSet, xFakedAggregate );
480 Reference< XPersistObject > xFakedPersist( xFakedAggregate, UNO_QUERY );
481 OSL_ENSURE( xFakedPersist.is(),
"OEditModel::writeAggregate: no XPersistObject!" );
482 if ( xFakedPersist.is() )
483 xFakedPersist->write( _rxOutStream );
487void OEditModel::readAggregate(
const Reference< XObjectInputStream >& _rxInStream )
492 Reference< XPropertySet > xFakedAggregate(
496 Reference< XPersistObject > xFakedPersist( xFakedAggregate, UNO_QUERY );
497 OSL_ENSURE( xFakedPersist.is(),
"OEditModel::readAggregate: no XPersistObject, or no faked aggregate at all!" );
498 if ( xFakedPersist.is() )
500 xFakedPersist->read( _rxInStream );
501 lcl_transferProperties( xFakedAggregate, m_xAggregateSet );
506void OEditModel::write(
const Reference<XObjectOutputStream>& _rxOutStream)
509 sal_Int16 nOldTextLen = 0;
511 if ( m_bMaxTextLenModified )
515 aCurrentText = m_xAggregateSet->getPropertyValue(
PROPERTY_TEXT);
521 OEditBaseModel::write(_rxOutStream);
523 if ( m_bMaxTextLenModified )
531 m_xAggregateSet->setPropertyValue(
PROPERTY_TEXT, aCurrentText);
536void OEditModel::read(
const Reference<XObjectInputStream>& _rxInStream)
538 OEditBaseModel::read(_rxInStream);
543 if (m_xAggregateSet.is())
546 if ( (aDefaultControl.getValueType().getTypeClass() == TypeClass_STRING)
558sal_uInt16 OEditModel::getPersistenceFlags()
const
560 sal_uInt16 nFlags = OEditBaseModel::getPersistenceFlags();
562 if (m_bWritingFormattedFake)
569void OEditModel::onConnectedDbColumn(
const Reference< XInterface >& _rxForm )
571 Reference< XPropertySet > xField =
getField();
575 m_pValueFormatter.reset( new ::dbtools::FormattedColumnValue( getContext(), Reference< XRowSet >( _rxForm, UNO_QUERY ), xField ) );
577 if ( m_pValueFormatter->getKeyType() == NumberFormat::SCIENTIFIC )
581 if ( !m_bMaxTextLenModified )
583 sal_Int32 nFieldLen = 0;
584 xField->getPropertyValue(
"Precision") >>= nFieldLen;
589 aVal <<= static_cast<sal_Int16>(nFieldLen);
592 m_bMaxTextLenModified =
true;
596 m_bMaxTextLenModified =
false;
600void OEditModel::onDisconnectedDbColumn()
602 OEditBaseModel::onDisconnectedDbColumn();
604 m_pValueFormatter.reset();
606 if ( hasField() && m_bMaxTextLenModified )
609 aVal <<= sal_Int16(0);
611 m_bMaxTextLenModified =
false;
616bool OEditModel::approveDbColumnType( sal_Int32 _nColumnType )
619 if ( implActsAsRichText() )
622 return OEditBaseModel::approveDbColumnType( _nColumnType );
626bool OEditModel::commitControlValueToDbColumn(
bool )
628 Any aNewValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
631 aNewValue >>= sNewValue;
633 if ( !aNewValue.hasValue()
634 || ( sNewValue.isEmpty()
639 m_xColumnUpdate->updateNull();
643 OSL_PRECOND(m_pValueFormatter,
644 "OEditModel::commitControlValueToDbColumn: no value formatter!");
647 if (m_pValueFormatter)
649 if ( !m_pValueFormatter->setFormattedValue( sNewValue ) )
653 m_xColumnUpdate->updateString( sNewValue );
665Any OEditModel::translateDbColumnToControlValue()
667 OSL_PRECOND(m_pValueFormatter,
668 "OEditModel::translateDbColumnToControlValue: no value formatter!");
670 if (m_pValueFormatter)
672 OUString sValue( m_pValueFormatter->getFormattedValue() );
673 if ( sValue.isEmpty()
674 && m_pValueFormatter->getColumn().is()
675 && m_pValueFormatter->getColumn()->wasNull()
683 if ( nMaxTextLen && sValue.getLength() > nMaxTextLen )
685 sal_Int32 nDiff = sValue.getLength() - nMaxTextLen;
686 sValue = sValue.replaceAt( nMaxTextLen, nDiff,
u"" );
693 return aRet.hasValue() ? aRet :
Any( OUString() );
697Any OEditModel::getDefaultForReset()
const
699 return Any( m_aDefaultText );
704extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
706 css::uno::Sequence<css::uno::Any>
const &)
711extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
713 css::uno::Sequence<css::uno::Any>
const &)
#define PF_FAKE_FORMATTED_FIELD
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_form_OEditModel_get_implementation(css::uno::XComponentContext *component, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_form_OEditControl_get_implementation(css::uno::XComponentContext *component, css::uno::Sequence< css::uno::Any > const &)
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
static void RemoveUserEvent(ImplSVEvent *nUserEvent)
sal_Int32 addInterface(const css::uno::Reference< ListenerT > &rxIFace)
void disposeAndClear(const css::lang::EventObject &rEvt)
sal_Int32 removeInterface(const css::uno::Reference< ListenerT > &rxIFace)
void notifyEach(void(SAL_CALL ListenerT::*NotificationMethod)(const EventT &), const EventT &Event)
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() SAL_OVERRIDE
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) SAL_OVERRIDE
virtual void SAL_CALL acquire() SAL_NOEXCEPT SAL_OVERRIDE
oslInterlockedCount m_refCount
virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &_rType) override
virtual void SAL_CALL disposing() override
virtual css::uno::Sequence< css::uno::Type > _getTypes() override
css::uno::Reference< css::uno::XAggregation > m_xAggregate
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Reference< css::awt::XControlModel > SAL_CALL getModel() override
virtual void SAL_CALL dispose() override
virtual void SAL_CALL focusGained(const css::awt::FocusEvent &e) override
::comphelper::OInterfaceContainerHelper3< css::form::XChangeListener > m_aChangeListeners
virtual void SAL_CALL addChangeListener(const css::uno::Reference< css::form::XChangeListener > &_rxListener) override
virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &_rType) override
OUString m_aHtmlChangeValue
virtual void SAL_CALL keyReleased(const css::awt::KeyEvent &e) override
virtual ~OEditControl() override
OEditControl(const css::uno::Reference< css::uno::XComponentContext > &_rxContext)
virtual void SAL_CALL removeChangeListener(const css::uno::Reference< css::form::XChangeListener > &_rxListener) override
virtual void SAL_CALL disposing() override
virtual css::uno::Sequence< css::uno::Type > _getTypes() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL focusLost(const css::awt::FocusEvent &e) override
ImplSVEvent * m_nKeyEvent
virtual void SAL_CALL keyPressed(const css::awt::KeyEvent &e) override
OEditModel(const css::uno::Reference< css::uno::XComponentContext > &_rxFactory)
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define DBG_UNHANDLED_EXCEPTION(...)
constexpr OUStringLiteral PROPERTY_TABINDEX
constexpr OUStringLiteral PROPERTY_DEFAULTCONTROL
constexpr OUStringLiteral PROPERTY_NAME
constexpr OUStringLiteral PROPERTY_FILTERPROPOSAL
constexpr OUStringLiteral PROPERTY_DEFAULT_TEXT
constexpr OUStringLiteral PROPERTY_TARGET_URL
constexpr OUStringLiteral PROPERTY_NATIVE_LOOK
constexpr OUStringLiteral PROPERTY_TEXT
constexpr OUStringLiteral PROPERTY_STANDARD_THEME
constexpr OUStringLiteral PROPERTY_EMPTY_IS_NULL
constexpr OUStringLiteral PROPERTY_MAXTEXTLEN
constexpr OUStringLiteral PROPERTY_CLASSID
constexpr OUStringLiteral PROPERTY_TAG
constexpr OUStringLiteral PROPERTY_PERSISTENCE_MAXTEXTLENGTH
constexpr OUStringLiteral PROPERTY_RICH_TEXT
constexpr OUStringLiteral PROPERTY_MULTILINE
constexpr sal_uInt16 KEY_RETURN
#define LINK(Instance, Class, Member)
bool hasProperty(const OUString &_rName, const Reference< XPropertySet > &_rxSet)
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &... rSn)
bool getBOOL(const Any &_rAny)
bool query_aggregation(const css::uno::Reference< css::uno::XAggregation > &_rxAggregate, css::uno::Reference< iface > &_rxOut)
sal_Int16 getINT16(const Any &_rAny)
OUString getString(const Any &_rAny)
void RemoveProperty(Sequence< Property > &_rProps, const OUString &_rPropName)
const ColumnProperty * getField(guint n)
ListBox is a bit confusing / different from other form components, so here are a few notes:
IMPL_LINK_NOARG(OButtonControl, OnClick, void *, void)
#define PROPERTY_ID_FILTERPROPOSAL
#define PROPERTY_ID_PERSISTENCE_MAXTEXTLENGTH
#define PROPERTY_ID_EMPTY_IS_NULL
#define PROPERTY_ID_DEFAULT_TEXT
#define PROPERTY_ID_TABINDEX
constexpr OUStringLiteral FRM_SUN_COMPONENT_DATABASE_TEXTFIELD
constexpr OUStringLiteral VALIDATABLE_BINDABLE_CONTROL_MODEL
constexpr OUStringLiteral STARDIV_ONE_FORM_CONTROL_EDIT
constexpr OUStringLiteral VCL_CONTROLMODEL_EDIT
constexpr OUStringLiteral BINDABLE_DATA_AWARE_CONTROL_MODEL
constexpr OUStringLiteral FRM_SUN_CONTROL_RICHTEXTCONTROL
constexpr OUStringLiteral STARDIV_ONE_FORM_CONTROL_TEXTFIELD
constexpr OUStringLiteral DATA_AWARE_CONTROL_MODEL
constexpr OUStringLiteral FRM_SUN_CONTROL_TEXTFIELD
constexpr OUStringLiteral VALIDATABLE_CONTROL_MODEL
constexpr OUStringLiteral FRM_SUN_COMPONENT_RICHTEXTCONTROL
constexpr OUStringLiteral FRM_SUN_COMPONENT_TEXTFIELD
constexpr OUStringLiteral FRM_COMPONENT_EDIT
constexpr OUStringLiteral BINDABLE_CONTROL_MODEL
constexpr OUStringLiteral FRM_COMPONENT_TEXTFIELD
constexpr OUStringLiteral BINDABLE_DATABASE_TEXT_FIELD