From f7a344dab108224cc2dcb1e39eba5b41efcadefd Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 4 May 2014 21:52:21 +0000 Subject: - duplicated code removed git-svn-id: http://svn.miranda-ng.org/main/trunk@9130 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Scriver/src/msgs.cpp | 61 ++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 36 deletions(-) (limited to 'plugins/Scriver/src') diff --git a/plugins/Scriver/src/msgs.cpp b/plugins/Scriver/src/msgs.cpp index 8ca0b613d7..738d552810 100644 --- a/plugins/Scriver/src/msgs.cpp +++ b/plugins/Scriver/src/msgs.cpp @@ -137,67 +137,56 @@ static int MessageEventAdded(WPARAM hContact, LPARAM lParam) return 0; } -static INT_PTR SendMessageCommandW(WPARAM hContact, LPARAM lParam) +///////////////////////////////////////////////////////////////////////////////////////// + +static INT_PTR SendMessageCommandWorker(MCONTACT hContact, LPCSTR pszMsg, bool isWchar) { - /* does the MCONTACT's protocol support IM messages? */ + if (db_mc_isSub(hContact)) + hContact = db_mc_getMeta(hContact); + + /* does the MCONTACT's protocol support IM messages? */ char *szProto = GetContactProto(hContact); - if (szProto == NULL) - return 1; /* unknown contact */ + if (szProto == NULL) + return 1; /* unknown contact */ if (!CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IMSEND) return 1; HWND hwnd = WindowList_Find(g_dat.hMessageWindowList, hContact); if (hwnd != NULL) { - if (lParam) { + if (pszMsg) { HWND hEdit = GetDlgItem(hwnd, IDC_MESSAGE); SendMessage(hEdit, EM_SETSEL, -1, SendMessage(hEdit, WM_GETTEXTLENGTH, 0, 0)); - SendMessage(hEdit, EM_REPLACESEL, FALSE, (LPARAM)(TCHAR *) lParam); + if (isWchar) + SendMessageW(hEdit, EM_REPLACESEL, FALSE, (LPARAM)pszMsg); + else + SendMessageA(hEdit, EM_REPLACESEL, FALSE, (LPARAM)pszMsg); } SendMessage(GetParent(hwnd), CM_POPUPWINDOW, 0, (LPARAM)hwnd); } else { NewMessageWindowLParam newData = { 0 }; newData.hContact = hContact; - newData.szInitialText = (const char *) lParam; - newData.isWchar = 1; + newData.szInitialText = pszMsg; + newData.isWchar = isWchar; HWND hParent = GetParentWindow(newData.hContact, FALSE); - CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_MSG), hParent, DlgProcMessage, (LPARAM)& newData); + CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_MSG), hParent, DlgProcMessage, (LPARAM)&newData); } return 0; } -static INT_PTR SendMessageCommand(WPARAM hContact, LPARAM lParam) +static INT_PTR SendMessageCommandW(WPARAM hContact, LPARAM lParam) { - char *szProto = GetContactProto(hContact); - //logInfo("Show message window for: %s (%s)", CallService(MS_CLIST_GETCONTACTDISPLAYNAME, wParam, 0), szProto); - if (szProto) { - /* does the MCONTACT's protocol support IM messages? */ - if (!CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0) & PF1_IMSEND) - return 1; - } - else /* unknown contact */ - return 1; + return SendMessageCommandWorker(hContact, LPCSTR(lParam), true); +} - HWND hwnd = WindowList_Find(g_dat.hMessageWindowList, hContact); - if (hwnd != NULL) { - if (lParam) { - HWND hEdit = GetDlgItem(hwnd, IDC_MESSAGE); - SendMessage(hEdit, EM_SETSEL, -1, SendMessage(hEdit, WM_GETTEXTLENGTH, 0, 0)); - SendMessageA(hEdit, EM_REPLACESEL, FALSE, (LPARAM)(char*) lParam); - } - SendMessage(GetParent(hwnd), CM_POPUPWINDOW, 0, (LPARAM)hwnd); - } - else { - NewMessageWindowLParam newData = { 0 }; - newData.hContact = hContact; - newData.szInitialText = (const char *)lParam; - HWND hParent = GetParentWindow(newData.hContact, FALSE); - CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_MSG), hParent, DlgProcMessage, (LPARAM)& newData); - } - return 0; +static INT_PTR SendMessageCommand(WPARAM hContact, LPARAM lParam) +{ + return SendMessageCommandWorker(hContact, LPCSTR(lParam), false); } +///////////////////////////////////////////////////////////////////////////////////////// + static INT_PTR TypingMessageCommand(WPARAM wParam, LPARAM lParam) { CLISTEVENT *cle = (CLISTEVENT*)lParam; -- cgit v1.2.3