#include "wx/frame.h"
#include "wx/bitmap.h"
#include "wx/utils.h"
+ #include "wx/intl.h"
#endif
#if wxUSE_METAFILE
#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
bool wxOpenClipboard()
{
- wxCHECK_MSG( !gs_wxClipboardIsOpen, TRUE, "clipboard already opened." );
+ wxCHECK_MSG( !gs_wxClipboardIsOpen, TRUE, wxT("clipboard already opened.") );
wxWindow *win = wxTheApp->GetTopWindow();
if ( win )
}
else
{
- wxLogDebug("Can not open clipboard without a main window,");
+ wxLogDebug(wxT("Can not open clipboard without a main window."));
return FALSE;
}
bool wxCloseClipboard()
{
- wxCHECK_MSG( gs_wxClipboardIsOpen, FALSE, "clipboard is not opened" );
+ wxCHECK_MSG( gs_wxClipboardIsOpen, FALSE, wxT("clipboard is not opened") );
gs_wxClipboardIsOpen = FALSE;
return ::IsClipboardFormatAvailable(dataFormat) != 0;
}
+#if wxUSE_DRAG_AND_DROP
+static bool wxSetClipboardData(wxDataObject *data)
+{
+ wxDataFormat format = data->GetPreferredFormat();
+ size_t size = data->GetDataSize(format);
+ 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(format, lpGlobalMemory);
+
+ GlobalUnlock(hGlobal);
+
+ 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)
wxBitmap *bitmap = (wxBitmap *)data;
HBITMAP hBitmap = (HBITMAP)bitmap->GetHBITMAP();
// NULL palette means to use the system one
- HANDLE hDIB = BitmapToDIB(hBitmap, (HPALETTE)NULL);
+ HANDLE hDIB = wxBitmapToDIB(hBitmap, (HPALETTE)NULL);
handle = SetClipboardData(CF_DIB, hDIB);
#endif
break;
{
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)
+int wxRegisterClipboardFormat(wxChar *formatName)
{
return ::RegisterClipboardFormat(formatName);
}
bool wxGetClipboardFormatName(wxDataFormat dataFormat,
- char *formatName,
+ wxChar *formatName,
int maxCount)
{
return ::GetClipboardFormatName((int)dataFormat, formatName, maxCount) > 0;
bool wxClipboard::AddData( wxDataObject *data )
{
- wxCHECK_MSG( data, FALSE, "data is invalid" );
+ wxCHECK_MSG( data, FALSE, wxT("data is invalid") );
#if wxUSE_DRAG_AND_DROP
- wxCHECK_MSG( wxIsClipboardOpened(), FALSE, "clipboard not open" );
+ wxCHECK_MSG( wxIsClipboardOpened(), FALSE, wxT("clipboard not open") );
wxDataFormat format = data->GetFormat();
#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()
bool wxClipboard::GetData( wxDataObject *data )
{
- wxCHECK_MSG( wxIsClipboardOpened(), FALSE, "clipboard not open" );
+ wxCHECK_MSG( wxIsClipboardOpened(), FALSE, wxT("clipboard not open") );
#if wxUSE_DRAG_AND_DROP
wxDataFormat format = data->GetFormat();
}
#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;
}