bookctrl.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/persist/bookctrl.h
  3. // Purpose: persistence support for wxBookCtrl
  4. // Author: Vadim Zeitlin
  5. // Created: 2009-01-19
  6. // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_PERSIST_BOOKCTRL_H_
  10. #define _WX_PERSIST_BOOKCTRL_H_
  11. #include "wx/persist/window.h"
  12. #include "wx/bookctrl.h"
  13. // ----------------------------------------------------------------------------
  14. // string constants used by wxPersistentBookCtrl
  15. // ----------------------------------------------------------------------------
  16. #define wxPERSIST_BOOK_KIND "Book"
  17. #define wxPERSIST_BOOK_SELECTION "Selection"
  18. // ----------------------------------------------------------------------------
  19. // wxPersistentBookCtrl: supports saving/restoring book control selection
  20. // ----------------------------------------------------------------------------
  21. class wxPersistentBookCtrl : public wxPersistentWindow<wxBookCtrlBase>
  22. {
  23. public:
  24. wxPersistentBookCtrl(wxBookCtrlBase *book)
  25. : wxPersistentWindow<wxBookCtrlBase>(book)
  26. {
  27. }
  28. virtual void Save() const
  29. {
  30. SaveValue(wxPERSIST_BOOK_SELECTION, Get()->GetSelection());
  31. }
  32. virtual bool Restore()
  33. {
  34. long sel;
  35. if ( RestoreValue(wxPERSIST_BOOK_SELECTION, &sel) )
  36. {
  37. wxBookCtrlBase * const book = Get();
  38. if ( sel >= 0 && (unsigned)sel < book->GetPageCount() )
  39. {
  40. book->SetSelection(sel);
  41. return true;
  42. }
  43. }
  44. return false;
  45. }
  46. virtual wxString GetKind() const { return wxPERSIST_BOOK_KIND; }
  47. };
  48. inline wxPersistentObject *wxCreatePersistentObject(wxBookCtrlBase *book)
  49. {
  50. return new wxPersistentBookCtrl(book);
  51. }
  52. #endif // _WX_PERSIST_BOOKCTRL_H_