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

📄 bcgptoolbar.cpp

📁 远程网络监视程序的源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		pButton->m_nStyle |= TBBS_PRESSED;

		InvalidateButton (iButton);
		UpdateWindow(); // immediate feedback

		ShowCommandMessageString (pButton->m_nID);

		if (pButton->OnClick (this, FALSE /* No delay*/))
		{
			if (m_Buttons.Find (pButton) != NULL)
			{
				pButton->m_nStyle &= ~TBBS_PRESSED;
			}

			m_iButtonCapture = -1;
			m_iHighlighted = -1;

			OnChangeHot (m_iHighlighted);

			InvalidateButton (iButton);
			UpdateWindow(); // immediate feedback
		}
		else
		{
			m_pWndLastCapture = SetCapture ();
		}
	}

#ifndef BCG_NO_CUSTOMIZATION
	else
	{
		int iSelected = m_iSelected;
		m_iSelected = iButton;

		CRect rect;
		GetItemRect (iButton, &rect);

		if (iSelected != -1)
		{
			InvalidateButton (iSelected);
		}

		m_pDragButton = GetButton (m_iSelected);
		ASSERT (m_pDragButton != NULL);

		m_bIsDragCopy = (nFlags & MK_CONTROL);

		if (!m_pDragButton->IsEditable ())
		{
			m_iSelected = -1;
			m_pDragButton = NULL;

			if (iSelected != -1)
			{
				InvalidateButton (iSelected);
			}
			return;
		}

		InvalidateButton (iButton);
		UpdateWindow(); // immediate feedback

		if (m_pDragButton->CanBeStretched () &&
			abs (point.x - rect.right) <= STRETCH_DELTA &&
			!m_bAltCustomizeMode)
		{
			m_bStretchButton = TRUE;

			m_rectTrack = m_pDragButton->Rect ();

			if (m_pDragButton->GetHwnd () != NULL)
			{
				m_rectTrack.InflateRect (2, 2);
			}

			m_pWndLastCapture = SetCapture ();
			::SetCursor (globalData.m_hcurStretch);
		}
		else if (m_pDragButton->CanBeStored () &&
			m_pDragButton->OnBeforeDrag ())
		{
			COleDataSource srcItem;
			m_pDragButton->PrepareDrag (srcItem);

			ShowCommandMessageString (pButton->m_nID);

			m_DropSource.m_bDragStarted = FALSE;
			m_ptStartDrag = point;

			HWND hwndSaved = m_hWnd;

			if (m_bAltCustomizeMode)
			{
				m_bCustomizeMode = TRUE;
			}

			DROPEFFECT dropEffect = srcItem.DoDragDrop 
				(DROPEFFECT_COPY|DROPEFFECT_MOVE, &rect, &m_DropSource);

			if (!::IsWindow (hwndSaved))
			{
				if (m_bAltCustomizeMode)
				{
					m_bCustomizeMode = FALSE;
					m_bAltCustomizeMode = FALSE;
				}

				return;
			}

			CPoint ptDrop;
			::GetCursorPos (&ptDrop);
			ScreenToClient (&ptDrop);

			if (m_DropSource.m_bDragStarted &&
				!rect.PtInRect (ptDrop))
			{
				if (dropEffect != DROPEFFECT_COPY && 
					m_pDragButton != NULL &&
					!m_DropSource.m_bEscapePressed &&
					OnBeforeRemoveButton (m_pDragButton, dropEffect))
				{
					//---------------------
					// Remove source button:
					//---------------------
					RemoveButton (ButtonToIndex (m_pDragButton));
					AdjustLocations ();
					RedrawWindow (NULL, NULL, RDW_FRAME | RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);
					AdjustSizeImmediate ();

					if (!m_bAltCustomizeMode)
					{
						AdjustLayout ();
						RedrawWindow (NULL, NULL, RDW_FRAME | RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);
					}
					
					if (GetParent ()->IsKindOf (RUNTIME_CLASS (CBCGPTabWnd)))
					{
						CBCGPToolBar* pParentTabbedBar = 
							DYNAMIC_DOWNCAST (CBCGPToolBar, GetParent ()->GetParent ());
						if (pParentTabbedBar != NULL)
						{
							pParentTabbedBar->RecalcLayout ();
						}
					}
				}
				else if (m_pDragButton != NULL)
				{
					InvalidateRect (m_pDragButton->Rect ());
				}
			}
			else
			{
				m_iHighlighted = iButton;
				OnChangeHot (m_iHighlighted);
			}

			m_pDragButton = NULL;
			m_ptStartDrag = CPoint (-1, -1);
		}
		else
		{
			m_pDragButton = NULL;
		}
	}

#endif // BCG_NO_CUSTOMIZATION

	if (m_bAltCustomizeMode)
	{
		m_bAltCustomizeMode = FALSE;
		SetCustomizeMode (FALSE);

		RedrawWindow (NULL, NULL, RDW_FRAME | RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);
	}
}
//**************************************************************************************
void CBCGPToolBar::OnMouseMove(UINT nFlags, CPoint point)
{
	if (m_bDragMode)
	{
		CBCGPBaseToolBar::OnMouseMove (nFlags, point);
		return;
	}

	if (IsCustomizeMode () && !m_bLocked)
	{
		if (m_bStretchButton)
		{
			ASSERT_VALID (m_pDragButton);

			if (point.x - m_pDragButton->Rect ().left >= BUTTON_MIN_WIDTH)
			{
				CClientDC dc (this);

				CRect rectTrackOld = m_rectTrack;
				m_rectTrack.right = point.x;
				dc.DrawDragRect (&m_rectTrack, CSize (2, 2), &rectTrackOld, CSize (2, 2));
			}

			::SetCursor (globalData.m_hcurStretch);
		}

		return;
	}

	if (m_ptLastMouse != CPoint (-1, -1) &&
		abs (m_ptLastMouse.x - point.x) < 1 &&
		abs (m_ptLastMouse.y - point.y) < 1)
	{
		m_ptLastMouse = point;
		return;
	}

	m_ptLastMouse = point;

	int iPrevHighlighted = m_iHighlighted;
	m_iHighlighted = HitTest (point);

	int nTracked = m_iHighlighted;

	if (m_bLeaveFocus && m_iHighlighted == -1 && GetFocus () == this)
	{
		m_iHighlighted = iPrevHighlighted;
		return;
	}

	CBCGPToolbarButton* pButton = m_iHighlighted == -1 ?
							NULL : GetButton (m_iHighlighted);
	if (pButton != NULL &&
		(pButton->m_nStyle & TBBS_SEPARATOR || 
		(pButton->m_nStyle & TBBS_DISABLED && 
		!AllowSelectDisabled ())))
	{
		m_iHighlighted = -1;
	}

	if (!m_bTracked)
	{
		m_bTracked = TRUE;
		
		TRACKMOUSEEVENT trackmouseevent;
		trackmouseevent.cbSize = sizeof(trackmouseevent);
		trackmouseevent.dwFlags = TME_LEAVE;
		trackmouseevent.hwndTrack = GetSafeHwnd();
		trackmouseevent.dwHoverTime = HOVER_DEFAULT;
		::BCGPTrackMouse (&trackmouseevent);	
	}
	
	if (iPrevHighlighted != nTracked)
	{
		if (nTracked != -1 && 
			(m_bMenuMode || nTracked == m_iButtonCapture || m_iButtonCapture == -1))
		{
			if (pButton != NULL)
			{
				ShowCommandMessageString (pButton->m_nID);
			}
		}
		else if ((m_iButtonCapture == -1 || (m_bMenuMode && nTracked == -1))
			&& m_hookMouseHelp == NULL)
		{
			GetOwner()->SendMessage (WM_SETMESSAGESTRING, AFX_IDS_IDLEMESSAGE);
		}
	}

	if (iPrevHighlighted != m_iHighlighted)
	{
		BOOL bNeedUpdate = FALSE;

		if (m_iButtonCapture != -1)
		{
			CBCGPToolbarButton* pTBBCapt = GetButton (m_iButtonCapture);
			ASSERT (pTBBCapt != NULL);
			ASSERT (!(pTBBCapt->m_nStyle & TBBS_SEPARATOR));

			UINT nNewStyle = (pTBBCapt->m_nStyle & ~TBBS_PRESSED);
			if (m_iHighlighted == m_iButtonCapture)
			{
				nNewStyle |= TBBS_PRESSED;
			}

			if (nNewStyle != pTBBCapt->m_nStyle)
			{
				SetButtonStyle (m_iButtonCapture, nNewStyle);
				bNeedUpdate = TRUE;
			}
		}

		if ((m_bMenuMode || m_iButtonCapture == -1 || 
			iPrevHighlighted == m_iButtonCapture) &&
			iPrevHighlighted != -1)
		{
			InvalidateButton (iPrevHighlighted);
			bNeedUpdate = TRUE;
		}

		if ((m_bMenuMode || m_iButtonCapture == -1 || 
			m_iHighlighted == m_iButtonCapture) &&
			m_iHighlighted != -1)
		{
			InvalidateButton (m_iHighlighted);
			bNeedUpdate = TRUE;
		}

		OnChangeHot (m_iHighlighted);
		if (bNeedUpdate)
		{
			UpdateWindow ();
		}
	}

	CBCGPBaseToolBar::OnMouseMove (nFlags, point);
}
//*************************************************************************************
void CBCGPToolBar::OnLButtonUp(UINT nFlags, CPoint point)
{
	if (IsCustomizeMode () && !m_bLocked)
	{
		if (m_bStretchButton)
		{
			ASSERT_VALID (m_pDragButton);

			CRect rect = m_pDragButton->Rect ();
			rect.right = point.x;

			if (rect.Width () >= BUTTON_MIN_WIDTH &&
				abs (m_pDragButton->Rect ().right - point.x) > STRETCH_DELTA)
			{
				m_pDragButton->OnSize (rect.Width ());
				AdjustLayout ();
			}

			m_rectTrack.SetRectEmpty ();

			m_pDragButton = NULL;
			m_bStretchButton = FALSE;

			RedrawWindow (NULL, NULL, RDW_FRAME | RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);

			::ReleaseCapture ();

			if (m_pWndLastCapture != NULL)
			{
				m_pWndLastCapture->SetCapture ();
				m_pWndLastCapture = NULL;
			}

			AdjustSizeImmediate ();
		}
		CBCGPBaseToolBar::OnLButtonUp(nFlags, point);
		return;
	}

	if (m_bDragMode)
	{
		CBCGPBaseToolBar::OnLButtonUp(nFlags, point);
		return;
	}

	if (m_iButtonCapture == -1)
	{
		if (HitTest (point) == -1)
		{
			CBCGPBaseToolBar::OnLButtonUp(nFlags, point);

			m_ptLastMouse = CPoint (-1, -1);
			OnMouseMove (0, point);
		}

		return;     // not captured
	}

	::ReleaseCapture();
	if (m_pWndLastCapture != NULL)
	{
		m_pWndLastCapture->SetCapture ();
		m_pWndLastCapture = NULL;
	}

	m_iHighlighted = HitTest (point);

	CBCGPToolbarButton* pButton = GetButton(m_iButtonCapture);
	if (pButton == NULL)
	{
		ASSERT (FALSE);
		return;
	}

	ASSERT(!(pButton->m_nStyle & TBBS_SEPARATOR));
	UINT nIDCmd = 0;

	UINT nNewStyle = (pButton->m_nStyle & ~TBBS_PRESSED);
	if (m_iButtonCapture == m_iHighlighted)
	{
		// we did not lose the capture
		if (HitTest(point) == m_iButtonCapture)
		{
			// give button a chance to update
			UpdateButton(m_iButtonCapture);

			// then check for disabled state
			if (!(pButton->m_nStyle & TBBS_DISABLED))
			{
				// pressed, will send command notification
				nIDCmd = pButton->m_nID;

				if (pButton->m_nStyle & TBBS_CHECKBOX)
				{
					// auto check: three state => down
					if (nNewStyle & TBBS_INDETERMINATE)
						nNewStyle &= ~TBBS_INDETERMINATE;

					nNewStyle ^= TBBS_CHECKED;
				}
			}
		}
	}

	if (m_hookMouseHelp == NULL)
	{
		GetOwner()->SendMessage(WM_SETMESSAGESTRING, AFX_IDS_IDLEMESSAGE);
	}

	int iButtonCapture = m_iButtonCapture;
	m_iButtonCapture = -1;
	m_iHighlighted = -1;

	HWND hwndSaved = m_hWnd;
	RestoreFocus ();

	if (HitTest(point) == iButtonCapture && 
		!OnSendCommand (pButton) &&
		nIDCmd != 0 && nIDCmd != (UINT) -1)
	{
		InvalidateButton (iButtonCapture);
		UpdateWindow(); // immediate feedback

		AddCommandUsage (nIDCmd);

		if (!pButton->OnClickUp () && 
			(g_pUserToolsManager == NULL ||
			!g_pUserToolsManager->InvokeTool (nIDCmd)))
		{
			GetOwner()->SendMessage (WM_COMMAND, nIDCmd);    // send command
		}
	}
	else
	{
		if (::IsWindow (hwndSaved) && !::IsIconic (hwndSaved) &&
			::IsZoomed (hwndSaved))
		{
			pButton->OnClickUp ();
		}
   }


	if (::IsWindow (hwndSaved) &&				// "This" may be destoyed now!
		iButtonCapture < m_Buttons.GetCount ())	// Button may disappear now!
	{
		SetButtonStyle(iButtonCapture, nNewStyle);
		UpdateButton(iButtonCapture);
		InvalidateButton (iButtonCapture);
		UpdateWindow(); // immediate feedback

		m_ptLastMouse = CPoint (-1, -1);
		OnMouseMove (0, point);
	}
}
//*************************************************************************************
void CBCGPToolBar::OnCancelMode()
{
	CBCGPBaseToolBar::OnCancelMode();

	if (m_bStretchButton)
	{
		m_pDragButton = NULL;
		m_bStretchButton = FALSE;

		m_rectTrack.SetRectEmpty ();

		::ReleaseCapture ();
		if (m_pWndLastCapture != NULL)
		{
			m_pWndLastCapture->SetCapture ();
			m_pWndLastCapture = NULL;
		}
	}

	if (m_iButtonCapture >= 0 ||
		m_iHighlighted >= 0)
	{
		if (m_iButtonCapture >= 0)
		{
			CBCGPToolbarButton* pButton = GetButton(m_iButtonCapture);
			if (pButton == NULL)
			{
				ASSERT (FALSE);
			}
			else
			{
				ASSERT(!(pButton->m_nStyle & TBBS_SEPARATOR));
				UINT nNewStyle = (pButton->m_nStyle & ~TBBS_PRESSED);
				if (GetCapture() == this)
				{
					::ReleaseCapture();

					if (m_pWndLastCapture != NULL)
					{
						m_pWndLastCapture->SetCapture ();
						m_pWndLastCapture = NULL;
					}
				}

				SetButtonStyle(m_iButtonCapture, nNewStyle);
			}
		}

		m_iButtonCapture = -1

⌨️ 快捷键说明

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