📄 buttonslist.cpp
字号:
//*******************************************************************************
// COPYRIGHT NOTES
// ---------------
// This is a part of the BCGControlBar Library
// Copyright (C) 1998-2000 BCGSoft Ltd.
// All rights reserved.
//
// This source code can be used, distributed or modified
// only under terms and conditions
// of the accompanying license agreement.
//*******************************************************************************
// ButtonsList.cpp : implementation file
//
#include "stdafx.h"
#ifndef BCG_NO_CUSTOMIZATION
#include "afxadv.h"
#include <afxpriv.h>
#include "bcgprores.h"
#include "ButtonsList.h"
#include "BCGPToolbarButton.h"
#include "BCGPToolBarImages.h"
#include "BCGGlobals.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static const int iXOffset = 4;
static const int iYOffset = 5;
/////////////////////////////////////////////////////////////////////////////
// CButtonsList
CButtonsList::CButtonsList()
{
m_pSelButton = NULL;
m_pImages = NULL;
m_iScrollOffset = 0;
m_iScrollTotal = 0;
m_iScrollPage = 0;
m_bEnableDragFromList = FALSE;
m_bInited = FALSE;
m_bFocused = FALSE;
}
//**************************************************************************************
CButtonsList::~CButtonsList()
{
}
BEGIN_MESSAGE_MAP(CButtonsList, CButton)
//{{AFX_MSG_MAP(CButtonsList)
ON_WM_ERASEBKGND()
ON_WM_LBUTTONDOWN()
ON_WM_VSCROLL()
ON_WM_ENABLE()
ON_WM_SYSCOLORCHANGE()
ON_WM_SIZE()
ON_WM_CTLCOLOR()
ON_WM_KEYDOWN()
ON_WM_GETDLGCODE()
ON_WM_SETFOCUS()
ON_WM_KILLFOCUS()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CButtonsList message handlers
BOOL CButtonsList::OnEraseBkgnd(CDC* pDC)
{
CRect rectClient; // Client area rectangle
GetClientRect (&rectClient);
pDC->FillSolidRect (&rectClient, globalData.clrBtnFace);
return TRUE;
}
//*********************************************************************************************
void CButtonsList::DrawItem (LPDRAWITEMSTRUCT lpDIS)
{
if (!m_bInited)
{
RebuildLocations ();
}
CDC* pDC = CDC::FromHandle (lpDIS->hDC);
CRect rectClient = lpDIS->rcItem;
if (m_pImages != NULL)
{
CBCGPDrawState ds;
if (!m_pImages->PrepareDrawImage (ds))
{
return;
}
for (POSITION pos = m_Buttons.GetHeadPosition (); pos != NULL;)
{
CBCGPToolbarButton* pButton = (CBCGPToolbarButton*) m_Buttons.GetNext (pos);
ASSERT (pButton != NULL);
CRect rect = pButton->Rect ();
rect.OffsetRect (0, -m_iScrollOffset);
if (rect.top >= rectClient.bottom)
{
break;
}
if (rect.bottom > rectClient.top)
{
int nSaveStyle = pButton->m_nStyle;
if (!IsWindowEnabled ())
{
pButton->m_nStyle |= TBBS_DISABLED;
}
pButton->OnDraw (pDC, rect, m_pImages);
pButton->m_nStyle = nSaveStyle;
if (pButton == m_pSelButton && IsWindowEnabled ())
{
//--------------------
// Draw selection bar:
//--------------------
HWND hwndButton = pButton->GetHwnd ();
if (hwndButton != NULL)
{
rect.InflateRect (0, 2);
}
if (!m_bFocused)
{
for (int i = 0; i < 2; i ++)
{
pDC->DrawFocusRect (&rect);
rect.DeflateRect (1, 1);
}
}
else
{
pDC->Draw3dRect (rect, globalData.clrBtnShadow, globalData.clrBtnHilite);
}
}
}
}
m_pImages->EndDrawImage (ds);
}
pDC->Draw3dRect (rectClient, globalData.clrBtnShadow, globalData.clrBtnHilite);
}
//*********************************************************************************************
void CButtonsList::OnLButtonDown(UINT /*nFlags*/, CPoint point)
{
SetFocus ();
CBCGPToolbarButton* pButton = HitTest (point);
if (pButton == NULL)
{
return;
}
SelectButton (pButton);
if (m_bEnableDragFromList)
{
COleDataSource srcItem;
pButton->m_bDragFromCollection = TRUE;
pButton->PrepareDrag (srcItem);
pButton->m_bDragFromCollection = TRUE;
srcItem.DoDragDrop ();
}
}
//*********************************************************************************************
void CButtonsList::SetImages (CBCGPToolBarImages* pImages)
{
ASSERT_VALID (pImages);
m_pImages = pImages;
m_sizeButton.cx = m_pImages->GetImageSize ().cx + 6;
m_sizeButton.cy = m_pImages->GetImageSize ().cy + 7;
RemoveButtons ();
}
//*********************************************************************************************
void CButtonsList::AddButton (CBCGPToolbarButton* pButton)
{
ASSERT_VALID (pButton);
ASSERT (m_pImages != NULL);
m_Buttons.AddTail (pButton);
pButton->OnChangeParentWnd (this);
RebuildLocations ();
HWND hwnd = pButton->GetHwnd ();
if (hwnd != NULL)
{
::EnableWindow (hwnd, FALSE);
}
}
//*********************************************************************************************
void CButtonsList::RemoveButtons ()
{
SelectButton ((CBCGPToolbarButton*) NULL);
while (!m_Buttons.IsEmpty ())
{
CBCGPToolbarButton* pButton =
(CBCGPToolbarButton*) m_Buttons.RemoveHead ();
ASSERT_VALID (pButton);
pButton->OnChangeParentWnd (NULL);
}
m_iScrollOffset = 0;
m_iScrollTotal = 0;
m_iScrollPage = 0;
EnableScrollBarCtrl (SB_VERT, FALSE);
SetScrollRange (SB_VERT, 0, 0);
}
//*********************************************************************************************
CBCGPToolbarButton* CButtonsList::HitTest (POINT point) const
{
CRect rectClient;
GetClientRect (&rectClient);
for (POSITION pos = m_Buttons.GetHeadPosition (); pos != NULL;)
{
CBCGPToolbarButton* pButton = (CBCGPToolbarButton*) m_Buttons.GetNext (pos);
ASSERT (pButton != NULL);
CRect rect = pButton->Rect ();
rect.OffsetRect (0, -m_iScrollOffset);
if (rect.PtInRect (point))
{
return pButton;
}
}
return NULL;
}
//*********************************************************************************************
void CButtonsList::SelectButton (CBCGPToolbarButton* pButton)
{
if (m_pSelButton == pButton)
{
RedrawSelection ();
return;
}
CBCGPToolbarButton* pOldSel = m_pSelButton;
m_pSelButton = pButton;
CRect rectClient;
GetClientRect (&rectClient);
CRect rectSelected;
rectSelected.SetRectEmpty ();
for (POSITION pos = m_Buttons.GetHeadPosition (); pos != NULL;)
{
CBCGPToolbarButton* pListButton = (CBCGPToolbarButton*) m_Buttons.GetNext (pos);
ASSERT (pListButton != NULL);
CRect rect = pListButton->Rect ();
rect.OffsetRect (0, -m_iScrollOffset);
if (pListButton == m_pSelButton)
{
rectSelected = rect;
}
if (pListButton == m_pSelButton ||
pListButton == pOldSel)
{
rect.InflateRect (2, 2);
CRect rectInter;
if (rectInter.IntersectRect (rectClient, rect))
{
InvalidateRect (&rectInter);
}
}
}
if (!rectSelected.IsRectEmpty ())
{
if (rectSelected.top >= rectClient.bottom ||
rectSelected.bottom <= rectClient.top)
{
int iNewOffset =
max (0,
min (rectSelected.bottom - m_iScrollOffset - rectClient.Height (),
m_iScrollTotal));
SetScrollPos (SB_VERT, iNewOffset);
m_iScrollOffset = iNewOffset;
Invalidate ();
}
}
UpdateWindow ();
//-------------------------------------------------------
// Trigger mouse up event (to button click notification):
//-------------------------------------------------------
CWnd* pParent = GetParent ();
if (pParent != NULL)
{
pParent->SendMessage ( WM_COMMAND,
MAKEWPARAM (GetDlgCtrlID (), BN_CLICKED),
(LPARAM) m_hWnd);
}
}
//*********************************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -