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