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 <caolanm@redhat.com>
This commit is contained in:
Caolán McNamara
2022-12-19 11:55:05 +00:00
parent d7ada1052f
commit ee767c1453
4 changed files with 45 additions and 32 deletions

View File

@@ -202,8 +202,19 @@ namespace svt
m_aMouseMoveHdl = rHdl; 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: protected:
DECL_DLLPRIVATE_LINK(KeyInputHdl, const KeyEvent&, bool); DECL_DLLPRIVATE_LINK(KeyInputHdl, const KeyEvent&, bool);
DECL_DLLPRIVATE_LINK(KeyReleaseHdl, const KeyEvent&, bool);
DECL_DLLPRIVATE_LINK(FocusInHdl, weld::Widget&, void); DECL_DLLPRIVATE_LINK(FocusInHdl, weld::Widget&, void);
DECL_DLLPRIVATE_LINK(FocusOutHdl, weld::Widget&, void); DECL_DLLPRIVATE_LINK(FocusOutHdl, weld::Widget&, void);
DECL_DLLPRIVATE_LINK(MousePressHdl, const MouseEvent&, bool); DECL_DLLPRIVATE_LINK(MousePressHdl, const MouseEvent&, bool);
@@ -215,6 +226,8 @@ namespace svt
Link<const MouseEvent&,void> m_aMousePressHdl; Link<const MouseEvent&,void> m_aMousePressHdl;
Link<const MouseEvent&,void> m_aMouseReleaseHdl; Link<const MouseEvent&,void> m_aMouseReleaseHdl;
Link<const MouseEvent&,void> m_aMouseMoveHdl; Link<const MouseEvent&,void> m_aMouseMoveHdl;
Link<const KeyEvent&,void> m_aKeyInputHdl;
Link<const KeyEvent&,void> m_aKeyReleaseHdl;
}; };
class SVT_DLLPUBLIC EditControlBase : public ControlBase class SVT_DLLPUBLIC EditControlBase : public ControlBase

View File

@@ -30,6 +30,7 @@ namespace svt
m_xWidget->set_entry_width_chars(1); // so a smaller than default width can be used 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_changed(LINK(this, ComboBoxControl, SelectHdl));
m_xWidget->connect_key_press(LINK(this, ControlBase, KeyInputHdl)); 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_in(LINK(this, ControlBase, FocusInHdl));
m_xWidget->connect_focus_out(LINK(this, ControlBase, FocusOutHdl)); m_xWidget->connect_focus_out(LINK(this, ControlBase, FocusOutHdl));
m_xWidget->connect_mouse_press(LINK(this, ControlBase, MousePressHdl)); 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->set_size_request(42, -1); // so a later narrow size request can stick
m_xWidget->connect_changed(LINK(this, ListBoxControl, SelectHdl)); m_xWidget->connect_changed(LINK(this, ListBoxControl, SelectHdl));
m_xWidget->connect_key_press(LINK(this, ControlBase, KeyInputHdl)); 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_in(LINK(this, ControlBase, FocusInHdl));
m_xWidget->connect_focus_out(LINK(this, ControlBase, FocusOutHdl)); m_xWidget->connect_focus_out(LINK(this, ControlBase, FocusOutHdl));
m_xWidget->connect_mouse_press(LINK(this, ControlBase, MousePressHdl)); m_xWidget->connect_mouse_press(LINK(this, ControlBase, MousePressHdl));
@@ -203,6 +205,7 @@ namespace svt
m_aModeState.bTriStateEnabled = true; m_aModeState.bTriStateEnabled = true;
InitControlBase(m_xBox.get()); InitControlBase(m_xBox.get());
m_xBox->connect_key_press(LINK(this, ControlBase, KeyInputHdl)); 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_in(LINK(this, ControlBase, FocusInHdl));
m_xBox->connect_focus_out(LINK(this, ControlBase, FocusOutHdl)); m_xBox->connect_focus_out(LINK(this, ControlBase, FocusOutHdl));
m_xBox->connect_mouse_press(LINK(this, ControlBase, MousePressHdl)); m_xBox->connect_mouse_press(LINK(this, ControlBase, MousePressHdl));
@@ -362,9 +365,10 @@ namespace svt
m_pEntry = pEntry; m_pEntry = pEntry;
m_pEntry->show(); m_pEntry->show();
m_pEntry->set_width_chars(1); // so a smaller than default width can be used 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)); // need to chain with pattern handler
connect_focus_in(LINK(this, ControlBase, FocusInHdl)); connect_focus_out(LINK(this, ControlBase, FocusOutHdl)); // need to chain with pattern handler
connect_focus_out(LINK(this, ControlBase, FocusOutHdl)); 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_press(LINK(this, ControlBase, MousePressHdl));
m_pEntry->connect_mouse_release(LINK(this, ControlBase, MouseReleaseHdl)); m_pEntry->connect_mouse_release(LINK(this, ControlBase, MouseReleaseHdl));
m_pEntry->connect_mouse_move(LINK(this, ControlBase, MouseMoveHdl)); m_pEntry->connect_mouse_move(LINK(this, ControlBase, MouseMoveHdl));
@@ -377,9 +381,16 @@ namespace svt
IMPL_LINK(ControlBase, KeyInputHdl, const KeyEvent&, rKEvt, bool) IMPL_LINK(ControlBase, KeyInputHdl, const KeyEvent&, rKEvt, bool)
{ {
m_aKeyInputHdl.Call(rKEvt);
return ProcessKey(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) IMPL_LINK_NOARG(ControlBase, FocusInHdl, weld::Widget&, void)
{ {
m_aFocusInHdl.Call(nullptr); m_aFocusInHdl.Call(nullptr);
@@ -703,6 +714,7 @@ namespace svt
{ {
InitControlBase(m_xWidget.get()); InitControlBase(m_xWidget.get());
m_xWidget->connect_key_press(LINK(this, ControlBase, KeyInputHdl)); 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_in(LINK(this, ControlBase, FocusInHdl));
m_xWidget->connect_focus_out(LINK(this, ControlBase, FocusOutHdl)); m_xWidget->connect_focus_out(LINK(this, ControlBase, FocusOutHdl));
m_xWidget->connect_mouse_press(LINK(this, ControlBase, MousePressHdl)); m_xWidget->connect_mouse_press(LINK(this, ControlBase, MousePressHdl));

View File

@@ -3204,12 +3204,13 @@ void FmXGridCell::init()
svt::ControlBase* pEventWindow( getEventWindow() ); svt::ControlBase* pEventWindow( getEventWindow() );
if ( pEventWindow ) if ( pEventWindow )
{ {
pEventWindow->AddEventListener( LINK( this, FmXGridCell, OnWindowEvent ) );
pEventWindow->SetFocusInHdl(LINK( this, FmXGridCell, OnFocusGained)); pEventWindow->SetFocusInHdl(LINK( this, FmXGridCell, OnFocusGained));
pEventWindow->SetFocusOutHdl(LINK( this, FmXGridCell, OnFocusLost)); pEventWindow->SetFocusOutHdl(LINK( this, FmXGridCell, OnFocusLost));
pEventWindow->SetMousePressHdl(LINK( this, FmXGridCell, OnMousePress)); pEventWindow->SetMousePressHdl(LINK( this, FmXGridCell, OnMousePress));
pEventWindow->SetMouseReleaseHdl(LINK( this, FmXGridCell, OnMouseRelease)); pEventWindow->SetMouseReleaseHdl(LINK( this, FmXGridCell, OnMouseRelease));
pEventWindow->SetMouseMoveHdl(LINK( this, FmXGridCell, OnMouseMove)); 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" ); 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 ) void FmXGridCell::onFocusGained( const awt::FocusEvent& _rEvent )
{ {
checkDisposed(OComponentHelper::rBHelper.bDisposed); 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 ) if (!m_aKeyListeners.getLength())
{ return;
case VclEventId::WindowKeyInput:
case VclEventId::WindowKeyUp:
{
if ( !m_aKeyListeners.getLength() )
break;
const bool bKeyPressed = ( _nEventId == VclEventId::WindowKeyInput ); awt::KeyEvent aEvent(VCLUnoHelper::createKeyEvent(rEventData, *this));
awt::KeyEvent aEvent( VCLUnoHelper::createKeyEvent( *static_cast< const ::KeyEvent* >( _pEventData ), *this ) ); m_aKeyListeners.notifyEach(&awt::XKeyListener::keyPressed, aEvent);
m_aKeyListeners.notifyEach( bKeyPressed ? &awt::XKeyListener::keyPressed: &awt::XKeyListener::keyReleased, aEvent );
}
break;
default: break;
}
} }
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, void FmXDataCell::PaintFieldToCell(OutputDevice& rDev, const tools::Rectangle& rRect,
const Reference< css::sdb::XColumn >& _rxField, 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 ); m_pCellControl->PaintFieldToCell( rDev, rRect, _rxField, xFormatter );
} }
void FmXDataCell::UpdateFromColumn() void FmXDataCell::UpdateFromColumn()
{ {
Reference< css::sdb::XColumn > xField(m_pColumn->GetCurrentFieldValue()); Reference< css::sdb::XColumn > xField(m_pColumn->GetCurrentFieldValue());
@@ -3558,14 +3550,12 @@ void FmXDataCell::UpdateFromColumn()
m_pCellControl->UpdateFromField(xField, m_pColumn->GetParent().getNumberFormatter()); m_pCellControl->UpdateFromField(xField, m_pColumn->GetParent().getNumberFormatter());
} }
FmXTextCell::FmXTextCell( DbGridColumn* pColumn, std::unique_ptr<DbCellControl> pControl ) FmXTextCell::FmXTextCell( DbGridColumn* pColumn, std::unique_ptr<DbCellControl> pControl )
:FmXDataCell( pColumn, std::move(pControl) ) :FmXDataCell( pColumn, std::move(pControl) )
,m_bIsMultiLineText(false) ,m_bIsMultiLineText(false)
{ {
} }
void FmXTextCell::PaintFieldToCell(OutputDevice& rDev, void FmXTextCell::PaintFieldToCell(OutputDevice& rDev,
const tools::Rectangle& rRect, const tools::Rectangle& rRect,
const Reference< css::sdb::XColumn >& _rxField, const Reference< css::sdb::XColumn >& _rxField,

View File

@@ -763,8 +763,6 @@ public:
{ m_pCellControl->AlignControl(nAlignment);} { m_pCellControl->AlignControl(nAlignment);}
protected: 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 // 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 onFocusGained( const css::awt::FocusEvent& _rEvent );
virtual void onFocusLost( 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(OnMousePress, const MouseEvent&, void);
DECL_LINK(OnMouseRelease, const MouseEvent&, void); DECL_LINK(OnMouseRelease, const MouseEvent&, void);
DECL_LINK(OnMouseMove, const MouseEvent&, void); DECL_LINK(OnMouseMove, const MouseEvent&, void);
DECL_LINK(OnKeyInput, const KeyEvent&, void);
DECL_LINK( OnWindowEvent, VclWindowEvent&, void ); DECL_LINK(OnKeyRelease, const KeyEvent&, void);
}; };