implement listview selection event (GTK) newapi

Mon, 28 Oct 2024 08:33:22 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 28 Oct 2024 08:33:22 +0100
branch
newapi
changeset 362
59e94e97ba68
parent 361
16c8b9ea3aa3
child 363
cd221f1e9ff6

implement listview selection event (GTK)

ui/gtk/list.c file | annotate | diff | comparison | revisions
--- a/ui/gtk/list.c	Mon Oct 28 07:41:47 2024 +0100
+++ b/ui/gtk/list.c	Mon Oct 28 08:33:22 2024 +0100
@@ -205,19 +205,35 @@
     list->obj = listview;
     
     // add callback
+    UiTreeEventData *event = malloc(sizeof(UiTreeEventData));
+    event->obj = obj;
+    event->activate = args.onactivate;
+    event->activatedata = args.onactivatedata;
+    event->selection = args.onselection;
+    event->selectiondata = args.onselectiondata;
+    g_signal_connect(
+            view,
+            "destroy",
+            G_CALLBACK(ui_destroy_userdata),
+            event);
+    
     if(args.onactivate) {
-        UiTreeEventData *event = ui_malloc(obj->ctx, sizeof(UiTreeEventData));
-        event->obj = obj;
-        event->activatedata = args.onactivatedata;
-        event->activate = args.onactivate;
-        event->selection = NULL;
-
         g_signal_connect(
                 view,
                 "row-activated",
                 G_CALLBACK(ui_listview_activate_event),
                 event);
     }
+    if(args.onselection) {
+        GtkTreeSelection *selection = gtk_tree_view_get_selection(
+                GTK_TREE_VIEW(view));
+        g_signal_connect(
+                selection,
+                "changed",
+                G_CALLBACK(ui_listview_selection_event),
+                event);
+    }
+    
     
     // add widget to the current container
     GtkWidget *scroll_area = SCROLLEDWINDOW_NEW();

mercurial