[balsa/wip/gtk4: 280/351] Store GtkGestures in objects



commit 428092d6ebd47934f644f6f4880211dcba9492f7
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Tue Apr 17 19:43:33 2018 -0400

    Store GtkGestures in objects
    
    …so that we can unref them in dispose/finalize methods, instead of using
    g_object_set_data_full with g_object_unref.

 src/balsa-index.c    |    3 +--
 src/balsa-mblist.c   |   19 +++++++++++++++----
 src/balsa-mblist.h   |    2 ++
 src/balsa-message.c  |    4 ++--
 src/balsa-message.h  |    2 ++
 src/sendmsg-window.c |   11 +++++------
 src/sendmsg-window.h |    2 ++
 7 files changed, 29 insertions(+), 14 deletions(-)
---
diff --git a/src/balsa-index.c b/src/balsa-index.c
index bd78bc5..e35bebe 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -426,7 +426,7 @@ bndx_instance_init(BalsaIndex * index)
 
     /* we want to handle button presses to pop up context menus if
      * necessary */
-    gesture = gtk_gesture_multi_press_new(GTK_WIDGET(index));
+    index->gesture = gesture = gtk_gesture_multi_press_new(GTK_WIDGET(index));
     gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), 0);
     g_signal_connect(gesture, "pressed",
                     G_CALLBACK(bndx_gesture_pressed_cb), NULL);
@@ -434,7 +434,6 @@ bndx_instance_init(BalsaIndex * index)
      * so we jump in at the capture phase: */
     gtk_event_controller_set_propagation_phase(GTK_EVENT_CONTROLLER(gesture),
                                                GTK_PHASE_CAPTURE);
-    index->gesture = gesture;
 
     g_signal_connect(tree_view, "row-activated",
                     G_CALLBACK(bndx_row_activated), NULL);
diff --git a/src/balsa-mblist.c b/src/balsa-mblist.c
index e9a164a..3884343 100644
--- a/src/balsa-mblist.c
+++ b/src/balsa-mblist.c
@@ -166,6 +166,15 @@ balsa_mblist_get_type(void)
     return mblist_type;
 }
 
+static void
+bmbl_dispose(GObject * object)
+{
+    BalsaMBList *mblist = (BalsaMBList *) object;
+
+    g_clear_object(&mblist->gesture);
+
+    G_OBJECT_CLASS(parent_class)->dispose(object);
+}
 
 static void
 bmbl_class_init(BalsaMBListClass * klass)
@@ -193,6 +202,7 @@ bmbl_class_init(BalsaMBListClass * klass)
     /* GObject signals */
     object_class->set_property = bmbl_set_property;
     object_class->get_property = bmbl_get_property;
+    object_class->dispose      = bmbl_dispose;
 
     /* GtkWidget signals */
     widget_class->drag_motion = bmbl_drag_motion;
@@ -687,12 +697,14 @@ bmbl_gesture_pressed_cb(GtkGestureMultiPress *multi_press,
     GtkTreePath *path;
 
     gesture = GTK_GESTURE(multi_press);
-    event = gtk_gesture_get_last_event(gesture, gtk_gesture_get_last_updated_sequence(gesture));
+    event = gtk_gesture_get_last_event(gesture,
+                                       gtk_gesture_get_last_updated_sequence(gesture));
     g_return_if_fail(event != NULL);
     if (!gdk_event_triggers_context_menu(event))
         return;
 
-    tree_view = GTK_TREE_VIEW(gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture)));
+    tree_view =
+        GTK_TREE_VIEW(gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture)));
 
     if (!gtk_tree_view_get_path_at_pos(tree_view, (gint) x, (gint) y,
                                        &path, NULL, NULL, NULL))
@@ -1174,9 +1186,8 @@ balsa_mblist_default_signal_bindings(BalsaMBList * mblist)
     GtkGesture *gesture;
     GdkContentFormats *formats;
 
-    gesture = gtk_gesture_multi_press_new(GTK_WIDGET(mblist));
+    mblist->gesture= gesture = gtk_gesture_multi_press_new(GTK_WIDGET(mblist));
     gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), 0);
-    g_object_set_data_full(G_OBJECT(mblist), "balsa-gesture", gesture, g_object_unref);
     g_signal_connect(gesture, "pressed",
                      G_CALLBACK(bmbl_gesture_pressed_cb), NULL);
 
diff --git a/src/balsa-mblist.h b/src/balsa-mblist.h
index 79d94d0..114c290 100644
--- a/src/balsa-mblist.h
+++ b/src/balsa-mblist.h
@@ -42,6 +42,8 @@ struct _BalsaMBList {
     /* to set sort order in an idle callback */
     gint  sort_column_id;
     guint sort_idle_id;
+
+    GtkGesture *gesture;
 };
 
 struct _BalsaMBListClass {
diff --git a/src/balsa-message.c b/src/balsa-message.c
index 21b6fc1..061b575 100644
--- a/src/balsa-message.c
+++ b/src/balsa-message.c
@@ -725,9 +725,8 @@ balsa_message_init(BalsaMessage * bm)
     g_signal_connect(bm->treeview, "row-activated",
                      G_CALLBACK(tree_activate_row_cb), bm);
 
-    gesture = gtk_gesture_multi_press_new(GTK_WIDGET(bm->treeview));
+    bm->gesture = gesture = gtk_gesture_multi_press_new(GTK_WIDGET(bm->treeview));
     gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), 0);
-    g_object_set_data_full(G_OBJECT(bm->treeview), "balsa-gesture", gesture, g_object_unref);
     g_signal_connect(gesture, "pressed",
                      G_CALLBACK(bm_gesture_pressed_cb), NULL);
 
@@ -808,6 +807,7 @@ balsa_message_destroy(GObject * object)
     g_clear_object(&bm->save_all_popup);
     g_clear_object(&bm->parts_popup);
     g_clear_object(&bm->bm_widget);
+    g_clear_object(&bm->gesture);
 
 #ifdef HAVE_HTML_WIDGET
     g_clear_object(&bm->html_find_info);
diff --git a/src/balsa-message.h b/src/balsa-message.h
index 20a9942..6db56e0 100644
--- a/src/balsa-message.h
+++ b/src/balsa-message.h
@@ -99,6 +99,8 @@ struct _BalsaMessage {
 #ifdef HAVE_HTML_WIDGET
         gpointer html_find_info;
 #endif                         /* HAVE_HTML_WIDGET */
+
+        GtkGesture *gesture;
 };
 
 struct _BalsaMessageClass {
diff --git a/src/sendmsg-window.c b/src/sendmsg-window.c
index c9e0531..3a9d28a 100644
--- a/src/sendmsg-window.c
+++ b/src/sendmsg-window.c
@@ -636,14 +636,12 @@ balsa_sendmsg_destroy_handler(BalsaSendmsg * bsmsg)
     if (balsa_app.debug)
        printf("balsa_sendmsg_destroy_handler: Freeing bsmsg\n");
     gtk_widget_destroy(bsmsg->window);
-    quit_on_close = bsmsg->quit_on_close;
     g_free(bsmsg->fcc_url);
     g_free(bsmsg->in_reply_to);
     libbalsa_clear_list(&bsmsg->references, g_free);
 
 #if !(HAVE_GSPELL || HAVE_GTKSPELL)
-    if (bsmsg->spell_checker)
-        gtk_widget_destroy(bsmsg->spell_checker);
+    g_clear_pointer(&bsmsg->spell_checker, gtk_widget_destroy);
 #endif                          /* HAVE_GTKSPELL */
     libbalsa_clear_source_id(&bsmsg->autosave_timeout_id);
 
@@ -658,8 +656,9 @@ balsa_sendmsg_destroy_handler(BalsaSendmsg * bsmsg)
                                           bsmsg->ident);
 
     g_free(bsmsg->spell_check_lang);
-    bsmsg->spell_check_lang = NULL;
+    g_clear_object(&bsmsg->gesture);
 
+    quit_on_close = bsmsg->quit_on_close;
     g_free(bsmsg);
 
     if (quit_on_close) {
@@ -2721,9 +2720,8 @@ sw_attachment_list(BalsaSendmsg *bsmsg)
     gtk_tree_selection_set_mode(gtk_tree_view_get_selection(view),
                                GTK_SELECTION_SINGLE);
 
-    gesture = gtk_gesture_multi_press_new(tree_view);
+    bsmsg->gesture = gesture = gtk_gesture_multi_press_new(tree_view);
     gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), 0);
-    g_object_set_data_full(G_OBJECT(tree_view), "balsa-gesture", gesture, g_object_unref);
     g_signal_connect(gesture, "pressed",
                      G_CALLBACK(sw_gesture_pressed_cb), NULL);
 
@@ -6646,6 +6644,7 @@ sendmsg_window_new()
     bsmsg->update_config = FALSE;
     bsmsg->quit_on_close = FALSE;
     bsmsg->state = SENDMSG_STATE_CLEAN;
+    bsmsg->gesture = NULL;
 
     bsmsg->window = window =
         gtk_application_window_new(balsa_app.application);
diff --git a/src/sendmsg-window.h b/src/sendmsg-window.h
index e77aa4a..1de4074 100644
--- a/src/sendmsg-window.h
+++ b/src/sendmsg-window.h
@@ -107,6 +107,8 @@ G_BEGIN_DECLS
 
         GtkWidget *paned;
         gboolean ready_to_send;
+
+        GtkGesture *gesture;
     };
 
     BalsaSendmsg *sendmsg_window_compose(void);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]