The miniframe class CPaneFrameWnd contains bug in smart docking algorithm! This class used in MFC as miniframe for floating panes and can dock its to parent frame dock sites or to tabbed panes. It works fine when all panes can be docked to main frame only, but when panes docked to the child frame in MDI applications this class have a bug. Steps to reproduce the bug:
- Undock some pane to float state.
- Save docking state in MDI child frame:
GetDockingManager()->SaveState(...)
- Restore docking state for this MDI child frame:
GetDockingManager()->LoadState(...); GetDockingManager()->SetDockState();
- And try to dock this pane to same frame side by the mouse.
- You can't this. The pane are moved by mouse to frame side but NOT DOCKED.
Bug in CPaneFrameWnd class source. In many places class uses code m_pDockManager != NULL ? m_pDockManager : afxGlobalUtils.GetDockingManager(GetParent());
for access its dockmanager.
But in some places of class this code looks like m_pDockManager != NULL ? m_pDockManager : afxGlobalUtils.GetDockingManager(this);
. And this is reason of the bug - global function afxGlobalUtils.GetDockingManager() can't get dock manager from this
pointer and try to get it from parent window of this
pointer. It looks like pManager != NULL ? pManager : GetDockingManager(pWnd->GetParent());
. But class CPaneFrameWnd have INLINE NONVIRTUAL GetParent() method that can't be accessed by afxGlobalUtils.GetDockingManager(). So, after some recursions afxGlobalUtils.GetDockingManager() returns dockmanager for MAIN app frame! And of course this dockmanager is not same as docmanager for MDI child frame.
Single right solution is to change all m_pDockManager != NULL ? m_pDockManager : afxGlobalUtils.GetDockingManager(this);
to m_pDockManager != NULL ? m_pDockManager : afxGlobalUtils.GetDockingManager(GetParent());
in CPaneFrameWnd source (afxpaneframewnd.cpp file).
But this is requires patch to MFC code. And all of us knows how Microsoft lazy.
May be somebody knows how to fix this bug in current MFC release ?