diff options
author | George Hazan <ghazan@miranda.im> | 2022-08-13 14:13:26 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-08-13 14:14:00 +0300 |
commit | 93554ecf4c8435fd53268d0f3d80bc407d523bd3 (patch) | |
tree | 74fd2cb80f17e7aaadbd40cec1df104627e25b45 | |
parent | b9c7df217208302b971f86a60046f5bd4d8590fe (diff) |
VoiceService: code cleaning
-rw-r--r-- | plugins/VoiceService/src/VoiceCall.cpp | 3 | ||||
-rw-r--r-- | plugins/VoiceService/src/frame.cpp | 738 | ||||
-rw-r--r-- | plugins/VoiceService/src/frame.h | 9 | ||||
-rw-r--r-- | plugins/VoiceService/src/hooks.cpp | 95 | ||||
-rw-r--r-- | plugins/VoiceService/src/services.cpp | 15 | ||||
-rw-r--r-- | plugins/VoiceService/src/version.h | 2 |
6 files changed, 396 insertions, 466 deletions
diff --git a/plugins/VoiceService/src/VoiceCall.cpp b/plugins/VoiceService/src/VoiceCall.cpp index fbfd0760a1..a0df61dcfd 100644 --- a/plugins/VoiceService/src/VoiceCall.cpp +++ b/plugins/VoiceService/src/VoiceCall.cpp @@ -181,8 +181,7 @@ void VoiceCall::Notify(bool popup, bool sound, bool clist) clistBlinking = true; } - if (hwnd_frame != NULL) - PostMessage(hwnd_frame, WMU_REFRESH, 0, 0); + RefreshFrame(); } bool VoiceCall::IsFinished() diff --git a/plugins/VoiceService/src/frame.cpp b/plugins/VoiceService/src/frame.cpp index 2fbc1ca592..5440e1d7f1 100644 --- a/plugins/VoiceService/src/frame.cpp +++ b/plugins/VoiceService/src/frame.cpp @@ -21,7 +21,6 @@ Boston, MA 02111-1307, USA. // Prototypes ///////////////////////////////////////////////////////////////////////////////////// -HWND hwnd_frame = NULL; HWND hwnd_container = NULL; int frame_id = -1; @@ -93,7 +92,7 @@ void ResizeFrame(int id, HWND hwnd) } } -void ShowFrame(int id, HWND hwnd, int show) +static void ShowFrame(int id, HWND hwnd, int show) { if (!g_plugin.bFramesExist || id == -1) { ShowWindow(GetParent(hwnd), show); @@ -137,86 +136,14 @@ static wchar_t *lstrtrim(wchar_t *str) static void InvalidateAll(HWND hwnd) { InvalidateRect(GetDlgItem(hwnd, IDC_CALLS), NULL, FALSE); - for (int i = 0; i < _countof(dialCtrls); ++i) - InvalidateRect(GetDlgItem(hwnd, dialCtrls[i]), NULL, FALSE); + for (auto &it : dialCtrls) + InvalidateRect(GetDlgItem(hwnd, it), NULL, FALSE); InvalidateRect(hwnd, NULL, FALSE); if (frame_id != -1) CallService(MS_CLIST_FRAMES_UPDATEFRAME, (WPARAM)frame_id, (LPARAM)(FU_FMREDRAW)); } -static void ShowHideDialpad(HWND hwnd) -{ - SendMessage(hwnd, WM_SETREDRAW, FALSE, 0); - - if (!CanCallNumber()) { - for (int i = 0; i < _countof(dialCtrls); ++i) - ShowWindow(GetDlgItem(hwnd, dialCtrls[i]), SW_HIDE); - } - else { - int i; - for (i = 0; i < 3; ++i) - ShowWindow(GetDlgItem(hwnd, dialCtrls[i]), SW_SHOW); - - bool showDialpad = (SendMessage(GetDlgItem(hwnd, IDC_DIALPAD), BM_GETCHECK, 0, 0) == BST_CHECKED); - - for (i = 3; i < _countof(dialCtrls); ++i) - ShowWindow(GetDlgItem(hwnd, dialCtrls[i]), showDialpad ? SW_SHOW : SW_HIDE); - - VoiceCall *talking = NULL; - bool ringing = false; - bool calling = false; - for (i = 0; i < calls.getCount(); i++) { - VoiceCall *call = &calls[i]; - if (call->state == VOICE_STATE_TALKING) - talking = call; - else if (call->state == VOICE_STATE_CALLING) - calling = true; - else if (call->state == VOICE_STATE_RINGING) - ringing = true; - } - - wchar_t number[1024]; - GetDlgItemText(hwnd, IDC_NUMBER, number, _countof(number)); - lstrtrim(number); - - if (ringing && number[0] != 0) { - SetWindowText(GetDlgItem(hwnd, IDC_NUMBER), _T("")); - number[0] = 0; - } - - if (ringing || calling) { - for (i = 0; i < _countof(dialCtrls); ++i) - EnableWindow(GetDlgItem(hwnd, dialCtrls[i]), FALSE); - } - else if (talking) { - if (!showDialpad || !talking->CanSendDTMF()) { - for (i = 0; i < _countof(dialCtrls); ++i) - EnableWindow(GetDlgItem(hwnd, dialCtrls[i]), FALSE); - - EnableWindow(GetDlgItem(hwnd, IDC_DIALPAD), TRUE); - } - else { - for (i = 0; i < _countof(dialCtrls); ++i) - EnableWindow(GetDlgItem(hwnd, dialCtrls[i]), TRUE); - - EnableWindow(GetDlgItem(hwnd, IDC_NUMBER), FALSE); - EnableWindow(GetDlgItem(hwnd, IDC_CALL), FALSE); - } - } - else { - for (i = 0; i < _countof(dialCtrls); ++i) - EnableWindow(GetDlgItem(hwnd, dialCtrls[i]), TRUE); - - EnableWindow(GetDlgItem(hwnd, IDC_CALL), CanCall(number)); - } - } - - SendMessage(hwnd, WM_SETREDRAW, TRUE, 0); - - InvalidateAll(hwnd); -} - static int sttCompareProvidesByDescription(const VoiceProvider *p1, const VoiceProvider *p2) { return lstrcmp(p2->description, p1->description); @@ -232,381 +159,410 @@ static void DrawIconLib(HDC hDC, const RECT &rc, int iconId) IcoLib_ReleaseIcon(hIcon); } -static INT_PTR CALLBACK FrameWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +class CFrameDlg : public CDlgBase { - RECT rc; - - switch (msg) { - case WM_CREATE: - case WM_INITDIALOG: - SendDlgItemMessage(hwnd, IDC_DIALPAD, BUTTONSETASFLATBTN, TRUE, 0); - SendDlgItemMessage(hwnd, IDC_DIALPAD, BUTTONSETASPUSHBTN, TRUE, 0); - SendDlgItemMessageA(hwnd, IDC_DIALPAD, BUTTONADDTOOLTIP, (LPARAM)Translate("Show dialpad"), 0); - SendDlgItemMessage(hwnd, IDC_DIALPAD, BM_SETIMAGE, IMAGE_ICON, (LPARAM)IcoLib_GetIcon("vc_dialpad", TRUE)); + CCtrlEdit edtNumber; + CCtrlListBox m_calls; + CCtrlMButton btnDialpad, btnCall; - SendDlgItemMessage(hwnd, IDC_CALL, BUTTONSETASFLATBTN, TRUE, 0); - SendDlgItemMessageA(hwnd, IDC_CALL, BUTTONADDTOOLTIP, (LPARAM)Translate("Make call"), 0); - SendDlgItemMessage(hwnd, IDC_CALL, BM_SETIMAGE, IMAGE_ICON, (LPARAM)IcoLib_GetIcon("vca_call", TRUE)); + void ResizeFrame(bool bResizeAll) + { + ShowHideDialpad(0); - PostMessage(hwnd, WMU_RESIZE_FRAME, 0, 1); - break; + if (bResizeAll) + SendMessage(m_hwnd, WM_SIZE, 0, 0); - case WM_SIZE: - SendMessage(hwnd, WM_SETREDRAW, FALSE, 0); - GetClientRect(hwnd, &rc); - { - int width = rc.right - rc.left; - int height = rc.bottom - rc.top; - - if (CanCallNumber()) { - bool showDialpad = (SendMessage(GetDlgItem(hwnd, IDC_DIALPAD), BM_GETCHECK, 0, 0) == BST_CHECKED); - - GetWindowRect(hwnd, &rc); - - RECT first = { 0 }, last = { 0 }; - GetWindowRect(GetDlgItem(hwnd, IDC_1), &first); - GetWindowRect(GetDlgItem(hwnd, IDC_SHARP), &last); + if (opts.resize_frame) { + if (calls.getCount() == 0 && !CanCallNumber()) { + ShowFrame(frame_id, m_hwnd, SW_HIDE); + } + else { + ::ResizeFrame(frame_id, m_hwnd); + ShowFrame(frame_id, m_hwnd, SW_SHOW); + } + } + } - int dialpad_height = last.bottom - first.top; - int dialpad_width = last.right - first.left; + void ShowHideDialpad(CCtrlEdit *) + { + SendMessage(m_hwnd, WM_SETREDRAW, FALSE, 0); + if (!CanCallNumber()) { + for (auto &it : dialCtrls) + ShowWindow(GetDlgItem(m_hwnd, it), SW_HIDE); + } + else { + for (int i = 0; i < 3; ++i) + ShowWindow(GetDlgItem(m_hwnd, dialCtrls[i]), SW_SHOW); + + bool showDialpad = (SendMessage(GetDlgItem(m_hwnd, IDC_DIALPAD), BM_GETCHECK, 0, 0) == BST_CHECKED); + + for (int i = 3; i < _countof(dialCtrls); ++i) + ShowWindow(GetDlgItem(m_hwnd, dialCtrls[i]), showDialpad ? SW_SHOW : SW_HIDE); + + VoiceCall *talking = NULL; + bool ringing = false; + bool calling = false; + for (auto &call : calls) { + if (call->state == VOICE_STATE_TALKING) + talking = call; + else if (call->state == VOICE_STATE_CALLING) + calling = true; + else if (call->state == VOICE_STATE_RINGING) + ringing = true; + } - int call_height = 23; - int call_width = 25; - int top = height - call_height - 1; + wchar_t number[1024]; + GetDlgItemText(m_hwnd, IDC_NUMBER, number, _countof(number)); + lstrtrim(number); - if (showDialpad) - top -= dialpad_height + 1; + if (ringing && number[0] != 0) { + SetWindowText(GetDlgItem(m_hwnd, IDC_NUMBER), _T("")); + number[0] = 0; + } - MoveWindow(GetDlgItem(hwnd, IDC_DIALPAD), 1, top, call_width - 2, call_height, FALSE); - MoveWindow(GetDlgItem(hwnd, IDC_NUMBER), call_width, top, width - 2 * call_width, call_height, FALSE); - MoveWindow(GetDlgItem(hwnd, IDC_CALL), width - call_width, top, call_width, call_height + 1, FALSE); + if (ringing || calling) { + for (auto &it : dialCtrls) + EnableWindow(GetDlgItem(m_hwnd, it), FALSE); + } + else if (talking) { + if (!showDialpad || !talking->CanSendDTMF()) { + for (auto &it : dialCtrls) + EnableWindow(GetDlgItem(m_hwnd, it), FALSE); - int dialpad_top = top + call_height + 1; - int dialpad_left = ((rc.right - rc.left) - dialpad_width) / 2; - int deltaX = dialpad_left - first.left; - int deltaY = dialpad_top - first.top; - for (int i = 3; i < _countof(dialCtrls); ++i) { - GetWindowRect(GetDlgItem(hwnd, dialCtrls[i]), &rc); - MoveWindow(GetDlgItem(hwnd, dialCtrls[i]), rc.left + deltaX, rc.top + deltaY, rc.right - rc.left, rc.bottom - rc.top, FALSE); + EnableWindow(GetDlgItem(m_hwnd, IDC_DIALPAD), TRUE); } + else { + for (auto &it : dialCtrls) + EnableWindow(GetDlgItem(m_hwnd, it), TRUE); - height -= call_height + 2; - if (showDialpad) - height -= dialpad_height + 1; - } - - if (height <= 2) { - ShowWindow(GetDlgItem(hwnd, IDC_CALLS), SW_HIDE); + EnableWindow(GetDlgItem(m_hwnd, IDC_NUMBER), FALSE); + EnableWindow(GetDlgItem(m_hwnd, IDC_CALL), FALSE); + } } else { - MoveWindow(GetDlgItem(hwnd, IDC_CALLS), 1, 1, width - 2, height - 2, FALSE); - ShowWindow(GetDlgItem(hwnd, IDC_CALLS), SW_SHOW); + for (auto &it : dialCtrls) + EnableWindow(GetDlgItem(m_hwnd, it), TRUE); + + EnableWindow(GetDlgItem(m_hwnd, IDC_CALL), CanCall(number)); } } - SendMessage(hwnd, WM_SETREDRAW, TRUE, 0); - InvalidateAll(hwnd); - break; - case WMU_REFRESH: - { - HWND list = GetDlgItem(hwnd, IDC_CALLS); + SendMessage(m_hwnd, WM_SETREDRAW, TRUE, 0); - SendMessage(list, WM_SETREDRAW, FALSE, 0); - SendMessage(list, LB_RESETCONTENT, 0, 0); - for (int i = 0; i < calls.getCount(); i++) { - VoiceCall *call = &calls[i]; + InvalidateAll(m_hwnd); + } - wchar_t text[512]; - mir_snwprintf(text, _countof(text), _T("%d %s"), call->state, call->displayName); +public: + CFrameDlg() : + CDlgBase(g_plugin, IDD_CALLS), + m_calls(this, IDC_CALLS), + edtNumber(this, IDC_NUMBER), + btnCall(this, IDC_CALL, g_plugin.getIcon(IDI_ACTION_CALL), "Make call"), + btnDialpad(this, IDC_DIALPAD, g_plugin.getIcon(IDI_DIALPAD), LPGEN("Show dialpad")) + { + SetParent(g_clistApi.hwndContactList); - int pos = SendMessage(list, LB_ADDSTRING, 0, (LPARAM)text); - if (pos == LB_ERR) - // TODO Show error - continue; + btnCall.OnClick = Callback(this, &CFrameDlg::onClick_Call); + btnDialpad.OnClick = Callback(this, &CFrameDlg::onClick_DialPad); - SendMessage(list, LB_SETITEMDATA, pos, (LPARAM)call); - } - SendMessage(list, WM_SETREDRAW, TRUE, 0); - } - __fallthrough; + edtNumber.OnChange = Callback(this, &CFrameDlg::ShowHideDialpad); - case WMU_RESIZE_FRAME: - ShowHideDialpad(hwnd); + m_calls.OnSelChange = Callback(this, &CFrameDlg::onSelChange_Calls); + } - if (lParam) - SendMessage(hwnd, WM_SIZE, 0, 0); + bool OnInitDialog() override + { + btnCall.MakeFlat(); + btnDialpad.MakePush(); - if (opts.resize_frame) { - if (calls.getCount() == 0 && !CanCallNumber()) { - ShowFrame(frame_id, hwnd, SW_HIDE); - } - else { - ResizeFrame(frame_id, hwnd); - ShowFrame(frame_id, hwnd, SW_SHOW); - } - } + ResizeFrame(true); + return true; + } - break; + void OnResize() override + { + SendMessage(m_hwnd, WM_SETREDRAW, FALSE, 0); - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDC_CALL: - { - wchar_t number[1024]; - GetDlgItemText(hwnd, IDC_NUMBER, number, _countof(number)); - lstrtrim(number); + RECT rc; + GetClientRect(m_hwnd, &rc); - LIST<VoiceProvider> candidates(10, &sttCompareProvidesByDescription); + int width = rc.right - rc.left; + int height = rc.bottom - rc.top; - for (int i = 0; i < modules.getCount(); i++) { - if (!modules[i].CanCall(number)) - continue; + if (CanCallNumber()) { + bool showDialpad = btnDialpad.IsPushed(); - candidates.insert(&modules[i]); - } + GetWindowRect(m_hwnd, &rc); - if (candidates.getCount() < 1) - break; + RECT first = { 0 }, last = { 0 }; + GetWindowRect(GetDlgItem(m_hwnd, IDC_1), &first); + GetWindowRect(GetDlgItem(m_hwnd, IDC_SHARP), &last); - int selected; - if (candidates.getCount() == 1) { - selected = 0; - } - else { - HMENU menu = CreatePopupMenu(); + int dialpad_height = last.bottom - first.top; + int dialpad_width = last.right - first.left; - for (int i = 0; i < candidates.getCount(); ++i) { - wchar_t text[1024]; - mir_snwprintf(text, _countof(text), TranslateT("Call with %s"), candidates[i]->description); - MENUITEMINFO mii = { 0 }; - mii.cbSize = sizeof(mii); - mii.fMask = MIIM_ID | MIIM_TYPE; - mii.fType = MFT_STRING; - mii.dwTypeData = text; - mii.cch = lstrlen(text); - mii.wID = i + 1; + int call_height = 23; + int call_width = 25; + int top = height - call_height - 1; - // TODO: Add icon to menu + if (showDialpad) + top -= dialpad_height + 1; - InsertMenuItem(menu, 0, TRUE, &mii); - } + MoveWindow(btnDialpad.GetHwnd(), 1, top, call_width - 2, call_height, FALSE); + MoveWindow(GetDlgItem(m_hwnd, IDC_NUMBER), call_width, top, width - 2 * call_width, call_height, FALSE); + MoveWindow(btnCall.GetHwnd(), width - call_width, top, call_width, call_height + 1, FALSE); - GetWindowRect(GetDlgItem(hwnd, IDC_CALL), &rc); + int dialpad_top = top + call_height + 1; + int dialpad_left = ((rc.right - rc.left) - dialpad_width) / 2; + int deltaX = dialpad_left - first.left; + int deltaY = dialpad_top - first.top; + for (int i = 3; i < _countof(dialCtrls); ++i) { + GetWindowRect(GetDlgItem(m_hwnd, dialCtrls[i]), &rc); + MoveWindow(GetDlgItem(m_hwnd, dialCtrls[i]), rc.left + deltaX, rc.top + deltaY, rc.right - rc.left, rc.bottom - rc.top, FALSE); + } - POINT p; - p.x = rc.right; - p.y = rc.bottom + 1; + height -= call_height + 2; + if (showDialpad) + height -= dialpad_height + 1; + } - selected = TrackPopupMenu(menu, TPM_TOPALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD | TPM_RIGHTALIGN, - p.x, p.y, 0, hwnd, NULL); + if (height <= 2) { + m_calls.Hide(); + } + else { + MoveWindow(m_calls.GetHwnd(), 1, 1, width - 2, height - 2, FALSE); + m_calls.Show(); + } - DestroyMenu(menu); + SendMessage(m_hwnd, WM_SETREDRAW, TRUE, 0); + InvalidateAll(m_hwnd); + } - if (selected == 0) - break; + void onClick_DialPad(CCtrlMButton *) + { + ShowHideDialpad(0); + ResizeFrame(false); + } - selected--; - } + void onClick_Call(CCtrlMButton *) + { + wchar_t number[1024]; + GetDlgItemText(m_hwnd, IDC_NUMBER, number, _countof(number)); + lstrtrim(number); - candidates[selected]->Call(NULL, number); - break; - } + LIST<VoiceProvider> candidates(10, &sttCompareProvidesByDescription); - case IDC_NUMBER: - if (HIWORD(wParam) == EN_CHANGE) - ShowHideDialpad(hwnd); - break; + for (auto &it: modules) { + if (!it->CanCall(number)) + continue; - case IDC_DIALPAD: - ShowHideDialpad(hwnd); - SendMessage(hwnd, WMU_RESIZE_FRAME, 0, 0); - break; + candidates.insert(it); + } - case IDC_1: - case IDC_2: - case IDC_3: - case IDC_4: - case IDC_5: - case IDC_6: - case IDC_7: - case IDC_8: - case IDC_9: - case IDC_AST: - case IDC_0: - case IDC_SHARP: - wchar_t text[2]; - switch (LOWORD(wParam)) { - case IDC_1: text[0] = _T('1'); break; - case IDC_2: text[0] = _T('2'); break; - case IDC_3: text[0] = _T('3'); break; - case IDC_4: text[0] = _T('4'); break; - case IDC_5: text[0] = _T('5'); break; - case IDC_6: text[0] = _T('6'); break; - case IDC_7: text[0] = _T('7'); break; - case IDC_8: text[0] = _T('8'); break; - case IDC_9: text[0] = _T('9'); break; - case IDC_AST: text[0] = _T('*'); break; - case IDC_0: text[0] = _T('0'); break; - case IDC_SHARP: text[0] = _T('#'); break; - } - text[1] = 0; + if (candidates.getCount() < 1) + return; - Skin_PlaySound("voice_dialpad"); - { - VoiceCall *call = GetTalkingCall(); - if (call == NULL) { - SendMessage(GetDlgItem(hwnd, IDC_NUMBER), EM_REPLACESEL, TRUE, (LPARAM)text); - } - else { - wchar_t tmp[1024]; + int selected; + if (candidates.getCount() == 1) { + selected = 0; + } + else { + HMENU menu = CreatePopupMenu(); - GetWindowText(GetDlgItem(hwnd, IDC_NUMBER), tmp, _countof(tmp)); + for (int i = 0; i < candidates.getCount(); ++i) { + wchar_t text[1024]; + mir_snwprintf(text, _countof(text), TranslateT("Call with %s"), candidates[i]->description); - tmp[_countof(tmp) - 2] = 0; - lstrcat(tmp, text); + MENUITEMINFO mii = { 0 }; + mii.cbSize = sizeof(mii); + mii.fMask = MIIM_ID | MIIM_TYPE; + mii.fType = MFT_STRING; + mii.dwTypeData = text; + mii.cch = lstrlen(text); + mii.wID = i + 1; - SetWindowText(GetDlgItem(hwnd, IDC_NUMBER), tmp); + // TODO: Add icon to menu - call->SendDTMF(text[0]); - } + InsertMenuItem(menu, 0, TRUE, &mii); } - break; - case IDC_CALLS: - if (HIWORD(wParam) == LBN_SELCHANGE) { - HWND list = GetDlgItem(hwnd, IDC_CALLS); + RECT rc; + GetWindowRect(GetDlgItem(m_hwnd, IDC_CALL), &rc); - int pos = SendMessage(list, LB_GETCURSEL, 0, 0); - if (pos == LB_ERR) - break; + POINT p; + p.x = rc.right; + p.y = rc.bottom + 1; - POINT p; - GetCursorPos(&p); - ScreenToClient(list, &p); + selected = TrackPopupMenu(menu, TPM_TOPALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD | TPM_RIGHTALIGN, p.x, p.y, 0, m_hwnd, 0); - int ret = SendMessage(list, LB_ITEMFROMPOINT, 0, MAKELONG(p.x, p.y)); - if (HIWORD(ret)) - break; - if (pos != LOWORD(ret)) - break; + DestroyMenu(menu); - SendMessage(list, LB_GETITEMRECT, pos, (LPARAM)&rc); - int x = rc.right - p.x; + if (selected == 0) + return; - int action; - if (x >= H_SPACE && x <= ICON_SIZE + H_SPACE) - action = 2; - else if (x >= ICON_SIZE + 2 * H_SPACE && x <= 2 * (ICON_SIZE + H_SPACE)) - action = 1; - else - break; + selected--; + } - VoiceCall *call = (VoiceCall *)SendMessage(list, LB_GETITEMDATA, pos, 0); - switch (call->state) { - case VOICE_STATE_TALKING: - if (action == 1) - call->Hold(); - else - call->Drop(); - break; + candidates[selected]->Call(0, number); + } - case VOICE_STATE_RINGING: - case VOICE_STATE_ON_HOLD: - if (action == 1) - Answer(call); - else - call->Drop(); - break; + void onChange_Dialpad(CCtrlCheck *pCheck) + { + wchar_t text[2]; + switch (pCheck->GetCtrlId()) { + case IDC_1: text[0] = _T('1'); break; + case IDC_2: text[0] = _T('2'); break; + case IDC_3: text[0] = _T('3'); break; + case IDC_4: text[0] = _T('4'); break; + case IDC_5: text[0] = _T('5'); break; + case IDC_6: text[0] = _T('6'); break; + case IDC_7: text[0] = _T('7'); break; + case IDC_8: text[0] = _T('8'); break; + case IDC_9: text[0] = _T('9'); break; + case IDC_AST: text[0] = _T('*'); break; + case IDC_0: text[0] = _T('0'); break; + case IDC_SHARP: text[0] = _T('#'); break; + } + text[1] = 0; - case VOICE_STATE_CALLING: - if (action == 2) - call->Drop(); - break; - } - } + Skin_PlaySound("voice_dialpad"); + + VoiceCall *call = GetTalkingCall(); + if (call == NULL) { + SendMessage(GetDlgItem(m_hwnd, IDC_NUMBER), EM_REPLACESEL, TRUE, (LPARAM)text); } - break; + else { + wchar_t tmp[1024]; - case WM_CONTEXTMENU: - { - HWND list = GetDlgItem(hwnd, IDC_CALLS); - if ((HANDLE)wParam != list) - break; + GetWindowText(GetDlgItem(m_hwnd, IDC_NUMBER), tmp, _countof(tmp)); - POINT p; - p.x = LOWORD(lParam); - p.y = HIWORD(lParam); - ScreenToClient(list, &p); + tmp[_countof(tmp) - 2] = 0; + lstrcat(tmp, text); - int pos = SendMessage(list, LB_ITEMFROMPOINT, 0, MAKELONG(p.x, p.y)); - if (HIWORD(pos)) - break; - pos = LOWORD(pos); + SetWindowText(GetDlgItem(m_hwnd, IDC_NUMBER), tmp); - if (pos >= calls.getCount()) - break; + call->SendDTMF(text[0]); + } + } - if (IsFinalState(calls[pos].state)) - break; + void onSelChange_Calls(CCtrlListBox*) + { + int pos = m_calls.GetCurSel(); + if (pos == LB_ERR) + return; - // Just to get things strait - SendMessage(list, LB_SETCURSEL, pos, 0); + POINT p; + GetCursorPos(&p); + ScreenToClient(m_calls.GetHwnd(), &p); - HMENU menu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_MENUS)); - HMENU submenu = GetSubMenu(menu, 0); - TranslateMenu(submenu); + int ret = m_calls.SendMsg(LB_ITEMFROMPOINT, 0, MAKELONG(p.x, p.y)); + if (HIWORD(ret)) + return; + if (pos != LOWORD(ret)) + return; - switch (calls[pos].state) { - case VOICE_STATE_CALLING: - DeleteMenu(menu, ID_FRAMEPOPUP_ANSWERCALL, MF_BYCOMMAND); - DeleteMenu(menu, ID_FRAMEPOPUP_HOLDCALL, MF_BYCOMMAND); - break; + RECT rc; + m_calls.GetItemRect(pos, &rc); + int x = rc.right - p.x; - case VOICE_STATE_TALKING: - DeleteMenu(menu, ID_FRAMEPOPUP_ANSWERCALL, MF_BYCOMMAND); - if (!calls[pos].module->CanHold()) - DeleteMenu(menu, ID_FRAMEPOPUP_HOLDCALL, MF_BYCOMMAND); - break; - } + int action; + if (x >= H_SPACE && x <= ICON_SIZE + H_SPACE) + action = 2; + else if (x >= ICON_SIZE + 2 * H_SPACE && x <= 2 * (ICON_SIZE + H_SPACE)) + action = 1; + else + return; - p.x = LOWORD(lParam); - p.y = HIWORD(lParam); - int ret = TrackPopupMenu(submenu, TPM_TOPALIGN | TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, p.x, p.y, 0, hwnd, NULL); - DestroyMenu(menu); + VoiceCall *call = (VoiceCall *)m_calls.GetItemData(pos); + switch (call->state) { + case VOICE_STATE_TALKING: + if (action == 1) + call->Hold(); + else + call->Drop(); + break; - switch (ret) { - case ID_FRAMEPOPUP_DROPCALL: - calls[pos].Drop(); - break; + case VOICE_STATE_RINGING: + case VOICE_STATE_ON_HOLD: + if (action == 1) + Answer(call); + else + call->Drop(); + break; - case ID_FRAMEPOPUP_ANSWERCALL: - Answer(&calls[pos]); - break; + case VOICE_STATE_CALLING: + if (action == 2) + call->Drop(); + break; + } + } - case ID_FRAMEPOPUP_HOLDCALL: - calls[pos].Hold(); - break; - } + void onMenu_Calls(CContextMenuPos *pPos) + { + int pos = pPos->iCurr; + if (pos >= calls.getCount()) + return; + + if (IsFinalState(calls[pos].state)) + return; + + // Just to get things strait + m_calls.SetCurSel(pos); + + HMENU menu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_MENUS)); + HMENU submenu = GetSubMenu(menu, 0); + TranslateMenu(submenu); + + switch (calls[pos].state) { + case VOICE_STATE_CALLING: + DeleteMenu(menu, ID_FRAMEPOPUP_ANSWERCALL, MF_BYCOMMAND); + DeleteMenu(menu, ID_FRAMEPOPUP_HOLDCALL, MF_BYCOMMAND); + break; + + case VOICE_STATE_TALKING: + DeleteMenu(menu, ID_FRAMEPOPUP_ANSWERCALL, MF_BYCOMMAND); + if (!calls[pos].module->CanHold()) + DeleteMenu(menu, ID_FRAMEPOPUP_HOLDCALL, MF_BYCOMMAND); break; } - case WM_MEASUREITEM: - { - LPMEASUREITEMSTRUCT mis = (LPMEASUREITEMSTRUCT)lParam; - if (mis->CtlID != IDC_CALLS) - break; + int ret = TrackPopupMenu(submenu, TPM_TOPALIGN | TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, pPos->pt.x, pPos->pt.y, 0, m_hwnd, NULL); + DestroyMenu(menu); + + switch (ret) { + case ID_FRAMEPOPUP_DROPCALL: + calls[pos].Drop(); + break; + + case ID_FRAMEPOPUP_ANSWERCALL: + Answer(&calls[pos]); + break; - mis->itemHeight = GetMaxLineHeight(); + case ID_FRAMEPOPUP_HOLDCALL: + calls[pos].Hold(); + break; } - return TRUE; + } + + INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) override + { + switch (msg) { + case WM_MEASUREITEM: + { + LPMEASUREITEMSTRUCT mis = (LPMEASUREITEMSTRUCT)lParam; + if (mis->CtlID != IDC_CALLS) + break; - case WM_CTLCOLORLISTBOX: - return (LRESULT)bk_brush; + mis->itemHeight = GetMaxLineHeight(); + } + return TRUE; + + case WM_CTLCOLORLISTBOX: + return (LRESULT)bk_brush; - case WM_DRAWITEM: - { + case WM_DRAWITEM: DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam; if (dis->CtlID != IDC_CALLS || dis->itemID == -1) break; @@ -615,7 +571,7 @@ static INT_PTR CALLBACK FrameWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM if (call == NULL) break; - rc = dis->rcItem; + RECT rc = dis->rcItem; FillRect(dis->hDC, &rc, bk_brush); @@ -709,37 +665,59 @@ static INT_PTR CALLBACK FrameWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM return TRUE; } + return CDlgBase::DlgProc(msg, wParam, lParam); } - return DefWindowProc(hwnd, msg, wParam, lParam); -} + + void Refresh() + { + m_calls.SendMsg(WM_SETREDRAW, FALSE, 0); + m_calls.ResetContent(); + + for (auto &call : calls) { + wchar_t text[512]; + mir_snwprintf(text, _countof(text), _T("%d %s"), call->state, call->displayName); + m_calls.AddString(text, (LPARAM)call); + } + + m_calls.SendMsg(WM_SETREDRAW, TRUE, 0); + ResizeFrame(false); + } +}; // Module entry point ///////////////////////////////////////////////////////////////////////////// +static CFrameDlg *pDialog = nullptr; + void InitFrames() { if (g_plugin.bFramesExist) { - hwnd_frame = CreateDialogW(g_plugin.getInst(), MAKEINTRESOURCE(IDD_CALLS), g_clistApi.hwndContactList, FrameWndProc); + pDialog = new CFrameDlg(); CLISTFrame Frame = {}; Frame.cbSize = sizeof(CLISTFrame); Frame.szName.w = TranslateT("Voice Calls"); - Frame.hWnd = hwnd_frame; + Frame.hWnd = pDialog->GetHwnd(); Frame.height = ICON_SIZE; Frame.align = alBottom; Frame.Flags = F_NOBORDER | F_LOCKED | F_UNICODE; Frame.hIcon = g_plugin.getIcon(IDI_MAIN, true); - frame_id = CallService(MS_CLIST_FRAMES_ADDFRAME, (WPARAM)&Frame, 0); + frame_id = g_plugin.addFrame(&Frame); - int flags = CallService(MS_CLIST_FRAMES_GETFRAMEOPTIONS, MAKEWPARAM(FO_FLAGS, frame_id), 0); - CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS, MAKEWPARAM(FO_FLAGS, frame_id), flags & ~F_VISIBLE); + ShowFrame(frame_id, pDialog->GetHwnd(), SW_HIDE); } } +void RefreshFrame() +{ + if (pDialog) + pDialog->Refresh(); +} + void DeInitFrames() { if (g_plugin.bFramesExist && frame_id != -1) CallService(MS_CLIST_FRAMES_REMOVEFRAME, frame_id, 0); - if (hwnd_frame != NULL) - DestroyWindow(hwnd_frame); + if (pDialog) + pDialog->Close(); } diff --git a/plugins/VoiceService/src/frame.h b/plugins/VoiceService/src/frame.h index 992ab45612..d5850f484e 100644 --- a/plugins/VoiceService/src/frame.h +++ b/plugins/VoiceService/src/frame.h @@ -21,16 +21,9 @@ Boston, MA 02111-1307, USA. #ifndef __FRAME_H__ # define __FRAME_H__ - void InitFrames(); void DeInitFrames(); - -extern HWND hwnd_frame; - - -#define WMU_REFRESH (WM_USER + 25) -#define WMU_RESIZE_FRAME (WM_USER + 26) - +void RefreshFrame(); #endif // __FRAME_H__
\ No newline at end of file diff --git a/plugins/VoiceService/src/hooks.cpp b/plugins/VoiceService/src/hooks.cpp index 45fea47d59..b9c41336d6 100644 --- a/plugins/VoiceService/src/hooks.cpp +++ b/plugins/VoiceService/src/hooks.cpp @@ -126,20 +126,16 @@ static int sttCompareCallingMethods(const CallingMethod *p1, const CallingMethod static void AddMethodsFrom(OBJLIST<CallingMethod> *list, MCONTACT hContact) { - for (int i = 0; i < modules.getCount(); i++) { - VoiceProvider *provider = &modules[i]; + for (auto &provider: modules) if (provider->CanCall(hContact)) list->insert(new CallingMethod(provider, hContact)); - } } static void AddMethodsFrom(OBJLIST<CallingMethod> *list, MCONTACT hContact, const wchar_t *number) { - for (int i = 0; i < modules.getCount(); i++) { - VoiceProvider *provider = &modules[i]; + for (auto &provider: modules) if (provider->CanCall(number)) list->insert(new CallingMethod(provider, hContact, number)); - } } static void BuildCallingMethodsList(OBJLIST<CallingMethod> *list, MCONTACT hContact) @@ -362,14 +358,6 @@ static int PreBuildContactMenu(WPARAM wParam, LPARAM) ///////////////////////////////////////////////////////////////////////////////////////// -static int IconsChanged(WPARAM, LPARAM) -{ - if (hwnd_frame != NULL) - PostMessage(hwnd_frame, WMU_REFRESH, 0, 0); - - return 0; -} - static int ReloadColor(WPARAM, LPARAM) { ColourIDW ci = { 0 }; @@ -382,17 +370,15 @@ static int ReloadColor(WPARAM, LPARAM) DeleteObject(bk_brush); bk_brush = CreateSolidBrush(bkg_color); - if (hwnd_frame != NULL) - InvalidateRect(hwnd_frame, NULL, TRUE); - + RefreshFrame(); return 0; } -VoiceProvider *FindModule(const char *szModule) +VoiceProvider* FindModule(const char *szModule) { - for (int i = 0; i < modules.getCount(); i++) - if (strcmp(modules[i].name, szModule) == 0) - return &modules[i]; + for (auto &it : modules) + if (strcmp(it->name, szModule) == 0) + return it; return NULL; } @@ -405,11 +391,9 @@ static bool IsCall(VoiceCall *call, const char *szModule, const char *id) VoiceCall* FindVoiceCall(const char *szModule, const char *id, bool add) { - for (int i = 0; i < calls.getCount(); i++) { - if (IsCall(&calls[i], szModule, id)) { - return &calls[i]; - } - } + for (auto &call : calls) + if (IsCall(call, szModule, id)) + return call; if (add) { VoiceProvider *module = FindModule(szModule); @@ -421,63 +405,56 @@ VoiceCall* FindVoiceCall(const char *szModule, const char *id, bool add) return tmp; } - return NULL; + return nullptr; } VoiceCall* FindVoiceCall(MCONTACT hContact) { - for (int i = 0; i < calls.getCount(); i++) { - if (calls[i].state != VOICE_STATE_ENDED && calls[i].hContact == hContact) { - return &calls[i]; - } - } + for (auto &call : calls) + if (call->state != VOICE_STATE_ENDED && call->hContact == hContact) + return call; - return NULL; + return nullptr; } static VOID CALLBACK ClearOldVoiceCalls(HWND, UINT, UINT_PTR, DWORD) { DWORD now = GetTickCount(); - BOOL refresh = FALSE; - for (int i = calls.getCount() - 1; i >= 0; --i) { - VoiceCall *call = &calls[i]; - + bool refresh = false; + for (auto &call : calls.rev_iter()) { if (call->state == VOICE_STATE_ENDED && call->end_time + TIME_TO_SHOW_ENDED_CALL < now) { - calls.remove(i); - refresh = TRUE; + calls.remove(calls.indexOf(&call)); + refresh = true; } } - if (refresh && hwnd_frame != NULL) - PostMessage(hwnd_frame, WMU_REFRESH, 0, 0); + if (refresh) + RefreshFrame(); } bool CanCall(MCONTACT hContact, BOOL now) { - for (int i = 0; i < modules.getCount(); i++) { - if (modules[i].CanCall(hContact, now)) + for (auto &it : modules) + if (it->CanCall(hContact, now)) return true; - } return false; } bool CanCall(const wchar_t *number) { - for (int i = 0; i < modules.getCount(); i++) { - if (modules[i].CanCall(number)) + for (auto &it : modules) + if (it->CanCall(number)) return true; - } return false; } bool CanCallNumber() { - for (int i = 0; i < modules.getCount(); i++) { - if (modules[i].flags & VOICE_CAPS_CALL_STRING) + for (auto &it : modules) + if (it->flags & VOICE_CAPS_CALL_STRING) return true; - } return false; } @@ -489,21 +466,16 @@ bool IsFinalState(int state) VoiceCall* GetTalkingCall() { - for (int i = 0; i < calls.getCount(); ++i) { - VoiceCall *call = &calls[i]; - + for (auto &call : calls) if (call->state == VOICE_STATE_TALKING) return call; - } return NULL; } void HoldOtherCalls(VoiceCall *call) { - for (int i = 0; i < calls.getCount(); ++i) { - VoiceCall *other = &calls[i]; - + for (auto &other: calls) { if (other == call || other->state != VOICE_STATE_TALKING) continue; @@ -545,9 +517,7 @@ static int ReloadFont(WPARAM, LPARAM) font_max_height = max(font_max_height, log_font.lfHeight); } - if (hwnd_frame != NULL) - PostMessage(hwnd_frame, WMU_REFRESH, 0, 0); - + RefreshFrame(); return 0; } @@ -643,8 +613,6 @@ int ModulesLoaded(WPARAM, LPARAM) g_plugin.registerIcon(LPGEN("Voice Calls"), stateIcons, "vc"); g_plugin.registerIcon(LPGEN("Voice Calls"), actionIcons, "vca"); - HookEvent(ME_SKIN_ICONSCHANGED, IconsChanged); - // Init fonts { FontID fi = {}; @@ -745,8 +713,7 @@ int ProtoAck(WPARAM, LPARAM lParam) { ACKDATA *ack = (ACKDATA *)lParam; if (ack->type == ACKTYPE_STATUS) - if (hwnd_frame != NULL) - PostMessage(hwnd_frame, WMU_REFRESH, 0, 0); + RefreshFrame(); return 0; } diff --git a/plugins/VoiceService/src/services.cpp b/plugins/VoiceService/src/services.cpp index 0c8f4c9d3a..0d33415b27 100644 --- a/plugins/VoiceService/src/services.cpp +++ b/plugins/VoiceService/src/services.cpp @@ -126,9 +126,7 @@ INT_PTR VoiceRegister(WPARAM wParam, LPARAM) modules.insert(new VoiceProvider(in->name, in->description, in->flags, in->icon)); - if (hwnd_frame != NULL) - PostMessage(hwnd_frame, WMU_REFRESH, 0, 0); - + RefreshFrame(); return 0; } @@ -142,22 +140,17 @@ INT_PTR VoiceUnregister(WPARAM wParam, LPARAM) if (module == NULL) return -2; - for (int i = calls.getCount() - 1; i >= 0; --i) { - VoiceCall *call = &calls[i]; - + for (auto &call: calls.rev_iter()) if (call->module == module) { call->Drop(); call->SetState(VOICE_STATE_ENDED); - calls.remove(i); + calls.remove(calls.indexOf(&call)); } - } modules.remove(module); - if (hwnd_frame != NULL) - PostMessage(hwnd_frame, WMU_REFRESH, 0, 0); - + RefreshFrame(); return 0; } diff --git a/plugins/VoiceService/src/version.h b/plugins/VoiceService/src/version.h index cb6ca83d46..00a4b356cd 100644 --- a/plugins/VoiceService/src/version.h +++ b/plugins/VoiceService/src/version.h @@ -1,6 +1,6 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 1 -#define __RELEASE_NUM 2 +#define __RELEASE_NUM 3 #define __BUILD_NUM 0 #include <stdver.h> |