diff options
author | George Hazan <george.hazan@gmail.com> | 2016-08-10 15:41:23 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2016-08-10 15:41:23 +0000 |
commit | db146a5cb80ab954dfb5c0e6a97930b830352846 (patch) | |
tree | 5a8669ece564991f9e109545020df9f55805c50a | |
parent | f7bdc97d3a76f14d28866f60b2e44f9e1e7f98bf (diff) |
- unused variable logIconBmpSize removed;
- last remaining buffer/bufAlloced replaced with CMStringA
git-svn-id: http://svn.miranda-ng.org/main/trunk@17173 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | include/m_chat_int.h | 1 | ||||
-rw-r--r-- | plugins/Scriver/src/msglog.cpp | 262 | ||||
-rw-r--r-- | plugins/TabSRMM/src/chat/log.cpp | 2 | ||||
-rw-r--r-- | src/core/stdmsg/src/msglog.cpp | 3 | ||||
-rw-r--r-- | src/mir_app/src/chat.h | 1 | ||||
-rw-r--r-- | src/mir_app/src/chat_log.cpp | 182 | ||||
-rw-r--r-- | src/mir_app/src/chat_manager.cpp | 1 |
7 files changed, 185 insertions, 267 deletions
diff --git a/include/m_chat_int.h b/include/m_chat_int.h index e2c9711c4f..30cc1e1115 100644 --- a/include/m_chat_int.h +++ b/include/m_chat_int.h @@ -405,7 +405,6 @@ struct CHAT_MANAGER HANDLE hBuildMenuEvent, hSendEvent;
FONTINFO aFonts[OPTIONS_FONTCOUNT];
SESSION_INFO *wndList;
- size_t *logIconBmpSize;
char **pLogIconBmpBits;
// user-defined custom callbacks
diff --git a/plugins/Scriver/src/msglog.cpp b/plugins/Scriver/src/msglog.cpp index b890d7f12b..129ad0818a 100644 --- a/plugins/Scriver/src/msglog.cpp +++ b/plugins/Scriver/src/msglog.cpp @@ -30,7 +30,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern int RTL_Detect(WCHAR *pszwText);
static int logPixelSY;
static char* pLogIconBmpBits[3];
-static size_t logIconBmpSize[_countof(pLogIconBmpBits)];
static HIMAGELIST g_hImageList;
#define STREAMSTAGE_HEADER 0
@@ -210,79 +209,63 @@ static void freeEvent(EventData *evt) mir_free(evt);
}
-static int AppendUnicodeOrAnsiiToBufferL(char *&buffer, size_t &cbBufferEnd, size_t &cbBufferAlloced, const WCHAR *line, size_t maxLen, BOOL isAnsii)
+static int AppendUnicodeOrAnsiiToBufferL(CMStringA &buf, const WCHAR *line, size_t maxLen, BOOL isAnsii)
{
if (maxLen == -1)
maxLen = mir_wstrlen(line);
-
+
const WCHAR *maxLine = line + maxLen;
- size_t lineLen = maxLen*9 + 8;
- if (cbBufferEnd + lineLen > cbBufferAlloced) {
- cbBufferAlloced += lineLen + 1024 - lineLen % 1024;
- buffer = (char*)mir_realloc(buffer, cbBufferAlloced);
- }
- char *d = buffer + cbBufferEnd;
- if (isAnsii) {
- mir_strcpy(d, "{");
- d++;
- }
- else {
- mir_strcpy(d, "{\\uc1 ");
- d += 6;
- }
+ if (isAnsii)
+ buf.Append("{");
+ else
+ buf.Append("{\\uc1 ");
int wasEOL = 0, textCharsCount = 0;
for (; line < maxLine; line++, textCharsCount++) {
wasEOL = 0;
if (*line == '\r' && line[1] == '\n') {
- memcpy(d, "\\line ", 6);
+ buf.Append("\\line ");
wasEOL = 1;
- d += 6;
line++;
}
else if (*line == '\n') {
- memcpy(d, "\\line ", 6);
+ buf.Append("\\line ");
wasEOL = 1;
- d += 6;
}
else if (*line == '\t') {
- memcpy(d, "\\tab ", 5);
- d += 5;
+ buf.Append("\\tab ");
}
else if (*line == '\\' || *line == '{' || *line == '}') {
- *d++ = '\\';
- *d++ = (char)*line;
+ buf.AppendChar('\\');
+ buf.AppendChar((char)*line);
}
else if (*line < 128) {
- *d++ = (char)*line;
+ buf.AppendChar((char)*line);
}
else if (isAnsii) {
- d += sprintf(d, "\\'%02x", (*line) & 0xFF);
+ buf.AppendFormat("\\'%02x", (*line) & 0xFF);
}
else {
- d += sprintf(d, "\\u%d ?", *line);
+ buf.AppendFormat("\\u%d ?", *line);
}
}
- if (wasEOL) {
- memcpy(d, " ", 1);
- d++;
- }
- mir_strcpy(d, "}");
- d++;
+ if (wasEOL)
+ buf.AppendChar(' ');
+
+ buf.AppendChar('}');
- cbBufferEnd = (int)(d - buffer);
return textCharsCount;
}
-static int AppendAnsiToBuffer(char *&buffer, size_t &cbBufferEnd, size_t &cbBufferAlloced, const char *line)
+static int AppendAnsiToBuffer(CMStringA &buf, const char *line)
{
- return AppendUnicodeOrAnsiiToBufferL(buffer, cbBufferEnd, cbBufferAlloced, _A2T(line), -1, TRUE);
+ return AppendUnicodeOrAnsiiToBufferL(buf, _A2T(line), -1, true);
}
-static int AppendUnicodeToBuffer(char *&buffer, size_t &cbBufferEnd, size_t &cbBufferAlloced, const WCHAR *line)
+static int AppendUnicodeToBuffer(CMStringA &buf, const WCHAR *line)
{
- return AppendUnicodeOrAnsiiToBufferL(buffer, cbBufferEnd, cbBufferAlloced, line, -1, FALSE);
+ return AppendUnicodeOrAnsiiToBufferL(buf, line, -1, false);
}
// mir_free() the return value
@@ -292,47 +275,42 @@ static char* CreateRTFHeader() logPixelSY = GetDeviceCaps(hdc, LOGPIXELSY);
ReleaseDC(NULL, hdc);
- size_t bufferEnd = 0, bufferAlloced = 1024;
- char *buffer = (char*)mir_alloc(bufferAlloced);
- buffer[0] = '\0';
+ CMStringA buf;
- AppendToBuffer(buffer, bufferEnd, bufferAlloced,"{\\rtf1\\ansi\\deff0{\\fonttbl");
+ buf.Append("{\\rtf1\\ansi\\deff0{\\fonttbl");
for (int i = 0; i < fontOptionsListSize; i++) {
LOGFONT lf;
LoadMsgDlgFont(i, &lf, NULL);
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "{\\f%u\\fnil\\fcharset%u %S;}", i, lf.lfCharSet, lf.lfFaceName);
+ buf.AppendFormat("{\\f%u\\fnil\\fcharset%u %S;}", i, lf.lfCharSet, lf.lfFaceName);
}
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "}{\\colortbl ");
+ buf.Append("}{\\colortbl ");
COLORREF colour;
for (int i = 0; i < fontOptionsListSize; i++) {
LoadMsgDlgFont(i, NULL, &colour);
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour));
+ buf.AppendFormat("\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour));
}
if (GetSysColorBrush(COLOR_HOTLIGHT) == NULL)
colour = RGB(0, 0, 255);
else
colour = GetSysColor(COLOR_HOTLIGHT);
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour));
+ buf.AppendFormat("\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour));
colour = db_get_dw(NULL, SRMMMOD, SRMSGSET_BKGCOLOUR, SRMSGDEFSET_BKGCOLOUR);
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour));
+ buf.AppendFormat("\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour));
colour = db_get_dw(NULL, SRMMMOD, SRMSGSET_INCOMINGBKGCOLOUR, SRMSGDEFSET_INCOMINGBKGCOLOUR);
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour));
+ buf.AppendFormat("\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour));
colour = db_get_dw(NULL, SRMMMOD, SRMSGSET_OUTGOINGBKGCOLOUR, SRMSGDEFSET_OUTGOINGBKGCOLOUR);
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour));
+ buf.AppendFormat("\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour));
colour = db_get_dw(NULL, SRMMMOD, SRMSGSET_LINECOLOUR, SRMSGDEFSET_LINECOLOUR);
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour));
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "}");
- return buffer;
+ buf.AppendFormat("\\red%u\\green%u\\blue%u;", GetRValue(colour), GetGValue(colour), GetBValue(colour));
+ buf.Append("}");
+ return buf.Detach();
}
// mir_free() the return value
static char* CreateRTFTail()
{
- size_t bufferAlloced = 1024, bufferEnd = 0;
- char *buffer = (char*)mir_alloc(bufferAlloced); buffer[0] = '\0';
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "}");
- return buffer;
+ return mir_strdup("}");
}
// return value is static
@@ -404,27 +382,29 @@ int isSameDate(time_t time1, time_t time2) return 0;
}
-static int DetectURL(wchar_t *text, BOOL firstChar) {
+static int DetectURL(wchar_t *text, BOOL firstChar)
+{
wchar_t c;
- struct prefix_s {
+ struct prefix_s
+ {
wchar_t *text;
int length;
} prefixes[12] = {
- {L"http:", 5},
- {L"file:", 5},
- {L"mailto:", 7},
- {L"ftp:", 4},
- {L"https:", 6},
- {L"gopher:", 7},
- {L"nntp:", 5},
- {L"prospero:", 9},
- {L"telnet:", 7},
- {L"news:", 5},
- {L"wais:", 5},
- {L"www.", 4}
+ { L"http:", 5 },
+ { L"file:", 5 },
+ { L"mailto:", 7 },
+ { L"ftp:", 4 },
+ { L"https:", 6 },
+ { L"gopher:", 7 },
+ { L"nntp:", 5 },
+ { L"prospero:", 9 },
+ { L"telnet:", 7 },
+ { L"news:", 5 },
+ { L"wais:", 5 },
+ { L"www.", 4 }
};
c = firstChar ? ' ' : text[-1];
- if (!((c >= '0' && c<='9') || (c >= 'A' && c<='Z') || (c >= 'a' && c<='z'))) {
+ if (!((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))) {
int found = 0;
int i, len = 0;
int prefixlen = _countof(prefixes);
@@ -436,9 +416,9 @@ static int DetectURL(wchar_t *text, BOOL firstChar) { }
}
if (found) {
- for (; text[len]!='\n' && text[len]!='\r' && text[len]!='\t' && text[len]!=' ' && text[len]!='\0'; len++);
- for (; len > 0; len --)
- if ((text[len-1] >= '0' && text[len-1]<='9') || iswalpha(text[len-1]))
+ for (; text[len] != '\n' && text[len] != '\r' && text[len] != '\t' && text[len] != ' ' && text[len] != '\0'; len++);
+ for (; len > 0; len--)
+ if ((text[len - 1] >= '0' && text[len - 1] <= '9') || iswalpha(text[len - 1]))
break;
return len;
@@ -447,7 +427,7 @@ static int DetectURL(wchar_t *text, BOOL firstChar) { return 0;
}
-static void AppendWithCustomLinks(EventData *evt, int style, char *&buffer, size_t &bufferEnd, size_t &bufferAlloced)
+static void AppendWithCustomLinks(EventData *evt, int style, CMStringA &buf)
{
if (evt->pszText == NULL)
return;
@@ -475,22 +455,22 @@ static void AppendWithCustomLinks(EventData *evt, int style, char *&buffer, size if (newtoken != lasttoken) {
if (lasttoken == 0)
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", SetToStyle(style));
+ buf.AppendFormat("%s ", SetToStyle(style));
else
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYURL : MSGFONTID_YOURURL));
+ buf.AppendFormat("%s ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYURL : MSGFONTID_YOURURL));
- AppendUnicodeOrAnsiiToBufferL(buffer, bufferEnd, bufferAlloced, wText + laststart, j - laststart, isAnsii);
+ AppendUnicodeOrAnsiiToBufferL(buf, wText + laststart, j - laststart, isAnsii);
laststart = j;
lasttoken = newtoken;
}
}
if (len - laststart > 0) {
if (lasttoken == 0)
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", SetToStyle(style));
+ buf.AppendFormat("%s ", SetToStyle(style));
else
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYURL : MSGFONTID_YOURURL));
+ buf.AppendFormat("%s ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYURL : MSGFONTID_YOURURL));
- AppendUnicodeOrAnsiiToBufferL(buffer, bufferEnd, bufferAlloced, wText + laststart, len - laststart, isAnsii);
+ AppendUnicodeOrAnsiiToBufferL(buf, wText + laststart, len - laststart, isAnsii);
}
if (isAnsii)
mir_free(wText);
@@ -502,50 +482,47 @@ static char* CreateRTFFromEvent(SrmmWindowData *dat, EventData *evt, GlobalMessa int style, showColon = 0;
int isGroupBreak = TRUE;
int highlight = 0;
-
- size_t bufferEnd = 0, bufferAlloced = 1024;
- char *buffer = (char*)mir_alloc(bufferAlloced); buffer[0] = '\0';
- if ((gdat->flags & SMF_GROUPMESSAGES) && evt->dwFlags == LOWORD(dat->lastEventType) &&
- evt->eventType == EVENTTYPE_MESSAGE && HIWORD(dat->lastEventType) == EVENTTYPE_MESSAGE &&
- (isSameDate(evt->time, dat->lastEventTime)) && ((((int)evt->time < dat->startTime) == (dat->lastEventTime < dat->startTime)) || !(evt->dwFlags & IEEDF_READ)))
- {
+ if ((gdat->flags & SMF_GROUPMESSAGES) && evt->dwFlags == LOWORD(dat->lastEventType) &&
+ evt->eventType == EVENTTYPE_MESSAGE && HIWORD(dat->lastEventType) == EVENTTYPE_MESSAGE &&
+ (isSameDate(evt->time, dat->lastEventTime)) && ((((int)evt->time < dat->startTime) == (dat->lastEventTime < dat->startTime)) || !(evt->dwFlags & IEEDF_READ))) {
isGroupBreak = FALSE;
}
-
+
+ CMStringA buf;
if (!streamData->isFirst && !dat->isMixed) {
if (isGroupBreak || gdat->flags & SMF_MARKFOLLOWUPS)
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\par");
+ buf.Append("\\par");
else
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\line");
+ buf.Append("\\line");
}
if (evt->dwFlags & IEEDF_RTL)
dat->isMixed = 1;
if (!streamData->isFirst && isGroupBreak && (gdat->flags & SMF_DRAWLINES))
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\sl-1\\slmult0\\highlight%d\\cf%d\\fs1 \\par\\sl0", fontOptionsListSize + 4, fontOptionsListSize + 4);
+ buf.AppendFormat("\\sl-1\\slmult0\\highlight%d\\cf%d\\fs1 \\par\\sl0", fontOptionsListSize + 4, fontOptionsListSize + 4);
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, (evt->dwFlags & IEEDF_RTL) ? "\\rtlpar" : "\\ltrpar");
+ buf.Append((evt->dwFlags & IEEDF_RTL) ? "\\rtlpar" : "\\ltrpar");
if (evt->eventType == EVENTTYPE_MESSAGE)
highlight = fontOptionsListSize + 2 + ((evt->dwFlags & IEEDF_SENT) ? 1 : 0);
else
highlight = fontOptionsListSize + 1;
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\highlight%d\\cf%d", highlight, highlight);
+ buf.AppendFormat("\\highlight%d\\cf%d", highlight, highlight);
if (!streamData->isFirst && dat->isMixed) {
if (isGroupBreak)
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\sl-1 \\par\\sl0");
+ buf.Append("\\sl-1 \\par\\sl0");
else
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\sl-1 \\line\\sl0");
+ buf.Append("\\sl-1 \\line\\sl0");
}
streamData->isFirst = FALSE;
if (dat->isMixed) {
if (evt->dwFlags & IEEDF_RTL)
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\ltrch\\rtlch");
+ buf.Append("\\ltrch\\rtlch");
else
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\rtlch\\ltrch");
+ buf.Append("\\rtlch\\ltrch");
}
if ((gdat->flags & SMF_SHOWICONS) && isGroupBreak) {
int i = LOGICON_MSG_NOTICE;
@@ -563,13 +540,9 @@ static char* CreateRTFFromEvent(SrmmWindowData *dat, EventData *evt, GlobalMessa break;
}
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\fs1 ");
- while (bufferAlloced - bufferEnd < logIconBmpSize[i])
- bufferAlloced += 1024;
- buffer = (char*)mir_realloc(buffer, bufferAlloced);
- memcpy(buffer + bufferEnd, pLogIconBmpBits[i], logIconBmpSize[i]);
- bufferEnd += logIconBmpSize[i];
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, " ");
+ buf.Append("\\fs1 ");
+ buf.Append(pLogIconBmpBits[i]);
+ buf.AppendChar(' ');
}
if (gdat->flags & SMF_SHOWTIME && (evt->eventType != EVENTTYPE_MESSAGE ||
@@ -588,47 +561,47 @@ static char* CreateRTFFromEvent(SrmmWindowData *dat, EventData *evt, GlobalMessa else timestampString = TimestampToString(gdat->flags, evt->time, 0);
if (timestampString != NULL) {
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYTIME : MSGFONTID_YOURTIME));
- AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, timestampString);
+ buf.AppendFormat("%s ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYTIME : MSGFONTID_YOURTIME));
+ AppendUnicodeToBuffer(buf, timestampString);
}
if (evt->eventType != EVENTTYPE_MESSAGE)
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s: ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYCOLON : MSGFONTID_YOURCOLON));
+ buf.AppendFormat("%s: ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYCOLON : MSGFONTID_YOURCOLON));
showColon = 1;
}
if ((!(gdat->flags & SMF_HIDENAMES) && evt->eventType == EVENTTYPE_MESSAGE && isGroupBreak) || evt->eventType == EVENTTYPE_JABBER_CHATSTATES || evt->eventType == EVENTTYPE_JABBER_PRESENCE) {
if (evt->eventType == EVENTTYPE_MESSAGE) {
if (showColon)
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, " %s ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYNAME : MSGFONTID_YOURNAME));
+ buf.AppendFormat(" %s ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYNAME : MSGFONTID_YOURNAME));
else
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYNAME : MSGFONTID_YOURNAME));
+ buf.AppendFormat("%s ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYNAME : MSGFONTID_YOURNAME));
}
- else AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", SetToStyle(MSGFONTID_NOTICE));
+ else buf.AppendFormat("%s ", SetToStyle(MSGFONTID_NOTICE));
if (evt->dwFlags & IEEDF_UNICODE_NICK)
- AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, evt->pszNickW);
+ AppendUnicodeToBuffer(buf, evt->pszNickW);
else
- AppendAnsiToBuffer(buffer, bufferEnd, bufferAlloced, evt->pszNick);
+ AppendAnsiToBuffer(buf, evt->pszNick);
showColon = 1;
if (evt->eventType == EVENTTYPE_MESSAGE && gdat->flags & SMF_GROUPMESSAGES) {
if (gdat->flags & SMF_MARKFOLLOWUPS)
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\par");
+ buf.Append("\\par");
else
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\line");
+ buf.Append("\\line");
showColon = 0;
}
}
if ((gdat->flags & SMF_AFTERMASK) == SMF_AFTERMASK && evt->eventType == EVENTTYPE_MESSAGE && isGroupBreak) {
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, " %s ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYTIME : MSGFONTID_YOURTIME));
- AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, TimestampToString(gdat->flags, evt->time, 2));
+ buf.AppendFormat(" %s ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYTIME : MSGFONTID_YOURTIME));
+ AppendUnicodeToBuffer(buf, TimestampToString(gdat->flags, evt->time, 2));
showColon = 1;
}
if (showColon && evt->eventType == EVENTTYPE_MESSAGE) {
if (evt->dwFlags & IEEDF_RTL)
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\~%s: ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYCOLON : MSGFONTID_YOURCOLON));
+ buf.AppendFormat("\\~%s: ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYCOLON : MSGFONTID_YOURCOLON));
else
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s: ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYCOLON : MSGFONTID_YOURCOLON));
+ buf.AppendFormat("%s: ", SetToStyle(evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYCOLON : MSGFONTID_YOURCOLON));
}
switch (evt->eventType) {
case EVENTTYPE_JABBER_CHATSTATES:
@@ -636,53 +609,53 @@ static char* CreateRTFFromEvent(SrmmWindowData *dat, EventData *evt, GlobalMessa case EVENTTYPE_URL:
case EVENTTYPE_FILE:
style = MSGFONTID_NOTICE;
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", SetToStyle(style));
+ buf.AppendFormat("%s ", SetToStyle(style));
if (evt->eventType == EVENTTYPE_FILE) {
if (evt->dwFlags & IEEDF_SENT)
- AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, TranslateT("File sent"));
+ AppendUnicodeToBuffer(buf, TranslateT("File sent"));
else
- AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, TranslateT("File received"));
- AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, L":");
+ AppendUnicodeToBuffer(buf, TranslateT("File received"));
+ AppendUnicodeToBuffer(buf, L":");
}
else if (evt->eventType == EVENTTYPE_URL) {
if (evt->dwFlags & IEEDF_SENT)
- AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, TranslateT("URL sent"));
+ AppendUnicodeToBuffer(buf, TranslateT("URL sent"));
else
- AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, TranslateT("URL received"));
- AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, L":");
+ AppendUnicodeToBuffer(buf, TranslateT("URL received"));
+ AppendUnicodeToBuffer(buf, L":");
}
- AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, L" ");
+ AppendUnicodeToBuffer(buf, L" ");
if (evt->pszTextW != NULL) {
if (evt->dwFlags & IEEDF_UNICODE_TEXT)
- AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, evt->pszTextW);
+ AppendUnicodeToBuffer(buf, evt->pszTextW);
else
- AppendAnsiToBuffer(buffer, bufferEnd, bufferAlloced, evt->pszText);
+ AppendAnsiToBuffer(buf, evt->pszText);
}
if (evt->pszText2W != NULL) {
- AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, L" (");
+ AppendUnicodeToBuffer(buf, L" (");
if (evt->dwFlags & IEEDF_UNICODE_TEXT2)
- AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, evt->pszText2W);
+ AppendUnicodeToBuffer(buf, evt->pszText2W);
else
- AppendAnsiToBuffer(buffer, bufferEnd, bufferAlloced, evt->pszText2);
- AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, L")");
+ AppendAnsiToBuffer(buf, evt->pszText2);
+ AppendUnicodeToBuffer(buf, L")");
}
break;
default:
if (gdat->flags & SMF_MSGONNEWLINE && showColon)
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\line");
+ buf.Append("\\line");
style = evt->dwFlags & IEEDF_SENT ? MSGFONTID_MYMSG : MSGFONTID_YOURMSG;
- AppendWithCustomLinks(evt, style, buffer, bufferEnd, bufferAlloced);
+ AppendWithCustomLinks(evt, style, buf);
break;
}
if (dat->isMixed)
- AppendToBuffer(buffer, bufferEnd, bufferAlloced, "\\par");
+ buf.Append("\\par");
dat->lastEventTime = evt->time;
dat->lastEventType = MAKELONG(evt->dwFlags, evt->eventType);
- return buffer;
+ return buf.Detach();
}
static DWORD CALLBACK LogStreamInEvents(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
@@ -717,8 +690,7 @@ static DWORD CALLBACK LogStreamInEvents(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG dat->hDbEvent = db_event_next(dat->hContact, dat->hDbEvent);
if (--dat->eventsToInsert == 0)
break;
- }
- while (dat->buffer == NULL && dat->hDbEvent);
+ } while (dat->buffer == NULL && dat->hDbEvent);
}
if (dat->buffer)
break;
@@ -768,7 +740,7 @@ void StreamInEvents(HWND hwndDlg, MEVENT hDbEventFirst, int count, int fAppend) FINDTEXTEXA fi;
EDITSTREAM stream = { 0 };
LogStreamData streamData = { 0 };
- SrmmWindowData *dat = (SrmmWindowData *) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+ SrmmWindowData *dat = (SrmmWindowData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
CHARRANGE oldSel, sel;
// IEVIew MOD Begin
@@ -837,10 +809,10 @@ void StreamInEvents(HWND hwndDlg, MEVENT hDbEventFirst, int count, int fAppend) SMADD_RICHEDIT3 smre;
smre.cbSize = sizeof(SMADD_RICHEDIT3);
smre.hwndRichEditControl = GetDlgItem(hwndDlg, IDC_LOG);
-
+
MCONTACT hContact = db_mc_getSrmmSub(dat->hContact);
smre.Protocolname = (hContact != NULL) ? GetContactProto(hContact) : dat->szProto;
-
+
if (fi.chrg.cpMin > 0) {
sel.cpMin = fi.chrg.cpMin;
sel.cpMax = -1;
@@ -909,7 +881,7 @@ void LoadMsgLogIcons(void) hBrush = hBkgBrush;
break;
}
-
+
pLogIconBmpBits[i] = (char*)mir_alloc(RTFPICTHEADERMAXSIZE + (bih.biSize + widthBytes * bih.biHeight) * 2);
size_t rtfHeaderSize = sprintf(pLogIconBmpBits[i], "{\\pict\\dibitmap0\\wbmbitspixel%u\\wbmplanes1\\wbmwidthbytes%u\\picw%u\\pich%u ", bih.biBitCount, widthBytes, (UINT)bih.biWidth, (UINT)bih.biHeight); //!!!!!!!!!!!
@@ -924,8 +896,6 @@ void LoadMsgLogIcons(void) bin2hex(&bih, sizeof(bih), szDest); szDest += sizeof(bih) * 2;
bin2hex(pBmpBits, widthBytes * bih.biHeight, szDest); szDest += widthBytes * bih.biHeight * 2;
mir_strcpy(szDest, "}");
-
- logIconBmpSize[i] = size_t(szDest - pLogIconBmpBits[i]) + 1;
}
mir_free(pBmpBits);
DeleteDC(hdcMem);
diff --git a/plugins/TabSRMM/src/chat/log.cpp b/plugins/TabSRMM/src/chat/log.cpp index fc0a3a3169..61b4431505 100644 --- a/plugins/TabSRMM/src/chat/log.cpp +++ b/plugins/TabSRMM/src/chat/log.cpp @@ -740,7 +740,7 @@ static char* Log_CreateRTF(LOGSTREAMDATA *streamData) else if (g_Settings.dwIconFlags) {
int iIndex = lin->bIsHighlighted ? ICON_HIGHLIGHT : EventToIcon(lin);
str.Append("\\f0\\fs14");
- str.AppendFormat(pci->pLogIconBmpBits[iIndex], (int)pci->logIconBmpSize[iIndex]);
+ str.Append(pci->pLogIconBmpBits[iIndex]);
}
if (g_Settings.bTimeStampEventColour) {
diff --git a/src/core/stdmsg/src/msglog.cpp b/src/core/stdmsg/src/msglog.cpp index 4771ce1622..bb813b25a2 100644 --- a/src/core/stdmsg/src/msglog.cpp +++ b/src/core/stdmsg/src/msglog.cpp @@ -28,7 +28,6 @@ extern IconItem iconList[]; #define LOGICON_MSG_NOTICE 2
static char *pLogIconBmpBits[3];
-static size_t logIconBmpSize[ _countof(pLogIconBmpBits) ];
#define STREAMSTAGE_HEADER 0
#define STREAMSTAGE_EVENTS 1
@@ -501,8 +500,6 @@ void LoadMsgLogIcons(void) bin2hex(&bih, sizeof(bih), szDest); szDest += sizeof(bih) * 2;
bin2hex(pBmpBits, widthBytes * bih.biHeight, szDest); szDest += widthBytes * bih.biHeight * 2;
mir_strcpy(szDest, "}");
-
- logIconBmpSize[i] = size_t(szDest - pLogIconBmpBits[i]) + 1;
}
mir_free(pBmpBits);
DeleteDC(hdcMem);
diff --git a/src/mir_app/src/chat.h b/src/mir_app/src/chat.h index 84d418ac78..e83904cde8 100644 --- a/src/mir_app/src/chat.h +++ b/src/mir_app/src/chat.h @@ -42,7 +42,6 @@ extern wchar_t *g_szFontGroup; extern mir_cs cs;
extern char* pLogIconBmpBits[14];
-extern size_t logIconBmpSize[14];
// log.c
void LoadMsgLogBitmaps(void);
diff --git a/src/mir_app/src/chat_log.cpp b/src/mir_app/src/chat_log.cpp index 529d1b423a..ca8fa5e1cd 100644 --- a/src/mir_app/src/chat_log.cpp +++ b/src/mir_app/src/chat_log.cpp @@ -25,8 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // The code for streaming the text is to a large extent copied from
// the srmm module and then modified to fit the chat module.
-char* pLogIconBmpBits[14];
-size_t logIconBmpSize[ _countof(pLogIconBmpBits) ];
+char *pLogIconBmpBits[14];
#define RTFCACHELINESIZE 128
static char CHAT_rtfFontsGlobal[OPTIONS_FONTCOUNT][RTFCACHELINESIZE];
@@ -87,28 +86,11 @@ char* Log_SetStyle(int style) return "";
}
-static void Log_Append(char *&buffer, size_t &cbBufferEnd, size_t &cbBufferAlloced, const char *fmt, ...)
-{
- va_list va;
- int charsDone = 0;
-
- va_start(va, fmt);
- for (;;) {
- charsDone = mir_vsnprintf(buffer + cbBufferEnd, cbBufferAlloced - cbBufferEnd, fmt, va);
- if (charsDone >= 0)
- break;
- cbBufferAlloced += 4096;
- buffer = (char*)mir_realloc(buffer, cbBufferAlloced);
- }
- va_end(va);
- cbBufferEnd += charsDone;
-}
-
-static int Log_AppendRTF(LOGSTREAMDATA *streamData, BOOL simpleMode, char *&buffer, size_t &cbBufferEnd, size_t &cbBufferAlloced, const wchar_t *fmt, ...)
+static int Log_AppendRTF(LOGSTREAMDATA *streamData, bool simpleMode, CMStringA &buf, const wchar_t *fmt, ...)
{
va_list va;
int lineLen, textCharsCount = 0;
- wchar_t* line = (wchar_t*)alloca(8001 * sizeof(wchar_t));
+ wchar_t *line = (wchar_t*)alloca(8001 * sizeof(wchar_t));
va_start(va, fmt);
lineLen = mir_vsnwprintf(line, 8000, fmt, va);
@@ -117,22 +99,14 @@ static int Log_AppendRTF(LOGSTREAMDATA *streamData, BOOL simpleMode, char *&buff va_end(va);
lineLen = lineLen * 20 + 8;
- if (cbBufferEnd + lineLen > cbBufferAlloced) {
- cbBufferAlloced += (lineLen + 1024 - lineLen % 1024);
- buffer = (char *)mir_realloc(buffer, cbBufferAlloced);
- }
-
- char *d = buffer + cbBufferEnd;
for (; *line; line++, textCharsCount++) {
if (*line == '\r' && line[1] == '\n') {
- memcpy(d, "\\par ", 5);
+ buf.Append("\\par ");
line++;
- d += 5;
}
else if (*line == '\n') {
- memcpy(d, "\\line ", 6);
- d += 6;
+ buf.Append("\\line ");
}
else if (*line == '%' && !simpleMode) {
char szTemp[200];
@@ -141,7 +115,7 @@ static int Log_AppendRTF(LOGSTREAMDATA *streamData, BOOL simpleMode, char *&buff switch (*++line) {
case '\0':
case '%':
- *d++ = '%';
+ buf.AppendChar('%');
break;
case 'c':
@@ -196,31 +170,26 @@ static int Log_AppendRTF(LOGSTREAMDATA *streamData, BOOL simpleMode, char *&buff break;
}
- if (szTemp[0]) {
- size_t iLen = mir_strlen(szTemp);
- memcpy(d, szTemp, iLen);
- d += iLen;
- }
+ if (szTemp[0])
+ buf.Append(szTemp);
}
else if (*line == '\t' && !streamData->bStripFormat) {
- memcpy(d, "\\tab ", 5);
- d += 5;
+ buf.Append("\\tab ");
}
else if ((*line == '\\' || *line == '{' || *line == '}') && !streamData->bStripFormat) {
- *d++ = '\\';
- *d++ = (char)*line;
+ buf.AppendChar('\\');
+ buf.AppendChar(*line);
}
else if (*line > 0 && *line < 128) {
- *d++ = (char)*line;
+ buf.AppendChar(*line);
}
- else d += sprintf(d, "\\u%u ?", (WORD)*line); //!!!!!!!!!!!
+ else buf.AppendFormat("\\u%u ?", (WORD)*line);
}
- cbBufferEnd = (int)(d - buffer);
return textCharsCount;
}
-static void AddEventToBuffer(char *&buffer, size_t &bufferEnd, size_t &bufferAlloced, LOGSTREAMDATA *streamData)
+static void AddEventToBuffer(CMStringA &buf, LOGSTREAMDATA *streamData)
{
wchar_t szTemp[512], szTemp2[512];
wchar_t* pszNick = NULL;
@@ -241,73 +210,73 @@ static void AddEventToBuffer(char *&buffer, size_t &bufferEnd, size_t &bufferAll switch (streamData->lin->iType) {
case GC_EVENT_MESSAGE:
if (streamData->lin->ptszText)
- Log_AppendRTF(streamData, FALSE, buffer, bufferEnd, bufferAlloced, L"%s", streamData->lin->ptszText);
+ Log_AppendRTF(streamData, false, buf, L"%s", streamData->lin->ptszText);
break;
case GC_EVENT_ACTION:
if (streamData->lin->ptszNick && streamData->lin->ptszText) {
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, L"%s ", streamData->lin->ptszNick);
- Log_AppendRTF(streamData, FALSE, buffer, bufferEnd, bufferAlloced, L"%s", streamData->lin->ptszText);
+ Log_AppendRTF(streamData, true, buf, L"%s ", streamData->lin->ptszNick);
+ Log_AppendRTF(streamData, false, buf, L"%s", streamData->lin->ptszText);
}
break;
case GC_EVENT_JOIN:
if (pszNick) {
if (!streamData->lin->bIsMe)
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, TranslateT("%s has joined"), pszNick);
+ Log_AppendRTF(streamData, true, buf, TranslateT("%s has joined"), pszNick);
else
- Log_AppendRTF(streamData, FALSE, buffer, bufferEnd, bufferAlloced, TranslateT("You have joined %s"), streamData->si->ptszName);
+ Log_AppendRTF(streamData, false, buf, TranslateT("You have joined %s"), streamData->si->ptszName);
}
break;
case GC_EVENT_PART:
if (pszNick)
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, TranslateT("%s has left"), pszNick);
+ Log_AppendRTF(streamData, true, buf, TranslateT("%s has left"), pszNick);
if (streamData->lin->ptszText)
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, L": %s", streamData->lin->ptszText);
+ Log_AppendRTF(streamData, true, buf, L": %s", streamData->lin->ptszText);
break;
case GC_EVENT_QUIT:
if (pszNick)
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, TranslateT("%s has disconnected"), pszNick);
+ Log_AppendRTF(streamData, true, buf, TranslateT("%s has disconnected"), pszNick);
if (streamData->lin->ptszText)
- Log_AppendRTF(streamData, FALSE, buffer, bufferEnd, bufferAlloced, L": %s", streamData->lin->ptszText);
+ Log_AppendRTF(streamData, false, buf, L": %s", streamData->lin->ptszText);
break;
case GC_EVENT_NICK:
if (pszNick && streamData->lin->ptszText) {
if (!streamData->lin->bIsMe)
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, TranslateT("%s is now known as %s"), pszNick, streamData->lin->ptszText);
+ Log_AppendRTF(streamData, true, buf, TranslateT("%s is now known as %s"), pszNick, streamData->lin->ptszText);
else
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, TranslateT("You are now known as %s"), streamData->lin->ptszText);
+ Log_AppendRTF(streamData, true, buf, TranslateT("You are now known as %s"), streamData->lin->ptszText);
}
break;
case GC_EVENT_KICK:
if (streamData->lin->ptszNick && streamData->lin->ptszStatus)
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, TranslateT("%s kicked %s"), streamData->lin->ptszStatus, streamData->lin->ptszNick);
+ Log_AppendRTF(streamData, true, buf, TranslateT("%s kicked %s"), streamData->lin->ptszStatus, streamData->lin->ptszNick);
if (streamData->lin->ptszText)
- Log_AppendRTF(streamData, FALSE, buffer, bufferEnd, bufferAlloced, L": %s", streamData->lin->ptszText);
+ Log_AppendRTF(streamData, false, buf, L": %s", streamData->lin->ptszText);
break;
case GC_EVENT_NOTICE:
if (pszNick && streamData->lin->ptszText) {
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, TranslateT("Notice from %s: "), pszNick);
- Log_AppendRTF(streamData, FALSE, buffer, bufferEnd, bufferAlloced, L"%s", streamData->lin->ptszText);
+ Log_AppendRTF(streamData, true, buf, TranslateT("Notice from %s: "), pszNick);
+ Log_AppendRTF(streamData, false, buf, L"%s", streamData->lin->ptszText);
}
break;
case GC_EVENT_TOPIC:
if (streamData->lin->ptszText)
- Log_AppendRTF(streamData, FALSE, buffer, bufferEnd, bufferAlloced, TranslateT("The topic is '%s%s'"), streamData->lin->ptszText, L"%r");
+ Log_AppendRTF(streamData, false, buf, TranslateT("The topic is '%s%s'"), streamData->lin->ptszText, L"%r");
if (streamData->lin->ptszNick)
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced,
+ Log_AppendRTF(streamData, true, buf,
streamData->lin->ptszUserInfo ? TranslateT(" (set by %s on %s)") : TranslateT(" (set by %s)"),
streamData->lin->ptszNick, streamData->lin->ptszUserInfo);
break;
case GC_EVENT_INFORMATION:
if (streamData->lin->ptszText)
- Log_AppendRTF(streamData, FALSE, buffer, bufferEnd, bufferAlloced, (streamData->lin->bIsMe) ? L"--> %s" : L"%s", streamData->lin->ptszText);
+ Log_AppendRTF(streamData, false, buf, (streamData->lin->bIsMe) ? L"--> %s" : L"%s", streamData->lin->ptszText);
break;
case GC_EVENT_ADDSTATUS:
if (streamData->lin->ptszNick && streamData->lin->ptszText && streamData->lin->ptszStatus)
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, TranslateT("%s enables '%s' status for %s"), streamData->lin->ptszText, streamData->lin->ptszStatus, streamData->lin->ptszNick);
+ Log_AppendRTF(streamData, true, buf, TranslateT("%s enables '%s' status for %s"), streamData->lin->ptszText, streamData->lin->ptszStatus, streamData->lin->ptszNick);
break;
case GC_EVENT_REMOVESTATUS:
if (streamData->lin->ptszNick && streamData->lin->ptszText && streamData->lin->ptszStatus)
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, TranslateT("%s disables '%s' status for %s"), streamData->lin->ptszText, streamData->lin->ptszStatus, streamData->lin->ptszNick);
+ Log_AppendRTF(streamData, TRUE, buf, TranslateT("%s disables '%s' status for %s"), streamData->lin->ptszText, streamData->lin->ptszStatus, streamData->lin->ptszNick);
break;
}
}
@@ -325,14 +294,12 @@ char* Log_CreateRTF(LOGSTREAMDATA *streamData) MODULEINFO *mi = chatApi.MM_FindModule(streamData->si->pszModule);
// guesstimate amount of memory for the RTF
- size_t bufferEnd = 0, bufferAlloced = streamData->bRedraw ? 1024 * (streamData->si->iEventCount + 2) : 2048;
- char *buffer = (char *)mir_alloc(bufferAlloced);
- buffer[0] = '\0';
+ CMStringA buf;
// ### RTF HEADER
char *header = mi->pszHeader;
if (header)
- Log_Append(buffer, bufferEnd, bufferAlloced, header);
+ buf.Append(header);
// ### RTF BODY (one iteration per event that should be streamed in)
for (LOGINFO *lin = streamData->lin; lin; lin = lin->prev) {
@@ -343,40 +310,33 @@ char* Log_CreateRTF(LOGSTREAMDATA *streamData) // create new line, and set font and color
if (lin->next != NULL)
- Log_Append(buffer, bufferEnd, bufferAlloced, "\\par ");
- Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", Log_SetStyle(0));
+ buf.Append("\\par ");
+ buf.AppendFormat("%s ", Log_SetStyle(0));
// Insert icon
if ((lin->iType & g_Settings->dwIconFlags) || lin->bIsHighlighted && (g_Settings->dwIconFlags & GC_EVENT_HIGHLIGHT)) {
int iIndex = (lin->bIsHighlighted && g_Settings->dwIconFlags & GC_EVENT_HIGHLIGHT) ? ICON_HIGHLIGHT : EventToIcon(lin);
- Log_Append(buffer, bufferEnd, bufferAlloced, "\\f0\\fs14");
- while (bufferAlloced - bufferEnd < logIconBmpSize[0])
- bufferAlloced += 4096;
- buffer = (char *)mir_realloc(buffer, bufferAlloced);
- memcpy(buffer + bufferEnd, pLogIconBmpBits[iIndex], logIconBmpSize[iIndex]);
- bufferEnd += logIconBmpSize[iIndex];
+ buf.Append("\\f0\\fs14");
+ buf.Append(pLogIconBmpBits[iIndex]);
}
if (g_Settings->bTimeStampEventColour) {
LOGFONT &lf = chatApi.aFonts[0].lf;
// colored timestamps
- static char szStyle[256];
if (lin->ptszNick && lin->iType == GC_EVENT_MESSAGE) {
int iii = lin->bIsHighlighted ? 16 : (lin->bIsMe ? 2 : 1);
- mir_snprintf(szStyle, "\\f0\\cf%u\\ul0\\highlight0\\b%d\\i%d\\fs%u", iii + 1, lf.lfWeight >= FW_BOLD ? 1 : 0, lf.lfItalic, 2 * abs(lf.lfHeight) * 74 / chatApi.logPixelSY);
- Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", szStyle);
+ buf.AppendFormat("\\f0\\cf%u\\ul0\\highlight0\\b%d\\i%d\\fs%u", iii + 1, lf.lfWeight >= FW_BOLD ? 1 : 0, lf.lfItalic, 2 * abs(lf.lfHeight) * 74 / chatApi.logPixelSY);
}
else {
int iii = lin->bIsHighlighted ? 16 : EventToIndex(lin);
- mir_snprintf(szStyle, "\\f0\\cf%u\\ul0\\highlight0\\b%d\\i%d\\fs%u", iii + 1, lf.lfWeight >= FW_BOLD ? 1 : 0, lf.lfItalic, 2 * abs(lf.lfHeight) * 74 / chatApi.logPixelSY);
- Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", szStyle);
+ buf.AppendFormat("\\f0\\cf%u\\ul0\\highlight0\\b%d\\i%d\\fs%u", iii + 1, lf.lfWeight >= FW_BOLD ? 1 : 0, lf.lfItalic, 2 * abs(lf.lfHeight) * 74 / chatApi.logPixelSY);
}
}
- else Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", Log_SetStyle(0));
+ else buf.AppendFormat("%s ", Log_SetStyle(0));
if (g_Settings->dwIconFlags)
- Log_Append(buffer, bufferEnd, bufferAlloced, "\\tab ");
+ buf.Append("\\tab ");
//insert timestamp
if (g_Settings->bShowTime) {
@@ -386,47 +346,43 @@ char* Log_CreateRTF(LOGSTREAMDATA *streamData) mir_wstrncpy(szOldTimeStamp, MakeTimeStamp(g_Settings->pszTimeStamp, streamData->si->LastTime), 30);
if (!g_Settings->bShowTimeIfChanged || streamData->si->LastTime == 0 || mir_wstrcmp(szTimeStamp, szOldTimeStamp)) {
streamData->si->LastTime = lin->time;
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, L"%s", szTimeStamp);
+ Log_AppendRTF(streamData, TRUE, buf, L"%s", szTimeStamp);
}
- Log_Append(buffer, bufferEnd, bufferAlloced, "\\tab ");
+ buf.Append("\\tab ");
}
// Insert the nick
if (lin->ptszNick && lin->iType == GC_EVENT_MESSAGE) {
wchar_t pszTemp[300], *p1;
- Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", Log_SetStyle(lin->bIsMe ? 2 : 1));
+ buf.AppendFormat("%s ", Log_SetStyle(lin->bIsMe ? 2 : 1));
mir_wstrncpy(pszTemp, lin->bIsMe ? g_Settings->pszOutgoingNick : g_Settings->pszIncomingNick, 299);
p1 = wcsstr(pszTemp, L"%n");
if (p1)
p1[1] = 's';
- Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, pszTemp, lin->ptszNick);
- Log_Append(buffer, bufferEnd, bufferAlloced, " ");
+ Log_AppendRTF(streamData, TRUE, buf, pszTemp, lin->ptszNick);
+ buf.AppendChar(' ');
}
// Insert the message
- Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", Log_SetStyle(lin->bIsHighlighted ? 16 : EventToIndex(lin)));
+ buf.AppendFormat("%s ", Log_SetStyle(lin->bIsHighlighted ? 16 : EventToIndex(lin)));
streamData->lin = lin;
- AddEventToBuffer(buffer, bufferEnd, bufferAlloced, streamData);
+ AddEventToBuffer(buf, streamData);
}
// ### RTF END
if (streamData->bRedraw)
- Log_Append(buffer, bufferEnd, bufferAlloced, "\\par}");
+ buf.Append("\\par}");
else
- Log_Append(buffer, bufferEnd, bufferAlloced, "}");
- return buffer;
+ buf.Append("}");
+ return buf.Detach();
}
char* Log_CreateRtfHeader(MODULEINFO *mi)
{
- int i;
-
// guesstimate amount of memory for the RTF header
- size_t bufferEnd = 0, bufferAlloced = 4096;
- char *buffer = (char *)mir_realloc(mi->pszHeader, bufferAlloced);
- buffer[0] = '\0';
+ CMStringA buf;
// get the number of pixels per logical inch
HDC hdc = GetDC(NULL);
@@ -437,38 +393,38 @@ char* Log_CreateRtfHeader(MODULEINFO *mi) // ### RTF HEADER
// font table
- Log_Append(buffer, bufferEnd, bufferAlloced, "{\\rtf1\\ansi\\deff0{\\fonttbl");
- for (i = 0; i < OPTIONS_FONTCOUNT; i++)
- Log_Append(buffer, bufferEnd, bufferAlloced, "{\\f%u\\fnil\\fcharset%u%S;}", i, chatApi.aFonts[i].lf.lfCharSet, chatApi.aFonts[i].lf.lfFaceName);
+ buf.Append("{\\rtf1\\ansi\\deff0{\\fonttbl");
+ for (int i = 0; i < OPTIONS_FONTCOUNT; i++)
+ buf.AppendFormat("{\\f%u\\fnil\\fcharset%u%S;}", i, chatApi.aFonts[i].lf.lfCharSet, chatApi.aFonts[i].lf.lfFaceName);
// colour table
- Log_Append(buffer, bufferEnd, bufferAlloced, "}{\\colortbl ;");
+ buf.Append("}{\\colortbl ;");
- for (i = 0; i < OPTIONS_FONTCOUNT; i++)
- Log_Append(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(chatApi.aFonts[i].color), GetGValue(chatApi.aFonts[i].color), GetBValue(chatApi.aFonts[i].color));
+ for (int i = 0; i < OPTIONS_FONTCOUNT; i++)
+ buf.AppendFormat("\\red%u\\green%u\\blue%u;", GetRValue(chatApi.aFonts[i].color), GetGValue(chatApi.aFonts[i].color), GetBValue(chatApi.aFonts[i].color));
- for (i = 0; i < mi->nColorCount; i++)
- Log_Append(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(mi->crColors[i]), GetGValue(mi->crColors[i]), GetBValue(mi->crColors[i]));
+ for (int i = 0; i < mi->nColorCount; i++)
+ buf.AppendFormat("\\red%u\\green%u\\blue%u;", GetRValue(mi->crColors[i]), GetGValue(mi->crColors[i]), GetBValue(mi->crColors[i]));
// new paragraph
- Log_Append(buffer, bufferEnd, bufferAlloced, "}\\pard");
+ buf.Append("}\\pard");
// set tabs and indents
int iIndent = 0;
if (g_Settings->dwIconFlags) {
iIndent += (14 * 1440) / chatApi.logPixelSX;
- Log_Append(buffer, bufferEnd, bufferAlloced, "\\tx%u", iIndent);
+ buf.Append("\\tx%u", iIndent);
}
if (g_Settings->bShowTime) {
int iSize = (g_Settings->LogTextIndent * 1440) / chatApi.logPixelSX;
- Log_Append(buffer, bufferEnd, bufferAlloced, "\\tx%u", iIndent + iSize);
+ buf.Append("\\tx%u", iIndent + iSize);
if (g_Settings->bLogIndentEnabled)
iIndent += iSize;
}
- Log_Append(buffer, bufferEnd, bufferAlloced, "\\fi-%u\\li%u", iIndent, iIndent);
- return buffer;
+ buf.AppendFormat("\\fi-%u\\li%u", iIndent, iIndent);
+ return buf.Detach();
}
#define RTFPICTHEADERMAXSIZE 78
@@ -510,8 +466,6 @@ void LoadMsgLogBitmaps(void) bin2hex(&bih, sizeof(bih), szDest); szDest += sizeof(bih) * 2;
bin2hex(pBmpBits, widthBytes * bih.biHeight, szDest); szDest += widthBytes * bih.biHeight * 2;
mir_strcpy(szDest, "}");
-
- logIconBmpSize[i] = size_t(szDest - pLogIconBmpBits[i]) + 1;
}
mir_free(pBmpBits);
DeleteDC(hdcMem);
diff --git a/src/mir_app/src/chat_manager.cpp b/src/mir_app/src/chat_manager.cpp index f031dd24b3..83044f9d79 100644 --- a/src/mir_app/src/chat_manager.cpp +++ b/src/mir_app/src/chat_manager.cpp @@ -1323,7 +1323,6 @@ INT_PTR SvcGetChatManager(WPARAM wParam, LPARAM lParam) chatApi.ColorChooser = ColorChooser;
chatApi.pLogIconBmpBits = pLogIconBmpBits;
- chatApi.logIconBmpSize = logIconBmpSize;
RegisterFonts();
OptionsInit();
|