]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/dnd.cpp
wxDataObejct and related changes (won't compile right now)
[wxWidgets.git] / src / gtk / dnd.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: dnd.cpp
3 // Purpose: wxDropTarget class
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #ifdef __GNUG__
11 #pragma implementation "dnd.h"
12 #endif
13
14 #include "wx/dnd.h"
15
16 #if wxUSE_DRAG_AND_DROP
17
18 #include "wx/window.h"
19 #include "wx/app.h"
20 #include "wx/gdicmn.h"
21 #include "wx/intl.h"
22 #include "wx/utils.h"
23
24 #include "gdk/gdk.h"
25 #include "gtk/gtk.h"
26 #include "gdk/gdkprivate.h"
27
28 #include "gtk/gtkdnd.h"
29 #include "gtk/gtkselection.h"
30
31 //-----------------------------------------------------------------------------
32 // idle system
33 //-----------------------------------------------------------------------------
34
35 extern void wxapp_install_idle_handler();
36 extern bool g_isIdle;
37
38 //-----------------------------------------------------------------------------
39 // thread system
40 //-----------------------------------------------------------------------------
41
42 #if wxUSE_THREADS
43 extern void wxapp_install_thread_wakeup();
44 extern void wxapp_uninstall_thread_wakeup();
45 #endif
46
47 //----------------------------------------------------------------------------
48 // global data
49 //----------------------------------------------------------------------------
50
51 extern bool g_blockEventsOnDrag;
52
53 //----------------------------------------------------------------------------
54 // standard icons
55 //----------------------------------------------------------------------------
56
57 /* XPM */
58 static char * gv_xpm[] = {
59 "40 34 3 1",
60 " s None c None",
61 ". c black",
62 "X c white",
63 " ",
64 " ",
65 " ...... ",
66 " ..XXXXXX.. ",
67 " .XXXXXXXXXX. ",
68 " .XXXXXXXXXXXX. ",
69 " .XXXXXXXXXXXX. ",
70 " .XXXXXXXXXXXXXX. ",
71 " .XXX..XXXX..XXX. ",
72 " ....XX....XX....XX. ",
73 " .XXX.XXX..XXXX..XXX.... ",
74 " .XXXXXXXXXXXXXXXXXXX.XXX. ",
75 " .XXXXXXXXXXXXXXXXXXXXXXXX. ",
76 " .XXXXXXXXXXXXXXXXXXXXXXXX. ",
77 " ..XXXXXXXXXXXXXXXXXXXXXX. ",
78 " .XXXXXXXXXXXXXXXXXX... ",
79 " ..XXXXXXXXXXXXXXXX. ",
80 " .XXXXXXXXXXXXXXXX. ",
81 " .XXXXXXXXXXXXXXXX. ",
82 " .XXXXXXXXXXXXXXXXX. ",
83 " .XXXXXXXXXXXXXXXXX. ",
84 " .XXXXXXXXXXXXXXXXXX. ",
85 " .XXXXXXXXXXXXXXXXXXX. ",
86 " .XXXXXXXXXXXXXXXXXXXXX. ",
87 " .XXXXXXXXXXXXXX.XXXXXXX. ",
88 " .XXXXXXX.XXXXXXX.XXXXXXX. ",
89 " .XXXXXXXX.XXXXXXX.XXXXXXX. ",
90 " .XXXXXXX...XXXXX...XXXXX. ",
91 " .XXXXXXX. ..... ..... ",
92 " ..XXXX.. ",
93 " .... ",
94 " ",
95 " ",
96 " "};
97
98 /* XPM */
99 static char * page_xpm[] = {
100 /* width height ncolors chars_per_pixel */
101 "32 32 5 1",
102 /* colors */
103 " s None c None",
104 ". c black",
105 "X c wheat",
106 "o c tan",
107 "O c #6699FF",
108 /* pixels */
109 " ................... ",
110 " .XXXXXXXXXXXXXXXXX.. ",
111 " .XXXXXXXXXXXXXXXXX.o. ",
112 " .XXXXXXXXXXXXXXXXX.oo. ",
113 " .XXXXXXXXXXXXXXXXX.ooo. ",
114 " .XXXXXXXXXXXXXXXXX.oooo. ",
115 " .XXXXXXXXXXXXXXXXX....... ",
116 " .XXXXXOOOOOOOOOOXXXooooo. ",
117 " .XXXXXXXXXXXXXXXXXXooooo. ",
118 " .XXXXXOOOOOOOOOOXXXXXXXX. ",
119 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
120 " .XXXXXXXOOOOOOOOOXXXXXXX. ",
121 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
122 " .XXXXXXOOOOOOOOOOXXXXXXX. ",
123 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
124 " .XXXXXOOOOOOOOOOXXXXXXXX. ",
125 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
126 " .XXXXXXXOOOOOOOOOXXXXXXX. ",
127 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
128 " .XXXXXXOOOOOOOOOOXXXXXXX. ",
129 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
130 " .XXXXXOOOOOOOOOOXXXXXXXX. ",
131 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
132 " .XXXXXXOOOOOOOOOOXXXXXXX. ",
133 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
134 " .XXXXXOOOOOOOXXXXXXXXXXX. ",
135 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
136 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
137 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
138 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
139 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
140 " ......................... "};
141
142
143
144 // ----------------------------------------------------------------------------
145 // "drag_leave"
146 // ----------------------------------------------------------------------------
147
148 static void target_drag_leave( GtkWidget *WXUNUSED(widget),
149 GdkDragContext *context,
150 guint WXUNUSED(time),
151 wxDropTarget *drop_target )
152 {
153 if (g_isIdle) wxapp_install_idle_handler();
154
155 /* inform the wxDropTarget about the current GdkDragContext.
156 this is only valid for the duration of this call */
157 drop_target->SetDragContext( context );
158
159 /* we don't need return values. this event is just for
160 information */
161 drop_target->OnLeave();
162
163 /* this has to be done because GDK has no "drag_enter" event */
164 drop_target->m_firstMotion = TRUE;
165
166 /* after this, invalidate the drop_target's GdkDragContext */
167 drop_target->SetDragContext( (GdkDragContext*) NULL );
168 }
169
170 // ----------------------------------------------------------------------------
171 // "drag_motion"
172 // ----------------------------------------------------------------------------
173
174 static gboolean target_drag_motion( GtkWidget *WXUNUSED(widget),
175 GdkDragContext *context,
176 gint x,
177 gint y,
178 guint time,
179 wxDropTarget *drop_target )
180 {
181 if (g_isIdle) wxapp_install_idle_handler();
182
183 /* Owen Taylor: "if the coordinates not in a drop zone,
184 return FALSE, otherwise call gtk_drag_status() and
185 return TRUE" */
186
187 /* inform the wxDropTarget about the current GdkDragContext.
188 this is only valid for the duration of this call */
189 drop_target->SetDragContext( context );
190
191 bool ret = FALSE;
192
193 if (drop_target->m_firstMotion)
194 {
195 /* the first "drag_motion" event substitutes a "drag_enter" event */
196 ret = drop_target->OnEnter( x, y );
197 }
198 else
199 {
200 /* give program a chance to react (i.e. to say no by returning FALSE) */
201 ret = drop_target->OnMove( x, y );
202 }
203
204 /* we don't yet handle which "actions" (i.e. copy or move)
205 the target accepts. so far we simply accept the
206 suggested action. TODO. */
207 if (ret)
208 gdk_drag_status( context, context->suggested_action, time );
209
210 /* after this, invalidate the drop_target's GdkDragContext */
211 drop_target->SetDragContext( (GdkDragContext*) NULL );
212
213 /* this has to be done because GDK has no "drag_enter" event */
214 drop_target->m_firstMotion = FALSE;
215
216 return ret;
217 }
218
219 // ----------------------------------------------------------------------------
220 // "drag_drop"
221 // ----------------------------------------------------------------------------
222
223 static gboolean target_drag_drop( GtkWidget *widget,
224 GdkDragContext *context,
225 gint x,
226 gint y,
227 guint time,
228 wxDropTarget *drop_target )
229 {
230 if (g_isIdle) wxapp_install_idle_handler();
231
232 /* Owen Taylor: "if the drop is not in a drop zone,
233 return FALSE, otherwise, if you aren't accepting
234 the drop, call gtk_drag_finish() with success == FALSE
235 otherwise call gtk_drag_data_get()" */
236
237 // printf( "drop.\n" );
238
239 /* this seems to make a difference between not accepting
240 due to wrong target area and due to wrong format. let
241 us hope that this is not required.. */
242
243 /* inform the wxDropTarget about the current GdkDragContext.
244 this is only valid for the duration of this call */
245 drop_target->SetDragContext( context );
246
247 /* inform the wxDropTarget about the current drag widget.
248 this is only valid for the duration of this call */
249 drop_target->SetDragWidget( widget );
250
251 /* inform the wxDropTarget about the current drag time.
252 this is only valid for the duration of this call */
253 drop_target->SetDragTime( time );
254
255 bool ret = drop_target->OnDrop( x, y );
256
257 if (!ret)
258 {
259 /* cancel the whole thing */
260 gtk_drag_finish( context,
261 FALSE, /* no success */
262 FALSE, /* don't delete data on dropping side */
263 time );
264 }
265 else
266 {
267 #if wxUSE_THREADS
268 /* disable GUI threads */
269 wxapp_uninstall_thread_wakeup();
270 #endif
271
272 GdkAtom format = drop_target->GetMatchingPair();
273 wxASSERT( format );
274
275 /* this should trigger an "drag_data_received" event */
276 gtk_drag_get_data( widget,
277 context,
278 format,
279 time );
280
281 #if wxUSE_THREADS
282 /* re-enable GUI threads */
283 wxapp_install_thread_wakeup();
284 #endif
285 }
286
287 /* after this, invalidate the drop_target's GdkDragContext */
288 drop_target->SetDragContext( (GdkDragContext*) NULL );
289
290 /* after this, invalidate the drop_target's drag widget */
291 drop_target->SetDragWidget( (GtkWidget*) NULL );
292
293 /* this has to be done because GDK has no "drag_enter" event */
294 drop_target->m_firstMotion = TRUE;
295
296 return ret;
297 }
298
299 // ----------------------------------------------------------------------------
300 // "drag_data_received"
301 // ----------------------------------------------------------------------------
302
303 static void target_drag_data_received( GtkWidget *WXUNUSED(widget),
304 GdkDragContext *context,
305 gint x,
306 gint y,
307 GtkSelectionData *data,
308 guint WXUNUSED(info),
309 guint time,
310 wxDropTarget *drop_target )
311 {
312 if (g_isIdle) wxapp_install_idle_handler();
313
314 /* Owen Taylor: "call gtk_drag_finish() with
315 success == TRUE" */
316
317
318 if ((data->length <= 0) || (data->format != 8))
319 {
320 /* negative data length and non 8-bit data format
321 qualifies for junk */
322 gtk_drag_finish (context, FALSE, FALSE, time);
323
324 return;
325 }
326
327 wxLogDebug( wxT( "Drop target: data received") );
328
329 /* inform the wxDropTarget about the current GtkSelectionData.
330 this is only valid for the duration of this call */
331 drop_target->SetDragData( data );
332
333 if (drop_target->OnData( x, y ))
334 {
335 /* tell GTK that data transfer was successfull */
336 gtk_drag_finish( context, TRUE, FALSE, time );
337 }
338 else
339 {
340 /* tell GTK that data transfer was not successfull */
341 gtk_drag_finish( context, FALSE, FALSE, time );
342 }
343
344 /* after this, invalidate the drop_target's drag data */
345 drop_target->SetDragData( (GtkSelectionData*) NULL );
346 }
347
348 //----------------------------------------------------------------------------
349 // wxDropTarget
350 //----------------------------------------------------------------------------
351
352 wxDropTarget::wxDropTarget( wxDataObject *data )
353 {
354 m_firstMotion = TRUE;
355 m_dragContext = (GdkDragContext*) NULL;
356 m_dragWidget = (GtkWidget*) NULL;
357 m_dragData = (GtkSelectionData*) NULL;
358 m_dragTime = 0;
359 m_data = data;
360 }
361
362 wxDropTarget::~wxDropTarget()
363 {
364 }
365
366 bool wxDropTarget::OnEnter( int WXUNUSED(x), int WXUNUSED(y) )
367 {
368 if (!m_data)
369 return FALSE;
370
371 return (GetMatchingPair() != (GdkAtom) 0);
372 }
373
374 void wxDropTarget::OnLeave()
375 {
376 }
377
378 bool wxDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) )
379 {
380 if (!m_data)
381 return FALSE;
382
383 return (GetMatchingPair() != (GdkAtom) 0);
384 }
385
386 bool wxDropTarget::OnDrop( int WXUNUSED(x), int WXUNUSED(y) )
387 {
388 if (!m_data)
389 return FALSE;
390
391 return (GetMatchingPair() != (GdkAtom) 0);
392 }
393
394 bool wxDropTarget::OnData( int WXUNUSED(x), int WXUNUSED(y) )
395 {
396 if (!m_data)
397 return FALSE;
398
399 if (GetMatchingPair() == (GdkAtom) 0)
400 return FALSE;
401
402 return GetData();
403 }
404
405 GdkAtom wxDropTarget::GetMatchingPair()
406 {
407 if (!m_data)
408 return (GdkAtom) 0;
409
410 if (!m_dragContext)
411 return (GdkAtom) 0;
412
413 GList *child = m_dragContext->targets;
414 while (child)
415 {
416 GdkAtom formatAtom = (GdkAtom) GPOINTER_TO_INT(child->data);
417 wxDataFormat format( formatAtom );
418
419 #ifdef __WXDEBUG__
420 char *name = gdk_atom_name( formatAtom );
421 if (name) wxLogDebug( "Drop target: drag has format: %s", name );
422 #endif
423 if (m_data->IsSupportedFormat( format ))
424 return formatAtom;
425
426 child = child->next;
427 }
428
429 return (GdkAtom) 0;
430 }
431
432 bool wxDropTarget::GetData()
433 {
434 if (!m_dragData)
435 return FALSE;
436
437 if (!m_data)
438 return FALSE;
439
440 wxDataFormat dragFormat( m_dragData->target );
441
442 if (!m_data->IsSupportedFormat( dragFormat ))
443 return FALSE;
444
445 if (dragFormat.GetType() == wxDF_TEXT)
446 {
447 wxTextDataObject *text_object = (wxTextDataObject*)m_data;
448 text_object->SetText( (const char*)m_dragData->data );
449 return TRUE;
450 }
451
452 if (dragFormat.GetType() == wxDF_FILENAME)
453 {
454 wxFileDataObject *file_object = (wxFileDataObject*)m_data;
455 file_object->SetFiles( (const char*)m_dragData->data );
456 return TRUE;
457 }
458
459 return FALSE;
460 }
461
462 void wxDropTarget::UnregisterWidget( GtkWidget *widget )
463 {
464 wxCHECK_RET( widget != NULL, wxT("unregister widget is NULL") );
465
466 gtk_drag_dest_unset( widget );
467
468 gtk_signal_disconnect_by_func( GTK_OBJECT(widget),
469 GTK_SIGNAL_FUNC(target_drag_leave), (gpointer) this );
470
471 gtk_signal_disconnect_by_func( GTK_OBJECT(widget),
472 GTK_SIGNAL_FUNC(target_drag_motion), (gpointer) this );
473
474 gtk_signal_disconnect_by_func( GTK_OBJECT(widget),
475 GTK_SIGNAL_FUNC(target_drag_drop), (gpointer) this );
476
477 gtk_signal_disconnect_by_func( GTK_OBJECT(widget),
478 GTK_SIGNAL_FUNC(target_drag_data_received), (gpointer) this );
479 }
480
481 void wxDropTarget::RegisterWidget( GtkWidget *widget )
482 {
483 wxCHECK_RET( widget != NULL, wxT("register widget is NULL") );
484
485 /* gtk_drag_dest_set() determines what default behaviour we'd like
486 GTK to supply. we don't want to specify out targets (=formats)
487 or actions in advance (i.e. not GTK_DEST_DEFAULT_MOTION and
488 not GTK_DEST_DEFAULT_DROP). instead we react individually to
489 "drag_motion" and "drag_drop" events. this makes it possible
490 to allow dropping on only a small area. we should set
491 GTK_DEST_DEFAULT_HIGHLIGHT as this will switch on the nice
492 highlighting if dragging over standard controls, but this
493 seems to be broken without the other two. */
494
495 gtk_drag_dest_set( widget,
496 (GtkDestDefaults) 0, /* no default behaviour */
497 (GtkTargetEntry*) NULL, /* we don't supply any formats here */
498 0, /* number of targets = 0 */
499 (GdkDragAction) 0 ); /* we don't supply any actions here */
500
501 gtk_signal_connect( GTK_OBJECT(widget), "drag_leave",
502 GTK_SIGNAL_FUNC(target_drag_leave), (gpointer) this );
503
504 gtk_signal_connect( GTK_OBJECT(widget), "drag_motion",
505 GTK_SIGNAL_FUNC(target_drag_motion), (gpointer) this );
506
507 gtk_signal_connect( GTK_OBJECT(widget), "drag_drop",
508 GTK_SIGNAL_FUNC(target_drag_drop), (gpointer) this );
509
510 gtk_signal_connect( GTK_OBJECT(widget), "drag_data_received",
511 GTK_SIGNAL_FUNC(target_drag_data_received), (gpointer) this );
512 }
513
514 //----------------------------------------------------------------------------
515 // "drag_data_get"
516 //----------------------------------------------------------------------------
517
518 static void
519 source_drag_data_get (GtkWidget *WXUNUSED(widget),
520 GdkDragContext *context,
521 GtkSelectionData *selection_data,
522 guint WXUNUSED(info),
523 guint WXUNUSED(time),
524 wxDropSource *drop_source )
525 {
526 if (g_isIdle) wxapp_install_idle_handler();
527
528 #ifdef __WXDEBUG__
529 char *name = gdk_atom_name( selection_data->target );
530 if (name) wxLogDebug( wxT("Drop source: format requested: %s"), name );
531 #endif
532
533 drop_source->m_retValue = wxDragCancel;
534
535 wxDataObject *data = drop_source->m_data;
536
537 if (!data)
538 return;
539
540 if (!data->IsSupportedFormat(selection_data->target))
541 return;
542
543 if (data->GetDataSize(selection_data->target) == 0)
544 return;
545
546 size_t size = data->GetDataSize(selection_data->target);
547
548 // printf( "data size: %d.\n", (int)data_size );
549
550 guchar *d = new guchar[size];
551
552 if (!data->GetDataHere( selection_data->target, (void*)d ))
553 {
554 free( d );
555 return;
556 }
557
558 #if wxUSE_THREADS
559 /* disable GUI threads */
560 wxapp_uninstall_thread_wakeup();
561 #endif
562
563 gtk_selection_data_set( selection_data,
564 selection_data->target,
565 8, // 8-bit
566 d,
567 size );
568
569 #if wxUSE_THREADS
570 /* enable GUI threads */
571 wxapp_install_thread_wakeup();
572 #endif
573
574 free( d );
575
576 /* so far only copy, no moves. TODO. */
577 drop_source->m_retValue = wxDragCopy;
578 }
579
580 //----------------------------------------------------------------------------
581 // "drag_data_delete"
582 //----------------------------------------------------------------------------
583
584 static void source_drag_data_delete( GtkWidget *WXUNUSED(widget),
585 GdkDragContext *WXUNUSED(context),
586 wxDropSource *drop_source )
587 {
588 if (g_isIdle) wxapp_install_idle_handler();
589
590 // printf( "Delete the data!\n" );
591
592 drop_source->m_retValue = wxDragMove;
593 }
594
595 //----------------------------------------------------------------------------
596 // "drag_begin"
597 //----------------------------------------------------------------------------
598
599 static void source_drag_begin( GtkWidget *WXUNUSED(widget),
600 GdkDragContext *WXUNUSED(context),
601 wxDropSource *WXUNUSED(drop_source) )
602 {
603 if (g_isIdle) wxapp_install_idle_handler();
604
605 // printf( "drag_begin.\n" );
606 }
607
608 //----------------------------------------------------------------------------
609 // "drag_end"
610 //----------------------------------------------------------------------------
611
612 static void source_drag_end( GtkWidget *WXUNUSED(widget),
613 GdkDragContext *WXUNUSED(context),
614 wxDropSource *drop_source )
615 {
616 if (g_isIdle) wxapp_install_idle_handler();
617
618 // printf( "drag_end.\n" );
619
620 drop_source->m_waiting = FALSE;
621 }
622
623 //---------------------------------------------------------------------------
624 // wxDropSource
625 //---------------------------------------------------------------------------
626
627 wxDropSource::wxDropSource( wxWindow *win, const wxIcon &go, const wxIcon &stop )
628 {
629 g_blockEventsOnDrag = TRUE;
630 m_waiting = TRUE;
631
632 m_window = win;
633 m_widget = win->m_widget;
634 if (win->m_wxwindow) m_widget = win->m_wxwindow;
635
636 m_data = (wxDataObject*) NULL;
637 m_retValue = wxDragCancel;
638
639 m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
640 m_goaheadCursor = wxCursor( wxCURSOR_HAND );
641
642 m_goIcon = go;
643 if (wxNullIcon == go) m_goIcon = wxIcon( page_xpm );
644 m_stopIcon = stop;
645 if (wxNullIcon == stop) m_stopIcon = wxIcon( gv_xpm );
646 }
647
648 wxDropSource::wxDropSource( wxDataObject& data, wxWindow *win,
649 const wxIcon &go, const wxIcon &stop )
650 {
651 m_waiting = TRUE;
652
653 m_window = win;
654 m_widget = win->m_widget;
655 if (win->m_wxwindow) m_widget = win->m_wxwindow;
656 m_retValue = wxDragCancel;
657
658 m_data = &data;
659
660 m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
661 m_goaheadCursor = wxCursor( wxCURSOR_HAND );
662
663 m_goIcon = go;
664 if (wxNullIcon == go) m_goIcon = wxIcon( page_xpm );
665 m_stopIcon = stop;
666 if (wxNullIcon == stop) m_stopIcon = wxIcon( gv_xpm );
667 }
668
669 void wxDropSource::SetData( wxDataObject& data )
670 {
671 if (m_data)
672 delete m_data;
673
674 m_data = &data;
675 }
676
677 wxDropSource::~wxDropSource()
678 {
679 if (m_data)
680 // delete m_data;
681
682 g_blockEventsOnDrag = FALSE;
683 }
684
685 wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
686 {
687 wxASSERT_MSG( m_data, wxT("wxDragSource: no data") );
688
689 if (!m_data)
690 return (wxDragResult) wxDragNone;
691
692 if (m_data->GetFormatCount() == 0)
693 return (wxDragResult) wxDragNone;
694
695 g_blockEventsOnDrag = TRUE;
696
697 RegisterWindow();
698
699 m_waiting = TRUE;
700
701 GtkTargetList *target_list = gtk_target_list_new( (GtkTargetEntry*) NULL, 0 );
702
703 wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ];
704 m_data->GetAllFormats( array, TRUE );
705 for (size_t i = 0; i < m_data->GetFormatCount(); i++)
706 {
707 GdkAtom atom = array[i];
708 wxLogDebug( wxT("Supported atom %s"), gdk_atom_name( atom ) );
709 gtk_target_list_add( target_list, atom, 0, 0 );
710 }
711 delete[] array;
712
713 GdkEventMotion event;
714 event.window = m_widget->window;
715 int x = 0;
716 int y = 0;
717 GdkModifierType state;
718 gdk_window_get_pointer( event.window, &x, &y, &state );
719 event.x = x;
720 event.y = y;
721 event.state = state;
722 event.time = GDK_CURRENT_TIME;
723
724 /* GTK wants to know which button was pressed which caused the dragging */
725 int button_number = 0;
726 if (event.state & GDK_BUTTON1_MASK) button_number = 1;
727 else if (event.state & GDK_BUTTON2_MASK) button_number = 2;
728 else if (event.state & GDK_BUTTON3_MASK) button_number = 3;
729
730 #if wxUSE_THREADS
731 /* disable GUI threads */
732 wxapp_uninstall_thread_wakeup();
733 #endif
734
735 /* don't start dragging if no button is down */
736 if (button_number)
737 {
738 GdkDragContext *context = gtk_drag_begin( m_widget,
739 target_list,
740 GDK_ACTION_COPY,
741 button_number, /* number of mouse button which started drag */
742 (GdkEvent*) &event );
743
744 wxMask *mask = m_goIcon.GetMask();
745 GdkBitmap *bm = (GdkBitmap *) NULL;
746 if (mask) bm = mask->GetBitmap();
747 GdkPixmap *pm = m_goIcon.GetPixmap();
748
749 gtk_drag_set_icon_pixmap( context,
750 gtk_widget_get_colormap( m_widget ),
751 pm,
752 bm,
753 0,
754 0 );
755
756 while (m_waiting) gtk_main_iteration();;
757 }
758
759 #if wxUSE_THREADS
760 /* re-enable GUI threads */
761 wxapp_install_thread_wakeup();
762 #endif
763
764 g_blockEventsOnDrag = FALSE;
765
766 UnregisterWindow();
767
768 return m_retValue;
769 }
770
771 void wxDropSource::RegisterWindow()
772 {
773 if (!m_widget) return;
774
775 gtk_signal_connect( GTK_OBJECT(m_widget), "drag_data_get",
776 GTK_SIGNAL_FUNC (source_drag_data_get), (gpointer) this);
777 gtk_signal_connect (GTK_OBJECT(m_widget), "drag_data_delete",
778 GTK_SIGNAL_FUNC (source_drag_data_delete), (gpointer) this );
779 gtk_signal_connect (GTK_OBJECT(m_widget), "drag_begin",
780 GTK_SIGNAL_FUNC (source_drag_begin), (gpointer) this );
781 gtk_signal_connect (GTK_OBJECT(m_widget), "drag_end",
782 GTK_SIGNAL_FUNC (source_drag_end), (gpointer) this );
783
784 }
785
786 void wxDropSource::UnregisterWindow()
787 {
788 if (!m_widget) return;
789
790 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
791 GTK_SIGNAL_FUNC(source_drag_data_get), (gpointer) this );
792 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
793 GTK_SIGNAL_FUNC(source_drag_data_delete), (gpointer) this );
794 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
795 GTK_SIGNAL_FUNC(source_drag_begin), (gpointer) this );
796 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
797 GTK_SIGNAL_FUNC(source_drag_end), (gpointer) this );
798 }
799
800 #endif
801
802 // wxUSE_DRAG_AND_DROP