From f0e49b0185cdb3116babefa3df29c780a56a0a51 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Sun, 9 Mar 2014 21:26:08 +0000 Subject: QuickReplies: - removed stl - removed replies text limit git-svn-id: http://svn.miranda-ng.org/main/trunk@8532 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/QuickReplies/src/common.h | 15 +++---- plugins/QuickReplies/src/events.cpp | 68 ++++++++++++++++--------------- plugins/QuickReplies/src/options.cpp | 77 ++++++++++++++++++------------------ 3 files changed, 77 insertions(+), 83 deletions(-) (limited to 'plugins/QuickReplies') diff --git a/plugins/QuickReplies/src/common.h b/plugins/QuickReplies/src/common.h index b09b83f3a2..6ea75ae0c6 100644 --- a/plugins/QuickReplies/src/common.h +++ b/plugins/QuickReplies/src/common.h @@ -22,10 +22,10 @@ Boston, MA 02111-1307, USA. #define __QUICK_REPLY_H__ #include -#include #include #include +#include #include #include #include @@ -33,15 +33,14 @@ Boston, MA 02111-1307, USA. #include #include -#include "resource.h" #include "version.h" +#include "resource.h" -#define MODULE_NAME "QuickReplies" -#define TEXT_LIMIT 2048 -#define IDC_MESSAGE 1002 -#define IDC_CHATMESSAGE 1009 +#define MODULE "QuickReplies" +#define IDC_MESSAGE 1002 +#define IDC_CHATMESSAGE 1009 -#define MS_QUICKREPLIES_SERVICE MODULE_NAME"/Service" +#define MS_QUICKREPLIES_SERVICE MODULE"/Service" extern HINSTANCE hInstance; @@ -53,8 +52,6 @@ extern HANDLE hQuickRepliesService; extern HANDLE hOnModulesLoaded; extern HANDLE hOnPreShutdown; -typedef std::wstring tString; - INT_PTR QuickRepliesService(WPARAM wParam, LPARAM lParam); int OnModulesLoaded(WPARAM wParam, LPARAM lParam); diff --git a/plugins/QuickReplies/src/events.cpp b/plugins/QuickReplies/src/events.cpp index f570d52306..b3dd97fdc2 100644 --- a/plugins/QuickReplies/src/events.cpp +++ b/plugins/QuickReplies/src/events.cpp @@ -42,18 +42,18 @@ int OnModulesLoaded(WPARAM wParam, LPARAM lParam) iNumber = 0; hQuickRepliesService = CreateServiceFunction(MS_QUICKREPLIES_SERVICE, QuickRepliesService); } - else iNumber = db_get_b(NULL, MODULE_NAME, "InstancesCount", 0); - db_set_b(NULL, MODULE_NAME, "InstancesCount", iNumber + 1); + else iNumber = db_get_b(NULL, MODULE, "InstancesCount", 0); + db_set_b(NULL, MODULE, "InstancesCount", iNumber + 1); - hOnOptInitialized = HookEvent(ME_OPT_INITIALISE, OnOptInitialized); - hOnButtonPressed = HookEvent(ME_MSG_BUTTONPRESSED, OnButtonPressed); + hOnOptInitialized = HookEvent(ME_OPT_INITIALISE, OnOptInitialized); + hOnButtonPressed = HookEvent(ME_MSG_BUTTONPRESSED, OnButtonPressed); if ( ServiceExists(MS_BB_ADDBUTTON)) { Icon_Register(hInstance, "TabSRMM/Quick Replies", &icon, 1); char buttonNameTranslated[32], buttonName[32]; - mir_snprintf(buttonNameTranslated, SIZEOF(buttonNameTranslated), "%s %x",Translate("Button"), iNumber + 1); - mir_snprintf(buttonName, SIZEOF(buttonName), MODULE_NAME" %x", iNumber + 1); + mir_snprintf(buttonNameTranslated, SIZEOF(buttonNameTranslated), "%s %x", Translate("Button"), iNumber + 1); + mir_snprintf(buttonName, SIZEOF(buttonName), MODULE" %x", iNumber + 1); BBButton bbd = {0}; bbd.cbSize = sizeof(BBButton); @@ -77,24 +77,24 @@ int OnButtonPressed(WPARAM wParam, LPARAM lParam) int count = 0; HMENU hMenu = NULL; char buttonName[32]; - tString replies = _T(""); - vector replyList; + CMString replies; + LIST replyList(1); CustomButtonClickData *cbcd = (CustomButtonClickData *)lParam; - mir_snprintf(buttonName, SIZEOF(buttonName), MODULE_NAME" %x", iNumber + 1); + mir_snprintf(buttonName, SIZEOF(buttonName), MODULE" %x", iNumber + 1); if (strcmp(cbcd->pszModule, buttonName)) return 0; - if (cbcd->dwButtonId != iNumber) + if (cbcd->dwButtonId != iNumber) return 1; - mir_snprintf(key, 64, "RepliesCount_%x", iNumber); - count = db_get_w(NULL, MODULE_NAME, key, 0); - - { + mir_snprintf(key, SIZEOF(key), "RepliesCount_%x", iNumber); + count = db_get_w(NULL, MODULE, key, 0); + + { if (count == 0 || cbcd->flags & BBCF_RIGHTBUTTON) { - mir_snprintf(buttonName, SIZEOF(buttonName), "Button %x", iNumber + 1); + mir_snprintf(buttonName, SIZEOF(buttonName), "%s %x", Translate("Button"), iNumber + 1); OPENOPTIONSDIALOG ood = {0}; ood.cbSize = sizeof(ood); @@ -107,48 +107,46 @@ int OnButtonPressed(WPARAM wParam, LPARAM lParam) hMenu = CreatePopupMenu(); - DBVARIANT dbv = {0}; - for (int i = 0; i < count; i++) { - mir_snprintf(key, 64, "Reply_%x_%x", iNumber, i); - db_get_ts(NULL, MODULE_NAME, key, &dbv); + mir_snprintf(key, SIZEOF(key), "Reply_%x_%x", iNumber, i); + wchar_t *value = db_get_wsa(NULL, MODULE, key); - if (dbv.ptszVal == NULL) - replyList.push_back(_T("")); + if (!value) + replyList.insert(mir_wstrdup(_T(""))); else - replyList.push_back((TCHAR*)variables_parsedup(dbv.ptszVal, 0, wParam)); + replyList.insert(variables_parsedup(value, 0, wParam)); - if (_tcscmp(dbv.ptszVal, _T("---"))) - AppendMenu((HMENU)hMenu, MF_STRING, i + 1, replyList[i].c_str()); + if (!lstrcmp(value, _T("---"))) + AppendMenu((HMENU)hMenu, MF_SEPARATOR, i + 1, NULL); else - AppendMenu((HMENU)hMenu, MF_SEPARATOR, i + 1, NULL); - } + AppendMenu((HMENU)hMenu, MF_STRING, i + 1, replyList[i]); - db_free(&dbv); + mir_free(value); + } } { int index = TrackPopupMenu(hMenu, TPM_RETURNCMD, cbcd->pt.x, cbcd->pt.y, 0, cbcd->hwndFrom, NULL); if (index > 0) { - if (_tcscmp(replyList.at(index - 1).c_str(), _T(""))) + if (lstrcmp(replyList[index - 1], _T(""))) { HWND hEdit = GetDlgItem(cbcd->hwndFrom, IDC_MESSAGE); if (!hEdit) hEdit = GetDlgItem(cbcd->hwndFrom, IDC_CHATMESSAGE); - SendMessage(hEdit, EM_REPLACESEL, TRUE, (LPARAM)replyList.at(index - 1).c_str()); + SendMessage(hEdit, EM_REPLACESEL, TRUE, (LPARAM)replyList[index - 1]); - mir_snprintf(key, 64, "ImmediatelySend_%x", iNumber); - if ((BYTE)db_get_b(NULL, MODULE_NAME, key, 1) || cbcd->flags & BBCF_CONTROLPRESSED) + mir_snprintf(key, SIZEOF(key), "ImmediatelySend_%x", iNumber); + if ((BYTE)db_get_b(NULL, MODULE, key, 1) || cbcd->flags & BBCF_CONTROLPRESSED) SendMessage(cbcd->hwndFrom, WM_COMMAND, IDOK, 0); } } } - for (std::vector::reverse_iterator item = replyList.rbegin(); item != replyList.rend(); ++item) - ((tString)*item).clear(); - replyList.clear(); + for (int i = 0; i < replyList.getCount(); i++) + mir_free(replyList[i]); + replyList.destroy(); return 1; } @@ -158,7 +156,7 @@ int OnPreShutdown(WPARAM wParam, LPARAM lParam) if (ServiceExists(MS_BB_REMOVEBUTTON)) { char buttonName[32]; - mir_snprintf(buttonName, SIZEOF(buttonName), MODULE_NAME" %x", iNumber + 1); + mir_snprintf(buttonName, SIZEOF(buttonName), MODULE" %x", iNumber + 1); BBButton bbd = {0}; bbd.cbSize = sizeof(BBButton); diff --git a/plugins/QuickReplies/src/options.cpp b/plugins/QuickReplies/src/options.cpp index 2c5b858671..ee3b0112f5 100644 --- a/plugins/QuickReplies/src/options.cpp +++ b/plugins/QuickReplies/src/options.cpp @@ -46,7 +46,6 @@ static LRESULT CALLBACK MessageEditSubclassProc(HWND hwnd,UINT msg,WPARAM wParam GetWindowText(hwnd, text, 1024); MoveMemory(text + start, text + end, sizeof(WCHAR) * (wcslen(text) + 1 - end)); SetWindowText(hwnd, text); - //SAFE_FREE((void**)&text); SendMessage(hwnd, EM_SETSEL, start, start); SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(hwnd), EN_CHANGE), (LPARAM) hwnd); return 0; @@ -64,33 +63,32 @@ INT_PTR CALLBACK DlgProcOptionsPage(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPAR { char key[64]; int count = 0; - DBVARIANT dbv = {0}; - tString replies = _T(""); + CMString replies; TranslateDialogDefault(hwndDlg); variables_skin_helpbutton(hwndDlg, IDC_VARIABLES); + ShowWindow(GetDlgItem(hwndDlg, IDC_VARIABLES_HINT), ServiceExists(MS_VARS_FORMATSTRING)); - SendDlgItemMessage(hwndDlg, IDC_REPLIES, EM_LIMITTEXT, TEXT_LIMIT, 0); - mir_subclassWindow( GetDlgItem(hwndDlg, IDC_REPLIES), MessageEditSubclassProc); + mir_subclassWindow(GetDlgItem(hwndDlg, IDC_REPLIES), MessageEditSubclassProc); - mir_snprintf(key, 64, "ImmediatelySend_%x", iNumber); - CheckDlgButton(hwndDlg, IDC_IMMEDIATELY, (BYTE)db_get_w(NULL, MODULE_NAME, key, 1)); + mir_snprintf(key, SIZEOF(key), "ImmediatelySend_%x", iNumber); + CheckDlgButton(hwndDlg, IDC_IMMEDIATELY, (BYTE)db_get_w(NULL, MODULE, key, 1)); - mir_snprintf(key, 64, "RepliesCount_%x", iNumber); - count = db_get_w(NULL, MODULE_NAME, key, 0); + mir_snprintf(key, SIZEOF(key), "RepliesCount_%x", iNumber); + count = db_get_w(NULL, MODULE, key, 0); for (int i = 0; i < count; i++) { - mir_snprintf(key, 64, "Reply_%x_%x", iNumber, i); - if (!db_get_ts(NULL, MODULE_NAME, key, &dbv)) - if(dbv.ptszVal != NULL) - replies.append(dbv.ptszVal); - if (i < count - 1) - replies.append(_T("\r\n")); + mir_snprintf(key, SIZEOF(key), "Reply_%x_%x", iNumber, i); + wchar_t *value = db_get_wsa(NULL, MODULE, key); + if (value) + { + replies.Append(value); + replies.Append(_T("\r\n")); + } + mir_free(value); } - SetDlgItemText(hwndDlg, IDC_REPLIES, replies.c_str()); - - db_free(&dbv); + SetDlgItemText(hwndDlg, IDC_REPLIES, replies.GetBuffer()); } return TRUE; @@ -117,41 +115,42 @@ INT_PTR CALLBACK DlgProcOptionsPage(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPAR { char key[64]; int count = 0; - TCHAR tszReplies[TEXT_LIMIT]; + wchar_t *tszReplies; - mir_snprintf(key, 64, "RepliesCount_%x", iNumber); - count = db_get_b(NULL, MODULE_NAME, key, 0); + mir_snprintf(key, SIZEOF(key), "RepliesCount_%x", iNumber); + count = db_get_b(NULL, MODULE, key, 0); for (int i = 0; i < count; i++) { - mir_snprintf(key, 64, "Reply_%x_%x", iNumber, i); - db_unset(NULL, MODULE_NAME, key); + mir_snprintf(key, SIZEOF(key), "Reply_%x_%x", iNumber, i); + db_unset(NULL, MODULE, key); } - GetDlgItemText(hwndDlg, IDC_REPLIES, tszReplies, TEXT_LIMIT); + int length = SendDlgItemMessage(hwndDlg, IDC_REPLIES, WM_GETTEXTLENGTH, 0, 0); + tszReplies = (wchar_t*)mir_alloc(sizeof(wchar_t)* (length + 1)); + GetDlgItemText(hwndDlg, IDC_REPLIES, tszReplies, length + 1); + tszReplies[length] = '\0'; { - tString replies = tszReplies; - - if (replies.length() > 0) - replies.append(_T("\r\n")); + CMString replies = tszReplies; + if (replies.Right(2) != _T("\r\n")) + replies.Append(_T("\r\n")); count = 0; - tString::size_type pos = tString::npos; - while ((pos = replies.find(_T("\r\n"))) != tString::npos) + int pos = -1, prev = 0; + while ((pos = replies.Find(_T("\r\n"), prev)) != -1) { mir_snprintf(key, 64, "Reply_%x_%x", iNumber, count++); - db_set_ts(NULL, MODULE_NAME, key, replies.substr(0, pos).c_str()); - replies = replies.substr(pos + 2); + db_set_ws(NULL, MODULE, key, replies.Mid(prev, pos - prev).GetBuffer()); + prev = pos + 2; } } + mir_free(tszReplies); - mir_snprintf(key, 64, "RepliesCount_%x", iNumber); - db_set_w(NULL, MODULE_NAME, key, count); - - mir_snprintf(key, 64, "ImmediatelySend_%x", iNumber); - db_set_b(NULL, MODULE_NAME, key, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_IMMEDIATELY)); + mir_snprintf(key, SIZEOF(key), "RepliesCount_%x", iNumber); + db_set_w(NULL, MODULE, key, count); - mir_free(key); + mir_snprintf(key, SIZEOF(key), "ImmediatelySend_%x", iNumber); + db_set_b(NULL, MODULE, key, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_IMMEDIATELY)); return TRUE; } @@ -170,7 +169,7 @@ INT_PTR CALLBACK DlgProcOptionsPage(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPAR int OnOptInitialized(WPARAM wParam, LPARAM lParam) { char tabName[32]; - mir_snprintf(tabName, SIZEOF(tabName), "Button %x", iNumber + 1); + mir_snprintf(tabName, SIZEOF(tabName), "%s %x", Translate("Button"), iNumber + 1); OPTIONSDIALOGPAGE odp = { sizeof(odp) }; odp.pszGroup = LPGEN("Message Sessions"); -- cgit v1.2.3