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 wxSUPPRESS_DOLOG_HIDE_WARNING()
233 wxSUPPRESS_DOLOGSTRING_HIDE_WARNING()
235 // implement sink functions
236 virtual void DoLog(wxLogLevel level
, const wxString
& str
, time_t t
)
238 // don't put trace messages into listbox or we can get into infinite
240 if ( level
== wxLOG_Trace
)
243 m_logOld
->Log(level
, str
, t
);
247 wxLog::DoLog(level
, str
, t
);
251 virtual void DoLogString(const wxString
& str
, time_t WXUNUSED(t
))
257 #ifdef __WXUNIVERSAL__
258 m_lbox
->AppendAndEnsureVisible(msg
);
259 #else // other ports don't have this method yet
261 m_lbox
->SetFirstItem(m_lbox
->GetCount() - 1);
265 // the control we use
268 // the old log target
274 WX_DEFINE_ARRAY_PTR(WidgetsPage
*, ArrayWidgetsPage
);
276 // ----------------------------------------------------------------------------
278 // ----------------------------------------------------------------------------
280 IMPLEMENT_APP(WidgetsApp
)
282 // ----------------------------------------------------------------------------
284 // ----------------------------------------------------------------------------
286 BEGIN_EVENT_TABLE(WidgetsFrame
, wxFrame
)
288 EVT_BUTTON(Widgets_ClearLog
, WidgetsFrame::OnButtonClearLog
)
290 EVT_BUTTON(Widgets_Quit
, WidgetsFrame::OnExit
)
293 EVT_MENU(Widgets_SetTooltip
, WidgetsFrame::OnSetTooltip
)
294 #endif // wxUSE_TOOLTIPS
297 EVT_WIDGETS_PAGE_CHANGING(wxID_ANY
, WidgetsFrame::OnPageChanging
)
298 EVT_MENU_RANGE(Widgets_GoToPage
, Widgets_GoToPageLast
,
299 WidgetsFrame::OnGoToPage
)
301 EVT_MENU(Widgets_SetFgColour
, WidgetsFrame::OnSetFgCol
)
302 EVT_MENU(Widgets_SetBgColour
, WidgetsFrame::OnSetBgCol
)
303 EVT_MENU(Widgets_SetFont
, WidgetsFrame::OnSetFont
)
304 EVT_MENU(Widgets_Enable
, WidgetsFrame::OnEnable
)
306 EVT_MENU_RANGE(Widgets_BorderNone
, Widgets_BorderDefault
,
307 WidgetsFrame::OnSetBorder
)
309 EVT_MENU(Widgets_GlobalBusyCursor
, WidgetsFrame::OnToggleGlobalBusyCursor
)
310 EVT_MENU(Widgets_BusyCursor
, WidgetsFrame::OnToggleBusyCursor
)
312 EVT_MENU(TextEntry_DisableAutoComplete
, WidgetsFrame::OnDisableAutoComplete
)
313 EVT_MENU(TextEntry_AutoCompleteFixed
, WidgetsFrame::OnAutoCompleteFixed
)
314 EVT_MENU(TextEntry_AutoCompleteFilenames
, WidgetsFrame::OnAutoCompleteFilenames
)
316 EVT_MENU(TextEntry_SetHint
, WidgetsFrame::OnSetHint
)
318 EVT_UPDATE_UI_RANGE(TextEntry_Begin
, TextEntry_End
- 1,
319 WidgetsFrame::OnUpdateTextUI
)
321 EVT_MENU(wxID_EXIT
, WidgetsFrame::OnExit
)
322 #endif // wxUSE_MENUS
325 // ============================================================================
327 // ============================================================================
329 // ----------------------------------------------------------------------------
331 // ----------------------------------------------------------------------------
333 bool WidgetsApp::OnInit()
335 if ( !wxApp::OnInit() )
338 SetVendorName("wxWidgets_Samples");
340 // the reason for having these ifdef's is that I often run two copies of
341 // this sample side by side and it is useful to see which one is which
343 #if defined(__WXUNIVERSAL__)
344 title
= _T("wxUniv/");
347 #if defined(__WXMSW__)
348 title
+= _T("wxMSW");
349 #elif defined(__WXGTK__)
350 title
+= _T("wxGTK");
351 #elif defined(__WXMAC__)
352 title
+= _T("wxMAC");
353 #elif defined(__WXMOTIF__)
354 title
+= _T("wxMOTIF");
356 title
+= _T("wxPALMOS5");
358 title
+= _T("wxPALMOS6");
360 title
+= _T("wxWidgets");
363 wxFrame
*frame
= new WidgetsFrame(title
+ _T(" widgets demo"));
369 // ----------------------------------------------------------------------------
370 // WidgetsFrame construction
371 // ----------------------------------------------------------------------------
373 WidgetsFrame::WidgetsFrame(const wxString
& title
)
374 : wxFrame(NULL
, wxID_ANY
, title
)
377 const bool sizeSet
= wxPersistentRegisterAndRestore(this);
379 // set the frame icon
380 SetIcon(wxICON(sample
));
390 // create the menubar
391 wxMenuBar
*mbar
= new wxMenuBar
;
392 wxMenu
*menuWidget
= new wxMenu
;
394 menuWidget
->Append(Widgets_SetTooltip
, _T("Set &tooltip...\tCtrl-T"));
395 menuWidget
->AppendSeparator();
396 #endif // wxUSE_TOOLTIPS
397 menuWidget
->Append(Widgets_SetFgColour
, _T("Set &foreground...\tCtrl-F"));
398 menuWidget
->Append(Widgets_SetBgColour
, _T("Set &background...\tCtrl-B"));
399 menuWidget
->Append(Widgets_SetFont
, _T("Set f&ont...\tCtrl-O"));
400 menuWidget
->AppendCheckItem(Widgets_Enable
, _T("&Enable/disable\tCtrl-E"));
402 wxMenu
*menuBorders
= new wxMenu
;
403 menuBorders
->AppendRadioItem(Widgets_BorderDefault
, _T("De&fault\tCtrl-Shift-9"));
404 menuBorders
->AppendRadioItem(Widgets_BorderNone
, _T("&None\tCtrl-Shift-0"));
405 menuBorders
->AppendRadioItem(Widgets_BorderSimple
, _T("&Simple\tCtrl-Shift-1"));
406 menuBorders
->AppendRadioItem(Widgets_BorderDouble
, _T("&Double\tCtrl-Shift-2"));
407 menuBorders
->AppendRadioItem(Widgets_BorderStatic
, _T("Stati&c\tCtrl-Shift-3"));
408 menuBorders
->AppendRadioItem(Widgets_BorderRaised
, _T("&Raised\tCtrl-Shift-4"));
409 menuBorders
->AppendRadioItem(Widgets_BorderSunken
, _T("S&unken\tCtrl-Shift-5"));
410 menuWidget
->AppendSubMenu(menuBorders
, _T("Set &border"));
412 menuWidget
->AppendSeparator();
413 menuWidget
->AppendCheckItem(Widgets_GlobalBusyCursor
,
414 _T("Toggle &global busy cursor\tCtrl-Shift-U"));
415 menuWidget
->AppendCheckItem(Widgets_BusyCursor
,
416 _T("Toggle b&usy cursor\tCtrl-U"));
418 menuWidget
->AppendSeparator();
419 menuWidget
->Append(wxID_EXIT
, _T("&Quit\tCtrl-Q"));
420 mbar
->Append(menuWidget
, _T("&Widget"));
422 wxMenu
*menuTextEntry
= new wxMenu
;
423 menuTextEntry
->AppendRadioItem(TextEntry_DisableAutoComplete
,
424 _T("&Disable auto-completion"));
425 menuTextEntry
->AppendRadioItem(TextEntry_AutoCompleteFixed
,
426 _T("Fixed-&list auto-completion"));
427 menuTextEntry
->AppendRadioItem(TextEntry_AutoCompleteFilenames
,
428 _T("&Files names auto-completion"));
429 menuTextEntry
->AppendSeparator();
430 menuTextEntry
->Append(TextEntry_SetHint
, "Set help &hint");
432 mbar
->Append(menuTextEntry
, _T("&Text"));
436 mbar
->Check(Widgets_Enable
, true);
437 #endif // wxUSE_MENUS
440 m_panel
= new wxPanel(this, wxID_ANY
);
442 wxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
444 // we have 2 panes: book with pages demonstrating the controls in the
445 // upper one and the log window with some buttons in the lower
447 int style
= wxBK_DEFAULT
;
448 // Uncomment to suppress page theme (draw in solid colour)
449 //style |= wxNB_NOPAGETHEME;
451 m_book
= new WidgetsBookCtrl(m_panel
, Widgets_BookCtrl
,
452 wxDefaultPosition
, wxDefaultSize
,
457 #ifndef __WXHANDHELD__
458 // the lower one only has the log listbox and a button to clear it
460 wxSizer
*sizerDown
= new wxStaticBoxSizer(
461 new wxStaticBox( m_panel
, wxID_ANY
, _T("&Log window") ),
464 m_lboxLog
= new wxListBox(m_panel
, wxID_ANY
);
465 sizerDown
->Add(m_lboxLog
, 1, wxGROW
| wxALL
, 5);
466 sizerDown
->SetMinSize(100, 150);
468 wxSizer
*sizerDown
= new wxBoxSizer(wxVERTICAL
);
471 wxBoxSizer
*sizerBtns
= new wxBoxSizer(wxHORIZONTAL
);
474 btn
= new wxButton(m_panel
, Widgets_ClearLog
, _T("Clear &log"));
476 sizerBtns
->Add(10, 0); // spacer
478 btn
= new wxButton(m_panel
, Widgets_Quit
, _T("E&xit"));
480 sizerDown
->Add(sizerBtns
, 0, wxALL
| wxALIGN_RIGHT
, 5);
482 // put everything together
483 sizerTop
->Add(m_book
, 1, wxGROW
| (wxALL
& ~(wxTOP
| wxBOTTOM
)), 10);
484 sizerTop
->Add(0, 5, 0, wxGROW
); // spacer in between
485 sizerTop
->Add(sizerDown
, 0, wxGROW
| (wxALL
& ~wxTOP
), 10);
487 #else // !__WXHANDHELD__/__WXHANDHELD__
489 sizerTop
->Add(m_book
, 1, wxGROW
| wxALL
);
491 #endif // __WXHANDHELD__
493 m_panel
->SetSizer(sizerTop
);
495 const wxSize sizeMin
= m_panel
->GetBestSize();
497 SetClientSize(sizeMin
);
498 SetMinClientSize(sizeMin
);
500 #if USE_LOG && !defined(__WXCOCOA__)
501 // wxCocoa's listbox is too flakey to use for logging right now
502 // now that everything is created we can redirect the log messages to the
504 m_logTarget
= new LboxLogger(m_lboxLog
, wxLog::GetActiveTarget());
505 wxLog::SetActiveTarget(m_logTarget
);
509 void WidgetsFrame::InitBook()
511 #if USE_ICONS_IN_BOOK
512 wxImageList
*imageList
= new wxImageList(ICON_SIZE
, ICON_SIZE
);
514 wxImage
img(sample_xpm
);
515 imageList
->Add(wxBitmap(img
.Scale(ICON_SIZE
, ICON_SIZE
)));
517 wxImageList
*imageList
= NULL
;
521 WidgetsBookCtrl
*books
[MAX_PAGES
];
524 ArrayWidgetsPage pages
[MAX_PAGES
];
525 wxArrayString labels
[MAX_PAGES
];
527 wxMenu
*menuPages
= new wxMenu
;
528 unsigned int nPage
= 0, nFKey
= 0;
529 int cat
, imageId
= 1;
531 // we need to first create all pages and only then add them to the book
532 // as we need the image list first
534 // we also construct the pages menu during this first iteration
535 for ( cat
= 0; cat
< MAX_PAGES
; cat
++ )
538 nPage
++; // increase for parent page
540 books
[cat
] = new WidgetsBookCtrl(m_book
,
547 for ( WidgetsPageInfo
*info
= WidgetsPage::ms_widgetPages
;
549 info
= info
->GetNext() )
551 if( (info
->GetCategories() & ( 1 << cat
)) == 0)
554 WidgetsPage
*page
= (*info
->GetCtor())(
561 pages
[cat
].Add(page
);
563 labels
[cat
].Add(info
->GetLabel());
564 if ( cat
== ALL_PAGE
)
566 wxString
radioLabel(info
->GetLabel());
570 radioLabel
<< wxT("\tF" ) << nFKey
;
573 menuPages
->AppendRadioItem(
574 Widgets_GoToPage
+ nPage
,
578 // consider only for book in book architecture
584 // consider only for treebook architecture (with subpages)
590 GetMenuBar()->Append(menuPages
, _T("&Page"));
592 #if USE_ICONS_IN_BOOK
593 m_book
->AssignImageList(imageList
);
596 for ( cat
= 0; cat
< MAX_PAGES
; cat
++ )
599 m_book
->AddPage(NULL
,WidgetsCategories
[cat
],false,0);
601 m_book
->AddPage(books
[cat
],WidgetsCategories
[cat
],false,0);
602 #if USE_ICONS_IN_BOOK
603 books
[cat
]->SetImageList(imageList
);
608 size_t count
= pages
[cat
].GetCount();
609 for ( size_t n
= 0; n
< count
; n
++ )
619 false, // don't select
626 wxEVT_COMMAND_WIDGETS_PAGE_CHANGED
,
627 wxWidgetsbookEventHandler(WidgetsFrame::OnPageChanged
) );
629 const bool pageSet
= wxPersistentRegisterAndRestore(m_book
);
632 // for treebook page #0 is empty parent page only so select the first page
633 // with some contents
635 m_book
->SetSelection(1);
637 // but ensure that the top of the tree is shown nevertheless
638 wxTreeCtrl
* const tree
= m_book
->GetTreeCtrl();
640 wxTreeItemIdValue cookie
;
641 tree
->EnsureVisible(tree
->GetFirstChild(tree
->GetRootItem(), cookie
));
645 // for other books set selection twice to force connected event handler
646 // to force lazy creation of initial visible content
647 m_book
->SetSelection(1);
648 m_book
->SetSelection(0);
650 #endif // USE_TREEBOOK
653 WidgetsPage
*WidgetsFrame::CurrentPage()
655 wxWindow
*page
= m_book
->GetCurrentPage();
658 WidgetsBookCtrl
*subBook
= wxStaticCast(page
, WidgetsBookCtrl
);
659 wxCHECK_MSG( subBook
, NULL
, _T("no WidgetsBookCtrl?") );
661 page
= subBook
->GetCurrentPage();
662 #endif // !USE_TREEBOOK
664 return wxStaticCast(page
, WidgetsPage
);
667 WidgetsFrame::~WidgetsFrame()
674 // ----------------------------------------------------------------------------
675 // WidgetsFrame event handlers
676 // ----------------------------------------------------------------------------
678 void WidgetsFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
684 void WidgetsFrame::OnButtonClearLog(wxCommandEvent
& WXUNUSED(event
))
692 void WidgetsFrame::OnPageChanging(WidgetsBookCtrlEvent
& event
)
695 // don't allow selection of entries without pages (categories)
696 if ( !m_book
->GetPage(event
.GetSelection()) )
703 void WidgetsFrame::OnPageChanged(WidgetsBookCtrlEvent
& event
)
705 const int sel
= event
.GetSelection();
707 // adjust "Page" menu selection
708 wxMenuItem
*item
= GetMenuBar()->FindItem(Widgets_GoToPage
+ sel
);
712 GetMenuBar()->Check(Widgets_BusyCursor
, false);
714 // create the pages on demand, otherwise the sample startup is too slow as
715 // it creates hundreds of controls
716 WidgetsPage
*page
= CurrentPage();
717 if ( page
->GetChildren().empty() )
719 wxWindowUpdateLocker
noUpdates(page
);
720 page
->CreateContent();
722 page
->GetSizer()->Fit(page
);
724 WidgetsBookCtrl
*book
= wxStaticCast(page
->GetParent(), WidgetsBookCtrl
);
726 for ( size_t i
= 0; i
< book
->GetPageCount(); ++i
)
728 wxWindow
*page
= book
->GetPage(i
);
731 size
.IncTo(page
->GetSize());
740 void WidgetsFrame::OnGoToPage(wxCommandEvent
& event
)
743 m_book
->SetSelection(event
.GetId() - Widgets_GoToPage
);
745 m_book
->SetSelection(m_book
->GetPageCount()-1);
746 WidgetsBookCtrl
*book
= wxStaticCast(m_book
->GetCurrentPage(), WidgetsBookCtrl
);
747 book
->SetSelection(event
.GetId() - Widgets_GoToPage
);
753 void WidgetsFrame::OnSetTooltip(wxCommandEvent
& WXUNUSED(event
))
755 static wxString s_tip
= _T("This is a tooltip");
757 wxTextEntryDialog dialog
760 _T("Tooltip text (may use \\n, leave empty to remove): "),
761 _T("Widgets sample"),
765 if ( dialog
.ShowModal() != wxID_OK
)
768 s_tip
= dialog
.GetValue();
769 s_tip
.Replace(_T("\\n"), _T("\n"));
771 WidgetsPage
*page
= CurrentPage();
773 page
->GetWidget()->SetToolTip(s_tip
);
775 wxControl
*ctrl2
= page
->GetWidget2();
777 ctrl2
->SetToolTip(s_tip
);
780 #endif // wxUSE_TOOLTIPS
782 void WidgetsFrame::OnSetFgCol(wxCommandEvent
& WXUNUSED(event
))
785 // allow for debugging the default colour the first time this is called
786 WidgetsPage
*page
= CurrentPage();
789 m_colFg
= page
->GetForegroundColour();
791 wxColour col
= wxGetColourFromUser(this, m_colFg
);
797 page
->GetWidget()->SetForegroundColour(m_colFg
);
798 page
->GetWidget()->Refresh();
800 wxControl
*ctrl2
= page
->GetWidget2();
803 ctrl2
->SetForegroundColour(m_colFg
);
807 wxLogMessage(_T("Colour selection dialog not available in current build."));
811 void WidgetsFrame::OnSetBgCol(wxCommandEvent
& WXUNUSED(event
))
814 WidgetsPage
*page
= CurrentPage();
817 m_colBg
= page
->GetBackgroundColour();
819 wxColour col
= wxGetColourFromUser(this, m_colBg
);
825 page
->GetWidget()->SetBackgroundColour(m_colBg
);
826 page
->GetWidget()->Refresh();
828 wxControl
*ctrl2
= page
->GetWidget2();
831 ctrl2
->SetBackgroundColour(m_colFg
);
835 wxLogMessage(_T("Colour selection dialog not available in current build."));
839 void WidgetsFrame::OnSetFont(wxCommandEvent
& WXUNUSED(event
))
842 WidgetsPage
*page
= CurrentPage();
845 m_font
= page
->GetFont();
847 wxFont font
= wxGetFontFromUser(this, m_font
);
853 page
->GetWidget()->SetFont(m_font
);
854 page
->GetWidget()->Refresh();
856 wxControl
*ctrl2
= page
->GetWidget2();
859 ctrl2
->SetFont(m_font
);
863 wxLogMessage(_T("Font selection dialog not available in current build."));
867 void WidgetsFrame::OnEnable(wxCommandEvent
& event
)
869 CurrentPage()->GetWidget()->Enable(event
.IsChecked());
870 if (CurrentPage()->GetWidget2())
871 CurrentPage()->GetWidget2()->Enable(event
.IsChecked());
874 void WidgetsFrame::OnSetBorder(wxCommandEvent
& event
)
877 switch ( event
.GetId() )
879 case Widgets_BorderNone
: border
= wxBORDER_NONE
; break;
880 case Widgets_BorderStatic
: border
= wxBORDER_STATIC
; break;
881 case Widgets_BorderSimple
: border
= wxBORDER_SIMPLE
; break;
882 case Widgets_BorderRaised
: border
= wxBORDER_RAISED
; break;
883 case Widgets_BorderSunken
: border
= wxBORDER_SUNKEN
; break;
884 case Widgets_BorderDouble
: border
= wxBORDER_DOUBLE
; break;
887 wxFAIL_MSG( _T("unknown border style") );
890 case Widgets_BorderDefault
: border
= wxBORDER_DEFAULT
; break;
893 WidgetsPage::ms_defaultFlags
&= ~wxBORDER_MASK
;
894 WidgetsPage::ms_defaultFlags
|= border
;
896 WidgetsPage
*page
= CurrentPage();
898 page
->RecreateWidget();
901 void WidgetsFrame::OnToggleGlobalBusyCursor(wxCommandEvent
& event
)
903 if ( event
.IsChecked() )
909 void WidgetsFrame::OnToggleBusyCursor(wxCommandEvent
& event
)
911 CurrentPage()->GetWidget()->SetCursor(*(event
.IsChecked()
913 : wxSTANDARD_CURSOR
));
916 void WidgetsFrame::OnDisableAutoComplete(wxCommandEvent
& WXUNUSED(event
))
918 wxTextEntryBase
*entry
= CurrentPage()->GetTextEntry();
919 wxCHECK_RET( entry
, "menu item should be disabled" );
921 if ( entry
->AutoComplete(wxArrayString()) )
922 wxLogMessage("Disabled auto completion.");
924 wxLogMessage("AutoComplete() failed.");
927 void WidgetsFrame::OnAutoCompleteFixed(wxCommandEvent
& WXUNUSED(event
))
929 wxTextEntryBase
*entry
= CurrentPage()->GetTextEntry();
930 wxCHECK_RET( entry
, "menu item should be disabled" );
932 wxArrayString completion_choices
;
934 // add a few strings so a completion occurs on any letter typed
935 for ( char idxc
= 'a'; idxc
< 'z'; ++idxc
)
936 completion_choices
.push_back(wxString::Format("%c%c", idxc
, idxc
));
938 completion_choices
.push_back("is this string for test?");
939 completion_choices
.push_back("this is a test string");
940 completion_choices
.push_back("this is another test string");
941 completion_choices
.push_back("this string is for test");
943 if ( entry
->AutoComplete(completion_choices
) )
944 wxLogMessage("Enabled auto completion of a set of fixed strings.");
946 wxLogMessage("AutoComplete() failed.");
949 void WidgetsFrame::OnAutoCompleteFilenames(wxCommandEvent
& WXUNUSED(event
))
951 wxTextEntryBase
*entry
= CurrentPage()->GetTextEntry();
952 wxCHECK_RET( entry
, "menu item should be disabled" );
954 if ( entry
->AutoCompleteFileNames() )
955 wxLogMessage("Enable auto completion of file names.");
957 wxLogMessage("AutoCompleteFileNames() failed.");
960 void WidgetsFrame::OnSetHint(wxCommandEvent
& WXUNUSED(event
))
962 wxTextEntryBase
*entry
= CurrentPage()->GetTextEntry();
963 wxCHECK_RET( entry
, "menu item should be disabled" );
965 static wxString
s_hint("Type here");
967 hint
= wxGetTextFromUser("Text hint:", "Widgets sample", s_hint
, this);
973 if ( entry
->SetHint(hint
) )
974 wxLogMessage("Set hint to \"%s\".", hint
);
976 wxLogMessage("Text hints not supported.");
979 #endif // wxUSE_MENUS
981 // ----------------------------------------------------------------------------
983 // ----------------------------------------------------------------------------
985 WidgetsPageInfo::WidgetsPageInfo(Constructor ctor
, const wxChar
*label
, int categories
)
987 , m_categories(categories
)
993 // dummy sorting: add and immediately sort in the list according to label
994 if ( WidgetsPage::ms_widgetPages
)
996 WidgetsPageInfo
*node_prev
= WidgetsPage::ms_widgetPages
;
997 if ( wxStrcmp(label
, node_prev
->GetLabel().c_str()) < 0 )
1001 WidgetsPage::ms_widgetPages
= this;
1005 WidgetsPageInfo
*node_next
;
1008 node_next
= node_prev
->GetNext();
1011 // add if between two
1012 if ( wxStrcmp(label
, node_next
->GetLabel().c_str()) < 0 )
1014 node_prev
->SetNext(this);
1016 // force to break loop
1023 node_prev
->SetNext(this);
1026 node_prev
= node_next
;
1028 while ( node_next
);
1034 WidgetsPage::ms_widgetPages
= this;
1038 // ----------------------------------------------------------------------------
1040 // ----------------------------------------------------------------------------
1042 int WidgetsPage::ms_defaultFlags
= wxBORDER_DEFAULT
;
1043 WidgetsPageInfo
*WidgetsPage::ms_widgetPages
= NULL
;
1045 WidgetsPage::WidgetsPage(WidgetsBookCtrl
*book
,
1046 wxImageList
*imaglist
,
1047 const char *const icon
[])
1048 : wxPanel(book
, wxID_ANY
,
1049 wxDefaultPosition
, wxDefaultSize
,
1050 wxNO_FULL_REPAINT_ON_RESIZE
|
1054 #if USE_ICONS_IN_BOOK
1055 imaglist
->Add(wxBitmap(wxImage(icon
).Scale(ICON_SIZE
, ICON_SIZE
)));
1057 wxUnusedVar(imaglist
);
1062 wxSizer
*WidgetsPage::CreateSizerWithText(wxControl
*control
,
1064 wxTextCtrl
**ppText
)
1066 wxSizer
*sizerRow
= new wxBoxSizer(wxHORIZONTAL
);
1067 wxTextCtrl
*text
= new wxTextCtrl(this, id
, wxEmptyString
,
1068 wxDefaultPosition
, wxDefaultSize
, wxTE_PROCESS_ENTER
);
1070 sizerRow
->Add(control
, 0, wxRIGHT
| wxALIGN_CENTRE_VERTICAL
, 5);
1071 sizerRow
->Add(text
, 1, wxLEFT
| wxALIGN_CENTRE_VERTICAL
, 5);
1079 // create a sizer containing a label and a text ctrl
1080 wxSizer
*WidgetsPage::CreateSizerWithTextAndLabel(const wxString
& label
,
1082 wxTextCtrl
**ppText
)
1084 return CreateSizerWithText(new wxStaticText(this, wxID_ANY
, label
),
1088 // create a sizer containing a button and a text ctrl
1089 wxSizer
*WidgetsPage::CreateSizerWithTextAndButton(wxWindowID idBtn
,
1090 const wxString
& label
,
1092 wxTextCtrl
**ppText
)
1094 return CreateSizerWithText(new wxButton(this, idBtn
, label
), id
, ppText
);
1097 wxCheckBox
*WidgetsPage::CreateCheckBoxAndAddToSizer(wxSizer
*sizer
,
1098 const wxString
& label
,
1101 wxCheckBox
*checkbox
= new wxCheckBox(this, id
, label
);
1102 sizer
->Add(checkbox
, 0, wxLEFT
| wxRIGHT
, 5);
1103 sizer
->Add(0, 2, 0, wxGROW
); // spacer