3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU Lesser General Public License as published by
5 * the Free Software Foundation.
7 * This program is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * You should have received a copy of the GNU Lesser General Public License
13 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 * Chris Lahey <clahey@ximian.com>
19 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
23 #include "e-canvas-utils.h"
27 #include <libedataserver/libedataserver.h>
30 e_canvas_item_move_absolute (GnomeCanvasItem
*item
,
34 cairo_matrix_t translate
;
36 g_return_if_fail (GNOME_IS_CANVAS_ITEM (item
));
38 cairo_matrix_init_translate (&translate
, dx
, dy
);
40 gnome_canvas_item_set_matrix (item
, &translate
);
44 compute_offset (gint top
,
49 gint size
= bottom
- top
;
52 if (top
<= page_top
&& bottom
>= page_bottom
)
55 if (bottom
> page_bottom
)
56 offset
= (bottom
- page_bottom
);
57 if (top
< page_top
+ offset
)
58 offset
= (top
- page_top
);
60 if (top
<= page_top
+ offset
&& bottom
>= page_bottom
+ offset
)
63 if (top
< page_top
+ size
* 3 / 2 + offset
)
64 offset
= top
- (page_top
+ size
* 3 / 2);
65 if (bottom
> page_bottom
- size
* 3 / 2 + offset
)
66 offset
= bottom
- (page_bottom
- size
* 3 / 2);
67 if (top
< page_top
+ size
* 3 / 2 + offset
)
68 offset
= top
- ((page_top
+ page_bottom
- (bottom
- top
)) / 2);
74 e_canvas_show_area (GnomeCanvas
*canvas
,
87 g_return_if_fail (canvas
!= NULL
);
88 g_return_if_fail (GNOME_IS_CANVAS (canvas
));
90 h
= gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas
));
91 page_size
= gtk_adjustment_get_page_size (h
);
92 lower
= gtk_adjustment_get_lower (h
);
93 upper
= gtk_adjustment_get_upper (h
);
94 value
= gtk_adjustment_get_value (h
);
95 dx
= compute_offset (x1
, x2
, value
, value
+ page_size
);
97 gtk_adjustment_set_value (h
, CLAMP (value
+ dx
, lower
, upper
- page_size
));
99 v
= gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas
));
100 page_size
= gtk_adjustment_get_page_size (v
);
101 lower
= gtk_adjustment_get_lower (v
);
102 upper
= gtk_adjustment_get_upper (v
);
103 value
= gtk_adjustment_get_value (v
);
104 dy
= compute_offset (y1
, y2
, value
, value
+ page_size
);
106 gtk_adjustment_set_value (v
, CLAMP (value
+ dy
, lower
, upper
- page_size
));
110 e_canvas_item_show_area (GnomeCanvasItem
*item
,
116 g_return_if_fail (item
!= NULL
);
117 g_return_if_fail (GNOME_IS_CANVAS_ITEM (item
));
119 gnome_canvas_item_i2w (item
, &x1
, &y1
);
120 gnome_canvas_item_i2w (item
, &x2
, &y2
);
122 e_canvas_show_area (item
->canvas
, x1
, y1
, x2
, y2
);
126 e_canvas_area_shown (GnomeCanvas
*canvas
,
132 GtkAdjustment
*h
, *v
;
139 g_return_val_if_fail (canvas
!= NULL
, FALSE
);
140 g_return_val_if_fail (GNOME_IS_CANVAS (canvas
), FALSE
);
142 h
= gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas
));
143 page_size
= gtk_adjustment_get_page_size (h
);
144 lower
= gtk_adjustment_get_lower (h
);
145 upper
= gtk_adjustment_get_upper (h
);
146 value
= gtk_adjustment_get_value (h
);
147 dx
= compute_offset (x1
, x2
, value
, value
+ page_size
);
148 if (CLAMP (value
+ dx
, lower
, upper
- page_size
) - value
!= 0)
151 v
= gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas
));
152 page_size
= gtk_adjustment_get_page_size (v
);
153 lower
= gtk_adjustment_get_lower (v
);
154 upper
= gtk_adjustment_get_upper (v
);
155 value
= gtk_adjustment_get_value (v
);
156 dy
= compute_offset (y1
, y2
, value
, value
+ page_size
);
157 if (CLAMP (value
+ dy
, lower
, upper
- page_size
) - value
!= 0)
163 e_canvas_item_area_shown (GnomeCanvasItem
*item
,
169 g_return_val_if_fail (item
!= NULL
, FALSE
);
170 g_return_val_if_fail (GNOME_IS_CANVAS_ITEM (item
), FALSE
);
172 gnome_canvas_item_i2w (item
, &x1
, &y1
);
173 gnome_canvas_item_i2w (item
, &x2
, &y2
);
175 return e_canvas_area_shown (item
->canvas
, x1
, y1
, x2
, y2
);
187 doubs_and_canvas_free (gpointer ptr
)
189 DoubsAndCanvas
*dac
= ptr
;
192 g_object_unref (dac
->canvas
);
198 show_area_timeout (gpointer data
)
200 DoubsAndCanvas
*dac
= data
;
202 e_canvas_show_area (dac
->canvas
, dac
->x1
, dac
->y1
, dac
->x2
, dac
->y2
);
208 e_canvas_item_show_area_delayed (GnomeCanvasItem
*item
,
217 source
= e_canvas_item_show_area_delayed_ex (item
, x1
, y1
, x2
, y2
, delay
);
219 g_source_unref (source
);
222 /* Use g_source_unref() when done with the returned pointer. */
224 e_canvas_item_show_area_delayed_ex (GnomeCanvasItem
*item
,
234 g_return_val_if_fail (item
!= NULL
, NULL
);
235 g_return_val_if_fail (GNOME_IS_CANVAS_ITEM (item
), NULL
);
237 gnome_canvas_item_i2w (item
, &x1
, &y1
);
238 gnome_canvas_item_i2w (item
, &x2
, &y2
);
240 dac
= g_new (DoubsAndCanvas
, 1);
245 dac
->canvas
= g_object_ref (item
->canvas
);
247 source
= g_timeout_source_new (delay
);
248 g_source_set_callback (source
, show_area_timeout
, dac
, doubs_and_canvas_free
);
249 g_source_set_name (source
, G_STRFUNC
);
250 g_source_attach (source
, NULL
);