diff options
author | sje <sje@4f64403b-2f21-0410-a795-97e2b3489a10> | 2006-11-23 03:22:18 +0000 |
---|---|---|
committer | sje <sje@4f64403b-2f21-0410-a795-97e2b3489a10> | 2006-11-23 03:22:18 +0000 |
commit | 6db050eb2d23035c71971cc88219211bbacca23d (patch) | |
tree | 29c91aa26ece9421eb638b33576fd7ad866418c7 | |
parent | 96101e2721d4cb277bf0b9d02f077dc2dd9087d8 (diff) |
use ansi font services if unicode unavailable
bigfixes to allow pure ansi build
git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@56 4f64403b-2f21-0410-a795-97e2b3489a10
-rw-r--r-- | tipper/common.h | 2 | ||||
-rw-r--r-- | tipper/m_tipper.h | 4 | ||||
-rw-r--r-- | tipper/message_pump.cpp | 19 | ||||
-rw-r--r-- | tipper/options.cpp | 32 | ||||
-rw-r--r-- | tipper/popwin.cpp | 108 | ||||
-rw-r--r-- | tipper/str_utils.cpp | 203 | ||||
-rw-r--r-- | tipper/str_utils.h | 44 | ||||
-rw-r--r-- | tipper/subst.cpp | 93 | ||||
-rw-r--r-- | tipper/subst.h | 2 | ||||
-rw-r--r-- | tipper/tipper.cpp | 189 | ||||
-rw-r--r-- | tipper/tipper_8.vcproj | 18 | ||||
-rw-r--r-- | tipper/translations.cpp | 33 | ||||
-rw-r--r-- | tipper/version.h | 6 |
13 files changed, 537 insertions, 216 deletions
diff --git a/tipper/common.h b/tipper/common.h index 9b9e0e4..7cf7690 100644 --- a/tipper/common.h +++ b/tipper/common.h @@ -56,7 +56,7 @@ #include <m_popup.h>
#include <m_updater.h>
-#include <m_fontservicew.h>
+#include <m_fontservice.h>
#include <m_avatars.h>
#include <m_variables.h>
diff --git a/tipper/m_tipper.h b/tipper/m_tipper.h index 81dcb59..a2b5abf 100644 --- a/tipper/m_tipper.h +++ b/tipper/m_tipper.h @@ -5,11 +5,11 @@ // translation function type
// use hContact, module and setting to read your db value(s) and put the resulting string into buff
// return buff if the translation was successful, or return 0 for failure
-typedef wchar_t *(TranslateFunc)(HANDLE hContact, const char *module, const char *setting_or_prefix, wchar_t *buff, int bufflen);
+typedef TCHAR *(TranslateFunc)(HANDLE hContact, const char *module, const char *setting_or_prefix, TCHAR *buff, int bufflen);
typedef struct {
TranslateFunc *tfunc; // address of your translation function (see typedef above)
- const wchar_t *name; // make sure this is unique, and DO NOT translate it
+ const TCHAR *name; // make sure this is unique, and DO NOT translate it
DWORD id; // will be overwritten by Tipper - do not use
} DBVTranslation;
diff --git a/tipper/message_pump.cpp b/tipper/message_pump.cpp index d891a33..ae679c0 100644 --- a/tipper/message_pump.cpp +++ b/tipper/message_pump.cpp @@ -2,6 +2,7 @@ #include "message_pump.h"
#include "popwin.h"
#include "options.h"
+#include "str_utils.h"
HMODULE hUserDll;
BOOL (WINAPI *MySetLayeredWindowAttributes)(HWND,COLORREF,BYTE,DWORD) = 0;
@@ -122,12 +123,7 @@ int ShowTip(WPARAM wParam, LPARAM lParam) { clcit2->text = 0;
if(wParam) { // wParam is char pointer containing text - e.g. status bar tooltip
- int size = MultiByteToWideChar(code_page, 0, (char *)wParam, -1, 0, 0); - if(size) { - clcit2->text = (wchar_t *)malloc(size * sizeof(wchar_t)); - MultiByteToWideChar(code_page, 0, (char *)wParam, -1, clcit2->text, size); - GetCursorPos(&clcit2->ptCursor); // cursor pos broken?
- } + clcit2->text = a2t((char *)wParam);
}
PostMPMessage(MUM_CREATEPOPUP, 0, (LPARAM)clcit2);
@@ -164,12 +160,23 @@ int ProtoAck(WPARAM wParam, LPARAM lParam) { ACKDATA *ack = (ACKDATA *)lParam;
char *szMsg = (char *)ack->lParam;
if(ack->type == ACKTYPE_AWAYMSG && ack->result == ACKRESULT_SUCCESS && szMsg) {
+ /*
int size = MultiByteToWideChar(code_page, 0, szMsg, -1, 0, 0);
if(size > 1) {
wchar_t *msg = (wchar_t *)malloc(size * sizeof(wchar_t));
MultiByteToWideChar(code_page, 0, (char *) szMsg, -1, msg, size);
PostMPMessage(MUM_GOTSTATUS, (WPARAM)ack->hContact, (LPARAM)msg);
}
+ */
+ /*
+ int size = MultiByteToWideChar(CP_UTF8, 0, szMsg, -1, 0, 0);
+ if(size > 1) {
+ wchar_t *msg = (wchar_t *)malloc(size * sizeof(wchar_t));
+ MultiByteToWideChar(CP_UTF8, 0, (char *) szMsg, -1, msg, size);
+ PostMPMessage(MUM_GOTSTATUS, (WPARAM)ack->hContact, (LPARAM)msg);
+ }
+ */
+ PostMPMessage(MUM_GOTSTATUS, (WPARAM)ack->hContact, (LPARAM)u2t(szMsg));
}
return 0;
}
diff --git a/tipper/options.cpp b/tipper/options.cpp index 260ccbb..c6fdccd 100644 --- a/tipper/options.cpp +++ b/tipper/options.cpp @@ -3,6 +3,7 @@ #include "resource.h" #include "popwin.h" #include <commctrl.h> +#include "str_utils.h" Options options; @@ -136,13 +137,13 @@ bool LoadDS(DisplaySubst *ds, int index) { mir_snprintf(setting, 512, "Name%d", index); ds->name[0] = 0; if(!DBGetContactSettingWString(0, MODULE, setting, &dbv)) { - _tcsncpy(ds->name, dbv.pwszVal, LABEL_LEN); + w2t(dbv.pwszVal, ds->name, LABEL_LEN); DBFreeVariant(&dbv); } else if(!DBGetContactSettingStringUtf(0, MODULE, setting, &dbv)) { - MultiByteToWideChar(CP_UTF8, 0, dbv.pszVal, -1, ds->name, LABEL_LEN); + u2t(dbv.pszVal, ds->name, LABEL_LEN); DBFreeVariant(&dbv); } else if(!DBGetContactSetting(0, MODULE, setting, &dbv)) { - if(dbv.type == DBVT_ASCIIZ) MultiByteToWideChar(code_page, 0, dbv.pszVal, -1, ds->name, LABEL_LEN); + if(dbv.type == DBVT_ASCIIZ) a2t(dbv.pszVal, ds->name, LABEL_LEN); DBFreeVariant(&dbv); } else return false; @@ -181,10 +182,9 @@ bool LoadDS(DisplaySubst *ds, int index) { void SaveDS(DisplaySubst *ds, int index) { char setting[512]; mir_snprintf(setting, 512, "Name%d", index); - if(DBWriteContactSettingWString(0, MODULE, setting, ds->name)) { + if(DBWriteContactSettingTString(0, MODULE, setting, ds->name)) { char buff[LABEL_LEN]; - WideCharToMultiByte(code_page, 0, ds->name, -1, buff, LABEL_LEN, 0, 0); - buff[LABEL_LEN] = 0; + t2a(ds->name, buff, LABEL_LEN); DBWriteContactSettingString(0, MODULE, setting, buff); } mir_snprintf(setting, 512, "Type%d", index); @@ -203,13 +203,13 @@ bool LoadDI(DisplayItem *di, int index) { mir_snprintf(setting, 512, "DILabel%d", index); di->label[0] = 0; if(!DBGetContactSettingWString(0, MODULE, setting, &dbv)) { - _tcsncpy(di->label, dbv.pwszVal, LABEL_LEN); + w2t(dbv.pwszVal, di->label, LABEL_LEN); DBFreeVariant(&dbv); } else if(!DBGetContactSettingStringUtf(0, MODULE, setting, &dbv)) { - MultiByteToWideChar(CP_UTF8, 0, dbv.pszVal, -1, di->label, LABEL_LEN); + u2t(dbv.pszVal, di->label, LABEL_LEN); DBFreeVariant(&dbv); } else if(!DBGetContactSetting(0, MODULE, setting, &dbv)) { - if(dbv.type == DBVT_ASCIIZ) MultiByteToWideChar(code_page, 0, dbv.pszVal, -1, di->label, LABEL_LEN); + if(dbv.type == DBVT_ASCIIZ) a2t(dbv.pszVal, di->label, LABEL_LEN); DBFreeVariant(&dbv); } else return false; @@ -218,13 +218,13 @@ bool LoadDI(DisplayItem *di, int index) { mir_snprintf(setting, 512, "DIValue%d", index); di->value[0] = 0; if(!DBGetContactSettingWString(0, MODULE, setting, &dbv)) { - _tcsncpy(di->value, dbv.pwszVal, VALUE_LEN); + w2t(dbv.pwszVal, di->value, VALUE_LEN); DBFreeVariant(&dbv); } else if(!DBGetContactSettingStringUtf(0, MODULE, setting, &dbv)) { - MultiByteToWideChar(CP_UTF8, 0, dbv.pszVal, -1, di->value, VALUE_LEN); + u2t(dbv.pszVal, di->value, VALUE_LEN); DBFreeVariant(&dbv); } else if(!DBGetContactSetting(0, MODULE, setting, &dbv)) { - MultiByteToWideChar(code_page, 0, dbv.pszVal, -1, di->value, VALUE_LEN); + if(dbv.type == DBVT_ASCIIZ) a2t(dbv.pszVal, di->value, VALUE_LEN); DBFreeVariant(&dbv); } @@ -241,15 +241,15 @@ bool LoadDI(DisplayItem *di, int index) { void SaveDI(DisplayItem *di, int index) { char setting[512]; mir_snprintf(setting, 512, "DILabel%d", index); - if(DBWriteContactSettingWString(0, MODULE, setting, di->label)) { + if(DBWriteContactSettingTString(0, MODULE, setting, di->label)) { char buff[LABEL_LEN]; - WideCharToMultiByte(code_page, 0, di->label, -1, buff, LABEL_LEN, 0, 0); + t2a(di->label, buff, LABEL_LEN); DBWriteContactSettingString(0, MODULE, setting, buff); } mir_snprintf(setting, 512, "DIValue%d", index); - if(DBWriteContactSettingWString(0, MODULE, setting, di->value)) { + if(DBWriteContactSettingTString(0, MODULE, setting, di->value)) { char buff[VALUE_LEN]; - WideCharToMultiByte(code_page, 0, di->value, -1, buff, VALUE_LEN, 0, 0); + t2a(di->value, buff, VALUE_LEN); DBWriteContactSettingString(0, MODULE, setting, buff); } mir_snprintf(setting, 512, "DILineAbove%d", index); diff --git a/tipper/popwin.cpp b/tipper/popwin.cpp index c42467b..72d38c8 100644 --- a/tipper/popwin.cpp +++ b/tipper/popwin.cpp @@ -2,6 +2,7 @@ #include "subst.h" #include "popwin.h" #include "message_pump.h" +#include "str_utils.h" #define TITLE_TEXT_LEN 512 @@ -66,17 +67,16 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa pwd->indent = options.text_indent; pwd->sb_width = options.sidebar_width; - MultiByteToWideChar(code_page, 0, pwd->clcit.proto, -1, pwd->swzTitle, 512); + a2t(pwd->clcit.proto, pwd->swzTitle, TITLE_TEXT_LEN); WORD status = CallProtoService(pwd->clcit.proto, PS_GETSTATUS, 0, 0); char *strptr = (char *)CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, (WPARAM)status, (LPARAM)0);
- int size = MultiByteToWideChar(code_page, 0, strptr, -1, 0, 0);
- if(size) { - wchar_t *swzText = (wchar_t *)malloc(size * sizeof(wchar_t)); - MultiByteToWideChar(code_page, 0, strptr, -1, swzText, size); + if(strptr) {
+ TCHAR *swzText = a2t(strptr); + pwd->rows = (RowData *) realloc(pwd->rows, sizeof(RowData) * (pwd->row_count + 1)); - pwd->rows[pwd->row_count].swzLabel = wcsdup(TranslateT("Status:")); + pwd->rows[pwd->row_count].swzLabel = _tcsdup(TranslateT("Status:")); pwd->rows[pwd->row_count].swzValue = swzText; pwd->rows[pwd->row_count].value_newline = false; pwd->rows[pwd->row_count].line_above = false; @@ -86,19 +86,16 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa if(status >= ID_STATUS_OFFLINE && status <= ID_STATUS_IDLE) { char *status_msg = (char *)CallService(MS_AWAYMSG_GETSTATUSMSG, status, 0); if(status_msg) { - int size = MultiByteToWideChar(code_page, 0, status_msg, -1, 0, 0); - if(size) { - wchar_t *swzText = (wchar_t *)malloc(size * sizeof(wchar_t)); - MultiByteToWideChar(code_page, 0, status_msg, -1, swzText, size); - StripBBCodesInPlace(swzText); - pwd->rows = (RowData *) realloc(pwd->rows, sizeof(RowData) * (pwd->row_count + 1)); - - pwd->rows[pwd->row_count].swzLabel = wcsdup(TranslateT("Status message:")); - pwd->rows[pwd->row_count].swzValue = swzText; - pwd->rows[pwd->row_count].value_newline = true; - pwd->rows[pwd->row_count].line_above = true; - pwd->row_count++; - } + TCHAR *swzText = a2t(status_msg); + StripBBCodesInPlace(swzText); + pwd->rows = (RowData *) realloc(pwd->rows, sizeof(RowData) * (pwd->row_count + 1)); + + pwd->rows[pwd->row_count].swzLabel = _tcsdup(TranslateT("Status message:")); + pwd->rows[pwd->row_count].swzValue = swzText; + pwd->rows[pwd->row_count].value_newline = true; + pwd->rows[pwd->row_count].line_above = true; + pwd->row_count++; + mir_free(status_msg); } } @@ -110,7 +107,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa //MessageBox(0, swzText, _T("tip"), MB_OK);
- wchar_t buff[2048], *swzText = pwd->clcit.text; + TCHAR buff[2048], *swzText = pwd->clcit.text; int buff_pos, i = 0, size = _tcslen(pwd->clcit.text); bool top_message = false; @@ -126,7 +123,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa pwd->rows[pwd->row_count].line_above = false; pwd->rows[pwd->row_count].value_newline = true; pwd->rows[pwd->row_count].swzLabel = _T(""); - pwd->rows[pwd->row_count].swzValue = wcsdup(buff);
+ pwd->rows[pwd->row_count].swzValue = _tcsdup(buff);
pwd->row_count++; top_message = true; } @@ -135,9 +132,9 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa // parse bold bits into labels and the rest into items while(i < size) { while(i + 2 < size - && (swzText[i] != L'<' - || swzText[i + 1] != L'b' - || swzText[i + 2] != L'>')) + && (swzText[i] != _T('<') + || swzText[i + 1] != _T('b') + || swzText[i + 2] != _T('>'))) { i++; } @@ -147,12 +144,12 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa buff_pos = 0; while(i + 3 < size && buff_pos < 2048 - && (swzText[i] != L'<' - || swzText[i + 1] != L'/' - || swzText[i + 2] != L'b' - || swzText[i + 3] != L'>')) + && (swzText[i] != _T('<') + || swzText[i + 1] != _T('/') + || swzText[i + 2] != _T('b') + || swzText[i + 3] != _T('>'))) { - if(swzText[i] != L'\t') + if(swzText[i] != _T('\t')) buff[buff_pos++] = swzText[i]; i++; } @@ -164,7 +161,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa if(buff_pos) { pwd->rows = (RowData *)realloc(pwd->rows, sizeof(RowData) * (pwd->row_count + 1)); pwd->rows[pwd->row_count].value_newline = false; - pwd->rows[pwd->row_count].swzLabel = wcsdup(buff); + pwd->rows[pwd->row_count].swzLabel = _tcsdup(buff); if(pwd->row_count == 1 && top_message) pwd->rows[pwd->row_count].line_above = true; else @@ -173,15 +170,15 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa buff_pos = 0; while(i < size && buff_pos < 2048 - && swzText[i] != L'\n') + && swzText[i] != _T('\n')) { - if(swzText[i] != L'\t' && swzText[i] != L'\r') + if(swzText[i] != _T('\t') && swzText[i] != _T('\r')) buff[buff_pos++] = swzText[i]; i++; } buff[buff_pos] = 0; - pwd->rows[pwd->row_count].swzValue = wcsdup(buff); + pwd->rows[pwd->row_count].swzValue = _tcsdup(buff); pwd->row_count++; } @@ -210,28 +207,11 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa // don't use stored status message DBDeleteContactSetting(pwd->hContact, MODULE, "TempStatusMsg"); - { // get unicode name if possible, else ascii - wchar_t *swzCDN = (wchar_t *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)pwd->hContact, GCDNF_UNICODE); - char *szCDN = (char *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)pwd->hContact, 0); - - if(szCDN) { - // detect if the clist provided unicode display name by comparing with non-unicode - if(swzCDN && strncmp(szCDN, (char *)swzCDN, strlen(szCDN)) != 0) { - wcsncpy(pwd->swzTitle, swzCDN, TITLE_TEXT_LEN); - } else { - // convert to unicode - //swzContactDisplayName = (wchar_t *) _alloca(sizeof(wchar_t) * (strlen(szCDN) + 1)); - int size = MultiByteToWideChar(code_page, 0, (char *) szCDN, -1, 0, 0); - if(size > 0) { - MultiByteToWideChar(code_page, 0, (char *) szCDN, -1, pwd->swzTitle, TITLE_TEXT_LEN); - } else { - wcsncpy(pwd->swzTitle, TranslateT("(Unknown)"), TITLE_TEXT_LEN); - } - } - pwd->swzTitle[TITLE_TEXT_LEN - 1] = 0; - } else { - wcscpy(pwd->swzTitle, TranslateT("(Unknown)")); - } + { + TCHAR *stzCDN = (TCHAR *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)pwd->hContact, GCDNF_TCHAR); + + if(stzCDN) _tcsncpy(pwd->swzTitle, stzCDN, TITLE_TEXT_LEN); + else _tcscpy(pwd->swzTitle, TranslateT("(Unknown)")); } SendMessage(hwnd, PUM_REFRESH_VALUES, 0, 0); @@ -393,7 +373,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa SetTextColor(ps.hdc, options.title_col); tr.top = r.top + options.padding; tr.bottom = tr.top + pwd->tb_height - options.padding; - DrawText(ps.hdc, pwd->swzTitle, wcslen(pwd->swzTitle), &tr, DT_VCENTER | DT_LEFT | DT_END_ELLIPSIS | DT_SINGLELINE | DT_NOPREFIX);
+ DrawText(ps.hdc, pwd->swzTitle, _tcslen(pwd->swzTitle), &tr, DT_VCENTER | DT_LEFT | DT_END_ELLIPSIS | DT_SINGLELINE | DT_NOPREFIX);
} // values @@ -440,7 +420,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa tr.top += options.text_padding; tr.bottom = tr.top + row_height; SetTextColor(ps.hdc, options.label_col); - DrawText(ps.hdc, pwd->rows[i].swzLabel, wcslen(pwd->rows[i].swzLabel), &tr, options.label_valign | ((options.label_halign == DT_RIGHT && !pwd->rows[i].value_newline) ? DT_RIGHT : DT_LEFT) | DT_END_ELLIPSIS | DT_SINGLELINE | DT_NOPREFIX); + DrawText(ps.hdc, pwd->rows[i].swzLabel, _tcslen(pwd->rows[i].swzLabel), &tr, options.label_valign | ((options.label_halign == DT_RIGHT && !pwd->rows[i].value_newline) ? DT_RIGHT : DT_LEFT) | DT_END_ELLIPSIS | DT_SINGLELINE | DT_NOPREFIX); if(pwd->rows[i].value_newline) tr.top = tr.bottom; } else @@ -467,7 +447,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa if(pwd->rows[i].value_height) { if(pwd->rows[i].value_newline || !pwd->rows[i].label_height) tr.top += options.text_padding; tr.bottom = tr.top + row_height; - DrawText(ps.hdc, pwd->rows[i].swzValue, wcslen(pwd->rows[i].swzValue), &tr, options.value_valign | options.value_halign | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS | DT_NOPREFIX); + DrawText(ps.hdc, pwd->rows[i].swzValue, _tcslen(pwd->rows[i].swzValue), &tr, options.value_valign | options.value_halign | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS | DT_NOPREFIX); } } @@ -581,8 +561,8 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa } else pwd->rows = (RowData *) realloc(pwd->rows, sizeof(RowData) * (pwd->row_count + 1)); - pwd->rows[pwd->row_count].swzLabel = wcsdup(buff_label); - pwd->rows[pwd->row_count].swzValue = wcsdup(buff); + pwd->rows[pwd->row_count].swzLabel = _tcsdup(buff_label); + pwd->rows[pwd->row_count].swzValue = _tcsdup(buff); pwd->rows[pwd->row_count].value_newline = node->di.value_newline; pwd->rows[pwd->row_count].line_above = node->di.line_above; pwd->row_count++; @@ -622,7 +602,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa // titlebar height if(!pwd->text_tip && pwd->swzTitle && options.title_layout != PTL_NOTITLE) { if(hFontTitle) SelectObject(hdc, (HGDIOBJ)hFontTitle); - GetTextExtentPoint32(hdc, pwd->swzTitle, wcslen(pwd->swzTitle), &size); + GetTextExtentPoint32(hdc, pwd->swzTitle, _tcslen(pwd->swzTitle), &size); width += options.padding + size.cx; if(options.title_layout != PTL_NOICON) { pwd->tb_height = options.padding + max(size.cy, 16); @@ -658,7 +638,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa for(i = 0; i < pwd->row_count; i++) { if(pwd->rows[i].swzLabel && pwd->rows[i].value_newline == false) { if(hFontLabels) SelectObject(hdc, (HGDIOBJ)hFontLabels); - GetTextExtentPoint32(hdc, pwd->rows[i].swzLabel, wcslen(pwd->rows[i].swzLabel), &size); + GetTextExtentPoint32(hdc, pwd->rows[i].swzLabel, _tcslen(pwd->rows[i].swzLabel), &size); if(size.cx > pwd->label_width) pwd->label_width = size.cx; } @@ -667,7 +647,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa for(i = 0; i < pwd->row_count; i++) { if(hFontLabels) SelectObject(hdc, (HGDIOBJ)hFontLabels); if(pwd->rows[i].swzLabel) - GetTextExtentPoint32(hdc, pwd->rows[i].swzLabel, wcslen(pwd->rows[i].swzLabel), &size); + GetTextExtentPoint32(hdc, pwd->rows[i].swzLabel, _tcslen(pwd->rows[i].swzLabel), &size); else size.cy = size.cx = 0; @@ -685,7 +665,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa smr.right -= options.padding; if(!pwd->rows[i].value_newline) smr.right -= pwd->label_width + options.padding; if(pwd->rows[i].swzValue) - DrawText(hdc, pwd->rows[i].swzValue, wcslen(pwd->rows[i].swzValue), &smr, DT_CALCRECT | DT_VCENTER | DT_LEFT | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS | DT_NOPREFIX); + DrawText(hdc, pwd->rows[i].swzValue, _tcslen(pwd->rows[i].swzValue), &smr, DT_CALCRECT | DT_VCENTER | DT_LEFT | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS | DT_NOPREFIX); // save so we don't have to recalculate pwd->rows[i].value_height = smr.bottom; diff --git a/tipper/str_utils.cpp b/tipper/str_utils.cpp new file mode 100644 index 0000000..b226bfe --- /dev/null +++ b/tipper/str_utils.cpp @@ -0,0 +1,203 @@ +#include "common.h"
+#include "str_utils.h"
+
+int code_page = CP_ACP;
+
+void set_codepage() {
+ if(ServiceExists(MS_LANGPACK_GETCODEPAGE))
+ code_page = CallService(MS_LANGPACK_GETCODEPAGE, 0, 0);
+}
+
+bool a2w(const char *as, wchar_t *buff, int bufflen){
+ if(as) MultiByteToWideChar(code_page, 0, as, -1, buff, bufflen);
+ return true;
+}
+
+bool w2a(const wchar_t *ws, char *buff, int bufflen) {
+ if(ws) WideCharToMultiByte(code_page, 0, ws, -1, buff, bufflen, 0, 0);
+ return true;
+}
+
+bool u2w(const char *us, wchar_t *buff, int bufflen) {
+ if(us) MultiByteToWideChar(CP_UTF8, 0, us, -1, buff, bufflen);
+ return true;
+}
+
+bool w2u(const wchar_t *ws, char *buff, int bufflen) {
+ if(ws) WideCharToMultiByte(CP_UTF8, 0, ws, -1, buff, bufflen, 0, 0);
+ return true;
+}
+
+bool a2u(const char *as, char *buff, int bufflen) {
+ if(!as) return false;
+
+ wchar_t *ws = a2w(as);
+ if(ws) WideCharToMultiByte(CP_UTF8, 0, ws, -1, buff, bufflen, 0, 0);
+ free(ws);
+ return true;
+}
+
+bool u2a(const char *us, char *buff, int bufflen) {
+ if(!us) return false;
+
+ wchar_t *ws = u2w(us);
+ if(ws) WideCharToMultiByte(code_page, 0, ws, -1, buff, bufflen, 0, 0);
+ free(ws);
+ return true;
+}
+
+
+bool t2w(const TCHAR *ts, wchar_t *buff, int bufflen) {
+#ifdef _UNICODE
+ wcsncpy(buff, ts, bufflen);
+ return true;
+#else
+ return a2w(ts, buff, bufflen);
+#endif
+}
+
+bool w2t(const wchar_t *ws, TCHAR *buff, int bufflen) {
+#ifdef _UNICODE
+ wcsncpy(buff, ws, bufflen);
+ return true;
+#else
+ return w2a(ws, buff, bufflen);
+#endif
+}
+
+bool t2a(const TCHAR *ts, char *buff, int bufflen) {
+#ifdef _UNICODE
+ return w2a(ts, buff, bufflen);
+#else
+ strncpy(buff, ts, bufflen);
+ return true;
+#endif
+}
+
+bool a2t(const char *as, TCHAR *buff, int bufflen) {
+#ifdef _UNICODE
+ return a2w(as, buff, bufflen);
+#else
+ strncpy(buff, as, bufflen);
+ return true;
+#endif
+}
+
+bool t2u(const TCHAR *ts, char *buff, int bufflen) {
+#ifdef _UNICODE
+ return w2u(ts, buff, bufflen);
+#else
+ return a2u(ts, buff, bufflen);
+#endif
+}
+
+bool u2t(const char *us, TCHAR *buff, int bufflen) {
+#ifdef _UNICODE
+ return u2w(us, buff, bufflen);
+#else
+ return u2a(us, buff, bufflen);
+#endif
+}
+
+wchar_t *u2w(const char *us) {
+ if(us) {
+ int size = MultiByteToWideChar(CP_UTF8, 0, us, -1, 0, 0);
+ wchar_t *buff = (wchar_t *)malloc(size * sizeof(wchar_t));
+ MultiByteToWideChar(CP_UTF8, 0, us, -1, buff, size);
+ return buff;
+ } else
+ return 0;
+}
+
+char *w2u(const wchar_t *ws) {
+ if(ws) {
+ int size = WideCharToMultiByte(CP_UTF8, 0, ws, -1, 0, 0, 0, 0);
+ char *buff = (char *)malloc(size);
+ WideCharToMultiByte(CP_UTF8, 0, ws, -1, buff, size, 0, 0);
+ return buff;
+ } else
+ return 0;
+}
+
+wchar_t *a2w(const char *as) {
+ int size = MultiByteToWideChar(code_page, 0, as, -1, 0, 0);
+ wchar_t *buff = (wchar_t *)malloc(size * sizeof(wchar_t));
+ MultiByteToWideChar(code_page, 0, as, -1, buff, size);
+ return buff;
+}
+
+char *w2a(const wchar_t *ws) {
+ int size = WideCharToMultiByte(code_page, 0, ws, -1, 0, 0, 0, 0);
+ char *buff = (char *)malloc(size);
+ WideCharToMultiByte(code_page, 0, ws, -1, buff, size, 0, 0);
+ return buff;
+}
+
+char *u2a(const char *utfs) {
+ wchar_t *ws = u2w(utfs);
+ char *ret = w2a(ws);
+ free(ws);
+ return ret;
+}
+
+char *a2u(const char *as) {
+ wchar_t *ws = a2w(as);
+ char *ret = w2u(ws);
+ free(ws);
+ return ret;
+}
+
+TCHAR *w2t(const wchar_t *ws) {
+#ifdef _UNICODE
+ return wcsdup(ws);
+#else
+ return w2a(ws);
+#endif
+}
+
+wchar_t *t2w(const TCHAR *ts) {
+#ifdef _UNICODE
+ return _tcsdup(ts);
+#else
+ return a2w(ts);
+#endif
+}
+
+
+char *t2a(const TCHAR *ts) {
+#ifdef _UNICODE
+ return w2a(ts);
+#else
+ return _strdup(ts);
+#endif
+}
+
+TCHAR *a2t(const char *as) {
+#ifdef _UNICODE
+ return a2w(as);
+#else
+ return _strdup(as);
+#endif
+}
+
+TCHAR *u2t(const char *utfs) {
+#ifdef _UNICODE
+ return u2w(utfs);
+#else
+ wchar_t *ws = u2w(utfs);
+ char *ret = w2a(ws);
+ free(ws);
+ return ret;
+#endif
+}
+
+char *t2u(const TCHAR *ts) {
+#ifdef _UNICODE
+ return w2u(ts);
+#else
+ wchar_t *ws = a2w(ts);
+ char *ret = w2u(ws);
+ free(ws);
+ return ret;
+#endif
+}
diff --git a/tipper/str_utils.h b/tipper/str_utils.h new file mode 100644 index 0000000..5cef279 --- /dev/null +++ b/tipper/str_utils.h @@ -0,0 +1,44 @@ +#ifndef _STR_UTILS_INC
+#define _STR_UTILS_INC
+
+void set_codepage();
+
+bool a2w(const char *as, wchar_t *buff, int bufflen);
+bool w2a(const wchar_t *ws, char *buff, int bufflen);
+
+bool u2w(const char *us, wchar_t *buff, int bufflen);
+bool w2u(const wchar_t *ws, char *buff, int bufflen);
+
+bool a2u(const char *as, char *buff, int bufflen);
+bool u2a(const char *ws, char *buff, int bufflen);
+
+bool t2w(const TCHAR *ts, wchar_t *buff, int bufflen);
+bool w2t(const wchar_t *ws, TCHAR *buff, int bufflen);
+
+bool t2a(const TCHAR *ts, char *buff, int bufflen);
+bool a2t(const char *as, TCHAR *buff, int bufflen);
+
+bool t2u(const TCHAR *ts, char *buff, int bufflen);
+bool u2t(const char *us, TCHAR *buff, int bufflen);
+
+// remember to free return value
+wchar_t *a2w(const char *as);
+char *w2a(const wchar_t *ws);
+
+wchar_t *u2w(const char *us);
+char *w2u(const wchar_t *ws);
+
+char *u2a(const char *us);
+char *a2u(const char *as);
+
+wchar_t *t2w(const TCHAR *ts);
+TCHAR *w2t(const wchar_t *ws);
+
+TCHAR *u2t(const char *us);
+char *t2u(const TCHAR *ts);
+
+char *t2a(const TCHAR *ts);
+TCHAR *a2t(const char *as);
+
+#endif
+
diff --git a/tipper/subst.cpp b/tipper/subst.cpp index 7f43b51..b07f567 100644 --- a/tipper/subst.cpp +++ b/tipper/subst.cpp @@ -1,29 +1,32 @@ #include "common.h"
#include "subst.h"
#include <time.h>
+#include "str_utils.h"
-void StripBBCodesInPlace(wchar_t *text) { +void StripBBCodesInPlace(TCHAR *text) { if(!DBGetContactSettingByte(0, MODULE, "StripBBCodes", 1)) return; + if(text == 0) return; + int read = 0, write = 0; - int len = wcslen(text); + int len = _tcslen(text); while(read <= len) { // copy terminating null too - while(read <= len && text[read] != L'[') { + while(read <= len && text[read] != _T('[')) { if(text[read] != text[write]) text[write] = text[read]; read++; write++; } if(read > len) break; - if(len - read >= 3 && (wcsnicmp(text + read, L"[b]", 3) == 0 || wcsnicmp(text + read, L"[i]", 3) == 0)) + if(len - read >= 3 && (_tcsnicmp(text + read, _T("[b]"), 3) == 0 || _tcsnicmp(text + read, _T("[i]"), 3) == 0)) read += 3; - else if(len - read >= 4 && (wcsnicmp(text + read, L"[/b]", 4) == 0 || wcsnicmp(text + read, L"[/i]", 4) == 0)) + else if(len - read >= 4 && (_tcsnicmp(text + read, _T("[/b]"), 4) == 0 || _tcsnicmp(text + read, _T("[/i]"), 4) == 0)) read += 4; - else if(len - read >= 6 && (wcsnicmp(text + read, L"[color", 6) == 0)) { + else if(len - read >= 6 && (_tcsnicmp(text + read, _T("[color"), 6) == 0)) { while(read < len && text[read] != L']') read++; read++;// skip the ']' - } else if(len - read >= 8 && (wcsnicmp(text + read, L"[/color]", 8) == 0)) + } else if(len - read >= 8 && (_tcsnicmp(text + read, _T("[/color]"), 8) == 0)) read += 8; else { if(text[read] != text[write]) text[write] = text[read]; @@ -56,7 +59,7 @@ void format_timestamp(DWORD ts, char *format, TCHAR *buff, int bufflen) { DBTIMETOSTRINGT dbt = {0};
dbt.cbDest = bufflen;
dbt.szDest = buff;
- MultiByteToWideChar(code_page, 0, format, -1, form, 16);
+ a2t(format, form, 16);
dbt.szFormat = form;
CallService(MS_DB_TIME_TIMESTAMPTOSTRINGT, (WPARAM)ts, (LPARAM)&dbt);
} else {
@@ -66,7 +69,7 @@ void format_timestamp(DWORD ts, char *format, TCHAR *buff, int bufflen) { dbt.szDest = buffA;
dbt.szFormat = format;
CallService(MS_DB_TIME_TIMESTAMPTOSTRING, (WPARAM)ts, (LPARAM)&dbt);
- MultiByteToWideChar(code_page, 0, buffA, -1, buff, bufflen);
+ a2t(buffA, buff, bufflen);
}
}
@@ -88,8 +91,7 @@ bool uid(HANDLE hContact, TCHAR *buff, int bufflen) { _ltot(ci.dVal, buff, 10);
break;
case CNFT_ASCIIZ:
- if(unicode_system) _tcsncpy(buff, ci.pszVal, bufflen);
- else MultiByteToWideChar(code_page, 0, (char *)ci.pszVal, -1, buff, bufflen);
+ a2t(ci.pszVal, buff, bufflen);
break;
default:
return false;
@@ -119,40 +121,18 @@ TCHAR *GetLastMessageText(HANDLE hContact) { if(dbei.cbBlob == 0 || dbei.pBlob == 0) return 0; - wchar_t *msg; + TCHAR *msg = 0; unsigned int msglen = strlen((char *)dbei.pBlob) + 1; - // here we detect the double-zero wide char zero terminator - in case of messages that are not unicode but have - // other data after the message (e.g. metacontact copied messages with source identifier) - bool dz = false; - for(unsigned int i = msglen; i < dbei.cbBlob; i++) { - if(dbei.pBlob[i] == 0 && dbei.pBlob[i - 1] == 0) { // safe since msglen + 1 above - dz = true; - break; - } - } - // does blob contain unicode message? - if(msglen < dbei.cbBlob && dz && wcslen((wchar_t *)(&dbei.pBlob[msglen]))) { - // yes - msg = (wchar_t *)(&dbei.pBlob[msglen]); - wchar_t *ret = wcsdup(msg); - StripBBCodesInPlace(ret); - return ret; + if(msglen < dbei.cbBlob) { + msg = w2t((wchar_t *)(&dbei.pBlob[msglen])); } else { - // no, convert to unciode (allocate stack memory); - int size = MultiByteToWideChar(code_page, 0, (char *) dbei.pBlob, -1, 0, 0); - if(size > 0) { - msg = (wchar_t *) malloc(sizeof(wchar_t) * size); - MultiByteToWideChar(code_page, 0, (char *) dbei.pBlob, -1, msg, size); - } else { - msg = (wchar_t *) malloc(sizeof(wchar_t) * (wcslen(TranslateT("Empty message")) + 1)); - wcscpy(msg, TranslateT("Empty message")); - } - StripBBCodesInPlace(msg); - return msg; + msg = a2t((char *)dbei.pBlob); } + StripBBCodesInPlace(msg); + return msg; } return 0; @@ -186,7 +166,7 @@ bool GetSysSubstText(HANDLE hContact, TCHAR *raw_spec, TCHAR *buff, int bufflen) } else if (!_tcscmp(raw_spec, _T("proto"))) {
char *szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
if (szProto){
- MultiByteToWideChar(code_page, 0, szProto, -1, buff, bufflen);
+ a2t(szProto, buff, bufflen);
return true;
}
} else if (!_tcscmp(raw_spec, _T("uidname"))) {
@@ -194,7 +174,7 @@ bool GetSysSubstText(HANDLE hContact, TCHAR *raw_spec, TCHAR *buff, int bufflen) if (szProto){
char *szUniqueId = (char*)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDTEXT, 0);
if(szUniqueId) {
- MultiByteToWideChar(code_page, 0, szUniqueId, -1, buff, bufflen);
+ a2t(szUniqueId, buff, bufflen);
return true;
}
}
@@ -216,24 +196,9 @@ bool GetSysSubstText(HANDLE hContact, TCHAR *raw_spec, TCHAR *buff, int bufflen) HANDLE hSubContact = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0);
if(!hSubContact) return false;
- if(unicode_system) { // get unicode name if possible, else get ascii and convert - wchar_t *swzCDN = (wchar_t *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hSubContact, GCDNF_UNICODE); - if(swzCDN) { - wcsncpy(buff, swzCDN, bufflen); - return true; - } - } else { - char *szCDN = (char *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hSubContact, 0); - if(szCDN) { - int size = MultiByteToWideChar(code_page, 0, (char *) szCDN, -1, 0, 0); - if(size > 0) { - MultiByteToWideChar(code_page, 0, (char *) szCDN, -1, buff, bufflen); - return true; - } - } - } - return false; -
+ TCHAR *stzCDN = (TCHAR *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hSubContact, GCDNF_TCHAR); + if(stzCDN) _tcsncpy(buff, stzCDN, bufflen); + return true;
} else if (!_tcscmp(raw_spec, _T("meta_subuid"))){
HANDLE hSubContact = (HANDLE)CallService(MS_MC_GETMOSTONLINECONTACT, (WPARAM)hContact, 0);
if(!hSubContact) return false;
@@ -245,7 +210,7 @@ bool GetSysSubstText(HANDLE hContact, TCHAR *raw_spec, TCHAR *buff, int bufflen) char *szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hSubContact, 0);
if (szProto){
- MultiByteToWideChar(code_page, 0, szProto, -1, buff, bufflen);
+ a2t(szProto, buff, bufflen);
return true;
}
} else if (!_tcscmp(raw_spec, _T("last_msg_time"))) {
@@ -373,7 +338,7 @@ bool ApplySubst(HANDLE hContact, const TCHAR *source, TCHAR *dest, int dest_len) } char sproto[256], *cp; - WideCharToMultiByte(code_page, 0, p, -1, sproto, 256, 0, 0); + t2a(p, sproto, 256); cp = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); if(cp == 0 || (negate ? stricmp(cp, sproto) == 0 : stricmp(cp, sproto) != 0)) goto empty; @@ -395,7 +360,7 @@ bool ApplySubst(HANDLE hContact, const TCHAR *source, TCHAR *dest, int dest_len) // get subst text if(v > 4 && _tcsncmp(vname, _T("raw:"), 4) == 0) { // raw db substitution char raw_spec[LABEL_LEN]; - WideCharToMultiByte(code_page, 0, &vname[4], -1, raw_spec, LABEL_LEN, 0, 0); + t2a(&vname[4], raw_spec, LABEL_LEN); subst = GetRawSubstText(hContact, raw_spec, rep, VALUE_LEN); } else if(v > 4 && _tcsncmp(vname, _T("sys:"), 4) == 0) { // 'system' substitution subst = GetSysSubstText(hContact, &vname[4], rep, VALUE_LEN); @@ -415,11 +380,11 @@ bool ApplySubst(HANDLE hContact, const TCHAR *source, TCHAR *dest, int dest_len) if(subst) { int rep_len = _tcslen(rep); - wcsncpy(&dest[di], rep, min(rep_len, dest_len - di)); + _tcsncpy(&dest[di], rep, min(rep_len, dest_len - di)); di += rep_len - 1; // -1 because we inc at bottom of loop } else if(alt_subst) { int alt_len = _tcslen(alt); - wcsncpy(&dest[di], alt, min(alt_len, dest_len - di)); + _tcsncpy(&dest[di], alt, min(alt_len, dest_len - di)); di += alt_len - 1; // -1 because we inc at bottom of loop } else goto empty; // empty value diff --git a/tipper/subst.h b/tipper/subst.h index 7fbf5f1..8912aa6 100644 --- a/tipper/subst.h +++ b/tipper/subst.h @@ -9,6 +9,6 @@ bool GetLabelText(HANDLE hContact, const DisplayItem &di, TCHAR *buff, int bufflen);
bool GetValueText(HANDLE hContact, const DisplayItem &di, TCHAR *buff, int bufflen);
-void StripBBCodesInPlace(wchar_t *text);
+void StripBBCodesInPlace(TCHAR *text);
#endif
diff --git a/tipper/tipper.cpp b/tipper/tipper.cpp index cd8085b..cc03ca9 100644 --- a/tipper/tipper.cpp +++ b/tipper/tipper.cpp @@ -7,15 +7,16 @@ #include "message_pump.h"
#include "options.h"
#include "popwin.h"
+#include "str_utils.h"
HMODULE hInst = 0;
HANDLE mainThread = 0;
-int code_page = CP_ACP;
+FontID font_id_title = {0}, font_id_labels = {0}, font_id_values = {0};
+ColourID colour_id_bg = {0}, colour_id_border = {0}, colour_id_divider = {0}, colour_id_sidebar = {0};
+FontIDW font_id_titlew = {0}, font_id_labelsw = {0}, font_id_valuesw = {0};
+ColourIDW colour_id_bgw = {0}, colour_id_borderw = {0}, colour_id_dividerw = {0}, colour_id_sidebarw = {0};
-
-FontIDW font_id_title = {0}, font_id_labels = {0}, font_id_values = {0};
-ColourIDW colour_id_bg = {0}, colour_id_border = {0}, colour_id_divider = {0}, colour_id_sidebar = {0};
HFONT hFontTitle = 0, hFontLabels = 0, hFontValues = 0;
// hooked here so it's in the main thread
@@ -27,7 +28,11 @@ struct MM_INTERFACE memoryManagerInterface = {0}; PLUGININFO pluginInfo={
sizeof(PLUGININFO),
+#ifndef _UNICODE
+ __PLUGIN_NAME " (ANSI)",
+#else
__PLUGIN_NAME,
+#endif
PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
__DESC,
__AUTHOR,
@@ -55,20 +60,37 @@ extern "C" __declspec(dllexport) PLUGININFO* MirandaPluginInfo(DWORD mirandaVers int ReloadFont(WPARAM wParam, LPARAM lParam) {
LOGFONT log_font;
- if(hFontTitle) DeleteObject(hFontTitle);
- options.title_col = CallService(MS_FONT_GETW, (WPARAM)&font_id_title, (LPARAM)&log_font);
- hFontTitle = CreateFontIndirect(&log_font);
- if(hFontLabels) DeleteObject(hFontLabels);
- options.label_col = CallService(MS_FONT_GETW, (WPARAM)&font_id_labels, (LPARAM)&log_font);
- hFontLabels = CreateFontIndirect(&log_font);
- if(hFontValues) DeleteObject(hFontValues);
- options.value_col = CallService(MS_FONT_GETW, (WPARAM)&font_id_values, (LPARAM)&log_font);
- hFontValues = CreateFontIndirect(&log_font);
-
- options.bg_col = CallService(MS_COLOUR_GETW, (WPARAM)&colour_id_bg, 0);
- options.border_col = CallService(MS_COLOUR_GETW, (WPARAM)&colour_id_border, 0);
- options.sidebar_col = CallService(MS_COLOUR_GETW, (WPARAM)&colour_id_sidebar, 0);
- options.div_col = CallService(MS_COLOUR_GETW, (WPARAM)&colour_id_divider, 0);
+ if(ServiceExists(MS_FONT_GETW)) {
+ if(hFontTitle) DeleteObject(hFontTitle);
+ options.title_col = CallService(MS_FONT_GETW, (WPARAM)&font_id_titlew, (LPARAM)&log_font);
+ hFontTitle = CreateFontIndirect(&log_font);
+ if(hFontLabels) DeleteObject(hFontLabels);
+ options.label_col = CallService(MS_FONT_GETW, (WPARAM)&font_id_labelsw, (LPARAM)&log_font);
+ hFontLabels = CreateFontIndirect(&log_font);
+ if(hFontValues) DeleteObject(hFontValues);
+ options.value_col = CallService(MS_FONT_GETW, (WPARAM)&font_id_valuesw, (LPARAM)&log_font);
+ hFontValues = CreateFontIndirect(&log_font);
+
+ options.bg_col = CallService(MS_COLOUR_GETW, (WPARAM)&colour_id_bgw, 0);
+ options.border_col = CallService(MS_COLOUR_GETW, (WPARAM)&colour_id_borderw, 0);
+ options.sidebar_col = CallService(MS_COLOUR_GETW, (WPARAM)&colour_id_sidebarw, 0);
+ options.div_col = CallService(MS_COLOUR_GETW, (WPARAM)&colour_id_dividerw, 0);
+ } else {
+ if(hFontTitle) DeleteObject(hFontTitle);
+ options.title_col = CallService(MS_FONT_GET, (WPARAM)&font_id_title, (LPARAM)&log_font);
+ hFontTitle = CreateFontIndirect(&log_font);
+ if(hFontLabels) DeleteObject(hFontLabels);
+ options.label_col = CallService(MS_FONT_GET, (WPARAM)&font_id_labels, (LPARAM)&log_font);
+ hFontLabels = CreateFontIndirect(&log_font);
+ if(hFontValues) DeleteObject(hFontValues);
+ options.value_col = CallService(MS_FONT_GET, (WPARAM)&font_id_values, (LPARAM)&log_font);
+ hFontValues = CreateFontIndirect(&log_font);
+
+ options.bg_col = CallService(MS_COLOUR_GET, (WPARAM)&colour_id_bg, 0);
+ options.border_col = CallService(MS_COLOUR_GET, (WPARAM)&colour_id_border, 0);
+ options.sidebar_col = CallService(MS_COLOUR_GET, (WPARAM)&colour_id_sidebar, 0);
+ options.div_col = CallService(MS_COLOUR_GET, (WPARAM)&colour_id_divider, 0);
+ }
return 0;
}
@@ -101,10 +123,97 @@ int ModulesLoaded(WPARAM wParam, LPARAM lParam) { }
if(ServiceExists(MS_FONT_REGISTERW)) {
+ font_id_titlew.cbSize = sizeof(FontIDW);
+ font_id_titlew.flags = FIDF_ALLOWEFFECTS;
+ t2w(TranslateT("Tooltips"), font_id_titlew.group, 64);
+ t2w(TranslateT("Title"), font_id_titlew.name, 64);
+ strcpy(font_id_titlew.dbSettingsGroup, MODULE);
+ strcpy(font_id_titlew.prefix, "FontFirst");
+ font_id_titlew.order = 0;
+
+ font_id_titlew.deffontsettings.charset = DEFAULT_CHARSET;
+ font_id_titlew.deffontsettings.size = -14;
+ font_id_titlew.deffontsettings.style = DBFONTF_BOLD;
+ font_id_titlew.deffontsettings.colour = RGB(255, 0, 0);
+ font_id_titlew.flags |= FIDF_DEFAULTVALID;
+
+ font_id_labelsw.cbSize = sizeof(FontIDW);
+ font_id_labelsw.flags = FIDF_ALLOWEFFECTS;
+ t2w(TranslateT("Tooltips"), font_id_labelsw.group, 64);
+ t2w(TranslateT("Labels"), font_id_labelsw.name, 64);
+ strcpy(font_id_labelsw.dbSettingsGroup, MODULE);
+ strcpy(font_id_labelsw.prefix, "FontLabels");
+ font_id_labelsw.order = 1;
+
+ font_id_labelsw.deffontsettings.charset = DEFAULT_CHARSET;
+ font_id_labelsw.deffontsettings.size = -12;
+ font_id_labelsw.deffontsettings.style = DBFONTF_ITALIC;
+ font_id_labelsw.deffontsettings.colour = RGB(128, 128, 128);
+ font_id_labelsw.flags |= FIDF_DEFAULTVALID;
+
+ font_id_valuesw.cbSize = sizeof(FontIDW);
+ font_id_valuesw.flags = FIDF_ALLOWEFFECTS;
+ t2w(TranslateT("Tooltips"), font_id_valuesw.group, 64);
+ t2w(TranslateT("Values"), font_id_valuesw.name, 64);
+ strcpy(font_id_valuesw.dbSettingsGroup, MODULE);
+ strcpy(font_id_valuesw.prefix, "FontValues");
+ font_id_valuesw.order = 2;
+
+ font_id_valuesw.deffontsettings.charset = DEFAULT_CHARSET;
+ font_id_valuesw.deffontsettings.size = -12;
+ font_id_valuesw.deffontsettings.style = 0;
+ font_id_valuesw.deffontsettings.colour = RGB(0, 0, 0);
+ font_id_valuesw.flags |= FIDF_DEFAULTVALID;
+
+ CallService(MS_FONT_REGISTERW, (WPARAM)&font_id_titlew, 0);
+ CallService(MS_FONT_REGISTERW, (WPARAM)&font_id_labelsw, 0);
+ CallService(MS_FONT_REGISTERW, (WPARAM)&font_id_valuesw, 0);
+
+ colour_id_bgw.cbSize = sizeof(ColourIDW);
+ t2w(TranslateT("Tooltips"), colour_id_bgw.group, 64);
+ t2w(TranslateT("Background"), colour_id_bgw.name, 64);
+ strcpy(colour_id_bgw.dbSettingsGroup, MODULE);
+ strcpy(colour_id_bgw.setting, "ColourBg");
+ colour_id_bgw.defcolour = RGB(219, 219, 219);
+ colour_id_bgw.order = 0;
+
+ colour_id_borderw.cbSize = sizeof(ColourIDW);
+ t2w(TranslateT("Tooltips"), colour_id_borderw.group, 64);
+ t2w(TranslateT("Border"), colour_id_borderw.name, 64);
+ strcpy(colour_id_borderw.dbSettingsGroup, MODULE);
+ strcpy(colour_id_borderw.setting, "BorderCol");
+ colour_id_borderw.defcolour = 0;
+ colour_id_borderw.order = 0;
+
+ colour_id_dividerw.cbSize = sizeof(ColourIDW);
+ t2w(TranslateT("Tooltips"), colour_id_dividerw.group, 64);
+ t2w(TranslateT("Dividers"), colour_id_dividerw.name, 64);
+ strcpy(colour_id_dividerw.dbSettingsGroup, MODULE);
+ strcpy(colour_id_dividerw.setting, "DividerCol");
+ colour_id_dividerw.defcolour = 0;
+ colour_id_dividerw.order = 0;
+
+ colour_id_sidebarw.cbSize = sizeof(ColourIDW);
+ t2w(TranslateT("Tooltips"), colour_id_sidebarw.group, 64);
+ t2w(TranslateT("Sidebar"), colour_id_sidebarw.name, 64);
+ strcpy(colour_id_sidebarw.dbSettingsGroup, MODULE);
+ strcpy(colour_id_sidebarw.setting, "SidebarCol");
+ colour_id_sidebarw.defcolour = RGB(192, 192, 192);
+ colour_id_sidebarw.order = 0;
+
+ CallService(MS_COLOUR_REGISTERT, (WPARAM)&colour_id_bgw, 0);
+ CallService(MS_COLOUR_REGISTERT, (WPARAM)&colour_id_borderw, 0);
+ CallService(MS_COLOUR_REGISTERT, (WPARAM)&colour_id_dividerw, 0);
+ CallService(MS_COLOUR_REGISTERT, (WPARAM)&colour_id_sidebarw, 0);
+
+ ReloadFont(0, 0);
+
+ HookEvent(ME_FONT_RELOAD, ReloadFont);
+ } else if(ServiceExists(MS_FONT_REGISTER)) {
font_id_title.cbSize = sizeof(FontIDW);
font_id_title.flags = FIDF_ALLOWEFFECTS;
- wcscpy(font_id_title.group, TranslateT("Tooltips"));
- wcscpy(font_id_title.name, TranslateT("Title"));
+ t2a(TranslateT("Tooltips"), font_id_title.group, 64);
+ t2a(TranslateT("Title"), font_id_title.name, 64);
strcpy(font_id_title.dbSettingsGroup, MODULE);
strcpy(font_id_title.prefix, "FontFirst");
font_id_title.order = 0;
@@ -117,8 +226,8 @@ int ModulesLoaded(WPARAM wParam, LPARAM lParam) { font_id_labels.cbSize = sizeof(FontIDW);
font_id_labels.flags = FIDF_ALLOWEFFECTS;
- wcscpy(font_id_labels.group, TranslateT("Tooltips"));
- wcscpy(font_id_labels.name, TranslateT("Labels"));
+ t2a(TranslateT("Tooltips"), font_id_labels.group, 64);
+ t2a(TranslateT("Labels"), font_id_labels.name, 64);
strcpy(font_id_labels.dbSettingsGroup, MODULE);
strcpy(font_id_labels.prefix, "FontLabels");
font_id_labels.order = 1;
@@ -131,8 +240,8 @@ int ModulesLoaded(WPARAM wParam, LPARAM lParam) { font_id_values.cbSize = sizeof(FontIDW);
font_id_values.flags = FIDF_ALLOWEFFECTS;
- wcscpy(font_id_values.group, TranslateT("Tooltips"));
- wcscpy(font_id_values.name, TranslateT("Values"));
+ t2a(TranslateT("Tooltips"), font_id_values.group, 64);
+ t2a(TranslateT("Values"), font_id_values.name, 64);
strcpy(font_id_values.dbSettingsGroup, MODULE);
strcpy(font_id_values.prefix, "FontValues");
font_id_values.order = 2;
@@ -143,46 +252,46 @@ int ModulesLoaded(WPARAM wParam, LPARAM lParam) { font_id_values.deffontsettings.colour = RGB(0, 0, 0);
font_id_values.flags |= FIDF_DEFAULTVALID;
- CallService(MS_FONT_REGISTERW, (WPARAM)&font_id_title, 0);
- CallService(MS_FONT_REGISTERW, (WPARAM)&font_id_labels, 0);
- CallService(MS_FONT_REGISTERW, (WPARAM)&font_id_values, 0);
+ CallService(MS_FONT_REGISTER, (WPARAM)&font_id_title, 0);
+ CallService(MS_FONT_REGISTER, (WPARAM)&font_id_labels, 0);
+ CallService(MS_FONT_REGISTER, (WPARAM)&font_id_values, 0);
colour_id_bg.cbSize = sizeof(ColourIDW);
- wcscpy(colour_id_bg.group, TranslateT("Tooltips"));
- wcscpy(colour_id_bg.name, TranslateT("Background"));
+ t2a(TranslateT("Tooltips"), colour_id_bg.group, 64);
+ t2a(TranslateT("Background"), colour_id_bg.name, 64);
strcpy(colour_id_bg.dbSettingsGroup, MODULE);
strcpy(colour_id_bg.setting, "ColourBg");
colour_id_bg.defcolour = RGB(219, 219, 219);
colour_id_bg.order = 0;
colour_id_border.cbSize = sizeof(ColourIDW);
- wcscpy(colour_id_border.group, TranslateT("Tooltips"));
- wcscpy(colour_id_border.name, TranslateT("Border"));
+ t2a(TranslateT("Tooltips"), colour_id_border.group, 64);
+ t2a(TranslateT("Border"), colour_id_border.name, 64);
strcpy(colour_id_border.dbSettingsGroup, MODULE);
strcpy(colour_id_border.setting, "BorderCol");
colour_id_border.defcolour = 0;
colour_id_border.order = 0;
colour_id_divider.cbSize = sizeof(ColourIDW);
- wcscpy(colour_id_divider.group, TranslateT("Tooltips"));
- wcscpy(colour_id_divider.name, TranslateT("Dividers"));
+ t2a(TranslateT("Tooltips"), colour_id_divider.group, 64);
+ t2a(TranslateT("Dividers"), colour_id_divider.name, 64);
strcpy(colour_id_divider.dbSettingsGroup, MODULE);
strcpy(colour_id_divider.setting, "DividerCol");
colour_id_divider.defcolour = 0;
colour_id_divider.order = 0;
colour_id_sidebar.cbSize = sizeof(ColourIDW);
- wcscpy(colour_id_sidebar.group, TranslateT("Tooltips"));
- wcscpy(colour_id_sidebar.name, TranslateT("Sidebar"));
+ t2a(TranslateT("Tooltips"), colour_id_sidebar.group, 64);
+ t2a(TranslateT("Sidebar"), colour_id_sidebar.name, 64);
strcpy(colour_id_sidebar.dbSettingsGroup, MODULE);
strcpy(colour_id_sidebar.setting, "SidebarCol");
colour_id_sidebar.defcolour = RGB(192, 192, 192);
colour_id_sidebar.order = 0;
- CallService(MS_COLOUR_REGISTERW, (WPARAM)&colour_id_bg, 0);
- CallService(MS_COLOUR_REGISTERW, (WPARAM)&colour_id_border, 0);
- CallService(MS_COLOUR_REGISTERW, (WPARAM)&colour_id_divider, 0);
- CallService(MS_COLOUR_REGISTERW, (WPARAM)&colour_id_sidebar, 0);
+ CallService(MS_COLOUR_REGISTER, (WPARAM)&colour_id_bg, 0);
+ CallService(MS_COLOUR_REGISTER, (WPARAM)&colour_id_border, 0);
+ CallService(MS_COLOUR_REGISTER, (WPARAM)&colour_id_divider, 0);
+ CallService(MS_COLOUR_REGISTER, (WPARAM)&colour_id_sidebar, 0);
ReloadFont(0, 0);
@@ -249,6 +358,8 @@ extern "C" int TIPPER_API Load(PLUGINLINK *link) { pluginLink = link;
DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &mainThread, THREAD_SET_CONTEXT, FALSE, 0);
+ set_codepage();
+
// get the internal malloc/free()
memoryManagerInterface.cbSize = sizeof(memoryManagerInterface);
CallService(MS_SYSTEM_GET_MMI, 0, (LPARAM)&memoryManagerInterface);
diff --git a/tipper/tipper_8.vcproj b/tipper/tipper_8.vcproj index 0ba6fa1..51e763e 100644 --- a/tipper/tipper_8.vcproj +++ b/tipper/tipper_8.vcproj @@ -20,7 +20,7 @@ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
- CharacterSet="1"
+ CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
@@ -41,13 +41,12 @@ Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../include"
- PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;TIPPER_EXPORTS;_UNICODE;UNICODE;MICROSOFT_LAYER_FOR_UNICODE=1"
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;TIPPER_EXPORTS;MICROSOFT_LAYER_FOR_UNICODE=1"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="common.h"
- WarningLevel="3"
DebugInformationFormat="4"
DisableSpecificWarnings="4996"
/>
@@ -128,7 +127,6 @@ RuntimeLibrary="0"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="common.h"
- WarningLevel="3"
DebugInformationFormat="3"
DisableSpecificWarnings="4996"
/>
@@ -252,6 +250,10 @@ </FileConfiguration>
</File>
<File
+ RelativePath=".\str_utils.cpp"
+ >
+ </File>
+ <File
RelativePath=".\subst.cpp"
>
</File>
@@ -290,6 +292,10 @@ >
</File>
<File
+ RelativePath=".\m_tipper.h"
+ >
+ </File>
+ <File
RelativePath=".\message_pump.h"
>
</File>
@@ -306,6 +312,10 @@ >
</File>
<File
+ RelativePath=".\str_utils.h"
+ >
+ </File>
+ <File
RelativePath=".\subst.h"
>
</File>
diff --git a/tipper/translations.cpp b/tipper/translations.cpp index f22e726..4e5dbd8 100644 --- a/tipper/translations.cpp +++ b/tipper/translations.cpp @@ -2,6 +2,7 @@ #include "translations.h" #include <winsock.h> #include <time.h> +#include "str_utils.h" int num_tfuncs = 0; DBVTranslation *translations = 0; @@ -21,7 +22,7 @@ void AddTranslation(DBVTranslation *new_trans) { #ifdef _UNICODE WideCharToMultiByte(code_page, 0, new_trans->name, -1, setting, 256, 0, 0); #else - strncpy(setting, new_trans.name, 256); + strncpy(setting, new_trans->name, 256); #endif if(_tcscmp(new_trans->name, _T("[No translation]")) == 0) @@ -56,20 +57,20 @@ TCHAR *null_translation(HANDLE hContact, const char *module_name, const char *se DBFreeVariant(&dbv); return 0; case DBVT_BYTE: - _itow(dbv.bVal, buff, 10); + _itot(dbv.bVal, buff, 10); break; case DBVT_WORD: - _ltow(dbv.wVal, buff, 10); + _ltot(dbv.wVal, buff, 10); break; case DBVT_DWORD: - _ltow(dbv.dVal, buff, 10); + _ltot(dbv.dVal, buff, 10); break; case DBVT_ASCIIZ: - MultiByteToWideChar(code_page, 0, dbv.pszVal, -1, buff, bufflen); + a2t(dbv.pszVal, buff, bufflen); buff[bufflen - 1] = 0; break; case DBVT_UTF8: - MultiByteToWideChar(CP_UTF8, 0, dbv.pszVal, -1, buff, bufflen); + u2t(dbv.pszVal, buff, bufflen); buff[bufflen - 1] = 0; break; //case DBVT_WCHAR: @@ -85,7 +86,7 @@ TCHAR *null_translation(HANDLE hContact, const char *module_name, const char *se } DBFreeVariant(&dbv); - if(wcslen(buff) == 0) + if(_tcslen(buff) == 0) return 0; return buff; } @@ -107,7 +108,7 @@ TCHAR *timestamp_to_short_date(HANDLE hContact, const char *module_name, const c dbt.szDest = buffA; dbt.szFormat = "d"; CallService(MS_DB_TIME_TIMESTAMPTOSTRING, (WPARAM)ts, (LPARAM)&dbt); - MultiByteToWideChar(code_page, 0, buffA, -1, buff, bufflen); + a2t(buffA, buff, bufflen); } buff[bufflen - 1] = 0; @@ -131,7 +132,7 @@ TCHAR *timestamp_to_long_date(HANDLE hContact, const char *module_name, const ch dbt.szDest = buffA; dbt.szFormat = "D"; CallService(MS_DB_TIME_TIMESTAMPTOSTRING, (WPARAM)ts, (LPARAM)&dbt); - MultiByteToWideChar(code_page, 0, buffA, -1, buff, bufflen); + a2t(buffA, buff, bufflen); } buff[bufflen - 1] = 0; @@ -155,7 +156,7 @@ TCHAR *timestamp_to_time(HANDLE hContact, const char *module_name, const char *s dbt.szDest = buffA; dbt.szFormat = "s"; CallService(MS_DB_TIME_TIMESTAMPTOSTRING, (WPARAM)ts, (LPARAM)&dbt); - MultiByteToWideChar(code_page, 0, buffA, -1, buff, bufflen); + a2t(buffA, buff, bufflen); } buff[bufflen - 1] = 0; @@ -179,7 +180,7 @@ TCHAR *timestamp_to_time_no_secs(HANDLE hContact, const char *module_name, const dbt.szDest = buffA; dbt.szFormat = "t"; CallService(MS_DB_TIME_TIMESTAMPTOSTRING, (WPARAM)ts, (LPARAM)&dbt); - MultiByteToWideChar(code_page, 0, buffA, -1, buff, bufflen); + a2t(buffA, buff, bufflen); } return buff; @@ -223,7 +224,7 @@ TCHAR *seconds_to_time_difference(HANDLE hContact, const char *module_name, cons TCHAR *word_to_status_desc(HANDLE hContact, const char *module_name, const char *setting_name, TCHAR *buff, int bufflen) { int status = DBGetContactSettingWord(hContact, module_name, setting_name, ID_STATUS_OFFLINE); char *strptr = (char *)CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, (WPARAM)status, (LPARAM)0); - MultiByteToWideChar(code_page, 0, strptr, -1, buff, bufflen); + a2t(strptr, buff, bufflen); buff[bufflen - 1] = 0; return buff; } @@ -246,7 +247,7 @@ TCHAR *byte_to_yesno(HANDLE hContact, const char *module_name, const char *setti } TCHAR *byte_to_mf(HANDLE hContact, const char *module_name, const char *setting_name, TCHAR *buff, int bufflen) { - BYTE val = DBGetContactSettingByte(hContact, module_name, setting_name, 0); + BYTE val = (BYTE)DBGetContactSettingByte(hContact, module_name, setting_name, 0); if(val == 'F') _tcsncpy(buff, TranslateT("Female"), bufflen); else if(val == 'M') @@ -260,11 +261,11 @@ TCHAR *byte_to_mf(HANDLE hContact, const char *module_name, const char *setting_ TCHAR *word_to_country(HANDLE hContact, const char *module_name, const char *setting_name, TCHAR *buff, int bufflen) { char *cname = 0; - WORD cid = DBGetContactSettingWord(hContact, module_name, setting_name, (WORD)-1); + WORD cid = (WORD)DBGetContactSettingWord(hContact, module_name, setting_name, (WORD)-1); if(cid != (WORD)-1 && ServiceExists(MS_UTILS_GETCOUNTRYBYNUMBER) && (cname = (char *)CallService(MS_UTILS_GETCOUNTRYBYNUMBER, cid, 0)) != 0) { if(strcmp(cname, "Unknown") == 0) return 0; - MultiByteToWideChar(code_page, 0, Translate(cname), -1, buff, bufflen); + a2t(cname, buff, bufflen); buff[bufflen - 1] = 0; return buff; } @@ -276,7 +277,7 @@ TCHAR *dword_to_ip(HANDLE hContact, const char *module_name, const char *setting if(ip) { in_addr in; in.S_un.S_addr = htonl(ip); - MultiByteToWideChar(code_page, 0, inet_ntoa(in), -1, buff, bufflen); + a2t(inet_ntoa(in), buff, bufflen); buff[bufflen - 1] = 0; return buff; } diff --git a/tipper/version.h b/tipper/version.h index e6ea42e..21dc46d 100644 --- a/tipper/version.h +++ b/tipper/version.h @@ -2,9 +2,9 @@ #define __VERSION_H_INCLUDED
#define __MAJOR_VERSION 0
-#define __MINOR_VERSION 2
-#define __RELEASE_NUM 4
-#define __BUILD_NUM 4
+#define __MINOR_VERSION 3
+#define __RELEASE_NUM 0
+#define __BUILD_NUM 0
#define __FILEVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM
#define __FILEVERSION_STRING_DOTS __MAJOR_VERSION.__MINOR_VERSION.__RELEASE_NUM.__BUILD_NUM
|