Example #1
0
int CxEdit::DeleteLine(int nLine, BOOL bScroll, int nCount /*= 1*/)
{
   if (nCount >= 1)
   {
      const int linecount = GetLineCount();
      const BOOL bFirstLine = (nLine == 0);
      const BOOL bLastLine  = (nLine == (linecount - 1));
      
//TRACE("%i,%i,%i\n", LineIndex(nLine - 1), LineLength(nLine - 1), LineIndex(nLine));

      const int nStartChar = (bLastLine && (!bFirstLine)) 
         ? (LineIndex(nLine - 1) + LineLength(nLine - 1) + 0) 
         : LineIndex(nLine);
      const int nEndChar   = ((nLine + nCount) >= linecount) 
         ? (LineIndex(linecount - 1) + LineLength(linecount - 1) + 0)
         : LineIndex(nLine + nCount);
      const BOOL bReadOnly = IsStyleReadOnly();

      if (bReadOnly)
      {
         SetReadOnly(FALSE);
      }
      SetSel(nStartChar, nEndChar, !bScroll); // end of edit text
      Clear();        // ..then delete
      GotoEnd(bScroll);
      if (bReadOnly)
      {
         SetReadOnly(TRUE);
      }
   }
   return GetLineCount();
}
/*
================
CSyntaxRichEditCtrl::GetVisibleRange
================
*/
CHARRANGE CSyntaxRichEditCtrl::GetVisibleRange(void) const
{
	RECT rectArea;
	int firstLine, lastLine;
	CHARRANGE range;

	firstLine = GetFirstVisibleLine();
	GetClientRect(&rectArea);
	lastLine = firstLine + (rectArea.bottom / (defaultCharFormat.yHeight / 20));

	if (lastLine >= GetLineCount()) {
		lastLine = GetLineCount() - 1;
	}

	range.cpMin = LineIndex(firstLine);

	if (range.cpMin < 0) {
		range.cpMin = 0;
	}

	range.cpMax = LineIndex(lastLine);

	if (range.cpMax == -1) {
		range.cpMax = range.cpMin + LineLength(range.cpMin);
	} else {
		range.cpMax += LineLength(range.cpMax);
	}

	if (range.cpMax >= GetTextLength()) {
		range.cpMax = GetTextLength() - 1;
	}

	return range;
}
LRESULT CLineNumberEdit::OnSelectLine(WPARAM wParam, LPARAM /*lParam*/ )
/* ============================================================
	Function :		CLineNumberEdit::OnSelectLine
	Description :	Handler for the urm_SELECTLINE registered
					message. Will select the line in wParam.
					
	Return :		LRESULT			-	Not used
	Parameters :	WPARAM wParam	-	The line to select
					LPARAM lParam	-	Not used
					
	Usage :			Called from MFC. Use 
					SendMessage( urm_SELECTLINE, line ) from 
					code.

   ============================================================*/
{

	// Calc start and end position of the line
	int lineno = wParam + GetScrollPos( SB_VERT );
	int start = LineIndex( lineno );
	int end = LineIndex( lineno + 1 );
	SetSel( start, end - 1 );
	return 0;

}
Example #4
0
/////////////////////////////////////////////////////////////////////////////
// 清除指定行
/////////////////////////////////////////////////////////////////////////////
void COutputCtrl::ClearLineFrom(INT dlineFrom, INT dlineTo)
{
	int Num1 = LineIndex(dlineFrom);
	int Num2 = LineIndex(dlineTo+1);
	SetSel(Num1,Num2);
	ReplaceSel("");
}
Example #5
0
void CEmoticonRichEditCtrl::FormatTextLines(int nLineStart, int nLineEnd)
{		
	long nStart = LineIndex(LineFromChar(nLineStart));
	long nEnd = LineIndex(LineFromChar(nLineEnd));
	nEnd += LineLength(nLineEnd);

	FormatTextRange(nStart, nEnd);
}
Example #6
0
void CTWScriptEdit::FormatTextLines(int nLineStart, int nLineEnd)
{
	long nStart = LineIndex(LineFromChar(nLineStart));
	long nEnd = LineIndex(LineFromChar(nLineEnd));
	nEnd += LineLength(nLineEnd);

	FormatTextRange(nStart, nEnd);
}
LRESULT CLineNumberEdit::OnSelectLine(WPARAM wParam, LPARAM /*lParam*/ )
{
	// Calc start and end position of the line
	int lineno = static_cast<int>(wParam) + GetScrollPos( SB_VERT );
	int start = LineIndex( lineno );
	int end = LineIndex( lineno + 1 );
	SetSel( start, end - 1 );
	return 0;
}
Example #8
0
void CNumEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
  const bool bSeparator = nChar == L' ' || nChar == L';' || nChar == L',';

  if (LineLength(LineIndex(0)) == 0) {
    // Initialise variables
    m_bLastMinus = m_bLastSeparator = false;

    // Ignore leading zeroes, backspaces, return or separator if edit field is empty
    if (bSeparator || nChar == L'0' || nChar == VK_BACK || nChar == VK_RETURN)
      return;
  }

  // Ensure character is a digit or a valid delimiter
  // Minus signs are allowed but must be followed by a digit
  // Otherwise just ignore it!

  // Ignore pressed character if last character was a minus sign and now another minus sign
  // or a zero or a separator is pressed
  if (m_bLastMinus && (nChar == L'-' || nChar == L'0' || bSeparator))
    return;

  // Ignore pressed character if last character was a separator and now another separator
  // or a zero is pressed
  if (m_bLastSeparator && (nChar == L'0' || bSeparator))
    return;

  // Do not pass on any character that is not a digit, minus sign or separator
  if (isdigit(nChar) || nChar == L'-' || bSeparator || nChar == VK_BACK) {
    // Send on to CEdit control
    CEdit::OnChar(nChar, nRepCnt, nFlags);

    // Set minus sign state if pressed
    if (nChar == L'-')
      m_bLastMinus = true;

    // Reset minus sign state after a digit or last character was a minus sign and
    // a backspace has been pressed
    if (isdigit(nChar) || (m_bLastMinus && nChar == VK_BACK))
      m_bLastMinus = false;

    // Set separator state if pressed
    if (bSeparator)
      m_bLastSeparator = true;

    // Reset separator state after a digit or a minus sign or last character was a separator and
    // a backspace has been pressed
    if (isdigit(nChar) || nChar == L'-' || (m_bLastSeparator && nChar == VK_BACK))
      m_bLastSeparator = false;
  }

  // If a separator is pressed, update displayed password subset
  if (bSeparator || nChar == VK_RETURN || LineLength(LineIndex(0)) == 0)
    GetParent()->SendMessage(WM_DISPLAYPASSWORDSUBSET);
}
Example #9
0
int JHCEdit::SetSelFullLines(void)
{
	int s, e, sl, el;
	GetSel(s, e);
	if (e < 0) return 0;
	sl = LineFromChar(s); el = LineFromChar(e);
	s = LineIndex(sl);
	if (e > LineIndex(el))
		e = LineIndex(el) + LineLength(e);
	else
		e = LineIndex(el) + LineLength(LineIndex(el));
	SetSel(s, e);
	return (el - sl + 1);
}
/*
================
CSyntaxRichEditCtrl::GetNameBeforeCurrentSelection
================
*/
bool CSyntaxRichEditCtrl::GetNameBeforeCurrentSelection(CString &name, int &charIndex) const
{
	long selStart, selEnd;
	int line, column, length;
	char buffer[1024];

	GetSel(selStart, selEnd);
	charIndex = selStart;
	line = LineFromChar(selStart);
	length = GetLine(line, buffer, sizeof(buffer));
	column = selStart - LineIndex(line) - 1;

	do {
		buffer[column--] = '\0';
	} while (charType[buffer[column]] == CT_WHITESPACE);

	for (length = 0; length < column; length++) {
		if (charType[buffer[column-length-1]] != CT_NAME) {
			break;
		}
	}

	if (length > 0) {
		name = buffer + column - length;
		return true;
	}

	return false;
}
Example #11
0
String TextBuffer::getNth(int i) const
{
	int index0 = LineIndex(i);
	int index1 = BeginningOfNextLine(index0);
	const String line(Text(index0), index1 - index0);
	return line;
}
Example #12
0
void CEditLogB::Update () 
{
	//LOCK_BLOCK (_lock);

	if (!_init) {
		SetLimitText(_maxLine*1024);
		_init = true;
	}

	int lineCount = GetLineCount ();
	if (_maxLine < lineCount) {
		LockWindowUpdate();

		SetSel (0, LineIndex (lineCount - _maxLine*8/10));
		ReplaceSel ("");

		_textLength = GetWindowTextLength();
		LineScroll(_maxLine, 0);

		UnlockWindowUpdate();
	}

	for (int i=0, n=_logList.size (); i<n; ++i) {
		string &smsg = _logList[i];

		SetSel (_textLength, _textLength);
		ReplaceSel (smsg.c_str ());

		_textLength += smsg.length ();
	}
	_logList.clear ();
}
/*
================
CSyntaxRichEditCtrl::BracedSectionAdjustEndTabs
================
*/
void CSyntaxRichEditCtrl::BracedSectionAdjustEndTabs(void)
{
	int line, lineIndex, length, column, numTabs, i;
	char buffer[1024];
	idStr text;

	line = LineFromChar(bracedSection[0]);
	length = GetLine(line, buffer, sizeof(buffer));

	for (numTabs = 0; numTabs < length; numTabs++) {
		if (!idStr::CharIsTab(buffer[numTabs])) {
			break;
		}

		text.Append('\t');
	}

	line = LineFromChar(bracedSection[1]);
	lineIndex = LineIndex(line);
	length = GetLine(line, buffer, sizeof(buffer));
	column = bracedSection[1] - lineIndex;

	for (i = 0; i < column; i++) {
		if (charType[buffer[i]] != CT_WHITESPACE) {
			return;
		}
	}

	ReplaceText(lineIndex, lineIndex + column, text);

	bracedSection[1] += numTabs - column;
	SetSel(bracedSection[1]+1, bracedSection[1]+1);
}
Example #14
0
void CEditExtn::OnKillFocus(CWnd* pNewWnd)
{
  m_bIsFocused = FALSE;
  m_lastposition = LineIndex();
  GetSel(m_nStartChar, m_nEndChar);
  CEdit::OnKillFocus(pNewWnd);
  Invalidate(TRUE);
}
Example #15
0
int CxEdit::GetCol(void) const 
{ 
   int begin = 0, end = 0;
   GetSel(begin, end);
   int nRow = LineFromChar();
   int nCol = begin - LineIndex(nRow);
   return nCol;
}
int CCustRichEdit::GetCurLineCharPos (void) {
  long StartChar;
  long EndChar;
  int  CharPos;

  GetSel(StartChar, EndChar);
  CharPos = StartChar - LineIndex(-1);
  return (CharPos);
 }
Example #17
0
void CRichEditExtn::OnKillFocus(CWnd* pNewWnd)
{
  m_bIsFocused = FALSE;
  m_lastposition = LineIndex();
  GetSel(m_nStartChar, m_nEndChar);
  CRichEditCtrl::OnKillFocus(pNewWnd);

  SetBackgroundColor(FALSE, crefNoFocus);
  Invalidate(TRUE);
}
Example #18
0
void JHCEdit::SetSelStartLine(int line)
{
	int lc, i;
	lc = GetLineCount();
	if (line < 0) i = lc + line + 1; else i = line;
	if ((i < 0) || (i > lc)) return;
	i--; if (i < 0) i = LineFromChar();
	i = LineIndex(i);
	SetSel(i, i);
}
Example #19
0
int JHCEdit::GetLine(CString& str, int line)
{
	int n, lc, i;
	lc = GetLineCount();
	if (line < 0) i = lc + line + 1; else i = line;
	if ((i < 0) || (i > lc)) return 0;
	i--; if (i < 0) i = LineFromChar();
	n = LineLength(LineIndex(i));
	CEdit::GetLine(i, str.GetBuffer(n+1), n); str.ReleaseBuffer(n);
	return n;
}
Example #20
0
String TextBuffer::getNth(int i) const
{
	int index0 = LineIndex(i);
	int index1 = BeginningOfNextLine(index0);
	tbi_ = (tbi_ + 1)%20;
	if (tb_[tbi_]) { delete tb_[tbi_]; }
	tb_[tbi_] = new CopyString(Text(index0), index1 - index0);
//DebugMessage("%d %d %d %d |%s|\n", i, index0, index1,
//tb_[tbi_]->length(), tb_[tbi_]->string());
	return *tb_[tbi_];
}
Example #21
0
int JHCEdit::GetString(CString& str, int start, int end)
{
	int s, e, ls, le, n;
	CString ss;
	if (start < 0) GetSel(s, e); else {s = start; e = end;}
	if (e < s) e = s;
	ls = LineFromChar(s);
	le = LineFromChar(e);
	str = CString("");
	for (int i = ls; (i <= le); i++)
	{
		n = LineLength(LineIndex(i));
		CEdit::GetLine(i, ss.GetBuffer(n+1), n); ss.ReleaseBuffer(n);
		if (i == ls) ss = ss.Mid(s - LineIndex(i)); else str += CString("\r\n");
		if (i == le)
		{
			n = e - (s + str.GetLength());
			ss = ss.Left(n);
		}
		str += ss;
	}
	return str.GetLength();
}
Example #22
0
void JHCEdit::DeleteLine(int line)
{
	int n, lc, i;
	lc = GetLineCount();
	if (line < 0) i = lc + line + 1; else i = line;
	if ((i < 0) || (i > lc)) return;
	i--; if (i < 0) i = LineFromChar();
	i = LineIndex(i);
	n = LineLength(i);
	SetSel(i, i + n + 1);
	ReplaceSel(CString(""), TRUE);
	n = LineLength(i);
	SetSel(i, i);
}
Example #23
0
void TextDisplay::Redraw (IntCoord l, IntCoord b, IntCoord r, IntCoord t) {
    if (canvas != nil) {
        int first = LineNumber(t);
        int last = LineNumber(b);
        for (int i = first; i <= last; ++i) {
            int begin = LineIndex(i, l, false);
            int end = LineIndex(i, r, false);
            TextLine* line = Line(i, false);
            if (line != nil) {
                line->Draw(this, i, begin, end);
            } else {
                IntCoord base = Base(i);
                IntCoord top = Top(i);
                painter->ClearRect(
		    canvas, l, Math::max(base, b), r, Math::min(top, t)
		);
            }
            if (caretline == i && caretindex >= begin && caretindex <= end) {
                ShowCaret();
            }
        }
    }
}
/*
================
CSyntaxRichEditCtrl::GoToLine
================
*/
void CSyntaxRichEditCtrl::GoToLine( int line ) {

	int index = LineIndex( line );

	m_TextDoc->Freeze( NULL );

	SetSel( index, index );

	m_TextDoc->Unfreeze( NULL );

	UpdateVisibleRange();

	RedrawWindow();
}
Example #25
0
BOOL CxEdit::InsertString(int nLine, LPCTSTR lpsz, BOOL bScroll /*= TRUE*/, BOOL bCanUndo /*= FALSE*/)
{
   const int linecount = GetLineCount();
   BOOL bOK = (nLine <= linecount);
   if (bOK)
   {
      if (nLine == linecount)
      {
         AddString(_T("\r\n"), FALSE, bCanUndo);
      }
      const int index = LineIndex(nLine);
      SetSel(index, index, !bScroll);
      ReplaceSel(lpsz, bCanUndo);
   }
   return bOK;
}
Example #26
0
/////////////////////////////////////////////////////////////////////////////
// CNotifyShowCase message handlers
void CNotifyShowCase::AddLine(LPCTSTR lpsz)
{
	TCHAR   szt[50];
	int     nLastChar;
	int     cLines;

	if (GetLineCount() >= m_totalLines)
	{
		SetSel(0, LineLength(0), TRUE/*bNoScroll*/);  // select the first line
		Clear();  // and remove it
	}

	nLastChar = LineIndex((cLines = GetLineCount() - 1)) + LineLength(cLines);
	_stprintf_s(szt, 50, _T("%s\x0D\x0A"), lpsz);
	SetSel(nLastChar, nLastChar, TRUE/*bNoScroll*/);
	ReplaceSel(szt);
}
/*
================
CSyntaxRichEditCtrl::GetCursorPos
================
*/
void CSyntaxRichEditCtrl::GetCursorPos( int &line, int &column, int &character ) const {
	long start, end;
	char buffer[MAX_STRING_CHARS];

	GetSel( start, end );
	line = LineFromChar( start );
	start -= LineIndex( line );
	GetLine( line, buffer, sizeof( buffer ) );
	for ( column = 1, character = 0; character < start; character++ ) {
		if ( idStr::CharIsTab( buffer[character] ) ) {
			column += TAB_SIZE;
			column -= column % TAB_SIZE;
		} else {
			column++;
		}
	}
	character++;
}
Example #28
0
int JHCEdit::DeleteChar(int count)
{
	if (count == 0) return 0;
	int s, e, ls, le;
	GetSel(s, e);
	ls = LineIndex(LineFromChar(s));
	le = ls + LineLength(ls);
	if (count > 0)
	{
		e = s + count;
		if (e > le) e = le;
	}
	else
	{
		e = s;
		s = s + count;
		if (s < ls) s = ls;
	}
	SetSel(s, e);
	Clear();
	return e - s + 1;
}
Example #29
0
LRESULT CScriptEditView::OnKey( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& )
{
	LRESULT lRet = DefWindowProc( uMsg, wParam, lParam );

	//if( uMsg == WM_KEYDOWN && wParam == VK_INSERT )
	//{
	//	bool bOn = ((GetKeyState(VK_INSERT) & 1) == 1);
	//	if( bOn )
	//		CreateSolidCaret( 10, 10 );
	//	else
	//		CreateSolidCaret( 2, 10 );
	//}

	// calc caret position
	long nStartPos, nEndPos;
	GetSel( nStartPos, nEndPos );
	int nRow = LineFromChar( nEndPos );
	int nCol = 0;
	int nChar = nEndPos - LineIndex();
	if( nChar > 0 )
	{
		// min = WORD for length
		LPTSTR lpstrLine = (LPTSTR)_alloca( (nChar + 2) * sizeof(TCHAR) );
		nChar = GetLine( nRow, lpstrLine, nChar );
		for( int i = 0; i < nChar; i++ )
		{
			if(lpstrLine[i] == _T('\t'))
				nCol = ((nCol / m_nTabStop) + 1) * m_nTabStop;
			else
				nCol++;
		}
	}

	WtlGetMainWnd().UndateRowCol( nRow + 1, nCol + 1 );

	return lRet;
}
Example #30
0
void CStatusCtrl::ShowStatus(CString status, int nType)
{
    USES_CONVERSION;

    CString rtfstr = m_RTFHeader;

    status.Replace(_T("\\"), _T("\\\\"));
    status.Replace(_T("{"), _T("\\{"));
    status.Replace(_T("}"), _T("\\}"));
    status.Replace(_T("\r"), _T(""));
    status.Replace(_T("\n"), _T("\\status"));

    CString str;
    switch (nType)
    {
    case 0:
        str = "\\cf2";
        break;
    case 1:
        str = "\\cf5";
        break;
    case 2:
        str = "\\cf3";
        break;
    case 3:
        str = "\\cf4";
        break;
    }

    status = str + status;

    if (!m_bEmpty)
        rtfstr += "\\par " + status;
    else
    {
        m_bEmpty = FALSE;
        rtfstr += status;
    }

    rtfstr += "} ";

    char *buffer = new char[rtfstr.GetLength() + 5]; //Make it large enough to hold unicode data
    strcpy(buffer + 4, T2CA(rtfstr));
    *(int *)buffer = 0;

    EDITSTREAM es;

    es.dwCookie = (DWORD)buffer; // Pass a pointer to the CString to the callback function
    es.pfnCallback = RichEditStreamInCallback; // Specify the pointer to the callback function.

    CWnd *pFocusWnd = GetFocus();
    if (pFocusWnd && pFocusWnd == this)
        AfxGetMainWnd()->SetFocus();

    long nStart, nEnd;
    GetSel(nStart, nEnd);
    BOOL nScrollToEnd = FALSE;

    int num = 0;            //this is the number of visible lines
    CRect rect;
    GetRect(rect);
    int height = rect.Height();

    for (int i = GetFirstVisibleLine();
            i < GetLineCount() && GetCharPos(LineIndex(i)).y < height;
            i++)
        num++;


    if (GetFirstVisibleLine() + num+m_nMoveToBottom >= GetLineCount())
        nScrollToEnd = TRUE;
    HideSelection(TRUE, FALSE);
    SetSel(-1, -1);
    StreamIn(SF_RTF | SFF_SELECTION, es); // Perform the streaming

    if (GetLineCount() > 1000)
    {
        nStart -= LineLength(0) + 2;
        nEnd -= LineLength(0) + 2;
        if (nStart < 0)
            nEnd = 0;
        if (nEnd < 0)
            nEnd = 0;
        SetSel(0, LineLength(0) + 2);
        ReplaceSel(_T(""));
    }

    SetSel(nStart, nEnd);

    if (pFocusWnd && pFocusWnd == this)
        SetFocus();

    HideSelection(FALSE, FALSE);
    if (nScrollToEnd)
    {
        if (nStart != nEnd && (LineFromChar(nStart) >= GetFirstVisibleLine() && LineFromChar(nStart) <= GetFirstVisibleLine() + num ||
                               LineFromChar(nEnd) >= GetFirstVisibleLine() && LineFromChar(nEnd) <= GetFirstVisibleLine() + num))
            LineScroll(1);
        else
        {
            m_nMoveToBottom++;
            if (!m_nTimerID)
                m_nTimerID = SetTimer(654, 25, NULL);
        }
    }

    delete [] buffer;
}