X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e6ebb51430cd8e4a9a11c6c5a5ca7c3ff9d7a72a..222702b112dcc7bebe018d6f4d66fe469fefd02c:/src/os2/dataobj.cpp diff --git a/src/os2/dataobj.cpp b/src/os2/dataobj.cpp index 98031a0a75..e0941f6268 100644 --- a/src/os2/dataobj.cpp +++ b/src/os2/dataobj.cpp @@ -6,7 +6,7 @@ // Created: 10/21/99 // RCS-ID: $Id$ // Copyright: (c) 1999 David Webster -// Licence: wxWindows license +// Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -41,166 +41,185 @@ // functions // ---------------------------------------------------------------------------- -#ifdef __WXDEBUG__ - static const wxChar *GetTymedName(DWORD tymed); -#endif // Debug - // ---------------------------------------------------------------------------- // wxDataFormat // ---------------------------------------------------------------------------- -wxDataFormat::wxDataFormat() -{ - m_vType = wxDF_INVALID; - m_vFormat = 0; -} - -wxDataFormat::wxDataFormat( - wxDataFormatId vType -) +wxString wxDataFormat::GetId() const { - PrepareFormats(); - SetType(vType); -} + wxChar zBuf[256]; + wxString sRet; + + ::WinQueryAtomName( ::WinQuerySystemAtomTable() + ,m_uFormat + ,(PSZ)zBuf + ,256 + ); + sRet = zBuf; + return sRet; +} // end of wxDataFormat::GetId() -wxDataFormat::wxDataFormat( +void wxDataFormat::SetId ( const wxChar* zId ) { - PrepareFormats(); - SetId(zId); -} + m_uFormat = ::WinAddAtom( ::WinQuerySystemAtomTable() + ,(PSZ)zId + ); +} // end of wxDataFormat::SetId -wxDataFormat::wxDataFormat( - const wxString& rId -) +class CIDataObject { - PrepareFormats(); - SetId(rId); -} - -wxDataFormat::wxDataFormat( - NativeFormat vFormat +public: + CIDataObject(wxDataObject* pDataObject); + ~CIDataObject(); + + // + // Operations on the DRAGITEM struct + // + bool GetData( const wxDataFormat& rFormat + ,char* pzBuffer + ,ULONG ulLen + ); + void GetDataHere( const wxDataFormat& rFormat + ,char* pzBuffer + ,ULONG ulLen + ); + void QueryGetData(const wxDataFormat& rFormat); + void SetData( const wxDataFormat& rFormat + ,char* pzBuffer + ); +private: + wxDataObject* m_pDataObject; // pointer to C++ class we belong to + DRAGITEM m_vDragItem; +}; // end of CLASS CIDataObject + +bool CIDataObject::GetData ( + const wxDataFormat& rFormat +, char* pzBuffer +, ULONG ulLen ) { - PrepareFormats(); - SetId(vFormat); -} + QueryGetData(rFormat); + if (rFormat.GetType() == wxDF_INVALID) + return FALSE; -void wxDataFormat::SetType( - wxDataFormatId vType -) -{ - m_vType = vType; - - if (m_vType == wxDF_TEXT) - m_vFormat = 0; - else - if (m_vType == wxDF_BITMAP) - m_vFormat = 0; - else - if (m_vType == wxDF_FILENAME) - m_vFormat = 0; - else + ULONG ulSize = m_pDataObject->GetDataSize(rFormat); + + if (ulSize == 0) { - wxFAIL_MSG( wxT("invalid dataformat") ); + // + // It probably means that the method is just not implemented + // + return FALSE; + } + if (rFormat.GetType() == wxDF_PRIVATE) + { + // + // For custom formats, put the size with the data - alloc the + // space for it + // + ulSize += sizeof(ULONG); } -} -wxDataFormatId wxDataFormat::GetType() const -{ - return m_vType; -} + if (ulSize > ulLen) // not enough room to copy + return FALSE; -wxString wxDataFormat::GetId() const + // + // Copy the data + // + GetDataHere( rFormat + ,pzBuffer + ,ulSize + ); + return TRUE; +} // end of CIDataObject::GetData + +void CIDataObject::GetDataHere( + const wxDataFormat& rFormat +, char* pzBuffer +, ULONG WXUNUSED(ulLen) +) { - wxString sRet(""); // TODO: gdk_atom_name( m_format ) ); - return sRet; -} + m_pDataObject->GetDataHere( rFormat + ,(void*)pzBuffer + ); +} // end of CIDataObject::GetDataHere -void wxDataFormat::SetId( - NativeFormat vFormat +void CIDataObject::QueryGetData ( + const wxDataFormat& rFormat ) { - m_vFormat = vFormat; -// TODO: -/* - if (m_format == g_textAtom) - m_type = wxDF_TEXT; - else - if (m_format == g_pngAtom) - m_type = wxDF_BITMAP; - else - if (m_format == g_fileAtom) - m_type = wxDF_FILENAME; - else - m_type = wxDF_PRIVATE; -*/ -} + m_pDataObject->IsSupportedFormat(rFormat); +} // end of CIDataObject::QueryGetData -void wxDataFormat::SetId( - const wxChar* zId +void CIDataObject::SetData ( + const wxDataFormat& rFormat +, char* pzBuffer ) { - wxString tmp(zId); + ULONG ulSize = 0; - m_vType = wxDF_PRIVATE; - m_vFormat = 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE ); -} + switch (rFormat.GetType()) + { + case wxDF_TEXT: + case wxDF_OEMTEXT: + case wxDF_FILENAME: + case wxDF_HTML: + ulSize = strlen((const char *)pzBuffer); + break; + +#if wxUSE_UNICODE + case wxDF_UNICODETEXT: + ulSize = ::wcslen((const wchar_t *)pzBuffer); + break; +#endif -void wxDataFormat::PrepareFormats() -{ -// TODO: -/* - if (!g_textAtom) - g_textAtom = gdk_atom_intern( "STRING", FALSE ); - if (!g_pngAtom) - g_pngAtom = gdk_atom_intern( "image/png", FALSE ); - if (!g_fileAtom) - g_fileAtom = gdk_atom_intern( "file:ALL", FALSE ); -*/ -} + case wxDF_BITMAP: + case wxDF_METAFILE: + case wxDF_ENHMETAFILE: + case wxDF_TIFF: + case wxDF_DIB: + ulSize = 0; // pass via a handle + break; + + + case wxDF_SYLK: + case wxDF_DIF: + case wxDF_PALETTE: + case wxDF_PENDATA: + case wxDF_RIFF: + case wxDF_WAVE: + case wxDF_LOCALE: + //PUNT + break; + + case wxDF_PRIVATE: + size_t* p = (size_t *)pzBuffer; + + ulSize = *p++; + pzBuffer = (char*)p; + break; + } + m_pDataObject->SetData( rFormat + ,ulSize + ,(void*)pzBuffer + ); +} // end of CIDataObject::SetData //------------------------------------------------------------------------- // wxDataObject //------------------------------------------------------------------------- -wxDataObject::wxDataObject() +wxDataObject::wxDataObject () { -} + m_pDataObject = new DRAGITEM; +} // end of wxDataObject::wxDataObject -bool wxDataObject::IsSupportedFormat( - const wxDataFormat& rFormat -, Direction vDir -) const +wxDataObject::~wxDataObject () { - size_t nFormatCount = GetFormatCount(vDir); - - if (nFormatCount == 1) - { - return rFormat == GetPreferredFormat(); - } - else - { - wxDataFormat* pFormats = new wxDataFormat[nFormatCount]; - GetAllFormats( pFormats - ,vDir - ); - - size_t n; - - for (n = 0; n < nFormatCount; n++) - { - if (pFormats[n] == rFormat) - break; - } - - delete [] pFormats; - - // found? - return n < nFormatCount; - } -} + delete m_pDataObject; +} // end of wxDataObject::~wxDataObject // ---------------------------------------------------------------------------- // wxFileDataObject @@ -242,7 +261,7 @@ bool wxFileDataObject::SetData( { /* TODO */ - wxString sFile( (const char *)pBuf); /* char, not wxChar */ + wxString sFile((const wxChar *)pBuf); /* char, not wxChar */ AddFile(sFile); @@ -313,6 +332,7 @@ bool wxBitmapDataObject::SetData( memcpy(m_pngData, pBuf, m_pngSize); +#if wxUSE_STREAMS wxMemoryInputStream vMstream((char*)m_pngData, m_pngSize); wxImage vImage; wxPNGHandler vHandler; @@ -322,7 +342,9 @@ bool wxBitmapDataObject::SetData( return FALSE; } - m_bitmap = vImage.ConvertToBitmap(); + m_bitmap = wxBitmap(vImage); +#endif //wxUSE_STREAMS + return m_bitmap.Ok(); } @@ -331,7 +353,8 @@ void wxBitmapDataObject::DoConvertToPng() if (!m_bitmap.Ok()) return; - wxImage vImage(m_bitmap); +#if wxUSE_STREAMS + wxImage vImage = m_bitmap.ConvertToImage(); wxPNGHandler vHandler; wxCountingOutputStream vCount; @@ -343,5 +366,6 @@ void wxBitmapDataObject::DoConvertToPng() wxMemoryOutputStream vMstream((char*) m_pngData, m_pngSize); vHandler.SaveFile(&vImage, vMstream ); +#endif }