]>
Commit | Line | Data |
---|---|---|
dc63c944 | 1 | /////////////////////////////////////////////////////////////////////////////// |
7520f3da | 2 | // Name: src/motif/dataobj.cpp |
dc63c944 JS |
3 | // Purpose: wxDataObject class |
4 | // Author: Julian Smart | |
dc63c944 | 5 | // Copyright: (c) 1998 Julian Smart |
65571936 | 6 | // Licence: wxWindows licence |
dc63c944 JS |
7 | /////////////////////////////////////////////////////////////////////////////// |
8 | ||
1248b41f MB |
9 | // For compilers that support precompilation, includes "wx.h". |
10 | #include "wx/wxprec.h" | |
11 | ||
dfe1eee3 VZ |
12 | #if wxUSE_CLIPBOARD |
13 | ||
dc63c944 | 14 | #include "wx/dataobj.h" |
670f9935 WS |
15 | |
16 | #ifndef WX_PRECOMP | |
17 | #include "wx/app.h" | |
de6185e2 | 18 | #include "wx/utils.h" |
670f9935 WS |
19 | #endif |
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 | ||
da175b2c RR |
63 | wxDataFormat::wxDataFormat( const wxString &id ) |
64 | { | |
76db86e7 | 65 | PrepareFormats(); |
da175b2c RR |
66 | SetId( id ); |
67 | } | |
68 | ||
76db86e7 | 69 | wxDataFormat::wxDataFormat( NativeFormat format ) |
da175b2c | 70 | { |
76db86e7 RR |
71 | PrepareFormats(); |
72 | SetId( format ); | |
da175b2c RR |
73 | } |
74 | ||
75 | void wxDataFormat::SetType( wxDataFormatId type ) | |
76 | { | |
76db86e7 | 77 | PrepareFormats(); |
da175b2c RR |
78 | m_type = type; |
79 | ||
80 | if (m_type == wxDF_TEXT) | |
76db86e7 | 81 | m_format = g_textAtom; |
da175b2c RR |
82 | else |
83 | if (m_type == wxDF_BITMAP) | |
dd38c875 | 84 | m_format = g_bitmapAtom; |
da175b2c RR |
85 | else |
86 | if (m_type == wxDF_FILENAME) | |
76db86e7 | 87 | m_format = g_fileAtom; |
da175b2c RR |
88 | else |
89 | { | |
223d09f6 | 90 | wxFAIL_MSG( wxT("invalid dataformat") ); |
da175b2c | 91 | } |
76db86e7 RR |
92 | } |
93 | ||
94 | wxDataFormatId wxDataFormat::GetType() const | |
95 | { | |
96 | return m_type; | |
97 | } | |
98 | ||
99 | wxString wxDataFormat::GetId() const | |
100 | { | |
101 | char *t = XGetAtomName ((Display*) wxGetDisplay(), m_format); | |
102 | wxString ret( t ); // this will convert from ascii to Unicode | |
7520f3da | 103 | if (t) |
76db86e7 RR |
104 | XFree( t ); |
105 | return ret; | |
106 | } | |
107 | ||
108 | void wxDataFormat::SetId( NativeFormat format ) | |
109 | { | |
110 | PrepareFormats(); | |
111 | m_format = format; | |
da175b2c | 112 | |
76db86e7 RR |
113 | if (m_format == g_textAtom) |
114 | m_type = wxDF_TEXT; | |
115 | else | |
dd38c875 | 116 | if (m_format == g_bitmapAtom) |
76db86e7 RR |
117 | m_type = wxDF_BITMAP; |
118 | else | |
119 | if (m_format == g_fileAtom) | |
120 | m_type = wxDF_FILENAME; | |
121 | else | |
122 | m_type = wxDF_PRIVATE; | |
da175b2c RR |
123 | } |
124 | ||
a1eb65c2 | 125 | void wxDataFormat::SetId( const wxString& id ) |
da175b2c | 126 | { |
76db86e7 | 127 | PrepareFormats(); |
da175b2c | 128 | m_type = wxDF_PRIVATE; |
dd38c875 | 129 | m_format = XInternAtom( wxGlobalDisplay(), |
a1eb65c2 | 130 | id.mbc_str(), False ); |
da175b2c RR |
131 | } |
132 | ||
76db86e7 | 133 | void wxDataFormat::PrepareFormats() |
da175b2c | 134 | { |
76db86e7 | 135 | if (!g_textAtom) |
96be256b | 136 | g_textAtom = XInternAtom( wxGlobalDisplay(), "STRING", False ); |
dd38c875 | 137 | if (!g_bitmapAtom) |
96be256b | 138 | g_bitmapAtom = XInternAtom( wxGlobalDisplay(), "PIXMAP", False ); |
76db86e7 | 139 | if (!g_fileAtom) |
96be256b | 140 | g_fileAtom = XInternAtom( wxGlobalDisplay(), "file:ALL", False ); |
da175b2c RR |
141 | } |
142 | ||
1eaf587e VZ |
143 | // ---------------------------------------------------------------------------- |
144 | // wxDataObject | |
145 | // ---------------------------------------------------------------------------- | |
146 | ||
147 | wxDataObject::~wxDataObject() | |
148 | { | |
149 | } | |
150 | ||
dc63c944 | 151 | // ---------------------------------------------------------------------------- |
dd38c875 | 152 | // wxBitmapDataObject |
dc63c944 JS |
153 | // ---------------------------------------------------------------------------- |
154 | ||
dd38c875 | 155 | size_t wxBitmapDataObject::GetDataSize() const |
da175b2c | 156 | { |
dd38c875 | 157 | return sizeof(Pixmap); |
dc63c944 | 158 | } |
da175b2c | 159 | |
dd38c875 | 160 | bool wxBitmapDataObject::GetDataHere(void* buf) const |
da175b2c | 161 | { |
a1b806b9 | 162 | if( !GetBitmap().IsOk() ) |
dd38c875 | 163 | return false; |
da175b2c | 164 | |
dd38c875 | 165 | (*(Pixmap*)buf) = (Pixmap)GetBitmap().GetDrawable(); |
da175b2c | 166 | |
dd38c875 | 167 | return true; |
dc63c944 | 168 | } |
da175b2c | 169 | |
dd38c875 | 170 | bool wxBitmapDataObject::SetData(size_t len, const void* buf) |
dc63c944 | 171 | { |
dd38c875 MB |
172 | if( len != sizeof(Pixmap) ) |
173 | return false; | |
da175b2c | 174 | |
dd38c875 | 175 | WXPixmap pixmap = (WXPixmap)*(Pixmap*)buf; |
da175b2c | 176 | |
dd38c875 | 177 | m_bitmap.Create( pixmap ); |
da175b2c | 178 | |
dd38c875 | 179 | return true; |
dc63c944 JS |
180 | } |
181 | ||
dfe1eee3 | 182 | #endif // wxUSE_CLIPBOARD |