#if wxUSE_CLIPBOARD
#ifndef WX_PRECOMP
+#include "wx/object.h"
+#include "wx/event.h"
#include "wx/app.h"
#include "wx/frame.h"
#include "wx/bitmap.h"
#include "wx/utils.h"
#endif
+#if wxUSE_METAFILE
#include "wx/metafile.h"
+#endif
+
#include "wx/clipbrd.h"
+
+#include <windows.h>
+
+HICON myIcon;
+
#include "wx/msw/private.h"
#include "wx/msw/dib.h"
-#include <string.h>
-
-#if !USE_SHARED_LIBRARY
-IMPLEMENT_DYNAMIC_CLASS(wxClipboard, wxObject)
-IMPLEMENT_ABSTRACT_CLASS(wxClipboardClient, wxObject)
+// wxDataObject is tied to OLE/drag and drop implementation,
+// therefore so is wxClipboard :-(
+#if wxUSE_DRAG_AND_DROP
+#include "wx/dataobj.h"
#endif
+#include <string.h>
+
bool wxClipboardIsOpen = FALSE;
bool wxOpenClipboard(void)
return wxClipboardIsOpen;
}
-bool wxIsClipboardFormatAvailable(int dataFormat)
+bool wxIsClipboardFormatAvailable(wxDataFormat dataFormat)
{
return (::IsClipboardFormatAvailable(dataFormat) != 0);
}
-bool wxSetClipboardData(int dataFormat, wxObject *obj, int width, int height)
+bool wxSetClipboardData(wxDataFormat dataFormat, wxObject *obj, int width, int height)
{
switch (dataFormat)
{
{
wxBitmap *wxBM = (wxBitmap *)obj;
- HDC hdcMem = CreateCompatibleDC(NULL);
- HDC hdcSrc = CreateCompatibleDC(NULL);
+ HDC hdcMem = CreateCompatibleDC((HDC) NULL);
+ HDC hdcSrc = CreateCompatibleDC((HDC) NULL);
HBITMAP old = (HBITMAP) ::SelectObject(hdcSrc, (HBITMAP) wxBM->GetHBITMAP());
HBITMAP hBitmap = CreateCompatibleBitmap(hdcSrc,
wxBM->GetWidth(), wxBM->GetHeight());
{
#if wxUSE_IMAGE_LOADING_IN_MSW
HBITMAP hBitmap=(HBITMAP) ((wxBitmap *)obj)->GetHBITMAP();
- HANDLE hDIB=BitmapToDIB(hBitmap,NULL); // NULL==uses system palette
+ HANDLE hDIB=BitmapToDIB(hBitmap,(HPALETTE) NULL); // NULL==uses system palette
bool success = (::SetClipboardData(CF_DIB,hDIB) != 0);
#else
bool success=FALSE;
#if wxUSE_METAFILE
case wxDF_METAFILE:
{
- wxMetaFile *wxMF = (wxMetaFile *)obj;
+ wxMetafile *wxMF = (wxMetafile *)obj;
HANDLE data = GlobalAlloc(GHND, sizeof(METAFILEPICT) + 1);
#ifdef __WINDOWS_386__
METAFILEPICT *mf = (METAFILEPICT *)MK_FP32(GlobalLock(data));
return FALSE;
}
-wxObject *wxGetClipboardData(int dataFormat, long *len)
+wxObject *wxGetClipboardData(wxDataFormat dataFormat, long *len)
{
switch (dataFormat)
{
if (!hBitmap)
return NULL;
- HDC hdcMem = CreateCompatibleDC(NULL);
- HDC hdcSrc = CreateCompatibleDC(NULL);
+ HDC hdcMem = CreateCompatibleDC((HDC) NULL);
+ HDC hdcSrc = CreateCompatibleDC((HDC) NULL);
HBITMAP old = (HBITMAP) ::SelectObject(hdcSrc, hBitmap);
GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
return NULL;
}
-int wxEnumClipboardFormats(int dataFormat)
+wxDataFormat wxEnumClipboardFormats(wxDataFormat dataFormat)
{
- return ::EnumClipboardFormats(dataFormat);
+ return (wxDataFormat) ::EnumClipboardFormats(dataFormat);
}
int wxRegisterClipboardFormat(char *formatName)
return ::RegisterClipboardFormat(formatName);
}
-bool wxGetClipboardFormatName(int dataFormat, char *formatName, int maxCount)
+bool wxGetClipboardFormatName(wxDataFormat dataFormat, char *formatName, int maxCount)
{
- return (::GetClipboardFormatName(dataFormat, formatName, maxCount) > 0);
+ return (::GetClipboardFormatName((int) dataFormat, formatName, maxCount) > 0);
}
-/*
- * Generalized clipboard implementation by Matthew Flatt
- */
+//-----------------------------------------------------------------------------
+// wxClipboard
+//-----------------------------------------------------------------------------
-wxClipboard *wxTheClipboard = NULL;
+IMPLEMENT_DYNAMIC_CLASS(wxClipboard,wxObject)
-void wxInitClipboard(void)
-{
- if (!wxTheClipboard)
- wxTheClipboard = new wxClipboard;
-}
+wxClipboard* wxTheClipboard = (wxClipboard*) NULL;
wxClipboard::wxClipboard()
{
- clipOwner = NULL;
- cbString = NULL;
+ m_open = FALSE;
}
wxClipboard::~wxClipboard()
{
- if (clipOwner)
- clipOwner->BeingReplaced();
- if (cbString)
- delete[] cbString;
+ Clear();
}
-static int FormatStringToID(char *str)
+void wxClipboard::Clear()
{
- if (!strcmp(str, "TEXT"))
- return wxDF_TEXT;
+#if wxUSE_DRAG_AND_DROP
+ wxNode* node = m_data.First();
+ while (node)
+ {
+ wxDataObject* data = (wxDataObject*) node->Data();
+ delete data;
+ node = node->Next();
+ }
+ m_data.Clear();
+#endif
+}
+
+bool wxClipboard::Open()
+{
+ wxCHECK_MSG( !m_open, FALSE, "clipboard already open" );
+
+ m_open = TRUE;
- return wxRegisterClipboardFormat(str);
+ return wxOpenClipboard();
}
-void wxClipboard::SetClipboardClient(wxClipboardClient *client, long time)
+bool wxClipboard::SetData( wxDataObject *data )
{
- bool got_selection;
-
- if (clipOwner)
- clipOwner->BeingReplaced();
- clipOwner = client;
- if (cbString) {
- delete[] cbString;
- cbString = NULL;
- }
+#if wxUSE_DRAG_AND_DROP
+ wxCHECK_MSG( data, FALSE, "data is invalid" );
+ wxCHECK_MSG( m_open, FALSE, "clipboard not open" );
- if (wxOpenClipboard()) {
- char **formats, *data;
- int i;
- int ftype;
- long size;
-
- formats = clipOwner->formats.ListToArray(FALSE);
- for (i = clipOwner->formats.Number(); i--; ) {
- ftype = FormatStringToID(formats[i]);
- data = clipOwner->GetData(formats[i], &size);
- if (!wxSetClipboardData(ftype, (wxObject *)data, size, 1)) {
- got_selection = FALSE;
- break;
- }
+ switch (data->GetFormat())
+ {
+ case wxDF_TEXT:
+ case wxDF_OEMTEXT:
+ {
+ wxTextDataObject* textDataObject = (wxTextDataObject*) data;
+ wxString str(textDataObject->GetText());
+ return wxSetClipboardData(data->GetFormat(), (wxObject*) (const char*) str);
+ break;
+ }
+ case wxDF_BITMAP:
+ case wxDF_DIB:
+ {
+ wxBitmapDataObject* bitmapDataObject = (wxBitmapDataObject*) data;
+ wxBitmap bitmap(bitmapDataObject->GetBitmap());
+ return wxSetClipboardData(data->GetFormat(), & bitmap);
+ break;
+ }
+#if wxUSE_METAFILE
+ case wxDF_METAFILE:
+ {
+ wxMetafileDataObject* metaFileDataObject = (wxMetafileDataObject*) data;
+ wxMetafile metaFile = metaFileDataObject->GetMetafile();
+ return wxSetClipboardData(wxDF_METAFILE, & metaFile, metaFileDataObject->GetWidth(), metaFileDataObject->GetHeight());
+ break;
+ }
+#endif
+ default:
+ {
+ return FALSE;
+ }
}
-
- if (i < 0)
- got_selection = wxCloseClipboard();
- } else
- got_selection = FALSE;
- got_selection = FALSE; // Assume another process takes over
-
- if (!got_selection) {
- clipOwner->BeingReplaced();
- clipOwner = NULL;
- }
+ return FALSE;
+#else
+ return FALSE;
+#endif
}
-wxClipboardClient *wxClipboard::GetClipboardClient()
+void wxClipboard::Close()
{
- return clipOwner;
+ wxCHECK_RET( m_open, "clipboard not open" );
+
+ m_open = FALSE;
+ wxCloseClipboard();
}
-void wxClipboard::SetClipboardString(char *str, long time)
+bool wxClipboard::IsSupportedFormat( wxDataFormat format, const wxString& WXUNUSED(id) )
{
- bool got_selection;
-
- if (clipOwner) {
- clipOwner->BeingReplaced();
- clipOwner = NULL;
- }
- if (cbString)
- delete[] cbString;
-
- cbString = str;
-
- if (wxOpenClipboard()) {
- if (!wxSetClipboardData(wxDF_TEXT, (wxObject *)str))
- got_selection = FALSE;
- else
- got_selection = wxCloseClipboard();
- } else
- got_selection = FALSE;
-
- got_selection = FALSE; // Assume another process takes over
-
- if (!got_selection) {
- delete[] cbString;
- cbString = NULL;
- }
+ return wxIsClipboardFormatAvailable(format);
}
-char *wxClipboard::GetClipboardString(long time)
+bool wxClipboard::GetData( wxDataObject *data )
{
- char *str;
- long length;
+ wxCHECK_MSG( m_open, FALSE, "clipboard not open" );
+
+#if wxUSE_DRAG_AND_DROP
+ switch (data->GetFormat())
+ {
+ case wxDF_TEXT:
+ case wxDF_OEMTEXT:
+ {
+ wxTextDataObject* textDataObject = (wxTextDataObject*) data;
+ char* s = (char*) wxGetClipboardData(data->GetFormat());
+ if (s)
+ {
+ textDataObject->SetText(s);
+ delete[] s;
+ return TRUE;
+ }
+ else
+ return FALSE;
+ break;
+ }
+ case wxDF_BITMAP:
+ case wxDF_DIB:
+ {
+ wxBitmapDataObject* bitmapDataObject = (wxBitmapDataObject*) data;
+ wxBitmap* bitmap = (wxBitmap*) wxGetClipboardData(data->GetFormat());
+ if (bitmap)
+ {
+ bitmapDataObject->SetBitmap(* bitmap);
+ delete bitmap;
+ return TRUE;
+ }
+ else
+ return FALSE;
+ break;
+ }
+#if wxUSE_METAFILE
+ case wxDF_METAFILE:
+ {
+ wxMetafileDataObject* metaFileDataObject = (wxMetafileDataObject*) data;
+ wxMetafile* metaFile = (wxMetafile*) wxGetClipboardData(wxDF_METAFILE);
+ if (metaFile)
+ {
+ metaFileDataObject->SetMetafile(* metaFile);
+ delete metaFile;
+ return TRUE;
+ }
+ else
+ return FALSE;
+
+ break;
+ }
+#endif
+ default:
+ {
+ return FALSE;
+ }
+ }
+ return FALSE;
+#else
+ return FALSE;
+#endif
+}
- str = GetClipboardData("TEXT", &length, time);
- if (!str) {
- str = new char[1];
- *str = 0;
- }
+//-----------------------------------------------------------------------------
+// wxClipboardModule
+//-----------------------------------------------------------------------------
- return str;
-}
+IMPLEMENT_DYNAMIC_CLASS(wxClipboardModule,wxModule)
-char *wxClipboard::GetClipboardData(char *format, long *length, long time)
+bool wxClipboardModule::OnInit()
{
- if (clipOwner) {
- if (clipOwner->formats.Member(format))
- return clipOwner->GetData(format, length);
- else
- return NULL;
- } else if (cbString) {
- if (!strcmp(format, "TEXT"))
- return copystring(cbString);
- else
- return NULL;
- } else {
- if (wxOpenClipboard()) {
- receivedString = (char *)wxGetClipboardData(FormatStringToID(format),
- length);
- wxCloseClipboard();
- } else
- receivedString = NULL;
-
- return receivedString;
- }
+ wxTheClipboard = new wxClipboard();
+
+ return TRUE;
}
+void wxClipboardModule::OnExit()
+{
+ if (wxTheClipboard) delete wxTheClipboard;
+ wxTheClipboard = (wxClipboard*) NULL;
+}
#endif // wxUSE_CLIPBOARD