]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/dataobj.cpp
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDataObject class
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "dataobj.h"
14 #include "wx/dataobj.h"
21 //-------------------------------------------------------------------------
23 //-------------------------------------------------------------------------
25 GdkAtom g_textAtom
= 0;
27 //-------------------------------------------------------------------------
29 //-------------------------------------------------------------------------
31 IMPLEMENT_CLASS(wxDataFormat
, wxObject
)
33 wxDataFormat::wxDataFormat()
35 if (!g_textAtom
) g_textAtom
= gdk_atom_intern( "STRING", FALSE
);
36 m_type
= wxDF_INVALID
;
41 wxDataFormat::wxDataFormat( wxDataType type
)
43 if (!g_textAtom
) g_textAtom
= gdk_atom_intern( "STRING", FALSE
);
47 wxDataFormat::wxDataFormat( const wxString
&id
)
49 if (!g_textAtom
) g_textAtom
= gdk_atom_intern( "STRING", FALSE
);
53 wxDataFormat::wxDataFormat( wxDataFormat
&format
)
55 if (!g_textAtom
) g_textAtom
= gdk_atom_intern( "STRING", FALSE
);
56 m_type
= format
.GetType();
57 m_id
= format
.GetId();
59 m_atom
= format
.GetAtom();
62 wxDataFormat::wxDataFormat( const GdkAtom atom
)
64 if (!g_textAtom
) g_textAtom
= gdk_atom_intern( "STRING", FALSE
);
69 if (m_atom
== g_textAtom
)
73 if (m_atom
== GDK_TARGET_BITMAP
)
78 m_type
= wxDF_PRIVATE
;
79 m_id
= gdk_atom_name( m_atom
);
81 if (m_id
== _T("file:ALL"))
83 m_type
= wxDF_FILENAME
;
88 void wxDataFormat::SetType( wxDataType type
)
92 if (m_type
== wxDF_TEXT
)
97 if (m_type
== wxDF_BITMAP
)
102 if (m_type
== wxDF_FILENAME
)
104 m_id
= _T("file:ALL");
108 wxFAIL_MSG( _T("invalid dataformat") );
114 wxDataType
wxDataFormat::GetType() const
119 wxString
wxDataFormat::GetId() const
124 void wxDataFormat::SetId( const wxString
&id
)
126 m_type
= wxDF_PRIVATE
;
131 GdkAtom
wxDataFormat::GetAtom()
137 if (m_type
== wxDF_TEXT
)
142 if (m_type
== wxDF_BITMAP
)
144 m_atom
= GDK_TARGET_BITMAP
;
147 if (m_type
== wxDF_PRIVATE
)
149 m_atom
= gdk_atom_intern( MBSTRINGCAST m_id
.mbc_str(), FALSE
);
152 if (m_type
== wxDF_FILENAME
)
154 m_atom
= gdk_atom_intern( "file:ALL", FALSE
);
159 m_atom
= (GdkAtom
) 0;
166 //-------------------------------------------------------------------------
168 //-------------------------------------------------------------------------
170 IMPLEMENT_CLASS(wxDataBroker
,wxObject
)
172 wxDataBroker::wxDataBroker()
174 m_dataObjects
.DeleteContents(TRUE
);
178 void wxDataBroker::Add( wxDataObject
*dataObject
, bool preferred
)
180 if (preferred
) m_preferred
= m_dataObjects
.GetCount();
181 m_dataObjects
.Append( dataObject
);
184 size_t wxDataBroker::GetFormatCount() const
186 return m_dataObjects
.GetCount();
189 wxDataFormat
&wxDataBroker::GetPreferredFormat() const
191 wxNode
*node
= m_dataObjects
.Nth( m_preferred
);
195 wxDataObject
* data_obj
= (wxDataObject
*)node
->Data();
197 return data_obj
->GetFormat();
200 wxDataFormat
&wxDataBroker::GetNthFormat( size_t nth
) const
202 wxNode
*node
= m_dataObjects
.Nth( nth
);
206 wxDataObject
* data_obj
= (wxDataObject
*)node
->Data();
208 return data_obj
->GetFormat();
211 bool wxDataBroker::IsSupportedFormat( wxDataFormat
&format
) const
213 wxNode
*node
= m_dataObjects
.First();
216 wxDataObject
*dobj
= (wxDataObject
*)node
->Data();
218 if (dobj
->GetFormat().GetAtom() == format
.GetAtom())
229 size_t wxDataBroker::GetSize( wxDataFormat
& format
) const
231 wxNode
*node
= m_dataObjects
.First();
234 wxDataObject
*dobj
= (wxDataObject
*)node
->Data();
236 if (dobj
->GetFormat().GetAtom() == format
.GetAtom())
238 return dobj
->GetSize();
247 void wxDataBroker::WriteData( wxDataFormat
& format
, void *dest
) const
249 wxNode
*node
= m_dataObjects
.First();
252 wxDataObject
*dobj
= (wxDataObject
*)node
->Data();
254 if (dobj
->GetFormat().GetAtom() == format
.GetAtom())
256 dobj
->WriteData( dest
);
263 //-------------------------------------------------------------------------
265 //-------------------------------------------------------------------------
267 IMPLEMENT_ABSTRACT_CLASS( wxDataObject
, wxObject
)
269 wxDataObject::wxDataObject()
273 wxDataObject::~wxDataObject()
277 wxDataFormat
&wxDataObject::GetFormat()
282 wxDataType
wxDataObject::GetFormatType() const
284 return m_format
.GetType();
287 wxString
wxDataObject::GetFormatId() const
289 return m_format
.GetId();
292 GdkAtom
wxDataObject::GetFormatAtom() const
294 GdkAtom ret
= ((wxDataObject
*) this)->m_format
.GetAtom();
298 // ----------------------------------------------------------------------------
300 // ----------------------------------------------------------------------------
302 IMPLEMENT_DYNAMIC_CLASS( wxTextDataObject
, wxDataObject
)
304 wxTextDataObject::wxTextDataObject()
306 m_format
.SetType( wxDF_TEXT
);
309 wxTextDataObject::wxTextDataObject( const wxString
& data
)
311 m_format
.SetType( wxDF_TEXT
);
316 void wxTextDataObject::SetText( const wxString
& data
)
321 wxString
wxTextDataObject::GetText() const
326 void wxTextDataObject::WriteData( void *dest
) const
328 WriteString( m_data
, dest
);
331 size_t wxTextDataObject::GetSize() const
333 return m_data
.Len() + 1;
336 void wxTextDataObject::WriteString( const wxString
&str
, void *dest
) const
338 memcpy( dest
, m_data
.c_str(), GetSize() );
341 // ----------------------------------------------------------------------------
343 // ----------------------------------------------------------------------------
345 IMPLEMENT_DYNAMIC_CLASS( wxFileDataObject
, wxDataObject
)
347 wxFileDataObject::wxFileDataObject()
349 m_format
.SetType( wxDF_FILENAME
);
352 void wxFileDataObject::AddFile( const wxString
&file
)
355 m_files
+= (wxChar
)0;
358 wxString
wxFileDataObject::GetFiles() const
363 void wxFileDataObject::WriteData( void *dest
) const
365 memcpy( dest
, m_files
.c_str(), GetSize() );
368 size_t wxFileDataObject::GetSize() const
370 return m_files
.Len() + 1;
373 // ----------------------------------------------------------------------------
374 // wxBitmapDataObject
375 // ----------------------------------------------------------------------------
377 IMPLEMENT_DYNAMIC_CLASS( wxBitmapDataObject
, wxDataObject
)
379 wxBitmapDataObject::wxBitmapDataObject()
381 m_format
.SetType( wxDF_BITMAP
);
384 wxBitmapDataObject::wxBitmapDataObject( const wxBitmap
& bitmap
)
386 m_format
.SetType( wxDF_BITMAP
);
391 void wxBitmapDataObject::SetBitmap( const wxBitmap
&bitmap
)
396 wxBitmap
wxBitmapDataObject::GetBitmap() const
401 void wxBitmapDataObject::WriteData( void *dest
) const
403 WriteBitmap( m_bitmap
, dest
);
406 size_t wxBitmapDataObject::GetSize() const
411 void wxBitmapDataObject::WriteBitmap( const wxBitmap
&bitmap
, void *dest
) const
413 memcpy( dest
, m_bitmap
.GetPixmap(), GetSize() );
416 // ----------------------------------------------------------------------------
417 // wxPrivateDataObject
418 // ----------------------------------------------------------------------------
420 IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject
, wxDataObject
)
422 wxPrivateDataObject::wxPrivateDataObject()
424 m_id
= "application/";
425 m_id
+= wxTheApp
->GetAppName();
427 m_format
.SetId( m_id
);
430 m_data
= (char*) NULL
;
433 wxPrivateDataObject::~wxPrivateDataObject()
435 if (m_data
) delete[] m_data
;
438 void wxPrivateDataObject::SetId( const wxString
& id
)
441 m_format
.SetId( m_id
);
444 wxString
wxPrivateDataObject::GetId() const
449 void wxPrivateDataObject::SetData( const char *data
, size_t size
)
453 if (m_data
) delete[] m_data
;
455 m_data
= new char[size
];
457 memcpy( m_data
, data
, size
);
460 char* wxPrivateDataObject::GetData() const
465 void wxPrivateDataObject::WriteData( void *dest
) const
467 WriteData( m_data
, dest
);
470 size_t wxPrivateDataObject::GetSize() const
475 void wxPrivateDataObject::WriteData( const char *data
, void *dest
) const
477 memcpy( dest
, data
, GetSize() );