diff --git a/include/wx/propgrid/propgrid.h b/include/wx/propgrid/propgrid.h index cfaa02a408..90c022a1ed 100644 --- a/include/wx/propgrid/propgrid.h +++ b/include/wx/propgrid/propgrid.h @@ -439,36 +439,57 @@ private: // These are used with wxPropertyGrid::AddActionTrigger() and // wxPropertyGrid::ClearActionTriggers(). -enum wxPG_KEYBOARD_ACTIONS +enum class wxPGKeyboardActions { - wxPG_ACTION_INVALID = 0, +#if WXWIN_COMPATIBILITY_3_2 + Invalid = 0, +#else + Invalid, +#endif // Select the next property. - wxPG_ACTION_NEXT_PROPERTY, + NextProperty, // Select the previous property. - wxPG_ACTION_PREV_PROPERTY, + PrevProperty, // Expand the selected property, if it has child items. - wxPG_ACTION_EXPAND_PROPERTY, + ExpandProperty, // Collapse the selected property, if it has child items. - wxPG_ACTION_COLLAPSE_PROPERTY, + CollapseProperty, // Cancel and undo any editing done in the currently active property // editor. - wxPG_ACTION_CANCEL_EDIT, + CancelEdit, // Move focus to the editor control of the currently selected // property. - wxPG_ACTION_EDIT, + Edit, // Causes editor's button (if any) to be pressed. - wxPG_ACTION_PRESS_BUTTON, - - wxPG_ACTION_MAX + PressButton, }; +#if WXWIN_COMPATIBILITY_3_2 +wxDEPRECATED_MSG("use wxPGKeyboardActions::Invalid instead") +constexpr wxPGKeyboardActions wxPG_ACTION_INVALID { wxPGKeyboardActions::Invalid }; +wxDEPRECATED_MSG("use wxPGKeyboardActions::NextProperty instead") +constexpr wxPGKeyboardActions wxPG_ACTION_NEXT_PROPERTY { wxPGKeyboardActions::NextProperty }; +wxDEPRECATED_MSG("use wxPGKeyboardActions::PrevProperty instead") +constexpr wxPGKeyboardActions wxPG_ACTION_PREV_PROPERTY { wxPGKeyboardActions::PrevProperty }; +wxDEPRECATED_MSG("use wxPGKeyboardActions::ExpandProperty instead") +constexpr wxPGKeyboardActions wxPG_ACTION_EXPAND_PROPERTY { wxPGKeyboardActions::ExpandProperty }; +wxDEPRECATED_MSG("use wxPGKeyboardActions::CollapseProperty instead") +constexpr wxPGKeyboardActions wxPG_ACTION_COLLAPSE_PROPERTY { wxPGKeyboardActions::CollapseProperty }; +wxDEPRECATED_MSG("use wxPGKeyboardActions::CancelEdit instead") +constexpr wxPGKeyboardActions wxPG_ACTION_CANCEL_EDIT { wxPGKeyboardActions::CancelEdit }; +wxDEPRECATED_MSG("use wxPGKeyboardActions::Edit instead") +constexpr wxPGKeyboardActions wxPG_ACTION_EDIT { wxPGKeyboardActions::Edit }; +wxDEPRECATED_MSG("use wxPGKeyboardActions::PressButton instead") +constexpr wxPGKeyboardActions wxPG_ACTION_PRESS_BUTTON { wxPGKeyboardActions::PressButton }; +#endif // WXWIN_COMPATIBILITY_3_2 + // ----------------------------------------------------------------------- // ----------------------------------------------------------------------- @@ -565,13 +586,20 @@ public: // Adds given key combination to trigger given action. // Here is a sample code to make Enter key press move focus to // the next property. - // propGrid->AddActionTrigger(wxPG_ACTION_NEXT_PROPERTY, WXK_RETURN); + // propGrid->AddActionTrigger(wxPGKeyboardActions::NextProperty, WXK_RETURN); // propGrid->DedicateKey(WXK_RETURN); // action - Which action to trigger. See @ref propgrid_keyboard_actions. // keycode - Which keycode triggers the action. // modifiers - Which key event modifiers, in addition to keycode, are needed to // trigger the action. - void AddActionTrigger( int action, int keycode, int modifiers = 0 ); +#if WXWIN_COMPATIBILITY_3_2 + wxDEPRECATED_MSG("use AddActionTrigger with 'action' argument as wxPGKeyboardActions") + void AddActionTrigger(int action, int keycode, int modifiers) + { + AddActionTrigger(static_cast(action), keycode, modifiers); + } +#endif // WXWIN_COMPATIBILITY_3_2 + void AddActionTrigger(wxPGKeyboardActions action, int keycode, int modifiers = 0); // Dedicates a specific keycode to wxPropertyGrid. This means that such // key presses will not be redirected to editor controls. @@ -604,7 +632,14 @@ public: virtual void Clear() override; // Clears action triggers for given action. - void ClearActionTriggers( int action ); +#if WXWIN_COMPATIBILITY_3_2 + wxDEPRECATED_MSG("use ClearActionTriggers with wxPGKeyboardActions argument") + void ClearActionTriggers(int action) + { + ClearActionTriggers(static_cast(action)); + } +#endif // WXWIN_COMPATIBILITY_3_2 + void ClearActionTriggers(wxPGKeyboardActions action); // Forces updating the value of property from the editor control. // Note that wxEVT_PG_CHANGING and wxEVT_PG_CHANGED are dispatched using @@ -1478,7 +1513,7 @@ protected: wxPGValidationInfo m_validationInfo; // Actions and keys that trigger them. - std::unordered_map> m_actionTriggers; + std::unordered_map> m_actionTriggers; // Appearance of currently active editor. wxPGCell m_editorAppearance; @@ -1734,14 +1769,14 @@ protected: unsigned int bottomItemY, const wxRect* itemsRect = nullptr ); - // Translate wxKeyEvent to wxPG_ACTION_XXX - std::pair KeyEventToActions(const wxKeyEvent& event) const; + // Translate wxKeyEvent to wxPGKeyboardActions::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; + wxPGKeyboardActions KeyEventToActions(wxKeyEvent &event, wxPGKeyboardActions* pSecond) const; #endif // WXWIN_COMPATIBILITY_3_2 - int KeyEventToAction(wxKeyEvent& event) const; + wxPGKeyboardActions KeyEventToAction(wxKeyEvent& event) const; void ImprovedClientToScreen( int* px, int* py ) const; @@ -1835,7 +1870,7 @@ protected: private: - bool ButtonTriggerKeyTest( int action, wxKeyEvent& event ); + bool ButtonTriggerKeyTest(wxPGKeyboardActions action, wxKeyEvent& event); wxDECLARE_EVENT_TABLE(); }; diff --git a/interface/wx/propgrid/propgrid.h b/interface/wx/propgrid/propgrid.h index 496cb8f000..886704a705 100644 --- a/interface/wx/propgrid/propgrid.h +++ b/interface/wx/propgrid/propgrid.h @@ -396,38 +396,34 @@ public: @{ */ -enum wxPG_KEYBOARD_ACTIONS +enum class wxPGKeyboardActions { - /** - @hideinitializer - */ - wxPG_ACTION_INVALID = 0, + Invalid, /** Select the next property. */ - wxPG_ACTION_NEXT_PROPERTY, + NextProperty, /** Select the previous property. */ - wxPG_ACTION_PREV_PROPERTY, + PrevProperty, /** Expand the selected property, if it has child items. */ - wxPG_ACTION_EXPAND_PROPERTY, + ExpandProperty, /** Collapse the selected property, if it has child items. */ - wxPG_ACTION_COLLAPSE_PROPERTY, + CollapseProperty, - // Cancel and undo any editing done in the currently active property - // editor. - wxPG_ACTION_CANCEL_EDIT, + /** Cancel and undo any editing done in the currently active property + editor. + */ + CancelEdit, /** Move focus to the editor control of the currently selected property. */ - wxPG_ACTION_EDIT, + Edit, /** Causes editor's button (if any) to be pressed. */ - wxPG_ACTION_PRESS_BUTTON, - - wxPG_ACTION_MAX + PressButton, }; /** @} @@ -521,7 +517,7 @@ public: the next property. @code - propGrid->AddActionTrigger(wxPG_ACTION_NEXT_PROPERTY, + propGrid->AddActionTrigger(wxPGKeyboardActions::NextProperty, WXK_RETURN); propGrid->DedicateKey(WXK_RETURN); @endcode @@ -534,7 +530,7 @@ public: Which key event modifiers, in addition to keycode, are needed to trigger the action. */ - void AddActionTrigger( int action, int keycode, int modifiers = 0 ); + void AddActionTrigger(wxPGKeyboardActions action, int keycode, int modifiers = 0); /** Adds given property into selection. If ::wxPG_EX_MULTIPLE_SELECTION @@ -606,7 +602,7 @@ public: @param action Which action to clear. @ref propgrid_keyboard_actions. */ - void ClearActionTriggers( int action ); + void ClearActionTriggers(wxPGKeyboardActions action); /** Forces updating the value of property from the editor control. diff --git a/samples/propgrid/propgrid.cpp b/samples/propgrid/propgrid.cpp index 7b423ca2d7..2ddcd58ee7 100644 --- a/samples/propgrid/propgrid.cpp +++ b/samples/propgrid/propgrid.cpp @@ -2436,7 +2436,7 @@ void FormMain::OnExtendedKeyNav( wxCommandEvent& WXUNUSED(event) ) // Up, and Down keys for navigating between properties. wxPropertyGrid* propGrid = m_pPropGridManager->GetGrid(); - propGrid->AddActionTrigger(wxPG_ACTION_NEXT_PROPERTY, + propGrid->AddActionTrigger(wxPGKeyboardActions::NextProperty, WXK_RETURN); propGrid->DedicateKey(WXK_RETURN); diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index d962855e1e..d56c770eb0 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -380,15 +380,15 @@ void wxPropertyGrid::Init1() m_unspecifiedAppearance.SetFgCol(*wxLIGHT_GREY); // Set default keys - AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RIGHT ); - AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_DOWN ); - AddActionTrigger( wxPG_ACTION_PREV_PROPERTY, WXK_LEFT ); - AddActionTrigger( wxPG_ACTION_PREV_PROPERTY, WXK_UP ); - AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY, WXK_RIGHT); - AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY, WXK_LEFT); - AddActionTrigger( wxPG_ACTION_CANCEL_EDIT, WXK_ESCAPE ); - AddActionTrigger( wxPG_ACTION_PRESS_BUTTON, WXK_DOWN, wxMOD_ALT ); - AddActionTrigger( wxPG_ACTION_PRESS_BUTTON, WXK_F4 ); + AddActionTrigger(wxPGKeyboardActions::NextProperty, WXK_RIGHT); + AddActionTrigger(wxPGKeyboardActions::NextProperty, WXK_DOWN); + AddActionTrigger(wxPGKeyboardActions::PrevProperty, WXK_LEFT); + AddActionTrigger(wxPGKeyboardActions::PrevProperty, WXK_UP); + AddActionTrigger(wxPGKeyboardActions::ExpandProperty, WXK_RIGHT); + AddActionTrigger(wxPGKeyboardActions::CollapseProperty, WXK_LEFT); + AddActionTrigger(wxPGKeyboardActions::CancelEdit, WXK_ESCAPE); + AddActionTrigger(wxPGKeyboardActions::PressButton, WXK_DOWN, wxMOD_ALT); + AddActionTrigger(wxPGKeyboardActions::PressButton, WXK_F4); m_coloursCustomized = 0; @@ -5526,9 +5526,9 @@ void wxPropertyGrid::OnMouseUpChild( wxMouseEvent &event ) // wxPropertyGrid keyboard event handling // ----------------------------------------------------------------------- -std::pair wxPropertyGrid::KeyEventToActions(const wxKeyEvent& event) const +std::pair wxPropertyGrid::KeyEventToActions(const wxKeyEvent& event) const { - // Translates wxKeyEvent to wxPG_ACTION_XXX + // Translates wxKeyEvent to wxPGKeyboardActions::XXX int keycode = event.GetKeyCode(); int modifiers = event.GetModifiers(); @@ -5540,16 +5540,16 @@ std::pair wxPropertyGrid::KeyEventToActions(const wxKeyEvent& event) c auto it = m_actionTriggers.find(hashMapKey); if ( it == m_actionTriggers.end() ) - return std::make_pair(0, 0); + return std::make_pair(wxPGKeyboardActions::Invalid, wxPGKeyboardActions::Invalid); return it->second; } #if WXWIN_COMPATIBILITY_3_2 -int wxPropertyGrid::KeyEventToActions(wxKeyEvent &event, int* pSecond) const +wxPGKeyboardActions wxPropertyGrid::KeyEventToActions(wxKeyEvent &event, wxPGKeyboardActions* pSecond) const { - // Translates wxKeyEvent to wxPG_ACTION_XXX - std::pair actions = KeyEventToActions(event); + // Translates wxKeyEvent to wxPGKeyboardActions::XXX + std::pair actions = KeyEventToActions(event); if ( pSecond ) { @@ -5560,18 +5560,18 @@ int wxPropertyGrid::KeyEventToActions(wxKeyEvent &event, int* pSecond) const } #endif // WXWIN_COMPATIBILITY_3_2 -int wxPropertyGrid::KeyEventToAction(wxKeyEvent& event) const +wxPGKeyboardActions wxPropertyGrid::KeyEventToAction(wxKeyEvent& event) const { return KeyEventToActions(event).first; } -void wxPropertyGrid::AddActionTrigger( int action, int keycode, int modifiers ) +void wxPropertyGrid::AddActionTrigger(wxPGKeyboardActions action, int keycode, int modifiers) { wxASSERT( !(modifiers&~(0xFFFF)) ); int hashMapKey = (keycode & 0xFFFF) | ((modifiers & 0xFFFF) << 16); - std::pair curActions; + std::pair curActions; auto it = m_actionTriggers.find(hashMapKey); if ( it != m_actionTriggers.end() ) @@ -5580,34 +5580,34 @@ void wxPropertyGrid::AddActionTrigger( int action, int keycode, int modifiers ) curActions = it->second; // Can add secondary? - wxASSERT_MSG( curActions.second == 0, - wxS("You can only add up to two separate actions per key combination.") ); + wxASSERT_MSG( curActions.second == wxPGKeyboardActions::Invalid, + "You can only add up to two separate actions per key combination." ); curActions.second = action; } else { - curActions = std::make_pair(action, 0); + curActions = std::make_pair(action, wxPGKeyboardActions::Invalid); } m_actionTriggers[hashMapKey] = curActions; } -void wxPropertyGrid::ClearActionTriggers(int action) +void wxPropertyGrid::ClearActionTriggers(wxPGKeyboardActions action) { - wxCHECK_RET(!(action & ~(0xFFFF)), wxS("You can only clear triggers for one action at a time.") +// wxCHECK_RET(!(action & ~(0xFFFF)), wxS("You can only clear triggers for one action at a time.") auto it = m_actionTriggers.begin(); while ( it != m_actionTriggers.end() ) { if ( it->second.second == action ) { - it->second.second = 0; + it->second.second = wxPGKeyboardActions::Invalid; } if ( it->second.first == action ) { - if ( it->second.second == 0 ) + if ( it->second.second == wxPGKeyboardActions::Invalid ) { it = m_actionTriggers.erase(it); continue; @@ -5680,11 +5680,11 @@ void wxPropertyGrid::HandleKeyEvent( wxKeyEvent &event, bool fromChild ) return; } - int action; - int secondAction; + wxPGKeyboardActions action; + wxPGKeyboardActions secondAction; std::tie(action, secondAction) = KeyEventToActions(event); - if ( editorFocused && action == wxPG_ACTION_CANCEL_EDIT ) + if ( editorFocused && action == wxPGKeyboardActions::CancelEdit ) { // // Esc cancels any changes @@ -5728,7 +5728,7 @@ void wxPropertyGrid::HandleKeyEvent( wxKeyEvent &event, bool fromChild ) wxPGProperty* p = selected; - if ( action == wxPG_ACTION_EDIT && !editorFocused ) + if ( action == wxPGKeyboardActions::Edit && !editorFocused ) { // Mark as handled only for editable property if ( !p->IsCategory() && p->IsEnabled() && !p->HasFlag(wxPG_PROP_READONLY) ) @@ -5743,12 +5743,12 @@ void wxPropertyGrid::HandleKeyEvent( wxKeyEvent &event, bool fromChild ) if ( p->GetChildCount() ) { - if ( action == wxPG_ACTION_COLLAPSE_PROPERTY || secondAction == wxPG_ACTION_COLLAPSE_PROPERTY ) + if ( action == wxPGKeyboardActions::CollapseProperty || secondAction == wxPGKeyboardActions::CollapseProperty ) { if ( (m_windowStyle & wxPG_HIDE_MARGIN) || DoCollapse(p, true) ) wasHandled = true; } - else if ( action == wxPG_ACTION_EXPAND_PROPERTY || secondAction == wxPG_ACTION_EXPAND_PROPERTY ) + else if ( action == wxPGKeyboardActions::ExpandProperty || secondAction == wxPGKeyboardActions::ExpandProperty ) { if ( (m_windowStyle & wxPG_HIDE_MARGIN) || DoExpand(p, true) ) wasHandled = true; @@ -5757,11 +5757,11 @@ void wxPropertyGrid::HandleKeyEvent( wxKeyEvent &event, bool fromChild ) if ( !wasHandled ) { - if ( action == wxPG_ACTION_PREV_PROPERTY || secondAction == wxPG_ACTION_PREV_PROPERTY ) + if ( action == wxPGKeyboardActions::PrevProperty || secondAction == wxPGKeyboardActions::PrevProperty ) { selectDir = -1; } - else if ( action == wxPG_ACTION_NEXT_PROPERTY || secondAction == wxPG_ACTION_NEXT_PROPERTY ) + else if ( action == wxPGKeyboardActions::NextProperty || secondAction == wxPGKeyboardActions::NextProperty ) { selectDir = 1; } @@ -5775,7 +5775,7 @@ void wxPropertyGrid::HandleKeyEvent( wxKeyEvent &event, bool fromChild ) wxPGSelectPropertyFlags selFlags = wxPGSelectPropertyFlags::Null; int reopenLabelEditorCol = -1; - if ( action == wxPG_ACTION_EDIT ) + if ( action == wxPGKeyboardActions::Edit ) { // Make the next editor focused as well // if we are actually going to edit the property. @@ -5793,7 +5793,7 @@ void wxPropertyGrid::HandleKeyEvent( wxKeyEvent &event, bool fromChild ) if ( reopenLabelEditorCol >= 0 ) DoBeginLabelEdit(reopenLabelEditorCol); } - else if ( action == wxPG_ACTION_EDIT ) + else if ( action == wxPGKeyboardActions::Edit ) { // For first and last item just validate the value CommitChangesFromEditor(); @@ -5805,7 +5805,7 @@ void wxPropertyGrid::HandleKeyEvent( wxKeyEvent &event, bool fromChild ) { // If nothing was selected, select the first item now // (or navigate out of tab). - if ( action != wxPG_ACTION_CANCEL_EDIT && secondAction != wxPG_ACTION_CANCEL_EDIT ) + if ( action != wxPGKeyboardActions::CancelEdit && secondAction != wxPGKeyboardActions::CancelEdit ) { wxPGProperty* p = wxPropertyGridInterface::GetFirst(); if ( p ) DoSelectProperty(p); @@ -5839,15 +5839,15 @@ void wxPropertyGrid::OnKey( wxKeyEvent &event ) // ----------------------------------------------------------------------- -bool wxPropertyGrid::ButtonTriggerKeyTest( int action, wxKeyEvent& event ) +bool wxPropertyGrid::ButtonTriggerKeyTest(wxPGKeyboardActions action, wxKeyEvent& event) { - if ( action == -1 ) + if ( action == wxPGKeyboardActions::Invalid ) { action = KeyEventToActions(event).first; } // Does the keycode trigger button? - if ( action == wxPG_ACTION_PRESS_BUTTON && + if ( action == wxPGKeyboardActions::PressButton && m_wndEditor2 ) { wxCommandEvent evt(wxEVT_BUTTON, m_wndEditor2->GetId());