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"
54 #include "wx/persist/toplevel.h"
55 #include "wx/persist/treebook.h"
59 #include "../sample.xpm"
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
68 Widgets_ClearLog
= 100,
75 #endif // wxUSE_TOOLTIPS
87 Widgets_BorderDefault
,
89 Widgets_GlobalBusyCursor
,
93 Widgets_GoToPageLast
= Widgets_GoToPage
+ 100,
97 TextEntry_DisableAutoComplete
= TextEntry_Begin
,
98 TextEntry_AutoCompleteFixed
,
99 TextEntry_AutoCompleteFilenames
,
105 const wxChar
*WidgetsCategories
[MAX_PAGES
] = {
106 #if defined(__WXUNIVERSAL__)
120 // ----------------------------------------------------------------------------
122 // ----------------------------------------------------------------------------
124 // Define a new application type, each program should derive a class from wxApp
125 class WidgetsApp
: public wxApp
128 // override base class virtuals
129 // ----------------------------
131 // this one is called on application startup and is a good place for the app
132 // initialization (doing it here and not in the ctor allows to have an error
133 // return: if OnInit() returns false, the application terminates)
134 virtual bool OnInit();
137 // Define a new frame type: this is going to be our main frame
138 class WidgetsFrame
: public wxFrame
142 WidgetsFrame(const wxString
& title
);
143 virtual ~WidgetsFrame();
148 void OnButtonClearLog(wxCommandEvent
& event
);
150 void OnExit(wxCommandEvent
& event
);
153 void OnPageChanging(WidgetsBookCtrlEvent
& event
);
154 void OnPageChanged(WidgetsBookCtrlEvent
& event
);
155 void OnGoToPage(wxCommandEvent
& event
);
158 void OnSetTooltip(wxCommandEvent
& event
);
159 #endif // wxUSE_TOOLTIPS
160 void OnSetFgCol(wxCommandEvent
& event
);
161 void OnSetBgCol(wxCommandEvent
& event
);
162 void OnSetFont(wxCommandEvent
& event
);
163 void OnEnable(wxCommandEvent
& event
);
164 void OnSetBorder(wxCommandEvent
& event
);
166 void OnToggleGlobalBusyCursor(wxCommandEvent
& event
);
167 void OnToggleBusyCursor(wxCommandEvent
& event
);
169 // wxTextEntry-specific tests
170 void OnDisableAutoComplete(wxCommandEvent
& event
);
171 void OnAutoCompleteFixed(wxCommandEvent
& event
);
172 void OnAutoCompleteFilenames(wxCommandEvent
& event
);
174 void OnSetHint(wxCommandEvent
& event
);
176 void OnUpdateTextUI(wxUpdateUIEvent
& event
)
178 event
.Enable( CurrentPage()->GetTextEntry() != NULL
);
180 #endif // wxUSE_MENUS
182 // initialize the book: add all pages to it
185 // return the currently selected page (never NULL)
186 WidgetsPage
*CurrentPage();
189 // the panel containing everything
193 // the listbox for logging messages
194 wxListBox
*m_lboxLog
;
196 // the log target we use to redirect messages to the listbox
200 // the book containing the test pages
201 WidgetsBookCtrl
*m_book
;
204 // last chosen fg/bg colours and font
208 #endif // wxUSE_MENUS
210 // any class wishing to process wxWidgets events must use this macro
211 DECLARE_EVENT_TABLE()
215 // A log target which just redirects the messages to a listbox
216 class LboxLogger
: public wxLog
219 LboxLogger(wxListBox
*lbox
, wxLog
*logOld
)
222 //m_lbox->Disable(); -- looks ugly under MSW
226 virtual ~LboxLogger()
228 wxLog::SetActiveTarget(m_logOld
);
232 // implement sink functions
233 virtual void DoLogTextAtLevel(wxLogLevel level
, const wxString
& msg
)
235 if ( level
== wxLOG_Trace
)
238 m_logOld
->LogTextAtLevel(level
, msg
);
242 #ifdef __WXUNIVERSAL__
243 m_lbox
->AppendAndEnsureVisible(msg
);
244 #else // other ports don't have this method yet
246 m_lbox
->SetFirstItem(m_lbox
->GetCount() - 1);
250 // the control we use
253 // the old log target
259 WX_DEFINE_ARRAY_PTR(WidgetsPage
*, ArrayWidgetsPage
);
261 // ----------------------------------------------------------------------------
263 // ----------------------------------------------------------------------------
265 IMPLEMENT_APP(WidgetsApp
)
267 // ----------------------------------------------------------------------------
269 // ----------------------------------------------------------------------------
271 BEGIN_EVENT_TABLE(WidgetsFrame
, wxFrame
)
273 EVT_BUTTON(Widgets_ClearLog
, WidgetsFrame::OnButtonClearLog
)
275 EVT_BUTTON(Widgets_Quit
, WidgetsFrame::OnExit
)
278 EVT_MENU(Widgets_SetTooltip
, WidgetsFrame::OnSetTooltip
)
279 #endif // wxUSE_TOOLTIPS
282 EVT_WIDGETS_PAGE_CHANGING(wxID_ANY
, WidgetsFrame::OnPageChanging
)
283 EVT_MENU_RANGE(Widgets_GoToPage
, Widgets_GoToPageLast
,
284 WidgetsFrame::OnGoToPage
)
286 EVT_MENU(Widgets_SetFgColour
, WidgetsFrame::OnSetFgCol
)
287 EVT_MENU(Widgets_SetBgColour
, WidgetsFrame::OnSetBgCol
)
288 EVT_MENU(Widgets_SetFont
, WidgetsFrame::OnSetFont
)
289 EVT_MENU(Widgets_Enable
, WidgetsFrame::OnEnable
)
291 EVT_MENU_RANGE(Widgets_BorderNone
, Widgets_BorderDefault
,
292 WidgetsFrame::OnSetBorder
)
294 EVT_MENU(Widgets_GlobalBusyCursor
, WidgetsFrame::OnToggleGlobalBusyCursor
)
295 EVT_MENU(Widgets_BusyCursor
, WidgetsFrame::OnToggleBusyCursor
)
297 EVT_MENU(TextEntry_DisableAutoComplete
, WidgetsFrame::OnDisableAutoComplete
)
298 EVT_MENU(TextEntry_AutoCompleteFixed
, WidgetsFrame::OnAutoCompleteFixed
)
299 EVT_MENU(TextEntry_AutoCompleteFilenames
, WidgetsFrame::OnAutoCompleteFilenames
)
301 EVT_MENU(TextEntry_SetHint
, WidgetsFrame::OnSetHint
)
303 EVT_UPDATE_UI_RANGE(TextEntry_Begin
, TextEntry_End
- 1,
304 WidgetsFrame::OnUpdateTextUI
)
306 EVT_MENU(wxID_EXIT
, WidgetsFrame::OnExit
)
307 #endif // wxUSE_MENUS
310 // ============================================================================
312 // ============================================================================
314 // ----------------------------------------------------------------------------
316 // ----------------------------------------------------------------------------
318 bool WidgetsApp::OnInit()
320 if ( !wxApp::OnInit() )
323 SetVendorName("wxWidgets_Samples");
325 // the reason for having these ifdef's is that I often run two copies of
326 // this sample side by side and it is useful to see which one is which
328 #if defined(__WXUNIVERSAL__)
329 title
= _T("wxUniv/");
332 #if defined(__WXMSW__)
333 title
+= _T("wxMSW");
334 #elif defined(__WXGTK__)
335 title
+= _T("wxGTK");
336 #elif defined(__WXMAC__)
337 title
+= _T("wxMAC");
338 #elif defined(__WXMOTIF__)
339 title
+= _T("wxMOTIF");
341 title
+= _T("wxPALMOS5");
343 title
+= _T("wxPALMOS6");
345 title
+= _T("wxWidgets");
348 wxFrame
*frame
= new WidgetsFrame(title
+ _T(" widgets demo"));
354 // ----------------------------------------------------------------------------
355 // WidgetsFrame construction
356 // ----------------------------------------------------------------------------
358 WidgetsFrame::WidgetsFrame(const wxString
& title
)
359 : wxFrame(NULL
, wxID_ANY
, title
)
362 const bool sizeSet
= wxPersistentRegisterAndRestore(this);
364 // set the frame icon
365 SetIcon(wxICON(sample
));
375 // create the menubar
376 wxMenuBar
*mbar
= new wxMenuBar
;
377 wxMenu
*menuWidget
= new wxMenu
;
379 menuWidget
->Append(Widgets_SetTooltip
, _T("Set &tooltip...\tCtrl-T"));
380 menuWidget
->AppendSeparator();
381 #endif // wxUSE_TOOLTIPS
382 menuWidget
->Append(Widgets_SetFgColour
, _T("Set &foreground...\tCtrl-F"));
383 menuWidget
->Append(Widgets_SetBgColour
, _T("Set &background...\tCtrl-B"));
384 menuWidget
->Append(Widgets_SetFont
, _T("Set f&ont...\tCtrl-O"));
385 menuWidget
->AppendCheckItem(Widgets_Enable
, _T("&Enable/disable\tCtrl-E"));
387 wxMenu
*menuBorders
= new wxMenu
;
388 menuBorders
->AppendRadioItem(Widgets_BorderDefault
, _T("De&fault\tCtrl-Shift-9"));
389 menuBorders
->AppendRadioItem(Widgets_BorderNone
, _T("&None\tCtrl-Shift-0"));
390 menuBorders
->AppendRadioItem(Widgets_BorderSimple
, _T("&Simple\tCtrl-Shift-1"));
391 menuBorders
->AppendRadioItem(Widgets_BorderDouble
, _T("&Double\tCtrl-Shift-2"));
392 menuBorders
->AppendRadioItem(Widgets_BorderStatic
, _T("Stati&c\tCtrl-Shift-3"));
393 menuBorders
->AppendRadioItem(Widgets_BorderRaised
, _T("&Raised\tCtrl-Shift-4"));
394 menuBorders
->AppendRadioItem(Widgets_BorderSunken
, _T("S&unken\tCtrl-Shift-5"));
395 menuWidget
->AppendSubMenu(menuBorders
, _T("Set &border"));
397 menuWidget
->AppendSeparator();
398 menuWidget
->AppendCheckItem(Widgets_GlobalBusyCursor
,
399 _T("Toggle &global busy cursor\tCtrl-Shift-U"));
400 menuWidget
->AppendCheckItem(Widgets_BusyCursor
,
401 _T("Toggle b&usy cursor\tCtrl-U"));
403 menuWidget
->AppendSeparator();
404 menuWidget
->Append(wxID_EXIT
, _T("&Quit\tCtrl-Q"));
405 mbar
->Append(menuWidget
, _T("&Widget"));
407 wxMenu
*menuTextEntry
= new wxMenu
;
408 menuTextEntry
->AppendRadioItem(TextEntry_DisableAutoComplete
,
409 _T("&Disable auto-completion"));
410 menuTextEntry
->AppendRadioItem(TextEntry_AutoCompleteFixed
,
411 _T("Fixed-&list auto-completion"));
412 menuTextEntry
->AppendRadioItem(TextEntry_AutoCompleteFilenames
,
413 _T("&Files names auto-completion"));
414 menuTextEntry
->AppendSeparator();
415 menuTextEntry
->Append(TextEntry_SetHint
, "Set help &hint");
417 mbar
->Append(menuTextEntry
, _T("&Text"));
421 mbar
->Check(Widgets_Enable
, true);
422 #endif // wxUSE_MENUS
425 m_panel
= new wxPanel(this, wxID_ANY
);
427 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
429 // we have 2 panes: book with pages demonstrating the controls in the
430 // upper one and the log window with some buttons in the lower
432 int style
= wxBK_DEFAULT
;
433 // Uncomment to suppress page theme (draw in solid colour)
434 //style |= wxNB_NOPAGETHEME;
436 m_book
= new WidgetsBookCtrl(m_panel
, Widgets_BookCtrl
,
437 wxDefaultPosition
, wxDefaultSize
,
442 #ifndef __WXHANDHELD__
443 // the lower one only has the log listbox and a button to clear it
445 wxSizer
*sizerDown
= new wxStaticBoxSizer(
446 new wxStaticBox( m_panel
, wxID_ANY
, _T("&Log window") ),
449 m_lboxLog
= new wxListBox(m_panel
, wxID_ANY
);
450 sizerDown
->Add(m_lboxLog
, 1, wxGROW
| wxALL
, 5);
451 sizerDown
->SetMinSize(100, 150);
453 wxSizer
*sizerDown
= new wxBoxSizer(wxVERTICAL
);
456 wxBoxSizer
*sizerBtns
= new wxBoxSizer(wxHORIZONTAL
);
459 btn
= new wxButton(m_panel
, Widgets_ClearLog
, _T("Clear &log"));
461 sizerBtns
->Add(10, 0); // spacer
463 btn
= new wxButton(m_panel
, Widgets_Quit
, _T("E&xit"));
465 sizerDown
->Add(sizerBtns
, 0, wxALL
| wxALIGN_RIGHT
, 5);
467 // put everything together
468 sizerTop
->Add(m_book
, 1, wxGROW
| (wxALL
& ~(wxTOP
| wxBOTTOM
)), 10);
469 sizerTop
->Add(0, 5, 0, wxGROW
); // spacer in between
470 sizerTop
->Add(sizerDown
, 0, wxGROW
| (wxALL
& ~wxTOP
), 10);
472 #else // !__WXHANDHELD__/__WXHANDHELD__
474 sizerTop
->Add(m_book
, 1, wxGROW
| wxALL
);
476 #endif // __WXHANDHELD__
478 m_panel
->SetSizer(sizerTop
);
480 const wxSize sizeMin
= m_panel
->GetBestSize();
482 SetClientSize(sizeMin
);
483 SetMinClientSize(sizeMin
);
485 #if USE_LOG && !defined(__WXCOCOA__)
486 // wxCocoa's listbox is too flakey to use for logging right now
487 // now that everything is created we can redirect the log messages to the
489 m_logTarget
= new LboxLogger(m_lboxLog
, wxLog::GetActiveTarget());
490 wxLog::SetActiveTarget(m_logTarget
);
494 void WidgetsFrame::InitBook()
496 #if USE_ICONS_IN_BOOK
497 wxImageList
*imageList
= new wxImageList(ICON_SIZE
, ICON_SIZE
);
499 wxImage
img(sample_xpm
);
500 imageList
->Add(wxBitmap(img
.Scale(ICON_SIZE
, ICON_SIZE
)));
502 wxImageList
*imageList
= NULL
;
506 WidgetsBookCtrl
*books
[MAX_PAGES
];
509 ArrayWidgetsPage pages
[MAX_PAGES
];
510 wxArrayString labels
[MAX_PAGES
];
512 wxMenu
*menuPages
= new wxMenu
;
513 unsigned int nPage
= 0, nFKey
= 0;
514 int cat
, imageId
= 1;
516 // we need to first create all pages and only then add them to the book
517 // as we need the image list first
519 // we also construct the pages menu during this first iteration
520 for ( cat
= 0; cat
< MAX_PAGES
; cat
++ )
523 nPage
++; // increase for parent page
525 books
[cat
] = new WidgetsBookCtrl(m_book
,
532 for ( WidgetsPageInfo
*info
= WidgetsPage::ms_widgetPages
;
534 info
= info
->GetNext() )
536 if( (info
->GetCategories() & ( 1 << cat
)) == 0)
539 WidgetsPage
*page
= (*info
->GetCtor())(
546 pages
[cat
].Add(page
);
548 labels
[cat
].Add(info
->GetLabel());
549 if ( cat
== ALL_PAGE
)
551 wxString
radioLabel(info
->GetLabel());
555 radioLabel
<< wxT("\tF" ) << nFKey
;
558 menuPages
->AppendRadioItem(
559 Widgets_GoToPage
+ nPage
,
563 // consider only for book in book architecture
569 // consider only for treebook architecture (with subpages)
575 GetMenuBar()->Append(menuPages
, _T("&Page"));
577 #if USE_ICONS_IN_BOOK
578 m_book
->AssignImageList(imageList
);
581 for ( cat
= 0; cat
< MAX_PAGES
; cat
++ )
584 m_book
->AddPage(NULL
,WidgetsCategories
[cat
],false,0);
586 m_book
->AddPage(books
[cat
],WidgetsCategories
[cat
],false,0);
587 #if USE_ICONS_IN_BOOK
588 books
[cat
]->SetImageList(imageList
);
593 size_t count
= pages
[cat
].GetCount();
594 for ( size_t n
= 0; n
< count
; n
++ )
604 false, // don't select
611 wxEVT_COMMAND_WIDGETS_PAGE_CHANGED
,
612 wxWidgetsbookEventHandler(WidgetsFrame::OnPageChanged
) );
614 const bool pageSet
= wxPersistentRegisterAndRestore(m_book
);
617 // for treebook page #0 is empty parent page only so select the first page
618 // with some contents
620 m_book
->SetSelection(1);
622 // but ensure that the top of the tree is shown nevertheless
623 wxTreeCtrl
* const tree
= m_book
->GetTreeCtrl();
625 wxTreeItemIdValue cookie
;
626 tree
->EnsureVisible(tree
->GetFirstChild(tree
->GetRootItem(), cookie
));
630 // for other books set selection twice to force connected event handler
631 // to force lazy creation of initial visible content
632 m_book
->SetSelection(1);
633 m_book
->SetSelection(0);
635 #endif // USE_TREEBOOK
638 WidgetsPage
*WidgetsFrame::CurrentPage()
640 wxWindow
*page
= m_book
->GetCurrentPage();
643 WidgetsBookCtrl
*subBook
= wxStaticCast(page
, WidgetsBookCtrl
);
644 wxCHECK_MSG( subBook
, NULL
, _T("no WidgetsBookCtrl?") );
646 page
= subBook
->GetCurrentPage();
647 #endif // !USE_TREEBOOK
649 return wxStaticCast(page
, WidgetsPage
);
652 WidgetsFrame::~WidgetsFrame()
659 // ----------------------------------------------------------------------------
660 // WidgetsFrame event handlers
661 // ----------------------------------------------------------------------------
663 void WidgetsFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
669 void WidgetsFrame::OnButtonClearLog(wxCommandEvent
& WXUNUSED(event
))
677 void WidgetsFrame::OnPageChanging(WidgetsBookCtrlEvent
& event
)
680 // don't allow selection of entries without pages (categories)
681 if ( !m_book
->GetPage(event
.GetSelection()) )
688 void WidgetsFrame::OnPageChanged(WidgetsBookCtrlEvent
& event
)
690 const int sel
= event
.GetSelection();
692 // adjust "Page" menu selection
693 wxMenuItem
*item
= GetMenuBar()->FindItem(Widgets_GoToPage
+ sel
);
697 GetMenuBar()->Check(Widgets_BusyCursor
, false);
699 // create the pages on demand, otherwise the sample startup is too slow as
700 // it creates hundreds of controls
701 WidgetsPage
*page
= CurrentPage();
702 if ( page
->GetChildren().empty() )
704 wxWindowUpdateLocker
noUpdates(page
);
705 page
->CreateContent();
707 page
->GetSizer()->Fit(page
);
709 WidgetsBookCtrl
*book
= wxStaticCast(page
->GetParent(), WidgetsBookCtrl
);
711 for ( size_t i
= 0; i
< book
->GetPageCount(); ++i
)
713 wxWindow
*page
= book
->GetPage(i
);
716 size
.IncTo(page
->GetSize());
725 void WidgetsFrame::OnGoToPage(wxCommandEvent
& event
)
728 m_book
->SetSelection(event
.GetId() - Widgets_GoToPage
);
730 m_book
->SetSelection(m_book
->GetPageCount()-1);
731 WidgetsBookCtrl
*book
= wxStaticCast(m_book
->GetCurrentPage(), WidgetsBookCtrl
);
732 book
->SetSelection(event
.GetId() - Widgets_GoToPage
);
738 void WidgetsFrame::OnSetTooltip(wxCommandEvent
& WXUNUSED(event
))
740 static wxString s_tip
= _T("This is a tooltip");
742 wxTextEntryDialog dialog
745 _T("Tooltip text (may use \\n, leave empty to remove): "),
746 _T("Widgets sample"),
750 if ( dialog
.ShowModal() != wxID_OK
)
753 s_tip
= dialog
.GetValue();
754 s_tip
.Replace(_T("\\n"), _T("\n"));
756 WidgetsPage
*page
= CurrentPage();
758 page
->GetWidget()->SetToolTip(s_tip
);
760 wxControl
*ctrl2
= page
->GetWidget2();
762 ctrl2
->SetToolTip(s_tip
);
765 #endif // wxUSE_TOOLTIPS
767 void WidgetsFrame::OnSetFgCol(wxCommandEvent
& WXUNUSED(event
))
770 // allow for debugging the default colour the first time this is called
771 WidgetsPage
*page
= CurrentPage();
774 m_colFg
= page
->GetForegroundColour();
776 wxColour col
= wxGetColourFromUser(this, m_colFg
);
782 page
->GetWidget()->SetForegroundColour(m_colFg
);
783 page
->GetWidget()->Refresh();
785 wxControl
*ctrl2
= page
->GetWidget2();
788 ctrl2
->SetForegroundColour(m_colFg
);
792 wxLogMessage(_T("Colour selection dialog not available in current build."));
796 void WidgetsFrame::OnSetBgCol(wxCommandEvent
& WXUNUSED(event
))
799 WidgetsPage
*page
= CurrentPage();
802 m_colBg
= page
->GetBackgroundColour();
804 wxColour col
= wxGetColourFromUser(this, m_colBg
);
810 page
->GetWidget()->SetBackgroundColour(m_colBg
);
811 page
->GetWidget()->Refresh();
813 wxControl
*ctrl2
= page
->GetWidget2();
816 ctrl2
->SetBackgroundColour(m_colFg
);
820 wxLogMessage(_T("Colour selection dialog not available in current build."));
824 void WidgetsFrame::OnSetFont(wxCommandEvent
& WXUNUSED(event
))
827 WidgetsPage
*page
= CurrentPage();
830 m_font
= page
->GetFont();
832 wxFont font
= wxGetFontFromUser(this, m_font
);
838 page
->GetWidget()->SetFont(m_font
);
839 page
->GetWidget()->Refresh();
841 wxControl
*ctrl2
= page
->GetWidget2();
844 ctrl2
->SetFont(m_font
);
848 wxLogMessage(_T("Font selection dialog not available in current build."));
852 void WidgetsFrame::OnEnable(wxCommandEvent
& event
)
854 CurrentPage()->GetWidget()->Enable(event
.IsChecked());
855 if (CurrentPage()->GetWidget2())
856 CurrentPage()->GetWidget2()->Enable(event
.IsChecked());
859 void WidgetsFrame::OnSetBorder(wxCommandEvent
& event
)
862 switch ( event
.GetId() )
864 case Widgets_BorderNone
: border
= wxBORDER_NONE
; break;
865 case Widgets_BorderStatic
: border
= wxBORDER_STATIC
; break;
866 case Widgets_BorderSimple
: border
= wxBORDER_SIMPLE
; break;
867 case Widgets_BorderRaised
: border
= wxBORDER_RAISED
; break;
868 case Widgets_BorderSunken
: border
= wxBORDER_SUNKEN
; break;
869 case Widgets_BorderDouble
: border
= wxBORDER_DOUBLE
; break;
872 wxFAIL_MSG( _T("unknown border style") );
875 case Widgets_BorderDefault
: border
= wxBORDER_DEFAULT
; break;
878 WidgetsPage::ms_defaultFlags
&= ~wxBORDER_MASK
;
879 WidgetsPage::ms_defaultFlags
|= border
;
881 WidgetsPage
*page
= CurrentPage();
883 page
->RecreateWidget();
886 void WidgetsFrame::OnToggleGlobalBusyCursor(wxCommandEvent
& event
)
888 if ( event
.IsChecked() )
894 void WidgetsFrame::OnToggleBusyCursor(wxCommandEvent
& event
)
896 CurrentPage()->GetWidget()->SetCursor(*(event
.IsChecked()
898 : wxSTANDARD_CURSOR
));
901 void WidgetsFrame::OnDisableAutoComplete(wxCommandEvent
& WXUNUSED(event
))
903 wxTextEntryBase
*entry
= CurrentPage()->GetTextEntry();
904 wxCHECK_RET( entry
, "menu item should be disabled" );
906 if ( entry
->AutoComplete(wxArrayString()) )
907 wxLogMessage("Disabled auto completion.");
909 wxLogMessage("AutoComplete() failed.");
912 void WidgetsFrame::OnAutoCompleteFixed(wxCommandEvent
& WXUNUSED(event
))
914 wxTextEntryBase
*entry
= CurrentPage()->GetTextEntry();
915 wxCHECK_RET( entry
, "menu item should be disabled" );
917 wxArrayString completion_choices
;
919 // add a few strings so a completion occurs on any letter typed
920 for ( char idxc
= 'a'; idxc
< 'z'; ++idxc
)
921 completion_choices
.push_back(wxString::Format("%c%c", idxc
, idxc
));
923 completion_choices
.push_back("is this string for test?");
924 completion_choices
.push_back("this is a test string");
925 completion_choices
.push_back("this is another test string");
926 completion_choices
.push_back("this string is for test");
928 if ( entry
->AutoComplete(completion_choices
) )
929 wxLogMessage("Enabled auto completion of a set of fixed strings.");
931 wxLogMessage("AutoComplete() failed.");
934 void WidgetsFrame::OnAutoCompleteFilenames(wxCommandEvent
& WXUNUSED(event
))
936 wxTextEntryBase
*entry
= CurrentPage()->GetTextEntry();
937 wxCHECK_RET( entry
, "menu item should be disabled" );
939 if ( entry
->AutoCompleteFileNames() )
940 wxLogMessage("Enable auto completion of file names.");
942 wxLogMessage("AutoCompleteFileNames() failed.");
945 void WidgetsFrame::OnSetHint(wxCommandEvent
& WXUNUSED(event
))
947 wxTextEntryBase
*entry
= CurrentPage()->GetTextEntry();
948 wxCHECK_RET( entry
, "menu item should be disabled" );
950 static wxString
s_hint("Type here");
952 hint
= wxGetTextFromUser("Text hint:", "Widgets sample", s_hint
, this);
958 if ( entry
->SetHint(hint
) )
959 wxLogMessage("Set hint to \"%s\".", hint
);
961 wxLogMessage("Text hints not supported.");
964 #endif // wxUSE_MENUS
966 // ----------------------------------------------------------------------------
968 // ----------------------------------------------------------------------------
970 WidgetsPageInfo::WidgetsPageInfo(Constructor ctor
, const wxChar
*label
, int categories
)
972 , m_categories(categories
)
978 // dummy sorting: add and immediately sort in the list according to label
979 if ( WidgetsPage::ms_widgetPages
)
981 WidgetsPageInfo
*node_prev
= WidgetsPage::ms_widgetPages
;
982 if ( wxStrcmp(label
, node_prev
->GetLabel().c_str()) < 0 )
986 WidgetsPage::ms_widgetPages
= this;
990 WidgetsPageInfo
*node_next
;
993 node_next
= node_prev
->GetNext();
996 // add if between two
997 if ( wxStrcmp(label
, node_next
->GetLabel().c_str()) < 0 )
999 node_prev
->SetNext(this);
1001 // force to break loop
1008 node_prev
->SetNext(this);
1011 node_prev
= node_next
;
1013 while ( node_next
);
1019 WidgetsPage::ms_widgetPages
= this;
1023 // ----------------------------------------------------------------------------
1025 // ----------------------------------------------------------------------------
1027 int WidgetsPage::ms_defaultFlags
= wxBORDER_DEFAULT
;
1028 WidgetsPageInfo
*WidgetsPage::ms_widgetPages
= NULL
;
1030 WidgetsPage::WidgetsPage(WidgetsBookCtrl
*book
,
1031 wxImageList
*imaglist
,
1032 const char *const icon
[])
1033 : wxPanel(book
, wxID_ANY
,
1034 wxDefaultPosition
, wxDefaultSize
,
1035 wxNO_FULL_REPAINT_ON_RESIZE
|
1039 #if USE_ICONS_IN_BOOK
1040 imaglist
->Add(wxBitmap(wxImage(icon
).Scale(ICON_SIZE
, ICON_SIZE
)));
1042 wxUnusedVar(imaglist
);
1047 wxSizer
*WidgetsPage::CreateSizerWithText(wxControl
*control
,
1049 wxTextCtrl
**ppText
)
1051 wxSizer
*sizerRow
= new wxBoxSizer(wxHORIZONTAL
);
1052 wxTextCtrl
*text
= new wxTextCtrl(this, id
, wxEmptyString
,
1053 wxDefaultPosition
, wxDefaultSize
, wxTE_PROCESS_ENTER
);
1055 sizerRow
->Add(control
, 0, wxRIGHT
| wxALIGN_CENTRE_VERTICAL
, 5);
1056 sizerRow
->Add(text
, 1, wxLEFT
| wxALIGN_CENTRE_VERTICAL
, 5);
1064 // create a sizer containing a label and a text ctrl
1065 wxSizer
*WidgetsPage::CreateSizerWithTextAndLabel(const wxString
& label
,
1067 wxTextCtrl
**ppText
)
1069 return CreateSizerWithText(new wxStaticText(this, wxID_ANY
, label
),
1073 // create a sizer containing a button and a text ctrl
1074 wxSizer
*WidgetsPage::CreateSizerWithTextAndButton(wxWindowID idBtn
,
1075 const wxString
& label
,
1077 wxTextCtrl
**ppText
)
1079 return CreateSizerWithText(new wxButton(this, idBtn
, label
), id
, ppText
);
1082 wxCheckBox
*WidgetsPage::CreateCheckBoxAndAddToSizer(wxSizer
*sizer
,
1083 const wxString
& label
,
1086 wxCheckBox
*checkbox
= new wxCheckBox(this, id
, label
);
1087 sizer
->Add(checkbox
, 0, wxLEFT
| wxRIGHT
, 5);
1088 sizer
->Add(0, 2, 0, wxGROW
); // spacer