📄 bcgtoolbar.h
字号:
//*******************************************************************************
// 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>
//*******************************************************************************
//
// bcgtoolbar.h : definition of CBCGToolBar
//
// This code is based on the Microsoft Visual C++ sample file
// TOOLBAR.C from the OLDBARS example
//
#ifndef _TOOLBAR_H_
#define _TOOLBAR_H_
#ifndef __AFXTEMPL_H__
#include "afxtempl.h"
#endif
#include "bcgcontrolbar.h"
#include "BCGToolbarDropTarget.h"
#include "BCGToolbarDropSource.h"
#include "BCGToolBarImages.h"
#include "BCGToolbarButton.h"
#include "BCGControlBarImpl.h"
#include "CmdUsageCount.h"
#include "BCGCommandManager.h"
#include "globals.h"
class CBCGToolbarMenuButton;
class CCustomizeButton;
//----------------------------------
// BCGToolbar notification messages:
//----------------------------------
BCGCONTROLBARDLLEXPORT extern UINT BCGM_TOOLBARMENU;
BCGCONTROLBARDLLEXPORT extern UINT BCGM_CUSTOMIZETOOLBAR;
BCGCONTROLBARDLLEXPORT extern UINT BCGM_CREATETOOLBAR;
BCGCONTROLBARDLLEXPORT extern UINT BCGM_DELETETOOLBAR;
BCGCONTROLBARDLLEXPORT extern UINT BCGM_CUSTOMIZEHELP;
BCGCONTROLBARDLLEXPORT extern UINT BCGM_RESETTOOLBAR;
BCGCONTROLBARDLLEXPORT extern UINT BCGM_SHOWREGULARMENU;
static const int dwDefaultToolbarStyle = (WS_CHILD | WS_VISIBLE | CBRS_TOP |
CBRS_GRIPPER | CBRS_HIDE_INPLACE);
class BCGCONTROLBARDLLEXPORT CBCGToolBar : public CControlBar
{
friend class CBCGToolbarDropTarget;
friend class CBCGToolbarsPage;
friend class CBCGOptionsPage;
friend class CButtonsTextList;
friend class CBCGCommandManager;
DECLARE_SERIAL(CBCGToolBar)
//--------------
// Construction:
//--------------
public:
CBCGToolBar();
virtual BOOL Create(CWnd* pParentWnd,
DWORD dwStyle = dwDefaultToolbarStyle,
UINT nID = AFX_IDW_TOOLBAR);
virtual BOOL CreateEx(CWnd* pParentWnd, DWORD dwCtrlStyle = TBSTYLE_FLAT,
DWORD dwStyle = dwDefaultToolbarStyle,
CRect rcBorders = CRect(1, 1, 1, 1),
UINT nID = AFX_IDW_TOOLBAR);
//----------------------------------------------------------------
// Set toolbar buttons image resources.
// You should use SINGLE CBCGToolBarImages for ALL your toolbars!
//----------------------------------------------------------------
static BOOL SetUserImages (CBCGToolBarImages* pUserImages);
//------------------------------
// Clear all images except user:
//------------------------------
static void ResetAllImages();
//--------------------------------
// Dimension manipulation methods:
//--------------------------------
static void SetSizes (SIZE sizeButton, SIZE sizeImage);
static void SetMenuSizes (SIZE sizeButton, SIZE sizeImage);
static CSize GetMenuImageSize ();
static CSize GetMenuButtonSize ();
void SetLockedSizes (SIZE sizeButton, SIZE sizeImage);
void SetHeight (int cyHeight);
//-----------------
// Toolbar context:
//-----------------
BOOL LoadBitmap (UINT uiResID, UINT uiColdResID = 0,
UINT uiMenuResID = 0, BOOL bLocked = FALSE,
UINT uiDisabledResID = 0, UINT uiMenuDisabledResID = 0);
BOOL LoadToolBar (UINT uiResID, UINT uiColdResID = 0,
UINT uiMenuResID = 0, BOOL bLocked = FALSE,
UINT uiDisabledResID = 0, UINT uiMenuDisabledResID = 0);
//----------------------------
// Toolbar buttons add/remove:
//----------------------------
BOOL SetButtons(const UINT* lpIDArray, int nIDCount);
int InsertButton (const CBCGToolbarButton& button, int iInsertAt = -1);
int InsertSeparator (int iInsertAt = -1);
BOOL ReplaceButton (UINT uiCmd, const CBCGToolbarButton& button);
BOOL RemoveButton (int iIndex);
virtual void RemoveAllButtons ();
static BOOL IsLastCommandFromButton (CBCGToolbarButton* pButton);
static BOOL AddToolBarForImageCollection (UINT uiResID);
static void SetNonPermittedCommands (CList<UINT, UINT>& lstCommands);
static BOOL IsCommandPermitted (UINT uiCmd)
{
return m_lstUnpermittedCommands.Find (uiCmd) == NULL;
}
static void SetBasicCommands (CList<UINT, UINT>& lstCommands);
static BOOL IsBasicCommand (UINT uiCmd)
{
return m_lstBasicCommands.Find (uiCmd) != NULL;
}
static BOOL IsCommandRarelyUsed (UINT uiCmd);
static void AddCommandUsage (UINT uiCommand)
{
m_UsageCount.AddCmd (uiCommand);
}
virtual int GetRowHeight () const
{
if (m_bDrawTextLabels)
{
ASSERT (m_nMaxBtnHeight > 0);
return m_nMaxBtnHeight;
}
return max (globalData.GetTextHeight (m_dwStyle & CBRS_ORIENT_HORZ),
m_bMenuMode ?
m_sizeMenuButton.cy > 0 ?
m_sizeMenuButton.cy : m_sizeButton.cy :
GetButtonSize ().cy);
}
virtual int GetColumnWidth () const
{
return m_bMenuMode ?
m_sizeMenuButton.cx > 0 ?
m_sizeMenuButton.cx : m_sizeButton.cx :
GetButtonSize ().cx;
}
static void SetHelpMode (BOOL bOn = TRUE);
virtual void Deactivate ();
void RestoreFocus ();
void SetToolBarBtnText (UINT nBtnIndex,
LPCTSTR szText = NULL,
BOOL bShowText = TRUE,
BOOL bShowImage = TRUE);
void EnableLargeIcons (BOOL bEnable);
static void SetLargeIcons (BOOL bLargeIcons = TRUE);
static BOOL IsLargeIcons ()
{
return m_bLargeIcons;
}
CSize GetButtonSize () const
{
return m_bLocked ?
m_bLargeIconsAreEnbaled ? m_sizeCurButtonLocked : m_sizeButtonLocked :
m_bLargeIconsAreEnbaled ? m_sizeCurButton : m_sizeButton;
}
CSize GetImageSize () const
{
return m_bLocked ?
m_bLargeIconsAreEnbaled ? m_sizeCurImageLocked : m_sizeImageLocked :
m_bLargeIconsAreEnbaled ? m_sizeCurImage : m_sizeImage;
}
//------------
// Attributes:
//------------
public:
// standard control bar things
int CommandToIndex(UINT nIDFind) const;
UINT GetItemID(int nIndex) const;
virtual void GetItemRect(int nIndex, LPRECT lpRect) const;
virtual void GetInvalidateItemRect(int nIndex, LPRECT lpRect) const;
UINT GetButtonStyle(int nIndex) const;
virtual void SetButtonStyle(int nIndex, UINT nStyle);
int GetCount () const;
int ButtonToIndex(const CBCGToolbarButton* pButton) const;
CBCGToolbarButton* GetButton (int iIndex) const;
// Find all buttons specified by the given command ID from the all
// toolbars:
static int GetCommandButtons (UINT uiCmd, CObList& listButtons);
static BOOL SetCustomizeMode (BOOL bSet = TRUE);
static BOOL IsCustomizeMode ()
{
return m_bCustomizeMode;
}
static CBCGToolBar* FromHandlePermanent (HWND hwnd);
static CBCGToolBarImages* GetImages ()
{
return &m_Images;
}
static CBCGToolBarImages* GetUserImages ()
{
return m_pUserImages;
}
static int GetDefaultImage (UINT uiID)
{
int iImage;
if (m_DefaultImages.Lookup (uiID, iImage))
{
return iImage;
}
return -1;
}
int GetImagesOffset () const
{
return m_iImagesOffset;
}
CBCGToolbarButton* GetHighlightedButton () const;
static void SetHotTextColor (COLORREF clrText);
static COLORREF GetHotTextColor ();
void SetHotBorder (BOOL bShowHotBorder)
{
m_bShowHotBorder = bShowHotBorder;
}
BOOL GetHotBorder () const
{
return m_bShowHotBorder;
}
void SetGrayDisabledButtons (BOOL bGrayDisabledButtons)
{
m_bGrayDisabledButtons = bGrayDisabledButtons;
}
BOOL GetGrayDisabledButtons () const
{
return m_bGrayDisabledButtons;
}
//------------------------------------------------------
// Enable/disable quick customization mode ("Alt+drag"):
//------------------------------------------------------
static void EnableQuickCustomization (BOOL bEnable = TRUE)
{
m_bAltCustomization = bEnable;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -