File: tixGrRC.c

package info (click to toggle)
tix 8.4.3-10
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster, sid
  • size: 9,080 kB
  • ctags: 7,129
  • sloc: ansic: 28,082; tcl: 22,774; python: 7,577; makefile: 331; cs: 253; sh: 210; perl: 128
file content (121 lines) | stat: -rw-r--r-- 3,212 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

/*	$Id: tixGrRC.c,v 1.3 2004/03/28 02:44:56 hobbs Exp $	*/

/* 
 * tixGrRC.c --
 *
 *	This module handles "size" sub-commands.
 *
 * Copyright (c) 1996, Expert Interface Technologies
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 */

#include <tixPort.h>
#include <tixInt.h>
#include <tixDef.h>
#include <tixGrid.h>

static TIX_DECLARE_SUBCMD(Tix_GrRCSize);
EXTERN TIX_DECLARE_SUBCMD(Tix_GrSetSize);

int
Tix_GrSetSize(clientData, interp, argc, argv)
    ClientData clientData;
    Tcl_Interp *interp;		/* Current interpreter. */
    int argc;			/* Number of arguments. */
    CONST84 char **argv;	/* Argument strings. */
{
    static Tix_SubCmdInfo subCmdInfo[] = {
	{TIX_DEFAULT_LEN, "row",    1, TIX_VAR_ARGS, Tix_GrRCSize,
	   "index ?option value ...?"},
	{TIX_DEFAULT_LEN, "column", 1, TIX_VAR_ARGS, Tix_GrRCSize,
	   "index ?option value ...?"},
    };
    static Tix_CmdInfo cmdInfo = {
	Tix_ArraySize(subCmdInfo), 1, TIX_VAR_ARGS, "option index ?arg ...?",
    };

    return Tix_HandleSubCmds(&cmdInfo, subCmdInfo, clientData,
	interp, argc+1, argv-1);
}


static int
Tix_GrRCSize(clientData, interp, argc, argv)
    ClientData clientData;
    Tcl_Interp *interp;		/* Current interpreter. */
    int argc;			/* Number of arguments. */
    CONST84 char **argv;	/* Argument strings. */
{
    WidgetPtr wPtr = (WidgetPtr) clientData;
    int which, index, code;
    char errorMsg[300];
    int changed;

    /* TODO: can the index be <0?? */
    if (argv[-1][0] == 'c') {
	which = 0;
    } else {
	which = 1;
    }
    if (Tcl_GetInt(interp, argv[0], &index) != TCL_OK) {
	size_t len = strlen(argv[0]);

	Tcl_ResetResult(interp);
	if (strncmp(argv[0], "default", len) != 0) {
	    Tcl_AppendResult(interp, "unknown option \"", argv[0],
		"\"; must be an integer or \"default\"", NULL);
	    return TCL_ERROR;
	} else {
	    /*
             * Set the default sizes
             */

            /* Buffer size checked: test=grrc-1.2 */
	    sprintf(errorMsg, "%s %s ?option value ...?", argv[-2], argv[-1]);

	    code = Tix_GrConfigSize(interp, wPtr, argc-1, argv+1,
		    &wPtr->defSize[which], errorMsg, &changed);

	    /* Handling special cases */
	    if (code == TCL_OK) {
		switch (wPtr->defSize[which].sizeType) {
		  case TIX_GR_DEFAULT:
		    wPtr->defSize[which].sizeType = TIX_GR_DEFINED_CHAR;
		    if (which == 0) {
			wPtr->defSize[which].charValue = 10.0;
		    } else {
			wPtr->defSize[which].charValue = 1.1;
		    }
		}

		switch (wPtr->defSize[which].sizeType) {
		  case TIX_GR_DEFINED_PIXEL:
		    wPtr->defSize[which].pixels=wPtr->defSize[which].sizeValue;
		    break;

		  case TIX_GR_DEFINED_CHAR:
		    wPtr->defSize[which].pixels =
		       (int)(wPtr->defSize[which].charValue *
			     wPtr->fontSize[which]);
		    break;
		}
	    }
	}
    } else {
        /* Buffer size checked: test=grrc-1.3 */
	sprintf(errorMsg, "%s %s ?option value ...?", argv[-2], argv[-1]);

	code = TixGridDataConfigRowColSize(interp, wPtr, wPtr->dataSet,
	    which, index, argc-1, argv+1, errorMsg, &changed);
    }

    if (changed) {
	Tix_GrDoWhenIdle(wPtr, TIX_GR_RESIZE);
    }

    return code;
}