Debian Codegraph @

pTk/mTk/tixGeneric/tixDiITxt.c

raw symbols SCIP
1
2 /* $Id: tixDiITxt.c,v 1.2 2000/10/12 02:54:04 idiscovery Exp $ */
3
4 /*
5 * tixDiImgTxt.c --
6 *
7 * This file implements one of the "Display Items" in the Tix library :
8 * Image-text display items.
9 *
10 * Copyright (c) 1996, Expert Interface Technologies
11 *
12 * See the file "license.terms" for information on usage and redistribution
13 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 *
15 */
16
17 #include "tixPort.h"
18 #include "tk.h"
19 #include "tixInt.h"
20 #include "tixDef.h"
21
22 #define DEF_IMAGETEXTITEM_BITMAP ""
23 #define DEF_IMAGETEXTITEM_IMAGE ""
24 #define DEF_IMAGETEXTITEM_TYPE "imagetext"
25 #define DEF_IMAGETEXTITEM_SHOWIMAGE "1"
26 #define DEF_IMAGETEXTITEM_SHOWTEXT "1"
27 #define DEF_IMAGETEXTITEM_STYLE ""
28 #define DEF_IMAGETEXTITEM_TEXT ""
29 #define DEF_IMAGETEXTITEM_UNDERLINE "-1"
30
31 static Tk_ConfigSpec imageTextItemConfigSpecs[] = {
32
33 {TK_CONFIG_BITMAP, "-bitmap", "bitmap", "Bitmap",
34 DEF_IMAGETEXTITEM_BITMAP, Tk_Offset(TixImageTextItem, bitmap),
35 TK_CONFIG_NULL_OK},
36
37 {TK_CONFIG_OBJECT, "-image", "image", "Image",
38 DEF_IMAGETEXTITEM_IMAGE, Tk_Offset(TixImageTextItem, imageString),
39 TK_CONFIG_NULL_OK},
40
41 {TK_CONFIG_CUSTOM, "-itemtype", "itemType", "ItemType",
42 DEF_IMAGETEXTITEM_TYPE, Tk_Offset(TixImageTextItem, diTypePtr),
43 0, &tixConfigItemType},
44
45 {TK_CONFIG_INT, "-showimage", "showImage", "ShowImage",
46 DEF_IMAGETEXTITEM_SHOWIMAGE, Tk_Offset(TixImageTextItem, showImage), 0},
47
48 {TK_CONFIG_INT, "-showtext", "showText", "ShowText",
49 DEF_IMAGETEXTITEM_SHOWTEXT, Tk_Offset(TixImageTextItem, showText), 0},
50
51 {TK_CONFIG_CUSTOM, "-style", "imageTextStyle", "ImageTextStyle",
52 DEF_IMAGETEXTITEM_STYLE, Tk_Offset(TixImageTextItem, stylePtr),
53 TK_CONFIG_NULL_OK, &tixConfigItemStyle},
54
55 {TK_CONFIG_LANGARG, "-text", "text", "Text",
56 DEF_IMAGETEXTITEM_TEXT, Tk_Offset(TixImageTextItem, text),
57 TK_CONFIG_NULL_OK},
58
59 {TK_CONFIG_INT, "-underline", "underline", "Underline",
60 DEF_IMAGETEXTITEM_UNDERLINE, Tk_Offset(TixImageTextItem, underline), 0},
61
62 {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
63 (char *) NULL, 0, 0}
64 };
65
66 /*----------------------------------------------------------------------
67 *
68 * Configuration options for Text Styles
69 *
70 *----------------------------------------------------------------------
71 */
72
73
74 #define SELECTED_BG SELECT_BG
75 #define DISABLED_BG DISABLED
76
77 #define DEF_IMAGETEXTSTYLE_NORMAL_FG_COLOR BLACK
78 #define DEF_IMAGETEXTSTYLE_NORMAL_FG_MONO BLACK
79 #define DEF_IMAGETEXTSTYLE_NORMAL_BG_COLOR NORMAL_BG
80 #define DEF_IMAGETEXTSTYLE_NORMAL_BG_MONO WHITE
81
82 #define DEF_IMAGETEXTSTYLE_ACTIVE_FG_COLOR BLACK
83 #define DEF_IMAGETEXTSTYLE_ACTIVE_FG_MONO WHITE
84 #define DEF_IMAGETEXTSTYLE_ACTIVE_BG_COLOR ACTIVE_BG
85 #define DEF_IMAGETEXTSTYLE_ACTIVE_BG_MONO BLACK
86
87 #define DEF_IMAGETEXTSTYLE_SELECTED_FG_COLOR BLACK
88 #define DEF_IMAGETEXTSTYLE_SELECTED_FG_MONO WHITE
89 #define DEF_IMAGETEXTSTYLE_SELECTED_BG_COLOR SELECTED_BG
90 #define DEF_IMAGETEXTSTYLE_SELECTED_BG_MONO BLACK
91
92 #define DEF_IMAGETEXTSTYLE_DISABLED_FG_COLOR BLACK
93 #define DEF_IMAGETEXTSTYLE_DISABLED_FG_MONO BLACK
94 #define DEF_IMAGETEXTSTYLE_DISABLED_BG_COLOR DISABLED_BG
95 #define DEF_IMAGETEXTSTYLE_DISABLED_BG_MONO WHITE
96
97 #define DEF_IMAGETEXTSTYLE_FONT CTL_FONT
98 #define DEF_IMAGETEXTSTYLE_GAP "4"
99 #define DEF_IMAGETEXTSTYLE_PADX "2"
100 #define DEF_IMAGETEXTSTYLE_PADY "2"
101 #define DEF_IMAGETEXTSTYLE_JUSTIFY "left"
102 #define DEF_IMAGETEXTSTYLE_WLENGTH "0"
103 #define DEF_IMAGETEXTSTYLE_ANCHOR "w"
104 #define DEF_IMAGETEXTSTYLE_TEXTANCHOR "e"
105
106
107 static Tk_ConfigSpec imageTextStyleConfigSpecs[] = {
108 {TK_CONFIG_ANCHOR, "-anchor", "anchor", "Anchor",
109 DEF_IMAGETEXTSTYLE_ANCHOR, Tk_Offset(TixImageTextStyle, anchor), 0},
110
111 {TK_CONFIG_SYNONYM, "-bg", "background", (char *) NULL,
112 (char *) NULL, 0, 0},
113 {TK_CONFIG_SYNONYM, "-fg", "foreground", (char *) NULL,
114 (char *) NULL, 0, 0},
115
116 {TK_CONFIG_FONT, "-font", "font", "Font",
117 DEF_IMAGETEXTSTYLE_FONT, Tk_Offset(TixImageTextStyle, font), 0},
118
119 {TK_CONFIG_PIXELS, "-gap", "gap", "Gap",
120 DEF_IMAGETEXTSTYLE_GAP, Tk_Offset(TixImageTextStyle, gap), 0},
121
122 {TK_CONFIG_JUSTIFY, "-justify", "justify", "Justyfy",
123 DEF_IMAGETEXTSTYLE_JUSTIFY, Tk_Offset(TixImageTextStyle, justify),
124 TK_CONFIG_NULL_OK},
125
126 {TK_CONFIG_PIXELS, "-padx", "padX", "Pad",
127 DEF_IMAGETEXTSTYLE_PADX, Tk_Offset(TixImageTextStyle, pad[0]), 0},
128
129 {TK_CONFIG_PIXELS, "-pady", "padY", "Pad",
130 DEF_IMAGETEXTSTYLE_PADY, Tk_Offset(TixImageTextStyle, pad[1]), 0},
131
132 {TK_CONFIG_ANCHOR, "-textanchor", "textAnchor", "TextAnchor",
133 DEF_IMAGETEXTSTYLE_TEXTANCHOR, Tk_Offset(TixImageTextStyle, textanchor), 0},
134
135 {TK_CONFIG_PIXELS, "-wraplength", "wrapLength", "WrapLength",
136 DEF_IMAGETEXTSTYLE_WLENGTH, Tk_Offset(TixImageTextStyle, wrapLength),
137 0},
138
139 /* The following is automatically generated */
140 {TK_CONFIG_COLOR,"-background","background","Background",
141 DEF_IMAGETEXTSTYLE_NORMAL_BG_COLOR,
142 Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_NORMAL].bg),
143 TK_CONFIG_COLOR_ONLY},
144 {TK_CONFIG_COLOR,"-background","background","Background",
145 DEF_IMAGETEXTSTYLE_NORMAL_BG_MONO,
146 Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_NORMAL].bg),
147 TK_CONFIG_MONO_ONLY},
148 {TK_CONFIG_COLOR,"-foreground","foreground","Foreground",
149 DEF_IMAGETEXTSTYLE_NORMAL_FG_COLOR,
150 Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_NORMAL].fg),
151 TK_CONFIG_COLOR_ONLY},
152 {TK_CONFIG_COLOR,"-foreground","foreground","Foreground",
153 DEF_IMAGETEXTSTYLE_NORMAL_FG_MONO,
154 Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_NORMAL].fg),
155 TK_CONFIG_MONO_ONLY},
156 {TK_CONFIG_COLOR,"-activebackground","activeBackground","ActiveBackground",
157 DEF_IMAGETEXTSTYLE_ACTIVE_BG_COLOR,
158 Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_ACTIVE].bg),
159 TK_CONFIG_COLOR_ONLY},
160 {TK_CONFIG_COLOR,"-activebackground","activeBackground","ActiveBackground",
161 DEF_IMAGETEXTSTYLE_ACTIVE_BG_MONO,
162 Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_ACTIVE].bg),
163 TK_CONFIG_MONO_ONLY},
164 {TK_CONFIG_COLOR,"-activeforeground","activeForeground","ActiveForeground",
165 DEF_IMAGETEXTSTYLE_ACTIVE_FG_COLOR,
166 Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_ACTIVE].fg),
167 TK_CONFIG_COLOR_ONLY},
168 {TK_CONFIG_COLOR,"-activeforeground","activeForeground","ActiveForeground",
169 DEF_IMAGETEXTSTYLE_ACTIVE_FG_MONO,
170 Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_ACTIVE].fg),
171 TK_CONFIG_MONO_ONLY},
172 {TK_CONFIG_COLOR,"-selectbackground","selectBackground","SelectBackground",
173 DEF_IMAGETEXTSTYLE_SELECTED_BG_COLOR,
174 Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_SELECTED].bg),
175 TK_CONFIG_COLOR_ONLY},
176 {TK_CONFIG_COLOR,"-selectbackground","selectBackground","SelectBackground",
177 DEF_IMAGETEXTSTYLE_SELECTED_BG_MONO,
178 Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_SELECTED].bg),
179 TK_CONFIG_MONO_ONLY},
180 {TK_CONFIG_COLOR,"-selectforeground","selectForeground","SelectForeground",
181 DEF_IMAGETEXTSTYLE_SELECTED_FG_COLOR,
182 Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_SELECTED].fg),
183 TK_CONFIG_COLOR_ONLY},
184 {TK_CONFIG_COLOR,"-selectforeground","selectForeground","SelectForeground",
185 DEF_IMAGETEXTSTYLE_SELECTED_FG_MONO,
186 Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_SELECTED].fg),
187 TK_CONFIG_MONO_ONLY},
188 {TK_CONFIG_COLOR,"-disabledbackground","disabledBackground","DisabledBackground",
189 DEF_IMAGETEXTSTYLE_DISABLED_BG_COLOR,
190 Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_DISABLED].bg),
191 TK_CONFIG_COLOR_ONLY},
192 {TK_CONFIG_COLOR,"-disabledbackground","disabledBackground","DisabledBackground",
193 DEF_IMAGETEXTSTYLE_DISABLED_BG_MONO,
194 Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_DISABLED].bg),
195 TK_CONFIG_MONO_ONLY},
196 {TK_CONFIG_COLOR,"-disabledforeground","disabledForeground","DisabledForeground",
197 DEF_IMAGETEXTSTYLE_DISABLED_FG_COLOR,
198 Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_DISABLED].fg),
199 TK_CONFIG_COLOR_ONLY},
200 {TK_CONFIG_COLOR,"-disabledforeground","disabledForeground","DisabledForeground",
201 DEF_IMAGETEXTSTYLE_DISABLED_FG_MONO,
202 Tk_Offset(TixImageTextStyle,colors[TIX_DITEM_DISABLED].fg),
203 TK_CONFIG_MONO_ONLY},
204
205 {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
206 (char *) NULL, 0, 0}
207 };
208
209 /*----------------------------------------------------------------------
210 * Forward declarations for procedures defined later in this file:
211 *----------------------------------------------------------------------
212 */
213 static void ImageProc _ANSI_ARGS_((ClientData clientData,
214 int x, int y, int width, int height,
215 int imgWidth, int imgHeight));
216 static void Tix_ImageTextItemCalculateSize _ANSI_ARGS_((
217 Tix_DItem * iPtr));
218 static char * Tix_ImageTextItemComponent _ANSI_ARGS_((
219 Tix_DItem * iPtr, int x, int y));
220 static int Tix_ImageTextItemConfigure _ANSI_ARGS_((
221 Tix_DItem * iPtr, int argc, char ** argv,
222 int flags));
223 static Tix_DItem * Tix_ImageTextItemCreate _ANSI_ARGS_((
224 Tix_DispData * ddPtr, Tix_DItemInfo * diTypePtr));
225 static void Tix_ImageTextItemDisplay _ANSI_ARGS_((
226 Pixmap pixmap, GC gc, Tix_DItem * iPtr,
227 int x, int y, int width, int height, int flag));
228 static void Tix_ImageTextItemFree _ANSI_ARGS_((
229 Tix_DItem * iPtr));
230 static void Tix_ImageTextItemLostStyle _ANSI_ARGS_((
231 Tix_DItem * iPtr));
232 static void Tix_ImageTextItemStyleChanged _ANSI_ARGS_((
233 Tix_DItem * iPtr));
234 static int Tix_ImageTextStyleConfigure _ANSI_ARGS_((
235 Tix_DItemStyle* style, int argc, char ** argv,
236 int flags));
237 static Tix_DItemStyle * Tix_ImageTextStyleCreate _ANSI_ARGS_((
238 Tcl_Interp *interp, Tk_Window tkwin,
239 Tix_DItemInfo * diTypePtr, char * name));
240 static void Tix_ImageTextStyleFree _ANSI_ARGS_((
241 Tix_DItemStyle* style));
242 static void Tix_ImageTextStyleSetTemplate _ANSI_ARGS_((
243 Tix_DItemStyle* style,
244 Tix_StyleTemplate * tmplPtr));
245
246 Tix_DItemInfo tix_ImageTextItemType = {
247 "imagetext", /* type */
248 TIX_DITEM_IMAGETEXT,
249 Tix_ImageTextItemCreate, /* createProc */
250 Tix_ImageTextItemConfigure,
251 Tix_ImageTextItemCalculateSize,
252 Tix_ImageTextItemComponent,
253 Tix_ImageTextItemDisplay,
254 Tix_ImageTextItemFree,
255 Tix_ImageTextItemStyleChanged,
256 Tix_ImageTextItemLostStyle,
257
258 Tix_ImageTextStyleCreate,
259 Tix_ImageTextStyleConfigure,
260 Tix_ImageTextStyleFree,
261 Tix_ImageTextStyleSetTemplate,
262
263 imageTextItemConfigSpecs,
264 imageTextStyleConfigSpecs,
265 NULL, /*next */
266 };
267
268
269 /*----------------------------------------------------------------------
270 * Tix_ImageText --
271 *
272 *
273 *----------------------------------------------------------------------
274 */
275 static Tix_DItem * Tix_ImageTextItemCreate(ddPtr, diTypePtr)
276 Tix_DispData * ddPtr;
277 Tix_DItemInfo * diTypePtr;
278 {
279 TixImageTextItem * itPtr;
280
281 itPtr = (TixImageTextItem*) ckalloc(sizeof(TixImageTextItem));
282
283 itPtr->diTypePtr = diTypePtr;
284 itPtr->ddPtr = ddPtr;
285 itPtr->stylePtr = NULL;
286 itPtr->clientData = 0;
287 itPtr->size[0] = 0;
288 itPtr->size[1] = 0;
289
290 itPtr->bitmap = None;
291 itPtr->bitmapW = 0;
292 itPtr->bitmapH = 0;
293
294 itPtr->imageString = NULL;
295 itPtr->image = NULL;
296 itPtr->imageW = 0;
297 itPtr->imageH = 0;
298
299 itPtr->numChars = 0;
300 itPtr->text = NULL;
301 itPtr->textW = 0;
302 itPtr->textH = 0;
303 itPtr->underline = -1;
304
305 itPtr->showImage = 1;
306 itPtr->showText = 1;
307
308 return (Tix_DItem *)itPtr;
309 }
310
311 static void Tix_ImageTextItemFree(iPtr)
312 Tix_DItem * iPtr;
313 {
314 TixImageTextItem * itPtr = (TixImageTextItem *) iPtr;
315
316 if (itPtr->image) {
317 Tk_FreeImage(itPtr->image);
318 }
319 if (itPtr->stylePtr) {
320 TixDItemStyleFree(iPtr, (Tix_DItemStyle*)itPtr->stylePtr);
321 }
322
323 Tk_FreeOptions(imageTextItemConfigSpecs, (char *)itPtr,
324 itPtr->ddPtr->display, 0);
325 ckfree((char*)itPtr);
326 }
327
328 static int Tix_ImageTextItemConfigure(iPtr, argc, argv, flags)
329 Tix_DItem * iPtr;
330 int argc;
331 char ** argv;
332 int flags;
333 {
334 TixImageTextItem * itPtr = (TixImageTextItem *) iPtr;
335 TixImageTextStyle * oldStyle = itPtr->stylePtr;
336
337 if (Tk_ConfigureWidget(itPtr->ddPtr->interp, itPtr->ddPtr->tkwin,
338 imageTextItemConfigSpecs,
339 argc, argv, (char *)itPtr, flags) != TCL_OK) {
340 return TCL_ERROR;
341 }
342 if (itPtr->stylePtr == NULL) {
343 itPtr->stylePtr = (TixImageTextStyle*)TixGetDefaultDItemStyle(
344 itPtr->ddPtr, &tix_ImageTextItemType, iPtr, NULL);
345 }
346
347 /*
348 * Free the old images for the widget, if there were any.
349 */
350 if (itPtr->image != NULL) {
351 Tk_FreeImage(itPtr->image);
352 itPtr->image = NULL;
353 }
354
355 if (itPtr->imageString != NULL) {
356 itPtr->image = Tk_GetImage(itPtr->ddPtr->interp, itPtr->ddPtr->tkwin,
357 itPtr->imageString, ImageProc, (ClientData) itPtr);
358 if (itPtr->image == NULL) {
359 return TCL_ERROR;
360 }
361 }
362
363 if (oldStyle != NULL && itPtr->stylePtr != oldStyle) {
364 Tix_ImageTextItemStyleChanged(iPtr);
365 }
366 else {
367 Tix_ImageTextItemCalculateSize((Tix_DItem*)itPtr);
368 }
369
370 return TCL_OK;
371 }
372
373 static void Tix_ImageTextItemDisplay(pixmap, gc, iPtr, x, y,
374 width, height, flags)
375 Pixmap pixmap;
376 GC gc;
377 Tix_DItem * iPtr;
378 int x;
379 int y;
380 int width;
381 int height;
382 int flags;
383 {
384 TixImageTextItem *itPtr = (TixImageTextItem *)iPtr;
385 GC foreGC, backGC;
386 TixpSubRegion subReg;
387 int bitY;
388 int bitX;
389 int textY;
390 int textX;
391 int imageH = 0;
392 int imageW = 0;
393
394 if ((width <= 0) || (height <= 0)) {
395 return;
396 }
397
398 TixGetColorDItemGC(iPtr, &backGC, &foreGC, flags);
399 TixpStartSubRegionDraw(itPtr->ddPtr, pixmap, foreGC,
400 &subReg, 0, 0, x, y, width, height,
401 itPtr->size[0], itPtr->size[1]);
402
403 if (backGC != None) {
404 TixpSubRegFillRectangle(itPtr->ddPtr->display, pixmap,
405 backGC, &subReg, x, y, width, height);
406 }
407
408 TixDItemGetAnchor(itPtr->stylePtr->anchor, x, y, width, height,
409 itPtr->size[0], itPtr->size[1], &x, &y);
410
411
412 if (itPtr->image != NULL)
413 {
414 imageH = itPtr->imageH;
415 imageW = itPtr->imageW;
416 }
417 else if (itPtr->bitmap != None)
418 {
419 imageH = itPtr->bitmapH;
420 imageW = itPtr->bitmapW;
421 }
422
423 bitX = textX = x + itPtr->stylePtr->pad[0];
424 bitY = textY = y + itPtr->stylePtr->pad[1];
425 /* Adjust X position according to textanchor */
426 switch(itPtr->stylePtr->textanchor) {
427 case TK_ANCHOR_NW:
428 case TK_ANCHOR_SW:
429 case TK_ANCHOR_W:
430 bitX += itPtr->textW + itPtr->stylePtr->gap;
431 break;
432 case TK_ANCHOR_NE:
433 case TK_ANCHOR_SE:
434 case TK_ANCHOR_E:
435 textX += imageW + itPtr->stylePtr->gap;
436 break;
437 default:
438 bitX = itPtr->size[0] - imageW - 2*itPtr->stylePtr->pad[0];
439
440 if (bitX > 0) {
441 bitX = bitX / 2 + (bitX %2);
442 } else {
443 bitX = 0;
444 }
445 bitX += x;
446 textX = itPtr->size[0] - itPtr->textW - 2*itPtr->stylePtr->pad[0];
447 if (textX > 0) {
448 textX = textX / 2 + (textX %2);
449 } else {
450 textX = 0;
451 }
452 textX += x;
453 break;
454 }
455 /* Adjust Y position according to textanchor */
456 switch(itPtr->stylePtr->textanchor) {
457 case TK_ANCHOR_NW:
458 case TK_ANCHOR_NE:
459 case TK_ANCHOR_N:
460 bitY += itPtr->textH + itPtr->stylePtr->gap;
461 break;
462 case TK_ANCHOR_SE:
463 case TK_ANCHOR_SW:
464 case TK_ANCHOR_S:
465 textY += imageH + itPtr->stylePtr->gap;
466 break;
467 default:
468 bitY = itPtr->size[1] - imageH - 2*itPtr->stylePtr->pad[1];
469
470 if (bitY > 0) {
471 bitY = bitY / 2 + (bitY %2);
472 } else {
473 bitY = 0;
474 }
475 bitY += y;
476 textY = itPtr->size[1] - itPtr->textH - 2*itPtr->stylePtr->pad[1];
477 if (textY > 0) {
478 textY = textY / 2 + (textY %2);
479 } else {
480 textY = 0;
481 }
482 textY += y;
483 break;
484 }
485
486 if (itPtr->image != NULL) {
487 if (itPtr->showImage) {
488 TixpSubRegDrawImage(&subReg, itPtr->image, 0, 0,
489 itPtr->imageW, itPtr->imageH, pixmap, bitX, bitY);
490 }
491 }
492 else if (itPtr->bitmap != None && foreGC != None) {
493 if (itPtr->showImage) {
494 TixpSubRegDrawBitmap(itPtr->ddPtr->display, pixmap, foreGC,
495 &subReg, itPtr->bitmap, 0, 0,
496 itPtr->bitmapW, itPtr->bitmapH,
497 bitX, bitY, 1);
498 }
499 }
500
501 if (itPtr->text && itPtr->showText && foreGC != None) {
502 TixpSubRegDisplayText(itPtr->ddPtr->display, pixmap, foreGC, &subReg,
503 itPtr->stylePtr->font, Tcl_GetString(itPtr->text), itPtr->numChars,
504 textX, textY,
505 itPtr->textW,
506 itPtr->stylePtr->justify,
507 itPtr->underline);
508 }
509
510 TixpEndSubRegionDraw(itPtr->ddPtr->display, pixmap, foreGC,
511 &subReg);
512 }
513
514 static void Tix_ImageTextItemCalculateSize(iPtr)
515 Tix_DItem * iPtr;
516 {
517 TixImageTextItem *itPtr = (TixImageTextItem *)iPtr;
518
519 itPtr->size[0] = 0;
520 itPtr->size[1] = 0;
521
522 /* Note: the size of the image or the text are used even when
523 * the showImage or showText options are off. These two options are
524 * used to "blank" the respective components temporarily without
525 * affecting the geometry of the ditem. The main is to indicate
526 * transfer during drag+drop.
527 *
528 * If you want the image or text to completely disappear, config them
529 * to NULL
530 */
531 if (itPtr->image != NULL) {
532 Tk_SizeOfImage(itPtr->image, &itPtr->imageW, &itPtr->imageH);
533
534 itPtr->size[0] = itPtr->imageW;
535 itPtr->size[1] = itPtr->imageH;
536 }
537 else if (itPtr->bitmap != None) {
538 Tk_SizeOfBitmap(itPtr->ddPtr->display, itPtr->bitmap, &itPtr->bitmapW,
539 &itPtr->bitmapH);
540
541 itPtr->size[0] = itPtr->bitmapW;
542 itPtr->size[1] = itPtr->bitmapH;
543 }
544
545 if (itPtr->text) {
546 itPtr->numChars = strlen(Tcl_GetString(itPtr->text));
547 TixComputeTextGeometry(itPtr->stylePtr->font, Tcl_GetString(itPtr->text),
548 itPtr->numChars, itPtr->stylePtr->wrapLength,
549 &itPtr->textW, &itPtr->textH);
550 /* Adjust size[0] i.e. X for EW-ness */
551 switch(itPtr->stylePtr->textanchor) {
552 case TK_ANCHOR_SE: case TK_ANCHOR_SW:
553 case TK_ANCHOR_NE: case TK_ANCHOR_NW:
554 case TK_ANCHOR_E: case TK_ANCHOR_W:
555 itPtr->size[0] += itPtr->stylePtr->gap;
556 itPtr->size[0] += itPtr->textW;
557 break;
558 case TK_ANCHOR_CENTER:
559 case TK_ANCHOR_N: case TK_ANCHOR_S:
560 if (itPtr->textW > itPtr->size[0]) {
561 itPtr->size[0] = itPtr->textW;
562 }
563 break;
564 }
565 /* Adjust size[1] i.e. Y for NS-ness */
566 switch(itPtr->stylePtr->textanchor) {
567 case TK_ANCHOR_NW: case TK_ANCHOR_NE:
568 case TK_ANCHOR_SW: case TK_ANCHOR_SE:
569 case TK_ANCHOR_N: case TK_ANCHOR_S:
570 itPtr->size[1] += itPtr->stylePtr->gap;
571 itPtr->size[1] += itPtr->textH;
572 break;
573 case TK_ANCHOR_CENTER:
574 case TK_ANCHOR_E: case TK_ANCHOR_W:
575 if (itPtr->textH > itPtr->size[1]) {
576 itPtr->size[1] = itPtr->textH;
577 }
578 break;
579 }
580 }
581
582 itPtr->size[0] += 2*itPtr->stylePtr->pad[0];
583 itPtr->size[1] += 2*itPtr->stylePtr->pad[1];
584 }
585
586 static char * Tix_ImageTextItemComponent(iPtr, x, y)
587 Tix_DItem * iPtr;
588 int x;
589 int y;
590 {
591 /* Unimplemented */
592 #if 0
593 TixImageTextItem *itPtr = (TixImageTextItem *)iPtr;
594 #endif
595
596 static char * body = "body";
597
598 return body;
599 }
600
601
602 static void Tix_ImageTextItemStyleChanged(iPtr)
603 Tix_DItem * iPtr;
604 {
605 TixImageTextItem *itPtr = (TixImageTextItem *)iPtr;
606
607 if (itPtr->stylePtr == NULL) {
608 /* Maybe we haven't set the style to default style yet */
609 return;
610 }
611 Tix_ImageTextItemCalculateSize(iPtr);
612 if (itPtr->ddPtr->sizeChangedProc != NULL) {
613 itPtr->ddPtr->sizeChangedProc(iPtr);
614 }
615 }
616 static void Tix_ImageTextItemLostStyle(iPtr)
617 Tix_DItem * iPtr;
618 {
619 TixImageTextItem *itPtr = (TixImageTextItem *)iPtr;
620
621 itPtr->stylePtr = (TixImageTextStyle*)TixGetDefaultDItemStyle(
622 itPtr->ddPtr, &tix_ImageTextItemType, iPtr, NULL);
623
624 Tix_ImageTextItemStyleChanged(iPtr);
625 }
626
627 /*
628 *----------------------------------------------------------------------
629 *
630 * ImageProc --
631 *
632 * This procedure is invoked by the image code whenever the manager
633 * for an image does something that affects the size of contents
634 * of an image displayed in this widget.
635 *
636 * Results:
637 * None.
638 *
639 * Side effects:
640 * Arranges for the HList to get redisplayed.
641 *
642 *----------------------------------------------------------------------
643 */
644 static void
645 ImageProc(clientData, x, y, width, height, imgWidth, imgHeight)
646 ClientData clientData; /* Pointer to widget record. */
647 int x, y; /* Upper left pixel (within image)
648 * that must be redisplayed. */
649 int width, height; /* Dimensions of area to redisplay
650 * (may be <= 0). */
651 int imgWidth, imgHeight; /* New dimensions of image. */
652 {
653 TixImageTextItem *itPtr = (TixImageTextItem *)clientData;
654
655 Tix_ImageTextItemCalculateSize((Tix_DItem *)itPtr);
656 if (itPtr->ddPtr->sizeChangedProc != NULL) {
657 itPtr->ddPtr->sizeChangedProc((Tix_DItem *)itPtr);
658 }
659 }
660
661 /*----------------------------------------------------------------------
662 *
663 *
664 * Display styles
665 *
666 *
667 *----------------------------------------------------------------------
668 */
669 static Tix_DItemStyle *
670 Tix_ImageTextStyleCreate(interp, tkwin, diTypePtr, name)
671 Tcl_Interp * interp;
672 Tk_Window tkwin;
673 char * name;
674 Tix_DItemInfo * diTypePtr;
675 {
676 int i;
677 TixImageTextStyle * stylePtr =
678 (TixImageTextStyle *)ckalloc(sizeof(TixImageTextStyle));
679
680 stylePtr->font = NULL;
681 stylePtr->gap = 0;
682 stylePtr->textanchor = TK_ANCHOR_E;
683 stylePtr->justify = TK_JUSTIFY_LEFT;
684 stylePtr->wrapLength = 0;
685 stylePtr->pad[0] = 0;
686 stylePtr->pad[1] = 0;
687 stylePtr->anchor = TK_ANCHOR_CENTER;
688
689 for (i=0; i<4; i++) {
690 stylePtr->colors[i].bg = NULL;
691 stylePtr->colors[i].fg = NULL;
692 stylePtr->colors[i].backGC = None;
693 stylePtr->colors[i].foreGC = NULL;
694 }
695
696 return (Tix_DItemStyle *)stylePtr;
697 }
698
699 static int
700 Tix_ImageTextStyleConfigure(style, argc, argv, flags)
701 Tix_DItemStyle *style;
702 int argc;
703 char ** argv;
704 int flags;
705 {
706 TixImageTextStyle * stylePtr = (TixImageTextStyle *)style;
707 XGCValues gcValues;
708 GC newGC;
709 int i, isNew;
710
711 if (stylePtr->font == NULL) {
712 isNew = 1;
713 } else {
714 isNew = 0;
715 }
716
717 if (!(flags &TIX_DONT_CALL_CONFIG)) {
718 if (Tk_ConfigureWidget(stylePtr->interp, stylePtr->tkwin,
719 imageTextStyleConfigSpecs,
720 argc, argv, (char *)stylePtr, flags) != TCL_OK) {
721 return TCL_ERROR;
722 }
723 }
724
725 gcValues.font = TixFontId(stylePtr->font);
726 gcValues.graphics_exposures = False;
727
728 for (i=0; i<4; i++) {
729 /* Foreground */
730 gcValues.background = stylePtr->colors[i].bg->pixel;
731 gcValues.foreground = stylePtr->colors[i].fg->pixel;
732 newGC = Tk_GetGC(stylePtr->tkwin,
733 GCFont|GCForeground|GCBackground|GCGraphicsExposures, &gcValues);
734
735 if (stylePtr->colors[i].foreGC != None) {
736 Tk_FreeGC(Tk_Display(stylePtr->tkwin),
737 stylePtr->colors[i].foreGC);
738 }
739 stylePtr->colors[i].foreGC = newGC;
740
741 /* Background */
742 gcValues.foreground = stylePtr->colors[i].bg->pixel;
743 newGC = Tk_GetGC(stylePtr->tkwin,
744 GCFont|GCForeground|GCGraphicsExposures, &gcValues);
745
746 if (stylePtr->colors[i].backGC != None) {
747 Tk_FreeGC(Tk_Display(stylePtr->tkwin),
748 stylePtr->colors[i].backGC);
749 }
750 stylePtr->colors[i].backGC = newGC;
751 }
752
753 if (!isNew) {
754 TixDItemStyleChanged(stylePtr->diTypePtr, (Tix_DItemStyle *)stylePtr);
755 }
756
757 return TCL_OK;
758 }
759
760 static void Tix_ImageTextStyleFree(style)
761 Tix_DItemStyle *style;
762 {
763 TixImageTextStyle * stylePtr = (TixImageTextStyle *)style;
764 int i;
765
766 for (i=0; i<4; i++) {
767 if (stylePtr->colors[i].backGC != None) {
768 Tk_FreeGC(Tk_Display(stylePtr->tkwin), stylePtr->colors[i].backGC);
769 }
770 if (stylePtr->colors[i].foreGC != None) {
771 Tk_FreeGC(Tk_Display(stylePtr->tkwin), stylePtr->colors[i].foreGC);
772 }
773 }
774
775 Tk_FreeOptions(imageTextStyleConfigSpecs, (char *)stylePtr,
776 Tk_Display(stylePtr->tkwin), 0);
777 ckfree((char *)stylePtr);
778 }
779
780 static int bg_flags [4] = {
781 TIX_DITEM_NORMAL_BG,
782 TIX_DITEM_ACTIVE_BG,
783 TIX_DITEM_SELECTED_BG,
784 TIX_DITEM_DISABLED_BG
785 };
786 static int fg_flags [4] = {
787 TIX_DITEM_NORMAL_FG,
788 TIX_DITEM_ACTIVE_FG,
789 TIX_DITEM_SELECTED_FG,
790 TIX_DITEM_DISABLED_FG
791 };
792
793 static void
794 Tix_ImageTextStyleSetTemplate(style, tmplPtr)
795 Tix_DItemStyle* style;
796 Tix_StyleTemplate * tmplPtr;
797 {
798 TixImageTextStyle * stylePtr = (TixImageTextStyle *)style;
799 int i;
800
801 if (tmplPtr->flags & TIX_DITEM_FONT) {
802 if (stylePtr->font != NULL) {
803 TixFreeFont(stylePtr->font);
804 }
805 stylePtr->font = TixGetFont(
806 stylePtr->interp, stylePtr->tkwin,
807 TixNameOfFont(tmplPtr->font));
808 }
809 if (tmplPtr->flags & TIX_DITEM_PADX) {
810 stylePtr->pad[0] = tmplPtr->pad[0];
811 }
812 if (tmplPtr->flags & TIX_DITEM_PADY) {
813 stylePtr->pad[1] = tmplPtr->pad[1];
814 }
815
816 for (i=0; i<4; i++) {
817 if (tmplPtr->flags & bg_flags[i]) {
818 if (stylePtr->colors[i].bg != NULL) {
819 Tk_FreeColor(stylePtr->colors[i].bg);
820 }
821 stylePtr->colors[i].bg = Tk_GetColor(
822 stylePtr->interp, stylePtr->tkwin,
823 Tk_NameOfColor(tmplPtr->colors[i].bg));
824 }
825 }
826 for (i=0; i<4; i++) {
827 if (tmplPtr->flags & fg_flags[i]) {
828 if (stylePtr->colors[i].fg != NULL) {
829 Tk_FreeColor(stylePtr->colors[i].fg);
830 }
831 stylePtr->colors[i].fg = Tk_GetColor(
832 stylePtr->interp, stylePtr->tkwin,
833 Tk_NameOfColor(tmplPtr->colors[i].fg));
834 }
835 }
836
837 Tix_ImageTextStyleConfigure(style, 0, 0, TIX_DONT_CALL_CONFIG);
838 }