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"
37 if ( !wxApp::OnInit() )
41 wxHelpProvider::Set( new wxSimpleHelpProvider
);
44 // Create the main window
45 MyFrame
*frame
= new MyFrame();
47 // Problem with generic wxNotebook implementation whereby it doesn't size
48 // properly unless you set the size again
49 #if defined(__WXMOTIF__)
51 frame
->GetSize(& width
, & height
);
52 frame
->SetSize(wxDefaultCoord
, wxDefaultCoord
, width
, height
);
60 wxPanel
*CreateUserCreatedPage(wxBookCtrlBase
*parent
)
62 wxPanel
*panel
= new wxPanel(parent
);
65 panel
->SetHelpText( wxT( "Panel with a Button" ) );
68 (void) new wxButton( panel
, wxID_ANY
, wxT("Button"),
69 wxPoint(10, 10), wxDefaultSize
);
74 wxPanel
*CreateRadioButtonsPage(wxBookCtrlBase
*parent
)
76 wxPanel
*panel
= new wxPanel(parent
);
79 panel
->SetHelpText( wxT( "Panel with some Radio Buttons" ) );
82 wxString animals
[] = { wxT("Fox"), wxT("Hare"), wxT("Rabbit"),
83 wxT("Sabre-toothed tiger"), wxT("T Rex") };
85 wxRadioBox
*radiobox1
= new wxRadioBox(panel
, wxID_ANY
, wxT("Choose one"),
86 wxDefaultPosition
, wxDefaultSize
, 5, animals
, 2, wxRA_SPECIFY_ROWS
);
88 wxString computers
[] = { wxT("Amiga"), wxT("Commodore 64"), wxT("PET"),
91 wxRadioBox
*radiobox2
= new wxRadioBox(panel
, wxID_ANY
,
92 wxT("Choose your favourite"), wxDefaultPosition
, wxDefaultSize
,
93 4, computers
, 0, wxRA_SPECIFY_COLS
);
95 wxBoxSizer
*sizerPanel
= new wxBoxSizer(wxVERTICAL
);
96 sizerPanel
->Add(radiobox1
, 2, wxEXPAND
);
97 sizerPanel
->Add(radiobox2
, 1, wxEXPAND
);
98 panel
->SetSizer(sizerPanel
);
103 wxPanel
*CreateVetoPage(wxBookCtrlBase
*parent
)
105 wxPanel
*panel
= new wxPanel(parent
);
108 panel
->SetHelpText( wxT( "An empty panel" ) );
111 (void) new wxStaticText( panel
, wxID_ANY
,
112 wxT("This page intentionally left blank"), wxPoint(10, 10) );
117 wxPanel
*CreateBigButtonPage(wxBookCtrlBase
*parent
)
119 wxPanel
*panel
= new wxPanel(parent
);
122 panel
->SetHelpText( wxT( "Panel with a maximized button" ) );
125 wxButton
*buttonBig
= new wxButton(panel
, wxID_ANY
, wxT("Maximized button"));
127 wxBoxSizer
*sizerPanel
= new wxBoxSizer(wxVERTICAL
);
128 sizerPanel
->Add(buttonBig
, 1, wxEXPAND
);
129 panel
->SetSizer(sizerPanel
);
135 wxPanel
*CreateInsertPage(wxBookCtrlBase
*parent
)
137 wxPanel
*panel
= new wxPanel(parent
);
140 panel
->SetHelpText( wxT( "Maroon panel" ) );
143 panel
->SetBackgroundColour( wxColour( wxT("MAROON") ) );
144 (void) new wxStaticText( panel
, wxID_ANY
,
145 wxT("This page has been inserted, not added."), wxPoint(10, 10) );
150 int GetIconIndex(wxBookCtrlBase
* bookCtrl
)
152 if (bookCtrl
&& bookCtrl
->GetImageList())
154 int nImages
= bookCtrl
->GetImageList()->GetImageCount();
157 return bookCtrl
->GetPageCount() % nImages
;
164 void CreateInitialPages(wxBookCtrlBase
*parent
)
166 // Create and add some panels to the notebook
168 wxPanel
*panel
= CreateRadioButtonsPage(parent
);
169 parent
->AddPage( panel
, RADIOBUTTONS_PAGE_NAME
, false, GetIconIndex(parent
) );
171 panel
= CreateVetoPage(parent
);
172 parent
->AddPage( panel
, VETO_PAGE_NAME
, false, GetIconIndex(parent
) );
174 panel
= CreateBigButtonPage(parent
);
175 parent
->AddPage( panel
, MAXIMIZED_BUTTON_PAGE_NAME
, false, GetIconIndex(parent
) );
177 panel
= CreateInsertPage(parent
);
178 parent
->InsertPage( 0, panel
, I_WAS_INSERTED_PAGE_NAME
, false, GetIconIndex(parent
) );
180 parent
->SetSelection(1);
183 wxPanel
*CreatePage(wxBookCtrlBase
*parent
, const wxString
&pageName
)
185 if ( pageName
.Contains(INSERTED_PAGE_NAME
) ||
186 pageName
.Contains(ADDED_PAGE_NAME
) ||
187 pageName
.Contains(ADDED_SUB_PAGE_NAME
) ||
188 pageName
.Contains(ADDED_PAGE_NAME_BEFORE
) )
189 return CreateUserCreatedPage(parent
);
191 if ( pageName
== I_WAS_INSERTED_PAGE_NAME
)
192 return CreateInsertPage(parent
);
194 if ( pageName
== VETO_PAGE_NAME
)
195 return CreateVetoPage(parent
);
197 if ( pageName
== RADIOBUTTONS_PAGE_NAME
)
198 return CreateRadioButtonsPage(parent
);
200 if ( pageName
== MAXIMIZED_BUTTON_PAGE_NAME
)
201 return CreateBigButtonPage(parent
);
203 wxFAIL_MSG( _T("unknown page name") );
209 : wxFrame(NULL
, wxID_ANY
, wxString(wxT("wxWidgets book controls sample")))
212 SetExtraStyle(wxFRAME_EX_CONTEXTHELP
);
216 m_type
= Type_Notebook
;
217 #elif wxUSE_CHOICEBOOK
218 m_type
= Type_Choicebook
;
220 m_type
= Type_Listbook
;
222 m_type
= Type_Treebook
;
224 #error "Don't use Notebook sample without any book enabled in wxWidgets build!"
227 m_orient
= ID_ORIENT_DEFAULT
;
228 m_chkShowImages
= true;
231 SetIcon(wxICON(sample
));
233 // menu of the sample
234 wxMenu
*menuType
= new wxMenu
;
236 menuType
->AppendRadioItem(ID_BOOK_NOTEBOOK
, wxT("&Notebook\tCtrl-1"));
239 menuType
->AppendRadioItem(ID_BOOK_LISTBOOK
, wxT("&Listbook\tCtrl-2"));
242 menuType
->AppendRadioItem(ID_BOOK_CHOICEBOOK
, wxT("&Choicebook\tCtrl-3"));
245 menuType
->AppendRadioItem(ID_BOOK_TREEBOOK
, wxT("&Treebook\tCtrl-4"));
248 menuType
->AppendRadioItem(ID_BOOK_TOOLBOOK
, wxT("T&oolbook\tCtrl-5"));
251 menuType
->Check(ID_BOOK_NOTEBOOK
+ m_type
, true);
253 wxMenu
*menuOrient
= new wxMenu
;
254 menuOrient
->AppendRadioItem(ID_ORIENT_DEFAULT
, wxT("&Default\tCtrl-5"));
255 menuOrient
->AppendRadioItem(ID_ORIENT_TOP
, wxT("&Top\tCtrl-6"));
256 menuOrient
->AppendRadioItem(ID_ORIENT_BOTTOM
, wxT("&Bottom\tCtrl-7"));
257 menuOrient
->AppendRadioItem(ID_ORIENT_LEFT
, wxT("&Left\tCtrl-8"));
258 menuOrient
->AppendRadioItem(ID_ORIENT_RIGHT
, wxT("&Right\tCtrl-9"));
260 wxMenu
*menuPageOperations
= new wxMenu
;
261 menuPageOperations
->Append(ID_ADD_PAGE
, wxT("&Add page\tAlt-A"));
262 menuPageOperations
->Append(ID_ADD_PAGE_NO_SELECT
, wxT("&Add page (don't select)\tAlt-B"));
263 menuPageOperations
->Append(ID_INSERT_PAGE
, wxT("&Insert page\tAlt-I"));
264 menuPageOperations
->Append(ID_DELETE_CUR_PAGE
, wxT("&Delete current page\tAlt-D"));
265 menuPageOperations
->Append(ID_DELETE_LAST_PAGE
, wxT("D&elete last page\tAlt-L"));
266 menuPageOperations
->Append(ID_NEXT_PAGE
, wxT("&Next page\tAlt-N"));
268 menuPageOperations
->AppendSeparator();
269 menuPageOperations
->Append(ID_ADD_PAGE_BEFORE
, wxT("Insert page &before\tAlt-B"));
270 menuPageOperations
->Append(ID_ADD_SUB_PAGE
, wxT("Add s&ub page\tAlt-U"));
272 menuPageOperations
->AppendSeparator();
273 menuPageOperations
->Append(ID_GO_HOME
, wxT("Go to the first page\tCtrl-F"));
275 wxMenu
*menuOperations
= new wxMenu
;
277 menuOperations
->Append(ID_CONTEXT_HELP
, wxT("&Context help\tCtrl-F1"));
279 menuOperations
->Append(ID_HITTEST
, wxT("&Hit test\tCtrl-H"));
281 wxMenu
*menuFile
= new wxMenu
;
282 menuFile
->Append(wxID_ANY
, wxT("&Type"), menuType
, wxT("Type of control"));
283 menuFile
->Append(wxID_ANY
, wxT("&Orientation"), menuOrient
, wxT("Orientation of control"));
284 menuFile
->AppendCheckItem(ID_SHOW_IMAGES
, wxT("&Show images\tAlt-S"));
285 menuFile
->AppendCheckItem(ID_MULTI
, wxT("&Multiple lines\tAlt-M"));
286 menuFile
->AppendSeparator();
287 menuFile
->Append(wxID_EXIT
, wxT("E&xit"), wxT("Quits the application"));
288 menuFile
->Check(ID_SHOW_IMAGES
, m_chkShowImages
);
289 menuFile
->Check(ID_MULTI
, m_multi
);
291 wxMenuBar
*menuBar
= new wxMenuBar
;
292 menuBar
->Append(menuFile
, wxT("&File"));
293 menuBar
->Append(menuPageOperations
, wxT("&Pages"));
294 menuBar
->Append(menuOperations
, wxT("&Operations"));
301 // create a dummy image list with a few icons
302 const wxSize
imageSize(32, 32);
304 m_imageList
= new wxImageList(imageSize
.GetWidth(), imageSize
.GetHeight());
306 Add(wxArtProvider::GetIcon(wxART_INFORMATION
, wxART_OTHER
, imageSize
));
308 Add(wxArtProvider::GetIcon(wxART_QUESTION
, wxART_OTHER
, imageSize
));
310 Add(wxArtProvider::GetIcon(wxART_WARNING
, wxART_OTHER
, imageSize
));
312 Add(wxArtProvider::GetIcon(wxART_ERROR
, wxART_OTHER
, imageSize
));
314 m_panel
= new wxPanel(this);
317 m_text
= new wxTextCtrl(m_panel
, wxID_ANY
, wxEmptyString
,
318 wxDefaultPosition
, wxDefaultSize
,
319 wxTE_MULTILINE
| wxTE_READONLY
);
321 m_logTargetOld
= wxLog::SetActiveTarget( new wxLogTextCtrl(m_text
) );
325 m_sizerFrame
= new wxBoxSizer(wxVERTICAL
);
328 m_sizerFrame
->Add(m_text
, 1, wxEXPAND
);
333 m_panel
->SetSizer(m_sizerFrame
);
335 m_sizerFrame
->Fit(this);
336 m_sizerFrame
->SetSizeHints(this);
344 delete wxLog::SetActiveTarget(m_logTargetOld
);
350 // DISPATCH_ON_TYPE() macro is an ugly way to write the "same" code for
351 // different wxBookCtrlBase-derived classes without duplicating code and
352 // without using templates, it expands into "before <xxx> after" where "xxx"
353 // part is control class-specific
355 #define CASE_NOTEBOOK(x) case Type_Notebook: x; break;
357 #define CASE_NOTEBOOK(x)
361 #define CASE_LISTBOOK(x) case Type_Listbook: x; break;
363 #define CASE_LISTBOOK(x)
367 #define CASE_CHOICEBOOK(x) case Type_Choicebook: x; break;
369 #define CASE_CHOICEBOOK(x)
373 #define CASE_TREEBOOK(x) case Type_Treebook: x; break;
375 #define CASE_TREEBOOK(x)
379 #define CASE_TOOLBOOK(x) case Type_Toolbook: x; break;
381 #define CASE_TOOLBOOK(x)
384 #define DISPATCH_ON_TYPE(before, nb, lb, cb, tb, toolb, after) \
387 CASE_NOTEBOOK(before nb after) \
388 CASE_LISTBOOK(before lb after) \
389 CASE_CHOICEBOOK(before cb after) \
390 CASE_TREEBOOK(before tb after) \
391 CASE_TOOLBOOK(before toolb after) \
394 wxFAIL_MSG( _T("unknown book control type") ); \
397 int MyFrame::TranslateBookFlag(int nb
, int lb
, int chb
, int tbk
, int toolbk
) const
401 DISPATCH_ON_TYPE(flag
=, nb
, lb
, chb
, tbk
, toolbk
, + 0);
406 void MyFrame::RecreateBook()
415 case ID_ORIENT_BOTTOM
:
423 case ID_ORIENT_RIGHT
:
428 flags
= wxBK_DEFAULT
;
431 if ( m_multi
&& m_type
== Type_Notebook
)
432 flags
|= wxNB_MULTILINE
;
433 flags
|= wxDOUBLE_BORDER
;
435 wxBookCtrlBase
*oldBook
= m_bookCtrl
;
439 DISPATCH_ON_TYPE(m_bookCtrl
= new,
445 (m_panel
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, flags
));
452 if ( m_chkShowImages
)
454 m_bookCtrl
->SetImageList(m_imageList
);
460 // we only need the old treebook if we're recreating another treebook
461 wxTreebook
*tbkOld
= m_type
== Type_Treebook
462 ? wxDynamicCast(oldBook
, wxTreebook
)
464 #endif // wxUSE_TREEBOOK
466 const int count
= oldBook
->GetPageCount();
467 for ( int n
= 0; n
< count
; n
++ )
469 const int image
= GetIconIndex(m_bookCtrl
);
470 const wxString str
= oldBook
->GetPageText(n
);
472 wxWindow
*page
= CreatePage(m_bookCtrl
, str
);
474 // treebook complication: need to account for possible parent page
478 const int parent
= tbkOld
->GetPageParent(n
);
479 if ( parent
!= wxNOT_FOUND
)
481 wxStaticCast(m_bookCtrl
, wxTreebook
)->
482 InsertSubPage(parent
, page
, str
, false, image
);
484 // skip adding it again below
488 #endif // wxUSE_TREEBOOK
490 m_bookCtrl
->AddPage(page
, str
, false, image
);
493 const int sel
= oldBook
->GetSelection();
494 if ( sel
!= wxNOT_FOUND
)
495 m_bookCtrl
->SetSelection(sel
);
498 m_sizerFrame
->Detach(oldBook
);
503 CreateInitialPages(m_bookCtrl
);
506 m_sizerFrame
->Insert(0, m_bookCtrl
, wxSizerFlags(5).Expand().Border());
508 m_sizerFrame
->Show(m_bookCtrl
);
509 m_sizerFrame
->Layout();
512 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
514 EVT_MENU_RANGE(ID_BOOK_NOTEBOOK
, ID_BOOK_MAX
, MyFrame::OnType
)
515 EVT_MENU_RANGE(ID_ORIENT_DEFAULT
, ID_ORIENT_MAX
, MyFrame::OnOrient
)
516 EVT_MENU(ID_SHOW_IMAGES
, MyFrame::OnShowImages
)
517 EVT_MENU(ID_MULTI
, MyFrame::OnMulti
)
518 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
521 EVT_MENU(ID_ADD_PAGE
, MyFrame::OnAddPage
)
522 EVT_MENU(ID_ADD_PAGE_NO_SELECT
, MyFrame::OnAddPageNoSelect
)
523 EVT_MENU(ID_INSERT_PAGE
, MyFrame::OnInsertPage
)
524 EVT_MENU(ID_DELETE_CUR_PAGE
, MyFrame::OnDeleteCurPage
)
525 EVT_MENU(ID_DELETE_LAST_PAGE
, MyFrame::OnDeleteLastPage
)
526 EVT_MENU(ID_NEXT_PAGE
, MyFrame::OnNextPage
)
527 EVT_MENU(ID_GO_HOME
, MyFrame::OnGoHome
)
530 EVT_MENU(ID_CONTEXT_HELP
, MyFrame::OnContextHelp
)
532 EVT_MENU(ID_HITTEST
, MyFrame::OnHitTest
)
536 EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY
, MyFrame::OnNotebook
)
537 EVT_NOTEBOOK_PAGE_CHANGING(wxID_ANY
, MyFrame::OnNotebook
)
540 EVT_LISTBOOK_PAGE_CHANGED(wxID_ANY
, MyFrame::OnListbook
)
541 EVT_LISTBOOK_PAGE_CHANGING(wxID_ANY
, MyFrame::OnListbook
)
544 EVT_CHOICEBOOK_PAGE_CHANGED(wxID_ANY
, MyFrame::OnChoicebook
)
545 EVT_CHOICEBOOK_PAGE_CHANGING(wxID_ANY
, MyFrame::OnChoicebook
)
548 EVT_TREEBOOK_PAGE_CHANGED(wxID_ANY
, MyFrame::OnTreebook
)
549 EVT_TREEBOOK_PAGE_CHANGING(wxID_ANY
, MyFrame::OnTreebook
)
551 EVT_MENU(ID_ADD_SUB_PAGE
, MyFrame::OnAddSubPage
)
552 EVT_MENU(ID_ADD_PAGE_BEFORE
, MyFrame::OnAddPageBefore
)
553 EVT_UPDATE_UI_RANGE(ID_ADD_PAGE_BEFORE
, ID_ADD_SUB_PAGE
,
554 MyFrame::OnUpdateTreeMenu
)
557 EVT_TOOLBOOK_PAGE_CHANGED(wxID_ANY
, MyFrame::OnToolbook
)
558 EVT_TOOLBOOK_PAGE_CHANGING(wxID_ANY
, MyFrame::OnToolbook
)
561 // Update title in idle time
562 EVT_IDLE(MyFrame::OnIdle
)
567 void MyFrame::OnContextHelp(wxCommandEvent
& WXUNUSED(event
))
569 // launches local event loop
570 wxContextHelp
ch( this );
575 void MyFrame::AddFlagStrIfFlagPresent(wxString
& flagStr
, long flags
, long flag
, const wxChar
* flagName
) const
577 if( (flags
& flag
) == flag
)
579 if( !flagStr
.empty() )
580 flagStr
+= _T(" | ");
585 void MyFrame::OnHitTest(wxCommandEvent
& WXUNUSED(event
))
587 wxBookCtrlBase
* book
= GetCurrentBook();
588 const wxPoint pt
= ::wxGetMousePosition();
591 int pagePos
= book
->HitTest( book
->ScreenToClient(pt
), &flags
);
595 AddFlagStrIfFlagPresent( flagsStr
, flags
, wxBK_HITTEST_NOWHERE
, _T("wxBK_HITTEST_NOWHERE") );
596 AddFlagStrIfFlagPresent( flagsStr
, flags
, wxBK_HITTEST_ONICON
, _T("wxBK_HITTEST_ONICON") );
597 AddFlagStrIfFlagPresent( flagsStr
, flags
, wxBK_HITTEST_ONLABEL
, _T("wxBK_HITTEST_ONLABEL") );
598 AddFlagStrIfFlagPresent( flagsStr
, flags
, wxBK_HITTEST_ONPAGE
, _T("wxBK_HITTEST_ONPAGE") );
600 wxLogMessage(wxT("HitTest at (%d,%d): %d: %s"),
607 void MyFrame::OnType(wxCommandEvent
& event
)
609 m_type
= wx_static_cast(BookType
, event
.GetId() - ID_BOOK_NOTEBOOK
);
612 m_sizerFrame
->Hide(m_bookCtrl
);
619 void MyFrame::OnUpdateTreeMenu(wxUpdateUIEvent
& event
)
621 event
.Enable(m_type
== Type_Treebook
);
624 #endif // wxUSE_TREEBOOK
627 void MyFrame::OnOrient(wxCommandEvent
& event
)
629 m_orient
= event
.GetId();
631 m_sizerFrame
->Layout();
634 void MyFrame::OnShowImages(wxCommandEvent
& event
)
636 m_chkShowImages
= event
.IsChecked();
638 m_sizerFrame
->Layout();
641 void MyFrame::OnMulti(wxCommandEvent
& event
)
643 m_multi
= event
.IsChecked();
645 m_sizerFrame
->Layout();
646 wxLogMessage(_T("Multiline setting works only in wxNotebook."));
649 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
654 wxPanel
*MyFrame::CreateNewPage() const
656 wxPanel
*panel
= new wxPanel(m_bookCtrl
, wxID_ANY
);
659 panel
->SetHelpText( wxT( "Panel with \"First\" and \"Second\" buttons" ) );
662 (void) new wxButton(panel
, wxID_ANY
, wxT("First button"), wxPoint(10, 10));
663 (void) new wxButton(panel
, wxID_ANY
, wxT("Second button"), wxPoint(50, 100));
668 void MyFrame::OnAddPage(wxCommandEvent
& WXUNUSED(event
))
670 wxBookCtrlBase
*currBook
= GetCurrentBook();
674 static unsigned s_pageAdded
= 0;
675 currBook
->AddPage(CreateNewPage(),
678 ADDED_PAGE_NAME
wxT("%u"),
682 GetIconIndex(currBook
));
686 void MyFrame::OnAddPageNoSelect(wxCommandEvent
& WXUNUSED(event
))
688 wxBookCtrlBase
*currBook
= GetCurrentBook();
692 static unsigned s_pageAdded
= 0;
693 currBook
->AddPage(CreateNewPage(),
696 ADDED_PAGE_NAME
wxT("%u"),
700 GetIconIndex(currBook
));
705 void MyFrame::OnAddSubPage(wxCommandEvent
& WXUNUSED(event
))
707 wxTreebook
*currBook
= wxDynamicCast(GetCurrentBook(), wxTreebook
);
710 const int selPos
= currBook
->GetSelection();
711 if ( selPos
== wxNOT_FOUND
)
713 wxLogError(_T("Select the parent page first!"));
717 static unsigned s_subPageAdded
= 0;
718 currBook
->InsertSubPage
724 ADDED_SUB_PAGE_NAME
wxT("%u"),
728 GetIconIndex(currBook
)
733 void MyFrame::OnAddPageBefore(wxCommandEvent
& WXUNUSED(event
))
735 wxBookCtrlBase
*currBook
= GetCurrentBook();
738 const int selPos
= currBook
->GetSelection();
739 if ( selPos
== wxNOT_FOUND
)
741 wxLogError(_T("Select the parent page first!"));
745 static unsigned s_subPageAdded
= 0;
746 currBook
->InsertPage(selPos
,
750 ADDED_PAGE_NAME_BEFORE
wxT("%u"),
754 GetIconIndex(currBook
));
757 #endif // wxUSE_TREEBOOK
759 void MyFrame::OnInsertPage(wxCommandEvent
& WXUNUSED(event
))
761 static unsigned s_pageIns
= 0;
763 wxBookCtrlBase
*currBook
= GetCurrentBook();
767 wxPanel
*panel
= CreateUserCreatedPage( currBook
);
769 currBook
->InsertPage( 0, panel
,
770 wxString::Format(INSERTED_PAGE_NAME
wxT("%u"), ++s_pageIns
), false,
771 GetIconIndex(currBook
) );
773 currBook
->SetSelection(0);
777 void MyFrame::OnDeleteCurPage(wxCommandEvent
& WXUNUSED(event
))
779 wxBookCtrlBase
*currBook
= GetCurrentBook();
783 int sel
= currBook
->GetSelection();
785 if (sel
!= wxNOT_FOUND
)
787 currBook
->DeletePage(sel
);
792 void MyFrame::OnDeleteLastPage(wxCommandEvent
& WXUNUSED(event
))
794 wxBookCtrlBase
*currBook
= GetCurrentBook();
798 int page
= currBook
->GetPageCount();
802 currBook
->DeletePage(page
- 1);
807 void MyFrame::OnNextPage(wxCommandEvent
& WXUNUSED(event
))
809 wxBookCtrlBase
*currBook
= GetCurrentBook();
813 currBook
->AdvanceSelection();
817 void MyFrame::OnGoHome(wxCommandEvent
& WXUNUSED(event
))
819 wxBookCtrlBase
*currBook
= GetCurrentBook();
823 // ChangeSelection shouldn't send any events, SetSelection() should
824 currBook
->ChangeSelection(0);
825 //currBook->SetSelection(0);
829 void MyFrame::OnIdle( wxIdleEvent
& WXUNUSED(event
) )
831 static int s_nPages
= wxNOT_FOUND
;
832 static int s_nSel
= wxNOT_FOUND
;
833 static wxBookCtrlBase
*s_currBook
= NULL
;
835 wxBookCtrlBase
*currBook
= GetCurrentBook();
837 int nPages
= currBook
? currBook
->GetPageCount() : 0;
838 int nSel
= currBook
? currBook
->GetSelection() : wxNOT_FOUND
;
840 if ( nPages
!= s_nPages
|| nSel
!= s_nSel
|| s_currBook
!= currBook
)
844 s_currBook
= currBook
;
847 if ( nSel
== wxNOT_FOUND
)
848 selection
<< wxT("not found");
853 title
.Printf(wxT("Notebook and friends (%d pages, selection: %s)"), nPages
, selection
.c_str());
859 void MyFrame::OnBookCtrl(wxBookCtrlBaseEvent
& event
)
861 static const struct EventInfo
863 wxEventType typeChanged
,
870 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
,
871 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
,
874 #endif // wxUSE_NOTEBOOK
877 wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED
,
878 wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING
,
881 #endif // wxUSE_LISTBOOK
884 wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED
,
885 wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING
,
888 #endif // wxUSE_CHOICEBOOK
891 wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED
,
892 wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING
,
895 #endif // wxUSE_TREEBOOK
898 wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGED
,
899 wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGING
,
902 #endif // wxUSE_TOOLBOOK
909 const wxEventType eventType
= event
.GetEventType();
910 for ( size_t n
= 0; n
< WXSIZEOF(events
); n
++ )
912 const EventInfo
& ei
= events
[n
];
913 if ( eventType
== ei
.typeChanged
)
915 nameEvent
= wxT("Changed");
917 else if ( eventType
== ei
.typeChanging
)
919 const int idx
= event
.GetOldSelection();
921 // NB: can't use wxStaticCast here as wxBookCtrlBase is not in
923 const wxBookCtrlBase
* const
924 book
= wx_static_cast(wxBookCtrlBase
*, event
.GetEventObject());
925 if ( idx
!= wxNOT_FOUND
&&
926 book
&& book
->GetPageText(idx
) == VETO_PAGE_NAME
)
930 wxT("Are you sure you want to leave this page?\n")
931 wxT("(This demonstrates veto-ing)"),
932 wxT("Notebook sample"),
933 wxICON_QUESTION
| wxYES_NO
,
938 veto
= _T(" (vetoed)");
942 nameEvent
= wxT("Changing");
944 else // skip end of the loop
949 nameControl
= ei
.name
;
953 static int s_num
= 0;
955 wxLogMessage(wxT("Event #%d: %s: %s (%d) new sel %d, old %d%s"),
960 event
.GetSelection(),
961 event
.GetOldSelection(),
965 m_text
->SetInsertionPointEnd();