]> git.saurik.com Git - wxWidgets.git/blame - src/common/dobjcmn.cpp
Add missing WXK constants for the control keys
[wxWidgets.git] / src / common / dobjcmn.cpp
CommitLineData
3f364be8 1///////////////////////////////////////////////////////////////////////////////
8b445796 2// Name: src/common/dobjcmn.cpp
3f364be8
VZ
3// Purpose: implementation of data object methods common to all platforms
4// Author: Vadim Zeitlin, Robert Roebling
5// Modified by:
6// Created: 19.10.99
7// RCS-ID: $Id$
77ffb593 8// Copyright: (c) wxWidgets Team
65571936 9// Licence: wxWindows licence
3f364be8
VZ
10///////////////////////////////////////////////////////////////////////////////
11
8b445796 12// For compilers that support precompilation, includes "wx.h".
3f364be8
VZ
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16 #pragma hdrstop
17#endif
18
1e6feb95
VZ
19#if wxUSE_DATAOBJ
20
e7c80f9e
WS
21#include "wx/dataobj.h"
22
3f364be8
VZ
23#ifndef WX_PRECOMP
24 #include "wx/app.h"
8b445796 25#endif
3f364be8 26
229f00eb
VZ
27#include "wx/textbuf.h"
28
3f364be8
VZ
29// ----------------------------------------------------------------------------
30// lists
31// ----------------------------------------------------------------------------
32
33#include "wx/listimpl.cpp"
34
259c43f6 35WX_DEFINE_LIST(wxSimpleDataObjectList)
3f364be8 36
0c2b453f
VZ
37// ----------------------------------------------------------------------------
38// globals
39// ----------------------------------------------------------------------------
40
41static wxDataFormat dataFormatInvalid;
31e78e0c 42WXDLLEXPORT const wxDataFormat& wxFormatInvalid = dataFormatInvalid;
0c2b453f 43
3f364be8
VZ
44// ============================================================================
45// implementation
46// ============================================================================
47
48// ----------------------------------------------------------------------------
49// wxDataObjectBase
50// ----------------------------------------------------------------------------
51
52wxDataObjectBase::~wxDataObjectBase()
53{
54}
55
d9317fd4
VZ
56bool wxDataObjectBase::IsSupported(const wxDataFormat& format,
57 Direction dir) const
58{
8b445796 59 size_t nFormatCount = GetFormatCount( dir );
d9317fd4
VZ
60 if ( nFormatCount == 1 )
61 {
8b445796 62 return format == GetPreferredFormat( dir );
d9317fd4
VZ
63 }
64 else
65 {
66 wxDataFormat *formats = new wxDataFormat[nFormatCount];
8b445796 67 GetAllFormats( formats, dir );
d9317fd4
VZ
68
69 size_t n;
70 for ( n = 0; n < nFormatCount; n++ )
71 {
72 if ( formats[n] == format )
73 break;
74 }
75
76 delete [] formats;
77
78 // found?
79 return n < nFormatCount;
80 }
81}
82
3f364be8
VZ
83// ----------------------------------------------------------------------------
84// wxDataObjectComposite
85// ----------------------------------------------------------------------------
86
e6b01b78
VZ
87wxDataObjectComposite::wxDataObjectComposite()
88{
89 m_preferred = 0;
c072c757 90 m_receivedFormat = wxFormatInvalid;
222ed1d6 91}
e6b01b78 92
222ed1d6
MB
93wxDataObjectComposite::~wxDataObjectComposite()
94{
8b445796 95 WX_CLEAR_LIST( wxSimpleDataObjectList, m_dataObjects );
e6b01b78
VZ
96}
97
3f364be8 98wxDataObjectSimple *
dc892843 99wxDataObjectComposite::GetObject(const wxDataFormat& format, wxDataObjectBase::Direction dir) const
3f364be8 100{
222ed1d6 101 wxSimpleDataObjectList::compatibility_iterator node = m_dataObjects.GetFirst();
dc892843 102
3f364be8
VZ
103 while ( node )
104 {
105 wxDataObjectSimple *dataObj = node->GetData();
106
dc892843
RR
107 if (dataObj->IsSupported(format,dir))
108 return dataObj;
3f364be8
VZ
109 node = node->GetNext();
110 }
d3b9f782 111 return NULL;
3f364be8
VZ
112}
113
114void wxDataObjectComposite::Add(wxDataObjectSimple *dataObject, bool preferred)
115{
116 if ( preferred )
117 m_preferred = m_dataObjects.GetCount();
c82f9bcf 118
3f364be8
VZ
119 m_dataObjects.Append( dataObject );
120}
121
c072c757
RD
122wxDataFormat wxDataObjectComposite::GetReceivedFormat() const
123{
124 return m_receivedFormat;
125}
126
3f364be8
VZ
127wxDataFormat
128wxDataObjectComposite::GetPreferredFormat(Direction WXUNUSED(dir)) const
129{
222ed1d6 130 wxSimpleDataObjectList::compatibility_iterator node = m_dataObjects.Item( m_preferred );
3f364be8 131
2ee3ee1b 132 wxCHECK_MSG( node, wxFormatInvalid, wxT("no preferred format") );
3f364be8
VZ
133
134 wxDataObjectSimple* dataObj = node->GetData();
135
136 return dataObj->GetFormat();
137}
138
e1b435af 139#if defined(__WXMSW__)
7d584866 140
e1b435af
MB
141size_t wxDataObjectComposite::GetBufferOffset( const wxDataFormat& format )
142{
143 wxDataObjectSimple *dataObj = GetObject(format);
144
f7f50f49 145 wxCHECK_MSG( dataObj, 0,
e1b435af
MB
146 wxT("unsupported format in wxDataObjectComposite"));
147
148 return dataObj->GetBufferOffset( format );
149}
150
7d584866 151
e1b435af
MB
152const void* wxDataObjectComposite::GetSizeFromBuffer( const void* buffer,
153 size_t* size,
154 const wxDataFormat& format )
155{
156 wxDataObjectSimple *dataObj = GetObject(format);
157
f7f50f49 158 wxCHECK_MSG( dataObj, NULL,
e1b435af
MB
159 wxT("unsupported format in wxDataObjectComposite"));
160
161 return dataObj->GetSizeFromBuffer( buffer, size, format );
162}
163
7d584866 164
e1b435af
MB
165void* wxDataObjectComposite::SetSizeInBuffer( void* buffer, size_t size,
166 const wxDataFormat& format )
167{
8b445796 168 wxDataObjectSimple *dataObj = GetObject( format );
e1b435af 169
f7f50f49 170 wxCHECK_MSG( dataObj, NULL,
e1b435af
MB
171 wxT("unsupported format in wxDataObjectComposite"));
172
173 return dataObj->SetSizeInBuffer( buffer, size, format );
174}
175
176#endif
177
9113ffaf 178size_t wxDataObjectComposite::GetFormatCount(Direction dir) const
3f364be8 179{
9113ffaf
FM
180 size_t n = 0;
181
182 // NOTE: some wxDataObjectSimple objects may return a number greater than 1
183 // from GetFormatCount(): this is the case of e.g. wxTextDataObject
184 // under wxMac and wxGTK
185 wxSimpleDataObjectList::compatibility_iterator node;
186 for ( node = m_dataObjects.GetFirst(); node; node = node->GetNext() )
187 n += node->GetData()->GetFormatCount(dir);
188
189 return n;
3f364be8
VZ
190}
191
192void wxDataObjectComposite::GetAllFormats(wxDataFormat *formats,
0dd48109 193 Direction dir) const
3f364be8 194{
0dd48109 195 size_t index(0);
222ed1d6 196 wxSimpleDataObjectList::compatibility_iterator node;
0dd48109 197
3f364be8
VZ
198 for ( node = m_dataObjects.GetFirst(); node; node = node->GetNext() )
199 {
9113ffaf
FM
200 // NOTE: some wxDataObjectSimple objects may return more than 1 format
201 // from GetAllFormats(): this is the case of e.g. wxTextDataObject
202 // under wxMac and wxGTK
203 node->GetData()->GetAllFormats(formats+index, dir);
204 index += node->GetData()->GetFormatCount(dir);
3f364be8
VZ
205 }
206}
207
208size_t wxDataObjectComposite::GetDataSize(const wxDataFormat& format) const
209{
210 wxDataObjectSimple *dataObj = GetObject(format);
211
212 wxCHECK_MSG( dataObj, 0,
213 wxT("unsupported format in wxDataObjectComposite"));
214
215 return dataObj->GetDataSize();
216}
217
218bool wxDataObjectComposite::GetDataHere(const wxDataFormat& format,
219 void *buf) const
220{
8b445796 221 wxDataObjectSimple *dataObj = GetObject( format );
3f364be8 222
68379eaf 223 wxCHECK_MSG( dataObj, false,
3f364be8
VZ
224 wxT("unsupported format in wxDataObjectComposite"));
225
8b445796 226 return dataObj->GetDataHere( buf );
3f364be8
VZ
227}
228
229bool wxDataObjectComposite::SetData(const wxDataFormat& format,
230 size_t len,
231 const void *buf)
232{
8b445796 233 wxDataObjectSimple *dataObj = GetObject( format );
3f364be8 234
68379eaf 235 wxCHECK_MSG( dataObj, false,
3f364be8
VZ
236 wxT("unsupported format in wxDataObjectComposite"));
237
c072c757 238 m_receivedFormat = format;
d361ea0d
VZ
239
240 // Notice that we must pass "format" here as wxTextDataObject, that we can
241 // have as one of our "simple" sub-objects actually is not that simple and
242 // can support multiple formats (ASCII/UTF-8/UTF-16/...) and so needs to
243 // know which one it is given.
244 return dataObj->SetData( format, len, buf );
3f364be8
VZ
245}
246
247// ----------------------------------------------------------------------------
248// wxTextDataObject
249// ----------------------------------------------------------------------------
250
98ecad06
VZ
251#ifdef wxNEEDS_UTF8_FOR_TEXT_DATAOBJ
252
253// FIXME-UTF8: we should be able to merge wchar_t and UTF-8 versions once we
254// have a way to get UTF-8 string (and its length) in both builds
255// without loss of efficiency (i.e. extra buffer copy/strlen call)
256
257#if wxUSE_UNICODE_WCHAR
c7d6d883 258
f4370741
VZ
259static inline wxMBConv& GetConv(const wxDataFormat& format)
260{
261 // use UTF8 for wxDF_UNICODETEXT and UCS4 for wxDF_TEXT
262 return format == wxDF_UNICODETEXT ? wxConvUTF8 : wxConvLibc;
263}
264
c7d6d883
RR
265size_t wxTextDataObject::GetDataSize(const wxDataFormat& format) const
266{
f4370741 267 wxCharBuffer buffer = GetConv(format).cWX2MB( GetText().c_str() );
8b445796 268
2c906a49 269 return buffer ? strlen( buffer ) : 0;
c7d6d883
RR
270}
271
272bool wxTextDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
273{
f7570f57 274 if ( !buf )
8b445796
DS
275 return false;
276
f4370741 277 wxCharBuffer buffer = GetConv(format).cWX2MB( GetText().c_str() );
f7570f57
RR
278 if ( !buffer )
279 return false;
f4370741 280
f7570f57
RR
281 memcpy( (char*) buf, buffer, GetDataSize(format) );
282 // strcpy( (char*) buf, buffer );
68379eaf
WS
283
284 return true;
c7d6d883
RR
285}
286
287bool wxTextDataObject::SetData(const wxDataFormat& format,
288 size_t WXUNUSED(len), const void *buf)
289{
8b445796 290 if ( buf == NULL )
f4370741
VZ
291 return false;
292
8b445796 293 wxWCharBuffer buffer = GetConv(format).cMB2WX( (const char*)buf );
8b445796
DS
294
295 SetText( buffer );
68379eaf
WS
296
297 return true;
c7d6d883
RR
298}
299
98ecad06
VZ
300#else // wxUSE_UNICODE_UTF8
301
302size_t wxTextDataObject::GetDataSize(const wxDataFormat& format) const
303{
46a0544e 304 const wxString& text = GetText();
98ecad06
VZ
305 if ( format == wxDF_UNICODETEXT || wxLocaleIsUtf8 )
306 {
46a0544e 307 return text.utf8_length();
98ecad06
VZ
308 }
309 else // wxDF_TEXT
310 {
46a0544e 311 const wxCharBuffer buf(wxConvLocal.cWC2MB(text.wc_str()));
98ecad06
VZ
312 return buf ? strlen(buf) : 0;
313 }
314}
315
316bool wxTextDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
317{
318 if ( !buf )
319 return false;
320
46a0544e 321 const wxString& text = GetText();
98ecad06
VZ
322 if ( format == wxDF_UNICODETEXT || wxLocaleIsUtf8 )
323 {
46a0544e 324 memcpy(buf, text.utf8_str(), text.utf8_length());
98ecad06
VZ
325 }
326 else // wxDF_TEXT
327 {
46a0544e 328 const wxCharBuffer bufLocal(wxConvLocal.cWC2MB(text.wc_str()));
98ecad06
VZ
329 if ( !bufLocal )
330 return false;
331
332 memcpy(buf, bufLocal, strlen(bufLocal));
333 }
334
335 return true;
336}
337
338bool wxTextDataObject::SetData(const wxDataFormat& format,
339 size_t len, const void *buf_)
340{
5c33522f 341 const char * const buf = static_cast<const char *>(buf_);
98ecad06
VZ
342
343 if ( buf == NULL )
344 return false;
345
346 if ( format == wxDF_UNICODETEXT || wxLocaleIsUtf8 )
347 {
348 // normally the data is in UTF-8 so we could use FromUTF8Unchecked()
349 // but it's not absolutely clear what GTK+ does if the clipboard data
350 // is not in UTF-8 so do an extra check for tranquility, it shouldn't
351 // matter much if we lose a bit of performance when pasting from
352 // clipboard
46a0544e 353 SetText(wxString::FromUTF8(buf, len));
98ecad06
VZ
354 }
355 else // wxDF_TEXT, convert from current (non-UTF8) locale
356 {
46a0544e 357 SetText(wxConvLocal.cMB2WC(buf, len, NULL));
98ecad06
VZ
358 }
359
360 return true;
361}
362
363#endif // wxUSE_UNICODE_WCHAR/wxUSE_UNICODE_UTF8
364
365#elif defined(wxNEEDS_UTF16_FOR_TEXT_DATAOBJ)
25758297 366
5dea30b3
VZ
367namespace
368{
671478ee 369
5dea30b3 370inline wxMBConv& GetConv(const wxDataFormat& format)
671478ee 371{
5dea30b3
VZ
372 static wxMBConvUTF16 s_UTF16Converter;
373
374 return format == wxDF_UNICODETEXT ? static_cast<wxMBConv&>(s_UTF16Converter)
375 : static_cast<wxMBConv&>(wxConvLocal);
671478ee
SC
376}
377
5dea30b3
VZ
378} // anonymous namespace
379
25758297
SC
380size_t wxTextDataObject::GetDataSize(const wxDataFormat& format) const
381{
5dea30b3 382 return GetConv(format).WC2MB(NULL, GetText().wc_str(), 0);
25758297
SC
383}
384
385bool wxTextDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
386{
8b445796 387 if ( buf == NULL )
671478ee
SC
388 return false;
389
5dea30b3 390 wxCharBuffer buffer(GetConv(format).cWX2MB(GetText().c_str()));
671478ee 391
5dea30b3 392 memcpy(buf, buffer.data(), buffer.length());
68379eaf
WS
393
394 return true;
25758297
SC
395}
396
397bool wxTextDataObject::SetData(const wxDataFormat& format,
5dea30b3
VZ
398 size_t WXUNUSED(len),
399 const void *buf)
25758297 400{
8b445796 401 if ( buf == NULL )
671478ee 402 return false;
8b445796 403
5dea30b3 404 SetText(GetConv(format).cMB2WX(static_cast<const char*>(buf)));
8b445796 405
68379eaf 406 return true;
25758297
SC
407}
408
98ecad06 409#else // !wxNEEDS_UTF{8,16}_FOR_TEXT_DATAOBJ
c7d6d883 410
229f00eb
VZ
411// NB: This branch, using native wxChar for the clipboard, is only used under
412// Windows currently. It's just a coincidence, but Windows is also the only
413// platform where we need to convert the text to the native EOL format, so
414// wxTextBuffer::Translate() is only used here and not in the code above.
415
c7d6d883
RR
416size_t wxTextDataObject::GetDataSize() const
417{
229f00eb 418 return (wxTextBuffer::Translate(GetText()).length() + 1)*sizeof(wxChar);
3f364be8
VZ
419}
420
421bool wxTextDataObject::GetDataHere(void *buf) const
422{
229f00eb
VZ
423 const wxString textNative = wxTextBuffer::Translate(GetText());
424
f453d7ea
FM
425 // NOTE: use wxTmemcpy() instead of wxStrncpy() to allow
426 // retrieval of strings with embedded NULLs
229f00eb 427 wxTmemcpy(static_cast<wxChar*>(buf),
73ed2b2b
VZ
428 textNative.t_str(),
429 textNative.length() + 1);
3f364be8 430
68379eaf 431 return true;
3f364be8
VZ
432}
433
f453d7ea 434bool wxTextDataObject::SetData(size_t len, const void *buf)
3f364be8 435{
229f00eb
VZ
436 const wxString
437 text = wxString(static_cast<const wxChar*>(buf), len/sizeof(wxChar));
438 SetText(wxTextBuffer::Translate(text, wxTextFileType_Unix));
3f364be8 439
68379eaf 440 return true;
3f364be8
VZ
441}
442
98ecad06 443#endif // different wxTextDataObject implementations
9e2896e5 444
229f00eb
VZ
445// ----------------------------------------------------------------------------
446// wxHTMLDataObject
447// ----------------------------------------------------------------------------
448
b8acf11e
RD
449size_t wxHTMLDataObject::GetDataSize() const
450{
f421e3f1
VZ
451 const wxScopedCharBuffer buffer(GetHTML().utf8_str());
452
453 size_t size = buffer.length();
b8acf11e 454
6b66bb1e 455#ifdef __WXMSW__
f421e3f1
VZ
456 // On Windows we need to add some stuff to the string to satisfy
457 // its clipboard format requirements.
458 size += 400;
b8acf11e 459#endif
b8acf11e
RD
460
461 return size;
462}
463
464bool wxHTMLDataObject::GetDataHere(void *buf) const
465{
466 if ( !buf )
467 return false;
468
469 // Windows and Mac always use UTF-8, and docs suggest GTK does as well.
f421e3f1 470 const wxScopedCharBuffer html(GetHTML().utf8_str());
b8acf11e
RD
471 if ( !html )
472 return false;
473
f421e3f1
VZ
474 char* const buffer = static_cast<char*>(buf);
475
6b66bb1e 476#ifdef __WXMSW__
b8acf11e 477 // add the extra info that the MSW clipboard format requires.
b8acf11e
RD
478
479 // Create a template string for the HTML header...
480 strcpy(buffer,
481 "Version:0.9\r\n"
482 "StartHTML:00000000\r\n"
483 "EndHTML:00000000\r\n"
484 "StartFragment:00000000\r\n"
485 "EndFragment:00000000\r\n"
486 "<html><body>\r\n"
487 "<!--StartFragment -->\r\n");
488
489 // Append the HTML...
490 strcat(buffer, html);
491 strcat(buffer, "\r\n");
492 // Finish up the HTML format...
493 strcat(buffer,
494 "<!--EndFragment-->\r\n"
495 "</body>\r\n"
496 "</html>");
497
498 // Now go back, calculate all the lengths, and write out the
499 // necessary header information. Note, wsprintf() truncates the
500 // string when you overwrite it so you follow up with code to replace
501 // the 0 appended at the end with a '\r'...
502 char *ptr = strstr(buffer, "StartHTML");
503 sprintf(ptr+10, "%08u", (unsigned)(strstr(buffer, "<html>") - buffer));
504 *(ptr+10+8) = '\r';
505
506 ptr = strstr(buffer, "EndHTML");
507 sprintf(ptr+8, "%08u", (unsigned)strlen(buffer));
508 *(ptr+8+8) = '\r';
509
510 ptr = strstr(buffer, "StartFragment");
511 sprintf(ptr+14, "%08u", (unsigned)(strstr(buffer, "<!--StartFrag") - buffer));
512 *(ptr+14+8) = '\r';
513
514 ptr = strstr(buffer, "EndFragment");
515 sprintf(ptr+12, "%08u", (unsigned)(strstr(buffer, "<!--EndFrag") - buffer));
516 *(ptr+12+8) = '\r';
517#else
f421e3f1 518 strcpy(buffer, html);
b8acf11e
RD
519#endif // __WXMSW__
520
b8acf11e
RD
521 return true;
522}
523
524bool wxHTMLDataObject::SetData(size_t WXUNUSED(len), const void *buf)
525{
526 if ( buf == NULL )
527 return false;
528
529 // Windows and Mac always use UTF-8, and docs suggest GTK does as well.
1dcb50be 530 wxString html = wxString::FromUTF8(static_cast<const char*>(buf));
b8acf11e 531
f421e3f1 532#ifdef __WXMSW__
b8acf11e
RD
533 // To be consistent with other platforms, we only add the Fragment part
534 // of the Windows HTML clipboard format to the data object.
b8acf11e
RD
535 int fragmentStart = html.rfind("StartFragment");
536 int fragmentEnd = html.rfind("EndFragment");
537
f421e3f1 538 if (fragmentStart != wxNOT_FOUND && fragmentEnd != wxNOT_FOUND)
b8acf11e
RD
539 {
540 int startCommentEnd = html.find("-->", fragmentStart) + 3;
541 int endCommentStart = html.rfind("<!--", fragmentEnd);
f421e3f1 542
b8acf11e
RD
543 if (startCommentEnd != wxNOT_FOUND && endCommentStart != wxNOT_FOUND)
544 html = html.Mid(startCommentEnd, endCommentStart - startCommentEnd);
545 }
f421e3f1
VZ
546#endif // __WXMSW__
547
b8acf11e
RD
548 SetHTML( html );
549
550 return true;
551}
552
553
3f364be8
VZ
554// ----------------------------------------------------------------------------
555// wxCustomDataObject
556// ----------------------------------------------------------------------------
557
775e1c62
RD
558wxCustomDataObject::wxCustomDataObject(const wxDataFormat& format)
559 : wxDataObjectSimple(format)
560{
8b445796
DS
561 m_data = NULL;
562 m_size = 0;
775e1c62
RD
563}
564
3f364be8
VZ
565wxCustomDataObject::~wxCustomDataObject()
566{
567 Free();
568}
569
570void wxCustomDataObject::TakeData(size_t size, void *data)
571{
572 Free();
573
574 m_size = size;
575 m_data = data;
576}
577
578void *wxCustomDataObject::Alloc(size_t size)
579{
580 return (void *)new char[size];
581}
582
583void wxCustomDataObject::Free()
584{
8b445796 585 delete [] (char*)m_data;
3f364be8 586 m_size = 0;
d3b9f782 587 m_data = NULL;
3f364be8
VZ
588}
589
590size_t wxCustomDataObject::GetDataSize() const
591{
592 return GetSize();
593}
594
595bool wxCustomDataObject::GetDataHere(void *buf) const
596{
8b445796
DS
597 if ( buf == NULL )
598 return false;
599
3f364be8 600 void *data = GetData();
8b445796 601 if ( data == NULL )
68379eaf 602 return false;
3f364be8 603
8b445796 604 memcpy( buf, data, GetSize() );
3f364be8 605
68379eaf 606 return true;
3f364be8
VZ
607}
608
9e2896e5 609bool wxCustomDataObject::SetData(size_t size, const void *buf)
3f364be8
VZ
610{
611 Free();
612
613 m_data = Alloc(size);
8b445796 614 if ( m_data == NULL )
68379eaf 615 return false;
3f364be8 616
8b445796
DS
617 m_size = size;
618 memcpy( m_data, buf, m_size );
3f364be8 619
68379eaf 620 return true;
3f364be8
VZ
621}
622
8ee9d618
VZ
623// ============================================================================
624// some common dnd related code
625// ============================================================================
626
8fb3a512
JS
627#if wxUSE_DRAG_AND_DROP
628
8ee9d618
VZ
629#include "wx/dnd.h"
630
631// ----------------------------------------------------------------------------
632// wxTextDropTarget
633// ----------------------------------------------------------------------------
634
f3ac12aa
VZ
635// NB: we can't use "new" in ctor initializer lists because this provokes an
636// internal compiler error with VC++ 5.0 (hey, even gcc compiles this!),
637// so use SetDataObject() instead
638
8ee9d618 639wxTextDropTarget::wxTextDropTarget()
8ee9d618 640{
f3ac12aa 641 SetDataObject(new wxTextDataObject);
8ee9d618
VZ
642}
643
644wxDragResult wxTextDropTarget::OnData(wxCoord x, wxCoord y, wxDragResult def)
645{
646 if ( !GetData() )
647 return wxDragNone;
648
649 wxTextDataObject *dobj = (wxTextDataObject *)m_dataObject;
8b445796 650 return OnDropText( x, y, dobj->GetText() ) ? def : wxDragNone;
8ee9d618
VZ
651}
652
653// ----------------------------------------------------------------------------
654// wxFileDropTarget
655// ----------------------------------------------------------------------------
656
657wxFileDropTarget::wxFileDropTarget()
8ee9d618 658{
f3ac12aa 659 SetDataObject(new wxFileDataObject);
8ee9d618
VZ
660}
661
662wxDragResult wxFileDropTarget::OnData(wxCoord x, wxCoord y, wxDragResult def)
663{
664 if ( !GetData() )
665 return wxDragNone;
666
667 wxFileDataObject *dobj = (wxFileDataObject *)m_dataObject;
8b445796 668 return OnDropFiles( x, y, dobj->GetFilenames() ) ? def : wxDragNone;
8ee9d618
VZ
669}
670
1e6feb95 671#endif // wxUSE_DRAG_AND_DROP
8fb3a512 672
1e6feb95 673#endif // wxUSE_DATAOBJ