void PluginManageDlg::drag_data_received_cb(GtkWidget *widget, GdkDragContext *ctx, guint x, guint y, GtkSelectionData *sd, guint info, guint t, PluginManageDlg *oPluginManageDlg) { if (gtk_selection_data_get_target(sd) == gdk_atom_intern("STARDICT_PLUGINMANAGE", FALSE) && gtk_selection_data_get_data(sd)) { GtkTreePath *path = NULL; GtkTreeViewDropPosition position; GtkTreeIter drag_iter; memcpy(&drag_iter, gtk_selection_data_get_data(sd), sizeof(drag_iter)); if (gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(widget), x, y, &path, &position)) { GtkTreeIter iter; GtkTreeModel *model = GTK_TREE_MODEL(oPluginManageDlg->plugin_tree_model); gtk_tree_model_get_iter(model, &iter, path); if (gtk_tree_model_iter_has_child(model, &iter)) { gtk_drag_finish (ctx, FALSE, FALSE, t); return; } if (gtk_tree_model_iter_has_child(model, &drag_iter)) { gtk_drag_finish (ctx, FALSE, FALSE, t); return; } GtkTreeIter parent_iter; if (!gtk_tree_model_iter_parent(model, &parent_iter, &iter)) { gtk_drag_finish (ctx, FALSE, FALSE, t); return; } GtkTreeIter drag_parent_iter; if (!gtk_tree_model_iter_parent(model, &drag_parent_iter, &drag_iter)) { gtk_drag_finish (ctx, FALSE, FALSE, t); return; } char *iter_str, *drag_iter_str; iter_str = gtk_tree_model_get_string_from_iter(model, &parent_iter); drag_iter_str = gtk_tree_model_get_string_from_iter(model, &drag_parent_iter); if (strcmp(iter_str, drag_iter_str) != 0) { g_free(iter_str); g_free(drag_iter_str); gtk_drag_finish (ctx, FALSE, FALSE, t); return; } g_free(iter_str); g_free(drag_iter_str); switch (position) { case GTK_TREE_VIEW_DROP_AFTER: case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: gtk_tree_store_move_after(GTK_TREE_STORE(model), &drag_iter, &iter); break; case GTK_TREE_VIEW_DROP_BEFORE: case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: gtk_tree_store_move_before(GTK_TREE_STORE(model), &drag_iter, &iter); break; default: { gtk_drag_finish (ctx, FALSE, FALSE, t); return; } } oPluginManageDlg->write_order_list(); oPluginManageDlg->order_changed_ = true; gtk_drag_finish (ctx, TRUE, FALSE, t); } } }
static char * get_drop_target_uri_at_pos (NemoTreeViewDragDest *dest, int x, int y) { char *drop_target; GtkTreePath *path; GtkTreePath *drop_path; GtkTreeViewDropPosition pos; gtk_tree_view_get_dest_row_at_pos (dest->details->tree_view, x, y, &path, &pos); drop_path = get_drop_path (dest, path); drop_target = get_drop_target_uri_for_path (dest, drop_path); if (path != NULL) { gtk_tree_path_free (path); } if (drop_path != NULL) { gtk_tree_path_free (drop_path); } return drop_target; }
static char * get_drop_target_uri_at_pos (NautilusTreeViewDragDest *dest, int x, int y) { char *drop_target = NULL; GtkTreePath *path; GtkTreePath *drop_path; GtkTreeViewDropPosition pos; gtk_tree_view_get_dest_row_at_pos (dest->details->tree_view, x, y, &path, &pos); if (pos == GTK_TREE_VIEW_DROP_BEFORE || pos == GTK_TREE_VIEW_DROP_AFTER) { gtk_tree_path_free (path); path = NULL; } drop_path = get_drop_path (dest, path); drop_target = get_drop_target_uri_for_path (dest, drop_path); if (path != NULL) { gtk_tree_path_free (path); } if (drop_path != NULL) { gtk_tree_path_free (drop_path); } return drop_target; }
static gint bar_pane_keywords_dnd_motion(GtkWidget *tree_view, GdkDragContext *context, gint x, gint y, guint time, gpointer data) { GtkTreePath *tpath = NULL; GtkTreeViewDropPosition pos; gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(tree_view), x, y, &tpath, &pos); if (tpath) { GtkTreeModel *model; GtkTreeIter dest_iter; model = gtk_tree_view_get_model(GTK_TREE_VIEW(tree_view)); gtk_tree_model_get_iter(model, &dest_iter, tpath); if (pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE && gtk_tree_model_iter_has_child(model, &dest_iter)) pos = GTK_TREE_VIEW_DROP_BEFORE; if (pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER && gtk_tree_model_iter_has_child(model, &dest_iter)) pos = GTK_TREE_VIEW_DROP_AFTER; } gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW(tree_view), tpath, pos); gtk_tree_path_free(tpath); if (tree_view == gtk_drag_get_source_widget(context)) gdk_drag_status(context, GDK_ACTION_MOVE, time); else gdk_drag_status(context, GDK_ACTION_COPY, time); return TRUE; }
/* * text has been dragged into the watch tree view */ static void on_watch_dragged_callback(GtkWidget *wgt, GdkDragContext *context, int x, int y, GtkSelectionData *seldata, guint info, guint _time, gpointer userdata) { /* string that is dragged */ gchar *expression = (gchar*)seldata->data; GtkTreePath *path = NULL; GtkTreeViewDropPosition pos; GtkTreePath *empty_path; GtkTreeIter newvar; /* lookup for where the text has been dropped */ gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(wtree), x, y, &path, &pos); /* if dropped into last row - insert before it */ empty_path = wtree_empty_path(); if (!gtk_tree_path_compare(empty_path, path)) pos = GTK_TREE_VIEW_DROP_BEFORE; gtk_tree_path_free(empty_path); /* if dropped into children area - insert before parent */ if (gtk_tree_path_get_depth(path) > 1) { while (gtk_tree_path_get_depth(path) > 1) gtk_tree_path_up(path); pos = GTK_TREE_VIEW_DROP_BEFORE; } /* insert new row */ if (path) { GtkTreeIter sibling; gtk_tree_model_get_iter(wmodel, &sibling, path); if (GTK_TREE_VIEW_DROP_BEFORE == pos || GTK_TREE_VIEW_DROP_INTO_OR_BEFORE == pos) gtk_tree_store_insert_before(wstore, &newvar, NULL, &sibling); else gtk_tree_store_insert_after(wstore, &newvar, NULL, &sibling); } else { GtkTreeIter empty; wtree_empty_row(&empty); gtk_tree_store_insert_before(wstore, &newvar, NULL, &empty); } /* if debugger is active (in stopped condition) - add to run-time watch list * if not - just set new expession in the tree view */ if (DBS_STOPPED == debug_state) { variable *var = active_module->add_watch(expression); change_watch(GTK_TREE_VIEW(wtree), &newvar, var); } else variable_set_name_only(wstore, &newvar, expression); config_set_debug_changed(); }
/* methods to receive URLs which were dropped anywhere in the main window */ static void liferea_shell_URL_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *data, guint info, guint time_received) { gchar *tmp1, *tmp2, *freeme; GtkWidget *mainwindow; GtkAllocation alloc; GtkTreeView *treeview; GtkTreeModel *model; GtkTreePath *path; GtkTreeIter iter; nodePtr node; gint tx, ty; g_return_if_fail (gtk_selection_data_get_data (data) != NULL); mainwindow = GTK_WIDGET (shell->priv->window); treeview = GTK_TREE_VIEW (shell->priv->feedlistView); model = gtk_tree_view_get_model (treeview); /* x and y are relative to the main window, make them relative to the treeview */ gtk_widget_translate_coordinates (mainwindow, GTK_WIDGET (treeview), x, y, &tx, &ty); /* Allow link drops only over feed list widget. This is to avoid the frequent accidental text drops in the HTML view. */ gtk_widget_get_allocation(GTK_WIDGET(treeview), &alloc); if((x > alloc.x+alloc.width) || (x < alloc.x) || (y > alloc.y+alloc.height) || (y < alloc.y)) { gtk_drag_finish (context, FALSE, FALSE, time_received); return; } if ((gtk_selection_data_get_length (data) >= 0) && (gtk_selection_data_get_format (data) == 8)) { /* extra handling to accept multiple drops */ freeme = tmp1 = g_strdup (gtk_selection_data_get_data (data)); while ((tmp2 = strsep (&tmp1, "\n\r"))) { if (strlen (tmp2)) { /* if the drop is over a node, select it so that feedlist_add_subscription() * adds it in the correct folder */ if (gtk_tree_view_get_dest_row_at_pos (treeview, tx, ty, &path, NULL)) { if (gtk_tree_model_get_iter (model, &iter, path)) { gtk_tree_model_get (model, &iter, FS_PTR, &node, -1); /* if node is NULL, feed_list_view_select() will unselect the tv */ feed_list_view_select (node); } gtk_tree_path_free (path); } feedlist_add_subscription (g_strdup (tmp2), NULL, NULL, FEED_REQ_PRIORITY_HIGH); } } g_free (freeme); gtk_drag_finish (context, TRUE, FALSE, time_received); } else { gtk_drag_finish (context, FALSE, FALSE, time_received); } }
static void _lib_keywords_drag_data_received_callback(GtkWidget *w, GdkDragContext *dctx, guint x, guint y, GtkSelectionData *data, guint info, guint time, gpointer user_data) { dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_keywords_t *d = (dt_lib_keywords_t*)self->data; GtkTreePath *dpath; GtkTreeViewDropPosition dpos; GtkTreeModel *model = gtk_tree_view_get_model(d->view); if (data->format == 8) { if (gtk_tree_view_get_dest_row_at_pos(d->view, x, y, &dpath, &dpos)) { /* fetch tree iter of source and dest dnd operation */ GtkTreePath *spath = gtk_tree_path_new_from_string((char *)data->data); char dtag[1024]; char stag[1024]; _lib_keywords_string_from_path(dtag, 1024, model, dpath); _lib_keywords_string_from_path(stag, 1024, model, spath); /* reject drop onto ourself */ if (strcmp(dtag,stag) == 0) goto reject_drop; /* updated tags in database */ dt_tag_reorganize(stag,dtag); /* lets move the source iter into dest iter */ GtkTreeIter sit,dit; gtk_tree_model_get_iter(model, &sit, spath); gtk_tree_model_get_iter(model, &dit, dpath); _gtk_tree_move_iter(GTK_TREE_STORE(model), &sit, &dit); /* accept drop */ gtk_drag_finish(dctx, TRUE, FALSE, time); } } /* reject drop */ reject_drop: gtk_drag_finish (dctx, FALSE, FALSE, time); }
static GtkTreePath* fm_list_view_get_path_at_pos (FMDirectoryView *view, gint x, gint y) { GtkTreePath *path; g_return_val_if_fail (FM_IS_LIST_VIEW (view), NULL); if (gtk_tree_view_get_dest_row_at_pos (FM_LIST_VIEW (view)->tree, x, y, &path, NULL)) return path; return NULL; }
static gboolean gw_settingswindow_dictionary_drag_reorder ( GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer user_data) { //Declarations GwSettingsWindow *window; GwApplication *application; GwDictionaryList *dictionarylist; LwPreferences *preferences; GtkTreeViewDropPosition drop_position; GtkTreePath *path; GtkTreeView *view; GtkTreeSelection *selection; GtkTreeModel *model; GtkTreeIter iter, position; //Initializations window = GW_SETTINGSWINDOW (gtk_widget_get_ancestor (GTK_WIDGET (widget), GW_TYPE_SETTINGSWINDOW)); application = gw_window_get_application (GW_WINDOW (window)); dictionarylist = gw_application_get_installed_dictionarylist (application); preferences = gw_application_get_preferences (application); g_return_val_if_fail (window != NULL, FALSE); view = GTK_TREE_VIEW (widget); selection = gtk_tree_view_get_selection (view); model = gtk_tree_view_get_model (view); gtk_tree_view_get_dest_row_at_pos (view, x, y, &path, &drop_position); if (path == NULL) return FALSE; gtk_tree_model_get_iter (model, &position, path); gtk_tree_path_free (path); path = NULL; if (drop_position == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE) drop_position = GTK_TREE_VIEW_DROP_BEFORE; else if (drop_position == GTK_TREE_VIEW_DROP_INTO_OR_AFTER) drop_position = GTK_TREE_VIEW_DROP_AFTER; gtk_tree_selection_get_selected (selection, &model, &iter); if (drop_position == GTK_TREE_VIEW_DROP_BEFORE) gtk_list_store_move_before (GTK_LIST_STORE (model), &iter, &position); else if (drop_position == GTK_TREE_VIEW_DROP_AFTER) gtk_list_store_move_after (GTK_LIST_STORE (model), &iter, &position); gw_dictionarylist_save_order (dictionarylist, preferences); return TRUE; }
void iupdrvListConvertXYToItem(Ihandle* ih, int x, int y, int *pos) { if (!ih->data->is_dropdown) { GtkTreePath* path; if (gtk_tree_view_get_dest_row_at_pos((GtkTreeView*)ih->handle, x, y, &path, NULL)) { int* indices = gtk_tree_path_get_indices(path); *pos = indices[0]+1; /* IUP starts at 1 */ gtk_tree_path_free (path); } } }
static VALUE rg_get_dest_row_at_pos(VALUE self, VALUE drag_x, VALUE drag_y) { GtkTreePath* path; GtkTreeViewDropPosition pos; gboolean ret; ret = gtk_tree_view_get_dest_row_at_pos(_SELF(self), NUM2INT(drag_x), NUM2INT(drag_y), &path, &pos); return ret ? rb_ary_new3(2, path ? GTKTREEPATH2RVAL(path) : Qnil, GENUM2RVAL(pos, GTK_TYPE_TREE_VIEW_DROP_POSITION)) : Qnil; }
static gboolean rb_tree_dnd_drag_drop_cb (GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time) { GtkTreeView *tree_view; GtkTreePath *path; GtkTreeModel *model; GtkTreeViewDropPosition pos; RbTreeDndData *priv_data; tree_view = GTK_TREE_VIEW (widget); model = gtk_tree_view_get_model (tree_view); priv_data = g_object_get_data (G_OBJECT (widget), RB_TREE_DND_STRING); gtk_tree_view_get_dest_row_at_pos (tree_view, x, y, &path, &pos); remove_scroll_timeout (tree_view); /* Unset this thing */ gtk_tree_view_set_drag_dest_row (tree_view, NULL, GTK_TREE_VIEW_DROP_BEFORE); if (path || priv_data->dest_flags & RB_TREE_DEST_EMPTY_VIEW_DROP) { GdkAtom target; RbTreeDragDestIface *iface = RB_TREE_DRAG_DEST_GET_IFACE (model); if (iface->rb_get_drag_target) { RbTreeDragDest *dest = RB_TREE_DRAG_DEST (model); target = (* iface->rb_get_drag_target) (dest, widget, context, path, priv_data->dest_target_list); } else { target = gtk_drag_dest_find_target (widget, context, priv_data->dest_target_list); } if (path) gtk_tree_path_free (path); if (target != GDK_NONE) { gtk_drag_get_data (widget, context, target, time); return TRUE; } } return FALSE; }
static void drag_data_received_cb(GtkWidget *widget, GdkDragContext *ctx, guint x, guint y, GtkSelectionData *sd, guint info, guint t, AccountsWindow *dialog) { if (sd->target == gdk_atom_intern("PURPLE_ACCOUNT", FALSE) && sd->data) { gint dest_index; PurpleAccount *a = NULL; GtkTreePath *path = NULL; GtkTreeViewDropPosition position; memcpy(&a, sd->data, sizeof(a)); if (gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(widget), x, y, &path, &position)) { GtkTreeIter iter; PurpleAccount *account; GValue val = {0}; gtk_tree_model_get_iter(GTK_TREE_MODEL(dialog->model), &iter, path); gtk_tree_model_get_value(GTK_TREE_MODEL(dialog->model), &iter, COLUMN_DATA, &val); account = g_value_get_pointer(&val); switch (position) { case GTK_TREE_VIEW_DROP_AFTER: case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: move_account_after(dialog->model, &dialog->drag_iter, &iter); dest_index = g_list_index(purple_accounts_get_all(), account) + 1; break; case GTK_TREE_VIEW_DROP_BEFORE: case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: dest_index = g_list_index(purple_accounts_get_all(), account); move_account_before(dialog->model, &dialog->drag_iter, &iter); break; default: return; } purple_accounts_reorder(a, dest_index); } } }
gboolean on_dnd_dest_query_info(FmDndDest* dd, int x, int y, GdkDragAction* action, FmPlacesView* view) { GtkTreeViewDropPosition pos; GtkTreePath* tp = NULL; GtkTreeViewColumn* col; if(gtk_tree_view_get_dest_row_at_pos((GtkTreeView*)view, x, y, &tp, &pos)) { /* FIXME: this is inefficient. we should record the index of separator instead. */ if(pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE || pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER) { } else { GtkTreePath* sep = gtk_tree_model_get_path(GTK_TREE_MODEL(model), &sep_it); if(gtk_tree_path_compare(sep, tp) < 0) /* tp is after sep */ { *action = GDK_ACTION_LINK; } else { *action = 0; gtk_tree_path_free(tp); tp = NULL; } gtk_tree_path_free(sep); } } else { tp = gtk_tree_path_new_from_indices(gtk_tree_model_iter_n_children(GTK_TREE_MODEL(model), NULL)-1, -1); pos = GTK_TREE_VIEW_DROP_AFTER; *action = GDK_ACTION_LINK; } gtk_tree_view_set_drag_dest_row((GtkTreeView*)view, tp, pos); fm_dnd_dest_set_dest_file(view->dnd_dest, NULL); if(view->dest_row) gtk_tree_path_free(view->dest_row); view->dest_row = tp; view->dest_pos = pos; return TRUE; }
static void xkb_layouts_dnd_data_received (GtkWidget * widget, GdkDragContext * dc, gint x, gint y, GtkSelectionData * selection_data, guint info, guint t, GtkBuilder * dialog) { gint sidx = find_selected_layout_idx (dialog); GtkWidget *tree_view = WID ("xkb_layouts_selected"); GtkTreePath *path = NULL; GtkTreeViewDropPosition pos; gint didx; gchar *id; GSList *layouts_list; GSList *node2Remove; if (sidx == -1) return; layouts_list = xkb_layouts_get_selected_list (); node2Remove = g_slist_nth (layouts_list, sidx); id = (gchar *) node2Remove->data; layouts_list = g_slist_delete_link (layouts_list, node2Remove); if (!gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (tree_view), x, y, &path, &pos)) { /* Move to the very end */ layouts_list = g_slist_append (layouts_list, g_strdup (id)); xkb_layouts_set_selected_list (layouts_list); } else if (path != NULL) { gint *indices = gtk_tree_path_get_indices (path); didx = indices[0]; gtk_tree_path_free (path); /* Move to the new position */ if (sidx != didx) { layouts_list = g_slist_insert (layouts_list, g_strdup (id), didx); xkb_layouts_set_selected_list (layouts_list); } } g_free (id); clear_xkb_elements_list (layouts_list); }
static void rb_tree_dnd_drag_data_received_cb (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint info, guint time) { GtkTreeView *tree_view; GtkTreeModel *model; GtkTreePath *dest_row; GtkTreeViewDropPosition pos; gboolean filtered = TRUE; gboolean accepted = FALSE; tree_view = GTK_TREE_VIEW (widget); model = gtk_tree_view_get_model (tree_view); gtk_tree_view_get_dest_row_at_pos (tree_view, x, y, &dest_row, &pos); if (dest_row) if (!filter_drop_position (widget, context, dest_row, &pos)) filtered = FALSE; if (filtered && selection_data->length >= 0) { if (rb_tree_drag_dest_drag_data_received (RB_TREE_DRAG_DEST (model), dest_row, pos, selection_data)) accepted = TRUE; } gtk_drag_finish (context, accepted, (context->action == GDK_ACTION_MOVE), time); if (dest_row) gtk_tree_path_free (dest_row); g_signal_stop_emission_by_name (widget, "drag_data_received"); }
static void rc_gui_list2_dnd_motion(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer data) { GtkTreeViewDropPosition pos; GtkTreePath *path_drop = NULL; gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW( rc_ui->list2_tree_view), x, y, &path_drop, &pos); if(pos==GTK_TREE_VIEW_DROP_INTO_OR_BEFORE) pos=GTK_TREE_VIEW_DROP_BEFORE; if(pos==GTK_TREE_VIEW_DROP_INTO_OR_AFTER) pos=GTK_TREE_VIEW_DROP_AFTER; if(path_drop) { gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW( rc_ui->list2_tree_view), path_drop, pos); if(pos==GTK_TREE_VIEW_DROP_AFTER) gtk_tree_path_next(path_drop); else gtk_tree_path_prev(path_drop); gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW( rc_ui->list2_tree_view), path_drop, NULL, FALSE, 0.0, 0.0); gtk_tree_path_free(path_drop); } }
G_MODULE_EXPORT void gw_settingswindow_dictionary_drag_motion_cb ( GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gpointer data) { //Declarations GwSettingsWindow *window; GwSettingsWindowPrivate *priv; GtkTreeView *view; GtkTreeViewDropPosition drop_position; GtkTreePath *path; GtkTreeView *source; //Initializations window = GW_SETTINGSWINDOW (gtk_widget_get_ancestor (GTK_WIDGET (widget), GW_TYPE_SETTINGSWINDOW)); g_return_if_fail (window != NULL); priv = window->priv; view = GTK_TREE_VIEW (widget); source = GTK_TREE_VIEW (gtk_drag_get_source_widget (context)); if (source == priv->manage_dictionaries_treeview) { gtk_tree_view_get_dest_row_at_pos (view, x, y, &path, &drop_position); if (path != NULL) { if (drop_position == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE) drop_position = GTK_TREE_VIEW_DROP_BEFORE; else if (drop_position == GTK_TREE_VIEW_DROP_INTO_OR_AFTER) drop_position = GTK_TREE_VIEW_DROP_AFTER; gtk_tree_view_set_drag_dest_row (view, path, drop_position); } } if (path != NULL) gtk_tree_path_free (path); path = NULL; }
static void contact_list_view_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection, guint info, guint time) { EmpathyContactListViewPriv *priv; EmpathyContactList *list; EmpathyContactFactory *factory; McAccount *account; GtkTreeModel *model; GtkTreePath *path; GtkTreeViewDropPosition position; EmpathyContact *contact = NULL; const gchar *id; gchar **strv; gchar *new_group = NULL; gchar *old_group = NULL; gboolean is_row; priv = GET_PRIV (widget); id = (const gchar*) selection->data; DEBUG ("Received %s%s drag & drop contact from roster with id:'%s'", context->action == GDK_ACTION_MOVE ? "move" : "", context->action == GDK_ACTION_COPY ? "copy" : "", id); strv = g_strsplit (id, "/", 2); factory = empathy_contact_factory_new (); account = mc_account_lookup (strv[0]); if (account) { contact = empathy_contact_factory_get_from_id (factory, account, strv[1]); g_object_unref (account); } g_object_unref (factory); g_strfreev (strv); if (!contact) { DEBUG ("No contact found associated with drag & drop"); return; } empathy_contact_run_until_ready (contact, EMPATHY_CONTACT_READY_HANDLE, NULL); model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget)); /* Get source group information. */ if (priv->drag_row) { path = gtk_tree_row_reference_get_path (priv->drag_row); if (path) { old_group = empathy_contact_list_store_get_parent_group (model, path, NULL); gtk_tree_path_free (path); } } /* Get destination group information. */ is_row = gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget), x, y, &path, &position); if (is_row) { new_group = empathy_contact_list_store_get_parent_group (model, path, NULL); gtk_tree_path_free (path); } DEBUG ("contact %s (%d) dragged from '%s' to '%s'", empathy_contact_get_id (contact), empathy_contact_get_handle (contact), old_group, new_group); list = empathy_contact_list_store_get_list_iface (priv->store); if (new_group) { empathy_contact_list_add_to_group (list, contact, new_group); } if (old_group && context->action == GDK_ACTION_MOVE) { empathy_contact_list_remove_from_group (list, contact, old_group); } g_free (old_group); g_free (new_group); gtk_drag_finish (context, TRUE, FALSE, GDK_CURRENT_TIME); }
static gboolean drag_motion_cb (GtkWidget *widget, GdkDragContext *context, int x, int y, guint32 time, EphyNodeView *view) { EphyNode *node; GdkAtom target; GtkTreePath *path; GtkTreeViewDropPosition pos; guint action = 0; int priority; gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget), x, y, &path, &pos); if (!view->priv->have_drag_data) { get_drag_data (view, context, time); } target = gtk_drag_dest_find_target (widget, context, NULL); node = get_node_from_path (view, path); if (target != GDK_NONE && node != NULL) { priority = ephy_node_get_property_int (node, view->priv->priority_prop_id); if (priority != EPHY_NODE_VIEW_ALL_PRIORITY && priority != EPHY_NODE_VIEW_SPECIAL_PRIORITY && ephy_node_get_is_drag_source (node)) { action = gdk_drag_context_get_suggested_action (context); } } if (action) { set_drag_dest_row (view, path); } else { clear_drag_dest_row (view); } if (path) { gtk_tree_path_free (path); } if (view->priv->scroll_id == 0) { view->priv->scroll_id = g_timeout_add (150, scroll_timeout, GTK_TREE_VIEW (view)); } gdk_drag_status (context, action, time); return TRUE; }
static void on_drag_data_received ( GtkWidget *dest_widget, GdkDragContext *drag_context, gint x, gint y, GtkSelectionData *sel_data, guint info, guint time) { FmPlacesView* view = FM_PLACES_VIEW(dest_widget); GtkTreePath* dest_tp = NULL; GtkTreeViewDropPosition pos; gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(view), x, y, &dest_tp, &pos); switch(info) { case FM_DND_DEST_TARGET_BOOOKMARK: if(get_bookmark_drag_dest(view, &dest_tp, &pos)) /* got the drop position */ { GtkTreePath* src_tp; /* get the source row */ gboolean ret = gtk_tree_get_row_drag_data(sel_data, NULL, &src_tp); if(ret) { /* don't do anything if source and dest are the same row */ if(G_UNLIKELY(gtk_tree_path_compare(src_tp, dest_tp) == 0)) ret = FALSE; else { /* don't do anything if this is not a bookmark item */ if(!fm_places_model_path_is_bookmark(FM_PLACES_MODEL(model), src_tp)) ret = FALSE; } if(ret) { GtkTreeIter src_it, dest_it; FmPlaceItem* item = NULL; ret = FALSE; /* get the source bookmark item */ if(gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &src_it, src_tp)) gtk_tree_model_get(GTK_TREE_MODEL(model), &src_it, FM_PLACES_MODEL_COL_INFO, &item, -1); if(item) { /* move it to destination position */ if(gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &dest_it, dest_tp)) { int new_pos, sep_pos; /* get index of the separator */ const GtkTreePath* sep_tp = fm_places_model_get_separator_path(FM_PLACES_MODEL(model)); sep_pos = gtk_tree_path_get_indices(sep_tp)[0]; if(pos == GTK_TREE_VIEW_DROP_BEFORE) gtk_list_store_move_before(model, &src_it, &dest_it); else gtk_list_store_move_after(model, &src_it, &dest_it); new_pos = gtk_tree_path_get_indices(dest_tp)[0] - sep_pos - 1; /* reorder the bookmark item */ fm_bookmarks_reorder(FM_PLACES_MODEL(model)->bookmarks, item->bm_item, new_pos); ret = TRUE; } } } gtk_tree_path_free(src_tp); } gtk_drag_finish(drag_context, ret, FALSE, time); } break; default: /* check if files are received. */ fm_dnd_dest_drag_data_received(view->dnd_dest, drag_context, x, y, sel_data, info, time); break; } if(dest_tp) gtk_tree_path_free(dest_tp); }
static gboolean on_drag_motion (GtkWidget *dest_widget, GdkDragContext *drag_context, gint x, gint y, guint time) { FmPlacesView* view = FM_PLACES_VIEW(dest_widget); /* fm_drag_context_has_target_name(drag_context, "GTK_TREE_MODEL_ROW"); */ GdkAtom target; GtkTreeViewDropPosition pos; GtkTreePath* tp, *sep; gboolean ret = FALSE; GdkDragAction action = 0; target = gtk_drag_dest_find_target(dest_widget, drag_context, NULL); if(target == GDK_NONE) return FALSE; gtk_tree_view_get_dest_row_at_pos((GtkTreeView*)view, x, y, &tp, &pos); /* handle reordering bookmark items first */ if(target == gdk_atom_intern_static_string("GTK_TREE_MODEL_ROW")) { /* bookmark item is being dragged */ ret = get_bookmark_drag_dest(view, &tp, &pos); action = ret ? GDK_ACTION_MOVE : 0; /* bookmark items can only be moved */ } /* try FmDndDest */ else if(fm_dnd_dest_is_target_supported(view->dnd_dest, target)) { /* the user is dragging files. get FmFileInfo of drop site. */ if(pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE || pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER) /* drag into items */ { FmPlaceItem* item = NULL; GtkTreeIter it; /* FIXME: handle adding bookmarks with Dnd */ if(tp && gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &it, tp)) gtk_tree_model_get(GTK_TREE_MODEL(model), &it, FM_PLACES_MODEL_COL_INFO, &item, -1); fm_dnd_dest_set_dest_file(view->dnd_dest, item && item->fi ? item->fi : NULL); action = fm_dnd_dest_get_default_action(view->dnd_dest, drag_context, target); ret = action != 0; } else /* drop between items, create bookmark items for dragged files */ { if( (!tp || fm_places_model_path_is_bookmark(FM_PLACES_MODEL(model), tp)) && get_bookmark_drag_dest(view, &tp, &pos)) /* tp is after separator */ { action = GDK_ACTION_LINK; ret = TRUE; } else { action = 0; ret = FALSE; } } } gdk_drag_status(drag_context, action, time); if(ret) gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW(view), tp, pos); else gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW(view), NULL, 0); if(tp) gtk_tree_path_free(tp); return ret; }
static void rc_gui_list1_dnd_data_received(GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *seldata, guint info, guint time, gpointer data) { gint source = -1; gint target = 0; gint *index = NULL; gint i = 0; gint length = 0; gboolean end_flag = FALSE; GtkTreeViewDropPosition pos; GtkTreePath *path_start = NULL, *path_drop = NULL; GtkTreeIter iter_start, iter_drop; GList *path_list = NULL; GList *list_foreach = NULL; GtkTreePath **path_array; gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW( rc_ui->list1_tree_view), x,y, &path_drop, &pos); if(path_drop!=NULL) { gtk_tree_model_get_iter(rc_ui->list1_tree_model, &iter_drop, path_drop); index = gtk_tree_path_get_indices(path_drop); target = index[0]; gtk_tree_path_free(path_drop); } else end_flag = TRUE; switch(info) { case 0: { source = *(gtk_selection_data_get_data(seldata)); if(pos==GTK_TREE_VIEW_DROP_AFTER || pos==GTK_TREE_VIEW_DROP_INTO_OR_AFTER) { target++; if(!gtk_tree_model_iter_next(rc_ui->list1_tree_model, &iter_drop)) end_flag = TRUE; } path_start = gtk_tree_path_new_from_indices(source, -1); gtk_tree_model_get_iter(rc_ui->list1_tree_model, &iter_start, path_start); gtk_tree_path_free(path_start); if(!end_flag) gtk_list_store_move_before(GTK_LIST_STORE( rc_ui->list1_tree_model), &iter_start, &iter_drop); else gtk_list_store_move_before(GTK_LIST_STORE( rc_ui->list1_tree_model), &iter_start, NULL); break; } case 1: { if(target==rc_gui_list1_get_selected_index()) break; memcpy(&path_list, gtk_selection_data_get_data(seldata), sizeof(path_list)); if(path_list==NULL) break; length = g_list_length(path_list); path_list = g_list_sort_with_data(path_list, (GCompareDataFunc) gtk_tree_path_compare, NULL); path_array = g_new0(GtkTreePath *, length); for(list_foreach=path_list, i=0;list_foreach!=NULL; list_foreach=g_list_next(list_foreach), i++) { path_array[i] = list_foreach->data; } rc_plist_plist_move2(rc_gui_list1_get_selected_index(), path_array, length, target); break; } default: break; } }
static void bar_pane_keywords_dnd_receive(GtkWidget *tree_view, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint info, guint time, gpointer data) { PaneKeywordsData *pkd = data; GtkTreePath *tpath = NULL; GtkTreeViewDropPosition pos; GtkTreeModel *model; GtkTreeModel *keyword_tree; gboolean src_valid = FALSE; GList *new_keywords = NULL; GList *work; /* iterators for keyword_tree */ GtkTreeIter src_kw_iter; GtkTreeIter dest_kw_iter; GtkTreeIter new_kw_iter; g_signal_stop_emission_by_name(tree_view, "drag_data_received"); model = gtk_tree_view_get_model(GTK_TREE_VIEW(tree_view)); keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(tree_view), x, y, &tpath, &pos); gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW(tree_view), NULL, pos); switch (info) { case TARGET_APP_KEYWORD_PATH: { GList *path = *(gpointer *)gtk_selection_data_get_data(selection_data); src_valid = keyword_tree_get_iter(keyword_tree, &src_kw_iter, path); string_list_free(path); break; } default: new_keywords = string_to_keywords_list((gchar *)gtk_selection_data_get_data(selection_data)); break; } if (tpath) { GtkTreeIter dest_iter; gtk_tree_model_get_iter(model, &dest_iter, tpath); gtk_tree_path_free(tpath); gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &dest_kw_iter, &dest_iter); if (src_valid && gtk_tree_store_is_ancestor(GTK_TREE_STORE(keyword_tree), &src_kw_iter, &dest_kw_iter)) { /* can't move to it's own child */ return; } if (src_valid && keyword_compare(keyword_tree, &src_kw_iter, &dest_kw_iter) == 0) { /* can't move to itself */ return; } if ((pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE || pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER) && !gtk_tree_model_iter_has_child(keyword_tree, &dest_kw_iter)) { /* the node has no children, all keywords can be added */ gtk_tree_store_append(GTK_TREE_STORE(keyword_tree), &new_kw_iter, &dest_kw_iter); } else { if (src_valid && !bar_pane_keywords_dnd_can_move(keyword_tree, &src_kw_iter, &dest_kw_iter)) { /* the keyword can't be moved if the same name already exist */ return; } if (new_keywords && !bar_pane_keywords_dnd_skip_existing(keyword_tree, &dest_kw_iter, &new_keywords)) { /* the keywords can't be added if the same name already exist */ return; } switch (pos) { case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: case GTK_TREE_VIEW_DROP_BEFORE: gtk_tree_store_insert_before(GTK_TREE_STORE(keyword_tree), &new_kw_iter, NULL, &dest_kw_iter); break; case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: case GTK_TREE_VIEW_DROP_AFTER: gtk_tree_store_insert_after(GTK_TREE_STORE(keyword_tree), &new_kw_iter, NULL, &dest_kw_iter); break; } } } else { if (src_valid && !bar_pane_keywords_dnd_can_move(keyword_tree, &src_kw_iter, NULL)) { /* the keyword can't be moved if the same name already exist */ return; } if (new_keywords && !bar_pane_keywords_dnd_skip_existing(keyword_tree, NULL, &new_keywords)) { /* the keywords can't be added if the same name already exist */ return; } gtk_tree_store_append(GTK_TREE_STORE(keyword_tree), &new_kw_iter, NULL); } if (src_valid) { keyword_move_recursive(GTK_TREE_STORE(keyword_tree), &new_kw_iter, &src_kw_iter); } work = new_keywords; while (work) { gchar *keyword = work->data; keyword_set(GTK_TREE_STORE(keyword_tree), &new_kw_iter, keyword, TRUE); work = work->next; if (work) { GtkTreeIter add; gtk_tree_store_insert_after(GTK_TREE_STORE(keyword_tree), &add, NULL, &new_kw_iter); new_kw_iter = add; } } string_list_free(new_keywords); bar_keyword_tree_sync(pkd); }
static void bar_pane_keywords_menu_popup(GtkWidget *widget, PaneKeywordsData *pkd, gint x, gint y) { GtkWidget *menu; GtkWidget *item; GtkWidget *submenu; GtkTreeViewDropPosition pos; if (pkd->click_tpath) gtk_tree_path_free(pkd->click_tpath); pkd->click_tpath = NULL; gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(pkd->keyword_treeview), x, y, &pkd->click_tpath, &pos); menu = popup_menu_short_lived(); menu_item_add_stock(menu, _("Add keyword"), GTK_STOCK_EDIT, G_CALLBACK(bar_pane_keywords_add_dialog_cb), pkd); menu_item_add_divider(menu); menu_item_add(menu, _("Add keyword to all selected images"), G_CALLBACK(bar_pane_keywords_add_to_selected_cb), pkd); menu_item_add_divider(menu); if (pkd->click_tpath) { /* for the entry */ gchar *text; gchar *mark; gint i; GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview)); GtkTreeIter iter; gtk_tree_model_get_iter(model, &iter, pkd->click_tpath); gchar *name; gtk_tree_model_get(model, &iter, FILTER_KEYWORD_COLUMN_NAME, &name, FILTER_KEYWORD_COLUMN_MARK, &mark, -1); text = g_strdup_printf(_("Hide \"%s\""), name); menu_item_add_stock(menu, text, GTK_STOCK_EDIT, G_CALLBACK(bar_pane_keywords_hide_cb), pkd); g_free(text); submenu = gtk_menu_new(); for (i = 0; i < FILEDATA_MARKS_SIZE; i++) { text = g_strdup_printf(_("Mark %d"), i + 1); item = menu_item_add(submenu, text, G_CALLBACK(bar_pane_keywords_connect_mark_cb), pkd); g_object_set_data(G_OBJECT(item), "mark", GINT_TO_POINTER(i + 1)); g_free(text); } text = g_strdup_printf(_("Connect \"%s\" to mark"), name); item = menu_item_add(menu, text, NULL, NULL); gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); g_free(text); menu_item_add_divider(menu); text = g_strdup_printf(_("Edit \"%s\""), name); menu_item_add_stock(menu, text, GTK_STOCK_EDIT, G_CALLBACK(bar_pane_keywords_edit_dialog_cb), pkd); g_free(text); text = g_strdup_printf(_("Remove \"%s\""), name); menu_item_add_stock(menu, text, GTK_STOCK_DELETE, G_CALLBACK(bar_pane_keywords_delete_cb), pkd); g_free(text); if (mark && mark[0]) { text = g_strdup_printf(_("Disconnect \"%s\" from mark %s"), name, mark); menu_item_add_stock(menu, text, GTK_STOCK_DELETE, G_CALLBACK(bar_pane_keywords_connect_mark_cb), pkd); g_free(text); } menu_item_add_divider(menu); g_free(mark); g_free(name); } /* for the pane */ menu_item_add(menu, _("Expand checked"), G_CALLBACK(bar_pane_keywords_expand_checked_cb), pkd); menu_item_add(menu, _("Collapse unchecked"), G_CALLBACK(bar_pane_keywords_collapse_unchecked_cb), pkd); menu_item_add(menu, _("Hide unchecked"), G_CALLBACK(bar_pane_keywords_hide_unchecked_cb), pkd); menu_item_add(menu, _("Show all"), G_CALLBACK(bar_pane_keywords_show_all_cb), pkd); submenu = gtk_menu_new(); item = menu_item_add(menu, _("On any change"), NULL, NULL); gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); menu_item_add_check(submenu, _("Expand checked"), pkd->expand_checked, G_CALLBACK(bar_pane_keywords_expand_checked_toggle_cb), pkd); menu_item_add_check(submenu, _("Collapse unchecked"), pkd->collapse_unchecked, G_CALLBACK(bar_pane_keywords_collapse_unchecked_toggle_cb), pkd); menu_item_add_check(submenu, _("Hide unchecked"), pkd->hide_unchecked, G_CALLBACK(bar_pane_keywords_hide_unchecked_toggle_cb), pkd); gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, GDK_CURRENT_TIME); }
// This little bit is needed to prevent the default drag motion // handler from expanding rows if you hover over them while // dragging. // Also controls where valid drop locations are G_MODULE_EXPORT gboolean queue_drag_motion_cb( GtkTreeView *tv, GdkDragContext *ctx, gint x, gint y, guint time, signal_user_data_t *ud) { GtkTreePath *path = NULL; GtkTreeViewDropPosition pos; gint *indices, row, status, finished; GValue *js; GtkTreeIter iter; GtkTreeView *srctv; GtkTreeModel *model; GtkTreeSelection *select; GtkWidget *widget; widget = gtk_drag_get_source_widget(ctx); if (widget == NULL || widget != GTK_WIDGET(tv)) return TRUE; // This bit checks to see if the source is allowed to be // moved. Only pending and canceled items may be moved. srctv = GTK_TREE_VIEW(gtk_drag_get_source_widget(ctx)); select = gtk_tree_view_get_selection (srctv); gtk_tree_selection_get_selected (select, &model, &iter); path = gtk_tree_model_get_path (model, &iter); indices = gtk_tree_path_get_indices(path); row = indices[0]; gtk_tree_path_free(path); js = ghb_array_get_nth(ud->queue, row); status = ghb_settings_get_int(js, "job_status"); if (status != GHB_QUEUE_PENDING && status != GHB_QUEUE_CANCELED) { gdk_drag_status(ctx, 0, time); return TRUE; } // The reset checks that the destination is a valid position // in the list. Can not move above any finished or running items gtk_tree_view_get_dest_row_at_pos (tv, x, y, &path, &pos); if (path == NULL) { gdk_drag_status(ctx, GDK_ACTION_MOVE, time); return TRUE; } // Don't allow *drop into* if (pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE) pos = GTK_TREE_VIEW_DROP_BEFORE; if (pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER) pos = GTK_TREE_VIEW_DROP_AFTER; // Don't allow droping int child items if (gtk_tree_path_get_depth(path) > 1) { gtk_tree_path_up(path); pos = GTK_TREE_VIEW_DROP_AFTER; } indices = gtk_tree_path_get_indices(path); row = indices[0]; js = ghb_array_get_nth(ud->queue, row); finished = find_last_finished(ud->queue); if (row < finished) { gtk_tree_path_free(path); gdk_drag_status(ctx, 0, time); return TRUE; } if (pos != GTK_TREE_VIEW_DROP_AFTER && row == finished) { gtk_tree_path_free(path); gdk_drag_status(ctx, 0, time); return TRUE; } gtk_tree_view_set_drag_dest_row(tv, path, pos); gtk_tree_path_free(path); gdk_drag_status(ctx, GDK_ACTION_MOVE, time); return TRUE; }
// retrieve data TILP_EXPORT void on_treeview1_drag_data_received(GtkWidget * widget, GdkDragContext * drag_context, gint x, gint y, GtkSelectionData * data, guint info, guint _time, gpointer user_data) { GtkTreeView *view = GTK_TREE_VIEW(widget); GtkTreeModel *model = gtk_tree_view_get_model(view); GtkTreePath *path; GtkTreeViewDropPosition pos; GtkTreeIter iter; VarEntry *ve; gchar *name; gchar *target = NULL; gboolean success = FALSE; if ((data->length >= 0) && (data->format == 8)) { if (drag_context->action == GDK_ACTION_ASK) { drag_context->action = GDK_ACTION_COPY; } if (info == TARGET_TEXT_URI_LIST) { int i; gchar **list; //list = g_uri_list_extract_uris((gchar *)gtk_selection_data_get_data(data)); list = gtk_selection_data_get_uris(data); tilp_local_selection_destroy(); for (i = 0;list[i] != NULL; i++) { name = g_filename_from_uri(list[i], NULL, NULL); tilp_local_selection_add(name); } g_strfreev(list); } gtk_tree_view_get_dest_row_at_pos(view, x, y, &path, &pos); if (path == NULL) goto end; gtk_tree_model_get_iter(model, &iter, path); gtk_tree_model_get(model, &iter, COLUMN_DATA, &ve, -1); gtk_tree_model_get(model, &iter, COLUMN_NAME, &name, -1); //g_print("Received \"%s\" as selection information.\n", name); if(strchr(name, '#')) // Calc { } else if(!strcmp(name, NODE4)) // Applications { // send to flash target=(char *)"<FLASH>"; } else if (ve && tifiles_has_folder(options.calc_model)) { // send to folder if(!strcmp(ve->folder, "")) target = ve->name; else target = ve->folder; } else if(!strcmp(name, NODE2)) // Operating System { target=(char *)""; } else { if(options.calc_model == CALC_NSPIRE) { gif->msg_box1(_("Error"), "You have to drag&drop to a target folder!"); return; } else { // send standard target=(char *)""; } } if (target!=NULL) on_tilp_send(target); tilp_local_selection_destroy(); success = TRUE; } end: gtk_drag_finish(drag_context, success, FALSE, _time); return; }
G_MODULE_EXPORT void queue_drag_cb( GtkTreeView *dstwidget, GdkDragContext *dc, gint x, gint y, GtkSelectionData *selection_data, guint info, guint t, signal_user_data_t *ud) { GtkTreePath *path = NULL; //GtkTreeModel *model; GtkTreeViewDropPosition pos; GtkTreeIter dstiter, srciter; gint *indices, row; GValue *js; GtkTreeModel *dstmodel = gtk_tree_view_get_model(dstwidget); g_debug("queue_drag_cb ()"); // This doesn't work here for some reason... // gtk_tree_view_get_drag_dest_row(dstwidget, &path, &pos); gtk_tree_view_get_dest_row_at_pos (dstwidget, x, y, &path, &pos); // This little hack is needed because attempting to drop after // the last item gives us no path or pos. if (path == NULL) { gint n_children; n_children = gtk_tree_model_iter_n_children(dstmodel, NULL); if (n_children) { pos = GTK_TREE_VIEW_DROP_AFTER; path = gtk_tree_path_new_from_indices(n_children-1, -1); } else { pos = GTK_TREE_VIEW_DROP_BEFORE; path = gtk_tree_path_new_from_indices(0, -1); } } if (path) { if (gtk_tree_path_get_depth(path) > 1) gtk_tree_path_up(path); if (gtk_tree_model_get_iter (dstmodel, &dstiter, path)) { GtkTreeIter iter; GtkTreeView *srcwidget; GtkTreeModel *srcmodel; GtkTreeSelection *select; GtkTreePath *srcpath = NULL; GtkTreePath *dstpath = NULL; srcwidget = GTK_TREE_VIEW(gtk_drag_get_source_widget(dc)); //srcmodel = gtk_tree_view_get_model(srcwidget); select = gtk_tree_view_get_selection (srcwidget); gtk_tree_selection_get_selected (select, &srcmodel, &srciter); srcpath = gtk_tree_model_get_path (srcmodel, &srciter); indices = gtk_tree_path_get_indices(srcpath); row = indices[0]; gtk_tree_path_free(srcpath); js = ghb_array_get_nth(ud->queue, row); switch (pos) { case GTK_TREE_VIEW_DROP_BEFORE: case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: gtk_tree_store_insert_before (GTK_TREE_STORE (dstmodel), &iter, NULL, &dstiter); break; case GTK_TREE_VIEW_DROP_AFTER: case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: gtk_tree_store_insert_after (GTK_TREE_STORE (dstmodel), &iter, NULL, &dstiter); break; default: break; } // Reset job to pending ghb_settings_set_int(js, "job_status", GHB_QUEUE_PENDING); add_to_queue_list(ud, js, &iter); dstpath = gtk_tree_model_get_path (dstmodel, &iter); indices = gtk_tree_path_get_indices(dstpath); row = indices[0]; gtk_tree_path_free(dstpath); ghb_array_insert(ud->queue, row, js); srcpath = gtk_tree_model_get_path (srcmodel, &srciter); indices = gtk_tree_path_get_indices(srcpath); row = indices[0]; gtk_tree_path_free(srcpath); ghb_array_remove(ud->queue, row); gtk_tree_store_remove (GTK_TREE_STORE (srcmodel), &srciter); ghb_save_queue(ud->queue); } gtk_tree_path_free(path); } }
static void drag_data_received_cb (GtkWidget *widget, GdkDragContext *context, int x, int y, GtkSelectionData *selection_data, guint info, guint32 time, EphyNodeView *view) { GtkTreeViewDropPosition pos; /* x and y here are valid only on drop ! */ if ((gtk_selection_data_get_length (selection_data) <= 0) || (gtk_selection_data_get_data (selection_data) == NULL)) { return; } /* appease GtkTreeView by preventing its drag_data_receive * from being called */ g_signal_stop_emission_by_name (view, "drag_data_received"); if (!view->priv->have_drag_data) { view->priv->have_drag_data = TRUE; view->priv->drag_data = gtk_selection_data_copy (selection_data); } if (view->priv->drop_occurred) { EphyNode *node; char **uris; gboolean success = FALSE; GtkTreePath *path; if (gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget), x, y, &path, &pos) == FALSE) { return; } node = get_node_from_path (view, path); if (node == NULL) return; uris = gtk_selection_data_get_uris (selection_data); if (uris != NULL && ephy_node_get_is_drag_dest (node)) { /* FIXME fill success */ g_signal_emit (G_OBJECT (view), ephy_node_view_signals[NODE_DROPPED], 0, node, uris); g_strfreev (uris); } view->priv->drop_occurred = FALSE; free_drag_data (view); gtk_drag_finish (context, success, FALSE, time); if (path) { gtk_tree_path_free (path); } } }
static gboolean drag_motion_callback (GtkWidget *widget, GdkDragContext *context, int x, int y, guint32 time, gpointer data) { NautilusTreeViewDragDest *dest; GtkTreePath *path; GtkTreePath *drop_path, *old_drop_path; GtkTreeViewDropPosition pos; GdkWindow *bin_window; guint action; gboolean res = TRUE; dest = NAUTILUS_TREE_VIEW_DRAG_DEST (data); gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget), x, y, &path, &pos); if (pos == GTK_TREE_VIEW_DROP_BEFORE || pos == GTK_TREE_VIEW_DROP_AFTER) { gtk_tree_path_free (path); path = NULL; } if (!dest->details->have_drag_data) { res = get_drag_data (dest, context, time); } if (!res) { return FALSE; } drop_path = get_drop_path (dest, path); action = 0; bin_window = gtk_tree_view_get_bin_window (GTK_TREE_VIEW (widget)); if (bin_window != NULL) { int bin_x, bin_y; gdk_window_get_position (bin_window, &bin_x, &bin_y); if (bin_y <= y) { /* ignore drags on the header */ action = get_drop_action (dest, context, drop_path); } } gtk_tree_view_get_drag_dest_row (GTK_TREE_VIEW (widget), &old_drop_path, NULL); if (action) { set_drag_dest_row (dest, drop_path); check_hover_expand_timer (dest, path, drop_path, old_drop_path); } else { clear_drag_dest_row (dest); remove_hover_timer (dest); remove_expand_timer (dest); } if (path) { gtk_tree_path_free (path); } if (drop_path) { gtk_tree_path_free (drop_path); } if (old_drop_path) { gtk_tree_path_free (old_drop_path); } if (dest->details->scroll_id == 0) { dest->details->scroll_id = g_timeout_add (150, scroll_timeout, dest->details->tree_view); } gdk_drag_status (context, action, time); return TRUE; }