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
,
103 const wxChar
*WidgetsCategories
[MAX_PAGES
] = {
104 #if defined(__WXUNIVERSAL__)
118 // ----------------------------------------------------------------------------
120 // ----------------------------------------------------------------------------
122 // Define a new application type, each program should derive a class from wxApp
123 class WidgetsApp
: public wxApp
126 // override base class virtuals
127 // ----------------------------
129 // this one is called on application startup and is a good place for the app
130 // initialization (doing it here and not in the ctor allows to have an error
131 // return: if OnInit() returns false, the application terminates)
132 virtual bool OnInit();
135 // Define a new frame type: this is going to be our main frame
136 class WidgetsFrame
: public wxFrame
140 WidgetsFrame(const wxString
& title
);
141 virtual ~WidgetsFrame();
146 void OnButtonClearLog(wxCommandEvent
& event
);
148 void OnExit(wxCommandEvent
& event
);
151 void OnPageChanging(WidgetsBookCtrlEvent
& event
);
152 void OnPageChanged(WidgetsBookCtrlEvent
& event
);
153 void OnGoToPage(wxCommandEvent
& event
);
156 void OnSetTooltip(wxCommandEvent
& event
);
157 #endif // wxUSE_TOOLTIPS
158 void OnSetFgCol(wxCommandEvent
& event
);
159 void OnSetBgCol(wxCommandEvent
& event
);
160 void OnSetFont(wxCommandEvent
& event
);
161 void OnEnable(wxCommandEvent
& event
);
162 void OnSetBorder(wxCommandEvent
& event
);
164 void OnToggleGlobalBusyCursor(wxCommandEvent
& event
);
165 void OnToggleBusyCursor(wxCommandEvent
& event
);
167 void OnDisableAutoComplete(wxCommandEvent
& event
);
168 void OnAutoCompleteFixed(wxCommandEvent
& event
);
169 void OnAutoCompleteFilenames(wxCommandEvent
& event
);
171 void OnUpdateTextUI(wxUpdateUIEvent
& event
)
173 event
.Enable( CurrentPage()->GetTextEntry() != NULL
);
175 #endif // wxUSE_MENUS
177 // initialize the book: add all pages to it
180 // return the currently selected page (never NULL)
181 WidgetsPage
*CurrentPage();
184 // the panel containing everything
188 // the listbox for logging messages
189 wxListBox
*m_lboxLog
;
191 // the log target we use to redirect messages to the listbox
195 // the book containing the test pages
196 WidgetsBookCtrl
*m_book
;
199 // last chosen fg/bg colours and font
203 #endif // wxUSE_MENUS
205 // any class wishing to process wxWidgets events must use this macro
206 DECLARE_EVENT_TABLE()
210 // A log target which just redirects the messages to a listbox
211 class LboxLogger
: public wxLog
214 LboxLogger(wxListBox
*lbox
, wxLog
*logOld
)
217 //m_lbox->Disable(); -- looks ugly under MSW
221 virtual ~LboxLogger()
223 wxLog::SetActiveTarget(m_logOld
);
227 // implement sink functions
228 virtual void DoLog(wxLogLevel level
, const wxString
& str
, time_t t
)
230 // don't put trace messages into listbox or we can get into infinite
232 if ( level
== wxLOG_Trace
)
236 // cast is needed to call protected method
237 ((LboxLogger
*)m_logOld
)->DoLog(level
, str
, t
);
242 wxLog::DoLog(level
, str
, t
);
246 virtual void DoLogString(const wxString
& str
, time_t WXUNUSED(t
))
252 #ifdef __WXUNIVERSAL__
253 m_lbox
->AppendAndEnsureVisible(msg
);
254 #else // other ports don't have this method yet
256 m_lbox
->SetFirstItem(m_lbox
->GetCount() - 1);
260 // the control we use
263 // the old log target
269 WX_DEFINE_ARRAY_PTR(WidgetsPage
*, ArrayWidgetsPage
);
271 // ----------------------------------------------------------------------------
273 // ----------------------------------------------------------------------------
275 IMPLEMENT_APP(WidgetsApp
)
277 // ----------------------------------------------------------------------------
279 // ----------------------------------------------------------------------------
281 BEGIN_EVENT_TABLE(WidgetsFrame
, wxFrame
)
283 EVT_BUTTON(Widgets_ClearLog
, WidgetsFrame::OnButtonClearLog
)
285 EVT_BUTTON(Widgets_Quit
, WidgetsFrame::OnExit
)
288 EVT_MENU(Widgets_SetTooltip
, WidgetsFrame::OnSetTooltip
)
289 #endif // wxUSE_TOOLTIPS
292 EVT_WIDGETS_PAGE_CHANGING(wxID_ANY
, WidgetsFrame::OnPageChanging
)
293 EVT_MENU_RANGE(Widgets_GoToPage
, Widgets_GoToPageLast
,
294 WidgetsFrame::OnGoToPage
)
296 EVT_MENU(Widgets_SetFgColour
, WidgetsFrame::OnSetFgCol
)
297 EVT_MENU(Widgets_SetBgColour
, WidgetsFrame::OnSetBgCol
)
298 EVT_MENU(Widgets_SetFont
, WidgetsFrame::OnSetFont
)
299 EVT_MENU(Widgets_Enable
, WidgetsFrame::OnEnable
)
301 EVT_MENU_RANGE(Widgets_BorderNone
, Widgets_BorderDefault
,
302 WidgetsFrame::OnSetBorder
)
304 EVT_MENU(Widgets_GlobalBusyCursor
, WidgetsFrame::OnToggleGlobalBusyCursor
)
305 EVT_MENU(Widgets_BusyCursor
, WidgetsFrame::OnToggleBusyCursor
)
307 EVT_MENU(TextEntry_DisableAutoComplete
, WidgetsFrame::OnDisableAutoComplete
)
308 EVT_MENU(TextEntry_AutoCompleteFixed
, WidgetsFrame::OnAutoCompleteFixed
)
309 EVT_MENU(TextEntry_AutoCompleteFilenames
, WidgetsFrame::OnAutoCompleteFilenames
)
311 EVT_UPDATE_UI_RANGE(TextEntry_Begin
, TextEntry_End
- 1,
312 WidgetsFrame::OnUpdateTextUI
)
314 EVT_MENU(wxID_EXIT
, WidgetsFrame::OnExit
)
315 #endif // wxUSE_MENUS
318 // ============================================================================
320 // ============================================================================
322 // ----------------------------------------------------------------------------
324 // ----------------------------------------------------------------------------
326 bool WidgetsApp::OnInit()
328 if ( !wxApp::OnInit() )
331 SetVendorName("wxWidgets_Samples");
333 // the reason for having these ifdef's is that I often run two copies of
334 // this sample side by side and it is useful to see which one is which
336 #if defined(__WXUNIVERSAL__)
337 title
= _T("wxUniv/");
340 #if defined(__WXMSW__)
341 title
+= _T("wxMSW");
342 #elif defined(__WXGTK__)
343 title
+= _T("wxGTK");
344 #elif defined(__WXMAC__)
345 title
+= _T("wxMAC");
346 #elif defined(__WXMOTIF__)
347 title
+= _T("wxMOTIF");
349 title
+= _T("wxPALMOS5");
351 title
+= _T("wxPALMOS6");
353 title
+= _T("wxWidgets");
356 wxFrame
*frame
= new WidgetsFrame(title
+ _T(" widgets demo"));
362 // ----------------------------------------------------------------------------
363 // WidgetsFrame construction
364 // ----------------------------------------------------------------------------
366 WidgetsFrame::WidgetsFrame(const wxString
& title
)
367 : wxFrame(NULL
, wxID_ANY
, title
)
370 const bool sizeSet
= wxPersistentRegisterAndRestore(this);
372 // set the frame icon
373 SetIcon(wxICON(sample
));
383 // create the menubar
384 wxMenuBar
*mbar
= new wxMenuBar
;
385 wxMenu
*menuWidget
= new wxMenu
;
387 menuWidget
->Append(Widgets_SetTooltip
, _T("Set &tooltip...\tCtrl-T"));
388 menuWidget
->AppendSeparator();
389 #endif // wxUSE_TOOLTIPS
390 menuWidget
->Append(Widgets_SetFgColour
, _T("Set &foreground...\tCtrl-F"));
391 menuWidget
->Append(Widgets_SetBgColour
, _T("Set &background...\tCtrl-B"));
392 menuWidget
->Append(Widgets_SetFont
, _T("Set f&ont...\tCtrl-O"));
393 menuWidget
->AppendCheckItem(Widgets_Enable
, _T("&Enable/disable\tCtrl-E"));
395 wxMenu
*menuBorders
= new wxMenu
;
396 menuBorders
->AppendRadioItem(Widgets_BorderDefault
, _T("De&fault\tCtrl-Shift-9"));
397 menuBorders
->AppendRadioItem(Widgets_BorderNone
, _T("&None\tCtrl-Shift-0"));
398 menuBorders
->AppendRadioItem(Widgets_BorderSimple
, _T("&Simple\tCtrl-Shift-1"));
399 menuBorders
->AppendRadioItem(Widgets_BorderDouble
, _T("&Double\tCtrl-Shift-2"));
400 menuBorders
->AppendRadioItem(Widgets_BorderStatic
, _T("Stati&c\tCtrl-Shift-3"));
401 menuBorders
->AppendRadioItem(Widgets_BorderRaised
, _T("&Raised\tCtrl-Shift-4"));
402 menuBorders
->AppendRadioItem(Widgets_BorderSunken
, _T("S&unken\tCtrl-Shift-5"));
403 menuWidget
->AppendSubMenu(menuBorders
, _T("Set &border"));
405 menuWidget
->AppendSeparator();
406 menuWidget
->AppendCheckItem(Widgets_GlobalBusyCursor
,
407 _T("Toggle &global busy cursor\tCtrl-Shift-U"));
408 menuWidget
->AppendCheckItem(Widgets_BusyCursor
,
409 _T("Toggle b&usy cursor\tCtrl-U"));
411 menuWidget
->AppendSeparator();
412 menuWidget
->Append(wxID_EXIT
, _T("&Quit\tCtrl-Q"));
413 mbar
->Append(menuWidget
, _T("&Widget"));
415 wxMenu
*menuTextEntry
= new wxMenu
;
416 menuTextEntry
->AppendRadioItem(TextEntry_DisableAutoComplete
,
417 _T("&Disable auto-completion"));
418 menuTextEntry
->AppendRadioItem(TextEntry_AutoCompleteFixed
,
419 _T("Fixed-&list auto-completion"));
420 menuTextEntry
->AppendRadioItem(TextEntry_AutoCompleteFilenames
,
421 _T("&Files names auto-completion"));
423 mbar
->Append(menuTextEntry
, _T("&Text"));
427 mbar
->Check(Widgets_Enable
, true);
428 #endif // wxUSE_MENUS
431 m_panel
= new wxPanel(this, wxID_ANY
);
433 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
435 // we have 2 panes: book with pages demonstrating the controls in the
436 // upper one and the log window with some buttons in the lower
438 int style
= wxBK_DEFAULT
;
439 // Uncomment to suppress page theme (draw in solid colour)
440 //style |= wxNB_NOPAGETHEME;
442 m_book
= new WidgetsBookCtrl(m_panel
, Widgets_BookCtrl
,
443 wxDefaultPosition
, wxDefaultSize
,
448 #ifndef __WXHANDHELD__
449 // the lower one only has the log listbox and a button to clear it
451 wxSizer
*sizerDown
= new wxStaticBoxSizer(
452 new wxStaticBox( m_panel
, wxID_ANY
, _T("&Log window") ),
455 m_lboxLog
= new wxListBox(m_panel
, wxID_ANY
);
456 sizerDown
->Add(m_lboxLog
, 1, wxGROW
| wxALL
, 5);
457 sizerDown
->SetMinSize(100, 150);
459 wxSizer
*sizerDown
= new wxBoxSizer(wxVERTICAL
);
462 wxBoxSizer
*sizerBtns
= new wxBoxSizer(wxHORIZONTAL
);
465 btn
= new wxButton(m_panel
, Widgets_ClearLog
, _T("Clear &log"));
467 sizerBtns
->Add(10, 0); // spacer
469 btn
= new wxButton(m_panel
, Widgets_Quit
, _T("E&xit"));
471 sizerDown
->Add(sizerBtns
, 0, wxALL
| wxALIGN_RIGHT
, 5);
473 // put everything together
474 sizerTop
->Add(m_book
, 1, wxGROW
| (wxALL
& ~(wxTOP
| wxBOTTOM
)), 10);
475 sizerTop
->Add(0, 5, 0, wxGROW
); // spacer in between
476 sizerTop
->Add(sizerDown
, 0, wxGROW
| (wxALL
& ~wxTOP
), 10);
478 #else // !__WXHANDHELD__/__WXHANDHELD__
480 sizerTop
->Add(m_book
, 1, wxGROW
| wxALL
);
482 #endif // __WXHANDHELD__
484 m_panel
->SetSizer(sizerTop
);
486 const wxSize sizeMin
= m_panel
->GetBestSize();
488 SetClientSize(sizeMin
);
489 SetMinClientSize(sizeMin
);
491 #if USE_LOG && !defined(__WXCOCOA__)
492 // wxCocoa's listbox is too flakey to use for logging right now
493 // now that everything is created we can redirect the log messages to the
495 m_logTarget
= new LboxLogger(m_lboxLog
, wxLog::GetActiveTarget());
496 wxLog::SetActiveTarget(m_logTarget
);
500 void WidgetsFrame::InitBook()
502 #if USE_ICONS_IN_BOOK
503 wxImageList
*imageList
= new wxImageList(ICON_SIZE
, ICON_SIZE
);
505 wxImage
img(sample_xpm
);
506 imageList
->Add(wxBitmap(img
.Scale(ICON_SIZE
, ICON_SIZE
)));
508 wxImageList
*imageList
= NULL
;
512 WidgetsBookCtrl
*books
[MAX_PAGES
];
515 ArrayWidgetsPage pages
[MAX_PAGES
];
516 wxArrayString labels
[MAX_PAGES
];
518 wxMenu
*menuPages
= new wxMenu
;
519 unsigned int nPage
= 0, nFKey
= 0;
520 int cat
, imageId
= 1;
522 // we need to first create all pages and only then add them to the book
523 // as we need the image list first
525 // we also construct the pages menu during this first iteration
526 for ( cat
= 0; cat
< MAX_PAGES
; cat
++ )
529 nPage
++; // increase for parent page
531 books
[cat
] = new WidgetsBookCtrl(m_book
,
538 for ( WidgetsPageInfo
*info
= WidgetsPage::ms_widgetPages
;
540 info
= info
->GetNext() )
542 if( (info
->GetCategories() & ( 1 << cat
)) == 0)
545 WidgetsPage
*page
= (*info
->GetCtor())(
552 pages
[cat
].Add(page
);
554 labels
[cat
].Add(info
->GetLabel());
555 if ( cat
== ALL_PAGE
)
557 wxString
radioLabel(info
->GetLabel());
561 radioLabel
<< wxT("\tF" ) << nFKey
;
564 menuPages
->AppendRadioItem(
565 Widgets_GoToPage
+ nPage
,
569 // consider only for book in book architecture
575 // consider only for treebook architecture (with subpages)
581 GetMenuBar()->Append(menuPages
, _T("&Page"));
583 #if USE_ICONS_IN_BOOK
584 m_book
->AssignImageList(imageList
);
587 for ( cat
= 0; cat
< MAX_PAGES
; cat
++ )
590 m_book
->AddPage(NULL
,WidgetsCategories
[cat
],false,0);
592 m_book
->AddPage(books
[cat
],WidgetsCategories
[cat
],false,0);
593 #if USE_ICONS_IN_BOOK
594 books
[cat
]->SetImageList(imageList
);
599 size_t count
= pages
[cat
].GetCount();
600 for ( size_t n
= 0; n
< count
; n
++ )
610 false, // don't select
617 wxEVT_COMMAND_WIDGETS_PAGE_CHANGED
,
618 wxWidgetsbookEventHandler(WidgetsFrame::OnPageChanged
) );
620 const bool pageSet
= wxPersistentRegisterAndRestore(m_book
);
623 // for treebook page #0 is empty parent page only so select the first page
624 // with some contents
626 m_book
->SetSelection(1);
628 // but ensure that the top of the tree is shown nevertheless
629 wxTreeCtrl
* const tree
= m_book
->GetTreeCtrl();
631 wxTreeItemIdValue cookie
;
632 tree
->EnsureVisible(tree
->GetFirstChild(tree
->GetRootItem(), cookie
));
636 // for other books set selection twice to force connected event handler
637 // to force lazy creation of initial visible content
638 m_book
->SetSelection(1);
639 m_book
->SetSelection(0);
641 #endif // USE_TREEBOOK
644 WidgetsPage
*WidgetsFrame::CurrentPage()
646 wxWindow
*page
= m_book
->GetCurrentPage();
649 WidgetsBookCtrl
*subBook
= wxStaticCast(page
, WidgetsBookCtrl
);
650 wxCHECK_MSG( subBook
, NULL
, _T("no WidgetsBookCtrl?") );
652 page
= subBook
->GetCurrentPage();
653 #endif // !USE_TREEBOOK
655 return wxStaticCast(page
, WidgetsPage
);
658 WidgetsFrame::~WidgetsFrame()
665 // ----------------------------------------------------------------------------
666 // WidgetsFrame event handlers
667 // ----------------------------------------------------------------------------
669 void WidgetsFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
675 void WidgetsFrame::OnButtonClearLog(wxCommandEvent
& WXUNUSED(event
))
683 void WidgetsFrame::OnPageChanging(WidgetsBookCtrlEvent
& event
)
686 // don't allow selection of entries without pages (categories)
687 if ( !m_book
->GetPage(event
.GetSelection()) )
694 void WidgetsFrame::OnPageChanged(WidgetsBookCtrlEvent
& event
)
696 const int sel
= event
.GetSelection();
698 // adjust "Page" menu selection
699 wxMenuItem
*item
= GetMenuBar()->FindItem(Widgets_GoToPage
+ sel
);
703 GetMenuBar()->Check(Widgets_BusyCursor
, false);
705 // create the pages on demand, otherwise the sample startup is too slow as
706 // it creates hundreds of controls
707 WidgetsPage
*page
= CurrentPage();
708 if ( page
->GetChildren().empty() )
710 wxWindowUpdateLocker
noUpdates(page
);
711 page
->CreateContent();
713 page
->GetSizer()->Fit(page
);
715 WidgetsBookCtrl
*book
= wxStaticCast(page
->GetParent(), WidgetsBookCtrl
);
717 for ( size_t i
= 0; i
< book
->GetPageCount(); ++i
)
719 wxWindow
*page
= book
->GetPage(i
);
722 size
.IncTo(page
->GetSize());
731 void WidgetsFrame::OnGoToPage(wxCommandEvent
& event
)
734 m_book
->SetSelection(event
.GetId() - Widgets_GoToPage
);
736 m_book
->SetSelection(m_book
->GetPageCount()-1);
737 WidgetsBookCtrl
*book
= wxStaticCast(m_book
->GetCurrentPage(), WidgetsBookCtrl
);
738 book
->SetSelection(event
.GetId() - Widgets_GoToPage
);
744 void WidgetsFrame::OnSetTooltip(wxCommandEvent
& WXUNUSED(event
))
746 static wxString s_tip
= _T("This is a tooltip");
748 wxTextEntryDialog dialog
751 _T("Tooltip text (may use \\n, leave empty to remove): "),
752 _T("Widgets sample"),
756 if ( dialog
.ShowModal() != wxID_OK
)
759 s_tip
= dialog
.GetValue();
760 s_tip
.Replace(_T("\\n"), _T("\n"));
762 WidgetsPage
*page
= CurrentPage();
764 page
->GetWidget()->SetToolTip(s_tip
);
766 wxControl
*ctrl2
= page
->GetWidget2();
768 ctrl2
->SetToolTip(s_tip
);
771 #endif // wxUSE_TOOLTIPS
773 void WidgetsFrame::OnSetFgCol(wxCommandEvent
& WXUNUSED(event
))
776 // allow for debugging the default colour the first time this is called
777 WidgetsPage
*page
= CurrentPage();
780 m_colFg
= page
->GetForegroundColour();
782 wxColour col
= wxGetColourFromUser(this, m_colFg
);
788 page
->GetWidget()->SetForegroundColour(m_colFg
);
789 page
->GetWidget()->Refresh();
791 wxControl
*ctrl2
= page
->GetWidget2();
794 ctrl2
->SetForegroundColour(m_colFg
);
798 wxLogMessage(_T("Colour selection dialog not available in current build."));
802 void WidgetsFrame::OnSetBgCol(wxCommandEvent
& WXUNUSED(event
))
805 WidgetsPage
*page
= CurrentPage();
808 m_colBg
= page
->GetBackgroundColour();
810 wxColour col
= wxGetColourFromUser(this, m_colBg
);
816 page
->GetWidget()->SetBackgroundColour(m_colBg
);
817 page
->GetWidget()->Refresh();
819 wxControl
*ctrl2
= page
->GetWidget2();
822 ctrl2
->SetBackgroundColour(m_colFg
);
826 wxLogMessage(_T("Colour selection dialog not available in current build."));
830 void WidgetsFrame::OnSetFont(wxCommandEvent
& WXUNUSED(event
))
833 WidgetsPage
*page
= CurrentPage();
836 m_font
= page
->GetFont();
838 wxFont font
= wxGetFontFromUser(this, m_font
);
844 page
->GetWidget()->SetFont(m_font
);
845 page
->GetWidget()->Refresh();
847 wxControl
*ctrl2
= page
->GetWidget2();
850 ctrl2
->SetFont(m_font
);
854 wxLogMessage(_T("Font selection dialog not available in current build."));
858 void WidgetsFrame::OnEnable(wxCommandEvent
& event
)
860 CurrentPage()->GetWidget()->Enable(event
.IsChecked());
861 if (CurrentPage()->GetWidget2())
862 CurrentPage()->GetWidget2()->Enable(event
.IsChecked());
865 void WidgetsFrame::OnSetBorder(wxCommandEvent
& event
)
868 switch ( event
.GetId() )
870 case Widgets_BorderNone
: border
= wxBORDER_NONE
; break;
871 case Widgets_BorderStatic
: border
= wxBORDER_STATIC
; break;
872 case Widgets_BorderSimple
: border
= wxBORDER_SIMPLE
; break;
873 case Widgets_BorderRaised
: border
= wxBORDER_RAISED
; break;
874 case Widgets_BorderSunken
: border
= wxBORDER_SUNKEN
; break;
875 case Widgets_BorderDouble
: border
= wxBORDER_DOUBLE
; break;
878 wxFAIL_MSG( _T("unknown border style") );
881 case Widgets_BorderDefault
: border
= wxBORDER_DEFAULT
; break;
884 WidgetsPage::ms_defaultFlags
&= ~wxBORDER_MASK
;
885 WidgetsPage::ms_defaultFlags
|= border
;
887 WidgetsPage
*page
= CurrentPage();
889 page
->RecreateWidget();
892 void WidgetsFrame::OnToggleGlobalBusyCursor(wxCommandEvent
& event
)
894 if ( event
.IsChecked() )
900 void WidgetsFrame::OnToggleBusyCursor(wxCommandEvent
& event
)
902 CurrentPage()->GetWidget()->SetCursor(*(event
.IsChecked()
904 : wxSTANDARD_CURSOR
));
907 void WidgetsFrame::OnDisableAutoComplete(wxCommandEvent
& WXUNUSED(event
))
909 wxTextEntryBase
*entry
= CurrentPage()->GetTextEntry();
910 wxCHECK_RET( entry
, "menu item should be disabled" );
912 if ( entry
->AutoComplete(wxArrayString()) )
913 wxLogMessage("Disabled auto completion.");
915 wxLogMessage("AutoComplete() failed.");
918 void WidgetsFrame::OnAutoCompleteFixed(wxCommandEvent
& WXUNUSED(event
))
920 wxTextEntryBase
*entry
= CurrentPage()->GetTextEntry();
921 wxCHECK_RET( entry
, "menu item should be disabled" );
923 wxArrayString completion_choices
;
925 // add a few strings so a completion occurs on any letter typed
926 for ( char idxc
= 'a'; idxc
< 'z'; ++idxc
)
927 completion_choices
.push_back(wxString::Format("%c%c", idxc
, idxc
));
929 completion_choices
.push_back("is this string for test?");
930 completion_choices
.push_back("this is a test string");
931 completion_choices
.push_back("this is another test string");
932 completion_choices
.push_back("this string is for test");
934 if ( entry
->AutoComplete(completion_choices
) )
935 wxLogMessage("Enabled auto completion of a set of fixed strings.");
937 wxLogMessage("AutoComplete() failed.");
940 void WidgetsFrame::OnAutoCompleteFilenames(wxCommandEvent
& WXUNUSED(event
))
942 wxTextEntryBase
*entry
= CurrentPage()->GetTextEntry();
943 wxCHECK_RET( entry
, "menu item should be disabled" );
945 if ( entry
->AutoCompleteFileNames() )
946 wxLogMessage("Enable auto completion of file names.");
948 wxLogMessage("AutoCompleteFileNames() failed.");
951 #endif // wxUSE_MENUS
953 // ----------------------------------------------------------------------------
955 // ----------------------------------------------------------------------------
957 WidgetsPageInfo::WidgetsPageInfo(Constructor ctor
, const wxChar
*label
, int categories
)
959 , m_categories(categories
)
965 // dummy sorting: add and immediately sort in the list according to label
966 if ( WidgetsPage::ms_widgetPages
)
968 WidgetsPageInfo
*node_prev
= WidgetsPage::ms_widgetPages
;
969 if ( wxStrcmp(label
, node_prev
->GetLabel().c_str()) < 0 )
973 WidgetsPage::ms_widgetPages
= this;
977 WidgetsPageInfo
*node_next
;
980 node_next
= node_prev
->GetNext();
983 // add if between two
984 if ( wxStrcmp(label
, node_next
->GetLabel().c_str()) < 0 )
986 node_prev
->SetNext(this);
988 // force to break loop
995 node_prev
->SetNext(this);
998 node_prev
= node_next
;
1000 while ( node_next
);
1006 WidgetsPage::ms_widgetPages
= this;
1010 // ----------------------------------------------------------------------------
1012 // ----------------------------------------------------------------------------
1014 int WidgetsPage::ms_defaultFlags
= wxBORDER_DEFAULT
;
1015 WidgetsPageInfo
*WidgetsPage::ms_widgetPages
= NULL
;
1017 WidgetsPage::WidgetsPage(WidgetsBookCtrl
*book
,
1018 wxImageList
*imaglist
,
1019 const char *const icon
[])
1020 : wxPanel(book
, wxID_ANY
,
1021 wxDefaultPosition
, wxDefaultSize
,
1022 wxNO_FULL_REPAINT_ON_RESIZE
|
1026 #if USE_ICONS_IN_BOOK
1027 imaglist
->Add(wxBitmap(wxImage(icon
).Scale(ICON_SIZE
, ICON_SIZE
)));
1029 wxUnusedVar(imaglist
);
1034 wxSizer
*WidgetsPage::CreateSizerWithText(wxControl
*control
,
1036 wxTextCtrl
**ppText
)
1038 wxSizer
*sizerRow
= new wxBoxSizer(wxHORIZONTAL
);
1039 wxTextCtrl
*text
= new wxTextCtrl(this, id
, wxEmptyString
,
1040 wxDefaultPosition
, wxDefaultSize
, wxTE_PROCESS_ENTER
);
1042 sizerRow
->Add(control
, 0, wxRIGHT
| wxALIGN_CENTRE_VERTICAL
, 5);
1043 sizerRow
->Add(text
, 1, wxLEFT
| wxALIGN_CENTRE_VERTICAL
, 5);
1051 // create a sizer containing a label and a text ctrl
1052 wxSizer
*WidgetsPage::CreateSizerWithTextAndLabel(const wxString
& label
,
1054 wxTextCtrl
**ppText
)
1056 return CreateSizerWithText(new wxStaticText(this, wxID_ANY
, label
),
1060 // create a sizer containing a button and a text ctrl
1061 wxSizer
*WidgetsPage::CreateSizerWithTextAndButton(wxWindowID idBtn
,
1062 const wxString
& label
,
1064 wxTextCtrl
**ppText
)
1066 return CreateSizerWithText(new wxButton(this, idBtn
, label
), id
, ppText
);
1069 wxCheckBox
*WidgetsPage::CreateCheckBoxAndAddToSizer(wxSizer
*sizer
,
1070 const wxString
& label
,
1073 wxCheckBox
*checkbox
= new wxCheckBox(this, id
, label
);
1074 sizer
->Add(checkbox
, 0, wxLEFT
| wxRIGHT
, 5);
1075 sizer
->Add(0, 2, 0, wxGROW
); // spacer