]> git.saurik.com Git - wxWidgets.git/blame - samples/widgets/widgets.cpp
Don't hardcode the number of toolbar tools in the toolbar sample.
[wxWidgets.git] / samples / widgets / widgets.cpp
CommitLineData
32b8ec41 1/////////////////////////////////////////////////////////////////////////////
be5a51fb 2// Program: wxWidgets Widgets Sample
2ddb4d13 3// Name: samples/widgets/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
526954c5 9// Licence: wxWindows licence
32b8ec41
VZ
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 32 #include "wx/menu.h"
e273c962 33 #include "wx/image.h"
e6f3cbd2 34
32b8ec41
VZ
35 #include "wx/button.h"
36 #include "wx/checkbox.h"
37 #include "wx/listbox.h"
38 #include "wx/statbox.h"
39 #include "wx/stattext.h"
40 #include "wx/textctrl.h"
bd018e7e 41 #include "wx/msgdlg.h"
32b8ec41
VZ
42#endif
43
25057aba 44#include "wx/sysopt.h"
61c083e7 45#include "wx/bookctrl.h"
f2fdc4d5 46#include "wx/treebook.h"
32b8ec41 47#include "wx/sizer.h"
195df7a7 48#include "wx/colordlg.h"
822b9009 49#include "wx/fontdlg.h"
1bdd1007 50#include "wx/textdlg.h"
261357eb 51#include "wx/imaglist.h"
453535a7 52#include "wx/wupdlock.h"
ea98f11c 53#include "wx/textcompleter.h"
32b8ec41 54
0fa541e8
VZ
55#include "wx/persist/toplevel.h"
56#include "wx/persist/treebook.h"
57
32b8ec41
VZ
58#include "widgets.h"
59
f2fdc4d5
WS
60#include "../sample.xpm"
61
32b8ec41
VZ
62// ----------------------------------------------------------------------------
63// constants
64// ----------------------------------------------------------------------------
65
66// control ids
67enum
68{
69 Widgets_ClearLog = 100,
195df7a7 70 Widgets_Quit,
1301e228 71
3700e21b
VZ
72 Widgets_BookCtrl,
73
1c01dd16
VZ
74#if wxUSE_TOOLTIPS
75 Widgets_SetTooltip,
76#endif // wxUSE_TOOLTIPS
195df7a7 77 Widgets_SetFgColour,
822b9009 78 Widgets_SetBgColour,
ebfee179 79 Widgets_SetPageBg,
a17c1df4 80 Widgets_SetFont,
1301e228
VZ
81 Widgets_Enable,
82
83 Widgets_BorderNone,
84 Widgets_BorderStatic,
85 Widgets_BorderSimple,
86 Widgets_BorderRaised,
87 Widgets_BorderSunken,
88 Widgets_BorderDouble,
3700e21b
VZ
89 Widgets_BorderDefault,
90
e32bcef6
VZ
91 Widgets_GlobalBusyCursor,
92 Widgets_BusyCursor,
93
3700e21b 94 Widgets_GoToPage,
6a8d7937
VZ
95 Widgets_GoToPageLast = Widgets_GoToPage + 100,
96
97
98 TextEntry_Begin,
99 TextEntry_DisableAutoComplete = TextEntry_Begin,
100 TextEntry_AutoCompleteFixed,
101 TextEntry_AutoCompleteFilenames,
03dede4d 102 TextEntry_AutoCompleteDirectories,
ea98f11c 103 TextEntry_AutoCompleteCustom,
63f7d502
VZ
104
105 TextEntry_SetHint,
6a8d7937 106 TextEntry_End
32b8ec41
VZ
107};
108
f2fdc4d5 109const wxChar *WidgetsCategories[MAX_PAGES] = {
d8d07a79
WS
110#if defined(__WXUNIVERSAL__)
111 wxT("Universal"),
112#else
f2fdc4d5 113 wxT("Native"),
d8d07a79 114#endif
f2fdc4d5
WS
115 wxT("Generic"),
116 wxT("Pickers"),
117 wxT("Comboboxes"),
118 wxT("With items"),
119 wxT("Editable"),
120 wxT("Books"),
121 wxT("All controls")
122};
123
32b8ec41
VZ
124// ----------------------------------------------------------------------------
125// our classes
126// ----------------------------------------------------------------------------
127
128// Define a new application type, each program should derive a class from wxApp
129class WidgetsApp : public wxApp
130{
131public:
132 // override base class virtuals
133 // ----------------------------
134
135 // this one is called on application startup and is a good place for the app
136 // initialization (doing it here and not in the ctor allows to have an error
137 // return: if OnInit() returns false, the application terminates)
138 virtual bool OnInit();
139};
140
141// Define a new frame type: this is going to be our main frame
142class WidgetsFrame : public wxFrame
143{
144public:
145 // ctor(s) and dtor
146 WidgetsFrame(const wxString& title);
147 virtual ~WidgetsFrame();
148
149protected:
150 // event handlers
49abcb2f 151#if USE_LOG
32b8ec41 152 void OnButtonClearLog(wxCommandEvent& event);
49abcb2f 153#endif // USE_LOG
195df7a7 154 void OnExit(wxCommandEvent& event);
a17c1df4 155
195df7a7 156#if wxUSE_MENUS
3e859739 157 void OnPageChanging(WidgetsBookCtrlEvent& event);
f2fdc4d5 158 void OnPageChanged(WidgetsBookCtrlEvent& event);
3700e21b
VZ
159 void OnGoToPage(wxCommandEvent& event);
160
1c01dd16
VZ
161#if wxUSE_TOOLTIPS
162 void OnSetTooltip(wxCommandEvent& event);
163#endif // wxUSE_TOOLTIPS
195df7a7
VZ
164 void OnSetFgCol(wxCommandEvent& event);
165 void OnSetBgCol(wxCommandEvent& event);
ebfee179 166 void OnSetPageBg(wxCommandEvent& event);
822b9009 167 void OnSetFont(wxCommandEvent& event);
a17c1df4 168 void OnEnable(wxCommandEvent& event);
1301e228 169 void OnSetBorder(wxCommandEvent& event);
e32bcef6
VZ
170
171 void OnToggleGlobalBusyCursor(wxCommandEvent& event);
172 void OnToggleBusyCursor(wxCommandEvent& event);
6a8d7937 173
63f7d502 174 // wxTextEntry-specific tests
6a8d7937
VZ
175 void OnDisableAutoComplete(wxCommandEvent& event);
176 void OnAutoCompleteFixed(wxCommandEvent& event);
177 void OnAutoCompleteFilenames(wxCommandEvent& event);
03dede4d 178 void OnAutoCompleteDirectories(wxCommandEvent& event);
ea98f11c 179 void OnAutoCompleteCustom(wxCommandEvent& event);
6a8d7937 180
63f7d502
VZ
181 void OnSetHint(wxCommandEvent& event);
182
6a8d7937
VZ
183 void OnUpdateTextUI(wxUpdateUIEvent& event)
184 {
185 event.Enable( CurrentPage()->GetTextEntry() != NULL );
186 }
195df7a7 187#endif // wxUSE_MENUS
32b8ec41 188
61c083e7
WS
189 // initialize the book: add all pages to it
190 void InitBook();
32b8ec41 191
3e859739 192 // return the currently selected page (never NULL)
f2fdc4d5
WS
193 WidgetsPage *CurrentPage();
194
32b8ec41
VZ
195private:
196 // the panel containing everything
197 wxPanel *m_panel;
198
49abcb2f 199#if USE_LOG
32b8ec41
VZ
200 // the listbox for logging messages
201 wxListBox *m_lboxLog;
202
203 // the log target we use to redirect messages to the listbox
204 wxLog *m_logTarget;
49abcb2f 205#endif // USE_LOG
32b8ec41 206
61c083e7 207 // the book containing the test pages
f2fdc4d5 208 WidgetsBookCtrl *m_book;
32b8ec41 209
195df7a7 210#if wxUSE_MENUS
822b9009 211 // last chosen fg/bg colours and font
195df7a7
VZ
212 wxColour m_colFg,
213 m_colBg;
822b9009 214 wxFont m_font;
195df7a7
VZ
215#endif // wxUSE_MENUS
216
be5a51fb 217 // any class wishing to process wxWidgets events must use this macro
32b8ec41
VZ
218 DECLARE_EVENT_TABLE()
219};
220
49abcb2f 221#if USE_LOG
32b8ec41
VZ
222// A log target which just redirects the messages to a listbox
223class LboxLogger : public wxLog
224{
225public:
226 LboxLogger(wxListBox *lbox, wxLog *logOld)
227 {
228 m_lbox = lbox;
229 //m_lbox->Disable(); -- looks ugly under MSW
230 m_logOld = logOld;
231 }
232
233 virtual ~LboxLogger()
234 {
235 wxLog::SetActiveTarget(m_logOld);
236 }
237
238private:
239 // implement sink functions
f5427762 240 virtual void DoLogTextAtLevel(wxLogLevel level, const wxString& msg)
32b8ec41 241 {
32b8ec41
VZ
242 if ( level == wxLOG_Trace )
243 {
244 if ( m_logOld )
f5427762
VZ
245 m_logOld->LogTextAtLevel(level, msg);
246 return;
32b8ec41 247 }
32b8ec41
VZ
248
249 #ifdef __WXUNIVERSAL__
250 m_lbox->AppendAndEnsureVisible(msg);
251 #else // other ports don't have this method yet
252 m_lbox->Append(msg);
253 m_lbox->SetFirstItem(m_lbox->GetCount() - 1);
254 #endif
255 }
256
257 // the control we use
258 wxListBox *m_lbox;
259
260 // the old log target
261 wxLog *m_logOld;
262};
49abcb2f 263#endif // USE_LOG
32b8ec41
VZ
264
265// array of pages
38d6b957 266WX_DEFINE_ARRAY_PTR(WidgetsPage *, ArrayWidgetsPage);
32b8ec41
VZ
267
268// ----------------------------------------------------------------------------
269// misc macros
270// ----------------------------------------------------------------------------
271
272IMPLEMENT_APP(WidgetsApp)
273
32b8ec41
VZ
274// ----------------------------------------------------------------------------
275// event tables
276// ----------------------------------------------------------------------------
277
278BEGIN_EVENT_TABLE(WidgetsFrame, wxFrame)
49abcb2f 279#if USE_LOG
32b8ec41 280 EVT_BUTTON(Widgets_ClearLog, WidgetsFrame::OnButtonClearLog)
49abcb2f 281#endif // USE_LOG
195df7a7
VZ
282 EVT_BUTTON(Widgets_Quit, WidgetsFrame::OnExit)
283
1c01dd16
VZ
284#if wxUSE_TOOLTIPS
285 EVT_MENU(Widgets_SetTooltip, WidgetsFrame::OnSetTooltip)
286#endif // wxUSE_TOOLTIPS
287
3700e21b 288#if wxUSE_MENUS
3e859739 289 EVT_WIDGETS_PAGE_CHANGING(wxID_ANY, WidgetsFrame::OnPageChanging)
3700e21b
VZ
290 EVT_MENU_RANGE(Widgets_GoToPage, Widgets_GoToPageLast,
291 WidgetsFrame::OnGoToPage)
292
195df7a7
VZ
293 EVT_MENU(Widgets_SetFgColour, WidgetsFrame::OnSetFgCol)
294 EVT_MENU(Widgets_SetBgColour, WidgetsFrame::OnSetBgCol)
ebfee179 295 EVT_MENU(Widgets_SetPageBg, WidgetsFrame::OnSetPageBg)
822b9009 296 EVT_MENU(Widgets_SetFont, WidgetsFrame::OnSetFont)
a17c1df4 297 EVT_MENU(Widgets_Enable, WidgetsFrame::OnEnable)
1c01dd16 298
1301e228
VZ
299 EVT_MENU_RANGE(Widgets_BorderNone, Widgets_BorderDefault,
300 WidgetsFrame::OnSetBorder)
301
e32bcef6
VZ
302 EVT_MENU(Widgets_GlobalBusyCursor, WidgetsFrame::OnToggleGlobalBusyCursor)
303 EVT_MENU(Widgets_BusyCursor, WidgetsFrame::OnToggleBusyCursor)
304
6a8d7937
VZ
305 EVT_MENU(TextEntry_DisableAutoComplete, WidgetsFrame::OnDisableAutoComplete)
306 EVT_MENU(TextEntry_AutoCompleteFixed, WidgetsFrame::OnAutoCompleteFixed)
307 EVT_MENU(TextEntry_AutoCompleteFilenames, WidgetsFrame::OnAutoCompleteFilenames)
03dede4d 308 EVT_MENU(TextEntry_AutoCompleteDirectories, WidgetsFrame::OnAutoCompleteDirectories)
ea98f11c 309 EVT_MENU(TextEntry_AutoCompleteCustom, WidgetsFrame::OnAutoCompleteCustom)
6a8d7937 310
63f7d502
VZ
311 EVT_MENU(TextEntry_SetHint, WidgetsFrame::OnSetHint)
312
6a8d7937
VZ
313 EVT_UPDATE_UI_RANGE(TextEntry_Begin, TextEntry_End - 1,
314 WidgetsFrame::OnUpdateTextUI)
315
1c01dd16 316 EVT_MENU(wxID_EXIT, WidgetsFrame::OnExit)
3700e21b 317#endif // wxUSE_MENUS
32b8ec41
VZ
318END_EVENT_TABLE()
319
320// ============================================================================
321// implementation
322// ============================================================================
323
324// ----------------------------------------------------------------------------
325// app class
326// ----------------------------------------------------------------------------
327
328bool WidgetsApp::OnInit()
329{
bf188f1a 330 if ( !wxApp::OnInit() )
206d3a16 331 return false;
1bdd1007 332
0fa541e8
VZ
333 SetVendorName("wxWidgets_Samples");
334
32b8ec41
VZ
335 // the reason for having these ifdef's is that I often run two copies of
336 // this sample side by side and it is useful to see which one is which
24e78d27 337 wxString title;
32b8ec41 338#if defined(__WXUNIVERSAL__)
9a83f860 339 title = wxT("wxUniv/");
24e78d27
VZ
340#endif
341
342#if defined(__WXMSW__)
9a83f860 343 title += wxT("wxMSW");
32b8ec41 344#elif defined(__WXGTK__)
9a83f860 345 title += wxT("wxGTK");
0f9390c3 346#elif defined(__WXMAC__)
9a83f860 347 title += wxT("wxMAC");
0f9390c3 348#elif defined(__WXMOTIF__)
9a83f860 349 title += wxT("wxMOTIF");
0e9eb80c 350#elif defined(__WXPALMOS5__)
9a83f860 351 title += wxT("wxPALMOS5");
0e9eb80c 352#elif defined(__WXPALMOS6__)
9a83f860 353 title += wxT("wxPALMOS6");
32b8ec41 354#else
9a83f860 355 title += wxT("wxWidgets");
32b8ec41 356#endif
32b8ec41 357
9a83f860 358 wxFrame *frame = new WidgetsFrame(title + wxT(" widgets demo"));
32b8ec41
VZ
359 frame->Show();
360
206d3a16 361 return true;
32b8ec41
VZ
362}
363
364// ----------------------------------------------------------------------------
365// WidgetsFrame construction
366// ----------------------------------------------------------------------------
367
368WidgetsFrame::WidgetsFrame(const wxString& title)
1e3fc113 369 : wxFrame(NULL, wxID_ANY, title)
32b8ec41 370{
679ab0b3 371 const bool sizeSet = wxPersistentRegisterAndRestore(this, "Main");
0fa541e8 372
f2fdc4d5
WS
373 // set the frame icon
374 SetIcon(wxICON(sample));
375
32b8ec41 376 // init everything
49abcb2f 377#if USE_LOG
0fa541e8
VZ
378 m_lboxLog = NULL;
379 m_logTarget = NULL;
49abcb2f 380#endif // USE_LOG
0fa541e8 381 m_book = NULL;
32b8ec41 382
195df7a7
VZ
383#if wxUSE_MENUS
384 // create the menubar
385 wxMenuBar *mbar = new wxMenuBar;
386 wxMenu *menuWidget = new wxMenu;
1c01dd16 387#if wxUSE_TOOLTIPS
9a83f860 388 menuWidget->Append(Widgets_SetTooltip, wxT("Set &tooltip...\tCtrl-T"));
1c01dd16
VZ
389 menuWidget->AppendSeparator();
390#endif // wxUSE_TOOLTIPS
9a83f860
VZ
391 menuWidget->Append(Widgets_SetFgColour, wxT("Set &foreground...\tCtrl-F"));
392 menuWidget->Append(Widgets_SetBgColour, wxT("Set &background...\tCtrl-B"));
ebfee179 393 menuWidget->Append(Widgets_SetPageBg, wxT("Set &page background...\tShift-Ctrl-B"));
9a83f860
VZ
394 menuWidget->Append(Widgets_SetFont, wxT("Set f&ont...\tCtrl-O"));
395 menuWidget->AppendCheckItem(Widgets_Enable, wxT("&Enable/disable\tCtrl-E"));
1301e228
VZ
396
397 wxMenu *menuBorders = new wxMenu;
9a83f860
VZ
398 menuBorders->AppendRadioItem(Widgets_BorderDefault, wxT("De&fault\tCtrl-Shift-9"));
399 menuBorders->AppendRadioItem(Widgets_BorderNone, wxT("&None\tCtrl-Shift-0"));
400 menuBorders->AppendRadioItem(Widgets_BorderSimple, wxT("&Simple\tCtrl-Shift-1"));
401 menuBorders->AppendRadioItem(Widgets_BorderDouble, wxT("&Double\tCtrl-Shift-2"));
402 menuBorders->AppendRadioItem(Widgets_BorderStatic, wxT("Stati&c\tCtrl-Shift-3"));
403 menuBorders->AppendRadioItem(Widgets_BorderRaised, wxT("&Raised\tCtrl-Shift-4"));
404 menuBorders->AppendRadioItem(Widgets_BorderSunken, wxT("S&unken\tCtrl-Shift-5"));
405 menuWidget->AppendSubMenu(menuBorders, wxT("Set &border"));
1301e228 406
e32bcef6
VZ
407 menuWidget->AppendSeparator();
408 menuWidget->AppendCheckItem(Widgets_GlobalBusyCursor,
9a83f860 409 wxT("Toggle &global busy cursor\tCtrl-Shift-U"));
e32bcef6 410 menuWidget->AppendCheckItem(Widgets_BusyCursor,
9a83f860 411 wxT("Toggle b&usy cursor\tCtrl-U"));
e32bcef6 412
195df7a7 413 menuWidget->AppendSeparator();
9a83f860
VZ
414 menuWidget->Append(wxID_EXIT, wxT("&Quit\tCtrl-Q"));
415 mbar->Append(menuWidget, wxT("&Widget"));
6a8d7937
VZ
416
417 wxMenu *menuTextEntry = new wxMenu;
418 menuTextEntry->AppendRadioItem(TextEntry_DisableAutoComplete,
9a83f860 419 wxT("&Disable auto-completion"));
6a8d7937 420 menuTextEntry->AppendRadioItem(TextEntry_AutoCompleteFixed,
9a83f860 421 wxT("Fixed-&list auto-completion"));
6a8d7937 422 menuTextEntry->AppendRadioItem(TextEntry_AutoCompleteFilenames,
9a83f860 423 wxT("&Files names auto-completion"));
03dede4d
VZ
424 menuTextEntry->AppendRadioItem(TextEntry_AutoCompleteDirectories,
425 wxT("&Directories names auto-completion"));
ea98f11c
VZ
426 menuTextEntry->AppendRadioItem(TextEntry_AutoCompleteCustom,
427 wxT("&Custom auto-completion"));
63f7d502
VZ
428 menuTextEntry->AppendSeparator();
429 menuTextEntry->Append(TextEntry_SetHint, "Set help &hint");
6a8d7937 430
9a83f860 431 mbar->Append(menuTextEntry, wxT("&Text"));
6a8d7937 432
195df7a7 433 SetMenuBar(mbar);
a17c1df4
VZ
434
435 mbar->Check(Widgets_Enable, true);
195df7a7
VZ
436#endif // wxUSE_MENUS
437
32b8ec41 438 // create controls
1e3fc113 439 m_panel = new wxPanel(this, wxID_ANY);
32b8ec41
VZ
440
441 wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
442
25057aba 443 // we have 2 panes: book with pages demonstrating the controls in the
32b8ec41 444 // upper one and the log window with some buttons in the lower
1bdd1007 445
1e3fc113 446 int style = wxBK_DEFAULT;
25057aba 447 // Uncomment to suppress page theme (draw in solid colour)
8c9f8f91 448 //style |= wxNB_NOPAGETHEME;
32b8ec41 449
0fa541e8
VZ
450 m_book = new WidgetsBookCtrl(m_panel, Widgets_BookCtrl,
451 wxDefaultPosition, wxDefaultSize,
452 style, "Widgets");
453
61c083e7 454 InitBook();
32b8ec41 455
261357eb 456#ifndef __WXHANDHELD__
32b8ec41 457 // the lower one only has the log listbox and a button to clear it
49abcb2f 458#if USE_LOG
206d3a16 459 wxSizer *sizerDown = new wxStaticBoxSizer(
9a83f860 460 new wxStaticBox( m_panel, wxID_ANY, wxT("&Log window") ),
206d3a16
JS
461 wxVERTICAL);
462
463 m_lboxLog = new wxListBox(m_panel, wxID_ANY);
32b8ec41 464 sizerDown->Add(m_lboxLog, 1, wxGROW | wxALL, 5);
7b127900 465 sizerDown->SetMinSize(100, 150);
b29903d4
WS
466#else
467 wxSizer *sizerDown = new wxBoxSizer(wxVERTICAL);
49abcb2f 468#endif // USE_LOG
88633ca7 469
32b8ec41 470 wxBoxSizer *sizerBtns = new wxBoxSizer(wxHORIZONTAL);
b29903d4 471 wxButton *btn;
49abcb2f 472#if USE_LOG
9a83f860 473 btn = new wxButton(m_panel, Widgets_ClearLog, wxT("Clear &log"));
32b8ec41
VZ
474 sizerBtns->Add(btn);
475 sizerBtns->Add(10, 0); // spacer
49abcb2f 476#endif // USE_LOG
9a83f860 477 btn = new wxButton(m_panel, Widgets_Quit, wxT("E&xit"));
32b8ec41
VZ
478 sizerBtns->Add(btn);
479 sizerDown->Add(sizerBtns, 0, wxALL | wxALIGN_RIGHT, 5);
480
481 // put everything together
61c083e7 482 sizerTop->Add(m_book, 1, wxGROW | (wxALL & ~(wxTOP | wxBOTTOM)), 10);
32b8ec41
VZ
483 sizerTop->Add(0, 5, 0, wxGROW); // spacer in between
484 sizerTop->Add(sizerDown, 0, wxGROW | (wxALL & ~wxTOP), 10);
485
261357eb 486#else // !__WXHANDHELD__/__WXHANDHELD__
49abcb2f
WS
487
488 sizerTop->Add(m_book, 1, wxGROW | wxALL );
489
261357eb 490#endif // __WXHANDHELD__
49abcb2f 491
32b8ec41
VZ
492 m_panel->SetSizer(sizerTop);
493
0fa541e8
VZ
494 const wxSize sizeMin = m_panel->GetBestSize();
495 if ( !sizeSet )
496 SetClientSize(sizeMin);
497 SetMinClientSize(sizeMin);
32b8ec41 498
49abcb2f 499#if USE_LOG && !defined(__WXCOCOA__)
7bb70733 500 // wxCocoa's listbox is too flakey to use for logging right now
32b8ec41
VZ
501 // now that everything is created we can redirect the log messages to the
502 // listbox
503 m_logTarget = new LboxLogger(m_lboxLog, wxLog::GetActiveTarget());
504 wxLog::SetActiveTarget(m_logTarget);
b29903d4 505#endif
32b8ec41
VZ
506}
507
61c083e7 508void WidgetsFrame::InitBook()
32b8ec41 509{
261357eb 510#if USE_ICONS_IN_BOOK
993b016d 511 wxImageList *imageList = new wxImageList(ICON_SIZE, ICON_SIZE);
32b8ec41 512
993b016d
VZ
513 wxImage img(sample_xpm);
514 imageList->Add(wxBitmap(img.Scale(ICON_SIZE, ICON_SIZE)));
261357eb
WS
515#else
516 wxImageList *imageList = NULL;
517#endif
f2fdc4d5
WS
518
519#if !USE_TREEBOOK
520 WidgetsBookCtrl *books[MAX_PAGES];
521#endif
522
523 ArrayWidgetsPage pages[MAX_PAGES];
524 wxArrayString labels[MAX_PAGES];
32b8ec41 525
3700e21b 526 wxMenu *menuPages = new wxMenu;
f2fdc4d5
WS
527 unsigned int nPage = 0, nFKey = 0;
528 int cat, imageId = 1;
3700e21b 529
61c083e7 530 // we need to first create all pages and only then add them to the book
32b8ec41 531 // as we need the image list first
3700e21b
VZ
532 //
533 // we also construct the pages menu during this first iteration
f2fdc4d5 534 for ( cat = 0; cat < MAX_PAGES; cat++ )
32b8ec41 535 {
f2fdc4d5
WS
536#if USE_TREEBOOK
537 nPage++; // increase for parent page
538#else
261357eb
WS
539 books[cat] = new WidgetsBookCtrl(m_book,
540 wxID_ANY,
541 wxDefaultPosition,
542 wxDefaultSize,
895cc205 543 wxBK_DEFAULT);
f2fdc4d5
WS
544#endif
545
546 for ( WidgetsPageInfo *info = WidgetsPage::ms_widgetPages;
547 info;
548 info = info->GetNext() )
549 {
550 if( (info->GetCategories() & ( 1 << cat )) == 0)
551 continue;
552
553 WidgetsPage *page = (*info->GetCtor())(
554#if USE_TREEBOOK
555 m_book
556#else
557 books[cat]
558#endif
559 , imageList);
560 pages[cat].Add(page);
561
562 labels[cat].Add(info->GetLabel());
563 if ( cat == ALL_PAGE )
564 {
565 wxString radioLabel(info->GetLabel());
566 nFKey++;
567 if ( nFKey <= 12 )
568 {
569 radioLabel << wxT("\tF" ) << nFKey;
570 }
571
572 menuPages->AppendRadioItem(
573 Widgets_GoToPage + nPage,
574 radioLabel
575 );
576#if !USE_TREEBOOK
577 // consider only for book in book architecture
578 nPage++;
579#endif
580 }
581
582#if USE_TREEBOOK
583 // consider only for treebook architecture (with subpages)
584 nPage++;
585#endif
586 }
32b8ec41
VZ
587 }
588
9a83f860 589 GetMenuBar()->Append(menuPages, wxT("&Page"));
3700e21b 590
261357eb 591#if USE_ICONS_IN_BOOK
f2fdc4d5 592 m_book->AssignImageList(imageList);
261357eb 593#endif
32b8ec41 594
f2fdc4d5 595 for ( cat = 0; cat < MAX_PAGES; cat++ )
32b8ec41 596 {
f2fdc4d5
WS
597#if USE_TREEBOOK
598 m_book->AddPage(NULL,WidgetsCategories[cat],false,0);
599#else
600 m_book->AddPage(books[cat],WidgetsCategories[cat],false,0);
261357eb 601#if USE_ICONS_IN_BOOK
f2fdc4d5 602 books[cat]->SetImageList(imageList);
261357eb 603#endif
f2fdc4d5
WS
604#endif
605
606 // now do add them
607 size_t count = pages[cat].GetCount();
608 for ( size_t n = 0; n < count; n++ )
609 {
610#if USE_TREEBOOK
3e859739 611 m_book->AddSubPage
f2fdc4d5 612#else
3e859739 613 books[cat]->AddPage
f2fdc4d5 614#endif
3e859739 615 (
f2fdc4d5
WS
616 pages[cat][n],
617 labels[cat][n],
618 false, // don't select
619 imageId++
620 );
621 }
32b8ec41 622 }
f2fdc4d5 623
0cebbfc2
WS
624 Connect( wxID_ANY,
625 wxEVT_COMMAND_WIDGETS_PAGE_CHANGED,
626 wxWidgetsbookEventHandler(WidgetsFrame::OnPageChanged) );
627
77cc73a7 628 const bool pageSet = wxPersistentRegisterAndRestore(m_book);
0fa541e8 629
f2fdc4d5 630#if USE_TREEBOOK
3e859739
VZ
631 // for treebook page #0 is empty parent page only so select the first page
632 // with some contents
0fa541e8
VZ
633 if ( !pageSet )
634 m_book->SetSelection(1);
3e859739
VZ
635
636 // but ensure that the top of the tree is shown nevertheless
637 wxTreeCtrl * const tree = m_book->GetTreeCtrl();
23c2b62b
VZ
638
639 wxTreeItemIdValue cookie;
640 tree->EnsureVisible(tree->GetFirstChild(tree->GetRootItem(), cookie));
0cebbfc2 641#else
0fa541e8
VZ
642 if ( !pageSet )
643 {
644 // for other books set selection twice to force connected event handler
645 // to force lazy creation of initial visible content
646 m_book->SetSelection(1);
647 m_book->SetSelection(0);
648 }
3e859739 649#endif // USE_TREEBOOK
f2fdc4d5
WS
650}
651
652WidgetsPage *WidgetsFrame::CurrentPage()
653{
453535a7 654 wxWindow *page = m_book->GetCurrentPage();
453535a7 655
3e859739 656#if !USE_TREEBOOK
453535a7 657 WidgetsBookCtrl *subBook = wxStaticCast(page, WidgetsBookCtrl);
9a83f860 658 wxCHECK_MSG( subBook, NULL, wxT("no WidgetsBookCtrl?") );
3e859739 659
453535a7 660 page = subBook->GetCurrentPage();
3e859739
VZ
661#endif // !USE_TREEBOOK
662
453535a7 663 return wxStaticCast(page, WidgetsPage);
32b8ec41
VZ
664}
665
666WidgetsFrame::~WidgetsFrame()
667{
49abcb2f 668#if USE_LOG
32b8ec41 669 delete m_logTarget;
49abcb2f 670#endif // USE_LOG
32b8ec41
VZ
671}
672
673// ----------------------------------------------------------------------------
674// WidgetsFrame event handlers
675// ----------------------------------------------------------------------------
676
195df7a7 677void WidgetsFrame::OnExit(wxCommandEvent& WXUNUSED(event))
32b8ec41
VZ
678{
679 Close();
680}
681
49abcb2f 682#if USE_LOG
c02e5a31 683void WidgetsFrame::OnButtonClearLog(wxCommandEvent& WXUNUSED(event))
32b8ec41
VZ
684{
685 m_lboxLog->Clear();
686}
49abcb2f 687#endif // USE_LOG
32b8ec41 688
195df7a7
VZ
689#if wxUSE_MENUS
690
3e859739
VZ
691void WidgetsFrame::OnPageChanging(WidgetsBookCtrlEvent& event)
692{
0cebbfc2
WS
693#if USE_TREEBOOK
694 // don't allow selection of entries without pages (categories)
3e859739
VZ
695 if ( !m_book->GetPage(event.GetSelection()) )
696 event.Veto();
b2b98dfd
WS
697#else
698 wxUnusedVar(event);
0cebbfc2 699#endif
3e859739
VZ
700}
701
f2fdc4d5 702void WidgetsFrame::OnPageChanged(WidgetsBookCtrlEvent& event)
3700e21b 703{
3e859739
VZ
704 const int sel = event.GetSelection();
705
453535a7 706 // adjust "Page" menu selection
3e859739
VZ
707 wxMenuItem *item = GetMenuBar()->FindItem(Widgets_GoToPage + sel);
708 if ( item )
709 item->Check();
453535a7 710
fe24a945
VZ
711 GetMenuBar()->Check(Widgets_BusyCursor, false);
712
be16b859
VZ
713 // create the pages on demand, otherwise the sample startup is too slow as
714 // it creates hundreds of controls
3e859739
VZ
715 WidgetsPage *page = CurrentPage();
716 if ( page->GetChildren().empty() )
453535a7
WS
717 {
718 wxWindowUpdateLocker noUpdates(page);
719 page->CreateContent();
be16b859
VZ
720 //page->Layout();
721 page->GetSizer()->Fit(page);
722
453535a7
WS
723 WidgetsBookCtrl *book = wxStaticCast(page->GetParent(), WidgetsBookCtrl);
724 wxSize size;
725 for ( size_t i = 0; i < book->GetPageCount(); ++i )
726 {
727 wxWindow *page = book->GetPage(i);
3e859739 728 if ( page )
453535a7
WS
729 {
730 size.IncTo(page->GetSize());
731 }
732 }
733 page->SetSize(size);
734 }
735
3700e21b
VZ
736 event.Skip();
737}
738
739void WidgetsFrame::OnGoToPage(wxCommandEvent& event)
740{
f2fdc4d5 741#if USE_TREEBOOK
3700e21b 742 m_book->SetSelection(event.GetId() - Widgets_GoToPage);
f2fdc4d5
WS
743#else
744 m_book->SetSelection(m_book->GetPageCount()-1);
745 WidgetsBookCtrl *book = wxStaticCast(m_book->GetCurrentPage(), WidgetsBookCtrl);
746 book->SetSelection(event.GetId() - Widgets_GoToPage);
747#endif
3700e21b
VZ
748}
749
1c01dd16
VZ
750#if wxUSE_TOOLTIPS
751
752void WidgetsFrame::OnSetTooltip(wxCommandEvent& WXUNUSED(event))
753{
9a83f860 754 static wxString s_tip = wxT("This is a tooltip");
1c01dd16 755
60c84f85
VZ
756 wxTextEntryDialog dialog
757 (
758 this,
9a83f860
VZ
759 wxT("Tooltip text (may use \\n, leave empty to remove): "),
760 wxT("Widgets sample"),
60c84f85
VZ
761 s_tip
762 );
763
764 if ( dialog.ShowModal() != wxID_OK )
1c01dd16
VZ
765 return;
766
60c84f85 767 s_tip = dialog.GetValue();
9a83f860 768 s_tip.Replace(wxT("\\n"), wxT("\n"));
bd018e7e 769
3e859739
VZ
770 WidgetsPage *page = CurrentPage();
771
ca288f2a
VZ
772 const Widgets widgets = page->GetWidgets();
773 for ( Widgets::const_iterator it = widgets.begin();
774 it != widgets.end();
775 ++it )
776 {
777 (*it)->SetToolTip(s_tip);
778 }
1c01dd16
VZ
779}
780
781#endif // wxUSE_TOOLTIPS
782
ebfee179
VZ
783namespace
784{
785
786// Trivial wrapper for wxGetColourFromUser() which also does something even if
787// the colour dialog is not available in the current build (which may happen
788// for the ports in development and it is still useful to see how colours work)
789wxColour GetColourFromUser(wxWindow *parent, const wxColour& colDefault)
195df7a7 790{
923f4e79 791#if wxUSE_COLOURDLG
ebfee179
VZ
792 return wxGetColourFromUser(parent, colDefault);
793#else // !wxUSE_COLOURDLG
794 if ( colDefault == *wxBLACK )
795 return *wxWHITE;
796 else
797 return *wxBLACK;
798#endif // wxUSE_COLOURDLG/!wxUSE_COLOURDLG
799}
800
801} // anonymous namespace
802
803void WidgetsFrame::OnSetFgCol(wxCommandEvent& WXUNUSED(event))
804{
822b9009 805 // allow for debugging the default colour the first time this is called
f2fdc4d5 806 WidgetsPage *page = CurrentPage();
63da71ba 807
a1b806b9 808 if (!m_colFg.IsOk())
822b9009
VZ
809 m_colFg = page->GetForegroundColour();
810
ebfee179 811 wxColour col = GetColourFromUser(this, m_colFg);
a1b806b9 812 if ( !col.IsOk() )
195df7a7
VZ
813 return;
814
815 m_colFg = col;
816
ca288f2a
VZ
817 const Widgets widgets = page->GetWidgets();
818 for ( Widgets::const_iterator it = widgets.begin();
819 it != widgets.end();
820 ++it )
1c01dd16 821 {
ca288f2a
VZ
822 (*it)->SetForegroundColour(m_colFg);
823 (*it)->Refresh();
1c01dd16 824 }
195df7a7
VZ
825}
826
827void WidgetsFrame::OnSetBgCol(wxCommandEvent& WXUNUSED(event))
828{
f2fdc4d5 829 WidgetsPage *page = CurrentPage();
63da71ba 830
a1b806b9 831 if ( !m_colBg.IsOk() )
822b9009
VZ
832 m_colBg = page->GetBackgroundColour();
833
ebfee179 834 wxColour col = GetColourFromUser(this, m_colBg);
a1b806b9 835 if ( !col.IsOk() )
195df7a7
VZ
836 return;
837
838 m_colBg = col;
839
ca288f2a
VZ
840 const Widgets widgets = page->GetWidgets();
841 for ( Widgets::const_iterator it = widgets.begin();
842 it != widgets.end();
843 ++it )
1c01dd16 844 {
ca288f2a
VZ
845 (*it)->SetBackgroundColour(m_colBg);
846 (*it)->Refresh();
1c01dd16 847 }
ebfee179
VZ
848}
849
850void WidgetsFrame::OnSetPageBg(wxCommandEvent& WXUNUSED(event))
851{
852 wxColour col = GetColourFromUser(this, GetBackgroundColour());
a1b806b9 853 if ( !col.IsOk() )
ebfee179
VZ
854 return;
855
856 CurrentPage()->SetBackgroundColour(col);
857 CurrentPage()->Refresh();
195df7a7
VZ
858}
859
822b9009
VZ
860void WidgetsFrame::OnSetFont(wxCommandEvent& WXUNUSED(event))
861{
862#if wxUSE_FONTDLG
f2fdc4d5 863 WidgetsPage *page = CurrentPage();
63da71ba 864
a1b806b9 865 if (!m_font.IsOk())
822b9009
VZ
866 m_font = page->GetFont();
867
868 wxFont font = wxGetFontFromUser(this, m_font);
a1b806b9 869 if ( !font.IsOk() )
822b9009
VZ
870 return;
871
872 m_font = font;
873
ca288f2a
VZ
874 const Widgets widgets = page->GetWidgets();
875 for ( Widgets::const_iterator it = widgets.begin();
876 it != widgets.end();
877 ++it )
822b9009 878 {
ca288f2a
VZ
879 (*it)->SetFont(m_font);
880 (*it)->Refresh();
822b9009
VZ
881 }
882#else
9a83f860 883 wxLogMessage(wxT("Font selection dialog not available in current build."));
822b9009
VZ
884#endif
885}
886
a17c1df4
VZ
887void WidgetsFrame::OnEnable(wxCommandEvent& event)
888{
ca288f2a
VZ
889 const Widgets widgets = CurrentPage()->GetWidgets();
890 for ( Widgets::const_iterator it = widgets.begin();
891 it != widgets.end();
892 ++it )
893 {
894 (*it)->Enable(event.IsChecked());
895 }
a17c1df4
VZ
896}
897
1301e228
VZ
898void WidgetsFrame::OnSetBorder(wxCommandEvent& event)
899{
900 int border;
901 switch ( event.GetId() )
902 {
903 case Widgets_BorderNone: border = wxBORDER_NONE; break;
904 case Widgets_BorderStatic: border = wxBORDER_STATIC; break;
905 case Widgets_BorderSimple: border = wxBORDER_SIMPLE; break;
906 case Widgets_BorderRaised: border = wxBORDER_RAISED; break;
907 case Widgets_BorderSunken: border = wxBORDER_SUNKEN; break;
908 case Widgets_BorderDouble: border = wxBORDER_DOUBLE; break;
909
910 default:
9a83f860 911 wxFAIL_MSG( wxT("unknown border style") );
1301e228
VZ
912 // fall through
913
914 case Widgets_BorderDefault: border = wxBORDER_DEFAULT; break;
915 }
916
917 WidgetsPage::ms_defaultFlags &= ~wxBORDER_MASK;
918 WidgetsPage::ms_defaultFlags |= border;
919
f2fdc4d5 920 WidgetsPage *page = CurrentPage();
63da71ba 921
1301e228
VZ
922 page->RecreateWidget();
923}
924
e32bcef6
VZ
925void WidgetsFrame::OnToggleGlobalBusyCursor(wxCommandEvent& event)
926{
927 if ( event.IsChecked() )
928 wxBeginBusyCursor();
929 else
930 wxEndBusyCursor();
931}
932
933void WidgetsFrame::OnToggleBusyCursor(wxCommandEvent& event)
934{
ca288f2a
VZ
935 wxCursor cursor(*(event.IsChecked() ? wxHOURGLASS_CURSOR
936 : wxSTANDARD_CURSOR));
937
938 const Widgets widgets = CurrentPage()->GetWidgets();
939 for ( Widgets::const_iterator it = widgets.begin();
940 it != widgets.end();
941 ++it )
942 {
943 (*it)->SetCursor(cursor);
944 }
e32bcef6
VZ
945}
946
6a8d7937
VZ
947void WidgetsFrame::OnDisableAutoComplete(wxCommandEvent& WXUNUSED(event))
948{
949 wxTextEntryBase *entry = CurrentPage()->GetTextEntry();
950 wxCHECK_RET( entry, "menu item should be disabled" );
951
952 if ( entry->AutoComplete(wxArrayString()) )
43b2d5e7 953 {
6a8d7937 954 wxLogMessage("Disabled auto completion.");
43b2d5e7 955 }
6a8d7937 956 else
43b2d5e7 957 {
6a8d7937 958 wxLogMessage("AutoComplete() failed.");
43b2d5e7 959 }
6a8d7937
VZ
960}
961
962void WidgetsFrame::OnAutoCompleteFixed(wxCommandEvent& WXUNUSED(event))
963{
964 wxTextEntryBase *entry = CurrentPage()->GetTextEntry();
965 wxCHECK_RET( entry, "menu item should be disabled" );
966
967 wxArrayString completion_choices;
968
969 // add a few strings so a completion occurs on any letter typed
970 for ( char idxc = 'a'; idxc < 'z'; ++idxc )
971 completion_choices.push_back(wxString::Format("%c%c", idxc, idxc));
972
973 completion_choices.push_back("is this string for test?");
974 completion_choices.push_back("this is a test string");
975 completion_choices.push_back("this is another test string");
976 completion_choices.push_back("this string is for test");
977
978 if ( entry->AutoComplete(completion_choices) )
43b2d5e7 979 {
6a8d7937 980 wxLogMessage("Enabled auto completion of a set of fixed strings.");
43b2d5e7 981 }
6a8d7937 982 else
43b2d5e7 983 {
6a8d7937 984 wxLogMessage("AutoComplete() failed.");
43b2d5e7 985 }
6a8d7937
VZ
986}
987
988void WidgetsFrame::OnAutoCompleteFilenames(wxCommandEvent& WXUNUSED(event))
989{
990 wxTextEntryBase *entry = CurrentPage()->GetTextEntry();
991 wxCHECK_RET( entry, "menu item should be disabled" );
992
993 if ( entry->AutoCompleteFileNames() )
43b2d5e7 994 {
ea98f11c 995 wxLogMessage("Enabled auto completion of file names.");
43b2d5e7 996 }
6a8d7937 997 else
43b2d5e7 998 {
6a8d7937 999 wxLogMessage("AutoCompleteFileNames() failed.");
43b2d5e7 1000 }
6a8d7937
VZ
1001}
1002
03dede4d
VZ
1003void WidgetsFrame::OnAutoCompleteDirectories(wxCommandEvent& WXUNUSED(event))
1004{
1005 wxTextEntryBase *entry = CurrentPage()->GetTextEntry();
1006 wxCHECK_RET( entry, "menu item should be disabled" );
1007
1008 if ( entry->AutoCompleteDirectories() )
1009 {
1010 wxLogMessage("Enabled auto completion of directories.");
1011 }
1012 else
1013 {
1014 wxLogMessage("AutoCompleteDirectories() failed.");
1015 }
1016}
1017
ea98f11c
VZ
1018void WidgetsFrame::OnAutoCompleteCustom(wxCommandEvent& WXUNUSED(event))
1019{
1020 wxTextEntryBase *entry = CurrentPage()->GetTextEntry();
1021 wxCHECK_RET( entry, "menu item should be disabled" );
1022
1023 // This is a simple (and hence rather useless) example of a custom
1024 // completer class that completes the first word (only) initially and only
1025 // build the list of the possible second words once the first word is
1026 // known. This allows to avoid building the full 676000 item list of
1027 // possible strings all at once as the we have 1000 possibilities for the
1028 // first word (000..999) and 676 (aa..zz) for the second one.
85047589 1029 class CustomTextCompleter : public wxTextCompleterSimple
ea98f11c
VZ
1030 {
1031 public:
1032 virtual void GetCompletions(const wxString& prefix, wxArrayString& res)
1033 {
1034 // This is used for illustrative purposes only and shows how many
1035 // completions we return every time when we're called.
1036 class LogCompletions
1037 {
1038 public:
1039 LogCompletions(const wxString& prefix, const wxArrayString& res)
1040 : m_prefix(prefix),
1041 m_res(res)
1042 {
1043 }
1044
1045 ~LogCompletions()
1046 {
1047 wxLogMessage("Returning %lu possible completions for "
1048 "prefix \"%s\"",
1049 m_res.size(), m_prefix);
1050 }
1051
1052 private:
1053 const wxString& m_prefix;
1054 const wxArrayString& m_res;
1055 } logCompletions(prefix, res);
1056
1057
1058 // Normally it doesn't make sense to complete empty control, there
1059 // are too many choices and listing them all wouldn't be helpful.
1060 if ( prefix.empty() )
1061 return;
1062
1063 // The only valid strings start with 3 digits so check for their
1064 // presence proposing to complete the remaining ones.
1065 if ( !wxIsdigit(prefix[0]) )
1066 return;
1067
1068 if ( prefix.length() == 1 )
1069 {
1070 for ( int i = 0; i < 10; i++ )
1071 for ( int j = 0; j < 10; j++ )
1072 res.push_back(wxString::Format("%s%02d",
1073 prefix, 10*i + j));
1074 return;
1075 }
1076 else if ( !wxIsdigit(prefix[1]) )
1077 return;
1078
1079 if ( prefix.length() == 2 )
1080 {
1081 for ( int i = 0; i < 10; i++ )
1082 res.push_back(wxString::Format("%s%d", prefix, i));
1083 return;
1084 }
1085 else if ( !wxIsdigit(prefix[2]) )
1086 return;
1087
1088 // Next we must have a space and two letters.
1089 wxString prefix2(prefix);
1090 if ( prefix.length() == 3 )
1091 prefix2 += ' ';
1092 else if ( prefix[3] != ' ' )
1093 return;
1094
1095 if ( prefix2.length() == 4 )
1096 {
1097 for ( char c = 'a'; c <= 'z'; c++ )
1098 for ( char d = 'a'; d <= 'z'; d++ )
1099 res.push_back(wxString::Format("%s%c%c", prefix2, c, d));
1100 return;
1101 }
1102 else if ( !wxIslower(prefix[4]) )
1103 return;
1104
1105 if ( prefix.length() == 5 )
1106 {
1107 for ( char c = 'a'; c <= 'z'; c++ )
1108 res.push_back(prefix + c);
1109 }
1110 }
1111 };
1112
1113 if ( entry->AutoComplete(new CustomTextCompleter) )
1114 {
1115 wxLogMessage("Enabled custom auto completer for \"NNN XX\" items "
1116 "(where N is a digit and X is a letter).");
1117 }
1118 else
1119 {
1120 wxLogMessage("AutoComplete() failed.");
1121 }
1122}
1123
63f7d502
VZ
1124void WidgetsFrame::OnSetHint(wxCommandEvent& WXUNUSED(event))
1125{
1126 wxTextEntryBase *entry = CurrentPage()->GetTextEntry();
1127 wxCHECK_RET( entry, "menu item should be disabled" );
1128
1129 static wxString s_hint("Type here");
1130 wxString
1131 hint = wxGetTextFromUser("Text hint:", "Widgets sample", s_hint, this);
1132 if ( hint.empty() )
1133 return;
1134
1135 s_hint = hint;
1136
1137 if ( entry->SetHint(hint) )
43b2d5e7 1138 {
63f7d502 1139 wxLogMessage("Set hint to \"%s\".", hint);
43b2d5e7 1140 }
63f7d502 1141 else
43b2d5e7 1142 {
63f7d502 1143 wxLogMessage("Text hints not supported.");
43b2d5e7 1144 }
63f7d502
VZ
1145}
1146
195df7a7
VZ
1147#endif // wxUSE_MENUS
1148
32b8ec41
VZ
1149// ----------------------------------------------------------------------------
1150// WidgetsPageInfo
1151// ----------------------------------------------------------------------------
1152
f2fdc4d5 1153WidgetsPageInfo::WidgetsPageInfo(Constructor ctor, const wxChar *label, int categories)
32b8ec41 1154 : m_label(label)
f2fdc4d5 1155 , m_categories(categories)
32b8ec41
VZ
1156{
1157 m_ctor = ctor;
1158
2673bcb0
DS
1159 m_next = NULL;
1160
fdfe568d 1161 // dummy sorting: add and immediately sort in the list according to label
3700e21b 1162 if ( WidgetsPage::ms_widgetPages )
2673bcb0
DS
1163 {
1164 WidgetsPageInfo *node_prev = WidgetsPage::ms_widgetPages;
fdfe568d 1165 if ( wxStrcmp(label, node_prev->GetLabel().c_str()) < 0 )
2673bcb0
DS
1166 {
1167 // add as first
1168 m_next = node_prev;
1169 WidgetsPage::ms_widgetPages = this;
1170 }
1171 else
1172 {
1173 WidgetsPageInfo *node_next;
1174 do
1175 {
1176 node_next = node_prev->GetNext();
fdfe568d 1177 if ( node_next )
2673bcb0
DS
1178 {
1179 // add if between two
fdfe568d 1180 if ( wxStrcmp(label, node_next->GetLabel().c_str()) < 0 )
2673bcb0
DS
1181 {
1182 node_prev->SetNext(this);
1183 m_next = node_next;
1184 // force to break loop
1185 node_next = NULL;
1186 }
1187 }
1188 else
1189 {
1190 // add as last
1191 node_prev->SetNext(this);
1192 m_next = node_next;
1193 }
1194 node_prev = node_next;
fdfe568d
VZ
1195 }
1196 while ( node_next );
2673bcb0
DS
1197 }
1198 }
1199 else
1200 {
1201 // add when first
2673bcb0 1202 WidgetsPage::ms_widgetPages = this;
2673bcb0 1203 }
32b8ec41
VZ
1204}
1205
1206// ----------------------------------------------------------------------------
1207// WidgetsPage
1208// ----------------------------------------------------------------------------
1209
1301e228
VZ
1210int WidgetsPage::ms_defaultFlags = wxBORDER_DEFAULT;
1211WidgetsPageInfo *WidgetsPage::ms_widgetPages = NULL;
1212
261357eb
WS
1213WidgetsPage::WidgetsPage(WidgetsBookCtrl *book,
1214 wxImageList *imaglist,
747d7d7c 1215 const char *const icon[])
61c083e7 1216 : wxPanel(book, wxID_ANY,
df0787b6
VZ
1217 wxDefaultPosition, wxDefaultSize,
1218 wxNO_FULL_REPAINT_ON_RESIZE |
1219 wxCLIP_CHILDREN |
1220 wxTAB_TRAVERSAL)
32b8ec41 1221{
261357eb 1222#if USE_ICONS_IN_BOOK
993b016d 1223 imaglist->Add(wxBitmap(wxImage(icon).Scale(ICON_SIZE, ICON_SIZE)));
261357eb
WS
1224#else
1225 wxUnusedVar(imaglist);
1226 wxUnusedVar(icon);
1227#endif
32b8ec41
VZ
1228}
1229
1230wxSizer *WidgetsPage::CreateSizerWithText(wxControl *control,
1231 wxWindowID id,
1232 wxTextCtrl **ppText)
1233{
1234 wxSizer *sizerRow = new wxBoxSizer(wxHORIZONTAL);
206d3a16
JS
1235 wxTextCtrl *text = new wxTextCtrl(this, id, wxEmptyString,
1236 wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
4589ec39 1237
32b8ec41
VZ
1238 sizerRow->Add(control, 0, wxRIGHT | wxALIGN_CENTRE_VERTICAL, 5);
1239 sizerRow->Add(text, 1, wxLEFT | wxALIGN_CENTRE_VERTICAL, 5);
1240
1241 if ( ppText )
1242 *ppText = text;
1243
1244 return sizerRow;
1245}
1246
1247// create a sizer containing a label and a text ctrl
1248wxSizer *WidgetsPage::CreateSizerWithTextAndLabel(const wxString& label,
1249 wxWindowID id,
1250 wxTextCtrl **ppText)
1251{
206d3a16
JS
1252 return CreateSizerWithText(new wxStaticText(this, wxID_ANY, label),
1253 id, ppText);
32b8ec41
VZ
1254}
1255
1256// create a sizer containing a button and a text ctrl
1257wxSizer *WidgetsPage::CreateSizerWithTextAndButton(wxWindowID idBtn,
1258 const wxString& label,
1259 wxWindowID id,
1260 wxTextCtrl **ppText)
1261{
1262 return CreateSizerWithText(new wxButton(this, idBtn, label), id, ppText);
1263}
1264
1265wxCheckBox *WidgetsPage::CreateCheckBoxAndAddToSizer(wxSizer *sizer,
1266 const wxString& label,
1267 wxWindowID id)
1268{
1269 wxCheckBox *checkbox = new wxCheckBox(this, id, label);
1270 sizer->Add(checkbox, 0, wxLEFT | wxRIGHT, 5);
1271 sizer->Add(0, 2, 0, wxGROW); // spacer
1272
1273 return checkbox;
1274}