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 // License: wxWindows license
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"
38 wxHelpProvider::Set( new wxSimpleHelpProvider
);
41 // Create the main window
42 MyFrame
*frame
= new MyFrame();
44 // Problem with generic wxNotebook implementation whereby it doesn't size
45 // properly unless you set the size again
46 #if defined(__WXMOTIF__)
48 frame
->GetSize(& width
, & height
);
49 frame
->SetSize(wxDefaultCoord
, wxDefaultCoord
, width
, height
);
57 wxPanel
*CreateUserCreatedPage(wxBookCtrlBase
*parent
)
59 wxPanel
*panel
= new wxPanel(parent
);
62 panel
->SetHelpText( wxT( "Panel with a Button" ) );
65 (void) new wxButton( panel
, wxID_ANY
, wxT("Button"),
66 wxPoint(10, 10), wxDefaultSize
);
71 wxPanel
*CreateRadioButtonsPage(wxBookCtrlBase
*parent
)
73 wxPanel
*panel
= new wxPanel(parent
);
76 panel
->SetHelpText( wxT( "Panel with some Radio Buttons" ) );
79 wxString animals
[] = { wxT("Fox"), wxT("Hare"), wxT("Rabbit"),
80 wxT("Sabre-toothed tiger"), wxT("T Rex") };
82 wxRadioBox
*radiobox1
= new wxRadioBox(panel
, wxID_ANY
, wxT("Choose one"),
83 wxDefaultPosition
, wxDefaultSize
, 5, animals
, 2, wxRA_SPECIFY_ROWS
);
85 wxString computers
[] = { wxT("Amiga"), wxT("Commodore 64"), wxT("PET"),
88 wxRadioBox
*radiobox2
= new wxRadioBox(panel
, wxID_ANY
,
89 wxT("Choose your favourite"), wxDefaultPosition
, wxDefaultSize
,
90 4, computers
, 0, wxRA_SPECIFY_COLS
);
92 wxBoxSizer
*sizerPanel
= new wxBoxSizer(wxVERTICAL
);
93 sizerPanel
->Add(radiobox1
, 2, wxEXPAND
);
94 sizerPanel
->Add(radiobox2
, 1, wxEXPAND
);
95 panel
->SetSizer(sizerPanel
);
100 wxPanel
*CreateVetoPage(wxBookCtrlBase
*parent
)
102 wxPanel
*panel
= new wxPanel(parent
);
105 panel
->SetHelpText( wxT( "An empty panel" ) );
108 (void) new wxStaticText( panel
, wxID_ANY
,
109 wxT("This page intentionally left blank"), wxPoint(10, 10) );
114 wxPanel
*CreateBigButtonPage(wxBookCtrlBase
*parent
)
116 wxPanel
*panel
= new wxPanel(parent
);
119 panel
->SetHelpText( wxT( "Panel with a maximized button" ) );
122 wxButton
*buttonBig
= new wxButton(panel
, wxID_ANY
, wxT("Maximized button"));
124 wxBoxSizer
*sizerPanel
= new wxBoxSizer(wxVERTICAL
);
125 sizerPanel
->Add(buttonBig
, 1, wxEXPAND
);
126 panel
->SetSizer(sizerPanel
);
132 wxPanel
*CreateInsertPage(wxBookCtrlBase
*parent
)
134 wxPanel
*panel
= new wxPanel(parent
);
137 panel
->SetHelpText( wxT( "Maroon panel" ) );
140 panel
->SetBackgroundColour( wxColour( wxT("MAROON") ) );
141 (void) new wxStaticText( panel
, wxID_ANY
,
142 wxT("This page has been inserted, not added."), wxPoint(10, 10) );
147 int GetIconIndex(wxBookCtrlBase
* bookCtrl
)
149 if (bookCtrl
&& bookCtrl
->GetImageList())
151 int nImages
= bookCtrl
->GetImageList()->GetImageCount();
154 return bookCtrl
->GetPageCount() % nImages
;
161 void CreateInitialPages(wxBookCtrlBase
*parent
)
163 // Create and add some panels to the notebook
165 wxPanel
*panel
= CreateRadioButtonsPage(parent
);
166 parent
->AddPage( panel
, RADIOBUTTONS_PAGE_NAME
, false, GetIconIndex(parent
) );
168 panel
= CreateVetoPage(parent
);
169 parent
->AddPage( panel
, VETO_PAGE_NAME
, false, GetIconIndex(parent
) );
171 panel
= CreateBigButtonPage(parent
);
172 parent
->AddPage( panel
, MAXIMIZED_BUTTON_PAGE_NAME
, false, GetIconIndex(parent
) );
174 panel
= CreateInsertPage(parent
);
175 parent
->InsertPage( 0, panel
, I_WAS_INSERTED_PAGE_NAME
, false, GetIconIndex(parent
) );
177 parent
->SetSelection(1);
180 wxPanel
*CreatePage(wxBookCtrlBase
*parent
, const wxString
&pageName
)
182 if ( pageName
.Contains(INSERTED_PAGE_NAME
) ||
183 pageName
.Contains(ADDED_PAGE_NAME
) ||
184 pageName
.Contains(ADDED_SUB_PAGE_NAME
) ||
185 pageName
.Contains(ADDED_PAGE_NAME_BEFORE
) )
186 return CreateUserCreatedPage(parent
);
188 if ( pageName
== I_WAS_INSERTED_PAGE_NAME
)
189 return CreateInsertPage(parent
);
191 if ( pageName
== VETO_PAGE_NAME
)
192 return CreateVetoPage(parent
);
194 if ( pageName
== RADIOBUTTONS_PAGE_NAME
)
195 return CreateRadioButtonsPage(parent
);
197 if ( pageName
== MAXIMIZED_BUTTON_PAGE_NAME
)
198 return CreateBigButtonPage(parent
);
200 wxFAIL_MSG( _T("unknown page name") );
206 : wxFrame(NULL
, wxID_ANY
, wxString(wxT("wxWidgets book controls sample")))
209 SetExtraStyle(wxFRAME_EX_CONTEXTHELP
);
213 m_type
= Type_Notebook
;
214 #elif wxUSE_CHOICEBOOK
215 m_type
= Type_Choicebook
;
217 m_type
= Type_Listbook
;
219 m_type
= Type_Treebook
;
221 #error "Don't use Notebook sample without any book enabled in wxWidgets build!"
224 m_orient
= ID_ORIENT_DEFAULT
;
225 m_chkShowImages
= true;
228 SetIcon(wxICON(sample
));
230 // menu of the sample
231 wxMenu
*menuType
= new wxMenu
;
233 menuType
->AppendRadioItem(ID_BOOK_NOTEBOOK
, wxT("&Notebook\tCtrl-1"));
236 menuType
->AppendRadioItem(ID_BOOK_LISTBOOK
, wxT("&Listbook\tCtrl-2"));
239 menuType
->AppendRadioItem(ID_BOOK_CHOICEBOOK
, wxT("&Choicebook\tCtrl-3"));
242 menuType
->AppendRadioItem(ID_BOOK_TREEBOOK
, wxT("&Treebook\tCtrl-4"));
245 menuType
->AppendRadioItem(ID_BOOK_TOOLBOOK
, wxT("T&oolbook\tCtrl-5"));
248 menuType
->Check(ID_BOOK_NOTEBOOK
+ m_type
, true);
250 wxMenu
*menuOrient
= new wxMenu
;
251 menuOrient
->AppendRadioItem(ID_ORIENT_DEFAULT
, wxT("&Default\tCtrl-5"));
252 menuOrient
->AppendRadioItem(ID_ORIENT_TOP
, wxT("&Top\tCtrl-6"));
253 menuOrient
->AppendRadioItem(ID_ORIENT_BOTTOM
, wxT("&Bottom\tCtrl-7"));
254 menuOrient
->AppendRadioItem(ID_ORIENT_LEFT
, wxT("&Left\tCtrl-8"));
255 menuOrient
->AppendRadioItem(ID_ORIENT_RIGHT
, wxT("&Right\tCtrl-9"));
257 wxMenu
*menuPageOperations
= new wxMenu
;
258 menuPageOperations
->Append(ID_ADD_PAGE
, wxT("&Add page\tAlt-A"));
259 menuPageOperations
->Append(ID_ADD_PAGE_NO_SELECT
, wxT("&Add page (don't select)\tAlt-B"));
260 menuPageOperations
->Append(ID_INSERT_PAGE
, wxT("&Insert page\tAlt-I"));
261 menuPageOperations
->Append(ID_DELETE_CUR_PAGE
, wxT("&Delete current page\tAlt-D"));
262 menuPageOperations
->Append(ID_DELETE_LAST_PAGE
, wxT("D&elete last page\tAlt-L"));
263 menuPageOperations
->Append(ID_NEXT_PAGE
, wxT("&Next page\tAlt-N"));
265 menuPageOperations
->AppendSeparator();
266 menuPageOperations
->Append(ID_ADD_PAGE_BEFORE
, wxT("Insert page &before\tAlt-B"));
267 menuPageOperations
->Append(ID_ADD_SUB_PAGE
, wxT("Add s&ub page\tAlt-U"));
269 menuPageOperations
->AppendSeparator();
270 menuPageOperations
->Append(ID_GO_HOME
, wxT("Go to the first page\tCtrl-F"));
272 wxMenu
*menuOperations
= new wxMenu
;
274 menuOperations
->Append(ID_CONTEXT_HELP
, wxT("&Context help\tCtrl-F1"));
276 menuOperations
->Append(ID_HITTEST
, wxT("&Hit test\tCtrl-H"));
278 wxMenu
*menuFile
= new wxMenu
;
279 menuFile
->Append(wxID_ANY
, wxT("&Type"), menuType
, wxT("Type of control"));
280 menuFile
->Append(wxID_ANY
, wxT("&Orientation"), menuOrient
, wxT("Orientation of control"));
281 menuFile
->AppendCheckItem(ID_SHOW_IMAGES
, wxT("&Show images\tAlt-S"));
282 menuFile
->AppendCheckItem(ID_MULTI
, wxT("&Multiple lines\tAlt-M"));
283 menuFile
->AppendSeparator();
284 menuFile
->Append(wxID_EXIT
, wxT("E&xit"), wxT("Quits the application"));
285 menuFile
->Check(ID_SHOW_IMAGES
, m_chkShowImages
);
286 menuFile
->Check(ID_MULTI
, m_multi
);
288 wxMenuBar
*menuBar
= new wxMenuBar
;
289 menuBar
->Append(menuFile
, wxT("&File"));
290 menuBar
->Append(menuPageOperations
, wxT("&Pages"));
291 menuBar
->Append(menuOperations
, wxT("&Operations"));
298 // create a dummy image list with a few icons
299 const wxSize
imageSize(32, 32);
301 m_imageList
= new wxImageList(imageSize
.GetWidth(), imageSize
.GetHeight());
303 Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, imageSize
));
305 Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, imageSize
));
307 Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, imageSize
));
309 Add(wxArtProvider::GetIcon(wxART_ERROR
, wxART_OTHER
, imageSize
));
311 m_panel
= new wxPanel(this);
314 m_text
= new wxTextCtrl(m_panel
, wxID_ANY
, wxEmptyString
,
315 wxDefaultPosition
, wxDefaultSize
,
316 wxTE_MULTILINE
| wxTE_READONLY
);
318 m_logTargetOld
= wxLog::SetActiveTarget( new wxLogTextCtrl(m_text
) );
322 m_sizerFrame
= new wxBoxSizer(wxVERTICAL
);
325 m_sizerFrame
->Add(m_text
, 1, wxEXPAND
);
330 m_panel
->SetSizer(m_sizerFrame
);
332 m_sizerFrame
->Fit(this);
333 m_sizerFrame
->SetSizeHints(this);
341 delete wxLog::SetActiveTarget(m_logTargetOld
);
347 // DISPATCH_ON_TYPE() macro is an ugly way to write the "same" code for
348 // different wxBookCtrlBase-derived classes without duplicating code and
349 // without using templates, it expands into "before <xxx> after" where "xxx"
350 // part is control class-specific
352 #define CASE_NOTEBOOK(x) case Type_Notebook: x; break;
354 #define CASE_NOTEBOOK(x)
358 #define CASE_LISTBOOK(x) case Type_Listbook: x; break;
360 #define CASE_LISTBOOK(x)
364 #define CASE_CHOICEBOOK(x) case Type_Choicebook: x; break;
366 #define CASE_CHOICEBOOK(x)
370 #define CASE_TREEBOOK(x) case Type_Treebook: x; break;
372 #define CASE_TREEBOOK(x)
376 #define CASE_TOOLBOOK(x) case Type_Toolbook: x; break;
378 #define CASE_TOOLBOOK(x)
381 #define DISPATCH_ON_TYPE(before, nb, lb, cb, tb, toolb, after) \
384 CASE_NOTEBOOK(before nb after) \
385 CASE_LISTBOOK(before lb after) \
386 CASE_CHOICEBOOK(before cb after) \
387 CASE_TREEBOOK(before tb after) \
388 CASE_TOOLBOOK(before toolb after) \
391 wxFAIL_MSG( _T("unknown book control type") ); \
394 int MyFrame::TranslateBookFlag(int nb
, int lb
, int chb
, int tbk
, int toolbk
) const
398 DISPATCH_ON_TYPE(flag
=, nb
, lb
, chb
, tbk
, toolbk
, + 0);
403 void MyFrame::RecreateBook()
412 case ID_ORIENT_BOTTOM
:
420 case ID_ORIENT_RIGHT
:
425 flags
= wxBK_DEFAULT
;
428 if ( m_multi
&& m_type
== Type_Notebook
)
429 flags
|= wxNB_MULTILINE
;
430 flags
|= wxDOUBLE_BORDER
;
432 wxBookCtrlBase
*oldBook
= m_bookCtrl
;
436 DISPATCH_ON_TYPE(m_bookCtrl
= new,
442 (m_panel
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, flags
));
449 if ( m_chkShowImages
)
451 m_bookCtrl
->SetImageList(m_imageList
);
457 // we only need the old treebook if we're recreating another treebook
458 wxTreebook
*tbkOld
= m_type
== Type_Treebook
459 ? wxDynamicCast(oldBook
, wxTreebook
)
461 #endif // wxUSE_TREEBOOK
463 const int count
= oldBook
->GetPageCount();
464 for ( int n
= 0; n
< count
; n
++ )
466 const int image
= GetIconIndex(m_bookCtrl
);
467 const wxString str
= oldBook
->GetPageText(n
);
469 wxWindow
*page
= CreatePage(m_bookCtrl
, str
);
471 // treebook complication: need to account for possible parent page
475 const int parent
= tbkOld
->GetPageParent(n
);
476 if ( parent
!= wxNOT_FOUND
)
478 wxStaticCast(m_bookCtrl
, wxTreebook
)->
479 InsertSubPage(parent
, page
, str
, false, image
);
481 // skip adding it again below
485 #endif // wxUSE_TREEBOOK
487 m_bookCtrl
->AddPage(page
, str
, false, image
);
490 const int sel
= oldBook
->GetSelection();
491 if ( sel
!= wxNOT_FOUND
)
492 m_bookCtrl
->SetSelection(sel
);
495 m_sizerFrame
->Detach(oldBook
);
500 CreateInitialPages(m_bookCtrl
);
503 m_sizerFrame
->Insert(0, m_bookCtrl
, wxSizerFlags(5).Expand().Border());
505 m_sizerFrame
->Show(m_bookCtrl
);
506 m_sizerFrame
->Layout();
509 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
511 EVT_MENU_RANGE(ID_BOOK_NOTEBOOK
, ID_BOOK_MAX
, MyFrame::OnType
)
512 EVT_MENU_RANGE(ID_ORIENT_DEFAULT
, ID_ORIENT_MAX
, MyFrame::OnOrient
)
513 EVT_MENU(ID_SHOW_IMAGES
, MyFrame::OnShowImages
)
514 EVT_MENU(ID_MULTI
, MyFrame::OnMulti
)
515 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
518 EVT_MENU(ID_ADD_PAGE
, MyFrame::OnAddPage
)
519 EVT_MENU(ID_ADD_PAGE_NO_SELECT
, MyFrame::OnAddPageNoSelect
)
520 EVT_MENU(ID_INSERT_PAGE
, MyFrame::OnInsertPage
)
521 EVT_MENU(ID_DELETE_CUR_PAGE
, MyFrame::OnDeleteCurPage
)
522 EVT_MENU(ID_DELETE_LAST_PAGE
, MyFrame::OnDeleteLastPage
)
523 EVT_MENU(ID_NEXT_PAGE
, MyFrame::OnNextPage
)
524 EVT_MENU(ID_GO_HOME
, MyFrame::OnGoHome
)
527 EVT_MENU(ID_CONTEXT_HELP
, MyFrame::OnContextHelp
)
529 EVT_MENU(ID_HITTEST
, MyFrame::OnHitTest
)
533 EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY
, MyFrame::OnNotebook
)
534 EVT_NOTEBOOK_PAGE_CHANGING(wxID_ANY
, MyFrame::OnNotebook
)
537 EVT_LISTBOOK_PAGE_CHANGED(wxID_ANY
, MyFrame::OnListbook
)
538 EVT_LISTBOOK_PAGE_CHANGING(wxID_ANY
, MyFrame::OnListbook
)
541 EVT_CHOICEBOOK_PAGE_CHANGED(wxID_ANY
, MyFrame::OnChoicebook
)
542 EVT_CHOICEBOOK_PAGE_CHANGING(wxID_ANY
, MyFrame::OnChoicebook
)
545 EVT_TREEBOOK_PAGE_CHANGED(wxID_ANY
, MyFrame::OnTreebook
)
546 EVT_TREEBOOK_PAGE_CHANGING(wxID_ANY
, MyFrame::OnTreebook
)
548 EVT_MENU(ID_ADD_SUB_PAGE
, MyFrame::OnAddSubPage
)
549 EVT_MENU(ID_ADD_PAGE_BEFORE
, MyFrame::OnAddPageBefore
)
550 EVT_UPDATE_UI_RANGE(ID_ADD_PAGE_BEFORE
, ID_ADD_SUB_PAGE
,
551 MyFrame::OnUpdateTreeMenu
)
554 EVT_TOOLBOOK_PAGE_CHANGED(wxID_ANY
, MyFrame::OnToolbook
)
555 EVT_TOOLBOOK_PAGE_CHANGING(wxID_ANY
, MyFrame::OnToolbook
)
558 // Update title in idle time
559 EVT_IDLE(MyFrame::OnIdle
)
564 void MyFrame::OnContextHelp(wxCommandEvent
& WXUNUSED(event
))
566 // launches local event loop
567 wxContextHelp
ch( this );
572 void MyFrame::AddFlagStrIfFlagPresent(wxString
& flagStr
, long flags
, long flag
, const wxChar
* flagName
) const
574 if( (flags
& flag
) == flag
)
576 if( !flagStr
.empty() )
577 flagStr
+= _T(" | ");
582 void MyFrame::OnHitTest(wxCommandEvent
& WXUNUSED(event
))
584 wxBookCtrlBase
* book
= GetCurrentBook();
585 const wxPoint pt
= ::wxGetMousePosition();
588 int pagePos
= book
->HitTest( book
->ScreenToClient(pt
), &flags
);
592 AddFlagStrIfFlagPresent( flagsStr
, flags
, wxBK_HITTEST_NOWHERE
, _T("wxBK_HITTEST_NOWHERE") );
593 AddFlagStrIfFlagPresent( flagsStr
, flags
, wxBK_HITTEST_ONICON
, _T("wxBK_HITTEST_ONICON") );
594 AddFlagStrIfFlagPresent( flagsStr
, flags
, wxBK_HITTEST_ONLABEL
, _T("wxBK_HITTEST_ONLABEL") );
595 AddFlagStrIfFlagPresent( flagsStr
, flags
, wxBK_HITTEST_ONPAGE
, _T("wxBK_HITTEST_ONPAGE") );
597 wxLogMessage(wxT("HitTest at (%d,%d): %d: %s"),
604 void MyFrame::OnType(wxCommandEvent
& event
)
606 m_type
= wx_static_cast(BookType
, event
.GetId() - ID_BOOK_NOTEBOOK
);
609 m_sizerFrame
->Hide(m_bookCtrl
);
616 void MyFrame::OnUpdateTreeMenu(wxUpdateUIEvent
& event
)
618 event
.Enable(m_type
== Type_Treebook
);
621 #endif // wxUSE_TREEBOOK
624 void MyFrame::OnOrient(wxCommandEvent
& event
)
626 m_orient
= event
.GetId();
628 m_sizerFrame
->Layout();
631 void MyFrame::OnShowImages(wxCommandEvent
& event
)
633 m_chkShowImages
= event
.IsChecked();
635 m_sizerFrame
->Layout();
638 void MyFrame::OnMulti(wxCommandEvent
& event
)
640 m_multi
= event
.IsChecked();
642 m_sizerFrame
->Layout();
643 wxLogMessage(_T("Multiline setting works only in wxNotebook."));
646 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
651 wxPanel
*MyFrame::CreateNewPage() const
653 wxPanel
*panel
= new wxPanel(m_bookCtrl
, wxID_ANY
);
656 panel
->SetHelpText( wxT( "Panel with \"First\" and \"Second\" buttons" ) );
659 (void) new wxButton(panel
, wxID_ANY
, wxT("First button"), wxPoint(10, 10));
660 (void) new wxButton(panel
, wxID_ANY
, wxT("Second button"), wxPoint(50, 100));
665 void MyFrame::OnAddPage(wxCommandEvent
& WXUNUSED(event
))
667 wxBookCtrlBase
*currBook
= GetCurrentBook();
671 static unsigned s_pageAdded
= 0;
672 currBook
->AddPage(CreateNewPage(),
675 ADDED_PAGE_NAME
wxT("%u"),
679 GetIconIndex(currBook
));
683 void MyFrame::OnAddPageNoSelect(wxCommandEvent
& WXUNUSED(event
))
685 wxBookCtrlBase
*currBook
= GetCurrentBook();
689 static unsigned s_pageAdded
= 0;
690 currBook
->AddPage(CreateNewPage(),
693 ADDED_PAGE_NAME
wxT("%u"),
697 GetIconIndex(currBook
));
702 void MyFrame::OnAddSubPage(wxCommandEvent
& WXUNUSED(event
))
704 wxTreebook
*currBook
= wxDynamicCast(GetCurrentBook(), wxTreebook
);
707 const int selPos
= currBook
->GetSelection();
708 if ( selPos
== wxNOT_FOUND
)
710 wxLogError(_T("Select the parent page first!"));
714 static unsigned s_subPageAdded
= 0;
715 currBook
->InsertSubPage
721 ADDED_SUB_PAGE_NAME
wxT("%u"),
725 GetIconIndex(currBook
)
730 void MyFrame::OnAddPageBefore(wxCommandEvent
& WXUNUSED(event
))
732 wxBookCtrlBase
*currBook
= GetCurrentBook();
735 const int selPos
= currBook
->GetSelection();
736 if ( selPos
== wxNOT_FOUND
)
738 wxLogError(_T("Select the parent page first!"));
742 static unsigned s_subPageAdded
= 0;
743 currBook
->InsertPage(selPos
,
747 ADDED_PAGE_NAME_BEFORE
wxT("%u"),
751 GetIconIndex(currBook
));
754 #endif // wxUSE_TREEBOOK
756 void MyFrame::OnInsertPage(wxCommandEvent
& WXUNUSED(event
))
758 static unsigned s_pageIns
= 0;
760 wxBookCtrlBase
*currBook
= GetCurrentBook();
764 wxPanel
*panel
= CreateUserCreatedPage( currBook
);
766 currBook
->InsertPage( 0, panel
,
767 wxString::Format(INSERTED_PAGE_NAME
wxT("%u"), ++s_pageIns
), false,
768 GetIconIndex(currBook
) );
770 currBook
->SetSelection(0);
774 void MyFrame::OnDeleteCurPage(wxCommandEvent
& WXUNUSED(event
))
776 wxBookCtrlBase
*currBook
= GetCurrentBook();
780 int sel
= currBook
->GetSelection();
782 if (sel
!= wxNOT_FOUND
)
784 currBook
->DeletePage(sel
);
789 void MyFrame::OnDeleteLastPage(wxCommandEvent
& WXUNUSED(event
))
791 wxBookCtrlBase
*currBook
= GetCurrentBook();
795 int page
= currBook
->GetPageCount();
799 currBook
->DeletePage(page
- 1);
804 void MyFrame::OnNextPage(wxCommandEvent
& WXUNUSED(event
))
806 wxBookCtrlBase
*currBook
= GetCurrentBook();
810 currBook
->AdvanceSelection();
814 void MyFrame::OnGoHome(wxCommandEvent
& WXUNUSED(event
))
816 wxBookCtrlBase
*currBook
= GetCurrentBook();
820 // ChangeSelection shouldn't send any events, SetSelection() should
821 currBook
->ChangeSelection(0);
822 //currBook->SetSelection(0);
826 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
828 static int s_nPages
= wxNOT_FOUND
;
829 static int s_nSel
= wxNOT_FOUND
;
830 static wxBookCtrlBase
*s_currBook
= NULL
;
832 wxBookCtrlBase
*currBook
= GetCurrentBook();
834 int nPages
= currBook
? currBook
->GetPageCount() : 0;
835 int nSel
= currBook
? currBook
->GetSelection() : wxNOT_FOUND
;
837 if ( nPages
!= s_nPages
|| nSel
!= s_nSel
|| s_currBook
!= currBook
)
841 s_currBook
= currBook
;
844 if ( nSel
== wxNOT_FOUND
)
845 selection
<< wxT("not found");
850 title
.Printf(wxT("Notebook and friends (%d pages, selection: %s)"), nPages
, selection
.c_str());
856 void MyFrame::OnBookCtrl(wxBookCtrlBaseEvent
& event
)
858 static const struct EventInfo
860 wxEventType typeChanged
,
867 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
,
868 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
,
871 #endif // wxUSE_NOTEBOOK
874 wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED
,
875 wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING
,
878 #endif // wxUSE_LISTBOOK
881 wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED
,
882 wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING
,
885 #endif // wxUSE_CHOICEBOOK
888 wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED
,
889 wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING
,
892 #endif // wxUSE_TREEBOOK
895 wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGED
,
896 wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGING
,
899 #endif // wxUSE_TOOLBOOK
906 const wxEventType eventType
= event
.GetEventType();
907 for ( size_t n
= 0; n
< WXSIZEOF(events
); n
++ )
909 const EventInfo
& ei
= events
[n
];
910 if ( eventType
== ei
.typeChanged
)
912 nameEvent
= wxT("Changed");
914 else if ( eventType
== ei
.typeChanging
)
916 const int idx
= event
.GetOldSelection();
918 // NB: can't use wxStaticCast here as wxBookCtrlBase is not in
920 const wxBookCtrlBase
* const
921 book
= wx_static_cast(wxBookCtrlBase
*, event
.GetEventObject());
922 if ( idx
!= wxNOT_FOUND
&&
923 book
&& book
->GetPageText(idx
) == VETO_PAGE_NAME
)
927 wxT("Are you sure you want to leave this page?\n")
928 wxT("(This demonstrates veto-ing)"),
929 wxT("Notebook sample"),
930 wxICON_QUESTION
| wxYES_NO
,
935 veto
= _T(" (vetoed)");
939 nameEvent
= wxT("Changing");
941 else // skip end of the loop
946 nameControl
= ei
.name
;
950 static int s_num
= 0;
952 wxLogMessage(wxT("Event #%d: %s: %s (%d) new sel %d, old %d%s"),
957 event
.GetSelection(),
958 event
.GetOldSelection(),
962 m_text
->SetInsertionPointEnd();