X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b91b22004d7095481b4fd8a15e21b44527604245..cd212ee42521a28c8947cf287940121cde7cde8f:/src/generic/choicdgg.cpp diff --git a/src/generic/choicdgg.cpp b/src/generic/choicdgg.cpp index 017151f363..f2c529666a 100644 --- a/src/generic/choicdgg.cpp +++ b/src/generic/choicdgg.cpp @@ -28,6 +28,7 @@ #include "wx/listbox.h" #include "wx/stattext.h" #include "wx/intl.h" + #include "wx/sizer.h" #endif #if wxUSE_STATLINE @@ -44,10 +45,11 @@ wxString wxGetSingleChoice( const wxString& message, const wxString& caption, in int WXUNUSED(width), int WXUNUSED(height) ) { wxSingleChoiceDialog dialog(parent, message, caption, n, choices); + wxString choice; if ( dialog.ShowModal() == wxID_OK ) - return dialog.GetStringSelection(); - else - return _T(""); + choice = dialog.GetStringSelection(); + + return choice; } // Overloaded for backward compatibility @@ -74,10 +76,13 @@ int wxGetSingleChoiceIndex( const wxString& message, const wxString& caption, in int WXUNUSED(width), int WXUNUSED(height) ) { wxSingleChoiceDialog dialog(parent, message, caption, n, choices); + int choice; if ( dialog.ShowModal() == wxID_OK ) - return dialog.GetSelection(); + choice = dialog.GetSelection(); else - return -1; + choice = -1; + + return choice; } // Overloaded for backward compatibility @@ -95,21 +100,24 @@ 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, (char **)client_data); + void *data; if ( dialog.ShowModal() == wxID_OK ) - return (wxChar *)dialog.GetSelectionClientData(); + data = dialog.GetSelectionClientData(); else - return NULL; + data = NULL; + + return data; } // 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 +127,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 +163,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, @@ -224,120 +238,47 @@ bool wxSingleChoiceDialog::Create( wxWindow *WXUNUSED(parent), const wxPoint& WXUNUSED(pos) ) { m_selection = 0; - m_clientData = NULL; - // calc the message size - // --------------------- + m_dialogStyle = style; - wxArrayString lines; - wxSize sizeText = SplitTextMessage(message, &lines); - long heightTextMax = sizeText.GetHeight(), - widthTextMax = sizeText.GetWidth(); - size_t nLineCount = lines.Count(); - long hTotalMsg = heightTextMax*nLineCount; + wxBeginBusyCursor(); - // calc the button size - // -------------------- + wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL ); - // 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") ); + // 1) text message + topsizer->Add( CreateTextSizer( message ), 0, wxALL, 10 ); - 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 ) + // 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 + // 4) buttons + topsizer->Add( CreateButtonSizer( wxOK|wxCANCEL ), 0, wxCENTRE | wxALL, 10 ); - y += 2*LAYOUT_X_MARGIN; + SetAutoLayout( TRUE ); + SetSizer( topsizer ); - CreateStandardButtons(wDialog, y, wButton, hButton, hasCancel); - - SetClientSize( wDialog, hDialog ); + topsizer->SetSizeHints( this ); + topsizer->Fit( this ); Centre( wxBOTH ); + m_listbox->SetFocus(); + + wxEndBusyCursor(); + return TRUE; } @@ -352,8 +293,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 +305,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); }