From 357f611a48bb7082631f5d7cbbe149661482bee8 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek <7330332+a-wi@users.noreply.github.com> Date: Fri, 30 Dec 2022 14:08:15 +0200 Subject: [PATCH] Simplify returnig two values from wxPropertyGrid::KeyEventToActions() Use std::pair to return pair of values from function. --- include/wx/propgrid/propgrid.h | 9 +++++---- src/propgrid/propgrid.cpp | 36 ++++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/include/wx/propgrid/propgrid.h b/include/wx/propgrid/propgrid.h index e8bd72a676..ad3df90aef 100644 --- a/include/wx/propgrid/propgrid.h +++ b/include/wx/propgrid/propgrid.h @@ -1817,12 +1817,13 @@ protected: const wxRect* itemsRect = nullptr ); // Translate wxKeyEvent to wxPG_ACTION_XXX + std::pair KeyEventToActions(const wxKeyEvent& event) const; +#if WXWIN_COMPATIBILITY_3_2 + wxDEPRECATED_MSG("use single-argument function KeyEventToActions(event)") int KeyEventToActions(wxKeyEvent &event, int* pSecond) const; +#endif // WXWIN_COMPATIBILITY_3_2 - int KeyEventToAction(wxKeyEvent &event) const - { - return KeyEventToActions(event, nullptr); - } + int KeyEventToAction(wxKeyEvent& event) const; void ImprovedClientToScreen( int* px, int* py ) const; diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index fe2a1a20fa..c47102da89 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -3810,6 +3810,7 @@ void wxPropertyGrid::ImprovedClientToScreen( int* px, int* py ) const wxASSERT(px && py); CalcScrolledPosition(*px, *py, px, py); ClientToScreen( px, py ); + } // ----------------------------------------------------------------------- @@ -5497,29 +5498,44 @@ void wxPropertyGrid::OnMouseUpChild( wxMouseEvent &event ) // wxPropertyGrid keyboard event handling // ----------------------------------------------------------------------- -int wxPropertyGrid::KeyEventToActions(wxKeyEvent &event, int* pSecond) const +std::pair wxPropertyGrid::KeyEventToActions(const wxKeyEvent& event) const { // Translates wxKeyEvent to wxPG_ACTION_XXX int keycode = event.GetKeyCode(); int modifiers = event.GetModifiers(); - wxASSERT( !(modifiers&~(0xFFFF)) ); + wxASSERT(!(modifiers & ~(0xFFFF))); int hashMapKey = (keycode & 0xFFFF) | ((modifiers & 0xFFFF) << 16); wxPGHashMapI2I::const_iterator it = m_actionTriggers.find(hashMapKey); if ( it == m_actionTriggers.end() ) - return 0; + return std::make_pair(0, 0); + + wxInt32 actions = it->second; + return std::make_pair(actions & 0xFFFF, (actions >> 16) & 0xFFFF); +} + +#if WXWIN_COMPATIBILITY_3_2 +int wxPropertyGrid::KeyEventToActions(wxKeyEvent &event, int* pSecond) const +{ + // Translates wxKeyEvent to wxPG_ACTION_XXX + std::pair actions = KeyEventToActions(event); if ( pSecond ) { - int second = (it->second>>16) & 0xFFFF; - *pSecond = second; + *pSecond = actions.second; } - return (it->second & 0xFFFF); + return actions.first; +} +#endif // WXWIN_COMPATIBILITY_3_2 + +int wxPropertyGrid::KeyEventToAction(wxKeyEvent& event) const +{ + return KeyEventToActions(event).first; } void wxPropertyGrid::AddActionTrigger( int action, int keycode, int modifiers ) @@ -5642,8 +5658,9 @@ void wxPropertyGrid::HandleKeyEvent( wxKeyEvent &event, bool fromChild ) return; } - int secondAction; - int action = KeyEventToActions(event, &secondAction); + std::pair actions = KeyEventToActions(event); + int action = actions.first; + int secondAction = actions.second; if ( editorFocused && action == wxPG_ACTION_CANCEL_EDIT ) { @@ -5810,8 +5827,7 @@ bool wxPropertyGrid::ButtonTriggerKeyTest( int action, wxKeyEvent& event ) { if ( action == -1 ) { - int secondAction; - action = KeyEventToActions(event, &secondAction); + action = KeyEventToActions(event).first; } // Does the keycode trigger button?