diff options
author | George Hazan <ghazan@miranda.im> | 2023-04-14 23:33:11 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2023-04-14 23:33:11 +0300 |
commit | 123fa87f68c42b4f121ad315623a9fb5a39ab30c (patch) | |
tree | b4bb358ed586b4514a099e445577887bc5f117f7 /src/mir_app | |
parent | e90d73641e9df9d3c181c9eddd85b59b8d81f8e6 (diff) |
all LogStreamInEvents implementations unified, old memory allocation schema dropped
Diffstat (limited to 'src/mir_app')
-rw-r--r-- | src/mir_app/src/mir_app.def | 2 | ||||
-rw-r--r-- | src/mir_app/src/mir_app64.def | 2 | ||||
-rw-r--r-- | src/mir_app/src/srmm_log_rtf.cpp | 104 |
3 files changed, 108 insertions, 0 deletions
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 6086dfd503..f2f4b08172 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -853,3 +853,5 @@ Chat_IsMuted @941 NONAME ?GetDialog@CSrmmLogWindow@@QBEAAVCMsgDialog@@XZ @969 NONAME
?isHistory@EventInfo@DB@@QBE_NXZ @970 NONAME
?isSrmm@EventInfo@DB@@QBE_NXZ @971 NONAME
+?CreateRtfTail@CRtfLogWindow@@UAEXPAURtfLogStreamData@@@Z @972 NONAME
+?StreamRtfEvents@CRtfLogWindow@@QAEXPAURtfLogStreamData@@_N@Z @973 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 678dd85842..5151b526c4 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -853,3 +853,5 @@ Chat_IsMuted @941 NONAME ?GetDialog@CSrmmLogWindow@@QEBAAEAVCMsgDialog@@XZ @969 NONAME
?isHistory@EventInfo@DB@@QEBA_NXZ @970 NONAME
?isSrmm@EventInfo@DB@@QEBA_NXZ @971 NONAME
+?CreateRtfTail@CRtfLogWindow@@UEAAXPEAURtfLogStreamData@@@Z @972 NONAME
+?StreamRtfEvents@CRtfLogWindow@@QEAAXPEAURtfLogStreamData@@_N@Z @973 NONAME
diff --git a/src/mir_app/src/srmm_log_rtf.cpp b/src/mir_app/src/srmm_log_rtf.cpp index eae329a4f0..88a8466f93 100644 --- a/src/mir_app/src/srmm_log_rtf.cpp +++ b/src/mir_app/src/srmm_log_rtf.cpp @@ -27,6 +27,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h"
#include "chat.h"
+#define STREAMSTAGE_HEADER 0
+#define STREAMSTAGE_EVENTS 1
+#define STREAMSTAGE_TAIL 2
+#define STREAMSTAGE_STOP 3
+
#define EVENTTYPE_STATUSCHANGE 25368
#define EVENTTYPE_ERRMSG 25366
@@ -61,6 +66,13 @@ void CRtfLogWindow::Attach() /////////////////////////////////////////////////////////////////////////////////////////
+void CRtfLogWindow::CreateRtfTail(RtfLogStreamData *dat)
+{
+ dat->buf = "}";
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
void CRtfLogWindow::Detach()
{
mir_unsubclassWindow(m_rtf.GetHwnd(), stubLogProc);
@@ -263,6 +275,98 @@ void CRtfLogWindow::ScrollToBottom() /////////////////////////////////////////////////////////////////////////////////////////
+#define EVENTTYPE_JABBER_CHATSTATES 2000
+#define EVENTTYPE_JABBER_PRESENCE 2001
+
+static bool CreateRtfFromDbEvent(RtfLogStreamData *dat)
+{
+ DB::EventInfo dbei(dat->hDbEvent);
+ if (!dbei)
+ return false;
+
+ if (!dat->pLog->CreateRtfEvent(dat, dbei))
+ return false;
+
+ if (!(dbei.flags & DBEF_SENT) && (dbei.eventType == EVENTTYPE_MESSAGE || dbei.isSrmm())) {
+ db_event_markRead(dat->hContact, dat->hDbEvent);
+ g_clistApi.pfnRemoveEvent(dat->hContact, dat->hDbEvent);
+ }
+ else if (dbei.eventType == EVENTTYPE_JABBER_CHATSTATES || dbei.eventType == EVENTTYPE_JABBER_PRESENCE) {
+ db_event_markRead(dat->hContact, dat->hDbEvent);
+ }
+
+ return true;
+}
+
+static DWORD CALLBACK LogStreamInEvents(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
+{
+ auto *dat = (RtfLogStreamData *)dwCookie;
+
+ if (dat->buf.IsEmpty()) {
+ switch (dat->stage) {
+ case STREAMSTAGE_HEADER:
+ dat->pLog->CreateRtfHeader(dat);
+ dat->stage = STREAMSTAGE_EVENTS;
+ break;
+
+ case STREAMSTAGE_EVENTS:
+ if (dat->dbei) {
+ if (dat->pLog->CreateRtfEvent(dat, *dat->dbei)) {
+ dat->eventsToInsert++;
+ break;
+ }
+ }
+ else if (dat->eventsToInsert) {
+ bool bOk;
+ do {
+ bOk = CreateRtfFromDbEvent(dat);
+ if (bOk)
+ dat->hDbEventLast = dat->hDbEvent;
+
+ dat->hDbEvent = db_event_next(dat->hContact, dat->hDbEvent);
+ if (--dat->eventsToInsert == 0)
+ break;
+ } while (!bOk && dat->hDbEvent);
+
+ if (bOk) {
+ dat->isEmpty = false;
+ break;
+ }
+ }
+ dat->stage = STREAMSTAGE_TAIL;
+ __fallthrough;
+
+ case STREAMSTAGE_TAIL:
+ dat->pLog->CreateRtfTail(dat);
+ dat->stage = STREAMSTAGE_STOP;
+ break;
+
+ case STREAMSTAGE_STOP:
+ *pcb = 0;
+ return 0;
+ }
+ }
+
+ *pcb = min(cb, dat->buf.GetLength());
+ memcpy(pbBuff, dat->buf.GetBuffer(), *pcb);
+ if (dat->buf.GetLength() == *pcb)
+ dat->buf.Empty();
+ else
+ dat->buf.Delete(0, *pcb);
+
+ return 0;
+}
+
+void CRtfLogWindow::StreamRtfEvents(RtfLogStreamData *dat, bool bAppend)
+{
+ EDITSTREAM stream = {};
+ stream.pfnCallback = LogStreamInEvents;
+ stream.dwCookie = (DWORD_PTR)dat;
+ m_rtf.SendMsg(EM_STREAMIN, bAppend ? SFF_SELECTION | SF_RTF : SF_RTF, (LPARAM)&stream);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
static wchar_t szTrimString[] = L":;,.!?\'\"><()[]- \r\n";
INT_PTR CRtfLogWindow::WndProc(UINT msg, WPARAM wParam, LPARAM lParam)
|