⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bcgpbarcontainer.cpp

📁 远程网络监视程序的源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
// BCGBarContainer.cpp: implementation of the CBCGPBarContainer class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "BCGPBarContainer.h"

#include "BCGPDockingControlBar.h"
#include "BCGPBaseTabbedBar.h"
#include "BCGPSlider.h"
#include "BCGPMiniFrameWnd.h"

#include "BCGPBarContainerManager.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

IMPLEMENT_DYNAMIC(CBCGPBarContainer, CObject)

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CBCGPBarContainer::CBCGPBarContainer(CBCGPBarContainerManager* pManager,
									 CBCGPDockingControlBar* pLeftBar, 
									 CBCGPDockingControlBar* pRightBar, 
									 CBCGPSlider* pSlider) : 
									m_pContainerManager (pManager),	
									m_pBarLeftTop (pLeftBar), 
									m_pBarRightBottom (pRightBar),
									m_pSlider (pSlider), 
									m_pLeftContainer (NULL), 
									m_pRightContainer (NULL),
									m_pParentContainer (NULL), 
									m_dwRefCount (0)
{
	m_nSavedLeftBarID			= (UINT)-1;
	m_nSavedRightBarID			= (UINT)-1;
	m_nSavedSliderID			= (UINT)-1;	
	m_bSavedSliderVisibility	= FALSE;
	m_rectSavedSliderRect.SetRectEmpty ();

	m_dwRecentSliderStyle = 0;
	m_rectRecentSlider.SetRectEmpty ();

	m_nRecentPercent = 50;
	m_bIsRecentSliderHorz = FALSE;
}
//-----------------------------------------------------------------------------------//
CBCGPBarContainer::~CBCGPBarContainer()
{
	CleanUp ();
}
//-----------------------------------------------------------------------------------//
void CBCGPBarContainer::CleanUp ()
{
	if (m_pLeftContainer != NULL)
	{
		m_pLeftContainer->CleanUp ();
		delete m_pLeftContainer;
		m_pLeftContainer = NULL;
	}

	if (m_pRightContainer != NULL)
	{
		m_pRightContainer->CleanUp ();
		delete m_pRightContainer;
		m_pRightContainer = NULL;
	}

	if (m_pSlider != NULL && !m_pSlider->IsDefault () && 
		m_pSlider->GetSafeHwnd () != NULL)
	{
		m_pSlider->DestroyWindow ();
		m_pSlider = NULL;
	}
}
//-----------------------------------------------------------------------------------//
int CBCGPBarContainer::GetResizeStep () const
{
	ASSERT_VALID (this);

	int nStep = -1;
	
	if (m_pBarLeftTop != NULL)
	{
		nStep = m_pBarLeftTop->GetResizeStep ();
	}

	if (m_pBarRightBottom != NULL)
	{
		nStep = max (nStep, m_pBarRightBottom->GetResizeStep ());
	}

	if (m_pLeftContainer != NULL)
	{
		nStep = m_pLeftContainer->GetResizeStep ();
	}

	if (m_pRightContainer != NULL)
	{
		nStep = max (nStep, m_pRightContainer->GetResizeStep ());
	}
	
	return nStep;
}
//-----------------------------------------------------------------------------------//
void CBCGPBarContainer::GetWindowRect (CRect& rect, BOOL bIgnoreVisibility) const
{
	ASSERT_VALID (this);
	CRect rectLeft;
	CRect rectRight;
	CRect rectContainer;

	rect.SetRectEmpty ();
	rectLeft.SetRectEmpty ();
	rectRight.SetRectEmpty ();

	// VCheck 
	BOOL bAutoHideMode = m_pContainerManager->IsAutoHideMode ();

	if (m_pBarLeftTop != NULL && (m_pBarLeftTop->IsBarVisible () || bIgnoreVisibility || bAutoHideMode))
	{
		m_pBarLeftTop->GetWindowRect (rectLeft);
		if (rectLeft.IsRectEmpty ())
		{
			CSize sz; 
			m_pBarLeftTop->GetMinSize (sz);

			if (rectLeft.Width () == 0)
			{
				rectLeft.InflateRect (0, 0, sz.cx, 0);
			}
			
			if (rectLeft.Height () == 0)
			{
				rectLeft.InflateRect (0, 0, 0, sz.cy);
			}

		}
	}

	if (m_pBarRightBottom != NULL && (m_pBarRightBottom->IsBarVisible () || bIgnoreVisibility || bAutoHideMode))
	{
		m_pBarRightBottom->GetWindowRect (rectRight);
		if (rectRight.IsRectEmpty ())
		{
			CSize sz; 
			m_pBarRightBottom->GetMinSize (sz);
			
			if (rectRight.Width () == 0)
			{
				rectRight.InflateRect (0, 0, sz.cx, 0);
			}
			
			if (rectRight.Height () == 0)
			{
				rectRight.InflateRect (0, 0, 0, sz.cy);
			}
		}
	}

	rect.UnionRect (rectLeft, rectRight);

	if (m_pLeftContainer != NULL && (m_pLeftContainer->IsContainerVisible () || bIgnoreVisibility || bAutoHideMode))
	{
		m_pLeftContainer->GetWindowRect (rectContainer);
		rect.UnionRect (rect, rectContainer);
	}

	if (m_pRightContainer != NULL && (m_pRightContainer->IsContainerVisible () || bIgnoreVisibility || bAutoHideMode))
	{
		m_pRightContainer->GetWindowRect (rectContainer);
		rect.UnionRect (rect, rectContainer);
	}
}
//-----------------------------------------------------------------------------------//
void CBCGPBarContainer::GetMinSize (CSize& size) const
{
	ASSERT_VALID (this);
	ASSERT (m_pContainerManager != NULL);

	CSize minSizeLeft (0, 0);
	CSize minSizeRight (0, 0);
	size.cx = size.cy = 0;

	BOOL bAutoHideMode = m_pContainerManager->IsAutoHideMode ();

	// VCheck
	if (m_pBarLeftTop != NULL && (m_pBarLeftTop->IsBarVisible () || bAutoHideMode))
	{
		m_pBarLeftTop->GetMinSize (minSizeLeft);
	}
	
	if (m_pBarRightBottom != NULL && (m_pBarRightBottom->IsBarVisible () || bAutoHideMode))
	{
		m_pBarRightBottom->GetMinSize (minSizeRight);
	}

	CSize sizeLeftContainer (0, 0);
	if (m_pLeftContainer != NULL && (m_pLeftContainer->IsContainerVisible () || bAutoHideMode))
	{
		m_pLeftContainer->GetMinSize (sizeLeftContainer);
	}

	CSize sizeRightContainer (0, 0);
	if (m_pRightContainer != NULL && (m_pRightContainer->IsContainerVisible () || bAutoHideMode))
	{
		m_pRightContainer->GetMinSize (sizeRightContainer);
	}

	if (m_pSlider != NULL && (m_pSlider->IsBarVisible () || bAutoHideMode))
	{
		if (IsSliderHorz ())
		{
			size.cx = max (minSizeLeft.cx, minSizeRight.cx);
			size.cx = max (sizeLeftContainer.cx, size.cx);
			size.cx = max (sizeRightContainer.cx, size.cx);
			size.cy = minSizeLeft.cy + minSizeRight.cy + sizeLeftContainer.cy + 
						sizeRightContainer.cy + m_pSlider->GetWidth ();
		}
		else
		{
			size.cy = max (minSizeLeft.cy, minSizeRight.cy);
			size.cy = max (sizeLeftContainer.cy, size.cy);
			size.cy = max (sizeRightContainer.cy, size.cy);
			size.cx = minSizeLeft.cx + minSizeRight.cx + sizeLeftContainer.cx + 
						sizeRightContainer.cx + m_pSlider->GetWidth ();
		}
	}
	else
	{
		size.cx = max (minSizeLeft.cx, minSizeRight.cx);
		size.cy = max (minSizeLeft.cy, minSizeRight.cy);
		if (m_pLeftContainer != NULL && m_pLeftContainer->IsContainerVisible ())
		{
			size = sizeLeftContainer;
		}
		if (m_pRightContainer != NULL && m_pRightContainer->IsContainerVisible ())
		{
			size = sizeRightContainer;
		}
	}
}
//-----------------------------------------------------------------------------------//
void CBCGPBarContainer::GetMinSizeLeft (CSize& size) const
{
	ASSERT_VALID (this);

	BOOL bAutoHideMode = m_pContainerManager->IsAutoHideMode ();

	// VCheck
	CSize minSizeLeft (0, 0);
	if (m_pBarLeftTop != NULL && (m_pBarLeftTop->IsBarVisible () || bAutoHideMode))
	{
		m_pBarLeftTop->GetMinSize (minSizeLeft);
	}

	CSize sizeLeftContainer (0, 0);
	if (m_pLeftContainer != NULL && (m_pLeftContainer->IsContainerVisible () || bAutoHideMode))
	{
		m_pLeftContainer->GetMinSize (sizeLeftContainer);
	}
	
	size.cx = max (minSizeLeft.cx, sizeLeftContainer.cx);
	size.cy = max (minSizeLeft.cy, sizeLeftContainer.cy);
		
}
//-----------------------------------------------------------------------------------//
void CBCGPBarContainer::GetMinSizeRight(CSize& size) const
{
	ASSERT_VALID (this);
	// VCheck
	BOOL bAutoHideMode = m_pContainerManager->IsAutoHideMode ();
	CSize minSizeRight (0, 0);
	if (m_pBarRightBottom != NULL && (m_pBarRightBottom->IsBarVisible () || bAutoHideMode))
	{
		m_pBarRightBottom->GetMinSize (minSizeRight);
	}

	CSize sizeRightContainer (0, 0);
	if (m_pRightContainer != NULL && (m_pRightContainer->IsContainerVisible () || bAutoHideMode))
	{
		m_pRightContainer->GetMinSize (sizeRightContainer);
	}
	
	size.cx = max (minSizeRight.cx, sizeRightContainer.cx);
	size.cy = max (minSizeRight.cy, sizeRightContainer.cy);
}
//-----------------------------------------------------------------------------------//
CBCGPDockingControlBar* CBCGPBarContainer::AddControlBar (CBCGPDockingControlBar* pBar)
{
	ASSERT_VALID  (this);
	ASSERT_KINDOF (CBCGPDockingControlBar, pBar);
	
	CWnd* pDockSite = m_pContainerManager->GetDockSite ();
	ASSERT_VALID (pDockSite);

	BOOL bAddToMiniFrame = pDockSite->
		IsKindOf (RUNTIME_CLASS (CBCGPMiniFrameWnd));

	CRect rectNew = pBar->m_recentDockInfo.GetRecentDockedRect (!bAddToMiniFrame);
	

	CRect rectContainer;
	rectContainer.SetRectEmpty ();
	GetWindowRect (rectContainer);

	pDockSite->ScreenToClient (rectContainer);

	int nNewWidth  = rectNew.Width ();  
	int nNewHeight = rectNew.Height (); 

	CSize sizeMin;
	pBar->GetMinSize (sizeMin);

	if (nNewWidth < sizeMin.cx)
	{
		nNewWidth = sizeMin.cx;
	}

	if (nNewHeight < sizeMin.cy)
	{
		nNewHeight = sizeMin.cy;
	}

	int nRecentPercent = pBar->m_recentDockInfo.GetRecentDockedPercent (!bAddToMiniFrame);

	if (nRecentPercent == 100 || nRecentPercent == 0)
    {
		nRecentPercent = 50;
    }

	// if the container was empty we'll need to expand its parent container
	BOOL bExpandParentContainer = IsContainerEmpty ();
	// find first non-empty parent container
	CBCGPBarContainer* pNextContainer = m_pParentContainer;
	while (pNextContainer != NULL)
	{
		if (!pNextContainer->IsContainerEmpty ())
		{
			break;
		}
		pNextContainer = pNextContainer->GetParentContainer ();
	}

	CRect rectParentContainer;
	if (pNextContainer != NULL)
	{
		pNextContainer->GetWindowRect (rectParentContainer);
		pDockSite->ScreenToClient (rectParentContainer);
	}


	if (!IsContainerEmpty () && m_pSlider != NULL)
	{
		if (IsSliderHorz ())
		{			
			if (pBar->m_recentDockInfo.IsRecentLeftBar (!bAddToMiniFrame))
			{
				nNewHeight = rectContainer.Height () * nRecentPercent / 100;
				rectNew.top = rectContainer.top;
			}
			else
			{
				nNewHeight = rectContainer.Height () - 
					(rectContainer.Height () * (100 - nRecentPercent) / 100)
					- m_pSlider->GetWidth ();

				rectNew.top = rectContainer.bottom - nNewHeight;
			}
		}
		else
		{
			
			if (pBar->m_recentDockInfo.IsRecentLeftBar (!bAddToMiniFrame))
			{
				nNewWidth = rectContainer.Width () * nRecentPercent / 100;
				rectNew.left = rectContainer.left;
			}
			else
			{
				nNewWidth = rectContainer.Width () - 
					(rectContainer.Width () * (100 - nRecentPercent) / 100)
					- m_pSlider->GetWidth ();

				rectNew.left = rectContainer.right - nNewWidth;
			}
		}
	}

	rectNew.bottom = rectNew.top + nNewHeight;
	rectNew.right = rectNew.left + nNewWidth;

	BOOL bShowSlider = FALSE;
	
	HDWP hdwp = BeginDeferWindowPos (10);

	hdwp = pBar->MoveWindow (rectNew, FALSE, hdwp);

	CRect rectSlider = rectNew;
	CRect rectSecondBar;

	BOOL bIsRecentLeftBar = pBar->m_recentDockInfo.IsRecentLeftBar (!bAddToMiniFrame);

	if (bIsRecentLeftBar && m_pLeftContainer != NULL)
	{
		return m_pLeftContainer->AddControlBar (pBar);
	}

	if (!bIsRecentLeftBar && m_pRightContainer != NULL)
	{
		return m_pRightContainer->AddControlBar (pBar);	
	}

	if (bIsRecentLeftBar)
	{
		ASSERT (m_pLeftContainer == NULL);

		if (m_pBarLeftTop != NULL)
		{
			CBCGPDockingControlBar* pTabbedControlBar = NULL;
			pBar->AttachToTabWnd (m_pBarLeftTop, DM_DBL_CLICK, TRUE, &pTabbedControlBar);
			if (pTabbedControlBar != NULL && m_pBarLeftTop != NULL)
			{
				m_pContainerManager->ReplaceControlBar (m_pBarLeftTop, pTabbedControlBar);
			}
			else if (pTabbedControlBar != NULL)
			{
				m_pContainerManager->AddControlBarToList (pTabbedControlBar);
				m_pBarLeftTop = pTabbedControlBar;
			}
			return pTabbedControlBar;
		}
		//ASSERT (m_pBarLeftTop == NULL);
		m_pBarLeftTop = pBar;

		bShowSlider = (m_pBarRightBottom != NULL) || (m_pRightContainer != NULL);

		if (m_pBarRightBottom != NULL)
		{
			m_pBarRightBottom->GetWindowRect (rectSecondBar);
		}
		else if (m_pRightContainer != NULL)
		{
			m_pRightContainer->GetWindowRect (rectSecondBar);
		}

		pDockSite->ScreenToClient (rectSecondBar);

		if (m_pSlider != NULL)
		{
			if (IsSliderHorz ())
			{
				rectSlider.top = rectNew.bottom;
				rectSlider.bottom = rectSlider.top + m_pSlider->GetWidth ();
				rectSecondBar.top = rectSlider.bottom;
			}
			else
			{
				rectSlider.left     = rectNew.right;
				rectSlider.right    = rectSlider.left + m_pSlider->GetWidth ();
				rectSecondBar.left  = rectSlider.right;
			}
		}

		if (m_pBarRightBottom != NULL)
		{
			hdwp = m_pBarRightBottom->MoveWindow (rectSecondBar, FALSE, hdwp);
		} 
		else if (m_pRightContainer != NULL)
		{
			m_pRightContainer->ResizeContainer (rectSecondBar, hdwp);
		}
	}
	else
	{
		ASSERT (m_pRightContainer == NULL);
		if (m_pBarRightBottom != NULL)
		{
			CBCGPDockingControlBar* pTabbedControlBar = NULL;
			pBar->AttachToTabWnd (m_pBarRightBottom, DM_DBL_CLICK, TRUE, &pTabbedControlBar);
			if (pTabbedControlBar != NULL && m_pBarRightBottom != NULL)
			{
				m_pContainerManager->ReplaceControlBar (m_pBarRightBottom, pTabbedControlBar);
			}
			else if (pTabbedControlBar != NULL)
			{
				m_pContainerManager->AddControlBarToList (pTabbedControlBar);
				m_pBarRightBottom = pTabbedControlBar;
			}
			return pTabbedControlBar;
		}
		
		m_pBarRightBottom = pBar;

		bShowSlider = (m_pBarLeftTop != NULL) || (m_pLeftContainer != NULL);

		if (m_pBarLeftTop != NULL)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -