]>
git.zerfleddert.de Git - micropolis/blob - src/tk/main.c
4 * A simple program to test the toolkit facilities.
6 * Copyright 1990-1992 Regents of the University of California.
7 * Permission to use, copy, modify, and distribute this
8 * software and its documentation for any purpose and without
9 * fee is hereby granted, provided that the above copyright
10 * notice appear in all copies. The University of California
11 * makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without
13 * express or implied warranty.
17 static char rcsid
[] = "$Header: /user6/ouster/wish/RCS/main.c,v 1.68 92/05/07 08:52:02 ouster Exp $ SPRITE (Berkeley)";
24 * Declarations for library procedures:
30 * Command used to initialize wish:
33 char initCmd
[] = "source $tk_library/wish.tcl";
35 Tk_Window w
; /* NULL means window has been deleted. */
36 Tk_TimerToken timeToken
= 0;
42 extern int Tk_SquareCmd
_ANSI_ARGS_((ClientData clientData
,
43 Tcl_Interp
*interp
, int argc
, char **argv
));
46 * Information for testing out command-line options:
50 char *fileName
= NULL
;
53 char *geometry
= NULL
;
55 Tk_ArgvInfo argTable
[] = {
56 {"-file", TK_ARGV_STRING
, (char *) NULL
, (char *) &fileName
,
57 "File from which to read commands"},
58 {"-geometry", TK_ARGV_STRING
, (char *) NULL
, (char *) &geometry
,
59 "Initial geometry for window"},
60 {"-display", TK_ARGV_STRING
, (char *) NULL
, (char *) &display
,
62 {"-name", TK_ARGV_STRING
, (char *) NULL
, (char *) &name
,
63 "Name to use for application"},
64 {"-sync", TK_ARGV_CONSTANT
, (char *) 1, (char *) &synchronize
,
65 "Use synchronous mode for display server"},
66 {(char *) NULL
, TK_ARGV_END
, (char *) NULL
, (char *) NULL
,
72 StdinProc(clientData
, mask
)
73 ClientData clientData
; /* Not used. */
77 static int gotPartial
= 0;
81 if (mask
& TK_READABLE
) {
82 if (fgets(line
, 200, stdin
) == NULL
) {
85 Tcl_Eval(interp
, "destroy .", 0, (char **) NULL
);
88 Tk_DeleteFileHandler(0);
95 cmd
= Tcl_AssembleCmd(buffer
, line
);
101 result
= Tcl_RecordAndEval(interp
, cmd
, 0);
102 if (*interp
->result
!= 0) {
103 if ((result
!= TCL_OK
) || (tty
)) {
104 printf("%s\n", interp
->result
);
116 StructureProc(clientData
, eventPtr
)
117 ClientData clientData
; /* Information about window. */
118 XEvent
*eventPtr
; /* Information about event. */
120 if (eventPtr
->type
== DestroyNotify
) {
126 * Procedure to map initial window. This is invoked as a do-when-idle
127 * handler. Wait for all other when-idle handlers to be processed
128 * before mapping the window, so that the window's correct geometry
129 * has been determined.
134 DelayedMap(clientData
)
135 ClientData clientData
; /* Not used. */
138 while (Tk_DoOneEvent(TK_IDLE_EVENTS
) != 0) {
139 /* Empty loop body. */
149 DotCmd(dummy
, interp
, argc
, argv
)
150 ClientData dummy
; /* Not used. */
151 Tcl_Interp
*interp
; /* Current interpreter. */
152 int argc
; /* Number of arguments. */
153 char **argv
; /* Argument strings. */
158 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
159 " x y\"", (char *) NULL
);
162 x
= strtol(argv
[1], (char **) NULL
, 0);
163 y
= strtol(argv
[2], (char **) NULL
, 0);
164 Tk_MakeWindowExist(w
);
165 XDrawPoint(Tk_Display(w
), Tk_WindowId(w
),
166 DefaultGCOfScreen(Tk_Screen(w
)), x
, y
);
172 MovetoCmd(dummy
, interp
, argc
, argv
)
173 ClientData dummy
; /* Not used. */
174 Tcl_Interp
*interp
; /* Current interpreter. */
175 int argc
; /* Number of arguments. */
176 char **argv
; /* Argument strings. */
179 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
180 " x y\"", (char *) NULL
);
183 x
= strtol(argv
[1], (char **) NULL
, 0);
184 y
= strtol(argv
[2], (char **) NULL
, 0);
189 LinetoCmd(dummy
, interp
, argc
, argv
)
190 ClientData dummy
; /* Not used. */
191 Tcl_Interp
*interp
; /* Current interpreter. */
192 int argc
; /* Number of arguments. */
193 char **argv
; /* Argument strings. */
198 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
199 " x y\"", (char *) NULL
);
202 newX
= strtol(argv
[1], (char **) NULL
, 0);
203 newY
= strtol(argv
[2], (char **) NULL
, 0);
204 Tk_MakeWindowExist(w
);
205 XDrawLine(Tk_Display(w
), Tk_WindowId(w
),
206 DefaultGCOfScreen(Tk_Screen(w
)), x
, y
, newX
, newY
);
217 char *args
, *p
, *msg
;
222 { extern char *TCL_Library
, *TK_Library
;
223 extern int TK_CreateColormap
;
224 char *tcllib
= getenv("TCL_LIBRARY");
225 char *tklib
= getenv("TK_LIBRARY");
226 char *create
= getenv("CREATE_COLORMAP");
230 TCL_Library
= tcllib
;
232 TK_CreateColormap
= 1;
235 interp
= Tcl_CreateInterp();
237 Tcl_InitMemory(interp
);
239 if (Tk_ParseArgv(interp
, (Tk_Window
) NULL
, &argc
, argv
, argTable
, 0)
241 fprintf(stderr
, "%s\n", interp
->result
);
245 if (fileName
!= NULL
) {
250 name
= strrchr(p
, '/');
257 w
= Tk_CreateMainWindow(interp
, display
, name
);
259 fprintf(stderr
, "%s\n", interp
->result
);
262 Tk_SetClass(w
, "Tk");
263 Tk_CreateEventHandler(w
, StructureNotifyMask
, StructureProc
,
265 Tk_DoWhenIdle(DelayedMap
, (ClientData
) NULL
);
268 args
= Tcl_Merge(argc
-1, argv
+1);
269 Tcl_SetVar(interp
, "argv", args
, TCL_GLOBAL_ONLY
);
271 sprintf(buf
, "%d", argc
-1);
272 Tcl_SetVar(interp
, "argc", buf
, TCL_GLOBAL_ONLY
);
275 XSynchronize(Tk_Display(w
), True
);
277 Tk_GeometryRequest(w
, 200, 200);
278 border
= Tk_Get3DBorder(interp
, w
, None
, "#4eee94");
279 if (border
== NULL
) {
280 Tcl_SetResult(interp
, (char *) NULL
, TCL_STATIC
);
281 Tk_SetWindowBackground(w
, WhitePixelOfScreen(Tk_Screen(w
)));
283 Tk_SetBackgroundFromBorder(w
, border
);
285 XSetForeground(Tk_Display(w
), DefaultGCOfScreen(Tk_Screen(w
)),
286 BlackPixelOfScreen(Tk_Screen(w
)));
287 Tcl_CreateCommand(interp
, "dot", DotCmd
, (ClientData
) w
,
289 Tcl_CreateCommand(interp
, "lineto", LinetoCmd
, (ClientData
) w
,
291 Tcl_CreateCommand(interp
, "moveto", MovetoCmd
, (ClientData
) w
,
294 Tcl_CreateCommand(interp
, "square", Tk_SquareCmd
, (ClientData
) w
,
297 if (geometry
!= NULL
) {
298 Tcl_SetVar(interp
, "geometry", geometry
, TCL_GLOBAL_ONLY
);
300 result
= Tcl_Eval(interp
, initCmd
, 0, (char **) NULL
);
301 if (result
!= TCL_OK
) {
304 if (fileName
!= NULL
) {
305 result
= Tcl_VarEval(interp
, "source ", fileName
, (char *) NULL
);
306 if (result
!= TCL_OK
) {
312 Tk_CreateFileHandler(0, TK_READABLE
, StdinProc
, (ClientData
) 0);
318 buffer
= Tcl_CreateCmdBuf();
319 (void) Tcl_Eval(interp
, "update", 0, (char **) NULL
);
322 Tcl_DeleteInterp(interp
);
323 Tcl_DeleteCmdBuf(buffer
);
327 msg
= Tcl_GetVar(interp
, "errorInfo", TCL_GLOBAL_ONLY
);
329 msg
= interp
->result
;
331 fprintf(stderr
, "%s\n", msg
);
332 Tcl_Eval(interp
, "destroy .", 0, (char **) NULL
);