Debian Codegraph @

pTk/mTk/generic/tkFrame.c

raw symbols SCIP
1 /*
2 * tkFrame.c --
3 *
4 * This module implements "frame", "labelframe" and "toplevel" widgets
5 * for 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-1997 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 * RCS: @(#) $Id: tkFrame.c,v 1.15.2.1 2003/07/16 23:17:38 pspjuth Exp $
16 */
17
18 #include "default.h"
19 #include "tkPort.h"
20 #include "tkInt.h"
21 #include "tkOption.h"
22 #include "tkOption.m"
23
24 /*
25 * The following enum is used to define the type of the frame.
26 */
27
28 enum FrameType {
29 TYPE_FRAME, TYPE_TOPLEVEL, TYPE_LABELFRAME
30 };
31
32 /*
33 * A data structure of the following type is kept for each
34 * frame that currently exists for this process:
35 */
36
37 typedef struct {
38 Tk_Window tkwin; /* Window that embodies the frame. NULL
39 * means that the window has been destroyed
40 * but the data structures haven't yet been
41 * cleaned up. */
42 Display *display; /* Display containing widget. Used, among
43 * other things, so that resources can be
44 * freed even after tkwin has gone away. */
45 Tcl_Interp *interp; /* Interpreter associated with widget. Used
46 * to delete widget command. */
47 Tcl_Command widgetCmd; /* Token for frame's widget command. */
48 Tk_OptionTable optionTable; /* Table that defines configuration options
49 * available for this widget. */
50 char *className; /* Class name for widget (from configuration
51 * option). Malloc-ed. */
52 enum FrameType type; /* Type of widget, such as TYPE_FRAME. */
53 char *screenName; /* Screen on which widget is created. Non-null
54 * only for top-levels. Malloc-ed, may be
55 * NULL. */
56 Tcl_Obj * visualName; /* Textual description of visual for window,
57 * from -visual option. Malloc-ed, may be
58 * NULL. */
59 char *colormapName; /* Textual description of colormap for window,
60 * from -colormap option. Malloc-ed, may be
61 * NULL. */
62 Tcl_Obj *menuName; /* Textual description of menu to use for
63 * menubar. Malloc-ed, may be NULL. */
64 Colormap colormap; /* If not None, identifies a colormap
65 * allocated for this window, which must be
66 * freed when the window is deleted. */
67 Tk_3DBorder border; /* Structure used to draw 3-D border and
68 * background. NULL means no background
69 * or border. */
70 int borderWidth; /* Width of 3-D border (if any). */
71 int relief; /* 3-d effect: TK_RELIEF_RAISED etc. */
72 int highlightWidth; /* Width in pixels of highlight to draw
73 * around widget when it has the focus.
74 * 0 means don't draw a highlight. */
75 XColor *highlightBgColorPtr;
76 /* Color for drawing traversal highlight
77 * area when highlight is off. */
78 XColor *highlightColorPtr; /* Color for drawing traversal highlight. */
79 int width; /* Width to request for window. <= 0 means
80 * don't request any size. */
81 int height; /* Height to request for window. <= 0 means
82 * don't request any size. */
83 Tk_Cursor cursor; /* Current cursor for window, or None. */
84 char *takeFocus; /* Value of -takefocus option; not used in
85 * the C code, but used by keyboard traversal
86 * scripts. Malloc'ed, but may be NULL. */
87 int isContainer; /* 1 means this window is a container, 0 means
88 * that it isn't. */
89 Tcl_Obj * useThis; /* If the window is embedded, this points to
90 * the name of the window in which it is
91 * embedded (malloc'ed). For non-embedded
92 * windows this is NULL. */
93 int flags; /* Various flags; see below for
94 * definitions. */
95 Tcl_Obj *padXPtr; /* Value of -padx option: specifies how many
96 * pixels of extra space to leave on left and
97 * right of child area. */
98 int padX; /* Integer value corresponding to padXPtr. */
99 Tcl_Obj *padYPtr; /* Value of -padx option: specifies how many
100 * pixels of extra space to leave above and
101 * below child area. */
102 int padY; /* Integer value corresponding to padYPtr. */
103 } Frame;
104
105 /*
106 * A data structure of the following type is kept for each labelframe
107 * widget managed by this file:
108 */
109
110 typedef struct {
111 Frame frame; /* A pointer to the generic frame structure.
112 * This must be the first element of the
113 * Labelframe. */
114
115 /*
116 * Labelframe specific configuration settings.
117 */
118
119 Tcl_Obj *textPtr; /* Value of -text option: specifies text to
120 * display in button. */
121 Tk_Font tkfont; /* Value of -font option: specifies font
122 * to use for display text. */
123 XColor *textColorPtr; /* Value of -fg option: specifies foreground
124 * color in normal mode. */
125 int labelAnchor; /* Value of -labelanchor option: specifies
126 * where to place the label. */
127 Tk_Window labelWin; /* Value of -labelwidget option: Window to
128 * use as label for the frame. */
129
130 /*
131 * Labelframe specific fields for use with configuration settings above.
132 */
133
134 GC textGC; /* GC for drawing text in normal mode. */
135 Tk_TextLayout textLayout; /* Stored text layout information. */
136 XRectangle labelBox; /* The label's actual size and position. */
137 int labelReqWidth; /* The label's requested width. */
138 int labelReqHeight; /* The label's requested height. */
139 int labelTextX, labelTextY; /* Position of the text to be drawn. */
140
141 } Labelframe;
142
143 /*
144 * The following macros define how many extra pixels to leave
145 * around a label's text.
146 */
147
148 #define LABELSPACING 1
149 #define LABELMARGIN 4
150
151 /*
152 * Flag bits for frames:
153 *
154 * REDRAW_PENDING: Non-zero means a DoWhenIdle handler
155 * has already been queued to redraw
156 * this window.
157 * GOT_FOCUS: Non-zero means this widget currently
158 * has the input focus.
159 */
160
161 #define REDRAW_PENDING 1
162 #define GOT_FOCUS 4
163
164 /*
165 * The following enum is used to define a type for the -labelanchor option
166 * of the Labelframe widget. These values are used as indices into the
167 * string table below.
168 */
169
170 enum labelanchor {
171 LABELANCHOR_E, LABELANCHOR_EN, LABELANCHOR_ES,
172 LABELANCHOR_N, LABELANCHOR_NE, LABELANCHOR_NW,
173 LABELANCHOR_S, LABELANCHOR_SE, LABELANCHOR_SW,
174 LABELANCHOR_W, LABELANCHOR_WN, LABELANCHOR_WS
175 };
176
177 static char *labelAnchorStrings[] = {
178 "e", "en", "es", "n", "ne", "nw", "s", "se", "sw", "w", "wn", "ws",
179 (char *) NULL
180 };
181
182 /*
183 * Information used for parsing configuration options. There are
184 * one common table used by all and one table for each widget class.
185 */
186
187 static Tk_OptionSpec commonOptSpec[] = {
188 {TK_OPTION_BORDER, "-background", "background", "Background",
189 DEF_FRAME_BG_COLOR, -1, Tk_Offset(Frame, border),
190 TK_OPTION_NULL_OK, (ClientData) DEF_FRAME_BG_MONO, 0},
191 {TK_OPTION_SYNONYM, "-bg", (char *) NULL, (char *) NULL,
192 (char *) NULL, 0, -1, 0, (ClientData) "-background", 0},
193 {TK_OPTION_STRING, "-colormap", "colormap", "Colormap",
194 DEF_FRAME_COLORMAP, -1, Tk_Offset(Frame, colormapName),
195 TK_OPTION_NULL_OK, 0, 0},
196 {TK_OPTION_BOOLEAN, "-container", "container", "Container",
197 DEF_FRAME_CONTAINER, -1, Tk_Offset(Frame, isContainer),
198 0, 0, 0},
199 {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor",
200 DEF_FRAME_CURSOR, -1, Tk_Offset(Frame, cursor),
201 TK_OPTION_NULL_OK, 0, 0},
202 {TK_OPTION_PIXELS, "-height", "height", "Height",
203 DEF_FRAME_HEIGHT, -1, Tk_Offset(Frame, height),
204 0, 0, 0},
205 {TK_OPTION_COLOR, "-highlightbackground", "highlightBackground",
206 "HighlightBackground", DEF_FRAME_HIGHLIGHT_BG, -1,
207 Tk_Offset(Frame, highlightBgColorPtr), 0, 0, 0},
208 {TK_OPTION_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
209 DEF_FRAME_HIGHLIGHT, -1, Tk_Offset(Frame, highlightColorPtr),
210 0, 0, 0},
211 {TK_OPTION_PIXELS, "-highlightthickness", "highlightThickness",
212 "HighlightThickness", DEF_FRAME_HIGHLIGHT_WIDTH, -1,
213 Tk_Offset(Frame, highlightWidth), 0, 0, 0},
214 {TK_OPTION_PIXELS, "-padx", "padX", "Pad",
215 DEF_FRAME_PADX, Tk_Offset(Frame, padXPtr),
216 Tk_Offset(Frame, padX), 0, 0, 0},
217 {TK_OPTION_PIXELS, "-pady", "padY", "Pad",
218 DEF_FRAME_PADY, Tk_Offset(Frame, padYPtr),
219 Tk_Offset(Frame, padY), 0, 0, 0},
220 {TK_OPTION_STRING, "-takefocus", "takeFocus", "TakeFocus",
221 DEF_FRAME_TAKE_FOCUS, -1, Tk_Offset(Frame, takeFocus),
222 TK_OPTION_NULL_OK, 0, 0},
223 {TK_OPTION_STRING, "-visual", "visual", "Visual",
224 DEF_FRAME_VISUAL, -1, Tk_Offset(Frame, visualName),
225 TK_OPTION_NULL_OK, 0, 0},
226 {TK_OPTION_PIXELS, "-width", "width", "Width",
227 DEF_FRAME_WIDTH, -1, Tk_Offset(Frame, width),
228 0, 0, 0},
229 {TK_OPTION_END, (char *) NULL, (char *) NULL, (char *) NULL,
230 (char *) NULL, 0, 0, 0, 0, 0}
231 };
232
233 static Tk_OptionSpec frameOptSpec[] = {
234 {TK_OPTION_SYNONYM, "-bd", (char *) NULL, (char *) NULL,
235 (char *) NULL, 0, -1, 0, (ClientData) "-borderwidth", 0},
236 {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
237 DEF_FRAME_BORDER_WIDTH, -1, Tk_Offset(Frame, borderWidth),
238 0, 0, 0},
239 {TK_OPTION_STRING, "-class", "class", "Class",
240 DEF_FRAME_CLASS, -1, Tk_Offset(Frame, className),
241 0, 0, 0},
242 {TK_OPTION_RELIEF, "-relief", "relief", "Relief",
243 DEF_FRAME_RELIEF, -1, Tk_Offset(Frame, relief),
244 0, 0, 0},
245 {TK_OPTION_END, (char *) NULL, (char *) NULL, (char *) NULL,
246 (char *) NULL, 0, 0, 0, (ClientData) commonOptSpec, 0}
247 };
248
249 static Tk_OptionSpec toplevelOptSpec[] = {
250 {TK_OPTION_SYNONYM, "-bd", (char *) NULL, (char *) NULL,
251 (char *) NULL, 0, -1, 0, (ClientData) "-borderwidth", 0},
252 {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
253 DEF_FRAME_BORDER_WIDTH, -1, Tk_Offset(Frame, borderWidth),
254 0, 0, 0},
255 {TK_OPTION_STRING, "-class", "class", "Class",
256 DEF_TOPLEVEL_CLASS, -1, Tk_Offset(Frame, className),
257 0, 0, 0},
258 {TK_OPTION_OBJ, "-menu", "menu", "Menu",
259 DEF_TOPLEVEL_MENU, -1, Tk_Offset(Frame, menuName),
260 TK_OPTION_NULL_OK, 0, 0},
261 {TK_OPTION_RELIEF, "-relief", "relief", "Relief",
262 DEF_FRAME_RELIEF, -1, Tk_Offset(Frame, relief),
263 0, 0, 0},
264 {TK_OPTION_STRING, "-screen", "screen", "Screen",
265 DEF_TOPLEVEL_SCREEN, -1, Tk_Offset(Frame, screenName),
266 TK_OPTION_NULL_OK, 0, 0},
267 {TK_OPTION_STRING, "-use", "use", "Use",
268 DEF_TOPLEVEL_USE, -1, Tk_Offset(Frame, useThis),
269 TK_OPTION_NULL_OK, 0, 0},
270 {TK_OPTION_END, (char *) NULL, (char *) NULL, (char *) NULL,
271 (char *) NULL, 0, 0, 0, (ClientData) commonOptSpec, 0}
272 };
273
274 static Tk_OptionSpec labelframeOptSpec[] = {
275 {TK_OPTION_SYNONYM, "-bd", (char *) NULL, (char *) NULL,
276 (char *) NULL, 0, -1, 0, (ClientData) "-borderwidth", 0},
277 {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
278 DEF_LABELFRAME_BORDER_WIDTH, -1, Tk_Offset(Frame, borderWidth),
279 0, 0, 0},
280 {TK_OPTION_STRING, "-class", "class", "Class",
281 DEF_LABELFRAME_CLASS, -1, Tk_Offset(Frame, className),
282 0, 0, 0},
283 {TK_OPTION_SYNONYM, "-fg", "foreground", (char *) NULL,
284 (char *) NULL, 0, -1, 0, (ClientData) "-foreground", 0},
285 {TK_OPTION_FONT, "-font", "font", "Font",
286 DEF_LABELFRAME_FONT, -1, Tk_Offset(Labelframe, tkfont), 0, 0, 0},
287 {TK_OPTION_COLOR, "-foreground", "foreground", "Foreground",
288 DEF_LABELFRAME_FG, -1, Tk_Offset(Labelframe, textColorPtr), 0, 0, 0},
289 {TK_OPTION_STRING_TABLE, "-labelanchor", "labelAnchor", "LabelAnchor",
290 DEF_LABELFRAME_LABELANCHOR, -1, Tk_Offset(Labelframe, labelAnchor),
291 0, (ClientData) labelAnchorStrings, 0},
292 {TK_OPTION_WINDOW, "-labelwidget", "labelWidget", "LabelWidget",
293 (char *) NULL, -1, Tk_Offset(Labelframe, labelWin),
294 TK_OPTION_NULL_OK, 0, 0},
295 {TK_OPTION_RELIEF, "-relief", "relief", "Relief",
296 DEF_LABELFRAME_RELIEF, -1, Tk_Offset(Frame, relief),
297 0, 0, 0},
298 {TK_OPTION_STRING, "-text", "text", "Text",
299 DEF_LABELFRAME_TEXT, Tk_Offset(Labelframe, textPtr), -1,
300 TK_OPTION_NULL_OK, 0, 0},
301 {TK_OPTION_END, (char *) NULL, (char *) NULL, (char *) NULL,
302 (char *) NULL, 0, 0, 0, (ClientData) commonOptSpec, 0}
303 };
304
305 /*
306 * Class names for widgets, indexed by FrameType.
307 */
308
309 static char *classNames[] = {"Frame", "Toplevel", "Labelframe"};
310
311 /*
312 * The following table maps from FrameType to the option template for
313 * that class of widgets.
314 */
315
316 static Tk_OptionSpec *optionSpecs[] = {
317 frameOptSpec,
318 toplevelOptSpec,
319 labelframeOptSpec,
320 };
321
322 /*
323 * Forward declarations for procedures defined later in this file:
324 */
325
326 static void ComputeFrameGeometry _ANSI_ARGS_((Frame *framePtr));
327 static int ConfigureFrame _ANSI_ARGS_((Tcl_Interp *interp,
328 Frame *framePtr, int objc, Tcl_Obj *CONST objv[]));
329 static int CreateFrame _ANSI_ARGS_((ClientData clientData,
330 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[],
331 enum FrameType type, char *appName));
332 static void DestroyFrame _ANSI_ARGS_((char *memPtr));
333 static void DestroyFramePartly _ANSI_ARGS_((Frame *framePtr));
334 static void DisplayFrame _ANSI_ARGS_((ClientData clientData));
335 static void FrameCmdDeletedProc _ANSI_ARGS_((
336 ClientData clientData));
337 static void FrameEventProc _ANSI_ARGS_((ClientData clientData,
338 XEvent *eventPtr));
339 static void FrameLostSlaveProc _ANSI_ARGS_((
340 ClientData clientData, Tk_Window tkwin));
341 static void FrameRequestProc _ANSI_ARGS_((ClientData clientData,
342 Tk_Window tkwin));
343 static void FrameStructureProc _ANSI_ARGS_((
344 ClientData clientData, XEvent *eventPtr));
345 static int FrameWidgetObjCmd _ANSI_ARGS_((ClientData clientData,
346 Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]));
347 static void FrameWorldChanged _ANSI_ARGS_((
348 ClientData instanceData));
349 static void MapFrame _ANSI_ARGS_((ClientData clientData));
350
351 /*
352 * The structure below defines frame class behavior by means of procedures
353 * that can be invoked from generic window code.
354 */
355
356 static Tk_ClassProcs frameClass = {
357 sizeof(Tk_ClassProcs), /* size */
358 FrameWorldChanged /* worldChangedProc */
359 };
360
361 /*
362 * The structure below defines the official type record for the
363 * labelframe's geometry manager:
364 */
365
366 static Tk_GeomMgr frameGeomType = {
367 "labelframe", /* name */
368 FrameRequestProc, /* requestProc */
369 FrameLostSlaveProc /* lostSlaveProc */
370 };
371
372
373 /*
374 *--------------------------------------------------------------
375 *
376 * Tk_FrameObjCmd, Tk_ToplevelObjCmd, Tk_LabelframeObjCmd --
377 *
378 * These procedures are invoked to process the "frame",
379 * "toplevel" and "labelframe" Tcl commands. See the user
380 * documentation for details on what they do.
381 *
382 * Results:
383 * A standard Tcl result.
384 *
385 * Side effects:
386 * See the user documentation. These procedures are just wrappers;
387 * they call CreateFrame to do all of the real work.
388 *
389 *--------------------------------------------------------------
390 */
391
392 int
393 Tk_FrameObjCmd(clientData, interp, objc, objv)
394 ClientData clientData; /* Either NULL or pointer to option table. */
395 Tcl_Interp *interp; /* Current interpreter. */
396 int objc; /* Number of arguments. */
397 Tcl_Obj *CONST objv[]; /* Argument objects. */
398 {
399 return CreateFrame(clientData, interp, objc, objv, TYPE_FRAME,
400 (char *) NULL);
401 }
402
403 int
404 Tk_ToplevelObjCmd(clientData, interp, objc, objv)
405 ClientData clientData; /* Either NULL or pointer to option table. */
406 Tcl_Interp *interp; /* Current interpreter. */
407 int objc; /* Number of arguments. */
408 Tcl_Obj *CONST objv[]; /* Argument objects. */
409 {
410 return CreateFrame(clientData, interp, objc, objv, TYPE_TOPLEVEL,
411 (char *) NULL);
412 }
413
414 int
415 Tk_LabelframeObjCmd(clientData, interp, objc, objv)
416 ClientData clientData; /* Either NULL or pointer to option table. */
417 Tcl_Interp *interp; /* Current interpreter. */
418 int objc; /* Number of arguments. */
419 Tcl_Obj *CONST objv[]; /* Argument objects. */
420 {
421 return CreateFrame(clientData, interp, objc, objv, TYPE_LABELFRAME,
422 (char *) NULL);
423 }
424
425 /*
426 *--------------------------------------------------------------
427 *
428 * TkCreateFrame --
429 *
430 * This procedure is the old command procedure for the "frame"
431 * and "toplevel" commands. Now it is used directly by Tk_Init to
432 * create a new main window. See the user documentation for the
433 * "frame" and "toplevel" commands for details on what it does.
434 *
435 * Results:
436 * A standard Tcl result.
437 *
438 * Side effects:
439 * See the user documentation.
440 *
441 *--------------------------------------------------------------
442 */
443
444 int
445 TkCreateFrame(clientData, interp, argc, argv, toplevel, appName)
446 ClientData clientData; /* Either NULL or pointer to option table. */
447 Tcl_Interp *interp; /* Current interpreter. */
448 int argc; /* Number of arguments. */
449 char **argv; /* Argument strings. */
450 int toplevel; /* Non-zero means create a toplevel window,
451 * zero means create a frame. */
452 char *appName; /* Should only be non-NULL if there is no main
453 * window associated with the interpreter.
454 * Gives the base name to use for the
455 * new application. */
456 {
457 int result, i;
458 #ifndef _LANG
459 Tcl_Obj **objv = (Tcl_Obj **) ckalloc((argc+1) * sizeof(Tcl_Obj **));
460 for (i=0; i<argc; i++) {
461 objv[i] = Tcl_NewStringObj(args[i], -1);
462 Tcl_IncrRefCount(objv[i]);
463 }
464 objv[argc] = NULL;
465 #endif
466 result = CreateFrame(clientData, interp, argc, objv,
467 toplevel ? TYPE_TOPLEVEL : TYPE_FRAME, appName);
468 #ifndef _LANG
469 for (i=0; i<argc; i++) {
470 Tcl_DecrRefCount(objv[i]);
471 }
472 ckfree((char *) objv);
473 #endif
474 return result;
475 }
476
477 static int
478 CreateFrame(clientData, interp, objc, objv, type, appName)
479 ClientData clientData; /* NULL. */
480 Tcl_Interp *interp; /* Current interpreter. */
481 int objc; /* Number of arguments. */
482 Tcl_Obj *CONST objv[]; /* Argument objects. */
483 enum FrameType type; /* What widget type to create. */
484 char *appName; /* Should only be non-NULL if there are no
485 * Main window associated with the interpreter.
486 * Gives the base name to use for the
487 * new application. */
488 {
489 Tk_Window tkwin;
490 Frame *framePtr;
491 Tk_OptionTable optionTable;
492 Tk_Window new;
493 CONST char *className, *screenName, *colormapName, *arg;
494 Tcl_Obj *visualName;
495 Tcl_Obj *useOption;
496 int i, c, depth;
497 size_t length;
498 unsigned int mask;
499 Colormap colormap;
500 Visual *visual;
501
502 if (objc < 2) {
503 Tcl_WrongNumArgs(interp, 1, objv, "pathName ?options?");
504 return TCL_ERROR;
505 }
506
507 /*
508 * Create the option table for this widget class. If it has already
509 * been created, the cached pointer will be returned.
510 */
511
512 optionTable = Tk_CreateOptionTable(interp, optionSpecs[type]);
513
514 /*
515 * Pre-process the argument list. Scan through it to find any
516 * "-class", "-screen", "-visual", and "-colormap" options. These
517 * arguments need to be processed specially, before the window
518 * is configured using the usual Tk mechanisms.
519 */
520
521 className = colormapName = screenName = NULL;
522 useOption = NULL;
523 visualName = NULL;
524 colormap = None;
525 for (i = 2; i < objc; i += 2) {
526 arg = Tcl_GetStringFromObj(objv[i], (int *) &length);
527 if (length < 2) {
528 continue;
529 }
530 c = arg[1];
531 if ((c == 'c') && (strncmp(arg, "-class", length) == 0)
532 && (length >= 3)) {
533 className = Tcl_GetString(objv[i+1]);
534 } else if ((c == 'c')
535 && (strncmp(arg, "-colormap", length) == 0)) {
536 colormapName = Tcl_GetString(objv[i+1]);
537 } else if ((c == 's') && (type == TYPE_TOPLEVEL)
538 && (strncmp(arg, "-screen", length) == 0)) {
539 screenName = Tcl_GetString(objv[i+1]);
540 } else if ((c == 'u') && (type == TYPE_TOPLEVEL)
541 && (strncmp(arg, "-use", length) == 0)) {
542 useOption = objv[i+1];
543 } else if ((c == 'v')
544 && (strncmp(arg, "-visual", length) == 0)) {
545 visualName = objv[i+1];
546 }
547 }
548
549 /*
550 * Create the window, and deal with the special options -use,
551 * -classname, -colormap, -screenname, and -visual. These options
552 * must be handle before calling ConfigureFrame below, and they must
553 * also be processed in a particular order, for the following
554 * reasons:
555 * 1. Must set the window's class before calling ConfigureFrame,
556 * so that unspecified options are looked up in the option
557 * database using the correct class.
558 * 2. Must set visual information before calling ConfigureFrame
559 * so that colors are allocated in a proper colormap.
560 * 3. Must call TkpUseWindow before setting non-default visual
561 * information, since TkpUseWindow changes the defaults.
562 */
563
564 if (screenName == NULL) {
565 screenName = (type == TYPE_TOPLEVEL) ? "" : NULL;
566 }
567
568 /*
569 * Main window associated with interpreter.
570 * If we're called by Tk_Init to create a
571 * new application, then this is NULL.
572 */
573
574 tkwin = Tk_MainWindow(interp);
575 if (tkwin != NULL) {
576 new = Tk_CreateWindowFromPath(interp, tkwin, Tcl_GetString(objv[1]),
577 screenName);
578 } else if (appName == NULL) {
579 /*
580 * This occurs when someone tried to create a frame/toplevel
581 * while we are being destroyed. Let an error be thrown.
582 */
583
584 Tcl_AppendResult(interp, "unable to create widget \"",
585 Tcl_GetString(objv[1]), "\"", (char *) NULL);
586 new = NULL;
587 } else {
588 /*
589 * We were called from Tk_Init; create a new application.
590 */
591
592 new = TkCreateMainWindow(interp, screenName, appName);
593 }
594 if (new == NULL) {
595 goto error;
596 }
597 if (className == NULL) {
598 className = Tk_GetOption(new, "class", "Class");
599 if (className == NULL) {
600 className = classNames[type];
601 }
602 }
603 Tk_SetClass(new, className);
604 if (useOption == NULL) {
605 CONST char *s = Tk_GetOption(new, "use", "Use");
606 if (s)
607 LangSetDefault(&useOption,s);
608 }
609 if (!LangNull(useOption)) {
610 if (TkpUseWindow(interp, new, useOption) != TCL_OK) {
611 goto error;
612 }
613 }
614 if (visualName == NULL) {
615 CONST char *s = Tk_GetOption(new, "visual", "Visual");
616 if (s)
617 LangSetDefault(&visualName,s);
618 }
619 if (colormapName == NULL) {
620 colormapName = Tk_GetOption(new, "colormap", "Colormap");
621 }
622 if ((colormapName != NULL) && (*colormapName == 0)) {
623 colormapName = NULL;
624 }
625 if (visualName != NULL) {
626 visual = Tk_GetVisual(interp, new, visualName, &depth,
627 (colormapName == NULL) ? &colormap : (Colormap *) NULL);
628 if (visual == NULL) {
629 goto error;
630 }
631 Tk_SetWindowVisual(new, visual, depth, colormap);
632 }
633 if (colormapName != NULL) {
634 colormap = Tk_GetColormap(interp, new, colormapName);
635 if (colormap == None) {
636 goto error;
637 }
638 Tk_SetWindowColormap(new, colormap);
639 }
640
641 /*
642 * For top-level windows, provide an initial geometry request of
643 * 200x200, just so the window looks nicer on the screen if it
644 * doesn't request a size for itself.
645 */
646
647 if (type == TYPE_TOPLEVEL) {
648 Tk_GeometryRequest(new, 200, 200);
649 }
650
651 /*
652 * Create the widget record, process configuration options, and
653 * create event handlers. Then fill in a few additional fields
654 * in the widget record from the special options.
655 */
656
657 if (type == TYPE_LABELFRAME) {
658 framePtr = (Frame *) ckalloc(sizeof(Labelframe));
659 memset((void *) framePtr, 0, (sizeof(Labelframe)));
660 } else {
661 framePtr = (Frame *) ckalloc(sizeof(Frame));
662 memset((void *) framePtr, 0, (sizeof(Frame)));
663 }
664 framePtr->tkwin = new;
665 framePtr->display = Tk_Display(new);
666 framePtr->interp = interp;
667 framePtr->widgetCmd = Tcl_CreateObjCommand(interp,
668 Tk_PathName(new), FrameWidgetObjCmd,
669 (ClientData) framePtr, FrameCmdDeletedProc);
670 framePtr->optionTable = optionTable;
671 framePtr->type = type;
672 framePtr->colormap = colormap;
673 framePtr->relief = TK_RELIEF_FLAT;
674 framePtr->cursor = None;
675
676 if (framePtr->type == TYPE_LABELFRAME) {
677 Labelframe *labelframePtr = (Labelframe *) framePtr;
678 labelframePtr->labelAnchor = LABELANCHOR_NW;
679 labelframePtr->textGC = None;
680 }
681
682 /*
683 * Store backreference to frame widget in window structure.
684 */
685 Tk_SetClassProcs(new, &frameClass, (ClientData) framePtr);
686
687 mask = ExposureMask | StructureNotifyMask | FocusChangeMask;
688 if (type == TYPE_TOPLEVEL) {
689 mask |= ActivateMask;
690 }
691 Tk_CreateEventHandler(new, mask, FrameEventProc, (ClientData) framePtr);
692 if ((Tk_InitOptions(interp, (char *) framePtr, optionTable, new)
693 != TCL_OK) ||
694 (ConfigureFrame(interp, framePtr, objc-2, objv+2) != TCL_OK)) {
695 goto error;
696 }
697 if ((framePtr->isContainer)) {
698 if (framePtr->useThis == NULL) {
699 TkpMakeContainer(framePtr->tkwin);
700 } else {
701 Tcl_AppendResult(interp, "A window cannot have both the -use ",
702 "and the -container option set.", (char *) NULL);
703 goto error;
704 }
705 }
706 if (type == TYPE_TOPLEVEL) {
707 Tcl_DoWhenIdle(MapFrame, (ClientData) framePtr);
708 }
709 Tcl_SetResult(interp, Tk_PathName(new), TCL_STATIC);
710 return TCL_OK;
711
712 error:
713 if (new != NULL) {
714 Tk_DestroyWindow(new);
715 }
716 return TCL_ERROR;
717 }
718
719 /*
720 *--------------------------------------------------------------
721 *
722 * FrameWidgetObjCmd --
723 *
724 * This procedure is invoked to process the Tcl command
725 * that corresponds to a frame widget. See the user
726 * documentation for details on what it does.
727 *
728 * Results:
729 * A standard Tcl result.
730 *
731 * Side effects:
732 * See the user documentation.
733 *
734 *--------------------------------------------------------------
735 */
736
737 static int
738 FrameWidgetObjCmd(clientData, interp, objc, objv)
739 ClientData clientData; /* Information about frame widget. */
740 Tcl_Interp *interp; /* Current interpreter. */
741 int objc; /* Number of arguments. */
742 Tcl_Obj *CONST objv[]; /* Argument objects. */
743 {
744 static CONST char *frameOptions[] = {
745 "cget", "configure", (char *) NULL
746 };
747 enum options {
748 FRAME_CGET, FRAME_CONFIGURE
749 };
750 register Frame *framePtr = (Frame *) clientData;
751 int result = TCL_OK, index;
752 size_t length;
753 int c, i;
754 Tcl_Obj *objPtr;
755
756 if (objc < 2) {
757 Tcl_WrongNumArgs(interp, 1, objv, "option ?arg arg ...?");
758 return TCL_ERROR;
759 }
760 if (Tcl_GetIndexFromObj(interp, objv[1], frameOptions, "option", 0,
761 &index) != TCL_OK) {
762 return TCL_ERROR;
763 }
764 Tcl_Preserve((ClientData) framePtr);
765 switch ((enum options) index) {
766 case FRAME_CGET: {
767 if (objc != 3) {
768 Tcl_WrongNumArgs(interp, 2, objv, "option");
769 result = TCL_ERROR;
770 goto done;
771 }
772 objPtr = Tk_GetOptionValue(interp, (char *) framePtr,
773 framePtr->optionTable, objv[2], framePtr->tkwin);
774 if (objPtr == NULL) {
775 result = TCL_ERROR;
776 goto done;
777 } else {
778 Tcl_SetObjResult(interp, objPtr);
779 }
780 break;
781 }
782 case FRAME_CONFIGURE: {
783 if (objc <= 3) {
784 objPtr = Tk_GetOptionInfo(interp, (char *) framePtr,
785 framePtr->optionTable,
786 (objc == 3) ? objv[2] : (Tcl_Obj *) NULL,
787 framePtr->tkwin);
788 if (objPtr == NULL) {
789 result = TCL_ERROR;
790 goto done;
791 } else {
792 Tcl_SetObjResult(interp, objPtr);
793 }
794 } else {
795 /*
796 * Don't allow the options -class, -colormap, -container,
797 * -newcmap, -screen, -use, or -visual to be changed.
798 */
799
800 for (i = 2; i < objc; i++) {
801 char *arg = Tcl_GetStringFromObj(objv[i], (int *) &length);
802 if (length < 2) {
803 continue;
804 }
805 c = arg[1];
806 if (((c == 'c') && (strncmp(arg, "-class", length) == 0)
807 && (length >= 2))
808 || ((c == 'c')
809 && (strncmp(arg, "-colormap", length) == 0)
810 && (length >= 3))
811 || ((c == 'c')
812 && (strncmp(arg, "-container", length) == 0)
813 && (length >= 3))
814 || ((c == 's') && (framePtr->type == TYPE_TOPLEVEL)
815 && (strncmp(arg, "-screen", length) == 0))
816 || ((c == 'u') && (framePtr->type == TYPE_TOPLEVEL)
817 && (strncmp(arg, "-use", length) == 0))
818 || ((c == 'v')
819 && (strncmp(arg, "-visual", length) == 0))) {
820 Tcl_AppendResult(interp, "can't modify ", arg,
821 " option after widget is created", (char *) NULL);
822 result = TCL_ERROR;
823 goto done;
824 }
825 }
826 result = ConfigureFrame(interp, framePtr, objc-2, objv+2);
827 }
828 break;
829 }
830 }
831
832 done:
833 Tcl_Release((ClientData) framePtr);
834 return result;
835 }
836
837 /*
838 *----------------------------------------------------------------------
839 *
840 * DestroyFrame --
841 *
842 * This procedure is invoked by Tcl_EventuallyFree or Tcl_Release
843 * to clean up the internal structure of a frame at a safe time
844 * (when no-one is using it anymore).
845 *
846 * Results:
847 * None.
848 *
849 * Side effects:
850 * Everything associated with the frame is freed up.
851 *
852 *----------------------------------------------------------------------
853 */
854
855 static void
856 DestroyFrame(memPtr)
857 char *memPtr; /* Info about frame widget. */
858 {
859 register Frame *framePtr = (Frame *) memPtr;
860 register Labelframe *labelframePtr = (Labelframe *) memPtr;
861
862 if (framePtr->type == TYPE_LABELFRAME) {
863 Tk_FreeTextLayout(labelframePtr->textLayout);
864 if (labelframePtr->textGC != None) {
865 Tk_FreeGC(framePtr->display, labelframePtr->textGC);
866 }
867 }
868 if (framePtr->colormap != None) {
869 Tk_FreeColormap(framePtr->display, framePtr->colormap);
870 }
871 ckfree((char *) framePtr);
872 }
873
874 /*
875 *----------------------------------------------------------------------
876 *
877 * DestroyFramePartly --
878 *
879 * This procedure is invoked to clean up everything that needs
880 * tkwin to be defined when deleted. During the destruction
881 * process tkwin is always set to NULL and this procedure must
882 * be called before that happens.
883 *
884 * Results:
885 * None.
886 *
887 * Side effects:
888 * Some things associated with the frame are freed up.
889 *
890 *----------------------------------------------------------------------
891 */
892
893 static void
894 DestroyFramePartly(framePtr)
895 Frame *framePtr; /* Info about frame widget. */
896 {
897 register Labelframe *labelframePtr = (Labelframe *) framePtr;
898
899 if (framePtr->type == TYPE_LABELFRAME && labelframePtr->labelWin != NULL) {
900 Tk_DeleteEventHandler(labelframePtr->labelWin, StructureNotifyMask,
901 FrameStructureProc, (ClientData) framePtr);
902 Tk_ManageGeometry(labelframePtr->labelWin, (Tk_GeomMgr *) NULL,
903 (ClientData) NULL);
904 if (framePtr->tkwin != Tk_Parent(labelframePtr->labelWin)) {
905 Tk_UnmaintainGeometry(labelframePtr->labelWin, framePtr->tkwin);
906 }
907 Tk_UnmapWindow(labelframePtr->labelWin);
908 labelframePtr->labelWin = NULL;
909 }
910
911 Tk_FreeConfigOptions((char *) framePtr, framePtr->optionTable,
912 framePtr->tkwin);
913 }
914
915 /*
916 *----------------------------------------------------------------------
917 *
918 * ConfigureFrame --
919 *
920 * This procedure is called to process an objv/objc list, plus
921 * the Tk option database, in order to configure (or
922 * reconfigure) a frame widget.
923 *
924 * Results:
925 * The return value is a standard Tcl result. If TCL_ERROR is
926 * returned, then the interp's result contains an error message.
927 *
928 * Side effects:
929 * Configuration information, such as text string, colors, font,
930 * etc. get set for framePtr; old resources get freed, if there
931 * were any.
932 *
933 *----------------------------------------------------------------------
934 */
935
936 static int
937 ConfigureFrame(interp, framePtr, objc, objv)
938 Tcl_Interp *interp; /* Used for error reporting. */
939 register Frame *framePtr; /* Information about widget; may or may
940 * not already have values for some fields. */
941 int objc; /* Number of valid entries in objv. */
942 Tcl_Obj *CONST objv[]; /* Arguments. */
943 {
944 Tk_SavedOptions savedOptions;
945 Tcl_Obj *oldMenuName;
946 Tk_Window oldWindow = NULL;
947 Labelframe *labelframePtr = (Labelframe *) framePtr;
948
949 /*
950 * Need the old menubar name for the menu code to delete it.
951 */
952
953 if (framePtr->menuName == NULL) {
954 oldMenuName = NULL;
955 } else {
956 oldMenuName = LangCopyArg(framePtr->menuName);
957 }
958
959 if (framePtr->type == TYPE_LABELFRAME) {
960 oldWindow = labelframePtr->labelWin;
961 }
962 if (Tk_SetOptions(interp, (char *) framePtr,
963 framePtr->optionTable, objc, objv,
964 framePtr->tkwin, &savedOptions, (int *) NULL) != TCL_OK) {
965 if (oldMenuName != NULL) {
966 #ifndef _LANG
967 ckfree(oldMenuName);
968 #else
969 LangFreeArg(oldMenuName,TCL_DYNAMIC);
970 #endif
971 }
972 return TCL_ERROR;
973 } else {
974 Tk_FreeSavedOptions(&savedOptions);
975 }
976
977 /*
978 * A few of the options require additional processing.
979 */
980
981 if (((oldMenuName == NULL) && (framePtr->menuName != NULL))
982 || ((oldMenuName != NULL) && (framePtr->menuName == NULL))
983 || ((oldMenuName != NULL) && (framePtr->menuName != NULL)
984 && oldMenuName != framePtr->menuName
985 && strcmp(Tcl_GetString(oldMenuName), Tcl_GetString(framePtr->menuName)) != 0)) {
986 TkSetWindowMenuBar(interp, framePtr->tkwin, oldMenuName,
987 framePtr->menuName);
988 }
989
990 #ifndef _LANG
991 if (oldMenuName != NULL) {
992 ckfree(oldMenuName);
993 }
994 #endif
995
996 if (framePtr->border != NULL) {
997 Tk_SetBackgroundFromBorder(framePtr->tkwin, framePtr->border);
998 } else {
999 Tk_SetWindowBackgroundPixmap(framePtr->tkwin, None);
1000 }
1001
1002 if (framePtr->highlightWidth < 0) {
1003 framePtr->highlightWidth = 0;
1004 }
1005 if (framePtr->padX < 0) {
1006 framePtr->padX = 0;
1007 }
1008 if (framePtr->padY < 0) {
1009 framePtr->padY = 0;
1010 }
1011
1012 /*
1013 * If a -labelwidget is specified, check that it is valid and set
1014 * up geometry management for it.
1015 */
1016
1017 if (framePtr->type == TYPE_LABELFRAME) {
1018 if (oldWindow != labelframePtr->labelWin) {
1019 if (oldWindow != NULL) {
1020 Tk_DeleteEventHandler(oldWindow, StructureNotifyMask,
1021 FrameStructureProc, (ClientData) framePtr);
1022 Tk_ManageGeometry(oldWindow, (Tk_GeomMgr *) NULL,
1023 (ClientData) NULL);
1024 Tk_UnmaintainGeometry(oldWindow, framePtr->tkwin);
1025 Tk_UnmapWindow(oldWindow);
1026 }
1027 if (labelframePtr->labelWin != NULL) {
1028 Tk_Window ancestor, parent, sibling = NULL;
1029
1030 /*
1031 * Make sure that the frame is either the parent of the
1032 * window used as label or a descendant of that
1033 * parent. Also, don't allow a top-level window to be
1034 * managed inside the frame.
1035 */
1036
1037 parent = Tk_Parent(labelframePtr->labelWin);
1038 for (ancestor = framePtr->tkwin; ;
1039 ancestor = Tk_Parent(ancestor)) {
1040 if (ancestor == parent) {
1041 break;
1042 }
1043 sibling = ancestor;
1044 if (Tk_IsTopLevel(ancestor)) {
1045 badWindow:
1046 Tcl_AppendResult(interp, "can't use ",
1047 Tk_PathName(labelframePtr->labelWin),
1048 " as label in this frame", (char *) NULL);
1049 labelframePtr->labelWin = NULL;
1050 return TCL_ERROR;
1051 }
1052 }
1053 if (Tk_IsTopLevel(labelframePtr->labelWin)) {
1054 goto badWindow;
1055 }
1056 if (labelframePtr->labelWin == framePtr->tkwin) {
1057 goto badWindow;
1058 }
1059 Tk_CreateEventHandler(labelframePtr->labelWin,
1060 StructureNotifyMask, FrameStructureProc,
1061 (ClientData) framePtr);
1062 Tk_ManageGeometry(labelframePtr->labelWin, &frameGeomType,
1063 (ClientData) framePtr);
1064
1065 /*
1066 * If the frame is not parent to the label, make
1067 * sure the label is above its sibling in the stacking
1068 * order.
1069 */
1070
1071 if (sibling != NULL) {
1072 Tk_RestackWindow(labelframePtr->labelWin, Above, sibling);
1073 }
1074 }
1075 }
1076 }
1077
1078 FrameWorldChanged((ClientData) framePtr);
1079
1080 return TCL_OK;
1081 }
1082
1083 /*
1084 *---------------------------------------------------------------------------
1085 *
1086 * FrameWorldChanged --
1087 *
1088 * This procedure is called when the world has changed in some
1089 * way and the widget needs to recompute all its graphics contexts
1090 * and determine its new geometry.
1091 *
1092 * Results:
1093 * None.
1094 *
1095 * Side effects:
1096 * Frame will be relayed out and redisplayed.
1097 *
1098 *---------------------------------------------------------------------------
1099 */
1100
1101 static void
1102 FrameWorldChanged(instanceData)
1103 ClientData instanceData; /* Information about widget. */
1104 {
1105 Frame *framePtr = (Frame *) instanceData;
1106 Labelframe *labelframePtr = (Labelframe *) framePtr;
1107 Tk_Window tkwin = framePtr->tkwin;
1108 XGCValues gcValues;
1109 GC gc;
1110 int anyTextLabel, anyWindowLabel;
1111 int bWidthLeft, bWidthRight, bWidthTop, bWidthBottom;
1112 char *labelText;
1113
1114 anyTextLabel = (framePtr->type == TYPE_LABELFRAME) &&
1115 (labelframePtr->textPtr != NULL) &&
1116 (labelframePtr->labelWin == NULL);
1117 anyWindowLabel = (framePtr->type == TYPE_LABELFRAME) &&
1118 (labelframePtr->labelWin != NULL);
1119
1120 if (framePtr->type == TYPE_LABELFRAME) {
1121 /*
1122 * The textGC is needed even in the labelWin case, so it's
1123 * always created for a labelframe.
1124 */
1125
1126 gcValues.font = Tk_FontId(labelframePtr->tkfont);
1127 gcValues.foreground = labelframePtr->textColorPtr->pixel;
1128 gcValues.graphics_exposures = False;
1129 gc = Tk_GetGC(tkwin, GCForeground | GCFont | GCGraphicsExposures,
1130 &gcValues);
1131 if (labelframePtr->textGC != None) {
1132 Tk_FreeGC(framePtr->display, labelframePtr->textGC);
1133 }
1134 labelframePtr->textGC = gc;
1135
1136 /*
1137 * Calculate label size.
1138 */
1139
1140 labelframePtr->labelReqWidth = labelframePtr->labelReqHeight = 0;
1141
1142 if (anyTextLabel) {
1143 labelText = Tcl_GetString(labelframePtr->textPtr);
1144 Tk_FreeTextLayout(labelframePtr->textLayout);
1145 labelframePtr->textLayout = Tk_ComputeTextLayout(labelframePtr->tkfont,
1146 labelText, -1, 0, TK_JUSTIFY_CENTER, 0,
1147 &labelframePtr->labelReqWidth, &labelframePtr->labelReqHeight);
1148 labelframePtr->labelReqWidth += 2 * LABELSPACING;
1149 labelframePtr->labelReqHeight += 2 * LABELSPACING;
1150 } else if (anyWindowLabel) {
1151 labelframePtr->labelReqWidth = Tk_ReqWidth(labelframePtr->labelWin);
1152 labelframePtr->labelReqHeight = Tk_ReqHeight(labelframePtr->labelWin);
1153 }
1154
1155 /*
1156 * Make sure label size is at least as big as the border.
1157 * This simplifies later calculations and gives a better
1158 * appearance with thick borders.
1159 */
1160
1161 if ((labelframePtr->labelAnchor >= LABELANCHOR_N) &&
1162 (labelframePtr->labelAnchor <= LABELANCHOR_SW)) {
1163 if (labelframePtr->labelReqHeight < framePtr->borderWidth) {
1164 labelframePtr->labelReqHeight = framePtr->borderWidth;
1165 }
1166 } else {
1167 if (labelframePtr->labelReqWidth < framePtr->borderWidth) {
1168 labelframePtr->labelReqWidth = framePtr->borderWidth;
1169 }
1170 }
1171 }
1172
1173 /*
1174 * Calculate individual border widths.
1175 */
1176
1177 bWidthBottom = bWidthTop = bWidthRight = bWidthLeft =
1178 framePtr->borderWidth + framePtr->highlightWidth;
1179
1180 bWidthLeft += framePtr->padX;
1181 bWidthRight += framePtr->padX;
1182 bWidthTop += framePtr->padY;
1183 bWidthBottom += framePtr->padY;
1184
1185 if (anyTextLabel || anyWindowLabel) {
1186 switch (labelframePtr->labelAnchor) {
1187 case LABELANCHOR_E:
1188 case LABELANCHOR_EN:
1189 case LABELANCHOR_ES:
1190 bWidthRight += labelframePtr->labelReqWidth -
1191 framePtr->borderWidth;
1192 break;
1193 case LABELANCHOR_N:
1194 case LABELANCHOR_NE:
1195 case LABELANCHOR_NW:
1196 bWidthTop += labelframePtr->labelReqHeight - framePtr->borderWidth;
1197 break;
1198 case LABELANCHOR_S:
1199 case LABELANCHOR_SE:
1200 case LABELANCHOR_SW:
1201 bWidthBottom += labelframePtr->labelReqHeight -
1202 framePtr->borderWidth;
1203 break;
1204 default:
1205 bWidthLeft += labelframePtr->labelReqWidth - framePtr->borderWidth;
1206 break;
1207 }
1208 }
1209
1210 Tk_SetInternalBorderEx(tkwin, bWidthLeft, bWidthRight, bWidthTop,
1211 bWidthBottom);
1212
1213 ComputeFrameGeometry(framePtr);
1214
1215 /*
1216 * A labelframe should request size for its label.
1217 */
1218
1219 if (framePtr->type == TYPE_LABELFRAME) {
1220 int minwidth = labelframePtr->labelReqWidth;
1221 int minheight = labelframePtr->labelReqHeight;
1222 int padding = framePtr->highlightWidth;
1223 if (framePtr->borderWidth > 0) {
1224 padding += framePtr->borderWidth + LABELMARGIN;
1225 }
1226 padding *= 2;
1227 if ((labelframePtr->labelAnchor >= LABELANCHOR_N) &&
1228 (labelframePtr->labelAnchor <= LABELANCHOR_SW)) {
1229 minwidth += padding;
1230 minheight += framePtr->borderWidth + framePtr->highlightWidth;
1231 } else {
1232 minheight += padding;
1233 minwidth += framePtr->borderWidth + framePtr->highlightWidth;
1234 }
1235 Tk_SetMinimumRequestSize(tkwin, minwidth, minheight);
1236 }
1237
1238 if ((framePtr->width > 0) || (framePtr->height > 0)) {
1239 Tk_GeometryRequest(tkwin, framePtr->width, framePtr->height);
1240 }
1241
1242 if (Tk_IsMapped(tkwin)) {
1243 if (!(framePtr->flags & REDRAW_PENDING)) {
1244 Tcl_DoWhenIdle(DisplayFrame, (ClientData) framePtr);
1245 }
1246 framePtr->flags |= REDRAW_PENDING;
1247 }
1248 }
1249
1250 /*
1251 *----------------------------------------------------------------------
1252 *
1253 * ComputeFrameGeometry --
1254 *
1255 * This procedure is called to compute various geometrical
1256 * information for a frame, such as where various things get
1257 * displayed. It's called when the window is reconfigured.
1258 *
1259 * Results:
1260 * None.
1261 *
1262 * Side effects:
1263 * Display-related numbers get changed in *framePtr.
1264 *
1265 *----------------------------------------------------------------------
1266 */
1267
1268 static void
1269 ComputeFrameGeometry(framePtr)
1270 register Frame *framePtr; /* Information about widget. */
1271 {
1272 int otherWidth, otherHeight, otherWidthT, otherHeightT, padding;
1273 int maxWidth, maxHeight;
1274 Tk_Window tkwin;
1275 Labelframe *labelframePtr = (Labelframe *) framePtr;
1276
1277 /*
1278 * We have nothing to do here unless there is a label.
1279 */
1280
1281 if (framePtr->type != TYPE_LABELFRAME) return;
1282 if ((labelframePtr->textPtr == NULL) &&
1283 (labelframePtr->labelWin == NULL)) return;
1284
1285 tkwin = framePtr->tkwin;
1286
1287 /*
1288 * Calculate the available size for the label
1289 */
1290
1291 labelframePtr->labelBox.width = labelframePtr->labelReqWidth;
1292 labelframePtr->labelBox.height = labelframePtr->labelReqHeight;
1293
1294 padding = framePtr->highlightWidth;
1295 if (framePtr->borderWidth > 0) {
1296 padding += framePtr->borderWidth + LABELMARGIN;
1297 }
1298 padding *= 2;
1299
1300 maxHeight = Tk_Height(tkwin);
1301 maxWidth = Tk_Width(tkwin);
1302
1303 if ((labelframePtr->labelAnchor >= LABELANCHOR_N) &&
1304 (labelframePtr->labelAnchor <= LABELANCHOR_SW)) {
1305 maxWidth -= padding;
1306 if (maxWidth < 1) maxWidth = 1;
1307 } else {
1308 maxHeight -= padding;
1309 if (maxHeight < 1) maxHeight = 1;
1310 }
1311 if (labelframePtr->labelBox.width > maxWidth) {
1312 labelframePtr->labelBox.width = maxWidth;
1313 }
1314 if (labelframePtr->labelBox.height > maxHeight) {
1315 labelframePtr->labelBox.height = maxHeight;
1316 }
1317
1318 /*
1319 * Calculate label and text position.
1320 * The text's position is based on the requested size (= the text's
1321 * real size) to get proper alignment if the text does not fit.
1322 */
1323
1324 otherWidth = Tk_Width(tkwin) - labelframePtr->labelBox.width;
1325 otherHeight = Tk_Height(tkwin) - labelframePtr->labelBox.height;
1326 otherWidthT = Tk_Width(tkwin) - labelframePtr->labelReqWidth;
1327 otherHeightT = Tk_Height(tkwin) - labelframePtr->labelReqHeight;
1328 padding = framePtr->highlightWidth;
1329
1330 switch (labelframePtr->labelAnchor) {
1331 case LABELANCHOR_E:
1332 case LABELANCHOR_EN:
1333 case LABELANCHOR_ES:
1334 labelframePtr->labelTextX = otherWidthT - padding;
1335 labelframePtr->labelBox.x = otherWidth - padding;
1336 break;
1337 case LABELANCHOR_N:
1338 case LABELANCHOR_NE:
1339 case LABELANCHOR_NW:
1340 labelframePtr->labelTextY = padding;
1341 labelframePtr->labelBox.y = padding;
1342 break;
1343 case LABELANCHOR_S:
1344 case LABELANCHOR_SE:
1345 case LABELANCHOR_SW:
1346 labelframePtr->labelTextY = otherHeightT - padding;
1347 labelframePtr->labelBox.y = otherHeight - padding;
1348 break;
1349 default:
1350 labelframePtr->labelTextX = padding;
1351 labelframePtr->labelBox.x = padding;
1352 break;
1353 }
1354
1355 if (framePtr->borderWidth > 0) {
1356 padding += framePtr->borderWidth + LABELMARGIN;
1357 }
1358
1359 switch (labelframePtr->labelAnchor) {
1360 case LABELANCHOR_NW:
1361 case LABELANCHOR_SW:
1362 labelframePtr->labelTextX = padding;
1363 labelframePtr->labelBox.x = padding;
1364 break;
1365 case LABELANCHOR_N:
1366 case LABELANCHOR_S:
1367 labelframePtr->labelTextX = otherWidthT / 2;
1368 labelframePtr->labelBox.x = otherWidth / 2;
1369 break;
1370 case LABELANCHOR_NE:
1371 case LABELANCHOR_SE:
1372 labelframePtr->labelTextX = otherWidthT - padding;
1373 labelframePtr->labelBox.x = otherWidth - padding;
1374 break;
1375 case LABELANCHOR_EN:
1376 case LABELANCHOR_WN:
1377 labelframePtr->labelTextY = padding;
1378 labelframePtr->labelBox.y = padding;
1379 break;
1380 case LABELANCHOR_E:
1381 case LABELANCHOR_W:
1382 labelframePtr->labelTextY = otherHeightT / 2;
1383 labelframePtr->labelBox.y = otherHeight / 2;
1384 break;
1385 default:
1386 labelframePtr->labelTextY = otherHeightT - padding;
1387 labelframePtr->labelBox.y = otherHeight - padding;
1388 break;
1389 }
1390 }
1391
1392 /*
1393 *----------------------------------------------------------------------
1394 *
1395 * DisplayFrame --
1396 *
1397 * This procedure is invoked to display a frame widget.
1398 *
1399 * Results:
1400 * None.
1401 *
1402 * Side effects:
1403 * Commands are output to X to display the frame in its
1404 * current mode.
1405 *
1406 *----------------------------------------------------------------------
1407 */
1408
1409 static void
1410 DisplayFrame(clientData)
1411 ClientData clientData; /* Information about widget. */
1412 {
1413 register Frame *framePtr = (Frame *) clientData;
1414 register Tk_Window tkwin = framePtr->tkwin;
1415 int bdX1, bdY1, bdX2, bdY2, hlWidth;
1416 Pixmap pixmap;
1417 TkRegion clipRegion = NULL;
1418
1419 framePtr->flags &= ~REDRAW_PENDING;
1420 /* FIXME: do we get here ? */
1421 if ((framePtr->tkwin == NULL) || !Tk_IsMapped(tkwin)
1422 || framePtr->isContainer) {
1423 return;
1424 }
1425
1426 /*
1427 * Highlight shall always be drawn if it exists, so do that first.
1428 */
1429
1430 hlWidth = framePtr->highlightWidth;
1431
1432 if (hlWidth != 0) {
1433 GC fgGC, bgGC;
1434
1435 bgGC = Tk_GCForColor(framePtr->highlightBgColorPtr,
1436 Tk_WindowId(tkwin));
1437 if (framePtr->flags & GOT_FOCUS) {
1438 fgGC = Tk_GCForColor(framePtr->highlightColorPtr,
1439 Tk_WindowId(tkwin));
1440 TkpDrawHighlightBorder(tkwin, fgGC, bgGC, hlWidth,
1441 Tk_WindowId(tkwin));
1442 } else {
1443 TkpDrawHighlightBorder(tkwin, bgGC, bgGC, hlWidth,
1444 Tk_WindowId(tkwin));
1445 }
1446 }
1447
1448 /*
1449 * If -background is set to "", no interior is drawn.
1450 */
1451
1452 if (framePtr->border == NULL) return;
1453
1454 if (framePtr->type != TYPE_LABELFRAME) {
1455 /*
1456 * There is no label so there is just a simple rectangle to draw.
1457 */
1458
1459 noLabel:
1460 Tk_Fill3DRectangle(tkwin, Tk_WindowId(tkwin),
1461 framePtr->border, hlWidth, hlWidth,
1462 Tk_Width(tkwin) - 2 * hlWidth,
1463 Tk_Height(tkwin) - 2 * hlWidth,
1464 framePtr->borderWidth, framePtr->relief);
1465 } else {
1466 Labelframe *labelframePtr = (Labelframe *) framePtr;
1467
1468 if ((labelframePtr->textPtr == NULL) &&
1469 (labelframePtr->labelWin == NULL)) {
1470 goto noLabel;
1471 }
1472
1473 /*
1474 * In order to avoid screen flashes, this procedure redraws the
1475 * frame into off-screen memory, then copies it back on-screen
1476 * in a single operation. This means there's no point in time
1477 * where the on-screen image has been cleared.
1478 */
1479
1480 pixmap = Tk_GetPixmap(framePtr->display, Tk_WindowId(tkwin),
1481 Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin));
1482
1483 /*
1484 * Clear the pixmap.
1485 */
1486
1487 Tk_Fill3DRectangle(tkwin, pixmap, framePtr->border, 0, 0,
1488 Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
1489
1490 /*
1491 * Calculate how the label affects the border's position.
1492 */
1493
1494 bdX1 = bdY1 = hlWidth;
1495 bdX2 = Tk_Width(tkwin) - hlWidth;
1496 bdY2 = Tk_Height(tkwin) - hlWidth;
1497
1498 switch (labelframePtr->labelAnchor) {
1499 case LABELANCHOR_E:
1500 case LABELANCHOR_EN:
1501 case LABELANCHOR_ES:
1502 bdX2 -= (labelframePtr->labelBox.width - framePtr->borderWidth)
1503 / 2;
1504 break;
1505 case LABELANCHOR_N:
1506 case LABELANCHOR_NE:
1507 case LABELANCHOR_NW:
1508 /*
1509 * Since the glyphs of the text tend to be in the lower part
1510 * we favor a lower border position by rounding up.
1511 */
1512
1513 bdY1 += (labelframePtr->labelBox.height - framePtr->borderWidth +1)
1514 / 2;
1515 break;
1516 case LABELANCHOR_S:
1517 case LABELANCHOR_SE:
1518 case LABELANCHOR_SW:
1519 bdY2 -= (labelframePtr->labelBox.height - framePtr->borderWidth)
1520 / 2;
1521 break;
1522 default:
1523 bdX1 += (labelframePtr->labelBox.width - framePtr->borderWidth)
1524 / 2;
1525 break;
1526 }
1527
1528 /*
1529 * Draw border
1530 */
1531
1532 Tk_Draw3DRectangle(tkwin, pixmap, framePtr->border, bdX1, bdY1,
1533 bdX2 - bdX1, bdY2 - bdY1, framePtr->borderWidth,
1534 framePtr->relief);
1535
1536 if (labelframePtr->labelWin == NULL) {
1537 /*
1538 * Clear behind the label
1539 */
1540
1541 Tk_Fill3DRectangle(tkwin, pixmap,
1542 framePtr->border, labelframePtr->labelBox.x,
1543 labelframePtr->labelBox.y, labelframePtr->labelBox.width,
1544 labelframePtr->labelBox.height, 0, TK_RELIEF_FLAT);
1545
1546 /*
1547 * Draw label.
1548 * If there is not room for the entire label, use clipping to
1549 * get a nice appearance.
1550 */
1551
1552 if ((labelframePtr->labelBox.width < labelframePtr->labelReqWidth)
1553 || (labelframePtr->labelBox.height <
1554 labelframePtr->labelReqHeight)) {
1555 clipRegion = TkCreateRegion();
1556 TkUnionRectWithRegion(&labelframePtr->labelBox, clipRegion,
1557 clipRegion);
1558 TkSetRegion(framePtr->display, labelframePtr->textGC,
1559 clipRegion);
1560 }
1561
1562 Tk_DrawTextLayout(framePtr->display, pixmap,
1563 labelframePtr->textGC, labelframePtr->textLayout,
1564 labelframePtr->labelTextX + LABELSPACING,
1565 labelframePtr->labelTextY + LABELSPACING, 0, -1);
1566
1567 if (clipRegion != NULL) {
1568 XSetClipMask(framePtr->display, labelframePtr->textGC, None);
1569 TkDestroyRegion(clipRegion);
1570 }
1571 } else {
1572 /*
1573 * Reposition and map the window (but in different ways depending
1574 * on whether the frame is the window's parent).
1575 */
1576
1577 if (framePtr->tkwin == Tk_Parent(labelframePtr->labelWin)) {
1578 if ((labelframePtr->labelBox.x != Tk_X(labelframePtr->labelWin))
1579 || (labelframePtr->labelBox.y !=
1580 Tk_Y(labelframePtr->labelWin))
1581 || (labelframePtr->labelBox.width !=
1582 Tk_Width(labelframePtr->labelWin))
1583 || (labelframePtr->labelBox.height !=
1584 Tk_Height(labelframePtr->labelWin))) {
1585 Tk_MoveResizeWindow(labelframePtr->labelWin,
1586 labelframePtr->labelBox.x, labelframePtr->labelBox.y,
1587 labelframePtr->labelBox.width,
1588 labelframePtr->labelBox.height);
1589 }
1590 Tk_MapWindow(labelframePtr->labelWin);
1591 } else {
1592 Tk_MaintainGeometry(labelframePtr->labelWin, framePtr->tkwin,
1593 labelframePtr->labelBox.x, labelframePtr->labelBox.y,
1594 labelframePtr->labelBox.width,
1595 labelframePtr->labelBox.height);
1596 }
1597 }
1598
1599
1600 /*
1601 * Everything's been redisplayed; now copy the pixmap onto the screen
1602 * and free up the pixmap.
1603 */
1604
1605 XCopyArea(framePtr->display, pixmap, Tk_WindowId(tkwin),
1606 labelframePtr->textGC, hlWidth, hlWidth,
1607 (unsigned) (Tk_Width(tkwin) - 2 * hlWidth),
1608 (unsigned) (Tk_Height(tkwin) - 2 * hlWidth),
1609 hlWidth, hlWidth);
1610 Tk_FreePixmap(framePtr->display, pixmap);
1611 }
1612
1613 }
1614
1615 /*
1616 *--------------------------------------------------------------
1617 *
1618 * FrameEventProc --
1619 *
1620 * This procedure is invoked by the Tk dispatcher on
1621 * structure changes to a frame. For frames with 3D
1622 * borders, this procedure is also invoked for exposures.
1623 *
1624 * Results:
1625 * None.
1626 *
1627 * Side effects:
1628 * When the window gets deleted, internal structures get
1629 * cleaned up. When it gets exposed, it is redisplayed.
1630 *
1631 *--------------------------------------------------------------
1632 */
1633
1634 static void
1635 FrameEventProc(clientData, eventPtr)
1636 ClientData clientData; /* Information about window. */
1637 register XEvent *eventPtr; /* Information about event. */
1638 {
1639 register Frame *framePtr = (Frame *) clientData;
1640
1641 if ((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0)) {
1642 goto redraw;
1643 } else if (eventPtr->type == ConfigureNotify) {
1644 ComputeFrameGeometry(framePtr);
1645 goto redraw;
1646 } else if (eventPtr->type == DestroyNotify) {
1647 if (framePtr->menuName != NULL) {
1648 TkSetWindowMenuBar(framePtr->interp, framePtr->tkwin,
1649 framePtr->menuName, NULL);
1650 LangFreeArg(framePtr->menuName,TCL_DYNAMIC);
1651 framePtr->menuName = NULL;
1652 }
1653 if (framePtr->tkwin != NULL) {
1654
1655 /*
1656 * If this window is a container, then this event could be
1657 * coming from the embedded application, in which case
1658 * Tk_DestroyWindow hasn't been called yet. When Tk_DestroyWindow
1659 * is called later, then another destroy event will be generated.
1660 * We need to be sure we ignore the second event, since the frame
1661 * could be gone by then. To do so, delete the event handler
1662 * explicitly (normally it's done implicitly by Tk_DestroyWindow).
1663 */
1664
1665 /*
1666 * Since the tkwin pointer will be gone when we reach
1667 * DestroyFrame, we must free all options now.
1668 */
1669
1670 DestroyFramePartly(framePtr);
1671
1672 Tk_DeleteEventHandler(framePtr->tkwin,
1673 ExposureMask|StructureNotifyMask|FocusChangeMask,
1674 FrameEventProc, (ClientData) framePtr);
1675 framePtr->tkwin = NULL;
1676 Tcl_DeleteCommandFromToken(framePtr->interp, framePtr->widgetCmd);
1677 }
1678 if (framePtr->flags & REDRAW_PENDING) {
1679 Tcl_CancelIdleCall(DisplayFrame, (ClientData) framePtr);
1680 }
1681 Tcl_CancelIdleCall(MapFrame, (ClientData) framePtr);
1682 Tcl_EventuallyFree((ClientData) framePtr, DestroyFrame);
1683 } else if (eventPtr->type == FocusIn) {
1684 if (eventPtr->xfocus.detail != NotifyInferior) {
1685 framePtr->flags |= GOT_FOCUS;
1686 if (framePtr->highlightWidth > 0) {
1687 goto redraw;
1688 }
1689 }
1690 } else if (eventPtr->type == FocusOut) {
1691 if (eventPtr->xfocus.detail != NotifyInferior) {
1692 framePtr->flags &= ~GOT_FOCUS;
1693 if (framePtr->highlightWidth > 0) {
1694 goto redraw;
1695 }
1696 }
1697 } else if (eventPtr->type == ActivateNotify) {
1698 TkpSetMainMenubar(framePtr->interp, framePtr->tkwin,
1699 Tcl_GetString(framePtr->menuName));
1700 }
1701 return;
1702
1703 redraw:
1704 if ((framePtr->tkwin != NULL) && !(framePtr->flags & REDRAW_PENDING)) {
1705 Tcl_DoWhenIdle(DisplayFrame, (ClientData) framePtr);
1706 framePtr->flags |= REDRAW_PENDING;
1707 }
1708 }
1709
1710 /*
1711 *----------------------------------------------------------------------
1712 *
1713 * FrameCmdDeletedProc --
1714 *
1715 * This procedure is invoked when a widget command is deleted. If
1716 * the widget isn't already in the process of being destroyed,
1717 * this command destroys it.
1718 *
1719 * Results:
1720 * None.
1721 *
1722 * Side effects:
1723 * The widget is destroyed.
1724 *
1725 *----------------------------------------------------------------------
1726 */
1727
1728 static void
1729 FrameCmdDeletedProc(clientData)
1730 ClientData clientData; /* Pointer to widget record for widget. */
1731 {
1732 Frame *framePtr = (Frame *) clientData;
1733 Tk_Window tkwin = framePtr->tkwin;
1734
1735 if (framePtr->menuName != NULL) {
1736 TkSetWindowMenuBar(framePtr->interp, framePtr->tkwin,
1737 framePtr->menuName, NULL);
1738 LangFreeArg(framePtr->menuName,TCL_DYNAMIC);
1739 framePtr->menuName = NULL;
1740 }
1741
1742 /*
1743 * This procedure could be invoked either because the window was
1744 * destroyed and the command was then deleted (in which case tkwin
1745 * is NULL) or because the command was deleted, and then this procedure
1746 * destroys the widget.
1747 */
1748
1749 if (tkwin != NULL) {
1750 /*
1751 * Some options need tkwin to be freed, so we free them here,
1752 * before setting tkwin to NULL.
1753 */
1754
1755 DestroyFramePartly(framePtr);
1756
1757 framePtr->tkwin = NULL;
1758 Tk_DestroyWindow(tkwin);
1759 }
1760 }
1761
1762 /*
1763 *----------------------------------------------------------------------
1764 *
1765 * MapFrame --
1766 *
1767 * This procedure is invoked as a when-idle handler to map a
1768 * newly-created top-level frame.
1769 *
1770 * Results:
1771 * None.
1772 *
1773 * Side effects:
1774 * The frame given by the clientData argument is mapped.
1775 *
1776 *----------------------------------------------------------------------
1777 */
1778
1779 static void
1780 MapFrame(clientData)
1781 ClientData clientData; /* Pointer to frame structure. */
1782 {
1783 Frame *framePtr = (Frame *) clientData;
1784
1785 /*
1786 * Wait for all other background events to be processed before
1787 * mapping window. This ensures that the window's correct geometry
1788 * will have been determined before it is first mapped, so that the
1789 * window manager doesn't get a false idea of its desired geometry.
1790 */
1791
1792 Tcl_Preserve((ClientData) framePtr);
1793 while (1) {
1794 if (Tcl_DoOneEvent(TCL_IDLE_EVENTS) == 0) {
1795 break;
1796 }
1797
1798 /*
1799 * After each event, make sure that the window still exists
1800 * and quit if the window has been destroyed.
1801 */
1802
1803 if (framePtr->tkwin == NULL) {
1804 Tcl_Release((ClientData) framePtr);
1805 return;
1806 }
1807 }
1808 Tk_MapWindow(framePtr->tkwin);
1809 Tcl_Release((ClientData) framePtr);
1810 }
1811
1812 /*
1813 *--------------------------------------------------------------
1814 *
1815 * TkInstallFrameMenu --
1816 *
1817 * This function is needed when a Windows HWND is created
1818 * and a menubar has been set to the window with a system
1819 * menu. It notifies the menu package so that the system
1820 * menu can be rebuilt.
1821 *
1822 * Results:
1823 * None.
1824 *
1825 * Side effects:
1826 * The system menu (if any) is created for the menubar
1827 * associated with this frame.
1828 *
1829 *--------------------------------------------------------------
1830 */
1831
1832 void
1833 TkInstallFrameMenu(tkwin)
1834 Tk_Window tkwin; /* The window that was just created. */
1835 {
1836 TkWindow *winPtr = (TkWindow *) tkwin;
1837
1838 if (winPtr->mainPtr != NULL) {
1839 Frame *framePtr;
1840 framePtr = (Frame*) winPtr->instanceData;
1841 if (framePtr == NULL) {
1842 panic("TkInstallFrameMenu couldn't get frame pointer");
1843 }
1844 TkpMenuNotifyToplevelCreate(winPtr->mainPtr->interp,
1845 Tcl_GetString(framePtr->menuName));
1846 }
1847 }
1848
1849 /*
1850 *--------------------------------------------------------------
1851 *
1852 * FrameStructureProc --
1853 *
1854 * This procedure is invoked whenever StructureNotify events
1855 * occur for a window that's managed as label for the frame.
1856 * This procudure's only purpose is to clean up when windows
1857 * are deleted.
1858 *
1859 * Results:
1860 * None.
1861 *
1862 * Side effects:
1863 * The window is disassociated from the frame when it is
1864 * deleted.
1865 *
1866 *--------------------------------------------------------------
1867 */
1868
1869 static void
1870 FrameStructureProc(clientData, eventPtr)
1871 ClientData clientData; /* Pointer to record describing frame. */
1872 XEvent *eventPtr; /* Describes what just happened. */
1873 {
1874 Labelframe *labelframePtr = (Labelframe *) clientData;
1875
1876 if (eventPtr->type == DestroyNotify) {
1877 /*
1878 * This should only happen in a labelframe but it doesn't
1879 * hurt to be careful.
1880 */
1881
1882 if (labelframePtr->frame.type == TYPE_LABELFRAME) {
1883 labelframePtr->labelWin = NULL;
1884 FrameWorldChanged((ClientData) labelframePtr);
1885 }
1886 }
1887 }
1888
1889 /*
1890 *--------------------------------------------------------------
1891 *
1892 * FrameRequestProc --
1893 *
1894 * This procedure is invoked whenever a window that's associated
1895 * with a frame changes its requested dimensions.
1896 *
1897 * Results:
1898 * None.
1899 *
1900 * Side effects:
1901 * The size and location on the screen of the window may change.
1902 * depending on the options specified for the frame.
1903 *
1904 *--------------------------------------------------------------
1905 */
1906
1907 static void
1908 FrameRequestProc(clientData, tkwin)
1909 ClientData clientData; /* Pointer to record for frame. */
1910 Tk_Window tkwin; /* Window that changed its desired
1911 * size. */
1912 {
1913 Frame *framePtr = (Frame *) clientData;
1914
1915 FrameWorldChanged((ClientData) framePtr);
1916 }
1917
1918 /*
1919 *--------------------------------------------------------------
1920 *
1921 * FrameLostSlaveProc --
1922 *
1923 * This procedure is invoked by Tk whenever some other geometry
1924 * claims control over a slave that used to be managed by us.
1925 *
1926 * Results:
1927 * None.
1928 *
1929 * Side effects:
1930 * Forgets all frame-related information about the slave.
1931 *
1932 *--------------------------------------------------------------
1933 */
1934
1935 static void
1936 FrameLostSlaveProc(clientData, tkwin)
1937 ClientData clientData; /* Frame structure for slave window that
1938 * was stolen away. */
1939 Tk_Window tkwin; /* Tk's handle for the slave window. */
1940 {
1941 Frame *framePtr = (Frame *) clientData;
1942 Labelframe *labelframePtr = (Labelframe *) clientData;
1943
1944 /*
1945 * This should only happen in a labelframe but it doesn't
1946 * hurt to be careful.
1947 */
1948
1949 if (labelframePtr->frame.type == TYPE_LABELFRAME) {
1950 Tk_DeleteEventHandler(labelframePtr->labelWin, StructureNotifyMask,
1951 FrameStructureProc, (ClientData) labelframePtr);
1952 if (framePtr->tkwin != Tk_Parent(labelframePtr->labelWin)) {
1953 Tk_UnmaintainGeometry(labelframePtr->labelWin, framePtr->tkwin);
1954 }
1955 Tk_UnmapWindow(labelframePtr->labelWin);
1956 labelframePtr->labelWin = NULL;
1957 }
1958 FrameWorldChanged((ClientData) framePtr);
1959 }
1960
1961 /*
1962 *--------------------------------------------------------------
1963 *
1964 * TkToplevelWindowFromCommandToken --
1965 *
1966 * If the given command name to the command for a toplevel window
1967 * in the given interpreter, return the tkwin for that toplevel
1968 * window. Note that this lookup can't be done using the
1969 * standard tkwin internal table because the command might have
1970 * been renamed.
1971 *
1972 * Results:
1973 * A Tk_Window token, or NULL if the name does not refer to a
1974 * toplevel window.
1975 *
1976 * Side effects:
1977 * None.
1978 *
1979 *--------------------------------------------------------------
1980 */
1981
1982 Tk_Window
1983 TkToplevelWindowForCommand(interp, cmdName)
1984 Tcl_Interp *interp;
1985 CONST char *cmdName;
1986 {
1987 Tcl_CmdInfo cmdInfo;
1988 Frame *framePtr;
1989
1990 if (Tcl_GetCommandInfo(interp, cmdName, &cmdInfo) == 0) {
1991 return NULL;
1992 }
1993 if (cmdInfo.objProc != FrameWidgetObjCmd) {
1994 return NULL;
1995 }
1996 framePtr = (Frame *) cmdInfo.objClientData;
1997 if (framePtr->type != TYPE_TOPLEVEL) {
1998 return NULL;
1999 }
2000 return framePtr->tkwin;
2001 }
2002