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