Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libtk/generic/tkFrame.c
1810 views
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 "tkInt.h"
19
#include "tkDefault.h"
20
21
/*
22
* A data structure of the following type is kept for each
23
* frame that currently exists for this process:
24
*/
25
26
typedef struct {
27
Tk_Window tkwin; /* Window that embodies the frame. NULL
28
* means that the window has been destroyed
29
* but the data structures haven't yet been
30
* cleaned up. */
31
Display *display; /* Display containing widget. Used, among
32
* other things, so that resources can be
33
* freed even after tkwin has gone away. */
34
Tcl_Interp *interp; /* Interpreter associated with widget. Used
35
* to delete widget command. */
36
Tcl_Command widgetCmd; /* Token for frame's widget command. */
37
char *className; /* Class name for widget (from configuration
38
* option). Malloc-ed. */
39
int mask; /* Either FRAME or TOPLEVEL; used to select
40
* which configuration options are valid for
41
* widget. */
42
char *screenName; /* Screen on which widget is created. Non-null
43
* only for top-levels. Malloc-ed, may be
44
* NULL. */
45
char *visualName; /* Textual description of visual for window,
46
* from -visual option. Malloc-ed, may be
47
* NULL. */
48
char *colormapName; /* Textual description of colormap for window,
49
* from -colormap option. Malloc-ed, may be
50
* NULL. */
51
Colormap colormap; /* If not None, identifies a colormap
52
* allocated for this window, which must be
53
* freed when the window is deleted. */
54
Tk_3DBorder border; /* Structure used to draw 3-D border and
55
* background. NULL means no background
56
* or border. */
57
int borderWidth; /* Width of 3-D border (if any). */
58
int relief; /* 3-d effect: TK_RELIEF_RAISED etc. */
59
int highlightWidth; /* Width in pixels of highlight to draw
60
* around widget when it has the focus.
61
* 0 means don't draw a highlight. */
62
XColor *highlightBgColorPtr;
63
/* Color for drawing traversal highlight
64
* area when highlight is off. */
65
XColor *highlightColorPtr; /* Color for drawing traversal highlight. */
66
int width; /* Width to request for window. <= 0 means
67
* don't request any size. */
68
int height; /* Height to request for window. <= 0 means
69
* don't request any size. */
70
Tk_Cursor cursor; /* Current cursor for window, or None. */
71
char *takeFocus; /* Value of -takefocus option; not used in
72
* the C code, but used by keyboard traversal
73
* scripts. Malloc'ed, but may be NULL. */
74
int flags; /* Various flags; see below for
75
* definitions. */
76
} Frame;
77
78
/*
79
* Flag bits for frames:
80
*
81
* REDRAW_PENDING: Non-zero means a DoWhenIdle handler
82
* has already been queued to redraw
83
* this window.
84
* GOT_FOCUS: Non-zero means this widget currently
85
* has the input focus.
86
*/
87
88
#define REDRAW_PENDING 1
89
#define GOT_FOCUS 4
90
91
/*
92
* The following flag bits are used so that there can be separate
93
* defaults for some configuration options for frames and toplevels.
94
*/
95
96
#define FRAME TK_CONFIG_USER_BIT
97
#define TOPLEVEL (TK_CONFIG_USER_BIT << 1)
98
#define BOTH (FRAME | TOPLEVEL)
99
100
static Tk_ConfigSpec configSpecs[] = {
101
{TK_CONFIG_BORDER, "-background", "background", "Background",
102
DEF_FRAME_BG_COLOR, Tk_Offset(Frame, border),
103
BOTH|TK_CONFIG_COLOR_ONLY|TK_CONFIG_NULL_OK},
104
{TK_CONFIG_BORDER, "-background", "background", "Background",
105
DEF_FRAME_BG_MONO, Tk_Offset(Frame, border),
106
BOTH|TK_CONFIG_MONO_ONLY|TK_CONFIG_NULL_OK},
107
{TK_CONFIG_SYNONYM, "-bd", "borderWidth", (char *) NULL,
108
(char *) NULL, 0, BOTH},
109
{TK_CONFIG_SYNONYM, "-bg", "background", (char *) NULL,
110
(char *) NULL, 0, BOTH},
111
{TK_CONFIG_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
112
DEF_FRAME_BORDER_WIDTH, Tk_Offset(Frame, borderWidth), BOTH},
113
{TK_CONFIG_STRING, "-class", "class", "Class",
114
DEF_FRAME_CLASS, Tk_Offset(Frame, className), FRAME},
115
{TK_CONFIG_STRING, "-class", "class", "Class",
116
DEF_TOPLEVEL_CLASS, Tk_Offset(Frame, className), TOPLEVEL},
117
{TK_CONFIG_STRING, "-colormap", "colormap", "Colormap",
118
DEF_FRAME_COLORMAP, Tk_Offset(Frame, colormapName),
119
BOTH|TK_CONFIG_NULL_OK},
120
{TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor",
121
DEF_FRAME_CURSOR, Tk_Offset(Frame, cursor), BOTH|TK_CONFIG_NULL_OK},
122
{TK_CONFIG_PIXELS, "-height", "height", "Height",
123
DEF_FRAME_HEIGHT, Tk_Offset(Frame, height), BOTH},
124
{TK_CONFIG_COLOR, "-highlightbackground", "highlightBackground",
125
"HighlightBackground", DEF_FRAME_HIGHLIGHT_BG,
126
Tk_Offset(Frame, highlightBgColorPtr), BOTH},
127
{TK_CONFIG_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
128
DEF_FRAME_HIGHLIGHT, Tk_Offset(Frame, highlightColorPtr), BOTH},
129
{TK_CONFIG_PIXELS, "-highlightthickness", "highlightThickness",
130
"HighlightThickness",
131
DEF_FRAME_HIGHLIGHT_WIDTH, Tk_Offset(Frame, highlightWidth), BOTH},
132
{TK_CONFIG_RELIEF, "-relief", "relief", "Relief",
133
DEF_FRAME_RELIEF, Tk_Offset(Frame, relief), BOTH},
134
{TK_CONFIG_STRING, "-screen", "screen", "Screen",
135
DEF_TOPLEVEL_SCREEN, Tk_Offset(Frame, screenName),
136
TOPLEVEL|TK_CONFIG_NULL_OK},
137
{TK_CONFIG_STRING, "-takefocus", "takeFocus", "TakeFocus",
138
DEF_FRAME_TAKE_FOCUS, Tk_Offset(Frame, takeFocus),
139
BOTH|TK_CONFIG_NULL_OK},
140
{TK_CONFIG_STRING, "-visual", "visual", "Visual",
141
DEF_FRAME_VISUAL, Tk_Offset(Frame, visualName),
142
BOTH|TK_CONFIG_NULL_OK},
143
{TK_CONFIG_PIXELS, "-width", "width", "Width",
144
DEF_FRAME_WIDTH, Tk_Offset(Frame, width), BOTH},
145
{TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
146
(char *) NULL, 0, 0}
147
};
148
149
/*
150
* Forward declarations for procedures defined later in this file:
151
*/
152
153
static int ConfigureFrame _ANSI_ARGS_((Tcl_Interp *interp,
154
Frame *framePtr, int argc, char **argv,
155
int flags));
156
static void DestroyFrame _ANSI_ARGS_((char *memPtr));
157
static void DisplayFrame _ANSI_ARGS_((ClientData clientData));
158
static void FrameCmdDeletedProc _ANSI_ARGS_((
159
ClientData clientData));
160
static void FrameEventProc _ANSI_ARGS_((ClientData clientData,
161
XEvent *eventPtr));
162
static int FrameWidgetCmd _ANSI_ARGS_((ClientData clientData,
163
Tcl_Interp *interp, int argc, char **argv));
164
static void MapFrame _ANSI_ARGS_((ClientData clientData));
165
166
/*
167
*--------------------------------------------------------------
168
*
169
* Tk_FrameCmd, Tk_ToplevelCmd --
170
*
171
* These procedures are invoked to process the "frame" and
172
* "toplevel" Tcl commands. See the user documentation for
173
* details on what they do.
174
*
175
* Results:
176
* A standard Tcl result.
177
*
178
* Side effects:
179
* See the user documentation. These procedures are just wrappers;
180
* they call ButtonCreate to do all of the real work.
181
*
182
*--------------------------------------------------------------
183
*/
184
185
int
186
Tk_FrameCmd(clientData, interp, argc, argv)
187
ClientData clientData; /* Main window associated with
188
* interpreter. */
189
Tcl_Interp *interp; /* Current interpreter. */
190
int argc; /* Number of arguments. */
191
char **argv; /* Argument strings. */
192
{
193
return TkCreateFrame(clientData, interp, argc, argv, 0, (char *) NULL);
194
}
195
196
int
197
Tk_ToplevelCmd(clientData, interp, argc, argv)
198
ClientData clientData; /* Main window associated with
199
* interpreter. */
200
Tcl_Interp *interp; /* Current interpreter. */
201
int argc; /* Number of arguments. */
202
char **argv; /* Argument strings. */
203
{
204
return TkCreateFrame(clientData, interp, argc, argv, 1, (char *) NULL);
205
}
206
207
/*
208
*--------------------------------------------------------------
209
*
210
* TkFrameCreate --
211
*
212
* This procedure is invoked to process the "frame" and "toplevel"
213
* Tcl commands; it is also invoked directly by Tk_Init to create
214
* a new main window. See the user documentation for the "frame"
215
* and "toplevel" commands for details on what it does.
216
*
217
* Results:
218
* A standard Tcl result.
219
*
220
* Side effects:
221
* See the user documentation.
222
*
223
*--------------------------------------------------------------
224
*/
225
226
int
227
TkCreateFrame(clientData, interp, argc, argv, toplevel, appName)
228
ClientData clientData; /* Main window associated with interpreter.
229
* If we're called by Tk_Init to create a
230
* new application, then this is NULL. */
231
Tcl_Interp *interp; /* Current interpreter. */
232
int argc; /* Number of arguments. */
233
char **argv; /* Argument strings. */
234
int toplevel; /* Non-zero means create a toplevel window,
235
* zero means create a frame. */
236
char *appName; /* Should only be non-NULL if clientData is
237
* NULL: gives the base name to use for the
238
* new application. */
239
{
240
Tk_Window tkwin = (Tk_Window) clientData;
241
Frame *framePtr;
242
Tk_Window new = NULL;
243
char *className, *screenName, *visualName, *colormapName, *arg;
244
int i, c, length, depth;
245
Colormap colormap;
246
Visual *visual;
247
248
if (argc < 2) {
249
Tcl_AppendResult(interp, "wrong # args: should be \"",
250
argv[0], " pathName ?options?\"", (char *) NULL);
251
return TCL_ERROR;
252
}
253
254
/*
255
* Pre-process the argument list. Scan through it to find any
256
* "-class", "-screen", "-visual", and "-colormap" options. These
257
* arguments need to be processed specially, before the window
258
* is configured using the usual Tk mechanisms.
259
*/
260
261
className = colormapName = screenName = visualName = NULL;
262
colormap = None;
263
for (i = 2; i < argc; i += 2) {
264
arg = argv[i];
265
length = strlen(arg);
266
if (length < 2) {
267
continue;
268
}
269
c = arg[1];
270
if ((c == 'c') && (strncmp(arg, "-class", strlen(arg)) == 0)
271
&& (length >= 3)) {
272
className = argv[i+1];
273
} else if ((c == 'c')
274
&& (strncmp(arg, "-colormap", strlen(arg)) == 0)) {
275
colormapName = argv[i+1];
276
} else if ((c == 's') && toplevel
277
&& (strncmp(arg, "-screen", strlen(arg)) == 0)) {
278
screenName = argv[i+1];
279
} else if ((c == 'v')
280
&& (strncmp(arg, "-visual", strlen(arg)) == 0)) {
281
visualName = argv[i+1];
282
}
283
}
284
285
/*
286
* Create the window, and deal with the special options -classname,
287
* -colormap, -screenname, and -visual. The order here is tricky,
288
* because we want to allow values for these options to come from
289
* the database, yet we can't do that until the window is created.
290
*/
291
292
if (screenName == NULL) {
293
screenName = (toplevel) ? "" : NULL;
294
}
295
if (tkwin != NULL) {
296
new = Tk_CreateWindowFromPath(interp, tkwin, argv[1], screenName);
297
} else {
298
/*
299
* We were called from Tk_Init; create a new application.
300
*/
301
302
if (appName == NULL) {
303
panic("TkCreateFrame didn't get application name");
304
}
305
new = TkCreateMainWindow(interp, screenName, appName);
306
}
307
if (new == NULL) {
308
goto error;
309
}
310
if (className == NULL) {
311
className = Tk_GetOption(new, "class", "Class");
312
if (className == NULL) {
313
className = (toplevel) ? "Toplevel" : "Frame";
314
}
315
}
316
Tk_SetClass(new, className);
317
if (visualName == NULL) {
318
visualName = Tk_GetOption(new, "visual", "Visual");
319
}
320
if (colormapName == NULL) {
321
colormapName = Tk_GetOption(new, "colormap", "Colormap");
322
}
323
if (visualName != NULL) {
324
visual = Tk_GetVisual(interp, new, visualName, &depth,
325
(colormapName == NULL) ? &colormap : (Colormap *) NULL);
326
if (visual == NULL) {
327
goto error;
328
}
329
Tk_SetWindowVisual(new, visual, depth, colormap);
330
}
331
if (colormapName != NULL) {
332
colormap = Tk_GetColormap(interp, new, colormapName);
333
if (colormap == None) {
334
goto error;
335
}
336
Tk_SetWindowColormap(new, colormap);
337
}
338
339
/*
340
* For top-level windows, provide an initial geometry request of
341
* 200x200, just so the window looks nicer on the screen if it
342
* doesn't request a size for itself.
343
*/
344
345
if (toplevel) {
346
Tk_GeometryRequest(new, 200, 200);
347
}
348
349
/*
350
* Create the widget record, process configuration options, and
351
* create event handlers. Then fill in a few additional fields
352
* in the widget record from the special options.
353
*/
354
355
framePtr = (Frame *) ckalloc(sizeof(Frame));
356
framePtr->tkwin = new;
357
framePtr->display = Tk_Display(new);
358
framePtr->interp = interp;
359
framePtr->widgetCmd = Tcl_CreateCommand(interp,
360
Tk_PathName(new), FrameWidgetCmd,
361
(ClientData) framePtr, FrameCmdDeletedProc);
362
framePtr->className = NULL;
363
framePtr->mask = (toplevel) ? TOPLEVEL : FRAME;
364
framePtr->screenName = NULL;
365
framePtr->visualName = NULL;
366
framePtr->colormapName = NULL;
367
framePtr->colormap = colormap;
368
framePtr->border = NULL;
369
framePtr->borderWidth = 0;
370
framePtr->relief = TK_RELIEF_FLAT;
371
framePtr->highlightWidth = 0;
372
framePtr->highlightBgColorPtr = NULL;
373
framePtr->highlightColorPtr = NULL;
374
framePtr->width = 0;
375
framePtr->height = 0;
376
framePtr->cursor = None;
377
framePtr->takeFocus = NULL;
378
framePtr->flags = 0;
379
Tk_CreateEventHandler(new, ExposureMask|StructureNotifyMask|FocusChangeMask,
380
FrameEventProc, (ClientData) framePtr);
381
if (ConfigureFrame(interp, framePtr, argc-2, argv+2, 0) != TCL_OK) {
382
goto error;
383
}
384
if (toplevel) {
385
Tcl_DoWhenIdle(MapFrame, (ClientData) framePtr);
386
}
387
interp->result = Tk_PathName(new);
388
return TCL_OK;
389
390
error:
391
if (new != NULL) {
392
Tk_DestroyWindow(new);
393
}
394
return TCL_ERROR;
395
}
396
397
/*
398
*--------------------------------------------------------------
399
*
400
* FrameWidgetCmd --
401
*
402
* This procedure is invoked to process the Tcl command
403
* that corresponds to a frame widget. See the user
404
* documentation for details on what it does.
405
*
406
* Results:
407
* A standard Tcl result.
408
*
409
* Side effects:
410
* See the user documentation.
411
*
412
*--------------------------------------------------------------
413
*/
414
415
static int
416
FrameWidgetCmd(clientData, interp, argc, argv)
417
ClientData clientData; /* Information about frame widget. */
418
Tcl_Interp *interp; /* Current interpreter. */
419
int argc; /* Number of arguments. */
420
char **argv; /* Argument strings. */
421
{
422
register Frame *framePtr = (Frame *) clientData;
423
int result = TCL_OK;
424
size_t length;
425
int c, i;
426
427
if (argc < 2) {
428
Tcl_AppendResult(interp, "wrong # args: should be \"",
429
argv[0], " option ?arg arg ...?\"", (char *) NULL);
430
return TCL_ERROR;
431
}
432
Tcl_Preserve((ClientData) framePtr);
433
c = argv[1][0];
434
length = strlen(argv[1]);
435
if ((c == 'c') && (strncmp(argv[1], "cget", length) == 0)
436
&& (length >= 2)) {
437
if (argc != 3) {
438
Tcl_AppendResult(interp, "wrong # args: should be \"",
439
argv[0], " cget option\"",
440
(char *) NULL);
441
result = TCL_ERROR;
442
goto done;
443
}
444
result = Tk_ConfigureValue(interp, framePtr->tkwin, configSpecs,
445
(char *) framePtr, argv[2], framePtr->mask);
446
} else if ((c == 'c') && (strncmp(argv[1], "configure", length) == 0)
447
&& (length >= 2)) {
448
if (argc == 2) {
449
result = Tk_ConfigureInfo(interp, framePtr->tkwin, configSpecs,
450
(char *) framePtr, (char *) NULL, framePtr->mask);
451
} else if (argc == 3) {
452
result = Tk_ConfigureInfo(interp, framePtr->tkwin, configSpecs,
453
(char *) framePtr, argv[2], framePtr->mask);
454
} else {
455
/*
456
* Don't allow the options -class, -newcmap, -screen,
457
* or -visual to be changed.
458
*/
459
460
for (i = 2; i < argc; i++) {
461
length = strlen(argv[i]);
462
if (length < 2) {
463
continue;
464
}
465
c = argv[i][1];
466
if (((c == 'c') && (strncmp(argv[i], "-class", length) == 0)
467
&& (length >= 2))
468
|| ((c == 'c') && (framePtr->mask == TOPLEVEL)
469
&& (strncmp(argv[i], "-colormap", length) == 0))
470
|| ((c == 's') && (framePtr->mask == TOPLEVEL)
471
&& (strncmp(argv[i], "-screen", length) == 0))
472
|| ((c == 'v') && (framePtr->mask == TOPLEVEL)
473
&& (strncmp(argv[i], "-visual", length) == 0))) {
474
Tcl_AppendResult(interp, "can't modify ", argv[i],
475
" option after widget is created", (char *) NULL);
476
result = TCL_ERROR;
477
goto done;
478
}
479
}
480
result = ConfigureFrame(interp, framePtr, argc-2, argv+2,
481
TK_CONFIG_ARGV_ONLY);
482
}
483
} else {
484
Tcl_AppendResult(interp, "bad option \"", argv[1],
485
"\": must be cget or configure", (char *) NULL);
486
result = TCL_ERROR;
487
}
488
489
done:
490
Tcl_Release((ClientData) framePtr);
491
return result;
492
}
493
494
/*
495
*----------------------------------------------------------------------
496
*
497
* DestroyFrame --
498
*
499
* This procedure is invoked by Tcl_EventuallyFree or Tcl_Release
500
* to clean up the internal structure of a frame at a safe time
501
* (when no-one is using it anymore).
502
*
503
* Results:
504
* None.
505
*
506
* Side effects:
507
* Everything associated with the frame is freed up.
508
*
509
*----------------------------------------------------------------------
510
*/
511
512
static void
513
DestroyFrame(memPtr)
514
char *memPtr; /* Info about frame widget. */
515
{
516
register Frame *framePtr = (Frame *) memPtr;
517
518
Tk_FreeOptions(configSpecs, (char *) framePtr, framePtr->display,
519
framePtr->mask);
520
if (framePtr->colormap != None) {
521
Tk_FreeColormap(framePtr->display, framePtr->colormap);
522
}
523
ckfree((char *) framePtr);
524
}
525
526
/*
527
*----------------------------------------------------------------------
528
*
529
* ConfigureFrame --
530
*
531
* This procedure is called to process an argv/argc list, plus
532
* the Tk option database, in order to configure (or
533
* reconfigure) a frame widget.
534
*
535
* Results:
536
* The return value is a standard Tcl result. If TCL_ERROR is
537
* returned, then interp->result contains an error message.
538
*
539
* Side effects:
540
* Configuration information, such as text string, colors, font,
541
* etc. get set for framePtr; old resources get freed, if there
542
* were any.
543
*
544
*----------------------------------------------------------------------
545
*/
546
547
static int
548
ConfigureFrame(interp, framePtr, argc, argv, flags)
549
Tcl_Interp *interp; /* Used for error reporting. */
550
register Frame *framePtr; /* Information about widget; may or may
551
* not already have values for some fields. */
552
int argc; /* Number of valid entries in argv. */
553
char **argv; /* Arguments. */
554
int flags; /* Flags to pass to Tk_ConfigureWidget. */
555
{
556
if (Tk_ConfigureWidget(interp, framePtr->tkwin, configSpecs,
557
argc, argv, (char *) framePtr, flags | framePtr->mask) != TCL_OK) {
558
return TCL_ERROR;
559
}
560
561
if (framePtr->border != NULL) {
562
Tk_SetBackgroundFromBorder(framePtr->tkwin, framePtr->border);
563
}
564
if (framePtr->highlightWidth < 0) {
565
framePtr->highlightWidth = 0;
566
}
567
Tk_SetInternalBorder(framePtr->tkwin,
568
framePtr->borderWidth + framePtr->highlightWidth);
569
if ((framePtr->width > 0) || (framePtr->height > 0)) {
570
Tk_GeometryRequest(framePtr->tkwin, framePtr->width,
571
framePtr->height);
572
}
573
574
if (Tk_IsMapped(framePtr->tkwin)) {
575
if (!(framePtr->flags & REDRAW_PENDING)) {
576
Tcl_DoWhenIdle(DisplayFrame, (ClientData) framePtr);
577
}
578
framePtr->flags |= REDRAW_PENDING;
579
}
580
return TCL_OK;
581
}
582
583
/*
584
*----------------------------------------------------------------------
585
*
586
* DisplayFrame --
587
*
588
* This procedure is invoked to display a frame widget.
589
*
590
* Results:
591
* None.
592
*
593
* Side effects:
594
* Commands are output to X to display the frame in its
595
* current mode.
596
*
597
*----------------------------------------------------------------------
598
*/
599
600
static void
601
DisplayFrame(clientData)
602
ClientData clientData; /* Information about widget. */
603
{
604
register Frame *framePtr = (Frame *) clientData;
605
register Tk_Window tkwin = framePtr->tkwin;
606
GC gc;
607
608
framePtr->flags &= ~REDRAW_PENDING;
609
if ((framePtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
610
return;
611
}
612
613
if (framePtr->border != NULL) {
614
Tk_Fill3DRectangle(tkwin, Tk_WindowId(tkwin),
615
framePtr->border, framePtr->highlightWidth,
616
framePtr->highlightWidth,
617
Tk_Width(tkwin) - 2*framePtr->highlightWidth,
618
Tk_Height(tkwin) - 2*framePtr->highlightWidth,
619
framePtr->borderWidth, framePtr->relief);
620
}
621
if (framePtr->highlightWidth != 0) {
622
if (framePtr->flags & GOT_FOCUS) {
623
gc = Tk_GCForColor(framePtr->highlightColorPtr,
624
Tk_WindowId(tkwin));
625
} else {
626
gc = Tk_GCForColor(framePtr->highlightBgColorPtr,
627
Tk_WindowId(tkwin));
628
}
629
Tk_DrawFocusHighlight(tkwin, gc, framePtr->highlightWidth,
630
Tk_WindowId(tkwin));
631
}
632
}
633
634
/*
635
*--------------------------------------------------------------
636
*
637
* FrameEventProc --
638
*
639
* This procedure is invoked by the Tk dispatcher on
640
* structure changes to a frame. For frames with 3D
641
* borders, this procedure is also invoked for exposures.
642
*
643
* Results:
644
* None.
645
*
646
* Side effects:
647
* When the window gets deleted, internal structures get
648
* cleaned up. When it gets exposed, it is redisplayed.
649
*
650
*--------------------------------------------------------------
651
*/
652
653
static void
654
FrameEventProc(clientData, eventPtr)
655
ClientData clientData; /* Information about window. */
656
register XEvent *eventPtr; /* Information about event. */
657
{
658
register Frame *framePtr = (Frame *) clientData;
659
660
if (((eventPtr->type == Expose) && (eventPtr->xexpose.count == 0))
661
|| (eventPtr->type == ConfigureNotify)) {
662
goto redraw;
663
} else if (eventPtr->type == DestroyNotify) {
664
if (framePtr->tkwin != NULL) {
665
framePtr->tkwin = NULL;
666
Tcl_DeleteCommand(framePtr->interp,
667
Tcl_GetCommandName(framePtr->interp, framePtr->widgetCmd));
668
}
669
if (framePtr->flags & REDRAW_PENDING) {
670
Tcl_CancelIdleCall(DisplayFrame, (ClientData) framePtr);
671
}
672
Tcl_CancelIdleCall(MapFrame, (ClientData) framePtr);
673
Tcl_EventuallyFree((ClientData) framePtr, DestroyFrame);
674
} else if (eventPtr->type == FocusIn) {
675
if (eventPtr->xfocus.detail != NotifyInferior) {
676
framePtr->flags |= GOT_FOCUS;
677
if (framePtr->highlightWidth > 0) {
678
goto redraw;
679
}
680
}
681
} else if (eventPtr->type == FocusOut) {
682
if (eventPtr->xfocus.detail != NotifyInferior) {
683
framePtr->flags &= ~GOT_FOCUS;
684
if (framePtr->highlightWidth > 0) {
685
goto redraw;
686
}
687
}
688
}
689
return;
690
691
redraw:
692
if ((framePtr->tkwin != NULL) && !(framePtr->flags & REDRAW_PENDING)) {
693
Tcl_DoWhenIdle(DisplayFrame, (ClientData) framePtr);
694
framePtr->flags |= REDRAW_PENDING;
695
}
696
}
697
698
/*
699
*----------------------------------------------------------------------
700
*
701
* FrameCmdDeletedProc --
702
*
703
* This procedure is invoked when a widget command is deleted. If
704
* the widget isn't already in the process of being destroyed,
705
* this command destroys it.
706
*
707
* Results:
708
* None.
709
*
710
* Side effects:
711
* The widget is destroyed.
712
*
713
*----------------------------------------------------------------------
714
*/
715
716
static void
717
FrameCmdDeletedProc(clientData)
718
ClientData clientData; /* Pointer to widget record for widget. */
719
{
720
Frame *framePtr = (Frame *) clientData;
721
Tk_Window tkwin = framePtr->tkwin;
722
723
/*
724
* This procedure could be invoked either because the window was
725
* destroyed and the command was then deleted (in which case tkwin
726
* is NULL) or because the command was deleted, and then this procedure
727
* destroys the widget.
728
*/
729
730
if (tkwin != NULL) {
731
framePtr->tkwin = NULL;
732
Tk_DestroyWindow(tkwin);
733
}
734
}
735
736
/*
737
*----------------------------------------------------------------------
738
*
739
* MapFrame --
740
*
741
* This procedure is invoked as a when-idle handler to map a
742
* newly-created top-level frame.
743
*
744
* Results:
745
* None.
746
*
747
* Side effects:
748
* The frame given by the clientData argument is mapped.
749
*
750
*----------------------------------------------------------------------
751
*/
752
753
static void
754
MapFrame(clientData)
755
ClientData clientData; /* Pointer to frame structure. */
756
{
757
Frame *framePtr = (Frame *) clientData;
758
759
/*
760
* Wait for all other background events to be processed before
761
* mapping window. This ensures that the window's correct geometry
762
* will have been determined before it is first mapped, so that the
763
* window manager doesn't get a false idea of its desired geometry.
764
*/
765
766
Tcl_Preserve((ClientData) framePtr);
767
while (1) {
768
if (Tcl_DoOneEvent(TCL_IDLE_EVENTS) == 0) {
769
break;
770
}
771
772
/*
773
* After each event, make sure that the window still exists
774
* and quit if the window has been destroyed.
775
*/
776
777
if (framePtr->tkwin == NULL) {
778
Tcl_Release((ClientData) framePtr);
779
return;
780
}
781
}
782
Tk_MapWindow(framePtr->tkwin);
783
Tcl_Release((ClientData) framePtr);
784
}
785
786