Remove non-const Sequence::begin()/end() in internal code
[LibreOffice.git] / dbaccess / source / ui / browser / formadapter.cxx
blob37f35a0472ee3e117fd11b4dd929f7704ccf4d4b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <formadapter.hxx>
21 #include <o3tl/safeint.hxx>
22 #include <osl/diagnose.h>
23 #include <comphelper/types.hxx>
24 #include <comphelper/enumhelper.hxx>
25 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
26 #include <strings.hxx>
27 #include <connectivity/dbexception.hxx>
28 #include <comphelper/sequence.hxx>
30 using namespace dbaui;
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::sdb;
33 using namespace ::com::sun::star::sdbcx;
34 using namespace ::com::sun::star::beans;
35 using namespace ::com::sun::star::container;
37 // SbaXFormAdapter
39 SbaXFormAdapter::SbaXFormAdapter()
40 :m_aLoadListeners(*this, m_aMutex)
41 ,m_aRowSetListeners(*this, m_aMutex)
42 ,m_aRowSetApproveListeners(*this, m_aMutex)
43 ,m_aErrorListeners(*this, m_aMutex)
44 ,m_aParameterListeners(*this, m_aMutex)
45 ,m_aSubmitListeners(*this, m_aMutex)
46 ,m_aResetListeners(*this, m_aMutex)
47 ,m_aPropertyChangeListeners(*this, m_aMutex)
48 ,m_aVetoablePropertyChangeListeners(*this, m_aMutex)
49 ,m_aPropertiesChangeListeners(*this, m_aMutex)
50 ,m_aDisposeListeners(m_aMutex)
51 ,m_aContainerListeners(m_aMutex)
52 ,m_nNamePropHandle(-1)
57 SbaXFormAdapter::~SbaXFormAdapter()
62 Sequence< Type > SAL_CALL SbaXFormAdapter::getTypes( )
64 return ::comphelper::concatSequences(
65 SbaXFormAdapter_BASE1::getTypes(),
66 SbaXFormAdapter_BASE2::getTypes(),
67 SbaXFormAdapter_BASE3::getTypes()
71 Sequence< sal_Int8 > SAL_CALL SbaXFormAdapter::getImplementationId( )
73 return css::uno::Sequence<sal_Int8>();
76 Any SAL_CALL SbaXFormAdapter::queryInterface(const Type& _rType)
78 Any aReturn = SbaXFormAdapter_BASE1::queryInterface( _rType );
80 if (!aReturn.hasValue())
81 aReturn = SbaXFormAdapter_BASE2::queryInterface( _rType );
83 if (!aReturn.hasValue())
84 aReturn = SbaXFormAdapter_BASE3::queryInterface( _rType );
86 return aReturn;
89 void SbaXFormAdapter::StopListening()
91 // log off all our multiplexers
92 STOP_MULTIPLEXER_LISTENING(LoadListener, m_aLoadListeners, css::form::XLoadable, m_xMainForm);
93 STOP_MULTIPLEXER_LISTENING(RowSetListener, m_aRowSetListeners, css::sdbc::XRowSet, m_xMainForm);
94 STOP_MULTIPLEXER_LISTENING(RowSetApproveListener, m_aRowSetApproveListeners, css::sdb::XRowSetApproveBroadcaster, m_xMainForm);
95 STOP_MULTIPLEXER_LISTENING(SQLErrorListener, m_aErrorListeners, css::sdb::XSQLErrorBroadcaster, m_xMainForm);
96 STOP_MULTIPLEXER_LISTENING(SubmitListener, m_aSubmitListeners, css::form::XSubmit, m_xMainForm);
97 STOP_MULTIPLEXER_LISTENING(ResetListener, m_aResetListeners, css::form::XReset, m_xMainForm);
99 if (m_aParameterListeners.getLength())
101 Reference< css::form::XDatabaseParameterBroadcaster > xBroadcaster(m_xMainForm, UNO_QUERY);
102 if (xBroadcaster.is())
103 xBroadcaster->removeParameterListener(&m_aParameterListeners);
106 STOP_PROPERTY_MULTIPLEXER_LISTENING(PropertyChangeListener, m_aPropertyChangeListeners, css::beans::XPropertySet, m_xMainForm);
107 STOP_PROPERTY_MULTIPLEXER_LISTENING(VetoableChangeListener, m_aVetoablePropertyChangeListeners, css::beans::XPropertySet, m_xMainForm);
108 if (m_aPropertiesChangeListeners.getLength())
110 Reference< css::beans::XMultiPropertySet > xBroadcaster(m_xMainForm, UNO_QUERY);
111 if (xBroadcaster.is())
112 xBroadcaster->removePropertiesChangeListener(&m_aPropertiesChangeListeners);
115 // log off ourself
116 Reference< css::lang::XComponent > xComp(m_xMainForm, UNO_QUERY);
117 if (xComp.is())
118 xComp->removeEventListener(static_cast<css::lang::XEventListener*>(static_cast<css::beans::XPropertyChangeListener*>(this)));
121 void SbaXFormAdapter::StartListening()
123 // log off all our multiplexers
124 START_MULTIPLEXER_LISTENING(LoadListener, m_aLoadListeners, css::form::XLoadable, m_xMainForm);
125 START_MULTIPLEXER_LISTENING(RowSetListener, m_aRowSetListeners, css::sdbc::XRowSet, m_xMainForm);
126 START_MULTIPLEXER_LISTENING(RowSetApproveListener, m_aRowSetApproveListeners, css::sdb::XRowSetApproveBroadcaster, m_xMainForm);
127 START_MULTIPLEXER_LISTENING(SQLErrorListener, m_aErrorListeners, css::sdb::XSQLErrorBroadcaster, m_xMainForm);
128 START_MULTIPLEXER_LISTENING(SubmitListener, m_aSubmitListeners, css::form::XSubmit, m_xMainForm);
129 START_MULTIPLEXER_LISTENING(ResetListener, m_aResetListeners, css::form::XReset, m_xMainForm);
131 if (m_aParameterListeners.getLength())
133 Reference< css::form::XDatabaseParameterBroadcaster > xBroadcaster(m_xMainForm, UNO_QUERY);
134 if (xBroadcaster.is())
135 xBroadcaster->addParameterListener(&m_aParameterListeners);
138 START_PROPERTY_MULTIPLEXER_LISTENING(PropertyChangeListener, m_aPropertyChangeListeners, css::beans::XPropertySet, m_xMainForm);
139 START_PROPERTY_MULTIPLEXER_LISTENING(VetoableChangeListener, m_aVetoablePropertyChangeListeners, css::beans::XPropertySet, m_xMainForm);
140 if (m_aPropertiesChangeListeners.getLength())
142 Reference< css::beans::XMultiPropertySet > xBroadcaster(m_xMainForm, UNO_QUERY);
143 if (xBroadcaster.is())
144 xBroadcaster->addPropertiesChangeListener(css::uno::Sequence<OUString>{""}, &m_aPropertiesChangeListeners);
147 // log off ourself
148 Reference< css::lang::XComponent > xComp(m_xMainForm, UNO_QUERY);
149 if (xComp.is())
150 xComp->addEventListener(static_cast<css::lang::XEventListener*>(static_cast<css::beans::XPropertyChangeListener*>(this)));
153 void SbaXFormAdapter::AttachForm(const Reference< css::sdbc::XRowSet >& xNewMaster)
155 if (xNewMaster == m_xMainForm)
156 return;
158 OSL_ENSURE(xNewMaster.get() != static_cast< css::sdbc::XRowSet* >(this), "SbaXFormAdapter::AttachForm : invalid argument !");
160 if (m_xMainForm.is())
162 StopListening();
164 // if our old master is loaded we have to send an 'unloaded' event
165 Reference< css::form::XLoadable > xLoadable(m_xMainForm, UNO_QUERY);
166 if (xLoadable->isLoaded())
168 css::lang::EventObject aEvt(*this);
169 ::comphelper::OInterfaceIteratorHelper2 aIt(m_aLoadListeners);
170 while (aIt.hasMoreElements())
171 static_cast< css::form::XLoadListener*>(aIt.next())->unloaded(aEvt);
175 m_xMainForm = xNewMaster;
177 if (!m_xMainForm.is())
178 return;
180 StartListening();
182 // if our new master is loaded we have to send an 'loaded' event
183 Reference< css::form::XLoadable > xLoadable(m_xMainForm, UNO_QUERY);
184 if (xLoadable->isLoaded())
186 css::lang::EventObject aEvt(*this);
187 ::comphelper::OInterfaceIteratorHelper2 aIt(m_aLoadListeners);
188 while (aIt.hasMoreElements())
189 static_cast< css::form::XLoadListener*>(aIt.next())->loaded(aEvt);
192 // TODO : perhaps _all_ of our listeners should be notified about our new state
193 // (nearly every aspect of us may have changed with new master form)
196 // css::sdbc::XCloseable
197 void SAL_CALL SbaXFormAdapter::close()
199 Reference< css::sdbc::XCloseable > xIface(m_xMainForm, UNO_QUERY);
200 if (xIface.is())
201 xIface->close();
204 // css::sdbc::XResultSetMetaDataSupplier
205 Reference< css::sdbc::XResultSetMetaData > SAL_CALL SbaXFormAdapter::getMetaData()
207 Reference< css::sdbc::XResultSetMetaDataSupplier > xIface(m_xMainForm, UNO_QUERY);
208 if (xIface.is())
209 return xIface->getMetaData();
210 return Reference< css::sdbc::XResultSetMetaData > ();
213 // css::sdbc::XColumnLocate
214 sal_Int32 SAL_CALL SbaXFormAdapter::findColumn(const OUString& columnName)
216 Reference< css::sdbc::XColumnLocate > xIface(m_xMainForm, UNO_QUERY);
217 if (xIface.is())
218 return xIface->findColumn(columnName);
220 ::dbtools::throwInvalidColumnException( columnName, *this );
221 assert(false);
222 return 0; // Never reached
225 // css::sdbcx::XColumnsSupplier
226 Reference< css::container::XNameAccess > SAL_CALL SbaXFormAdapter::getColumns()
228 Reference< css::sdbcx::XColumnsSupplier > xIface(m_xMainForm, UNO_QUERY);
229 if (xIface.is())
230 return xIface->getColumns();
231 return Reference< css::container::XNameAccess > ();
234 // css::sdbc::XRow
235 sal_Bool SAL_CALL SbaXFormAdapter::wasNull()
237 Reference< css::sdbc::XRow > xIface(m_xMainForm, UNO_QUERY);
238 if (xIface.is())
239 return xIface->wasNull();
240 return true;
243 OUString SAL_CALL SbaXFormAdapter::getString(sal_Int32 columnIndex)
245 Reference< css::sdbc::XRow > xIface(m_xMainForm, UNO_QUERY);
246 if (xIface.is())
247 return xIface->getString(columnIndex);
248 return OUString();
251 sal_Bool SAL_CALL SbaXFormAdapter::getBoolean(sal_Int32 columnIndex)
253 Reference< css::sdbc::XRow > xIface(m_xMainForm, UNO_QUERY);
254 if (xIface.is())
255 return xIface->getBoolean(columnIndex);
256 return false;
259 sal_Int8 SAL_CALL SbaXFormAdapter::getByte(sal_Int32 columnIndex)
262 Reference< css::sdbc::XRow > xIface(m_xMainForm, UNO_QUERY);
263 if (xIface.is())
264 return xIface->getByte(columnIndex);
265 return 0;
268 sal_Int16 SAL_CALL SbaXFormAdapter::getShort(sal_Int32 columnIndex)
270 Reference< css::sdbc::XRow > xIface(m_xMainForm, UNO_QUERY);
271 if (xIface.is())
272 return xIface->getShort(columnIndex);
273 return 0;
276 sal_Int32 SAL_CALL SbaXFormAdapter::getInt(sal_Int32 columnIndex)
278 Reference< css::sdbc::XRow > xIface(m_xMainForm, UNO_QUERY);
279 if (xIface.is())
280 return xIface->getInt(columnIndex);
281 return 0;
284 sal_Int64 SAL_CALL SbaXFormAdapter::getLong(sal_Int32 columnIndex)
286 Reference< css::sdbc::XRow > xIface(m_xMainForm, UNO_QUERY);
287 if (xIface.is())
288 return xIface->getLong(columnIndex);
289 return 0;
292 float SAL_CALL SbaXFormAdapter::getFloat(sal_Int32 columnIndex)
294 Reference< css::sdbc::XRow > xIface(m_xMainForm, UNO_QUERY);
295 if (xIface.is())
296 return xIface->getFloat(columnIndex);
297 return 0.0;
300 double SAL_CALL SbaXFormAdapter::getDouble(sal_Int32 columnIndex)
302 Reference< css::sdbc::XRow > xIface(m_xMainForm, UNO_QUERY);
303 if (xIface.is())
304 return xIface->getDouble(columnIndex);
305 return 0.0;
308 Sequence< sal_Int8 > SAL_CALL SbaXFormAdapter::getBytes(sal_Int32 columnIndex)
310 Reference< css::sdbc::XRow > xIface(m_xMainForm, UNO_QUERY);
311 if (xIface.is())
312 return xIface->getBytes(columnIndex);
313 return Sequence <sal_Int8> ();
316 css::util::Date SAL_CALL SbaXFormAdapter::getDate(sal_Int32 columnIndex)
318 Reference< css::sdbc::XRow > xIface(m_xMainForm, UNO_QUERY);
319 if (xIface.is())
320 return xIface->getDate(columnIndex);
321 return css::util::Date();
324 css::util::Time SAL_CALL SbaXFormAdapter::getTime(sal_Int32 columnIndex)
326 Reference< css::sdbc::XRow > xIface(m_xMainForm, UNO_QUERY);
327 if (xIface.is())
328 return xIface->getTime(columnIndex);
329 return css::util::Time();
332 css::util::DateTime SAL_CALL SbaXFormAdapter::getTimestamp(sal_Int32 columnIndex)
334 Reference< css::sdbc::XRow > xIface(m_xMainForm, UNO_QUERY);
335 if (xIface.is())
336 return xIface->getTimestamp(columnIndex);
337 return css::util::DateTime();
340 Reference< css::io::XInputStream > SAL_CALL SbaXFormAdapter::getBinaryStream(sal_Int32 columnIndex)
342 Reference< css::sdbc::XRow > xIface(m_xMainForm, UNO_QUERY);
343 if (xIface.is())
344 return xIface->getBinaryStream(columnIndex);
345 return Reference< css::io::XInputStream > ();
348 Reference< css::io::XInputStream > SAL_CALL SbaXFormAdapter::getCharacterStream(sal_Int32 columnIndex)
350 Reference< css::sdbc::XRow > xIface(m_xMainForm, UNO_QUERY);
351 if (xIface.is())
352 return xIface->getCharacterStream(columnIndex);
353 return Reference< css::io::XInputStream > ();
356 Any SAL_CALL SbaXFormAdapter::getObject(sal_Int32 columnIndex, const Reference< css::container::XNameAccess >& typeMap)
358 Reference< css::sdbc::XRow > xIface(m_xMainForm, UNO_QUERY);
359 if (xIface.is())
360 return xIface->getObject(columnIndex, typeMap);
361 return Any();
364 Reference< css::sdbc::XRef > SAL_CALL SbaXFormAdapter::getRef(sal_Int32 columnIndex)
366 Reference< css::sdbc::XRow > xIface(m_xMainForm, UNO_QUERY);
367 if (xIface.is())
368 return xIface->getRef(columnIndex);
369 return Reference< css::sdbc::XRef > ();
372 Reference< css::sdbc::XBlob > SAL_CALL SbaXFormAdapter::getBlob(sal_Int32 columnIndex)
374 Reference< css::sdbc::XRow > xIface(m_xMainForm, UNO_QUERY);
375 if (xIface.is())
376 return xIface->getBlob(columnIndex);
377 return Reference< css::sdbc::XBlob > ();
380 Reference< css::sdbc::XClob > SAL_CALL SbaXFormAdapter::getClob(sal_Int32 columnIndex)
382 Reference< css::sdbc::XRow > xIface(m_xMainForm, UNO_QUERY);
383 if (xIface.is())
384 return xIface->getClob(columnIndex);
385 return Reference< css::sdbc::XClob > ();
388 Reference< css::sdbc::XArray > SAL_CALL SbaXFormAdapter::getArray(sal_Int32 columnIndex)
390 Reference< css::sdbc::XRow > xIface(m_xMainForm, UNO_QUERY);
391 if (xIface.is())
392 return xIface->getArray(columnIndex);
393 return Reference< css::sdbc::XArray > ();
396 // css::sdbcx::XRowLocate
397 Any SAL_CALL SbaXFormAdapter::getBookmark()
399 Reference< css::sdbcx::XRowLocate > xIface(m_xMainForm, UNO_QUERY);
400 if (xIface.is())
401 return xIface->getBookmark();
402 return Any();
405 sal_Bool SAL_CALL SbaXFormAdapter::moveToBookmark(const Any& bookmark)
407 Reference< css::sdbcx::XRowLocate > xIface(m_xMainForm, UNO_QUERY);
408 if (xIface.is())
409 return xIface->moveToBookmark(bookmark);
410 return false;
413 sal_Bool SAL_CALL SbaXFormAdapter::moveRelativeToBookmark(const Any& bookmark, sal_Int32 rows)
415 Reference< css::sdbcx::XRowLocate > xIface(m_xMainForm, UNO_QUERY);
416 if (xIface.is())
417 return xIface->moveRelativeToBookmark(bookmark,rows);
418 return false;
421 sal_Int32 SAL_CALL SbaXFormAdapter::compareBookmarks(const Any& _first, const Any& _second)
423 Reference< css::sdbcx::XRowLocate > xIface(m_xMainForm, UNO_QUERY);
424 if (xIface.is())
425 return xIface->compareBookmarks(_first, _second);
426 return 0;
429 sal_Bool SAL_CALL SbaXFormAdapter::hasOrderedBookmarks()
431 Reference< css::sdbcx::XRowLocate > xIface(m_xMainForm, UNO_QUERY);
432 if (xIface.is())
433 return xIface->hasOrderedBookmarks();
434 return false;
437 sal_Int32 SAL_CALL SbaXFormAdapter::hashBookmark(const Any& bookmark)
439 Reference< css::sdbcx::XRowLocate > xIface(m_xMainForm, UNO_QUERY);
440 if (xIface.is())
441 return xIface->hashBookmark(bookmark);
442 return 0;
445 // css::sdbc::XRowUpdate
446 void SAL_CALL SbaXFormAdapter::updateNull(sal_Int32 columnIndex)
448 Reference< css::sdbc::XRowUpdate > xIface(m_xMainForm, UNO_QUERY);
449 if (xIface.is())
450 xIface->updateNull(columnIndex);
453 void SAL_CALL SbaXFormAdapter::updateBoolean(sal_Int32 columnIndex, sal_Bool x)
455 Reference< css::sdbc::XRowUpdate > xIface(m_xMainForm, UNO_QUERY);
456 if (xIface.is())
457 xIface->updateBoolean(columnIndex, x);
460 void SAL_CALL SbaXFormAdapter::updateByte(sal_Int32 columnIndex, sal_Int8 x)
462 Reference< css::sdbc::XRowUpdate > xIface(m_xMainForm, UNO_QUERY);
463 if (xIface.is())
464 xIface->updateByte(columnIndex, x);
467 void SAL_CALL SbaXFormAdapter::updateShort(sal_Int32 columnIndex, sal_Int16 x)
469 Reference< css::sdbc::XRowUpdate > xIface(m_xMainForm, UNO_QUERY);
470 if (xIface.is())
471 xIface->updateShort(columnIndex, x);
474 void SAL_CALL SbaXFormAdapter::updateInt(sal_Int32 columnIndex, sal_Int32 x)
476 Reference< css::sdbc::XRowUpdate > xIface(m_xMainForm, UNO_QUERY);
477 if (xIface.is())
478 xIface->updateInt(columnIndex, x);
481 void SAL_CALL SbaXFormAdapter::updateLong(sal_Int32 columnIndex, sal_Int64 x)
483 Reference< css::sdbc::XRowUpdate > xIface(m_xMainForm, UNO_QUERY);
484 if (xIface.is())
485 xIface->updateLong(columnIndex, x);
488 void SAL_CALL SbaXFormAdapter::updateFloat(sal_Int32 columnIndex, float x)
490 Reference< css::sdbc::XRowUpdate > xIface(m_xMainForm, UNO_QUERY);
491 if (xIface.is())
492 xIface->updateFloat(columnIndex, x);
495 void SAL_CALL SbaXFormAdapter::updateDouble(sal_Int32 columnIndex, double x)
497 Reference< css::sdbc::XRowUpdate > xIface(m_xMainForm, UNO_QUERY);
498 if (xIface.is())
499 xIface->updateDouble(columnIndex, x);
502 void SAL_CALL SbaXFormAdapter::updateString(sal_Int32 columnIndex, const OUString& x)
504 Reference< css::sdbc::XRowUpdate > xIface(m_xMainForm, UNO_QUERY);
505 if (xIface.is())
506 xIface->updateString(columnIndex, x);
509 void SAL_CALL SbaXFormAdapter::updateBytes(sal_Int32 columnIndex, const Sequence< sal_Int8 >& x)
511 Reference< css::sdbc::XRowUpdate > xIface(m_xMainForm, UNO_QUERY);
512 if (xIface.is())
513 xIface->updateBytes(columnIndex, x);
516 void SAL_CALL SbaXFormAdapter::updateDate(sal_Int32 columnIndex, const css::util::Date& x)
518 Reference< css::sdbc::XRowUpdate > xIface(m_xMainForm, UNO_QUERY);
519 if (xIface.is())
520 xIface->updateDate(columnIndex, x);
523 void SAL_CALL SbaXFormAdapter::updateTime(sal_Int32 columnIndex, const css::util::Time& x)
525 Reference< css::sdbc::XRowUpdate > xIface(m_xMainForm, UNO_QUERY);
526 if (xIface.is())
527 xIface->updateTime(columnIndex, x);
530 void SAL_CALL SbaXFormAdapter::updateTimestamp(sal_Int32 columnIndex, const css::util::DateTime& x)
532 Reference< css::sdbc::XRowUpdate > xIface(m_xMainForm, UNO_QUERY);
533 if (xIface.is())
534 xIface->updateTimestamp(columnIndex, x);
537 void SAL_CALL SbaXFormAdapter::updateBinaryStream(sal_Int32 columnIndex, const Reference< css::io::XInputStream >& x, sal_Int32 length)
539 Reference< css::sdbc::XRowUpdate > xIface(m_xMainForm, UNO_QUERY);
540 if (xIface.is())
541 xIface->updateBinaryStream(columnIndex, x, length);
544 void SAL_CALL SbaXFormAdapter::updateCharacterStream(sal_Int32 columnIndex, const Reference< css::io::XInputStream >& x, sal_Int32 length)
546 Reference< css::sdbc::XRowUpdate > xIface(m_xMainForm, UNO_QUERY);
547 if (xIface.is())
548 xIface->updateCharacterStream(columnIndex, x, length);
551 void SAL_CALL SbaXFormAdapter::updateObject(sal_Int32 columnIndex, const Any& x)
553 Reference< css::sdbc::XRowUpdate > xIface(m_xMainForm, UNO_QUERY);
554 if (xIface.is())
555 xIface->updateObject(columnIndex, x);
558 void SAL_CALL SbaXFormAdapter::updateNumericObject(sal_Int32 columnIndex, const Any& x, sal_Int32 scale)
560 Reference< css::sdbc::XRowUpdate > xIface(m_xMainForm, UNO_QUERY);
561 if (xIface.is())
562 xIface->updateNumericObject(columnIndex, x, scale);
565 // css::sdbc::XResultSet
566 sal_Bool SAL_CALL SbaXFormAdapter::next()
568 if (m_xMainForm.is())
569 return m_xMainForm->next();
570 return false;
573 sal_Bool SAL_CALL SbaXFormAdapter::isBeforeFirst()
575 if (m_xMainForm.is())
576 return m_xMainForm->isBeforeFirst();
577 return false;
580 sal_Bool SAL_CALL SbaXFormAdapter::isAfterLast()
582 if (m_xMainForm.is())
583 return m_xMainForm->isAfterLast();
584 return false;
587 sal_Bool SAL_CALL SbaXFormAdapter::isFirst()
589 if (m_xMainForm.is())
590 return m_xMainForm->isFirst();
591 return false;
594 sal_Bool SAL_CALL SbaXFormAdapter::isLast()
596 if (m_xMainForm.is())
597 return m_xMainForm->isLast();
598 return false;
601 void SAL_CALL SbaXFormAdapter::beforeFirst()
603 if (m_xMainForm.is())
604 m_xMainForm->beforeFirst();
607 void SAL_CALL SbaXFormAdapter::afterLast()
609 if (m_xMainForm.is())
610 m_xMainForm->afterLast();
613 sal_Bool SAL_CALL SbaXFormAdapter::first()
615 if (m_xMainForm.is())
616 return m_xMainForm->first();
617 return false;
620 sal_Bool SAL_CALL SbaXFormAdapter::last()
622 if (m_xMainForm.is())
623 return m_xMainForm->last();
624 return false;
627 sal_Int32 SAL_CALL SbaXFormAdapter::getRow()
629 if (m_xMainForm.is())
630 return m_xMainForm->getRow();
631 return 0;
634 sal_Bool SAL_CALL SbaXFormAdapter::absolute(sal_Int32 row)
636 if (m_xMainForm.is())
637 return m_xMainForm->absolute(row);
638 return false;
641 sal_Bool SAL_CALL SbaXFormAdapter::relative(sal_Int32 rows)
643 if (m_xMainForm.is())
644 return m_xMainForm->relative(rows);
645 return false;
648 sal_Bool SAL_CALL SbaXFormAdapter::previous()
650 if (m_xMainForm.is())
651 return m_xMainForm->previous();
652 return false;
655 void SAL_CALL SbaXFormAdapter::refreshRow()
657 if (m_xMainForm.is())
658 m_xMainForm->refreshRow();
661 sal_Bool SAL_CALL SbaXFormAdapter::rowUpdated()
663 if (m_xMainForm.is())
664 return m_xMainForm->rowUpdated();
665 return false;
668 sal_Bool SAL_CALL SbaXFormAdapter::rowInserted()
670 if (m_xMainForm.is())
671 return m_xMainForm->rowInserted();
672 return false;
675 sal_Bool SAL_CALL SbaXFormAdapter::rowDeleted()
677 if (m_xMainForm.is())
678 return m_xMainForm->rowDeleted();
679 return false;
682 Reference< XInterface > SAL_CALL SbaXFormAdapter::getStatement()
684 if (m_xMainForm.is())
685 return m_xMainForm->getStatement();
686 return nullptr;
689 // css::sdbc::XResultSetUpdate
690 void SAL_CALL SbaXFormAdapter::insertRow()
692 Reference< css::sdbc::XResultSetUpdate > xIface(m_xMainForm, UNO_QUERY);
693 if (xIface.is())
694 xIface->insertRow();
697 void SAL_CALL SbaXFormAdapter::updateRow()
699 Reference< css::sdbc::XResultSetUpdate > xIface(m_xMainForm, UNO_QUERY);
700 if (xIface.is())
701 xIface->updateRow();
704 void SAL_CALL SbaXFormAdapter::deleteRow()
706 Reference< css::sdbc::XResultSetUpdate > xIface(m_xMainForm, UNO_QUERY);
707 if (xIface.is())
708 xIface->deleteRow();
711 void SAL_CALL SbaXFormAdapter::cancelRowUpdates()
713 Reference< css::sdbc::XResultSetUpdate > xIface(m_xMainForm, UNO_QUERY);
714 if (xIface.is())
715 xIface->cancelRowUpdates();
718 void SAL_CALL SbaXFormAdapter::moveToInsertRow()
720 Reference< css::sdbc::XResultSetUpdate > xIface(m_xMainForm, UNO_QUERY);
721 if (xIface.is())
722 xIface->moveToInsertRow();
725 void SAL_CALL SbaXFormAdapter::moveToCurrentRow()
727 Reference< css::sdbc::XResultSetUpdate > xIface(m_xMainForm, UNO_QUERY);
728 if (xIface.is())
729 xIface->moveToCurrentRow();
732 // css::sdbc::XRowSet
733 void SAL_CALL SbaXFormAdapter::execute()
735 if (m_xMainForm.is())
736 m_xMainForm->execute();
739 IMPLEMENT_LISTENER_ADMINISTRATION(SbaXFormAdapter, sdbc, RowSetListener, m_aRowSetListeners, css::sdbc::XRowSet, m_xMainForm)
741 // css::sdbcx::XDeleteRows
742 Sequence<sal_Int32> SAL_CALL SbaXFormAdapter::deleteRows(const Sequence< Any >& rows)
744 Reference< css::sdbcx::XDeleteRows > xIface(m_xMainForm, UNO_QUERY);
745 if (xIface.is())
746 return xIface->deleteRows(rows);
747 return Sequence<sal_Int32>();
750 // css::sdbc::XWarningsSupplier
751 Any SAL_CALL SbaXFormAdapter::getWarnings()
753 Reference< css::sdbc::XWarningsSupplier > xIface(m_xMainForm, UNO_QUERY);
754 if (xIface.is())
755 return xIface->getWarnings();
756 return Any();
759 void SAL_CALL SbaXFormAdapter::clearWarnings()
761 Reference< css::sdbc::XWarningsSupplier > xIface(m_xMainForm, UNO_QUERY);
762 if (xIface.is())
763 xIface->clearWarnings();
766 // css::sdb::XRowSetApproveBroadcaster
767 IMPLEMENT_LISTENER_ADMINISTRATION(SbaXFormAdapter, sdb, RowSetApproveListener, m_aRowSetApproveListeners, css::sdb::XRowSetApproveBroadcaster, m_xMainForm)
769 // css::sdbc::XSQLErrorBroadcaster
770 IMPLEMENT_LISTENER_ADMINISTRATION(SbaXFormAdapter, sdb, SQLErrorListener, m_aErrorListeners, css::sdb::XSQLErrorBroadcaster, m_xMainForm)
772 // css::sdb::XResultSetAccess
773 Reference< css::sdbc::XResultSet > SAL_CALL SbaXFormAdapter::createResultSet()
775 Reference< css::sdb::XResultSetAccess > xIface(m_xMainForm, UNO_QUERY);
776 if (xIface.is())
777 return xIface->createResultSet();
778 return Reference< css::sdbc::XResultSet > ();
781 // css::form::XLoadable
782 void SAL_CALL SbaXFormAdapter::load()
784 Reference< css::form::XLoadable > xIface(m_xMainForm, UNO_QUERY);
785 if (xIface.is())
786 xIface->load();
789 void SAL_CALL SbaXFormAdapter::unload()
791 Reference< css::form::XLoadable > xIface(m_xMainForm, UNO_QUERY);
792 if (xIface.is())
793 xIface->unload();
796 void SAL_CALL SbaXFormAdapter::reload()
798 Reference< css::form::XLoadable > xIface(m_xMainForm, UNO_QUERY);
799 if (xIface.is())
800 xIface->reload();
803 sal_Bool SAL_CALL SbaXFormAdapter::isLoaded()
805 Reference< css::form::XLoadable > xIface(m_xMainForm, UNO_QUERY);
806 if (xIface.is())
807 return xIface->isLoaded();
808 return false;
811 IMPLEMENT_LISTENER_ADMINISTRATION(SbaXFormAdapter, form, LoadListener, m_aLoadListeners, css::form::XLoadable, m_xMainForm)
813 // css::sdbc::XParameters
814 void SAL_CALL SbaXFormAdapter::setNull(sal_Int32 parameterIndex, sal_Int32 sqlType)
816 Reference< css::sdbc::XParameters > xIface(m_xMainForm, UNO_QUERY);
817 if (xIface.is())
818 xIface->setNull(parameterIndex, sqlType);
821 void SAL_CALL SbaXFormAdapter::setObjectNull(sal_Int32 parameterIndex, sal_Int32 sqlType, const OUString& typeName)
823 Reference< css::sdbc::XParameters > xIface(m_xMainForm, UNO_QUERY);
824 if (xIface.is())
825 xIface->setObjectNull(parameterIndex, sqlType, typeName);
828 void SAL_CALL SbaXFormAdapter::setBoolean(sal_Int32 parameterIndex, sal_Bool x)
830 Reference< css::sdbc::XParameters > xIface(m_xMainForm, UNO_QUERY);
831 if (xIface.is())
832 xIface->setBoolean(parameterIndex, x);
835 void SAL_CALL SbaXFormAdapter::setByte(sal_Int32 parameterIndex, sal_Int8 x)
837 Reference< css::sdbc::XParameters > xIface(m_xMainForm, UNO_QUERY);
838 if (xIface.is())
839 xIface->setByte(parameterIndex, x);
842 void SAL_CALL SbaXFormAdapter::setShort(sal_Int32 parameterIndex, sal_Int16 x)
844 Reference< css::sdbc::XParameters > xIface(m_xMainForm, UNO_QUERY);
845 if (xIface.is())
846 xIface->setShort(parameterIndex, x);
849 void SAL_CALL SbaXFormAdapter::setInt(sal_Int32 parameterIndex, sal_Int32 x)
851 Reference< css::sdbc::XParameters > xIface(m_xMainForm, UNO_QUERY);
852 if (xIface.is())
853 xIface->setInt(parameterIndex, x);
856 void SAL_CALL SbaXFormAdapter::setLong(sal_Int32 parameterIndex, sal_Int64 x)
858 Reference< css::sdbc::XParameters > xIface(m_xMainForm, UNO_QUERY);
859 if (xIface.is())
860 xIface->setLong(parameterIndex, x);
863 void SAL_CALL SbaXFormAdapter::setFloat(sal_Int32 parameterIndex, float x)
865 Reference< css::sdbc::XParameters > xIface(m_xMainForm, UNO_QUERY);
866 if (xIface.is())
867 xIface->setFloat(parameterIndex, x);
870 void SAL_CALL SbaXFormAdapter::setDouble(sal_Int32 parameterIndex, double x)
872 Reference< css::sdbc::XParameters > xIface(m_xMainForm, UNO_QUERY);
873 if (xIface.is())
874 xIface->setDouble(parameterIndex, x);
877 void SAL_CALL SbaXFormAdapter::setString(sal_Int32 parameterIndex, const OUString& x)
879 Reference< css::sdbc::XParameters > xIface(m_xMainForm, UNO_QUERY);
880 if (xIface.is())
881 xIface->setString(parameterIndex, x);
884 void SAL_CALL SbaXFormAdapter::setBytes(sal_Int32 parameterIndex, const Sequence< sal_Int8 >& x)
886 Reference< css::sdbc::XParameters > xIface(m_xMainForm, UNO_QUERY);
887 if (xIface.is())
888 xIface->setBytes(parameterIndex, x);
891 void SAL_CALL SbaXFormAdapter::setDate(sal_Int32 parameterIndex, const css::util::Date& x)
893 Reference< css::sdbc::XParameters > xIface(m_xMainForm, UNO_QUERY);
894 if (xIface.is())
895 xIface->setDate(parameterIndex, x);
898 void SAL_CALL SbaXFormAdapter::setTime(sal_Int32 parameterIndex, const css::util::Time& x)
900 Reference< css::sdbc::XParameters > xIface(m_xMainForm, UNO_QUERY);
901 if (xIface.is())
902 xIface->setTime(parameterIndex, x);
905 void SAL_CALL SbaXFormAdapter::setTimestamp(sal_Int32 parameterIndex, const css::util::DateTime& x)
907 Reference< css::sdbc::XParameters > xIface(m_xMainForm, UNO_QUERY);
908 if (xIface.is())
909 xIface->setTimestamp(parameterIndex, x);
912 void SAL_CALL SbaXFormAdapter::setBinaryStream(sal_Int32 parameterIndex, const Reference< css::io::XInputStream >& x, sal_Int32 length)
914 Reference< css::sdbc::XParameters > xIface(m_xMainForm, UNO_QUERY);
915 if (xIface.is())
916 xIface->setBinaryStream(parameterIndex, x, length);
919 void SAL_CALL SbaXFormAdapter::setCharacterStream(sal_Int32 parameterIndex, const Reference< css::io::XInputStream >& x, sal_Int32 length)
921 Reference< css::sdbc::XParameters > xIface(m_xMainForm, UNO_QUERY);
922 if (xIface.is())
923 xIface->setCharacterStream(parameterIndex, x, length);
926 void SAL_CALL SbaXFormAdapter::setObject(sal_Int32 parameterIndex, const Any& x)
928 Reference< css::sdbc::XParameters > xIface(m_xMainForm, UNO_QUERY);
929 if (xIface.is())
930 xIface->setObject(parameterIndex, x);
933 void SAL_CALL SbaXFormAdapter::setObjectWithInfo(sal_Int32 parameterIndex, const Any& x, sal_Int32 targetSqlType, sal_Int32 scale)
935 Reference< css::sdbc::XParameters > xIface(m_xMainForm, UNO_QUERY);
936 if (xIface.is())
937 xIface->setObjectWithInfo(parameterIndex, x, targetSqlType, scale);
940 void SAL_CALL SbaXFormAdapter::setRef(sal_Int32 parameterIndex, const Reference< css::sdbc::XRef >& x)
942 Reference< css::sdbc::XParameters > xIface(m_xMainForm, UNO_QUERY);
943 if (xIface.is())
944 xIface->setRef(parameterIndex, x);
947 void SAL_CALL SbaXFormAdapter::setBlob(sal_Int32 parameterIndex, const Reference< css::sdbc::XBlob >& x)
949 Reference< css::sdbc::XParameters > xIface(m_xMainForm, UNO_QUERY);
950 if (xIface.is())
951 xIface->setBlob(parameterIndex, x);
954 void SAL_CALL SbaXFormAdapter::setClob(sal_Int32 parameterIndex, const Reference< css::sdbc::XClob >& x)
956 Reference< css::sdbc::XParameters > xIface(m_xMainForm, UNO_QUERY);
957 if (xIface.is())
958 xIface->setClob(parameterIndex, x);
961 void SAL_CALL SbaXFormAdapter::setArray(sal_Int32 parameterIndex, const Reference< css::sdbc::XArray >& x)
963 Reference< css::sdbc::XParameters > xIface(m_xMainForm, UNO_QUERY);
964 if (xIface.is())
965 xIface->setArray(parameterIndex, x);
968 void SAL_CALL SbaXFormAdapter::clearParameters()
970 Reference< css::sdbc::XParameters > xIface(m_xMainForm, UNO_QUERY);
971 if (xIface.is())
972 xIface->clearParameters();
975 // css::form::XDatabaseParameterBroadcaster
976 void SAL_CALL SbaXFormAdapter::addParameterListener(const Reference< css::form::XDatabaseParameterListener >& aListener)
978 m_aParameterListeners.addInterface(aListener);
979 if (m_aParameterListeners.getLength() == 1)
981 Reference< css::form::XDatabaseParameterBroadcaster > xBroadcaster(m_xMainForm, UNO_QUERY);
982 if (xBroadcaster.is())
983 xBroadcaster->addParameterListener(&m_aParameterListeners);
987 void SAL_CALL SbaXFormAdapter::removeParameterListener(const Reference< css::form::XDatabaseParameterListener >& aListener)
989 if (m_aParameterListeners.getLength() == 1)
991 Reference< css::form::XDatabaseParameterBroadcaster > xBroadcaster(m_xMainForm, UNO_QUERY);
992 if (xBroadcaster.is())
993 xBroadcaster->removeParameterListener(&m_aParameterListeners);
995 m_aParameterListeners.removeInterface(aListener);
998 // css::container::XChild
999 Reference< XInterface > SAL_CALL SbaXFormAdapter::getParent()
1001 return m_xParent;
1004 void SAL_CALL SbaXFormAdapter::setParent(const Reference< XInterface >& Parent)
1006 m_xParent = Parent;
1009 // css::form::XSubmit
1010 void SAL_CALL SbaXFormAdapter::submit(const Reference< css::awt::XControl >& aControl, const css::awt::MouseEvent& aMouseEvt)
1012 Reference< css::form::XSubmit > xSubmit(m_xMainForm, UNO_QUERY);
1013 if (xSubmit.is())
1014 xSubmit->submit(aControl, aMouseEvt);
1017 IMPLEMENT_LISTENER_ADMINISTRATION(SbaXFormAdapter, form, SubmitListener, m_aSubmitListeners, css::form::XSubmit, m_xMainForm)
1019 // css::awt::XTabControllerModel
1020 sal_Bool SAL_CALL SbaXFormAdapter::getGroupControl()
1022 OSL_FAIL("SAL_CALL SbaXFormAdapter::getGroupControl : not supported !");
1023 return false;
1026 void SAL_CALL SbaXFormAdapter::setGroupControl(sal_Bool /*GroupControl*/)
1028 OSL_FAIL("SAL_CALL SbaXFormAdapter::setGroupControl : not supported !");
1031 void SAL_CALL SbaXFormAdapter::setControlModels(const Sequence< Reference< css::awt::XControlModel > >& /*Controls*/)
1033 OSL_FAIL("SAL_CALL SbaXFormAdapter::setControlModels : not supported !");
1036 Sequence< Reference< css::awt::XControlModel > > SAL_CALL SbaXFormAdapter::getControlModels()
1038 OSL_FAIL("SAL_CALL SbaXFormAdapter::getControlModels : not supported !");
1039 return Sequence< Reference< css::awt::XControlModel > >();
1042 void SAL_CALL SbaXFormAdapter::setGroup(const Sequence< Reference< css::awt::XControlModel > >& /*_rGroup*/, const OUString& /*GroupName*/)
1044 OSL_FAIL("SAL_CALL SbaXFormAdapter::setGroup : not supported !");
1047 sal_Int32 SAL_CALL SbaXFormAdapter::getGroupCount()
1049 OSL_FAIL("SAL_CALL SbaXFormAdapter::getGroupCount : not supported !");
1050 return 0;
1053 void SAL_CALL SbaXFormAdapter::getGroup(sal_Int32 /*nGroup*/, Sequence< Reference< css::awt::XControlModel > >& /*_rGroup*/, OUString& /*Name*/)
1055 OSL_FAIL("SAL_CALL SbaXFormAdapter::getGroup : not supported !");
1058 void SAL_CALL SbaXFormAdapter::getGroupByName(const OUString& /*Name*/, Sequence< Reference< css::awt::XControlModel > >& /*_rGroup*/)
1060 OSL_FAIL("SAL_CALL SbaXFormAdapter::getGroupByName : not supported !");
1063 // css::lang::XComponent
1064 void SAL_CALL SbaXFormAdapter::dispose()
1066 // log off all multiplexers
1067 if (m_xMainForm.is())
1068 StopListening();
1070 css::lang::EventObject aEvt(*this);
1071 m_aLoadListeners.disposeAndClear(aEvt);
1072 m_aRowSetListeners.disposeAndClear(aEvt);
1073 m_aRowSetApproveListeners.disposeAndClear(aEvt);
1074 m_aErrorListeners.disposeAndClear(aEvt);
1075 m_aParameterListeners.disposeAndClear(aEvt);
1076 m_aSubmitListeners.disposeAndClear(aEvt);
1077 m_aResetListeners.disposeAndClear(aEvt);
1079 m_aVetoablePropertyChangeListeners.disposeAndClear();
1080 m_aPropertyChangeListeners.disposeAndClear();
1081 m_aPropertiesChangeListeners.disposeAndClear(aEvt);
1083 m_aDisposeListeners.disposeAndClear(aEvt);
1084 m_aContainerListeners.disposeAndClear(aEvt);
1086 // dispose all children
1087 for (auto const& child : m_aChildren)
1089 Reference< css::beans::XPropertySet > xSet(child, UNO_QUERY);
1090 if (xSet.is())
1091 xSet->removePropertyChangeListener(PROPERTY_NAME, static_cast<css::beans::XPropertyChangeListener*>(this));
1093 Reference< css::container::XChild > xChild(child, UNO_QUERY);
1094 if (xChild.is())
1095 xChild->setParent(Reference< XInterface > ());
1097 Reference< css::lang::XComponent > xComp(child, UNO_QUERY);
1098 if (xComp.is())
1099 xComp->dispose();
1101 m_aChildren.clear();
1104 void SAL_CALL SbaXFormAdapter::addEventListener(const Reference< css::lang::XEventListener >& xListener)
1106 m_aDisposeListeners.addInterface(xListener);
1109 void SAL_CALL SbaXFormAdapter::removeEventListener(const Reference< css::lang::XEventListener >& aListener)
1111 m_aDisposeListeners.removeInterface(aListener);
1114 // css::beans::XFastPropertySet
1115 void SAL_CALL SbaXFormAdapter::setFastPropertyValue(sal_Int32 nHandle, const Any& aValue)
1117 Reference< css::beans::XFastPropertySet > xSet(m_xMainForm, UNO_QUERY);
1118 OSL_ENSURE(xSet.is(), "SAL_CALL SbaXFormAdapter::setFastPropertyValue : have no master form !");
1120 if (m_nNamePropHandle == nHandle)
1122 if (aValue.getValueType().getTypeClass() != TypeClass_STRING)
1124 throw css::lang::IllegalArgumentException();
1127 // for notifying property listeners
1128 css::beans::PropertyChangeEvent aEvt;
1129 aEvt.Source = *this;
1130 aEvt.PropertyName = PROPERTY_NAME;
1131 aEvt.PropertyHandle = m_nNamePropHandle;
1132 aEvt.OldValue <<= m_sName;
1133 aEvt.NewValue = aValue;
1135 aValue >>= m_sName;
1137 ::comphelper::OInterfaceIteratorHelper2 aIt(*m_aPropertyChangeListeners.getContainer(PROPERTY_NAME));
1138 while (aIt.hasMoreElements())
1139 static_cast< css::beans::XPropertyChangeListener*>(aIt.next())->propertyChange(aEvt);
1141 return;
1144 xSet->setFastPropertyValue(nHandle, aValue);
1147 Any SAL_CALL SbaXFormAdapter::getFastPropertyValue(sal_Int32 nHandle)
1149 Reference< css::beans::XFastPropertySet > xSet(m_xMainForm, UNO_QUERY);
1150 OSL_ENSURE(xSet.is(), "SAL_CALL SbaXFormAdapter::getFastPropertyValue : have no master form !");
1152 if (m_nNamePropHandle == nHandle)
1153 return makeAny(m_sName);
1155 return xSet->getFastPropertyValue(nHandle);
1158 // css::container::XNamed
1159 OUString SAL_CALL SbaXFormAdapter::getName()
1161 return ::comphelper::getString(getPropertyValue(PROPERTY_NAME));
1164 void SAL_CALL SbaXFormAdapter::setName(const OUString& aName)
1166 setPropertyValue(PROPERTY_NAME, makeAny(aName));
1169 // css::io::XPersistObject
1170 OUString SAL_CALL SbaXFormAdapter::getServiceName()
1172 Reference< css::io::XPersistObject > xPersist(m_xMainForm, UNO_QUERY);
1173 if (xPersist.is())
1174 return xPersist->getServiceName();
1175 return OUString();
1178 void SAL_CALL SbaXFormAdapter::write(const Reference< css::io::XObjectOutputStream >& _rxOutStream)
1180 Reference< css::io::XPersistObject > xPersist(m_xMainForm, UNO_QUERY);
1181 if (xPersist.is())
1182 xPersist->write(_rxOutStream);
1185 void SAL_CALL SbaXFormAdapter::read(const Reference< css::io::XObjectInputStream >& _rxInStream)
1187 Reference< css::io::XPersistObject > xPersist(m_xMainForm, UNO_QUERY);
1188 if (xPersist.is())
1189 xPersist->read(_rxInStream);
1192 // css::beans::XMultiPropertySet
1193 Reference< css::beans::XPropertySetInfo > SAL_CALL SbaXFormAdapter::getPropertySetInfo()
1195 Reference< css::beans::XMultiPropertySet > xSet(m_xMainForm, UNO_QUERY);
1196 if (!xSet.is())
1197 return Reference< css::beans::XPropertySetInfo > ();
1199 Reference< css::beans::XPropertySetInfo > xReturn = xSet->getPropertySetInfo();
1200 if (-1 == m_nNamePropHandle)
1202 // we need to determine the handle for the NAME property
1203 const Sequence<css::beans::Property> aProps = xReturn->getProperties();
1204 for (const css::beans::Property& rProp : aProps)
1206 if (rProp.Name == PROPERTY_NAME)
1208 m_nNamePropHandle = rProp.Handle;
1209 break;
1213 return xReturn;
1216 void SAL_CALL SbaXFormAdapter::setPropertyValues(const Sequence< OUString >& PropertyNames, const Sequence< Any >& Values)
1218 Reference< css::beans::XMultiPropertySet > xSet(m_xMainForm, UNO_QUERY);
1219 if (xSet.is())
1220 xSet->setPropertyValues(PropertyNames, Values);
1223 Sequence< Any > SAL_CALL SbaXFormAdapter::getPropertyValues(const Sequence< OUString >& aPropertyNames)
1225 Reference< css::beans::XMultiPropertySet > xSet(m_xMainForm, UNO_QUERY);
1226 if (!xSet.is())
1227 return Sequence< Any>(aPropertyNames.getLength());
1229 Sequence< Any> aReturn = xSet->getPropertyValues(aPropertyNames);
1231 // search for (and fake) the NAME property
1232 OSL_ENSURE(aReturn.getLength() == aPropertyNames.getLength(), "SAL_CALL SbaXFormAdapter::getPropertyValues : the main form returned an invalid-length sequence !");
1233 for (sal_Int32 i=0; i<aPropertyNames.getLength(); ++i)
1234 if (aPropertyNames[i] == PROPERTY_NAME)
1236 aReturn[i] <<= m_sName;
1237 break;
1240 return aReturn;
1243 void SAL_CALL SbaXFormAdapter::addPropertiesChangeListener(const Sequence< OUString>& /*aPropertyNames*/, const Reference< css::beans::XPropertiesChangeListener >& xListener)
1245 // we completely ignore the property names, _all_ changes of _all_ properties will be forwarded to _all_ listeners
1246 m_aPropertiesChangeListeners.addInterface(xListener);
1247 if (m_aPropertiesChangeListeners.getLength() == 1)
1249 Reference< css::beans::XMultiPropertySet > xBroadcaster(m_xMainForm, UNO_QUERY);
1250 if (xBroadcaster.is())
1251 xBroadcaster->addPropertiesChangeListener(Sequence< OUString>{""}, &m_aPropertiesChangeListeners);
1255 void SAL_CALL SbaXFormAdapter::removePropertiesChangeListener(const Reference< css::beans::XPropertiesChangeListener >& Listener)
1257 if (m_aPropertiesChangeListeners.getLength() == 1)
1259 Reference< css::beans::XMultiPropertySet > xBroadcaster(m_xMainForm, UNO_QUERY);
1260 if (xBroadcaster.is())
1261 xBroadcaster->removePropertiesChangeListener(&m_aPropertiesChangeListeners);
1263 m_aPropertiesChangeListeners.removeInterface(Listener);
1266 void SAL_CALL SbaXFormAdapter::firePropertiesChangeEvent(const Sequence< OUString >& aPropertyNames, const Reference< css::beans::XPropertiesChangeListener >& xListener)
1268 Reference< css::beans::XMultiPropertySet > xSet(m_xMainForm, UNO_QUERY);
1269 if (xSet.is())
1270 xSet->firePropertiesChangeEvent(aPropertyNames, xListener);
1273 // css::beans::XPropertySet
1274 void SAL_CALL SbaXFormAdapter::setPropertyValue(const OUString& aPropertyName, const Any& aValue)
1276 Reference< css::beans::XPropertySet > xSet(m_xMainForm, UNO_QUERY);
1277 if (!xSet.is())
1278 return;
1280 // special handling for the "name" property
1281 if (aPropertyName == PROPERTY_NAME)
1282 setFastPropertyValue(m_nNamePropHandle, aValue);
1284 xSet->setPropertyValue(aPropertyName, aValue);
1287 Any SAL_CALL SbaXFormAdapter::getPropertyValue(const OUString& PropertyName)
1289 Reference< css::beans::XPropertySet > xSet(m_xMainForm, UNO_QUERY);
1290 if (!xSet.is())
1291 return Any();
1293 // special handling for the "name" property
1294 if (PropertyName == PROPERTY_NAME)
1295 return getFastPropertyValue(m_nNamePropHandle);
1297 return xSet->getPropertyValue(PropertyName);
1300 IMPLEMENT_PROPERTY_LISTENER_ADMINISTRATION(SbaXFormAdapter, PropertyChangeListener, m_aPropertyChangeListeners, css::beans::XPropertySet, m_xMainForm);
1301 IMPLEMENT_PROPERTY_LISTENER_ADMINISTRATION(SbaXFormAdapter, VetoableChangeListener, m_aVetoablePropertyChangeListeners, css::beans::XPropertySet, m_xMainForm);
1303 // css::util::XCancellable
1304 void SAL_CALL SbaXFormAdapter::cancel()
1306 Reference< css::util::XCancellable > xCancel(m_xMainForm, UNO_QUERY);
1307 if (xCancel.is())
1308 return;
1309 xCancel->cancel();
1312 // css::beans::XPropertyState
1313 css::beans::PropertyState SAL_CALL SbaXFormAdapter::getPropertyState(const OUString& PropertyName)
1315 Reference< css::beans::XPropertyState > xState(m_xMainForm, UNO_QUERY);
1316 if (xState.is())
1317 return xState->getPropertyState(PropertyName);
1318 return css::beans::PropertyState_DEFAULT_VALUE;
1321 Sequence< css::beans::PropertyState> SAL_CALL SbaXFormAdapter::getPropertyStates(const Sequence< OUString >& aPropertyName)
1323 Reference< css::beans::XPropertyState > xState(m_xMainForm, UNO_QUERY);
1324 if (xState.is())
1325 return xState->getPropertyStates(aPropertyName);
1327 // set them all to DEFAULT
1328 Sequence< css::beans::PropertyState> aReturn(aPropertyName.getLength());
1329 for (css::beans::PropertyState& rState : asNonConstRange(aReturn))
1330 rState = css::beans::PropertyState_DEFAULT_VALUE;
1331 return aReturn;
1334 void SAL_CALL SbaXFormAdapter::setPropertyToDefault(const OUString& PropertyName)
1336 Reference< css::beans::XPropertyState > xState(m_xMainForm, UNO_QUERY);
1337 if (xState.is())
1338 xState->setPropertyToDefault(PropertyName);
1341 Any SAL_CALL SbaXFormAdapter::getPropertyDefault(const OUString& aPropertyName)
1343 Reference< css::beans::XPropertyState > xState(m_xMainForm, UNO_QUERY);
1344 if (xState.is())
1345 return xState->getPropertyDefault(aPropertyName);
1346 return Any();
1349 // css::form::XReset
1350 void SAL_CALL SbaXFormAdapter::reset()
1352 Reference< css::form::XReset > xReset(m_xMainForm, UNO_QUERY);
1353 if (xReset.is())
1354 xReset->reset();
1357 IMPLEMENT_LISTENER_ADMINISTRATION(SbaXFormAdapter, form, ResetListener, m_aResetListeners, css::form::XReset, m_xMainForm)
1359 // css::container::XNameContainer
1360 void SbaXFormAdapter::implInsert(const Any& aElement, sal_Int32 nIndex, const OUString* pNewElName)
1362 // extract the form component
1363 if (aElement.getValueType().getTypeClass() != TypeClass_INTERFACE)
1365 throw css::lang::IllegalArgumentException();
1368 Reference< css::form::XFormComponent > xElement(aElement, UNO_QUERY);
1369 if (!xElement.is())
1371 throw css::lang::IllegalArgumentException();
1374 // for the name we need the propset
1375 Reference< css::beans::XPropertySet > xElementSet(xElement, UNO_QUERY);
1376 if (!xElementSet.is())
1378 throw css::lang::IllegalArgumentException();
1380 OUString sName;
1383 if (pNewElName)
1384 xElementSet->setPropertyValue(PROPERTY_NAME, makeAny(*pNewElName));
1386 xElementSet->getPropertyValue(PROPERTY_NAME) >>= sName;
1388 catch(Exception&)
1390 // the set didn't support the name prop
1391 throw css::lang::IllegalArgumentException();
1394 // check the index
1395 OSL_ASSERT(nIndex >= 0);
1396 if (sal::static_int_cast< sal_uInt32 >(nIndex) > m_aChildren.size())
1397 nIndex = m_aChildren.size();
1399 OSL_ENSURE(m_aChildren.size() == m_aChildNames.size(), "SAL_CALL SbaXFormAdapter::implInsert : inconsistent container state !");
1400 m_aChildren.insert(m_aChildren.begin() + nIndex, xElement);
1401 m_aChildNames.insert(m_aChildNames.begin() + nIndex, sName);
1403 // listen for a change of the name
1404 xElementSet->addPropertyChangeListener(PROPERTY_NAME, static_cast<css::beans::XPropertyChangeListener*>(this));
1406 // we are now the parent of the new element
1407 xElement->setParent(static_cast<css::container::XContainer*>(this));
1409 // notify the container listeners
1410 css::container::ContainerEvent aEvt;
1411 aEvt.Source = *this;
1412 aEvt.Accessor <<= nIndex;
1413 aEvt.Element <<= xElement;
1414 ::comphelper::OInterfaceIteratorHelper2 aIt(m_aContainerListeners);
1415 while (aIt.hasMoreElements())
1416 static_cast< css::container::XContainerListener*>(aIt.next())->elementInserted(aEvt);
1419 sal_Int32 SbaXFormAdapter::implGetPos(const OUString& rName)
1421 std::vector< OUString>::const_iterator aIter = std::find( m_aChildNames.begin(),
1422 m_aChildNames.end(),
1423 rName);
1425 if(aIter != m_aChildNames.end())
1426 return aIter - m_aChildNames.begin();
1428 return -1;
1431 void SAL_CALL SbaXFormAdapter::insertByName(const OUString& aName, const Any& aElement)
1433 implInsert(aElement, m_aChildren.size(), &aName);
1436 void SAL_CALL SbaXFormAdapter::removeByName(const OUString& Name)
1438 sal_Int32 nPos = implGetPos(Name);
1439 if (-1 == nPos)
1441 throw css::container::NoSuchElementException();
1443 removeByIndex(nPos);
1446 // css::container::XNameReplace
1447 void SAL_CALL SbaXFormAdapter::replaceByName(const OUString& aName, const Any& aElement)
1449 sal_Int32 nPos = implGetPos(aName);
1450 if (-1 == nPos)
1452 throw css::container::NoSuchElementException();
1454 replaceByIndex(nPos, aElement);
1457 // css::container::XNameAccess
1458 Any SAL_CALL SbaXFormAdapter::getByName(const OUString& aName)
1460 sal_Int32 nPos = implGetPos(aName);
1461 if (-1 == nPos)
1463 throw css::container::NoSuchElementException();
1465 return makeAny(m_aChildren[nPos]);
1468 Sequence< OUString > SAL_CALL SbaXFormAdapter::getElementNames()
1470 return Sequence< OUString >(m_aChildNames.data(), m_aChildNames.size());
1473 sal_Bool SAL_CALL SbaXFormAdapter::hasByName(const OUString& aName)
1475 return (-1 != implGetPos(aName));
1478 // css::container::XElementAccess
1479 Type SAL_CALL SbaXFormAdapter::getElementType()
1481 return cppu::UnoType<css::form::XFormComponent>::get();
1484 sal_Bool SAL_CALL SbaXFormAdapter::hasElements()
1486 return !m_aChildren.empty();
1489 // css::container::XIndexContainer
1490 void SAL_CALL SbaXFormAdapter::insertByIndex(sal_Int32 _rIndex, const Any& Element)
1492 if ( ( _rIndex < 0 ) || ( o3tl::make_unsigned(_rIndex) >= m_aChildren.size() ) )
1493 throw css::lang::IndexOutOfBoundsException();
1494 implInsert(Element, _rIndex);
1497 void SAL_CALL SbaXFormAdapter::removeByIndex(sal_Int32 _rIndex)
1499 if ( ( _rIndex < 0 ) || ( o3tl::make_unsigned(_rIndex) >= m_aChildren.size() ) )
1500 throw css::lang::IndexOutOfBoundsException();
1502 Reference< css::form::XFormComponent > xAffected = *(m_aChildren.begin() + _rIndex);
1504 OSL_ENSURE(m_aChildren.size() == m_aChildNames.size(), "SAL_CALL SbaXFormAdapter::removeByIndex : inconsistent container state !");
1505 m_aChildren.erase(m_aChildren.begin() + _rIndex);
1506 m_aChildNames.erase(m_aChildNames.begin() + _rIndex);
1508 // no need to listen anymore
1509 Reference< css::beans::XPropertySet > xAffectedSet(xAffected, UNO_QUERY);
1510 xAffectedSet->removePropertyChangeListener(PROPERTY_NAME, static_cast<css::beans::XPropertyChangeListener*>(this));
1512 // we are no longer the parent
1513 xAffected->setParent(Reference< XInterface > ());
1515 // notify container listeners
1516 css::container::ContainerEvent aEvt;
1517 aEvt.Source = *this;
1518 aEvt.Element <<= xAffected;
1519 ::comphelper::OInterfaceIteratorHelper2 aIt(m_aContainerListeners);
1520 while (aIt.hasMoreElements())
1521 static_cast< css::container::XContainerListener*>(aIt.next())->elementRemoved(aEvt);
1525 // css::container::XIndexReplace
1526 void SAL_CALL SbaXFormAdapter::replaceByIndex(sal_Int32 _rIndex, const Any& Element)
1528 if ( ( _rIndex < 0 ) || ( o3tl::make_unsigned(_rIndex) >= m_aChildren.size() ) )
1529 throw css::lang::IndexOutOfBoundsException();
1531 // extract the form component
1532 if (Element.getValueType().getTypeClass() != TypeClass_INTERFACE)
1534 throw css::lang::IllegalArgumentException();
1537 Reference< css::form::XFormComponent > xElement(Element, UNO_QUERY);
1538 if (!xElement.is())
1540 throw css::lang::IllegalArgumentException();
1543 // for the name we need the propset
1544 Reference< css::beans::XPropertySet > xElementSet(xElement, UNO_QUERY);
1545 if (!xElementSet.is())
1547 throw css::lang::IllegalArgumentException();
1549 OUString sName;
1552 xElementSet->getPropertyValue(PROPERTY_NAME) >>= sName;
1554 catch(Exception&)
1556 // the set didn't support the name prop
1557 throw css::lang::IllegalArgumentException();
1560 Reference< css::form::XFormComponent > xOld = *(m_aChildren.begin() + _rIndex);
1562 OSL_ENSURE(m_aChildren.size() == m_aChildNames.size(), "SAL_CALL SbaXFormAdapter::replaceByIndex : inconsistent container state !");
1563 *(m_aChildren.begin() + _rIndex) = xElement;
1564 *(m_aChildNames.begin() + _rIndex) = sName;
1566 // correct property change listening
1567 Reference< css::beans::XPropertySet > xOldSet(xOld, UNO_QUERY);
1568 xOldSet->removePropertyChangeListener(PROPERTY_NAME, static_cast<css::beans::XPropertyChangeListener*>(this));
1569 xElementSet->addPropertyChangeListener(PROPERTY_NAME, static_cast<css::beans::XPropertyChangeListener*>(this));
1571 // parent reset
1572 xOld->setParent(Reference< XInterface > ());
1573 xElement->setParent(static_cast<css::container::XContainer*>(this));
1575 // notify container listeners
1576 css::container::ContainerEvent aEvt;
1577 aEvt.Source = *this;
1578 aEvt.Accessor <<= _rIndex;
1579 aEvt.Element <<= xElement;
1580 aEvt.ReplacedElement <<= xOld;
1582 ::comphelper::OInterfaceIteratorHelper2 aIt(m_aContainerListeners);
1583 while (aIt.hasMoreElements())
1584 static_cast< css::container::XContainerListener*>(aIt.next())->elementReplaced(aEvt);
1587 // css::container::XIndexAccess
1588 sal_Int32 SAL_CALL SbaXFormAdapter::getCount()
1590 return m_aChildren.size();
1593 Any SAL_CALL SbaXFormAdapter::getByIndex(sal_Int32 _rIndex)
1595 if ( ( _rIndex < 0 ) || ( o3tl::make_unsigned(_rIndex) >= m_aChildren.size() ) )
1596 throw css::lang::IndexOutOfBoundsException();
1598 Reference< css::form::XFormComponent > xElement = *(m_aChildren.begin() + _rIndex);
1599 return makeAny(xElement);
1602 // css::container::XContainer
1603 void SAL_CALL SbaXFormAdapter::addContainerListener(const Reference< css::container::XContainerListener >& xListener)
1605 m_aContainerListeners.addInterface(xListener);
1608 void SAL_CALL SbaXFormAdapter::removeContainerListener(const Reference< css::container::XContainerListener >& xListener)
1610 m_aContainerListeners.removeInterface(xListener);
1613 // css::container::XEnumerationAccess
1614 Reference< css::container::XEnumeration > SAL_CALL SbaXFormAdapter::createEnumeration()
1616 return new ::comphelper::OEnumerationByName(this);
1619 // css::beans::XPropertyChangeListener
1620 void SAL_CALL SbaXFormAdapter::propertyChange(const css::beans::PropertyChangeEvent& evt)
1622 if (evt.PropertyName != PROPERTY_NAME)
1623 return;
1625 std::vector< css::uno::Reference< css::form::XFormComponent > >::const_iterator aIter = std::find_if( m_aChildren.begin(),
1626 m_aChildren.end(),
1627 [&evt](css::uno::Reference< css::uno::XInterface > const & x) { return x == evt.Source; });
1629 if(aIter != m_aChildren.end())
1631 sal_Int32 nPos = aIter - m_aChildren.begin();
1632 OSL_ENSURE(*(m_aChildNames.begin() + nPos) == ::comphelper::getString(evt.OldValue), "SAL_CALL SbaXFormAdapter::propertyChange : object has a wrong name !");
1633 *(m_aChildNames.begin() + nPos) = ::comphelper::getString(evt.NewValue);
1637 // css::lang::XEventListener
1638 void SAL_CALL SbaXFormAdapter::disposing(const css::lang::EventObject& Source)
1640 // was it our main form ?
1641 if (Source.Source == m_xMainForm)
1642 dispose();
1644 std::vector< css::uno::Reference< css::form::XFormComponent > >::const_iterator aIter = std::find_if( m_aChildren.begin(),
1645 m_aChildren.end(),
1646 [&Source](css::uno::Reference< css::uno::XInterface > const & x) { return x == Source.Source; });
1647 if(aIter != m_aChildren.end())
1648 removeByIndex(aIter - m_aChildren.begin());
1651 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */