comparison foosdk/sdk/libPPUI/clipboard.cpp @ 1:20d02a178406 default tip

*: check in everything else yay
author Paper <paper@tflc.us>
date Mon, 05 Jan 2026 02:15:46 -0500
parents
children
comparison
equal deleted inserted replaced
0:e9bb126753e7 1:20d02a178406
1 #include "stdafx.h"
2
3 #include "clipboard.h"
4 #include "win32_op.h"
5
6 #ifdef UNICODE
7 #define CF_TCHAR CF_UNICODETEXT
8 #else
9 #define CF_TCHAR CF_TEXT
10 #endif
11
12 namespace ClipboardHelper {
13 void OpenScope::Open(HWND p_owner) {
14 Close();
15 WIN32_OP(OpenClipboard(p_owner));
16 m_open = true;
17 }
18 void OpenScope::Close() {
19 if (m_open) {
20 m_open = false;
21 CloseClipboard();
22 }
23 }
24 void SetRaw(UINT format,const void * data, t_size size) {
25 HANDLE buffer = GlobalAlloc(GMEM_DDESHARE,size);
26 if (buffer == NULL) throw std::bad_alloc();
27 try {
28 CGlobalLockScope lock(buffer);
29 PFC_ASSERT(lock.GetSize() == size);
30 memcpy(lock.GetPtr(),data,size);
31 } catch(...) {
32 GlobalFree(buffer); throw;
33 }
34
35 WIN32_OP(SetClipboardData(format,buffer) != NULL);
36 }
37 void SetString(const char * in) {
38 pfc::stringcvt::string_os_from_utf8 temp(in);
39 SetRaw(CF_TCHAR,temp.get_ptr(),(temp.length() + 1) * sizeof(TCHAR));
40 }
41
42 bool GetString(pfc::string_base & out) {
43 pfc::array_t<t_uint8> temp;
44 if (!GetRaw(CF_TCHAR,temp)) return false;
45 out = pfc::stringcvt::string_utf8_from_os(reinterpret_cast<const TCHAR*>(temp.get_ptr()),temp.get_size() / sizeof(TCHAR));
46 return true;
47 }
48 bool IsTextAvailable() {
49 return IsClipboardFormatAvailable(CF_TCHAR) == TRUE;
50 }
51 }