1 #ifndef _FIGURINE_DEFINE_H
2 #define _FIGURINE_DEFINE_H
3 
4 /* COPYRIGHT (C) 2000 THE VICTORIA UNIVERSITY OF MANCHESTER and John Levon
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the Free
7  * Software Foundation; either version 2 of the License, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17  * Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19 /*
20  * $Log: define.h,v $
21  * Revision 1.4  2001/01/31 15:38:06  movement
22  * pre11 - fix netscape, add metapost support, credit foggy
23  *
24  * Revision 1.4  2001/01/29 20:57:31  moz
25  * Make netscape work again, metapost support.
26  *
27  * Revision 1.3  2000/12/17 00:57:44  moz
28  * examples, filled open splines, highlight_objects
29  *
30  * Revision 1.2  2000/12/06 20:56:08  moz
31  * GPL stuff.
32  *
33  * Revision 1.1.1.1  2000/08/21 01:05:32  moz
34  *
35  *
36  * Revision 1.1.1.1  2000/07/19 22:45:32  moz
37  * CVS Import
38  *
39  * Revision 1.32  2000/03/09 01:06:03  moz
40  * Compile fixes.
41  *
42  * Revision 1.31  2000/03/06 02:21:06  moz
43  * is_in_bbox() all signed.
44  *
45  * Revision 1.30  2000/02/18 21:19:15  moz
46  * Compile fix.
47  *
48  * Revision 1.29  2000/02/18 04:08:02  moz
49  * Compile fixes.
50  *
51  * Revision 1.28  2000/02/17 22:25:18  moz
52  * Compiler fixes.
53  *
54  * Revision 1.27  2000/01/29 21:27:07  moz
55  * Fixed comment.
56  *
57  * Revision 1.26  2000/01/29 20:59:33  moz
58  * Reduce maxpoints.
59  *
60  * Revision 1.25  2000/01/28 17:36:59  moz
61  * "###FIGURINE" is 11 characters long !
62  *
63  * Revision 1.24  2000/01/26 18:25:17  moz
64  * Add FIG_DEBUG_LIST_ALLOC.
65  *
66  * Revision 1.23  1999/11/29 20:35:06  moz
67  * BBSIZE() renamed to avoid IRIX param.h namespace clash.
68  *
69  * Revision 1.22  1999/11/15 02:12:16  moz
70  * Use enums where possible.
71  * Name change.
72  *
73  * Revision 1.21  1999/08/17 00:38:10  moz
74  * Sign P_IN_DOC.
75  *
76  * Revision 1.20  1999/08/09 00:17:02  moz
77  * New selob() macros added.
78  * IS_TEXT_FUNC() added.
79  * NVIW() added.
80  *
81  * Revision 1.19  1999/06/30 17:42:50  moz
82  * Change of view icon size.
83  * Define caddr_t and S_IFDIR if not present (unlikely).
84  *
85  * Revision 1.18  1999/06/17 19:09:45  moz
86  * PDERRY(), numstreq(), and is_vcomment() added.
87  *
88  * Revision 1.17  1999/06/16 00:57:52  moz
89  * More fluid ROTATE_PIXEL_SIZE.
90  *
91  * Revision 1.16  1999/05/31 23:05:53  moz
92  * SHAPE_ATTACH_THRESHOLD added.
93  *
94  * Revision 1.15  1999/05/22 23:39:47  moz
95  *  Pedantic ANSI.
96  *
97  * Revision 1.14  1999/05/19 17:11:43  moz
98  * 1.0 Checkin.
99  *
100  * Revision 1.13  1999/05/02 22:49:27  moz
101  * UNDO_UNCOMPOUND added.
102  *
103  * Revision 1.12  1999/04/29 22:57:27  moz
104  * VIEW_REDO added.
105  *
106  * Revision 1.11  1999/04/29 00:26:26  moz
107  * Removed nodebox icon.
108  *
109  * Revision 1.10  1999/04/27 21:15:20  moz
110  * HELP_TOOLTIPS added.
111  *
112  * Revision 1.9  1999/04/27 16:58:42  moz
113  * FLIP_X and FLIP_Y defined.
114  *
115  * Revision 1.8  1999/04/27 07:40:59  moz
116  * Defined UNDO_IGNOREME
117  *
118  * Revision 1.7  1999/04/26 20:00:22  moz
119  * min3,max3 convenience macros.
120  *
121  * Revision 1.6  1999/04/25 00:21:56  moz
122  * Added ROTATE_PIXEL_SIZE
123  *
124  * Revision 1.5  1999/04/24 22:24:34  moz
125  * Removed macro cruft.
126  * Added UCOLOUR deref macro.
127  *
128  * Revision 1.4  1999/04/23 00:40:32  moz
129  * Start to move out old macros from code.
130  *
131  * Revision 1.3  1999/04/22 22:18:00  moz
132  * Define ulong.
133  * UNDO_COMPOUND added.
134  *
135  * Revision 1.2  1999/04/04 01:50:23  moz
136  * Defines for exporting.
137  *
138  * Revision 1.1  1999/03/30 00:09:58  moz
139  * Initial revision
140  *
141  */
142 
143 #include <X11/Xlib.h>
144 #include <X11/Xresource.h>
145 #include <X11/Xutil.h>
146 #include <limits.h>
147 #include <sys/param.h>
148 #include <stdio.h>
149 #include <X11/cursorfont.h>
150 
151 /* define ulong and uint */
152 #undef ulong
153 #define ulong unsigned long
154 #undef uint
155 #define uint unsigned int
156 
157 #ifndef caddr_t
158 #define caddr_t char *
159 #endif
160 
161 #ifndef __LINE__
162 #define __LINE__ 0
163 #endif
164 
165 #ifndef S_IFDIR
166 #define S_IFDIR 0040000
167 #endif
168 
169 #define FAIL -1
170 /* used in icon_chosen()  */
171 #define MATCHED -1
172 
173 #define LETTER_INCH_WIDTH  8.5
174 #define LETTER_INCH_HEIGHT 11
175 
176 /* proves quite useful  */
177 #undef PI
178 #define PI   3.14159265358979323846
179 
180 #ifndef BLACK
181 #	define BLACK 0
182 #endif
183 
184 #ifndef WHITE
185 #	define WHITE 1
186 #endif
187 
188 /* used by ellipse_box  */
189 #define NO_INTERSECT 0
190 #define CONTAINS 1
191 #define CONTAINED 2
192 
193 /* button stuff  */
194 #define BUTTON_HELD 1
195 #define BUTTON_CLICKED 2
196 #define BUTTON_RELEASED 3
197 
198 /* these are defined for the ruler movement functions  */
199 #define LEFT -1
200 #define CENTRE 0
201 #define RIGHT 1
202 #define UP -1
203 #define DOWN 1
204 
205 /* line styles  */
206 typedef enum { SOLID, DASHED, DOTTED, DASH_DOTTED, DASH_DOUBLE_DOTTED, DASH_TRIPLE_DOTTED } LineStyle;
207 
208 /* arrow styles  */
209 typedef enum { ARROWSTICK, ARROWFLAT, ARROWINDENTED, ARROWPOINTED } ArrowStyle;
210 
211 /* undo types  */
212 typedef enum { UNDO_VOID, UNDO_OB_PROP, UNDO_CUT, UNDO_PASTE, UNDO_COMPOUND, UNDO_UNCOMPOUND } UndoType;
213 
214 /* for scaling, which corner stays tied  */
215 typedef enum { NOTSCALING, TOPLEFT, TOPRIGHT, BOTTOMLEFT, BOTTOMRIGHT } ScalingCorner;
216 
217 /* object types  */
218 typedef enum { POLYLINE=1, ELLIPSE, TEXT, RECTANGLE, POLYGON,
219                SPLINE, ROUNDBOX, ARCELLIPSE, COMPOUND, NODE, ARC } ObjectType;
220 
221 /* export file types  */
222 /* these are *dependent* on ordering of textlist creation in init.c  */
223 typedef enum {  EXPORT_LATEX_BOX, EXPORT_EEPIC, EXPORT_EEPICEMU, EXPORT_EPIC,
224 		EXPORT_EPS, EXPORT_GIF, EXPORT_IBMGL, EXPORT_JPEG, EXPORT_LATEX_PICTURE,
225 		EXPORT_METAFONT, EXPORT_METAPOST, EXPORT_MULTIMETAPOST, EXPORT_PCX, EXPORT_PIC, EXPORT_PICTEX, EXPORT_PNG,
226 		EXPORT_PPM, EXPORT_PS, EXPORT_PSLATEX, EXPORT_AUTOCAD, EXPORT_TEXTYL,
227 		EXPORT_TIFF, EXPORT_TPIC, EXPORT_XBM, EXPORT_XPM } ExportType;
228 
229 /* defines used for STK communication  */
230 typedef enum { RECTANGLEICON=1, ELLIPSEICON, POLYGONICON, SPLINEICON, NODEICON, POLYLINEICON,
231                TEXTICON, POINTERICON, EYEICON, GRIDICON, LINESTYLEICON, SOLIDICON, DASHEDICON,
232                DOTTEDICON, DASHDOTTEDICON, DASHDOUBLEDOTTEDICON, DASHTRIPLEDOTTEDICON,
233                FILLSTYLEICON, COLOURICON, FILLCOLOURICON, ARCELLIPSEICON, COMPOUNDICON, ARCICON,
234                BOXELLIPSEICON, SHOWGRIDICON, ZOOMINICON, ZOOMOUTICON, ARROWICON, SETPOLYGONICON,
235                ENDSTYLEICON, JOINSTYLEICON, FONTICON, LINEWIDTHICON, SETSPLINEICON, ROUNDBOXICON,
236                JUSTIFICATIONICON, ROUNDENDICON, FLATENDICON, PROJECTINGENDICON, ROUNDJOINICON,
237                SHARPJOINICON, BEVELJOINICON, SETARCELLIPSEICON, CLOSEDARCELLIPSEICON,
238                OPENARCELLIPSEICON, LEFTJUSTICON, CENTREJUSTICON, RIGHTJUSTICON } IconType;
239 
240 /* leave 200-300 for fill styles */
241 #define NONE -1
242 #define STARTOFFILLSTYLES 200
243 #define FILLSTYLENONE 243
244 
245 /* leave 300-400 for colours  */
246 #define STARTOFCOLOURS 300
247 typedef enum { CBLACK=300, CBLUE, CGREEN, CCYAN, CRED, CMAGENTA, CYELLOW, CWHITE, CBLUE4, CBLUE3, CBLUE2,
248                CLIGHTBLUE, CGREEN4, CGREEN3, CGREEN2, CCYAN4, CCYAN3, CCYAN2, CRED4, CRED3, CRED2, CMAGENTA4,
249                CMAGENTA3, CMAGENTA2, CBROWN4, CBROWN3, CBROWN2, CPINK4, CPINK3, CPINK2, CPINK, CGOLD } ColourType;
250 
251 /* leave 400-500 for fillcolours  */
252 #define STARTOFFILLCOLOURS 400
253 typedef enum { FILLCBLACK=400, FILLCBLUE, FILLCGREEN, FILLCCYAN, FILLCRED, FILLCMAGENTA,
254                FILLCYELLOW, FILLCWHITE, FILLCBLUE4, FILLCBLUE3, FILLCBLUE2, FILLCLIGHTBLUE, FILLCGREEN4, FILLCGREEN3,
255                FILLCGREEN2, FILLCCYAN4, FILLCCYAN3, FILLCCYAN2, FILLCRED4, FILLCRED3, FILLCRED2, FILLCMAGENTA4,
256                FILLCMAGENTA3, FILLCMAGENTA2, FILLCBROWN4, FILLCBROWN3, FILLCBROWN2, FILLCPINK4, FILLCPINK3,
257                FILLCPINK2, FILLCPINK, FILLCGOLD } FillColourType;
258 
259 #define FILE_NEW 100
260 #define FILE_OPEN 101
261 #define VIEW_UNDO 102
262 #define FILE_INSERT 103
263 #define FILE_QUIT 110
264 #define HELP_CONTENTS 111
265 #define FILE_SAVE 122
266 #define FILE_SAVE_AS 123
267 #define FILE_CLOSE 124
268 #define FILE_EXPORT 125
269 #define NEW_VIEW 126
270 #define VIEW_SETTINGS 127
271 #define FILE_PRINT 128
272 #define EDIT_CUT 129
273 #define EDIT_COPY 130
274 #define EDIT_PASTE 131
275 #define EDIT_DELETE 132
276 #define EDIT_RAISE 133
277 #define EDIT_LOWER 134
278 #define FLIP_X 135
279 #define FLIP_Y 136
280 #define HELP_TOOLTIPS 137
281 #define VIEW_REDO 138
282 
283 /* justification values  */
284 #define J_FILE_SLIDERS 3
285 #define J_FILE_BUTTONS 4
286 #define J_GRID 5
287 #define J_VIEW_BUTTONS 6
288 #define J_UNITS 7
289 #define J_ARROW1 8
290 #define J_ARROW2 9
291 #define J_ARROW3 10
292 
293 /* constrictions  */
294 
295 #ifdef PATH_MAX
296 #	define FIGURINE_PATH_MAX PATH_MAX
297 #else
298 #	define FIGURINE_PATH_MAX 1024
299 #endif
300 
301 #ifdef MAXHOSTNAMELEN
302 #	define FIGURINE_HOSTNAME_MAX MAXHOSTNAMELEN
303 #else
304 #	define FIGURINE_HOSTNAME_MAX 1024
305 #endif
306 
307 #define POINTS_IN_INCH 72.27
308 /* this affects the ability to render filled splines */
309 /* this is a reasonable value, if you have problems with */
310 /* filling the filled spline : */
311 /* a) wonder what you're doing with such a complex spline */
312 /* b) increase this number and recompile */
313 #define MAXPOINTS 5000
314 #define MIN_ZOOM 0.2
315 #define MAX_ZOOM 20.0
316 #define USER_ZOOM -1
317 #define ZOOM_MULT 1.1
318 #define RULER_PIXEL_SIZE 20
319 #define HANDLE_PIXEL_SIZE 8
320 /* defines the distance needed to move the mouse for rotation
321    smaller amounts rotate more sharply, but less smoothly */
322 #define ROTATE_PIXEL_SIZE 200
323 /* difference at which an angle should mean rectilinear rotation */
324 #define ROTATE_RECTI_THRESHOLD .02
325 #define VIEW_ICON_SIZE 25
326 #define VIEW_ICON_WIDTH 25
327 #define GUIDE_LINE_GAP 30
328 #define NUM_FILLSTYLES 43
329 #define RELEASE_DEFAULTS_LATENCY 300 /* in ms, the time before a held mouse button defaults to drawing starting */
330 #define MOVE_BOUNDARY 20 /* pixel border when drawing to scroll document  */
331 #define MIN_GRID_PIXEL_SEPARATION 10 /* greek out the grid when grid_x or grid_y is very small on screen  */
332 #define POINTER_JUMP_SIZE 20 /* max number of pixels the pointer can jump when editing points  */
333 #define SELECT_PIXEL_LOOSENESS 3 /* pixels around object that select it (for 1-pixel wide lines)  */
334 #define SHAPE_ATTACH_THRESHOLD 0.1 /* shape factors below this are considered to be co-incident with point */
335 
336 /* window types  */
337 #define MAIN_VIEW_WIN 1
338 #define RULER_X_WIN 2
339 #define RULER_Y_WIN 3
340 #define DRAW_WIN 4
341 #define VIEW_ICON_WIN 5
342 
343 /* MACROS  */
344 
345 /* these are used for values stored in list,
346 	casting the ->data to the correct type */
347 #define DOC(a) ((Document *)((a)->data))
348 #define WS(a) ((WindowStruct *)((a)->data))
349 #define VIEW(a) ((View *)((a)->data))
350 #define OB(a) ((Object *)(a)->data)
351 #define POINT(a) ((VPoint *)(a)->data)
352 #define SPOINT(a) ((SPoint *)(a)->data)
353 #define FONT(a) ((VFont *)(a)->data)
354 #define TEXTSEC(a) ((TextSection *)(a)->data)
355 #define TEXTLINE(a) ((TextLine *)(a)->data)
356 #define DERRY(a) ((Derry *)(a)->data)
357 #define PDERRY(a) ((PDerry *)(a)->data)
358 #define UCOLOUR(a) ((UColour *)(a)->data)
359 #define UNDO(a) ((Undo *)(a)->data)
360 
361 /* obvious utility macros  */
362 #define max(a,b) (((a)>(b)) ? (a) : (b))
363 #define min(a,b) (((a)<(b)) ? (a) : (b))
364 #define min3(a,b,c) min((a),min((b),(c)))
365 #define max3(a,b,c) max((a),max((b),(c)))
366 #define abs(a)  ((a)<0 ? -(a) : (a))
367 #define sqr(a)  ((a)*(a))
368 #define streq(a,b) (!strcmp((a),(b)))
369 #define numstreq(a,b,c) (!strncmp((a),(b),(c)))
370 #define between(t,a,b) ((t)>(a) && (t)<(b))
371 #define is_vcomment(a) (numstreq((a),"###FIGURINE",11))
372 #define selobtype(v,t) ((v)->selected_object!=NULL && (v)->selected_object->ob->type==(t))
373 #define isselob(v) ((v)->selected_object!=NULL)
374 #define selob(v) ((v)->selected_object->ob)
375 #define NVIW(v) ((v) ? (v->view_icon_window->win) : (Window)-1)
376 
377 
378 #define R(a,b) ((long)(((double)(a))*(b)))
379 
380 /* gnarly scaling stuff with view  */
381 /* usage FUNC(double value, View *view) or similar */
382 #define ZPO(a,v) (int)(((double)((a)*10))*(v)->zoom_factor) /* zoomed screen point size from nominal */
383 #define P2I(a,v) ((double)(a))/(screen_ppi*(v)->zoom_factor)  /* pixels to inches at current zoom  */
384 #define I2P(a,v) ((long)((a)*screen_ppi*(v)->zoom_factor)) /* inches to pixels at current zoom  */
385 #define I2D(a,v) ((long)((a)*(v)->doc->ppi)) /* inches to document pixels */
386 #define D2I(a,v) (((double)(a)/(v)->doc->ppi)) /* doc pixels to inches  */
387 #define M2I(a)   ((a)/25.4) /* mm to inches conversion  */
388 #define I2M(a)   ((a)*25.4) /* inches to mm conversion  */
389 #define D2P(a,v) ((long)((((a))*(screen_ppi*(v)->zoom_factor))/(v)->doc->ppi))
390 #define P2D(a,v) ((long)(((a)*(v)->doc->ppi)/(screen_ppi*(v)->zoom_factor)))
391 
392 /* pixels to document, with offset  */
393 #define XP2D(a,v) ((long)((((a)*(v)->doc->ppi)/((v)->zoom_factor*screen_ppi))) + I2D((v)->x_inches_offset,v)+1)
394 #define YP2D(a,v) ((long)((((a)*(v)->doc->ppi)/((v)->zoom_factor*screen_ppi))) + I2D((v)->y_inches_offset,v)+1)
395 
396 /* pixels to document, snapped to grid  */
397 #define GXP2D(a,v) snap((v)->grid_x,((long)((((a)*(v)->doc->ppi)/((v)->zoom_factor*screen_ppi))) + I2D((v)->x_inches_offset,v)+1))
398 #define GYP2D(a,v) snap((v)->grid_y,((long)((((a)*(v)->doc->ppi)/((v)->zoom_factor*screen_ppi))) + I2D((v)->y_inches_offset,v)+1))
399 
400 #define XD2P(a,v) ((long)((((a)-I2D((v)->x_inches_offset,v))*(screen_ppi*(v)->zoom_factor))/(v)->doc->ppi))
401 #define YD2P(a,v) ((long)((((a)-I2D((v)->y_inches_offset,v))*(screen_ppi*(v)->zoom_factor))/(v)->doc->ppi))
402 
403 /* useful measure of bbox size  */
404 #define FIG_BBSIZE(b) ((ulong)(((b).x2-(b).x1)*((b).y2-(b).y1)))
405 
406 /* pixel bounds of doc  */
407 #define DOCPBOUNDS(v) XD2P(0,(v)), YD2P(0,(v)), XD2P(0,(v))+XD2P(I2D((v)->doc->width_in_inches,(v)),(v)), XD2P(0,(v))+YD2P(I2D((v)->doc->height_in_inches,(v)),(v))
408 /* document bounds of doc  */
409 #define DOCDBOUNDS(v) 0, 0, I2D((v)->doc->width_in_inches,(v)), I2D((v)->doc->height_in_inches,(v))
410 
411 /* is a pixel in the document window ?  */
412 #define P_IN_DOC(x,y,v)  is_in_bbox(((int)x),((int)y), 0, 0, (int)(v)->draw_window->w, (int)(v)->draw_window->h)
413 
414 #define INCHES_TO_PIXELS(a) ((int)((a)*screen_ppi))
415 #define MM_TO_INCHES(a) ((a)/25.4)
416 #define INCHES_TO_MM(a) ((a)*25.4)
417 
418 #define REDRAW_ALL_WINDOW(a) (send_redraw((a),0,0,(int)(a)->w,(int)(a)->h))
419 #define SET_CLIP_WINDOW(g,l) (set_clip((g),0,0, (int)((l)->w), (int)((l)->h)))
420 
421 /* is a text cursor wanted ?  */
422 
423 #define IS_TEXT_FUNC(a) ((a)==NODEICON || (a)==TEXTICON)
424 
425 /* provides pixel co-ords for edges of doc  */
426 /* returns 4 ,-separated values x1,y1,x2,y2  */
427 
428 #define DOC_PIXEL_BOUNDS(l) 		DOC_PIXEL_BOUNDS_V(VIEW(l))
429 
430 #define DOC_PIXEL_BOUNDS_V(v) 	I2P(0-v->x_inches_offset,(v)), \
431 											I2P(0-v->y_inches_offset,(v)), \
432 									 		I2P(v->doc->width_in_inches-v->x_inches_offset,(v)), \
433 									 		I2P(v->doc->height_in_inches-v->y_inches_offset,(v))
434 
435 /* test for inside document borders  */
436 /* use DRAW_WIN relative pixels co-ords  */
437 #define IS_IN_DOC(x,y,l) is_in_bbox((x),(y),DOC_PIXEL_BOUNDS((l)))
438 
439 /* constrain between two points  */
440 /* minval is lowest, maxval is highest */
441 #define MINMAX(val,minval,maxval) min(max((val),(minval)),(maxval))
442 
443 /* debuggin output */
444 
445 #ifndef FIG_DEBUG_LIST_ALLOC
446 #define add_to_list(a,b,c,d) add_to_list0((a),(b),(c),(d))
447 #define add_to_list_neq(a,b,c,d) add_to_list_neq0((a),(b),(c),(d))
448 #else
449 #define add_to_list(a,b,c,d) add_to_list0((a),(b),(c),(d)); \
450    fprintf(stderr, "figurine: add_to_list called from " __FILE__ " line %d\n", __LINE__)
451 #define add_to_list_neq(a,b,c,d) add_to_list_neq0((a),(b),(c),(d)); \
452    fprintf(stderr, "figurine: add_to_list_neq called from " __FILE__ " line %d\n", __LINE__)
453 #endif
454 
455 #define E(a) fprintf(stderr,(a))
456 #define v_error(d) fprintf(stderr,"figurine: BUG at "__FILE__ " line %d: %d\n", __LINE__, (d))
457 
458 #endif
459