Ejemplo n.º 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;
}
Ejemplo n.º 3
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);
}
Ejemplo n.º 4
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);
}
Ejemplo n.º 5
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);
}
Ejemplo n.º 6
0
/******************************************************************************
 Function Name  :   OnChange

 Input(s)       :   -
 Output         :   -
 Functionality  :   Called by the frame work on keying a character. If floating
                    point is not allowed, then charactres until "." are 
                    considered as valid.
 Member of      :   CRadixEdit
 Friend of      :   

 Author(s)      :   Soj Thomas
 Date Created   :   08-03-2002
 Modifications  :   Ratnadip Choudhury, Amarnath Shastry
					Rajesh Kumar 05.03.2003 : call strtol/strtoul based on sign 
 Modifications  :   Amitesh Bharti, 05.06.2003,replace datatype for supporting 
                    64bits to __int64                             
******************************************************************************/
void CRadixEdit::OnChange() 
{
    int nBufLength = LineLength() + 1;
    TCHAR* acBuffer = new TCHAR[nBufLength];

    if (acBuffer != NULL)
    {
        GetWindowText(acBuffer, nBufLength);
        if (m_bFloatAllowed) 
        {
            m_fValue = (float) _tstof(acBuffer);
        }
        else 
        {
			if(m_nBase == BASE_DECIMAL )
			{
				m_n64Value = _tstoi64(acBuffer);
			}
			else 
			{
                INT nCurrentPost = 0;
                __int64 n64Val = 0;
                INT nActualLength = nBufLength - 1;
                BOOL bNegativeNumber = FALSE;
                m_n64Value = 0;

				while(nActualLength > nCurrentPost)
                {
                    if(acBuffer[nCurrentPost] >='0' 
                       && acBuffer[nCurrentPost] <='9')
                    {
                        acBuffer[nCurrentPost] -='0';
                    }
                    else if(acBuffer[nCurrentPost] != '-')
                    {
                        acBuffer[nCurrentPost] = (TCHAR)(tolower(acBuffer[nCurrentPost]));
                        acBuffer[nCurrentPost] -= 87;
                    }
                    else
                    {
                        bNegativeNumber = TRUE;
                    }
                    if(acBuffer[nCurrentPost] != '-')
                    {
                        n64Val = acBuffer[nCurrentPost];
                        n64Val <<= ((nActualLength - nCurrentPost - 1 )* 4 );
                        m_n64Value |= n64Val;
                    }
                    nCurrentPost++;
                }
                if(bNegativeNumber == TRUE )
                {
                    m_n64Value = -m_n64Value;
                }
			}
        }
        delete []acBuffer;
        acBuffer = NULL;
    }
}
Ejemplo n.º 7
0
static int checkRightMove( linenum line, int *col, range *r )
{
    int         len;

    if( CurrentLine == NULL ) {
        return( ERR_NO_FILE );
    }
    len = LineLength( line );
    if( EditFlags.Modeless ) {
        len++;
    }
    if( (*col) > len ) {
        if( EditFlags.Modeless ) {
            if( !IsPastLastLine( line + 1 ) ) {
                r->start.line = line + 1;
                r->line_based = TRUE;
                *col = 1;
            } else {
                *col = len;
            }
        } else {
            if( EditFlags.OperatorWantsMove ) {
                if( *col == len + 1 ) {
                    return( ERR_NO_ERR );
                }
            }
            *col = len;
            return( ERR_NO_SUCH_COLUMN );
        }
    }
    return( ERR_NO_ERR );
}
Ejemplo n.º 8
0
/*
 * SetSelectedRegion - set the selected region to a specific area
 */
vi_rc SetSelectedRegion( range *r )
{
    vi_rc   rc;
    line    *line;
    fcb     *fcb;

    UnselectRegion();
    SelRgn.start.line = r->start.line;
    SelRgn.end.line = r->end.line;

    SelRgn.start_col_v = 1;
    if( r->line_based ) {
        SelRgn.lines = TRUE;
        SelRgn.start.column = 1;
        SelRgn.end.column = LineLength( r->end.line );
    } else {
        SelRgn.lines = FALSE;
        if( r->start.column < r->end.column ) {
            SelRgn.start.column = r->start.column + 1;
            SelRgn.end.column = r->end.column + 2;
        } else {
            SelRgn.start.column = r->end.column + 1;
            SelRgn.end.column = r->start.column + 2;
        }
        rc = CGimmeLinePtr( SelRgn.start.line, &fcb, &line );
        if( rc == ERR_NO_ERR ) {
            SelRgn.start_col_v = WinVirtualCursorPosition( line->data,
                                                           SelRgn.start.column );
        }
    }
    SelRgn.selected = TRUE;
    updateRegion();
    return( ERR_NO_ERR );

} /* SetSelectedRegion */
Ejemplo n.º 9
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);
}
Ejemplo n.º 10
0
void CTWScriptEdit::FormatTextLines(int nLineStart, int nLineEnd)
{
	long nStart = LineIndex(LineFromChar(nLineStart));
	long nEnd = LineIndex(LineFromChar(nLineEnd));
	nEnd += LineLength(nLineEnd);

	FormatTextRange(nStart, nEnd);
}
Ejemplo n.º 11
0
void CEmoticonRichEditCtrl::FormatTextLines(int nLineStart, int nLineEnd)
{		
	long nStart = LineIndex(LineFromChar(nLineStart));
	long nEnd = LineIndex(LineFromChar(nLineEnd));
	nEnd += LineLength(nLineEnd);

	FormatTextRange(nStart, nEnd);
}
Ejemplo n.º 12
0
static char *prevLine( i_mark *mark )
{
    do {
        mark->line -= 1;
        mark->column = LineLength( mark->line );
    } while( mark->column == 0 && mark->line > 0 );
    return( ptrFromMark( mark ) );

} /* prevLine */
Ejemplo n.º 13
0
static char *nextLine( i_mark *mark )
{
    do {
        mark->line += 1;
        mark->column = 1;
    } while( LineLength( mark->line ) == 0 && !IsPastLastLine( mark->line ) );
    return( ptrFromMark( mark ) );

} /* nextLine */
Ejemplo n.º 14
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;
}
Ejemplo n.º 15
0
void CodeEdit::OnCharAdded(wxStyledTextEvent& event)
{

    // Indent the line to the same indentation as the previous line.
    // Adapted from http://STCntilla.sourceforge.net/STCntillaUsage.html

    char ch = event.GetKey();

    if  (ch == '\r' || ch == '\n')
    {

        int line        = GetCurrentLine();
        int lineLength  = LineLength(line);

        if (line > 0 && lineLength <= 2)
        {

            wxString buffer = GetLine(line - 1);
                
            for (unsigned int i =  0; i < buffer.Length();  ++i)
            {
                if (buffer[i] != ' ' && buffer[i] != '\t')
                {
                    buffer.Truncate(i);
                    break;
                }
            }

            ReplaceSelection(buffer);
            
            // Remember that we just auto-indented so that the backspace
            // key will un-autoindent us.
            m_autoIndented = true;
            
        }
        
    }
    else if (m_enableAutoComplete && m_autoCompleteManager != NULL)
    {

        // Handle auto completion.

        wxString token;
        
        if (GetTokenFromPosition(GetCurrentPos() - 1, ".:", token))
        {
            StartAutoCompletion(token);
        }

    }

    event.Skip();

}
Ejemplo n.º 16
0
static vi_rc changeToEndOfLine( linenum line, int start )
{
    int         len;
    vi_rc       rc;

    rc = ERR_NO_ERR;
    len = LineLength( line );
    if( len ) {
        rc = changeOneLine( line, start, len - 1 );
    }
    return( rc );
}
Ejemplo n.º 17
0
void C3DLine::setSegment(CVector3D vertA, CVector3D vertB)
{
	CLineIndex segment;

	segment.a = addPoint(vertA);
	segment.b = addPoint(vertB);

	// there should be a check to see if this already exists
	// but for now this is fine

	m_Segments.push_back(segment);

	m_fLineLength = LineLength();
}
Ejemplo n.º 18
0
tstring ChatCtrl::LineFromPos(const POINT& p) const {
	int iCharPos = CharFromPos(p);
	int len = LineLength(iCharPos);

	if(len < 3) {
		return Util::emptyStringT;
	}

	tstring tmp;
	tmp.resize(len);

	GetLine(LineFromChar(iCharPos), &tmp[0], len);

	return tmp;
}
Ejemplo n.º 19
0
/*
 * NormalizeRange - convert a range to the (external) selrgn format
 */
void NormalizeRange( range *r )
{
    i_mark      tmp;

    if( r->start.line > r->end.line ) {
        tmp = r->start;
        r->start = r->end;
        r->end = tmp;
    } else if( r->start.line == r->end.line ) {
        if( r->start.column > r->end.column ) {
            tmp = r->start;
            r->start = r->end;
            r->end = tmp;
        }
    }
    if( r->line_based ) {
        r->start.column = 1;
        if( r->fix_range && r->end.column == 1 ) {
            r->end.line -= 1;
        }
        r->end.column = LineLength( r->end.line );
    } else {
        if( r->fix_range ) {
            r->end.column -= 1;
            if( r->end.column == 0 ) {
                r->end.line -= 1;
                r->end.column = LineLength( r->end.line );
            }
        }
    }

    /* change these to be zero-based instead of one-based */
    r->start.column -= 1;
    r->end.column -= 1;

} /* NormalizeRange */
Ejemplo n.º 20
0
/*
 * GimmeCurrentEntireWordDim - fetch forward & backward to get the entire word
 */
vi_rc GimmeCurrentEntireWordDim( int *sc, int *ec, bool big )
{
    i_mark      curr, start, end;
    char        *s;
    int         last_col;
    btype       block_type;
    vi_rc       rc;

    noWrap = false;
    rc = ERR_NO_WORD_TO_FIND;
    curr = CurrentPos;
    s = ptrFromMark( &curr );
    if( s == NULL ) {
        return( rc );
    }
    block_type = charType( *s, big );
    if( block_type == BLOCK_WORD || block_type == BLOCK_DELIM ) {
        end = curr;
        last_col = LineLength( end.line );
        while( charType( *s, big ) == block_type ) {
            if( end.column > last_col ) {
                break;
            }
            s = incrementMark( &end );
            if( s == NULL ) {
                break;
            }
        }
        start = curr;
        s = ptrFromMark( &start );
        while( charType( *s, big ) == block_type ) {
            if( start.column < 1 ) {
                break;
            }
            s = decrementMark( &start );
            if( s == NULL ) {
                break;
            }
        }
        *sc = start.column + 1;
        *ec = end.column - 1;
        rc = ERR_NO_ERR;
    }
    return( rc );

} /* GimmeCurrentEntireWordDim */
Ejemplo n.º 21
0
/*
 * SelectAll - select the entire contents of the file
 */
vi_rc SelectAll( void )
{
    range   r;
    vi_rc   rc;
    r.line_based = TRUE;
    r.start.line = 1;
    CFindLastLine( &r.end.line );
    rc = SetSelectedRegion( &r );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }
    rc = GoToLineNoRelCurs( r.end.line );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }
    return( GoToColumnOK( LineLength( r.end.line ) + 1 ) );

} /* SelectAll */
Ejemplo n.º 22
0
void CListEditCtrl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
    switch(nChar) {
    case VK_RETURN:
        nChar = VK_DOWN;
    case VK_TAB:
        if (g_bOptEditOkDown) {
            // 親ウィンドウにポスト(カーソルを移動させるため)
            if (!g_bEndEditMoveRightCell) { /* BeachMonster 091 */
                GetParent()->PostMessage(WM_KEYDOWN, nChar, 0);
                GetParent()->PostMessage(WM_KEYUP, nChar, 0); /* Baja 165 */
            } else {
                GetParent()->PostMessage(WM_KEYDOWN, VK_RIGHT, 0); /* BeachMonster 091 */
            }
        }
        // 終了
        GetParent()->SetFocus();
        return;
    case VK_ESCAPE:
        if (g_bOptESCEditCancel == false) {
            // 現在、何か入力されている場合は、文字をクリアする
            if (LineLength() != 0) {
                SetWindowText(_T(""));
                return;
            }
        }
        // 何も入力されていない状態で [ESC] が押された場合はキャンセル
        m_bVK_ESCAPE = 1;
        // 終了
        GetParent()->SetFocus();
        return;
    }

    CEdit::OnChar(nChar, nRepCnt, nFlags);

    // ここからしたごっそり変更 /* BeachMonster 089 */
    CRect rect;
    if (CalculateSize(rect)) {
        MoveWindow( &rect );
    }
}
Ejemplo n.º 23
0
static int checkLeftMove( linenum line, int *col, range *r )
{
    if( CurrentLine == NULL ) {
        return( ERR_NO_FILE );
    }
    if( (*col) < 1 ) {
        if( EditFlags.Modeless ) {
            if( line > 1 ) {
                r->start.line = line - 1;
                r->line_based = TRUE;
                *col = LineLength( line - 1 ) + 1;
            } else {
                *col = 1;
            }
        } else {
            *col = 1;
            return( ERR_NO_SUCH_COLUMN );
        }
    }
    return( ERR_NO_ERR );
}
Ejemplo n.º 24
0
const TCHAR* CCustRichEdit::GetCurLineText (CString& Buffer) {
  int	  LineSize;
  int	  LineIndex;
  TCHAR*  pBuffer;

	/* Get the current line text buffer */
  LineIndex = LineFromChar(-1);
  LineSize  = LineLength(-1);

  if (LineSize > 0) {
    pBuffer = Buffer.GetBuffer(LineSize+4);
    GetLine(LineIndex, pBuffer, LineSize+4);
    pBuffer[LineSize] = NULL_CHAR;
    Buffer.ReleaseBuffer(LineSize);
   }
  else {
    Buffer.Empty();
   }

  return (const TCHAR*) (Buffer);
 }
Ejemplo n.º 25
0
bool ChatCtrl::HitIP(const POINT& p, tstring& sIP, int& iBegin, int& iEnd) {
	int iCharPos = CharFromPos(p), len = LineLength(iCharPos) + 1;
	if(len < 3)
		return false;

	DWORD lPosBegin = FindWordBreak(WB_LEFT, iCharPos);
	DWORD lPosEnd = FindWordBreak(WB_RIGHTBREAK, iCharPos);
	len = lPosEnd - lPosBegin;

	tstring sText;
	sText.resize(len);
	GetTextRange(lPosBegin, lPosEnd, &sText[0]);

	for(int i = 0; i < len; i++) {
		if(!((sText[i] == 0) || (sText[i] == '.') || ((sText[i] >= '0') && (sText[i] <= '9')))) {
			return false;
		}
	}

	sText += _T('.');
	size_t iFindBegin = 0, iPos = tstring::npos, iEnd2 = 0;

	for(int i = 0; i < 4; ++i) {
		iPos = sText.find(_T('.'), iFindBegin);
		if(iPos == tstring::npos) {
			return false;
		}
		iEnd2 = atoi(Text::fromT(sText.substr(iFindBegin)).c_str());
		if((iEnd2 < 0) || (iEnd2 > 255)) { // 13197	V547	Expression 'iEnd2 < 0' is always false. Unsigned type value is never < 0.
			return false;
		}
		iFindBegin = iPos + 1;
	}

		sIP = sText.substr(0, iPos);
		iBegin = lPosBegin;
		iEnd = lPosEnd;

	return true;
}
Ejemplo n.º 26
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;
}
Ejemplo n.º 27
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();
}
Ejemplo n.º 28
0
void CHTRichEditCtrl::SafeAddLine(int nPos, LPCTSTR pszLine, int iLen, long& lStartChar, long& lEndChar, bool bLink, COLORREF cr, COLORREF bk, DWORD mask)
{
	// EN_ERRSPACE and EN_MAXTEXT are not working for rich edit control (at least not same as for standard control),
	// need to explicitly check the log buffer limit..
	int iCurSize = nPos;
	if (iCurSize + iLen >= m_iLimitText)
	{
		bool bOldNoPaint = m_bNoPaint;
		m_bNoPaint = true;
		BOOL bIsVisible = IsWindowVisible();
		if (bIsVisible)
			SetRedraw(FALSE);

		while (iCurSize > 0 && iCurSize + iLen > m_iLimitText)
		{
			// delete 1st line
			int iLine0Len = LineLength(0) + 1; // add NL character
			SetSel(0, iLine0Len);
			ReplaceSel(_T(""));

			// update any possible available selection
			lStartChar -= iLine0Len;
			if (lStartChar < 0)
				lStartChar = 0;
			lEndChar -= iLine0Len;
			if (lEndChar < 0)
				lEndChar = 0;

			iCurSize = GetWindowTextLength();
		}

		m_bNoPaint = bOldNoPaint;
		if (bIsVisible && !m_bNoPaint){
			SetRedraw();
			if (m_bRichEdit)
				Invalidate();
		}
	}

	AddString(nPos, pszLine, bLink, cr, bk, mask);

	if (m_bEnErrSpace)
	{
		bool bOldNoPaint = m_bNoPaint;
		m_bNoPaint = true;
		BOOL bIsVisible = IsWindowVisible();
		if (bIsVisible)
			SetRedraw(FALSE);

		// remove the first line as long as we are capable of adding the new line
		int iSafetyCounter = 0;
		while (m_bEnErrSpace && iSafetyCounter < 10)
		{
			// delete the previous partially added line
			SetSel(nPos, -1);
			ReplaceSel(_T(""));

			// delete 1st line
			int iLine0Len = LineLength(0) + 1; // add NL character
			SetSel(0, iLine0Len);
			ReplaceSel(_T(""));

			// update any possible available selection
			lStartChar -= iLine0Len;
			if (lStartChar < 0)
				lStartChar = 0;
			lEndChar -= iLine0Len;
			if (lEndChar < 0)
				lEndChar = 0;

			// add the new line again
			nPos = GetWindowTextLength();
			AddString(nPos, pszLine, bLink, cr, bk, mask);

			if (m_bEnErrSpace && nPos == 0){
				// should never happen: if we tried to add the line another time in the 1st line, there
				// will be no chance to add the line at all -> avoid endless loop!
				break;
			}
			iSafetyCounter++; // never ever create an endless loop!
		}
		m_bNoPaint = bOldNoPaint;
		if (bIsVisible && !m_bNoPaint){
			SetRedraw();
			if (m_bRichEdit)
				Invalidate();
		}
	}
}
Ejemplo n.º 29
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;
}
Ejemplo n.º 30
0
LineLength LogData::doGetLineLength( LineNumber line ) const
{
    if ( line >= indexing_data_.getNbLines() ) { return 0_length; /* exception? */ }

    return LineLength( doGetExpandedLineString( line ).length() );
}