summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-02-23 19:57:58 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-02-23 19:57:58 +0300
commitdc597d70cef7202480eae6708e2142148e09356f (patch)
tree459e171a2e8a5bb2def7d7aea67fb769aa224bb2 /src
parent349ff91be06644a8b611ecf6a39ce0ac1bcde86a (diff)
clipboard copy function is able now to copy in multiple formats at a time
Diffstat (limited to 'src')
-rw-r--r--src/core/stdmsg/src/msgdialog.cpp2
-rw-r--r--src/core/stdpopup/src/yapp_history_dlg.cpp2
-rw-r--r--src/core/stduserinfo/src/stdinfo.cpp2
-rw-r--r--src/mir_app/src/file.h2
-rw-r--r--src/mir_app/src/srmm_log_rtf.cpp2
-rw-r--r--src/mir_core/mir_core.vcxproj3
-rw-r--r--src/mir_core/mir_core.vcxproj.filters3
-rw-r--r--src/mir_core/src/Windows/clipboard.cpp111
-rw-r--r--src/mir_core/src/Windows/winutil.cpp42
-rw-r--r--src/mir_core/src/mir_core.def15
-rw-r--r--src/mir_core/src/mir_core64.def15
11 files changed, 148 insertions, 51 deletions
diff --git a/src/core/stdmsg/src/msgdialog.cpp b/src/core/stdmsg/src/msgdialog.cpp
index 6f17354162..5b808c4ee9 100644
--- a/src/core/stdmsg/src/msgdialog.cpp
+++ b/src/core/stdmsg/src/msgdialog.cpp
@@ -662,7 +662,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));
- Utils_ClipboardCopy(id);
+ Utils_ClipboardCopy(MClipUnicode(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 dc6a5775ad..8b6e1b7506 100644
--- a/src/core/stdpopup/src/yapp_history_dlg.cpp
+++ b/src/core/stdpopup/src/yapp_history_dlg.cpp
@@ -422,7 +422,7 @@ void CopyPopupDataToClipboard(HWND hList, int selection)
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);
+ Utils_ClipboardCopy(MClipUnicode(buffer));
break;
}
}
diff --git a/src/core/stduserinfo/src/stdinfo.cpp b/src/core/stduserinfo/src/stdinfo.cpp
index b2fed06847..a2a72e1d80 100644
--- a/src/core/stduserinfo/src/stdinfo.cpp
+++ b/src/core/stduserinfo/src/stdinfo.cpp
@@ -130,7 +130,7 @@ public:
{
wchar_t buf[1024];
if (GetDlgItemText(m_hwnd, IDC_ADDR, buf, _countof(buf)))
- Utils_ClipboardCopy(buf);
+ Utils_ClipboardCopy(MClipUnicode(buf));
}
int Resizer(UTILRESIZECONTROL *urc) override
diff --git a/src/mir_app/src/file.h b/src/mir_app/src/file.h
index 01b7b47fab..677222615e 100644
--- a/src/mir_app/src/file.h
+++ b/src/mir_app/src/file.h
@@ -145,7 +145,7 @@ struct OFD_CopyUrl : public OFD_Callback
void Invoke(const OFDTHREAD &ofd) override
{
- Utils_ClipboardCopy(ofd.wszPath.IsEmpty() ? wszUrl : ofd.wszPath);
+ Utils_ClipboardCopy(MClipUnicode(ofd.wszPath.IsEmpty() ? wszUrl : ofd.wszPath));
}
};
diff --git a/src/mir_app/src/srmm_log_rtf.cpp b/src/mir_app/src/srmm_log_rtf.cpp
index 6b81c438d0..709d173c74 100644
--- a/src/mir_app/src/srmm_log_rtf.cpp
+++ b/src/mir_app/src/srmm_log_rtf.cpp
@@ -278,7 +278,7 @@ INT_PTR CRtfLogWindow::Notify(WPARAM, LPARAM lParam)
break;
case IDM_COPYLINK:
- Utils_ClipboardCopy(wszText);
+ Utils_ClipboardCopy(MClipUnicode(wszText));
break;
}
diff --git a/src/mir_core/mir_core.vcxproj b/src/mir_core/mir_core.vcxproj
index 5926603bf0..fa4f5b08c3 100644
--- a/src/mir_core/mir_core.vcxproj
+++ b/src/mir_core/mir_core.vcxproj
@@ -125,6 +125,9 @@
<ClCompile Include="src\Windows\CDlgBase.cpp">
<PrecompiledHeaderFile>../stdafx.h</PrecompiledHeaderFile>
</ClCompile>
+ <ClCompile Include="src\Windows\clipboard.cpp">
+ <PrecompiledHeaderFile>../stdafx.h</PrecompiledHeaderFile>
+ </ClCompile>
<ClCompile Include="src\Windows\cmdline.cpp">
<PrecompiledHeaderFile>../stdafx.h</PrecompiledHeaderFile>
</ClCompile>
diff --git a/src/mir_core/mir_core.vcxproj.filters b/src/mir_core/mir_core.vcxproj.filters
index 1b936d0685..1ead550a86 100644
--- a/src/mir_core/mir_core.vcxproj.filters
+++ b/src/mir_core/mir_core.vcxproj.filters
@@ -185,6 +185,9 @@
<ClCompile Include="src\Windows\shareable.cpp">
<Filter>Source Files\Windows</Filter>
</ClCompile>
+ <ClCompile Include="src\Windows\clipboard.cpp">
+ <Filter>Source Files\Windows</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\stdafx.h">
diff --git a/src/mir_core/src/Windows/clipboard.cpp b/src/mir_core/src/Windows/clipboard.cpp
new file mode 100644
index 0000000000..13c52a5c44
--- /dev/null
+++ b/src/mir_core/src/Windows/clipboard.cpp
@@ -0,0 +1,111 @@
+/*
+
+Miranda NG: the free IM client for Microsoft* Windows*
+
+Copyright (C) 2012-24 Miranda NG team (https://miranda-ng.org),
+Copyright (c) 2000-12 Miranda IM project,
+all portions of this codebase are copyrighted to the people
+listed in contributors.txt.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "../stdafx.h"
+
+static UINT g_iRtf = 0;
+
+MClipAnsi::MClipAnsi(const char *pszString) :
+ m_szString(pszString)
+{}
+
+void MClipAnsi::Copy() const
+{
+ size_t cbLen = mir_strlen(m_szString);
+ if (!cbLen)
+ return;
+
+ HGLOBAL hData = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, cbLen + 1);
+ if (hData) {
+ mir_strcpy((char *)GlobalLock(hData), m_szString);
+ GlobalUnlock(hData);
+ SetClipboardData(CF_TEXT, hData);
+ }
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+MClipRtf::MClipRtf(const char *pszString) :
+ m_szString(pszString)
+{}
+
+void MClipRtf::Copy() const
+{
+ size_t cbLen = mir_strlen(m_szString);
+ if (!cbLen)
+ return;
+
+ if (g_iRtf == 0)
+ g_iRtf = RegisterClipboardFormatW(CF_RTF);
+
+ HGLOBAL hData = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, cbLen + 1);
+ if (hData) {
+ mir_strcpy((char *)GlobalLock(hData), m_szString);
+ GlobalUnlock(hData);
+ SetClipboardData(g_iRtf, hData);
+ }
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+MClipUnicode::MClipUnicode(const wchar_t *pwszString) :
+ m_wszString(pwszString)
+{}
+
+void MClipUnicode::Copy() const
+{
+ size_t cbLen = mir_wstrlen(m_wszString);
+ if (!cbLen)
+ return;
+
+ HGLOBAL hData = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, (cbLen + 1) * sizeof(wchar_t));
+ if (hData) {
+ mir_wstrcpy((wchar_t *)GlobalLock(hData), m_wszString);
+ GlobalUnlock(hData);
+ SetClipboardData(CF_UNICODETEXT, hData);
+ }
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+MClipData& MClipData::operator+(const MClipData &p2)
+{
+ m_pNext = &p2;
+ return *this;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+MIR_CORE_DLL(void) Utils_ClipboardCopy(const MClipData &pData)
+{
+ if (!OpenClipboard(nullptr))
+ return;
+
+ EmptyClipboard();
+
+ for (const MClipData *p = &pData; p; p = p->m_pNext)
+ p->Copy();
+
+ CloseClipboard();
+}
diff --git a/src/mir_core/src/Windows/winutil.cpp b/src/mir_core/src/Windows/winutil.cpp
index b0bdc915ee..6320622ada 100644
--- a/src/mir_core/src/Windows/winutil.cpp
+++ b/src/mir_core/src/Windows/winutil.cpp
@@ -133,45 +133,3 @@ MIR_CORE_DLL(int) Utils_CorrectFontSize(int size)
return size * ncm.lfMessageFont.lfHeight / -12;
}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
-MIR_CORE_DLL(void) Utils_ClipboardCopy(const char *pszText)
-{
- size_t cbLen = mir_strlen(pszText);
- if (!cbLen)
- return;
-
- if (!OpenClipboard(nullptr))
- return;
-
- EmptyClipboard();
-
- HGLOBAL hData = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, cbLen+1);
- if (hData) {
- mir_strcpy((char *)GlobalLock(hData), pszText);
- GlobalUnlock(hData);
- SetClipboardData(CF_TEXT, hData);
- }
- CloseClipboard();
-}
-
-MIR_CORE_DLL(void) Utils_ClipboardCopy(const wchar_t *pwszText)
-{
- size_t cbLen = mir_wstrlen(pwszText);
- if (!cbLen)
- return;
-
- if (!OpenClipboard(nullptr))
- 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 66d2dda017..dc56ef8ee3 100644
--- a/src/mir_core/src/mir_core.def
+++ b/src/mir_core/src/mir_core.def
@@ -1539,8 +1539,7 @@ _Utils_CorrectFontSize@4 @1762 NONAME
?OnResize@CDlgBase@@MAEXXZ @1763 NONAME
??0MBinBuffer@@QAE@ABV0@@Z @1764 NONAME
??0MBinBuffer@@QAE@I@Z @1765 NONAME
-?Utils_ClipboardCopy@@YGXPBD@Z @1766 NONAME
-?Utils_ClipboardCopy@@YGXPB_W@Z @1767 NONAME
+?Utils_ClipboardCopy@@YGXABUMClipData@@@Z @1766 NONAME
?mir_base64_encode@@YGPADABVMBinBuffer@@@Z @1768 NONAME
?append@MBinBuffer@@QAEXABV1@@Z @1769 NONAME
?appendBefore@MBinBuffer@@QAEXABV1@@Z @1770 NONAME
@@ -1565,3 +1564,15 @@ _EventExists@4 @1787 NONAME
_newStr@4 @1789 NONAME
?ChildElementCount@XMLNode@tinyxml2@@QBEHPBD@Z @1790 NONAME
?ChildElementCount@XMLNode@tinyxml2@@QBEHXZ @1791 NONAME
+??0MClipAnsi@@QAE@PBD@Z @1792 NONAME
+??0MClipData@@QAE@XZ @1793 NONAME
+??0MClipRtf@@QAE@PBD@Z @1794 NONAME
+??0MClipUnicode@@QAE@PB_W@Z @1795 NONAME
+??HMClipData@@QAEAAU0@ABU0@@Z @1796 NONAME
+??_7MClipAnsi@@6B@ @1797 NONAME
+??_7MClipData@@6B@ @1798 NONAME
+??_7MClipRtf@@6B@ @1799 NONAME
+??_7MClipUnicode@@6B@ @1800 NONAME
+?Copy@MClipAnsi@@UBEXXZ @1801 NONAME
+?Copy@MClipRtf@@UBEXXZ @1802 NONAME
+?Copy@MClipUnicode@@UBEXXZ @1803 NONAME
diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def
index 061063c7d1..7d9885b02d 100644
--- a/src/mir_core/src/mir_core64.def
+++ b/src/mir_core/src/mir_core64.def
@@ -1539,8 +1539,7 @@ Utils_CorrectFontSize @1762 NONAME
?OnResize@CDlgBase@@MEAAXXZ @1763 NONAME
??0MBinBuffer@@QEAA@AEBV0@@Z @1764 NONAME
??0MBinBuffer@@QEAA@_K@Z @1765 NONAME
-?Utils_ClipboardCopy@@YAXPEBD@Z @1766 NONAME
-?Utils_ClipboardCopy@@YAXPEB_W@Z @1767 NONAME
+?Utils_ClipboardCopy@@YAXAEBUMClipData@@@Z @1766 NONAME
?mir_base64_encode@@YAPEADAEBVMBinBuffer@@@Z @1768 NONAME
?append@MBinBuffer@@QEAAXAEBV1@@Z @1769 NONAME
?appendBefore@MBinBuffer@@QEAAXAEBV1@@Z @1770 NONAME
@@ -1565,3 +1564,15 @@ EventExists @1787 NONAME
newStr @1789 NONAME
?ChildElementCount@XMLNode@tinyxml2@@QEBAHPEBD@Z @1790 NONAME
?ChildElementCount@XMLNode@tinyxml2@@QEBAHXZ @1791 NONAME
+??0MClipAnsi@@QEAA@PEBD@Z @1792 NONAME
+??0MClipData@@QEAA@XZ @1793 NONAME
+??0MClipRtf@@QEAA@PEBD@Z @1794 NONAME
+??0MClipUnicode@@QEAA@PEB_W@Z @1795 NONAME
+??HMClipData@@QEAAAEAU0@AEBU0@@Z @1796 NONAME
+??_7MClipAnsi@@6B@ @1797 NONAME
+??_7MClipData@@6B@ @1798 NONAME
+??_7MClipRtf@@6B@ @1799 NONAME
+??_7MClipUnicode@@6B@ @1800 NONAME
+?Copy@MClipAnsi@@UEBAXXZ @1801 NONAME
+?Copy@MClipRtf@@UEBAXXZ @1802 NONAME
+?Copy@MClipUnicode@@UEBAXXZ @1803 NONAME