]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/dnd.cpp
Minor fixes, should be ok now.
[wxWidgets.git] / src / gtk / dnd.cpp
index 225318a2352b6499cad6404adcfe2dafd7ec7261..9378aba506d4c3a58c84af171dacfcc1c10b438c 100644 (file)
 #include "gtk/gtkdnd.h"
 #include "gtk/gtkselection.h"
 
+//-----------------------------------------------------------------------------
+// idle system
+//-----------------------------------------------------------------------------
+
+extern void wxapp_install_idle_handler();
+extern bool g_isIdle;
+
 //----------------------------------------------------------------------------
 // global data
 //----------------------------------------------------------------------------
@@ -134,6 +141,8 @@ static void target_drag_leave( GtkWidget *WXUNUSED(widget),
                               guint WXUNUSED(time),
                               wxDropTarget *drop_target )
 {
+    if (g_isIdle) wxapp_install_idle_handler();
+
     /* inform the wxDropTarget about the current GdkDragContext.
        this is only valid for the duration of this call */
     drop_target->SetDragContext( context );
@@ -160,6 +169,8 @@ static gboolean target_drag_motion( GtkWidget *WXUNUSED(widget),
                                    guint time,
                                    wxDropTarget *drop_target )
 {
+    if (g_isIdle) wxapp_install_idle_handler();
+
     /* Owen Taylor: "if the coordinates not in a drop zone,
        return FALSE, otherwise call gtk_drag_status() and
        return TRUE" */
@@ -203,6 +214,8 @@ static gboolean target_drag_drop( GtkWidget *widget,
                                  guint time,
                                  wxDropTarget *drop_target )
 {
+    if (g_isIdle) wxapp_install_idle_handler();
+
     /* Owen Taylor: "if the drop is not in a drop zone,
        return FALSE, otherwise, if you aren't accepting
        the drop, call gtk_drag_finish() with success == FALSE
@@ -262,6 +275,8 @@ static void target_drag_data_received( GtkWidget *WXUNUSED(widget),
                                       guint time,
                                       wxDropTarget *drop_target )
 {
+    if (g_isIdle) wxapp_install_idle_handler();
+
     /* Owen Taylor: "call gtk_drag_finish() with
        success == TRUE" */
 
@@ -273,6 +288,8 @@ static void target_drag_data_received( GtkWidget *WXUNUSED(widget),
            qualifies for junk */
         gtk_drag_finish (context, FALSE, FALSE, time);
        
+//     printf( "no data.\n" );
+       
        return;
     }
     
@@ -340,6 +357,12 @@ bool wxDropTarget::RequestData( wxDataFormat format )
     if (!m_dragContext) return FALSE;
     if (!m_dragWidget) return FALSE;
     
+/*
+    wxPrintf( _T("format: %s.\n"), format.GetId().c_str() );
+    if (format.GetType() == wxDF_PRIVATE) wxPrintf( _T("private data.\n") );
+    if (format.GetType() == wxDF_TEXT) wxPrintf( _T("text data.\n") );
+*/
+
     /* this should trigger an "drag_data_received" event */
     gtk_drag_get_data( m_dragWidget, 
                       m_dragContext,
@@ -470,7 +493,7 @@ bool wxTextDropTarget::OnData( int x, int y )
     wxTextDataObject data;
     if (!GetData( &data )) return FALSE;
     
-    OnDropText( x, y, data.GetText().mbc_str() );
+    OnDropText( x, y, data.GetText() );
     
     return TRUE;
 }
@@ -581,6 +604,10 @@ source_drag_data_get  (GtkWidget          *WXUNUSED(widget),
                       guint               WXUNUSED(time),
                       wxDropSource       *drop_source )
 {
+    if (g_isIdle) wxapp_install_idle_handler();
+
+//    printf( "Provide data!\n" );
+
 //    char *name = gdk_atom_name( selection_data->target );
 //    if (name) printf( "Format requested: %s.\n", name );
     
@@ -590,15 +617,20 @@ source_drag_data_get  (GtkWidget          *WXUNUSED(widget),
         wxDataObject *data_object = (wxDataObject*) node->Data();
        if (data_object->GetFormat().GetAtom() == selection_data->target)
        {
+//         printf( "format found.\n" );
+       
            size_t data_size = data_object->GetSize();
+           
            if (data_size > 0)
            {
+//             printf( "data size: %d.\n", (int)data_size );
+           
                guchar *buffer = new guchar[data_size];
                data_object->WriteData( buffer );
                
                 gtk_selection_data_set( selection_data,
                                        selection_data->target,
-                                       8,   /* 8-bit */
+                                       8,   // 8-bit
                                        buffer, 
                                        data_size );
                                        
@@ -625,6 +657,8 @@ static void source_drag_data_delete( GtkWidget          *WXUNUSED(widget),
                                     GdkDragContext     *WXUNUSED(context),
                                     wxDropSource       *drop_source )
 {
+    if (g_isIdle) wxapp_install_idle_handler();
+
 //    printf( "Delete the data!\n" );
 
     drop_source->m_retValue = wxDragMove;
@@ -638,6 +672,8 @@ static void source_drag_begin( GtkWidget          *WXUNUSED(widget),
                               GdkDragContext     *WXUNUSED(context),
                               wxDropSource       *WXUNUSED(drop_source) )
 {
+    if (g_isIdle) wxapp_install_idle_handler();
+
 //    printf( "drag_begin.\n" );
 }
   
@@ -649,6 +685,8 @@ static void source_drag_end( GtkWidget          *WXUNUSED(widget),
                             GdkDragContext     *WXUNUSED(context),
                             wxDropSource       *drop_source )
 {
+    if (g_isIdle) wxapp_install_idle_handler();
+
 //    printf( "drag_end.\n" );
 
     drop_source->m_waiting = FALSE;
@@ -761,8 +799,11 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
     
     m_waiting = TRUE;
 
+    GdkAtom atom = gdk_atom_intern( "STRING", FALSE );
+//    wxPrintf( _T("atom id: %d.\n"), (int)atom );
+
     GtkTargetList *target_list = gtk_target_list_new( (GtkTargetEntry*) NULL, 0 );
-    gtk_target_list_add( target_list, gdk_atom_intern( "STRING", FALSE ), 0, 0 );
+    gtk_target_list_add( target_list, atom, 0, 0 );
     
     GdkEventMotion event;
     event.window = m_widget->window;
@@ -773,6 +814,7 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
     event.x = x;
     event.y = y;
     event.state = state;
+    event.time = GDK_CURRENT_TIME;
     
     /* GTK wants to know which button was pressed which caused the dragging */
     int button_number = 0;
@@ -801,9 +843,7 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
                                  0,
                                  0 );
     
-        gdk_flush();
-    
-        while (m_waiting) wxYield();
+        while (m_waiting) gtk_main_iteration();;
     }
 
     g_blockEventsOnDrag = FALSE;