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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [insight/] [tix/] [generic/] [tixUtils.c] - Blame information for rev 578

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
2
 * tixUtils.c --
3
 *
4
 *      This file contains some utility functions for Tix, such as the
5
 *      subcommand handling functions and option handling functions.
6
 *
7
 * Copyright (c) 1996, Expert Interface Technologies
8
 *
9
 * See the file "license.terms" for information on usage and redistribution
10
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11
 *
12
 */
13
 
14
/*
15
 * tclInt.h is needed for the va_list declaration.
16
 */
17
#include <tclInt.h>
18
#include <tixPort.h>
19
#include <tixInt.h>
20
 
21
/*
22
 * Forward declarations for procedures defined later in this file:
23
 */
24
 
25
static void             Prompt _ANSI_ARGS_((Tcl_Interp *interp, int partial));
26
static void             StdinProc _ANSI_ARGS_((ClientData clientData,
27
                            int mask));
28
 
29
static int              ReliefParseProc _ANSI_ARGS_((ClientData clientData,
30
                            Tcl_Interp *interp, Tk_Window tkwin, char *value,
31
                            char *widRec, int offset));
32
static char *           ReliefPrintProc _ANSI_ARGS_((ClientData clientData,
33
                            Tk_Window tkwin, char *widRec, int offset,
34
                            Tix_FreeProc **freeProcPtr));
35
/*
36
 * Global vars used in this file
37
 */
38
static Tcl_DString command;     /* Used to assemble lines of terminal input
39
                                 * into Tcl commands. */
40
 
41
 
42
#define WRONG_ARGC 1
43
#define NO_MATCH   2
44
 
45
 
46
/*----------------------------------------------------------------------
47
 * TixSaveInterpState --
48
 *
49
 *      Save the current application-visible state of the interpreter.
50
 *      This can later be restored by the TixSaveInterpState() function.
51
 *      These two functions are useful if you want to evaluate a Tcl
52
 *      command, which may cause errors, inside a command function.
53
 *
54
 *      Each TixSaveInterpState() call much be matched by one
55
 *      TixRestoreInterpState() call with the same statePtr. statePtr
56
 *      should be allocated by the calling function, usually
57
 *      as a variable on the stack.
58
 *----------------------------------------------------------------------
59
 */
60
 
61
void
62
TixSaveInterpState(interp, statePtr)
63
    Tcl_Interp * interp;
64
    TixInterpState * statePtr;
65
{
66
    char * p;
67
    if (interp->result) {
68
        statePtr->result = (char*)tixStrDup(interp->result);
69
    } else {
70
        statePtr->result = NULL;
71
    }
72
 
73
    p = Tcl_GetVar2(interp, "errorInfo", NULL, TCL_GLOBAL_ONLY);
74
    if (p) {
75
        statePtr->errorInfo = (char*)tixStrDup(p);
76
    } else {
77
        statePtr->errorInfo = NULL;
78
    }
79
 
80
    p = Tcl_GetVar2(interp, "errorCode", NULL, TCL_GLOBAL_ONLY);
81
    if (p) {
82
        statePtr->errorCode = (char*)tixStrDup(p);
83
    } else {
84
        statePtr->errorCode = NULL;
85
    }
86
}
87
 
88
/*----------------------------------------------------------------------
89
 * TixRestoreInterpState --
90
 *
91
 *      See TixSaveInterpState above.
92
 *----------------------------------------------------------------------
93
 */
94
 
95
void
96
TixRestoreInterpState(interp, statePtr)
97
    Tcl_Interp * interp;
98
    TixInterpState * statePtr;
99
{
100
    if (statePtr->result) {
101
        Tcl_SetResult(interp, statePtr->result, TCL_DYNAMIC);
102
    }
103
    if (statePtr->errorInfo) {
104
        Tcl_SetVar2(interp, "errorInfo", NULL, statePtr->errorInfo,
105
                TCL_GLOBAL_ONLY);
106
        ckfree((char*)statePtr->errorInfo);
107
    } else {
108
        Tcl_UnsetVar2(interp, "errorInfo", NULL, TCL_GLOBAL_ONLY);
109
    }
110
    if (statePtr->errorCode) {
111
        Tcl_SetVar2(interp, "errorCode", NULL, statePtr->errorCode,
112
                TCL_GLOBAL_ONLY);
113
        ckfree((char*)statePtr->errorCode);
114
    } else {
115
        Tcl_UnsetVar2(interp, "errorCode", NULL, TCL_GLOBAL_ONLY);
116
    }
117
}
118
 
119
/*----------------------------------------------------------------------
120
 * Tix_HandleSubCmds --
121
 *
122
 *      This function makes it easier to write major-minor style TCL
123
 *      commands.  It matches the minor command (sub-command) names
124
 *      with names defined in the cmdInfo structure and call the
125
 *      appropriate sub-command functions for you. This function will
126
 *      automatically generate error messages when the user calls an
127
 *      invalid sub-command or calls a sub-command with incorrect
128
 *      number of arguments.
129
 *
130
 *----------------------------------------------------------------------
131
 */
132
 
133
int Tix_HandleSubCmds(cmdInfo, subCmdInfo, clientData, interp, argc, argv)
134
    Tix_CmdInfo * cmdInfo;
135
    Tix_SubCmdInfo * subCmdInfo;
136
    ClientData clientData;      /* Main window associated with
137
                                 * interpreter. */
138
    Tcl_Interp *interp;         /* Current interpreter. */
139
    int argc;                   /* Number of arguments. */
140
    char **argv;                /* Argument strings. */
141
{
142
 
143
    int i;
144
    int len;
145
    int error = NO_MATCH;
146
    Tix_SubCmdInfo * s;
147
 
148
    /*
149
     * First check if the number of arguments to the major command
150
     * is correct
151
     */
152
    argc -= 1;
153
    if (argc < cmdInfo->minargc ||
154
        (cmdInfo->maxargc != TIX_VAR_ARGS && argc > cmdInfo->maxargc)) {
155
 
156
        Tcl_AppendResult(interp, "wrong # args: should be \"",
157
            argv[0], " ", cmdInfo->info, "\".", (char *) NULL);
158
 
159
        return TCL_ERROR;
160
    }
161
 
162
    /*
163
     * Now try to match the subcommands with argv[1]
164
     */
165
    argc -= 1;
166
    len = strlen(argv[1]);
167
 
168
    for (i = 0, s = subCmdInfo; i < cmdInfo->numSubCmds; i++, s++) {
169
        if (s->name == TIX_DEFAULT_SUBCMD) {
170
            if (s->checkArgvProc) {
171
              if (!((*s->checkArgvProc)(clientData, interp, argc+1, argv+1))) {
172
                    /* Some improper argv in the arguments of the default
173
                     * subcommand
174
                     */
175
                    break;
176
                }
177
            }
178
            return (*s->proc)(clientData, interp, argc+1, argv+1);
179
        }
180
 
181
        if (s->namelen == TIX_DEFAULT_LEN) {
182
            s->namelen = strlen(s->name);
183
        }
184
        if (s->name[0] == argv[1][0] && strncmp(argv[1],s->name,len)==0) {
185
            if (argc < s->minargc) {
186
                error = WRONG_ARGC;
187
                break;
188
            }
189
 
190
            if (s->maxargc != TIX_VAR_ARGS &&
191
                argc > s->maxargc) {
192
                error = WRONG_ARGC;
193
                break;
194
            }
195
 
196
            /*
197
             * Here we have a matched argc and command name --> go for it!
198
             */
199
            return (*s->proc)(clientData, interp, argc, argv+2);
200
        }
201
    }
202
 
203
    if (error == WRONG_ARGC) {
204
        /*
205
         * got a match but incorrect number of arguments
206
         */
207
        Tcl_AppendResult(interp, "wrong # args: should be \"",
208
            argv[0], " ", argv[1], " ", s->info, "\"", (char *) NULL);
209
    } else {
210
        int max;
211
 
212
        /*
213
         * no match: let print out all the options
214
         */
215
        Tcl_AppendResult(interp, "unknown option \"",
216
            argv[1], "\".",  (char *) NULL);
217
 
218
        if (cmdInfo->numSubCmds == 0) {
219
            max = 0;
220
        } else {
221
            if (subCmdInfo[cmdInfo->numSubCmds-1].name == TIX_DEFAULT_SUBCMD) {
222
                max = cmdInfo->numSubCmds-1;
223
            } else {
224
                max = cmdInfo->numSubCmds;
225
            }
226
        }
227
 
228
        if (max == 0) {
229
            Tcl_AppendResult(interp,
230
                " This command does not take any options.",
231
                (char *) NULL);
232
        } else if (max == 1) {
233
            Tcl_AppendResult(interp,
234
                " Must be ", subCmdInfo->name, ".", (char *)NULL);
235
        } else {
236
            Tcl_AppendResult(interp, " Must be ", (char *) NULL);
237
 
238
            for (i = 0, s = subCmdInfo; i < max; i++, s++) {
239
                if (i == max-1) {
240
                    Tcl_AppendResult(interp,"or ",s->name, ".", (char *) NULL);
241
                } else if (i == max-2) {
242
                    Tcl_AppendResult(interp, s->name, " ", (char *) NULL);
243
                } else {
244
                    Tcl_AppendResult(interp, s->name, ", ", (char *) NULL);
245
                }
246
            }
247
        }
248
    }
249
    return TCL_ERROR;
250
}
251
 
252
/*----------------------------------------------------------------------
253
 * Tix_Exit --
254
 *
255
 *      Call the "exit" tcl command so that things can be cleaned up
256
 *      before calling the unix exit(2);
257
 *
258
 *----------------------------------------------------------------------
259
 */
260
void Tix_Exit(interp, code)
261
    Tcl_Interp* interp;
262
    int code;
263
{
264
    if (code != 0 && interp && interp->result != 0) {
265
        fprintf(stderr, "%s\n", interp->result);
266
        fprintf(stderr, "%s\n",
267
            Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY));
268
    }
269
 
270
    if (interp) {
271
        Tcl_GlobalEval(interp, "exit");
272
    }
273
    exit(code);
274
}
275
 
276
/*
277
 *----------------------------------------------------------------------
278
 *
279
 * Tix_LoadTclLibrary --
280
 *
281
 *      Loads in a TCL library for an application according to
282
 *      the library settings.
283
 *
284
 * Results:
285
 *      TCL_OK or TCL_ERROR
286
 *
287
 * envName      the environment variable that indicates the library
288
 * tclName      the TCL variable that points to the TCL library.
289
 * initFile     the file to load in during initialization.
290
 * defDir       the default directory to search if the user hasn't set
291
 *              the environment variable.
292
 * appName      the name of the application.
293
 *----------------------------------------------------------------------
294
 */
295
 
296
/* Some compilers can't handle multi-line character strings very well ...
297
 * So I just using this big lump of mess here.
298
 */
299
 
300
static char _format[] = "lappend auto_path $%s \nif [file exists $%s/%s] {\nsource $%s/%s\n} else {\nset msg \"\ncan't find $%s/%s;\\nperhaps you \"\nappend msg \"need to install %s\\nor set your %s \"\nappend msg \"environment variable?\"\nerror $msg\n}";
301
 
302
int
303
Tix_LoadTclLibrary(interp, envName, tclName, initFile, defDir, appName)
304
    Tcl_Interp *interp;
305
    char *envName;
306
    char *tclName;
307
    char *initFile;
308
    char *defDir;
309
    char *appName;
310
{
311
    char * libDir, *initCmd;
312
    size_t size;
313
    int code;
314
    char *format;
315
    format = _format;
316
 
317
    libDir = getenv(envName);
318
    if (libDir == NULL) {
319
        libDir = defDir;
320
    }
321
 
322
    /*
323
     * This size should be big enough.
324
     */
325
 
326
    size = strlen(format) + strlen(tclName)*4 + strlen(initFile)*3
327
        + strlen(appName) + strlen(envName) + 100;
328
    initCmd = ckalloc(sizeof(char) * size);
329
 
330
    Tcl_SetVar(interp, tclName, libDir, TCL_GLOBAL_ONLY);
331
 
332
    sprintf(initCmd, format,
333
        tclName,
334
        tclName, initFile,
335
        tclName, initFile,
336
        tclName, initFile,
337
        appName, envName
338
    );
339
 
340
    code =  Tcl_GlobalEval(interp, initCmd);
341
    ckfree(initCmd);
342
    return code;
343
}
344
 
345
/*----------------------------------------------------------------------
346
 * Tix_CreateCommands --
347
 *
348
 *
349
 *      Creates a list of commands stored in the array "commands"
350
 *----------------------------------------------------------------------
351
 */
352
 
353
void Tix_CreateCommands(interp, commands, clientData, deleteProc)
354
    Tcl_Interp *interp;
355
    Tix_TclCmd *commands;
356
    ClientData clientData;
357
    Tcl_CmdDeleteProc *deleteProc;
358
{
359
    Tix_TclCmd * cmdPtr;
360
 
361
    for (cmdPtr = commands; cmdPtr->name != NULL; cmdPtr++) {
362
        Tcl_CreateCommand(interp, cmdPtr->name,
363
             cmdPtr->cmdProc, clientData, deleteProc);
364
    }
365
}
366
 
367
/*----------------------------------------------------------------------
368
 * Tix_DrawAnchorLines --
369
 *
370
 *      Draw dotted anchor lines around anchor elements
371
 *----------------------------------------------------------------------
372
 */
373
 
374
void Tix_DrawAnchorLines(display, drawable, gc, x, y, w, h)
375
    Display *display;
376
    Drawable drawable;
377
    GC gc;
378
    int x;
379
    int y;
380
    int w;
381
    int h;
382
{
383
    TixpDrawAnchorLines(display, drawable, gc, x, y, w, h);
384
}
385
 
386
/*----------------------------------------------------------------------
387
 * Tix_CreateSubWindow --
388
 *
389
 *      Creates a subwindow for a widget (usually used to draw headers,
390
 *      e.g, HList and Grid widgets)
391
 *----------------------------------------------------------------------
392
 */
393
 
394
Tk_Window
395
Tix_CreateSubWindow(interp, tkwin, subPath)
396
    Tcl_Interp * interp;
397
    Tk_Window tkwin;
398
    char * subPath;
399
{
400
    Tcl_DString dString;
401
    Tk_Window subwin;
402
 
403
    Tcl_DStringInit(&dString);
404
    Tcl_DStringAppend(&dString, Tk_PathName(tkwin),
405
        strlen(Tk_PathName(tkwin)));
406
    Tcl_DStringAppend(&dString, ".tixsw:", 7);
407
    Tcl_DStringAppend(&dString, subPath, strlen(subPath));
408
 
409
    subwin = Tk_CreateWindowFromPath(interp, tkwin, dString.string,
410
        (char *) NULL);
411
 
412
    Tcl_DStringFree(&dString);
413
 
414
    return subwin;
415
}
416
 
417
/*----------------------------------------------------------------------
418
 * Tix_GetRenderBuffer --
419
 *
420
 *      Returns a drawable for rendering a widget. If there is sufficient
421
 *      resource, a pixmap is returned so that double-buffering can
422
 *      be done. However, if resource is insufficient, then the
423
 *      windowId is returned. In the second case happens, the caller
424
 *      of this function has two choices: (1) draw to the window directly
425
 *      (which may lead to flashing on the screen) or (2) try to allocate
426
 *      smaller pixmaps.
427
 *----------------------------------------------------------------------
428
 */
429
 
430
static int
431
ErrorProc(clientData, errorEventPtr)
432
    ClientData clientData;
433
    XErrorEvent *errorEventPtr;         /* unused */
434
{
435
    int * badAllocPtr = (int*) clientData;
436
 
437
    * badAllocPtr = 1;
438
    return 0;                            /* return 0 means error has been
439
                                         * handled properly */
440
}
441
 
442
Drawable Tix_GetRenderBuffer(display, windowId, width, height, depth)
443
    Display *display;
444
    Window windowId;
445
    int width;
446
    int height;
447
    int depth;
448
{
449
    Tk_ErrorHandler handler;
450
    Pixmap pixmap;
451
    int badAlloc = 0;
452
 
453
    handler= Tk_CreateErrorHandler(display, BadAlloc,
454
        -1, -1, (Tk_ErrorProc *) ErrorProc, (ClientData) &badAlloc);
455
    pixmap = Tk_GetPixmap(display, windowId, width, height, depth);
456
 
457
#ifndef _WINDOWS
458
    /*
459
     * This XSync call is necessary because X may delay the delivery of the
460
     * error message. This will make our graphics a bit slower, though,
461
     * especially over slow lines
462
     */
463
    XSync(display, 0);
464
#endif
465
    /* If ErrorProc() is eevr called, it is called before XSync returns */
466
 
467
    Tk_DeleteErrorHandler(handler);
468
 
469
    if (!badAlloc) {
470
        return pixmap;
471
    } else {
472
        return windowId;
473
    }
474
}
475
 
476
/*
477
 *----------------------------------------------------------------------
478
 *
479
 * Tix_GlobalVarEval --
480
 *
481
 *      Given a variable number of string arguments, concatenate them
482
 *      all together and execute the result as a Tcl command in the global
483
 *      scope.
484
 *
485
 * Results:
486
 *      A standard Tcl return result.  An error message or other
487
 *      result may be left in interp->result.
488
 *
489
 * Side effects:
490
 *      Depends on what was done by the command.
491
 *
492
 *----------------------------------------------------------------------
493
 */
494
        /* VARARGS2 */ /* ARGSUSED */
495
int
496
#ifdef TCL_VARARGS_DEF
497
Tix_GlobalVarEval TCL_VARARGS_DEF(Tcl_Interp *,arg1)
498
#else
499
#ifndef lint
500
Tix_GlobalVarEval(va_alist)
501
#else
502
Tix_GlobalVarEval(iPtr, p, va_alist)
503
    Tcl_Interp *iPtr;           /* Interpreter in which to execute command. */
504
    char *p;                    /* One or more strings to concatenate,
505
                                 * terminated with a NULL string. */
506
#endif
507
    va_dcl
508
#endif
509
{
510
    va_list argList;
511
    Tcl_DString buf;
512
    char *string;
513
    Tcl_Interp *interp;
514
    int result;
515
 
516
#ifdef TCL_VARARGS_DEF
517
    /*
518
     * Copy the strings one after the other into a single larger
519
     * string.  Use stack-allocated space for small commands, but if
520
     * the command gets too large than call ckalloc to create the
521
     * space.
522
     */
523
 
524
    interp = TCL_VARARGS_START(Tcl_Interp *,arg1,argList);
525
    Tcl_DStringInit(&buf);
526
    while (1) {
527
        string = va_arg(argList, char *);
528
        if (string == NULL) {
529
            break;
530
        }
531
        Tcl_DStringAppend(&buf, string, -1);
532
    }
533
    va_end(argList);
534
 
535
    result = Tcl_GlobalEval(interp, Tcl_DStringValue(&buf));
536
    Tcl_DStringFree(&buf);
537
    return result;
538
#else
539
    va_start(argList);
540
    interp = va_arg(argList, Tcl_Interp *);
541
    Tcl_DStringInit(&buf);
542
    while (1) {
543
        string = va_arg(argList, char *);
544
        if (string == NULL) {
545
            break;
546
        }
547
        Tcl_DStringAppend(&buf, string, -1);
548
    }
549
    va_end(argList);
550
 
551
    result = Tcl_GlobalEval(interp, Tcl_DStringValue(&buf));
552
    Tcl_DStringFree(&buf);
553
    return result;
554
#endif
555
}
556
 
557
/*----------------------------------------------------------------------
558
 * TixGetHashTable --
559
 *
560
 *      This functions makes it possible to keep one hash table per
561
 *      interpreter. This way, Tix classes can be used in multiple
562
 *      interpreters.
563
 *
564
 *----------------------------------------------------------------------
565
 */
566
 
567
#ifdef TK_4_1_OR_LATER
568
 
569
static void             DeleteHashTableProc _ANSI_ARGS_((ClientData clientData,
570
                            Tcl_Interp * interp));
571
static void
572
DeleteHashTableProc(clientData, interp)
573
    ClientData clientData;
574
    Tcl_Interp * interp;
575
{
576
    Tcl_HashTable * htPtr = (Tcl_HashTable *)clientData;
577
    Tcl_HashSearch hashSearch;
578
    Tcl_HashEntry * hashPtr;
579
 
580
    for (hashPtr = Tcl_FirstHashEntry(htPtr, &hashSearch);
581
            hashPtr;
582
            hashPtr = Tcl_NextHashEntry(&hashSearch)) {
583
        Tcl_DeleteHashEntry(hashPtr);
584
    }
585
 
586
    Tcl_DeleteHashTable(htPtr);
587
    ckfree((char*)htPtr);
588
}
589
 
590
Tcl_HashTable *
591
TixGetHashTable(interp, name, deleteProc)
592
    Tcl_Interp * interp;
593
    char * name;
594
    Tcl_InterpDeleteProc *deleteProc;
595
{
596
    Tcl_HashTable * htPtr;
597
 
598
    htPtr = (Tcl_HashTable*)Tcl_GetAssocData(interp, name, NULL);
599
    if (htPtr == NULL) {
600
        htPtr = (Tcl_HashTable *)ckalloc(sizeof(Tcl_HashTable));
601
        Tcl_InitHashTable(htPtr, TCL_STRING_KEYS);
602
        Tcl_SetAssocData(interp, name, NULL, (ClientData)htPtr);
603
        if (deleteProc) {
604
            Tcl_CallWhenDeleted(interp, deleteProc, (ClientData)htPtr);
605
        } else {
606
            Tcl_CallWhenDeleted(interp, DeleteHashTableProc,
607
                    (ClientData)htPtr);
608
        }
609
    }
610
 
611
    return htPtr;
612
}
613
 
614
#else
615
 
616
Tcl_HashTable *
617
TixGetHashTable(interp, name)
618
    Tcl_Interp * interp;        /* Current interpreter. */
619
    char * name;                /* Textual name of the hash table. */
620
{
621
    static int inited = 0;
622
    static Tcl_HashTable classTable;
623
    static Tcl_HashTable methodTable;
624
    static Tcl_HashTable specTable;
625
 
626
    if (!inited) {
627
        Tcl_InitHashTable(&classTable, TCL_STRING_KEYS);
628
        Tcl_InitHashTable(&methodTable, TCL_STRING_KEYS);
629
        Tcl_InitHashTable(&specTable, TCL_STRING_KEYS);
630
        inited = 1;
631
    }
632
 
633
    if (strcmp(name, "tixClassTab") == 0) {
634
        return &classTable;
635
    } else if (strcmp(name, "tixSpecTab") == 0) {
636
        return &specTable;
637
    } else if (strcmp(name, "tixMethodTab") == 0) {
638
        return &methodTable;
639
    } else {
640
        panic("Unknown hash table %s", name);
641
    }
642
}
643
#endif
644
 
645
/*----------------------------------------------------------------------
646
 *
647
 *               The Tix Customed Config Options
648
 *
649
 *----------------------------------------------------------------------
650
 */
651
 
652
/*----------------------------------------------------------------------
653
 *  ReliefParseProc --
654
 *
655
 *      Parse the text string and store the Tix_Relief information
656
 *      inside the widget record.
657
 *----------------------------------------------------------------------
658
 */
659
static int ReliefParseProc(clientData, interp, tkwin, value, widRec,offset)
660
    ClientData clientData;
661
    Tcl_Interp *interp;
662
    Tk_Window tkwin;
663
    char *value;
664
    char *widRec;               /* Must point to a valid Tix_DItem struct */
665
    int offset;
666
{
667
    Tix_Relief * ptr = (Tix_Relief *)(widRec + offset);
668
    Tix_Relief   newVal;
669
 
670
    if (value != NULL) {
671
        size_t len = strlen(value);
672
 
673
        if (strncmp(value, "raised", len) == 0) {
674
            newVal = TIX_RELIEF_RAISED;
675
        } else if (strncmp(value, "flat", len) == 0) {
676
            newVal = TIX_RELIEF_FLAT;
677
        } else if (strncmp(value, "sunken", len) == 0) {
678
            newVal = TIX_RELIEF_SUNKEN;
679
        } else if (strncmp(value, "groove", len) == 0) {
680
            newVal = TIX_RELIEF_GROOVE;
681
        } else if (strncmp(value, "ridge", len) == 0) {
682
            newVal = TIX_RELIEF_RIDGE;
683
        } else if (strncmp(value, "solid", len) == 0) {
684
            newVal = TIX_RELIEF_SOLID;
685
        } else {
686
            goto error;
687
        }
688
    } else {
689
        value = "";
690
        goto error;
691
    }
692
 
693
    *ptr = newVal;
694
    return TCL_OK;
695
 
696
  error:
697
    Tcl_AppendResult(interp, "bad relief type \"", value,
698
        "\":  must be flat, groove, raised, ridge, solid or sunken", NULL);
699
    return TCL_ERROR;
700
}
701
 
702
static char *ReliefPrintProc(clientData, tkwin, widRec,offset, freeProcPtr)
703
    ClientData clientData;
704
    Tk_Window tkwin;
705
    char *widRec;
706
    int offset;
707
    Tix_FreeProc **freeProcPtr;
708
{
709
    Tix_Relief *ptr = (Tix_Relief*)(widRec+offset);
710
 
711
    switch (*ptr) {
712
      case TIX_RELIEF_RAISED:
713
        return "raised";
714
      case TIX_RELIEF_FLAT:
715
        return "flat";
716
      case TIX_RELIEF_SUNKEN:
717
        return "sunken";
718
      case TIX_RELIEF_GROOVE:
719
        return "groove";
720
      case TIX_RELIEF_RIDGE:
721
        return "ridge";
722
      case TIX_RELIEF_SOLID:
723
        return "solid";
724
      default:
725
        return "unknown";
726
    }
727
}
728
/*
729
 * The global data structures to use in widget configSpecs arrays
730
 *
731
 * These are declared in <tix.h>
732
 */
733
 
734
Tk_CustomOption tixConfigRelief = {
735
    ReliefParseProc, ReliefPrintProc, 0,
736
};
737
 
738
/* Tix_SetRcFileName --
739
 *
740
 *      Sets a user-specific startup file in a way that's compatible with
741
 *      different versions of Tclsh
742
 */
743
void Tix_SetRcFileName(interp, rcFileName)
744
    Tcl_Interp * interp;
745
    char * rcFileName;
746
{
747
#ifdef TCL_7_5_OR_LATER
748
    /*
749
     * Starting from TCL 7.5, the symbol tcl_rcFileName is no longer
750
     * exported by libtcl.a. Instead, this variable must be set using
751
     * a TCL global variable
752
     */
753
    Tcl_SetVar(interp, "tcl_rcFileName", rcFileName, TCL_GLOBAL_ONLY);
754
#else
755
    tcl_RcFileName = rcFileName;
756
#endif
757
}
758
 
759
#if (TK_MAJOR_VERSION > 4)
760
 
761
/*
762
 * The TkComputeTextGeometry function is no longer supported in Tk 8.0+
763
 */
764
 
765
/*
766
 *----------------------------------------------------------------------
767
 *
768
 * TixComputeTextGeometry --
769
 *
770
 *      This procedure computes the amount of screen space needed to
771
 *      display a multi-line string of text.
772
 *
773
 * Results:
774
 *      There is no return value.  The dimensions of the screen area
775
 *      needed to display the text are returned in *widthPtr, and *heightPtr.
776
 *
777
 * Side effects:
778
 *      None.
779
 *
780
 *----------------------------------------------------------------------
781
 */
782
 
783
void
784
TixComputeTextGeometry(font, string, numChars, wrapLength,
785
        widthPtr, heightPtr)
786
    TixFont font;               /* Font that will be used to display text. */
787
    char *string;               /* String whose dimensions are to be
788
                                 * computed. */
789
    int numChars;               /* Number of characters to consider from
790
                                 * string. */
791
    int wrapLength;             /* Longest permissible line length, in
792
                                 * pixels.  <= 0 means no automatic wrapping:
793
                                 * just let lines get as long as needed. */
794
    int *widthPtr;              /* Store width of string here. */
795
    int *heightPtr;             /* Store height of string here. */
796
{
797
    Tk_TextLayout textLayout;
798
 
799
    /*
800
     * The justification itself doesn't affect the geometry (size) of
801
     * the text string. We pass TK_JUSTIFY_LEFT.
802
     */
803
 
804
    textLayout = Tk_ComputeTextLayout(font,
805
        string, numChars, wrapLength, TK_JUSTIFY_LEFT, 0,
806
        widthPtr, heightPtr);
807
    Tk_FreeTextLayout(textLayout);
808
}
809
 
810
/*
811
 *----------------------------------------------------------------------
812
 *
813
 * TixDisplayText --
814
 *
815
 *      Display a text string on one or more lines.
816
 *
817
 * Results:
818
 *      None.
819
 *
820
 * Side effects:
821
 *      The text given by "string" gets displayed at the given location
822
 *      in the given drawable with the given font etc.
823
 *
824
 *----------------------------------------------------------------------
825
 */
826
 
827
void
828
TixDisplayText(display, drawable, font, string, numChars, x, y,
829
        length, justify, underline, gc)
830
    Display *display;           /* X display to use for drawing text. */
831
    Drawable drawable;          /* Window or pixmap in which to draw the
832
                                 * text. */
833
    TixFont font;               /* Font that determines geometry of text
834
                                 * (should be same as font in gc). */
835
    char *string;               /* String to display;  may contain embedded
836
                                 * newlines. */
837
    int numChars;               /* Number of characters to use from string. */
838
    int x, y;                   /* Pixel coordinates within drawable of
839
                                 * upper left corner of display area. */
840
    int length;                 /* Line length in pixels;  used to compute
841
                                 * word wrap points and also for
842
                                 * justification.   Must be > 0. */
843
    Tk_Justify justify;         /* How to justify lines. */
844
    int underline;              /* Index of character to underline, or < 0
845
                                 * for no underlining. */
846
    GC gc;                      /* Graphics context to use for drawing text. */
847
{
848
    Tk_TextLayout textLayout;
849
    int dummy;
850
 
851
    textLayout = Tk_ComputeTextLayout(font,
852
        string, numChars, length, justify, 0,
853
        &dummy, &dummy);
854
 
855
    Tk_DrawTextLayout(display, drawable, gc, textLayout,
856
            x, y, 0, -1);
857
    Tk_UnderlineTextLayout(display, drawable, gc,
858
            textLayout, x, y, underline);
859
 
860
    Tk_FreeTextLayout(textLayout);
861
}
862
#endif
863
 

powered by: WebSVN 2.1.0

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