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