]>
git.saurik.com Git - wxWidgets.git/blob - samples/widgets/statbmp.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Program: wxWidgets Widgets Sample
4 // Purpose: Part of the widgets sample showing wxStaticBitmap
5 // Author: Marcin Wojdyr
7 // Copyright: (c) 2008 Marcin Wojdyr
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx/wx.h".
20 #include "wx/wxprec.h"
26 // for all others, include the necessary headers
30 #include "wx/button.h"
32 #include "wx/radiobox.h"
33 #include "wx/statbmp.h"
34 #include "wx/statbox.h"
35 #include "wx/textctrl.h"
38 #include "wx/filename.h"
40 #include "wx/generic/statbmpg.h"
42 #include "wx/filepicker.h"
45 #include "icons/statbmp.xpm"
48 class StatBmpWidgetsPage
: public WidgetsPage
51 StatBmpWidgetsPage(WidgetsBookCtrl
*book
, wxImageList
*imaglist
)
52 : WidgetsPage(book
, imaglist
, statbmp_xpm
) {}
54 virtual void CreateContent();
55 virtual wxControl
*GetWidget() const { return m_statbmp
; }
56 virtual void RecreateWidget();
59 void OnFileChange(wxFileDirPickerEvent
&WXUNUSED(ev
)) { RecreateWidget(); }
60 void OnRadioChange(wxCommandEvent
&WXUNUSED(ev
)) { RecreateWidget(); }
62 void OnMouseEvent(wxMouseEvent
& WXUNUSED(event
))
64 wxLogMessage(wxT("wxStaticBitmap clicked."));
67 wxStaticBitmapBase
*m_statbmp
;
68 wxFilePickerCtrl
*m_filepicker
;
70 wxStaticBoxSizer
*m_sbsizer
;
72 DECLARE_WIDGETS_PAGE(StatBmpWidgetsPage
)
75 IMPLEMENT_WIDGETS_PAGE(StatBmpWidgetsPage
, wxT("StaticBitmap"),
78 void StatBmpWidgetsPage::CreateContent()
81 static const wxString choices
[] = { "native", "generic" };
82 m_radio
= new wxRadioBox(this, wxID_ANY
, "implementation",
83 wxDefaultPosition
, wxDefaultSize
,
84 WXSIZEOF(choices
), choices
);
88 wxFileName
fn("../image/toucan.png");
89 if ( fn
.FileExists() )
90 testImage
= fn
.GetFullPath();
91 #endif // wxUSE_LIBPNG
92 m_filepicker
= new wxFilePickerCtrl(this, wxID_ANY
, testImage
);
94 m_sbsizer
= new wxStaticBoxSizer(wxVERTICAL
, this, "wxStaticBitmap inside");
96 wxSizer
*leftsizer
= new wxBoxSizer(wxVERTICAL
);
97 leftsizer
->Add(m_radio
, wxSizerFlags().Expand().Border());
98 leftsizer
->Add(m_filepicker
, wxSizerFlags().Expand().Border());
99 wxSizer
*sizer
= new wxBoxSizer(wxHORIZONTAL
);
100 sizer
->Add(leftsizer
, wxSizerFlags().Border());
101 sizer
->Add(m_sbsizer
, wxSizerFlags().Center());
104 wxInitAllImageHandlers();
106 Connect(wxEVT_FILEPICKER_CHANGED
,
107 wxFileDirPickerEventHandler(StatBmpWidgetsPage::OnFileChange
));
108 Connect(wxEVT_RADIOBOX
,
109 wxCommandEventHandler(StatBmpWidgetsPage::OnRadioChange
));
115 void StatBmpWidgetsPage::RecreateWidget()
119 wxString filepath
= m_filepicker
->GetPath();
120 if ( filepath
.empty() )
123 wxImage
image(filepath
);
126 wxLogMessage("Reading image from file '%s' failed.", filepath
.c_str());
129 if (m_radio
->GetSelection() == 0)
130 m_statbmp
= new wxStaticBitmap(this, wxID_ANY
, wxBitmap(image
));
132 m_statbmp
= new wxGenericStaticBitmap(this, wxID_ANY
, wxBitmap(image
));
133 m_sbsizer
->Add(m_statbmp
, wxSizerFlags(1).Expand());
134 GetSizer()->Layout();
135 m_statbmp
->Connect(wxEVT_LEFT_DOWN
,
136 wxMouseEventHandler(StatBmpWidgetsPage::OnMouseEvent
),
138 // When switching from generic to native control on wxMSW under Wine,
139 // the explicit Refresh() is necessary
140 m_statbmp
->Refresh();