diff options
author | George Hazan <ghazan@miranda.im> | 2017-05-01 11:58:04 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-05-01 11:58:04 +0300 |
commit | 28d98a38c756991d461301efb483e4980a2def69 (patch) | |
tree | d317b4a941832d3cc4137a6f597c029757913987 | |
parent | d75d5e8706b06457b799831448f282818233abe9 (diff) |
Utils_IsRtl - core function to detect RTL direcction
-rw-r--r-- | include/m_utils.h | 10 | ||||
-rw-r--r-- | libs/win32/mir_core.lib | bin | 317344 -> 317544 bytes | |||
-rw-r--r-- | libs/win64/mir_core.lib | bin | 318334 -> 318516 bytes | |||
-rw-r--r-- | plugins/Scriver/src/msgdialog.cpp | 21 | ||||
-rw-r--r-- | plugins/Scriver/src/msglog.cpp | 3 | ||||
-rw-r--r-- | plugins/TabSRMM/src/msgdialog.cpp | 2 | ||||
-rw-r--r-- | plugins/TabSRMM/src/sendqueue.cpp | 22 | ||||
-rw-r--r-- | plugins/TabSRMM/src/sendqueue.h | 1 | ||||
-rw-r--r-- | src/core/stdmsg/src/msgdialog.cpp | 15 | ||||
-rw-r--r-- | src/mir_core/src/mir_core.def | 1 | ||||
-rw-r--r-- | src/mir_core/src/mir_core64.def | 1 | ||||
-rw-r--r-- | src/mir_core/src/utils.cpp | 13 |
12 files changed, 26 insertions, 63 deletions
diff --git a/include/m_utils.h b/include/m_utils.h index 0b5b29468c..549cc18815 100644 --- a/include/m_utils.h +++ b/include/m_utils.h @@ -303,13 +303,17 @@ EXTERN_C MIR_CORE_DLL(int) PathIsAbsoluteW(const wchar_t *pSrc); /////////////////////////////////////////////////////////////////////////////////////////
// Generates Random number of any length
-// wParam = size - length of the random number to generate
-// lParam = (LPARAM)(char*)pszArray - pointer to array to fill with random number
-// Always returns 0
+// cbLen = length of the random number to generate
+// pszDest = pointer to array to fill with random number
EXTERN_C MIR_CORE_DLL(void) Utils_GetRandom(void *pszDest, size_t cbLen);
/////////////////////////////////////////////////////////////////////////////////////////
+// Checks if a string is RTL
+
+EXTERN_C MIR_CORE_DLL(bool) Utils_IsRtl(const wchar_t *pszwText);
+
+/////////////////////////////////////////////////////////////////////////////////////////
// Replace variables in text
// wParam = (char*/wchar_t*/wchar_t*)string (depends on RVF_UNICODE/RVF_TCHAR flag)
// lParam = (REPLACEVARSDATA *) data about variables, item with key = 0 terminates the list
diff --git a/libs/win32/mir_core.lib b/libs/win32/mir_core.lib Binary files differindex 184319b633..34233a6070 100644 --- a/libs/win32/mir_core.lib +++ b/libs/win32/mir_core.lib diff --git a/libs/win64/mir_core.lib b/libs/win64/mir_core.lib Binary files differindex 7eadc5e162..ba1d3709a7 100644 --- a/libs/win64/mir_core.lib +++ b/libs/win64/mir_core.lib diff --git a/plugins/Scriver/src/msgdialog.cpp b/plugins/Scriver/src/msgdialog.cpp index b270d3fac1..fb9c8ed2f0 100644 --- a/plugins/Scriver/src/msgdialog.cpp +++ b/plugins/Scriver/src/msgdialog.cpp @@ -91,25 +91,6 @@ static wchar_t* GetQuotedTextW(wchar_t *text) return out;
}
-int RTL_Detect(WCHAR *pszwText)
-{
- size_t iLen = mir_wstrlen(pszwText);
-
- WORD *infoTypeC2 = (WORD *)mir_calloc(sizeof(WORD) * (iLen + 2));
- if (infoTypeC2) {
- GetStringTypeW(CT_CTYPE2, pszwText, (int)iLen, infoTypeC2);
-
- for (size_t i = 0; i < iLen; i++) {
- if (infoTypeC2[i] == C2_RIGHTTOLEFT) {
- mir_free(infoTypeC2);
- return 1;
- }
- }
- mir_free(infoTypeC2);
- }
- return 0;
-}
-
static void AddToFileList(wchar_t ***pppFiles, int *totalCount, const wchar_t* szFilename)
{
*pppFiles = (wchar_t**)mir_realloc(*pppFiles, (++*totalCount + 1)*sizeof(wchar_t*));
@@ -465,7 +446,7 @@ void CSrmmWindow::onClick_Ok(CCtrlButton *pButton) gt.cb = bufSize * sizeof(wchar_t);
gt.codepage = 1200; // Unicode
m_message.SendMsg(EM_GETTEXTEX, (WPARAM)>, ptszUnicode);
- if (RTL_Detect(ptszUnicode))
+ if (Utils_IsRtl(ptszUnicode))
msi.flags |= PREF_RTL;
msi.sendBuffer = mir_utf8encodeW(ptszUnicode);
diff --git a/plugins/Scriver/src/msglog.cpp b/plugins/Scriver/src/msglog.cpp index a96257bef1..f2beec5ee5 100644 --- a/plugins/Scriver/src/msglog.cpp +++ b/plugins/Scriver/src/msglog.cpp @@ -27,7 +27,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define LOGICON_MSG_OUT 1
#define LOGICON_MSG_NOTICE 2
-extern int RTL_Detect(WCHAR *pszwText);
static int logPixelSY;
static char* pLogIconBmpBits[3];
static HIMAGELIST g_hImageList;
@@ -157,7 +156,7 @@ EventData* getEventFromDB(CSrmmWindow *dat, MCONTACT hContact, MEVENT hDbEvent) }
else evt->pszTextT = DbEvent_GetTextW(&dbei, CP_UTF8);
- if (!dat->m_bUseRtl && RTL_Detect(evt->pszTextT))
+ if (!dat->m_bUseRtl && Utils_IsRtl(evt->pszTextT))
evt->dwFlags |= IEEDF_RTL;
mir_free(dbei.pBlob);
diff --git a/plugins/TabSRMM/src/msgdialog.cpp b/plugins/TabSRMM/src/msgdialog.cpp index ec495316bc..9ce6c0605a 100644 --- a/plugins/TabSRMM/src/msgdialog.cpp +++ b/plugins/TabSRMM/src/msgdialog.cpp @@ -1122,7 +1122,7 @@ void CSrmmWindow::onClick_Ok(CCtrlButton*) int flags = 0;
if (pf2.wEffects & PFE_RTLPARA)
- if (SendQueue::RTL_Detect(decoded))
+ if (Utils_IsRtl(decoded))
flags |= PREF_RTL;
SendMessage(hwndEdit, WM_SETREDRAW, TRUE, 0);
diff --git a/plugins/TabSRMM/src/sendqueue.cpp b/plugins/TabSRMM/src/sendqueue.cpp index 787e815da8..4292b89b9c 100644 --- a/plugins/TabSRMM/src/sendqueue.cpp +++ b/plugins/TabSRMM/src/sendqueue.cpp @@ -412,28 +412,6 @@ void SendQueue::recallFailed(CTabBaseDlg *dat, int iEntry) const SendDlgItemMessage(dat->GetHwnd(), IDC_SRMM_MESSAGE, EM_SETSEL, -1, -1); } -///////////////////////////////////////////////////////////////////////////////////////// -// searches string for characters typical for RTL text(hebrew and other RTL languages - -int SendQueue::RTL_Detect(const wchar_t *pszwText) -{ - size_t iLen = mir_wstrlen(pszwText); - - WORD *infoTypeC2 = (WORD*)mir_calloc(sizeof(WORD) * (iLen + 2)); - if (infoTypeC2 == nullptr) - return 0; - - GetStringTypeW(CT_CTYPE2, pszwText, (int)iLen, infoTypeC2); - - int n = 0; - for (size_t i = 0; i < iLen; i++) - if (infoTypeC2[i] == C2_RIGHTTOLEFT) - n++; - - mir_free(infoTypeC2); - return(n >= 2 ? 1 : 0); -} - int SendQueue::ackMessage(CTabBaseDlg *dat, WPARAM wParam, LPARAM lParam) { ACKDATA *ack = (ACKDATA *)lParam; diff --git a/plugins/TabSRMM/src/sendqueue.h b/plugins/TabSRMM/src/sendqueue.h index 603ced7c2b..f6e48e769e 100644 --- a/plugins/TabSRMM/src/sendqueue.h +++ b/plugins/TabSRMM/src/sendqueue.h @@ -98,7 +98,6 @@ public: int doSendLater(int iIndex, CTabBaseDlg *dat, MCONTACT hContact = 0, bool fIsSendLater = true);
// static members
- static int TSAPI RTL_Detect(const wchar_t *pszwText);
static LRESULT TSAPI WarnPendingJobs(unsigned int uNrMessages);
private:
diff --git a/src/core/stdmsg/src/msgdialog.cpp b/src/core/stdmsg/src/msgdialog.cpp index d66a15cc00..e8e58a5fdc 100644 --- a/src/core/stdmsg/src/msgdialog.cpp +++ b/src/core/stdmsg/src/msgdialog.cpp @@ -35,26 +35,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static const UINT sendControls[] = { IDC_SRMM_MESSAGE };
-static int RTL_Detect(const wchar_t *ptszText)
-{
- int iLen = (int)mir_wstrlen(ptszText);
- WORD *infoTypeC2 = (WORD*)alloca(sizeof(WORD)* (iLen + 2));
- GetStringTypeEx(LOCALE_USER_DEFAULT, CT_CTYPE2, ptszText, iLen, infoTypeC2);
-
- for (int i = 0; i < iLen; i++)
- if (infoTypeC2[i] == C2_RIGHTTOLEFT)
- return 1;
-
- return 0;
-}
-
int SendMessageDirect(const wchar_t *szMsg, MCONTACT hContact)
{
if (hContact == 0)
return 0;
int flags = 0;
- if (RTL_Detect(szMsg))
+ if (Utils_IsRtl(szMsg))
flags |= PREF_RTL;
T2Utf sendBuffer(szMsg);
diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index ebc69f8d19..5fd89d1bca 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -1050,3 +1050,4 @@ CallFunctionSync @1170 ?SetReadOnly@CCtrlRichEdit@@QAEX_N@Z @1237 NONAME
?Hide@CDlgBase@@QAEXXZ @1238 NONAME
?Resize@CDlgBase@@QAEXXZ @1239 NONAME
+Utils_IsRtl @1240
diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index 2e5c83b8af..02fa033f13 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -1050,3 +1050,4 @@ CallFunctionSync @1170 ?SetReadOnly@CCtrlRichEdit@@QEAAX_N@Z @1237 NONAME
?Hide@CDlgBase@@QEAAXXZ @1238 NONAME
?Resize@CDlgBase@@QEAAXXZ @1239 NONAME
+Utils_IsRtl @1240
diff --git a/src/mir_core/src/utils.cpp b/src/mir_core/src/utils.cpp index 7b26bb6aab..f2f007d2f4 100644 --- a/src/mir_core/src/utils.cpp +++ b/src/mir_core/src/utils.cpp @@ -536,3 +536,16 @@ MIR_CORE_DLL(void) Utils_GetRandom(void *pszDest, size_t cbLen) p[i] = rand() & 0xFF;
}
}
+
+MIR_CORE_DLL(bool) Utils_IsRtl(const wchar_t *pszwText)
+{
+ size_t iLen = mir_wstrlen(pszwText);
+ mir_ptr<WORD> infoTypeC2((WORD*)mir_calloc(sizeof(WORD) * (iLen + 2)));
+ GetStringTypeW(CT_CTYPE2, pszwText, (int)iLen, infoTypeC2);
+
+ for (size_t i = 0; i < iLen; i++)
+ if (infoTypeC2[i] == C2_RIGHTTOLEFT)
+ return true;
+
+ return false;
+}
|