File: tixHLInd.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 (281 lines) | stat: -rw-r--r-- 8,416 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281

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

/*
 *  tixHLInd.c ---
 *
 *	Implements indicators inside tixHList widgets
 *
 * Copyright (c) 1994-1995 Ioi Kim Lam. All rights reserved.
 *
 * 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 <tixHList.h>

static TIX_DECLARE_SUBCMD(Tix_HLIndCreate);
static TIX_DECLARE_SUBCMD(Tix_HLIndConfig);
static TIX_DECLARE_SUBCMD(Tix_HLIndCGet);
static TIX_DECLARE_SUBCMD(Tix_HLIndDelete);
static TIX_DECLARE_SUBCMD(Tix_HLIndExists);
static TIX_DECLARE_SUBCMD(Tix_HLIndSize);


/*----------------------------------------------------------------------
 * "indicator" sub command
 *----------------------------------------------------------------------
 */
int
Tix_HLIndicator(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, "cget", 2, 2, Tix_HLIndCGet,
	   "entryPath option"},
	{TIX_DEFAULT_LEN, "configure", 1, TIX_VAR_ARGS, Tix_HLIndConfig,
	   "entryPath ?option? ?value ...?"},
	{TIX_DEFAULT_LEN, "create", 1, TIX_VAR_ARGS, Tix_HLIndCreate,
	   "entryPath ?option value ...?"},
	{TIX_DEFAULT_LEN, "delete", 1, 1, Tix_HLIndDelete,
	   "entryPath"},
	{TIX_DEFAULT_LEN, "exists", 1, 1, Tix_HLIndExists,
	   "entryPath"},
	{TIX_DEFAULT_LEN, "size", 1, 1, Tix_HLIndSize,
	   "entryPath"},
    };
    static Tix_CmdInfo cmdInfo = {
	Tix_ArraySize(subCmdInfo), 1, TIX_VAR_ARGS, "?option? ?arg ...?",
    };

    return Tix_HandleSubCmds(&cmdInfo, subCmdInfo, clientData,
	interp, argc+1, argv-1);
}

/*----------------------------------------------------------------------
 * "indicator cget" sub command
 *----------------------------------------------------------------------
 */
static int
Tix_HLIndCGet(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;
    HListElement * chPtr;

    if ((chPtr = Tix_HLFindElement(interp, wPtr, argv[0])) == NULL) {
	return TCL_ERROR;
    }
    if (chPtr->indicator == NULL) {
	Tcl_AppendResult(interp, "entry \"", argv[0],
	    "\" does not have an indicator", (char*)NULL); 
	return TCL_ERROR;
    }
    return Tk_ConfigureValue(interp, wPtr->dispData.tkwin, 
	chPtr->indicator->base.diTypePtr->itemConfigSpecs,
	(char *)chPtr->indicator, argv[1], 0);
}

/*----------------------------------------------------------------------
 * "indicator configure" sub command
 *----------------------------------------------------------------------
 */
static int
Tix_HLIndConfig(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;
    HListElement * chPtr;

    if ((chPtr = Tix_HLFindElement(interp, wPtr, argv[0])) == NULL) {
	return TCL_ERROR;
    }
    if (chPtr->indicator == NULL) {
	Tcl_AppendResult(interp, "entry \"", argv[0],
	    "\" does not have an indicator", (char*)NULL); 
	return TCL_ERROR;
    }
    if (argc == 1) {
	return Tk_ConfigureInfo(interp, wPtr->dispData.tkwin, 
	    chPtr->indicator->base.diTypePtr->itemConfigSpecs,
	    (char *)chPtr->indicator, NULL, 0);
    } else if (argc == 2) {
	return Tk_ConfigureInfo(interp, wPtr->dispData.tkwin, 
	    chPtr->indicator->base.diTypePtr->itemConfigSpecs,
	    (char *)chPtr->indicator, argv[1], 0);
    } else {
	Tix_HLMarkElementDirty(wPtr, chPtr);
	Tix_HLResizeWhenIdle(wPtr);

	return Tix_DItemConfigure(chPtr->indicator,
	    argc-1, argv+1, TK_CONFIG_ARGV_ONLY);
    }
}

/*----------------------------------------------------------------------
 * "indicator create" sub command
 *----------------------------------------------------------------------
 */
static int
Tix_HLIndCreate(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;
    HListElement * chPtr;
    int i;
    size_t len;
    Tix_DItem * iPtr;
    CONST84 char * ditemType = NULL;

    if ((chPtr = Tix_HLFindElement(interp, wPtr, argv[0])) == NULL) {
	return TCL_ERROR;
    }
    if ((argc %2) == 0) {
	Tcl_AppendResult(interp, "value for \"", argv[argc-1],
	    "\" missing", NULL);
	return TCL_ERROR;
    }
    for (i=1; i<argc; i+=2) {
	len = strlen(argv[i]);
	if (strncmp(argv[i], "-itemtype", len) == 0) {
	    ditemType = argv[i+1];
	}
    }
    if (ditemType == NULL) {
	ditemType = wPtr->diTypePtr->name;
    }

    iPtr = Tix_DItemCreate(&wPtr->dispData, ditemType);
    if (iPtr == NULL) {
	return TCL_ERROR;
    }
    if (Tix_DItemType(iPtr) == TIX_DITEM_WINDOW) {
	wPtr->needToRaise = 1;
    }

    iPtr->base.clientData = (ClientData)chPtr;
    if (Tix_DItemConfigure(iPtr, argc-1, argv+1, 0) != TCL_OK) {
	return TCL_ERROR;
    }

    if (chPtr->indicator != NULL) {
	if (Tix_DItemType(chPtr->indicator) == TIX_DITEM_WINDOW) {
	    Tix_WindowItemListRemove(&wPtr->mappedWindows,
		chPtr->indicator);
	}
	Tix_DItemFree(chPtr->indicator);
    }
    chPtr->indicator = iPtr;
    Tix_HLMarkElementDirty(wPtr, chPtr);
    Tix_HLResizeWhenIdle(wPtr);

    return TCL_OK;
}
/*----------------------------------------------------------------------
 * "indicator delete" sub command
 *----------------------------------------------------------------------
 */
static int
Tix_HLIndDelete(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;
    HListElement * chPtr;

    if ((chPtr = Tix_HLFindElement(interp, wPtr, argv[0])) == NULL) {
	return TCL_ERROR;
    }
    if (chPtr->indicator == NULL) {
	Tcl_AppendResult(interp, "entry \"", argv[0],
	    "\" does not have an indicator", (char*)NULL); 
	return TCL_ERROR;
    }

    if (Tix_DItemType(chPtr->indicator) == TIX_DITEM_WINDOW) {
	Tix_WindowItemListRemove(&wPtr->mappedWindows,
	    chPtr->indicator);
    }

    /* Free the item and leave a blank! */

    Tix_DItemFree(chPtr->indicator);
    chPtr->indicator = NULL;

    Tix_HLMarkElementDirty(wPtr, chPtr);
    Tix_HLResizeWhenIdle(wPtr);

    return TCL_OK;
}
/*----------------------------------------------------------------------
 * "indicator exists" sub command
 *----------------------------------------------------------------------
 */
static int
Tix_HLIndExists(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;
    HListElement * chPtr;

    if ((chPtr = Tix_HLFindElement(interp, wPtr, argv[0])) == NULL) {
	return TCL_ERROR;
    }
    if (chPtr->indicator == NULL) {
	Tcl_AppendResult(interp, "0", NULL);
    } else {
	Tcl_AppendResult(interp, "1", NULL);
    }

    return TCL_OK;
}

/*----------------------------------------------------------------------
 * "indicator size" sub command
 *----------------------------------------------------------------------
 */
static int
Tix_HLIndSize(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;
    HListElement * chPtr;
    char buff[100];

    if ((chPtr = Tix_HLFindElement(interp, wPtr, argv[0])) == NULL) {
	return TCL_ERROR;
    }
    if (chPtr->indicator == NULL) {
	Tcl_AppendResult(interp, "entry \"", argv[0],
	    "\" does not have an indicator", (char*)NULL); 
	return TCL_ERROR;
    }
    sprintf(buff, "%d %d",
	Tix_DItemWidth(chPtr->indicator),
	Tix_DItemHeight(chPtr->indicator));
    Tcl_AppendResult(interp, buff, NULL);
    return TCL_OK;
}