PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/tcl/mactkinit.c

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