From 1a4f628e405661c042dcaa5f62c076a9c328719e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 21 Sep 2020 15:36:41 +0200 Subject: [PATCH] Make radio button navigation functions const This requires adding a couple of const_cast<>s in their implementation in order to still allow them returning non-const wxRadioButton pointers, but this seems preferable to not being able to call them on a const wxRadioButton in the first place. --- include/wx/radiobut.h | 24 ++++++++++++------------ interface/wx/radiobut.h | 8 ++++---- src/common/containr.cpp | 16 ++++++++-------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/include/wx/radiobut.h b/include/wx/radiobut.h index d68ac4a665..d999800efb 100644 --- a/include/wx/radiobut.h +++ b/include/wx/radiobut.h @@ -36,10 +36,10 @@ class WXDLLIMPEXP_FWD_CORE wxRadioButton; namespace wxPrivate { - WXDLLIMPEXP_CORE wxRadioButton* wxGetNextButtonInGroup(wxRadioButton *btn); - WXDLLIMPEXP_CORE wxRadioButton* wxGetPreviousButtonInGroup(wxRadioButton *btn); - WXDLLIMPEXP_CORE wxRadioButton* wxGetFirstButtonInGroup(wxRadioButton *btn); - WXDLLIMPEXP_CORE wxRadioButton* wxGetLastButtonInGroup(wxRadioButton *btn); + WXDLLIMPEXP_CORE wxRadioButton* wxGetNextButtonInGroup(const wxRadioButton *btn); + WXDLLIMPEXP_CORE wxRadioButton* wxGetPreviousButtonInGroup(const wxRadioButton *btn); + WXDLLIMPEXP_CORE wxRadioButton* wxGetFirstButtonInGroup(const wxRadioButton *btn); + WXDLLIMPEXP_CORE wxRadioButton* wxGetLastButtonInGroup(const wxRadioButton *btn); } // namespace wxPrivate template @@ -50,24 +50,24 @@ public: wxRadioButtonBase() { } - wxRadioButton* GetFirstInGroup() + wxRadioButton* GetFirstInGroup() const { - return wxPrivate::wxGetFirstButtonInGroup( static_cast(this)); + return wxPrivate::wxGetFirstButtonInGroup(static_cast(this)); } - wxRadioButton* GetLastInGroup() + wxRadioButton* GetLastInGroup() const { - return wxPrivate::wxGetLastButtonInGroup( static_cast(this)); + return wxPrivate::wxGetLastButtonInGroup(static_cast(this)); } - wxRadioButton* GetPreviousInGroup() + wxRadioButton* GetPreviousInGroup() const { - return wxPrivate::wxGetPreviousButtonInGroup( static_cast(this)); + return wxPrivate::wxGetPreviousButtonInGroup(static_cast(this)); } - wxRadioButton* GetNextInGroup() + wxRadioButton* GetNextInGroup() const { - return wxPrivate::wxGetNextButtonInGroup( static_cast(this)); + return wxPrivate::wxGetNextButtonInGroup(static_cast(this)); } private: diff --git a/interface/wx/radiobut.h b/interface/wx/radiobut.h index 2bf6b22261..9094b23fde 100644 --- a/interface/wx/radiobut.h +++ b/interface/wx/radiobut.h @@ -139,7 +139,7 @@ public: @since 3.1.5 */ - wxRadioButton* GetFirstInGroup(); + wxRadioButton* GetFirstInGroup() const; /** Returns the last radio button of the @c wxRB_GROUP this instance is in. @@ -150,7 +150,7 @@ public: @since 3.1.5 */ - wxRadioButton* GetLastInGroup(); + wxRadioButton* GetLastInGroup() const; /** Returns the previous radio button of the @c wxRB_GROUP this instance is in. @@ -162,7 +162,7 @@ public: @since 3.1.5 */ - wxRadioButton* GetPreviousInGroup(); + wxRadioButton* GetPreviousInGroup() const; /** Returns the next radio button of the @c wxRB_GROUP this instance is in. @@ -174,6 +174,6 @@ public: @since 3.1.5 */ - wxRadioButton* GetNextInGroup(); + wxRadioButton* GetNextInGroup() const; }; diff --git a/src/common/containr.cpp b/src/common/containr.cpp index 93245b674d..52b808a29f 100644 --- a/src/common/containr.cpp +++ b/src/common/containr.cpp @@ -246,7 +246,7 @@ void wxControlContainer::SetLastFocus(wxWindow *win) namespace wxPrivate { -wxRadioButton* wxGetPreviousButtonInGroup(wxRadioButton *btn) +wxRadioButton* wxGetPreviousButtonInGroup(const wxRadioButton *btn) { if ( btn->HasFlag(wxRB_GROUP) || btn->HasFlag(wxRB_SINGLE) ) return NULL; @@ -276,7 +276,7 @@ wxRadioButton* wxGetPreviousButtonInGroup(wxRadioButton *btn) return prevBtn; } -wxRadioButton* wxGetNextButtonInGroup(wxRadioButton *btn) +wxRadioButton* wxGetNextButtonInGroup(const wxRadioButton *btn) { if (btn->HasFlag(wxRB_SINGLE)) return NULL; @@ -306,35 +306,35 @@ wxRadioButton* wxGetNextButtonInGroup(wxRadioButton *btn) return nextBtn; } -wxRadioButton* wxGetFirstButtonInGroup(wxRadioButton *btn) +wxRadioButton* wxGetFirstButtonInGroup(const wxRadioButton *btn) { while (true) { wxRadioButton* prevBtn = wxGetPreviousButtonInGroup(btn); if (!prevBtn) - return btn; + return const_cast(btn); btn = prevBtn; } } -wxRadioButton* wxGetLastButtonInGroup(wxRadioButton *btn) +wxRadioButton* wxGetLastButtonInGroup(const wxRadioButton *btn) { while (true) { wxRadioButton* nextBtn = wxGetNextButtonInGroup(btn); if (!nextBtn) - return btn; + return const_cast(btn); btn = nextBtn; } } -wxRadioButton* wxGetSelectedButtonInGroup(wxRadioButton *btn) +wxRadioButton* wxGetSelectedButtonInGroup(const wxRadioButton *btn) { // Find currently selected button if (btn->GetValue()) - return btn; + return const_cast(btn); if (btn->HasFlag(wxRB_SINGLE)) return NULL;