From 1bf045456fb04344dfe4bd9de0adedfbc8b7a920 Mon Sep 17 00:00:00 2001 From: Francesco Montorsi Date: Fri, 28 Nov 2008 22:32:00 +0000 Subject: [PATCH] fix crash caused by cancelling querybitmap dialog; fix crash caused by clicking 'add widget icons' on an empty bitmapcombobox git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57015 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/widgets/bmpcombobox.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/samples/widgets/bmpcombobox.cpp b/samples/widgets/bmpcombobox.cpp index f5e73f7331..61ef1dac46 100644 --- a/samples/widgets/bmpcombobox.cpp +++ b/samples/widgets/bmpcombobox.cpp @@ -578,12 +578,16 @@ void BitmapComboBoxWidgetsPage::OnButtonLoadFromFile(wxCommandEvent& WXUNUSED(ev if ( sel == wxNOT_FOUND ) sel = m_combobox->GetCount(); - m_combobox->Insert(s, QueryBitmap(&s), sel); + wxBitmap bmp = QueryBitmap(&s); + if (bmp.IsOk()) + m_combobox->Insert(s, bmp, sel); } void BitmapComboBoxWidgetsPage::OnButtonSetFromFile(wxCommandEvent& WXUNUSED(event)) { - m_combobox->SetItemBitmap(m_combobox->GetSelection(), QueryBitmap(NULL)); + wxBitmap bmp = QueryBitmap(NULL); + if (bmp.IsOk()) + m_combobox->SetItemBitmap(m_combobox->GetSelection(), bmp); } void BitmapComboBoxWidgetsPage::OnButtonAddMany(wxCommandEvent& WXUNUSED(event)) @@ -661,6 +665,7 @@ void BitmapComboBoxWidgetsPage::LoadWidgetImages( wxArrayString* strings, wxImag if ( !wxDir::Exists(fn.GetFullPath()) || !wxDir::GetAllFiles(fn.GetFullPath(),strings,wxT("*.xpm")) ) { + // Try ../../samples/widgets/icons fn.RemoveLastDir(); fn.RemoveLastDir(); fn.AppendDir(wxT("icons")); @@ -693,7 +698,7 @@ void BitmapComboBoxWidgetsPage::LoadWidgetImages( wxArrayString* strings, wxImag for ( i=0; isize(); i++ ) { fn.SetFullName((*strings)[i]); - wxString name =fn.GetName(); + wxString name = fn.GetName(); // Handle few exceptions if ( name == wxT("bmpbtn") ) @@ -715,6 +720,11 @@ void BitmapComboBoxWidgetsPage::LoadWidgetImages( wxArrayString* strings, wxImag #endif images->Add(bmp); (*strings)[i] = name; + + // if the combobox is empty, use as bitmap size of the image list + // the size of the first valid image loaded + if (foundSize == wxDefaultSize) + foundSize = bmp.GetSize(); } } @@ -894,7 +904,8 @@ wxBitmap BitmapComboBoxWidgetsPage::QueryBitmap(wxString* pStr) bitmap = LoadBitmap(filepath); } - wxLogDebug(wxT("%i, %i"),bitmap.GetWidth(), bitmap.GetHeight()); + if (bitmap.IsOk()) + wxLogDebug(wxT("%i, %i"),bitmap.GetWidth(), bitmap.GetHeight()); ::wxSetCursor( *wxSTANDARD_CURSOR ); -- 2.45.2