Made wxGTK compile and link again. Broke wxMSW a little.
[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 : wxDropTargetBase( data )
354 {
355 m_firstMotion = TRUE;
356 m_dragContext = (GdkDragContext*) NULL;
357 m_dragWidget = (GtkWidget*) NULL;
358 m_dragData = (GtkSelectionData*) NULL;
359 m_dragTime = 0;
360 }
361
362 bool wxDropTarget::OnEnter( int WXUNUSED(x), int WXUNUSED(y) )
363 {
364 if (!m_dataObject)
365 return FALSE;
366
367 return (GetMatchingPair() != (GdkAtom) 0);
368 }
369
370 bool wxDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) )
371 {
372 if (!m_dataObject)
373 return FALSE;
374
375 return (GetMatchingPair() != (GdkAtom) 0);
376 }
377
378 bool wxDropTarget::OnDrop( int WXUNUSED(x), int WXUNUSED(y) )
379 {
380 if (!m_dataObject)
381 return FALSE;
382
383 return (GetMatchingPair() != (GdkAtom) 0);
384 }
385
386 bool wxDropTarget::OnData( int WXUNUSED(x), int WXUNUSED(y) )
387 {
388 if (!m_dataObject)
389 return FALSE;
390
391 if (GetMatchingPair() == (GdkAtom) 0)
392 return FALSE;
393
394 return GetData();
395 }
396
397 GdkAtom wxDropTarget::GetMatchingPair()
398 {
399 if (!m_dataObject)
400 return (GdkAtom) 0;
401
402 if (!m_dragContext)
403 return (GdkAtom) 0;
404
405 GList *child = m_dragContext->targets;
406 while (child)
407 {
408 GdkAtom formatAtom = (GdkAtom) GPOINTER_TO_INT(child->data);
409 wxDataFormat format( formatAtom );
410
411 #ifdef __WXDEBUG__
412 char *name = gdk_atom_name( formatAtom );
413 if (name) wxLogDebug( "Drop target: drag has format: %s", name );
414 #endif
415 if (m_dataObject->IsSupportedFormat( format ))
416 return formatAtom;
417
418 child = child->next;
419 }
420
421 return (GdkAtom) 0;
422 }
423
424 bool wxDropTarget::GetData()
425 {
426 if (!m_dragData)
427 return FALSE;
428
429 if (!m_dataObject)
430 return FALSE;
431
432 wxDataFormat dragFormat( m_dragData->target );
433
434 if (!m_dataObject->IsSupportedFormat( dragFormat ))
435 return FALSE;
436
437 if (dragFormat.GetType() == wxDF_TEXT)
438 {
439 wxTextDataObject *text_object = (wxTextDataObject*)m_dataObject;
440 text_object->SetText( (const char*)m_dragData->data );
441 return TRUE;
442 }
443
444 if (dragFormat.GetType() == wxDF_FILENAME)
445 {
446 wxFileDataObject *file_object = (wxFileDataObject*)m_dataObject;
447 file_object->SetData( 0, (const char*)m_dragData->data );
448 return TRUE;
449 }
450
451 return FALSE;
452 }
453
454 void wxDropTarget::UnregisterWidget( GtkWidget *widget )
455 {
456 wxCHECK_RET( widget != NULL, wxT("unregister widget is NULL") );
457
458 gtk_drag_dest_unset( widget );
459
460 gtk_signal_disconnect_by_func( GTK_OBJECT(widget),
461 GTK_SIGNAL_FUNC(target_drag_leave), (gpointer) this );
462
463 gtk_signal_disconnect_by_func( GTK_OBJECT(widget),
464 GTK_SIGNAL_FUNC(target_drag_motion), (gpointer) this );
465
466 gtk_signal_disconnect_by_func( GTK_OBJECT(widget),
467 GTK_SIGNAL_FUNC(target_drag_drop), (gpointer) this );
468
469 gtk_signal_disconnect_by_func( GTK_OBJECT(widget),
470 GTK_SIGNAL_FUNC(target_drag_data_received), (gpointer) this );
471 }
472
473 void wxDropTarget::RegisterWidget( GtkWidget *widget )
474 {
475 wxCHECK_RET( widget != NULL, wxT("register widget is NULL") );
476
477 /* gtk_drag_dest_set() determines what default behaviour we'd like
478 GTK to supply. we don't want to specify out targets (=formats)
479 or actions in advance (i.e. not GTK_DEST_DEFAULT_MOTION and
480 not GTK_DEST_DEFAULT_DROP). instead we react individually to
481 "drag_motion" and "drag_drop" events. this makes it possible
482 to allow dropping on only a small area. we should set
483 GTK_DEST_DEFAULT_HIGHLIGHT as this will switch on the nice
484 highlighting if dragging over standard controls, but this
485 seems to be broken without the other two. */
486
487 gtk_drag_dest_set( widget,
488 (GtkDestDefaults) 0, /* no default behaviour */
489 (GtkTargetEntry*) NULL, /* we don't supply any formats here */
490 0, /* number of targets = 0 */
491 (GdkDragAction) 0 ); /* we don't supply any actions here */
492
493 gtk_signal_connect( GTK_OBJECT(widget), "drag_leave",
494 GTK_SIGNAL_FUNC(target_drag_leave), (gpointer) this );
495
496 gtk_signal_connect( GTK_OBJECT(widget), "drag_motion",
497 GTK_SIGNAL_FUNC(target_drag_motion), (gpointer) this );
498
499 gtk_signal_connect( GTK_OBJECT(widget), "drag_drop",
500 GTK_SIGNAL_FUNC(target_drag_drop), (gpointer) this );
501
502 gtk_signal_connect( GTK_OBJECT(widget), "drag_data_received",
503 GTK_SIGNAL_FUNC(target_drag_data_received), (gpointer) this );
504 }
505
506 //----------------------------------------------------------------------------
507 // "drag_data_get"
508 //----------------------------------------------------------------------------
509
510 static void
511 source_drag_data_get (GtkWidget *WXUNUSED(widget),
512 GdkDragContext *context,
513 GtkSelectionData *selection_data,
514 guint WXUNUSED(info),
515 guint WXUNUSED(time),
516 wxDropSource *drop_source )
517 {
518 if (g_isIdle) wxapp_install_idle_handler();
519
520 #ifdef __WXDEBUG__
521 char *name = gdk_atom_name( selection_data->target );
522 if (name) wxLogDebug( wxT("Drop source: format requested: %s"), name );
523 #endif
524
525 drop_source->m_retValue = wxDragCancel;
526
527 wxDataObject *data = drop_source->m_data;
528
529 if (!data)
530 return;
531
532 if (!data->IsSupportedFormat(selection_data->target))
533 return;
534
535 if (data->GetDataSize(selection_data->target) == 0)
536 return;
537
538 size_t size = data->GetDataSize(selection_data->target);
539
540 // printf( "data size: %d.\n", (int)data_size );
541
542 guchar *d = new guchar[size];
543
544 if (!data->GetDataHere( selection_data->target, (void*)d ))
545 {
546 free( d );
547 return;
548 }
549
550 #if wxUSE_THREADS
551 /* disable GUI threads */
552 wxapp_uninstall_thread_wakeup();
553 #endif
554
555 gtk_selection_data_set( selection_data,
556 selection_data->target,
557 8, // 8-bit
558 d,
559 size );
560
561 #if wxUSE_THREADS
562 /* enable GUI threads */
563 wxapp_install_thread_wakeup();
564 #endif
565
566 free( d );
567
568 /* so far only copy, no moves. TODO. */
569 drop_source->m_retValue = wxDragCopy;
570 }
571
572 //----------------------------------------------------------------------------
573 // "drag_data_delete"
574 //----------------------------------------------------------------------------
575
576 static void source_drag_data_delete( GtkWidget *WXUNUSED(widget),
577 GdkDragContext *WXUNUSED(context),
578 wxDropSource *drop_source )
579 {
580 if (g_isIdle) wxapp_install_idle_handler();
581
582 // printf( "Delete the data!\n" );
583
584 drop_source->m_retValue = wxDragMove;
585 }
586
587 //----------------------------------------------------------------------------
588 // "drag_begin"
589 //----------------------------------------------------------------------------
590
591 static void source_drag_begin( GtkWidget *WXUNUSED(widget),
592 GdkDragContext *WXUNUSED(context),
593 wxDropSource *WXUNUSED(drop_source) )
594 {
595 if (g_isIdle) wxapp_install_idle_handler();
596
597 // printf( "drag_begin.\n" );
598 }
599
600 //----------------------------------------------------------------------------
601 // "drag_end"
602 //----------------------------------------------------------------------------
603
604 static void source_drag_end( GtkWidget *WXUNUSED(widget),
605 GdkDragContext *WXUNUSED(context),
606 wxDropSource *drop_source )
607 {
608 if (g_isIdle) wxapp_install_idle_handler();
609
610 // printf( "drag_end.\n" );
611
612 drop_source->m_waiting = FALSE;
613 }
614
615 //---------------------------------------------------------------------------
616 // wxDropSource
617 //---------------------------------------------------------------------------
618
619 wxDropSource::wxDropSource( wxWindow *win, const wxIcon &go, const wxIcon &stop )
620 {
621 g_blockEventsOnDrag = TRUE;
622 m_waiting = TRUE;
623
624 m_window = win;
625 m_widget = win->m_widget;
626 if (win->m_wxwindow) m_widget = win->m_wxwindow;
627
628 m_retValue = wxDragCancel;
629
630 m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
631 m_goaheadCursor = wxCursor( wxCURSOR_HAND );
632
633 m_goIcon = go;
634 if (wxNullIcon == go) m_goIcon = wxIcon( page_xpm );
635 m_stopIcon = stop;
636 if (wxNullIcon == stop) m_stopIcon = wxIcon( gv_xpm );
637 }
638
639 wxDropSource::wxDropSource( wxDataObject& data, wxWindow *win,
640 const wxIcon &go, const wxIcon &stop )
641 {
642 m_waiting = TRUE;
643
644 SetData( data );
645
646 m_window = win;
647 m_widget = win->m_widget;
648 if (win->m_wxwindow) m_widget = win->m_wxwindow;
649 m_retValue = wxDragCancel;
650
651 m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
652 m_goaheadCursor = wxCursor( wxCURSOR_HAND );
653
654 m_goIcon = go;
655 if (wxNullIcon == go) m_goIcon = wxIcon( page_xpm );
656 m_stopIcon = stop;
657 if (wxNullIcon == stop) m_stopIcon = wxIcon( gv_xpm );
658 }
659
660 wxDropSource::~wxDropSource()
661 {
662 g_blockEventsOnDrag = FALSE;
663 }
664
665 wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
666 {
667 wxASSERT_MSG( m_data, wxT("wxDragSource: no data") );
668
669 if (!m_data)
670 return (wxDragResult) wxDragNone;
671
672 if (m_data->GetFormatCount() == 0)
673 return (wxDragResult) wxDragNone;
674
675 g_blockEventsOnDrag = TRUE;
676
677 RegisterWindow();
678
679 m_waiting = TRUE;
680
681 GtkTargetList *target_list = gtk_target_list_new( (GtkTargetEntry*) NULL, 0 );
682
683 wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ];
684 m_data->GetAllFormats( array );
685 for (size_t i = 0; i < m_data->GetFormatCount(); i++)
686 {
687 GdkAtom atom = array[i];
688 wxLogDebug( wxT("Supported atom %s"), gdk_atom_name( atom ) );
689 gtk_target_list_add( target_list, atom, 0, 0 );
690 }
691 delete[] array;
692
693 GdkEventMotion event;
694 event.window = m_widget->window;
695 int x = 0;
696 int y = 0;
697 GdkModifierType state;
698 gdk_window_get_pointer( event.window, &x, &y, &state );
699 event.x = x;
700 event.y = y;
701 event.state = state;
702 event.time = GDK_CURRENT_TIME;
703
704 /* GTK wants to know which button was pressed which caused the dragging */
705 int button_number = 0;
706 if (event.state & GDK_BUTTON1_MASK) button_number = 1;
707 else if (event.state & GDK_BUTTON2_MASK) button_number = 2;
708 else if (event.state & GDK_BUTTON3_MASK) button_number = 3;
709
710 #if wxUSE_THREADS
711 /* disable GUI threads */
712 wxapp_uninstall_thread_wakeup();
713 #endif
714
715 /* don't start dragging if no button is down */
716 if (button_number)
717 {
718 GdkDragContext *context = gtk_drag_begin( m_widget,
719 target_list,
720 GDK_ACTION_COPY,
721 button_number, /* number of mouse button which started drag */
722 (GdkEvent*) &event );
723
724 wxMask *mask = m_goIcon.GetMask();
725 GdkBitmap *bm = (GdkBitmap *) NULL;
726 if (mask) bm = mask->GetBitmap();
727 GdkPixmap *pm = m_goIcon.GetPixmap();
728
729 gtk_drag_set_icon_pixmap( context,
730 gtk_widget_get_colormap( m_widget ),
731 pm,
732 bm,
733 0,
734 0 );
735
736 while (m_waiting) gtk_main_iteration();;
737 }
738
739 #if wxUSE_THREADS
740 /* re-enable GUI threads */
741 wxapp_install_thread_wakeup();
742 #endif
743
744 g_blockEventsOnDrag = FALSE;
745
746 UnregisterWindow();
747
748 return m_retValue;
749 }
750
751 void wxDropSource::RegisterWindow()
752 {
753 if (!m_widget) return;
754
755 gtk_signal_connect( GTK_OBJECT(m_widget), "drag_data_get",
756 GTK_SIGNAL_FUNC (source_drag_data_get), (gpointer) this);
757 gtk_signal_connect (GTK_OBJECT(m_widget), "drag_data_delete",
758 GTK_SIGNAL_FUNC (source_drag_data_delete), (gpointer) this );
759 gtk_signal_connect (GTK_OBJECT(m_widget), "drag_begin",
760 GTK_SIGNAL_FUNC (source_drag_begin), (gpointer) this );
761 gtk_signal_connect (GTK_OBJECT(m_widget), "drag_end",
762 GTK_SIGNAL_FUNC (source_drag_end), (gpointer) this );
763
764 }
765
766 void wxDropSource::UnregisterWindow()
767 {
768 if (!m_widget) return;
769
770 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
771 GTK_SIGNAL_FUNC(source_drag_data_get), (gpointer) this );
772 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
773 GTK_SIGNAL_FUNC(source_drag_data_delete), (gpointer) this );
774 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
775 GTK_SIGNAL_FUNC(source_drag_begin), (gpointer) this );
776 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
777 GTK_SIGNAL_FUNC(source_drag_end), (gpointer) this );
778 }
779
780 #endif
781
782 // wxUSE_DRAG_AND_DROP