X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d8cda32e74512a28dcca1f05a5076d3c5d712640..cb6b81bc94108bcb0a702ac5fdaf4944fa7706a0:/samples/widgets/statbmp.cpp diff --git a/samples/widgets/statbmp.cpp b/samples/widgets/statbmp.cpp index 9b64407887..d4b155ce95 100644 --- a/samples/widgets/statbmp.cpp +++ b/samples/widgets/statbmp.cpp @@ -4,9 +4,8 @@ // Purpose: Part of the widgets sample showing wxStaticBitmap // Author: Marcin Wojdyr // Created: 2008-06-19 -// Id: $Id$ // Copyright: (c) 2008 Marcin Wojdyr -// License: wxWindows license +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -36,6 +35,8 @@ #include "wx/textctrl.h" #endif +#include "wx/filename.h" + #include "wx/generic/statbmpg.h" #include "wx/sizer.h" #include "wx/filepicker.h" @@ -82,7 +83,13 @@ void StatBmpWidgetsPage::CreateContent() wxDefaultPosition, wxDefaultSize, WXSIZEOF(choices), choices); - m_filepicker = new wxFilePickerCtrl(this, wxID_ANY, "../image/toucan.png"); + wxString testImage; +#if wxUSE_LIBPNG + wxFileName fn("../image/toucan.png"); + if ( fn.FileExists() ) + testImage = fn.GetFullPath(); +#endif // wxUSE_LIBPNG + m_filepicker = new wxFilePickerCtrl(this, wxID_ANY, testImage); m_sbsizer = new wxStaticBoxSizer(wxVERTICAL, this, "wxStaticBitmap inside"); @@ -96,9 +103,9 @@ void StatBmpWidgetsPage::CreateContent() wxInitAllImageHandlers(); - Connect(wxEVT_COMMAND_FILEPICKER_CHANGED, + Connect(wxEVT_FILEPICKER_CHANGED, wxFileDirPickerEventHandler(StatBmpWidgetsPage::OnFileChange)); - Connect(wxEVT_COMMAND_RADIOBOX_SELECTED, + Connect(wxEVT_RADIOBOX, wxCommandEventHandler(StatBmpWidgetsPage::OnRadioChange)); m_statbmp = NULL; @@ -107,13 +114,16 @@ void StatBmpWidgetsPage::CreateContent() void StatBmpWidgetsPage::RecreateWidget() { - delete m_statbmp; + wxDELETE(m_statbmp); + wxString filepath = m_filepicker->GetPath(); + if ( filepath.empty() ) + return; + wxImage image(filepath); - if (! image.Ok() ) + if (! image.IsOk() ) { wxLogMessage("Reading image from file '%s' failed.", filepath.c_str()); - m_statbmp = NULL; return; } if (m_radio->GetSelection() == 0) @@ -122,11 +132,11 @@ void StatBmpWidgetsPage::RecreateWidget() m_statbmp = new wxGenericStaticBitmap(this, wxID_ANY, wxBitmap(image)); m_sbsizer->Add(m_statbmp, wxSizerFlags(1).Expand()); GetSizer()->Layout(); - m_statbmp->Connect(wxEVT_LEFT_DOWN, + m_statbmp->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(StatBmpWidgetsPage::OnMouseEvent), NULL, this); - // When switching from generic to native control on wxMSW under Wine, + // When switching from generic to native control on wxMSW under Wine, // the explicit Refresh() is necessary - m_statbmp->Refresh(); + m_statbmp->Refresh(); }