diff options
author | pescuma <pescuma@c086bb3d-8645-0410-b8da-73a8550f86e7> | 2009-05-02 00:08:17 +0000 |
---|---|---|
committer | pescuma <pescuma@c086bb3d-8645-0410-b8da-73a8550f86e7> | 2009-05-02 00:08:17 +0000 |
commit | 7c52bd0b47d68806777152e097f1bf6f3f718170 (patch) | |
tree | 2b8bb05622141f9dff4a4fe1b53196b9860c2f1c | |
parent | 74de73a0d9a2a40ed77ac2ee6a2714ceb7c633b0 (diff) |
utils: sync with berliOS
git-svn-id: http://pescuma.googlecode.com/svn/trunk/Miranda@174 c086bb3d-8645-0410-b8da-73a8550f86e7
-rw-r--r-- | Plugins/utils/ContactAsyncQueue.cpp | 2 | ||||
-rw-r--r-- | Plugins/utils/ContactAsyncQueue.h | 2 | ||||
-rw-r--r-- | Plugins/utils/mir_buffer.h | 2 | ||||
-rw-r--r-- | Plugins/utils/mir_icons.cpp | 41 | ||||
-rw-r--r-- | Plugins/utils/mir_icons.h | 6 | ||||
-rw-r--r-- | Plugins/utils/mir_memory.cpp | 78 | ||||
-rw-r--r-- | Plugins/utils/mir_memory.h | 37 | ||||
-rw-r--r-- | Plugins/utils/mir_options.cpp | 47 | ||||
-rw-r--r-- | Plugins/utils/mir_options.h | 2 | ||||
-rw-r--r-- | Plugins/utils/mir_scope.h | 12 | ||||
-rw-r--r-- | Plugins/utils/mir_smileys.cpp | 3 | ||||
-rw-r--r-- | Plugins/utils/utf8_helpers.h | 180 |
12 files changed, 241 insertions, 171 deletions
diff --git a/Plugins/utils/ContactAsyncQueue.cpp b/Plugins/utils/ContactAsyncQueue.cpp index 9ea2682..2d5d1f1 100644 --- a/Plugins/utils/ContactAsyncQueue.cpp +++ b/Plugins/utils/ContactAsyncQueue.cpp @@ -1,5 +1,5 @@ /*
-Copyright (C) 2006 Ricardo Pescuma Domenecci
+Copyright (C) 2006-2009 Ricardo Pescuma Domenecci
This is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
diff --git a/Plugins/utils/ContactAsyncQueue.h b/Plugins/utils/ContactAsyncQueue.h index fe1032f..f329769 100644 --- a/Plugins/utils/ContactAsyncQueue.h +++ b/Plugins/utils/ContactAsyncQueue.h @@ -1,5 +1,5 @@ /*
-Copyright (C) 2006 Ricardo Pescuma Domenecci
+Copyright (C) 2006-2009 Ricardo Pescuma Domenecci
This is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
diff --git a/Plugins/utils/mir_buffer.h b/Plugins/utils/mir_buffer.h index 1161b23..3268f45 100644 --- a/Plugins/utils/mir_buffer.h +++ b/Plugins/utils/mir_buffer.h @@ -1,5 +1,5 @@ /*
-Copyright (C) 2005 Ricardo Pescuma Domenecci
+Copyright (C) 2005-2009 Ricardo Pescuma Domenecci
This is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
diff --git a/Plugins/utils/mir_icons.cpp b/Plugins/utils/mir_icons.cpp index 1ee7999..a0d4939 100644 --- a/Plugins/utils/mir_icons.cpp +++ b/Plugins/utils/mir_icons.cpp @@ -24,14 +24,20 @@ Boston, MA 02111-1307, USA. #include <m_system.h>
#include <m_icolib.h>
+extern HINSTANCE hInst;
-HICON LoadIconEx(const char *iconName, BOOL copy)
+
+
+HICON IcoLib_LoadIcon(const char *iconName, BOOL copy)
{
if (!ServiceExists(MS_SKIN2_GETICON))
return NULL;
+
+ if (iconName == NULL || iconName[0] == 0)
+ return NULL;
HICON hIcon = (HICON) CallService(MS_SKIN2_GETICON, 0, (LPARAM) iconName);
- if (copy)
+ if (copy && hIcon != NULL)
{
hIcon = CopyIcon(hIcon);
CallService(MS_SKIN2_RELEASEICON, 0, (LPARAM) iconName);
@@ -40,10 +46,35 @@ HICON LoadIconEx(const char *iconName, BOOL copy) }
-void ReleaseIconEx(HICON hIcon)
+void IcoLib_ReleaseIcon(HICON hIcon)
{
if (ServiceExists(MS_SKIN2_RELEASEICON))
CallService(MS_SKIN2_RELEASEICON, (WPARAM) hIcon, 0);
- else
- DestroyIcon(hIcon);
}
+
+
+void IcoLib_Register(char *name, TCHAR *section, TCHAR *description, int id)
+{
+ HICON hIcon = (HICON) CallService(MS_SKIN2_GETICON, 0, (LPARAM) name);
+ if (hIcon != NULL)
+ {
+ CallService(MS_SKIN2_RELEASEICON, (WPARAM) hIcon, 0);
+ return;
+ }
+
+ SKINICONDESC sid = {0};
+ sid.cbSize = sizeof(SKINICONDESC);
+ sid.flags = SIDF_TCHAR;
+ sid.pszName = name;
+ sid.ptszSection = section;
+ sid.ptszDescription = description;
+
+ int cx = GetSystemMetrics(SM_CXSMICON);
+ sid.hDefaultIcon = (HICON) LoadImage(hInst, MAKEINTRESOURCE(id), IMAGE_ICON, cx, cx, LR_DEFAULTCOLOR | LR_SHARED);
+
+ CallService(MS_SKIN2_ADDICON, 0, (LPARAM)&sid);
+
+ if (sid.hDefaultIcon)
+ DestroyIcon(sid.hDefaultIcon);
+}
+
diff --git a/Plugins/utils/mir_icons.h b/Plugins/utils/mir_icons.h index e5e0105..a6fcb53 100644 --- a/Plugins/utils/mir_icons.h +++ b/Plugins/utils/mir_icons.h @@ -24,8 +24,10 @@ Boston, MA 02111-1307, USA. #include <windows.h>
-HICON LoadIconEx(const char *iconName, BOOL copy = FALSE);
-void ReleaseIconEx(HICON hIcon);
+void IcoLib_Register(char *name, TCHAR *section, TCHAR *description, int id);
+
+HICON IcoLib_LoadIcon(const char *iconName, BOOL copy = FALSE);
+void IcoLib_ReleaseIcon(HICON hIcon);
diff --git a/Plugins/utils/mir_memory.cpp b/Plugins/utils/mir_memory.cpp deleted file mode 100644 index 615f3dc..0000000 --- a/Plugins/utils/mir_memory.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/*
-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.
-*/
-
-
-#define MIRANDA_VER 0x0700
-#include "mir_memory.h"
-
-#include <newpluginapi.h>
-#include <m_system.h>
-
-
-struct MM_INTERFACE mmi;
-struct UTF8_INTERFACE utfi;
-
-void init_mir_malloc()
-{
- mir_getMMI(&mmi);
- mir_getUTFI(&utfi);
-}
-
-
-BOOL mir_is_unicode()
-{
- char ver[1024];
- CallService(MS_SYSTEM_GETVERSIONTEXT, (WPARAM) sizeof(ver), (LPARAM) ver);
- return strstr(ver, "Unicode") != NULL;
-}
-
-
-void * mir_alloc0(size_t size)
-{
- void * ptr = mir_alloc(size);
-
- if (ptr != NULL)
- memset(ptr, 0, size);
-
- return ptr;
-}
-
-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;
-
- return strcmp(str1, str2);
-}
-
-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;
-
- return lstrcmpW(str1, str2);
-}
diff --git a/Plugins/utils/mir_memory.h b/Plugins/utils/mir_memory.h index b3f32fc..a976dc9 100644 --- a/Plugins/utils/mir_memory.h +++ b/Plugins/utils/mir_memory.h @@ -1,22 +1,21 @@ -/*
-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.
-*/
-
+/*
+ Copyright (C) 2005-2009 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_MEMORY_H__
# define __MIR_MEMORY_H__
diff --git a/Plugins/utils/mir_options.cpp b/Plugins/utils/mir_options.cpp index f9a6e1c..b4dfe05 100644 --- a/Plugins/utils/mir_options.cpp +++ b/Plugins/utils/mir_options.cpp @@ -1,5 +1,5 @@ /*
-Copyright (C) 2005 Ricardo Pescuma Domenecci
+Copyright (C) 2005-2009 Ricardo Pescuma Domenecci
This is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
@@ -41,7 +41,7 @@ Boston, MA 02111-1307, USA. static TCHAR* MyDBGetContactSettingTString(HANDLE hContact, char* module, char* setting, TCHAR* out, size_t len, TCHAR *def)
{
- DBVARIANT dbv;
+ DBVARIANT dbv = {0};
out[0] = _T('\0');
@@ -257,9 +257,6 @@ BOOL CALLBACK SaveOptsDlgProc(OptPageControl *controls, int controlsSize, char * HWND hwndProtocols = GetDlgItem(hwndDlg, ctrl->nID);
LVCOLUMN lvc;
LVITEM lvi;
- PROTOCOLDESCRIPTOR **protos;
- int i,count;
- char szName[128];
ListView_SetExtendedListViewStyle(hwndProtocols, LVS_EX_CHECKBOXES);
@@ -273,36 +270,50 @@ BOOL CALLBACK SaveOptsDlgProc(OptPageControl *controls, int controlsSize, char * lvi.iSubItem = 0;
lvi.iItem = 1000;
- CallService(MS_PROTO_ENUMPROTOCOLS, (WPARAM)&count, (LPARAM)&protos);
+ PROTOACCOUNT **protos;
+ int count;
+
+ BOOL hasAccounts = ServiceExists(MS_PROTO_ENUMACCOUNTS);
+
+ if (hasAccounts)
+ CallService(MS_PROTO_ENUMACCOUNTS, (WPARAM)&count, (LPARAM)&protos);
+ else
+ CallService(MS_PROTO_ENUMPROTOCOLS, (WPARAM)&count, (LPARAM)&protos);
- for (i = 0; i < count; i++)
+ for (int i = 0; i < count; i++)
{
if (protos[i]->type != PROTOTYPE_PROTOCOL)
continue;
- if (protos[i]->szName == NULL || protos[i]->szName[0] == '\0')
+ if (protos[i]->szModuleName == NULL || protos[i]->szModuleName[0] == '\0')
continue;
- if (ctrl->allowProtocol != NULL && !ctrl->allowProtocol(protos[i]->szName))
+ if (ctrl->allowProtocol != NULL && !ctrl->allowProtocol(protos[i]->szModuleName))
continue;
- CallProtoService(protos[i]->szName, PS_GETNAME, sizeof(szName), (LPARAM)szName);
+ TCHAR *name;
+ if (hasAccounts)
+ {
+ name = mir_tstrdup(protos[i]->tszAccountName);
+ }
+ else
+ {
+ char szName[128];
+ CallProtoService(protos[i]->szModuleName, PS_GETNAME, sizeof(szName), (LPARAM)szName);
+ name = mir_a2t(szName);
+ }
char *setting = (char *) mir_alloc(128 * sizeof(char));
- mir_snprintf(setting, 128, ctrl->setting, protos[i]->szName);
+ mir_snprintf(setting, 128, ctrl->setting, protos[i]->szModuleName);
BOOL show = (BOOL)DBGetContactSettingByte(NULL, module, setting, ctrl->dwDefValue);
lvi.lParam = (LPARAM)setting;
-#ifdef UNICODE
- WCHAR szwName[128];
- MultiByteToWideChar(CP_ACP, 0, szName, -1, szwName, 128);
- lvi.pszText = TranslateTS(szwName);
-#else
- lvi.pszText = TranslateTS(szName);
-#endif
+ lvi.pszText = TranslateTS(name);
lvi.iItem = ListView_InsertItem(hwndProtocols, &lvi);
ListView_SetItemState(hwndProtocols, lvi.iItem, INDEXTOSTATEIMAGEMASK(show?2:1), LVIS_STATEIMAGEMASK);
+
+ mir_free(name);
}
ListView_SetColumnWidth(hwndProtocols, 0, LVSCW_AUTOSIZE);
diff --git a/Plugins/utils/mir_options.h b/Plugins/utils/mir_options.h index 2c433df..c392373 100644 --- a/Plugins/utils/mir_options.h +++ b/Plugins/utils/mir_options.h @@ -1,5 +1,5 @@ /*
-Copyright (C) 2005 Ricardo Pescuma Domenecci
+Copyright (C) 2005-2009 Ricardo Pescuma Domenecci
This is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
diff --git a/Plugins/utils/mir_scope.h b/Plugins/utils/mir_scope.h index 31edde0..a18bf55 100644 --- a/Plugins/utils/mir_scope.h +++ b/Plugins/utils/mir_scope.h @@ -3,22 +3,20 @@ template<class T>
-class mir_scope
+class scope
{
public:
- mir_scope() : p(NULL) {}
- mir_scope(T t) : p(t) {}
- ~mir_scope() { release(); }
+ scope(T t) : p(t) {}
+ ~scope() { free(); }
- void release()
+ void free()
{
if (p != NULL)
mir_free(p);
p = NULL;
}
- T operator=(T t) { release(); p = t; return t; }
- T operator->() const { return p; }
+// 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 index 067b2b5..50c9169 100644 --- a/Plugins/utils/mir_smileys.cpp +++ b/Plugins/utils/mir_smileys.cpp @@ -108,6 +108,9 @@ int Smileys_DrawText(HDC hDC, LPCSTR lpString, int nCount, LPRECT lpRect, UINT u SmileysParseInfo info;
int ret;
+ if (nCount < 0)
+ nCount = strlen(lpString);
+
// Get parse info
if (parseInfo == NULL)
info = Smileys_PreParse(lpString, nCount, protocol);
diff --git a/Plugins/utils/utf8_helpers.h b/Plugins/utils/utf8_helpers.h index 149efcf..1b7785d 100644 --- a/Plugins/utils/utf8_helpers.h +++ b/Plugins/utils/utf8_helpers.h @@ -141,17 +141,7 @@ public: #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_ACP, 0, str, -1, tmp, size);
-
- tchar = tmp;
+ tchar = mir_a2u(str);
#else
@@ -209,15 +199,7 @@ public: #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);
+ tchar = mir_u2a(str);
#endif
}
@@ -259,6 +241,42 @@ private: +class CharToWchar
+{
+public:
+ CharToWchar(const char *str) : wchar(NULL)
+ {
+ if (str == NULL)
+ return;
+
+ wchar = mir_a2u(str);
+ }
+
+
+ ~CharToWchar()
+ {
+ if (wchar != NULL)
+ mir_free(wchar);
+ }
+
+ WCHAR *detach()
+ {
+ WCHAR *ret = wchar;
+ wchar = NULL;
+ return ret;
+ }
+
+ operator const WCHAR *()
+ {
+ return wchar;
+ }
+
+private:
+ WCHAR *wchar;
+};
+
+
+
class TcharToChar
{
public:
@@ -269,15 +287,7 @@ public: #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);
+ val = mir_u2a(str);
#else
@@ -335,15 +345,7 @@ public: #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);
+ val = mir_a2u(str);
#endif
}
@@ -383,4 +385,106 @@ private: };
+
+
+class BstrToTchar
+{
+public:
+ BstrToTchar() : bstr(NULL)
+#ifndef UNICODE
+ , tchar(NULL)
+#endif
+ {
+ }
+
+ BstrToTchar(const WCHAR *str) : bstr(NULL)
+#ifndef UNICODE
+ , tchar(NULL)
+#endif
+ {
+ if (str == NULL)
+ return;
+
+ bstr = SysAllocString(str);
+ }
+
+ BstrToTchar(const char *str) : bstr(NULL)
+#ifndef UNICODE
+ , tchar(NULL)
+#endif
+ {
+ if (str == NULL)
+ return;
+
+ bstr = SysAllocString(CharToWchar(str));
+ }
+
+
+ ~BstrToTchar()
+ {
+ if (bstr != NULL)
+ SysFreeString(bstr);
+
+#ifndef UNICODE
+ freeTchar();
+#endif
+ }
+
+ BSTR detach()
+ {
+ BSTR ret = bstr;
+ bstr = NULL;
+ return ret;
+ }
+
+ operator const TCHAR *()
+ {
+#ifdef UNICODE
+
+ return bstr;
+
+#else
+
+ if (tchar == NULL)
+ tchar = mir_u2a(bstr);
+
+ return tchar;
+
+#endif
+ }
+
+ operator const BSTR()
+ {
+ return bstr;
+ }
+
+ operator BSTR *()
+ {
+#ifndef UNICODE
+ freeTchar();
+#endif
+
+ return &bstr;
+ }
+
+private:
+ BSTR bstr;
+
+#ifndef UNICODE
+
+ TCHAR *tchar;
+
+ void freeTchar()
+ {
+ if (tchar != NULL)
+ {
+ mir_free(tchar);
+ tchar = NULL;
+ }
+ }
+
+#endif
+};
+
+
#endif // __UTF8_HELPERS_H__
|