aboutsummaryrefslogtreecommitdiff
path: root/generic/Item.h
blob: c4b04642c97ce99cda3275f77c86f5c1555bb97a (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
/*
 * 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 "List.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_MULTI_POINT_PRIORITY	2
#define DEFAULT_ARC_PRIORITY		2
#define	DEFAULT_RETICLE_PRIORITY	2
#define	DEFAULT_MAP_PRIORITY		1
#define DEFAULT_GROUP_PRIORITY		0
#define DEFAULT_ICON_PRIORITY		2
#define DEFAULT_TEXT_PRIORITY		2
#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

/*
 * 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


/*
 * 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 char			flags;			
  unsigned char			part_sensitive;		/* Currently limited to 8 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;


/*
 * Group item special record.
 */
typedef struct _GroupItemStruct {
  ItemStruct		header;

  /* Public data */
  Item			clip;
  
  /* Private data */
  Item			head;		/* Doubly linked list of all items.	*/
  Item			tail;
  ZnList		dependents;	/* List of dependent items.		*/
#ifdef OM
  /* Overlap manager variables.
   * These variables are valid *only* if the overlap
   * manager is active. */
  ZnBool		call_om;	/* Tell if there is a need to call the	*/
					/* overlap manager.			*/
#endif
} GroupItemStruct, *GroupItem;


/*
 * Field array management record.
 */
typedef struct _FieldSetStruct {
  struct _WidgetInfo	*wi;
  LabelFormat		label_format;
  unsigned int		num_fields;
  struct _FieldStruct	*fields;
  ZnDim			label_width;	/* Describe the label size. Access these */
  ZnDim			label_height;	/* 2 only with GetLabelBBox. -1 means
					 * not up to date. */
  ZnPoint		label_pos;	/* Describe the label origin. */
} FieldSetStruct, *FieldSet;


/*
 * Item class record --
 */
typedef int (*ItemInitMethod)(Item item, int *argc, Arg **args);
typedef int (*ItemConfigureMethod)(Item item, int argc, ZnAttrList args,
				   int *flags);
typedef int (*ItemQueryMethod)(Item item, int argc, ZnAttrList args);
typedef void (*ItemCloneMethod)(Item item);
typedef void (*ItemDestroyMethod)(Item item);
typedef void (*ItemDrawMethod)(Item item);
typedef void (*ItemComputeCoordinatesMethod)(Item item, ZnBool force);
typedef int (*ItemToAreaMethod)(Item item, ZnBBox *area,
				Tk_Uid tag_uid, int enclosed, ZnBool report);
typedef ZnBool (*ItemIsSensitiveMethod)(Item item, int part);
typedef double (*ItemPickMethod)(Item item, ZnPoint *point,
				 Item start_item, int aperture,
				 Item *a_item, int *a_part);
typedef FieldSet (*ItemGetFieldSetMethod)(Item item);
typedef void (*ItemGetAnchorMethod)(Item item, ZnAnchor anchor, ZnPoint *p);
typedef ZnBool (*ItemGetClipVerticesMethod)(Item item, ZnPoint **points,
					    int *num_points);
typedef int (*ItemCoordsMethod)(Item item, int index, int cmd,
				ZnPoint **points, int *num_points);
typedef void (*ItemPostScriptMethod)(Item item, PostScriptInfo ps_info);

typedef struct _ItemClassStruct {
  int				item_size;
  ZnBool			has_fields;
  ZnBool			has_parts;	/* True for items with parts
						 * other than fields. */
  ZnBool			has_anchors;
  char				*name;
  ZnAttrConfig			*attr_desc;
  ItemInitMethod		Init;
  ItemCloneMethod		Clone;
  ItemDestroyMethod		Destroy;
  ItemConfigureMethod		Configure;
  ItemQueryMethod		Query;
  ItemGetFieldSetMethod		GetFieldSet;
  ItemGetAnchorMethod		GetAnchor;
  ItemGetClipVerticesMethod	GetClipVertices;
  ItemCoordsMethod		Coords;
  ItemComputeCoordinatesMethod	ComputeCoordinates;
  ItemToAreaMethod		ToArea;
  ItemDrawMethod		Draw;
  ItemIsSensitiveMethod		IsSensitive;
  ItemPickMethod		Pick;
  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, ZnAttrList args, ZnBool init);
  int (*QueryItem)(Item item, int field, int argc, ZnAttrList args);
  int (*AttributesInfo)(Item item, int field, int argc, Arg *args);
  void (*SetFieldsAutoAlign)(Item item, int alignment);
  void (*InsertItem)(Item item, Item group, Item mark_item, ZnBool before);
  void (*UpdateItemPriority)(Item item, Item mark_item, ZnBool before);
  void (*InsertDependentItem)(Item item);
  void (*UpdateItemDependency)(Item item, Item old_connection);
  void (*RemoveItem)(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);
  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 (*ComposeItemTransform)(Item item, struct _ZnTransfo *current_t,
			       struct _ZnTransfo *new_t);
  void (*GetTransform)(Item item, struct _ZnTransfo *t);
} ITEM;


/*
 **********************************************************************************
 *
 * Methods defined in item.c useful for writing items.
 *
 **********************************************************************************
 */
extern struct _ITEM_P {
  void (*GlobalModuleInit)();
  Item (*CreateItem)(struct _WidgetInfo *wi, ItemClass item_class,
		     int *argc, Arg **args);
  void (*AddItemClass)(ItemClass class);
  ItemClass (*LookupItemClass)(char *class_name);
  ZnList (*ItemClassList)();
  void (*Damage)(struct _WidgetInfo *wi, ZnBBox *damage);
  void (*Repair)(struct _WidgetInfo *wi);
  void (*Update)(struct _WidgetInfo *wi);
  int (*ConfigureAttributes)(char *record, int field, int argc, Arg *args, int *flags);
  int (*QueryAttribute)(char *record, int field, Arg attr_name);
  void (*InitFields)(FieldSet field_set);
  void (*CloneFields)(FieldSet field_set);
  void (*FreeFields)(FieldSet field_set);
  void (*DrawFields)(FieldSet field_set);
  int (*FieldsToArea)(FieldSet field_set, ZnBBox *area);
  ZnBool (*IsFieldSensitive)(FieldSet field_set, int part);
  double (*FieldsPick)(FieldSet field_set, ZnPoint *p, int *part);
  void (*LeaderToLabel)(FieldSet field_set, ZnPoint *start, ZnPoint *end);
  void (*GetLabelBBox)(FieldSet field_set, ZnDim *w, ZnDim *h);
  void (*GetFieldBBox)(FieldSet field_set, unsigned int index, ZnBBox *field_bbox);
  void (*ResetTransformStack)(struct _WidgetInfo *wi);
  void (*ResetClipStack)(struct _WidgetInfo *wi);
} ITEM_P;


extern ZnItemClassId	ZnArc;
extern ZnItemClassId	ZnMap;
extern ZnItemClassId	ZnTabular;
extern ZnItemClassId	ZnMosaic;
extern ZnItemClassId	ZnCurve;
extern ZnItemClassId	ZnRectangle;
extern ZnItemClassId	ZnReticle;
extern ZnItemClassId	ZnTrack;
extern ZnItemClassId	ZnWayPoint;
extern ZnItemClassId	ZnGroup;
extern ZnItemClassId	ZnIcon;
extern ZnItemClassId	ZnText;


#endif	/* _Item_h */