From fc12b1f12a26bfa569bbfe2af10af3e5352b6fd4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 5 Feb 2012 14:18:33 +0000 Subject: [PATCH] Take void** client data in wxSingleChoiceDialog ctor and not char**. The client data is supposed to be untyped, there is really no reason (other than compatibility with C conventions of 40 years ago) to use char** here. So don't do it and provide the versions taking "void**" keeping "char**" ones for backwards compatibility only. Also deprecate GetSelectionClientData() that returned char* and add a new GetSelectionData() returning void* instead. Closes #13876. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70514 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 10 ++++ include/wx/generic/choicdgg.h | 89 +++++++++++++++++++++++++++++++---- interface/wx/choicdlg.h | 8 ++-- src/generic/choicdgg.cpp | 31 ++---------- src/html/helpwnd.cpp | 4 +- 5 files changed, 103 insertions(+), 39 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index c723c17e1d..efa010c1f4 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -344,6 +344,11 @@ Changes in behaviour which may result in compilation errors - wxComboBox::IsEmpty(), which was previously available in some ports (but not wxMSW), doesn't exist any more, use either IsListEmpty() or IsTextEmpty(). +- wxSingleChoiceDialog ctors and Create() now have 2 overloaded versions: one + taking void** client data and the deprecated one taking char**. This can + result in compilation errors due to an ambiguity between them if you pass + NULL as client data. To fix this, cast NULL explicitly to "void**". + Deprecated methods and their replacements ----------------------------------------- @@ -412,6 +417,11 @@ Deprecated methods and their replacements - Second parameter of wxSlider::SetTickFreq(int n, int pos) is deprecated, simply remove it from your code and use wxSlider::SetTickFreq(int n) as it was never used anyhow. +- wxSingleChoiceDialog ctor and Create() take "void**" client data pointer + instead of "char**". As the client data is typically untyped, you should + simply remove the casts to "char**" which you probably have in your code if + you use these functions. + Major new features in this release ---------------------------------- diff --git a/include/wx/generic/choicdgg.h b/include/wx/generic/choicdgg.h index 306c3df287..230757b01f 100644 --- a/include/wx/generic/choicdgg.h +++ b/include/wx/generic/choicdgg.h @@ -106,39 +106,112 @@ public: const wxString& caption, int n, const wxString *choices, - char **clientData = (char **)NULL, + void **clientData = NULL, long style = wxCHOICEDLG_STYLE, - const wxPoint& pos = wxDefaultPosition); + const wxPoint& pos = wxDefaultPosition) + { + Create(parent, message, caption, n, choices, clientData, style, pos); + } + wxSingleChoiceDialog(wxWindow *parent, const wxString& message, const wxString& caption, const wxArrayString& choices, - char **clientData = (char **)NULL, + void **clientData = NULL, long style = wxCHOICEDLG_STYLE, - const wxPoint& pos = wxDefaultPosition); + const wxPoint& pos = wxDefaultPosition) + { + Create(parent, message, caption, choices, clientData, style, pos); + } bool Create(wxWindow *parent, const wxString& message, const wxString& caption, int n, const wxString *choices, - char **clientData = (char **)NULL, + void **clientData = NULL, long style = wxCHOICEDLG_STYLE, const wxPoint& pos = wxDefaultPosition); bool Create(wxWindow *parent, const wxString& message, const wxString& caption, const wxArrayString& choices, - char **clientData = (char **)NULL, + void **clientData = NULL, long style = wxCHOICEDLG_STYLE, const wxPoint& pos = wxDefaultPosition); void SetSelection(int sel); int GetSelection() const { return m_selection; } wxString GetStringSelection() const { return m_stringSelection; } + void* GetSelectionData() { return m_clientData; } - // obsolete function (NB: no need to make it return wxChar, it's untyped) - char *GetSelectionClientData() const { return (char *)m_clientData; } +#if WXWIN_COMPATIBILITY_2_8 + // Deprecated overloads taking "char**" client data. + wxDEPRECATED_CONSTRUCTOR + ( + wxSingleChoiceDialog(wxWindow *parent, + const wxString& message, + const wxString& caption, + int n, + const wxString *choices, + char **clientData, + long style = wxCHOICEDLG_STYLE, + const wxPoint& pos = wxDefaultPosition) + ) + { + Create(parent, message, caption, n, choices, + (void**)clientData, style, pos); + } + + wxDEPRECATED_CONSTRUCTOR + ( + wxSingleChoiceDialog(wxWindow *parent, + const wxString& message, + const wxString& caption, + const wxArrayString& choices, + char **clientData, + long style = wxCHOICEDLG_STYLE, + const wxPoint& pos = wxDefaultPosition) + ) + { + Create(parent, message, caption, choices, + (void**)clientData, style, pos); + } + + wxDEPRECATED_INLINE + ( + bool Create(wxWindow *parent, + const wxString& message, + const wxString& caption, + int n, + const wxString *choices, + char **clientData, + long style = wxCHOICEDLG_STYLE, + const wxPoint& pos = wxDefaultPosition), + return Create(parent, message, caption, n, choices, + (void**)clientData, style, pos); + ) + + wxDEPRECATED_INLINE + ( + bool Create(wxWindow *parent, + const wxString& message, + const wxString& caption, + const wxArrayString& choices, + char **clientData, + long style = wxCHOICEDLG_STYLE, + const wxPoint& pos = wxDefaultPosition), + return Create(parent, message, caption, choices, + (void**)clientData, style, pos); + ) + + // NB: no need to make it return wxChar, it's untyped + wxDEPRECATED_ACCESSOR + ( + char* GetSelectionClientData(), + (char*)GetClientData() + ) +#endif // WXWIN_COMPATIBILITY_2_8 // implementation from now on void OnOK(wxCommandEvent& event); diff --git a/interface/wx/choicdlg.h b/interface/wx/choicdlg.h index c10074aad9..70ff5d444b 100644 --- a/interface/wx/choicdlg.h +++ b/interface/wx/choicdlg.h @@ -170,7 +170,7 @@ public: An array of strings, or a string list, containing the choices. @param clientData An array of client data to be associated with the items. See - GetSelectionClientData(). + GetSelectionData(). @param style A dialog style (bitlist) containing flags chosen from standard dialog styles and the ones listed below. The default value is @@ -222,7 +222,7 @@ public: An array of strings, or a string list, containing the choices. @param clientData An array of client data to be associated with the items. See - GetSelectionClientData(). + GetSelectionData(). @param style A dialog style (bitlist) containing flags chosen from standard dialog styles and the ones listed below. The default value is @@ -270,8 +270,10 @@ public: /** Returns the client data associated with the selection. + + @since 2.9.4 */ - char* GetSelectionClientData() const; + void* GetSelectionData() const; /** Returns the selected string. diff --git a/src/generic/choicdgg.cpp b/src/generic/choicdgg.cpp index 79f7019d0d..612b285ba4 100644 --- a/src/generic/choicdgg.cpp +++ b/src/generic/choicdgg.cpp @@ -222,13 +222,13 @@ void *wxGetSingleChoiceData( const wxString& message, int initialSelection) { wxSingleChoiceDialog dialog(parent, message, caption, n, choices, - (char **)client_data); + client_data); dialog.SetSelection(initialSelection); void *data; if ( dialog.ShowModal() == wxID_OK ) - data = dialog.GetSelectionClientData(); + data = dialog.GetSelectionData(); else data = NULL; @@ -467,35 +467,12 @@ END_EVENT_TABLE() IMPLEMENT_DYNAMIC_CLASS(wxSingleChoiceDialog, wxDialog) -wxSingleChoiceDialog::wxSingleChoiceDialog(wxWindow *parent, - const wxString& message, - const wxString& caption, - int n, - const wxString *choices, - char **clientData, - long style, - const wxPoint& WXUNUSED(pos)) -{ - Create(parent, message, caption, n, choices, clientData, style); -} - -wxSingleChoiceDialog::wxSingleChoiceDialog(wxWindow *parent, - const wxString& message, - const wxString& caption, - const wxArrayString& choices, - char **clientData, - long style, - const wxPoint& WXUNUSED(pos)) -{ - Create(parent, message, caption, choices, clientData, style); -} - bool wxSingleChoiceDialog::Create( wxWindow *parent, const wxString& message, const wxString& caption, int n, const wxString *choices, - char **clientData, + void **clientData, long style, const wxPoint& pos ) { @@ -519,7 +496,7 @@ bool wxSingleChoiceDialog::Create( wxWindow *parent, const wxString& message, const wxString& caption, const wxArrayString& choices, - char **clientData, + void **clientData, long style, const wxPoint& pos ) { diff --git a/src/html/helpwnd.cpp b/src/html/helpwnd.cpp index dcd41a55bd..3518cb3b2d 100644 --- a/src/html/helpwnd.cpp +++ b/src/html/helpwnd.cpp @@ -813,7 +813,9 @@ void wxHtmlHelpWindow::DisplayIndexItem(const wxHtmlHelpMergedIndexItem *it) wxSingleChoiceDialog dlg(this, _("Please choose the page to display:"), _("Help Topics"), - arr, NULL, wxCHOICEDLG_STYLE & ~wxCENTRE); + arr, + (void**)NULL, // No client data + wxCHOICEDLG_STYLE & ~wxCENTRE); if (dlg.ShowModal() == wxID_OK) { m_HtmlWin->LoadPage(it->items[dlg.GetSelection()]->GetFullPath()); -- 2.45.2