37#include <com/sun/star/beans/PropertyAttribute.hpp>
38#include <com/sun/star/sdbc/DataType.hpp>
39#include <com/sun/star/util/NumberFormat.hpp>
40#include <com/sun/star/util/Date.hpp>
41#include <com/sun/star/util/Time.hpp>
42#include <com/sun/star/awt/MouseEvent.hpp>
43#include <com/sun/star/form/XSubmit.hpp>
44#include <com/sun/star/awt/XWindow.hpp>
45#include <com/sun/star/form/FormComponentType.hpp>
46#include <com/sun/star/util/XNumberFormatTypes.hpp>
47#include <com/sun/star/form/XForm.hpp>
48#include <com/sun/star/container/XIndexAccess.hpp>
49#include <osl/mutex.hxx>
59using namespace css::uno;
60using namespace css::sdb;
61using namespace css::sdbc;
62using namespace css::sdbcx;
63using namespace css::beans;
64using namespace css::container;
65using namespace css::form;
66using namespace css::awt;
67using namespace css::io;
68using namespace css::lang;
69using namespace css::util;
70using namespace css::form::binding;
82 static Reference< XNumberFormatsSupplier >
get(
const Reference< XComponentContext >& _rxORB );
84 StandardFormatsSupplier(
const Reference< XComponentContext >& _rxFactory,
LanguageType _eSysLanguage);
85 virtual ~StandardFormatsSupplier()
override;
87 virtual bool queryTermination()
const override;
88 virtual void notifyTermination()
override;
94StandardFormatsSupplier::StandardFormatsSupplier(
const Reference< XComponentContext > & _rxContext,
LanguageType _eSysLanguage)
99 ::utl::DesktopTerminationObserver::registerTerminationListener(
this );
101StandardFormatsSupplier::~StandardFormatsSupplier()
103 ::utl::DesktopTerminationObserver::revokeTerminationListener(
this );
105Reference< XNumberFormatsSupplier > StandardFormatsSupplier::get(
const Reference< XComponentContext >& _rxORB )
109 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
111 if ( xSupplier.is() )
118 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
120 if ( xSupplier.is() )
128bool StandardFormatsSupplier::queryTermination()
const
132void StandardFormatsSupplier::notifyTermination()
134 Reference< XNumberFormatsSupplier > xKeepAlive =
this;
139 SetNumberFormatter(
nullptr );
142Sequence<Type> OFormattedControl::_getTypes()
144 return ::comphelper::concatSequences(
145 OFormattedControl_BASE::getTypes(),
146 OBoundControl::_getTypes()
149Any SAL_CALL OFormattedControl::queryAggregation(
const Type& _rType)
151 Any aReturn = OBoundControl::queryAggregation(_rType);
152 if (!aReturn.hasValue())
153 aReturn = OFormattedControl_BASE::queryInterface(_rType);
156OFormattedControl::OFormattedControl(
const Reference<XComponentContext>& _rxFactory)
158 ,m_nKeyEvent(nullptr)
162 Reference<XWindow> xComp;
165 xComp->addKeyListener(
this);
174 if (!OComponentHelper::rBHelper.bDisposed)
188 if( e.KeyCode !=
KEY_RETURN || e.Modifiers != 0 )
191 Reference<css::beans::XPropertySet> xSet(
getModel(), UNO_QUERY);
194 Reference<XFormComponent> xFComp(xSet, UNO_QUERY);
195 css::uno::Reference<css::uno::XInterface> xParent = xFComp->getParent();
198 Reference<css::beans::XPropertySet> xFormSet(xParent, UNO_QUERY);
202 if (!aTmp.has<OUString>() ||
205 Reference<XIndexAccess> xElements(xParent, UNO_QUERY);
206 sal_Int32
nCount = xElements->getCount();
209 Reference<css::beans::XPropertySet> xFCSet;
213 xElements->getByIndex(
nIndex) >>= xFCSet;
236 m_nKeyEvent =
nullptr;
237 Reference<XFormComponent> xFComp(getModel(), UNO_QUERY);
238 css::uno::Reference<css::uno::XInterface> xParent = xFComp->getParent();
239 Reference<XSubmit> xSubmit(xParent, UNO_QUERY);
241 xSubmit->submit( Reference<XControl> (), css::awt::MouseEvent() );
247 aSupported.realloc(aSupported.getLength() + 2);
248 OUString*pArray = aSupported.getArray();
279 :OEditBaseModel( _pOriginal, _rxFactory )
280 ,OErrorBroadcaster( OComponentHelper::rBHelper )
293 pClone->clonedFrom(
this);
307 sal_Int32 nOldLen = aSupported.getLength();
308 aSupported.realloc( nOldLen + 9 );
309 OUString* pStoreTo = aSupported.getArray() + nOldLen;
332 return ::comphelper::concatSequences(
348 sal_Int32 nOldCount = _rProps.getLength();
349 _rProps.realloc( nOldCount + 3);
350 css::beans::Property* pProperties = _rProps.getArray() + nOldCount;
352 css::beans::PropertyAttribute::BOUND);
355 css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::MAYBEDEFAULT);
356 DBG_ASSERT( pProperties == _rProps.getArray() + _rProps.getLength(),
"<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
380 DBG_ASSERT(m_xAggregateSet.is(),
"OFormattedModel::setPropertyToDefaultByHandle(FORMATSSUPPLIER) : have no aggregate !");
381 if (m_xAggregateSet.is())
395 OEditBaseModel::setPropertyToDefault(aPropertyName);
403 return Any(xSupplier);
416 return OEditBaseModel::getPropertyDefault(aPropertyName);
422 OSL_ENSURE( evt.Source == m_xAggregateSet,
"OFormattedModel::_propertyChanged: where did this come from?" );
423 if ( evt.Source != m_xAggregateSet )
428 if ( evt.NewValue.getValueType().getTypeClass() == TypeClass_LONG )
432 ::osl::MutexGuard aGuard(
m_aMutex );
466 if ( xSupplier.is() )
467 xSupplier->getNumberFormatSettings()->getPropertyValue(
"NullDate") >>=
m_aNullDate;
472 Reference<XNumberFormatsSupplier> xSupplier;
473 DBG_ASSERT(m_xAggregateSet.is(),
"OFormattedModel::calcFormatsSupplier : have no aggregate !");
475 if( m_xAggregateSet.is() )
482 DBG_ASSERT(xSupplier.is(),
"OFormattedModel::calcFormatsSupplier : no supplier !");
491 DBG_ASSERT(xMe.is(),
"OFormattedModel::calcFormFormatsSupplier : I should have a content interface !");
493 Reference<XChild> xParent(xMe->getParent(), UNO_QUERY);
494 Reference<XForm> xNextParentForm(xParent, UNO_QUERY);
495 while (!xNextParentForm.is() && xParent.is())
497 xParent.set(xParent->getParent(), css::uno::UNO_QUERY);
498 xNextParentForm.set(xParent, css::uno::UNO_QUERY);
500 if (!xNextParentForm.is())
502 OSL_FAIL(
"OFormattedModel::calcFormFormatsSupplier : have no ancestor which is a form !");
506 Reference< XRowSet > xRowSet( xNextParentForm, UNO_QUERY );
507 Reference< XNumberFormatsSupplier > xSupplier;
515 return StandardFormatsSupplier::get(
getContext() );
537 Reference<XPropertySet> xField =
getField();
538 sal_Int32 nFormatKey = 0;
539 DBG_ASSERT(m_xAggregateSet.is(),
"OFormattedModel::onConnectedDbColumn : have no aggregate !");
540 if (m_xAggregateSet.is())
543 DBG_ASSERT( aSupplier.hasValue(),
"OFormattedModel::onConnectedDbColumn : invalid property value !" );
546 if ( !(aFmtKey >>= nFormatKey ) )
549 sal_Int32
nType = DataType::VARCHAR;
556 DBG_ASSERT(xSupplier.is(),
"OFormattedModel::onConnectedDbColumn : bound to a field but no parent with a formatter ? how this ?");
560 if (!aFmtKey.hasValue())
563 Reference<XNumberFormatTypes> xTypes(xSupplier->getNumberFormats(), UNO_QUERY);
568 aFmtKey <<= xTypes->getStandardFormat(NumberFormat::NUMBER, aApplicationLocale);
570 aFmtKey <<= xTypes->getStandardFormat(NumberFormat::TEXT, aApplicationLocale);
583 case DataType::BOOLEAN:
584 case DataType::TINYINT:
585 case DataType::SMALLINT:
586 case DataType::INTEGER:
587 case DataType::BIGINT:
588 case DataType::FLOAT:
590 case DataType::DOUBLE:
591 case DataType::NUMERIC:
592 case DataType::DECIMAL:
595 case DataType::TIMESTAMP:
603 OSL_VERIFY( aFmtKey >>= nFormatKey );
610 xSupplier->getNumberFormatSettings()->getPropertyValue(
"NullDate") >>=
m_aNullDate;
631 _rxOutStream->writeShort(0x0003);
632 DBG_ASSERT(m_xAggregateSet.is(),
"OFormattedModel::write : have no aggregate !");
636 Reference<XNumberFormatsSupplier> xSupplier;
638 bool bVoidKey =
true;
639 if (m_xAggregateSet.is())
642 if (aSupplier.getValueType().getTypeClass() != TypeClass_VOID)
644 OSL_VERIFY( aSupplier >>= xSupplier );
650 _rxOutStream->writeBoolean(!bVoidKey);
655 sal_Int32 nKey = aKey.hasValue() ?
getINT32(aKey) : 0;
656 Reference<XNumberFormats> xFormats = xSupplier->getNumberFormats();
657 OUString sFormatDescription;
659 static constexpr OUStringLiteral s_aLocaleProp =
u"Locale";
660 Reference<css::beans::XPropertySet> xFormat = xFormats->getByKey(nKey);
663 Any aLocale = xFormat->getPropertyValue(s_aLocaleProp);
664 DBG_ASSERT(aLocale.has<
Locale>(),
"OFormattedModel::write : invalid language property !");
665 if (
auto pLocale = o3tl::tryAccess<Locale>(aLocale))
670 static constexpr OUStringLiteral s_aFormatStringProp =
u"FormatString";
672 xFormat->getPropertyValue(s_aFormatStringProp) >>= sFormatDescription;
673 _rxOutStream->writeUTF(sFormatDescription);
674 _rxOutStream->writeLong(
static_cast<sal_uInt16
>(eFormatLanguage));
684 OStreamSection aDownCompat(_rxOutStream);
686 _rxOutStream->writeShort(0x0000);
689 if (m_xAggregateSet.is())
694 OStreamSection aDownCompat2(_rxOutStream);
695 switch (aEffectiveValue.getValueType().getTypeClass())
697 case TypeClass_STRING:
698 _rxOutStream->writeShort(0x0000);
699 _rxOutStream->writeUTF(::comphelper::getString(aEffectiveValue));
701 case TypeClass_DOUBLE:
702 _rxOutStream->writeShort(0x0001);
703 _rxOutStream->writeDouble(::comphelper::getDouble(aEffectiveValue));
706 DBG_ASSERT(!aEffectiveValue.hasValue(),
"FmXFormattedModel::write : unknown property value type !");
707 _rxOutStream->writeShort(0x0002);
717 sal_uInt16
nVersion = _rxInStream->readShort();
718 Reference<XNumberFormatsSupplier> xSupplier;
726 bool bNonVoidKey = _rxInStream->readBoolean();
730 OUString sFormatDescription = _rxInStream->readUTF();
731 LanguageType eDescriptionLanguage(_rxInStream->readLong());
735 Reference<XNumberFormats> xFormats = xSupplier->getNumberFormats();
739 nKey = xFormats->queryKey(sFormatDescription, aDescriptionLanguage,
false);
740 if (nKey == sal_Int32(-1))
742 nKey = xFormats->addNew(sFormatDescription, aDescriptionLanguage);
750 OStreamSection aDownCompat(_rxInStream);
751 _rxInStream->readShort();
755 OStreamSection aDownCompat2(_rxInStream);
756 switch (_rxInStream->readShort())
759 aEffectiveValue <<= _rxInStream->readUTF();
762 aEffectiveValue <<= _rxInStream->readDouble();
767 OSL_FAIL(
"FmXFormattedModel::read : unknown effective value type!");
786 OSL_FAIL(
"OFormattedModel::read : unknown version !");
791 if ((nKey != -1) && m_xAggregateSet.is())
816 if ( !aControlValue.hasValue()
817 || ( ( aControlValue.getValueType().getTypeClass() == TypeClass_STRING )
828 if ( aControlValue.getValueType().getTypeClass() == TypeClass_DOUBLE || (aControlValue >>= f))
834 DBG_ASSERT( aControlValue.getValueType().getTypeClass() == TypeClass_STRING,
"OFormattedModel::commitControlValueToDbColumn: invalid value type!" );
856 switch( _rExternalValue.getValueTypeClass() )
860 case TypeClass_STRING:
861 aControlValue = _rExternalValue;
863 case TypeClass_BOOLEAN:
865 bool bExternalValue =
false;
866 _rExternalValue >>= bExternalValue;
867 aControlValue <<= static_cast<double>( bExternalValue ? 1 : 0 );
874 css::util::Date aDate;
875 _rExternalValue >>= aDate;
876 aControlValue <<= DBTypeConversion::toDouble( aDate,
m_aNullDate );
880 css::util::Time aTime;
881 _rExternalValue >>= aTime;
882 aControlValue <<= DBTypeConversion::toDouble( aTime );
886 css::util::DateTime aDateTime;
887 _rExternalValue >>= aDateTime;
888 aControlValue <<= DBTypeConversion::toDouble( aDateTime,
m_aNullDate );
892 OSL_ENSURE( _rExternalValue.getValueTypeClass() == TypeClass_DOUBLE,
893 "OFormattedModel::translateExternalValueToControlValue: don't know how to translate this type!" );
895 OSL_VERIFY( _rExternalValue >>= fValue );
896 aControlValue <<= fValue;
900 return aControlValue;
906 "OFormattedModel::translateControlValueToExternalValue: precondition not met!" );
908 if ( !aControlValue.hasValue() )
909 return aControlValue;
913 switch ( aExternalValueType.getTypeClass() )
915 case TypeClass_STRING:
918 if ( aControlValue >>= sString )
920 aExternalValue <<= sString;
925 case TypeClass_BOOLEAN:
928 OSL_VERIFY( aControlValue >>= fValue );
932 aExternalValue <<= fValue != 0.0;
938 OSL_VERIFY( aControlValue >>= fValue );
944 aExternalValue <<= DBTypeConversion::toDate( fValue,
m_aNullDate );
948 aExternalValue <<= DBTypeConversion::toTime( fValue );
952 aExternalValue <<= DBTypeConversion::toDateTime( fValue,
m_aNullDate );
957 "OFormattedModel::translateControlValueToExternalValue: don't know how to translate this type!" );
958 aExternalValue <<= fValue;
963 return aExternalValue;
979 ::std::vector< Type >
aTypes;
980 switch (
m_nKeyType & ~NumberFormat::DEFINED )
982 case NumberFormat::DATE:
985 case NumberFormat::TIME:
988 case NumberFormat::DATETIME:
991 case NumberFormat::TEXT:
994 case NumberFormat::LOGICAL:
1015extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
1017 css::uno::Sequence<css::uno::Any>
const &)
#define PF_HANDLE_COMMON_PROPS
const LanguageTag & GetUILanguageTag() const
static const AllSettings & GetSettings()
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
static void RemoveUserEvent(ImplSVEvent *nUserEvent)
LanguageType getLanguageType(bool bResolveSystem=true) const
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
static css::lang::Locale convertToLocale(LanguageType nLangID, bool bResolveSystem=true)
static LanguageType convertToLanguageType(const css::lang::Locale &rLocale, bool bResolveSystem=true)
const LanguageTag & GetLanguageTag() const
virtual sal_Int32 SAL_CALL getHandleByName(const OUString &_rPropertyName) override
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) SAL_OVERRIDE
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() SAL_OVERRIDE
virtual void SAL_CALL acquire() SAL_NOEXCEPT SAL_OVERRIDE
oslInterlockedCount m_refCount
sal_Int32 getValuePropertyAggHandle() const
bool hasExternalValueBinding() const
checks whether we currently have an external value binding in place
virtual void onConnectedDbColumn(const css::uno::Reference< css::uno::XInterface > &_rxForm)
called whenever a connection to a database column has been established
const css::uno::Type & getExternalValueType() const
returns the type which should be used to exchange data with our external value binding
virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &_rType) override
virtual void onConnectedExternalValue()
called whenever a connection to an external supplier of values (XValueBinding) has been established
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
void setControlValue(const css::uno::Any &_rValue, ValueChangeInstigator _eInstigator)
sets the given value as new current value for the control
virtual void SAL_CALL disposing() override
void initValueProperty(const OUString &_rValuePropertyName, sal_Int32 _nValuePropertyExternalHandle)
initializes the part of the class which is related to the control value.
css::uno::Reference< css::sdb::XColumn > m_xColumn
virtual void describeFixedProperties(css::uno::Sequence< css::beans::Property > &_rProps) const override
describes the properties provided by this class, or its respective derived class
virtual void resetNoBroadcast()
called to reset the control to some kind of default.
const OUString & getControlSource() const
virtual css::uno::Sequence< css::uno::Type > _getTypes() override
void calculateExternalValueType()
calculates the type which is to be used to communicate with the current external binding,...
virtual void SAL_CALL loaded(const css::lang::EventObject &aEvent) override
css::uno::Reference< css::sdbc::XRowSet > m_xCursor
const css::uno::Reference< css::beans::XPropertySet > & getField() const
css::uno::Reference< css::sdb::XColumnUpdate > m_xColumnUpdate
void startAggregatePropertyListening(const OUString &_rPropertyName)
starts listening at the aggregate, for changes in the given property
virtual void onDisconnectedDbColumn()
called whenever a connection to a database column has been suspended
virtual css::uno::Any getControlValue() const
retrieves the current value of the control
virtual void _propertyChanged(const css::beans::PropertyChangeEvent &_rEvt) override
virtual void SAL_CALL disposing() override
PropertyBagHelper m_aPropertyBagHelper
const css::uno::Reference< css::uno::XComponentContext > & getContext() const
virtual void setPropertyToDefaultByHandle(sal_Int32 nHandle) override
virtual void describeAggregateProperties(css::uno::Sequence< css::beans::Property > &_rAggregateProps) const
describes the properties of our aggregate
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 sal_uInt16 getPersistenceFlags() const
virtual void SAL_CALL read(const css::uno::Reference< css::io::XObjectInputStream > &_rxInStream) override
virtual css::uno::Any getPropertyDefaultByHandle(sal_Int32 nHandle) const override
void defaultCommonEditProperties()
void readCommonEditProperties(const css::uno::Reference< css::io::XObjectInputStream > &_rxInStream)
virtual void SAL_CALL write(const css::uno::Reference< css::io::XObjectOutputStream > &_rxOutStream) override
void writeCommonEditProperties(const css::uno::Reference< css::io::XObjectOutputStream > &_rxOutStream)
inline ::comphelper::OPropertyArrayAggregationHelper & getInfoHelper() const
#define DBG_ASSERT(sCon, aError)
constexpr OUStringLiteral PROPERTY_TREATASNUMERIC
constexpr OUStringLiteral PROPERTY_TABINDEX
constexpr OUStringLiteral PROPERTY_FILTERPROPOSAL
constexpr OUStringLiteral PROPERTY_EFFECTIVE_DEFAULT
constexpr OUStringLiteral PROPERTY_TARGET_URL
constexpr OUStringLiteral PROPERTY_EFFECTIVE_VALUE
constexpr OUStringLiteral PROPERTY_EMPTY_IS_NULL
constexpr OUStringLiteral PROPERTY_STRICTFORMAT
constexpr OUStringLiteral PROPERTY_CLASSID
constexpr OUStringLiteral PROPERTY_FIELDTYPE
constexpr OUStringLiteral PROPERTY_FORMATKEY
constexpr OUStringLiteral PROPERTY_FORMATSSUPPLIER
constexpr sal_uInt16 KEY_RETURN
#define LANGUAGE_DONTKNOW
#define LINK(Instance, Class, Member)
bool hasProperty(const OUString &_rName, const Reference< XPropertySet > &_rxSet)
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)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
double getDouble(const Any &_rAny)
sal_Int32 getINT32(const Any &_rAny)
void ModifyPropertyAttributes(Sequence< Property > &seqProps, const OUString &sPropName, sal_Int16 nAddAttrib, sal_Int16 nRemoveAttrib)
OUString getString(const Any &_rAny)
void RemoveProperty(Sequence< Property > &_rProps, const OUString &_rPropName)
sal_Int16 getNumberFormatType(const css::uno::Reference< css::util::XNumberFormats > &xFormats, sal_Int32 nKey)
ListBox is a bit confusing / different from other form components, so here are a few notes:
IMPL_LINK_NOARG(OButtonControl, OnClick, void *, void)
VBAHELPER_DLLPUBLIC bool setPropertyValue(css::uno::Sequence< css::beans::PropertyValue > &aProp, const OUString &aName, const css::uno::Any &aValue)
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
#define PROPERTY_ID_FILTERPROPOSAL
#define PROPERTY_ID_EFFECTIVE_VALUE
#define PROPERTY_ID_EMPTY_IS_NULL
#define PROPERTY_ID_FORMATSSUPPLIER
#define PROPERTY_ID_TABINDEX
constexpr OUStringLiteral FRM_SUN_COMPONENT_FORMATTEDFIELD
constexpr OUStringLiteral VALIDATABLE_BINDABLE_CONTROL_MODEL
constexpr OUStringLiteral BINDABLE_DATA_AWARE_CONTROL_MODEL
constexpr OUStringLiteral STARDIV_ONE_FORM_CONTROL_FORMATTEDFIELD
constexpr OUStringLiteral DATA_AWARE_CONTROL_MODEL
constexpr OUStringLiteral VCL_CONTROL_FORMATTEDFIELD
constexpr OUStringLiteral FRM_SUN_COMPONENT_DATABASE_FORMATTEDFIELD
constexpr OUStringLiteral VALIDATABLE_CONTROL_MODEL
constexpr OUStringLiteral VCL_CONTROLMODEL_FORMATTEDFIELD
constexpr OUStringLiteral FRM_SUN_CONTROL_FORMATTEDFIELD
constexpr OUStringLiteral FRM_COMPONENT_FORMATTEDFIELD
constexpr OUStringLiteral FRM_COMPONENT_EDIT
constexpr OUStringLiteral BINDABLE_CONTROL_MODEL
constexpr OUStringLiteral BINDABLE_DATABASE_FORMATTED_FIELD