]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/dataobj.cpp
adding raw_control for osx
[wxWidgets.git] / src / os2 / dataobj.cpp
index 80c9b8479c3e49d293bac6b061897026cc114850..be55a32aef8f159f322bb8b5c9ed7ed8342d725d 100644 (file)
@@ -1,12 +1,12 @@
 ///////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////
-// Name:        os2/dataobj.cpp
+// Name:        src/os2/dataobj.cpp
 // Purpose:     implementation of wx[I]DataObject class
 // Author:      David Webster
 // Modified by:
 // Created:     10/21/99
 // RCS-ID:      $Id$
 // Copyright:   (c) 1999 David Webster
 // Purpose:     implementation of wx[I]DataObject class
 // Author:      David Webster
 // Modified by:
 // Created:     10/21/99
 // RCS-ID:      $Id$
 // Copyright:   (c) 1999 David Webster
-// Licence:     wxWindows license
+// Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
 
 // ============================================================================
 ///////////////////////////////////////////////////////////////////////////////
 
 // ============================================================================
 // headers
 // ----------------------------------------------------------------------------
 
 // headers
 // ----------------------------------------------------------------------------
 
-#ifdef __GNUG__
-  #pragma implementation "dataobj.h"
-#endif
-
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
+#if wxUSE_DATAOBJ
+
+#include "wx/dataobj.h"
+
 #ifndef WX_PRECOMP
 #ifndef WX_PRECOMP
-#include "wx/intl.h"
+    #include "wx/intl.h"
+    #include "wx/log.h"
+    #include "wx/image.h"
 #endif
 #endif
-#include "wx/defs.h"
 
 
-#include "wx/log.h"
-#include "wx/dataobj.h"
+#include "wx/mstream.h"
 
 
-#define INCL_DOS
-#include <os2.h>
+#include "wx/os2/private.h"
 
 // ----------------------------------------------------------------------------
 // functions
 // ----------------------------------------------------------------------------
 
 
 // ----------------------------------------------------------------------------
 // functions
 // ----------------------------------------------------------------------------
 
-#ifdef __WXDEBUG__
-    static const wxChar *GetTymedName(DWORD tymed);
-#endif // Debug
-
 // ----------------------------------------------------------------------------
 // wxDataFormat
 // ----------------------------------------------------------------------------
 
 // ----------------------------------------------------------------------------
 // wxDataFormat
 // ----------------------------------------------------------------------------
 
-wxDataFormat::wxDataFormat(
-  wxDataFormatId                    vType
-)
+wxString wxDataFormat::GetId() const
 {
 {
-    PrepareFormats();
-    m_vType = wxDF_INVALID;
-    m_vFormat = 0;
-}
+    wxChar                          zBuf[256];
+    wxString                        sRet;
+
+    ::WinQueryAtomName( ::WinQuerySystemAtomTable()
+                       ,m_uFormat
+                       ,(PSZ)zBuf
+                       ,256
+                      );
+    sRet = zBuf;
+    return sRet;
+} // end of wxDataFormat::GetId()
 
 
-wxDataFormat::wxDataFormat(
-  wxDataFormatId                    vType
+void wxDataFormat::SetId (
+  const wxString&                     zId
 )
 {
 )
 {
-    PrepareFormats();
-    SetType(vType);
-}
+    m_uFormat = ::WinAddAtom( ::WinQuerySystemAtomTable()
+                             ,zId.char_str()
+                            );
+} // end of wxDataFormat::SetId
 
 
-wxDataFormat::wxDataFormat(
-  const wxChar*                     zId
-)
+class CIDataObject
 {
 {
-    PrepareFormats();
-    SetId(zId);
-}
-
-wxDataFormat::wxDataFormat(
-  const wxString&                   rId
-)
+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(rId);
-}
+    QueryGetData(rFormat);
+    if (rFormat.GetType() == wxDF_INVALID)
+        return false;
 
 
-wxDataFormat::wxDataFormat(
-  NativeFormat                      vFormat
-)
-{
-    PrepareFormats();
-    SetId(vFormat);
-}
+    ULONG                           ulSize = m_pDataObject->GetDataSize(rFormat);
 
 
-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
+    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::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( rFormats
-                      ,vDir
-                     );
-
-        size_t                      n;
-
-        for (n = 0; n < nFormatCount; n++)
-        {
-            if (rFormats[n] == rFormat)
-                break;
-        }
-
-        delete [] rFormats;
-
-        // found?
-        return n < nFormatCount;
-    }
-}
+    delete m_pDataObject;
+} // end of wxDataObject::~wxDataObject
 
 // ----------------------------------------------------------------------------
 // wxFileDataObject
 // ----------------------------------------------------------------------------
 
 
 // ----------------------------------------------------------------------------
 // wxFileDataObject
 // ----------------------------------------------------------------------------
 
-bool wxFileDataObject::GetDataHere(
-  void*                             pBuf
-) const
+bool wxFileDataObject::GetDataHere( void* pBuf ) const
 {
     wxString                        sFilenames;
 
     for (size_t i = 0; i < m_filenames.GetCount(); i++)
     {
 {
     wxString                        sFilenames;
 
     for (size_t i = 0; i < m_filenames.GetCount(); i++)
     {
-        filenames += m_filenames[i];
-        filenames += (wxChar)0;
+        sFilenames += m_filenames[i];
+        sFilenames += (wxChar)0;
     }
 
     }
 
-    memcpy(pBuf, filenames.mbc_str(), filenames.Len() + 1);
-    return TRUE;
+    memcpy(pBuf, sFilenames.mbc_str(), sFilenames.length() + 1);
+    return true;
 }
 
 size_t wxFileDataObject::GetDataSize() const
 }
 
 size_t wxFileDataObject::GetDataSize() const
@@ -229,25 +240,23 @@ size_t wxFileDataObject::GetDataSize() const
 
     for (size_t i = 0; i < m_filenames.GetCount(); i++)
     {
 
     for (size_t i = 0; i < m_filenames.GetCount(); i++)
     {
-        nRes += m_filenames[i].Len();
+        nRes += m_filenames[i].length();
         nRes += 1;
     }
 
     return nRes + 1;
 }
 
         nRes += 1;
     }
 
     return nRes + 1;
 }
 
-bool wxFileDataObject::SetData(
-  size_t                            WXUNUSED(nSize)
-, const void*                       pBuf
-)
+bool wxFileDataObject::SetData( size_t WXUNUSED(nSize),
+                                const void* pBuf )
 {
     /* TODO */
 
 {
     /* TODO */
 
-    wxString                        sFile( (const char *)pBuf);  /* char, not wxChar */
+    wxString sFile((const wxChar *)pBuf);  /* char, not wxChar */
 
     AddFile(sFile);
 
 
     AddFile(sFile);
 
-    return TRUE;
+    return true;
 }
 
 void wxFileDataObject::AddFile(
 }
 
 void wxFileDataObject::AddFile(
@@ -281,32 +290,25 @@ wxBitmapDataObject::~wxBitmapDataObject()
     Clear();
 }
 
     Clear();
 }
 
-void wxBitmapDataObject::SetBitmap(
-  const wxBitmap&                   rBitmap
-)
+void wxBitmapDataObject::SetBitmap( const wxBitmap& rBitmap )
 {
     ClearAll();
     wxBitmapDataObjectBase::SetBitmap(rBitmap);
     DoConvertToPng();
 }
 
 {
     ClearAll();
     wxBitmapDataObjectBase::SetBitmap(rBitmap);
     DoConvertToPng();
 }
 
-bool wxBitmapDataObject::GetDataHere(
-  void*                             pBuf
-) const
+bool wxBitmapDataObject::GetDataHere( void* pBuf ) const
 {
     if (!m_pngSize)
     {
         wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
 {
     if (!m_pngSize)
     {
         wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
-        return FALSE;
+        return false;
     }
     memcpy(pBuf, m_pngData, m_pngSize);
     }
     memcpy(pBuf, m_pngData, m_pngSize);
-    return TRUE;
+    return true;
 }
 
 }
 
-bool wxBitmapDataObject::SetData(
-  size_t                            nSize
-, const void*                       pBuf
-)
+bool wxBitmapDataObject::SetData( size_t nSize, const void* pBuf)
 {
     Clear();
     m_pngSize = nSize;
 {
     Clear();
     m_pngSize = nSize;
@@ -314,34 +316,41 @@ bool wxBitmapDataObject::SetData(
 
     memcpy(m_pngData, pBuf, m_pngSize);
 
 
     memcpy(m_pngData, pBuf, m_pngSize);
 
+#if wxUSE_STREAMS
     wxMemoryInputStream             vMstream((char*)m_pngData, m_pngSize);
     wxImage                         vImage;
     wxPNGHandler                    vHandler;
 
     if (!vHandler.LoadFile(&vImage, vMstream))
     {
     wxMemoryInputStream             vMstream((char*)m_pngData, m_pngSize);
     wxImage                         vImage;
     wxPNGHandler                    vHandler;
 
     if (!vHandler.LoadFile(&vImage, vMstream))
     {
-        return FALSE;
+        return false;
     }
 
     }
 
-    m_bitmap = vImage.ConvertToBitmap();
-    return m_bitmap.Ok();
+    m_bitmap = wxBitmap(vImage);
+#endif //wxUSE_STREAMS
+
+    return m_bitmap.IsOk();
 }
 
 void wxBitmapDataObject::DoConvertToPng()
 {
 }
 
 void wxBitmapDataObject::DoConvertToPng()
 {
-    if (!m_bitmap.Ok())
+    if (!m_bitmap.IsOk())
         return;
 
         return;
 
-    wxImage                         vImage(m_bitmap);
+#if wxUSE_STREAMS
+    wxImage                         vImage = m_bitmap.ConvertToImage();
     wxPNGHandler                    vHandler;
     wxCountingOutputStream          vCount;
 
     wxPNGHandler                    vHandler;
     wxCountingOutputStream          vCount;
 
-    vHandler.SaveFile(&rImage, vCount);
+    vHandler.SaveFile(&vImage, vCount);
 
     m_pngSize = vCount.GetSize() + 100; // sometimes the size seems to vary ???
     m_pngData = malloc(m_pngSize);
 
 
     m_pngSize = vCount.GetSize() + 100; // sometimes the size seems to vary ???
     m_pngData = malloc(m_pngSize);
 
-    wxMemoryOutputStream mstream((char*) m_pngData, m_pngSize);
+    wxMemoryOutputStream            vMstream((char*) m_pngData, m_pngSize);
+
     vHandler.SaveFile(&vImage, vMstream );
     vHandler.SaveFile(&vImage, vMstream );
+#endif
 }
 
 }
 
+#endif // wxUSE_DATAOBJ