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.

185 lines
5.2 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. #ifdef WITH_MOREBUTTONS
  24. Tk_Window main_window;
  25. #endif
  26. const char *_tkinter_skip_tk_init;
  27. #ifdef TKINTER_PROTECT_LOADTK
  28. const char *_tkinter_tk_failed;
  29. #endif
  30. #ifdef TK_AQUA
  31. #ifndef MAX_PATH_LEN
  32. #define MAX_PATH_LEN 1024
  33. #endif
  34. char tclLibPath[MAX_PATH_LEN], tkLibPath[MAX_PATH_LEN];
  35. Tcl_Obj* pathPtr;
  36. /* pre- Tcl_Init code copied from tkMacOSXAppInit.c */
  37. Tk_MacOSXOpenBundleResources (interp, "com.tcltk.tcllibrary",
  38. tclLibPath, MAX_PATH_LEN, 0);
  39. if (tclLibPath[0] != '\0') {
  40. Tcl_SetVar(interp, "tcl_library", tclLibPath, TCL_GLOBAL_ONLY);
  41. Tcl_SetVar(interp, "tclDefaultLibrary", tclLibPath, TCL_GLOBAL_ONLY);
  42. Tcl_SetVar(interp, "tcl_pkgPath", tclLibPath, TCL_GLOBAL_ONLY);
  43. }
  44. if (tclLibPath[0] != '\0') {
  45. Tcl_SetVar(interp, "tcl_library", tclLibPath, TCL_GLOBAL_ONLY);
  46. Tcl_SetVar(interp, "tclDefaultLibrary", tclLibPath, TCL_GLOBAL_ONLY);
  47. Tcl_SetVar(interp, "tcl_pkgPath", tclLibPath, TCL_GLOBAL_ONLY);
  48. }
  49. #endif
  50. if (Tcl_Init (interp) == TCL_ERROR)
  51. return TCL_ERROR;
  52. #ifdef TK_AQUA
  53. /* pre- Tk_Init code copied from tkMacOSXAppInit.c */
  54. Tk_MacOSXOpenBundleResources (interp, "com.tcltk.tklibrary",
  55. tkLibPath, MAX_PATH_LEN, 1);
  56. if (tclLibPath[0] != '\0') {
  57. pathPtr = Tcl_NewStringObj(tclLibPath, -1);
  58. } else {
  59. Tcl_Obj *pathPtr = TclGetLibraryPath();
  60. }
  61. if (tkLibPath[0] != '\0') {
  62. Tcl_Obj *objPtr;
  63. Tcl_SetVar(interp, "tk_library", tkLibPath, TCL_GLOBAL_ONLY);
  64. objPtr = Tcl_NewStringObj(tkLibPath, -1);
  65. Tcl_ListObjAppendElement(NULL, pathPtr, objPtr);
  66. }
  67. TclSetLibraryPath(pathPtr);
  68. #endif
  69. #ifdef WITH_XXX
  70. /* Initialize modules that don't require Tk */
  71. #endif
  72. _tkinter_skip_tk_init = Tcl_GetVar(interp,
  73. "_tkinter_skip_tk_init", TCL_GLOBAL_ONLY);
  74. if (_tkinter_skip_tk_init != NULL &&
  75. strcmp(_tkinter_skip_tk_init, "1") == 0) {
  76. return TCL_OK;
  77. }
  78. #ifdef TKINTER_PROTECT_LOADTK
  79. _tkinter_tk_failed = Tcl_GetVar(interp,
  80. "_tkinter_tk_failed", TCL_GLOBAL_ONLY);
  81. if (tk_load_failed || (
  82. _tkinter_tk_failed != NULL &&
  83. strcmp(_tkinter_tk_failed, "1") == 0)) {
  84. Tcl_SetResult(interp, TKINTER_LOADTK_ERRMSG, TCL_STATIC);
  85. return TCL_ERROR;
  86. }
  87. #endif
  88. if (Tk_Init(interp) == TCL_ERROR) {
  89. #ifdef TKINTER_PROTECT_LOADTK
  90. tk_load_failed = 1;
  91. Tcl_SetVar(interp, "_tkinter_tk_failed", "1", TCL_GLOBAL_ONLY);
  92. #endif
  93. return TCL_ERROR;
  94. }
  95. #ifdef WITH_MOREBUTTONS
  96. main_window = Tk_MainWindow(interp);
  97. #else
  98. Tk_MainWindow(interp);
  99. #endif
  100. #ifdef TK_AQUA
  101. TkMacOSXInitAppleEvents(interp);
  102. TkMacOSXInitMenus(interp);
  103. #endif
  104. #ifdef WITH_MOREBUTTONS
  105. {
  106. extern Tcl_CmdProc studButtonCmd;
  107. extern Tcl_CmdProc triButtonCmd;
  108. Tcl_CreateCommand(interp, "studbutton", studButtonCmd,
  109. (ClientData) main_window, NULL);
  110. Tcl_CreateCommand(interp, "tributton", triButtonCmd,
  111. (ClientData) main_window, NULL);
  112. }
  113. #endif
  114. #ifdef WITH_PIL /* 0.2b5 and later -- not yet released as of May 14 */
  115. {
  116. extern void TkImaging_Init(Tcl_Interp *);
  117. TkImaging_Init(interp);
  118. /* XXX TkImaging_Init() doesn't have the right return type */
  119. /*Tcl_StaticPackage(interp, "Imaging", TkImaging_Init, NULL);*/
  120. }
  121. #endif
  122. #ifdef WITH_PIL_OLD /* 0.2b4 and earlier */
  123. {
  124. extern void TkImaging_Init(void);
  125. /* XXX TkImaging_Init() doesn't have the right prototype */
  126. /*Tcl_StaticPackage(interp, "Imaging", TkImaging_Init, NULL);*/
  127. }
  128. #endif
  129. #ifdef WITH_TIX
  130. {
  131. extern int Tix_Init(Tcl_Interp *interp);
  132. extern int Tix_SafeInit(Tcl_Interp *interp);
  133. Tcl_StaticPackage(NULL, "Tix", Tix_Init, Tix_SafeInit);
  134. }
  135. #endif
  136. #ifdef WITH_BLT
  137. {
  138. extern int Blt_Init(Tcl_Interp *);
  139. extern int Blt_SafeInit(Tcl_Interp *);
  140. Tcl_StaticPackage(NULL, "Blt", Blt_Init, Blt_SafeInit);
  141. }
  142. #endif
  143. #ifdef WITH_TOGL
  144. {
  145. /* XXX I've heard rumors that this doesn't work */
  146. extern int Togl_Init(Tcl_Interp *);
  147. /* XXX Is there no Togl_SafeInit? */
  148. Tcl_StaticPackage(NULL, "Togl", Togl_Init, NULL);
  149. }
  150. #endif
  151. #ifdef WITH_XXX
  152. #endif
  153. return TCL_OK;
  154. }