summaryrefslogtreecommitdiff
path: root/src/glade-widget-class.h
blob: 26fb864dd7f831ec38ae7b2f1cce4ba2f0bf9c8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
#ifndef __GLADE_WIDGET_CLASS_H__
#define __GLADE_WIDGET_CLASS_H__

#include <glib-object.h>
#include <gmodule.h>
#include <gtk/gtk.h>
#include "glade-xml-utils.h"
#include "glade-property-class.h"

G_BEGIN_DECLS

#define GLADE_WIDGET_CLASS(gwc)           ((GladeWidgetClass *) gwc)
#define GLADE_IS_WIDGET_CLASS(gwc)        (gwc != NULL)
#define GLADE_VALID_CREATE_REASON(reason) (reason >= 0 && reason < GLADE_CREATE_REASONS)

typedef struct _GladeWidgetClass       GladeWidgetClass;
typedef struct _GladeSupportedChild    GladeSupportedChild;
typedef struct _GladeSignalClass       GladeSignalClass;


/**
 * GladeCreateReason:
 * @GLADE_CREATE_USER: Was created at the user's request
 *                     (this is a good time to set any properties
 *                     or add children to the project; like GtkFrame's 
 *                     label for example).
 * @GLADE_CREATE_COPY: Was created as a result of the copy/paste 
 *                     mechanism, at this point you can count on glade
 *                     to follow up with properties and children on 
 *                     its own.
 * @GLADE_CREATE_LOAD: Was created during the load process.
 * @GLADE_CREATE_REBUILD: Was created as a replacement for another project 
 *                        object; this only happens when the user is 
 *                        changing a property that is marked by the type 
 *                        system as G_PARAM_SPEC_CONSTRUCT_ONLY.
 * @GLADE_CREATE_REASONS: Never used.
 *
 * These are the reasons your #GladePostCreateFunc can be called.
 */
typedef enum _GladeCreateReason 
{
	GLADE_CREATE_USER = 0,
	GLADE_CREATE_COPY,
	GLADE_CREATE_LOAD,
	GLADE_CREATE_REBUILD,
	GLADE_CREATE_REASONS
} GladeCreateReason;

/**
 * GladeChildSetPropertyFunc:
 * @container: A #GObject container
 * @child: The #GObject child
 * @property_name: The property name
 * @value: The #GValue
 *
 * Called to set the packing property @property_name to @value
 * on the @child object of @container.
 */
typedef void (* GladeChildSetPropertyFunc)      (GObject            *container,
						 GObject            *child,
						 const gchar        *property_name,
						 const GValue       *value);

/**
 * GladeChildGetPropertyFunc:
 * @container: A #GObject container
 * @child: The #GObject child
 * @property_name: The property name
 * @value: The #GValue
 *
 * Called to get the packing property @property_name
 * on the @child object of @container into @value.
 */
typedef void (* GladeChildGetPropertyFunc)      (GObject            *container,
						 GObject            *child,
						 const gchar        *property_name,
						 GValue             *value);


/**
 * GladeGetChildrenFunc:
 * @container: A #GObject container
 * @Returns: A #GList of #GObject children.
 *
 * A function called to get @containers children.
 */
typedef GList *(* GladeGetChildrenFunc)         (GObject            *container);

/**
 * GladeAddChildFunc:
 * @parent: A #GObject container
 * @child: A #GObject child
 *
 * Called to add @child to @parent.
 */
typedef void   (* GladeAddChildFunc)            (GObject            *parent,
						 GObject            *child);
/**
 * GladeRemoveChildFunc:
 * @parent: A #GObject container
 * @child: A #GObject child
 *
 * Called to remove @child from @parent.
 */
typedef void   (* GladeRemoveChildFunc)         (GObject            *parent,
						 GObject            *child);

/**
 * GladeReplaceChildFunc:
 * @container: A #GObject container
 * @old: The old #GObject child
 * @new: The new #GObject child to take its place
 * 
 * Called to swap placeholders with project objects
 * in containers.
 */
typedef void   (* GladeReplaceChildFunc)        (GObject            *container,  
						 GObject            *old,
						 GObject            *new);

/**
 * GladePostCreateFunc:
 * @object: a #GObject
 * @reason: a #GladeCreateReason
 *
 * This function is called exactly once for any project object
 * instance and can be for any #GladeCreateReason.
 */
typedef void   (* GladePostCreateFunc)          (GObject            *object,
						 GladeCreateReason   reason);

/**
 * GladeGetInternalFunc:
 * @parent: A #GObject composite object
 * @name: A string identifier
 * @child: A return location for a #GObject
 *
 * Called to lookup @child in composite object @parent by @name.
 */
typedef void   (* GladeGetInternalFunc)         (GObject            *parent,
						 const gchar        *name,
						 GObject           **child);


/**
 * GladeEditorLaunchFunc:
 * @object: A #GObject
 *
 * Called to launch a custom editor for @object
 */
typedef void   (* GladeEditorLaunchFunc)        (GObject            *object);


/* GladeWidgetClass contains all the information we need regarding an widget
 * type. It is also used to store information that has been loaded to memory
 * for that object like the icon/mask.
 */
struct _GladeWidgetClass
{
	GType type;          /* GType of the widget */

	gchar *name;         /* Name of the widget, for example GtkButton */

	gchar *catalog;      /* The name of the widget catalog this class
			      * was declared by.
			      */

	gchar *book;         /* Devhelp search namespace
			      */

	GdkPixbuf *large_icon;     /* The 22x22 icon for the widget */

	GdkPixbuf *small_icon;     /* The 16x16 icon for the widget */


	GdkCursor *cursor;         /* a cursor for inserting widgets */


	gboolean fixed;      /* If this is a GtkContainer, use free-form
			      * placement with drag/resize/paste at mouse...
			      */

	gchar *generic_name; /* Use to generate names of new widgets, for
			      * example "button" so that we generate button1,
			      * button2, buttonX ..
			      */

	gchar *palette_name; /* Name used in the palette */

	GList *properties;   /* List of GladePropertyClass objects.
			      * [see glade-property.h ] this list contains
			      * properties about the widget that we are going
			      * to modify. Like "title", "label", "rows" .
			      * Each property creates an input in the propety
			      * editor.
			      */

	GList *signals;     /* List of GladeSignalClass objects */


	GList *children;    /* List of GladeSupportedChild objects */

        GList *child_packings; /* Default packing property values */

	GModule *module;	/* Module with the (optional) special functions
				 * needed for placeholder_replace, post_create_function
				 * and the set & get functions of the properties
				 * of this class.
				 */
				 
	gboolean toplevel;	/* If this class is toplevel */
	
	/* Executed after widget creation: it takes care of creating the
	 * GladeWidgets associated with internal children. It's also the place
	 * to set sane defaults, e.g. set the size of a window.
	 */
	GladePostCreateFunc           post_create_function;

	/* Retrieves the the internal child of the given name.
	 */
	GladeGetInternalFunc          get_internal_child;

	/* Entry point for custom editors.
	 */
	GladeEditorLaunchFunc         launch_editor;
};

struct _GladeSupportedChild
{
	GType        type;         /* This supported child type */

	GList       *properties;   /* List of GladePropertyClass objects representing
				    * child_properties of a container (the list is empty if
				    * this container has no child_properties)
				    * Note that the actual GladeProperty corresponding to
				    * each class end up in the packing_properties list of
				    * each _child_ of the container and thus are edited
				    * when the _child_ is selected.
				    */

	GladeAddChildFunc             add;              /* Adds a new child of this type */
	GladeRemoveChildFunc          remove;           /* Removes a child from the container */
	GladeGetChildrenFunc          get_children;     /* Returns a list of direct children for
							 * this support type.
							 */
	
	GladeChildSetPropertyFunc     set_property; /* Sets/Gets a packing property */
	GladeChildGetPropertyFunc     get_property; /* for this child */
	
	GladeReplaceChildFunc         replace_child;  /* This method replaces a 
						       * child widget with
						       * another one: it's used to
						       * replace a placeholder with
						       * a widget and viceversa.
						       */

	gchar                        *special_child_type; /* Special case code for children that
							   * are special children (like notebook tab 
							   * widgets for example).
							   */
};


/* GladeSignalClass contains all the info we need for a given signal, such as
 * the signal name, and maybe more in the future 
 */
struct _GladeSignalClass
{
	GSignalQuery query;

	const gchar *name;         /* Name of the signal, eg clicked */
	gchar       *type;         /* Name of the object class that this signal belongs to
				    * eg GtkButton */

};

#define glade_widget_class_create_widget(class, query, ...) \
    (glade_widget_class_create_widget_real (query, "class", class, __VA_ARGS__));
 
LIBGLADEUI_API
GladeWidgetClass    *glade_widget_class_new                (GladeXmlNode     *class_node,
							    const gchar      *catname,
							    const gchar      *library,
							    const gchar      *domain,
							    const gchar      *book);
LIBGLADEUI_API 
GladeWidget         *glade_widget_class_create_internal    (GladeWidget      *parent,
							    GObject          *internal_object,
							    const gchar      *internal_name,
							    const gchar      *parent_name,
							    gboolean          anarchist,
							    GladeCreateReason reason);
LIBGLADEUI_API
GladeWidget         *glade_widget_class_create_widget_real (gboolean          query, 
							    const gchar      *first_property,
							    ...);
LIBGLADEUI_API
void                 glade_widget_class_free               (GladeWidgetClass *widget_class);
LIBGLADEUI_API
GladeWidgetClass    *glade_widget_class_get_by_name        (const char       *name);
LIBGLADEUI_API
GladeWidgetClass    *glade_widget_class_get_by_type        (GType             type);
LIBGLADEUI_API
GList               *glade_widget_class_get_derived_types  (GType             type);
LIBGLADEUI_API
GType 	            glade_widget_class_get_type           (GladeWidgetClass *class);
LIBGLADEUI_API
void                 glade_widget_class_dump_param_specs   (GladeWidgetClass *class);
LIBGLADEUI_API
GladePropertyClass  *glade_widget_class_get_property_class (GladeWidgetClass *class,
							    const gchar      *name);
LIBGLADEUI_API
GladeSupportedChild *glade_widget_class_get_child_support  (GladeWidgetClass *class,
							    GType             child_type);
LIBGLADEUI_API
GParameter          *glade_widget_class_default_params             (GladeWidgetClass *class,
								    gboolean          construct,
								    guint            *n_params);
LIBGLADEUI_API
void                 glade_widget_class_container_add              (GladeWidgetClass *class,
								    GObject          *container,
								    GObject          *child);
LIBGLADEUI_API
void                 glade_widget_class_container_remove           (GladeWidgetClass *class,
								    GObject          *container,
								    GObject          *child);
LIBGLADEUI_API
gboolean             glade_widget_class_container_has_child        (GladeWidgetClass *class,
								    GObject          *container,
								    GObject          *child);
LIBGLADEUI_API
GList               *glade_widget_class_container_get_children     (GladeWidgetClass *class,
								    GObject          *container);
LIBGLADEUI_API
void                 glade_widget_class_container_set_property     (GladeWidgetClass *class,
								    GObject      *container,
								    GObject      *child,
								    const gchar  *property_name,
								    const GValue *value);
LIBGLADEUI_API
void                 glade_widget_class_container_get_property     (GladeWidgetClass *class,
								    GObject      *container,
								    GObject      *child,
								    const gchar  *property_name,
								    GValue       *value);
LIBGLADEUI_API
void                 glade_widget_class_container_replace_child    (GladeWidgetClass *class,
								    GObject      *container,
								    GObject      *old,
								    GObject      *new);
LIBGLADEUI_API
gboolean             glade_widget_class_contains_extra             (GladeWidgetClass *class);
LIBGLADEUI_API
gboolean             glade_widget_class_query                      (GladeWidgetClass *class);
LIBGLADEUI_API
GladePackingDefault *glade_widget_class_get_packing_default        (GladeWidgetClass *child_class,
								    GladeWidgetClass *container_class,
								    const gchar *propert_id);

#define glade_widget_class_from_pclass(pclass) \
    ((pclass) ? (GladeWidgetClass *)((GladePropertyClass *)(pclass))->handle : NULL)

G_END_DECLS

#endif /* __GLADE_WIDGET_CLASS_H__ */