]>
git.saurik.com Git - wxWidgets.git/blob - src/x11/dataobj.cpp
f9120e6be4c3a590466070f603a3e4fad8320532
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDataObject class
4 // Author: Julian Smart
6 // Copyright: (c) 1998 Julian Smart
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "dataobj.h"
18 #include "wx/dataobj.h"
22 #pragma message disable nosimpint
25 #pragma message enable nosimpint
29 //-------------------------------------------------------------------------
31 //-------------------------------------------------------------------------
37 //-------------------------------------------------------------------------
39 //-------------------------------------------------------------------------
41 wxDataFormat::wxDataFormat()
43 // do *not* call PrepareFormats() from here for 2 reasons:
45 // 1. we will have time to do it later because some other Set function
46 // must be called before we really need them
48 // 2. doing so prevents us from declaring global wxDataFormats because
49 // calling PrepareFormats (and thus gdk_atom_intern) before GDK is
50 // initialised will result in a crash
51 m_type
= wxDF_INVALID
;
55 wxDataFormat::wxDataFormat( wxDataFormatId type
)
61 wxDataFormat::wxDataFormat( const wxChar
*id
)
67 wxDataFormat::wxDataFormat( const wxString
&id
)
73 wxDataFormat::wxDataFormat( NativeFormat format
)
79 void wxDataFormat::SetType( wxDataFormatId type
)
84 if (m_type
== wxDF_TEXT
)
85 m_format
= g_textAtom
;
87 if (m_type
== wxDF_BITMAP
)
90 if (m_type
== wxDF_FILENAME
)
91 m_format
= g_fileAtom
;
94 wxFAIL_MSG( wxT("invalid dataformat") );
98 wxDataFormatId
wxDataFormat::GetType() const
103 wxString
wxDataFormat::GetId() const
105 char *t
= XGetAtomName ((Display
*) wxGetDisplay(), m_format
);
106 wxString
ret( t
); // this will convert from ascii to Unicode
112 void wxDataFormat::SetId( NativeFormat format
)
117 if (m_format
== g_textAtom
)
120 if (m_format
== g_pngAtom
)
121 m_type
= wxDF_BITMAP
;
123 if (m_format
== g_fileAtom
)
124 m_type
= wxDF_FILENAME
;
126 m_type
= wxDF_PRIVATE
;
129 void wxDataFormat::SetId( const wxChar
*id
)
132 m_type
= wxDF_PRIVATE
;
134 m_format
= XInternAtom( (Display
*) wxGetDisplay(), wxMBSTRINGCAST tmp
.mbc_str(), FALSE
); // what is the string cast for?
137 void wxDataFormat::PrepareFormats()
140 g_textAtom
= XInternAtom( (Display
*) wxGetDisplay(), "STRING", FALSE
);
142 g_pngAtom
= XInternAtom( (Display
*) wxGetDisplay(), "image/png", FALSE
);
144 g_fileAtom
= XInternAtom( (Display
*) wxGetDisplay(), "file:ALL", FALSE
);
149 // ----------------------------------------------------------------------------
150 // wxPrivateDataObject
151 // ----------------------------------------------------------------------------
153 IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject
, wxDataObject
)
155 void wxPrivateDataObject::Free()
161 wxPrivateDataObject::wxPrivateDataObject()
163 wxString id
= wxT("application/");
164 id
+= wxTheApp
->GetAppName();
166 m_format
.SetId( id
);
169 m_data
= (void *)NULL
;
172 void wxPrivateDataObject::SetData( const void *data
, size_t size
)
177 m_data
= malloc(size
);
179 memcpy( m_data
, data
, size
);
182 void wxPrivateDataObject::WriteData( void *dest
) const
184 WriteData( m_data
, dest
);
187 size_t wxPrivateDataObject::GetSize() const
192 void wxPrivateDataObject::WriteData( const void *data
, void *dest
) const
194 memcpy( dest
, data
, GetSize() );
199 #endif // wxUSE_CLIPBOARD