Debian Codegraph @

generic/tkFrame.c

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