summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2022-09-26 18:23:52 +0300
committerGeorge Hazan <ghazan@miranda.im>2022-09-26 18:23:52 +0300
commit30a9e9e370aa9aff9f64158aa0942b471621a7ef (patch)
tree013f47dfcc748e7a816eb3b59a9ee852d34de0ad /protocols
parentcb0412427ffb4819f2026906f259f4a2dd3ef177 (diff)
Utils_ClipboardCopy - system-wide helper for writing text to clipboard
Diffstat (limited to 'protocols')
-rw-r--r--protocols/Gadu-Gadu/src/sessions.cpp39
-rw-r--r--protocols/JabberG/src/jabber_chat.cpp10
-rw-r--r--protocols/JabberG/src/jabber_disco.cpp6
-rw-r--r--protocols/JabberG/src/jabber_userinfo.cpp6
-rw-r--r--protocols/JabberG/src/jabber_util.cpp33
-rw-r--r--protocols/JabberG/src/stdafx.h9
-rw-r--r--protocols/Tox/src/tox_options.cpp12
-rw-r--r--protocols/Tox/src/tox_profile.cpp11
8 files changed, 32 insertions, 94 deletions
diff --git a/protocols/Gadu-Gadu/src/sessions.cpp b/protocols/Gadu-Gadu/src/sessions.cpp
index 6c71aeab95..080882053e 100644
--- a/protocols/Gadu-Gadu/src/sessions.cpp
+++ b/protocols/Gadu-Gadu/src/sessions.cpp
@@ -317,38 +317,27 @@ static INT_PTR CALLBACK gg_sessions_viewdlg(HWND hwndDlg, UINT message, WPARAM w
int iSelection = TrackPopupMenu(hMenu, TPM_RIGHTBUTTON | TPM_RETURNCMD, pt.x, pt.y, 0, hwndDlg, nullptr);
switch (iSelection) {
case 10001:
- {
- wchar_t szText[512], szClientName[256], szIP[64], szLoginTime[64];
- HGLOBAL hData;
- if (!OpenClipboard(hwndDlg))
- break;
-
- EmptyClipboard();
- szClientName[0] = szIP[0] = szLoginTime[0] = 0;
- ListView_GetItemText(hList, lvhti.iItem, 0, szClientName, _countof(szClientName));
- ListView_GetItemText(hList, lvhti.iItem, 1, szIP, _countof(szIP));
- ListView_GetItemText(hList, lvhti.iItem, 2, szLoginTime, _countof(szLoginTime));
- mir_snwprintf(szText, L"%s\t%s\t%s", szClientName, szIP, szLoginTime);
- if ((hData = GlobalAlloc(GMEM_MOVEABLE, mir_wstrlen(szText) + 1)) != nullptr)
{
- mir_wstrcpy((wchar_t*)GlobalLock(hData), szText);
- GlobalUnlock(hData);
- SetClipboardData(CF_TEXT, hData);
+ wchar_t szText[512], szClientName[256], szIP[64], szLoginTime[64];
+ szClientName[0] = szIP[0] = szLoginTime[0] = 0;
+ ListView_GetItemText(hList, lvhti.iItem, 0, szClientName, _countof(szClientName));
+ ListView_GetItemText(hList, lvhti.iItem, 1, szIP, _countof(szIP));
+ ListView_GetItemText(hList, lvhti.iItem, 2, szLoginTime, _countof(szLoginTime));
+ mir_snwprintf(szText, L"%s\t%s\t%s", szClientName, szIP, szLoginTime);
+ Utils_ClipboardCopy(szText);
}
- CloseClipboard();
break;
- }
case 10002:
- {
- wchar_t szUrl[256], szIP[64];
- szIP[0] = 0;
- ListView_GetItemText(hList, lvhti.iItem, 1, szIP, _countof(szIP));
- mir_snwprintf(szUrl, L"http://whois.domaintools.com/%s", szIP);
- Utils_OpenUrlW(szUrl);
+ {
+ wchar_t szUrl[256], szIP[64];
+ szIP[0] = 0;
+ ListView_GetItemText(hList, lvhti.iItem, 1, szIP, _countof(szIP));
+ mir_snwprintf(szUrl, L"http://whois.domaintools.com/%s", szIP);
+ Utils_OpenUrlW(szUrl);
+ }
break;
}
- }
DestroyMenu(hMenu);
}
break;
diff --git a/protocols/JabberG/src/jabber_chat.cpp b/protocols/JabberG/src/jabber_chat.cpp
index a657f1af40..da93040fa9 100644
--- a/protocols/JabberG/src/jabber_chat.cpp
+++ b/protocols/JabberG/src/jabber_chat.cpp
@@ -1129,16 +1129,16 @@ static void sttNickListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK*
break;
case IDM_CPY_NICK:
- JabberCopyText(g_clistApi.hwndContactList, him->m_szResourceName);
+ Utils_ClipboardCopy(him->m_szResourceName);
break;
case IDM_RJID_COPY:
case IDM_CPY_RJID:
- JabberCopyText(g_clistApi.hwndContactList, him->m_szRealJid);
+ Utils_ClipboardCopy(him->m_szRealJid);
break;
case IDM_CPY_INROOMJID:
- JabberCopyText(g_clistApi.hwndContactList, MakeJid(item->jid, him->m_szResourceName));
+ Utils_ClipboardCopy(MakeJid(item->jid, him->m_szResourceName));
break;
case IDM_RJID_VCARD:
@@ -1303,11 +1303,11 @@ static void sttLogListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK *g
break;
case IDM_CPY_RJID:
- JabberCopyText(g_clistApi.hwndContactList, item->jid);
+ Utils_ClipboardCopy(item->jid);
break;
case IDM_CPY_TOPIC:
- JabberCopyText(g_clistApi.hwndContactList, item->getTemp()->m_szStatusMessage);
+ Utils_ClipboardCopy(item->getTemp()->m_szStatusMessage);
break;
}
}
diff --git a/protocols/JabberG/src/jabber_disco.cpp b/protocols/JabberG/src/jabber_disco.cpp
index 7ec1988e6a..94168f47ff 100644
--- a/protocols/JabberG/src/jabber_disco.cpp
+++ b/protocols/JabberG/src/jabber_disco.cpp
@@ -1056,15 +1056,15 @@ public:
break;
case SD_ACT_COPYJID:
- JabberCopyText(m_hwnd, pNode->GetJid());
+ Utils_ClipboardCopy(pNode->GetJid());
break;
case SD_ACT_COPYNODE:
- JabberCopyText(m_hwnd, pNode->GetNode());
+ Utils_ClipboardCopy(pNode->GetNode());
break;
case SD_ACT_COPYINFO:
- JabberCopyText(m_hwnd, pNode->GetTooltipText());
+ Utils_ClipboardCopy(pNode->GetTooltipText());
break;
case SD_ACT_FAVORITE:
diff --git a/protocols/JabberG/src/jabber_userinfo.cpp b/protocols/JabberG/src/jabber_userinfo.cpp
index 595a0c663a..f164252fbd 100644
--- a/protocols/JabberG/src/jabber_userinfo.cpp
+++ b/protocols/JabberG/src/jabber_userinfo.cpp
@@ -497,7 +497,7 @@ public:
if (nReturnCmd == 1) {
CMStringW buf;
GetNodeText(pos->hItem, buf);
- JabberCopyText(m_hwnd, buf);
+ Utils_ClipboardCopy(buf);
}
else if (nReturnCmd == 2) {
wchar_t szBuffer[1024];
@@ -508,9 +508,9 @@ public:
tvi.pszText = szBuffer;
if (m_tree.GetItem(&tvi)) {
if (wchar_t *str = wcsstr(szBuffer, L": "))
- JabberCopyText(m_hwnd, str + 2);
+ Utils_ClipboardCopy(str + 2);
else
- JabberCopyText(m_hwnd, szBuffer);
+ Utils_ClipboardCopy(szBuffer);
}
}
DestroyMenu(hMenu);
diff --git a/protocols/JabberG/src/jabber_util.cpp b/protocols/JabberG/src/jabber_util.cpp
index aad05772f7..3eebd4e2c7 100644
--- a/protocols/JabberG/src/jabber_util.cpp
+++ b/protocols/JabberG/src/jabber_util.cpp
@@ -740,39 +740,6 @@ const wchar_t *JabberStrIStr(const wchar_t *str, const wchar_t *substr)
}
////////////////////////////////////////////////////////////////////////
-// clipboard processing
-
-void JabberCopyText(HWND hwnd, const char *pszText)
-{
- if (!hwnd || !pszText) return;
-
- if (OpenClipboard(hwnd)) {
- Utf2T text(pszText);
-
- EmptyClipboard();
- HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, sizeof(wchar_t)*(mir_wstrlen(text) + 1));
- wchar_t *s = (wchar_t *)GlobalLock(hMem);
- mir_wstrcpy(s, text);
- GlobalUnlock(hMem);
- SetClipboardData(CF_UNICODETEXT, hMem);
- CloseClipboard();
- }
-}
-
-void JabberCopyText(HWND hwnd, const wchar_t *text)
-{
- if (!hwnd || !text) return;
-
- if (OpenClipboard(hwnd)) {
- EmptyClipboard();
- HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, sizeof(wchar_t)*(mir_wstrlen(text) + 1));
- wchar_t *s = (wchar_t *)GlobalLock(hMem);
- mir_wstrcpy(s, text);
- GlobalUnlock(hMem);
- SetClipboardData(CF_UNICODETEXT, hMem);
- CloseClipboard();
- }
-}
BOOL CJabberProto::EnterString(CMStringW &result, const wchar_t *caption, int type, char *windowName, int recentCount, int timeout)
{
diff --git a/protocols/JabberG/src/stdafx.h b/protocols/JabberG/src/stdafx.h
index dc0dc76647..67eaad3244 100644
--- a/protocols/JabberG/src/stdafx.h
+++ b/protocols/JabberG/src/stdafx.h
@@ -682,7 +682,7 @@ char* JabberStripJid(const char *jid, char *dest, size_t destLen);
int JabberGetPacketID(const char*);
char* JabberId2string(int id);
-__inline int JabberGetPacketID(const TiXmlElement *n)
+__forceinline int JabberGetPacketID(const TiXmlElement *n)
{ return JabberGetPacketID(XmlGetAttr(n, "id"));
}
@@ -694,12 +694,13 @@ wchar_t* JabberStrFixLines(const wchar_t *str);
wchar_t* JabberErrorStr(int errorCode);
CMStringW JabberErrorMsg(const TiXmlElement *errorNode, int *errorCode = nullptr);
-void JabberCopyText(HWND hwnd, const char *text);
-void JabberCopyText(HWND hwnd, const wchar_t *text);
-
const wchar_t *JabberStrIStr(const wchar_t *str, const wchar_t *substr);
CJabberProto* JabberChooseInstance(bool bIsLink=false);
+__forceinline void Utils_ClipboardCopy(const char *p)
+{ Utils_ClipboardCopy(Utf2T(p));
+}
+
bool JabberReadXep203delay(const TiXmlElement *node, time_t &msgTime);
void SetWindowTextUtf(HWND hwndDlg, const char *szValue);
diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp
index 1c3a463a6f..5bd7044b1d 100644
--- a/protocols/Tox/src/tox_options.cpp
+++ b/protocols/Tox/src/tox_options.cpp
@@ -102,17 +102,7 @@ void CToxOptionsMain::EnableUdp_OnClick(CCtrlBase*)
void CToxOptionsMain::ToxAddressCopy_OnClick(CCtrlButton*)
{
- char *toxAddress = m_toxAddress.GetTextA();
- size_t toxAddressLength = mir_strlen(toxAddress) + 1;
- if (OpenClipboard(m_toxAddress.GetHwnd())) {
- EmptyClipboard();
- HGLOBAL hMemory = GlobalAlloc(GMEM_FIXED, toxAddressLength);
- memcpy(GlobalLock(hMemory), toxAddress, toxAddressLength);
- GlobalUnlock(hMemory);
- SetClipboardData(CF_TEXT, hMemory);
- CloseClipboard();
- }
- mir_free(toxAddress);
+ Utils_ClipboardCopy(ptrW(m_toxAddress.GetText()));
}
void CToxOptionsMain::ProfileCreate_OnClick(CCtrlButton*)
diff --git a/protocols/Tox/src/tox_profile.cpp b/protocols/Tox/src/tox_profile.cpp
index d414f75a8d..d6b53fb0e9 100644
--- a/protocols/Tox/src/tox_profile.cpp
+++ b/protocols/Tox/src/tox_profile.cpp
@@ -186,16 +186,7 @@ void CToxProto::OnErase()
INT_PTR CToxProto::OnCopyToxID(WPARAM, LPARAM)
{
- ptrA address(getStringA(TOX_SETTINGS_ID));
- size_t length = mir_strlen(address) + 1;
- if (OpenClipboard(nullptr)) {
- EmptyClipboard();
- HGLOBAL hMemory = GlobalAlloc(GMEM_FIXED, length);
- memcpy(GlobalLock(hMemory), address, length);
- GlobalUnlock(hMemory);
- SetClipboardData(CF_TEXT, hMemory);
- CloseClipboard();
- }
+ Utils_ClipboardCopy(ptrW(getWStringA(TOX_SETTINGS_ID)));
return 0;
}