]> git.saurik.com Git - wxWidgets.git/blame - include/wx/persist/treebook.h
Don't define __STRICT_ANSI__, we should build both with and without it.
[wxWidgets.git] / include / wx / persist / treebook.h
CommitLineData
0fa541e8
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/persist/treebook.h
3// Purpose: persistence support for wxBookCtrl
4// Author: Vadim Zeitlin
5// Created: 2009-01-19
0fa541e8
VZ
6// Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
7// Licence: wxWindows licence
8///////////////////////////////////////////////////////////////////////////////
9
10#ifndef _WX_PERSIST_TREEBOOK_H_
11#define _WX_PERSIST_TREEBOOK_H_
12
13#include "wx/persist/bookctrl.h"
14
15#include "wx/arrstr.h"
16#include "wx/treebook.h"
17
18// ----------------------------------------------------------------------------
19// string constants used by wxPersistentTreeBookCtrl
20// ----------------------------------------------------------------------------
21
22#define wxPERSIST_TREEBOOK_KIND "TreeBook"
23
24// this key contains the indices of all expanded nodes in the tree book
25// separated by wxPERSIST_TREEBOOK_EXPANDED_SEP
26#define wxPERSIST_TREEBOOK_EXPANDED_BRANCHES "Expanded"
27#define wxPERSIST_TREEBOOK_EXPANDED_SEP ','
28
29// ----------------------------------------------------------------------------
30// wxPersistentTreeBookCtrl: supports saving/restoring open tree branches
31// ----------------------------------------------------------------------------
32
33class wxPersistentTreeBookCtrl : public wxPersistentBookCtrl
34{
35public:
36 wxPersistentTreeBookCtrl(wxTreebook *book)
37 : wxPersistentBookCtrl(book)
38 {
39 }
40
41 virtual void Save() const
42 {
43 const wxTreebook * const book = GetTreeBook();
44
45 wxString expanded;
46 const size_t count = book->GetPageCount();
47 for ( size_t n = 0; n < count; n++ )
48 {
49 if ( book->IsNodeExpanded(n) )
50 {
51 if ( !expanded.empty() )
52 expanded += wxPERSIST_TREEBOOK_EXPANDED_SEP;
53
54 expanded += wxString::Format("%u", static_cast<unsigned>(n));
55 }
56 }
57
58 SaveValue(wxPERSIST_TREEBOOK_EXPANDED_BRANCHES, expanded);
59
60 wxPersistentBookCtrl::Save();
61 }
62
63 virtual bool Restore()
64 {
65 wxTreebook * const book = GetTreeBook();
66
67 wxString expanded;
68 if ( RestoreValue(wxPERSIST_TREEBOOK_EXPANDED_BRANCHES, &expanded) )
69 {
70 const wxArrayString
71 indices(wxSplit(expanded, wxPERSIST_TREEBOOK_EXPANDED_SEP));
72
73 const size_t pageCount = book->GetPageCount();
74 const size_t count = indices.size();
75 for ( size_t n = 0; n < count; n++ )
76 {
77 unsigned long idx;
78 if ( indices[n].ToULong(&idx) && idx < pageCount )
79 book->ExpandNode(idx);
80 }
81 }
82
83 return wxPersistentBookCtrl::Restore();
84 }
85
86 virtual wxString GetKind() const { return wxPERSIST_TREEBOOK_KIND; }
87
88 wxTreebook *GetTreeBook() const { return static_cast<wxTreebook *>(Get()); }
89};
90
91inline wxPersistentObject *wxCreatePersistentObject(wxTreebook *book)
92{
93 return new wxPersistentTreeBookCtrl(book);
94}
95
96#endif // _WX_PERSIST_TREEBOOK_H_