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
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"
41 #include "wx/msgdlg.h"
44 #include "wx/sysopt.h"
45 #include "wx/bookctrl.h"
46 #include "wx/treebook.h"
48 #include "wx/colordlg.h"
49 #include "wx/fontdlg.h"
50 #include "wx/textdlg.h"
51 #include "wx/imaglist.h"
52 #include "wx/wupdlock.h"
56 #include "../sample.xpm"
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
65 Widgets_ClearLog
= 100,
72 #endif // wxUSE_TOOLTIPS
84 Widgets_BorderDefault
,
86 Widgets_GlobalBusyCursor
,
90 Widgets_GoToPageLast
= Widgets_GoToPage
+ 100,
94 TextEntry_DisableAutoComplete
= TextEntry_Begin
,
95 TextEntry_AutoCompleteFixed
,
96 TextEntry_AutoCompleteFilenames
,
100 const wxChar
*WidgetsCategories
[MAX_PAGES
] = {
101 #if defined(__WXUNIVERSAL__)
115 // ----------------------------------------------------------------------------
117 // ----------------------------------------------------------------------------
119 // Define a new application type, each program should derive a class from wxApp
120 class WidgetsApp
: public wxApp
123 // override base class virtuals
124 // ----------------------------
126 // this one is called on application startup and is a good place for the app
127 // initialization (doing it here and not in the ctor allows to have an error
128 // return: if OnInit() returns false, the application terminates)
129 virtual bool OnInit();
132 // Define a new frame type: this is going to be our main frame
133 class WidgetsFrame
: public wxFrame
137 WidgetsFrame(const wxString
& title
);
138 virtual ~WidgetsFrame();
143 void OnButtonClearLog(wxCommandEvent
& event
);
145 void OnExit(wxCommandEvent
& event
);
148 void OnPageChanging(WidgetsBookCtrlEvent
& event
);
149 void OnPageChanged(WidgetsBookCtrlEvent
& event
);
150 void OnGoToPage(wxCommandEvent
& event
);
153 void OnSetTooltip(wxCommandEvent
& event
);
154 #endif // wxUSE_TOOLTIPS
155 void OnSetFgCol(wxCommandEvent
& event
);
156 void OnSetBgCol(wxCommandEvent
& event
);
157 void OnSetFont(wxCommandEvent
& event
);
158 void OnEnable(wxCommandEvent
& event
);
159 void OnSetBorder(wxCommandEvent
& event
);
161 void OnToggleGlobalBusyCursor(wxCommandEvent
& event
);
162 void OnToggleBusyCursor(wxCommandEvent
& event
);
164 void OnDisableAutoComplete(wxCommandEvent
& event
);
165 void OnAutoCompleteFixed(wxCommandEvent
& event
);
166 void OnAutoCompleteFilenames(wxCommandEvent
& event
);
168 void OnUpdateTextUI(wxUpdateUIEvent
& event
)
170 event
.Enable( CurrentPage()->GetTextEntry() != NULL
);
172 #endif // wxUSE_MENUS
174 // initialize the book: add all pages to it
177 // return the currently selected page (never NULL)
178 WidgetsPage
*CurrentPage();
181 // the panel containing everything
185 // the listbox for logging messages
186 wxListBox
*m_lboxLog
;
188 // the log target we use to redirect messages to the listbox
192 // the book containing the test pages
193 WidgetsBookCtrl
*m_book
;
196 // last chosen fg/bg colours and font
200 #endif // wxUSE_MENUS
202 // any class wishing to process wxWidgets events must use this macro
203 DECLARE_EVENT_TABLE()
207 // A log target which just redirects the messages to a listbox
208 class LboxLogger
: public wxLog
211 LboxLogger(wxListBox
*lbox
, wxLog
*logOld
)
214 //m_lbox->Disable(); -- looks ugly under MSW
218 virtual ~LboxLogger()
220 wxLog::SetActiveTarget(m_logOld
);
224 // implement sink functions
225 virtual void DoLog(wxLogLevel level
, const wxString
& str
, time_t t
)
227 // don't put trace messages into listbox or we can get into infinite
229 if ( level
== wxLOG_Trace
)
233 // cast is needed to call protected method
234 ((LboxLogger
*)m_logOld
)->DoLog(level
, str
, t
);
239 wxLog::DoLog(level
, str
, t
);
243 virtual void DoLogString(const wxString
& str
, time_t WXUNUSED(t
))
249 #ifdef __WXUNIVERSAL__
250 m_lbox
->AppendAndEnsureVisible(msg
);
251 #else // other ports don't have this method yet
253 m_lbox
->SetFirstItem(m_lbox
->GetCount() - 1);
257 // the control we use
260 // the old log target
266 WX_DEFINE_ARRAY_PTR(WidgetsPage
*, ArrayWidgetsPage
);
268 // ----------------------------------------------------------------------------
270 // ----------------------------------------------------------------------------
272 IMPLEMENT_APP(WidgetsApp
)
274 // ----------------------------------------------------------------------------
276 // ----------------------------------------------------------------------------
278 BEGIN_EVENT_TABLE(WidgetsFrame
, wxFrame
)
280 EVT_BUTTON(Widgets_ClearLog
, WidgetsFrame::OnButtonClearLog
)
282 EVT_BUTTON(Widgets_Quit
, WidgetsFrame::OnExit
)
285 EVT_MENU(Widgets_SetTooltip
, WidgetsFrame::OnSetTooltip
)
286 #endif // wxUSE_TOOLTIPS
289 EVT_WIDGETS_PAGE_CHANGING(wxID_ANY
, WidgetsFrame::OnPageChanging
)
290 EVT_MENU_RANGE(Widgets_GoToPage
, Widgets_GoToPageLast
,
291 WidgetsFrame::OnGoToPage
)
293 EVT_MENU(Widgets_SetFgColour
, WidgetsFrame::OnSetFgCol
)
294 EVT_MENU(Widgets_SetBgColour
, WidgetsFrame::OnSetBgCol
)
295 EVT_MENU(Widgets_SetFont
, WidgetsFrame::OnSetFont
)
296 EVT_MENU(Widgets_Enable
, WidgetsFrame::OnEnable
)
298 EVT_MENU_RANGE(Widgets_BorderNone
, Widgets_BorderDefault
,
299 WidgetsFrame::OnSetBorder
)
301 EVT_MENU(Widgets_GlobalBusyCursor
, WidgetsFrame::OnToggleGlobalBusyCursor
)
302 EVT_MENU(Widgets_BusyCursor
, WidgetsFrame::OnToggleBusyCursor
)
304 EVT_MENU(TextEntry_DisableAutoComplete
, WidgetsFrame::OnDisableAutoComplete
)
305 EVT_MENU(TextEntry_AutoCompleteFixed
, WidgetsFrame::OnAutoCompleteFixed
)
306 EVT_MENU(TextEntry_AutoCompleteFilenames
, WidgetsFrame::OnAutoCompleteFilenames
)
308 EVT_UPDATE_UI_RANGE(TextEntry_Begin
, TextEntry_End
- 1,
309 WidgetsFrame::OnUpdateTextUI
)
311 EVT_MENU(wxID_EXIT
, WidgetsFrame::OnExit
)
312 #endif // wxUSE_MENUS
315 // ============================================================================
317 // ============================================================================
319 // ----------------------------------------------------------------------------
321 // ----------------------------------------------------------------------------
323 bool WidgetsApp::OnInit()
325 if ( !wxApp::OnInit() )
328 // the reason for having these ifdef's is that I often run two copies of
329 // this sample side by side and it is useful to see which one is which
331 #if defined(__WXUNIVERSAL__)
332 title
= _T("wxUniv/");
335 #if defined(__WXMSW__)
336 title
+= _T("wxMSW");
337 #elif defined(__WXGTK__)
338 title
+= _T("wxGTK");
339 #elif defined(__WXMAC__)
340 title
+= _T("wxMAC");
341 #elif defined(__WXMOTIF__)
342 title
+= _T("wxMOTIF");
344 title
+= _T("wxPALMOS5");
346 title
+= _T("wxPALMOS6");
348 title
+= _T("wxWidgets");
351 wxFrame
*frame
= new WidgetsFrame(title
+ _T(" widgets demo"));
354 //wxLog::AddTraceMask(_T("listbox"));
355 //wxLog::AddTraceMask(_T("scrollbar"));
356 //wxLog::AddTraceMask(_T("focus"));
361 // ----------------------------------------------------------------------------
362 // WidgetsFrame construction
363 // ----------------------------------------------------------------------------
365 WidgetsFrame::WidgetsFrame(const wxString
& title
)
366 : wxFrame(NULL
, wxID_ANY
, title
)
368 // set the frame icon
369 SetIcon(wxICON(sample
));
373 m_lboxLog
= (wxListBox
*)NULL
;
374 m_logTarget
= (wxLog
*)NULL
;
376 m_book
= (WidgetsBookCtrl
*)NULL
;
379 // create the menubar
380 wxMenuBar
*mbar
= new wxMenuBar
;
381 wxMenu
*menuWidget
= new wxMenu
;
383 menuWidget
->Append(Widgets_SetTooltip
, _T("Set &tooltip...\tCtrl-T"));
384 menuWidget
->AppendSeparator();
385 #endif // wxUSE_TOOLTIPS
386 menuWidget
->Append(Widgets_SetFgColour
, _T("Set &foreground...\tCtrl-F"));
387 menuWidget
->Append(Widgets_SetBgColour
, _T("Set &background...\tCtrl-B"));
388 menuWidget
->Append(Widgets_SetFont
, _T("Set f&ont...\tCtrl-O"));
389 menuWidget
->AppendCheckItem(Widgets_Enable
, _T("&Enable/disable\tCtrl-E"));
391 wxMenu
*menuBorders
= new wxMenu
;
392 menuBorders
->AppendRadioItem(Widgets_BorderDefault
, _T("De&fault\tCtrl-Shift-9"));
393 menuBorders
->AppendRadioItem(Widgets_BorderNone
, _T("&None\tCtrl-Shift-0"));
394 menuBorders
->AppendRadioItem(Widgets_BorderSimple
, _T("&Simple\tCtrl-Shift-1"));
395 menuBorders
->AppendRadioItem(Widgets_BorderDouble
, _T("&Double\tCtrl-Shift-2"));
396 menuBorders
->AppendRadioItem(Widgets_BorderStatic
, _T("Stati&c\tCtrl-Shift-3"));
397 menuBorders
->AppendRadioItem(Widgets_BorderRaised
, _T("&Raised\tCtrl-Shift-4"));
398 menuBorders
->AppendRadioItem(Widgets_BorderSunken
, _T("S&unken\tCtrl-Shift-5"));
399 menuWidget
->AppendSubMenu(menuBorders
, _T("Set &border"));
401 menuWidget
->AppendSeparator();
402 menuWidget
->AppendCheckItem(Widgets_GlobalBusyCursor
,
403 _T("Toggle &global busy cursor\tCtrl-Shift-U"));
404 menuWidget
->AppendCheckItem(Widgets_BusyCursor
,
405 _T("Toggle b&usy cursor\tCtrl-U"));
407 menuWidget
->AppendSeparator();
408 menuWidget
->Append(wxID_EXIT
, _T("&Quit\tCtrl-Q"));
409 mbar
->Append(menuWidget
, _T("&Widget"));
411 wxMenu
*menuTextEntry
= new wxMenu
;
412 menuTextEntry
->AppendRadioItem(TextEntry_DisableAutoComplete
,
413 _T("&Disable auto-completion"));
414 menuTextEntry
->AppendRadioItem(TextEntry_AutoCompleteFixed
,
415 _T("Fixed-&list auto-completion"));
416 menuTextEntry
->AppendRadioItem(TextEntry_AutoCompleteFilenames
,
417 _T("&Files names auto-completion"));
419 mbar
->Append(menuTextEntry
, _T("&Text"));
423 mbar
->Check(Widgets_Enable
, true);
424 #endif // wxUSE_MENUS
427 m_panel
= new wxPanel(this, wxID_ANY
);
429 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
431 // we have 2 panes: book with pages demonstrating the controls in the
432 // upper one and the log window with some buttons in the lower
434 int style
= wxBK_DEFAULT
;
435 // Uncomment to suppress page theme (draw in solid colour)
436 //style |= wxNB_NOPAGETHEME;
438 m_book
= new WidgetsBookCtrl(m_panel
, Widgets_BookCtrl
, wxDefaultPosition
,
440 wxSize(500, wxDefaultCoord
), // under Motif, height is a function of the width...
447 #ifndef __WXHANDHELD__
448 // the lower one only has the log listbox and a button to clear it
450 wxSizer
*sizerDown
= new wxStaticBoxSizer(
451 new wxStaticBox( m_panel
, wxID_ANY
, _T("&Log window") ),
454 m_lboxLog
= new wxListBox(m_panel
, wxID_ANY
);
455 sizerDown
->Add(m_lboxLog
, 1, wxGROW
| wxALL
, 5);
456 sizerDown
->SetMinSize(100, 150);
458 wxSizer
*sizerDown
= new wxBoxSizer(wxVERTICAL
);
461 wxBoxSizer
*sizerBtns
= new wxBoxSizer(wxHORIZONTAL
);
464 btn
= new wxButton(m_panel
, Widgets_ClearLog
, _T("Clear &log"));
466 sizerBtns
->Add(10, 0); // spacer
468 btn
= new wxButton(m_panel
, Widgets_Quit
, _T("E&xit"));
470 sizerDown
->Add(sizerBtns
, 0, wxALL
| wxALIGN_RIGHT
, 5);
472 // put everything together
473 sizerTop
->Add(m_book
, 1, wxGROW
| (wxALL
& ~(wxTOP
| wxBOTTOM
)), 10);
474 sizerTop
->Add(0, 5, 0, wxGROW
); // spacer in between
475 sizerTop
->Add(sizerDown
, 0, wxGROW
| (wxALL
& ~wxTOP
), 10);
477 #else // !__WXHANDHELD__/__WXHANDHELD__
479 sizerTop
->Add(m_book
, 1, wxGROW
| wxALL
);
481 #endif // __WXHANDHELD__
483 m_panel
->SetSizer(sizerTop
);
485 sizerTop
->SetSizeHints(this);
487 #if USE_LOG && !defined(__WXCOCOA__)
488 // wxCocoa's listbox is too flakey to use for logging right now
489 // now that everything is created we can redirect the log messages to the
491 m_logTarget
= new LboxLogger(m_lboxLog
, wxLog::GetActiveTarget());
492 wxLog::SetActiveTarget(m_logTarget
);
496 void WidgetsFrame::InitBook()
498 #if USE_ICONS_IN_BOOK
499 wxImageList
*imageList
= new wxImageList(ICON_SIZE
, ICON_SIZE
);
501 wxImage
img(sample_xpm
);
502 imageList
->Add(wxBitmap(img
.Scale(ICON_SIZE
, ICON_SIZE
)));
504 wxImageList
*imageList
= NULL
;
508 WidgetsBookCtrl
*books
[MAX_PAGES
];
511 ArrayWidgetsPage pages
[MAX_PAGES
];
512 wxArrayString labels
[MAX_PAGES
];
514 wxMenu
*menuPages
= new wxMenu
;
515 unsigned int nPage
= 0, nFKey
= 0;
516 int cat
, imageId
= 1;
518 // we need to first create all pages and only then add them to the book
519 // as we need the image list first
521 // we also construct the pages menu during this first iteration
522 for ( cat
= 0; cat
< MAX_PAGES
; cat
++ )
525 nPage
++; // increase for parent page
527 books
[cat
] = new WidgetsBookCtrl(m_book
,
534 for ( WidgetsPageInfo
*info
= WidgetsPage::ms_widgetPages
;
536 info
= info
->GetNext() )
538 if( (info
->GetCategories() & ( 1 << cat
)) == 0)
541 WidgetsPage
*page
= (*info
->GetCtor())(
548 pages
[cat
].Add(page
);
550 labels
[cat
].Add(info
->GetLabel());
551 if ( cat
== ALL_PAGE
)
553 wxString
radioLabel(info
->GetLabel());
557 radioLabel
<< wxT("\tF" ) << nFKey
;
560 menuPages
->AppendRadioItem(
561 Widgets_GoToPage
+ nPage
,
565 // consider only for book in book architecture
571 // consider only for treebook architecture (with subpages)
577 GetMenuBar()->Append(menuPages
, _T("&Page"));
579 #if USE_ICONS_IN_BOOK
580 m_book
->AssignImageList(imageList
);
583 for ( cat
= 0; cat
< MAX_PAGES
; cat
++ )
586 m_book
->AddPage(NULL
,WidgetsCategories
[cat
],false,0);
588 m_book
->AddPage(books
[cat
],WidgetsCategories
[cat
],false,0);
589 #if USE_ICONS_IN_BOOK
590 books
[cat
]->SetImageList(imageList
);
595 size_t count
= pages
[cat
].GetCount();
596 for ( size_t n
= 0; n
< count
; n
++ )
606 false, // don't select
613 wxEVT_COMMAND_WIDGETS_PAGE_CHANGED
,
614 wxWidgetsbookEventHandler(WidgetsFrame::OnPageChanged
) );
617 // for treebook page #0 is empty parent page only so select the first page
618 // with some contents
619 m_book
->SetSelection(1);
621 // but ensure that the top of the tree is shown nevertheless
622 wxTreeCtrl
* const tree
= m_book
->GetTreeCtrl();
624 wxTreeItemIdValue cookie
;
625 tree
->EnsureVisible(tree
->GetFirstChild(tree
->GetRootItem(), cookie
));
627 // for other books set selection twice to force connected event handler
628 // to force lazy creation of initial visible content
629 m_book
->SetSelection(1);
630 m_book
->SetSelection(0);
631 #endif // USE_TREEBOOK
634 WidgetsPage
*WidgetsFrame::CurrentPage()
636 wxWindow
*page
= m_book
->GetCurrentPage();
639 WidgetsBookCtrl
*subBook
= wxStaticCast(page
, WidgetsBookCtrl
);
640 wxCHECK_MSG( subBook
, NULL
, _T("no WidgetsBookCtrl?") );
642 page
= subBook
->GetCurrentPage();
643 #endif // !USE_TREEBOOK
645 return wxStaticCast(page
, WidgetsPage
);
648 WidgetsFrame::~WidgetsFrame()
655 // ----------------------------------------------------------------------------
656 // WidgetsFrame event handlers
657 // ----------------------------------------------------------------------------
659 void WidgetsFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
665 void WidgetsFrame::OnButtonClearLog(wxCommandEvent
& WXUNUSED(event
))
673 void WidgetsFrame::OnPageChanging(WidgetsBookCtrlEvent
& event
)
676 // don't allow selection of entries without pages (categories)
677 if ( !m_book
->GetPage(event
.GetSelection()) )
684 void WidgetsFrame::OnPageChanged(WidgetsBookCtrlEvent
& event
)
686 const int sel
= event
.GetSelection();
688 // adjust "Page" menu selection
689 wxMenuItem
*item
= GetMenuBar()->FindItem(Widgets_GoToPage
+ sel
);
693 GetMenuBar()->Check(Widgets_BusyCursor
, false);
695 // create the pages on demand, otherwise the sample startup is too slow as
696 // it creates hundreds of controls
697 WidgetsPage
*page
= CurrentPage();
698 if ( page
->GetChildren().empty() )
700 wxWindowUpdateLocker
noUpdates(page
);
701 page
->CreateContent();
703 page
->GetSizer()->Fit(page
);
705 WidgetsBookCtrl
*book
= wxStaticCast(page
->GetParent(), WidgetsBookCtrl
);
707 for ( size_t i
= 0; i
< book
->GetPageCount(); ++i
)
709 wxWindow
*page
= book
->GetPage(i
);
712 size
.IncTo(page
->GetSize());
721 void WidgetsFrame::OnGoToPage(wxCommandEvent
& event
)
724 m_book
->SetSelection(event
.GetId() - Widgets_GoToPage
);
726 m_book
->SetSelection(m_book
->GetPageCount()-1);
727 WidgetsBookCtrl
*book
= wxStaticCast(m_book
->GetCurrentPage(), WidgetsBookCtrl
);
728 book
->SetSelection(event
.GetId() - Widgets_GoToPage
);
734 void WidgetsFrame::OnSetTooltip(wxCommandEvent
& WXUNUSED(event
))
736 static wxString s_tip
= _T("This is a tooltip");
738 wxTextEntryDialog dialog
741 _T("Tooltip text (may use \\n, leave empty to remove): "),
742 _T("Widgets sample"),
746 if ( dialog
.ShowModal() != wxID_OK
)
749 s_tip
= dialog
.GetValue();
750 s_tip
.Replace(_T("\\n"), _T("\n"));
752 WidgetsPage
*page
= CurrentPage();
754 page
->GetWidget()->SetToolTip(s_tip
);
756 wxControl
*ctrl2
= page
->GetWidget2();
758 ctrl2
->SetToolTip(s_tip
);
761 #endif // wxUSE_TOOLTIPS
763 void WidgetsFrame::OnSetFgCol(wxCommandEvent
& WXUNUSED(event
))
766 // allow for debugging the default colour the first time this is called
767 WidgetsPage
*page
= CurrentPage();
770 m_colFg
= page
->GetForegroundColour();
772 wxColour col
= wxGetColourFromUser(this, m_colFg
);
778 page
->GetWidget()->SetForegroundColour(m_colFg
);
779 page
->GetWidget()->Refresh();
781 wxControl
*ctrl2
= page
->GetWidget2();
784 ctrl2
->SetForegroundColour(m_colFg
);
788 wxLogMessage(_T("Colour selection dialog not available in current build."));
792 void WidgetsFrame::OnSetBgCol(wxCommandEvent
& WXUNUSED(event
))
795 WidgetsPage
*page
= CurrentPage();
798 m_colBg
= page
->GetBackgroundColour();
800 wxColour col
= wxGetColourFromUser(this, m_colBg
);
806 page
->GetWidget()->SetBackgroundColour(m_colBg
);
807 page
->GetWidget()->Refresh();
809 wxControl
*ctrl2
= page
->GetWidget2();
812 ctrl2
->SetBackgroundColour(m_colFg
);
816 wxLogMessage(_T("Colour selection dialog not available in current build."));
820 void WidgetsFrame::OnSetFont(wxCommandEvent
& WXUNUSED(event
))
823 WidgetsPage
*page
= CurrentPage();
826 m_font
= page
->GetFont();
828 wxFont font
= wxGetFontFromUser(this, m_font
);
834 page
->GetWidget()->SetFont(m_font
);
835 page
->GetWidget()->Refresh();
837 wxControl
*ctrl2
= page
->GetWidget2();
840 ctrl2
->SetFont(m_font
);
844 wxLogMessage(_T("Font selection dialog not available in current build."));
848 void WidgetsFrame::OnEnable(wxCommandEvent
& event
)
850 CurrentPage()->GetWidget()->Enable(event
.IsChecked());
853 void WidgetsFrame::OnSetBorder(wxCommandEvent
& event
)
856 switch ( event
.GetId() )
858 case Widgets_BorderNone
: border
= wxBORDER_NONE
; break;
859 case Widgets_BorderStatic
: border
= wxBORDER_STATIC
; break;
860 case Widgets_BorderSimple
: border
= wxBORDER_SIMPLE
; break;
861 case Widgets_BorderRaised
: border
= wxBORDER_RAISED
; break;
862 case Widgets_BorderSunken
: border
= wxBORDER_SUNKEN
; break;
863 case Widgets_BorderDouble
: border
= wxBORDER_DOUBLE
; break;
866 wxFAIL_MSG( _T("unknown border style") );
869 case Widgets_BorderDefault
: border
= wxBORDER_DEFAULT
; break;
872 WidgetsPage::ms_defaultFlags
&= ~wxBORDER_MASK
;
873 WidgetsPage::ms_defaultFlags
|= border
;
875 WidgetsPage
*page
= CurrentPage();
877 page
->RecreateWidget();
880 void WidgetsFrame::OnToggleGlobalBusyCursor(wxCommandEvent
& event
)
882 if ( event
.IsChecked() )
888 void WidgetsFrame::OnToggleBusyCursor(wxCommandEvent
& event
)
890 CurrentPage()->GetWidget()->SetCursor(*(event
.IsChecked()
892 : wxSTANDARD_CURSOR
));
895 void WidgetsFrame::OnDisableAutoComplete(wxCommandEvent
& WXUNUSED(event
))
897 wxTextEntryBase
*entry
= CurrentPage()->GetTextEntry();
898 wxCHECK_RET( entry
, "menu item should be disabled" );
900 if ( entry
->AutoComplete(wxArrayString()) )
901 wxLogMessage("Disabled auto completion.");
903 wxLogMessage("AutoComplete() failed.");
906 void WidgetsFrame::OnAutoCompleteFixed(wxCommandEvent
& WXUNUSED(event
))
908 wxTextEntryBase
*entry
= CurrentPage()->GetTextEntry();
909 wxCHECK_RET( entry
, "menu item should be disabled" );
911 wxArrayString completion_choices
;
913 // add a few strings so a completion occurs on any letter typed
914 for ( char idxc
= 'a'; idxc
< 'z'; ++idxc
)
915 completion_choices
.push_back(wxString::Format("%c%c", idxc
, idxc
));
917 completion_choices
.push_back("is this string for test?");
918 completion_choices
.push_back("this is a test string");
919 completion_choices
.push_back("this is another test string");
920 completion_choices
.push_back("this string is for test");
922 if ( entry
->AutoComplete(completion_choices
) )
923 wxLogMessage("Enabled auto completion of a set of fixed strings.");
925 wxLogMessage("AutoComplete() failed.");
928 void WidgetsFrame::OnAutoCompleteFilenames(wxCommandEvent
& WXUNUSED(event
))
930 wxTextEntryBase
*entry
= CurrentPage()->GetTextEntry();
931 wxCHECK_RET( entry
, "menu item should be disabled" );
933 if ( entry
->AutoCompleteFileNames() )
934 wxLogMessage("Enable auto completion of file names.");
936 wxLogMessage("AutoCompleteFileNames() failed.");
939 #endif // wxUSE_MENUS
941 // ----------------------------------------------------------------------------
943 // ----------------------------------------------------------------------------
945 WidgetsPageInfo::WidgetsPageInfo(Constructor ctor
, const wxChar
*label
, int categories
)
947 , m_categories(categories
)
953 // dummy sorting: add and immediately sort in the list according to label
954 if ( WidgetsPage::ms_widgetPages
)
956 WidgetsPageInfo
*node_prev
= WidgetsPage::ms_widgetPages
;
957 if ( wxStrcmp(label
, node_prev
->GetLabel().c_str()) < 0 )
961 WidgetsPage::ms_widgetPages
= this;
965 WidgetsPageInfo
*node_next
;
968 node_next
= node_prev
->GetNext();
971 // add if between two
972 if ( wxStrcmp(label
, node_next
->GetLabel().c_str()) < 0 )
974 node_prev
->SetNext(this);
976 // force to break loop
983 node_prev
->SetNext(this);
986 node_prev
= node_next
;
994 WidgetsPage::ms_widgetPages
= this;
998 // ----------------------------------------------------------------------------
1000 // ----------------------------------------------------------------------------
1002 int WidgetsPage::ms_defaultFlags
= wxBORDER_DEFAULT
;
1003 WidgetsPageInfo
*WidgetsPage::ms_widgetPages
= NULL
;
1005 WidgetsPage::WidgetsPage(WidgetsBookCtrl
*book
,
1006 wxImageList
*imaglist
,
1007 const char *const icon
[])
1008 : wxPanel(book
, wxID_ANY
,
1009 wxDefaultPosition
, wxDefaultSize
,
1010 wxNO_FULL_REPAINT_ON_RESIZE
|
1014 #if USE_ICONS_IN_BOOK
1015 imaglist
->Add(wxBitmap(wxImage(icon
).Scale(ICON_SIZE
, ICON_SIZE
)));
1017 wxUnusedVar(imaglist
);
1022 wxSizer
*WidgetsPage::CreateSizerWithText(wxControl
*control
,
1024 wxTextCtrl
**ppText
)
1026 wxSizer
*sizerRow
= new wxBoxSizer(wxHORIZONTAL
);
1027 wxTextCtrl
*text
= new wxTextCtrl(this, id
, wxEmptyString
,
1028 wxDefaultPosition
, wxDefaultSize
, wxTE_PROCESS_ENTER
);
1030 sizerRow
->Add(control
, 0, wxRIGHT
| wxALIGN_CENTRE_VERTICAL
, 5);
1031 sizerRow
->Add(text
, 1, wxLEFT
| wxALIGN_CENTRE_VERTICAL
, 5);
1039 // create a sizer containing a label and a text ctrl
1040 wxSizer
*WidgetsPage::CreateSizerWithTextAndLabel(const wxString
& label
,
1042 wxTextCtrl
**ppText
)
1044 return CreateSizerWithText(new wxStaticText(this, wxID_ANY
, label
),
1048 // create a sizer containing a button and a text ctrl
1049 wxSizer
*WidgetsPage::CreateSizerWithTextAndButton(wxWindowID idBtn
,
1050 const wxString
& label
,
1052 wxTextCtrl
**ppText
)
1054 return CreateSizerWithText(new wxButton(this, idBtn
, label
), id
, ppText
);
1057 wxCheckBox
*WidgetsPage::CreateCheckBoxAndAddToSizer(wxSizer
*sizer
,
1058 const wxString
& label
,
1061 wxCheckBox
*checkbox
= new wxCheckBox(this, id
, label
);
1062 sizer
->Add(checkbox
, 0, wxLEFT
| wxRIGHT
, 5);
1063 sizer
->Add(0, 2, 0, wxGROW
); // spacer