/Modules/tkappinit.c

http://unladen-swallow.googlecode.com/ · C · 149 lines · 103 code · 24 blank · 22 comment · 17 complexity · 46fcc6e614e6c0f671fe9aa68256ca89 MD5 · raw file

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