1 /**
2  * D bindings to Tcl/Tk
3  *
4  * License:
5  *     MIT. See LICENSE for full details.
6  */
7 module tcltk.tk;
8 
9 import core.stdc.config;
10 import x11.X;
11 import x11.Xlib;
12 
13 public import tcltk.tcl;
14 
15 static if (TCL_MAJOR_VERSION != 8 || TCL_MINOR_VERSION != 5)
16 {
17 	static assert(false, "Error Tk 8.5 must be compiled with tcl.h from Tcl 8.5");
18 }
19 
20 /*
21  * When version numbers change here, you must also go into the following files
22  * and update the version numbers:
23  *
24  * library/tk.tcl	(2 LOC patch)
25  * unix/configure.in	(2 LOC Major, 2 LOC minor, 1 LOC patch)
26  * win/configure.in	(as above)
27  * README		(sections 0 and 1)
28  * macosx/Wish.xcode/project.pbxproj (not patchlevel) 1 LOC
29  * macosx/Wish-Common.xcconfig (not patchlevel) 1 LOC
30  * win/README		(not patchlevel)
31  * unix/README		(not patchlevel)
32  * unix/tk.spec		(1 LOC patch)
33  * win/tcl.m4		(not patchlevel)
34  *
35  * You may also need to update some of these files when the numbers change for
36  * the version of Tcl that this release of Tk is compiled against.
37  */
38 enum TK_MAJOR_VERSION  = 8;
39 enum TK_MINOR_VERSION  = 5;
40 enum TK_RELEASE_LEVEL  = TCL_FINAL_RELEASE;
41 enum TK_RELEASE_SERIAL = 11;
42 enum TK_VERSION        = "8.5";
43 enum TK_PATCH_LEVEL    = "8.5.11";
44 
45 /*
46  * Dummy types that are used by clients:
47  */
48 struct Tk_BindingTable_;
49 alias Tk_BindingTable = Tk_BindingTable_*;
50 struct Tk_Canvas_;
51 alias Tk_Canvas = Tk_Canvas_*;
52 struct Tk_Cursor_;
53 alias Tk_Cursor = Tk_Cursor_*;
54 struct Tk_ErrorHandler_;
55 alias Tk_ErrorHandler = Tk_ErrorHandler_*;
56 struct Tk_Font_;
57 alias Tk_Font = Tk_Font_*;
58 struct Tk_Image_;
59 alias Tk_Image = Tk_Image_*;
60 struct Tk_ImageMaster_;
61 alias Tk_ImageMaster = Tk_ImageMaster_*;
62 struct Tk_OptionTable_;
63 alias Tk_OptionTable = Tk_OptionTable_*;
64 struct Tk_PostscriptInfo_;
65 alias Tk_PostscriptInfo = Tk_PostscriptInfo_*;
66 struct Tk_TextLayout_;
67 alias Tk_TextLayout = Tk_TextLayout_*;
68 struct Tk_Window_;
69 alias Tk_Window = Tk_Window_*;
70 struct Tk_3DBorder_;
71 alias Tk_3DBorder = Tk_3DBorder_*;
72 struct Tk_Style_;
73 alias Tk_Style = Tk_Style_*;
74 struct Tk_StyleEngine_;
75 alias Tk_StyleEngine = Tk_StyleEngine_*;
76 struct Tk_StyledElement_;
77 alias Tk_StyledElement = Tk_StyledElement_*;
78 
79 /*
80  * Additional types exported to clients.
81  */
82 alias Tk_Uid = const(char)*;
83 
84 /*
85  * The enum below defines the valid types for Tk configuration options as
86  * implemented by Tk_InitOptions, Tk_SetOptions, etc.
87  */
88 enum Tk_OptionType
89 {
90     TK_OPTION_BOOLEAN,
91     TK_OPTION_INT,
92     TK_OPTION_DOUBLE,
93     TK_OPTION_STRING,
94     TK_OPTION_STRING_TABLE,
95     TK_OPTION_COLOR,
96     TK_OPTION_FONT,
97     TK_OPTION_BITMAP,
98     TK_OPTION_BORDER,
99     TK_OPTION_RELIEF,
100     TK_OPTION_CURSOR,
101     TK_OPTION_JUSTIFY,
102     TK_OPTION_ANCHOR,
103     TK_OPTION_SYNONYM,
104     TK_OPTION_PIXELS,
105     TK_OPTION_WINDOW,
106     TK_OPTION_END,
107     TK_OPTION_CUSTOM,
108     TK_OPTION_STYLE,
109 }
110 
111 /*
112  * Structures of the following type are used by widgets to specify their
113  * configuration options. Typically each widget has a static array of these
114  * structures, where each element of the array describes a single
115  * configuration option. The array is passed to Tk_CreateOptionTable.
116  */
117 struct Tk_OptionSpec
118 {
119 	/* Type of option, such as TK_OPTION_COLOR;
120 	 * see definitions above. Last option in table
121 	 * must have type TK_OPTION_END. */
122 	Tk_OptionType type;
123 
124 	/* Name used to specify option in Tcl
125 	 * commands. */
126 	const(char)* optionName;
127 
128 	/* Name for option in option database. */
129 	const(char)* dbName;
130 
131 	/* Class for option in database. */
132 	const(char)* dbClass;
133 
134 	/* Default value for option if not specified
135 	 * in command line, the option database, or
136 	 * the system. */
137 	const(char)* defValue;
138 
139 	/* Where in record to store a Tcl_Obj * that
140 	 * holds the value of this option, specified
141 	 * as an offset in bytes from the start of the
142 	 * record. Use the Tk_Offset macro to generate
143 	 * values for this. -1 means don't store the
144 	 * Tcl_Obj in the record. */
145 	int objOffset;
146 
147 	/* Where in record to store the internal
148 	 * representation of the value of this option,
149 	 * such as an int or XColor *. This field is
150 	 * specified as an offset in bytes from the
151 	 * start of the record. Use the Tk_Offset
152 	 * macro to generate values for it. -1 means
153 	 * don't store the internal representation in
154 	 * the record. */
155 	int internalOffset;
156 
157 	/* Any combination of the values defined
158 	 * below. */
159 	int flags;
160 
161 	/* An alternate place to put option-specific
162 	 * data. Used for the monochrome default value
163 	 * for colors, etc. */
164 	ClientData clientData;
165 
166 	/* An arbitrary bit mask defined by the class
167 	 * manager; typically bits correspond to
168 	 * certain kinds of options such as all those
169 	 * that require a redisplay when they change.
170 	 * Tk_SetOptions returns the bit-wise OR of
171 	 * the typeMasks of all options that were
172 	 * changed. */
173 	int typeMask;
174 }
175 
176 /*
177  * Flag values for Tk_OptionSpec structures. These flags are shared by
178  * Tk_ConfigSpec structures, so be sure to coordinate any changes carefully.
179  */
180 enum TK_OPTION_NULL_OK          = (1 << 0);
181 enum TK_OPTION_DONT_SET_DEFAULT = (1 << 3);
182 
183 /*
184  * The following structure and function types are used by TK_OPTION_CUSTOM
185  * options; the structure holds pointers to the functions needed by the Tk
186  * option config code to handle a custom option.
187  */
188 alias extern(C) int function(ClientData clientData, Tcl_Interp* interp, Tk_Window tkwin, Tcl_Obj** value, const(char)* widgRec, int offset, const(char)* saveInternalPtr, int flags) nothrow Tk_CustomOptionSetProc;
189 alias extern(C) Tcl_Obj* function(ClientData clientData, Tk_Window tkwin, const(char)* widgRec, int offset) nothrow Tk_CustomOptionGetProc;
190 alias extern(C) void function(ClientData clientData, Tk_Window tkwin, const(char)* internalPtr, const(char)* saveInternalPtr) nothrow Tk_CustomOptionRestoreProc;
191 alias extern(C) void function(ClientData clientData, Tk_Window tkwin, const(char)* internalPtr) nothrow Tk_CustomOptionFreeProc;
192 
193 struct Tk_ObjCustomOption
194 {
195 	/* Name of the custom option. */
196 	const(char)* name;
197 
198 	/* Function to use to set a record's option
199 	 * value from a Tcl_Obj */
200 	Tk_CustomOptionSetProc setProc;
201 
202 	/* Function to use to get a Tcl_Obj
203 	 * representation from an internal
204 	 * representation of an option. */
205 	Tk_CustomOptionGetProc getProc;
206 
207 	/* Function to use to restore a saved value
208 	 * for the internal representation. */
209 	Tk_CustomOptionRestoreProc restoreProc;
210 
211 	/* Function to use to free the internal
212 	 * representation of an option. */
213 	Tk_CustomOptionFreeProc freeProc;
214 
215 	/* Arbitrary one-word value passed to the
216 	 * handling procs. */
217 	ClientData clientData;
218 }
219 
220 /*
221  * Macro to use to fill in "offset" fields of the Tk_OptionSpec structure.
222  * Computes number of bytes from beginning of structure to a given field.
223  */
224 int Tk_Offset(Type, string field)()
225 {
226 	return mixin(Type.stringof ~ ".init." ~ field ~ ".offsetof");
227 }
228 
229 /*
230  * The following two structures are used for error handling. When config
231  * options are being modified, the old values are saved in a Tk_SavedOptions
232  * structure. If an error occurs, then the contents of the structure can be
233  * used to restore all of the old values. The contents of this structure are
234  * for the private use Tk. No-one outside Tk should ever read or write any of
235  * the fields of these structures.
236  */
237 struct TkOption;
238 struct Tk_SavedOption
239 {
240 	/* Points to information that describes the
241 	 * option. */
242 	TkOption* optionPtr;
243 
244 	/* The old value of the option, in the form of
245 	 * a Tcl object; may be NULL if the value was
246 	 * not saved as an object. */
247 	Tcl_Obj* valuePtr;
248 
249 	/* The old value of the option, in some
250 	 * internal representation such as an int or
251 	 * (XColor *). Valid only if the field
252 	 * optionPtr->specPtr->objOffset is < 0. The
253 	 * space must be large enough to accommodate a
254 	 * double, a long, or a pointer; right now it
255 	 * looks like a double (i.e., 8 bytes) is big
256 	 * enough. Also, using a double guarantees
257 	 * that the field is properly aligned for
258 	 * storing large values. */
259 	double internalForm;
260 }
261 
262 version(TCL_MEM_DEBUG)
263 {
264 	enum TK_NUM_SAVED_OPTIONS = 2;
265 }
266 else
267 {
268 	enum TK_NUM_SAVED_OPTIONS = 20;
269 }
270 
271 struct Tk_SavedOptions
272 {
273 	/* The data structure in which to restore
274 	 * configuration options. */
275 	const(char)* recordPtr;
276 
277 	/* Window associated with recordPtr; needed to
278 	 * restore certain options. */
279 	Tk_Window tkwin;
280 
281 	/* The number of valid items in items field. */
282 	int numItems;
283 
284 	/* Items used to hold old values. */
285 	Tk_SavedOption[TK_NUM_SAVED_OPTIONS] items;
286 
287 	/* Points to next structure in list; needed if
288 	 * too many options changed to hold all the
289 	 * old values in a single structure. NULL
290 	 * means no more structures. */
291 	Tk_SavedOptions* nextPtr;
292 }
293 
294 /*
295  * Structure used to describe application-specific configuration options:
296  * indicates procedures to call to parse an option and to return a text string
297  * describing an option. THESE ARE DEPRECATED; PLEASE USE THE NEW STRUCTURES
298  * LISTED ABOVE.
299  */
300 
301 /*
302  * This is a temporary flag used while tkObjConfig and new widgets are in
303  * development.
304  */
305 enum __NO_OLD_CONFIG = false;
306 
307 static if (!__NO_OLD_CONFIG)
308 {
309 	alias extern(C) int function(ClientData clientData, Tcl_Interp* interp, Tk_Window tkwin, const(char)* value, const(char)* widgRec, int offset) nothrow Tk_OptionParseProc;
310 	alias extern(C) const(char)* function(ClientData clientData, Tk_Window tkwin, const(char)* widgRec, int offset, Tcl_FreeProc* freeProcPtr) nothrow Tk_OptionPrintProc;
311 
312 	struct Tk_CustomOption
313 	{
314 		/* Procedure to call to parse an option and
315 		 * store it in converted form. */
316 		Tk_OptionParseProc parseProc;
317 
318 		/* Procedure to return a printable string
319 		 * describing an existing option. */
320 		Tk_OptionPrintProc printProc;
321 
322 		/* Arbitrary one-word value used by option
323 		 * parser: passed to parseProc and
324 		 * printProc. */
325 		ClientData clientData;
326 	}
327 
328 	/*
329 	 * Structure used to specify information for Tk_ConfigureWidget. Each
330 	 * structure gives complete information for one option, including how the
331 	 * option is specified on the command line, where it appears in the option
332 	 * database, etc.
333 	 */
334 	struct Tk_ConfigSpec
335 	{
336 		/* Type of option, such as TK_CONFIG_COLOR;
337 		 * see definitions below. Last option in table
338 		 * must have type TK_CONFIG_END. */
339 		int type;
340 
341 		/* Switch used to specify option in argv. NULL
342 		 * means this spec is part of a group. */
343 		const(char)* argvName;
344 
345 		/* Name for option in option database. */
346 		Tk_Uid dbName;
347 
348 		/* Class for option in database. */
349 		Tk_Uid dbClass;
350 
351 		/* Default value for option if not specified
352 		 * in command line or database. */
353 		Tk_Uid defValue;
354 
355 		/* Where in widget record to store value; use
356 		 * Tk_Offset macro to generate values for
357 		 * this. */
358 		int offset;
359 
360 		/* Any combination of the values defined
361 		 * below; other bits are used internally by
362 		 * tkConfig.c. */
363 		int specFlags;
364 
365 		/* If type is TK_CONFIG_CUSTOM then this is a
366 		 * pointer to info about how to parse and
367 		 * print the option. Otherwise it is
368 		 * irrelevant. */
369 		Tk_CustomOption* customPtr;
370 	}
371 
372 	/*
373 	 * Type values for Tk_ConfigSpec structures. See the user documentation for
374 	 * details.
375 	 */
376 	enum Tk_ConfigTypes
377 	{
378 		TK_CONFIG_BOOLEAN,
379 		TK_CONFIG_INT,
380 		TK_CONFIG_DOUBLE,
381 		TK_CONFIG_STRING,
382 		TK_CONFIG_UID,
383 		TK_CONFIG_COLOR,
384 		TK_CONFIG_FONT,
385 		TK_CONFIG_BITMAP,
386 		TK_CONFIG_BORDER,
387 		TK_CONFIG_RELIEF,
388 		TK_CONFIG_CURSOR,
389 		TK_CONFIG_ACTIVE_CURSOR,
390 		TK_CONFIG_JUSTIFY,
391 		TK_CONFIG_ANCHOR,
392 		TK_CONFIG_SYNONYM,
393 		TK_CONFIG_CAP_STYLE,
394 		TK_CONFIG_JOIN_STYLE,
395 		TK_CONFIG_PIXELS,
396 		TK_CONFIG_MM,
397 		TK_CONFIG_WINDOW,
398 		TK_CONFIG_CUSTOM,
399 		TK_CONFIG_END,
400 	}
401 
402 	/*
403 	 * Possible values for flags argument to Tk_ConfigureWidget:
404 	 */
405 	enum TK_CONFIG_ARGV_ONLY = 1;
406 	enum TK_CONFIG_OBJS      = 0x80;
407 
408 	/*
409 	 * Possible flag values for Tk_ConfigSpec structures. Any bits at or above
410 	 * TK_CONFIG_USER_BIT may be used by clients for selecting certain entries.
411 	 * Before changing any values here, coordinate with tkOldConfig.c
412 	 * (internal-use-only flags are defined there).
413 	 */
414 	enum TK_CONFIG_NULL_OK          = (1 << 0);
415 	enum TK_CONFIG_COLOR_ONLY       = (1 << 1);
416 	enum TK_CONFIG_MONO_ONLY        = (1 << 2);
417 	enum TK_CONFIG_DONT_SET_DEFAULT = (1 << 3);
418 	enum TK_CONFIG_OPTION_SPECIFIED = (1 << 4);
419 	enum TK_CONFIG_USER_BIT         = 0x100;
420 }
421 
422 /*
423  * Structure used to specify how to handle argv options.
424  */
425 struct Tk_ArgvInfo
426 {
427 	/* The key string that flags the option in the
428 	 * argv array. */
429 	const(char)* key;
430 
431 	/* Indicates option type; see below. */
432 	int type;
433 
434 	/* Value to be used in setting dst; usage
435 	 * depends on type. */
436 	const(char)* src;
437 
438 	/* Address of value to be modified; usage
439 	 * depends on type. */
440 	const(char)* dst;
441 
442 	/* Documentation message describing this
443 	 * option. */
444 	const(char)* help;
445 }
446 
447 /*
448  * Legal values for the type field of a Tk_ArgvInfo: see the user
449  * documentation for details.
450  */
451 enum TK_ARGV_CONSTANT          = 15;
452 enum TK_ARGV_INT               = 16;
453 enum TK_ARGV_STRING            = 17;
454 enum TK_ARGV_UID               = 18;
455 enum TK_ARGV_REST              = 19;
456 enum TK_ARGV_FLOAT             = 20;
457 enum TK_ARGV_FUNC              = 21;
458 enum TK_ARGV_GENFUNC           = 22;
459 enum TK_ARGV_HELP              = 23;
460 enum TK_ARGV_CONST_OPTION      = 24;
461 enum TK_ARGV_OPTION_VALUE      = 25;
462 enum TK_ARGV_OPTION_NAME_VALUE = 26;
463 enum TK_ARGV_END               = 27;
464 
465 /*
466  * Flag bits for passing to Tk_ParseArgv:
467  */
468 enum TK_ARGV_NO_DEFAULTS         = 0x1;
469 enum TK_ARGV_NO_LEFTOVERS        = 0x2;
470 enum TK_ARGV_NO_ABBREV           = 0x4;
471 enum TK_ARGV_DONT_SKIP_FIRST_ARG = 0x8;
472 
473 /*
474  * Enumerated type for describing actions to be taken in response to a
475  * restrictProc established by Tk_RestrictEvents.
476  */
477 enum Tk_RestrictAction
478 {
479 	TK_DEFER_EVENT,
480 	TK_PROCESS_EVENT,
481 	TK_DISCARD_EVENT,
482 }
483 
484 /*
485  * Priority levels to pass to Tk_AddOption:
486  */
487 enum TK_WIDGET_DEFAULT_PRIO = 20;
488 enum TK_STARTUP_FILE_PRIO   = 40;
489 enum TK_USER_DEFAULT_PRIO   = 60;
490 enum TK_INTERACTIVE_PRIO    = 80;
491 enum TK_MAX_PRIO            = 100;
492 
493 /*
494  * Relief values returned by Tk_GetRelief:
495  */
496 enum TK_RELIEF_NULL   = -1;
497 enum TK_RELIEF_FLAT   = 0;
498 enum TK_RELIEF_GROOVE = 1;
499 enum TK_RELIEF_RAISED = 2;
500 enum TK_RELIEF_RIDGE  = 3;
501 enum TK_RELIEF_SOLID  = 4;
502 enum TK_RELIEF_SUNKEN = 5;
503 
504 /*
505  * "Which" argument values for Tk_3DBorderGC:
506  */
507 enum TK_3D_FLAT_GC  = 1;
508 enum TK_3D_LIGHT_GC = 2;
509 enum TK_3D_DARK_GC  = 3;
510 
511 /*
512  * Special EnterNotify/LeaveNotify "mode" for use in events generated by
513  * tkShare.c. Pick a high enough value that it's unlikely to conflict with
514  * existing values (like NotifyNormal) or any new values defined in the
515  * future.
516  */
517 enum TK_NOTIFY_SHARE = 20;
518 
519 /*
520  * Enumerated type for describing a point by which to anchor something:
521  */
522 enum  Tk_Anchor
523 {
524 	TK_ANCHOR_N,
525 	TK_ANCHOR_NE,
526 	TK_ANCHOR_E,
527 	TK_ANCHOR_SE,
528 	TK_ANCHOR_S,
529 	TK_ANCHOR_SW,
530 	TK_ANCHOR_W,
531 	TK_ANCHOR_NW,
532 	TK_ANCHOR_CENTER,
533 }
534 
535 /*
536  * Enumerated type for describing a style of justification:
537  */
538 enum Tk_Justify
539 {
540 	TK_JUSTIFY_LEFT,
541 	TK_JUSTIFY_RIGHT,
542 	TK_JUSTIFY_CENTER,
543 }
544 
545 /*
546  * The following structure is used by Tk_GetFontMetrics() to return
547  * information about the properties of a Tk_Font.
548  */
549 struct Tk_FontMetrics
550 {
551 	/* The amount in pixels that the tallest
552 	 * letter sticks up above the baseline, plus
553 	 * any extra blank space added by the designer
554 	 * of the font. */
555 	int ascent;
556 
557 	/* The largest amount in pixels that any
558 	 * letter sticks below the baseline, plus any
559 	 * extra blank space added by the designer of
560 	 * the font. */
561 	int descent;
562 
563 	/* The sum of the ascent and descent. How far
564 	 * apart two lines of text in the same font
565 	 * should be placed so that none of the
566 	 * characters in one line overlap any of the
567 	 * characters in the other line. */
568 	int linespace;
569 }
570 
571 /*
572  * Flags passed to Tk_MeasureChars:
573  */
574 enum TK_WHOLE_WORDS  = 1;
575 enum TK_AT_LEAST_ONE = 2;
576 enum TK_PARTIAL_OK   = 4;
577 
578 /*
579  * Flags passed to Tk_ComputeTextLayout:
580  */
581 enum TK_IGNORE_TABS     = 8;
582 enum TK_IGNORE_NEWLINES = 16;
583 
584 /*
585  * Widget class procedures used to implement platform specific widget
586  * behavior.
587  */
588 
589 alias extern(C) Window function(Tk_Window tkwin, Window parent, ClientData instanceData) nothrow Tk_ClassCreateProc;
590 alias extern(C) void function(ClientData instanceData) nothrow Tk_ClassWorldChangedProc;
591 alias extern(C) void function(Tk_Window tkwin, XEvent* eventPtr) nothrow Tk_ClassModalProc;
592 
593 struct Tk_ClassProcs
594 {
595 	uint size;
596 
597 	/* Procedure to invoke when the widget needs
598 	 * to respond in some way to a change in the
599 	 * world (font changes, etc.) */
600 	Tk_ClassWorldChangedProc worldChangedProc;
601 
602 	/* Procedure to invoke when the platform-
603 	 * dependent window needs to be created. */
604 	Tk_ClassCreateProc createProc;
605 
606 	/* Procedure to invoke after all bindings on a
607 	 * widget have been triggered in order to
608 	 * handle a modal loop. */
609 	Tk_ClassModalProc modalProc;
610 }
611 
612 /*
613  * Each geometry manager (the packer, the placer, etc.) is represented by a
614  * structure of the following form, which indicates procedures to invoke in
615  * the geometry manager to carry out certain functions.
616  */
617 alias extern(C) void function(ClientData clientData, Tk_Window tkwin) nothrow Tk_GeomRequestProc;
618 alias extern(C) void function(ClientData clientData, Tk_Window tkwin) nothrow Tk_GeomLostSlaveProc;
619 
620 struct Tk_GeomMgr
621 {
622 	/* Name of the geometry manager (command used
623 	 * to invoke it, or name of widget class that
624 	 * allows embedded widgets). */
625 	const(char)* name;
626 
627 	/* Procedure to invoke when a slave's
628 	 * requested geometry changes. */
629 	Tk_GeomRequestProc requestProc;
630 
631 	/* Procedure to invoke when a slave is taken
632 	 * away from one geometry manager by another.
633 	 * NULL means geometry manager doesn't care
634 	 * when slaves are lost. */
635 	Tk_GeomLostSlaveProc lostSlaveProc;
636 }
637 
638 /*
639  * Result values returned by Tk_GetScrollInfo:
640  */
641 enum TK_SCROLL_MOVETO = 1;
642 enum TK_SCROLL_PAGES  = 2;
643 enum TK_SCROLL_UNITS  = 3;
644 enum TK_SCROLL_ERROR  = 4;
645 
646 /*
647  *---------------------------------------------------------------------------
648  *
649  * Extensions to the X event set
650  *
651  *---------------------------------------------------------------------------
652  */
653 enum VirtualEvent     = (MappingNotify + 1);
654 enum ActivateNotify   = (MappingNotify + 2);
655 enum DeactivateNotify = (MappingNotify + 3);
656 enum MouseWheelEvent  = (MappingNotify + 4);
657 enum TK_LASTEVENT     = (MappingNotify + 5);
658 enum MouseWheelMask   = (1L << 28);
659 enum ActivateMask     = (1L << 29);
660 enum VirtualEventMask = (1L << 30);
661 
662 /*
663  * A virtual event shares most of its fields with the XKeyEvent and
664  * XButtonEvent structures. 99% of the time a virtual event will be an
665  * abstraction of a key or button event, so this structure provides the most
666  * information to the user. The only difference is the changing of the detail
667  * field for a virtual event so that it holds the name of the virtual event
668  * being triggered.
669  *
670  * When using this structure, you should ensure that you zero out all the
671  * fields first using memset() or bzero().
672  */
673 struct XVirtualEvent
674 {
675 	int type;
676 
677 	/* # of last request processed by server. */
678 	c_ulong serial;
679 
680 	/* True if this came from a SendEvent
681 	 * request. */
682 	bool send_event;
683 
684 	/* Display the event was read from. */
685 	Display* display;
686 
687 	/* Window on which event was requested. */
688 	Window event;
689 
690 	/* Root window that the event occured on. */
691 	Window root;
692 
693 	/* Child window. */
694 	Window subwindow;
695 
696 	/* Milliseconds. */
697 	Time time;
698 
699 	/* Pointer x, y coordinates in event
700 	 * window. */
701 	int x, y;
702 
703 	/* Coordinates relative to root. */
704 	int x_root, y_root;
705 
706 	/* Key or button mask */
707 	uint state;
708 
709 	/* Name of virtual event. */
710 	Tk_Uid name;
711 
712 	/* Same screen flag. */
713 	bool same_screen;
714 
715 	/* Application-specific data reference; Tk
716 	 * will decrement the reference count *once*
717 	 * when it has finished processing the
718 	 * event. */
719 	Tcl_Obj* user_data;
720 }
721 
722 struct XActivateDeactivateEvent
723 {
724 	int type;
725 
726 	/* # of last request processed by server. */
727 	c_ulong serial;
728 
729 	/* True if this came from a SendEvent
730 	 * request. */
731 	bool send_event;
732 
733 	/* Display the event was read from. */
734 	Display* display;
735 
736 	/* Window in which event occurred. */
737 	Window window;
738 }
739 
740 alias XActivateEvent   = XActivateDeactivateEvent;
741 alias XDeactivateEvent = XActivateDeactivateEvent;
742 
743 /*
744  * The structure below is needed by the macros below so that they can access
745  * the fields of a Tk_Window. The fields not needed by the macros are declared
746  * as "dummyX". The structure has its own type in order to prevent apps from
747  * accessing Tk_Window fields except using official macros. WARNING!! The
748  * structure definition must be kept consistent with the TkWindow structure in
749  * tkInt.h. If you change one, then change the other. See the declaration in
750  * tkInt.h for documentation on what the fields are used for internally.
751  */
752 struct Tk_FakeWin
753 {
754     Display* display;
755     void* dummy1; /* dispPtr */
756     int screenNum;
757     Visual* visual;
758     int depth;
759     Window window;
760     void* dummy2; /* childList */
761     void* dummy3; /* lastChildPtr */
762     Tk_Window parentPtr; /* parentPtr */
763     void* dummy4; /* nextPtr */
764     void* dummy5; /* mainPtr */
765     const(char)* pathName;
766     Tk_Uid nameUid;
767     Tk_Uid classUid;
768     XWindowChanges changes;
769     uint dummy6; /* dirtyChanges */
770     XSetWindowAttributes atts;
771     c_ulong dummy7; /* dirtyAtts */
772     uint flags;
773     void* dummy8; /* handlerList */
774     ClientData* dummy10; /* tagPtr */
775     int dummy11; /* numTags */
776     int dummy12; /* optionLevel */
777     void* dummy13; /* selHandlerList */
778     void* dummy14; /* geomMgrPtr */
779     ClientData dummy15; /* geomData */
780     int reqWidth;
781 	int reqHeight;
782     int internalBorderLeft;
783     void* dummy16; /* wmInfoPtr */
784     void* dummy17; /* classProcPtr */
785     ClientData dummy18; /* instanceData */
786     void* dummy19; /* privatePtr */
787     int internalBorderRight;
788     int internalBorderTop;
789     int internalBorderBottom;
790     int minReqWidth;
791     int minReqHeight;
792 }
793 
794 /*
795  * Flag values for TkWindow (and Tk_FakeWin) structures are:
796  *
797  * TK_MAPPED:			1 means window is currently mapped,
798  *				0 means unmapped.
799  * TK_TOP_LEVEL:		1 means this is a top-level widget.
800  * TK_ALREADY_DEAD:		1 means the window is in the process of
801  *				being destroyed already.
802  * TK_NEED_CONFIG_NOTIFY:	1 means that the window has been reconfigured
803  *				before it was made to exist. At the time of
804  *				making it exist a ConfigureNotify event needs
805  *				to be generated.
806  * TK_GRAB_FLAG:		Used to manage grabs. See tkGrab.c for details
807  * TK_CHECKED_IC:		1 means we've already tried to get an input
808  *				context for this window; if the ic field is
809  *				NULL it means that there isn't a context for
810  *				the field.
811  * TK_DONT_DESTROY_WINDOW:	1 means that Tk_DestroyWindow should not
812  *				invoke XDestroyWindow to destroy this widget's
813  *				X window. The flag is set when the window has
814  *				already been destroyed elsewhere (e.g. by
815  *				another application) or when it will be
816  *				destroyed later (e.g. by destroying its parent)
817  * TK_WM_COLORMAP_WINDOW:	1 means that this window has at some time
818  *				appeared in the WM_COLORMAP_WINDOWS property
819  *				for its toplevel, so we have to remove it from
820  *				that property if the window is deleted and the
821  *				toplevel isn't.
822  * TK_EMBEDDED:			1 means that this window (which must be a
823  *				toplevel) is not a free-standing window but
824  *				rather is embedded in some other application.
825  * TK_CONTAINER:		1 means that this window is a container, and
826  *				that some other application (either in this
827  *				process or elsewhere) may be embedding itself
828  *				inside the window.
829  * TK_BOTH_HALVES:		1 means that this window is used for
830  *				application embedding (either as container or
831  *				embedded application), and both the containing
832  *				and embedded halves are associated with
833  *				windows in this particular process.
834  * TK_DEFER_MODAL:		1 means that this window has deferred a modal
835  *				loop until all of the bindings for the current
836  *				event have been invoked.
837  * TK_WRAPPER:			1 means that this window is the extra wrapper
838  *				window created around a toplevel to hold the
839  *				menubar under Unix. See tkUnixWm.c for more
840  *				information.
841  * TK_REPARENTED:		1 means that this window has been reparented
842  *				so that as far as the window system is
843  *				concerned it isn't a child of its Tk parent.
844  *				Initially this is used only for special Unix
845  *				menubar windows.
846  * TK_ANONYMOUS_WINDOW:		1 means that this window has no name, and is
847  *				thus not accessible from Tk.
848  * TK_HAS_WRAPPER		1 means that this window has a wrapper window
849  * TK_WIN_MANAGED		1 means that this window is a child of the root
850  *				window, and is managed by the window manager.
851  * TK_TOP_HIERARCHY		1 means this window is at the top of a physical
852  *				window hierarchy within this process, i.e. the
853  *				window's parent either doesn't exist or is not
854  *				owned by this Tk application.
855  * TK_PROP_PROPCHANGE		1 means that PropertyNotify events in the
856  *				window's children should propagate up to this
857  *				window.
858  * TK_WM_MANAGEABLE		1 marks a window as capable of being converted
859  *				into a toplevel using [wm manage].
860  */
861 enum TK_MAPPED              = 1;
862 enum TK_TOP_LEVEL           = 2;
863 enum TK_ALREADY_DEAD        = 4;
864 enum TK_NEED_CONFIG_NOTIFY  = 8;
865 enum TK_GRAB_FLAG           = 0x10;
866 enum TK_CHECKED_IC          = 0x20;
867 enum TK_DONT_DESTROY_WINDOW = 0x40;
868 enum TK_WM_COLORMAP_WINDOW  = 0x80;
869 enum TK_EMBEDDED            = 0x100;
870 enum TK_CONTAINER           = 0x200;
871 enum TK_BOTH_HALVES         = 0x400;
872 enum TK_DEFER_MODAL         = 0x800;
873 enum TK_WRAPPER             = 0x1000;
874 enum TK_REPARENTED          = 0x2000;
875 enum TK_ANONYMOUS_WINDOW    = 0x4000;
876 enum TK_HAS_WRAPPER         = 0x8000;
877 enum TK_WIN_MANAGED         = 0x10000;
878 enum TK_TOP_HIERARCHY       = 0x20000;
879 enum TK_PROP_PROPCHANGE     = 0x40000;
880 enum TK_WM_MANAGEABLE       = 0x80000;
881 
882 /*
883  *--------------------------------------------------------------
884  *
885  * Macros for querying Tk_Window structures. See the manual entries for
886  * documentation.
887  *
888  *--------------------------------------------------------------
889  */
890 Display* Tk_Display(Tk_Window tkwin)
891 {
892 	return (*(cast(Tk_FakeWin*)tkwin)).display;
893 }
894 
895 int Tk_ScreenNumber(Tk_Window tkwin)
896 {
897 	return (*(cast(Tk_FakeWin*)tkwin)).screenNum;
898 }
899 
900 Screen* Tk_Screen(Tk_Window tkwin)
901 {
902 	return ScreenOfDisplay(Tk_Display(tkwin), Tk_ScreenNumber(tkwin));
903 }
904 
905 int Tk_Depth(Tk_Window tkwin)
906 {
907 	return (*(cast(Tk_FakeWin*)tkwin)).depth;
908 }
909 
910 Visual* Tk_Visual(Tk_Window tkwin)
911 {
912 	return (*(cast(Tk_FakeWin*)tkwin)).visual;
913 }
914 
915 Window Tk_WindowId(Tk_Window tkwin)
916 {
917 	return (*(cast(Tk_FakeWin*)tkwin)).window;
918 }
919 
920 const(char)* Tk_PathName(Tk_Window tkwin)
921 {
922 	return (*(cast(Tk_FakeWin*)tkwin)).pathName;
923 }
924 
925 Tk_Uid Tk_Name(Tk_Window tkwin)
926 {
927 	return (*(cast(Tk_FakeWin*)tkwin)).nameUid;
928 }
929 
930 Tk_Uid Tk_Class(Tk_Window tkwin)
931 {
932 	return (*(cast(Tk_FakeWin*)tkwin)).classUid;
933 }
934 
935 int Tk_X(Tk_Window tkwin)
936 {
937 	return Tk_Changes(tkwin).x;
938 }
939 
940 int Tk_Y(Tk_Window tkwin)
941 {
942 	return Tk_Changes(tkwin).y;
943 }
944 
945 int Tk_Width(Tk_Window tkwin)
946 {
947 	return Tk_Changes(tkwin).width;
948 }
949 
950 int Tk_Height(Tk_Window tkwin)
951 {
952 	return Tk_Changes(tkwin).height;
953 }
954 
955 XWindowChanges Tk_Changes(Tk_Window tkwin)
956 {
957 	return (*(cast(Tk_FakeWin*)tkwin)).changes;
958 }
959 
960 XSetWindowAttributes Tk_Attributes(Tk_Window tkwin)
961 {
962 	return (*(cast(Tk_FakeWin*)tkwin)).atts;
963 }
964 
965 uint Tk_IsEmbedded(Tk_Window tkwin)
966 {
967 	return (*(cast(Tk_FakeWin*)tkwin)).flags & TK_EMBEDDED;
968 }
969 
970 uint Tk_IsContainer(Tk_Window tkwin)
971 {
972 	return (*(cast(Tk_FakeWin*)tkwin)).flags & TK_CONTAINER;
973 }
974 
975 uint Tk_IsMapped(Tk_Window tkwin)
976 {
977 	return (*(cast(Tk_FakeWin*)tkwin)).flags & TK_MAPPED;
978 }
979 
980 uint Tk_IsTopLevel(Tk_Window tkwin)
981 {
982 	return (*(cast(Tk_FakeWin*)tkwin)).flags & TK_TOP_LEVEL;
983 }
984 
985 uint Tk_HasWrapper(Tk_Window tkwin)
986 {
987 	return (*(cast(Tk_FakeWin*)tkwin)).flags & TK_HAS_WRAPPER;
988 }
989 
990 uint Tk_WinManaged(Tk_Window tkwin)
991 {
992 	return (*(cast(Tk_FakeWin*)tkwin)).flags & TK_WIN_MANAGED;
993 }
994 
995 uint Tk_TopWinHierarchy(Tk_Window tkwin)
996 {
997 	return (*(cast(Tk_FakeWin*)tkwin)).flags & TK_TOP_HIERARCHY;
998 }
999 
1000 uint Tk_IsManageable(Tk_Window tkwin)
1001 {
1002 	return (*(cast(Tk_FakeWin*)tkwin)).flags & TK_WM_MANAGEABLE;
1003 }
1004 
1005 int Tk_ReqWidth(Tk_Window tkwin)
1006 {
1007 	return (*(cast(Tk_FakeWin*)tkwin)).reqWidth;
1008 }
1009 
1010 int Tk_ReqHeight(Tk_Window tkwin)
1011 {
1012 	return (*(cast(Tk_FakeWin*)tkwin)).reqHeight;
1013 }
1014 
1015 deprecated int Tk_InternalBorderWidth(Tk_Window tkwin)
1016 {
1017 	return (*(cast(Tk_FakeWin*)tkwin)).internalBorderLeft;
1018 }
1019 
1020 int Tk_InternalBorderLeft(Tk_Window tkwin)
1021 {
1022 	return (*(cast(Tk_FakeWin*)tkwin)).internalBorderLeft;
1023 }
1024 
1025 int Tk_InternalBorderRight(Tk_Window tkwin)
1026 {
1027 	return (*(cast(Tk_FakeWin*)tkwin)).internalBorderRight;
1028 }
1029 
1030 int Tk_InternalBorderTop(Tk_Window tkwin)
1031 {
1032 	return (*(cast(Tk_FakeWin*)tkwin)).internalBorderTop;
1033 }
1034 
1035 int Tk_InternalBorderBottom(Tk_Window tkwin)
1036 {
1037 	return (*(cast(Tk_FakeWin*)tkwin)).internalBorderBottom;
1038 }
1039 
1040 int Tk_MinReqWidth(Tk_Window tkwin)
1041 {
1042 	return (*(cast(Tk_FakeWin*)tkwin)).minReqWidth;
1043 }
1044 
1045 int Tk_MinReqHeight(Tk_Window tkwin)
1046 {
1047 	return (*(cast(Tk_FakeWin*)tkwin)).minReqHeight;
1048 }
1049 
1050 Tk_Window Tk_Parent(Tk_Window tkwin)
1051 {
1052 	return (*(cast(Tk_FakeWin*)tkwin)).parentPtr;
1053 }
1054 
1055 Colormap Tk_Colormap(Tk_Window tkwin)
1056 {
1057 	return Tk_Attributes(tkwin).colormap;
1058 }
1059 
1060 /*
1061  *--------------------------------------------------------------
1062  *
1063  * Procedure prototypes and structures used for defining new canvas items:
1064  *
1065  *--------------------------------------------------------------
1066  */
1067 enum Tk_State
1068 {
1069     TK_STATE_NULL = -1,
1070 	TK_STATE_ACTIVE,
1071 	TK_STATE_DISABLED,
1072     TK_STATE_NORMAL,
1073 	TK_STATE_HIDDEN,
1074 }
1075 
1076 struct Tk_SmoothMethod
1077 {
1078     const(char)* name;
1079 	extern(C) int function(Tk_Canvas canvas, double* pointPtr, int numPoints, int numSteps, XPoint[] xPoints, double[] dblPoints) nothrow coordProc;
1080 	extern(C) void function(Tcl_Interp* interp, Tk_Canvas canvas, double* coordPtr, int numPoints, int numSteps) nothrow postscriptProc;
1081 }
1082 
1083 enum USE_OLD_CANVAS = false;
1084 
1085 static if (USE_OLD_CANVAS)
1086 {
1087 	alias extern(C) int function(Tcl_Interp* interp, Tk_Canvas canvas, Tk_Item* itemPtr, int argc, const(char)** argv) nothrow Tk_ItemCreateProc;
1088 	alias extern(C) int function(Tcl_Interp* interp, Tk_Canvas canvas, Tk_Item* itemPtr, int argc, const(char)** argv, int flags) nothrow Tk_ItemConfigureProc;
1089 	alias extern(C) int function(Tcl_Interp* interp, Tk_Canvas canvas, Tk_Item* itemPtr, int argc, const(char)** argv) nothrow Tk_ItemCoordProc;
1090 }
1091 else
1092 {
1093 	alias extern(C) int function(Tcl_Interp* interp, Tk_Canvas canvas, Tk_Item* itemPtr, int argc, const(Tcl_Obj*)[] objv) nothrow Tk_ItemCreateProc;
1094 	alias extern(C) int function(Tcl_Interp* interp, Tk_Canvas canvas, Tk_Item* itemPtr, int argc, const(Tcl_Obj*)[] objv, int flags) nothrow Tk_ItemConfigureProc;
1095 	alias extern(C) int function(Tcl_Interp* interp, Tk_Canvas canvas, Tk_Item* itemPtr, int argc, const(Tcl_Obj*)[] argv) nothrow Tk_ItemCoordProc;
1096 }
1097 
1098 alias extern(C) void function(Tk_Canvas canvas, Tk_Item* itemPtr, Display* display) nothrow Tk_ItemDeleteProc;
1099 alias extern(C) void function(Tk_Canvas canvas, Tk_Item* itemPtr, Display* display, Drawable dst, int x, int y, int width, int height) nothrow Tk_ItemDisplayProc;
1100 alias extern(C) double function(Tk_Canvas canvas, Tk_Item* itemPtr, double* pointPtr) nothrow Tk_ItemPointProc;
1101 alias extern(C) int function(Tk_Canvas canvas, Tk_Item* itemPtr, double* rectPtr) nothrow Tk_ItemAreaProc;
1102 alias extern(C) int function(Tcl_Interp* interp, Tk_Canvas canvas, Tk_Item* itemPtr, int prepass) nothrow Tk_ItemPostscriptProc;
1103 alias extern(C) void function(Tk_Canvas canvas, Tk_Item* itemPtr, double originX, double originY, double scaleX, double scaleY) nothrow Tk_ItemScaleProc;
1104 alias extern(C) void function(Tk_Canvas canvas, Tk_Item* itemPtr, double deltaX, double deltaY) nothrow Tk_ItemTranslateProc;
1105 alias extern(C) int function(Tcl_Interp* interp, Tk_Canvas canvas, Tk_Item* itemPtr, const(char)* indexString, int* indexPtr) nothrow Tk_ItemIndexProc;
1106 alias extern(C) void function(Tk_Canvas canvas, Tk_Item* itemPtr, int index) nothrow Tk_ItemCursorProc;
1107 alias extern(C) int function(Tk_Canvas canvas, Tk_Item* itemPtr, int offset, const(char)* buffer, int maxBytes) nothrow Tk_ItemSelectionProc;
1108 alias extern(C) void function(Tk_Canvas canvas, Tk_Item* itemPtr, int beforeThis, const(char)* string) nothrow Tk_ItemInsertProc;
1109 alias extern(C) void function(Tk_Canvas canvas, Tk_Item* itemPtr, int first, int last) nothrow Tk_ItemDCharsProc;
1110 
1111 static if (!__NO_OLD_CONFIG)
1112 {
1113 	/*
1114 	 * Records of the following type are used to describe a type of item (e.g.
1115 	 * lines, circles, etc.) that can form part of a canvas widget.
1116 	 */
1117 	struct Tk_ItemType
1118 	{
1119 		/* The name of this type of item, such as
1120 		 * "line". */
1121 		const(char)* name;
1122 
1123 		/* Total amount of space needed for item's
1124 		 * record. */
1125 		int itemSize;
1126 
1127 		/* Procedure to create a new item of this
1128 		 * type. */
1129 		Tk_ItemCreateProc createProc;
1130 
1131 		/* Pointer to array of configuration specs for
1132 		 * this type. Used for returning configuration
1133 		 * info. */
1134 		Tk_ConfigSpec* configSpecs;
1135 
1136 		/* Procedure to call to change configuration
1137 		 * options. */
1138 		Tk_ItemConfigureProc configProc;
1139 
1140 		/* Procedure to call to get and set the item's
1141 		 * coordinates. */
1142 		Tk_ItemCoordProc coordProc;
1143 
1144 		/* Procedure to delete existing item of this
1145 		 * type. */
1146 		Tk_ItemDeleteProc deleteProc;
1147 
1148 		/* Procedure to display items of this type. */
1149 		Tk_ItemDisplayProc displayProc;
1150 
1151 		/* Non-zero means displayProc should be called
1152 		 * even when the item has been moved
1153 		 * off-screen. */
1154 		int alwaysRedraw;
1155 
1156 		/* Computes distance from item to a given
1157 		 * point. */
1158 		Tk_ItemPointProc pointProc;
1159 
1160 		/* Computes whether item is inside, outside,
1161 		 * or overlapping an area. */
1162 		Tk_ItemAreaProc areaProc;
1163 
1164 		/* Procedure to write a Postscript description
1165 		 * for items of this type. */
1166 		Tk_ItemPostscriptProc postscriptProc;
1167 
1168 		/* Procedure to rescale items of this type. */
1169 		Tk_ItemScaleProc scaleProc;
1170 
1171 		/* Procedure to translate items of this
1172 		 * type. */
1173 		Tk_ItemTranslateProc translateProc;
1174 
1175 		/* Procedure to determine index of indicated
1176 		 * character. NULL if item doesn't support
1177 		 * indexing. */
1178 		Tk_ItemIndexProc indexProc;
1179 
1180 		/* Procedure to set insert cursor posn to just
1181 		 * before a given position. */
1182 		Tk_ItemCursorProc icursorProc;
1183 
1184 		/* Procedure to return selection (in STRING
1185 		 * format) when it is in this item. */
1186 		Tk_ItemSelectionProc selectionProc;
1187 
1188 		/* Procedure to insert something into an
1189 		 * item. */
1190 		Tk_ItemInsertProc insertProc;
1191 
1192 		/* Procedure to delete characters from an
1193 		 * item. */
1194 		Tk_ItemDCharsProc dCharsProc;
1195 
1196 		/* Used to link types together into a list. */
1197 		Tk_ItemType* nextPtr;
1198 
1199 		/* Reserved for future extension. */
1200 		void* reserved1;
1201 
1202 		/* Carefully compatible with */
1203 		int reserved2;
1204 
1205 		/* Jan Nijtmans dash patch */
1206 		void* reserved3;
1207 		void* reserved4;
1208 	}
1209 }
1210 else
1211 {
1212 	struct Tk_ItemType;
1213 }
1214 
1215 /*
1216  * For each item in a canvas widget there exists one record with the following
1217  * structure. Each actual item is represented by a record with the following
1218  * stuff at its beginning, plus additional type-specific stuff after that.
1219  */
1220 enum TK_TAG_SPACE = 3;
1221 
1222 struct Tk_Item
1223 {
1224 	/* Unique identifier for this item (also
1225 	 * serves as first tag for item). */
1226 	int id;
1227 
1228 	/* Next in display list of all items in this
1229 	 * canvas. Later items in list are drawn on
1230 	 * top of earlier ones. */
1231 	Tk_Item* nextPtr;
1232 
1233 	/* Built-in space for limited # of tags. */
1234 	Tk_Uid[TK_TAG_SPACE] staticTagSpace;
1235 
1236 	/* Pointer to array of tags. Usually points to
1237 	 * staticTagSpace, but may point to malloc-ed
1238 	 * space if there are lots of tags. */
1239 	Tk_Uid* tagPtr;
1240 
1241 	/* Total amount of tag space available at
1242 	 * tagPtr. */
1243 	int tagSpace;
1244 
1245 	/* Number of tag slots actually used at
1246 	 * *tagPtr. */
1247 	int numTags;
1248 
1249 	/* Table of procedures that implement this
1250 	 * type of item. */
1251 	Tk_ItemType* typePtr;
1252 
1253 	/* Bounding box for item, in integer canvas
1254 	 * units. Set by item-specific code and
1255 	 * guaranteed to contain every pixel drawn in
1256 	 * item. Item area includes x1 and y1 but not
1257 	 * x2 and y2. */
1258 	int x1;
1259 	int y1;
1260 	int x2;
1261 	int y2;
1262 
1263 	/* Previous in display list of all items in
1264 	 * this canvas. Later items in list are drawn
1265 	 * just below earlier ones. */
1266 	Tk_Item* prevPtr;
1267 
1268 	/* State of item. */
1269 	Tk_State state;
1270 
1271 	/* reserved for future use */
1272 	void* reserved1;
1273 
1274 	/* Some flags used in the canvas */
1275 	int redraw_flags;
1276 
1277 	/*
1278 	 *------------------------------------------------------------------
1279 	 * Starting here is additional type-specific stuff; see the declarations
1280 	 * for individual types to see what is part of each type. The actual space
1281 	 * below is determined by the "itemInfoSize" of the type's Tk_ItemType
1282 	 * record.
1283 	 *------------------------------------------------------------------
1284 	 */
1285 }
1286 
1287 /*
1288  * Flag bits for canvases (redraw_flags):
1289  *
1290  * TK_ITEM_STATE_DEPENDANT -	1 means that object needs to be redrawn if the
1291  *				canvas state changes.
1292  * TK_ITEM_DONT_REDRAW - 	1 means that the object redraw is already been
1293  *				prepared, so the general canvas code doesn't
1294  *				need to do that any more.
1295  */
1296 enum TK_ITEM_STATE_DEPENDANT = 1;
1297 enum TK_ITEM_DONT_REDRAW     = 2;
1298 
1299 /*
1300  * The following structure provides information about the selection and the
1301  * insertion cursor. It is needed by only a few items, such as those that
1302  * display text. It is shared by the generic canvas code and the item-specific
1303  * code, but most of the fields should be written only by the canvas generic
1304  * code.
1305  */
1306 struct Tk_CanvasTextInfo
1307 {
1308 	/* Border and background for selected
1309 	 * characters. Read-only to items.*/
1310 	Tk_3DBorder selBorder;
1311 
1312 	/* Width of border around selection. Read-only
1313 	 * to items. */
1314 	int selBorderWidth;
1315 
1316 	/* Foreground color for selected text.
1317 	 * Read-only to items. */
1318 	XColor* selFgColorPtr;
1319 
1320 	/* Pointer to selected item. NULL means
1321 	 * selection isn't in this canvas. Writable by
1322 	 * items. */
1323 	Tk_Item* selItemPtr;
1324 
1325 	/* Character index of first selected
1326 	 * character. Writable by items. */
1327 	int selectFirst;
1328 
1329 	/* Character index of last selected character.
1330 	 * Writable by items. */
1331 	int selectLast;
1332 
1333 	/* Item corresponding to "selectAnchor": not
1334 	 * necessarily selItemPtr. Read-only to
1335 	 * items. */
1336 	Tk_Item* anchorItemPtr;
1337 
1338 	/* Character index of fixed end of selection
1339 	 * (i.e. "select to" operation will use this
1340 	 * as one end of the selection). Writable by
1341 	 * items. */
1342 	int selectAnchor;
1343 
1344 	/* Used to draw vertical bar for insertion
1345 	 * cursor. Read-only to items. */
1346 	Tk_3DBorder insertBorder;
1347 
1348 	/* Total width of insertion cursor. Read-only
1349 	 * to items. */
1350 	int insertWidth;
1351 
1352 	/* Width of 3-D border around insert cursor.
1353 	 * Read-only to items. */
1354 	int insertBorderWidth;
1355 
1356 	/* Item that currently has the input focus, or
1357 	 * NULL if no such item. Read-only to items. */
1358 	Tk_Item* focusItemPtr;
1359 
1360 	/* Non-zero means that the canvas widget has
1361 	 * the input focus. Read-only to items.*/
1362 	int gotFocus;
1363 
1364 	/* Non-zero means that an insertion cursor
1365 	 * should be displayed in focusItemPtr.
1366 	 * Read-only to items.*/
1367 	int cursorOn;
1368 }
1369 
1370 /*
1371  * Structures used for Dashing and Outline.
1372  */
1373 struct Tk_Dash
1374 {
1375     int number;
1376 
1377     static union pattern_
1378 	{
1379 		ubyte* pt;
1380 		ubyte[(ubyte*).sizeof] array;
1381     }
1382 	pattern_ pattern;
1383 }
1384 
1385 struct Tk_TSOffset
1386 {
1387     int flags;   /* Flags; see below for possible values */
1388     int xoffset; /* x offset */
1389     int yoffset; /* y offset */
1390 }
1391 
1392 /*
1393  * Bit fields in Tk_Offset->flags:
1394  */
1395 enum TK_OFFSET_INDEX    = 1;
1396 enum TK_OFFSET_RELATIVE = 2;
1397 enum TK_OFFSET_LEFT     = 4;
1398 enum TK_OFFSET_CENTER   = 8;
1399 enum TK_OFFSET_RIGHT    = 16;
1400 enum TK_OFFSET_TOP      = 32;
1401 enum TK_OFFSET_MIDDLE   = 64;
1402 enum TK_OFFSET_BOTTOM   = 128;
1403 
1404 struct Tk_Outline
1405 {
1406     GC gc;                  /* Graphics context. */
1407     double width;           /* Width of outline. */
1408     double activeWidth;     /* Width of outline. */
1409     double disabledWidth;   /* Width of outline. */
1410     int offset;             /* Dash offset. */
1411     Tk_Dash dash;           /* Dash pattern. */
1412     Tk_Dash activeDash;     /* Dash pattern if state is active. */
1413     Tk_Dash disabledDash;   /* Dash pattern if state is disabled. */
1414     void* reserved1;        /* Reserved for future expansion. */
1415     void* reserved2;
1416     void* reserved3;
1417     Tk_TSOffset tsoffset;   /* Stipple offset for outline. */
1418     XColor* color;          /* Outline color. */
1419     XColor* activeColor;    /* Outline color if state is active. */
1420     XColor* disabledColor;  /* Outline color if state is disabled. */
1421     Pixmap stipple;         /* Outline Stipple pattern. */
1422     Pixmap activeStipple;   /* Outline Stipple pattern if state is active. */
1423     Pixmap disabledStipple; /* Outline Stipple pattern if state is disabled. */
1424 }
1425 
1426 /*
1427  *--------------------------------------------------------------
1428  *
1429  * Procedure prototypes and structures used for managing images:
1430  *
1431  *--------------------------------------------------------------
1432  */
1433 enum USE_OLD_IMAGE = false;
1434 
1435 static if (USE_OLD_IMAGE)
1436 {
1437 	alias extern(C) int function(Tcl_Interp* interp, const(char)* name, int argc, const(char)** argv, Tk_ImageType* typePtr, Tk_ImageMaster master, ClientData* masterDataPtr) nothrow Tk_ImageCreateProc;
1438 }
1439 else
1440 {
1441 	alias extern(C) int function(Tcl_Interp* interp, const(char)* name, int objc, const(Tcl_Obj*)[] objv, Tk_ImageType* typePtr, Tk_ImageMaster master, ClientData* masterDataPtr) nothrow Tk_ImageCreateProc;
1442 }
1443 alias extern(C) ClientData function(Tk_Window tkwin, ClientData masterData) nothrow Tk_ImageGetProc;
1444 alias extern(C) void function(ClientData instanceData, Display* display, Drawable drawable, int imageX, int imageY, int width, int height, int drawableX, int drawableY) nothrow Tk_ImageDisplayProc;
1445 alias extern(C) void function(ClientData instanceData, Display* display) nothrow Tk_ImageFreeProc;
1446 alias extern(C) void function(ClientData masterData) nothrow Tk_ImageDeleteProc;
1447 alias extern(C) void function(ClientData clientData, int x, int y, int width, int height, int imageWidth, int imageHeight) nothrow Tk_ImageChangedProc;
1448 alias extern(C) int function(ClientData clientData, Tcl_Interp* interp, Tk_Window tkwin, Tk_PostscriptInfo psinfo, int x, int y, int width, int height, int prepass) nothrow Tk_ImagePostscriptProc;
1449 
1450 /*
1451  * The following structure represents a particular type of image (bitmap, xpm
1452  * image, etc.). It provides information common to all images of that type,
1453  * such as the type name and a collection of procedures in the image manager
1454  * that respond to various events. Each image manager is represented by one of
1455  * these structures.
1456  */
1457 struct Tk_ImageType
1458 {
1459 	/* Name of image type. */
1460 	const(char)* name;
1461 
1462 	/* Procedure to call to create a new image of
1463 	 * this type. */
1464 	Tk_ImageCreateProc createProc;
1465 
1466 	/* Procedure to call the first time
1467 	 * Tk_GetImage is called in a new way (new
1468 	 * visual or screen). */
1469 	Tk_ImageGetProc getProc;
1470 
1471 	/* Call to draw image, in response to
1472 	 * Tk_RedrawImage calls. */
1473 	Tk_ImageDisplayProc displayProc;
1474 
1475 	/* Procedure to call whenever Tk_FreeImage is
1476 	 * called to release an instance of an
1477 	 * image. */
1478 	Tk_ImageFreeProc freeProc;
1479 
1480 	/* Procedure to call to delete image. It will
1481 	 * not be called until after freeProc has been
1482 	 * called for each instance of the image. */
1483 	Tk_ImageDeleteProc deleteProc;
1484 
1485 	/* Procedure to call to produce postscript
1486 	 * output for the image. */
1487 	Tk_ImagePostscriptProc postscriptProc;
1488 
1489 	/* Next in list of all image types currently
1490 	 * known. Filled in by Tk, not by image
1491 	 * manager. */
1492 	Tk_ImageType* nextPtr;
1493 
1494 	/* reserved for future expansion */
1495 	void* reserved;
1496 }
1497 
1498 /*
1499  *--------------------------------------------------------------
1500  *
1501  * Additional definitions used to manage images of type "photo".
1502  *
1503  *--------------------------------------------------------------
1504  */
1505 
1506 /*
1507  * The following type is used to identify a particular photo image to be
1508  * manipulated:
1509  */
1510 alias void* Tk_PhotoHandle;
1511 
1512 /*
1513  * The following structure describes a block of pixels in memory:
1514  */
1515 struct Tk_PhotoImageBlock
1516 {
1517 	/* Pointer to the first pixel. */
1518 	ubyte* pixelPtr;
1519 
1520 	/* Width of block, in pixels. */
1521 	int width;
1522 
1523 	/* Height of block, in pixels. */
1524 	int height;
1525 
1526 	/* Address difference between corresponding
1527 	 * pixels in successive lines. */
1528 	int pitch;
1529 
1530 	/* Address difference between successive
1531 	 * pixels in the same line. */
1532 	int pixelSize;
1533 
1534 	/* Address differences between the red, green,
1535 	 * blue and alpha components of the pixel and
1536 	 * the pixel as a whole. */
1537 	int offset[4];
1538 }
1539 
1540 /*
1541  * The following values control how blocks are combined into photo images when
1542  * the alpha component of a pixel is not 255, a.k.a. the compositing rule.
1543  */
1544 enum TK_PHOTO_COMPOSITE_OVERLAY = 0;
1545 enum TK_PHOTO_COMPOSITE_SET     = 1;
1546 
1547 /*
1548  * Procedure prototypes and structures used in reading and writing photo
1549  * images:
1550  */
1551 static if (USE_OLD_IMAGE)
1552 {
1553 	alias extern(C) int function(Tcl_Channel chan, const(char)* fileName, const(char)* formatString, int* widthPtr, int* heightPtr) nothrow Tk_ImageFileMatchProc;
1554 	alias extern(C) int function(const(char)* string_, const(char)* formatString, int* widthPtr, int* heightPtr) nothrow Tk_ImageStringMatchProc;
1555 	alias extern(C) int function(Tcl_Interp* interp, Tcl_Channel chan, const(char)* fileName, const(char)* formatString, Tk_PhotoHandle imageHandle, int destX, int destY, int width, int height, int srcX, int srcY) nothrow Tk_ImageFileReadProc;
1556 	alias extern(C) int function(Tcl_Interp* interp, const(char)* string, const(char)* formatString, Tk_PhotoHandle imageHandle, int destX, int destY, int width, int height, int srcX, int srcY) nothrow Tk_ImageStringReadProc;
1557 	alias extern(C) int function(Tcl_Interp* interp, const(char)* fileName, const(char)* formatString, Tk_PhotoImageBlock* blockPtr) nothrow Tk_ImageFileWriteProc;
1558 	alias extern(C) int function(Tcl_Interp* interp, Tcl_DString* dataPtr, const(char)* formatString, Tk_PhotoImageBlock* blockPtr) nothrow Tk_ImageStringWriteProc;
1559 }
1560 else
1561 {
1562 	alias extern(C) int function(Tcl_Channel chan, const(char)* fileName, Tcl_Obj* format, int* widthPtr, int* heightPtr, Tcl_Interp* interp) nothrow Tk_ImageFileMatchProc;
1563 	alias extern(C) int function(Tcl_Obj* dataObj, Tcl_Obj* format, int* widthPtr, int* heightPtr, Tcl_Interp* interp) nothrow Tk_ImageStringMatchProc;
1564 	alias extern(C) int function(Tcl_Interp* interp, Tcl_Channel chan, const(char)* fileName, Tcl_Obj* format, Tk_PhotoHandle imageHandle, int destX, int destY, int width, int height, int srcX, int srcY) nothrow Tk_ImageFileReadProc;
1565 	alias extern(C) int function(Tcl_Interp* interp, Tcl_Obj* dataObj, Tcl_Obj* format, Tk_PhotoHandle imageHandle, int destX, int destY, int width, int height, int srcX, int srcY) nothrow Tk_ImageStringReadProc;
1566 	alias extern(C) int function(Tcl_Interp* interp, const(char)* fileName, Tcl_Obj* format, Tk_PhotoImageBlock* blockPtr) nothrow Tk_ImageFileWriteProc;
1567 	alias extern(C) int function(Tcl_Interp* interp, Tcl_Obj* format, Tk_PhotoImageBlock* blockPtr) nothrow Tk_ImageStringWriteProc;
1568 }
1569 
1570 /*
1571  * The following structure represents a particular file format for storing
1572  * images (e.g., PPM, GIF, JPEG, etc.). It provides information to allow image
1573  * files of that format to be recognized and read into a photo image.
1574  */
1575 struct Tk_PhotoImageFormat
1576 {
1577 	/* Name of image file format */
1578 	const(char)* name;
1579 
1580 	/* Procedure to call to determine whether an
1581 	 * image file matches this format. */
1582 	Tk_ImageFileMatchProc fileMatchProc;
1583 
1584 	/* Procedure to call to determine whether the
1585 	 * data in a string matches this format. */
1586 	Tk_ImageStringMatchProc stringMatchProc;
1587 
1588 	/* Procedure to call to read data from an
1589 	 * image file into a photo image. */
1590 	Tk_ImageFileReadProc fileReadProc;
1591 
1592 	/* Procedure to call to read data from a
1593 	 * string into a photo image. */
1594 	Tk_ImageStringReadProc stringReadProc;
1595 
1596 	/* Procedure to call to write data from a
1597 	 * photo image to a file. */
1598 	Tk_ImageFileWriteProc fileWriteProc;
1599 
1600 	/* Procedure to call to obtain a string
1601 	 * representation of the data in a photo
1602 	 * image.*/
1603 	Tk_ImageStringWriteProc stringWriteProc;
1604 
1605 	/* Next in list of all photo image formats
1606 	 * currently known. Filled in by Tk, not by
1607 	 * image format handler. */
1608 	Tk_PhotoImageFormat* nextPtr;
1609 }
1610 
1611 static if (USE_OLD_IMAGE)
1612 {
1613 	alias Tk_CreateOldImageType        = Tk_CreateImageType;
1614 	alias Tk_CreateOldPhotoImageFormat = Tk_CreatePhotoImageFormat;
1615 }
1616 
1617 /*
1618  *--------------------------------------------------------------
1619  *
1620  * Procedure prototypes and structures used for managing styles:
1621  *
1622  *--------------------------------------------------------------
1623  */
1624 
1625 /*
1626  * Style support version tag.
1627  */
1628 enum TK_STYLE_VERSION_1 = 0x1;
1629 enum TK_STYLE_VERSION   = TK_STYLE_VERSION_1;
1630 
1631 /*
1632  * The following structures and prototypes are used as static templates to
1633  * declare widget elements.
1634  */
1635 alias extern(C) void function(ClientData clientData, char* recordPtr, const(Tk_OptionSpec)** optionsPtr, Tk_Window tkwin, int width, int height, int inner, int* widthPtr, int* heightPtr) nothrow Tk_GetElementSizeProc;
1636 alias extern(C) void function(ClientData clientData, char* recordPtr, const(Tk_OptionSpec)** optionsPtr, Tk_Window tkwin, int x, int y, int width, int height, int inner, int* xPtr, int* yPtr, int* widthPtr, int* heightPtr) nothrow Tk_GetElementBoxProc;
1637 alias extern(C) int function(ClientData clientData, char* recordPtr, const(Tk_OptionSpec)** optionsPtr, Tk_Window tkwin) nothrow Tk_GetElementBorderWidthProc;
1638 alias extern(C) void function(ClientData clientData, char* recordPtr, const(Tk_OptionSpec)** optionsPtr, Tk_Window tkwin, Drawable d, int x, int y, int width, int height, int state) nothrow Tk_DrawElementProc;
1639 
1640 struct Tk_ElementOptionSpec
1641 {
1642 	/* Name of the required option. */
1643 	const(char)* name;
1644 
1645 	/* Accepted option type. TK_OPTION_END means
1646 	 * any. */
1647 	Tk_OptionType type;
1648 }
1649 
1650 struct Tk_ElementSpec
1651 {
1652 	/* Version of the style support. */
1653 	int version_;
1654 
1655 	/* Name of element. */
1656 	const(char)* name;
1657 
1658 	/* List of required options. Last one's name
1659 	 * must be NULL. */
1660 	Tk_ElementOptionSpec* options;
1661 
1662 	/* Compute the external (resp. internal) size
1663 	 * of the element from its desired internal
1664 	 * (resp. external) size. */
1665 	Tk_GetElementSizeProc getSize;
1666 
1667 	/* Compute the inscribed or bounding boxes
1668 	 * within a given area. */
1669 	Tk_GetElementBoxProc getBox;
1670 
1671 	/* Return the element's internal border width.
1672 	 * Mostly useful for widgets. */
1673 	Tk_GetElementBorderWidthProc getBorderWidth;
1674 
1675 	/* Draw the element in the given bounding
1676 	 * box. */
1677 	Tk_DrawElementProc draw;
1678 }
1679 
1680 /*
1681  * Element state flags. Can be OR'ed.
1682  */
1683 enum TK_ELEMENT_STATE_ACTIVE   = (1<<0);
1684 enum TK_ELEMENT_STATE_DISABLED = (1<<1);
1685 enum TK_ELEMENT_STATE_FOCUS    = (1<<2);
1686 enum TK_ELEMENT_STATE_PRESSED  = (1<<3);
1687 
1688 /*
1689  *--------------------------------------------------------------
1690  *
1691  * The definitions below provide backward compatibility for functions and
1692  * types related to event handling that used to be in Tk but have moved to
1693  * Tcl.
1694  *
1695  *--------------------------------------------------------------
1696  */
1697 alias TK_READABLE           = TCL_READABLE;
1698 alias TK_WRITABLE           = TCL_WRITABLE;
1699 alias TK_EXCEPTION          = TCL_EXCEPTION;
1700 alias TK_DONT_WAIT          = TCL_DONT_WAIT;
1701 alias TK_X_EVENTS           = TCL_WINDOW_EVENTS;
1702 alias TK_WINDOW_EVENTS      = TCL_WINDOW_EVENTS;
1703 alias TK_FILE_EVENTS        = TCL_FILE_EVENTS;
1704 alias TK_TIMER_EVENTS       = TCL_TIMER_EVENTS;
1705 alias TK_IDLE_EVENTS        = TCL_IDLE_EVENTS;
1706 alias TK_ALL_EVENTS         = TCL_ALL_EVENTS;
1707 alias Tk_IdleProc           = Tcl_IdleProc;
1708 alias Tk_FileProc           = Tcl_FileProc;
1709 alias Tk_TimerProc          = Tcl_TimerProc;
1710 alias Tk_TimerToken         = Tcl_TimerToken;
1711 alias Tk_BackgroundError    = Tcl_BackgroundError;
1712 alias Tk_CancelIdleCall     = Tcl_CancelIdleCall;
1713 alias Tk_CreateTimerHandler = Tcl_CreateTimerHandler;
1714 
1715 version(Posix)
1716 {
1717 	alias Tk_CreateFileHandler  = Tcl_CreateFileHandler;
1718 	alias Tk_DeleteFileHandler  = Tcl_DeleteFileHandler;
1719 }
1720 
1721 alias Tk_DeleteTimerHandler = Tcl_DeleteTimerHandler;
1722 alias Tk_DoOneEvent         = Tcl_DoOneEvent;
1723 alias Tk_DoWhenIdle         = Tcl_DoWhenIdle;
1724 alias Tk_Sleep              = Tcl_Sleep;
1725 
1726 /* Additional stuff that has moved to Tcl: */
1727 alias Tk_EventuallyFree = Tcl_EventuallyFree;
1728 alias Tk_FreeProc       = Tcl_FreeProc;
1729 alias Tk_Preserve       = Tcl_Preserve;
1730 alias Tk_Release        = Tcl_Release;
1731 
1732 /* Removed Tk_Main, use macro instead */
1733 void Tk_Main(int argc, const(char)** argv, Tcl_AppInitProc proc)
1734 {
1735 	Tk_MainEx(argc, argv, proc, Tcl_CreateInterp());
1736 }
1737 
1738 extern(C) const(char)* Tk_PkgInitStubsCheck (Tcl_Interp* interp, const(char)* version_, int exact) nothrow;
1739 
1740 enum USE_TK_STUBS = false;
1741 
1742 static if (USE_TK_STUBS)
1743 {
1744 	const(char)* Tk_InitStubs(Tcl_Interp* interp, const(char)* version_, int exact)
1745 	{
1746 		return Tk_PkgInitStubsCheck(interp, version_, exact);
1747 	}
1748 }
1749 else
1750 {
1751 	extern(C) const(char)* Tk_InitStubs(Tcl_Interp* interp, const(char)* version_, int exact) nothrow;
1752 }
1753 
1754 /*
1755  *--------------------------------------------------------------
1756  *
1757  * Additional procedure types defined by Tk.
1758  *
1759  *--------------------------------------------------------------
1760  */
1761 alias extern(C) int function(ClientData clientData, XErrorEvent* errEventPtr) nothrow Tk_ErrorProc;
1762 alias extern(C) void function(ClientData clientData, XEvent* eventPtr) nothrow Tk_EventProc;
1763 alias extern(C) int function(ClientData clientData, XEvent* eventPtr) nothrow Tk_GenericProc;
1764 alias extern(C) int function(Tk_Window tkwin, XEvent* eventPtr) nothrow Tk_ClientMessageProc;
1765 alias extern(C) int function(ClientData clientData, Tcl_Interp* interp, ubyte* portion) nothrow Tk_GetSelProc;
1766 alias extern(C) void function(ClientData clientData) nothrow Tk_LostSelProc;
1767 alias extern(C) Tk_RestrictAction function(ClientData clientData, XEvent* eventPtr) nothrow Tk_RestrictProc;
1768 alias extern(C) int function(ClientData clientData, int offset, ubyte* buffer, int maxBytes) nothrow Tk_SelectionProc;
1769 
1770 /*
1771  *--------------------------------------------------------------
1772  *
1773  * Platform independant exported procedures and variables.
1774  *
1775  *--------------------------------------------------------------
1776  */
1777 public import tcltk.tkdecls;