manager.cpp
来自「A*算法 A*算法 A*算法 A*算法A*算法A*算法」· C++ 代码 · 共 2,037 行 · 第 1/5 页
CPP
2,037 行
{ if (m_frame->ProcessEvent(event)) return; } ProcessEvent(event);}// SetArtProvider() instructs wxFrameManager to use the// specified art provider for all drawing calls. This allows// plugable look-and-feel featuresvoid wxFrameManager::SetArtProvider(wxDockArt* art_provider){ // delete the last art provider, if any delete m_art; // assign the new art provider m_art = art_provider;}bool wxFrameManager::AddPane(wxWindow* window, const wxPaneInfo& pane_info){ // check if the pane has a valid window if (!window) return false; // check if the pane already exists if (GetPane(pane_info.window).IsOk()) return false; m_panes.Add(pane_info); wxPaneInfo& pinfo = m_panes.Last(); // set the pane window pinfo.window = window; // if the pane's name identifier is blank, create a random string if (pinfo.name.IsEmpty()) { pinfo.name.Printf(wxT("%08x%08x%08x%08x"), ((unsigned long)pinfo.window) & 0xffffffff, (unsigned int)time(NULL), (unsigned int)clock(), m_panes.GetCount()); } // set initial proportion (if not already set) if (pinfo.dock_proportion == 0) pinfo.dock_proportion = 100000; if (pinfo.HasCloseButton() && pinfo.buttons.size() == 0) { wxPaneButton button; button.button_id = wxPaneInfo::buttonClose; pinfo.buttons.Add(button); } if (pinfo.best_size == wxDefaultSize && pinfo.window) { pinfo.best_size = pinfo.window->GetClientSize(); if (pinfo.window->IsKindOf(CLASSINFO(wxToolBar))) { // GetClientSize() doesn't get the best size for // a toolbar under some newer versions of wxWidgets, // so use GetBestSize() pinfo.best_size = pinfo.window->GetBestSize(); // for some reason, wxToolBar::GetBestSize() is returning // a size that is a pixel shy of the correct amount. // I believe this to be the correct action, until // wxToolBar::GetBestSize() is fixed. Is this assumption // correct? pinfo.best_size.y++; } if (pinfo.min_size != wxDefaultSize) { if (pinfo.best_size.x < pinfo.min_size.x) pinfo.best_size.x = pinfo.min_size.x; if (pinfo.best_size.y < pinfo.min_size.y) pinfo.best_size.y = pinfo.min_size.y; } } return true;}bool wxFrameManager::AddPane(wxWindow* window, int direction, const wxString& caption){ wxPaneInfo pinfo; pinfo.Caption(caption); switch (direction) { case wxTOP: pinfo.Top(); break; case wxBOTTOM: pinfo.Bottom(); break; case wxLEFT: pinfo.Left(); break; case wxRIGHT: pinfo.Right(); break; case wxCENTER: pinfo.CenterPane(); break; } return AddPane(window, pinfo);}bool wxFrameManager::InsertPane(wxWindow* window, const wxPaneInfo& pane_info, int insert_level){ // shift the panes around, depending on the insert level switch (insert_level) { case wxAUI_INSERT_PANE: DoInsertPane(m_panes, pane_info.dock_direction, pane_info.dock_layer, pane_info.dock_row, pane_info.dock_pos); break; case wxAUI_INSERT_ROW: DoInsertDockRow(m_panes, pane_info.dock_direction, pane_info.dock_layer, pane_info.dock_row); break; case wxAUI_INSERT_DOCK: DoInsertDockLayer(m_panes, pane_info.dock_direction, pane_info.dock_layer); break; } // if the window already exists, we are basically just moving/inserting the // existing window. If it doesn't exist, we need to add it and insert it wxPaneInfo& existing_pane = GetPane(window); if (!existing_pane.IsOk()) { return AddPane(window, pane_info); } else { if (pane_info.IsFloating()) { existing_pane.Float(); if (pane_info.floating_pos != wxDefaultPosition) existing_pane.FloatingPosition(pane_info.floating_pos); if (pane_info.floating_size != wxDefaultSize) existing_pane.FloatingSize(pane_info.floating_size); } else { existing_pane.Direction(pane_info.dock_direction); existing_pane.Layer(pane_info.dock_layer); existing_pane.Row(pane_info.dock_row); existing_pane.Position(pane_info.dock_pos); } } return true;} bool wxFrameManager::DetachPane(wxWindow* window){ int i, count; for (i = 0, count = m_panes.GetCount(); i < count; ++i) { wxPaneInfo& p = m_panes.Item(i); if (p.window == window) { if (p.frame) { // we have a floating frame which is being detached. We need to // reparent it to m_frame and destroy the floating frame // reduce flicker p.window->SetSize(1,1); p.frame->Show(false); // reparent to m_frame and destroy the pane p.window->Reparent(m_frame); p.frame->SetSizer(NULL); p.frame->Destroy(); p.frame = NULL; } m_panes.RemoveAt(i); return true; } } return false;}// EscapeDelimiters() changes ";" into "\;" and "|" into "\|"// in the input string. This is an internal functions which is// used for saving perspectivesstatic 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;}// 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 timewxString 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 += 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); 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 updatedbool 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.IsEmpty()) 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('=')); 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.IsEmpty()) 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(";")); wxPaneInfo& p = GetPane(pane.name); if (!p.IsOk()) { // the pane window couldn't be found // in the existing layout return false; } pane.window = p.window; pane.frame = p.frame;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?