aboutsummaryrefslogtreecommitdiff
path: root/generic/Item.h
blob: f30e1a326633d26283cfcfc1a03297af3b4472e6 (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
/*
 * 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>


#define	DEFAULT_TRACK_PRIORITY		5
#define	DEFAULT_WAY_POINT_PRIORITY	4
#define	DEFAULT_TABULAR_PRIORITY	3
#define DEFAULT_RECTANGLE_PRIORITY	2
#define DEFAULT_CURVE_PRIORITY		2
#define DEFAULT_BEZIER_PRIORITY		2
#define DEFAULT_TRIANGLES_PRIORITY	2
#define DEFAULT_ARC_PRIORITY		2
#define	DEFAULT_RETICLE_PRIORITY	2
#define	DEFAULT_MAP_PRIORITY		1
#define DEFAULT_GROUP_PRIORITY		6
#define DEFAULT_ICON_PRIORITY		2
#define DEFAULT_TEXT_PRIORITY		2
#define DEFAULT_WINDOW_PRIORITY		0	/* N/A */
#define DEFAULT_MOSAIC_PRIORITY		0

#define DEFAULT_MARKER_SIZE		0
#define DEFAULT_VISIBLE_HISTORY_SIZE	6
#define DEFAULT_MANAGED_HISTORY_SIZE	6
#define DEFAULT_SPEED_VECTOR_LENGTH	3
#define DEFAULT_RETICLE_STEP_SIZE	80
#define DEFAULT_RETICLE_PERIOD		5
#define DEFAULT_LABEL_ANGLE		20
#define DEFAULT_LABEL_DISTANCE		50
#define DEFAULT_LINE_WIDTH		1
#define DEFAULT_TILE_SIZE		1
#define DEFAULT_ROW_COUNT		1
#define DEFAULT_COLUMN_COUNT		1

#define DEFAULT_LABEL_PREFERRED_ANGLE	0
#define DEFAULT_CONVERGENCE_STYLE	0

/*
 * Item flags values.
 */
#define VISIBLE_BIT			1
#define SENSITIVE_BIT			2
#define ATOMIC_BIT			4
#define UPDATE_DEPENDENT_BIT	       16
#define COMPOSE_SCALE_BIT	       32
#define COMPOSE_ROTATION_BIT	       64
#define COMPOSE_ALPHA_BIT	      128


struct _WidgetInfo;
struct _ZnTransfo;

/*
 * Item record header --
 */
typedef struct _ItemStruct {
  /* Private data */
  int			id;
  ZnList		tags;
  struct _WidgetInfo	*wi;			/* The widget this item is on	*/
  struct _ItemClassStruct *class;		/* item class			*/
  struct _ItemStruct	*previous;		/* previous item in group list	*/
  struct _ItemStruct	*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 _ItemStruct	*parent;
  int			priority;
  struct _ZnTransfo	*transfo;
  struct _ItemStruct	*connected_item;	/* Item this item is connected to 	*/
} ItemStruct, *Item;

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

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


/*
 * Item class record --
 */
typedef int (*ItemInitMethod)(Item item, int *argc, Tcl_Obj *CONST *args[]);
typedef int (*ItemConfigureMethod)(Item item, int argc, Tcl_Obj *CONST args[],
				   int *flags);
typedef int (*ItemQueryMethod)(Item item, int argc, Tcl_Obj *CONST args[]);
typedef void (*ItemCloneMethod)(Item item);
typedef void (*ItemDestroyMethod)(Item item);
typedef void (*ItemDrawMethod)(Item item);
typedef void (*ItemRenderMethod)(Item item);
typedef void (*ItemComputeCoordinatesMethod)(Item item, ZnBool force);
typedef int (*ItemToAreaMethod)(Item item, ZnToArea ta);
typedef double (*ItemPickMethod)(Item item, ZnPick ps);
typedef ZnBool (*ItemIsSensitiveMethod)(Item item, int part);
typedef struct _FieldSetStruct* (*ItemGetFieldSetMethod)(Item item);
typedef int (*ItemContourMethod)(Item item, int cmd, ZnPoly *poly);
typedef void (*ItemPickVertexMethod)(Item item, ZnPoint *p, int *contour,
				     int *vertex, int *o_vertex);
typedef void (*ItemGetAnchorMethod)(Item item, ZnAnchor anchor, ZnPoint *p);
typedef ZnBool (*ItemGetClipVerticesMethod)(Item item, ZnTriStrip *tristrip);
typedef ZnBool (*ItemGetContoursMethod)(Item item, ZnPoly *poly);
typedef int (*ItemCoordsMethod)(Item item, int contour, int index, int cmd,
				ZnPoint **points, int *num_points);
typedef void (*ItemInsertCharsMethod)(Item item, int field, int *index,
				      char *chars);
typedef void (*ItemDeleteCharsMethod)(Item item, int field, int *first,
				      int *last);
typedef void (*ItemCursorMethod)(Item item, int field, int index);
typedef int (*ItemIndexMethod)(Item item, int field, Tcl_Obj *index_spec,
			       int *index);
typedef int (*ItemPartMethod)(Item item, Tcl_Obj **part_spec, int *part);
typedef int (*ItemSelectionMethod)(Item item, int field, int offset,
				   char *chars, int max_chars);
typedef void (*ItemPostScriptMethod)(Item item, PostScriptInfo ps_info);

typedef struct _ItemClassStruct {
  int				size;
  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;
  ItemInitMethod		Init;
  ItemCloneMethod		Clone;
  ItemDestroyMethod		Destroy;
  ItemConfigureMethod		Configure;
  ItemQueryMethod		Query;
  ItemGetFieldSetMethod		GetFieldSet;
  ItemGetAnchorMethod		GetAnchor;
  ItemGetClipVerticesMethod	GetClipVertices;
  ItemGetContoursMethod		GetContours;
  ItemCoordsMethod		Coords;
  ItemInsertCharsMethod		InsertChars;
  ItemDeleteCharsMethod		DeleteChars;
  ItemCursorMethod		Cursor;
  ItemIndexMethod		Index;
  ItemPartMethod		Part;
  ItemSelectionMethod		Selection;
  ItemContourMethod		Contour;
  ItemComputeCoordinatesMethod	ComputeCoordinates;
  ItemToAreaMethod		ToArea;
  ItemDrawMethod		Draw;
  ItemRenderMethod		Render;
  ItemIsSensitiveMethod		IsSensitive;
  ItemPickMethod		Pick;
  ItemPickVertexMethod		PickVertex;
  ItemPostScriptMethod		PostScript;
} ItemClassStruct, *ItemClass;


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


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


extern ZnItemClassId	ZnArc;
extern ZnItemClassId	ZnMap;
extern ZnItemClassId	ZnTabular;
extern ZnItemClassId	ZnMosaic;
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	ZnWind;


#endif	/* _Item_h */