]> git.saurik.com Git - wxWidgets.git/blob - samples/widgets/statbmp.cpp
Add <span> tag and limited support for CSS styles to wxHTML.
[wxWidgets.git] / samples / widgets / statbmp.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Program: wxWidgets Widgets Sample
3 // Name: statbmp.cpp
4 // Purpose: Part of the widgets sample showing wxStaticBitmap
5 // Author: Marcin Wojdyr
6 // Created: 2008-06-19
7 // Id: $Id$
8 // Copyright: (c) 2008 Marcin Wojdyr
9 // License: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // for compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 // for all others, include the necessary headers
28 #ifndef WX_PRECOMP
29 #include "wx/log.h"
30
31 #include "wx/button.h"
32 #include "wx/image.h"
33 #include "wx/radiobox.h"
34 #include "wx/statbmp.h"
35 #include "wx/statbox.h"
36 #include "wx/textctrl.h"
37 #endif
38
39 #include "wx/filename.h"
40
41 #include "wx/generic/statbmpg.h"
42 #include "wx/sizer.h"
43 #include "wx/filepicker.h"
44
45 #include "widgets.h"
46 #include "icons/statbmp.xpm"
47
48
49 class StatBmpWidgetsPage : public WidgetsPage
50 {
51 public:
52 StatBmpWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist)
53 : WidgetsPage(book, imaglist, statbmp_xpm) {}
54
55 virtual void CreateContent();
56 virtual wxControl *GetWidget() const { return m_statbmp; }
57 virtual void RecreateWidget();
58
59 private:
60 void OnFileChange(wxFileDirPickerEvent &WXUNUSED(ev)) { RecreateWidget(); }
61 void OnRadioChange(wxCommandEvent &WXUNUSED(ev)) { RecreateWidget(); }
62
63 void OnMouseEvent(wxMouseEvent& WXUNUSED(event))
64 {
65 wxLogMessage(wxT("wxStaticBitmap clicked."));
66 }
67
68 wxStaticBitmapBase *m_statbmp;
69 wxFilePickerCtrl *m_filepicker;
70 wxRadioBox *m_radio;
71 wxStaticBoxSizer *m_sbsizer;
72
73 DECLARE_WIDGETS_PAGE(StatBmpWidgetsPage)
74 };
75
76 IMPLEMENT_WIDGETS_PAGE(StatBmpWidgetsPage, wxT("StaticBitmap"),
77 ALL_CTRLS);
78
79 void StatBmpWidgetsPage::CreateContent()
80 {
81
82 static const wxString choices[] = { "native", "generic" };
83 m_radio = new wxRadioBox(this, wxID_ANY, "implementation",
84 wxDefaultPosition, wxDefaultSize,
85 WXSIZEOF(choices), choices);
86
87 wxString testImage;
88 #if wxUSE_LIBPNG
89 wxFileName fn("../image/toucan.png");
90 if ( fn.FileExists() )
91 testImage = fn.GetFullPath();
92 #endif // wxUSE_LIBPNG
93 m_filepicker = new wxFilePickerCtrl(this, wxID_ANY, testImage);
94
95 m_sbsizer = new wxStaticBoxSizer(wxVERTICAL, this, "wxStaticBitmap inside");
96
97 wxSizer *leftsizer = new wxBoxSizer(wxVERTICAL);
98 leftsizer->Add(m_radio, wxSizerFlags().Expand().Border());
99 leftsizer->Add(m_filepicker, wxSizerFlags().Expand().Border());
100 wxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
101 sizer->Add(leftsizer, wxSizerFlags().Border());
102 sizer->Add(m_sbsizer, wxSizerFlags().Center());
103 SetSizer(sizer);
104
105 wxInitAllImageHandlers();
106
107 Connect(wxEVT_COMMAND_FILEPICKER_CHANGED,
108 wxFileDirPickerEventHandler(StatBmpWidgetsPage::OnFileChange));
109 Connect(wxEVT_COMMAND_RADIOBOX_SELECTED,
110 wxCommandEventHandler(StatBmpWidgetsPage::OnRadioChange));
111
112 m_statbmp = NULL;
113 RecreateWidget();
114 }
115
116 void StatBmpWidgetsPage::RecreateWidget()
117 {
118 delete m_statbmp;
119 m_statbmp = NULL;
120
121 wxString filepath = m_filepicker->GetPath();
122 if ( filepath.empty() )
123 return;
124
125 wxImage image(filepath);
126 if (! image.Ok() )
127 {
128 wxLogMessage("Reading image from file '%s' failed.", filepath.c_str());
129 return;
130 }
131 if (m_radio->GetSelection() == 0)
132 m_statbmp = new wxStaticBitmap(this, wxID_ANY, wxBitmap(image));
133 else
134 m_statbmp = new wxGenericStaticBitmap(this, wxID_ANY, wxBitmap(image));
135 m_sbsizer->Add(m_statbmp, wxSizerFlags(1).Expand());
136 GetSizer()->Layout();
137 m_statbmp->Connect(wxEVT_LEFT_DOWN,
138 wxMouseEventHandler(StatBmpWidgetsPage::OnMouseEvent),
139 NULL, this);
140 // When switching from generic to native control on wxMSW under Wine,
141 // the explicit Refresh() is necessary
142 m_statbmp->Refresh();
143 }
144