summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLionel Elie Mamane <lionel@mamane.lu>2015-07-21 16:58:38 +0200
committerLionel Elie Mamane <lionel@mamane.lu>2015-07-21 18:05:19 +0200
commit42f0a84764add89c6b22943d55c821acbcf3f37d (patch)
treec66846d37a1187bbf70e9ce8a0ae3ff3bbcef386
parentbb7c3821208feef6cf713591a9805e4118dd7554 (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
-rw-r--r--svx/source/form/fmvwimp.cxx96
1 files changed, 79 insertions, 17 deletions
diff --git a/svx/source/form/fmvwimp.cxx b/svx/source/form/fmvwimp.cxx
index 51db4998cc73..6d6c9a63225c 100644
--- a/svx/source/form/fmvwimp.cxx
+++ b/svx/source/form/fmvwimp.cxx
@@ -654,6 +654,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)
{
@@ -668,6 +728,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();
@@ -681,6 +748,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
@@ -690,27 +758,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;