Debian Codegraph @

pTk/mTk/tixGeneric/tixImgCmp.c

raw symbols SCIP
1
2 /* $Id: tixImgCmp.c,v 1.3 2000/10/17 16:41:56 idiscovery Exp $ */
3
4 /*
5 * tkImgCmp.c --
6 *
7 * This procedure implements images of type "compound" for Tix.
8 *
9 * Copyright (c) 1996, Expert Interface Technologies
10 *
11 * See the file "license.terms" for information on usage and redistribution
12 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13 *
14 */
15 #include "tkInt.h"
16 #include "tixPort.h"
17 #include "tixInt.h"
18 #include "tixDef.h"
19 #include "tkVMacro.h"
20
21 /* Should use USE_OLD_IMAGE ImgCmpCreate */
22 #if (TCL_MAJOR_VERSION <= 7)
23 # define USE_OLD_IMAGE
24 #else
25 # if ((TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION <= 2))
26 # define USE_OLD_IMAGE
27 # endif
28 /* Otherwise use tk.h's definition */
29 #endif
30
31 /*
32 * ToDo:
33 * - lineconfig and itemconfig command
34 */
35
36 /*
37 * The following data structure represents the master for a bitmap
38 * image:
39 */
40 typedef struct CmpMaster {
41 Tk_ImageMaster tkMaster; /* Tk's token for image master. NULL means
42 * the image is being deleted. */
43 Tcl_Interp *interp; /* Interpreter for application that is
44 * using image. */
45 Tcl_Command imageCmd; /* Token for image command (used to delete
46 * it when the image goes away). NULL means
47 * the image command has already been
48 * deleted. */
49 Display * display; /* Display of the the window associated with
50 * this image. We need to keep it
51 * because Tk_Display(CmpMaster.tkwin) may
52 * be invalid. */
53 Tk_Window tkwin; /* default options are taken from this window.
54 * If undefined, will use the main window
55 * of this application */
56 int width, height; /* Dimensions of image. */
57 int padX, padY;
58 struct CmpLine * lineHead;
59 struct CmpLine * lineTail;
60
61 /* Thde default options, etc */
62 int borderWidth; /* Width of 3-D borders. */
63 Tk_3DBorder background; /* Used for drawing background. */
64 int relief; /* Indicates whether window as a whole is
65 * raised, sunken, or flat. */
66
67 TixFont font; /* Information about text font.*/
68 XColor *foreground; /* Color for drawing text and bitmaps */
69 GC gc; /* default GC for drawing text. */
70
71 int showBackground; /* whether the background should be drawn */
72 unsigned int changing; /* is this image going to call Tk_ImageChanged
73 * in an idle event? */
74 unsigned int isDeleted;
75
76 int winCount; /* Number of windows using image */
77 } CmpMaster;
78
79 /* This is the per-instance data - this is currently minimal
80 it should really have all Display/Visual related stuff like
81 GCs, Pixmaps etc. so that master is window independant.
82 Instead we check (a bit) that instance tkwin is "compatible"
83 with the one specified on the master.
84 */
85
86 typedef struct CmpInstance {
87 CmpMaster *master; /* Master data */
88 Tk_Window tkwin; /* Window where used */
89 } CmpInstance;
90
91 #define TYPE_TEXT 0
92 #define TYPE_SPACE 1
93 #define TYPE_IMAGE 2
94 #define TYPE_BITMAP 3
95 #define TYPE_WIDGET 4
96
97 typedef struct CmpLine {
98 struct CmpMaster *masterPtr;
99 struct CmpLine * next;
100 struct CmpItem * itemHead;
101 struct CmpItem * itemTail;
102 int padX, padY;
103 Tk_Anchor anchor;
104 int width, height; /* Dimensions of this line. */
105 } CmpLine;
106
107 /* abstract type */
108
109 #define COMMON_MEMBERS \
110 struct CmpLine * line; \
111 struct CmpItem * next; \
112 Tk_Anchor anchor; \
113 char type; \
114 int width; \
115 int height; \
116 int padX, padY
117
118 typedef struct CmpItem {
119 COMMON_MEMBERS;
120 } CmpItem;
121
122 typedef struct CmpBitmapItem {
123 COMMON_MEMBERS;
124
125 Pixmap bitmap;
126 XColor *foreground;
127 XColor *background;
128 GC gc; /* GC for drawing the bitmap. */
129 } CmpBitmapItem;
130
131 typedef struct CmpImageItem {
132 COMMON_MEMBERS;
133
134 Tk_Image image;
135 char * imageString;
136 } CmpImageItem;
137
138 typedef struct CmpSpaceItem {
139 COMMON_MEMBERS;
140
141 } CmpSpaceItem;
142
143 typedef struct CmpTextItem {
144 COMMON_MEMBERS;
145
146 char * text;
147 int numChars;
148 Tk_Justify justify; /* Justification to use for multi-line text. */
149 int wrapLength;
150 int underline; /* Index of character to underline. < 0 means
151 * don't underline anything. */
152 XColor *foreground;
153 TixFont font; /* Information about text font, or NULL. */
154 GC gc; /* GC for drawing the bitmap. */
155 } CmpTextItem;
156
157 typedef union CmpItemPtr {
158 CmpItem * item;
159 CmpBitmapItem * bitmap;
160 CmpImageItem * image;
161 CmpSpaceItem * space;
162 CmpTextItem * text;
163 } CmpItemPtr;
164
165 /*
166 * The type record for bitmap images:
167 */
168 static int ImgCmpCreate _ANSI_ARGS_((Tcl_Interp *interp,
169 char *name, int argc, Tcl_Obj *CONST *objv,
170 Tk_ImageType *typePtr, Tk_ImageMaster master,
171 ClientData *clientDataPtr));
172 static ClientData ImgCmpGet _ANSI_ARGS_((Tk_Window tkwin,
173 ClientData clientData));
174 static void ImgCmpDisplay _ANSI_ARGS_((ClientData clientData,
175 Display *display, Drawable drawable,
176 int imageX, int imageY, int width, int height,
177 int drawableX, int drawableY));
178 static void ImgCmpFree _ANSI_ARGS_((ClientData clientData,
179 Display *display));
180 static void ImgCmpDelete _ANSI_ARGS_((ClientData clientData));
181 static void ImgCmpFreeResources _ANSI_ARGS_((ClientData clientData));
182 static void CalculateMasterSize _ANSI_ARGS_((ClientData clientData));
183
184 Tk_ImageType tixCompoundImageType = {
185 "compound", /* name */
186 ImgCmpCreate, /* createProc */
187 ImgCmpGet, /* getProc */
188 ImgCmpDisplay, /* displayProc */
189 ImgCmpFree, /* freeProc */
190 ImgCmpDelete, /* deleteProc */
191 NULL, /* postscriptProc */
192 (Tk_ImageType *) NULL /* nextPtr */
193 };
194
195 static Tk_ConfigSpec configSpecs[] = {
196 {TK_CONFIG_BORDER, "-background", "background", "Background",
197 DEF_CMPIMAGE_BG_COLOR, Tk_Offset(CmpMaster, background),
198 TK_CONFIG_COLOR_ONLY},
199
200 {TK_CONFIG_BORDER, "-background", "background", "Background",
201 DEF_CMPIMAGE_BG_MONO, Tk_Offset(CmpMaster, background),
202 TK_CONFIG_MONO_ONLY},
203
204 {TK_CONFIG_SYNONYM, "-bd", "borderWidth", (char *) NULL,
205 (char *) NULL, 0, 0},
206
207 {TK_CONFIG_SYNONYM, "-bg", "background", (char *) NULL,
208 (char *) NULL, 0, 0},
209
210 {TK_CONFIG_PIXELS, "-borderwidth", "borderWidth", (char *) NULL,
211 "0", Tk_Offset(CmpMaster, borderWidth), 0},
212
213 {TK_CONFIG_SYNONYM, "-fg", "foreground", (char *) NULL,
214 (char *) NULL, 0, 0},
215
216 {TK_CONFIG_FONT, "-font", "font", "Font",
217 DEF_CMPIMAGE_FONT, Tk_Offset(CmpMaster, font), 0},
218
219 {TK_CONFIG_COLOR, "-foreground", "foreground", "Foreground",
220 DEF_CMPIMAGE_FG_COLOR, Tk_Offset(CmpMaster, foreground),
221 TK_CONFIG_COLOR_ONLY},
222
223 {TK_CONFIG_COLOR, "-foreground", "foreground", "Foreground",
224 DEF_CMPIMAGE_FG_MONO, Tk_Offset(CmpMaster, foreground),
225 TK_CONFIG_MONO_ONLY},
226
227 {TK_CONFIG_PIXELS, "-padx", (char *) NULL, (char *) NULL,
228 "0", Tk_Offset(CmpMaster, padX), 0},
229
230 {TK_CONFIG_PIXELS, "-pady", (char *) NULL, (char *) NULL,
231 "0", Tk_Offset(CmpMaster, padY), 0},
232
233 {TK_CONFIG_RELIEF, "-relief", (char *) NULL, (char *) NULL,
234 "flat", Tk_Offset(CmpMaster, relief), 0},
235
236 {TK_CONFIG_BOOLEAN, "-showbackground", (char *) NULL, (char *) NULL,
237 "0", Tk_Offset(CmpMaster, showBackground), 0},
238
239 {TK_CONFIG_WINDOW, "-window", (char *) NULL, (char *) NULL,
240 (char *) NULL, Tk_Offset(CmpMaster, tkwin), TK_CONFIG_NULL_OK},
241
242 {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
243 (char *) NULL, 0, 0}
244 };
245
246 static Tk_ConfigSpec lineConfigSpecs[] = {
247 {TK_CONFIG_ANCHOR, "-anchor", (char *) NULL, (char *) NULL,
248 "c", Tk_Offset(CmpLine, anchor), 0},
249 {TK_CONFIG_PIXELS, "-padx", (char *) NULL, (char *) NULL,
250 "0", Tk_Offset(CmpLine, padX), 0},
251 {TK_CONFIG_PIXELS, "-pady", (char *) NULL, (char *) NULL,
252 "0", Tk_Offset(CmpLine, padY), 0},
253 {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
254 (char *) NULL, 0, 0}
255 };
256
257 static Tk_ConfigSpec bitmapConfigSpecs[] = {
258 {TK_CONFIG_ANCHOR, "-anchor", (char *) NULL, (char *) NULL,
259 "c", Tk_Offset(CmpBitmapItem, anchor), 0},
260
261 {TK_CONFIG_COLOR, "-background", "background", "Background",
262 "", Tk_Offset(CmpBitmapItem, background),
263 TK_CONFIG_NULL_OK},
264
265 {TK_CONFIG_SYNONYM, "-bg", "background", (char *) NULL,
266 (char *) NULL, 0, 0},
267
268 {TK_CONFIG_BITMAP, "-bitmap", (char *) NULL, (char *) NULL,
269 "", Tk_Offset(CmpBitmapItem, bitmap), TK_CONFIG_NULL_OK},
270
271 {TK_CONFIG_SYNONYM, "-fg", "foreground", (char *) NULL,
272 (char *) NULL, 0, 0},
273
274 {TK_CONFIG_COLOR, "-foreground", "foreground", "Foreground",
275 "", Tk_Offset(CmpBitmapItem, foreground),
276 TK_CONFIG_NULL_OK},
277
278 {TK_CONFIG_PIXELS, "-padx", (char *) NULL, (char *) NULL,
279 "0", Tk_Offset(CmpBitmapItem, padX), 0},
280
281 {TK_CONFIG_PIXELS, "-pady", (char *) NULL, (char *) NULL,
282 "0", Tk_Offset(CmpBitmapItem, padY), 0},
283
284 {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
285 (char *) NULL, 0, 0}
286 };
287
288 static Tk_ConfigSpec imageConfigSpecs[] = {
289 {TK_CONFIG_ANCHOR, "-anchor", (char *) NULL, (char *) NULL,
290 "c", Tk_Offset(CmpImageItem, anchor), 0},
291 {TK_CONFIG_STRING, "-image", (char *) NULL, (char *) NULL,
292 (char *) NULL, Tk_Offset(CmpImageItem, imageString), TK_CONFIG_NULL_OK},
293 {TK_CONFIG_PIXELS, "-padx", (char *) NULL, (char *) NULL,
294 "0", Tk_Offset(CmpImageItem, padX), 0},
295 {TK_CONFIG_PIXELS, "-pady", (char *) NULL, (char *) NULL,
296 "0", Tk_Offset(CmpImageItem, padY), 0},
297 {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
298 (char *) NULL, 0, 0}
299 };
300
301 static Tk_ConfigSpec spaceConfigSpecs[] = {
302 {TK_CONFIG_PIXELS, "-height", (char *) NULL, (char *) NULL,
303 "0", Tk_Offset(CmpSpaceItem, height), 0},
304 {TK_CONFIG_PIXELS, "-width", (char *) NULL, (char *) NULL,
305 "0", Tk_Offset(CmpSpaceItem, width), 0},
306 {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
307 (char *) NULL, 0, 0}
308 };
309
310 static Tk_ConfigSpec textConfigSpecs[] = {
311 {TK_CONFIG_ANCHOR, "-anchor", (char *) NULL, (char *) NULL,
312 "c", Tk_Offset(CmpTextItem, anchor), 0},
313
314 {TK_CONFIG_SYNONYM, "-fg", "foreground", (char *) NULL,
315 (char *) NULL, 0, 0},
316
317 {TK_CONFIG_FONT, "-font", (char *) NULL, (char *) NULL,
318 "", Tk_Offset(CmpTextItem, font), TK_CONFIG_NULL_OK},
319
320 {TK_CONFIG_COLOR, "-foreground", "foreground", "Foreground",
321 "", Tk_Offset(CmpTextItem, foreground),
322 TK_CONFIG_NULL_OK},
323
324 {TK_CONFIG_JUSTIFY, "-justify", (char *) NULL, (char *) NULL,
325 "left", Tk_Offset(CmpTextItem, justify), 0},
326
327 {TK_CONFIG_PIXELS, "-padx", (char *) NULL, (char *) NULL,
328 "0", Tk_Offset(CmpTextItem, padX), 0},
329
330 {TK_CONFIG_PIXELS, "-pady", (char *) NULL, (char *) NULL,
331 "0", Tk_Offset(CmpTextItem, padY), 0},
332
333 {TK_CONFIG_STRING, "-text", (char *) NULL, (char *) NULL,
334 "", Tk_Offset(CmpTextItem, text), TK_CONFIG_NULL_OK},
335
336 {TK_CONFIG_INT, "-underline", (char *) NULL, (char *) NULL,
337 "-1", Tk_Offset(CmpTextItem, underline), 0},
338
339 {TK_CONFIG_PIXELS, "-wraplength", (char *) NULL, (char *) NULL,
340 "0", Tk_Offset(CmpTextItem, wrapLength), 0},
341
342 {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
343 (char *) NULL, 0, 0}
344 };
345
346 /*
347 * Prototypes for procedures used only locally in this file:
348 */
349
350 static int ImgCmpCmd _ANSI_ARGS_((ClientData clientData,
351 Tcl_Interp *interp, int argc, char **argv));
352 static void ImgCmpCmdDeletedProc _ANSI_ARGS_((
353 ClientData clientData));
354 static int ImgCmpConfigureMaster _ANSI_ARGS_((
355 CmpMaster *masterPtr, int argc, char **argv,
356 int flags));
357 CmpBitmapItem * AddNewBitmap _ANSI_ARGS_((CmpMaster *masterPtr,
358 CmpLine *line,
359 int argc, char **argv));
360 CmpImageItem * AddNewImage _ANSI_ARGS_((CmpMaster *masterPtr,
361 CmpLine *line,
362 int argc, char **argv));
363 CmpSpaceItem * AddNewSpace _ANSI_ARGS_((CmpMaster *masterPtr,
364 CmpLine *line,
365 int argc, char **argv));
366 CmpTextItem * AddNewText _ANSI_ARGS_((CmpMaster *masterPtr,
367 CmpLine *line,
368 int argc, char **argv));
369 CmpLine* AddNewLine _ANSI_ARGS_((CmpMaster *masterPtr,
370 int argc, char **argv));
371 static void CalculateMasterSize _ANSI_ARGS_((
372 ClientData clientData));
373 static void ChangeImageWhenIdle _ANSI_ARGS_((
374 CmpMaster *masterPtr));
375 static void ImageProc _ANSI_ARGS_((ClientData clientData,
376 int x, int y, int width, int height,
377 int imgWidth, int imgHeight));
378 static void FreeLine _ANSI_ARGS_((CmpLine * lPtr));
379 static void FreeItem _ANSI_ARGS_((CmpItemPtr p));
380
381 /*
382 *----------------------------------------------------------------------
383 *
384 * ImgCmpCreate --
385 *
386 * This procedure is called by the Tk image code to create "test"
387 * images.
388 *
389 * Results:
390 * A standard Tcl result.
391 *
392 * Side effects:
393 * The data structure for a new image is allocated.
394 *
395 *----------------------------------------------------------------------
396 */
397
398 /* ARGSUSED */
399 static int
400 ImgCmpCreate(interp, name, argc, objv, typePtr, master, clientDataPtr)
401 Tcl_Interp *interp; /* Interpreter for application containing
402 * image. */
403 char *name; /* Name to use for image. */
404 int argc; /* Number of arguments. */
405 Tcl_Obj *CONST*objv; /* Argument strings for options (doesn't
406 * include image name or type). */
407 Tk_ImageType *typePtr; /* Pointer to our type record (not used). */
408 Tk_ImageMaster master; /* Token for image, to be used by us in
409 * later callbacks. */
410 ClientData *clientDataPtr; /* Store manager's token for image here;
411 * it will be returned in later callbacks. */
412 {
413 CmpMaster *masterPtr;
414 int i;
415 #ifndef _LANG
416 char *argvbuf[10];
417 char **args = argvbuf;
418
419 /*
420 * Convert the objv arguments into string equivalent.
421 */
422 if (argc > 10) {
423 argv = (char **) ckalloc(argc * sizeof(char *));
424 }
425 for (i = 0; i < argc; i++) {
426 argv[i] = TixGetStringFromObj(objv[i], NULL);
427 }
428 #endif
429
430 masterPtr = (CmpMaster *) ckalloc(sizeof(CmpMaster));
431 masterPtr->tkMaster = master;
432 masterPtr->interp = interp;
433 masterPtr->imageCmd = Lang_CreateImage(interp, name, ImgCmpCmd,
434 (ClientData)masterPtr, ImgCmpCmdDeletedProc, typePtr);
435 masterPtr->tkwin = NULL;
436 masterPtr->display = NULL;
437 masterPtr->width = 0;
438 masterPtr->height = 0;
439 masterPtr->padX = 0;
440 masterPtr->padY = 0;
441 masterPtr->lineHead = NULL;
442 masterPtr->lineTail = NULL;
443 masterPtr->borderWidth = 0;
444 masterPtr->background = NULL;
445 masterPtr->relief = 0;
446 masterPtr->font = NULL;
447 masterPtr->foreground = NULL;
448 masterPtr->gc = None;
449 masterPtr->showBackground = 0;
450 masterPtr->changing = 0;
451 masterPtr->isDeleted = 0;
452 masterPtr->winCount = 0;
453
454 if (ImgCmpConfigureMaster(masterPtr, argc, objv, 0) != TCL_OK) {
455 ImgCmpDelete((ClientData) masterPtr);
456 return TCL_ERROR;
457 }
458 *clientDataPtr = (ClientData) masterPtr;
459 return TCL_OK;
460 }
461
462 /*
463 *----------------------------------------------------------------------
464 *
465 * ImgCmpConfigureMaster --
466 *
467 * This procedure is called when a bitmap image is created or
468 * reconfigured. It process configuration options and resets
469 * any instances of the image.
470 *
471 * Results:
472 * A standard Tcl return value. If TCL_ERROR is returned then
473 * an error message is left in masterPtr->interp->result.
474 *
475 * Side effects:
476 * Existing instances of the image will be redisplayed to match
477 * the new configuration options.
478 *
479 *----------------------------------------------------------------------
480 */
481 static int
482 ImgCmpConfigureMaster(masterPtr, argc, argv, flags)
483 CmpMaster *masterPtr; /* Pointer to data structure describing
484 * overall bitmap image to (reconfigure). */
485 int argc; /* Number of entries in argv. */
486 char **argv; /* Pairs of configuration options for image. */
487 int flags; /* Flags to pass to Tk_ConfigureWidget,
488 * such as TK_CONFIG_ARGV_ONLY. */
489 {
490 XGCValues gcValues;
491 GC newGC;
492 int i;
493
494 if (argc %2) {
495 Tcl_AppendResult(masterPtr->interp, "value missing for option \"",
496 argv[argc-1], "\"", NULL);
497 return TCL_ERROR;
498 }
499 for (i=0; i<argc; i+=2) {
500 size_t length = strlen(argv[i]);
501 if (strncmp(argv[i], "-window", length) == 0) {
502 masterPtr->tkwin = Tk_NameToWindow(masterPtr->interp, argv[i+1],
503 Tk_MainWindow(masterPtr->interp));
504 if (masterPtr->tkwin == NULL) {
505 return TCL_ERROR;
506 }
507 }
508 }
509 if (masterPtr->tkwin == NULL) {
510 masterPtr->tkwin = Tk_MainWindow(masterPtr->interp);
511 }
512 masterPtr->display = Tk_Display(masterPtr->tkwin);
513
514 if (Tk_ConfigureWidget(masterPtr->interp, masterPtr->tkwin,
515 configSpecs, argc, argv, (char *) masterPtr, flags) != TCL_OK) {
516 return TCL_ERROR;
517 }
518
519
520 /*
521 * Get the default GC for text and bitmaps
522 */
523 gcValues.foreground = masterPtr->foreground->pixel;
524 gcValues.background = Tk_3DBorderColor(masterPtr->background)->pixel;
525 gcValues.font = TixFontId(masterPtr->font);
526 gcValues.graphics_exposures = False;
527 newGC = Tk_GetGC(masterPtr->tkwin,
528 GCBackground|GCForeground|GCFont|GCGraphicsExposures,
529 &gcValues);
530 if (masterPtr->gc != None) {
531 Tk_FreeGC(Tk_Display(masterPtr->tkwin), masterPtr->gc);
532 }
533 masterPtr->gc = newGC;
534
535 ChangeImageWhenIdle(masterPtr);
536 return TCL_OK;
537 }
538
539 /*
540 *--------------------------------------------------------------
541 *
542 * ImgCmpCmd --
543 *
544 * This procedure is invoked to process the Tcl command
545 * that corresponds to an image managed by this module.
546 * See the user documentation for details on what it does.
547 *
548 * Results:
549 * A standard Tcl result.
550 *
551 * Side effects:
552 * See the user documentation.
553 *
554 *--------------------------------------------------------------
555 */
556 static int
557 ImgCmpCmd(clientData, interp, argc, argv)
558 ClientData clientData; /* Information about button widget. */
559 Tcl_Interp *interp; /* Current interpreter. */
560 int argc; /* Number of arguments. */
561 char **argv; /* Argument strings. */
562 {
563 CmpMaster *masterPtr = (CmpMaster *) clientData;
564 int c, code;
565 size_t length;
566
567 if (argc < 2) {
568 sprintf(interp->result,
569 "wrong # args: should be \"%.50s option ?arg arg ...?\"",
570 argv[0]);
571 return TCL_ERROR;
572 }
573 c = argv[1][0];
574 length = strlen(argv[1]);
575 if ((c == 'a') && (strncmp(argv[1], "add", length) == 0)) {
576 if (argc < 3) {
577 return Tix_ArgcError(interp, argc, argv, 2,
578 "type ?option value? ...");
579 }
580 c = argv[2][0];
581 length = strlen(argv[2]);
582
583 if ((c == 'l') && (strncmp(argv[2], "line", length) == 0)) {
584 CmpLine * newLine;
585
586 newLine = AddNewLine(masterPtr, argc-3, argv+3);
587 if (newLine == NULL) {
588 return TCL_ERROR;
589 }
590 }
591 else {
592 CmpItemPtr p;
593
594 if (masterPtr->lineTail == 0) {
595 if (AddNewLine(masterPtr, 0, 0) == NULL) {
596 return TCL_ERROR;
597 }
598 }
599 if ((c == 'b') && (strncmp(argv[2], "bitmap", length) == 0)) {
600 p.bitmap = AddNewBitmap(masterPtr, masterPtr->lineTail,
601 argc-3, argv+3);
602 if (p.bitmap == NULL) {
603 return TCL_ERROR;
604 }
605 }
606 else if ((c == 'i') && (strncmp(argv[2], "image", length) == 0)) {
607 p.image = AddNewImage(masterPtr, masterPtr->lineTail,
608 argc-3, argv+3);
609 if (p.image == NULL) {
610 return TCL_ERROR;
611 }
612 }
613 else if ((c == 's') && (strncmp(argv[2], "space", length) == 0)) {
614 p.space = AddNewSpace(masterPtr, masterPtr->lineTail,
615 argc-3, argv+3);
616 if (p.space == NULL) {
617 return TCL_ERROR;
618 }
619 }
620 else if ((c == 't') && (strncmp(argv[2], "text", length) == 0)) {
621 p.text = AddNewText(masterPtr, masterPtr->lineTail,
622 argc-3, argv+3);
623 if (p.text == NULL) {
624 return TCL_ERROR;
625 }
626 }
627 else {
628 Tcl_AppendResult(interp, "unknown option \"",
629 argv[2], "\", must be bitmap, image, line, ",
630 "space, text or widget", NULL);
631 return TCL_ERROR;
632 }
633
634 /* append to the end of the line */
635 if (masterPtr->lineTail->itemHead == NULL) {
636 masterPtr->lineTail->itemHead = p.item;
637 masterPtr->lineTail->itemTail = p.item;
638 } else {
639 masterPtr->lineTail->itemTail->next = p.item;
640 masterPtr->lineTail->itemTail = p.item;
641 }
642 }
643 ChangeImageWhenIdle(masterPtr);
644 return TCL_OK;
645 } else if ((c == 'c') && (strncmp(argv[1], "cget", length) == 0)
646 && (length >= 2)) {
647 if (argc != 3) {
648 Tcl_AppendResult(interp, "wrong # args: should be \"",
649 argv[0], " cget option\"",
650 (char *) NULL);
651 return TCL_ERROR;
652 }
653 return Tk_ConfigureValue(interp, Tk_MainWindow(interp), configSpecs,
654 (char *) masterPtr, argv[2], 0);
655 } else if ((c == 'c') && (strncmp(argv[1], "configure", length) == 0)
656 && (length >= 2)) {
657 if (argc == 2) {
658 code = Tk_ConfigureInfo(interp, Tk_MainWindow(interp),
659 configSpecs, (char *) masterPtr, (char *) NULL, 0);
660 } else if (argc == 3) {
661 code = Tk_ConfigureInfo(interp, Tk_MainWindow(interp),
662 configSpecs, (char *) masterPtr, argv[2], 0);
663 } else {
664 int i;
665 for (i=2; i<argc-2; i++) {
666 length = strlen(argv[i]);
667 if (strncmp(argv[i], "-window", length) == 0) {
668 Tcl_AppendResult(interp, "The -window option cannot ",
669 "be changed.", (char *) NULL);
670 return TCL_ERROR;
671 }
672 }
673 code = ImgCmpConfigureMaster(masterPtr, argc-2, argv+2,
674 TK_CONFIG_ARGV_ONLY);
675 }
676 return code;
677 } else if ((c == 'i') && (strncmp(argv[1], "itemconfigure", length)== 0)) {
678 Tcl_AppendResult(interp, "unimplemented", NULL);
679 return TCL_ERROR;
680 } else if ((c == 'l') && (strncmp(argv[1], "lineconfigure", length)== 0)) {
681 Tcl_AppendResult(interp, "unimplemented", NULL);
682 return TCL_ERROR;
683 } else {
684 Tcl_AppendResult(interp, "bad option \"", argv[1],
685 "\": must be cget or configure", (char *) NULL);
686 return TCL_ERROR;
687 }
688 return TCL_OK;
689 }
690
691 /*----------------------------------------------------------------------
692 *
693 *
694 *----------------------------------------------------------------------
695 */
696 CmpLine *
697 AddNewLine(masterPtr, argc, argv)
698 CmpMaster *masterPtr;
699 int argc; /* Number of arguments. */
700 char **argv; /* Argument strings. */
701 {
702 CmpLine * lPtr = (CmpLine *)ckalloc(sizeof(CmpLine));
703
704 lPtr->masterPtr = masterPtr;
705 lPtr->next = NULL;
706 lPtr->itemHead = NULL;
707 lPtr->itemTail = NULL;
708 lPtr->padX = 0;
709 lPtr->padY = 0;
710 lPtr->width = 1;
711 lPtr->height = 1;
712
713 lPtr->anchor = TK_ANCHOR_CENTER;
714
715 if (Tk_ConfigureWidget(masterPtr->interp, masterPtr->tkwin,
716 lineConfigSpecs, argc, argv, (char *) lPtr,
717 TK_CONFIG_ARGV_ONLY) != TCL_OK) {
718 FreeLine(lPtr);
719 return NULL;
720 }
721
722 /*
723 * Append to the end of the master's lines
724 */
725 if (masterPtr->lineHead == NULL) {
726 masterPtr->lineHead = masterPtr->lineTail = lPtr;
727 } else {
728 masterPtr->lineTail->next = lPtr;
729 masterPtr->lineTail = lPtr;
730 }
731
732 return lPtr;
733 }
734
735 /*----------------------------------------------------------------------
736 *
737 *
738 *----------------------------------------------------------------------
739 */
740 CmpBitmapItem *
741 AddNewBitmap(masterPtr, line, argc, argv)
742 CmpMaster *masterPtr;
743 CmpLine *line;
744 int argc; /* Number of arguments. */
745 char **argv; /* Argument strings. */
746 {
747 CmpItemPtr p;
748 XGCValues gcValues;
749
750 p.bitmap = (CmpBitmapItem*) ckalloc(sizeof(CmpBitmapItem));
751 p.bitmap->line = line;
752 p.bitmap->next = NULL;
753 p.bitmap->anchor = TK_ANCHOR_CENTER;
754 p.bitmap->type = TYPE_BITMAP;
755 p.bitmap->padX = 0;
756 p.bitmap->padY = 0;
757 p.bitmap->width = 0;
758 p.bitmap->height = 0;
759
760 p.bitmap->bitmap = None;
761 p.bitmap->foreground = NULL;
762 p.bitmap->background = NULL;
763 p.bitmap->gc = None;
764
765 if (Tk_ConfigureWidget(masterPtr->interp, masterPtr->tkwin,
766 bitmapConfigSpecs, argc, argv, (char *) p.bitmap,
767 TK_CONFIG_ARGV_ONLY) != TCL_OK) {
768 goto error;
769 }
770
771 /* Get the GC for the bitmap */
772 if (p.bitmap->background) {
773 gcValues.background = p.bitmap->background->pixel;
774 } else {
775 gcValues.background = Tk_3DBorderColor(masterPtr->background)->pixel;
776 }
777 if (p.bitmap->foreground) {
778 gcValues.foreground = p.bitmap->foreground->pixel;
779 } else {
780 gcValues.foreground = masterPtr->foreground->pixel;
781 }
782 gcValues.graphics_exposures = False;
783 p.bitmap->gc = Tk_GetGC(masterPtr->tkwin,
784 GCBackground|GCForeground|GCGraphicsExposures,
785 &gcValues);
786
787 return p.bitmap;
788
789 error:
790
791 FreeItem(p);
792 return NULL;
793 }
794
795 /*----------------------------------------------------------------------
796 *
797 *
798 *----------------------------------------------------------------------
799 */
800 CmpImageItem *
801 AddNewImage(masterPtr, line, argc, argv)
802 CmpMaster *masterPtr;
803 CmpLine *line;
804 int argc; /* Number of arguments. */
805 char **argv; /* Argument strings. */
806 {
807 CmpItemPtr p;
808
809
810 p.image = (CmpImageItem*) ckalloc(sizeof(CmpImageItem));
811 p.image->line = line;
812 p.image->next = NULL;
813 p.image->anchor = TK_ANCHOR_CENTER;
814 p.image->type = TYPE_IMAGE;
815 p.image->padX = 0;
816 p.image->padY = 0;
817 p.image->width = 0;
818 p.image->height = 0;
819
820 p.image->imageString = NULL;
821 p.image->image = NULL;
822
823 if (Tk_ConfigureWidget(masterPtr->interp, masterPtr->tkwin,
824 imageConfigSpecs, argc, argv, (char *) p.image,
825 TK_CONFIG_ARGV_ONLY) != TCL_OK) {
826 goto error;
827 }
828
829 /* Get the image */
830 if (p.image->imageString != NULL) {
831 p.image->image = Tk_GetImage(masterPtr->interp, masterPtr->tkwin,
832 p.image->imageString, ImageProc, (ClientData)p.image);
833 if (p.image->image == NULL) {
834 goto error;
835 }
836 }
837
838 return p.image;
839
840 error:
841
842 FreeItem(p);
843 return NULL;
844 }
845
846 /*----------------------------------------------------------------------
847 *
848 *
849 *----------------------------------------------------------------------
850 */
851 CmpSpaceItem *
852 AddNewSpace(masterPtr, line, argc, argv)
853 CmpMaster *masterPtr;
854 CmpLine *line;
855 int argc; /* Number of arguments. */
856 char **argv; /* Argument strings. */
857 {
858 CmpItemPtr p;
859
860 p.space = (CmpSpaceItem*) ckalloc(sizeof(CmpSpaceItem));
861 p.space->line = line;
862 p.space->next = NULL;
863 p.space->anchor = TK_ANCHOR_CENTER;
864 p.space->type = TYPE_SPACE;
865 p.space->padX = 0;
866 p.space->padY = 0;
867 p.space->width = 0;
868 p.space->height = 0;
869
870 if (Tk_ConfigureWidget(masterPtr->interp, masterPtr->tkwin,
871 spaceConfigSpecs, argc, argv, (char *)p.space,
872 TK_CONFIG_ARGV_ONLY) != TCL_OK) {
873 goto error;
874 }
875
876 return p.space;
877
878 error:
879
880 FreeItem(p);
881 return NULL;
882 }
883
884 /*----------------------------------------------------------------------
885 *
886 *
887 *----------------------------------------------------------------------
888 */
889 CmpTextItem *
890 AddNewText(masterPtr, line, argc, argv)
891 CmpMaster *masterPtr;
892 CmpLine *line;
893 int argc; /* Number of arguments. */
894 char **argv; /* Argument strings. */
895 {
896 CmpItemPtr p;
897 XGCValues gcValues;
898
899 p.text = (CmpTextItem*) ckalloc(sizeof(CmpTextItem));
900 p.text->line = line;
901 p.text->next = NULL;
902 p.text->anchor = TK_ANCHOR_CENTER;
903 p.text->type = TYPE_TEXT;
904 p.text->padX = 0;
905 p.text->padY = 0;
906 p.text->width = 0;
907 p.text->height = 0;
908
909 p.text->text = NULL;
910 p.text->numChars = 0;
911 p.text->justify = TK_JUSTIFY_CENTER;
912 p.text->underline = -1;
913 p.text->wrapLength = 0;
914
915 p.text->foreground = NULL;
916 p.text->font = NULL;
917 p.text->gc = None;
918
919 if (Tk_ConfigureWidget(masterPtr->interp, masterPtr->tkwin,
920 textConfigSpecs, argc, argv, (char *) p.text,
921 TK_CONFIG_ARGV_ONLY) != TCL_OK) {
922
923 goto error;
924 }
925
926 /* Get the GC for the text */
927 if (p.text->foreground) {
928 gcValues.foreground = p.text->foreground->pixel;
929 } else {
930 gcValues.foreground = masterPtr->foreground->pixel;
931 }
932 if (p.text->font) {
933 gcValues.font = TixFontId(p.text->font);
934 } else {
935 gcValues.font = TixFontId(masterPtr->font);
936 }
937 gcValues.graphics_exposures = False;
938 p.text->gc = Tk_GetGC(masterPtr->tkwin,
939 GCFont|GCForeground|GCGraphicsExposures,
940 &gcValues);
941
942 return p.text;
943
944 error:
945
946 FreeItem(p);
947 return NULL;
948 }
949
950 /*
951 *----------------------------------------------------------------------
952 *
953 * ImgCmpGet --
954 *
955 * This procedure is called for each use of a bitmap image in a
956 * widget.
957 *
958 * Results:
959 * The return value is a token for the instance, which is passed
960 * back to us in calls to ImgCmpDisplay and ImgCmpFree.
961 *
962 * Side effects:
963 * A data structure is set up for the instance (or, an existing
964 * instance is re-used for the new one).
965 *
966 *----------------------------------------------------------------------
967 */
968 static ClientData
969 ImgCmpGet(tkwin, masterData)
970 Tk_Window tkwin; /* Window in which the instance will be
971 * used. */
972 ClientData masterData; /* Pointer to our master structure for the
973 * image. */
974 {
975 CmpMaster *masterPtr = (CmpMaster *)masterData;
976
977 if (Tk_Display(tkwin) == masterPtr->display) {
978 CmpInstance *instance = (CmpInstance *) ckalloc(sizeof(CmpInstance));
979 if (instance) {
980 instance->master = masterPtr;
981 instance->tkwin = tkwin;
982 masterPtr->winCount++;
983 }
984 return (ClientData) instance;
985 }
986
987 Tcl_AppendResult(masterPtr->interp,
988 "Image \"",
989 Tk_NameOfImage(masterPtr->tkMaster),
990 "\" can only be assigned to display of window \"",
991 Tk_PathName(masterPtr->tkwin), "\"", NULL);
992 Tcl_AddErrorInfo(masterPtr->interp, "\n (while configuring image \"");
993 Tcl_AddErrorInfo(masterPtr->interp, Tk_NameOfImage(masterPtr->tkMaster));
994 Tcl_AddErrorInfo(masterPtr->interp, "\")");
995 Tcl_BackgroundError(masterPtr->interp);
996
997 return NULL;
998 }
999
1000 static void
1001 CalculateMasterSize(clientData)
1002 ClientData clientData;
1003 {
1004 CmpMaster *masterPtr = (CmpMaster *)clientData;
1005 CmpLine *lPtr;
1006 CmpItemPtr p;
1007
1008 masterPtr->width = 0;
1009 masterPtr->height = 0;
1010
1011 for (lPtr = masterPtr->lineHead; lPtr; lPtr=lPtr->next) {
1012 lPtr->width = 0;
1013 lPtr->height = 0;
1014 for (p.item = lPtr->itemHead; p.item; p.item=p.item->next) {
1015
1016 switch (p.item->type) {
1017 case TYPE_IMAGE:
1018 Tk_SizeOfImage(p.image->image,
1019 &p.image->width, &p.image->height);
1020 break;
1021
1022 case TYPE_SPACE:
1023 /* Do nothing */
1024 break;
1025
1026 case TYPE_TEXT:
1027 {
1028 TixFont font;
1029
1030 if (p.text->text == NULL) {
1031 break;
1032 }
1033
1034 if (p.text->font) {
1035 font = p.text->font;
1036 } else {
1037 font = masterPtr->font;
1038 }
1039
1040 p.text->numChars = -1;
1041 TixComputeTextGeometry(font, p.text->text,
1042 p.text->numChars,
1043 p.text->wrapLength,
1044 &p.text->width, &p.text->height);
1045 }
1046 break;
1047
1048 case TYPE_BITMAP:
1049 Tk_SizeOfBitmap(Tk_Display(masterPtr->tkwin),
1050 p.bitmap->bitmap, &p.bitmap->width,
1051 &p.bitmap->height);
1052 break;
1053
1054 case TYPE_WIDGET:
1055
1056
1057 break;
1058 }
1059 p.item->width += 2*p.item->padX;
1060 p.item->height += 2*p.item->padY;
1061
1062 lPtr->width += p.item->width;
1063 if (lPtr->height < p.item->height) {
1064 lPtr->height = p.item->height;
1065 }
1066 }
1067 lPtr->width += 2*lPtr->padX;
1068 lPtr->height += 2*lPtr->padY;
1069
1070 if (masterPtr->width < lPtr->width) {
1071 masterPtr->width = lPtr->width;
1072 }
1073 masterPtr->height += lPtr->height;
1074 }
1075 masterPtr->width += 2*masterPtr->padX + 2*masterPtr->borderWidth;
1076 masterPtr->height += 2*masterPtr->padY + 2*masterPtr->borderWidth;
1077
1078 Tk_ImageChanged(masterPtr->tkMaster, 0, 0, masterPtr->width,
1079 masterPtr->height, masterPtr->width, masterPtr->height);
1080 masterPtr->changing = 0;
1081 }
1082
1083 static void
1084 ChangeImageWhenIdle(masterPtr)
1085 CmpMaster *masterPtr;
1086 {
1087 if (!masterPtr->changing) {
1088 masterPtr->changing = 1;
1089 Tcl_DoWhenIdle(CalculateMasterSize, (ClientData)masterPtr);
1090 }
1091 }
1092
1093 /*
1094 *----------------------------------------------------------------------
1095 *
1096 * ImgCmpDisplay --
1097 *
1098 * This procedure is invoked to draw a bitmap image.
1099 *
1100 * Results:
1101 * None.
1102 *
1103 * Side effects:
1104 * A portion of the image gets rendered in a pixmap or window.
1105 *
1106 *----------------------------------------------------------------------
1107 */
1108 static void
1109 ImgCmpDisplay(clientData, display, drawable, imageX, imageY, width,
1110 height, drawableX, drawableY)
1111 ClientData clientData; /* Pointer to CmpInstance structure for
1112 * for instance to be displayed. */
1113 Display *display; /* Display on which to draw image. */
1114 Drawable drawable; /* Pixmap or window in which to draw image. */
1115 int imageX, imageY; /* Upper-left corner of region within image
1116 * to draw. */
1117 int width, height; /* Dimensions of region within image to draw.*/
1118 int drawableX, drawableY; /* Coordinates within drawable that
1119 * correspond to imageX and imageY. */
1120 {
1121 CmpInstance *instance = (CmpInstance *) clientData;
1122 CmpMaster * masterPtr;
1123 CmpLine *lPtr;
1124 CmpItemPtr p;
1125 int dx, dy, extraX;
1126
1127 if (instance == NULL) {
1128 /* attempting to draw into a invalid window (can only be drawn into
1129 * the original window set by the -window option */
1130 return;
1131 }
1132
1133 masterPtr = instance->master;
1134
1135 if (masterPtr == NULL) {
1136 /* attempting to draw into a invalid window (can only be drawn into
1137 * the original window set by the -window option */
1138 return;
1139 }
1140
1141 if (masterPtr->showBackground) {
1142 Tk_Fill3DRectangle(instance->tkwin, drawable,
1143 masterPtr->background,
1144 drawableX + masterPtr->padX - imageX,
1145 drawableY + masterPtr->padY - imageY,
1146 masterPtr->width - 2*masterPtr->padX,
1147 masterPtr->height - 2*masterPtr->padY,
1148 masterPtr->borderWidth, masterPtr->relief);
1149 }
1150
1151 /* ToDo: Set the clipping region according to the imageX,Y, and
1152 * width, height */
1153 dy = drawableY + masterPtr->padY + masterPtr->borderWidth - imageY;
1154
1155 for (lPtr = masterPtr->lineHead; lPtr; lPtr=lPtr->next) {
1156 dx = drawableX + masterPtr->padX - imageX;
1157 dx += lPtr->padX;
1158 dy += lPtr->padY;
1159
1160 extraX = masterPtr->width - 2*masterPtr->padX - lPtr->width;
1161 switch (lPtr->anchor) {
1162 case TK_ANCHOR_SW: case TK_ANCHOR_W: case TK_ANCHOR_NW:
1163 extraX = 0;
1164 break;
1165 case TK_ANCHOR_N: case TK_ANCHOR_CENTER: case TK_ANCHOR_S:
1166 extraX /= 2;
1167 break;
1168 case TK_ANCHOR_SE: case TK_ANCHOR_E: case TK_ANCHOR_NE:
1169 break;
1170 }
1171 dx += extraX;
1172
1173 for (p.item = lPtr->itemHead; p.item; p.item=p.item->next) {
1174 int extraY;
1175 dx += p.item->padX;
1176
1177 extraY = lPtr->height - 2*lPtr->padY - p.item->height;
1178 switch (p.item->anchor) {
1179 case TK_ANCHOR_SW: case TK_ANCHOR_S: case TK_ANCHOR_SE:
1180 break;
1181 case TK_ANCHOR_W: case TK_ANCHOR_CENTER: case TK_ANCHOR_E:
1182 extraY /= 2;
1183 break;
1184 case TK_ANCHOR_NW: case TK_ANCHOR_N: case TK_ANCHOR_NE:
1185 extraY = 0;
1186 break;
1187 }
1188
1189 switch (p.item->type) {
1190 case TYPE_IMAGE:
1191 Tk_RedrawImage(p.image->image, 0, 0,
1192 p.image->width - 2*p.item->padX,
1193 p.image->height - 2*p.item->padY,
1194 drawable, dx, dy+extraY);
1195 break;
1196
1197 case TYPE_SPACE:
1198 /* Do nothing */
1199 break;
1200
1201 case TYPE_TEXT:
1202 {
1203 TixFont font;
1204
1205 if (p.text->text == NULL) {
1206 break;
1207 }
1208
1209 if (p.text->font) {
1210 font = p.text->font;
1211 } else {
1212 font = masterPtr->font;
1213 }
1214
1215 TixDisplayText(Tk_Display(instance->tkwin), drawable,
1216 font, p.text->text, p.text->numChars,
1217 dx, dy+extraY,
1218 p.text->width - 2*p.item->padX,
1219 p.text->justify,
1220 p.text->underline,
1221 p.text->gc);
1222 }
1223 break;
1224
1225 case TYPE_BITMAP:
1226 XCopyPlane(Tk_Display(instance->tkwin), p.bitmap->bitmap,
1227 drawable, p.bitmap->gc, 0, 0,
1228 p.bitmap->width - 2*p.item->padX,
1229 p.bitmap->height - 2*p.item->padY,
1230 dx, dy+extraY, 1);
1231
1232 break;
1233
1234 case TYPE_WIDGET:
1235
1236
1237 break;
1238 }
1239 dx += p.item->width - p.item->padX;
1240 }
1241 dy += lPtr->height - lPtr->padY;
1242 }
1243 }
1244
1245 /*
1246 *----------------------------------------------------------------------
1247 *
1248 * ImgCmpFree --
1249 *
1250 * This procedure is called when a widget ceases to use a
1251 * particular instance of an image.
1252 *
1253 * Results:
1254 * None.
1255 *
1256 * Side effects:
1257 * Internal data structures get cleaned up.
1258 *
1259 * Arguments:
1260 * clientData -- Pointer to CmpInstance for instance to be displayed
1261 * display -- Display containing image window
1262 *
1263 *----------------------------------------------------------------------
1264 */
1265
1266 static void
1267 ImgCmpFree(clientData, display)
1268 ClientData clientData;
1269 Display *display;
1270 {
1271 CmpInstance *instance = (CmpInstance *) clientData;
1272 /* Free per-instance resources and data */
1273 instance->master->winCount--;
1274 ckfree((char *) instance);
1275 }
1276
1277 static void FreeLine(lPtr)
1278 CmpLine * lPtr;
1279 {
1280 Tk_FreeOptions(lineConfigSpecs, (char *)lPtr,
1281 Tk_Display(lPtr->masterPtr->tkwin), 0);
1282 ckfree((char *) lPtr);
1283 }
1284
1285 static void FreeItem(p)
1286 CmpItemPtr p;
1287 {
1288 Display *display = p.item->line->masterPtr->display;
1289
1290 switch (p.item->type) {
1291 case TYPE_IMAGE:
1292 if (p.image->image) {
1293 Tk_FreeImage(p.image->image);
1294 }
1295 Tk_FreeOptions(imageConfigSpecs, (char *)p.image, display, 0);
1296 break;
1297
1298 case TYPE_SPACE:
1299 Tk_FreeOptions(spaceConfigSpecs, (char *)p.space, display, 0);
1300 break;
1301
1302 case TYPE_TEXT:
1303 if (p.text->gc != None) {
1304 Tk_FreeGC(display, p.text->gc);
1305 }
1306 Tk_FreeOptions(textConfigSpecs, (char *)p.text, display, 0);
1307 break;
1308
1309 case TYPE_BITMAP:
1310 if (p.bitmap->gc != None) {
1311 Tk_FreeGC(display, p.bitmap->gc);
1312 }
1313 Tk_FreeOptions(bitmapConfigSpecs, (char *)p.bitmap, display, 0);
1314 break;
1315
1316 case TYPE_WIDGET:
1317 break;
1318 }
1319 ckfree((char *) p.item);
1320 }
1321
1322 /*
1323 *----------------------------------------------------------------------
1324 *
1325 * ImgCmpFreeResources --
1326 *
1327 * This procedure frees resources associated with the window
1328 * specified with the -window arg to "image create compound ..."
1329 *
1330 * This procedure must be called from ImgCmpDelete
1331 * in order to ensure resources are freed under all circumstances.
1332 *
1333 * Results:
1334 * None.
1335 *
1336 * Side effects:
1337 * Resources associated with the image get freed, new image command
1338 * is removed from interpreter.
1339 *
1340 *----------------------------------------------------------------------
1341 */
1342 static void
1343 ImgCmpFreeResources(masterData)
1344 ClientData masterData; /* Pointer to CmpMaster structure for
1345 * image. Must not have any more instances. */
1346 {
1347 CmpMaster *masterPtr = (CmpMaster *) masterData;
1348 CmpLine * lPtr;
1349 CmpItemPtr p;
1350
1351
1352 if (masterPtr->tkwin == NULL) {
1353 return ;
1354 }
1355
1356 Tcl_Preserve((ClientData) masterPtr);
1357
1358 if (masterPtr->isDeleted == 0) {
1359
1360 masterPtr->isDeleted = 1;
1361
1362 for (lPtr=masterPtr->lineHead; lPtr;) {
1363 CmpLine * toDelete = lPtr;
1364 lPtr = lPtr->next;
1365
1366 for (p.item=toDelete->itemHead; p.item;) {
1367 CmpItemPtr toDelete;
1368
1369 toDelete.item = p.item;
1370 p.item=p.item->next;
1371
1372 FreeItem(toDelete);
1373 }
1374 FreeLine(toDelete);
1375 }
1376
1377 if (masterPtr->changing) {
1378 Tcl_CancelIdleCall(CalculateMasterSize, (ClientData)masterPtr);
1379 }
1380 masterPtr->tkMaster = NULL;
1381
1382 if (masterPtr->imageCmd != NULL) {
1383 Tcl_DeleteCommandFromToken(masterPtr->interp, masterPtr->imageCmd);
1384 masterPtr->imageCmd = NULL;
1385 }
1386
1387 if (masterPtr->gc != None) {
1388 Tk_FreeGC(masterPtr->display, masterPtr->gc);
1389 }
1390
1391 Tk_FreeOptions(configSpecs, (char *) masterPtr, masterPtr->display, 0);
1392 }
1393
1394 Tcl_Release((ClientData) masterPtr);
1395 }
1396
1397 /*
1398 *----------------------------------------------------------------------
1399 *
1400 * ImgCmpDelete --
1401 *
1402 * This procedure is called by the image code to delete the
1403 * master structure for an image.
1404 *
1405 * Results:
1406 * None.
1407 *
1408 * Side effects:
1409 * Resources associated with the image get freed.
1410 *
1411 *----------------------------------------------------------------------
1412 */
1413 static void
1414 ImgCmpDelete(masterData)
1415 ClientData masterData; /* Pointer to CmpMaster structure for
1416 * image. Must not have any more instances. */
1417 {
1418 CmpMaster *masterPtr = (CmpMaster *) masterData;
1419 ImgCmpFreeResources(masterData);
1420 ckfree((char *) masterPtr);
1421 }
1422
1423 /*
1424 *----------------------------------------------------------------------
1425 *
1426 * ImgCmpCmdDeletedProc --
1427 *
1428 * This procedure is invoked when the image command for an image
1429 * is deleted. It deletes the image.
1430 *
1431 * Results:
1432 * None.
1433 *
1434 * Side effects:
1435 * The image is deleted.
1436 *
1437 *----------------------------------------------------------------------
1438 */
1439 static void
1440 ImgCmpCmdDeletedProc(clientData)
1441 ClientData clientData; /* Pointer to CmpMaster structure for
1442 * image. */
1443 {
1444 CmpMaster *masterPtr = (CmpMaster *) clientData;
1445
1446 masterPtr->imageCmd = NULL;
1447
1448 if (masterPtr->tkMaster != NULL) {
1449 Tk_DeleteImage(masterPtr->interp,
1450 Tk_NameOfImage(masterPtr->tkMaster));
1451 }
1452 }
1453 /*
1454 *----------------------------------------------------------------------
1455 *
1456 * ImageProc --
1457 *
1458 * This procedure is invoked by the image code whenever the manager
1459 * for an image does something that affects the size or contents
1460 * of an image displayed in a button.
1461 *
1462 * Results:
1463 * None.
1464 *
1465 * Side effects:
1466 * Arranges for the HList to get redisplayed.
1467 *
1468 *----------------------------------------------------------------------
1469 */
1470 static void
1471 ImageProc(clientData, x, y, width, height, imgWidth, imgHeight)
1472 ClientData clientData; /* Pointer to widget record. */
1473 int x, y; /* Upper left pixel (within image)
1474 * that must be redisplayed. */
1475 int width, height; /* Dimensions of area to redisplay
1476 * (may be <= 0). */
1477 int imgWidth, imgHeight; /* New dimensions of image. */
1478 {
1479 CmpItemPtr p;
1480
1481 p.image = (CmpImageItem *)clientData;
1482
1483 ChangeImageWhenIdle(p.item->line->masterPtr);
1484 }
1485