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

📄 dockingframe.h

📁 These listed libraries are written in WTL. But it s really hard to mix both MFC & WTL together. Obvi
💻 H
📖 第 1 页 / 共 2 页
字号:
// Copyright (c) 2002
// Sergey Klimov (kidd@ukr.net)
// WTL Docking windows
//
// This code is provided "as is", with absolutely no warranty expressed
// or implied. Any use is at your own risk.
//
// This code may be used in compiled form in any way you desire. This
// file may be redistributed unmodified by any means PROVIDING it is
// not sold for profit without the authors written consent, and
// providing that this notice and the authors name is included. If
// the source code in  this file is used in any commercial application
// then a simple email woulod be nice.

#ifndef __WTL_DW__DOCKINGFRAME_H__
#define __WTL_DW__DOCKINGFRAME_H__

#include <atlframe.h>
#include "DockMisc.h"
#include "PackageWindow.h"

namespace dockwins{
/////////////////CDockingFrameImplBase

template <class T, class TBase,class TWinTraits = CDockingFrameTraits >
class ATL_NO_VTABLE CDockingFrameImplBase : public TBase
{
	typedef CDockingFrameImplBase<T,TBase,TWinTraits>	thisClass;
	typedef TBase										baseClass;
	typedef TWinTraits									CTraits;
	typedef typename CTraits::CSplitterBar				CSplitterBar;
	typedef CPackageWindowFrame<CTraits>				CPackageFrame;
	typedef CSubWndFramesPackage<CPackageFrame,CTraits>	CWndPackage;
	typedef typename CDWSettings::CStyle				CStyle;
#ifdef DF_AUTO_HIDE_FEATURES
	typedef CAutoHideManager<typename CTraits::CAutoHidePaneTraits>	CAHManager;
#endif
	struct  CDockOrientationFlag
	{
		enum{hor=0x80000000,ver=0};
		static void SetVertical(DWORD& flag)
		{
			flag&=~hor;
		}
		static void SetHorizontal(DWORD& flag)
		{
			flag|=hor;
		}
		static bool ResetAndCheckIsHorizontal(DWORD& flag)
		{
			bool bRes=(flag&hor)!=0;
			flag&=~hor;
			return bRes;
		}
	};
public:
	CDockingFrameImplBase()
		:m_vPackage(false),m_hPackage(true)
	{
	}
	void ApplySystemSettings()
	{
		m_settings.Update();
#ifdef DF_AUTO_HIDE_FEATURES
		m_ahManager.ApplySystemSettings(m_hWnd);
#endif
	}
	bool InitializeDockingFrame(CStyle style=CStyle::sUseSysSettings)
	{
		m_settings.SetStyle(style);
		bool bRes=true;
#ifdef DF_AUTO_HIDE_FEATURES
		assert(m_hWnd);
		bRes=m_ahManager.Initialize(m_hWnd);
		assert(bRes);
#endif
		T* pThis = static_cast<T*>(this);
		pThis->ApplySystemSettings();
		pThis->UpdateLayout(FALSE);
		m_vPackage.Insert(&m_hPackage,m_vPackage);
		m_hPackage.Insert(&m_hWndClient,m_vPackage);
#ifdef DF_FOCUS_FEATURES
		m_focusHandler.InstallHook(pThis->m_hWnd);
#endif
		return bRes;
	}

	void UpdateLayout(BOOL bResizeBars = TRUE)
	{
		CRect rc;
		GetClientRect(&rc);
		UpdateBarsPosition(rc, bResizeBars);
		CClientDC dc(m_hWnd);
#ifdef DF_AUTO_HIDE_FEATURES
		m_ahManager.UpdateLayout(dc,rc);
#endif
		m_vPackage.UpdateLayout(rc);
		Draw(dc);
	}

	void GetMinMaxInfo(LPMINMAXINFO pMinMaxInfo) const
	{
		pMinMaxInfo->ptMinTrackSize.x=0;
		pMinMaxInfo->ptMinTrackSize.y=0;
		m_vPackage.GetMinMaxInfo(pMinMaxInfo);
		CRect rc;
		GetWindowRect(&rc);
		if(rc.top<=m_vPackage.top
			&&(rc.bottom>=m_vPackage.bottom)
				&&(rc.left<=m_vPackage.left)
					&&(rc.right>=m_vPackage.right))
		{
			pMinMaxInfo->ptMinTrackSize.x+=rc.Width()-m_vPackage.Width();
			pMinMaxInfo->ptMinTrackSize.y+=rc.Height()-m_vPackage.Height();
		}
#ifdef DF_AUTO_HIDE_FEATURES
		pMinMaxInfo->ptMinTrackSize.x+=m_ahManager.Width();
		pMinMaxInfo->ptMinTrackSize.y+=m_ahManager.Height();
#endif
	}

	void Draw(CDC& dc)
	{
		m_vPackage.Draw(dc);
		m_hPackage.Draw(dc);
#ifdef DF_AUTO_HIDE_FEATURES
		m_ahManager.Draw(dc);
#endif
	}

	HCURSOR GetCursor(const CPoint& pt)
	{
		HCURSOR hCursor=NULL;
		if(m_hPackage.PtInRect(pt))
			hCursor=m_hPackage.GetCursor(pt);
		else
		{
			if(m_vPackage.PtInRect(pt))
				hCursor=m_vPackage.GetCursor(pt);
		}
		return hCursor;
	}

	bool StartSliding(const CPoint& pt)
	{
		bool bRes=!m_vPackage.PtInRect(pt);
		if(!bRes)
		{
			if(m_hPackage.PtInRect(pt))
				bRes=m_hPackage.StartSliding(m_hWnd,pt,m_settings.GhostDrag());
			else
				bRes=m_vPackage.StartSliding(m_hWnd,pt,m_settings.GhostDrag());
			if(bRes)
				RedrawWindow(NULL,NULL,RDW_INVALIDATE | RDW_UPDATENOW |
										((m_hWndClient==NULL)?RDW_ERASE:0));
		}
		return bRes;
	}

	bool AdjustDragRect(DFDOCKRECT* pHdr)
	{
		CRect rc;
		GetClientRect(&rc);
		int limit=rc.Width()/3;
		if(pHdr->rect.right-pHdr->rect.left>limit)
			pHdr->rect.right=pHdr->rect.left+limit;

		limit=GetSystemMetrics(SM_CXMIN);
		if(pHdr->rect.right-pHdr->rect.left<limit)
			pHdr->rect.right=pHdr->rect.left+limit;

		limit=rc.Height()/3;
		if(pHdr->rect.bottom-pHdr->rect.top>limit)
			pHdr->rect.bottom=pHdr->rect.top+limit;

		limit=GetSystemMetrics(SM_CYMIN);
		if(pHdr->rect.bottom-pHdr->rect.top<limit)
			pHdr->rect.bottom=pHdr->rect.top+limit;

		return true;
	}

	LRESULT AcceptDock(DFDOCKRECT* pHdr)
	{
		ScreenToClient(&(pHdr->rect));
		pHdr->hdr.hBar=m_hWnd;
		pHdr->flag=0;
		LRESULT lRes=m_hPackage.AcceptDock(pHdr);
		if(lRes!=FALSE)
			CDockOrientationFlag::SetHorizontal(pHdr->flag);
		else
		{
			lRes=m_vPackage.AcceptDock(pHdr);
			if(lRes!=FALSE)
				CDockOrientationFlag::SetVertical(pHdr->flag);
			else
				pHdr->hdr.hBar=HNONDOCKBAR;
		}
		ClientToScreen(&(pHdr->rect));
		return lRes;
	}

	LRESULT Dock(DFDOCKRECT* pHdr)
	{
		LRESULT lRes=FALSE;
		ScreenToClient(&(pHdr->rect));
		if(CDockOrientationFlag::ResetAndCheckIsHorizontal(pHdr->flag))
			lRes=m_hPackage.Dock(pHdr);
		else
			lRes=m_vPackage.Dock(pHdr);
		ClientToScreen(&(pHdr->rect));
		RedrawWindow(NULL,NULL,RDW_INVALIDATE | RDW_UPDATENOW |
									((m_hWndClient==NULL)?RDW_ERASE:0));
		return lRes;
	}

	LRESULT Undock(DFMHDR* pHdr)
	{
		bool bRes;
		assert(::IsWindow(pHdr->hWnd));
		bRes=m_vPackage.Undock(pHdr);
		if(!bRes)
			bRes=m_hPackage.Undock(pHdr);
		assert(bRes);
		RedrawWindow(NULL,NULL,RDW_INVALIDATE | RDW_UPDATENOW |
									((m_hWndClient==NULL)?RDW_ERASE:0));
		return bRes;
	}
	template<class T>
	bool DockWindow(T& dockWnd,CDockingSide side,unsigned long nBar,float fPctPos,unsigned long	nWidth, unsigned long nHeight)
	{
		if(dockWnd.IsDocking())
			dockWnd.Undock();

		DFDOCKPOS dockHdr;
		dockHdr.hdr.code=DC_SETDOCKPOSITION;
		dockHdr.hdr.hWnd=dockWnd.m_hWnd;
		dockHdr.hdr.hBar=m_hWnd;

		dockHdr.dwDockSide=side;
		dockHdr.nBar=nBar;
		dockHdr.fPctPos=fPctPos;
		dockHdr.nWidth=nWidth;
		dockHdr.nHeight=nHeight;
		return SetDockingPosition(&dockHdr);
	}

	bool SetDockingPosition(DFDOCKPOS* pHdr)
	{
		assert(::IsWindow(pHdr->hdr.hWnd));
		bool bRes;
		CDockingSide side(pHdr->dwDockSide);
		if(side.IsHorizontal())
			bRes=m_vPackage.SetDockingPosition(pHdr);
		else
			bRes=m_hPackage.SetDockingPosition(pHdr);
		RedrawWindow(NULL,NULL,RDW_INVALIDATE | RDW_UPDATENOW |
									((m_hWndClient==NULL)?RDW_ERASE:0));
		return bRes;
	}

	bool GetDockingPosition(DFDOCKPOS* pHdr) const
	{
		assert(::IsWindow(pHdr->hdr.hWnd));
		bool bRes;
#ifdef DF_AUTO_HIDE_FEATURES
		bRes=m_ahManager.GetDockingPosition(pHdr);
		if(!bRes)
		{
#endif
			pHdr->dwDockSide=CDockingSide::sBottom;
			bRes=m_vPackage.GetDockingPosition(pHdr);
			if(!bRes)
			{
				pHdr->dwDockSide=CDockingSide::sRight;
				bRes=m_hPackage.GetDockingPosition(pHdr);
			}
#ifdef DF_AUTO_HIDE_FEATURES
		}
#endif
		return bRes;
	}
#ifdef DF_AUTO_HIDE_FEATURES
	bool OnMouseMove(DWORD key,const CPoint& pt)
	{

⌨️ 快捷键说明

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