Example #1
0
void OutputCtrl::ShowLine( int line )
{
   // First make sure the line is not folded.
   EnsureVisible( line );

   line = VisibleFromDocLine( line );

   int firstVisible = GetFirstVisibleLine();
   int lastVisible = firstVisible + ( LinesOnScreen() - 1 );
   if ( line <= firstVisible ) {

      int lines = line - firstVisible;
      if ( lines < -1 ) {
         lines -= LinesOnScreen() / 2;
      }
      LineScroll( 0, lines );

   } else if ( line >= lastVisible ) {

      int lines = line - lastVisible;
      if ( lines > 1 ) {
         lines += LinesOnScreen() / 2;
      }
      LineScroll( 0, lines );
   }
}
Example #2
0
void kexConsole::ParseKey(int c) {
    switch(c) {
        case KKEY_BACKSPACE:
            BackSpace();
            return;
        case KKEY_DELETE:
            DeleteChar();
            return;
        case KKEY_LEFT:
            MoveTypePos(0);
            return;
        case KKEY_RIGHT:
            MoveTypePos(1);
            return;
        case KKEY_PAGEUP:
            LineScroll(1);
            return;
        case KKEY_PAGEDOWN:
            LineScroll(0);
            return;
    }

    if(c >= KKEY_SPACE && c < KKEY_z) {
        if(typeStrPos >= CON_INPUT_LENGTH) {
            return;
        }

        typeStr[typeStrPos++] = inputKey.GetAsciiKey((char)c, bShiftDown);
        typeStr[typeStrPos] = '\0';
    }
}
void cbStyledTextCtrl::MakeNearbyLinesVisible(int line)
{
    const int dist = VisibleFromDocLine(line) - GetFirstVisibleLine();
    if (dist >= 0 && dist < 2)
        LineScroll(0, dist - 2);
    else if (dist >= LinesOnScreen() - 2)
        LineScroll(0, 3 + dist - LinesOnScreen());
}
/*
================
CSyntaxRichEditCtrl::OnMouseWheel
================
*/
BOOL CSyntaxRichEditCtrl::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
	if (autoCompleteStart >= 0) {
		int sel;

		if (zDelta > 0) {
			sel = Max(0, autoCompleteListBox.GetCurSel() - (zDelta / WHEEL_DELTA));
		} else {
			sel = Min(autoCompleteListBox.GetCount() - 1, autoCompleteListBox.GetCurSel() - (zDelta / WHEEL_DELTA));
		}

		autoCompleteListBox.SetCurSel(sel);
		return TRUE;
	}

	m_TextDoc->Freeze(NULL);

	LineScroll(-3 *((int) zDelta) / WHEEL_DELTA, 0);

	UpdateVisibleRange();

	m_TextDoc->Unfreeze(NULL);

	return TRUE;
}
Example #5
0
/////////////////////////////////////////////////////////////////////////////
// add a system message
/////////////////////////////////////////////////////////////////////////////
void CChatControl::addSysMessage(CNetSysMessage *pMsg)
{
	int iColor;
	CString str;
	COLORREF cr;

	//get the formatted string
	str = getSysString(pMsg);

	//get the color
	iColor = pMsg->m_iColor;

	if(-1 == iColor)
	{
		cr = COLOR_WHITE;
	}
	else
	{
		cr = COLORS->getTextColor(iColor);
	}

	//write it bold
	addString(str, (-1 == iColor), cr);

	//scroll it
	LineScroll(1);
}
Example #6
0
/////////////////////////////////////////////////////////////////////////////
// add a chat message to the control
/////////////////////////////////////////////////////////////////////////////
void CChatControl::addMessage(CNetChatMessage *pMsg)
{
	CString str;
	COLORREF cr;

	//get the color
	cr = COLORS->getTextColor(pMsg->m_iColor);

	//get the player
	str = '\n';
	str += pMsg->m_strName;

	//write it bold
	addString(str, TRUE, cr);

	//get the message
	str = ": ";
	str += pMsg->m_strMessage;
	
	//write it normal
	addString(str, FALSE, cr);

	//scroll it
	LineScroll(1);
}
Example #7
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 ();
}
Example #8
0
void CEditExtn::OnSetFocus(CWnd* pOldWnd)
{
  m_bIsFocused = TRUE;
  CEdit::OnSetFocus(pOldWnd);
  if (m_lastposition >= 0) {
    int iLine = LineFromChar(m_lastposition);
    LineScroll(iLine);
    SetSel(m_nStartChar, m_nEndChar); 
  }
  Invalidate(TRUE);
}
void CHTRichEditCtrl::ScrollToLastLine(bool bForceLastLineAtBottom)
{
	if (bForceLastLineAtBottom)
	{
		int iFirstVisible = GetFirstVisibleLine();
		if (iFirstVisible > 0)
			LineScroll(-iFirstVisible);
	}

	// WM_VSCROLL does not work correctly under Win98 (or older version of comctl.dll)
	SendMessage(WM_VSCROLL, SB_BOTTOM);
}
Example #10
0
void CCmdShellEdit::AddText(LPCWSTR szText)
{
	int nLen = GetWindowTextLength();
	CString str ;
	this->GetWindowText(str);
	str += szText;
	SetWindowText(str);
	LineScroll(GetLineCount());
	SetFocus();
	SetSel(str.GetLength(), -1);
	m_TextdwLen = str.GetLength() + 1;
}
Example #11
0
BOOL CStatusCtrl::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
    OSVERSIONINFO info = {0};
    info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    GetVersionEx(&info);
    if (info.dwMajorVersion >= 5)
        return CRichEditCtrl::OnMouseWheel(nFlags, zDelta, pt);

    LineScroll(-zDelta / 120 * 3);

    return TRUE;
}
Example #12
0
void CRichEditExtn::OnSetFocus(CWnd* pOldWnd)
{
  m_bIsFocused = TRUE;
  CRichEditCtrl::OnSetFocus(pOldWnd);
  if (m_lastposition >= 0) {
    int iLine = LineFromChar(m_lastposition);
    LineScroll(iLine);
    SetSel(m_nStartChar, m_nEndChar); 
  }

  SetBackgroundColor(FALSE, m_crefInFocus);
  Invalidate(TRUE);
}
Example #13
0
//
//  Purpose:
//    Appends a text string to the history buffer.
//
//  Returns:
//    None.
//
void CHistoryEdit::AppendString(CString str)
{
	
	// Get current time
	static CString time, newstr;
	static SYSTEMTIME st;
	GetLocalTime(&st);
	time.Format("%04d-%02d-%02d %02d:%02d:%02d:%03d, ",st.wYear,st.wMonth,st.wDay,
		st.wHour,st.wMinute,st.wSecond,st.wMilliseconds);
	newstr = time + str + _T("\r\n");
	int   nLength = SendMessage(WM_GETTEXTLENGTH);
	SetSel(nLength, nLength);
    ReplaceSel(newstr);
	// Scroll the edit control
	LineScroll (GetLineCount(), 0);
}
/*
================
CSyntaxRichEditCtrl::FindNext
================
*/
bool CSyntaxRichEditCtrl::FindNext(const char *find, bool matchCase, bool matchWholeWords, bool searchForward)
{
	long selStart, selEnd, flags, search, length, start;
	tom::ITextRange *range;

	if (find[0] == '\0') {
		return false;
	}

	GetSel(selStart, selEnd);

	flags = 0;
	flags |= matchCase ? tom::tomMatchCase : 0;
	flags |= matchWholeWords ? tom::tomMatchWord : 0;

	if (searchForward) {
		m_TextDoc->Range(selEnd, GetTextLength(), &range);
		search = GetTextLength() - selEnd;
	} else {
		m_TextDoc->Range(0, selStart, &range);
		search = -selStart;
	}

	if (range->FindShit(A2BSTR(find), search, flags, &length) == S_OK) {

		m_TextDoc->Freeze(NULL);

		range->get_Start(&start);
		range->Release();

		SetSel(start, start + length);

		int line = Max((int) LineFromChar(start) - 5, 0);
		LineScroll(line - GetFirstVisibleLine(), 0);

		UpdateVisibleRange();

		m_TextDoc->Unfreeze(NULL);
		return true;
	} else {
		range->Release();
		return false;
	}
}
Example #15
0
void CHTRichEditCtrl::ScrollToLastLine(bool bForceLastLineAtBottom)
{
	if (bForceLastLineAtBottom)
	{
		int iFirstVisible = GetFirstVisibleLine();
		if (iFirstVisible > 0)
			LineScroll(-iFirstVisible);
	}

	// WM_VSCROLL does not work correctly under Win98 (or older version of comctl.dll)
	SendMessage(WM_VSCROLL, SB_BOTTOM);
	if (afxIsWin95())
	{
		// older version of comctl.dll seem to need this to properly update the display
		int iPos = GetScrollPos(SB_VERT);
		SendMessage(WM_VSCROLL, MAKELONG(SB_THUMBPOSITION, iPos));
		SendMessage(WM_VSCROLL, SB_ENDSCROLL);
	}
}
Example #16
0
void CHistoryEdit::AppendString
  (CString str)
//
//  Purpose:
//    Appends a text string to the history buffer.
//
//  Returns:
//    None.
//
{
CString   strBuffer;    // current contents of edit control

  // Append string
  GetWindowText (strBuffer);
  if (!strBuffer.IsEmpty())
     strBuffer += "\r\n";
  strBuffer += str;
  SetWindowText (strBuffer);

  // Scroll the edit control
  LineScroll (GetLineCount(), 0);
}
void CHTRichEditCtrl::AddLine(LPCTSTR pszMsg, int iLen, bool bLink, COLORREF cr, COLORREF bk, DWORD mask)
{
	int iMsgLen = (iLen == -1) ? _tcslen(pszMsg) : iLen;
	if (iMsgLen == 0)
		return;
#ifdef _DEBUG
	//	if (pszMsg[iMsgLen - 1] == _T('\n'))
	//		ASSERT( iMsgLen >= 2 && pszMsg[iMsgLen - 2] == _T('\r') );
#endif

	// Get Edit contents dimensions and cursor position
	long lStartChar, lEndChar;
	GetSel(lStartChar, lEndChar);
	int iSize = GetWindowTextLength();

	if (lStartChar == iSize && iSize == lEndChar)
	{
		// The cursor resides at the end of text
		SCROLLINFO si;
		si.cbSize = sizeof si;
		si.fMask = SIF_ALL;
		if (m_bAutoScroll && GetScrollInfo(SB_VERT, &si) && si.nPos >= (int)(si.nMax - si.nPage + 1))
		{
			// Not scrolled away
			SafeAddLine(iSize, pszMsg, iLen, lStartChar, lEndChar, bLink, cr, bk, mask);
			if (m_bAutoScroll && !IsWindowVisible())
				ScrollToLastLine();
		}
		else
		{
			// Reduce flicker by ignoring WM_PAINT
			m_bNoPaint = true;
			BOOL bIsVisible = IsWindowVisible();
			if (bIsVisible)
				SetRedraw(FALSE);

			// Remember where we are
			int iFirstLine = !m_bAutoScroll ? GetFirstVisibleLine() : 0;

			// Select at the end of text and replace the selection
			// This is a very fast way to add text to an edit control
			SafeAddLine(iSize, pszMsg, iLen, lStartChar, lEndChar, bLink, cr, bk, mask);
			//if (m_bAutoScroll && lStartChar == lEndChar)
			//	lStartChar = lEndChar = -1;
			SetSel(lStartChar, lEndChar); // Restore our previous selection

			if (!m_bAutoScroll)
				LineScroll(iFirstLine - GetFirstVisibleLine());
			else
				ScrollToLastLine();

			m_bNoPaint = false;
			if (bIsVisible){
				SetRedraw();
				if (m_bRichEdit)
					Invalidate();
			}
		}
	}
	else
	{
		// We should add the text anyway...

		// Reduce flicker by ignoring WM_PAINT
		m_bNoPaint = true;
		BOOL bIsVisible = IsWindowVisible();
		if (bIsVisible)
			SetRedraw(FALSE);

		// Remember where we are
		int iFirstLine = !m_bAutoScroll ? GetFirstVisibleLine() : 0;
		// Very annoying problems with EM_GETSCROLLPOS/EM_SETSCROLLPOS. Depending
		// on the amount of data in the control, the control may start to scroll up
		// by itself(!!) -- obviously because of some internal rounding errors..
		//
		// Using 'LineScroll' also gives glitches (also depending on the amount of
		// data stored in the control), but at least it doesn't start to show some 'life'
		/*POINT ptScrollPos;
		if (!m_bAutoScroll)
			SendMessage(EM_GETSCROLLPOS, 0, (LPARAM)&ptScrollPos);*/

		if (lStartChar != lEndChar)
		{
			// If we are currently selecting some text, we have to find out
			// if the caret is near the beginning of this block or near the end.
			// Note that this does not always work. Because of the EM_CHARFROMPOS
			// message returning only 16 bits this will fail if the user has selected
			// a block with a length dividable by 64k.

			// NOTE: This may cause a lot of terrible CRASHES within the RichEdit control when used for a RichEdit control!?
			// To reproduce the crash: click in the RE control while it's drawing a line and start a selection!
			if (!m_bRichEdit){
				CPoint pt;
				::GetCaretPos(&pt);
				int iCaretPos = CharFromPos(pt);
				if (abs((lStartChar % 0xffff - iCaretPos)) < abs((lEndChar % 0xffff - iCaretPos)))
				{
					iCaretPos = lStartChar;
					lStartChar = lEndChar;
					lEndChar = iCaretPos;
				}
			}
		}

		// Note: This will flicker, if someone has a good idea how to prevent this - let me know

		// Select at the end of text and replace the selection
		// This is a very fast way to add text to an edit control
		SafeAddLine(iSize, pszMsg, iLen, lStartChar, lEndChar, bLink, cr, bk, mask);
		//if (m_bAutoScroll && lStartChar == lEndChar)
		//	lStartChar = lEndChar = -1;
		SetSel(lStartChar, lEndChar); // Restore our previous selection

		if (!m_bAutoScroll){
			LineScroll(iFirstLine - GetFirstVisibleLine());
			//SendMessage(EM_SETSCROLLPOS, 0, (LPARAM)&ptScrollPos);
		}
		else
			ScrollToLastLine();

		m_bNoPaint = false;
		if (bIsVisible){
			SetRedraw();
			if (m_bRichEdit)
				Invalidate();
		}
	}
}
Example #18
0
bool kexConsole::ProcessInput(const event_t *ev) {
    if(ev->type == ev_mousedown || ev->type == ev_mouseup ||
        ev->type == ev_mouse) {
            return false;
    }

    if(ev->type == ev_mousewheel && state == CON_STATE_DOWN) {
        switch(ev->data1) {
            case KM_BUTTON_SCROLL_UP:
                LineScroll(1);
                break;
            case KM_BUTTON_SCROLL_DOWN:
                LineScroll(0);
                break;
        }

        return true;
    }

    CheckShift(ev);
    CheckStickyKeys(ev);

    int c = ev->data1;

    switch(state) {
        case CON_STATE_DOWN:
            if(ev->type == ev_keydown) {
                switch(c) {
                    case KKEY_BACKQUOTE:
                        state = CON_STATE_UP;
                        inputSystem->MouseCenter();
                        return true;
                    case KKEY_RETURN:
                        ParseInput();
                        return true;
                    case KKEY_UP:
                        GetHistory(false);
                        return true;
                    case KKEY_DOWN:
                        GetHistory(true);
                        return true;
                    case KKEY_TAB:
                        cvarManager.AutoComplete(typeStr);
                        command.AutoComplete(typeStr);
                        return true;
                    default:
                        ParseKey(c);
                        return true;
                }

                return false;
            }
            break;
        case CON_STATE_UP:
            if(ev->type == ev_keydown) {
                switch(c) {
                    case KKEY_BACKQUOTE:
                        state = CON_STATE_DOWN;
                        return true;
                    default:
                        break;
                }

                return false;
            }
            break;
        default:
            return false;
    }

    return false;
}
bool CFulEditCtrl::AddLine(const tstring & line, bool aTimeStamps) {
	bool noScroll = false;
	matchedTab = false;
	timeStamps = aTimeStamps;

	tstring aLine = Util::replace(line, _T("\r\n"), _T("\r"));
	if(GetWindowTextLength() > SETTING(CHATBUFFERSIZE)) {
		SetRedraw(FALSE);
		int ch = LineIndex(LineFromChar(2000));
		SetSel(0, ch);
		ReplaceSel(_T(""));
		UpdateUrlRanges(ch);
		SetSel(GetTextLengthEx(GTL_NUMCHARS), GetTextLengthEx(GTL_NUMCHARS));
		ScrollCaret();
		SetRedraw(TRUE);
	}
	if(Util::strnicmp(_T("<") + nick + _T(">"), aLine, nick.length() + 2) == 0)
		skipLog = true;

	if(isSet(STRIP_ISP) && aLine[0] == _T('<')) {
		tstring::size_type end = aLine.find(_T(">"));
		if( end != tstring::npos ) {
			tstring::size_type pos = aLine.rfind(_T("]"), end);
			if( end > 0 && (end-1) == pos )
				pos = aLine.rfind(_T("]"), pos-1);
			
			if(pos != string::npos) 
				aLine = _T("<") + aLine.substr(pos+1);
		}
	}
		
	tstring::size_type pos = aLine.find(_T("> /me "));
	if( pos != tstring::npos)
		aLine = _T("** ") + aLine.substr(1, pos-1) +  aLine.substr(pos+5, aLine.length());

	if(timeStamps)
		aLine = _T("[") + Util::getShortTimeString() + _T("] ") + aLine;
	
	
	SetRedraw(FALSE);
	
	//Get the pos of the last char
	POINT pt = PosFromChar(GetTextLengthEx(GTL_NUMCHARS));
	CRect rc;
	GetClientRect(&rc);
	int l = -1;

	//check if the last char is visible, if not then save the
	//scrollbar position
	if(rc.PtInRect(pt)){
		noScroll = false;
	} else {
		noScroll = true;
		l = GetFirstVisibleLine();
	}
    
	AddInternalLine(aLine);
				
	//restore the scrollbar position
	if(noScroll) {
		LineScroll(l - GetFirstVisibleLine());
	} 

	SetRedraw();
	Invalidate();
	UpdateWindow();

	return matchedTab;
}
Example #20
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;
}
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 FZ_LOG_STATUS:
		//str.LoadString(IDS_STATUSMSG_PREFIX);
		str += "\\cf2";
		break;
	case FZ_LOG_ERROR:
		//str.LoadString(IDS_ERRORMSG_PREFIX);
		str="\\cf5";
		break;
	case FZ_LOG_COMMAND:
		//str.LoadString(IDS_COMMANDMSG_PREFIX);
		str="\\cf3";
		break;
	case FZ_LOG_REPLY:
		//str.LoadString(IDS_RESPONSEMSG_PREFIX);
		str="\\cf4";
		break;
	case FZ_LOG_LIST:
		//str.LoadString(IDS_TRACEMSG_TRACE);
		str="\\cf11";
		break;
	case FZ_LOG_APIERROR:
	case FZ_LOG_WARNING:
	case FZ_LOG_INFO:
	case FZ_LOG_DEBUG:
		//str.LoadString(IDS_TRACEMSG_TRACE);
		str="\\cf7";
		break;
	}

	CString tmp;
	tmp += str;
	tmp += "\\tab ";
	tmp += status;
	status = tmp;

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


	EDITSTREAM es;

	string s = Util::ws2s(wstring(rtfstr));
	es.dwCookie = (DWORD)&s;	// Pass a pointer to the string 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);
		}
	}

}
Example #22
0
/*----------------------------------------------------------------------------------------------
	This processes Windows messages on the window. In general, it normally calls the
	appropriate method on the edit class.
----------------------------------------------------------------------------------------------*/
bool TssEdit::FWndProc(uint wm, WPARAM wp, LPARAM lp, long & lnRet)
{
	bool fRet;

	switch (wm)
	{
	case WM_GETDLGCODE:
		// This is essential when embedded in a dialog to tell the dialog manager that it
		// wants to get key strokes. (We could try DLGC_WANTALLKEYS but I think we would then
		// get the Tab and Return keys...we may get them anyway with this combination...)
		// The last value tells Windows that when tabbing to this control we should use
		// EM_SETSEL to select all the text.
		lnRet = DLGC_WANTCHARS | DLGC_WANTARROWS | DLGC_HASSETSEL;
		return true;
	case EM_GETLINE:	// Use FW_EM_GETLINE.
	case EM_REPLACESEL:	// Use FW_EM_REPLACESEL.
		// We don't support these methods. Use the replacement TsString versions instead.
		Assert(false);
		lnRet = LB_ERR;
		return true;

	// NOTE: DO NOT send this message to a TssEdit if you want the actual text. Send the
	// FW_EM_GETTEXT message instead. This method is required for TssEdit controls on a
	// dialog because Windows will send the message to the control anytime the user hits a
	// key.
	case WM_GETTEXT:
		{
			ITsStringPtr qtss;
			GetText(&qtss);
			const wchar * pwrgch;
			int cch;
			HRESULT hr;
			IgnoreHr(hr = qtss->LockText(&pwrgch, &cch));
			if (FAILED(hr))
				return true;
			StrApp str(pwrgch, cch);
			qtss->UnlockText(pwrgch);
			lnRet = Min(cch + 1, (int)wp);
			achar * psz = reinterpret_cast<achar *>(lp);
			StrCpyN(psz, str.Chars(), lnRet);
		}
		return true;

	// NOTE: You should be sending an FW_EM_SETTEXT message instead of this.
	case WM_SETTEXT:
		{
			achar * psz = reinterpret_cast<achar *>(lp);
			StrUni stu(psz);
			ITsStrFactoryPtr qtsf;
			qtsf.CreateInstance(CLSID_TsStrFactory);
			ITsStringPtr qtss;
			CheckHr(qtsf->MakeStringRgch(stu.Chars(), stu.Length(), m_wsBase, &qtss));
			SetText(qtss);
		}
		return true;

	case EM_CANUNDO:
	case EM_CHARFROMPOS:
	case EM_EMPTYUNDOBUFFER:
	case EM_FMTLINES:
	case EM_GETFIRSTVISIBLELINE:
	case EM_GETHANDLE:
	case EM_GETMODIFY:
	case EM_GETPASSWORDCHAR:
	case EM_GETRECT:
	case EM_GETTHUMB:
	case EM_GETWORDBREAKPROC:
	case EM_POSFROMCHAR:
	case EM_SETHANDLE:
	case EM_SETMODIFY:
	case EM_SETPASSWORDCHAR:
	case EM_SETRECT:
	case EM_SETRECTNP:
	case EM_SETTABSTOPS:
	case EM_SETWORDBREAKPROC:
	case EM_UNDO:
	case WM_GETFONT:
	case WM_SETFONT:
		// We don't support these methods.
		Assert(false);
		lnRet = LB_ERR;
		return true;

	case EM_GETLIMITTEXT:
		lnRet = GetLimitText();
		return true;

	case FW_EM_GETLINE:
		lnRet = GetLine(wp, (ITsString **)lp);
		return true;

	case EM_GETLINECOUNT:
		lnRet = GetLineCount();
		return true;

	case EM_GETMARGINS:
		lnRet = GetMargins();
		return true;

	case FW_EM_GETSTYLE:
		GetStyle((StrUni *)lp, (COLORREF *)wp);
		return true;

	case EM_GETSEL:
		lnRet = GetSel((int *)wp, (int *)lp);
		return true;

	case EM_LINEFROMCHAR:
		lnRet = LineFromChar(wp);
		return true;

	case EM_LINEINDEX:
		lnRet = LineIndex(wp);
		return true;

	case EM_LINELENGTH:
		lnRet = LineLength(wp);
		return true;

	case EM_LINESCROLL:
		LineScroll(lp, wp);
		return true;

	case FW_EM_REPLACESEL:
		ReplaceSel((ITsString *)lp);
		return true;

	case EM_SCROLL:
		lnRet = ::SendMessage(m_hwnd, WM_VSCROLL, LOWORD(wp), 0);
		return true;

	case EM_SCROLLCARET:
		ScrollCaret();
		return true;

	case EM_SETLIMITTEXT:
		SetLimitText(wp);
		return true;

	case EM_SETMARGINS:
		SetMargins(wp, LOWORD(lp), HIWORD(lp));
		return true;

	case EM_SETREADONLY:
		SetReadOnly(wp);
		return true;

	case EM_SETSEL:
		SetSel(wp, lp);
		return true;

	case FW_EM_SETSTYLE:
		SetStyle((StrUni *)lp, (COLORREF)wp);
		return true;

	case WM_GETTEXTLENGTH:
		lnRet = GetTextLength();
		return true;

	case FW_EM_GETTEXT:
		GetText((ITsString **)lp);
		return true;

	case FW_EM_SETTEXT:
		SetText((ITsString *)lp);
		return true;

	case WM_COPY:
		Copy();
		return true;

	case WM_CUT:
		Cut();
		return true;

	case WM_PASTE:
		Paste();
		return true;

	case WM_HSCROLL:
		if (!OnHScroll(LOWORD(wp), HIWORD(wp), (HWND)lp))
		{
			::SendMessage(::GetParent(m_hwnd), WM_COMMAND,
				MAKEWPARAM(::GetDlgCtrlID(m_hwnd), EN_HSCROLL), (LPARAM)m_hwnd);
		}
		return true;

	case WM_VSCROLL:
		if (!OnVScroll(LOWORD(wp), HIWORD(wp), (HWND)lp))
		{
			::SendMessage(::GetParent(m_hwnd), WM_COMMAND,
				MAKEWPARAM(::GetDlgCtrlID(m_hwnd), EN_VSCROLL), (LPARAM)m_hwnd);
		}
		return true;

	case WM_KILLFOCUS:
		if (!OnKillFocus((HWND)wp))
		{
			::SendMessage(::GetParent(m_hwnd), WM_COMMAND,
				MAKEWPARAM(::GetDlgCtrlID(m_hwnd), EN_KILLFOCUS), (LPARAM)m_hwnd);
		}
		return true;

	case WM_SETFOCUS:
		if (!OnSetFocus((HWND)wp))
		{
			::SendMessage(::GetParent(m_hwnd), WM_COMMAND,
				MAKEWPARAM(::GetDlgCtrlID(m_hwnd), EN_SETFOCUS), (LPARAM)m_hwnd);
		}
		return true;
		// Calling SuperClass here causes two OnSetFocus calls for each OnKillFocus.
		//return SuperClass::FWndProc(wm, wp, lp, lnRet);

	case WM_CHAR:
		fRet = false;
		if (wp == VK_TAB)  // '\t'
		{
			fRet = OnCharTab();
		}
		else if (wp == VK_RETURN) // '\r'
		{
			fRet = OnCharEnter();
		}
		else if (wp == VK_ESCAPE) // '\33'
		{
			fRet = OnCharEscape();
		}
		if (fRet)
			return fRet;
		else
			return SuperClass::FWndProc(wm, wp, lp, lnRet);

	case WM_LBUTTONDOWN:
	case WM_LBUTTONUP:
	case WM_MBUTTONDOWN:
	case WM_MBUTTONUP:
	case WM_RBUTTONDOWN:
	case WM_RBUTTONUP:
	case WM_MOUSEMOVE:
		if (HasToolTip())
		{
			// Notify the tooltip belonging to the parent toolbar of the mouse message.
			Assert(m_hwndToolTip);
			MSG msg;
			msg.hwnd = m_hwnd; // ::GetParent(m_hwnd);
			msg.message = wm;
			msg.wParam = wp;
			msg.lParam = lp;
			::SendMessage(m_hwndToolTip, TTM_RELAYEVENT, 0, (LPARAM)&msg);
		}
		break;

	default:
		break;
	}
	return SuperClass::FWndProc(wm, wp, lp, lnRet);
}
Example #23
0
//////////////////////////////////////////////////////////////////////////////
// This function is based on Daniel Lohmann's article "CEditLog - fast logging
// into an edit control with cout" at http://www.codeproject.com
void CLogEditCtrl::AddLine(LPCTSTR pszMsg, int iLen)
{
	int iMsgLen = (iLen == -1) ? _tcslen(pszMsg) : iLen;
	if (iMsgLen == 0)
		return;
#ifdef _DEBUG
	if (pszMsg[iMsgLen - 1] == _T('\n'))
		ASSERT( iMsgLen >= 2 && pszMsg[iMsgLen - 2] == _T('\r') );
#endif

	// Get Edit contents dimensions and cursor position
	int iStartChar, iEndChar;
	GetSel(iStartChar, iEndChar);
	int iWndTxtLen = GetWindowTextLength();

	if (iStartChar == iWndTxtLen && iWndTxtLen == iEndChar)
	{
		// The cursor resides at the end of text
		SCROLLINFO si;
		si.cbSize = sizeof si;
		si.fMask = SIF_ALL;
		if (m_bAutoScroll && GetScrollInfo(SB_VERT, &si) && si.nPos >= (int)(si.nMax - si.nPage + 1))
		{
			// Not scrolled away
			SafeAddLine(iWndTxtLen, iMsgLen, pszMsg, iStartChar, iEndChar);
			if (m_bAutoScroll && !IsWindowVisible())
				ScrollToLastLine();
		}
		else
		{
			// Reduce flicker by ignoring WM_PAINT
			m_bNoPaint = true;
			BOOL bIsVisible = IsWindowVisible();
			if (bIsVisible)
				SetRedraw(FALSE);

			// Remember where we are
			int nFirstLine = !m_bAutoScroll ? GetFirstVisibleLine() : 0;
		
			// Select at the end of text and replace the selection
			// This is a very fast way to add text to an edit control
			SafeAddLine(iWndTxtLen, iMsgLen, pszMsg, iStartChar, iEndChar);
			SetSel(iStartChar, iEndChar, TRUE); // Restore our previous selection

			if (!m_bAutoScroll)
				LineScroll(nFirstLine - GetFirstVisibleLine());
			else
				ScrollToLastLine();

			m_bNoPaint = false;
			if (bIsVisible){
				SetRedraw();
				if (m_bRichEdit)
					Invalidate();
			}
		}
	}
	else
	{
		// We should add the text anyway...

		// Reduce flicker by ignoring WM_PAINT
		m_bNoPaint = true;
		BOOL bIsVisible = IsWindowVisible();
		if (bIsVisible)
			SetRedraw(FALSE);

		// Remember where we are
		int nFirstLine = !m_bAutoScroll ? GetFirstVisibleLine() : 0;
	
		if (iStartChar != iEndChar)
		{
			// If we are currently selecting some text, we have to find out
			// if the caret is near the beginning of this block or near the end.
			// Note that this does not always work. Because of the EM_CHARFROMPOS
			// message returning only 16 bits this will fail if the user has selected 
			// a block with a length dividable by 64k.

			// NOTE: This may cause a lot of terrible CRASHES within the RichEdit control when used for a RichEdit control!?
			// To reproduce the crash: click in the RE control while it's drawing a line an start a selection!
			if (!m_bRichEdit){
			    CPoint pt;
			    ::GetCaretPos(&pt);
			    int nCaretPos = CharFromPos(pt);
			    if (abs((iStartChar % 0xffff - nCaretPos)) < abs((iEndChar % 0xffff - nCaretPos)))
			    {
				    nCaretPos = iStartChar;
				    iStartChar = iEndChar;
				    iEndChar = nCaretPos;
			    }
		    }
		}

		// Note: This will flicker, if someone has a good idea how to prevent this - let me know
		
		// Select at the end of text and replace the selection
		// This is a very fast way to add text to an edit control
		SafeAddLine(iWndTxtLen, iMsgLen, pszMsg, iStartChar, iEndChar);
		SetSel(iStartChar, iEndChar, TRUE); // Restore our previous selection

		if (!m_bAutoScroll)
			LineScroll(nFirstLine - GetFirstVisibleLine());
		else
			ScrollToLastLine();

		m_bNoPaint = false;
		if (bIsVisible){
			SetRedraw();
			if (m_bRichEdit)
				Invalidate();
		}
	}
}
Example #24
0
void CLogEditCtrl::ScrollToLastLine()
{
	// WM_VSCROLL does not work correctly under Win98 (or older version of comctl.dll)
	//SendMessage(WM_VSCROLL, SB_BOTTOM, 0);
	LineScroll(GetLineCount());
}