From 6941069d497389c9881a3597fe806242b4cc3442 Mon Sep 17 00:00:00 2001 From: Toshio Sekiya Date: Sun, 5 Feb 2023 00:56:18 +0900 Subject: [PATCH] Bug fixed. Solve GtkText warnings. --- docs/sec30.html | 38 +++++++++++++++++++++++++++++------- gfm/sec30.md | 38 ++++++++++++++++++++++++++++++------ src/listeditor/listeditor.c | 17 +++++++++------- src/listeditor/listeditor.ui | 2 -- src/sec30.src.md | 33 +++++++++++++++++++++++++------ 5 files changed, 100 insertions(+), 28 deletions(-) diff --git a/docs/sec30.html b/docs/sec30.html index 24db3ce..4788d59 100644 --- a/docs/sec30.html +++ b/docs/sec30.html @@ -448,14 +448,38 @@ template children for the given widget. This is the opposite of version. If your GTK version is lower than 4.8, you need to modify the program.

A waring from GtkText

-

If the list has many items and it needs to be scrolled, a warning -message can be issued.

+

If your program has the following two, 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.

+

I don’t have an exact idea why this happens. But if GtkText +“focusable” property is FALSE, the warning doesn’t happen. So it +probably comes from focus and scroll.

+

You can avoid this by unsetting any focus widget under the main +window. When scroll begins, the “value-changed” signal on the vertical +adjustment of the scrolled window is emitted.

+

The following is extracted from the ui file and C source file.

+
... ... ...
+<object class="GtkScrolledWindow">
+  <property name="hexpand">TRUE</property>
+  <property name="vexpand">TRUE</property>
+  <property name="vadjustment">
+    <object class="GtkAdjustment">
+      <signal name="value-changed" handler="adjustment_value_changed_cb" swapped="no" object="LeWindow"/>
+    </object>
+  </property>
+... ... ...  
+
static void
+adjustment_value_changed_cb (GtkAdjustment *adjustment, gpointer user_data) {
+  GtkWidget *win = GTK_WIDGET (user_data);
+
+  gtk_window_set_focus (GTK_WINDOW (win), NULL);
+}
diff --git a/gfm/sec30.md b/gfm/sec30.md index 5d7ba57..b5a9d2e 100644 --- a/gfm/sec30.md +++ b/gfm/sec30.md @@ -323,18 +323,44 @@ If your GTK version is lower than 4.8, you need to modify the program. ## A waring from GtkText -If the list has many items and it needs to be scrolled, a warning message can be issued. +If your program has the following two, a warning message can be issued. + +- The list has many items and it needs to be scrolled. +- A GtkText instance is the focus widget. ~~~ GtkText - unexpected blinking selection. Removing ~~~ -I don't have an idea why this happens. +I don't have an exact 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. +So it probably comes from focus and scroll. -It is a warning message, not a fatal error. -I think we can ignore it. +You can avoid this by unsetting any focus widget under the main window. +When scroll begins, the "value-changed" signal on the vertical adjustment of the scrolled window is emitted. + +The following is extracted from the ui file and C source file. + +~~~xml +... ... ... + + TRUE + TRUE + + + + + +... ... ... +~~~ + +~~~C +1 static void +2 adjustment_value_changed_cb (GtkAdjustment *adjustment, gpointer user_data) { +3 GtkWidget *win = GTK_WIDGET (user_data); +4 +5 gtk_window_set_focus (GTK_WINDOW (win), NULL); +6 } +~~~ Up: [README.md](../README.md), Prev: [Section 29](sec29.md) diff --git a/src/listeditor/listeditor.c b/src/listeditor/listeditor.c index 069a439..5125486 100644 --- a/src/listeditor/listeditor.c +++ b/src/listeditor/listeditor.c @@ -218,9 +218,12 @@ ins_cb (GtkButton *btn, LeWindow *win) { static void rm_cb (GtkButton *btn, LeWindow *win) { + int position; + if (win->position >= 0) { - g_list_store_remove (win->liststore, win->position); + position = win->position; win->position = -1; + g_list_store_remove (win->liststore, position); update_current (win, -1); } } @@ -453,12 +456,12 @@ unbind2_cb (GtkListItemFactory *factory, GtkListItem *listitem) { g_object_set_data (G_OBJECT (listitem), "bind", NULL); } -// static void -// adjustment_value_changed_cb (GtkAdjustment *adjustment, gpointer user_data) { -// GtkWidget *win = GTK_WIDGET (user_data); +static void +adjustment_value_changed_cb (GtkAdjustment *adjustment, gpointer user_data) { + GtkWidget *win = GTK_WIDGET (user_data); -// gtk_widget_set_can_focus (win, FALSE); -// } + gtk_window_set_focus (GTK_WINDOW (win), NULL); +} static void le_window_init (LeWindow *win) { @@ -503,7 +506,7 @@ le_window_class_init (LeWindowClass *class) { gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (class), setup2_cb); gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (class), bind2_cb); gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (class), unbind2_cb); - // gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (class), adjustment_value_changed_cb); + gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (class), adjustment_value_changed_cb); } GtkWidget * diff --git a/src/listeditor/listeditor.ui b/src/listeditor/listeditor.ui index d5a9ab5..7cd1d84 100644 --- a/src/listeditor/listeditor.ui +++ b/src/listeditor/listeditor.ui @@ -84,13 +84,11 @@ TRUE TRUE - TRUE diff --git a/src/sec30.src.md b/src/sec30.src.md index 5362ed2..a04ae0f 100644 --- a/src/sec30.src.md +++ b/src/sec30.src.md @@ -221,16 +221,37 @@ If your GTK version is lower than 4.8, you need to modify the program. ## A waring from GtkText -If the list has many items and it needs to be scrolled, a warning message can be issued. +If your program has the following two, a warning message can be issued. + +- The list has many items and it needs to be scrolled. +- A GtkText instance is the focus widget. ~~~ GtkText - unexpected blinking selection. Removing ~~~ -I don't have an idea why this happens. +I don't have an exact 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. +So it probably comes from focus and scroll. -It is a warning message, not a fatal error. -I think we can ignore it. +You can avoid this by unsetting any focus widget under the main window. +When scroll begins, the "value-changed" signal on the vertical adjustment of the scrolled window is emitted. + +The following is extracted from the ui file and C source file. + +~~~xml +... ... ... + + TRUE + TRUE + + + + + +... ... ... +~~~ + +@@@include +listeditor/listeditor.c adjustment_value_changed_cb +@@@