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

Subversion Repositories or1k_old

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
2
 * tixFormMisc.c --
3
 *
4
 *      Implements the tixForm geometry manager, which has similar
5
 *      capability as the Motif Form geometry manager. Please
6
 *      refer to the documentation for the use of tixForm.
7
 *
8
 * Copyright (c) 1996, Expert Interface Technologies
9
 *
10
 * See the file "license.terms" for information on usage and redistribution
11
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12
 *
13
 */
14
 
15
#include <tixPort.h>
16
#include <tix.h>
17
#include <tixForm.h>
18
 
19
/*
20
 * SubCommands of the tixForm command.
21
 */
22
TIX_DECLARE_SUBCMD(TixFm_Info);
23
 
24
static void             AttachInfo _ANSI_ARGS_((Tcl_Interp * interp,
25
                            FormInfo * clientPtr, int axis, int which));
26
static int              ConfigureAttachment _ANSI_ARGS_((FormInfo *clientPtr,
27
                            Tk_Window topLevel, Tcl_Interp* interp,
28
                            int axis, int which, char *value));
29
static int              ConfigureFill _ANSI_ARGS_((
30
                            FormInfo *clientPtr, Tk_Window tkwin,
31
                            Tcl_Interp* interp, char *value));
32
static int              ConfigurePadding _ANSI_ARGS_((
33
                            FormInfo *clientPtr, Tk_Window tkwin,
34
                            Tcl_Interp* interp, int axis, int which,
35
                            char *value));
36
static int              ConfigureSpring _ANSI_ARGS_((FormInfo *clientPtr,
37
                            Tk_Window topLevel, Tcl_Interp* interp,
38
                            int axis, int which, char *value));
39
 
40
 
41
/*----------------------------------------------------------------------
42
 * TixFm_Info --
43
 *
44
 *      Return the information about the attachment of a client window
45
 *----------------------------------------------------------------------
46
 */
47
int TixFm_Info(clientData, interp, argc, argv)
48
    ClientData clientData;      /* Main window associated with
49
                                 * interpreter. */
50
    Tcl_Interp *interp;         /* Current interpreter. */
51
    int argc;                   /* Number of arguments. */
52
    char **argv;                /* Argument strings. */
53
{
54
    Tk_Window topLevel = (Tk_Window) clientData;
55
    FormInfo * clientPtr;
56
    char buff[256];
57
    int i,j;
58
    static char *sideNames[2][2] = {
59
        {"-left", "-right"},
60
        {"-top", "-bottom"}
61
    };
62
    static char *padNames[2][2] = {
63
        {"-padleft", "-padright"},
64
        {"-padtop", "-padbottom"}
65
    };
66
 
67
    clientPtr = TixFm_FindClientPtrByName(interp, argv[0], topLevel);
68
    if (clientPtr == NULL) {
69
        return TCL_ERROR;
70
    }
71
 
72
    if (argc == 2) {
73
        /* user wants some specific info
74
         */
75
 
76
        for (i=0; i<2; i++) {
77
            for (j=0; j<2; j++) {
78
                /* Do you want to know attachment? */
79
                if (strcmp(argv[1], sideNames[i][j]) == 0) {
80
                    AttachInfo(interp, clientPtr, i, j);
81
                    return TCL_OK;
82
                }
83
 
84
                /* Do you want to know padding? */
85
                if (strcmp(argv[1], padNames[i][j]) == 0) {
86
                    sprintf(buff, "%d", clientPtr->pad[i][j]);
87
                    Tcl_AppendResult(interp, buff, NULL);
88
                    return TCL_OK;
89
                }
90
            }
91
        }
92
        Tcl_AppendResult(interp, "Unknown option \"", argv[1], "\"", NULL);
93
        return TCL_ERROR;
94
    }
95
 
96
    /* Otherwise, give full info */
97
 
98
    for (i=0; i<2; i++) {
99
        for (j=0; j<2; j++) {
100
            /* The information about attachment */
101
            Tcl_AppendResult(interp, sideNames[i][j], " ", NULL);
102
            AttachInfo(interp, clientPtr, i, j);
103
 
104
            /* The information about padding */
105
            Tcl_AppendResult(interp, padNames[i][j], " ", NULL);
106
            sprintf(buff, "%d", clientPtr->pad[i][j]);
107
            Tcl_AppendResult(interp, buff, " ", NULL);
108
        }
109
    }
110
    return TCL_OK;
111
}
112
 
113
static void AttachInfo(interp, clientPtr, axis, which)
114
    Tcl_Interp * interp;
115
    FormInfo * clientPtr;
116
    int axis;
117
    int which;
118
{
119
    char buff[256];
120
 
121
    switch(clientPtr->attType[axis][which]) {
122
      case ATT_NONE:
123
        Tcl_AppendElement(interp, "none");
124
        break;
125
 
126
      case ATT_GRID:
127
        sprintf(buff, "{%%%d %d}", clientPtr->att[axis][which].grid,
128
            clientPtr->off[axis][which]);
129
        Tcl_AppendResult(interp, buff, " ", NULL);
130
        break;
131
 
132
      case ATT_OPPOSITE:
133
        sprintf(buff, "%d", clientPtr->off[axis][which]);
134
        Tcl_AppendResult(interp, "{",
135
            Tk_PathName(clientPtr->att[axis][which].widget->tkwin),
136
            " ", buff, "} ", NULL);
137
        break;
138
 
139
      case ATT_PARALLEL:
140
        sprintf(buff, "%d", clientPtr->off[axis][which]);
141
        Tcl_AppendResult(interp, "{&",
142
            Tk_PathName(clientPtr->att[axis][which].widget->tkwin),
143
            " ", buff, "} ", NULL);
144
        break;
145
    }
146
}
147
 
148
/*----------------------------------------------------------------------
149
 * Form Parameter Configuration
150
 *
151
 *----------------------------------------------------------------------
152
 */
153
static int ConfigureAttachment(clientPtr, topLevel, interp, axis, which, value)
154
    FormInfo *clientPtr;
155
    Tk_Window topLevel;
156
    Tcl_Interp* interp;
157
    int axis, which;
158
    char *value;
159
{
160
    Tk_Window tkwin;
161
    FormInfo * attWidget;
162
    int code = TCL_OK;
163
    int offset;
164
    int grid;
165
    int argc;
166
    char ** argv;
167
 
168
    if (Tcl_SplitList(interp, value, &argc, &argv) != TCL_OK) {
169
        return TCL_ERROR;
170
    }
171
    if (argc < 1 || argc > 2) {
172
        Tcl_AppendResult(interp, "Malformed attachment value \"", value,
173
            "\"", NULL);
174
        code = TCL_ERROR;
175
        goto done;
176
    }
177
 
178
    switch (argv[0][0]) {
179
      case '#':         /* Attached to grid */
180
      case '%':         /* Attached to percent (aka grid) */
181
        if (Tcl_GetInt(interp, argv[0]+1, &grid) == TCL_ERROR) {
182
            code = TCL_ERROR;
183
            goto done;
184
        }
185
        clientPtr->attType[axis][which]   = ATT_GRID;
186
        clientPtr->att[axis][which].grid  = grid;
187
        break;
188
 
189
      case '&':                 /* Attached to parallel widget */
190
        tkwin = Tk_NameToWindow(interp, argv[0]+1, topLevel);
191
 
192
        if (tkwin != NULL) {
193
            if (Tk_IsTopLevel(tkwin)) {
194
                Tcl_AppendResult(interp, "can't attach to \"", value,
195
                    "\": it's a top-level window", (char *) NULL);
196
                code = TCL_ERROR;
197
                goto done;
198
            }
199
            attWidget = TixFm_GetFormInfo(tkwin, 1);
200
            TixFm_AddToMaster(clientPtr->master, attWidget);
201
 
202
            clientPtr->attType[axis][which]    = ATT_PARALLEL;
203
            clientPtr->att[axis][which].widget = attWidget;
204
        } else {
205
            code = TCL_ERROR;
206
            goto done;
207
        }
208
        break;
209
 
210
      case '.':                 /* Attach to opposite widget */
211
        tkwin = Tk_NameToWindow(interp, argv[0], topLevel);
212
 
213
        if (tkwin != NULL) {
214
            if (Tk_IsTopLevel(tkwin)) {
215
                Tcl_AppendResult(interp, "can't attach to \"", value,
216
                    "\": it's a top-level window", (char *) NULL);
217
                code = TCL_ERROR;
218
                goto done;
219
            }
220
            attWidget = TixFm_GetFormInfo(tkwin, 1);
221
            TixFm_AddToMaster(clientPtr->master, attWidget);
222
 
223
            clientPtr->attType[axis][which]    = ATT_OPPOSITE;
224
            clientPtr->att[axis][which].widget = attWidget;
225
        } else {
226
            code = TCL_ERROR;
227
            goto done;
228
        }
229
        break;
230
 
231
      case 'n':         /* none */
232
        if (argc == 1 && strcmp(argv[0], "none") == 0) {
233
            clientPtr->attType[axis][which]    = ATT_NONE;
234
            goto done;
235
        } else {
236
            Tcl_AppendResult(interp, "Malformed attachment value \"", value,
237
                "\"", NULL);
238
            code = TCL_ERROR;
239
            goto done;
240
        }
241
        break;
242
 
243
      default:          /* Check if is attached to pixel */
244
        /* If there is only one value, this can be the offset with implicit
245
         * anchor point 0% or max_grid%
246
         */
247
        if (argc != 1) {
248
            Tcl_AppendResult(interp, "Malformed attachment value \"", value,
249
                "\"", NULL);
250
            code = TCL_ERROR;
251
            goto done;
252
        }
253
#if 1
254
        if (Tk_GetPixels(interp, topLevel, argv[0], &offset) != TCL_OK) {
255
#else
256
        if (Tcl_GetInt(interp, argv[0], &offset) == TCL_ERROR) {
257
#endif
258
            code = TCL_ERROR;
259
            goto done;
260
        }
261
 
262
        clientPtr->attType[axis][which]      = ATT_GRID;
263
        clientPtr->off    [axis][which]      = offset;
264
        if (offset < 0 || (offset == 0 && strcmp(argv[0], "-0") ==0)) {
265
            clientPtr->att[axis][which].grid = clientPtr->master->grids[axis];
266
        } else {
267
            clientPtr->att[axis][which].grid = 0;
268
        }
269
 
270
        goto done;      /* We have already gotten both anchor and offset */
271
    }
272
 
273
    if (argc  == 2) {
274
#if 1
275
        if (Tk_GetPixels(interp, topLevel, argv[1], &offset) != TCL_OK) {
276
#else
277
        if (Tcl_GetInt(interp, argv[1], &offset) == TCL_ERROR) {
278
#endif
279
            code = TCL_ERROR;
280
            goto done;
281
        }
282
        clientPtr->off[axis][which] = offset;
283
    } else {
284
        clientPtr->off[axis][which] = 0;
285
    }
286
 
287
  done:
288
    if (argv) {
289
        ckfree((char*) argv);
290
    }
291
    if (code == TCL_ERROR) {
292
        clientPtr->attType[axis][which] = ATT_NONE;
293
        clientPtr->off[axis][which] = 0;
294
    }
295
    return code;
296
}
297
 
298
static int ConfigurePadding(clientPtr, tkwin, interp, axis, which, value)
299
    FormInfo *clientPtr;
300
    Tk_Window tkwin;
301
    Tcl_Interp* interp;
302
    int axis, which;
303
    char *value;
304
{
305
    int p_value;
306
 
307
    if (Tk_GetPixels(interp, tkwin, value, &p_value) != TCL_OK) {
308
        return TCL_ERROR;
309
    }
310
    else {
311
        clientPtr->pad[axis][which] = p_value;
312
        return TCL_OK;
313
    }
314
}
315
 
316
static int ConfigureFill(clientPtr, tkwin, interp, value)
317
    FormInfo *clientPtr;
318
    Tk_Window tkwin;
319
    Tcl_Interp* interp;
320
    char *value;
321
{
322
    size_t len = strlen(value);
323
 
324
    if (strncmp(value, "x", len) == 0) {
325
        clientPtr->fill[AXIS_X] = 1;
326
        clientPtr->fill[AXIS_Y] = 0;
327
    }
328
    else if (strncmp(value, "y", len) == 0) {
329
        clientPtr->fill[AXIS_X] = 0;
330
        clientPtr->fill[AXIS_Y] = 1;
331
    }
332
    else if (strncmp(value, "both", len) == 0) {
333
        clientPtr->fill[AXIS_X] = 1;
334
        clientPtr->fill[AXIS_Y] = 1;
335
    }
336
    else if (strncmp(value, "none", len) == 0) {
337
        clientPtr->fill[AXIS_X] = 0;
338
        clientPtr->fill[AXIS_Y] = 0;
339
    }
340
    else {
341
        Tcl_AppendResult(interp, "bad fill style \"", value,
342
            "\": must be none, x, y, or both", NULL);
343
        return TCL_ERROR;
344
    }
345
 
346
    return TCL_OK;
347
}
348
 
349
static int ConfigureSpring(clientPtr, topLevel, interp, axis, which, value)
350
    FormInfo *clientPtr;
351
    Tk_Window topLevel;
352
    Tcl_Interp* interp;
353
    int axis, which;
354
    char *value;
355
{
356
    int         strength;
357
    int         i = axis, j = which;
358
 
359
    if (Tcl_GetInt(interp, value, &strength) != TCL_OK) {
360
        return TCL_ERROR;
361
    }
362
 
363
    clientPtr->spring[i][j] = strength;
364
 
365
    if (clientPtr->attType[i][j] == ATT_OPPOSITE) {
366
        FormInfo * oppo;
367
 
368
        oppo = clientPtr->att[i][j].widget;
369
        oppo->spring[i][!j]  = strength;
370
 
371
        if (strength != 0 && clientPtr->strWidget[i][j] == NULL) {
372
            clientPtr->strWidget[i][j] = oppo;
373
 
374
            if (oppo->strWidget[i][!j] != clientPtr) {
375
                if (oppo->strWidget[i][!j] != NULL) {
376
                    oppo->strWidget[i][!j]->strWidget[i][j] = NULL;
377
                    oppo->strWidget[i][!j]->spring[i][j]  = 0;
378
                }
379
            }
380
            oppo->strWidget[i][!j] = clientPtr;
381
        }
382
    }
383
 
384
    return TCL_OK;
385
}
386
 
387
int TixFm_Configure(clientPtr, topLevel, interp, argc, argv)
388
    FormInfo *clientPtr;
389
    Tk_Window topLevel;
390
    Tcl_Interp* interp;
391
    int argc;
392
    char **argv;
393
{
394
    int i, flag, value;
395
 
396
    for (i=0; i< argc; i+=2) {
397
        flag  = i;
398
        value = i+1;
399
 
400
        if (strcmp(argv[flag], "-in") == 0) {
401
            /* Reset the parent of the widget
402
             */
403
            Tcl_AppendResult(interp,
404
                "\"-in \" must be the first option given to tixForm", NULL);
405
            return TCL_ERROR;
406
        } else if (strcmp(argv[flag], "-l") == 0) {
407
            if (ConfigureAttachment(clientPtr, topLevel, interp,
408
                0, 0, argv[value]) == TCL_ERROR) {
409
 
410
                return TCL_ERROR;
411
            }
412
        } else if (strcmp(argv[flag], "-left") == 0) {
413
            if (ConfigureAttachment(clientPtr, topLevel, interp,
414
                0, 0, argv[value]) == TCL_ERROR) {
415
 
416
                return TCL_ERROR;
417
            }
418
        } else if (strcmp(argv[flag], "-r") == 0) {
419
            if (ConfigureAttachment(clientPtr, topLevel, interp,
420
                0, 1, argv[value]) == TCL_ERROR) {
421
 
422
                return TCL_ERROR;
423
            }
424
        } else if (strcmp(argv[flag], "-right") == 0) {
425
            if (ConfigureAttachment(clientPtr, topLevel, interp,
426
                0, 1, argv[value]) == TCL_ERROR) {
427
 
428
                return TCL_ERROR;
429
            }
430
        } else if (strcmp(argv[flag], "-top") == 0) {
431
            if (ConfigureAttachment(clientPtr, topLevel, interp,
432
                1, 0, argv[value]) == TCL_ERROR) {
433
 
434
                return TCL_ERROR;
435
            }
436
        } else if (strcmp(argv[flag], "-t") == 0) {
437
            if (ConfigureAttachment(clientPtr, topLevel, interp,
438
                1, 0, argv[value]) == TCL_ERROR) {
439
 
440
                return TCL_ERROR;
441
            }
442
        } else if (strcmp(argv[flag], "-bottom") == 0) {
443
            if (ConfigureAttachment(clientPtr, topLevel, interp,
444
                1, 1, argv[value]) == TCL_ERROR) {
445
 
446
                return TCL_ERROR;
447
            }
448
        } else if (strcmp(argv[flag], "-b") == 0) {
449
            if (ConfigureAttachment(clientPtr, topLevel, interp,
450
                1, 1, argv[value]) == TCL_ERROR) {
451
 
452
                return TCL_ERROR;
453
            }
454
        } else if (strcmp(argv[flag], "-padx") == 0) {
455
            if (ConfigurePadding(clientPtr, topLevel, interp,
456
                0, 0, argv[value]) == TCL_ERROR) {
457
 
458
                return TCL_ERROR;
459
            }
460
            if (ConfigurePadding(clientPtr, topLevel, interp,
461
                0, 1, argv[value]) == TCL_ERROR) {
462
 
463
                return TCL_ERROR;
464
            }
465
        } else if (strcmp(argv[flag], "-pady") == 0) {
466
            if (ConfigurePadding(clientPtr,topLevel,interp,
467
                1, 0, argv[value]) == TCL_ERROR) {
468
 
469
                return TCL_ERROR;
470
            }
471
            if (ConfigurePadding(clientPtr, topLevel, interp,
472
                1, 1, argv[value]) == TCL_ERROR) {
473
 
474
                return TCL_ERROR;
475
            }
476
        } else if (strcmp(argv[flag], "-padleft") == 0) {
477
            if (ConfigurePadding(clientPtr, topLevel, interp,
478
                0, 0, argv[value]) == TCL_ERROR) {
479
 
480
                return TCL_ERROR;
481
            }
482
        } else if (strcmp(argv[flag], "-lp") == 0) {
483
            if (ConfigurePadding(clientPtr, topLevel, interp,
484
                0, 0, argv[value]) == TCL_ERROR) {
485
 
486
                return TCL_ERROR;
487
            }
488
        } else if (strcmp(argv[flag], "-padright")== 0){
489
            if (ConfigurePadding(clientPtr, topLevel, interp,
490
                0, 1, argv[value]) == TCL_ERROR) {
491
 
492
                return TCL_ERROR;
493
            }
494
        } else if (strcmp(argv[flag], "-rp")== 0){
495
            if (ConfigurePadding(clientPtr, topLevel, interp,
496
                0, 1, argv[value]) == TCL_ERROR) {
497
 
498
                return TCL_ERROR;
499
            }
500
        } else if (strcmp(argv[flag], "-padtop")== 0) {
501
            if (ConfigurePadding(clientPtr, topLevel, interp,
502
                1, 0, argv[value]) == TCL_ERROR) {
503
 
504
                return TCL_ERROR;
505
            }
506
        } else if (strcmp(argv[flag], "-tp")== 0) {
507
            if (ConfigurePadding(clientPtr, topLevel, interp,
508
                1, 0, argv[value]) == TCL_ERROR) {
509
 
510
                return TCL_ERROR;
511
            }
512
        } else if (strcmp(argv[flag],"-padbottom")== 0){
513
            if (ConfigurePadding(clientPtr, topLevel, interp,
514
                1, 1, argv[value]) == TCL_ERROR) {
515
 
516
                return TCL_ERROR;
517
            }
518
        } else if (strcmp(argv[flag],"-bp")== 0){
519
            if (ConfigurePadding(clientPtr, topLevel, interp,
520
                1, 1, argv[value]) == TCL_ERROR) {
521
 
522
                return TCL_ERROR;
523
            }
524
        } else if (strcmp(argv[flag], "-leftspring") == 0) {
525
            if (ConfigureSpring(clientPtr, topLevel, interp,
526
                0, 0, argv[value]) == TCL_ERROR) {
527
                return TCL_ERROR;
528
            }
529
        } else if (strcmp(argv[flag], "-ls") == 0) {
530
            if (ConfigureSpring(clientPtr, topLevel, interp,
531
                0, 0, argv[value]) == TCL_ERROR) {
532
                return TCL_ERROR;
533
            }
534
        } else if (strcmp(argv[flag], "-rightspring") == 0) {
535
            if (ConfigureSpring(clientPtr, topLevel, interp,
536
                0, 1, argv[value]) == TCL_ERROR) {
537
                return TCL_ERROR;
538
            }
539
        } else if (strcmp(argv[flag], "-rs") == 0) {
540
            if (ConfigureSpring(clientPtr, topLevel, interp,
541
                0, 1, argv[value]) == TCL_ERROR) {
542
                return TCL_ERROR;
543
            }
544
        } else if (strcmp(argv[flag], "-topspring") == 0) {
545
            if (ConfigureSpring(clientPtr, topLevel, interp,
546
                1, 0, argv[value]) == TCL_ERROR) {
547
                return TCL_ERROR;
548
            }
549
        } else if (strcmp(argv[flag], "-ts") == 0) {
550
            if (ConfigureSpring(clientPtr, topLevel, interp,
551
                1, 0, argv[value]) == TCL_ERROR) {
552
                return TCL_ERROR;
553
            }
554
        } else if (strcmp(argv[flag], "-bottomspring") == 0) {
555
            if (ConfigureSpring(clientPtr, topLevel, interp,
556
                1, 1, argv[value]) == TCL_ERROR) {
557
                return TCL_ERROR;
558
            }
559
        } else if (strcmp(argv[flag], "-bs") == 0) {
560
            if (ConfigureSpring(clientPtr, topLevel, interp,
561
                1, 1, argv[value]) == TCL_ERROR) {
562
                return TCL_ERROR;
563
            }
564
        } else if (strcmp(argv[flag], "-fill") == 0) {
565
            if (ConfigureFill(clientPtr, topLevel, interp,
566
                argv[value]) == TCL_ERROR) {
567
                return TCL_ERROR;
568
            }
569
        } else {
570
            Tcl_AppendResult(interp, "Wrong option \"",
571
                argv[i], "\".", (char *) NULL);
572
            return TCL_ERROR;
573
        }
574
    }
575
 
576
    /*
577
     * Clear the previously set default attachment if the opposide
578
     * edge is attached.
579
     */
580
 
581
#if 0
582
    /* (1) The X axis */
583
    if ((clientPtr->attType[0][0] ==  ATT_DEFAULT_PIXEL)
584
        &&(clientPtr->attType[0][1]  !=  ATT_NONE)) {
585
        clientPtr->attType[0][0]   = ATT_NONE;
586
    }
587
 
588
    /* (2) The Y axis */
589
    if ((clientPtr->attType[1][0] ==  ATT_DEFAULT_PIXEL)
590
        &&(clientPtr->attType[1][1]  !=  ATT_NONE)) {
591
        clientPtr->attType[1][0]   = ATT_NONE;
592
    }
593
#endif
594
 
595
    return TCL_OK;
596
}
597
 

powered by: WebSVN 2.1.0

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