Hello,
I have two (2) questions about the GtkColumnView on GTK4.
Question 1:
How do I find the data/row when right-clicking on the GtkColumnView listing?
Meaning, how do I find the clicked GListStore item at mouse (x, y) position?
My example program creates a popup-menu at the right-click (x,y) location, but I cannot find the corresponding GtkColumnView data. I want to delete the row and data.
See the example code (colview1.c).
Notice:
In GtkTreeView widget on GTK3/GTK4 I can find the clicked GtkTreePath with these lines:
gtk_tree_view_convert_widget_to_bin_window_coords(tv, … x, y, …&xx, &yy…)
gtk_tree_view_get_path_at_pos(tv, xx, yy…)
But the new GtkColumnView widget has no equivalent option, or does it have?
Question 2:
Problem with sorting when clicking on the headers (GtklColumnView).
My example program (colview1.c) has column headers, but the code does not sort data when clicked on the column-header. It displays and changes a small arrow on the headers, but does no sorting.
I have added my own sort-function on column headers !
Why does’t it work?
See the example code (colview1.c).
GtkColumnView:
I found a GRAZY way to find the clicked row.
I do not mean the selected row here. I mean the RIGHT-MOUSE clicked row. That is a different thing.
I find the position (clicked row and item) by counting Widget heights and Y-positions.
LOOL, I MUST BE GRAZY … OR THIS TOOL-KIT IS IT. SURELY IT IS !
static void button_pressed_cb(GtkGestureClick *gesture, gint n_press, gdouble x, gdouble y, MainData *main) {
GtkWidget *colview = gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture));
const gchar *colview_type_s = G_OBJECT_TYPE_NAME(colview);
if (strcmp(colview_type_s, "GtkColumnView") != 0) return;
gint line_no = -1;
GtkWidget *child = gtk_widget_get_first_child(colview);
GtkAllocation header_alloc = {0, 0, 0, 0};
while (GTK_IS_WIDGET(child)) {
if (strcmp(G_OBJECT_TYPE_NAME(child), "GtkListItemWidget") == 0) {
gtk_widget_get_allocation(child, &header_alloc);
}
//if (G_OBJECT_TYPE(child) == GTK_TYPE_COLUMN_LIST_VIEW) {
if (strcmp(G_OBJECT_TYPE_NAME(child), "GtkColumnListView") == 0) {
line_no = check_list_widgets(child, y, header_alloc.y + header_alloc.height);
// Break out the loop
break;
}
child = gtk_widget_get_next_sibling(child);
}
if (line_no > -1) {
GFileInfo *finfo = g_list_model_get_item(G_LIST_MODEL(gtk_column_view_get_model(colview)), line_no);
if (!G_IS_FILE_INFO(finfo)) {
g_warning("Cannot read GFileInfo at row #%d\n", line_no);
return;
}
const gchar *name = g_file_info_get_name(finfo);
g_print("You clicked on %s\n", name);
g_object_unref(finfo);
}
}