wxAUI: Support serialization of individual PaneInfo structures
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40321 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -192,6 +192,19 @@ public:
|
|||||||
}
|
}
|
||||||
#endif // SWIG
|
#endif // SWIG
|
||||||
|
|
||||||
|
// Write the safe parts of a newly loaded PaneInfo structure "source" into "this"
|
||||||
|
// used on loading perspectives etc.
|
||||||
|
void SafeSet(wxPaneInfo source)
|
||||||
|
{
|
||||||
|
// note source is not passed by reference so we can overwrite, to keep the
|
||||||
|
// unsafe bits of "dest"
|
||||||
|
source.window = window;
|
||||||
|
source.frame = frame;
|
||||||
|
source.buttons = buttons;
|
||||||
|
// now assign
|
||||||
|
*this = source;
|
||||||
|
}
|
||||||
|
|
||||||
bool IsOk() const { return (window != NULL) ? true : false; }
|
bool IsOk() const { return (window != NULL) ? true : false; }
|
||||||
bool IsFixed() const { return !HasFlag(optionResizable); }
|
bool IsFixed() const { return !HasFlag(optionResizable); }
|
||||||
bool IsResizable() const { return HasFlag(optionResizable); }
|
bool IsResizable() const { return HasFlag(optionResizable); }
|
||||||
@@ -415,6 +428,9 @@ public:
|
|||||||
|
|
||||||
bool DetachPane(wxWindow* window);
|
bool DetachPane(wxWindow* window);
|
||||||
|
|
||||||
|
wxString SavePaneInfo(wxPaneInfo& pane);
|
||||||
|
wxString LoadPaneInfo(wxString pane_part, wxPaneInfo &pane);
|
||||||
|
|
||||||
wxString SavePerspective();
|
wxString SavePerspective();
|
||||||
|
|
||||||
bool LoadPerspective(const wxString& perspective,
|
bool LoadPerspective(const wxString& perspective,
|
||||||
|
@@ -928,24 +928,9 @@ static wxString EscapeDelimiters(const wxString& s)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxString wxFrameManager::SavePaneInfo(wxPaneInfo& pane)
|
||||||
// SavePerspective() saves all pane information as a single string.
|
|
||||||
// This string may later be fed into LoadPerspective() to restore
|
|
||||||
// all pane settings. This save and load mechanism allows an
|
|
||||||
// exact pane configuration to be saved and restored at a later time
|
|
||||||
|
|
||||||
wxString wxFrameManager::SavePerspective()
|
|
||||||
{
|
{
|
||||||
wxString result;
|
wxString result = wxT("name=");
|
||||||
result.Alloc(500);
|
|
||||||
result = wxT("layout1|");
|
|
||||||
|
|
||||||
int pane_i, pane_count = m_panes.GetCount();
|
|
||||||
for (pane_i = 0; pane_i < pane_count; ++pane_i)
|
|
||||||
{
|
|
||||||
wxPaneInfo& pane = m_panes.Item(pane_i);
|
|
||||||
|
|
||||||
result += wxT("name=");
|
|
||||||
result += EscapeDelimiters(pane.name);
|
result += EscapeDelimiters(pane.name);
|
||||||
result += wxT(";");
|
result += wxT(";");
|
||||||
|
|
||||||
@@ -969,90 +954,19 @@ wxString wxFrameManager::SavePerspective()
|
|||||||
result += wxString::Format(wxT("floaty=%d;"), pane.floating_pos.y);
|
result += wxString::Format(wxT("floaty=%d;"), pane.floating_pos.y);
|
||||||
result += wxString::Format(wxT("floatw=%d;"), pane.floating_size.x);
|
result += wxString::Format(wxT("floatw=%d;"), pane.floating_size.x);
|
||||||
result += wxString::Format(wxT("floath=%d"), pane.floating_size.y);
|
result += wxString::Format(wxT("floath=%d"), pane.floating_size.y);
|
||||||
result += wxT("|");
|
|
||||||
}
|
|
||||||
|
|
||||||
int dock_i, dock_count = m_docks.GetCount();
|
|
||||||
for (dock_i = 0; dock_i < dock_count; ++dock_i)
|
|
||||||
{
|
|
||||||
wxDockInfo& dock = m_docks.Item(dock_i);
|
|
||||||
|
|
||||||
result += wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
|
|
||||||
dock.dock_direction, dock.dock_layer,
|
|
||||||
dock.dock_row, dock.size);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadPerspective() loads a layout which was saved with SavePerspective()
|
// Load a "pane" with the pane infor settings in pane_part; return the remainder of the
|
||||||
// If the "update" flag parameter is true, the GUI will immediately be updated
|
// string
|
||||||
|
wxString wxFrameManager::LoadPaneInfo(wxString pane_part, wxPaneInfo &pane)
|
||||||
bool wxFrameManager::LoadPerspective(const wxString& layout, bool update)
|
|
||||||
{
|
{
|
||||||
wxString input = layout;
|
|
||||||
wxString part;
|
|
||||||
|
|
||||||
// check layout string version
|
|
||||||
part = input.BeforeFirst(wxT('|'));
|
|
||||||
input = input.AfterFirst(wxT('|'));
|
|
||||||
part.Trim(true);
|
|
||||||
part.Trim(false);
|
|
||||||
if (part != wxT("layout1"))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
|
|
||||||
// mark all panes currently managed as docked and hidden
|
|
||||||
int pane_i, pane_count = m_panes.GetCount();
|
|
||||||
for (pane_i = 0; pane_i < pane_count; ++pane_i)
|
|
||||||
m_panes.Item(pane_i).Dock().Hide();
|
|
||||||
|
|
||||||
// clear out the dock array; this will be reconstructed
|
|
||||||
m_docks.Clear();
|
|
||||||
|
|
||||||
// replace escaped characters so we can
|
// replace escaped characters so we can
|
||||||
// split up the string easily
|
// split up the string easily
|
||||||
input.Replace(wxT("\\|"), wxT("\a"));
|
pane_part.Replace(wxT("\\|"), wxT("\a"));
|
||||||
input.Replace(wxT("\\;"), wxT("\b"));
|
pane_part.Replace(wxT("\\;"), wxT("\b"));
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
wxPaneInfo pane;
|
|
||||||
|
|
||||||
wxString pane_part = input.BeforeFirst(wxT('|'));
|
|
||||||
input = input.AfterFirst(wxT('|'));
|
|
||||||
pane_part.Trim(true);
|
|
||||||
|
|
||||||
// if the string is empty, we're done parsing
|
|
||||||
if (pane_part.empty())
|
|
||||||
break;
|
|
||||||
|
|
||||||
|
|
||||||
if (pane_part.Left(9) == wxT("dock_size"))
|
|
||||||
{
|
|
||||||
wxString val_name = pane_part.BeforeFirst(wxT('='));
|
|
||||||
wxString value = pane_part.AfterFirst(wxT('='));
|
|
||||||
|
|
||||||
long dir, layer, row, size;
|
|
||||||
wxString piece = val_name.AfterFirst(wxT('('));
|
|
||||||
piece = piece.BeforeLast(wxT(')'));
|
|
||||||
piece.BeforeFirst(wxT(',')).ToLong(&dir);
|
|
||||||
piece = piece.AfterFirst(wxT(','));
|
|
||||||
piece.BeforeFirst(wxT(',')).ToLong(&layer);
|
|
||||||
piece.AfterFirst(wxT(',')).ToLong(&row);
|
|
||||||
value.ToLong(&size);
|
|
||||||
|
|
||||||
wxDockInfo dock;
|
|
||||||
dock.dock_direction = dir;
|
|
||||||
dock.dock_layer = layer;
|
|
||||||
dock.dock_row = row;
|
|
||||||
dock.size = size;
|
|
||||||
m_docks.Add(dock);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
wxString val_part = pane_part.BeforeFirst(wxT(';'));
|
wxString val_part = pane_part.BeforeFirst(wxT(';'));
|
||||||
pane_part = pane_part.AfterFirst(wxT(';'));
|
pane_part = pane_part.AfterFirst(wxT(';'));
|
||||||
wxString val_name = val_part.BeforeFirst(wxT('='));
|
wxString val_name = val_part.BeforeFirst(wxT('='));
|
||||||
@@ -1064,7 +978,7 @@ bool wxFrameManager::LoadPerspective(const wxString& layout, bool update)
|
|||||||
value.Trim(false);
|
value.Trim(false);
|
||||||
|
|
||||||
if (val_name.empty())
|
if (val_name.empty())
|
||||||
break;
|
return wxEmptyString;
|
||||||
|
|
||||||
if (val_name == wxT("name"))
|
if (val_name == wxT("name"))
|
||||||
pane.name = value;
|
pane.name = value;
|
||||||
@@ -1105,7 +1019,6 @@ bool wxFrameManager::LoadPerspective(const wxString& layout, bool update)
|
|||||||
else {
|
else {
|
||||||
wxFAIL_MSG(wxT("Bad Perspective String"));
|
wxFAIL_MSG(wxT("Bad Perspective String"));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// replace escaped characters so we can
|
// replace escaped characters so we can
|
||||||
// split up the string easily
|
// split up the string easily
|
||||||
@@ -1113,6 +1026,117 @@ bool wxFrameManager::LoadPerspective(const wxString& layout, bool update)
|
|||||||
pane.name.Replace(wxT("\b"), wxT(";"));
|
pane.name.Replace(wxT("\b"), wxT(";"));
|
||||||
pane.caption.Replace(wxT("\a"), wxT("|"));
|
pane.caption.Replace(wxT("\a"), wxT("|"));
|
||||||
pane.caption.Replace(wxT("\b"), wxT(";"));
|
pane.caption.Replace(wxT("\b"), wxT(";"));
|
||||||
|
pane_part.Replace(wxT("\a"), wxT("|"));
|
||||||
|
pane_part.Replace(wxT("\b"), wxT(";"));
|
||||||
|
|
||||||
|
return pane_part;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// SavePerspective() saves all pane information as a single string.
|
||||||
|
// This string may later be fed into LoadPerspective() to restore
|
||||||
|
// all pane settings. This save and load mechanism allows an
|
||||||
|
// exact pane configuration to be saved and restored at a later time
|
||||||
|
|
||||||
|
wxString wxFrameManager::SavePerspective()
|
||||||
|
{
|
||||||
|
wxString result;
|
||||||
|
result.Alloc(500);
|
||||||
|
result = wxT("layout1|");
|
||||||
|
|
||||||
|
int pane_i, pane_count = m_panes.GetCount();
|
||||||
|
for (pane_i = 0; pane_i < pane_count; ++pane_i)
|
||||||
|
{
|
||||||
|
wxPaneInfo& pane = m_panes.Item(pane_i);
|
||||||
|
result += SavePaneInfo(pane)+wxT("|");
|
||||||
|
}
|
||||||
|
|
||||||
|
int dock_i, dock_count = m_docks.GetCount();
|
||||||
|
for (dock_i = 0; dock_i < dock_count; ++dock_i)
|
||||||
|
{
|
||||||
|
wxDockInfo& dock = m_docks.Item(dock_i);
|
||||||
|
|
||||||
|
result += wxString::Format(wxT("dock_size(%d,%d,%d)=%d|"),
|
||||||
|
dock.dock_direction, dock.dock_layer,
|
||||||
|
dock.dock_row, dock.size);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoadPerspective() loads a layout which was saved with SavePerspective()
|
||||||
|
// If the "update" flag parameter is true, the GUI will immediately be updated
|
||||||
|
|
||||||
|
bool wxFrameManager::LoadPerspective(const wxString& layout, bool update)
|
||||||
|
{
|
||||||
|
wxString input = layout;
|
||||||
|
wxString part;
|
||||||
|
|
||||||
|
// check layout string version
|
||||||
|
part = input.BeforeFirst(wxT('|'));
|
||||||
|
input = input.AfterFirst(wxT('|'));
|
||||||
|
part.Trim(true);
|
||||||
|
part.Trim(false);
|
||||||
|
if (part != wxT("layout1"))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// mark all panes currently managed as docked and hidden
|
||||||
|
int pane_i, pane_count = m_panes.GetCount();
|
||||||
|
for (pane_i = 0; pane_i < pane_count; ++pane_i)
|
||||||
|
m_panes.Item(pane_i).Dock().Hide();
|
||||||
|
|
||||||
|
// clear out the dock array; this will be reconstructed
|
||||||
|
m_docks.Clear();
|
||||||
|
|
||||||
|
// replace escaped characters so we can
|
||||||
|
// split up the string easily
|
||||||
|
input.Replace(wxT("\\|"), wxT("\a"));
|
||||||
|
input.Replace(wxT("\\;"), wxT("\b"));
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
wxPaneInfo pane;
|
||||||
|
|
||||||
|
wxString pane_part = input.BeforeFirst(wxT('|'));
|
||||||
|
input = input.AfterFirst(wxT('|'));
|
||||||
|
pane_part.Trim(true);
|
||||||
|
|
||||||
|
// if the string is empty, we're done parsing
|
||||||
|
if (pane_part.empty())
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (pane_part.Left(9) == wxT("dock_size"))
|
||||||
|
{
|
||||||
|
wxString val_name = pane_part.BeforeFirst(wxT('='));
|
||||||
|
wxString value = pane_part.AfterFirst(wxT('='));
|
||||||
|
|
||||||
|
long dir, layer, row, size;
|
||||||
|
wxString piece = val_name.AfterFirst(wxT('('));
|
||||||
|
piece = piece.BeforeLast(wxT(')'));
|
||||||
|
piece.BeforeFirst(wxT(',')).ToLong(&dir);
|
||||||
|
piece = piece.AfterFirst(wxT(','));
|
||||||
|
piece.BeforeFirst(wxT(',')).ToLong(&layer);
|
||||||
|
piece.AfterFirst(wxT(',')).ToLong(&row);
|
||||||
|
value.ToLong(&size);
|
||||||
|
|
||||||
|
wxDockInfo dock;
|
||||||
|
dock.dock_direction = dir;
|
||||||
|
dock.dock_layer = layer;
|
||||||
|
dock.dock_row = row;
|
||||||
|
dock.size = size;
|
||||||
|
m_docks.Add(dock);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Undo our escaping as LoadPaneInfo needs to take an unescaped
|
||||||
|
// name so it can be called by external callers
|
||||||
|
pane_part.Replace(wxT("\a"), wxT("|"));
|
||||||
|
pane_part.Replace(wxT("\b"), wxT(";"));
|
||||||
|
|
||||||
|
while (!pane_part.empty())
|
||||||
|
{
|
||||||
|
pane_part = LoadPaneInfo(pane_part, pane);
|
||||||
|
}
|
||||||
|
|
||||||
wxPaneInfo& p = GetPane(pane.name);
|
wxPaneInfo& p = GetPane(pane.name);
|
||||||
if (!p.IsOk())
|
if (!p.IsOk())
|
||||||
@@ -1122,10 +1146,8 @@ bool wxFrameManager::LoadPerspective(const wxString& layout, bool update)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pane.window = p.window;
|
p.SafeSet(pane);
|
||||||
pane.frame = p.frame;
|
|
||||||
pane.buttons = p.buttons;
|
|
||||||
p = pane;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (update)
|
if (update)
|
||||||
@@ -1134,7 +1156,6 @@ bool wxFrameManager::LoadPerspective(const wxString& layout, bool update)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void wxFrameManager::GetPanePositionsAndSizes(wxDockInfo& dock,
|
void wxFrameManager::GetPanePositionsAndSizes(wxDockInfo& dock,
|
||||||
wxArrayInt& positions,
|
wxArrayInt& positions,
|
||||||
wxArrayInt& sizes)
|
wxArrayInt& sizes)
|
||||||
|
Reference in New Issue
Block a user