void Smileys_FreeParse(SmileysParseInfo parseInfo) { if (parseInfo != NULL) { if (parseInfo->pieces != NULL) DestroySmileyList(parseInfo->pieces); mir_free(parseInfo); } }
void CSmileyString::AddListeningToIcon(struct SHORTDATA *dat, PDNCE pdnce, TCHAR *szText, BOOL replace_smileys) { iMaxSmileyHeight = 0; DestroySmileyList(); if (szText == NULL) return; int text_size = (int)_tcslen( szText ); plText = li.List_Create( 0, 1 ); // Add Icon { BITMAP bm; ICONINFO icon; ClcContactTextPiece *piece = (ClcContactTextPiece *) mir_alloc(sizeof(ClcContactTextPiece)); piece->type = TEXT_PIECE_TYPE_SMILEY; piece->len = 0; piece->smiley = g_hListeningToIcon; piece->smiley_width = 16; piece->smiley_height = 16; if (GetIconInfo(piece->smiley, &icon)) { if (GetObject(icon.hbmColor,sizeof(BITMAP),&bm)) { piece->smiley_width = bm.bmWidth; piece->smiley_height = bm.bmHeight; } DeleteObject(icon.hbmMask); DeleteObject(icon.hbmColor); } dat->text_smiley_height = max(piece->smiley_height, dat->text_smiley_height); iMaxSmileyHeight = max(piece->smiley_height, iMaxSmileyHeight); li.List_Insert( plText, piece, plText->realCount); } // Add text { ClcContactTextPiece *piece = (ClcContactTextPiece *) mir_alloc(sizeof(ClcContactTextPiece)); piece->type = TEXT_PIECE_TYPE_TEXT; piece->start_pos = 0; piece->len = text_size; li.List_Insert( plText, piece, plText->realCount); } }
void CSmileyString::AddListeningToIcon(ClcData *dat, wchar_t *szText) { iMaxSmileyHeight = 0; DestroySmileyList(); if (szText == nullptr) return; int text_size = (int)mir_wstrlen(szText); plText = List_Create(0, 1); // Add Icon { ClcContactTextPiece *piece = (ClcContactTextPiece *)mir_alloc(sizeof(ClcContactTextPiece)); piece->type = TEXT_PIECE_TYPE_SMILEY; piece->len = 0; piece->smiley = g_hListeningToIcon; piece->smiley_width = 16; piece->smiley_height = 16; ICONINFO icon; if (GetIconInfo(piece->smiley, &icon)) { BITMAP bm; if (GetObject(icon.hbmColor, sizeof(BITMAP), &bm)) { piece->smiley_width = bm.bmWidth; piece->smiley_height = bm.bmHeight; } DeleteObject(icon.hbmMask); DeleteObject(icon.hbmColor); } dat->text_smiley_height = max(piece->smiley_height, dat->text_smiley_height); iMaxSmileyHeight = max(piece->smiley_height, iMaxSmileyHeight); List_Insert(plText, piece, plText->realCount); } // Add text { ClcContactTextPiece *piece = (ClcContactTextPiece *)mir_alloc(sizeof(ClcContactTextPiece)); piece->type = TEXT_PIECE_TYPE_TEXT; piece->start_pos = 0; piece->len = text_size; List_Insert(plText, piece, plText->realCount); } }
void CSmileyString::ReplaceSmileys(SHORTDATA *dat, ClcCacheEntry *pdnce, TCHAR * szText, BOOL replace_smileys) { int last_pos = 0; iMaxSmileyHeight = 0; DestroySmileyList(); if (!dat->text_replace_smileys || !replace_smileys || szText == NULL) return; int text_size = (int)mir_tstrlen(szText); // Call service for the first time to see if needs to be used... SMADD_BATCHPARSE2 sp = { 0 }; sp.cbSize = sizeof(sp); if (dat->text_use_protocol_smileys) { sp.Protocolname = pdnce->m_cache_cszProto; if (db_get_b(NULL, "CLC", "Meta", SETTING_USEMETAICON_DEFAULT) != 1 && pdnce->m_cache_cszProto != NULL && mir_strcmp(pdnce->m_cache_cszProto, META_PROTO) == 0) { MCONTACT hContact = db_mc_getMostOnline(pdnce->hContact); if (hContact != 0) sp.Protocolname = GetContactProto(hContact); } } else sp.Protocolname = "clist"; sp.str = szText; sp.flag = SAFL_TCHAR; SMADD_BATCHPARSERES *spr = (SMADD_BATCHPARSERES*)CallService(MS_SMILEYADD_BATCHPARSE, 0, (LPARAM)&sp); // Did not find a simley if (spr == NULL || (INT_PTR)spr == CALLSERVICE_NOTFOUND) return; // Lets add smileys plText = List_Create(0, 1); for (unsigned i = 0; i < sp.numSmileys; ++i) { if (spr[i].hIcon != NULL) { // For deffective smileypacks // Add text if (spr[i].startChar - last_pos > 0) { ClcContactTextPiece *piece = (ClcContactTextPiece *)mir_alloc(sizeof(ClcContactTextPiece)); piece->type = TEXT_PIECE_TYPE_TEXT; piece->start_pos = last_pos;//sp.str - text; piece->len = spr[i].startChar - last_pos; List_Insert(plText, piece, plText->realCount); } // Add smiley { BITMAP bm; ICONINFO icon; ClcContactTextPiece *piece = (ClcContactTextPiece *)mir_alloc(sizeof(ClcContactTextPiece)); piece->type = TEXT_PIECE_TYPE_SMILEY; piece->len = spr[i].size; piece->smiley = spr[i].hIcon; piece->smiley_width = 16; piece->smiley_height = 16; if (GetIconInfo(piece->smiley, &icon)) { if (GetObject(icon.hbmColor, sizeof(BITMAP), &bm)) { piece->smiley_width = bm.bmWidth; piece->smiley_height = bm.bmHeight; } DeleteObject(icon.hbmMask); DeleteObject(icon.hbmColor); } dat->text_smiley_height = max(piece->smiley_height, dat->text_smiley_height); iMaxSmileyHeight = max(piece->smiley_height, iMaxSmileyHeight); List_Insert(plText, piece, plText->realCount); } } // Get next last_pos = spr[i].startChar + spr[i].size; } CallService(MS_SMILEYADD_BATCHFREE, 0, (LPARAM)spr); // Add rest of text if (last_pos < text_size) { ClcContactTextPiece *piece = (ClcContactTextPiece *)mir_alloc(sizeof(ClcContactTextPiece)); piece->type = TEXT_PIECE_TYPE_TEXT; piece->start_pos = last_pos; piece->len = text_size - last_pos; List_Insert(plText, piece, plText->realCount); } }
/* * Parsing of text for smiley */ void CSmileyString::ReplaceSmileys(struct SHORTDATA *dat, PDNCE pdnce, TCHAR * szText, BOOL replace_smileys) { SMADD_BATCHPARSE2 sp = {0}; SMADD_BATCHPARSERES *spr; int last_pos=0; iMaxSmileyHeight = 0; DestroySmileyList(); if (!dat->text_replace_smileys || !replace_smileys || szText == NULL) { return; } int text_size = (int)_tcslen( szText ); // Call service for the first time to see if needs to be used... sp.cbSize = sizeof(sp); if (dat->text_use_protocol_smileys) { sp.Protocolname = pdnce->m_cache_cszProto; if (ModernGetSettingByte(NULL,"CLC","Meta",SETTING_USEMETAICON_DEFAULT) != 1 && pdnce->m_cache_cszProto != NULL && g_szMetaModuleName && strcmp(pdnce->m_cache_cszProto, g_szMetaModuleName) == 0) { HANDLE hContact = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (LPARAM)pdnce->m_cache_hContact, 0); if (hContact != 0) { sp.Protocolname = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (LPARAM)hContact, 0); } } } else { sp.Protocolname = "clist"; } sp.str = szText; sp.flag = SAFL_TCHAR; spr = (SMADD_BATCHPARSERES*)CallService(MS_SMILEYADD_BATCHPARSE, 0, (LPARAM)&sp); if (spr == NULL || (INT_PTR)spr == CALLSERVICE_NOTFOUND) { // Did not find a simley return; } // Lets add smileys plText = li.List_Create( 0, 1 ); for (unsigned i = 0; i < sp.numSmileys; ++i) { if (spr[i].hIcon != NULL) // For deffective smileypacks { // Add text if (spr[i].startChar - last_pos > 0) { ClcContactTextPiece *piece = (ClcContactTextPiece *) mir_alloc(sizeof(ClcContactTextPiece)); piece->type = TEXT_PIECE_TYPE_TEXT; piece->start_pos = last_pos ;//sp.str - text; piece->len = spr[i].startChar - last_pos; li.List_Insert(plText, piece, plText->realCount); } // Add smiley { BITMAP bm; ICONINFO icon; ClcContactTextPiece *piece = (ClcContactTextPiece *) mir_alloc(sizeof(ClcContactTextPiece)); piece->type = TEXT_PIECE_TYPE_SMILEY; piece->len = spr[i].size; piece->smiley = spr[i].hIcon; piece->smiley_width = 16; piece->smiley_height = 16; if (GetIconInfo(piece->smiley, &icon)) { if (GetObject(icon.hbmColor,sizeof(BITMAP),&bm)) { piece->smiley_width = bm.bmWidth; piece->smiley_height = bm.bmHeight; } DeleteObject(icon.hbmMask); DeleteObject(icon.hbmColor); } dat->text_smiley_height = max( piece->smiley_height, dat->text_smiley_height ); iMaxSmileyHeight = max( piece->smiley_height, iMaxSmileyHeight ); li.List_Insert(plText, piece, plText->realCount); } } // Get next last_pos = spr[i].startChar + spr[i].size; } CallService(MS_SMILEYADD_BATCHFREE, 0, (LPARAM)spr); // Add rest of text if (last_pos < text_size) { ClcContactTextPiece *piece = (ClcContactTextPiece *) mir_alloc(sizeof(ClcContactTextPiece)); piece->type = TEXT_PIECE_TYPE_TEXT; piece->start_pos = last_pos; piece->len = text_size-last_pos; li.List_Insert(plText, piece, plText->realCount); } }