aboutsummaryrefslogtreecommitdiff
path: root/CPP/Windows/Clipboard.cpp
diff options
context:
space:
mode:
authorIgor Pavlov <87184205+ip7z@users.noreply.github.com>2021-12-27 00:00:00 +0000
committerIgor Pavlov <87184205+ip7z@users.noreply.github.com>2022-03-18 15:35:13 +0500
commitf19f813537c7aea1c20749c914e756b54a9c3cf5 (patch)
tree816ba62ca7c0fa19f2eb46d9e9d6f7dd7c3a744d /CPP/Windows/Clipboard.cpp
parent98e06a519b63b81986abe76d28887f6984a7732b (diff)
download7zip-21.07.tar.gz
7zip-21.07.tar.bz2
7zip-21.07.zip
'21.07'21.07
Diffstat (limited to 'CPP/Windows/Clipboard.cpp')
-rw-r--r--CPP/Windows/Clipboard.cpp130
1 files changed, 130 insertions, 0 deletions
diff --git a/CPP/Windows/Clipboard.cpp b/CPP/Windows/Clipboard.cpp
new file mode 100644
index 0000000..bc7e201
--- /dev/null
+++ b/CPP/Windows/Clipboard.cpp
@@ -0,0 +1,130 @@
1// Windows/Clipboard.cpp
2
3#include "StdAfx.h"
4
5#ifdef UNDER_CE
6#include <winuserm.h>
7#endif
8
9#include "../Common/StringConvert.h"
10
11#include "Clipboard.h"
12#include "Defs.h"
13#include "MemoryGlobal.h"
14#include "Shell.h"
15
16namespace NWindows {
17
18bool CClipboard::Open(HWND wndNewOwner) throw()
19{
20 m_Open = BOOLToBool(::OpenClipboard(wndNewOwner));
21 return m_Open;
22}
23
24bool CClipboard::Close() throw()
25{
26 if (!m_Open)
27 return true;
28 m_Open = !BOOLToBool(CloseClipboard());
29 return !m_Open;
30}
31
32bool ClipboardIsFormatAvailableHDROP()
33{
34 return BOOLToBool(IsClipboardFormatAvailable(CF_HDROP));
35}
36
37/*
38bool ClipboardGetTextString(AString &s)
39{
40 s.Empty();
41 if (!IsClipboardFormatAvailable(CF_TEXT))
42 return false;
43 CClipboard clipboard;
44
45 if (!clipboard.Open(NULL))
46 return false;
47
48 HGLOBAL h = ::GetClipboardData(CF_TEXT);
49 if (h != NULL)
50 {
51 NMemory::CGlobalLock globalLock(h);
52 const char *p = (const char *)globalLock.GetPointer();
53 if (p != NULL)
54 {
55 s = p;
56 return true;
57 }
58 }
59 return false;
60}
61*/
62
63/*
64bool ClipboardGetFileNames(UStringVector &names)
65{
66 names.Clear();
67 if (!IsClipboardFormatAvailable(CF_HDROP))
68 return false;
69 CClipboard clipboard;
70
71 if (!clipboard.Open(NULL))
72 return false;
73
74 HGLOBAL h = ::GetClipboardData(CF_HDROP);
75 if (h != NULL)
76 {
77 NMemory::CGlobalLock globalLock(h);
78 void *p = (void *)globalLock.GetPointer();
79 if (p != NULL)
80 {
81 NShell::CDrop drop(false);
82 drop.Attach((HDROP)p);
83 drop.QueryFileNames(names);
84 return true;
85 }
86 }
87 return false;
88}
89*/
90
91static bool ClipboardSetData(UINT uFormat, const void *data, size_t size) throw()
92{
93 NMemory::CGlobal global;
94 if (!global.Alloc(GMEM_DDESHARE | GMEM_MOVEABLE, size))
95 return false;
96 {
97 NMemory::CGlobalLock globalLock(global);
98 LPVOID p = globalLock.GetPointer();
99 if (!p)
100 return false;
101 memcpy(p, data, size);
102 }
103 if (::SetClipboardData(uFormat, global) == NULL)
104 return false;
105 global.Detach();
106 return true;
107}
108
109bool ClipboardSetText(HWND owner, const UString &s)
110{
111 CClipboard clipboard;
112 if (!clipboard.Open(owner))
113 return false;
114 if (!::EmptyClipboard())
115 return false;
116
117 bool res;
118 res = ClipboardSetData(CF_UNICODETEXT, (const wchar_t *)s, (s.Len() + 1) * sizeof(wchar_t));
119 #ifndef _UNICODE
120 AString a (UnicodeStringToMultiByte(s, CP_ACP));
121 if (ClipboardSetData(CF_TEXT, (const char *)a, (a.Len() + 1) * sizeof(char)))
122 res = true;
123 a = UnicodeStringToMultiByte(s, CP_OEMCP);
124 if (ClipboardSetData(CF_OEMTEXT, (const char *)a, (a.Len() + 1) * sizeof(char)))
125 res = true;
126 #endif
127 return res;
128}
129
130}