From 697f4a966e71daf9cc88f44c703fba386ad0b0fd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 21 Mar 2010 11:06:31 +0000 Subject: [PATCH] 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 --- docs/changes.txt | 1 + include/wx/generic/choicdgg.h | 59 +++++++++++++++-- interface/wx/choicdlg.h | 60 +++++++++++++++-- src/generic/choicdgg.cpp | 118 +++++++++++++++++++++++++++++++--- 4 files changed, 216 insertions(+), 22 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 57b498e5bc..c0d0cafc94 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -496,6 +496,7 @@ All (GUI): - Add wxComboBox::Popup() and Dismiss() methods (Igor Korot). - Added wxTreeCtrl::SelectChildren() (Nikolay Tjushkov). - Show pages icons in window list menu in wxAuiNotebook (Ronny Krüger). +- Add "initial selection" parameter to wxGetSingleChoice() (Nikolay Tjushkov). GTK: diff --git a/include/wx/generic/choicdgg.h b/include/wx/generic/choicdgg.h index 505a63b3a5..306c3df287 100644 --- a/include/wx/generic/choicdgg.h +++ b/include/wx/generic/choicdgg.h @@ -235,7 +235,8 @@ WXDLLIMPEXP_CORE wxString wxGetSingleChoice(const wxString& message, int y = wxDefaultCoord, bool centre = true, 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, @@ -245,7 +246,20 @@ WXDLLIMPEXP_CORE wxString wxGetSingleChoice(const wxString& message, int y = wxDefaultCoord, bool centre = true, 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, // or -1 if no selection @@ -257,7 +271,8 @@ WXDLLIMPEXP_CORE int wxGetSingleChoiceIndex(const wxString& message, int y = wxDefaultCoord, bool centre = true, int width = wxCHOICE_WIDTH, - int height = wxCHOICE_HEIGHT); + int height = wxCHOICE_HEIGHT, + int initialSelection = 0); WXDLLIMPEXP_CORE int wxGetSingleChoiceIndex(const wxString& message, const wxString& caption, @@ -267,9 +282,22 @@ WXDLLIMPEXP_CORE int wxGetSingleChoiceIndex(const wxString& message, int y = wxDefaultCoord, bool centre = true, int width = wxCHOICE_WIDTH, - int height = wxCHOICE_HEIGHT); + int height = wxCHOICE_HEIGHT, + int initialSelection = 0); + +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 cancelled +// Return client data instead or NULL if canceled WXDLLIMPEXP_CORE void* wxGetSingleChoiceData(const wxString& message, const wxString& caption, const wxArrayString& choices, @@ -279,7 +307,8 @@ WXDLLIMPEXP_CORE void* wxGetSingleChoiceData(const wxString& message, int y = wxDefaultCoord, bool centre = true, 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, @@ -290,7 +319,23 @@ WXDLLIMPEXP_CORE void* wxGetSingleChoiceData(const wxString& message, int y = wxDefaultCoord, bool centre = true, 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 // if no items were selected or Cancel was pressed - return the number of diff --git a/interface/wx/choicdlg.h b/interface/wx/choicdlg.h index 534564455d..239951e4d9 100644 --- a/interface/wx/choicdlg.h +++ b/interface/wx/choicdlg.h @@ -316,7 +316,9 @@ int wxGetSingleChoiceIndex(const wxString& message, int y = -1, bool centre = true, int width = 150, - int height = 200); + int height = 200, + int initialSelection = 0); + int wxGetSingleChoiceIndex(const wxString& message, const wxString& caption, int n, @@ -326,8 +328,21 @@ int wxGetSingleChoiceIndex(const wxString& message, int y = -1, bool centre = true, 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 */ @@ -361,7 +376,8 @@ wxString wxGetSingleChoice(const wxString& message, int y = -1, bool centre = true, int width = 150, - int height = 200); + int height = 200 + int initialSelection = 0); wxString wxGetSingleChoice(const wxString& message, const wxString& caption, int n, @@ -371,7 +387,21 @@ wxString wxGetSingleChoice(const wxString& message, int y = -1, bool centre = true, 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, bool centre = true, int width = 150, - int height = 200); + int height = 200 + int initialSelection = 0); + wxString wxGetSingleChoiceData(const wxString& message, const wxString& caption, int n, @@ -410,7 +442,22 @@ wxString wxGetSingleChoiceData(const wxString& message, int y = -1, bool centre = true, 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, int width = 150, int height = 200); + int wxGetSelectedChoices(wxArrayInt& selections, const wxString& message, const wxString& caption, diff --git a/src/generic/choicdgg.cpp b/src/generic/choicdgg.cpp index 3a97b383fc..073e669417 100644 --- a/src/generic/choicdgg.cpp +++ b/src/generic/choicdgg.cpp @@ -87,9 +87,13 @@ wxString wxGetSingleChoice( const wxString& message, wxWindow *parent, int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(centre), - int WXUNUSED(width), int WXUNUSED(height) ) + int WXUNUSED(width), int WXUNUSED(height), + int initialSelection) { wxSingleChoiceDialog dialog(parent, message, caption, n, choices); + + dialog.SetSelection(initialSelection); + wxString choice; if ( dialog.ShowModal() == wxID_OK ) choice = dialog.GetStringSelection(); @@ -103,26 +107,56 @@ wxString wxGetSingleChoice( const wxString& message, wxWindow *parent, int x, int y, bool centre, - int width, int height) + int width, int height, + int initialSelection) { wxString *choices; int n = ConvertWXArrayToC(aChoices, &choices); wxString res = wxGetSingleChoice(message, caption, n, choices, parent, - x, y, centre, width, height); + x, y, centre, width, height, + initialSelection); delete [] choices; 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, const wxString& caption, int n, const wxString *choices, wxWindow *parent, int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(centre), - int WXUNUSED(width), int WXUNUSED(height) ) + int WXUNUSED(width), int WXUNUSED(height), + int initialSelection) { wxSingleChoiceDialog dialog(parent, message, caption, n, choices); + + dialog.SetSelection(initialSelection); + int choice; if ( dialog.ShowModal() == wxID_OK ) choice = dialog.GetSelection(); @@ -138,17 +172,45 @@ int wxGetSingleChoiceIndex( const wxString& message, wxWindow *parent, int x, int y, bool centre, - int width, int height) + int width, int height, + int initialSelection) { wxString *choices; int n = ConvertWXArrayToC(aChoices, &choices); int res = wxGetSingleChoiceIndex(message, caption, n, choices, parent, - x, y, centre, width, height); + x, y, centre, width, height, + initialSelection); delete [] choices; 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, const wxString& caption, int n, const wxString *choices, @@ -156,10 +218,14 @@ void *wxGetSingleChoiceData( const wxString& message, wxWindow *parent, int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(centre), - int WXUNUSED(width), int WXUNUSED(height) ) + int WXUNUSED(width), int WXUNUSED(height), + int initialSelection) { wxSingleChoiceDialog dialog(parent, message, caption, n, choices, (char **)client_data); + + dialog.SetSelection(initialSelection); + void *data; if ( dialog.ShowModal() == wxID_OK ) data = dialog.GetSelectionClientData(); @@ -176,18 +242,49 @@ void *wxGetSingleChoiceData( const wxString& message, wxWindow *parent, int x, int y, bool centre, - int width, int height) + int width, int height, + int initialSelection) { wxString *choices; int n = ConvertWXArrayToC(aChoices, &choices); void *res = wxGetSingleChoiceData(message, caption, n, choices, client_data, parent, - x, y, centre, width, height); + x, y, centre, width, height, + initialSelection); delete [] choices; 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, const wxString& message, const wxString& caption, @@ -434,6 +531,9 @@ bool wxSingleChoiceDialog::Create( wxWindow *parent, // Set the selection void wxSingleChoiceDialog::SetSelection(int sel) { + wxCHECK_RET( sel > 0 && (unsigned)sel < m_listbox->GetCount(), + "Invalid initial selection" ); + m_listbox->SetSelection(sel); m_selection = sel; } -- 2.45.2