#include "wx/metafile.h"
#endif
+#include "wx/log.h"
#include "wx/clipbrd.h"
+#include <string.h>
#include <windows.h>
#include "wx/msw/private.h"
// therefore so is wxClipboard :-(
#if wxUSE_DRAG_AND_DROP
#include "wx/dataobj.h"
+
+ static bool wxSetClipboardData(wxDataObject *data);
#endif
-#include <string.h>
+#ifdef __WIN16__
+ #define memcpy hmemcpy
+#endif
// ===========================================================================
// implementation
return ::IsClipboardFormatAvailable(dataFormat) != 0;
}
+#if wxUSE_DRAG_AND_DROP
+static bool wxSetClipboardData(wxDataObject *data)
+{
+ size_t size = data->GetDataSize();
+ HANDLE hGlobal = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, size);
+ if ( !hGlobal )
+ {
+ wxLogSysError(_("Failed to allocate %dKb of memory for clipboard "
+ "transfer."), size / 1024);
+
+ return FALSE;
+ }
+
+ LPVOID lpGlobalMemory = ::GlobalLock(hGlobal);
+
+ data->GetDataHere(lpGlobalMemory);
+
+ GlobalUnlock(hGlobal);
+
+ wxDataFormat format = data->GetPreferredFormat();
+ if ( !::SetClipboardData(format, hGlobal) )
+ {
+ wxLogSysError(_("Failed to set clipboard data in format %s"),
+ wxDataObject::GetFormatName(format));
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+#endif // wxUSE_DRAG_AND_DROP
+
bool wxSetClipboardData(wxDataFormat dataFormat,
const void *data,
int width, int height)
{
wxMetafile *wxMF = (wxMetafile *)data;
HANDLE data = GlobalAlloc(GHND, sizeof(METAFILEPICT) + 1);
-#ifdef __WINDOWS_386__
- METAFILEPICT *mf = (METAFILEPICT *)MK_FP32(GlobalLock(data));
-#else
METAFILEPICT *mf = (METAFILEPICT *)GlobalLock(data);
-#endif
mf->mm = wxMF->GetWindowsMappingMode();
mf->xExt = width;
HANDLE hGlobalMemory = GlobalAlloc(GHND, l);
if ( hGlobalMemory )
{
-#ifdef __WINDOWS_386__
- LPSTR lpGlobalMemory = (LPSTR)MK_FP32(GlobalLock(hGlobalMemory));
-#else
LPSTR lpGlobalMemory = (LPSTR)GlobalLock(hGlobalMemory);
-#endif
-#ifdef __WIN32__
memcpy(lpGlobalMemory, s, l);
-#elif defined(__WATCOMC__) && defined(__WINDOWS_386__)
- memcpy(lpGlobalMemory, s, l);
-#else
- hmemcpy(lpGlobalMemory, s, l);
-#endif
GlobalUnlock(hGlobalMemory);
}
case CF_TIFF:
case CF_PALETTE:
case wxDF_DIB:
- default:
{
wxLogError(_("Unsupported clipboard format."));
return FALSE;
if (!s)
break;
-#ifdef __WINDOWS_386__
- LPSTR lpGlobalMemory = (LPSTR)MK_FP32(GlobalLock(hGlobalMemory));
-#else
LPSTR lpGlobalMemory = (LPSTR)::GlobalLock(hGlobalMemory);
-#endif
-#ifdef __WIN32__
- memcpy(s, lpGlobalMemory, hsize);
-#elif __WATCOMC__ && defined(__WINDOWS_386__)
memcpy(s, lpGlobalMemory, hsize);
-#else
- hmemcpy(s, lpGlobalMemory, hsize);
-#endif
::GlobalUnlock(hGlobalMemory);
retval = s;
break;
}
+
+ default:
+ {
+ HANDLE hGlobalMemory = ::GetClipboardData(dataFormat);
+ if ( !hGlobalMemory )
+ break;
+
+ DWORD size = ::GlobalSize(hGlobalMemory);
+ if ( len )
+ *len = size;
+
+ void *buf = malloc(size);
+ if ( !buf )
+ break;
+
+ LPSTR lpGlobalMemory = (LPSTR)::GlobalLock(hGlobalMemory);
+
+ memcpy(buf, lpGlobalMemory, size);
+
+ ::GlobalUnlock(hGlobalMemory);
+
+ retval = buf;
+ break;
+ }
}
if ( !retval )
return retval;
}
-wxDataFormat wxEnumClipboardFormats(wxDataFormat dataFormat)
+wxDataFormat wxEnumClipboardFormats(wxDataFormat dataFormat)
{
- return (wxDataFormat)::EnumClipboardFormats(dataFormat);
+ return ::EnumClipboardFormats(dataFormat);
}
int wxRegisterClipboardFormat(char *formatName)
#endif // wxUSE_METAFILE
default:
- wxLogError(_("Can not put data in format '%s' on clipboard."),
- wxDataObject::GetFormatName(format));
-
- return FALSE;
+ return wxSetClipboardData(data);
}
-
+#else // !wxUSE_DRAG_AND_DROP
return FALSE;
-#else
- return FALSE;
-#endif
+#endif // wxUSE_DRAG_AND_DROP/!wxUSE_DRAG_AND_DROP
}
void wxClipboard::Close()
}
#endif
default:
- wxLogError(_("Can not get data in format '%s' from clipboard."),
- wxDataObject::GetFormatName(format));
+ {
+ long len;
+ void *buf = wxGetClipboardData(format, &len);
+ if ( buf )
+ {
+ // FIXME this is for testing only!!
+ ((wxPrivateDataObject *)data)->SetData(buf, len);
+ free(buf);
+
+ return TRUE;
+ }
+ }
return FALSE;
}