diff options
-rw-r--r-- | protocols/VKontakte/src/stdafx.h | 4 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_captcha.cpp | 98 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_dialogs.cpp | 102 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_messages.cpp | 5 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.h | 2 |
5 files changed, 111 insertions, 100 deletions
diff --git a/protocols/VKontakte/src/stdafx.h b/protocols/VKontakte/src/stdafx.h index 8495a2dbd0..a0bf3c178d 100644 --- a/protocols/VKontakte/src/stdafx.h +++ b/protocols/VKontakte/src/stdafx.h @@ -49,6 +49,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include <m_timezones.h>
#include <m_userinfo.h>
#include <m_proto_listeningto.h>
+#include <m_gui.h>
#include <m_messagestate.h>
#include <m_popup.h>
@@ -56,9 +57,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include <m_metacontacts.h>
#include "win2k.h"
+
extern FI_INTERFACE *fii;
+extern HINSTANCE hInst;
#include "resource.h"
#include "vk.h"
#include "vk_struct.h"
#include "vk_proto.h"
+#include "vk_dialogs.h"
diff --git a/protocols/VKontakte/src/vk_captcha.cpp b/protocols/VKontakte/src/vk_captcha.cpp index fdc450911d..59fec9fac8 100644 --- a/protocols/VKontakte/src/vk_captcha.cpp +++ b/protocols/VKontakte/src/vk_captcha.cpp @@ -21,94 +21,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. /////////////////////////////////////////////////////////////////////////////////////////
// Captcha form
-struct CAPTCHA_FORM_PARAMS
-{
- HBITMAP bmp;
- int w,h;
- char Result[100];
- CVkProto* proto;
-};
-
-static INT_PTR CALLBACK CaptchaFormDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- CAPTCHA_FORM_PARAMS *params = (CAPTCHA_FORM_PARAMS*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- switch (msg) {
- case WM_INITDIALOG: {
- TranslateDialogDefault(hwndDlg);
- SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)IcoLib_GetIconByHandle(GetIconHandle(IDI_KEYS), TRUE));
- SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)IcoLib_GetIconByHandle(GetIconHandle(IDI_KEYS)));
- params = (CAPTCHA_FORM_PARAMS*)lParam;
-
- SetDlgItemText(hwndDlg, IDC_INSTRUCTION, TranslateT("Enter the text you see"));
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)params);
-
- if (!params->proto)
- EnableWindow(GetDlgItem(hwndDlg,IDOPENBROWSER), false);
-
- return TRUE;
- }
- case WM_CTLCOLORSTATIC:
- switch (GetWindowLongPtr((HWND)lParam, GWL_ID)) {
- case IDC_WHITERECT:
- case IDC_INSTRUCTION:
- case IDC_TITLE:
- return (INT_PTR)GetStockObject(WHITE_BRUSH);
- }
- return NULL;
-
- case WM_PAINT:
- if (params && params->proto) {
- PAINTSTRUCT ps;
- HDC hdc, hdcMem;
- RECT rc;
-
- GetClientRect(hwndDlg, &rc);
- hdc = BeginPaint(hwndDlg, &ps);
- hdcMem = CreateCompatibleDC(hdc);
- HGDIOBJ hOld = SelectObject(hdcMem, params->bmp);
-
- int y = (rc.bottom + rc.top - params->h) / 2;
- int x = (rc.right + rc.left - params->w) / 2;
- BitBlt(hdc, x, y, params->w, params->h, hdcMem, 0,0, SRCCOPY);
- SelectObject(hdcMem, hOld);
- DeleteDC(hdcMem);
-
- EndPaint(hwndDlg, &ps);
-
- if (params->proto->getBool("AlwaysOpenCaptchaInBrowser", false))
- params->proto->ShowCaptchaInBrowser(params->bmp);
- }
- break;
-
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDCANCEL:
- EndDialog(hwndDlg, 0);
- return TRUE;
-
- case IDOPENBROWSER:
- if (params->proto)
- params->proto->ShowCaptchaInBrowser(params->bmp);
- break;
-
- case IDOK:
- GetDlgItemTextA(hwndDlg, IDC_VALUE, params->Result, _countof(params->Result));
- EndDialog(hwndDlg, 1);
- return TRUE;
- }
- break;
-
- case WM_CLOSE:
- EndDialog(hwndDlg, 0);
- break;
-
- case WM_DESTROY:
- IcoLib_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0));
- IcoLib_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, 0));
- break;
- }
- return FALSE;
-}
bool CVkProto::RunCaptchaForm(LPCSTR szUrl, CMStringA &result)
{
@@ -119,7 +31,6 @@ bool CVkProto::RunCaptchaForm(LPCSTR szUrl, CMStringA &result) if (getBool("UseCaptchaAssistant", false)) {
CMStringA szCaptchaAssistant(FORMAT, "http://ca.tiflohelp.ru/?link=%s", ptrA(ExpUrlEncode(szUrl)));
Utils_OpenUrl(szCaptchaAssistant);
- param.proto = NULL;
}
else {
NETLIBHTTPREQUEST req = { sizeof(req) };
@@ -136,7 +47,6 @@ bool CVkProto::RunCaptchaForm(LPCSTR szUrl, CMStringA &result) return false;
}
-
IMGSRVC_MEMIO memio = { 0 };
memio.iLen = reply->dataLength;
memio.pBuf = reply->pData;
@@ -147,14 +57,12 @@ bool CVkProto::RunCaptchaForm(LPCSTR szUrl, CMStringA &result) GetObject(param.bmp, sizeof(bmp), &bmp);
param.w = bmp.bmWidth;
param.h = bmp.bmHeight;
- param.proto = this;
-
}
- int res = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_CAPTCHAFORM), NULL, CaptchaFormDlgProc, (LPARAM)¶m);
- if (res == 0)
+ CaptchaForm dlg(this, ¶m);
+ if (!dlg.DoModal())
return false;
-
+
debugLogA("CVkProto::RunCaptchaForm: user entered text %s", param.Result);
result = param.Result;
return true;
diff --git a/protocols/VKontakte/src/vk_dialogs.cpp b/protocols/VKontakte/src/vk_dialogs.cpp new file mode 100644 index 0000000000..bfd08e0e86 --- /dev/null +++ b/protocols/VKontakte/src/vk_dialogs.cpp @@ -0,0 +1,102 @@ +/*
+Copyright (c) 2013-16 Miranda NG project (http://miranda-ng.org)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation version 2
+of the License.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "stdafx.h"
+
+CaptchaForm::CaptchaForm(CVkProto *proto, CAPTCHA_FORM_PARAMS* param) :
+ CVkDlgBase(proto, IDD_CAPTCHAFORM),
+ m_instruction(this, IDC_INSTRUCTION),
+ m_edtValue(this, IDC_VALUE),
+ m_btnOpenInBrowser(this, IDOPENBROWSER),
+ m_btnOk(this, IDOK),
+ m_param(param)
+{
+ m_btnOpenInBrowser.OnClick = Callback(this, &CaptchaForm::On_btnOpenInBrowser_Click);
+ m_btnOk.OnClick = Callback(this, &CaptchaForm::On_btnOk_Click);
+ m_edtValue.OnChange = Callback(this, &CaptchaForm::On_edtValue_Change);
+}
+
+void CaptchaForm::OnInitDialog()
+{
+ SendMessage(m_hwnd, WM_SETICON, ICON_BIG, (LPARAM)IcoLib_GetIconByHandle(GetIconHandle(IDI_KEYS), TRUE));
+ SendMessage(m_hwnd, WM_SETICON, ICON_SMALL, (LPARAM)IcoLib_GetIconByHandle(GetIconHandle(IDI_KEYS)));
+
+ m_btnOk.Disable();
+ m_btnOpenInBrowser.Enable((m_param->bmp != NULL));
+ m_instruction.SetText(TranslateT("Enter the text you see"));
+}
+
+INT_PTR CaptchaForm::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch (msg) {
+ case WM_CTLCOLORSTATIC:
+ switch (GetWindowLongPtr((HWND)lParam, GWL_ID)) {
+ case IDC_WHITERECT:
+ case IDC_INSTRUCTION:
+ case IDC_TITLE:
+ return (INT_PTR)GetStockObject(WHITE_BRUSH);
+ }
+ return NULL;
+
+ case WM_PAINT:
+ if (m_param->bmp) {
+ PAINTSTRUCT ps;
+ HDC hdc, hdcMem;
+ RECT rc;
+
+ GetClientRect(m_hwnd, &rc);
+ hdc = BeginPaint(m_hwnd, &ps);
+ hdcMem = CreateCompatibleDC(hdc);
+ HGDIOBJ hOld = SelectObject(hdcMem, m_param->bmp);
+
+ int y = (rc.bottom + rc.top - m_param->h) / 2;
+ int x = (rc.right + rc.left - m_param->w) / 2;
+ BitBlt(hdc, x, y, m_param->w, m_param->h, hdcMem, 0, 0, SRCCOPY);
+ SelectObject(hdcMem, hOld);
+ DeleteDC(hdcMem);
+ EndPaint(m_hwnd, &ps);
+
+ if (m_proto->getBool("AlwaysOpenCaptchaInBrowser", false))
+ m_proto->ShowCaptchaInBrowser(m_param->bmp);
+ }
+ break;
+
+ }
+ return CDlgBase::DlgProc(msg, wParam, lParam);
+}
+
+void CaptchaForm::OnDestroy()
+{
+ IcoLib_ReleaseIcon((HICON)SendMessage(m_hwnd, WM_SETICON, ICON_BIG, 0));
+ IcoLib_ReleaseIcon((HICON)SendMessage(m_hwnd, WM_SETICON, ICON_SMALL, 0));
+}
+
+void CaptchaForm::On_btnOpenInBrowser_Click(CCtrlButton*)
+{
+ m_proto->ShowCaptchaInBrowser(m_param->bmp);
+}
+
+void CaptchaForm::On_btnOk_Click(CCtrlButton*)
+{
+ m_edtValue.GetTextA(m_param->Result, _countof(m_param->Result));
+ EndDialog(m_hwnd, 1);
+}
+
+void CaptchaForm::On_edtValue_Change(CCtrlEdit*)
+{
+ m_btnOk.Enable(mir_strlen(ptrA(m_edtValue.GetTextA())));
+}
\ No newline at end of file diff --git a/protocols/VKontakte/src/vk_messages.cpp b/protocols/VKontakte/src/vk_messages.cpp index b23804b267..44efc6a53e 100644 --- a/protocols/VKontakte/src/vk_messages.cpp +++ b/protocols/VKontakte/src/vk_messages.cpp @@ -73,10 +73,9 @@ int CVkProto::SendMsg(MCONTACT hContact, int, const char *szMsg) if (!m_bServerDelivery && !bIsChat)
ForkThread(&CVkProto::SendMsgAck, new CVkSendMsgParam(hContact, uMsgId));
- if (!IsEmpty(pszRetMsg)) {
- Sleep(330);
+ if (!IsEmpty(pszRetMsg))
SendMsg(hContact, 0, pszRetMsg);
- }
+
return uMsgId;
}
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index 04a7605f9c..410180dd0e 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -14,8 +14,6 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
-#include "stdafx.h"
#pragma once
#define PS_CREATECHAT "/CreateNewChat"
|