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 
10 #ifndef _WX_PERSIST_BOOKCTRL_H_
11 #define _WX_PERSIST_BOOKCTRL_H_
12 
13 #include "wx/persist/window.h"
14 
15 #if wxUSE_BOOKCTRL
16 
17 #include "wx/bookctrl.h"
18 
19 // ----------------------------------------------------------------------------
20 // string constants used by wxPersistentBookCtrl
21 // ----------------------------------------------------------------------------
22 
23 #define wxPERSIST_BOOK_KIND wxASCII_STR("Book")
24 
25 #define wxPERSIST_BOOK_SELECTION wxASCII_STR("Selection")
26 
27 // ----------------------------------------------------------------------------
28 // wxPersistentBookCtrl: supports saving/restoring book control selection
29 // ----------------------------------------------------------------------------
30 
31 class wxPersistentBookCtrl : public wxPersistentWindow<wxBookCtrlBase>
32 {
33 public:
wxPersistentBookCtrl(wxBookCtrlBase * book)34     wxPersistentBookCtrl(wxBookCtrlBase *book)
35         : wxPersistentWindow<wxBookCtrlBase>(book)
36     {
37     }
38 
Save()39     virtual void Save() const wxOVERRIDE
40     {
41         SaveValue(wxPERSIST_BOOK_SELECTION, Get()->GetSelection());
42     }
43 
Restore()44     virtual bool Restore() wxOVERRIDE
45     {
46         long sel;
47         if ( RestoreValue(wxPERSIST_BOOK_SELECTION, &sel) )
48         {
49             wxBookCtrlBase * const book = Get();
50             if ( sel >= 0 && (unsigned)sel < book->GetPageCount() )
51             {
52                 book->SetSelection(sel);
53                 return true;
54             }
55         }
56 
57         return false;
58     }
59 
GetKind()60     virtual wxString GetKind() const wxOVERRIDE { return wxPERSIST_BOOK_KIND; }
61 };
62 
wxCreatePersistentObject(wxBookCtrlBase * book)63 inline wxPersistentObject *wxCreatePersistentObject(wxBookCtrlBase *book)
64 {
65     return new wxPersistentBookCtrl(book);
66 }
67 
68 #endif // wxUSE_BOOKCTRL
69 
70 #endif // _WX_PERSIST_BOOKCTRL_H_
71