@@ -12,11 +12,22 @@ struct _Displaybar {
1212 */
1313 ImageWindow * win ;
1414
15+ /* The tile_source we are currently controlling. Not a ref.
16+ */
17+ TileSource * tile_source ;
18+
1519 GtkWidget * action_bar ;
1620 GtkWidget * gears ;
1721 GtkWidget * page ;
1822 GtkWidget * scale ;
1923 GtkWidget * offset ;
24+
25+ /* We have to disconnect and reconnect these when imagewindow gets a new
26+ * tile_source.
27+ */
28+ guint changed_sid ;
29+ guint tiles_changed_sid ;
30+ guint page_changed_sid ;
2031};
2132
2233G_DEFINE_TYPE (Displaybar , displaybar , GTK_TYPE_WIDGET );
@@ -32,8 +43,8 @@ static void
3243displaybar_tile_source_changed (TileSource * tile_source , Displaybar * displaybar )
3344{
3445#ifdef DEBUG
35- printf ("displaybar_tile_source_changed:\n" );
3646#endif /*DEBUG*/
47+ printf ("displaybar_tile_source_changed:\n" );
3748
3849 if (TSLIDER (displaybar -> scale )-> value != tile_source -> scale ) {
3950 TSLIDER (displaybar -> scale )-> value = tile_source -> scale ;
@@ -63,23 +74,45 @@ displaybar_page_changed(TileSource *tile_source, Displaybar *displaybar)
6374 tile_source -> page );
6475}
6576
77+ static void
78+ displaybar_disconnect (Displaybar * displaybar )
79+ {
80+ if (displaybar -> tile_source ) {
81+ FREESID (displaybar -> changed_sid , displaybar -> tile_source );
82+ FREESID (displaybar -> tiles_changed_sid , displaybar -> tile_source );
83+ FREESID (displaybar -> page_changed_sid , displaybar -> tile_source );
84+
85+ displaybar -> tile_source = NULL ;
86+ }
87+ }
88+
6689/* Imagewindow has a new tile_source.
6790 */
6891static void
6992displaybar_image_window_changed (ImageWindow * win , Displaybar * displaybar )
7093{
71- TileSource * tile_source ;
94+ TileSource * tile_source = image_window_get_tile_source (win );
95+
96+ #ifdef DEBUG
97+ #endif /*DEBUG*/
98+ printf ("displaybar_image_window_changed:\n" );
99+
100+ displaybar_disconnect (displaybar );
101+
102+ if (tile_source ) {
103+ displaybar -> changed_sid = g_signal_connect (tile_source ,
104+ "changed" ,
105+ G_CALLBACK (displaybar_tile_source_changed ), displaybar );
106+ displaybar -> tiles_changed_sid = g_signal_connect (tile_source ,
107+ "tiles-changed" ,
108+ G_CALLBACK (displaybar_tile_source_changed ), displaybar );
109+ displaybar -> page_changed_sid = g_signal_connect (tile_source ,
110+ "page-changed" ,
111+ G_CALLBACK (displaybar_page_changed ), displaybar );
72112
73- if ((tile_source = image_window_get_tile_source (win ))) {
74- g_signal_connect_object (tile_source , "changed" ,
75- G_CALLBACK (displaybar_tile_source_changed ),
76- displaybar , 0 );
77- g_signal_connect_object (tile_source , "tiles-changed" ,
78- G_CALLBACK (displaybar_tile_source_changed ),
79- displaybar , 0 );
80- g_signal_connect_object (tile_source , "page-changed" ,
81- G_CALLBACK (displaybar_page_changed ),
82- displaybar , 0 );
113+ displaybar -> tile_source = tile_source ;
114+
115+ displaybar_tile_source_changed (tile_source , displaybar );
83116 }
84117}
85118
@@ -89,6 +122,7 @@ displaybar_set_image_window(Displaybar *displaybar, ImageWindow *win)
89122 /* No need to ref ... win holds a ref to us.
90123 */
91124 displaybar -> win = win ;
125+ displaybar -> tile_source = image_window_get_tile_source (win );
92126
93127 g_signal_connect_object (win , "changed" ,
94128 G_CALLBACK (displaybar_image_window_changed ),
@@ -150,6 +184,8 @@ displaybar_dispose(GObject *object)
150184 printf ("displaybar_dispose:\n" );
151185#endif /*DEBUG*/
152186
187+ displaybar_disconnect (displaybar );
188+
153189 VIPS_FREEF (gtk_widget_unparent , displaybar -> action_bar );
154190
155191 G_OBJECT_CLASS (displaybar_parent_class )-> dispose (object );
@@ -159,7 +195,7 @@ static void
159195displaybar_page_value_changed (GtkSpinButton * spin_button ,
160196 Displaybar * displaybar )
161197{
162- TileSource * tile_source = image_window_get_tile_source ( displaybar -> win ) ;
198+ TileSource * tile_source = displaybar -> tile_source ;
163199 int new_page = gtk_spin_button_get_value_as_int (spin_button );
164200
165201#ifdef DEBUG
@@ -175,7 +211,7 @@ displaybar_page_value_changed(GtkSpinButton *spin_button,
175211static void
176212displaybar_scale_value_changed (Tslider * slider , Displaybar * displaybar )
177213{
178- TileSource * tile_source = image_window_get_tile_source ( displaybar -> win ) ;
214+ TileSource * tile_source = displaybar -> tile_source ;
179215
180216 if (tile_source )
181217 g_object_set (tile_source ,
@@ -186,7 +222,7 @@ displaybar_scale_value_changed(Tslider *slider, Displaybar *displaybar)
186222static void
187223displaybar_offset_value_changed (Tslider * slider , Displaybar * displaybar )
188224{
189- TileSource * tile_source = image_window_get_tile_source ( displaybar -> win ) ;
225+ TileSource * tile_source = displaybar -> tile_source ;
190226
191227 if (tile_source )
192228 g_object_set (tile_source ,
0 commit comments