]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/choicdgg.cpp
define WX_XTI_TEMPLATE_FIX in case it is not yet
[wxWidgets.git] / src / generic / choicdgg.cpp
index b99fe2057f6ef1cbe3b26d3800b2e3755ff507c5..695b283eefbb26ecf45a0f7932338dd9e9f753c1 100644 (file)
@@ -6,7 +6,7 @@
 // Created:     04/01/98
 // RCS-ID:      $Id$
 // Copyright:   (c) wxWindows team
-// Licence:     wxWindows license
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // ============================================================================
@@ -28,6 +28,8 @@
     #pragma hdrstop
 #endif
 
+#if wxUSE_CHOICEDLG
+
 #ifndef WX_PRECOMP
     #include <stdio.h>
     #include "wx/utils.h"
@@ -37,6 +39,7 @@
     #include "wx/stattext.h"
     #include "wx/intl.h"
     #include "wx/sizer.h"
+    #include "wx/arrstr.h"
 #endif
 
 #if wxUSE_STATLINE
 
 #define wxID_LISTBOX 3000
 
-#if defined(__WXMSW__) || defined(__WXMAC__)
-#define wxCHOICEDLG_DIALOG_STYLE (wxDEFAULT_DIALOG_STYLE | \
-                                  wxDIALOG_MODAL |         \
-                                  wxTAB_TRAVERSAL)
-#else
-#define wxCHOICEDLG_DIALOG_STYLE (wxDEFAULT_DIALOG_STYLE | \
-                                  wxDIALOG_MODAL |         \
-                                  wxRESIZE_BORDER |        \
-                                  wxTAB_TRAVERSAL)
-#endif
-
 // ----------------------------------------------------------------------------
 // private functions
 // ----------------------------------------------------------------------------
@@ -81,9 +73,10 @@ int ConvertWXArrayToC(const wxArrayString& aChoices, wxString **choices)
 {
     int n = aChoices.GetCount();
     *choices = new wxString[n];
+
     for ( int i = 0; i < n; i++ )
     {
-        *choices[i] = aChoices[i];
+        (*choices)[i] = aChoices[i];
     }
 
     return n;
@@ -126,11 +119,11 @@ wxString wxGetSingleChoice( const wxString& message,
     return res;
 }
 
-#ifdef WXWIN_COMPATIBILITY_2
+#if WXWIN_COMPATIBILITY_2
 // Overloaded for backward compatibility
 wxString wxGetSingleChoice( const wxString& message,
                             const wxString& caption,
-                            int n, char *choices[],
+                            int n, wxChar *choices[],
                             wxWindow *parent,
                             int x, int y, bool centre,
                             int width, int height )
@@ -166,7 +159,24 @@ int wxGetSingleChoiceIndex( const wxString& message,
     return choice;
 }
 
-#ifdef WXWIN_COMPATIBILITY_2
+int wxGetSingleChoiceIndex( 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 = wxGetSingleChoiceIndex(message, caption, n, choices, parent,
+                                     x, y, centre, width, height);
+    delete [] choices;
+
+    return res;
+}
+
+#if WXWIN_COMPATIBILITY_2
 // Overloaded for backward compatibility
 int wxGetSingleChoiceIndex( const wxString& message,
                             const wxString& caption,
@@ -194,7 +204,8 @@ void *wxGetSingleChoiceData( const wxString& message,
                              bool WXUNUSED(centre),
                              int WXUNUSED(width), int WXUNUSED(height) )
 {
-    wxSingleChoiceDialog dialog(parent, message, caption, n, choices, (char **)client_data);
+    wxSingleChoiceDialog dialog(parent, message, caption, n, choices,
+                                (char **)client_data);
     void *data;
     if ( dialog.ShowModal() == wxID_OK )
         data = dialog.GetSelectionClientData();
@@ -204,7 +215,26 @@ void *wxGetSingleChoiceData( const wxString& message,
     return data;
 }
 
-#ifdef WXWIN_COMPATIBILITY_2
+void *wxGetSingleChoiceData( const wxString& message,
+                             const wxString& caption,
+                             const wxArrayString& aChoices,
+                             void **client_data,
+                             wxWindow *parent,
+                             int x, int y,
+                             bool centre,
+                             int width, int height)
+{
+    wxString *choices;
+    int n = ConvertWXArrayToC(aChoices, &choices);
+    void *res = wxGetSingleChoiceData(message, caption, n, choices,
+                                      client_data, parent,
+                                      x, y, centre, width, height);
+    delete [] choices;
+
+    return res;
+}
+
+#if WXWIN_COMPATIBILITY_2
 // Overloaded for backward compatibility
 void *wxGetSingleChoiceData( const wxString& message,
                              const wxString& caption,
@@ -238,6 +268,10 @@ size_t wxGetMultipleChoices(wxArrayInt& selections,
                             int WXUNUSED(width), int WXUNUSED(height))
 {
     wxMultiChoiceDialog dialog(parent, message, caption, n, choices);
+
+    if ( !selections.IsEmpty() )
+        dialog.SetSelections(selections);
+
     if ( dialog.ShowModal() == wxID_OK )
         selections = dialog.GetSelections();
     else
@@ -246,7 +280,7 @@ size_t wxGetMultipleChoices(wxArrayInt& selections,
     return selections.GetCount();
 }
 
-size_t wxGetMultipleChoices(wxArrayInt selections,
+size_t wxGetMultipleChoices(wxArrayInt& selections,
                             const wxString& message,
                             const wxString& caption,
                             const wxArrayString& aChoices,
@@ -277,8 +311,7 @@ bool wxAnyChoiceDialog::Create(wxWindow *parent,
                                const wxPoint& pos,
                                long styleLbox)
 {
-    if ( !wxDialog::Create(parent, -1, caption, pos, wxDefaultSize,
-                           wxCHOICEDLG_DIALOG_STYLE) )
+    if ( !wxDialog::Create(parent, -1, caption, pos, wxDefaultSize, styleDlg) )
         return FALSE;
 
     wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
@@ -302,7 +335,7 @@ bool wxAnyChoiceDialog::Create(wxWindow *parent,
 #endif
 
     // 4) buttons
-    topsizer->Add( CreateButtonSizer( wxOK|wxCANCEL ), 0, wxCENTRE | wxALL, 10 );
+    topsizer->Add( CreateButtonSizer( styleDlg & (wxOK|wxCANCEL) ), 0, wxCENTRE | wxALL, 10 );
 
     SetAutoLayout( TRUE );
     SetSizer( topsizer );
@@ -335,12 +368,12 @@ wxSingleChoiceDialog::wxSingleChoiceDialog(wxWindow *parent,
                                            const wxString *choices,
                                            char **clientData,
                                            long style,
-                                           const wxPoint& pos)
+                                           const wxPoint& WXUNUSED(pos))
 {
     Create(parent, message, caption, n, choices, clientData, style);
 }
 
-#ifdef WXWIN_COMPATIBILITY_2
+#if WXWIN_COMPATIBILITY_2
 
 wxSingleChoiceDialog::wxSingleChoiceDialog(wxWindow *parent,
                                            const wxString& message,
@@ -348,7 +381,7 @@ wxSingleChoiceDialog::wxSingleChoiceDialog(wxWindow *parent,
                                            const wxStringList& choices,
                                            char **clientData,
                                            long style,
-                                           const wxPoint& pos)
+                                           const wxPoint& WXUNUSED(pos))
 {
     Create(parent, message, caption, choices, clientData, style);
 }
@@ -410,11 +443,8 @@ void wxSingleChoiceDialog::OnOK(wxCommandEvent& WXUNUSED(event))
 {
     m_selection = m_listbox->GetSelection();
     m_stringSelection = m_listbox->GetStringSelection();
-    // TODO!
-#ifndef __WXMOTIF__
     if ( m_listbox->HasClientUntypedData() )
         SetClientData(m_listbox->GetClientData(m_selection));
-#endif
     EndModal(wxID_OK);
 }
 
@@ -423,11 +453,8 @@ void wxSingleChoiceDialog::OnListBoxDClick(wxCommandEvent& WXUNUSED(event))
     m_selection = m_listbox->GetSelection();
     m_stringSelection = m_listbox->GetStringSelection();
 
-    // TODO!
-#ifndef __WXMOTIF__
     if ( m_listbox->HasClientUntypedData() )
         SetClientData(m_listbox->GetClientData(m_selection));
-#endif
 
     EndModal(wxID_OK);
 }
@@ -476,3 +503,5 @@ bool wxMultiChoiceDialog::TransferDataFromWindow()
 
     return TRUE;
 }
+
+#endif // wxUSE_CHOICEDLG