1 #ifndef _GNM_SHEET_OBJECT_IMPL_H_
2 # define _GNM_SHEET_OBJECT_IMPL_H_
3 
4 G_BEGIN_DECLS
5 
6 #include <sheet-object.h>
7 #include <goffice/goffice.h>
8 #include <gsf/gsf-libxml.h>
9 #include <libxml/tree.h>
10 #include <glib-object.h>
11 
12 typedef enum {
13 	SHEET_OBJECT_IS_VISIBLE	= 1 << 0,	/* user selectable */
14 	SHEET_OBJECT_PRINT	= 1 << 1,
15 	SHEET_OBJECT_CAN_PRESS	= 1 << 2,
16 	SHEET_OBJECT_CAN_RESIZE	= 1 << 3,
17 	SHEET_OBJECT_CAN_EDIT	= 1 << 4,
18 
19 	/* Gnumeric specific properties */
20 	SHEET_OBJECT_MOVE_WITH_CELLS	= 1 << 16,
21 	SHEET_OBJECT_SIZE_WITH_CELLS	= 1 << 17,
22 	SHEET_OBJECT_OBSCURED		= 1 << 18	/* cells associated with region are hidden */
23 } SheetObjectFlags;
24 
25 struct _SheetObject {
26 	GObject            parent_object;
27 	Sheet             *sheet;
28 	GList             *realized_list;
29 	SheetObjectAnchor  anchor;
30 	SheetObjectFlags   flags;
31 	char              *name;
32 };
33 
34 typedef void (*SheetObjectActionFunc) (SheetObject *so, SheetControl *sc);
35 typedef gboolean (*SheetObjectEnableActionFunc) (SheetObject const *so);
36 typedef struct {
37 	char const *icon;	/* optionally NULL */
38 	char const *label;	/* NULL for separators */
39 	char const *msg_domain;	/* for plugins to specify translations */
40 	int  submenu;		/* > 1 starts a menu, < 1 end one */
41 	SheetObjectActionFunc	func;
42 	SheetObjectEnableActionFunc	enable_func;
43 } SheetObjectAction;
44 
45 typedef struct {
46 	GObjectClass parent_class;
47 
48 	/* Signals */
49 	void (*bounds_changed) (SheetObject *so);
50 	void (*unrealized)     (SheetObject *so);
51 	void (*signal_pad1)	(void);
52 	void (*signal_pad2)	(void);
53 
54 	/* Virtual methods */
55 	gboolean (*remove_from_sheet) (SheetObject	*so);
56 	gboolean   (*assign_to_sheet) (SheetObject	*so,
57 				       Sheet		*sheet);
58 
59 	SheetObjectView	*(*new_view) (SheetObject	*so,
60 				      SheetObjectViewContainer *container);
61 	void        (*populate_menu) (SheetObject	*so,
62 				      GPtrArray		*actions);
63 	void	      (*user_config) (SheetObject	*so,
64 				      SheetControl	*s_control);
65 	void      (*prep_sax_parser) (SheetObject *so,
66 				      GsfXMLIn *xin, xmlChar const **attrs,
67 				      GnmConventions const *convs);
68 	void        (*write_xml_sax) (SheetObject const *so,
69 				      GsfXMLOut *output,
70 				      GnmConventions const *convs);
71 	void		    (*copy)  (SheetObject *dst,
72 				      SheetObject const *src);
73 
74 	void	     (*default_size) (SheetObject const *so,
75 				      double *w, double *h);
76 
77 	void	       (*draw_cairo) (SheetObject const *so, cairo_t *cr,
78 				      double width, double height);
79 
80 	void          (*foreach_dep) (SheetObject *so,
81 				      SheetObjectForeachDepFunc func,
82 				      gpointer user);
83 
84 	void (*func_pad1)	(void);
85 	void (*func_pad2)	(void);
86 
87 	/*
88 	 * If false, we draw a rectangle where the object is going to
89 	 * be layed out If true, we draw the object while laying
90 	 * it out on the sheet.
91 	 */
92 	gboolean rubber_band_directly;
93 
94 	/*
95 	 * If FALSE, a mouse click will select the object.
96 	 */
97 	gboolean interactive;
98 
99 	char const *xml_export_name;
100 
101 	void *data_pad1;
102 	void *data_pad2;
103 	void *data_pad3;
104 	void *data_pad4;
105 } SheetObjectClass;
106 #define GNM_SO_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GNM_SO_TYPE, SheetObjectClass))
107 
108 /***************************************************************************/
109 
110 struct _SheetObjectView {
111 	GocGroup base;
112 
113 	GnmSOResizeMode resize_mode;
114 };
115 
116 typedef struct {
117 	GocGroupClass base;
118 
119 	void (*active)	   (SheetObjectView *sov, gboolean is_active);
120 	void (*set_bounds) (SheetObjectView *sov,
121 			    double const *coords, gboolean visible);
122 } SheetObjectViewClass;
123 
124 #define GNM_SO_VIEW_TYPE		(sheet_object_view_get_type ())
125 #define GNM_SO_VIEW(o)		(G_TYPE_CHECK_INSTANCE_CAST((o), GNM_SO_VIEW_TYPE, SheetObjectView))
126 #define GNM_IS_SO_VIEW(o)		(G_TYPE_CHECK_INSTANCE_TYPE((o), GNM_SO_VIEW_TYPE))
127 #define GNM_SO_VIEW_CLASS(k)	(G_TYPE_CHECK_CLASS_CAST((k), GNM_SO_VIEW_TYPE, SheetObjectViewIface))
128 #define GNM_IS_SO_VIEW_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE((k), GNM_SO_VIEW_TYPE))
129 #define GNM_SO_VIEW_GET_CLASS(o)  (G_TYPE_INSTANCE_GET_CLASS ((o), GNM_SO_VIEW_TYPE, SheetObjectViewClass))
130 
131 GType	     sheet_object_view_get_type	  (void);
132 SheetObject *sheet_object_view_get_so	  (SheetObjectView *sov);
133 void	     sheet_object_view_set_bounds (SheetObjectView *sov,
134 					   double const *coords,
135 					   gboolean visible);
136 GocItem     *sheet_object_view_get_item   (SheetObjectView *sov);
137 
138 /***************************************************************************/
139 
140 typedef struct {
141 	GTypeInterface base;
142 
143 	/* Map between anchors and un-normalized coordinates */
144 	void (*anchor_to_coords) (SheetObjectViewContainer *sovc,
145 				  SheetObjectAnchor const *input, double *output);
146 	void (*coords_to_anchor) (SheetObjectViewContainer *sovc,
147 				  double const *input, SheetObjectAnchor *output);
148 } SheetObjectViewContainerIface;
149 
150 #if 0
151 void so_vc_anchor_to_coords (SheetObjectViewContainer *sovc,
152 			     SheetObjectAnchor const *input, double *output);
153 void so_vc_coords_to_anchor (SheetObjectViewContainer *sovc,
154 			     double const *input, SheetObjectAnchor *output);
155 #endif
156 
157 /***************************************************************************/
158 
159 typedef struct {
160 	GTypeInterface base;
161 
162 	GtkTargetList *(*get_target_list) (SheetObject const *so);
163 	void           (*write_image)	  (SheetObject const *so,
164 					   char const *format,
165 					   double resolution,
166 					   GsfOutput *output,
167 					   GError **err);
168 } SheetObjectImageableIface;
169 
170 /***************************************************************************/
171 
172 typedef struct {
173 	GTypeInterface base;
174 
175 	GtkTargetList *(*get_target_list) (SheetObject const *so);
176 	void           (*write_object)	  (SheetObject const *so,
177 					   char const *format,
178 					   GsfOutput *output, GError **err,
179 					   GnmConventions const *convs);
180 } SheetObjectExportableIface;
181 
182 G_END_DECLS
183 
184 #endif /* _GNM_SHEET_OBJECT_IMPL_H_ */
185