diff options
Diffstat (limited to 'plugins/TipperYM/src/mir_smileys.cpp')
-rw-r--r-- | plugins/TipperYM/src/mir_smileys.cpp | 159 |
1 files changed, 60 insertions, 99 deletions
diff --git a/plugins/TipperYM/src/mir_smileys.cpp b/plugins/TipperYM/src/mir_smileys.cpp index ca94e5310c..53cc09fe46 100644 --- a/plugins/TipperYM/src/mir_smileys.cpp +++ b/plugins/TipperYM/src/mir_smileys.cpp @@ -23,8 +23,7 @@ Boston, MA 02111-1307, USA. int InitTipperSmileys()
{
// Register smiley category
- if (ServiceExists(MS_SMILEYADD_REGISTERCATEGORY))
- {
+ if (ServiceExists(MS_SMILEYADD_REGISTERCATEGORY)) {
SMADD_REGCAT rc;
rc.cbSize = sizeof(rc);
rc.name = "tipper";
@@ -43,11 +42,10 @@ SMILEYPARSEINFO Smileys_PreParse(LPCTSTR lpString, int nCount, const char *proto if (nCount == -1)
nCount = (int)mir_tstrlen(lpString);
- SMILEYPARSEINFO info = (SMILEYPARSEINFO) mir_calloc(sizeof(tagSMILEYPARSEINFO));
+ SMILEYPARSEINFO info = (SMILEYPARSEINFO)mir_calloc(sizeof(tagSMILEYPARSEINFO));
info->pieces = ReplaceSmileys(lpString, nCount, protocol, &info->max_height);
- if (!info->pieces)
- {
+ if (!info->pieces) {
mir_free(info);
return NULL;
}
@@ -57,8 +55,7 @@ SMILEYPARSEINFO Smileys_PreParse(LPCTSTR lpString, int nCount, const char *proto void Smileys_FreeParse(SMILEYPARSEINFO parseInfo)
{
- if (parseInfo != NULL)
- {
+ if (parseInfo != NULL) {
if (parseInfo->pieces != NULL)
DestroySmileyList(parseInfo->pieces);
@@ -109,72 +106,62 @@ int Smileys_DrawText(HDC hDC, LPCTSTR lpString, int nCount, LPRECT lpRect, UINT SIZE GetTextSize(HDC hdcMem, const TCHAR *szText, SMILEYPARSEINFO info, UINT uTextFormat, int max_smiley_height, int max_width)
{
- SIZE text_size = {0};
+ SIZE text_size = { 0 };
int text_height;
int row_count = 0, pos_x = 0;
- if (szText == NULL || _tcsclen(szText) == 0)
- {
+ if (szText == NULL || _tcsclen(szText) == 0) {
text_size.cy = 0;
text_size.cx = 0;
}
- else
- {
- RECT text_rc = {0, 0, 2048, 2048};
+ else {
+ RECT text_rc = { 0, 0, 2048, 2048 };
- if (info->pieces == NULL)
- {
+ if (info->pieces == NULL) {
DrawText(hdcMem, szText, -1, &text_rc, DT_CALCRECT | uTextFormat);
text_size.cx = text_rc.right - text_rc.left;
text_size.cy = text_rc.bottom - text_rc.top;
}
- else
- {
+ else {
// Get real height of the line
text_height = DrawText(hdcMem, _T("A"), 1, &text_rc, DT_CALCRECT | uTextFormat);
// See each item of list
int i;
- for (i = 0; i < info->pieces->realCount; i++)
- {
- TEXTPIECE *piece = (TEXTPIECE *) info->pieces->items[i];
+ for (i = 0; i < info->pieces->realCount; i++) {
+ TEXTPIECE *piece = (TEXTPIECE *)info->pieces->items[i];
info->row_height[row_count] = max(info->row_height[row_count], text_height);
- if (piece->type == TEXT_PIECE_TYPE_TEXT)
- {
- RECT text_rc = {0, 0, 2048, 2048};
+ if (piece->type == TEXT_PIECE_TYPE_TEXT) {
+ RECT text_rc = { 0, 0, 2048, 2048 };
DrawText(hdcMem, szText + piece->start_pos, piece->len, &text_rc, DT_CALCRECT | uTextFormat);
pos_x += (text_rc.right - text_rc.left);
- if (pos_x > max_width)
- {
+ if (pos_x > max_width) {
text_size.cx = max(text_size.cx, pos_x - (text_rc.right - text_rc.left));
pos_x = text_rc.right - text_rc.left;
info->row_height[++row_count] = text_height;
}
- if (szText[piece->start_pos + piece->len - 1] == '\n')
- {
+ if (szText[piece->start_pos + piece->len - 1] == '\n') {
text_size.cx = max(text_size.cx, pos_x);
pos_x = 0;
info->row_height[++row_count] = 0;
}
}
- else
- {
+ else {
double factor;
if (uTextFormat & DT_RESIZE_SMILEYS && piece->smiley_height > text_height)
- factor = text_height / (double) piece->smiley_height;
+ factor = text_height / (double)piece->smiley_height;
else
factor = 1;
info->row_height[row_count] = max(info->row_height[row_count], piece->smiley_height * factor);
pos_x += piece->smiley_width * factor;
- if (pos_x > max_width)
- {
+ if (pos_x > max_width) {
text_size.cx = max(text_size.cx, pos_x - (piece->smiley_width * factor));
pos_x = piece->smiley_width * factor;
info->row_height[++row_count] = piece->smiley_height * factor;
@@ -212,36 +199,30 @@ void DrawTextSmiley(HDC hdcMem, RECT free_rc, const TCHAR *szText, int len, SMIL // Get real height of the line
text_height = DrawText(hdcMem, _T("A"), 1, &tmp_rc, DT_CALCRECT | uTextFormat);
- SaveAlpha(&free_rc);
+ mir_ptr<COLOR32> pBits(SaveAlpha(&free_rc));
// Just draw ellipsis
if (free_rc.right <= free_rc.left)
- {
DrawText(hdcMem, _T("..."), 3, &free_rc, uTextFormat & ~DT_END_ELLIPSIS);
- }
- else
- {
+ else {
// Draw text and smileys
RECT text_rc = free_rc;
- for (; i < info->pieces->realCount && i >= 0 && len > 0; i += (uTextFormat & DT_RTLREADING ? -1 : 1))
- {
- TEXTPIECE *piece = (TEXTPIECE *) info->pieces->items[i];
+ for (; i < info->pieces->realCount && i >= 0 && len > 0; i += (uTextFormat & DT_RTLREADING ? -1 : 1)) {
+ TEXTPIECE *piece = (TEXTPIECE *)info->pieces->items[i];
if (uTextFormat & DT_RTLREADING)
text_rc.right = free_rc.right - pos_x;
else
text_rc.left = free_rc.left + pos_x;
- if (piece->type == TEXT_PIECE_TYPE_TEXT)
- {
+ if (piece->type == TEXT_PIECE_TYPE_TEXT) {
tmp_rc = text_rc;
tmp_rc.right = 2048;
DrawText(hdcMem, szText + piece->start_pos, min(len, piece->len), &tmp_rc, DT_CALCRECT | (uTextFormat & ~DT_END_ELLIPSIS));
pos_x += (tmp_rc.right - tmp_rc.left);
- if (pos_x > (free_rc.right - free_rc.left))
- {
+ if (pos_x > (free_rc.right - free_rc.left)) {
pos_x = tmp_rc.right - tmp_rc.left;
text_rc.left = free_rc.left;
text_rc.right = free_rc.right;
@@ -259,8 +240,7 @@ void DrawTextSmiley(HDC hdcMem, RECT free_rc, const TCHAR *szText, int len, SMIL len -= piece->len;
text_rc.top -= shift;
- if (szText[piece->start_pos + piece->len - 1] == '\n')
- {
+ if (szText[piece->start_pos + piece->len - 1] == '\n') {
text_rc.left = free_rc.left;
text_rc.right = free_rc.right;
text_rc.top += info->row_height[row_count];
@@ -268,20 +248,17 @@ void DrawTextSmiley(HDC hdcMem, RECT free_rc, const TCHAR *szText, int len, SMIL row_count++;
}
}
- else
- {
+ else {
double factor;
- if (len < piece->len)
- {
+ if (len < piece->len) {
len = 0;
}
- else
- {
+ else {
len -= piece->len;
if (uTextFormat & DT_RESIZE_SMILEYS && piece->smiley_height > text_height)
- factor = text_height / (double) piece->smiley_height;
+ factor = text_height / (double)piece->smiley_height;
else
factor = 1;
@@ -289,8 +266,7 @@ void DrawTextSmiley(HDC hdcMem, RECT free_rc, const TCHAR *szText, int len, SMIL text_rc.left = max(text_rc.right - (int)(piece->smiley_width * factor), text_rc.left);
pos_x += piece->smiley_width * factor;
- if (pos_x > (free_rc.right - free_rc.left))
- {
+ if (pos_x > (free_rc.right - free_rc.left)) {
pos_x = piece->smiley_width * factor;
text_rc.left = free_rc.left;
text_rc.right = free_rc.right;
@@ -305,7 +281,7 @@ void DrawTextSmiley(HDC hdcMem, RECT free_rc, const TCHAR *szText, int len, SMIL }
}
- RestoreAlpha(&free_rc);
+ RestoreAlpha(&free_rc, pBits);
}
void DestroySmileyList(SortedList* p_list)
@@ -313,14 +289,10 @@ void DestroySmileyList(SortedList* p_list) if (p_list == NULL)
return;
- if (p_list->items != NULL)
- {
- int i;
- for (i = 0 ; i < p_list->realCount ; i++)
- {
+ if (p_list->items != NULL) {
+ for (int i = 0; i < p_list->realCount; i++) {
TEXTPIECE *piece = (TEXTPIECE *)p_list->items[i];
- if (piece != NULL)
- {
+ if (piece != NULL) {
if (piece->type == TEXT_PIECE_TYPE_SMILEY)
DestroyIcon(piece->smiley);
@@ -332,7 +304,7 @@ void DestroySmileyList(SortedList* p_list) mir_free(p_list); //this free the p_list itself (alloc by List_Create)
}
-// Generete the list of smileys / text to be drawn
+// Generate the list of smileys / text to be drawn
SortedList *ReplaceSmileys(const TCHAR *text, int text_size, const char *protocol, int *max_smiley_height)
{
*max_smiley_height = 0;
@@ -349,7 +321,7 @@ SortedList *ReplaceSmileys(const TCHAR *text, int text_size, const char *protoco strncpy(smileyProto, protocol, sizeof(smileyProto) - 1);
// Parse it!
- SMADD_BATCHPARSE2 sp = {0};
+ SMADD_BATCHPARSE2 sp = { 0 };
sp.cbSize = sizeof(sp);
sp.str = (TCHAR *)text;
sp.flag = SAFL_TCHAR;
@@ -368,24 +340,21 @@ SortedList *ReplaceSmileys(const TCHAR *text, int text_size, const char *protoco word_start = word_end = (TCHAR *)text;
- for (unsigned i = 0; i < sp.numSmileys; i++)
- {
+ for (unsigned i = 0; i < sp.numSmileys; i++) {
// Get smile position
smiley_start = _tcsninc(text, spres[i].startChar);
smiley_end = _tcsninc(smiley_start, spres[i].size);
if (spres[i].hIcon) // For deffective smileypacks
{
- if (opt.iSmileyAddFlags & SMILEYADD_ONLYISOLATED)
- {
+ if (opt.iSmileyAddFlags & SMILEYADD_ONLYISOLATED) {
if ((smiley_start > text && *(smiley_start - 1) != ' ' && *(smiley_start - 1) != '\n' && *smiley_end != '\r') ||
(*smiley_end != '\0' && *smiley_end != ' ' && *smiley_end != '\n' && *smiley_end != '\r'))
continue;
}
// Add text
- while (word_end != smiley_start)
- {
+ while (word_end != smiley_start) {
while (word_end[0] != ' ' && word_end[0] != '\n')
word_end++;
@@ -394,8 +363,7 @@ SortedList *ReplaceSmileys(const TCHAR *text, int text_size, const char *protoco else
word_end++;
- if (word_end > word_start)
- {
+ if (word_end > word_start) {
TEXTPIECE *piece = (TEXTPIECE *)mir_calloc(sizeof(TEXTPIECE));
piece->type = TEXT_PIECE_TYPE_TEXT;
piece->start_pos = word_start - text;
@@ -406,48 +374,41 @@ SortedList *ReplaceSmileys(const TCHAR *text, int text_size, const char *protoco }
// Add smiley
- {
+ TEXTPIECE *piece = (TEXTPIECE *)mir_calloc(sizeof(TEXTPIECE));
+ piece->type = TEXT_PIECE_TYPE_SMILEY;
+ piece->len = spres[i].size;
+ piece->smiley = spres[i].hIcon;
+ piece->smiley_width = 16;
+ piece->smiley_height = 16;
+
+ ICONINFO icon;
+ if (GetIconInfo(piece->smiley, &icon)) {
BITMAP bm;
- ICONINFO icon;
- TEXTPIECE *piece = (TEXTPIECE *) mir_calloc(sizeof(TEXTPIECE));
-
- piece->type = TEXT_PIECE_TYPE_SMILEY;
- piece->len = spres[i].size;
- piece->smiley = spres[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);
+ if (GetObject(icon.hbmColor, sizeof(BITMAP), &bm)) {
+ piece->smiley_width = bm.bmWidth;
+ piece->smiley_height = bm.bmHeight;
}
- *max_smiley_height = max(piece->smiley_height, *max_smiley_height);
- List_Insert(plText, piece, plText->realCount);
+ DeleteObject(icon.hbmMask);
+ DeleteObject(icon.hbmColor);
}
+ *max_smiley_height = max(piece->smiley_height, *max_smiley_height);
+ List_Insert(plText, piece, plText->realCount);
+
word_start = word_end = smiley_end;
}
}
// Add rest of the text
- while (word_end != last_text_pos)
- {
+ while (word_end != last_text_pos) {
while (word_end[0] && word_end[0] != ' ' && word_end[0] != '\n')
word_end++;
if (word_end[0])
word_end++;
- if (word_end > word_start)
- {
+ if (word_end > word_start) {
TEXTPIECE *piece = (TEXTPIECE *)mir_calloc(sizeof(TEXTPIECE));
piece->type = TEXT_PIECE_TYPE_TEXT;
piece->start_pos = word_start - text;
|