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