]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/dataobj.cpp
   1 /////////////////////////////////////////////////////////////////////////////// 
   2 // Name:        mac/dataobj.cpp 
   3 // Purpose:     implementation of wxDataObject class 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) 1999 Stefan Csomor 
   9 // Licence:     wxWindows licence 
  10 /////////////////////////////////////////////////////////////////////////////// 
  12 // ============================================================================ 
  14 // ============================================================================ 
  16 // ---------------------------------------------------------------------------- 
  18 // ---------------------------------------------------------------------------- 
  21   #pragma implementation "dataobj.h" 
  24 // For compilers that support precompilation, includes "wx.h". 
  25 #include "wx/wxprec.h" 
  33 #include "wx/dataobj.h" 
  34 #include "wx/mstream.h" 
  36 #include "wx/mac/private.h" 
  39 // ---------------------------------------------------------------------------- 
  41 // ---------------------------------------------------------------------------- 
  43 // ---------------------------------------------------------------------------- 
  45 // ---------------------------------------------------------------------------- 
  47 wxDataFormat::wxDataFormat() 
  49     m_type 
= wxDF_INVALID
; 
  53 wxDataFormat::wxDataFormat(  wxDataFormatId   vType 
) 
  58 wxDataFormat::wxDataFormat(  const wxChar
*  zId
) 
  63 wxDataFormat::wxDataFormat(  const wxString
&   rId
) 
  68 wxDataFormat::wxDataFormat( NativeFormat vFormat
) 
  73 void wxDataFormat::SetType(  wxDataFormatId  Type 
) 
  77     if (m_type 
== wxDF_TEXT 
) 
  78         m_format 
= kScrapFlavorTypeText
; 
  79     else if (m_type 
== wxDF_UNICODETEXT 
) 
  80         m_format 
= kScrapFlavorTypeUnicode 
; 
  81     else if (m_type 
== wxDF_BITMAP 
|| m_type 
== wxDF_METAFILE 
) 
  82         m_format 
= kScrapFlavorTypePicture
; 
  83     else if (m_type 
== wxDF_FILENAME
) 
  84         m_format 
= kDragFlavorTypeHFS 
; 
  87        wxFAIL_MSG( wxT("invalid dataformat") ); 
  89        // this is '????' but it can't be used in the code because ??' is 
  90        // parsed as a trigraph! 
  91        m_format 
= 0x3f3f3f3f; 
  95 wxString 
wxDataFormat::GetId() const 
  97     // note that m_format is not a pointer to string, it *is* itself a 4 
 100     strncpy( text 
, (char*) &m_format 
, 4 ) ; 
 103     return wxString::FromAscii( text 
) ; 
 106 void wxDataFormat::SetId(  NativeFormat  format 
) 
 110     if (m_format 
== kScrapFlavorTypeText
) 
 112     else if (m_format 
== kScrapFlavorTypeUnicode 
) 
 113         m_type 
= wxDF_UNICODETEXT
; 
 114     else if (m_format 
== kScrapFlavorTypePicture
) 
 115         m_type 
= wxDF_BITMAP
; 
 116     else if (m_format 
== kDragFlavorTypeHFS 
) 
 117         m_type 
= wxDF_FILENAME
; 
 119         m_type 
= wxDF_PRIVATE
; 
 122 void wxDataFormat::SetId( const wxChar
* zId 
) 
 124     m_type 
= wxDF_PRIVATE
; 
 125     m_format 
= 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE ); 
 128 //------------------------------------------------------------------------- 
 130 //------------------------------------------------------------------------- 
 132 wxDataObject::wxDataObject() 
 136 bool wxDataObject::IsSupportedFormat( 
 137   const wxDataFormat
&               rFormat
 
 141     size_t                          nFormatCount 
= GetFormatCount(vDir
); 
 143     if (nFormatCount 
== 1) 
 145         return rFormat 
== GetPreferredFormat(); 
 149         wxDataFormat
* pFormats 
= new wxDataFormat
[nFormatCount
]; 
 150         GetAllFormats( pFormats
 
 156         for (n 
= 0; n 
< nFormatCount
; n
++) 
 158             if (pFormats
[n
] == rFormat
) 
 165         return n 
< nFormatCount
; 
 169 // ---------------------------------------------------------------------------- 
 171 // ---------------------------------------------------------------------------- 
 173 bool wxFileDataObject::GetDataHere( 
 179     for (size_t i 
= 0; i 
< m_filenames
.GetCount(); i
++) 
 181         sFilenames 
+= m_filenames
[i
]; 
 182         sFilenames 
+= (wxChar
)0; 
 185     memcpy(pBuf
, sFilenames
.mbc_str(), sFilenames
.Len() + 1); 
 189 size_t wxFileDataObject::GetDataSize() const 
 193     for (size_t i 
= 0; i 
< m_filenames
.GetCount(); i
++) 
 195         nRes 
+= m_filenames
[i
].Len(); 
 202 bool wxFileDataObject::SetData( 
 203   size_t                            WXUNUSED(nSize
) 
 209     AddFile(wxString::FromAscii((char*)pBuf
)); 
 214 void wxFileDataObject::AddFile( 
 215   const wxString
&                   rFilename
 
 218     m_filenames
.Add(rFilename
); 
 221 // ---------------------------------------------------------------------------- 
 222 // wxBitmapDataObject 
 223 // ---------------------------------------------------------------------------- 
 225 wxBitmapDataObject::wxBitmapDataObject() 
 230 wxBitmapDataObject::wxBitmapDataObject( 
 231   const wxBitmap
& rBitmap
 
 233 : wxBitmapDataObjectBase(rBitmap
) 
 238         m_pictHandle 
= m_bitmap
.GetPict( &m_pictCreated 
) ; 
 242 wxBitmapDataObject::~wxBitmapDataObject() 
 247 void wxBitmapDataObject::SetBitmap( 
 248   const wxBitmap
&                   rBitmap
 
 252     wxBitmapDataObjectBase::SetBitmap(rBitmap
); 
 255         m_pictHandle 
= m_bitmap
.GetPict( &m_pictCreated 
) ; 
 259 void wxBitmapDataObject::Init()  
 261     m_pictHandle 
= NULL 
; 
 262     m_pictCreated 
= false ; 
 265 void wxBitmapDataObject::Clear()  
 267     if ( m_pictCreated 
&& m_pictHandle 
) 
 269         KillPicture( (PicHandle
) m_pictHandle 
) ; 
 271     m_pictHandle 
= NULL 
; 
 274 bool wxBitmapDataObject::GetDataHere( 
 280         wxFAIL_MSG(wxT("attempt to copy empty bitmap failed")); 
 283     memcpy(pBuf
, *(Handle
)m_pictHandle
, GetHandleSize((Handle
)m_pictHandle
)); 
 287 size_t wxBitmapDataObject::GetDataSize() const 
 289     return GetHandleSize((Handle
)m_pictHandle
) ; 
 292 bool wxBitmapDataObject::SetData( 
 298     PicHandle picHandle 
= (PicHandle
) NewHandle( nSize 
) ; 
 299     memcpy( *picHandle 
, pBuf 
, nSize 
) ; 
 300     m_pictHandle 
= picHandle 
; 
 301     m_pictCreated 
= false ; 
 302     Rect frame 
= (**picHandle
).picFrame 
; 
 304     m_bitmap
.SetPict( picHandle 
) ; 
 305     m_bitmap
.SetWidth( frame
.right 
- frame
.left 
) ; 
 306     m_bitmap
.SetHeight( frame
.bottom 
- frame
.top 
) ; 
 307     return m_bitmap
.Ok();