Exemplo n.º 1
0
void LogViewRE::LogExtro()
{
  // reset color
  CHARFORMAT cf = {0};
  cf.cbSize = sizeof(CHARFORMAT);
  cf.dwMask = CFM_COLOR;
  cf.crTextColor = LOG_DEFAULTCOLOR;
  SetSelectionCharFormat(cf);
  AppendText(_T("\r\n"));
}
Exemplo n.º 2
0
void CRichEditCtrlGS::SetFontSize(int nPointSize)
{ CHARFORMAT cf;
  cf.cbSize = sizeof(CHARFORMAT);
  cf.dwMask = CFM_SIZE;
  GetSelectionCharFormat(cf);
  nPointSize *= 20;	// convert from points to twips
  cf.yHeight = nPointSize;
  cf.dwMask = CFM_SIZE;
  SetSelectionCharFormat(cf);
}
Exemplo n.º 3
0
void CRichEditCtrlGS::SetColour(COLORREF color)
{ CHARFORMAT cf;
  cf.cbSize = sizeof(CHARFORMAT);
  cf.dwMask = CFM_COLOR;

  GetSelectionCharFormat(cf);
  cf.crTextColor = color;
  if( cf.dwEffects & CFE_AUTOCOLOR )
    { cf.dwEffects ^= CFE_AUTOCOLOR;
	}
  SetSelectionCharFormat(cf);
}
void CAutoRichEditCtrl::SetFontName(CString sFontName)
{
	CHARFORMAT cf = GetCharFormat();

	// Set the font name.
	for (int i = 0; i <= sFontName.GetLength()-1; i++)
		cf.szFaceName[i] = sFontName[i];


	cf.dwMask = CFM_FACE;

	SetSelectionCharFormat(cf);
}
Exemplo n.º 5
0
void CRichEditCtrlGS::SetFontName(const CString strFontName)
{ CHARFORMAT cf;
  cf.cbSize = sizeof(CHARFORMAT);
  cf.dwMask = CFM_FACE;
  GetSelectionCharFormat(cf);
  CString strName = strFontName.Left(31);  
  int i;
  for (i = 0; i <= strName.GetLength()-1; i++)
		cf.szFaceName[i] = strName[i];

  cf.szFaceName[i]='\0';
  cf.dwMask = CFM_FACE;
  SetSelectionCharFormat(cf);
}
void CAutoRichEditCtrl::SetSelectTextColor(COLORREF color)
{
	CString floatstrnumber;
	GetWindowText(floatstrnumber);
	SetSel(0,floatstrnumber.GetLength());
	CHARFORMAT cf = GetCharFormat();

	if (cf.dwEffects & CFE_AUTOCOLOR) cf.dwEffects -= CFE_AUTOCOLOR;
	cf.crTextColor =color;
	cf.dwMask = CFM_COLOR;


	SetSelectionCharFormat(cf);
}
void CAutoRichEditCtrl::SetFontSize(int nPointSize)
{
	CString floatstrnumber;
	int size=nPointSize;
	GetWindowText(floatstrnumber);
	SetSel(0,floatstrnumber.GetLength());
	CHARFORMAT cf = GetCharFormat();

	nPointSize *= 20;	// convert from to twips
	cf.yHeight = nPointSize;
	
	cf.dwMask = CFM_SIZE;

	SetSelectionCharFormat(cf);
}
Exemplo n.º 8
0
void CTWScriptEdit::OnSelectfont() 
{
	// TODO: Add your command handler code here
	CHARFORMAT cf;
	LOGFONT lf;
	memset(&cf, 0, sizeof(CHARFORMAT));
	memset(&lf, 0, sizeof(LOGFONT));
	//判断是否选择了内容
	BOOL m_bSelect = (GetSelectionType() != SEL_EMPTY) ? TRUE : FALSE;
	if (m_bSelect)
	{
		GetSelectionCharFormat(cf);
	}
	else
	{
		GetDefaultCharFormat(cf);
	}
	//得到相关字体属性
	BOOL bIsBold = cf.dwEffects & CFE_BOLD;
	BOOL bIsItalic = cf.dwEffects & CFE_ITALIC;
	BOOL bIsUnderline = cf.dwEffects & CFE_UNDERLINE;
	BOOL bIsStrickout = cf.dwEffects & CFE_STRIKEOUT;
	//设置属性
	lf.lfCharSet = cf.bCharSet;
	lf.lfHeight = cf.yHeight/15;
	lf.lfPitchAndFamily = cf.bPitchAndFamily;
	lf.lfItalic = bIsItalic;
	lf.lfWeight = (bIsBold ? FW_BOLD : FW_NORMAL);
	lf.lfUnderline = bIsUnderline;
	lf.lfStrikeOut = bIsStrickout;
	sprintf(lf.lfFaceName, cf.szFaceName);

	CFontDialog dlg(&lf);
	dlg.m_cf.rgbColors = cf.crTextColor;
	if (dlg.DoModal() == IDOK)
	{
		dlg.GetCharFormat(cf);//获得所选字体的属性
		if (m_bSelect) 
			SetSelectionCharFormat(cf);	//为选定的内容设定所选字体
		else
			SetWordCharFormat(cf);	//为将要输入的内容设定字体
	}



}
Exemplo n.º 9
0
void CEditCtrl::SetText(const CString& text, COLORREF color)
{
  CHARFORMAT cf;
  ::memset(&cf, 0, sizeof(CHARFORMAT));
  cf.cbSize = sizeof(CHARFORMAT);
  cf.dwMask = CFM_COLOR;
  cf.crTextColor = color;

  int iTotalLength = GetWindowTextLength();

  HideSelection(TRUE, TRUE);
  SetSel(iTotalLength, iTotalLength);
  SetSelectionCharFormat(cf);
  ReplaceSel((LPCTSTR)text);

  HideSelection(FALSE, TRUE);
}
Exemplo n.º 10
0
void CRichEditCtrlGS::SetLink(void)
{ CHARFORMAT cf;
  cf.cbSize = sizeof(CHARFORMAT);
  cf.dwMask = CFM_LINK;
 
  DWORD dwSelMask = GetSelectionCharFormat(cf);
  // If selection is all the same toggle PROTECTED style
  // turn it on otherwise over the whole selection
  if( (cf.dwMask & CFM_LINK) & (dwSelMask & CFM_LINK) )
	{ cf.dwEffects ^= CFE_LINK; 
	}
  else
	{ cf.dwEffects |= CFE_LINK;
	}
  cf.dwMask = CFM_LINK;
  SetSelectionCharFormat(cf);
}
Exemplo n.º 11
0
void CRichEditCtrlGS::SetStrikeout(void)
{ CHARFORMAT cf;
  cf.cbSize = sizeof(CHARFORMAT);
  cf.dwMask = CFM_STRIKEOUT;
 
  DWORD dwSelMask = GetSelectionCharFormat(cf);
  // If selection is all the same toggle STRIKEOUT style
  // turn it on otherwise over the whole selection
  if( (cf.dwMask & CFM_STRIKEOUT) & (dwSelMask & CFM_STRIKEOUT) )
	{ cf.dwEffects ^= CFE_STRIKEOUT; 
	}
  else
	{ cf.dwEffects |= CFE_STRIKEOUT;
	}
  cf.dwMask = CFM_STRIKEOUT;
  SetSelectionCharFormat(cf);
}
Exemplo n.º 12
0
void CRichEditCtrlGS::SetUnderlined(void)
{ CHARFORMAT cf;
  cf.cbSize = sizeof(CHARFORMAT);
  cf.dwMask = CFM_UNDERLINE;
 
  DWORD dwSelMask = GetSelectionCharFormat(cf);
  // If selection is all the same toggle UNDERLINE style
  // turn it on otherwise over the whole selection
  if( (cf.dwMask & CFM_UNDERLINE) & (dwSelMask & CFM_UNDERLINE) )
	{ cf.dwEffects ^= CFE_UNDERLINE; 
	}
  else
	{ cf.dwEffects |= CFE_UNDERLINE;
	}
  cf.dwMask = CFM_UNDERLINE;
  SetSelectionCharFormat(cf);
}
Exemplo n.º 13
0
void CRichEditCtrlGS::SetItalic(void)
{ CHARFORMAT cf;
  cf.cbSize = sizeof(CHARFORMAT);
  cf.dwMask = CFM_ITALIC;
 
  DWORD dwSelMask = GetSelectionCharFormat(cf);
  // If selection is all the same toggle ITALIC style
  // turn it on otherwise over the whole selection
  if( (cf.dwMask & CFM_ITALIC) & (dwSelMask & CFM_ITALIC) )
	{ cf.dwEffects ^= CFE_ITALIC; 
	}
  else
	{ cf.dwEffects |= CFE_ITALIC;
	}
  cf.dwMask = CFM_ITALIC;
  SetSelectionCharFormat(cf);
}
void CAutoRichEditCtrl::SelectColor()
{
	CColorDialog dlg;

	CHARFORMAT cf = GetCharFormat();

	if (cf.dwEffects & CFE_AUTOCOLOR) cf.dwEffects -= CFE_AUTOCOLOR;

	// Get a color from the common color dialog.
	if( dlg.DoModal() == IDOK )
	{	
		cf.crTextColor = dlg.GetColor();
	}

	cf.dwMask = CFM_COLOR;

	SetSelectionCharFormat(cf);
}
void CAutoRichEditCtrl::SetCharStyle(int MASK, int STYLE, int nStart, int nEnd)
{
	CHARFORMAT cf;
	cf.cbSize = sizeof(CHARFORMAT);
	//cf.dwMask = MASK;
	
	GetSelectionCharFormat(cf);
	
	if (cf.dwMask & MASK)	// selection is all the same
	{
		cf.dwEffects ^= STYLE; 
	}
	else
	{
		cf.dwEffects |= STYLE;
	}
	
	cf.dwMask = MASK;

	SetSelectionCharFormat(cf);

}
Exemplo n.º 16
0
void CTWScriptEdit::SetFormatRange(int nStart, int nEnd, BOOL bBold, COLORREF clr)
{
	if (nStart >= nEnd)
		return;

	SetSel(nStart, nEnd);

	DWORD dwEffects = bBold?CFE_BOLD:0;

	CHARFORMAT cfm;
	cfm.cbSize = sizeof(cfm);
    GetSelectionCharFormat(cfm);
	
	if ((cfm.dwMask & CFM_COLOR)  && cfm.crTextColor == clr && 
		(cfm.dwMask & CFM_BOLD) && (cfm.dwEffects & CFE_BOLD) == dwEffects)
		return;

	cfm.dwEffects = dwEffects;
	cfm.crTextColor = clr;
	cfm.dwMask = CFM_BOLD | CFM_COLOR;

	SetSelectionCharFormat(cfm);
}
Exemplo n.º 17
0
void CSMLStatic::InsertDocument()
{
	if(FALSE == ::IsWindow(m_hWnd)) {
		return;
	}

	CSMLDoc::CSMLTextGroup				*group;
	CSMLDoc::CSMLTextGroup::CSMLTextBlock	*blk;
	int			grpCount;
	int			grpIndex;
	int			blkCount;
	int			blkIndex;

	// Make sure we can insert text to the rich edit control
	SetReadOnly(FALSE);
	SetSel(0, -1);
	Clear();

	// If a SML document is not present, set the plain text and return
	if(NULL == m_Document) {
		ReplaceSel(m_Text, FALSE);
		return;
	}

	// Set the background color to the document
	SetBackgroundColor(FALSE, m_Document->GetBkgndColor());

	// Step through all text groups
	grpCount = m_Document->GetGroupCount();
	for(grpIndex = 0; grpIndex < grpCount; grpIndex++) {
		PARAFORMAT	format;
		DWORD		style;
		group = m_Document->GetTextGroup(grpIndex);

		blkCount = group->GetBlockCount();

		// Get the default font information for the group
		format.cbSize = sizeof(format);
		format.dwMask = PFM_ALIGNMENT;
		format.wAlignment = PFA_LEFT;

		// Step through all text blocks for the group and collect the
		// text justification
		for(blkIndex = 0; blkIndex < blkCount; blkIndex++) {
			blk = group->GetBlock(blkIndex);

			// Process the style information
			style = blk->GetStyle() & JUSTIFY_MASK;

			if(0 != style) {
				switch(style) {
				case JUSTIFY_LEFT:
					format.wAlignment =	PFA_LEFT;
					break;
				case JUSTIFY_CENTER:
					format.wAlignment =	PFA_CENTER;
					break;
				case JUSTIFY_RIGHT:
					format.wAlignment =	PFA_RIGHT;
					break;
				default:
					ASSERT(0);
				}
				break;
			}
		}
		
		// Set the paragraph font and style information
		SetParaFormat(format);


		// Step through all text blocks and insert the text
		for(blkIndex = 0; blkIndex < blkCount; blkIndex++) {
			CHARFORMAT	charFmt;
			CString		typeface;

			blk = group->GetBlock(blkIndex);
			

			// Create the text block font formatting information for the
			// rich edit control
			charFmt.cbSize = sizeof(charFmt);
			charFmt.dwMask = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_SIZE | CFM_COLOR;
			charFmt.dwEffects = 0;
			charFmt.yHeight = blk->GetPointSize() * 20;
			charFmt.crTextColor = blk->GetColor();

			// Add typeface
			typeface = blk->GetTypeface();
			if(0 == typeface.GetLength()) {
				typeface = m_Document->GetTypeface();
			}
			
			if(typeface.GetLength() >= LF_FACESIZE) {
				TRACE1("Typeface %s is too long for CHARFORMAT member\n", typeface.GetBuffer(0));
			} else {
				strcpy(charFmt.szFaceName, typeface);
				charFmt.bPitchAndFamily = FF_DONTCARE;
				charFmt.dwMask |= CFM_FACE;
			}

			// Add style
			style = blk->GetStyle();
			if(style & STYLE_BOLD) {
				charFmt.dwEffects |= CFE_BOLD;
			}

			if(style & STYLE_ITALICS) {
				charFmt.dwEffects |= CFE_ITALIC;
			}

			if(style & STYLE_UNDERLINE) {
				charFmt.dwEffects |= CFE_UNDERLINE;
			}

			SetSelectionCharFormat(charFmt);
			
			ReplaceSel(blk->GetText(), FALSE);
		}

		ReplaceSel("\n", FALSE);
	}


	SetReadOnly(TRUE);
}
Exemplo n.º 18
0
void CIRCEditCtrl::PutIRCText( char *Message,COLORREF Foreground, COLORREF Background)
{
	CHARFORMAT2 fmt;
	long effects = 0;
	int i, si, cfi,cbi;
	char sfgcol[9]; // can hold "0\0" - "16777215\0" in decimal (HEX 0x00FFFFFF)
	char sbgcol[9];
  int colornum;

  int len = lstrlen(Message);
  char *sputbuf=strdup(Message);

  if (!sputbuf)
    return;

  sputbuf[0] = 0; // null terminate


  SetSel(-1,-1); // deselect and move to end
  GetDefaultCharFormat(fmt);
  fmt.dwMask = CFM_BOLD | CFM_COLOR | CFM_BACKCOLOR | CFM_UNDERLINE | CFM_ITALIC;
	fmt.dwEffects = effects;
  fmt.crTextColor = Foreground;
	fmt.crBackColor = Background;  
	fmt.cbSize = sizeof(CHARFORMAT2);
  SetSelectionCharFormat(fmt);  

  // remember some stuff for highlighting
  BOOL HighlightMode;
	COLORREF LastTextColor = fmt.crTextColor;
	COLORREF LastBackColor = fmt.crBackColor;

  si = 0;
	for (i = 0; i < len; i++)
	{
    if (m_ControlCodeMode == CTRLCODE_MODE_DISPLAY)
    {
      if (Message[i] == '\r')
        continue;
      sputbuf[si] = Message[i];
      si++;
      sputbuf[si] = 0; // null terminate

      // count the lines
      if (Message[i] == '\n')
      {
        if (sputbuf[0])
        {
          ReplaceSel(sputbuf);
          SetSel(-1,-1);
        }
        si = 0;
        sputbuf[si] = 0; // null terminate
      }
    }
    else
    {
      switch(Message[i])
		  {
        // bold
			  case '\002':
          if (m_ControlCodeMode == CTRLCODE_MODE_STRIP) break;

				  if (sputbuf[0])
				  {
            ReplaceSel(sputbuf);
            //ScrollCaret();
            SetSel(-1,-1);
				  }
				  //ZeroMemory(&sbuf, sizeof(sbuf));
				  si = 0;
          sputbuf[si] = 0; // null terminate

          //GetDefaultCharFormat(fmt);
				  fmt.cbSize = sizeof(CHARFORMAT2);
				  fmt.dwMask = CFM_BOLD;
					effects ^= CFE_BOLD;
				  fmt.dwEffects = effects;
          SetSelectionCharFormat(fmt);
          break;

        // color (ctrl+k)
			  case '\003':
				  if (sputbuf[0])
				  {
            ReplaceSel(sputbuf);
            //ScrollCaret();
            SetSel(-1,-1);
				  }
          si = 0;
          sputbuf[si] = 0; // null terminate
				  ZeroMemory(&sfgcol, sizeof(sfgcol));
				  ZeroMemory(&sbgcol, sizeof(sbgcol));

          // get the fg color
          if (i < lstrlen(Message)-1)
          {
            if (isdigit((unsigned char)Message[i+1]))
            {
              sfgcol[0] = Message[i+1];
              i++;

              if (i < lstrlen(Message)-1)
              {
                if (isdigit((unsigned char)Message[i+1]))
                {
                  sfgcol[1] = Message[i+1];
                  i++;

                  // check for invalid color number, step back a character if it's not valid
                  colornum = atoi(sfgcol);
                  if ((colornum <0 || colornum >15) && colornum != 99)
                  {
                    sfgcol[1] = 0;
                    i--;
                  }
                }
              }
            }
          }

          // if we've got a , then get the bg color
          if (i < lstrlen(Message)-1 && Message[i+1] == ',')
          {
            i++;

            if (i < lstrlen(Message)-1)
            {
              if (isdigit((unsigned char)Message[i+1]))
              {
                sbgcol[0] = Message[i+1];
                i++;
                if (i < lstrlen(Message)-1)
                {
                  if (isdigit((unsigned char)Message[i+1]))
                  {
                    sbgcol[1] = Message[i+1];
                    i++;

                    // check for invalid color number, step back a character if it's not valid
                    colornum = atoi(sbgcol);
                    if ((colornum <0 || colornum >15) && colornum != 99)
                    {
                      sbgcol[1] = 0;
                      i--;
                    }
                  }
                }
              }
            }
          }

          if (m_ControlCodeMode == CTRLCODE_MODE_INTERPRET)
          {
            if (sfgcol[0])
            {
              fmt.cbSize = sizeof(CHARFORMAT2);
              fmt.dwMask = CFM_COLOR;
              fmt.dwEffects = effects;
              colornum = atoi(sfgcol);
              if (colornum >= 0 && colornum <= 15)
              {
                fmt.crTextColor = m_Colors[colornum];
              }
              else // assume color code 99
              {
                fmt.crTextColor = Foreground;
              }
            }
            if (sbgcol[0])
            {
              fmt.dwMask |= CFM_BACKCOLOR;
              colornum = atoi(sbgcol);
              if (colornum >= 0 && colornum <= 15)
              {                  
                fmt.crBackColor = m_Colors[colornum];
              }
              else // assume color code 99
              {
                fmt.crBackColor = Background;
              }
            }
            if (!sfgcol[0] && !sbgcol[0])
            {
              // didn't get colors, behave as if this was ctrl+o
              fmt.cbSize = sizeof(CHARFORMAT2);
              fmt.dwMask = CFM_COLOR | CFM_BACKCOLOR;
              fmt.dwEffects = 0;
              fmt.crTextColor = Foreground;
              fmt.crBackColor = Background;
            }
            SetSelectionCharFormat(fmt);
          }
          break;

        case '\007': // 16 million color (HydraIRC Highlighting) - hex
        case '\004': // 16 million color - hex

          if (Message[i] == '\007')
            HighlightMode = TRUE;
          else
            HighlightMode = FALSE;

				  if (sputbuf[0])
				  {
            ReplaceSel(sputbuf);
            SetSel(-1,-1);
				  }
          si = 0;
          sputbuf[si] = 0; // null terminate
				  ZeroMemory(&sfgcol, sizeof(sfgcol));
				  ZeroMemory(&sbgcol, sizeof(sbgcol));

          // get the fg color
				  cfi = 0;
          while ((i < lstrlen(Message)-1) && (isxdigit((unsigned char)Message[i+1])) && (cfi < 6))
          {
						sfgcol[cfi++] = Message[i+1];
						i++;
          }
          if (cfi != 6)
            i-=cfi; //step back if we've not got 6 hex digits

          // if we've got a ',' then get the bg color
          cbi = 0;
          if (i < lstrlen(Message)-1 && Message[i+1] == ',')
          {
            i++;
            // get the bg color
            while ((i < lstrlen(Message)-1) && (isxdigit((unsigned char)Message[i+1])) && (cbi < 6))
            {
						    sbgcol[cbi++] = Message[i+1];
						    i++;
            }
            if (cbi != 6)
              i-=cbi; //step back if we've not got 6 hex digits
          }

          if (m_ControlCodeMode == CTRLCODE_MODE_INTERPRET || HighlightMode )
          {
				    fmt.cbSize = sizeof(CHARFORMAT2);
				    fmt.dwMask = CFM_COLOR;
				    fmt.dwEffects = effects;


            if (cfi == 6 || cbi == 6)
            {
              if (HighlightMode)
              {
                LastTextColor = fmt.crTextColor;
                LastBackColor = fmt.crBackColor;
              }
              if (cfi == 6)
				      {
                if (sscanf(sfgcol,"%x",&colornum) == 1 && colornum >= 0 && colornum <= 0xffffff)
                {
                  // RGB(0,0,255) == 0xff0000 not 0x0000ff
                  // so we swap the bytes.
                  fmt.crTextColor = RGBVALTOCOLORREF(colornum);
                }
              }

              if (cbi == 6)
              {
                fmt.dwMask |= CFM_BACKCOLOR;                
                if (sscanf(sbgcol,"%x",&colornum) == 1 && colornum >= 0 && colornum <= 0xffffff)
                {                  
                  fmt.crBackColor = RGBVALTOCOLORREF(colornum);
                }
                else
                {
                  fmt.crBackColor = Background;
                }
              }
              SetSelectionCharFormat(fmt);
            }
            else
            {              
              // didn't get colors, behave as if this was ctrl+o
	            fmt.cbSize = sizeof(CHARFORMAT2);
	            fmt.dwMask = CFM_BOLD | CFM_COLOR | CFM_BACKCOLOR | CFM_UNDERLINE | CFM_ITALIC;
	            fmt.dwEffects = 0;
              if (HighlightMode)
              {
	              fmt.crTextColor = LastTextColor;
	              fmt.crBackColor = LastBackColor;
              }
              else
              {
	              fmt.crTextColor = Foreground;
	              fmt.crBackColor = Background;
              }
              SetSelectionCharFormat(fmt);
            }

				  }
          break;
        // underline
			  case '\037':
          if (m_ControlCodeMode == CTRLCODE_MODE_STRIP) break;
				  if (sputbuf[0])
				  {
            ReplaceSel(sputbuf);
            SetSel(-1,-1);
				  }
				  si = 0;
          sputbuf[si] = 0; // null terminate
				  fmt.cbSize = sizeof(CHARFORMAT2);
				  fmt.dwMask = CFM_UNDERLINE;
          effects ^= CFE_UNDERLINE;
				  fmt.dwEffects = effects;
          SetSelectionCharFormat(fmt);
				  break;

        // italics
			  case '\035':
          if (m_ControlCodeMode == CTRLCODE_MODE_STRIP) break;
				  if (sputbuf[0])
				  {
            ReplaceSel(sputbuf);
            SetSel(-1,-1);
				  }
				  si = 0;
          sputbuf[si] = 0; // null terminate
				  fmt.cbSize = sizeof(CHARFORMAT2);
				  fmt.dwMask = CFM_ITALIC;
          effects ^= CFE_ITALIC;
				  fmt.dwEffects = effects;
          SetSelectionCharFormat(fmt);
				  break;

        // reverse
			  case '\026':
          if (m_ControlCodeMode == CTRLCODE_MODE_STRIP) break;
				  if (sputbuf[0])
				  {
            ReplaceSel(sputbuf);
            SetSel(-1,-1);
				  }
				  si = 0;
          sputbuf[si] = 0; // null terminate
				  fmt.cbSize = sizeof(CHARFORMAT2);
				  fmt.dwMask = CFM_COLOR | CFM_BACKCOLOR;

          // swap the colors.
          colornum = fmt.crBackColor;
          fmt.crBackColor = fmt.crTextColor;
          fmt.crTextColor = colornum;
          
          SetSelectionCharFormat(fmt);
          break;
        // normal
			  case '\017':
          if (m_ControlCodeMode == CTRLCODE_MODE_STRIP) break;
				  if (sputbuf[0])
				  {
            ReplaceSel(sputbuf);
            SetSel(-1,-1);
				  }
				  si = 0;
          sputbuf[si] = 0; // null terminate
	        fmt.cbSize = sizeof(CHARFORMAT2);
	        fmt.dwMask = CFM_BOLD | CFM_COLOR | CFM_BACKCOLOR | CFM_UNDERLINE | CFM_ITALIC;
	        fmt.dwEffects = 0;
	        fmt.crTextColor = Foreground;
	        fmt.crBackColor = Background;
          SetSelectionCharFormat(fmt);

          break;
			  case '\006':
			  case '\023':
			  case '\022':
				  break;

			  default:
				  {
					  sputbuf[si] = Message[i];
					  si++;
            sputbuf[si] = 0; // null terminate

            // count the lines, add a timestamp if needed.
            if (Message[i] == '\n')
            {
              if (sputbuf[0])
              {
                ReplaceSel(sputbuf);
                SetSel(-1,-1);
              }
              si = 0;
              sputbuf[si] = 0; // null terminate
            }
				  }
				  break;
		  }
    }
  }
  if (sputbuf[0])
  {
    ReplaceSel(sputbuf);
    SetSel(-1,-1);
  }

  free (sputbuf);
}
Exemplo n.º 19
0
void CUrlRichEditCtrl::ParseAndFormatText(BOOL bForceReformat)
{
	KillTimer(TIMER_REPARSE);
	AF_NOREENTRANT // prevent reentrancy
		
	// parse the control content
	CString sText;
	GetWindowText(sText);
	
	// richedit2 uses '\r\n' whereas richedit uses just '\n'
	if (!CWinClasses::IsClass(*this, WC_RICHEDIT))
		sText.Replace(_T("\r\n"), _T("\n"));
	
	// parse the text into an array of URLPOS
	CUrlArray aUrls;
	LPCTSTR szText = sText;
	BOOL bPrevDelim = TRUE;
	int nPos = 0;
	BOOL bBracedFile = FALSE;
	
	while (*szText) 
	{
		// if nChar < 0 then its a multibyte char and can't be part
		// of a url, so we bump the text buffer by 2 but the pos by 1
#ifndef _UNICODE
		TCHAR nChar = *szText;
		
		if (IsDBCSLeadByte(nChar))
		{
			szText++; 
			szText++;
			nPos++;
			continue;
		}
#endif
		// if the previous item was not a delimiter then there's no
		// point checking for a protocol match so we just update the
		// value of bPrevDelim for the current char
		if (!bPrevDelim)
		{
			bPrevDelim = IsDelim(szText);
			szText++;
			nPos++;
			continue;
		}
		// if the current char is a delim then this can't be the start
		// of a url either
		else if (IsDelim(szText))
		{
			bPrevDelim = TRUE;
			szText++;
			nPos++;
			continue;
		}
		
		// now check for a protocol
		int nProt = MatchProtocol(szText);
		
		// if no match then increment pos and go to next char
		if (nProt == -1)
		{
			bPrevDelim = FALSE;
			szText++;
			nPos++;
			continue;
		}
		
		// check for braces (<...>)
		if (nPos > 0)
			bBracedFile = (szText[-1] == '<');
		else
			bBracedFile = FALSE;
		
		// find the end of the url (URLDELIMS)
		int nLen = 0;
		LPCTSTR szStart = szText;
		
		if (bBracedFile)
		{
			while (*szText && *szText != '>')
			{
				szText++;
				nLen++;
			}
		}
		else
		{
			while (!IsDelim(szText))
			{
				szText++;
				nLen++;
			}
		}
		
		bPrevDelim = TRUE;
		
		// save the result
		URLITEM urli;
		urli.cr.cpMin = nPos;
		urli.cr.cpMax = urli.cr.cpMin + nLen;
		nPos += nLen;
		
		// make sure the url does not end in a punctuation mark
		while (ENDPUNCTUATION.Find(szStart[nLen - 1]) != -1)
		{
			nLen--;
			urli.cr.cpMax--;
		}
		
		// Only save if the link is more than just the protocol
		if (nLen > m_aProtocols[nProt].sProtocol.GetLength())
		{
			urli.sUrl = CString(szStart, nLen);
			urli.bWantNotify = m_aProtocols[nProt].bWantNotify;
			
			InsertInOrder(urli, aUrls);
		}
	}
	
	// compare aUrls with m_aUrls to see if anything has changed
	BOOL bReformat = !sText.IsEmpty() && (bForceReformat || !UrlsMatch(aUrls));
	
	// then overwrite (always)	
	m_aUrls.Copy(aUrls);
	
	if (bReformat)
	{
		BOOL bVisible = IsWindowVisible();
		CRePauseUndo rep(*this);
		
		if (bVisible)
			SetRedraw(FALSE);
		
		// save current selection
		CHARRANGE crSel;
		GetSel(crSel);
		
		// and first line
		int nFirstLine = GetFirstVisibleLine();
		
		// save/reset event mask
		DWORD dwEventMask = SetEventMask(0);
		
		// retrieve default character attribs
		CHARFORMAT cf;
		cf.cbSize = sizeof(cf);
		cf.dwMask = CFM_LINK;
		
		// format urls
		int nUrls = aUrls.GetSize();
		CHARRANGE cr = { 0, 0 };
		
		for (int nUrl = 0; nUrl < nUrls; nUrl++)
		{
			// clear formatting from the end of the previous
			// url to the start of this url
			cr.cpMax = aUrls[nUrl].cr.cpMin;
			cf.dwEffects = 0;
			
			SetSel(cr);
			SetSelectionCharFormat(cf);
			
			// update for next url
			cr.cpMin = aUrls[nUrl].cr.cpMax;
			
			// then format url
			cf.dwEffects = CFM_LINK;
			
			SetSel(aUrls[nUrl].cr);
			SetSelectionCharFormat(cf);
		}	
		
		// clear formatting for whatever's left
		cr.cpMax = -1;
		cf.dwEffects = 0;
		
		SetSel(cr);
		SetSelectionCharFormat(cf);
		
		// restore selection
		SetSel(crSel);
		
		// and first line
		SetFirstVisibleLine(nFirstLine);
		
		// restore event mask
		SetEventMask(dwEventMask);

		if (bVisible)
		{
			SetRedraw(TRUE);
			Invalidate(FALSE);
		}
	}
}
Exemplo n.º 20
0
void ChatCtrl::FormatEmoticonsAndLinks(tstring& sMsg, tstring& sMsgLower, LONG lSelBegin, bool bUseEmo) {
	if(!sMsg.size())
		return;
	LONG lSelEnd = lSelBegin + sMsg.size();

	// hightlight all URLs and make them clickable
	for(size_t i = 0; i < (sizeof(protocols) / sizeof(protocols[0])); ++i) {
		size_t linkStart = sMsgLower.find(protocols[i]);
		bool isMagnet = (protocols[i] == _T("magnet:?"));
		while(linkStart != tstring::npos) {
			size_t linkEnd = linkStart + protocols[i].size();
			
			try {
				// TODO: complete regexp for URLs
				std::tr1::wregex reg;
//[+]PPA Исправил регулярное выражение для коррктного поиска урлов в VC++ 2010 (пример урла - magnet:?xt=urn:tree:tiger:V3LVT4CSASPLNHRG6DOORAD2SDSBBANIKEI7XHI&xl=260524251&dn=cstrike_full_v.35_(4156).exe  )
				if(isMagnet) // magnet links have totally indifferent structure than classic URL // -/?%&=~#'\\w\\.\\+\\*\\(\\)
					reg.assign(_T("^(\\w)+=[:\\w]+(&(\\w)+=[\\S]*)*[^\\s<>{}\"']+"), std::tr1::regex_constants::icase);
				else
					reg.assign(_T("^([@\\w-]+(\\.)*)+(:[\\d]+)?(/[\\S]*)*[^\\s<>{}\"']+"), std::tr1::regex_constants::icase);
					
				tstring::const_iterator start = sMsg.begin();
				tstring::const_iterator end = sMsg.end();
				std::tr1::match_results<tstring::const_iterator> result;

				if(std::tr1::regex_search(start + linkEnd, end, result, reg, std::tr1::regex_constants::match_default)) {
					dcassert(!result.empty());
					
					 linkEnd += result.length(0);
					 SetSel(lSelBegin + linkStart, lSelBegin + linkEnd);
					if(isMagnet) {
						tstring cURL = ((tstring)(result[0]));
						tstring::size_type dn = cURL.find(_T("dn="));
						if(dn != tstring::npos) {
							string sFileName = Util::encodeURI(Text::fromT(cURL).substr(dn + 3), true);
							int64_t filesize = Util::toInt64(Text::fromT(cURL.substr(cURL.find(_T("xl=")) + 3, cURL.find(_T("&")) - cURL.find(_T("xl=")))));
							tstring shortLink = Text::toT(sFileName) + _T(" (") + Util::formatBytesW(filesize) + _T(")");

							sMsg.replace(linkStart, linkEnd - linkStart, shortLink.c_str());
							std::transform(&sMsgLower.replace(linkStart, linkEnd - linkStart, shortLink.c_str())[linkStart], &sMsgLower[linkEnd], &sMsgLower[linkStart], _totlower);

							setText(shortLink);
							linkEnd = linkStart + shortLink.size();
							SetSel(lSelBegin + linkStart, lSelBegin + linkEnd);
							magnets[shortLink] = _T("magnet:?") + cURL;
					}
				}
					SetSelectionCharFormat(WinUtil::m_TextStyleURL);
				}
			} catch(...) {
			}
			
			linkStart = sMsgLower.find(protocols[i], linkEnd);			
		}
	}

	// insert emoticons
	if(bUseEmo && emoticonsManager->getUseEmoticons()) {
		const Emoticon::List& emoticonsList = emoticonsManager->getEmoticonsList();
		tstring::size_type lastReplace = 0;
		uint8_t smiles = 0;

		while(true) {
			tstring::size_type curReplace = tstring::npos;
			Emoticon* foundEmoticon = NULL;

			for(Emoticon::Iter emoticon = emoticonsList.begin(); emoticon != emoticonsList.end(); ++emoticon) {
				tstring::size_type idxFound = sMsg.find((*emoticon)->getEmoticonText(), lastReplace);
				if(idxFound < curReplace || curReplace == tstring::npos) {
					curReplace = idxFound;
					foundEmoticon = (*emoticon);
				}
			}

			if(curReplace != tstring::npos && smiles < MAX_EMOTICONS) {
				CHARFORMAT2 cfSel;
				cfSel.cbSize = sizeof(cfSel);

				lSelBegin += (curReplace - lastReplace);
				lSelEnd = lSelBegin + foundEmoticon->getEmoticonText().size();
				SetSel(lSelBegin, lSelEnd);

				GetSelectionCharFormat(cfSel);
				if(!(cfSel.dwEffects & CFE_LINK)) {
					CImageDataObject::InsertBitmap(GetOleInterface(), foundEmoticon->getEmoticonBmp(cfSel.crBackColor));

					++smiles;
					++lSelBegin;
				} else lSelBegin = lSelEnd;
				lastReplace = curReplace + foundEmoticon->getEmoticonText().size();
			} else break;
		}
	}

}
Exemplo n.º 21
0
void CRichEditCtrlExtn::SetWindowText(LPCWSTR lpszString)
{
  int iError;
  CRichEditCtrl::SetWindowText(L"");
  ShowWindow(SW_HIDE);

  CString cs_formatstring(lpszString);
  CString cs_plaintext = GetTextFormatting(cs_formatstring, iError);
  if (iError != 0) {
    // Had an error - show unchanged text
    CRichEditCtrl::SetWindowText(cs_formatstring);
  } else {
    CRichEditCtrl::SetWindowText(cs_plaintext);

    CHARFORMAT2 cf2;
    // Now apply formating
    if (!m_vFormat.empty()) {
      std::sort(m_vFormat.begin(), m_vFormat.end(), iStartCompare);
      std::vector<st_format>::const_iterator format_iter;
      SecureZeroMemory(&cf2, sizeof(cf2));
      cf2.cbSize = sizeof(cf2);

      for (format_iter = m_vFormat.begin();
           format_iter != m_vFormat.end(); format_iter++) {
        SetSel(format_iter->iStart, format_iter->iEnd);
        GetSelectionCharFormat(cf2);
        if (format_iter->entrytype == Bold) {
          cf2.dwMask |= CFM_BOLD;
          cf2.dwEffects |= CFE_BOLD;
        } else if (format_iter->entrytype == Italic) {
          cf2.dwMask |= CFM_ITALIC;
          cf2.dwEffects |= CFE_ITALIC;
        } else if (format_iter->entrytype == Underline) {
          cf2.dwMask |= CFM_UNDERLINE;
          cf2.dwEffects |= CFE_UNDERLINE;
        } else if (format_iter->entrytype == Colour) {
          cf2.dwMask = CFM_COLOR;
          cf2.crTextColor = format_iter->cr;
          cf2.dwEffects &= ~CFE_AUTOCOLOR;
        } else if (format_iter->entrytype == Size) {
          cf2.dwMask = CFM_SIZE;
          cf2.yHeight = (format_iter->iSize) * 20;
        } else if (format_iter->entrytype == Name) {
          cf2.dwMask = CFM_FACE;
#if (_MSC_VER >= 1400)
          memcpy_s(cf2.szFaceName, sizeof(cf2.szFaceName),
                   format_iter->tcszFACENAME, sizeof(format_iter->tcszFACENAME));
#else
          memcpy(cf2.szFaceName, Name_iter->tcszFACENAME, 
                 sizeof(format_iter->tcszFACENAME));
#endif
        }
        SetSelectionCharFormat(cf2);
      }
    }

    if (!m_vALink.empty()) {
      SetEventMask(GetEventMask() | ENM_LINK); 
      std::vector<ALink>::const_iterator ALink_iter;
      SecureZeroMemory(&cf2, sizeof(cf2));
      cf2.cbSize = sizeof(cf2);
      cf2.dwMask = CFM_LINK;
      cf2.dwEffects = CFE_LINK;

      for (ALink_iter = m_vALink.begin(); ALink_iter != m_vALink.end(); ALink_iter++) {
        SetSel(ALink_iter->iStart, ALink_iter->iEnd);
        SetSelectionCharFormat(cf2);
      }
    } else {
      SetEventMask(GetEventMask() & ~ENM_LINK);
    }
  }
  ShowWindow(SW_SHOW);
}
void CHTRichEditCtrl::AddString(int nPos, LPCTSTR pszString, bool bLink, COLORREF cr, COLORREF bk, DWORD mask)
{
	bool bRestoreFormat = false;
	m_bEnErrSpace = false;
	SetSel(nPos, nPos);
	if (bLink)
	{
		CHARFORMAT2 cf;
		memset(&cf, 0, sizeof cf);
		GetSelectionCharFormat(cf);
		cf.dwMask |= CFM_LINK;
		cf.dwEffects |= CFE_LINK;
		SetSelectionCharFormat(cf);
	}
	else if (cr != CLR_DEFAULT || bk != CLR_DEFAULT || (mask & (CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE)) != 0)
	{
		CHARFORMAT2 cf;
		memset(&cf, 0, sizeof(cf));
		GetSelectionCharFormat(cf);

		cf.dwMask |= CFM_COLOR;
		if (cr == CLR_DEFAULT)
		{
			if (m_bDfltForeground)
				cf.dwEffects |= CFE_AUTOCOLOR;
			else {
				ASSERT( m_crForeground != CLR_DEFAULT );
				cf.dwEffects &= ~CFE_AUTOCOLOR;
				cf.crTextColor = m_crForeground;
			}
		}
		else
		{
			cf.dwEffects &= ~CFE_AUTOCOLOR;
			cf.crTextColor = cr;
		}

		if (bk == CLR_DEFAULT)
		{
			// Background color is a little different than foreground color. Even if the
			// background color is set to a non-standard value (e.g. via skin), the
			// CFE_AUTOBACKCOLOR can be used to get this value. The usage of this flag instead
			// of the explicit color has the advantage that on a change of the skin or on a
			// change of the windows system colors, the control can display the colored
			// text in the new color scheme better (e.g. the text is at least readable and
			// not shown as black-on-black or white-on-white).
			//if (m_bDfltBackground) {
				cf.dwMask |= CFM_BACKCOLOR;
				cf.dwEffects |= CFE_AUTOBACKCOLOR;
			//}
			//else {
			//	ASSERT( m_crBackground != CLR_DEFAULT );
			//	cf.dwEffects &= ~CFE_AUTOBACKCOLOR;
			//	cf.crBackColor = m_crBackground;
			//}
		}
		else
		{
			cf.dwMask |= CFM_BACKCOLOR;
			cf.dwEffects &= ~CFE_AUTOBACKCOLOR;
			cf.crBackColor = bk;
		}

		cf.dwMask |= mask;

		if (mask & CFM_BOLD)
			cf.dwEffects |= CFE_BOLD;
		else if (cf.dwEffects & CFE_BOLD)
			cf.dwEffects ^= CFE_BOLD;

		if (mask & CFM_ITALIC)
			cf.dwEffects |= CFE_ITALIC;
		else if (cf.dwEffects & CFE_ITALIC)
			cf.dwEffects ^= CFE_ITALIC;

		if (mask & CFM_UNDERLINE)
			cf.dwEffects |= CFE_UNDERLINE;
		else if (cf.dwEffects & CFE_UNDERLINE)
			cf.dwEffects ^= CFE_UNDERLINE;

		SetSelectionCharFormat(cf);
		bRestoreFormat = true;
	}
	else if (m_bRestoreFormat)
	{
		SetSelectionCharFormat(m_cfDefault);
	}

	if (m_bEnableSmileys)
		AddSmileys(pszString);
	else
		ReplaceSel(pszString);

	m_bRestoreFormat = bRestoreFormat;
}
Exemplo n.º 23
0
void CRichMsgView::appendMsg(IcqMsg &msg, COLORREF color)
{
	const char *nick = "";

	if (!msg.id) {
		IcqContact *c = icqLink->findContact(msg.qid);
		if (c)
			nick = c->nick.c_str();
	} else {
		IcqGroup *g = icqLink->findGroup(msg.id);
		if (g) {
			GroupMember *m = g->getMemberInfo(msg.qid.uin);
			if (m)
				nick = m->nick.c_str();
		}
	}

	long start, end;
	SetSel(-1, -1);
	GetSel(start, end);

	CHARFORMAT defFormat;
	defFormat.cbSize = sizeof(defFormat);
	defFormat.dwMask = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_FACE | CFM_SIZE | CFM_COLOR;
	GetDefaultCharFormat(defFormat);

	PARAFORMAT pf;
	pf.cbSize = sizeof(pf);
	pf.dwMask = PFM_STARTINDENT;
	pf.dxStartIndent = 0;
	SetParaFormat(pf);

	CHARFORMAT cf;
	cf.cbSize = sizeof(cf);

	CString text;
	CString strTime = CTime(msg.when).Format("%H:%M:%S");
	text.Format("%s (%s): \r\n",
		(msg.flags & MF_RECEIVED) ? nick : icqLink->myInfo.nick.c_str(),
		(LPCTSTR) strTime);

	ReplaceSel(text);
	SetSel(start, -1);
	cf = defFormat;
	cf.crTextColor = color;
	cf.dwEffects = 0;
	SetSelectionCharFormat(cf);

	SetSel(-1, -1);
	insertMsg(msg);

	pf.dxStartIndent = 200;
	SetParaFormat(pf);

	uint8 mask = (MF_RELAY | MF_RECEIVED);
	if ((msg.flags & mask) == mask) {
		GetSel(start, end);

		text.LoadString(IDS_SERVER_RELAY);
		ReplaceSel("\r\n");
		ReplaceSel(text);
		SetSel(start, -1);

		cf = defFormat;
		cf.crTextColor = color;
		cf.dwEffects = 0;
		SetSelectionCharFormat(cf);
	}

	SetSel(-1, -1);
	ReplaceSel("\r\n");

	scrollToBottom();
}
void CAutoRichEditCtrl::SetNumberDefaultTex(COLORREF crf)
{   int nPointSize=11;
	CString floatstrnumber;
	int size=nPointSize;
	GetWindowText(floatstrnumber);
	int index=floatstrnumber.Find(_T("."));
	int len=floatstrnumber.GetLength();
	if (index!=-1)
	{
 		SetSel(0,len);
 		CHARFORMAT cf = GetCharFormat();
 		nPointSize *= 20;	// convert from to twips
		cf.crTextColor=RGB(0,0,0);
 		cf.yHeight = nPointSize;
 		cf.dwMask = CFM_SIZE;
		 
		//strcpy(cf.szFaceName ,_T("Arial"));//ÉèÖÃ×ÖÌå
		memcpy(&cf.szFaceName,"Arial",sizeof(cf.szFaceName));
 		SetSelectionCharFormat(cf);

 		SetSel(index,len);
 		cf = GetCharFormat();
 		nPointSize=size-4;
 		nPointSize*=20;	// convert from to twips
 		cf.yHeight = nPointSize;
 		cf.dwMask = CFM_SIZE;
 		SetSelectionCharFormat(cf);


  		SetSel(index+2,len);
  		 cf = GetCharFormat();
		 nPointSize=size;
  		nPointSize *= 20;	// convert from to twips
  		cf.yHeight = nPointSize;
		cf.crTextColor=RGB(0,0,0);
		memcpy(&cf.szFaceName,"Arial",sizeof(cf.szFaceName));
  		cf.dwMask = CFM_SIZE;
  		SetSelectionCharFormat(cf);
	}
	else
	{
		SetSel(0,len);
		CHARFORMAT cf = GetCharFormat();
		nPointSize *= 20;	// convert from to twips
		cf.yHeight = nPointSize;
		cf.dwMask = CFM_SIZE;
		cf.crTextColor=RGB(0,0,0);
		memcpy(&cf.szFaceName,"Arial",sizeof(cf.szFaceName));
		SetSelectionCharFormat(cf);
	}
	SetSel(0,len);
	 
	 
	 
	CHARFORMAT cf = GetCharFormat();

	if (cf.dwEffects & CFE_AUTOCOLOR) cf.dwEffects -= CFE_AUTOCOLOR;
	cf.crTextColor =crf;
	cf.crTextColor=RGB(0,0,0);
	cf.dwMask = CFM_COLOR;

	SetSelectionCharFormat(cf);
}
Exemplo n.º 25
0
int CFulEditCtrl::FullTextMatch(ColorSettings* cs, CHARFORMAT2 &cf, const tstring &line, int pos, int &lineIndex) {
	int index = tstring::npos;
	tstring searchString;

	if( cs->getMyNick() ) {
		tstring::size_type p = cs->getMatch().find(_T("$mynick$"));
		if(p != tstring::npos) {
			searchString = cs->getMatch();
			searchString = searchString.replace(p, 8, nick);
		} 
	} else {
		searchString = cs->getMatch();
	}
	
	//we don't have any nick to search for
	//happens in pm's have to find a solution for this
	if(searchString.empty())
		return tstring::npos;


	//do we want to highlight the timestamps?
	if( cs->getTimestamps() ) {
		if( line[0] != _T('[') )
			return tstring::npos;
		index = 0;
	} else if( cs->getUsers() ) {
		if(timeStamps) {
			index = line.find(_T("] <"));
			// /me might cause this to happen
			if(index == tstring::npos)
				return tstring::npos;
			//compensate for "] "
			index += 2;
		} else if( line[0] == _T('<')) {
			index = 0;
		}
	}else{
		if( cs->getCaseSensitive() ) {
			index = line.find(searchString, pos);
		}else {
			index = Util::findSubString(line, searchString, pos);	
			//index = Text::toLower(line).find(Text::toLower(searchString), pos);
		}
	}
	//return if no matches where found
	if( index == tstring::npos )
		return tstring::npos;

	pos = index + searchString.length();
	
	//found the string, now make sure it matches
	//the way the user specified
	int length;
		
	if( !cs->getUsers() && !cs->getTimestamps() ) {
		length = searchString.length();
		int p = 0;
			
		switch(cs->getMatchType()){
			case 0: //Begins
				p = index-1;
                if(line[p] != _T(' ') && line[p] != _T('\r') &&	line[p] != _T('\t') )
					return tstring::npos;
				break;
			case 1: //Contains
				break;
			case 2: // Ends
				p = index+length;
				if(line[p] != _T(' ') && line[p] != _T('\r') &&	line[p] != _T('\t') )
					return tstring::npos;
				break;
			case 3: // Equals
				if( !( (index == 0 || line[index-1] == _T(' ') || line[index-1] == _T('\t')) && 
					(line[index+length] == _T(' ') || line[index+length] == _T('\r') || 
					line[index+length] == _T('\t')) ) )
					return tstring::npos;
				break;
		}
	}

	long begin, end;

	begin = lineIndex;
		
	if( cs->getTimestamps() ) {
		tstring::size_type pos = line.find(_T("]"));
		if( pos == tstring::npos ) 
			return tstring::npos;  //hmm no ]? this can't be right, return
		
		begin += index +1;
		end = begin + pos -1;
	} else if( cs->getUsers() ) {
		end = begin + line.find(_T(">"));
		begin += index +1;
	} else if( cs->getWholeLine() ) {
		end = begin + line.length();
	} else if( cs->getWholeWord() ) {
		int tmp;

		tmp = line.find_last_of(_T(" \t\r"), index);
		if(tmp != tstring::npos )
			begin += tmp+1;
		
		tmp = line.find_first_of(_T(" \t\r"), index);
		if(tmp != tstring::npos )
			end = lineIndex + tmp;
		else
			end = lineIndex + line.length();
	} else {
		begin += index;
		end = begin + searchString.length();
	}

	SetSel(begin, end);
		
	SetSelectionCharFormat(cf);

	SetSel(GetTextLength()-1, GetTextLength()-1);
	SetSelectionCharFormat(selFormat);

	CheckAction(cs, line);

	if( cs->getTimestamps() || cs->getUsers() )
		return tstring::npos;
	
	return pos;
}
Exemplo n.º 26
0
void ChatCtrl::AppendText(const Identity& i, const tstring& sMyNick, const tstring& sTime, tstring sMsg, CHARFORMAT2& cf, bool bUseEmo/* = true*/) {
	SetRedraw(FALSE);

	SCROLLINFO si = { 0 };
	POINT pt = { 0 };

	si.cbSize = sizeof(si);
	si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
	GetScrollInfo(SB_VERT, &si);
	GetScrollPos(&pt);

	LONG lSelBegin = 0, lSelEnd = 0, lTextLimit = 0, lNewTextLen = 0;
	LONG lSelBeginSaved, lSelEndSaved;

	// Unify line endings
	tstring::size_type j = 0; 
	while((j = sMsg.find(_T("\r"), j)) != tstring::npos)
		sMsg.erase(j, 1);

	GetSel(lSelBeginSaved, lSelEndSaved);
	lSelEnd = lSelBegin = GetTextLengthEx(GTL_NUMCHARS);

	bool isMyMessage = i.getUser() == ClientManager::getInstance()->getMe();
	tstring sLine = sTime + sMsg;

	// Remove old chat if size exceeds
	lNewTextLen = sLine.size();
	lTextLimit = GetLimitText();

	if(lSelEnd + lNewTextLen > lTextLimit) {
		LONG lRemoveChars = 0;
		int multiplier = 1;

		if(lNewTextLen >= lTextLimit) {
			lRemoveChars = lSelEnd;
			magnets.clear();
		} else {
			while(lRemoveChars < lNewTextLen)
				lRemoveChars = LineIndex(LineFromChar(multiplier++ * lTextLimit / 10));
		}

		if(magnets.size()) {
			tstring buf;
			buf.resize(lRemoveChars);
			GetTextRange(0, lRemoveChars, &buf[0]);

			CHARFORMAT2 cfSel;
			cfSel.cbSize = sizeof(CHARFORMAT2);

			for(TStringMap::iterator i = magnets.begin(); i != magnets.end();) {
				tstring::size_type j = 0;
				while((j = buf.find(i->first, j)) != tstring::npos) {
					SetSel(j, j + i->first.size());
					GetSelectionCharFormat(cfSel);
					if(cfSel.dwEffects & CFE_LINK) {
						magnets.erase(i++);
						break;
					}
					j += i->first.size();
				} if(j == tstring::npos) {
					++i;
				}
			}
		}

		// Update selection ranges
		lSelEnd = lSelBegin -= lRemoveChars;
		lSelEndSaved -= lRemoveChars;
		lSelBeginSaved -= lRemoveChars;

		// ...and the scroll position
		pt.y -= PosFromChar(lRemoveChars).y;

		SetSel(0, lRemoveChars);
		ReplaceSel(_T(""));
	}


	// Add to the end
	SetSel(lSelBegin, lSelEnd);
	setText(sLine);

	CHARFORMAT2 enc;
	enc.bCharSet = RUSSIAN_CHARSET;
	enc.dwMask = CFM_CHARSET;

	SetSel(0, sLine.length());
	SetSelectionCharFormat(enc);

	// Format TimeStamp
	if(!sTime.empty()) {
		lSelEnd += sTime.size();
		SetSel(lSelBegin, lSelEnd - 1);
		SetSelectionCharFormat(WinUtil::m_TextStyleTimestamp);

		PARAFORMAT2 pf;
		memzero(&pf, sizeof(PARAFORMAT2));
		pf.dwMask = PFM_STARTINDENT; 
		pf.dxStartIndent = 0;
		SetParaFormat(pf);
	}

	// Authors nick
	tstring sAuthor = Text::toT(i.getNick());
	if(!sAuthor.empty()) {
		LONG iLen = (sMsg[0] == _T('*')) ? 1 : 0;
		LONG iAuthorLen = sAuthor.size() + 1;
		sMsg.erase(0, iAuthorLen + iLen);
   		
		lSelBegin = lSelEnd;
		lSelEnd += iAuthorLen + iLen;
		
		if(isMyMessage) {
			SetSel(lSelBegin, lSelBegin + iLen + 1);
			SetSelectionCharFormat(WinUtil::m_ChatTextMyOwn);
			SetSel(lSelBegin + iLen + 1, lSelBegin + iLen + iAuthorLen);
			SetSelectionCharFormat(WinUtil::m_TextStyleMyNick);
		} else {
			bool isFavorite = FavoriteManager::getInstance()->isFavoriteUser(i.getUser());

			if(BOOLSETTING(BOLD_AUTHOR_MESS) || isFavorite || i.isOp()) {
				SetSel(lSelBegin, lSelBegin + iLen + 1);
				SetSelectionCharFormat(cf);
				SetSel(lSelBegin + iLen + 1, lSelEnd);
				if(isFavorite){
					SetSelectionCharFormat(WinUtil::m_TextStyleFavUsers);
				} else if(i.isOp()) {
					SetSelectionCharFormat(WinUtil::m_TextStyleOPs);
				} else {
					SetSelectionCharFormat(WinUtil::m_TextStyleBold);
				}
			} else {
				SetSel(lSelBegin, lSelEnd);
				SetSelectionCharFormat(cf);
            }
		}
	} else {
		bool thirdPerson = false;
        switch(sMsg[0]) {
			case _T('*'):
				if(sMsg[1] != _T(' ')) break;
				thirdPerson = true;
            case _T('<'):
				tstring::size_type iAuthorLen = sMsg.find(thirdPerson ? _T(' ') : _T('>'), thirdPerson ? 2 : 1);
				if(iAuthorLen != tstring::npos) {
                    bool isOp = false, isFavorite = false;

                    if(client != NULL) {
						tstring nick(sMsg.c_str() + 1);
						nick.erase(iAuthorLen - 1);
						
						const OnlineUserPtr ou = client->findUser(Text::fromT(nick));
						if(ou != NULL) {
							isFavorite = FavoriteManager::getInstance()->isFavoriteUser(ou->getUser());
							isOp = ou->getIdentity().isOp();
						}
                    }
                    
					lSelBegin = lSelEnd;
					lSelEnd += iAuthorLen;
					sMsg.erase(0, iAuthorLen);

        			if(BOOLSETTING(BOLD_AUTHOR_MESS) || isFavorite || isOp) {
        				SetSel(lSelBegin, lSelBegin + 1);
        				SetSelectionCharFormat(cf);
						SetSel(lSelBegin + 1, lSelEnd);
						if(isFavorite){
							SetSelectionCharFormat(WinUtil::m_TextStyleFavUsers);
						} else if(isOp) {
							SetSelectionCharFormat(WinUtil::m_TextStyleOPs);
						} else {
							SetSelectionCharFormat(WinUtil::m_TextStyleBold);
						}
        			} else {
        				SetSel(lSelBegin, lSelEnd);
        				SetSelectionCharFormat(cf);
                    }
				}
        }
	}
				   			
	// Format the message part
	FormatChatLine(sMyNick, sMsg, cf, isMyMessage, sAuthor, lSelEnd, bUseEmo);

	SetSel(lSelBeginSaved, lSelEndSaved);
	if(	isMyMessage || ((si.nPage == 0 || (size_t)si.nPos >= (size_t)si.nMax - si.nPage - 5) &&
		(lSelBeginSaved == lSelEndSaved || !selectedUser.empty() || !selectedIP.empty() || !selectedURL.empty())))
	{
		PostMessage(EM_SCROLL, SB_BOTTOM, 0);
	} else {
		SetScrollPos(&pt);
	}

	// Force window to redraw
	SetRedraw(TRUE);
	InvalidateRect(NULL);
}
Exemplo n.º 27
0
void CEmoticonRichEditCtrl::FormatTextRange(int nStart, int nEnd)
{	
	BOOL bEmoticon = FALSE;

	if (nStart >= nEnd)
	{
		TRACE("\nreturn!!\n");
		return;
	}

	m_bInForcedChange = TRUE;

	CHARRANGE crOldSel;
	
	GetSel(crOldSel);	

	TRACE("crOldSel MIN [%d] MAX [%d] \n", crOldSel.cpMin, crOldSel.cpMax );
			
	HideSelection(TRUE, FALSE);
	
	TCHAR *pBuffer = NULL;
	//char *pBuffer = NULL;	

	try 
	{
		TRACE("FormatTextRange : nStart [%d] nEnd [%d] \n", nStart, nEnd);

		SetSel(nStart, nEnd);
								
		pBuffer = new TCHAR[nEnd - nStart + 1];
		//pBuffer = new char[nEnd - nStart + 1];

		long nLen = GetSelText(pBuffer);
		pBuffer[nLen] = 0;

		TRACE("new [%d] pBuffer [%S]\n", nEnd - nStart + 1, pBuffer);
		//ASSERT(nLen <= nEnd - nStart);	

		TCHAR *pStart, *pPtr, *pSymbolStart ;		
		//char* pStart = NULL, *pPtr = NULL;		
		//char* pSymbolStart = NULL;

		pStart = pPtr = pBuffer;
		
		while (*pPtr != 0) 
		{			
			TCHAR ch = *pPtr;					
			//char ch = *pPtr;					
			
			if ( _istalpha(ch) || ch == '_') 
			{ 
				pSymbolStart = pPtr;
				
				do 
				{
					ch = *(++pPtr);
				} 
				while (_istalnum(ch) || ch == '_');

				*pPtr = 0;
				
				//TRACE("pSymbolStart  [%s]\n", pSymbolStart );	
								
				int nPos = IsEmoticon(pSymbolStart);
				
				if (nPos >= 0) 
				{					
					bEmoticon = TRUE;					
		
					SetBackgroundColor( FALSE, CChatSession::Instance().m_ColorBG);					
		
					//TRACE("이모티콘!!! [%s]\n", pSymbolStart );
					
					SetSel(nStart + pSymbolStart - pBuffer, nStart + pPtr - pBuffer  );
					
					ReplaceSel("  ");					
										
					TRACE("이모티콘영역 [%d] [%d]\n", nStart + pSymbolStart - pBuffer, nStart + pPtr - pBuffer );	
					
					CString strTmp(pSymbolStart);
					int nIndex = atoi( (LPCSTR)strTmp.Mid(2,2) ) ;
					
					HBITMAP hBitmap = GetImage( m_imgListFaces , nIndex );

					if (hBitmap)
					{
						CString strOutID;
						strOutID.Empty();
						CImageDataObject::InsertBitmap(m_pRichEditOle, hBitmap, strOutID ); // strTmp => ec01 , strOutID = 12232132321 

						if(m_nRole == ROLE_SEND_INPUT )
						{
							char* pszID = new char[10+1];
							char* pszVal = new char[10+1];
							strncpy(pszID, (LPCSTR)strOutID, 10);
							strcpy(pszVal, pSymbolStart);
							
							TRACE("WM_EMOTICON_MAP : pszID [%s] pszVal [%s]\n", pszID, pszVal );
							GetParent()->SendMessage( WM_EMOTICON_MAP, (WPARAM) pszID , (LPARAM) pszVal) ;
						}						
					}

					ReplaceSel(" ");
					
					pStart = pPtr;
					pSymbolStart = 0;
										
				}
				else
				{
					pSymbolStart = NULL;
				}
				
				*pPtr = ch;
			}
			else 
			{
				pPtr++;
			}
		}
		
	} 
	catch(...)
	{
		//delete [] pBuffer;
		//pBuffer = NULL ;
	}	
	
	delete [] pBuffer;
	
	if(m_nRole == ROLE_SEND_INPUT )
	{	
		CHARFORMAT2 cf;
		GetSelectionCharFormat(cf);
		cf.dwMask = CFM_COLOR | CFM_FACE | CFM_SIZE    ; 
		cf.crTextColor =  CChatSession::Instance().m_ColorMe;			
		cf.dwEffects &=(unsigned long) ~CFE_AUTOCOLOR;	
		SetSelectionCharFormat(cf);
	}
	
	SetSel(crOldSel);
	
	if(m_nRole == ROLE_SEND_INPUT )
	{	
		CHARFORMAT2 cf;
		GetSelectionCharFormat(cf);
		cf.dwMask = CFM_COLOR | CFM_FACE | CFM_SIZE    ; 
		cf.crTextColor =  CChatSession::Instance().m_ColorMe;			
		cf.dwEffects &=(unsigned long) ~CFE_AUTOCOLOR;	
		SetSelectionCharFormat(cf);
	}
	

	HideSelection(FALSE, FALSE);
		
	//UnlockWindowUpdate();		
			
	SetBackgroundColor( FALSE, CChatSession::Instance().m_ColorBG );	
	
	m_bInForcedChange = FALSE;
}