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 #ifndef wxHAS_IMAGES_IN_RESOURCES
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
)
242 EVT_MENU(ID_GET_PAGE_SIZE
, MyFrame::OnGetPageSize
)
243 EVT_MENU(ID_SET_PAGE_SIZE
, MyFrame::OnSetPageSize
)
246 EVT_MENU(ID_CONTEXT_HELP
, MyFrame::OnContextHelp
)
248 EVT_MENU(ID_HITTEST
, MyFrame::OnHitTest
)
252 EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY
, MyFrame::OnNotebook
)
253 EVT_NOTEBOOK_PAGE_CHANGING(wxID_ANY
, MyFrame::OnNotebook
)
256 EVT_LISTBOOK_PAGE_CHANGED(wxID_ANY
, MyFrame::OnListbook
)
257 EVT_LISTBOOK_PAGE_CHANGING(wxID_ANY
, MyFrame::OnListbook
)
260 EVT_CHOICEBOOK_PAGE_CHANGED(wxID_ANY
, MyFrame::OnChoicebook
)
261 EVT_CHOICEBOOK_PAGE_CHANGING(wxID_ANY
, MyFrame::OnChoicebook
)
264 EVT_TREEBOOK_PAGE_CHANGED(wxID_ANY
, MyFrame::OnTreebook
)
265 EVT_TREEBOOK_PAGE_CHANGING(wxID_ANY
, MyFrame::OnTreebook
)
267 EVT_MENU(ID_ADD_SUB_PAGE
, MyFrame::OnAddSubPage
)
268 EVT_MENU(ID_ADD_PAGE_BEFORE
, MyFrame::OnAddPageBefore
)
269 EVT_UPDATE_UI_RANGE(ID_ADD_PAGE_BEFORE
, ID_ADD_SUB_PAGE
,
270 MyFrame::OnUpdateTreeMenu
)
273 EVT_TOOLBOOK_PAGE_CHANGED(wxID_ANY
, MyFrame::OnToolbook
)
274 EVT_TOOLBOOK_PAGE_CHANGING(wxID_ANY
, MyFrame::OnToolbook
)
277 EVT_AUINOTEBOOK_PAGE_CHANGED(wxID_ANY
, MyFrame::OnAuiNotebook
)
278 EVT_AUINOTEBOOK_PAGE_CHANGING(wxID_ANY
, MyFrame::OnAuiNotebook
)
281 // Update title in idle time
282 EVT_IDLE(MyFrame::OnIdle
)
286 : wxFrame(NULL
, wxID_ANY
, wxString(wxT("wxWidgets book controls sample")))
289 SetExtraStyle(wxFRAME_EX_CONTEXTHELP
);
293 m_type
= Type_Notebook
;
294 #elif wxUSE_CHOICEBOOK
295 m_type
= Type_Choicebook
;
297 m_type
= Type_Listbook
;
299 m_type
= Type_Treebook
;
301 m_type
= Type_Toolbook
;
305 #error "Don't use Notebook sample without any book enabled in wxWidgets build!"
308 m_orient
= ID_ORIENT_DEFAULT
;
309 m_chkShowImages
= true;
310 m_fixedWidth
= false;
312 m_noPageTheme
= false;
314 m_horzLayout
= false;
316 SetIcon(wxICON(sample
));
318 // menu of the sample
319 wxMenu
*menuType
= new wxMenu
;
321 menuType
->AppendRadioItem(ID_BOOK_NOTEBOOK
, wxT("&Notebook\tCtrl-1"));
324 menuType
->AppendRadioItem(ID_BOOK_LISTBOOK
, wxT("&Listbook\tCtrl-2"));
327 menuType
->AppendRadioItem(ID_BOOK_CHOICEBOOK
, wxT("&Choicebook\tCtrl-3"));
330 menuType
->AppendRadioItem(ID_BOOK_TREEBOOK
, wxT("&Treebook\tCtrl-4"));
333 menuType
->AppendRadioItem(ID_BOOK_TOOLBOOK
, wxT("T&oolbook\tCtrl-5"));
336 menuType
->AppendRadioItem(ID_BOOK_AUINOTEBOOK
, wxT("&AuiNotebook\tCtrl-6"));
339 menuType
->Check(ID_BOOK_NOTEBOOK
+ m_type
, true);
341 wxMenu
*menuOrient
= new wxMenu
;
342 menuOrient
->AppendRadioItem(ID_ORIENT_DEFAULT
, wxT("&Default\tAlt-0"));
343 menuOrient
->AppendRadioItem(ID_ORIENT_TOP
, wxT("&Top\tAlt-1"));
344 menuOrient
->AppendRadioItem(ID_ORIENT_BOTTOM
, wxT("&Bottom\tAlt-2"));
345 menuOrient
->AppendRadioItem(ID_ORIENT_LEFT
, wxT("&Left\tAlt-3"));
346 menuOrient
->AppendRadioItem(ID_ORIENT_RIGHT
, wxT("&Right\tAlt-4"));
348 wxMenu
*menuStyle
= new wxMenu
;
350 menuStyle
->AppendCheckItem(ID_FIXEDWIDTH
, wxT("&Fixed Width (wxNotebook)"));
351 menuStyle
->AppendCheckItem(ID_MULTI
, wxT("&Multiple lines (wxNotebook)"));
352 menuStyle
->AppendCheckItem(ID_NOPAGETHEME
, wxT("&No Page Theme (wxNotebook)"));
355 menuStyle
->AppendCheckItem(ID_BUTTONBAR
, wxT("&Button Bar (wxToolbook)"));
356 menuStyle
->AppendCheckItem(ID_HORZ_LAYOUT
, wxT("&Horizontal layout (wxToolbook)"));
359 wxMenu
*menuPageOperations
= new wxMenu
;
360 menuPageOperations
->Append(ID_ADD_PAGE
, wxT("&Add page\tAlt-A"));
361 menuPageOperations
->Append(ID_ADD_PAGE_NO_SELECT
, wxT("&Add page (don't select)\tAlt-B"));
362 menuPageOperations
->Append(ID_INSERT_PAGE
, wxT("&Insert page\tAlt-I"));
363 menuPageOperations
->Append(ID_DELETE_CUR_PAGE
, wxT("&Delete current page\tAlt-D"));
364 menuPageOperations
->Append(ID_DELETE_LAST_PAGE
, wxT("D&elete last page\tAlt-L"));
365 menuPageOperations
->Append(ID_NEXT_PAGE
, wxT("&Next page\tAlt-N"));
367 menuPageOperations
->AppendSeparator();
368 menuPageOperations
->Append(ID_ADD_PAGE_BEFORE
, wxT("Insert page &before\tAlt-B"));
369 menuPageOperations
->Append(ID_ADD_SUB_PAGE
, wxT("Add s&ub page\tAlt-U"));
371 menuPageOperations
->AppendSeparator();
372 menuPageOperations
->Append(ID_CHANGE_SELECTION
, wxT("&Change selection to 0\tCtrl-0"));
373 menuPageOperations
->Append(ID_SET_SELECTION
, wxT("&Set selection to 0\tShift-Ctrl-0"));
374 menuPageOperations
->AppendSeparator();
375 menuPageOperations
->Append(ID_GET_PAGE_SIZE
, "Sho&w page size");
376 menuPageOperations
->Append(ID_SET_PAGE_SIZE
, "Set &page size");
378 wxMenu
*menuOperations
= new wxMenu
;
380 menuOperations
->Append(ID_CONTEXT_HELP
, wxT("&Context help\tCtrl-F1"));
382 menuOperations
->Append(ID_HITTEST
, wxT("&Hit test\tCtrl-H"));
384 wxMenu
*menuFile
= new wxMenu
;
385 menuFile
->Append(wxID_ANY
, wxT("&Type"), menuType
, wxT("Type of control"));
386 menuFile
->Append(wxID_ANY
, wxT("&Orientation"), menuOrient
, wxT("Orientation of control"));
387 menuFile
->AppendCheckItem(ID_SHOW_IMAGES
, wxT("&Show images\tAlt-S"));
388 menuFile
->Append(wxID_ANY
, wxT("&Style"), menuStyle
, wxT("Style of control"));
389 menuFile
->AppendSeparator();
390 menuFile
->Append(wxID_EXIT
, wxT("E&xit"), wxT("Quits the application"));
391 menuFile
->Check(ID_SHOW_IMAGES
, m_chkShowImages
);
393 wxMenuBar
*menuBar
= new wxMenuBar
;
394 menuBar
->Append(menuFile
, wxT("&File"));
395 menuBar
->Append(menuPageOperations
, wxT("&Pages"));
396 menuBar
->Append(menuOperations
, wxT("&Operations"));
403 // create a dummy image list with a few icons
404 const wxSize
imageSize(32, 32);
406 m_imageList
= new wxImageList(imageSize
.GetWidth(), imageSize
.GetHeight());
408 Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, imageSize
));
410 Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, imageSize
));
412 Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, imageSize
));
414 Add(wxArtProvider::GetIcon(wxART_ERROR
, wxART_OTHER
, imageSize
));
416 m_panel
= new wxPanel(this);
419 m_text
= new wxTextCtrl(m_panel
, wxID_ANY
, wxEmptyString
,
420 wxDefaultPosition
, wxDefaultSize
,
421 wxTE_MULTILINE
| wxTE_READONLY
);
423 m_logTargetOld
= wxLog::SetActiveTarget( new wxLogTextCtrl(m_text
) );
427 m_sizerFrame
= new wxBoxSizer(wxVERTICAL
);
430 m_sizerFrame
->Add(m_text
, 1, wxEXPAND
);
435 m_panel
->SetSizer(m_sizerFrame
);
438 wxBoxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
439 sizer
->Add(m_panel
, wxSizerFlags(1).Expand());
440 SetSizerAndFit(sizer
);
446 delete wxLog::SetActiveTarget(m_logTargetOld
);
452 // DISPATCH_ON_TYPE() macro is an ugly way to write the "same" code for
453 // different wxBookCtrlBase-derived classes without duplicating code and
454 // without using templates, it expands into "before <xxx> after" where "xxx"
455 // part is control class-specific
457 #define CASE_NOTEBOOK(x) case Type_Notebook: x; break;
459 #define CASE_NOTEBOOK(x)
463 #define CASE_LISTBOOK(x) case Type_Listbook: x; break;
465 #define CASE_LISTBOOK(x)
469 #define CASE_CHOICEBOOK(x) case Type_Choicebook: x; break;
471 #define CASE_CHOICEBOOK(x)
475 #define CASE_TREEBOOK(x) case Type_Treebook: x; break;
477 #define CASE_TREEBOOK(x)
481 #define CASE_TOOLBOOK(x) case Type_Toolbook: x; break;
483 #define CASE_TOOLBOOK(x)
487 #define CASE_AUINOTEBOOK(x) case Type_AuiNotebook: x; break;
489 #define CASE_AUINOTEBOOK(x)
492 #define DISPATCH_ON_TYPE(before, nb, lb, cb, tb, toolb, aui, after) \
495 CASE_NOTEBOOK(before nb after) \
496 CASE_LISTBOOK(before lb after) \
497 CASE_CHOICEBOOK(before cb after) \
498 CASE_TREEBOOK(before tb after) \
499 CASE_TOOLBOOK(before toolb after) \
500 CASE_AUINOTEBOOK(before aui after) \
503 wxFAIL_MSG( wxT("unknown book control type") ); \
506 int MyFrame::TranslateBookFlag(int nb
, int lb
, int chb
, int tbk
, int toolbk
, int aui
) const
510 DISPATCH_ON_TYPE(flag
=, nb
, lb
, chb
, tbk
, toolbk
, aui
, + 0);
515 void MyFrame::RecreateBook()
524 case ID_ORIENT_BOTTOM
:
532 case ID_ORIENT_RIGHT
:
537 flags
= wxBK_DEFAULT
;
541 if ( m_fixedWidth
&& m_type
== Type_Notebook
)
542 flags
|= wxNB_FIXEDWIDTH
;
543 if ( m_multi
&& m_type
== Type_Notebook
)
544 flags
|= wxNB_MULTILINE
;
545 if ( m_noPageTheme
&& m_type
== Type_Notebook
)
546 flags
|= wxNB_NOPAGETHEME
;
549 if ( m_buttonBar
&& m_type
== Type_Toolbook
)
550 flags
|= wxTBK_BUTTONBAR
;
551 if ( m_horzLayout
&& m_type
== Type_Toolbook
)
552 flags
|= wxTBK_HORZ_LAYOUT
;
555 wxBookCtrlBase
*oldBook
= m_bookCtrl
;
559 DISPATCH_ON_TYPE(m_bookCtrl
= new,
566 (m_panel
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, flags
));
573 // wxToolbook doesn't work without icons so always use them for it.
574 if ( m_chkShowImages
|| m_type
== Type_Toolbook
)
576 m_bookCtrl
->SetImageList(m_imageList
);
582 // we only need the old treebook if we're recreating another treebook
583 wxTreebook
*tbkOld
= m_type
== Type_Treebook
584 ? wxDynamicCast(oldBook
, wxTreebook
)
586 #endif // wxUSE_TREEBOOK
588 const int count
= oldBook
->GetPageCount();
589 for ( int n
= 0; n
< count
; n
++ )
591 const int image
= GetIconIndex(m_bookCtrl
);
592 const wxString str
= oldBook
->GetPageText(n
);
594 wxWindow
*page
= CreatePage(m_bookCtrl
, str
);
596 // treebook complication: need to account for possible parent page
600 const int parent
= tbkOld
->GetPageParent(n
);
601 if ( parent
!= wxNOT_FOUND
)
603 wxStaticCast(m_bookCtrl
, wxTreebook
)->
604 InsertSubPage(parent
, page
, str
, false, image
);
606 // skip adding it again below
610 #endif // wxUSE_TREEBOOK
612 m_bookCtrl
->AddPage(page
, str
, false, image
);
615 const int sel
= oldBook
->GetSelection();
616 if ( sel
!= wxNOT_FOUND
)
617 m_bookCtrl
->SetSelection(sel
);
620 m_sizerFrame
->Detach(oldBook
);
625 CreateInitialPages(m_bookCtrl
);
628 m_sizerFrame
->Insert(0, m_bookCtrl
, wxSizerFlags(5).Expand().Border());
630 m_sizerFrame
->Show(m_bookCtrl
);
631 m_sizerFrame
->Layout();
634 void MyFrame::AddFlagStrIfFlagPresent(wxString
& flagStr
, long flags
, long flag
,
635 const wxChar
* flagName
) const
637 if( (flags
& flag
) == flag
)
639 if( !flagStr
.empty() )
640 flagStr
+= wxT(" | ");
645 wxPanel
*MyFrame::CreateNewPage() const
647 wxPanel
*panel
= new wxPanel(m_bookCtrl
, wxID_ANY
);
650 panel
->SetHelpText( wxT( "Panel with \"First\" and \"Second\" buttons" ) );
653 (void) new wxButton(panel
, wxID_ANY
, wxT("First button"), wxPoint(10, 30));
654 (void) new wxButton(panel
, wxID_ANY
, wxT("Second button"), wxPoint(150, 30));
660 //-----------------------------------------------------------------------------
661 // MyFrame - event handlers
662 //-----------------------------------------------------------------------------
666 void MyFrame::OnContextHelp(wxCommandEvent
& WXUNUSED(event
))
668 // launches local event loop
669 wxContextHelp
ch( this );
674 void MyFrame::OnHitTest(wxCommandEvent
& WXUNUSED(event
))
676 wxBookCtrlBase
* book
= GetCurrentBook();
677 const wxPoint pt
= ::wxGetMousePosition();
680 int pagePos
= book
->HitTest( book
->ScreenToClient(pt
), &flags
);
684 AddFlagStrIfFlagPresent( flagsStr
, flags
, wxBK_HITTEST_NOWHERE
, wxT("wxBK_HITTEST_NOWHERE") );
685 AddFlagStrIfFlagPresent( flagsStr
, flags
, wxBK_HITTEST_ONICON
, wxT("wxBK_HITTEST_ONICON") );
686 AddFlagStrIfFlagPresent( flagsStr
, flags
, wxBK_HITTEST_ONLABEL
, wxT("wxBK_HITTEST_ONLABEL") );
687 AddFlagStrIfFlagPresent( flagsStr
, flags
, wxBK_HITTEST_ONPAGE
, wxT("wxBK_HITTEST_ONPAGE") );
689 wxLogMessage(wxT("HitTest at (%d,%d): %d: %s"),
696 void MyFrame::OnType(wxCommandEvent
& event
)
698 m_type
= static_cast<BookType
>(event
.GetId() - ID_BOOK_NOTEBOOK
);
701 m_sizerFrame
->Hide(m_bookCtrl
);
708 void MyFrame::OnUpdateTreeMenu(wxUpdateUIEvent
& event
)
710 event
.Enable(m_type
== Type_Treebook
);
713 #endif // wxUSE_TREEBOOK
715 void MyFrame::OnOrient(wxCommandEvent
& event
)
717 m_orient
= event
.GetId();
719 m_sizerFrame
->Layout();
722 void MyFrame::OnShowImages(wxCommandEvent
& event
)
724 m_chkShowImages
= event
.IsChecked();
726 m_sizerFrame
->Layout();
729 void MyFrame::OnStyle(wxCommandEvent
& event
)
731 bool checked
= event
.IsChecked();
732 switch (event
.GetId())
734 case ID_FIXEDWIDTH
: m_fixedWidth
= checked
; break;
735 case ID_MULTI
: m_multi
= checked
; break;
736 case ID_NOPAGETHEME
: m_noPageTheme
= checked
; break;
737 case ID_BUTTONBAR
: m_buttonBar
= checked
; break;
738 case ID_HORZ_LAYOUT
: m_horzLayout
= checked
; break;
739 default: break; // avoid compiler warning
743 m_sizerFrame
->Layout();
746 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
751 void MyFrame::OnAddPage(wxCommandEvent
& WXUNUSED(event
))
753 wxBookCtrlBase
*currBook
= GetCurrentBook();
757 static unsigned s_pageAdded
= 0;
758 currBook
->AddPage(CreateNewPage(),
761 ADDED_PAGE_NAME
wxT("%u"),
765 GetIconIndex(currBook
));
769 void MyFrame::OnAddPageNoSelect(wxCommandEvent
& WXUNUSED(event
))
771 wxBookCtrlBase
*currBook
= GetCurrentBook();
775 static unsigned s_pageAdded
= 0;
776 currBook
->AddPage(CreateNewPage(),
779 ADDED_PAGE_NAME
wxT("%u"),
783 GetIconIndex(currBook
));
788 void MyFrame::OnAddSubPage(wxCommandEvent
& WXUNUSED(event
))
790 wxTreebook
*currBook
= wxDynamicCast(GetCurrentBook(), wxTreebook
);
793 const int selPos
= currBook
->GetSelection();
794 if ( selPos
== wxNOT_FOUND
)
796 wxLogError(wxT("Select the parent page first!"));
800 static unsigned s_subPageAdded
= 0;
801 currBook
->InsertSubPage
807 ADDED_SUB_PAGE_NAME
wxT("%u"),
811 GetIconIndex(currBook
)
816 void MyFrame::OnAddPageBefore(wxCommandEvent
& WXUNUSED(event
))
818 wxBookCtrlBase
*currBook
= GetCurrentBook();
821 const int selPos
= currBook
->GetSelection();
822 if ( selPos
== wxNOT_FOUND
)
824 wxLogError(wxT("Select the parent page first!"));
828 static unsigned s_subPageAdded
= 0;
829 currBook
->InsertPage(selPos
,
833 ADDED_PAGE_NAME_BEFORE
wxT("%u"),
837 GetIconIndex(currBook
));
840 #endif // wxUSE_TREEBOOK
842 void MyFrame::OnInsertPage(wxCommandEvent
& WXUNUSED(event
))
844 static unsigned s_pageIns
= 0;
846 wxBookCtrlBase
*currBook
= GetCurrentBook();
850 wxPanel
*panel
= CreateUserCreatedPage( currBook
);
852 currBook
->InsertPage( 0, panel
,
853 wxString::Format(INSERTED_PAGE_NAME
wxT("%u"), ++s_pageIns
), false,
854 GetIconIndex(currBook
) );
856 currBook
->SetSelection(0);
860 void MyFrame::OnDeleteCurPage(wxCommandEvent
& WXUNUSED(event
))
862 wxBookCtrlBase
*currBook
= GetCurrentBook();
866 int sel
= currBook
->GetSelection();
868 if (sel
!= wxNOT_FOUND
)
870 currBook
->DeletePage(sel
);
875 void MyFrame::OnDeleteLastPage(wxCommandEvent
& WXUNUSED(event
))
877 wxBookCtrlBase
*currBook
= GetCurrentBook();
881 int page
= currBook
->GetPageCount();
885 currBook
->DeletePage(page
- 1);
890 void MyFrame::OnNextPage(wxCommandEvent
& WXUNUSED(event
))
892 wxBookCtrlBase
*currBook
= GetCurrentBook();
896 currBook
->AdvanceSelection();
900 void MyFrame::OnChangeSelection(wxCommandEvent
& WXUNUSED(event
))
902 wxBookCtrlBase
*currBook
= GetCurrentBook();
905 currBook
->ChangeSelection(0);
908 void MyFrame::OnSetSelection(wxCommandEvent
& WXUNUSED(event
))
910 wxBookCtrlBase
*currBook
= GetCurrentBook();
913 currBook
->SetSelection(0);
916 void MyFrame::OnGetPageSize(wxCommandEvent
& WXUNUSED(event
))
918 wxBookCtrlBase
* const currBook
= GetCurrentBook();
922 const wxSize sizePage
= currBook
->GetPage(0)->GetSize();
923 const wxSize sizeBook
= currBook
->GetSize();
925 wxLogMessage("Page size is (%d, %d), book size (%d, %d)",
926 sizePage
.x
, sizePage
.y
,
927 sizeBook
.x
, sizeBook
.y
);
930 void MyFrame::OnSetPageSize(wxCommandEvent
& WXUNUSED(event
))
932 wxBookCtrlBase
* const currBook
= GetCurrentBook();
936 const wxSize
sizePage(300, 300);
937 currBook
->SetPageSize(sizePage
);
939 wxLogMessage("Page size set to (%d, %d)",
940 sizePage
.x
, sizePage
.y
);
943 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
945 static int s_nPages
= wxNOT_FOUND
;
946 static int s_nSel
= wxNOT_FOUND
;
947 static wxBookCtrlBase
*s_currBook
= NULL
;
949 wxBookCtrlBase
*currBook
= GetCurrentBook();
951 int nPages
= currBook
? currBook
->GetPageCount() : 0;
952 int nSel
= currBook
? currBook
->GetSelection() : wxNOT_FOUND
;
954 if ( nPages
!= s_nPages
|| nSel
!= s_nSel
|| s_currBook
!= currBook
)
958 s_currBook
= currBook
;
961 if ( nSel
== wxNOT_FOUND
)
962 selection
<< wxT("not found");
967 title
.Printf(wxT("Notebook and friends (%d pages, selection: %s)"), nPages
, selection
.c_str());
973 void MyFrame::OnBookCtrl(wxBookCtrlBaseEvent
& event
)
975 static const struct EventInfo
977 wxEventType typeChanged
,
984 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
,
985 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
,
988 #endif // wxUSE_NOTEBOOK
991 wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED
,
992 wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING
,
995 #endif // wxUSE_LISTBOOK
998 wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED
,
999 wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING
,
1002 #endif // wxUSE_CHOICEBOOK
1005 wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED
,
1006 wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING
,
1009 #endif // wxUSE_TREEBOOK
1012 wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGED
,
1013 wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGING
,
1016 #endif // wxUSE_TOOLBOOK
1019 wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED
,
1020 wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGING
,
1021 wxT("wxAuiNotebook")
1030 const wxEventType eventType
= event
.GetEventType();
1032 // NB: can't use wxStaticCast here as wxBookCtrlBase is not in
1034 const wxBookCtrlBase
* const
1035 book
= static_cast<wxBookCtrlBase
*>(event
.GetEventObject());
1037 for ( size_t n
= 0; n
< WXSIZEOF(events
); n
++ )
1039 const EventInfo
& ei
= events
[n
];
1040 if ( eventType
== ei
.typeChanged
)
1042 nameEvent
= wxT("Changed");
1044 else if ( eventType
== ei
.typeChanging
)
1046 const int idx
= event
.GetOldSelection();
1048 if ( idx
!= wxNOT_FOUND
&&
1049 book
&& book
->GetPageText(idx
) == VETO_PAGE_NAME
)
1053 wxT("Are you sure you want to leave this page?\n")
1054 wxT("(This demonstrates veto-ing)"),
1055 wxT("Notebook sample"),
1056 wxICON_QUESTION
| wxYES_NO
,
1061 veto
= wxT(" (vetoed)");
1065 nameEvent
= wxT("Changing");
1067 else // skip end of the loop
1072 nameControl
= ei
.name
;
1076 static int s_num
= 0;
1078 wxLogMessage(wxT("Event #%d: %s: %s (%d) new sel %d, old %d, current %d%s"),
1080 nameControl
.c_str(),
1083 event
.GetSelection(),
1084 event
.GetOldSelection(),
1085 book
->GetSelection(),
1089 m_text
->SetInsertionPointEnd();