diff options
author | Thomas White <taw@physics.org> | 2021-08-12 10:42:26 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2021-08-12 11:24:33 +0200 |
commit | bb45726711a19188d54d9d65fa531b47a74341ae (patch) | |
tree | f4de4d943c40eba400bdef826d7900b7213d65cc /src | |
parent | f0473ac9af56b6aa69f0334d9ac22f41bebeec38 (diff) |
CrystFELImageView: Fix adjustment semantics
This changes how CrystFELImageView handles its adjustments for the
GtkScrollable interface, to match the GTK examples. In particular, it
adds a call to g_object_ref_sink() which prevents premature destruction
of the adjustments when the GUI is closed down.
Diffstat (limited to 'src')
-rw-r--r-- | src/crystfelimageview.c | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/src/crystfelimageview.c b/src/crystfelimageview.c index f1cbe877..44c0c039 100644 --- a/src/crystfelimageview.c +++ b/src/crystfelimageview.c @@ -617,6 +617,39 @@ static void scroll_adjust_sig(GtkAdjustment *adj, CrystFELImageView *iv) redraw(iv); } +static void set_adjustment_horizontal(CrystFELImageView *iv, GtkAdjustment *adj) +{ + if ( iv->hadj == adj ) return; + + if ( adj == NULL ) { + adj = gtk_adjustment_new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); + } + + iv->hadj = adj; + g_object_ref_sink(iv->hadj); + + configure_scroll_adjustments(iv); + g_signal_connect(G_OBJECT(iv->hadj), "value-changed", + G_CALLBACK(scroll_adjust_sig), iv); +} + + +static void set_adjustment_vertical(CrystFELImageView *iv, GtkAdjustment *adj) +{ + if ( iv->vadj == adj ) return; + + if ( adj == NULL ) { + adj = gtk_adjustment_new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); + } + + iv->vadj = adj; + g_object_ref_sink(iv->vadj); + + configure_scroll_adjustments(iv); + g_signal_connect(G_OBJECT(iv->vadj), "value-changed", + G_CALLBACK(scroll_adjust_sig), iv); +} + static void crystfel_image_view_set_property(GObject *obj, guint id, const GValue *val, @@ -635,21 +668,11 @@ static void crystfel_image_view_set_property(GObject *obj, guint id, break; case CRYSTFELIMAGEVIEW_VADJ : - iv->vadj = g_value_get_object(val); - configure_scroll_adjustments(iv); - if ( iv->vadj != NULL ) { - g_signal_connect(G_OBJECT(iv->vadj), "value-changed", - G_CALLBACK(scroll_adjust_sig), iv); - } + set_adjustment_vertical(iv, g_value_get_object(val)); break; case CRYSTFELIMAGEVIEW_HADJ : - iv->hadj = g_value_get_object(val); - configure_scroll_adjustments(iv); - if ( iv->hadj != NULL ) { - g_signal_connect(G_OBJECT(iv->hadj), "value-changed", - G_CALLBACK(scroll_adjust_sig), iv); - } + set_adjustment_horizontal(iv, g_value_get_object(val)); break; default : |