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