]> git.saurik.com Git - wxWidgets.git/blob - include/wx/persist/treebook.h
Use correct reload flags on all platforms to avoid compilation errors
[wxWidgets.git] / include / wx / persist / treebook.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/persist/treebook.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_TREEBOOK_H_
12 #define _WX_PERSIST_TREEBOOK_H_
13
14 #include "wx/persist/bookctrl.h"
15
16 #include "wx/arrstr.h"
17 #include "wx/treebook.h"
18
19 // ----------------------------------------------------------------------------
20 // string constants used by wxPersistentTreeBookCtrl
21 // ----------------------------------------------------------------------------
22
23 #define wxPERSIST_TREEBOOK_KIND "TreeBook"
24
25 // this key contains the indices of all expanded nodes in the tree book
26 // separated by wxPERSIST_TREEBOOK_EXPANDED_SEP
27 #define wxPERSIST_TREEBOOK_EXPANDED_BRANCHES "Expanded"
28 #define wxPERSIST_TREEBOOK_EXPANDED_SEP ','
29
30 // ----------------------------------------------------------------------------
31 // wxPersistentTreeBookCtrl: supports saving/restoring open tree branches
32 // ----------------------------------------------------------------------------
33
34 class wxPersistentTreeBookCtrl : public wxPersistentBookCtrl
35 {
36 public:
37 wxPersistentTreeBookCtrl(wxTreebook *book)
38 : wxPersistentBookCtrl(book)
39 {
40 }
41
42 virtual void Save() const
43 {
44 const wxTreebook * const book = GetTreeBook();
45
46 wxString expanded;
47 const size_t count = book->GetPageCount();
48 for ( size_t n = 0; n < count; n++ )
49 {
50 if ( book->IsNodeExpanded(n) )
51 {
52 if ( !expanded.empty() )
53 expanded += wxPERSIST_TREEBOOK_EXPANDED_SEP;
54
55 expanded += wxString::Format("%u", static_cast<unsigned>(n));
56 }
57 }
58
59 SaveValue(wxPERSIST_TREEBOOK_EXPANDED_BRANCHES, expanded);
60
61 wxPersistentBookCtrl::Save();
62 }
63
64 virtual bool Restore()
65 {
66 wxTreebook * const book = GetTreeBook();
67
68 wxString expanded;
69 if ( RestoreValue(wxPERSIST_TREEBOOK_EXPANDED_BRANCHES, &expanded) )
70 {
71 const wxArrayString
72 indices(wxSplit(expanded, wxPERSIST_TREEBOOK_EXPANDED_SEP));
73
74 const size_t pageCount = book->GetPageCount();
75 const size_t count = indices.size();
76 for ( size_t n = 0; n < count; n++ )
77 {
78 unsigned long idx;
79 if ( indices[n].ToULong(&idx) && idx < pageCount )
80 book->ExpandNode(idx);
81 }
82 }
83
84 return wxPersistentBookCtrl::Restore();
85 }
86
87 virtual wxString GetKind() const { return wxPERSIST_TREEBOOK_KIND; }
88
89 wxTreebook *GetTreeBook() const { return static_cast<wxTreebook *>(Get()); }
90 };
91
92 inline wxPersistentObject *wxCreatePersistentObject(wxTreebook *book)
93 {
94 return new wxPersistentTreeBookCtrl(book);
95 }
96
97 #endif // _WX_PERSIST_TREEBOOK_H_