1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_forms.hxx"
26
27 #include "componenttools.hxx"
28 #include "DatabaseForm.hxx"
29 #include "EventThread.hxx"
30 #include "frm_module.hxx"
31 #include "frm_resource.hrc"
32 #include "frm_resource.hxx"
33 #include "GroupManager.hxx"
34 #include "property.hrc"
35 #include "property.hxx"
36 #include "services.hxx"
37
38 #include <com/sun/star/awt/XControlContainer.hpp>
39 #include <com/sun/star/awt/XTextComponent.hpp>
40 #include <com/sun/star/form/DataSelectionType.hpp>
41 #include <com/sun/star/form/FormComponentType.hpp>
42 #include <com/sun/star/form/TabulatorCycle.hpp>
43 #include <com/sun/star/frame/FrameSearchFlag.hpp>
44 #include <com/sun/star/frame/XDispatch.hpp>
45 #include <com/sun/star/frame/XDispatchProvider.hpp>
46 #include <com/sun/star/frame/XModel.hpp>
47 #include <com/sun/star/io/XObjectInputStream.hpp>
48 #include <com/sun/star/io/XObjectOutputStream.hpp>
49 #include <com/sun/star/sdb/CommandType.hpp>
50 #include <com/sun/star/sdb/RowSetVetoException.hpp>
51 #include <com/sun/star/sdb/SQLContext.hpp>
52 #include <com/sun/star/sdb/XColumnUpdate.hpp>
53 #include <com/sun/star/sdbc/DataType.hpp>
54 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
55 #include <com/sun/star/sdbc/ResultSetType.hpp>
56 #include <com/sun/star/sdbc/XRowSet.hpp>
57 #include <com/sun/star/sdbcx/Privilege.hpp>
58 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
59 #include <com/sun/star/util/XCancellable.hpp>
60 #include <com/sun/star/util/XURLTransformer.hpp>
61 #include <com/sun/star/util/XModifiable2.hpp>
62
63 #include <comphelper/basicio.hxx>
64 #include <comphelper/container.hxx>
65 #include <comphelper/enumhelper.hxx>
66 #include <comphelper/extract.hxx>
67 #include <comphelper/seqstream.hxx>
68 #include <comphelper/sequence.hxx>
69 #include <comphelper/stl_types.hxx>
70 #include <comphelper/uno3.hxx>
71 #include <connectivity/dbtools.hxx>
72 #include <cppuhelper/exc_hlp.hxx>
73 #include <cppuhelper/implbase2.hxx>
74 #include <osl/mutex.hxx>
75 #include <rtl/math.hxx>
76 #include <rtl/tencinfo.h>
77 #include <svl/inetstrm.hxx>
78 #include <svl/inettype.hxx>
79 #include <tools/debug.hxx>
80 #include <tools/diagnose_ex.h>
81 #include <tools/fsys.hxx>
82 #include <tools/inetmsg.hxx>
83 #include <tools/urlobj.hxx>
84 #include <unotools/ucblockbytes.hxx>
85 #include <unotools/ucbstreamhelper.hxx>
86 #include <vcl/svapp.hxx>
87 #include <vcl/timer.hxx>
88 #include <vos/mutex.hxx>
89
90 #include <ctype.h>
91 #include <hash_map>
92
93 // compatiblity: DatabaseCursorType is dead, but for compatiblity reasons we still have to write it ...
94 namespace com {
95 namespace sun {
96 namespace star {
97 namespace data {
98
99 enum DatabaseCursorType
100 {
101 DatabaseCursorType_FORWARD = 0,
102 DatabaseCursorType_SNAPSHOT = 1,
103 DatabaseCursorType_KEYSET = 2,
104 DatabaseCursorType_DYNAMIC = 3,
105 DatabaseCursorType_MAKE_FIXED_SIZE = SAL_MAX_ENUM
106 };
107
108 } } } }
109
110 using namespace ::dbtools;
111 using namespace ::comphelper;
112 using namespace ::com::sun::star::uno;
113 using namespace ::com::sun::star::sdb;
114 using namespace ::com::sun::star::sdbc;
115 using namespace ::com::sun::star::sdbcx;
116 using namespace ::com::sun::star::beans;
117 using namespace ::com::sun::star::container;
118 using namespace ::com::sun::star::task;
119 using namespace ::com::sun::star::frame;
120 using namespace ::com::sun::star::form;
121 using namespace ::com::sun::star::awt;
122 using namespace ::com::sun::star::io;
123 using namespace ::com::sun::star::lang;
124 using namespace ::com::sun::star::data;
125 using namespace ::com::sun::star::util;
126
127 //--------------------------------------------------------------------------
createRegistryInfo_ODatabaseForm()128 extern "C" void SAL_CALL createRegistryInfo_ODatabaseForm()
129 {
130 static ::frm::OMultiInstanceAutoRegistration< ::frm::ODatabaseForm > aAutoRegistration;
131 }
132
133 //.........................................................................
134 namespace frm
135 {
136 //.........................................................................
137
138 //==================================================================
139 //= DocumentModifyGuard
140 //==================================================================
141 class DocumentModifyGuard
142 {
143 public:
DocumentModifyGuard(const Reference<XInterface> & _rxFormComponent)144 DocumentModifyGuard( const Reference< XInterface >& _rxFormComponent )
145 :m_xDocumentModify( getXModel( _rxFormComponent ), UNO_QUERY )
146 {
147 impl_changeModifiableFlag_nothrow( false );
148 }
~DocumentModifyGuard()149 ~DocumentModifyGuard()
150 {
151 impl_changeModifiableFlag_nothrow( true );
152 }
153
154 private:
impl_changeModifiableFlag_nothrow(const bool _enable)155 void impl_changeModifiableFlag_nothrow( const bool _enable )
156 {
157 try
158 {
159 if ( m_xDocumentModify.is() )
160 _enable ? m_xDocumentModify->enableSetModified() : m_xDocumentModify->disableSetModified();
161 }
162 catch( const Exception& )
163 {
164 DBG_UNHANDLED_EXCEPTION();
165 }
166 }
167
168 private:
169 Reference< XModifiable2 > m_xDocumentModify;
170 };
171
172 //==================================================================
173 //= OFormSubmitResetThread
174 //=-----------------------------------------------------------------
175 //= submitting and resetting html-forms asynchronously
176 //==================================================================
177
178 //------------------------------------------------------------------
179 class OFormSubmitResetThread: public OComponentEventThread
180 {
181 protected:
182
183 // duplicate an event with respect to it's type
184 virtual EventObject *cloneEvent( const EventObject *pEvt ) const;
185
186 // process an event. while processing the mutex isn't locked, and pCompImpl
187 // is made sure to remain valid
188 virtual void processEvent( ::cppu::OComponentHelper* _pCompImpl,
189 const EventObject* _pEvt,
190 const Reference<XControl>& _rControl,
191 sal_Bool _bSubmit);
192
193 public:
194
OFormSubmitResetThread(ODatabaseForm * pControl)195 OFormSubmitResetThread(ODatabaseForm* pControl) : OComponentEventThread(pControl) { }
196 };
197
198 //------------------------------------------------------------------
cloneEvent(const EventObject * pEvt) const199 EventObject* OFormSubmitResetThread::cloneEvent(
200 const EventObject *pEvt ) const
201 {
202 return new ::com::sun::star::awt::MouseEvent( *(::com::sun::star::awt::MouseEvent *)pEvt );
203 }
204
205 //------------------------------------------------------------------
processEvent(::cppu::OComponentHelper * pCompImpl,const EventObject * _pEvt,const Reference<XControl> & _rControl,sal_Bool _bSubmit)206 void OFormSubmitResetThread::processEvent(
207 ::cppu::OComponentHelper* pCompImpl,
208 const EventObject *_pEvt,
209 const Reference<XControl>& _rControl,
210 sal_Bool _bSubmit)
211 {
212 if (_bSubmit)
213 ((ODatabaseForm *)pCompImpl)->submit_impl(_rControl, *static_cast<const ::com::sun::star::awt::MouseEvent*>(_pEvt), true);
214 else
215 ((ODatabaseForm *)pCompImpl)->reset_impl(true);
216 }
217
218 //==================================================================
219 //= ODatabaseForm
220 //==================================================================
221
222 //------------------------------------------------------------------
Create(const Reference<XMultiServiceFactory> & _rxFactory)223 Reference< XInterface > SAL_CALL ODatabaseForm::Create( const Reference< XMultiServiceFactory >& _rxFactory )
224 {
225 return *( new ODatabaseForm( _rxFactory ) );
226 }
227
228 //------------------------------------------------------------------------------
getImplementationId()229 Sequence<sal_Int8> SAL_CALL ODatabaseForm::getImplementationId() throw(RuntimeException)
230 {
231 return OImplementationIds::getImplementationId(getTypes());
232 }
233
234 //------------------------------------------------------------------
getTypes()235 Sequence<Type> SAL_CALL ODatabaseForm::getTypes() throw(RuntimeException)
236 {
237 // ask the aggregate
238 Sequence<Type> aAggregateTypes;
239 Reference<XTypeProvider> xAggregateTypes;
240 if (query_aggregation(m_xAggregate, xAggregateTypes))
241 aAggregateTypes = xAggregateTypes->getTypes();
242
243 Sequence< Type > aRet = concatSequences(
244 aAggregateTypes, ODatabaseForm_BASE1::getTypes(), OFormComponents::getTypes()
245 );
246 aRet = concatSequences( aRet, ODatabaseForm_BASE2::getTypes(), ODatabaseForm_BASE3::getTypes() );
247 return concatSequences( aRet, OPropertySetAggregationHelper::getTypes() );
248 }
249
250 //------------------------------------------------------------------
queryAggregation(const Type & _rType)251 Any SAL_CALL ODatabaseForm::queryAggregation(const Type& _rType) throw(RuntimeException)
252 {
253 Any aReturn = ODatabaseForm_BASE1::queryInterface(_rType);
254 // our own interfaces
255 if (!aReturn.hasValue())
256 {
257 aReturn = ODatabaseForm_BASE2::queryInterface(_rType);
258 // property set related interfaces
259 if (!aReturn.hasValue())
260 {
261 aReturn = OPropertySetAggregationHelper::queryInterface(_rType);
262
263 // form component collection related interfaces
264 if (!aReturn.hasValue())
265 {
266 aReturn = OFormComponents::queryAggregation(_rType);
267
268 // interfaces already present in the aggregate which we want to reroute
269 // only available if we could create the aggregate
270 if (!aReturn.hasValue() && m_xAggregateAsRowSet.is())
271 aReturn = ODatabaseForm_BASE3::queryInterface(_rType);
272
273 // aggregate interfaces
274 // (ask the aggregated object _after_ the OComponentHelper (base of OFormComponents),
275 // so calls to the XComponent interface reach us and not the aggreagtion)
276 if (!aReturn.hasValue() && m_xAggregate.is())
277 aReturn = m_xAggregate->queryAggregation(_rType);
278 }
279 }
280 }
281
282 return aReturn;
283 }
284
285 DBG_NAME(ODatabaseForm);
286 //------------------------------------------------------------------
ODatabaseForm(const Reference<XMultiServiceFactory> & _rxFactory)287 ODatabaseForm::ODatabaseForm(const Reference<XMultiServiceFactory>& _rxFactory)
288 :OFormComponents(_rxFactory)
289 ,OPropertySetAggregationHelper(OComponentHelper::rBHelper)
290 ,OPropertyChangeListener(m_aMutex)
291 ,m_aLoadListeners(m_aMutex)
292 ,m_aRowSetApproveListeners(m_aMutex)
293 ,m_aRowSetListeners(m_aMutex)
294 ,m_aSubmitListeners(m_aMutex)
295 ,m_aErrorListeners(m_aMutex)
296 ,m_aResetListeners( *this, m_aMutex )
297 ,m_aPropertyBagHelper( *this )
298 ,m_pAggregatePropertyMultiplexer(NULL)
299 ,m_pGroupManager( NULL )
300 ,m_aParameterManager( m_aMutex, _rxFactory )
301 ,m_aFilterManager( _rxFactory )
302 ,m_pLoadTimer(NULL)
303 ,m_pThread(NULL)
304 ,m_nResetsPending(0)
305 ,m_nPrivileges(0)
306 ,m_bInsertOnly( sal_False )
307 ,m_eSubmitMethod(FormSubmitMethod_GET)
308 ,m_eSubmitEncoding(FormSubmitEncoding_URL)
309 ,m_eNavigation(NavigationBarMode_CURRENT)
310 ,m_bAllowInsert(sal_True)
311 ,m_bAllowUpdate(sal_True)
312 ,m_bAllowDelete(sal_True)
313 ,m_bLoaded(sal_False)
314 ,m_bSubForm(sal_False)
315 ,m_bForwardingConnection(sal_False)
316 ,m_bSharingConnection( sal_False )
317 {
318 DBG_CTOR( ODatabaseForm, NULL );
319 impl_construct();
320 }
321
322 //------------------------------------------------------------------
ODatabaseForm(const ODatabaseForm & _cloneSource)323 ODatabaseForm::ODatabaseForm( const ODatabaseForm& _cloneSource )
324 :OFormComponents( _cloneSource )
325 ,OPropertySetAggregationHelper( OComponentHelper::rBHelper )
326 ,OPropertyChangeListener( m_aMutex )
327 ,ODatabaseForm_BASE1()
328 ,ODatabaseForm_BASE2()
329 ,ODatabaseForm_BASE3()
330 ,IPropertyBagHelperContext()
331 ,m_aLoadListeners( m_aMutex )
332 ,m_aRowSetApproveListeners( m_aMutex )
333 ,m_aRowSetListeners( m_aMutex )
334 ,m_aSubmitListeners( m_aMutex )
335 ,m_aErrorListeners( m_aMutex )
336 ,m_aResetListeners( *this, m_aMutex )
337 ,m_aPropertyBagHelper( *this )
338 ,m_pAggregatePropertyMultiplexer( NULL )
339 ,m_pGroupManager( NULL )
340 ,m_aParameterManager( m_aMutex, _cloneSource.m_xServiceFactory )
341 ,m_aFilterManager( _cloneSource.m_xServiceFactory )
342 ,m_pLoadTimer( NULL )
343 ,m_pThread( NULL )
344 ,m_nResetsPending( 0 )
345 ,m_nPrivileges( 0 )
346 ,m_bInsertOnly( _cloneSource.m_bInsertOnly )
347 ,m_aControlBorderColorFocus( _cloneSource.m_aControlBorderColorFocus )
348 ,m_aControlBorderColorMouse( _cloneSource.m_aControlBorderColorMouse )
349 ,m_aControlBorderColorInvalid( _cloneSource.m_aControlBorderColorInvalid )
350 ,m_aDynamicControlBorder( _cloneSource.m_aDynamicControlBorder )
351 ,m_sName( _cloneSource.m_sName )
352 ,m_aTargetURL( _cloneSource.m_aTargetURL )
353 ,m_aTargetFrame( _cloneSource.m_aTargetFrame )
354 ,m_eSubmitMethod( _cloneSource.m_eSubmitMethod )
355 ,m_eSubmitEncoding( _cloneSource.m_eSubmitEncoding )
356 ,m_eNavigation( _cloneSource.m_eNavigation )
357 ,m_bAllowInsert( _cloneSource.m_bAllowInsert )
358 ,m_bAllowUpdate( _cloneSource.m_bAllowUpdate )
359 ,m_bAllowDelete( _cloneSource.m_bAllowDelete )
360 ,m_bLoaded( sal_False )
361 ,m_bSubForm( sal_False )
362 ,m_bForwardingConnection( sal_False )
363 ,m_bSharingConnection( sal_False )
364 {
365 DBG_CTOR( ODatabaseForm, NULL );
366
367 impl_construct();
368
369 osl_incrementInterlockedCount( &m_refCount );
370 {
371 // our aggregated rowset itself is not cloneable, so simply copy the properties
372 ::comphelper::copyProperties( _cloneSource.m_xAggregateSet, m_xAggregateSet );
373
374 // also care for the dynamic properties: If the clone source has properties which we do not have,
375 // then add them
376 try
377 {
378 Reference< XPropertySet > xSourceProps( const_cast< ODatabaseForm& >( _cloneSource ).queryAggregation(
379 XPropertySet::static_type() ), UNO_QUERY_THROW );
380 Reference< XPropertySetInfo > xSourcePSI( xSourceProps->getPropertySetInfo(), UNO_SET_THROW );
381 Reference< XPropertyState > xSourcePropState( xSourceProps, UNO_QUERY );
382
383 Reference< XPropertySetInfo > xDestPSI( getPropertySetInfo(), UNO_QUERY_THROW );
384
385 Sequence< Property > aSourceProperties( xSourcePSI->getProperties() );
386 for ( const Property* pSourceProperty = aSourceProperties.getConstArray();
387 pSourceProperty != aSourceProperties.getConstArray() + aSourceProperties.getLength();
388 ++pSourceProperty
389 )
390 {
391 if ( xDestPSI->hasPropertyByName( pSourceProperty->Name ) )
392 continue;
393
394 // the initial value passed to XPropertyContainer is also used as default, usually. So, try
395 // to retrieve the default of the source property
396 Any aInitialValue;
397 if ( xSourcePropState.is() )
398 {
399 aInitialValue = xSourcePropState->getPropertyDefault( pSourceProperty->Name );
400 }
401 else
402 {
403 aInitialValue = xSourceProps->getPropertyValue( pSourceProperty->Name );
404 }
405 addProperty( pSourceProperty->Name, pSourceProperty->Attributes, aInitialValue );
406 setPropertyValue( pSourceProperty->Name, xSourceProps->getPropertyValue( pSourceProperty->Name ) );
407 }
408 }
409 catch( const Exception& )
410 {
411 throw WrappedTargetException(
412 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Could not clone the given database form." ) ),
413 *const_cast< ODatabaseForm* >( &_cloneSource ),
414 ::cppu::getCaughtException()
415 );
416 }
417 }
418 osl_decrementInterlockedCount( &m_refCount );
419 }
420
421 //------------------------------------------------------------------
impl_construct()422 void ODatabaseForm::impl_construct()
423 {
424 // aggregate a row set
425 increment(m_refCount);
426 {
427 m_xAggregate = Reference< XAggregation >( m_xServiceFactory->createInstance( SRV_SDB_ROWSET ), UNO_QUERY_THROW );
428 m_xAggregateAsRowSet.set( m_xAggregate, UNO_QUERY_THROW );
429 setAggregation( m_xAggregate );
430 }
431
432 // listen for the properties, important for Parameters
433 if ( m_xAggregateSet.is() )
434 {
435 m_pAggregatePropertyMultiplexer = new OPropertyChangeMultiplexer(this, m_xAggregateSet, sal_False);
436 m_pAggregatePropertyMultiplexer->acquire();
437 m_pAggregatePropertyMultiplexer->addProperty(PROPERTY_COMMAND);
438 m_pAggregatePropertyMultiplexer->addProperty(PROPERTY_ACTIVE_CONNECTION);
439 }
440
441 {
442 Reference< XWarningsSupplier > xRowSetWarnings( m_xAggregate, UNO_QUERY );
443 m_aWarnings.setExternalWarnings( xRowSetWarnings );
444 }
445
446 if ( m_xAggregate.is() )
447 {
448 m_xAggregate->setDelegator( static_cast< XWeak* >( this ) );
449 }
450
451 {
452 m_aFilterManager.initialize( m_xAggregateSet );
453 m_aParameterManager.initialize( this, m_xAggregate );
454
455 declareForwardedProperty( PROPERTY_ID_ACTIVE_CONNECTION );
456 }
457 decrement( m_refCount );
458
459 m_pGroupManager = new OGroupManager( this );
460 m_pGroupManager->acquire();
461 }
462
463 //------------------------------------------------------------------
~ODatabaseForm()464 ODatabaseForm::~ODatabaseForm()
465 {
466 DBG_DTOR(ODatabaseForm,NULL);
467
468 m_pGroupManager->release();
469 m_pGroupManager = NULL;
470
471 if (m_xAggregate.is())
472 m_xAggregate->setDelegator( NULL );
473
474 m_aWarnings.setExternalWarnings( NULL );
475
476 if (m_pAggregatePropertyMultiplexer)
477 {
478 m_pAggregatePropertyMultiplexer->dispose();
479 m_pAggregatePropertyMultiplexer->release();
480 m_pAggregatePropertyMultiplexer = NULL;
481 }
482 }
483
484 //==============================================================================
485 // html tools
486 //------------------------------------------------------------------------
GetDataURLEncoded(const Reference<XControl> & SubmitButton,const::com::sun::star::awt::MouseEvent & MouseEvt)487 ::rtl::OUString ODatabaseForm::GetDataURLEncoded(const Reference<XControl>& SubmitButton, const ::com::sun::star::awt::MouseEvent& MouseEvt)
488 {
489 return GetDataEncoded(true,SubmitButton,MouseEvt);
490 }
491 // -----------------------------------------------------------------------------
GetDataEncoded(bool _bURLEncoded,const Reference<XControl> & SubmitButton,const::com::sun::star::awt::MouseEvent & MouseEvt)492 ::rtl::OUString ODatabaseForm::GetDataEncoded(bool _bURLEncoded,const Reference<XControl>& SubmitButton, const ::com::sun::star::awt::MouseEvent& MouseEvt)
493 {
494 // Liste von successful Controls fuellen
495 HtmlSuccessfulObjList aSuccObjList;
496 FillSuccessfulList( aSuccObjList, SubmitButton, MouseEvt );
497
498
499 // Liste zu ::rtl::OUString zusammensetzen
500 ::rtl::OUStringBuffer aResult;
501 ::rtl::OUString aName;
502 ::rtl::OUString aValue;
503
504 for ( HtmlSuccessfulObjListIterator pSuccObj = aSuccObjList.begin();
505 pSuccObj < aSuccObjList.end();
506 ++pSuccObj
507 )
508 {
509 aName = pSuccObj->aName;
510 aValue = pSuccObj->aValue;
511 if( pSuccObj->nRepresentation == SUCCESSFUL_REPRESENT_FILE && aValue.getLength() )
512 {
513 // Bei File-URLs wird der Dateiname und keine URL uebertragen,
514 // weil Netscape dies so macht.
515 INetURLObject aURL;
516 aURL.SetSmartProtocol(INET_PROT_FILE);
517 aURL.SetSmartURL(aValue);
518 if( INET_PROT_FILE == aURL.GetProtocol() )
519 aValue = INetURLObject::decode(aURL.PathToFileName(), '%', INetURLObject::DECODE_UNAMBIGUOUS);
520 }
521 Encode( aName );
522 Encode( aValue );
523
524 aResult.append(aName);
525 aResult.append(sal_Unicode('='));
526 aResult.append(aValue);
527
528 if (pSuccObj < aSuccObjList.end() - 1)
529 {
530 if ( _bURLEncoded )
531 aResult.append(sal_Unicode('&'));
532 else
533 aResult.appendAscii("\r\n");
534 }
535 }
536
537
538 aSuccObjList.clear();
539
540 return aResult.makeStringAndClear();
541 }
542
543 //==============================================================================
544 // html tools
545 //------------------------------------------------------------------------
GetDataTextEncoded(const Reference<XControl> & SubmitButton,const::com::sun::star::awt::MouseEvent & MouseEvt)546 ::rtl::OUString ODatabaseForm::GetDataTextEncoded(const Reference<XControl>& SubmitButton, const ::com::sun::star::awt::MouseEvent& MouseEvt)
547 {
548 return GetDataEncoded(false,SubmitButton,MouseEvt);
549 }
550
551 //------------------------------------------------------------------------
GetDataMultiPartEncoded(const Reference<XControl> & SubmitButton,const::com::sun::star::awt::MouseEvent & MouseEvt,::rtl::OUString & rContentType)552 Sequence<sal_Int8> ODatabaseForm::GetDataMultiPartEncoded(const Reference<XControl>& SubmitButton, const ::com::sun::star::awt::MouseEvent& MouseEvt, ::rtl::OUString& rContentType)
553 {
554
555 // Parent erzeugen
556 INetMIMEMessage aParent;
557 aParent.EnableAttachChild( INETMSG_MULTIPART_FORM_DATA );
558
559
560 // Liste von successful Controls fuellen
561 HtmlSuccessfulObjList aSuccObjList;
562 FillSuccessfulList( aSuccObjList, SubmitButton, MouseEvt );
563
564
565 // Liste zu ::rtl::OUString zusammensetzen
566 ::rtl::OUString aResult;
567 for ( HtmlSuccessfulObjListIterator pSuccObj = aSuccObjList.begin();
568 pSuccObj < aSuccObjList.end();
569 ++pSuccObj
570 )
571 {
572 if( pSuccObj->nRepresentation == SUCCESSFUL_REPRESENT_TEXT )
573 InsertTextPart( aParent, pSuccObj->aName, pSuccObj->aValue );
574 else if( pSuccObj->nRepresentation == SUCCESSFUL_REPRESENT_FILE )
575 InsertFilePart( aParent, pSuccObj->aName, pSuccObj->aValue );
576 }
577
578
579 // Liste loeschen
580 aSuccObjList.clear();
581
582 // Fuer Parent MessageStream erzeugen
583 INetMIMEMessageStream aMessStream;
584 aMessStream.SetSourceMessage( &aParent );
585 aMessStream.GenerateHeader( sal_False );
586
587 // MessageStream in SvStream kopieren
588 SvMemoryStream aMemStream;
589 char* pBuf = new char[1025];
590 int nRead;
591 while( (nRead = aMessStream.Read(pBuf, 1024)) > 0 )
592 aMemStream.Write( pBuf, nRead );
593 delete[] pBuf;
594
595 aMemStream.Flush();
596 aMemStream.Seek( 0 );
597 void* pData = (void*)aMemStream.GetData();
598 sal_Int32 nLen = aMemStream.Seek(STREAM_SEEK_TO_END);
599
600 rContentType = UniString(aParent.GetContentType());
601 return Sequence<sal_Int8>((sal_Int8*)pData, nLen);
602 }
603
604 //------------------------------------------------------------------------
605 namespace
606 {
appendDigits(sal_Int32 _nNumber,sal_Int8 nDigits,::rtl::OUStringBuffer & _rOut)607 static void appendDigits( sal_Int32 _nNumber, sal_Int8 nDigits, ::rtl::OUStringBuffer& _rOut )
608 {
609 sal_Int32 nCurLen = _rOut.getLength();
610 _rOut.append( _nNumber );
611 while ( _rOut.getLength() - nCurLen < nDigits )
612 _rOut.insert( nCurLen, (sal_Unicode)'0' );
613 }
614 }
615
616 //------------------------------------------------------------------------
AppendComponent(HtmlSuccessfulObjList & rList,const Reference<XPropertySet> & xComponentSet,const::rtl::OUString & rNamePrefix,const Reference<XControl> & rxSubmitButton,const::com::sun::star::awt::MouseEvent & MouseEvt)617 void ODatabaseForm::AppendComponent(HtmlSuccessfulObjList& rList, const Reference<XPropertySet>& xComponentSet, const ::rtl::OUString& rNamePrefix,
618 const Reference<XControl>& rxSubmitButton, const ::com::sun::star::awt::MouseEvent& MouseEvt)
619 {
620 if (!xComponentSet.is())
621 return;
622
623 // MIB 25.6.98: Geschachtelte Formulare abfangen ... oder muesste
624 // man sie submitten?
625 if (!hasProperty(PROPERTY_CLASSID, xComponentSet))
626 return;
627
628 // Namen ermitteln
629 if (!hasProperty(PROPERTY_NAME, xComponentSet))
630 return;
631
632 sal_Int16 nClassId = 0;
633 xComponentSet->getPropertyValue(PROPERTY_CLASSID) >>= nClassId;
634 ::rtl::OUString aName;
635 xComponentSet->getPropertyValue( PROPERTY_NAME ) >>= aName;
636 if( !aName.getLength() && nClassId != FormComponentType::IMAGEBUTTON)
637 return;
638 else // Name um den Prefix erweitern
639 aName = rNamePrefix + aName;
640
641 switch( nClassId )
642 {
643 // Buttons
644 case FormComponentType::COMMANDBUTTON:
645 {
646 // Es wird nur der gedrueckte Submit-Button ausgewertet
647 // MIB: Sofern ueberhaupt einer uebergeben wurde
648 if( rxSubmitButton.is() )
649 {
650 Reference<XPropertySet> xSubmitButtonComponent(rxSubmitButton->getModel(), UNO_QUERY);
651 if (xSubmitButtonComponent == xComponentSet && hasProperty(PROPERTY_LABEL, xComponentSet))
652 {
653 // <name>=<label>
654 ::rtl::OUString aLabel;
655 xComponentSet->getPropertyValue( PROPERTY_LABEL ) >>= aLabel;
656 rList.push_back( HtmlSuccessfulObj(aName, aLabel) );
657 }
658 }
659 } break;
660
661 // ImageButtons
662 case FormComponentType::IMAGEBUTTON:
663 {
664 // Es wird nur der gedrueckte Submit-Button ausgewertet
665 // MIB: Sofern ueberhaupt einer uebergeben wurde
666 if( rxSubmitButton.is() )
667 {
668 Reference<XPropertySet> xSubmitButtonComponent(rxSubmitButton->getModel(), UNO_QUERY);
669 if (xSubmitButtonComponent == xComponentSet)
670 {
671 // <name>.x=<pos.X>&<name>.y=<pos.Y>
672 ::rtl::OUString aLhs = aName;
673 ::rtl::OUString aRhs = ::rtl::OUString::valueOf( MouseEvt.X );
674
675 // nur wenn ein Name vorhanden ist, kann ein name.x
676 aLhs += aName.getLength() ? UniString::CreateFromAscii(".x") : UniString::CreateFromAscii("x");
677 rList.push_back( HtmlSuccessfulObj(aLhs, aRhs) );
678
679 aLhs = aName;
680 aRhs = ::rtl::OUString::valueOf( MouseEvt.Y );
681 aLhs += aName.getLength() ? UniString::CreateFromAscii(".y") : UniString::CreateFromAscii("y");
682 rList.push_back( HtmlSuccessfulObj(aLhs, aRhs) );
683
684 }
685 }
686 } break;
687
688 // CheckBoxen / RadioButtons
689 case FormComponentType::CHECKBOX:
690 case FormComponentType::RADIOBUTTON:
691 {
692 // <name>=<refValue>
693 if( !hasProperty(PROPERTY_STATE, xComponentSet) )
694 break;
695 sal_Int16 nChecked = 0;
696 xComponentSet->getPropertyValue( PROPERTY_STATE ) >>= nChecked;
697 if( nChecked != 1 )
698 break;
699
700 ::rtl::OUString aStrValue;
701 if( hasProperty(PROPERTY_REFVALUE, xComponentSet) )
702 xComponentSet->getPropertyValue( PROPERTY_REFVALUE ) >>= aStrValue;
703
704 rList.push_back( HtmlSuccessfulObj(aName, aStrValue) );
705 } break;
706
707 // Edit
708 case FormComponentType::TEXTFIELD:
709 {
710 // <name>=<text>
711 if( !hasProperty(PROPERTY_TEXT, xComponentSet) )
712 break;
713
714 // MIB: Spezial-Behandlung fuer Multiline-Edit nur dann, wenn
715 // es auch ein Control dazu gibt.
716 Any aTmp = xComponentSet->getPropertyValue( PROPERTY_MULTILINE );
717 sal_Bool bMulti = rxSubmitButton.is()
718 && (aTmp.getValueType().getTypeClass() == TypeClass_BOOLEAN)
719 && getBOOL(aTmp);
720 ::rtl::OUString sText;
721 if ( bMulti ) // Bei MultiLineEdit Text am Control abholen
722 {
723
724 Reference<XControlContainer> xControlContainer(rxSubmitButton->getContext(), UNO_QUERY);
725 if( !xControlContainer.is() ) break;
726
727 Sequence<Reference<XControl> > aControlSeq = xControlContainer->getControls();
728 Reference<XControl> xControl;
729 Reference<XFormComponent> xControlComponent;
730
731 // Richtiges Control suchen
732 sal_Int32 i;
733 for( i=0; i<aControlSeq.getLength(); i++ )
734 {
735 xControl = aControlSeq.getConstArray()[i];
736 Reference<XPropertySet> xModel(xControl->getModel(), UNO_QUERY);
737 if (xModel == xComponentSet)
738 {
739 Reference<XTextComponent> xTextComponent(xControl, UNO_QUERY);
740 if( xTextComponent.is() )
741 sText = xTextComponent->getText();
742 break;
743 }
744 }
745 // Control nicht gefunden oder nicht existent, (Edit im Grid)
746 if (i == aControlSeq.getLength())
747 xComponentSet->getPropertyValue( PROPERTY_TEXT ) >>= sText;
748 }
749 else
750 xComponentSet->getPropertyValue( PROPERTY_TEXT ) >>= sText;
751
752 rList.push_back( HtmlSuccessfulObj(aName, sText) );
753 } break;
754
755 // ComboBox, Patternfield
756 case FormComponentType::COMBOBOX:
757 case FormComponentType::PATTERNFIELD:
758 {
759 // <name>=<text>
760 if( hasProperty(PROPERTY_TEXT, xComponentSet) )
761 {
762 ::rtl::OUString aText;
763 xComponentSet->getPropertyValue( PROPERTY_TEXT ) >>= aText;
764 rList.push_back( HtmlSuccessfulObj(aName, aText) );
765 }
766 } break;
767 case FormComponentType::CURRENCYFIELD:
768 case FormComponentType::NUMERICFIELD:
769 {
770 // <name>=<wert> // wert wird als double mit Punkt als Decimaltrenner
771 // kein Wert angegeben (NULL) -> wert leer
772 if( hasProperty(PROPERTY_VALUE, xComponentSet) )
773 {
774 ::rtl::OUString aText;
775 Any aVal = xComponentSet->getPropertyValue( PROPERTY_VALUE );
776
777 double aDoubleVal = 0;
778 if (aVal >>= aDoubleVal)
779 {
780 sal_Int16 nScale = 0;
781 xComponentSet->getPropertyValue( PROPERTY_DECIMAL_ACCURACY ) >>= nScale;
782 aText = ::rtl::math::doubleToUString(aDoubleVal, rtl_math_StringFormat_F, nScale, '.', sal_True);
783 }
784 rList.push_back( HtmlSuccessfulObj(aName, aText) );
785 }
786 } break;
787 case FormComponentType::DATEFIELD:
788 {
789 // <name>=<wert> // Wert wird als Datum im Format (MM-DD-YYYY)
790 // kein Wert angegeben (NULL) -> wert leer
791 if( hasProperty(PROPERTY_DATE, xComponentSet) )
792 {
793 ::rtl::OUString aText;
794 Any aVal = xComponentSet->getPropertyValue( PROPERTY_DATE );
795 sal_Int32 nInt32Val = 0;
796 if (aVal >>= nInt32Val)
797 {
798 ::Date aDate( nInt32Val );
799 ::rtl::OUStringBuffer aBuffer;
800 appendDigits( aDate.GetMonth(), 2, aBuffer );
801 aBuffer.append( (sal_Unicode)'-' );
802 appendDigits( aDate.GetDay(), 2, aBuffer );
803 aBuffer.append( (sal_Unicode)'-' );
804 appendDigits( aDate.GetYear(), 4, aBuffer );
805 aText = aBuffer.makeStringAndClear();
806 }
807 rList.push_back( HtmlSuccessfulObj(aName, aText) );
808 }
809 } break;
810 case FormComponentType::TIMEFIELD:
811 {
812 // <name>=<wert> // Wert wird als Zeit im Format (HH:MM:SS) angegeben
813 // kein Wert angegeben (NULL) -> wert leer
814 if( hasProperty(PROPERTY_TIME, xComponentSet) )
815 {
816 ::rtl::OUString aText;
817 Any aVal = xComponentSet->getPropertyValue( PROPERTY_TIME );
818 sal_Int32 nInt32Val = 0;
819 if (aVal >>= nInt32Val)
820 {
821 ::Time aTime(nInt32Val);
822 ::rtl::OUStringBuffer aBuffer;
823 appendDigits( aTime.GetHour(), 2, aBuffer );
824 aBuffer.append( (sal_Unicode)'-' );
825 appendDigits( aTime.GetMin(), 2, aBuffer );
826 aBuffer.append( (sal_Unicode)'-' );
827 appendDigits( aTime.GetSec(), 2, aBuffer );
828 aText = aBuffer.makeStringAndClear();
829 }
830 rList.push_back( HtmlSuccessfulObj(aName, aText) );
831 }
832 } break;
833
834 // starform
835 case FormComponentType::HIDDENCONTROL:
836 {
837
838 // <name>=<value>
839 if( hasProperty(PROPERTY_HIDDEN_VALUE, xComponentSet) )
840 {
841 ::rtl::OUString aText;
842 xComponentSet->getPropertyValue( PROPERTY_HIDDEN_VALUE ) >>= aText;
843 rList.push_back( HtmlSuccessfulObj(aName, aText) );
844 }
845 } break;
846
847 // starform
848 case FormComponentType::FILECONTROL:
849 {
850 // <name>=<text>
851 if( hasProperty(PROPERTY_TEXT, xComponentSet) )
852 {
853
854 ::rtl::OUString aText;
855 xComponentSet->getPropertyValue( PROPERTY_TEXT ) >>= aText;
856 rList.push_back( HtmlSuccessfulObj(aName, aText, SUCCESSFUL_REPRESENT_FILE) );
857 }
858 } break;
859
860 // starform
861 case FormComponentType::LISTBOX:
862 {
863
864 // <name>=<Token0>&<name>=<Token1>&...&<name>=<TokenN> (Mehrfachselektion)
865 if (!hasProperty(PROPERTY_SELECT_SEQ, xComponentSet) ||
866 !hasProperty(PROPERTY_STRINGITEMLIST, xComponentSet))
867 break;
868
869 // angezeigte Werte
870 Sequence< ::rtl::OUString > aVisibleList;
871 xComponentSet->getPropertyValue( PROPERTY_STRINGITEMLIST ) >>= aVisibleList;
872 sal_Int32 nStringCnt = aVisibleList.getLength();
873 const ::rtl::OUString* pStrings = aVisibleList.getConstArray();
874
875 // Werte-Liste
876 Sequence< ::rtl::OUString > aValueList;
877 xComponentSet->getPropertyValue( PROPERTY_VALUE_SEQ ) >>= aValueList;
878 sal_Int32 nValCnt = aValueList.getLength();
879 const ::rtl::OUString* pVals = aValueList.getConstArray();
880
881 // Selektion
882 Sequence<sal_Int16> aSelectList;
883 xComponentSet->getPropertyValue( PROPERTY_SELECT_SEQ ) >>= aSelectList;
884 sal_Int32 nSelCount = aSelectList.getLength();
885 const sal_Int16* pSels = aSelectList.getConstArray();
886
887 // Einfach- oder Mehrfach-Selektion
888 // Bei Einfach-Selektionen beruecksichtigt MT nur den ersten Eintrag
889 // in der Liste.
890 if (nSelCount > 1 && !getBOOL(xComponentSet->getPropertyValue(PROPERTY_MULTISELECTION)))
891 nSelCount = 1;
892
893 // Die Indizes in der Selektions-Liste koennen auch ungueltig sein,
894 // also muss man die gueltigen erstmal raussuchen um die Laenge
895 // der neuen Liste zu bestimmen.
896 sal_Int32 nCurCnt = 0;
897 sal_Int32 i;
898 for( i=0; i<nSelCount; ++i )
899 {
900 if( pSels[i] < nStringCnt )
901 ++nCurCnt;
902 }
903
904 ::rtl::OUString aSubValue;
905 for(i=0; i<nCurCnt; ++i )
906 {
907 sal_Int16 nSelPos = pSels[i];
908 if (nSelPos < nValCnt && pVals[nSelPos].getLength())
909 {
910 aSubValue = pVals[nSelPos];
911 }
912 else
913 {
914 aSubValue = pStrings[nSelPos];
915 }
916 rList.push_back( HtmlSuccessfulObj(aName, aSubValue) );
917 }
918 } break;
919 case FormComponentType::GRIDCONTROL:
920 {
921 // Die einzelnen Spaltenwerte werden verschickt,
922 // der Name wird mit dem Prefix des Names des Grids erweitert
923 Reference<XIndexAccess> xContainer(xComponentSet, UNO_QUERY);
924 if (!xContainer.is())
925 break;
926
927 aName += UniString('.');
928
929 Reference<XPropertySet> xSet;
930 sal_Int32 nCount = xContainer->getCount();
931 // we know already how many objects should be appended,
932 // so why not allocate the space for them
933 rList.reserve( nCount + rList.capacity() ); // not size()
934 for (sal_Int32 i = 0; i < nCount; ++i)
935 {
936 xContainer->getByIndex(i) >>= xSet;
937 if (xSet.is())
938 AppendComponent(rList, xSet, aName, rxSubmitButton, MouseEvt);
939 }
940 }
941 }
942 }
943
944 //------------------------------------------------------------------------
FillSuccessfulList(HtmlSuccessfulObjList & rList,const Reference<XControl> & rxSubmitButton,const::com::sun::star::awt::MouseEvent & MouseEvt)945 void ODatabaseForm::FillSuccessfulList( HtmlSuccessfulObjList& rList,
946 const Reference<XControl>& rxSubmitButton, const ::com::sun::star::awt::MouseEvent& MouseEvt )
947 {
948 // Liste loeschen
949 rList.clear();
950 // Ueber Components iterieren
951 Reference<XPropertySet> xComponentSet;
952 ::rtl::OUString aPrefix;
953
954 // we know already how many objects should be appended,
955 // so why not allocate the space for them
956 rList.reserve( getCount() );
957 for( sal_Int32 nIndex=0; nIndex < getCount(); nIndex++ )
958 {
959 getByIndex( nIndex ) >>= xComponentSet;
960 AppendComponent(rList, xComponentSet, aPrefix, rxSubmitButton, MouseEvt);
961 }
962 }
963
964 //------------------------------------------------------------------------
Encode(::rtl::OUString & rString) const965 void ODatabaseForm::Encode( ::rtl::OUString& rString ) const
966 {
967 ::rtl::OUString aResult;
968
969 // Immer ANSI #58641
970 // rString.Convert(CHARSET_SYSTEM, CHARSET_ANSI);
971
972
973 // Zeilenendezeichen werden als CR dargestellt
974 UniString sConverter = rString;
975 sConverter.ConvertLineEnd( LINEEND_CR );
976 rString = sConverter;
977
978
979 // Jeden einzelnen Character ueberpruefen
980 sal_Int32 nStrLen = rString.getLength();
981 sal_Unicode nCharCode;
982 for( sal_Int32 nCurPos=0; nCurPos < nStrLen; ++nCurPos )
983 {
984 nCharCode = rString[nCurPos];
985
986 // Behandlung fuer chars, die kein alphanumerisches Zeichen sind
987 // und CharacterCodes > 127
988 if( (!isalnum(nCharCode) && nCharCode != (sal_Unicode)' ') || nCharCode > 127 )
989 {
990 switch( nCharCode )
991 {
992 case 13: // CR
993 aResult += ::rtl::OUString::createFromAscii("%0D%0A"); // Hex-Darstellung CR LF
994 break;
995
996
997 // Netscape Sonderbehandlung
998 case 42: // '*'
999 case 45: // '-'
1000 case 46: // '.'
1001 case 64: // '@'
1002 case 95: // '_'
1003 aResult += UniString(nCharCode);
1004 break;
1005
1006 default:
1007 {
1008 // In Hex umrechnen
1009 short nHi = ((sal_Int16)nCharCode) / 16;
1010 short nLo = ((sal_Int16)nCharCode) - (nHi*16);
1011 if( nHi > 9 ) nHi += (int)'A'-10; else nHi += (int)'0';
1012 if( nLo > 9 ) nLo += (int)'A'-10; else nLo += (int)'0';
1013 aResult += UniString('%');
1014 aResult += UniString((sal_Unicode)nHi);
1015 aResult += UniString((sal_Unicode)nLo);
1016 }
1017 }
1018 }
1019 else
1020 aResult += UniString(nCharCode);
1021 }
1022
1023
1024 // Spaces durch '+' ersetzen
1025 aResult = aResult.replace(' ', '+');
1026
1027 rString = aResult;
1028 }
1029
1030 //------------------------------------------------------------------------
InsertTextPart(INetMIMEMessage & rParent,const::rtl::OUString & rName,const::rtl::OUString & rData)1031 void ODatabaseForm::InsertTextPart( INetMIMEMessage& rParent, const ::rtl::OUString& rName,
1032 const ::rtl::OUString& rData )
1033 {
1034
1035 // Part als Message-Child erzeugen
1036 INetMIMEMessage* pChild = new INetMIMEMessage();
1037
1038
1039 // Header
1040 ::rtl::OUString aContentDisp = ::rtl::OUString::createFromAscii("form-data; name=\"");
1041 aContentDisp += rName;
1042 aContentDisp += UniString('\"');
1043 pChild->SetContentDisposition( aContentDisp );
1044 pChild->SetContentType( UniString::CreateFromAscii("text/plain") );
1045
1046 rtl_TextEncoding eSystemEncoding = gsl_getSystemTextEncoding();
1047 const sal_Char* pBestMatchingEncoding = rtl_getBestMimeCharsetFromTextEncoding( eSystemEncoding );
1048 UniString aBestMatchingEncoding = UniString::CreateFromAscii( pBestMatchingEncoding );
1049 pChild->SetContentTransferEncoding(aBestMatchingEncoding);
1050
1051 // Body
1052 SvMemoryStream* pStream = new SvMemoryStream;
1053 pStream->WriteLine( ByteString( UniString(rData), rtl_getTextEncodingFromMimeCharset(pBestMatchingEncoding) ) );
1054 pStream->Flush();
1055 pStream->Seek( 0 );
1056 pChild->SetDocumentLB( new SvLockBytes(pStream, sal_True) );
1057 rParent.AttachChild( *pChild );
1058 }
1059
1060 //------------------------------------------------------------------------
InsertFilePart(INetMIMEMessage & rParent,const::rtl::OUString & rName,const::rtl::OUString & rFileName)1061 sal_Bool ODatabaseForm::InsertFilePart( INetMIMEMessage& rParent, const ::rtl::OUString& rName,
1062 const ::rtl::OUString& rFileName )
1063 {
1064 UniString aFileName( rFileName );
1065 UniString aContentType(UniString::CreateFromAscii(CONTENT_TYPE_STR_TEXT_PLAIN));
1066 SvStream *pStream = 0;
1067
1068 if( aFileName.Len() )
1069 {
1070 // Bisher koennen wir nur File-URLs verarbeiten
1071 INetURLObject aURL;
1072 aURL.SetSmartProtocol(INET_PROT_FILE);
1073 aURL.SetSmartURL(rFileName);
1074 if( INET_PROT_FILE == aURL.GetProtocol() )
1075 {
1076 aFileName = INetURLObject::decode(aURL.PathToFileName(), '%', INetURLObject::DECODE_UNAMBIGUOUS);
1077 DirEntry aDirEntry( aFileName );
1078 if( aDirEntry.Exists() )
1079 {
1080 pStream = ::utl::UcbStreamHelper::CreateStream(aFileName, STREAM_READ);
1081 if (!pStream || (pStream->GetError() != ERRCODE_NONE))
1082 {
1083 delete pStream;
1084 pStream = 0;
1085 }
1086 }
1087 INetContentType eContentType = INetContentTypes::GetContentType4Extension(
1088 aDirEntry.GetExtension() );
1089 if (eContentType != CONTENT_TYPE_UNKNOWN)
1090 aContentType = INetContentTypes::GetContentType(eContentType);
1091 }
1092 }
1093
1094 // Wenn irgendetwas nicht geklappt hat, legen wir einen leeren
1095 // MemoryStream an
1096 if( !pStream )
1097 pStream = new SvMemoryStream;
1098
1099
1100 // Part als Message-Child erzeugen
1101 INetMIMEMessage* pChild = new INetMIMEMessage;
1102
1103
1104 // Header
1105 ::rtl::OUString aContentDisp = ::rtl::OUString::createFromAscii( "form-data; name=\"" );
1106 aContentDisp += rName;
1107 aContentDisp += UniString('\"');
1108 aContentDisp += ::rtl::OUString::createFromAscii("; filename=\"");
1109 aContentDisp += aFileName;
1110 aContentDisp += UniString('\"');
1111 pChild->SetContentDisposition( aContentDisp );
1112 pChild->SetContentType( aContentType );
1113 pChild->SetContentTransferEncoding( UniString(::rtl::OUString::createFromAscii("8bit")) );
1114
1115
1116 // Body
1117 pChild->SetDocumentLB( new SvLockBytes(pStream, sal_True) );
1118 rParent.AttachChild( *pChild );
1119
1120 return sal_True;
1121 }
1122
1123 //==============================================================================
1124 // internals
1125 //------------------------------------------------------------------------------
onError(const SQLErrorEvent & _rEvent)1126 void ODatabaseForm::onError( const SQLErrorEvent& _rEvent )
1127 {
1128 m_aErrorListeners.notifyEach( &XSQLErrorListener::errorOccured, _rEvent );
1129 }
1130
1131 //------------------------------------------------------------------------------
onError(const SQLException & _rException,const::rtl::OUString & _rContextDescription)1132 void ODatabaseForm::onError( const SQLException& _rException, const ::rtl::OUString& _rContextDescription )
1133 {
1134 if ( !m_aErrorListeners.getLength() )
1135 return;
1136
1137 SQLErrorEvent aEvent( *this, makeAny( prependErrorInfo( _rException, *this, _rContextDescription ) ) );
1138 onError( aEvent );
1139 }
1140
1141 //------------------------------------------------------------------------------
updateParameterInfo()1142 void ODatabaseForm::updateParameterInfo()
1143 {
1144 m_aParameterManager.updateParameterInfo( m_aFilterManager );
1145 }
1146
1147 //------------------------------------------------------------------------------
hasValidParent() const1148 bool ODatabaseForm::hasValidParent() const
1149 {
1150 // do we have to fill the parameters again?
1151 if (m_bSubForm)
1152 {
1153 Reference<XResultSet> xResultSet(m_xParent, UNO_QUERY);
1154 if (!xResultSet.is())
1155 {
1156 DBG_ERROR("ODatabaseForm::hasValidParent() : no parent resultset !");
1157 return false;
1158 }
1159 try
1160 {
1161 Reference< XPropertySet > xSet( m_xParent, UNO_QUERY );
1162 Reference< XLoadable > xLoad( m_xParent, UNO_QUERY );
1163 if ( xLoad->isLoaded()
1164 && ( xResultSet->isBeforeFirst()
1165 || xResultSet->isAfterLast()
1166 || getBOOL( xSet->getPropertyValue( PROPERTY_ISNEW ) )
1167 )
1168 )
1169 // the parent form is loaded and on a "virtual" row -> not valid
1170 return false;
1171 }
1172 catch(Exception&)
1173 {
1174 // parent could be forwardonly?
1175 return false;
1176 }
1177 }
1178 return true;
1179 }
1180
1181 //------------------------------------------------------------------------------
fillParameters(::osl::ResettableMutexGuard & _rClearForNotifies,const Reference<XInteractionHandler> & _rxCompletionHandler)1182 bool ODatabaseForm::fillParameters( ::osl::ResettableMutexGuard& _rClearForNotifies, const Reference< XInteractionHandler >& _rxCompletionHandler )
1183 {
1184 // do we have to fill the parameters again?
1185 if ( !m_aParameterManager.isUpToDate() )
1186 updateParameterInfo();
1187
1188 // is there a valid parent?
1189 if ( m_bSubForm && !hasValidParent() )
1190 return true;
1191
1192 // ensure we're connected
1193 if ( !implEnsureConnection() )
1194 return false;
1195
1196 if ( m_aParameterManager.isUpToDate() )
1197 return m_aParameterManager.fillParameterValues( _rxCompletionHandler, _rClearForNotifies );
1198
1199 return true;
1200 }
1201
1202 //------------------------------------------------------------------------------
saveInsertOnlyState()1203 void ODatabaseForm::saveInsertOnlyState( )
1204 {
1205 OSL_ENSURE( !m_aIgnoreResult.hasValue(), "ODatabaseForm::saveInsertOnlyState: overriding old value!" );
1206 m_aIgnoreResult = m_xAggregateSet->getPropertyValue( PROPERTY_INSERTONLY );
1207 }
1208
1209 //------------------------------------------------------------------------------
restoreInsertOnlyState()1210 void ODatabaseForm::restoreInsertOnlyState( )
1211 {
1212 if ( m_aIgnoreResult.hasValue() )
1213 {
1214 m_xAggregateSet->setPropertyValue( PROPERTY_INSERTONLY, m_aIgnoreResult );
1215 m_aIgnoreResult = Any();
1216 }
1217 }
1218
1219 //------------------------------------------------------------------------------
executeRowSet(::osl::ResettableMutexGuard & _rClearForNotifies,sal_Bool bMoveToFirst,const Reference<XInteractionHandler> & _rxCompletionHandler)1220 sal_Bool ODatabaseForm::executeRowSet(::osl::ResettableMutexGuard& _rClearForNotifies, sal_Bool bMoveToFirst, const Reference< XInteractionHandler >& _rxCompletionHandler)
1221 {
1222 if (!m_xAggregateAsRowSet.is())
1223 return sal_False;
1224
1225 if (!fillParameters(_rClearForNotifies, _rxCompletionHandler))
1226 return sal_False;
1227
1228 restoreInsertOnlyState( );
1229
1230 // ensure the aggregated row set has the correct properties
1231 sal_Int32 nConcurrency = ResultSetConcurrency::READ_ONLY;
1232
1233 // if we have a parent, who is not positioned on a valid row
1234 // we can't be updatable!
1235 if (m_bSubForm && !hasValidParent())
1236 {
1237 nConcurrency = ResultSetConcurrency::READ_ONLY;
1238
1239 // don't use any parameters if we don't have a valid parent
1240 m_aParameterManager.setAllParametersNull();
1241
1242 // switch to "insert only" mode
1243 saveInsertOnlyState( );
1244 m_xAggregateSet->setPropertyValue( PROPERTY_INSERTONLY, makeAny( sal_True ) );
1245 }
1246 else if (m_bAllowInsert || m_bAllowUpdate || m_bAllowDelete)
1247 nConcurrency = ResultSetConcurrency::UPDATABLE;
1248 else
1249 nConcurrency = ResultSetConcurrency::READ_ONLY;
1250
1251 m_xAggregateSet->setPropertyValue( PROPERTY_RESULTSET_CONCURRENCY, makeAny( (sal_Int32)nConcurrency ) );
1252 m_xAggregateSet->setPropertyValue( PROPERTY_RESULTSET_TYPE, makeAny( (sal_Int32)ResultSetType::SCROLL_SENSITIVE ) );
1253
1254 sal_Bool bSuccess = sal_False;
1255 try
1256 {
1257 m_xAggregateAsRowSet->execute();
1258 bSuccess = sal_True;
1259 }
1260 catch( const RowSetVetoException& eVeto )
1261 {
1262 (void)eVeto;
1263 }
1264 catch(SQLException& eDb)
1265 {
1266 _rClearForNotifies.clear();
1267 if (m_sCurrentErrorContext.getLength())
1268 onError(eDb, m_sCurrentErrorContext);
1269 else
1270 onError(eDb, FRM_RES_STRING(RID_STR_READERROR));
1271 _rClearForNotifies.reset();
1272
1273 restoreInsertOnlyState( );
1274 }
1275
1276 if (bSuccess)
1277 {
1278 // adjust the privilege property
1279 // m_nPrivileges;
1280 m_xAggregateSet->getPropertyValue(PROPERTY_PRIVILEGES) >>= m_nPrivileges;
1281 if (!m_bAllowInsert)
1282 m_nPrivileges &= ~Privilege::INSERT;
1283 if (!m_bAllowUpdate)
1284 m_nPrivileges &= ~Privilege::UPDATE;
1285 if (!m_bAllowDelete)
1286 m_nPrivileges &= ~Privilege::DELETE;
1287
1288 if (bMoveToFirst)
1289 {
1290 // the row set is positioned _before_ the first row (per definitionem), so move the set ...
1291 try
1292 {
1293 // if we have an insert only rowset we move to the insert row
1294 next();
1295 if (((m_nPrivileges & Privilege::INSERT) == Privilege::INSERT)
1296 && isAfterLast())
1297 {
1298 // move on the insert row of set
1299 // resetting must be done later, after the load events have been posted
1300 // see :moveToInsertRow and load , reload
1301 Reference<XResultSetUpdate> xUpdate;
1302 if (query_aggregation( m_xAggregate, xUpdate))
1303 xUpdate->moveToInsertRow();
1304 }
1305 }
1306 catch(SQLException& eDB)
1307 {
1308 _rClearForNotifies.clear();
1309 if (m_sCurrentErrorContext.getLength())
1310 onError(eDB, m_sCurrentErrorContext);
1311 else
1312 onError(eDB, FRM_RES_STRING(RID_STR_READERROR));
1313 _rClearForNotifies.reset();
1314 bSuccess = sal_False;
1315 }
1316 }
1317 }
1318 return bSuccess;
1319 }
1320
1321 //------------------------------------------------------------------
disposing()1322 void ODatabaseForm::disposing()
1323 {
1324 if (m_pAggregatePropertyMultiplexer)
1325 m_pAggregatePropertyMultiplexer->dispose();
1326
1327 if (m_bLoaded)
1328 unload();
1329
1330 // cancel the submit/reset-thread
1331 {
1332 ::osl::MutexGuard aGuard( m_aMutex );
1333 if (m_pThread)
1334 {
1335 m_pThread->release();
1336 m_pThread = NULL;
1337 }
1338 }
1339
1340 EventObject aEvt(static_cast<XWeak*>(this));
1341 m_aLoadListeners.disposeAndClear(aEvt);
1342 m_aRowSetApproveListeners.disposeAndClear(aEvt);
1343 m_aParameterManager.disposing( aEvt );
1344 m_aResetListeners.disposing();
1345 m_aSubmitListeners.disposeAndClear(aEvt);
1346 m_aErrorListeners.disposeAndClear(aEvt);
1347
1348 m_aParameterManager.dispose(); // (to free any references it may have to me)
1349 m_aFilterManager.dispose(); // (dito)
1350
1351 OFormComponents::disposing();
1352 OPropertySetAggregationHelper::disposing();
1353
1354 // stop listening on the aggregate
1355 if (m_xAggregateAsRowSet.is())
1356 m_xAggregateAsRowSet->removeRowSetListener(this);
1357
1358 // dispose the active connection
1359 Reference<XComponent> xAggregationComponent;
1360 if (query_aggregation(m_xAggregate, xAggregationComponent))
1361 xAggregationComponent->dispose();
1362
1363 m_aPropertyBagHelper.dispose();
1364 }
1365
1366 //------------------------------------------------------------------------------
getConnection()1367 Reference< XConnection > ODatabaseForm::getConnection()
1368 {
1369 Reference< XConnection > xConn;
1370 m_xAggregateSet->getPropertyValue( PROPERTY_ACTIVE_CONNECTION ) >>= xConn;
1371 return xConn;
1372 }
1373
1374 //------------------------------------------------------------------------------
getMutex()1375 ::osl::Mutex& ODatabaseForm::getMutex()
1376 {
1377 return m_aMutex;
1378 }
1379
1380 //==============================================================================
1381 // property handling
1382 //------------------------------------------------------------------------------
describeFixedAndAggregateProperties(Sequence<Property> & _rProps,Sequence<Property> & _rAggregateProps) const1383 void ODatabaseForm::describeFixedAndAggregateProperties(
1384 Sequence< Property >& _rProps,
1385 Sequence< Property >& _rAggregateProps ) const
1386 {
1387 BEGIN_DESCRIBE_AGGREGATION_PROPERTIES(22, m_xAggregateSet)
1388 // we want to "override" the privileges, since we have additional "AllowInsert" etc. properties
1389 RemoveProperty( _rAggregateProps, PROPERTY_PRIVILEGES );
1390
1391 // InsertOnly is also to be overridden, since we sometimes change it ourself
1392 RemoveProperty( _rAggregateProps, PROPERTY_INSERTONLY );
1393
1394 // we remove and re-declare the DataSourceName property, 'cause we want it to be constrained, and the
1395 // original property of our aggregate isn't
1396 RemoveProperty( _rAggregateProps, PROPERTY_DATASOURCE );
1397
1398 // for connection sharing, we need to override the ActiveConnection property, too
1399 RemoveProperty( _rAggregateProps, PROPERTY_ACTIVE_CONNECTION );
1400
1401 // the Filter property is also overwritten, since we have some implicit filters
1402 // (e.g. the ones which result from linking master fields to detail fields
1403 // via column names instead of parameters)
1404 RemoveProperty( _rAggregateProps, PROPERTY_FILTER );
1405 RemoveProperty( _rAggregateProps, PROPERTY_APPLYFILTER );
1406
1407 DECL_IFACE_PROP4(ACTIVE_CONNECTION, XConnection, BOUND, TRANSIENT, MAYBEVOID, CONSTRAINED);
1408 DECL_BOOL_PROP2 ( APPLYFILTER, BOUND, MAYBEDEFAULT );
1409 DECL_PROP1 ( NAME, ::rtl::OUString, BOUND );
1410 DECL_PROP1 ( MASTERFIELDS, Sequence< ::rtl::OUString >, BOUND );
1411 DECL_PROP1 ( DETAILFIELDS, Sequence< ::rtl::OUString >, BOUND );
1412 DECL_PROP2 ( DATASOURCE, ::rtl::OUString, BOUND, CONSTRAINED );
1413 DECL_PROP3 ( CYCLE, TabulatorCycle, BOUND, MAYBEVOID, MAYBEDEFAULT );
1414 DECL_PROP2 ( FILTER, ::rtl::OUString, BOUND, MAYBEDEFAULT );
1415 DECL_BOOL_PROP2 ( INSERTONLY, BOUND, MAYBEDEFAULT );
1416 DECL_PROP1 ( NAVIGATION, NavigationBarMode, BOUND );
1417 DECL_BOOL_PROP1 ( ALLOWADDITIONS, BOUND );
1418 DECL_BOOL_PROP1 ( ALLOWEDITS, BOUND );
1419 DECL_BOOL_PROP1 ( ALLOWDELETIONS, BOUND );
1420 DECL_PROP2 ( PRIVILEGES, sal_Int32, TRANSIENT, READONLY );
1421 DECL_PROP1 ( TARGET_URL, ::rtl::OUString, BOUND );
1422 DECL_PROP1 ( TARGET_FRAME, ::rtl::OUString, BOUND );
1423 DECL_PROP1 ( SUBMIT_METHOD, FormSubmitMethod, BOUND );
1424 DECL_PROP1 ( SUBMIT_ENCODING, FormSubmitEncoding, BOUND );
1425 DECL_BOOL_PROP3 ( DYNAMIC_CONTROL_BORDER, BOUND, MAYBEVOID, MAYBEDEFAULT );
1426 DECL_PROP3 ( CONTROL_BORDER_COLOR_FOCUS, sal_Int32, BOUND, MAYBEVOID, MAYBEDEFAULT );
1427 DECL_PROP3 ( CONTROL_BORDER_COLOR_MOUSE, sal_Int32, BOUND, MAYBEVOID, MAYBEDEFAULT );
1428 DECL_PROP3 ( CONTROL_BORDER_COLOR_INVALID, sal_Int32, BOUND, MAYBEVOID, MAYBEDEFAULT );
1429 END_DESCRIBE_PROPERTIES();
1430 }
1431
1432 //------------------------------------------------------------------------------
getPropertiesInterface()1433 Reference< XMultiPropertySet > ODatabaseForm::getPropertiesInterface()
1434 {
1435 return Reference< XMultiPropertySet >( *this, UNO_QUERY );
1436 }
1437
1438 //------------------------------------------------------------------------------
getInfoHelper()1439 ::cppu::IPropertyArrayHelper& ODatabaseForm::getInfoHelper()
1440 {
1441 return m_aPropertyBagHelper.getInfoHelper();
1442 }
1443
1444 //------------------------------------------------------------------------------
getPropertySetInfo()1445 Reference< XPropertySetInfo > ODatabaseForm::getPropertySetInfo() throw( RuntimeException )
1446 {
1447 return createPropertySetInfo( getInfoHelper() );
1448 }
1449
1450 //--------------------------------------------------------------------
addProperty(const::rtl::OUString & _rName,::sal_Int16 _nAttributes,const Any & _rInitialValue)1451 void SAL_CALL ODatabaseForm::addProperty( const ::rtl::OUString& _rName, ::sal_Int16 _nAttributes, const Any& _rInitialValue ) throw (PropertyExistException, IllegalTypeException, IllegalArgumentException, RuntimeException)
1452 {
1453 m_aPropertyBagHelper.addProperty( _rName, _nAttributes, _rInitialValue );
1454 }
1455
1456 //--------------------------------------------------------------------
removeProperty(const::rtl::OUString & _rName)1457 void SAL_CALL ODatabaseForm::removeProperty( const ::rtl::OUString& _rName ) throw (UnknownPropertyException, NotRemoveableException, RuntimeException)
1458 {
1459 m_aPropertyBagHelper.removeProperty( _rName );
1460 }
1461
1462 //--------------------------------------------------------------------
getPropertyValues()1463 Sequence< PropertyValue > SAL_CALL ODatabaseForm::getPropertyValues() throw (RuntimeException)
1464 {
1465 return m_aPropertyBagHelper.getPropertyValues();
1466 }
1467
1468 //--------------------------------------------------------------------
setPropertyValues(const Sequence<PropertyValue> & _rProps)1469 void SAL_CALL ODatabaseForm::setPropertyValues( const Sequence< PropertyValue >& _rProps ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
1470 {
1471 m_aPropertyBagHelper.setPropertyValues( _rProps );
1472 }
1473
1474 //------------------------------------------------------------------------------
getWarnings()1475 Any SAL_CALL ODatabaseForm::getWarnings( ) throw (SQLException, RuntimeException)
1476 {
1477 return m_aWarnings.getWarnings();
1478 }
1479
1480 //------------------------------------------------------------------------------
clearWarnings()1481 void SAL_CALL ODatabaseForm::clearWarnings( ) throw (SQLException, RuntimeException)
1482 {
1483 m_aWarnings.clearWarnings();
1484 }
1485
1486 //------------------------------------------------------------------------------
createClone()1487 Reference< XCloneable > SAL_CALL ODatabaseForm::createClone( ) throw (RuntimeException)
1488 {
1489 ODatabaseForm* pClone = new ODatabaseForm( *this );
1490 osl_incrementInterlockedCount( &pClone->m_refCount );
1491 pClone->clonedFrom( *this );
1492 osl_decrementInterlockedCount( &pClone->m_refCount );
1493 return pClone;
1494 }
1495
1496 //------------------------------------------------------------------------------
fire(sal_Int32 * pnHandles,const Any * pNewValues,const Any * pOldValues,sal_Int32 nCount,sal_Bool bVetoable)1497 void ODatabaseForm::fire( sal_Int32* pnHandles, const Any* pNewValues, const Any* pOldValues, sal_Int32 nCount, sal_Bool bVetoable )
1498 {
1499 // same as in getFastPropertyValue(sal_Int32) : if we're resetting currently don't fire any changes of the
1500 // IsModified property from sal_False to sal_True, as this is only temporary 'til the reset is done
1501 if (m_nResetsPending > 0)
1502 {
1503 // look for the PROPERTY_ID_ISMODIFIED
1504 sal_Int32 nPos = 0;
1505 for (nPos=0; nPos<nCount; ++nPos)
1506 if (pnHandles[nPos] == PROPERTY_ID_ISMODIFIED)
1507 break;
1508
1509 if ((nPos < nCount) && (pNewValues[nPos].getValueType().getTypeClass() == TypeClass_BOOLEAN) && getBOOL(pNewValues[nPos]))
1510 { // yeah, we found it, and it changed to TRUE
1511 if (nPos == 0)
1512 { // just cut the first element
1513 ++pnHandles;
1514 ++pNewValues;
1515 ++pOldValues;
1516 --nCount;
1517 }
1518 else if (nPos == nCount - 1)
1519 // just cut the last element
1520 --nCount;
1521 else
1522 { // split into two base class calls
1523 OPropertySetAggregationHelper::fire(pnHandles, pNewValues, pOldValues, nPos, bVetoable);
1524 ++nPos;
1525 OPropertySetAggregationHelper::fire(pnHandles + nPos, pNewValues + nPos, pOldValues + nPos, nCount - nPos, bVetoable);
1526 return;
1527 }
1528 }
1529 }
1530
1531 OPropertySetAggregationHelper::fire(pnHandles, pNewValues, pOldValues, nCount, bVetoable);
1532 }
1533
1534 //------------------------------------------------------------------------------
getFastPropertyValue(sal_Int32 nHandle)1535 Any SAL_CALL ODatabaseForm::getFastPropertyValue( sal_Int32 nHandle )
1536 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1537 {
1538 if ((nHandle == PROPERTY_ID_ISMODIFIED) && (m_nResetsPending > 0))
1539 return ::cppu::bool2any((sal_False));
1540 // don't allow the aggregate which is currently being reset to return a (temporary) "yes"
1541 else
1542 return OPropertySetAggregationHelper::getFastPropertyValue(nHandle);
1543 }
1544
1545 //------------------------------------------------------------------------------
getFastPropertyValue(Any & rValue,sal_Int32 nHandle) const1546 void ODatabaseForm::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
1547 {
1548 switch (nHandle)
1549 {
1550 case PROPERTY_ID_INSERTONLY:
1551 rValue <<= m_bInsertOnly;
1552 break;
1553
1554 case PROPERTY_ID_FILTER:
1555 rValue <<= m_aFilterManager.getFilterComponent( FilterManager::fcPublicFilter );
1556 break;
1557
1558 case PROPERTY_ID_APPLYFILTER:
1559 rValue <<= m_aFilterManager.isApplyPublicFilter();
1560 break;
1561
1562 case PROPERTY_ID_DATASOURCE:
1563 rValue = m_xAggregateSet->getPropertyValue( PROPERTY_DATASOURCE );
1564 break;
1565
1566 case PROPERTY_ID_TARGET_URL:
1567 rValue <<= m_aTargetURL;
1568 break;
1569 case PROPERTY_ID_TARGET_FRAME:
1570 rValue <<= m_aTargetFrame;
1571 break;
1572 case PROPERTY_ID_SUBMIT_METHOD:
1573 rValue <<= m_eSubmitMethod;
1574 break;
1575 case PROPERTY_ID_SUBMIT_ENCODING:
1576 rValue <<= m_eSubmitEncoding;
1577 break;
1578 case PROPERTY_ID_NAME:
1579 rValue <<= m_sName;
1580 break;
1581 case PROPERTY_ID_MASTERFIELDS:
1582 rValue <<= m_aMasterFields;
1583 break;
1584 case PROPERTY_ID_DETAILFIELDS:
1585 rValue <<= m_aDetailFields;
1586 break;
1587 case PROPERTY_ID_CYCLE:
1588 rValue = m_aCycle;
1589 break;
1590 case PROPERTY_ID_NAVIGATION:
1591 rValue <<= m_eNavigation;
1592 break;
1593 case PROPERTY_ID_ALLOWADDITIONS:
1594 rValue <<= (sal_Bool)m_bAllowInsert;
1595 break;
1596 case PROPERTY_ID_ALLOWEDITS:
1597 rValue <<= (sal_Bool)m_bAllowUpdate;
1598 break;
1599 case PROPERTY_ID_ALLOWDELETIONS:
1600 rValue <<= (sal_Bool)m_bAllowDelete;
1601 break;
1602 case PROPERTY_ID_PRIVILEGES:
1603 rValue <<= (sal_Int32)m_nPrivileges;
1604 break;
1605 case PROPERTY_ID_DYNAMIC_CONTROL_BORDER:
1606 rValue = m_aDynamicControlBorder;
1607 break;
1608 case PROPERTY_ID_CONTROL_BORDER_COLOR_FOCUS:
1609 rValue = m_aControlBorderColorFocus;
1610 break;
1611 case PROPERTY_ID_CONTROL_BORDER_COLOR_MOUSE:
1612 rValue = m_aControlBorderColorMouse;
1613 break;
1614 case PROPERTY_ID_CONTROL_BORDER_COLOR_INVALID:
1615 rValue = m_aControlBorderColorInvalid;
1616 break;
1617 default:
1618 if ( m_aPropertyBagHelper.hasDynamicPropertyByHandle( nHandle ) )
1619 m_aPropertyBagHelper.getDynamicFastPropertyValue( nHandle, rValue );
1620 else
1621 OPropertySetAggregationHelper::getFastPropertyValue( rValue, nHandle );
1622 break;
1623 }
1624 }
1625
1626 //------------------------------------------------------------------------------
convertFastPropertyValue(Any & rConvertedValue,Any & rOldValue,sal_Int32 nHandle,const Any & rValue)1627 sal_Bool ODatabaseForm::convertFastPropertyValue( Any& rConvertedValue, Any& rOldValue,
1628 sal_Int32 nHandle, const Any& rValue ) throw( IllegalArgumentException )
1629 {
1630 sal_Bool bModified(sal_False);
1631 switch (nHandle)
1632 {
1633 case PROPERTY_ID_INSERTONLY:
1634 bModified = tryPropertyValue( rConvertedValue, rOldValue, rValue, m_bInsertOnly );
1635 break;
1636
1637 case PROPERTY_ID_FILTER:
1638 bModified = tryPropertyValue( rConvertedValue, rOldValue, rValue, m_aFilterManager.getFilterComponent( FilterManager::fcPublicFilter ) );
1639 break;
1640
1641 case PROPERTY_ID_APPLYFILTER:
1642 bModified = tryPropertyValue( rConvertedValue, rOldValue, rValue, m_aFilterManager.isApplyPublicFilter() );
1643 break;
1644
1645 case PROPERTY_ID_DATASOURCE:
1646 {
1647 Any aAggregateProperty;
1648 getFastPropertyValue(aAggregateProperty, PROPERTY_ID_DATASOURCE);
1649 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, aAggregateProperty, ::getCppuType(static_cast<const ::rtl::OUString*>(NULL)));
1650 }
1651 break;
1652 case PROPERTY_ID_TARGET_URL:
1653 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_aTargetURL);
1654 break;
1655 case PROPERTY_ID_TARGET_FRAME:
1656 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_aTargetFrame);
1657 break;
1658 case PROPERTY_ID_SUBMIT_METHOD:
1659 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_eSubmitMethod);
1660 break;
1661 case PROPERTY_ID_SUBMIT_ENCODING:
1662 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_eSubmitEncoding);
1663 break;
1664 case PROPERTY_ID_NAME:
1665 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_sName);
1666 break;
1667 case PROPERTY_ID_MASTERFIELDS:
1668 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_aMasterFields);
1669 break;
1670 case PROPERTY_ID_DETAILFIELDS:
1671 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_aDetailFields);
1672 break;
1673 case PROPERTY_ID_CYCLE:
1674 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_aCycle, ::getCppuType(static_cast<const TabulatorCycle*>(NULL)));
1675 break;
1676 case PROPERTY_ID_NAVIGATION:
1677 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_eNavigation);
1678 break;
1679 case PROPERTY_ID_ALLOWADDITIONS:
1680 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAllowInsert);
1681 break;
1682 case PROPERTY_ID_ALLOWEDITS:
1683 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAllowUpdate);
1684 break;
1685 case PROPERTY_ID_ALLOWDELETIONS:
1686 bModified = tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bAllowDelete);
1687 break;
1688 case PROPERTY_ID_DYNAMIC_CONTROL_BORDER:
1689 bModified = tryPropertyValue( rConvertedValue, rOldValue, rValue, m_aDynamicControlBorder, ::getBooleanCppuType() );
1690 break;
1691 case PROPERTY_ID_CONTROL_BORDER_COLOR_FOCUS:
1692 bModified = tryPropertyValue( rConvertedValue, rOldValue, rValue, m_aControlBorderColorFocus, getCppuType( static_cast< sal_Int32* >( NULL ) ) );
1693 break;
1694 case PROPERTY_ID_CONTROL_BORDER_COLOR_MOUSE:
1695 bModified = tryPropertyValue( rConvertedValue, rOldValue, rValue, m_aControlBorderColorMouse, getCppuType( static_cast< sal_Int32* >( NULL ) ) );
1696 break;
1697 case PROPERTY_ID_CONTROL_BORDER_COLOR_INVALID:
1698 bModified = tryPropertyValue( rConvertedValue, rOldValue, rValue, m_aControlBorderColorInvalid, getCppuType( static_cast< sal_Int32* >( NULL ) ) );
1699 break;
1700 default:
1701 if ( m_aPropertyBagHelper.hasDynamicPropertyByHandle ( nHandle ) )
1702 bModified = m_aPropertyBagHelper.convertDynamicFastPropertyValue( nHandle, rValue, rConvertedValue, rOldValue );
1703 else
1704 bModified = OPropertySetAggregationHelper::convertFastPropertyValue( rConvertedValue, rOldValue, nHandle, rValue );
1705 break;
1706 }
1707 return bModified;
1708 }
1709
1710 //------------------------------------------------------------------------------
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any & rValue)1711 void ODatabaseForm::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) throw( Exception )
1712 {
1713 switch (nHandle)
1714 {
1715 case PROPERTY_ID_INSERTONLY:
1716 rValue >>= m_bInsertOnly;
1717 if ( m_aIgnoreResult.hasValue() )
1718 m_aIgnoreResult <<= m_bInsertOnly;
1719 else
1720 m_xAggregateSet->setPropertyValue( PROPERTY_INSERTONLY, makeAny( m_bInsertOnly ) );
1721 break;
1722
1723 case PROPERTY_ID_FILTER:
1724 {
1725 ::rtl::OUString sNewFilter;
1726 rValue >>= sNewFilter;
1727 m_aFilterManager.setFilterComponent( FilterManager::fcPublicFilter, sNewFilter );
1728 }
1729 break;
1730
1731 case PROPERTY_ID_APPLYFILTER:
1732 {
1733 sal_Bool bApply = sal_True;
1734 rValue >>= bApply;
1735 m_aFilterManager.setApplyPublicFilter( bApply );
1736 }
1737 break;
1738
1739 case PROPERTY_ID_DATASOURCE:
1740 {
1741 Reference< XConnection > xSomeConnection;
1742 if ( ::dbtools::isEmbeddedInDatabase( getParent(), xSomeConnection ) )
1743 throw PropertyVetoException();
1744
1745 try
1746 {
1747 m_xAggregateSet->setPropertyValue(PROPERTY_DATASOURCE, rValue);
1748 }
1749 catch(Exception&) { }
1750 }
1751 break;
1752 case PROPERTY_ID_TARGET_URL:
1753 rValue >>= m_aTargetURL;
1754 break;
1755 case PROPERTY_ID_TARGET_FRAME:
1756 rValue >>= m_aTargetFrame;
1757 break;
1758 case PROPERTY_ID_SUBMIT_METHOD:
1759 rValue >>= m_eSubmitMethod;
1760 break;
1761 case PROPERTY_ID_SUBMIT_ENCODING:
1762 rValue >>= m_eSubmitEncoding;
1763 break;
1764 case PROPERTY_ID_NAME:
1765 rValue >>= m_sName;
1766 break;
1767 case PROPERTY_ID_MASTERFIELDS:
1768 rValue >>= m_aMasterFields;
1769 invlidateParameters();
1770 break;
1771 case PROPERTY_ID_DETAILFIELDS:
1772 rValue >>= m_aDetailFields;
1773 invlidateParameters();
1774 break;
1775 case PROPERTY_ID_CYCLE:
1776 m_aCycle = rValue;
1777 break;
1778 case PROPERTY_ID_NAVIGATION:
1779 rValue >>= m_eNavigation;
1780 break;
1781 case PROPERTY_ID_ALLOWADDITIONS:
1782 m_bAllowInsert = getBOOL(rValue);
1783 break;
1784 case PROPERTY_ID_ALLOWEDITS:
1785 m_bAllowUpdate = getBOOL(rValue);
1786 break;
1787 case PROPERTY_ID_ALLOWDELETIONS:
1788 m_bAllowDelete = getBOOL(rValue);
1789 break;
1790 case PROPERTY_ID_DYNAMIC_CONTROL_BORDER:
1791 m_aDynamicControlBorder = rValue;
1792 break;
1793 case PROPERTY_ID_CONTROL_BORDER_COLOR_FOCUS:
1794 m_aControlBorderColorFocus = rValue;
1795 break;
1796 case PROPERTY_ID_CONTROL_BORDER_COLOR_MOUSE:
1797 m_aControlBorderColorMouse = rValue;
1798 break;
1799 case PROPERTY_ID_CONTROL_BORDER_COLOR_INVALID:
1800 m_aControlBorderColorInvalid = rValue;
1801 break;
1802
1803 case PROPERTY_ID_ACTIVE_CONNECTION:
1804 {
1805 Reference< XConnection > xOuterConnection;
1806 if ( ::dbtools::isEmbeddedInDatabase( getParent(), xOuterConnection ) )
1807 {
1808 if ( xOuterConnection != Reference< XConnection >( rValue, UNO_QUERY ) )
1809 // somebody's trying to set a connection which is not equal the connection
1810 // implied by the database we're embedded in
1811 throw PropertyVetoException();
1812 }
1813 OPropertySetAggregationHelper::setFastPropertyValue_NoBroadcast( nHandle, rValue );
1814 break;
1815 }
1816
1817 default:
1818 if ( m_aPropertyBagHelper.hasDynamicPropertyByHandle( nHandle ) )
1819 m_aPropertyBagHelper.setDynamicFastPropertyValue( nHandle, rValue );
1820 else
1821 OPropertySetAggregationHelper::setFastPropertyValue_NoBroadcast( nHandle, rValue );
1822 break;
1823 }
1824 }
1825
1826 //------------------------------------------------------------------
forwardingPropertyValue(sal_Int32 _nHandle)1827 void SAL_CALL ODatabaseForm::forwardingPropertyValue( sal_Int32 _nHandle )
1828 {
1829 OSL_ENSURE( _nHandle == PROPERTY_ID_ACTIVE_CONNECTION, "ODatabaseForm::forwardingPropertyValue: unexpected property!" );
1830 if ( _nHandle == PROPERTY_ID_ACTIVE_CONNECTION )
1831 {
1832 if ( m_bSharingConnection )
1833 stopSharingConnection( );
1834 m_bForwardingConnection = sal_True;
1835 }
1836 }
1837
1838 //------------------------------------------------------------------
forwardedPropertyValue(sal_Int32 _nHandle,bool)1839 void SAL_CALL ODatabaseForm::forwardedPropertyValue( sal_Int32 _nHandle, bool /*_bSuccess*/ )
1840 {
1841 OSL_ENSURE( _nHandle == PROPERTY_ID_ACTIVE_CONNECTION, "ODatabaseForm::forwardedPropertyValue: unexpected property!" );
1842 if ( _nHandle == PROPERTY_ID_ACTIVE_CONNECTION )
1843 {
1844 m_bForwardingConnection = sal_False;
1845 }
1846 }
1847
1848 //==============================================================================
1849 // com::sun::star::beans::XPropertyState
1850 //------------------------------------------------------------------
getPropertyStateByHandle(sal_Int32 nHandle)1851 PropertyState ODatabaseForm::getPropertyStateByHandle(sal_Int32 nHandle)
1852 {
1853 PropertyState eState;
1854 switch (nHandle)
1855 {
1856 case PROPERTY_ID_NAVIGATION:
1857 return (NavigationBarMode_CURRENT == m_eNavigation) ? PropertyState_DEFAULT_VALUE : PropertyState_DIRECT_VALUE;
1858
1859 case PROPERTY_ID_CYCLE:
1860 eState = m_aCycle.hasValue() ? PropertyState_DIRECT_VALUE : PropertyState_DEFAULT_VALUE;
1861 break;
1862
1863 case PROPERTY_ID_INSERTONLY:
1864 eState = m_bInsertOnly ? PropertyState_DIRECT_VALUE : PropertyState_DEFAULT_VALUE;
1865 break;
1866
1867 case PROPERTY_ID_FILTER:
1868 if ( !m_aFilterManager.getFilterComponent( FilterManager::fcPublicFilter ).getLength() )
1869 eState = PropertyState_DEFAULT_VALUE;
1870 else
1871 eState = PropertyState_DIRECT_VALUE;
1872 break;
1873
1874 case PROPERTY_ID_APPLYFILTER:
1875 eState = m_aFilterManager.isApplyPublicFilter() ? PropertyState_DEFAULT_VALUE : PropertyState_DIRECT_VALUE;
1876 break;
1877
1878 case PROPERTY_ID_DYNAMIC_CONTROL_BORDER:
1879 eState = m_aDynamicControlBorder.hasValue() ? PropertyState_DIRECT_VALUE : PropertyState_DEFAULT_VALUE;
1880 break;
1881
1882 case PROPERTY_ID_CONTROL_BORDER_COLOR_FOCUS:
1883 eState = m_aControlBorderColorFocus.hasValue() ? PropertyState_DIRECT_VALUE : PropertyState_DEFAULT_VALUE;
1884 break;
1885
1886 case PROPERTY_ID_CONTROL_BORDER_COLOR_MOUSE:
1887 eState = m_aControlBorderColorMouse.hasValue() ? PropertyState_DIRECT_VALUE : PropertyState_DEFAULT_VALUE;
1888 break;
1889
1890 case PROPERTY_ID_CONTROL_BORDER_COLOR_INVALID:
1891 eState = m_aControlBorderColorInvalid.hasValue() ? PropertyState_DIRECT_VALUE : PropertyState_DEFAULT_VALUE;
1892 break;
1893
1894 default:
1895 eState = OPropertySetAggregationHelper::getPropertyStateByHandle(nHandle);
1896 }
1897 return eState;
1898 }
1899
1900 //------------------------------------------------------------------
setPropertyToDefaultByHandle(sal_Int32 nHandle)1901 void ODatabaseForm::setPropertyToDefaultByHandle(sal_Int32 nHandle)
1902 {
1903 switch (nHandle)
1904 {
1905 case PROPERTY_ID_INSERTONLY:
1906 case PROPERTY_ID_FILTER:
1907 case PROPERTY_ID_APPLYFILTER:
1908 case PROPERTY_ID_NAVIGATION:
1909 case PROPERTY_ID_CYCLE:
1910 case PROPERTY_ID_DYNAMIC_CONTROL_BORDER:
1911 case PROPERTY_ID_CONTROL_BORDER_COLOR_FOCUS:
1912 case PROPERTY_ID_CONTROL_BORDER_COLOR_MOUSE:
1913 case PROPERTY_ID_CONTROL_BORDER_COLOR_INVALID:
1914 setFastPropertyValue( nHandle, getPropertyDefaultByHandle( nHandle ) );
1915 break;
1916
1917 default:
1918 OPropertySetAggregationHelper::setPropertyToDefaultByHandle(nHandle);
1919 }
1920 }
1921
1922 //------------------------------------------------------------------
getPropertyDefaultByHandle(sal_Int32 nHandle) const1923 Any ODatabaseForm::getPropertyDefaultByHandle( sal_Int32 nHandle ) const
1924 {
1925 Any aReturn;
1926 switch (nHandle)
1927 {
1928 case PROPERTY_ID_INSERTONLY:
1929 case PROPERTY_ID_DYNAMIC_CONTROL_BORDER:
1930 aReturn <<= sal_False;
1931 break;
1932
1933 case PROPERTY_ID_FILTER:
1934 aReturn <<= ::rtl::OUString();
1935 break;
1936
1937 case PROPERTY_ID_APPLYFILTER:
1938 aReturn <<= sal_True;
1939 break;
1940
1941 case PROPERTY_ID_NAVIGATION:
1942 aReturn = makeAny(NavigationBarMode_CURRENT);
1943 break;
1944
1945 case PROPERTY_ID_CYCLE:
1946 case PROPERTY_ID_CONTROL_BORDER_COLOR_FOCUS:
1947 case PROPERTY_ID_CONTROL_BORDER_COLOR_MOUSE:
1948 case PROPERTY_ID_CONTROL_BORDER_COLOR_INVALID:
1949 break;
1950
1951 default:
1952 if ( m_aPropertyBagHelper.hasDynamicPropertyByHandle( nHandle ) )
1953 m_aPropertyBagHelper.getDynamicPropertyDefaultByHandle( nHandle, aReturn );
1954 else
1955 aReturn = OPropertySetAggregationHelper::getPropertyDefaultByHandle( nHandle );
1956 break;
1957 }
1958 return aReturn;
1959 }
1960
1961 //==============================================================================
1962 // com::sun::star::form::XReset
1963 //------------------------------------------------------------------------------
reset()1964 void SAL_CALL ODatabaseForm::reset() throw( RuntimeException )
1965 {
1966 ::osl::ResettableMutexGuard aGuard(m_aMutex);
1967
1968 if (isLoaded())
1969 {
1970 ::osl::MutexGuard aResetGuard(m_aResetSafety);
1971 ++m_nResetsPending;
1972 reset_impl(true);
1973 return;
1974 }
1975
1976 if ( !m_aResetListeners.empty() )
1977 {
1978 ::osl::MutexGuard aResetGuard(m_aResetSafety);
1979 ++m_nResetsPending;
1980 // create an own thread if we have (approve-)reset-listeners (so the listeners can't do that much damage
1981 // to this thread which is probably the main one)
1982 if (!m_pThread)
1983 {
1984 m_pThread = new OFormSubmitResetThread(this);
1985 m_pThread->acquire();
1986 m_pThread->create();
1987 }
1988 EventObject aEvt;
1989 m_pThread->addEvent(&aEvt, sal_False);
1990 }
1991 else
1992 {
1993 // direct call without any approving by the listeners
1994 aGuard.clear();
1995
1996 ::osl::MutexGuard aResetGuard(m_aResetSafety);
1997 ++m_nResetsPending;
1998 reset_impl(false);
1999 }
2000 }
2001
2002 //-----------------------------------------------------------------------------
reset_impl(bool _bAproveByListeners)2003 void ODatabaseForm::reset_impl(bool _bAproveByListeners)
2004 {
2005 if ( _bAproveByListeners )
2006 if ( !m_aResetListeners.approveReset() )
2007 return;
2008
2009 ::osl::ResettableMutexGuard aResetGuard(m_aResetSafety);
2010 // do we have a database connected form and stay on the insert row
2011 sal_Bool bInsertRow = sal_False;
2012 if (m_xAggregateSet.is())
2013 bInsertRow = getBOOL(m_xAggregateSet->getPropertyValue(PROPERTY_ISNEW));
2014 if (bInsertRow)
2015 {
2016 try
2017 {
2018 // Iterate through all columns and set the default value
2019 Reference< XColumnsSupplier > xColsSuppl( m_xAggregateSet, UNO_QUERY );
2020 Reference< XIndexAccess > xIndexCols( xColsSuppl->getColumns(), UNO_QUERY );
2021 for (sal_Int32 i = 0; i < xIndexCols->getCount(); ++i)
2022 {
2023 Reference< XPropertySet > xColProps;
2024 xIndexCols->getByIndex(i) >>= xColProps;
2025
2026 Reference< XColumnUpdate > xColUpdate( xColProps, UNO_QUERY );
2027 if ( !xColUpdate.is() )
2028 continue;
2029
2030 Reference< XPropertySetInfo > xPSI;
2031 if ( xColProps.is() )
2032 xPSI = xColProps->getPropertySetInfo( );
2033
2034 static const ::rtl::OUString PROPERTY_CONTROLDEFAULT( RTL_CONSTASCII_USTRINGPARAM( "ControlDefault" ) );
2035 if ( xPSI.is() && xPSI->hasPropertyByName( PROPERTY_CONTROLDEFAULT ) )
2036 {
2037 Any aDefault = xColProps->getPropertyValue( PROPERTY_CONTROLDEFAULT );
2038
2039 sal_Bool bReadOnly = sal_False;
2040 if ( xPSI->hasPropertyByName( PROPERTY_ISREADONLY ) )
2041 xColProps->getPropertyValue( PROPERTY_ISREADONLY ) >>= bReadOnly;
2042
2043 if ( !bReadOnly )
2044 {
2045 try
2046 {
2047 if ( aDefault.hasValue() )
2048 xColUpdate->updateObject( aDefault );
2049 }
2050 catch(Exception&)
2051 {
2052 DBG_UNHANDLED_EXCEPTION();
2053 }
2054 }
2055 }
2056 }
2057 }
2058 catch(Exception&)
2059 {
2060 }
2061
2062 if (m_bSubForm)
2063 {
2064 Reference< XColumnsSupplier > xParentColSupp( m_xParent, UNO_QUERY );
2065 Reference< XNameAccess > xParentCols;
2066 if ( xParentColSupp.is() )
2067 xParentCols = xParentColSupp->getColumns();
2068
2069 if ( xParentCols.is() && xParentCols->hasElements() && m_aMasterFields.getLength() )
2070 {
2071 try
2072 {
2073 // analyze our parameters
2074 if ( !m_aParameterManager.isUpToDate() )
2075 updateParameterInfo();
2076
2077 m_aParameterManager.resetParameterValues( );
2078 }
2079 catch(const Exception&)
2080 {
2081 OSL_ENSURE(sal_False, "ODatabaseForm::reset_impl: could not initialize the master-detail-driven parameters!");
2082 }
2083 }
2084 }
2085 }
2086
2087 aResetGuard.clear();
2088 // iterate through all components. don't use an XIndexAccess as this will cause massive
2089 // problems with the count.
2090 Reference<XEnumeration> xIter = createEnumeration();
2091 while (xIter->hasMoreElements())
2092 {
2093 Reference<XReset> xReset;
2094 xIter->nextElement() >>= xReset;
2095 if (xReset.is())
2096 {
2097 // TODO : all reset-methods have to be thread-safe
2098 xReset->reset();
2099 }
2100 }
2101
2102 aResetGuard.reset();
2103 // ensure that the row isn't modified
2104 // (do this _before_ the listeners are notified ! their reaction (maybe asynchronous) may depend
2105 // on the modified state of the row
2106 // 21.02.00 - 73265 - FS)
2107 if (bInsertRow)
2108 m_xAggregateSet->setPropertyValue(PROPERTY_ISMODIFIED, ::cppu::bool2any(sal_Bool(sal_False)));
2109
2110 aResetGuard.clear();
2111 {
2112 m_aResetListeners.resetted();
2113 }
2114
2115 aResetGuard.reset();
2116 // and again : ensure the row isn't modified
2117 // we already did this after we (and maybe our dependents) resetted the values, but the listeners may have changed the row, too
2118 if (bInsertRow)
2119 m_xAggregateSet->setPropertyValue(PROPERTY_ISMODIFIED, ::cppu::bool2any((sal_False)));
2120
2121 --m_nResetsPending;
2122 }
2123
2124 //-----------------------------------------------------------------------------
addResetListener(const Reference<XResetListener> & _rListener)2125 void SAL_CALL ODatabaseForm::addResetListener(const Reference<XResetListener>& _rListener) throw( RuntimeException )
2126 {
2127 m_aResetListeners.addTypedListener( _rListener );
2128 }
2129
2130 //-----------------------------------------------------------------------------
removeResetListener(const Reference<XResetListener> & _rListener)2131 void SAL_CALL ODatabaseForm::removeResetListener(const Reference<XResetListener>& _rListener) throw( RuntimeException )
2132 {
2133 m_aResetListeners.removeTypedListener( _rListener );
2134 }
2135
2136 //==============================================================================
2137 // com::sun::star::form::XSubmit
2138 //------------------------------------------------------------------------------
submit(const Reference<XControl> & Control,const::com::sun::star::awt::MouseEvent & MouseEvt)2139 void SAL_CALL ODatabaseForm::submit( const Reference<XControl>& Control,
2140 const ::com::sun::star::awt::MouseEvent& MouseEvt ) throw( RuntimeException )
2141 {
2142 {
2143 ::osl::MutexGuard aGuard(m_aMutex);
2144 // Sind Controls und eine Submit-URL vorhanden?
2145 if( !getCount() || !m_aTargetURL.getLength() )
2146 return;
2147 }
2148
2149 ::osl::ClearableMutexGuard aGuard(m_aMutex);
2150 if (m_aSubmitListeners.getLength())
2151 {
2152 // create an own thread if we have (approve-)submit-listeners (so the listeners can't do that much damage
2153 // to this thread which is probably the main one)
2154 if (!m_pThread)
2155 {
2156 m_pThread = new OFormSubmitResetThread(this);
2157 m_pThread->acquire();
2158 m_pThread->create();
2159 }
2160 m_pThread->addEvent(&MouseEvt, Control, sal_True);
2161 }
2162 else
2163 {
2164 // direct call without any approving by the listeners
2165 aGuard.clear();
2166 submit_impl( Control, MouseEvt, true );
2167 }
2168 }
2169 // -----------------------------------------------------------------------------
lcl_dispatch(const Reference<XFrame> & xFrame,const Reference<XURLTransformer> & xTransformer,const::rtl::OUString & aURLStr,const::rtl::OUString & aReferer,const::rtl::OUString & aTargetName,const::rtl::OUString & aData,rtl_TextEncoding _eEncoding)2170 void lcl_dispatch(const Reference< XFrame >& xFrame,const Reference<XURLTransformer>& xTransformer,const ::rtl::OUString& aURLStr,const ::rtl::OUString& aReferer,const ::rtl::OUString& aTargetName
2171 ,const ::rtl::OUString& aData,rtl_TextEncoding _eEncoding)
2172 {
2173 URL aURL;
2174 aURL.Complete = aURLStr;
2175 xTransformer->parseStrict(aURL);
2176
2177 Reference< XDispatch > xDisp = Reference< XDispatchProvider > (xFrame,UNO_QUERY)->queryDispatch(aURL, aTargetName,
2178 FrameSearchFlag::SELF | FrameSearchFlag::PARENT | FrameSearchFlag::CHILDREN |
2179 FrameSearchFlag::SIBLINGS | FrameSearchFlag::CREATE | FrameSearchFlag::TASKS);
2180
2181 if (xDisp.is())
2182 {
2183 Sequence<PropertyValue> aArgs(2);
2184 aArgs.getArray()[0].Name = ::rtl::OUString::createFromAscii("Referer");
2185 aArgs.getArray()[0].Value <<= aReferer;
2186
2187 // build a sequence from the to-be-submitted string
2188 ByteString a8BitData(aData.getStr(), (sal_uInt16)aData.getLength(), _eEncoding);
2189 // always ANSI #58641
2190 Sequence< sal_Int8 > aPostData((sal_Int8*)a8BitData.GetBuffer(), a8BitData.Len());
2191 Reference< XInputStream > xPostData = new SequenceInputStream(aPostData);
2192
2193 aArgs.getArray()[1].Name = ::rtl::OUString::createFromAscii("PostData");
2194 aArgs.getArray()[1].Value <<= xPostData;
2195
2196 xDisp->dispatch(aURL, aArgs);
2197 } // if (xDisp.is())
2198 }
2199 //------------------------------------------------------------------------------
submit_impl(const Reference<XControl> & Control,const::com::sun::star::awt::MouseEvent & MouseEvt,bool _bAproveByListeners)2200 void ODatabaseForm::submit_impl(const Reference<XControl>& Control, const ::com::sun::star::awt::MouseEvent& MouseEvt, bool _bAproveByListeners)
2201 {
2202
2203 if (_bAproveByListeners)
2204 {
2205 ::cppu::OInterfaceIteratorHelper aIter(m_aSubmitListeners);
2206 EventObject aEvt(static_cast<XWeak*>(this));
2207 sal_Bool bCanceled = sal_False;
2208 while (aIter.hasMoreElements() && !bCanceled)
2209 {
2210 if (!((XSubmitListener*)aIter.next())->approveSubmit(aEvt))
2211 bCanceled = sal_True;
2212 }
2213
2214 if (bCanceled)
2215 return;
2216 }
2217
2218 FormSubmitEncoding eSubmitEncoding;
2219 FormSubmitMethod eSubmitMethod;
2220 ::rtl::OUString aURLStr;
2221 ::rtl::OUString aReferer;
2222 ::rtl::OUString aTargetName;
2223 Reference< XModel > xModel;
2224 {
2225 ::vos::OGuard aGuard( Application::GetSolarMutex() );
2226 // starform->Forms
2227
2228 Reference<XChild> xParent(m_xParent, UNO_QUERY);
2229
2230 if (xParent.is())
2231 xModel = getXModel(xParent->getParent());
2232
2233 if (xModel.is())
2234 aReferer = xModel->getURL();
2235
2236 // TargetItem
2237 aTargetName = m_aTargetFrame;
2238
2239 eSubmitEncoding = m_eSubmitEncoding;
2240 eSubmitMethod = m_eSubmitMethod;
2241 aURLStr = m_aTargetURL;
2242 }
2243
2244 if (!xModel.is())
2245 return;
2246 Reference< XFrame > xFrame = xModel->getCurrentController()->getFrame();
2247 if (!xFrame.is())
2248 return;
2249
2250 Reference<XURLTransformer>
2251 xTransformer(m_xServiceFactory->createInstance(
2252 ::rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer")), UNO_QUERY);
2253 DBG_ASSERT(xTransformer.is(), "ODatabaseForm::submit_impl : could not create an URL transformer !");
2254
2255 // URL-Encoding
2256 if( eSubmitEncoding == FormSubmitEncoding_URL )
2257 {
2258 ::rtl::OUString aData;
2259 {
2260 ::vos::OGuard aGuard( Application::GetSolarMutex() );
2261 aData = GetDataURLEncoded( Control, MouseEvt );
2262 }
2263
2264 URL aURL;
2265 // FormMethod GET
2266 if( eSubmitMethod == FormSubmitMethod_GET )
2267 {
2268 INetURLObject aUrlObj( aURLStr, INetURLObject::WAS_ENCODED );
2269 aUrlObj.SetParam( aData, INetURLObject::ENCODE_ALL );
2270 aURL.Complete = aUrlObj.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
2271 if (xTransformer.is())
2272 xTransformer->parseStrict(aURL);
2273
2274 Reference< XDispatch > xDisp = Reference< XDispatchProvider > (xFrame,UNO_QUERY)->queryDispatch(aURL, aTargetName,
2275 FrameSearchFlag::SELF | FrameSearchFlag::PARENT | FrameSearchFlag::CHILDREN |
2276 FrameSearchFlag::SIBLINGS | FrameSearchFlag::CREATE | FrameSearchFlag::TASKS);
2277
2278 if (xDisp.is())
2279 {
2280 Sequence<PropertyValue> aArgs(1);
2281 aArgs.getArray()->Name = ::rtl::OUString::createFromAscii("Referer");
2282 aArgs.getArray()->Value <<= aReferer;
2283 xDisp->dispatch(aURL, aArgs);
2284 }
2285 }
2286 // FormMethod POST
2287 else if( eSubmitMethod == FormSubmitMethod_POST )
2288 {
2289 lcl_dispatch(xFrame,xTransformer,aURLStr,aReferer,aTargetName,aData,RTL_TEXTENCODING_MS_1252);
2290 }
2291 }
2292 else if( eSubmitEncoding == FormSubmitEncoding_MULTIPART )
2293 {
2294 URL aURL;
2295 aURL.Complete = aURLStr;
2296 xTransformer->parseStrict(aURL);
2297
2298 Reference< XDispatch > xDisp = Reference< XDispatchProvider > (xFrame,UNO_QUERY)->queryDispatch(aURL, aTargetName,
2299 FrameSearchFlag::SELF | FrameSearchFlag::PARENT | FrameSearchFlag::CHILDREN |
2300 FrameSearchFlag::SIBLINGS | FrameSearchFlag::CREATE | FrameSearchFlag::TASKS);
2301
2302 if (xDisp.is())
2303 {
2304 ::rtl::OUString aContentType;
2305 Sequence<sal_Int8> aData;
2306 {
2307 ::vos::OGuard aGuard( Application::GetSolarMutex() );
2308 aData = GetDataMultiPartEncoded(Control, MouseEvt, aContentType);
2309 }
2310 if (!aData.getLength())
2311 return;
2312
2313 Sequence<PropertyValue> aArgs(3);
2314 aArgs.getArray()[0].Name = ::rtl::OUString::createFromAscii("Referer");
2315 aArgs.getArray()[0].Value <<= aReferer;
2316 aArgs.getArray()[1].Name = ::rtl::OUString::createFromAscii("ContentType");
2317 aArgs.getArray()[1].Value <<= aContentType;
2318
2319 // build a sequence from the to-be-submitted string
2320 Reference< XInputStream > xPostData = new SequenceInputStream(aData);
2321
2322 aArgs.getArray()[2].Name = ::rtl::OUString::createFromAscii("PostData");
2323 aArgs.getArray()[2].Value <<= xPostData;
2324
2325 xDisp->dispatch(aURL, aArgs);
2326 }
2327 }
2328 else if( eSubmitEncoding == FormSubmitEncoding_TEXT )
2329 {
2330 ::rtl::OUString aData;
2331 {
2332 ::vos::OGuard aGuard( Application::GetSolarMutex() );
2333 aData = GetDataTextEncoded( Reference<XControl> (), MouseEvt );
2334 }
2335
2336 lcl_dispatch(xFrame,xTransformer,aURLStr,aReferer,aTargetName,aData,osl_getThreadTextEncoding());
2337 }
2338 else {
2339 DBG_ERROR("ODatabaseForm::submit_Impl : wrong encoding !");
2340 }
2341
2342 }
2343
2344 // XSubmit
2345 //------------------------------------------------------------------------------
addSubmitListener(const Reference<XSubmitListener> & _rListener)2346 void SAL_CALL ODatabaseForm::addSubmitListener(const Reference<XSubmitListener>& _rListener) throw( RuntimeException )
2347 {
2348 m_aSubmitListeners.addInterface(_rListener);
2349 }
2350
2351 //------------------------------------------------------------------------------
removeSubmitListener(const Reference<XSubmitListener> & _rListener)2352 void SAL_CALL ODatabaseForm::removeSubmitListener(const Reference<XSubmitListener>& _rListener) throw( RuntimeException )
2353 {
2354 m_aSubmitListeners.removeInterface(_rListener);
2355 }
2356
2357 //==============================================================================
2358 // com::sun::star::sdbc::XSQLErrorBroadcaster
2359 //------------------------------------------------------------------------------
addSQLErrorListener(const Reference<XSQLErrorListener> & _rListener)2360 void SAL_CALL ODatabaseForm::addSQLErrorListener(const Reference<XSQLErrorListener>& _rListener) throw( RuntimeException )
2361 {
2362 m_aErrorListeners.addInterface(_rListener);
2363 }
2364
2365 //------------------------------------------------------------------------------
removeSQLErrorListener(const Reference<XSQLErrorListener> & _rListener)2366 void SAL_CALL ODatabaseForm::removeSQLErrorListener(const Reference<XSQLErrorListener>& _rListener) throw( RuntimeException )
2367 {
2368 m_aErrorListeners.removeInterface(_rListener);
2369 }
2370
2371 //------------------------------------------------------------------------------
invlidateParameters()2372 void ODatabaseForm::invlidateParameters()
2373 {
2374 ::osl::MutexGuard aGuard(m_aMutex);
2375 m_aParameterManager.clearAllParameterInformation();
2376 }
2377
2378 //==============================================================================
2379 // OChangeListener
2380 //------------------------------------------------------------------------------
_propertyChanged(const PropertyChangeEvent & evt)2381 void ODatabaseForm::_propertyChanged(const PropertyChangeEvent& evt) throw( RuntimeException )
2382 {
2383 if ((0 == evt.PropertyName.compareToAscii(PROPERTY_ACTIVE_CONNECTION)) && !m_bForwardingConnection)
2384 {
2385 // the rowset changed its active connection itself (without interaction from our side), so
2386 // we need to fire this event, too
2387 sal_Int32 nHandle = PROPERTY_ID_ACTIVE_CONNECTION;
2388 fire(&nHandle, &evt.NewValue, &evt.OldValue, 1, sal_False);
2389 }
2390 else // it was one of the statement relevant props
2391 {
2392 // if the statement has changed we have to delete the parameter info
2393 invlidateParameters();
2394 }
2395 }
2396
2397 //==============================================================================
2398 // smartXChild
2399 //------------------------------------------------------------------------------
setParent(const InterfaceRef & Parent)2400 void SAL_CALL ODatabaseForm::setParent(const InterfaceRef& Parent) throw ( ::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException)
2401 {
2402 // SYNCHRONIZED ----->
2403 ::osl::ResettableMutexGuard aGuard(m_aMutex);
2404
2405 Reference<XForm> xParentForm(getParent(), UNO_QUERY);
2406 if (xParentForm.is())
2407 {
2408 try
2409 {
2410 Reference< XRowSetApproveBroadcaster > xParentApprBroadcast( xParentForm, UNO_QUERY_THROW );
2411 xParentApprBroadcast->removeRowSetApproveListener( this );
2412
2413 Reference< XLoadable > xParentLoadable( xParentForm, UNO_QUERY_THROW );
2414 xParentLoadable->removeLoadListener( this );
2415
2416 Reference< XPropertySet > xParentProperties( xParentForm, UNO_QUERY_THROW );
2417 xParentProperties->removePropertyChangeListener( PROPERTY_ISNEW, this );
2418 }
2419 catch( const Exception& )
2420 {
2421 DBG_UNHANDLED_EXCEPTION();
2422 }
2423 }
2424
2425 OFormComponents::setParent(Parent);
2426
2427 xParentForm.set(getParent(), UNO_QUERY);
2428 if ( xParentForm.is() )
2429 {
2430 try
2431 {
2432 Reference< XRowSetApproveBroadcaster > xParentApprBroadcast( xParentForm, UNO_QUERY_THROW );
2433 xParentApprBroadcast->addRowSetApproveListener( this );
2434
2435 Reference< XLoadable > xParentLoadable( xParentForm, UNO_QUERY_THROW );
2436 xParentLoadable->addLoadListener( this );
2437
2438 Reference< XPropertySet > xParentProperties( xParentForm, UNO_QUERY_THROW );
2439 xParentProperties->addPropertyChangeListener( PROPERTY_ISNEW, this );
2440 }
2441 catch( const Exception& )
2442 {
2443 DBG_UNHANDLED_EXCEPTION();
2444 }
2445 }
2446
2447 Reference< XPropertySet > xAggregateProperties( m_xAggregateSet );
2448 aGuard.clear();
2449 // <----- SYNCHRONIZED
2450
2451 Reference< XConnection > xOuterConnection;
2452 sal_Bool bIsEmbedded = ::dbtools::isEmbeddedInDatabase( Parent, xOuterConnection );
2453
2454 if ( bIsEmbedded )
2455 xAggregateProperties->setPropertyValue( PROPERTY_DATASOURCE, makeAny( ::rtl::OUString() ) );
2456 }
2457
2458 //==============================================================================
2459 // smartXTabControllerModel
2460 //------------------------------------------------------------------------------
getGroupControl()2461 sal_Bool SAL_CALL ODatabaseForm::getGroupControl() throw(com::sun::star::uno::RuntimeException)
2462 {
2463 ::osl::ResettableMutexGuard aGuard(m_aMutex);
2464
2465 // Sollen Controls in einer TabOrder gruppe zusammengefasst werden?
2466 if (m_aCycle.hasValue())
2467 {
2468 sal_Int32 nCycle = 0;
2469 ::cppu::enum2int(nCycle, m_aCycle);
2470 return nCycle != TabulatorCycle_PAGE;
2471 }
2472
2473 if (isLoaded() && getConnection().is())
2474 return sal_True;
2475
2476 return sal_False;
2477 }
2478
2479 //------------------------------------------------------------------------------
setControlModels(const Sequence<Reference<XControlModel>> & rControls)2480 void SAL_CALL ODatabaseForm::setControlModels(const Sequence<Reference<XControlModel> >& rControls) throw( RuntimeException )
2481 {
2482 ::osl::ResettableMutexGuard aGuard(m_aMutex);
2483
2484 // TabIndex in der Reihenfolge der Sequence setzen
2485 const Reference<XControlModel>* pControls = rControls.getConstArray();
2486 sal_Int16 nTabIndex = 1;
2487 sal_Int32 nCount = getCount();
2488 sal_Int32 nNewCount = rControls.getLength();
2489
2490 // HiddenControls und Formulare werden nicht aufgefuehrt
2491 if (nNewCount <= nCount)
2492 {
2493 Any aElement;
2494 for (sal_Int32 i=0; i < nNewCount; ++i, ++pControls)
2495 {
2496 Reference<XFormComponent> xComp(*pControls, UNO_QUERY);
2497 if (xComp.is())
2498 {
2499 // suchen der Componente in der Liste
2500 for (sal_Int32 j = 0; j < nCount; ++j)
2501 {
2502 Reference<XFormComponent> xElement;
2503 ::cppu::extractInterface(xElement, getByIndex(j));
2504 if (xComp == xElement)
2505 {
2506 Reference<XPropertySet> xSet(xComp, UNO_QUERY);
2507 if (xSet.is() && hasProperty(PROPERTY_TABINDEX, xSet))
2508 xSet->setPropertyValue( PROPERTY_TABINDEX, makeAny(nTabIndex++) );
2509 break;
2510 }
2511 }
2512 }
2513 }
2514 }
2515 }
2516
2517 //------------------------------------------------------------------------------
getControlModels()2518 Sequence<Reference<XControlModel> > SAL_CALL ODatabaseForm::getControlModels() throw( RuntimeException )
2519 {
2520 ::osl::MutexGuard aGuard(m_aMutex);
2521 return m_pGroupManager->getControlModels();
2522 }
2523
2524 //------------------------------------------------------------------------------
setGroup(const Sequence<Reference<XControlModel>> & _rGroup,const::rtl::OUString & Name)2525 void SAL_CALL ODatabaseForm::setGroup( const Sequence<Reference<XControlModel> >& _rGroup, const ::rtl::OUString& Name ) throw( RuntimeException )
2526 {
2527 ::osl::MutexGuard aGuard(m_aMutex);
2528
2529 // Die Controls werden gruppiert, indem ihr Name dem Namen des ersten
2530 // Controls der Sequenz angepasst wird
2531 const Reference<XControlModel>* pControls = _rGroup.getConstArray();
2532 Reference< XPropertySet > xSet;
2533 ::rtl::OUString sGroupName( Name );
2534
2535 for( sal_Int32 i=0; i<_rGroup.getLength(); ++i, ++pControls )
2536 {
2537 xSet = xSet.query( *pControls );
2538 if ( !xSet.is() )
2539 {
2540 // can't throw an exception other than a RuntimeException (which would not be appropriate),
2541 // so we ignore (and only assert) this
2542 OSL_ENSURE( sal_False, "ODatabaseForm::setGroup: invalid arguments!" );
2543 continue;
2544 }
2545
2546 if (!sGroupName.getLength())
2547 xSet->getPropertyValue(PROPERTY_NAME) >>= sGroupName;
2548 else
2549 xSet->setPropertyValue(PROPERTY_NAME, makeAny(sGroupName));
2550 }
2551 }
2552
2553 //------------------------------------------------------------------------------
getGroupCount()2554 sal_Int32 SAL_CALL ODatabaseForm::getGroupCount() throw( RuntimeException )
2555 {
2556 ::osl::MutexGuard aGuard(m_aMutex);
2557 return m_pGroupManager->getGroupCount();
2558 }
2559
2560 //------------------------------------------------------------------------------
getGroup(sal_Int32 nGroup,Sequence<Reference<XControlModel>> & _rGroup,::rtl::OUString & _rName)2561 void SAL_CALL ODatabaseForm::getGroup( sal_Int32 nGroup, Sequence<Reference<XControlModel> >& _rGroup, ::rtl::OUString& _rName ) throw( RuntimeException )
2562 {
2563 ::osl::MutexGuard aGuard(m_aMutex);
2564 _rGroup.realloc(0);
2565 _rName = ::rtl::OUString();
2566
2567 if ((nGroup < 0) || (nGroup >= m_pGroupManager->getGroupCount()))
2568 return;
2569 m_pGroupManager->getGroup( nGroup, _rGroup, _rName );
2570 }
2571
2572 //------------------------------------------------------------------------------
getGroupByName(const::rtl::OUString & Name,Sequence<Reference<XControlModel>> & _rGroup)2573 void SAL_CALL ODatabaseForm::getGroupByName(const ::rtl::OUString& Name, Sequence< Reference<XControlModel> >& _rGroup) throw( RuntimeException )
2574 {
2575 ::osl::MutexGuard aGuard(m_aMutex);
2576 _rGroup.realloc(0);
2577 m_pGroupManager->getGroupByName( Name, _rGroup );
2578 }
2579
2580 //==============================================================================
2581 // com::sun::star::lang::XEventListener
2582 //------------------------------------------------------------------------------
disposing(const EventObject & Source)2583 void SAL_CALL ODatabaseForm::disposing(const EventObject& Source) throw( RuntimeException )
2584 {
2585 // does the call come from the connection which we are sharing with our parent?
2586 if ( isSharingConnection() )
2587 {
2588 Reference< XConnection > xConnSource( Source.Source, UNO_QUERY );
2589 if ( xConnSource.is() )
2590 {
2591 #if OSL_DEBUG_LEVEL > 0
2592 Reference< XConnection > xActiveConn;
2593 m_xAggregateSet->getPropertyValue( PROPERTY_ACTIVE_CONNECTION ) >>= xActiveConn;
2594 OSL_ENSURE( xActiveConn.get() == xConnSource.get(), "ODatabaseForm::disposing: where did this come from?" );
2595 // there should be exactly one XConnection object we're listening at - our aggregate connection
2596 #endif
2597 disposingSharedConnection( xConnSource );
2598 }
2599 }
2600
2601 OInterfaceContainer::disposing(Source);
2602
2603 // does the disposing come from the aggregate ?
2604 if (m_xAggregate.is())
2605 { // no -> forward it
2606 com::sun::star::uno::Reference<com::sun::star::lang::XEventListener> xListener;
2607 if (query_aggregation(m_xAggregate, xListener))
2608 xListener->disposing(Source);
2609 }
2610 }
2611
2612 //------------------------------------------------------------------------------
impl_createLoadTimer()2613 void ODatabaseForm::impl_createLoadTimer()
2614 {
2615 OSL_PRECOND( m_pLoadTimer == NULL, "ODatabaseForm::impl_createLoadTimer: timer already exists!" );
2616 m_pLoadTimer = new Timer();
2617 m_pLoadTimer->SetTimeout(100);
2618 m_pLoadTimer->SetTimeoutHdl(LINK(this,ODatabaseForm,OnTimeout));
2619 }
2620
2621 //==============================================================================
2622 // com::sun::star::form::XLoadListener
2623 //------------------------------------------------------------------------------
loaded(const EventObject &)2624 void SAL_CALL ODatabaseForm::loaded(const EventObject& /*aEvent*/) throw( RuntimeException )
2625 {
2626 {
2627 ::osl::MutexGuard aGuard( m_aMutex );
2628 Reference< XRowSet > xParentRowSet( m_xParent, UNO_QUERY_THROW );
2629 xParentRowSet->addRowSetListener( this );
2630
2631 impl_createLoadTimer();
2632 }
2633
2634 load_impl( sal_True );
2635 }
2636
2637 //------------------------------------------------------------------------------
unloading(const EventObject &)2638 void SAL_CALL ODatabaseForm::unloading(const EventObject& /*aEvent*/) throw( RuntimeException )
2639 {
2640 {
2641 // now stop the rowset listening if we are a subform
2642 ::osl::MutexGuard aGuard( m_aMutex );
2643
2644 if ( m_pLoadTimer && m_pLoadTimer->IsActive() )
2645 m_pLoadTimer->Stop();
2646 DELETEZ( m_pLoadTimer );
2647
2648 Reference< XRowSet > xParentRowSet( m_xParent, UNO_QUERY_THROW );
2649 xParentRowSet->removeRowSetListener( this );
2650 }
2651
2652 unload();
2653 }
2654
2655 //------------------------------------------------------------------------------
unloaded(const EventObject &)2656 void SAL_CALL ODatabaseForm::unloaded(const EventObject& /*aEvent*/) throw( RuntimeException )
2657 {
2658 // nothing to do
2659 }
2660
2661 //------------------------------------------------------------------------------
reloading(const EventObject &)2662 void SAL_CALL ODatabaseForm::reloading(const EventObject& /*aEvent*/) throw( RuntimeException )
2663 {
2664 // now stop the rowset listening if we are a subform
2665 ::osl::MutexGuard aGuard(m_aMutex);
2666 Reference<XRowSet> xParentRowSet(m_xParent, UNO_QUERY);
2667 if (xParentRowSet.is())
2668 xParentRowSet->removeRowSetListener(this);
2669
2670 if (m_pLoadTimer && m_pLoadTimer->IsActive())
2671 m_pLoadTimer->Stop();
2672 }
2673
2674 //------------------------------------------------------------------------------
reloaded(const EventObject &)2675 void SAL_CALL ODatabaseForm::reloaded(const EventObject& /*aEvent*/) throw( RuntimeException )
2676 {
2677 reload_impl(sal_True);
2678 {
2679 ::osl::MutexGuard aGuard(m_aMutex);
2680 Reference<XRowSet> xParentRowSet(m_xParent, UNO_QUERY);
2681 if (xParentRowSet.is())
2682 xParentRowSet->addRowSetListener(this);
2683 }
2684 }
2685
2686 //------------------------------------------------------------------------------
IMPL_LINK(ODatabaseForm,OnTimeout,void *,EMPTYARG)2687 IMPL_LINK( ODatabaseForm, OnTimeout, void*, EMPTYARG )
2688 {
2689 reload_impl(sal_True);
2690 return 1;
2691 }
2692
2693 //==============================================================================
2694 // com::sun::star::form::XLoadable
2695 //------------------------------------------------------------------------------
load()2696 void SAL_CALL ODatabaseForm::load() throw( RuntimeException )
2697 {
2698 load_impl(sal_False);
2699 }
2700
2701 //------------------------------------------------------------------------------
canShareConnection(const Reference<XPropertySet> & _rxParentProps)2702 sal_Bool ODatabaseForm::canShareConnection( const Reference< XPropertySet >& _rxParentProps )
2703 {
2704 // our own data source
2705 ::rtl::OUString sOwnDatasource;
2706 m_xAggregateSet->getPropertyValue( PROPERTY_DATASOURCE ) >>= sOwnDatasource;
2707
2708 // our parents data source
2709 ::rtl::OUString sParentDataSource;
2710 OSL_ENSURE( _rxParentProps.is() && _rxParentProps->getPropertySetInfo().is() && _rxParentProps->getPropertySetInfo()->hasPropertyByName( PROPERTY_DATASOURCE ),
2711 "ODatabaseForm::doShareConnection: invalid parent form!" );
2712 if ( _rxParentProps.is() )
2713 _rxParentProps->getPropertyValue( PROPERTY_DATASOURCE ) >>= sParentDataSource;
2714
2715 sal_Bool bCanShareConnection = sal_False;
2716
2717 // both rowsets share are connected to the same data source
2718 if ( sParentDataSource == sOwnDatasource )
2719 {
2720 if ( 0 != sParentDataSource.getLength() )
2721 // and it's really a data source name (not empty)
2722 bCanShareConnection = sal_True;
2723 else
2724 { // the data source name is empty
2725 // -> ook for the URL
2726 ::rtl::OUString sParentURL;
2727 ::rtl::OUString sMyURL;
2728 _rxParentProps->getPropertyValue( PROPERTY_URL ) >>= sParentURL;
2729 m_xAggregateSet->getPropertyValue( PROPERTY_URL ) >>= sMyURL;
2730
2731 bCanShareConnection = (sParentURL == sMyURL);
2732 }
2733 }
2734
2735 if ( bCanShareConnection )
2736 {
2737 // check for the user/password
2738
2739 // take the user property on the rowset (if any) into account
2740 ::rtl::OUString sParentUser, sParentPwd;
2741 _rxParentProps->getPropertyValue( PROPERTY_USER ) >>= sParentUser;
2742 _rxParentProps->getPropertyValue( PROPERTY_PASSWORD ) >>= sParentPwd;
2743
2744 ::rtl::OUString sMyUser, sMyPwd;
2745 m_xAggregateSet->getPropertyValue( PROPERTY_USER ) >>= sMyUser;
2746 m_xAggregateSet->getPropertyValue( PROPERTY_PASSWORD ) >>= sMyPwd;
2747
2748 bCanShareConnection =
2749 ( sParentUser == sMyUser )
2750 && ( sParentPwd == sMyPwd );
2751 }
2752
2753 return bCanShareConnection;
2754 }
2755
2756 //------------------------------------------------------------------------------
doShareConnection(const Reference<XPropertySet> & _rxParentProps)2757 void ODatabaseForm::doShareConnection( const Reference< XPropertySet >& _rxParentProps )
2758 {
2759 // get the conneciton of the parent
2760 Reference< XConnection > xParentConn;
2761 _rxParentProps->getPropertyValue( PROPERTY_ACTIVE_CONNECTION ) >>= xParentConn;
2762 OSL_ENSURE( xParentConn.is(), "ODatabaseForm::doShareConnection: we're a valid sub-form, but the parent has no connection?!" );
2763
2764 if ( xParentConn.is() )
2765 {
2766 // add as dispose listener to the connection
2767 Reference< XComponent > xParentConnComp( xParentConn, UNO_QUERY );
2768 OSL_ENSURE( xParentConnComp.is(), "ODatabaseForm::doShareConnection: invalid connection!" );
2769 xParentConnComp->addEventListener( static_cast< XLoadListener* >( this ) );
2770
2771 // forward the connection to our own aggreagte
2772 m_bForwardingConnection = sal_True;
2773 m_xAggregateSet->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, makeAny( xParentConn ) );
2774 m_bForwardingConnection = sal_False;
2775
2776 m_bSharingConnection = sal_True;
2777 }
2778 else
2779 m_bSharingConnection = sal_False;
2780 }
2781
2782 //------------------------------------------------------------------------------
disposingSharedConnection(const Reference<XConnection> &)2783 void ODatabaseForm::disposingSharedConnection( const Reference< XConnection >& /*_rxConn*/ )
2784 {
2785 stopSharingConnection();
2786
2787 // TODO: we could think about whether or not to re-connect.
2788 unload( );
2789 }
2790
2791 //------------------------------------------------------------------------------
stopSharingConnection()2792 void ODatabaseForm::stopSharingConnection( )
2793 {
2794 OSL_ENSURE( m_bSharingConnection, "ODatabaseForm::stopSharingConnection: invalid call!" );
2795
2796 if ( m_bSharingConnection )
2797 {
2798 // get the connection
2799 Reference< XConnection > xSharedConn;
2800 m_xAggregateSet->getPropertyValue( PROPERTY_ACTIVE_CONNECTION ) >>= xSharedConn;
2801 OSL_ENSURE( xSharedConn.is(), "ODatabaseForm::stopSharingConnection: there's no conn!" );
2802
2803 // remove ourself as event listener
2804 Reference< XComponent > xSharedConnComp( xSharedConn, UNO_QUERY );
2805 if ( xSharedConnComp.is() )
2806 xSharedConnComp->removeEventListener( static_cast< XLoadListener* >( this ) );
2807
2808 // no need to dispose the conn: we're not the owner, this is our parent
2809 // (in addition, this method may be called if the connection is beeing disposed while we use it)
2810
2811 // reset the property
2812 xSharedConn.clear();
2813 m_bForwardingConnection = sal_True;
2814 m_xAggregateSet->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, makeAny( xSharedConn ) );
2815 m_bForwardingConnection = sal_False;
2816
2817 // reset the flag
2818 m_bSharingConnection = sal_False;
2819 }
2820 }
2821
2822 //------------------------------------------------------------------------------
implEnsureConnection()2823 sal_Bool ODatabaseForm::implEnsureConnection()
2824 {
2825 try
2826 {
2827 if ( getConnection( ).is() )
2828 // if our aggregate already has a connection, nothing needs to be done about it
2829 return sal_True;
2830
2831 // see whether we're an embedded form
2832 Reference< XConnection > xOuterConnection;
2833 if ( ::dbtools::isEmbeddedInDatabase( getParent(), xOuterConnection ) )
2834 {
2835 m_xAggregateSet->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, makeAny( xOuterConnection ) );
2836 return xOuterConnection.is();
2837 }
2838
2839 m_bSharingConnection = sal_False;
2840
2841 // if we're a sub form, we try to re-use the connection of our parent
2842 if (m_bSubForm)
2843 {
2844 OSL_ENSURE( Reference< XForm >( getParent(), UNO_QUERY ).is(),
2845 "ODatabaseForm::implEnsureConnection: m_bSubForm is TRUE, but the parent is no form?" );
2846
2847 Reference< XPropertySet > xParentProps( getParent(), UNO_QUERY );
2848
2849 // can we re-use (aka share) the connection of the parent?
2850 if ( canShareConnection( xParentProps ) )
2851 {
2852 // yep -> do it
2853 doShareConnection( xParentProps );
2854 // success?
2855 if ( m_bSharingConnection )
2856 // yes -> outta here
2857 return sal_True;
2858 }
2859 }
2860
2861 if (m_xAggregateSet.is())
2862 {
2863 Reference< XConnection > xConnection = connectRowset(
2864 Reference<XRowSet> (m_xAggregate, UNO_QUERY),
2865 m_xServiceFactory,
2866 sal_True // set a calculated connection as ActiveConnection
2867 );
2868 return xConnection.is();
2869 }
2870 }
2871 catch(SQLException& eDB)
2872 {
2873 onError(eDB, FRM_RES_STRING(RID_STR_CONNECTERROR));
2874 }
2875 catch( Exception )
2876 {
2877 DBG_UNHANDLED_EXCEPTION();
2878 }
2879
2880 return sal_False;
2881 }
2882
2883 //------------------------------------------------------------------------------
load_impl(sal_Bool bCausedByParentForm,sal_Bool bMoveToFirst,const Reference<XInteractionHandler> & _rxCompletionHandler)2884 void ODatabaseForm::load_impl(sal_Bool bCausedByParentForm, sal_Bool bMoveToFirst, const Reference< XInteractionHandler >& _rxCompletionHandler ) throw( RuntimeException )
2885 {
2886 ::osl::ResettableMutexGuard aGuard(m_aMutex);
2887
2888 // are we already loaded?
2889 if (isLoaded())
2890 return;
2891
2892 m_bSubForm = bCausedByParentForm;
2893
2894 // if we don't have a connection, we are not intended to be a database form or the aggregate was not able
2895 // to establish a connection
2896 sal_Bool bConnected = implEnsureConnection();
2897
2898 // we don't have to execute if we do not have a command to execute
2899 sal_Bool bExecute = bConnected && m_xAggregateSet.is() && getString(m_xAggregateSet->getPropertyValue(PROPERTY_COMMAND)).getLength();
2900
2901 // a database form always uses caching
2902 // we use starting fetchsize with at least 10 rows
2903 if (bConnected)
2904 m_xAggregateSet->setPropertyValue(PROPERTY_FETCHSIZE, makeAny((sal_Int32)40));
2905
2906 // if we're loaded as sub form we got a "rowSetChanged" from the parent rowset _before_ we got the "loaded"
2907 // so we don't need to execute the statement again, this was already done
2908 // (and there were no relevant changes between these two listener calls, the "load" of a form is quite an
2909 // atomar operation.)
2910
2911 sal_Bool bSuccess = sal_False;
2912 if (bExecute)
2913 {
2914 m_sCurrentErrorContext = FRM_RES_STRING(RID_ERR_LOADING_FORM);
2915 bSuccess = executeRowSet(aGuard, bMoveToFirst, _rxCompletionHandler);
2916 }
2917
2918 if (bSuccess)
2919 {
2920 m_bLoaded = sal_True;
2921 aGuard.clear();
2922 EventObject aEvt(static_cast<XWeak*>(this));
2923 m_aLoadListeners.notifyEach( &XLoadListener::loaded, aEvt );
2924
2925 // if we are on the insert row, we have to reset all controls
2926 // to set the default values
2927 if (bExecute && getBOOL(m_xAggregateSet->getPropertyValue(PROPERTY_ISNEW)))
2928 reset();
2929 }
2930 }
2931
2932 //------------------------------------------------------------------------------
unload()2933 void SAL_CALL ODatabaseForm::unload() throw( RuntimeException )
2934 {
2935 ::osl::ResettableMutexGuard aGuard(m_aMutex);
2936 if (!isLoaded())
2937 return;
2938
2939 DELETEZ(m_pLoadTimer);
2940
2941 aGuard.clear();
2942 EventObject aEvt(static_cast<XWeak*>(this));
2943 m_aLoadListeners.notifyEach( &XLoadListener::unloading, aEvt );
2944
2945 if (m_xAggregateAsRowSet.is())
2946 {
2947 // we may have reset the InsertOnly property on the aggregate - restore it
2948 restoreInsertOnlyState( );
2949
2950 // clear the parameters if there are any
2951 invlidateParameters();
2952
2953 try
2954 {
2955 // close the aggregate
2956 Reference<XCloseable> xCloseable;
2957 query_aggregation( m_xAggregate, xCloseable);
2958 aGuard.clear();
2959 if (xCloseable.is())
2960 xCloseable->close();
2961 }
2962 catch( const SQLException& e )
2963 {
2964 (void)e;
2965 }
2966 aGuard.reset();
2967 }
2968
2969 m_bLoaded = sal_False;
2970
2971 // if the connection we used while we were loaded is only shared with our parent, we
2972 // reset it
2973 if ( isSharingConnection() )
2974 stopSharingConnection();
2975
2976 aGuard.clear();
2977 m_aLoadListeners.notifyEach( &XLoadListener::unloaded, aEvt );
2978 }
2979
2980 //------------------------------------------------------------------------------
reload()2981 void SAL_CALL ODatabaseForm::reload() throw( RuntimeException )
2982 {
2983 reload_impl(sal_True);
2984 }
2985
2986 //------------------------------------------------------------------------------
reload_impl(sal_Bool bMoveToFirst,const Reference<XInteractionHandler> & _rxCompletionHandler)2987 void ODatabaseForm::reload_impl(sal_Bool bMoveToFirst, const Reference< XInteractionHandler >& _rxCompletionHandler ) throw( RuntimeException )
2988 {
2989 ::osl::ResettableMutexGuard aGuard(m_aMutex);
2990 if (!isLoaded())
2991 return;
2992
2993 DocumentModifyGuard aModifyGuard( *this );
2994 // ensures the document is not marked as "modified" just because we change some control's content during
2995 // reloading ...
2996
2997 EventObject aEvent(static_cast<XWeak*>(this));
2998 {
2999 // only if there is no approve listener we can post the event at this time
3000 // otherwise see approveRowsetChange
3001 // the aprrovement is done by the aggregate
3002 if (!m_aRowSetApproveListeners.getLength())
3003 {
3004 ::cppu::OInterfaceIteratorHelper aIter(m_aLoadListeners);
3005 aGuard.clear();
3006
3007 while (aIter.hasMoreElements())
3008 ((XLoadListener*)aIter.next())->reloading(aEvent);
3009
3010 aGuard.reset();
3011 }
3012 }
3013
3014 sal_Bool bSuccess = sal_True;
3015 try
3016 {
3017 m_sCurrentErrorContext = FRM_RES_STRING(RID_ERR_REFRESHING_FORM);
3018 bSuccess = executeRowSet(aGuard, bMoveToFirst, _rxCompletionHandler);
3019 }
3020 catch( const SQLException& e )
3021 {
3022 DBG_ERROR("ODatabaseForm::reload_impl : shouldn't executeRowSet catch this exception?");
3023 (void)e;
3024 }
3025
3026 if (bSuccess)
3027 {
3028 ::cppu::OInterfaceIteratorHelper aIter(m_aLoadListeners);
3029 aGuard.clear();
3030 while (aIter.hasMoreElements())
3031 ((XLoadListener*)aIter.next())->reloaded(aEvent);
3032
3033 // if we are on the insert row, we have to reset all controls
3034 // to set the default values
3035 if (getBOOL(m_xAggregateSet->getPropertyValue(PROPERTY_ISNEW)))
3036 reset();
3037 }
3038 else
3039 m_bLoaded = sal_False;
3040 }
3041
3042 //------------------------------------------------------------------------------
isLoaded()3043 sal_Bool SAL_CALL ODatabaseForm::isLoaded() throw( RuntimeException )
3044 {
3045 return m_bLoaded;
3046 }
3047
3048 //------------------------------------------------------------------------------
addLoadListener(const Reference<XLoadListener> & aListener)3049 void SAL_CALL ODatabaseForm::addLoadListener(const Reference<XLoadListener>& aListener) throw( RuntimeException )
3050 {
3051 m_aLoadListeners.addInterface(aListener);
3052 }
3053
3054 //------------------------------------------------------------------------------
removeLoadListener(const Reference<XLoadListener> & aListener)3055 void SAL_CALL ODatabaseForm::removeLoadListener(const Reference<XLoadListener>& aListener) throw( RuntimeException )
3056 {
3057 m_aLoadListeners.removeInterface(aListener);
3058 }
3059
3060 //==============================================================================
3061 // com::sun::star::sdbc::XCloseable
3062 //==============================================================================
close()3063 void SAL_CALL ODatabaseForm::close() throw( SQLException, RuntimeException )
3064 {
3065 // unload will close the aggregate
3066 unload();
3067 }
3068
3069 //==============================================================================
3070 // com::sun::star::sdbc::XRowSetListener
3071 //------------------------------------------------------------------------------
cursorMoved(const EventObject &)3072 void SAL_CALL ODatabaseForm::cursorMoved(const EventObject& /*event*/) throw( RuntimeException )
3073 {
3074 // reload the subform with the new parameters of the parent
3075 // do this handling delayed to provide of execute too many SQL Statements
3076 ::osl::ResettableMutexGuard aGuard(m_aMutex);
3077
3078 DBG_ASSERT( m_pLoadTimer, "ODatabaseForm::cursorMoved: how can this happen?!" );
3079 if ( !m_pLoadTimer )
3080 impl_createLoadTimer();
3081
3082 if ( m_pLoadTimer->IsActive() )
3083 m_pLoadTimer->Stop();
3084
3085 // and start the timer again
3086 m_pLoadTimer->Start();
3087 }
3088
3089 //------------------------------------------------------------------------------
rowChanged(const EventObject &)3090 void SAL_CALL ODatabaseForm::rowChanged(const EventObject& /*event*/) throw( RuntimeException )
3091 {
3092 // ignore it
3093 }
3094
3095 //------------------------------------------------------------------------------
rowSetChanged(const EventObject &)3096 void SAL_CALL ODatabaseForm::rowSetChanged(const EventObject& /*event*/) throw( RuntimeException )
3097 {
3098 // not interested in :
3099 // if our parent is an ODatabaseForm, too, then after this rowSetChanged we'll get a "reloaded"
3100 // or a "loaded" event.
3101 // If somebody gave us another parent which is an XRowSet but doesn't handle an execute as
3102 // "load" respectivly "reload" ... can't do anything ....
3103 }
3104
3105 //------------------------------------------------------------------------------
impl_approveRowChange_throw(const EventObject & _rEvent,const bool _bAllowSQLException,::osl::ClearableMutexGuard & _rGuard)3106 bool ODatabaseForm::impl_approveRowChange_throw( const EventObject& _rEvent, const bool _bAllowSQLException,
3107 ::osl::ClearableMutexGuard& _rGuard )
3108 {
3109 ::cppu::OInterfaceIteratorHelper aIter( m_aRowSetApproveListeners );
3110 _rGuard.clear();
3111 while ( aIter.hasMoreElements() )
3112 {
3113 Reference< XRowSetApproveListener > xListener( static_cast< XRowSetApproveListener* >( aIter.next() ) );
3114 if ( !xListener.is() )
3115 continue;
3116
3117 try
3118 {
3119 if ( !xListener->approveRowSetChange( _rEvent ) )
3120 return false;
3121 }
3122 catch ( const DisposedException& e )
3123 {
3124 if ( e.Context == xListener )
3125 aIter.remove();
3126 }
3127 catch ( const RuntimeException& ) { throw; }
3128 catch ( const SQLException& )
3129 {
3130 if ( _bAllowSQLException )
3131 throw;
3132 DBG_UNHANDLED_EXCEPTION();
3133 }
3134 catch ( const Exception& )
3135 {
3136 DBG_UNHANDLED_EXCEPTION();
3137 }
3138 }
3139 return true;
3140 }
3141
3142 //------------------------------------------------------------------------------
approveCursorMove(const EventObject & event)3143 sal_Bool SAL_CALL ODatabaseForm::approveCursorMove(const EventObject& event) throw( RuntimeException )
3144 {
3145 // is our aggregate calling?
3146 if (event.Source == InterfaceRef(static_cast<XWeak*>(this)))
3147 {
3148 // Our aggregate doesn't have any ApproveRowSetListeners (expect ourself), as we re-routed the queryInterface
3149 // for XRowSetApproveBroadcaster-interface.
3150 // So we have to multiplex this approve request.
3151 ::cppu::OInterfaceIteratorHelper aIter( m_aRowSetApproveListeners );
3152 while ( aIter.hasMoreElements() )
3153 {
3154 Reference< XRowSetApproveListener > xListener( static_cast< XRowSetApproveListener* >( aIter.next() ) );
3155 if ( !xListener.is() )
3156 continue;
3157
3158 try
3159 {
3160 if ( !xListener->approveCursorMove( event ) )
3161 return sal_False;
3162 }
3163 catch ( const DisposedException& e )
3164 {
3165 if ( e.Context == xListener )
3166 aIter.remove();
3167 }
3168 catch ( const RuntimeException& ) { throw; }
3169 catch ( const Exception& )
3170 {
3171 DBG_UNHANDLED_EXCEPTION();
3172 }
3173 }
3174 return true;
3175 }
3176 else
3177 {
3178 // this is a call from our parent ...
3179 // a parent's cursor move will result in a re-execute of our own row-set, so we have to
3180 // ask our own RowSetChangesListeners, too
3181 ::osl::ClearableMutexGuard aGuard( m_aMutex );
3182 if ( !impl_approveRowChange_throw( event, false, aGuard ) )
3183 return sal_False;
3184 }
3185 return sal_True;
3186 }
3187
3188 //------------------------------------------------------------------------------
approveRowChange(const RowChangeEvent & event)3189 sal_Bool SAL_CALL ODatabaseForm::approveRowChange(const RowChangeEvent& event) throw( RuntimeException )
3190 {
3191 // is our aggregate calling?
3192 if (event.Source == InterfaceRef(static_cast<XWeak*>(this)))
3193 {
3194 // Our aggregate doesn't have any ApproveRowSetListeners (expect ourself), as we re-routed the queryInterface
3195 // for XRowSetApproveBroadcaster-interface.
3196 // So we have to multiplex this approve request.
3197 ::cppu::OInterfaceIteratorHelper aIter( m_aRowSetApproveListeners );
3198 while ( aIter.hasMoreElements() )
3199 {
3200 Reference< XRowSetApproveListener > xListener( static_cast< XRowSetApproveListener* >( aIter.next() ) );
3201 if ( !xListener.is() )
3202 continue;
3203
3204 try
3205 {
3206 if ( !xListener->approveRowChange( event ) )
3207 return false;
3208 }
3209 catch ( const DisposedException& e )
3210 {
3211 if ( e.Context == xListener )
3212 aIter.remove();
3213 }
3214 catch ( const RuntimeException& ) { throw; }
3215 catch ( const Exception& )
3216 {
3217 DBG_UNHANDLED_EXCEPTION();
3218 }
3219 }
3220 return true;
3221 }
3222 return sal_True;
3223 }
3224
3225 //------------------------------------------------------------------------------
approveRowSetChange(const EventObject & event)3226 sal_Bool SAL_CALL ODatabaseForm::approveRowSetChange(const EventObject& event) throw( RuntimeException )
3227 {
3228 if (event.Source == InterfaceRef(static_cast<XWeak*>(this))) // ignore our aggregate as we handle this approve ourself
3229 {
3230 ::osl::ClearableMutexGuard aGuard( m_aMutex );
3231 bool bWasLoaded = isLoaded();
3232 if ( !impl_approveRowChange_throw( event, false, aGuard ) )
3233 return sal_False;
3234
3235 if ( bWasLoaded )
3236 {
3237 m_aLoadListeners.notifyEach( &XLoadListener::reloading, event );
3238 }
3239 }
3240 else
3241 {
3242 // this is a call from our parent ...
3243 // a parent's cursor move will result in a re-execute of our own row-set, so we have to
3244 // ask our own RowSetChangesListeners, too
3245 ::osl::ClearableMutexGuard aGuard( m_aMutex );
3246 if ( !impl_approveRowChange_throw( event, false, aGuard ) )
3247 return sal_False;
3248 }
3249 return sal_True;
3250 }
3251
3252 //==============================================================================
3253 // com::sun::star::sdb::XRowSetApproveBroadcaster
3254 //------------------------------------------------------------------------------
addRowSetApproveListener(const Reference<XRowSetApproveListener> & _rListener)3255 void SAL_CALL ODatabaseForm::addRowSetApproveListener(const Reference<XRowSetApproveListener>& _rListener) throw( RuntimeException )
3256 {
3257 ::osl::ResettableMutexGuard aGuard(m_aMutex);
3258 m_aRowSetApproveListeners.addInterface(_rListener);
3259
3260 // do we have to multiplex ?
3261 if (m_aRowSetApproveListeners.getLength() == 1)
3262 {
3263 Reference<XRowSetApproveBroadcaster> xBroadcaster;
3264 if (query_aggregation( m_xAggregate, xBroadcaster))
3265 {
3266 Reference<XRowSetApproveListener> xListener((XRowSetApproveListener*)this);
3267 xBroadcaster->addRowSetApproveListener(xListener);
3268 }
3269 }
3270 }
3271
3272 //------------------------------------------------------------------------------
removeRowSetApproveListener(const Reference<XRowSetApproveListener> & _rListener)3273 void SAL_CALL ODatabaseForm::removeRowSetApproveListener(const Reference<XRowSetApproveListener>& _rListener) throw( RuntimeException )
3274 {
3275 ::osl::ResettableMutexGuard aGuard(m_aMutex);
3276 // do we have to remove the multiplex ?
3277 m_aRowSetApproveListeners.removeInterface(_rListener);
3278 if ( m_aRowSetApproveListeners.getLength() == 0 )
3279 {
3280 Reference<XRowSetApproveBroadcaster> xBroadcaster;
3281 if (query_aggregation( m_xAggregate, xBroadcaster))
3282 {
3283 Reference<XRowSetApproveListener> xListener((XRowSetApproveListener*)this);
3284 xBroadcaster->removeRowSetApproveListener(xListener);
3285 }
3286 }
3287 }
3288
3289 //==============================================================================
3290 // com::sun:star::form::XDatabaseParameterBroadcaster
3291 //------------------------------------------------------------------------------
addDatabaseParameterListener(const Reference<XDatabaseParameterListener> & _rListener)3292 void SAL_CALL ODatabaseForm::addDatabaseParameterListener(const Reference<XDatabaseParameterListener>& _rListener) throw( RuntimeException )
3293 {
3294 m_aParameterManager.addParameterListener( _rListener );
3295 }
3296 //------------------------------------------------------------------------------
removeDatabaseParameterListener(const Reference<XDatabaseParameterListener> & _rListener)3297 void SAL_CALL ODatabaseForm::removeDatabaseParameterListener(const Reference<XDatabaseParameterListener>& _rListener) throw( RuntimeException )
3298 {
3299 m_aParameterManager.removeParameterListener( _rListener );
3300 }
3301
3302 //------------------------------------------------------------------------------
addParameterListener(const Reference<XDatabaseParameterListener> & _rListener)3303 void SAL_CALL ODatabaseForm::addParameterListener(const Reference<XDatabaseParameterListener>& _rListener) throw( RuntimeException )
3304 {
3305 ODatabaseForm::addDatabaseParameterListener( _rListener );
3306 }
3307
3308 //------------------------------------------------------------------------------
removeParameterListener(const Reference<XDatabaseParameterListener> & _rListener)3309 void SAL_CALL ODatabaseForm::removeParameterListener(const Reference<XDatabaseParameterListener>& _rListener) throw( RuntimeException )
3310 {
3311 ODatabaseForm::removeDatabaseParameterListener( _rListener );
3312 }
3313
3314 //==============================================================================
3315 // com::sun::star::sdb::XCompletedExecution
3316 //------------------------------------------------------------------------------
executeWithCompletion(const Reference<XInteractionHandler> & _rxHandler)3317 void SAL_CALL ODatabaseForm::executeWithCompletion( const Reference< XInteractionHandler >& _rxHandler ) throw(SQLException, RuntimeException)
3318 {
3319 ::osl::ClearableMutexGuard aGuard(m_aMutex);
3320 // the difference between execute and load is, that we position on the first row in case of load
3321 // after execute we remain before the first row
3322 if (!isLoaded())
3323 {
3324 aGuard.clear();
3325 load_impl(sal_False, sal_False, _rxHandler);
3326 }
3327 else
3328 {
3329 EventObject event(static_cast< XWeak* >(this));
3330 if ( !impl_approveRowChange_throw( event, true, aGuard ) )
3331 return;
3332
3333 // we're loaded and somebody want's to execute ourself -> this means a reload
3334 reload_impl(sal_False, _rxHandler);
3335 }
3336 }
3337
3338 //==============================================================================
3339 // com::sun::star::sdbc::XRowSet
3340 //------------------------------------------------------------------------------
execute()3341 void SAL_CALL ODatabaseForm::execute() throw( SQLException, RuntimeException )
3342 {
3343 ::osl::ResettableMutexGuard aGuard(m_aMutex);
3344 // if somebody calls an execute and we're not loaded we reroute this call to our load method.
3345
3346 // the difference between execute and load is, that we position on the first row in case of load
3347 // after execute we remain before the first row
3348 if (!isLoaded())
3349 {
3350 aGuard.clear();
3351 load_impl(sal_False, sal_False);
3352 }
3353 else
3354 {
3355 EventObject event(static_cast< XWeak* >(this));
3356 if ( !impl_approveRowChange_throw( event, true, aGuard ) )
3357 return;
3358
3359 // we're loaded and somebody want's to execute ourself -> this means a reload
3360 reload_impl(sal_False);
3361 }
3362 }
3363
3364 //------------------------------------------------------------------------------
addRowSetListener(const Reference<XRowSetListener> & _rListener)3365 void SAL_CALL ODatabaseForm::addRowSetListener(const Reference<XRowSetListener>& _rListener) throw( RuntimeException )
3366 {
3367 if (m_xAggregateAsRowSet.is())
3368 m_xAggregateAsRowSet->addRowSetListener(_rListener);
3369 }
3370
3371 //------------------------------------------------------------------------------
removeRowSetListener(const Reference<XRowSetListener> & _rListener)3372 void SAL_CALL ODatabaseForm::removeRowSetListener(const Reference<XRowSetListener>& _rListener) throw( RuntimeException )
3373 {
3374 if (m_xAggregateAsRowSet.is())
3375 m_xAggregateAsRowSet->removeRowSetListener(_rListener);
3376 }
3377
3378 //==============================================================================
3379 // com::sun::star::sdbc::XResultSet
3380 //------------------------------------------------------------------------------
next()3381 sal_Bool SAL_CALL ODatabaseForm::next() throw( SQLException, RuntimeException )
3382 {
3383 return m_xAggregateAsRowSet->next();
3384 }
3385
3386 //------------------------------------------------------------------------------
isBeforeFirst()3387 sal_Bool SAL_CALL ODatabaseForm::isBeforeFirst() throw( SQLException, RuntimeException )
3388 {
3389 return m_xAggregateAsRowSet->isBeforeFirst();
3390 }
3391
3392 //------------------------------------------------------------------------------
isAfterLast()3393 sal_Bool SAL_CALL ODatabaseForm::isAfterLast() throw( SQLException, RuntimeException )
3394 {
3395 return m_xAggregateAsRowSet->isAfterLast();
3396 }
3397
3398 //------------------------------------------------------------------------------
isFirst()3399 sal_Bool SAL_CALL ODatabaseForm::isFirst() throw( SQLException, RuntimeException )
3400 {
3401 return m_xAggregateAsRowSet->isFirst();
3402 }
3403
3404 //------------------------------------------------------------------------------
isLast()3405 sal_Bool SAL_CALL ODatabaseForm::isLast() throw( SQLException, RuntimeException )
3406 {
3407 return m_xAggregateAsRowSet->isLast();
3408 }
3409
3410 //------------------------------------------------------------------------------
beforeFirst()3411 void SAL_CALL ODatabaseForm::beforeFirst() throw( SQLException, RuntimeException )
3412 {
3413 m_xAggregateAsRowSet->beforeFirst();
3414 }
3415
3416 //------------------------------------------------------------------------------
afterLast()3417 void SAL_CALL ODatabaseForm::afterLast() throw( SQLException, RuntimeException )
3418 {
3419 m_xAggregateAsRowSet->afterLast();
3420 }
3421
3422 //------------------------------------------------------------------------------
first()3423 sal_Bool SAL_CALL ODatabaseForm::first() throw( SQLException, RuntimeException )
3424 {
3425 return m_xAggregateAsRowSet->first();
3426 }
3427
3428 //------------------------------------------------------------------------------
last()3429 sal_Bool SAL_CALL ODatabaseForm::last() throw( SQLException, RuntimeException )
3430 {
3431 return m_xAggregateAsRowSet->last();
3432 }
3433
3434 //------------------------------------------------------------------------------
getRow()3435 sal_Int32 SAL_CALL ODatabaseForm::getRow() throw( SQLException, RuntimeException )
3436 {
3437 return m_xAggregateAsRowSet->getRow();
3438 }
3439
3440 //------------------------------------------------------------------------------
absolute(sal_Int32 row)3441 sal_Bool SAL_CALL ODatabaseForm::absolute(sal_Int32 row) throw( SQLException, RuntimeException )
3442 {
3443 return m_xAggregateAsRowSet->absolute(row);
3444 }
3445
3446 //------------------------------------------------------------------------------
relative(sal_Int32 rows)3447 sal_Bool SAL_CALL ODatabaseForm::relative(sal_Int32 rows) throw( SQLException, RuntimeException )
3448 {
3449 return m_xAggregateAsRowSet->relative(rows);
3450 }
3451
3452 //------------------------------------------------------------------------------
previous()3453 sal_Bool SAL_CALL ODatabaseForm::previous() throw( SQLException, RuntimeException )
3454 {
3455 return m_xAggregateAsRowSet->previous();
3456 }
3457
3458 //------------------------------------------------------------------------------
refreshRow()3459 void SAL_CALL ODatabaseForm::refreshRow() throw( SQLException, RuntimeException )
3460 {
3461 m_xAggregateAsRowSet->refreshRow();
3462 }
3463
3464 //------------------------------------------------------------------------------
rowUpdated()3465 sal_Bool SAL_CALL ODatabaseForm::rowUpdated() throw( SQLException, RuntimeException )
3466 {
3467 return m_xAggregateAsRowSet->rowUpdated();
3468 }
3469
3470 //------------------------------------------------------------------------------
rowInserted()3471 sal_Bool SAL_CALL ODatabaseForm::rowInserted() throw( SQLException, RuntimeException )
3472 {
3473 return m_xAggregateAsRowSet->rowInserted();
3474 }
3475
3476 //------------------------------------------------------------------------------
rowDeleted()3477 sal_Bool SAL_CALL ODatabaseForm::rowDeleted() throw( SQLException, RuntimeException )
3478 {
3479 return m_xAggregateAsRowSet->rowDeleted();
3480 }
3481
3482 //------------------------------------------------------------------------------
getStatement()3483 InterfaceRef SAL_CALL ODatabaseForm::getStatement() throw( SQLException, RuntimeException )
3484 {
3485 return m_xAggregateAsRowSet->getStatement();
3486 }
3487
3488 // com::sun::star::sdbc::XResultSetUpdate
3489 // exceptions during insert update and delete will be forwarded to the errorlistener
3490 //------------------------------------------------------------------------------
insertRow()3491 void SAL_CALL ODatabaseForm::insertRow() throw( SQLException, RuntimeException )
3492 {
3493 try
3494 {
3495 Reference<XResultSetUpdate> xUpdate;
3496 if (query_aggregation( m_xAggregate, xUpdate))
3497 xUpdate->insertRow();
3498 }
3499 catch( const RowSetVetoException& eVeto )
3500 {
3501 (void)eVeto;
3502 throw;
3503 }
3504 catch(SQLException& eDb)
3505 {
3506 onError(eDb, FRM_RES_STRING(RID_STR_ERR_INSERTRECORD));
3507 throw;
3508 }
3509 }
3510
3511 //------------------------------------------------------------------------------
updateRow()3512 void SAL_CALL ODatabaseForm::updateRow() throw( SQLException, RuntimeException )
3513 {
3514 try
3515 {
3516 Reference<XResultSetUpdate> xUpdate;
3517 if (query_aggregation( m_xAggregate, xUpdate))
3518 xUpdate->updateRow();
3519 }
3520 catch( const RowSetVetoException& eVeto )
3521 {
3522 (void)eVeto;
3523 throw;
3524 }
3525 catch(SQLException& eDb)
3526 {
3527 onError(eDb, FRM_RES_STRING(RID_STR_ERR_UPDATERECORD));
3528 throw;
3529 }
3530 }
3531
3532 //------------------------------------------------------------------------------
deleteRow()3533 void SAL_CALL ODatabaseForm::deleteRow() throw( SQLException, RuntimeException )
3534 {
3535 try
3536 {
3537 Reference<XResultSetUpdate> xUpdate;
3538 if (query_aggregation( m_xAggregate, xUpdate))
3539 xUpdate->deleteRow();
3540 }
3541 catch( const RowSetVetoException& eVeto )
3542 {
3543 (void)eVeto;
3544 throw;
3545 }
3546 catch(SQLException& eDb)
3547 {
3548 onError(eDb, FRM_RES_STRING(RID_STR_ERR_DELETERECORD));
3549 throw;
3550 }
3551 }
3552
3553 //------------------------------------------------------------------------------
cancelRowUpdates()3554 void SAL_CALL ODatabaseForm::cancelRowUpdates() throw( SQLException, RuntimeException )
3555 {
3556 try
3557 {
3558 Reference<XResultSetUpdate> xUpdate;
3559 if (query_aggregation( m_xAggregate, xUpdate))
3560 xUpdate->cancelRowUpdates();
3561 }
3562 catch( const RowSetVetoException& eVeto )
3563 {
3564 (void)eVeto;
3565 throw;
3566 }
3567 catch(SQLException& eDb)
3568 {
3569 onError(eDb, FRM_RES_STRING(RID_STR_ERR_INSERTRECORD));
3570 throw;
3571 }
3572 }
3573
3574 //------------------------------------------------------------------------------
moveToInsertRow()3575 void SAL_CALL ODatabaseForm::moveToInsertRow() throw( SQLException, RuntimeException )
3576 {
3577 Reference<XResultSetUpdate> xUpdate;
3578 if (query_aggregation( m_xAggregate, xUpdate))
3579 {
3580 // _always_ move to the insert row
3581 //
3582 // Formerly, the following line was conditioned with a "not is new", means we did not move the aggregate
3583 // to the insert row if it was already positioned there.
3584 //
3585 // This prevented the RowSet implementation from resetting it's column values. We, ourself, formerly
3586 // did this reset of columns in reset_impl, where we set every column to the ControlDefault, or, if this
3587 // was not present, to NULL. However, the problem with setting to NULL was #88888#, the problem with
3588 // _not_ setting to NULL (which was the original fix for #88888#) was #97955#.
3589 //
3590 // So now we
3591 // * move our aggregate to the insert row
3592 // * in reset_impl
3593 // - set the control defaults into the columns if not void
3594 // - do _not_ set the columns to NULL if no control default is set
3595 // This fixes both #88888# and #97955#
3596 //
3597 // Still, there is #72756#. During fixing this bug, DG introduced not calling the aggregate here. So
3598 // in theory, we re-introduced #72756#. But the bug described therein does not happen anymore, as the
3599 // preliminaries for it changed (no display of guessed values for new records with autoinc fields)
3600 //
3601 // BTW: the public Issuezilla bug for #97955# is #i2815#
3602 //
3603 // 16.04.2002 - 97955 - fs@openoffice.org
3604 xUpdate->moveToInsertRow();
3605
3606 // then set the default values and the parameters given from the parent
3607 reset();
3608 }
3609 }
3610
3611 //------------------------------------------------------------------------------
moveToCurrentRow()3612 void SAL_CALL ODatabaseForm::moveToCurrentRow() throw( SQLException, RuntimeException )
3613 {
3614 Reference<XResultSetUpdate> xUpdate;
3615 if (query_aggregation( m_xAggregate, xUpdate))
3616 xUpdate->moveToCurrentRow();
3617 }
3618
3619 // com::sun::star::sdbcx::XDeleteRows
3620 //------------------------------------------------------------------------------
deleteRows(const Sequence<Any> & rows)3621 Sequence<sal_Int32> SAL_CALL ODatabaseForm::deleteRows(const Sequence<Any>& rows) throw( SQLException, RuntimeException )
3622 {
3623 try
3624 {
3625 Reference<XDeleteRows> xDelete;
3626 if (query_aggregation( m_xAggregate, xDelete))
3627 return xDelete->deleteRows(rows);
3628 }
3629 catch( const RowSetVetoException& eVeto )
3630 {
3631 (void)eVeto; // make compiler happy
3632 throw;
3633 }
3634 catch(SQLException& eDb)
3635 {
3636 onError(eDb, FRM_RES_STRING(RID_STR_ERR_DELETERECORDS));
3637 throw;
3638 }
3639
3640 return Sequence< sal_Int32 >();
3641 }
3642
3643 // com::sun::star::sdbc::XParameters
3644 //------------------------------------------------------------------------------
setNull(sal_Int32 parameterIndex,sal_Int32 sqlType)3645 void SAL_CALL ODatabaseForm::setNull(sal_Int32 parameterIndex, sal_Int32 sqlType) throw( SQLException, RuntimeException )
3646 {
3647 m_aParameterManager.setNull(parameterIndex, sqlType);
3648 }
3649
3650 //------------------------------------------------------------------------------
setObjectNull(sal_Int32 parameterIndex,sal_Int32 sqlType,const::rtl::OUString & typeName)3651 void SAL_CALL ODatabaseForm::setObjectNull(sal_Int32 parameterIndex, sal_Int32 sqlType, const ::rtl::OUString& typeName) throw( SQLException, RuntimeException )
3652 {
3653 m_aParameterManager.setObjectNull(parameterIndex, sqlType, typeName);
3654 }
3655
3656 //------------------------------------------------------------------------------
setBoolean(sal_Int32 parameterIndex,sal_Bool x)3657 void SAL_CALL ODatabaseForm::setBoolean(sal_Int32 parameterIndex, sal_Bool x) throw( SQLException, RuntimeException )
3658 {
3659 m_aParameterManager.setBoolean(parameterIndex, x);
3660 }
3661
3662 //------------------------------------------------------------------------------
setByte(sal_Int32 parameterIndex,sal_Int8 x)3663 void SAL_CALL ODatabaseForm::setByte(sal_Int32 parameterIndex, sal_Int8 x) throw( SQLException, RuntimeException )
3664 {
3665 m_aParameterManager.setByte(parameterIndex, x);
3666 }
3667
3668 //------------------------------------------------------------------------------
setShort(sal_Int32 parameterIndex,sal_Int16 x)3669 void SAL_CALL ODatabaseForm::setShort(sal_Int32 parameterIndex, sal_Int16 x) throw( SQLException, RuntimeException )
3670 {
3671 m_aParameterManager.setShort(parameterIndex, x);
3672 }
3673
3674 //------------------------------------------------------------------------------
setInt(sal_Int32 parameterIndex,sal_Int32 x)3675 void SAL_CALL ODatabaseForm::setInt(sal_Int32 parameterIndex, sal_Int32 x) throw( SQLException, RuntimeException )
3676 {
3677 m_aParameterManager.setInt(parameterIndex, x);
3678 }
3679
3680 //------------------------------------------------------------------------------
setLong(sal_Int32 parameterIndex,sal_Int64 x)3681 void SAL_CALL ODatabaseForm::setLong(sal_Int32 parameterIndex, sal_Int64 x) throw( SQLException, RuntimeException )
3682 {
3683 m_aParameterManager.setLong(parameterIndex, x);
3684 }
3685
3686 //------------------------------------------------------------------------------
setFloat(sal_Int32 parameterIndex,float x)3687 void SAL_CALL ODatabaseForm::setFloat(sal_Int32 parameterIndex, float x) throw( SQLException, RuntimeException )
3688 {
3689 m_aParameterManager.setFloat(parameterIndex, x);
3690 }
3691
3692 //------------------------------------------------------------------------------
setDouble(sal_Int32 parameterIndex,double x)3693 void SAL_CALL ODatabaseForm::setDouble(sal_Int32 parameterIndex, double x) throw( SQLException, RuntimeException )
3694 {
3695 m_aParameterManager.setDouble(parameterIndex, x);
3696 }
3697
3698 //------------------------------------------------------------------------------
setString(sal_Int32 parameterIndex,const::rtl::OUString & x)3699 void SAL_CALL ODatabaseForm::setString(sal_Int32 parameterIndex, const ::rtl::OUString& x) throw( SQLException, RuntimeException )
3700 {
3701 m_aParameterManager.setString(parameterIndex, x);
3702 }
3703
3704 //------------------------------------------------------------------------------
setBytes(sal_Int32 parameterIndex,const Sequence<sal_Int8> & x)3705 void SAL_CALL ODatabaseForm::setBytes(sal_Int32 parameterIndex, const Sequence< sal_Int8 >& x) throw( SQLException, RuntimeException )
3706 {
3707 m_aParameterManager.setBytes(parameterIndex, x);
3708 }
3709
3710 //------------------------------------------------------------------------------
setDate(sal_Int32 parameterIndex,const::com::sun::star::util::Date & x)3711 void SAL_CALL ODatabaseForm::setDate(sal_Int32 parameterIndex, const ::com::sun::star::util::Date& x) throw( SQLException, RuntimeException )
3712 {
3713 m_aParameterManager.setDate(parameterIndex, x);
3714 }
3715
3716 //------------------------------------------------------------------------------
setTime(sal_Int32 parameterIndex,const::com::sun::star::util::Time & x)3717 void SAL_CALL ODatabaseForm::setTime(sal_Int32 parameterIndex, const ::com::sun::star::util::Time& x) throw( SQLException, RuntimeException )
3718 {
3719 m_aParameterManager.setTime(parameterIndex, x);
3720 }
3721
3722 //------------------------------------------------------------------------------
setTimestamp(sal_Int32 parameterIndex,const::com::sun::star::util::DateTime & x)3723 void SAL_CALL ODatabaseForm::setTimestamp(sal_Int32 parameterIndex, const ::com::sun::star::util::DateTime& x) throw( SQLException, RuntimeException )
3724 {
3725 m_aParameterManager.setTimestamp(parameterIndex, x);
3726 }
3727
3728 //------------------------------------------------------------------------------
setBinaryStream(sal_Int32 parameterIndex,const Reference<XInputStream> & x,sal_Int32 length)3729 void SAL_CALL ODatabaseForm::setBinaryStream(sal_Int32 parameterIndex, const Reference<XInputStream>& x, sal_Int32 length) throw( SQLException, RuntimeException )
3730 {
3731 m_aParameterManager.setBinaryStream(parameterIndex, x, length);
3732 }
3733
3734 //------------------------------------------------------------------------------
setCharacterStream(sal_Int32 parameterIndex,const Reference<XInputStream> & x,sal_Int32 length)3735 void SAL_CALL ODatabaseForm::setCharacterStream(sal_Int32 parameterIndex, const Reference<XInputStream>& x, sal_Int32 length) throw( SQLException, RuntimeException )
3736 {
3737 m_aParameterManager.setCharacterStream(parameterIndex, x, length);
3738 }
3739
3740 //------------------------------------------------------------------------------
setObjectWithInfo(sal_Int32 parameterIndex,const Any & x,sal_Int32 targetSqlType,sal_Int32 scale)3741 void SAL_CALL ODatabaseForm::setObjectWithInfo(sal_Int32 parameterIndex, const Any& x, sal_Int32 targetSqlType, sal_Int32 scale) throw( SQLException, RuntimeException )
3742 {
3743 m_aParameterManager.setObjectWithInfo(parameterIndex, x, targetSqlType, scale);
3744 }
3745
3746 //------------------------------------------------------------------------------
setObject(sal_Int32 parameterIndex,const Any & x)3747 void SAL_CALL ODatabaseForm::setObject(sal_Int32 parameterIndex, const Any& x) throw( SQLException, RuntimeException )
3748 {
3749 m_aParameterManager.setObject(parameterIndex, x);
3750 }
3751
3752 //------------------------------------------------------------------------------
setRef(sal_Int32 parameterIndex,const Reference<XRef> & x)3753 void SAL_CALL ODatabaseForm::setRef(sal_Int32 parameterIndex, const Reference<XRef>& x) throw( SQLException, RuntimeException )
3754 {
3755 m_aParameterManager.setRef(parameterIndex, x);
3756 }
3757
3758 //------------------------------------------------------------------------------
setBlob(sal_Int32 parameterIndex,const Reference<XBlob> & x)3759 void SAL_CALL ODatabaseForm::setBlob(sal_Int32 parameterIndex, const Reference<XBlob>& x) throw( SQLException, RuntimeException )
3760 {
3761 m_aParameterManager.setBlob(parameterIndex, x);
3762 }
3763
3764 //------------------------------------------------------------------------------
setClob(sal_Int32 parameterIndex,const Reference<XClob> & x)3765 void SAL_CALL ODatabaseForm::setClob(sal_Int32 parameterIndex, const Reference<XClob>& x) throw( SQLException, RuntimeException )
3766 {
3767 m_aParameterManager.setClob(parameterIndex, x);
3768 }
3769
3770 //------------------------------------------------------------------------------
setArray(sal_Int32 parameterIndex,const Reference<XArray> & x)3771 void SAL_CALL ODatabaseForm::setArray(sal_Int32 parameterIndex, const Reference<XArray>& x) throw( SQLException, RuntimeException )
3772 {
3773 m_aParameterManager.setArray(parameterIndex, x);
3774 }
3775
3776 //------------------------------------------------------------------------------
clearParameters()3777 void SAL_CALL ODatabaseForm::clearParameters() throw( SQLException, RuntimeException )
3778 {
3779 m_aParameterManager.clearParameters();
3780 }
3781
3782 //------------------------------------------------------------------------------
propertyChange(const PropertyChangeEvent & evt)3783 void SAL_CALL ODatabaseForm::propertyChange( const PropertyChangeEvent& evt ) throw (RuntimeException)
3784 {
3785 if ( evt.Source == m_xParent )
3786 {
3787 if ( evt.PropertyName == PROPERTY_ISNEW )
3788 {
3789 sal_Bool bCurrentIsNew( sal_False );
3790 OSL_VERIFY( evt.NewValue >>= bCurrentIsNew );
3791 if ( !bCurrentIsNew )
3792 reload_impl( sal_True );
3793 }
3794 return;
3795 }
3796 OFormComponents::propertyChange( evt );
3797 }
3798
3799 // com::sun::star::lang::XServiceInfo
3800 //------------------------------------------------------------------------------
getImplementationName_Static()3801 ::rtl::OUString SAL_CALL ODatabaseForm::getImplementationName_Static()
3802 {
3803 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.forms.ODatabaseForm" ) );
3804 }
3805
3806 //------------------------------------------------------------------------------
getCompatibleServiceNames_Static()3807 Sequence< ::rtl::OUString > SAL_CALL ODatabaseForm::getCompatibleServiceNames_Static()
3808 {
3809 Sequence< ::rtl::OUString > aServices( 1 );
3810 ::rtl::OUString* pServices = aServices.getArray();
3811
3812 *pServices++ = FRM_COMPONENT_FORM;
3813
3814 return aServices;
3815 }
3816
3817 //------------------------------------------------------------------------------
getCurrentServiceNames_Static()3818 Sequence< ::rtl::OUString > SAL_CALL ODatabaseForm::getCurrentServiceNames_Static()
3819 {
3820 Sequence< ::rtl::OUString > aServices( 5 );
3821 ::rtl::OUString* pServices = aServices.getArray();
3822
3823 *pServices++ = FRM_SUN_FORMCOMPONENT;
3824 *pServices++ = ::rtl::OUString::createFromAscii("com.sun.star.form.FormComponents");
3825 *pServices++ = FRM_SUN_COMPONENT_FORM;
3826 *pServices++ = FRM_SUN_COMPONENT_HTMLFORM;
3827 *pServices++ = FRM_SUN_COMPONENT_DATAFORM;
3828
3829 return aServices;
3830 }
3831
3832 //------------------------------------------------------------------------------
getSupportedServiceNames_Static()3833 Sequence< ::rtl::OUString > SAL_CALL ODatabaseForm::getSupportedServiceNames_Static()
3834 {
3835 return ::comphelper::concatSequences(
3836 getCurrentServiceNames_Static(),
3837 getCompatibleServiceNames_Static()
3838 );
3839 }
3840
3841 //------------------------------------------------------------------------------
getImplementationName()3842 ::rtl::OUString SAL_CALL ODatabaseForm::getImplementationName() throw( RuntimeException )
3843 {
3844 return getImplementationName_Static();
3845 }
3846
3847 //------------------------------------------------------------------------------
getSupportedServiceNames()3848 Sequence< ::rtl::OUString > SAL_CALL ODatabaseForm::getSupportedServiceNames() throw( RuntimeException )
3849 {
3850 // the services of our aggregate
3851 Sequence< ::rtl::OUString > aServices;
3852 Reference< XServiceInfo > xInfo;
3853 if (query_aggregation(m_xAggregate, xInfo))
3854 aServices = xInfo->getSupportedServiceNames();
3855
3856 // concat with out own services
3857 return ::comphelper::concatSequences(
3858 getCurrentServiceNames_Static(),
3859 aServices
3860 );
3861 // use getCurrentXXX instead of getSupportedXXX, because at runtime, we do not want to have
3862 // the compatible names
3863 // This is maily to be consistent with the implementation before fixing #97083#, though the
3864 // better solution _may_ be to return the compatible names at runtime, too
3865 // 04.03.2002 - fs@openoffice.org
3866 }
3867
3868 //------------------------------------------------------------------------------
supportsService(const::rtl::OUString & ServiceName)3869 sal_Bool SAL_CALL ODatabaseForm::supportsService(const ::rtl::OUString& ServiceName) throw( RuntimeException )
3870 {
3871 Sequence< ::rtl::OUString > aSupported( getSupportedServiceNames() );
3872 const ::rtl::OUString* pArray = aSupported.getConstArray();
3873 for( sal_Int32 i = 0; i < aSupported.getLength(); ++i, ++pArray )
3874 if( pArray->equals( ServiceName ) )
3875 return sal_True;
3876 return sal_False;
3877 }
3878
3879 //==============================================================================
3880 // com::sun::star::io::XPersistObject
3881 //------------------------------------------------------------------------------
3882
3883 const sal_uInt16 CYCLE = 0x0001;
3884 const sal_uInt16 DONTAPPLYFILTER = 0x0002;
3885
3886 //------------------------------------------------------------------------------
getServiceName()3887 ::rtl::OUString ODatabaseForm::getServiceName() throw( RuntimeException )
3888 {
3889 return FRM_COMPONENT_FORM; // old (non-sun) name for compatibility !
3890 }
3891
3892 //------------------------------------------------------------------------------
write(const Reference<XObjectOutputStream> & _rxOutStream)3893 void SAL_CALL ODatabaseForm::write(const Reference<XObjectOutputStream>& _rxOutStream) throw( IOException, RuntimeException )
3894 {
3895 DBG_ASSERT(m_xAggregateSet.is(), "ODatabaseForm::write : only to be called if the aggregate exists !");
3896
3897 // all children
3898 OFormComponents::write(_rxOutStream);
3899
3900 // version
3901 _rxOutStream->writeShort(0x0003);
3902
3903 // Name
3904 _rxOutStream << m_sName;
3905
3906 ::rtl::OUString sDataSource;
3907 if (m_xAggregateSet.is())
3908 m_xAggregateSet->getPropertyValue(PROPERTY_DATASOURCE) >>= sDataSource;
3909 _rxOutStream << sDataSource;
3910
3911 // former CursorSource
3912 ::rtl::OUString sCommand;
3913 if (m_xAggregateSet.is())
3914 m_xAggregateSet->getPropertyValue(PROPERTY_COMMAND) >>= sCommand;
3915 _rxOutStream << sCommand;
3916
3917 // former MasterFields
3918 _rxOutStream << m_aMasterFields;
3919 // former DetailFields
3920 _rxOutStream << m_aDetailFields;
3921
3922 // former DataSelectionType
3923 DataSelectionType eTranslated = DataSelectionType_TABLE;
3924 if (m_xAggregateSet.is())
3925 {
3926 sal_Int32 nCommandType = 0;
3927 m_xAggregateSet->getPropertyValue(PROPERTY_COMMANDTYPE) >>= nCommandType;
3928 switch (nCommandType)
3929 {
3930 case CommandType::TABLE : eTranslated = DataSelectionType_TABLE; break;
3931 case CommandType::QUERY : eTranslated = DataSelectionType_QUERY; break;
3932 case CommandType::COMMAND:
3933 {
3934 sal_Bool bEscapeProcessing = getBOOL(m_xAggregateSet->getPropertyValue(PROPERTY_ESCAPE_PROCESSING));
3935 eTranslated = bEscapeProcessing ? DataSelectionType_SQL : DataSelectionType_SQLPASSTHROUGH;
3936 }
3937 break;
3938 default : DBG_ERROR("ODatabaseForm::write : wrong CommandType !");
3939 }
3940 }
3941 _rxOutStream->writeShort((sal_Int16)eTranslated); // former DataSelectionType
3942
3943 // very old versions expect a CursorType here
3944 _rxOutStream->writeShort(DatabaseCursorType_KEYSET);
3945
3946 _rxOutStream->writeBoolean(m_eNavigation != NavigationBarMode_NONE);
3947
3948 // former DataEntry
3949 if (m_xAggregateSet.is())
3950 _rxOutStream->writeBoolean(getBOOL(m_xAggregateSet->getPropertyValue(PROPERTY_INSERTONLY)));
3951 else
3952 _rxOutStream->writeBoolean(sal_False);
3953
3954 _rxOutStream->writeBoolean(m_bAllowInsert);
3955 _rxOutStream->writeBoolean(m_bAllowUpdate);
3956 _rxOutStream->writeBoolean(m_bAllowDelete);
3957
3958 // html form stuff
3959 ::rtl::OUString sTmp = INetURLObject::decode( m_aTargetURL, '%', INetURLObject::DECODE_UNAMBIGUOUS);
3960 _rxOutStream << sTmp;
3961 _rxOutStream->writeShort( (sal_Int16)m_eSubmitMethod );
3962 _rxOutStream->writeShort( (sal_Int16)m_eSubmitEncoding );
3963 _rxOutStream << m_aTargetFrame;
3964
3965 // version 2 didn't know some options and the "default" state
3966 sal_Int32 nCycle = TabulatorCycle_RECORDS;
3967 if (m_aCycle.hasValue())
3968 {
3969 ::cppu::enum2int(nCycle, m_aCycle);
3970 if (m_aCycle == TabulatorCycle_PAGE)
3971 // unknown in earlier versions
3972 nCycle = TabulatorCycle_RECORDS;
3973 }
3974 _rxOutStream->writeShort((sal_Int16) nCycle);
3975
3976 _rxOutStream->writeShort((sal_Int16)m_eNavigation);
3977
3978 ::rtl::OUString sFilter;
3979 ::rtl::OUString sOrder;
3980 if (m_xAggregateSet.is())
3981 {
3982 m_xAggregateSet->getPropertyValue(PROPERTY_FILTER) >>= sFilter;
3983 m_xAggregateSet->getPropertyValue(PROPERTY_SORT) >>= sOrder;
3984 }
3985 _rxOutStream << sFilter;
3986 _rxOutStream << sOrder;
3987
3988
3989 // version 3
3990 sal_uInt16 nAnyMask = 0;
3991 if (m_aCycle.hasValue())
3992 nAnyMask |= CYCLE;
3993
3994 if (m_xAggregateSet.is() && !getBOOL(m_xAggregateSet->getPropertyValue(PROPERTY_APPLYFILTER)))
3995 nAnyMask |= DONTAPPLYFILTER;
3996
3997 _rxOutStream->writeShort(nAnyMask);
3998
3999 if (nAnyMask & CYCLE)
4000 {
4001 sal_Int32 nRealCycle = 0;
4002 ::cppu::enum2int(nRealCycle, m_aCycle);
4003 _rxOutStream->writeShort((sal_Int16)nRealCycle);
4004 }
4005 }
4006
4007 //------------------------------------------------------------------------------
read(const Reference<XObjectInputStream> & _rxInStream)4008 void SAL_CALL ODatabaseForm::read(const Reference<XObjectInputStream>& _rxInStream) throw( IOException, RuntimeException )
4009 {
4010 DBG_ASSERT(m_xAggregateSet.is(), "ODatabaseForm::read : only to be called if the aggregate exists !");
4011
4012 OFormComponents::read(_rxInStream);
4013
4014 // version
4015 sal_uInt16 nVersion = _rxInStream->readShort();
4016
4017 _rxInStream >> m_sName;
4018
4019 ::rtl::OUString sAggregateProp;
4020 _rxInStream >> sAggregateProp;
4021 if (m_xAggregateSet.is())
4022 m_xAggregateSet->setPropertyValue(PROPERTY_DATASOURCE, makeAny(sAggregateProp));
4023 _rxInStream >> sAggregateProp;
4024 if (m_xAggregateSet.is())
4025 m_xAggregateSet->setPropertyValue(PROPERTY_COMMAND, makeAny(sAggregateProp));
4026
4027 _rxInStream >> m_aMasterFields;
4028 _rxInStream >> m_aDetailFields;
4029
4030 sal_Int16 nCursorSourceType = _rxInStream->readShort();
4031 sal_Int32 nCommandType = 0;
4032 switch ((DataSelectionType)nCursorSourceType)
4033 {
4034 case DataSelectionType_TABLE : nCommandType = CommandType::TABLE; break;
4035 case DataSelectionType_QUERY : nCommandType = CommandType::QUERY; break;
4036 case DataSelectionType_SQL:
4037 case DataSelectionType_SQLPASSTHROUGH:
4038 {
4039 nCommandType = CommandType::COMMAND;
4040 sal_Bool bEscapeProcessing = ((DataSelectionType)nCursorSourceType) != DataSelectionType_SQLPASSTHROUGH;
4041 m_xAggregateSet->setPropertyValue(PROPERTY_ESCAPE_PROCESSING, makeAny((sal_Bool)bEscapeProcessing));
4042 }
4043 break;
4044 default : DBG_ERROR("ODatabaseForm::read : wrong CommandType !");
4045 }
4046 if (m_xAggregateSet.is())
4047 m_xAggregateSet->setPropertyValue(PROPERTY_COMMANDTYPE, makeAny(nCommandType));
4048
4049 // obsolete
4050 _rxInStream->readShort();
4051
4052 // navigation mode was a boolean in version 1
4053 // war in der version 1 ein sal_Bool
4054 sal_Bool bNavigation = _rxInStream->readBoolean();
4055 if (nVersion == 1)
4056 m_eNavigation = bNavigation ? NavigationBarMode_CURRENT : NavigationBarMode_NONE;
4057
4058 sal_Bool bInsertOnly = _rxInStream->readBoolean();
4059 if (m_xAggregateSet.is())
4060 m_xAggregateSet->setPropertyValue(PROPERTY_INSERTONLY, makeAny(bInsertOnly));
4061
4062 m_bAllowInsert = _rxInStream->readBoolean();
4063 m_bAllowUpdate = _rxInStream->readBoolean();
4064 m_bAllowDelete = _rxInStream->readBoolean();
4065
4066 // html stuff
4067 ::rtl::OUString sTmp;
4068 _rxInStream >> sTmp;
4069 m_aTargetURL = INetURLObject::decode( sTmp, '%', INetURLObject::DECODE_UNAMBIGUOUS);
4070 m_eSubmitMethod = (FormSubmitMethod)_rxInStream->readShort();
4071 m_eSubmitEncoding = (FormSubmitEncoding)_rxInStream->readShort();
4072 _rxInStream >> m_aTargetFrame;
4073
4074 if (nVersion > 1)
4075 {
4076 sal_Int32 nCycle = _rxInStream->readShort();
4077 m_aCycle = ::cppu::int2enum(nCycle, ::getCppuType(static_cast<const TabulatorCycle*>(NULL)));
4078 m_eNavigation = (NavigationBarMode)_rxInStream->readShort();
4079
4080 _rxInStream >> sAggregateProp;
4081 setPropertyValue(PROPERTY_FILTER, makeAny(sAggregateProp));
4082
4083 _rxInStream >> sAggregateProp;
4084 if (m_xAggregateSet.is())
4085 m_xAggregateSet->setPropertyValue(PROPERTY_SORT, makeAny(sAggregateProp));
4086 }
4087
4088 sal_uInt16 nAnyMask = 0;
4089 if (nVersion > 2)
4090 {
4091 nAnyMask = _rxInStream->readShort();
4092 if (nAnyMask & CYCLE)
4093 {
4094 sal_Int32 nCycle = _rxInStream->readShort();
4095 m_aCycle = ::cppu::int2enum(nCycle, ::getCppuType(static_cast<const TabulatorCycle*>(NULL)));
4096 }
4097 else
4098 m_aCycle.clear();
4099 }
4100 if (m_xAggregateSet.is())
4101 m_xAggregateSet->setPropertyValue(PROPERTY_APPLYFILTER, makeAny((sal_Bool)((nAnyMask & DONTAPPLYFILTER) == 0)));
4102 }
4103
4104 //------------------------------------------------------------------------------
implInserted(const ElementDescription * _pElement)4105 void ODatabaseForm::implInserted( const ElementDescription* _pElement )
4106 {
4107 OFormComponents::implInserted( _pElement );
4108
4109 Reference< XSQLErrorBroadcaster > xBroadcaster( _pElement->xInterface, UNO_QUERY );
4110 Reference< XForm > xForm ( _pElement->xInterface, UNO_QUERY );
4111
4112 if ( xBroadcaster.is() && !xForm.is() )
4113 { // the object is an error broadcaster, but no form itself -> add ourself as listener
4114 xBroadcaster->addSQLErrorListener( this );
4115 }
4116 }
4117
4118 //------------------------------------------------------------------------------
implRemoved(const InterfaceRef & _rxObject)4119 void ODatabaseForm::implRemoved(const InterfaceRef& _rxObject)
4120 {
4121 OFormComponents::implRemoved( _rxObject );
4122
4123 Reference<XSQLErrorBroadcaster> xBroadcaster(_rxObject, UNO_QUERY);
4124 Reference<XForm> xForm(_rxObject, UNO_QUERY);
4125 if (xBroadcaster.is() && !xForm.is())
4126 { // the object is an error broadcaster, but no form itself -> remove ourself as listener
4127 xBroadcaster->removeSQLErrorListener(this);
4128 }
4129 }
4130
4131 //------------------------------------------------------------------------------
errorOccured(const SQLErrorEvent & _rEvent)4132 void SAL_CALL ODatabaseForm::errorOccured(const SQLErrorEvent& _rEvent) throw( RuntimeException )
4133 {
4134 // give it to my own error listener
4135 onError(_rEvent);
4136 // TODO : think about extending the chain with an SQLContext object saying
4137 // "this was an error of one of my children"
4138 }
4139
4140 // com::sun::star::container::XNamed
4141 //------------------------------------------------------------------------------
getName()4142 ::rtl::OUString SAL_CALL ODatabaseForm::getName() throw( RuntimeException )
4143 {
4144 ::rtl::OUString sReturn;
4145 OPropertySetHelper::getFastPropertyValue(PROPERTY_ID_NAME) >>= sReturn;
4146 return sReturn;
4147 }
4148
4149 //------------------------------------------------------------------------------
setName(const::rtl::OUString & aName)4150 void SAL_CALL ODatabaseForm::setName(const ::rtl::OUString& aName) throw( RuntimeException )
4151 {
4152 setFastPropertyValue(PROPERTY_ID_NAME, makeAny(aName));
4153 }
4154
4155 //.........................................................................
4156 } // namespace frm
4157 //.........................................................................
4158
4159