notebook.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Program: wxWidgets Widgets Sample
  3. // Name: notebook.cpp
  4. // Purpose: Part of the widgets sample showing book controls
  5. // Author: Vadim Zeitlin, Wlodzimierz ABX Skiba
  6. // Created: 06.04.01
  7. // Copyright: (c) 2001 Vadim Zeitlin, 2006 Wlodzimierz Skiba
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. // ============================================================================
  11. // declarations
  12. // ============================================================================
  13. // ----------------------------------------------------------------------------
  14. // headers
  15. // ----------------------------------------------------------------------------
  16. // for compilers that support precompilation, includes "wx/wx.h".
  17. #include "wx/wxprec.h"
  18. #ifdef __BORLANDC__
  19. #pragma hdrstop
  20. #endif
  21. #if wxUSE_BOOKCTRL
  22. // for all others, include the necessary headers
  23. #ifndef WX_PRECOMP
  24. #include "wx/app.h"
  25. #include "wx/log.h"
  26. #include "wx/button.h"
  27. #include "wx/checkbox.h"
  28. #include "wx/combobox.h"
  29. #include "wx/radiobox.h"
  30. #include "wx/statbox.h"
  31. #include "wx/textctrl.h"
  32. #include "wx/dynarray.h"
  33. #endif
  34. #include "wx/sizer.h"
  35. #include "wx/bookctrl.h"
  36. #include "wx/artprov.h"
  37. #include "wx/imaglist.h"
  38. #include "widgets.h"
  39. // ----------------------------------------------------------------------------
  40. // constants
  41. // ----------------------------------------------------------------------------
  42. // control ids
  43. enum
  44. {
  45. BookPage_Reset = wxID_HIGHEST,
  46. BookPage_SelectPage,
  47. BookPage_AddPage,
  48. BookPage_InsertPage,
  49. BookPage_RemovePage,
  50. BookPage_DeleteAll,
  51. BookPage_InsertText,
  52. BookPage_RemoveText,
  53. BookPage_SelectText,
  54. BookPage_NumPagesText,
  55. BookPage_CurSelectText,
  56. BookPage_Book
  57. };
  58. // book orientations
  59. enum Orient
  60. {
  61. Orient_Top,
  62. Orient_Bottom,
  63. Orient_Left,
  64. Orient_Right,
  65. Orient_Max
  66. };
  67. // ----------------------------------------------------------------------------
  68. // BookWidgetsPage
  69. // ----------------------------------------------------------------------------
  70. class BookWidgetsPage : public WidgetsPage
  71. {
  72. public:
  73. BookWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist, const char *const icon[]);
  74. virtual ~BookWidgetsPage();
  75. virtual wxControl *GetWidget() const { return m_book; }
  76. virtual void RecreateWidget() { RecreateBook(); }
  77. // lazy creation of the content
  78. virtual void CreateContent();
  79. protected:
  80. // event handlers
  81. void OnButtonReset(wxCommandEvent& event);
  82. void OnButtonDeleteAll(wxCommandEvent& event);
  83. void OnButtonSelectPage(wxCommandEvent& event);
  84. void OnButtonAddPage(wxCommandEvent& event);
  85. void OnButtonInsertPage(wxCommandEvent& event);
  86. void OnButtonRemovePage(wxCommandEvent& event);
  87. void OnCheckOrRadioBox(wxCommandEvent& event);
  88. void OnUpdateUINumPagesText(wxUpdateUIEvent& event);
  89. void OnUpdateUICurSelectText(wxUpdateUIEvent& event);
  90. void OnUpdateUISelectButton(wxUpdateUIEvent& event);
  91. void OnUpdateUIInsertButton(wxUpdateUIEvent& event);
  92. void OnUpdateUIRemoveButton(wxUpdateUIEvent& event);
  93. void OnUpdateUIResetButton(wxUpdateUIEvent& event);
  94. // reset book parameters
  95. void Reset();
  96. // (re)create book
  97. void RecreateBook();
  98. virtual wxBookCtrlBase *CreateBook(long flags) = 0;
  99. #if USE_ICONS_IN_BOOK
  100. // create or destroy the image list
  101. void CreateImageList();
  102. #endif // USE_ICONS_IN_BOOK
  103. // create a new page
  104. wxWindow *CreateNewPage();
  105. // get the image index for the new page
  106. int GetIconIndex() const;
  107. // get the numeric value of text ctrl
  108. int GetTextValue(wxTextCtrl *text) const;
  109. // is the value in range?
  110. bool IsValidValue(int val) const
  111. { return (val >= 0) && (val < (int) m_book->GetPageCount()); }
  112. // the controls
  113. // ------------
  114. // the check/radio boxes for styles
  115. wxCheckBox *m_chkImages;
  116. wxRadioBox *m_radioOrient;
  117. // the text controls containing input for various commands
  118. wxTextCtrl *m_textInsert,
  119. *m_textRemove,
  120. *m_textSelect;
  121. // the book itself and the sizer it is in
  122. wxBookCtrlBase *m_book;
  123. wxSizer *m_sizerBook;
  124. #if USE_ICONS_IN_BOOK
  125. // the image list for our book
  126. wxImageList *m_imageList;
  127. #endif // USE_ICONS_IN_BOOK
  128. private:
  129. wxDECLARE_EVENT_TABLE();
  130. };
  131. // ----------------------------------------------------------------------------
  132. // event tables
  133. // ----------------------------------------------------------------------------
  134. wxBEGIN_EVENT_TABLE(BookWidgetsPage, WidgetsPage)
  135. EVT_BUTTON(BookPage_Reset, BookWidgetsPage::OnButtonReset)
  136. EVT_BUTTON(BookPage_SelectPage, BookWidgetsPage::OnButtonSelectPage)
  137. EVT_BUTTON(BookPage_AddPage, BookWidgetsPage::OnButtonAddPage)
  138. EVT_BUTTON(BookPage_InsertPage, BookWidgetsPage::OnButtonInsertPage)
  139. EVT_BUTTON(BookPage_RemovePage, BookWidgetsPage::OnButtonRemovePage)
  140. EVT_BUTTON(BookPage_DeleteAll, BookWidgetsPage::OnButtonDeleteAll)
  141. EVT_UPDATE_UI(BookPage_NumPagesText, BookWidgetsPage::OnUpdateUINumPagesText)
  142. EVT_UPDATE_UI(BookPage_CurSelectText, BookWidgetsPage::OnUpdateUICurSelectText)
  143. EVT_UPDATE_UI(BookPage_SelectPage, BookWidgetsPage::OnUpdateUISelectButton)
  144. EVT_UPDATE_UI(BookPage_InsertPage, BookWidgetsPage::OnUpdateUIInsertButton)
  145. EVT_UPDATE_UI(BookPage_RemovePage, BookWidgetsPage::OnUpdateUIRemoveButton)
  146. EVT_CHECKBOX(wxID_ANY, BookWidgetsPage::OnCheckOrRadioBox)
  147. EVT_RADIOBOX(wxID_ANY, BookWidgetsPage::OnCheckOrRadioBox)
  148. wxEND_EVENT_TABLE()
  149. // ============================================================================
  150. // implementation
  151. // ============================================================================
  152. BookWidgetsPage::BookWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist, const char *const icon[])
  153. :WidgetsPage(book, imaglist, icon)
  154. {
  155. // init everything
  156. m_chkImages = NULL;
  157. #if USE_ICONS_IN_BOOK
  158. m_imageList = NULL;
  159. #endif // USE_ICONS_IN_BOOK
  160. m_book = NULL;
  161. m_radioOrient = NULL;
  162. m_sizerBook = (wxSizer *)NULL;
  163. }
  164. void BookWidgetsPage::CreateContent()
  165. {
  166. wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
  167. // left pane
  168. wxStaticBox *box = new wxStaticBox(this, wxID_ANY, wxT("&Set style"));
  169. // must be in sync with Orient enum
  170. wxArrayString orientations;
  171. orientations.Add(wxT("&top"));
  172. orientations.Add(wxT("&bottom"));
  173. orientations.Add(wxT("&left"));
  174. orientations.Add(wxT("&right"));
  175. wxASSERT_MSG( orientations.GetCount() == Orient_Max,
  176. wxT("forgot to update something") );
  177. m_chkImages = new wxCheckBox(this, wxID_ANY, wxT("Show &images"));
  178. m_radioOrient = new wxRadioBox(this, wxID_ANY, wxT("&Tab orientation"),
  179. wxDefaultPosition, wxDefaultSize,
  180. orientations, 1, wxRA_SPECIFY_COLS);
  181. wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
  182. sizerLeft->Add(m_chkImages, 0, wxALL, 5);
  183. sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
  184. sizerLeft->Add(m_radioOrient, 0, wxALL, 5);
  185. wxButton *btn = new wxButton(this, BookPage_Reset, wxT("&Reset"));
  186. sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
  187. // middle pane
  188. wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY, wxT("&Contents"));
  189. wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL);
  190. wxTextCtrl *text;
  191. wxSizer *sizerRow = CreateSizerWithTextAndLabel(wxT("Number of pages: "),
  192. BookPage_NumPagesText,
  193. &text);
  194. text->SetEditable(false);
  195. sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
  196. sizerRow = CreateSizerWithTextAndLabel(wxT("Current selection: "),
  197. BookPage_CurSelectText,
  198. &text);
  199. text->SetEditable(false);
  200. sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
  201. sizerRow = CreateSizerWithTextAndButton(BookPage_SelectPage,
  202. wxT("&Select page"),
  203. BookPage_SelectText,
  204. &m_textSelect);
  205. sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
  206. btn = new wxButton(this, BookPage_AddPage, wxT("&Add page"));
  207. sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
  208. sizerRow = CreateSizerWithTextAndButton(BookPage_InsertPage,
  209. wxT("&Insert page at"),
  210. BookPage_InsertText,
  211. &m_textInsert);
  212. sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
  213. sizerRow = CreateSizerWithTextAndButton(BookPage_RemovePage,
  214. wxT("&Remove page"),
  215. BookPage_RemoveText,
  216. &m_textRemove);
  217. sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
  218. btn = new wxButton(this, BookPage_DeleteAll, wxT("&Delete All"));
  219. sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5);
  220. // right pane
  221. m_sizerBook = new wxBoxSizer(wxHORIZONTAL);
  222. // the 3 panes compose the window
  223. sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10);
  224. sizerTop->Add(sizerMiddle, 0, wxGROW | wxALL, 10);
  225. sizerTop->Add(m_sizerBook, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
  226. RecreateBook();
  227. // final initializations
  228. Reset();
  229. #if USE_ICONS_IN_BOOK
  230. CreateImageList();
  231. #endif // USE_ICONS_IN_BOOK
  232. SetSizer(sizerTop);
  233. }
  234. BookWidgetsPage::~BookWidgetsPage()
  235. {
  236. #if USE_ICONS_IN_BOOK
  237. delete m_imageList;
  238. #endif // USE_ICONS_IN_BOOK
  239. }
  240. // ----------------------------------------------------------------------------
  241. // operations
  242. // ----------------------------------------------------------------------------
  243. void BookWidgetsPage::Reset()
  244. {
  245. m_chkImages->SetValue(true);
  246. m_radioOrient->SetSelection(Orient_Top);
  247. }
  248. #if USE_ICONS_IN_BOOK
  249. void BookWidgetsPage::CreateImageList()
  250. {
  251. if ( m_chkImages->GetValue() )
  252. {
  253. if ( !m_imageList )
  254. {
  255. // create a dummy image list with a few icons
  256. m_imageList = new wxImageList(32, 32);
  257. wxSize size(32, 32);
  258. m_imageList->Add(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, size));
  259. m_imageList->Add(wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, size));
  260. m_imageList->Add(wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, size));
  261. m_imageList->Add(wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, size));
  262. }
  263. if ( m_book )
  264. m_book->SetImageList(m_imageList);
  265. }
  266. else // no images
  267. {
  268. wxDELETE(m_imageList);
  269. }
  270. // because of the bug in wxMSW we can't use SetImageList(NULL) - although
  271. // it would be logical if this removed the image list from book, under
  272. // MSW it crashes instead - FIXME
  273. }
  274. #endif // USE_ICONS_IN_BOOK
  275. void BookWidgetsPage::RecreateBook()
  276. {
  277. // do not recreate anything in case page content was not prepared yet
  278. if(!m_radioOrient)
  279. return;
  280. int flags = ms_defaultFlags;
  281. switch ( m_radioOrient->GetSelection() )
  282. {
  283. default:
  284. wxFAIL_MSG( wxT("unknown orientation") );
  285. // fall through
  286. case Orient_Top:
  287. flags |= wxBK_TOP;
  288. break;
  289. case Orient_Bottom:
  290. flags |= wxBK_BOTTOM;
  291. break;
  292. case Orient_Left:
  293. flags |= wxBK_LEFT;
  294. break;
  295. case Orient_Right:
  296. flags |= wxBK_RIGHT;
  297. break;
  298. }
  299. wxBookCtrlBase *oldBook = m_book;
  300. m_book = CreateBook(flags);
  301. #if USE_ICONS_IN_BOOK
  302. CreateImageList();
  303. #endif // USE_ICONS_IN_BOOK
  304. if ( oldBook )
  305. {
  306. const int sel = oldBook->GetSelection();
  307. const int count = oldBook->GetPageCount();
  308. // recreate the pages
  309. for ( int n = 0; n < count; n++ )
  310. {
  311. m_book->AddPage(CreateNewPage(),
  312. oldBook->GetPageText(n),
  313. false,
  314. m_chkImages->GetValue() ?
  315. GetIconIndex() : -1);
  316. }
  317. m_sizerBook->Detach( oldBook );
  318. delete oldBook;
  319. // restore selection
  320. if ( sel != -1 )
  321. {
  322. m_book->SetSelection(sel);
  323. }
  324. }
  325. m_sizerBook->Add(m_book, 1, wxGROW | wxALL, 5);
  326. m_sizerBook->SetMinSize(150, 0);
  327. m_sizerBook->Layout();
  328. }
  329. // ----------------------------------------------------------------------------
  330. // helpers
  331. // ----------------------------------------------------------------------------
  332. int BookWidgetsPage::GetTextValue(wxTextCtrl *text) const
  333. {
  334. long pos = -1;
  335. if ( !text || !text->GetValue().ToLong(&pos) )
  336. pos = -1;
  337. return (int)pos;
  338. }
  339. int BookWidgetsPage::GetIconIndex() const
  340. {
  341. #if USE_ICONS_IN_BOOK
  342. if ( m_imageList )
  343. {
  344. int nImages = m_imageList->GetImageCount();
  345. if ( nImages > 0 )
  346. {
  347. return m_book->GetPageCount() % nImages;
  348. }
  349. }
  350. #endif // USE_ICONS_IN_BOOK
  351. return -1;
  352. }
  353. wxWindow *BookWidgetsPage::CreateNewPage()
  354. {
  355. return new wxTextCtrl(m_book, wxID_ANY, wxT("I'm a book page"));
  356. }
  357. // ----------------------------------------------------------------------------
  358. // event handlers
  359. // ----------------------------------------------------------------------------
  360. void BookWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
  361. {
  362. Reset();
  363. RecreateBook();
  364. }
  365. void BookWidgetsPage::OnButtonDeleteAll(wxCommandEvent& WXUNUSED(event))
  366. {
  367. m_book->DeleteAllPages();
  368. }
  369. void BookWidgetsPage::OnButtonSelectPage(wxCommandEvent& WXUNUSED(event))
  370. {
  371. int pos = GetTextValue(m_textSelect);
  372. wxCHECK_RET( IsValidValue(pos), wxT("button should be disabled") );
  373. m_book->SetSelection(pos);
  374. }
  375. void BookWidgetsPage::OnButtonAddPage(wxCommandEvent& WXUNUSED(event))
  376. {
  377. m_book->AddPage(CreateNewPage(), wxT("Added page"), false,
  378. GetIconIndex());
  379. }
  380. void BookWidgetsPage::OnButtonInsertPage(wxCommandEvent& WXUNUSED(event))
  381. {
  382. int pos = GetTextValue(m_textInsert);
  383. wxCHECK_RET( IsValidValue(pos), wxT("button should be disabled") );
  384. m_book->InsertPage(pos, CreateNewPage(), wxT("Inserted page"), false,
  385. GetIconIndex());
  386. }
  387. void BookWidgetsPage::OnButtonRemovePage(wxCommandEvent& WXUNUSED(event))
  388. {
  389. int pos = GetTextValue(m_textRemove);
  390. wxCHECK_RET( IsValidValue(pos), wxT("button should be disabled") );
  391. m_book->DeletePage(pos);
  392. }
  393. void BookWidgetsPage::OnUpdateUISelectButton(wxUpdateUIEvent& event)
  394. {
  395. event.Enable( IsValidValue(GetTextValue(m_textSelect)) );
  396. }
  397. void BookWidgetsPage::OnUpdateUIInsertButton(wxUpdateUIEvent& event)
  398. {
  399. event.Enable( IsValidValue(GetTextValue(m_textInsert)) );
  400. }
  401. void BookWidgetsPage::OnUpdateUIRemoveButton(wxUpdateUIEvent& event)
  402. {
  403. event.Enable( IsValidValue(GetTextValue(m_textRemove)) );
  404. }
  405. void BookWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event)
  406. {
  407. if(m_chkImages && m_radioOrient)
  408. event.Enable( !m_chkImages->GetValue() ||
  409. m_radioOrient->GetSelection() != wxBK_TOP );
  410. }
  411. void BookWidgetsPage::OnUpdateUINumPagesText(wxUpdateUIEvent& event)
  412. {
  413. if(m_book)
  414. event.SetText( wxString::Format(wxT("%u"), unsigned(m_book->GetPageCount())) );
  415. }
  416. void BookWidgetsPage::OnUpdateUICurSelectText(wxUpdateUIEvent& event)
  417. {
  418. if(m_book)
  419. event.SetText( wxString::Format(wxT("%d"), m_book->GetSelection()) );
  420. }
  421. void BookWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
  422. {
  423. RecreateBook();
  424. }
  425. #if wxUSE_NOTEBOOK
  426. #include "icons/notebook.xpm"
  427. #include "wx/notebook.h"
  428. // ----------------------------------------------------------------------------
  429. // NotebookWidgetsPage
  430. // ----------------------------------------------------------------------------
  431. class NotebookWidgetsPage : public BookWidgetsPage
  432. {
  433. public:
  434. NotebookWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist)
  435. : BookWidgetsPage(book, imaglist, notebook_xpm)
  436. {
  437. RecreateBook();
  438. }
  439. virtual ~NotebookWidgetsPage() {}
  440. protected:
  441. // event handlers
  442. void OnPageChanging(wxNotebookEvent& event);
  443. void OnPageChanged(wxNotebookEvent& event);
  444. // (re)create book
  445. virtual wxBookCtrlBase *CreateBook(long flags)
  446. {
  447. return new wxNotebook(this, BookPage_Book,
  448. wxDefaultPosition, wxDefaultSize,
  449. flags);
  450. }
  451. private:
  452. wxDECLARE_EVENT_TABLE();
  453. DECLARE_WIDGETS_PAGE(NotebookWidgetsPage)
  454. };
  455. // ----------------------------------------------------------------------------
  456. // event table
  457. // ----------------------------------------------------------------------------
  458. wxBEGIN_EVENT_TABLE(NotebookWidgetsPage, BookWidgetsPage)
  459. EVT_NOTEBOOK_PAGE_CHANGING(wxID_ANY, NotebookWidgetsPage::OnPageChanging)
  460. EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, NotebookWidgetsPage::OnPageChanged)
  461. wxEND_EVENT_TABLE()
  462. #if defined(__WXUNIVERSAL__)
  463. #define FAMILY_CTRLS UNIVERSAL_CTRLS
  464. #elif defined(__WXMOTIF__)
  465. #define FAMILY_CTRLS GENERIC_CTRLS
  466. #else
  467. #define FAMILY_CTRLS NATIVE_CTRLS
  468. #endif
  469. IMPLEMENT_WIDGETS_PAGE(NotebookWidgetsPage, wxT("Notebook"),
  470. FAMILY_CTRLS | BOOK_CTRLS
  471. );
  472. void NotebookWidgetsPage::OnPageChanging(wxNotebookEvent& event)
  473. {
  474. wxLogMessage(wxT("Notebook page changing from %d to %d (currently %d)."),
  475. event.GetOldSelection(),
  476. event.GetSelection(),
  477. m_book->GetSelection());
  478. event.Skip();
  479. }
  480. void NotebookWidgetsPage::OnPageChanged(wxNotebookEvent& event)
  481. {
  482. wxLogMessage(wxT("Notebook page changed from %d to %d (currently %d)."),
  483. event.GetOldSelection(),
  484. event.GetSelection(),
  485. m_book->GetSelection());
  486. event.Skip();
  487. }
  488. #endif // wxUSE_NOTEBOOK
  489. #if wxUSE_LISTBOOK
  490. #include "icons/listbook.xpm"
  491. #include "wx/listbook.h"
  492. // ----------------------------------------------------------------------------
  493. // ListbookWidgetsPage
  494. // ----------------------------------------------------------------------------
  495. class ListbookWidgetsPage : public BookWidgetsPage
  496. {
  497. public:
  498. ListbookWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist)
  499. : BookWidgetsPage(book, imaglist, listbook_xpm)
  500. {
  501. RecreateBook();
  502. }
  503. virtual ~ListbookWidgetsPage() {}
  504. protected:
  505. // event handlers
  506. void OnPageChanging(wxListbookEvent& event);
  507. void OnPageChanged(wxListbookEvent& event);
  508. // (re)create book
  509. virtual wxBookCtrlBase *CreateBook(long flags)
  510. {
  511. return new wxListbook(this, BookPage_Book,
  512. wxDefaultPosition, wxDefaultSize,
  513. flags);
  514. }
  515. private:
  516. wxDECLARE_EVENT_TABLE();
  517. DECLARE_WIDGETS_PAGE(ListbookWidgetsPage)
  518. };
  519. // ----------------------------------------------------------------------------
  520. // event table
  521. // ----------------------------------------------------------------------------
  522. wxBEGIN_EVENT_TABLE(ListbookWidgetsPage, BookWidgetsPage)
  523. EVT_LISTBOOK_PAGE_CHANGING(wxID_ANY, ListbookWidgetsPage::OnPageChanging)
  524. EVT_LISTBOOK_PAGE_CHANGED(wxID_ANY, ListbookWidgetsPage::OnPageChanged)
  525. wxEND_EVENT_TABLE()
  526. IMPLEMENT_WIDGETS_PAGE(ListbookWidgetsPage, wxT("Listbook"),
  527. GENERIC_CTRLS | BOOK_CTRLS
  528. );
  529. void ListbookWidgetsPage::OnPageChanging(wxListbookEvent& event)
  530. {
  531. wxLogMessage(wxT("Listbook page changing from %d to %d (currently %d)."),
  532. event.GetOldSelection(),
  533. event.GetSelection(),
  534. m_book->GetSelection());
  535. event.Skip();
  536. }
  537. void ListbookWidgetsPage::OnPageChanged(wxListbookEvent& event)
  538. {
  539. wxLogMessage(wxT("Listbook page changed from %d to %d (currently %d)."),
  540. event.GetOldSelection(),
  541. event.GetSelection(),
  542. m_book->GetSelection());
  543. event.Skip();
  544. }
  545. #endif // wxUSE_LISTBOOK
  546. #if wxUSE_CHOICEBOOK
  547. #include "icons/choicebk.xpm"
  548. #include "wx/choicebk.h"
  549. // ----------------------------------------------------------------------------
  550. // ChoicebookWidgetsPage
  551. // ----------------------------------------------------------------------------
  552. class ChoicebookWidgetsPage : public BookWidgetsPage
  553. {
  554. public:
  555. ChoicebookWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist)
  556. : BookWidgetsPage(book, imaglist, choicebk_xpm)
  557. {
  558. RecreateBook();
  559. }
  560. virtual ~ChoicebookWidgetsPage() {}
  561. protected:
  562. // event handlers
  563. void OnPageChanging(wxChoicebookEvent& event);
  564. void OnPageChanged(wxChoicebookEvent& event);
  565. // (re)create book
  566. virtual wxBookCtrlBase *CreateBook(long flags)
  567. {
  568. return new wxChoicebook(this, BookPage_Book,
  569. wxDefaultPosition, wxDefaultSize,
  570. flags);
  571. }
  572. private:
  573. wxDECLARE_EVENT_TABLE();
  574. DECLARE_WIDGETS_PAGE(ChoicebookWidgetsPage)
  575. };
  576. // ----------------------------------------------------------------------------
  577. // event table
  578. // ----------------------------------------------------------------------------
  579. wxBEGIN_EVENT_TABLE(ChoicebookWidgetsPage, BookWidgetsPage)
  580. EVT_CHOICEBOOK_PAGE_CHANGING(wxID_ANY, ChoicebookWidgetsPage::OnPageChanging)
  581. EVT_CHOICEBOOK_PAGE_CHANGED(wxID_ANY, ChoicebookWidgetsPage::OnPageChanged)
  582. wxEND_EVENT_TABLE()
  583. IMPLEMENT_WIDGETS_PAGE(ChoicebookWidgetsPage, wxT("Choicebook"),
  584. GENERIC_CTRLS | BOOK_CTRLS
  585. );
  586. void ChoicebookWidgetsPage::OnPageChanging(wxChoicebookEvent& event)
  587. {
  588. wxLogMessage(wxT("Choicebook page changing from %d to %d (currently %d)."),
  589. event.GetOldSelection(),
  590. event.GetSelection(),
  591. m_book->GetSelection());
  592. event.Skip();
  593. }
  594. void ChoicebookWidgetsPage::OnPageChanged(wxChoicebookEvent& event)
  595. {
  596. wxLogMessage(wxT("Choicebook page changed from %d to %d (currently %d)."),
  597. event.GetOldSelection(),
  598. event.GetSelection(),
  599. m_book->GetSelection());
  600. event.Skip();
  601. }
  602. #endif // wxUSE_CHOICEBOOK
  603. #endif // wxUSE_BOOKCTRL