Add initial selection parameter to wxGetSingleChoice() functions.

Allow to easily specify the initially selected item.

Closes #11749.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63731 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-03-21 11:06:31 +00:00
parent be103d4a3d
commit 697f4a966e
4 changed files with 216 additions and 22 deletions

View File

@@ -496,6 +496,7 @@ All (GUI):
- Add wxComboBox::Popup() and Dismiss() methods (Igor Korot). - Add wxComboBox::Popup() and Dismiss() methods (Igor Korot).
- Added wxTreeCtrl::SelectChildren() (Nikolay Tjushkov). - Added wxTreeCtrl::SelectChildren() (Nikolay Tjushkov).
- Show pages icons in window list menu in wxAuiNotebook (Ronny Krüger). - Show pages icons in window list menu in wxAuiNotebook (Ronny Krüger).
- Add "initial selection" parameter to wxGetSingleChoice() (Nikolay Tjushkov).
GTK: GTK:

View File

@@ -235,7 +235,8 @@ WXDLLIMPEXP_CORE wxString wxGetSingleChoice(const wxString& message,
int y = wxDefaultCoord, int y = wxDefaultCoord,
bool centre = true, bool centre = true,
int width = wxCHOICE_WIDTH, int width = wxCHOICE_WIDTH,
int height = wxCHOICE_HEIGHT); int height = wxCHOICE_HEIGHT,
int initialSelection = 0);
WXDLLIMPEXP_CORE wxString wxGetSingleChoice(const wxString& message, WXDLLIMPEXP_CORE wxString wxGetSingleChoice(const wxString& message,
const wxString& caption, const wxString& caption,
@@ -245,7 +246,20 @@ WXDLLIMPEXP_CORE wxString wxGetSingleChoice(const wxString& message,
int y = wxDefaultCoord, int y = wxDefaultCoord,
bool centre = true, bool centre = true,
int width = wxCHOICE_WIDTH, int width = wxCHOICE_WIDTH,
int height = wxCHOICE_HEIGHT); int height = wxCHOICE_HEIGHT,
int initialSelection = 0);
WXDLLIMPEXP_CORE wxString wxGetSingleChoice(const wxString& message,
const wxString& caption,
const wxArrayString& choices,
int initialSelection,
wxWindow *parent = NULL);
WXDLLIMPEXP_CORE wxString wxGetSingleChoice(const wxString& message,
const wxString& caption,
int n, const wxString *choices,
int initialSelection,
wxWindow *parent = NULL);
// Same as above but gets position in list of strings, instead of string, // Same as above but gets position in list of strings, instead of string,
// or -1 if no selection // or -1 if no selection
@@ -257,7 +271,8 @@ WXDLLIMPEXP_CORE int wxGetSingleChoiceIndex(const wxString& message,
int y = wxDefaultCoord, int y = wxDefaultCoord,
bool centre = true, bool centre = true,
int width = wxCHOICE_WIDTH, int width = wxCHOICE_WIDTH,
int height = wxCHOICE_HEIGHT); int height = wxCHOICE_HEIGHT,
int initialSelection = 0);
WXDLLIMPEXP_CORE int wxGetSingleChoiceIndex(const wxString& message, WXDLLIMPEXP_CORE int wxGetSingleChoiceIndex(const wxString& message,
const wxString& caption, const wxString& caption,
@@ -267,9 +282,22 @@ WXDLLIMPEXP_CORE int wxGetSingleChoiceIndex(const wxString& message,
int y = wxDefaultCoord, int y = wxDefaultCoord,
bool centre = true, bool centre = true,
int width = wxCHOICE_WIDTH, int width = wxCHOICE_WIDTH,
int height = wxCHOICE_HEIGHT); int height = wxCHOICE_HEIGHT,
int initialSelection = 0);
// Return client data instead or NULL if cancelled WXDLLIMPEXP_CORE int wxGetSingleChoiceIndex(const wxString& message,
const wxString& caption,
const wxArrayString& choices,
int initialSelection,
wxWindow *parent = NULL);
WXDLLIMPEXP_CORE int wxGetSingleChoiceIndex(const wxString& message,
const wxString& caption,
int n, const wxString *choices,
int initialSelection,
wxWindow *parent = NULL);
// Return client data instead or NULL if canceled
WXDLLIMPEXP_CORE void* wxGetSingleChoiceData(const wxString& message, WXDLLIMPEXP_CORE void* wxGetSingleChoiceData(const wxString& message,
const wxString& caption, const wxString& caption,
const wxArrayString& choices, const wxArrayString& choices,
@@ -279,7 +307,8 @@ WXDLLIMPEXP_CORE void* wxGetSingleChoiceData(const wxString& message,
int y = wxDefaultCoord, int y = wxDefaultCoord,
bool centre = true, bool centre = true,
int width = wxCHOICE_WIDTH, int width = wxCHOICE_WIDTH,
int height = wxCHOICE_HEIGHT); int height = wxCHOICE_HEIGHT,
int initialSelection = 0);
WXDLLIMPEXP_CORE void* wxGetSingleChoiceData(const wxString& message, WXDLLIMPEXP_CORE void* wxGetSingleChoiceData(const wxString& message,
const wxString& caption, const wxString& caption,
@@ -290,7 +319,23 @@ WXDLLIMPEXP_CORE void* wxGetSingleChoiceData(const wxString& message,
int y = wxDefaultCoord, int y = wxDefaultCoord,
bool centre = true, bool centre = true,
int width = wxCHOICE_WIDTH, int width = wxCHOICE_WIDTH,
int height = wxCHOICE_HEIGHT); int height = wxCHOICE_HEIGHT,
int initialSelection = 0);
WXDLLIMPEXP_CORE void* wxGetSingleChoiceData(const wxString& message,
const wxString& caption,
const wxArrayString& choices,
void **client_data,
int initialSelection,
wxWindow *parent = NULL);
WXDLLIMPEXP_CORE void* wxGetSingleChoiceData(const wxString& message,
const wxString& caption,
int n, const wxString *choices,
void **client_data,
int initialSelection,
wxWindow *parent = NULL);
// 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

View File

@@ -316,7 +316,9 @@ int wxGetSingleChoiceIndex(const wxString& message,
int y = -1, int y = -1,
bool centre = true, bool centre = true,
int width = 150, int width = 150,
int height = 200); int height = 200,
int initialSelection = 0);
int wxGetSingleChoiceIndex(const wxString& message, int wxGetSingleChoiceIndex(const wxString& message,
const wxString& caption, const wxString& caption,
int n, int n,
@@ -326,8 +328,21 @@ int wxGetSingleChoiceIndex(const wxString& message,
int y = -1, int y = -1,
bool centre = true, bool centre = true,
int width = 150, int width = 150,
int height = 200); int height = 200,
int initialSelection = 0);
int wxGetSingleChoiceIndex(const wxString& message,
const wxString& caption,
const wxArrayString& choices,
int initialSelection,
wxWindow *parent = NULL);
int wxGetSingleChoiceIndex(const wxString& message,
const wxString& caption,
int n, const wxString *choices,
int initialSelection,
wxWindow *parent = NULL);
//@} //@}
/** @addtogroup group_funcmacro_dialog */ /** @addtogroup group_funcmacro_dialog */
@@ -361,7 +376,8 @@ wxString wxGetSingleChoice(const wxString& message,
int y = -1, int y = -1,
bool centre = true, bool centre = true,
int width = 150, int width = 150,
int height = 200); int height = 200
int initialSelection = 0);
wxString wxGetSingleChoice(const wxString& message, wxString wxGetSingleChoice(const wxString& message,
const wxString& caption, const wxString& caption,
int n, int n,
@@ -371,7 +387,21 @@ wxString wxGetSingleChoice(const wxString& message,
int y = -1, int y = -1,
bool centre = true, bool centre = true,
int width = 150, int width = 150,
int height = 200); int height = 200
int initialSelection = 0);
wxString wxGetSingleChoice(const wxString& message,
const wxString& caption,
const wxArrayString& choices,
int initialSelection,
wxWindow *parent = NULL);
wxString wxGetSingleChoice(const wxString& message,
const wxString& caption,
int n, const wxString *choices,
int initialSelection,
wxWindow *parent = NULL);
//@} //@}
@@ -399,7 +429,9 @@ wxString wxGetSingleChoiceData(const wxString& message,
int y = -1, int y = -1,
bool centre = true, bool centre = true,
int width = 150, int width = 150,
int height = 200); int height = 200
int initialSelection = 0);
wxString wxGetSingleChoiceData(const wxString& message, wxString wxGetSingleChoiceData(const wxString& message,
const wxString& caption, const wxString& caption,
int n, int n,
@@ -410,7 +442,22 @@ wxString wxGetSingleChoiceData(const wxString& message,
int y = -1, int y = -1,
bool centre = true, bool centre = true,
int width = 150, int width = 150,
int height = 200); int height = 200
int initialSelection = 0);
void* wxGetSingleChoiceData(const wxString& message,
const wxString& caption,
const wxArrayString& choices,
void **client_data,
int initialSelection,
wxWindow *parent = NULL);
void* wxGetSingleChoiceData(const wxString& message,
const wxString& caption,
int n, const wxString *choices,
void **client_data,
int initialSelection,
wxWindow *parent = NULL);
//@} //@}
@@ -450,6 +497,7 @@ int wxGetSelectedChoices(wxArrayInt& selections,
bool centre = true, bool centre = true,
int width = 150, int width = 150,
int height = 200); int height = 200);
int wxGetSelectedChoices(wxArrayInt& selections, int wxGetSelectedChoices(wxArrayInt& selections,
const wxString& message, const wxString& message,
const wxString& caption, const wxString& caption,

View File

@@ -87,9 +87,13 @@ wxString wxGetSingleChoice( const wxString& message,
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),
int initialSelection)
{ {
wxSingleChoiceDialog dialog(parent, message, caption, n, choices); wxSingleChoiceDialog dialog(parent, message, caption, n, choices);
dialog.SetSelection(initialSelection);
wxString choice; wxString choice;
if ( dialog.ShowModal() == wxID_OK ) if ( dialog.ShowModal() == wxID_OK )
choice = dialog.GetStringSelection(); choice = dialog.GetStringSelection();
@@ -103,26 +107,56 @@ wxString wxGetSingleChoice( const wxString& message,
wxWindow *parent, wxWindow *parent,
int x, int y, int x, int y,
bool centre, bool centre,
int width, int height) int width, int height,
int initialSelection)
{ {
wxString *choices; wxString *choices;
int n = ConvertWXArrayToC(aChoices, &choices); int n = ConvertWXArrayToC(aChoices, &choices);
wxString res = wxGetSingleChoice(message, caption, n, choices, parent, wxString res = wxGetSingleChoice(message, caption, n, choices, parent,
x, y, centre, width, height); x, y, centre, width, height,
initialSelection);
delete [] choices; delete [] choices;
return res; return res;
} }
wxString wxGetSingleChoice( const wxString& message,
const wxString& caption,
const wxArrayString& choices,
int initialSelection,
wxWindow *parent)
{
return wxGetSingleChoice(message, caption, choices, parent,
wxDefaultCoord, wxDefaultCoord,
true, wxCHOICE_WIDTH, wxCHOICE_HEIGHT,
initialSelection);
}
wxString wxGetSingleChoice( const wxString& message,
const wxString& caption,
int n, const wxString *choices,
int initialSelection,
wxWindow *parent)
{
return wxGetSingleChoice(message, caption, n, choices, parent,
wxDefaultCoord, wxDefaultCoord,
true, wxCHOICE_WIDTH, wxCHOICE_HEIGHT,
initialSelection);
}
int wxGetSingleChoiceIndex( const wxString& message, int wxGetSingleChoiceIndex( 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),
int initialSelection)
{ {
wxSingleChoiceDialog dialog(parent, message, caption, n, choices); wxSingleChoiceDialog dialog(parent, message, caption, n, choices);
dialog.SetSelection(initialSelection);
int choice; int choice;
if ( dialog.ShowModal() == wxID_OK ) if ( dialog.ShowModal() == wxID_OK )
choice = dialog.GetSelection(); choice = dialog.GetSelection();
@@ -138,17 +172,45 @@ int wxGetSingleChoiceIndex( const wxString& message,
wxWindow *parent, wxWindow *parent,
int x, int y, int x, int y,
bool centre, bool centre,
int width, int height) int width, int height,
int initialSelection)
{ {
wxString *choices; wxString *choices;
int n = ConvertWXArrayToC(aChoices, &choices); int n = ConvertWXArrayToC(aChoices, &choices);
int res = wxGetSingleChoiceIndex(message, caption, n, choices, parent, int res = wxGetSingleChoiceIndex(message, caption, n, choices, parent,
x, y, centre, width, height); x, y, centre, width, height,
initialSelection);
delete [] choices; delete [] choices;
return res; return res;
} }
int wxGetSingleChoiceIndex( const wxString& message,
const wxString& caption,
const wxArrayString& choices,
int initialSelection,
wxWindow *parent)
{
return wxGetSingleChoiceIndex(message, caption, choices, parent,
wxDefaultCoord, wxDefaultCoord,
true, wxCHOICE_WIDTH, wxCHOICE_HEIGHT,
initialSelection);
}
int wxGetSingleChoiceIndex( const wxString& message,
const wxString& caption,
int n, const wxString *choices,
int initialSelection,
wxWindow *parent)
{
return wxGetSingleChoiceIndex(message, caption, n, choices, parent,
wxDefaultCoord, wxDefaultCoord,
true, wxCHOICE_WIDTH, wxCHOICE_HEIGHT,
initialSelection);
}
void *wxGetSingleChoiceData( const wxString& message, void *wxGetSingleChoiceData( const wxString& message,
const wxString& caption, const wxString& caption,
int n, const wxString *choices, int n, const wxString *choices,
@@ -156,10 +218,14 @@ void *wxGetSingleChoiceData( const wxString& message,
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),
int initialSelection)
{ {
wxSingleChoiceDialog dialog(parent, message, caption, n, choices, wxSingleChoiceDialog dialog(parent, message, caption, n, choices,
(char **)client_data); (char **)client_data);
dialog.SetSelection(initialSelection);
void *data; void *data;
if ( dialog.ShowModal() == wxID_OK ) if ( dialog.ShowModal() == wxID_OK )
data = dialog.GetSelectionClientData(); data = dialog.GetSelectionClientData();
@@ -176,18 +242,49 @@ void *wxGetSingleChoiceData( const wxString& message,
wxWindow *parent, wxWindow *parent,
int x, int y, int x, int y,
bool centre, bool centre,
int width, int height) int width, int height,
int initialSelection)
{ {
wxString *choices; wxString *choices;
int n = ConvertWXArrayToC(aChoices, &choices); int n = ConvertWXArrayToC(aChoices, &choices);
void *res = wxGetSingleChoiceData(message, caption, n, choices, void *res = wxGetSingleChoiceData(message, caption, n, choices,
client_data, parent, client_data, parent,
x, y, centre, width, height); x, y, centre, width, height,
initialSelection);
delete [] choices; delete [] choices;
return res; return res;
} }
void* wxGetSingleChoiceData( const wxString& message,
const wxString& caption,
const wxArrayString& choices,
void **client_data,
int initialSelection,
wxWindow *parent)
{
return wxGetSingleChoiceData(message, caption, choices,
client_data, parent,
wxDefaultCoord, wxDefaultCoord,
true, wxCHOICE_WIDTH, wxCHOICE_HEIGHT,
initialSelection);
}
void* wxGetSingleChoiceData( const wxString& message,
const wxString& caption,
int n, const wxString *choices,
void **client_data,
int initialSelection,
wxWindow *parent)
{
return wxGetSingleChoiceData(message, caption, n, choices,
client_data, parent,
wxDefaultCoord, wxDefaultCoord,
true, wxCHOICE_WIDTH, wxCHOICE_HEIGHT,
initialSelection);
}
int wxGetSelectedChoices(wxArrayInt& selections, int wxGetSelectedChoices(wxArrayInt& selections,
const wxString& message, const wxString& message,
const wxString& caption, const wxString& caption,
@@ -434,6 +531,9 @@ bool wxSingleChoiceDialog::Create( wxWindow *parent,
// Set the selection // Set the selection
void wxSingleChoiceDialog::SetSelection(int sel) void wxSingleChoiceDialog::SetSelection(int sel)
{ {
wxCHECK_RET( sel > 0 && (unsigned)sel < m_listbox->GetCount(),
"Invalid initial selection" );
m_listbox->SetSelection(sel); m_listbox->SetSelection(sel);
m_selection = sel; m_selection = sel;
} }