📄 bcgcontrolbarimpl.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"
#include "XPDrawlayer.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CBCGControlBarImpl::CBCGControlBarImpl(CControlBar* pBar,BOOL bMenu /*= FALSE*/) :
m_pBar (pBar)
{
ASSERT_VALID (m_pBar);
m_bMenuBar = bMenu;
}
//*****************************************************************************************
CBCGControlBarImpl::~CBCGControlBarImpl()
{
}
//****************************************************************************************
void CBCGControlBarImpl::DrawNcArea ()
{
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);
if(rectClient.top<rectClient.bottom && rectClient.top<rectClient.bottom)
dc.ExcludeClipRect(rectClient);
// erase parts not drawn
m_pBar->SendMessage(WM_ERASEBKGND, (WPARAM)dc.m_hDC);
// draw borders in non-client area
rectWindow.OffsetRect(-rectWindow.left, -rectWindow.top);
CRect rcClip;
dc.GetClipBox(&rcClip);
CDC mdc;
mdc.CreateCompatibleDC(&dc);
CBitmap memBmp;
memBmp.CreateCompatibleBitmap(&dc,rectWindow.Width(),rectWindow.Height());
CBitmap* pOldBmp = mdc.SelectObject(&memBmp);
{
CBrush cb;
cb.CreateSolidBrush(GetSysColor(COLOR_3DFACE));
mdc.FillRect(rectWindow,&cb);
cb.DeleteObject();
rectWindow.DeflateRect(0,1,0,1);
}
{
CBrush cb;
cb.CreateSolidBrush(m_bMenuBar?GetSysColor(COLOR_3DFACE):
GuiDrawLayer::GetRGBColorXP());
mdc.FillRect(rectWindow,&cb);
cb.DeleteObject();
}
BOOL bHorz = (m_pBar->m_dwStyle & CBRS_ORIENT_HORZ) ? TRUE : FALSE;
DrawGripper(&mdc,&rectWindow,bHorz);
dc.BitBlt (rcClip.left, rcClip.top, rcClip.Width(), rcClip.Height(),
&mdc, rcClip.left, rcClip.top, SRCCOPY);
mdc.SelectObject(pOldBmp);
ReleaseDC(m_pBar->m_hWnd,dc.m_hDC);
mdc.DeleteDC();
/**
// 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);
CBrush cb;
cb.CreateSolidBrush(GuiDrawLayer::GetRGBColorXP());
dc.FillRect(rectWindow,&cb);
cb.DeleteObject();
// 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* dc, CRect* rcWin, BOOL bHorz)
//--------------------------------------------
// Support for single-gripper - by Alan Fritz
//--------------------------------------------
{
if(bHorz)
{
rcWin->top+=5;
rcWin->left+=4;
rcWin->right=rcWin->left+3;
rcWin->bottom-=3;
for(int i=0; i < rcWin->Height(); i+=2)
{
CRect rcWindow;
CBrush cb;
cb.CreateSolidBrush(::GetSysColor(COLOR_BTNSHADOW));
rcWindow=rcWin;
rcWindow.top=rcWin->top+i;
rcWindow.bottom=rcWindow.top+1;
dc->FillRect(rcWindow,&cb);
}
}
else
{
rcWin->top+=2;
rcWin->left+=2;
rcWin->right-=2;
rcWin->bottom=rcWin->top+3;
for (int i=0; i < rcWin->Width(); i+=2)
{
CRect rcWindow;
CBrush cb;
cb.CreateSolidBrush(::GetSysColor(COLOR_BTNSHADOW));
rcWindow=rcWin;
rcWindow.left=rcWindow.left+i;
rcWindow.right=rcWindow.left+1;
dc->FillRect(rcWindow,&cb);
}
}
/**
ASSERT_VALID (pDC);
if (bHorz)
{
rcWin.top+=2;
rcWin.left+=2;
rcWin.right=rcWin.left+3;
rcWin.bottom-=1;
pDC->Draw3dRect(rcWin,::GetSysColor(COLOR_BTNHIGHLIGHT),
::GetSysColor(COLOR_BTNSHADOW));
/**
if (m_style == Office97)
{
rcWin.left=rcWin.right+1;
rcWin.right=rcWin.left+3;
pDC->Draw3dRect(rcWin,::GetSysColor(COLOR_BTNHIGHLIGHT),
::GetSysColor(COLOR_BTNSHADOW));
}
**
}
else
{
rcWin.top+=2;
//rcWin.left+=1;
rcWin.right-=2;
rcWin.bottom=rcWin.top+3;
pDC->Draw3dRect(rcWin,::GetSysColor(COLOR_BTNHIGHLIGHT),
::GetSysColor(COLOR_BTNSHADOW));
/**
if (m_style == Office97)
{
rcWin.top=rcWin.bottom+1;
rcWin.bottom=rcWin.top+3;
pDC->Draw3dRect(rcWin,::GetSysColor(COLOR_BTNHIGHLIGHT),
::GetSysColor(COLOR_BTNSHADOW));
}
**
}
/*****
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 = GuiDrawLayer::GetRGBColorXP();//(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*/GuiDrawLayer::GetRGBColorXP());
if(m_pBar->m_dwStyle & CBRS_BORDER_BOTTOM)
pDC->FillSolidRect(0, rect.bottom, rect.Width()-1, -1, /*globalData.clrBtnShadow*/GuiDrawLayer::GetRGBColorXP());
// 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*/GuiDrawLayer::GetRGBColorXP());
pDC->FillSolidRect(0,1,rect.Width(),1,/*globalData.clrBtnHilite*/GuiDrawLayer::GetRGBColorXP());
}
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 + -