Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void RichTextBox::addText(const RichTextBox::TextItem::List& texts) {
- if(texts.empty())
- return;
- dwt::Point scrollPos;
- ::SendMessage(handle(), EM_GETSCROLLPOS, 0, reinterpret_cast<LPARAM>(&scrollPos));
- bool scroll = scrollIsAtEnd();
- if(!scroll)
- ::SendMessage(handle(), WM_SETREDRAW, FALSE, 0);
- std::pair<int, int> cr = getCaretPosRange();
- unsigned charsRemoved = 0;
- {
- size_t len = 0;
- std::for_each(texts.begin(), texts.end(), [&len](const TextItem& ti) { len += ti.text.size(); } );
- int multipler = 1;
- size_t limit = ::SendMessage(handle(), EM_GETLIMITTEXT, 0, 0);
- if(length() + len > limit) {
- if(scroll)
- ::SendMessage(handle(), WM_SETREDRAW, FALSE, 0);
- if(len >= limit) {
- charsRemoved = length();
- } else {
- while (charsRemoved < len)
- charsRemoved = ::SendMessage(handle(), EM_LINEINDEX, sendMessage(EM_LINEFROMCHAR, multipler++ * limit / 10), 0);
- }
- scrollPos.y -= posFromChar(charsRemoved).y;
- ::SendMessage(handle(), EM_SETSEL, 0, charsRemoved);
- ::SendMessage(handle(), EM_REPLACESEL, static_cast<WPARAM>(TRUE), reinterpret_cast<LPARAM>(_T("")));
- if(scroll)
- ::SendMessage(handle(), WM_SETREDRAW, TRUE, 0);
- }
- }
- ::SendMessage(handle(), EM_SETSEL, -1, -1);
- SETTEXTEX config = { ST_SELECTION, CP_ACP };
- for(TextItem::IterC i = texts.begin(); i != texts.end(); ++i) {
- if(i->text.empty())
- continue; // nothing to do here
- if(i->check) {
- // do keywords here
- // continue;
- }
- string line = escapeUnicode(_T("{\\urtf1\n") + rtfEscape(Text::toT(Text::toDOS(i->text))) + _T("}\n"));
- ::SendMessage(handle(), EM_SETCHARFORMAT, SCF_SELECTION, reinterpret_cast<LPARAM>(&i->cf));
- ::SendMessage(handle(), EM_SETTEXTEX, reinterpret_cast<WPARAM>(&config), reinterpret_cast<LPARAM>(line.c_str()));
- }
- ::SendMessage(handle(), EM_SETSEL, cr.first-charsRemoved, cr.second-charsRemoved);
- if(scroll) {
- const std::pair<int, int> sel = getCaretPosRange();
- ::SendMessage(handle(), EM_SETSEL, length(), -1);
- ::SendMessage(handle(), EM_SCROLLCARET, 0, 0);
- ::SendMessage(handle(), EM_SETSEL, sel.first, sel.second);
- ::SendMessage(handle(), WM_VSCROLL, SB_BOTTOM, 0);
- } else {
- ::SendMessage(handle(), EM_SETSCROLLPOS, 0, reinterpret_cast<LPARAM>(&scrollPos));
- }
- if(!scroll)
- ::SendMessage(handle(), WM_SETREDRAW, TRUE, 0);
- redraw();
- }
Advertisement
Add Comment
Please, Sign In to add comment