X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dbda9e86f0e5ec1184bc16d135bb7205bc99236e..30760ce7e58df02af3308cd7de8bd7694e791b8d:/src/msw/clipbrd.cpp diff --git a/src/msw/clipbrd.cpp b/src/msw/clipbrd.cpp index 9fb76f0b08..cd94dce908 100644 --- a/src/msw/clipbrd.cpp +++ b/src/msw/clipbrd.cpp @@ -41,6 +41,7 @@ #include "wx/frame.h" #include "wx/bitmap.h" #include "wx/utils.h" + #include "wx/intl.h" #endif #if wxUSE_METAFILE @@ -50,6 +51,7 @@ #include "wx/log.h" #include "wx/clipbrd.h" +#include #include #include "wx/msw/private.h" @@ -59,9 +61,13 @@ // therefore so is wxClipboard :-( #if wxUSE_DRAG_AND_DROP #include "wx/dataobj.h" + + static bool wxSetClipboardData(wxDataObject *data); #endif -#include +#ifdef __WIN16__ + #define memcpy hmemcpy +#endif // =========================================================================== // implementation @@ -75,7 +81,7 @@ static bool gs_wxClipboardIsOpen = FALSE; 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 ) @@ -89,7 +95,7 @@ bool wxOpenClipboard() } else { - wxLogDebug("Can not open clipboard without a main window,"); + wxLogDebug(wxT("Can not open clipboard without a main window.")); return FALSE; } @@ -97,7 +103,7 @@ bool wxOpenClipboard() bool wxCloseClipboard() { - wxCHECK_MSG( gs_wxClipboardIsOpen, FALSE, "clipboard is not opened" ); + wxCHECK_MSG( gs_wxClipboardIsOpen, FALSE, wxT("clipboard is not opened") ); gs_wxClipboardIsOpen = FALSE; @@ -133,6 +139,38 @@ bool wxIsClipboardFormatAvailable(wxDataFormat dataFormat) 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) @@ -183,7 +221,7 @@ bool wxSetClipboardData(wxDataFormat dataFormat, 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; @@ -194,11 +232,7 @@ bool wxSetClipboardData(wxDataFormat dataFormat, { 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; @@ -235,19 +269,9 @@ bool wxSetClipboardData(wxDataFormat dataFormat, 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); } @@ -325,7 +349,6 @@ void *wxGetClipboardData(wxDataFormat dataFormat, long *len) case CF_TIFF: case CF_PALETTE: case wxDF_DIB: - default: { wxLogError(_("Unsupported clipboard format.")); return FALSE; @@ -349,25 +372,39 @@ void *wxGetClipboardData(wxDataFormat dataFormat, long *len) 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 ) @@ -378,18 +415,18 @@ void *wxGetClipboardData(wxDataFormat dataFormat, long *len) 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; @@ -433,10 +470,10 @@ bool wxClipboard::SetData( wxDataObject *data ) 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(); @@ -471,16 +508,11 @@ bool wxClipboard::AddData( wxDataObject *data ) #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() @@ -495,7 +527,7 @@ bool wxClipboard::IsSupported( wxDataFormat format ) 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(); @@ -546,8 +578,18 @@ bool wxClipboard::GetData( wxDataObject *data ) } #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; }