]>
git.saurik.com Git - wxWidgets.git/blob - src/motif/dataobj.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/dataobj.cpp
3 // Purpose: wxDataObject class
4 // Author: Julian Smart
6 // Copyright: (c) 1998 Julian Smart
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
15 #include "wx/dataobj.h"
24 #pragma message disable nosimpint
28 #pragma message enable nosimpint
31 #include "wx/motif/private.h"
33 //-------------------------------------------------------------------------
35 //-------------------------------------------------------------------------
38 Atom g_bitmapAtom
= 0;
41 //-------------------------------------------------------------------------
43 //-------------------------------------------------------------------------
45 wxDataFormat::wxDataFormat()
47 // do *not* call PrepareFormats() from here for 2 reasons:
49 // 1. we will have time to do it later because some other Set function
50 // must be called before we really need them
52 // 2. doing so prevents us from declaring global wxDataFormats because
53 // calling PrepareFormats (and thus gdk_atom_intern) before GDK is
54 // initialised will result in a crash
55 m_type
= wxDF_INVALID
;
59 wxDataFormat::wxDataFormat( wxDataFormatId type
)
65 wxDataFormat::wxDataFormat( const wxChar
*id
)
71 wxDataFormat::wxDataFormat( const wxString
&id
)
77 wxDataFormat::wxDataFormat( NativeFormat format
)
83 void wxDataFormat::SetType( wxDataFormatId type
)
88 if (m_type
== wxDF_TEXT
)
89 m_format
= g_textAtom
;
91 if (m_type
== wxDF_BITMAP
)
92 m_format
= g_bitmapAtom
;
94 if (m_type
== wxDF_FILENAME
)
95 m_format
= g_fileAtom
;
98 wxFAIL_MSG( wxT("invalid dataformat") );
102 wxDataFormatId
wxDataFormat::GetType() const
107 wxString
wxDataFormat::GetId() const
109 char *t
= XGetAtomName ((Display
*) wxGetDisplay(), m_format
);
110 wxString
ret( t
); // this will convert from ascii to Unicode
116 void wxDataFormat::SetId( NativeFormat format
)
121 if (m_format
== g_textAtom
)
124 if (m_format
== g_bitmapAtom
)
125 m_type
= wxDF_BITMAP
;
127 if (m_format
== g_fileAtom
)
128 m_type
= wxDF_FILENAME
;
130 m_type
= wxDF_PRIVATE
;
133 void wxDataFormat::SetId( const wxChar
*id
)
136 m_type
= wxDF_PRIVATE
;
138 m_format
= XInternAtom( wxGlobalDisplay(),
139 tmp
.mbc_str(), False
);
142 void wxDataFormat::PrepareFormats()
145 g_textAtom
= XInternAtom( wxGlobalDisplay(), "STRING", False
);
147 g_bitmapAtom
= XInternAtom( wxGlobalDisplay(), "PIXMAP", False
);
149 g_fileAtom
= XInternAtom( wxGlobalDisplay(), "file:ALL", False
);
152 // ----------------------------------------------------------------------------
154 // ----------------------------------------------------------------------------
156 wxDataObject::~wxDataObject()
160 // ----------------------------------------------------------------------------
161 // wxBitmapDataObject
162 // ----------------------------------------------------------------------------
164 size_t wxBitmapDataObject::GetDataSize() const
166 return sizeof(Pixmap
);
169 bool wxBitmapDataObject::GetDataHere(void* buf
) const
171 if( !GetBitmap().Ok() )
174 (*(Pixmap
*)buf
) = (Pixmap
)GetBitmap().GetDrawable();
179 bool wxBitmapDataObject::SetData(size_t len
, const void* buf
)
181 if( len
!= sizeof(Pixmap
) )
184 WXPixmap pixmap
= (WXPixmap
)*(Pixmap
*)buf
;
186 m_bitmap
.Create( pixmap
);
191 #endif // wxUSE_CLIPBOARD