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 wxWidgets 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 (drop_target
->GetDefaultAction() == wxDragNone
) 
 192         // use default action set by wxDropSource::DoDragDrop() 
 193     if ( (gs_flagsForDrag 
& wxDrag_DefaultMove
) == wxDrag_DefaultMove 
&& 
 194             (context
->actions 
& GDK_ACTION_MOVE 
) ) 
 196         // move is requested by the program and allowed by GTK+ - do it, even 
 197         // though suggested_action may be currently wxDragCopy 
 200     else // use whatever GTK+ says we should 
 202         result 
= ConvertFromGTK(context
->suggested_action
); 
 204         if ( (result 
== wxDragMove
) && !(gs_flagsForDrag 
& wxDrag_AllowMove
) ) 
 206             // we're requested to move but we can't 
 211     else if (drop_target
->GetDefaultAction() == wxDragMove 
&& 
 212                 (context
->actions 
& GDK_ACTION_MOVE
)) 
 218         if (context
->actions 
& GDK_ACTION_COPY
) 
 220         else if (context
->actions 
& GDK_ACTION_MOVE
) 
 226     if (drop_target
->m_firstMotion
) 
 228         /* the first "drag_motion" event substitutes a "drag_enter" event */ 
 229         result 
= drop_target
->OnEnter( x
, y
, result 
); 
 233         /* give program a chance to react (i.e. to say no by returning FALSE) */ 
 234         result 
= drop_target
->OnDragOver( x
, y
, result 
); 
 237     bool ret 
= wxIsDragResultOk( result 
); 
 240         GdkDragAction action
; 
 241         if (result 
== wxDragCopy
) 
 242             action 
= GDK_ACTION_COPY
; 
 243         else if (result 
== wxDragLink
) 
 244             action 
= GDK_ACTION_LINK
; 
 246             action 
= GDK_ACTION_MOVE
; 
 248         gdk_drag_status( context
, action
, time 
); 
 251     /* after this, invalidate the drop_target's GdkDragContext */ 
 252     drop_target
->SetDragContext( (GdkDragContext
*) NULL 
); 
 254     /* this has to be done because GDK has no "drag_enter" event */ 
 255     drop_target
->m_firstMotion 
= FALSE
; 
 260 // ---------------------------------------------------------------------------- 
 262 // ---------------------------------------------------------------------------- 
 264 static gboolean 
target_drag_drop( GtkWidget 
*widget
, 
 265                                   GdkDragContext 
*context
, 
 269                                   wxDropTarget 
*drop_target 
) 
 271     if (g_isIdle
) wxapp_install_idle_handler(); 
 273     /* Owen Taylor: "if the drop is not in a drop zone, 
 274        return FALSE, otherwise, if you aren't accepting 
 275        the drop, call gtk_drag_finish() with success == FALSE 
 276        otherwise call gtk_drag_data_get()" */ 
 278 //    printf( "drop.\n" ); 
 280     /* this seems to make a difference between not accepting 
 281        due to wrong target area and due to wrong format. let 
 282        us hope that this is not required.. */ 
 284     /* inform the wxDropTarget about the current GdkDragContext. 
 285        this is only valid for the duration of this call */ 
 286     drop_target
->SetDragContext( context 
); 
 288     /* inform the wxDropTarget about the current drag widget. 
 289        this is only valid for the duration of this call */ 
 290     drop_target
->SetDragWidget( widget 
); 
 292     /* inform the wxDropTarget about the current drag time. 
 293        this is only valid for the duration of this call */ 
 294     drop_target
->SetDragTime( time 
); 
 297     wxDragResult result = wxDragMove; 
 298     if (context->suggested_action == GDK_ACTION_COPY) result = wxDragCopy; 
 301     /* reset the block here as someone might very well 
 302        show a dialog as a reaction to a drop and this 
 303        wouldn't work without events */ 
 304     g_blockEventsOnDrag 
= FALSE
; 
 306     bool ret 
= drop_target
->OnDrop( x
, y 
); 
 310         wxLogTrace(TRACE_DND
, wxT( "Drop target: OnDrop returned FALSE") ); 
 312         /* cancel the whole thing */ 
 313         gtk_drag_finish( context
, 
 314                           FALSE
,        /* no success */ 
 315                           FALSE
,        /* don't delete data on dropping side */ 
 320         wxLogTrace(TRACE_DND
, wxT( "Drop target: OnDrop returned TRUE") ); 
 323         /* disable GUI threads */ 
 326         GdkAtom format 
= drop_target
->GetMatchingPair(); 
 328         // this does happen somehow, see bug 555111 
 329         wxCHECK_MSG( format
, FALSE
, _T("no matching GdkAtom for format?") ) 
 332         GdkDragAction action = GDK_ACTION_MOVE; 
 333         if (result == wxDragCopy) action == GDK_ACTION_COPY; 
 334         context->action = action; 
 336         /* this should trigger an "drag_data_received" event */ 
 337         gtk_drag_get_data( widget
, 
 343         /* re-enable GUI threads */ 
 347     /* after this, invalidate the drop_target's GdkDragContext */ 
 348     drop_target
->SetDragContext( (GdkDragContext
*) NULL 
); 
 350     /* after this, invalidate the drop_target's drag widget */ 
 351     drop_target
->SetDragWidget( (GtkWidget
*) NULL 
); 
 353     /* this has to be done because GDK has no "drag_enter" event */ 
 354     drop_target
->m_firstMotion 
= TRUE
; 
 359 // ---------------------------------------------------------------------------- 
 360 // "drag_data_received" 
 361 // ---------------------------------------------------------------------------- 
 363 static void target_drag_data_received( GtkWidget 
*WXUNUSED(widget
), 
 364                                        GdkDragContext 
*context
, 
 367                                        GtkSelectionData 
*data
, 
 368                                        guint 
WXUNUSED(info
), 
 370                                        wxDropTarget 
*drop_target 
) 
 372     if (g_isIdle
) wxapp_install_idle_handler(); 
 374     /* Owen Taylor: "call gtk_drag_finish() with 
 377     if ((data
->length 
<= 0) || (data
->format 
!= 8)) 
 379         /* negative data length and non 8-bit data format 
 380            qualifies for junk */ 
 381         gtk_drag_finish (context
, FALSE
, FALSE
, time
); 
 386     wxLogTrace(TRACE_DND
, wxT( "Drop target: data received event") ); 
 388     /* inform the wxDropTarget about the current GtkSelectionData. 
 389        this is only valid for the duration of this call */ 
 390     drop_target
->SetDragData( data 
); 
 392     wxDragResult result 
= ConvertFromGTK(context
->action
); 
 394     if ( wxIsDragResultOk( drop_target
->OnData( x
, y
, result 
) ) ) 
 396         wxLogTrace(TRACE_DND
, wxT( "Drop target: OnData returned TRUE") ); 
 398         /* tell GTK that data transfer was successfull */ 
 399         gtk_drag_finish( context
, TRUE
, FALSE
, time 
); 
 403         wxLogTrace(TRACE_DND
, wxT( "Drop target: OnData returned FALSE") ); 
 405         /* tell GTK that data transfer was not successfull */ 
 406         gtk_drag_finish( context
, FALSE
, FALSE
, time 
); 
 409     /* after this, invalidate the drop_target's drag data */ 
 410     drop_target
->SetDragData( (GtkSelectionData
*) NULL 
); 
 413 //---------------------------------------------------------------------------- 
 415 //---------------------------------------------------------------------------- 
 417 wxDropTarget::wxDropTarget( wxDataObject 
*data 
) 
 418             : wxDropTargetBase( data 
) 
 420     m_firstMotion 
= TRUE
; 
 421     m_dragContext 
= (GdkDragContext
*) NULL
; 
 422     m_dragWidget 
= (GtkWidget
*) NULL
; 
 423     m_dragData 
= (GtkSelectionData
*) NULL
; 
 427 wxDragResult 
wxDropTarget::OnDragOver( wxCoord 
WXUNUSED(x
), 
 431     // GetMatchingPair() checks for m_dataObject too, no need to do it here 
 433     // disable the debug message from GetMatchingPair() - there are too many 
 439     return (GetMatchingPair() != (GdkAtom
) 0) ? def 
: wxDragNone
; 
 442 bool wxDropTarget::OnDrop( wxCoord 
WXUNUSED(x
), wxCoord 
WXUNUSED(y
) ) 
 447     return (GetMatchingPair() != (GdkAtom
) 0); 
 450 wxDragResult 
wxDropTarget::OnData( wxCoord 
WXUNUSED(x
), wxCoord 
WXUNUSED(y
), 
 456     if (GetMatchingPair() == (GdkAtom
) 0) 
 459     return GetData() ? def 
: wxDragNone
; 
 462 GdkAtom 
wxDropTarget::GetMatchingPair() 
 470     GList 
*child 
= m_dragContext
->targets
; 
 473         GdkAtom formatAtom 
= (GdkAtom
) GPOINTER_TO_INT(child
->data
); 
 474         wxDataFormat 
format( formatAtom 
); 
 477         wxLogTrace(TRACE_DND
, wxT("Drop target: drag has format: %s"), 
 478                    format
.GetId().c_str()); 
 481         if (m_dataObject
->IsSupportedFormat( format 
)) 
 490 bool wxDropTarget::GetData() 
 498     wxDataFormat 
dragFormat( m_dragData
->target 
); 
 500     if (!m_dataObject
->IsSupportedFormat( dragFormat 
)) 
 503     m_dataObject
->SetData( dragFormat
, (size_t)m_dragData
->length
, (const void*)m_dragData
->data 
); 
 508 void wxDropTarget::UnregisterWidget( GtkWidget 
*widget 
) 
 510     wxCHECK_RET( widget 
!= NULL
, wxT("unregister widget is NULL") ); 
 512     gtk_drag_dest_unset( widget 
); 
 514     gtk_signal_disconnect_by_func( GTK_OBJECT(widget
), 
 515                       GTK_SIGNAL_FUNC(target_drag_leave
), (gpointer
) this ); 
 517     gtk_signal_disconnect_by_func( GTK_OBJECT(widget
), 
 518                       GTK_SIGNAL_FUNC(target_drag_motion
), (gpointer
) this ); 
 520     gtk_signal_disconnect_by_func( GTK_OBJECT(widget
), 
 521                       GTK_SIGNAL_FUNC(target_drag_drop
), (gpointer
) this ); 
 523     gtk_signal_disconnect_by_func( GTK_OBJECT(widget
), 
 524                       GTK_SIGNAL_FUNC(target_drag_data_received
), (gpointer
) this ); 
 527 void wxDropTarget::RegisterWidget( GtkWidget 
*widget 
) 
 529     wxCHECK_RET( widget 
!= NULL
, wxT("register widget is NULL") ); 
 531     /* gtk_drag_dest_set() determines what default behaviour we'd like 
 532        GTK to supply. we don't want to specify out targets (=formats) 
 533        or actions in advance (i.e. not GTK_DEST_DEFAULT_MOTION and 
 534        not GTK_DEST_DEFAULT_DROP). instead we react individually to 
 535        "drag_motion" and "drag_drop" events. this makes it possible 
 536        to allow dropping on only a small area. we should set 
 537        GTK_DEST_DEFAULT_HIGHLIGHT as this will switch on the nice 
 538        highlighting if dragging over standard controls, but this 
 539        seems to be broken without the other two. */ 
 541     gtk_drag_dest_set( widget
, 
 542                        (GtkDestDefaults
) 0,         /* no default behaviour */ 
 543                        (GtkTargetEntry
*) NULL
,      /* we don't supply any formats here */ 
 544                        0,                           /* number of targets = 0 */ 
 545                        (GdkDragAction
) 0 );         /* we don't supply any actions here */ 
 547     gtk_signal_connect( GTK_OBJECT(widget
), "drag_leave", 
 548                       GTK_SIGNAL_FUNC(target_drag_leave
), (gpointer
) this ); 
 550     gtk_signal_connect( GTK_OBJECT(widget
), "drag_motion", 
 551                       GTK_SIGNAL_FUNC(target_drag_motion
), (gpointer
) this ); 
 553     gtk_signal_connect( GTK_OBJECT(widget
), "drag_drop", 
 554                       GTK_SIGNAL_FUNC(target_drag_drop
), (gpointer
) this ); 
 556     gtk_signal_connect( GTK_OBJECT(widget
), "drag_data_received", 
 557                       GTK_SIGNAL_FUNC(target_drag_data_received
), (gpointer
) this ); 
 560 //---------------------------------------------------------------------------- 
 562 //---------------------------------------------------------------------------- 
 565 source_drag_data_get  (GtkWidget          
*WXUNUSED(widget
), 
 566                        GdkDragContext     
*WXUNUSED(context
), 
 567                        GtkSelectionData   
*selection_data
, 
 568                        guint               
WXUNUSED(info
), 
 569                        guint               
WXUNUSED(time
), 
 570                        wxDropSource       
*drop_source 
) 
 572     if (g_isIdle
) wxapp_install_idle_handler(); 
 574     wxDataFormat 
format( selection_data
->target 
); 
 576     wxLogTrace(TRACE_DND
, wxT("Drop source: format requested: %s"), 
 577                format
.GetId().c_str()); 
 579     drop_source
->m_retValue 
= wxDragCancel
; 
 581     wxDataObject 
*data 
= drop_source
->GetDataObject(); 
 585         wxLogTrace(TRACE_DND
, wxT("Drop source: no data object") ); 
 589     if (!data
->IsSupportedFormat(format
)) 
 591         wxLogTrace(TRACE_DND
, wxT("Drop source: unsupported format") ); 
 595     if (data
->GetDataSize(format
) == 0) 
 597         wxLogTrace(TRACE_DND
, wxT("Drop source: empty data") ); 
 601     size_t size 
= data
->GetDataSize(format
); 
 603 //  printf( "data size: %d.\n", (int)data_size ); 
 605     guchar 
*d 
= new guchar
[size
]; 
 607     if (!data
->GetDataHere( format
, (void*)d 
)) 
 614     /* disable GUI threads */ 
 617                 gtk_selection_data_set( selection_data
, 
 618                                         selection_data
->target
, 
 624     /* enable GUI threads */ 
 630 //---------------------------------------------------------------------------- 
 631 // "drag_data_delete" 
 632 //---------------------------------------------------------------------------- 
 634 static void source_drag_data_delete( GtkWidget 
*WXUNUSED(widget
), 
 635                                      GdkDragContext 
*context
, 
 636                                      wxDropSource 
*WXUNUSED(drop_source
) ) 
 639         wxapp_install_idle_handler(); 
 641     // printf( "Drag source: drag_data_delete\n" ); 
 644 //---------------------------------------------------------------------------- 
 646 //---------------------------------------------------------------------------- 
 648 static void source_drag_begin( GtkWidget          
*WXUNUSED(widget
), 
 649                                GdkDragContext     
*WXUNUSED(context
), 
 650                                wxDropSource       
*WXUNUSED(drop_source
) ) 
 653         wxapp_install_idle_handler(); 
 655     // printf( "Drag source: drag_begin.\n" ); 
 658 //---------------------------------------------------------------------------- 
 660 //---------------------------------------------------------------------------- 
 662 static void source_drag_end( GtkWidget          
*WXUNUSED(widget
), 
 663                              GdkDragContext     
*WXUNUSED(context
), 
 664                              wxDropSource       
*drop_source 
) 
 666     if (g_isIdle
) wxapp_install_idle_handler(); 
 668     // printf( "Drag source: drag_end.\n" ); 
 670     drop_source
->m_waiting 
= FALSE
; 
 673 //----------------------------------------------------------------------------- 
 674 // "configure_event" from m_iconWindow 
 675 //----------------------------------------------------------------------------- 
 678 gtk_dnd_window_configure_callback( GtkWidget 
*WXUNUSED(widget
), GdkEventConfigure 
*WXUNUSED(event
), wxDropSource 
*source 
) 
 681         wxapp_install_idle_handler(); 
 683     source
->GiveFeedback( ConvertFromGTK(source
->m_dragContext
->action
) ); 
 688 //--------------------------------------------------------------------------- 
 690 //--------------------------------------------------------------------------- 
 692 wxDropSource::wxDropSource(wxWindow 
*win
, 
 693                            const wxIcon 
&iconCopy
, 
 694                            const wxIcon 
&iconMove
, 
 695                            const wxIcon 
&iconNone
) 
 699     m_iconWindow 
= (GtkWidget
*) NULL
; 
 702     m_widget 
= win
->m_widget
; 
 703     if (win
->m_wxwindow
) m_widget 
= win
->m_wxwindow
; 
 705     m_retValue 
= wxDragCancel
; 
 707     SetIcons(iconCopy
, iconMove
, iconNone
); 
 710 wxDropSource::wxDropSource(wxDataObject
& data
, 
 712                            const wxIcon 
&iconCopy
, 
 713                            const wxIcon 
&iconMove
, 
 714                            const wxIcon 
&iconNone
) 
 720     m_iconWindow 
= (GtkWidget
*) NULL
; 
 723     m_widget 
= win
->m_widget
; 
 724     if (win
->m_wxwindow
) m_widget 
= win
->m_wxwindow
; 
 726     m_retValue 
= wxDragCancel
; 
 728     SetIcons(iconCopy
, iconMove
, iconNone
); 
 731 void wxDropSource::SetIcons(const wxIcon 
&iconCopy
, 
 732                             const wxIcon 
&iconMove
, 
 733                             const wxIcon 
&iconNone
) 
 735     m_iconCopy 
= iconCopy
; 
 736     m_iconMove 
= iconMove
; 
 737     m_iconNone 
= iconNone
; 
 739     if ( !m_iconCopy
.Ok() ) 
 740         m_iconCopy 
= wxIcon(page_xpm
); 
 741     if ( !m_iconMove
.Ok() ) 
 742         m_iconMove 
= m_iconCopy
; 
 743     if ( !m_iconNone
.Ok() ) 
 744         m_iconNone 
= m_iconCopy
; 
 747 wxDropSource::~wxDropSource() 
 751 void wxDropSource::PrepareIcon( int action
, GdkDragContext 
*context 
) 
 753     // get the right icon to display 
 755     if ( action 
& GDK_ACTION_MOVE 
) 
 757     else if ( action 
& GDK_ACTION_COPY 
) 
 763     if ( icon
->GetMask() ) 
 764         mask 
= icon
->GetMask()->GetBitmap(); 
 766         mask 
= (GdkBitmap 
*)NULL
; 
 768     GdkPixmap 
*pixmap 
= icon
->GetPixmap(); 
 771     gdk_window_get_size (pixmap
, &width
, &height
); 
 773     GdkColormap 
*colormap 
= gtk_widget_get_colormap( m_widget 
); 
 775     gtk_widget_push_visual (gdk_colormap_get_visual (colormap
)); 
 777     gtk_widget_push_colormap (colormap
); 
 779     m_iconWindow 
= gtk_window_new (GTK_WINDOW_POPUP
); 
 780     gtk_widget_set_events (m_iconWindow
, GDK_BUTTON_PRESS_MASK 
| GDK_BUTTON_RELEASE_MASK
); 
 781     gtk_widget_set_app_paintable (GTK_WIDGET (m_iconWindow
), TRUE
); 
 784     gtk_widget_pop_visual (); 
 786     gtk_widget_pop_colormap (); 
 788     gtk_widget_set_usize (m_iconWindow
, width
, height
); 
 789     gtk_widget_realize (m_iconWindow
); 
 791     gtk_signal_connect( GTK_OBJECT(m_iconWindow
), "configure_event", 
 792         GTK_SIGNAL_FUNC(gtk_dnd_window_configure_callback
), (gpointer
)this ); 
 794     gdk_window_set_back_pixmap (m_iconWindow
->window
, pixmap
, FALSE
); 
 797         gtk_widget_shape_combine_mask (m_iconWindow
, mask
, 0, 0); 
 799     gtk_drag_set_icon_widget( context
, m_iconWindow
, 0, 0 ); 
 802 wxDragResult 
wxDropSource::DoDragDrop(int flags
) 
 804     wxCHECK_MSG( m_data 
&& m_data
->GetFormatCount(), wxDragNone
, 
 805                  wxT("Drop source: no data") ); 
 808     if (g_blockEventsOnDrag
) 
 812     g_blockEventsOnDrag 
= TRUE
; 
 818     GtkTargetList 
*target_list 
= gtk_target_list_new( (GtkTargetEntry
*) NULL
, 0 ); 
 820     wxDataFormat 
*array 
= new wxDataFormat
[ m_data
->GetFormatCount() ]; 
 821     m_data
->GetAllFormats( array 
); 
 822     size_t count 
= m_data
->GetFormatCount(); 
 823     for (size_t i 
= 0; i 
< count
; i
++) 
 825         GdkAtom atom 
= array
[i
]; 
 826         wxLogTrace(TRACE_DND
, wxT("Drop source: Supported atom %s"), gdk_atom_name( atom 
)); 
 827         gtk_target_list_add( target_list
, atom
, 0, 0 ); 
 831     GdkEventMotion event
; 
 832     event
.window 
= m_widget
->window
; 
 835     GdkModifierType state
; 
 836     gdk_window_get_pointer( event
.window
, &x
, &y
, &state 
); 
 840     event
.time 
= (guint32
)GDK_CURRENT_TIME
; 
 842     /* GTK wants to know which button was pressed which caused the dragging */ 
 843     int button_number 
= 0; 
 844     if (event
.state 
& GDK_BUTTON1_MASK
) button_number 
= 1; 
 845     else if (event
.state 
& GDK_BUTTON2_MASK
) button_number 
= 2; 
 846     else if (event
.state 
& GDK_BUTTON3_MASK
) button_number 
= 3; 
 849     /* disable GUI threads */ 
 852     /* don't start dragging if no button is down */ 
 855         int action 
= GDK_ACTION_COPY
; 
 856         if ( flags 
& wxDrag_AllowMove 
) 
 857             action 
|= GDK_ACTION_MOVE
; 
 859         // VZ: as we already use g_blockEventsOnDrag it shouldn't be that bad 
 860         //     to use a global to pass the flags to the drop target but I'd 
 861         //     surely prefer a better way to do it 
 862         gs_flagsForDrag 
= flags
; 
 864         GdkDragContext 
*context 
= gtk_drag_begin( m_widget
, 
 866                 (GdkDragAction
)action
, 
 867                 button_number
,  /* number of mouse button which started drag */ 
 868                 (GdkEvent
*) &event 
); 
 870         m_dragContext 
= context
; 
 872         PrepareIcon( action
, context 
); 
 875             gtk_main_iteration(); 
 877         m_retValue 
= ConvertFromGTK(context
->action
); 
 878         if ( m_retValue 
== wxDragNone 
) 
 879             m_retValue 
= wxDragCancel
; 
 883     /* re-enable GUI threads */ 
 886     g_blockEventsOnDrag 
= FALSE
; 
 893 void wxDropSource::RegisterWindow() 
 895     if (!m_widget
) return; 
 897     gtk_signal_connect( GTK_OBJECT(m_widget
), "drag_data_get", 
 898                       GTK_SIGNAL_FUNC (source_drag_data_get
), (gpointer
) this); 
 899     gtk_signal_connect (GTK_OBJECT(m_widget
), "drag_data_delete", 
 900                       GTK_SIGNAL_FUNC (source_drag_data_delete
),  (gpointer
) this ); 
 901     gtk_signal_connect (GTK_OBJECT(m_widget
), "drag_begin", 
 902                       GTK_SIGNAL_FUNC (source_drag_begin
),  (gpointer
) this ); 
 903     gtk_signal_connect (GTK_OBJECT(m_widget
), "drag_end", 
 904                       GTK_SIGNAL_FUNC (source_drag_end
),  (gpointer
) this ); 
 908 void wxDropSource::UnregisterWindow() 
 910     if (!m_widget
) return; 
 912     gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
), 
 913                       GTK_SIGNAL_FUNC(source_drag_data_get
), (gpointer
) this ); 
 914     gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
), 
 915                       GTK_SIGNAL_FUNC(source_drag_data_delete
), (gpointer
) this ); 
 916     gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
), 
 917                       GTK_SIGNAL_FUNC(source_drag_begin
), (gpointer
) this ); 
 918     gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
), 
 919                       GTK_SIGNAL_FUNC(source_drag_end
), (gpointer
) this ); 
 923       // wxUSE_DRAG_AND_DROP