Debian Codegraph @

pTk/mTk/generic/tkObj.c

raw symbols SCIP
1 /*
2 * tkObj.c --
3 *
4 * This file contains procedures that implement the common Tk object
5 * types
6 *
7 * Copyright (c) 1997 Sun Microsystems, Inc.
8 *
9 * See the file "license.terms" for information on usage and redistribution
10 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 *
12 * RCS: @(#) $Id: tkObj.c,v 1.8 2003/01/28 20:39:16 jenglish Exp $
13 */
14
15 #include "tkInt.h"
16
17 /*
18 * The following structure is the internal representation for pixel objects.
19 */
20
21 typedef struct PixelRep {
22 double value;
23 int units;
24 Tk_Window tkwin;
25 int returnValue;
26 } PixelRep;
27
28 #define SIMPLE_PIXELREP(objPtr) \
29 (TclObjInternal(objPtr)->twoPtrValue.ptr2 == 0)
30
31 #define SET_SIMPLEPIXEL(objPtr, intval) \
32 TclObjInternal(objPtr)->twoPtrValue.ptr1 = (VOID *) (intval); \
33 TclObjInternal(objPtr)->twoPtrValue.ptr2 = 0
34
35 #define GET_SIMPLEPIXEL(objPtr) \
36 ((int) TclObjInternal(objPtr)->twoPtrValue.ptr1)
37
38 #define SET_COMPLEXPIXEL(objPtr, repPtr) \
39 TclObjInternal(objPtr)->twoPtrValue.ptr1 = 0; \
40 TclObjInternal(objPtr)->twoPtrValue.ptr2 = (VOID *) repPtr
41
42 #define GET_COMPLEXPIXEL(objPtr) \
43 ((PixelRep *) TclObjInternal(objPtr)->twoPtrValue.ptr2)
44
45
46 /*
47 * The following structure is the internal representation for mm objects.
48 */
49
50 typedef struct MMRep {
51 double value;
52 int units;
53 Tk_Window tkwin;
54 double returnValue;
55 } MMRep;
56
57 /*
58 * The following structure is the internal representation for window objects.
59 * A WindowRep caches name-to-window lookups. The cache is invalid
60 * if tkwin is NULL or if mainPtr->deletionEpoch does not match epoch.
61 */
62 typedef struct WindowRep {
63 Tk_Window tkwin; /* Cached window; NULL if not found */
64 TkMainInfo *mainPtr; /* MainWindow associated with tkwin */
65 long epoch; /* Value of mainPtr->deletionEpoch at last
66 * successful lookup. */
67 } WindowRep;
68
69 /*
70 * Prototypes for procedures defined later in this file:
71 */
72
73 static void DupMMInternalRep _ANSI_ARGS_((Tcl_Obj *srcPtr,
74 Tcl_Obj *copyPtr));
75 static void DupPixelInternalRep _ANSI_ARGS_((Tcl_Obj *srcPtr,
76 Tcl_Obj *copyPtr));
77 static void DupWindowInternalRep _ANSI_ARGS_((Tcl_Obj *srcPtr,
78 Tcl_Obj *copyPtr));
79 static void FreeMMInternalRep _ANSI_ARGS_((Tcl_Obj *objPtr));
80 static void FreePixelInternalRep _ANSI_ARGS_((Tcl_Obj *objPtr));
81 static void FreeWindowInternalRep _ANSI_ARGS_((Tcl_Obj *objPtr));
82 static void UpdateStringOfMM _ANSI_ARGS_((Tcl_Obj *objPtr));
83 static int SetMMFromAny _ANSI_ARGS_((Tcl_Interp *interp,
84 Tcl_Obj *objPtr));
85 static int SetPixelFromAny _ANSI_ARGS_((Tcl_Interp *interp,
86 Tcl_Obj *objPtr));
87 static int SetWindowFromAny _ANSI_ARGS_((Tcl_Interp *interp,
88 Tcl_Obj *objPtr));
89
90 /*
91 * The following structure defines the implementation of the "pixel"
92 * Tcl object, used for measuring distances. The pixel object remembers
93 * its initial display-independant settings.
94 */
95
96 static Tcl_ObjType pixelObjType = {
97 "pixel", /* name */
98 FreePixelInternalRep, /* freeIntRepProc */
99 DupPixelInternalRep, /* dupIntRepProc */
100 NULL, /* updateStringProc */
101 SetPixelFromAny /* setFromAnyProc */
102 };
103
104 /*
105 * The following structure defines the implementation of the "pixel"
106 * Tcl object, used for measuring distances. The pixel object remembers
107 * its initial display-independant settings.
108 */
109
110 static Tcl_ObjType mmObjType = {
111 "mm", /* name */
112 FreeMMInternalRep, /* freeIntRepProc */
113 DupMMInternalRep, /* dupIntRepProc */
114 UpdateStringOfMM, /* updateStringProc */
115 SetMMFromAny /* setFromAnyProc */
116 };
117
118 /*
119 * The following structure defines the implementation of the "window"
120 * Tcl object.
121 */
122
123 static Tcl_ObjType windowObjType = {
124 "window", /* name */
125 FreeWindowInternalRep, /* freeIntRepProc */
126 DupWindowInternalRep, /* dupIntRepProc */
127 NULL, /* updateStringProc */
128 SetWindowFromAny /* setFromAnyProc */
129 };
130
131
132
133 /*
134 *----------------------------------------------------------------------
135 *
136 * Tk_GetPixelsFromObj --
137 *
138 * Attempt to return a pixel value from the Tcl object "objPtr". If the
139 * object is not already a pixel value, an attempt will be made to convert
140 * it to one.
141 *
142 * Results:
143 * The return value is a standard Tcl object result. If an error occurs
144 * during conversion, an error message is left in the interpreter's
145 * result unless "interp" is NULL.
146 *
147 * Side effects:
148 * If the object is not already a pixel, the conversion will free
149 * any old internal representation.
150 *
151 *----------------------------------------------------------------------
152 */
153
154 int
155 Tk_GetPixelsFromObj(interp, tkwin, objPtr, intPtr)
156 Tcl_Interp *interp; /* Used for error reporting if not NULL. */
157 Tk_Window tkwin;
158 Tcl_Obj *objPtr; /* The object from which to get pixels. */
159 int *intPtr; /* Place to store resulting pixels. */
160 {
161 int result;
162 double d;
163 PixelRep *pixelPtr;
164 static double bias[] = {
165 1.0, 10.0, 25.4, 25.4 / 72.0
166 };
167
168 if (objPtr->typePtr != &pixelObjType) {
169 result = SetPixelFromAny(interp, objPtr);
170 if (result != TCL_OK) {
171 return result;
172 }
173 }
174
175 if (SIMPLE_PIXELREP(objPtr)) {
176 *intPtr = GET_SIMPLEPIXEL(objPtr);
177 } else {
178 pixelPtr = GET_COMPLEXPIXEL(objPtr);
179 if (pixelPtr->tkwin != tkwin) {
180 d = pixelPtr->value;
181 if (pixelPtr->units >= 0) {
182 d *= bias[pixelPtr->units] * WidthOfScreen(Tk_Screen(tkwin));
183 d /= WidthMMOfScreen(Tk_Screen(tkwin));
184 }
185 if (d < 0) {
186 pixelPtr->returnValue = (int) (d - 0.5);
187 } else {
188 pixelPtr->returnValue = (int) (d + 0.5);
189 }
190 pixelPtr->tkwin = tkwin;
191 }
192 *intPtr = pixelPtr->returnValue;
193 }
194 return TCL_OK;
195 }
196
197 /*
198 *----------------------------------------------------------------------
199 *
200 * FreePixelInternalRep --
201 *
202 * Deallocate the storage associated with a pixel object's internal
203 * representation.
204 *
205 * Results:
206 * None.
207 *
208 * Side effects:
209 * Frees objPtr's internal representation and sets objPtr's
210 * internalRep to NULL.
211 *
212 *----------------------------------------------------------------------
213 */
214
215 static void
216 FreePixelInternalRep(objPtr)
217 Tcl_Obj *objPtr; /* Pixel object with internal rep to free. */
218 {
219 PixelRep *pixelPtr;
220
221 if (!SIMPLE_PIXELREP(objPtr)) {
222 pixelPtr = GET_COMPLEXPIXEL(objPtr);
223 ckfree((char *) pixelPtr);
224 }
225 SET_SIMPLEPIXEL(objPtr, 0);
226 objPtr->typePtr = NULL;
227 }
228
229 /*
230 *----------------------------------------------------------------------
231 *
232 * DupPixelInternalRep --
233 *
234 * Initialize the internal representation of a pixel Tcl_Obj to a
235 * copy of the internal representation of an existing pixel object.
236 *
237 * Results:
238 * None.
239 *
240 * Side effects:
241 * copyPtr's internal rep is set to the pixel corresponding to
242 * srcPtr's internal rep.
243 *
244 *----------------------------------------------------------------------
245 */
246
247 static void
248 DupPixelInternalRep(srcObjPtr, copyObjPtr)
249 register Tcl_Obj *srcObjPtr; /* Object with internal rep to copy. */
250 register Tcl_Obj *copyObjPtr; /* Object with internal rep to set. */
251 {
252 PixelRep *oldPtr, *newPtr;
253
254 copyObjPtr->typePtr = srcObjPtr->typePtr;
255
256 if (SIMPLE_PIXELREP(srcObjPtr)) {
257 SET_SIMPLEPIXEL(copyObjPtr, GET_SIMPLEPIXEL(srcObjPtr));
258 } else {
259 oldPtr = GET_COMPLEXPIXEL(srcObjPtr);
260 newPtr = (PixelRep *) ckalloc(sizeof(PixelRep));
261 newPtr->value = oldPtr->value;
262 newPtr->units = oldPtr->units;
263 newPtr->tkwin = oldPtr->tkwin;
264 newPtr->returnValue = oldPtr->returnValue;
265 SET_COMPLEXPIXEL(copyObjPtr, newPtr);
266 }
267 }
268
269 /*
270 *----------------------------------------------------------------------
271 *
272 * SetPixelFromAny --
273 *
274 * Attempt to generate a pixel internal form for the Tcl object
275 * "objPtr".
276 *
277 * Results:
278 * The return value is a standard Tcl result. If an error occurs during
279 * conversion, an error message is left in the interpreter's result
280 * unless "interp" is NULL.
281 *
282 * Side effects:
283 * If no error occurs, a pixel representation of the object is
284 * stored internally and the type of "objPtr" is set to pixel.
285 *
286 *----------------------------------------------------------------------
287 */
288
289 static int
290 SetPixelFromAny(interp, objPtr)
291 Tcl_Interp *interp; /* Used for error reporting if not NULL. */
292 Tcl_Obj *objPtr; /* The object to convert. */
293 {
294 Tcl_ObjType *typePtr;
295 char *string, *rest;
296 double d;
297 int i, units;
298 PixelRep *pixelPtr;
299
300 string = Tcl_GetStringFromObj(objPtr, NULL);
301
302 d = strtod(string, &rest);
303 if (rest == string) {
304 /*
305 * Must copy string before resetting the result in case a caller
306 * is trying to convert the interpreter's result to pixels.
307 */
308
309 char buf[100];
310
311 error:
312 sprintf(buf, "bad screen distance \"%.50s\"", string);
313 Tcl_ResetResult(interp);
314 Tcl_AppendResult(interp, buf, NULL);
315 return TCL_ERROR;
316 }
317 while ((*rest != '\0') && isspace(UCHAR(*rest))) {
318 rest++;
319 }
320 switch (*rest) {
321 case '\0':
322 units = -1;
323 break;
324
325 case 'm':
326 units = 0;
327 break;
328
329 case 'c':
330 units = 1;
331 break;
332
333 case 'i':
334 units = 2;
335 break;
336
337 case 'p':
338 units = 3;
339 break;
340
341 default:
342 goto error;
343 }
344
345 /*
346 * Free the old internalRep before setting the new one.
347 */
348
349 typePtr = objPtr->typePtr;
350 if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) {
351 (*typePtr->freeIntRepProc)(objPtr);
352 }
353
354 TclObjSetType(objPtr,&pixelObjType);
355
356 i = (int) d;
357 if ((units < 0) && (i == d)) {
358 SET_SIMPLEPIXEL(objPtr, i);
359 } else {
360 pixelPtr = (PixelRep *) ckalloc(sizeof(PixelRep));
361 pixelPtr->value = d;
362 pixelPtr->units = units;
363 pixelPtr->tkwin = NULL;
364 pixelPtr->returnValue = i;
365 SET_COMPLEXPIXEL(objPtr, pixelPtr);
366 }
367 return TCL_OK;
368 }
369
370 /*
371 *----------------------------------------------------------------------
372 *
373 * Tk_GetMMFromObj --
374 *
375 * Attempt to return an mm value from the Tcl object "objPtr". If the
376 * object is not already an mm value, an attempt will be made to convert
377 * it to one.
378 *
379 * Results:
380 * The return value is a standard Tcl object result. If an error occurs
381 * during conversion, an error message is left in the interpreter's
382 * result unless "interp" is NULL.
383 *
384 * Side effects:
385 * If the object is not already a pixel, the conversion will free
386 * any old internal representation.
387 *
388 *----------------------------------------------------------------------
389 */
390
391 int
392 Tk_GetMMFromObj(interp, tkwin, objPtr, doublePtr)
393 Tcl_Interp *interp; /* Used for error reporting if not NULL. */
394 Tk_Window tkwin;
395 Tcl_Obj *objPtr; /* The object from which to get mms. */
396 double *doublePtr; /* Place to store resulting millimeters. */
397 {
398 int result;
399 double d;
400 MMRep *mmPtr;
401 static double bias[] = {
402 10.0, 25.4, 1.0, 25.4 / 72.0
403 };
404
405 if (objPtr->typePtr != &mmObjType) {
406 result = SetMMFromAny(interp, objPtr);
407 if (result != TCL_OK) {
408 return result;
409 }
410 }
411
412 mmPtr = (MMRep *) objPtr->internalRep.otherValuePtr;
413 if (mmPtr->tkwin != tkwin) {
414 d = mmPtr->value;
415 if (mmPtr->units == -1) {
416 d /= WidthOfScreen(Tk_Screen(tkwin));
417 d *= WidthMMOfScreen(Tk_Screen(tkwin));
418 } else {
419 d *= bias[mmPtr->units];
420 }
421 mmPtr->tkwin = tkwin;
422 mmPtr->returnValue = d;
423 }
424 *doublePtr = mmPtr->returnValue;
425
426 return TCL_OK;
427 }
428
429 /*
430 *----------------------------------------------------------------------
431 *
432 * FreeMMInternalRep --
433 *
434 * Deallocate the storage associated with a mm object's internal
435 * representation.
436 *
437 * Results:
438 * None.
439 *
440 * Side effects:
441 * Frees objPtr's internal representation and sets objPtr's
442 * internalRep to NULL.
443 *
444 *----------------------------------------------------------------------
445 */
446
447 static void
448 FreeMMInternalRep(objPtr)
449 Tcl_Obj *objPtr; /* MM object with internal rep to free. */
450 {
451 ckfree((char *) objPtr->internalRep.otherValuePtr);
452 objPtr->internalRep.otherValuePtr = NULL;
453 objPtr->typePtr = NULL;
454 }
455
456 /*
457 *----------------------------------------------------------------------
458 *
459 * DupMMInternalRep --
460 *
461 * Initialize the internal representation of a pixel Tcl_Obj to a
462 * copy of the internal representation of an existing pixel object.
463 *
464 * Results:
465 * None.
466 *
467 * Side effects:
468 * copyPtr's internal rep is set to the pixel corresponding to
469 * srcPtr's internal rep.
470 *
471 *----------------------------------------------------------------------
472 */
473
474 static void
475 DupMMInternalRep(srcObjPtr, copyObjPtr)
476 register Tcl_Obj *srcObjPtr; /* Object with internal rep to copy. */
477 register Tcl_Obj *copyObjPtr; /* Object with internal rep to set. */
478 {
479 MMRep *oldPtr, *newPtr;
480
481 copyObjPtr->typePtr = srcObjPtr->typePtr;
482 oldPtr = (MMRep *) srcObjPtr->internalRep.otherValuePtr;
483 newPtr = (MMRep *) ckalloc(sizeof(MMRep));
484 newPtr->value = oldPtr->value;
485 newPtr->units = oldPtr->units;
486 newPtr->tkwin = oldPtr->tkwin;
487 newPtr->returnValue = oldPtr->returnValue;
488 copyObjPtr->internalRep.otherValuePtr = (VOID *) newPtr;
489 }
490
491 /*
492 *----------------------------------------------------------------------
493 *
494 * UpdateStringOfMM --
495 *
496 * Update the string representation for a pixel Tcl_Obj
497 * this function is only called, if the pixel Tcl_Obj has no unit,
498 * because with units the string representation is created by
499 * SetMMFromAny
500 *
501 * Results:
502 * None.
503 *
504 * Side effects:
505 * The object's string is set to a valid string that results from
506 * the double-to-string conversion.
507 *
508 *----------------------------------------------------------------------
509 */
510
511 static void
512 UpdateStringOfMM(objPtr)
513 register Tcl_Obj *objPtr; /* pixel obj with string rep to update. */
514 {
515 #ifndef _LANG
516 MMRep *mmPtr;
517 char buffer[TCL_DOUBLE_SPACE];
518 register int len;
519
520 mmPtr = (MMRep *) objPtr->internalRep.otherValuePtr;
521 /* assert( mmPtr->units == -1 && objPtr->bytes == NULL ); */
522 if ((mmPtr->units != -1) || (objPtr->bytes != NULL)) {
523 panic("UpdateStringOfMM: false precondition");
524 }
525
526 Tcl_PrintDouble((Tcl_Interp *) NULL, mmPtr->value, buffer);
527 len = strlen(buffer);
528
529 objPtr->bytes = (char *) ckalloc((unsigned) len + 1);
530 strcpy(objPtr->bytes, buffer);
531 objPtr->length = len;
532 #else
533 /* FIXME */
534 abort();
535 #endif
536 }
537
538 /*
539 *----------------------------------------------------------------------
540 *
541 * SetMMFromAny --
542 *
543 * Attempt to generate a mm internal form for the Tcl object
544 * "objPtr".
545 *
546 * Results:
547 * The return value is a standard Tcl result. If an error occurs during
548 * conversion, an error message is left in the interpreter's result
549 * unless "interp" is NULL.
550 *
551 * Side effects:
552 * If no error occurs, a mm representation of the object is
553 * stored internally and the type of "objPtr" is set to mm.
554 *
555 *----------------------------------------------------------------------
556 */
557
558 static int
559 SetMMFromAny(interp, objPtr)
560 Tcl_Interp *interp; /* Used for error reporting if not NULL. */
561 Tcl_Obj *objPtr; /* The object to convert. */
562 {
563 Tcl_ObjType *typePtr;
564 char *string, *rest;
565 double d;
566 int units;
567 MMRep *mmPtr;
568
569 static Tcl_ObjType *tclDoubleObjType = NULL;
570 static Tcl_ObjType *tclIntObjType = NULL;
571
572 if (tclDoubleObjType == NULL) {
573 /*
574 * Cache the object types for comaprison below.
575 * This allows optimized checks for standard cases.
576 */
577
578 tclDoubleObjType = Tcl_GetObjType("double");
579 tclIntObjType = Tcl_GetObjType("int");
580 }
581
582 if (objPtr->typePtr == tclDoubleObjType) {
583 Tcl_GetDoubleFromObj(interp, objPtr, &d);
584 units = -1;
585 } else if (objPtr->typePtr == tclIntObjType) {
586 Tcl_GetIntFromObj(interp, objPtr, &units);
587 d = (double) units;
588 units = -1;
589
590 /*
591 * In the case of ints, we need to ensure that a valid
592 * string exists in order for int-but-not-string objects
593 * to be converted back to ints again from mm obj types.
594 */
595 (void) Tcl_GetStringFromObj(objPtr, NULL);
596 } else {
597 /*
598 * It wasn't a known int or double, so parse it.
599 */
600
601 string = Tcl_GetStringFromObj(objPtr, NULL);
602
603 d = strtod(string, &rest);
604 if (rest == string) {
605 /*
606 * Must copy string before resetting the result in case a caller
607 * is trying to convert the interpreter's result to mms.
608 */
609
610 error:
611 Tcl_AppendResult(interp, "bad screen distance \"", string,
612 "\"", (char *) NULL);
613 return TCL_ERROR;
614 }
615 while ((*rest != '\0') && isspace(UCHAR(*rest))) {
616 rest++;
617 }
618 switch (*rest) {
619 case '\0':
620 units = -1;
621 break;
622
623 case 'c':
624 units = 0;
625 break;
626
627 case 'i':
628 units = 1;
629 break;
630
631 case 'm':
632 units = 2;
633 break;
634
635 case 'p':
636 units = 3;
637 break;
638
639 default:
640 goto error;
641 }
642 }
643
644 /*
645 * Free the old internalRep before setting the new one.
646 */
647
648 typePtr = objPtr->typePtr;
649 if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) {
650 (*typePtr->freeIntRepProc)(objPtr);
651 }
652
653 objPtr->typePtr = &mmObjType;
654
655 mmPtr = (MMRep *) ckalloc(sizeof(MMRep));
656 mmPtr->value = d;
657 mmPtr->units = units;
658 mmPtr->tkwin = NULL;
659 mmPtr->returnValue = d;
660
661 objPtr->internalRep.otherValuePtr = (VOID *) mmPtr;
662
663 return TCL_OK;
664 }
665
666 /*
667 *----------------------------------------------------------------------
668 *
669 * TkGetWindowFromObj --
670 *
671 * Attempt to return a Tk_Window from the Tcl object "objPtr". If the
672 * object is not already a Tk_Window, an attempt will be made to convert
673 * it to one.
674 *
675 * Results:
676 * The return value is a standard Tcl object result. If an error occurs
677 * during conversion, an error message is left in the interpreter's
678 * result unless "interp" is NULL.
679 *
680 * Side effects:
681 * If the object is not already a Tk_Window, the conversion will free
682 * any old internal representation.
683 *
684 *----------------------------------------------------------------------
685 */
686
687 int
688 TkGetWindowFromObj(interp, tkwin, objPtr, windowPtr)
689 Tcl_Interp *interp; /* Used for error reporting if not NULL. */
690 Tk_Window tkwin; /* A token to get the main window from. */
691 Tcl_Obj *objPtr; /* The object from which to get window. */
692 Tk_Window *windowPtr; /* Place to store resulting window. */
693 {
694 TkMainInfo *mainPtr = ((TkWindow *)tkwin)->mainPtr;
695 register WindowRep *winPtr;
696 int result;
697
698 result = Tcl_ConvertToType(interp, objPtr, &windowObjType);
699 if (result != TCL_OK) {
700 return result;
701 }
702
703 winPtr = (WindowRep *) objPtr->internalRep.otherValuePtr;
704 if ( winPtr->tkwin == NULL
705 || winPtr->mainPtr == NULL
706 || winPtr->mainPtr != mainPtr
707 || winPtr->epoch != mainPtr->deletionEpoch)
708 {
709 /* Cache is invalid.
710 */
711 winPtr->tkwin = Tk_NameToWindow(interp,
712 Tcl_GetStringFromObj(objPtr, NULL), tkwin);
713 winPtr->mainPtr = mainPtr;
714 winPtr->epoch = mainPtr ? mainPtr->deletionEpoch : 0;
715 }
716
717 *windowPtr = winPtr->tkwin;
718
719 if (winPtr->tkwin == NULL) {
720 /* ASSERT: Tk_NameToWindow has left error message in interp */
721 return TCL_ERROR;
722 }
723 return TCL_OK;
724 }
725
726 /*
727 *----------------------------------------------------------------------
728 *
729 * SetWindowFromAny --
730 * Generate a windowObj internal form for the Tcl object "objPtr".
731 *
732 * Results:
733 * Always returns TCL_OK.
734 *
735 * Side effects:
736 * Sets objPtr's internal representation to an uninitialized
737 * windowObj. Frees the old internal representation, if any.
738 *
739 * See also:
740 * TkGetWindowFromObj, which initializes the WindowRep cache.
741 *
742 *----------------------------------------------------------------------
743 */
744
745 static int
746 SetWindowFromAny(interp, objPtr)
747 Tcl_Interp *interp; /* Used for error reporting if not NULL. */
748 register Tcl_Obj *objPtr; /* The object to convert. */
749 {
750 Tcl_ObjType *typePtr;
751 WindowRep *winPtr;
752
753 /*
754 * Free the old internalRep before setting the new one.
755 */
756
757 Tcl_GetStringFromObj(objPtr, NULL);
758 typePtr = objPtr->typePtr;
759 if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) {
760 (*typePtr->freeIntRepProc)(objPtr);
761 }
762
763 winPtr = (WindowRep *) ckalloc(sizeof(WindowRep));
764 winPtr->tkwin = NULL;
765 winPtr->mainPtr = NULL;
766 winPtr->epoch = 0;
767
768 objPtr->internalRep.otherValuePtr = (VOID*)winPtr;
769 TclObjSetType(objPtr,&windowObjType);
770
771 return TCL_OK;
772 }
773
774 /*
775 *----------------------------------------------------------------------
776 *
777 * DupWindowInternalRep --
778 *
779 * Initialize the internal representation of a window Tcl_Obj to a
780 * copy of the internal representation of an existing window object.
781 *
782 * Results:
783 * None.
784 *
785 * Side effects:
786 * copyPtr's internal rep is set to refer to the same window as
787 * srcPtr's internal rep.
788 *
789 *----------------------------------------------------------------------
790 */
791
792 static void
793 DupWindowInternalRep(srcObjPtr, copyObjPtr)
794 register Tcl_Obj *srcObjPtr;
795 register Tcl_Obj *copyObjPtr;
796 {
797 register WindowRep *oldPtr, *newPtr;
798
799 oldPtr = srcObjPtr->internalRep.otherValuePtr;
800 newPtr = (WindowRep *) ckalloc(sizeof(WindowRep));
801 newPtr->tkwin = oldPtr->tkwin;
802 newPtr->mainPtr = oldPtr->mainPtr;
803 newPtr->epoch = oldPtr->epoch;
804 copyObjPtr->internalRep.otherValuePtr = (VOID *)newPtr;
805 copyObjPtr->typePtr = srcObjPtr->typePtr;
806 }
807
808 /*
809 *----------------------------------------------------------------------
810 *
811 * FreeWindowInternalRep --
812 *
813 * Deallocate the storage associated with a window object's internal
814 * representation.
815 *
816 * Results:
817 * None.
818 *
819 * Side effects:
820 * Frees objPtr's internal representation and sets objPtr's
821 * internalRep to NULL.
822 *
823 *----------------------------------------------------------------------
824 */
825
826 static void
827 FreeWindowInternalRep(objPtr)
828 Tcl_Obj *objPtr; /* Window object with internal rep to free. */
829 {
830 ckfree((char *) objPtr->internalRep.otherValuePtr);
831 objPtr->internalRep.otherValuePtr = NULL;
832 objPtr->typePtr = NULL;
833 }
834
835 /*
836 *----------------------------------------------------------------------
837 *
838 * TkRegisterObjTypes --
839 *
840 * Registers Tk's Tcl_ObjType structures with the Tcl run-time.
841 *
842 * Results:
843 * None
844 *
845 * Side effects:
846 * All instances of Tcl_ObjType structues used in Tk are registered
847 * with Tcl.
848 *
849 *----------------------------------------------------------------------
850 */
851
852 void
853 TkRegisterObjTypes()
854 {
855 Tcl_RegisterObjType(&tkBorderObjType);
856 Tcl_RegisterObjType(&tkBitmapObjType);
857 Tcl_RegisterObjType(&tkColorObjType);
858 Tcl_RegisterObjType(&tkCursorObjType);
859 Tcl_RegisterObjType(&tkFontObjType);
860 Tcl_RegisterObjType(&mmObjType);
861 Tcl_RegisterObjType(&tkOptionObjType);
862 Tcl_RegisterObjType(&pixelObjType);
863 Tcl_RegisterObjType(&tkStateKeyObjType);
864 Tcl_RegisterObjType(&windowObjType);
865 }
866
867