1 /* abstract base class for all nip objects
2  */
3 
4 /*
5 
6     Copyright (C) 1991-2003 The National Gallery
7 
8     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation; either version 2 of the License, or
11     (at your option) any later version.
12 
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17 
18     You should have received a copy of the GNU General Public License along
19     with this program; if not, write to the Free Software Foundation, Inc.,
20     51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 
22  */
23 
24 /*
25 
26     These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
27 
28  */
29 
30 #define TYPE_IOBJECT (iobject_get_type())
31 #define IOBJECT( obj ) \
32 	(G_TYPE_CHECK_INSTANCE_CAST( (obj), TYPE_IOBJECT, iObject ))
33 #define IOBJECT_CLASS( klass ) \
34 	(G_TYPE_CHECK_CLASS_CAST( (klass), TYPE_IOBJECT, iObjectClass))
35 #define IS_IOBJECT( obj ) \
36 	(G_TYPE_CHECK_INSTANCE_TYPE( (obj), TYPE_IOBJECT ))
37 #define IS_IOBJECT_CLASS( klass ) \
38 	(G_TYPE_CHECK_CLASS_TYPE( (klass), TYPE_IOBJECT ))
39 #define IOBJECT_GET_CLASS( obj ) \
40 	(G_TYPE_INSTANCE_GET_CLASS( (obj), TYPE_IOBJECT, iObjectClass ))
41 
42 /* Handy iobject_destroy() shortcut.
43  */
44 #define IDESTROY( O ) { \
45 	if( O ) { \
46 		(void) iobject_destroy( IOBJECT( O ) ); \
47 		( O ) = NULL; \
48 	} \
49 }
50 
51 struct _iObject {
52 	GObject parent_object;
53 
54 	/* My instance vars.
55 	 */
56         char *name;             /* iObject name */
57         char *caption;          /* Comment of some sort */
58 
59 	/* True when created ... the 1 reference that gobject makes is
60 	 * 'floating' and not owned by anyone. Do _sink() after every _ref()
61 	 * to transfer ownership to the parent container. Upshot: no need to
62 	 * _unref() after _add() in _new().
63 	 */
64 	gboolean floating;
65 
66 	/* Stop destroy loops with this.
67 	 */
68 	gboolean in_destruction;
69 };
70 
71 typedef struct _iObjectClass {
72 	GObjectClass parent_class;
73 
74 	/* End object's lifetime, just like gtk_object_destroy.
75 	 */
76 	void (*destroy)( iObject * );
77 
78 	/* Something about the object has changed. Should use glib's properties
79 	 * but fix this later.
80 	 */
81 	void (*changed)( iObject * );
82 
83 	/* Try and say something useful about us.
84 	 */
85 	void (*info)( iObject *, VipsBuf * );
86 
87 	/* Called on _changed() to update the caption. Define this if you want
88 	 * the caption to be an explanatory note about the object.
89 	 */
90 	const char *(*generate_caption)( iObject * );
91 
92 	/* The i18n name for this class we show the user. FOr example,
93 	 * Workspace is referred to as "tab" by the user.
94 	 */
95 	const char *user_name;
96 } iObjectClass;
97 
98 #define IOBJECT_GET_CLASS_NAME( obj ) \
99 	((G_TYPE_INSTANCE_GET_CLASS( (obj), \
100 		TYPE_IOBJECT, iObjectClass ))->user_name)
101 
102 void *iobject_destroy( iObject *iobject );
103 void *iobject_changed( iObject *iobject );
104 void *iobject_info( iObject *iobject, VipsBuf * );
105 
106 GType iobject_get_type( void );
107 
108 void *iobject_test_name( iObject *iobject, const char *name );
109 void *iobject_print( iObject *iobject );
110 void iobject_set( iObject *iobject, const char *name, const char *caption );
111 void iobject_sink( iObject *iobject );
112 void iobject_dump( iObject *iobject );
113