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