1
/////////////////////////////////////////////////////////////////////////////
3
// Purpose: wxThings control test program
4
// Author: John Labenski
8
// Copyright: (c) John Labenski
9
// Licence: wxWidgets licence
10
/////////////////////////////////////////////////////////////////////////////
12
// For compilers that support precompilation, includes "wx/wx.h".
13
#include "wx/wxprec.h"
19
// for all others, include the necessary headers (this file is usually all you
20
// need because it includes almost all "standard" wxWidgets headers)
25
#include "wx/buffer.h"
27
#include "wx/splitter.h"
28
#include "wx/tglbtn.h"
29
#include "wx/notebook.h"
30
#include "wx/things/toggle.h"
31
#include "wx/things/spinctld.h"
32
#include "wx/things/menubtn.h"
33
#include "wx/things/bmpcombo.h"
36
static char *mondrian_xpm[] = {
37
/* columns rows colors chars-per-pixel */
47
" oooooo +++++++++++++++++++++++ ",
48
" oooooo +++++++++++++++++++++++ ",
49
" oooooo +++++++++++++++++++++++ ",
50
" oooooo +++++++++++++++++++++++ ",
51
" oooooo +++++++++++++++++++++++ ",
52
" oooooo +++++++++++++++++++++++ ",
53
" oooooo +++++++++++++++++++++++ ",
55
" ++++++ ++++++++++++++++++ .... ",
56
" ++++++ ++++++++++++++++++ .... ",
57
" ++++++ ++++++++++++++++++ .... ",
58
" ++++++ ++++++++++++++++++ .... ",
59
" ++++++ ++++++++++++++++++ .... ",
60
" ++++++ ++++++++++++++++++ ",
61
" ++++++ ++++++++++++++++++ ++++ ",
62
" ++++++ ++++++++++++++++++ ++++ ",
63
" ++++++ ++++++++++++++++++ ++++ ",
64
" ++++++ ++++++++++++++++++ ++++ ",
65
" ++++++ ++++++++++++++++++ ++++ ",
66
" ++++++ ++++++++++++++++++ ++++ ",
67
" ++++++ ++++++++++++++++++ ++++ ",
68
" ++++++ ++++++++++++++++++ ++++ ",
69
" ++++++ ++++++++++++++++++ ++++ ",
71
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
72
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
73
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
74
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
75
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
76
" ++++++ OOOOOOOOOOOO XXXXX ++++ ",
79
// ----------------------------------------------------------------------------
81
// ----------------------------------------------------------------------------
86
Minimal_About = wxID_ABOUT,
89
// ----------------------------------------------------------------------------
91
// ----------------------------------------------------------------------------
93
class MyFrame : public wxFrame
96
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size,
97
long style = wxDEFAULT_FRAME_STYLE);
99
virtual ~MyFrame() { }
101
wxScrolledWindow *CreateButtonPage(wxWindow *parent);
103
void OnQuit(wxCommandEvent& WXUNUSED(event)) { Close(true); }
104
void OnAbout(wxCommandEvent& event);
106
void OnSpin(wxSpinEvent &event);
107
void OnTextEnter(wxCommandEvent &event);
108
void OnText(wxCommandEvent &event);
109
void OnToggle(wxCommandEvent &event);
110
void OnButton(wxCommandEvent &event);
111
void OnMenu(wxCommandEvent &event);
112
void OnComboBox(wxCommandEvent &event);
114
wxTextCtrl *m_textCtrl;
116
wxNotebook *m_notebook;
119
DECLARE_EVENT_TABLE()
122
// ----------------------------------------------------------------------------
124
// ----------------------------------------------------------------------------
126
class MyApp : public wxApp
129
virtual bool OnInit()
131
MyFrame *frame = new MyFrame(_T("Minimal wxWidgets App"),
132
wxPoint(50, 50), wxSize(450, 400));
139
// ----------------------------------------------------------------------------
140
// event tables and other macros for wxWidgets
141
// ----------------------------------------------------------------------------
143
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
144
EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
145
EVT_MENU(Minimal_About, MyFrame::OnAbout)
147
EVT_SPINCTRL (wxID_ANY, MyFrame::OnSpin)
148
EVT_TEXT_ENTER (wxID_ANY, MyFrame::OnTextEnter)
149
EVT_TEXT (wxID_ANY, MyFrame::OnText)
150
EVT_TOGGLEBUTTON(wxID_ANY, MyFrame::OnToggle)
151
EVT_BUTTON (wxID_ANY, MyFrame::OnButton)
152
EVT_MENU (wxID_ANY, MyFrame::OnMenu)
153
EVT_COMBOBOX (wxID_ANY, MyFrame::OnComboBox)
158
// ----------------------------------------------------------------------------
160
// ----------------------------------------------------------------------------
162
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style)
163
: wxFrame(NULL, -1, title, pos, size, style)
166
wxMenu *menuFile = new wxMenu;
167
menuFile->Append(Minimal_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
169
wxMenu *helpMenu = new wxMenu;
170
helpMenu->Append(Minimal_About, _T("&About...\tF1"), _T("Show about dialog"));
172
wxMenuBar *menuBar = new wxMenuBar();
173
menuBar->Append(menuFile, _T("&File"));
174
menuBar->Append(helpMenu, _T("&Help"));
177
#endif // wxUSE_MENUS
180
// create a status bar just for fun (by default with 1 pane only)
182
SetStatusText(_T("Welcome to wxWidgets!"));
183
#endif // wxUSE_STATUSBAR
185
wxInitAllImageHandlers();
187
wxSplitterWindow *splitter = new wxSplitterWindow(this, -1, wxDefaultPosition, wxDefaultSize, wxSP_3D);
188
splitter->SetMinimumPaneSize(20);
190
m_textCtrl = new wxTextCtrl( splitter, -1, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY|wxVSCROLL|wxHSCROLL );
192
m_notebook = new wxNotebook(splitter, -1);
194
m_notebook->AddPage(CreateButtonPage(m_notebook), wxT("Controls"));
196
splitter->SplitHorizontally(m_notebook, m_textCtrl, 300);
199
wxScrolledWindow *MyFrame::CreateButtonPage(wxWindow *parent)
201
wxScrolledWindow *panel = new wxScrolledWindow(parent, -1);
202
panel->SetScrollbars(1, 1, 2000, 2000);
204
wxFlexGridSizer *item0 = new wxFlexGridSizer( 4, 0, 0 );
206
wxBitmap mondrian(mondrian_xpm);
210
item0->Add(new wxStaticText(panel, -1, wxT("wxSpinCtrl constructor")), 0, wxALIGN_CENTRE|wxALL, 5 );
211
item0->Add(new wxStaticText(panel, -1, wxT("Native constructor")), 0, wxALIGN_CENTRE|wxALL, 5 );
212
item0->Add(new wxStaticText(panel, -1, wxT("Exponential")), 0, wxALIGN_CENTRE|wxALL, 5 );
213
item0->Add(new wxStaticText(panel, -1, wxT("Default constructor")), 0, wxALIGN_CENTRE|wxALL, 5 );
215
wxSpinCtrlDbl *item1 = new wxSpinCtrlDbl( panel, ID++, wxT("hello"), wxDefaultPosition, wxSize(100,-1), 0, 0, 100, 0 );
216
item0->Add( item1, 0, wxALIGN_CENTRE|wxLEFT|wxRIGHT, 5 );
218
wxSpinCtrlDbl *item2 = new wxSpinCtrlDbl( *panel, ID++, wxT("hello"), wxDefaultPosition, wxSize(100,-1), 0, 0, 100, .003, .001 );
219
item0->Add( item2, 0, wxALIGN_CENTRE|wxALL, 5 );
221
wxSpinCtrlDbl *item3 = new wxSpinCtrlDbl( *panel, ID++, wxT("hello"), wxDefaultPosition, wxSize(100,-1), 0, 0, 100, .003, .001 );
222
item3->SetDigits(4, wxSpinCtrlDbl::lf_fmt);
223
item0->Add( item3, 0, wxALIGN_CENTRE|wxALL, 5 );
225
wxSpinCtrlDbl *item4 = new wxSpinCtrlDbl( panel, ID++, wxT("0"), wxDefaultPosition, wxSize(100,-1), 0, 0, 100, 0 );
226
item0->Add( item4, 0, wxALIGN_CENTRE|wxALL, 5 );
230
item0->Add(new wxStaticText(panel, -1, wxT("wxButton")), 0, wxALIGN_CENTRE|wxALL, 5 );
231
item0->Add(new wxStaticText(panel, -1, wxT("wxToggleButton")), 0, wxALIGN_CENTRE|wxALL, 5 );
232
item0->Add(new wxStaticText(panel, -1, wxT("Button Dclick Toggle")), 0, wxALIGN_CENTRE|wxALL, 5 );
233
item0->Add(new wxStaticText(panel, -1, wxT("Toggle Dclick Button")), 0, wxALIGN_CENTRE|wxALL, 5 );
237
wxCustomButton *cbutton;
239
cbutton = new wxCustomButton( panel, ID++, wxT("Left"), mondrian, wxDefaultPosition, wxDefaultSize, wxCUSTBUT_BUTTON|wxCUSTBUT_LEFT );
240
item0->Add( cbutton, 0, wxALIGN_CENTRE|wxALL, 5 );
242
cbutton = new wxCustomButton( panel, ID++, wxT("Right"), mondrian, wxDefaultPosition, wxDefaultSize, wxCUSTBUT_TOGGLE|wxCUSTBUT_RIGHT );
243
item0->Add( cbutton, 0, wxALIGN_CENTRE|wxALL, 5 );
245
cbutton = new wxCustomButton( panel, ID++, wxT("Top"), mondrian, wxDefaultPosition, wxDefaultSize, wxCUSTBUT_BUT_DCLICK_TOG|wxCUSTBUT_TOP );
246
item0->Add( cbutton, 0, wxALIGN_CENTRE|wxALL, 5 );
248
cbutton = new wxCustomButton( panel, ID++, wxT("Bottom"), mondrian, wxDefaultPosition, wxDefaultSize, wxCUSTBUT_TOG_DCLICK_BUT|wxCUSTBUT_BOTTOM );
249
item0->Add( cbutton, 0, wxALIGN_CENTRE|wxALL, 5 );
253
cbutton = new wxCustomButton( panel, ID++, wxT("Left"), mondrian, wxDefaultPosition, wxDefaultSize, wxCUSTBUT_BUTTON|wxCUSTBUT_LEFT );
254
cbutton->SetMargins(wxSize(20,20), true);
255
cbutton->Enable(false);
256
item0->Add( cbutton, 0, wxALIGN_CENTRE|wxALL, 5 );
258
cbutton = new wxCustomButton( panel, ID++, wxT("Right"), mondrian, wxDefaultPosition, wxDefaultSize, wxCUSTBUT_TOGGLE|wxCUSTBUT_RIGHT );
259
cbutton->SetMargins(wxSize(20,20), true);
260
item0->Add( cbutton, 0, wxALIGN_CENTRE|wxALL, 5 );
262
cbutton = new wxCustomButton( panel, ID++, wxT("Top"), mondrian, wxDefaultPosition, wxDefaultSize, wxCUSTBUT_BUT_DCLICK_TOG|wxCUSTBUT_TOP );
263
cbutton->SetMargins(wxSize(20,20), true);
264
item0->Add( cbutton, 0, wxALIGN_CENTRE|wxALL, 5 );
266
cbutton = new wxCustomButton( panel, ID++, wxT("Bottom"), mondrian, wxDefaultPosition, wxDefaultSize, wxCUSTBUT_TOG_DCLICK_BUT|wxCUSTBUT_BOTTOM );
267
cbutton->SetMargins(wxSize(20,20), true);
268
item0->Add( cbutton, 0, wxALIGN_CENTRE|wxALL, 5 );
272
cbutton = new wxCustomButton( panel, ID++, mondrian, wxDefaultPosition, wxDefaultSize, wxCUSTBUT_BUTTON|wxCUSTBUT_LEFT );
273
item0->Add( cbutton, 0, wxALIGN_CENTRE|wxALL, 5 );
275
cbutton = new wxCustomButton( panel, ID++, mondrian, wxDefaultPosition, wxDefaultSize, wxCUSTBUT_TOGGLE|wxCUSTBUT_RIGHT );
276
cbutton->SetMargins(wxSize(20,20), true);
277
item0->Add( cbutton, 0, wxALIGN_CENTRE|wxALL, 5 );
279
cbutton = new wxCustomButton( panel, ID++, wxT("Top"), wxDefaultPosition, wxDefaultSize, wxCUSTBUT_BUT_DCLICK_TOG|wxCUSTBUT_TOP );
280
item0->Add( cbutton, 0, wxALIGN_CENTRE|wxALL, 5 );
282
cbutton = new wxCustomButton( panel, ID++, wxT("Bottom"), wxDefaultPosition, wxDefaultSize, wxCUSTBUT_TOG_DCLICK_BUT|wxCUSTBUT_BOTTOM );
283
cbutton->SetMargins(wxSize(20,20), true);
284
item0->Add( cbutton, 0, wxALIGN_CENTRE|wxALL, 5 );
288
item0->Add(new wxStaticText(panel, -1, wxT("wxButton")), 0, wxALIGN_CENTRE|wxALL, 5 );
289
item0->Add(new wxStaticText(panel, -1, wxT("wxToggleButton")), 0, wxALIGN_CENTRE|wxALL, 5 );
290
item0->Add(new wxStaticText(panel, -1, wxT("Button Dclick Toggle")), 0, wxALIGN_CENTRE|wxALL, 5 );
291
item0->Add(new wxStaticText(panel, -1, wxT("Toggle Dclick Button")), 0, wxALIGN_CENTRE|wxALL, 5 );
295
wxMenuButton *menubtn;
297
menubtn = new wxMenuButton(panel, ID++, mondrian);
298
item0->Add( menubtn, 0, wxALIGN_CENTRE|wxALL, 5 );
299
wxMenu *dmenu = new wxMenu();
300
dmenu->AppendRadioItem(ID++, wxT("Tree view"));
301
dmenu->AppendRadioItem(ID++, wxT("List view"));
302
dmenu->AppendRadioItem(ID++, wxT("Details view"));
303
dmenu->AppendRadioItem(ID++, wxT("Small icon view"));
304
dmenu->AppendRadioItem(ID++, wxT("Large icon view"));
305
dmenu->AppendRadioItem(ID++, wxT("Image preview view"));
306
menubtn->AssignMenu(dmenu);
308
wxArrayBitmap bitmaps;
309
bitmaps.Add(wxBitmap(wxImage(mondrian.ConvertToImage()).Scale(6,6)));
310
bitmaps.Add(wxBitmap(wxImage(mondrian.ConvertToImage()).Scale(10,10)));
311
bitmaps.Add(wxBitmap(wxImage(mondrian.ConvertToImage()).Scale(12,12)));
312
bitmaps.Add(wxBitmap(wxImage(mondrian.ConvertToImage()).Scale(14,14)));
313
bitmaps.Add(wxBitmap(wxImage(mondrian.ConvertToImage()).Scale(16,16)));
314
bitmaps.Add(wxBitmap(wxImage(mondrian.ConvertToImage()).Scale(18,18)));
315
bitmaps.Add(wxBitmap(wxImage(mondrian.ConvertToImage()).Scale(20,20)));
316
bitmaps.Add(wxBitmap(wxImage(mondrian.ConvertToImage()).Scale(24,24)));
317
bitmaps.Add(mondrian);
319
wxArrayString labels;
320
labels.Add(wxT("Hello"));
321
labels.Add(wxT("Hello 1"));
322
labels.Add(wxT("H"));
323
labels.Add(wxT("Hello 3"));
324
labels.Add(wxT("Hello 4 "));
325
labels.Add(wxT("Hello 5"));
326
labels.Add(wxT("Hello 7 "));
327
labels.Add(wxT("Hello 9"));
328
labels.Add(wxT("Hello 10asdasda"));
330
wxBitmapComboBox *bmpcombo = new wxBitmapComboBox(panel, ID++, labels, bitmaps);
331
item0->Add( bmpcombo, 0, wxALIGN_CENTRE|wxALL, 5 );
334
bitmaps.Add(wxBitmap(wxImage(mondrian.ConvertToImage()).Scale(16,16)), 9);
335
bmpcombo = new wxBitmapComboBox(panel, ID++, labels, bitmaps);
336
item0->Add( bmpcombo, 0, wxALIGN_CENTRE|wxALL, 5 );
339
wxString labels[9] = { wxT("Hello"),
347
wxT("Hello 10asdasda") };
349
wxBitmapComboBox *bmpcombo1 = new wxBitmapComboBox(panel, ID++, wxEmptyString,
350
wxDefaultPosition, wxDefaultSize, 9, labels);
352
wxBitmapComboBox *bmpcombo2 = new wxBitmapComboBox(panel, ID++, wxEmptyString,
353
wxDefaultPosition, wxDefaultSize, 9, labels);
355
// freeze while adding items
359
wxImage mondrianImage(mondrian.ConvertToImage());
360
for (int n=0; n<9; n++)
362
bmpcombo1->SetBitmap(n, wxBitmap(mondrianImage.Scale(n*3+8,n*3+8)));
363
bmpcombo2->SetBitmap(n, wxBitmap(mondrianImage.Scale(16,16)));
365
// after adding items use Thaw to CalcLayout
368
bmpcombo1->SetSize(bmpcombo1->GetBestSize());
369
bmpcombo2->SetSize(bmpcombo2->GetBestSize());
371
item0->Add( bmpcombo1, 0, wxALIGN_CENTRE|wxALL, 5 );
372
item0->Add( bmpcombo2, 0, wxALIGN_CENTRE|wxALL, 5 );
374
panel->SetAutoLayout(true);
375
panel->SetSizer(item0);
379
void MyFrame::OnSpin(wxSpinEvent &event)
381
m_textCtrl->AppendText(wxString::Format(wxT("%s Spin id %d, val %ld\n"), wxNow().c_str(), event.GetId(), event.GetInt()));
383
void MyFrame::OnTextEnter(wxCommandEvent& event)
385
if (m_textCtrl->GetId() != event.GetId())
386
m_textCtrl->AppendText(wxString::Format(wxT("%s TextEnter id %d, val '%s'\n"), wxNow().c_str(), event.GetId(), event.GetString().c_str()));
388
void MyFrame::OnText(wxCommandEvent& event)
390
if (m_textCtrl->GetId() != event.GetId())
391
m_textCtrl->AppendText(wxString::Format(wxT("%s TextUpdated id %d, val '%s'\n"), wxNow().c_str(), event.GetId(), event.GetString().c_str()));
393
void MyFrame::OnToggle(wxCommandEvent &event)
395
m_textCtrl->AppendText(wxString::Format(wxT("%s Toggle id %d, val %ld\n"), wxNow().c_str(), event.GetId(), event.GetInt()));
397
void MyFrame::OnButton(wxCommandEvent &event)
399
m_textCtrl->AppendText(wxString::Format(wxT("%s Button id %d, val %ld\n"), wxNow().c_str(), event.GetId(), event.GetInt()));
401
void MyFrame::OnMenu(wxCommandEvent &event)
403
m_textCtrl->AppendText(wxString::Format(wxT("%s Menu id %d, val %ld\n"), wxNow().c_str(), event.GetId(), event.GetInt()));
405
void MyFrame::OnComboBox(wxCommandEvent &event)
407
m_textCtrl->AppendText(wxString::Format(wxT("%s ComboBox id %d, val %ld\n"), wxNow().c_str(), event.GetId(), event.GetInt()));
410
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
413
msg.Printf( _T("This is the About dialog of the thingsdemo sample.\n")
414
_T("Welcome to %s"), wxVERSION_STRING);
416
wxMessageBox(msg, _T("About Minimal"), wxOK | wxICON_INFORMATION, this);