1 /*
2  * goc-canvas.h :
3  *
4  * Copyright (C) 2008 Jean Brefort (jean.brefort@normalesup.org)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
19  * USA
20  */
21 
22 #ifndef GOC_CANVAS_H
23 #define GOC_CANVAS_H
24 
25 #include <goffice/goffice.h>
26 #ifdef GOFFICE_WITH_GTK
27 #include <gdk/gdk.h>
28 #endif
29 
30 G_BEGIN_DECLS
31 
32 typedef enum {
33 	GOC_DIRECTION_LTR,
34 	GOC_DIRECTION_RTL,
35 	GOC_DIRECTION_MAX
36 } GocDirection;
37 
38 struct _GocCanvas {
39 #ifdef GOFFICE_WITH_GTK
40 	GtkLayout base;
41 #else
42 	GObject base;
43 #endif
44 	double scroll_x1, scroll_y1;
45 	double pixels_per_unit;
46 	int width, height;
47 	GocGroup *root;
48 	GocItem *grabbed_item;
49 	GocItem	*last_item;
50 	GODoc *document;
51 #ifdef GOFFICE_WITH_GTK
52 	GdkEvent *cur_event;
53 #endif
54 	GocDirection direction;
55 	gpointer priv;
56 };
57 
58 #ifdef GOFFICE_WITH_GTK
59 typedef GtkLayoutClass GocCanvasClass;
60 #else
61 typedef GObjectClass GocCanvasClass;
62 #endif
63 
64 #define GOC_TYPE_CANVAS	(goc_canvas_get_type ())
65 #define GOC_CANVAS(o)	(G_TYPE_CHECK_INSTANCE_CAST ((o), GOC_TYPE_CANVAS, GocCanvas))
66 #define GOC_IS_CANVAS(o)	(G_TYPE_CHECK_INSTANCE_TYPE ((o), GOC_TYPE_CANVAS))
67 
68 GType goc_canvas_get_type (void);
69 
70 GocGroup	*goc_canvas_get_root (GocCanvas *canvas);
71 int		 goc_canvas_get_width (GocCanvas *canvas);
72 int		 goc_canvas_get_height (GocCanvas *canvas);
73 void		 goc_canvas_scroll_to (GocCanvas *canvas, double x, double y);
74 void		 goc_canvas_get_scroll_position (GocCanvas *canvas, double *x, double *y);
75 void		 goc_canvas_set_pixels_per_unit (GocCanvas *canvas, double pixels_per_unit);
76 double		 goc_canvas_get_pixels_per_unit (GocCanvas *canvas);
77 void		 goc_canvas_invalidate (GocCanvas *canvas, double x0, double y0, double x1, double y1);
78 void		 goc_canvas_invalidate_region (GocCanvas *canvas, GocItem *item, cairo_region_t *region);
79 gboolean         goc_canvas_get_realized (GocCanvas *canvas);
80 GocItem		*goc_canvas_get_item_at (GocCanvas *canvas, double x, double y);
81 void		 goc_canvas_grab_item (GocCanvas *canvas, GocItem *item);
82 void		 goc_canvas_ungrab_item (GocCanvas *canvas);
83 GocItem		*goc_canvas_get_grabbed_item (GocCanvas *canvas);
84 void		 goc_canvas_set_document (GocCanvas *canvas, GODoc *document);
85 GODoc		*goc_canvas_get_document (GocCanvas *canvas);
86 #ifdef GOFFICE_WITH_GTK
87 GdkEvent	*goc_canvas_get_cur_event (GocCanvas *canvas);
88 #endif
89 void		 goc_canvas_set_direction (GocCanvas *canvas, GocDirection direction);
90 GocDirection     goc_canvas_get_direction (GocCanvas *canvas);
91 void		 goc_canvas_w2c (GocCanvas *canvas, int x, int y, double *x_, double *y_);
92 void		 goc_canvas_c2w (GocCanvas *canvas, double x, double y, int *x_, int *y_);
93 void		 goc_canvas_render (GocCanvas *canvas, cairo_t *cr, double x0, double y0, double x1, double y1);
94 void		 goc_canvas_get_bounds (GocCanvas *canvas, double *x0, double *y0, double *x1, double *y1);
95 
96 void _goc_canvas_remove_item (GocCanvas *canvas, GocItem *item);
97 
98 G_END_DECLS
99 
100 #endif  /* GOC_CANVAS_H */
101