X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a30e7029749646348aaacf61da9ed66743d77a40..d5cc191c9cd48a915ce0dfc6e49511b2fddb6746:/samples/widgets/statbmp.cpp?ds=sidebyside diff --git a/samples/widgets/statbmp.cpp b/samples/widgets/statbmp.cpp index b1e04d6615..6449d23ef9 100644 --- a/samples/widgets/statbmp.cpp +++ b/samples/widgets/statbmp.cpp @@ -6,7 +6,7 @@ // Created: 2008-06-19 // Id: $Id$ // Copyright: (c) 2008 Marcin Wojdyr -// License: wxWindows license +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -29,12 +29,15 @@ #include "wx/log.h" #include "wx/button.h" + #include "wx/image.h" #include "wx/radiobox.h" #include "wx/statbmp.h" #include "wx/statbox.h" #include "wx/textctrl.h" #endif +#include "wx/filename.h" + #include "wx/generic/statbmpg.h" #include "wx/sizer.h" #include "wx/filepicker.h" @@ -81,7 +84,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"); @@ -95,9 +104,9 @@ void StatBmpWidgetsPage::CreateContent() wxInitAllImageHandlers(); - Connect(wxEVT_COMMAND_FILEPICKER_CHANGED, + Connect(wxEVT_COMMAND_FILEPICKER_CHANGED, wxFileDirPickerEventHandler(StatBmpWidgetsPage::OnFileChange)); - Connect(wxEVT_COMMAND_RADIOBOX_SELECTED, + Connect(wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler(StatBmpWidgetsPage::OnRadioChange)); m_statbmp = NULL; @@ -106,13 +115,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) @@ -121,11 +133,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(); }