@@ -12,7 +12,7 @@ struct _Displaybar {
1212 */
1313 ImageWindow * win ;
1414
15- /* The tile_source we are currently controlling. Not a ref.
15+ /* A ref to the tile_source we are currently controlling.
1616 */
1717 TileSource * tile_source ;
1818
@@ -43,8 +43,10 @@ static void
4343displaybar_tile_source_changed (TileSource * tile_source , Displaybar * displaybar )
4444{
4545#ifdef DEBUG
46- #endif /*DEBUG*/
4746 printf ("displaybar_tile_source_changed:\n" );
47+ #endif /*DEBUG*/
48+
49+ g_assert (tile_source == displaybar -> tile_source );
4850
4951 if (TSLIDER (displaybar -> scale )-> value != tile_source -> scale ) {
5052 TSLIDER (displaybar -> scale )-> value = tile_source -> scale ;
@@ -70,6 +72,8 @@ displaybar_page_changed(TileSource *tile_source, Displaybar *displaybar)
7072 printf ("displaybar_page_changed:\n" );
7173#endif /*DEBUG*/
7274
75+ g_assert (tile_source == displaybar -> tile_source );
76+
7377 gtk_spin_button_set_value (GTK_SPIN_BUTTON (displaybar -> page ),
7478 tile_source -> page );
7579}
@@ -82,7 +86,7 @@ displaybar_disconnect(Displaybar *displaybar)
8286 FREESID (displaybar -> tiles_changed_sid , displaybar -> tile_source );
8387 FREESID (displaybar -> page_changed_sid , displaybar -> tile_source );
8488
85- displaybar -> tile_source = NULL ;
89+ VIPS_UNREF ( displaybar -> tile_source ) ;
8690 }
8791}
8892
@@ -91,28 +95,33 @@ displaybar_disconnect(Displaybar *displaybar)
9195static void
9296displaybar_image_window_changed (ImageWindow * win , Displaybar * displaybar )
9397{
94- TileSource * tile_source = image_window_get_tile_source (win );
95-
9698#ifdef DEBUG
97- #endif /*DEBUG*/
9899 printf ("displaybar_image_window_changed:\n" );
100+ #endif /*DEBUG*/
99101
100102 displaybar_disconnect (displaybar );
101103
102- if (tile_source ) {
103- displaybar -> changed_sid = g_signal_connect (tile_source ,
104+ TileSource * new_tile_source = image_window_get_tile_source (win );
105+ if (new_tile_source ) {
106+ /* Set new source.
107+ */
108+ displaybar -> changed_sid = g_signal_connect (new_tile_source ,
104109 "changed" ,
105110 G_CALLBACK (displaybar_tile_source_changed ), displaybar );
106- displaybar -> tiles_changed_sid = g_signal_connect (tile_source ,
111+ displaybar -> tiles_changed_sid = g_signal_connect (new_tile_source ,
107112 "tiles-changed" ,
108113 G_CALLBACK (displaybar_tile_source_changed ), displaybar );
109- displaybar -> page_changed_sid = g_signal_connect (tile_source ,
114+ displaybar -> page_changed_sid = g_signal_connect (new_tile_source ,
110115 "page-changed" ,
111116 G_CALLBACK (displaybar_page_changed ), displaybar );
112117
113- displaybar -> tile_source = tile_source ;
118+ displaybar -> tile_source = new_tile_source ;
119+ g_object_ref (new_tile_source );
114120
115- displaybar_tile_source_changed (tile_source , displaybar );
121+ /* Init from new source.
122+ */
123+ displaybar_tile_source_changed (new_tile_source , displaybar );
124+ displaybar_page_changed (new_tile_source , displaybar );
116125 }
117126}
118127
@@ -122,11 +131,12 @@ displaybar_set_image_window(Displaybar *displaybar, ImageWindow *win)
122131 /* No need to ref ... win holds a ref to us.
123132 */
124133 displaybar -> win = win ;
125- displaybar -> tile_source = image_window_get_tile_source (win );
126134
127135 g_signal_connect_object (win , "changed" ,
128136 G_CALLBACK (displaybar_image_window_changed ),
129137 displaybar , 0 );
138+
139+ displaybar_image_window_changed (win , displaybar );
130140}
131141
132142static void
0 commit comments