xref: /trunk/main/forms/source/component/FormattedField.cxx (revision 24acc54625a85f778a4f966495e8f4cd9d7b247c)
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
10cdf0e10cSrcweir  *
11*24acc546SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
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.
19cdf0e10cSrcweir  *
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 "FormattedField.hxx"
28cdf0e10cSrcweir #include "services.hxx"
29cdf0e10cSrcweir #include "property.hrc"
30cdf0e10cSrcweir #include "property.hxx"
31cdf0e10cSrcweir #include "frm_resource.hxx"
32cdf0e10cSrcweir #include "frm_resource.hrc"
33cdf0e10cSrcweir #include "propertybaghelper.hxx"
34cdf0e10cSrcweir #include <comphelper/sequence.hxx>
35cdf0e10cSrcweir #include <comphelper/numbers.hxx>
36cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
37cdf0e10cSrcweir #include <connectivity/dbconversion.hxx>
38cdf0e10cSrcweir #include <svl/zforlist.hxx>
39cdf0e10cSrcweir #include <svl/numuno.hxx>
40cdf0e10cSrcweir #include <vcl/svapp.hxx>
41cdf0e10cSrcweir #include <tools/debug.hxx>
42cdf0e10cSrcweir #include <tools/wintypes.hxx>
43cdf0e10cSrcweir #include <i18npool/mslangid.hxx>
44cdf0e10cSrcweir #include <rtl/textenc.h>
45cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp>
46cdf0e10cSrcweir #include <com/sun/star/util/NumberFormat.hpp>
47cdf0e10cSrcweir #include <com/sun/star/util/Date.hpp>
48cdf0e10cSrcweir #include <com/sun/star/util/Time.hpp>
49cdf0e10cSrcweir #include <com/sun/star/awt/MouseEvent.hpp>
50cdf0e10cSrcweir #include <com/sun/star/form/XSubmit.hpp>
51cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp>
52cdf0e10cSrcweir #include <com/sun/star/awt/XKeyListener.hpp>
53cdf0e10cSrcweir #include <com/sun/star/form/FormComponentType.hpp>
54cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
55cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatTypes.hpp>
56cdf0e10cSrcweir #include <com/sun/star/form/XForm.hpp>
57cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp>
58cdf0e10cSrcweir #include <vos/mutex.hxx>
59cdf0e10cSrcweir     // needed as long as we use the SolarMutex
60cdf0e10cSrcweir #include <comphelper/streamsection.hxx>
61cdf0e10cSrcweir #include <cppuhelper/weakref.hxx>
62cdf0e10cSrcweir #include <unotools/desktopterminationobserver.hxx>
63cdf0e10cSrcweir 
64cdf0e10cSrcweir #include <list>
65cdf0e10cSrcweir #include <algorithm>
66cdf0e10cSrcweir 
67cdf0e10cSrcweir using namespace dbtools;
68cdf0e10cSrcweir using namespace ::com::sun::star::uno;
69cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
70cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
71cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
72cdf0e10cSrcweir using namespace ::com::sun::star::beans;
73cdf0e10cSrcweir using namespace ::com::sun::star::container;
74cdf0e10cSrcweir using namespace ::com::sun::star::form;
75cdf0e10cSrcweir using namespace ::com::sun::star::awt;
76cdf0e10cSrcweir using namespace ::com::sun::star::io;
77cdf0e10cSrcweir using namespace ::com::sun::star::lang;
78cdf0e10cSrcweir using namespace ::com::sun::star::util;
79cdf0e10cSrcweir using namespace ::com::sun::star::form::binding;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir namespace
82cdf0e10cSrcweir {
83cdf0e10cSrcweir     typedef com::sun::star::util::Date UNODate;
84cdf0e10cSrcweir     typedef com::sun::star::util::Time UNOTime;
85cdf0e10cSrcweir     typedef com::sun::star::util::DateTime UNODateTime;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir //.........................................................................
89cdf0e10cSrcweir namespace frm
90cdf0e10cSrcweir {
91cdf0e10cSrcweir 
92cdf0e10cSrcweir /*************************************************************************/
93cdf0e10cSrcweir 
94cdf0e10cSrcweir class StandardFormatsSupplier : protected SvNumberFormatsSupplierObj, public ::utl::ITerminationListener
95cdf0e10cSrcweir {
96cdf0e10cSrcweir protected:
97cdf0e10cSrcweir             SvNumberFormatter*                       m_pMyPrivateFormatter;
98cdf0e10cSrcweir     static  WeakReference< XNumberFormatsSupplier >  s_xDefaultFormatsSupplier;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir public:
101cdf0e10cSrcweir     static Reference< XNumberFormatsSupplier > get( const Reference< XMultiServiceFactory >& _rxORB );
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     using SvNumberFormatsSupplierObj::operator new;
104cdf0e10cSrcweir     using SvNumberFormatsSupplierObj::operator delete;
105cdf0e10cSrcweir 
106cdf0e10cSrcweir protected:
107cdf0e10cSrcweir     StandardFormatsSupplier(const Reference<XMultiServiceFactory>& _rxFactory,LanguageType _eSysLanguage);
108cdf0e10cSrcweir     ~StandardFormatsSupplier();
109cdf0e10cSrcweir 
110cdf0e10cSrcweir protected:
111cdf0e10cSrcweir     virtual bool    queryTermination() const;
112cdf0e10cSrcweir     virtual void    notifyTermination();
113cdf0e10cSrcweir };
114cdf0e10cSrcweir 
115cdf0e10cSrcweir //------------------------------------------------------------------
116cdf0e10cSrcweir WeakReference< XNumberFormatsSupplier > StandardFormatsSupplier::s_xDefaultFormatsSupplier;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir //------------------------------------------------------------------
119cdf0e10cSrcweir StandardFormatsSupplier::StandardFormatsSupplier(const Reference< XMultiServiceFactory > & _rxFactory,LanguageType _eSysLanguage)
120cdf0e10cSrcweir     :SvNumberFormatsSupplierObj()
121cdf0e10cSrcweir     ,m_pMyPrivateFormatter(new SvNumberFormatter(_rxFactory, _eSysLanguage))
122cdf0e10cSrcweir {
123cdf0e10cSrcweir     SetNumberFormatter(m_pMyPrivateFormatter);
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     // #i29147# - 2004-06-18 - fs@openoffice.org
126cdf0e10cSrcweir     ::utl::DesktopTerminationObserver::registerTerminationListener( this );
127cdf0e10cSrcweir }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir //------------------------------------------------------------------
130cdf0e10cSrcweir StandardFormatsSupplier::~StandardFormatsSupplier()
131cdf0e10cSrcweir {
132cdf0e10cSrcweir     ::utl::DesktopTerminationObserver::revokeTerminationListener( this );
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     DELETEZ( m_pMyPrivateFormatter );
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir //------------------------------------------------------------------
138cdf0e10cSrcweir Reference< XNumberFormatsSupplier > StandardFormatsSupplier::get( const Reference< XMultiServiceFactory >& _rxORB )
139cdf0e10cSrcweir {
140cdf0e10cSrcweir     LanguageType eSysLanguage = LANGUAGE_SYSTEM;
141cdf0e10cSrcweir     {
142cdf0e10cSrcweir         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
143cdf0e10cSrcweir         Reference< XNumberFormatsSupplier > xSupplier = s_xDefaultFormatsSupplier;
144cdf0e10cSrcweir         if ( xSupplier.is() )
145cdf0e10cSrcweir             return xSupplier;
146cdf0e10cSrcweir 
147cdf0e10cSrcweir         // get the Office's locale
148cdf0e10cSrcweir         const Locale& rSysLocale = SvtSysLocale().GetLocaleData().getLocale();
149cdf0e10cSrcweir         // translate
150cdf0e10cSrcweir         eSysLanguage = MsLangId::convertLocaleToLanguage( rSysLocale );
151cdf0e10cSrcweir     }
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     StandardFormatsSupplier* pSupplier = new StandardFormatsSupplier( _rxORB, eSysLanguage );
154cdf0e10cSrcweir     Reference< XNumberFormatsSupplier > xNewlyCreatedSupplier( pSupplier );
155cdf0e10cSrcweir 
156cdf0e10cSrcweir     {
157cdf0e10cSrcweir         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
158cdf0e10cSrcweir         Reference< XNumberFormatsSupplier > xSupplier = s_xDefaultFormatsSupplier;
159cdf0e10cSrcweir         if ( xSupplier.is() )
160cdf0e10cSrcweir             // somebody used the small time frame where the mutex was not locked to create and set
161cdf0e10cSrcweir             // the supplier
162cdf0e10cSrcweir             return xSupplier;
163cdf0e10cSrcweir 
164cdf0e10cSrcweir         s_xDefaultFormatsSupplier = xNewlyCreatedSupplier;
165cdf0e10cSrcweir     }
166cdf0e10cSrcweir 
167cdf0e10cSrcweir     return xNewlyCreatedSupplier;
168cdf0e10cSrcweir }
169cdf0e10cSrcweir 
170cdf0e10cSrcweir //------------------------------------------------------------------
171cdf0e10cSrcweir bool StandardFormatsSupplier::queryTermination() const
172cdf0e10cSrcweir {
173cdf0e10cSrcweir     return true;
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir //------------------------------------------------------------------
177cdf0e10cSrcweir void StandardFormatsSupplier::notifyTermination()
178cdf0e10cSrcweir {
179cdf0e10cSrcweir     Reference< XNumberFormatsSupplier > xKeepAlive = this;
180cdf0e10cSrcweir     // when the application is terminating, release our static reference so that we are cleared/destructed
181cdf0e10cSrcweir     // earlier than upon unloading the library
182cdf0e10cSrcweir     // #i29147# - 2004-06-18 - fs@openoffice.org
183cdf0e10cSrcweir     s_xDefaultFormatsSupplier = WeakReference< XNumberFormatsSupplier >( );
184cdf0e10cSrcweir 
185cdf0e10cSrcweir     SetNumberFormatter( NULL );
186cdf0e10cSrcweir     DELETEZ( m_pMyPrivateFormatter );
187cdf0e10cSrcweir }
188cdf0e10cSrcweir 
189cdf0e10cSrcweir /*************************************************************************/
190cdf0e10cSrcweir //------------------------------------------------------------------
191cdf0e10cSrcweir InterfaceRef SAL_CALL OFormattedControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
192cdf0e10cSrcweir {
193cdf0e10cSrcweir     return *(new OFormattedControl(_rxFactory));
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
196cdf0e10cSrcweir //------------------------------------------------------------------
197cdf0e10cSrcweir Sequence<Type> OFormattedControl::_getTypes()
198cdf0e10cSrcweir {
199cdf0e10cSrcweir     return ::comphelper::concatSequences(
200cdf0e10cSrcweir         OFormattedControl_BASE::getTypes(),
201cdf0e10cSrcweir         OBoundControl::_getTypes()
202cdf0e10cSrcweir     );
203cdf0e10cSrcweir }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir //------------------------------------------------------------------
206cdf0e10cSrcweir Any SAL_CALL OFormattedControl::queryAggregation(const Type& _rType) throw (RuntimeException)
207cdf0e10cSrcweir {
208cdf0e10cSrcweir     Any aReturn = OBoundControl::queryAggregation(_rType);
209cdf0e10cSrcweir     if (!aReturn.hasValue())
210cdf0e10cSrcweir         aReturn = OFormattedControl_BASE::queryInterface(_rType);
211cdf0e10cSrcweir     return aReturn;
212cdf0e10cSrcweir }
213cdf0e10cSrcweir 
214cdf0e10cSrcweir 
215cdf0e10cSrcweir DBG_NAME(OFormattedControl);
216cdf0e10cSrcweir //------------------------------------------------------------------------------
217cdf0e10cSrcweir OFormattedControl::OFormattedControl(const Reference<XMultiServiceFactory>& _rxFactory)
218cdf0e10cSrcweir                :OBoundControl(_rxFactory, VCL_CONTROL_FORMATTEDFIELD)
219cdf0e10cSrcweir                ,m_nKeyEvent(0)
220cdf0e10cSrcweir {
221cdf0e10cSrcweir     DBG_CTOR(OFormattedControl,NULL);
222cdf0e10cSrcweir 
223cdf0e10cSrcweir     increment(m_refCount);
224cdf0e10cSrcweir     {
225cdf0e10cSrcweir         Reference<XWindow>  xComp;
226cdf0e10cSrcweir         if (query_aggregation(m_xAggregate, xComp))
227cdf0e10cSrcweir         {
228cdf0e10cSrcweir             xComp->addKeyListener(this);
229cdf0e10cSrcweir         }
230cdf0e10cSrcweir     }
231cdf0e10cSrcweir     decrement(m_refCount);
232cdf0e10cSrcweir }
233cdf0e10cSrcweir 
234cdf0e10cSrcweir //------------------------------------------------------------------------------
235cdf0e10cSrcweir OFormattedControl::~OFormattedControl()
236cdf0e10cSrcweir {
237cdf0e10cSrcweir     if( m_nKeyEvent )
238cdf0e10cSrcweir         Application::RemoveUserEvent( m_nKeyEvent );
239cdf0e10cSrcweir 
240cdf0e10cSrcweir     if (!OComponentHelper::rBHelper.bDisposed)
241cdf0e10cSrcweir     {
242cdf0e10cSrcweir         acquire();
243cdf0e10cSrcweir         dispose();
244cdf0e10cSrcweir     }
245cdf0e10cSrcweir 
246cdf0e10cSrcweir     DBG_DTOR(OFormattedControl,NULL);
247cdf0e10cSrcweir }
248cdf0e10cSrcweir 
249cdf0e10cSrcweir // XKeyListener
250cdf0e10cSrcweir //------------------------------------------------------------------------------
251cdf0e10cSrcweir void OFormattedControl::disposing(const EventObject& _rSource) throw(RuntimeException)
252cdf0e10cSrcweir {
253cdf0e10cSrcweir     OBoundControl::disposing(_rSource);
254cdf0e10cSrcweir }
255cdf0e10cSrcweir 
256cdf0e10cSrcweir //------------------------------------------------------------------------------
257cdf0e10cSrcweir void OFormattedControl::keyPressed(const ::com::sun::star::awt::KeyEvent& e) throw ( ::com::sun::star::uno::RuntimeException)
258cdf0e10cSrcweir {
259cdf0e10cSrcweir     if( e.KeyCode != KEY_RETURN || e.Modifiers != 0 )
260cdf0e10cSrcweir         return;
261cdf0e10cSrcweir 
262cdf0e10cSrcweir     // Steht das Control in einem Formular mit einer Submit-URL?
263cdf0e10cSrcweir     Reference<com::sun::star::beans::XPropertySet>  xSet(getModel(), UNO_QUERY);
264cdf0e10cSrcweir     if( !xSet.is() )
265cdf0e10cSrcweir         return;
266cdf0e10cSrcweir 
267cdf0e10cSrcweir     Reference<XFormComponent>  xFComp(xSet, UNO_QUERY);
268cdf0e10cSrcweir     InterfaceRef  xParent = xFComp->getParent();
269cdf0e10cSrcweir     if( !xParent.is() )
270cdf0e10cSrcweir         return;
271cdf0e10cSrcweir 
272cdf0e10cSrcweir     Reference<com::sun::star::beans::XPropertySet>  xFormSet(xParent, UNO_QUERY);
273cdf0e10cSrcweir     if( !xFormSet.is() )
274cdf0e10cSrcweir         return;
275cdf0e10cSrcweir 
276cdf0e10cSrcweir     Any aTmp(xFormSet->getPropertyValue( PROPERTY_TARGET_URL ));
277cdf0e10cSrcweir     if (!isA(aTmp, static_cast< ::rtl::OUString* >(NULL)) ||
278cdf0e10cSrcweir         !getString(aTmp).getLength() )
279cdf0e10cSrcweir         return;
280cdf0e10cSrcweir 
281cdf0e10cSrcweir     Reference<XIndexAccess>  xElements(xParent, UNO_QUERY);
282cdf0e10cSrcweir     sal_Int32 nCount = xElements->getCount();
283cdf0e10cSrcweir     if( nCount > 1 )
284cdf0e10cSrcweir     {
285cdf0e10cSrcweir 
286cdf0e10cSrcweir         Reference<com::sun::star::beans::XPropertySet>  xFCSet;
287cdf0e10cSrcweir         for( sal_Int32 nIndex=0; nIndex < nCount; nIndex++ )
288cdf0e10cSrcweir         {
289cdf0e10cSrcweir             //  Any aElement(xElements->getByIndex(nIndex));
290cdf0e10cSrcweir             xElements->getByIndex(nIndex) >>= xFCSet;
291cdf0e10cSrcweir 
292cdf0e10cSrcweir             if (hasProperty(PROPERTY_CLASSID, xFCSet) &&
293cdf0e10cSrcweir                 getINT16(xFCSet->getPropertyValue(PROPERTY_CLASSID)) == FormComponentType::TEXTFIELD)
294cdf0e10cSrcweir             {
295cdf0e10cSrcweir                 // Noch ein weiteres Edit gefunden ==> dann nicht submitten
296cdf0e10cSrcweir                 if (xFCSet != xSet)
297cdf0e10cSrcweir                     return;
298cdf0e10cSrcweir             }
299cdf0e10cSrcweir         }
300cdf0e10cSrcweir     }
301cdf0e10cSrcweir 
302cdf0e10cSrcweir     // Da wir noch im Haender stehen, submit asynchron ausloesen
303cdf0e10cSrcweir     if( m_nKeyEvent )
304cdf0e10cSrcweir         Application::RemoveUserEvent( m_nKeyEvent );
305cdf0e10cSrcweir     m_nKeyEvent = Application::PostUserEvent( LINK(this, OFormattedControl,
306cdf0e10cSrcweir                                             OnKeyPressed) );
307cdf0e10cSrcweir }
308cdf0e10cSrcweir 
309cdf0e10cSrcweir //------------------------------------------------------------------------------
310cdf0e10cSrcweir void OFormattedControl::keyReleased(const ::com::sun::star::awt::KeyEvent& /*e*/) throw ( ::com::sun::star::uno::RuntimeException)
311cdf0e10cSrcweir {
312cdf0e10cSrcweir }
313cdf0e10cSrcweir 
314cdf0e10cSrcweir //------------------------------------------------------------------------------
315cdf0e10cSrcweir IMPL_LINK(OFormattedControl, OnKeyPressed, void*, /*EMPTYARG*/)
316cdf0e10cSrcweir {
317cdf0e10cSrcweir     m_nKeyEvent = 0;
318cdf0e10cSrcweir 
319cdf0e10cSrcweir     Reference<XFormComponent>  xFComp(getModel(), UNO_QUERY);
320cdf0e10cSrcweir     InterfaceRef  xParent = xFComp->getParent();
321cdf0e10cSrcweir     Reference<XSubmit>  xSubmit(xParent, UNO_QUERY);
322cdf0e10cSrcweir     if (xSubmit.is())
323cdf0e10cSrcweir         xSubmit->submit( Reference<XControl> (), ::com::sun::star::awt::MouseEvent() );
324cdf0e10cSrcweir     return 0L;
325cdf0e10cSrcweir }
326cdf0e10cSrcweir 
327cdf0e10cSrcweir //------------------------------------------------------------------------------
328cdf0e10cSrcweir StringSequence  OFormattedControl::getSupportedServiceNames() throw()
329cdf0e10cSrcweir {
330cdf0e10cSrcweir     StringSequence aSupported = OBoundControl::getSupportedServiceNames();
331cdf0e10cSrcweir     aSupported.realloc(aSupported.getLength() + 1);
332cdf0e10cSrcweir 
333cdf0e10cSrcweir     ::rtl::OUString*pArray = aSupported.getArray();
334cdf0e10cSrcweir     pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_FORMATTEDFIELD;
335cdf0e10cSrcweir     return aSupported;
336cdf0e10cSrcweir }
337cdf0e10cSrcweir 
338cdf0e10cSrcweir //------------------------------------------------------------------------------
339cdf0e10cSrcweir void OFormattedControl::setDesignMode(sal_Bool bOn) throw ( ::com::sun::star::uno::RuntimeException)
340cdf0e10cSrcweir {
341cdf0e10cSrcweir     OBoundControl::setDesignMode(bOn);
342cdf0e10cSrcweir }
343cdf0e10cSrcweir 
344cdf0e10cSrcweir /*************************************************************************/
345cdf0e10cSrcweir DBG_NAME(OFormattedModel)
346cdf0e10cSrcweir //------------------------------------------------------------------
347cdf0e10cSrcweir void OFormattedModel::implConstruct()
348cdf0e10cSrcweir {
349cdf0e10cSrcweir     // members
350cdf0e10cSrcweir     m_bOriginalNumeric = sal_False;
351cdf0e10cSrcweir     m_bNumeric = sal_False;
352cdf0e10cSrcweir     m_xOriginalFormatter = NULL;
353cdf0e10cSrcweir     m_nKeyType = NumberFormat::UNDEFINED;
354cdf0e10cSrcweir     m_aNullDate = DBTypeConversion::getStandardDate();
355cdf0e10cSrcweir     m_nFieldType =  DataType::OTHER;
356cdf0e10cSrcweir 
357cdf0e10cSrcweir     // default our formats supplier
358cdf0e10cSrcweir     increment(m_refCount);
359cdf0e10cSrcweir     setPropertyToDefaultByHandle(PROPERTY_ID_FORMATSSUPPLIER);
360cdf0e10cSrcweir     decrement(m_refCount);
361cdf0e10cSrcweir 
362cdf0e10cSrcweir     startAggregatePropertyListening( PROPERTY_FORMATKEY );
363cdf0e10cSrcweir     startAggregatePropertyListening( PROPERTY_FORMATSSUPPLIER );
364cdf0e10cSrcweir }
365cdf0e10cSrcweir 
366cdf0e10cSrcweir //------------------------------------------------------------------
367cdf0e10cSrcweir OFormattedModel::OFormattedModel(const Reference<XMultiServiceFactory>& _rxFactory)
368cdf0e10cSrcweir     :OEditBaseModel(_rxFactory, VCL_CONTROLMODEL_FORMATTEDFIELD, FRM_SUN_CONTROL_FORMATTEDFIELD, sal_True, sal_True )
369cdf0e10cSrcweir                             // use the old control name for compytibility reasons
370cdf0e10cSrcweir     ,OErrorBroadcaster( OComponentHelper::rBHelper )
371cdf0e10cSrcweir {
372cdf0e10cSrcweir     DBG_CTOR(OFormattedModel, NULL);
373cdf0e10cSrcweir 
374cdf0e10cSrcweir     implConstruct();
375cdf0e10cSrcweir 
376cdf0e10cSrcweir     m_nClassId = FormComponentType::TEXTFIELD;
377cdf0e10cSrcweir     initValueProperty( PROPERTY_EFFECTIVE_VALUE, PROPERTY_ID_EFFECTIVE_VALUE );
378cdf0e10cSrcweir }
379cdf0e10cSrcweir 
380cdf0e10cSrcweir //------------------------------------------------------------------
381cdf0e10cSrcweir OFormattedModel::OFormattedModel( const OFormattedModel* _pOriginal, const Reference< XMultiServiceFactory >& _rxFactory )
382cdf0e10cSrcweir     :OEditBaseModel( _pOriginal, _rxFactory )
383cdf0e10cSrcweir     ,OErrorBroadcaster( OComponentHelper::rBHelper )
384cdf0e10cSrcweir {
385cdf0e10cSrcweir     DBG_CTOR(OFormattedModel, NULL);
386cdf0e10cSrcweir 
387cdf0e10cSrcweir     implConstruct();
388cdf0e10cSrcweir }
389cdf0e10cSrcweir 
390cdf0e10cSrcweir //------------------------------------------------------------------------------
391cdf0e10cSrcweir OFormattedModel::~OFormattedModel()
392cdf0e10cSrcweir {
393cdf0e10cSrcweir     DBG_DTOR(OFormattedModel, NULL);
394cdf0e10cSrcweir }
395cdf0e10cSrcweir 
396cdf0e10cSrcweir // XCloneable
397cdf0e10cSrcweir //------------------------------------------------------------------------------
398cdf0e10cSrcweir IMPLEMENT_DEFAULT_CLONING( OFormattedModel )
399cdf0e10cSrcweir 
400cdf0e10cSrcweir //------------------------------------------------------------------------------
401cdf0e10cSrcweir void SAL_CALL OFormattedModel::disposing()
402cdf0e10cSrcweir {
403cdf0e10cSrcweir     OErrorBroadcaster::disposing();
404cdf0e10cSrcweir     OEditBaseModel::disposing();
405cdf0e10cSrcweir }
406cdf0e10cSrcweir 
407cdf0e10cSrcweir // XServiceInfo
408cdf0e10cSrcweir //------------------------------------------------------------------------------
409cdf0e10cSrcweir StringSequence OFormattedModel::getSupportedServiceNames() throw()
410cdf0e10cSrcweir {
411cdf0e10cSrcweir     StringSequence aSupported = OEditBaseModel::getSupportedServiceNames();
412cdf0e10cSrcweir 
413cdf0e10cSrcweir     sal_Int32 nOldLen = aSupported.getLength();
414cdf0e10cSrcweir     aSupported.realloc( nOldLen + 8 );
415cdf0e10cSrcweir     ::rtl::OUString* pStoreTo = aSupported.getArray() + nOldLen;
416cdf0e10cSrcweir 
417cdf0e10cSrcweir     *pStoreTo++ = BINDABLE_CONTROL_MODEL;
418cdf0e10cSrcweir     *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
419cdf0e10cSrcweir     *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
420cdf0e10cSrcweir 
421cdf0e10cSrcweir     *pStoreTo++ = BINDABLE_DATA_AWARE_CONTROL_MODEL;
422cdf0e10cSrcweir     *pStoreTo++ = VALIDATABLE_BINDABLE_CONTROL_MODEL;
423cdf0e10cSrcweir 
424cdf0e10cSrcweir     *pStoreTo++ = FRM_SUN_COMPONENT_FORMATTEDFIELD;
425cdf0e10cSrcweir     *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_FORMATTEDFIELD;
426cdf0e10cSrcweir     *pStoreTo++ = BINDABLE_DATABASE_FORMATTED_FIELD;
427cdf0e10cSrcweir 
428cdf0e10cSrcweir     return aSupported;
429cdf0e10cSrcweir }
430cdf0e10cSrcweir 
431cdf0e10cSrcweir // XAggregation
432cdf0e10cSrcweir //------------------------------------------------------------------------------
433cdf0e10cSrcweir Any SAL_CALL OFormattedModel::queryAggregation(const Type& _rType) throw(RuntimeException)
434cdf0e10cSrcweir {
435cdf0e10cSrcweir     Any aReturn = OEditBaseModel::queryAggregation( _rType );
436cdf0e10cSrcweir     return aReturn.hasValue() ? aReturn : OErrorBroadcaster::queryInterface( _rType );
437cdf0e10cSrcweir }
438cdf0e10cSrcweir 
439cdf0e10cSrcweir // XTypeProvider
440cdf0e10cSrcweir //------------------------------------------------------------------------------
441cdf0e10cSrcweir Sequence< Type > OFormattedModel::_getTypes()
442cdf0e10cSrcweir {
443cdf0e10cSrcweir     return ::comphelper::concatSequences(
444cdf0e10cSrcweir         OEditBaseModel::_getTypes(),
445cdf0e10cSrcweir         OErrorBroadcaster::getTypes()
446cdf0e10cSrcweir     );
447cdf0e10cSrcweir }
448cdf0e10cSrcweir 
449cdf0e10cSrcweir // XPersistObject
450cdf0e10cSrcweir //------------------------------------------------------------------------------
451cdf0e10cSrcweir ::rtl::OUString SAL_CALL OFormattedModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException)
452cdf0e10cSrcweir {
453cdf0e10cSrcweir     return ::rtl::OUString(FRM_COMPONENT_EDIT);
454cdf0e10cSrcweir }
455cdf0e10cSrcweir 
456cdf0e10cSrcweir // XPropertySet
457cdf0e10cSrcweir //------------------------------------------------------------------------------
458cdf0e10cSrcweir void OFormattedModel::describeFixedProperties( Sequence< Property >& _rProps ) const
459cdf0e10cSrcweir {
460cdf0e10cSrcweir     BEGIN_DESCRIBE_PROPERTIES( 3, OEditBaseModel )
461cdf0e10cSrcweir         DECL_BOOL_PROP1(EMPTY_IS_NULL,                          BOUND);
462cdf0e10cSrcweir         DECL_PROP1(TABINDEX,            sal_Int16,              BOUND);
463cdf0e10cSrcweir         DECL_BOOL_PROP2(FILTERPROPOSAL,                         BOUND, MAYBEDEFAULT);
464cdf0e10cSrcweir     END_DESCRIBE_PROPERTIES();
465cdf0e10cSrcweir }
466cdf0e10cSrcweir 
467cdf0e10cSrcweir //------------------------------------------------------------------------------
468cdf0e10cSrcweir void OFormattedModel::describeAggregateProperties( Sequence< Property >& _rAggregateProps ) const
469cdf0e10cSrcweir {
470cdf0e10cSrcweir     OEditBaseModel::describeAggregateProperties( _rAggregateProps );
471cdf0e10cSrcweir 
472cdf0e10cSrcweir     // TreatAsNumeric nicht transient : wir wollen es an der UI anbinden (ist noetig, um dem EffectiveDefault
473cdf0e10cSrcweir     // - der kann Text oder Zahl sein - einen Sinn zu geben)
474cdf0e10cSrcweir     ModifyPropertyAttributes(_rAggregateProps, PROPERTY_TREATASNUMERIC, 0, PropertyAttribute::TRANSIENT);
475cdf0e10cSrcweir     // same for FormatKey
476cdf0e10cSrcweir     // (though the paragraph above for the TreatAsNumeric does not hold anymore - we do not have an UI for this.
477cdf0e10cSrcweir     // But we have for the format key ...)
478cdf0e10cSrcweir     // 25.06.2001 - 87862 - frank.schoenheit@sun.com
479cdf0e10cSrcweir     ModifyPropertyAttributes(_rAggregateProps, PROPERTY_FORMATKEY, 0, PropertyAttribute::TRANSIENT);
480cdf0e10cSrcweir 
481cdf0e10cSrcweir     RemoveProperty(_rAggregateProps, PROPERTY_STRICTFORMAT);
482cdf0e10cSrcweir         // no strict format property for formatted fields: it does not make sense, 'cause
483cdf0e10cSrcweir         // there is no general way to decide which characters/sub strings are allowed during the input of an
484cdf0e10cSrcweir         // arbitraryly formatted control
485cdf0e10cSrcweir         // 81441 - 12/07/00 - FS
486cdf0e10cSrcweir }
487cdf0e10cSrcweir 
488cdf0e10cSrcweir //------------------------------------------------------------------------------
489cdf0e10cSrcweir void OFormattedModel::getFastPropertyValue(Any& rValue, sal_Int32 nHandle) const
490cdf0e10cSrcweir {
491cdf0e10cSrcweir     OEditBaseModel::getFastPropertyValue(rValue, nHandle);
492cdf0e10cSrcweir }
493cdf0e10cSrcweir 
494cdf0e10cSrcweir //------------------------------------------------------------------------------
495cdf0e10cSrcweir void OFormattedModel::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const Any& rValue) throw ( ::com::sun::star::uno::Exception)
496cdf0e10cSrcweir {
497cdf0e10cSrcweir     OEditBaseModel::setFastPropertyValue_NoBroadcast(nHandle, rValue);
498cdf0e10cSrcweir }
499cdf0e10cSrcweir 
500cdf0e10cSrcweir //------------------------------------------------------------------------------
501cdf0e10cSrcweir sal_Bool OFormattedModel::convertFastPropertyValue(Any& rConvertedValue, Any& rOldValue, sal_Int32 nHandle, const Any& rValue)
502cdf0e10cSrcweir                                                         throw( IllegalArgumentException )
503cdf0e10cSrcweir {
504cdf0e10cSrcweir     return OEditBaseModel::convertFastPropertyValue(rConvertedValue, rOldValue, nHandle, rValue);
505cdf0e10cSrcweir }
506cdf0e10cSrcweir 
507cdf0e10cSrcweir //------------------------------------------------------------------------------
508cdf0e10cSrcweir void OFormattedModel::setPropertyToDefaultByHandle(sal_Int32 nHandle)
509cdf0e10cSrcweir {
510cdf0e10cSrcweir     if (nHandle == PROPERTY_ID_FORMATSSUPPLIER)
511cdf0e10cSrcweir     {
512cdf0e10cSrcweir         Reference<XNumberFormatsSupplier>  xSupplier = calcDefaultFormatsSupplier();
513cdf0e10cSrcweir         DBG_ASSERT(m_xAggregateSet.is(), "OFormattedModel::setPropertyToDefaultByHandle(FORMATSSUPPLIER) : have no aggregate !");
514cdf0e10cSrcweir         if (m_xAggregateSet.is())
515cdf0e10cSrcweir             m_xAggregateSet->setPropertyValue(PROPERTY_FORMATSSUPPLIER, makeAny(xSupplier));
516cdf0e10cSrcweir     }
517cdf0e10cSrcweir     else
518cdf0e10cSrcweir         OEditBaseModel::setPropertyToDefaultByHandle(nHandle);
519cdf0e10cSrcweir }
520cdf0e10cSrcweir 
521cdf0e10cSrcweir //------------------------------------------------------------------------------
522cdf0e10cSrcweir void OFormattedModel::setPropertyToDefault(const ::rtl::OUString& aPropertyName) throw( com::sun::star::beans::UnknownPropertyException, RuntimeException )
523cdf0e10cSrcweir {
524cdf0e10cSrcweir     OPropertyArrayAggregationHelper& rPH = m_aPropertyBagHelper.getInfoHelper();
525cdf0e10cSrcweir     sal_Int32 nHandle = rPH.getHandleByName( aPropertyName );
526cdf0e10cSrcweir 
527cdf0e10cSrcweir     if (nHandle == PROPERTY_ID_FORMATSSUPPLIER)
528cdf0e10cSrcweir         setPropertyToDefaultByHandle(PROPERTY_ID_FORMATSSUPPLIER);
529cdf0e10cSrcweir     else
530cdf0e10cSrcweir         OEditBaseModel::setPropertyToDefault(aPropertyName);
531cdf0e10cSrcweir }
532cdf0e10cSrcweir 
533cdf0e10cSrcweir //------------------------------------------------------------------------------
534cdf0e10cSrcweir Any OFormattedModel::getPropertyDefaultByHandle( sal_Int32 nHandle ) const
535cdf0e10cSrcweir {
536cdf0e10cSrcweir     if (nHandle == PROPERTY_ID_FORMATSSUPPLIER)
537cdf0e10cSrcweir     {
538cdf0e10cSrcweir         Reference<XNumberFormatsSupplier>  xSupplier = calcDefaultFormatsSupplier();
539cdf0e10cSrcweir         return makeAny(xSupplier);
540cdf0e10cSrcweir     }
541cdf0e10cSrcweir     else
542cdf0e10cSrcweir         return OEditBaseModel::getPropertyDefaultByHandle(nHandle);
543cdf0e10cSrcweir }
544cdf0e10cSrcweir 
545cdf0e10cSrcweir //------------------------------------------------------------------------------
546cdf0e10cSrcweir Any SAL_CALL OFormattedModel::getPropertyDefault( const ::rtl::OUString& aPropertyName ) throw( com::sun::star::beans::UnknownPropertyException, RuntimeException )
547cdf0e10cSrcweir {
548cdf0e10cSrcweir     OPropertyArrayAggregationHelper& rPH = m_aPropertyBagHelper.getInfoHelper();
549cdf0e10cSrcweir     sal_Int32 nHandle = rPH.getHandleByName( aPropertyName );
550cdf0e10cSrcweir 
551cdf0e10cSrcweir     if (nHandle == PROPERTY_ID_FORMATSSUPPLIER)
552cdf0e10cSrcweir         return getPropertyDefaultByHandle(PROPERTY_ID_FORMATSSUPPLIER);
553cdf0e10cSrcweir     else
554cdf0e10cSrcweir         return OEditBaseModel::getPropertyDefault(aPropertyName);
555cdf0e10cSrcweir }
556cdf0e10cSrcweir 
557cdf0e10cSrcweir //------------------------------------------------------------------------------
558cdf0e10cSrcweir void OFormattedModel::_propertyChanged( const com::sun::star::beans::PropertyChangeEvent& evt ) throw(RuntimeException)
559cdf0e10cSrcweir {
560cdf0e10cSrcweir     // TODO: check how this works with external bindings
561cdf0e10cSrcweir 
562cdf0e10cSrcweir     OSL_ENSURE( evt.Source == m_xAggregateSet, "OFormattedModel::_propertyChanged: where did this come from?" );
563cdf0e10cSrcweir     if ( evt.Source == m_xAggregateSet )
564cdf0e10cSrcweir     {
565cdf0e10cSrcweir         Reference< XPropertySet > xSourceSet( evt.Source, UNO_QUERY );
566cdf0e10cSrcweir         if ( evt.PropertyName.equals( PROPERTY_FORMATKEY ) )
567cdf0e10cSrcweir         {
568cdf0e10cSrcweir             if ( evt.NewValue.getValueType().getTypeClass() == TypeClass_LONG )
569cdf0e10cSrcweir             {
570cdf0e10cSrcweir                 try
571cdf0e10cSrcweir                 {
572cdf0e10cSrcweir                     ::osl::MutexGuard aGuard( m_aMutex );
573cdf0e10cSrcweir 
574cdf0e10cSrcweir                     Reference<XNumberFormatsSupplier> xSupplier( calcFormatsSupplier() );
575cdf0e10cSrcweir                     m_nKeyType  = getNumberFormatType(xSupplier->getNumberFormats(), getINT32( evt.NewValue ) );
576cdf0e10cSrcweir 
577cdf0e10cSrcweir                     // as m_aSaveValue (which is used by commitControlValueToDbColumn) is format dependent we have
578cdf0e10cSrcweir                     // to recalc it, which is done by translateDbColumnToControlValue
579cdf0e10cSrcweir                     if ( m_xColumn.is() && m_xAggregateFastSet.is()  && !m_xCursor->isBeforeFirst() && !m_xCursor->isAfterLast())
580cdf0e10cSrcweir                     {
581cdf0e10cSrcweir                         setControlValue( translateDbColumnToControlValue(), eOther );
582cdf0e10cSrcweir                     }
583cdf0e10cSrcweir 
584cdf0e10cSrcweir                     // if we're connected to an external value binding, then re-calculate the type
585cdf0e10cSrcweir                     // used to exchange the value - it depends on the format, too
586cdf0e10cSrcweir                     if ( hasExternalValueBinding() )
587cdf0e10cSrcweir                     {
588cdf0e10cSrcweir                         calculateExternalValueType();
589cdf0e10cSrcweir                     }
590cdf0e10cSrcweir                 }
591cdf0e10cSrcweir                 catch(Exception&)
592cdf0e10cSrcweir                 {
593cdf0e10cSrcweir                 }
594cdf0e10cSrcweir             }
595cdf0e10cSrcweir             return;
596cdf0e10cSrcweir         }
597cdf0e10cSrcweir 
598cdf0e10cSrcweir         if ( evt.PropertyName.equals( PROPERTY_FORMATSSUPPLIER ) )
599cdf0e10cSrcweir         {
600cdf0e10cSrcweir             updateFormatterNullDate();
601cdf0e10cSrcweir             return;
602cdf0e10cSrcweir         }
603cdf0e10cSrcweir 
604cdf0e10cSrcweir         OBoundControlModel::_propertyChanged( evt );
605cdf0e10cSrcweir     }
606cdf0e10cSrcweir }
607cdf0e10cSrcweir 
608cdf0e10cSrcweir //------------------------------------------------------------------------------
609cdf0e10cSrcweir void OFormattedModel::updateFormatterNullDate()
610cdf0e10cSrcweir {
611cdf0e10cSrcweir     // calc the current NULL date
612cdf0e10cSrcweir     Reference< XNumberFormatsSupplier > xSupplier( calcFormatsSupplier() );
613cdf0e10cSrcweir     if ( xSupplier.is() )
614cdf0e10cSrcweir         xSupplier->getNumberFormatSettings()->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "NullDate" ) ) ) >>= m_aNullDate;
615cdf0e10cSrcweir }
616cdf0e10cSrcweir 
617cdf0e10cSrcweir //------------------------------------------------------------------------------
618cdf0e10cSrcweir Reference< XNumberFormatsSupplier > OFormattedModel::calcFormatsSupplier() const
619cdf0e10cSrcweir {
620cdf0e10cSrcweir     Reference<XNumberFormatsSupplier>  xSupplier;
621cdf0e10cSrcweir 
622cdf0e10cSrcweir     DBG_ASSERT(m_xAggregateSet.is(), "OFormattedModel::calcFormatsSupplier : have no aggregate !");
623cdf0e10cSrcweir     // hat mein aggregiertes Model einen FormatSupplier ?
624cdf0e10cSrcweir     if( m_xAggregateSet.is() )
625cdf0e10cSrcweir         m_xAggregateSet->getPropertyValue(PROPERTY_FORMATSSUPPLIER) >>= xSupplier;
626cdf0e10cSrcweir 
627cdf0e10cSrcweir     if (!xSupplier.is())
628cdf0e10cSrcweir         // check if my parent form has a supplier
629cdf0e10cSrcweir         xSupplier = calcFormFormatsSupplier();
630cdf0e10cSrcweir 
631cdf0e10cSrcweir     if (!xSupplier.is())
632cdf0e10cSrcweir         xSupplier = calcDefaultFormatsSupplier();
633cdf0e10cSrcweir 
634cdf0e10cSrcweir     DBG_ASSERT(xSupplier.is(), "OFormattedModel::calcFormatsSupplier : no supplier !");
635cdf0e10cSrcweir         // jetzt sollte aber einer da sein
636cdf0e10cSrcweir     return xSupplier;
637cdf0e10cSrcweir }
638cdf0e10cSrcweir 
639cdf0e10cSrcweir //------------------------------------------------------------------------------
640cdf0e10cSrcweir Reference<XNumberFormatsSupplier>  OFormattedModel::calcFormFormatsSupplier() const
641cdf0e10cSrcweir {
642cdf0e10cSrcweir     Reference<XChild>  xMe;
643cdf0e10cSrcweir     query_interface(static_cast<XWeak*>(const_cast<OFormattedModel*>(this)), xMe);
644cdf0e10cSrcweir     // damit stellen wir sicher, dass wir auch fuer den Fall der Aggregation das richtige
645cdf0e10cSrcweir     // Objekt bekommen
646cdf0e10cSrcweir     DBG_ASSERT(xMe.is(), "OFormattedModel::calcFormFormatsSupplier : I should have a content interface !");
647cdf0e10cSrcweir 
648cdf0e10cSrcweir     // jetzt durchhangeln nach oben, bis wir auf eine starform treffen (angefangen mit meinem eigenen Parent)
649cdf0e10cSrcweir     Reference<XChild>  xParent(xMe->getParent(), UNO_QUERY);
650cdf0e10cSrcweir     Reference<XForm>  xNextParentForm(xParent, UNO_QUERY);
651cdf0e10cSrcweir     while (!xNextParentForm.is() && xParent.is())
652cdf0e10cSrcweir     {
653cdf0e10cSrcweir         xParent         = xParent.query( xParent->getParent() );
654cdf0e10cSrcweir         xNextParentForm = xNextParentForm.query( xParent );
655cdf0e10cSrcweir     }
656cdf0e10cSrcweir 
657cdf0e10cSrcweir     if (!xNextParentForm.is())
658cdf0e10cSrcweir     {
659cdf0e10cSrcweir         DBG_ERROR("OFormattedModel::calcFormFormatsSupplier : have no ancestor which is a form !");
660cdf0e10cSrcweir         return NULL;
661cdf0e10cSrcweir     }
662cdf0e10cSrcweir 
663cdf0e10cSrcweir     // den FormatSupplier von meinem Vorfahren (falls der einen hat)
664cdf0e10cSrcweir     Reference< XRowSet > xRowSet( xNextParentForm, UNO_QUERY );
665cdf0e10cSrcweir     Reference< XNumberFormatsSupplier > xSupplier;
666cdf0e10cSrcweir     if (xRowSet.is())
667cdf0e10cSrcweir         xSupplier = getNumberFormats( getConnection(xRowSet), sal_True, getContext().getLegacyServiceFactory() );
668cdf0e10cSrcweir     return xSupplier;
669cdf0e10cSrcweir }
670cdf0e10cSrcweir 
671cdf0e10cSrcweir //------------------------------------------------------------------------------
672cdf0e10cSrcweir Reference< XNumberFormatsSupplier > OFormattedModel::calcDefaultFormatsSupplier() const
673cdf0e10cSrcweir {
674cdf0e10cSrcweir     return StandardFormatsSupplier::get( getContext().getLegacyServiceFactory() );
675cdf0e10cSrcweir }
676cdf0e10cSrcweir 
677cdf0e10cSrcweir // XBoundComponent
678cdf0e10cSrcweir //------------------------------------------------------------------------------
679cdf0e10cSrcweir void OFormattedModel::loaded(const EventObject& rEvent) throw ( ::com::sun::star::uno::RuntimeException)
680cdf0e10cSrcweir {
681cdf0e10cSrcweir     // HACK : our onConnectedDbColumn accesses our NumberFormatter which locks the solar mutex (as it doesn't have
682cdf0e10cSrcweir     // an own one). To prevent deadlocks with other threads which may request a property from us in an
683cdf0e10cSrcweir     // UI-triggered action (e.g. an tooltip) we lock the solar mutex _here_ before our base class locks
684cdf0e10cSrcweir     // it's own muext (which is used for property requests)
685cdf0e10cSrcweir     // alternative a): we use two mutexes, one which is passed to the OPropertysetHelper and used for
686cdf0e10cSrcweir     // property requests and one for our own code. This would need a lot of code rewriting
687cdf0e10cSrcweir     // alternative b): The NumberFormatter has to be really threadsafe (with an own mutex), which is
688cdf0e10cSrcweir     // the only "clean" solution for me.
689cdf0e10cSrcweir     // FS - 69603 - 02.11.99
690cdf0e10cSrcweir 
691cdf0e10cSrcweir     ::vos::OGuard aGuard(Application::GetSolarMutex());
692cdf0e10cSrcweir     OEditBaseModel::loaded(rEvent);
693cdf0e10cSrcweir }
694cdf0e10cSrcweir 
695cdf0e10cSrcweir //------------------------------------------------------------------------------
696cdf0e10cSrcweir void OFormattedModel::onConnectedDbColumn( const Reference< XInterface >& _rxForm )
697cdf0e10cSrcweir {
698cdf0e10cSrcweir     m_xOriginalFormatter = NULL;
699cdf0e10cSrcweir 
700cdf0e10cSrcweir     // get some properties of the field
701cdf0e10cSrcweir     m_nFieldType = DataType::OTHER;
702cdf0e10cSrcweir     Reference<XPropertySet> xField = getField();
703cdf0e10cSrcweir     if ( xField.is() )
704cdf0e10cSrcweir         xField->getPropertyValue( PROPERTY_FIELDTYPE ) >>= m_nFieldType;
705cdf0e10cSrcweir 
706cdf0e10cSrcweir     sal_Int32 nFormatKey = 0;
707cdf0e10cSrcweir 
708cdf0e10cSrcweir     DBG_ASSERT(m_xAggregateSet.is(), "OFormattedModel::onConnectedDbColumn : have no aggregate !");
709cdf0e10cSrcweir     if (m_xAggregateSet.is())
710cdf0e10cSrcweir     {   // all the following doesn't make any sense if we have no aggregate ...
711cdf0e10cSrcweir         Any aSupplier = m_xAggregateSet->getPropertyValue(PROPERTY_FORMATSSUPPLIER);
712cdf0e10cSrcweir         DBG_ASSERT( aSupplier.hasValue(), "OFormattedModel::onConnectedDbColumn : invalid property value !" );
713cdf0e10cSrcweir         // das sollte im Constructor oder im read auf was richtiges gesetzt worden sein
714cdf0e10cSrcweir 
715cdf0e10cSrcweir         Any aFmtKey = m_xAggregateSet->getPropertyValue(PROPERTY_FORMATKEY);
716cdf0e10cSrcweir         if ( !(aFmtKey >>= nFormatKey ) )
717cdf0e10cSrcweir         {   // nobody gave us a format to use. So we examine the field we're bound to for a
718cdf0e10cSrcweir             // format key, and use it ourself, too
719cdf0e10cSrcweir             sal_Int32 nType = DataType::VARCHAR;
720cdf0e10cSrcweir             if (xField.is())
721cdf0e10cSrcweir             {
722cdf0e10cSrcweir                 aFmtKey = xField->getPropertyValue(PROPERTY_FORMATKEY);
723cdf0e10cSrcweir                 xField->getPropertyValue(PROPERTY_FIELDTYPE) >>= nType ;
724cdf0e10cSrcweir             }
725cdf0e10cSrcweir 
726cdf0e10cSrcweir             Reference<XNumberFormatsSupplier>  xSupplier = calcFormFormatsSupplier();
727cdf0e10cSrcweir             DBG_ASSERT(xSupplier.is(), "OFormattedModel::onConnectedDbColumn : bound to a field but no parent with a formatter ? how this ?");
728cdf0e10cSrcweir             if (xSupplier.is())
729cdf0e10cSrcweir             {
730cdf0e10cSrcweir                 m_bOriginalNumeric = getBOOL(getPropertyValue(PROPERTY_TREATASNUMERIC));
731cdf0e10cSrcweir 
732cdf0e10cSrcweir                 if (!aFmtKey.hasValue())
733cdf0e10cSrcweir                 {   // we aren't bound to a field (or this field's format is invalid)
734cdf0e10cSrcweir                     // -> determine the standard text (or numeric) format of the supplier
735cdf0e10cSrcweir                     Reference<XNumberFormatTypes>  xTypes(xSupplier->getNumberFormats(), UNO_QUERY);
736cdf0e10cSrcweir                     if (xTypes.is())
737cdf0e10cSrcweir                     {
738cdf0e10cSrcweir                         Locale aApplicationLocale = Application::GetSettings().GetUILocale();
739cdf0e10cSrcweir 
740cdf0e10cSrcweir                         if (m_bOriginalNumeric)
741cdf0e10cSrcweir                             aFmtKey <<= (sal_Int32)xTypes->getStandardFormat(NumberFormat::NUMBER, aApplicationLocale);
742cdf0e10cSrcweir                         else
743cdf0e10cSrcweir                             aFmtKey <<= (sal_Int32)xTypes->getStandardFormat(NumberFormat::TEXT, aApplicationLocale);
744cdf0e10cSrcweir                     }
745cdf0e10cSrcweir                 }
746cdf0e10cSrcweir 
747cdf0e10cSrcweir                 aSupplier >>= m_xOriginalFormatter;
748cdf0e10cSrcweir                 m_xAggregateSet->setPropertyValue(PROPERTY_FORMATSSUPPLIER, makeAny(xSupplier));
749cdf0e10cSrcweir                 m_xAggregateSet->setPropertyValue(PROPERTY_FORMATKEY, aFmtKey);
750cdf0e10cSrcweir 
751cdf0e10cSrcweir                 // das Numeric-Flag an mein gebundenes Feld anpassen
752cdf0e10cSrcweir                 if (xField.is())
753cdf0e10cSrcweir                 {
754cdf0e10cSrcweir                     m_bNumeric = sal_False;
755cdf0e10cSrcweir                     switch (nType)
756cdf0e10cSrcweir                     {
757cdf0e10cSrcweir                         case DataType::BIT:
758cdf0e10cSrcweir                         case DataType::BOOLEAN:
759cdf0e10cSrcweir                         case DataType::TINYINT:
760cdf0e10cSrcweir                         case DataType::SMALLINT:
761cdf0e10cSrcweir                         case DataType::INTEGER:
762cdf0e10cSrcweir                         case DataType::BIGINT:
763cdf0e10cSrcweir                         case DataType::FLOAT:
764cdf0e10cSrcweir                         case DataType::REAL:
765cdf0e10cSrcweir                         case DataType::DOUBLE:
766cdf0e10cSrcweir                         case DataType::NUMERIC:
767cdf0e10cSrcweir                         case DataType::DECIMAL:
768cdf0e10cSrcweir                         case DataType::DATE:
769cdf0e10cSrcweir                         case DataType::TIME:
770cdf0e10cSrcweir                         case DataType::TIMESTAMP:
771cdf0e10cSrcweir                             m_bNumeric = sal_True;
772cdf0e10cSrcweir                             break;
773cdf0e10cSrcweir                     }
774cdf0e10cSrcweir                 }
775cdf0e10cSrcweir                 else
776cdf0e10cSrcweir                     m_bNumeric = m_bOriginalNumeric;
777cdf0e10cSrcweir 
778cdf0e10cSrcweir                 setPropertyValue(PROPERTY_TREATASNUMERIC, makeAny((sal_Bool)m_bNumeric));
779cdf0e10cSrcweir 
780cdf0e10cSrcweir                 OSL_VERIFY( aFmtKey >>= nFormatKey );
781cdf0e10cSrcweir             }
782cdf0e10cSrcweir         }
783cdf0e10cSrcweir     }
784cdf0e10cSrcweir 
785cdf0e10cSrcweir     Reference<XNumberFormatsSupplier>  xSupplier = calcFormatsSupplier();
786cdf0e10cSrcweir     m_bNumeric = getBOOL( getPropertyValue( PROPERTY_TREATASNUMERIC ) );
787cdf0e10cSrcweir     m_nKeyType  = getNumberFormatType( xSupplier->getNumberFormats(), nFormatKey );
788cdf0e10cSrcweir     xSupplier->getNumberFormatSettings()->getPropertyValue( ::rtl::OUString::createFromAscii("NullDate") ) >>= m_aNullDate;
789cdf0e10cSrcweir 
790cdf0e10cSrcweir     OEditBaseModel::onConnectedDbColumn( _rxForm );
791cdf0e10cSrcweir }
792cdf0e10cSrcweir 
793cdf0e10cSrcweir //------------------------------------------------------------------------------
794cdf0e10cSrcweir void OFormattedModel::onDisconnectedDbColumn()
795cdf0e10cSrcweir {
796cdf0e10cSrcweir     OEditBaseModel::onDisconnectedDbColumn();
797cdf0e10cSrcweir     if (m_xOriginalFormatter.is())
798cdf0e10cSrcweir     {   // unser aggregiertes Model hatte keinerlei Format-Informationen
799cdf0e10cSrcweir         m_xAggregateSet->setPropertyValue(PROPERTY_FORMATSSUPPLIER, makeAny(m_xOriginalFormatter));
800cdf0e10cSrcweir         m_xAggregateSet->setPropertyValue(PROPERTY_FORMATKEY, Any());
801cdf0e10cSrcweir         setPropertyValue(PROPERTY_TREATASNUMERIC, makeAny((sal_Bool)m_bOriginalNumeric));
802cdf0e10cSrcweir         m_xOriginalFormatter = NULL;
803cdf0e10cSrcweir     }
804cdf0e10cSrcweir 
805cdf0e10cSrcweir     m_nFieldType = DataType::OTHER;
806cdf0e10cSrcweir     m_nKeyType   = NumberFormat::UNDEFINED;
807cdf0e10cSrcweir     m_aNullDate  = DBTypeConversion::getStandardDate();
808cdf0e10cSrcweir }
809cdf0e10cSrcweir 
810cdf0e10cSrcweir //------------------------------------------------------------------------------
811cdf0e10cSrcweir void OFormattedModel::write(const Reference<XObjectOutputStream>& _rxOutStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
812cdf0e10cSrcweir {
813cdf0e10cSrcweir     OEditBaseModel::write(_rxOutStream);
814cdf0e10cSrcweir     _rxOutStream->writeShort(0x0003);
815cdf0e10cSrcweir 
816cdf0e10cSrcweir     DBG_ASSERT(m_xAggregateSet.is(), "OFormattedModel::write : have no aggregate !");
817cdf0e10cSrcweir 
818cdf0e10cSrcweir     // mein Format (evtl. void) in ein persistentes Format bringen (der Supplier zusammen mit dem Key ist es zwar auch,
819cdf0e10cSrcweir     // aber deswegen muessen wir ja nicht gleich den ganzen Supplier speichern, das waere ein klein wenig Overhead ;)
820cdf0e10cSrcweir 
821cdf0e10cSrcweir         Reference<XNumberFormatsSupplier>  xSupplier;
822cdf0e10cSrcweir         Any aFmtKey;
823cdf0e10cSrcweir     sal_Bool bVoidKey = sal_True;
824cdf0e10cSrcweir     if (m_xAggregateSet.is())
825cdf0e10cSrcweir     {
826cdf0e10cSrcweir         Any aSupplier = m_xAggregateSet->getPropertyValue(PROPERTY_FORMATSSUPPLIER);
827cdf0e10cSrcweir         if (aSupplier.getValueType().getTypeClass() != TypeClass_VOID)
828cdf0e10cSrcweir         {
829cdf0e10cSrcweir             OSL_VERIFY( aSupplier >>= xSupplier );
830cdf0e10cSrcweir         }
831cdf0e10cSrcweir 
832cdf0e10cSrcweir         aFmtKey = m_xAggregateSet->getPropertyValue(PROPERTY_FORMATKEY);
833cdf0e10cSrcweir         bVoidKey = (!xSupplier.is() || !aFmtKey.hasValue()) || (isLoaded() && m_xOriginalFormatter.is());
834cdf0e10cSrcweir             // (kein Fomatter und/oder Key) oder (loaded und faked Formatter)
835cdf0e10cSrcweir     }
836cdf0e10cSrcweir 
837cdf0e10cSrcweir     _rxOutStream->writeBoolean(!bVoidKey);
838cdf0e10cSrcweir     if (!bVoidKey)
839cdf0e10cSrcweir     {
840cdf0e10cSrcweir         // aus dem FormatKey und dem Formatter persistente Angaben basteln
841cdf0e10cSrcweir 
842cdf0e10cSrcweir         Any aKey = m_xAggregateSet->getPropertyValue(PROPERTY_FORMATKEY);
843cdf0e10cSrcweir         sal_Int32 nKey = aKey.hasValue() ? getINT32(aKey) : 0;
844cdf0e10cSrcweir 
845cdf0e10cSrcweir         Reference<XNumberFormats>  xFormats = xSupplier->getNumberFormats();
846cdf0e10cSrcweir 
847cdf0e10cSrcweir         ::rtl::OUString         sFormatDescription;
848cdf0e10cSrcweir         LanguageType    eFormatLanguage = LANGUAGE_DONTKNOW;
849cdf0e10cSrcweir 
850cdf0e10cSrcweir         static const ::rtl::OUString s_aLocaleProp = ::rtl::OUString::createFromAscii("Locale");
851cdf0e10cSrcweir         Reference<com::sun::star::beans::XPropertySet>  xFormat = xFormats->getByKey(nKey);
852cdf0e10cSrcweir         if (hasProperty(s_aLocaleProp, xFormat))
853cdf0e10cSrcweir         {
854cdf0e10cSrcweir             Any aLocale = xFormat->getPropertyValue(s_aLocaleProp);
855cdf0e10cSrcweir             DBG_ASSERT(isA(aLocale, static_cast<Locale*>(NULL)), "OFormattedModel::write : invalid language property !");
856cdf0e10cSrcweir             if (isA(aLocale, static_cast<Locale*>(NULL)))
857cdf0e10cSrcweir             {
858cdf0e10cSrcweir                 Locale* pLocale = (Locale*)aLocale.getValue();
859cdf0e10cSrcweir                 eFormatLanguage = MsLangId::convertLocaleToLanguage( *pLocale );
860cdf0e10cSrcweir             }
861cdf0e10cSrcweir         }
862cdf0e10cSrcweir 
863cdf0e10cSrcweir         static const ::rtl::OUString s_aFormatStringProp = ::rtl::OUString::createFromAscii("FormatString");
864cdf0e10cSrcweir         if (hasProperty(s_aFormatStringProp, xFormat))
865cdf0e10cSrcweir             xFormat->getPropertyValue(s_aFormatStringProp) >>= sFormatDescription;
866cdf0e10cSrcweir 
867cdf0e10cSrcweir         _rxOutStream->writeUTF(sFormatDescription);
868cdf0e10cSrcweir         _rxOutStream->writeLong((sal_Int32)eFormatLanguage);
869cdf0e10cSrcweir     }
870cdf0e10cSrcweir 
871cdf0e10cSrcweir     // version 2 : write the properties common to all OEditBaseModels
872cdf0e10cSrcweir     writeCommonEditProperties(_rxOutStream);
873cdf0e10cSrcweir 
874cdf0e10cSrcweir     // version 3 : write the effective value property of the aggregate
875cdf0e10cSrcweir     // Due to a bug within the UnoControlFormattedFieldModel implementation (our default aggregate) this props value isn't correctly read
876cdf0e10cSrcweir     // and this can't be corrected without being incompatible.
877cdf0e10cSrcweir     // so we have our own handling.
878cdf0e10cSrcweir 
879cdf0e10cSrcweir     // and to be a little bit more compatible we make the following section skippable
880cdf0e10cSrcweir     {
881cdf0e10cSrcweir         Reference< XDataOutputStream > xOut(_rxOutStream, UNO_QUERY);
882cdf0e10cSrcweir         OStreamSection aDownCompat(xOut);
883cdf0e10cSrcweir 
884cdf0e10cSrcweir         // a sub version within the skippable block
885cdf0e10cSrcweir         _rxOutStream->writeShort(0x0000);
886cdf0e10cSrcweir 
887cdf0e10cSrcweir         // version 0: the effective value of the aggregate
888cdf0e10cSrcweir                 Any aEffectiveValue;
889cdf0e10cSrcweir         if (m_xAggregateSet.is())
890cdf0e10cSrcweir         {
891cdf0e10cSrcweir             try { aEffectiveValue = m_xAggregateSet->getPropertyValue(PROPERTY_EFFECTIVE_VALUE); } catch(Exception&) { }
892cdf0e10cSrcweir         }
893cdf0e10cSrcweir 
894cdf0e10cSrcweir         {
895cdf0e10cSrcweir             OStreamSection aDownCompat2(xOut);
896cdf0e10cSrcweir             switch (aEffectiveValue.getValueType().getTypeClass())
897cdf0e10cSrcweir             {
898cdf0e10cSrcweir                 case TypeClass_STRING:
899cdf0e10cSrcweir                     _rxOutStream->writeShort(0x0000);
900cdf0e10cSrcweir                     _rxOutStream->writeUTF(::comphelper::getString(aEffectiveValue));
901cdf0e10cSrcweir                     break;
902cdf0e10cSrcweir                 case TypeClass_DOUBLE:
903cdf0e10cSrcweir                     _rxOutStream->writeShort(0x0001);
904cdf0e10cSrcweir                     _rxOutStream->writeDouble(::comphelper::getDouble(aEffectiveValue));
905cdf0e10cSrcweir                     break;
906cdf0e10cSrcweir                 default:    // void and all unknown states
907cdf0e10cSrcweir                     DBG_ASSERT(!aEffectiveValue.hasValue(), "FmXFormattedModel::write : unknown property value type !");
908cdf0e10cSrcweir                     _rxOutStream->writeShort(0x0002);
909cdf0e10cSrcweir                     break;
910cdf0e10cSrcweir             }
911cdf0e10cSrcweir         }
912cdf0e10cSrcweir     }
913cdf0e10cSrcweir }
914cdf0e10cSrcweir 
915cdf0e10cSrcweir //------------------------------------------------------------------------------
916cdf0e10cSrcweir void OFormattedModel::read(const Reference<XObjectInputStream>& _rxInStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
917cdf0e10cSrcweir {
918cdf0e10cSrcweir     OEditBaseModel::read(_rxInStream);
919cdf0e10cSrcweir     sal_uInt16 nVersion = _rxInStream->readShort();
920cdf0e10cSrcweir 
921cdf0e10cSrcweir     Reference<XNumberFormatsSupplier>  xSupplier;
922cdf0e10cSrcweir     sal_Int32 nKey = -1;
923cdf0e10cSrcweir     switch (nVersion)
924cdf0e10cSrcweir     {
925cdf0e10cSrcweir         case 0x0001 :
926cdf0e10cSrcweir         case 0x0002 :
927cdf0e10cSrcweir         case 0x0003 :
928cdf0e10cSrcweir         {
929cdf0e10cSrcweir             sal_Bool bNonVoidKey = _rxInStream->readBoolean();
930cdf0e10cSrcweir             if (bNonVoidKey)
931cdf0e10cSrcweir             {
932cdf0e10cSrcweir                 // den String und die Language lesen ....
933cdf0e10cSrcweir                 ::rtl::OUString sFormatDescription = _rxInStream->readUTF();
934cdf0e10cSrcweir                 LanguageType eDescriptionLanguage = (LanguageType)_rxInStream->readLong();
935cdf0e10cSrcweir 
936cdf0e10cSrcweir                 // und daraus von einem Formatter zu einem Key zusammenwuerfeln lassen ...
937cdf0e10cSrcweir                 xSupplier = calcFormatsSupplier();
938cdf0e10cSrcweir                     // calcFormatsSupplier nimmt erst den vom Model, dann einen von der starform, dann einen ganz neuen ....
939cdf0e10cSrcweir                 Reference<XNumberFormats>  xFormats = xSupplier->getNumberFormats();
940cdf0e10cSrcweir 
941cdf0e10cSrcweir                 if (xFormats.is())
942cdf0e10cSrcweir                 {
943cdf0e10cSrcweir                     Locale aDescriptionLanguage( MsLangId::convertLanguageToLocale(eDescriptionLanguage));
944cdf0e10cSrcweir 
945cdf0e10cSrcweir                     nKey = xFormats->queryKey(sFormatDescription, aDescriptionLanguage, sal_False);
946cdf0e10cSrcweir                     if (nKey == (sal_Int32)-1)
947cdf0e10cSrcweir                     {   // noch nicht vorhanden in meinem Formatter ...
948cdf0e10cSrcweir                         nKey = xFormats->addNew(sFormatDescription, aDescriptionLanguage);
949cdf0e10cSrcweir                     }
950cdf0e10cSrcweir                 }
951cdf0e10cSrcweir             }
952cdf0e10cSrcweir             if ((nVersion == 0x0002) || (nVersion == 0x0003))
953cdf0e10cSrcweir                 readCommonEditProperties(_rxInStream);
954cdf0e10cSrcweir 
955cdf0e10cSrcweir             if (nVersion == 0x0003)
956cdf0e10cSrcweir             {   // since version 3 there is a "skippable" block at this position
957cdf0e10cSrcweir                 Reference< XDataInputStream > xIn(_rxInStream, UNO_QUERY);
958cdf0e10cSrcweir                 OStreamSection aDownCompat(xIn);
959cdf0e10cSrcweir 
960cdf0e10cSrcweir                 sal_Int16 nSubVersion = _rxInStream->readShort();
961cdf0e10cSrcweir                 (void)nSubVersion;
962cdf0e10cSrcweir 
963cdf0e10cSrcweir                 // version 0 and higher : the "effective value" property
964cdf0e10cSrcweir                 Any aEffectiveValue;
965cdf0e10cSrcweir                 {
966cdf0e10cSrcweir                     OStreamSection aDownCompat2(xIn);
967cdf0e10cSrcweir                     switch (_rxInStream->readShort())
968cdf0e10cSrcweir                     {
969cdf0e10cSrcweir                         case 0: // String
970cdf0e10cSrcweir                             aEffectiveValue <<= _rxInStream->readUTF();
971cdf0e10cSrcweir                             break;
972cdf0e10cSrcweir                         case 1: // double
973cdf0e10cSrcweir                             aEffectiveValue <<= (double)_rxInStream->readDouble();
974cdf0e10cSrcweir                             break;
975cdf0e10cSrcweir                         case 2:
976cdf0e10cSrcweir                             break;
977cdf0e10cSrcweir                         case 3:
978cdf0e10cSrcweir                             DBG_ERROR("FmXFormattedModel::read : unknown effective value type !");
979cdf0e10cSrcweir                     }
980cdf0e10cSrcweir                 }
981cdf0e10cSrcweir 
982cdf0e10cSrcweir                 // this property is only to be set if we have no control source : in all other cases the base class did a
983cdf0e10cSrcweir                 // reset after it's read and this set the effective value to a default value
984cdf0e10cSrcweir                 if ( m_xAggregateSet.is() && ( getControlSource().getLength() == 0 ) )
985cdf0e10cSrcweir                 {
986cdf0e10cSrcweir                     try
987cdf0e10cSrcweir                     {
988cdf0e10cSrcweir                         m_xAggregateSet->setPropertyValue(PROPERTY_EFFECTIVE_VALUE, aEffectiveValue);
989cdf0e10cSrcweir                     }
990cdf0e10cSrcweir                     catch(Exception&)
991cdf0e10cSrcweir                     {
992cdf0e10cSrcweir                     }
993cdf0e10cSrcweir                 }
994cdf0e10cSrcweir             }
995cdf0e10cSrcweir         }
996cdf0e10cSrcweir         break;
997cdf0e10cSrcweir         default :
998cdf0e10cSrcweir             DBG_ERROR("OFormattedModel::read : unknown version !");
999cdf0e10cSrcweir             // dann bleibt das Format des aggregierten Sets, wie es bei der Erzeugung ist : void
1000cdf0e10cSrcweir             defaultCommonEditProperties();
1001cdf0e10cSrcweir             break;
1002cdf0e10cSrcweir     }
1003cdf0e10cSrcweir 
1004cdf0e10cSrcweir     if ((nKey != -1) && m_xAggregateSet.is())
1005cdf0e10cSrcweir     {
1006cdf0e10cSrcweir                 m_xAggregateSet->setPropertyValue(PROPERTY_FORMATSSUPPLIER, makeAny(xSupplier));
1007cdf0e10cSrcweir                 m_xAggregateSet->setPropertyValue(PROPERTY_FORMATKEY, makeAny((sal_Int32)nKey));
1008cdf0e10cSrcweir     }
1009cdf0e10cSrcweir     else
1010cdf0e10cSrcweir     {
1011cdf0e10cSrcweir         setPropertyToDefault(PROPERTY_FORMATSSUPPLIER);
1012cdf0e10cSrcweir         setPropertyToDefault(PROPERTY_FORMATKEY);
1013cdf0e10cSrcweir     }
1014cdf0e10cSrcweir }
1015cdf0e10cSrcweir 
1016cdf0e10cSrcweir //------------------------------------------------------------------------------
1017cdf0e10cSrcweir sal_uInt16 OFormattedModel::getPersistenceFlags() const
1018cdf0e10cSrcweir {
1019cdf0e10cSrcweir     return (OEditBaseModel::getPersistenceFlags() & ~PF_HANDLE_COMMON_PROPS);
1020cdf0e10cSrcweir     // a) we do our own call to writeCommonEditProperties
1021cdf0e10cSrcweir }
1022cdf0e10cSrcweir 
1023cdf0e10cSrcweir //------------------------------------------------------------------------------
1024cdf0e10cSrcweir sal_Bool OFormattedModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
1025cdf0e10cSrcweir {
1026cdf0e10cSrcweir     Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
1027cdf0e10cSrcweir     if ( aControlValue != m_aSaveValue )
1028cdf0e10cSrcweir     {
1029cdf0e10cSrcweir         // Leerstring + EmptyIsNull = void
1030cdf0e10cSrcweir         if  (   !aControlValue.hasValue()
1031cdf0e10cSrcweir             ||  (   ( aControlValue.getValueType().getTypeClass() == TypeClass_STRING )
1032cdf0e10cSrcweir                 &&  ( getString( aControlValue ).getLength() == 0 )
1033cdf0e10cSrcweir                 &&  m_bEmptyIsNull
1034cdf0e10cSrcweir                 )
1035cdf0e10cSrcweir             )
1036cdf0e10cSrcweir             m_xColumnUpdate->updateNull();
1037cdf0e10cSrcweir         else
1038cdf0e10cSrcweir         {
1039cdf0e10cSrcweir             try
1040cdf0e10cSrcweir             {
1041cdf0e10cSrcweir                 double f = 0.0;
1042cdf0e10cSrcweir                 if ( aControlValue.getValueType().getTypeClass() == TypeClass_DOUBLE || (aControlValue >>= f)) // #i110323
1043cdf0e10cSrcweir                 {
1044cdf0e10cSrcweir                     DBTypeConversion::setValue( m_xColumnUpdate, m_aNullDate, getDouble( aControlValue ), m_nKeyType );
1045cdf0e10cSrcweir                 }
1046cdf0e10cSrcweir                 else
1047cdf0e10cSrcweir                 {
1048cdf0e10cSrcweir                     DBG_ASSERT( aControlValue.getValueType().getTypeClass() == TypeClass_STRING, "OFormattedModel::commitControlValueToDbColumn: invalud value type !" );
1049cdf0e10cSrcweir                     m_xColumnUpdate->updateString( getString( aControlValue ) );
1050cdf0e10cSrcweir                 }
1051cdf0e10cSrcweir             }
1052cdf0e10cSrcweir             catch(Exception&)
1053cdf0e10cSrcweir             {
1054cdf0e10cSrcweir                 return sal_False;
1055cdf0e10cSrcweir             }
1056cdf0e10cSrcweir         }
1057cdf0e10cSrcweir         m_aSaveValue = aControlValue;
1058cdf0e10cSrcweir     }
1059cdf0e10cSrcweir     return sal_True;
1060cdf0e10cSrcweir }
1061cdf0e10cSrcweir 
1062cdf0e10cSrcweir //------------------------------------------------------------------------------
1063cdf0e10cSrcweir void OFormattedModel::onConnectedExternalValue( )
1064cdf0e10cSrcweir {
1065cdf0e10cSrcweir     OEditBaseModel::onConnectedExternalValue();
1066cdf0e10cSrcweir     updateFormatterNullDate();
1067cdf0e10cSrcweir }
1068cdf0e10cSrcweir 
1069cdf0e10cSrcweir //------------------------------------------------------------------------------
1070cdf0e10cSrcweir Any OFormattedModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const
1071cdf0e10cSrcweir {
1072cdf0e10cSrcweir     Any aControlValue;
1073cdf0e10cSrcweir     switch( _rExternalValue.getValueTypeClass() )
1074cdf0e10cSrcweir     {
1075cdf0e10cSrcweir     case TypeClass_VOID:
1076cdf0e10cSrcweir         break;
1077cdf0e10cSrcweir 
1078cdf0e10cSrcweir     case TypeClass_STRING:
1079cdf0e10cSrcweir         aControlValue = _rExternalValue;
1080cdf0e10cSrcweir         break;
1081cdf0e10cSrcweir 
1082cdf0e10cSrcweir     case TypeClass_BOOLEAN:
1083cdf0e10cSrcweir     {
1084cdf0e10cSrcweir         sal_Bool bExternalValue = sal_False;
1085cdf0e10cSrcweir         _rExternalValue >>= bExternalValue;
1086cdf0e10cSrcweir         aControlValue <<= (double)( bExternalValue ? 1 : 0 );
1087cdf0e10cSrcweir     }
1088cdf0e10cSrcweir     break;
1089cdf0e10cSrcweir 
1090cdf0e10cSrcweir     default:
1091cdf0e10cSrcweir     {
1092cdf0e10cSrcweir         if ( _rExternalValue.getValueType().equals( ::getCppuType( static_cast< UNODate* >( NULL ) ) ) )
1093cdf0e10cSrcweir         {
1094cdf0e10cSrcweir             UNODate aDate;
1095cdf0e10cSrcweir             _rExternalValue >>= aDate;
1096cdf0e10cSrcweir             aControlValue <<= DBTypeConversion::toDouble( aDate, m_aNullDate );
1097cdf0e10cSrcweir         }
1098cdf0e10cSrcweir         else if ( _rExternalValue.getValueType().equals( ::getCppuType( static_cast< UNOTime* >( NULL ) ) ) )
1099cdf0e10cSrcweir         {
1100cdf0e10cSrcweir             UNOTime aTime;
1101cdf0e10cSrcweir             _rExternalValue >>= aTime;
1102cdf0e10cSrcweir             aControlValue <<= DBTypeConversion::toDouble( aTime );
1103cdf0e10cSrcweir         }
1104cdf0e10cSrcweir         else if ( _rExternalValue.getValueType().equals( ::getCppuType( static_cast< UNODateTime* >( NULL ) ) ) )
1105cdf0e10cSrcweir         {
1106cdf0e10cSrcweir             UNODateTime aDateTime;
1107cdf0e10cSrcweir             _rExternalValue >>= aDateTime;
1108cdf0e10cSrcweir             aControlValue <<= DBTypeConversion::toDouble( aDateTime, m_aNullDate );
1109cdf0e10cSrcweir         }
1110cdf0e10cSrcweir         else
1111cdf0e10cSrcweir         {
1112cdf0e10cSrcweir             OSL_ENSURE( _rExternalValue.getValueTypeClass() == TypeClass_DOUBLE,
1113cdf0e10cSrcweir                 "OFormattedModel::translateExternalValueToControlValue: don't know how to translate this type!" );
1114cdf0e10cSrcweir             double fValue = 0;
1115cdf0e10cSrcweir             OSL_VERIFY( _rExternalValue >>= fValue );
1116cdf0e10cSrcweir             aControlValue <<= fValue;
1117cdf0e10cSrcweir         }
1118cdf0e10cSrcweir     }
1119cdf0e10cSrcweir     }
1120cdf0e10cSrcweir 
1121cdf0e10cSrcweir     return aControlValue;
1122cdf0e10cSrcweir }
1123cdf0e10cSrcweir 
1124cdf0e10cSrcweir //------------------------------------------------------------------------------
1125cdf0e10cSrcweir Any OFormattedModel::translateControlValueToExternalValue( ) const
1126cdf0e10cSrcweir {
1127cdf0e10cSrcweir     OSL_PRECOND( hasExternalValueBinding(),
1128cdf0e10cSrcweir         "OFormattedModel::translateControlValueToExternalValue: precondition not met!" );
1129cdf0e10cSrcweir 
1130cdf0e10cSrcweir     Any aControlValue( getControlValue() );
1131cdf0e10cSrcweir     if ( !aControlValue.hasValue() )
1132cdf0e10cSrcweir         return aControlValue;
1133cdf0e10cSrcweir 
1134cdf0e10cSrcweir     Any aExternalValue;
1135cdf0e10cSrcweir 
1136cdf0e10cSrcweir     // translate into the the external value type
1137cdf0e10cSrcweir     Type aExternalValueType( getExternalValueType() );
1138cdf0e10cSrcweir     switch ( aExternalValueType.getTypeClass() )
1139cdf0e10cSrcweir     {
1140cdf0e10cSrcweir     case TypeClass_STRING:
1141cdf0e10cSrcweir     {
1142cdf0e10cSrcweir         ::rtl::OUString sString;
1143cdf0e10cSrcweir         if ( aControlValue >>= sString )
1144cdf0e10cSrcweir         {
1145cdf0e10cSrcweir             aExternalValue <<= sString;
1146cdf0e10cSrcweir             break;
1147cdf0e10cSrcweir         }
1148cdf0e10cSrcweir     }
1149cdf0e10cSrcweir     // NO break here!
1150cdf0e10cSrcweir 
1151cdf0e10cSrcweir     case TypeClass_BOOLEAN:
1152cdf0e10cSrcweir     {
1153cdf0e10cSrcweir         double fValue = 0;
1154cdf0e10cSrcweir         OSL_VERIFY( aControlValue >>= fValue );
1155cdf0e10cSrcweir             // if this asserts ... well, the somebody set the TreatAsNumeric property to false,
1156cdf0e10cSrcweir             // and the control value is a string. This implies some weird misconfiguration
1157cdf0e10cSrcweir             // of the FormattedModel, so we won't care for it for the moment.
1158cdf0e10cSrcweir         aExternalValue <<= (sal_Bool)( fValue ? sal_True : sal_False );
1159cdf0e10cSrcweir     }
1160cdf0e10cSrcweir     break;
1161cdf0e10cSrcweir 
1162cdf0e10cSrcweir     default:
1163cdf0e10cSrcweir     {
1164cdf0e10cSrcweir         double fValue = 0;
1165cdf0e10cSrcweir         OSL_VERIFY( aControlValue >>= fValue );
1166cdf0e10cSrcweir             // if this asserts ... well, the somebody set the TreatAsNumeric property to false,
1167cdf0e10cSrcweir             // and the control value is a string. This implies some weird misconfiguration
1168cdf0e10cSrcweir             // of the FormattedModel, so we won't care for it for the moment.
1169cdf0e10cSrcweir 
1170cdf0e10cSrcweir         if ( aExternalValueType.equals( ::getCppuType( static_cast< UNODate* >( NULL ) ) ) )
1171cdf0e10cSrcweir         {
1172cdf0e10cSrcweir             aExternalValue <<= DBTypeConversion::toDate( fValue, m_aNullDate );
1173cdf0e10cSrcweir         }
1174cdf0e10cSrcweir         else if ( aExternalValueType.equals( ::getCppuType( static_cast< UNOTime* >( NULL ) ) ) )
1175cdf0e10cSrcweir         {
1176cdf0e10cSrcweir             aExternalValue <<= DBTypeConversion::toTime( fValue );
1177cdf0e10cSrcweir         }
1178cdf0e10cSrcweir         else if ( aExternalValueType.equals( ::getCppuType( static_cast< UNODateTime* >( NULL ) ) ) )
1179cdf0e10cSrcweir         {
1180cdf0e10cSrcweir             aExternalValue <<= DBTypeConversion::toDateTime( fValue, m_aNullDate );
1181cdf0e10cSrcweir         }
1182cdf0e10cSrcweir         else
1183cdf0e10cSrcweir         {
1184cdf0e10cSrcweir             OSL_ENSURE( aExternalValueType.equals( ::getCppuType( static_cast< double* >( NULL ) ) ),
1185cdf0e10cSrcweir                 "OFormattedModel::translateControlValueToExternalValue: don't know how to translate this type!" );
1186cdf0e10cSrcweir             aExternalValue <<= fValue;
1187cdf0e10cSrcweir         }
1188cdf0e10cSrcweir     }
1189cdf0e10cSrcweir     break;
1190cdf0e10cSrcweir     }
1191cdf0e10cSrcweir     return aExternalValue;
1192cdf0e10cSrcweir }
1193cdf0e10cSrcweir 
1194cdf0e10cSrcweir //------------------------------------------------------------------------------
1195cdf0e10cSrcweir Any OFormattedModel::translateDbColumnToControlValue()
1196cdf0e10cSrcweir {
1197cdf0e10cSrcweir     if ( m_bNumeric )
1198cdf0e10cSrcweir         m_aSaveValue <<= DBTypeConversion::getValue( m_xColumn, m_aNullDate ); // #100056# OJ
1199cdf0e10cSrcweir     else
1200cdf0e10cSrcweir         m_aSaveValue <<= m_xColumn->getString();
1201cdf0e10cSrcweir 
1202cdf0e10cSrcweir     if ( m_xColumn->wasNull() )
1203cdf0e10cSrcweir         m_aSaveValue.clear();
1204cdf0e10cSrcweir 
1205cdf0e10cSrcweir     return m_aSaveValue;
1206cdf0e10cSrcweir }
1207cdf0e10cSrcweir 
1208cdf0e10cSrcweir // -----------------------------------------------------------------------------
1209cdf0e10cSrcweir Sequence< Type > OFormattedModel::getSupportedBindingTypes()
1210cdf0e10cSrcweir {
1211cdf0e10cSrcweir     ::std::list< Type > aTypes;
1212cdf0e10cSrcweir     aTypes.push_back( ::getCppuType( static_cast< double* >( NULL ) ) );
1213cdf0e10cSrcweir 
1214cdf0e10cSrcweir     switch ( m_nKeyType & ~NumberFormat::DEFINED )
1215cdf0e10cSrcweir     {
1216cdf0e10cSrcweir     case NumberFormat::DATE:
1217cdf0e10cSrcweir         aTypes.push_front(::getCppuType( static_cast< UNODate* >( NULL ) ) );
1218cdf0e10cSrcweir         break;
1219cdf0e10cSrcweir     case NumberFormat::TIME:
1220cdf0e10cSrcweir         aTypes.push_front(::getCppuType( static_cast< UNOTime* >( NULL ) ) );
1221cdf0e10cSrcweir         break;
1222cdf0e10cSrcweir     case NumberFormat::DATETIME:
1223cdf0e10cSrcweir         aTypes.push_front(::getCppuType( static_cast< UNODateTime* >( NULL ) ) );
1224cdf0e10cSrcweir         break;
1225cdf0e10cSrcweir     case NumberFormat::TEXT:
1226cdf0e10cSrcweir         aTypes.push_front(::getCppuType( static_cast< ::rtl::OUString* >( NULL ) ) );
1227cdf0e10cSrcweir         break;
1228cdf0e10cSrcweir     case NumberFormat::LOGICAL:
1229cdf0e10cSrcweir         aTypes.push_front(::getCppuType( static_cast< sal_Bool* >( NULL ) ) );
1230cdf0e10cSrcweir         break;
1231cdf0e10cSrcweir     }
1232cdf0e10cSrcweir 
1233cdf0e10cSrcweir     Sequence< Type > aTypesRet( aTypes.size() );
1234cdf0e10cSrcweir     ::std::copy( aTypes.begin(), aTypes.end(), aTypesRet.getArray() );
1235cdf0e10cSrcweir     return aTypesRet;
1236cdf0e10cSrcweir }
1237cdf0e10cSrcweir 
1238cdf0e10cSrcweir //------------------------------------------------------------------------------
1239cdf0e10cSrcweir Any OFormattedModel::getDefaultForReset() const
1240cdf0e10cSrcweir {
1241cdf0e10cSrcweir     return m_xAggregateSet->getPropertyValue( PROPERTY_EFFECTIVE_DEFAULT );
1242cdf0e10cSrcweir }
1243cdf0e10cSrcweir 
1244cdf0e10cSrcweir //------------------------------------------------------------------------------
1245cdf0e10cSrcweir void OFormattedModel::resetNoBroadcast()
1246cdf0e10cSrcweir {
1247cdf0e10cSrcweir     OEditBaseModel::resetNoBroadcast();
1248cdf0e10cSrcweir     m_aSaveValue.clear();
1249cdf0e10cSrcweir }
1250cdf0e10cSrcweir 
1251cdf0e10cSrcweir //.........................................................................
1252cdf0e10cSrcweir }
1253cdf0e10cSrcweir //.........................................................................
1254