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.
This commit is contained in:
Vadim Zeitlin
2020-09-21 15:36:41 +02:00
parent b5fb9bd8d6
commit 1a4f628e40
3 changed files with 24 additions and 24 deletions

View File

@@ -36,10 +36,10 @@ class WXDLLIMPEXP_FWD_CORE wxRadioButton;
namespace wxPrivate namespace wxPrivate
{ {
WXDLLIMPEXP_CORE wxRadioButton* wxGetNextButtonInGroup(wxRadioButton *btn); WXDLLIMPEXP_CORE wxRadioButton* wxGetNextButtonInGroup(const wxRadioButton *btn);
WXDLLIMPEXP_CORE wxRadioButton* wxGetPreviousButtonInGroup(wxRadioButton *btn); WXDLLIMPEXP_CORE wxRadioButton* wxGetPreviousButtonInGroup(const wxRadioButton *btn);
WXDLLIMPEXP_CORE wxRadioButton* wxGetFirstButtonInGroup(wxRadioButton *btn); WXDLLIMPEXP_CORE wxRadioButton* wxGetFirstButtonInGroup(const wxRadioButton *btn);
WXDLLIMPEXP_CORE wxRadioButton* wxGetLastButtonInGroup(wxRadioButton *btn); WXDLLIMPEXP_CORE wxRadioButton* wxGetLastButtonInGroup(const wxRadioButton *btn);
} // namespace wxPrivate } // namespace wxPrivate
template <class W> template <class W>
@@ -50,24 +50,24 @@ public:
wxRadioButtonBase() { } wxRadioButtonBase() { }
wxRadioButton* GetFirstInGroup() wxRadioButton* GetFirstInGroup() const
{ {
return wxPrivate::wxGetFirstButtonInGroup( static_cast<wxRadioButton*>(this)); return wxPrivate::wxGetFirstButtonInGroup(static_cast<const wxRadioButton*>(this));
} }
wxRadioButton* GetLastInGroup() wxRadioButton* GetLastInGroup() const
{ {
return wxPrivate::wxGetLastButtonInGroup( static_cast<wxRadioButton*>(this)); return wxPrivate::wxGetLastButtonInGroup(static_cast<const wxRadioButton*>(this));
} }
wxRadioButton* GetPreviousInGroup() wxRadioButton* GetPreviousInGroup() const
{ {
return wxPrivate::wxGetPreviousButtonInGroup( static_cast<wxRadioButton*>(this)); return wxPrivate::wxGetPreviousButtonInGroup(static_cast<const wxRadioButton*>(this));
} }
wxRadioButton* GetNextInGroup() wxRadioButton* GetNextInGroup() const
{ {
return wxPrivate::wxGetNextButtonInGroup( static_cast<wxRadioButton*>(this)); return wxPrivate::wxGetNextButtonInGroup(static_cast<const wxRadioButton*>(this));
} }
private: private:

View File

@@ -139,7 +139,7 @@ public:
@since 3.1.5 @since 3.1.5
*/ */
wxRadioButton* GetFirstInGroup(); wxRadioButton* GetFirstInGroup() const;
/** /**
Returns the last radio button of the @c wxRB_GROUP this instance is in. Returns the last radio button of the @c wxRB_GROUP this instance is in.
@@ -150,7 +150,7 @@ public:
@since 3.1.5 @since 3.1.5
*/ */
wxRadioButton* GetLastInGroup(); wxRadioButton* GetLastInGroup() const;
/** /**
Returns the previous radio button of the @c wxRB_GROUP this instance is in. Returns the previous radio button of the @c wxRB_GROUP this instance is in.
@@ -162,7 +162,7 @@ public:
@since 3.1.5 @since 3.1.5
*/ */
wxRadioButton* GetPreviousInGroup(); wxRadioButton* GetPreviousInGroup() const;
/** /**
Returns the next radio button of the @c wxRB_GROUP this instance is in. Returns the next radio button of the @c wxRB_GROUP this instance is in.
@@ -174,6 +174,6 @@ public:
@since 3.1.5 @since 3.1.5
*/ */
wxRadioButton* GetNextInGroup(); wxRadioButton* GetNextInGroup() const;
}; };

View File

@@ -246,7 +246,7 @@ void wxControlContainer::SetLastFocus(wxWindow *win)
namespace wxPrivate namespace wxPrivate
{ {
wxRadioButton* wxGetPreviousButtonInGroup(wxRadioButton *btn) wxRadioButton* wxGetPreviousButtonInGroup(const wxRadioButton *btn)
{ {
if ( btn->HasFlag(wxRB_GROUP) || btn->HasFlag(wxRB_SINGLE) ) if ( btn->HasFlag(wxRB_GROUP) || btn->HasFlag(wxRB_SINGLE) )
return NULL; return NULL;
@@ -276,7 +276,7 @@ wxRadioButton* wxGetPreviousButtonInGroup(wxRadioButton *btn)
return prevBtn; return prevBtn;
} }
wxRadioButton* wxGetNextButtonInGroup(wxRadioButton *btn) wxRadioButton* wxGetNextButtonInGroup(const wxRadioButton *btn)
{ {
if (btn->HasFlag(wxRB_SINGLE)) if (btn->HasFlag(wxRB_SINGLE))
return NULL; return NULL;
@@ -306,35 +306,35 @@ wxRadioButton* wxGetNextButtonInGroup(wxRadioButton *btn)
return nextBtn; return nextBtn;
} }
wxRadioButton* wxGetFirstButtonInGroup(wxRadioButton *btn) wxRadioButton* wxGetFirstButtonInGroup(const wxRadioButton *btn)
{ {
while (true) while (true)
{ {
wxRadioButton* prevBtn = wxGetPreviousButtonInGroup(btn); wxRadioButton* prevBtn = wxGetPreviousButtonInGroup(btn);
if (!prevBtn) if (!prevBtn)
return btn; return const_cast<wxRadioButton*>(btn);
btn = prevBtn; btn = prevBtn;
} }
} }
wxRadioButton* wxGetLastButtonInGroup(wxRadioButton *btn) wxRadioButton* wxGetLastButtonInGroup(const wxRadioButton *btn)
{ {
while (true) while (true)
{ {
wxRadioButton* nextBtn = wxGetNextButtonInGroup(btn); wxRadioButton* nextBtn = wxGetNextButtonInGroup(btn);
if (!nextBtn) if (!nextBtn)
return btn; return const_cast<wxRadioButton*>(btn);
btn = nextBtn; btn = nextBtn;
} }
} }
wxRadioButton* wxGetSelectedButtonInGroup(wxRadioButton *btn) wxRadioButton* wxGetSelectedButtonInGroup(const wxRadioButton *btn)
{ {
// Find currently selected button // Find currently selected button
if (btn->GetValue()) if (btn->GetValue())
return btn; return const_cast<wxRadioButton*>(btn);
if (btn->HasFlag(wxRB_SINGLE)) if (btn->HasFlag(wxRB_SINGLE))
return NULL; return NULL;