1 /////////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxDropTarget class 
   4 // Author:      Robert Roebling 
   6 // Copyright:   (c) 1998 Robert Roebling 
   7 // Licence:     wxWindows licence 
   8 /////////////////////////////////////////////////////////////////////////////// 
  10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) 
  11     #pragma implementation "dnd.h" 
  14 // For compilers that support precompilation, includes "wx.h". 
  15 #include "wx/wxprec.h" 
  21 #if wxUSE_DRAG_AND_DROP 
  23 #include "wx/window.h" 
  25 #include "wx/gdicmn.h" 
  29 #include "wx/gtk/private.h" 
  31 #include <gdk/gdkprivate.h> 
  33 #include <gtk/gtkdnd.h> 
  34 #include <gtk/gtkselection.h> 
  36 //----------------------------------------------------------------------------- 
  38 //----------------------------------------------------------------------------- 
  40 extern void wxapp_install_idle_handler(); 
  43 //----------------------------------------------------------------------------- 
  45 //----------------------------------------------------------------------------- 
  50 //---------------------------------------------------------------------------- 
  52 //---------------------------------------------------------------------------- 
  54 extern bool g_blockEventsOnDrag
; 
  56 // the flags used for the last DoDragDrop() 
  57 static long gs_flagsForDrag 
= 0; 
  59 // the trace mask we use with wxLogTrace() - call 
  60 // wxLog::AddTraceMask(TRACE_DND) to enable the trace messages from here 
  61 // (there are quite a few of them, so don't enable this by default) 
  62 static const wxChar 
*TRACE_DND 
= _T("dnd"); 
  64 //---------------------------------------------------------------------------- 
  66 //---------------------------------------------------------------------------- 
  69 static const char * page_xpm
[] = { 
  70 /* width height ncolors chars_per_pixel */ 
  79 "    ...................         ", 
  80 "    .XXXXXXXXXXXXXXXXX..        ", 
  81 "    .XXXXXXXXXXXXXXXXX.o.       ", 
  82 "    .XXXXXXXXXXXXXXXXX.oo.      ", 
  83 "    .XXXXXXXXXXXXXXXXX.ooo.     ", 
  84 "    .XXXXXXXXXXXXXXXXX.oooo.    ", 
  85 "    .XXXXXXXXXXXXXXXXX.......   ", 
  86 "    .XXXXXOOOOOOOOOOXXXooooo.   ", 
  87 "    .XXXXXXXXXXXXXXXXXXooooo.   ", 
  88 "    .XXXXXOOOOOOOOOOXXXXXXXX.   ", 
  89 "    .XXXXXXXXXXXXXXXXXXXXXXX.   ", 
  90 "    .XXXXXXXOOOOOOOOOXXXXXXX.   ", 
  91 "    .XXXXXXXXXXXXXXXXXXXXXXX.   ", 
  92 "    .XXXXXXOOOOOOOOOOXXXXXXX.   ", 
  93 "    .XXXXXXXXXXXXXXXXXXXXXXX.   ", 
  94 "    .XXXXXOOOOOOOOOOXXXXXXXX.   ", 
  95 "    .XXXXXXXXXXXXXXXXXXXXXXX.   ", 
  96 "    .XXXXXXXOOOOOOOOOXXXXXXX.   ", 
  97 "    .XXXXXXXXXXXXXXXXXXXXXXX.   ", 
  98 "    .XXXXXXOOOOOOOOOOXXXXXXX.   ", 
  99 "    .XXXXXXXXXXXXXXXXXXXXXXX.   ", 
 100 "    .XXXXXOOOOOOOOOOXXXXXXXX.   ", 
 101 "    .XXXXXXXXXXXXXXXXXXXXXXX.   ", 
 102 "    .XXXXXXOOOOOOOOOOXXXXXXX.   ", 
 103 "    .XXXXXXXXXXXXXXXXXXXXXXX.   ", 
 104 "    .XXXXXOOOOOOOXXXXXXXXXXX.   ", 
 105 "    .XXXXXXXXXXXXXXXXXXXXXXX.   ", 
 106 "    .XXXXXXXXXXXXXXXXXXXXXXX.   ", 
 107 "    .XXXXXXXXXXXXXXXXXXXXXXX.   ", 
 108 "    .XXXXXXXXXXXXXXXXXXXXXXX.   ", 
 109 "    .XXXXXXXXXXXXXXXXXXXXXXX.   ", 
 110 "    .........................   "}; 
 113 // ============================================================================ 
 115 // ============================================================================ 
 117 // ---------------------------------------------------------------------------- 
 118 // convert between GTK+ and wxWindows DND constants 
 119 // ---------------------------------------------------------------------------- 
 121 static wxDragResult 
ConvertFromGTK(long action
) 
 125         case GDK_ACTION_COPY
: 
 128         case GDK_ACTION_LINK
: 
 131         case GDK_ACTION_MOVE
: 
 138 // ---------------------------------------------------------------------------- 
 140 // ---------------------------------------------------------------------------- 
 142 static void target_drag_leave( GtkWidget 
*WXUNUSED(widget
), 
 143                                GdkDragContext 
*context
, 
 144                                guint 
WXUNUSED(time
), 
 145                                wxDropTarget 
*drop_target 
) 
 147     if (g_isIdle
) wxapp_install_idle_handler(); 
 149     /* inform the wxDropTarget about the current GdkDragContext. 
 150        this is only valid for the duration of this call */ 
 151     drop_target
->SetDragContext( context 
); 
 153     /* we don't need return values. this event is just for 
 155     drop_target
->OnLeave(); 
 157     /* this has to be done because GDK has no "drag_enter" event */ 
 158     drop_target
->m_firstMotion 
= TRUE
; 
 160     /* after this, invalidate the drop_target's GdkDragContext */ 
 161     drop_target
->SetDragContext( (GdkDragContext
*) NULL 
); 
 164 // ---------------------------------------------------------------------------- 
 166 // ---------------------------------------------------------------------------- 
 168 static gboolean 
target_drag_motion( GtkWidget 
*WXUNUSED(widget
), 
 169                                     GdkDragContext 
*context
, 
 173                                     wxDropTarget 
*drop_target 
) 
 175     if (g_isIdle
) wxapp_install_idle_handler(); 
 177     /* Owen Taylor: "if the coordinates not in a drop zone, 
 178        return FALSE, otherwise call gtk_drag_status() and 
 181     /* inform the wxDropTarget about the current GdkDragContext. 
 182        this is only valid for the duration of this call */ 
 183     drop_target
->SetDragContext( context 
); 
 185     // GTK+ always supposes that we want to copy the data by default while we 
 186     // might want to move it, so examine not only suggested_action - which is 
 187     // only good if we don't have our own preferences - but also the actions 
 190     if ( (gs_flagsForDrag 
& wxDrag_DefaultMove
) == wxDrag_DefaultMove 
&& 
 191             (context
->actions 
& GDK_ACTION_MOVE 
) ) 
 193         // move is requested by the program and allowed by GTK+ - do it, even 
 194         // though suggested_action may be currently wxDragCopy 
 197     else // use whatever GTK+ says we should 
 199         result 
= ConvertFromGTK(context
->suggested_action
); 
 201         if ( (result 
== wxDragMove
) && !(gs_flagsForDrag 
& wxDrag_AllowMove
) ) 
 203             // we're requested to move but we can't 
 208     if (drop_target
->m_firstMotion
) 
 210         /* the first "drag_motion" event substitutes a "drag_enter" event */ 
 211         result 
= drop_target
->OnEnter( x
, y
, result 
); 
 215         /* give program a chance to react (i.e. to say no by returning FALSE) */ 
 216         result 
= drop_target
->OnDragOver( x
, y
, result 
); 
 219     bool ret 
= wxIsDragResultOk( result 
); 
 222         GdkDragAction action
; 
 223         if (result 
== wxDragCopy
) 
 224             action 
= GDK_ACTION_COPY
; 
 225         else if (result 
== wxDragLink
) 
 226             action 
= GDK_ACTION_LINK
; 
 228             action 
= GDK_ACTION_MOVE
; 
 230         gdk_drag_status( context
, action
, time 
); 
 233     /* after this, invalidate the drop_target's GdkDragContext */ 
 234     drop_target
->SetDragContext( (GdkDragContext
*) NULL 
); 
 236     /* this has to be done because GDK has no "drag_enter" event */ 
 237     drop_target
->m_firstMotion 
= FALSE
; 
 242 // ---------------------------------------------------------------------------- 
 244 // ---------------------------------------------------------------------------- 
 246 static gboolean 
target_drag_drop( GtkWidget 
*widget
, 
 247                                   GdkDragContext 
*context
, 
 251                                   wxDropTarget 
*drop_target 
) 
 253     if (g_isIdle
) wxapp_install_idle_handler(); 
 255     /* Owen Taylor: "if the drop is not in a drop zone, 
 256        return FALSE, otherwise, if you aren't accepting 
 257        the drop, call gtk_drag_finish() with success == FALSE 
 258        otherwise call gtk_drag_data_get()" */ 
 260 //    printf( "drop.\n" ); 
 262     /* this seems to make a difference between not accepting 
 263        due to wrong target area and due to wrong format. let 
 264        us hope that this is not required.. */ 
 266     /* inform the wxDropTarget about the current GdkDragContext. 
 267        this is only valid for the duration of this call */ 
 268     drop_target
->SetDragContext( context 
); 
 270     /* inform the wxDropTarget about the current drag widget. 
 271        this is only valid for the duration of this call */ 
 272     drop_target
->SetDragWidget( widget 
); 
 274     /* inform the wxDropTarget about the current drag time. 
 275        this is only valid for the duration of this call */ 
 276     drop_target
->SetDragTime( time 
); 
 279     wxDragResult result = wxDragMove; 
 280     if (context->suggested_action == GDK_ACTION_COPY) result = wxDragCopy; 
 283     /* reset the block here as someone might very well 
 284        show a dialog as a reaction to a drop and this 
 285        wouldn't work without events */ 
 286     g_blockEventsOnDrag 
= FALSE
; 
 288     bool ret 
= drop_target
->OnDrop( x
, y 
); 
 292         wxLogTrace(TRACE_DND
, wxT( "Drop target: OnDrop returned FALSE") ); 
 294         /* cancel the whole thing */ 
 295         gtk_drag_finish( context
, 
 296                           FALSE
,        /* no success */ 
 297                           FALSE
,        /* don't delete data on dropping side */ 
 302         wxLogTrace(TRACE_DND
, wxT( "Drop target: OnDrop returned TRUE") ); 
 305         /* disable GUI threads */ 
 308         GdkAtom format 
= drop_target
->GetMatchingPair(); 
 310         // this does happen somehow, see bug 555111 
 311         wxCHECK_MSG( format
, FALSE
, _T("no matching GdkAtom for format?") ) 
 314         GdkDragAction action = GDK_ACTION_MOVE; 
 315         if (result == wxDragCopy) action == GDK_ACTION_COPY; 
 316         context->action = action; 
 318         /* this should trigger an "drag_data_received" event */ 
 319         gtk_drag_get_data( widget
, 
 325         /* re-enable GUI threads */ 
 329     /* after this, invalidate the drop_target's GdkDragContext */ 
 330     drop_target
->SetDragContext( (GdkDragContext
*) NULL 
); 
 332     /* after this, invalidate the drop_target's drag widget */ 
 333     drop_target
->SetDragWidget( (GtkWidget
*) NULL 
); 
 335     /* this has to be done because GDK has no "drag_enter" event */ 
 336     drop_target
->m_firstMotion 
= TRUE
; 
 341 // ---------------------------------------------------------------------------- 
 342 // "drag_data_received" 
 343 // ---------------------------------------------------------------------------- 
 345 static void target_drag_data_received( GtkWidget 
*WXUNUSED(widget
), 
 346                                        GdkDragContext 
*context
, 
 349                                        GtkSelectionData 
*data
, 
 350                                        guint 
WXUNUSED(info
), 
 352                                        wxDropTarget 
*drop_target 
) 
 354     if (g_isIdle
) wxapp_install_idle_handler(); 
 356     /* Owen Taylor: "call gtk_drag_finish() with 
 359     if ((data
->length 
<= 0) || (data
->format 
!= 8)) 
 361         /* negative data length and non 8-bit data format 
 362            qualifies for junk */ 
 363         gtk_drag_finish (context
, FALSE
, FALSE
, time
); 
 368     wxLogTrace(TRACE_DND
, wxT( "Drop target: data received event") ); 
 370     /* inform the wxDropTarget about the current GtkSelectionData. 
 371        this is only valid for the duration of this call */ 
 372     drop_target
->SetDragData( data 
); 
 374     wxDragResult result 
= ConvertFromGTK(context
->suggested_action
); 
 376     if ( wxIsDragResultOk( drop_target
->OnData( x
, y
, result 
) ) ) 
 378         wxLogTrace(TRACE_DND
, wxT( "Drop target: OnData returned TRUE") ); 
 380         /* tell GTK that data transfer was successfull */ 
 381         gtk_drag_finish( context
, TRUE
, FALSE
, time 
); 
 385         wxLogTrace(TRACE_DND
, wxT( "Drop target: OnData returned FALSE") ); 
 387         /* tell GTK that data transfer was not successfull */ 
 388         gtk_drag_finish( context
, FALSE
, FALSE
, time 
); 
 391     /* after this, invalidate the drop_target's drag data */ 
 392     drop_target
->SetDragData( (GtkSelectionData
*) NULL 
); 
 395 //---------------------------------------------------------------------------- 
 397 //---------------------------------------------------------------------------- 
 399 wxDropTarget::wxDropTarget( wxDataObject 
*data 
) 
 400             : wxDropTargetBase( data 
) 
 402     m_firstMotion 
= TRUE
; 
 403     m_dragContext 
= (GdkDragContext
*) NULL
; 
 404     m_dragWidget 
= (GtkWidget
*) NULL
; 
 405     m_dragData 
= (GtkSelectionData
*) NULL
; 
 409 wxDragResult 
wxDropTarget::OnDragOver( wxCoord 
WXUNUSED(x
), 
 413     // GetMatchingPair() checks for m_dataObject too, no need to do it here 
 415     // disable the debug message from GetMatchingPair() - there are too many 
 421     return (GetMatchingPair() != (GdkAtom
) 0) ? def 
: wxDragNone
; 
 424 bool wxDropTarget::OnDrop( wxCoord 
WXUNUSED(x
), wxCoord 
WXUNUSED(y
) ) 
 429     return (GetMatchingPair() != (GdkAtom
) 0); 
 432 wxDragResult 
wxDropTarget::OnData( wxCoord 
WXUNUSED(x
), wxCoord 
WXUNUSED(y
), 
 438     if (GetMatchingPair() == (GdkAtom
) 0) 
 441     return GetData() ? def 
: wxDragNone
; 
 444 GdkAtom 
wxDropTarget::GetMatchingPair() 
 452     GList 
*child 
= m_dragContext
->targets
; 
 455         GdkAtom formatAtom 
= (GdkAtom
) GPOINTER_TO_INT(child
->data
); 
 456         wxDataFormat 
format( formatAtom 
); 
 459         wxLogTrace(TRACE_DND
, wxT("Drop target: drag has format: %s"), 
 460                    format
.GetId().c_str()); 
 463         if (m_dataObject
->IsSupportedFormat( format 
)) 
 472 bool wxDropTarget::GetData() 
 480     wxDataFormat 
dragFormat( m_dragData
->target 
); 
 482     if (!m_dataObject
->IsSupportedFormat( dragFormat 
)) 
 485     m_dataObject
->SetData( dragFormat
, (size_t)m_dragData
->length
, (const void*)m_dragData
->data 
); 
 490 void wxDropTarget::UnregisterWidget( GtkWidget 
*widget 
) 
 492     wxCHECK_RET( widget 
!= NULL
, wxT("unregister widget is NULL") ); 
 494     gtk_drag_dest_unset( widget 
); 
 496     gtk_signal_disconnect_by_func( GTK_OBJECT(widget
), 
 497                       GTK_SIGNAL_FUNC(target_drag_leave
), (gpointer
) this ); 
 499     gtk_signal_disconnect_by_func( GTK_OBJECT(widget
), 
 500                       GTK_SIGNAL_FUNC(target_drag_motion
), (gpointer
) this ); 
 502     gtk_signal_disconnect_by_func( GTK_OBJECT(widget
), 
 503                       GTK_SIGNAL_FUNC(target_drag_drop
), (gpointer
) this ); 
 505     gtk_signal_disconnect_by_func( GTK_OBJECT(widget
), 
 506                       GTK_SIGNAL_FUNC(target_drag_data_received
), (gpointer
) this ); 
 509 void wxDropTarget::RegisterWidget( GtkWidget 
*widget 
) 
 511     wxCHECK_RET( widget 
!= NULL
, wxT("register widget is NULL") ); 
 513     /* gtk_drag_dest_set() determines what default behaviour we'd like 
 514        GTK to supply. we don't want to specify out targets (=formats) 
 515        or actions in advance (i.e. not GTK_DEST_DEFAULT_MOTION and 
 516        not GTK_DEST_DEFAULT_DROP). instead we react individually to 
 517        "drag_motion" and "drag_drop" events. this makes it possible 
 518        to allow dropping on only a small area. we should set 
 519        GTK_DEST_DEFAULT_HIGHLIGHT as this will switch on the nice 
 520        highlighting if dragging over standard controls, but this 
 521        seems to be broken without the other two. */ 
 523     gtk_drag_dest_set( widget
, 
 524                        (GtkDestDefaults
) 0,         /* no default behaviour */ 
 525                        (GtkTargetEntry
*) NULL
,      /* we don't supply any formats here */ 
 526                        0,                           /* number of targets = 0 */ 
 527                        (GdkDragAction
) 0 );         /* we don't supply any actions here */ 
 529     gtk_signal_connect( GTK_OBJECT(widget
), "drag_leave", 
 530                       GTK_SIGNAL_FUNC(target_drag_leave
), (gpointer
) this ); 
 532     gtk_signal_connect( GTK_OBJECT(widget
), "drag_motion", 
 533                       GTK_SIGNAL_FUNC(target_drag_motion
), (gpointer
) this ); 
 535     gtk_signal_connect( GTK_OBJECT(widget
), "drag_drop", 
 536                       GTK_SIGNAL_FUNC(target_drag_drop
), (gpointer
) this ); 
 538     gtk_signal_connect( GTK_OBJECT(widget
), "drag_data_received", 
 539                       GTK_SIGNAL_FUNC(target_drag_data_received
), (gpointer
) this ); 
 542 //---------------------------------------------------------------------------- 
 544 //---------------------------------------------------------------------------- 
 547 source_drag_data_get  (GtkWidget          
*WXUNUSED(widget
), 
 548                        GdkDragContext     
*WXUNUSED(context
), 
 549                        GtkSelectionData   
*selection_data
, 
 550                        guint               
WXUNUSED(info
), 
 551                        guint               
WXUNUSED(time
), 
 552                        wxDropSource       
*drop_source 
) 
 554     if (g_isIdle
) wxapp_install_idle_handler(); 
 556     wxDataFormat 
format( selection_data
->target 
); 
 558     wxLogTrace(TRACE_DND
, wxT("Drop source: format requested: %s"), 
 559                format
.GetId().c_str()); 
 561     drop_source
->m_retValue 
= wxDragCancel
; 
 563     wxDataObject 
*data 
= drop_source
->GetDataObject(); 
 567         wxLogTrace(TRACE_DND
, wxT("Drop source: no data object") ); 
 571     if (!data
->IsSupportedFormat(format
)) 
 573         wxLogTrace(TRACE_DND
, wxT("Drop source: unsupported format") ); 
 577     if (data
->GetDataSize(format
) == 0) 
 579         wxLogTrace(TRACE_DND
, wxT("Drop source: empty data") ); 
 583     size_t size 
= data
->GetDataSize(format
); 
 585 //  printf( "data size: %d.\n", (int)data_size ); 
 587     guchar 
*d 
= new guchar
[size
]; 
 589     if (!data
->GetDataHere( format
, (void*)d 
)) 
 596     /* disable GUI threads */ 
 599                 gtk_selection_data_set( selection_data
, 
 600                                         selection_data
->target
, 
 606     /* enable GUI threads */ 
 612 //---------------------------------------------------------------------------- 
 613 // "drag_data_delete" 
 614 //---------------------------------------------------------------------------- 
 616 static void source_drag_data_delete( GtkWidget 
*WXUNUSED(widget
), 
 617                                      GdkDragContext 
*context
, 
 618                                      wxDropSource 
*WXUNUSED(drop_source
) ) 
 621         wxapp_install_idle_handler(); 
 623     // printf( "Drag source: drag_data_delete\n" ); 
 626 //---------------------------------------------------------------------------- 
 628 //---------------------------------------------------------------------------- 
 630 static void source_drag_begin( GtkWidget          
*WXUNUSED(widget
), 
 631                                GdkDragContext     
*WXUNUSED(context
), 
 632                                wxDropSource       
*WXUNUSED(drop_source
) ) 
 635         wxapp_install_idle_handler(); 
 637     // printf( "Drag source: drag_begin.\n" ); 
 640 //---------------------------------------------------------------------------- 
 642 //---------------------------------------------------------------------------- 
 644 static void source_drag_end( GtkWidget          
*WXUNUSED(widget
), 
 645                              GdkDragContext     
*WXUNUSED(context
), 
 646                              wxDropSource       
*drop_source 
) 
 648     if (g_isIdle
) wxapp_install_idle_handler(); 
 650     // printf( "Drag source: drag_end.\n" ); 
 652     drop_source
->m_waiting 
= FALSE
; 
 655 //----------------------------------------------------------------------------- 
 656 // "configure_event" from m_iconWindow 
 657 //----------------------------------------------------------------------------- 
 660 gtk_dnd_window_configure_callback( GtkWidget 
*WXUNUSED(widget
), GdkEventConfigure 
*WXUNUSED(event
), wxDropSource 
*source 
) 
 663         wxapp_install_idle_handler(); 
 665     source
->GiveFeedback( ConvertFromGTK(source
->m_dragContext
->action
) ); 
 670 //--------------------------------------------------------------------------- 
 672 //--------------------------------------------------------------------------- 
 674 wxDropSource::wxDropSource(wxWindow 
*win
, 
 675                            const wxIcon 
&iconCopy
, 
 676                            const wxIcon 
&iconMove
, 
 677                            const wxIcon 
&iconNone
) 
 681     m_iconWindow 
= (GtkWidget
*) NULL
; 
 684     m_widget 
= win
->m_widget
; 
 685     if (win
->m_wxwindow
) m_widget 
= win
->m_wxwindow
; 
 687     m_retValue 
= wxDragCancel
; 
 689     SetIcons(iconCopy
, iconMove
, iconNone
); 
 692 wxDropSource::wxDropSource(wxDataObject
& data
, 
 694                            const wxIcon 
&iconCopy
, 
 695                            const wxIcon 
&iconMove
, 
 696                            const wxIcon 
&iconNone
) 
 702     m_iconWindow 
= (GtkWidget
*) NULL
; 
 705     m_widget 
= win
->m_widget
; 
 706     if (win
->m_wxwindow
) m_widget 
= win
->m_wxwindow
; 
 708     m_retValue 
= wxDragCancel
; 
 710     SetIcons(iconCopy
, iconMove
, iconNone
); 
 713 void wxDropSource::SetIcons(const wxIcon 
&iconCopy
, 
 714                             const wxIcon 
&iconMove
, 
 715                             const wxIcon 
&iconNone
) 
 717     m_iconCopy 
= iconCopy
; 
 718     m_iconMove 
= iconMove
; 
 719     m_iconNone 
= iconNone
; 
 721     if ( !m_iconCopy
.Ok() ) 
 722         m_iconCopy 
= wxIcon(page_xpm
); 
 723     if ( !m_iconMove
.Ok() ) 
 724         m_iconMove 
= m_iconCopy
; 
 725     if ( !m_iconNone
.Ok() ) 
 726         m_iconNone 
= m_iconCopy
; 
 729 wxDropSource::~wxDropSource() 
 733 void wxDropSource::PrepareIcon( int action
, GdkDragContext 
*context 
) 
 735     // get the right icon to display 
 737     if ( action 
& GDK_ACTION_MOVE 
) 
 739     else if ( action 
& GDK_ACTION_COPY 
) 
 745     if ( icon
->GetMask() ) 
 746         mask 
= icon
->GetMask()->GetBitmap(); 
 748         mask 
= (GdkBitmap 
*)NULL
; 
 750     GdkPixmap 
*pixmap 
= icon
->GetPixmap(); 
 753     gdk_window_get_size (pixmap
, &width
, &height
); 
 755     GdkColormap 
*colormap 
= gtk_widget_get_colormap( m_widget 
); 
 757     gtk_widget_push_visual (gdk_colormap_get_visual (colormap
)); 
 759     gtk_widget_push_colormap (colormap
); 
 761     m_iconWindow 
= gtk_window_new (GTK_WINDOW_POPUP
); 
 762     gtk_widget_set_events (m_iconWindow
, GDK_BUTTON_PRESS_MASK 
| GDK_BUTTON_RELEASE_MASK
); 
 763     gtk_widget_set_app_paintable (GTK_WIDGET (m_iconWindow
), TRUE
); 
 766     gtk_widget_pop_visual (); 
 768     gtk_widget_pop_colormap (); 
 770     gtk_widget_set_usize (m_iconWindow
, width
, height
); 
 771     gtk_widget_realize (m_iconWindow
); 
 773     gtk_signal_connect( GTK_OBJECT(m_iconWindow
), "configure_event", 
 774         GTK_SIGNAL_FUNC(gtk_dnd_window_configure_callback
), (gpointer
)this ); 
 776     gdk_window_set_back_pixmap (m_iconWindow
->window
, pixmap
, FALSE
); 
 779         gtk_widget_shape_combine_mask (m_iconWindow
, mask
, 0, 0); 
 781     gtk_drag_set_icon_widget( context
, m_iconWindow
, 0, 0 ); 
 784 wxDragResult 
wxDropSource::DoDragDrop(int flags
) 
 786     wxCHECK_MSG( m_data 
&& m_data
->GetFormatCount(), wxDragNone
, 
 787                  wxT("Drop source: no data") ); 
 790     if (g_blockEventsOnDrag
) 
 794     g_blockEventsOnDrag 
= TRUE
; 
 800     GtkTargetList 
*target_list 
= gtk_target_list_new( (GtkTargetEntry
*) NULL
, 0 ); 
 802     wxDataFormat 
*array 
= new wxDataFormat
[ m_data
->GetFormatCount() ]; 
 803     m_data
->GetAllFormats( array 
); 
 804     size_t count 
= m_data
->GetFormatCount(); 
 805     for (size_t i 
= 0; i 
< count
; i
++) 
 807         GdkAtom atom 
= array
[i
]; 
 808         wxLogTrace(TRACE_DND
, wxT("Drop source: Supported atom %s"), gdk_atom_name( atom 
)); 
 809         gtk_target_list_add( target_list
, atom
, 0, 0 ); 
 813     GdkEventMotion event
; 
 814     event
.window 
= m_widget
->window
; 
 817     GdkModifierType state
; 
 818     gdk_window_get_pointer( event
.window
, &x
, &y
, &state 
); 
 822     event
.time 
= (guint32
)GDK_CURRENT_TIME
; 
 824     /* GTK wants to know which button was pressed which caused the dragging */ 
 825     int button_number 
= 0; 
 826     if (event
.state 
& GDK_BUTTON1_MASK
) button_number 
= 1; 
 827     else if (event
.state 
& GDK_BUTTON2_MASK
) button_number 
= 2; 
 828     else if (event
.state 
& GDK_BUTTON3_MASK
) button_number 
= 3; 
 831     /* disable GUI threads */ 
 834     /* don't start dragging if no button is down */ 
 837         int action 
= GDK_ACTION_COPY
; 
 838         if ( flags 
& wxDrag_AllowMove 
) 
 839             action 
|= GDK_ACTION_MOVE
; 
 841         // VZ: as we already use g_blockEventsOnDrag it shouldn't be that bad 
 842         //     to use a global to pass the flags to the drop target but I'd 
 843         //     surely prefer a better way to do it 
 844         gs_flagsForDrag 
= flags
; 
 846         GdkDragContext 
*context 
= gtk_drag_begin( m_widget
, 
 848                 (GdkDragAction
)action
, 
 849                 button_number
,  /* number of mouse button which started drag */ 
 850                 (GdkEvent
*) &event 
); 
 852         m_dragContext 
= context
; 
 854         PrepareIcon( action
, context 
); 
 857             gtk_main_iteration(); 
 859         m_retValue 
= ConvertFromGTK(context
->action
); 
 860         if ( m_retValue 
== wxDragNone 
) 
 861             m_retValue 
= wxDragCancel
; 
 865     /* re-enable GUI threads */ 
 868     g_blockEventsOnDrag 
= FALSE
; 
 875 void wxDropSource::RegisterWindow() 
 877     if (!m_widget
) return; 
 879     gtk_signal_connect( GTK_OBJECT(m_widget
), "drag_data_get", 
 880                       GTK_SIGNAL_FUNC (source_drag_data_get
), (gpointer
) this); 
 881     gtk_signal_connect (GTK_OBJECT(m_widget
), "drag_data_delete", 
 882                       GTK_SIGNAL_FUNC (source_drag_data_delete
),  (gpointer
) this ); 
 883     gtk_signal_connect (GTK_OBJECT(m_widget
), "drag_begin", 
 884                       GTK_SIGNAL_FUNC (source_drag_begin
),  (gpointer
) this ); 
 885     gtk_signal_connect (GTK_OBJECT(m_widget
), "drag_end", 
 886                       GTK_SIGNAL_FUNC (source_drag_end
),  (gpointer
) this ); 
 890 void wxDropSource::UnregisterWindow() 
 892     if (!m_widget
) return; 
 894     gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
), 
 895                       GTK_SIGNAL_FUNC(source_drag_data_get
), (gpointer
) this ); 
 896     gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
), 
 897                       GTK_SIGNAL_FUNC(source_drag_data_delete
), (gpointer
) this ); 
 898     gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
), 
 899                       GTK_SIGNAL_FUNC(source_drag_begin
), (gpointer
) this ); 
 900     gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
), 
 901                       GTK_SIGNAL_FUNC(source_drag_end
), (gpointer
) this ); 
 905       // wxUSE_DRAG_AND_DROP