WIP: item value (a string) = gtk_string_object_get_string (g_list_model_get_item (selection_model, position))
This commit is contained in:
parent
baf6263d15
commit
8094259bb2
|
@ -20,7 +20,6 @@
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <gtk-4.0/gtk/gtk.h>
|
#include <gtk-4.0/gtk/gtk.h>
|
||||||
#include <gdk/gdk.h>
|
#include <gdk/gdk.h>
|
||||||
|
@ -40,16 +39,22 @@ static void setup_cb (GtkSignalListItemFactory *self, GtkListItem *my_list_item,
|
||||||
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. */
|
/* my_string_object 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));
|
|
||||||
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)
|
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);
|
printf("list size = %d item type = %d\
|
||||||
|
position (premier élement ayant changé d'état) = %2d %7s\
|
||||||
|
nombre d'éléments ayant changé d'état = %2d\n",
|
||||||
|
g_list_model_get_n_items (self),
|
||||||
|
g_list_model_get_item_type(self),
|
||||||
|
position,
|
||||||
|
gtk_string_object_get_string(g_list_model_get_item(self, position)),
|
||||||
|
n_items );
|
||||||
}
|
}
|
||||||
|
|
||||||
enum { COLUMN_DESCRIPTION };
|
enum { COLUMN_DESCRIPTION };
|
||||||
|
@ -58,7 +63,6 @@ static void and_now_let_s_climb_that_tree (GtkWidget *in_that_box)
|
||||||
{
|
{
|
||||||
const gchar *my_array[] = {"zero", "one", "two", "three", "four", "five",
|
const gchar *my_array[] = {"zero", "one", "two", "three", "four", "five",
|
||||||
"six", "seven", "eight", "nine", "ten", "eleven", "twelve", NULL};
|
"six", "seven", "eight", "nine", "ten", "eleven", "twelve", NULL};
|
||||||
// https://toshiocp.github.io/Gtk4-tutorial/sec29.html
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
@ -67,18 +71,11 @@ static void and_now_let_s_climb_that_tree (GtkWidget *in_that_box)
|
||||||
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);
|
||||||
|
|
||||||
// factory = GtkSignalListItemFactory(setup_cb, bind_cb)
|
|
||||||
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);
|
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);
|
||||||
}
|
}
|
||||||
|
@ -99,8 +96,10 @@ void on_activate_window_creation (GtkApplication *app, gpointer data) {
|
||||||
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");}
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//-------------------------------------------------------------------- notes
|
||||||
|
|
||||||
// guix shell -m manifest.scm && pkg-config --libs gtk4 make clean && clear && time make run
|
// guix shell -m manifest.scm && pkg-config --libs gtk4 make clean && clear && time make run
|
||||||
// my local widgets examples are in user/jean/01/GTK4/tree (learning)/The_Gnome_way/demos/gtk-demo
|
// my local widgets examples are in user/jean/01/GTK4/tree (learning)/The_Gnome_way/demos/gtk-demo
|
||||||
|
// https://toshiocp.github.io/Gtk4-tutorial/sec29.html
|
||||||
|
// factory = GtkSignalListItemFactory(setup_cb, bind_cb)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue