include/svtools/editbrowsebox.hxx     |   13 +++++++++++
 svtools/source/brwbox/ebbcontrols.cxx |   18 ++++++++++++---
 svx/source/fmcomp/gridcell.cxx        |   40 ++++++++++++----------------------
 svx/source/inc/gridcell.hxx           |    6 +----
 4 files changed, 45 insertions(+), 32 deletions(-)

New commits:
commit ee767c14530ad1fb8b7660e9352199f185fe61dc
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Mon Dec 19 11:55:05 2022 +0000
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Mon Dec 19 20:33:47 2022 +0000

    Resolves: tdf#146933 wire up keypress events for table control widgets
    
    Change-Id: Idc8cc3c24d061537a76a37f4fa84951a41a42657
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144470
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/include/svtools/editbrowsebox.hxx 
b/include/svtools/editbrowsebox.hxx
index aa6b72441373..2297c45a63a8 100644
--- a/include/svtools/editbrowsebox.hxx
+++ b/include/svtools/editbrowsebox.hxx
@@ -202,8 +202,19 @@ namespace svt
             m_aMouseMoveHdl = rHdl;
         }
 
+        void SetKeyInputHdl(const Link<const KeyEvent&,void>& rHdl)
+        {
+            m_aKeyInputHdl = rHdl;
+        }
+
+        void SetKeyReleaseHdl(const Link<const KeyEvent&,void>& rHdl)
+        {
+            m_aKeyReleaseHdl = rHdl;
+        }
+
     protected:
         DECL_DLLPRIVATE_LINK(KeyInputHdl, const KeyEvent&, bool);
+        DECL_DLLPRIVATE_LINK(KeyReleaseHdl, const KeyEvent&, bool);
         DECL_DLLPRIVATE_LINK(FocusInHdl, weld::Widget&, void);
         DECL_DLLPRIVATE_LINK(FocusOutHdl, weld::Widget&, void);
         DECL_DLLPRIVATE_LINK(MousePressHdl, const MouseEvent&, bool);
@@ -215,6 +226,8 @@ namespace svt
         Link<const MouseEvent&,void> m_aMousePressHdl;
         Link<const MouseEvent&,void> m_aMouseReleaseHdl;
         Link<const MouseEvent&,void> m_aMouseMoveHdl;
+        Link<const KeyEvent&,void> m_aKeyInputHdl;
+        Link<const KeyEvent&,void> m_aKeyReleaseHdl;
     };
 
     class SVT_DLLPUBLIC EditControlBase : public ControlBase
diff --git a/svtools/source/brwbox/ebbcontrols.cxx 
b/svtools/source/brwbox/ebbcontrols.cxx
index b6a27a2567f4..b0a2ad1bbcc3 100644
--- a/svtools/source/brwbox/ebbcontrols.cxx
+++ b/svtools/source/brwbox/ebbcontrols.cxx
@@ -30,6 +30,7 @@ namespace svt
         m_xWidget->set_entry_width_chars(1); // so a smaller than default 
width can be used
         m_xWidget->connect_changed(LINK(this, ComboBoxControl, SelectHdl));
         m_xWidget->connect_key_press(LINK(this, ControlBase, KeyInputHdl));
+        m_xWidget->connect_key_release(LINK(this, ControlBase, KeyReleaseHdl));
         m_xWidget->connect_focus_in(LINK(this, ControlBase, FocusInHdl));
         m_xWidget->connect_focus_out(LINK(this, ControlBase, FocusOutHdl));
         m_xWidget->connect_mouse_press(LINK(this, ControlBase, MousePressHdl));
@@ -125,6 +126,7 @@ namespace svt
         m_xWidget->set_size_request(42, -1); // so a later narrow size request 
can stick
         m_xWidget->connect_changed(LINK(this, ListBoxControl, SelectHdl));
         m_xWidget->connect_key_press(LINK(this, ControlBase, KeyInputHdl));
+        m_xWidget->connect_key_release(LINK(this, ControlBase, KeyReleaseHdl));
         m_xWidget->connect_focus_in(LINK(this, ControlBase, FocusInHdl));
         m_xWidget->connect_focus_out(LINK(this, ControlBase, FocusOutHdl));
         m_xWidget->connect_mouse_press(LINK(this, ControlBase, MousePressHdl));
@@ -203,6 +205,7 @@ namespace svt
         m_aModeState.bTriStateEnabled = true;
         InitControlBase(m_xBox.get());
         m_xBox->connect_key_press(LINK(this, ControlBase, KeyInputHdl));
+        m_xBox->connect_key_release(LINK(this, ControlBase, KeyReleaseHdl));
         m_xBox->connect_focus_in(LINK(this, ControlBase, FocusInHdl));
         m_xBox->connect_focus_out(LINK(this, ControlBase, FocusOutHdl));
         m_xBox->connect_mouse_press(LINK(this, ControlBase, MousePressHdl));
@@ -362,9 +365,10 @@ namespace svt
         m_pEntry = pEntry;
         m_pEntry->show();
         m_pEntry->set_width_chars(1); // so a smaller than default width can 
be used
-        connect_key_press(LINK(this, ControlBase, KeyInputHdl));
-        connect_focus_in(LINK(this, ControlBase, FocusInHdl));
-        connect_focus_out(LINK(this, ControlBase, FocusOutHdl));
+        connect_focus_in(LINK(this, ControlBase, FocusInHdl));   // need to 
chain with pattern handler
+        connect_focus_out(LINK(this, ControlBase, FocusOutHdl)); // need to 
chain with pattern handler
+        connect_key_press(LINK(this, ControlBase, KeyInputHdl)); // need to 
chain with pattern handler
+        m_pEntry->connect_key_release(LINK(this, ControlBase, KeyReleaseHdl));
         m_pEntry->connect_mouse_press(LINK(this, ControlBase, MousePressHdl));
         m_pEntry->connect_mouse_release(LINK(this, ControlBase, 
MouseReleaseHdl));
         m_pEntry->connect_mouse_move(LINK(this, ControlBase, MouseMoveHdl));
@@ -377,9 +381,16 @@ namespace svt
 
     IMPL_LINK(ControlBase, KeyInputHdl, const KeyEvent&, rKEvt, bool)
     {
+        m_aKeyInputHdl.Call(rKEvt);
         return ProcessKey(rKEvt);
     }
 
+    IMPL_LINK(ControlBase, KeyReleaseHdl, const KeyEvent&, rKEvt, bool)
+    {
+        m_aKeyReleaseHdl.Call(rKEvt);
+        return false;
+    }
+
     IMPL_LINK_NOARG(ControlBase, FocusInHdl, weld::Widget&, void)
     {
         m_aFocusInHdl.Call(nullptr);
@@ -703,6 +714,7 @@ namespace svt
     {
         InitControlBase(m_xWidget.get());
         m_xWidget->connect_key_press(LINK(this, ControlBase, KeyInputHdl));
+        m_xWidget->connect_key_release(LINK(this, ControlBase, KeyReleaseHdl));
         m_xWidget->connect_focus_in(LINK(this, ControlBase, FocusInHdl));
         m_xWidget->connect_focus_out(LINK(this, ControlBase, FocusOutHdl));
         m_xWidget->connect_mouse_press(LINK(this, ControlBase, MousePressHdl));
diff --git a/svx/source/fmcomp/gridcell.cxx b/svx/source/fmcomp/gridcell.cxx
index fead2880f100..c231d7415ec6 100644
--- a/svx/source/fmcomp/gridcell.cxx
+++ b/svx/source/fmcomp/gridcell.cxx
@@ -3204,12 +3204,13 @@ void FmXGridCell::init()
     svt::ControlBase* pEventWindow( getEventWindow() );
     if ( pEventWindow )
     {
-        pEventWindow->AddEventListener( LINK( this, FmXGridCell, OnWindowEvent 
) );
         pEventWindow->SetFocusInHdl(LINK( this, FmXGridCell, OnFocusGained));
         pEventWindow->SetFocusOutHdl(LINK( this, FmXGridCell, OnFocusLost));
         pEventWindow->SetMousePressHdl(LINK( this, FmXGridCell, OnMousePress));
         pEventWindow->SetMouseReleaseHdl(LINK( this, FmXGridCell, 
OnMouseRelease));
         pEventWindow->SetMouseMoveHdl(LINK( this, FmXGridCell, OnMouseMove));
+        pEventWindow->SetKeyInputHdl( LINK( this, FmXGridCell, OnKeyInput) );
+        pEventWindow->SetKeyReleaseHdl( LINK( this, FmXGridCell, OnKeyRelease) 
);
     }
 }
 
@@ -3441,12 +3442,6 @@ void SAL_CALL FmXGridCell::removePaintListener( const 
Reference< awt::XPaintList
     OSL_FAIL( "FmXGridCell::removePaintListener: not implemented" );
 }
 
-IMPL_LINK( FmXGridCell, OnWindowEvent, VclWindowEvent&, _rEvent, void )
-{
-    ENSURE_OR_THROW( _rEvent.GetWindow(), "illegal window" );
-    onWindowEvent(_rEvent.GetId(), _rEvent.GetData());
-}
-
 void FmXGridCell::onFocusGained( const awt::FocusEvent& _rEvent )
 {
     checkDisposed(OComponentHelper::rBHelper.bDisposed);
@@ -3523,25 +3518,23 @@ IMPL_LINK(FmXGridCell, OnMouseMove, const MouseEvent&, 
rMouseEvent, void)
     }
 }
 
-void FmXGridCell::onWindowEvent(const VclEventId _nEventId, const void* 
_pEventData)
+IMPL_LINK(FmXGridCell, OnKeyInput, const KeyEvent&, rEventData, void)
 {
-    switch ( _nEventId )
-    {
-    case VclEventId::WindowKeyInput:
-    case VclEventId::WindowKeyUp:
-    {
-        if ( !m_aKeyListeners.getLength() )
-            break;
+    if (!m_aKeyListeners.getLength())
+        return;
 
-        const bool bKeyPressed = ( _nEventId == VclEventId::WindowKeyInput );
-        awt::KeyEvent aEvent( VCLUnoHelper::createKeyEvent( *static_cast< 
const ::KeyEvent* >( _pEventData ), *this ) );
-        m_aKeyListeners.notifyEach( bKeyPressed ? 
&awt::XKeyListener::keyPressed: &awt::XKeyListener::keyReleased, aEvent );
-    }
-    break;
-    default: break;
-    }
+    awt::KeyEvent aEvent(VCLUnoHelper::createKeyEvent(rEventData, *this));
+    m_aKeyListeners.notifyEach(&awt::XKeyListener::keyPressed, aEvent);
 }
 
+IMPL_LINK(FmXGridCell, OnKeyRelease, const KeyEvent&, rEventData, void)
+{
+    if (!m_aKeyListeners.getLength())
+        return;
+
+    awt::KeyEvent aEvent(VCLUnoHelper::createKeyEvent(rEventData, *this));
+    m_aKeyListeners.notifyEach(&awt::XKeyListener::keyReleased, aEvent);
+}
 
 void FmXDataCell::PaintFieldToCell(OutputDevice& rDev, const tools::Rectangle& 
rRect,
                         const Reference< css::sdb::XColumn >& _rxField,
@@ -3550,7 +3543,6 @@ void FmXDataCell::PaintFieldToCell(OutputDevice& rDev, 
const tools::Rectangle& r
     m_pCellControl->PaintFieldToCell( rDev, rRect, _rxField, xFormatter );
 }
 
-
 void FmXDataCell::UpdateFromColumn()
 {
     Reference< css::sdb::XColumn >  xField(m_pColumn->GetCurrentFieldValue());
@@ -3558,14 +3550,12 @@ void FmXDataCell::UpdateFromColumn()
         m_pCellControl->UpdateFromField(xField, 
m_pColumn->GetParent().getNumberFormatter());
 }
 
-
 FmXTextCell::FmXTextCell( DbGridColumn* pColumn, 
std::unique_ptr<DbCellControl> pControl )
     :FmXDataCell( pColumn, std::move(pControl) )
     ,m_bIsMultiLineText(false)
 {
 }
 
-
 void FmXTextCell::PaintFieldToCell(OutputDevice& rDev,
                         const tools::Rectangle& rRect,
                         const Reference< css::sdb::XColumn >& _rxField,
diff --git a/svx/source/inc/gridcell.hxx b/svx/source/inc/gridcell.hxx
index dc30f72802b3..8b62384343f5 100644
--- a/svx/source/inc/gridcell.hxx
+++ b/svx/source/inc/gridcell.hxx
@@ -763,8 +763,6 @@ public:
         { m_pCellControl->AlignControl(nAlignment);}
 
 protected:
-    void onWindowEvent(const VclEventId _nEventId, const void* _pEventData);
-
     // default implementations call our focus listeners, don't forget to call 
them if you override this
     virtual void onFocusGained( const css::awt::FocusEvent& _rEvent );
     virtual void onFocusLost( const css::awt::FocusEvent& _rEvent );
@@ -776,8 +774,8 @@ private:
     DECL_LINK(OnMousePress, const MouseEvent&, void);
     DECL_LINK(OnMouseRelease, const MouseEvent&, void);
     DECL_LINK(OnMouseMove, const MouseEvent&, void);
-
-    DECL_LINK( OnWindowEvent, VclWindowEvent&, void );
+    DECL_LINK(OnKeyInput, const KeyEvent&, void);
+    DECL_LINK(OnKeyRelease, const KeyEvent&, void);
 };
 
 

Reply via email to