Debian Codegraph @

generic/tkFrame.c

raw symbols ◀ ▶
Source reconstructed at patch state 1 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 /*
2 * tkFrame.c --
3 *
4 * This module implements "frame" and "toplevel" widgets for
5 * the Tk toolkit. Frames are windows with a background color
6 * and possibly a 3-D effect, but not much else in the way of
7 * attributes.
8 *
9 * Copyright (c) 1990-1994 The Regents of the University of California.
10 * Copyright (c) 1994-1995 Sun Microsystems, Inc.
11 *
12 * See the file "license.terms" for information on usage and redistribution
13 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 *
15 * SCCS: @(#) tkFrame.c 1.68 96/02/15 18:53:30
16 */
17
18 #include "bltInt.h"
19
20 #ifndef NO_TILEFRAME
21
22 #include "bltTile.h"
23 /*
24 * Defaults for frames:
25 */
26
27 #define DEF_FRAME_BACKGROUND STD_NORMAL_BACKGROUND
28 #define DEF_FRAME_BG_MONO STD_NORMAL_BG_MONO
29 #define DEF_FRAME_BORDERWIDTH "0"
30 #define DEF_FRAME_CLASS "Frame"
31 #define DEF_FRAME_COLORMAP ""
32 #define DEF_FRAME_CONTAINER "0"
33 #define DEF_FRAME_CURSOR ""
34 #define DEF_FRAME_HEIGHT "0"
35 #define DEF_FRAME_HIGHLIGHT_BG STD_NORMAL_BACKGROUND
36 #define DEF_FRAME_HIGHLIGHT RGB_BLACK
37 #define DEF_FRAME_HIGHLIGHT_WIDTH "0"
38 #define DEF_FRAME_RELIEF "flat"
39 #define DEF_FRAME_TAKE_FOCUS "0"
40 #define DEF_FRAME_USE ""
41 #define DEF_FRAME_VISUAL ""
42 #define DEF_FRAME_WIDTH "0"
43
44 /*
45 * Defaults for toplevels (most of the defaults for frames also apply
46 * to toplevels):
47 */
48
49 #define DEF_TOPLEVEL_CLASS "Toplevel"
50 #define DEF_TOPLEVEL_SCREEN ""
51 #define DEF_TOPLEVEL_MENU ""
52
53 extern Tk_CustomOption bltTileOption;
54
55 /*
56 * A data structure of the following type is kept for each
57 * frame that currently exists for this process:
58 */
59
60 typedef struct {
61 Tk_Window tkwin; /* Window that embodies the frame. NULL
62 * means that the window has been destroyed
63 * but the data structures haven't yet been
64 * cleaned up. */
65 Display *display; /* Display containing widget. Used, among
66 * other things, so that resources can be
67 * freed even after tkwin has gone away. */
68 Tcl_Interp *interp; /* Interpreter associated with widget. Used
69 * to delete widget command. */
70 Tcl_Command widgetCmd; /* Token for frame's widget command. */
71 char *className; /* Class name for widget (from configuration
72 * option). Malloc-ed. */
73 int mask; /* Either FRAME or TOPLEVEL; used to select
74 * which configuration options are valid for
75 * widget. */
76 char *screenName; /* Screen on which widget is created. Non-null
77 * only for top-levels. Malloc-ed, may be
78 * NULL. */
79 char *visualName; /* Textual description of visual for window,
80 * from -visual option. Malloc-ed, may be
81 * NULL. */
82 char *colormapName; /* Textual description of colormap for window,
83 * from -colormap option. Malloc-ed, may be
84 * NULL. */
85 char *menuName; /* Textual description of menu to use for
86 * menubar. Malloc-ed, may be NULL. */
87 Colormap colormap; /* If not None, identifies a colormap
88 * allocated for this window, which must be
89 * freed when the window is deleted. */
90 Tk_3DBorder border; /* Structure used to draw 3-D border and
91 * background. NULL means no background
92 * or border. */
93 int borderWidth; /* Width of 3-D border (if any). */
94 int relief; /* 3-d effect: TK_RELIEF_RAISED etc. */
95 int highlightWidth; /* Width in pixels of highlight to draw
96 * around widget when it has the focus.
97 * 0 means don't draw a highlight. */
98 XColor *highlightBgColorPtr;
99 /* Color for drawing traversal highlight
100 * area when highlight is off. */
101 XColor *highlightColorPtr; /* Color for drawing traversal highlight. */
102 int width; /* Width to request for window. <= 0 means
103 * don't request any size. */
104 int height; /* Height to request for window. <= 0 means
105 * don't request any size. */
106 Tk_Cursor cursor; /* Current cursor for window, or None. */
107 char *takeFocus; /* Value of -takefocus option; not used in
108 * the C code, but used by keyboard traversal
109 * scripts. Malloc'ed, but may be NULL. */
110 int isContainer; /* 1 means this window is a container, 0 means
111 * that it isn't. */
112 char *useThis; /* If the window is embedded, this points to
113 * the name of the window in which it is
114 * embedded (malloc'ed). For non-embedded
115 * windows this is NULL. */
116 int flags; /* Various flags; see below for
117 * definitions. */
118 Blt_Tile tile;
119 } bltFrame;
120
121 /*
122 * Flag bits for frames:
123 *
124 * REDRAW_PENDING: Non-zero means a DoWhenIdle handler
125 * has already been queued to redraw
126 * this window.
127 * GOT_FOCUS: Non-zero means this widget currently
128 * has the input focus.
129 */
130
131 #define REDRAW_PENDING 1
132 #define GOT_FOCUS 4
133
134 /*
135 * The following flag bits are used so that there can be separate
136 * defaults for some configuration options for frames and toplevels.
137 */
138
139 #define FRAME TK_CONFIG_USER_BIT
140 #define TOPLEVEL (TK_CONFIG_USER_BIT << 1)
141 #define BOTH (FRAME | TOPLEVEL)
142
143 static Tk_ConfigSpec configSpecs[] =
144 {
145 {TK_CONFIG_BORDER, "-background", "background", "Background",
146 DEF_FRAME_BACKGROUND, Tk_Offset(bltFrame, border),
147 BOTH | TK_CONFIG_COLOR_ONLY | TK_CONFIG_NULL_OK},
148 {TK_CONFIG_BORDER, "-background", "background", "Background",
149 DEF_FRAME_BG_MONO, Tk_Offset(bltFrame, border),
150 BOTH | TK_CONFIG_MONO_ONLY | TK_CONFIG_NULL_OK},
151 {TK_CONFIG_SYNONYM, "-bd", "borderWidth", (char *)NULL,
152 (char *)NULL, 0, BOTH},
153 {TK_CONFIG_SYNONYM, "-bg", "background", (char *)NULL,
154 (char *)NULL, 0, BOTH},
155 {TK_CONFIG_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
156 DEF_FRAME_BORDERWIDTH, Tk_Offset(bltFrame, borderWidth), BOTH},
157 {TK_CONFIG_STRING, "-class", "class", "Class",
158 DEF_FRAME_CLASS, Tk_Offset(bltFrame, className), FRAME},
159 {TK_CONFIG_STRING, "-class", "class", "Class",
160 DEF_TOPLEVEL_CLASS, Tk_Offset(bltFrame, className), TOPLEVEL},
161 {TK_CONFIG_STRING, "-colormap", "colormap", "Colormap",
162 DEF_FRAME_COLORMAP, Tk_Offset(bltFrame, colormapName),
163 BOTH | TK_CONFIG_NULL_OK},
164 #if (TK_MAJOR_VERSION > 4)
165 {TK_CONFIG_BOOLEAN, "-container", "container", "Container",
166 DEF_FRAME_CONTAINER, Tk_Offset(bltFrame, isContainer), BOTH},
167 #endif /* TK_MAJOR_VERSION > 4 */
168 {TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor",
169 DEF_FRAME_CURSOR, Tk_Offset(bltFrame, cursor), BOTH | TK_CONFIG_NULL_OK},
170 {TK_CONFIG_PIXELS, "-height", "height", "Height",
171 DEF_FRAME_HEIGHT, Tk_Offset(bltFrame, height), BOTH},
172 {TK_CONFIG_COLOR, "-highlightbackground", "highlightBackground",
173 "HighlightBackground", DEF_FRAME_HIGHLIGHT_BG,
174 Tk_Offset(bltFrame, highlightBgColorPtr), BOTH},
175 {TK_CONFIG_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
176 DEF_FRAME_HIGHLIGHT, Tk_Offset(bltFrame, highlightColorPtr), BOTH},
177 {TK_CONFIG_PIXELS, "-highlightthickness", "highlightThickness",
178 "HighlightThickness",
179 DEF_FRAME_HIGHLIGHT_WIDTH, Tk_Offset(bltFrame, highlightWidth), BOTH},
180 #if (TK_MAJOR_VERSION > 4)
181 {TK_CONFIG_STRING, "-menu", "menu", "Menu",
182 DEF_TOPLEVEL_MENU, Tk_Offset(bltFrame, menuName),
183 TOPLEVEL | TK_CONFIG_NULL_OK},
184 #endif /* TK_MAJOR_VERSION > 4 */
185 {TK_CONFIG_RELIEF, "-relief", "relief", "Relief",
186 DEF_FRAME_RELIEF, Tk_Offset(bltFrame, relief), BOTH},
187 {TK_CONFIG_STRING, "-screen", "screen", "Screen",
188 DEF_TOPLEVEL_SCREEN, Tk_Offset(bltFrame, screenName),
189 TOPLEVEL | TK_CONFIG_NULL_OK},
190 {TK_CONFIG_STRING, "-takefocus", "takeFocus", "TakeFocus",
191 DEF_FRAME_TAKE_FOCUS, Tk_Offset(bltFrame, takeFocus),
192 BOTH | TK_CONFIG_NULL_OK},
193 {TK_CONFIG_CUSTOM, "-tile", "tile", "Tile",
194 (char *)NULL, Tk_Offset(bltFrame, tile), BOTH | TK_CONFIG_NULL_OK,
195 &bltTileOption},
196 #if (TK_MAJOR_VERSION > 4)
197 {TK_CONFIG_STRING, "-use", "use", "Use",
198 DEF_FRAME_USE, Tk_Offset(bltFrame, useThis), TOPLEVEL|TK_CONFIG_NULL_OK},
199 #endif
200 {TK_CONFIG_STRING, "-visual", "visual", "Visual",
201 DEF_FRAME_VISUAL, Tk_Offset(bltFrame, visualName),
202 BOTH | TK_CONFIG_NULL_OK},
203 {TK_CONFIG_PIXELS, "-width", "width", "Width",
204 DEF_FRAME_WIDTH, Tk_Offset(bltFrame, width), BOTH},
205 {TK_CONFIG_END, (char *)NULL, (char *)NULL, (char *)NULL,
206 (char *)NULL, 0, 0}
207 };
208
209 /*
210 * Forward declarations for procedures defined later in this file:
211 */
212
213 static int ConfigureFrame _ANSI_ARGS_((Tcl_Interp *interp,
214 bltFrame * framePtr, int argc, CONST84 char **argv,
215 int flags));
216 static void DestroyFrame _ANSI_ARGS_((DestroyData *memPtr));
217 static void DisplayFrame _ANSI_ARGS_((ClientData clientData));
218 static void FrameCmdDeletedProc _ANSI_ARGS_((
219 ClientData clientData));
220 static void FrameEventProc _ANSI_ARGS_((ClientData clientData,
221 XEvent *eventPtr));
222 static void MapFrame _ANSI_ARGS_((ClientData clientData));
223
224 static Blt_TileChangedProc TileChangedProc;
225 static Tcl_CmdProc FrameCmd, ToplevelCmd, FrameWidgetCmd;
226
227 static
228 int BltCreateFrame _ANSI_ARGS_((ClientData clientData,
229 Tcl_Interp *interp, int argc, CONST84 char **argv,
230 int toplevel, char *appName));
231
232 #if (TK_MAJOR_VERSION == 8) && (TK_MINOR_VERSION > 3)
233 #define TkSetClassProcs Tk_SetClassProcs
234 #else
235 EXTERN void TkSetClassProcs _ANSI_ARGS_((Tk_Window tkwin, void *procs,
236 ClientData instanceData));
237 #endif /* TK_MAJOR_VERSION == 8 && TK_MINOR_VERSION > 3 */
238
239 #if (TCL_VERSION_NUMBER < _VERSION(8,6,0))
240 EXTERN void TkpSetMainMenubar _ANSI_ARGS_((Tcl_Interp * interp, Tk_Window tkwin,
241 char * menuName));
242 #endif
243 EXTERN void TkpMakeContainer _ANSI_ARGS_((Tk_Window tkwin));
244
245
246 /*
247 *--------------------------------------------------------------
248 *
249 * FrameCmd, ToplevelCmd --
250 *
251 * These procedures are invoked to process the "frame" and
252 * "toplevel" Tcl commands. See the user documentation for
253 * details on what they do.
254 *
255 * Results:
256 * A standard Tcl result.
257 *
258 * Side effects:
259 * See the user documentation. These procedures are just wrappers;
260 * they call ButtonCreate to do all of the real work.
261 *
262 *--------------------------------------------------------------
263 */
264
265 static int
266 FrameCmd(clientData, interp, argc, argv)
267 ClientData clientData; /* Main window associated with
268 * interpreter. */
269 Tcl_Interp *interp; /* Current interpreter. */
270 int argc; /* Number of arguments. */
271 CONST84 char **argv; /* Argument strings. */
272 {
273 return BltCreateFrame(clientData, interp, argc, argv, 0, (char *)NULL);
274 }
275
276 static int
277 ToplevelCmd(clientData, interp, argc, argv)
278 ClientData clientData; /* Main window associated with
279 * interpreter. */
280 Tcl_Interp *interp; /* Current interpreter. */
281 int argc; /* Number of arguments. */
282 CONST84 char **argv; /* Argument strings. */
283 {
284 return BltCreateFrame(clientData, interp, argc, argv, 1, (char *)NULL);
285 }
286
287 /*
288 *--------------------------------------------------------------
289 *
290 * TkFrameCreate --
291 *
292 * This procedure is invoked to process the "frame" and "toplevel"
293 * Tcl commands; it is also invoked directly by Tk_Init to create
294 * a new main window. See the user documentation for the "frame"
295 * and "toplevel" commands for details on what it does.
296 *
297 * Results:
298 * A standard Tcl result.
299 *
300 * Side effects:
301 * See the user documentation.
302 *
303 *--------------------------------------------------------------
304 */
305
306 /*ARGSUSED*/
307 #ifndef TILE_MAINWINDOW
308 static
309 #endif /* TILE_MAINWINDOW */
310 int
311 BltCreateFrame(clientData, interp, argc, argv, toplevel, appName)
312 ClientData clientData; /* Main window associated with interpreter.
313 * If we're called by Tk_Init to create a
314 * new application, then this is NULL. */
315 Tcl_Interp *interp; /* Current interpreter. */
316 int argc; /* Number of arguments. */
317 CONST84 char *argv[]; /* Argument strings. */
318 int toplevel; /* Non-zero means create a toplevel window,
319 * zero means create a frame. */
320 char *appName; /* Should only be non-NULL if clientData is
321 * NULL: gives the base name to use for the
322 * new application. */
323 {
324 bltFrame *framePtr;
325 Tk_Window new;
326 char *className, *screenName, *visualName, *colormapName, *arg, *useOption;
327 int i, c, length, depth;
328 unsigned int mask;
329 Colormap colormap;
330 Visual *visual;
331 Tk_Window tkwin;
332
333 if (argc < 2) {
334 Tcl_AppendResult(interp, "wrong # args: should be \"",
335 argv[0], " pathName ?options?\"", (char *)NULL);
336 return TCL_ERROR;
337 }
338 /*
339 * Pre-process the argument list. Scan through it to find any
340 * "-class", "-screen", "-visual", and "-colormap" options. These
341 * arguments need to be processed specially, before the window
342 * is configured using the usual Tk mechanisms.
343 */
344
345 className = colormapName = screenName = visualName = useOption = NULL;
346 colormap = None;
347 for (i = 2; i < argc; i += 2) {
348 arg = argv[i];
349 length = strlen(arg);
350 if (length < 2) {
351 continue;
352 }
353 c = arg[1];
354 if ((c == 'c') && (strncmp(arg, "-class", strlen(arg)) == 0)
355 && (length >= 3)) {
356 className = argv[i + 1];
357 } else if ((c == 'c')
358 && (strncmp(arg, "-colormap", strlen(arg)) == 0)) {
359 colormapName = argv[i + 1];
360 } else if ((c == 's') && toplevel
361 && (strncmp(arg, "-screen", strlen(arg)) == 0)) {
362 screenName = argv[i + 1];
363 } else if ((c == 'u') && toplevel
364 && (strncmp(arg, "-use", strlen(arg)) == 0)) {
365 useOption = argv[i + 1];
366 } else if ((c == 'v')
367 && (strncmp(arg, "-visual", strlen(arg)) == 0)) {
368 visualName = argv[i + 1];
369 }
370 }
371
372 /*
373 * Create the window, and deal with the special options -use,
374 * -classname, -colormap, -screenname, and -visual. These options
375 * must be handle before calling ConfigureFrame below, and they must
376 * also be processed in a particular order, for the following
377 * reasons:
378 * 1. Must set the window's class before calling ConfigureFrame,
379 * so that unspecified options are looked up in the option
380 * database using the correct class.
381 * 2. Must set visual information before calling ConfigureFrame
382 * so that colors are allocated in a proper colormap.
383 * 3. Must call TkpUseWindow before setting non-default visual
384 * information, since TkpUseWindow changes the defaults.
385 */
386
387 if (screenName == NULL) {
388 screenName = (toplevel) ? "" : NULL;
389 }
390 tkwin = Tk_MainWindow(interp);
391 if (tkwin != NULL) {
392 new = Tk_CreateWindowFromPath(interp, tkwin, argv[1], screenName);
393 } else {
394 /*
395 * We were called from Tk_Init; create a new application.
396 */
397
398 if (appName == NULL) {
399 panic("BltCreateFrame didn't get application name");
400 }
401 new = (Tk_Window)TkCreateMainWindow(interp, screenName, appName);
402 }
403 if (new == NULL) {
404 goto error;
405 }
406 if (className == NULL) {
407 className = (char *)Tk_GetOption(new, "class", "Class");
408 if (className == NULL) {
409 className = (toplevel) ? "Toplevel" : "Frame";
410 }
411 }
412 Tk_SetClass(new, className);
413 #if (TK_MAJOR_VERSION > 4)
414 if (useOption == NULL) {
415 useOption = (char *)Tk_GetOption(new, "use", "Use");
416 }
417 if (useOption != NULL) {
418 if (TkpUseWindow(interp, new, useOption) != TCL_OK) {
419 goto error;
420 }
421 }
422 #endif
423 if (visualName == NULL) {
424 visualName = (char *)Tk_GetOption(new, "visual", "Visual");
425 }
426 if (colormapName == NULL) {
427 colormapName = (char *)Tk_GetOption(new, "colormap", "Colormap");
428 }
429 if (visualName != NULL) {
430 visual = Tk_GetVisual(interp, new, visualName, &depth,
431 (colormapName == NULL) ? &colormap : (Colormap *) NULL);
432 if (visual == NULL) {
433 goto error;
434 }
435 Tk_SetWindowVisual(new, visual, depth, colormap);
436 }
437 if (colormapName != NULL) {
438 colormap = Tk_GetColormap(interp, new, colormapName);
439 if (colormap == None) {
440 goto error;
441 }
442 Tk_SetWindowColormap(new, colormap);
443 }
444 /*
445 * For top-level windows, provide an initial geometry request of
446 * 200x200, just so the window looks nicer on the screen if it
447 * doesn't request a size for itself.
448 */
449
450 if (toplevel) {
451 Tk_GeometryRequest(new, 200, 200);
452 }
453 /*
454 * Create the widget record, process configuration options, and
455 * create event handlers. Then fill in a few additional fields
456 * in the widget record from the special options.
457 */
458
459 framePtr = Blt_Malloc(sizeof(bltFrame));
460 framePtr->tkwin = new;
461 framePtr->display = Tk_Display(new);
462 framePtr->interp = interp;
463 framePtr->widgetCmd = Tcl_CreateCommand(interp,
464 Tk_PathName(new), FrameWidgetCmd,
465 (ClientData)framePtr, FrameCmdDeletedProc);
466 framePtr->className = NULL;
467 framePtr->mask = (toplevel) ? TOPLEVEL : FRAME;
468 framePtr->screenName = NULL;
469 framePtr->visualName = NULL;
470 framePtr->colormapName = NULL;
471 framePtr->colormap = colormap;
472 framePtr->border = NULL;
473 framePtr->borderWidth = 0;
474 framePtr->relief = TK_RELIEF_FLAT;
475 framePtr->highlightWidth = 0;
476 framePtr->highlightBgColorPtr = NULL;
477 framePtr->highlightColorPtr = NULL;
478 framePtr->width = 0;
479 framePtr->height = 0;
480 framePtr->cursor = None;
481 framePtr->takeFocus = NULL;
482 framePtr->isContainer = 0;
483 framePtr->useThis = NULL;
484 framePtr->flags = 0;
485 framePtr->tile = NULL;
486 framePtr->menuName = NULL;
487
488 #if (TK_MAJOR_VERSION > 4)
489 /*
490 * Store backreference to frame widget in window structure.
491 */
492 TkSetClassProcs(new, NULL, (ClientData)framePtr);
493 #endif
494
495 mask = ExposureMask | StructureNotifyMask | FocusChangeMask;
496 if (toplevel) {
497 mask |= ActivateMask;
498 }
499 Tk_CreateEventHandler(new, mask, FrameEventProc, (ClientData)framePtr);
500 if (ConfigureFrame(interp, framePtr, argc - 2, argv + 2, 0) != TCL_OK) {
501 goto error;
502 }
503 #if (TK_MAJOR_VERSION > 4)
504 if ((framePtr->isContainer)) {
505 if (framePtr->useThis == NULL) {
506 TkpMakeContainer(framePtr->tkwin);
507 } else {
508 Tcl_AppendResult(interp, "A window cannot have both the -use ",
509 "and the -container option set.", (char *)NULL);
510 return TCL_ERROR;
511 }
512 }
513 #endif
514 if (toplevel) {
515 Tcl_DoWhenIdle(MapFrame, (ClientData)framePtr);
516 }
517 Tcl_SetResult(interp, Tk_PathName(new), TCL_VOLATILE);
518 return TCL_OK;
519
520 error:
521 if (new != NULL) {
522 Tk_DestroyWindow(new);
523 }
524 return TCL_ERROR;
525 }
526
527 /*
528 *--------------------------------------------------------------
529 *
530 * FrameWidgetCmd --
531 *
532 * This procedure is invoked to process the Tcl command
533 * that corresponds to a frame widget. See the user
534 * documentation for details on what it does.
535 *
536 * Results:
537 * A standard Tcl result.
538 *
539 * Side effects:
540 * See the user documentation.
541 *
542 *--------------------------------------------------------------
543 */
544
545 static int
546 FrameWidgetCmd(clientData, interp, argc, argv)
547 ClientData clientData; /* Information about frame widget. */
548 Tcl_Interp *interp; /* Current interpreter. */
549 int argc; /* Number of arguments. */
550 CONST84 char *argv[]; /* Argument strings. */
551 {
552 register bltFrame *framePtr = (bltFrame *) clientData;
553 int result;
554 size_t length;
555 int c, i;
556
557 if (argc < 2) {
558 Tcl_AppendResult(interp, "wrong # args: should be \"",
559 argv[0], " option ?arg arg ...?\"", (char *)NULL);
560 return TCL_ERROR;
561 }
562 Tcl_Preserve((ClientData)framePtr);
563 c = argv[1][0];
564 length = strlen(argv[1]);
565 if ((c == 'c') && (strncmp(argv[1], "cget", length) == 0)
566 && (length >= 2)) {
567 if (argc != 3) {
568 Tcl_AppendResult(interp, "wrong # args: should be \"",
569 argv[0], " cget option\"",
570 (char *)NULL);
571 result = TCL_ERROR;
572 goto done;
573 }
574 result = Tk_ConfigureValue(interp, framePtr->tkwin, configSpecs,
575 (char *)framePtr, argv[2], framePtr->mask);
576 } else if ((c == 'c') && (strncmp(argv[1], "configure", length) == 0)
577 && (length >= 2)) {
578 if (argc == 2) {
579 result = Tk_ConfigureInfo(interp, framePtr->tkwin, configSpecs,
580 (char *)framePtr, (char *)NULL, framePtr->mask);
581 } else if (argc == 3) {
582 result = Tk_ConfigureInfo(interp, framePtr->tkwin, configSpecs,
583 (char *)framePtr, argv[2], framePtr->mask);
584 } else {
585 /*
586 * Don't allow the options -class, -colormap, -container,
587 * -newcmap, -screen, -use, or -visual to be changed.
588 */
589
590 for (i = 2; i < argc; i++) {
591 length = strlen(argv[i]);
592 if (length < 2) {
593 continue;
594 }
595 c = argv[i][1];
596 if (((c == 'c') && (strncmp(argv[i], "-class", length) == 0)
597 && (length >= 2))
598 || ((c == 'c') && (framePtr->mask == TOPLEVEL)
599 && (strncmp(argv[i], "-colormap", length) == 0)
600 && (length >= 3))
601 || ((c == 'c')
602 && (strncmp(argv[i], "-container", length) == 0)
603 && (length >= 3))
604 || ((c == 's') && (framePtr->mask == TOPLEVEL)
605 && (strncmp(argv[i], "-screen", length) == 0))
606 || ((c == 'u') && (framePtr->mask == TOPLEVEL)
607 && (strncmp(argv[i], "-use", length) == 0))
608 || ((c == 'v') && (framePtr->mask == TOPLEVEL)
609 && (strncmp(argv[i], "-visual", length) == 0))) {
610 Tcl_AppendResult(interp, "can't modify ", argv[i],
611 " option after widget is created", (char *)NULL);
612 result = TCL_ERROR;
613 goto done;
614 }
615 }
616 result = ConfigureFrame(interp, framePtr, argc - 2, argv + 2,
617 TK_CONFIG_ARGV_ONLY);
618 }
619 } else {
620 Tcl_AppendResult(interp, "bad option \"", argv[1],
621 "\": must be cget or configure", (char *)NULL);
622 result = TCL_ERROR;
623 }
624
625 done:
626 Tcl_Release((ClientData)framePtr);
627 return result;
628 }
629
630 /*
631 *----------------------------------------------------------------------
632 *
633 * DestroyFrame --
634 *
635 * This procedure is invoked by Tcl_EventuallyFree or Tcl_Release
636 * to clean up the internal structure of a frame at a safe time
637 * (when no-one is using it anymore).
638 *
639 * Results:
640 * None.
641 *
642 * Side effects:
643 * Everything associated with the frame is freed up.
644 *
645 *----------------------------------------------------------------------
646 */
647
648 static void
649 DestroyFrame(memPtr)
650 DestroyData *memPtr; /* Info about frame widget. */
651 {
652 register bltFrame *framePtr = (bltFrame *) memPtr;
653
654 Tk_FreeOptions(configSpecs, (char *)framePtr, framePtr->display,
655 framePtr->mask);
656 if (framePtr->tile != NULL) {
657 Blt_FreeTile(framePtr->tile);
658 }
659 if (framePtr->colormap != None) {
660 Tk_FreeColormap(framePtr->display, framePtr->colormap);
661 }
662 Blt_Free(framePtr);
663 }
664
665 /*
666 *----------------------------------------------------------------------
667 *
668 * TileChangedProc
669 *
670 * Results:
671 * None.
672 *
673 *----------------------------------------------------------------------
674 */
675 /* ARGSUSED */
676 static void
677 TileChangedProc(clientData, tile)
678 ClientData clientData;
679 Blt_Tile tile;
680 {
681 bltFrame *framePtr = (bltFrame *) clientData;
682
683 if (framePtr->tkwin != NULL) {
684 if (!(framePtr->flags & REDRAW_PENDING)) {
685 Tcl_DoWhenIdle(DisplayFrame, (ClientData)framePtr);
686 framePtr->flags |= REDRAW_PENDING;
687 }
688 }
689 }
690
691 /*
692 *----------------------------------------------------------------------
693 *
694 * ConfigureFrame --
695 *
696 * This procedure is called to process an argv/argc list, plus
697 * the Tk option database, in order to configure (or
698 * reconfigure) a frame widget.
699 *
700 * Results:
701 * The return value is a standard Tcl result. If TCL_ERROR is
702 * returned, then interp->result contains an error message.
703 *
704 * Side effects:
705 * Configuration information, such as text string, colors, font,
706 * etc. get set for framePtr; old resources get freed, if there
707 * were any.
708 *
709 *----------------------------------------------------------------------
710 */
711
712 static int
713 ConfigureFrame(interp, framePtr, argc, argv, flags)
714 Tcl_Interp *interp; /* Used for error reporting. */
715 register bltFrame *framePtr; /* Information about widget; may or may
716 * not already have values for some fields. */
717 int argc; /* Number of valid entries in argv. */
718 CONST84 char **argv; /* Arguments. */
719 int flags; /* Flags to pass to Tk_ConfigureWidget. */
720 {
721 #if (TK_MAJOR_VERSION > 4)
722 char *oldMenuName;
723
724 /*
725 * Need the old menubar name for the menu code to delete it.
726 */
727
728 if (framePtr->menuName == NULL) {
729 oldMenuName = NULL;
730 } else {
731 oldMenuName = Blt_Malloc(strlen(framePtr->menuName) + 1);
732 strcpy(oldMenuName, framePtr->menuName);
733 }
734 #endif /* TK_MAJOR_VERSION > 4 */
735
736 if (Tk_ConfigureWidget(interp, framePtr->tkwin, configSpecs,
737 argc, argv, (char *)framePtr, flags | framePtr->mask) != TCL_OK) {
738 return TCL_ERROR;
739 }
740 if (framePtr->tile != NULL) {
741 Blt_SetTileChangedProc(framePtr->tile, TileChangedProc,
742 (ClientData)framePtr);
743 }
744 #if (TK_MAJOR_VERSION > 4)
745 if (((oldMenuName == NULL) && (framePtr->menuName != NULL))
746 || ((oldMenuName != NULL) && (framePtr->menuName == NULL))
747 || ((oldMenuName != NULL) && (framePtr->menuName != NULL)
748 && strcmp(oldMenuName, framePtr->menuName) != 0)) {
749 TkSetWindowMenuBar(interp, framePtr->tkwin, oldMenuName,
750 framePtr->menuName);
751 }
752 #endif /* TK_MAJOR_VERSION > 4 */
753 if (framePtr->border != NULL) {
754 Tk_SetBackgroundFromBorder(framePtr->tkwin, framePtr->border);
755 } else {
756 Tk_SetWindowBackgroundPixmap(framePtr->tkwin, None);
757 }
758 if (framePtr->highlightWidth < 0) {
759 framePtr->highlightWidth = 0;
760 }
761 Tk_SetInternalBorder(framePtr->tkwin,
762 framePtr->borderWidth + framePtr->highlightWidth);
763 if ((framePtr->width > 0) || (framePtr->height > 0)) {
764 Tk_GeometryRequest(framePtr->tkwin, framePtr->width,
765 framePtr->height);
766 }
767 #if (TK_MAJOR_VERSION > 4)
768 if (oldMenuName != NULL) {
769 Blt_Free(oldMenuName);
770 }
771 #endif /* TK_MAJOR_VERSION > 4 */
772
773 if (Tk_IsMapped(framePtr->tkwin)) {
774 if (!(framePtr->flags & REDRAW_PENDING)) {
775 Tcl_DoWhenIdle(DisplayFrame, (ClientData)framePtr);
776 }
777 framePtr->flags |= REDRAW_PENDING;
778 }
779 return TCL_OK;
780 }
781
782 /*
783 *----------------------------------------------------------------------
784 *
785 * DisplayFrame --
786 *
787 * This procedure is invoked to display a frame widget.
788 *
789 * Results:
790 * None.
791 *
792 * Side effects:
793 * Commands are output to X to display the frame in its
794 * current mode.
795 *
796 *----------------------------------------------------------------------
797 */
798 static void
799 DisplayFrame(clientData)
800 ClientData clientData; /* Information about widget. */
801 {
802 register bltFrame *framePtr = (bltFrame *) clientData;
803 register Tk_Window tkwin = framePtr->tkwin;
804 GC gc;
805
806 framePtr->flags &= ~REDRAW_PENDING;
807 if ((framePtr->tkwin == NULL) || !Tk_IsMapped(tkwin)
808 || framePtr->isContainer) {
809 return;
810 }
811 if (framePtr->tile == NULL) {
812 Blt_Fill3DRectangle(tkwin, Tk_WindowId(tkwin),
813 framePtr->border, framePtr->highlightWidth,
814 framePtr->highlightWidth,
815 Tk_Width(tkwin) - 2 * framePtr->highlightWidth,
816 Tk_Height(tkwin) - 2 * framePtr->highlightWidth,
817 framePtr->borderWidth, framePtr->relief);
818 } else {
819 Blt_SetTileOrigin(tkwin, framePtr->tile, 0, 0);
820 Blt_TileRectangle(tkwin, Tk_WindowId(tkwin), framePtr->tile, 0, 0,
821 Tk_Width(tkwin), Tk_Height(tkwin));
822 if ((framePtr->border != NULL) &&
823 (framePtr->relief != TK_RELIEF_FLAT)) {
824 Blt_Draw3DRectangle(tkwin, Tk_WindowId(tkwin),
825 framePtr->border, framePtr->highlightWidth,
826 framePtr->highlightWidth,
827 Tk_Width(tkwin) - 2 * framePtr->highlightWidth,
828 Tk_Height(tkwin) - 2 * framePtr->highlightWidth,
829 framePtr->borderWidth, framePtr->relief);
830 }
831 }
832 if (framePtr->highlightWidth != 0) {
833 if (framePtr->flags & GOT_FOCUS) {
834 gc = Tk_GCForColor(framePtr->highlightColorPtr,
835 Tk_WindowId(tkwin));
836 } else {
837 gc = Tk_GCForColor(framePtr->highlightBgColorPtr,
838 Tk_WindowId(tkwin));
839 }
840 Tk_DrawFocusHighlight(tkwin, gc, framePtr->highlightWidth,
841 Tk_WindowId(tkwin));
842 }
843 }
844
845 /*
846 *--------------------------------------------------------------
847 *
848 * FrameEventProc --
849 *
850 * This procedure is invoked by the Tk dispatcher on
851 * structure changes to a frame. For frames with 3D
852 * borders, this procedure is also invoked for exposures.
853 *
854 * Results:
855 * None.
856 *
857 * Side effects:
858 * When the window gets deleted, internal structures get
859 * cleaned up. When it gets exposed, it is redisplayed.
860 *
861 *--------------------------------------------------------------
862 */
863
864 static void
865 FrameEventProc(clientData, eventPtr)
866 ClientData clientData; /* Information about window. */
867 register XEvent *eventPtr; /* Information about event. */
868 {
869 register bltFrame *framePtr = (bltFrame *) clientData;
870
871 if (((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0))
872 || (eventPtr->type == ConfigureNotify)) {
873 goto redraw;
874 } else if (eventPtr->type == DestroyNotify) {
875 #if (TK_MAJOR_VERSION > 4)
876 if (framePtr->menuName != NULL) {
877 TkSetWindowMenuBar(framePtr->interp, framePtr->tkwin,
878 framePtr->menuName, NULL);
879 Blt_Free(framePtr->menuName);
880 framePtr->menuName = NULL;
881 }
882 #endif /* TK_MAJOR_VERSION > 4 */
883 if (framePtr->tkwin != NULL) {
884
885 /*
886 * If this window is a container, then this event could be
887 * coming from the embedded application, in which case
888 * Tk_DestroyWindow hasn't been called yet. When Tk_DestroyWindow
889 * is called later, then another destroy event will be generated.
890 * We need to be sure we ignore the second event, since the frame
891 * could be gone by then. To do so, delete the event handler
892 * explicitly (normally it's done implicitly by Tk_DestroyWindow).
893 */
894 Tk_DeleteEventHandler(framePtr->tkwin,
895 ExposureMask | StructureNotifyMask | FocusChangeMask,
896 FrameEventProc, (ClientData)framePtr);
897 framePtr->tkwin = NULL;
898 Tcl_DeleteCommandFromToken(framePtr->interp, framePtr->widgetCmd);
899 }
900 if (framePtr->flags & REDRAW_PENDING) {
901 Tcl_CancelIdleCall(DisplayFrame, (ClientData)framePtr);
902 }
903 Tcl_CancelIdleCall(MapFrame, (ClientData)framePtr);
904 Tcl_EventuallyFree((ClientData)framePtr, (Tcl_FreeProc *)DestroyFrame);
905 } else if (eventPtr->type == FocusIn) {
906 if (eventPtr->xfocus.detail != NotifyInferior) {
907 framePtr->flags |= GOT_FOCUS;
908 if (framePtr->highlightWidth > 0) {
909 goto redraw;
910 }
911 }
912 } else if (eventPtr->type == FocusOut) {
913 if (eventPtr->xfocus.detail != NotifyInferior) {
914 framePtr->flags &= ~GOT_FOCUS;
915 if (framePtr->highlightWidth > 0) {
916 goto redraw;
917 }
918 }
919 #if (TK_MAJOR_VERSION > 4)
920 } else if (eventPtr->type == ActivateNotify) {
921 TkpSetMainMenubar(framePtr->interp, framePtr->tkwin,
922 framePtr->menuName);
923 #endif /* TK_MAJOR_VERSION > 4 */
924 }
925 return;
926
927 redraw:
928 if ((framePtr->tkwin != NULL) && !(framePtr->flags & REDRAW_PENDING)) {
929 Tcl_DoWhenIdle(DisplayFrame, (ClientData)framePtr);
930 framePtr->flags |= REDRAW_PENDING;
931 }
932 }
933
934 /*
935 *----------------------------------------------------------------------
936 *
937 * FrameCmdDeletedProc --
938 *
939 * This procedure is invoked when a widget command is deleted. If
940 * the widget isn't already in the process of being destroyed,
941 * this command destroys it.
942 *
943 * Results:
944 * None.
945 *
946 * Side effects:
947 * The widget is destroyed.
948 *
949 *----------------------------------------------------------------------
950 */
951
952 static void
953 FrameCmdDeletedProc(clientData)
954 ClientData clientData; /* Pointer to widget record for widget. */
955 {
956 bltFrame *framePtr = (bltFrame *) clientData;
957 Tk_Window tkwin = framePtr->tkwin;
958
959 #if (TK_MAJOR_VERSION > 4)
960 if (framePtr->menuName != NULL) {
961 TkSetWindowMenuBar(framePtr->interp, framePtr->tkwin,
962 framePtr->menuName, NULL);
963 Blt_Free(framePtr->menuName);
964 framePtr->menuName = NULL;
965 }
966 #endif /* TK_MAJOR_VERSION > 4 */
967
968 /*
969 * This procedure could be invoked either because the window was
970 * destroyed and the command was then deleted (in which case tkwin
971 * is NULL) or because the command was deleted, and then this procedure
972 * destroys the widget.
973 */
974
975 if (tkwin != NULL) {
976 framePtr->tkwin = NULL;
977 Tk_DestroyWindow(tkwin);
978 }
979 }
980
981 /*
982 *----------------------------------------------------------------------
983 *
984 * MapFrame --
985 *
986 * This procedure is invoked as a when-idle handler to map a
987 * newly-created top-level frame.
988 *
989 * Results:
990 * None.
991 *
992 * Side effects:
993 * The frame given by the clientData argument is mapped.
994 *
995 *----------------------------------------------------------------------
996 */
997
998 static void
999 MapFrame(clientData)
1000 ClientData clientData; /* Pointer to frame structure. */
1001 {
1002 bltFrame *framePtr = (bltFrame *) clientData;
1003
1004 /*
1005 * Wait for all other background events to be processed before
1006 * mapping window. This ensures that the window's correct geometry
1007 * will have been determined before it is first mapped, so that the
1008 * window manager doesn't get a false idea of its desired geometry.
1009 */
1010
1011 Tcl_Preserve((ClientData)framePtr);
1012 for(;;) {
1013 if (Tcl_DoOneEvent(TCL_IDLE_EVENTS) == 0) {
1014 break;
1015 }
1016 /*
1017 * After each event, make sure that the window still exists
1018 * and quit if the window has been destroyed.
1019 */
1020
1021 if (framePtr->tkwin == NULL) {
1022 Tcl_Release((ClientData)framePtr);
1023 return;
1024 }
1025 }
1026 Tk_MapWindow(framePtr->tkwin);
1027 Tcl_Release((ClientData)framePtr);
1028 }
1029
1030 /*
1031 *--------------------------------------------------------------
1032 *
1033 * TkInstallFrameMenu --
1034 *
1035 * This function is needed when a Windows HWND is created
1036 * and a menubar has been set to the window with a system
1037 * menu. It notifies the menu package so that the system
1038 * menu can be rebuilt.
1039 *
1040 * Results:
1041 * None.
1042 *
1043 * Side effects:
1044 * The system menu (if any) is created for the menubar
1045 * associated with this frame.
1046 *
1047 *--------------------------------------------------------------
1048 */
1049
1050 #ifdef notdef
1051 void
1052 TkInstallFrameMenu(tkwin)
1053 Tk_Window tkwin; /* The window that was just created. */
1054 {
1055 #if (TK_MAJOR_VERSION > 4)
1056 #define Tk_InstanceData(tkwin) (((Tk_FakeWin *)(tkwin))->dummy18)
1057 #define Tk_MainPtr(tkwin) (((Tk_FakeWin *)(tkwin))->dummy5)
1058 if (Tk_MainPtr(tkwin) != NULL) {
1059 bltFrame *framePtr;
1060
1061 framePtr = (bltFrame *) Tk_InstanceData(tkwin);
1062 TkpMenuNotifyToplevelCreate(framePtr->interp, framePtr->menuName);
1063 }
1064 #endif /* TK_MAJOR_VERSION > 4 */
1065 }
1066
1067 #endif
1068
1069 int
1070 Blt_FrameInit(interp)
1071 Tcl_Interp *interp;
1072 {
1073 static Blt_CmdSpec cmdSpecs[2] =
1074 {
1075 #if HAVE_NAMESPACES
1076 {"frame", FrameCmd,},
1077 {"toplevel", ToplevelCmd,},
1078 #else
1079 {"tileframe", FrameCmd,},
1080 {"tiletoplevel", ToplevelCmd,},
1081 #endif /* HAVE_NAMESPACES */
1082 };
1083 return Blt_InitCmds(interp, "blt::tile", cmdSpecs, 2);
1084 }
1085
1086 #endif /* NO_TILEFRAME */