diff --git a/samples/widgets/statbmp.cpp b/samples/widgets/statbmp.cpp index b31b3a0370..97ebb97030 100644 --- a/samples/widgets/statbmp.cpp +++ b/samples/widgets/statbmp.cpp @@ -35,6 +35,7 @@ #include "wx/textctrl.h" #endif +#include "wx/artprov.h" #include "wx/filename.h" #include "wx/generic/statbmpg.h" @@ -126,28 +127,39 @@ void StatBmpWidgetsPage::RecreateWidget() { wxDELETE(m_statbmp); - wxString filepath = m_filepicker->GetPath(); - if ( filepath.empty() ) - return; + wxBitmap bmp; - wxImage image(filepath); - if (! image.IsOk() ) + wxString filepath = m_filepicker->GetPath(); + if ( !filepath.empty() ) { - wxLogMessage("Reading image from file '%s' failed.", filepath.c_str()); - return; + wxImage image(filepath); + if ( image.IsOk() ) + { + bmp = image; + } + else + { + wxLogMessage("Reading image from file '%s' failed.", filepath.c_str()); + } + } + + if ( !bmp.IsOk() ) + { + // Show at least something. + bmp = wxArtProvider::GetBitmap(wxART_MISSING_IMAGE); } long style = GetAttrs().m_defaultFlags; if (m_radio->GetSelection() == 0) { - m_statbmp = new wxStaticBitmap(this, wxID_ANY, wxBitmap(image), + m_statbmp = new wxStaticBitmap(this, wxID_ANY, bmp, wxDefaultPosition, wxDefaultSize, style); } else { - m_statbmp = new wxGenericStaticBitmap(this, wxID_ANY, wxBitmap(image), + m_statbmp = new wxGenericStaticBitmap(this, wxID_ANY, bmp, wxDefaultPosition, wxDefaultSize, style); } diff --git a/samples/widgets/widgets.cpp b/samples/widgets/widgets.cpp index 5df2d6972c..c14cadcc26 100644 --- a/samples/widgets/widgets.cpp +++ b/samples/widgets/widgets.cpp @@ -680,8 +680,11 @@ void WidgetsFrame::ConnectToWidgetEvents() it != widgets.end(); ++it ) { - (*it)->Bind(wxEVT_SET_FOCUS, &WidgetsFrame::OnWidgetFocus, this); - (*it)->Bind(wxEVT_KILL_FOCUS, &WidgetsFrame::OnWidgetFocus, this); + wxWindow* const w = *it; + wxCHECK_RET(w, "NULL widget"); + + w->Bind(wxEVT_SET_FOCUS, &WidgetsFrame::OnWidgetFocus, this); + w->Bind(wxEVT_KILL_FOCUS, &WidgetsFrame::OnWidgetFocus, this); } }