1 /*
2  * gog-object.h :
3  *
4  * Copyright (C) 2003-2004 Jody Goldberg (jody@gnome.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) version 3.
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 #ifndef GOG_OBJECT_H
22 #define GOG_OBJECT_H
23 
24 #include <goffice/goffice.h>
25 
26 G_BEGIN_DECLS
27 
28 typedef enum {
29 	GOG_OBJECT_NAME_BY_ROLE	 = 1,
30 	GOG_OBJECT_NAME_BY_TYPE  = 2,
31 	GOG_OBJECT_NAME_MANUALLY = 3
32 } GogObjectNamingConv;
33 
34 typedef enum {
35 	GOG_MANUAL_SIZE_AUTO,   /* auto size, can't be changed */
36 	GOG_MANUAL_SIZE_WIDTH,  /*=1*/
37 	GOG_MANUAL_SIZE_HEIGHT, /*=2*/
38 	GOG_MANUAL_SIZE_FULL    /*=3 or GOG_MANUAL_SIZE_WIDTH | GOG_MANUAL_SIZE_HEIGHT */
39 } GogManualSizeMode;
40 
41 struct _GogObjectRole {
42 	char const *id;	/* for persistence */
43 	char const *is_a_typename;
44 	unsigned    int priority;
45 
46 	guint32		  	allowable_positions;
47 	GogObjectPosition 	default_position;
48 	GogObjectNamingConv	naming_conv;
49 
50 	gboolean   (*can_add)	  (GogObject const *parent);
51 	gboolean   (*can_remove)  (GogObject const *child);
52 	GogObject *(*allocate)    (GogObject *parent);
53 	void	   (*post_add)    (GogObject *parent, GogObject *child);
54 	void       (*pre_remove)  (GogObject *parent, GogObject *child);
55 	void       (*post_remove) (GogObject *parent, GogObject *child);
56 
57 	union { /* allow people to tack some useful tidbits on the end */
58 		int		i;
59 		gpointer	p;
60 	} user;
61 };
62 GType gog_object_role_get_type (void);
63 
64 struct _GogObject {
65 	GObject		 base;
66 
67 	unsigned int	 id;
68 	char		*user_name;	/* user assigned, NULL will fall back to system generated */
69 	char		*auto_name;	/* system generated, in current locale */
70 
71 	GogObjectRole const *role;
72 
73 	GogObject	*parent;
74 	GSList		*children;
75 
76 	GogObjectPosition  position;
77 	GogViewAllocation  manual_position;
78 
79 	unsigned needs_update : 1;
80 	unsigned being_updated : 1;
81 	unsigned explicitly_typed_role : 1; /* did we create it automaticly */
82 	unsigned invisible : 1;
83 
84 	void		*_priv; /* for future use */
85 };
86 
87 typedef struct {
88 	GObjectClass	base;
89 
90 	GHashTable *roles;
91 	GType	    view_type;
92 
93 	unsigned int use_parent_as_proxy : 1; /* when we change, pretend it was our parent */
94 	unsigned int roles_allocated:1;
95 	/*< public >*/
96 
97 	/* Virtuals */
98 	void	     (*update)		(GogObject *obj);
99 	void	     (*parent_changed)	(GogObject *obj, gboolean was_set);
100 	char const  *(*type_name)	(GogObject const *obj);
101 	void	     (*populate_editor)	(GogObject *obj,
102 					 GOEditor *editor,
103 					 GogDataAllocator *dalloc,
104 					 GOCmdContext *cc);
105 	void	     (*document_changed)(GogObject *obj, GODoc *doc);
106 	GogManualSizeMode (*get_manual_size_mode) (GogObject *obj);
107 	 /*< private >*/
108 	void	     (*reserved1)		(GogObject *view);
109 	void	     (*reserved2)		(GogObject *view);
110 	/*< public >*/
111 
112 	/* signals */
113 	void (*changed)		(GogObject *obj, gboolean size);
114 	void (*name_changed)	(GogObject *obj);
115 	void (*possible_additions_changed) (GogObject const *obj);
116 	void (*child_added)	   (GogObject *parent, GogObject *child);
117 	void (*child_removed)	   (GogObject *parent, GogObject *child);
118 	void (*child_name_changed) (GogObject const *obj, GogObject const *child);
119 	void (*children_reordered) (GogObject *obj);
120 	void (*update_editor)	   (GogObject *obj);
121 	 /*< private >*/
122 	void (*extra_signal1)	   (GogObject *view);
123 	void (*extra_signal2)	   (GogObject *view);
124 } GogObjectClass;
125 
126 #define GOG_TYPE_OBJECT		(gog_object_get_type ())
127 #define GOG_OBJECT(o)		(G_TYPE_CHECK_INSTANCE_CAST ((o), GOG_TYPE_OBJECT, GogObject))
128 #define GOG_IS_OBJECT(o)	(G_TYPE_CHECK_INSTANCE_TYPE ((o), GOG_TYPE_OBJECT))
129 #define GOG_OBJECT_CLASS(k)	(G_TYPE_CHECK_CLASS_CAST ((k), GOG_TYPE_OBJECT, GogObjectClass))
130 #define GOG_IS_OBJECT_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), GOG_TYPE_OBJECT))
131 #define GOG_OBJECT_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), GOG_TYPE_OBJECT, GogObjectClass))
132 
133 #define GOG_PARAM_FORCE_SAVE	(1 << (G_PARAM_USER_SHIFT+1))	/* even if the value == default */
134 #define GOG_PARAM_POSITION	(1 << (G_PARAM_USER_SHIFT+2))	/* position parameters */
135 
136 GType gog_object_get_type (void);
137 
138 typedef void (*GogDataDuplicator) (GogDataset const *src, GogDataset *dst);
139 
140 GogObject   *gog_object_dup		 (GogObject const *src, GogObject *new_parent, GogDataDuplicator datadup);
141 GogObject   *gog_object_get_parent	 (GogObject const *obj);
142 GogObject   *gog_object_get_parent_typed (GogObject const *obj, GType t);
143 GogGraph    *gog_object_get_graph	 (GogObject const *obj);
144 GogTheme    *gog_object_get_theme	 (GogObject const *obj);
145 unsigned     gog_object_get_id		 (GogObject const *obj);
146 char const  *gog_object_get_name	 (GogObject const *obj);
147 void	     gog_object_set_name	 (GogObject *obj, char *name, GError **err);
148 GSList      *gog_object_get_children	 (GogObject const *obj, GogObjectRole const *filter);
149 GogObject   *gog_object_get_child_by_role(GogObject const *obj, GogObjectRole const *role);
150 GogObject   *gog_object_get_child_by_name(GogObject const *obj, char const *name);
151 gpointer     gog_object_get_editor	 (GogObject *obj,
152 					  GogDataAllocator *dalloc, GOCmdContext *cc);
153 GogView	  *gog_object_new_view		 (GogObject const *obj, GogView *parent);
154 gboolean   gog_object_is_deletable	 (GogObject const *obj);
155 GSList    *gog_object_possible_additions (GogObject const *parent);
156 GogObject *gog_object_add_by_role	 (GogObject *parent,
157 					  GogObjectRole const *role, GogObject *child);
158 GogObject   *gog_object_add_by_name	 (GogObject *parent,
159 					  char const *role, GogObject *child);
160 void		  gog_object_can_reorder (GogObject const *obj,
161 					  gboolean *inc_ok, gboolean *dec_ok);
162 GogObject	 *gog_object_reorder	 (GogObject const *obj,
163 					  gboolean inc, gboolean goto_max);
164 
165 #define	  gog_object_is_visible(obj) (!((GogObject*)obj)->invisible)
166 void		  gog_object_set_invisible	       (GogObject *obj, gboolean invisible);
167 GogObjectPosition gog_object_get_position_flags	       (GogObject const *obj, GogObjectPosition mask);
168 gboolean          gog_object_set_position_flags        (GogObject *obj, GogObjectPosition flags,
169 							GogObjectPosition mask);
170 gboolean 	  gog_object_is_default_position_flags (GogObject const *obj, char const *name);
171 void	          gog_object_get_manual_position       (GogObject *obj, GogViewAllocation *pos);
172 void 		  gog_object_set_manual_position       (GogObject *obj, GogViewAllocation const *pos);
173 
174 GogViewAllocation gog_object_get_manual_allocation (GogObject *gobj,
175 						    GogViewAllocation const *parent_allocation,
176 						    GogViewRequisition const *requisition);
177 
178 GogObjectRole const *gog_object_find_role_by_name (GogObject const *obj,
179 						   char const *role);
180 
181 /* protected */
182 void	 gog_object_update		  (GogObject *obj);
183 gboolean gog_object_request_update	  (GogObject *obj);
184 void 	 gog_object_emit_changed	  (GogObject *obj, gboolean size);
185 gboolean gog_object_clear_parent	  (GogObject *obj);
186 gboolean gog_object_set_parent		  (GogObject *child, GogObject *parent,
187 					   GogObjectRole const *role, unsigned int id);
188 void 	 gog_object_register_roles	  (GogObjectClass *klass,
189 					   GogObjectRole const *roles, unsigned int n_roles);
190 void 	 gog_object_request_editor_update (GogObject *obj);
191 
192 void	 gog_object_document_changed	  (GogObject *obj, GODoc *doc);
193 GogManualSizeMode gog_object_get_manual_size_mode  (GogObject *obj);
194 
195 G_END_DECLS
196 
197 #endif /* GOG_OBJECT_H */
198