diff options
author | Lionel Elie Mamane <lionel@mamane.lu> | 2015-07-21 16:58:38 +0200 |
---|---|---|
committer | Christian Lohmaier <lohmaier+LibreOffice@googlemail.com> | 2015-08-07 17:07:05 +0000 |
commit | 107edbf3c1d109f915b5fbed03d2625c0a45d780 (patch) | |
tree | 981ddceee12186c819c806b5694e794532195d8b /svx | |
parent | 3136d9698054cfe0f68a424ebf03f0fd5e017373 (diff) |
form document view activation: prioritise activation of already active form
This avoids arbitrarily switching to the first form in the document,
which would do a (premature!) save to the database of the
modifications pending in the active form. This may lead to a database
error, when the data is not in a shape to be written to the database,
e.g. when on an insertion row and not all mandatory fields have been
filled in. This then pops up an error message to the user.
Change-Id: I30bb533598ca707b892bb7155e54ce05d4ddf275
Reviewed-on: https://gerrit.libreoffice.org/17269
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/form/fmvwimp.cxx | 96 |
1 files changed, 79 insertions, 17 deletions
diff --git a/svx/source/form/fmvwimp.cxx b/svx/source/form/fmvwimp.cxx index 8044e8b6c6dc..5fae555d94d0 100644 --- a/svx/source/form/fmvwimp.cxx +++ b/svx/source/form/fmvwimp.cxx @@ -656,6 +656,66 @@ void FmXFormView::resumeTabOrderUpdate() m_aNeedTabOrderUpdate.clear(); } +namespace +{ + bool isActivableDatabaseForm(const Reference< XFormController > &xController) + { + // only database forms are to be activated + Reference< XRowSet > xForm(xController->getModel(), UNO_QUERY); + if ( !xForm.is() || !getConnection( xForm ).is() ) + return false; + + Reference< XPropertySet > xFormSet( xForm, UNO_QUERY ); + if ( !xFormSet.is() ) + { + SAL_WARN( "svx.form", "FmXFormView::OnActivate: a form which does not have properties?" ); + return false; + } + + const OUString aSource = ::comphelper::getString( xFormSet->getPropertyValue( FM_PROP_COMMAND ) ); + + return !aSource.isEmpty(); + } + + class find_active_databaseform + { + const Reference< XFormController > xActiveController; + + public: + + find_active_databaseform( const Reference< XFormController > _xActiveController ) + : xActiveController(_xActiveController ) + {} + + Reference < XFormController > operator() (const Reference< XFormController > &xController) + { + if(xController == xActiveController && isActivableDatabaseForm(xController)) + return xController; + + Reference< XIndexAccess > xSubControllers( xController, UNO_QUERY ); + if ( !xSubControllers.is() ) + { + SAL_WARN( "svx.form", "FmXFormView::OnActivate: a form controller which does not have children?" ); + return nullptr; + } + + for(sal_Int32 i = 0; i < xSubControllers->getCount(); ++i) + { + const Any a(xSubControllers->getByIndex(i)); + Reference < XFormController > xI; + if ((a >>= xI) && xI.is()) + { + Reference < XFormController > xRes(operator()(xI)); + if (xRes.is()) + return xRes; + } + } + + return nullptr; + } + }; +} + IMPL_LINK_NOARG(FmXFormView, OnActivate) { @@ -670,6 +730,13 @@ IMPL_LINK_NOARG(FmXFormView, OnActivate) // setting the controller to activate if (m_pView->GetFormShell() && m_pView->GetActualOutDev() && m_pView->GetActualOutDev()->GetOutDevType() == OUTDEV_WINDOW) { + FmXFormShell* const pShImpl = m_pView->GetFormShell()->GetImpl(); + + if(!pShImpl) + return 0; + + find_active_databaseform fad(pShImpl->getActiveController()); + vcl::Window* pWindow = const_cast<vcl::Window*>(static_cast<const vcl::Window*>(m_pView->GetActualOutDev())); PFormViewPageWindowAdapter pAdapter = m_aPageWindowAdapters.empty() ? NULL : m_aPageWindowAdapters[0]; for ( PageWindowAdapterList::const_iterator i = m_aPageWindowAdapters.begin(); @@ -683,6 +750,7 @@ IMPL_LINK_NOARG(FmXFormView, OnActivate) if ( pAdapter.get() ) { + Reference< XFormController > xControllerToActivate; for ( ::std::vector< Reference< XFormController > >::const_iterator i = pAdapter->GetList().begin(); i != pAdapter->GetList().end(); ++i @@ -692,27 +760,21 @@ IMPL_LINK_NOARG(FmXFormView, OnActivate) if ( !xController.is() ) continue; - // only database forms are to be activated - Reference< XRowSet > xForm(xController->getModel(), UNO_QUERY); - if ( !xForm.is() || !getConnection( xForm ).is() ) - continue; - - Reference< XPropertySet > xFormSet( xForm, UNO_QUERY ); - if ( !xFormSet.is() ) { - SAL_WARN( "svx.form", "FmXFormView::OnActivate: a form which does not have properties?" ); - continue; + Reference< XFormController > xActiveController(fad(xController)); + if (xActiveController.is()) + { + xControllerToActivate = xActiveController; + break; + } } - const OUString aSource = ::comphelper::getString( xFormSet->getPropertyValue( FM_PROP_COMMAND ) ); - if ( !aSource.isEmpty() ) - { - FmXFormShell* pShImpl = m_pView->GetFormShell()->GetImpl(); - if ( pShImpl ) - pShImpl->setActiveController( xController ); - break; - } + if(xControllerToActivate.is() || !isActivableDatabaseForm(xController)) + continue; + + xControllerToActivate = xController; } + pShImpl->setActiveController( xControllerToActivate ); } } return 0; |