13#if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
24 DWORD dwProcessID = 0;
25 GetWindowThreadProcessId(hWnd, &dwProcessID);
27 if (dwProcessID != (DWORD)lParam)
30 if (GetParent(hWnd) ==
nullptr)
42 DWORD dwProcessID = 0;
43 GetWindowThreadProcessId(hWnd, &dwProcessID);
45 if (dwProcessID != GetCurrentProcessId())
48 if (GetWindowLongPtr(hWnd, GWLP_HINSTANCE) == lParam)
58 WindowsClipboardHandler::WindowsClipboardHandler()
62 void WindowsClipboardHandler::initialise()
66 GetModuleFileName(0, (LPCH)&buf, MAX_PATH);
68 HINSTANCE instance = GetModuleHandle(buf);
70 EnumChildWindows(GetDesktopWindow(), (WNDENUMPROC)
EnumWindowProc, (LPARAM)instance);
74 newDelegate(
this, &WindowsClipboardHandler::handleClipboardChanged);
76 newDelegate(
this, &WindowsClipboardHandler::handleClipboardRequested);
79 void WindowsClipboardHandler::shutdown()
82 newDelegate(
this, &WindowsClipboardHandler::handleClipboardChanged);
84 newDelegate(
this, &WindowsClipboardHandler::handleClipboardRequested);
87 void WindowsClipboardHandler::handleClipboardChanged(std::string_view _type, std::string_view _data)
92 size_t size = (mPutTextInClipboard.size() + 1) * 2;
94 if (OpenClipboard((HWND)mHwnd))
97 HGLOBAL hgBuffer = GlobalAlloc(GMEM_DDESHARE, size);
98 wchar_t* chBuffer = hgBuffer ? (
wchar_t*)GlobalLock(hgBuffer) : nullptr;
101 memcpy(chBuffer, mPutTextInClipboard.asWStr_c_str(), size);
102 GlobalUnlock(hgBuffer);
103 SetClipboardData(CF_UNICODETEXT, hgBuffer);
110 void WindowsClipboardHandler::handleClipboardRequested(std::string_view _type, std::string& _data)
116 if (OpenClipboard((HWND)mHwnd))
118 HANDLE hData = GetClipboardData(CF_UNICODETEXT);
119 wchar_t* chBuffer = hData ? (
wchar_t*)GlobalLock(hData) : nullptr;
128 if (mPutTextInClipboard != buff)
132 _data = text.asUTF8();
static ClipboardManager & getInstance()
EventPairConvertStringView< delegates::MultiDelegate< const std::string &, const std::string & >, delegates::MultiDelegate< std::string_view, std::string_view > > eventClipboardChanged
EventPairConvertStringView< delegates::MultiDelegate< const std::string &, std::string & >, delegates::MultiDelegate< std::string_view, std::string & > > eventClipboardRequested
static UString getOnlyText(const UString &_text)
static UString toTagsString(const UString &_text)
BOOL CALLBACK EnumChildWindowProc(HWND hWnd, LPARAM lParam)
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
BOOL CALLBACK EnumWindowProc(HWND hWnd, LPARAM lParam)