PageRenderTime 34ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Lib/tcl/mactkinit.c

#
C | 233 lines | 104 code | 37 blank | 92 comment | 16 complexity | 8573d3c0821ed7c4819f16156d5c3ec3 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* -----------------------------------------------------------------------------
  2. * mactkinit.c
  3. *
  4. * This is a support file needed to build a new version of Wish.
  5. * Normally, this capability is found in TkAppInit.c, but this creates
  6. * tons of namespace problems for many applications.
  7. * ----------------------------------------------------------------------------- */
  8. #include <Gestalt.h>
  9. #include <ToolUtils.h>
  10. #include <Fonts.h>
  11. #include <Dialogs.h>
  12. #include <SegLoad.h>
  13. #include <Traps.h>
  14. #include "tk.h"
  15. #include "tkInt.h"
  16. #include "tkMacInt.h"
  17. typedef int (*TclMacConvertEventPtr) _ANSI_ARGS_((EventRecord *eventPtr));
  18. Tcl_Interp *gStdoutInterp = NULL;
  19. void TclMacSetEventProc _ANSI_ARGS_((TclMacConvertEventPtr procPtr));
  20. int TkMacConvertEvent _ANSI_ARGS_((EventRecord *eventPtr));
  21. /*
  22. * Prototypes for functions the ANSI library needs to link against.
  23. */
  24. short InstallConsole _ANSI_ARGS_((short fd));
  25. void RemoveConsole _ANSI_ARGS_((void));
  26. long WriteCharsToConsole _ANSI_ARGS_((char *buff, long n));
  27. long ReadCharsFromConsole _ANSI_ARGS_((char *buff, long n));
  28. char * __ttyname _ANSI_ARGS_((long fildes));
  29. short SIOUXHandleOneEvent _ANSI_ARGS_((EventRecord *event));
  30. /*
  31. * Forward declarations for procedures defined later in this file:
  32. */
  33. /*
  34. *----------------------------------------------------------------------
  35. *
  36. * MacintoshInit --
  37. *
  38. * This procedure calls Mac specific initilization calls. Most of
  39. * these calls must be made as soon as possible in the startup
  40. * process.
  41. *
  42. * Results:
  43. * Returns TCL_OK if everything went fine. If it didn't the
  44. * application should probably fail.
  45. *
  46. * Side effects:
  47. * Inits the application.
  48. *
  49. *----------------------------------------------------------------------
  50. */
  51. int
  52. MacintoshInit()
  53. {
  54. int i;
  55. long result, mask = 0x0700; /* mask = system 7.x */
  56. /*
  57. * Tk needs us to set the qd pointer it uses. This is needed
  58. * so Tk doesn't have to assume the availablity of the qd global
  59. * variable. Which in turn allows Tk to be used in code resources.
  60. */
  61. tcl_macQdPtr = &qd;
  62. InitGraf(&tcl_macQdPtr->thePort);
  63. InitFonts();
  64. InitWindows();
  65. InitMenus();
  66. InitDialogs((long) NULL);
  67. InitCursor();
  68. /*
  69. * Make sure we are running on system 7 or higher
  70. */
  71. if ((NGetTrapAddress(_Gestalt, ToolTrap) ==
  72. NGetTrapAddress(_Unimplemented, ToolTrap))
  73. || (((Gestalt(gestaltSystemVersion, &result) != noErr)
  74. || (mask != (result & mask))))) {
  75. panic("Tcl/Tk requires System 7 or higher.");
  76. }
  77. /*
  78. * Make sure we have color quick draw
  79. * (this means we can't run on 68000 macs)
  80. */
  81. if (((Gestalt(gestaltQuickdrawVersion, &result) != noErr)
  82. || (result < gestalt32BitQD13))) {
  83. panic("Tk requires Color QuickDraw.");
  84. }
  85. FlushEvents(everyEvent, 0);
  86. SetEventMask(everyEvent);
  87. /*
  88. * Set up stack & heap sizes
  89. */
  90. /* TODO: stack size
  91. size = StackSpace();
  92. SetAppLimit(GetAppLimit() - 8192);
  93. */
  94. MaxApplZone();
  95. for (i = 0; i < 4; i++) {
  96. (void) MoreMasters();
  97. }
  98. TclMacSetEventProc(TkMacConvertEvent);
  99. TkConsoleCreate();
  100. return TCL_OK;
  101. }
  102. /*
  103. *----------------------------------------------------------------------
  104. *
  105. * SetupMainInterp --
  106. *
  107. * This procedure calls initalization routines require a Tcl
  108. * interp as an argument. This call effectively makes the passed
  109. * iterpreter the "main" interpreter for the application.
  110. *
  111. * Results:
  112. * Returns TCL_OK if everything went fine. If it didn't the
  113. * application should probably fail.
  114. *
  115. * Side effects:
  116. * More initilization.
  117. *
  118. *----------------------------------------------------------------------
  119. */
  120. int
  121. SetupMainInterp(
  122. Tcl_Interp *interp)
  123. {
  124. /*
  125. * Initialize the console only if we are running as an interactive
  126. * application.
  127. */
  128. TkMacInitAppleEvents(interp);
  129. TkMacInitMenus(interp);
  130. if (strcmp(Tcl_GetVar(interp, "tcl_interactive", TCL_GLOBAL_ONLY), "1")
  131. == 0) {
  132. if (TkConsoleInit(interp) == TCL_ERROR) {
  133. goto error;
  134. }
  135. }
  136. /*
  137. * Attach the global interpreter to tk's expected global console
  138. */
  139. gStdoutInterp = interp;
  140. return TCL_OK;
  141. error:
  142. panic(interp->result);
  143. return TCL_ERROR;
  144. }
  145. /*
  146. *----------------------------------------------------------------------
  147. *
  148. * InstallConsole, RemoveConsole, etc. --
  149. *
  150. * The following functions provide the UI for the console package.
  151. * Users wishing to replace SIOUX with their own console package
  152. * need only provide the four functions below in a library.
  153. *
  154. * Results:
  155. * See SIOUX documentation for details.
  156. *
  157. * Side effects:
  158. * See SIOUX documentation for details.
  159. *
  160. *----------------------------------------------------------------------
  161. */
  162. short
  163. InstallConsole(short fd)
  164. {
  165. #pragma unused (fd)
  166. return 0;
  167. }
  168. void
  169. RemoveConsole(void)
  170. {
  171. }
  172. long
  173. WriteCharsToConsole(char *buffer, long n)
  174. {
  175. TkConsolePrint(gStdoutInterp, TCL_STDOUT, buffer, n);
  176. return n;
  177. }
  178. long
  179. ReadCharsFromConsole(char *buffer, long n)
  180. {
  181. return 0;
  182. }
  183. extern char *
  184. __ttyname(long fildes)
  185. {
  186. static char *devicename = "null device";
  187. if (fildes >= 0 && fildes <= 2) {
  188. return (devicename);
  189. }
  190. return (0L);
  191. }
  192. short
  193. SIOUXHandleOneEvent(EventRecord *event)
  194. {
  195. return 0;
  196. }