WIP: on_selection_change() affiche le premier élement ayant changé d'état et le nombre d'éléments ayant changé d'état
This commit is contained in:
parent
556a7f0c69
commit
baf6263d15
|
@ -30,21 +30,29 @@
|
||||||
|
|
||||||
static void on_destroy (GtkWidget *widget, gpointer data) {if (data) g_print (data); exit(0);}
|
static void on_destroy (GtkWidget *widget, gpointer data) {if (data) g_print (data); exit(0);}
|
||||||
|
|
||||||
static void setup_cb (GtkSignalListItemFactory *self, GtkListItem *my_list_item, gpointer user_data) {
|
static void setup_cb (GtkSignalListItemFactory *self, GtkListItem *my_list_item, gpointer user_data)
|
||||||
|
{
|
||||||
GtkWidget *my_label = gtk_label_new (NULL);
|
GtkWidget *my_label = gtk_label_new (NULL);
|
||||||
gtk_list_item_set_child (my_list_item, my_label);
|
gtk_list_item_set_child (my_list_item, my_label);
|
||||||
/* Because gtk_list_item_set_child sunk the floating reference of my_label, releasing (unref) isn't necessary for my_label. */
|
/* Because gtk_list_item_set_child sunk the floating reference of my_label, releasing (unref) isn't necessary for my_label. */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bind_cb (GtkSignalListItemFactory *self, GtkListItem *my_list_item, gpointer user_data) {
|
static void bind_cb (GtkSignalListItemFactory *self, GtkListItem *my_list_item, gpointer user_data)
|
||||||
|
{
|
||||||
GtkWidget *my_label = gtk_list_item_get_child (my_list_item);
|
GtkWidget *my_label = gtk_list_item_get_child (my_list_item);
|
||||||
/* Strobj is owned by the instance. Caller mustn't change or destroy it. */
|
/* Strobj is owned by the instance. Caller mustn't change or destroy it. */
|
||||||
GtkStringObject *my_string_object = gtk_list_item_get_item (my_list_item);
|
GtkStringObject *my_string_object = gtk_list_item_get_item (my_list_item);
|
||||||
/* The string returned by gtk_string_object_get_string is owned by the instance. */
|
/* The string returned by gtk_string_object_get_string is owned by the instance. */
|
||||||
printf("%s\n", gtk_string_object_get_string (my_string_object));
|
//printf("%s\n", gtk_string_object_get_string (my_string_object));
|
||||||
gtk_label_set_text (GTK_LABEL (my_label), gtk_string_object_get_string (my_string_object));
|
gtk_label_set_text (GTK_LABEL (my_label), gtk_string_object_get_string (my_string_object));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void on_selection_change (GtkSelectionModel* self, guint position, guint n_items, gpointer user_data)
|
||||||
|
{
|
||||||
|
printf("Premier élement ayant changé d'état : %d (%d ont changé d'état)\n", position, n_items);
|
||||||
|
}
|
||||||
|
|
||||||
|
enum { COLUMN_DESCRIPTION };
|
||||||
|
|
||||||
static void and_now_let_s_climb_that_tree (GtkWidget *in_that_box)
|
static void and_now_let_s_climb_that_tree (GtkWidget *in_that_box)
|
||||||
{
|
{
|
||||||
|
@ -54,7 +62,7 @@ static void and_now_let_s_climb_that_tree (GtkWidget *in_that_box)
|
||||||
|
|
||||||
GtkStringList *my_string_list = gtk_string_list_new ((const char * const *) my_array);
|
GtkStringList *my_string_list = gtk_string_list_new ((const char * const *) my_array);
|
||||||
|
|
||||||
GtkSingleSelection *my_selection_model = gtk_single_selection_new (G_LIST_MODEL (my_string_list));
|
GtkMultiSelection *my_selection_model = gtk_multi_selection_new (G_LIST_MODEL (my_string_list));
|
||||||
|
|
||||||
if (gtk_single_selection_get_selected_item (my_selection_model))
|
if (gtk_single_selection_get_selected_item (my_selection_model))
|
||||||
gtk_selection_model_selection_changed (my_selection_model, 0, 1);
|
gtk_selection_model_selection_changed (my_selection_model, 0, 1);
|
||||||
|
@ -63,6 +71,13 @@ static void and_now_let_s_climb_that_tree (GtkWidget *in_that_box)
|
||||||
GtkListItemFactory *my_factory = gtk_signal_list_item_factory_new ();
|
GtkListItemFactory *my_factory = gtk_signal_list_item_factory_new ();
|
||||||
g_signal_connect (my_factory, "setup", G_CALLBACK (setup_cb), NULL);
|
g_signal_connect (my_factory, "setup", G_CALLBACK (setup_cb), NULL);
|
||||||
g_signal_connect (my_factory, "bind", G_CALLBACK (bind_cb), NULL);
|
g_signal_connect (my_factory, "bind", G_CALLBACK (bind_cb), NULL);
|
||||||
|
g_signal_connect (my_selection_model, "selection-changed", G_CALLBACK (on_selection_change), NULL);
|
||||||
|
|
||||||
|
GtkWidget *treeview;
|
||||||
|
treeview = gtk_tree_view_new_with_model (my_selection_model);
|
||||||
|
gtk_widget_set_vexpand (treeview, TRUE);
|
||||||
|
gtk_tree_view_set_search_column (GTK_TREE_VIEW (treeview),
|
||||||
|
COLUMN_DESCRIPTION);
|
||||||
|
|
||||||
GtkWidget *my_list_view = gtk_list_view_new (GTK_SELECTION_MODEL (my_selection_model), my_factory);
|
GtkWidget *my_list_view = gtk_list_view_new (GTK_SELECTION_MODEL (my_selection_model), my_factory);
|
||||||
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (in_that_box), my_list_view);
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (in_that_box), my_list_view);
|
||||||
|
@ -81,7 +96,7 @@ void on_activate_window_creation (GtkApplication *app, gpointer data) {
|
||||||
|
|
||||||
and_now_let_s_climb_that_tree (my_scrolling_thing);
|
and_now_let_s_climb_that_tree (my_scrolling_thing);
|
||||||
|
|
||||||
if (data) {g_print (data); g_print (" and is displayed by [sand_box.c > on_activate_window_creation()]\n");}
|
if (data) {g_print (data); g_print (" and is displayed by [sand_box.c / on_activate_window_creation()]\n");}
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue