]>
Commit | Line | Data |
---|---|---|
dc63c944 JS |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: dataobj.cpp | |
3 | // Purpose: wxDataObject class | |
4 | // Author: Julian Smart | |
5 | // Id: $Id$ | |
6 | // Copyright: (c) 1998 Julian Smart | |
dfe1eee3 | 7 | // Licence: wxWindows licence |
dc63c944 JS |
8 | /////////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "dataobj.h" | |
12 | #endif | |
13 | ||
dfe1eee3 VZ |
14 | #include "wx/defs.h" |
15 | ||
16 | #if wxUSE_CLIPBOARD | |
17 | ||
dc63c944 JS |
18 | #include "wx/dataobj.h" |
19 | #include "wx/app.h" | |
20 | ||
da175b2c RR |
21 | #include <Xm/Xm.h> |
22 | #include "wx/utils.h" | |
23 | ||
24 | //------------------------------------------------------------------------- | |
25 | // global data | |
26 | //------------------------------------------------------------------------- | |
27 | ||
12db77ca | 28 | Atom g_textAtom = 0; |
da175b2c RR |
29 | |
30 | //------------------------------------------------------------------------- | |
31 | // wxDataFormat | |
32 | //------------------------------------------------------------------------- | |
33 | ||
da175b2c RR |
34 | wxDataFormat::wxDataFormat() |
35 | { | |
36 | if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE ); | |
37 | m_type = wxDF_INVALID; | |
38 | m_hasAtom = FALSE; | |
39 | m_atom = (Atom) 0; | |
40 | } | |
41 | ||
42 | wxDataFormat::wxDataFormat( wxDataFormatId type ) | |
43 | { | |
44 | if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE ); | |
45 | SetType( type ); | |
46 | } | |
47 | ||
48 | wxDataFormat::wxDataFormat( const wxChar *id ) | |
49 | { | |
50 | if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE ); | |
51 | SetId( id ); | |
52 | } | |
53 | ||
54 | wxDataFormat::wxDataFormat( const wxString &id ) | |
55 | { | |
56 | if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE ); | |
57 | SetId( id ); | |
58 | } | |
59 | ||
60 | wxDataFormat::wxDataFormat( const wxDataFormat &format ) | |
61 | { | |
62 | if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE ); | |
63 | m_type = format.GetType(); | |
64 | m_id = format.GetId(); | |
65 | m_hasAtom = TRUE; | |
66 | m_atom = ((wxDataFormat &)format).GetAtom(); // const_cast | |
67 | } | |
68 | ||
69 | wxDataFormat::wxDataFormat( const Atom atom ) | |
70 | { | |
71 | if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE ); | |
72 | m_hasAtom = TRUE; | |
73 | ||
74 | m_atom = atom; | |
75 | ||
76 | if (m_atom == g_textAtom) | |
77 | { | |
78 | m_type = wxDF_TEXT; | |
79 | } else | |
80 | /* | |
81 | if (m_atom == GDK_TARGET_BITMAP) | |
82 | { | |
83 | m_type = wxDF_BITMAP; | |
84 | } else | |
85 | */ | |
86 | { | |
87 | m_type = wxDF_PRIVATE; | |
88 | m_id = XGetAtomName( (Display*) wxGetDisplay(), m_atom ); | |
89 | ||
223d09f6 | 90 | if (m_id == wxT("file:ALL")) |
da175b2c RR |
91 | { |
92 | m_type = wxDF_FILENAME; | |
93 | } | |
94 | } | |
95 | } | |
96 | ||
97 | void wxDataFormat::SetType( wxDataFormatId type ) | |
98 | { | |
99 | m_type = type; | |
100 | ||
101 | if (m_type == wxDF_TEXT) | |
102 | { | |
223d09f6 | 103 | m_id = wxT("STRING"); |
da175b2c RR |
104 | } |
105 | else | |
106 | if (m_type == wxDF_BITMAP) | |
107 | { | |
223d09f6 | 108 | m_id = wxT("BITMAP"); |
da175b2c RR |
109 | } |
110 | else | |
111 | if (m_type == wxDF_FILENAME) | |
112 | { | |
223d09f6 | 113 | m_id = wxT("file:ALL"); |
da175b2c RR |
114 | } |
115 | else | |
116 | { | |
223d09f6 | 117 | wxFAIL_MSG( wxT("invalid dataformat") ); |
da175b2c RR |
118 | } |
119 | ||
120 | m_hasAtom = FALSE; | |
121 | } | |
122 | ||
da175b2c RR |
123 | void wxDataFormat::SetId( const wxChar *id ) |
124 | { | |
125 | m_type = wxDF_PRIVATE; | |
126 | m_id = id; | |
127 | m_hasAtom = FALSE; | |
128 | } | |
129 | ||
130 | Atom wxDataFormat::GetAtom() | |
131 | { | |
132 | if (!m_hasAtom) | |
133 | { | |
134 | m_hasAtom = TRUE; | |
135 | ||
136 | if (m_type == wxDF_TEXT) | |
137 | { | |
138 | m_atom = g_textAtom; | |
139 | } | |
140 | else | |
141 | /* | |
142 | if (m_type == wxDF_BITMAP) | |
143 | { | |
144 | m_atom = GDK_TARGET_BITMAP; | |
145 | } | |
146 | else | |
147 | */ | |
148 | if (m_type == wxDF_PRIVATE) | |
149 | { | |
e90c1d2a | 150 | m_atom = XInternAtom( (Display*) wxGetDisplay(), wxMBSTRINGCAST m_id.mbc_str(), FALSE ); |
da175b2c RR |
151 | } |
152 | else | |
153 | if (m_type == wxDF_FILENAME) | |
154 | { | |
155 | m_atom = XInternAtom( (Display*) wxGetDisplay(), "file:ALL", FALSE ); | |
156 | } | |
157 | else | |
158 | { | |
159 | m_hasAtom = FALSE; | |
160 | m_atom = (Atom) 0; | |
161 | } | |
162 | } | |
163 | ||
164 | return m_atom; | |
165 | } | |
166 | ||
12db77ca | 167 | #if 0 |
dc63c944 JS |
168 | |
169 | // ---------------------------------------------------------------------------- | |
170 | // wxPrivateDataObject | |
171 | // ---------------------------------------------------------------------------- | |
172 | ||
173 | IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject, wxDataObject ) | |
174 | ||
da175b2c RR |
175 | void wxPrivateDataObject::Free() |
176 | { | |
177 | if ( m_data ) | |
178 | free(m_data); | |
dc63c944 | 179 | } |
da175b2c RR |
180 | |
181 | wxPrivateDataObject::wxPrivateDataObject() | |
182 | { | |
223d09f6 | 183 | wxString id = wxT("application/"); |
da175b2c RR |
184 | id += wxTheApp->GetAppName(); |
185 | ||
186 | m_format.SetId( id ); | |
187 | ||
188 | m_size = 0; | |
189 | m_data = (void *)NULL; | |
dc63c944 | 190 | } |
da175b2c RR |
191 | |
192 | void wxPrivateDataObject::SetData( const void *data, size_t size ) | |
dc63c944 | 193 | { |
da175b2c RR |
194 | Free(); |
195 | ||
dc63c944 | 196 | m_size = size; |
da175b2c | 197 | m_data = malloc(size); |
dc63c944 | 198 | |
da175b2c RR |
199 | memcpy( m_data, data, size ); |
200 | } | |
201 | ||
202 | void wxPrivateDataObject::WriteData( void *dest ) const | |
203 | { | |
204 | WriteData( m_data, dest ); | |
205 | } | |
206 | ||
207 | size_t wxPrivateDataObject::GetSize() const | |
208 | { | |
209 | return m_size; | |
210 | } | |
211 | ||
212 | void wxPrivateDataObject::WriteData( const void *data, void *dest ) const | |
213 | { | |
214 | memcpy( dest, data, GetSize() ); | |
dc63c944 JS |
215 | } |
216 | ||
12db77ca VZ |
217 | #endif // 0 |
218 | ||
dfe1eee3 | 219 | #endif // wxUSE_CLIPBOARD |