summaryrefslogtreecommitdiff
path: root/plugins
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 /plugins
parentcb0412427ffb4819f2026906f259f4a2dd3ef177 (diff)
Utils_ClipboardCopy - system-wide helper for writing text to clipboard
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Import/src/progress.cpp14
-rw-r--r--plugins/NewStory/src/history_control.cpp2
-rw-r--r--plugins/NewStory/src/utils.cpp12
-rw-r--r--plugins/NewStory/src/utils.h2
-rw-r--r--plugins/Scriver/src/msgdialog.cpp10
-rw-r--r--plugins/StatusManager/src/ss_options.cpp17
-rw-r--r--plugins/TabSRMM/src/generic_msghandlers.cpp2
-rw-r--r--plugins/TabSRMM/src/infopanel.cpp4
-rw-r--r--plugins/TabSRMM/src/msgdlgother.cpp2
-rw-r--r--plugins/TabSRMM/src/sendlater.cpp2
-rw-r--r--plugins/TabSRMM/src/utils.cpp20
-rw-r--r--plugins/TabSRMM/src/utils.h2
12 files changed, 11 insertions, 78 deletions
diff --git a/plugins/Import/src/progress.cpp b/plugins/Import/src/progress.cpp
index d2037cad65..b602d0a655 100644
--- a/plugins/Import/src/progress.cpp
+++ b/plugins/Import/src/progress.cpp
@@ -87,20 +87,8 @@ void CProgressPageDlg::OnContextMenu(CCtrlBase*)
wszText.Append(L"\r\n");
}
}
- if (wszText.IsEmpty())
- break;
- if (::OpenClipboard(m_hwnd)) {
- size_t i = sizeof(wchar_t) * (wszText.GetLength() + 1);
-
- ::EmptyClipboard();
- HGLOBAL hData = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, i);
-
- memcpy((void*)::GlobalLock(hData), wszText, i);
- ::GlobalUnlock(hData);
- ::SetClipboardData(CF_UNICODETEXT, hData);
- ::CloseClipboard();
- }
+ Utils_ClipboardCopy(wszText);
break;
}
diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp
index bf292ba1b7..2ce131b9a3 100644
--- a/plugins/NewStory/src/history_control.cpp
+++ b/plugins/NewStory/src/history_control.cpp
@@ -648,7 +648,7 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
res.Append(ptrW(TplFormatString(p->getCopyTemplate(), p->hContact, p)));
}
- CopyText(hwnd, res);
+ Utils_ClipboardCopy(res);
}
__fallthrough;
// End of history list control messages
diff --git a/plugins/NewStory/src/utils.cpp b/plugins/NewStory/src/utils.cpp
index 4102ab3887..d1bf1e82a7 100644
--- a/plugins/NewStory/src/utils.cpp
+++ b/plugins/NewStory/src/utils.cpp
@@ -17,15 +17,3 @@ bool CheckFilter(wchar_t *buf, wchar_t *filter)
return true;
return false;
}
-
-void CopyText(HWND hwnd, const wchar_t *text)
-{
- 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();
-}
diff --git a/plugins/NewStory/src/utils.h b/plugins/NewStory/src/utils.h
index 903134dc4b..0b69a5d0e6 100644
--- a/plugins/NewStory/src/utils.h
+++ b/plugins/NewStory/src/utils.h
@@ -1,4 +1,2 @@
uint32_t toggleBit(uint32_t dw, uint32_t bit);
bool CheckFilter(wchar_t *buf, wchar_t *filter);
-
-void CopyText(HWND hwnd, const wchar_t *text);
diff --git a/plugins/Scriver/src/msgdialog.cpp b/plugins/Scriver/src/msgdialog.cpp
index be104cf8d5..ee2af9e908 100644
--- a/plugins/Scriver/src/msgdialog.cpp
+++ b/plugins/Scriver/src/msgdialog.cpp
@@ -458,15 +458,7 @@ void CMsgDialog::onClick_UserMenu(CCtrlButton *pButton)
{
if (GetKeyState(VK_SHIFT) & 0x8000) { // copy user name
ptrW id(Contact::GetInfo(CNF_UNIQUEID, m_hContact, m_szProto));
- if (!OpenClipboard(m_hwnd) || !mir_wstrlen(id))
- return;
-
- EmptyClipboard();
- HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE, 2*mir_wstrlen(id) + 1);
- mir_wstrcpy((LPWSTR)GlobalLock(hData), id);
- GlobalUnlock(hData);
- SetClipboardData(CF_UNICODETEXT, hData);
- CloseClipboard();
+ Utils_ClipboardCopy(id);
}
else {
RECT rc;
diff --git a/plugins/StatusManager/src/ss_options.cpp b/plugins/StatusManager/src/ss_options.cpp
index fad9da5be4..5274c9f6fb 100644
--- a/plugins/StatusManager/src/ss_options.cpp
+++ b/plugins/StatusManager/src/ss_options.cpp
@@ -159,20 +159,9 @@ public:
void onClick_Copy(CCtrlButton*)
{
- if (OpenClipboard(m_hwnd)) {
- EmptyClipboard();
-
- char cmdl[2048];
- GetDlgItemTextA(m_hwnd, IDC_CMDL, cmdl, _countof(cmdl));
- HGLOBAL cmdlGlob = GlobalAlloc(GMEM_MOVEABLE, sizeof(cmdl));
- if (cmdlGlob != nullptr) {
- LPTSTR cmdlStr = (LPTSTR)GlobalLock(cmdlGlob);
- memcpy(cmdlStr, &cmdl, sizeof(cmdl));
- GlobalUnlock(cmdlGlob);
- SetClipboardData(CF_TEXT, cmdlGlob);
- }
- CloseClipboard();
- }
+ wchar_t cmdl[2048];
+ GetDlgItemText(m_hwnd, IDC_CMDL, cmdl, _countof(cmdl));
+ Utils_ClipboardCopy(cmdl);
}
void onClick_Link(CCtrlButton*)
diff --git a/plugins/TabSRMM/src/generic_msghandlers.cpp b/plugins/TabSRMM/src/generic_msghandlers.cpp
index 2236ad344a..9399fdc313 100644
--- a/plugins/TabSRMM/src/generic_msghandlers.cpp
+++ b/plugins/TabSRMM/src/generic_msghandlers.cpp
@@ -226,7 +226,7 @@ LRESULT CMsgDialog::DM_MsgWindowCmdHandler(UINT cmd, WPARAM wParam, LPARAM lPara
case IDC_NAME:
if (GetKeyState(VK_SHIFT) & 0x8000) // copy UIN
- Utils::CopyToClipBoard(m_cache->getUIN(), m_hwnd);
+ Utils_ClipboardCopy(m_cache->getUIN());
else
CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)(m_cache->getActiveContact()), 0);
break;
diff --git a/plugins/TabSRMM/src/infopanel.cpp b/plugins/TabSRMM/src/infopanel.cpp
index cc7bed95c6..69b1400fcb 100644
--- a/plugins/TabSRMM/src/infopanel.cpp
+++ b/plugins/TabSRMM/src/infopanel.cpp
@@ -734,11 +734,11 @@ LRESULT CInfoPanel::cmdHandler(UINT cmd)
switch (cmd) {
case CMD_IP_COPY:
if (m_hoverFlags & HOVER_NICK) {
- Utils::CopyToClipBoard(m_dat->m_cache->getNick(), m_dat->GetHwnd());
+ Utils_ClipboardCopy(m_dat->m_cache->getNick());
return(S_OK);
}
if (m_hoverFlags & HOVER_UIN) {
- Utils::CopyToClipBoard(m_isChat ? m_dat->m_si->ptszTopic : m_dat->m_cache->getUIN(), m_dat->GetHwnd());
+ Utils_ClipboardCopy(m_isChat ? m_dat->m_si->ptszTopic : m_dat->m_cache->getUIN());
return(S_OK);
}
break;
diff --git a/plugins/TabSRMM/src/msgdlgother.cpp b/plugins/TabSRMM/src/msgdlgother.cpp
index 327439ab00..edaa0bacbc 100644
--- a/plugins/TabSRMM/src/msgdlgother.cpp
+++ b/plugins/TabSRMM/src/msgdlgother.cpp
@@ -2850,7 +2850,7 @@ LRESULT CMsgDialog::WMCopyHandler(UINT msg, WPARAM wParam, LPARAM lParam)
ptrW converted(mir_utf8decodeW(szFromStream));
if (converted != nullptr) {
Utils::FilterEventMarkers(converted);
- Utils::CopyToClipBoard(converted, m_pLog->GetHwnd());
+ Utils_ClipboardCopy(converted);
}
}
diff --git a/plugins/TabSRMM/src/sendlater.cpp b/plugins/TabSRMM/src/sendlater.cpp
index 77c23d8014..1ad1690076 100644
--- a/plugins/TabSRMM/src/sendlater.cpp
+++ b/plugins/TabSRMM/src/sendlater.cpp
@@ -442,7 +442,7 @@ public:
job->writeFlags();
break;
case ID_QUEUEMANAGER_COPYMESSAGETOCLIPBOARD:
- Utils::CopyToClipBoard((wchar_t*)ptrW(mir_utf8decodeW(job->sendBuffer)), m_hwnd);
+ Utils_ClipboardCopy(ptrW(mir_utf8decodeW(job->sendBuffer)));
break;
case ID_QUEUEMANAGER_RESETSELECTED:
if (job->bCode == CSendLaterJob::JOB_DEFERRED) {
diff --git a/plugins/TabSRMM/src/utils.cpp b/plugins/TabSRMM/src/utils.cpp
index 6dd803bac9..74fab10f8a 100644
--- a/plugins/TabSRMM/src/utils.cpp
+++ b/plugins/TabSRMM/src/utils.cpp
@@ -467,26 +467,6 @@ void Utils::setAvatarContact(HWND hWnd, MCONTACT hContact)
}
/////////////////////////////////////////////////////////////////////////////////////////
-// stub for copying data to clipboard
-
-size_t Utils::CopyToClipBoard(const wchar_t *str, const HWND hwndOwner)
-{
- if (!OpenClipboard(hwndOwner) || str == nullptr)
- return 0;
-
- size_t i = sizeof(wchar_t) * (mir_wstrlen(str) + 1);
-
- EmptyClipboard();
- HGLOBAL hData = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, i);
-
- memcpy((void*)GlobalLock(hData), str, i);
- GlobalUnlock(hData);
- SetClipboardData(CF_UNICODETEXT, hData);
- CloseClipboard();
- return i;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
HWND TSAPI GetTabWindow(HWND hwndTab, int i)
{
diff --git a/plugins/TabSRMM/src/utils.h b/plugins/TabSRMM/src/utils.h
index 8eef84659c..f60cebe2e3 100644
--- a/plugins/TabSRMM/src/utils.h
+++ b/plugins/TabSRMM/src/utils.h
@@ -82,8 +82,6 @@ namespace Utils
LRESULT CALLBACK PopupDlgProcError(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
LPTSTR extractURLFromRichEdit(const ENLINK* _e, const HWND hwndRich);
- size_t CopyToClipBoard(const wchar_t *str, const HWND hwndOwner);
-
//////////////////////////////////////////////////////////////////////////////////////
// safe mir_strlen function - do not overflow the given buffer length
// if the buffer does not contain a valid (zero-terminated) string, it