diff options
author | George Hazan <george.hazan@gmail.com> | 2014-12-02 23:25:04 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-12-02 23:25:04 +0000 |
commit | 4a6753b9df99107d0e83e1ed10f0effe0d00d9db (patch) | |
tree | d3443a04b21f94d68569a8e75beb648e23a75917 /plugins/TranslitSwitcher | |
parent | 4b01e299223c3fdb05d82ecde0117f88f8caa726 (diff) |
bugfix: last symbol got eaten
git-svn-id: http://svn.miranda-ng.org/main/trunk@11225 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/TranslitSwitcher')
-rw-r--r-- | plugins/TranslitSwitcher/src/Layoutproc.cpp | 201 | ||||
-rw-r--r-- | plugins/TranslitSwitcher/src/TranslitSwitcher.h | 1 | ||||
-rw-r--r-- | plugins/TranslitSwitcher/src/Version.h | 16 |
3 files changed, 67 insertions, 151 deletions
diff --git a/plugins/TranslitSwitcher/src/Layoutproc.cpp b/plugins/TranslitSwitcher/src/Layoutproc.cpp index 4925a08638..04a1d20abe 100644 --- a/plugins/TranslitSwitcher/src/Layoutproc.cpp +++ b/plugins/TranslitSwitcher/src/Layoutproc.cpp @@ -39,32 +39,22 @@ bool isItSmiley(unsigned int position) static DWORD CALLBACK StreamOutCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
- static int sendBufferSize;
- char **ppText = (char **)dwCookie;
-
- if (*ppText == NULL)
- sendBufferSize = 0;
-
- *ppText = (char *)mir_realloc(*ppText, size_t(sendBufferSize + cb + 2));
- memcpy(*ppText + sendBufferSize, pbBuff, (size_t)cb);
- sendBufferSize += cb;
- *((TCHAR *)(*ppText + sendBufferSize)) = '\0';
+ TCHAR **ppText = (TCHAR**)dwCookie;
+ *ppText = mir_tstrndup((TCHAR*)pbBuff, cb / sizeof(TCHAR));
*pcb = cb;
return 0;
}
TCHAR* Message_GetFromStream(HWND hwndRtf, DWORD dwPassedFlags)
{
- EDITSTREAM stream = { 0 };
- TCHAR *pszText = NULL;
-
if (hwndRtf == 0)
return NULL;
+ TCHAR *pszText = NULL;
+ EDITSTREAM stream = { 0 };
stream.pfnCallback = StreamOutCallback;
stream.dwCookie = (DWORD_PTR)&pszText;
SendMessage(hwndRtf, EM_STREAMOUT, (WPARAM)dwPassedFlags, (LPARAM)&stream);
-
return pszText;
}
@@ -430,7 +420,7 @@ VOID SwitchLayout(bool lastword) keys[VK_CONTROL] = (HIBYTE(vks) & 2) ? 0xFF : 0x00; // ctrl
keys[VK_MENU] = (HIBYTE(vks) & 4) ? 0xFF : 0x00; // alt
- if (!isItSmiley(i)) {
+ if (!isItSmiley(DWORD(i))) {
TCHAR tchr;
if (ToUnicodeEx(LOBYTE(vks), 0, keys, &tchr, 1, 0, GetKeyboardLayout(dwThreadID)) == 1)
buf[i] = tchr;
@@ -686,27 +676,40 @@ void InvertCase(bool lastword) int OnButtonPressed(WPARAM wParam, LPARAM lParam)
{
CustomButtonClickData *cbcd = (CustomButtonClickData *)lParam;
- if (mir_strcmp(cbcd->pszModule, "Switch Layout and Send") == 0) {
- HWND hEdit = GetDlgItem(cbcd->hwndFrom, IDC_MESSAGE);
- if (!hEdit)
- hEdit = GetDlgItem(cbcd->hwndFrom, IDC_CHATMESSAGE);
-
- BYTE byKeybState[256];
- GetKeyboardState(byKeybState);
- byKeybState[VK_CONTROL] = 128;
- SetKeyboardState(byKeybState);
- SendMessage(hEdit, WM_KEYDOWN, VK_UP, 0);
- byKeybState[VK_CONTROL] = 0;
- SetKeyboardState(byKeybState);
- DWORD dwProcessID;
- DWORD dwThreadID = GetWindowThreadProcessId(cbcd->hwndFrom, &dwProcessID);
- HKL hkl = GetKeyboardLayout(dwThreadID);
-
- TCHAR *sel = Message_GetFromStream(hEdit, SF_TEXT | SF_UNICODE);
- size_t slen = _tcslen(sel);
+ int iType;
+ if (!mir_strcmp(cbcd->pszModule, "Switch Layout and Send"))
+ iType = 1;
+ else if (!mir_strcmp(cbcd->pszModule, "Translit and Send"))
+ iType = 2;
+ else if (!mir_strcmp(cbcd->pszModule, "Invert Case and Send"))
+ iType = 3;
+ else
+ return 0;
+
+ HWND hEdit = GetDlgItem(cbcd->hwndFrom, IDC_MESSAGE);
+ if (!hEdit)
+ hEdit = GetDlgItem(cbcd->hwndFrom, IDC_CHATMESSAGE);
+
+ BYTE byKeybState[256];
+ GetKeyboardState(byKeybState);
+ byKeybState[VK_CONTROL] = 128;
+ SetKeyboardState(byKeybState);
+ SendMessage(hEdit, WM_KEYDOWN, VK_UP, 0);
+ byKeybState[VK_CONTROL] = 0;
+ SetKeyboardState(byKeybState);
+
+ TCHAR *sel = Message_GetFromStream(hEdit, SF_TEXT | SF_UNICODE);
+ size_t slen = _tcslen(sel);
+ if (slen != 0) {
+ switch (iType) {
+ case 3: Invert(sel); break;
+ case 2: Transliterate(sel); break;
+ case 1:
+ DWORD dwProcessID;
+ DWORD dwThreadID = GetWindowThreadProcessId(cbcd->hwndFrom, &dwProcessID);
+ HKL hkl = GetKeyboardLayout(dwThreadID);
- if (slen != 0) {
memset(&smgp, 0, sizeof(smgp));
smgp.cbSize = sizeof(smgp);
smgp.str = sel;
@@ -733,116 +736,28 @@ int OnButtonPressed(WPARAM wParam, LPARAM lParam) }
if (smileyPrs != NULL)
CallService(MS_SMILEYADD_BATCHFREE, 0, (LPARAM)smileyPrs);
-
- ptrT tszSymbol(db_get_tsa(NULL, "TranslitSwitcher", "ResendSymbol"));
- if (tszSymbol == NULL) {
- SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM)sel);
- SendMessage(hEdit, EM_SETSEL, 0, (LPARAM)slen);
- SendMessage(cbcd->hwndFrom, WM_COMMAND, IDOK, 0);
- }
- else {
- if (_tcsncmp(sel, tszSymbol, _tcslen(tszSymbol)) == 0) {
- SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM)sel);
- SendMessage(hEdit, EM_SETSEL, 0, (LPARAM)slen);
- SendMessage(cbcd->hwndFrom, WM_COMMAND, IDOK, 0);
- }
- else {
- size_t FinalLen = slen + _tcslen(tszSymbol) + 1;
- TCHAR *FinalString = (TCHAR*)mir_alloc((FinalLen + 1)*sizeof(TCHAR));
- mir_sntprintf(FinalString, FinalLen, _T("%s %s"), tszSymbol, sel);
- SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM)FinalString);
- SendMessage(hEdit, EM_SETSEL, 0, FinalLen);
- SendMessage(cbcd->hwndFrom, WM_COMMAND, IDOK, 0);
- mir_free(FinalString);
- }
- }
+ break;
}
- mir_free(sel);
- return 1;
}
- if (mir_strcmp(cbcd->pszModule, "Translit and Send") == 0) {
- HWND hEdit = GetDlgItem(cbcd->hwndFrom, IDC_MESSAGE);
- if (!hEdit)
- hEdit = GetDlgItem(cbcd->hwndFrom, IDC_CHATMESSAGE);
-
- BYTE byKeybState[256];
- GetKeyboardState(byKeybState);
- byKeybState[VK_CONTROL] = 128;
- SetKeyboardState(byKeybState);
- SendMessage(hEdit, WM_KEYDOWN, VK_UP, 0);
- byKeybState[VK_CONTROL] = 0;
- SetKeyboardState(byKeybState);
-
- TCHAR *sel = Message_GetFromStream(hEdit, SF_TEXT | SF_UNICODE);
- size_t slen = _tcslen(sel);
- if (slen != 0)
- Transliterate(sel);
- ptrT tszSymbol(db_get_tsa(NULL, "TranslitSwitcher", "ResendSymbol"));
- if (tszSymbol == NULL) {
- SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM)sel);
- SendMessage(hEdit, EM_SETSEL, 0, (LPARAM)slen);
- SendMessage(cbcd->hwndFrom, WM_COMMAND, IDOK, 0);
- }
- else {
- if (_tcsncmp(sel, tszSymbol, _tcslen(tszSymbol)) == 0) {
- SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM)sel);
- SendMessage(hEdit, EM_SETSEL, 0, (LPARAM)slen);
- SendMessage(cbcd->hwndFrom, WM_COMMAND, IDOK, 0);
- }
- else {
- size_t FinalLen = _tcslen(sel) + _tcslen(tszSymbol) + 1;
- TCHAR *FinalString = (TCHAR*)mir_alloc((FinalLen + 1)*sizeof(TCHAR));
- mir_sntprintf(FinalString, FinalLen, _T("%s %s"), tszSymbol, sel);
- SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM)FinalString);
- SendMessage(hEdit, EM_SETSEL, 0, (LPARAM)FinalLen);
- SendMessage(cbcd->hwndFrom, WM_COMMAND, IDOK, 0);
- mir_free(FinalString);
- }
- }
- mir_free(sel);
- return 1;
+
+ ptrT tszSymbol(db_get_tsa(NULL, "TranslitSwitcher", "ResendSymbol"));
+ if (tszSymbol == NULL) {
+ SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM)sel);
+ SendMessage(hEdit, EM_SETSEL, 0, (LPARAM)slen);
+ SendMessage(cbcd->hwndFrom, WM_COMMAND, IDOK, 0);
}
- if (mir_strcmp(cbcd->pszModule, "Invert Case and Send") == 0) {
- HWND hEdit = GetDlgItem(cbcd->hwndFrom, IDC_MESSAGE);
- if (!hEdit)
- hEdit = GetDlgItem(cbcd->hwndFrom, IDC_CHATMESSAGE);
-
- BYTE byKeybState[256];
- GetKeyboardState(byKeybState);
- byKeybState[VK_CONTROL] = 128;
- SetKeyboardState(byKeybState);
- SendMessage(hEdit, WM_KEYDOWN, VK_UP, 0);
- byKeybState[VK_CONTROL] = 0;
- SetKeyboardState(byKeybState);
-
- TCHAR *sel = Message_GetFromStream(hEdit, SF_TEXT | SF_UNICODE);
- size_t slen = _tcslen(sel);
- if (slen != 0)
- Invert(sel);
- ptrT tszSymbol(db_get_tsa(NULL, "TranslitSwitcher", "ResendSymbol"));
- if (tszSymbol == NULL) {
- SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM)sel);
- SendMessage(hEdit, EM_SETSEL, 0, (LPARAM)slen);
- SendMessage(cbcd->hwndFrom, WM_COMMAND, IDOK, 0);
- }
- else {
- if (_tcsncmp(sel, tszSymbol, _tcslen(tszSymbol)) == 0) {
- SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM)sel);
- SendMessage(hEdit, EM_SETSEL, 0, (LPARAM)slen);
- SendMessage(cbcd->hwndFrom, WM_COMMAND, IDOK, 0);
- }
- else {
- size_t FinalLen = slen + _tcslen(tszSymbol) + 1;
- TCHAR *FinalString = (TCHAR*)mir_alloc((FinalLen + 1)*sizeof(TCHAR));
- mir_sntprintf(FinalString, FinalLen, _T("%s %s"), tszSymbol, sel);
- SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM)FinalString);
- SendMessage(hEdit, EM_SETSEL, 0, (LPARAM)FinalLen);
- SendMessage(cbcd->hwndFrom, WM_COMMAND, IDOK, 0);
- mir_free(FinalString);
- }
- }
- mir_free(sel);
- return 1;
+ else if (_tcsncmp(sel, tszSymbol, _tcslen(tszSymbol)) == 0) {
+ SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM)sel);
+ SendMessage(hEdit, EM_SETSEL, 0, (LPARAM)slen);
+ SendMessage(cbcd->hwndFrom, WM_COMMAND, IDOK, 0);
}
- return 0;
-}
\ No newline at end of file + else {
+ CMString tszFinal(FORMAT, _T("%s %s"), tszSymbol, sel);
+ SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM)tszFinal.GetString());
+ SendMessage(hEdit, EM_SETSEL, 0, tszFinal.GetLength());
+ SendMessage(cbcd->hwndFrom, WM_COMMAND, IDOK, 0);
+ }
+
+ mir_free(sel);
+ return 1;
+}
diff --git a/plugins/TranslitSwitcher/src/TranslitSwitcher.h b/plugins/TranslitSwitcher/src/TranslitSwitcher.h index a38d4695cf..ed822a31d9 100644 --- a/plugins/TranslitSwitcher/src/TranslitSwitcher.h +++ b/plugins/TranslitSwitcher/src/TranslitSwitcher.h @@ -32,6 +32,7 @@ Boston, MA 02111-1307, USA. #include <win2k.h>
#include <m_icolib.h>
#include <m_popup.h>
+#include <m_string.h>
#include <m_msg_buttonsbar.h>
#include <m_smileyadd.h>
diff --git a/plugins/TranslitSwitcher/src/Version.h b/plugins/TranslitSwitcher/src/Version.h index c43da9d729..546a7b7dd7 100644 --- a/plugins/TranslitSwitcher/src/Version.h +++ b/plugins/TranslitSwitcher/src/Version.h @@ -1,14 +1,14 @@ -#define __MAJOR_VERSION 0
-#define __MINOR_VERSION 0
-#define __RELEASE_NUM 1
-#define __BUILD_NUM 0
+#define __MAJOR_VERSION 0
+#define __MINOR_VERSION 1
+#define __RELEASE_NUM 0
+#define __BUILD_NUM 1
#include <stdver.h>
#define __PLUGIN_NAME "Switch layout or transliterate"
#define __FILENAME "TranslitSwitcher.dll"
-#define __DESCRIPTION "Allows to switch a layout or transliterate or invert case of the entered text in the message window with SmileyAdd support."
-#define __AUTHOR "Mataes, tico-tico, Tim"
+#define __DESCRIPTION "Allows to switch a layout or transliterate or invert case of the entered text in the message window with SmileyAdd support."
+#define __AUTHOR "Mataes, tico-tico, Tim"
#define __AUTHOREMAIL "mataes2007@gmail.com"
-#define __AUTHORWEB "http://miranda-ng.org/p/TranslitSwitcher/"
-#define __COPYRIGHT "© 2011-2010 Mataes, tico-tico © 2007 Dmitry Titkov"
+#define __AUTHORWEB "http://miranda-ng.org/p/TranslitSwitcher/"
+#define __COPYRIGHT "© 2011-2010 Mataes, tico-tico © 2007 Dmitry Titkov"
|