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) { CHARFORMAT2 cf; memset(&cf, 0, sizeof(cf)); GetSelectionCharFormat(cf); if(cr != CLR_DEFAULT) { cf.dwMask |= CFM_COLOR; cf.dwEffects &= ~CFE_AUTOCOLOR; cf.crTextColor = cr; } if(bk != CLR_DEFAULT) { cf.dwMask |= CFM_BACKCOLOR; cf.dwEffects &= ~CFE_AUTOBACKCOLOR; cf.crBackColor = bk; } cf.dwMask |= mask; if(mask & CFM_BOLD) cf.dwEffects |= CFE_BOLD; //Checks if bold is set in the mask and then sets it in effects if it is else if(cf.dwEffects & CFE_BOLD) cf.dwEffects ^= CFE_BOLD; //Unset bold if(mask & CFM_ITALIC) cf.dwEffects |= CFE_ITALIC; //Checks if italic is set in the mask and then sets it in effects if it is else if(cf.dwEffects & CFE_ITALIC) cf.dwEffects ^= CFE_ITALIC; //Unset bold if(mask & CFM_UNDERLINE) cf.dwEffects |= CFE_UNDERLINE; //Checks if underlined is set in the mask and then sets it in effects if it is else if(cf.dwEffects & CFE_UNDERLINE) cf.dwEffects ^= CFE_UNDERLINE; //Unset italic SetSelectionCharFormat(cf); bRestoreFormat = true; } else if (m_bRestoreFormat) { SetSelectionCharFormat(m_cfDefault); } ReplaceSel(pszString); m_bRestoreFormat = bRestoreFormat; }
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); }
CHARFORMAT CAutoRichEditCtrl::GetCharFormat(DWORD dwMask) { CHARFORMAT cf; cf.cbSize = sizeof(CHARFORMAT); cf.dwMask = dwMask; GetSelectionCharFormat(cf); return cf; }
bool ChatCtrl::HitURL() { long lSelBegin = 0, lSelEnd = 0; GetSel(lSelBegin, lSelEnd); CHARFORMAT2 cfSel; memzero(&cfSel, sizeof(CHARFORMAT2)); //PPA cfSel.cbSize = sizeof(cfSel); GetSelectionCharFormat(cfSel); return (cfSel.dwEffects & CFE_LINK) == CFE_LINK; }
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); }
CString CRichEditCtrlGS::GetFontName(void) { CHARFORMAT cf; cf.cbSize = sizeof(CHARFORMAT); cf.dwMask = CFM_FACE; DWORD dwSelMask = GetSelectionCharFormat(cf); CString strName =_T(""); // return only the font name it is the same over the whole selection if( (cf.dwMask & CFM_FACE) & (dwSelMask & CFM_FACE) ) { strName = cf.szFaceName; } return strName; }
void CFulEditCtrl::SetTextColor( COLORREF color ) { CHARFORMAT cf; cf.cbSize = sizeof(CHARFORMAT); cf.dwMask = CFM_COLOR; cf.dwEffects = 0; cf.crTextColor = color; SetDefaultCharFormat(cf); //otroligt fulhack, måste lagas riktigt nån gång selFormat.cbSize = sizeof(CHARFORMAT2); GetSelectionCharFormat(selFormat); }
int CRichEditCtrlGS::GetFontSize(void) { CHARFORMAT cf; int nPointSize = 0; cf.cbSize = sizeof(CHARFORMAT); cf.dwMask = CFM_SIZE; DWORD dwSelMask = GetSelectionCharFormat(cf); // return only the font size it is the same over the whole selection if( (cf.dwMask & CFM_SIZE) & (dwSelMask & CFM_SIZE) ) { nPointSize = cf.yHeight/20;// convert from twips to points } return nPointSize; }
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 CRichEditStream::InitColors() { m_cfDef.cbSize = sizeof m_cfDef; if (GetSelectionCharFormat(m_cfDef)) { m_cfBold = m_cfDef; m_cfBold.dwMask |= CFM_BOLD; m_cfBold.dwEffects |= CFE_BOLD; m_cfRed = m_cfDef; m_cfRed.dwMask |= CFM_COLOR; m_cfRed.dwEffects &= ~CFE_AUTOCOLOR; m_cfRed.crTextColor = RGB(255, 0, 0); } }
void CHTRichEditCtrl::Init(LPCTSTR pszTitle, LPCTSTR pszSkinKey) { SetProfileSkinKey(pszSkinKey); SetTitle(pszTitle); VERIFY( SendMessage(EM_SETUNDOLIMIT, 0, 0) == 0 ); int iMaxLogBuff = thePrefs.GetMaxLogBuff(); LimitText(iMaxLogBuff ? iMaxLogBuff : 128*1024); m_iLimitText = GetLimitText(); VERIFY( GetSelectionCharFormat(m_cfDefault) ); // prevent the RE control to change the font height within single log lines (may happen with some Unicode chars) DWORD dwLangOpts = SendMessage(EM_GETLANGOPTIONS); SendMessage(EM_SETLANGOPTIONS, 0, dwLangOpts & ~(IMF_AUTOFONT /*| IMF_AUTOFONTSIZEADJUST*/)); //SendMessage(EM_SETEDITSTYLE, SES_EMULATESYSEDIT, SES_EMULATESYSEDIT); }
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); }
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); }
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); }
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 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); //为将要输入的内容设定字体 } }
void CHTRichEditCtrl::SetFont(CFont* pFont, BOOL bRedraw) { LOGFONT lf = {0}; pFont->GetLogFont(&lf); CHARFORMAT cf = {0}; cf.cbSize = sizeof cf; cf.dwMask |= CFM_BOLD; cf.dwEffects |= (lf.lfWeight == FW_BOLD) ? CFE_BOLD : 0; cf.dwMask |= CFM_ITALIC; cf.dwEffects |= (lf.lfItalic) ? CFE_ITALIC : 0; cf.dwMask |= CFM_UNDERLINE; cf.dwEffects |= (lf.lfUnderline) ? CFE_UNDERLINE : 0; cf.dwMask |= CFM_STRIKEOUT; cf.dwEffects |= (lf.lfStrikeOut) ? CFE_STRIKEOUT : 0; cf.dwMask |= CFM_SIZE; HDC hDC = ::GetDC(NULL); int iPointSize = -MulDiv(lf.lfHeight, 72, GetDeviceCaps(hDC, LOGPIXELSY)); cf.yHeight = iPointSize * 20; ::ReleaseDC(NULL, hDC); cf.dwMask |= CFM_FACE; cf.bPitchAndFamily = lf.lfPitchAndFamily; _tcsncpy(cf.szFaceName, lf.lfFaceName, ARRSIZE(cf.szFaceName)); cf.szFaceName[ARRSIZE(cf.szFaceName) - 1] = _T('\0'); // although this should work correctly (according SDK) it may give false results (e.g. the "click here..." text // which is shown in the server info window may not be entirely used as a hyperlink???) // cf.dwMask |= CFM_CHARSET; // cf.bCharSet = lf.lfCharSet; cf.yOffset = 0; VERIFY( SetDefaultCharFormat(cf) ); VERIFY( GetSelectionCharFormat(m_cfDefault) ); if (bRedraw){ Invalidate(); UpdateWindow(); } }
int CRichEditCtrlGS::IsStrikeout(void) { CHARFORMAT cf; cf.cbSize = sizeof(CHARFORMAT); cf.dwMask = CFM_STRIKEOUT; DWORD dwSelMask = GetSelectionCharFormat(cf); bool bConsistent = false; // STRIKEOUT inconsistent over the whole Selection if( dwSelMask & CFM_STRIKEOUT )// STRIKEOUT consistent over the whole Selection? { bConsistent = true; } if( !bConsistent ) { return (-1); // Set Button to indeterminate } if( cf.dwEffects & CFE_STRIKEOUT ) { return(1); // Set Button to checked } return 0; // Set Button to unchecked }
int CRichEditCtrlGS::IsUnderlined(void) { CHARFORMAT cf; cf.cbSize = sizeof(CHARFORMAT); cf.dwMask = CFM_UNDERLINE; DWORD dwSelMask = GetSelectionCharFormat(cf); bool bConsistent = false; // UNDERLINE inconsistent over the whole Selection if( dwSelMask & CFM_UNDERLINE )// UNDERLINE consistent over the whole Selection? { bConsistent = true; } if( !bConsistent ) { return (-1); // Set Button to indeterminate } if( cf.dwEffects & CFE_UNDERLINE ) { return(1); // Set Button to checked } return 0; // Set Button to unchecked }
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); }
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); }
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; }
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); }
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 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; } } }
void CHTRichEditCtrl::ApplySkin() { if (!m_strSkinKey.IsEmpty()) { // Use the 'ScrollInfo' only, if there is a scrollbar available, otherwise we would // use a scrollinfo which points to the top and we would thus stay at the top. bool bAtEndOfScroll; SCROLLINFO si; si.cbSize = sizeof si; si.fMask = SIF_ALL; if ((GetStyle() & WS_VSCROLL) && GetScrollInfo(SB_VERT, &si)) bAtEndOfScroll = (si.nPos >= (int)(si.nMax - si.nPage)); else bAtEndOfScroll = true; COLORREF cr; if (theApp.LoadSkinColor(m_strSkinKey + _T("Fg"), cr)) { m_bDfltForeground = false; m_crForeground = cr; } else { m_bDfltForeground = m_crDfltForeground == CLR_DEFAULT; m_crForeground = m_bDfltForeground ? GetSysColor(COLOR_WINDOWTEXT) : m_crDfltForeground; } bool bSetCharFormat = false; CHARFORMAT cf; GetDefaultCharFormat(cf); if (!m_bDfltForeground && (cf.dwEffects & CFE_AUTOCOLOR)) { cf.dwEffects &= ~CFE_AUTOCOLOR; bSetCharFormat = true; } else if (m_bDfltForeground && !(cf.dwEffects & CFE_AUTOCOLOR)) { cf.dwEffects |= CFE_AUTOCOLOR; bSetCharFormat = true; } if (bSetCharFormat) { cf.dwMask |= CFM_COLOR; cf.crTextColor = m_crForeground; VERIFY( SetDefaultCharFormat(cf) ); VERIFY( GetSelectionCharFormat(m_cfDefault) ); } if (theApp.LoadSkinColor(m_strSkinKey + _T("Bk"), cr)) { m_bDfltBackground = false; m_crBackground = cr; SetBackgroundColor(FALSE, m_crBackground); } else { m_bDfltBackground = m_crDfltBackground == CLR_DEFAULT; m_crBackground = m_bDfltBackground ? GetSysColor(COLOR_WINDOW) : m_crDfltBackground; SetBackgroundColor(m_bDfltBackground, m_crBackground); } if (bAtEndOfScroll) ScrollToLastLine(); } else { m_bDfltForeground = m_crDfltForeground == CLR_DEFAULT; m_crForeground = m_bDfltForeground ? GetSysColor(COLOR_WINDOWTEXT) : m_crDfltForeground; m_bDfltBackground = m_crDfltBackground == CLR_DEFAULT; m_crBackground = m_bDfltBackground ? GetSysColor(COLOR_WINDOW) : m_crDfltBackground; VERIFY( GetSelectionCharFormat(m_cfDefault) ); } PurgeSmileyCaches(); }
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; }