OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [insight/] [tix/] [generic/] [tixGrFmt.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.