2015-04-02 22:27:58 +08:00
|
|
|
#include "TextBuffer.h"
|
|
|
|
|
2018-06-11 08:35:24 +08:00
|
|
|
DWORD WINAPI FlushThread(LPVOID lParam)
|
|
|
|
{
|
|
|
|
TextBuffer* t = (TextBuffer*)lParam;
|
|
|
|
while (t->Running())
|
|
|
|
{
|
|
|
|
t->Flush();
|
|
|
|
Sleep(10);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2015-04-02 22:27:58 +08:00
|
|
|
|
|
|
|
TextBuffer::TextBuffer(HWND edit) : hThread(IthCreateThread(FlushThread, (DWORD)this)),
|
2016-01-05 23:01:17 +08:00
|
|
|
hEdit(edit),
|
|
|
|
running(true)
|
2015-04-02 22:27:58 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TextBuffer::~TextBuffer()
|
|
|
|
{
|
|
|
|
running = false;
|
|
|
|
WaitForSingleObject(hThread.get(), 0);
|
|
|
|
}
|
|
|
|
|
2018-07-19 04:18:43 +08:00
|
|
|
void TextBuffer::AddText(std::wstring text, bool line)
|
2015-04-02 22:27:58 +08:00
|
|
|
{
|
|
|
|
CSLock lock(cs);
|
2018-07-19 04:18:43 +08:00
|
|
|
this->str.append(text);
|
2015-04-02 22:27:58 +08:00
|
|
|
line_break = line;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextBuffer::Flush()
|
|
|
|
{
|
|
|
|
CSLock lock(cs);
|
|
|
|
if (line_break || str.empty())
|
|
|
|
return;
|
|
|
|
DWORD t = Edit_GetTextLength(hEdit);
|
|
|
|
Edit_SetSel(hEdit, t, -1);
|
|
|
|
Edit_ReplaceSel(hEdit, str.c_str());
|
|
|
|
str.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextBuffer::ClearBuffer()
|
|
|
|
{
|
|
|
|
CSLock lock(cs);
|
|
|
|
str.clear();
|
|
|
|
line_break = false;
|
|
|
|
}
|