1 
2 /*
3  * bltInt.h --
4  *
5  * Copyright 1993-1998 Lucent Technologies, Inc.
6  *
7  * Permission to use, copy, modify, and distribute this software and
8  * its documentation for any purpose and without fee is hereby
9  * granted, provided that the above copyright notice appear in all
10  * copies and that both that the copyright notice and warranty
11  * disclaimer appear in supporting documentation, and that the names
12  * of Lucent Technologies any of their entities not be used in
13  * advertising or publicity pertaining to distribution of the software
14  * without specific, written prior permission.
15  *
16  * Lucent Technologies disclaims all warranties with regard to this
17  * software, including all implied warranties of merchantability and
18  * fitness.  In no event shall Lucent Technologies be liable for any
19  * special, indirect or consequential damages or any damages
20  * whatsoever resulting from loss of use, data or profits, whether in
21  * an action of contract, negligence or other tortuous action, arising
22  * out of or in connection with the use or performance of this
23  * software.
24  */
25 
26 #ifndef _BLT_INT_H
27 #define _BLT_INT_H
28 
29 #ifdef WIN32
30 #define STRICT
31 #define WIN32_LEAN_AND_MEAN
32 #include <windows.h>
33 #undef STRICT
34 #undef WIN32_LEAN_AND_MEAN
35 #include <windowsx.h>
36 #endif /* WIN32 */
37 
38 #define USE_NON_CONST
39 #include <tcl.h>
40 #define USE_COMPOSITELESS_PHOTO_PUT_BLOCK
41 #include <tk.h>
42 
43 #define _VERSION(a,b,c)	    (((a) << 16) + ((b) << 8) + (c))
44 #define TCL_VERSION_NUMBER _VERSION(TCL_MAJOR_VERSION, TCL_MINOR_VERSION, TCL_RELEASE_SERIAL)
45 #define TK_VERSION_NUMBER _VERSION(TK_MAJOR_VERSION, TK_MINOR_VERSION, TK_RELEASE_SERIAL)
46 
47 #include "bltTkInt.h"
48 
49 #include <stdio.h>
50 #include <assert.h>
51 
52 #if defined(WIN32) && defined(__MINGW32__)
53 #include "bltWinConfig.h"
54 #elif defined(WIN32) && !defined(__GNUC__)
55 #include "bltWinConfig.h"
56 #else
57 #include "bltConfig.h"
58 #endif
59 
60 #ifdef WIN32
61 #ifndef EXPORT
62 #if defined(_MSC_VER) || defined(__BORLANDC__)
63 #define EXPORT __declspec(dllexport)
64 #else
65 #define EXPORT
66 #endif /* _MSC_VER || __BORLANDC__ */
67 #endif /* EXPORT */
68 
69 /* Misc. definitions */
70 #define	NO_CUTBUFFER	1
71 /* #define NO_TILESCROLLBAR	1 */
72 #define NO_DND		1
73 
74 #ifndef __GNUC__
75 #ifdef O_NONBLOCK
76 #define O_NONBLOCK	1
77 #endif
78 #endif /* __GNUC__ */
79 #endif /* WIN32 */
80 
81 #include "blt.h"
82 #include "bltNsUtil.h"
83 
84 #ifdef HAVE_STDLIB_H
85 #include <stdlib.h>
86 #endif /* HAVE_STDLIB_H */
87 
88 #ifdef HAVE_STRING_H
89 #include <string.h>
90 #endif /* HAVE_STRING_H */
91 
92 #ifdef HAVE_ERRNO_H
93 #include <errno.h>
94 #endif /* HAVE_ERRNO_H */
95 
96 #ifdef HAVE_CTYPE_H
97 #include <ctype.h>
98 #endif /* HAVE_CTYPE_H */
99 
100 #ifdef HAVE_MEMORY_H
101 #include <memory.h>
102 #endif /* HAVE_MEMORY_H */
103 
104 #ifdef HAVE_UNISTD_H
105 #include <unistd.h>
106 #endif /* HAVE_UNISTD_H */
107 
108 #ifdef HAVE_LIMITS_H
109 #include <limits.h>
110 #endif
111 
112 #include "bltMath.h"
113 
114 #undef INLINE
115 #ifdef __GNUC__
116 #define INLINE inline
117 #else
118 #define INLINE
119 #endif
120 #undef EXPORT
121 #define EXPORT
122 
123 #undef VARARGS
124 #ifdef __cplusplus
125 #define ANYARGS (...)
126 #define VARARGS(first)  (first, ...)
127 #define VARARGS2(first, second)  (first, second, ...)
128 #else
129 #define ANYARGS ()
130 #define VARARGS(first) ()
131 #define VARARGS2(first, second) ()
132 #endif /* __cplusplus */
133 
134 #undef MIN
135 #define MIN(a,b)	(((a)<(b))?(a):(b))
136 
137 #undef MAX
138 #define MAX(a,b)	(((a)>(b))?(a):(b))
139 
140 #undef MIN3
141 #define MIN3(a,b,c)	(((a)<(b))?(((a)<(c))?(a):(c)):(((b)<(c))?(b):(c)))
142 
143 #undef MAX3
144 #define MAX3(a,b,c)	(((a)>(b))?(((a)>(c))?(a):(c)):(((b)>(c))?(b):(c)))
145 
146 #define TRUE 	1
147 #define FALSE 	0
148 
149 /*
150  * The macro below is used to modify a "char" value (e.g. by casting
151  * it to an unsigned character) so that it can be used safely with
152  * macros such as isspace.
153  */
154 #define UCHAR(c) ((unsigned char) (c))
155 
156 #undef panic
157 #define panic(mesg)	Blt_Panic("%s:%d %s", __FILE__, __LINE__, (mesg))
158 
159 /*
160  * Since the Tcl/Tk distribution doesn't perform any asserts, dynamic
161  * loading can fail to find the __assert function.  As a workaround,
162  * we'll include our own.
163  */
164 #undef	assert
165 #ifdef	NDEBUG
166 #define	assert(EX) ((void)0)
167 #else
168 extern void Blt_Assert _ANSI_ARGS_((char *expr, char *file, int line));
169 #ifdef __STDC__
170 #define	assert(EX) (void)((EX) || (Blt_Assert(#EX, __FILE__, __LINE__), 0))
171 #else
172 #define	assert(EX) (void)((EX) || (Blt_Assert("EX", __FILE__, __LINE__), 0))
173 #endif /* __STDC__ */
174 
175 #endif /* NDEBUG */
176 
177 #if (TCL_MAJOR_VERSION >= 8)
178 extern Tcl_Obj *bltEmptyStringObjPtr;
179 #endif /* TCL_MAJOR_VERSION >= 8 */
180 
181 /*
182  * ----------------------------------------------------------------------
183  *
184  * Blt_CmdSpec --
185  *
186  * ----------------------------------------------------------------------
187  */
188 typedef struct {
189     char *name;			/* Name of command */
190     Tcl_CmdProc *cmdProc;
191     Tcl_CmdDeleteProc *cmdDeleteProc;
192     ClientData clientData;
193 } Blt_CmdSpec;
194 
195 #if (TCL_MAJOR_VERSION >= 8)
196 /*
197  * ----------------------------------------------------------------------
198  *
199  * Blt_CmdSpec --
200  *
201  * ----------------------------------------------------------------------
202  */
203 typedef struct {
204     char *name;			/* Name of command */
205     Tcl_ObjCmdProc *cmdProc;
206     Tcl_CmdDeleteProc *cmdDeleteProc;
207     ClientData clientData;
208 } Blt_ObjCmdSpec;
209 
210 #endif /* TCL_MAJOR_VERSION >= 8 */
211 
212 /*
213  * ----------------------------------------------------------------------
214  *
215  * Blt_Op --
216  *
217  * 	Generic function prototype of CmdOptions.
218  *
219  * ----------------------------------------------------------------------
220  */
221 typedef int (*Blt_Op) _ANSI_ARGS_(ANYARGS);
222 
223 /*
224  * ----------------------------------------------------------------------
225  *
226  * Blt_OpSpec --
227  *
228  * 	Structure to specify a set of operations for a Tcl command.
229  *      This is passed to the Blt_GetOp procedure to look
230  *      for a function pointer associated with the operation name.
231  *
232  * ----------------------------------------------------------------------
233  */
234 typedef struct {
235     char *name;			/* Name of operation */
236     int minChars;		/* Minimum # characters to disambiguate */
237     Blt_Op proc;
238     int minArgs;		/* Minimum # args required */
239     int maxArgs;		/* Maximum # args required */
240     char *usage;		/* Usage message */
241 
242 } Blt_OpSpec;
243 
244 typedef enum {
245     BLT_OP_ARG0,		/* Op is the first argument. */
246     BLT_OP_ARG1,		/* Op is the second argument. */
247     BLT_OP_ARG2,		/* Op is the third argument. */
248     BLT_OP_ARG3,		/* Op is the fourth argument. */
249     BLT_OP_ARG4			/* Op is the fifth argument. */
250 
251 } Blt_OpIndex;
252 
253 #define BLT_OP_LINEAR_SEARCH	1
254 #define BLT_OP_BINARY_SEARCH	0
255 
256 extern Blt_Op Blt_GetOp _ANSI_ARGS_((Tcl_Interp *interp, int nSpecs,
257 	Blt_OpSpec *specArr, int operPos, int argc, char **argv, int flags));
258 
259 #if (TCL_VERSION_NUMBER >= _VERSION(8,0,0))
260 extern Blt_Op Blt_GetOpFromObj _ANSI_ARGS_((Tcl_Interp *interp,
261 	int nSpecs, Blt_OpSpec *specArr, int operPos, int objc,
262 	Tcl_Obj *CONST *objv, int flags));
263 #endif
264 
265 /*
266  * ----------------------------------------------------------------------
267  *
268  *	Assume we need to declare free if there's no stdlib.h or malloc.h
269  *
270  * ----------------------------------------------------------------------
271  */
272 #if !defined(HAVE_STDLIB_H) && !defined(HAVE_MALLOC_H)
273 extern void free _ANSI_ARGS_((void *));
274 #endif
275 
276 #define free(x)		abc123(x)
277 
278 extern int Blt_DictionaryCompare _ANSI_ARGS_((CONST char *s1, CONST char *s2));
279 
280 EXTERN void Blt_Panic _ANSI_ARGS_(TCL_VARARGS(char *, args));
281 
282 
283 extern void Blt_Draw3DRectangle _ANSI_ARGS_((Tk_Window tkwin, Drawable drawable,
284 	Tk_3DBorder border, int x, int y, int width, int height,
285 	int borderWidth, int relief));
286 extern void Blt_Fill3DRectangle _ANSI_ARGS_((Tk_Window tkwin, Drawable drawable,
287 	Tk_3DBorder border, int x, int y, int width, int height,
288 	int borderWidth, int relief));
289 
290 #ifdef notdef
291 #define Blt_Fill3DRectangle	Tk_Fill3DRectangle
292 #define Blt_Draw3DRectangle	Tk_Draw3DRectangle
293 #endif
294 
295 /* ---------------------------------------------------------------- */
296 
297 
298 #define PIXELS_NONNEGATIVE	0
299 #define PIXELS_POSITIVE		1
300 #define PIXELS_ANY		2
301 
302 #define COUNT_NONNEGATIVE	0
303 #define COUNT_POSITIVE		1
304 #define COUNT_ANY		2
305 
306 #define BLT_SCROLL_MODE_CANVAS	(1<<0)
307 #define BLT_SCROLL_MODE_LISTBOX	(1<<1)
308 #define BLT_SCROLL_MODE_HIERBOX	(1<<2)
309 
310 #define RGB_ANTIQUEWHITE1	"#ffefdb"
311 #define RGB_BISQUE1		"#ffe4c4"
312 #define RGB_BISQUE2		"#eed5b7"
313 #define RGB_BISQUE3		"#cdb79e"
314 #define RGB_BLACK		"#000000"
315 #define RGB_BLUE		"#0000ff"
316 #define RGB_GREEN		"#00ff00"
317 #define RGB_GREY		"#b0b0b0"
318 #define RGB_GREY15		"#262626"
319 #define RGB_GREY50		"#7f7f7f"
320 #define RGB_GREY64		"#a3a3a3"
321 #define RGB_GREY70		"#b3b3b3"
322 #define RGB_GREY75		"#bfbfbf"
323 #define RGB_GREY77		"#c3c3c3"
324 #define RGB_GREY82		"#d1d1d1"
325 #define RGB_GREY85		"#d9d9d9"
326 #define RGB_GREY90		"#e5e5e5"
327 #define RGB_GREY95		"#f2f2f2"
328 #define RGB_LIGHTBLUE0		"#e4f7ff"
329 #define RGB_LIGHTBLUE1		"#bfefff"
330 #define RGB_LIGHTBLUE2		"#b2dfee"
331 #define RGB_LIGHTSKYBLUE1	"#b0e2ff"
332 #define RGB_MAROON		"#b03060"
333 #define RGB_NAVYBLUE		"#000080"
334 #define RGB_PINK		"#ffc0cb"
335 #define RGB_BISQUE1		"#ffe4c4"
336 #define RGB_RED			"#ff0000"
337 #define RGB_WHITE		"#ffffff"
338 #define RGB_YELLOW		"#ffff00"
339 
340 #ifdef OLD_TK_COLORS
341 #define STD_NORMAL_BACKGROUND	RGB_BISQUE1
342 #define STD_ACTIVE_BACKGROUND	RGB_BISQUE2
343 #define STD_SELECT_BACKGROUND	RGB_LIGHTBLUE1
344 #define STD_DISABLE_FOREGROUND	RGB_GREY64
345 #else
346 #define STD_NORMAL_BACKGROUND	RGB_GREY85
347 #define STD_ACTIVE_BACKGROUND	RGB_GREY64
348 #define STD_SELECT_BACKGROUND	RGB_LIGHTBLUE1
349 #define STD_DISABLE_FOREGROUND	RGB_GREY64
350 #endif /* OLD_TK_COLORS */
351 
352 #define STD_ACTIVE_BG_MONO	RGB_BLACK
353 #define STD_ACTIVE_FOREGROUND	RGB_BLACK
354 #define STD_ACTIVE_FG_MONO	RGB_WHITE
355 #define STD_BORDERWIDTH 	"2"
356 #ifdef OLD_TK_FONTS
357 #define STD_FONT		"*-Helvetica-Medium-R-Normal-*-12-120-*"
358 #define STD_FONT_HUGE		"*-Helvetica-Medium-R-Normal-*-18-180-*"
359 #define STD_FONT_LARGE		"*-Helvetica-Medium-R-Normal-*-14-140-*"
360 #define STD_FONT_SMALL		"*-Helvetica-Medium-R-Normal-*-10-100-*"
361 #else
362 #define STD_FONT		"Helvetica -12"
363 #define STD_FONT_HUGE		"*Helvetica  -18"
364 #define STD_FONT_LARGE		"Helvetica -14"
365 #define STD_FONT_SMALL		"Helvetica -10"
366 #endif
367 #define STD_INDICATOR_COLOR	RGB_MAROON
368 #define STD_NORMAL_BG_MONO	RGB_WHITE
369 #define STD_NORMAL_FOREGROUND	RGB_BLACK
370 #define STD_NORMAL_FG_MONO	RGB_BLACK
371 #define STD_SELECT_BG_MONO	RGB_BLACK
372 #define STD_SELECT_BORDERWIDTH	"2"
373 #define STD_SELECT_FOREGROUND	RGB_BLACK
374 #define STD_SELECT_FG_MONO	RGB_WHITE
375 #define STD_SHADOW_COLOR	RGB_GREY64
376 #define STD_SHADOW_MONO		RGB_BLACK
377 
378 #define LineWidth(w)	(((w) > 1) ? (w) : 0)
379 
380 #ifdef TCL_UTF_MAX
381 #define HAVE_UTF	1
382 extern FILE *Blt_OpenUtfFile _ANSI_ARGS_((CONST char *fileName, CONST char *mode));
383 #define fopen(f,m)	Blt_OpenUtfFile((f),(m));
384 #else
385 #define HAVE_UTF	0
386 #endif /* TCL_UTF_MAX */
387 
388 typedef char *DestroyData;
389 
390 
391 #ifndef TK_RELIEF_SOLID
392 #define TK_RELIEF_SOLID		TK_RELIEF_FLAT
393 #endif
394 
395 /*
396  * Tcl/Tk Backward compatibility section.
397  */
398 #if (TCL_MAJOR_VERSION > 7)
399 
400 #define NO_FLAGS			0
401 #define Blt_FindPhoto(interp, name)	Tk_FindPhoto(interp, name)
402 
403 #else
404 
405 #define Tcl_GetStringResult(interp)	((interp)->result)
406 #define Blt_FindPhoto(interp, name)	Tk_FindPhoto(name)
407 
408 #define Tcl_DeleteCommandFromToken(interp, token) \
409 	Tcl_DeleteCommand(interp, Tcl_GetCommandName(interp, token))
410 
411 /*
412  *--------------------------------------------------------------
413  *
414  * The definitions below provide foreward compatibility for
415  * functions and types related to event handling that used to
416  * be in Tk but have moved to Tcl.
417  *
418  *--------------------------------------------------------------
419  */
420 
421 #define Tcl_IdleProc		Tk_IdleProc
422 #define Tcl_FileProc		Tk_FileProc
423 #define Tcl_TimerProc		Tk_TimerProc
424 #define Tcl_TimerToken		Tk_TimerToken
425 
426 #define Tcl_BackgroundError	Tk_BackgroundError
427 #define Tcl_CancelIdleCall	Tk_CancelIdleCall
428 
429 #define Tcl_CreateTimerHandler	Tk_CreateTimerHandler
430 #define Tcl_DeleteTimerHandler	Tk_DeleteTimerHandler
431 #define Tcl_DoOneEvent		Tk_DoOneEvent
432 #define Tcl_DoWhenIdle		Tk_DoWhenIdle
433 #define Tcl_Sleep		Tk_Sleep
434 
435 /* Additional stuff that has moved to Tcl: */
436 
437 #define Tcl_AfterCmd		Tk_AfterCmd
438 #define Tcl_EventuallyFree	Tk_EventuallyFree
439 #define Tcl_FreeProc		Tk_FreeProc
440 #define Tcl_Preserve		Tk_Preserve
441 #define Tcl_Release		Tk_Release
442 
443 #endif /* TCL_MAJOR_VERSION > 7 */
444 
445 typedef int (QSortCompareProc) _ANSI_ARGS_((const void *, const void *));
446 
447 
448 /*
449  * ----------------------------------------------------------------------
450  *
451  * Blt_Pad --
452  *
453  * 	Specifies vertical and horizontal padding.
454  *
455  *	Padding can be specified on a per side basis.  The fields
456  *	side1 and side2 refer to the opposite sides, either
457  *	horizontally or vertically.
458  *
459  *		side1	side2
460  *              -----   -----
461  *          x | left    right
462  *	    y | top     bottom
463  *
464  * ----------------------------------------------------------------------
465  */
466 typedef struct {
467     short int side1, side2;
468 } Blt_Pad;
469 
470 #define padLeft  	padX.side1
471 #define padRight  	padX.side2
472 #define padTop		padY.side1
473 #define padBottom	padY.side2
474 #define PADDING(x)	((x).side1 + (x).side2)
475 
476 /*
477  * ----------------------------------------------------------------------
478  *
479  * The following enumerated values are used as bit flags.
480  *	FILL_NONE		Neither coordinate plane is specified
481  *	FILL_X			Horizontal plane.
482  *	FILL_Y			Vertical plane.
483  *	FILL_BOTH		Both vertical and horizontal planes.
484  *
485  * ----------------------------------------------------------------------
486  */
487 #define FILL_NONE	0
488 #define FILL_X		1
489 #define FILL_Y		2
490 #define FILL_BOTH	3
491 
492 #ifndef TK_BGTILE_TOP
493 #define TK_BGTILE_TOP 0x2000000
494 #endif
495 
496 #ifndef Tk_IsBgTileTop
497 #define Tk_IsBgTileTop(tkwin) \
498     (((Tk_FakeWin *) (tkwin))->flags & TK_BGTILE_TOP)
499 #endif
500 
501 
502 /*
503  * ----------------------------------------------------------------------
504  *
505  * Blt_Dashes --
506  *
507  * 	List of dash values (maximum 11 based upon PostScript limit).
508  *
509  * ----------------------------------------------------------------------
510  */
511 typedef struct {
512     unsigned char values[12];
513     int offset;
514 } Blt_Dashes;
515 
516 #define LineIsDashed(d) ((d).values[0] != 0)
517 
518 extern void Blt_SetDashes _ANSI_ARGS_((Display *display, GC gc,
519 	Blt_Dashes *dashesPtr));
520 extern Blt_Dashes *Blt_GetDashes _ANSI_ARGS_((GC gc));
521 
522 /*
523  * -------------------------------------------------------------------
524  *
525  * Point2D --
526  *
527  *	2-D coordinate.
528  *
529  * -------------------------------------------------------------------
530  */
531 typedef struct {
532     double x, y;
533 } Point2D;
534 
535 /*
536  * -------------------------------------------------------------------
537  *
538  * Point3D --
539  *
540  *	3-D coordinate.
541  *
542  * -------------------------------------------------------------------
543  */
544 typedef struct {
545     double x, y, z;
546 } Point3D;
547 
548 /*
549  * -------------------------------------------------------------------
550  *
551  * Segment2D --
552  *
553  *	2-D line segment.
554  *
555  * -------------------------------------------------------------------
556  */
557 typedef struct {
558     Point2D p, q;		/* The two end points of the segment. */
559 } Segment2D;
560 
561 /*
562  * -------------------------------------------------------------------
563  *
564  * Dim2D --
565  *
566  *	2-D dimension.
567  *
568  * -------------------------------------------------------------------
569  */
570 typedef struct {
571     short int width, height;
572 } Dim2D;
573 
574 /*
575  *----------------------------------------------------------------------
576  *
577  * Region2D --
578  *
579  *      2-D region.  Used to copy parts of images.
580  *
581  *----------------------------------------------------------------------
582  */
583 typedef struct {
584     int left, right, top, bottom;
585 } Region2D;
586 
587 #define RegionWidth(r)		((r)->right - (r)->left + 1)
588 #define RegionHeight(r)		((r)->bottom - (r)->top + 1)
589 
590 typedef struct {
591     double left, right, top, bottom;
592 } Extents2D;
593 
594 typedef struct {
595     double left, right, top, bottom, front, back;
596 } Extents3D;
597 
598 #define PointInRegion(e,x,y) \
599 	(((x) <= (e)->right) && ((x) >= (e)->left) && \
600 	 ((y) <= (e)->bottom) && ((y) >= (e)->top))
601 
602 #define PointInRectangle(r,x0,y0) \
603 	(((x0) <= (int)((r)->x + (r)->width - 1)) && ((x0) >= (int)(r)->x) && \
604 	 ((y0) <= (int)((r)->y + (r)->height - 1)) && ((y0) >= (int)(r)->y))
605 
606 
607 /* -------------------------------------------------------------------
608  *
609  * ColorPair --
610  *
611  *	Holds a pair of foreground, background colors.
612  *
613  * -------------------------------------------------------------------
614  */
615 typedef struct {
616     XColor *fgColor, *bgColor;
617 } ColorPair;
618 
619 #define COLOR_NONE		(XColor *)0
620 #define COLOR_DEFAULT		(XColor *)1
621 #define COLOR_ALLOW_DEFAULTS	1
622 
623 extern int Blt_GetColorPair _ANSI_ARGS_((Tcl_Interp *interp, Tk_Window tkwin,
624 	char *fgColor, char *bgColor, ColorPair *pairPtr, int colorFlag));
625 extern void Blt_FreeColorPair _ANSI_ARGS_((ColorPair *pairPtr));
626 
627 #define STATE_NORMAL	0
628 #define STATE_ACTIVE	(1<<0)
629 #define STATE_DISABLED	(1<<1)
630 #define STATE_EMPHASIS	(1<<2)
631 
632 
633 #define ARROW_NONE		(-1)
634 #define ARROW_LEFT		(0)
635 #define ARROW_UP		(1)
636 #define ARROW_RIGHT		(2)
637 #define ARROW_DOWN		(3)
638 #define ARROW_OFFSET		4
639 #define STD_ARROW_HEIGHT	3
640 #define STD_ARROW_WIDTH		((2 * (ARROW_OFFSET - 1)) + 1)
641 
642 #include "bltText.h"
643 
644 /*
645  * ----------------------------------------------------------------------
646  *
647  * 	X11/Xosdefs.h requires XNOSTDHDRS be set for some systems.
648  *	This is a guess.  If I can't find STDC headers or unistd.h,
649  *	assume that this is non-POSIX and non-STDC environment.
650  *	(needed for Encore Umax 3.4 ?)
651  *
652  * ----------------------------------------------------------------------
653  */
654 #if !defined(STDC_HEADERS) && !defined(HAVE_UNISTD_H)
655 #define XNOSTDHDRS 	1
656 #endif
657 
658 extern char *Blt_Itoa _ANSI_ARGS_((int value));
659 extern char *Blt_Utoa _ANSI_ARGS_((unsigned int value));
660 extern char *Blt_Dtoa _ANSI_ARGS_((Tcl_Interp *interp, double value));
661 extern Tcl_Command Blt_InitCmd _ANSI_ARGS_((Tcl_Interp *interp,
662 	char *namespace, Blt_CmdSpec *specPtr));
663 
664 #if (TCL_VERSION_NUMBER >= _VERSION(8,0,0))
665 extern Tcl_Command Blt_InitObjCmd _ANSI_ARGS_((Tcl_Interp *interp,
666 	char *namespace, Blt_ObjCmdSpec *specPtr));
667 #if (TCL_VERSION_NUMBER < _VERSION(8,1,0))
668 extern char *Tcl_GetString _ANSI_ARGS_((Tcl_Obj *objPtr));
669 extern int Tcl_EvalObjv _ANSI_ARGS_((Tcl_Interp *interp, int objc,
670 	Tcl_Obj **objv, int flags));
671 extern int Tcl_WriteObj _ANSI_ARGS_((Tcl_Channel channel, Tcl_Obj *objPtr));
672 extern char *Tcl_SetVar2Ex _ANSI_ARGS_((Tcl_Interp *interp, char *part1,
673 	char *part2, Tcl_Obj *objPtr, int flags));
674 extern Tcl_Obj *Tcl_GetVar2Ex _ANSI_ARGS_((Tcl_Interp *interp, char *part1,
675 	char *part2, int flags));
676 #endif /* TCL_VERSION_NUMBER < 8.2.0 */
677 #endif /* TCL_VERSION_NUMBER >= 8.0.0 */
678 
679 
680 extern int Blt_InitCmds _ANSI_ARGS_((Tcl_Interp *interp, char *namespace,
681 	Blt_CmdSpec *specPtr, int nCmds));
682 
683 extern int Blt_NaturalSpline _ANSI_ARGS_((Point2D *origPts, int nOrigPts,
684 	Point2D *intpPts, int nIntpPts));
685 
686 extern int Blt_QuadraticSpline _ANSI_ARGS_((Point2D *origPts, int nOrigPts,
687 	Point2D *intpPts, int nIntpPts));
688 
689 extern int Blt_SimplifyLine _ANSI_ARGS_((Point2D *origPts, int low, int high,
690 	 double tolerance, int indices[]));
691 
692 extern int Blt_NaturalParametricSpline _ANSI_ARGS_((Point2D *origPts,
693 	int nOrigPts, Extents2D *extsPtr, int isClosed, Point2D *intpPts,
694 	int nIntpPts));
695 
696 extern int Blt_CatromParametricSpline _ANSI_ARGS_((Point2D *origPts,
697 	int nOrigPts, Point2D *intpPts, int nIntpPts));
698 
699 extern int Blt_StringToFlag _ANSI_ARGS_((ClientData clientData,
700 	Tcl_Interp *interp, Tk_Window tkwin, char *string, char *widgRec,
701 	int flags));
702 extern char *Blt_FlagToString _ANSI_ARGS_((ClientData clientData,
703 	Tk_Window tkwin, char *string, int offset, Tcl_FreeProc **freeProc));
704 
705 extern void Blt_InitHexTable _ANSI_ARGS_((char *table));
706 
707 extern GC Blt_GetPrivateGC _ANSI_ARGS_((Tk_Window tkwin, unsigned long gcMask,
708 	XGCValues *valuePtr));
709 
710 extern GC Blt_GetPrivateGCFromDrawable _ANSI_ARGS_((Display *display,
711 	Drawable drawable, unsigned long gcMask, XGCValues *valuePtr));
712 
713 extern void Blt_FreePrivateGC _ANSI_ARGS_((Display *display, GC gc));
714 
715 extern Tk_Window Blt_FindChild _ANSI_ARGS_((Tk_Window parent, char *name));
716 
717 extern Tk_Window Blt_FirstChild _ANSI_ARGS_((Tk_Window parent));
718 
719 extern Tk_Window Blt_NextChild _ANSI_ARGS_((Tk_Window tkwin));
720 
721 extern void Blt_RelinkWindow _ANSI_ARGS_((Tk_Window tkwin, Tk_Window newParent,
722 	int x, int y));
723 
724 extern Tk_Window Blt_Toplevel _ANSI_ARGS_((Tk_Window tkwin));
725 
726 extern int Blt_GetPixels _ANSI_ARGS_((Tcl_Interp *interp, Tk_Window tkwin,
727 	char *string, int check, int *valuePtr));
728 extern int Blt_GetPosition _ANSI_ARGS_((Tcl_Interp *interp, char *string,
729 	int *indexPtr));
730 extern int Blt_GetPositionSize _ANSI_ARGS_((Tcl_Interp *interp, char *string,
731 	int size, int *indexPtr));
732 extern int Blt_GetCount _ANSI_ARGS_((Tcl_Interp *interp, char *string,
733 	int check, int *valuePtr));
734 
735 extern char *Blt_NameOfFill _ANSI_ARGS_((int fill));
736 
737 extern int Blt_GetXY _ANSI_ARGS_((Tcl_Interp *interp, Tk_Window tkwin,
738 	char *string, int *x, int *y));
739 
740 extern Point2D Blt_GetProjection _ANSI_ARGS_((int x, int y, Point2D *p,
741 	Point2D *q));
742 
743 extern void Blt_DrawArrow _ANSI_ARGS_((Display *display, Drawable drawable,
744 	GC gc, int x, int y, int arrowHeight, int orientation));
745 
746 extern Tk_OptionParseProc Blt_StringToEnum;
747 extern Tk_OptionPrintProc Blt_EnumToString;
748 
749 extern int Blt_ConfigModified _ANSI_ARGS_(TCL_VARARGS(Tk_ConfigSpec *, specs));
750 
751 extern void Blt_DStringAppendElements _ANSI_ARGS_(TCL_VARARGS(Tcl_DString *, args));
752 
753 extern void Blt_MakeTransparentWindowExist _ANSI_ARGS_((Tk_Window tkwin,
754 	Window parent, int isBusy));
755 
756 extern Window Blt_GetParent _ANSI_ARGS_((Display *display, Window tkwin));
757 
758 extern void Blt_GetBoundingBox _ANSI_ARGS_((int width, int height,
759 	double theta, double *widthPtr, double *heightPtr, Point2D *points));
760 
761 extern void Blt_InitEpsCanvasItem _ANSI_ARGS_((Tcl_Interp *interp));
762 
763 extern void Blt_TranslateAnchor _ANSI_ARGS_((int x, int y, int width,
764 	int height, Tk_Anchor anchor, int *transXPtr, int *transYPtr));
765 
766 extern Point2D Blt_TranslatePoint _ANSI_ARGS_((Point2D *pointPtr, int width,
767 	int height, Tk_Anchor anchor));
768 
769 extern int Blt_ConfigureWidgetComponent _ANSI_ARGS_((Tcl_Interp *interp,
770 	Tk_Window tkwin, char *name, char *class, Tk_ConfigSpec *specs,
771 	int argc, char **argv, char *widgRec, int flags));
772 
773 extern void Blt_HSV _ANSI_ARGS_((XColor *colorPtr, double *huePtr,
774 	double *valPtr, double *satPtr));
775 
776 extern void Blt_RGB _ANSI_ARGS_((double hue, double sat, double val,
777 	XColor *colorPtr));
778 
779 extern int Blt_ParseFlag _ANSI_ARGS_((ClientData, Tcl_Interp *, Tk_Window,
780 	char *, char *, int));
781 extern char *Blt_FlagPrint _ANSI_ARGS_((ClientData, Tk_Window, char *, int,
782 	Tcl_FreeProc **));
783 
784 extern int Blt_MaxRequestSize _ANSI_ARGS_((Display *display,
785 	unsigned int elemSize));
786 
787 extern Window Blt_GetRealWindowId _ANSI_ARGS_((Tk_Window tkwin));
788 extern int Blt_RootX _ANSI_ARGS_((Tk_Window tkwin));
789 extern int Blt_RootY _ANSI_ARGS_((Tk_Window tkwin));
790 extern void Blt_RootCoordinates _ANSI_ARGS_((Tk_Window tkwin, int x, int y,
791     int *rootXPtr, int *rootYPtr));
792 extern void Blt_MapToplevel _ANSI_ARGS_((Tk_Window tkwin));
793 extern void Blt_UnmapToplevel _ANSI_ARGS_((Tk_Window tkwin));
794 extern void Blt_RaiseToplevel _ANSI_ARGS_((Tk_Window tkwin));
795 extern void Blt_LowerToplevel _ANSI_ARGS_((Tk_Window tkwin));
796 extern void Blt_ResizeToplevel _ANSI_ARGS_((Tk_Window tkwin,
797 	int width, int height));
798 extern void Blt_MoveToplevel _ANSI_ARGS_((Tk_Window tkwin, int x, int y));
799 extern void Blt_MoveResizeToplevel _ANSI_ARGS_((Tk_Window tkwin,
800 	int x, int y, int width, int height));
801 extern ClientData Blt_GetWindowInstanceData _ANSI_ARGS_((Tk_Window tkwin));
802 
803 extern void Blt_SetWindowInstanceData _ANSI_ARGS_((Tk_Window tkwin,
804 	ClientData instanceData));
805 
806 extern void Blt_DeleteWindowInstanceData _ANSI_ARGS_((Tk_Window tkwin));
807 
808 extern int Blt_AdjustViewport _ANSI_ARGS_((int offset, int worldSize,
809 	int windowSize, int scrollUnits, int scrollMode));
810 
811 extern int Blt_GetScrollInfo _ANSI_ARGS_((Tcl_Interp *interp, int argc,
812 	char **argv, int *offsetPtr, int worldSize, int windowSize,
813 	int scrollUnits, int scrollMode));
814 
815 extern int Blt_WinResizeAlways _ANSI_ARGS_((Tk_Window tkwin));
816 
817 #if (TK_MAJOR_VERSION >= 8)
818 extern int Blt_GetScrollInfoFromObj _ANSI_ARGS_((Tcl_Interp *interp, int objc,
819 	Tcl_Obj *CONST *objv, int *offsetPtr, int worldSize, int windowSize,
820 	int scrollUnits, int scrollMode));
821 #endif
822 
823 extern void Blt_UpdateScrollbar _ANSI_ARGS_((Tcl_Interp *interp,
824 	char *scrollCmd, double firstFract, double lastFract));
825 
826 extern int Blt_ReparentWindow _ANSI_ARGS_((Display *display, Window window,
827 	Window newParent, int x, int y));
828 
829 #if defined(HAVE_JPEGLIB_H) || defined(HAVE_IJL_H)
830 #define HAVE_JPEG 1
831 extern int Blt_JPEGToPhoto _ANSI_ARGS_((Tcl_Interp *interp, char *fileName,
832 	Tk_PhotoHandle photo));
833 #endif /* HAVE_JPEGLIB_H || HAVE_IJL_H */
834 
835 #define Blt_SetBooleanResult(i, b) \
836 	Tcl_SetResult((i), (b) ? "1" : "0", TCL_STATIC)
837 
838 /*
839  * Define this if you want to be able to tile to the main window "."
840  * This will cause a conflict with Tk if you try to compile and link
841  * statically.
842  */
843 #undef TILE_MAINWINDOW
844 
845 #ifdef WIN32
846 #if (TCL_MAJOR_VERSION == 8)  && (TCL_MINOR_VERSION == 0)
847 #else
848 #define NO_DDE		1
849 #endif
850 #else
851 #define NO_DDE		1
852 #define NO_PRINTER	1
853 #endif /* WIN32 */
854 
855 #if (TCL_MAJOR_VERSION == 7)
856 #define NO_TREE		1
857 #define NO_ARRAY	1
858 #define NO_TREEVIEW	1
859 #endif
860 
861 /* #define NO_TED */
862 
863 #ifndef NO_BEEP
864 extern Tcl_AppInitProc Blt_BeepInit;
865 #endif
866 #ifndef NO_BGEXEC
867 extern Tcl_AppInitProc Blt_BgexecInit;
868 #endif
869 #ifndef NO_BITMAP
870 extern Tcl_AppInitProc Blt_BitmapInit;
871 #endif
872 #ifndef NO_BUSY
873 extern Tcl_AppInitProc Blt_BusyInit;
874 #endif
875 #ifndef NO_CONTAINER
876 extern Tcl_AppInitProc Blt_ContainerInit;
877 #endif
878 #ifndef NO_CRC32
879 extern Tcl_AppInitProc Blt_Crc32Init;
880 #endif
881 #ifndef NO_CUTBUFFER
882 extern Tcl_AppInitProc Blt_CutbufferInit;
883 #endif
884 #ifndef NO_DEBUG
885 extern Tcl_AppInitProc Blt_DebugInit;
886 #endif
887 #ifndef NO_DRAGDROP
888 extern Tcl_AppInitProc Blt_DragDropInit;
889 #endif
890 #ifndef NO_DND
891 extern Tcl_AppInitProc Blt_DndInit;
892 #endif
893 #ifndef NO_GRAPH
894 extern Tcl_AppInitProc Blt_GraphInit;
895 #endif
896 #ifndef NO_HIERBOX
897 extern Tcl_AppInitProc Blt_HierboxInit;
898 #endif
899 #ifndef NO_HIERTABLE
900 extern Tcl_AppInitProc Blt_HiertableInit;
901 #endif
902 #ifndef NO_HTEXT
903 extern Tcl_AppInitProc Blt_HtextInit;
904 #endif
905 #ifdef WIN32
906 #ifndef NO_PRINTER
907 extern Tcl_AppInitProc Blt_PrinterInit;
908 #endif
909 #endif
910 #ifndef NO_TABLE
911 extern Tcl_AppInitProc Blt_TableInit;
912 #endif
913 #ifndef NO_VECTOR
914 extern Tcl_AppInitProc Blt_VectorInit;
915 #endif
916 #ifndef NO_WINOP
917 extern Tcl_AppInitProc Blt_WinopInit;
918 #endif
919 #ifndef NO_WATCH
920 extern Tcl_AppInitProc Blt_WatchInit;
921 #endif
922 #ifndef NO_SPLINE
923 extern Tcl_AppInitProc Blt_SplineInit;
924 #endif
925 #ifndef NO_TABSET
926 extern Tcl_AppInitProc Blt_TabsetInit;
927 #endif
928 #ifndef NO_TABNOTEBOOK
929 extern Tcl_AppInitProc Blt_TabnotebookInit;
930 #endif
931 #ifndef NO_TREE
932 extern Tcl_AppInitProc Blt_TreeInit;
933 #endif
934 #ifndef NO_TREEVIEW
935 extern Tcl_AppInitProc Blt_TreeViewInit;
936 #endif
937 #ifndef NO_TILEFRAME
938 extern Tcl_AppInitProc Blt_FrameInit;
939 #endif
940 #ifndef NO_TILEBUTTON
941 extern Tcl_AppInitProc Blt_ButtonInit;
942 #endif
943 #ifndef NO_TILESCROLLBAR
944 extern Tcl_AppInitProc Blt_ScrollbarInit;
945 #endif
946 
947 #if (BLT_MAJOR_VERSION == 3)
948 #ifndef NO_MOUNTAIN
949 extern Tcl_AppInitProc Blt_MountainInit;
950 #endif
951 #endif
952 #ifndef NO_TED
953 extern Tcl_AppInitProc Blt_TedInit;
954 #endif
955 
956 #ifndef NO_DDE
957 extern Tcl_AppInitProc Blt_DdeInit;
958 #endif
959 
960 typedef void *(Blt_MallocProc) _ANSI_ARGS_((size_t size));
961 typedef void *(Blt_CallocProc) _ANSI_ARGS_((int nElem, size_t size));
962 typedef void *(Blt_ReallocProc) _ANSI_ARGS_((void *ptr, size_t size));
963 typedef void (Blt_FreeProc) _ANSI_ARGS_((void *ptr));
964 
965 EXTERN Blt_MallocProc *Blt_MallocProcPtr;
966 EXTERN Blt_FreeProc *Blt_FreeProcPtr;
967 EXTERN Blt_ReallocProc *Blt_ReallocProcPtr;
968 
969 #define Blt_Malloc(size)	(*Blt_MallocProcPtr)(size)
970 #define Blt_Free		(*Blt_FreeProcPtr)
971 #define Blt_Realloc(ptr, size)  (*Blt_ReallocProcPtr)(ptr, size)
972 
973 EXTERN char *Blt_Strdup _ANSI_ARGS_((CONST char *ptr));
974 EXTERN void *Blt_Calloc _ANSI_ARGS_((unsigned int nElem, size_t size));
975 
976 EXTERN Tk_CustomOption bltTileOption;
977 EXTERN Tk_ObjCustomOption bltCustomTileOption;
978 
979 #ifdef WIN32
980 #include "bltWin.h"
981 #endif
982 
983 #ifndef WIN32
984 #define PurifyPrintf  printf
985 #endif /* WIN32 */
986 #endif /*_BLT_INT_H*/
987