Remove unnecessary ConvertWXArrayToC() helper choice dialog code.

Just use the appropriate wxSingleChoiceDialog ctor directly.

Also some renamings/reformattings, but no other real changes.

Closes #16383.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76930 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-07-15 13:27:01 +00:00
parent a325ade884
commit a29e7318e6

View File

@@ -52,30 +52,10 @@
// private functions // private functions
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// convert wxArrayString into a wxString[] which must be delete[]d by caller
static int ConvertWXArrayToC(const wxArrayString& aChoices, wxString **choices);
// ============================================================================ // ============================================================================
// implementation // implementation
// ============================================================================ // ============================================================================
// ----------------------------------------------------------------------------
// helpers
// ----------------------------------------------------------------------------
int ConvertWXArrayToC(const wxArrayString& aChoices, wxString **choices)
{
int n = aChoices.GetCount();
*choices = new wxString[n];
for ( int i = 0; i < n; i++ )
{
(*choices)[i] = aChoices[i];
}
return n;
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wrapper functions // wrapper functions
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -92,31 +72,22 @@ wxString wxGetSingleChoice( const wxString& message,
wxSingleChoiceDialog dialog(parent, message, caption, n, choices); wxSingleChoiceDialog dialog(parent, message, caption, n, choices);
dialog.SetSelection(initialSelection); dialog.SetSelection(initialSelection);
return dialog.ShowModal() == wxID_OK ? dialog.GetStringSelection() : wxString();
wxString choice;
if ( dialog.ShowModal() == wxID_OK )
choice = dialog.GetStringSelection();
return choice;
} }
wxString wxGetSingleChoice( const wxString& message, wxString wxGetSingleChoice( const wxString& message,
const wxString& caption, const wxString& caption,
const wxArrayString& aChoices, const wxArrayString& choices,
wxWindow *parent, wxWindow *parent,
int x, int y, int WXUNUSED(x), int WXUNUSED(y),
bool centre, bool WXUNUSED(centre),
int width, int height, int WXUNUSED(width), int WXUNUSED(height),
int initialSelection) int initialSelection)
{ {
wxString *choices; wxSingleChoiceDialog dialog(parent, message, caption, choices);
int n = ConvertWXArrayToC(aChoices, &choices);
wxString res = wxGetSingleChoice(message, caption, n, choices, parent,
x, y, centre, width, height,
initialSelection);
delete [] choices;
return res; dialog.SetSelection(initialSelection);
return dialog.ShowModal() == wxID_OK ? dialog.GetStringSelection() : wxString();
} }
wxString wxGetSingleChoice( const wxString& message, wxString wxGetSingleChoice( const wxString& message,
@@ -155,33 +126,22 @@ int wxGetSingleChoiceIndex( const wxString& message,
wxSingleChoiceDialog dialog(parent, message, caption, n, choices); wxSingleChoiceDialog dialog(parent, message, caption, n, choices);
dialog.SetSelection(initialSelection); dialog.SetSelection(initialSelection);
return dialog.ShowModal() == wxID_OK ? dialog.GetSelection() : -1;
int choice;
if ( dialog.ShowModal() == wxID_OK )
choice = dialog.GetSelection();
else
choice = -1;
return choice;
} }
int wxGetSingleChoiceIndex( const wxString& message, int wxGetSingleChoiceIndex( const wxString& message,
const wxString& caption, const wxString& caption,
const wxArrayString& aChoices, const wxArrayString& choices,
wxWindow *parent, wxWindow *parent,
int x, int y, int WXUNUSED(x), int WXUNUSED(y),
bool centre, bool WXUNUSED(centre),
int width, int height, int WXUNUSED(width), int WXUNUSED(height),
int initialSelection) int initialSelection)
{ {
wxString *choices; wxSingleChoiceDialog dialog(parent, message, caption, choices);
int n = ConvertWXArrayToC(aChoices, &choices);
int res = wxGetSingleChoiceIndex(message, caption, n, choices, parent,
x, y, centre, width, height,
initialSelection);
delete [] choices;
return res; dialog.SetSelection(initialSelection);
return dialog.ShowModal() == wxID_OK ? dialog.GetSelection() : -1;
} }
int wxGetSingleChoiceIndex( const wxString& message, int wxGetSingleChoiceIndex( const wxString& message,
@@ -224,35 +184,23 @@ void *wxGetSingleChoiceData( const wxString& message,
client_data); client_data);
dialog.SetSelection(initialSelection); dialog.SetSelection(initialSelection);
return dialog.ShowModal() == wxID_OK ? dialog.GetSelectionData() : NULL;
void *data;
if ( dialog.ShowModal() == wxID_OK )
data = dialog.GetSelectionData();
else
data = NULL;
return data;
} }
void *wxGetSingleChoiceData( const wxString& message, void *wxGetSingleChoiceData( const wxString& message,
const wxString& caption, const wxString& caption,
const wxArrayString& aChoices, const wxArrayString& choices,
void **client_data, void **client_data,
wxWindow *parent, wxWindow *parent,
int x, int y, int WXUNUSED(x), int WXUNUSED(y),
bool centre, bool WXUNUSED(centre),
int width, int height, int WXUNUSED(width), int WXUNUSED(height),
int initialSelection) int initialSelection)
{ {
wxString *choices; wxSingleChoiceDialog dialog(parent, message, caption, choices, client_data);
int n = ConvertWXArrayToC(aChoices, &choices);
void *res = wxGetSingleChoiceData(message, caption, n, choices,
client_data, parent,
x, y, centre, width, height,
initialSelection);
delete [] choices;
return res; dialog.SetSelection(initialSelection);
return dialog.ShowModal() == wxID_OK ? dialog.GetSelectionData() : NULL;
} }
void* wxGetSingleChoiceData( const wxString& message, void* wxGetSingleChoiceData( const wxString& message,
@@ -285,13 +233,13 @@ void* wxGetSingleChoiceData( const wxString& message,
int wxGetSelectedChoices(wxArrayInt& selections, int wxGetSelectedChoices(wxArrayInt& selections,
const wxString& message, const wxString& message,
const wxString& caption, const wxString& caption,
int n, const wxString *choices, int n, const wxString *choices,
wxWindow *parent, wxWindow *parent,
int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(x), int WXUNUSED(y),
bool WXUNUSED(centre), bool WXUNUSED(centre),
int WXUNUSED(width), int WXUNUSED(height)) int WXUNUSED(width), int WXUNUSED(height))
{ {
wxMultiChoiceDialog dialog(parent, message, caption, n, choices); wxMultiChoiceDialog dialog(parent, message, caption, n, choices);
@@ -308,26 +256,34 @@ int wxGetSelectedChoices(wxArrayInt& selections,
} }
selections = dialog.GetSelections(); selections = dialog.GetSelections();
return selections.GetCount(); return static_cast<int>(selections.GetCount());
} }
int wxGetSelectedChoices(wxArrayInt& selections, int wxGetSelectedChoices(wxArrayInt& selections,
const wxString& message, const wxString& message,
const wxString& caption, const wxString& caption,
const wxArrayString& aChoices, const wxArrayString& choices,
wxWindow *parent, wxWindow *parent,
int x, int y, int WXUNUSED(x), int WXUNUSED(y),
bool centre, bool WXUNUSED(centre),
int width, int height) int WXUNUSED(width), int WXUNUSED(height))
{ {
wxString *choices; wxMultiChoiceDialog dialog(parent, message, caption, choices);
int n = ConvertWXArrayToC(aChoices, &choices);
int res = wxGetSelectedChoices(selections, message, caption,
n, choices, parent,
x, y, centre, width, height);
delete [] choices;
return res; // call this even if selections array is empty and this then (correctly)
// deselects the first item which is selected by default
dialog.SetSelections(selections);
if ( dialog.ShowModal() != wxID_OK )
{
// NB: intentionally do not clear the selections array here, the caller
// might want to preserve its original contents if the dialog was
// cancelled
return -1;
}
selections = dialog.GetSelections();
return static_cast<int>(selections.GetCount());
} }
#if WXWIN_COMPATIBILITY_2_8 #if WXWIN_COMPATIBILITY_2_8