diff options
Diffstat (limited to 'plugins/TabSRMM/src/chat/message.cpp')
-rw-r--r-- | plugins/TabSRMM/src/chat/message.cpp | 95 |
1 files changed, 54 insertions, 41 deletions
diff --git a/plugins/TabSRMM/src/chat/message.cpp b/plugins/TabSRMM/src/chat/message.cpp index 8a564fb0e7..605341583d 100644 --- a/plugins/TabSRMM/src/chat/message.cpp +++ b/plugins/TabSRMM/src/chat/message.cpp @@ -26,7 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static int RTFColorToIndex(int *pIndex, int iCol, SESSION_INFO *si)
{
int i;
- MODULEINFO * pMod = MM_FindModule(si->pszModule);
+ MODULEINFO *pMod = pci->MM_FindModule(si->pszModule);
for (i=0; i < pMod->nColorCount ; i++)
if (pIndex[i] == iCol)
@@ -52,9 +52,8 @@ static void CreateColorMap(char* Text, int *pIndex, SESSION_INFO *si) while (p2 && p2 < pEnd) {
if (sscanf(p2, lpszFmt, &szRed, &szGreen, &szBlue) > 0) {
- int i;
- MODULEINFO * pMod = MM_FindModule(si->pszModule);
- for (i=0; i < pMod->nColorCount ; i ++)
+ MODULEINFO * pMod = pci->MM_FindModule(si->pszModule);
+ for (int i=0; i < pMod->nColorCount ; i ++)
if (pMod->crColors[i] == RGB(atoi(szRed), atoi(szGreen), atoi(szBlue)))
pIndex[i] = iIndex;
}
@@ -92,8 +91,9 @@ TCHAR* Chat_DoRtfToTags(char* pszText, SESSION_INFO *si) // create an index of colors in the module and map them to
// corresponding colors in the RTF color table
- mir_ptr<int> pIndex((int*)mir_alloc(sizeof(int) * MM_FindModule(si->pszModule)->nColorCount));
- for (i=0; i < MM_FindModule(si->pszModule)->nColorCount ; i++)
+ MODULEINFO *mi = pci->MM_FindModule(si->pszModule);
+ mir_ptr<int> pIndex((int*)mir_alloc(sizeof(int)*mi->nColorCount));
+ for (i = 0; i < mi->nColorCount; i++)
pIndex[i] = -1;
CreateColorMap(pszText, pIndex, si);
@@ -123,52 +123,63 @@ TCHAR* Chat_DoRtfToTags(char* pszText, SESSION_INFO *si) iInd = RTFColorToIndex(pIndex, iCol, si);
bJustRemovedRTF = TRUE;
- if (bTextHasStarted || iInd >= 0)
- mir_snprintf(InsertThis, SIZEOF(InsertThis), (iInd >= 0) ? "%%c%02u" : "%%C", iInd);
- } else if (!memcmp(p1, "\\highlight", 10)) { //background color
+ // if (bTextHasStarted || iInd >= 0)
+ // mir_snprintf(InsertThis, SIZEOF(InsertThis), (iInd >= 0) ? "%%c%02u" : "%%C", iInd);
+ }
+ else if (!memcmp(p1, "\\highlight", 10)) { //background color
int iCol, iInd;
iRemoveChars = 10 + ReadInteger(p1 + 10, &iCol);
iInd = RTFColorToIndex(pIndex, iCol, si);
bJustRemovedRTF = TRUE;
- if (bTextHasStarted || iInd >= 0)
- mir_snprintf(InsertThis, SIZEOF(InsertThis), (iInd >= 0) ? "%%f%02u" : "%%F", iInd);
- } else if (!memcmp(p1, "\\lang", 5)) { // language id
+ // if (bTextHasStarted || iInd >= 0)
+ // mir_snprintf(InsertThis, SIZEOF(InsertThis), (iInd >= 0) ? "%%f%02u" : "%%F", iInd);
+ }
+ else if (!memcmp(p1, "\\lang", 5)) { // language id
bTextHasStarted = bJustRemovedRTF = TRUE;
iRemoveChars = 5 + ReadInteger(p1 + 5, NULL);
- } else if (!memcmp(p1, "\\par", 4)) { // newline
+ }
+ else if (!memcmp(p1, "\\par", 4)) { // newline
bTextHasStarted = bJustRemovedRTF = TRUE;
iRemoveChars = 4;
strcpy(InsertThis, "\n");
- } else if (!memcmp(p1, "\\endash", 7)) {
+ }
+ else if (!memcmp(p1, "\\endash", 7)) {
bTextHasStarted = bJustRemovedRTF = TRUE;
iRemoveChars = 7;
strcpy(InsertThis, "\xE2\x80\x93");
- } else if (!memcmp(p1, "\\emdash", 7)) {
+ }
+ else if (!memcmp(p1, "\\emdash", 7)) {
bTextHasStarted = bJustRemovedRTF = TRUE;
iRemoveChars = 7;
strcpy(InsertThis, "\xE2\x80\x94");
- } else if (!memcmp(p1, "\\bullet", 7)) {
+ }
+ else if (!memcmp(p1, "\\bullet", 7)) {
bTextHasStarted = bJustRemovedRTF = TRUE;
iRemoveChars = 7;
strcpy(InsertThis, "\xE2\x80\xA2");
- } else if (!memcmp(p1, "\\line", 5)) { // newline
+ }
+ else if (!memcmp(p1, "\\line", 5)) { // newline
bTextHasStarted = bJustRemovedRTF = TRUE;
iRemoveChars = 5;
strcpy(InsertThis, "\n");
- } else if (!memcmp(p1, "\\b", 2)) { //bold
+ }
+ else if (!memcmp(p1, "\\b", 2)) { //bold
bTextHasStarted = bJustRemovedRTF = TRUE;
iRemoveChars = (p1[2] != '0') ? 2 : 3;
strcpy(InsertThis, (p1[2] != '0') ? "%b" : "%B");
- } else if (!memcmp(p1, "\\i", 2)) { // italics
+ }
+ else if (!memcmp(p1, "\\i", 2)) { // italics
bTextHasStarted = bJustRemovedRTF = TRUE;
iRemoveChars = (p1[2] != '0') ? 2 : 3;
strcpy(InsertThis, (p1[2] != '0') ? "%i" : "%I");
- } else if (!memcmp(p1, "\\uc", 3)) { // number of Unicode chars
+ }
+ else if (!memcmp(p1, "\\uc", 3)) { // number of Unicode chars
bTextHasStarted = bJustRemovedRTF = TRUE;
iUcMode = p1[3] - '0';
iRemoveChars = 4;
- } else if (!memcmp(p1, "\\ul", 3)) { // underlined
+ }
+ else if (!memcmp(p1, "\\ul", 3)) { // underlined
bTextHasStarted = bJustRemovedRTF = TRUE;
if (p1[3] == 'n')
iRemoveChars = 7;
@@ -177,22 +188,23 @@ TCHAR* Chat_DoRtfToTags(char* pszText, SESSION_INFO *si) else
iRemoveChars = 3;
mir_snprintf(InsertThis, SIZEOF(InsertThis), (p1[3] != '0' && p1[3] != 'n') ? "%%u" : "%%U");
- } else if (p1[1] == 'f' && isdigit(p1[2])) { // unicode char
+ }
+ else if (p1[1] == 'f' && isdigit(p1[2])) { // unicode char
bTextHasStarted = bJustRemovedRTF = TRUE;
iRemoveChars = 2 + ReadInteger(p1 + 2, NULL);
- } else if (p1[1] == '\\' || p1[1] == '{' || p1[1] == '}') { // escaped characters
+ }
+ else if (p1[1] == '\\' || p1[1] == '{' || p1[1] == '}') { // escaped characters
bTextHasStarted = TRUE;
bJustRemovedRTF = FALSE;
iRemoveChars = 2;
mir_snprintf(InsertThis, SIZEOF(InsertThis), "%c", p1[1]);
- } else if (p1[1] == '~') { // non-breaking space
+ }
+ else if (p1[1] == '~') { // non-breaking space
bTextHasStarted = TRUE;
bJustRemovedRTF = FALSE;
iRemoveChars = 2;
strcpy(InsertThis, "\xC2\xA0");
}
-
-
else if (!memcmp(p1, "\\tab",4)) { // tab
bTextHasStarted = TRUE;
bJustRemovedRTF = TRUE;
@@ -223,7 +235,6 @@ TCHAR* Chat_DoRtfToTags(char* pszText, SESSION_INFO *si) iRemoveChars = 7;
strcpy(InsertThis, "\xE2\x80\x99");
}
-
else if (p1[1] == '\'') { // special character
char tmp[4], *p3 = tmp;
bTextHasStarted = TRUE;
@@ -239,8 +250,10 @@ TCHAR* Chat_DoRtfToTags(char* pszText, SESSION_INFO *si) sscanf(tmp, "%x", InsertThis);
InsertThis[1] = 0;
- } else iRemoveChars = 2;
- } else if (bJustRemovedRTF) { // remove unknown RTF command
+ }
+ else iRemoveChars = 2;
+ }
+ else if (bJustRemovedRTF) { // remove unknown RTF command
int j = 1;
bJustRemovedRTF = TRUE;
while (p1[j] != ' ' && p1[j] != '\\' && p1[j] != '\0')
@@ -266,6 +279,7 @@ TCHAR* Chat_DoRtfToTags(char* pszText, SESSION_INFO *si) iRemoveChars = 1;
strcpy(InsertThis, "%%");
break;
+
case ' ': // remove spaces following a RTF command
if (bJustRemovedRTF)
iRemoveChars = 1;
@@ -284,25 +298,26 @@ TCHAR* Chat_DoRtfToTags(char* pszText, SESSION_INFO *si) MoveMemory(p1 + lstrlenA(InsertThis) , p1 + iRemoveChars, lstrlenA(p1) - iRemoveChars + 1);
CopyMemory(p1, InsertThis, lstrlenA(InsertThis));
p1 += lstrlenA(InsertThis);
- } else p1++;
+ }
+ else p1++;
}
return mir_utf8decodeW(pszText);
}
-static DWORD CALLBACK Chat_Message_StreamCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG * pcb)
+static DWORD CALLBACK Chat_Message_StreamCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
static DWORD dwRead;
- char ** ppText = (char **) dwCookie;
-
+ char **ppText = (char**)dwCookie;
if (*ppText == NULL) {
*ppText = (char *)mir_alloc(cb + 1);
memcpy(*ppText, pbBuff, cb);
(*ppText)[cb] = 0;
*pcb = cb;
dwRead = cb;
- } else {
- char *p = (char *)mir_alloc(dwRead + cb + 1);
+ }
+ else {
+ char *p = (char*)mir_alloc(dwRead + cb + 1);
memcpy(p, *ppText, dwRead);
memcpy(p + dwRead, pbBuff, cb);
p[dwRead + cb] = 0;
@@ -316,18 +331,16 @@ static DWORD CALLBACK Chat_Message_StreamCallback(DWORD_PTR dwCookie, LPBYTE pbB char* Chat_Message_GetFromStream(HWND hwndDlg, SESSION_INFO *si)
{
- EDITSTREAM stream;
- char* pszText = NULL;
- DWORD dwFlags;
-
if (hwndDlg == 0 || si == 0)
return NULL;
+ char* pszText = NULL;
+ EDITSTREAM stream;
ZeroMemory(&stream, sizeof(stream));
stream.pfnCallback = Chat_Message_StreamCallback;
- stream.dwCookie = (DWORD_PTR) & pszText; // pass pointer to pointer
+ stream.dwCookie = (DWORD_PTR)&pszText; // pass pointer to pointer
- dwFlags = SF_RTFNOOBJS | SFF_PLAINRTF | SF_USECODEPAGE | (CP_UTF8 << 16);
+ DWORD dwFlags = SF_RTFNOOBJS | SFF_PLAINRTF | SF_USECODEPAGE | (CP_UTF8 << 16);
SendMessage(GetDlgItem(hwndDlg, IDC_CHAT_MESSAGE), EM_STREAMOUT, dwFlags, (LPARAM)&stream);
return pszText; // pszText contains the text
}
|