]> git.saurik.com Git - wxWidgets.git/commitdiff
replace wxGetMultipleChoices() with wxGetSelectedChoices() which allows to distinguis...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 7 Mar 2009 15:39:09 +0000 (15:39 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 7 Mar 2009 15:39:09 +0000 (15:39 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59417 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/generic/choicdgg.h
interface/wx/choicdlg.h
samples/dialogs/dialogs.cpp
src/generic/choicdgg.cpp

index 41c2e662889fe32ecdbd77c39af36d02b5b5e145..d0ef4c1da98bd23856607657f33acb4b82623cc8 100644 (file)
@@ -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.
   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
 ----------------------------------
 
 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.
 - 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:
 
 
 wxGTK:
 
index 97b9a8949b9ccdc7d0b9d46a63b458b7d6acab4a..505a63b3a57ef3dbbf842939742782e95fb24a5f 100644 (file)
@@ -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
 
 // 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,
                                         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);
 
                                         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,
                                         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);
 
                                         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_
 #endif // _WX_GENERIC_CHOICDGG_H_
index bd2238a33b7831d2cdb210d4044840d28c138c45..118f09048f6901d969adda6ea293daad73c5acfd 100644 (file)
@@ -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
     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
 
     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}
 */
 
     @header{wx/choicdlg.h}
 */
-size_t wxGetMultipleChoices(wxArrayInt& selections,
+int wxGetSelectedChoices(wxArrayInt& selections,
                             const wxString& message,
                             const wxString& caption,
                             const wxArrayString& aChoices,
                             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);
                             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,
                             const wxString& message,
                             const wxString& caption,
                             int n,
index 59197b76427b24fac1cac703bb74e593e3afec58..ceed79323d8f4dea7ee642e5b6449f14f355ce50 100644 (file)
@@ -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("A multi-choice convenience dialog"),
                                         _T("Please select a value"),
                                         WXSIZEOF(choices), choices,
                                         this);
                                         _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;
     {
         wxString msg;
-        msg.Printf(wxT("You selected %u items:\n"), (unsigned)count);
-        for ( size_t n = 0; n < count; n++ )
+        if ( count == 0 )
+        {
+            msg = wxT("You did not select any items");
+        }
+        else
         {
         {
-            msg += wxString::Format(wxT("\t%u: %u (%s)\n"),
-                                    (unsigned)n, (unsigned)selections[n],
-                                    choices[selections[n]].c_str());
+            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);
     }
         }
         wxLogMessage(msg);
     }
-    //else: cancelled or nothing selected
+    //else: cancelled
 }
 #endif // wxUSE_CHOICEDLG
 
 }
 #endif // wxUSE_CHOICEDLG
 
index fa3c19415bd479884041a577aa1afad3f2e54114..fb4eb2677da610b2d863848a5829f7c5aa74b1d7 100644 (file)
@@ -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& caption,
                             int n, const wxString *choices,
                             const wxString& message,
                             const wxString& caption,
                             int n, const wxString *choices,
@@ -203,15 +203,19 @@ size_t wxGetMultipleChoices(wxArrayInt& selections,
     // deselects the first item which is selected by default
     dialog.SetSelections(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();
 }
 
     return selections.GetCount();
 }
 
-size_t wxGetMultipleChoices(wxArrayInt& selections,
+int wxGetSelectedChoices(wxArrayInt& selections,
                             const wxString& message,
                             const wxString& caption,
                             const wxArrayString& aChoices,
                             const wxString& message,
                             const wxString& caption,
                             const wxArrayString& aChoices,
@@ -222,7 +226,7 @@ size_t wxGetMultipleChoices(wxArrayInt& selections,
 {
     wxString *choices;
     int n = ConvertWXArrayToC(aChoices, &choices);
 {
     wxString *choices;
     int n = ConvertWXArrayToC(aChoices, &choices);
-    size_t res = wxGetMultipleChoices(selections, message, caption,
+    int res = wxGetSelectedChoices(selections, message, caption,
                                       n, choices, parent,
                                       x, y, centre, width, height);
     delete [] choices;
                                       n, choices, parent,
                                       x, y, centre, width, height);
     delete [] choices;
@@ -230,6 +234,50 @@ size_t wxGetMultipleChoices(wxArrayInt& selections,
     return res;
 }
 
     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,
+                            const wxArrayString& aChoices,
+                            wxWindow *parent,
+                            int x, int y,
+                            bool centre,
+                            int width, int height)
+{
+    int rc = wxGetSelectedChoices(selections, message, caption,
+                                  aChoices,
+                                  parent, x, y, centre, width, height);
+    if ( rc == -1 )
+    {
+        selections.clear();
+        return 0;
+    }
+
+    return rc;
+}
+#endif // WXWIN_COMPATIBILITY_2_8
+
 // ----------------------------------------------------------------------------
 // wxAnyChoiceDialog
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // wxAnyChoiceDialog
 // ----------------------------------------------------------------------------