+ // if we have a frame, destroy it
+ if (paneInfo.frame)
+ {
+ paneInfo.frame->Destroy();
+ paneInfo.frame = NULL;
+ }
+
+ // now we need to either destroy or hide the pane
+ if (paneInfo.IsDestroyOnClose())
+ {
+ wxWindow * window = paneInfo.window;
+ DetachPane(window);
+ if (window)
+ {
+ window->Destroy();
+ }
+ }
+ else
+ {
+ paneInfo.Hide();
+ }
+}
+
+void wxAuiManager::MaximizePane(wxAuiPaneInfo& paneInfo)
+{
+ int i, pane_count;
+
+ // un-maximize and hide all other panes
+ for (i = 0, pane_count = m_panes.GetCount(); i < pane_count; ++i)
+ {
+ wxAuiPaneInfo& p = m_panes.Item(i);
+ if (!p.IsToolbar() && !p.IsFloating())
+ {
+ p.Restore();
+
+ // save hidden state
+ p.SetFlag(wxAuiPaneInfo::savedHiddenState,
+ p.HasFlag(wxAuiPaneInfo::optionHidden));
+
+ // hide the pane, because only the newly
+ // maximized pane should show
+ p.Hide();
+ }
+ }
+
+ // mark ourselves maximized
+ paneInfo.Maximize();
+ paneInfo.Show();
+ m_hasMaximized = true;
+
+ // last, show the window
+ if (paneInfo.window && !paneInfo.window->IsShown())
+ {
+ paneInfo.window->Show(true);
+ }
+}
+
+void wxAuiManager::RestorePane(wxAuiPaneInfo& paneInfo)
+{
+ int i, pane_count;
+
+ // restore all the panes
+ for (i = 0, pane_count = m_panes.GetCount(); i < pane_count; ++i)
+ {
+ wxAuiPaneInfo& p = m_panes.Item(i);
+ if (!p.IsToolbar() && !p.IsFloating())
+ {
+ p.SetFlag(wxAuiPaneInfo::optionHidden,
+ p.HasFlag(wxAuiPaneInfo::savedHiddenState));
+ }
+ }
+
+ // mark ourselves non-maximized
+ paneInfo.Restore();
+ m_hasMaximized = false;
+
+ // last, show the window
+ if (paneInfo.window && !paneInfo.window->IsShown())
+ {
+ paneInfo.window->Show(true);
+ }
+}
+
+void wxAuiManager::RestoreMaximizedPane()
+{
+ int i, pane_count;
+
+ // restore all the panes
+ for (i = 0, pane_count = m_panes.GetCount(); i < pane_count; ++i)
+ {
+ wxAuiPaneInfo& p = m_panes.Item(i);
+ if (p.IsMaximized())
+ {
+ RestorePane(p);
+ break;
+ }
+ }
+}
+
+// EscapeDelimiters() changes ";" into "\;" and "|" into "\|"
+// in the input string. This is an internal functions which is
+// used for saving perspectives
+static wxString EscapeDelimiters(const wxString& s)
+{
+ wxString result;
+ result.Alloc(s.length());
+ const wxChar* ch = s.c_str();
+ while (*ch)
+ {
+ if (*ch == wxT(';') || *ch == wxT('|'))
+ result += wxT('\\');
+ result += *ch;
+ ++ch;
+ }
+ return result;
+}
+
+wxString wxAuiManager::SavePaneInfo(wxAuiPaneInfo& pane)
+{
+ wxString result = wxT("name=");
+ result += EscapeDelimiters(pane.name);
+ result += wxT(";");
+
+ result += wxT("caption=");
+ result += EscapeDelimiters(pane.caption);
+ result += wxT(";");
+
+ result += wxString::Format(wxT("state=%u;"), pane.state);
+ result += wxString::Format(wxT("dir=%d;"), pane.dock_direction);
+ result += wxString::Format(wxT("layer=%d;"), pane.dock_layer);
+ result += wxString::Format(wxT("row=%d;"), pane.dock_row);
+ result += wxString::Format(wxT("pos=%d;"), pane.dock_pos);
+ result += wxString::Format(wxT("prop=%d;"), pane.dock_proportion);
+ result += wxString::Format(wxT("bestw=%d;"), pane.best_size.x);
+ result += wxString::Format(wxT("besth=%d;"), pane.best_size.y);
+ result += wxString::Format(wxT("minw=%d;"), pane.min_size.x);
+ result += wxString::Format(wxT("minh=%d;"), pane.min_size.y);
+ result += wxString::Format(wxT("maxw=%d;"), pane.max_size.x);
+ result += wxString::Format(wxT("maxh=%d;"), pane.max_size.y);
+ result += wxString::Format(wxT("floatx=%d;"), pane.floating_pos.x);
+ 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);
+
+ return result;
+}
+
+// Load a "pane" with the pane infor settings in pane_part
+void wxAuiManager::LoadPaneInfo(wxString pane_part, wxAuiPaneInfo &pane)
+{
+ // replace escaped characters so we can
+ // split up the string easily
+ pane_part.Replace(wxT("\\|"), wxT("\a"));
+ pane_part.Replace(wxT("\\;"), wxT("\b"));
+
+ while(1)
+ {
+ wxString val_part = pane_part.BeforeFirst(wxT(';'));
+ pane_part = pane_part.AfterFirst(wxT(';'));
+ wxString val_name = val_part.BeforeFirst(wxT('='));
+ wxString value = val_part.AfterFirst(wxT('='));
+ val_name.MakeLower();
+ val_name.Trim(true);
+ val_name.Trim(false);
+ value.Trim(true);
+ value.Trim(false);
+
+ if (val_name.empty())
+ break;
+
+ if (val_name == wxT("name"))
+ pane.name = value;
+ else if (val_name == wxT("caption"))
+ pane.caption = value;
+ else if (val_name == wxT("state"))
+ pane.state = (unsigned int)wxAtoi(value.c_str());
+ else if (val_name == wxT("dir"))
+ pane.dock_direction = wxAtoi(value.c_str());
+ else if (val_name == wxT("layer"))
+ pane.dock_layer = wxAtoi(value.c_str());
+ else if (val_name == wxT("row"))
+ pane.dock_row = wxAtoi(value.c_str());
+ else if (val_name == wxT("pos"))
+ pane.dock_pos = wxAtoi(value.c_str());
+ else if (val_name == wxT("prop"))
+ pane.dock_proportion = wxAtoi(value.c_str());
+ else if (val_name == wxT("bestw"))
+ pane.best_size.x = wxAtoi(value.c_str());
+ else if (val_name == wxT("besth"))
+ pane.best_size.y = wxAtoi(value.c_str());
+ else if (val_name == wxT("minw"))
+ pane.min_size.x = wxAtoi(value.c_str());
+ else if (val_name == wxT("minh"))
+ pane.min_size.y = wxAtoi(value.c_str());
+ else if (val_name == wxT("maxw"))
+ pane.max_size.x = wxAtoi(value.c_str());
+ else if (val_name == wxT("maxh"))
+ pane.max_size.y = wxAtoi(value.c_str());
+ else if (val_name == wxT("floatx"))
+ pane.floating_pos.x = wxAtoi(value.c_str());
+ else if (val_name == wxT("floaty"))
+ pane.floating_pos.y = wxAtoi(value.c_str());
+ else if (val_name == wxT("floatw"))
+ pane.floating_size.x = wxAtoi(value.c_str());
+ else if (val_name == wxT("floath"))
+ pane.floating_size.y = wxAtoi(value.c_str());
+ else {
+ wxFAIL_MSG(wxT("Bad Perspective String"));
+ }
+ }
+
+ // replace escaped characters so we can
+ // split up the string easily
+ pane.name.Replace(wxT("\a"), wxT("|"));
+ 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;
+}
+
+
+// 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 wxAuiManager::SavePerspective()
+{
+ wxString result;
+ result.Alloc(500);
+ result = wxT("layout2|");
+
+ int pane_i, pane_count = m_panes.GetCount();
+ for (pane_i = 0; pane_i < pane_count; ++pane_i)
+ {
+ wxAuiPaneInfo& 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)
+ {
+ wxAuiDockInfo& 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;
+}