]> git.saurik.com Git - wxWidgets.git/blame - src/motif/dataobj.cpp
Fix typo in last commit
[wxWidgets.git] / src / motif / dataobj.cpp
CommitLineData
dc63c944 1///////////////////////////////////////////////////////////////////////////////
7520f3da 2// Name: src/motif/dataobj.cpp
dc63c944
JS
3// Purpose: wxDataObject class
4// Author: Julian Smart
5// Id: $Id$
6// Copyright: (c) 1998 Julian Smart
65571936 7// Licence: wxWindows licence
dc63c944
JS
8///////////////////////////////////////////////////////////////////////////////
9
1248b41f
MB
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
dfe1eee3
VZ
13#if wxUSE_CLIPBOARD
14
dc63c944 15#include "wx/dataobj.h"
670f9935
WS
16
17#ifndef WX_PRECOMP
18 #include "wx/app.h"
de6185e2 19 #include "wx/utils.h"
670f9935
WS
20#endif
21
338dd992
JJ
22#ifdef __VMS__
23#pragma message disable nosimpint
24#endif
da175b2c 25#include <Xm/Xm.h>
338dd992
JJ
26#ifdef __VMS__
27#pragma message enable nosimpint
28#endif
dd38c875
MB
29
30#include "wx/motif/private.h"
da175b2c
RR
31
32//-------------------------------------------------------------------------
33// global data
34//-------------------------------------------------------------------------
35
76db86e7 36Atom g_textAtom = 0;
dd38c875 37Atom g_bitmapAtom = 0;
76db86e7 38Atom g_fileAtom = 0;
da175b2c
RR
39
40//-------------------------------------------------------------------------
41// wxDataFormat
42//-------------------------------------------------------------------------
43
da175b2c
RR
44wxDataFormat::wxDataFormat()
45{
76db86e7
RR
46 // do *not* call PrepareFormats() from here for 2 reasons:
47 //
48 // 1. we will have time to do it later because some other Set function
49 // must be called before we really need them
50 //
51 // 2. doing so prevents us from declaring global wxDataFormats because
52 // calling PrepareFormats (and thus gdk_atom_intern) before GDK is
53 // initialised will result in a crash
da175b2c 54 m_type = wxDF_INVALID;
76db86e7 55 m_format = (Atom) 0;
da175b2c
RR
56}
57
58wxDataFormat::wxDataFormat( wxDataFormatId type )
59{
76db86e7 60 PrepareFormats();
da175b2c
RR
61 SetType( type );
62}
63
da175b2c
RR
64wxDataFormat::wxDataFormat( const wxString &id )
65{
76db86e7 66 PrepareFormats();
da175b2c
RR
67 SetId( id );
68}
69
76db86e7 70wxDataFormat::wxDataFormat( NativeFormat format )
da175b2c 71{
76db86e7
RR
72 PrepareFormats();
73 SetId( format );
da175b2c
RR
74}
75
76void wxDataFormat::SetType( wxDataFormatId type )
77{
76db86e7 78 PrepareFormats();
da175b2c
RR
79 m_type = type;
80
81 if (m_type == wxDF_TEXT)
76db86e7 82 m_format = g_textAtom;
da175b2c
RR
83 else
84 if (m_type == wxDF_BITMAP)
dd38c875 85 m_format = g_bitmapAtom;
da175b2c
RR
86 else
87 if (m_type == wxDF_FILENAME)
76db86e7 88 m_format = g_fileAtom;
da175b2c
RR
89 else
90 {
223d09f6 91 wxFAIL_MSG( wxT("invalid dataformat") );
da175b2c 92 }
76db86e7
RR
93}
94
95wxDataFormatId wxDataFormat::GetType() const
96{
97 return m_type;
98}
99
100wxString wxDataFormat::GetId() const
101{
102 char *t = XGetAtomName ((Display*) wxGetDisplay(), m_format);
103 wxString ret( t ); // this will convert from ascii to Unicode
7520f3da 104 if (t)
76db86e7
RR
105 XFree( t );
106 return ret;
107}
108
109void wxDataFormat::SetId( NativeFormat format )
110{
111 PrepareFormats();
112 m_format = format;
da175b2c 113
76db86e7
RR
114 if (m_format == g_textAtom)
115 m_type = wxDF_TEXT;
116 else
dd38c875 117 if (m_format == g_bitmapAtom)
76db86e7
RR
118 m_type = wxDF_BITMAP;
119 else
120 if (m_format == g_fileAtom)
121 m_type = wxDF_FILENAME;
122 else
123 m_type = wxDF_PRIVATE;
da175b2c
RR
124}
125
a1eb65c2 126void wxDataFormat::SetId( const wxString& id )
da175b2c 127{
76db86e7 128 PrepareFormats();
da175b2c 129 m_type = wxDF_PRIVATE;
dd38c875 130 m_format = XInternAtom( wxGlobalDisplay(),
a1eb65c2 131 id.mbc_str(), False );
da175b2c
RR
132}
133
76db86e7 134void wxDataFormat::PrepareFormats()
da175b2c 135{
76db86e7 136 if (!g_textAtom)
96be256b 137 g_textAtom = XInternAtom( wxGlobalDisplay(), "STRING", False );
dd38c875 138 if (!g_bitmapAtom)
96be256b 139 g_bitmapAtom = XInternAtom( wxGlobalDisplay(), "PIXMAP", False );
76db86e7 140 if (!g_fileAtom)
96be256b 141 g_fileAtom = XInternAtom( wxGlobalDisplay(), "file:ALL", False );
da175b2c
RR
142}
143
1eaf587e
VZ
144// ----------------------------------------------------------------------------
145// wxDataObject
146// ----------------------------------------------------------------------------
147
148wxDataObject::~wxDataObject()
149{
150}
151
dc63c944 152// ----------------------------------------------------------------------------
dd38c875 153// wxBitmapDataObject
dc63c944
JS
154// ----------------------------------------------------------------------------
155
dd38c875 156size_t wxBitmapDataObject::GetDataSize() const
da175b2c 157{
dd38c875 158 return sizeof(Pixmap);
dc63c944 159}
da175b2c 160
dd38c875 161bool wxBitmapDataObject::GetDataHere(void* buf) const
da175b2c 162{
a1b806b9 163 if( !GetBitmap().IsOk() )
dd38c875 164 return false;
da175b2c 165
dd38c875 166 (*(Pixmap*)buf) = (Pixmap)GetBitmap().GetDrawable();
da175b2c 167
dd38c875 168 return true;
dc63c944 169}
da175b2c 170
dd38c875 171bool wxBitmapDataObject::SetData(size_t len, const void* buf)
dc63c944 172{
dd38c875
MB
173 if( len != sizeof(Pixmap) )
174 return false;
da175b2c 175
dd38c875 176 WXPixmap pixmap = (WXPixmap)*(Pixmap*)buf;
da175b2c 177
dd38c875 178 m_bitmap.Create( pixmap );
da175b2c 179
dd38c875 180 return true;
dc63c944
JS
181}
182
dfe1eee3 183#endif // wxUSE_CLIPBOARD