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