1 /////////////////////////////////////////////////////////////////////////////
2 // Name: samples/notebook/notebook.cpp
3 // Purpose: a sample demonstrating notebook usage
4 // Author: Julian Smart
5 // Modified by: Dimitri Schoolwerth
8 // Copyright: (c) 1998-2002 wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/imaglist.h"
24 #include "wx/artprov.h"
25 #include "wx/cshelp.h"
29 #if !defined(__WXMSW__) && !defined(__WXPM__)
30 #include "../sample.xpm"
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
41 if ( !wxApp::OnInit() )
45 wxHelpProvider::Set( new wxSimpleHelpProvider
);
48 // Create the main window
49 MyFrame
*frame
= new MyFrame();
51 // Problem with generic wxNotebook implementation whereby it doesn't size
52 // properly unless you set the size again
53 #if defined(__WXMOTIF__)
55 frame
->GetSize(& width
, & height
);
56 frame
->SetSize(wxDefaultCoord
, wxDefaultCoord
, width
, height
);
65 //-----------------------------------------------------------------------------
67 //-----------------------------------------------------------------------------
69 wxPanel
*CreateUserCreatedPage(wxBookCtrlBase
*parent
)
71 wxPanel
*panel
= new wxPanel(parent
);
74 panel
->SetHelpText( wxT( "Panel with a Button" ) );
77 (void) new wxButton( panel
, wxID_ANY
, wxT("Button"),
78 wxPoint(10, 10), wxDefaultSize
);
83 wxPanel
*CreateRadioButtonsPage(wxBookCtrlBase
*parent
)
85 wxPanel
*panel
= new wxPanel(parent
);
88 panel
->SetHelpText( wxT( "Panel with some Radio Buttons" ) );
92 { wxT("Fox"), wxT("Hare"), wxT("Rabbit"),
93 wxT("Sabre-toothed tiger"), wxT("T Rex") };
95 wxRadioBox
*radiobox1
= new wxRadioBox(panel
, wxID_ANY
, wxT("Choose one"),
96 wxDefaultPosition
, wxDefaultSize
, 5, animals
, 2, wxRA_SPECIFY_ROWS
);
98 wxString computers
[] =
99 { wxT("Amiga"), wxT("Commodore 64"), wxT("PET"),
102 wxRadioBox
*radiobox2
= new wxRadioBox(panel
, wxID_ANY
,
103 wxT("Choose your favourite"), wxDefaultPosition
, wxDefaultSize
,
104 4, computers
, 0, wxRA_SPECIFY_COLS
);
106 wxBoxSizer
*sizerPanel
= new wxBoxSizer(wxVERTICAL
);
107 sizerPanel
->Add(radiobox1
, 2, wxEXPAND
);
108 sizerPanel
->Add(radiobox2
, 1, wxEXPAND
);
109 panel
->SetSizer(sizerPanel
);
114 wxPanel
*CreateVetoPage(wxBookCtrlBase
*parent
)
116 wxPanel
*panel
= new wxPanel(parent
);
119 panel
->SetHelpText( wxT( "An empty panel" ) );
122 (void) new wxStaticText( panel
, wxID_ANY
,
123 wxT("This page intentionally left blank"),
129 wxPanel
*CreateBigButtonPage(wxBookCtrlBase
*parent
)
131 wxPanel
*panel
= new wxPanel(parent
);
134 panel
->SetHelpText( wxT( "Panel with a maximized button" ) );
137 wxButton
*buttonBig
= new wxButton(panel
, wxID_ANY
, wxT("Maximized button"));
139 wxBoxSizer
*sizerPanel
= new wxBoxSizer(wxVERTICAL
);
140 sizerPanel
->Add(buttonBig
, 1, wxEXPAND
);
141 panel
->SetSizer(sizerPanel
);
146 wxPanel
*CreateInsertPage(wxBookCtrlBase
*parent
)
148 wxPanel
*panel
= new wxPanel(parent
);
151 panel
->SetHelpText( wxT( "Maroon panel" ) );
154 panel
->SetBackgroundColour( wxColour( wxT("MAROON") ) );
155 (void) new wxStaticText( panel
, wxID_ANY
,
156 wxT("This page has been inserted, not added."),
162 int GetIconIndex(wxBookCtrlBase
* bookCtrl
)
164 if (bookCtrl
&& bookCtrl
->GetImageList())
166 int nImages
= bookCtrl
->GetImageList()->GetImageCount();
169 return bookCtrl
->GetPageCount() % nImages
;
176 void CreateInitialPages(wxBookCtrlBase
*parent
)
178 // Create and add some panels to the notebook
180 wxPanel
*panel
= CreateRadioButtonsPage(parent
);
181 parent
->AddPage( panel
, RADIOBUTTONS_PAGE_NAME
, false, GetIconIndex(parent
) );
183 panel
= CreateVetoPage(parent
);
184 parent
->AddPage( panel
, VETO_PAGE_NAME
, false, GetIconIndex(parent
) );
186 panel
= CreateBigButtonPage(parent
);
187 parent
->AddPage( panel
, MAXIMIZED_BUTTON_PAGE_NAME
, false, GetIconIndex(parent
) );
189 panel
= CreateInsertPage(parent
);
190 parent
->InsertPage( 0, panel
, I_WAS_INSERTED_PAGE_NAME
, false, GetIconIndex(parent
) );
192 parent
->SetSelection(1);
195 wxPanel
*CreatePage(wxBookCtrlBase
*parent
, const wxString
&pageName
)
197 if ( pageName
.Contains(INSERTED_PAGE_NAME
) ||
198 pageName
.Contains(ADDED_PAGE_NAME
) ||
199 pageName
.Contains(ADDED_SUB_PAGE_NAME
) ||
200 pageName
.Contains(ADDED_PAGE_NAME_BEFORE
) )
201 return CreateUserCreatedPage(parent
);
203 if ( pageName
== I_WAS_INSERTED_PAGE_NAME
)
204 return CreateInsertPage(parent
);
206 if ( pageName
== VETO_PAGE_NAME
)
207 return CreateVetoPage(parent
);
209 if ( pageName
== RADIOBUTTONS_PAGE_NAME
)
210 return CreateRadioButtonsPage(parent
);
212 if ( pageName
== MAXIMIZED_BUTTON_PAGE_NAME
)
213 return CreateBigButtonPage(parent
);
215 wxFAIL_MSG( wxT("unknown page name") );
221 //-----------------------------------------------------------------------------
223 //-----------------------------------------------------------------------------
225 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
227 EVT_MENU_RANGE(ID_BOOK_NOTEBOOK
, ID_BOOK_MAX
, MyFrame::OnType
)
228 EVT_MENU_RANGE(ID_ORIENT_DEFAULT
, ID_ORIENT_MAX
, MyFrame::OnOrient
)
229 EVT_MENU(ID_SHOW_IMAGES
, MyFrame::OnShowImages
)
230 EVT_MENU_RANGE(ID_FIXEDWIDTH
, ID_HORZ_LAYOUT
, MyFrame::OnStyle
)
231 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
234 EVT_MENU(ID_ADD_PAGE
, MyFrame::OnAddPage
)
235 EVT_MENU(ID_ADD_PAGE_NO_SELECT
, MyFrame::OnAddPageNoSelect
)
236 EVT_MENU(ID_INSERT_PAGE
, MyFrame::OnInsertPage
)
237 EVT_MENU(ID_DELETE_CUR_PAGE
, MyFrame::OnDeleteCurPage
)
238 EVT_MENU(ID_DELETE_LAST_PAGE
, MyFrame::OnDeleteLastPage
)
239 EVT_MENU(ID_NEXT_PAGE
, MyFrame::OnNextPage
)
240 EVT_MENU(ID_CHANGE_SELECTION
, MyFrame::OnChangeSelection
)
241 EVT_MENU(ID_SET_SELECTION
, MyFrame::OnSetSelection
)
244 EVT_MENU(ID_CONTEXT_HELP
, MyFrame::OnContextHelp
)
246 EVT_MENU(ID_HITTEST
, MyFrame::OnHitTest
)
250 EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY
, MyFrame::OnNotebook
)
251 EVT_NOTEBOOK_PAGE_CHANGING(wxID_ANY
, MyFrame::OnNotebook
)
254 EVT_LISTBOOK_PAGE_CHANGED(wxID_ANY
, MyFrame::OnListbook
)
255 EVT_LISTBOOK_PAGE_CHANGING(wxID_ANY
, MyFrame::OnListbook
)
258 EVT_CHOICEBOOK_PAGE_CHANGED(wxID_ANY
, MyFrame::OnChoicebook
)
259 EVT_CHOICEBOOK_PAGE_CHANGING(wxID_ANY
, MyFrame::OnChoicebook
)
262 EVT_TREEBOOK_PAGE_CHANGED(wxID_ANY
, MyFrame::OnTreebook
)
263 EVT_TREEBOOK_PAGE_CHANGING(wxID_ANY
, MyFrame::OnTreebook
)
265 EVT_MENU(ID_ADD_SUB_PAGE
, MyFrame::OnAddSubPage
)
266 EVT_MENU(ID_ADD_PAGE_BEFORE
, MyFrame::OnAddPageBefore
)
267 EVT_UPDATE_UI_RANGE(ID_ADD_PAGE_BEFORE
, ID_ADD_SUB_PAGE
,
268 MyFrame::OnUpdateTreeMenu
)
271 EVT_TOOLBOOK_PAGE_CHANGED(wxID_ANY
, MyFrame::OnToolbook
)
272 EVT_TOOLBOOK_PAGE_CHANGING(wxID_ANY
, MyFrame::OnToolbook
)
275 // Update title in idle time
276 EVT_IDLE(MyFrame::OnIdle
)
280 : wxFrame(NULL
, wxID_ANY
, wxString(wxT("wxWidgets book controls sample")))
283 SetExtraStyle(wxFRAME_EX_CONTEXTHELP
);
287 m_type
= Type_Notebook
;
288 #elif wxUSE_CHOICEBOOK
289 m_type
= Type_Choicebook
;
291 m_type
= Type_Listbook
;
293 m_type
= Type_Treebook
;
295 m_type
= Type_Toolbook
;
297 #error "Don't use Notebook sample without any book enabled in wxWidgets build!"
300 m_orient
= ID_ORIENT_DEFAULT
;
301 m_chkShowImages
= true;
302 m_fixedWidth
= false;
304 m_noPageTheme
= false;
306 m_horzLayout
= false;
308 SetIcon(wxICON(sample
));
310 // menu of the sample
311 wxMenu
*menuType
= new wxMenu
;
313 menuType
->AppendRadioItem(ID_BOOK_NOTEBOOK
, wxT("&Notebook\tCtrl-1"));
316 menuType
->AppendRadioItem(ID_BOOK_LISTBOOK
, wxT("&Listbook\tCtrl-2"));
319 menuType
->AppendRadioItem(ID_BOOK_CHOICEBOOK
, wxT("&Choicebook\tCtrl-3"));
322 menuType
->AppendRadioItem(ID_BOOK_TREEBOOK
, wxT("&Treebook\tCtrl-4"));
325 menuType
->AppendRadioItem(ID_BOOK_TOOLBOOK
, wxT("T&oolbook\tCtrl-5"));
328 menuType
->Check(ID_BOOK_NOTEBOOK
+ m_type
, true);
330 wxMenu
*menuOrient
= new wxMenu
;
331 menuOrient
->AppendRadioItem(ID_ORIENT_DEFAULT
, wxT("&Default\tAlt-0"));
332 menuOrient
->AppendRadioItem(ID_ORIENT_TOP
, wxT("&Top\tAlt-1"));
333 menuOrient
->AppendRadioItem(ID_ORIENT_BOTTOM
, wxT("&Bottom\tAlt-2"));
334 menuOrient
->AppendRadioItem(ID_ORIENT_LEFT
, wxT("&Left\tAlt-3"));
335 menuOrient
->AppendRadioItem(ID_ORIENT_RIGHT
, wxT("&Right\tAlt-4"));
337 wxMenu
*menuStyle
= new wxMenu
;
339 menuStyle
->AppendCheckItem(ID_FIXEDWIDTH
, wxT("&Fixed Width (wxNotebook)"));
340 menuStyle
->AppendCheckItem(ID_MULTI
, wxT("&Multiple lines (wxNotebook)"));
341 menuStyle
->AppendCheckItem(ID_NOPAGETHEME
, wxT("&No Page Theme (wxNotebook)"));
344 menuStyle
->AppendCheckItem(ID_BUTTONBAR
, wxT("&Button Bar (wxToolbook)"));
345 menuStyle
->AppendCheckItem(ID_HORZ_LAYOUT
, wxT("&Horizontal layout (wxToolbook)"));
348 wxMenu
*menuPageOperations
= new wxMenu
;
349 menuPageOperations
->Append(ID_ADD_PAGE
, wxT("&Add page\tAlt-A"));
350 menuPageOperations
->Append(ID_ADD_PAGE_NO_SELECT
, wxT("&Add page (don't select)\tAlt-B"));
351 menuPageOperations
->Append(ID_INSERT_PAGE
, wxT("&Insert page\tAlt-I"));
352 menuPageOperations
->Append(ID_DELETE_CUR_PAGE
, wxT("&Delete current page\tAlt-D"));
353 menuPageOperations
->Append(ID_DELETE_LAST_PAGE
, wxT("D&elete last page\tAlt-L"));
354 menuPageOperations
->Append(ID_NEXT_PAGE
, wxT("&Next page\tAlt-N"));
356 menuPageOperations
->AppendSeparator();
357 menuPageOperations
->Append(ID_ADD_PAGE_BEFORE
, wxT("Insert page &before\tAlt-B"));
358 menuPageOperations
->Append(ID_ADD_SUB_PAGE
, wxT("Add s&ub page\tAlt-U"));
360 menuPageOperations
->AppendSeparator();
361 menuPageOperations
->Append(ID_CHANGE_SELECTION
, wxT("&Change selection to 0\tCtrl-0"));
362 menuPageOperations
->Append(ID_SET_SELECTION
, wxT("&Set selection to 0\tShift-Ctrl-0"));
364 wxMenu
*menuOperations
= new wxMenu
;
366 menuOperations
->Append(ID_CONTEXT_HELP
, wxT("&Context help\tCtrl-F1"));
368 menuOperations
->Append(ID_HITTEST
, wxT("&Hit test\tCtrl-H"));
370 wxMenu
*menuFile
= new wxMenu
;
371 menuFile
->Append(wxID_ANY
, wxT("&Type"), menuType
, wxT("Type of control"));
372 menuFile
->Append(wxID_ANY
, wxT("&Orientation"), menuOrient
, wxT("Orientation of control"));
373 menuFile
->AppendCheckItem(ID_SHOW_IMAGES
, wxT("&Show images\tAlt-S"));
374 menuFile
->Append(wxID_ANY
, wxT("&Style"), menuStyle
, wxT("Style of control"));
375 menuFile
->AppendSeparator();
376 menuFile
->Append(wxID_EXIT
, wxT("E&xit"), wxT("Quits the application"));
377 menuFile
->Check(ID_SHOW_IMAGES
, m_chkShowImages
);
379 wxMenuBar
*menuBar
= new wxMenuBar
;
380 menuBar
->Append(menuFile
, wxT("&File"));
381 menuBar
->Append(menuPageOperations
, wxT("&Pages"));
382 menuBar
->Append(menuOperations
, wxT("&Operations"));
389 // create a dummy image list with a few icons
390 const wxSize
imageSize(32, 32);
392 m_imageList
= new wxImageList(imageSize
.GetWidth(), imageSize
.GetHeight());
394 Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, imageSize
));
396 Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, imageSize
));
398 Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, imageSize
));
400 Add(wxArtProvider::GetIcon(wxART_ERROR
, wxART_OTHER
, imageSize
));
402 m_panel
= new wxPanel(this);
405 m_text
= new wxTextCtrl(m_panel
, wxID_ANY
, wxEmptyString
,
406 wxDefaultPosition
, wxDefaultSize
,
407 wxTE_MULTILINE
| wxTE_READONLY
);
409 m_logTargetOld
= wxLog::SetActiveTarget( new wxLogTextCtrl(m_text
) );
413 m_sizerFrame
= new wxBoxSizer(wxVERTICAL
);
416 m_sizerFrame
->Add(m_text
, 1, wxEXPAND
);
421 m_panel
->SetSizer(m_sizerFrame
);
424 wxBoxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
425 sizer
->Add(m_panel
, wxSizerFlags(1).Expand());
426 SetSizerAndFit(sizer
);
432 delete wxLog::SetActiveTarget(m_logTargetOld
);
438 // DISPATCH_ON_TYPE() macro is an ugly way to write the "same" code for
439 // different wxBookCtrlBase-derived classes without duplicating code and
440 // without using templates, it expands into "before <xxx> after" where "xxx"
441 // part is control class-specific
443 #define CASE_NOTEBOOK(x) case Type_Notebook: x; break;
445 #define CASE_NOTEBOOK(x)
449 #define CASE_LISTBOOK(x) case Type_Listbook: x; break;
451 #define CASE_LISTBOOK(x)
455 #define CASE_CHOICEBOOK(x) case Type_Choicebook: x; break;
457 #define CASE_CHOICEBOOK(x)
461 #define CASE_TREEBOOK(x) case Type_Treebook: x; break;
463 #define CASE_TREEBOOK(x)
467 #define CASE_TOOLBOOK(x) case Type_Toolbook: x; break;
469 #define CASE_TOOLBOOK(x)
472 #define DISPATCH_ON_TYPE(before, nb, lb, cb, tb, toolb, after) \
475 CASE_NOTEBOOK(before nb after) \
476 CASE_LISTBOOK(before lb after) \
477 CASE_CHOICEBOOK(before cb after) \
478 CASE_TREEBOOK(before tb after) \
479 CASE_TOOLBOOK(before toolb after) \
482 wxFAIL_MSG( wxT("unknown book control type") ); \
485 int MyFrame::TranslateBookFlag(int nb
, int lb
, int chb
, int tbk
, int toolbk
) const
489 DISPATCH_ON_TYPE(flag
=, nb
, lb
, chb
, tbk
, toolbk
, + 0);
494 void MyFrame::RecreateBook()
503 case ID_ORIENT_BOTTOM
:
511 case ID_ORIENT_RIGHT
:
516 flags
= wxBK_DEFAULT
;
520 if ( m_fixedWidth
&& m_type
== Type_Notebook
)
521 flags
|= wxNB_FIXEDWIDTH
;
522 if ( m_multi
&& m_type
== Type_Notebook
)
523 flags
|= wxNB_MULTILINE
;
524 if ( m_noPageTheme
&& m_type
== Type_Notebook
)
525 flags
|= wxNB_NOPAGETHEME
;
528 if ( m_buttonBar
&& m_type
== Type_Toolbook
)
529 flags
|= wxTBK_BUTTONBAR
;
530 if ( m_horzLayout
&& m_type
== Type_Toolbook
)
531 flags
|= wxTBK_HORZ_LAYOUT
;
534 wxBookCtrlBase
*oldBook
= m_bookCtrl
;
538 DISPATCH_ON_TYPE(m_bookCtrl
= new,
544 (m_panel
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, flags
));
551 // wxToolbook doesn't work without icons so always use them for it.
552 if ( m_chkShowImages
|| m_type
== Type_Toolbook
)
554 m_bookCtrl
->SetImageList(m_imageList
);
560 // we only need the old treebook if we're recreating another treebook
561 wxTreebook
*tbkOld
= m_type
== Type_Treebook
562 ? wxDynamicCast(oldBook
, wxTreebook
)
564 #endif // wxUSE_TREEBOOK
566 const int count
= oldBook
->GetPageCount();
567 for ( int n
= 0; n
< count
; n
++ )
569 const int image
= GetIconIndex(m_bookCtrl
);
570 const wxString str
= oldBook
->GetPageText(n
);
572 wxWindow
*page
= CreatePage(m_bookCtrl
, str
);
574 // treebook complication: need to account for possible parent page
578 const int parent
= tbkOld
->GetPageParent(n
);
579 if ( parent
!= wxNOT_FOUND
)
581 wxStaticCast(m_bookCtrl
, wxTreebook
)->
582 InsertSubPage(parent
, page
, str
, false, image
);
584 // skip adding it again below
588 #endif // wxUSE_TREEBOOK
590 m_bookCtrl
->AddPage(page
, str
, false, image
);
593 const int sel
= oldBook
->GetSelection();
594 if ( sel
!= wxNOT_FOUND
)
595 m_bookCtrl
->SetSelection(sel
);
598 m_sizerFrame
->Detach(oldBook
);
603 CreateInitialPages(m_bookCtrl
);
606 m_sizerFrame
->Insert(0, m_bookCtrl
, wxSizerFlags(5).Expand().Border());
608 m_sizerFrame
->Show(m_bookCtrl
);
609 m_sizerFrame
->Layout();
612 void MyFrame::AddFlagStrIfFlagPresent(wxString
& flagStr
, long flags
, long flag
,
613 const wxChar
* flagName
) const
615 if( (flags
& flag
) == flag
)
617 if( !flagStr
.empty() )
618 flagStr
+= wxT(" | ");
623 wxPanel
*MyFrame::CreateNewPage() const
625 wxPanel
*panel
= new wxPanel(m_bookCtrl
, wxID_ANY
);
628 panel
->SetHelpText( wxT( "Panel with \"First\" and \"Second\" buttons" ) );
631 (void) new wxButton(panel
, wxID_ANY
, wxT("First button"), wxPoint(10, 30));
632 (void) new wxButton(panel
, wxID_ANY
, wxT("Second button"), wxPoint(150, 30));
638 //-----------------------------------------------------------------------------
639 // MyFrame - event handlers
640 //-----------------------------------------------------------------------------
644 void MyFrame::OnContextHelp(wxCommandEvent
& WXUNUSED(event
))
646 // launches local event loop
647 wxContextHelp
ch( this );
652 void MyFrame::OnHitTest(wxCommandEvent
& WXUNUSED(event
))
654 wxBookCtrlBase
* book
= GetCurrentBook();
655 const wxPoint pt
= ::wxGetMousePosition();
658 int pagePos
= book
->HitTest( book
->ScreenToClient(pt
), &flags
);
662 AddFlagStrIfFlagPresent( flagsStr
, flags
, wxBK_HITTEST_NOWHERE
, wxT("wxBK_HITTEST_NOWHERE") );
663 AddFlagStrIfFlagPresent( flagsStr
, flags
, wxBK_HITTEST_ONICON
, wxT("wxBK_HITTEST_ONICON") );
664 AddFlagStrIfFlagPresent( flagsStr
, flags
, wxBK_HITTEST_ONLABEL
, wxT("wxBK_HITTEST_ONLABEL") );
665 AddFlagStrIfFlagPresent( flagsStr
, flags
, wxBK_HITTEST_ONPAGE
, wxT("wxBK_HITTEST_ONPAGE") );
667 wxLogMessage(wxT("HitTest at (%d,%d): %d: %s"),
674 void MyFrame::OnType(wxCommandEvent
& event
)
676 m_type
= static_cast<BookType
>(event
.GetId() - ID_BOOK_NOTEBOOK
);
679 m_sizerFrame
->Hide(m_bookCtrl
);
686 void MyFrame::OnUpdateTreeMenu(wxUpdateUIEvent
& event
)
688 event
.Enable(m_type
== Type_Treebook
);
691 #endif // wxUSE_TREEBOOK
693 void MyFrame::OnOrient(wxCommandEvent
& event
)
695 m_orient
= event
.GetId();
697 m_sizerFrame
->Layout();
700 void MyFrame::OnShowImages(wxCommandEvent
& event
)
702 m_chkShowImages
= event
.IsChecked();
704 m_sizerFrame
->Layout();
707 void MyFrame::OnStyle(wxCommandEvent
& event
)
709 bool checked
= event
.IsChecked();
710 switch (event
.GetId())
712 case ID_FIXEDWIDTH
: m_fixedWidth
= checked
; break;
713 case ID_MULTI
: m_multi
= checked
; break;
714 case ID_NOPAGETHEME
: m_noPageTheme
= checked
; break;
715 case ID_BUTTONBAR
: m_buttonBar
= checked
; break;
716 case ID_HORZ_LAYOUT
: m_horzLayout
= checked
; break;
717 default: break; // avoid compiler warning
721 m_sizerFrame
->Layout();
724 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
729 void MyFrame::OnAddPage(wxCommandEvent
& WXUNUSED(event
))
731 wxBookCtrlBase
*currBook
= GetCurrentBook();
735 static unsigned s_pageAdded
= 0;
736 currBook
->AddPage(CreateNewPage(),
739 ADDED_PAGE_NAME
wxT("%u"),
743 GetIconIndex(currBook
));
747 void MyFrame::OnAddPageNoSelect(wxCommandEvent
& WXUNUSED(event
))
749 wxBookCtrlBase
*currBook
= GetCurrentBook();
753 static unsigned s_pageAdded
= 0;
754 currBook
->AddPage(CreateNewPage(),
757 ADDED_PAGE_NAME
wxT("%u"),
761 GetIconIndex(currBook
));
766 void MyFrame::OnAddSubPage(wxCommandEvent
& WXUNUSED(event
))
768 wxTreebook
*currBook
= wxDynamicCast(GetCurrentBook(), wxTreebook
);
771 const int selPos
= currBook
->GetSelection();
772 if ( selPos
== wxNOT_FOUND
)
774 wxLogError(wxT("Select the parent page first!"));
778 static unsigned s_subPageAdded
= 0;
779 currBook
->InsertSubPage
785 ADDED_SUB_PAGE_NAME
wxT("%u"),
789 GetIconIndex(currBook
)
794 void MyFrame::OnAddPageBefore(wxCommandEvent
& WXUNUSED(event
))
796 wxBookCtrlBase
*currBook
= GetCurrentBook();
799 const int selPos
= currBook
->GetSelection();
800 if ( selPos
== wxNOT_FOUND
)
802 wxLogError(wxT("Select the parent page first!"));
806 static unsigned s_subPageAdded
= 0;
807 currBook
->InsertPage(selPos
,
811 ADDED_PAGE_NAME_BEFORE
wxT("%u"),
815 GetIconIndex(currBook
));
818 #endif // wxUSE_TREEBOOK
820 void MyFrame::OnInsertPage(wxCommandEvent
& WXUNUSED(event
))
822 static unsigned s_pageIns
= 0;
824 wxBookCtrlBase
*currBook
= GetCurrentBook();
828 wxPanel
*panel
= CreateUserCreatedPage( currBook
);
830 currBook
->InsertPage( 0, panel
,
831 wxString::Format(INSERTED_PAGE_NAME
wxT("%u"), ++s_pageIns
), false,
832 GetIconIndex(currBook
) );
834 currBook
->SetSelection(0);
838 void MyFrame::OnDeleteCurPage(wxCommandEvent
& WXUNUSED(event
))
840 wxBookCtrlBase
*currBook
= GetCurrentBook();
844 int sel
= currBook
->GetSelection();
846 if (sel
!= wxNOT_FOUND
)
848 currBook
->DeletePage(sel
);
853 void MyFrame::OnDeleteLastPage(wxCommandEvent
& WXUNUSED(event
))
855 wxBookCtrlBase
*currBook
= GetCurrentBook();
859 int page
= currBook
->GetPageCount();
863 currBook
->DeletePage(page
- 1);
868 void MyFrame::OnNextPage(wxCommandEvent
& WXUNUSED(event
))
870 wxBookCtrlBase
*currBook
= GetCurrentBook();
874 currBook
->AdvanceSelection();
878 void MyFrame::OnChangeSelection(wxCommandEvent
& WXUNUSED(event
))
880 wxBookCtrlBase
*currBook
= GetCurrentBook();
883 currBook
->ChangeSelection(0);
886 void MyFrame::OnSetSelection(wxCommandEvent
& WXUNUSED(event
))
888 wxBookCtrlBase
*currBook
= GetCurrentBook();
891 currBook
->SetSelection(0);
894 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
896 static int s_nPages
= wxNOT_FOUND
;
897 static int s_nSel
= wxNOT_FOUND
;
898 static wxBookCtrlBase
*s_currBook
= NULL
;
900 wxBookCtrlBase
*currBook
= GetCurrentBook();
902 int nPages
= currBook
? currBook
->GetPageCount() : 0;
903 int nSel
= currBook
? currBook
->GetSelection() : wxNOT_FOUND
;
905 if ( nPages
!= s_nPages
|| nSel
!= s_nSel
|| s_currBook
!= currBook
)
909 s_currBook
= currBook
;
912 if ( nSel
== wxNOT_FOUND
)
913 selection
<< wxT("not found");
918 title
.Printf(wxT("Notebook and friends (%d pages, selection: %s)"), nPages
, selection
.c_str());
924 void MyFrame::OnBookCtrl(wxBookCtrlBaseEvent
& event
)
926 static const struct EventInfo
928 wxEventType typeChanged
,
935 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
,
936 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
,
939 #endif // wxUSE_NOTEBOOK
942 wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED
,
943 wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING
,
946 #endif // wxUSE_LISTBOOK
949 wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED
,
950 wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING
,
953 #endif // wxUSE_CHOICEBOOK
956 wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED
,
957 wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING
,
960 #endif // wxUSE_TREEBOOK
963 wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGED
,
964 wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGING
,
967 #endif // wxUSE_TOOLBOOK
974 const wxEventType eventType
= event
.GetEventType();
975 for ( size_t n
= 0; n
< WXSIZEOF(events
); n
++ )
977 const EventInfo
& ei
= events
[n
];
978 if ( eventType
== ei
.typeChanged
)
980 nameEvent
= wxT("Changed");
982 else if ( eventType
== ei
.typeChanging
)
984 const int idx
= event
.GetOldSelection();
986 // NB: can't use wxStaticCast here as wxBookCtrlBase is not in
988 const wxBookCtrlBase
* const
989 book
= static_cast<wxBookCtrlBase
*>(event
.GetEventObject());
990 if ( idx
!= wxNOT_FOUND
&&
991 book
&& book
->GetPageText(idx
) == VETO_PAGE_NAME
)
995 wxT("Are you sure you want to leave this page?\n")
996 wxT("(This demonstrates veto-ing)"),
997 wxT("Notebook sample"),
998 wxICON_QUESTION
| wxYES_NO
,
1003 veto
= wxT(" (vetoed)");
1007 nameEvent
= wxT("Changing");
1009 else // skip end of the loop
1014 nameControl
= ei
.name
;
1018 static int s_num
= 0;
1020 wxLogMessage(wxT("Event #%d: %s: %s (%d) new sel %d, old %d%s"),
1022 nameControl
.c_str(),
1025 event
.GetSelection(),
1026 event
.GetOldSelection(),
1030 m_text
->SetInsertionPointEnd();