]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/choicdgg.cpp
dbgrid.cpp dbtree.cpp
[wxWidgets.git] / src / generic / choicdgg.cpp
index 0ff03ba0b005f262e934298343eb518bebb54033..ec8857fa4dcca430e8f1a03f73805f8a655f25d8 100644 (file)
@@ -28,6 +28,7 @@
     #include "wx/listbox.h"
     #include "wx/stattext.h"
     #include "wx/intl.h"
+    #include "wx/sizer.h"
 #endif
 
 #if wxUSE_STATLINE
@@ -47,7 +48,7 @@ wxString wxGetSingleChoice( const wxString& message, const wxString& caption, in
     if ( dialog.ShowModal() == wxID_OK )
         return dialog.GetStringSelection();
     else
-        return _T("");
+        return wxT("");
 }
 
 // Overloaded for backward compatibility
@@ -95,12 +96,12 @@ int wxGetSingleChoiceIndex( const wxString& message, const wxString& caption, in
     return ans;
 }
 
-wxChar *wxGetSingleChoiceData( const wxString& message, const wxString& caption, int n,
-                   const wxString *choices, wxChar **client_data, wxWindow *parent,
+void *wxGetSingleChoiceData( const wxString& message, const wxString& caption, int n,
+                   const wxString *choices, void **client_data, wxWindow *parent,
                    int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(centre),
                    int WXUNUSED(width), int WXUNUSED(height) )
 {
-    wxSingleChoiceDialog dialog(parent, message, caption, n, choices, client_data);
+    wxSingleChoiceDialog dialog(parent, message, caption, n, choices, (char **)client_data);
     if ( dialog.ShowModal() == wxID_OK )
         return dialog.GetSelectionClientData();
     else
@@ -108,8 +109,8 @@ wxChar *wxGetSingleChoiceData( const wxString& message, const wxString& caption,
 }
 
 // Overloaded for backward compatibility
-wxChar *wxGetSingleChoiceData( const wxString& message, const wxString& caption, int n,
-                   wxChar *choices[], wxChar **client_data, wxWindow *parent,
+void *wxGetSingleChoiceData( const wxString& message, const wxString& caption, int n,
+                   wxChar *choices[], void **client_data, wxWindow *parent,
                    int x, int y, bool centre,
                    int width, int height )
 {
@@ -119,7 +120,7 @@ wxChar *wxGetSingleChoiceData( const wxString& message, const wxString& caption,
     {
         strings[i] = choices[i];
     }
-    wxChar *data = wxGetSingleChoiceData(message, caption, n, (const wxString *)strings, client_data, parent,
+    void *data = wxGetSingleChoiceData(message, caption, n, (const wxString *)strings, client_data, parent,
         x, y, centre, width, height);
     delete[] strings;
     return data;
@@ -155,18 +156,24 @@ int wxGetMultipleChoice(const wxString& message, const wxString& caption,
 
 // wxSingleChoiceDialog
 
-#if !USE_SHARED_LIBRARY
 BEGIN_EVENT_TABLE(wxSingleChoiceDialog, wxDialog)
     EVT_BUTTON(wxID_OK, wxSingleChoiceDialog::OnOK)
     EVT_LISTBOX_DCLICK(wxID_LISTBOX, wxSingleChoiceDialog::OnListBoxDClick)
 END_EVENT_TABLE()
 
 IMPLEMENT_CLASS(wxSingleChoiceDialog, wxDialog)
-#endif
 
+#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
+
 
 wxSingleChoiceDialog::wxSingleChoiceDialog(wxWindow *parent,
                                            const wxString& message,
@@ -186,7 +193,7 @@ wxSingleChoiceDialog::wxSingleChoiceDialog(wxWindow *parent,
                                            const wxString& message,
                                            const wxString& caption,
                                            const wxStringList& choices,
-                                           wxChar **clientData,
+                                           char **clientData,
                                            long style,
                                            const wxPoint& pos)
                     : wxDialog(parent, -1, caption, pos, wxDefaultSize,
@@ -224,120 +231,47 @@ bool wxSingleChoiceDialog::Create( wxWindow *WXUNUSED(parent),
                                    const wxPoint& WXUNUSED(pos) )
 {
     m_selection = 0;
-    m_clientData = NULL;
-
-    // calc the message size
-    // ---------------------
-
-    wxArrayString lines;
-    wxSize sizeText = SplitTextMessage(message, &lines);
-    long heightTextMax = sizeText.GetHeight(),
-         widthTextMax = sizeText.GetWidth();
-    size_t nLineCount = lines.Count();
-    long hTotalMsg = heightTextMax*nLineCount;
-
-    // calc the button size
-    // --------------------
 
-    // always create the OK button - the code below supposes we do have buttons
-    // and besides the user should have some way to close this dialog
-    wxASSERT_MSG( style & wxOK, _T("this dialog should have OK button") );
+    m_dialogStyle = style;
 
-    bool hasCancel = (style & wxCANCEL) != 0;
+    wxBeginBusyCursor();
 
-    wxSize sizeButtons = GetStandardButtonSize(hasCancel);
+    wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
 
-    long wButton = sizeButtons.GetWidth(),
-         hButton = sizeButtons.GetHeight();
+    // 1) text message
+    topsizer->Add( CreateTextSizer( message ), 0, wxALL, 10 );
 
-    long wTotalButtons = wButton;
-    if ( hasCancel )
-    {
-        wTotalButtons *= 2;                         // second button
-        wTotalButtons += MARGIN_BETWEEN_BUTTONS;    // margin between the 2
-    }
-
-    // listbox and stat line
-    // ---------------------
-
-    // make the listbox at least as tall as the message - otherwise it looks
-    // ugly (the lower limit of 300 for the width is arbitrary OTOH)
-    //
-    // NB: we write "n + 2" because the horiz. scrollbar also takes some place
-    long hListbox = wxMax((n + 2) * heightTextMax, hTotalMsg),
-         wListbox = wxMax(300, wxMax(wTotalButtons, widthTextMax));
-
-#if wxUSE_STATLINE
-    long hStatLine = wxStaticLine::GetDefaultSize();
-#endif
-
-    // now the complete dialog size
-    // ----------------------------
-
-    long hDialog = 2*LAYOUT_Y_MARGIN +  // top margin
-                   hTotalMsg +          // message
-                   2*LAYOUT_Y_MARGIN +  // margin between text and listbox
-                   hListbox +           // listbox
-#if wxUSE_STATLINE
-                   LAYOUT_Y_MARGIN +    // margin
-                   hStatLine +          // separator line
-#endif
-                   2*LAYOUT_Y_MARGIN +  // margin between listbox and buttons
-                   hButton +            // button(s)
-                   LAYOUT_Y_MARGIN;     // bottom margin
-
-    long wDialog = wxMax(wListbox, wxMax(wTotalButtons, widthTextMax)) +
-                   4*LAYOUT_X_MARGIN;   // 2 from each side
-
-    // create the controls
-    // -------------------
-
-    // message
-    wxStaticText *text;
-    int y = 2*LAYOUT_Y_MARGIN;
-    for ( size_t nLine = 0; nLine < nLineCount; nLine++ )
-    {
-        text = new wxStaticText(this, -1, lines[nLine],
-                                wxPoint(2*LAYOUT_X_MARGIN, y),
-                                wxSize(widthTextMax, heightTextMax));
-        y += heightTextMax;
-    }
-
-    y += 2*LAYOUT_X_MARGIN;
-
-    // listbox
-    m_listbox = new wxListBox( this, wxID_LISTBOX,
-                               wxPoint(2*LAYOUT_X_MARGIN, y),
-                               wxSize(wListbox, hListbox),
-                               n, choices,
-                               wxLB_HSCROLL);
-    y += hListbox;
-
-    if ( clientData )
+    // 2) list box
+    m_listbox = new wxListBox( this, wxID_LISTBOX, wxDefaultPosition, wxSize(160,100) ,
+                                        n, choices, wxLB_ALWAYS_SB );
+    m_listbox->SetSelection( m_selection );
+    if (clientData)
     {
         for (int i = 0; i < n; i++)
             m_listbox->SetClientData(i, clientData[i]);
     }
+    topsizer->Add( m_listbox, 1, wxEXPAND | wxLEFT|wxRIGHT, 15 );
 
-    // separator line
 #if wxUSE_STATLINE
-    (void) new wxStaticLine( this, -1,
-                             wxPoint(2*LAYOUT_X_MARGIN, y + LAYOUT_Y_MARGIN),
-                             wxSize(wDialog - 4*LAYOUT_X_MARGIN, hStatLine) );
-
-    y += LAYOUT_Y_MARGIN + hStatLine;
+    // 3) static line
+    topsizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 );
 #endif
 
-    // buttons
-
-    y += 2*LAYOUT_X_MARGIN;
+    // 4) buttons
+    topsizer->Add( CreateButtonSizer( wxOK|wxCANCEL ), 0, wxCENTRE | wxALL, 10 );
 
-    CreateStandardButtons(wDialog, y, wButton, hButton, hasCancel);
+    SetAutoLayout( TRUE );
+    SetSizer( topsizer );
 
-    SetClientSize( wDialog, hDialog );
+    topsizer->SetSizeHints( this );
+    topsizer->Fit( this );
 
     Centre( wxBOTH );
 
+    m_listbox->SetFocus();
+
+    wxEndBusyCursor();
+
     return TRUE;
 }
 
@@ -352,8 +286,11 @@ void wxSingleChoiceDialog::OnOK(wxCommandEvent& WXUNUSED(event))
 {
     m_selection = m_listbox->GetSelection();
     m_stringSelection = m_listbox->GetStringSelection();
-    m_clientData = m_listbox->GetClientData(m_selection);
-
+    // TODO!
+#ifndef __WXMOTIF__
+    if ( m_listbox->HasClientUntypedData() )
+        SetClientData(m_listbox->GetClientData(m_selection));
+#endif
     EndModal(wxID_OK);
 }
 
@@ -361,7 +298,12 @@ void wxSingleChoiceDialog::OnListBoxDClick(wxCommandEvent& WXUNUSED(event))
 {
     m_selection = m_listbox->GetSelection();
     m_stringSelection = m_listbox->GetStringSelection();
-    m_clientData = m_listbox->GetClientData(m_selection);
+
+    // TODO!
+#ifndef __WXMOTIF__
+    if ( m_listbox->HasClientUntypedData() )
+        SetClientData(m_listbox->GetClientData(m_selection));
+#endif
 
     EndModal(wxID_OK);
 }