[Libreoffice-commits] core.git: svtools/inc svtools/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Sat Aug 14 09:12:24 UTC 2021


 svtools/inc/mousefunction.hxx                |  133 +++++++++++++++++++++++++++
 svtools/inc/table/defaultinputhandler.hxx    |   19 ++-
 svtools/source/table/defaultinputhandler.cxx |  113 +++++++++-------------
 svtools/source/table/mousefunction.cxx       |    2 
 svtools/source/table/mousefunction.hxx       |  132 --------------------------
 5 files changed, 193 insertions(+), 206 deletions(-)

New commits:
commit ecfc229b090473ad28d4b6947e2e0e0d9cd3ef4b
Author:     Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Fri Aug 13 18:58:50 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sat Aug 14 11:11:49 2021 +0200

    flatten svt::table::DefaultInputHandler
    
    Change-Id: Idba4039bbedd7c276505c5e9763b559d505cf7a0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120467
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/svtools/inc/mousefunction.hxx b/svtools/inc/mousefunction.hxx
new file mode 100644
index 000000000000..979a2b6c463f
--- /dev/null
+++ b/svtools/inc/mousefunction.hxx
@@ -0,0 +1,133 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include "table/tabletypes.hxx"
+
+#include <salhelper/simplereferenceobject.hxx>
+
+class MouseEvent;
+
+namespace svt::table
+{
+class ITableControl;
+
+//= FunctionResult
+
+enum FunctionResult
+{
+    ActivateFunction,
+    ContinueFunction,
+    DeactivateFunction,
+
+    SkipFunction
+};
+
+//= MouseFunction
+
+class MouseFunction : public ::salhelper::SimpleReferenceObject
+{
+public:
+    MouseFunction() {}
+    MouseFunction(const MouseFunction&) = delete;
+    MouseFunction& operator=(const MouseFunction&) = delete;
+    virtual FunctionResult handleMouseMove(ITableControl& i_tableControl, MouseEvent const& i_event)
+        = 0;
+    virtual FunctionResult handleMouseDown(ITableControl& i_tableControl, MouseEvent const& i_event)
+        = 0;
+    virtual FunctionResult handleMouseUp(ITableControl& i_tableControl, MouseEvent const& i_event)
+        = 0;
+
+protected:
+    virtual ~MouseFunction() override {}
+};
+
+//= ColumnResize
+
+class ColumnResize : public MouseFunction
+{
+public:
+    ColumnResize()
+        : m_nResizingColumn(COL_INVALID)
+    {
+    }
+
+public:
+    // MouseFunction
+    virtual FunctionResult handleMouseMove(ITableControl& i_tableControl,
+                                           MouseEvent const& i_event) override;
+    virtual FunctionResult handleMouseDown(ITableControl& i_tableControl,
+                                           MouseEvent const& i_event) override;
+    virtual FunctionResult handleMouseUp(ITableControl& i_tableControl,
+                                         MouseEvent const& i_event) override;
+
+private:
+    ColPos m_nResizingColumn;
+};
+
+//= RowSelection
+
+class RowSelection : public MouseFunction
+{
+public:
+    RowSelection()
+        : m_bActive(false)
+    {
+    }
+
+public:
+    // MouseFunction
+    virtual FunctionResult handleMouseMove(ITableControl& i_tableControl,
+                                           MouseEvent const& i_event) override;
+    virtual FunctionResult handleMouseDown(ITableControl& i_tableControl,
+                                           MouseEvent const& i_event) override;
+    virtual FunctionResult handleMouseUp(ITableControl& i_tableControl,
+                                         MouseEvent const& i_event) override;
+
+private:
+    bool m_bActive;
+};
+
+//= ColumnSortHandler
+
+class ColumnSortHandler : public MouseFunction
+{
+public:
+    ColumnSortHandler()
+        : m_nActiveColumn(COL_INVALID)
+    {
+    }
+
+public:
+    // MouseFunction
+    virtual FunctionResult handleMouseMove(ITableControl& i_tableControl,
+                                           MouseEvent const& i_event) override;
+    virtual FunctionResult handleMouseDown(ITableControl& i_tableControl,
+                                           MouseEvent const& i_event) override;
+    virtual FunctionResult handleMouseUp(ITableControl& i_tableControl,
+                                         MouseEvent const& i_event) override;
+
+private:
+    ColPos m_nActiveColumn;
+};
+
+} // namespace svt::table
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svtools/inc/table/defaultinputhandler.hxx b/svtools/inc/table/defaultinputhandler.hxx
index c09328c50e66..136979db8576 100644
--- a/svtools/inc/table/defaultinputhandler.hxx
+++ b/svtools/inc/table/defaultinputhandler.hxx
@@ -20,24 +20,18 @@
 #pragma once
 
 #include <table/tableinputhandler.hxx>
+#include <rtl/ref.hxx>
+#include <mousefunction.hxx>
 
 #include <memory>
+#include <vector>
 
 
 namespace svt::table
 {
 
-
-    struct DefaultInputHandler_Impl;
-
-
-    //= DefaultInputHandler
-
     class DefaultInputHandler final : public ITableInputHandler
     {
-    private:
-        ::std::unique_ptr< DefaultInputHandler_Impl > m_pImpl;
-
     public:
         DefaultInputHandler();
         virtual ~DefaultInputHandler() override;
@@ -48,6 +42,13 @@ namespace svt::table
         virtual bool    KeyInput        ( ITableControl& _rControl, const KeyEvent& rKEvt ) override;
         virtual bool    GetFocus        ( ITableControl& _rControl ) override;
         virtual bool    LoseFocus       ( ITableControl& _rControl ) override;
+
+    private:
+        bool delegateMouseEvent( ITableControl& i_control, const MouseEvent& i_event,
+            FunctionResult ( MouseFunction::*i_handlerMethod )( ITableControl&, const MouseEvent& ) );
+
+        rtl::Reference< MouseFunction >  pActiveFunction;
+        std::vector< rtl::Reference< MouseFunction > >  aMouseFunctions;
     };
 
 
diff --git a/svtools/source/table/defaultinputhandler.cxx b/svtools/source/table/defaultinputhandler.cxx
index 6b84fbf318cf..0263b29689f5 100644
--- a/svtools/source/table/defaultinputhandler.cxx
+++ b/svtools/source/table/defaultinputhandler.cxx
@@ -21,8 +21,6 @@
 #include <table/defaultinputhandler.hxx>
 #include <table/tablecontrolinterface.hxx>
 
-#include "mousefunction.hxx"
-
 #include <vcl/event.hxx>
 #include <osl/diagnose.h>
 
@@ -31,24 +29,14 @@ namespace svt::table
 {
 
 
-    typedef ::rtl::Reference< MouseFunction >  PMouseFunction;
-    typedef ::std::vector< PMouseFunction >     MouseFunctions;
-    struct DefaultInputHandler_Impl
-    {
-        PMouseFunction  pActiveFunction;
-        MouseFunctions  aMouseFunctions;
-    };
-
-
     //= DefaultInputHandler
 
 
     DefaultInputHandler::DefaultInputHandler()
-        :m_pImpl( new DefaultInputHandler_Impl )
     {
-        m_pImpl->aMouseFunctions.push_back( new ColumnResize );
-        m_pImpl->aMouseFunctions.push_back( new RowSelection );
-        m_pImpl->aMouseFunctions.push_back( new ColumnSortHandler );
+        aMouseFunctions.push_back( new ColumnResize );
+        aMouseFunctions.push_back( new RowSelection );
+        aMouseFunctions.push_back( new ColumnSortHandler );
     }
 
 
@@ -57,78 +45,75 @@ namespace svt::table
     }
 
 
-    namespace
+    bool DefaultInputHandler::delegateMouseEvent( ITableControl& i_control, const MouseEvent& i_event,
+        FunctionResult ( MouseFunction::*i_handlerMethod )( ITableControl&, const MouseEvent& ) )
     {
-        bool lcl_delegateMouseEvent( DefaultInputHandler_Impl& i_impl, ITableControl& i_control, const MouseEvent& i_event,
-            FunctionResult ( MouseFunction::*i_handlerMethod )( ITableControl&, const MouseEvent& ) )
+        if ( pActiveFunction.is() )
         {
-            if ( i_impl.pActiveFunction.is() )
+            bool furtherHandler = false;
+            switch ( (pActiveFunction.get()->*i_handlerMethod)( i_control, i_event ) )
             {
-                bool furtherHandler = false;
-                switch ( (i_impl.pActiveFunction.get()->*i_handlerMethod)( i_control, i_event ) )
-                {
-                case ActivateFunction:
-                    OSL_ENSURE( false, "lcl_delegateMouseEvent: unexpected - function already *is* active!" );
-                    break;
-                case ContinueFunction:
-                    break;
-                case DeactivateFunction:
-                    i_impl.pActiveFunction.clear();
-                    break;
-                case SkipFunction:
-                    furtherHandler = true;
-                    break;
-                }
-                if ( !furtherHandler )
-                    // handled the event
-                    return true;
+            case ActivateFunction:
+                OSL_ENSURE( false, "lcl_delegateMouseEvent: unexpected - function already *is* active!" );
+                break;
+            case ContinueFunction:
+                break;
+            case DeactivateFunction:
+                pActiveFunction.clear();
+                break;
+            case SkipFunction:
+                furtherHandler = true;
+                break;
             }
+            if ( !furtherHandler )
+                // handled the event
+                return true;
+        }
+
+        // ask all other handlers
+        bool handled = false;
+        for (auto const& mouseFunction : aMouseFunctions)
+        {
+            if (handled)
+                break;
+            if (mouseFunction == pActiveFunction)
+                // we already invoked this function
+                continue;
 
-            // ask all other handlers
-            bool handled = false;
-            for (auto const& mouseFunction : i_impl.aMouseFunctions)
+            switch ( (mouseFunction.get()->*i_handlerMethod)( i_control, i_event ) )
             {
-                if (handled)
-                    break;
-                if (mouseFunction == i_impl.pActiveFunction)
-                    // we already invoked this function
-                    continue;
-
-                switch ( (mouseFunction.get()->*i_handlerMethod)( i_control, i_event ) )
-                {
-                case ActivateFunction:
-                    i_impl.pActiveFunction = mouseFunction;
-                    handled = true;
-                    break;
-                case ContinueFunction:
-                case DeactivateFunction:
-                    OSL_ENSURE( false, "lcl_delegateMouseEvent: unexpected: inactive handler cannot be continued or deactivated!" );
-                    break;
-                case SkipFunction:
-                    handled = false;
-                    break;
-                }
+            case ActivateFunction:
+                pActiveFunction = mouseFunction;
+                handled = true;
+                break;
+            case ContinueFunction:
+            case DeactivateFunction:
+                OSL_ENSURE( false, "lcl_delegateMouseEvent: unexpected: inactive handler cannot be continued or deactivated!" );
+                break;
+            case SkipFunction:
+                handled = false;
+                break;
             }
-            return handled;
         }
+        return handled;
     }
 
 
     bool DefaultInputHandler::MouseMove( ITableControl& i_tableControl, const MouseEvent& i_event )
     {
-        return lcl_delegateMouseEvent( *m_pImpl, i_tableControl, i_event, &MouseFunction::handleMouseMove );
+        return delegateMouseEvent( i_tableControl, i_event, &MouseFunction::handleMouseMove );
     }
 
 
     bool DefaultInputHandler::MouseButtonDown( ITableControl& i_tableControl, const MouseEvent& i_event )
     {
-        return lcl_delegateMouseEvent( *m_pImpl, i_tableControl, i_event, &MouseFunction::handleMouseDown );
+        return delegateMouseEvent( i_tableControl, i_event, &MouseFunction::handleMouseDown );
     }
 
 
     bool DefaultInputHandler::MouseButtonUp( ITableControl& i_tableControl, const MouseEvent& i_event )
     {
-        return lcl_delegateMouseEvent( *m_pImpl, i_tableControl, i_event, &MouseFunction::handleMouseUp );
+        return delegateMouseEvent( i_tableControl, i_event, &MouseFunction::handleMouseUp );
     }
 
 
diff --git a/svtools/source/table/mousefunction.cxx b/svtools/source/table/mousefunction.cxx
index a62af9fcc149..8bb30390a286 100644
--- a/svtools/source/table/mousefunction.cxx
+++ b/svtools/source/table/mousefunction.cxx
@@ -18,7 +18,7 @@
  */
 
 
-#include "mousefunction.hxx"
+#include <mousefunction.hxx>
 #include <table/tablecontrolinterface.hxx>
 #include <table/tablesort.hxx>
 
diff --git a/svtools/source/table/mousefunction.hxx b/svtools/source/table/mousefunction.hxx
deleted file mode 100644
index beadbcf59206..000000000000
--- a/svtools/source/table/mousefunction.hxx
+++ /dev/null
@@ -1,132 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#pragma once
-
-#include <table/tabletypes.hxx>
-
-#include <salhelper/simplereferenceobject.hxx>
-
-class MouseEvent;
-
-
-namespace svt::table
-{
-
-
-    class ITableControl;
-
-
-    //= FunctionResult
-
-    enum FunctionResult
-    {
-        ActivateFunction,
-        ContinueFunction,
-        DeactivateFunction,
-
-        SkipFunction
-    };
-
-
-    //= MouseFunction
-
-    class MouseFunction : public ::salhelper::SimpleReferenceObject
-    {
-    public:
-        MouseFunction() {}
-        MouseFunction(const MouseFunction&) = delete;
-        MouseFunction& operator=(const MouseFunction&) = delete;
-        virtual FunctionResult  handleMouseMove( ITableControl& i_tableControl, MouseEvent const & i_event ) = 0;
-        virtual FunctionResult  handleMouseDown( ITableControl& i_tableControl, MouseEvent const & i_event ) = 0;
-        virtual FunctionResult  handleMouseUp( ITableControl& i_tableControl, MouseEvent const & i_event ) = 0;
-
-    protected:
-        virtual ~MouseFunction() override { }
-    };
-
-
-    //= ColumnResize
-
-    class ColumnResize : public MouseFunction
-    {
-    public:
-        ColumnResize()
-            :m_nResizingColumn( COL_INVALID )
-        {
-        }
-
-    public:
-        // MouseFunction
-        virtual FunctionResult  handleMouseMove( ITableControl& i_tableControl, MouseEvent const & i_event ) override;
-        virtual FunctionResult  handleMouseDown( ITableControl& i_tableControl, MouseEvent const & i_event ) override;
-        virtual FunctionResult  handleMouseUp( ITableControl& i_tableControl, MouseEvent const & i_event ) override;
-
-    private:
-        ColPos  m_nResizingColumn;
-    };
-
-
-    //= RowSelection
-
-    class RowSelection : public MouseFunction
-    {
-    public:
-        RowSelection()
-            :m_bActive( false )
-        {
-        }
-
-    public:
-        // MouseFunction
-        virtual FunctionResult  handleMouseMove( ITableControl& i_tableControl, MouseEvent const & i_event ) override;
-        virtual FunctionResult  handleMouseDown( ITableControl& i_tableControl, MouseEvent const & i_event ) override;
-        virtual FunctionResult  handleMouseUp( ITableControl& i_tableControl, MouseEvent const & i_event ) override;
-
-    private:
-        bool    m_bActive;
-    };
-
-
-    //= ColumnSortHandler
-
-    class ColumnSortHandler : public MouseFunction
-    {
-    public:
-        ColumnSortHandler()
-            :m_nActiveColumn( COL_INVALID )
-        {
-        }
-
-    public:
-        // MouseFunction
-        virtual FunctionResult  handleMouseMove( ITableControl& i_tableControl, MouseEvent const & i_event ) override;
-        virtual FunctionResult  handleMouseDown( ITableControl& i_tableControl, MouseEvent const & i_event ) override;
-        virtual FunctionResult  handleMouseUp( ITableControl& i_tableControl, MouseEvent const & i_event ) override;
-
-    private:
-        ColPos  m_nActiveColumn;
-    };
-
-
-} // namespace svt::table
-
-
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list