Debian Codegraph @

pTk/mTk/tixGeneric/tixGrFmt.c

raw symbols SCIP
1
2 /* $Id: tixGrFmt.c,v 1.1.1.1 2000/05/17 11:08:42 idiscovery Exp $ */
3
4 /*
5 * tixGrFmt.c --
6 *
7 * This module handles the formatting of the elements inside a Grid
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
16 #include "tixPort.h"
17 #include "tixInt.h"
18 #include "tixDef.h"
19 #include "tixGrid.h"
20
21 typedef struct FormatStruct {
22 int x1, y1, x2, y2;
23 } FormatStruct;
24
25 typedef struct BorderFmtStruct {
26 int x1, y1, x2, y2;
27 Tk_3DBorder border;
28 Tk_3DBorder selectBorder; /* the border color color */
29 int borderWidth; /* Width of 3-D borders. */
30 int relief; /* Indicates whether window as a whole is
31 * raised, sunken, or flat. */
32 int xon, xoff;
33 int yon, yoff;
34 int filled;
35 } BorderFmtStruct;
36
37 typedef struct GridFmtStruct {
38 int x1, y1, x2, y2;
39 Tk_3DBorder border; /* the border color color */
40 Tk_3DBorder selectBorder; /* the border color color */
41 Tk_3DBorder bgBorder; /* the background color */
42 int borderWidth; /* Width of 3-D borders. */
43 int relief; /* Indicates whether window as a whole is
44 * raised, sunken, or flat. */
45 int xon, xoff;
46 int yon, yoff;
47 Tk_Anchor anchor;
48 int filled;
49 } GridFmtStruct;
50
51 static TIX_DECLARE_SUBCMD(Tix_GrFormatBorder);
52 static TIX_DECLARE_SUBCMD(Tix_GrFormatGrid);
53 EXTERN TIX_DECLARE_SUBCMD(Tix_GrFormat);
54
55 static int Tix_GrSaveColor _ANSI_ARGS_((WidgetPtr wPtr,
56 int type, void * ptr));
57 static void GetBlockPosn _ANSI_ARGS_((WidgetPtr wPtr, int x1,
58 int y1, int x2, int y2, int * bx1, int * by1,
59 int * bx2, int * by2));
60 static void GetRenderPosn _ANSI_ARGS_((WidgetPtr wPtr,
61 int bx1, int by1, int bx2, int by2, int * rx1,
62 int * ry1, int * rx2, int * ry2));
63 static void Tix_GrFillCells _ANSI_ARGS_((WidgetPtr wPtr,
64 Tk_3DBorder border, Tk_3DBorder selectBorder,
65 int bx1, int by1, int bx2, int by2,
66 int borderWidth, int relief, int filled,
67 int bw[2][2]));
68 static int GetInfo _ANSI_ARGS_((WidgetPtr wPtr,
69 Tcl_Interp *interp, int argc, char **argv,
70 FormatStruct * infoPtr,
71 Tk_ConfigSpec * configSpecs));
72
73 #define DEF_GRID_ANCHOR "se"
74 #define DEF_GRID_BORDER_XOFF "0"
75 #define DEF_GRID_BORDER_XON "1"
76 #define DEF_GRID_BORDER_YOFF "0"
77 #define DEF_GRID_BORDER_YON "1"
78 #define DEF_GRID_GRIDLINE_XOFF "0"
79 #define DEF_GRID_GRIDLINE_XON "1"
80 #define DEF_GRID_GRIDLINE_YOFF "0"
81 #define DEF_GRID_GRIDLINE_YON "1"
82 #define DEF_GRID_FILLED "0"
83 #define DEF_GRID_BORDER_COLOR NORMAL_BG
84 #define DEF_GRID_BORDER_MONO WHITE
85 #define DEF_GRID_GRIDLINE_COLOR BLACK
86 #define DEF_GRID_GRIDLINE_MONO BLACK
87
88 static Tk_ConfigSpec borderConfigSpecs[] = {
89 {TK_CONFIG_BORDER, "-background", "background", "Background",
90 DEF_GRID_BG_COLOR, Tk_Offset(BorderFmtStruct, border),
91 TK_CONFIG_COLOR_ONLY},
92 {TK_CONFIG_BORDER, "-background", "background", "Background",
93 DEF_GRID_BG_MONO, Tk_Offset(BorderFmtStruct, border),
94 TK_CONFIG_MONO_ONLY},
95 {TK_CONFIG_SYNONYM, "-bd", "borderWidth", (char *) NULL,
96 (char *) NULL, 0, 0},
97 {TK_CONFIG_SYNONYM, "-bg", "background", (char *) NULL,
98 (char *) NULL, 0, 0},
99 {TK_CONFIG_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
100 DEF_GRID_BORDER_WIDTH, Tk_Offset(BorderFmtStruct, borderWidth), 0},
101 {TK_CONFIG_BOOLEAN, "-filled", "filled", "Filled",
102 DEF_GRID_FILLED, Tk_Offset(BorderFmtStruct, filled), 0},
103 {TK_CONFIG_RELIEF, "-relief", "relief", "Relief",
104 DEF_GRID_RELIEF, Tk_Offset(BorderFmtStruct, relief), 0},
105 {TK_CONFIG_BORDER, "-selectbackground", "selectBackground", "Foreground",
106 DEF_GRID_SELECT_BG_COLOR, Tk_Offset(BorderFmtStruct, selectBorder),
107 TK_CONFIG_COLOR_ONLY},
108 {TK_CONFIG_BORDER, "-selectbackground", "selectBackground", "Foreground",
109 DEF_GRID_SELECT_BG_MONO, Tk_Offset(BorderFmtStruct, selectBorder),
110 TK_CONFIG_MONO_ONLY},
111 {TK_CONFIG_INT, "-xoff", "xoff", "Xoff",
112 DEF_GRID_BORDER_XOFF, Tk_Offset(BorderFmtStruct, xoff), 0},
113 {TK_CONFIG_INT, "-xon", "xon", "Xon",
114 DEF_GRID_BORDER_XON, Tk_Offset(BorderFmtStruct, xon), 0},
115 {TK_CONFIG_INT, "-yoff", "yoff", "Yoff",
116 DEF_GRID_BORDER_YOFF, Tk_Offset(BorderFmtStruct, yoff), 0},
117 {TK_CONFIG_INT, "-yon", "yon", "Yon",
118 DEF_GRID_BORDER_YON, Tk_Offset(BorderFmtStruct, yon), 0},
119
120 {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
121 (char *) NULL, 0, 0}
122 };
123
124 static Tk_ConfigSpec gridConfigSpecs[] = {
125 {TK_CONFIG_ANCHOR, "-anchor", "anchor", "Anchor",
126 DEF_GRID_ANCHOR, Tk_Offset(GridFmtStruct, anchor), 0},
127 {TK_CONFIG_BORDER, "-background", "background", "Background",
128 DEF_GRID_BG_COLOR, Tk_Offset(GridFmtStruct, bgBorder),
129 TK_CONFIG_COLOR_ONLY},
130 {TK_CONFIG_BORDER, "-background", "background", "Background",
131 DEF_GRID_BG_COLOR, Tk_Offset(GridFmtStruct, bgBorder),
132 TK_CONFIG_MONO_ONLY},
133 {TK_CONFIG_BORDER, "-bordercolor", "borderColor", "BorderColor",
134 DEF_GRID_GRIDLINE_COLOR, Tk_Offset(GridFmtStruct, border),
135 TK_CONFIG_COLOR_ONLY},
136 {TK_CONFIG_BORDER, "-bordercolor", "borderColor", "BorderColor",
137 DEF_GRID_GRIDLINE_MONO, Tk_Offset(GridFmtStruct, border),
138 TK_CONFIG_MONO_ONLY},
139 {TK_CONFIG_SYNONYM, "-bd", "borderWidth", (char *) NULL,
140 (char *) NULL, 0, 0},
141 {TK_CONFIG_SYNONYM, "-bg", "background", (char *) NULL,
142 (char *) NULL, 0, 0},
143 {TK_CONFIG_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
144 DEF_GRID_BORDER_WIDTH, Tk_Offset(GridFmtStruct, borderWidth), 0},
145 {TK_CONFIG_BOOLEAN, "-filled", "filled", "Filled",
146 DEF_GRID_FILLED, Tk_Offset(GridFmtStruct, filled), 0},
147 {TK_CONFIG_RELIEF, "-relief", "relief", "Relief",
148 DEF_GRID_RELIEF, Tk_Offset(GridFmtStruct, relief), 0},
149 {TK_CONFIG_BORDER, "-selectbackground", "selectBackground", "Foreground",
150 DEF_GRID_SELECT_BG_COLOR, Tk_Offset(GridFmtStruct, selectBorder),
151 TK_CONFIG_COLOR_ONLY},
152 {TK_CONFIG_BORDER, "-selectbackground", "selectBackground", "Foreground",
153 DEF_GRID_SELECT_BG_MONO, Tk_Offset(GridFmtStruct, selectBorder),
154 TK_CONFIG_MONO_ONLY},
155 {TK_CONFIG_INT, "-xoff", "xoff", "Xoff",
156 DEF_GRID_GRIDLINE_XOFF, Tk_Offset(GridFmtStruct, xoff), 0},
157 {TK_CONFIG_INT, "-xon", "xon", "Xon",
158 DEF_GRID_GRIDLINE_XON, Tk_Offset(GridFmtStruct, xon), 0},
159 {TK_CONFIG_INT, "-yoff", "yoff", "Yoff",
160 DEF_GRID_GRIDLINE_YOFF, Tk_Offset(GridFmtStruct, yoff), 0},
161 {TK_CONFIG_INT, "-yon", "yon", "Yon",
162 DEF_GRID_GRIDLINE_YON, Tk_Offset(GridFmtStruct, yon), 0},
163
164 {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
165 (char *) NULL, 0, 0}
166 };
167
168 int
169 Tix_GrFormat(clientData, interp, argc, argv)
170 ClientData clientData;
171 Tcl_Interp *interp; /* Current interpreter. */
172 int argc; /* Number of arguments. */
173 char **argv; /* Argument strings. */
174 {
175 static Tix_SubCmdInfo subCmdInfo[] = {
176 {TIX_DEFAULT_LEN, "border", 4, TIX_VAR_ARGS, Tix_GrFormatBorder,
177 "x1 y1 x2 y2 ?option value ...?"},
178 {TIX_DEFAULT_LEN, "grid", 4, TIX_VAR_ARGS, Tix_GrFormatGrid,
179 "x1 y1 x2 y2 ?option value ...?"},
180 };
181 static Tix_CmdInfo cmdInfo = {
182 Tix_ArraySize(subCmdInfo), 1, TIX_VAR_ARGS, "?option? ?arg ...?",
183 };
184 WidgetPtr wPtr = (WidgetPtr) clientData;
185
186 if (wPtr->renderInfo == NULL) {
187 Tcl_AppendResult(interp, "the \"format\" command can only be called ",
188 "by the -formatcmd handler of the tixGrid widget", NULL);
189 return TCL_ERROR;
190 }
191
192 return Tix_HandleSubCmds(&cmdInfo, subCmdInfo, clientData,
193 interp, argc+1, argv-1);
194 }
195
196
197
198 static int
199 GetInfo(wPtr, interp, argc, argv, infoPtr, configSpecs)
200 WidgetPtr wPtr;
201 Tcl_Interp *interp; /* Current interpreter. */
202 int argc; /* Number of arguments. */
203 char **argv; /* Argument strings. */
204 FormatStruct * infoPtr;
205 Tk_ConfigSpec * configSpecs;
206 {
207 int temp;
208
209 if (argc < 4) {
210 return Tix_ArgcError(interp, argc+2, argv-2, 2, "x1 y1 x2 y2 ...");
211 }
212 if (Tcl_GetIntFromObj(interp, argv[0], &infoPtr->x1) != TCL_OK) {
213 return TCL_ERROR;
214 }
215 if (Tcl_GetIntFromObj(interp, argv[1], &infoPtr->y1) != TCL_OK) {
216 return TCL_ERROR;
217 }
218 if (Tcl_GetIntFromObj(interp, argv[2], &infoPtr->x2) != TCL_OK) {
219 return TCL_ERROR;
220 }
221 if (Tcl_GetIntFromObj(interp, argv[3], &infoPtr->y2) != TCL_OK) {
222 return TCL_ERROR;
223 }
224 if (Tk_ConfigureWidget(interp, wPtr->dispData.tkwin, configSpecs,
225 argc-4, argv+4, (char *)infoPtr, 0) != TCL_OK) {
226 return TCL_ERROR;
227 }
228
229 if (infoPtr->x1 > infoPtr->x2) {
230 temp = infoPtr->x1;
231 infoPtr->x1 = infoPtr->x2;
232 infoPtr->x2 = temp;
233 }
234 if (infoPtr->y1 > infoPtr->y2) {
235 temp = infoPtr->y1;
236 infoPtr->y1 = infoPtr->y2;
237 infoPtr->y2 = temp;
238 }
239
240 /* trivial rejects */
241 if (infoPtr->x1 > wPtr->renderInfo->fmt.x2) {
242 return TCL_BREAK;
243 }
244 if (infoPtr->x2 < wPtr->renderInfo->fmt.x1) {
245 return TCL_BREAK;
246 }
247 if (infoPtr->y1 > wPtr->renderInfo->fmt.y2) {
248 return TCL_BREAK;
249 }
250 if (infoPtr->y2 < wPtr->renderInfo->fmt.y1) {
251 return TCL_BREAK;
252 }
253
254 /* the area is indeed visible, do some clipping */
255 if (infoPtr->x1 < wPtr->renderInfo->fmt.x1) {
256 infoPtr->x1 = wPtr->renderInfo->fmt.x1;
257 }
258 if (infoPtr->x2 > wPtr->renderInfo->fmt.x2) {
259 infoPtr->x2 = wPtr->renderInfo->fmt.x2;
260 }
261 if (infoPtr->y1 < wPtr->renderInfo->fmt.y1) {
262 infoPtr->y1 = wPtr->renderInfo->fmt.y1;
263 }
264 if (infoPtr->y2 > wPtr->renderInfo->fmt.y2) {
265 infoPtr->y2 = wPtr->renderInfo->fmt.y2;
266 }
267
268 return TCL_OK;
269 }
270
271 static void
272 GetBlockPosn(wPtr, x1, y1, x2, y2, bx1, by1, bx2, by2)
273 WidgetPtr wPtr;
274 int x1; /* cell index */
275 int x2;
276 int y1;
277 int y2;
278 int * bx1; /* block index */
279 int * by1;
280 int * bx2;
281 int * by2;
282 {
283 *bx1 = x1;
284 *bx2 = x2;
285 *by1 = y1;
286 *by2 = y2;
287
288 switch (wPtr->renderInfo->fmt.whichArea) {
289 case TIX_S_MARGIN:
290 break;
291 case TIX_X_MARGIN:
292 *bx1 -= wPtr->scrollInfo[0].offset;
293 *bx2 -= wPtr->scrollInfo[0].offset;
294 break;
295 case TIX_Y_MARGIN:
296 *by1 -= wPtr->scrollInfo[1].offset;
297 *by2 -= wPtr->scrollInfo[1].offset;
298 break;
299 case TIX_MAIN:
300 *bx1 -= wPtr->scrollInfo[0].offset;
301 *bx2 -= wPtr->scrollInfo[0].offset;
302 *by1 -= wPtr->scrollInfo[1].offset;
303 *by2 -= wPtr->scrollInfo[1].offset;
304 break;
305 }
306 }
307
308 static void
309 GetRenderPosn(wPtr, bx1, by1, bx2, by2, rx1, ry1, rx2, ry2)
310 WidgetPtr wPtr;
311 int bx1; /* block index */
312 int by1;
313 int bx2;
314 int by2;
315 int * rx1; /* render buffer position */
316 int * ry1;
317 int * rx2;
318 int * ry2;
319 {
320 int x, y, i;
321
322
323 for (x=0,i=0; i<=bx2; i++) {
324 if (i == bx1) {
325 *rx1 = x;
326 }
327 if (i == bx2) {
328 *rx2 = x + wPtr->mainRB->dispSize[0][i].total - 1;
329 break;
330
331 }
332 x += wPtr->mainRB->dispSize[0][i].total;
333 }
334
335
336 for (y=0,i=0; i<=by2; i++) {
337 if (i == by1) {
338 *ry1 = y;
339 }
340 if (i == by2) {
341 *ry2 = y + wPtr->mainRB->dispSize[1][i].total - 1;
342 break;
343 }
344 y += wPtr->mainRB->dispSize[1][i].total;
345 }
346
347 *rx1 += wPtr->renderInfo->origin[0];
348 *rx2 += wPtr->renderInfo->origin[0];
349 *ry1 += wPtr->renderInfo->origin[1];
350 *ry2 += wPtr->renderInfo->origin[1];
351 }
352
353 static void
354 Tix_GrFillCells(wPtr, border, selectBorder, bx1, by1, bx2, by2,
355 borderWidth, relief, filled, bw)
356 WidgetPtr wPtr;
357 Tk_3DBorder border;
358 Tk_3DBorder selectBorder;
359 int bx1;
360 int by1;
361 int bx2;
362 int by2;
363 int borderWidth;
364 int relief;
365 int filled;
366 int bw[2][2];
367 {
368 int rx1, ry1, rx2, ry2;
369 int i, j;
370 Tk_3DBorder targetBorder;
371
372 for (i=bx1; i<=bx2; i++) {
373 for (j=by1; j<=by2; j++) {
374
375 if (filled) {
376 GetRenderPosn(wPtr, i, j, i, j, &rx1,&ry1, &rx2,&ry2);
377
378 if (wPtr->mainRB->elms[i][j].selected) {
379 targetBorder = selectBorder;
380 } else {
381 targetBorder = border;
382 }
383
384 Tk_Fill3DRectangle(wPtr->dispData.tkwin,
385 wPtr->renderInfo->drawable,
386 targetBorder, rx1, ry1, rx2-rx1+1, ry2-ry1+1,
387 0, TK_RELIEF_FLAT);
388
389 wPtr->mainRB->elms[i][j].filled = 1;
390 } else {
391 if (!wPtr->mainRB->elms[i][j].filled) {
392 if (i == bx1) {
393 if (wPtr->mainRB->elms[i][j].borderW[0][0] < bw[0][0]){
394 wPtr->mainRB->elms[i][j].borderW[0][0] = bw[0][0];
395 }
396 }
397 if (i == bx2) {
398 if (wPtr->mainRB->elms[i][j].borderW[0][1] < bw[0][1]){
399 wPtr->mainRB->elms[i][j].borderW[0][1] = bw[0][1];
400 }
401 }
402 if (j == by1) {
403 if (wPtr->mainRB->elms[i][j].borderW[1][0] < bw[1][0]){
404 wPtr->mainRB->elms[i][j].borderW[1][0] = bw[1][0];
405 }
406 }
407 if (j == by2) {
408 if (wPtr->mainRB->elms[i][j].borderW[1][1] < bw[1][1]){
409 wPtr->mainRB->elms[i][j].borderW[1][1] = bw[1][1];
410 }
411 }
412 }
413 }
414 }
415 }
416 if (borderWidth > 0) {
417 GetRenderPosn(wPtr, bx1, by1, bx2, by2, &rx1,&ry1, &rx2,&ry2);
418
419 if (bx1 == bx2 && by1 == by2) {
420 /* special case: if a single cell is selected, we invert the
421 * border */
422
423 if (wPtr->mainRB->elms[bx1][by1].selected) {
424 if (relief == TK_RELIEF_RAISED) {
425 relief = TK_RELIEF_SUNKEN;
426 }
427 else if (relief == TK_RELIEF_SUNKEN) {
428 relief = TK_RELIEF_RAISED;
429 }
430 }
431 }
432
433 Tk_Draw3DRectangle(wPtr->dispData.tkwin,
434 wPtr->renderInfo->drawable,
435 border, rx1, ry1, rx2-rx1+1, ry2-ry1+1,
436 borderWidth, relief);
437 }
438 }
439
440 static int
441 Tix_GrFormatBorder(clientData, interp, argc, argv)
442 ClientData clientData;
443 Tcl_Interp *interp; /* Current interpreter. */
444 int argc; /* Number of arguments. */
445 char **argv; /* Argument strings. */
446 {
447 WidgetPtr wPtr = (WidgetPtr) clientData;
448 BorderFmtStruct info;
449 int code = TCL_OK;
450 int bx1, bx2, by1, by2;
451 int i, j;
452
453 info.x1 = 0;
454 info.y1 = 0;
455 info.x2 = 0;
456 info.y2 = 0;
457 info.border = NULL;
458 info.borderWidth = 0;
459 info.selectBorder = NULL;
460 info.relief = TK_RELIEF_FLAT;
461 info.xon = 0;
462 info.xoff = 0;
463 info.yon = 0;
464 info.yoff = 0;
465 info.filled = 0;
466
467 if ((code = GetInfo(wPtr, interp, argc, argv, (FormatStruct*)&info,
468 borderConfigSpecs))!= TCL_OK) {
469 goto done;
470 }
471
472 /*
473 * If the xon is not specified, then by default the xon is encloses the
474 * whole region. Same for yon.
475 */
476 if (info.xon == 0) {
477 info.xon = info.x2 - info.x1 + 1;
478 info.xoff = 0;
479 }
480 if (info.yon == 0) {
481 info.yon = info.y2 - info.y1 + 1;
482 info.yoff = 0;
483 }
484
485 GetBlockPosn(wPtr, info.x1, info.y1, info.x2, info.y2,
486 &bx1, &by1, &bx2, &by2);
487
488 for (i=bx1; i<=bx2; i+=(info.xon+info.xoff)) {
489 for (j=by1; j<=by2; j+=(info.yon+info.yoff)) {
490 int _bx1, _by1, _bx2, _by2;
491 int borderWidths[2][2];
492
493 _bx1 = i;
494 _bx2 = i+info.xon-1;
495 _by1 = j;
496 _by2 = j+info.yon-1;
497
498 if (_bx2 > bx2) {
499 _bx2 = bx2;
500 }
501 if (_by2 > by2) {
502 _by2 = by2;
503 }
504
505 borderWidths[0][0] = info.borderWidth;
506 borderWidths[0][1] = info.borderWidth;
507 borderWidths[1][0] = info.borderWidth;
508 borderWidths[1][1] = info.borderWidth;
509
510 Tix_GrFillCells(wPtr, info.border, info.selectBorder,
511 _bx1, _by1, _bx2, _by2,
512 info.borderWidth, info.relief, info.filled, borderWidths);
513 }
514 }
515
516 done:
517 if (code == TCL_BREAK) {
518 code = TCL_OK;
519 }
520 if (code == TCL_OK) {
521 if (Tix_GrSaveColor(wPtr, TK_CONFIG_BORDER, (void*)info.border) == 0) {
522 info.border = (Tk_3DBorder)NULL;
523 }
524 if (Tix_GrSaveColor(wPtr, TK_CONFIG_BORDER, (void*)info.selectBorder)
525 == 0) {
526 info.selectBorder = (Tk_3DBorder)NULL;
527 }
528 Tk_FreeOptions(borderConfigSpecs, (char *)&info,
529 wPtr->dispData.display, 0);
530 }
531 return code;
532 }
533
534 static int
535 Tix_GrFormatGrid(clientData, interp, argc, argv)
536 ClientData clientData;
537 Tcl_Interp *interp; /* Current interpreter. */
538 int argc; /* Number of arguments. */
539 char **argv; /* Argument strings. */
540 {
541 WidgetPtr wPtr = (WidgetPtr) clientData;
542 GridFmtStruct info;
543 int code = TCL_OK;
544 int rx1, rx2, ry1, ry2;
545 int bx1, bx2, by1, by2;
546 int i, j;
547 GC gc;
548 int borderWidths[2][2];
549
550 info.x1 = 0;
551 info.y1 = 0;
552 info.x2 = 0;
553 info.y2 = 0;
554 info.border = NULL;
555 info.selectBorder = NULL;
556 info.bgBorder = NULL;
557 info.borderWidth = 0;
558 info.relief = TK_RELIEF_FLAT;
559 info.xon = 1;
560 info.xoff = 0;
561 info.yon = 1;
562 info.yoff = 0;
563 info.filled = 0;
564
565 if ((code = GetInfo(wPtr, interp, argc, argv, (FormatStruct*)&info,
566 gridConfigSpecs))!= TCL_OK) {
567 goto done;
568 }
569 gc = Tk_3DBorderGC(wPtr->dispData.tkwin, info.border,
570 TK_3D_FLAT_GC);
571
572 GetBlockPosn(wPtr, info.x1, info.y1, info.x2, info.y2,
573 &bx1, &by1, &bx2, &by2);
574
575 borderWidths[0][0] = 0;
576 borderWidths[0][1] = 0;
577 borderWidths[1][0] = 0;
578 borderWidths[1][1] = 0;
579
580 switch(info.anchor) {
581 case TK_ANCHOR_N:
582 case TK_ANCHOR_NE:
583 case TK_ANCHOR_NW:
584 borderWidths[1][0] = info.borderWidth;
585 break;
586 default:
587 ; /* do nothing. This line gets rid of compiler warnings */
588 }
589 switch(info.anchor) {
590 case TK_ANCHOR_SE:
591 case TK_ANCHOR_S:
592 case TK_ANCHOR_SW:
593 borderWidths[1][1] = info.borderWidth;
594 break;
595 default:
596 ; /* do nothing. This line gets rid of compiler warnings */
597 }
598 switch(info.anchor) {
599 case TK_ANCHOR_SW:
600 case TK_ANCHOR_W:
601 case TK_ANCHOR_NW:
602 borderWidths[0][0] = info.borderWidth;
603 break;
604 default:
605 ; /* do nothing. This line gets rid of compiler warnings */
606 }
607 switch(info.anchor) {
608 case TK_ANCHOR_NE:
609 case TK_ANCHOR_E:
610 case TK_ANCHOR_SE:
611 borderWidths[0][1] = info.borderWidth;
612 break;
613 default:
614 ; /* do nothing. This line gets rid of compiler warnings */
615 }
616
617 for (i=bx1; i<=bx2; i+=(info.xon+info.xoff)) {
618 for (j=by1; j<=by2; j+=(info.yon+info.yoff)) {
619 int _bx1, _by1, _bx2, _by2;
620
621 _bx1 = i;
622 _bx2 = i+info.xon-1;
623 _by1 = j;
624 _by2 = j+info.yon-1;
625
626 if (_bx2 > bx2) {
627 _bx2 = bx2;
628 }
629 if (_by2 > by2) {
630 _by2 = by2;
631 }
632
633 Tix_GrFillCells(wPtr, info.bgBorder, info.selectBorder,
634 _bx1, _by1, _bx2, _by2, 0, TK_RELIEF_FLAT, info.filled,
635 borderWidths);
636
637 if (info.borderWidth > 0) {
638 GetRenderPosn(wPtr, _bx1, _by1, _bx2, _by2,
639 &rx1,&ry1, &rx2,&ry2);
640
641 switch(info.anchor) {
642 case TK_ANCHOR_N:
643 case TK_ANCHOR_NE:
644 case TK_ANCHOR_NW:
645 XDrawLine(wPtr->dispData.display,
646 wPtr->renderInfo->drawable, gc,
647 rx1, ry1, rx2, ry1);
648 break;
649 default:
650 ; /* do nothing. This line gets rid of compiler warnings */
651 }
652 switch(info.anchor) {
653 case TK_ANCHOR_SE:
654 case TK_ANCHOR_S:
655 case TK_ANCHOR_SW:
656 XDrawLine(wPtr->dispData.display,
657 wPtr->renderInfo->drawable, gc,
658 rx1, ry2, rx2, ry2);
659 break;
660 default:
661 ; /* do nothing. This line gets rid of compiler warnings */
662 }
663 switch(info.anchor) {
664 case TK_ANCHOR_SW:
665 case TK_ANCHOR_W:
666 case TK_ANCHOR_NW:
667 XDrawLine(wPtr->dispData.display,
668 wPtr->renderInfo->drawable, gc,
669 rx1, ry1, rx1, ry2);
670 break;
671 default:
672 ; /* do nothing. This line gets rid of compiler warnings */
673 }
674 switch(info.anchor) {
675 case TK_ANCHOR_NE:
676 case TK_ANCHOR_E:
677 case TK_ANCHOR_SE:
678 XDrawLine(wPtr->dispData.display,
679 wPtr->renderInfo->drawable, gc,
680 rx2, ry1, rx2, ry2);
681 break;
682 default:
683 ; /* do nothing. This line gets rid of compiler warnings */
684 }
685 }
686 }
687 }
688
689 done:
690 if (code == TCL_BREAK) {
691 code = TCL_OK;
692 }
693 if (code == TCL_OK) {
694 if (Tix_GrSaveColor(wPtr, TK_CONFIG_BORDER, (void*)info.border) == 0) {
695 info.border = (Tk_3DBorder)NULL;
696 }
697 if (Tix_GrSaveColor(wPtr, TK_CONFIG_BORDER, (void*)info.bgBorder)==0) {
698 info.bgBorder = (Tk_3DBorder)NULL;
699 }
700 if (Tix_GrSaveColor(wPtr, TK_CONFIG_BORDER, (void*)info.selectBorder)
701 == 0) {
702 info.selectBorder = (Tk_3DBorder)NULL;
703 }
704 Tk_FreeOptions(gridConfigSpecs, (char *)&info, wPtr->dispData.display,
705 0);
706 }
707 return code;
708 }
709
710
711 /* returns 1 if the caller can free the border/color */
712 static int Tix_GrSaveColor(wPtr, type, ptr)
713 WidgetPtr wPtr;
714 int type;
715 void * ptr;
716 {
717 Tk_3DBorder border = NULL;
718 XColor * color = NULL;
719 long pixel;
720 Tix_ListIterator li;
721 int found;
722 ColorInfo * cPtr;
723
724 if (type == TK_CONFIG_COLOR) {
725 color = (XColor *)ptr;
726 pixel = color->pixel;
727 } else {
728 border = (Tk_3DBorder)ptr;
729 pixel = Tk_3DBorderColor(border)->pixel;
730 }
731
732 Tix_SimpleListIteratorInit(&li);
733 for (found = 0, Tix_SimpleListStart(&wPtr->colorInfo, &li);
734 !Tix_SimpleListDone(&li);
735 Tix_SimpleListNext (&wPtr->colorInfo, &li)) {
736
737 cPtr = (ColorInfo *)li.curr;
738 if (cPtr->pixel == pixel) {
739 cPtr->counter = wPtr->colorInfoCounter;
740 return 1;
741
742 }
743 }
744
745 cPtr = (ColorInfo *)ckalloc(sizeof(ColorInfo));
746
747 if (type == TK_CONFIG_COLOR) {
748 cPtr->color = color;
749 } else {
750 cPtr->border = border;
751 }
752 cPtr->type = (int)type;
753 cPtr->pixel = pixel;
754 cPtr->counter = wPtr->colorInfoCounter;
755
756 Tix_SimpleListAppend(&wPtr->colorInfo, (char*)cPtr, 0);
757 return 0;
758 }
759
760 void
761 Tix_GrFreeUnusedColors(wPtr, freeAll)
762 WidgetPtr wPtr;
763 int freeAll;
764 {
765 Tix_ListIterator li;
766 ColorInfo * cPtr;
767
768 Tix_SimpleListIteratorInit(&li);
769 for (Tix_SimpleListStart(&wPtr->colorInfo, &li);
770 !Tix_SimpleListDone(&li);
771 Tix_SimpleListNext (&wPtr->colorInfo, &li)) {
772
773 cPtr = (ColorInfo *)li.curr;
774 if (freeAll || cPtr->counter < wPtr->colorInfoCounter) {
775 Tix_SimpleListDelete(&wPtr->colorInfo, &li);
776
777 if (cPtr->type == (int)(TK_CONFIG_COLOR)) {
778 Tk_FreeColor(cPtr->color);
779 } else {
780 Tk_Free3DBorder(cPtr->border);
781 }
782 ckfree((char*)cPtr);
783 }
784 }
785 }