From 23da585729242bc135e7a6da0dc5bf699e6c9b54 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 19 Apr 2015 21:12:24 +0000 Subject: - all strings operations were rewritten using CMString instead of ugly self-made buffers; - CComPtr<> introduced to simplify COM calls processing; - version bump. git-svn-id: http://svn.miranda-ng.org/main/trunk@12946 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/IEView/src/ChatHTMLBuilder.cpp | 115 ++++++++++++++------------------- 1 file changed, 50 insertions(+), 65 deletions(-) (limited to 'plugins/IEView/src/ChatHTMLBuilder.cpp') diff --git a/plugins/IEView/src/ChatHTMLBuilder.cpp b/plugins/IEView/src/ChatHTMLBuilder.cpp index 1584907cf4..b8264298bb 100644 --- a/plugins/IEView/src/ChatHTMLBuilder.cpp +++ b/plugins/IEView/src/ChatHTMLBuilder.cpp @@ -82,12 +82,11 @@ void ChatHTMLBuilder::loadMsgDlgFont(int i, LOGFONTA * lf, COLORREF * colour) } } -char *ChatHTMLBuilder::timestampToString(time_t time) +char* ChatHTMLBuilder::timestampToString(time_t time) { static char szResult[512]; static char str[80]; char *pszStamp = "[%H:%M]"; - //InitSetting( &g_Settings.pszTimeStamp, "HeaderTime", _T("[%H:%M]")); strftime(str, 79, pszStamp, localtime(&time)); mir_strncpy(szResult, ptrA(mir_utf8encode(str)), 500); return szResult; @@ -97,51 +96,47 @@ void ChatHTMLBuilder::buildHead(IEView *view, IEVIEWEVENT *event) { LOGFONTA lf; COLORREF color; - char *output = NULL; - int outputSize; + ProtocolSettings *protoSettings = getChatProtocolSettings(event->pszProto); - if (protoSettings == NULL) { + if (protoSettings == NULL) return; - } - if (protoSettings->getChatMode() == Options::MODE_TEMPLATE) { - // buildHeadTemplate(view, event); + + if (protoSettings->getChatMode() == Options::MODE_TEMPLATE) return; - } + + CMStringA str; if (protoSettings->getChatMode() == Options::MODE_CSS) { const char *externalCSS = protoSettings->getChatCssFilename(); - Utils::appendText(&output, &outputSize, "\n", externalCSS); + str.AppendFormat("\n", externalCSS); } else { HDC hdc = GetDC(NULL); int logPixelSY = GetDeviceCaps(hdc, LOGPIXELSY); ReleaseDC(NULL, hdc); - Utils::appendText(&output, &outputSize, ""); - Utils::appendText(&output, &outputSize, "\n"); - } - if (output != NULL) { - view->write(output); - free(output); + str.Append("\n"); } + + if (!str.IsEmpty()) + view->write(str); + setLastEventType(-1); } @@ -167,12 +162,9 @@ void ChatHTMLBuilder::appendEventNonTemplate(IEView *view, IEVIEWEVENT *event) DWORD iconFlags = db_get_dw(NULL, CHATMOD, CHAT_ICON_FLAGS, 0); IEVIEWEVENTDATA* eventData = event->eventData; for (int eventIdx = 0; eventData != NULL && (eventIdx < event->count || event->count == -1); eventData = eventData->next, eventIdx++) { - //DWORD dwFlags = eventData->dwFlags; const char *iconFile = ""; DWORD dwData = eventData->dwData; bool isSent = eventData->bIsMe != 0; - int outputSize = 0; - char *output = NULL; const char *className = ""; bool showIcon = false; @@ -238,44 +230,37 @@ void ChatHTMLBuilder::appendEventNonTemplate(IEView *view, IEVIEWEVENT *event) className = "information"; } } - Utils::appendText(&output, &outputSize, "
", isSent ? "divOut" : "divIn"); - if (dwData & IEEDD_GC_SHOW_ICON) { - Utils::appendIcon(&output, &outputSize, iconFile); - } - if (dwData & IEEDD_GC_SHOW_TIME) { - Utils::appendText(&output, &outputSize, "%s ", timestampToString(eventData->time)); - } - if ((dwData & IEEDD_GC_SHOW_NICK) && eventData->iType == IEED_GC_EVENT_MESSAGE) { - Utils::appendText(&output, &outputSize, "%s: ", - isSent ? "nameOut" : "nameIn", szName); - } - if (dwData & IEEDD_GC_MSG_ON_NEW_LINE) { - Utils::appendText(&output, &outputSize, "
"); - } - Utils::appendText(&output, &outputSize, "", className); - Utils::appendText(&output, &outputSize, "%s", szText); - Utils::appendText(&output, &outputSize, "
\n"); - if (output != NULL) { - view->write(output); - free(output); - } + + CMStringA str(FORMAT, "
", isSent ? "divOut" : "divIn"); + if (dwData & IEEDD_GC_SHOW_ICON) + Utils::appendIcon(str, iconFile); + + if (dwData & IEEDD_GC_SHOW_TIME) + str.AppendFormat("%s ", timestampToString(eventData->time)); + + if ((dwData & IEEDD_GC_SHOW_NICK) && eventData->iType == IEED_GC_EVENT_MESSAGE) + str.AppendFormat("%s: ", isSent ? "nameOut" : "nameIn", szName); + + if (dwData & IEEDD_GC_MSG_ON_NEW_LINE) + str.Append("
"); + + str.AppendFormat("", className); + str.Append(szText); + str.Append("
\n"); + + if (!str.IsEmpty()) + view->write(str); } } void ChatHTMLBuilder::appendEvent(IEView *view, IEVIEWEVENT *event) { ProtocolSettings *protoSettings = getChatProtocolSettings(event->pszProto); - if (protoSettings == NULL) { - return; - } - // if (protoSettings->getSRMMMode() == Options::MODE_TEMPLATE) { - // appendEventTemplate(view, event); - // } else { - appendEventNonTemplate(view, event); - // } + if (protoSettings != NULL) + appendEventNonTemplate(view, event); } -bool ChatHTMLBuilder::isDbEventShown(DBEVENTINFO *) +bool ChatHTMLBuilder::isDbEventShown(DBEVENTINFO*) { return true; } -- cgit v1.2.3