Re: Dual Drop on to GtkTreeView



It's a bit of a hack, but I found a solution. I'm posting it here in case anyone else has a similar question. The trick was to listen to signals to know when a user is trying to drag files into the GtkTreeView or when she is trying to reorder the rows. Here are the important bits of code:


typedef struct _AudioDragData           AudioDragData;

struct _AudioDragData
{
        gboolean drag_in_progress;
        gboolean is_dest_set;
        gulong handler_id;
};


view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
        
drag_data = g_new0 (AudioDragData, 1);
drag_data->drag_in_progress = FALSE;
drag_data->is_dest_set = TRUE;
drag_data->handler_id = g_signal_connect (G_OBJECT (view),
                "drag_data_received",
                G_CALLBACK (drag_audio_rcv_cb),
                store);
                        
gtk_drag_dest_set (view, GTK_DEST_DEFAULT_ALL, target_table,
                G_N_ELEMENTS (target_table), GDK_ACTION_COPY);

g_signal_connect (G_OBJECT (view), "button_press_event",
                G_CALLBACK (audio_button_press_cb), drag_data);
g_signal_connect (G_OBJECT (view), "button_release_event",
                G_CALLBACK (audio_button_release_cb), drag_data);
g_signal_connect (G_OBJECT (view), "drag_begin",
                G_CALLBACK (audio_drag_begin_cb), drag_data);
g_signal_connect (G_OBJECT (view), "drag_end",
                G_CALLBACK (audio_drag_end_cb), drag_data);


callback functions:

void
audio_drag_begin_cb (GtkWidget *view, GdkDragContext *context, gpointer data)
{
        AudioDragData *drag_data = data;
        
        drag_data->drag_in_progress = TRUE;

        return;
}

void
audio_drag_end_cb (GtkWidget *view, GdkDragContext *context, gpointer data)
{
        AudioDragData *drag_data = data;
        
        drag_data->drag_in_progress = FALSE;
        
        if (!drag_data->is_dest_set)
        {
                gtk_tree_view_set_reorderable (GTK_TREE_VIEW (view), FALSE);
                
                gtk_drag_dest_set (view, GTK_DEST_DEFAULT_ALL, target_table,
                                G_N_ELEMENTS (target_table), GDK_ACTION_COPY);
                g_signal_handler_unblock (view, drag_data->handler_id);
                drag_data->is_dest_set = TRUE;
        }
        
        return;
}

gboolean
audio_button_press_cb (GtkWidget *view, GdkEventButton *event, gpointer data)
{
        AudioDragData *drag_data = data;

        if (drag_data->is_dest_set)
        {
                gtk_drag_dest_unset (view);
                g_signal_handler_block (view, drag_data->handler_id);
                drag_data->is_dest_set = FALSE;
        }       
        
        gtk_tree_view_set_reorderable (GTK_TREE_VIEW (view), TRUE);
        
        return FALSE;
}

gboolean
audio_button_release_cb (GtkWidget *view, GdkEventButton *event, gpointer data)
{
        AudioDragData *drag_data = data;
        
        if (!drag_data->is_dest_set && !drag_data->drag_in_progress)
        {
                gtk_tree_view_set_reorderable (GTK_TREE_VIEW (view), FALSE);
        
                gtk_drag_dest_set (view, GTK_DEST_DEFAULT_ALL, target_table,
                                G_N_ELEMENTS (target_table), GDK_ACTION_COPY);
                g_signal_handler_unblock (view, drag_data->handler_id);
                drag_data->is_dest_set = TRUE;
        }
        
        return FALSE;
}




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]