[Libreoffice-commits] core.git: Branch 'libreoffice-5-0' - svx/source

Lionel Elie Mamane lionel at mamane.lu
Fri Aug 7 10:07:25 PDT 2015


 svx/source/form/fmvwimp.cxx |   96 ++++++++++++++++++++++++++++++++++++--------
 1 file changed, 79 insertions(+), 17 deletions(-)

New commits:
commit 107edbf3c1d109f915b5fbed03d2625c0a45d780
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Tue Jul 21 16:58:38 2015 +0200

    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 at libreoffice.org>
    Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice at googlemail.com>

diff --git a/svx/source/form/fmvwimp.cxx b/svx/source/form/fmvwimp.cxx
index 8044e8b..5fae555 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;


More information about the Libreoffice-commits mailing list