]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/choicdgg.cpp
Added a test to wxSocket sample (client side socket event test)
[wxWidgets.git] / src / generic / choicdgg.cpp
index 0ff03ba0b005f262e934298343eb518bebb54033..5f82eb8ae093444a367b13cebbb92445cb2f0b5e 100644 (file)
@@ -28,6 +28,7 @@
     #include "wx/listbox.h"
     #include "wx/stattext.h"
     #include "wx/intl.h"
     #include "wx/listbox.h"
     #include "wx/stattext.h"
     #include "wx/intl.h"
+    #include "wx/sizer.h"
 #endif
 
 #if wxUSE_STATLINE
 #endif
 
 #if wxUSE_STATLINE
@@ -100,9 +101,9 @@ wxChar *wxGetSingleChoiceData( const wxString& message, const wxString& caption,
                    int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(centre),
                    int WXUNUSED(width), int WXUNUSED(height) )
 {
                    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 )
     if ( dialog.ShowModal() == wxID_OK )
-        return dialog.GetSelectionClientData();
+        return (wxChar *)dialog.GetSelectionClientData();
     else
         return NULL;
 }
     else
         return NULL;
 }
@@ -164,9 +165,17 @@ END_EVENT_TABLE()
 IMPLEMENT_CLASS(wxSingleChoiceDialog, wxDialog)
 #endif
 
 IMPLEMENT_CLASS(wxSingleChoiceDialog, wxDialog)
 #endif
 
+#if defined(__WXMSW__) || defined(__WXMAC__)
 #define wxCHOICEDLG_DIALOG_STYLE (wxDEFAULT_DIALOG_STYLE | \
                                   wxDIALOG_MODAL |         \
                                   wxTAB_TRAVERSAL)
 #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,
 
 wxSingleChoiceDialog::wxSingleChoiceDialog(wxWindow *parent,
                                            const wxString& message,
@@ -186,7 +195,7 @@ wxSingleChoiceDialog::wxSingleChoiceDialog(wxWindow *parent,
                                            const wxString& message,
                                            const wxString& caption,
                                            const wxStringList& choices,
                                            const wxString& message,
                                            const wxString& caption,
                                            const wxStringList& choices,
-                                           wxChar **clientData,
+                                           char **clientData,
                                            long style,
                                            const wxPoint& pos)
                     : wxDialog(parent, -1, caption, pos, wxDefaultSize,
                                            long style,
                                            const wxPoint& pos)
                     : wxDialog(parent, -1, caption, pos, wxDefaultSize,
@@ -225,118 +234,47 @@ bool wxSingleChoiceDialog::Create( wxWindow *WXUNUSED(parent),
 {
     m_selection = 0;
     m_clientData = NULL;
 {
     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") );
-
-    bool hasCancel = (style & wxCANCEL) != 0;
-
-    wxSize sizeButtons = GetStandardButtonSize(hasCancel);
-
-    long wButton = sizeButtons.GetWidth(),
-         hButton = sizeButtons.GetHeight();
-
-    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 )
+    m_stringSelection = _T("");
+
+    m_dialogStyle = style;
+
+    wxBeginBusyCursor();
+    
+    wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
+
+    // 1) text message
+    topsizer->Add( CreateTextSizer( message ), 0, wxALL, 10 );
+    
+    // 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]);
     }
     {
         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
 #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
 
 #endif
 
-    // buttons
+    // 4) buttons
+    topsizer->Add( CreateButtonSizer( wxOK|wxCANCEL ), 0, wxCENTRE | wxALL, 10 );
 
 
-    y += 2*LAYOUT_X_MARGIN;
+    SetAutoLayout( TRUE );
+    SetSizer( topsizer );
+    
+    topsizer->SetSizeHints( this );
+    topsizer->Fit( this );
 
 
-    CreateStandardButtons(wDialog, y, wButton, hButton, hasCancel);
+    Centre( wxBOTH );
 
 
-    SetClientSize( wDialog, hDialog );
+    m_listbox->SetFocus();
 
 
-    Centre( wxBOTH );
+    wxEndBusyCursor();
 
     return TRUE;
 }
 
     return TRUE;
 }