]> git.saurik.com Git - wxWidgets.git/commitdiff
Add initial selection parameter to wxGetSingleChoice() functions.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 21 Mar 2010 11:06:31 +0000 (11:06 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 21 Mar 2010 11:06:31 +0000 (11:06 +0000)
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
include/wx/generic/choicdgg.h
interface/wx/choicdlg.h
src/generic/choicdgg.cpp

index 57b498e5bc91aaa5f277dac7e596009f5f20f54c..c0d0cafc94a4930cac59e7153b32826762d54f76 100644 (file)
@@ -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:
 
index 505a63b3a57ef3dbbf842939742782e95fb24a5f..306c3df287f8261a4eecda3b891dc2257f214efa 100644 (file)
@@ -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
index 534564455d75455b9380ab3ade7f6b2f3a5ab479..239951e4d9b775b4a11bf5dfb99d4c4524a33061 100644 (file)
@@ -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,
index 3a97b383fc11aa813a55ff13df6a051b39f29b69..073e669417ee38d1cf061aabb2706212489c56d2 100644 (file)
@@ -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;
 }