X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/519cb848a8f4c91c73421bb75314754284e593a4..0b7e6e7da208b6a95fb23cb50286a09dc90d96d2:/src/mac/clipbrd.cpp diff --git a/src/mac/clipbrd.cpp b/src/mac/clipbrd.cpp index 28a4b9ef3f..36f4c0f4d9 100644 --- a/src/mac/clipbrd.cpp +++ b/src/mac/clipbrd.cpp @@ -23,11 +23,7 @@ #include -#if !USE_SHARED_LIBRARY -IMPLEMENT_DYNAMIC_CLASS(wxClipboard, wxObject) -IMPLEMENT_ABSTRACT_CLASS(wxClipboardClient, wxObject) -#endif - +// open/close bool wxOpenClipboard() { return TRUE; @@ -35,54 +31,52 @@ bool wxOpenClipboard() bool wxCloseClipboard() { - return FALSE; + return TRUE; } -bool wxEmptyClipboard() +bool wxIsClipboardOpened() { - ZeroScrap() ; - return FALSE; + return TRUE; } -bool wxClipboardOpen() +// get/set data + +bool wxEmptyClipboard() { - // TODO - return FALSE; + ZeroScrap() ; + return TRUE; } -bool wxIsClipboardFormatAvailable(int dataFormat) +bool wxSetClipboardData(wxDataFormat dataFormat,const void *data,int width , int height) { - // TODO return FALSE; } -bool wxSetClipboardData(int dataFormat, wxObject *obj, int width, int height) +void *wxGetClipboardData(wxDataFormat dataFormat, long *len) { - // TODO - return FALSE; + return NULL; } -wxObject *wxGetClipboardData(int dataFormat, long *len) + +// clipboard formats + +bool wxIsClipboardFormatAvailable(wxDataFormat dataFormat) { - // TODO - return NULL; + return FALSE; } -int wxEnumClipboardFormats(int dataFormat) +wxDataFormat wxEnumClipboardFormats(wxDataFormat dataFormat) { - // TODO - return 0; + return wxDataFormat(); } -int wxRegisterClipboardFormat(char *formatName) +int wxRegisterClipboardFormat(wxChar *formatName) { - // TODO return 0; } -bool wxGetClipboardFormatName(int dataFormat, char *formatName, int maxCount) +bool wxGetClipboardFormatName(wxDataFormat dataFormat, wxChar *formatName, int maxCount) { - // TODO return FALSE; } @@ -90,26 +84,38 @@ bool wxGetClipboardFormatName(int dataFormat, char *formatName, int maxCount) * Generalized clipboard implementation by Matthew Flatt */ -wxClipboard *wxTheClipboard = NULL; +IMPLEMENT_DYNAMIC_CLASS(wxClipboard, wxObject) -void wxInitClipboard() +wxClipboard::wxClipboard() { - if (!wxTheClipboard) - wxTheClipboard = new wxClipboard; + m_clearOnExit = FALSE; } -wxClipboard::wxClipboard() +wxClipboard::~wxClipboard() { - clipOwner = NULL; - cbString = NULL; + if ( m_clearOnExit ) + { + Clear(); + } } -wxClipboard::~wxClipboard() +void wxClipboard::Clear() { - if (clipOwner) - clipOwner->BeingReplaced(); - if (cbString) - delete[] cbString; +} + +bool wxClipboard::Flush() +{ + return FALSE; +} + +bool wxClipboard::Open() +{ + return wxOpenClipboard(); +} + +bool wxClipboard::IsOpened() const +{ + return wxIsClipboardOpened(); } static int FormatStringToID(char *str) @@ -120,6 +126,129 @@ static int FormatStringToID(char *str) return wxRegisterClipboardFormat(str); } +bool wxClipboard::SetData( wxDataObject *data ) +{ + (void)wxEmptyClipboard(); + + if ( data ) + return AddData(data); + else + return TRUE; +} + +bool wxClipboard::AddData( wxDataObject *data ) +{ + wxCHECK_MSG( data, FALSE, wxT("data is invalid") ); + +#if wxUSE_DATAOBJ + wxCHECK_MSG( wxIsClipboardOpened(), FALSE, wxT("clipboard not open") ); + + wxDataFormat format = data->GetFormat(); + + switch ( format ) + { + case wxDF_TEXT: + case wxDF_OEMTEXT: + { + wxTextDataObject* textDataObject = (wxTextDataObject*) data; + wxString str(textDataObject->GetText()); + return wxSetClipboardData(format, str.c_str()); + } + + case wxDF_BITMAP: + case wxDF_DIB: + { + wxBitmapDataObject* bitmapDataObject = (wxBitmapDataObject*) data; + wxBitmap bitmap(bitmapDataObject->GetBitmap()); + return wxSetClipboardData(data->GetFormat(), &bitmap); + } + +#if wxUSE_METAFILE + case wxDF_METAFILE: + { + wxMetafileDataObject* metaFileDataObject = + (wxMetafileDataObject*) data; + wxMetafile metaFile = metaFileDataObject->GetMetafile(); + return wxSetClipboardData(wxDF_METAFILE, &metaFile, + metaFileDataObject->GetWidth(), + metaFileDataObject->GetHeight()); + } +#endif // wxUSE_METAFILE + + default: + return wxSetClipboardData(data); + } +#else // !wxUSE_DATAOBJ + return FALSE; +#endif +} + +void wxClipboard::Close() +{ + wxCloseClipboard(); +} + +bool wxClipboard::IsSupported( wxDataFormat format ) +{ + return wxIsClipboardFormatAvailable(format); +} + +bool wxClipboard::GetData( wxDataObject& data ) +{ +#if wxUSE_DATAOBJ + wxCHECK_MSG( wxIsClipboardOpened(), FALSE, wxT("clipboard not open") ); + + wxDataFormat format = data.GetFormat(); + switch ( format ) + { + case wxDF_TEXT: + case wxDF_OEMTEXT: + { + wxTextDataObject& textDataObject = (wxTextDataObject &)data; + char* s = (char*)wxGetClipboardData(format); + if ( !s ) + return FALSE; + + textDataObject.SetText(s); + delete [] s; + + return TRUE; + } + + case wxDF_BITMAP: + case wxDF_DIB: + { + wxBitmapDataObject& bitmapDataObject = (wxBitmapDataObject &)data; + wxBitmap* bitmap = (wxBitmap *)wxGetClipboardData(data->GetFormat()); + if ( !bitmap ) + return FALSE; + + bitmapDataObject.SetBitmap(*bitmap); + delete bitmap; + + return TRUE; + } +#if wxUSE_METAFILE + case wxDF_METAFILE: + { + wxMetafileDataObject& metaFileDataObject = (wxMetafileDataObject &)data; + wxMetafile* metaFile = (wxMetafile *)wxGetClipboardData(wxDF_METAFILE); + if ( !metaFile ) + return FALSE; + + metaFileDataObject.SetMetafile(*metaFile); + delete metaFile; + + return TRUE; + } +#endif // wxUSE_METAFILE + } +#else // !wxUSE_DATAOBJ + wxFAIL_MSG( wxT("no clipboard implementation") ); +#endif + return FALSE; +} +/* void wxClipboard::SetClipboardClient(wxClipboardClient *client, long time) { bool got_selection; @@ -167,7 +296,7 @@ wxClipboardClient *wxClipboard::GetClipboardClient() } void wxClipboard::SetClipboardString(char *str, long time) -{/* +{ bool got_selection; if (clipOwner) { @@ -193,9 +322,7 @@ void wxClipboard::SetClipboardString(char *str, long time) delete[] cbString; cbString = NULL; } - */ } - char *wxClipboard::GetClipboardString(long time) { char *str; @@ -210,6 +337,7 @@ char *wxClipboard::GetClipboardString(long time) return str; } + char *wxClipboard::GetClipboardData(char *format, long *length, long time) { if (clipOwner) { @@ -233,4 +361,5 @@ char *wxClipboard::GetClipboardData(char *format, long *length, long time) return receivedString; } } +*/