📄 layoutmanager.cpp
字号:
void wxLayoutManager::UndockWindow( wxDockWindowBase * pDockWindow, bool noShowOperation ) {
wxASSERT(pDockWindow);
// already undocked?
if( !pDockWindow->IsDocked() ) {
return;
}
// undock a window
wxDockPanel * pClient = pDockWindow->GetDockPanel();
wxASSERT(pClient);
wxDockHost * pDockHost = pClient->GetDockedHost();
wxASSERT(pDockHost);
pDockHost->UndockPanel( pClient );
pDockWindow->Layout();
if( !noShowOperation ) {
pDockWindow->ActualShow( true );
pDockWindow->SetDocked( false );
}
UpdateAllHosts( true );
}
void wxLayoutManager::OnSize() {
// callback event generated by the a host size change
UpdateAllHosts( true );
}
void wxLayoutManager::OnMove() {
// XXX: no longer used
}
void wxLayoutManager::OnUpdateLayout() {
UpdateAllHosts( false );
}
void wxLayoutManager::UpdateAllHosts( bool WXUNUSED(sizeChange), wxDockHost * WXUNUSED(pIgnoreHost) ) {
// NOTE (mandrav#1#): Moved event firing at the end of this function
wxLayoutAlgorithm layout;
wxMDIParentFrame * pMDIFrame = wxDynamicCast( pOwnerWindow_, wxMDIParentFrame );
if( pMDIFrame ) {
// layout within an MDI frame
layout.LayoutMDIFrame( pMDIFrame );
}
else {
// layout within an normal frame/or standard wxWindow
layout.LayoutWindow( pOwnerWindow_, pAutoLayoutClientWindow_ );
}
// generate an event
wxCommandEvent e( wxEVT_LAYOUT_CHANGED );
e.SetEventObject( this );
wxEvtHandler * pFrameEventHandler = pOwnerWindow_->GetEventHandler();
wxASSERT( pFrameEventHandler );
pFrameEventHandler->ProcessEvent( e );
}
wxDockHost * wxLayoutManager::findDockHost( const wxString& name ) {
// look for a particular host
for( DockHostList::Node *node = dockHosts_.GetFirst(); node; node = node->GetNext() ) {
wxDockHost * pDockHost = node->GetData();
if( pDockHost->GetName() == name ) {
// found
return pDockHost;
}
}
// not found
return NULL;
}
wxDockWindowBase * wxLayoutManager::findDockWindow( const wxString& name ) {
// look for a particular window
for( DockWindowList::Node *node = dockWindows_.GetFirst(); node; node = node->GetNext() ) {
wxDockWindowBase * pDockWindow = node->GetData();
if( pDockWindow->GetName() == name ) {
// found
return pDockWindow;
}
}
// not found
return NULL;
}
void wxLayoutManager::settingsChanged() {
// update size of all hosts
for( DockHostList::Node *node = dockHosts_.GetFirst(); node; node = node->GetNext() ) {
wxDockHost * pDockHost = node->GetData();
pDockHost->SettingsChanged();
}
}
bool wxLayoutManager::SaveToStream( wxOutputStream &stream ) {
// version
WriteString( stream, STREAM_VERSION );
// windows
WriteString( stream, wxT("<layout>") );
int winCount = dockWindows_.GetCount();
stream.Write( &winCount, sizeof( winCount ) );
for( DockWindowList::Node *node = dockWindows_.GetFirst(); node; node = node->GetNext() ) {
wxDockWindowBase * pDockWindow = node->GetData();
// name
WriteString( stream, pDockWindow->GetName() );
// undocked size
wxRect size = pDockWindow->GetRect();
stream.Write( &size.x, sizeof( size.x ) );
stream.Write( &size.y, sizeof( size.y ) );
stream.Write( &size.width, sizeof( size.width ) );
stream.Write( &size.height, sizeof( size.height ) );
// attributes
bool isShown = pDockWindow->IsShown();
stream.Write( &isShown, sizeof( isShown ) );
bool isDocked = pDockWindow->IsDocked();
stream.Write( &isDocked, sizeof( isDocked ) );
// area taken
wxDockPanel * pDockPanel = pDockWindow->GetDockPanel();
wxASSERT(pDockPanel);
int area = pDockPanel->GetArea();
stream.Write( &area, sizeof( area ) );
// docking info
HostInfo &hi = pDockWindow->GetDockingInfo();
if( hi.pHost ) {
WriteString( stream, hi.pHost->GetName() );
}
else {
WriteString( stream, wxT("<nohost>") );
}
}
// write out hosts
int hostCount = dockHosts_.GetCount();
stream.Write( &hostCount, sizeof( hostCount ) );
for( DockHostList::Node *hnode = dockHosts_.GetFirst(); hnode; hnode = hnode->GetNext() ) {
wxDockHost * pDockHost = hnode->GetData();
// name
WriteString( stream, pDockHost->GetName() );
// area size
int areaSize = pDockHost->GetAreaSize();
stream.Write( &areaSize, sizeof( areaSize ) );
// panel size
int panelArea = pDockHost->GetPanelArea();
stream.Write( &panelArea, sizeof( panelArea ) );
// docked windows
const DockWindowList & dwl = pDockHost->GetDockWindowList();
int winCount = dwl.GetCount();
stream.Write( &winCount, sizeof( winCount ) );
for( DockWindowList::Node *lnode = dwl.GetFirst(); lnode; lnode = lnode->GetNext() ) {
wxDockWindowBase * pDockWindow = lnode->GetData();
// name
WriteString( stream, pDockWindow->GetName() );
}
}
return true;
}
bool wxLayoutManager::LoadFromStream( wxInputStream &stream ) {
int i;
// version
wxString version = ReadString( stream );
if( version != STREAM_VERSION ) {
return false;
}
wxString layoutTag = ReadString( stream );
if( layoutTag == wxT("<layout>") ) {
DockPanelList lockedPanels;
// undock all windows
for( DockWindowList::Node *node = dockWindows_.GetFirst(); node; node = node->GetNext() ) {
wxDockWindowBase * pDockWindow = node->GetData();
wxASSERT( pDockWindow );
pDockWindow->Remove();
}
// read in windows
int winCount = 0;
stream.Read( &winCount, sizeof( winCount ) );
for( i=0; i<winCount; i++ ) {
// name
wxString name = ReadString( stream );
// undocked size
wxRect size;
stream.Read( &size.x, sizeof( size.x ) );
stream.Read( &size.y, sizeof( size.y ) );
stream.Read( &size.width, sizeof( size.width ) );
stream.Read( &size.height, sizeof( size.height ) );
// attributes
bool isShown = false;
stream.Read( &isShown, sizeof( isShown ) );
bool isDocked = false;
stream.Read( &isDocked, sizeof( isDocked ) );
// area taken
int area = 0;
stream.Read( &area, sizeof( area ) );
// docking info
wxString host = ReadString( stream );
// find window and apply
wxDockWindowBase * pDockWindow = findDockWindow( name );
if( pDockWindow ) {
pDockWindow->SetSize( size );
pDockWindow->SetDocked( isDocked );
wxDockPanel * pDockPanel = pDockWindow->GetDockPanel();
wxASSERT( pDockPanel );
// panel area
pDockPanel->SetArea( area );
pDockPanel->LockAreaValue( true );
lockedPanels.Append( pDockPanel );
// docking info
wxDockHost * pDockHost = findDockHost( host );
if( pDockHost && isDocked ) {
// was docked
HostInfo hi;
hi = pDockHost;
pDockWindow->SetDockingInfo( hi );
}
else {
// was not docked
if( isShown ) {
pDockWindow->Appear();
}
pDockWindow->ClearDockingInfo();
}
}
else {
// could not find window
}
}
DockHostList lockedHosts;
// read in hosts
int hostCount = 0;
stream.Read( &hostCount, sizeof( hostCount ) );
for( i=0; i<hostCount; i++ ) {
// name
wxString name = ReadString( stream );
// area size
int areaSize = 0;
stream.Read( &areaSize, sizeof( areaSize ) );
// panel area
int panelArea = 0;
stream.Read( &panelArea, sizeof( panelArea ) );
// find host and apply
wxDockHost * pDockHost = findDockHost( name );
if( pDockHost ) {
// areas
pDockHost->SetAreaSize( areaSize );
pDockHost->SetPanelArea( panelArea );
pDockHost->LockPanelValue( true );
lockedHosts.Append( pDockHost );
// docked windows
int winCount = 0;
stream.Read( &winCount, sizeof( winCount ) );
for( int i=0; i<winCount; i++ ) {
// name
wxString name = ReadString( stream );
// find window and dock
wxDockWindowBase * pDockWindow = findDockWindow( name );
if( pDockWindow ) {
HostInfo hi;
hi = pDockHost;
DockWindow( pDockWindow, hi );
}
else {
// could not find window
}
}
}
else {
// could not find host
}
}
UpdateAllHosts( true );
// unlock all panels
for( DockPanelList::Node *pnode = lockedPanels.GetFirst(); pnode; pnode = pnode->GetNext() ) {
wxDockPanel * pDockPanel = pnode->GetData();
wxASSERT( pDockPanel );
pDockPanel->LockAreaValue( false );
}
// unlock all hosts
for( DockHostList::Node *hnode = lockedHosts.GetFirst(); hnode; hnode = hnode->GetNext() ) {
wxDockHost * pDockHost = hnode->GetData();
wxASSERT( pDockHost );
pDockHost->LockPanelValue( false );
}
} // end <layout>
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -