File: tixInit.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 (367 lines) | stat: -rw-r--r-- 10,742 bytes parent folder | download
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/*	$Id: tixInit.c,v 1.20 2008/02/28 22:25:56 hobbs Exp $ */

/*
 * tixInit.c --
 *
 *	Initialze the Tix native code as well as the script library.
 *
 * Copyright (c) 1993-1999 Ioi Kim Lam.
 * Copyright (c) 2000-2001 Tix Project Group.
 * Copyright 2004 ActiveState
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * $Id: tixInit.c,v 1.20 2008/02/28 22:25:56 hobbs Exp $
 */

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

/*
 * Minimum required version of Tcl and Tk. These are used when we access
 * Tcl/Tk using the stubs API.
 */

#define MIN_TCL_VERSION "8.4"
#define MIN_TK_VERSION  "8.4"

/*
 * All the Tix commands implemented in C code.
 */

static Tix_TclCmd commands[] = {
    /*
     * Commands that are part of the intrinsics:
     */
    {"tixCallMethod",           Tix_CallMethodCmd},
    {"tixChainMethod",          Tix_ChainMethodCmd},
    {"tixClass",                Tix_ClassCmd},
    {"tixDisplayStyle",         Tix_ItemStyleCmd},
    {"tixDoWhenIdle",           Tix_DoWhenIdleCmd},
    {"tixDoWhenMapped",         Tix_DoWhenMappedCmd},
    {"tixFlushX",           	Tix_FlushXCmd},
    {"tixForm",                 Tix_FormCmd},
    {"tixGeometryRequest",      Tix_GeometryRequestCmd},
    {"tixGet3DBorder",		Tix_Get3DBorderCmd},
    {"tixGetDefault",           Tix_GetDefaultCmd},
    {"tixGetMethod",            Tix_GetMethodCmd},
    {"tixGrid",     		Tix_GridCmd},
    {"tixHandleOptions",        Tix_HandleOptionsCmd},
    {"tixHList",                Tix_HListCmd},
#if !defined(__WIN32__) && !defined(MAC_OSX_TK)
    {"tixInputOnly",		Tix_InputOnlyCmd},
#endif
    {"tixManageGeometry",       Tix_ManageGeometryCmd},
    {"tixMapWindow",            Tix_MapWindowCmd},
    {"tixMoveResizeWindow",     Tix_MoveResizeWindowCmd},
#if !defined(__WIN32__) && !defined(MAC_OSX_TK)
    {"tixMwm",     		Tix_MwmCmd},
#endif
    {"tixNoteBookFrame",        Tix_NoteBookFrameCmd},
    {"tixTList",     		Tix_TListCmd},
    {"tixTmpLine",              Tix_TmpLineCmd},
    {"tixUnmapWindow",          Tix_UnmapWindowCmd},
    {"tixWidgetClass",          Tix_ClassCmd},
    {"tixWidgetDoWhenIdle",     Tix_DoWhenIdleCmd},

    {(char *) NULL,		(Tix_CmdProc)NULL}
};

typedef struct {
    char      * binding;
    int		isDebug;
    char      * fontSet;
    char      * scheme;
    char      * schemePriority;
} OptionStruct;

static OptionStruct tixOption;

/*
 * TIX_DEF_FONTSET and TIX_DEF_SCHEME should have been defined in the
 * Makefile by the configure script. We define them here just in case
 * the configure script failed to determine the proper values.
 */

#ifndef TIX_DEF_FONTSET
#define TIX_DEF_FONTSET "WmDefault"
#endif

#ifndef TIX_DEF_SCHEME
#define TIX_DEF_SCHEME "WmDefault"
#endif

#define DEF_TIX_TOOLKIT_OPTION_BINDING		"TK"
#define DEF_TIX_TOOLKIT_OPTION_DEBUG		"0"
#define DEF_TIX_TOOLKIT_OPTION_FONTSET		TIX_DEF_FONTSET
#define DEF_TIX_TOOLKIT_OPTION_SCHEME		TIX_DEF_SCHEME
#define DEF_TIX_TOOLKIT_OPTION_SCHEME_PRIORITY	"20" /* widgetDefault */

static Tk_ConfigSpec configSpecs[] = {
    {TK_CONFIG_STRING, "-binding", "binding", "TixBinding",
       DEF_TIX_TOOLKIT_OPTION_BINDING, Tk_Offset(OptionStruct, binding),
       0},
    {TK_CONFIG_BOOLEAN, "-debug", "tixDebug", "TixDebug",
       DEF_TIX_TOOLKIT_OPTION_DEBUG, Tk_Offset(OptionStruct, isDebug),
       0},
    {TK_CONFIG_STRING, "-fontset", "tixFontSet", "TixFontSet",
       DEF_TIX_TOOLKIT_OPTION_FONTSET, Tk_Offset(OptionStruct, fontSet),
       0},
    {TK_CONFIG_STRING, "-scheme", "tixScheme", "TixScheme",
       DEF_TIX_TOOLKIT_OPTION_SCHEME, Tk_Offset(OptionStruct, scheme),
       0},
    {TK_CONFIG_STRING, "-schemepriority", "tixSchemePriority", "TixSchemePriority",
       DEF_TIX_TOOLKIT_OPTION_SCHEME_PRIORITY,
       Tk_Offset(OptionStruct, schemePriority),
       0},
    {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
       (char *) NULL, 0, 0}
};

/*----------------------------------------------------------------------
 *
 * 			Some global variables
 *
 *----------------------------------------------------------------------
 */
Tk_Uid tixNormalUid   = (Tk_Uid)NULL;
Tk_Uid tixCellUid     = (Tk_Uid)NULL;
Tk_Uid tixRowUid      = (Tk_Uid)NULL;
Tk_Uid tixColumnUid   = (Tk_Uid)NULL;
Tk_Uid tixDisabledUid = (Tk_Uid)NULL;

static int		ParseToolkitOptions _ANSI_ARGS_((Tcl_Interp * interp));

/*
 *----------------------------------------------------------------------
 * ParseToolkitOptions() --
 *
 *	Before the Tix initialized, we need to determine the toolkit
 *	options which are set by the options database.
 *
 * Results:
 *	A standard Tcl completion code (TCL_OK or TCL_ERROR).  Also
 *	leaves information in the interp's result.
 *
 * Side effects:
 *      Sets several variables in the global Tcl array "tixPriv".
 *
 *----------------------------------------------------------------------
 */

static int
ParseToolkitOptions(interp)
    Tcl_Interp * interp;
{
    char buff[10];
    int flag;

    tixOption.binding = NULL;
    tixOption.isDebug = 0;
    tixOption.fontSet = NULL;
    tixOption.scheme = NULL;
    tixOption.schemePriority = NULL;

    /*
     * The toolkit options may be set in the resources of the main
     * window, probably by using your .Xdefaults file.
     */

    if (Tk_ConfigureWidget(interp, Tk_MainWindow(interp), configSpecs,
	    0, 0, (char *) &tixOption, 0) != TCL_OK) {
	return TCL_ERROR;
    }

    /*
     * Now lets set the Tix toolkit variables so that the Toolkit can
     * initialize according to user options.
     */

    flag = TCL_GLOBAL_ONLY;

    Tcl_SetVar2(interp, "tix_priv", "-binding",
	tixOption.binding,    		flag);
    sprintf(buff, "%d", tixOption.isDebug);
    Tcl_SetVar2(interp, "tix_priv", "-debug", 
	buff,    		flag);
    Tcl_SetVar2(interp, "tix_priv", "-fontset", 
	tixOption.fontSet,    		flag);
    Tcl_SetVar2(interp, "tix_priv", "-scheme",  
	tixOption.scheme,     		flag);
    Tcl_SetVar2(interp, "tix_priv", "-schemepriority",
	tixOption.schemePriority,     flag);

    Tk_FreeOptions(configSpecs, (char *)&tixOption,
	Tk_Display(Tk_MainWindow(interp)), 0);

    return TCL_OK;
}


/*
 *------------------------------------------------------------------------
 * Package initialization.
 * tcl_findLibrary basename version patch initScript enVarName varName
 * We use patchLevel instead of version as we use the full patchlevel
 * in the directory naming on install.
 *------------------------------------------------------------------------
 */

static char initScript[] = "if {[info proc tixInit]==\"\"} {\n\
  proc tixInit {} {\n\
    global tix_library tix_version tix_patchLevel\n\
    rename tixInit {}\n\
    tcl_findLibrary Tix $tix_version $tix_patchLevel Init.tcl TIX_LIBRARY tix_library\n\
  }\n\
}\n\
tixInit";


/*
 *----------------------------------------------------------------------
 *
 * Tix_Init() --
 *
 *	Initialize the Tix library.
 *
 * Results:
 *	A standard Tcl completion code (TCL_OK or TCL_ERROR).  Also
 *	leaves information in the interp's result.
 *
 * Side effects:
 *	Sets "tix_library" Tcl variable, runs "Init.tcl" script from
 *      the Tix script library directory.
 * 
 *----------------------------------------------------------------------
 */

int
Tix_Init(interp)
	 Tcl_Interp * interp;
{
    Tk_Window topLevel;

    /*
     * This procedure may be called  several times for several
     * interpreters. Since some global variables are shared by
     * all of the interpreters, we initialize these variables only
     * once. The variable "globalInitialized" keeps track of this
     */
    static int globalInitialized = 0;

#ifdef USE_TCL_STUBS
    if ((Tcl_InitStubs(interp, MIN_TK_VERSION, 0) == NULL)
	    || (Tk_InitStubs(interp, MIN_TK_VERSION, 0) == NULL)) {
        return TCL_ERROR;
    }
#else
    if ((Tcl_PkgRequire(interp, "Tcl", TCL_VERSION, 1) == NULL)
	    || (Tcl_PkgRequire(interp, "Tk", TK_VERSION, 1) == NULL)) {
	return TCL_ERROR;
    }
#endif /* USE_TCL_STUBS */

    if (Tcl_PkgProvide(interp, "Tix", TIX_PATCH_LEVEL) != TCL_OK) {
        return TCL_ERROR;
    }

    if (!globalInitialized) {
	globalInitialized = 1;

	/*
	 * Initialize the global variables shared by all interpreters
	 */
	tixNormalUid   = Tk_GetUid("normal");
	tixCellUid     = Tk_GetUid("cell");
	tixRowUid      = Tk_GetUid("row");
	tixColumnUid   = Tk_GetUid("column");
	tixDisabledUid = Tk_GetUid("disabled");

#if !defined(__WIN32__) && !defined(MAC_OSX_TK)
	/* This is for tixMwm command */
	Tk_CreateGenericHandler(TixMwmProtocolHandler, NULL);
#endif

	/*
         * Initialize the image readers
         */

	Tk_CreateImageType(&tixPixmapImageType);
	Tk_CreateImageType(&tixCompoundImageType);

	/*
         * Initialize the display item subsystem.
         */

        TixInitializeDisplayItems();
    }

    /*
     * Initialize the per-interpreter variables
     */

    /*  Set the "tix_version" variable */
    Tcl_SetVar(interp, "tix_version",    TIX_VERSION,    TCL_GLOBAL_ONLY);
    Tcl_SetVar(interp, "tix_patchLevel", TIX_PATCH_LEVEL,TCL_GLOBAL_ONLY);
    Tcl_SetVar(interp, "tix_release",    TIX_RELEASE,    TCL_GLOBAL_ONLY);

    /*
     * Initialize the Tix commands
     */

    topLevel = Tk_MainWindow(interp);
    Tix_CreateCommands(interp, commands, (ClientData) topLevel,
	    (void (*)_ANSI_ARGS_((ClientData))) NULL);

    /*
     * Parse options database for fontSets, schemes, etc
     */

    if (ParseToolkitOptions(interp) == TCL_ERROR) {
	return TCL_ERROR;
    }

    /*
     * In normal operation mode, we use the command defined in
     * tixInitScript to load the Tix library scripts off the file
     * system
     */

    return Tcl_EvalEx(interp, initScript, -1, TCL_GLOBAL_ONLY);
}

/*----------------------------------------------------------------------
 * Tix_SafeInit --
 *
 * 	Initializes Tix for a safe interpreter.
 *
 *      TODO: the week security check in Tix is probably not complete
 *      and may lead to security holes. This function is temporarily
 *      disabled.
 *
 * Results:
 *	A standard Tcl completion code (TCL_OK or TCL_ERROR).  Also
 *	leaves information in the interp's result.
 *
 * Side effects:
 *	Sets "tix_library" Tcl variable, runs "Init.tcl" script from
 *      the Tix script library directory.
 * 
 *----------------------------------------------------------------------
 */

int
Tix_SafeInit(interp)
    Tcl_Interp * interp;
{
#if 0
    Tcl_SetVar2(interp, "tix_priv", "isSafe", "1", TCL_GLOBAL_ONLY);
    return Tix_Init(interp);
#else
    Tcl_AppendResult(interp, "Tix has not been tested for use in a safe ",
            "interppreter. Modify tixInit.c at your own risks", NULL);
    return TCL_ERROR;
#endif
}