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 if ( m_chkShowImages
)
553 m_bookCtrl
->SetImageList(m_imageList
);
559 // we only need the old treebook if we're recreating another treebook
560 wxTreebook
*tbkOld
= m_type
== Type_Treebook
561 ? wxDynamicCast(oldBook
, wxTreebook
)
563 #endif // wxUSE_TREEBOOK
565 const int count
= oldBook
->GetPageCount();
566 for ( int n
= 0; n
< count
; n
++ )
568 const int image
= GetIconIndex(m_bookCtrl
);
569 const wxString str
= oldBook
->GetPageText(n
);
571 wxWindow
*page
= CreatePage(m_bookCtrl
, str
);
573 // treebook complication: need to account for possible parent page
577 const int parent
= tbkOld
->GetPageParent(n
);
578 if ( parent
!= wxNOT_FOUND
)
580 wxStaticCast(m_bookCtrl
, wxTreebook
)->
581 InsertSubPage(parent
, page
, str
, false, image
);
583 // skip adding it again below
587 #endif // wxUSE_TREEBOOK
589 m_bookCtrl
->AddPage(page
, str
, false, image
);
592 const int sel
= oldBook
->GetSelection();
593 if ( sel
!= wxNOT_FOUND
)
594 m_bookCtrl
->SetSelection(sel
);
597 m_sizerFrame
->Detach(oldBook
);
602 CreateInitialPages(m_bookCtrl
);
605 m_sizerFrame
->Insert(0, m_bookCtrl
, wxSizerFlags(5).Expand().Border());
607 m_sizerFrame
->Show(m_bookCtrl
);
608 m_sizerFrame
->Layout();
611 void MyFrame::AddFlagStrIfFlagPresent(wxString
& flagStr
, long flags
, long flag
,
612 const wxChar
* flagName
) const
614 if( (flags
& flag
) == flag
)
616 if( !flagStr
.empty() )
617 flagStr
+= wxT(" | ");
622 wxPanel
*MyFrame::CreateNewPage() const
624 wxPanel
*panel
= new wxPanel(m_bookCtrl
, wxID_ANY
);
627 panel
->SetHelpText( wxT( "Panel with \"First\" and \"Second\" buttons" ) );
630 (void) new wxButton(panel
, wxID_ANY
, wxT("First button"), wxPoint(10, 30));
631 (void) new wxButton(panel
, wxID_ANY
, wxT("Second button"), wxPoint(150, 30));
637 //-----------------------------------------------------------------------------
638 // MyFrame - event handlers
639 //-----------------------------------------------------------------------------
643 void MyFrame::OnContextHelp(wxCommandEvent
& WXUNUSED(event
))
645 // launches local event loop
646 wxContextHelp
ch( this );
651 void MyFrame::OnHitTest(wxCommandEvent
& WXUNUSED(event
))
653 wxBookCtrlBase
* book
= GetCurrentBook();
654 const wxPoint pt
= ::wxGetMousePosition();
657 int pagePos
= book
->HitTest( book
->ScreenToClient(pt
), &flags
);
661 AddFlagStrIfFlagPresent( flagsStr
, flags
, wxBK_HITTEST_NOWHERE
, wxT("wxBK_HITTEST_NOWHERE") );
662 AddFlagStrIfFlagPresent( flagsStr
, flags
, wxBK_HITTEST_ONICON
, wxT("wxBK_HITTEST_ONICON") );
663 AddFlagStrIfFlagPresent( flagsStr
, flags
, wxBK_HITTEST_ONLABEL
, wxT("wxBK_HITTEST_ONLABEL") );
664 AddFlagStrIfFlagPresent( flagsStr
, flags
, wxBK_HITTEST_ONPAGE
, wxT("wxBK_HITTEST_ONPAGE") );
666 wxLogMessage(wxT("HitTest at (%d,%d): %d: %s"),
673 void MyFrame::OnType(wxCommandEvent
& event
)
675 m_type
= static_cast<BookType
>(event
.GetId() - ID_BOOK_NOTEBOOK
);
678 m_sizerFrame
->Hide(m_bookCtrl
);
685 void MyFrame::OnUpdateTreeMenu(wxUpdateUIEvent
& event
)
687 event
.Enable(m_type
== Type_Treebook
);
690 #endif // wxUSE_TREEBOOK
692 void MyFrame::OnOrient(wxCommandEvent
& event
)
694 m_orient
= event
.GetId();
696 m_sizerFrame
->Layout();
699 void MyFrame::OnShowImages(wxCommandEvent
& event
)
701 m_chkShowImages
= event
.IsChecked();
703 m_sizerFrame
->Layout();
706 void MyFrame::OnStyle(wxCommandEvent
& event
)
708 bool checked
= event
.IsChecked();
709 switch (event
.GetId())
711 case ID_FIXEDWIDTH
: m_fixedWidth
= checked
; break;
712 case ID_MULTI
: m_multi
= checked
; break;
713 case ID_NOPAGETHEME
: m_noPageTheme
= checked
; break;
714 case ID_BUTTONBAR
: m_buttonBar
= checked
; break;
715 case ID_HORZ_LAYOUT
: m_horzLayout
= checked
; break;
716 default: break; // avoid compiler warning
720 m_sizerFrame
->Layout();
723 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
728 void MyFrame::OnAddPage(wxCommandEvent
& WXUNUSED(event
))
730 wxBookCtrlBase
*currBook
= GetCurrentBook();
734 static unsigned s_pageAdded
= 0;
735 currBook
->AddPage(CreateNewPage(),
738 ADDED_PAGE_NAME
wxT("%u"),
742 GetIconIndex(currBook
));
746 void MyFrame::OnAddPageNoSelect(wxCommandEvent
& WXUNUSED(event
))
748 wxBookCtrlBase
*currBook
= GetCurrentBook();
752 static unsigned s_pageAdded
= 0;
753 currBook
->AddPage(CreateNewPage(),
756 ADDED_PAGE_NAME
wxT("%u"),
760 GetIconIndex(currBook
));
765 void MyFrame::OnAddSubPage(wxCommandEvent
& WXUNUSED(event
))
767 wxTreebook
*currBook
= wxDynamicCast(GetCurrentBook(), wxTreebook
);
770 const int selPos
= currBook
->GetSelection();
771 if ( selPos
== wxNOT_FOUND
)
773 wxLogError(wxT("Select the parent page first!"));
777 static unsigned s_subPageAdded
= 0;
778 currBook
->InsertSubPage
784 ADDED_SUB_PAGE_NAME
wxT("%u"),
788 GetIconIndex(currBook
)
793 void MyFrame::OnAddPageBefore(wxCommandEvent
& WXUNUSED(event
))
795 wxBookCtrlBase
*currBook
= GetCurrentBook();
798 const int selPos
= currBook
->GetSelection();
799 if ( selPos
== wxNOT_FOUND
)
801 wxLogError(wxT("Select the parent page first!"));
805 static unsigned s_subPageAdded
= 0;
806 currBook
->InsertPage(selPos
,
810 ADDED_PAGE_NAME_BEFORE
wxT("%u"),
814 GetIconIndex(currBook
));
817 #endif // wxUSE_TREEBOOK
819 void MyFrame::OnInsertPage(wxCommandEvent
& WXUNUSED(event
))
821 static unsigned s_pageIns
= 0;
823 wxBookCtrlBase
*currBook
= GetCurrentBook();
827 wxPanel
*panel
= CreateUserCreatedPage( currBook
);
829 currBook
->InsertPage( 0, panel
,
830 wxString::Format(INSERTED_PAGE_NAME
wxT("%u"), ++s_pageIns
), false,
831 GetIconIndex(currBook
) );
833 currBook
->SetSelection(0);
837 void MyFrame::OnDeleteCurPage(wxCommandEvent
& WXUNUSED(event
))
839 wxBookCtrlBase
*currBook
= GetCurrentBook();
843 int sel
= currBook
->GetSelection();
845 if (sel
!= wxNOT_FOUND
)
847 currBook
->DeletePage(sel
);
852 void MyFrame::OnDeleteLastPage(wxCommandEvent
& WXUNUSED(event
))
854 wxBookCtrlBase
*currBook
= GetCurrentBook();
858 int page
= currBook
->GetPageCount();
862 currBook
->DeletePage(page
- 1);
867 void MyFrame::OnNextPage(wxCommandEvent
& WXUNUSED(event
))
869 wxBookCtrlBase
*currBook
= GetCurrentBook();
873 currBook
->AdvanceSelection();
877 void MyFrame::OnChangeSelection(wxCommandEvent
& WXUNUSED(event
))
879 wxBookCtrlBase
*currBook
= GetCurrentBook();
882 currBook
->ChangeSelection(0);
885 void MyFrame::OnSetSelection(wxCommandEvent
& WXUNUSED(event
))
887 wxBookCtrlBase
*currBook
= GetCurrentBook();
890 currBook
->SetSelection(0);
893 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
895 static int s_nPages
= wxNOT_FOUND
;
896 static int s_nSel
= wxNOT_FOUND
;
897 static wxBookCtrlBase
*s_currBook
= NULL
;
899 wxBookCtrlBase
*currBook
= GetCurrentBook();
901 int nPages
= currBook
? currBook
->GetPageCount() : 0;
902 int nSel
= currBook
? currBook
->GetSelection() : wxNOT_FOUND
;
904 if ( nPages
!= s_nPages
|| nSel
!= s_nSel
|| s_currBook
!= currBook
)
908 s_currBook
= currBook
;
911 if ( nSel
== wxNOT_FOUND
)
912 selection
<< wxT("not found");
917 title
.Printf(wxT("Notebook and friends (%d pages, selection: %s)"), nPages
, selection
.c_str());
923 void MyFrame::OnBookCtrl(wxBookCtrlBaseEvent
& event
)
925 static const struct EventInfo
927 wxEventType typeChanged
,
934 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
,
935 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
,
938 #endif // wxUSE_NOTEBOOK
941 wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED
,
942 wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING
,
945 #endif // wxUSE_LISTBOOK
948 wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED
,
949 wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING
,
952 #endif // wxUSE_CHOICEBOOK
955 wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED
,
956 wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING
,
959 #endif // wxUSE_TREEBOOK
962 wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGED
,
963 wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGING
,
966 #endif // wxUSE_TOOLBOOK
973 const wxEventType eventType
= event
.GetEventType();
974 for ( size_t n
= 0; n
< WXSIZEOF(events
); n
++ )
976 const EventInfo
& ei
= events
[n
];
977 if ( eventType
== ei
.typeChanged
)
979 nameEvent
= wxT("Changed");
981 else if ( eventType
== ei
.typeChanging
)
983 const int idx
= event
.GetOldSelection();
985 // NB: can't use wxStaticCast here as wxBookCtrlBase is not in
987 const wxBookCtrlBase
* const
988 book
= static_cast<wxBookCtrlBase
*>(event
.GetEventObject());
989 if ( idx
!= wxNOT_FOUND
&&
990 book
&& book
->GetPageText(idx
) == VETO_PAGE_NAME
)
994 wxT("Are you sure you want to leave this page?\n")
995 wxT("(This demonstrates veto-ing)"),
996 wxT("Notebook sample"),
997 wxICON_QUESTION
| wxYES_NO
,
1002 veto
= wxT(" (vetoed)");
1006 nameEvent
= wxT("Changing");
1008 else // skip end of the loop
1013 nameControl
= ei
.name
;
1017 static int s_num
= 0;
1019 wxLogMessage(wxT("Event #%d: %s: %s (%d) new sel %d, old %d%s"),
1021 nameControl
.c_str(),
1024 event
.GetSelection(),
1025 event
.GetOldSelection(),
1029 m_text
->SetInsertionPointEnd();