2009-01-30 16:38:29 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/persist/treebook.h
|
|
|
|
// Purpose: persistence support for wxBookCtrl
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Created: 2009-01-19
|
|
|
|
// Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_PERSIST_TREEBOOK_H_
|
|
|
|
#define _WX_PERSIST_TREEBOOK_H_
|
|
|
|
|
|
|
|
#include "wx/persist/bookctrl.h"
|
|
|
|
|
2020-11-19 10:34:17 -05:00
|
|
|
#if wxUSE_TREEBOOK
|
|
|
|
|
2009-01-30 16:38:29 -05:00
|
|
|
#include "wx/arrstr.h"
|
|
|
|
#include "wx/treebook.h"
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// string constants used by wxPersistentTreeBookCtrl
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2020-11-19 07:04:57 -05:00
|
|
|
#define wxPERSIST_TREEBOOK_KIND wxASCII_STR("TreeBook")
|
2009-01-30 16:38:29 -05:00
|
|
|
|
|
|
|
// this key contains the indices of all expanded nodes in the tree book
|
|
|
|
// separated by wxPERSIST_TREEBOOK_EXPANDED_SEP
|
2020-11-19 07:04:57 -05:00
|
|
|
#define wxPERSIST_TREEBOOK_EXPANDED_BRANCHES wxASCII_STR("Expanded")
|
2009-01-30 16:38:29 -05:00
|
|
|
#define wxPERSIST_TREEBOOK_EXPANDED_SEP ','
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxPersistentTreeBookCtrl: supports saving/restoring open tree branches
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class wxPersistentTreeBookCtrl : public wxPersistentBookCtrl
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxPersistentTreeBookCtrl(wxTreebook *book)
|
|
|
|
: wxPersistentBookCtrl(book)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual void Save() const wxOVERRIDE
|
2009-01-30 16:38:29 -05:00
|
|
|
{
|
|
|
|
const wxTreebook * const book = GetTreeBook();
|
|
|
|
|
|
|
|
wxString expanded;
|
|
|
|
const size_t count = book->GetPageCount();
|
|
|
|
for ( size_t n = 0; n < count; n++ )
|
|
|
|
{
|
|
|
|
if ( book->IsNodeExpanded(n) )
|
|
|
|
{
|
|
|
|
if ( !expanded.empty() )
|
|
|
|
expanded += wxPERSIST_TREEBOOK_EXPANDED_SEP;
|
|
|
|
|
2019-10-22 06:34:29 -04:00
|
|
|
expanded += wxString::Format(wxASCII_STR("%u"), static_cast<unsigned>(n));
|
2009-01-30 16:38:29 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SaveValue(wxPERSIST_TREEBOOK_EXPANDED_BRANCHES, expanded);
|
|
|
|
|
|
|
|
wxPersistentBookCtrl::Save();
|
|
|
|
}
|
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual bool Restore() wxOVERRIDE
|
2009-01-30 16:38:29 -05:00
|
|
|
{
|
|
|
|
wxTreebook * const book = GetTreeBook();
|
|
|
|
|
|
|
|
wxString expanded;
|
|
|
|
if ( RestoreValue(wxPERSIST_TREEBOOK_EXPANDED_BRANCHES, &expanded) )
|
|
|
|
{
|
|
|
|
const wxArrayString
|
|
|
|
indices(wxSplit(expanded, wxPERSIST_TREEBOOK_EXPANDED_SEP));
|
|
|
|
|
|
|
|
const size_t pageCount = book->GetPageCount();
|
|
|
|
const size_t count = indices.size();
|
|
|
|
for ( size_t n = 0; n < count; n++ )
|
|
|
|
{
|
|
|
|
unsigned long idx;
|
|
|
|
if ( indices[n].ToULong(&idx) && idx < pageCount )
|
|
|
|
book->ExpandNode(idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return wxPersistentBookCtrl::Restore();
|
|
|
|
}
|
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual wxString GetKind() const wxOVERRIDE { return wxPERSIST_TREEBOOK_KIND; }
|
2009-01-30 16:38:29 -05:00
|
|
|
|
|
|
|
wxTreebook *GetTreeBook() const { return static_cast<wxTreebook *>(Get()); }
|
|
|
|
};
|
|
|
|
|
|
|
|
inline wxPersistentObject *wxCreatePersistentObject(wxTreebook *book)
|
|
|
|
{
|
|
|
|
return new wxPersistentTreeBookCtrl(book);
|
|
|
|
}
|
|
|
|
|
2020-11-19 10:34:17 -05:00
|
|
|
#endif // wxUSE_TREEBOOK
|
|
|
|
|
2009-01-30 16:38:29 -05:00
|
|
|
#endif // _WX_PERSIST_TREEBOOK_H_
|