1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_forms.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "Edit.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <com/sun/star/uno/Type.hxx> 34*cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/form/XSubmit.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/util/NumberFormat.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/awt/XVclWindowPeer.hpp> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir #include <vcl/svapp.hxx> 42*cdf0e10cSrcweir #include <tools/wintypes.hxx> 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir #include <connectivity/dbtools.hxx> 45*cdf0e10cSrcweir #include <connectivity/formattedcolumnvalue.hxx> 46*cdf0e10cSrcweir #include <connectivity/dbconversion.hxx> 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 49*cdf0e10cSrcweir #include <tools/debug.hxx> 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir #include <comphelper/container.hxx> 52*cdf0e10cSrcweir #include <comphelper/numbers.hxx> 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir using namespace dbtools; 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir //......................................................................... 57*cdf0e10cSrcweir namespace frm 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 60*cdf0e10cSrcweir using namespace ::com::sun::star::sdb; 61*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 62*cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx; 63*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 64*cdf0e10cSrcweir using namespace ::com::sun::star::container; 65*cdf0e10cSrcweir using namespace ::com::sun::star::form; 66*cdf0e10cSrcweir using namespace ::com::sun::star::awt; 67*cdf0e10cSrcweir using namespace ::com::sun::star::io; 68*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 69*cdf0e10cSrcweir using namespace ::com::sun::star::util; 70*cdf0e10cSrcweir using namespace ::com::sun::star::form::binding; 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir //------------------------------------------------------------------ 73*cdf0e10cSrcweir InterfaceRef SAL_CALL OEditControl_CreateInstance(const Reference< XMultiServiceFactory > & _rxFactory) 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir return *(new OEditControl(_rxFactory)); 76*cdf0e10cSrcweir } 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir //------------------------------------------------------------------------------ 79*cdf0e10cSrcweir Sequence<Type> OEditControl::_getTypes() 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir static Sequence<Type> aTypes; 82*cdf0e10cSrcweir if (!aTypes.getLength()) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir // my two base classes 85*cdf0e10cSrcweir aTypes = concatSequences(OBoundControl::_getTypes(), OEditControl_BASE::getTypes()); 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir return aTypes; 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir //------------------------------------------------------------------------------ 91*cdf0e10cSrcweir Any SAL_CALL OEditControl::queryAggregation(const Type& _rType) throw (RuntimeException) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir Any aReturn = OBoundControl::queryAggregation(_rType); 94*cdf0e10cSrcweir if (!aReturn.hasValue()) 95*cdf0e10cSrcweir aReturn = OEditControl_BASE::queryInterface(_rType); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir return aReturn; 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir DBG_NAME(OEditControl); 101*cdf0e10cSrcweir //------------------------------------------------------------------------------ 102*cdf0e10cSrcweir OEditControl::OEditControl(const Reference<XMultiServiceFactory>& _rxFactory) 103*cdf0e10cSrcweir :OBoundControl( _rxFactory, FRM_SUN_CONTROL_RICHTEXTCONTROL ) 104*cdf0e10cSrcweir ,m_aChangeListeners(m_aMutex) 105*cdf0e10cSrcweir ,m_nKeyEvent( 0 ) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir DBG_CTOR(OEditControl,NULL); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir increment(m_refCount); 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir Reference<XWindow> xComp; 112*cdf0e10cSrcweir if (query_aggregation(m_xAggregate, xComp)) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir xComp->addFocusListener(this); 115*cdf0e10cSrcweir xComp->addKeyListener(this); 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir decrement(m_refCount); 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir //------------------------------------------------------------------------------ 122*cdf0e10cSrcweir OEditControl::~OEditControl() 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir if( m_nKeyEvent ) 125*cdf0e10cSrcweir Application::RemoveUserEvent( m_nKeyEvent ); 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir if (!OComponentHelper::rBHelper.bDisposed) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir acquire(); 130*cdf0e10cSrcweir dispose(); 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir DBG_DTOR(OEditControl,NULL); 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir // XChangeBroadcaster 137*cdf0e10cSrcweir //------------------------------------------------------------------------------ 138*cdf0e10cSrcweir void OEditControl::addChangeListener(const Reference<XChangeListener>& l) throw ( ::com::sun::star::uno::RuntimeException) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir m_aChangeListeners.addInterface( l ); 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir //------------------------------------------------------------------------------ 144*cdf0e10cSrcweir void OEditControl::removeChangeListener(const Reference<XChangeListener>& l) throw ( ::com::sun::star::uno::RuntimeException) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir m_aChangeListeners.removeInterface( l ); 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir // OComponentHelper 150*cdf0e10cSrcweir //------------------------------------------------------------------------------ 151*cdf0e10cSrcweir void OEditControl::disposing() 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir OBoundControl::disposing(); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir EventObject aEvt(static_cast<XWeak*>(this)); 156*cdf0e10cSrcweir m_aChangeListeners.disposeAndClear(aEvt); 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir // XServiceInfo 160*cdf0e10cSrcweir //------------------------------------------------------------------------------ 161*cdf0e10cSrcweir StringSequence OEditControl::getSupportedServiceNames() throw() 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir StringSequence aSupported = OBoundControl::getSupportedServiceNames(); 164*cdf0e10cSrcweir aSupported.realloc(aSupported.getLength() + 1); 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir ::rtl::OUString*pArray = aSupported.getArray(); 167*cdf0e10cSrcweir pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_TEXTFIELD; 168*cdf0e10cSrcweir return aSupported; 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir // XEventListener 172*cdf0e10cSrcweir //------------------------------------------------------------------------------ 173*cdf0e10cSrcweir void OEditControl::disposing(const EventObject& Source) throw( RuntimeException ) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir OBoundControl::disposing(Source); 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir // XFocusListener 179*cdf0e10cSrcweir //------------------------------------------------------------------------------ 180*cdf0e10cSrcweir void OEditControl::focusGained( const FocusEvent& /*e*/ ) throw ( ::com::sun::star::uno::RuntimeException) 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir Reference<XPropertySet> xSet(getModel(), UNO_QUERY); 183*cdf0e10cSrcweir if (xSet.is()) 184*cdf0e10cSrcweir xSet->getPropertyValue( PROPERTY_TEXT ) >>= m_aHtmlChangeValue; 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir //------------------------------------------------------------------------------ 188*cdf0e10cSrcweir void OEditControl::focusLost( const FocusEvent& /*e*/ ) throw ( ::com::sun::star::uno::RuntimeException) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir Reference<XPropertySet> xSet(getModel(), UNO_QUERY); 191*cdf0e10cSrcweir if (xSet.is()) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir ::rtl::OUString sNewHtmlChangeValue; 194*cdf0e10cSrcweir xSet->getPropertyValue( PROPERTY_TEXT ) >>= sNewHtmlChangeValue; 195*cdf0e10cSrcweir if( sNewHtmlChangeValue != m_aHtmlChangeValue ) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir EventObject aEvt( *this ); 198*cdf0e10cSrcweir m_aChangeListeners.notifyEach( &XChangeListener::changed, aEvt ); 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir // XKeyListener 204*cdf0e10cSrcweir //------------------------------------------------------------------------------ 205*cdf0e10cSrcweir void OEditControl::keyPressed(const ::com::sun::star::awt::KeyEvent& e) throw ( ::com::sun::star::uno::RuntimeException) 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir if( e.KeyCode != KEY_RETURN || e.Modifiers != 0 ) 208*cdf0e10cSrcweir return; 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir // Steht das Control in einem Formular mit einer Submit-URL? 211*cdf0e10cSrcweir Reference<XPropertySet> xSet(getModel(), UNO_QUERY); 212*cdf0e10cSrcweir if( !xSet.is() ) 213*cdf0e10cSrcweir return; 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir // nicht fuer multiline edits 216*cdf0e10cSrcweir Any aTmp( xSet->getPropertyValue(PROPERTY_MULTILINE)); 217*cdf0e10cSrcweir if ((aTmp.getValueType().equals(::getBooleanCppuType())) && getBOOL(aTmp)) 218*cdf0e10cSrcweir return; 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir Reference<XFormComponent> xFComp(xSet, UNO_QUERY); 221*cdf0e10cSrcweir InterfaceRef xParent = xFComp->getParent(); 222*cdf0e10cSrcweir if( !xParent.is() ) 223*cdf0e10cSrcweir return; 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir Reference<XPropertySet> xFormSet(xParent, UNO_QUERY); 226*cdf0e10cSrcweir if( !xFormSet.is() ) 227*cdf0e10cSrcweir return; 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir aTmp = xFormSet->getPropertyValue( PROPERTY_TARGET_URL ); 230*cdf0e10cSrcweir if (!aTmp.getValueType().equals(::getCppuType((const ::rtl::OUString*)NULL)) || 231*cdf0e10cSrcweir !getString(aTmp).getLength() ) 232*cdf0e10cSrcweir return; 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir Reference<XIndexAccess> xElements(xParent, UNO_QUERY); 235*cdf0e10cSrcweir sal_Int32 nCount = xElements->getCount(); 236*cdf0e10cSrcweir if( nCount > 1 ) 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir Reference<XPropertySet> xFCSet; 239*cdf0e10cSrcweir for( sal_Int32 nIndex=0; nIndex < nCount; nIndex++ ) 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir // Any aElement(xElements->getByIndex(nIndex)); 242*cdf0e10cSrcweir xElements->getByIndex(nIndex) >>= xFCSet; 243*cdf0e10cSrcweir OSL_ENSURE(xFCSet.is(),"OEditControl::keyPressed: No XPropertySet!"); 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir if (hasProperty(PROPERTY_CLASSID, xFCSet) && 246*cdf0e10cSrcweir getINT16(xFCSet->getPropertyValue(PROPERTY_CLASSID)) == FormComponentType::TEXTFIELD) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir // Noch ein weiteres Edit gefunden ==> dann nicht submitten 249*cdf0e10cSrcweir if (xFCSet != xSet) 250*cdf0e10cSrcweir return; 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir // Da wir noch im Haender stehen, submit asynchron ausloesen 256*cdf0e10cSrcweir if( m_nKeyEvent ) 257*cdf0e10cSrcweir Application::RemoveUserEvent( m_nKeyEvent ); 258*cdf0e10cSrcweir m_nKeyEvent = Application::PostUserEvent( LINK(this, OEditControl,OnKeyPressed) ); 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir //------------------------------------------------------------------------------ 262*cdf0e10cSrcweir void OEditControl::keyReleased(const ::com::sun::star::awt::KeyEvent& /*e*/) throw ( ::com::sun::star::uno::RuntimeException) 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir //------------------------------------------------------------------------------ 267*cdf0e10cSrcweir IMPL_LINK(OEditControl, OnKeyPressed, void*, /*EMPTYARG*/) 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir m_nKeyEvent = 0; 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir Reference<XFormComponent> xFComp(getModel(), UNO_QUERY); 272*cdf0e10cSrcweir InterfaceRef xParent = xFComp->getParent(); 273*cdf0e10cSrcweir Reference<XSubmit> xSubmit(xParent, UNO_QUERY); 274*cdf0e10cSrcweir if (xSubmit.is()) 275*cdf0e10cSrcweir xSubmit->submit( Reference<XControl>(), ::com::sun::star::awt::MouseEvent() ); 276*cdf0e10cSrcweir return 0L; 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir //------------------------------------------------------------------ 280*cdf0e10cSrcweir void SAL_CALL OEditControl::createPeer( const Reference< XToolkit>& _rxToolkit, const Reference< XWindowPeer>& _rxParent ) throw ( RuntimeException ) 281*cdf0e10cSrcweir { 282*cdf0e10cSrcweir OBoundControl::createPeer(_rxToolkit, _rxParent); 283*cdf0e10cSrcweir } 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir /*************************************************************************/ 286*cdf0e10cSrcweir //------------------------------------------------------------------ 287*cdf0e10cSrcweir InterfaceRef SAL_CALL OEditModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) 288*cdf0e10cSrcweir { 289*cdf0e10cSrcweir return *(new OEditModel(_rxFactory)); 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir //------------------------------------------------------------------------------ 293*cdf0e10cSrcweir Sequence<Type> OEditModel::_getTypes() 294*cdf0e10cSrcweir { 295*cdf0e10cSrcweir return OEditBaseModel::_getTypes(); 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir DBG_NAME(OEditModel); 300*cdf0e10cSrcweir //------------------------------------------------------------------ 301*cdf0e10cSrcweir OEditModel::OEditModel(const Reference<XMultiServiceFactory>& _rxFactory) 302*cdf0e10cSrcweir :OEditBaseModel( _rxFactory, FRM_SUN_COMPONENT_RICHTEXTCONTROL, FRM_SUN_CONTROL_TEXTFIELD, sal_True, sal_True ) 303*cdf0e10cSrcweir ,m_bMaxTextLenModified(sal_False) 304*cdf0e10cSrcweir ,m_bWritingFormattedFake(sal_False) 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir DBG_CTOR(OEditModel,NULL); 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir m_nClassId = FormComponentType::TEXTFIELD; 309*cdf0e10cSrcweir initValueProperty( PROPERTY_TEXT, PROPERTY_ID_TEXT ); 310*cdf0e10cSrcweir } 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir //------------------------------------------------------------------ 313*cdf0e10cSrcweir OEditModel::OEditModel( const OEditModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory ) 314*cdf0e10cSrcweir :OEditBaseModel( _pOriginal, _rxFactory ) 315*cdf0e10cSrcweir ,m_bMaxTextLenModified(sal_False) 316*cdf0e10cSrcweir ,m_bWritingFormattedFake(sal_False) 317*cdf0e10cSrcweir { 318*cdf0e10cSrcweir DBG_CTOR( OEditModel, NULL ); 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir // Note that most of the properties are not clone from the original object: 321*cdf0e10cSrcweir // Things as the format key, it's type, and such, depend on the field being part of a loaded form 322*cdf0e10cSrcweir // (they're initialized in onConnectedDbColumn). Even if the original object _is_ part of such a form, we ourself 323*cdf0e10cSrcweir // certainly aren't, so these members are defaulted. If we're inserted into a form which is already loaded, 324*cdf0e10cSrcweir // they will be set to new values, anyway .... 325*cdf0e10cSrcweir } 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir //------------------------------------------------------------------ 328*cdf0e10cSrcweir OEditModel::~OEditModel() 329*cdf0e10cSrcweir { 330*cdf0e10cSrcweir if (!OComponentHelper::rBHelper.bDisposed) 331*cdf0e10cSrcweir { 332*cdf0e10cSrcweir acquire(); 333*cdf0e10cSrcweir dispose(); 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir DBG_DTOR(OEditModel,NULL); 337*cdf0e10cSrcweir } 338*cdf0e10cSrcweir 339*cdf0e10cSrcweir //------------------------------------------------------------------------------ 340*cdf0e10cSrcweir IMPLEMENT_DEFAULT_CLONING( OEditModel ) 341*cdf0e10cSrcweir 342*cdf0e10cSrcweir //------------------------------------------------------------------------------ 343*cdf0e10cSrcweir void OEditModel::disposing() 344*cdf0e10cSrcweir { 345*cdf0e10cSrcweir OEditBaseModel::disposing(); 346*cdf0e10cSrcweir m_pValueFormatter.reset(); 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir // XPersistObject 350*cdf0e10cSrcweir //------------------------------------------------------------------------------ 351*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OEditModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException) 352*cdf0e10cSrcweir { 353*cdf0e10cSrcweir return FRM_COMPONENT_EDIT; // old (non-sun) name for compatibility ! 354*cdf0e10cSrcweir } 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir // XServiceInfo 357*cdf0e10cSrcweir //------------------------------------------------------------------------------ 358*cdf0e10cSrcweir StringSequence SAL_CALL OEditModel::getSupportedServiceNames() throw() 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir StringSequence aSupported = OBoundControlModel::getSupportedServiceNames(); 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir sal_Int32 nOldLen = aSupported.getLength(); 363*cdf0e10cSrcweir aSupported.realloc( nOldLen + 8 ); 364*cdf0e10cSrcweir ::rtl::OUString* pStoreTo = aSupported.getArray() + nOldLen; 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir *pStoreTo++ = BINDABLE_CONTROL_MODEL; 367*cdf0e10cSrcweir *pStoreTo++ = DATA_AWARE_CONTROL_MODEL; 368*cdf0e10cSrcweir *pStoreTo++ = VALIDATABLE_CONTROL_MODEL; 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir *pStoreTo++ = BINDABLE_DATA_AWARE_CONTROL_MODEL; 371*cdf0e10cSrcweir *pStoreTo++ = VALIDATABLE_BINDABLE_CONTROL_MODEL; 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir *pStoreTo++ = FRM_SUN_COMPONENT_TEXTFIELD; 374*cdf0e10cSrcweir *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_TEXTFIELD; 375*cdf0e10cSrcweir *pStoreTo++ = BINDABLE_DATABASE_TEXT_FIELD; 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir return aSupported; 378*cdf0e10cSrcweir } 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir // XPropertySet 381*cdf0e10cSrcweir void SAL_CALL OEditModel::getFastPropertyValue(Any& rValue, sal_Int32 nHandle ) const 382*cdf0e10cSrcweir { 383*cdf0e10cSrcweir if ( PROPERTY_ID_PERSISTENCE_MAXTEXTLENGTH == nHandle ) 384*cdf0e10cSrcweir { 385*cdf0e10cSrcweir if ( m_bMaxTextLenModified ) 386*cdf0e10cSrcweir rValue <<= sal_Int16(0); 387*cdf0e10cSrcweir else if ( m_xAggregateSet.is() ) 388*cdf0e10cSrcweir rValue = m_xAggregateSet->getPropertyValue(PROPERTY_MAXTEXTLEN); 389*cdf0e10cSrcweir } 390*cdf0e10cSrcweir else 391*cdf0e10cSrcweir { 392*cdf0e10cSrcweir OEditBaseModel::getFastPropertyValue(rValue, nHandle ); 393*cdf0e10cSrcweir } 394*cdf0e10cSrcweir } 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir //------------------------------------------------------------------------------ 397*cdf0e10cSrcweir void OEditModel::describeFixedProperties( Sequence< Property >& _rProps ) const 398*cdf0e10cSrcweir { 399*cdf0e10cSrcweir BEGIN_DESCRIBE_PROPERTIES( 5, OEditBaseModel ) 400*cdf0e10cSrcweir DECL_PROP2(PERSISTENCE_MAXTEXTLENGTH,sal_Int16, READONLY, TRANSIENT); 401*cdf0e10cSrcweir DECL_PROP2(DEFAULT_TEXT, ::rtl::OUString, BOUND, MAYBEDEFAULT); 402*cdf0e10cSrcweir DECL_BOOL_PROP1(EMPTY_IS_NULL, BOUND); 403*cdf0e10cSrcweir DECL_PROP1(TABINDEX, sal_Int16, BOUND); 404*cdf0e10cSrcweir DECL_BOOL_PROP2(FILTERPROPOSAL, BOUND, MAYBEDEFAULT); 405*cdf0e10cSrcweir END_DESCRIBE_PROPERTIES(); 406*cdf0e10cSrcweir } 407*cdf0e10cSrcweir 408*cdf0e10cSrcweir //------------------------------------------------------------------------------ 409*cdf0e10cSrcweir void OEditModel::describeAggregateProperties( Sequence< Property >& _rAggregateProps ) const 410*cdf0e10cSrcweir { 411*cdf0e10cSrcweir OEditBaseModel::describeAggregateProperties( _rAggregateProps ); 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir // our aggregate is a rich text model, which also derives from OControlModel, as 414*cdf0e10cSrcweir // do we, so we need to remove some duplicate properties 415*cdf0e10cSrcweir RemoveProperty( _rAggregateProps, PROPERTY_TABINDEX ); 416*cdf0e10cSrcweir RemoveProperty( _rAggregateProps, PROPERTY_CLASSID ); 417*cdf0e10cSrcweir RemoveProperty( _rAggregateProps, PROPERTY_NAME ); 418*cdf0e10cSrcweir RemoveProperty( _rAggregateProps, PROPERTY_TAG ); 419*cdf0e10cSrcweir RemoveProperty( _rAggregateProps, PROPERTY_NATIVE_LOOK ); 420*cdf0e10cSrcweir 421*cdf0e10cSrcweir } 422*cdf0e10cSrcweir 423*cdf0e10cSrcweir //------------------------------------------------------------------------------ 424*cdf0e10cSrcweir bool OEditModel::implActsAsRichText( ) const 425*cdf0e10cSrcweir { 426*cdf0e10cSrcweir sal_Bool bActAsRichText = sal_False; 427*cdf0e10cSrcweir if ( m_xAggregateSet.is() ) 428*cdf0e10cSrcweir { 429*cdf0e10cSrcweir OSL_VERIFY( m_xAggregateSet->getPropertyValue( PROPERTY_RICH_TEXT ) >>= bActAsRichText ); 430*cdf0e10cSrcweir } 431*cdf0e10cSrcweir return bActAsRichText; 432*cdf0e10cSrcweir } 433*cdf0e10cSrcweir 434*cdf0e10cSrcweir //------------------------------------------------------------------------------ 435*cdf0e10cSrcweir void SAL_CALL OEditModel::reset( ) throw(RuntimeException) 436*cdf0e10cSrcweir { 437*cdf0e10cSrcweir // no reset if we currently act as rich text control 438*cdf0e10cSrcweir if ( implActsAsRichText() ) 439*cdf0e10cSrcweir return; 440*cdf0e10cSrcweir 441*cdf0e10cSrcweir OEditBaseModel::reset(); 442*cdf0e10cSrcweir } 443*cdf0e10cSrcweir 444*cdf0e10cSrcweir //------------------------------------------------------------------------------ 445*cdf0e10cSrcweir namespace 446*cdf0e10cSrcweir { 447*cdf0e10cSrcweir void lcl_transferProperties( const Reference< XPropertySet >& _rxSource, const Reference< XPropertySet >& _rxDest ) 448*cdf0e10cSrcweir { 449*cdf0e10cSrcweir try 450*cdf0e10cSrcweir { 451*cdf0e10cSrcweir Reference< XPropertySetInfo > xSourceInfo; 452*cdf0e10cSrcweir if ( _rxSource.is() ) 453*cdf0e10cSrcweir xSourceInfo = _rxSource->getPropertySetInfo(); 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir Reference< XPropertySetInfo > xDestInfo; 456*cdf0e10cSrcweir if ( _rxDest.is() ) 457*cdf0e10cSrcweir xDestInfo = _rxDest->getPropertySetInfo(); 458*cdf0e10cSrcweir 459*cdf0e10cSrcweir if ( !xSourceInfo.is() || !xDestInfo.is() ) 460*cdf0e10cSrcweir { 461*cdf0e10cSrcweir OSL_ENSURE( sal_False, "lcl_transferProperties: invalid property set(s)!" ); 462*cdf0e10cSrcweir return; 463*cdf0e10cSrcweir } 464*cdf0e10cSrcweir 465*cdf0e10cSrcweir Sequence< Property > aSourceProps( xSourceInfo->getProperties() ); 466*cdf0e10cSrcweir const Property* pSourceProps = aSourceProps.getConstArray(); 467*cdf0e10cSrcweir const Property* pSourcePropsEnd = aSourceProps.getConstArray() + aSourceProps.getLength(); 468*cdf0e10cSrcweir while ( pSourceProps != pSourcePropsEnd ) 469*cdf0e10cSrcweir { 470*cdf0e10cSrcweir if ( !xDestInfo->hasPropertyByName( pSourceProps->Name ) ) 471*cdf0e10cSrcweir { 472*cdf0e10cSrcweir ++pSourceProps; 473*cdf0e10cSrcweir continue; 474*cdf0e10cSrcweir } 475*cdf0e10cSrcweir 476*cdf0e10cSrcweir Property aDestProp( xDestInfo->getPropertyByName( pSourceProps->Name ) ); 477*cdf0e10cSrcweir if ( 0 != ( aDestProp.Attributes & PropertyAttribute::READONLY ) ) 478*cdf0e10cSrcweir { 479*cdf0e10cSrcweir ++pSourceProps; 480*cdf0e10cSrcweir continue; 481*cdf0e10cSrcweir } 482*cdf0e10cSrcweir 483*cdf0e10cSrcweir try 484*cdf0e10cSrcweir { 485*cdf0e10cSrcweir _rxDest->setPropertyValue( pSourceProps->Name, _rxSource->getPropertyValue( pSourceProps->Name ) ); 486*cdf0e10cSrcweir } 487*cdf0e10cSrcweir catch( IllegalArgumentException e ) 488*cdf0e10cSrcweir { 489*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 490*cdf0e10cSrcweir ::rtl::OString sMessage( "could not transfer the property named '" ); 491*cdf0e10cSrcweir sMessage += ::rtl::OString( pSourceProps->Name.getStr(), pSourceProps->Name.getLength(), RTL_TEXTENCODING_ASCII_US ); 492*cdf0e10cSrcweir sMessage += ::rtl::OString( "'." ); 493*cdf0e10cSrcweir if ( e.Message.getLength() ) 494*cdf0e10cSrcweir { 495*cdf0e10cSrcweir sMessage += ::rtl::OString( "\n\nMessage:\n" ); 496*cdf0e10cSrcweir sMessage += ::rtl::OString( e.Message.getStr(), e.Message.getLength(), RTL_TEXTENCODING_ASCII_US ); 497*cdf0e10cSrcweir } 498*cdf0e10cSrcweir OSL_ENSURE( sal_False, sMessage.getStr() ); 499*cdf0e10cSrcweir #endif 500*cdf0e10cSrcweir } 501*cdf0e10cSrcweir 502*cdf0e10cSrcweir ++pSourceProps; 503*cdf0e10cSrcweir } 504*cdf0e10cSrcweir } 505*cdf0e10cSrcweir catch( const Exception& ) 506*cdf0e10cSrcweir { 507*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 508*cdf0e10cSrcweir } 509*cdf0e10cSrcweir } 510*cdf0e10cSrcweir } 511*cdf0e10cSrcweir 512*cdf0e10cSrcweir //------------------------------------------------------------------------------ 513*cdf0e10cSrcweir void OEditModel::writeAggregate( const Reference< XObjectOutputStream >& _rxOutStream ) const 514*cdf0e10cSrcweir { 515*cdf0e10cSrcweir // we need to fake the writing of our aggregate. Since #i24387#, we have another aggregate, 516*cdf0e10cSrcweir // but for compatibility, we need to use an "old" aggregate for writing and reading 517*cdf0e10cSrcweir 518*cdf0e10cSrcweir Reference< XPropertySet > xFakedAggregate( 519*cdf0e10cSrcweir getContext().createComponent( (rtl::OUString)VCL_CONTROLMODEL_EDIT ), 520*cdf0e10cSrcweir UNO_QUERY 521*cdf0e10cSrcweir ); 522*cdf0e10cSrcweir OSL_ENSURE( xFakedAggregate.is(), "OEditModel::writeAggregate: could not create an old EditControlModel!" ); 523*cdf0e10cSrcweir if ( !xFakedAggregate.is() ) 524*cdf0e10cSrcweir return; 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir lcl_transferProperties( m_xAggregateSet, xFakedAggregate ); 527*cdf0e10cSrcweir 528*cdf0e10cSrcweir Reference< XPersistObject > xFakedPersist( xFakedAggregate, UNO_QUERY ); 529*cdf0e10cSrcweir OSL_ENSURE( xFakedPersist.is(), "OEditModel::writeAggregate: no XPersistObject!" ); 530*cdf0e10cSrcweir if ( xFakedPersist.is() ) 531*cdf0e10cSrcweir xFakedPersist->write( _rxOutStream ); 532*cdf0e10cSrcweir } 533*cdf0e10cSrcweir 534*cdf0e10cSrcweir //------------------------------------------------------------------------------ 535*cdf0e10cSrcweir void OEditModel::readAggregate( const Reference< XObjectInputStream >& _rxInStream ) 536*cdf0e10cSrcweir { 537*cdf0e10cSrcweir // we need to fake the reading of our aggregate. Since #i24387#, we have another aggregate, 538*cdf0e10cSrcweir // but for compatibility, we need to use an "old" aggregate for writing and reading 539*cdf0e10cSrcweir 540*cdf0e10cSrcweir Reference< XPropertySet > xFakedAggregate( 541*cdf0e10cSrcweir getContext().createComponent( (rtl::OUString)VCL_CONTROLMODEL_EDIT ), 542*cdf0e10cSrcweir UNO_QUERY 543*cdf0e10cSrcweir ); 544*cdf0e10cSrcweir Reference< XPersistObject > xFakedPersist( xFakedAggregate, UNO_QUERY ); 545*cdf0e10cSrcweir OSL_ENSURE( xFakedPersist.is(), "OEditModel::readAggregate: no XPersistObject, or no faked aggregate at all!" ); 546*cdf0e10cSrcweir if ( xFakedPersist.is() ) 547*cdf0e10cSrcweir { 548*cdf0e10cSrcweir xFakedPersist->read( _rxInStream ); 549*cdf0e10cSrcweir lcl_transferProperties( xFakedAggregate, m_xAggregateSet ); 550*cdf0e10cSrcweir } 551*cdf0e10cSrcweir } 552*cdf0e10cSrcweir 553*cdf0e10cSrcweir //------------------------------------------------------------------------------ 554*cdf0e10cSrcweir void OEditModel::write(const Reference<XObjectOutputStream>& _rxOutStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 555*cdf0e10cSrcweir { 556*cdf0e10cSrcweir Any aCurrentText; 557*cdf0e10cSrcweir sal_Int16 nOldTextLen = 0; 558*cdf0e10cSrcweir // bin ich gerade loaded und habe dazu zeitweilig die MaxTextLen umgesetzt ? 559*cdf0e10cSrcweir if ( m_bMaxTextLenModified ) 560*cdf0e10cSrcweir { // -> fuer die Dauer des Speicherns meinem aggregierten Model die alte TextLen einreden 561*cdf0e10cSrcweir 562*cdf0e10cSrcweir // before doing this we have to save the current text value of the aggregate, as this may be affected by resetting the text len 563*cdf0e10cSrcweir // FS - 08.12.99 - 70606 564*cdf0e10cSrcweir aCurrentText = m_xAggregateSet->getPropertyValue(PROPERTY_TEXT); 565*cdf0e10cSrcweir 566*cdf0e10cSrcweir m_xAggregateSet->getPropertyValue(PROPERTY_MAXTEXTLEN) >>= nOldTextLen; 567*cdf0e10cSrcweir m_xAggregateSet->setPropertyValue(PROPERTY_MAXTEXTLEN, makeAny((sal_Int16)0)); 568*cdf0e10cSrcweir } 569*cdf0e10cSrcweir 570*cdf0e10cSrcweir OEditBaseModel::write(_rxOutStream); 571*cdf0e10cSrcweir 572*cdf0e10cSrcweir if ( m_bMaxTextLenModified ) 573*cdf0e10cSrcweir { // wieder zuruecksetzen 574*cdf0e10cSrcweir m_xAggregateSet->setPropertyValue(PROPERTY_MAXTEXTLEN, makeAny(nOldTextLen)); 575*cdf0e10cSrcweir // and reset the text 576*cdf0e10cSrcweir // First we set it to an empty string : Without this the second setPropertyValue would not do anything as it thinks 577*cdf0e10cSrcweir // we aren't changing the prop (it didn't notify the - implicite - change of the text prop while setting the max text len) 578*cdf0e10cSrcweir // This seems to be a bug with in toolkit's EditControl-implementation. 579*cdf0e10cSrcweir m_xAggregateSet->setPropertyValue(PROPERTY_TEXT, makeAny(::rtl::OUString())); 580*cdf0e10cSrcweir m_xAggregateSet->setPropertyValue(PROPERTY_TEXT, aCurrentText); 581*cdf0e10cSrcweir } 582*cdf0e10cSrcweir } 583*cdf0e10cSrcweir 584*cdf0e10cSrcweir //------------------------------------------------------------------------------ 585*cdf0e10cSrcweir void OEditModel::read(const Reference<XObjectInputStream>& _rxInStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 586*cdf0e10cSrcweir { 587*cdf0e10cSrcweir OEditBaseModel::read(_rxInStream); 588*cdf0e10cSrcweir 589*cdf0e10cSrcweir // Some versions (5.1 'til about 552) wrote a wrong DefaultControl-property value which is unknown 590*cdf0e10cSrcweir // to older versions (5.0). 591*cdf0e10cSrcweir // correct this ... 592*cdf0e10cSrcweir if (m_xAggregateSet.is()) 593*cdf0e10cSrcweir { 594*cdf0e10cSrcweir Any aDefaultControl = m_xAggregateSet->getPropertyValue(PROPERTY_DEFAULTCONTROL); 595*cdf0e10cSrcweir if ( (aDefaultControl.getValueType().getTypeClass() == TypeClass_STRING) 596*cdf0e10cSrcweir && (getString(aDefaultControl).compareTo(STARDIV_ONE_FORM_CONTROL_TEXTFIELD) == COMPARE_EQUAL) 597*cdf0e10cSrcweir ) 598*cdf0e10cSrcweir { 599*cdf0e10cSrcweir m_xAggregateSet->setPropertyValue( PROPERTY_DEFAULTCONTROL, makeAny( (::rtl::OUString)STARDIV_ONE_FORM_CONTROL_EDIT ) ); 600*cdf0e10cSrcweir // Older as well as current versions should understand this : the former knew only the STARDIV_ONE_FORM_CONTROL_EDIT, 601*cdf0e10cSrcweir // the latter are registered for both STARDIV_ONE_FORM_CONTROL_EDIT and STARDIV_ONE_FORM_CONTROL_TEXTFIELD. 602*cdf0e10cSrcweir } 603*cdf0e10cSrcweir } 604*cdf0e10cSrcweir } 605*cdf0e10cSrcweir 606*cdf0e10cSrcweir //------------------------------------------------------------------------------ 607*cdf0e10cSrcweir sal_uInt16 OEditModel::getPersistenceFlags() const 608*cdf0e10cSrcweir { 609*cdf0e10cSrcweir sal_uInt16 nFlags = OEditBaseModel::getPersistenceFlags(); 610*cdf0e10cSrcweir 611*cdf0e10cSrcweir if (m_bWritingFormattedFake) 612*cdf0e10cSrcweir nFlags |= PF_FAKE_FORMATTED_FIELD; 613*cdf0e10cSrcweir 614*cdf0e10cSrcweir return nFlags; 615*cdf0e10cSrcweir } 616*cdf0e10cSrcweir 617*cdf0e10cSrcweir //------------------------------------------------------------------------------ 618*cdf0e10cSrcweir void OEditModel::onConnectedDbColumn( const Reference< XInterface >& _rxForm ) 619*cdf0e10cSrcweir { 620*cdf0e10cSrcweir Reference< XPropertySet > xField = getField(); 621*cdf0e10cSrcweir if ( xField.is() ) 622*cdf0e10cSrcweir { 623*cdf0e10cSrcweir m_pValueFormatter.reset( new ::dbtools::FormattedColumnValue( getContext(), Reference< XRowSet >( _rxForm, UNO_QUERY ), xField ) ); 624*cdf0e10cSrcweir 625*cdf0e10cSrcweir if ( m_pValueFormatter->getKeyType() != NumberFormat::SCIENTIFIC ) 626*cdf0e10cSrcweir { 627*cdf0e10cSrcweir m_bMaxTextLenModified = getINT16(m_xAggregateSet->getPropertyValue(PROPERTY_MAXTEXTLEN)) != 0; 628*cdf0e10cSrcweir if ( !m_bMaxTextLenModified ) 629*cdf0e10cSrcweir { 630*cdf0e10cSrcweir sal_Int32 nFieldLen = 0; 631*cdf0e10cSrcweir xField->getPropertyValue(::rtl::OUString::createFromAscii("Precision")) >>= nFieldLen; 632*cdf0e10cSrcweir 633*cdf0e10cSrcweir if (nFieldLen && nFieldLen <= USHRT_MAX) 634*cdf0e10cSrcweir { 635*cdf0e10cSrcweir Any aVal; 636*cdf0e10cSrcweir aVal <<= (sal_Int16)nFieldLen; 637*cdf0e10cSrcweir m_xAggregateSet->setPropertyValue(PROPERTY_MAXTEXTLEN, aVal); 638*cdf0e10cSrcweir 639*cdf0e10cSrcweir m_bMaxTextLenModified = sal_True; 640*cdf0e10cSrcweir } 641*cdf0e10cSrcweir } 642*cdf0e10cSrcweir else 643*cdf0e10cSrcweir m_bMaxTextLenModified = sal_False; // to get sure that the text len won't be set in unloaded 644*cdf0e10cSrcweir } 645*cdf0e10cSrcweir } 646*cdf0e10cSrcweir } 647*cdf0e10cSrcweir 648*cdf0e10cSrcweir //------------------------------------------------------------------------------ 649*cdf0e10cSrcweir void OEditModel::onDisconnectedDbColumn() 650*cdf0e10cSrcweir { 651*cdf0e10cSrcweir OEditBaseModel::onDisconnectedDbColumn(); 652*cdf0e10cSrcweir 653*cdf0e10cSrcweir m_pValueFormatter.reset(); 654*cdf0e10cSrcweir 655*cdf0e10cSrcweir if ( hasField() && m_bMaxTextLenModified ) 656*cdf0e10cSrcweir { 657*cdf0e10cSrcweir Any aVal; 658*cdf0e10cSrcweir aVal <<= (sal_Int16)0; // nur wenn es 0 war, habe ich es in onConnectedDbColumn umgesetzt 659*cdf0e10cSrcweir m_xAggregateSet->setPropertyValue(PROPERTY_MAXTEXTLEN, aVal); 660*cdf0e10cSrcweir m_bMaxTextLenModified = sal_False; 661*cdf0e10cSrcweir } 662*cdf0e10cSrcweir } 663*cdf0e10cSrcweir 664*cdf0e10cSrcweir //------------------------------------------------------------------------------ 665*cdf0e10cSrcweir sal_Bool OEditModel::approveDbColumnType( sal_Int32 _nColumnType ) 666*cdf0e10cSrcweir { 667*cdf0e10cSrcweir // if we act as rich text curently, we do not allow binding to a database column 668*cdf0e10cSrcweir if ( implActsAsRichText() ) 669*cdf0e10cSrcweir return sal_False; 670*cdf0e10cSrcweir 671*cdf0e10cSrcweir return OEditBaseModel::approveDbColumnType( _nColumnType ); 672*cdf0e10cSrcweir } 673*cdf0e10cSrcweir 674*cdf0e10cSrcweir //------------------------------------------------------------------------------ 675*cdf0e10cSrcweir void OEditModel::resetNoBroadcast() 676*cdf0e10cSrcweir { 677*cdf0e10cSrcweir OEditBaseModel::resetNoBroadcast(); 678*cdf0e10cSrcweir } 679*cdf0e10cSrcweir 680*cdf0e10cSrcweir //------------------------------------------------------------------------------ 681*cdf0e10cSrcweir sal_Bool OEditModel::commitControlValueToDbColumn( bool /*_bPostReset*/ ) 682*cdf0e10cSrcweir { 683*cdf0e10cSrcweir Any aNewValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) ); 684*cdf0e10cSrcweir 685*cdf0e10cSrcweir ::rtl::OUString sNewValue; 686*cdf0e10cSrcweir aNewValue >>= sNewValue; 687*cdf0e10cSrcweir 688*cdf0e10cSrcweir if ( !aNewValue.hasValue() 689*cdf0e10cSrcweir || ( !sNewValue.getLength() // an empty string 690*cdf0e10cSrcweir && m_bEmptyIsNull // which should be interpreted as NULL 691*cdf0e10cSrcweir ) 692*cdf0e10cSrcweir ) 693*cdf0e10cSrcweir { 694*cdf0e10cSrcweir m_xColumnUpdate->updateNull(); 695*cdf0e10cSrcweir } 696*cdf0e10cSrcweir else 697*cdf0e10cSrcweir { 698*cdf0e10cSrcweir OSL_PRECOND( m_pValueFormatter.get(), "OEditModel::commitControlValueToDbColumn: no value formatter!" ); 699*cdf0e10cSrcweir try 700*cdf0e10cSrcweir { 701*cdf0e10cSrcweir if ( m_pValueFormatter.get() ) 702*cdf0e10cSrcweir { 703*cdf0e10cSrcweir if ( !m_pValueFormatter->setFormattedValue( sNewValue ) ) 704*cdf0e10cSrcweir return sal_False; 705*cdf0e10cSrcweir } 706*cdf0e10cSrcweir else 707*cdf0e10cSrcweir m_xColumnUpdate->updateString( sNewValue ); 708*cdf0e10cSrcweir } 709*cdf0e10cSrcweir catch ( const Exception& ) 710*cdf0e10cSrcweir { 711*cdf0e10cSrcweir return sal_False; 712*cdf0e10cSrcweir } 713*cdf0e10cSrcweir } 714*cdf0e10cSrcweir 715*cdf0e10cSrcweir return sal_True; 716*cdf0e10cSrcweir } 717*cdf0e10cSrcweir 718*cdf0e10cSrcweir //------------------------------------------------------------------------------ 719*cdf0e10cSrcweir Any OEditModel::translateDbColumnToControlValue() 720*cdf0e10cSrcweir { 721*cdf0e10cSrcweir OSL_PRECOND( m_pValueFormatter.get(), "OEditModel::translateDbColumnToControlValue: no value formatter!" ); 722*cdf0e10cSrcweir Any aRet; 723*cdf0e10cSrcweir if ( m_pValueFormatter.get() ) 724*cdf0e10cSrcweir { 725*cdf0e10cSrcweir ::rtl::OUString sValue( m_pValueFormatter->getFormattedValue() ); 726*cdf0e10cSrcweir if ( !sValue.getLength() 727*cdf0e10cSrcweir && m_pValueFormatter->getColumn().is() 728*cdf0e10cSrcweir && m_pValueFormatter->getColumn()->wasNull() 729*cdf0e10cSrcweir ) 730*cdf0e10cSrcweir { 731*cdf0e10cSrcweir } 732*cdf0e10cSrcweir else 733*cdf0e10cSrcweir { 734*cdf0e10cSrcweir // #i2817# OJ 735*cdf0e10cSrcweir sal_uInt16 nMaxTextLen = getINT16( m_xAggregateSet->getPropertyValue( PROPERTY_MAXTEXTLEN ) ); 736*cdf0e10cSrcweir if ( nMaxTextLen && sValue.getLength() > nMaxTextLen ) 737*cdf0e10cSrcweir { 738*cdf0e10cSrcweir sal_Int32 nDiff = sValue.getLength() - nMaxTextLen; 739*cdf0e10cSrcweir sValue = sValue.replaceAt( nMaxTextLen, nDiff, ::rtl::OUString() ); 740*cdf0e10cSrcweir } 741*cdf0e10cSrcweir 742*cdf0e10cSrcweir aRet <<= sValue; 743*cdf0e10cSrcweir } 744*cdf0e10cSrcweir } 745*cdf0e10cSrcweir 746*cdf0e10cSrcweir return aRet.hasValue() ? aRet : makeAny( ::rtl::OUString() ); 747*cdf0e10cSrcweir } 748*cdf0e10cSrcweir 749*cdf0e10cSrcweir //------------------------------------------------------------------------------ 750*cdf0e10cSrcweir Any OEditModel::getDefaultForReset() const 751*cdf0e10cSrcweir { 752*cdf0e10cSrcweir return makeAny( m_aDefaultText ); 753*cdf0e10cSrcweir } 754*cdf0e10cSrcweir 755*cdf0e10cSrcweir //......................................................................... 756*cdf0e10cSrcweir } 757*cdf0e10cSrcweir //......................................................................... 758*cdf0e10cSrcweir 759