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.
|
were deprecated in favour of wxFileName methods. See docs for more info.
|
||||||
- wxEvtHandler::TryValidator/Parent() are deprecated, override the new and
|
- wxEvtHandler::TryValidator/Parent() are deprecated, override the new and
|
||||||
documented TryBefore/After() methods if you used to override these ones.
|
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
|
Major new features in this release
|
||||||
----------------------------------
|
----------------------------------
|
||||||
@@ -498,6 +499,7 @@ All (GUI):
|
|||||||
- Render <th> element contents in bold in wxHTML.
|
- Render <th> element contents in bold in wxHTML.
|
||||||
- Added wxGrid::{Set,Get}{Row,Col}Sizes() methods (Andrey Putrin).
|
- Added wxGrid::{Set,Get}{Row,Col}Sizes() methods (Andrey Putrin).
|
||||||
- Add support for wxSP_WRAP in the generic version of wxSpinCtrlDouble.
|
- Add support for wxSP_WRAP in the generic version of wxSpinCtrlDouble.
|
||||||
|
- Added wxGetSelectedChoices() replacing wxGetMultipleChoices() (Kolya Kosenko).
|
||||||
|
|
||||||
wxGTK:
|
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
|
// 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
|
// if no items were selected or Cancel was pressed - return the number of
|
||||||
// selections
|
// selections or -1 if cancelled
|
||||||
WXDLLIMPEXP_CORE size_t wxGetMultipleChoices(wxArrayInt& selections,
|
WXDLLIMPEXP_CORE 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,
|
||||||
@@ -306,7 +306,7 @@ WXDLLIMPEXP_CORE size_t wxGetMultipleChoices(wxArrayInt& selections,
|
|||||||
int width = wxCHOICE_WIDTH,
|
int width = wxCHOICE_WIDTH,
|
||||||
int height = wxCHOICE_HEIGHT);
|
int height = wxCHOICE_HEIGHT);
|
||||||
|
|
||||||
WXDLLIMPEXP_CORE size_t wxGetMultipleChoices(wxArrayInt& selections,
|
WXDLLIMPEXP_CORE int wxGetSelectedChoices(wxArrayInt& selections,
|
||||||
const wxString& message,
|
const wxString& message,
|
||||||
const wxString& caption,
|
const wxString& caption,
|
||||||
const wxArrayString& choices,
|
const wxArrayString& choices,
|
||||||
@@ -317,4 +317,31 @@ WXDLLIMPEXP_CORE size_t wxGetMultipleChoices(wxArrayInt& selections,
|
|||||||
int width = wxCHOICE_WIDTH,
|
int width = wxCHOICE_WIDTH,
|
||||||
int height = wxCHOICE_HEIGHT);
|
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_
|
#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)
|
multiple-selection listbox. The user may choose an arbitrary (including 0)
|
||||||
number of items in the listbox whose indices will be returned in
|
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
|
@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
|
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
|
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}
|
@header{wx/choicdlg.h}
|
||||||
*/
|
*/
|
||||||
size_t wxGetMultipleChoices(wxArrayInt& selections,
|
int wxGetSelectedChoices(wxArrayInt& selections,
|
||||||
const wxString& message,
|
const wxString& message,
|
||||||
const wxString& caption,
|
const wxString& caption,
|
||||||
const wxArrayString& aChoices,
|
const wxArrayString& aChoices,
|
||||||
@@ -415,7 +416,7 @@ size_t wxGetMultipleChoices(wxArrayInt& selections,
|
|||||||
bool centre = true,
|
bool centre = true,
|
||||||
int width = 150,
|
int width = 150,
|
||||||
int height = 200);
|
int height = 200);
|
||||||
size_t wxGetMultipleChoices(wxArrayInt& selections,
|
int wxGetSelectedChoices(wxArrayInt& selections,
|
||||||
const wxString& message,
|
const wxString& message,
|
||||||
const wxString& caption,
|
const wxString& caption,
|
||||||
int n,
|
int n,
|
||||||
|
@@ -809,25 +809,32 @@ void MyFrame::MultiChoice(wxCommandEvent& WXUNUSED(event) )
|
|||||||
};
|
};
|
||||||
|
|
||||||
wxArrayInt selections;
|
wxArrayInt selections;
|
||||||
size_t count = wxGetMultipleChoices(selections,
|
const int count = wxGetSelectedChoices(selections,
|
||||||
_T("This is a small sample\n")
|
_T("This is a small sample\n")
|
||||||
_T("A multi-choice convenience dialog"),
|
_T("A multi-choice convenience dialog"),
|
||||||
_T("Please select a value"),
|
_T("Please select a value"),
|
||||||
WXSIZEOF(choices), choices,
|
WXSIZEOF(choices), choices,
|
||||||
this);
|
this);
|
||||||
if ( count )
|
if ( count >= 0 )
|
||||||
{
|
{
|
||||||
wxString msg;
|
wxString msg;
|
||||||
|
if ( count == 0 )
|
||||||
|
{
|
||||||
|
msg = wxT("You did not select any items");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
msg.Printf(wxT("You selected %u items:\n"), (unsigned)count);
|
msg.Printf(wxT("You selected %u items:\n"), (unsigned)count);
|
||||||
for ( size_t n = 0; n < count; n++ )
|
for ( int n = 0; n < count; n++ )
|
||||||
{
|
{
|
||||||
msg += wxString::Format(wxT("\t%u: %u (%s)\n"),
|
msg += wxString::Format(wxT("\t%u: %u (%s)\n"),
|
||||||
(unsigned)n, (unsigned)selections[n],
|
(unsigned)n, (unsigned)selections[n],
|
||||||
choices[selections[n]].c_str());
|
choices[selections[n]].c_str());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
wxLogMessage(msg);
|
wxLogMessage(msg);
|
||||||
}
|
}
|
||||||
//else: cancelled or nothing selected
|
//else: cancelled
|
||||||
}
|
}
|
||||||
#endif // wxUSE_CHOICEDLG
|
#endif // wxUSE_CHOICEDLG
|
||||||
|
|
||||||
|
@@ -188,7 +188,7 @@ void *wxGetSingleChoiceData( const wxString& message,
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t wxGetMultipleChoices(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,
|
||||||
@@ -203,14 +203,59 @@ size_t wxGetMultipleChoices(wxArrayInt& selections,
|
|||||||
// deselects the first item which is selected by default
|
// deselects the first item which is selected by default
|
||||||
dialog.SetSelections(selections);
|
dialog.SetSelections(selections);
|
||||||
|
|
||||||
if ( dialog.ShowModal() == wxID_OK )
|
if ( dialog.ShowModal() != wxID_OK )
|
||||||
selections = dialog.GetSelections();
|
{
|
||||||
else
|
// NB: intentionally do not clear the selections array here, the caller
|
||||||
selections.Empty();
|
// might want to preserve its original contents if the dialog was
|
||||||
|
// cancelled
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
selections = dialog.GetSelections();
|
||||||
return selections.GetCount();
|
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,
|
size_t wxGetMultipleChoices(wxArrayInt& selections,
|
||||||
const wxString& message,
|
const wxString& message,
|
||||||
const wxString& caption,
|
const wxString& caption,
|
||||||
@@ -220,16 +265,19 @@ size_t wxGetMultipleChoices(wxArrayInt& selections,
|
|||||||
bool centre,
|
bool centre,
|
||||||
int width, int height)
|
int width, int height)
|
||||||
{
|
{
|
||||||
wxString *choices;
|
int rc = wxGetSelectedChoices(selections, message, caption,
|
||||||
int n = ConvertWXArrayToC(aChoices, &choices);
|
aChoices,
|
||||||
size_t res = wxGetMultipleChoices(selections, message, caption,
|
parent, x, y, centre, width, height);
|
||||||
n, choices, parent,
|
if ( rc == -1 )
|
||||||
x, y, centre, width, height);
|
{
|
||||||
delete [] choices;
|
selections.clear();
|
||||||
|
return 0;
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
#endif // WXWIN_COMPATIBILITY_2_8
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxAnyChoiceDialog
|
// wxAnyChoiceDialog
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user