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