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