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