From 9650830860b7adea70f1944f80bcafc37880f142 Mon Sep 17 00:00:00 2001
From: Toshio Sekiya This technique is not so complicated. You can use it when you make a
@@ -271,6 +277,10 @@ moves. The button of the current line is colored with red and otherwise
white.setup2_cb (GtkListItemFactory *factory, GtkListItem *listitem) {
GtkWidget *text = gtk_text_new ();
gtk_list_item_set_child (listitem, GTK_WIDGET (text));
-}
-
-static void
-bind2_cb (GtkListItemFactory *factory, GtkListItem *listitem) {
- GtkWidget *text = gtk_list_item_get_child (listitem);
- LeData *data = LE_DATA (gtk_list_item_get_item (listitem));
- GtkEntryBuffer *buffer;
- GBinding *bind;
-
- buffer = gtk_text_get_buffer (GTK_TEXT (text));
- gtk_entry_buffer_set_text (buffer, le_data_look_string (data), -1);
- bind = g_object_bind_property (buffer, "text", data, "string", G_BINDING_DEFAULT);
- g_object_set_data (G_OBJECT (listitem), "bind", bind);
-}
-
-static void
-unbind2_cb (GtkListItemFactory *factory, GtkListItem *listitem) {
- GBinding *bind = G_BINDING (g_object_get_data (G_OBJECT (listitem), "bind"));
-
- g_binding_unbind(bind);
- g_object_set_data (G_OBJECT (listitem), "bind", NULL);
-}
+ gtk_editable_set_alignment (GTK_EDITABLE (text), 0.0);
+}
+
+static void
+bind2_cb (GtkListItemFactory *factory, GtkListItem *listitem) {
+ GtkWidget *text = gtk_list_item_get_child (listitem);
+ GtkEntryBuffer *buffer = gtk_text_get_buffer (GTK_TEXT (text));
+ LeData *data = LE_DATA (gtk_list_item_get_item (listitem));
+ GBinding *bind;
+
+ gtk_editable_set_text (GTK_EDITABLE (text), le_data_look_string (data));
+ gtk_editable_set_position (GTK_EDITABLE (text), 0);
+
+ bind = g_object_bind_property (buffer, "text", data, "string", G_BINDING_DEFAULT);
+ g_object_set_data (G_OBJECT (listitem), "bind", bind);
+}
+
+static void
+unbind2_cb (GtkListItemFactory *factory, GtkListItem *listitem) {
+ GBinding *bind = G_BINDING (g_object_get_data (G_OBJECT (listitem), "bind"));
+
+ g_binding_unbind(bind);
+ g_object_set_data (G_OBJECT (listitem), "bind", NULL);
+}
-
-setup2_cb
is a setup signal handler on the
+setup2_cb
is a setup signal handler on the
GtkSignalListItemFactory. This factory is inserted to the factory
-property of the second GtkColumnViewColumn. Te handler just creates a
+property of the second GtkColumnViewColumn. The handler just creates a
GtkText instance and sets the child of listitem
to it. The
instance will be destroyed automatically when the listitem
is destroyed. So, teardown signal handler isn’t necessary.bind2_cb
is a bind signal handler. It is called
+bind2_cb
is a bind signal handler. It is called
when the listitem
is bound to an item in the list. The list
items are LeData instances. LeData is defined in the file
listeditor.c
(the C source file of the list editor). It is
a child class of GObject and has two data. The one is
-listitem
which points a GtkListItem instance when they are
-connected. If no GtkListItem is connected, it is NULL. The other is
-string
which is a content of the line.
+listitem
which points a first column GtkListItem instance
+when they are connected. Be careful that the GtkListItem instance is
+not the listitem
in this handler. If no
+GtkListItem is connected, it is NULL. The other is string
+which is a content of the line.
-
text
is a child of the listitem
and
-it is a GtkText instance. data
is an item pointed by the
-listitem
. It is a LeData instance.text
.text
is a child of the listitem
and
+it is a GtkText instance. And buffer
is a GtkTextBuffer
+instance of the text
.data
is an item pointed by the
+listitem
.text
to
le_data_look_string (data)
. le_data_look_string returns the
-string of the data and the ownership of the string is taken by the
-data
. So, the caller don’t need to free the string.g_object_bind_property
binds a property and another
+string of the data
and the ownership of the string is still
+taken by the data
. So, the caller don’t need to free the
+string.g_object_bind_property
binds a property and another
object property. This line binds the “text” property of the
buffer
(source) and the “string” property of the
data
(destination). It is a uni-directional binding
@@ -241,19 +247,19 @@ the same string is immediately put into the data
. The
function returns a GBinding instance. This binding is different from
bindings of GtkExpression. This binding needs the existence of the two
properties.g_object_set_data
sets the association from the key to the
value. This line sets the association from “bind” to bind
-instance on the listitem
instance. It makes possible for
-the “unbind” handler to get the bind
instance.bind
instance.unbind2_cb
is a unbind signal handler.
+unbind2_cb
is a unbind signal handler.
-
bind
instance from the table in the
+bind
instance from the table in the
listitem
instance.gtk_list_item_get_item
function. To accomplish this, we set
a listitem
element of LeData to point the corresponding
GtkListItem instance. Therefore, items (LeData) in the list always know
-the GtkListItem. If there’s no GtkListItem binded to the item, NULL is
+the GtkListItem. If there’s no GtkListItem bound to the item, NULL is
assigned.
void
@@ -298,42 +308,56 @@ class="sourceCode numberSource C numberLines">setup1_cb (GtkListItemFactory *factory, GtkListItem *listitem) {
GtkWidget *button = gtk_button_new ();
gtk_list_item_set_child (listitem, button);
- g_signal_connect (button, "clicked", G_CALLBACK (select_cb), listitem);
-}
-
-static void
-bind1_cb (GtkListItemFactory *factory, GtkListItem *listitem) {
- LeData *data = LE_DATA (gtk_list_item_get_item (listitem));
- if (data)
- le_data_set_listitem (data, listitem);
-}
-
-static void
-unbind1_cb (GtkListItemFactory *factory, GtkListItem *listitem) {
- LeData *data = LE_DATA (gtk_list_item_get_item (listitem));
- if (data)
- le_data_set_listitem (data, NULL);
-}
setup1_cb
is a setup signal handler on the
+setup1_cb
is a setup signal handler on the
GtkSignalListItemFactory. This factory is inserted to the factory
property of the first GtkColumnViewColumn. It sets the child of
-listitem
to a newly created GtkButton instance. The
-“clicked” signal on the button is connected to the handler
-select_cb
. When the listitem is destroyed, the child
-(GtkButton) is also destroyed. At the same time, the connection of the
-signal and handler is also destroyed. So, you don’t need teardown signal
-handler.listitem
to a GtkButton instance. The “clicked” signal on
+the button is connected to the handler select_cb
. When the
+listitem is destroyed, the child (GtkButton) is also destroyed. At the
+same time, the connection of the signal and the handler is also
+destroyed. So, you don’t need teardown signal handler.
select_cb
is a “clicked” signal handler. LeWindow
is defined in listeditor.c
. It’s a child class of
GtkApplicationWindow. The handler just calls the
update_current
function. The function will be explained
later.bind1_cb
is a bind signal handler. It sets the
+bind1_cb
is a bind signal handler. It sets the
“listitem” element of the item (LeData) to point the
listitem
(GtkListItem instance). It makes the item possible
-to find the corresponding GtkListItem instance.unbind1_cb
is an unbind signal handler. It
+to find the corresponding GtkListItem instance. If the item is the
+current line, the CSS class of the button includes “current” class.
+Otherwise it has no CSS class. This is necessary because the button may
+be recycled and it has had former CSS class. The class need to be
+updated.unbind1_cb
is an unbind signal handler. It
removes the listitem
instance from the “listitem” element
of the item. The element becomes NULL, which tells no GtkListItem is
bound. When referring GtkListItem, it needs to check the “listitem”
@@ -423,6 +447,15 @@ template children for the given widget. This is the opposite of
gtk_widget_init_template()
. It is a new function of GTK 4.8
version. If your GTK version is lower than 4.8, you need to modify the
program.
+If the list has many items and it needs to be scrolled, a warning +message can be issued.
+GtkText - unexpected blinking selection. Removing
+I don’t have an idea why this happens. But if GtkText “focusable” +property is FALSE, the warning doesn’t happen. So it probably come from +focus and scroll. If you know the reason, please let me know.
+It is a warning message, not a fatal error. I think we can ignore +it.