]>
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 | |
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 | #include "wx/defs.h" |
14 | ||
15 | #if wxUSE_CLIPBOARD | |
16 | ||
dc63c944 JS |
17 | #include "wx/dataobj.h" |
18 | #include "wx/app.h" | |
dd38c875 | 19 | #include "wx/utils.h" |
dc63c944 | 20 | |
338dd992 JJ |
21 | #ifdef __VMS__ |
22 | #pragma message disable nosimpint | |
23 | #endif | |
da175b2c | 24 | #include <Xm/Xm.h> |
338dd992 JJ |
25 | #ifdef __VMS__ |
26 | #pragma message enable nosimpint | |
27 | #endif | |
dd38c875 MB |
28 | |
29 | #include "wx/motif/private.h" | |
da175b2c RR |
30 | |
31 | //------------------------------------------------------------------------- | |
32 | // global data | |
33 | //------------------------------------------------------------------------- | |
34 | ||
76db86e7 | 35 | Atom g_textAtom = 0; |
dd38c875 | 36 | Atom g_bitmapAtom = 0; |
76db86e7 | 37 | Atom g_fileAtom = 0; |
da175b2c RR |
38 | |
39 | //------------------------------------------------------------------------- | |
40 | // wxDataFormat | |
41 | //------------------------------------------------------------------------- | |
42 | ||
da175b2c RR |
43 | wxDataFormat::wxDataFormat() |
44 | { | |
76db86e7 RR |
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 | |
da175b2c | 53 | m_type = wxDF_INVALID; |
76db86e7 | 54 | m_format = (Atom) 0; |
da175b2c RR |
55 | } |
56 | ||
57 | wxDataFormat::wxDataFormat( wxDataFormatId type ) | |
58 | { | |
76db86e7 | 59 | PrepareFormats(); |
da175b2c RR |
60 | SetType( type ); |
61 | } | |
62 | ||
63 | wxDataFormat::wxDataFormat( const wxChar *id ) | |
64 | { | |
76db86e7 | 65 | PrepareFormats(); |
da175b2c RR |
66 | SetId( id ); |
67 | } | |
68 | ||
69 | wxDataFormat::wxDataFormat( const wxString &id ) | |
70 | { | |
76db86e7 | 71 | PrepareFormats(); |
da175b2c RR |
72 | SetId( id ); |
73 | } | |
74 | ||
76db86e7 | 75 | wxDataFormat::wxDataFormat( NativeFormat format ) |
da175b2c | 76 | { |
76db86e7 RR |
77 | PrepareFormats(); |
78 | SetId( format ); | |
da175b2c RR |
79 | } |
80 | ||
81 | void wxDataFormat::SetType( wxDataFormatId type ) | |
82 | { | |
76db86e7 | 83 | PrepareFormats(); |
da175b2c RR |
84 | m_type = type; |
85 | ||
86 | if (m_type == wxDF_TEXT) | |
76db86e7 | 87 | m_format = g_textAtom; |
da175b2c RR |
88 | else |
89 | if (m_type == wxDF_BITMAP) | |
dd38c875 | 90 | m_format = g_bitmapAtom; |
da175b2c RR |
91 | else |
92 | if (m_type == wxDF_FILENAME) | |
76db86e7 | 93 | m_format = g_fileAtom; |
da175b2c RR |
94 | else |
95 | { | |
223d09f6 | 96 | wxFAIL_MSG( wxT("invalid dataformat") ); |
da175b2c | 97 | } |
76db86e7 RR |
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; | |
da175b2c | 118 | |
76db86e7 RR |
119 | if (m_format == g_textAtom) |
120 | m_type = wxDF_TEXT; | |
121 | else | |
dd38c875 | 122 | if (m_format == g_bitmapAtom) |
76db86e7 RR |
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; | |
da175b2c RR |
129 | } |
130 | ||
da175b2c RR |
131 | void wxDataFormat::SetId( const wxChar *id ) |
132 | { | |
76db86e7 | 133 | PrepareFormats(); |
da175b2c | 134 | m_type = wxDF_PRIVATE; |
76db86e7 | 135 | wxString tmp( id ); |
dd38c875 | 136 | m_format = XInternAtom( wxGlobalDisplay(), |
96be256b | 137 | tmp.mbc_str(), False ); |
da175b2c RR |
138 | } |
139 | ||
76db86e7 | 140 | void wxDataFormat::PrepareFormats() |
da175b2c | 141 | { |
76db86e7 | 142 | if (!g_textAtom) |
96be256b | 143 | g_textAtom = XInternAtom( wxGlobalDisplay(), "STRING", False ); |
dd38c875 | 144 | if (!g_bitmapAtom) |
96be256b | 145 | g_bitmapAtom = XInternAtom( wxGlobalDisplay(), "PIXMAP", False ); |
76db86e7 | 146 | if (!g_fileAtom) |
96be256b | 147 | g_fileAtom = XInternAtom( wxGlobalDisplay(), "file:ALL", False ); |
da175b2c RR |
148 | } |
149 | ||
1eaf587e VZ |
150 | // ---------------------------------------------------------------------------- |
151 | // wxDataObject | |
152 | // ---------------------------------------------------------------------------- | |
153 | ||
154 | wxDataObject::~wxDataObject() | |
155 | { | |
156 | } | |
157 | ||
dc63c944 | 158 | // ---------------------------------------------------------------------------- |
dd38c875 | 159 | // wxBitmapDataObject |
dc63c944 JS |
160 | // ---------------------------------------------------------------------------- |
161 | ||
dd38c875 | 162 | size_t wxBitmapDataObject::GetDataSize() const |
da175b2c | 163 | { |
dd38c875 | 164 | return sizeof(Pixmap); |
dc63c944 | 165 | } |
da175b2c | 166 | |
dd38c875 | 167 | bool wxBitmapDataObject::GetDataHere(void* buf) const |
da175b2c | 168 | { |
dd38c875 MB |
169 | if( !GetBitmap().Ok() ) |
170 | return false; | |
da175b2c | 171 | |
dd38c875 | 172 | (*(Pixmap*)buf) = (Pixmap)GetBitmap().GetDrawable(); |
da175b2c | 173 | |
dd38c875 | 174 | return true; |
dc63c944 | 175 | } |
da175b2c | 176 | |
dd38c875 | 177 | bool wxBitmapDataObject::SetData(size_t len, const void* buf) |
dc63c944 | 178 | { |
dd38c875 MB |
179 | if( len != sizeof(Pixmap) ) |
180 | return false; | |
da175b2c | 181 | |
dd38c875 | 182 | WXPixmap pixmap = (WXPixmap)*(Pixmap*)buf; |
da175b2c | 183 | |
dd38c875 | 184 | m_bitmap.Create( pixmap ); |
da175b2c | 185 | |
dd38c875 | 186 | return true; |
dc63c944 JS |
187 | } |
188 | ||
dfe1eee3 | 189 | #endif // wxUSE_CLIPBOARD |