From 2eaa3458b74ffdae9c91b4eb6fe84f8145af3fa1 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 4 Dec 2014 13:40:41 +0000 Subject: - bin2hex() instead of manual loops; - change of icon packets git-svn-id: http://svn.miranda-ng.org/main/trunk@11239 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Scriver/src/msglog.cpp | 36 ++++++------ plugins/TabSRMM/src/chat/log.cpp | 120 +++++++++++++++++++-------------------- plugins/TabSRMM/src/msglog.cpp | 61 ++++++++------------ 3 files changed, 99 insertions(+), 118 deletions(-) (limited to 'plugins') diff --git a/plugins/Scriver/src/msglog.cpp b/plugins/Scriver/src/msglog.cpp index f29db42b95..9e1c79da84 100644 --- a/plugins/Scriver/src/msglog.cpp +++ b/plugins/Scriver/src/msglog.cpp @@ -29,8 +29,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern int RTL_Detect(WCHAR *pszwText); static int logPixelSY; -static PBYTE pLogIconBmpBits[3]; -static int logIconBmpSize[SIZEOF(pLogIconBmpBits)]; +static char* pLogIconBmpBits[3]; +static size_t logIconBmpSize[SIZEOF(pLogIconBmpBits)]; static HIMAGELIST g_hImageList; #define STREAMSTAGE_HEADER 0 @@ -327,7 +327,7 @@ static int AppendUnicodeToBuffer(char *&buffer, size_t &cbBufferEnd, size_t &cbB } // mir_free() the return value -static char *CreateRTFHeader(SrmmWindowData *dat, struct GlobalMessageData *gdat) +static char* CreateRTFHeader(SrmmWindowData *dat, GlobalMessageData *gdat) { HDC hdc = GetDC(NULL); logPixelSY = GetDeviceCaps(hdc, LOGPIXELSY); @@ -538,7 +538,7 @@ static void AppendWithCustomLinks(EventData *evt, int style, char *&buffer, size } //mir_free() the return value -static char* CreateRTFFromEvent(SrmmWindowData *dat, EventData *evt, struct GlobalMessageData *gdat, struct LogStreamData *streamData) +static char* CreateRTFFromEvent(SrmmWindowData *dat, EventData *evt, GlobalMessageData *gdat, LogStreamData *streamData) { int style, showColon = 0; int isGroupBreak = TRUE; @@ -738,7 +738,7 @@ static char* CreateRTFFromEvent(SrmmWindowData *dat, EventData *evt, struct Glob static DWORD CALLBACK LogStreamInEvents(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb) { - struct LogStreamData *dat = (struct LogStreamData *)dwCookie; + LogStreamData *dat = (LogStreamData*)dwCookie; if (dat->buffer == NULL) { dat->bufferOffset = 0; @@ -796,10 +796,10 @@ static DWORD CALLBACK LogStreamInEvents(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG return 0; } -void StreamInTestEvents(HWND hEditWnd, struct GlobalMessageData *gdat) +void StreamInTestEvents(HWND hEditWnd, GlobalMessageData *gdat) { SrmmWindowData dat = { 0 }; - struct LogStreamData streamData = { 0 }; + LogStreamData streamData = { 0 }; streamData.isFirst = TRUE; streamData.events = GetTestEvents(); streamData.dlgDat = &dat; @@ -816,7 +816,7 @@ void StreamInEvents(HWND hwndDlg, HANDLE hDbEventFirst, int count, int fAppend) { FINDTEXTEXA fi; EDITSTREAM stream = { 0 }; - struct LogStreamData streamData = { 0 }; + LogStreamData streamData = { 0 }; SrmmWindowData *dat = (SrmmWindowData *) GetWindowLongPtr(hwndDlg, GWLP_USERDATA); CHARRANGE oldSel, sel; @@ -915,6 +915,7 @@ void StreamInEvents(HWND hwndDlg, HANDLE hDbEventFirst, int count, int fAppend) } #define RTFPICTHEADERMAXSIZE 78 + void LoadMsgLogIcons(void) { HICON hIcon = NULL; @@ -958,9 +959,10 @@ void LoadMsgLogIcons(void) hBrush = hBkgBrush; break; } - pLogIconBmpBits[i] = (PBYTE)mir_alloc(RTFPICTHEADERMAXSIZE + (bih.biSize + widthBytes * bih.biHeight) * 2); - //I can't seem to get binary mode working. No matter. - int rtfHeaderSize = sprintf((char*)pLogIconBmpBits[i], "{\\pict\\dibitmap0\\wbmbitspixel%u\\wbmplanes1\\wbmwidthbytes%u\\picw%u\\pich%u ", bih.biBitCount, widthBytes, (UINT)bih.biWidth, (UINT)bih.biHeight); //!!!!!!!!!!! + + 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); //!!!!!!!!!!! + HBITMAP hoBmp = (HBITMAP)SelectObject(hdcMem, hBmp); FillRect(hdcMem, &rc, hBrush); DrawIconEx(hdcMem, 0, 0, hIcon, bih.biWidth, bih.biHeight, 0, NULL, DI_NORMAL); @@ -968,14 +970,12 @@ void LoadMsgLogIcons(void) GetDIBits(hdc, hBmp, 0, bih.biHeight, pBmpBits, (BITMAPINFO *)& bih, DIB_RGB_COLORS); DestroyIcon(hIcon); - int n; - for (n = 0; n < sizeof(BITMAPINFOHEADER); n++) - sprintf((char*)pLogIconBmpBits[i] + rtfHeaderSize + n * 2, "%02X", ((PBYTE)& bih)[n]); //!!!!!!!!!!!!!! - for (n = 0; n < widthBytes * bih.biHeight; n += 4) - sprintf((char*)pLogIconBmpBits[i] + rtfHeaderSize + (bih.biSize + n) * 2, "%02X%02X%02X%02X", pBmpBits[n], pBmpBits[n + 1], pBmpBits[n + 2], pBmpBits[n + 3]); //!!!!!!!!!!!!!!!! + char *szDest = pLogIconBmpBits[i] + rtfHeaderSize; + bin2hex(&bih, sizeof(bih), szDest); szDest += sizeof(bih) * 2; + bin2hex(pBmpBits, widthBytes * bih.biHeight, szDest); szDest += widthBytes * bih.biHeight * 2; + strcpy(szDest, "}"); - logIconBmpSize[i] = rtfHeaderSize + (bih.biSize + widthBytes * bih.biHeight) * 2 + 1; - pLogIconBmpBits[i][logIconBmpSize[i] - 1] = '}'; + 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 233cdedbb7..b179170d7c 100644 --- a/plugins/TabSRMM/src/chat/log.cpp +++ b/plugins/TabSRMM/src/chat/log.cpp @@ -264,7 +264,7 @@ static void LogEventIEView(LOGSTREAMDATA *streamData, TCHAR *ptszNick) event.count = 1; memset(&ied, 0, sizeof(ied)); - AddEventToBufferIEView(&buffer, &bufferEnd, &bufferAlloced, streamData, ptszNick); + AddEventToBufferIEView(buffer, bufferEnd, bufferAlloced, streamData, ptszNick); ied.ptszNick = ptszNick; ied.ptszText = buffer; ied.time = streamData->lin->time; @@ -474,30 +474,29 @@ static TCHAR * _tcsnrplc(TCHAR *src, size_t n, const TCHAR *ptrn, const TCHAR *r return src; } -static void Log_Append(char **buffer, int *cbBufferEnd, int *cbBufferAlloced, const char *fmt, ...) +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); + charsDone = mir_vsnprintf(buffer + cbBufferEnd, cbBufferAlloced - cbBufferEnd, fmt, va); if (charsDone >= 0) break; - *cbBufferAlloced += 4096; - *buffer = (char *) mir_realloc(*buffer, *cbBufferAlloced); + cbBufferAlloced += 4096; + buffer = (char*)mir_realloc(buffer, cbBufferAlloced); } va_end(va); - *cbBufferEnd += charsDone; + cbBufferEnd += charsDone; } -static int Log_AppendRTF(LOGSTREAMDATA* streamData, BOOL simpleMode, char **buffer, int *cbBufferEnd, int *cbBufferAlloced, const TCHAR *fmt, ...) +static int Log_AppendRTF(LOGSTREAMDATA *streamData, BOOL simpleMode, char *&buffer, size_t &cbBufferEnd, size_t &cbBufferAlloced, const TCHAR *fmt, ...) { - va_list va; int textCharsCount = 0; - char *d; TCHAR *line = (TCHAR*)_alloca(8001 * sizeof(TCHAR)); + va_list va; va_start(va, fmt); int lineLen = mir_vsntprintf(line, 8000, fmt, va); if (lineLen < 0) @@ -506,14 +505,13 @@ static int Log_AppendRTF(LOGSTREAMDATA* streamData, BOOL simpleMode, char **buff va_end(va); lineLen = lineLen * 20 + 8; - if (*cbBufferEnd + lineLen > *cbBufferAlloced) { - cbBufferAlloced[0] += (lineLen + 1024 - lineLen % 1024); - if ((d = (char *) mir_realloc(*buffer, *cbBufferAlloced)) == 0) + if (cbBufferEnd + lineLen > cbBufferAlloced) { + cbBufferAlloced += (lineLen + 1024 - lineLen % 1024); + if ((buffer = (char*)mir_realloc(buffer, cbBufferAlloced)) == 0) return 0; - *buffer = d; } - d = *buffer + *cbBufferEnd; + char *d = buffer + cbBufferEnd; for (; *line; line++, textCharsCount++) { if (*line == '\r' && line[1] == '\n') { @@ -599,11 +597,11 @@ static int Log_AppendRTF(LOGSTREAMDATA* streamData, BOOL simpleMode, char **buff else d += sprintf(d, "\\u%u ?", (WORD) * line); //!!!!!!!!! } - *cbBufferEnd = (int)(d - *buffer); + cbBufferEnd = (int)(d - buffer); return textCharsCount; } -static void AddEventToBuffer(char **buffer, int *bufferEnd, int *bufferAlloced, LOGSTREAMDATA *streamData) +static void AddEventToBuffer(char *&buffer, size_t &bufferEnd, size_t &bufferAlloced, LOGSTREAMDATA *streamData) { TCHAR szTemp[512], szTemp2[512]; TCHAR* pszNick = NULL; @@ -718,15 +716,13 @@ static void AddEventToBuffer(char **buffer, int *bufferEnd, int *bufferAlloced, char* Log_CreateRtfHeader(MODULEINFO *mi) { - int bufferAlloced, bufferEnd, i = 0; + int i = 0; // guesstimate amount of memory for the RTF header - bufferEnd = 0; - bufferAlloced = 4096; + size_t bufferEnd = 0, bufferAlloced = 4096; char *buffer = (char *)mir_realloc(mi->pszHeader, bufferAlloced); buffer[0] = '\0'; - // get the number of pixels per logical inch if (pci->logPixelSY == 0) { HDC hdc = GetDC(NULL); @@ -738,24 +734,24 @@ char* Log_CreateRtfHeader(MODULEINFO *mi) // ### RTF HEADER // font table - Log_Append(&buffer, &bufferEnd, &bufferAlloced, "{\\rtf1\\ansi\\deff0{\\fonttbl"); + 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, pci->aFonts[i].lf.lfCharSet, pci->aFonts[i].lf.lfFaceName); + Log_Append(buffer, bufferEnd, bufferAlloced, "{\\f%u\\fnil\\fcharset%u%S;}", i, pci->aFonts[i].lf.lfCharSet, pci->aFonts[i].lf.lfFaceName); // colour table - Log_Append(&buffer, &bufferEnd, &bufferAlloced, "}{\\colortbl ;"); + Log_Append(buffer, bufferEnd, bufferAlloced, "}{\\colortbl ;"); for (i = 0; i < OPTIONS_FONTCOUNT; i++) - Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(pci->aFonts[i].color), GetGValue(pci->aFonts[i].color), GetBValue(pci->aFonts[i].color)); + Log_Append(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(pci->aFonts[i].color), GetGValue(pci->aFonts[i].color), GetBValue(pci->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])); + Log_Append(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(mi->crColors[i]), GetGValue(mi->crColors[i]), GetBValue(mi->crColors[i])); for (i = 0; i < STATUSICONCOUNT; i++) - Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(g_Settings.nickColors[i]), GetGValue(g_Settings.nickColors[i]), GetBValue(g_Settings.nickColors[i])); + Log_Append(buffer, bufferEnd, bufferAlloced, "\\red%u\\green%u\\blue%u;", GetRValue(g_Settings.nickColors[i]), GetGValue(g_Settings.nickColors[i]), GetBValue(g_Settings.nickColors[i])); // new paragraph - Log_Append(&buffer, &bufferEnd, &bufferAlloced, "}\\pard\\sl%d", 1000); + Log_Append(buffer, bufferEnd, bufferAlloced, "}\\pard\\sl%d", 1000); // set tabs and indents int iIndent = 0; @@ -771,34 +767,33 @@ char* Log_CreateRtfHeader(MODULEINFO *mi) int iText = GetTextPixelSize(szString, hFont, true) + 3; DeleteObject(hFont); iIndent += (iText * 1440) / pci->logPixelSX; - Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\tx%u", iIndent); + Log_Append(buffer, bufferEnd, bufferAlloced, "\\tx%u", iIndent); } else if (g_Settings.dwIconFlags) { iIndent += ((g_Settings.bScaleIcons ? 14 : 20) * 1440) / pci->logPixelSX; - Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\tx%u", iIndent); + Log_Append(buffer, bufferEnd, bufferAlloced, "\\tx%u", iIndent); } if (g_Settings.bShowTime) { int iSize = (g_Settings.LogTextIndent * 1440) / pci->logPixelSX; - Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\tx%u", iIndent + iSize); + Log_Append(buffer, bufferEnd, bufferAlloced, "\\tx%u", iIndent + iSize); if (g_Settings.bLogIndentEnabled) iIndent += iSize; } - Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\fi-%u\\li%u", iIndent, iIndent); + Log_Append(buffer, bufferEnd, bufferAlloced, "\\fi-%u\\li%u", iIndent, iIndent); return buffer; } static char* Log_CreateRTF(LOGSTREAMDATA *streamData) { - char *buffer, *header; - int bufferAlloced, bufferEnd, me = 0; - LOGINFO * lin = streamData->lin; + int me = 0; + LOGINFO *lin = streamData->lin; MODULEINFO *mi = pci->MM_FindModule(streamData->si->pszModule); // guesstimate amount of memory for the RTF - bufferEnd = 0; - bufferAlloced = streamData->bRedraw ? 2048 * (streamData->si->iEventCount + 2) : 2048; - buffer = (char *) mir_alloc(bufferAlloced); + size_t bufferEnd = 0; + size_t bufferAlloced = streamData->bRedraw ? 2048 * (streamData->si->iEventCount + 2) : 2048; + char *buffer = (char*)mir_alloc(bufferAlloced); buffer[0] = '\0'; // ### RTF HEADER @@ -806,19 +801,18 @@ static char* Log_CreateRTF(LOGSTREAMDATA *streamData) if (0 == mi->pszHeader) mi->pszHeader = Log_CreateRtfHeader(mi); - header = mi->pszHeader; + char *header = mi->pszHeader; streamData->crCount = mi->nColorCount; if (header) - Log_Append(&buffer, &bufferEnd, &bufferAlloced, header); - + Log_Append(buffer, bufferEnd, bufferAlloced, header); // ### RTF BODY (one iteration per event that should be streamed in) while (lin) { // filter if ((streamData->si->iType != GCW_CHATROOM && streamData->si->iType != GCW_PRIVMESS) || !streamData->si->bFilterEnabled || (streamData->si->iLogFilterFlags & lin->iType) != 0) { if (lin->next != NULL) - Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\par "); + Log_Append(buffer, bufferEnd, bufferAlloced, "\\par "); if (streamData->dat->dwFlags & MWF_DIVIDERWANTED || lin->dwFlags & MWF_DIVIDERWANTED) { static char szStyle_div[128] = "\0"; @@ -827,19 +821,19 @@ static char* Log_CreateRTF(LOGSTREAMDATA *streamData) lin->dwFlags |= MWF_DIVIDERWANTED; if (lin->prev || !streamData->bRedraw) - Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\qc\\sl-1\\highlight%d %s ---------------------------------------------------------------------------------------\\par ", 18, szStyle_div); + Log_Append(buffer, bufferEnd, bufferAlloced, "\\qc\\sl-1\\highlight%d %s ---------------------------------------------------------------------------------------\\par ", 18, szStyle_div); streamData->dat->dwFlags &= ~MWF_DIVIDERWANTED; } // create new line, and set font and color - Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\ql\\sl0%s ", pci->Log_SetStyle(0)); - Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\v~-+%d+-~\\v0 ", lin); + Log_Append(buffer, bufferEnd, bufferAlloced, "\\ql\\sl0%s ", pci->Log_SetStyle(0)); + Log_Append(buffer, bufferEnd, bufferAlloced, "\\v~-+%d+-~\\v0 ", lin); // Insert icon if (g_Settings.bLogSymbols) // use symbols - Log_Append(&buffer, &bufferEnd, &bufferAlloced, "%s %c", pci->Log_SetStyle(17), EventToSymbol(lin)); + Log_Append(buffer, bufferEnd, bufferAlloced, "%s %c", pci->Log_SetStyle(17), EventToSymbol(lin)); else if (g_Settings.dwIconFlags) { int iIndex = lin->bIsHighlighted ? ICON_HIGHLIGHT : EventToIcon(lin); - Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\f0\\fs14"); + Log_Append(buffer, bufferEnd, bufferAlloced, "\\f0\\fs14"); while (bufferAlloced - bufferEnd < (pci->logIconBmpSize[0] + 20)) bufferAlloced += 4096; buffer = (char *) mir_realloc(buffer, bufferAlloced); @@ -856,20 +850,20 @@ static char* Log_CreateRTF(LOGSTREAMDATA *streamData) iii = lin->bIsHighlighted ? 16 : (lin->bIsMe ? 2 : 1); mir_snprintf(szStyle, SIZEOF(szStyle), "\\f0\\cf%u\\ul0\\highlight0\\b%d\\i%d\\ul%d\\fs%u", iii + 1, F.lfWeight >= FW_BOLD ? 1 : 0,F.lfItalic,F.lfUnderline, 2 * abs(F.lfHeight) * 74 / pci->logPixelSY); - Log_Append(&buffer, &bufferEnd, &bufferAlloced, "%s ", szStyle); + Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", szStyle); } else { iii = lin->bIsHighlighted ? 16 : EventToIndex(lin); mir_snprintf(szStyle, SIZEOF(szStyle), "\\f0\\cf%u\\ul0\\highlight0\\b%d\\i%d\\ul%d\\fs%u", iii + 1, F.lfWeight >= FW_BOLD ? 1 : 0, F.lfItalic,F.lfUnderline ,2 * abs(F.lfHeight) * 74 / pci->logPixelSY); - Log_Append(&buffer, &bufferEnd, &bufferAlloced, "%s ", szStyle); + Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", szStyle); } } - else Log_Append(&buffer, &bufferEnd, &bufferAlloced, "%s ", pci->Log_SetStyle(0)); + else Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", pci->Log_SetStyle(0)); // insert a TAB if necessary to put the timestamp in the right position if (g_Settings.dwIconFlags) - Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\tab "); + Log_Append(buffer, bufferEnd, bufferAlloced, "\\tab "); //insert timestamp if (g_Settings.bShowTime) { @@ -879,9 +873,9 @@ static char* Log_CreateRTF(LOGSTREAMDATA *streamData) _tcsncpy_s(szOldTimeStamp, pci->MakeTimeStamp(g_Settings.pszTimeStamp, streamData->si->LastTime), _TRUNCATE); if (!g_Settings.bShowTimeIfChanged || streamData->si->LastTime == 0 || mir_tstrcmp(szTimeStamp, szOldTimeStamp)) { streamData->si->LastTime = lin->time; - Log_AppendRTF(streamData, TRUE, &buffer, &bufferEnd, &bufferAlloced, _T("%s"), szTimeStamp); + Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, _T("%s"), szTimeStamp); } - Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\tab "); + Log_Append(buffer, bufferEnd, bufferAlloced, "\\tab "); } // Insert the nick @@ -893,10 +887,10 @@ static char* Log_CreateRTF(LOGSTREAMDATA *streamData) if (g_Settings.bLogClassicIndicators || g_Settings.bColorizeNicksInLog) pszIndicator[0] = GetIndicator(streamData->si, lin->ptszNick, &crNickIndex); - Log_Append(&buffer, &bufferEnd, &bufferAlloced, "%s ", pci->Log_SetStyle(lin->bIsMe ? 2 : 1)); + Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", pci->Log_SetStyle(lin->bIsMe ? 2 : 1)); if (g_Settings.bLogClassicIndicators) - Log_Append(&buffer, &bufferEnd, &bufferAlloced, "%s", pszIndicator); + Log_Append(buffer, bufferEnd, bufferAlloced, "%s", pszIndicator); mir_tstrncpy(pszTemp, lin->bIsMe ? g_Settings.pszOutgoingNick : g_Settings.pszIncomingNick, SIZEOF(pszTemp)); p1 = _tcsstr(pszTemp, _T("%n")); @@ -910,26 +904,26 @@ static char* Log_CreateRTF(LOGSTREAMDATA *streamData) } if (g_Settings.bColorizeNicksInLog && pszIndicator[0]) - Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\cf%u ", OPTIONS_FONTCOUNT + streamData->crCount + crNickIndex); + Log_Append(buffer, bufferEnd, bufferAlloced, "\\cf%u ", OPTIONS_FONTCOUNT + streamData->crCount + crNickIndex); } - Log_AppendRTF(streamData, TRUE, &buffer, &bufferEnd, &bufferAlloced, pszTemp, lin->ptszNick); - Log_Append(&buffer, &bufferEnd, &bufferAlloced, " "); + Log_AppendRTF(streamData, TRUE, buffer, bufferEnd, bufferAlloced, pszTemp, lin->ptszNick); + Log_Append(buffer, bufferEnd, bufferAlloced, " "); } // Insert the message - Log_Append(&buffer, &bufferEnd, &bufferAlloced, "%s ", pci->Log_SetStyle(lin->bIsHighlighted ? 16 : EventToIndex(lin))); + Log_Append(buffer, bufferEnd, bufferAlloced, "%s ", pci->Log_SetStyle(lin->bIsHighlighted ? 16 : EventToIndex(lin))); streamData->lin = lin; - AddEventToBuffer(&buffer, &bufferEnd, &bufferAlloced, streamData); + AddEventToBuffer(buffer, bufferEnd, bufferAlloced, streamData); } lin = lin->prev; } // ### RTF END if (streamData->bRedraw) - Log_Append(&buffer, &bufferEnd, &bufferAlloced, "\\par}"); + Log_Append(buffer, bufferEnd, bufferAlloced, "\\par}"); else - Log_Append(&buffer, &bufferEnd, &bufferAlloced, "}"); + Log_Append(buffer, bufferEnd, bufferAlloced, "}"); return buffer; } @@ -1088,9 +1082,9 @@ void Log_StreamInEvent(HWND hwndDlg, LOGINFO* lin, SESSION_INFO *si, bool bRedr // this uses hidden marks in the rich text to find the events which should be deleted if (si->bTrimmed) { TCHAR szPattern[50]; - FINDTEXTEX fi; - mir_sntprintf(szPattern, SIZEOF(szPattern), _T("~-+%d+-~"), si->pLogEnd); + + FINDTEXTEX fi; fi.lpstrText = szPattern; fi.chrg.cpMin = 0; fi.chrg.cpMax = -1; diff --git a/plugins/TabSRMM/src/msglog.cpp b/plugins/TabSRMM/src/msglog.cpp index 35541fa20a..ad276f5bdf 100644 --- a/plugins/TabSRMM/src/msglog.cpp +++ b/plugins/TabSRMM/src/msglog.cpp @@ -137,16 +137,13 @@ void TSAPI CacheLogFonts() _tcsncpy(szYesterday, TranslateT("Yesterday"), 20); szToday[19] = szYesterday[19] = 0; - /* - * cache/create the info panel fonts - */ - - COLORREF clr; - LOGFONTA lf; - + // cache/create the info panel fonts for (int i = 0; i < IPFONTCOUNT; i++) { if (CInfoPanel::m_ipConfig.hFonts[i]) DeleteObject(CInfoPanel::m_ipConfig.hFonts[i]); + + COLORREF clr; + LOGFONTA lf; LoadLogfont(i + 100, &lf, &clr, FONTMODULE); lf.lfUnderline = 0; CInfoPanel::m_ipConfig.hFonts[i] = CreateFontIndirectA(&lf); @@ -310,9 +307,8 @@ static int AppendUnicodeToBuffer(char *&buffer, size_t &cbBufferEnd, size_t &cbB return textCharsCount; } -/* - * same as above but does "\r\n"->"\\par " and "\t"->"\\tab " too - */ +///////////////////////////////////////////////////////////////////////////////////////// +// same as above but does "\r\n"->"\\par " and "\t"->"\\tab " too static int AppendToBufferWithRTF(int mode, char **buffer, int *cbBufferEnd, int *cbBufferAlloced, const char *fmt, ...) { @@ -422,7 +418,6 @@ static int AppendToBufferWithRTF(int mode, char **buffer, int *cbBufferEnd, int static void Build_RTF_Header(char *&buffer, size_t &bufferEnd, size_t &bufferAlloced, TWindowData *dat) { int i; - char szTemp[30]; LOGFONTA *logFonts = dat->pContainer->theme.logFonts; COLORREF *fontColors = dat->pContainer->theme.fontColors; TLogTheme *theme = &dat->pContainer->theme; @@ -462,6 +457,7 @@ static void Build_RTF_Header(char *&buffer, size_t &bufferEnd, size_t &bufferAll // custom template colors... for (i = 1; i <= 5; i++) { + char szTemp[30]; mir_snprintf(szTemp, 10, "cc%d", i); colour = theme->custom_colors[i - 1]; if (colour == 0) @@ -560,7 +556,6 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, struct tm event_time; BOOL isBold = FALSE, isItalic = FALSE, isUnderline = FALSE; DWORD dwFormattingParams = MAKELONG(PluginConfig.m_FormatWholeWordsOnly, 0); - char *rtfMessage = NULL; size_t bufferEnd = 0, bufferAlloced = 1024; char *buffer = (char *)mir_alloc(bufferAlloced); buffer[0] = '\0'; @@ -588,17 +583,15 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, dat->cache->updateStats(TSessionStats::SET_LAST_RCV, mir_strlen((char *)dbei.pBlob)); TCHAR *formatted = NULL; - if (rtfMessage == NULL) { - TCHAR *msg = DbGetEventTextT(&dbei, dat->codePage); - if (!msg) { - mir_free(dbei.pBlob); - mir_free(buffer); - return NULL; - } - TrimMessage(msg); - formatted = const_cast(Utils::FormatRaw(dat, msg, dwFormattingParams, FALSE)); - mir_free(msg); + TCHAR *msg = DbGetEventTextT(&dbei, dat->codePage); + if (!msg) { + mir_free(dbei.pBlob); + mir_free(buffer); + return NULL; } + TrimMessage(msg); + formatted = const_cast(Utils::FormatRaw(dat, msg, dwFormattingParams, FALSE)); + mir_free(msg); BOOL bIsStatusChangeEvent = IsStatusEvent(dbei.eventType); @@ -704,9 +697,8 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, TCHAR cc = szTemplate[i + 1]; skipToNext = FALSE; skipFont = FALSE; - /* - * handle modifiers - */ + + // handle modifiers while (cc == '#' || cc == '$' || cc == '&' || cc == '?' || cc == '\\') { switch (cc) { case '#': @@ -975,11 +967,7 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, else if (!skipFont) AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", GetRTFFont(isSent ? MSGFONTID_MYMSG + iFontIDOffset : MSGFONTID_YOURMSG + iFontIDOffset)); - if (rtfMessage != NULL) - AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s", rtfMessage); - else - AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, formatted, MAKELONG(isSent, dat->bIsHistory)); - + AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, formatted, MAKELONG(isSent, dat->bIsHistory)); AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s", "\\b0\\ul0\\i0 "); break; @@ -988,18 +976,17 @@ static char *Template_CreateRTFFromDbEvent(TWindowData *dat, MCONTACT hContact, AppendToBuffer(buffer, bufferEnd, bufferAlloced, "%s ", GetRTFFont(isSent ? MSGFONTID_MYMISC + iFontIDOffset : MSGFONTID_YOURMISC + iFontIDOffset)); { char *szFileName = (char *)dbei.pBlob + sizeof(DWORD); + ptrT tszFileName(DbGetEventStringT(&dbei, szFileName)); + char *szDescr = szFileName + mir_strlen(szFileName) + 1; - TCHAR *tszFileName = DbGetEventStringT(&dbei, szFileName); if (*szDescr != 0) { - TCHAR *tszDescr = DbGetEventStringT(&dbei, szDescr); + ptrT tszDescr(DbGetEventStringT(&dbei, szDescr)); + TCHAR buf[1000]; mir_sntprintf(buf, SIZEOF(buf), _T("%s (%s)"), tszFileName, tszDescr); AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, buf, 0); - mir_free(tszDescr); } else AppendUnicodeToBuffer(buffer, bufferEnd, bufferAlloced, tszFileName, 0); - - mir_free(tszFileName); } break; @@ -1139,7 +1126,7 @@ skip: static DWORD CALLBACK LogStreamInEvents(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG * pcb) { - LogStreamData *dat = (LogStreamData *)dwCookie; + LogStreamData *dat = (LogStreamData*)dwCookie; if (dat->buffer == NULL) { dat->bufferOffset = 0; @@ -1389,7 +1376,7 @@ void TSAPI StreamInEvents(HWND hwndDlg, HANDLE hDbEventFirst, int count, int fAp event.hDbEventFirst = hDbEventFirst; event.count = count; CallService(MS_HPP_EG_EVENT, 0, (LPARAM)&event); - //SendMessage(hwndDlg, DM_FORCESCROLL, (WPARAM)&pt, (LPARAM)&si); + DM_ScrollToBottom(dat, 0, 0); if (fAppend) dat->hDbEventLast = hDbEventFirst; -- cgit v1.2.3