X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/64c794f6820f129444ebcbf9dd6368805470e78e..732e46f552027022e4dc87d013918c9d45b0f772:/src/generic/choicdgg.cpp?ds=sidebyside diff --git a/src/generic/choicdgg.cpp b/src/generic/choicdgg.cpp index c197380287..2b5b11b2a2 100644 --- a/src/generic/choicdgg.cpp +++ b/src/generic/choicdgg.cpp @@ -54,6 +54,20 @@ #define wxID_LISTBOX 3000 +// --------------------------------------------------------------------------- +// macros +// --------------------------------------------------------------------------- + +/* Macro for avoiding #ifdefs when value have to be different depending on size of + device we display on - take it from something like wxDesktopPolicy in the future + */ + +#if defined(__SMARTPHONE__) + #define wxLARGESMALL(large,small) small +#else + #define wxLARGESMALL(large,small) large +#endif + // ---------------------------------------------------------------------------- // private functions // ---------------------------------------------------------------------------- @@ -204,8 +218,9 @@ size_t wxGetMultipleChoices(wxArrayInt& selections, { wxMultiChoiceDialog dialog(parent, message, caption, n, choices); - if ( !selections.IsEmpty() ) - dialog.SetSelections(selections); + // call this even if selections array is empty and this then (correctly) + // deselects the first item which is selected by default + dialog.SetSelections(selections); if ( dialog.ShowModal() == wxID_OK ) selections = dialog.GetSelections(); @@ -251,10 +266,8 @@ bool wxAnyChoiceDialog::Create(wxWindow *parent, wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL ); -#ifdef __SMARTPHONE__ - // 1) text message - topsizer->Add( CreateTextSizer( message ), 0, wxEXPAND, 0 ); + topsizer->Add( CreateTextSizer( message ), 0, wxALL, wxLARGESMALL(10,0) ); // 2) list box m_listbox = new wxListBox( this, wxID_LISTBOX, @@ -264,32 +277,22 @@ bool wxAnyChoiceDialog::Create(wxWindow *parent, if ( n > 0 ) m_listbox->SetSelection(0); - topsizer->Add( m_listbox, 1, wxEXPAND, 0 ); + topsizer->Add( m_listbox, 1, wxEXPAND | wxLEFT|wxRIGHT, wxLARGESMALL(15,0) ); + + // smart phones does not support or do not waste space for wxButtons +#ifdef __SMARTPHONE__ SetRightMenu(wxID_CANCEL, _("Cancel")); #else // __SMARTPHONE__/!__SMARTPHONE__ - // 1) text message - topsizer->Add( CreateTextSizer( message ), 0, wxALL, 10 ); - - // 2) list box - m_listbox = new wxListBox( this, wxID_LISTBOX, - wxDefaultPosition, wxDefaultSize, - n, choices, - styleLbox ); - if ( n > 0 ) - m_listbox->SetSelection(0); - - topsizer->Add( m_listbox, 1, wxEXPAND | wxLEFT|wxRIGHT, 15 ); - #if wxUSE_STATLINE // 3) static line topsizer->Add( new wxStaticLine( this, wxID_ANY ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 ); #endif // 4) buttons - topsizer->Add( CreateButtonSizer( styleDlg & (wxOK|wxCANCEL) ), 0, wxCENTRE | wxALL, 10 ); + topsizer->Add( CreateButtonSizer( styleDlg & (wxOK|wxCANCEL) ), 0, wxEXPAND | wxALL, 10 ); #endif // !__SMARTPHONE__ @@ -299,7 +302,8 @@ bool wxAnyChoiceDialog::Create(wxWindow *parent, topsizer->SetSizeHints( this ); topsizer->Fit( this ); - Centre( wxBOTH ); + if ( styleDlg & wxCENTRE ) + Centre(wxBOTH); m_listbox->SetFocus(); @@ -324,11 +328,7 @@ bool wxAnyChoiceDialog::Create(wxWindow *parent, // ---------------------------------------------------------------------------- BEGIN_EVENT_TABLE(wxSingleChoiceDialog, wxDialog) -#if defined(__SMARTPHONE__) - EVT_MENU(wxID_OK, wxSingleChoiceDialog::OnOK) -#else EVT_BUTTON(wxID_OK, wxSingleChoiceDialog::OnOK) -#endif EVT_LISTBOX_DCLICK(wxID_LISTBOX, wxSingleChoiceDialog::OnListBoxDClick) END_EVENT_TABLE() @@ -459,8 +459,17 @@ bool wxMultiChoiceDialog::Create( wxWindow *parent, void wxMultiChoiceDialog::SetSelections(const wxArrayInt& selections) { - size_t count = selections.GetCount(); - for ( size_t n = 0; n < count; n++ ) + // first clear all currently selected items + size_t n, + count = m_listbox->GetCount(); + for ( n = 0; n < count; ++n ) + { + m_listbox->Deselect(n); + } + + // now select the ones which should be selected + count = selections.GetCount(); + for ( n = 0; n < count; n++ ) { m_listbox->Select(selections[n]); }