Add wx headers and ext
This commit is contained in:
parent
6390dcef6a
commit
66d3c7b811
1531 changed files with 295895 additions and 0 deletions
70
wxheaders/wx/persist/bookctrl.h
Normal file
70
wxheaders/wx/persist/bookctrl.h
Normal 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 wxOVERRIDE
|
||||
{
|
||||
SaveValue(wxPERSIST_BOOK_SELECTION, Get()->GetSelection());
|
||||
}
|
||||
|
||||
virtual bool Restore() wxOVERRIDE
|
||||
{
|
||||
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 wxOVERRIDE { return wxPERSIST_BOOK_KIND; }
|
||||
};
|
||||
|
||||
inline wxPersistentObject *wxCreatePersistentObject(wxBookCtrlBase *book)
|
||||
{
|
||||
return new wxPersistentBookCtrl(book);
|
||||
}
|
||||
|
||||
#endif // wxUSE_BOOKCTRL
|
||||
|
||||
#endif // _WX_PERSIST_BOOKCTRL_H_
|
||||
103
wxheaders/wx/persist/combobox.h
Normal file
103
wxheaders/wx/persist/combobox.h
Normal 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 wxOVERRIDE
|
||||
{
|
||||
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() wxOVERRIDE
|
||||
{
|
||||
wxString items;
|
||||
if ( !RestoreValue(wxPERSIST_COMBOBOX_ITEMS, &items) )
|
||||
return false;
|
||||
|
||||
Get()->Set(wxSplit(items, wxPERSIST_COMBOBOX_ITEMS_SEP));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual wxString GetKind() const wxOVERRIDE { return wxPERSIST_COMBOBOX_KIND; }
|
||||
};
|
||||
|
||||
inline wxPersistentObject *wxCreatePersistentObject(wxComboBox* combobox)
|
||||
{
|
||||
return new wxPersistentComboBox(combobox);
|
||||
}
|
||||
|
||||
#endif // wxUSE_COMBOBOX
|
||||
|
||||
#endif // _WX_PERSIST_COMBOBOX_H_
|
||||
175
wxheaders/wx/persist/dataview.h
Normal file
175
wxheaders/wx/persist/dataview.h
Normal 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 wxOVERRIDE
|
||||
{
|
||||
wxDataViewCtrl* const control = Get();
|
||||
|
||||
const wxDataViewColumn* sortColumn = NULL;
|
||||
|
||||
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() wxOVERRIDE
|
||||
{
|
||||
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 wxOVERRIDE
|
||||
{
|
||||
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 NULL.
|
||||
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 NULL;
|
||||
}
|
||||
};
|
||||
|
||||
inline wxPersistentObject *wxCreatePersistentObject(wxDataViewCtrl* control)
|
||||
{
|
||||
return new wxPersistentDataViewCtrl(control);
|
||||
}
|
||||
|
||||
#endif // wxUSE_DATAVIEWCTRL
|
||||
|
||||
#endif // _WX_PERSIST_DATAVIEW_H_
|
||||
68
wxheaders/wx/persist/splitter.h
Normal file
68
wxheaders/wx/persist/splitter.h
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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")
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxPersistentSplitter: supports saving/restoring splitter position
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxPersistentSplitter : public wxPersistentWindow<wxSplitterWindow>
|
||||
{
|
||||
public:
|
||||
wxPersistentSplitter(wxSplitterWindow* splitter)
|
||||
: wxPersistentWindow<wxSplitterWindow>(splitter)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void Save() const wxOVERRIDE
|
||||
{
|
||||
wxSplitterWindow* const splitter = Get();
|
||||
|
||||
int pos = splitter->IsSplit() ? splitter->GetSashPosition() : -1;
|
||||
SaveValue(wxPERSIST_SPLITTER_POSITION, pos);
|
||||
}
|
||||
|
||||
virtual bool Restore() wxOVERRIDE
|
||||
{
|
||||
int pos;
|
||||
if ( !RestoreValue(wxPERSIST_SPLITTER_POSITION, &pos) )
|
||||
return false;
|
||||
|
||||
if ( pos == -1 )
|
||||
Get()->Unsplit();
|
||||
else
|
||||
Get()->SetSashPosition(pos);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual wxString GetKind() const wxOVERRIDE { return wxPERSIST_SPLITTER_KIND; }
|
||||
};
|
||||
|
||||
inline wxPersistentObject *wxCreatePersistentObject(wxSplitterWindow* splitter)
|
||||
{
|
||||
return new wxPersistentSplitter(splitter);
|
||||
}
|
||||
|
||||
#endif // _WX_PERSIST_SPLITTER_H_
|
||||
73
wxheaders/wx/persist/toplevel.h
Normal file
73
wxheaders/wx/persist/toplevel.h
Normal 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 wxOVERRIDE
|
||||
{
|
||||
const wxTopLevelWindow * const tlw = Get();
|
||||
|
||||
tlw->SaveGeometry(*this);
|
||||
}
|
||||
|
||||
virtual bool Restore() wxOVERRIDE
|
||||
{
|
||||
wxTopLevelWindow * const tlw = Get();
|
||||
|
||||
return tlw->RestoreToGeometry(*this);
|
||||
}
|
||||
|
||||
virtual wxString GetKind() const wxOVERRIDE { return wxASCII_STR(wxPERSIST_TLW_KIND); }
|
||||
|
||||
private:
|
||||
virtual bool SaveField(const wxString& name, int value) const wxOVERRIDE
|
||||
{
|
||||
return SaveValue(name, value);
|
||||
}
|
||||
|
||||
virtual bool RestoreField(const wxString& name, int* value) wxOVERRIDE
|
||||
{
|
||||
return RestoreValue(name, value);
|
||||
}
|
||||
};
|
||||
|
||||
inline wxPersistentObject *wxCreatePersistentObject(wxTopLevelWindow *tlw)
|
||||
{
|
||||
return new wxPersistentTLW(tlw);
|
||||
}
|
||||
|
||||
#endif // _WX_PERSIST_TOPLEVEL_H_
|
||||
100
wxheaders/wx/persist/treebook.h
Normal file
100
wxheaders/wx/persist/treebook.h
Normal 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 wxOVERRIDE
|
||||
{
|
||||
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() wxOVERRIDE
|
||||
{
|
||||
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 wxOVERRIDE { 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_
|
||||
76
wxheaders/wx/persist/window.h
Normal file
76
wxheaders/wx/persist/window.h
Normal 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 wxOVERRIDE
|
||||
{
|
||||
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_
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue