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
8 // Copyright: (c) 2001 Vadim Zeitlin
9 // License: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
27 // for all others, include the necessary headers
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"
43 #include "wx/sysopt.h"
44 #include "wx/bookctrl.h"
45 #include "wx/treebook.h"
47 #include "wx/colordlg.h"
48 #include "wx/fontdlg.h"
49 #include "wx/textdlg.h"
50 #include "wx/imaglist.h"
51 #include "wx/wupdlock.h"
55 #include "../sample.xpm"
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
64 Widgets_ClearLog
= 100,
71 #endif // wxUSE_TOOLTIPS
83 Widgets_BorderDefault
,
85 Widgets_GlobalBusyCursor
,
89 Widgets_GoToPageLast
= Widgets_GoToPage
+ 100
92 const wxChar
*WidgetsCategories
[MAX_PAGES
] = {
93 #if defined(__WXUNIVERSAL__)
107 // ----------------------------------------------------------------------------
109 // ----------------------------------------------------------------------------
111 // Define a new application type, each program should derive a class from wxApp
112 class WidgetsApp
: public wxApp
115 // override base class virtuals
116 // ----------------------------
118 // this one is called on application startup and is a good place for the app
119 // initialization (doing it here and not in the ctor allows to have an error
120 // return: if OnInit() returns false, the application terminates)
121 virtual bool OnInit();
124 // Define a new frame type: this is going to be our main frame
125 class WidgetsFrame
: public wxFrame
129 WidgetsFrame(const wxString
& title
);
130 virtual ~WidgetsFrame();
135 void OnButtonClearLog(wxCommandEvent
& event
);
137 void OnExit(wxCommandEvent
& event
);
140 void OnPageChanging(WidgetsBookCtrlEvent
& event
);
141 void OnPageChanged(WidgetsBookCtrlEvent
& event
);
142 void OnGoToPage(wxCommandEvent
& event
);
145 void OnSetTooltip(wxCommandEvent
& event
);
146 #endif // wxUSE_TOOLTIPS
147 void OnSetFgCol(wxCommandEvent
& event
);
148 void OnSetBgCol(wxCommandEvent
& event
);
149 void OnSetFont(wxCommandEvent
& event
);
150 void OnEnable(wxCommandEvent
& event
);
151 void OnSetBorder(wxCommandEvent
& event
);
153 void OnToggleGlobalBusyCursor(wxCommandEvent
& event
);
154 void OnToggleBusyCursor(wxCommandEvent
& event
);
155 #endif // wxUSE_MENUS
157 // initialize the book: add all pages to it
160 // return the currently selected page (never NULL)
161 WidgetsPage
*CurrentPage();
164 // the panel containing everything
168 // the listbox for logging messages
169 wxListBox
*m_lboxLog
;
171 // the log target we use to redirect messages to the listbox
175 // the book containing the test pages
176 WidgetsBookCtrl
*m_book
;
179 // last chosen fg/bg colours and font
183 #endif // wxUSE_MENUS
185 // any class wishing to process wxWidgets events must use this macro
186 DECLARE_EVENT_TABLE()
190 // A log target which just redirects the messages to a listbox
191 class LboxLogger
: public wxLog
194 LboxLogger(wxListBox
*lbox
, wxLog
*logOld
)
197 //m_lbox->Disable(); -- looks ugly under MSW
201 virtual ~LboxLogger()
203 wxLog::SetActiveTarget(m_logOld
);
207 // implement sink functions
208 virtual void DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
210 // don't put trace messages into listbox or we can get into infinite
212 if ( level
== wxLOG_Trace
)
216 // cast is needed to call protected method
217 ((LboxLogger
*)m_logOld
)->DoLog(level
, szString
, t
);
222 wxLog::DoLog(level
, szString
, t
);
226 virtual void DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
232 #ifdef __WXUNIVERSAL__
233 m_lbox
->AppendAndEnsureVisible(msg
);
234 #else // other ports don't have this method yet
236 m_lbox
->SetFirstItem(m_lbox
->GetCount() - 1);
240 // the control we use
243 // the old log target
249 WX_DEFINE_ARRAY_PTR(WidgetsPage
*, ArrayWidgetsPage
);
251 // ----------------------------------------------------------------------------
253 // ----------------------------------------------------------------------------
255 IMPLEMENT_APP(WidgetsApp
)
257 // ----------------------------------------------------------------------------
259 // ----------------------------------------------------------------------------
261 BEGIN_EVENT_TABLE(WidgetsFrame
, wxFrame
)
263 EVT_BUTTON(Widgets_ClearLog
, WidgetsFrame::OnButtonClearLog
)
265 EVT_BUTTON(Widgets_Quit
, WidgetsFrame::OnExit
)
268 EVT_MENU(Widgets_SetTooltip
, WidgetsFrame::OnSetTooltip
)
269 #endif // wxUSE_TOOLTIPS
272 EVT_WIDGETS_PAGE_CHANGING(wxID_ANY
, WidgetsFrame::OnPageChanging
)
273 EVT_MENU_RANGE(Widgets_GoToPage
, Widgets_GoToPageLast
,
274 WidgetsFrame::OnGoToPage
)
276 EVT_MENU(Widgets_SetFgColour
, WidgetsFrame::OnSetFgCol
)
277 EVT_MENU(Widgets_SetBgColour
, WidgetsFrame::OnSetBgCol
)
278 EVT_MENU(Widgets_SetFont
, WidgetsFrame::OnSetFont
)
279 EVT_MENU(Widgets_Enable
, WidgetsFrame::OnEnable
)
281 EVT_MENU_RANGE(Widgets_BorderNone
, Widgets_BorderDefault
,
282 WidgetsFrame::OnSetBorder
)
284 EVT_MENU(Widgets_GlobalBusyCursor
, WidgetsFrame::OnToggleGlobalBusyCursor
)
285 EVT_MENU(Widgets_BusyCursor
, WidgetsFrame::OnToggleBusyCursor
)
287 EVT_MENU(wxID_EXIT
, WidgetsFrame::OnExit
)
288 #endif // wxUSE_MENUS
291 // ============================================================================
293 // ============================================================================
295 // ----------------------------------------------------------------------------
297 // ----------------------------------------------------------------------------
299 bool WidgetsApp::OnInit()
301 if ( !wxApp::OnInit() )
304 // the reason for having these ifdef's is that I often run two copies of
305 // this sample side by side and it is useful to see which one is which
307 #if defined(__WXUNIVERSAL__)
308 title
= _T("wxUniv/");
311 #if defined(__WXMSW__)
312 title
+= _T("wxMSW");
313 #elif defined(__WXGTK__)
314 title
+= _T("wxGTK");
315 #elif defined(__WXMAC__)
316 title
+= _T("wxMAC");
317 #elif defined(__WXMOTIF__)
318 title
+= _T("wxMOTIF");
320 title
+= _T("wxWidgets");
323 wxFrame
*frame
= new WidgetsFrame(title
+ _T(" widgets demo"));
326 //wxLog::AddTraceMask(_T("listbox"));
327 //wxLog::AddTraceMask(_T("scrollbar"));
328 //wxLog::AddTraceMask(_T("focus"));
333 // ----------------------------------------------------------------------------
334 // WidgetsFrame construction
335 // ----------------------------------------------------------------------------
337 WidgetsFrame::WidgetsFrame(const wxString
& title
)
338 : wxFrame(NULL
, wxID_ANY
, title
)
340 // set the frame icon
341 SetIcon(wxICON(sample
));
345 m_lboxLog
= (wxListBox
*)NULL
;
346 m_logTarget
= (wxLog
*)NULL
;
348 m_book
= (WidgetsBookCtrl
*)NULL
;
351 // create the menubar
352 wxMenuBar
*mbar
= new wxMenuBar
;
353 wxMenu
*menuWidget
= new wxMenu
;
355 menuWidget
->Append(Widgets_SetTooltip
, _T("Set &tooltip...\tCtrl-T"));
356 menuWidget
->AppendSeparator();
357 #endif // wxUSE_TOOLTIPS
358 menuWidget
->Append(Widgets_SetFgColour
, _T("Set &foreground...\tCtrl-F"));
359 menuWidget
->Append(Widgets_SetBgColour
, _T("Set &background...\tCtrl-B"));
360 menuWidget
->Append(Widgets_SetFont
, _T("Set f&ont...\tCtrl-O"));
361 menuWidget
->AppendCheckItem(Widgets_Enable
, _T("&Enable/disable\tCtrl-E"));
363 wxMenu
*menuBorders
= new wxMenu
;
364 menuBorders
->AppendRadioItem(Widgets_BorderDefault
, _T("De&fault\tCtrl-Shift-9"));
365 menuBorders
->AppendRadioItem(Widgets_BorderNone
, _T("&None\tCtrl-Shift-0"));
366 menuBorders
->AppendRadioItem(Widgets_BorderSimple
, _T("&Simple\tCtrl-Shift-1"));
367 menuBorders
->AppendRadioItem(Widgets_BorderDouble
, _T("&Double\tCtrl-Shift-2"));
368 menuBorders
->AppendRadioItem(Widgets_BorderStatic
, _T("Stati&c\tCtrl-Shift-3"));
369 menuBorders
->AppendRadioItem(Widgets_BorderRaised
, _T("&Raised\tCtrl-Shift-4"));
370 menuBorders
->AppendRadioItem(Widgets_BorderSunken
, _T("S&unken\tCtrl-Shift-5"));
371 menuWidget
->AppendSubMenu(menuBorders
, _T("Set &border"));
373 menuWidget
->AppendSeparator();
374 menuWidget
->AppendCheckItem(Widgets_GlobalBusyCursor
,
375 _T("Toggle &global busy cursor\tCtrl-Shift-U"));
376 menuWidget
->AppendCheckItem(Widgets_BusyCursor
,
377 _T("Toggle b&usy cursor\tCtrl-U"));
379 menuWidget
->AppendSeparator();
380 menuWidget
->Append(wxID_EXIT
, _T("&Quit\tCtrl-Q"));
381 mbar
->Append(menuWidget
, _T("&Widget"));
384 mbar
->Check(Widgets_Enable
, true);
385 #endif // wxUSE_MENUS
388 m_panel
= new wxPanel(this, wxID_ANY
);
390 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
392 // we have 2 panes: book with pages demonstrating the controls in the
393 // upper one and the log window with some buttons in the lower
395 int style
= wxBK_DEFAULT
;
396 // Uncomment to suppress page theme (draw in solid colour)
397 //style |= wxNB_NOPAGETHEME;
399 m_book
= new WidgetsBookCtrl(m_panel
, Widgets_BookCtrl
, wxDefaultPosition
,
401 wxSize(500, wxDefaultCoord
), // under Motif, height is a function of the width...
408 #ifndef __WXHANDHELD__
409 // the lower one only has the log listbox and a button to clear it
411 wxSizer
*sizerDown
= new wxStaticBoxSizer(
412 new wxStaticBox( m_panel
, wxID_ANY
, _T("&Log window") ),
415 m_lboxLog
= new wxListBox(m_panel
, wxID_ANY
);
416 sizerDown
->Add(m_lboxLog
, 1, wxGROW
| wxALL
, 5);
417 sizerDown
->SetMinSize(100, 150);
419 wxSizer
*sizerDown
= new wxBoxSizer(wxVERTICAL
);
422 wxBoxSizer
*sizerBtns
= new wxBoxSizer(wxHORIZONTAL
);
425 btn
= new wxButton(m_panel
, Widgets_ClearLog
, _T("Clear &log"));
427 sizerBtns
->Add(10, 0); // spacer
429 btn
= new wxButton(m_panel
, Widgets_Quit
, _T("E&xit"));
431 sizerDown
->Add(sizerBtns
, 0, wxALL
| wxALIGN_RIGHT
, 5);
433 // put everything together
434 sizerTop
->Add(m_book
, 1, wxGROW
| (wxALL
& ~(wxTOP
| wxBOTTOM
)), 10);
435 sizerTop
->Add(0, 5, 0, wxGROW
); // spacer in between
436 sizerTop
->Add(sizerDown
, 0, wxGROW
| (wxALL
& ~wxTOP
), 10);
438 #else // !__WXHANDHELD__/__WXHANDHELD__
440 sizerTop
->Add(m_book
, 1, wxGROW
| wxALL
);
442 #endif // __WXHANDHELD__
444 m_panel
->SetSizer(sizerTop
);
447 sizerTop
->SetSizeHints(this);
449 #if USE_LOG && !defined(__WXCOCOA__)
450 // wxCocoa's listbox is too flakey to use for logging right now
451 // now that everything is created we can redirect the log messages to the
453 m_logTarget
= new LboxLogger(m_lboxLog
, wxLog::GetActiveTarget());
454 wxLog::SetActiveTarget(m_logTarget
);
458 void WidgetsFrame::InitBook()
460 #if USE_ICONS_IN_BOOK
461 wxImageList
*imageList
= new wxImageList(ICON_SIZE
, ICON_SIZE
);
463 wxImage
img(sample_xpm
);
464 imageList
->Add(wxBitmap(img
.Scale(ICON_SIZE
, ICON_SIZE
)));
466 wxImageList
*imageList
= NULL
;
470 WidgetsBookCtrl
*books
[MAX_PAGES
];
473 ArrayWidgetsPage pages
[MAX_PAGES
];
474 wxArrayString labels
[MAX_PAGES
];
476 wxMenu
*menuPages
= new wxMenu
;
477 unsigned int nPage
= 0, nFKey
= 0;
478 int cat
, imageId
= 1;
480 // we need to first create all pages and only then add them to the book
481 // as we need the image list first
483 // we also construct the pages menu during this first iteration
484 for ( cat
= 0; cat
< MAX_PAGES
; cat
++ )
487 nPage
++; // increase for parent page
489 books
[cat
] = new WidgetsBookCtrl(m_book
,
496 for ( WidgetsPageInfo
*info
= WidgetsPage::ms_widgetPages
;
498 info
= info
->GetNext() )
500 if( (info
->GetCategories() & ( 1 << cat
)) == 0)
503 WidgetsPage
*page
= (*info
->GetCtor())(
510 pages
[cat
].Add(page
);
512 labels
[cat
].Add(info
->GetLabel());
513 if ( cat
== ALL_PAGE
)
515 wxString
radioLabel(info
->GetLabel());
519 radioLabel
<< wxT("\tF" ) << nFKey
;
522 menuPages
->AppendRadioItem(
523 Widgets_GoToPage
+ nPage
,
527 // consider only for book in book architecture
533 // consider only for treebook architecture (with subpages)
539 GetMenuBar()->Append(menuPages
, _T("&Page"));
541 #if USE_ICONS_IN_BOOK
542 m_book
->AssignImageList(imageList
);
545 for ( cat
= 0; cat
< MAX_PAGES
; cat
++ )
548 m_book
->AddPage(NULL
,WidgetsCategories
[cat
],false,0);
550 m_book
->AddPage(books
[cat
],WidgetsCategories
[cat
],false,0);
551 #if USE_ICONS_IN_BOOK
552 books
[cat
]->SetImageList(imageList
);
557 size_t count
= pages
[cat
].GetCount();
558 for ( size_t n
= 0; n
< count
; n
++ )
568 false, // don't select
575 wxEVT_COMMAND_WIDGETS_PAGE_CHANGED
,
576 wxWidgetsbookEventHandler(WidgetsFrame::OnPageChanged
) );
579 // for treebook page #0 is empty parent page only so select the first page
580 // with some contents
581 m_book
->SetSelection(1);
583 // but ensure that the top of the tree is shown nevertheless
584 wxTreeCtrl
* const tree
= m_book
->GetTreeCtrl();
586 wxTreeItemIdValue cookie
;
587 tree
->EnsureVisible(tree
->GetFirstChild(tree
->GetRootItem(), cookie
));
589 // for other books set selection twice to force connected event handler
590 // to force lazy creation of initial visible content
591 m_book
->SetSelection(1);
592 m_book
->SetSelection(0);
593 #endif // USE_TREEBOOK
596 WidgetsPage
*WidgetsFrame::CurrentPage()
598 wxWindow
*page
= m_book
->GetCurrentPage();
601 WidgetsBookCtrl
*subBook
= wxStaticCast(page
, WidgetsBookCtrl
);
602 wxCHECK_MSG( subBook
, NULL
, _T("no WidgetsBookCtrl?") );
604 page
= subBook
->GetCurrentPage();
605 #endif // !USE_TREEBOOK
607 return wxStaticCast(page
, WidgetsPage
);
610 WidgetsFrame::~WidgetsFrame()
617 // ----------------------------------------------------------------------------
618 // WidgetsFrame event handlers
619 // ----------------------------------------------------------------------------
621 void WidgetsFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
627 void WidgetsFrame::OnButtonClearLog(wxCommandEvent
& WXUNUSED(event
))
635 void WidgetsFrame::OnPageChanging(WidgetsBookCtrlEvent
& event
)
638 // don't allow selection of entries without pages (categories)
639 if ( !m_book
->GetPage(event
.GetSelection()) )
646 void WidgetsFrame::OnPageChanged(WidgetsBookCtrlEvent
& event
)
648 const int sel
= event
.GetSelection();
650 // adjust "Page" menu selection
651 wxMenuItem
*item
= GetMenuBar()->FindItem(Widgets_GoToPage
+ sel
);
655 GetMenuBar()->Check(Widgets_BusyCursor
, false);
657 // create the pages on demand, otherwise the sample startup is too slow as
658 // it creates hundreds of controls
659 WidgetsPage
*page
= CurrentPage();
660 if ( page
->GetChildren().empty() )
662 wxWindowUpdateLocker
noUpdates(page
);
663 page
->CreateContent();
665 page
->GetSizer()->Fit(page
);
667 WidgetsBookCtrl
*book
= wxStaticCast(page
->GetParent(), WidgetsBookCtrl
);
669 for ( size_t i
= 0; i
< book
->GetPageCount(); ++i
)
671 wxWindow
*page
= book
->GetPage(i
);
674 size
.IncTo(page
->GetSize());
683 void WidgetsFrame::OnGoToPage(wxCommandEvent
& event
)
686 m_book
->SetSelection(event
.GetId() - Widgets_GoToPage
);
688 m_book
->SetSelection(m_book
->GetPageCount()-1);
689 WidgetsBookCtrl
*book
= wxStaticCast(m_book
->GetCurrentPage(), WidgetsBookCtrl
);
690 book
->SetSelection(event
.GetId() - Widgets_GoToPage
);
696 void WidgetsFrame::OnSetTooltip(wxCommandEvent
& WXUNUSED(event
))
698 static wxString s_tip
= _T("This is a tooltip");
700 wxTextEntryDialog dialog
703 _T("Tooltip text (may use \\n, leave empty to remove): "),
704 _T("Widgets sample"),
708 if ( dialog
.ShowModal() != wxID_OK
)
711 s_tip
= dialog
.GetValue();
712 s_tip
.Replace(_T("\\n"), _T("\n"));
714 WidgetsPage
*page
= CurrentPage();
716 page
->GetWidget()->SetToolTip(s_tip
);
718 wxControl
*ctrl2
= page
->GetWidget2();
720 ctrl2
->SetToolTip(s_tip
);
723 #endif // wxUSE_TOOLTIPS
725 void WidgetsFrame::OnSetFgCol(wxCommandEvent
& WXUNUSED(event
))
728 // allow for debugging the default colour the first time this is called
729 WidgetsPage
*page
= CurrentPage();
732 m_colFg
= page
->GetForegroundColour();
734 wxColour col
= wxGetColourFromUser(this, m_colFg
);
740 page
->GetWidget()->SetForegroundColour(m_colFg
);
741 page
->GetWidget()->Refresh();
743 wxControl
*ctrl2
= page
->GetWidget2();
746 ctrl2
->SetForegroundColour(m_colFg
);
750 wxLogMessage(_T("Colour selection dialog not available in current build."));
754 void WidgetsFrame::OnSetBgCol(wxCommandEvent
& WXUNUSED(event
))
757 WidgetsPage
*page
= CurrentPage();
760 m_colBg
= page
->GetBackgroundColour();
762 wxColour col
= wxGetColourFromUser(this, m_colBg
);
768 page
->GetWidget()->SetBackgroundColour(m_colBg
);
769 page
->GetWidget()->Refresh();
771 wxControl
*ctrl2
= page
->GetWidget2();
774 ctrl2
->SetBackgroundColour(m_colFg
);
778 wxLogMessage(_T("Colour selection dialog not available in current build."));
782 void WidgetsFrame::OnSetFont(wxCommandEvent
& WXUNUSED(event
))
785 WidgetsPage
*page
= CurrentPage();
788 m_font
= page
->GetFont();
790 wxFont font
= wxGetFontFromUser(this, m_font
);
796 page
->GetWidget()->SetFont(m_font
);
797 page
->GetWidget()->Refresh();
799 wxControl
*ctrl2
= page
->GetWidget2();
802 ctrl2
->SetFont(m_font
);
806 wxLogMessage(_T("Font selection dialog not available in current build."));
810 void WidgetsFrame::OnEnable(wxCommandEvent
& event
)
812 CurrentPage()->GetWidget()->Enable(event
.IsChecked());
815 void WidgetsFrame::OnSetBorder(wxCommandEvent
& event
)
818 switch ( event
.GetId() )
820 case Widgets_BorderNone
: border
= wxBORDER_NONE
; break;
821 case Widgets_BorderStatic
: border
= wxBORDER_STATIC
; break;
822 case Widgets_BorderSimple
: border
= wxBORDER_SIMPLE
; break;
823 case Widgets_BorderRaised
: border
= wxBORDER_RAISED
; break;
824 case Widgets_BorderSunken
: border
= wxBORDER_SUNKEN
; break;
825 case Widgets_BorderDouble
: border
= wxBORDER_DOUBLE
; break;
828 wxFAIL_MSG( _T("unknown border style") );
831 case Widgets_BorderDefault
: border
= wxBORDER_DEFAULT
; break;
834 WidgetsPage::ms_defaultFlags
&= ~wxBORDER_MASK
;
835 WidgetsPage::ms_defaultFlags
|= border
;
837 WidgetsPage
*page
= CurrentPage();
839 page
->RecreateWidget();
842 void WidgetsFrame::OnToggleGlobalBusyCursor(wxCommandEvent
& event
)
844 if ( event
.IsChecked() )
850 void WidgetsFrame::OnToggleBusyCursor(wxCommandEvent
& event
)
852 CurrentPage()->GetWidget()->SetCursor(*(event
.IsChecked()
854 : wxSTANDARD_CURSOR
));
857 #endif // wxUSE_MENUS
859 // ----------------------------------------------------------------------------
861 // ----------------------------------------------------------------------------
863 WidgetsPageInfo::WidgetsPageInfo(Constructor ctor
, const wxChar
*label
, int categories
)
865 , m_categories(categories
)
871 // dummy sorting: add and immediately sort in the list according to label
872 if ( WidgetsPage::ms_widgetPages
)
874 WidgetsPageInfo
*node_prev
= WidgetsPage::ms_widgetPages
;
875 if ( wxStrcmp(label
, node_prev
->GetLabel().c_str()) < 0 )
879 WidgetsPage::ms_widgetPages
= this;
883 WidgetsPageInfo
*node_next
;
886 node_next
= node_prev
->GetNext();
889 // add if between two
890 if ( wxStrcmp(label
, node_next
->GetLabel().c_str()) < 0 )
892 node_prev
->SetNext(this);
894 // force to break loop
901 node_prev
->SetNext(this);
904 node_prev
= node_next
;
912 WidgetsPage::ms_widgetPages
= this;
916 // ----------------------------------------------------------------------------
918 // ----------------------------------------------------------------------------
920 int WidgetsPage::ms_defaultFlags
= wxBORDER_DEFAULT
;
921 WidgetsPageInfo
*WidgetsPage::ms_widgetPages
= NULL
;
923 WidgetsPage::WidgetsPage(WidgetsBookCtrl
*book
,
924 wxImageList
*imaglist
,
926 : wxPanel(book
, wxID_ANY
,
927 wxDefaultPosition
, wxDefaultSize
,
928 wxNO_FULL_REPAINT_ON_RESIZE
|
932 #if USE_ICONS_IN_BOOK
933 imaglist
->Add(wxBitmap(wxImage(icon
).Scale(ICON_SIZE
, ICON_SIZE
)));
935 wxUnusedVar(imaglist
);
940 wxSizer
*WidgetsPage::CreateSizerWithText(wxControl
*control
,
944 wxSizer
*sizerRow
= new wxBoxSizer(wxHORIZONTAL
);
945 wxTextCtrl
*text
= new wxTextCtrl(this, id
, wxEmptyString
,
946 wxDefaultPosition
, wxDefaultSize
, wxTE_PROCESS_ENTER
);
948 sizerRow
->Add(control
, 0, wxRIGHT
| wxALIGN_CENTRE_VERTICAL
, 5);
949 sizerRow
->Add(text
, 1, wxLEFT
| wxALIGN_CENTRE_VERTICAL
, 5);
957 // create a sizer containing a label and a text ctrl
958 wxSizer
*WidgetsPage::CreateSizerWithTextAndLabel(const wxString
& label
,
962 return CreateSizerWithText(new wxStaticText(this, wxID_ANY
, label
),
966 // create a sizer containing a button and a text ctrl
967 wxSizer
*WidgetsPage::CreateSizerWithTextAndButton(wxWindowID idBtn
,
968 const wxString
& label
,
972 return CreateSizerWithText(new wxButton(this, idBtn
, label
), id
, ppText
);
975 wxCheckBox
*WidgetsPage::CreateCheckBoxAndAddToSizer(wxSizer
*sizer
,
976 const wxString
& label
,
979 wxCheckBox
*checkbox
= new wxCheckBox(this, id
, label
);
980 sizer
->Add(checkbox
, 0, wxLEFT
| wxRIGHT
, 5);
981 sizer
->Add(0, 2, 0, wxGROW
); // spacer