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

📄 bcgpmenubar.cpp

📁 远程网络监视程序的源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
//*******************************************************************************
// 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.
//*******************************************************************************

// BCGPMenuBar.cpp : implementation file
//

#include "stdafx.h"

#include "BCGGlobals.h"
#include "BCGPMenuBar.h"
#include "BCGPToolbarButton.h"
#include "BCGPToolbarMenuButton.h"
#include "BCGPToolbarSystemMenuButton.h"
#include "BCGPToolbarMenuButtonsButton.h"
#include "BCGPPopupMenu.h"
#include "BCGPTearOffManager.h"
#include "MenuHash.h"
#include "bcgprores.h"
#include "BCGPLocalResource.h"
#include "BCGPMDIFrameWnd.h"
#include "BCGPFrameWnd.h"
#include "BCGPOleIPFrameWnd.h"
#include "BCGPMultiDocTemplate.h"
#include "RegPath.h"
#include "BCGPMenuPage.h"
#include "BCGPWorkspace.h"
#include "BCGPDockBar.h"
#include "BCGPDockBarRow.h"
#include "BCGPMiniFrameWnd.h"
#include "CustomizeButton.h"

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

IMPLEMENT_SERIAL(CBCGPMenuBar, CBCGPToolBar, VERSIONABLE_SCHEMA | 1)

BOOL CBCGPMenuBar::m_bShowAllCommands = FALSE;
BOOL CBCGPMenuBar::m_bRecentlyUsedMenus = TRUE;
BOOL CBCGPMenuBar::m_bShowAllMenusDelay = TRUE;
BOOL CBCGPMenuBar::m_bMenuShadows = TRUE;
BOOL CBCGPMenuBar::m_bHighlightDisabledItems = FALSE;

static const UINT uiShowAllItemsTimerId = 1;
static const int iShowAllItemsTimerFreq = 5000;	// 5 sec

static const CString strMenuProfile = _T("BCGMenuBar");

/////////////////////////////////////////////////////////////////////////////
// CBCGPMenuBar

CBCGPMenuBar::CBCGPMenuBar()
{
	m_bMaximizeMode = FALSE;
	m_hMenu = NULL;
	m_hDefaultMenu = NULL;
	m_hSysMenu = NULL;
	m_hSysIcon = NULL;
	m_uiDefMenuResId = 0;
	m_nSystemButtonsNum = 0;
	m_nSystemButtonsNumSaved = 0;
	m_bHaveButtons = FALSE;
	m_szSystemButton = CSize (0, 0);
	m_bAutoDocMenus = TRUE;
	m_pMenuPage = NULL;
    m_bForceDownArrows = FALSE;
	m_bExclusiveRow = TRUE;
}

CBCGPMenuBar::~CBCGPMenuBar()
{
	::DestroyMenu (m_hMenu);
}


BEGIN_MESSAGE_MAP(CBCGPMenuBar, CBCGPToolBar)
	//{{AFX_MSG_MAP(CBCGPMenuBar)
	ON_WM_CREATE()
	ON_WM_LBUTTONDOWN()
	ON_WM_SETFOCUS()
	ON_WM_TIMER()
	ON_WM_LBUTTONDBLCLK()
	ON_WM_SETTINGCHANGE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CBCGPMenuBar message handlers

void CBCGPMenuBar::CreateFromMenu (HMENU hMenu, BOOL bDefaultMenu, BOOL bForceUpdate)
{
	if (GetFocus () == this)
	{
		GetParentFrame()->SetFocus ();
	}

	if (m_hMenu != hMenu || IsCustomizeMode () || bForceUpdate)
	{
		if (g_pTearOffMenuManager != NULL && m_hMenu != NULL)
		{
			g_pTearOffMenuManager->Reset (m_hMenu);
		}

		g_menuHash.SaveMenuBar (m_hMenu, this);

		BOOL bMaximizeMode = m_bMaximizeMode;
		m_bMaximizeMode = FALSE;

		m_hMenu = hMenu;
		if (bDefaultMenu)
		{
			m_hDefaultMenu = hMenu;
		}

		DWORD dwOldAlignment = GetCurrentAlignment (); 

		if (!g_menuHash.LoadMenuBar (hMenu, this) || bForceUpdate)
		{
			CMenu* pMenu = CMenu::FromHandle (hMenu);
			if (pMenu == NULL)
			{
				return;
			}

			if (g_pTearOffMenuManager != NULL)
			{
				g_pTearOffMenuManager->SetupTearOffMenus (hMenu);
			}

			RemoveAllButtons ();

			int iCount = (int) pMenu->GetMenuItemCount ();
			for (int i = 0; i < iCount; i ++)
			{
				UINT uiID = pMenu->GetMenuItemID (i);
				
				CString strText;
				pMenu->GetMenuString (i, strText, MF_BYPOSITION);
				
				switch (uiID)
				{
				case -1:	// Pop-up menu
					{
						CMenu* pPopupMenu = pMenu->GetSubMenu (i);
						ASSERT (pPopupMenu != NULL);

						UINT uiTearOffId = 0;
						if (g_pTearOffMenuManager != NULL)
						{
							uiTearOffId = g_pTearOffMenuManager->Parse (strText);
						}

						CBCGPToolbarMenuButton button (
							0, pPopupMenu->GetSafeHmenu (), -1, strText);
						button.m_bText = TRUE;
						button.m_bImage = FALSE;
						button.SetTearOff (uiTearOffId);

						InsertButton (button);
					}
					break;

				case 0:		// Separator
					InsertSeparator ();
					break;

				default:	// Regular command
					{
						CBCGPToolbarButton button (uiID, -1, strText);
						button.m_bText = TRUE;
						button.m_bImage = FALSE;

						InsertButton (button);
					}
					break;
				}
			}
		}
		else
		{
			SetBarAlignment (dwOldAlignment);
		}

		if (bMaximizeMode)
		{
			CMDIFrameWnd* pParentFrame = DYNAMIC_DOWNCAST (CMDIFrameWnd, m_pParentWnd);
			if (pParentFrame != NULL)
			{
				SetMaximizeMode (TRUE, pParentFrame->MDIGetActive ());
			}
		}

		if (GetSafeHwnd () != NULL)
		{
			AdjustLayout ();
		}

		RebuildAccelerationKeys ();
	}
	else if (m_bMaximizeMode && !IsCustomizeMode ())
	{
		//----------------------------------
		// System menu should be re-checked:
		//----------------------------------
		SetMaximizeMode (FALSE, NULL, FALSE /* Don't recalculate layout */);
		SetMaximizeMode (TRUE, NULL, FALSE /* Don't recalculate layout */);

		//------------------------
		// Repaint system buttons:
		//------------------------
		InvalidateButton (0);
		for (int i = 0; i < m_nSystemButtonsNum; i++)
		{
			InvalidateButton (GetCount () - 1 - i);
		}
	}

	if (!m_bExclusiveRow)
	{
		AdjustSizeImmediate ();
	}
}
//***************************************************************************************
CSize CBCGPMenuBar::CalcLayout(DWORD dwMode, int nLength)
{
	OnChangeHot (-1);

	//------------------------------------------
	// Is menu bar have the buttons with images?
	//------------------------------------------
	m_bHaveButtons = FALSE;

	for (POSITION pos = m_Buttons.GetHeadPosition (); pos != NULL;)
	{
		CBCGPToolbarButton* pButton = (CBCGPToolbarButton*) m_Buttons.GetNext (pos);
		ASSERT_VALID (pButton);

		if (!pButton->IsKindOf (RUNTIME_CLASS (CBCGPToolbarMenuButtonsButton)) &&
			!pButton->IsKindOf (RUNTIME_CLASS (CBCGPToolbarSystemMenuButton)) &&
			pButton->m_bImage && pButton->IsDrawImage ())
		{
			m_bHaveButtons = TRUE;
			break;
		}
	}
	BOOL bVert = (dwMode & LM_VERTDOCK) || ((dwMode & LM_HORZ) == 0);

	if (IsFloating () || !m_bExclusiveRow)
	{
		return CBCGPToolBar::CalcLayout (dwMode, nLength);
	}

	CRect rect; rect.SetRectEmpty ();
	
	if (m_pDockBarRow != NULL)
	{
		m_pDockBarRow->GetClientRect (rect);
	}


	if (rect.IsRectEmpty ())
	{
		CWnd* pFrame = GetOwner ();
		pFrame->GetClientRect(&rect);
	}

	CSize size;

	CRect rectClient;
	rectClient.SetRectEmpty();
	CalcInsideRect (rectClient, (dwMode & LM_HORZ));

	if (!bVert)
	{
		WrapToolBar (rect.Width() + rectClient.Width() - 1);

		//-------------------------------------
		// Calculate size again after wrapping:
		//-------------------------------------
		size = CalcSize (FALSE);
		size.cx = rect.Width () - rectClient.Width() / 2;
		size.cy -= rectClient.Height();
	}
	else
	{
		//-------------------------------------
		// Calculate size again after wrapping:
		//-------------------------------------
		size = CalcSize (TRUE);

		size.cy = rect.Height () - rectClient.Height() / 2;
		size.cx -= rectClient.Width();
	}

	//--------------------------------------------------
	// Something may changed, rebuild acceleration keys:
	//--------------------------------------------------
	RebuildAccelerationKeys ();
	
	return size;
}
//***************************************************************************************
void CBCGPMenuBar::SetMaximizeMode (BOOL bMax, CWnd* pWnd, BOOL bRecalcLayout)
{
	if (m_bMaximizeMode == bMax)
	{
		return;
	}

	if (bMax)
	{
		if (pWnd == NULL)
		{
			bMax = FALSE;
		}
		else
		{
			ASSERT_VALID (pWnd);

            // get the sys menu.
			m_hSysMenu = pWnd->GetSystemMenu (FALSE)->GetSafeHmenu ();
			if (!::IsMenu (m_hSysMenu))
			{
				m_hSysMenu = NULL;
			}

            // If we have a system menu, then add a system menu button.
            if (m_hSysMenu != NULL)
            {
				m_hSysIcon = pWnd->GetIcon (FALSE);
				if (m_hSysIcon == NULL)
				{
					m_hSysIcon = (HICON) GetClassLong (*pWnd, GCL_HICONSM);
				}

                InsertButton (CBCGPToolbarSystemMenuButton (m_hSysMenu, m_hSysIcon), 0);
            }

            LONG style = ::GetWindowLong(*pWnd, GWL_STYLE);

            // Assume no buttons.
            m_nSystemButtonsNum = 0;

			if (m_hSysMenu != NULL)
			{
				// Add a minimize box if required.
				if (style & WS_MINIMIZEBOX)
				{
					InsertButton (CBCGPToolbarMenuButtonsButton (SC_MINIMIZE));
					m_nSystemButtonsNum++;
				}

				// Add a restore box if required.
				if (style & WS_MAXIMIZEBOX)
				{
    				InsertButton (CBCGPToolbarMenuButtonsButton (SC_RESTORE));
					m_nSystemButtonsNum++;
				}

				// Add a close box if required.
				CBCGPToolbarMenuButtonsButton closeButton (SC_CLOSE);
				if (m_hSysMenu != NULL)
				{
					//--------------------------------------------------------------
					// Jan Vasina: check if the maximized window has its system menu 
					// with the close button enabled:
					//--------------------------------------------------------------
					MENUITEMINFO menuInfo;
					ZeroMemory(&menuInfo,sizeof(MENUITEMINFO));
					menuInfo.cbSize = sizeof(MENUITEMINFO);
					menuInfo.fMask = MIIM_STATE;

					if (!::GetMenuItemInfo(m_hSysMenu, SC_CLOSE, FALSE, &menuInfo) ||
						(menuInfo.fState & MFS_GRAYED) || 
						(menuInfo.fState & MFS_DISABLED))
					{
						closeButton.m_nStyle |= TBBS_DISABLED;
					}
				}

				InsertButton (closeButton);
				m_nSystemButtonsNum++;
			}
		}
	}
	else
	{
		m_nSystemButtonsNumSaved = m_nSystemButtonsNum;

        // Remove first button if a system menu was added.
        if (m_hSysMenu != NULL)
        {
		    RemoveButton (0);
        }

		int iSysIndex = m_Buttons.GetCount () - 1;
        if (m_pCustomizeBtn != NULL)
        {
            iSysIndex--;
        }

        for (int i = 0; i < m_nSystemButtonsNum; i ++)
        {
			ASSERT_KINDOF (CBCGPToolbarMenuButtonsButton, GetButton (iSysIndex - i));
			RemoveButton (iSysIndex - i);
		}

        // Now we have no system buttons on the menu.
        m_nSystemButtonsNum = 0;
	}

	m_bMaximizeMode = bMax;

	if (bRecalcLayout)
	{
		AdjustLayout ();
	}

	if (!m_bExclusiveRow && bRecalcLayout)
	{
		AdjustSizeImmediate (bRecalcLayout);
	}

⌨️ 快捷键说明

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