]> git.saurik.com Git - wxWidgets.git/blame - samples/widgets/widgets.cpp
wxStreamToTextRedirector fixes, define wxHAS_TEXT_WINDOW_STREAM.
[wxWidgets.git] / samples / widgets / widgets.cpp
CommitLineData
32b8ec41 1/////////////////////////////////////////////////////////////////////////////
be5a51fb 2// Program: wxWidgets Widgets Sample
32b8ec41 3// Name: widgets.cpp
be5a51fb 4// Purpose: Sample showing most of the simple wxWidgets widgets
32b8ec41
VZ
5// Author: Vadim Zeitlin
6// Created: 27.03.01
7// Id: $Id$
8// Copyright: (c) 2001 Vadim Zeitlin
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/app.h"
30 #include "wx/log.h"
32b8ec41 31 #include "wx/frame.h"
e6f3cbd2
VZ
32 #include "wx/menu.h"
33
32b8ec41
VZ
34 #include "wx/button.h"
35 #include "wx/checkbox.h"
36 #include "wx/listbox.h"
37 #include "wx/statbox.h"
38 #include "wx/stattext.h"
39 #include "wx/textctrl.h"
40#endif
41
25057aba 42#include "wx/sysopt.h"
61c083e7 43#include "wx/bookctrl.h"
32b8ec41 44#include "wx/sizer.h"
195df7a7 45#include "wx/colordlg.h"
822b9009 46#include "wx/fontdlg.h"
1bdd1007 47#include "wx/textdlg.h"
32b8ec41
VZ
48
49#include "widgets.h"
50
51// ----------------------------------------------------------------------------
52// constants
53// ----------------------------------------------------------------------------
54
55// control ids
56enum
57{
58 Widgets_ClearLog = 100,
195df7a7 59 Widgets_Quit,
1c01dd16
VZ
60#if wxUSE_TOOLTIPS
61 Widgets_SetTooltip,
62#endif // wxUSE_TOOLTIPS
195df7a7 63 Widgets_SetFgColour,
822b9009
VZ
64 Widgets_SetBgColour,
65 Widgets_SetFont
32b8ec41
VZ
66};
67
68// ----------------------------------------------------------------------------
69// our classes
70// ----------------------------------------------------------------------------
71
72// Define a new application type, each program should derive a class from wxApp
73class WidgetsApp : public wxApp
74{
75public:
76 // override base class virtuals
77 // ----------------------------
78
79 // this one is called on application startup and is a good place for the app
80 // initialization (doing it here and not in the ctor allows to have an error
81 // return: if OnInit() returns false, the application terminates)
82 virtual bool OnInit();
83};
84
85// Define a new frame type: this is going to be our main frame
86class WidgetsFrame : public wxFrame
87{
88public:
89 // ctor(s) and dtor
90 WidgetsFrame(const wxString& title);
91 virtual ~WidgetsFrame();
92
93protected:
94 // event handlers
49abcb2f 95#if USE_LOG
32b8ec41 96 void OnButtonClearLog(wxCommandEvent& event);
49abcb2f 97#endif // USE_LOG
195df7a7
VZ
98 void OnExit(wxCommandEvent& event);
99#if wxUSE_MENUS
1c01dd16
VZ
100#if wxUSE_TOOLTIPS
101 void OnSetTooltip(wxCommandEvent& event);
102#endif // wxUSE_TOOLTIPS
195df7a7
VZ
103 void OnSetFgCol(wxCommandEvent& event);
104 void OnSetBgCol(wxCommandEvent& event);
822b9009 105 void OnSetFont(wxCommandEvent& event);
195df7a7 106#endif // wxUSE_MENUS
32b8ec41 107
61c083e7
WS
108 // initialize the book: add all pages to it
109 void InitBook();
32b8ec41
VZ
110
111private:
112 // the panel containing everything
113 wxPanel *m_panel;
114
49abcb2f 115#if USE_LOG
32b8ec41
VZ
116 // the listbox for logging messages
117 wxListBox *m_lboxLog;
118
119 // the log target we use to redirect messages to the listbox
120 wxLog *m_logTarget;
49abcb2f 121#endif // USE_LOG
32b8ec41 122
61c083e7
WS
123 // the book containing the test pages
124 wxBookCtrl *m_book;
32b8ec41
VZ
125
126 // and the image list for it
127 wxImageList *m_imaglist;
128
195df7a7 129#if wxUSE_MENUS
822b9009 130 // last chosen fg/bg colours and font
195df7a7
VZ
131 wxColour m_colFg,
132 m_colBg;
822b9009 133 wxFont m_font;
195df7a7
VZ
134#endif // wxUSE_MENUS
135
be5a51fb 136 // any class wishing to process wxWidgets events must use this macro
32b8ec41
VZ
137 DECLARE_EVENT_TABLE()
138};
139
49abcb2f 140#if USE_LOG
32b8ec41
VZ
141// A log target which just redirects the messages to a listbox
142class LboxLogger : public wxLog
143{
144public:
145 LboxLogger(wxListBox *lbox, wxLog *logOld)
146 {
147 m_lbox = lbox;
148 //m_lbox->Disable(); -- looks ugly under MSW
149 m_logOld = logOld;
150 }
151
152 virtual ~LboxLogger()
153 {
154 wxLog::SetActiveTarget(m_logOld);
155 }
156
157private:
158 // implement sink functions
159 virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t)
160 {
161 // don't put trace messages into listbox or we can get into infinite
162 // recursion
163 if ( level == wxLOG_Trace )
164 {
165 if ( m_logOld )
166 {
167 // cast is needed to call protected method
168 ((LboxLogger *)m_logOld)->DoLog(level, szString, t);
169 }
170 }
171 else
172 {
173 wxLog::DoLog(level, szString, t);
174 }
175 }
176
c02e5a31 177 virtual void DoLogString(const wxChar *szString, time_t WXUNUSED(t))
32b8ec41
VZ
178 {
179 wxString msg;
180 TimeStamp(&msg);
181 msg += szString;
182
183 #ifdef __WXUNIVERSAL__
184 m_lbox->AppendAndEnsureVisible(msg);
185 #else // other ports don't have this method yet
186 m_lbox->Append(msg);
187 m_lbox->SetFirstItem(m_lbox->GetCount() - 1);
188 #endif
189 }
190
191 // the control we use
192 wxListBox *m_lbox;
193
194 // the old log target
195 wxLog *m_logOld;
196};
49abcb2f 197#endif // USE_LOG
32b8ec41
VZ
198
199// array of pages
38d6b957 200WX_DEFINE_ARRAY_PTR(WidgetsPage *, ArrayWidgetsPage);
32b8ec41
VZ
201
202// ----------------------------------------------------------------------------
203// misc macros
204// ----------------------------------------------------------------------------
205
206IMPLEMENT_APP(WidgetsApp)
207
32b8ec41
VZ
208// ----------------------------------------------------------------------------
209// event tables
210// ----------------------------------------------------------------------------
211
212BEGIN_EVENT_TABLE(WidgetsFrame, wxFrame)
49abcb2f 213#if USE_LOG
32b8ec41 214 EVT_BUTTON(Widgets_ClearLog, WidgetsFrame::OnButtonClearLog)
49abcb2f 215#endif // USE_LOG
195df7a7
VZ
216 EVT_BUTTON(Widgets_Quit, WidgetsFrame::OnExit)
217
1c01dd16
VZ
218#if wxUSE_TOOLTIPS
219 EVT_MENU(Widgets_SetTooltip, WidgetsFrame::OnSetTooltip)
220#endif // wxUSE_TOOLTIPS
221
195df7a7
VZ
222 EVT_MENU(Widgets_SetFgColour, WidgetsFrame::OnSetFgCol)
223 EVT_MENU(Widgets_SetBgColour, WidgetsFrame::OnSetBgCol)
822b9009 224 EVT_MENU(Widgets_SetFont, WidgetsFrame::OnSetFont)
1c01dd16
VZ
225
226 EVT_MENU(wxID_EXIT, WidgetsFrame::OnExit)
32b8ec41
VZ
227END_EVENT_TABLE()
228
229// ============================================================================
230// implementation
231// ============================================================================
232
233// ----------------------------------------------------------------------------
234// app class
235// ----------------------------------------------------------------------------
236
237bool WidgetsApp::OnInit()
238{
bf188f1a 239 if ( !wxApp::OnInit() )
206d3a16 240 return false;
1bdd1007 241
32b8ec41
VZ
242 // the reason for having these ifdef's is that I often run two copies of
243 // this sample side by side and it is useful to see which one is which
24e78d27 244 wxString title;
32b8ec41 245#if defined(__WXUNIVERSAL__)
085a1f3c 246 title = _T("wxUniv/");
24e78d27
VZ
247#endif
248
249#if defined(__WXMSW__)
250 title += _T("wxMSW");
32b8ec41 251#elif defined(__WXGTK__)
24e78d27 252 title += _T("wxGTK");
0f9390c3
GD
253#elif defined(__WXMAC__)
254 title += _T("wxMAC");
255#elif defined(__WXMOTIF__)
256 title += _T("wxMOTIF");
32b8ec41 257#else
be5a51fb 258 title += _T("wxWidgets");
32b8ec41 259#endif
32b8ec41
VZ
260
261 wxFrame *frame = new WidgetsFrame(title + _T(" widgets demo"));
262 frame->Show();
263
264 //wxLog::AddTraceMask(_T("listbox"));
265 //wxLog::AddTraceMask(_T("scrollbar"));
58ec2255 266 //wxLog::AddTraceMask(_T("focus"));
32b8ec41 267
206d3a16 268 return true;
32b8ec41
VZ
269}
270
271// ----------------------------------------------------------------------------
272// WidgetsFrame construction
273// ----------------------------------------------------------------------------
274
275WidgetsFrame::WidgetsFrame(const wxString& title)
206d3a16 276 : wxFrame(NULL, wxID_ANY, title,
df0787b6
VZ
277 wxPoint(0, 50), wxDefaultSize,
278 wxDEFAULT_FRAME_STYLE |
279 wxNO_FULL_REPAINT_ON_RESIZE |
280 wxCLIP_CHILDREN |
281 wxTAB_TRAVERSAL)
32b8ec41
VZ
282{
283 // init everything
49abcb2f 284#if USE_LOG
32b8ec41
VZ
285 m_lboxLog = (wxListBox *)NULL;
286 m_logTarget = (wxLog *)NULL;
49abcb2f 287#endif // USE_LOG
61c083e7 288 m_book = (wxBookCtrl *)NULL;
32b8ec41
VZ
289 m_imaglist = (wxImageList *)NULL;
290
195df7a7
VZ
291#if wxUSE_MENUS
292 // create the menubar
293 wxMenuBar *mbar = new wxMenuBar;
294 wxMenu *menuWidget = new wxMenu;
1c01dd16
VZ
295#if wxUSE_TOOLTIPS
296 menuWidget->Append(Widgets_SetTooltip, _T("Set &tooltip...\tCtrl-T"));
297 menuWidget->AppendSeparator();
298#endif // wxUSE_TOOLTIPS
195df7a7
VZ
299 menuWidget->Append(Widgets_SetFgColour, _T("Set &foreground...\tCtrl-F"));
300 menuWidget->Append(Widgets_SetBgColour, _T("Set &background...\tCtrl-B"));
822b9009 301 menuWidget->Append(Widgets_SetFont, _T("Set f&ont...\tCtrl-O"));
195df7a7
VZ
302 menuWidget->AppendSeparator();
303 menuWidget->Append(wxID_EXIT, _T("&Quit\tCtrl-Q"));
304 mbar->Append(menuWidget, _T("&Widget"));
305 SetMenuBar(mbar);
306#endif // wxUSE_MENUS
307
32b8ec41 308 // create controls
206d3a16
JS
309 m_panel = new wxPanel(this, wxID_ANY,
310 wxDefaultPosition, wxDefaultSize, wxCLIP_CHILDREN);
32b8ec41
VZ
311
312 wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
313
25057aba 314 // we have 2 panes: book with pages demonstrating the controls in the
32b8ec41 315 // upper one and the log window with some buttons in the lower
1bdd1007 316
25057aba
JS
317 int style = wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN|wxBC_DEFAULT;
318 // Uncomment to suppress page theme (draw in solid colour)
8c9f8f91 319 //style |= wxNB_NOPAGETHEME;
32b8ec41 320
61c083e7 321 m_book = new wxBookCtrl(m_panel, wxID_ANY, wxDefaultPosition,
25057aba 322 wxDefaultSize, style);
61c083e7 323 InitBook();
32b8ec41 324
49abcb2f 325#ifndef __SMARTPHONE__
32b8ec41 326 // the lower one only has the log listbox and a button to clear it
49abcb2f 327#if USE_LOG
206d3a16
JS
328 wxSizer *sizerDown = new wxStaticBoxSizer(
329 new wxStaticBox( m_panel, wxID_ANY, _T("&Log window") ),
330 wxVERTICAL);
331
332 m_lboxLog = new wxListBox(m_panel, wxID_ANY);
32b8ec41 333 sizerDown->Add(m_lboxLog, 1, wxGROW | wxALL, 5);
7b127900 334 sizerDown->SetMinSize(100, 150);
b29903d4
WS
335#else
336 wxSizer *sizerDown = new wxBoxSizer(wxVERTICAL);
49abcb2f 337#endif // USE_LOG
88633ca7 338
32b8ec41 339 wxBoxSizer *sizerBtns = new wxBoxSizer(wxHORIZONTAL);
b29903d4 340 wxButton *btn;
49abcb2f 341#if USE_LOG
b29903d4 342 btn = new wxButton(m_panel, Widgets_ClearLog, _T("Clear &log"));
32b8ec41
VZ
343 sizerBtns->Add(btn);
344 sizerBtns->Add(10, 0); // spacer
49abcb2f 345#endif // USE_LOG
32b8ec41
VZ
346 btn = new wxButton(m_panel, Widgets_Quit, _T("E&xit"));
347 sizerBtns->Add(btn);
348 sizerDown->Add(sizerBtns, 0, wxALL | wxALIGN_RIGHT, 5);
349
350 // put everything together
61c083e7 351 sizerTop->Add(m_book, 1, wxGROW | (wxALL & ~(wxTOP | wxBOTTOM)), 10);
32b8ec41
VZ
352 sizerTop->Add(0, 5, 0, wxGROW); // spacer in between
353 sizerTop->Add(sizerDown, 0, wxGROW | (wxALL & ~wxTOP), 10);
354
49abcb2f
WS
355#else // !__SMARTPHONE__/__SMARTPHONE__
356
357 sizerTop->Add(m_book, 1, wxGROW | wxALL );
358
359#endif // __SMARTPHONE__
360
32b8ec41
VZ
361 m_panel->SetSizer(sizerTop);
362
363 sizerTop->Fit(this);
364 sizerTop->SetSizeHints(this);
365
49abcb2f 366#if USE_LOG && !defined(__WXCOCOA__)
7bb70733 367 // wxCocoa's listbox is too flakey to use for logging right now
32b8ec41
VZ
368 // now that everything is created we can redirect the log messages to the
369 // listbox
370 m_logTarget = new LboxLogger(m_lboxLog, wxLog::GetActiveTarget());
371 wxLog::SetActiveTarget(m_logTarget);
b29903d4 372#endif
32b8ec41
VZ
373}
374
61c083e7 375void WidgetsFrame::InitBook()
32b8ec41
VZ
376{
377 m_imaglist = new wxImageList(32, 32);
378
379 ArrayWidgetsPage pages;
380 wxArrayString labels;
381
61c083e7 382 // we need to first create all pages and only then add them to the book
32b8ec41
VZ
383 // as we need the image list first
384 WidgetsPageInfo *info = WidgetsPage::ms_widgetPages;
385 while ( info )
386 {
61c083e7 387 WidgetsPage *page = (*info->GetCtor())(m_book, m_imaglist);
32b8ec41
VZ
388 pages.Add(page);
389
390 labels.Add(info->GetLabel());
391
392 info = info->GetNext();
393 }
394
61c083e7 395 m_book->SetImageList(m_imaglist);
32b8ec41
VZ
396
397 // now do add them
398 size_t count = pages.GetCount();
399 for ( size_t n = 0; n < count; n++ )
400 {
61c083e7
WS
401 m_book->AddPage(
402 pages[n],
403 labels[n],
404 false, // don't select
405 n // image id
406 );
25057aba
JS
407
408/*
409 wxColour colour = m_book->MSWGetBgColourForChild(pages[n]);
410 pages[n]->SetBackgroundColour(colour);
411*/
32b8ec41
VZ
412 }
413}
414
415WidgetsFrame::~WidgetsFrame()
416{
49abcb2f 417#if USE_LOG
32b8ec41 418 delete m_logTarget;
49abcb2f 419#endif // USE_LOG
32b8ec41
VZ
420 delete m_imaglist;
421}
422
423// ----------------------------------------------------------------------------
424// WidgetsFrame event handlers
425// ----------------------------------------------------------------------------
426
195df7a7 427void WidgetsFrame::OnExit(wxCommandEvent& WXUNUSED(event))
32b8ec41
VZ
428{
429 Close();
430}
431
49abcb2f 432#if USE_LOG
c02e5a31 433void WidgetsFrame::OnButtonClearLog(wxCommandEvent& WXUNUSED(event))
32b8ec41
VZ
434{
435 m_lboxLog->Clear();
436}
49abcb2f 437#endif // USE_LOG
32b8ec41 438
195df7a7
VZ
439#if wxUSE_MENUS
440
1c01dd16
VZ
441#if wxUSE_TOOLTIPS
442
443void WidgetsFrame::OnSetTooltip(wxCommandEvent& WXUNUSED(event))
444{
445 static wxString s_tip = _T("This is a tooltip");
446
447 wxString s = wxGetTextFromUser
448 (
449 _T("Tooltip text: "),
450 _T("Widgets sample"),
451 s_tip,
452 this
453 );
454
455 if ( s.empty() )
456 return;
457
458 WidgetsPage *page = wxStaticCast(m_book->GetCurrentPage(), WidgetsPage);
459 page->GetWidget()->SetToolTip(s_tip = s);
460
461 wxControl *ctrl2 = page->GetWidget2();
462 if ( ctrl2 )
463 ctrl2->SetToolTip(s);
464}
465
466#endif // wxUSE_TOOLTIPS
467
195df7a7
VZ
468void WidgetsFrame::OnSetFgCol(wxCommandEvent& WXUNUSED(event))
469{
923f4e79 470#if wxUSE_COLOURDLG
822b9009
VZ
471 // allow for debugging the default colour the first time this is called
472 WidgetsPage *page = wxStaticCast(m_book->GetCurrentPage(), WidgetsPage);
473 if (!m_colFg.Ok())
474 m_colFg = page->GetForegroundColour();
475
195df7a7
VZ
476 wxColour col = wxGetColourFromUser(this, m_colFg);
477 if ( !col.Ok() )
478 return;
479
480 m_colFg = col;
481
195df7a7 482 page->GetWidget()->SetForegroundColour(m_colFg);
750972ab 483 page->GetWidget()->Refresh();
1c01dd16
VZ
484
485 wxControl *ctrl2 = page->GetWidget2();
486 if ( ctrl2 )
487 {
488 ctrl2->SetForegroundColour(m_colFg);
489 ctrl2->Refresh();
490 }
923f4e79 491#else
1c01dd16 492 wxLogMessage(_T("Colour selection dialog not available in current build."));
923f4e79 493#endif
195df7a7
VZ
494}
495
496void WidgetsFrame::OnSetBgCol(wxCommandEvent& WXUNUSED(event))
497{
923f4e79 498#if wxUSE_COLOURDLG
822b9009
VZ
499 WidgetsPage *page = wxStaticCast(m_book->GetCurrentPage(), WidgetsPage);
500 if ( !m_colBg.Ok() )
501 m_colBg = page->GetBackgroundColour();
502
195df7a7
VZ
503 wxColour col = wxGetColourFromUser(this, m_colBg);
504 if ( !col.Ok() )
505 return;
506
507 m_colBg = col;
508
195df7a7 509 page->GetWidget()->SetBackgroundColour(m_colBg);
750972ab 510 page->GetWidget()->Refresh();
1c01dd16
VZ
511
512 wxControl *ctrl2 = page->GetWidget2();
513 if ( ctrl2 )
514 {
515 ctrl2->SetBackgroundColour(m_colFg);
516 ctrl2->Refresh();
517 }
923f4e79 518#else
1c01dd16 519 wxLogMessage(_T("Colour selection dialog not available in current build."));
923f4e79 520#endif
195df7a7
VZ
521}
522
822b9009
VZ
523void WidgetsFrame::OnSetFont(wxCommandEvent& WXUNUSED(event))
524{
525#if wxUSE_FONTDLG
526 WidgetsPage *page = wxStaticCast(m_book->GetCurrentPage(), WidgetsPage);
527 if (!m_font.Ok())
528 m_font = page->GetFont();
529
530 wxFont font = wxGetFontFromUser(this, m_font);
531 if ( !font.Ok() )
532 return;
533
534 m_font = font;
535
536 page->GetWidget()->SetFont(m_font);
537 page->GetWidget()->Refresh();
538
539 wxControl *ctrl2 = page->GetWidget2();
540 if ( ctrl2 )
541 {
542 ctrl2->SetFont(m_font);
543 ctrl2->Refresh();
544 }
545#else
546 wxLogMessage(_T("Font selection dialog not available in current build."));
547#endif
548}
549
195df7a7
VZ
550#endif // wxUSE_MENUS
551
32b8ec41
VZ
552// ----------------------------------------------------------------------------
553// WidgetsPageInfo
554// ----------------------------------------------------------------------------
555
556WidgetsPageInfo *WidgetsPage::ms_widgetPages = NULL;
557
558WidgetsPageInfo::WidgetsPageInfo(Constructor ctor, const wxChar *label)
559 : m_label(label)
560{
561 m_ctor = ctor;
562
2673bcb0
DS
563 m_next = NULL;
564
565 // dummy sorting: add and immediately sort on list according to label
566
567 if(WidgetsPage::ms_widgetPages)
568 {
569 WidgetsPageInfo *node_prev = WidgetsPage::ms_widgetPages;
570 if(wxStrcmp(label,node_prev->GetLabel().c_str())<0)
571 {
572 // add as first
573 m_next = node_prev;
574 WidgetsPage::ms_widgetPages = this;
575 }
576 else
577 {
578 WidgetsPageInfo *node_next;
579 do
580 {
581 node_next = node_prev->GetNext();
582 if(node_next)
583 {
584 // add if between two
585 if(wxStrcmp(label,node_next->GetLabel().c_str())<0)
586 {
587 node_prev->SetNext(this);
588 m_next = node_next;
589 // force to break loop
590 node_next = NULL;
591 }
592 }
593 else
594 {
595 // add as last
596 node_prev->SetNext(this);
597 m_next = node_next;
598 }
599 node_prev = node_next;
600 }while(node_next);
601 }
602 }
603 else
604 {
605 // add when first
606
607 WidgetsPage::ms_widgetPages = this;
608
609 }
610
32b8ec41
VZ
611}
612
613// ----------------------------------------------------------------------------
614// WidgetsPage
615// ----------------------------------------------------------------------------
616
61c083e7
WS
617WidgetsPage::WidgetsPage(wxBookCtrl *book)
618 : wxPanel(book, wxID_ANY,
df0787b6
VZ
619 wxDefaultPosition, wxDefaultSize,
620 wxNO_FULL_REPAINT_ON_RESIZE |
621 wxCLIP_CHILDREN |
622 wxTAB_TRAVERSAL)
32b8ec41
VZ
623{
624}
625
626wxSizer *WidgetsPage::CreateSizerWithText(wxControl *control,
627 wxWindowID id,
628 wxTextCtrl **ppText)
629{
630 wxSizer *sizerRow = new wxBoxSizer(wxHORIZONTAL);
206d3a16
JS
631 wxTextCtrl *text = new wxTextCtrl(this, id, wxEmptyString,
632 wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
4589ec39 633
32b8ec41
VZ
634 sizerRow->Add(control, 0, wxRIGHT | wxALIGN_CENTRE_VERTICAL, 5);
635 sizerRow->Add(text, 1, wxLEFT | wxALIGN_CENTRE_VERTICAL, 5);
636
637 if ( ppText )
638 *ppText = text;
639
640 return sizerRow;
641}
642
643// create a sizer containing a label and a text ctrl
644wxSizer *WidgetsPage::CreateSizerWithTextAndLabel(const wxString& label,
645 wxWindowID id,
646 wxTextCtrl **ppText)
647{
206d3a16
JS
648 return CreateSizerWithText(new wxStaticText(this, wxID_ANY, label),
649 id, ppText);
32b8ec41
VZ
650}
651
652// create a sizer containing a button and a text ctrl
653wxSizer *WidgetsPage::CreateSizerWithTextAndButton(wxWindowID idBtn,
654 const wxString& label,
655 wxWindowID id,
656 wxTextCtrl **ppText)
657{
658 return CreateSizerWithText(new wxButton(this, idBtn, label), id, ppText);
659}
660
661wxCheckBox *WidgetsPage::CreateCheckBoxAndAddToSizer(wxSizer *sizer,
662 const wxString& label,
663 wxWindowID id)
664{
665 wxCheckBox *checkbox = new wxCheckBox(this, id, label);
666 sizer->Add(checkbox, 0, wxLEFT | wxRIGHT, 5);
667 sizer->Add(0, 2, 0, wxGROW); // spacer
668
669 return checkbox;
670}
671