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:
Alex Bligh
2006-07-25 11:41:46 +00:00
parent 7947a48ab7
commit 75c8d68f1d
2 changed files with 131 additions and 94 deletions

View File

@@ -192,6 +192,19 @@ public:
}
#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 IsFixed() const { return !HasFlag(optionResizable); }
bool IsResizable() const { return HasFlag(optionResizable); }
@@ -415,6 +428,9 @@ public:
bool DetachPane(wxWindow* window);
wxString SavePaneInfo(wxPaneInfo& pane);
wxString LoadPaneInfo(wxString pane_part, wxPaneInfo &pane);
wxString SavePerspective();
bool LoadPerspective(const wxString& perspective,

View File

@@ -928,24 +928,9 @@ static wxString EscapeDelimiters(const wxString& s)
return result;
}
// 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 wxFrameManager::SavePaneInfo(wxPaneInfo& pane)
{
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 += wxT("name=");
wxString result = wxT("name=");
result += EscapeDelimiters(pane.name);
result += wxT(";");
@@ -969,90 +954,19 @@ wxString wxFrameManager::SavePerspective()
result += wxString::Format(wxT("floaty=%d;"), pane.floating_pos.y);
result += wxString::Format(wxT("floatw=%d;"), pane.floating_size.x);
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;
}
// 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)
// Load a "pane" with the pane infor settings in pane_part; return the remainder of the
// string
wxString wxFrameManager::LoadPaneInfo(wxString pane_part, wxPaneInfo &pane)
{
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"));
pane_part.Replace(wxT("\\|"), wxT("\a"));
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(';'));
pane_part = pane_part.AfterFirst(wxT(';'));
wxString val_name = val_part.BeforeFirst(wxT('='));
@@ -1064,7 +978,7 @@ bool wxFrameManager::LoadPerspective(const wxString& layout, bool update)
value.Trim(false);
if (val_name.empty())
break;
return wxEmptyString;
if (val_name == wxT("name"))
pane.name = value;
@@ -1105,7 +1019,6 @@ bool wxFrameManager::LoadPerspective(const wxString& layout, bool update)
else {
wxFAIL_MSG(wxT("Bad Perspective String"));
}
}
// replace escaped characters so we can
// split up the string easily
@@ -1113,6 +1026,117 @@ bool wxFrameManager::LoadPerspective(const wxString& layout, bool update)
pane.name.Replace(wxT("\b"), wxT(";"));
pane.caption.Replace(wxT("\a"), 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);
if (!p.IsOk())
@@ -1122,10 +1146,8 @@ bool wxFrameManager::LoadPerspective(const wxString& layout, bool update)
return false;
}
pane.window = p.window;
pane.frame = p.frame;
pane.buttons = p.buttons;
p = pane;
p.SafeSet(pane);
}
if (update)
@@ -1134,7 +1156,6 @@ bool wxFrameManager::LoadPerspective(const wxString& layout, bool update)
return true;
}
void wxFrameManager::GetPanePositionsAndSizes(wxDockInfo& dock,
wxArrayInt& positions,
wxArrayInt& sizes)