You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

179 lines
5.1 KiB

32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
32 years ago
29 years ago
32 years ago
32 years ago
32 years ago
  1. /* appinit.c -- Tcl and Tk application initialization.
  2. The function Tcl_AppInit() below initializes various Tcl packages.
  3. It is called for each Tcl interpreter created by _tkinter.create().
  4. It needs to be compiled with -DWITH_<package> flags for each package
  5. that you are statically linking with. You may have to add sections
  6. for packages not yet listed below.
  7. Note that those packages for which Tcl_StaticPackage() is called with
  8. a NULL first argument are known as "static loadable" packages to
  9. Tcl but not actually initialized. To use these, you have to load
  10. it explicitly, e.g. tkapp.eval("load {} Blt").
  11. */
  12. #include <string.h>
  13. #include <tcl.h>
  14. #include <tk.h>
  15. #include "tkinter.h"
  16. #ifdef TKINTER_PROTECT_LOADTK
  17. /* See Tkapp_TkInit in _tkinter.c for the usage of tk_load_faile */
  18. static int tk_load_failed;
  19. #endif
  20. int
  21. Tcl_AppInit(Tcl_Interp *interp)
  22. {
  23. Tk_Window main_window;
  24. const char *_tkinter_skip_tk_init;
  25. #ifdef TKINTER_PROTECT_LOADTK
  26. const char *_tkinter_tk_failed;
  27. #endif
  28. #ifdef TK_AQUA
  29. #ifndef MAX_PATH_LEN
  30. #define MAX_PATH_LEN 1024
  31. #endif
  32. char tclLibPath[MAX_PATH_LEN], tkLibPath[MAX_PATH_LEN];
  33. Tcl_Obj* pathPtr;
  34. /* pre- Tcl_Init code copied from tkMacOSXAppInit.c */
  35. Tk_MacOSXOpenBundleResources (interp, "com.tcltk.tcllibrary",
  36. tclLibPath, MAX_PATH_LEN, 0);
  37. if (tclLibPath[0] != '\0') {
  38. Tcl_SetVar(interp, "tcl_library", tclLibPath, TCL_GLOBAL_ONLY);
  39. Tcl_SetVar(interp, "tclDefaultLibrary", tclLibPath, TCL_GLOBAL_ONLY);
  40. Tcl_SetVar(interp, "tcl_pkgPath", tclLibPath, TCL_GLOBAL_ONLY);
  41. }
  42. if (tclLibPath[0] != '\0') {
  43. Tcl_SetVar(interp, "tcl_library", tclLibPath, TCL_GLOBAL_ONLY);
  44. Tcl_SetVar(interp, "tclDefaultLibrary", tclLibPath, TCL_GLOBAL_ONLY);
  45. Tcl_SetVar(interp, "tcl_pkgPath", tclLibPath, TCL_GLOBAL_ONLY);
  46. }
  47. #endif
  48. if (Tcl_Init (interp) == TCL_ERROR)
  49. return TCL_ERROR;
  50. #ifdef TK_AQUA
  51. /* pre- Tk_Init code copied from tkMacOSXAppInit.c */
  52. Tk_MacOSXOpenBundleResources (interp, "com.tcltk.tklibrary",
  53. tkLibPath, MAX_PATH_LEN, 1);
  54. if (tclLibPath[0] != '\0') {
  55. pathPtr = Tcl_NewStringObj(tclLibPath, -1);
  56. } else {
  57. Tcl_Obj *pathPtr = TclGetLibraryPath();
  58. }
  59. if (tkLibPath[0] != '\0') {
  60. Tcl_Obj *objPtr;
  61. Tcl_SetVar(interp, "tk_library", tkLibPath, TCL_GLOBAL_ONLY);
  62. objPtr = Tcl_NewStringObj(tkLibPath, -1);
  63. Tcl_ListObjAppendElement(NULL, pathPtr, objPtr);
  64. }
  65. TclSetLibraryPath(pathPtr);
  66. #endif
  67. #ifdef WITH_XXX
  68. /* Initialize modules that don't require Tk */
  69. #endif
  70. _tkinter_skip_tk_init = Tcl_GetVar(interp,
  71. "_tkinter_skip_tk_init", TCL_GLOBAL_ONLY);
  72. if (_tkinter_skip_tk_init != NULL &&
  73. strcmp(_tkinter_skip_tk_init, "1") == 0) {
  74. return TCL_OK;
  75. }
  76. #ifdef TKINTER_PROTECT_LOADTK
  77. _tkinter_tk_failed = Tcl_GetVar(interp,
  78. "_tkinter_tk_failed", TCL_GLOBAL_ONLY);
  79. if (tk_load_failed || (
  80. _tkinter_tk_failed != NULL &&
  81. strcmp(_tkinter_tk_failed, "1") == 0)) {
  82. Tcl_SetResult(interp, TKINTER_LOADTK_ERRMSG, TCL_STATIC);
  83. return TCL_ERROR;
  84. }
  85. #endif
  86. if (Tk_Init(interp) == TCL_ERROR) {
  87. #ifdef TKINTER_PROTECT_LOADTK
  88. tk_load_failed = 1;
  89. Tcl_SetVar(interp, "_tkinter_tk_failed", "1", TCL_GLOBAL_ONLY);
  90. #endif
  91. return TCL_ERROR;
  92. }
  93. main_window = Tk_MainWindow(interp);
  94. #ifdef TK_AQUA
  95. TkMacOSXInitAppleEvents(interp);
  96. TkMacOSXInitMenus(interp);
  97. #endif
  98. #ifdef WITH_MOREBUTTONS
  99. {
  100. extern Tcl_CmdProc studButtonCmd;
  101. extern Tcl_CmdProc triButtonCmd;
  102. Tcl_CreateCommand(interp, "studbutton", studButtonCmd,
  103. (ClientData) main_window, NULL);
  104. Tcl_CreateCommand(interp, "tributton", triButtonCmd,
  105. (ClientData) main_window, NULL);
  106. }
  107. #endif
  108. #ifdef WITH_PIL /* 0.2b5 and later -- not yet released as of May 14 */
  109. {
  110. extern void TkImaging_Init(Tcl_Interp *);
  111. TkImaging_Init(interp);
  112. /* XXX TkImaging_Init() doesn't have the right return type */
  113. /*Tcl_StaticPackage(interp, "Imaging", TkImaging_Init, NULL);*/
  114. }
  115. #endif
  116. #ifdef WITH_PIL_OLD /* 0.2b4 and earlier */
  117. {
  118. extern void TkImaging_Init(void);
  119. /* XXX TkImaging_Init() doesn't have the right prototype */
  120. /*Tcl_StaticPackage(interp, "Imaging", TkImaging_Init, NULL);*/
  121. }
  122. #endif
  123. #ifdef WITH_TIX
  124. {
  125. extern int Tix_Init(Tcl_Interp *interp);
  126. extern int Tix_SafeInit(Tcl_Interp *interp);
  127. Tcl_StaticPackage(NULL, "Tix", Tix_Init, Tix_SafeInit);
  128. }
  129. #endif
  130. #ifdef WITH_BLT
  131. {
  132. extern int Blt_Init(Tcl_Interp *);
  133. extern int Blt_SafeInit(Tcl_Interp *);
  134. Tcl_StaticPackage(NULL, "Blt", Blt_Init, Blt_SafeInit);
  135. }
  136. #endif
  137. #ifdef WITH_TOGL
  138. {
  139. /* XXX I've heard rumors that this doesn't work */
  140. extern int Togl_Init(Tcl_Interp *);
  141. /* XXX Is there no Togl_SafeInit? */
  142. Tcl_StaticPackage(NULL, "Togl", Togl_Init, NULL);
  143. }
  144. #endif
  145. #ifdef WITH_XXX
  146. #endif
  147. return TCL_OK;
  148. }