From c559a18ca21a2a1fa3199c4bb60bcd031ec17134 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 11 Jan 2014 16:23:36 +0000 Subject: MS_UTILS_ENTERSTRING moved from Jabber to the core, cause it's very handy git-svn-id: http://svn.miranda-ng.org/main/trunk@7593 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/JabberG/res/jabber.rc | 14 -- protocols/JabberG/src/jabber_chat.cpp | 12 +- protocols/JabberG/src/jabber_groupchat.cpp | 2 +- protocols/JabberG/src/jabber_iqid_muc.cpp | 4 +- protocols/JabberG/src/jabber_menu.cpp | 2 +- protocols/JabberG/src/jabber_opt.cpp | 4 +- protocols/JabberG/src/jabber_proto.h | 3 - protocols/JabberG/src/jabber_util.cpp | 220 +++-------------------------- protocols/JabberG/src/resource.h | 5 - 9 files changed, 28 insertions(+), 238 deletions(-) (limited to 'protocols') diff --git a/protocols/JabberG/res/jabber.rc b/protocols/JabberG/res/jabber.rc index c10fb82dc0..42de6ac56e 100644 --- a/protocols/JabberG/res/jabber.rc +++ b/protocols/JabberG/res/jabber.rc @@ -707,20 +707,6 @@ BEGIN DEFPUSHBUTTON "Send",IDOK,299,209,50,14 END -IDD_GROUPCHAT_INPUT DIALOGEX 0, 0, 242, 42 -STYLE DS_SETFONT | DS_SETFOREGROUND | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME -EXSTYLE WS_EX_CONTROLPARENT -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - EDITTEXT IDC_TXT_MULTILINE,6,6,230,12,ES_MULTILINE | ES_AUTOVSCROLL | ES_WANTRETURN | NOT WS_VISIBLE | WS_VSCROLL - EDITTEXT IDC_TXT_PASSWORD,6,6,230,12,ES_AUTOHSCROLL | NOT WS_VISIBLE | ES_PASSWORD - COMBOBOX IDC_TXT_COMBO,6,6,230,92,CBS_DROPDOWN | CBS_AUTOHSCROLL | CBS_SORT | NOT WS_VISIBLE | WS_VSCROLL | WS_TABSTOP - CONTROL "",IDC_TXT_RICHEDIT,RICHEDIT_CLASS,NOT WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_TABSTOP | 0x1004,6,6,230,12 - DEFPUSHBUTTON "OK",IDOK,131,23,50,14 - PUSHBUTTON "Cancel",IDCANCEL,186,23,50,14 -END - - ///////////////////////////////////////////////////////////////////////////// // // DESIGNINFO diff --git a/protocols/JabberG/src/jabber_chat.cpp b/protocols/JabberG/src/jabber_chat.cpp index 8fadba06dc..295ee89257 100644 --- a/protocols/JabberG/src/jabber_chat.cpp +++ b/protocols/JabberG/src/jabber_chat.cpp @@ -1065,7 +1065,7 @@ static void sttNickListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK* szBuffer.Format(_T("%s: "), me->m_tszResourceName); szTitle.Format(TranslateT("Reason to kick %s"), him->m_tszResourceName); TCHAR *resourceName_copy = mir_tstrdup(him->m_tszResourceName); // copy resource name to prevent possible crash if user list rebuilds - if (ppro->EnterString(szBuffer, szTitle, JES_MULTILINE, "gcReason_")) + if (ppro->EnterString(szBuffer, szTitle, ESF_MULTILINE, "gcReason_")) ppro->m_ThreadInfo->send( XmlNodeIq(_T("set"), ppro->SerialNext(), item->jid) << XQUERY(JABBER_FEAT_MUC_ADMIN) << XCHILD(_T("item")) << XATTR(_T("nick"), resourceName_copy) << XATTR(_T("role"), _T("none")) @@ -1144,7 +1144,7 @@ static void sttNickListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK* szBuffer.Format(_T("%s: "), me->m_tszResourceName); szTitle.Format(TranslateT("Reason to ban %s"), him->m_tszResourceName); - if (ppro->EnterString(szBuffer, szTitle, JES_MULTILINE, "gcReason_")) + if (ppro->EnterString(szBuffer, szTitle, ESF_MULTILINE, "gcReason_")) ppro->m_ThreadInfo->send( XmlNodeIq(_T("set"), ppro->SerialNext(), item->jid) << XQUERY(JABBER_FEAT_MUC_ADMIN) << XCHILD(_T("item")) << XATTR(_T("jid"), szVictimBareJid) << XATTR(_T("affiliation"), _T("outcast")) @@ -1173,7 +1173,7 @@ static void sttNickListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK* if (!szInviteTo) break; szTitle.Format(TranslateT("Invite %s to %s"), him->m_tszResourceName, szInviteTo); - if (!ppro->EnterString(szBuffer, szTitle, JES_MULTILINE)) + if (!ppro->EnterString(szBuffer, szTitle, ESF_MULTILINE)) break; szTitle.Format(_T("%s/%s"), item->jid, resourceName_copy); @@ -1271,7 +1271,7 @@ static void sttLogListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK* g szTitle.Format(TranslateT("Set topic for %s"), gch->pDest->ptszID); szBuffer = item->getTemp()->m_tszStatusMessage; szBuffer.Replace(_T("\n"), _T("\r\n")); - if (ppro->EnterString(szBuffer, szTitle, JES_RICHEDIT, "gcTopic_")) + if (ppro->EnterString(szBuffer, szTitle, ESF_RICHEDIT, "gcTopic_")) ppro->m_ThreadInfo->send( XmlNode(_T("message")) << XATTR(_T("to"), gch->pDest->ptszID) << XATTR(_T("type"), _T("groupchat")) << XCHILD(_T("subject"), szBuffer)); @@ -1281,7 +1281,7 @@ static void sttLogListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK* g szTitle.Format(TranslateT("Change nickname in %s"), gch->pDest->ptszID); if (item->nick) szBuffer = item->nick; - if (ppro->EnterString(szBuffer, szTitle, JES_COMBO, "gcNick_")) { + if (ppro->EnterString(szBuffer, szTitle, ESF_COMBO, "gcNick_")) { JABBER_LIST_ITEM *item = ppro->ListGetItemPtr(LIST_CHATROOM, gch->pDest->ptszID); if (item != NULL) { TCHAR text[1024]; @@ -1317,7 +1317,7 @@ static void sttLogListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK* g } case IDM_DESTROY: szTitle.Format(TranslateT("Reason to destroy %s"), gch->pDest->ptszID); - if (ppro->EnterString(szBuffer, szTitle, JES_MULTILINE, "gcReason_")) + if (ppro->EnterString(szBuffer, szTitle, ESF_MULTILINE, "gcReason_")) ppro->m_ThreadInfo->send( XmlNodeIq(_T("set"), ppro->SerialNext(), gch->pDest->ptszID) << XQUERY(JABBER_FEAT_MUC_OWNER) << XCHILD(_T("destroy")) << XCHILD(_T("reason"), szBuffer)); diff --git a/protocols/JabberG/src/jabber_groupchat.cpp b/protocols/JabberG/src/jabber_groupchat.cpp index 517519b3e8..1e8560dcde 100644 --- a/protocols/JabberG/src/jabber_groupchat.cpp +++ b/protocols/JabberG/src/jabber_groupchat.cpp @@ -753,7 +753,7 @@ static VOID CALLBACK JabberGroupchatChangeNickname(void* arg) if (item->nick) szBuffer = item->nick; - if (param->ppro->EnterString(szBuffer, szTitle, JES_COMBO, "gcNick_")) { + if (param->ppro->EnterString(szBuffer, szTitle, ESF_COMBO, "gcNick_")) { replaceStrT(item->nick, szBuffer); param->ppro->SendPresenceTo(param->ppro->m_iStatus, CMString().Format(_T("%s/%s"), item->jid, szBuffer), NULL); } diff --git a/protocols/JabberG/src/jabber_iqid_muc.cpp b/protocols/JabberG/src/jabber_iqid_muc.cpp index 42d460c578..1e941ee9dc 100644 --- a/protocols/JabberG/src/jabber_iqid_muc.cpp +++ b/protocols/JabberG/src/jabber_iqid_muc.cpp @@ -326,7 +326,7 @@ static INT_PTR CALLBACK JabberMucJidListDlgProc(HWND hwndDlg, UINT msg, WPARAM w ListView_GetItem(nm->hdr.hwndFrom, &lvi); if (lvi.lParam == (LPARAM)(-1)) { CMString szBuffer(dat->type2str()); - if (!dat->ppro->EnterString(szBuffer, NULL, JES_COMBO, "gcAddNick_")) + if (!dat->ppro->EnterString(szBuffer, NULL, ESF_COMBO, "gcAddNick_")) break; // Trim leading and trailing whitespaces @@ -336,7 +336,7 @@ static INT_PTR CALLBACK JabberMucJidListDlgProc(HWND hwndDlg, UINT msg, WPARAM w CMString rsn(dat->type2str()); if (dat->type == MUC_BANLIST) { - dat->ppro->EnterString(rsn, TranslateT("Reason to ban"), JES_COMBO, "gcAddReason_"); + dat->ppro->EnterString(rsn, TranslateT("Reason to ban"), ESF_COMBO, "gcAddReason_"); if (szBuffer) dat->ppro->AddMucListItem(dat, szBuffer, rsn); else diff --git a/protocols/JabberG/src/jabber_menu.cpp b/protocols/JabberG/src/jabber_menu.cpp index 9d1036b90f..6f3cb5f8e2 100644 --- a/protocols/JabberG/src/jabber_menu.cpp +++ b/protocols/JabberG/src/jabber_menu.cpp @@ -1143,7 +1143,7 @@ INT_PTR __cdecl CJabberProto::OnMenuHandleDirectPresence(WPARAM wParam, LPARAM l else jid = tszJid; CMString szValue; - if (EnterString(szValue, TranslateT("Status Message"), JES_MULTILINE)) + if (EnterString(szValue, TranslateT("Status Message"), ESF_MULTILINE)) SendPresenceTo(res, jid, NULL, szValue); return 0; } diff --git a/protocols/JabberG/src/jabber_opt.cpp b/protocols/JabberG/src/jabber_opt.cpp index 14f3ca7cba..65ea059fc9 100644 --- a/protocols/JabberG/src/jabber_opt.cpp +++ b/protocols/JabberG/src/jabber_opt.cpp @@ -564,7 +564,7 @@ private: { CMString buf; TCHAR pass[512]; - if (!m_proto->EnterString(buf, TranslateT("Confirm password"), JES_PASSWORD)) + if (!m_proto->EnterString(buf, TranslateT("Confirm password"), ESF_PASSWORD)) return; m_txtPassword.GetText(pass, SIZEOF(pass)); @@ -1849,7 +1849,7 @@ private: void btnRegister_OnClick(CCtrlButton *) { CMString buf; - if (!m_proto->EnterString(buf, TranslateT("Confirm password"), JES_PASSWORD)) + if (!m_proto->EnterString(buf, TranslateT("Confirm password"), ESF_PASSWORD)) return; TCHAR pass[512]; diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index 73d56674f7..cf57fdc42b 100644 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -42,9 +42,6 @@ struct CJabberProto; enum TJabberGcLogInfoType { INFO_BAN, INFO_STATUS, INFO_CONFIG, INFO_AFFILIATION, INFO_ROLE }; -// for JabberEnterString -enum { JES_MULTILINE, JES_COMBO, JES_RICHEDIT, JES_PASSWORD }; - typedef UNIQUE_MAP U_TCHAR_MAP; #define JABBER_DEFAULT_RECENT_COUNT 10 diff --git a/protocols/JabberG/src/jabber_util.cpp b/protocols/JabberG/src/jabber_util.cpp index f15be70a32..ff95a160ee 100644 --- a/protocols/JabberG/src/jabber_util.cpp +++ b/protocols/JabberG/src/jabber_util.cpp @@ -1009,208 +1009,6 @@ void JabberCopyText(HWND hwnd, const TCHAR *text) CloseClipboard(); } -///////////////////////////////////////////////////////////////////////////////////////// -// One string entry dialog - -struct JabberEnterStringParam -{ - CJabberProto *ppro; - - int type; - LPCTSTR caption; - CMString &result; - char *windowName; - int recentCount; - int timeout; - int idcControl; - int height; -}; - -static int sttEnterStringResizer(HWND, LPARAM, UTILRESIZECONTROL *urc) -{ - switch (urc->wId) { - case IDC_TXT_MULTILINE: - case IDC_TXT_COMBO: - case IDC_TXT_RICHEDIT: - return RD_ANCHORX_LEFT | RD_ANCHORY_TOP | RD_ANCHORX_WIDTH | RD_ANCHORY_HEIGHT; - - case IDOK: - case IDCANCEL: - return RD_ANCHORX_RIGHT | RD_ANCHORY_BOTTOM; - } - return RD_ANCHORX_LEFT | RD_ANCHORY_TOP; -} - -static INT_PTR CALLBACK sttEnterStringDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - JabberEnterStringParam *params = (JabberEnterStringParam *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadSkinnedIconBig(SKINICON_OTHER_RENAME)); - SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadSkinnedIcon(SKINICON_OTHER_RENAME)); - params = (JabberEnterStringParam *)lParam; - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)params); - SetWindowText(hwndDlg, params->caption); - { - RECT rc; GetWindowRect(hwndDlg, &rc); - switch (params->type) { - case JES_PASSWORD: - params->idcControl = IDC_TXT_PASSWORD; - params->height = rc.bottom - rc.top; - break; - - case JES_MULTILINE: - params->idcControl = IDC_TXT_MULTILINE; - params->height = 0; - rc.bottom += (rc.bottom - rc.top) * 2; - SetWindowPos(hwndDlg, NULL, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOMOVE | SWP_NOREPOSITION); - break; - - case JES_COMBO: - params->idcControl = IDC_TXT_COMBO; - params->height = rc.bottom - rc.top; - if (params->windowName && params->recentCount) - params->ppro->ComboLoadRecentStrings(hwndDlg, IDC_TXT_COMBO, params->windowName, params->recentCount); - break; - - case JES_RICHEDIT: - params->idcControl = IDC_TXT_RICHEDIT; - SendDlgItemMessage(hwndDlg, IDC_TXT_RICHEDIT, EM_AUTOURLDETECT, TRUE, 0); - SendDlgItemMessage(hwndDlg, IDC_TXT_RICHEDIT, EM_SETEVENTMASK, 0, ENM_LINK); - params->height = 0; - rc.bottom += (rc.bottom - rc.top) * 2; - SetWindowPos(hwndDlg, NULL, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOMOVE | SWP_NOREPOSITION); - break; - } - } - ShowWindow(GetDlgItem(hwndDlg, params->idcControl), SW_SHOW); - SetDlgItemText(hwndDlg, params->idcControl, params->result); - - if (params->windowName) - Utils_RestoreWindowPosition(hwndDlg, NULL, params->ppro->m_szModuleName, params->windowName); - - SetTimer(hwndDlg, 1000, 50, NULL); - - if (params->timeout > 0) { - SetTimer(hwndDlg, 1001, 1000, NULL); - TCHAR buf[128]; - mir_sntprintf(buf, SIZEOF(buf), TranslateT("OK (%d)"), params->timeout); - SetDlgItemText(hwndDlg, IDOK, buf); - } - - return TRUE; - - case WM_DESTROY: - WindowFreeIcon(hwndDlg); - break; - - case WM_TIMER: - switch (wParam) { - case 1000: - KillTimer(hwndDlg,1000); - EnableWindow(GetParent(hwndDlg), TRUE); - break; - - case 1001: - TCHAR buf[128]; - mir_sntprintf(buf, SIZEOF(buf), TranslateT("OK (%d)"), --params->timeout); - SetDlgItemText(hwndDlg, IDOK, buf); - - if (params->timeout < 0) { - KillTimer(hwndDlg, 1001); - UIEmulateBtnClick(hwndDlg, IDOK); - } - } - return TRUE; - - case WM_SIZE: - { - UTILRESIZEDIALOG urd = { 0 }; - urd.cbSize = sizeof(urd); - urd.hInstance = hInst; - urd.hwndDlg = hwndDlg; - urd.lpTemplate = MAKEINTRESOURCEA(IDD_GROUPCHAT_INPUT); - urd.pfnResizer = sttEnterStringResizer; - CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd); - } - break; - - case WM_GETMINMAXINFO: - { - LPMINMAXINFO lpmmi = (LPMINMAXINFO)lParam; - if (params && params->height) - lpmmi->ptMaxSize.y = lpmmi->ptMaxTrackSize.y = params->height; - } - break; - - case WM_NOTIFY: - { - ENLINK *param = (ENLINK *)lParam; - if (param->nmhdr.idFrom != IDC_TXT_RICHEDIT) break; - if (param->nmhdr.code != EN_LINK) break; - if (param->msg != WM_LBUTTONUP) break; - - CHARRANGE sel; - SendMessage(param->nmhdr.hwndFrom, EM_EXGETSEL, 0, (LPARAM) & sel); - if (sel.cpMin != sel.cpMax) break; // allow link selection - - TEXTRANGE tr; - tr.chrg = param->chrg; - tr.lpstrText = (TCHAR *)mir_alloc(sizeof(TCHAR)*(tr.chrg.cpMax - tr.chrg.cpMin + 2)); - SendMessage(param->nmhdr.hwndFrom, EM_GETTEXTRANGE, 0, (LPARAM) & tr); - - char *tmp = mir_t2a(tr.lpstrText); - CallService(MS_UTILS_OPENURL, 1, (LPARAM)tmp); - mir_free(tmp); - mir_free(tr.lpstrText); - } - return TRUE; - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDC_TXT_MULTILINE: - case IDC_TXT_RICHEDIT: - if ((HIWORD(wParam) != EN_SETFOCUS) && (HIWORD(wParam) != EN_KILLFOCUS)) { - SetDlgItemText(hwndDlg, IDOK, TranslateT("OK")); - KillTimer(hwndDlg, 1001); - } - break; - - case IDC_TXT_COMBO: - if ((HIWORD(wParam) != CBN_SETFOCUS) && (HIWORD(wParam) != CBN_KILLFOCUS)) { - SetDlgItemText(hwndDlg, IDOK, TranslateT("OK")); - KillTimer(hwndDlg, 1001); - } - break; - - case IDCANCEL: - if (params->windowName) - Utils_SaveWindowPosition(hwndDlg, NULL, params->ppro->m_szModuleName, params->windowName); - - EndDialog(hwndDlg, 0); - break; - - case IDOK: - HWND hWnd = GetDlgItem(hwndDlg, params->idcControl); - int len = GetWindowTextLength(hWnd); - params->result.Truncate(len); - GetWindowText(hWnd, params->result.GetBuffer(), len+1); - - if ((params->type == JES_COMBO) && params->windowName && params->recentCount) - params->ppro->ComboAddRecentString(hwndDlg, IDC_TXT_COMBO, params->windowName, params->result, params->recentCount); - if (params->windowName) - Utils_SaveWindowPosition(hwndDlg, NULL, params->ppro->m_szModuleName, params->windowName); - - EndDialog(hwndDlg, 1); - break; - } - } - - return FALSE; -} - BOOL CJabberProto::EnterString(CMString &result, LPCTSTR caption, int type, char *windowName, int recentCount, int timeout) { if (caption == NULL) { @@ -1218,8 +1016,22 @@ BOOL CJabberProto::EnterString(CMString &result, LPCTSTR caption, int type, char result.Empty(); } - JabberEnterStringParam param = { this, type, caption, result, windowName, recentCount, timeout }; - return DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_GROUPCHAT_INPUT), GetForegroundWindow(), sttEnterStringDlgProc, LPARAM(¶m)); + TCHAR *pData = mir_tstrdup(result); + + ENTER_STRING param = { sizeof(param) }; + param.type = type; + param.caption = caption; + param.szModuleName = m_szModuleName; + param.szDataPrefix = windowName; + param.recentCount = recentCount; + param.timeout = timeout; + param.result = &pData; + BOOL res = ::EnterString(¶m); + if (res) { + result = pData; + mir_free(pData); + } + return res; } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/JabberG/src/resource.h b/protocols/JabberG/src/resource.h index aa0b90632c..8834602db5 100644 --- a/protocols/JabberG/src/resource.h +++ b/protocols/JabberG/src/resource.h @@ -44,7 +44,6 @@ #define IDI_AGENTS 154 #define IDI_VCARD 155 #define IDI_SAVE 166 -#define IDD_GROUPCHAT_INPUT 167 #define IDD_JIDLIST 171 #define IDD_GROUPCHAT_INVITE 183 #define IDD_GROUPCHAT_INVITE_ACCEPT 184 @@ -182,8 +181,6 @@ #define IDC_EDIT 1131 #define IDC_LIST 1133 #define IDC_TABS 1141 -#define IDC_TXT_MULTILINE 1141 -#define IDC_TXT_PASSWORD 1142 #define IDC_MANUAL_REGISTER 1167 #define IDC_REASON 1171 #define IDC_CLIST 1172 @@ -286,7 +283,6 @@ #define IDC_TXT_ID 1295 #define IDC_CB_FILTER 1296 #define IDC_TXT_ROLE 1296 -#define IDC_TXT_COMBO 1296 #define IDC_CB_TYPE 1296 #define IDC_TXT_METHOD 1296 #define IDC_CB_MODES 1296 @@ -295,7 +291,6 @@ #define IDC_TXT_FROM 1298 #define IDC_TXT_AFFILIATION 1299 #define IDC_ICO_STATUS 1300 -#define IDC_TXT_RICHEDIT 1302 #define IDC_TXT_SLAP 1304 #define IDC_TXT_TAGS 1304 #define IDC_EMAILS 1306 -- cgit v1.2.3