From e2c2a1f5a84c6c9b705dc85c6a2dd1f97edd57e4 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 22 May 2015 16:04:17 +0000 Subject: T2Utf - handy replacement for ptrA git-svn-id: http://svn.miranda-ng.org/main/trunk@13758 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/TabSRMM/src/globals.cpp | 2 +- plugins/TabSRMM/src/infopanel.cpp | 5 +--- plugins/TabSRMM/src/msgdialog.cpp | 58 ++++++++++++++++++++------------------- plugins/TabSRMM/src/sendqueue.cpp | 8 ++---- plugins/TabSRMM/src/srmm.cpp | 9 +----- plugins/TabSRMM/src/themeio.cpp | 18 ++++-------- plugins/TabSRMM/src/utils.cpp | 4 +-- 7 files changed, 42 insertions(+), 62 deletions(-) (limited to 'plugins/TabSRMM/src') diff --git a/plugins/TabSRMM/src/globals.cpp b/plugins/TabSRMM/src/globals.cpp index 074835e644..d64543ff14 100644 --- a/plugins/TabSRMM/src/globals.cpp +++ b/plugins/TabSRMM/src/globals.cpp @@ -605,7 +605,7 @@ void CGlobals::logStatusChange(WPARAM wParam, const CContactCache *c) else text.Format(TranslateT("changed status from %s to %s."), szOldStatus, szNewStatus); - ptrA szMsg(mir_utf8encodeT(text)); + T2Utf szMsg(text); DBEVENTINFO dbei = { sizeof(dbei) }; dbei.pBlob = (PBYTE)(char*)szMsg; dbei.cbBlob = (int)mir_strlen(szMsg) + 1; diff --git a/plugins/TabSRMM/src/infopanel.cpp b/plugins/TabSRMM/src/infopanel.cpp index 9e660bcf3d..caa644f02b 100644 --- a/plugins/TabSRMM/src/infopanel.cpp +++ b/plugins/TabSRMM/src/infopanel.cpp @@ -1326,10 +1326,7 @@ CTip::CTip(const HWND hwndParent, const MCONTACT hContact, const TCHAR *pszText, ::SendMessage(m_hRich, WM_SETFONT, (WPARAM)CInfoPanel::m_ipConfig.hFonts[IPFONTID_STATUS], 0); m_hContact = hContact; - if (pszText) - m_pszText = mir_utf8encodeT(pszText); - else - m_pszText = 0; + m_pszText = mir_utf8encodeT(pszText); m_panel = panel; m_hwndParent = hwndParent; mir_subclassWindow(m_hRich, RichEditProc); diff --git a/plugins/TabSRMM/src/msgdialog.cpp b/plugins/TabSRMM/src/msgdialog.cpp index 37ec46d0ab..6ff33acddf 100644 --- a/plugins/TabSRMM/src/msgdialog.cpp +++ b/plugins/TabSRMM/src/msgdialog.cpp @@ -609,7 +609,7 @@ static LRESULT CALLBACK MessageEditSubclassProc(HWND hwnd, UINT msg, WPARAM wPar if (OpenClipboard(hwnd)) { HANDLE hClip = GetClipboardData(CF_TEXT); if (hClip) { - if (mir_strlen((char*)hClip) > mwdat->nMax) { + if ((int)mir_strlen((char*)hClip) > mwdat->nMax) { TCHAR szBuffer[512]; if (M.GetByte("autosplit", 0)) mir_sntprintf(szBuffer, SIZEOF(szBuffer), TranslateT("WARNING: The message you are trying to paste exceeds the message size limit for the active protocol. It will be sent in chunks of max %d characters"), mwdat->nMax - 10); @@ -2667,34 +2667,36 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP int bufSize = WideCharToMultiByte(dat->codePage, 0, decoded, -1, dat->sendBuffer, 0, 0, 0); int flags = 0; - char *utfResult = mir_utf8encodeT(decoded); - size_t memRequired = mir_strlen(utfResult) + 1; - - // try to detect RTL - HWND hwndEdit = GetDlgItem(hwndDlg, IDC_MESSAGE); - SendMessage(hwndEdit, WM_SETREDRAW, FALSE, 0); - - PARAFORMAT2 pf2; - memset(&pf2, 0, sizeof(PARAFORMAT2)); - pf2.cbSize = sizeof(pf2); - pf2.dwMask = PFM_RTLPARA; - SendMessage(hwndEdit, EM_SETSEL, 0, -1); - SendMessage(hwndEdit, EM_GETPARAFORMAT, 0, (LPARAM)&pf2); - if (pf2.wEffects & PFE_RTLPARA) - if (SendQueue::RTL_Detect(decoded)) - flags |= PREF_RTL; - - SendMessage(hwndEdit, WM_SETREDRAW, TRUE, 0); - SendMessage(hwndEdit, EM_SETSEL, -1, -1); - InvalidateRect(hwndEdit, NULL, FALSE); - - if (memRequired > dat->iSendBufferSize) { - dat->sendBuffer = (char *)mir_realloc(dat->sendBuffer, memRequired); - dat->iSendBufferSize = memRequired; - } + size_t memRequired; + { + T2Utf utfResult(decoded); + memRequired = mir_strlen(utfResult) + 1; + + // try to detect RTL + HWND hwndEdit = GetDlgItem(hwndDlg, IDC_MESSAGE); + SendMessage(hwndEdit, WM_SETREDRAW, FALSE, 0); + + PARAFORMAT2 pf2; + memset(&pf2, 0, sizeof(PARAFORMAT2)); + pf2.cbSize = sizeof(pf2); + pf2.dwMask = PFM_RTLPARA; + SendMessage(hwndEdit, EM_SETSEL, 0, -1); + SendMessage(hwndEdit, EM_GETPARAFORMAT, 0, (LPARAM)&pf2); + if (pf2.wEffects & PFE_RTLPARA) + if (SendQueue::RTL_Detect(decoded)) + flags |= PREF_RTL; + + SendMessage(hwndEdit, WM_SETREDRAW, TRUE, 0); + SendMessage(hwndEdit, EM_SETSEL, -1, -1); + InvalidateRect(hwndEdit, NULL, FALSE); + + if (memRequired > dat->iSendBufferSize) { + dat->sendBuffer = (char *)mir_realloc(dat->sendBuffer, memRequired); + dat->iSendBufferSize = memRequired; + } - memcpy(dat->sendBuffer, utfResult, memRequired); - mir_free(utfResult); + memcpy(dat->sendBuffer, (char*)utfResult, memRequired); + } if (memRequired == 0 || dat->sendBuffer[0] == 0) break; diff --git a/plugins/TabSRMM/src/sendqueue.cpp b/plugins/TabSRMM/src/sendqueue.cpp index 4e9471f662..2795233135 100644 --- a/plugins/TabSRMM/src/sendqueue.cpp +++ b/plugins/TabSRMM/src/sendqueue.cpp @@ -681,7 +681,7 @@ int SendQueue::doSendLater(int iJobIndex, TWindowData *dat, MCONTACT hContact, b else szNote = TranslateT("The send later feature is not available on this protocol."); - char *utfText = mir_utf8encodeT(szNote); + T2Utf utfText(szNote); DBEVENTINFO dbei; dbei.cbSize = sizeof(dbei); dbei.eventType = EVENTTYPE_MESSAGE; @@ -689,7 +689,7 @@ int SendQueue::doSendLater(int iJobIndex, TWindowData *dat, MCONTACT hContact, b dbei.szModule = GetContactProto(dat->hContact); dbei.timestamp = time(NULL); dbei.cbBlob = (int)mir_strlen(utfText) + 1; - dbei.pBlob = (PBYTE)utfText; + dbei.pBlob = (PBYTE)(char*)utfText; StreamInEvents(dat->hwnd, 0, 1, 1, &dbei); if (dat->hDbEventFirst == NULL) SendMessage(dat->hwnd, DM_REMAKELOG, 0, 0); @@ -700,7 +700,6 @@ int SendQueue::doSendLater(int iJobIndex, TWindowData *dat, MCONTACT hContact, b SendDlgItemMessage(dat->hwnd, IDC_SAVE, BM_SETIMAGE, IMAGE_ICON, (LPARAM)PluginConfig.g_buttonBarIcons[ICON_BUTTON_CANCEL]); SendDlgItemMessage(dat->hwnd, IDC_SAVE, BUTTONADDTOOLTIP, (WPARAM)pszIDCSAVE_close, BATF_TCHAR); dat->dwFlags &= ~MWF_SAVEBTN_SAV; - mir_free(utfText); if (!fAvail) return 0; @@ -720,7 +719,7 @@ int SendQueue::doSendLater(int iJobIndex, TWindowData *dat, MCONTACT hContact, b } else mir_sntprintf(tszHeader, SIZEOF(tszHeader), _T("M%d|"), time(0)); - char *utf_header = mir_utf8encodeT(tszHeader); + T2Utf utf_header(tszHeader); size_t required = mir_strlen(utf_header) + mir_strlen(job->szSendBuffer) + 10; char *tszMsg = reinterpret_cast(mir_alloc(required)); @@ -732,7 +731,6 @@ int SendQueue::doSendLater(int iJobIndex, TWindowData *dat, MCONTACT hContact, b mir_snprintf(tszMsg, required, "%s%s", utf_header, job->szSendBuffer); sendLater->addJob(tszMsg, hContact); } - mir_free(utf_header); mir_free(tszMsg); if (fIsSendLater) { diff --git a/plugins/TabSRMM/src/srmm.cpp b/plugins/TabSRMM/src/srmm.cpp index afe680f635..c98b28c076 100644 --- a/plugins/TabSRMM/src/srmm.cpp +++ b/plugins/TabSRMM/src/srmm.cpp @@ -125,15 +125,8 @@ int _DebugTraceW(const wchar_t *fmt, ...) mir_snprintf(szLogFileName, SIZEOF(szLogFileName), "%s\\%s", szDataPath, "tabsrmm_debug.log"); f = fopen(szLogFileName, "a+"); if (f) { - char *szDebug = mir_utf8encodeT(debug); fputs(tszTime, f); - if (szDebug != NULL) { - fputs(szDebug, f); - mir_free(szDebug); - } - else { - fputs("mir_utf8encodeT() fail in _DebugTraceW()", f); - } + fputs(T2Utf(debug), f); fputs("\n", f); fclose(f); } diff --git a/plugins/TabSRMM/src/themeio.cpp b/plugins/TabSRMM/src/themeio.cpp index fe1f0d3f1a..6a1b1531f1 100644 --- a/plugins/TabSRMM/src/themeio.cpp +++ b/plugins/TabSRMM/src/themeio.cpp @@ -225,19 +225,11 @@ void TSAPI WriteThemeToINI(const TCHAR *szIniFilenameT, TWindowData *dat) WritePrivateProfileStringA("Message Log", "ExtraMicroLF", _itoa(M.GetByte("extramicrolf", 0), szBuf, 10), szIniFilename); for (i = 0; i <= TMPL_ERRMSG; i++) { - char *encoded; - if (dat == 0) - encoded = mir_utf8encodeT(LTR_Active.szTemplates[i]); - else - encoded = mir_utf8encodeT(dat->pContainer->ltr_templates->szTemplates[i]); - WritePrivateProfileStringA("Templates", TemplateNames[i], encoded, szIniFilename); - mir_free(encoded); - if (dat == 0) - encoded = mir_utf8encodeT(RTL_Active.szTemplates[i]); - else - encoded = mir_utf8encodeT(dat->pContainer->rtl_templates->szTemplates[i]); - WritePrivateProfileStringA("RTLTemplates", TemplateNames[i], encoded, szIniFilename); - mir_free(encoded); + T2Utf szLTR((dat == 0) ? LTR_Active.szTemplates[i] : dat->pContainer->ltr_templates->szTemplates[i]); + WritePrivateProfileStringA("Templates", TemplateNames[i], szLTR, szIniFilename); + + T2Utf szRTL((dat == 0) ? RTL_Active.szTemplates[i] : dat->pContainer->rtl_templates->szTemplates[i]); + WritePrivateProfileStringA("RTLTemplates", TemplateNames[i], szRTL, szIniFilename); } for (i = 0; i < CUSTOM_COLORS; i++) { mir_snprintf(szTemp, SIZEOF(szTemp), "cc%d", i + 1); diff --git a/plugins/TabSRMM/src/utils.cpp b/plugins/TabSRMM/src/utils.cpp index 55aeea166a..a13c263edd 100644 --- a/plugins/TabSRMM/src/utils.cpp +++ b/plugins/TabSRMM/src/utils.cpp @@ -1293,9 +1293,7 @@ INT_PTR CALLBACK CWarning::dlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP str->insert(pos, L"\\line "); } - char *utf8 = mir_utf8encodeT(str->c_str()); - ::SendDlgItemMessage(hwnd, IDC_WARNTEXT, EM_SETTEXTEX, (WPARAM)&stx, (LPARAM)utf8); - mir_free(utf8); + ::SendDlgItemMessage(hwnd, IDC_WARNTEXT, EM_SETTEXTEX, (WPARAM)&stx, T2Utf(str->c_str())); delete str; ::SetDlgItemTextW(hwnd, IDC_CAPTION, m_szTitle); -- cgit v1.2.3