replace wxGetMultipleChoices() with wxGetSelectedChoices() which allows to distinguish between cancelling the dialog and not selecting any items in it (closes #10057)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59417 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -274,7 +274,8 @@ Deprecated methods and their replacements
|
||||
were deprecated in favour of wxFileName methods. See docs for more info.
|
||||
- wxEvtHandler::TryValidator/Parent() are deprecated, override the new and
|
||||
documented TryBefore/After() methods if you used to override these ones.
|
||||
|
||||
- wxGetMultipleChoices() is deprecated, use wxGetSelectedChoices() which has
|
||||
the same signature but returns -1 and not 0 if the dialog was cancelled.
|
||||
|
||||
Major new features in this release
|
||||
----------------------------------
|
||||
@@ -498,6 +499,7 @@ All (GUI):
|
||||
- Render <th> element contents in bold in wxHTML.
|
||||
- Added wxGrid::{Set,Get}{Row,Col}Sizes() methods (Andrey Putrin).
|
||||
- Add support for wxSP_WRAP in the generic version of wxSpinCtrlDouble.
|
||||
- Added wxGetSelectedChoices() replacing wxGetMultipleChoices() (Kolya Kosenko).
|
||||
|
||||
wxGTK:
|
||||
|
||||
|
@@ -294,8 +294,8 @@ WXDLLIMPEXP_CORE void* wxGetSingleChoiceData(const wxString& message,
|
||||
|
||||
// fill the array with the indices of the chosen items, it will be empty
|
||||
// if no items were selected or Cancel was pressed - return the number of
|
||||
// selections
|
||||
WXDLLIMPEXP_CORE size_t wxGetMultipleChoices(wxArrayInt& selections,
|
||||
// selections or -1 if cancelled
|
||||
WXDLLIMPEXP_CORE int wxGetSelectedChoices(wxArrayInt& selections,
|
||||
const wxString& message,
|
||||
const wxString& caption,
|
||||
int n, const wxString *choices,
|
||||
@@ -306,7 +306,7 @@ WXDLLIMPEXP_CORE size_t wxGetMultipleChoices(wxArrayInt& selections,
|
||||
int width = wxCHOICE_WIDTH,
|
||||
int height = wxCHOICE_HEIGHT);
|
||||
|
||||
WXDLLIMPEXP_CORE size_t wxGetMultipleChoices(wxArrayInt& selections,
|
||||
WXDLLIMPEXP_CORE int wxGetSelectedChoices(wxArrayInt& selections,
|
||||
const wxString& message,
|
||||
const wxString& caption,
|
||||
const wxArrayString& choices,
|
||||
@@ -317,4 +317,31 @@ WXDLLIMPEXP_CORE size_t wxGetMultipleChoices(wxArrayInt& selections,
|
||||
int width = wxCHOICE_WIDTH,
|
||||
int height = wxCHOICE_HEIGHT);
|
||||
|
||||
#if WXWIN_COMPATIBILITY_2_8
|
||||
// fill the array with the indices of the chosen items, it will be empty
|
||||
// if no items were selected or Cancel was pressed - return the number of
|
||||
// selections
|
||||
wxDEPRECATED( WXDLLIMPEXP_CORE size_t wxGetMultipleChoices(wxArrayInt& selections,
|
||||
const wxString& message,
|
||||
const wxString& caption,
|
||||
int n, const wxString *choices,
|
||||
wxWindow *parent = NULL,
|
||||
int x = wxDefaultCoord,
|
||||
int y = wxDefaultCoord,
|
||||
bool centre = true,
|
||||
int width = wxCHOICE_WIDTH,
|
||||
int height = wxCHOICE_HEIGHT) );
|
||||
|
||||
wxDEPRECATED( WXDLLIMPEXP_CORE size_t wxGetMultipleChoices(wxArrayInt& selections,
|
||||
const wxString& message,
|
||||
const wxString& caption,
|
||||
const wxArrayString& choices,
|
||||
wxWindow *parent = NULL,
|
||||
int x = wxDefaultCoord,
|
||||
int y = wxDefaultCoord,
|
||||
bool centre = true,
|
||||
int width = wxCHOICE_WIDTH,
|
||||
int height = wxCHOICE_HEIGHT));
|
||||
#endif // WXWIN_COMPATIBILITY_2_8
|
||||
|
||||
#endif // _WX_GENERIC_CHOICDGG_H_
|
||||
|
@@ -394,7 +394,8 @@ wxString wxGetSingleChoiceData(const wxString& message,
|
||||
multiple-selection listbox. The user may choose an arbitrary (including 0)
|
||||
number of items in the listbox whose indices will be returned in
|
||||
@c selections array. The initial contents of this array will be used to
|
||||
select the items when the dialog is shown.
|
||||
select the items when the dialog is shown. If the user cancels the dialog,
|
||||
the function returns -1 and @c selections array is left unchanged.
|
||||
|
||||
You may pass the list of strings to choose from either using @c choices
|
||||
which is an array of @a n strings for the listbox or by using a single
|
||||
@@ -405,7 +406,7 @@ wxString wxGetSingleChoiceData(const wxString& message,
|
||||
|
||||
@header{wx/choicdlg.h}
|
||||
*/
|
||||
size_t wxGetMultipleChoices(wxArrayInt& selections,
|
||||
int wxGetSelectedChoices(wxArrayInt& selections,
|
||||
const wxString& message,
|
||||
const wxString& caption,
|
||||
const wxArrayString& aChoices,
|
||||
@@ -415,7 +416,7 @@ size_t wxGetMultipleChoices(wxArrayInt& selections,
|
||||
bool centre = true,
|
||||
int width = 150,
|
||||
int height = 200);
|
||||
size_t wxGetMultipleChoices(wxArrayInt& selections,
|
||||
int wxGetSelectedChoices(wxArrayInt& selections,
|
||||
const wxString& message,
|
||||
const wxString& caption,
|
||||
int n,
|
||||
|
@@ -809,25 +809,32 @@ void MyFrame::MultiChoice(wxCommandEvent& WXUNUSED(event) )
|
||||
};
|
||||
|
||||
wxArrayInt selections;
|
||||
size_t count = wxGetMultipleChoices(selections,
|
||||
const int count = wxGetSelectedChoices(selections,
|
||||
_T("This is a small sample\n")
|
||||
_T("A multi-choice convenience dialog"),
|
||||
_T("Please select a value"),
|
||||
WXSIZEOF(choices), choices,
|
||||
this);
|
||||
if ( count )
|
||||
if ( count >= 0 )
|
||||
{
|
||||
wxString msg;
|
||||
msg.Printf(wxT("You selected %u items:\n"), (unsigned)count);
|
||||
for ( size_t n = 0; n < count; n++ )
|
||||
if ( count == 0 )
|
||||
{
|
||||
msg += wxString::Format(wxT("\t%u: %u (%s)\n"),
|
||||
(unsigned)n, (unsigned)selections[n],
|
||||
choices[selections[n]].c_str());
|
||||
msg = wxT("You did not select any items");
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.Printf(wxT("You selected %u items:\n"), (unsigned)count);
|
||||
for ( int n = 0; n < count; n++ )
|
||||
{
|
||||
msg += wxString::Format(wxT("\t%u: %u (%s)\n"),
|
||||
(unsigned)n, (unsigned)selections[n],
|
||||
choices[selections[n]].c_str());
|
||||
}
|
||||
}
|
||||
wxLogMessage(msg);
|
||||
}
|
||||
//else: cancelled or nothing selected
|
||||
//else: cancelled
|
||||
}
|
||||
#endif // wxUSE_CHOICEDLG
|
||||
|
||||
|
@@ -188,7 +188,7 @@ void *wxGetSingleChoiceData( const wxString& message,
|
||||
return res;
|
||||
}
|
||||
|
||||
size_t wxGetMultipleChoices(wxArrayInt& selections,
|
||||
int wxGetSelectedChoices(wxArrayInt& selections,
|
||||
const wxString& message,
|
||||
const wxString& caption,
|
||||
int n, const wxString *choices,
|
||||
@@ -203,14 +203,59 @@ size_t wxGetMultipleChoices(wxArrayInt& selections,
|
||||
// deselects the first item which is selected by default
|
||||
dialog.SetSelections(selections);
|
||||
|
||||
if ( dialog.ShowModal() == wxID_OK )
|
||||
selections = dialog.GetSelections();
|
||||
else
|
||||
selections.Empty();
|
||||
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 selections.GetCount();
|
||||
}
|
||||
|
||||
int wxGetSelectedChoices(wxArrayInt& selections,
|
||||
const wxString& message,
|
||||
const wxString& caption,
|
||||
const wxArrayString& aChoices,
|
||||
wxWindow *parent,
|
||||
int x, int y,
|
||||
bool centre,
|
||||
int width, int height)
|
||||
{
|
||||
wxString *choices;
|
||||
int n = ConvertWXArrayToC(aChoices, &choices);
|
||||
int res = wxGetSelectedChoices(selections, message, caption,
|
||||
n, choices, parent,
|
||||
x, y, centre, width, height);
|
||||
delete [] choices;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#if WXWIN_COMPATIBILITY_2_8
|
||||
size_t wxGetMultipleChoices(wxArrayInt& selections,
|
||||
const wxString& message,
|
||||
const wxString& caption,
|
||||
int n, const wxString *choices,
|
||||
wxWindow *parent,
|
||||
int x, int y,
|
||||
bool centre,
|
||||
int width, int height)
|
||||
{
|
||||
int rc = wxGetSelectedChoices(selections, message, caption,
|
||||
n, choices,
|
||||
parent, x, y, centre, width, height);
|
||||
if ( rc == -1 )
|
||||
{
|
||||
selections.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
size_t wxGetMultipleChoices(wxArrayInt& selections,
|
||||
const wxString& message,
|
||||
const wxString& caption,
|
||||
@@ -220,15 +265,18 @@ size_t wxGetMultipleChoices(wxArrayInt& selections,
|
||||
bool centre,
|
||||
int width, int height)
|
||||
{
|
||||
wxString *choices;
|
||||
int n = ConvertWXArrayToC(aChoices, &choices);
|
||||
size_t res = wxGetMultipleChoices(selections, message, caption,
|
||||
n, choices, parent,
|
||||
x, y, centre, width, height);
|
||||
delete [] choices;
|
||||
int rc = wxGetSelectedChoices(selections, message, caption,
|
||||
aChoices,
|
||||
parent, x, y, centre, width, height);
|
||||
if ( rc == -1 )
|
||||
{
|
||||
selections.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
return res;
|
||||
return rc;
|
||||
}
|
||||
#endif // WXWIN_COMPATIBILITY_2_8
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxAnyChoiceDialog
|
||||
|
Reference in New Issue
Block a user