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

📄 bcgcontrolbarimpl.cpp

📁 一个完整的编辑器的代码(很值得参考
💻 CPP
字号:
//*******************************************************************************
// COPYRIGHT NOTES
// ---------------
// This source code is a part of BCGControlBar library.
// You may use, compile or redistribute it as part of your application 
// for free. You cannot redistribute it as a part of a software development 
// library without the agreement of the author. If the sources are 
// distributed along with the application, you should leave the original 
// copyright notes in the source code without any changes.
// This code can be used WITHOUT ANY WARRANTIES on your own risk.
// 
// Stas Levin <stas@iet.co.il>
//*******************************************************************************

// BCGControlBarImpl.cpp: implementation of the CBCGControlBarImpl class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "BCGControlBarImpl.h"
#include "BCGToolBar.h"
#include "globals.h"

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

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

CBCGControlBarImpl::CBCGControlBarImpl(CControlBar* pBar) :
	m_pBar (pBar)
{
	ASSERT_VALID (m_pBar);
}
//*****************************************************************************************
CBCGControlBarImpl::~CBCGControlBarImpl()
{
}
//****************************************************************************************
void CBCGControlBarImpl::DrawNcArea ()
{
	// get window DC that is clipped to the non-client area
	CWindowDC dc(m_pBar);

	CRect rectClient;
	m_pBar->GetClientRect(rectClient);

	CRect rectWindow;
	m_pBar->GetWindowRect(rectWindow);

	m_pBar->ScreenToClient(rectWindow);
	rectClient.OffsetRect(-rectWindow.left, -rectWindow.top);
	dc.ExcludeClipRect(rectClient);

	// draw borders in non-client area
	rectWindow.OffsetRect(-rectWindow.left, -rectWindow.top);
	DrawBorders(&dc, rectWindow);

	// erase parts not drawn
	dc.IntersectClipRect(rectWindow);
	m_pBar->SendMessage(WM_ERASEBKGND, (WPARAM)dc.m_hDC);

	// draw gripper in non-client area
	if ((m_pBar->m_dwStyle & (CBRS_GRIPPER|CBRS_FLOATING)) != CBRS_GRIPPER)
	{
		return;
	}

	BOOL bHorz = (m_pBar->m_dwStyle & CBRS_ORIENT_HORZ) ? TRUE : FALSE;
	CRect rectGripper;
	
	m_pBar->GetWindowRect (&rectGripper);

	// ET: Set gripper rect only to actual area, needed for
	// centering the gripper
	CRect rcClient;
	m_pBar->GetClientRect(&rcClient);
	m_pBar->ClientToScreen(&rcClient);

	if(bHorz) {
		rectGripper.right = min( rectGripper.right, rcClient.left - 1);
	}
	else {
		rectGripper.bottom = min( rectGripper.bottom, rcClient.top - 1);
	}
	////////////////////////////////////////////////////////

	rectGripper.OffsetRect (-rectGripper.left, -rectGripper.top);
	DrawGripper(&dc, rectGripper, bHorz);
}
//**********************************************************************************************
void CBCGControlBarImpl::DrawGripper (CDC* pDC, CRect rectGripper, BOOL bHorz)
//--------------------------------------------
// Support for single-gripper - by Alan Fritz
//--------------------------------------------
{
	ASSERT_VALID (pDC);

	const BOOL bSingleGripper = CBCGToolBar::IsLook2000 ();

	const int iGripperSize = 3;
	const int iGripperOffset = bSingleGripper ? 0 : 1;
	const int iLinesNum = bSingleGripper ? 1 : 2;

	if (bHorz)
	{
		//-----------------
		// Gripper at left:
		//-----------------
		rectGripper.DeflateRect (0, bSingleGripper ? 3 : 2);

		// ET: Center the grippers
		rectGripper.left = iGripperOffset + rectGripper.CenterPoint().x - 
			( iLinesNum*iGripperSize + (iLinesNum-1)*iGripperOffset) / 2;

		rectGripper.right = rectGripper.left + iGripperSize;

 
		for (int i = 0; i < iLinesNum; i ++)
		{
			pDC->Draw3dRect (rectGripper, 
							globalData.clrBtnHilite,
							globalData.clrBtnShadow);

			// ET: not used for NewFlat look
			if(! bSingleGripper ) {
				//-----------------------------------
				// To look same as MS Office Gripper!
				//-----------------------------------
				pDC->SetPixel (CPoint (rectGripper.left, rectGripper.bottom - 1),
								globalData.clrBtnHilite);
			}

			rectGripper.OffsetRect (iGripperSize+1, 0);
		}
	} 
	else 
	{
		//----------------
		// Gripper at top:
		//----------------
		rectGripper.top += iGripperOffset;
		rectGripper.DeflateRect (bSingleGripper ? 3 : 2, 0);

		// ET: Center the grippers
		rectGripper.top = iGripperOffset + rectGripper.CenterPoint().y - 
			( iLinesNum*iGripperSize + (iLinesNum-1)) / 2;

		rectGripper.bottom = rectGripper.top + iGripperSize;

		for (int i = 0; i < iLinesNum; i ++)
		{
			pDC->Draw3dRect (rectGripper,
							globalData.clrBtnHilite,
							globalData.clrBtnShadow);

			// ET: not used for NewFlat look
			if(! bSingleGripper ) {
				//-----------------------------------
				// To look same as MS Office Gripper!
				//-----------------------------------
				pDC->SetPixel (CPoint (rectGripper.right - 1, rectGripper.top),
								globalData.clrBtnHilite);
			}

			rectGripper.OffsetRect (0, iGripperSize+1);
		}
	}
}
//******************************************************************************************
void CBCGControlBarImpl::DrawBorders(CDC* pDC, CRect& rect)
{
	ASSERT_VALID(m_pBar);
	ASSERT_VALID(pDC);

	DWORD dwStyle = m_pBar->m_dwStyle;
	if (!(dwStyle & CBRS_BORDER_ANY))
		return;

	COLORREF clrBckOld = pDC->GetBkColor ();	// FillSolidRect changes it

	// Copyright (C) 1997,'98 by Joerg Koenig
	// All rights reserved
	//

	COLORREF clr = (m_pBar->m_dwStyle & CBRS_BORDER_3D) ? globalData.clrBtnHilite : globalData.clrBtnShadow;
	if(m_pBar->m_dwStyle & CBRS_BORDER_LEFT)
		pDC->FillSolidRect(0, 0, 1, rect.Height() - 1, clr);
	if(m_pBar->m_dwStyle & CBRS_BORDER_TOP)
		pDC->FillSolidRect(0, 0, rect.Width()-1 , 1, clr);
	if(m_pBar->m_dwStyle & CBRS_BORDER_RIGHT)
		pDC->FillSolidRect(rect.right, 1, -1, rect.Height() - 1, globalData.clrBtnShadow);
	if(m_pBar->m_dwStyle & CBRS_BORDER_BOTTOM)
		pDC->FillSolidRect(0, rect.bottom, rect.Width()-1, -1, globalData.clrBtnShadow);

	// if undockable toolbar at top of frame, apply special formatting to mesh
	// properly with frame menu
	if(!m_pBar->m_pDockContext) 
	{
		pDC->FillSolidRect(0,0,rect.Width(),1,globalData.clrBtnShadow);
		pDC->FillSolidRect(0,1,rect.Width(),1,globalData.clrBtnHilite);
	}

	if (dwStyle & CBRS_BORDER_LEFT)
		++rect.left;
	if (dwStyle & CBRS_BORDER_TOP)
		++rect.top;
	if (dwStyle & CBRS_BORDER_RIGHT)
		--rect.right;
	if (dwStyle & CBRS_BORDER_BOTTOM)
		--rect.bottom;

	// Restore Bk color:
	pDC->SetBkColor (clrBckOld);
}
//****************************************************************************************
void CBCGControlBarImpl::CalcNcSize (NCCALCSIZE_PARAMS FAR* lpncsp)
{
	ASSERT_VALID(m_pBar);

	CRect rect; rect.SetRectEmpty();
	BOOL bHorz = (m_pBar->m_dwStyle & CBRS_ORIENT_HORZ) != 0;

	m_pBar->CalcInsideRect(rect, bHorz);

	// adjust non-client area for border space
	lpncsp->rgrc[0].left += rect.left;
	lpncsp->rgrc[0].top += rect.top;

	lpncsp->rgrc[0].right += rect.right;
	lpncsp->rgrc[0].bottom += rect.bottom;
}

⌨️ 快捷键说明

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