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

📄 bcgppopupmenu.cpp

📁 远程网络监视程序的源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
			{
				pToolBar->PrevMenu ();
			}
			else if (m_pParentBtn != NULL && m_pParentBtn->IsDroppedDown ())		
			{
				CloseMenu ();
			}
		}
		return;

	case VK_DOWN:
		if ((::GetAsyncKeyState (VK_CONTROL) & 0x8000) &&	// Ctrl+Down
			!pMenuBar->m_bAreAllCommandsShown)
		{
			ShowAllCommands ();
			break;
		}

	case VK_UP:
	case VK_HOME:
	case VK_END:
		bHightlightWasChanged = TRUE;

	case VK_RETURN:
		if (!CBCGPToolBar::IsCustomizeMode ())
		{
			pMenuBar->OnKey (nChar);
		}
		break;

	case VK_ESCAPE:
		CloseMenu (TRUE);
		return;

	default:
		if (pMenuBar->OnKey (nChar))
		{
			return;
		}
		else
		{
			CMiniFrameWnd::OnKeyDown(nChar, nRepCnt, nFlags);
		}
	}

	if (bHightlightWasChanged &&
		m_bScrollable && pMenuBar->m_iHighlighted >= 0)
	{
		//---------------------------------------
		// Maybe, selected item is invisible now?
		//---------------------------------------
		CBCGPToolbarButton* pItem = pMenuBar->GetButton (pMenuBar->m_iHighlighted);
		if (pItem == NULL && pMenuBar->GetRowHeight () == 0)
		{
			ASSERT (FALSE);
		}
		else
		{
			CRect rectBar;
			pMenuBar->GetClientRect (rectBar);

			int iOffset = pMenuBar->GetOffset ();
			int iOffsetDelta = 0;

			if (pItem->Rect ().top < rectBar.top)
			{
				//---------------------
				// Scroll up is needed!
				//---------------------
				iOffsetDelta = (pItem->Rect ().top - rectBar.top) / 
					pMenuBar->GetRowHeight () - 1;
			}
			else if (pItem->Rect ().bottom > rectBar.bottom)
			{
				//-----------------------
				// Scroll down is needed!
				//-----------------------
				iOffsetDelta = (pItem->Rect ().bottom - rectBar.bottom) / 
					pMenuBar->GetRowHeight () + 1;
			}

			if (iOffsetDelta != 0)
			{
				int iTotalRows = m_FinalSize.cy / pMenuBar->GetRowHeight () - 2;

				iOffset += iOffsetDelta;
				iOffset = min (max (0, iOffset), 
					pMenuBar->m_Buttons.GetCount () - iTotalRows - 1);

				pMenuBar->SetOffset (iOffset);

				if (AdjustScroll ())
				{
					//------------------------------------------
					// Scroll buttons were changed, adjust again
					//------------------------------------------
					AdjustScroll ();
				}
			}
		}
	}
}
//****************************************************************************************
CBCGPPopupMenu* CBCGPPopupMenu::GetParentPopupMenu () const
{
	if (m_pParentBtn == NULL)
	{
		return NULL;
	}

	CBCGPPopupMenuBar* pParentBar = 
		DYNAMIC_DOWNCAST (CBCGPPopupMenuBar, m_pParentBtn->m_pWndParent);
	if (pParentBar != NULL)
	{
		CBCGPPopupMenu* pParentMenu =
			DYNAMIC_DOWNCAST (CBCGPPopupMenu, BCGPGetParentFrame (pParentBar));
		ASSERT_VALID (pParentMenu);

		return pParentMenu;
	}
	else
	{
		return NULL;
	}
}
//****************************************************************************************
CBCGPToolBar* CBCGPPopupMenu::GetParentToolBar () const
{
	if (m_pParentBtn == NULL)
	{
		return NULL;
	}

	CBCGPToolBar* pParentBar = 
		DYNAMIC_DOWNCAST (CBCGPToolBar, m_pParentBtn->m_pWndParent);
	return pParentBar;
}
//****************************************************************************************
CBCGPToolbarMenuButton* CBCGPPopupMenu::GetSelItem ()
{
	CBCGPPopupMenuBar* pMenuBar = GetMenuBar ();
	ASSERT_VALID (pMenuBar);

	return DYNAMIC_DOWNCAST (CBCGPToolbarMenuButton,
							pMenuBar->GetHighlightedButton ());
}
//****************************************************************************************
void CBCGPPopupMenu::CloseMenu (BOOL bSetFocusToBar)
{
	if (GetSafeHwnd () == NULL)
	{
		return;
	}

	m_bTobeDstroyed = TRUE;

	SaveState ();

	CBCGPPopupMenu* pParentMenu = GetParentPopupMenu ();
	CBCGPToolBar* pParentToolBar = GetParentToolBar ();

	CFrameWnd* pWndMain = BCGCBProGetTopLevelFrame (this);
	if (pParentMenu != NULL)
	{
		m_bAutoDestroyParent = FALSE;
		ActivatePopupMenu (pWndMain, pParentMenu);
	}
	else if (pParentToolBar != NULL)
	{
		ActivatePopupMenu (pWndMain, NULL);
		NotifyParentDlg (FALSE);

		if (bSetFocusToBar)
		{
			pParentToolBar->SetFocus ();
		}
	}
	else
	{
		ActivatePopupMenu (pWndMain, NULL);
		NotifyParentDlg (FALSE);
	}

	SendMessage (WM_CLOSE);
}
//****************************************************************************************
int CBCGPPopupMenu::InsertItem (const CBCGPToolbarMenuButton& button, int iInsertAt)
{
	CBCGPPopupMenuBar* pMenuBar = GetMenuBar ();
	ASSERT_VALID (pMenuBar);

	return pMenuBar->InsertButton (button, iInsertAt);
}
//****************************************************************************************
int CBCGPPopupMenu::InsertSeparator (int iInsertAt)
{
	CBCGPPopupMenuBar* pMenuBar = GetMenuBar ();
	ASSERT_VALID (pMenuBar);

	return pMenuBar->InsertSeparator (iInsertAt);
}
//****************************************************************************************
int CBCGPPopupMenu::GetMenuItemCount () const
{
	CBCGPPopupMenuBar* pMenuBar = ((CBCGPPopupMenu*) this)->GetMenuBar ();
	ASSERT_VALID (pMenuBar);

	return pMenuBar->m_Buttons.GetCount ();
}
//****************************************************************************************
CBCGPToolbarMenuButton* CBCGPPopupMenu::GetMenuItem (int iIndex) const
{
	CBCGPPopupMenuBar* pMenuBar = ((CBCGPPopupMenu*) this)->GetMenuBar ();
	ASSERT_VALID (pMenuBar);

	return (CBCGPToolbarMenuButton*) pMenuBar->GetButton (iIndex);
}
//****************************************************************************************
CBCGPToolbarMenuButton* CBCGPPopupMenu::FindSubItemByCommand (UINT uiCmd) const
{
	CBCGPPopupMenuBar* pMenuBar = ((CBCGPPopupMenu*) this)->GetMenuBar ();
	ASSERT_VALID (pMenuBar);

	for (POSITION pos = pMenuBar->m_Buttons.GetHeadPosition (); pos != NULL;)
	{
		CBCGPToolbarMenuButton* pItem = 
			DYNAMIC_DOWNCAST (CBCGPToolbarMenuButton, pMenuBar->m_Buttons.GetNext (pos));

		if (pItem != NULL)
		{
			ASSERT_VALID (pItem);

			const CObList& listCommands = pItem->GetCommands ();

			for (POSITION posList = listCommands.GetHeadPosition (); posList != NULL;)
			{
				CBCGPToolbarMenuButton* pSubItem = (CBCGPToolbarMenuButton*) listCommands.GetNext (posList);
				ASSERT_VALID (pSubItem);

				if (pSubItem->m_nID == uiCmd)
				{
					return pItem;
				}
			}
		}
	}

	return NULL;
}
//****************************************************************************************
BOOL CBCGPPopupMenu::RemoveItem (int iIndex)
{
	CBCGPPopupMenuBar* pMenuBar = GetMenuBar ();
	ASSERT_VALID (pMenuBar);

	return pMenuBar->RemoveButton (iIndex);
}
//****************************************************************************************
void CBCGPPopupMenu::RemoveAllItems ()
{
	CBCGPPopupMenuBar* pMenuBar = GetMenuBar ();
	ASSERT_VALID (pMenuBar);

	pMenuBar->RemoveAllButtons ();
}
//****************************************************************************************
BOOL CBCGPPopupMenu::OnEraseBkgnd(CDC* /*pDC*/) 
{
	return TRUE;
}
//****************************************************************************************
BOOL CBCGPPopupMenu::ActivatePopupMenu (CFrameWnd* pTopFrame, CBCGPPopupMenu* pPopupMenu)
{
	if (pPopupMenu != NULL)
	{
		pPopupMenu->NotifyParentDlg (TRUE);
	}

	if (pTopFrame != NULL)
	{
		ASSERT_VALID (pTopFrame);

		BOOL bRes = TRUE;

		CBCGPMDIFrameWnd* pMainFrame = DYNAMIC_DOWNCAST (CBCGPMDIFrameWnd, pTopFrame);
		if (pMainFrame != NULL)
		{
			bRes = pMainFrame->ShowPopupMenu (pPopupMenu);
		}
		else	// Maybe, SDI frame...
		{
			CBCGPFrameWnd* pFrame = DYNAMIC_DOWNCAST (CBCGPFrameWnd, pTopFrame);
			if (pFrame != NULL)
			{
				bRes = pFrame->ShowPopupMenu (pPopupMenu);
			}
			else	// Maybe, OLE frame
			{
				CBCGPOleIPFrameWnd* pOleFrame = 
					DYNAMIC_DOWNCAST (CBCGPOleIPFrameWnd, pTopFrame);
				if (pOleFrame != NULL)
				{
					bRes = pOleFrame->ShowPopupMenu (pPopupMenu);
				}
				else
				{
					CBCGPOleDocIPFrameWnd* pOleDocFrame = 
						DYNAMIC_DOWNCAST (CBCGPOleDocIPFrameWnd, pTopFrame);
					if (pOleDocFrame != NULL)
					{
						bRes = pOleDocFrame->ShowPopupMenu (pPopupMenu);
					}
				}
			}
		}

		if (!bRes)
		{
			if (pPopupMenu != NULL && !pPopupMenu->m_bTobeDstroyed)
			{
				pPopupMenu->CloseMenu ();
			}

			return FALSE;
		}
	}

	if (pPopupMenu != NULL)
	{
		CBCGPPopupMenuBar* pMenuBar = pPopupMenu->GetMenuBar ();
		ASSERT_VALID (pMenuBar);

		CBCGPPopupMenu* pParentMenu = DYNAMIC_DOWNCAST (CBCGPPopupMenu, pMenuBar->GetParent ());
		if (pParentMenu != NULL && pParentMenu->GetParentButton () != NULL &&
			!pMenuBar->m_bAreAllCommandsShown)
		{
			// Check if "Show all" button is not exist yet:
			if (pMenuBar->m_Buttons.IsEmpty () ||
				DYNAMIC_DOWNCAST (CBCGPShowAllButton, pMenuBar->m_Buttons.GetTail ()) == NULL)
			{
				pMenuBar->InsertButton (CBCGPShowAllButton ());
			}
		}

		if (pPopupMenu->m_bTrackMode)
		{
			CBCGPPopupMenu::m_pActivePopupMenu = pPopupMenu;
		}
	}

	return TRUE;
}
//************************************************************************************
#if _MSC_VER >= 1300
void CBCGPPopupMenu::OnActivateApp(BOOL bActive, DWORD /*dwThreadID*/)
#else
void CBCGPPopupMenu::OnActivateApp(BOOL bActive, HTASK /*hTask*/) 
#endif
{
	if (!bActive && !CBCGPToolBar::IsCustomizeMode () &&
		!InCommand ())
	{
		if (m_bTrackMode)
		{
			m_bTobeDstroyed = TRUE;
		}

		PostMessage (WM_CLOSE);
	}
}
//*************************************************************************************
void CBCGPPopupMenu::OnTimer(UINT nIDEvent) 
{
	CBCGPPopupMenuBar* pMenuBar = GetMenuBar ();
	ASSERT_VALID (pMenuBar);

	switch (nIDEvent)
	{
	case iAnimTimerId:
		if (!m_bAnimationIsDone)
		{
			clock_t nCurrAnimTime = clock ();

			int nDuration = nCurrAnimTime - nLastAnimTime;
			int nSteps = (int) (.5 + (float) nDuration / m_AnimationSpeed);

			switch (m_AnimationType)
			{
			case UNFOLD:
				m_AnimSize.cx += nSteps * pMenuBar->GetColumnWidth ();
				// no break intentionally

			case SLIDE:
				m_AnimSize.cy += nSteps * pMenuBar->GetRowHeight ();
				break;

			case FADE:
				m_iFadePercent += iFadeStep;
				if (m_iFadePercent > 100 + nSteps * iFadeStep)
				{
					m_iFadePercent = 101;
				}
				break;
			}

			if ((m_AnimationType != FADE && m_AnimSize.cy - m_iShadowSize >= m_FinalSize.cy) ||
				(m_AnimationType == UNFOLD && m_AnimSize.cx - m_iShadowSize >= m_FinalSize.cx) ||
				(m_AnimationType == FADE && m_iFadePercent > 100))
			{

				m_AnimSize.cx = m_FinalSize.cx + m_iShadowSize;
				m_AnimSize.cy = m_FinalSize.cy + m_iShadowSize;

				KillTimer (iAnimTimerId);

				pMenuBar->SetWindowPos (NULL,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOREDRAW|SWP_NOZORDER|SWP_SHOWWINDOW | SWP_NOACTIVATE);
				pMenuBar->ValidateRect (NULL);
    
				m_bAnimationIsDone = TRUE;
			}

			Invalidate ();
			UpdateWindow ();

			nLastAnimTime = nCurrAnimTime;
		}
		break;

	case iScrollTimerId:
		{
			CPoint point;
			::GetCursorPos (&point);
			ScreenToClient (&point);

			CBCGPToolbarMenuButton* pSelItem = GetSelItem ();
			if (pSelItem != NULL)
			{
				pSelItem->OnCancelMode ();
			}

			int iOffset = pMenuBar->GetOffset ();

			if (m_rectScrollUp.PtInRect (point) && m_iScrollMode < 0)	// Scroll Up
			{
				pMenuBar->SetOffset (iOffset - 1);
				AdjustScroll ();
			}
			else if (m_rectScrollDn.PtInRect (point) && m_iScrollMode > 0)	// Scroll Down
			{
				pMenuBar->SetOffset (iOffset + 1);
				AdjustScroll ();
			}
			else
			{
				KillTimer (iScrollTimerId);
				m_iScrollMode = 0;
				InvalidateRect (m_rectScrollDn);
				InvalidateRect (m_rectScrollUp);
			}
		}
		break;
	}

	CMiniFrameWnd::OnTimer(nIDEvent);
}
//****************************************************************************************
void CBCGPPopupMenu::OnMouseMove(UINT nFlags, CPoint point) 
{
	if (m_bTearOffTracking)
	{
		if (!m_rectTearOffCaption.PtInRect (point))
		{
			ReleaseCapture ();
			m_bTearOffTracking = FALSE;

			TearOff (point);
		}

		return;
	}

	CMiniFrameWnd::OnMouseMove(nFlags, point);

	if (!m_bScrollable || m_iScrollMode != 0)
	{
		return;
	}
	
	if (m_rectScrollUp.PtInRect (point) && IsScrollUpAvailable ())
	{
		m_iScrollMode = -1;
		InvalidateRect (m_rectScrollUp);
	}
	else if (m_rectScrollDn.PtInRect (point) && IsScrollDnAvailable ())
	{
		m_iScrollMode = 1;
		InvalidateRect (m_rectScrollDn);
	}
	else
	{
		m_iScrollMode = 0;
	}

	if (m_iScrollMode != 0)

⌨️ 快捷键说明

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