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

📄 bcgpeditctrl.cpp

📁 远程网络监视程序的源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		nCharCount += GetSymbolExtraLen (m_strBuffer, m_nCurrOffset, FALSE);
	}

	if (!SetCaret (m_nCurrOffset - nCharCount, TRUE, bRedrawOnScroll))
	{
		OnFailedOperation (g_dwOpLeft);
		return FALSE;
	}

	m_nLastMaxColumn = GetColumnFromOffset (m_nCurrOffset, TRUE);

	return TRUE;
}
//**************************************************************************************
BOOL CBCGPEditCtrl::Right (BOOL bRedrawOnScroll)
{
	if (m_nCurrOffset == m_strBuffer.GetLength ())
	{
		OnFailedOperation (g_dwOpRight);
		return FALSE;
	}

	int nCharCount = 1;
	CBCGPOutlineBaseNode* pHiddenText = FindCollapsedBlock (m_nCurrOffset);
	if (pHiddenText != NULL)
	{
		nCharCount += pHiddenText->m_nEnd - pHiddenText->m_nStart;
	}
	else if (m_bEnableSymSupport)
	{
		nCharCount += GetSymbolExtraLen (m_strBuffer, m_nCurrOffset);
	}

	if (!SetCaret (m_nCurrOffset + nCharCount, TRUE, bRedrawOnScroll))
	{
		OnFailedOperation (g_dwOpRight);
		return FALSE;
	}

	m_nLastMaxColumn = GetColumnFromOffset (m_nCurrOffset, TRUE);

	return TRUE;
}
//**************************************************************************************
BOOL CBCGPEditCtrl::Up (BOOL bSetCaretToMaxColumn, BOOL bRedrawOnScroll)
{
	if (m_nCurRow == 0)
	{
		OnFailedOperation (g_dwOpUp);
		return FALSE;
	}

	if (m_strBuffer.IsEmpty ())
	{
		OnFailedOperation (g_dwOpUp);
		return FALSE;
	}


	CPoint point (m_ptCaret.x, m_ptCaret.y);

	int nCurrOldRow = m_nCurRow;

	if (m_ptCaret.y - m_nLineHeight < m_rectText.top )
	{
		ScrollUp (SB_VERT, bRedrawOnScroll);
	}
	else
	{
		point.y -= m_nLineHeight;
	}

	int nOffset = HitTest (point, TRUE);
	if (nOffset >= 0 && nCurrOldRow > 0)
	{
		if (bSetCaretToMaxColumn && SetCaretToLastMaxColumn (nOffset, bRedrawOnScroll))
		{
			return TRUE;
		}
		else
		{
			return SetCaret (nOffset, TRUE, bRedrawOnScroll);
		}
	}

	OnFailedOperation (g_dwOpUp);
	return FALSE;
}
//**************************************************************************************
BOOL CBCGPEditCtrl::Down (BOOL bSetCaretToMaxColumn, BOOL bRedrawOnScroll)
{
	CPoint point (m_ptCaret.x, m_ptCaret.y);

	if (m_ptCaret.y + m_nLineHeight >= m_rectText.bottom - m_nLineHeight && m_nCurRow < m_szTotalScroll.cy)
	{
		ScrollDown (SB_VERT, bRedrawOnScroll);
	}
	else
	{
		point.y += m_nLineHeight;
	}
	
	int nOffset = HitTest (point, TRUE);

	if (nOffset >= 0)
	{
		if (bSetCaretToMaxColumn && SetCaretToLastMaxColumn (nOffset, bRedrawOnScroll))
		{
			return TRUE;
		}
		else
		{
			return SetCaret (nOffset, TRUE, bRedrawOnScroll);
		}
	}

	OnFailedOperation (g_dwOpDown);
	return FALSE;
}
//**************************************************************************************
BOOL CBCGPEditCtrl::PageUp (BOOL bRedrawOnScroll)
{
	if (m_strBuffer.IsEmpty ())
	{
		OnFailedOperation (g_dwOpPgUp);
		return FALSE;
	}

	SCROLLINFO scrollInfo;
	ZeroMemory(&scrollInfo, sizeof(SCROLLINFO));

    scrollInfo.cbSize = sizeof(SCROLLINFO);
	scrollInfo.fMask = SIF_ALL;

	GetScrollInfo (SB_VERT, &scrollInfo);

	CPoint point (m_ptCaret.x, m_ptCaret.y);

	if ((int) scrollInfo.nPage > m_nCurRow && m_nScrollOffsetVert == 0)
	{
		point.y = 0;
	}
	else
	{
		ScrollPageUp (SB_VERT, bRedrawOnScroll);
	}

	int nOffset = HitTest (point, TRUE);

	if (nOffset >= 0)
	{
		if (SetCaretToLastMaxColumn (nOffset, bRedrawOnScroll))
		{
			return TRUE;
		}
		else
		{
			return SetCaret (nOffset, TRUE, bRedrawOnScroll);
		}
	}

	OnFailedOperation (g_dwOpPgUp);
	return FALSE;
}
//**************************************************************************************
BOOL CBCGPEditCtrl::PageDown (BOOL bRedrawOnScroll)
{
	int nOffset = -1;
	if (!ScrollPageDown (SB_VERT, bRedrawOnScroll))
	{
		nOffset = max (m_strBuffer.GetLength (), 0);
	}
	else
	{
		CPoint point (m_ptCaret.x, m_ptCaret.y);
		nOffset = HitTest (point, TRUE);
	}

	nOffset = min (nOffset, m_strBuffer.GetLength ());

	if (nOffset >= 0)
	{
		if (SetCaretToLastMaxColumn (nOffset, bRedrawOnScroll))
		{
			return TRUE;
		}
		else
		{
			return SetCaret (nOffset, TRUE, bRedrawOnScroll);
		}
	}
	OnFailedOperation (g_dwOpPgDn);
	return FALSE;
}
//**************************************************************************************
BOOL CBCGPEditCtrl::Home (BOOL bRedrawOnScroll)
{
	if (m_strBuffer.IsEmpty ())
	{
		OnFailedOperation (g_dwOpHome);
		return FALSE;
	}

	BOOL bResult = FALSE;
	ScrollHome (SB_HORZ, bRedrawOnScroll);
	int nRowStart = GetCurrRowStart (TRUE);
	int nRowTextStart = GetCurrRowTextStart (TRUE);

	if (m_nCurrOffset == nRowTextStart)
	{
		bResult = SetCaret (nRowStart, TRUE, bRedrawOnScroll);
	}
	else
	{
		bResult = SetCaret (nRowTextStart, TRUE, bRedrawOnScroll);
	}

	if (bResult)
	{
		m_nLastMaxColumn = GetColumnFromOffset (m_nCurrOffset, TRUE);
	}
	return bResult;
}
//**************************************************************************************
BOOL CBCGPEditCtrl::End (BOOL bRedrawOnScroll)
{
	int nOffset = m_nCurrOffset;
	while (nOffset < m_strBuffer.GetLength () &&
		(m_strBuffer [nOffset] != _T('\n') || FindCollapsedBlock (nOffset) != NULL))
	{
		nOffset++;
	}

	nOffset = min (nOffset, m_strBuffer.GetLength ());

	SetCaret (nOffset, TRUE, bRedrawOnScroll);
	m_nLastMaxColumn = GetColumnFromOffset (m_nCurrOffset, TRUE);
	return TRUE;
}
//***************************************************************************************
BOOL CBCGPEditCtrl::StartOfText (BOOL bRedraw)
{
	ScrollHome (SB_VERT, FALSE);
	ScrollHome (SB_HORZ, FALSE);

	if (bRedraw)
	{
		RedrawWindow ();
	}

	BOOL bResult = SetCaret (0, TRUE, FALSE);
	m_nLastMaxColumn = 0;

	return bResult;
}
//***************************************************************************************
BOOL CBCGPEditCtrl::EndOfText (BOOL bRedrawOnScroll)
{
	if (m_strBuffer.IsEmpty ())
	{
		return TRUE;
	}

	return SetCaret (m_strBuffer.GetLength (), TRUE, bRedrawOnScroll);
}
//****************************************************************************************
BOOL CBCGPEditCtrl::NextWord (BOOL bRedrawOnScroll)
{
	if (m_nCurrOffset >= m_strBuffer.GetLength () - 1)
	{
		OnFailedOperation (g_dwOpNextWord);
		return FALSE;
	}

	int i = m_nCurrOffset;
	BOOL bCaretInsideWord = m_strWordDelimeters.Find (m_strBuffer [i]) < 0;
	BOOL bCaretInsideDelimiters = m_strWordDelimeters.Find (m_strBuffer [i]) >= 0 && 
								  m_strSpecialDelimiters.Find (m_strBuffer [i]) < 0 &&	
								  (m_strBuffer [i] != _T (' '));
	int nSpecialDelimiterIdx = m_strSpecialDelimiters.Find (m_strBuffer [i]);
	BOOL bCaretInsideSpecialDelimiters = (nSpecialDelimiterIdx >= 0);
	TCHAR chSpecialDelimeterToSkip = 0;

	if (bCaretInsideSpecialDelimiters)
	{
		chSpecialDelimeterToSkip = m_strSpecialDelimiters [nSpecialDelimiterIdx];
	}
	
	CBCGPOutlineBaseNode* pHiddenText = FindCollapsedBlock (i);
	if (pHiddenText != NULL)
	{
		// Move to end of hidden text:
		do
		{
			i += max (pHiddenText->m_nEnd - i + 1, 1); // skip the rest of the hidden text
			pHiddenText = (i < m_strBuffer.GetLength ()) ? FindCollapsedBlock (i) : NULL;
		}
		while (pHiddenText != NULL);
	}
	else if (bCaretInsideWord)
	{
		// Move to end of word:
		while (i < m_strBuffer.GetLength () &&
			m_strWordDelimeters.Find (m_strBuffer [i]) < 0 && 
			FindCollapsedBlock (i) == NULL)
		{
			i++;
		}
	}
	else if (bCaretInsideDelimiters)
	{
		// Move to end of delimiters string:
		while (i < m_strBuffer.GetLength () &&
			m_strWordDelimeters.Find (m_strBuffer [i]) >= 0 && 
			m_strSpecialDelimiters.Find (m_strBuffer [i]) < 0 &&
			m_strBuffer [i] != _T (' ') &&
			FindCollapsedBlock (i) == NULL)
		{
			i++;
		}
	}
	else if (bCaretInsideSpecialDelimiters)
	{
		// Move to end of special delimiters string:
		while (i < m_strBuffer.GetLength () &&
				m_strBuffer [i] == chSpecialDelimeterToSkip &&
				FindCollapsedBlock (i) == NULL)
		{
			i++;
			if (m_strBuffer [i] == g_chEOL)
			{
				break;
			}
		}
	}

	// Skip spaces:
	while (i < m_strBuffer.GetLength () &&
		m_strBuffer [i] == _T (' '))
	{
		i++;
	}

	if (!SetCaret (i, TRUE, bRedrawOnScroll))
	{
		OnFailedOperation (g_dwOpNextWord);
		return FALSE;
	}

	m_nLastMaxColumn = GetColumnFromOffset (m_nCurrOffset, TRUE);
	return TRUE;
}
//****************************************************************************************
BOOL CBCGPEditCtrl::PrevWord (BOOL bRedrawOnScroll)
{
	if (m_nCurrOffset <= 0)
	{
		OnFailedOperation (g_dwOpPrevWord);
		return FALSE;
	}

	int i = min (m_nCurrOffset - 1, m_strBuffer.GetLength () - 1);

	BOOL bCursorAtEOL = m_strBuffer [i] == g_chEOL;
	// Skip spaces:
	while (i >= 0 && m_strBuffer [i] == _T (' '))
	{
		i--;
		bCursorAtEOL = FALSE;
	}

	if (i == 0)
	{
		SetCaret (0, TRUE, bRedrawOnScroll);
		return TRUE;
	}

	BOOL bCaretInsideWord = m_strWordDelimeters.Find (m_strBuffer [i]) < 0;
	BOOL bCaretInsideDelimiters = m_strWordDelimeters.Find (m_strBuffer [i]) >= 0 && 
								  m_strSpecialDelimiters.Find (m_strBuffer [i]) < 0 &&	
								  (m_strBuffer [i] != _T (' '));
	int nSpecialDelimiterIdx = m_strSpecialDelimiters.Find (m_strBuffer [i]);
	BOOL bCaretInsideSpecialDelimiters = (nSpecialDelimiterIdx >= 0);
	TCHAR chSpecialDelimeterToSkip = 0;

	if (bCaretInsideSpecialDelimiters)
	{
		chSpecialDelimeterToSkip = m_strSpecialDelimiters [nSpecialDelimiterIdx];
	}

	CBCGPOutlineBaseNode* pHiddenText = FindCollapsedBlock (i);
	if (pHiddenText != NULL)
	{
		// Move to end of hidden text:
		do
		{
			i -= max (i - pHiddenText->m_nStart + 1, 1); // skip the rest of the hidden text
			pHiddenText = (i >= 0) ? FindCollapsedBlock (i) : NULL;
		}
		while (pHiddenText != NULL);
	}
	else if (bCaretInsideWord)
	{
		// Move to end of word:
		while (i >= 0 &&
			m_strWordDelimeters.Find (m_strBuffer [i]) < 0 && 
			m_strBuffer [i] != g_chEOL &&
			FindCollapsedBlock (i) == NULL)
		{
			i--;
		}
	}
	else if (bCaretInsideDelimiters)
	{
		// Move to end of delimiters string:
		while (i >= 0 &&
			m_strWordDelimeters.Find (m_strBuffer [i]) >= 0 && 
			m_strSpecialDelimiters.Find (m_strBuffer [i]) < 0 &&
			m_strBuffer [i] != _T (' ') && 
			m_strBuffer [i] != g_chEOL &&
			FindCollapsedBlock (i) == NULL)
		{
			i--;
		}
	}
	else if (bCaretInsideSpecialDelimiters)
	{
		// Move to end of special delimiters string:
		while  (i >= 0 &&
				m_strBuffer [i] == chSpecialDelimeterToSkip &&
				m_strBuffer [i] != _T (' ') && m_strBuffer [i] != g_chEOL &&
				FindCollapsedBlock (i) == NULL)
		{
			i--;
		}
	}
	else
	{
		// Skip spaces:
		while (i >= 0 && m_strBuffer [i] == _T (' '))
		{
			i--;
		}
	}

	if (bCursorAtEOL)
	{
		i--;
	}

	if (!SetCaret (i + 1, TRUE, bRedrawOnScroll))
	{
		OnFailedOperation (g_dwOpPrevWord);
		return FALSE;
	}

	m_nLastMaxColumn = GetColumnFromOffset (m_nCurrOffset, TRUE);

	return TRUE;
}
//****************************************************************************************
BOOL CBCGPEditCtrl::PrevIndent ()
{
	int nCurColumn = GetCurColumn ();

	if (nCurColumn == 0)
	{
		OnFailedOperation (g_dwOpPrevIndent);
		return FALSE;
	}

	int nOffsetToMove = nCurColumn % m_nIndentSize;
	
	if (nOffsetToMove == 0)
	{
		nOffsetToMove = m_nIndentSize;
	}
	
	for (int i = 0; i < nOffsetToMove; i++)
	{
		Left ();
		if (m_strBuffer [m_nCurrOffset] == _T ('\t'))
		{
			i += m_nTabSize;
		}
	}

	return TRUE;
}
//****************************************************************************************
int CBCGPEditCtrl::GetCurrRowStart (BOOL bSkipHidden) const
{
	for (int i = m_nCurrOffset - 1; i >= 0; i--)
	{
		if (m_strBuffer [i] == _T('\n'))
		{
			if (!bSkipHidden || FindCollapsedBlock (i) == NULL)
			{
				break;
			}
		}
	}

	return i + 1;
}
//***************************************************************************************
int CBCGPEditCtrl::GetCurrRowEnd (BOOL bSkipHidden) const
{
	for (int i = m_nCurrOffset; i < m_strBuffer.GetLength (); i++)
	{
		if (m_strBuffer [i] == _T('\n'))
		{
			if (!bSkipHidden || FindCollapsedBlock (i) == NULL)
			{
				break;
			}
		}
	}

	return i;
}
//***************************************************************************************
int CBCGPEditCtrl::GetCurrRowTextStart (BOOL bSkipHidden) const
{
	int nStart = GetCurrRowStart (bSkipHidden);
	return GetRowTextStart (nStart, bSkipHidden);
}
//***************************************************************************************
int CBCGPEditCtrl::GetNumOfColumnsInRowByOffset (int nOffset, int& nRowEndOffset, BOOL bSkipHidden) const
{
	nRowEndOffset = GetRowEndByOffset (nOffset, bSkipHidden);
	return GetColumnFromOffset (nRowEndOffset, bSkipHidden);
}
//***************************************************************************************
int CBCGPEditCtrl::GetRowStart (int nRow, BOOL bSkipHidden) const
{
	if (nRow == 0)
	{
		return 0;
	}

	for (int nIdx = 0, nRowIdx = 0;  nRowIdx != nRow; /*nRowIdx++,*/ nIdx++)
	{
		nIdx = m_strBuffer.Find (_T('\n'), nIdx);
		if (nIdx == -1)
		{
			break;
		}

		if (!bSkipHidden || FindCollapsedBlock (nIdx) == NULL)
		{
			nRowIdx++;
		}

⌨️ 快捷键说明

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