diff options
Diffstat (limited to 'plugins')
28 files changed, 69 insertions, 384 deletions
diff --git a/plugins/ChangeKeyboardLayout/src/hook_events.cpp b/plugins/ChangeKeyboardLayout/src/hook_events.cpp index c9598d5814..88e9b0c08d 100644 --- a/plugins/ChangeKeyboardLayout/src/hook_events.cpp +++ b/plugins/ChangeKeyboardLayout/src/hook_events.cpp @@ -189,7 +189,7 @@ int CALLBACK CKLPopupDlgProc(HWND hWnd, UINT uiMessage, WPARAM wParam, LPARAM lP case WM_COMMAND:
if (HIWORD(wParam) == STN_CLICKED) {
if (!IsBadStringPtr(ptszPopupText, MaxTextSize))
- CopyTextToClipboard(ptszPopupText);
+ Utils_ClipboardCopy(ptszPopupText);
PUDeletePopup(hWnd);
}
break;
@@ -200,7 +200,7 @@ int CALLBACK CKLPopupDlgProc(HWND hWnd, UINT uiMessage, WPARAM wParam, LPARAM lP case UM_POPUPACTION:
if ((lParam == 0) && (!IsBadStringPtr(ptszPopupText, MaxTextSize)))
- CopyTextToClipboard(ptszPopupText);
+ Utils_ClipboardCopy(ptszPopupText);
break;
case UM_FREEPLUGINDATA:
diff --git a/plugins/ChangeKeyboardLayout/src/text_operations.cpp b/plugins/ChangeKeyboardLayout/src/text_operations.cpp index 85fb6bf458..14d3d56894 100644 --- a/plugins/ChangeKeyboardLayout/src/text_operations.cpp +++ b/plugins/ChangeKeyboardLayout/src/text_operations.cpp @@ -47,20 +47,6 @@ wchar_t* GeTStringFromStreamData(EditStreamData *esd) /////////////////////////////////////////////////////////////////////////////////////////
-BOOL CopyTextToClipboard(wchar_t *ptszText)
-{
- if (!OpenClipboard(nullptr))
- return FALSE;
-
- EmptyClipboard();
- HGLOBAL hCopy = GlobalAlloc(GMEM_MOVEABLE, (mir_wstrlen(ptszText) + 1) * sizeof(wchar_t));
- mir_wstrcpy((wchar_t *)GlobalLock(hCopy), ptszText);
- GlobalUnlock(hCopy);
- SetClipboardData(CF_UNICODETEXT, hCopy);
- CloseClipboard();
- return TRUE;
-}
-
LPSTR GetNameOfLayout(HKL hklLayout)
{
LPSTR ptszLayName = (LPSTR)mir_alloc(KL_NAMELENGTH + 1);
@@ -438,7 +424,7 @@ int ChangeLayout(HWND hTextWnd, uint8_t TextOperation, BOOL CurrentWord) Skin_PlaySound(SND_ChangeCase);
if (moOptions.CopyToClipboard)
- CopyTextToClipboard(ptszMBox);
+ Utils_ClipboardCopy(ptszMBox);
//-------------------------------Покажем попапы------------------------------------------
if (moOptions.ShowPopup) {
diff --git a/plugins/ChangeKeyboardLayout/src/text_operations.h b/plugins/ChangeKeyboardLayout/src/text_operations.h index 786d811c2d..a8fe87770c 100644 --- a/plugins/ChangeKeyboardLayout/src/text_operations.h +++ b/plugins/ChangeKeyboardLayout/src/text_operations.h @@ -3,7 +3,6 @@ #include "stdafx.h"
-BOOL CopyTextToClipboard(wchar_t *ptszText);
LPSTR GetNameOfLayout(HKL hklLayout);
wchar_t *GetShortNameOfLayout(HKL hklLayout);
wchar_t *GenerateLayoutString(HKL hklLayout);
diff --git a/plugins/Console/src/Console.cpp b/plugins/Console/src/Console.cpp index a3584ffb85..51696191c2 100644 --- a/plugins/Console/src/Console.cpp +++ b/plugins/Console/src/Console.cpp @@ -498,17 +498,9 @@ static INT_PTR CALLBACK LogDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LP *dst = 0;
}
- if (dst - buf > 0 && OpenClipboard(hwndDlg)) {
- EmptyClipboard();
- HGLOBAL hClipboardData = GlobalAlloc(GMEM_DDESHARE, (dst - buf + 1) * sizeof(wchar_t));
- if (hClipboardData) {
- wchar_t *pchData = (wchar_t *)GlobalLock(hClipboardData);
- mir_wstrcpy(pchData, buf);
- GlobalUnlock(hClipboardData);
- SetClipboardData(CF_UNICODETEXT, hClipboardData);
- }
- CloseClipboard();
- }
+ if (dst - buf > 0)
+ Utils_ClipboardCopy(buf);
+
free(buf);
break;
}
diff --git a/plugins/CrashDumper/src/crshdmp.cpp b/plugins/CrashDumper/src/crshdmp.cpp index d204008dc1..5f0c12869b 100644 --- a/plugins/CrashDumper/src/crshdmp.cpp +++ b/plugins/CrashDumper/src/crshdmp.cpp @@ -92,8 +92,7 @@ INT_PTR StoreVersionInfoToClipboard(WPARAM, LPARAM lParam) PrintVersionInfo(buffer, (unsigned int)lParam | VI_FLAG_PRNVAR | VI_FLAG_FORMAT);
WriteBBFile(buffer, false);
- StoreStringToClip(buffer);
-
+ Utils_ClipboardCopy(buffer);
return 0;
}
diff --git a/plugins/CrashDumper/src/dumper.cpp b/plugins/CrashDumper/src/dumper.cpp index d4ae642135..c4c3b9f815 100644 --- a/plugins/CrashDumper/src/dumper.cpp +++ b/plugins/CrashDumper/src/dumper.cpp @@ -609,5 +609,5 @@ void CreateCrashReport(HANDLE hDumpFile, PEXCEPTION_POINTERS exc_ptr, const wcha free(dst);
if (g_plugin.getByte("ShowCrashMessageBox", 1) && msg && IDYES == MessageBox(nullptr, msg, L"Miranda Crash Dumper", MB_YESNO | MB_ICONERROR | MB_TASKMODAL | MB_DEFBUTTON2 | MB_TOPMOST))
- StoreStringToClip(buffer);
+ Utils_ClipboardCopy(buffer);
}
diff --git a/plugins/CrashDumper/src/stdafx.h b/plugins/CrashDumper/src/stdafx.h index 78db36af2a..dfe9421cb0 100644 --- a/plugins/CrashDumper/src/stdafx.h +++ b/plugins/CrashDumper/src/stdafx.h @@ -128,7 +128,6 @@ void ReadableExceptionInfo(PEXCEPTION_RECORD excrec, CMStringW& buffer); void GetLastWriteTime(LPCTSTR fileName, LPTSTR lpszString, uint32_t dwSize);
void GetLastWriteTime(FILETIME* ftime, LPTSTR lpszString, uint32_t dwSize);
-void StoreStringToClip(CMStringW& buffer);
void ShowMessage(int type, const wchar_t* format, ...);
const PLUGININFOEX* GetMirInfo(HMODULE hModule);
diff --git a/plugins/CrashDumper/src/utils.cpp b/plugins/CrashDumper/src/utils.cpp index 055ee355a3..54b4e2a2d2 100644 --- a/plugins/CrashDumper/src/utils.cpp +++ b/plugins/CrashDumper/src/utils.cpp @@ -396,22 +396,3 @@ void GetVersionInfo(HMODULE hLib, CMStringW& buffer) }
}
}
-
-void StoreStringToClip(CMStringW& buffer)
-{
- int bufLen = (buffer.GetLength() + 1) * sizeof(wchar_t);
- HANDLE hData = GlobalAlloc(GMEM_MOVEABLE, bufLen);
- LPSTR buf = (LPSTR)GlobalLock(hData);
-
- memcpy(buf, buffer.c_str(), bufLen);
-
- GlobalUnlock(hData);
-
- if(OpenClipboard(nullptr)) {
- EmptyClipboard();
-
-
- SetClipboardData(CF_UNICODETEXT, hData);
- CloseClipboard();
- }
-}
diff --git a/plugins/FTPFileYM/src/utils.cpp b/plugins/FTPFileYM/src/utils.cpp index a75bc14c08..f09f647a95 100644 --- a/plugins/FTPFileYM/src/utils.cpp +++ b/plugins/FTPFileYM/src/utils.cpp @@ -64,17 +64,7 @@ wchar_t* Utils::getFileNameFromPath(wchar_t *stzPath) void Utils::copyToClipboard(char *szText)
{
- if (szText) {
- if (OpenClipboard(nullptr)) {
- EmptyClipboard();
- HGLOBAL hClipboardData = GlobalAlloc(GMEM_DDESHARE, mir_strlen(szText) + 1);
- char *pchData = (char *)GlobalLock(hClipboardData);
- mir_strcpy(pchData, szText);
- GlobalUnlock(hClipboardData);
- SetClipboardData(CF_TEXT, hClipboardData);
- CloseClipboard();
- }
- }
+ Utils_ClipboardCopy(_A2T(szText));
}
void Utils::curlSetOpt(CURL *hCurl, ServerList::FTP *ftp, char *url, struct curl_slist *headerList, char *errorBuff)
diff --git a/plugins/HTTPServer/src/GuiElements.cpp b/plugins/HTTPServer/src/GuiElements.cpp index 5a409ad9e3..b0a8805461 100644 --- a/plugins/HTTPServer/src/GuiElements.cpp +++ b/plugins/HTTPServer/src/GuiElements.cpp @@ -897,24 +897,10 @@ static INT_PTR CALLBACK DlgProcStatsticView(HWND hwndDlg, UINT msg, WPARAM wPara if (sLink.size() <= 0)
return TRUE;
- if (LOWORD(wParam) == ID_SHARELIST_COPYLINK) {
- if (!OpenClipboard(hwndDlg))
- return TRUE;
-
- if (!EmptyClipboard())
- return TRUE;
-
- HGLOBAL hglbCopy = GlobalAlloc(GMEM_MOVEABLE, sLink.size() + 1);
- // Lock the handle and copy the text to the buffer.
- char * lptstrCopy = (char *)GlobalLock(hglbCopy);
- mir_strcpy(lptstrCopy, sLink.c_str());
- GlobalUnlock(hglbCopy);
-
- // Place the handle on the clipboard.
- SetClipboardData(CF_TEXT, hglbCopy);
- CloseClipboard();
- }
- else Utils_OpenUrl(sLink.c_str());
+ if (LOWORD(wParam) == ID_SHARELIST_COPYLINK)
+ Utils_ClipboardCopy(_A2T(sLink.c_str()));
+ else
+ Utils_OpenUrl(sLink.c_str());
}
}
diff --git a/plugins/HistoryLinkListPlus/src/linklist_dlg.cpp b/plugins/HistoryLinkListPlus/src/linklist_dlg.cpp index d006cad0af..269c3d3f48 100644 --- a/plugins/HistoryLinkListPlus/src/linklist_dlg.cpp +++ b/plugins/HistoryLinkListPlus/src/linklist_dlg.cpp @@ -162,18 +162,7 @@ INT_PTR CALLBACK MainDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) break;
case IDM_LINK_COPY:
- if (!OpenClipboard(hDlg))
- break;
-
- EmptyClipboard();
- {
- size_t dataLen = ((mir_wstrlen(link) + 1) * sizeof(wchar_t));
- HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE, dataLen);
- memcpy((LPTSTR)GlobalLock(hData), link, dataLen);
- GlobalUnlock(hData);
- SetClipboardData(CF_UNICODETEXT, hData);
- }
- CloseClipboard();
+ Utils_ClipboardCopy(link);
break;
case IDM_SHOWMESSAGE:
diff --git a/plugins/IEView/src/external_funcs.cpp b/plugins/IEView/src/external_funcs.cpp index db0fae3210..a690d9f0c8 100644 --- a/plugins/IEView/src/external_funcs.cpp +++ b/plugins/IEView/src/external_funcs.cpp @@ -206,24 +206,7 @@ namespace External if (pDispParams == nullptr || pDispParams->cArgs < 1)
return E_INVALIDARG;
- BSTR data = pDispParams->rgvarg[0].bstrVal;
- if (OpenClipboard(nullptr))
- {
- EmptyClipboard();
- size_t size = sizeof(wchar_t)* (mir_wstrlen(data) + 1);
- HGLOBAL hClipboardData = GlobalAlloc(0, size);
- if (hClipboardData)
- {
- wchar_t *pchData = (wchar_t*)GlobalLock(hClipboardData);
- if (pchData)
- {
- memcpy(pchData, (wchar_t*)data, size);
- GlobalUnlock(hClipboardData);
- SetClipboardData(CF_UNICODETEXT, hClipboardData);
- }
- }
- CloseClipboard();
- }
+ Utils_ClipboardCopy(pDispParams->rgvarg[0].bstrVal);
return S_OK;
}
}
\ No newline at end of file diff --git a/plugins/MenuItemEx/src/main.cpp b/plugins/MenuItemEx/src/main.cpp index a6cd043c2c..f30a2b9f97 100644 --- a/plugins/MenuItemEx/src/main.cpp +++ b/plugins/MenuItemEx/src/main.cpp @@ -212,26 +212,6 @@ BOOL DirectoryExists(MCONTACT hContact) return (attr != -1) && (attr&FILE_ATTRIBUTE_DIRECTORY);
}
-void CopyToClipboard(const wchar_t *pwszMsg)
-{
- if (pwszMsg == nullptr)
- return;
-
- HGLOBAL hglbCopy = GlobalAlloc(GMEM_MOVEABLE, (mir_wstrlen(pwszMsg) + 1) * sizeof(wchar_t));
- LPWSTR lptstrCopy = (LPWSTR)GlobalLock(hglbCopy);
- mir_wstrcpy(lptstrCopy, pwszMsg);
- GlobalUnlock(hglbCopy);
-
- if (OpenClipboard(nullptr) == NULL)
- return;
-
- EmptyClipboard();
-
- SetClipboardData(CF_UNICODETEXT, hglbCopy);
-
- CloseClipboard();
-}
-
BOOL isMetaContact(MCONTACT hContact)
{
char *proto = Proto_GetBaseAccountName(hContact);
@@ -479,7 +459,7 @@ static INT_PTR onCopyID(WPARAM hContact, LPARAM) }
else buf = wszId;
- CopyToClipboard(buf);
+ Utils_ClipboardCopy(buf);
if (CTRL_IS_PRESSED)
ShowPopup(buf, hContact);
@@ -515,7 +495,7 @@ static INT_PTR onCopyStatusMsg(WPARAM hContact, LPARAM) }
}
- CopyToClipboard(wszBuffer);
+ Utils_ClipboardCopy(wszBuffer);
if (CTRL_IS_PRESSED)
ShowPopup(wszBuffer, hContact);
@@ -535,7 +515,7 @@ static INT_PTR onCopyIP(WPARAM hContact, LPARAM) if (rIP)
wszBuffer.AppendFormat(L"Internal IP: %d.%d.%d.%d\r\n", rIP >> 24, (rIP >> 16) & 0xFF, (rIP >> 8) & 0xFF, rIP & 0xFF);
- CopyToClipboard(wszBuffer);
+ Utils_ClipboardCopy(wszBuffer);
if (CTRL_IS_PRESSED)
ShowPopup(wszBuffer, hContact);
@@ -546,7 +526,7 @@ static INT_PTR onCopyMirVer(WPARAM hContact, LPARAM) {
LPWSTR msg = getMirVer(hContact);
if (msg) {
- CopyToClipboard(msg);
+ Utils_ClipboardCopy(msg);
if (CTRL_IS_PRESSED)
ShowPopup(msg, hContact);
diff --git a/plugins/MirOTR/src/options.cpp b/plugins/MirOTR/src/options.cpp index 9c557c2266..6236df3f6c 100644 --- a/plugins/MirOTR/src/options.cpp +++ b/plugins/MirOTR/src/options.cpp @@ -410,7 +410,7 @@ public: if (proto) { char fprint[45]; if (otrl_privkey_fingerprint(otr_user_state, fprint, proto, proto)) - CopyToClipboard(_A2T(fprint)); + Utils_ClipboardCopy(_A2T(fprint)); } break; @@ -795,7 +795,7 @@ public: case IDM_OPT_COPY: wchar_t hash[45]; otrl_privkey_hash_to_humanT(hash, fp->fingerprint); - CopyToClipboard(hash); + Utils_ClipboardCopy(hash); break; case IDM_OPT_FINGER_FORGET: diff --git a/plugins/MirOTR/src/utils.cpp b/plugins/MirOTR/src/utils.cpp index 186a37364f..76b4d03c96 100644 --- a/plugins/MirOTR/src/utils.cpp +++ b/plugins/MirOTR/src/utils.cpp @@ -187,23 +187,6 @@ void ShowError(wchar_t *msg) } } -void CopyToClipboard(const wchar_t *pwszMsg) -{ - if (pwszMsg == nullptr) - return; - - HGLOBAL hglbCopy = GlobalAlloc(GMEM_MOVEABLE, (mir_wstrlen(pwszMsg) + 1) * sizeof(wchar_t)); - LPWSTR lptstrCopy = (LPWSTR)GlobalLock(hglbCopy); - mir_wstrcpy(lptstrCopy, pwszMsg); - GlobalUnlock(hglbCopy); - - if (OpenClipboard(nullptr)) { - EmptyClipboard(); - SetClipboardData(CF_UNICODETEXT, hglbCopy); - CloseClipboard(); - } -} - void ShowPopupUtf(const char* line1, const char* line2, int timeout, const MCONTACT hContact) { wchar_t* l1 = (line1) ? mir_utf8decodeW(line1) : nullptr; diff --git a/plugins/MirOTR/src/utils.h b/plugins/MirOTR/src/utils.h index 1bef577c29..17dc74d758 100644 --- a/plugins/MirOTR/src/utils.h +++ b/plugins/MirOTR/src/utils.h @@ -24,8 +24,6 @@ extern __inline const wchar_t* contact_get_nameT(MCONTACT hContact); wchar_t* ProtoGetNickname(const char* proto); -void CopyToClipboard(const wchar_t *pwszMsg); - char* GetDlgItemTextUtf(HWND hwndDlg, int ctrlId); void ShowPopup(const wchar_t* line1, const wchar_t* line2, int timeout, const MCONTACT hContact = NULL); diff --git a/plugins/Msg_Export/src/FileViewer.cpp b/plugins/Msg_Export/src/FileViewer.cpp index 6390f435e1..f6f018936b 100644 --- a/plugins/Msg_Export/src/FileViewer.cpp +++ b/plugins/Msg_Export/src/FileViewer.cpp @@ -548,41 +548,33 @@ bool bAdvancedCopy(HWND hwnd) CHARRANGE sSelectRange;
SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&sSelectRange);
int nSelLenght = sSelectRange.cpMax - sSelectRange.cpMin + 1; // +1 for null termination
- if (nSelLenght > 1) {
- if (OpenClipboard(nullptr)) {
- EmptyClipboard();
-
- wchar_t *pszSrcBuf = new wchar_t[nSelLenght];
- pszSrcBuf[0] = 0;
- SendMessage(hwnd, EM_GETSELTEXT, 0, (LPARAM)pszSrcBuf);
-
- HANDLE hDecMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, nSelLenght * sizeof(wchar_t));
- wchar_t *pszCurDec = (wchar_t*)GlobalLock(hDecMem);
-
- bool bInSpaces = false;
- for (wchar_t *pszCur = pszSrcBuf; pszCur[0]; pszCur++) {
- if (bInSpaces) {
- if (pszCur[0] == ' ')
- continue;
- bInSpaces = false;
- }
+ if (nSelLenght <= 1)
+ return false;
- if (pszCur[0] == '\n')
- bInSpaces = true;
+ wchar_t *pszSrcBuf = new wchar_t[nSelLenght];
+ pszSrcBuf[0] = 0;
+ SendMessage(hwnd, EM_GETSELTEXT, 0, (LPARAM)pszSrcBuf);
- pszCurDec[0] = pszCur[0];
- pszCurDec++;
- }
- pszCurDec[0] = 0;
- GlobalUnlock(hDecMem);
+ wchar_t *pszCurDec = pszSrcBuf;
- SetClipboardData(CF_UNICODETEXT, hDecMem);
- delete[] pszSrcBuf;
- CloseClipboard();
- return true;
+ bool bInSpaces = false;
+ for (wchar_t *pszCur = pszSrcBuf; pszCur[0]; pszCur++) {
+ if (bInSpaces) {
+ if (pszCur[0] == ' ')
+ continue;
+ bInSpaces = false;
}
+
+ if (pszCur[0] == '\n')
+ bInSpaces = true;
+
+ *pszCurDec = *pszCur;
+ pszCurDec++;
}
- return false;
+ pszCurDec[0] = 0;
+ Utils_ClipboardCopy(pszSrcBuf);
+ delete[] pszSrcBuf;
+ return true;
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/plugins/New_GPG/src/options.cpp b/plugins/New_GPG/src/options.cpp index 5dd4c3d03c..2462694f43 100644 --- a/plugins/New_GPG/src/options.cpp +++ b/plugins/New_GPG/src/options.cpp @@ -445,45 +445,11 @@ public: } } - void onClick_COPY_KEY(CCtrlButton*) + void onClick_COPY_KEY(CCtrlButton *) { - if (OpenClipboard(m_hwnd)) { - CMStringA str(g_plugin.getMStringA("GPGPubKey")); - str.Replace("\n", "\r\n"); - - HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, str.GetLength() + 1); - if (!hMem) { - MessageBox(nullptr, TranslateT("Failed to allocate memory"), TranslateT("Error"), MB_OK); - return; - } - - char *szKey = (char*)GlobalLock(hMem); - if (!szKey) { - wchar_t msg[64]; - mir_snwprintf(msg, TranslateT("Failed to lock memory with error %d"), GetLastError()); - MessageBox(nullptr, msg, TranslateT("Error"), MB_OK); - GlobalFree(hMem); - } - else { - memcpy(szKey, str.c_str(), str.GetLength()); - szKey[str.GetLength()] = '\0'; - - EmptyClipboard(); - GlobalUnlock(hMem); - if (!SetClipboardData(CF_OEMTEXT, hMem)) { - GlobalFree(hMem); - wchar_t msg[64]; - mir_snwprintf(msg, TranslateT("Failed write to clipboard with error %d"), GetLastError()); - MessageBox(nullptr, msg, TranslateT("Error"), MB_OK); - } - CloseClipboard(); - } - } - else { - wchar_t msg[64]; - mir_snwprintf(msg, TranslateT("Failed to open clipboard with error %d"), GetLastError()); - MessageBox(nullptr, msg, TranslateT("Error"), MB_OK); - } + CMStringW str(g_plugin.getMStringW("GPGPubKey")); + str.Replace(L"\n", L"\r\n"); + Utils_ClipboardCopy(str); } void onClick_LOG_FILE_SET(CCtrlButton*) diff --git a/plugins/New_GPG/src/ui.cpp b/plugins/New_GPG/src/ui.cpp index f56c876d71..7ae95a8443 100644 --- a/plugins/New_GPG/src/ui.cpp +++ b/plugins/New_GPG/src/ui.cpp @@ -538,9 +538,6 @@ public: if (i == -1) return; - if (!OpenClipboard(m_hwnd)) - return; - list_KEY_LIST.GetItemText(i, 0, fp, _countof(fp)); gpg_execution_params params; @@ -554,32 +551,7 @@ public: return; params.out.Remove('\r'); - HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, params.out.GetLength() + 1); - if (!hMem) { - MessageBox(nullptr, TranslateT("Failed to allocate memory"), TranslateT("Error"), MB_OK); - return; - } - - char *szKey = (char *)GlobalLock(hMem); - if (!szKey) { - wchar_t msg[64]; - mir_snwprintf(msg, TranslateT("Failed to lock memory with error %d"), GetLastError()); - MessageBox(nullptr, msg, TranslateT("Error"), MB_OK); - GlobalFree(hMem); - } - - memcpy(szKey, params.out.c_str(), params.out.GetLength()); - szKey[params.out.GetLength()] = '\0'; - - EmptyClipboard(); - GlobalUnlock(hMem); - if (!SetClipboardData(CF_OEMTEXT, hMem)) { - GlobalFree(hMem); - wchar_t msg[64]; - mir_snwprintf(msg, TranslateT("Failed write to clipboard with error %d"), GetLastError()); - MessageBox(nullptr, msg, TranslateT("Error"), MB_OK); - } - CloseClipboard(); + Utils_ClipboardCopy(_A2T(params.out)); } void onClick_EXPORT_PRIVATE(CCtrlButton *) diff --git a/plugins/Popup/src/popup_wnd2.cpp b/plugins/Popup/src/popup_wnd2.cpp index ded818c45f..57f77f0121 100644 --- a/plugins/Popup/src/popup_wnd2.cpp +++ b/plugins/Popup/src/popup_wnd2.cpp @@ -952,19 +952,8 @@ LRESULT CALLBACK PopupWnd2::WindowProc(UINT message, WPARAM wParam, LPARAM lPara case ACT_DEF_COPY:
if (m_lptzText || m_lptzTitle) {
- CMStringW tszText(FORMAT, L"%s\n\n%s",
- (m_lptzTitle) ? m_lptzTitle : L"",
- (m_lptzText) ? m_lptzText : L"");
-
- if (OpenClipboard(m_hwnd)) {
- EmptyClipboard();
- HGLOBAL clipbuffer = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, (tszText.GetLength() + 1) * sizeof(wchar_t));
- wchar_t *buffer = (wchar_t *)GlobalLock(clipbuffer);
- mir_wstrcpy(buffer, tszText);
- GlobalUnlock(clipbuffer);
- SetClipboardData(CF_UNICODETEXT, clipbuffer);
- CloseClipboard();
- }
+ CMStringW tszText(FORMAT, L"%s\n\n%s", (m_lptzTitle) ? m_lptzTitle : L"", (m_lptzText) ? m_lptzText : L"");
+ Utils_ClipboardCopy(tszText);
}
PUDeletePopup(m_hwnd);
break;
diff --git a/plugins/ProxySwitch/src/main.cpp b/plugins/ProxySwitch/src/main.cpp index d8ced5f0fe..470bb4ed80 100644 --- a/plugins/ProxySwitch/src/main.cpp +++ b/plugins/ProxySwitch/src/main.cpp @@ -104,15 +104,8 @@ static INT_PTR ProxyDisable(WPARAM, LPARAM) static INT_PTR CopyIP2Clipboard(WPARAM, LPARAM, LPARAM idx) { mir_cslock lck(csNIF_List); - if (g_arNIF[idx].IPcount == 0) - return 0; - - if (!OpenClipboard(NULL)) - return 0; - - EmptyClipboard(); - SetClipboardData(CF_UNICODETEXT, (HANDLE)g_arNIF[idx].IPstr); - CloseClipboard(); + if (g_arNIF[idx].IPcount != 0) + Utils_ClipboardCopy(_A2T(g_arNIF[idx].IPstr)); return 0; } diff --git a/plugins/QuickSearch/src/window_misc.cpp b/plugins/QuickSearch/src/window_misc.cpp index 448b8369d3..e6b5e23341 100644 --- a/plugins/QuickSearch/src/window_misc.cpp +++ b/plugins/QuickSearch/src/window_misc.cpp @@ -211,15 +211,7 @@ void QSMainDlg::CopyMultiLines() buf.Append(L"\r\n"); } - if (OpenClipboard(m_hwnd)) { - EmptyClipboard(); - if (HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE, (buf.GetLength() + 1) * sizeof(wchar_t))) { - mir_wstrcpy((wchar_t *)GlobalLock(hData), buf); - GlobalUnlock(hData); - SetClipboardData(CF_UNICODETEXT, hData); - } - CloseClipboard(); - } + Utils_ClipboardCopy(buf); } void QSMainDlg::DeleteByList() diff --git a/plugins/SecureIM/src/commonheaders.cpp b/plugins/SecureIM/src/commonheaders.cpp index 8355b59a75..db6b01fe01 100644 --- a/plugins/SecureIM/src/commonheaders.cpp +++ b/plugins/SecureIM/src/commonheaders.cpp @@ -80,20 +80,6 @@ int msgbox(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType) return r;
}
-void CopyToClipboard(HWND hwnd, LPSTR msg)
-{
- HGLOBAL hglbCopy = GlobalAlloc(GMEM_MOVEABLE, mir_strlen(msg) + 1);
- LPSTR lpstrCopy = (LPSTR)GlobalLock(hglbCopy);
- mir_strcpy(lpstrCopy, msg);
- GlobalUnlock(hglbCopy);
-
- if(OpenClipboard(nullptr)) {
- EmptyClipboard();
- SetClipboardData(CF_TEXT, hglbCopy);
- CloseClipboard();
- }
-}
-
HNETLIBUSER hNetlibUser;
void InitNetlib()
diff --git a/plugins/SecureIM/src/commonheaders.h b/plugins/SecureIM/src/commonheaders.h index 50c84cf18b..60839f80b7 100644 --- a/plugins/SecureIM/src/commonheaders.h +++ b/plugins/SecureIM/src/commonheaders.h @@ -103,7 +103,6 @@ void GetFlags(); void SetFlags();
int msgbox(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType);
-void CopyToClipboard(HWND hwnd,LPSTR msg);
#endif
diff --git a/plugins/SecureIM/src/options.cpp b/plugins/SecureIM/src/options.cpp index f2917aeeb3..a04e991ea7 100644 --- a/plugins/SecureIM/src/options.cpp +++ b/plugins/SecureIM/src/options.cpp @@ -1041,9 +1041,9 @@ static INT_PTR CALLBACK DlgProcOptionsProto(HWND hDlg, UINT wMsg, WPARAM wParam, case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDC_RSA_COPY:
- char txt[128];
- GetDlgItemText(hDlg, IDC_RSA_SHA, txt, _countof(txt));
- CopyToClipboard(hDlg, txt);
+ wchar_t txt[128];
+ GetDlgItemTextW(hDlg, IDC_RSA_SHA, txt, _countof(txt));
+ Utils_ClipboardCopy(txt);
return TRUE;
case IDC_RSA_EXP:
diff --git a/plugins/SendScreenshotPlus/src/CSend.cpp b/plugins/SendScreenshotPlus/src/CSend.cpp index f13760b7de..5a5e72e03e 100644 --- a/plugins/SendScreenshotPlus/src/CSend.cpp +++ b/plugins/SendScreenshotPlus/src/CSend.cpp @@ -162,23 +162,9 @@ INT_PTR CALLBACK CSend::ResultDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, memcpy(tmp + len, L"[/img][/url]", 13 * sizeof(wchar_t)); len += 12; } } - else - len = GetDlgItemText(hwndDlg, edtID, tmp, _countof(tmp)); - int retries = 3; - do { - if (!OpenClipboard(hwndDlg)) { - Sleep(100); - continue; - } - EmptyClipboard(); - HGLOBAL clipbuffer = GlobalAlloc(GMEM_MOVEABLE, len*sizeof(wchar_t) + sizeof(wchar_t)); - wchar_t* tmp2 = (wchar_t*)GlobalLock(clipbuffer); - mir_wstrncpy(tmp2, tmp, len + 1); tmp2[len] = '\0'; - GlobalUnlock(clipbuffer); - SetClipboardData(CF_UNICODETEXT, clipbuffer); - CloseClipboard(); - break; - } while (--retries); + else len = GetDlgItemText(hwndDlg, edtID, tmp, _countof(tmp)); + + Utils_ClipboardCopy(CMStringW(tmp, len + 1)); if (LOWORD(wParam) == IDOK) DestroyWindow(hwndDlg); diff --git a/plugins/SimpleStatusMsg/src/awaymsg.cpp b/plugins/SimpleStatusMsg/src/awaymsg.cpp index 6d25de503b..e034dc3009 100644 --- a/plugins/SimpleStatusMsg/src/awaymsg.cpp +++ b/plugins/SimpleStatusMsg/src/awaymsg.cpp @@ -115,28 +115,9 @@ public: void onClick_Copy(CCtrlButton*)
{
- if (!OpenClipboard(m_hwnd))
- return;
-
- if (EmptyClipboard()) {
- wchar_t msg[1024];
- int len = GetDlgItemText(m_hwnd, IDC_MSG, msg, _countof(msg));
- if (len) {
- LPTSTR lptstrCopy;
- HGLOBAL hglbCopy = GlobalAlloc(GMEM_MOVEABLE, (len + 1) * sizeof(wchar_t));
- if (hglbCopy == nullptr) {
- CloseClipboard();
- return;
- }
- lptstrCopy = (LPTSTR)GlobalLock(hglbCopy);
- memcpy(lptstrCopy, msg, len * sizeof(wchar_t));
- lptstrCopy[len] = (wchar_t)0;
- GlobalUnlock(hglbCopy);
-
- SetClipboardData(CF_UNICODETEXT, hglbCopy);
- }
- }
- CloseClipboard();
+ wchar_t msg[1024];
+ GetDlgItemText(m_hwnd, IDC_MSG, msg, _countof(msg));
+ Utils_ClipboardCopy(msg);
}
};
@@ -203,25 +184,10 @@ public: m_hAwayMsgEvent = nullptr;
}
- if (OpenClipboard(m_hwnd)) {
- if (EmptyClipboard()) {
- CMStringW wszMsg((wchar_t *)ack->lParam);
- wszMsg.Replace(L"\n", L"\r\n");
- if (wszMsg.GetLength()) {
- LPTSTR lptstrCopy;
- HGLOBAL hglbCopy = GlobalAlloc(GMEM_MOVEABLE, (wszMsg.GetLength() + 1) * sizeof(wchar_t));
- if (hglbCopy != nullptr) {
- lptstrCopy = (LPTSTR)GlobalLock(hglbCopy);
- memcpy(lptstrCopy, wszMsg, wszMsg.GetLength() * sizeof(wchar_t));
- lptstrCopy[wszMsg.GetLength()] = 0;
- GlobalUnlock(hglbCopy);
-
- SetClipboardData(CF_UNICODETEXT, hglbCopy);
- }
- }
- }
- CloseClipboard();
- }
+ CMStringW wszMsg((wchar_t *)ack->lParam);
+ wszMsg.Replace(L"\n", L"\r\n");
+ Utils_ClipboardCopy(wszMsg);
+
Close();
}
diff --git a/plugins/SimpleStatusMsg/src/msgbox.cpp b/plugins/SimpleStatusMsg/src/msgbox.cpp index 20d1a60343..6c21e44ef9 100644 --- a/plugins/SimpleStatusMsg/src/msgbox.cpp +++ b/plugins/SimpleStatusMsg/src/msgbox.cpp @@ -461,30 +461,9 @@ VOID APIENTRY HandlePopupMenu(HWND hwnd, POINT pt, HWND edit_control) break; default: - if (!OpenClipboard(GetParent(hwnd))) - break; - - if (EmptyClipboard()) { - wchar_t item_string[128]; - GetMenuString(hmenu, m_selection, (LPTSTR)&item_string, 128, MF_BYCOMMAND); - - int len = (int)mir_wstrlen(item_string); - if (len) { - LPTSTR lptstrCopy; - HGLOBAL hglbCopy = GlobalAlloc(GMEM_MOVEABLE, (len + 1) * sizeof(wchar_t)); - if (hglbCopy == nullptr) { - CloseClipboard(); - break; - } - lptstrCopy = (LPTSTR)GlobalLock(hglbCopy); - memcpy(lptstrCopy, item_string, len * sizeof(wchar_t)); - lptstrCopy[len] = (wchar_t)0; - GlobalUnlock(hglbCopy); - - SetClipboardData(CF_UNICODETEXT, hglbCopy); - } - } - CloseClipboard(); + wchar_t item_string[128]; + GetMenuString(hmenu, m_selection, (LPTSTR)&item_string, 128, MF_BYCOMMAND); + Utils_ClipboardCopy(item_string); SendMessage(edit_control, WM_PASTE, 0, 0); break; } |