diff options
29 files changed, 79 insertions, 232 deletions
diff --git a/include/m_utils.h b/include/m_utils.h index e7bff67f1a..7f880efcdd 100644 --- a/include/m_utils.h +++ b/include/m_utils.h @@ -51,6 +51,11 @@ EXTERN_C MIR_CORE_DLL(void) Utils_OpenUrl(const char *pszUrl, bool bOpenInNewWin EXTERN_C MIR_CORE_DLL(void) Utils_OpenUrlW(const wchar_t *pszUrl, bool bOpenInNewWindow = true);
/////////////////////////////////////////////////////////////////////////////////////////
+// copies a string into clipboard
+
+EXTERN_C MIR_CORE_DLL(void) Utils_ClipboardCopy(const wchar_t *pszText);
+
+/////////////////////////////////////////////////////////////////////////////////////////
// Resizes a dialog by calling a custom routine to move the individual
// Returns 0 on success, or nonzero on failure
// Does not support dialogtemplateex dialog boxes, and will return failure if you try to resize one
diff --git a/libs/win32/mir_core.lib b/libs/win32/mir_core.lib Binary files differindex f367e30c78..eb41a61894 100644 --- a/libs/win32/mir_core.lib +++ b/libs/win32/mir_core.lib diff --git a/libs/win64/mir_core.lib b/libs/win64/mir_core.lib Binary files differindex 39c8d95b2b..4b08e98189 100644 --- a/libs/win64/mir_core.lib +++ b/libs/win64/mir_core.lib 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
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;
}
diff --git a/src/core/stdmsg/src/msgdialog.cpp b/src/core/stdmsg/src/msgdialog.cpp index a03d02c70b..63ed7f47fa 100644 --- a/src/core/stdmsg/src/msgdialog.cpp +++ b/src/core/stdmsg/src/msgdialog.cpp @@ -756,16 +756,7 @@ INT_PTR CMsgDialog::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) case IDC_USERMENU:
if (GetKeyState(VK_SHIFT) & 0x8000) { // copy user name
ptrW id(Contact::GetInfo(CNF_UNIQUEID, m_hContact, m_szProto));
- if (id != nullptr && OpenClipboard(m_hwnd)) {
- HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE, mir_wstrlen(id) * sizeof(wchar_t) + 1);
- if (hData) {
- EmptyClipboard();
- mir_wstrcpy((wchar_t *)GlobalLock(hData), id);
- GlobalUnlock(hData);
- SetClipboardData(CF_UNICODETEXT, hData);
- CloseClipboard();
- }
- }
+ Utils_ClipboardCopy(id);
}
else {
HMENU hMenu = Menu_BuildContactMenu(m_hContact);
diff --git a/src/core/stdpopup/src/yapp_history_dlg.cpp b/src/core/stdpopup/src/yapp_history_dlg.cpp index 3751bb357a..dc6a5775ad 100644 --- a/src/core/stdpopup/src/yapp_history_dlg.cpp +++ b/src/core/stdpopup/src/yapp_history_dlg.cpp @@ -414,52 +414,18 @@ void RefreshPopupHistory(HWND hWnd, int renderer) void CopyPopupDataToClipboard(HWND hList, int selection) { - if (!selection) { + if (!selection) return; - } - - if (!GetOpenClipboardWindow()) { - if (OpenClipboard(hList)) { - wchar_t buffer[2048]; - buffer[0] = '\0'; - wchar_t *clipboard; - int i; - int found = 0; - int count = ListView_GetItemCount(hList); - int textType; - - textType = CF_UNICODETEXT; - - for (i = 0; i < count; i++) { - if (ListView_GetItemState(hList, i, LVIS_SELECTED)) { - ListView_GetItemText(hList, i, selection - 100, buffer, _countof(buffer)); - found = 1; - break; - } - } - if (found) { - EmptyClipboard(); - int len = (int)mir_wstrlen(buffer); - - HANDLE hData = GlobalAlloc(GMEM_MOVEABLE, (len + 2) * sizeof(wchar_t)); - clipboard = (wchar_t *)GlobalLock(hData); - wcsncpy(clipboard, buffer, len); - clipboard[len] = '\0'; - GlobalUnlock(hData); - if (!SetClipboardData(textType, hData)) { - PUShowMessage("Could not set clipboard data", SM_WARNING); - } - } - CloseClipboard(); - } - else { - PUShowMessage("Could not open clipboard", SM_WARNING); + int count = ListView_GetItemCount(hList); + for (int i = 0; i < count; i++) { + if (ListView_GetItemState(hList, i, LVIS_SELECTED)) { + wchar_t buffer[2048]; buffer[0] = '\0'; + ListView_GetItemText(hList, i, selection - 100, buffer, _countof(buffer)); + Utils_ClipboardCopy(buffer); + break; } } - else { - PUShowMessage("The clipboard is not available", SM_WARNING); - } } //subclass proc for the list view diff --git a/src/mir_app/src/srmm_log_rtf.cpp b/src/mir_app/src/srmm_log_rtf.cpp index b0ed13d3b7..01d8b7c5c8 100644 --- a/src/mir_app/src/srmm_log_rtf.cpp +++ b/src/mir_app/src/srmm_log_rtf.cpp @@ -168,14 +168,7 @@ INT_PTR CRtfLogWindow::Notify(WPARAM, LPARAM lParam) break; case IDM_COPYLINK: - if (OpenClipboard(m_pDlg.m_hwnd)) { - EmptyClipboard(); - HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE, (wszText.GetLength() + 1) * sizeof(wchar_t)); - mir_wstrcpy((wchar_t *)GlobalLock(hData), wszText); - GlobalUnlock(hData); - SetClipboardData(CF_UNICODETEXT, hData); - CloseClipboard(); - } + Utils_ClipboardCopy(wszText); break; } diff --git a/src/mir_core/src/Windows/winutil.cpp b/src/mir_core/src/Windows/winutil.cpp index b17feca760..27dec01400 100644 --- a/src/mir_core/src/Windows/winutil.cpp +++ b/src/mir_core/src/Windows/winutil.cpp @@ -133,3 +133,22 @@ MIR_CORE_DLL(int) Utils_CorrectFontSize(int size) return size * ncm.lfMessageFont.lfHeight / -12; } + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_CORE_DLL(void) Utils_ClipboardCopy(const wchar_t *pwszText) +{ + size_t cbLen = mir_wstrlen(pwszText); + if (!::OpenClipboard(nullptr) || !cbLen) + return; + + ::EmptyClipboard(); + + HGLOBAL hData = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, (cbLen+1) * sizeof(wchar_t)); + if (hData) { + mir_wstrcpy((wchar_t *)::GlobalLock(hData), pwszText); + ::GlobalUnlock(hData); + ::SetClipboardData(CF_UNICODETEXT, hData); + } + ::CloseClipboard(); +} diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index 619b069b3a..2a7c92d1f5 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -1543,3 +1543,4 @@ _Utils_CorrectFontSize@4 @1762 NONAME ?OnResize@CDlgBase@@MAEXXZ @1763 NONAME
??0MBinBuffer@@QAE@ABV0@@Z @1764 NONAME
??0MBinBuffer@@QAE@I@Z @1765 NONAME
+_Utils_ClipboardCopy@4 @1766 NONAME
diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index f3b2361862..56c4c541d5 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -1543,3 +1543,4 @@ Utils_CorrectFontSize @1762 NONAME ?OnResize@CDlgBase@@MEAAXXZ @1763 NONAME
??0MBinBuffer@@QEAA@AEBV0@@Z @1764 NONAME
??0MBinBuffer@@QEAA@_K@Z @1765 NONAME
+Utils_ClipboardCopy @1766 NONAME
|