+#if defined(WIN32)
+
+const char* c_clipboard_format = "RadiantClippings";
+
+#include <windows.h>
+
+void clipboard_copy(ClipboardCopyFunc copy)
+{
+ BufferOutputStream ostream;
+ copy(ostream);
+
+ bool bClipped = false;
+ UINT nClipboard = ::RegisterClipboardFormat(c_clipboard_format);
+ if (nClipboard > 0)
+ {
+ if (::OpenClipboard(0))
+ {
+ EmptyClipboard();
+ std::size_t length = ostream.size();
+ HANDLE h = ::GlobalAlloc(GMEM_ZEROINIT | GMEM_MOVEABLE | GMEM_DDESHARE, length + sizeof(std::size_t));
+ if (h != 0)
+ {
+ char *buffer = reinterpret_cast<char*>(::GlobalLock(h));
+ *reinterpret_cast<std::size_t*>(buffer) = length;
+ buffer += sizeof(std::size_t);
+ memcpy(buffer, ostream.data(), length);
+ ::GlobalUnlock(h);
+ ::SetClipboardData(nClipboard, h);
+ ::CloseClipboard();
+ bClipped = true;
+ }
+ }
+ }
+
+ if (!bClipped)
+ {
+ globalOutputStream() << "Unable to register Windows clipboard formats, copy/paste between editors will not be possible\n";
+ }
+}
+
+void clipboard_paste(ClipboardPasteFunc paste)
+{
+ UINT nClipboard = ::RegisterClipboardFormat(c_clipboard_format);
+ if (nClipboard > 0 && ::OpenClipboard(0))
+ {
+ if(IsClipboardFormatAvailable(nClipboard))
+ {
+ HANDLE h = ::GetClipboardData(nClipboard);
+ if(h)
+ {
+ const char *buffer = reinterpret_cast<const char*>(::GlobalLock(h));
+ std::size_t length = *reinterpret_cast<const std::size_t*>(buffer);
+ buffer += sizeof(std::size_t);
+ BufferInputStream istream(buffer, length);
+ paste(istream);
+ ::GlobalUnlock(h);
+ }
+ }
+ ::CloseClipboard();
+ }
+}
+
+#else