1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright : (C) 2008 by Eran Ifrah
// file name : dockablepanemenumanager.cpp
//
// -------------------------------------------------------------------------
// A
// _____ _ _ _ _
// / __ \ | | | | (_) |
// | / \/ ___ __| | ___| | _| |_ ___
// | | / _ \ / _ |/ _ \ | | | __/ _ )
// | \__/\ (_) | (_| | __/ |___| | || __/
// \____/\___/ \__,_|\___\_____/_|\__\___|
//
// F i l e
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
#include "dockablepanemenumanager.h"
#include <wx/app.h>
#include <wx/aui/aui.h>
#include <wx/control.h>
#include <wx/log.h>
#include <wx/xrc/xmlres.h>
void DockablePaneMenuManager::HackShowPane(wxAuiPaneInfo& pane_info, wxAuiManager* pAui)
{
if(pane_info.IsOk() && pAui) {
pane_info.MinSize(pane_info.best_size); // saved while hiding
pane_info.Show();
pAui->Update();
pane_info.MinSize(10, 5); // so it can't disappear if undocked
pAui->Update();
}
}
void DockablePaneMenuManager::HackHidePane(bool commit, wxAuiPaneInfo& pane_info, wxAuiManager* pAui)
{
if(pane_info.IsOk() && pAui) {
int width = 0;
int height = 0;
pane_info.window->GetClientSize(&width, &height);
pane_info.BestSize(width, height); // save for later subsequent show
pane_info.Hide();
if(commit) {
pAui->Update();
}
}
}
DockablePaneMenuManager::DockablePaneMenuManager(wxAuiManager* aui)
: m_aui(aui)
{
}
DockablePaneMenuManager::~DockablePaneMenuManager() {}
void DockablePaneMenuManager::RemoveMenu(const wxString& name)
{
int itemId = wxXmlResource::GetXRCID(name.c_str());
std::map<int, wxString>::iterator iter = m_id2nameMap.find(itemId);
if(iter != m_id2nameMap.end()) {
m_id2nameMap.erase(iter);
}
}
void DockablePaneMenuManager::AddMenu(const wxString& name)
{
int itemId = wxXmlResource::GetXRCID(name.c_str());
m_id2nameMap[itemId] = name;
}
wxString DockablePaneMenuManager::NameById(int id)
{
std::map<int, wxString>::iterator iter = m_id2nameMap.find(id);
if(iter != m_id2nameMap.end()) {
return iter->second;
}
return wxEmptyString;
}
void DockablePaneMenuManager::OnDockpaneMenuItem(wxCommandEvent& e)
{
wxString name = NameById(e.GetId());
wxAuiPaneInfo& info = m_aui->GetPane(name);
if(info.IsOk()) {
if(e.IsChecked()) {
HackShowPane(info, m_aui);
} else {
HackHidePane(true, info, m_aui);
}
}
}
void DockablePaneMenuManager::OnDockpaneMenuItemUI(wxUpdateUIEvent& e)
{
wxString name = NameById(e.GetId());
wxAuiPaneInfo& info = m_aui->GetPane(name);
if(info.IsOk()) {
if(info.IsShown()) {
e.Check(true);
} else {
e.Check(false);
}
}
}
wxArrayString DockablePaneMenuManager::GetDeatchedPanesList()
{
wxArrayString arr;
std::map<int, wxString>::iterator iter = m_id2nameMap.begin();
for(; iter != m_id2nameMap.end(); iter++) {
arr.Add(iter->second);
}
return arr;
}
bool DockablePaneMenuManager::IsPaneDetached(const wxString& name)
{
std::map<int, wxString>::iterator iter = m_id2nameMap.begin();
for(; iter != m_id2nameMap.end(); iter++) {
if(iter->second == name) {
return true;
}
}
return false;
}
|