diff options
Diffstat (limited to 'forms/source/component/FormattedField.cxx')
-rw-r--r-- | forms/source/component/FormattedField.cxx | 206 |
1 files changed, 7 insertions, 199 deletions
diff --git a/forms/source/component/FormattedField.cxx b/forms/source/component/FormattedField.cxx index afb857dd7a44..eb850260b2d0 100644 --- a/forms/source/component/FormattedField.cxx +++ b/forms/source/component/FormattedField.cxx @@ -16,8 +16,6 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ - - #include "FormattedField.hxx" #include "services.hxx" #include "property.hrc" @@ -51,14 +49,12 @@ #include <com/sun/star/form/XForm.hpp> #include <com/sun/star/container/XIndexAccess.hpp> #include <osl/mutex.hxx> - // needed as long as we use the SolarMutex +// needed as long as we use the SolarMutex #include <comphelper/streamsection.hxx> #include <cppuhelper/weakref.hxx> #include <unotools/desktopterminationobserver.hxx> - #include <list> #include <algorithm> - using namespace dbtools; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::sdb; @@ -72,64 +68,44 @@ using namespace ::com::sun::star::io; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::util; using namespace ::com::sun::star::form::binding; - namespace { typedef com::sun::star::util::Date UNODate; typedef com::sun::star::util::Time UNOTime; typedef com::sun::star::util::DateTime UNODateTime; } - -//......................................................................... namespace frm { - -/*************************************************************************/ - class StandardFormatsSupplier : protected SvNumberFormatsSupplierObj, public ::utl::ITerminationListener { protected: SvNumberFormatter* m_pMyPrivateFormatter; static WeakReference< XNumberFormatsSupplier > s_xDefaultFormatsSupplier; - public: static Reference< XNumberFormatsSupplier > get( const Reference< XComponentContext >& _rxORB ); - using SvNumberFormatsSupplierObj::operator new; using SvNumberFormatsSupplierObj::operator delete; - protected: StandardFormatsSupplier(const Reference< XComponentContext >& _rxFactory,LanguageType _eSysLanguage); ~StandardFormatsSupplier(); - protected: virtual bool queryTermination() const; virtual void notifyTermination(); }; - -//------------------------------------------------------------------ WeakReference< XNumberFormatsSupplier > StandardFormatsSupplier::s_xDefaultFormatsSupplier; - -//------------------------------------------------------------------ StandardFormatsSupplier::StandardFormatsSupplier(const Reference< XComponentContext > & _rxContext,LanguageType _eSysLanguage) :SvNumberFormatsSupplierObj() ,m_pMyPrivateFormatter(new SvNumberFormatter(_rxContext, _eSysLanguage)) { SetNumberFormatter(m_pMyPrivateFormatter); - // #i29147# ::utl::DesktopTerminationObserver::registerTerminationListener( this ); } - -//------------------------------------------------------------------ StandardFormatsSupplier::~StandardFormatsSupplier() { ::utl::DesktopTerminationObserver::revokeTerminationListener( this ); - DELETEZ( m_pMyPrivateFormatter ); } - -//------------------------------------------------------------------ Reference< XNumberFormatsSupplier > StandardFormatsSupplier::get( const Reference< XComponentContext >& _rxORB ) { LanguageType eSysLanguage = LANGUAGE_SYSTEM; @@ -138,14 +114,11 @@ Reference< XNumberFormatsSupplier > StandardFormatsSupplier::get( const Referenc Reference< XNumberFormatsSupplier > xSupplier = s_xDefaultFormatsSupplier; if ( xSupplier.is() ) return xSupplier; - // get the Office's locale eSysLanguage = SvtSysLocale().GetLanguageTag().getLanguageType( false); } - StandardFormatsSupplier* pSupplier = new StandardFormatsSupplier( _rxORB, eSysLanguage ); Reference< XNumberFormatsSupplier > xNewlyCreatedSupplier( pSupplier ); - { ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); Reference< XNumberFormatsSupplier > xSupplier = s_xDefaultFormatsSupplier; @@ -153,20 +126,14 @@ Reference< XNumberFormatsSupplier > StandardFormatsSupplier::get( const Referenc // somebody used the small time frame where the mutex was not locked to create and set // the supplier return xSupplier; - s_xDefaultFormatsSupplier = xNewlyCreatedSupplier; } - return xNewlyCreatedSupplier; } - -//------------------------------------------------------------------ bool StandardFormatsSupplier::queryTermination() const { return true; } - -//------------------------------------------------------------------ void StandardFormatsSupplier::notifyTermination() { Reference< XNumberFormatsSupplier > xKeepAlive = this; @@ -174,19 +141,13 @@ void StandardFormatsSupplier::notifyTermination() // earlier than upon unloading the library // #i29147# s_xDefaultFormatsSupplier = WeakReference< XNumberFormatsSupplier >( ); - SetNumberFormatter( NULL ); DELETEZ( m_pMyPrivateFormatter ); } - -/*************************************************************************/ -//------------------------------------------------------------------ InterfaceRef SAL_CALL OFormattedControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) { return *(new OFormattedControl( comphelper::getComponentContext(_rxFactory) )); } - -//------------------------------------------------------------------ Sequence<Type> OFormattedControl::_getTypes() { return ::comphelper::concatSequences( @@ -194,8 +155,6 @@ Sequence<Type> OFormattedControl::_getTypes() OBoundControl::_getTypes() ); } - -//------------------------------------------------------------------ Any SAL_CALL OFormattedControl::queryAggregation(const Type& _rType) throw (RuntimeException) { Any aReturn = OBoundControl::queryAggregation(_rType); @@ -203,14 +162,10 @@ Any SAL_CALL OFormattedControl::queryAggregation(const Type& _rType) throw (Runt aReturn = OFormattedControl_BASE::queryInterface(_rType); return aReturn; } - - -//------------------------------------------------------------------------------ OFormattedControl::OFormattedControl(const Reference<XComponentContext>& _rxFactory) :OBoundControl(_rxFactory, VCL_CONTROL_FORMATTEDFIELD) ,m_nKeyEvent(0) { - increment(m_refCount); { Reference<XWindow> xComp; @@ -221,64 +176,50 @@ OFormattedControl::OFormattedControl(const Reference<XComponentContext>& _rxFact } decrement(m_refCount); } - -//------------------------------------------------------------------------------ OFormattedControl::~OFormattedControl() { if( m_nKeyEvent ) Application::RemoveUserEvent( m_nKeyEvent ); - if (!OComponentHelper::rBHelper.bDisposed) { acquire(); dispose(); } - } // XKeyListener -//------------------------------------------------------------------------------ void OFormattedControl::disposing(const EventObject& _rSource) throw(RuntimeException) { OBoundControl::disposing(_rSource); } - -//------------------------------------------------------------------------------ void OFormattedControl::keyPressed(const ::com::sun::star::awt::KeyEvent& e) throw ( ::com::sun::star::uno::RuntimeException) { if( e.KeyCode != KEY_RETURN || e.Modifiers != 0 ) return; - // Steht das Control in einem Formular mit einer Submit-URL? Reference<com::sun::star::beans::XPropertySet> xSet(getModel(), UNO_QUERY); if( !xSet.is() ) return; - Reference<XFormComponent> xFComp(xSet, UNO_QUERY); InterfaceRef xParent = xFComp->getParent(); if( !xParent.is() ) return; - Reference<com::sun::star::beans::XPropertySet> xFormSet(xParent, UNO_QUERY); if( !xFormSet.is() ) return; - Any aTmp(xFormSet->getPropertyValue( PROPERTY_TARGET_URL )); if (!isA(aTmp, static_cast< OUString* >(NULL)) || getString(aTmp).isEmpty() ) return; - Reference<XIndexAccess> xElements(xParent, UNO_QUERY); sal_Int32 nCount = xElements->getCount(); if( nCount > 1 ) { - Reference<com::sun::star::beans::XPropertySet> xFCSet; for( sal_Int32 nIndex=0; nIndex < nCount; nIndex++ ) { // Any aElement(xElements->getByIndex(nIndex)); xElements->getByIndex(nIndex) >>= xFCSet; - if (hasProperty(PROPERTY_CLASSID, xFCSet) && getINT16(xFCSet->getPropertyValue(PROPERTY_CLASSID)) == FormComponentType::TEXTFIELD) { @@ -288,7 +229,6 @@ void OFormattedControl::keyPressed(const ::com::sun::star::awt::KeyEvent& e) thr } } } - // Da wir noch im Haender stehen, submit asynchron ausloesen if( m_nKeyEvent ) Application::RemoveUserEvent( m_nKeyEvent ); @@ -296,16 +236,13 @@ void OFormattedControl::keyPressed(const ::com::sun::star::awt::KeyEvent& e) thr OnKeyPressed) ); } -//------------------------------------------------------------------------------ void OFormattedControl::keyReleased(const ::com::sun::star::awt::KeyEvent& /*e*/) throw ( ::com::sun::star::uno::RuntimeException) { } -//------------------------------------------------------------------------------ IMPL_LINK(OFormattedControl, OnKeyPressed, void*, /*EMPTYARG*/) { m_nKeyEvent = 0; - Reference<XFormComponent> xFComp(getModel(), UNO_QUERY); InterfaceRef xParent = xFComp->getParent(); Reference<XSubmit> xSubmit(xParent, UNO_QUERY); @@ -314,25 +251,20 @@ IMPL_LINK(OFormattedControl, OnKeyPressed, void*, /*EMPTYARG*/) return 0L; } -//------------------------------------------------------------------------------ StringSequence OFormattedControl::getSupportedServiceNames() throw() { StringSequence aSupported = OBoundControl::getSupportedServiceNames(); aSupported.realloc(aSupported.getLength() + 1); - OUString*pArray = aSupported.getArray(); pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_FORMATTEDFIELD; return aSupported; } -//------------------------------------------------------------------------------ void OFormattedControl::setDesignMode(sal_Bool bOn) throw ( ::com::sun::star::uno::RuntimeException) { OBoundControl::setDesignMode(bOn); } -/*************************************************************************/ -//------------------------------------------------------------------ void OFormattedModel::implConstruct() { // members @@ -342,48 +274,36 @@ void OFormattedModel::implConstruct() m_nKeyType = NumberFormat::UNDEFINED; m_aNullDate = DBTypeConversion::getStandardDate(); m_nFieldType = DataType::OTHER; - // default our formats supplier increment(m_refCount); setPropertyToDefaultByHandle(PROPERTY_ID_FORMATSSUPPLIER); decrement(m_refCount); - startAggregatePropertyListening( PROPERTY_FORMATKEY ); startAggregatePropertyListening( PROPERTY_FORMATSSUPPLIER ); } - -//------------------------------------------------------------------ OFormattedModel::OFormattedModel(const Reference<XComponentContext>& _rxFactory) :OEditBaseModel(_rxFactory, VCL_CONTROLMODEL_FORMATTEDFIELD, FRM_SUN_CONTROL_FORMATTEDFIELD, sal_True, sal_True ) // use the old control name for compytibility reasons ,OErrorBroadcaster( OComponentHelper::rBHelper ) { - implConstruct(); - m_nClassId = FormComponentType::TEXTFIELD; initValueProperty( PROPERTY_EFFECTIVE_VALUE, PROPERTY_ID_EFFECTIVE_VALUE ); } - -//------------------------------------------------------------------ OFormattedModel::OFormattedModel( const OFormattedModel* _pOriginal, const Reference< XComponentContext >& _rxFactory ) :OEditBaseModel( _pOriginal, _rxFactory ) ,OErrorBroadcaster( OComponentHelper::rBHelper ) { - implConstruct(); } -//------------------------------------------------------------------------------ OFormattedModel::~OFormattedModel() { } // XCloneable -//------------------------------------------------------------------------------ IMPLEMENT_DEFAULT_CLONING( OFormattedModel ) -//------------------------------------------------------------------------------ void SAL_CALL OFormattedModel::disposing() { OErrorBroadcaster::disposing(); @@ -391,31 +311,24 @@ void SAL_CALL OFormattedModel::disposing() } // XServiceInfo -//------------------------------------------------------------------------------ StringSequence OFormattedModel::getSupportedServiceNames() throw() { StringSequence aSupported = OEditBaseModel::getSupportedServiceNames(); - sal_Int32 nOldLen = aSupported.getLength(); aSupported.realloc( nOldLen + 8 ); OUString* pStoreTo = aSupported.getArray() + nOldLen; - *pStoreTo++ = BINDABLE_CONTROL_MODEL; *pStoreTo++ = DATA_AWARE_CONTROL_MODEL; *pStoreTo++ = VALIDATABLE_CONTROL_MODEL; - *pStoreTo++ = BINDABLE_DATA_AWARE_CONTROL_MODEL; *pStoreTo++ = VALIDATABLE_BINDABLE_CONTROL_MODEL; - *pStoreTo++ = FRM_SUN_COMPONENT_FORMATTEDFIELD; *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_FORMATTEDFIELD; *pStoreTo++ = BINDABLE_DATABASE_FORMATTED_FIELD; - return aSupported; } // XAggregation -//------------------------------------------------------------------------------ Any SAL_CALL OFormattedModel::queryAggregation(const Type& _rType) throw(RuntimeException) { Any aReturn = OEditBaseModel::queryAggregation( _rType ); @@ -423,7 +336,6 @@ Any SAL_CALL OFormattedModel::queryAggregation(const Type& _rType) throw(Runtime } // XTypeProvider -//------------------------------------------------------------------------------ Sequence< Type > OFormattedModel::_getTypes() { return ::comphelper::concatSequences( @@ -433,14 +345,12 @@ Sequence< Type > OFormattedModel::_getTypes() } // XPersistObject -//------------------------------------------------------------------------------ OUString SAL_CALL OFormattedModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException) { return OUString(FRM_COMPONENT_EDIT); } // XPropertySet -//------------------------------------------------------------------------------ void OFormattedModel::describeFixedProperties( Sequence< Property >& _rProps ) const { BEGIN_DESCRIBE_PROPERTIES( 3, OEditBaseModel ) @@ -450,11 +360,9 @@ void OFormattedModel::describeFixedProperties( Sequence< Property >& _rProps ) c END_DESCRIBE_PROPERTIES(); } -//------------------------------------------------------------------------------ void OFormattedModel::describeAggregateProperties( Sequence< Property >& _rAggregateProps ) const { OEditBaseModel::describeAggregateProperties( _rAggregateProps ); - // TreatAsNumeric nicht transient : wir wollen es an der UI anbinden (ist noetig, um dem EffectiveDefault // - der kann Text oder Zahl sein - einen Sinn zu geben) ModifyPropertyAttributes(_rAggregateProps, PROPERTY_TREATASNUMERIC, 0, PropertyAttribute::TRANSIENT); @@ -462,33 +370,28 @@ void OFormattedModel::describeAggregateProperties( Sequence< Property >& _rAggre // (though the paragraph above for the TreatAsNumeric does not hold anymore - we do not have an UI for this. // But we have for the format key ...) ModifyPropertyAttributes(_rAggregateProps, PROPERTY_FORMATKEY, 0, PropertyAttribute::TRANSIENT); - RemoveProperty(_rAggregateProps, PROPERTY_STRICTFORMAT); // no strict format property for formatted fields: it does not make sense, 'cause // there is no general way to decide which characters/sub strings are allowed during the input of an // arbitraryly formatted control } -//------------------------------------------------------------------------------ void OFormattedModel::getFastPropertyValue(Any& rValue, sal_Int32 nHandle) const { OEditBaseModel::getFastPropertyValue(rValue, nHandle); } -//------------------------------------------------------------------------------ void OFormattedModel::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const Any& rValue) throw ( ::com::sun::star::uno::Exception) { OEditBaseModel::setFastPropertyValue_NoBroadcast(nHandle, rValue); } -//------------------------------------------------------------------------------ sal_Bool OFormattedModel::convertFastPropertyValue(Any& rConvertedValue, Any& rOldValue, sal_Int32 nHandle, const Any& rValue) throw( IllegalArgumentException ) { return OEditBaseModel::convertFastPropertyValue(rConvertedValue, rOldValue, nHandle, rValue); } -//------------------------------------------------------------------------------ void OFormattedModel::setPropertyToDefaultByHandle(sal_Int32 nHandle) { if (nHandle == PROPERTY_ID_FORMATSSUPPLIER) @@ -502,19 +405,16 @@ void OFormattedModel::setPropertyToDefaultByHandle(sal_Int32 nHandle) OEditBaseModel::setPropertyToDefaultByHandle(nHandle); } -//------------------------------------------------------------------------------ void OFormattedModel::setPropertyToDefault(const OUString& aPropertyName) throw( com::sun::star::beans::UnknownPropertyException, RuntimeException ) { OPropertyArrayAggregationHelper& rPH = m_aPropertyBagHelper.getInfoHelper(); sal_Int32 nHandle = rPH.getHandleByName( aPropertyName ); - if (nHandle == PROPERTY_ID_FORMATSSUPPLIER) setPropertyToDefaultByHandle(PROPERTY_ID_FORMATSSUPPLIER); else OEditBaseModel::setPropertyToDefault(aPropertyName); } -//------------------------------------------------------------------------------ Any OFormattedModel::getPropertyDefaultByHandle( sal_Int32 nHandle ) const { if (nHandle == PROPERTY_ID_FORMATSSUPPLIER) @@ -526,23 +426,19 @@ Any OFormattedModel::getPropertyDefaultByHandle( sal_Int32 nHandle ) const return OEditBaseModel::getPropertyDefaultByHandle(nHandle); } -//------------------------------------------------------------------------------ Any SAL_CALL OFormattedModel::getPropertyDefault( const OUString& aPropertyName ) throw( com::sun::star::beans::UnknownPropertyException, RuntimeException ) { OPropertyArrayAggregationHelper& rPH = m_aPropertyBagHelper.getInfoHelper(); sal_Int32 nHandle = rPH.getHandleByName( aPropertyName ); - if (nHandle == PROPERTY_ID_FORMATSSUPPLIER) return getPropertyDefaultByHandle(PROPERTY_ID_FORMATSSUPPLIER); else return OEditBaseModel::getPropertyDefault(aPropertyName); } -//------------------------------------------------------------------------------ void OFormattedModel::_propertyChanged( const com::sun::star::beans::PropertyChangeEvent& evt ) throw(RuntimeException) { // TODO: check how this works with external bindings - OSL_ENSURE( evt.Source == m_xAggregateSet, "OFormattedModel::_propertyChanged: where did this come from?" ); if ( evt.Source == m_xAggregateSet ) { @@ -554,17 +450,14 @@ void OFormattedModel::_propertyChanged( const com::sun::star::beans::PropertyCha try { ::osl::MutexGuard aGuard( m_aMutex ); - Reference<XNumberFormatsSupplier> xSupplier( calcFormatsSupplier() ); m_nKeyType = getNumberFormatType(xSupplier->getNumberFormats(), getINT32( evt.NewValue ) ); - // as m_aSaveValue (which is used by commitControlValueToDbColumn) is format dependent we have // to recalc it, which is done by translateDbColumnToControlValue if ( m_xColumn.is() && m_xAggregateFastSet.is() && !m_xCursor->isBeforeFirst() && !m_xCursor->isAfterLast()) { setControlValue( translateDbColumnToControlValue(), eOther ); } - // if we're connected to an external value binding, then re-calculate the type // used to exchange the value - it depends on the format, too if ( hasExternalValueBinding() ) @@ -578,18 +471,15 @@ void OFormattedModel::_propertyChanged( const com::sun::star::beans::PropertyCha } return; } - if ( evt.PropertyName.equals( PROPERTY_FORMATSSUPPLIER ) ) { updateFormatterNullDate(); return; } - OBoundControlModel::_propertyChanged( evt ); } } -//------------------------------------------------------------------------------ void OFormattedModel::updateFormatterNullDate() { // calc the current NULL date @@ -598,29 +488,23 @@ void OFormattedModel::updateFormatterNullDate() xSupplier->getNumberFormatSettings()->getPropertyValue("NullDate") >>= m_aNullDate; } -//------------------------------------------------------------------------------ Reference< XNumberFormatsSupplier > OFormattedModel::calcFormatsSupplier() const { Reference<XNumberFormatsSupplier> xSupplier; - DBG_ASSERT(m_xAggregateSet.is(), "OFormattedModel::calcFormatsSupplier : have no aggregate !"); // hat mein aggregiertes Model einen FormatSupplier ? if( m_xAggregateSet.is() ) m_xAggregateSet->getPropertyValue(PROPERTY_FORMATSSUPPLIER) >>= xSupplier; - if (!xSupplier.is()) // check if my parent form has a supplier xSupplier = calcFormFormatsSupplier(); - if (!xSupplier.is()) xSupplier = calcDefaultFormatsSupplier(); - DBG_ASSERT(xSupplier.is(), "OFormattedModel::calcFormatsSupplier : no supplier !"); // jetzt sollte aber einer da sein return xSupplier; } -//------------------------------------------------------------------------------ Reference<XNumberFormatsSupplier> OFormattedModel::calcFormFormatsSupplier() const { Reference<XChild> xMe; @@ -628,7 +512,6 @@ Reference<XNumberFormatsSupplier> OFormattedModel::calcFormFormatsSupplier() co // damit stellen wir sicher, dass wir auch fuer den Fall der Aggregation das richtige // Objekt bekommen DBG_ASSERT(xMe.is(), "OFormattedModel::calcFormFormatsSupplier : I should have a content interface !"); - // jetzt durchhangeln nach oben, bis wir auf eine starform treffen (angefangen mit meinem eigenen Parent) Reference<XChild> xParent(xMe->getParent(), UNO_QUERY); Reference<XForm> xNextParentForm(xParent, UNO_QUERY); @@ -637,13 +520,11 @@ Reference<XNumberFormatsSupplier> OFormattedModel::calcFormFormatsSupplier() co xParent = xParent.query( xParent->getParent() ); xNextParentForm = xNextParentForm.query( xParent ); } - if (!xNextParentForm.is()) { OSL_FAIL("OFormattedModel::calcFormFormatsSupplier : have no ancestor which is a form !"); return NULL; } - // den FormatSupplier von meinem Vorfahren (falls der einen hat) Reference< XRowSet > xRowSet( xNextParentForm, UNO_QUERY ); Reference< XNumberFormatsSupplier > xSupplier; @@ -652,14 +533,12 @@ Reference<XNumberFormatsSupplier> OFormattedModel::calcFormFormatsSupplier() co return xSupplier; } -//------------------------------------------------------------------------------ Reference< XNumberFormatsSupplier > OFormattedModel::calcDefaultFormatsSupplier() const { return StandardFormatsSupplier::get( getContext() ); } // XBoundComponent -//------------------------------------------------------------------------------ void OFormattedModel::loaded(const EventObject& rEvent) throw ( ::com::sun::star::uno::RuntimeException) { // HACK : our onConnectedDbColumn accesses our NumberFormatter which locks the solar mutex (as it doesn't have @@ -670,31 +549,25 @@ void OFormattedModel::loaded(const EventObject& rEvent) throw ( ::com::sun::star // property requests and one for our own code. This would need a lot of code rewriting // alternative b): The NumberFormatter has to be really threadsafe (with an own mutex), which is // the only "clean" solution for me. - SolarMutexGuard aGuard; OEditBaseModel::loaded(rEvent); } -//------------------------------------------------------------------------------ void OFormattedModel::onConnectedDbColumn( const Reference< XInterface >& _rxForm ) { m_xOriginalFormatter = NULL; - // get some properties of the field m_nFieldType = DataType::OTHER; Reference<XPropertySet> xField = getField(); if ( xField.is() ) xField->getPropertyValue( PROPERTY_FIELDTYPE ) >>= m_nFieldType; - sal_Int32 nFormatKey = 0; - DBG_ASSERT(m_xAggregateSet.is(), "OFormattedModel::onConnectedDbColumn : have no aggregate !"); if (m_xAggregateSet.is()) { // all the following doesn't make any sense if we have no aggregate ... Any aSupplier = m_xAggregateSet->getPropertyValue(PROPERTY_FORMATSSUPPLIER); DBG_ASSERT( aSupplier.hasValue(), "OFormattedModel::onConnectedDbColumn : invalid property value !" ); // das sollte im Constructor oder im read auf was richtiges gesetzt worden sein - Any aFmtKey = m_xAggregateSet->getPropertyValue(PROPERTY_FORMATKEY); if ( !(aFmtKey >>= nFormatKey ) ) { // nobody gave us a format to use. So we examine the field we're bound to for a @@ -705,13 +578,11 @@ void OFormattedModel::onConnectedDbColumn( const Reference< XInterface >& _rxFor aFmtKey = xField->getPropertyValue(PROPERTY_FORMATKEY); xField->getPropertyValue(PROPERTY_FIELDTYPE) >>= nType ; } - Reference<XNumberFormatsSupplier> xSupplier = calcFormFormatsSupplier(); DBG_ASSERT(xSupplier.is(), "OFormattedModel::onConnectedDbColumn : bound to a field but no parent with a formatter ? how this ?"); if (xSupplier.is()) { m_bOriginalNumeric = getBOOL(getPropertyValue(PROPERTY_TREATASNUMERIC)); - if (!aFmtKey.hasValue()) { // we aren't bound to a field (or this field's format is invalid) // -> determine the standard text (or numeric) format of the supplier @@ -719,18 +590,15 @@ void OFormattedModel::onConnectedDbColumn( const Reference< XInterface >& _rxFor if (xTypes.is()) { Locale aApplicationLocale = Application::GetSettings().GetUILanguageTag().getLocale(); - if (m_bOriginalNumeric) aFmtKey <<= (sal_Int32)xTypes->getStandardFormat(NumberFormat::NUMBER, aApplicationLocale); else aFmtKey <<= (sal_Int32)xTypes->getStandardFormat(NumberFormat::TEXT, aApplicationLocale); } } - aSupplier >>= m_xOriginalFormatter; m_xAggregateSet->setPropertyValue(PROPERTY_FORMATSSUPPLIER, makeAny(xSupplier)); m_xAggregateSet->setPropertyValue(PROPERTY_FORMATKEY, aFmtKey); - // das Numeric-Flag an mein gebundenes Feld anpassen if (xField.is()) { @@ -757,23 +625,18 @@ void OFormattedModel::onConnectedDbColumn( const Reference< XInterface >& _rxFor } else m_bNumeric = m_bOriginalNumeric; - setPropertyValue(PROPERTY_TREATASNUMERIC, makeAny((sal_Bool)m_bNumeric)); - OSL_VERIFY( aFmtKey >>= nFormatKey ); } } } - Reference<XNumberFormatsSupplier> xSupplier = calcFormatsSupplier(); m_bNumeric = getBOOL( getPropertyValue( PROPERTY_TREATASNUMERIC ) ); m_nKeyType = getNumberFormatType( xSupplier->getNumberFormats(), nFormatKey ); xSupplier->getNumberFormatSettings()->getPropertyValue("NullDate") >>= m_aNullDate; - OEditBaseModel::onConnectedDbColumn( _rxForm ); } -//------------------------------------------------------------------------------ void OFormattedModel::onDisconnectedDbColumn() { OEditBaseModel::onDisconnectedDbColumn(); @@ -784,23 +647,18 @@ void OFormattedModel::onDisconnectedDbColumn() setPropertyValue(PROPERTY_TREATASNUMERIC, makeAny((sal_Bool)m_bOriginalNumeric)); m_xOriginalFormatter = NULL; } - m_nFieldType = DataType::OTHER; m_nKeyType = NumberFormat::UNDEFINED; m_aNullDate = DBTypeConversion::getStandardDate(); } -//------------------------------------------------------------------------------ void OFormattedModel::write(const Reference<XObjectOutputStream>& _rxOutStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) { OEditBaseModel::write(_rxOutStream); _rxOutStream->writeShort(0x0003); - DBG_ASSERT(m_xAggregateSet.is(), "OFormattedModel::write : have no aggregate !"); - // mein Format (evtl. void) in ein persistentes Format bringen (der Supplier zusammen mit dem Key ist es zwar auch, // aber deswegen muessen wir ja nicht gleich den ganzen Supplier speichern, das waere ein klein wenig Overhead ;) - Reference<XNumberFormatsSupplier> xSupplier; Any aFmtKey; sal_Bool bVoidKey = sal_True; @@ -811,25 +669,19 @@ void OFormattedModel::write(const Reference<XObjectOutputStream>& _rxOutStream) { OSL_VERIFY( aSupplier >>= xSupplier ); } - aFmtKey = m_xAggregateSet->getPropertyValue(PROPERTY_FORMATKEY); bVoidKey = (!xSupplier.is() || !aFmtKey.hasValue()) || (isLoaded() && m_xOriginalFormatter.is()); // (kein Fomatter und/oder Key) oder (loaded und faked Formatter) } - _rxOutStream->writeBoolean(!bVoidKey); if (!bVoidKey) { // aus dem FormatKey und dem Formatter persistente Angaben basteln - Any aKey = m_xAggregateSet->getPropertyValue(PROPERTY_FORMATKEY); sal_Int32 nKey = aKey.hasValue() ? getINT32(aKey) : 0; - Reference<XNumberFormats> xFormats = xSupplier->getNumberFormats(); - OUString sFormatDescription; LanguageType eFormatLanguage = LANGUAGE_DONTKNOW; - static const OUString s_aLocaleProp ("Locale"); Reference<com::sun::star::beans::XPropertySet> xFormat = xFormats->getByKey(nKey); if (hasProperty(s_aLocaleProp, xFormat)) @@ -842,37 +694,29 @@ void OFormattedModel::write(const Reference<XObjectOutputStream>& _rxOutStream) eFormatLanguage = LanguageTag::convertToLanguageType( *pLocale, false); } } - static const OUString s_aFormatStringProp ("FormatString"); if (hasProperty(s_aFormatStringProp, xFormat)) xFormat->getPropertyValue(s_aFormatStringProp) >>= sFormatDescription; - _rxOutStream->writeUTF(sFormatDescription); _rxOutStream->writeLong((sal_Int32)eFormatLanguage); } - // version 2 : write the properties common to all OEditBaseModels writeCommonEditProperties(_rxOutStream); - // version 3 : write the effective value property of the aggregate // Due to a bug within the UnoControlFormattedFieldModel implementation (our default aggregate) this props value isn't correctly read // and this can't be corrected without being incompatible. // so we have our own handling. - // and to be a little bit more compatible we make the following section skippable { OStreamSection aDownCompat(_rxOutStream); - // a sub version within the skippable block _rxOutStream->writeShort(0x0000); - // version 0: the effective value of the aggregate Any aEffectiveValue; if (m_xAggregateSet.is()) { try { aEffectiveValue = m_xAggregateSet->getPropertyValue(PROPERTY_EFFECTIVE_VALUE); } catch(const Exception&) { } } - { OStreamSection aDownCompat2(_rxOutStream); switch (aEffectiveValue.getValueType().getTypeClass()) @@ -894,12 +738,10 @@ void OFormattedModel::write(const Reference<XObjectOutputStream>& _rxOutStream) } } -//------------------------------------------------------------------------------ void OFormattedModel::read(const Reference<XObjectInputStream>& _rxInStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) { OEditBaseModel::read(_rxInStream); sal_uInt16 nVersion = _rxInStream->readShort(); - Reference<XNumberFormatsSupplier> xSupplier; sal_Int32 nKey = -1; switch (nVersion) @@ -911,36 +753,30 @@ void OFormattedModel::read(const Reference<XObjectInputStream>& _rxInStream) thr sal_Bool bNonVoidKey = _rxInStream->readBoolean(); if (bNonVoidKey) { - // den String und die Language lesen .... + // read string and language... OUString sFormatDescription = _rxInStream->readUTF(); LanguageType eDescriptionLanguage = (LanguageType)_rxInStream->readLong(); - - // und daraus von einem Formatter zu einem Key zusammenwuerfeln lassen ... + // and let a formatter roll dice based on that to create a key... xSupplier = calcFormatsSupplier(); - // calcFormatsSupplier nimmt erst den vom Model, dann einen von der starform, dann einen ganz neuen .... + // calcFormatsSupplier first takes the one from the model, then one from the starform, then a new one... Reference<XNumberFormats> xFormats = xSupplier->getNumberFormats(); - if (xFormats.is()) { Locale aDescriptionLanguage( LanguageTag::convertToLocale(eDescriptionLanguage)); - nKey = xFormats->queryKey(sFormatDescription, aDescriptionLanguage, sal_False); if (nKey == (sal_Int32)-1) - { // noch nicht vorhanden in meinem Formatter ... + { // does not yet exist in my formatter... nKey = xFormats->addNew(sFormatDescription, aDescriptionLanguage); } } } if ((nVersion == 0x0002) || (nVersion == 0x0003)) readCommonEditProperties(_rxInStream); - if (nVersion == 0x0003) { // since version 3 there is a "skippable" block at this position OStreamSection aDownCompat(_rxInStream); - sal_Int16 nSubVersion = _rxInStream->readShort(); (void)nSubVersion; - // version 0 and higher : the "effective value" property Any aEffectiveValue; { @@ -959,7 +795,6 @@ void OFormattedModel::read(const Reference<XObjectInputStream>& _rxInStream) thr OSL_FAIL("FmXFormattedModel::read : unknown effective value type !"); } } - // this property is only to be set if we have no control source : in all other cases the base class did a // reset after it's read and this set the effective value to a default value if ( m_xAggregateSet.is() && getControlSource().isEmpty() ) @@ -977,11 +812,10 @@ void OFormattedModel::read(const Reference<XObjectInputStream>& _rxInStream) thr break; default : OSL_FAIL("OFormattedModel::read : unknown version !"); - // dann bleibt das Format des aggregierten Sets, wie es bei der Erzeugung ist : void + // then the format of the aggregated set stay like it was during creation: void defaultCommonEditProperties(); break; } - if ((nKey != -1) && m_xAggregateSet.is()) { m_xAggregateSet->setPropertyValue(PROPERTY_FORMATSSUPPLIER, makeAny(xSupplier)); @@ -994,20 +828,18 @@ void OFormattedModel::read(const Reference<XObjectInputStream>& _rxInStream) thr } } -//------------------------------------------------------------------------------ sal_uInt16 OFormattedModel::getPersistenceFlags() const { return (OEditBaseModel::getPersistenceFlags() & ~PF_HANDLE_COMMON_PROPS); // a) we do our own call to writeCommonEditProperties } -//------------------------------------------------------------------------------ sal_Bool OFormattedModel::commitControlValueToDbColumn( bool /*_bPostReset*/ ) { Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) ); if ( aControlValue != m_aSaveValue ) { - // Leerstring + EmptyIsNull = void + // empty string + EmptyIsNull = void if ( !aControlValue.hasValue() || ( ( aControlValue.getValueType().getTypeClass() == TypeClass_STRING ) && getString( aControlValue ).isEmpty() @@ -1040,14 +872,12 @@ sal_Bool OFormattedModel::commitControlValueToDbColumn( bool /*_bPostReset*/ ) return sal_True; } -//------------------------------------------------------------------------------ void OFormattedModel::onConnectedExternalValue( ) { OEditBaseModel::onConnectedExternalValue(); updateFormatterNullDate(); } -//------------------------------------------------------------------------------ Any OFormattedModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const { Any aControlValue; @@ -1055,11 +885,9 @@ Any OFormattedModel::translateExternalValueToControlValue( const Any& _rExternal { case TypeClass_VOID: break; - case TypeClass_STRING: aControlValue = _rExternalValue; break; - case TypeClass_BOOLEAN: { sal_Bool bExternalValue = sal_False; @@ -1067,7 +895,6 @@ Any OFormattedModel::translateExternalValueToControlValue( const Any& _rExternal aControlValue <<= (double)( bExternalValue ? 1 : 0 ); } break; - default: { if ( _rExternalValue.getValueType().equals( ::getCppuType( static_cast< UNODate* >( NULL ) ) ) ) @@ -1098,22 +925,17 @@ Any OFormattedModel::translateExternalValueToControlValue( const Any& _rExternal } } } - return aControlValue; } -//------------------------------------------------------------------------------ Any OFormattedModel::translateControlValueToExternalValue( ) const { OSL_PRECOND( hasExternalValueBinding(), "OFormattedModel::translateControlValueToExternalValue: precondition not met!" ); - Any aControlValue( getControlValue() ); if ( !aControlValue.hasValue() ) return aControlValue; - Any aExternalValue; - // translate into the external value type Type aExternalValueType( getExternalValueType() ); switch ( aExternalValueType.getTypeClass() ) @@ -1128,7 +950,6 @@ Any OFormattedModel::translateControlValueToExternalValue( ) const } } // NO break here! - case TypeClass_BOOLEAN: { double fValue = 0; @@ -1139,7 +960,6 @@ Any OFormattedModel::translateControlValueToExternalValue( ) const aExternalValue <<= (sal_Bool)( fValue ? sal_True : sal_False ); } break; - default: { double fValue = 0; @@ -1147,7 +967,6 @@ Any OFormattedModel::translateControlValueToExternalValue( ) const // if this asserts ... well, the somebody set the TreatAsNumeric property to false, // and the control value is a string. This implies some weird misconfiguration // of the FormattedModel, so we won't care for it for the moment. - if ( aExternalValueType.equals( ::getCppuType( static_cast< UNODate* >( NULL ) ) ) ) { aExternalValue <<= DBTypeConversion::toDate( fValue, m_aNullDate ); @@ -1172,26 +991,21 @@ Any OFormattedModel::translateControlValueToExternalValue( ) const return aExternalValue; } -//------------------------------------------------------------------------------ Any OFormattedModel::translateDbColumnToControlValue() { if ( m_bNumeric ) m_aSaveValue <<= DBTypeConversion::getValue( m_xColumn, m_aNullDate ); // #100056# OJ else m_aSaveValue <<= m_xColumn->getString(); - if ( m_xColumn->wasNull() ) m_aSaveValue.clear(); - return m_aSaveValue; } -// ----------------------------------------------------------------------------- Sequence< Type > OFormattedModel::getSupportedBindingTypes() { ::std::list< Type > aTypes; aTypes.push_back( ::getCppuType( static_cast< double* >( NULL ) ) ); - switch ( m_nKeyType & ~NumberFormat::DEFINED ) { case NumberFormat::DATE: @@ -1210,27 +1024,21 @@ Sequence< Type > OFormattedModel::getSupportedBindingTypes() aTypes.push_front(::getCppuType( static_cast< sal_Bool* >( NULL ) ) ); break; } - Sequence< Type > aTypesRet( aTypes.size() ); ::std::copy( aTypes.begin(), aTypes.end(), aTypesRet.getArray() ); return aTypesRet; } -//------------------------------------------------------------------------------ Any OFormattedModel::getDefaultForReset() const { return m_xAggregateSet->getPropertyValue( PROPERTY_EFFECTIVE_DEFAULT ); } -//------------------------------------------------------------------------------ void OFormattedModel::resetNoBroadcast() { OEditBaseModel::resetNoBroadcast(); m_aSaveValue.clear(); } - -//......................................................................... } -//......................................................................... /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |