int CUrlRichEditCtrl::FindUrlEx(const CPoint& point)
{
	int nUrl = m_aUrls.GetSize();
	
	while (nUrl--)
	{
		const URLITEM& urli = m_aUrls[nUrl];

		CRect rUrl(GetCharPos(urli.cr.cpMin), GetCharPos(urli.cr.cpMax));

		rUrl.bottom += GetLineHeight();
		
		if (rUrl.PtInRect(point))
			return nUrl;
	}

	// not found
	return -1;
}
Beispiel #2
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);
		}
	}

}
Beispiel #4
0
void CMyRichEdit::OnRButtonDown(UINT nFlags, CPoint point)
{
    // TODO: 在此添加消息处理程序代码和/或调用默认值
    LONG lCharHeight;
    CHARFORMAT cf;
    memset(&cf, 0, sizeof(CHARFORMAT));
    GetDefaultCharFormat(cf);
    
    //int nline = GetLineCount();

    int StartIndex = LineIndex(0);  
    int EndIndex = LineIndex(1);  
    if (EndIndex != -1)  
    {
        CPoint LinePoint = GetCharPos(StartIndex);
        CPoint AfterPoint = GetCharPos(EndIndex);
        lCharHeight = AfterPoint.y - LinePoint.y;
    }else
    {
        lCharHeight = cf.yHeight/15;
    }

    //设置为焦点
    SetFocus();
    //创建一个弹出式菜单
    CMenu popmenu;
    popmenu.CreatePopupMenu();
    //添加菜单项目
    //popmenu.AppendMenu(0, ID_RICH_UNDO, "&Undo");
    //popmenu.AppendMenu(0, MF_SEPARATOR);
    //popmenu.AppendMenu(0, ID_RICH_CUT, "&Cut");
    popmenu.AppendMenu(0, ID_RICH_COPY, _T("复制"));
    //popmenu.AppendMenu(0, ID_RICH_PASTE, "&Paste");
    popmenu.AppendMenu(0, ID_RICH_SELECTALL, _T("选择全部内容"));
    popmenu.AppendMenu(0, MF_SEPARATOR);
    popmenu.AppendMenu(0, ID_RICH_CLEAR, _T("清空全部内容"));
    //popmenu.AppendMenu(0, MF_SEPARATOR);
    //popmenu.AppendMenu(0, ID_RICH_SETFONT, "Select &Font");

    //初始化菜单项
    //UINT nUndo=(CanUndo() ? 0 : MF_GRAYED );
    //popmenu.EnableMenuItem(ID_RICH_UNDO, MF_BYCOMMAND|nUndo);

    CPoint CurrPoint;
    CurrPoint = GetCaretPos();
    long nStartChar;
    long nEndChar;
    GetSel(nStartChar, nEndChar);
    CPoint startPoint;
    CPoint endPoint;
    startPoint = GetCharPos(nStartChar);            // Gets the position (top-left corner) of a given character within this CRichEditCtrl
    endPoint = GetCharPos(nEndChar);

    if(point.y < startPoint.y || point.y > endPoint.y + lCharHeight 
        || (point.x < startPoint.x && point.y > startPoint.y && point.y < startPoint.y + lCharHeight)
        || (point.x > endPoint.x && point.y > endPoint.y && point.y < endPoint.y + lCharHeight))
    {
        //SetSel(0, -1);
        SetSel(-1, 0);                          // 取消文本选中
    }

    CurrPoint.y = point.y/lCharHeight*lCharHeight;
    CurrPoint.x = point.x;
    SetCaretPos(CurrPoint);
    //char chTT[100];
    //sprintf_s(chTT, "y: %d startY: %d endY: %d", CurrPoint.y, startPoint.y, endPoint.y);
    //OutputDebugStringA(chTT);

    UINT nSel=((GetSelectionType()!=SEL_EMPTY) ? 0 : MF_GRAYED) ;
    //popmenu.EnableMenuItem(ID_RICH_CUT, MF_BYCOMMAND|nSel);
    popmenu.EnableMenuItem(ID_RICH_COPY, MF_BYCOMMAND|nSel);
    //popmenu.EnableMenuItem(ID_RICH_CLEAR, MF_BYCOMMAND|nSel);

    //UINT nPaste=(CanPaste() ? 0 : MF_GRAYED) ;
    //popmenu.EnableMenuItem(ID_RICH_PASTE, MF_BYCOMMAND|nPaste);

    //显示菜单
    CPoint pt;
    GetCursorPos(&pt);
    popmenu.TrackPopupMenu(TPM_RIGHTBUTTON, pt.x, pt.y, this);
    popmenu.DestroyMenu();

    CRichEditCtrl::OnRButtonDown(nFlags, point);
}