diff options
| author | George Hazan <ghazan@miranda.im> | 2022-09-26 18:23:52 +0300 |
|---|---|---|
| committer | George Hazan <ghazan@miranda.im> | 2022-09-26 18:23:52 +0300 |
| commit | 30a9e9e370aa9aff9f64158aa0942b471621a7ef (patch) | |
| tree | 013f47dfcc748e7a816eb3b59a9ee852d34de0ad /src/core | |
| parent | cb0412427ffb4819f2026906f259f4a2dd3ef177 (diff) | |
Utils_ClipboardCopy - system-wide helper for writing text to clipboard
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/stdmsg/src/msgdialog.cpp | 11 | ||||
| -rw-r--r-- | src/core/stdpopup/src/yapp_history_dlg.cpp | 50 |
2 files changed, 9 insertions, 52 deletions
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 |
