static void select_or_unselect_range(GtkTreeSelection *selection, guint from, guint to, gboolean select) { if (from == to) return; GtkTreePath *pathfrom = gtk_tree_path_new(); gtk_tree_path_append_index(pathfrom, from); if (from+1 == to) { if (select) gtk_tree_selection_select_path(selection, pathfrom); else gtk_tree_selection_unselect_path(selection, pathfrom); } else { GtkTreePath *pathto = gtk_tree_path_new(); gtk_tree_path_append_index(pathto, to); if (select) gtk_tree_selection_select_range(selection, pathfrom, pathto); else gtk_tree_selection_unselect_range(selection, pathfrom, pathto); gtk_tree_path_free(pathto); } gtk_tree_path_free(pathfrom); }
gboolean listbox_drag (GtkWidget *listbox, GdkEventMotion *event, gpointer data) { gint x, y; GdkModifierType state; GtkTreeView *view = GTK_TREE_VIEW(listbox); GtkTreePath *path; if (event->is_hint) { gdk_window_get_pointer(event->window, &x, &y, &state); } else { x = event->x; y = event->y; state = event->state; } if ((state & GDK_BUTTON1_MASK) && gtk_tree_view_get_path_at_pos(view, x, y, &path, NULL, NULL, NULL)) { GtkTreeSelection *select = NULL; GtkTreePath *anchor_path = NULL; gchar *anchor_id = NULL; gint row; int anchor; static gint lastrow; anchor = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(listbox), "active_row")); row = tree_path_get_row_number(path); select = gtk_tree_view_get_selection(view); if (select == NULL) { return FALSE; } anchor_id = g_strdup_printf("%d", anchor); anchor_path = gtk_tree_path_new_from_string(anchor_id); g_free(anchor_id); if (row != lastrow) { gtk_tree_selection_unselect_all(select); gtk_tree_selection_select_range(select, anchor_path, path); } gtk_tree_path_free(path); gtk_tree_path_free(anchor_path); lastrow = row; } return FALSE; }
int clip_GTK_TREESELECTIONSELECTRANGE(ClipMachine * cm) { C_object *ctreesel = _fetch_co_arg(cm); C_object *cpath1 = _fetch_cobject(cm, _clip_spar(cm, 2)); C_object *cpath2 = _fetch_cobject(cm, _clip_spar(cm, 3)); CHECKOPT2(1, MAP_t, NUMERIC_t); CHECKCOBJ(ctreesel,GTK_IS_TREE_SELECTION(ctreesel->object)); CHECKCOBJ(cpath1,GTK_IS_TREE_PATH(cpath1->object)); CHECKCOBJ(cpath2,GTK_IS_TREE_PATH(cpath2->object)); gtk_tree_selection_select_range(GTK_TREE_SELECTION(ctreesel->object), GTK_TREE_PATH(cpath1->object), GTK_TREE_PATH(cpath2->object)); return 0; err: return 1; }
void ctree_select_vars(gint action) { GtkTreeView *view; GtkTreeModel *model; GtkTreePath *path = path_to_drag; GtkTreeIter parent, start_iter, end_iter, iter; view = GTK_TREE_VIEW(ctree_wnd); model = gtk_tree_view_get_model(view); // select var beneath a folder gtk_tree_model_get_iter(model, &parent, path); if (gtk_tree_model_iter_has_child(model, &parent)) { GtkTreeSelection *sel; GtkTreePath *start_path, *end_path; gint n; gboolean valid; sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(ctree_wnd)); n = gtk_tree_model_iter_n_children(model, &parent); valid = gtk_tree_model_iter_children(model, &start_iter, &parent); start_path = gtk_tree_model_get_path(model, &start_iter); valid = gtk_tree_model_iter_nth_child(model, &end_iter, &parent, n - 1); if(gtk_tree_model_iter_has_child(model, &end_iter)) { n = gtk_tree_model_iter_n_children(model, &end_iter); valid = gtk_tree_model_iter_nth_child(model, &iter, &end_iter, n - 1); memcpy(&end_iter, &iter, sizeof(GtkTreeIter)); } end_path = gtk_tree_model_get_path(model, &end_iter); if (!action) gtk_tree_selection_unselect_range(sel, start_path, end_path); else { gtk_tree_selection_select_range(sel, start_path, end_path); } gtk_tree_path_free(start_path); gtk_tree_path_free(end_path); } }
int clip_GTK_TREESELECTIONSELECTRANGE(ClipMachine * ClipMachineMemory) { C_object *ctreesel = _fetch_co_arg(ClipMachineMemory); C_object *cpath1 = _fetch_cobject(ClipMachineMemory, _clip_spar(ClipMachineMemory, 2)); C_object *cpath2 = _fetch_cobject(ClipMachineMemory, _clip_spar(ClipMachineMemory, 3)); CHECKOPT2(1, MAP_type_of_ClipVarType, NUMERIC_type_of_ClipVarType); CHECKCOBJ(ctreesel, GTK_IS_TREE_SELECTION(ctreesel->object)); CHECKCOBJ(cpath1, GTK_IS_TREE_PATH(cpath1->object)); CHECKCOBJ(cpath2, GTK_IS_TREE_PATH(cpath2->object)); gtk_tree_selection_select_range(GTK_TREE_SELECTION(ctreesel->object), GTK_TREE_PATH(cpath1->object), GTK_TREE_PATH(cpath2->object)); return 0; err: return 1; }
static void select_range_path_str(GtkWidget *w, char *from, char *to) { GtkTreePath *path1, *path2; GtkTreeSelection *sel; sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(w)); path1 = gtk_tree_path_new_from_string(from); if (! path1) return; path2 = gtk_tree_path_new_from_string(to); if (! path2) { gtk_tree_path_free(path1); return; } gtk_tree_selection_select_range(sel, path1, path2); gtk_tree_path_free(path2); gtk_tree_path_free(path1); }
static gboolean exo_tree_view_single_click_timeout (gpointer user_data) { GtkTreeViewColumn *cursor_column; GtkTreeSelection *selection; GtkTreeModel *model; GtkTreePath *cursor_path; GtkTreeIter iter; ExoTreeView *tree_view = EXO_TREE_VIEW (user_data); gboolean hover_path_selected; GList *rows; GList *lp; //GDK_THREADS_ENTER (); //sfm not needed because called from g_idle? /* verify that we are in single-click mode, have focus and a hover path */ if (gtk_widget_has_focus (GTK_WIDGET (tree_view)) && tree_view->priv->single_click && tree_view->priv->hover_path != NULL) { /* transform the hover_path to a tree iterator */ model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)); if (model != NULL && gtk_tree_model_get_iter (model, &iter, tree_view->priv->hover_path)) { /* determine the current cursor path/column */ gtk_tree_view_get_cursor (GTK_TREE_VIEW (tree_view), &cursor_path, &cursor_column); /* be sure the row is fully visible */ gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (tree_view), tree_view->priv->hover_path, 0, //sfm was cursor_column - caused horizontal scroll FALSE, 0.0f, 0.0f); /* determine the selection and change it appropriately */ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); if (gtk_tree_selection_get_mode (selection) == GTK_SELECTION_NONE) { /* just place the cursor on the row */ gtk_tree_view_set_cursor (GTK_TREE_VIEW (tree_view), tree_view->priv->hover_path, cursor_column, FALSE); } else if ((tree_view->priv->single_click_timeout_state & GDK_SHIFT_MASK) != 0 && gtk_tree_selection_get_mode (selection) == GTK_SELECTION_MULTIPLE) { /* check if the item is not already selected (otherwise do nothing) */ if (!gtk_tree_selection_path_is_selected (selection, tree_view->priv->hover_path)) { /* unselect all previously selected items */ gtk_tree_selection_unselect_all (selection); /* since we cannot access the anchor of a GtkTreeView, we * use the cursor instead which is usually the same row. */ if (G_UNLIKELY (cursor_path == NULL)) { /* place the cursor on the new row */ gtk_tree_view_set_cursor (GTK_TREE_VIEW (tree_view), tree_view->priv->hover_path, cursor_column, FALSE); } else { /* select all between the cursor and the current row */ gtk_tree_selection_select_range (selection, tree_view->priv->hover_path, cursor_path); } } } else { /* remember the previously selected rows as set_cursor() clears the selection */ rows = gtk_tree_selection_get_selected_rows (selection, NULL); /* check if the hover path is selected (as it will be selected after the set_cursor() call) */ hover_path_selected = gtk_tree_selection_path_is_selected (selection, tree_view->priv->hover_path); /* place the cursor on the hover row */ gtk_tree_view_set_cursor (GTK_TREE_VIEW (tree_view), tree_view->priv->hover_path, cursor_column, FALSE); /* restore the previous selection */ for (lp = rows; lp != NULL; lp = lp->next) { gtk_tree_selection_select_path (selection, lp->data); gtk_tree_path_free (lp->data); } g_list_free (rows); /* check what to do */ if ((gtk_tree_selection_get_mode (selection) == GTK_SELECTION_MULTIPLE || (gtk_tree_selection_get_mode (selection) == GTK_SELECTION_SINGLE && hover_path_selected)) && (tree_view->priv->single_click_timeout_state & GDK_CONTROL_MASK) != 0) { /* toggle the selection state of the row */ if (G_UNLIKELY (hover_path_selected)) gtk_tree_selection_unselect_path (selection, tree_view->priv->hover_path); else gtk_tree_selection_select_path (selection, tree_view->priv->hover_path); } else if (G_UNLIKELY (!hover_path_selected)) { /* unselect all other rows */ gtk_tree_selection_unselect_all (selection); /* select only the hover row */ gtk_tree_selection_select_path (selection, tree_view->priv->hover_path); } } /* cleanup */ if (G_LIKELY (cursor_path != NULL)) gtk_tree_path_free (cursor_path); } } //GDK_THREADS_LEAVE (); return FALSE; }