initial commit

Signed-off-by: Peter Siegmund <mars3142@noreply.mars3142.dev>
This commit is contained in:
2025-10-31 23:37:30 +01:00
commit bf6b52fd94
9654 changed files with 4035664 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/persist/bookctrl.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_BOOKCTRL_H_
#define _WX_PERSIST_BOOKCTRL_H_
#include "wx/persist/window.h"
#if wxUSE_BOOKCTRL
#include "wx/bookctrl.h"
// ----------------------------------------------------------------------------
// string constants used by wxPersistentBookCtrl
// ----------------------------------------------------------------------------
#define wxPERSIST_BOOK_KIND wxASCII_STR("Book")
#define wxPERSIST_BOOK_SELECTION wxASCII_STR("Selection")
// ----------------------------------------------------------------------------
// wxPersistentBookCtrl: supports saving/restoring book control selection
// ----------------------------------------------------------------------------
class wxPersistentBookCtrl : public wxPersistentWindow<wxBookCtrlBase>
{
public:
wxPersistentBookCtrl(wxBookCtrlBase *book)
: wxPersistentWindow<wxBookCtrlBase>(book)
{
}
virtual void Save() const override
{
SaveValue(wxPERSIST_BOOK_SELECTION, Get()->GetSelection());
}
virtual bool Restore() override
{
long sel;
if ( RestoreValue(wxPERSIST_BOOK_SELECTION, &sel) )
{
wxBookCtrlBase * const book = Get();
if ( sel >= 0 && (unsigned)sel < book->GetPageCount() )
{
book->SetSelection(sel);
return true;
}
}
return false;
}
virtual wxString GetKind() const override { return wxPERSIST_BOOK_KIND; }
};
inline wxPersistentObject *wxCreatePersistentObject(wxBookCtrlBase *book)
{
return new wxPersistentBookCtrl(book);
}
#endif // wxUSE_BOOKCTRL
#endif // _WX_PERSIST_BOOKCTRL_H_

View File

@@ -0,0 +1,89 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/persist/checkbox.h
// Purpose: Persistence support for wxCheckBox.
// Author: Alexander Koshelev, Vadim Zeitlin
// Created: 2025-06-11
// Copyright: (c) 2025 wxWidgets team
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_PERSIST_CHECKBOX_H_
#define _WX_PERSIST_CHECKBOX_H_
#include "wx/persist/window.h"
#include "wx/checkbox.h"
// ----------------------------------------------------------------------------
// string constants used by wxPersistentCheckBox
// ----------------------------------------------------------------------------
#define wxPERSIST_CHECKBOX_KIND wxASCII_STR("Checkbox")
#define wxPERSIST_CHECKBOX_VALUE wxASCII_STR("Value")
// ----------------------------------------------------------------------------
// wxPersistentCheckBox: supports saving/restoring checkbox state
// ----------------------------------------------------------------------------
// Implementation note: we depend on the values of wxCheckBoxState enum not
// changing, as we save them directly as numbers, but this seems a safe bet as
// it's hard to imagine adding any more values to it.
class wxPersistentCheckBox : public wxPersistentWindow<wxCheckBox>
{
public:
explicit wxPersistentCheckBox(wxCheckBox* checkbox)
: wxPersistentWindow<wxCheckBox>(checkbox)
{
}
virtual void Save() const override
{
const wxCheckBox* const checkbox = Get();
const auto value = checkbox->Get3StateValue();
SaveValue(wxPERSIST_CHECKBOX_VALUE, static_cast<int>(value));
}
virtual bool Restore() override
{
int value;
if ( !RestoreValue(wxPERSIST_CHECKBOX_VALUE, &value) )
return false;
switch ( value )
{
case wxCHK_UNCHECKED:
case wxCHK_CHECKED:
// These values are always valid.
break;
case wxCHK_UNDETERMINED:
if ( Get()->Is3State() )
{
// This value is valid for this checkbox.
break;
}
wxFALLTHROUGH;
default:
// Silently ignore invalid values, as it's not really clear
// what else can we do about them.
return false;
}
Get()->Set3StateValue(static_cast<wxCheckBoxState>(value));
return true;
}
virtual wxString GetKind() const override { return wxPERSIST_CHECKBOX_KIND; }
};
inline wxPersistentObject *wxCreatePersistentObject(wxCheckBox* checkbox)
{
return new wxPersistentCheckBox(checkbox);
}
#endif // _WX_PERSIST_CHECKBOX_H_

View File

@@ -0,0 +1,103 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/persist/combobox.h
// Purpose: Persistence adapter for wxComboBox
// Author: Vadim Zeitlin
// Created: 2020-11-19
// Copyright: (c) 2020 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_PERSIST_COMBOBOX_H_
#define _WX_PERSIST_COMBOBOX_H_
#include "wx/persist/window.h"
#if wxUSE_COMBOBOX
#include "wx/combobox.h"
#define wxPERSIST_COMBOBOX_KIND wxASCII_STR("Combobox")
// Stores semicolon-separated list of combobox entries (real semicolons are
// escaped using backslash), i.e. "first;second;...".
#define wxPERSIST_COMBOBOX_ITEMS wxASCII_STR("Items")
#define wxPERSIST_COMBOBOX_ITEMS_SEP ';'
// ----------------------------------------------------------------------------
// wxPersistentComboBox: supports saving/restoring combobox items
// ----------------------------------------------------------------------------
class wxPersistentComboBox : public wxPersistentWindow<wxComboBox>
{
public:
// The maximum number of items to save is currently hard-coded.
//
// Notice that we must have some limit, as otherwise the length of the
// items string in the config would be unbounded, which certainly wouldn't
// be a good idea.
enum { MaxSavedItemsCount = 10 };
explicit wxPersistentComboBox(wxComboBox* combobox)
: wxPersistentWindow<wxComboBox>(combobox)
{
}
virtual void Save() const override
{
const wxComboBox* const combobox = Get();
wxArrayString items = combobox->GetStrings();
const wxString value = combobox->GetValue();
if ( !value.empty() )
{
wxArrayString::iterator it;
for ( it = items.begin(); it != items.end(); ++it )
{
if ( *it == value )
{
// There is no need to add the text of an item already
// present in the combobox again, but do move it to the top
// of it to indicate that it was the last one used.
wxSwap(*items.begin(), *it);
break;
}
}
if ( it == items.end() )
{
// This is a genuinely new item, so just insert it front.
items.insert(items.begin(), value);
if ( items.size() > MaxSavedItemsCount )
items.erase(items.begin() + MaxSavedItemsCount, items.end());
}
}
SaveValue(wxPERSIST_COMBOBOX_ITEMS,
wxJoin(items, wxPERSIST_COMBOBOX_ITEMS_SEP));
}
virtual bool Restore() override
{
wxString items;
if ( !RestoreValue(wxPERSIST_COMBOBOX_ITEMS, &items) )
return false;
Get()->Set(wxSplit(items, wxPERSIST_COMBOBOX_ITEMS_SEP));
return true;
}
virtual wxString GetKind() const override { return wxPERSIST_COMBOBOX_KIND; }
};
inline wxPersistentObject *wxCreatePersistentObject(wxComboBox* combobox)
{
return new wxPersistentComboBox(combobox);
}
#endif // wxUSE_COMBOBOX
#endif // _WX_PERSIST_COMBOBOX_H_

View File

@@ -0,0 +1,175 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/persist/dataview.h
// Purpose: Persistence support for wxDataViewCtrl and its derivatives
// Author: wxWidgets Team
// Created: 2017-08-21
// Copyright: (c) 2017 wxWidgets.org
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_PERSIST_DATAVIEW_H_
#define _WX_PERSIST_DATAVIEW_H_
#include "wx/persist/window.h"
#if wxUSE_DATAVIEWCTRL
#include "wx/dataview.h"
// ----------------------------------------------------------------------------
// String constants used by wxPersistentDataViewCtrl.
// ----------------------------------------------------------------------------
#define wxPERSIST_DVC_KIND "DataView"
#define wxPERSIST_DVC_HIDDEN "Hidden"
#define wxPERSIST_DVC_POS "Position"
#define wxPERSIST_DVC_TITLE "Title"
#define wxPERSIST_DVC_WIDTH "Width"
#define wxPERSIST_DVC_SORT_KEY "Sorting/Column"
#define wxPERSIST_DVC_SORT_ASC "Sorting/Asc"
// ----------------------------------------------------------------------------
// wxPersistentDataViewCtrl: Saves and restores user modified column widths
// and single column sort order.
//
// Future improvements could be to save and restore column order if the user
// has changed it and multicolumn sorts.
// ----------------------------------------------------------------------------
class wxPersistentDataViewCtrl : public wxPersistentWindow<wxDataViewCtrl>
{
public:
wxPersistentDataViewCtrl(wxDataViewCtrl* control)
: wxPersistentWindow<wxDataViewCtrl>(control)
{
}
virtual void Save() const override
{
wxDataViewCtrl* const control = Get();
const wxDataViewColumn* sortColumn = nullptr;
for ( unsigned int col = 0; col < control->GetColumnCount(); col++ )
{
const wxDataViewColumn* const column = control->GetColumn(col);
// Create a prefix string to identify each column.
const wxString columnPrefix = MakeColumnPrefix(column);
// Save the column attributes.
SaveValue(columnPrefix + wxASCII_STR(wxPERSIST_DVC_HIDDEN), column->IsHidden());
SaveValue(columnPrefix + wxASCII_STR(wxPERSIST_DVC_POS),
control->GetColumnPosition(column));
// We take special care to save only the specified width instead of
// the currently used one. Usually they're one and the same, but
// they can be different for the last column, whose size can be
// greater than specified, as it's always expanded to fill the
// entire control width.
const int width = column->WXGetSpecifiedWidth();
if ( width > 0 )
SaveValue(columnPrefix + wxASCII_STR(wxPERSIST_DVC_WIDTH), width);
// Check if this column is the current sort key.
if ( column->IsSortKey() )
sortColumn = column;
}
// Note: The current implementation does not save and restore multi-
// column sort keys.
if ( control->IsMultiColumnSortAllowed() )
return;
// Save the sort key and direction if there is a valid sort.
if ( sortColumn )
{
SaveValue(wxASCII_STR(wxPERSIST_DVC_SORT_KEY), sortColumn->GetTitle());
SaveValue(wxASCII_STR(wxPERSIST_DVC_SORT_ASC),
sortColumn->IsSortOrderAscending());
}
}
virtual bool Restore() override
{
wxDataViewCtrl* const control = Get();
for ( unsigned int col = 0; col < control->GetColumnCount(); col++ )
{
wxDataViewColumn* const column = control->GetColumn(col);
// Create a prefix string to identify each column within the
// persistence store (columns are stored by title). The persistence
// store benignly handles cases where the title is not found.
const wxString columnPrefix = MakeColumnPrefix(column);
// Restore column hidden status.
bool hidden;
if ( RestoreValue(columnPrefix + wxASCII_STR(wxPERSIST_DVC_HIDDEN), &hidden) )
column->SetHidden(hidden);
// Restore the column width.
int width;
if ( RestoreValue(columnPrefix + wxASCII_STR(wxPERSIST_DVC_WIDTH), &width) )
column->SetWidth(width);
// TODO: Set the column's view position.
}
// Restore the sort key and order if there is a valid model and sort
// criteria.
wxString sortColumn;
if ( control->GetModel() &&
RestoreValue(wxASCII_STR(wxPERSIST_DVC_SORT_KEY), &sortColumn) &&
!sortColumn.empty() )
{
bool sortAsc = true;
if ( wxDataViewColumn* column = GetColumnByTitle(control, sortColumn) )
{
RestoreValue(wxASCII_STR(wxPERSIST_DVC_SORT_ASC), &sortAsc);
column->SetSortOrder(sortAsc);
// Resort the control based on the new sort criteria.
control->GetModel()->Resort();
}
}
return true;
}
virtual wxString GetKind() const override
{
return wxASCII_STR(wxPERSIST_DVC_KIND);
}
private:
// Return a (slash-terminated) prefix for the column-specific entries.
static wxString MakeColumnPrefix(const wxDataViewColumn* column)
{
return wxString::Format(wxASCII_STR("/Columns/%s/"), column->GetTitle());
}
// Return the column with the given title or nullptr.
static wxDataViewColumn*
GetColumnByTitle(wxDataViewCtrl* control, const wxString& title)
{
for ( unsigned int col = 0; col < control->GetColumnCount(); col++ )
{
if ( control->GetColumn(col)->GetTitle() == title )
return control->GetColumn(col);
}
return nullptr;
}
};
inline wxPersistentObject *wxCreatePersistentObject(wxDataViewCtrl* control)
{
return new wxPersistentDataViewCtrl(control);
}
#endif // wxUSE_DATAVIEWCTRL
#endif // _WX_PERSIST_DATAVIEW_H_

View File

@@ -0,0 +1,113 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/persist/radiobut.h
// Purpose: Persistence support for wxRadioButton.
// Author: Vadim Zeitlin
// Created: 2025-06-12
// Copyright: (c) 2025 Vadim Zeitlin
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_PERSIST_RADIOBUT_H_
#define _WX_PERSIST_RADIOBUT_H_
#include "wx/persist/window.h"
#include "wx/radiobut.h"
#if wxUSE_RADIOBTN
// ----------------------------------------------------------------------------
// string constants used by wxPersistentRadioButton
// ----------------------------------------------------------------------------
#define wxPERSIST_RADIOBUTTON_KIND wxASCII_STR("RadioButton")
#define wxPERSIST_RADIOBUTTON_VALUE wxASCII_STR("Value")
// ----------------------------------------------------------------------------
// wxPersistentRadioButton: supports saving/restoring radio buttons state
// ----------------------------------------------------------------------------
// This class should be always used with the first button in a group of radio
// buttons and it saves its state as an integer indicating the offset of the
// selected radio button in this group.
//
// Currently radio buttons with wxRB_SINGLE style are not supported. While it
// wouldn't be very difficult to add support for them if anybody really needs
// it, it seems relatively unlikely, so for now we don't bother to do it.
class wxPersistentRadioButton : public wxPersistentWindow<wxRadioButton>
{
public:
explicit wxPersistentRadioButton(wxRadioButton* radiobutton)
: wxPersistentWindow<wxRadioButton>(radiobutton)
{
wxASSERT_MSG( !radiobutton->HasFlag(wxRB_SINGLE),
"wxPersistentRadioButton doesn't support wxRB_SINGLE" );
wxASSERT_MSG( radiobutton->HasFlag(wxRB_GROUP),
"wxPersistentRadioButton should be used with the first "
"radio button in a group" );
}
virtual void Save() const override
{
const wxRadioButton* button = Get();
for ( int n = 0;; ++n )
{
if ( button->GetValue() )
{
// We found the selected button, save its index.
SaveValue(wxPERSIST_RADIOBUTTON_VALUE, n);
break;
}
button = button->GetNextInGroup();
if ( !button )
{
wxFAIL_MSG("Didn't find a selected radio button in the group?");
break;
}
}
}
virtual bool Restore() override
{
int value;
if ( !RestoreValue(wxPERSIST_RADIOBUTTON_VALUE, &value) )
return false;
wxRadioButton* button = Get();
for ( int n = 0;; ++n )
{
if ( n == value )
{
// We found the button with the saved index, set its value.
button->SetValue(true);
break;
}
button = button->GetNextInGroup();
if ( !button )
{
// The saved value is invalid, silently ignore it because there
// doesn't seem to be much else that we can do in this case.
break;
}
}
return true;
}
virtual wxString GetKind() const override { return wxPERSIST_RADIOBUTTON_KIND; }
};
inline wxPersistentObject *wxCreatePersistentObject(wxRadioButton* radiobutton)
{
return new wxPersistentRadioButton(radiobutton);
}
#endif // wxUSE_RADIOBTN
#endif // _WX_PERSIST_RADIOBUT_H_

View File

@@ -0,0 +1,87 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/persist/splitter.h
// Purpose: Persistence support for wxSplitterWindow.
// Author: Vadim Zeitlin
// Created: 2011-08-31
// Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_PERSIST_SPLITTER_H_
#define _WX_PERSIST_SPLITTER_H_
#include "wx/persist/window.h"
#include "wx/splitter.h"
// ----------------------------------------------------------------------------
// string constants used by wxPersistentSplitter
// ----------------------------------------------------------------------------
#define wxPERSIST_SPLITTER_KIND wxASCII_STR("Splitter")
// Special position value of -1 means the splitter is not split at all.
#define wxPERSIST_SPLITTER_POSITION wxASCII_STR("Position")
#define wxPERSIST_SPLITTER_DEFAULT_HORIZONTAL wxASCII_STR("LastHorz")
#define wxPERSIST_SPLITTER_DEFAULT_VERTICAL wxASCII_STR("LastVert")
// ----------------------------------------------------------------------------
// wxPersistentSplitter: supports saving/restoring splitter position
// ----------------------------------------------------------------------------
class wxPersistentSplitter : public wxPersistentWindow<wxSplitterWindow>
{
public:
wxPersistentSplitter(wxSplitterWindow* splitter)
: wxPersistentWindow<wxSplitterWindow>(splitter)
{
}
virtual void Save() const override
{
wxSplitterWindow* const splitter = Get();
int pos = splitter->IsSplit() ? splitter->GetSashPosition() : -1;
SaveValue(wxPERSIST_SPLITTER_POSITION, pos);
// Save the previously used position too if we have them.
const wxPoint lastSplitPos = splitter->GetLastSplitPosition();
if ( lastSplitPos.x || lastSplitPos.y )
{
SaveValue(wxPERSIST_SPLITTER_DEFAULT_HORIZONTAL, lastSplitPos.y);
SaveValue(wxPERSIST_SPLITTER_DEFAULT_VERTICAL, lastSplitPos.x);
}
}
virtual bool Restore() override
{
int pos;
if ( !RestoreValue(wxPERSIST_SPLITTER_POSITION, &pos) )
return false;
if ( pos == -1 )
Get()->Unsplit();
else
Get()->SetSashPosition(pos);
// Note that it's possible that default position was not stored, in
// which case lastSplitPos will just remain as (0, 0) and that's ok.
wxPoint lastSplitPos;
RestoreValue(wxPERSIST_SPLITTER_DEFAULT_HORIZONTAL, &lastSplitPos.x);
RestoreValue(wxPERSIST_SPLITTER_DEFAULT_VERTICAL, &lastSplitPos.y);
Get()->SetLastSplitPosition(lastSplitPos);
return true;
}
virtual wxString GetKind() const override { return wxPERSIST_SPLITTER_KIND; }
};
inline wxPersistentObject *wxCreatePersistentObject(wxSplitterWindow* splitter)
{
return new wxPersistentSplitter(splitter);
}
#endif // _WX_PERSIST_SPLITTER_H_

View File

@@ -0,0 +1,73 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/persist/toplevel.h
// Purpose: persistence support for wxTLW
// Author: Vadim Zeitlin
// Created: 2009-01-19
// Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_PERSIST_TOPLEVEL_H_
#define _WX_PERSIST_TOPLEVEL_H_
#include "wx/persist/window.h"
#include "wx/toplevel.h"
// ----------------------------------------------------------------------------
// string constants used by wxPersistentTLW
// ----------------------------------------------------------------------------
// we use just "Window" to keep configuration files and such short, there
// should be no confusion with wxWindow itself as we don't have persistent
// windows, just persistent controls which have their own specific kind strings
#define wxPERSIST_TLW_KIND "Window"
// ----------------------------------------------------------------------------
// wxPersistentTLW: supports saving/restoring window position and size as well
// as maximized/iconized/restore state
// ----------------------------------------------------------------------------
class wxPersistentTLW : public wxPersistentWindow<wxTopLevelWindow>,
private wxTopLevelWindow::GeometrySerializer
{
public:
wxPersistentTLW(wxTopLevelWindow *tlw)
: wxPersistentWindow<wxTopLevelWindow>(tlw)
{
}
virtual void Save() const override
{
const wxTopLevelWindow * const tlw = Get();
tlw->SaveGeometry(*this);
}
virtual bool Restore() override
{
wxTopLevelWindow * const tlw = Get();
return tlw->RestoreToGeometry(*this);
}
virtual wxString GetKind() const override { return wxASCII_STR(wxPERSIST_TLW_KIND); }
private:
virtual bool SaveField(const wxString& name, int value) const override
{
return SaveValue(name, value);
}
virtual bool RestoreField(const wxString& name, int* value) override
{
return RestoreValue(name, value);
}
};
inline wxPersistentObject *wxCreatePersistentObject(wxTopLevelWindow *tlw)
{
return new wxPersistentTLW(tlw);
}
#endif // _WX_PERSIST_TOPLEVEL_H_

View File

@@ -0,0 +1,100 @@
///////////////////////////////////////////////////////////////////////////////
// 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"
#if wxUSE_TREEBOOK
#include "wx/arrstr.h"
#include "wx/treebook.h"
// ----------------------------------------------------------------------------
// string constants used by wxPersistentTreeBookCtrl
// ----------------------------------------------------------------------------
#define wxPERSIST_TREEBOOK_KIND wxASCII_STR("TreeBook")
// this key contains the indices of all expanded nodes in the tree book
// separated by wxPERSIST_TREEBOOK_EXPANDED_SEP
#define wxPERSIST_TREEBOOK_EXPANDED_BRANCHES wxASCII_STR("Expanded")
#define wxPERSIST_TREEBOOK_EXPANDED_SEP ','
// ----------------------------------------------------------------------------
// wxPersistentTreeBookCtrl: supports saving/restoring open tree branches
// ----------------------------------------------------------------------------
class wxPersistentTreeBookCtrl : public wxPersistentBookCtrl
{
public:
wxPersistentTreeBookCtrl(wxTreebook *book)
: wxPersistentBookCtrl(book)
{
}
virtual void Save() const override
{
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;
expanded += wxString::Format(wxASCII_STR("%u"), static_cast<unsigned>(n));
}
}
SaveValue(wxPERSIST_TREEBOOK_EXPANDED_BRANCHES, expanded);
wxPersistentBookCtrl::Save();
}
virtual bool Restore() override
{
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();
}
virtual wxString GetKind() const override { return wxPERSIST_TREEBOOK_KIND; }
wxTreebook *GetTreeBook() const { return static_cast<wxTreebook *>(Get()); }
};
inline wxPersistentObject *wxCreatePersistentObject(wxTreebook *book)
{
return new wxPersistentTreeBookCtrl(book);
}
#endif // wxUSE_TREEBOOK
#endif // _WX_PERSIST_TREEBOOK_H_

View File

@@ -0,0 +1,76 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/persist/window.h
// Purpose: wxPersistentWindow declaration
// Author: Vadim Zeitlin
// Created: 2009-01-23
// Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_PERSIST_WINDOW_H_
#define _WX_PERSIST_WINDOW_H_
#include "wx/persist.h"
#include "wx/window.h"
// ----------------------------------------------------------------------------
// wxPersistentWindow: base class for persistent windows, uses the window name
// as persistent name by default and automatically reacts
// to the window destruction
// ----------------------------------------------------------------------------
// type-independent part of wxPersistentWindow
class wxPersistentWindowBase : public wxPersistentObject
{
public:
wxPersistentWindowBase(wxWindow *win)
: wxPersistentObject(win)
{
win->Bind(wxEVT_DESTROY, &wxPersistentWindowBase::HandleDestroy, this);
}
virtual wxString GetName() const override
{
const wxString name = GetWindow()->GetName();
wxASSERT_MSG( !name.empty(), "persistent windows should be named!" );
return name;
}
protected:
wxWindow *GetWindow() const { return static_cast<wxWindow *>(GetObject()); }
private:
void HandleDestroy(wxWindowDestroyEvent& event)
{
event.Skip();
// only react to the destruction of this object itself, not of any of
// its children
if ( event.GetEventObject() == GetObject() )
{
// this will delete this object itself
wxPersistenceManager::Get().SaveAndUnregister(GetWindow());
}
}
wxDECLARE_NO_COPY_CLASS(wxPersistentWindowBase);
};
template <class T>
class wxPersistentWindow : public wxPersistentWindowBase
{
public:
typedef T WindowType;
wxPersistentWindow(WindowType *win)
: wxPersistentWindowBase(win)
{
}
WindowType *Get() const { return static_cast<WindowType *>(GetWindow()); }
};
#endif // _WX_PERSIST_WINDOW_H_