Debian Codegraph @

pTk/mTk/tixGeneric/tixInit.c

raw symbols SCIP
1
2 /* $Id: tixInit.c,v 1.4.2.3 2001/11/10 08:12:45 idiscovery Exp $ */
3
4 /*
5 * tixInit.c --
6 *
7 * Initialze the internals of Tix.
8 *
9 * Copyright (c) 1996, Expert Interface Technologies
10 *
11 * See the file "license.terms" for information on usage and redistribution
12 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13 *
14 */
15
16 #include "tixPort.h"
17 #include "tixInt.h"
18
19 #ifdef ITCL_2
20 #include <itcl.h>
21 #endif
22
23 #ifdef _WINDOWS
24 #include <tkWinInt.h>
25 #endif
26
27 static Tix_TclCmd commands[] = {
28 /*
29 * Commands that are part of the intrinsics:
30 */
31 {"tixCallMethod", Tix_CallMethodCmd},
32 {"tixChainMethod", Tix_ChainMethodCmd},
33 {"tixClass", Tix_ClassCmd},
34 {"tixDisplayStyle", Tix_ItemStyleCmd},
35 {"tixDoWhenIdle", Tix_DoWhenIdleCmd},
36 {"tixDoWhenMapped", Tix_DoWhenMappedCmd},
37 {"tixFalse", Tix_FalseCmd},
38 {"tixFile", Tix_FileCmd},
39 {"tixFlushX", Tix_FlushXCmd},
40 {"tixForm", Tix_FormCmd},
41 {"tixHList", Tix_HListCmd},
42 {"tixItemStyle", Tix_ItemStyleCmd}, /* Old name */
43 {"tixGeometryRequest", Tix_GeometryRequestCmd},
44 {"tixGet3DBorder", Tix_Get3DBorderCmd},
45 {"tixGetBoolean", Tix_GetBooleanCmd},
46 {"tixGetInt", Tix_GetIntCmd},
47 {"tixGetMethod", Tix_GetMethodCmd},
48 {"tixHandleOptions", Tix_HandleOptionsCmd},
49 #ifndef _WINDOWS
50 {"tixInputOnly", Tix_InputOnlyCmd},
51 #endif
52 {"tixManageGeometry", Tix_ManageGeometryCmd},
53 {"tixMapWindow", Tix_MapWindowCmd},
54 {"tixMoveResizeWindow", Tix_MoveResizeWindowCmd},
55 #ifndef _WINDOWS
56 {"tixMwm", Tix_MwmCmd},
57 #endif
58 {"tixNoteBookFrame", Tix_NoteBookFrameCmd},
59 {"tixRaiseWindow", Tix_RaiseWindowCmd},
60 {"tixStringSub", Tix_StringSubCmd},
61 {"tixStrEq", Tix_StrEqCmd},
62 {"tixTmpLine", Tix_TmpLineCmd},
63 {"tixTrue", Tix_TrueCmd},
64 {"tixUnmapWindow", Tix_UnmapWindowCmd},
65 {"tixWidgetClass", Tix_ClassCmd},
66 {"tixWidgetDoWhenIdle", Tix_DoWhenIdleCmd},
67
68 #ifndef TIX_VERSION_4_0_x
69 {"tixTList", Tix_TListCmd},
70 {"tixGrid", Tix_GridCmd},
71 #endif
72
73 {(char *) NULL, (Tix_CmdProc)NULL}
74 };
75
76 typedef struct {
77 int isBeta;
78 char * binding;
79 int isDebug;
80 char * fontSet;
81 char * tixlibrary;
82 char * scheme;
83 char * schemePriority;
84 } OptionStruct;
85
86 static OptionStruct tixOption;
87
88 /*
89 * TIX_DEF_FONTSET and TIX_DEF_SCHEME should have been defined in the
90 * Makefile by the configure script. We define them here just in case
91 * the configure script failed to determine the proper values.
92 */
93
94 #ifndef TIX_DEF_FONTSET
95 #define TIX_DEF_FONTSET "WmDefault"
96 #endif
97
98 #ifndef TIX_DEF_SCHEME
99 #define TIX_DEF_SCHEME "WmDefault"
100 #endif
101
102 #define DEF_TIX_TOOLKIT_OPTION_BETA "0"
103 #define DEF_TIX_TOOLKIT_OPTION_BINDING "TK"
104 #define DEF_TIX_TOOLKIT_OPTION_DEBUG "0"
105 #define DEF_TIX_TOOLKIT_OPTION_FONTSET TIX_DEF_FONTSET
106 #define DEF_TIX_TOOLKIT_OPTION_LIBRARY ""
107 #define DEF_TIX_TOOLKIT_OPTION_SCHEME TIX_DEF_SCHEME
108 #define DEF_TIX_TOOLKIT_OPTION_SCHEME_PRIORITY "75"
109
110 static Tk_ConfigSpec configSpecs[] = {
111 {TK_CONFIG_BOOLEAN, "-beta", "tixBeta", "TixBeta",
112 DEF_TIX_TOOLKIT_OPTION_BETA, Tk_Offset(OptionStruct, isBeta),
113 0},
114 {TK_CONFIG_STRING, "-binding", "binding", "TixBinding",
115 DEF_TIX_TOOLKIT_OPTION_BINDING, Tk_Offset(OptionStruct, binding),
116 0},
117 {TK_CONFIG_BOOLEAN, "-debug", "tixDebug", "TixDebug",
118 DEF_TIX_TOOLKIT_OPTION_DEBUG, Tk_Offset(OptionStruct, isDebug),
119 0},
120 {TK_CONFIG_STRING, "-fontset", "tixFontSet", "TixFontSet",
121 DEF_TIX_TOOLKIT_OPTION_FONTSET, Tk_Offset(OptionStruct, fontSet),
122 0},
123 {TK_CONFIG_STRING, "-scheme", "tixScheme", "TixScheme",
124 DEF_TIX_TOOLKIT_OPTION_SCHEME, Tk_Offset(OptionStruct, scheme),
125 0},
126 {TK_CONFIG_STRING, "-schemepriority", "tixSchemePriority", "TixSchemePriority",
127 DEF_TIX_TOOLKIT_OPTION_SCHEME_PRIORITY,
128 Tk_Offset(OptionStruct, schemePriority),
129 0},
130 {TK_CONFIG_STRING, "-tixlibrary", "tixLibrary", "TixLibrary",
131 DEF_TIX_TOOLKIT_OPTION_LIBRARY, Tk_Offset(OptionStruct, tixlibrary),
132 TK_CONFIG_NULL_OK},
133 {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
134 (char *) NULL, 0, 0}
135 };
136
137 #ifndef TIX_LIBRARY
138 #define TIX_LIBRARY "../../library"
139 #endif
140
141 /*----------------------------------------------------------------------
142 *
143 * Some global variables
144 *
145 *----------------------------------------------------------------------
146 */
147 Tk_Uid tixNormalUid = (Tk_Uid)NULL;
148 Tk_Uid tixCellUid = (Tk_Uid)NULL;
149 Tk_Uid tixRowUid = (Tk_Uid)NULL;
150 Tk_Uid tixColumnUid = (Tk_Uid)NULL;
151 Tk_Uid tixDisabledUid = (Tk_Uid)NULL;
152
153 /*----------------------------------------------------------------------
154 *
155 * The Display Item types
156 *
157 *----------------------------------------------------------------------
158 */
159
160 extern Tix_DItemInfo tix_ImageTextItemType;
161 extern Tix_DItemInfo tix_TextItemType;
162 extern Tix_DItemInfo tix_WindowItemType;
163 extern Tix_DItemInfo tix_ImageItemType;
164
165 static int ParseToolkitOptions _ANSI_ARGS_((Tcl_Interp * interp));
166 extern int TixMwmProtocolHandler _ANSI_ARGS_((
167 ClientData clientData, XEvent *eventPtr));
168 static int Tix_Init_Internal _ANSI_ARGS_((Tcl_Interp * interp,
169 int doSource));
170 int Tix_EtInit _ANSI_ARGS_((Tcl_Interp * interp));
171
172 /*----------------------------------------------------------------------
173 * ParseToolkitOptions() --
174 *
175 * Before the Tix initialized, we need to determine the toolkit
176 * options which are set by the options database.
177 *----------------------------------------------------------------------
178 */
179 static int
180 ParseToolkitOptions(interp)
181 Tcl_Interp * interp;
182 {
183 char buff[10];
184 int flag;
185
186 tixOption.isBeta = 0;
187 tixOption.binding = NULL;
188 tixOption.isDebug = 0;
189 tixOption.fontSet = NULL;
190 tixOption.tixlibrary = NULL;
191 tixOption.scheme = NULL;
192 tixOption.schemePriority = NULL;
193
194 /*
195 * The toolkit options may be set in the resources of the main window
196 */
197 if (Tk_ConfigureWidget(interp, Tk_MainWindow(interp), configSpecs,
198 0, 0, (char *) &tixOption, 0) != TCL_OK) {
199 return TCL_ERROR;
200 }
201
202 /*
203 * Now lets set the Tix toolkit variables so that the Toolkit can
204 * initialize according to user options.
205 */
206 flag = TCL_GLOBAL_ONLY;
207 sprintf(buff, "%d", tixOption.isBeta);
208 Tcl_SetVar2(interp, "tix_priv", "-beta", buff, flag);
209 sprintf(buff, "%d", tixOption.isDebug);
210 Tcl_SetVar2(interp, "tix_priv", "-debug", buff, flag);
211
212 if (tixOption.tixlibrary == 0 || strlen(tixOption.tixlibrary) == 0) {
213 /*
214 * Set up the TCL variable "tix_library" according to the environment
215 * variable.
216 */
217 if (tixOption.tixlibrary != NULL) {
218 ckfree((char*)tixOption.tixlibrary);
219 }
220
221 tixOption.tixlibrary = (char*)getenv("TIX_LIBRARY");
222 if (tixOption.tixlibrary == NULL) {
223 tixOption.tixlibrary = TIX_LIBRARY;
224 }
225 Tcl_SetVar2(interp, "tix_priv", "-libdir",
226 tixOption.tixlibrary, flag);
227 } else {
228 Tcl_SetVar2(interp, "tix_priv", "-libdir",
229 tixOption.tixlibrary, flag);
230 ckfree((char*)tixOption.tixlibrary);
231 }
232
233 /*
234 * tixOption.tixlibrary may not be allocated by Tk_ConfigureWidget().
235 * We have already freed it (if necessary). We set it to NULL so
236 * that Tk_FreeOptions() won't try to free it.
237 */
238 tixOption.tixlibrary = NULL;
239
240 Tcl_SetVar2(interp, "tix_priv", "-binding",
241 tixOption.binding, flag);
242 Tcl_SetVar2(interp, "tix_priv", "-fontset",
243 tixOption.fontSet, flag);
244 Tcl_SetVar2(interp, "tix_priv", "-scheme",
245 tixOption.scheme, flag);
246 Tcl_SetVar2(interp, "tix_priv", "-schemepriority",
247 tixOption.schemePriority, flag);
248
249 Tk_FreeOptions(configSpecs, (char *)&tixOption,
250 Tk_Display(Tk_MainWindow(interp)), 0);
251
252 return TCL_OK;
253 }
254
255 /*----------------------------------------------------------------------
256 * Tix_Init_Internal() --
257 *
258 * Initialize the Tix library. The doSource argument specifies
259 * we should source the file Init.tcl from the Tix script library
260 * path. A doSource is not necessary if Tix was included in an ET
261 * applicattion.
262 *----------------------------------------------------------------------
263 */
264
265 static int
266 Tix_Init_Internal(interp, doSource)
267 Tcl_Interp * interp;
268 int doSource;
269 {
270 Tk_Window topLevel;
271 char * appName;
272 static int globalInitialized = 0;
273
274 /*
275 * This procedure may be called several times for several
276 * interpreters. Since some global variables are shared by
277 * all of the interpreters, we initialize these variables only
278 * once. The variable "globalInitialized" keeps track of this
279 */
280
281 extern Tk_ImageType tixPixmapImageType;
282 extern Tk_ImageType tixCompoundImageType;
283
284 #ifdef USE_TCL_STUBS
285 if(Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL)
286 return TCL_ERROR;
287 if(Tk_InitStubs(interp, TCL_VERSION, 0) == NULL)
288 return TCL_ERROR;
289 #endif
290
291 #ifdef TCL_7_5_OR_LATER
292 /*
293 * The new package mechanism, available in Tcl7.5 or later
294 */
295 if (Tcl_PkgRequire(interp, "Tcl", TCL_VERSION, 1) == NULL) {
296 return TCL_ERROR;
297 }
298 if (Tcl_PkgRequire(interp, "Tk", TK_VERSION, 1) == NULL) {
299 return TCL_ERROR;
300 }
301 #ifdef ITCL_2
302 if (Tcl_PkgRequire(interp, "Itcl", ITCL_VERSION, 0) == NULL) {
303 return TCL_ERROR;
304 }
305 if (Tcl_PkgRequire(interp, "Itk", ITCL_VERSION, 0) == NULL) {
306 return TCL_ERROR;
307 }
308 #endif
309 /*
310 * // This is now done in Init.tcl
311 * if (Tcl_PkgProvide(interp, "Tix", TIX_VERSION) != TCL_OK) {
312 * return TCL_ERROR;
313 * }
314 */
315 #endif
316
317 topLevel = Tk_MainWindow(interp);
318
319 if (!globalInitialized) {
320 globalInitialized = 1;
321
322 /*
323 * Initialize the global variables shared by all interpreters
324 */
325 tixNormalUid = Tk_GetUid("normal");
326 tixCellUid = Tk_GetUid("cell");
327 tixRowUid = Tk_GetUid("row");
328 tixColumnUid = Tk_GetUid("column");
329 tixDisabledUid = Tk_GetUid("disabled");
330
331 #ifndef _WINDOWS
332 /* This is for tixMwm command */
333 Tk_CreateGenericHandler(TixMwmProtocolHandler, NULL);
334 #endif
335
336 /* Initialize the image readers */
337 Tk_CreateImageType(&tixPixmapImageType);
338 Tk_CreateImageType(&tixCompoundImageType);
339
340 /* Initialize the display item types */
341 Tix_AddDItemType(&tix_ImageTextItemType);
342 Tix_AddDItemType(&tix_TextItemType);
343 Tix_AddDItemType(&tix_WindowItemType);
344 Tix_AddDItemType(&tix_ImageItemType);
345
346 /*
347 * Initializes all the Tix built-in bitmaps.
348 */
349 #define Et_Interp interp
350 #include "tixBitmaps.h"
351
352 }
353 else {
354 /*
355 * This variable is used in the __tixInit procedure.
356 */
357 Tcl_SetVar2(interp, "tix_priv", "slaveInterp", "", TCL_GLOBAL_ONLY);
358 }
359
360 /*
361 * Initialize the per-interpreter variables
362 */
363
364 /* Set the "tix_version" variable */
365 Tcl_SetVar(interp, "tix_version", TIX_VERSION, TCL_GLOBAL_ONLY);
366 Tcl_SetVar(interp, "tix_patchLevel", TIX_PATCHLEVEL, TCL_GLOBAL_ONLY);
367 Tcl_SetVar(interp, "tix_release", TIX_RELEASE, TCL_GLOBAL_ONLY);
368
369 /* Initialize the Tix commands */
370 Tix_CreateCommands(interp, commands, (ClientData) topLevel,
371 (void (*)_ANSI_ARGS_((ClientData))) NULL);
372
373 #ifdef _WINDOWS
374 Tcl_GlobalEval(interp, tixStrDup("set tixPriv(isWindows) 1"));
375 #endif
376
377 /* Parse options database for fontSets, schemes, etc */
378 if (ParseToolkitOptions(interp) == TCL_ERROR) {
379 return TCL_ERROR;
380 }
381
382 if ((appName = Tcl_GetVar(interp, "argv0", TCL_GLOBAL_ONLY))== NULL) {
383 appName = "tixwish";
384 }
385
386 if (doSource) {
387
388 if (TixLoadLibrary(interp) != TCL_OK) {
389 return TCL_ERROR;
390 }
391
392 if (Tcl_GlobalEval(interp, tixStrDup("__tixInit")) != TCL_OK) {
393 return TCL_ERROR;
394 }
395 } else {
396 Tcl_SetVar(interp, "tix_library", "", TCL_GLOBAL_ONLY);
397 }
398
399
400 return TCL_OK;
401 }
402
403 /*----------------------------------------------------------------------
404 * Tix_Init --
405 *
406 * This is the function to call in your Tcl_AppInit() function
407 *
408 *----------------------------------------------------------------------
409 */
410
411 int
412 Tix_Init(interp)
413 Tcl_Interp * interp;
414 {
415 int code = Tix_Init_Internal(interp, 1);
416
417 #ifdef _WINDOWS
418 if (code != TCL_OK) {
419 char * errorInfo;
420
421 errorInfo = Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY);
422 if (errorInfo == NULL) {
423 Tcl_SetVar(interp, "errorInfo", "unknown error", TCL_GLOBAL_ONLY);
424 }
425 Tix_GlobalVarEval(interp,
426 "toplevel .err; ",
427 "bind .err <Destroy> {set err_ok 1}; ",
428 "frame .err.f; pack .err.f -side bottom -fill both; "
429 "button .err.f.i -text Ignore -width 6 -command {set err_ok 1}; ",
430 "button .err.f.e -text Exit -width 6 -command {exit}; ",
431 "pack .err.f.i -side left -padx 4 -pady 4;"
432 "pack .err.f.e -side left -padx 4 -pady 4; "
433 "text .err.text -width 70 -wrap none -height 5; "
434 "pack .err.text -side top -expand yes -fill both; "
435 ".err.text insert end $errorInfo; ",
436 "tkwait variable err_ok; ",
437 "catch {destroy .err}; ",
438 NULL);
439 }
440 #endif
441 return code;
442 }
443
444 /*----------------------------------------------------------------------
445 * TixInitSam --
446 *
447 * This takes special care when you initialize the Tix library
448 * to run in stand-alone mode.
449 *----------------------------------------------------------------------
450 */
451 int TixInitSam(interp)
452 Tcl_Interp * interp;
453 {
454 return Tix_Init_Internal(interp, 0);
455 }
456
457 /*----------------------------------------------------------------------
458 * Tix_SafeInit --
459 *
460 * This is the function to call in your Tcl_AppInit() function
461 *
462 *----------------------------------------------------------------------
463 */
464
465 int
466 Tix_SafeInit(interp)
467 Tcl_Interp * interp;
468 {
469 Tcl_SetVar2(interp, "tix_priv", "isSafe", "1", TCL_GLOBAL_ONLY);
470 return Tix_Init(interp);
471 }
472
473 /*
474 *----------------------------------------------------------------------
475 * TixLoadLibrary --
476 *
477 * Loads the Tix library.
478 *
479 * Results:
480 * Standard Tcl result.
481 *
482 * Side effects:
483 * Tix gets initialized.
484 *----------------------------------------------------------------------
485 */
486
487 static char *initScript =
488 "proc init {} {\n\
489 global tix_library tix_version tix_patchLevel env errorInfo\n\
490 rename init {}\n\
491 set dirs {}\n\
492 set errors {}\n\
493 set lib tix$tix_version\n\
494 set Lib Tix$tix_version\n\
495 # ../ ../../ library - for uninstalled \n\
496 # [pwd] may not work inside safe Tcl\n\
497 set bindir [file dirname [info nameofexe]]\n\
498 set up [file dirname $bindir]\n\
499 lappend dirs [file join $up library]\n\
500 lappend dirs [file join $up $lib]\n\
501 set upup [file dirname $up]\n\
502 lappend dirs [file join $upup library]\n\
503 lappend dirs [file join $upup $lib]\n\
504 # beside lib/tcl8.x - for installed \n\
505 set instDir [file dirname [info library]]\n\
506 lappend dirs [file join $instDir $lib]\n\
507 # env(TIX_LIBRARY) used to take precedence\n\
508 if {[info exists env(TIX_LIBRARY)]} {\n\
509 lappend dirs $env(TIX_LIBRARY)\n\
510 }\n\
511 foreach i $dirs {\n\
512 if {![file isdir $i]} {continue}\n\
513 set tixfile [file join $i Init.tcl]\n\
514 if {![file exists $i]} {continue}\n\
515 set tix_library $i\n\
516 if {![catch {uplevel #0 [list source $tixfile]} err]} {\n\
517 return\n\
518 } else {\n\
519 append errors \"$tixfile: $err\n$errorInfo\n\"\n\
520 }\n\
521 }\n\
522 set msg \"Can't find a usable Tix Init.tcl in the following directories: \n\"\n\
523 append msg \"[join $dirs {\n}]\n\"\n\
524 append msg \"$errors\n\n\"\n\
525 append msg \"This probably means that Tix wasn't installed properly.\n\"\n\
526 error $msg\n\
527 }\n\
528 init";
529
530
531 int
532 TixLoadLibrary(interp)
533 Tcl_Interp * interp;
534 {
535 return Tcl_Eval(interp, tixStrDup(initScript));
536 }