X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c801d85f158c4cba50b588807daabdcbd0ed3853..520e470fdd0daef09c77938db642e4583933c90d:/src/generic/choicdgg.cpp diff --git a/src/generic/choicdgg.cpp b/src/generic/choicdgg.cpp index e6997e0511..c045765534 100644 --- a/src/generic/choicdgg.cpp +++ b/src/generic/choicdgg.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: choicesg.cpp +// Name: choicdgg.cpp // Purpose: Choice dialogs // Author: Julian Smart // Modified by: @@ -33,12 +33,43 @@ #include "wx/generic/choicdgg.h" -extern void wxSplitMessage2(const char *message, wxList *messageList, wxWindow *parent, wxRowColSizer *sizer); +// Split message, using constraints to position controls +static void wxSplitMessage2(const char *message, wxList *messageList, wxWindow *parent, wxRowColSizer *sizer) +{ + char *copyMessage = copystring(message); + size_t i = 0; + size_t len = strlen(copyMessage); + char *currentMessage = copyMessage; + +// wxWindow *lastWindow = parent; + + while (i < len) { + while ((i < len) && (copyMessage[i] != '\n')) i++; + if (i < len) copyMessage[i] = 0; + wxStaticText *mess = new wxStaticText(parent, -1, currentMessage); + +/* + wxLayoutConstraints *c = new wxLayoutConstraints; + c->left.SameAs (parent, wxLeft, 10); + c->top.SameAs (lastWindow, wxBottom, 5); + c->right.AsIs (); + c->height.AsIs (); + + mess->SetConstraints(c); +*/ + sizer->AddSizerChild(mess); -wxString wxGetSingleChoice( const wxString& message, const wxString& caption, const int n, - const wxString *choices, wxWindow *parent, - const int WXUNUSED(x), const int WXUNUSED(y), const bool WXUNUSED(centre), - const int WXUNUSED(width), const int WXUNUSED(height) ) + messageList->Append(mess); + + currentMessage = copyMessage + i + 1; + } + delete[] copyMessage; +} + +wxString wxGetSingleChoice( const wxString& message, const wxString& caption, int n, + const wxString *choices, wxWindow *parent, + int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(centre), + int WXUNUSED(width), int WXUNUSED(height) ) { wxSingleChoiceDialog dialog(parent, message, caption, n, choices); if ( dialog.ShowModal() == wxID_OK ) @@ -50,10 +81,10 @@ wxString wxGetSingleChoice( const wxString& message, const wxString& caption, co } // Overloaded for backward compatibility -wxString wxGetSingleChoice( const wxString& message, const wxString& caption, const int n, - char *choices[], wxWindow *parent, - const int x, const int y, const bool centre, - const int width, const int height ) +wxString wxGetSingleChoice( const wxString& message, const wxString& caption, int n, + char *choices[], wxWindow *parent, + int x, int y, bool centre, + int width, int height ) { wxString *strings = new wxString[n]; int i; @@ -67,10 +98,10 @@ wxString wxGetSingleChoice( const wxString& message, const wxString& caption, co return ans; } -int wxGetSingleChoiceIndex( const wxString& message, const wxString& caption, const int n, - const wxString *choices, wxWindow *parent, - const int WXUNUSED(x), const int WXUNUSED(y), const bool WXUNUSED(centre), - const int WXUNUSED(width), const int WXUNUSED(height) ) +int wxGetSingleChoiceIndex( const wxString& message, const wxString& caption, int n, + const wxString *choices, wxWindow *parent, + int WXUNUSED(x), int WXUNUSED(y), bool WXUNUSED(centre), + int WXUNUSED(width), int WXUNUSED(height) ) { wxSingleChoiceDialog dialog(parent, message, caption, n, choices); if ( dialog.ShowModal() == wxID_OK ) @@ -82,10 +113,10 @@ int wxGetSingleChoiceIndex( const wxString& message, const wxString& caption, co } // Overloaded for backward compatibility -int wxGetSingleChoiceIndex( const wxString& message, const wxString& caption, const int n, - char *choices[], wxWindow *parent, - const int x, const int y, const bool centre, - const int width, const int height ) +int wxGetSingleChoiceIndex( const wxString& message, const wxString& caption, int n, + char *choices[], wxWindow *parent, + int x, int y, bool centre, + int width, int height ) { wxString *strings = new wxString[n]; int i; @@ -99,10 +130,10 @@ int wxGetSingleChoiceIndex( const wxString& message, const wxString& caption, co return ans; } -char *wxGetSingleChoiceData( const wxString& message, const wxString& caption, const int n, - const wxString *choices, char **client_data, wxWindow *parent, - const int WXUNUSED(x), const int WXUNUSED(y), const bool WXUNUSED(centre), - const int WXUNUSED(width), const int WXUNUSED(height) ) +char *wxGetSingleChoiceData( const wxString& message, const wxString& caption, int n, + const wxString *choices, char **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); if ( dialog.ShowModal() == wxID_OK ) @@ -114,10 +145,10 @@ char *wxGetSingleChoiceData( const wxString& message, const wxString& caption, c } // Overloaded for backward compatibility -char *wxGetSingleChoiceData( const wxString& message, const wxString& caption, const int n, - char *choices[], char **client_data, wxWindow *parent, - const int x, const int y, const bool centre, - const int width, const int height ) +char *wxGetSingleChoiceData( const wxString& message, const wxString& caption, int n, + char *choices[], char **client_data, wxWindow *parent, + int x, int y, bool centre, + int width, int height ) { wxString *strings = new wxString[n]; int i; @@ -150,10 +181,10 @@ selected. */ /* int wxGetMultipleChoice(const wxString& message, const wxString& caption, - const int n, const wxString *choices, - const int nsel, int * selection, - wxWindow *parent , const int x , const int y, const bool centre, - const int width, const int height) + int n, const wxString *choices, + int nsel, int * selection, + wxWindow *parent , int x , int y, bool centre, + int width, int height) { return -1; } @@ -164,13 +195,14 @@ int wxGetMultipleChoice(const wxString& message, const wxString& caption, #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 wxSingleChoiceDialog::wxSingleChoiceDialog(wxWindow *parent, const wxString& message, const wxString& caption, - const int n, const wxString *choices, char **clientData, long style, const wxPoint& pos): + int n, const wxString *choices, char **clientData, long style, const wxPoint& pos): wxDialog(parent, -1, caption, pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL) { Create(parent, message, caption, n, choices, clientData, style); @@ -198,8 +230,8 @@ bool wxSingleChoiceDialog::Create(wxWindow *parent, const wxString& message, con } bool wxSingleChoiceDialog::Create( wxWindow *WXUNUSED(parent), const wxString& message, - const wxString& WXUNUSED(caption), const int n, - const wxString *choices, char **clientData, long style, + const wxString& WXUNUSED(caption), int n, + const wxString *choices, char **clientData, long style, const wxPoint& WXUNUSED(pos) ) { m_dialogStyle = style; @@ -225,6 +257,7 @@ bool wxSingleChoiceDialog::Create( wxWindow *WXUNUSED(parent), const wxString& m wxListBox *listBox = new wxListBox(this, wxID_LISTBOX, wxPoint(-1, -1), wxSize(240, 160), n, choices); + listBox->SetSelection(m_selection); if ( clientData ) { int i; @@ -287,6 +320,17 @@ bool wxSingleChoiceDialog::Create( wxWindow *WXUNUSED(parent), const wxString& m return TRUE; } +// Set the selection +void wxSingleChoiceDialog::SetSelection(int sel) +{ + wxListBox *listBox = (wxListBox *)FindWindow(wxID_LISTBOX); + if (listBox) + { + listBox->SetSelection(sel); + } + m_selection = sel; +} + void wxSingleChoiceDialog::OnOK(wxCommandEvent& WXUNUSED(event)) { wxListBox *listBox = (wxListBox *)FindWindow(wxID_LISTBOX); @@ -300,4 +344,17 @@ void wxSingleChoiceDialog::OnOK(wxCommandEvent& WXUNUSED(event)) EndModal(wxID_OK); } +void wxSingleChoiceDialog::OnListBoxDClick(wxCommandEvent& WXUNUSED(event)) +{ + wxListBox *listBox = (wxListBox *)FindWindow(wxID_LISTBOX); + if ( listBox ) + { + m_selection = listBox->GetSelection(); + m_stringSelection = listBox->GetStringSelection(); + m_clientData = listBox->GetClientData(m_selection); + } + + EndModal(wxID_OK); +} +