diff options
-rw-r--r-- | Plugins/utils/mir_buffer.h | 4 | ||||
-rw-r--r-- | Plugins/utils/mir_icons.h | 2 | ||||
-rw-r--r-- | Plugins/utils/mir_log.cpp | 28 | ||||
-rw-r--r-- | Plugins/utils/mir_log.h | 53 | ||||
-rw-r--r-- | Plugins/utils/mir_memory.h | 45 | ||||
-rw-r--r-- | Plugins/utils/mir_options.cpp | 7 | ||||
-rw-r--r-- | Plugins/utils/mir_scope.h | 12 | ||||
-rw-r--r-- | Plugins/utils/mir_smileys.cpp | 479 | ||||
-rw-r--r-- | Plugins/utils/mir_smileys.h | 65 | ||||
-rw-r--r-- | Plugins/utils/scope.h | 37 | ||||
-rw-r--r-- | Plugins/utils/tstring.h | 14 | ||||
-rw-r--r-- | Plugins/utils/utf8_helpers.h | 386 |
12 files changed, 1101 insertions, 31 deletions
diff --git a/Plugins/utils/mir_buffer.h b/Plugins/utils/mir_buffer.h index 4a5f012..1161b23 100644 --- a/Plugins/utils/mir_buffer.h +++ b/Plugins/utils/mir_buffer.h @@ -128,7 +128,7 @@ class Buffer Buffer(T in) : str(NULL), size(0), len(0)
{
- if (in == NUL)
+ if (in == NULL)
{
alloc(1);
pack();
@@ -148,7 +148,7 @@ class Buffer void pack()
{
if (str != NULL)
- str[len] = 0;
+ memset(&str[len], 0, sizeof(str[len]));
}
void alloc(size_t total)
diff --git a/Plugins/utils/mir_icons.h b/Plugins/utils/mir_icons.h index c61c7c6..e5e0105 100644 --- a/Plugins/utils/mir_icons.h +++ b/Plugins/utils/mir_icons.h @@ -30,4 +30,4 @@ void ReleaseIconEx(HICON hIcon); -#endif // __MIR_MEMORY_H__
+#endif // __MIR_ICONS_H__
diff --git a/Plugins/utils/mir_log.cpp b/Plugins/utils/mir_log.cpp index b842bb1..c469c20 100644 --- a/Plugins/utils/mir_log.cpp +++ b/Plugins/utils/mir_log.cpp @@ -22,20 +22,23 @@ Boston, MA 02111-1307, USA. #include <stdio.h>
-extern "C"
-{
#include <newpluginapi.h>
#include <m_netlib.h>
#include <m_protocols.h>
#include <m_clist.h>
-}
+#define ENABLE_LOG
-int mlog(const char *module, const char *function, const char *fmt, ...)
+
+int MLog::deep = 0;
+
+
+
+
+int mlog(const char *module, const char *function, const char *fmt, va_list va)
{
#ifdef ENABLE_LOG
- va_list va;
char text[1024];
size_t len;
@@ -43,9 +46,7 @@ int mlog(const char *module, const char *function, const char *fmt, ...) GetCurrentThreadId(), GetTickCount(), module, function);
len = strlen(text);
- va_start(va, fmt);
mir_vsnprintf(&text[len], sizeof(text) - len, fmt, va);
- va_end(va);
#ifdef LOG_TO_NETLIB
@@ -77,6 +78,19 @@ int mlog(const char *module, const char *function, const char *fmt, ...) #endif
}
+
+int mlog(const char *module, const char *function, const char *fmt, ...)
+{
+ va_list va;
+ va_start(va, fmt);
+
+ int ret = mlog(module, function, fmt, va);
+
+ va_end(va);
+
+ return ret;
+}
+
int mlogC(const char *module, const char *function, HANDLE hContact, const char *fmt, ...)
{
#ifdef ENABLE_LOG
diff --git a/Plugins/utils/mir_log.h b/Plugins/utils/mir_log.h index 395c7e1..3ceca42 100644 --- a/Plugins/utils/mir_log.h +++ b/Plugins/utils/mir_log.h @@ -22,20 +22,59 @@ Boston, MA 02111-1307, USA. # define __LOG_H__
#include <windows.h>
+#include <string>
+
+
+int mlog(const char *module, const char *function, const char *fmt, ...);
+int mlog(const char *module, const char *function, const char *fmt, va_list va);
+int mlogC(const char *module, const char *function, HANDLE hContact, const char *fmt, ...);
+
#ifdef __cplusplus
-extern "C"
+
+class MLog
{
-#endif
+private:
+ std::string module;
+ std::string function;
+ static int deep;
-int mlog(const char *module, const char *function, const char *fmt, ...);
-int mlogC(const char *module, const char *function, HANDLE hContact, const char *fmt, ...);
+public:
+ MLog(const char *aModule, const char *aFunction) : module(aModule)
+ {
+ function = "";
+ for(int i = 0; i < deep; i++)
+ function += " ";
+ function += aFunction;
+ deep ++;
+
+ mlog(module.c_str(), function.c_str(), "BEGIN");
+ }
+
+ ~MLog()
+ {
+ mlog(module.c_str(), function.c_str(), "END");
+ deep --;
+ }
+
+ int log(const char *fmt, ...)
+ {
+ va_list va;
+ va_start(va, fmt);
+
+ int ret = mlog(module.c_str(), function.c_str(), fmt, va);
+
+ va_end(va);
+
+ return ret;
+ }
+};
+
+
+#endif __cplusplus
-#ifdef __cplusplus
-}
-#endif
#endif // __LOG_H__
diff --git a/Plugins/utils/mir_memory.h b/Plugins/utils/mir_memory.h index 52440ae..b3f32fc 100644 --- a/Plugins/utils/mir_memory.h +++ b/Plugins/utils/mir_memory.h @@ -21,19 +21,52 @@ Boston, MA 02111-1307, USA. #ifndef __MIR_MEMORY_H__
# define __MIR_MEMORY_H__
+
#include <windows.h>
-// Need to be called on ME_SYSTEM_MODULESLOADED or Load
-void init_mir_malloc();
+static BOOL mir_is_unicode()
+{
+ char ver[1024];
+ CallService(MS_SYSTEM_GETVERSIONTEXT, (WPARAM) sizeof(ver), (LPARAM) ver);
+ return strstr(ver, "Unicode") != NULL;
+}
+
+
+static void * mir_alloc0(size_t size)
+{
+ void * ptr = mir_alloc(size);
+
+ if (ptr != NULL)
+ memset(ptr, 0, size);
+
+ return ptr;
+}
+
+static int strcmpnull(char *str1, char *str2)
+{
+ if ( str1 == NULL && str2 == NULL )
+ return 0;
+ if ( str1 != NULL && str2 == NULL )
+ return 1;
+ if ( str1 == NULL && str2 != NULL )
+ return -1;
-BOOL mir_is_unicode();
+ return strcmp(str1, str2);
+}
+static int strcmpnullW(WCHAR *str1, WCHAR *str2)
+{
+ if ( str1 == NULL && str2 == NULL )
+ return 0;
+ if ( str1 != NULL && str2 == NULL )
+ return 1;
+ if ( str1 == NULL && str2 != NULL )
+ return -1;
-void * mir_alloc0(size_t size);
-int strcmpnull(char *str1, char *str2);
-int strcmpnullW(WCHAR *str1, WCHAR *str2);
+ return lstrcmpW(str1, str2);
+}
#ifdef UNICODE
diff --git a/Plugins/utils/mir_options.cpp b/Plugins/utils/mir_options.cpp index 2d0c45d..f9a6e1c 100644 --- a/Plugins/utils/mir_options.cpp +++ b/Plugins/utils/mir_options.cpp @@ -18,9 +18,7 @@ Boston, MA 02111-1307, USA. */
-#include "mir_options.h"
-#include "mir_memory.h"
-
+#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include <tchar.h>
@@ -34,6 +32,9 @@ Boston, MA 02111-1307, USA. #include <m_protosvc.h>
#include <m_system.h>
+#include "mir_options.h"
+#include "mir_memory.h"
+
#define MAX_REGS(_A_) ( sizeof(_A_) / sizeof(_A_[0]) )
diff --git a/Plugins/utils/mir_scope.h b/Plugins/utils/mir_scope.h index a18bf55..31edde0 100644 --- a/Plugins/utils/mir_scope.h +++ b/Plugins/utils/mir_scope.h @@ -3,20 +3,22 @@ template<class T>
-class scope
+class mir_scope
{
public:
- scope(T t) : p(t) {}
- ~scope() { free(); }
+ mir_scope() : p(NULL) {}
+ mir_scope(T t) : p(t) {}
+ ~mir_scope() { release(); }
- void free()
+ void release()
{
if (p != NULL)
mir_free(p);
p = NULL;
}
-// T operator->() const { return p; }
+ T operator=(T t) { release(); p = t; return t; }
+ T operator->() const { return p; }
operator T() const { return p; }
T detach()
diff --git a/Plugins/utils/mir_smileys.cpp b/Plugins/utils/mir_smileys.cpp new file mode 100644 index 0000000..067b2b5 --- /dev/null +++ b/Plugins/utils/mir_smileys.cpp @@ -0,0 +1,479 @@ +/*
+Copyright (C) 2005 Ricardo Pescuma Domenecci
+
+This is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+This is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with this file; see the file license.txt. If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.
+*/
+
+
+#include "mir_smileys.h"
+#include "mir_memory.h"
+
+#include <richedit.h>
+#include <m_smileyadd.h>
+#include <newpluginapi.h>
+#include <m_langpack.h>
+#include <tchar.h>
+
+
+
+// Prototypes
+
+#define TEXT_PIECE_TYPE_TEXT 0
+#define TEXT_PIECE_TYPE_SMILEY 1
+typedef struct
+{
+ int type;
+ int len;
+ union
+ {
+ struct
+ {
+ int start_pos;
+ };
+ struct
+ {
+ HICON smiley;
+ int smiley_width;
+ int smiley_height;
+ };
+ };
+} TextPiece;
+
+
+
+SortedList * ReplaceSmileys(const char *text, int text_size, const char *protocol, int *max_smiley_height);
+void DrawTextSmiley(HDC hdcMem, RECT free_rc, const char *szText, int len, SortedList *plText, UINT uTextFormat, int max_smiley_height);
+void DestroySmileyList( SortedList* p_list );
+SIZE GetTextSize(HDC hdcMem, const char *szText, SortedList *plText, UINT uTextFormat, int max_smiley_height);
+
+
+
+// Functions
+
+int InitContactListSmileys()
+{
+ // Register smiley category
+ if (ServiceExists(MS_SMILEYADD_REGISTERCATEGORY))
+ {
+ SMADD_REGCAT rc;
+
+ rc.cbSize = sizeof(rc);
+ rc.name = "clist";
+ rc.dispname = Translate("Contact List smileys");
+
+ CallService(MS_SMILEYADD_REGISTERCATEGORY, 0, (LPARAM)&rc);
+ }
+
+ return 0;
+}
+
+SmileysParseInfo Smileys_PreParse(LPCSTR lpString, int nCount, const char *protocol)
+{
+ SmileysParseInfo info = (SmileysParseInfo) mir_alloc0(sizeof(_SmileysParseInfo));
+
+ info->pieces = ReplaceSmileys(lpString, nCount, protocol, &info->max_height);
+
+ return info;
+}
+
+void Smileys_FreeParse(SmileysParseInfo parseInfo)
+{
+ if (parseInfo != NULL)
+ {
+ if (parseInfo->pieces != NULL)
+ DestroySmileyList(parseInfo->pieces);
+
+ mir_free(parseInfo);
+ }
+}
+
+// Similar to DrawText win32 api function
+// Pass uFormat | DT_CALCRECT to calc rectangle to be returned by lpRect
+// parseInfo is optional (pass NULL and it will be calculated and deleted inside function
+int Smileys_DrawText(HDC hDC, LPCSTR lpString, int nCount, LPRECT lpRect, UINT uFormat, const char *protocol, SmileysParseInfo parseInfo)
+{
+ SmileysParseInfo info;
+ int ret;
+
+ // Get parse info
+ if (parseInfo == NULL)
+ info = Smileys_PreParse(lpString, nCount, protocol);
+ else
+ info = parseInfo;
+
+ if (uFormat & DT_CALCRECT)
+ {
+ SIZE text_size = GetTextSize(hDC, lpString, info->pieces, uFormat, info->max_height);
+
+ lpRect->bottom = min(lpRect->bottom, lpRect->top + text_size.cy);
+
+ if (text_size.cx < lpRect->right - lpRect->left)
+ {
+ if (uFormat & DT_RIGHT)
+ lpRect->left = lpRect->right - text_size.cx;
+ else
+ lpRect->right = lpRect->left + text_size.cx;
+ }
+
+ ret = text_size.cy;
+ }
+ else
+ {
+ // Clipping rgn
+ HRGN oldRgn = CreateRectRgn(0,0,1,1);
+ if (GetClipRgn(hDC, oldRgn) != 1)
+ {
+ DeleteObject(oldRgn);
+ oldRgn = NULL;
+ }
+
+ HRGN rgn = CreateRectRgnIndirect(lpRect);
+ ExtSelectClipRgn(hDC, rgn, RGN_AND);
+
+ // Draw
+ if (info->pieces == NULL)
+ {
+ ret = DrawText(hDC, lpString, nCount, lpRect, uFormat);
+ }
+ else
+ {
+ RECT rc = *lpRect;
+
+ SIZE text_size = GetTextSize(hDC, lpString, info->pieces, uFormat, info->max_height);
+
+ if (text_size.cx < rc.right - rc.left)
+ {
+ if (uFormat & DT_RIGHT)
+ rc.left = rc.right - text_size.cx;
+ else
+ rc.right = rc.left + text_size.cx;
+ }
+
+ ret = text_size.cy;
+
+ DrawTextSmiley(hDC, rc, lpString, nCount, info->pieces, uFormat, info->max_height);
+ }
+
+ // Clipping rgn
+ SelectClipRgn(hDC, oldRgn);
+ DeleteObject(rgn);
+ if (oldRgn) DeleteObject(oldRgn);
+ }
+
+
+ // Free parse info
+ if (parseInfo == NULL)
+ Smileys_FreeParse(info);
+
+ return ret;
+}
+
+
+
+SIZE GetTextSize(HDC hdcMem, const char *szText, SortedList *plText, UINT uTextFormat, int max_smiley_height)
+{
+ SIZE text_size;
+
+ if (szText == NULL)
+ {
+ text_size.cy = 0;
+ text_size.cx = 0;
+ }
+ else
+ {
+ RECT text_rc = {0, 0, 0x7FFFFFFF, 0x7FFFFFFF};
+
+ // Always need cy...
+ DrawText(hdcMem,szText,lstrlen(szText), &text_rc, DT_CALCRECT | uTextFormat);
+ text_size.cy = text_rc.bottom - text_rc.top;
+
+ if (plText == NULL)
+ {
+ text_size.cx = text_rc.right - text_rc.left;
+ }
+ else
+ {
+ if (!(uTextFormat & DT_RESIZE_SMILEYS))
+ text_size.cy = max(text_size.cy, max_smiley_height);
+
+ text_size.cx = 0;
+
+ // See each item of list
+ for (int i = 0; i < plText->realCount; i++)
+ {
+ TextPiece *piece = (TextPiece *) plText->items[i];
+
+ if (piece->type == TEXT_PIECE_TYPE_TEXT)
+ {
+ RECT text_rc = {0, 0, 0x7FFFFFFF, 0x7FFFFFFF};
+
+ DrawText(hdcMem, &szText[piece->start_pos], piece->len, &text_rc, DT_CALCRECT | uTextFormat);
+ text_size.cx = text_size.cx + text_rc.right - text_rc.left;
+ }
+ else
+ {
+ double factor;
+
+ if ((uTextFormat & DT_RESIZE_SMILEYS) && piece->smiley_height > text_size.cy)
+ {
+ factor = text_size.cy / (double) piece->smiley_height;
+ }
+ else
+ {
+ factor = 1;
+ }
+
+ text_size.cx = text_size.cx + (LONG)(factor * piece->smiley_width);
+ }
+ }
+ }
+ }
+
+ return text_size;
+}
+
+void DrawTextSmiley(HDC hdcMem, RECT free_rc, const char *szText, int len, SortedList *plText, UINT uTextFormat, int max_smiley_height)
+{
+ if (szText == NULL)
+ {
+ return;
+ }
+
+ uTextFormat &= ~DT_RIGHT;
+
+ // Draw list
+ int i;
+ int pos_x = 0;
+ int row_height, text_height;
+ RECT tmp_rc = free_rc;
+
+ if (uTextFormat & DT_RTLREADING)
+ i = plText->realCount - 1;
+ else
+ i = 0;
+
+ // Get real height of the line
+ text_height = DrawText(hdcMem, "A", 1, &tmp_rc, DT_CALCRECT | uTextFormat);
+ if (uTextFormat & DT_RESIZE_SMILEYS)
+ row_height = text_height;
+ else
+ row_height = max(text_height, max_smiley_height);
+
+ // Just draw ellipsis
+ if (free_rc.right <= free_rc.left)
+ {
+ DrawText(hdcMem, "...", 3, &free_rc, uTextFormat & ~DT_END_ELLIPSIS);
+ }
+ else
+ {
+ // Draw text and smileys
+ for (; i < plText->realCount && i >= 0 && pos_x < free_rc.right - free_rc.left && len > 0; i += (uTextFormat & DT_RTLREADING ? -1 : 1))
+ {
+ TextPiece *piece = (TextPiece *) plText->items[i];
+ RECT text_rc = free_rc;
+
+ if (uTextFormat & DT_RTLREADING)
+ text_rc.right -= pos_x;
+ else
+ text_rc.left += pos_x;
+
+ if (piece->type == TEXT_PIECE_TYPE_TEXT)
+ {
+ text_rc.top += (row_height - text_height) >> 1;
+
+ tmp_rc = text_rc;
+ tmp_rc.right += 50;
+ 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 (uTextFormat & DT_RTLREADING)
+ text_rc.left = max(text_rc.left, text_rc.right - (tmp_rc.right - tmp_rc.left));
+
+ DrawText(hdcMem, &szText[piece->start_pos], min(len, piece->len), &text_rc, uTextFormat);
+ len -= piece->len;
+ }
+ else
+ {
+ double factor;
+
+ if (len < piece->len)
+ {
+ len = 0;
+ }
+ else
+ {
+ len -= piece->len;
+
+ if ((uTextFormat & DT_RESIZE_SMILEYS) && piece->smiley_height > row_height)
+ {
+ factor = row_height / (double) piece->smiley_height;
+ }
+ else
+ {
+ factor = 1;
+ }
+
+ if (uTextFormat & DT_RTLREADING)
+ text_rc.left = max(text_rc.right - (LONG) (piece->smiley_width * factor), text_rc.left);
+
+ if ((LONG)(piece->smiley_width * factor) <= text_rc.right - text_rc.left)
+ {
+ text_rc.top += (row_height - (LONG)(piece->smiley_height * factor)) >> 1;
+
+ DrawIconEx(hdcMem, text_rc.left, text_rc.top, piece->smiley,
+ (LONG)(piece->smiley_width * factor), (LONG)(piece->smiley_height * factor), 0, NULL, DI_NORMAL);
+ }
+ else
+ {
+ text_rc.top += (row_height - text_height) >> 1;
+ DrawText(hdcMem, "...", 3, &text_rc, uTextFormat);
+ }
+
+ pos_x += (LONG)(piece->smiley_width * factor);
+ }
+ }
+ }
+ }
+}
+
+
+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++ )
+ {
+ TextPiece *piece = (TextPiece *) p_list->items[i];
+
+ if ( piece != NULL )
+ {
+ if (piece->type == TEXT_PIECE_TYPE_SMILEY)
+ DestroyIcon(piece->smiley);
+
+ mir_free(piece);
+ }
+ }
+ }
+
+ List_Destroy( p_list );
+}
+
+
+
+// Generete the list of smileys / text to be drawn
+SortedList * ReplaceSmileys(const char *text, int text_size, const char *protocol, int *max_smiley_height)
+{
+ SMADD_BATCHPARSE2 sp = {0};
+ SMADD_BATCHPARSERES *spres;
+
+ *max_smiley_height = 0;
+
+ if (text[0] == '\0' || !ServiceExists(MS_SMILEYADD_BATCHPARSE))
+ {
+ return NULL;
+ }
+
+ // Parse it!
+ sp.cbSize = sizeof(sp);
+ sp.Protocolname = protocol;
+ sp.str = (char *)text;
+ sp.oflag = SAFL_TCHAR;
+ spres = (SMADD_BATCHPARSERES *) CallService(MS_SMILEYADD_BATCHPARSE, 0, (LPARAM)&sp);
+
+ if (spres == NULL)
+ {
+ // Did not find a simley
+ return NULL;
+ }
+
+ // Lets add smileys
+ SortedList *plText = List_Create(0, 10);
+
+ const char *next_text_pos = text;
+ const char *last_text_pos = _tcsninc(text, text_size);
+
+ for (unsigned int i = 0; i < sp.numSmileys; i++)
+ {
+ char * start = _tcsninc(text, spres[i].startChar);
+ char * end = _tcsninc(start, spres[i].size);
+
+ if (spres[i].hIcon != NULL) // For deffective smileypacks
+ {
+ // Add text
+ if (start > next_text_pos)
+ {
+ TextPiece *piece = (TextPiece *) mir_alloc0(sizeof(TextPiece));
+
+ piece->type = TEXT_PIECE_TYPE_TEXT;
+ piece->start_pos = next_text_pos - text;
+ piece->len = start - next_text_pos;
+
+ List_Append(plText, piece);
+ }
+
+ // Add smiley
+ {
+ BITMAP bm;
+ ICONINFO icon;
+ TextPiece *piece = (TextPiece *) mir_alloc0(sizeof(TextPiece));
+
+ piece->type = TEXT_PIECE_TYPE_SMILEY;
+ piece->len = end - start;
+ 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);
+ }
+
+ *max_smiley_height = max(piece->smiley_height, *max_smiley_height);
+
+ List_Append(plText, piece);
+ }
+
+ next_text_pos = end;
+ }
+ }
+
+ // Add rest of text
+ if (last_text_pos > next_text_pos)
+ {
+ TextPiece *piece = (TextPiece *) mir_alloc0(sizeof(TextPiece));
+
+ piece->type = TEXT_PIECE_TYPE_TEXT;
+ piece->start_pos = next_text_pos - text;
+ piece->len = last_text_pos - next_text_pos;
+
+ List_Append(plText, piece);
+ }
+
+ CallService(MS_SMILEYADD_BATCHFREE, 0, (LPARAM)spres);
+
+ return plText;
+}
diff --git a/Plugins/utils/mir_smileys.h b/Plugins/utils/mir_smileys.h new file mode 100644 index 0000000..fe9997b --- /dev/null +++ b/Plugins/utils/mir_smileys.h @@ -0,0 +1,65 @@ +/*
+Copyright (C) 2005 Ricardo Pescuma Domenecci
+
+This is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+This is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with this file; see the file license.txt. If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.
+*/
+
+
+#ifndef __MIR_SMILEYS_H__
+# define __MIR_SMILEYS_H__
+
+#include <windows.h>
+
+
+/*
+To use this files mir_dblists.h/.c are needed
+*/
+#include "mir_dblists.h"
+
+
+// Init settings needed to draw smileys using the contact list itens
+// To use then, pass "clist" as the protocol name
+// Need to be called on ME_SYSTEM_MODULESLOADED
+int InitContactListSmileys();
+
+
+// Pre-parse smileys
+typedef struct _SmileysParseInfo
+{
+ SortedList *pieces;
+ int max_height;
+} * SmileysParseInfo;
+
+SmileysParseInfo Smileys_PreParse(LPCSTR lpString, int nCount, const char *protocol);
+void Smileys_FreeParse(SmileysParseInfo parseInfo);
+
+// TODO:
+// SmileysParseInfo Smileys_PreParseW(HDC hDC, LPCWSTR lpString, int nCount, const char *protocol);
+
+
+#define DT_RESIZE_SMILEYS 0x10000000
+
+// Similar to DrawText win32 api function
+// Pass uFormat | DT_CALCRECT to calc rectangle to be returned by lpRect
+// parseInfo is optional (pass NULL and it will be calculated and deleted inside function)
+int Smileys_DrawText(HDC hDC, LPCSTR lpString, int nCount, LPRECT lpRect, UINT uFormat, const char *protocol, SmileysParseInfo parseInfo);
+
+// TODO:
+// int Smileys_DrawTextW(HDC hDC, LPCWSTR lpString, int nCount, LPRECT lpRect, UINT uFormat, const char *protocol, SmileysParseInfo parseInfo);
+
+
+
+#endif // __MIR_SMILEYS_H__
diff --git a/Plugins/utils/scope.h b/Plugins/utils/scope.h new file mode 100644 index 0000000..2fad797 --- /dev/null +++ b/Plugins/utils/scope.h @@ -0,0 +1,37 @@ +#ifndef __PTR_H__
+# define __PTR_H__
+
+
+template<class T>
+class scope
+{
+public:
+ scope() : p(NULL) {}
+ scope(T t) : p(t) {}
+ ~scope() { release(); }
+
+ void release()
+ {
+ if (p != NULL)
+ delete p;
+ p = NULL;
+ }
+
+ T operator=(T t) { release(); p = t; return t; }
+ T operator->() const { return p; }
+ operator T() const { return p; }
+
+ T detach()
+ {
+ T ret = p;
+ p = NULL;
+ return ret;
+ }
+
+private:
+ T p;
+};
+
+
+
+#endif // __PTR_H__
diff --git a/Plugins/utils/tstring.h b/Plugins/utils/tstring.h new file mode 100644 index 0000000..fb340bc --- /dev/null +++ b/Plugins/utils/tstring.h @@ -0,0 +1,14 @@ +#ifndef __TSTRING_H__
+# define __TSTRING_H__
+
+#include <windows.h>
+#include <tchar.h>
+#include <string>
+
+
+namespace std {
+ typedef basic_string<TCHAR, char_traits<TCHAR>, allocator<TCHAR> > tstring;
+}
+
+
+#endif // __TSTRING_H__
diff --git a/Plugins/utils/utf8_helpers.h b/Plugins/utils/utf8_helpers.h new file mode 100644 index 0000000..2b08630 --- /dev/null +++ b/Plugins/utils/utf8_helpers.h @@ -0,0 +1,386 @@ +#ifndef __UTF8_HELPERS_H__
+# define __UTF8_HELPERS_H__
+
+#include <windows.h>
+#include <newpluginapi.h>
+#include <m_system.h>
+
+
+class TcharToUtf8
+{
+public:
+ TcharToUtf8(const char *str) : utf8(NULL)
+ {
+ int size = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
+ if (size <= 0)
+ throw _T("Could not convert string to WCHAR");
+
+ WCHAR *tmp = (WCHAR *) mir_alloc(size * sizeof(WCHAR));
+ if (tmp == NULL)
+ throw _T("mir_alloc returned NULL");
+
+ MultiByteToWideChar(CP_ACP, 0, str, -1, tmp, size);
+
+ init(tmp);
+
+ mir_free(tmp);
+ }
+
+
+ TcharToUtf8(const WCHAR *str) : utf8(NULL)
+ {
+ init(str);
+ }
+
+
+ ~TcharToUtf8()
+ {
+ if (utf8 != NULL)
+ mir_free(utf8);
+ }
+
+ operator char *()
+ {
+ return utf8;
+ }
+
+private:
+ char *utf8;
+
+ void init(const WCHAR *str)
+ {
+ int size = WideCharToMultiByte(CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL);
+ if (size <= 0)
+ throw _T("Could not convert string to UTF8");
+
+ utf8 = (char *) mir_alloc(size);
+ if (utf8 == NULL)
+ throw _T("mir_alloc returned NULL");
+
+ WideCharToMultiByte(CP_UTF8, 0, str, -1, utf8, size, NULL, NULL);
+ }
+};
+
+
+
+class Utf8ToTchar
+{
+public:
+ Utf8ToTchar(const char *str) : tchar(NULL)
+ {
+ if (str == NULL)
+ return;
+
+ int size = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
+ if (size <= 0)
+ throw _T("Could not convert string to WCHAR");
+
+ WCHAR *tmp = (WCHAR *) mir_alloc(size * sizeof(WCHAR));
+ if (tmp == NULL)
+ throw _T("mir_alloc returned NULL");
+
+ MultiByteToWideChar(CP_UTF8, 0, str, -1, tmp, size);
+
+#ifdef UNICODE
+
+ tchar = tmp;
+
+#else
+
+ size = WideCharToMultiByte(CP_ACP, 0, tmp, -1, NULL, 0, NULL, NULL);
+ if (size <= 0)
+ {
+ mir_free(tmp);
+ throw _T("Could not convert string to ACP");
+ }
+
+ tchar = (TCHAR *) mir_alloc(size * sizeof(char));
+ if (tchar == NULL)
+ {
+ mir_free(tmp);
+ throw _T("mir_alloc returned NULL");
+ }
+
+ WideCharToMultiByte(CP_ACP, 0, tmp, -1, tchar, size, NULL, NULL);
+
+ mir_free(tmp);
+
+#endif
+ }
+
+ ~Utf8ToTchar()
+ {
+ if (tchar != NULL)
+ mir_free(tchar);
+ }
+
+ TCHAR *detach()
+ {
+ TCHAR *ret = tchar;
+ tchar = NULL;
+ return ret;
+ }
+
+ operator TCHAR *()
+ {
+ return tchar;
+ }
+
+private:
+ TCHAR *tchar;
+};
+
+
+class CharToTchar
+{
+public:
+ CharToTchar(const char *str) : tchar(NULL)
+ {
+ if (str == NULL)
+ return;
+
+#ifdef UNICODE
+
+ int size = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
+ if (size <= 0)
+ throw _T("Could not convert string to WCHAR");
+
+ WCHAR *tmp = (WCHAR *) mir_alloc(size * sizeof(WCHAR));
+ if (tmp == NULL)
+ throw _T("mir_alloc returned NULL");
+
+ MultiByteToWideChar(CP_UTF8, 0, str, -1, tmp, size);
+
+ tchar = tmp;
+
+#else
+
+ tchar = str;
+
+#endif
+ }
+
+
+ ~CharToTchar()
+ {
+#ifdef UNICODE
+ if (tchar != NULL)
+ mir_free(tchar);
+#endif
+ }
+
+ TCHAR *detach()
+ {
+#ifdef UNICODE
+ TCHAR *ret = tchar;
+#else
+ TCHAR *ret = (tchar == NULL ? NULL : mir_strdup(tchar));
+#endif
+
+ tchar = NULL;
+ return ret;
+ }
+
+ operator const TCHAR *()
+ {
+ return tchar;
+ }
+
+private:
+#ifdef UNICODE
+ TCHAR *tchar;
+#else
+ const TCHAR *tchar;
+#endif
+};
+
+
+class WcharToTchar
+{
+public:
+ WcharToTchar(const WCHAR *str) : tchar(NULL)
+ {
+ if (str == NULL)
+ return;
+
+#ifdef UNICODE
+
+ tchar = str;
+
+#else
+
+ int size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
+ if (size <= 0)
+ throw _T("Could not convert string to ACP");
+
+ tchar = (TCHAR *) mir_alloc(size);
+ if (tchar == NULL)
+ throw _T("mir_alloc returned NULL");
+
+ WideCharToMultiByte(CP_ACP, 0, str, -1, tchar, size, NULL, NULL);
+
+#endif
+ }
+
+
+ ~WcharToTchar()
+ {
+#ifndef UNICODE
+ if (tchar != NULL)
+ mir_free(tchar);
+#endif
+ }
+
+ TCHAR *detach()
+ {
+#ifdef UNICODE
+ TCHAR *ret = (tchar == NULL ? NULL : mir_wstrdup(tchar));
+#else
+ TCHAR *ret = tchar;
+#endif
+
+ tchar = NULL;
+ return ret;
+ }
+
+ operator const TCHAR *()
+ {
+ return tchar;
+ }
+
+private:
+#ifdef UNICODE
+ const TCHAR *tchar;
+#else
+ TCHAR *tchar;
+#endif
+};
+
+
+
+
+class TcharToChar
+{
+public:
+ TcharToChar(const TCHAR *str) : val(NULL)
+ {
+ if (str == NULL)
+ return;
+
+#ifdef UNICODE
+
+ int size = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
+ if (size <= 0)
+ throw _T("Could not convert string to ACP");
+
+ val = (char *) mir_alloc(size);
+ if (val == NULL)
+ throw _T("mir_alloc returned NULL");
+
+ WideCharToMultiByte(CP_ACP, 0, str, -1, val, size, NULL, NULL);
+
+#else
+
+ val = str;
+
+#endif
+ }
+
+
+ ~TcharToChar()
+ {
+#ifdef UNICODE
+ if (val != NULL)
+ mir_free(val);
+#endif
+ }
+
+ char *detach()
+ {
+#ifdef UNICODE
+ char *ret = val;
+#else
+ char *ret = (val == NULL ? NULL : mir_strdup(val));
+#endif
+
+ val = NULL;
+ return ret;
+ }
+
+ operator const char *()
+ {
+ return val;
+ }
+
+private:
+#ifdef UNICODE
+ char *val;
+#else
+ const char *val;
+#endif
+};
+
+
+class TcharToWchar
+{
+public:
+ TcharToWchar(const TCHAR *str) : val(NULL)
+ {
+ if (str == NULL)
+ return;
+
+#ifdef UNICODE
+
+ val = str;
+
+#else
+
+ int size = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
+ if (size <= 0)
+ throw _T("Could not convert string to WCHAR");
+
+ val = (WCHAR *) mir_alloc(size * sizeof(WCHAR));
+ if (val == NULL)
+ throw _T("mir_alloc returned NULL");
+
+ MultiByteToWideChar(CP_UTF8, 0, str, -1, val, size);
+
+#endif
+ }
+
+
+ ~TcharToWchar()
+ {
+#ifndef UNICODE
+ if (val != NULL)
+ mir_free(val);
+#endif
+ }
+
+ WCHAR *detach()
+ {
+#ifdef UNICODE
+ WCHAR *ret = (val == NULL ? NULL : mir_wstrdup(val));
+#else
+ WCHAR *ret = val;
+#endif
+
+ val = NULL;
+ return ret;
+ }
+
+ operator const WCHAR *()
+ {
+ return val;
+ }
+
+private:
+#ifdef UNICODE
+ const WCHAR *val;
+#else
+ WCHAR *val;
+#endif
+};
+
+
+#endif // __UTF8_HELPERS_H__
|