aboutsummaryrefslogtreecommitdiff
path: root/generic/Item.h
blob: b72e02ecab63c367d30d4ddc6b62043f3bb849e3 (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
367
368
369
370
371
372
373
374
375
376
377
/*
 * Item.h -- Header to access items' common state and functions.
 *
 * Authors		: Patrick Lecoanet.
 * Creation date	:
 *
 * $Id$
 */

/*
 *  Copyright (c) 1996 1999 CENA, Patrick Lecoanet --
 *
 * This code is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This code is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this code; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */


#ifndef _Item_h
#define _Item_h


#include "PostScript.h"
#include "Attrs.h"
#include "Types.h"
#include "List.h"
#include "Field.h"

#include <X11/Xlib.h>
#include <tkInt.h>


/*
 * Types and constants for attribute processing.
 */
typedef struct _ZnAttrConfig {
  int	type;
  char	*name;
  Tk_Uid uid;
  int	offset;
  int	bool_bit;
  int	flags;
  ZnBool read_only;
} ZnAttrConfig;

/*
 * When adding new type in the following enum
 * do not forget to update attribute_type_strings
 * in Item.c.
 */
#define	ZN_CONFIG_END		0
#define ZN_CONFIG_BOOL		1
#define ZN_CONFIG_BITMAP	2
#define ZN_CONFIG_BITMAP_LIST	3
#define ZN_CONFIG_STRING	4
#define ZN_CONFIG_FONT		5
#define ZN_CONFIG_EDGE_LIST	6
#define ZN_CONFIG_RELIEF	7
#define ZN_CONFIG_DIM		8
#define ZN_CONFIG_PRI		9
#define ZN_CONFIG_ALIGNMENT	10
#define ZN_CONFIG_AUTO_ALIGNMENT 11
#define ZN_CONFIG_LINE_END	12
#define ZN_CONFIG_LABEL_FORMAT	13
#define ZN_CONFIG_LINE_STYLE	14
#define ZN_CONFIG_LINE_SHAPE	15
#define ZN_CONFIG_ITEM		16
#define ZN_CONFIG_ANGLE		17
#define ZN_CONFIG_INT		18
#define ZN_CONFIG_UINT		19
#define ZN_CONFIG_POINT		20
#define ZN_CONFIG_ANCHOR	21
#define ZN_CONFIG_TAG_LIST	22
#define ZN_CONFIG_MAP_INFO	23
#define ZN_CONFIG_IMAGE		24
#define ZN_CONFIG_LEADER_ANCHORS 25
#define ZN_CONFIG_JOIN_STYLE	26
#define	ZN_CONFIG_CAP_STYLE	27
#define	ZN_CONFIG_GRADIENT	28
#define ZN_CONFIG_GRADIENT_LIST	29
#define	ZN_CONFIG_WINDOW	30
#define	ZN_CONFIG_ALPHA		31
#define	ZN_CONFIG_FILL_RULE	32

#define ZN_DRAW_FLAG	1 << 0
#define	ZN_COORDS_FLAG	1 << 1
#define ZN_TRANSFO_FLAG	1 << 2
#define	ZN_REPICK_FLAG	1 << 3
#define	ZN_BORDER_FLAG	1 << 4
#define	ZN_CLFC_FLAG	1 << 5	/* Clear Label Format Cache. */
#define ZN_IMAGE_FLAG	1 << 6	/* Update image pointer. */
#define ZN_VIS_FLAG	1 << 7	/* Visibility has changed. */
#define ZN_MOVED_FLAG	1 << 8	/* Item has moved. */
#define ZN_ITEM_FLAG	1 << 9	/* Signal a change in an item type attribute. */
#define ZN_MAP_INFO_FLAG 1 << 10	/* Update mapinfo pointer. */
#define ZN_LAYOUT_FLAG	1 << 10	/* A layout need update. */
#define ZN_POLAR_FLAG	1 << 11	/* Signal a cartesian to polar change. */
#define ZN_CARTESIAN_FLAG 1 << 12	/* Signal a polar to cartesian change. */
#define ZN_TILE_FLAG	1 << 13	/* Update tile pointer. */
#define ZN_WINDOW_FLAG	1 << 14	/* Signal a change in a window type attribute. */


/*
 * This constant marks a non existant item
*/
#define ZN_NO_ITEM		NULL

/*
 * Constants for item parts. The item indexable parts (named fields) are coded
 * as positive or null integers. The item specific parts (not indexable) are
 * coded as negatives beginning at -2 up to -9 which is the current limit. The
 * -1 value is reserved to indicate no part.
 */
#define ZnPartToBit(part)	(1 << (ABS(part)-2))
#define ZN_NO_PART		-1

/*
 * Some flags macros.
 */
#define ISSET(var, mask)	((var) & (mask))
#define ISCLEAR(var, mask)	(((var) & (mask)) == 0)
#define SET(var,mask)		((var) |= (mask))
#define CLEAR(var, mask)	((var) &= ~(mask))
#define ASSIGN(var, mask, bool)	((bool) ? SET((var), (mask)) : CLEAR((var), (mask)))

/*
 * Item flags values.
 */
#define ZN_VISIBLE_BIT		(1<<0)
#define ZN_SENSITIVE_BIT	(1<<1)
#define ZN_UPDATE_DEPENDENT_BIT	(1<<2)
#define ZN_COMPOSE_SCALE_BIT	(1<<3)
#define ZN_COMPOSE_ROTATION_BIT	(1<<4)
#define ZN_COMPOSE_ALPHA_BIT	(1<<5)
/*
 * Must be kept one greater than the last flag shift count.
 */
#define ZN_PRIVATE_FLAGS_OFFSET 6


/*
 * Operator constants for the coord method.
 */
#define ZN_COORDS_READ		0
#define ZN_COORDS_READ_ALL	1
#define ZN_COORDS_REPLACE	2
#define ZN_COORDS_REPLACE_ALL	3
#define ZN_COORDS_ADD		4
#define ZN_COORDS_ADD_LAST	5
#define ZN_COORDS_REMOVE	6
  

struct _ZnWInfo;
struct _ZnTransfo;

/*
 * Item record header --
 */
typedef struct _ZnItemStruct {
  /* Private data */
  long			id;
  ZnList		tags;
  struct _ZnWInfo	*wi;			/* The widget this item is on	*/
  struct _ZnItemClassStruct *class;		/* item class			*/
  struct _ZnItemStruct	*previous;		/* previous item in group list	*/
  struct _ZnItemStruct	*next;			/* next item in group list	*/
  ZnBBox		item_bounding_box;	/* device item bounding box	*/

  /* Common attributes */
  unsigned short	flags;			
  unsigned short	part_sensitive;		/* Currently limited to 16 parts per item */
  short			inv_flags;
  struct _ZnItemStruct	*parent;
  int			priority;
  struct _ZnTransfo	*transfo;
  struct _ZnItemStruct	*connected_item;	/* Item this item is connected to 	*/
#ifdef GL
#ifdef GL_LIST
  GLuint		gl_list;		/* Display list storing the item graphics */
#endif
#endif
} ZnItemStruct, *ZnItem;

typedef struct _ZnToAreaStruct {
  Tk_Uid	tag_uid;
  ZnBool	enclosed;
  ZnItem	in_group;
  ZnBool	report;
  ZnBool	recursive;
  ZnBBox	*area;
} ZnToAreaStruct, *ZnToArea;

typedef struct _ZnPickStruct {
  int		aperture;
  ZnItem	in_group;
  ZnItem	start_item;
  ZnBool	recursive;
  ZnPoint	*point;
  ZnItem 	a_item;
  int		a_part;
} ZnPickStruct, *ZnPick;


/*
 * Item class record --
 */
typedef int (*ZnItemInitMethod)(ZnItem item, int *argc, Tcl_Obj *CONST *args[]);
typedef int (*ZnItemConfigureMethod)(ZnItem item, int argc, Tcl_Obj *CONST args[],
				     int *flags);
typedef int (*ZnItemQueryMethod)(ZnItem item, int argc, Tcl_Obj *CONST args[]);
typedef void (*ZnItemCloneMethod)(ZnItem item);
typedef void (*ZnItemDestroyMethod)(ZnItem item);
typedef void (*ZnItemDrawMethod)(ZnItem item);
typedef void (*ZnItemRenderMethod)(ZnItem item);
typedef void (*ZnItemComputeCoordinatesMethod)(ZnItem item, ZnBool force);
typedef int (*ZnItemToAreaMethod)(ZnItem item, ZnToArea ta);
typedef ZnReal (*ZnItemPickMethod)(ZnItem item, ZnPick ps);
typedef ZnBool (*ZnItemIsSensitiveMethod)(ZnItem item, int part);
typedef struct _ZnFieldSetStruct* (*ZnItemGetFieldSetMethod)(ZnItem item);
typedef int (*ZnItemContourMethod)(ZnItem item, int cmd, int index, ZnPoly *poly);
typedef void (*ZnItemPickVertexMethod)(ZnItem item, ZnPoint *p, int *contour,
				       int *vertex, int *o_vertex);
typedef void (*ZnItemGetAnchorMethod)(ZnItem item, Tk_Anchor anchor, ZnPoint *p);
typedef ZnBool (*ZnItemGetClipVerticesMethod)(ZnItem item, ZnTriStrip *tristrip);
typedef ZnBool (*ZnItemGetContoursMethod)(ZnItem item, ZnPoly *poly);
typedef int (*ZnItemCoordsMethod)(ZnItem item, int contour, int index, int cmd,
				  ZnPoint **points, char **controls, unsigned int *num_points);
typedef void (*ZnItemInsertCharsMethod)(ZnItem item, int field, int *index,
					char *chars);
typedef void (*ZnItemDeleteCharsMethod)(ZnItem item, int field, int *first,
					int *last);
typedef void (*ZnItemCursorMethod)(ZnItem item, int field, int index);
typedef int (*ZnItemIndexMethod)(ZnItem item, int field, Tcl_Obj *index_spec,
				 int *index);
typedef int (*ZnItemPartMethod)(ZnItem item, Tcl_Obj **part_spec, int *part);
typedef int (*ZnItemSelectionMethod)(ZnItem item, int field, int offset,
				     char *chars, int max_chars);
typedef void (*ZnItemPostScriptMethod)(ZnItem item, ZnPostScriptInfo ps_info);


typedef void	*ZnItemClassId;

typedef struct _ZnItemClassStruct {
  unsigned int			size;
  unsigned int			num_parts;	/* 0 if no special parts, else
						 * gives how many parts exist. */
  ZnBool			has_anchors;	/* 1 if anchors are supported */
  char				*name;
  ZnAttrConfig			*attr_desc;
  ZnItemInitMethod		Init;
  ZnItemCloneMethod		Clone;
  ZnItemDestroyMethod		Destroy;
  ZnItemConfigureMethod		Configure;
  ZnItemQueryMethod		Query;
  ZnItemGetFieldSetMethod	GetFieldSet;
  ZnItemGetAnchorMethod		GetAnchor;
  ZnItemGetClipVerticesMethod	GetClipVertices;
  ZnItemGetContoursMethod	GetContours;
  ZnItemCoordsMethod		Coords;
  ZnItemInsertCharsMethod	InsertChars;
  ZnItemDeleteCharsMethod	DeleteChars;
  ZnItemCursorMethod		Cursor;
  ZnItemIndexMethod		Index;
  ZnItemPartMethod		Part;
  ZnItemSelectionMethod		Selection;
  ZnItemContourMethod		Contour;
  ZnItemComputeCoordinatesMethod ComputeCoordinates;
  ZnItemToAreaMethod		ToArea;
  ZnItemDrawMethod		Draw;
  ZnItemRenderMethod		Render;
  ZnItemIsSensitiveMethod	IsSensitive;
  ZnItemPickMethod		Pick;
  ZnItemPickVertexMethod	PickVertex;
  ZnItemPostScriptMethod	PostScript;
} ZnItemClassStruct, *ZnItemClass;


/*
 **********************************************************************************
 *
 * Generic methods for all items.
 *
 **********************************************************************************
 */
extern struct _ZnITEM {
  ZnItem (*CloneItem)(ZnItem model);
  void (*DestroyItem)(ZnItem item);
  int (*ConfigureItem)(ZnItem item, int field, int argc, Tcl_Obj *CONST args[],
		       ZnBool init);
  int (*QueryItem)(ZnItem item, int field, int argc, Tcl_Obj *CONST args[]);
  void (*InsertItem)(ZnItem item, ZnItem group, ZnItem mark_item, ZnBool before);
  void (*UpdateItemPriority)(ZnItem item, ZnItem mark_item, ZnBool before);
  void (*UpdateItemDependency)(ZnItem item, ZnItem old_connection);
  void (*ExtractItem)(ZnItem item);
  void (*SetId)(ZnItem item);
  void (*FreeId)(ZnItem item);
  void (*AddTag)(ZnItem item, Tk_Uid tag);
  void (*RemoveTag)(ZnItem item, Tk_Uid tag);
  void (*FreeTags)(ZnItem item);
  ZnBool (*HasTag)(ZnItem item, Tk_Uid tag);
  void (*ResetTransfo)(ZnItem item);
  void (*SetTransfo)(ZnItem item, struct _ZnTransfo *t);
  void (*TranslateItem)(ZnItem item, ZnReal tx, ZnReal ty);
  void (*ScaleItem)(ZnItem item, ZnReal sx, ZnReal sy);
  void (*SkewItem)(ZnItem item, ZnReal x_skew, ZnReal y_skew);
  void (*RotateItem)(ZnItem item, ZnReal angle, ZnPoint *p);
  void (*Invalidate)(ZnItem item, int reason);
  void (*InvalidateItems)(ZnItem group, ZnItemClass item_class);
  void (*GetItemTransform)(ZnItem item, struct _ZnTransfo *t);
} ZnITEM;


/*
 **********************************************************************************
 *
 * Methods defined in Item.c useful for writing items.
 *
 **********************************************************************************
 */
void ZnItemInit();
ZnItem ZnCreateItem(struct _ZnWInfo *wi, ZnItemClass item_class,
		  int *argc, Tcl_Obj *CONST *args[]);
void ZnAddItemClass(ZnItemClass class);
ZnItemClass ZnLookupItemClass(char *class_name);
ZnList ZnItemClassList();
int ZnConfigureAttributes(struct _ZnWInfo *wi, ZnItem item, void *record,
			  ZnAttrConfig *attr_desc, int argc, Tcl_Obj *CONST args[],
			  int *flags);
int ZnAttributesInfo(struct _ZnWInfo *wi, void *record,
		     ZnAttrConfig *attr_desc, int argc, Tcl_Obj *CONST args[]);
int ZnQueryAttribute(struct _ZnWInfo *wi, void *record, ZnAttrConfig *attr_desc,
		     Tcl_Obj *attr_name);
void ZnInitTransformStack(struct _ZnWInfo *wi);
void ZnFreeTransformStack(struct _ZnWInfo *wi);
void ZnResetTransformStack(struct _ZnWInfo *wi);
void ZnPushTransform(struct _ZnWInfo *wi, struct _ZnTransfo *transfo,
		     ZnBool compose_scale, ZnBool compose_rot);
void ZnPopTransform(struct _ZnWInfo *wi);
void ZnInitClipStack(struct _ZnWInfo *wi);
void ZnFreeClipStack(struct _ZnWInfo *wi);
void ZnResetClipStack(struct _ZnWInfo *wi);
void ZnPushClip(struct _ZnWInfo *wi, ZnTriStrip *tristrip, ZnBool simple,
		ZnBool set_gc);
void ZnPopClip(struct _ZnWInfo *wi, ZnBool set_gc);
ZnBool ZnCurrentClip(struct _ZnWInfo *wi, TkRegion *reg, ZnBBox **clip_box,
		     ZnBool *simple);
void ZnUpdateItemImage(void *client_data);


extern ZnItemClassId	ZnArc;
extern ZnItemClassId	ZnMap;
extern ZnItemClassId	ZnTabular;
extern ZnItemClassId	ZnCurve;
extern ZnItemClassId	ZnBezier;
extern ZnItemClassId	ZnTriangles;
extern ZnItemClassId	ZnRectangle;
extern ZnItemClassId	ZnReticle;
extern ZnItemClassId	ZnTrack;
extern ZnItemClassId	ZnWayPoint;
extern ZnItemClassId	ZnGroup;
extern ZnItemClassId	ZnIcon;
extern ZnItemClassId	ZnText;
extern ZnItemClassId	ZnWindow;


#endif	/* _Item_h */