Debian Codegraph @

pTk/mTk/generic/tkPanedWindow.c

raw symbols SCIP
1 /*
2 * tkPanedWindow.c --
3 *
4 * This module implements "paned window" widgets that are object
5 * based. A "paned window" is a widget that manages the geometry for
6 * some number of other widgets, placing a movable "sash" between them,
7 * which can be used to alter the relative sizes of adjacent widgets.
8 *
9 * Copyright (c) 1997 Sun Microsystems, Inc.
10 * Copyright (c) 2000 Ajuba Solutions.
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: tkPanedWindow.c,v 1.13.2.4 2003/08/19 21:00:13 jenglish Exp $
16 */
17
18 #include "tkPort.h"
19 #include "default.h"
20 #include "tkInt.h"
21
22 /* Flag values for "sticky"ness The 16 combinations subsume the packer's
23 * notion of anchor and fill.
24 *
25 * STICK_NORTH This window sticks to the top of its cavity.
26 * STICK_EAST This window sticks to the right edge of its cavity.
27 * STICK_SOUTH This window sticks to the bottom of its cavity.
28 * STICK_WEST This window sticks to the left edge of its cavity.
29 */
30
31 #define STICK_NORTH 1
32 #define STICK_EAST 2
33 #define STICK_SOUTH 4
34 #define STICK_WEST 8
35 /*
36 * The following table defines the legal values for the -orient option.
37 */
38
39 static char *orientStrings[] = {
40 "horizontal", "vertical", (char *) NULL
41 };
42
43 enum orient { ORIENT_HORIZONTAL, ORIENT_VERTICAL };
44
45 typedef struct {
46 Tk_OptionTable pwOptions; /* Token for paned window option table. */
47 Tk_OptionTable slaveOpts; /* Token for slave cget option table. */
48 } OptionTables;
49
50 /*
51 * One structure of the following type is kept for each window
52 * managed by a paned window widget.
53 */
54
55 typedef struct Slave {
56 Tk_Window tkwin; /* Window being managed. */
57
58 int minSize; /* Minimum size of this pane, on the
59 * relevant axis, in pixels. */
60 int padx; /* Additional padding requested for
61 * slave, in the x dimension. */
62 int pady; /* Additional padding requested for
63 * slave, in the y dimension. */
64 Tcl_Obj *widthPtr, *heightPtr; /* Tcl_Obj rep's of slave width/height,
65 * to allow for null values. */
66 int width; /* Slave width. */
67 int height; /* Slave height. */
68 int sticky; /* Sticky string. */
69 int x, y; /* Coordinates of the widget. */
70 int paneWidth, paneHeight; /* Pane dimensions (may be different
71 * from slave width/height). */
72 int sashx, sashy; /* Coordinates of the sash of the
73 * right or bottom of this pane. */
74 int markx, marky; /* Coordinates of the last mark set
75 * for the sash. */
76 int handlex, handley; /* Coordinates of the sash handle. */
77 struct PanedWindow *masterPtr; /* Paned window managing the window. */
78 Tk_Window after; /* Placeholder for parsing options. */
79 Tk_Window before; /* Placeholder for parsing options. */
80 } Slave;
81
82 /*
83 * A data structure of the following type is kept for each paned window
84 * widget managed by this file:
85 */
86
87 typedef struct PanedWindow {
88 Tk_Window tkwin; /* Window that embodies the paned window. */
89 Tk_Window proxywin; /* Window for the resizing proxy. */
90 Display *display; /* X's token for the window's display. */
91 Tcl_Interp *interp; /* Interpreter associated with widget. */
92 Tcl_Command widgetCmd; /* Token for square's widget command. */
93 Tk_OptionTable optionTable; /* Token representing the configuration
94 * specifications. */
95 Tk_OptionTable slaveOpts; /* Token for slave cget table. */
96 Tk_3DBorder background; /* Background color. */
97 int borderWidth; /* Value of -borderwidth option. */
98 int relief; /* 3D border effect (TK_RELIEF_RAISED, etc) */
99 Tcl_Obj *widthPtr; /* Tcl_Obj rep for width. */
100 Tcl_Obj *heightPtr; /* Tcl_Obj rep for height. */
101 int width, height; /* Width and height of the widget. */
102 enum orient orient; /* Orientation of the widget. */
103 Tk_Cursor cursor; /* Current cursor for window, or None. */
104 int resizeOpaque; /* Boolean indicating whether resize should be
105 * opaque or rubberband style. */
106
107 int sashRelief; /* Relief used to draw sash. */
108 int sashWidth; /* Width of each sash, in pixels. */
109 Tcl_Obj *sashWidthPtr; /* Tcl_Obj rep for sash width. */
110 int sashPad; /* Additional padding around each sash. */
111 Tcl_Obj *sashPadPtr; /* Tcl_Obj rep for sash padding. */
112 int showHandle; /* Boolean indicating whether sash handles
113 * should be drawn. */
114 int handleSize; /* Size of one side of a sash handle (handles
115 * are square), in pixels. */
116 int handlePad; /* Distance from border to draw handle. */
117 Tcl_Obj *handleSizePtr; /* Tcl_Obj rep for handle size. */
118 Tk_Cursor sashCursor; /* Cursor used when mouse is above a sash. */
119
120 GC gc; /* Graphics context for copying from
121 * off-screen pixmap onto screen. */
122 int proxyx, proxyy; /* Proxy x,y coordinates. */
123 Slave **slaves; /* Pointer to array of Slaves. */
124 int numSlaves; /* Number of slaves. */
125 int sizeofSlaves; /* Number of elements in the slaves array. */
126 int flags; /* Flags for widget; see below. */
127 } PanedWindow;
128
129 /*
130 * Flags used for paned windows:
131 *
132 * REDRAW_PENDING: Non-zero means a DoWhenIdle handler has
133 * been queued to redraw this window.
134 *
135 * WIDGET_DELETED: Non-zero means that the paned window has
136 * been, or is in the process of being, deleted.
137 *
138 * RESIZE_PENDING: Non-zero means that the window might need to
139 * change its size (or the size of its panes)
140 * because of a change in the size of one of its
141 * children.
142 */
143
144 #define REDRAW_PENDING 0x0001
145 #define WIDGET_DELETED 0x0002
146 #define REQUESTED_RELAYOUT 0x0004
147 #define RECOMPUTE_GEOMETRY 0x0008
148 #define PROXY_REDRAW_PENDING 0x0010
149 #define RESIZE_PENDING 0x0020
150
151 /*
152 * Forward declarations for procedures defined later in this file:
153 */
154
155 int Tk_PanedWindowObjCmd _ANSI_ARGS_((ClientData clientData,
156 Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]));
157 static void PanedWindowCmdDeletedProc _ANSI_ARGS_((ClientData clientData));
158 static int ConfigurePanedWindow _ANSI_ARGS_((Tcl_Interp *interp,
159 PanedWindow *pwPtr, int objc, Tcl_Obj *CONST objv[]));
160 static void DestroyPanedWindow _ANSI_ARGS_((PanedWindow *pwPtr));
161 static void DisplayPanedWindow _ANSI_ARGS_((ClientData clientData));
162 static void PanedWindowEventProc _ANSI_ARGS_((ClientData clientData,
163 XEvent *eventPtr));
164 static void ProxyWindowEventProc _ANSI_ARGS_((ClientData clientData,
165 XEvent *eventPtr));
166 static void DisplayProxyWindow _ANSI_ARGS_((ClientData clientData));
167 void PanedWindowWorldChanged _ANSI_ARGS_((ClientData instanceData));
168 static int PanedWindowWidgetObjCmd _ANSI_ARGS_((ClientData clientData,
169 Tcl_Interp *, int objc, Tcl_Obj * CONST objv[]));
170 static void PanedWindowLostSlaveProc _ANSI_ARGS_((ClientData clientData,
171 Tk_Window tkwin));
172 static void PanedWindowReqProc _ANSI_ARGS_((ClientData clientData,
173 Tk_Window tkwin));
174 static void ArrangePanes _ANSI_ARGS_((ClientData clientData));
175 static void Unlink _ANSI_ARGS_((Slave *slavePtr));
176 static Slave * GetPane _ANSI_ARGS_((PanedWindow *pwPtr, Tk_Window tkwin));
177 static void SlaveStructureProc _ANSI_ARGS_((ClientData clientData,
178 XEvent *eventPtr));
179 static int PanedWindowSashCommand _ANSI_ARGS_((PanedWindow *pwPtr,
180 Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]));
181 static int PanedWindowProxyCommand _ANSI_ARGS_((PanedWindow *pwPtr,
182 Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]));
183 static void ComputeGeometry _ANSI_ARGS_((PanedWindow *pwPtr));
184 static int ConfigureSlaves _ANSI_ARGS_((PanedWindow *pwPtr,
185 Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]));
186 static void DestroyOptionTables _ANSI_ARGS_((ClientData clientData,
187 Tcl_Interp *interp));
188 static int SetSticky _ANSI_ARGS_((ClientData clientData,
189 Tcl_Interp *interp, Tk_Window tkwin,
190 Tcl_Obj **value, char *recordPtr, int internalOffset,
191 char *oldInternalPtr, int flags));
192 static Tcl_Obj *GetSticky _ANSI_ARGS_((ClientData clientData, Tk_Window tkwin,
193 char *recordPtr, int internalOffset));
194 static void RestoreSticky _ANSI_ARGS_((ClientData clientData,
195 Tk_Window tkwin, char *internalPtr,
196 char *oldInternalPtr));
197 static void AdjustForSticky _ANSI_ARGS_((int sticky, int cavityWidth,
198 int cavityHeight, int *xPtr, int *yPtr,
199 int *slaveWidthPtr, int *slaveHeightPtr));
200 static void MoveSash _ANSI_ARGS_((PanedWindow *pwPtr, int sash, int diff));
201 static int ObjectIsEmpty _ANSI_ARGS_((Tcl_Obj *objPtr));
202 static char * ComputeSlotAddress _ANSI_ARGS_((char *recordPtr, int offset));
203 static int PanedWindowIdentifyCoords _ANSI_ARGS_((PanedWindow *pwPtr,
204 Tcl_Interp *interp, int x, int y));
205
206 /*
207 * Sashes are between panes only, so there is one less sash than slaves
208 */
209
210 #define ValidSashIndex(pwPtr, sash) \
211 (((sash) >= 0) && ((sash) < ((pwPtr)->numSlaves-1)))
212
213 static Tk_GeomMgr panedWindowMgrType = {
214 "panedwindow", /* name */
215 PanedWindowReqProc, /* requestProc */
216 PanedWindowLostSlaveProc, /* lostSlaveProc */
217 };
218
219 /*
220 * Information used for objv parsing.
221 */
222
223 #define GEOMETRY 0x0001
224
225 /*
226 * The following structure contains pointers to functions used for processing
227 * the custom "-sticky" option for slave windows.
228 */
229
230 static Tk_ObjCustomOption stickyOption = {
231 "sticky", /* name */
232 SetSticky, /* setProc */
233 GetSticky, /* getProc */
234 RestoreSticky, /* restoreProc */
235 (Tk_CustomOptionFreeProc *)NULL, /* freeProc */
236 0
237 };
238
239 static Tk_OptionSpec optionSpecs[] = {
240 {TK_OPTION_BORDER, "-background", "background", "Background",
241 DEF_PANEDWINDOW_BG_COLOR, -1, Tk_Offset(PanedWindow, background), 0,
242 (ClientData) DEF_PANEDWINDOW_BG_MONO},
243 {TK_OPTION_SYNONYM, "-bd", (char *) NULL, (char *) NULL,
244 (char *) NULL, 0, -1, 0, (ClientData) "-borderwidth"},
245 {TK_OPTION_SYNONYM, "-bg", (char *) NULL, (char *) NULL,
246 (char *) NULL, 0, -1, 0, (ClientData) "-background"},
247 {TK_OPTION_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
248 DEF_PANEDWINDOW_BORDERWIDTH, -1, Tk_Offset(PanedWindow, borderWidth),
249 0, 0, GEOMETRY},
250 {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor",
251 DEF_PANEDWINDOW_CURSOR, -1, Tk_Offset(PanedWindow, cursor),
252 TK_OPTION_NULL_OK, 0, 0},
253 {TK_OPTION_PIXELS, "-handlepad", "handlePad", "HandlePad",
254 DEF_PANEDWINDOW_HANDLEPAD, -1, Tk_Offset(PanedWindow, handlePad),
255 0, 0},
256 {TK_OPTION_PIXELS, "-handlesize", "handleSize", "HandleSize",
257 DEF_PANEDWINDOW_HANDLESIZE, Tk_Offset(PanedWindow, handleSizePtr),
258 Tk_Offset(PanedWindow, handleSize), 0, 0, GEOMETRY},
259 {TK_OPTION_PIXELS, "-height", "height", "Height",
260 DEF_PANEDWINDOW_HEIGHT, Tk_Offset(PanedWindow, heightPtr),
261 Tk_Offset(PanedWindow, height), TK_OPTION_NULL_OK, 0, GEOMETRY},
262 {TK_OPTION_BOOLEAN, "-opaqueresize", "opaqueResize", "OpaqueResize",
263 DEF_PANEDWINDOW_OPAQUERESIZE, -1,
264 Tk_Offset(PanedWindow, resizeOpaque), 0, 0, 0},
265 {TK_OPTION_STRING_TABLE, "-orient", "orient", "Orient",
266 DEF_PANEDWINDOW_ORIENT, -1, Tk_Offset(PanedWindow, orient),
267 0, (ClientData) orientStrings, GEOMETRY},
268 {TK_OPTION_RELIEF, "-relief", "relief", "Relief",
269 DEF_PANEDWINDOW_RELIEF, -1, Tk_Offset(PanedWindow, relief), 0, 0, 0},
270 {TK_OPTION_CURSOR, "-sashcursor", "sashCursor", "Cursor",
271 DEF_PANEDWINDOW_SASHCURSOR, -1, Tk_Offset(PanedWindow, sashCursor),
272 TK_OPTION_NULL_OK, 0, 0},
273 {TK_OPTION_PIXELS, "-sashpad", "sashPad", "SashPad",
274 DEF_PANEDWINDOW_SASHPAD, -1, Tk_Offset(PanedWindow, sashPad),
275 0, 0, GEOMETRY},
276 {TK_OPTION_RELIEF, "-sashrelief", "sashRelief", "Relief",
277 DEF_PANEDWINDOW_SASHRELIEF, -1, Tk_Offset(PanedWindow, sashRelief),
278 0, 0, 0},
279 {TK_OPTION_PIXELS, "-sashwidth", "sashWidth", "Width",
280 DEF_PANEDWINDOW_SASHWIDTH, Tk_Offset(PanedWindow, sashWidthPtr),
281 Tk_Offset(PanedWindow, sashWidth), 0, 0, GEOMETRY},
282 {TK_OPTION_BOOLEAN, "-showhandle", "showHandle", "ShowHandle",
283 DEF_PANEDWINDOW_SHOWHANDLE, -1, Tk_Offset(PanedWindow, showHandle),
284 0, 0, GEOMETRY},
285 {TK_OPTION_PIXELS, "-width", "width", "Width",
286 DEF_PANEDWINDOW_WIDTH, Tk_Offset(PanedWindow, widthPtr),
287 Tk_Offset(PanedWindow, width), TK_OPTION_NULL_OK, 0, GEOMETRY},
288 {TK_OPTION_END}
289 };
290
291 static Tk_OptionSpec slaveOptionSpecs[] = {
292 {TK_OPTION_WINDOW, "-after", (char *) NULL, (char *) NULL,
293 DEF_PANEDWINDOW_PANE_AFTER, -1, Tk_Offset(Slave, after),
294 TK_OPTION_NULL_OK, 0, 0},
295 {TK_OPTION_WINDOW, "-before", (char *) NULL, (char *) NULL,
296 DEF_PANEDWINDOW_PANE_BEFORE, -1, Tk_Offset(Slave, before),
297 TK_OPTION_NULL_OK, 0, 0},
298 {TK_OPTION_PIXELS, "-height", (char *) NULL, (char *) NULL,
299 DEF_PANEDWINDOW_PANE_HEIGHT, Tk_Offset(Slave, heightPtr),
300 Tk_Offset(Slave, height), TK_OPTION_NULL_OK, 0, 0},
301 {TK_OPTION_PIXELS, "-minsize", (char *) NULL, (char *) NULL,
302 DEF_PANEDWINDOW_PANE_MINSIZE, -1, Tk_Offset(Slave, minSize), 0, 0, 0},
303 {TK_OPTION_PIXELS, "-padx", (char *) NULL, (char *) NULL,
304 DEF_PANEDWINDOW_PANE_PADX, -1, Tk_Offset(Slave, padx), 0, 0, 0},
305 {TK_OPTION_PIXELS, "-pady", (char *) NULL, (char *) NULL,
306 DEF_PANEDWINDOW_PANE_PADY, -1, Tk_Offset(Slave, pady), 0, 0, 0},
307 {TK_OPTION_CUSTOM, "-sticky", (char *) NULL, (char *) NULL,
308 DEF_PANEDWINDOW_PANE_STICKY, -1, Tk_Offset(Slave, sticky), 0,
309 (ClientData) &stickyOption, 0},
310 {TK_OPTION_PIXELS, "-width", (char *) NULL, (char *) NULL,
311 DEF_PANEDWINDOW_PANE_WIDTH, Tk_Offset(Slave, widthPtr),
312 Tk_Offset(Slave, width), TK_OPTION_NULL_OK, 0, 0},
313 {TK_OPTION_END}
314 };
315
316
317 /*
318 *--------------------------------------------------------------
319 *
320 * Tk_PanedWindowObjCmd --
321 *
322 * This procedure is invoked to process the "panedwindow" Tcl
323 * command. It creates a new "panedwindow" widget.
324 *
325 * Results:
326 * A standard Tcl result.
327 *
328 * Side effects:
329 * A new widget is created and configured.
330 *
331 *--------------------------------------------------------------
332 */
333
334 int
335 Tk_PanedWindowObjCmd(clientData, interp, objc, objv)
336 ClientData clientData; /* NULL. */
337 Tcl_Interp *interp; /* Current interpreter. */
338 int objc; /* Number of arguments. */
339 Tcl_Obj * CONST objv[]; /* Argument objects. */
340 {
341 PanedWindow *pwPtr;
342 Tk_Window tkwin, parent;
343 OptionTables *pwOpts;
344
345 if (objc < 2) {
346 Tcl_WrongNumArgs(interp, 1, objv, "pathName ?options?");
347 return TCL_ERROR;
348 }
349
350 tkwin = Tk_CreateWindowFromPath(interp, Tk_MainWindow(interp),
351 Tcl_GetStringFromObj(objv[1], NULL), (char *) NULL);
352 if (tkwin == NULL) {
353 return TCL_ERROR;
354 }
355
356 pwOpts = (OptionTables *)
357 Tcl_GetAssocData(interp, "PanedWindowOptionTables", NULL);
358 if (pwOpts == NULL) {
359 /*
360 * The first time this procedure is invoked, the option tables will
361 * be NULL. We then create the option tables from the templates
362 * and store a pointer to the tables as the command's clinical so
363 * we'll have easy access to it in the future.
364 */
365 pwOpts = (OptionTables *) ckalloc(sizeof(OptionTables));
366 /* Set up an exit handler to free the optionTables struct */
367 Tcl_SetAssocData(interp, "PanedWindowOptionTables",
368 DestroyOptionTables, (ClientData) pwOpts);
369
370 /* Create the paned window option tables. */
371 pwOpts->pwOptions = Tk_CreateOptionTable(interp, optionSpecs);
372 pwOpts->slaveOpts = Tk_CreateOptionTable(interp, slaveOptionSpecs);
373 }
374
375 Tk_SetClass(tkwin, "Panedwindow");
376
377 /*
378 * Allocate and initialize the widget record.
379 */
380
381 pwPtr = (PanedWindow *) ckalloc(sizeof(PanedWindow));
382 memset((void *)pwPtr, 0, (sizeof(PanedWindow)));
383 pwPtr->tkwin = tkwin;
384 pwPtr->display = Tk_Display(tkwin);
385 pwPtr->interp = interp;
386 pwPtr->widgetCmd = Tcl_CreateObjCommand(interp,
387 Tk_PathName(pwPtr->tkwin), PanedWindowWidgetObjCmd,
388 (ClientData) pwPtr, PanedWindowCmdDeletedProc);
389 pwPtr->optionTable = pwOpts->pwOptions;
390 pwPtr->slaveOpts = pwOpts->slaveOpts;
391 pwPtr->relief = TK_RELIEF_RAISED;
392 pwPtr->gc = None;
393 pwPtr->cursor = None;
394 pwPtr->sashCursor = None;
395
396 /*
397 * Keep a hold of the associated tkwin until we destroy the widget,
398 * otherwise Tk might free it while we still need it.
399 */
400
401 Tcl_Preserve((ClientData) pwPtr->tkwin);
402
403 if (Tk_InitOptions(interp, (char *) pwPtr, pwOpts->pwOptions,
404 tkwin) != TCL_OK) {
405 Tk_DestroyWindow(pwPtr->tkwin);
406 return TCL_ERROR;
407 }
408
409 Tk_CreateEventHandler(pwPtr->tkwin, ExposureMask|StructureNotifyMask,
410 PanedWindowEventProc, (ClientData) pwPtr);
411
412 /*
413 * Find the toplevel ancestor of the panedwindow, and make a proxy
414 * win as a child of that window; this way the proxy can always float
415 * above slaves in the panedwindow.
416 */
417 parent = Tk_Parent(pwPtr->tkwin);
418 while (!(Tk_IsTopLevel(parent))) {
419 parent = Tk_Parent(parent);
420 if (parent == NULL) {
421 parent = pwPtr->tkwin;
422 break;
423 }
424 }
425
426 pwPtr->proxywin = Tk_CreateAnonymousWindow(interp, parent, (char *) NULL);
427 /*
428 * The proxy window has to be able to share GCs with the main
429 * panedwindow despite being children of windows with potentially
430 * different characteristics, and it looks better that way too.
431 * [Bug 702230]
432 */
433 Tk_SetWindowVisual(pwPtr->proxywin,
434 Tk_Visual(tkwin), Tk_Depth(tkwin), Tk_Colormap(tkwin));
435 Tk_CreateEventHandler(pwPtr->proxywin, ExposureMask, ProxyWindowEventProc,
436 (ClientData) pwPtr);
437
438 if (ConfigurePanedWindow(interp, pwPtr, objc - 2, objv + 2) != TCL_OK) {
439 Tk_DestroyWindow(pwPtr->proxywin);
440 Tk_DestroyWindow(pwPtr->tkwin);
441 return TCL_ERROR;
442 }
443
444 Tcl_SetStringObj(Tcl_GetObjResult(interp), Tk_PathName(pwPtr->tkwin), -1);
445 return TCL_OK;
446 }
447
448 /*
449 *--------------------------------------------------------------
450 *
451 * PanedWindowWidgetObjCmd --
452 *
453 * This procedure is invoked to process the Tcl command
454 * that corresponds to a widget managed by this module.
455 * See the user documentation for details on what it does.
456 *
457 * Results:
458 * A standard Tcl result.
459 *
460 * Side effects:
461 * See the user documentation.
462 *
463 *--------------------------------------------------------------
464 */
465
466 static int
467 PanedWindowWidgetObjCmd(clientData, interp, objc, objv)
468 ClientData clientData; /* Information about square widget. */
469 Tcl_Interp *interp; /* Current interpreter. */
470 int objc; /* Number of arguments. */
471 Tcl_Obj * CONST objv[]; /* Argument objects. */
472 {
473 PanedWindow *pwPtr = (PanedWindow *) clientData;
474 int result = TCL_OK;
475 static CONST char *optionStrings[] = {"add", "cget", "configure", "forget",
476 "identify", "panecget",
477 "paneconfigure", "panes",
478 "proxy", "sash", (char *) NULL};
479 enum options { PW_ADD, PW_CGET, PW_CONFIGURE, PW_FORGET, PW_IDENTIFY,
480 PW_PANECGET, PW_PANECONFIGURE, PW_PANES, PW_PROXY,
481 PW_SASH };
482 Tcl_Obj *resultObj;
483 int index, count, i, x, y;
484 Tk_Window tkwin;
485 Slave *slavePtr;
486
487 if (objc < 2) {
488 Tcl_WrongNumArgs(interp, 1, objv, "option ?arg arg...?");
489 return TCL_ERROR;
490 }
491
492 if (Tcl_GetIndexFromObj(interp, objv[1], optionStrings, "command",
493 0, &index) != TCL_OK) {
494 return TCL_ERROR;
495 }
496
497 Tcl_Preserve((ClientData) pwPtr);
498
499 switch ((enum options) index) {
500 case PW_ADD: {
501 if (objc < 3) {
502 Tcl_WrongNumArgs(interp, 2, objv, "widget ?widget ...?");
503 result = TCL_ERROR;
504 break;
505 }
506
507 result = ConfigureSlaves(pwPtr, interp, objc, objv);
508 break;
509 }
510
511 case PW_CGET: {
512 if (objc != 3) {
513 Tcl_WrongNumArgs(interp, 2, objv, "option");
514 result = TCL_ERROR;
515 break;
516 }
517 resultObj = Tk_GetOptionValue(interp, (char *) pwPtr,
518 pwPtr->optionTable, objv[2], pwPtr->tkwin);
519 if (resultObj == NULL) {
520 result = TCL_ERROR;
521 } else {
522 Tcl_SetObjResult(interp, resultObj);
523 }
524 break;
525 }
526
527 case PW_CONFIGURE: {
528 resultObj = NULL;
529 if (objc <= 3) {
530 resultObj = Tk_GetOptionInfo(interp, (char *) pwPtr,
531 pwPtr->optionTable,
532 (objc == 3) ? objv[2] : (Tcl_Obj *) NULL,
533 pwPtr->tkwin);
534 if (resultObj == NULL) {
535 result = TCL_ERROR;
536 } else {
537 Tcl_SetObjResult(interp, resultObj);
538 }
539 } else {
540 result = ConfigurePanedWindow(interp, pwPtr, objc - 2,
541 objv + 2);
542 }
543 break;
544 }
545
546 case PW_FORGET: {
547 Tk_Window slave;
548 int i;
549
550 if (objc < 3) {
551 Tcl_WrongNumArgs(interp, 2, objv, "widget ?widget ...?");
552 result = TCL_ERROR;
553 break;
554 }
555
556 /*
557 * Clean up each window named in the arg list.
558 */
559 for (count = 0, i = 2; i < objc; i++) {
560 slave = Tk_NameToWindow(interp, Tcl_GetString(objv[i]),
561 pwPtr->tkwin);
562 if (slave == NULL) {
563 continue;
564 }
565 slavePtr = GetPane(pwPtr, slave);
566 if ((slavePtr != NULL) && (slavePtr->masterPtr != NULL)) {
567 count++;
568 Tk_ManageGeometry(slave, (Tk_GeomMgr *) NULL,
569 (ClientData) NULL);
570 Tk_UnmaintainGeometry(slavePtr->tkwin, pwPtr->tkwin);
571 Tk_DeleteEventHandler(slavePtr->tkwin, StructureNotifyMask,
572 SlaveStructureProc, (ClientData) slavePtr);
573 Tk_UnmapWindow(slavePtr->tkwin);
574 Unlink(slavePtr);
575 }
576 if (count != 0) {
577 ComputeGeometry(pwPtr);
578 }
579 }
580 break;
581 }
582
583 case PW_IDENTIFY: {
584 if (objc != 4) {
585 Tcl_WrongNumArgs(interp, 2, objv, "x y");
586 result = TCL_ERROR;
587 break;
588 }
589
590 if ((Tcl_GetIntFromObj(interp, objv[2], &x) != TCL_OK)
591 || (Tcl_GetIntFromObj(interp, objv[3], &y) != TCL_OK)) {
592 result = TCL_ERROR;
593 break;
594 }
595
596 result = PanedWindowIdentifyCoords(pwPtr, interp, x, y);
597 break;
598 }
599
600 case PW_PANECGET: {
601 if (objc != 4) {
602 Tcl_WrongNumArgs(interp, 2, objv, "pane option");
603 result = TCL_ERROR;
604 break;
605 }
606 tkwin = Tk_NameToWindow(interp, Tcl_GetString(objv[2]),
607 pwPtr->tkwin);
608 if (tkwin == NULL) {
609 result = TCL_ERROR;
610 break;
611 }
612 resultObj = NULL;
613 for (i = 0; i < pwPtr->numSlaves; i++) {
614 if (pwPtr->slaves[i]->tkwin == tkwin) {
615 resultObj = Tk_GetOptionValue(interp,
616 (char *) pwPtr->slaves[i], pwPtr->slaveOpts,
617 objv[3], tkwin);
618 }
619 }
620 if (i == pwPtr->numSlaves) {
621 Tcl_SetResult(interp, "not managed by this window",
622 TCL_STATIC);
623 }
624 if (resultObj == NULL) {
625 result = TCL_ERROR;
626 } else {
627 Tcl_SetObjResult(interp, resultObj);
628 }
629 break;
630 }
631
632 case PW_PANECONFIGURE: {
633 if (objc < 3) {
634 Tcl_WrongNumArgs(interp, 2, objv,
635 "pane ?option? ?value option value ...?");
636 result = TCL_ERROR;
637 break;
638 }
639 resultObj = NULL;
640 if (objc <= 4) {
641 tkwin = Tk_NameToWindow(interp, Tcl_GetString(objv[2]),
642 pwPtr->tkwin);
643 for (i = 0; i < pwPtr->numSlaves; i++) {
644 if (pwPtr->slaves[i]->tkwin == tkwin) {
645 resultObj = Tk_GetOptionInfo(interp,
646 (char *) pwPtr->slaves[i],
647 pwPtr->slaveOpts,
648 (objc == 4) ? objv[3] : (Tcl_Obj *) NULL,
649 pwPtr->tkwin);
650 if (resultObj == NULL) {
651 result = TCL_ERROR;
652 } else {
653 Tcl_SetObjResult(interp, resultObj);
654 }
655 break;
656 }
657 }
658 } else {
659 result = ConfigureSlaves(pwPtr, interp, objc, objv);
660 }
661 break;
662 }
663
664 case PW_PANES: {
665 resultObj = Tcl_NewObj();
666
667 Tcl_IncrRefCount(resultObj);
668
669 for (i = 0; i < pwPtr->numSlaves; i++) {
670 Tcl_ListObjAppendElement(interp, resultObj,
671 Tcl_NewStringObj(Tk_PathName(pwPtr->slaves[i]->tkwin),
672 -1));
673 }
674 Tcl_SetObjResult(interp, resultObj);
675 Tcl_DecrRefCount(resultObj);
676 break;
677 }
678
679 case PW_PROXY: {
680 result = PanedWindowProxyCommand(pwPtr, interp, objc, objv);
681 break;
682 }
683
684 case PW_SASH: {
685 result = PanedWindowSashCommand(pwPtr, interp, objc, objv);
686 break;
687 }
688 }
689 Tcl_Release((ClientData) pwPtr);
690 return result;
691 }
692
693 /*
694 *----------------------------------------------------------------------
695 *
696 * ConfigureSlaves --
697 *
698 * Add or alter the configuration options of a slave in a paned
699 * window.
700 *
701 * Results:
702 * Standard Tcl result.
703 *
704 * Side effects:
705 * Depends on options; may add a slave to the paned window, may
706 * alter the geometry management options of a slave.
707 *
708 *----------------------------------------------------------------------
709 */
710
711 static int
712 ConfigureSlaves(pwPtr, interp, objc, objv)
713 PanedWindow *pwPtr; /* Information about paned window. */
714 Tcl_Interp *interp; /* Current interpreter. */
715 int objc; /* Number of arguments. */
716 Tcl_Obj * CONST objv[]; /* Argument objects. */
717 {
718 int i, firstOptionArg, j, found, doubleBw, index, numNewSlaves, haveLoc;
719 int insertIndex;
720 Tk_Window tkwin = NULL, ancestor, parent;
721 Slave *slavePtr, **inserts, **new;
722 Slave options;
723 char *arg;
724
725 /*
726 * Find the non-window name arguments; these are the configure options
727 * for the slaves. Also validate that the window names given are
728 * legitimate (ie, they are real windows, they are not the panedwindow
729 * itself, etc.).
730 */
731 for (i = 2; i < objc; i++) {
732 arg = Tcl_GetString(objv[i]);
733 if (arg[0] == '-') {
734 break;
735 } else {
736 tkwin = Tk_NameToWindow(interp, arg, pwPtr->tkwin);
737 if (tkwin == NULL) {
738 /*
739 * Just a plain old bad window; Tk_NameToWindow filled in an
740 * error message for us.
741 */
742 return TCL_ERROR;
743 } else if (tkwin == pwPtr->tkwin) {
744 /*
745 * A panedwindow cannot manage itself.
746 */
747 Tcl_ResetResult(interp);
748 Tcl_AppendResult(interp, "can't add ", arg, " to itself",
749 (char *) NULL);
750 return TCL_ERROR;
751 } else if (Tk_IsTopLevel(tkwin)) {
752 /*
753 * A panedwindow cannot manage a toplevel.
754 */
755 Tcl_ResetResult(interp);
756 Tcl_AppendResult(interp, "can't add toplevel ", arg, " to ",
757 Tk_PathName(pwPtr->tkwin), (char *) NULL);
758 return TCL_ERROR;
759 } else {
760 /*
761 * Make sure the panedwindow is the parent of the slave,
762 * or a descendant of the slave's parent.
763 */
764 parent = Tk_Parent(tkwin);
765 for (ancestor = pwPtr->tkwin;;ancestor = Tk_Parent(ancestor)) {
766 if (ancestor == parent) {
767 break;
768 }
769 if (Tk_IsTopLevel(ancestor)) {
770 Tcl_ResetResult(interp);
771 Tcl_AppendResult(interp, "can't add ", arg,
772 " to ", Tk_PathName(pwPtr->tkwin),
773 (char *) NULL);
774 return TCL_ERROR;
775 }
776 }
777 }
778 }
779 }
780 firstOptionArg = i;
781
782 /*
783 * Pre-parse the configuration options, to get the before/after specifiers
784 * into an easy-to-find location (a local variable). Also, check the
785 * return from Tk_SetOptions once, here, so we can save a little bit of
786 * extra testing in the for loop below.
787 */
788 memset((void *)&options, 0, sizeof(Slave));
789 if (Tk_SetOptions(interp, (char *) &options, pwPtr->slaveOpts,
790 objc - firstOptionArg, objv + firstOptionArg,
791 pwPtr->tkwin, NULL, NULL) != TCL_OK) {
792 return TCL_ERROR;
793 }
794
795 /*
796 * If either -after or -before was given, find the numerical index that
797 * corresponds to the given window. If both -after and -before are
798 * given, the option precedence is: -after, then -before.
799 */
800 index = -1;
801 haveLoc = 0;
802 if (options.after != None) {
803 tkwin = options.after;
804 haveLoc = 1;
805 for (i = 0; i < pwPtr->numSlaves; i++) {
806 if (options.after == pwPtr->slaves[i]->tkwin) {
807 index = i + 1;
808 break;
809 }
810 }
811 } else if (options.before != None) {
812 tkwin = options.before;
813 haveLoc = 1;
814 for (i = 0; i < pwPtr->numSlaves; i++) {
815 if (options.before == pwPtr->slaves[i]->tkwin) {
816 index = i;
817 break;
818 }
819 }
820 }
821
822 /*
823 * If a window was given for -after/-before, but it's not a window
824 * managed by the panedwindow, throw an error
825 */
826 if (haveLoc && index == -1) {
827 Tcl_ResetResult(interp);
828 Tcl_AppendResult(interp, "window \"", Tk_PathName(tkwin),
829 "\" is not managed by ", Tk_PathName(pwPtr->tkwin),
830 (char *) NULL);
831 Tk_FreeConfigOptions((char *) &options, pwPtr->slaveOpts,
832 pwPtr->tkwin);
833 return TCL_ERROR;
834 }
835
836 /*
837 * Allocate an array to hold, in order, the pointers to the slave
838 * structures corresponding to the windows specified. Some of those
839 * structures may already have existed, some may be new.
840 */
841 inserts = (Slave **)ckalloc(sizeof(Slave *) * (firstOptionArg - 2));
842 insertIndex = 0;
843
844 /*
845 * Populate the inserts array, creating new slave structures as necessary,
846 * applying the options to each structure as we go, and, if necessary,
847 * marking the spot in the original slaves array as empty (for pre-existing
848 * slave structures).
849 */
850 for (i = 0, numNewSlaves = 0; i < firstOptionArg - 2; i++) {
851 /*
852 * We don't check that tkwin is NULL here, because the pre-pass above
853 * guarantees that the input at this stage is good.
854 */
855 tkwin = Tk_NameToWindow(interp, Tcl_GetString(objv[i + 2]),
856 pwPtr->tkwin);
857
858 found = 0;
859 for (j = 0; j < pwPtr->numSlaves; j++) {
860 if (pwPtr->slaves[j] != NULL && pwPtr->slaves[j]->tkwin == tkwin) {
861 Tk_SetOptions(interp, (char *) pwPtr->slaves[j],
862 pwPtr->slaveOpts, objc - firstOptionArg,
863 objv + firstOptionArg, pwPtr->tkwin, NULL, NULL);
864 found = 1;
865
866 /*
867 * If the slave is supposed to move, add it to the inserts
868 * array now; otherwise, leave it where it is.
869 */
870
871 if (index != -1) {
872 inserts[insertIndex++] = pwPtr->slaves[j];
873 pwPtr->slaves[j] = NULL;
874 }
875 break;
876 }
877 }
878
879 if (found) {
880 continue;
881 }
882
883 /*
884 * Make sure this slave wasn't already put into the inserts array,
885 * ie, when the user specifies the same window multiple times in
886 * a single add commaned.
887 */
888 for (j = 0; j < insertIndex; j++) {
889 if (inserts[j]->tkwin == tkwin) {
890 found = 1;
891 break;
892 }
893 }
894 if (found) {
895 continue;
896 }
897
898 /*
899 * Create a new slave structure and initialize it. All slaves
900 * start out with their "natural" dimensions.
901 */
902
903 slavePtr = (Slave *) ckalloc(sizeof(Slave));
904 memset(slavePtr, 0, sizeof(Slave));
905 Tk_InitOptions(interp, (char *)slavePtr, pwPtr->slaveOpts,
906 pwPtr->tkwin);
907 Tk_SetOptions(interp, (char *)slavePtr, pwPtr->slaveOpts,
908 objc - firstOptionArg, objv + firstOptionArg,
909 pwPtr->tkwin, NULL, NULL);
910 slavePtr->tkwin = tkwin;
911 slavePtr->masterPtr = pwPtr;
912 doubleBw = 2 * Tk_Changes(slavePtr->tkwin)->border_width;
913 if (slavePtr->width > 0) {
914 slavePtr->paneWidth = slavePtr->width;
915 } else {
916 slavePtr->paneWidth = Tk_ReqWidth(tkwin) + doubleBw;
917 }
918 if (slavePtr->height > 0) {
919 slavePtr->paneHeight = slavePtr->height;
920 } else {
921 slavePtr->paneHeight = Tk_ReqHeight(tkwin) + doubleBw;
922 }
923
924 /*
925 * Set up the geometry management callbacks for this slave.
926 */
927
928 Tk_CreateEventHandler(slavePtr->tkwin, StructureNotifyMask,
929 SlaveStructureProc, (ClientData) slavePtr);
930 Tk_ManageGeometry(slavePtr->tkwin, &panedWindowMgrType,
931 (ClientData) slavePtr);
932 inserts[insertIndex++] = slavePtr;
933 numNewSlaves++;
934 }
935
936 /*
937 * Allocate the new slaves array, then copy the slaves into it, in
938 * order.
939 */
940 i = sizeof(Slave *) * (pwPtr->numSlaves+numNewSlaves);
941 new = (Slave **)ckalloc((unsigned) i);
942 memset(new, 0, (size_t) i);
943 if (index == -1) {
944 /*
945 * If none of the existing slaves have to be moved, just copy the old
946 * and append the new.
947 */
948 memcpy((void *)&(new[0]), pwPtr->slaves,
949 sizeof(Slave *) * pwPtr->numSlaves);
950 memcpy((void *)&(new[pwPtr->numSlaves]), inserts,
951 sizeof(Slave *) * numNewSlaves);
952 } else {
953 /*
954 * If some of the existing slaves were moved, the old slaves array
955 * will be partially populated, with some valid and some invalid
956 * entries. Walk through it, copying valid entries to the new slaves
957 * array as we go; when we get to the insert location for the new
958 * slaves, copy the inserts array over, then finish off the old slaves
959 * array.
960 */
961 for (i = 0, j = 0; i < index; i++) {
962 if (pwPtr->slaves[i] != NULL) {
963 new[j] = pwPtr->slaves[i];
964 j++;
965 }
966 }
967
968 memcpy((void *)&(new[j]), inserts, sizeof(Slave *) * (insertIndex));
969 j += firstOptionArg - 2;
970
971 for (i = index; i < pwPtr->numSlaves; i++) {
972 if (pwPtr->slaves[i] != NULL) {
973 new[j] = pwPtr->slaves[i];
974 j++;
975 }
976 }
977 }
978
979 /*
980 * Make the new slaves array the paned window's slave array, and clean up.
981 */
982 ckfree((void *)pwPtr->slaves);
983 ckfree((void *)inserts);
984 pwPtr->slaves = new;
985
986 /*
987 * Set the paned window's slave count to the new value.
988 */
989 pwPtr->numSlaves += numNewSlaves;
990
991 Tk_FreeConfigOptions((char *) &options, pwPtr->slaveOpts, pwPtr->tkwin);
992
993 ComputeGeometry(pwPtr);
994 return TCL_OK;
995 }
996
997 /*
998 *----------------------------------------------------------------------
999 *
1000 * PanedWindowSashCommand --
1001 *
1002 * Implementation of the panedwindow sash subcommand. See the user
1003 * documentation for details on what it does.
1004 *
1005 * Results:
1006 * Standard Tcl result.
1007 *
1008 * Side effects:
1009 * Depends on the arguments.
1010 *
1011 *----------------------------------------------------------------------
1012 */
1013
1014 static int
1015 PanedWindowSashCommand(pwPtr, interp, objc, objv)
1016 PanedWindow *pwPtr; /* Pointer to paned window information. */
1017 Tcl_Interp *interp; /* Current interpreter. */
1018 int objc; /* Number of arguments. */
1019 Tcl_Obj * CONST objv[]; /* Argument objects. */
1020 {
1021 static CONST char *sashOptionStrings[] = { "coord", "dragto", "mark",
1022 "place", (char *) NULL };
1023 enum sashOptions { SASH_COORD, SASH_DRAGTO, SASH_MARK, SASH_PLACE };
1024 int index, sash, x, y, diff;
1025 Tcl_Obj *coords[2];
1026 Slave *slavePtr;
1027
1028 if (objc < 3) {
1029 Tcl_WrongNumArgs(interp, 2, objv, "option ?arg ...?");
1030 return TCL_ERROR;
1031 }
1032
1033 if (Tcl_GetIndexFromObj(interp, objv[2], sashOptionStrings,
1034 "option", 0, &index) != TCL_OK) {
1035 return TCL_ERROR;
1036 }
1037
1038 Tcl_ResetResult(interp);
1039 switch ((enum sashOptions) index) {
1040 case SASH_COORD: {
1041 if (objc != 4) {
1042 Tcl_WrongNumArgs(interp, 3, objv, "index");
1043 return TCL_ERROR;
1044 }
1045
1046 if (Tcl_GetIntFromObj(interp, objv[3], &sash) != TCL_OK) {
1047 return TCL_ERROR;
1048 }
1049
1050 if (!ValidSashIndex(pwPtr, sash)) {
1051 Tcl_ResetResult(interp);
1052 Tcl_SetResult(interp, "invalid sash index", TCL_STATIC);
1053 return TCL_ERROR;
1054 }
1055 slavePtr = pwPtr->slaves[sash];
1056
1057 coords[0] = Tcl_NewIntObj(slavePtr->sashx);
1058 coords[1] = Tcl_NewIntObj(slavePtr->sashy);
1059 Tcl_SetListObj(Tcl_GetObjResult(interp), 2, coords);
1060 break;
1061 }
1062
1063 case SASH_MARK: {
1064 if (objc != 6 && objc != 4) {
1065 Tcl_WrongNumArgs(interp, 3, objv, "index ?x y?");
1066 return TCL_ERROR;
1067 }
1068
1069 if (Tcl_GetIntFromObj(interp, objv[3], &sash) != TCL_OK) {
1070 return TCL_ERROR;
1071 }
1072
1073 if (!ValidSashIndex(pwPtr, sash)) {
1074 Tcl_ResetResult(interp);
1075 Tcl_SetResult(interp, "invalid sash index", TCL_STATIC);
1076 return TCL_ERROR;
1077 }
1078
1079 if (objc == 6) {
1080 if (Tcl_GetIntFromObj(interp, objv[4], &x) != TCL_OK) {
1081 return TCL_ERROR;
1082 }
1083
1084 if (Tcl_GetIntFromObj(interp, objv[5], &y) != TCL_OK) {
1085 return TCL_ERROR;
1086 }
1087
1088 pwPtr->slaves[sash]->markx = x;
1089 pwPtr->slaves[sash]->marky = y;
1090 } else {
1091 coords[0] = Tcl_NewIntObj(pwPtr->slaves[sash]->markx);
1092 coords[1] = Tcl_NewIntObj(pwPtr->slaves[sash]->marky);
1093 Tcl_SetListObj(Tcl_GetObjResult(interp), 2, coords);
1094 }
1095
1096 break;
1097 }
1098
1099 case SASH_DRAGTO:
1100 case SASH_PLACE: {
1101 if (objc != 6) {
1102 Tcl_WrongNumArgs(interp, 3, objv, "index x y");
1103 return TCL_ERROR;
1104 }
1105
1106 if (Tcl_GetIntFromObj(interp, objv[3], &sash) != TCL_OK) {
1107 return TCL_ERROR;
1108 }
1109
1110 if (!ValidSashIndex(pwPtr, sash)) {
1111 Tcl_ResetResult(interp);
1112 Tcl_SetResult(interp, "invalid sash index", TCL_STATIC);
1113 return TCL_ERROR;
1114 }
1115
1116 if (Tcl_GetIntFromObj(interp, objv[4], &x) != TCL_OK) {
1117 return TCL_ERROR;
1118 }
1119
1120 if (Tcl_GetIntFromObj(interp, objv[5], &y) != TCL_OK) {
1121 return TCL_ERROR;
1122 }
1123
1124 slavePtr = pwPtr->slaves[sash];
1125 if (pwPtr->orient == ORIENT_HORIZONTAL) {
1126 if (index == SASH_PLACE) {
1127 diff = x - pwPtr->slaves[sash]->sashx;
1128 } else {
1129 diff = x - pwPtr->slaves[sash]->markx;
1130 }
1131 } else {
1132 if (index == SASH_PLACE) {
1133 diff = y - pwPtr->slaves[sash]->sashy;
1134 } else {
1135 diff = y - pwPtr->slaves[sash]->marky;
1136 }
1137 }
1138
1139 MoveSash(pwPtr, sash, diff);
1140 ComputeGeometry(pwPtr);
1141 }
1142 }
1143 return TCL_OK;
1144 }
1145
1146 /*
1147 *----------------------------------------------------------------------
1148 *
1149 * ConfigurePanedWindow --
1150 *
1151 * This procedure is called to process an argv/argc list in
1152 * conjunction with the Tk option database to configure (or
1153 * reconfigure) a paned window widget.
1154 *
1155 * Results:
1156 * The return value is a standard Tcl result. If TCL_ERROR is
1157 * returned, then the interp's result contains an error message.
1158 *
1159 * Side effects:
1160 * Configuration information, such as colors, border width,
1161 * etc. get set for pwPtr; old resources get freed,
1162 * if there were any.
1163 *
1164 *----------------------------------------------------------------------
1165 */
1166
1167 static int
1168 ConfigurePanedWindow(interp, pwPtr, objc, objv)
1169 Tcl_Interp *interp; /* Used for error reporting. */
1170 PanedWindow *pwPtr; /* Information about widget. */
1171 int objc; /* Number of arguments. */
1172 Tcl_Obj *CONST objv[]; /* Argument values. */
1173 {
1174 Tk_SavedOptions savedOptions;
1175 int typemask = 0;
1176
1177 if (Tk_SetOptions(interp, (char *) pwPtr, pwPtr->optionTable, objc, objv,
1178 pwPtr->tkwin, &savedOptions, &typemask) != TCL_OK) {
1179 Tk_RestoreSavedOptions(&savedOptions);
1180 return TCL_ERROR;
1181 }
1182
1183 Tk_FreeSavedOptions(&savedOptions);
1184
1185 PanedWindowWorldChanged((ClientData) pwPtr);
1186
1187 /*
1188 * If an option that affects geometry has changed, make a relayout
1189 * request.
1190 */
1191
1192 if (typemask & GEOMETRY) {
1193 ComputeGeometry(pwPtr);
1194 }
1195
1196 return TCL_OK;
1197 }
1198
1199 /*
1200 *----------------------------------------------------------------------
1201 *
1202 * PanedWindowWorldChanged --
1203 *
1204 * This procedure is invoked anytime a paned window's world has
1205 * changed in some way that causes the widget to have to recompute
1206 * graphics contexts and geometry.
1207 *
1208 * Results:
1209 * None.
1210 *
1211 * Side effects:
1212 * Paned window will be relayed out and redisplayed.
1213 *
1214 *----------------------------------------------------------------------
1215 */
1216
1217 void
1218 PanedWindowWorldChanged(instanceData)
1219 ClientData instanceData; /* Information about the paned window. */
1220 {
1221 XGCValues gcValues;
1222 GC newGC;
1223 PanedWindow *pwPtr = (PanedWindow *) instanceData;
1224
1225 /*
1226 * Allocated a graphics context for drawing the paned window widget
1227 * elements (background, sashes, etc.) and set the window background.
1228 */
1229
1230 gcValues.background = Tk_3DBorderColor(pwPtr->background)->pixel;
1231 newGC = Tk_GetGC(pwPtr->tkwin, GCBackground, &gcValues);
1232 if (pwPtr->gc != None) {
1233 Tk_FreeGC(pwPtr->display, pwPtr->gc);
1234 }
1235 pwPtr->gc = newGC;
1236 Tk_SetWindowBackground(pwPtr->tkwin, gcValues.background);
1237
1238 /*
1239 * Issue geometry size requests to Tk.
1240 */
1241
1242 Tk_SetInternalBorder(pwPtr->tkwin, pwPtr->borderWidth);
1243 if (pwPtr->width > 0 || pwPtr->height > 0) {
1244 Tk_GeometryRequest(pwPtr->tkwin, pwPtr->width, pwPtr->height);
1245 }
1246
1247 /*
1248 * Arrange for the window to be redrawn, if neccessary.
1249 */
1250
1251 if (Tk_IsMapped(pwPtr->tkwin) && !(pwPtr->flags & REDRAW_PENDING)) {
1252 Tcl_DoWhenIdle(DisplayPanedWindow, (ClientData) pwPtr);
1253 pwPtr->flags |= REDRAW_PENDING;
1254 }
1255 }
1256
1257 /*
1258 *--------------------------------------------------------------
1259 *
1260 * PanedWindowEventProc --
1261 *
1262 * This procedure is invoked by the Tk dispatcher for various
1263 * events on paned windows.
1264 *
1265 * Results:
1266 * None.
1267 *
1268 * Side effects:
1269 * When the window gets deleted, internal structures get
1270 * cleaned up. When it gets exposed, it is redisplayed.
1271 *
1272 *--------------------------------------------------------------
1273 */
1274
1275 static void
1276 PanedWindowEventProc(clientData, eventPtr)
1277 ClientData clientData; /* Information about window. */
1278 XEvent *eventPtr; /* Information about event. */
1279 {
1280 PanedWindow *pwPtr = (PanedWindow *) clientData;
1281
1282 if (eventPtr->type == Expose) {
1283 if (pwPtr->tkwin != NULL && !(pwPtr->flags & REDRAW_PENDING)) {
1284 Tcl_DoWhenIdle(DisplayPanedWindow, (ClientData) pwPtr);
1285 pwPtr->flags |= REDRAW_PENDING;
1286 }
1287 } else if (eventPtr->type == ConfigureNotify) {
1288 pwPtr->flags |= REQUESTED_RELAYOUT;
1289 if (pwPtr->tkwin != NULL && !(pwPtr->flags & REDRAW_PENDING)) {
1290 Tcl_DoWhenIdle(DisplayPanedWindow, (ClientData) pwPtr);
1291 pwPtr->flags |= REDRAW_PENDING;
1292 }
1293 } else if (eventPtr->type == DestroyNotify) {
1294 DestroyPanedWindow(pwPtr);
1295 }
1296 }
1297
1298 /*
1299 *----------------------------------------------------------------------
1300 *
1301 * PanedWindowCmdDeletedProc --
1302 *
1303 * This procedure is invoked when a widget command is deleted. If
1304 * the widget isn't already in the process of being destroyed,
1305 * this command destroys it.
1306 *
1307 * Results:
1308 * None.
1309 *
1310 * Side effects:
1311 * The widget is destroyed.
1312 *
1313 *----------------------------------------------------------------------
1314 */
1315
1316 static void
1317 PanedWindowCmdDeletedProc(clientData)
1318 ClientData clientData; /* Pointer to widget record for widget. */
1319 {
1320 PanedWindow *pwPtr = (PanedWindow *) clientData;
1321
1322 /*
1323 * This procedure could be invoked either because the window was
1324 * destroyed and the command was then deleted or because the command was
1325 * deleted, and then this procedure destroys the widget. The
1326 * WIDGET_DELETED flag distinguishes these cases.
1327 */
1328
1329 if (!(pwPtr->flags & WIDGET_DELETED)) {
1330 Tk_DestroyWindow(pwPtr->proxywin);
1331 Tk_DestroyWindow(pwPtr->tkwin);
1332 }
1333 }
1334
1335 /*
1336 *--------------------------------------------------------------
1337 *
1338 * DisplayPanedWindow --
1339 *
1340 * This procedure redraws the contents of a paned window widget.
1341 * It is invoked as a do-when-idle handler, so it only runs
1342 * when there's nothing else for the application to do.
1343 *
1344 * Results:
1345 * None.
1346 *
1347 * Side effects:
1348 * Information appears on the screen.
1349 *
1350 *--------------------------------------------------------------
1351 */
1352
1353 static void
1354 DisplayPanedWindow(clientData)
1355 ClientData clientData; /* Information about window. */
1356 {
1357 PanedWindow *pwPtr = (PanedWindow *) clientData;
1358 Pixmap pixmap;
1359 Tk_Window tkwin = pwPtr->tkwin;
1360 int i, sashWidth, sashHeight;
1361
1362 pwPtr->flags &= ~REDRAW_PENDING;
1363 if ((pwPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) {
1364 return;
1365 }
1366
1367 if (pwPtr->flags & REQUESTED_RELAYOUT) {
1368 ArrangePanes(clientData);
1369 }
1370
1371 /*
1372 * Create a pixmap for double-buffering, if necessary.
1373 */
1374
1375 pixmap = Tk_GetPixmap(Tk_Display(tkwin), Tk_WindowId(tkwin),
1376 Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin));
1377
1378 /*
1379 * Redraw the widget's background and border.
1380 */
1381 Tk_Fill3DRectangle(tkwin, pixmap, pwPtr->background, 0, 0,
1382 Tk_Width(tkwin), Tk_Height(tkwin), pwPtr->borderWidth,
1383 pwPtr->relief);
1384
1385 /*
1386 * Set up boilerplate geometry values for sashes (width, height, common
1387 * coordinates).
1388 */
1389
1390 if (pwPtr->orient == ORIENT_HORIZONTAL) {
1391 sashHeight = Tk_Height(tkwin) - (2 * Tk_InternalBorderWidth(tkwin));
1392 sashWidth = pwPtr->sashWidth;
1393 } else {
1394 sashWidth = Tk_Width(tkwin) - (2 * Tk_InternalBorderWidth(tkwin));
1395 sashHeight = pwPtr->sashWidth;
1396 }
1397
1398 /*
1399 * Draw the sashes.
1400 */
1401 for (i = 0; i < pwPtr->numSlaves - 1; i++) {
1402 Tk_Fill3DRectangle(tkwin, pixmap, pwPtr->background,
1403 pwPtr->slaves[i]->sashx, pwPtr->slaves[i]->sashy,
1404 sashWidth, sashHeight, 1, pwPtr->sashRelief);
1405
1406 if (pwPtr->showHandle) {
1407 Tk_Fill3DRectangle(tkwin, pixmap, pwPtr->background,
1408 pwPtr->slaves[i]->handlex, pwPtr->slaves[i]->handley,
1409 pwPtr->handleSize, pwPtr->handleSize, 1,
1410 TK_RELIEF_RAISED);
1411 }
1412 }
1413
1414 /*
1415 * Copy the information from the off-screen pixmap onto the screen,
1416 * then delete the pixmap.
1417 */
1418
1419 XCopyArea(Tk_Display(tkwin), pixmap, Tk_WindowId(tkwin), pwPtr->gc,
1420 0, 0, (unsigned) Tk_Width(tkwin), (unsigned) Tk_Height(tkwin),
1421 0, 0);
1422 Tk_FreePixmap(Tk_Display(tkwin), pixmap);
1423 }
1424
1425 /*
1426 *----------------------------------------------------------------------
1427 *
1428 * DestroyPanedWindow --
1429 *
1430 * This procedure is invoked by PanedWindowEventProc to free the
1431 * internal structure of a paned window.
1432 *
1433 * Results:
1434 * None.
1435 *
1436 * Side effects:
1437 * Everything associated with the paned window is freed up.
1438 *
1439 *----------------------------------------------------------------------
1440 */
1441
1442 static void
1443 DestroyPanedWindow(pwPtr)
1444 PanedWindow *pwPtr; /* Info about paned window widget. */
1445 {
1446 int i;
1447
1448 /*
1449 * First mark the widget as in the process of being deleted,
1450 * so that any code that causes calls to other paned window procedures
1451 * will abort.
1452 */
1453
1454 pwPtr->flags |= WIDGET_DELETED;
1455
1456 /*
1457 * Cancel idle callbacks for redrawing the widget and for rearranging
1458 * the panes.
1459 */
1460 if (pwPtr->flags & REDRAW_PENDING) {
1461 Tcl_CancelIdleCall(DisplayPanedWindow, (ClientData) pwPtr);
1462 }
1463 if (pwPtr->flags & RESIZE_PENDING) {
1464 Tcl_CancelIdleCall(ArrangePanes, (ClientData) pwPtr);
1465 }
1466
1467 /*
1468 * Clean up the slave list; foreach slave:
1469 * o Cancel the slave's structure notification callback
1470 * o Cancel geometry management for the slave.
1471 * o Free memory for the slave
1472 */
1473
1474 for (i = 0; i < pwPtr->numSlaves; i++) {
1475 Tk_DeleteEventHandler(pwPtr->slaves[i]->tkwin, StructureNotifyMask,
1476 SlaveStructureProc, (ClientData) pwPtr->slaves[i]);
1477 Tk_ManageGeometry(pwPtr->slaves[i]->tkwin, NULL, NULL);
1478 Tk_FreeConfigOptions((char *)pwPtr->slaves[i], pwPtr->slaveOpts,
1479 pwPtr->tkwin);
1480 ckfree((void *)pwPtr->slaves[i]);
1481 pwPtr->slaves[i] = NULL;
1482 }
1483 if (pwPtr->slaves) {
1484 ckfree((char *) pwPtr->slaves);
1485 }
1486
1487 /*
1488 * Remove the widget command from the interpreter.
1489 */
1490
1491 Tcl_DeleteCommandFromToken(pwPtr->interp, pwPtr->widgetCmd);
1492
1493 /*
1494 * Let Tk_FreeConfigOptions clean up the rest.
1495 */
1496
1497 Tk_FreeConfigOptions((char *) pwPtr, pwPtr->optionTable, pwPtr->tkwin);
1498 Tcl_Release((ClientData) pwPtr->tkwin);
1499 pwPtr->tkwin = NULL;
1500
1501 Tcl_EventuallyFree((ClientData) pwPtr, TCL_DYNAMIC);
1502 }
1503
1504 /*
1505 *--------------------------------------------------------------
1506 *
1507 * PanedWindowReqProc --
1508 *
1509 * This procedure is invoked by Tk_GeometryRequest for
1510 * windows managed by a paned window.
1511 *
1512 * Results:
1513 * None.
1514 *
1515 * Side effects:
1516 * Arranges for tkwin, and all its managed siblings, to
1517 * be re-arranged at the next idle point.
1518 *
1519 *--------------------------------------------------------------
1520 */
1521
1522 static void
1523 PanedWindowReqProc(clientData, tkwin)
1524 ClientData clientData; /* Paned window's information about
1525 * window that got new preferred
1526 * geometry. */
1527 Tk_Window tkwin; /* Other Tk-related information
1528 * about the window. */
1529 {
1530 Slave *slavePtr = (Slave *) clientData;
1531 PanedWindow *pwPtr = (PanedWindow *) (slavePtr->masterPtr);
1532 if (Tk_IsMapped(pwPtr->tkwin)) {
1533 if (!(pwPtr->flags & RESIZE_PENDING)) {
1534 pwPtr->flags |= RESIZE_PENDING;
1535 Tcl_DoWhenIdle(ArrangePanes, (ClientData) pwPtr);
1536 }
1537 } else {
1538 int doubleBw = 2 * Tk_Changes(slavePtr->tkwin)->border_width;
1539 if (slavePtr->width <= 0) {
1540 slavePtr->paneWidth = Tk_ReqWidth(slavePtr->tkwin) + doubleBw;
1541 }
1542 if (slavePtr->height <= 0) {
1543 slavePtr->paneHeight = Tk_ReqHeight(slavePtr->tkwin) + doubleBw;
1544 }
1545 ComputeGeometry(pwPtr);
1546 }
1547 }
1548
1549 /*
1550 *--------------------------------------------------------------
1551 *
1552 * PanedWindowLostSlaveProc --
1553 *
1554 * This procedure is invoked by Tk whenever some other geometry
1555 * claims control over a slave that used to be managed by us.
1556 *
1557 * Results:
1558 * None.
1559 *
1560 * Side effects:
1561 * Forgets all information about the slave. Causes geometry to
1562 * be recomputed for the panedwindow.
1563 *
1564 *--------------------------------------------------------------
1565 */
1566
1567 static void
1568 PanedWindowLostSlaveProc(clientData, tkwin)
1569 ClientData clientData; /* Grid structure for slave window that
1570 * was stolen away. */
1571 Tk_Window tkwin; /* Tk's handle for the slave window. */
1572 {
1573 register Slave *slavePtr = (Slave *) clientData;
1574 PanedWindow *pwPtr = (PanedWindow *) (slavePtr->masterPtr);
1575 if (pwPtr->tkwin != Tk_Parent(slavePtr->tkwin)) {
1576 Tk_UnmaintainGeometry(slavePtr->tkwin, pwPtr->tkwin);
1577 }
1578 Unlink(slavePtr);
1579 Tk_DeleteEventHandler(slavePtr->tkwin, StructureNotifyMask,
1580 SlaveStructureProc, (ClientData) slavePtr);
1581 Tk_UnmapWindow(slavePtr->tkwin);
1582 slavePtr->tkwin = NULL;
1583 ckfree((void *)slavePtr);
1584 ComputeGeometry(pwPtr);
1585 }
1586
1587 /*
1588 *--------------------------------------------------------------
1589 *
1590 * ArrangePanes --
1591 *
1592 * This procedure is invoked (using the Tcl_DoWhenIdle
1593 * mechanism) to re-layout a set of windows managed by
1594 * a paned window. It is invoked at idle time so that a
1595 * series of pane requests can be merged into a single
1596 * layout operation.
1597 *
1598 * Results:
1599 * None.
1600 *
1601 * Side effects:
1602 * The slaves of masterPtr may get resized or moved.
1603 *
1604 *--------------------------------------------------------------
1605 */
1606
1607 static void
1608 ArrangePanes(clientData)
1609 ClientData clientData; /* Structure describing parent whose slaves
1610 * are to be re-layed out. */
1611 {
1612 register PanedWindow *pwPtr = (PanedWindow *) clientData;
1613 register Slave *slavePtr;
1614 int i, slaveWidth, slaveHeight, slaveX, slaveY, paneWidth, paneHeight;
1615 int doubleBw;
1616
1617 pwPtr->flags &= ~(REQUESTED_RELAYOUT|RESIZE_PENDING);
1618
1619 /*
1620 * If the parent has no slaves anymore, then don't do anything
1621 * at all: just leave the parent's size as-is. Otherwise there is
1622 * no way to "relinquish" control over the parent so another geometry
1623 * manager can take over.
1624 */
1625
1626 if (pwPtr->numSlaves == 0) {
1627 return;
1628 }
1629
1630 Tcl_Preserve((ClientData) pwPtr);
1631 for (i = 0; i < pwPtr->numSlaves; i++) {
1632 slavePtr = pwPtr->slaves[i];
1633
1634 /*
1635 * Compute the size of this slave. The algorithm (assuming a
1636 * horizontal paned window) is:
1637 *
1638 * 1. Get "base" dimensions. If a width or height is specified
1639 * for this slave, use those values; else use the
1640 * ReqWidth/ReqHeight.
1641 * 2. Using base dimensions, pane dimensions, and sticky values,
1642 * determine the x and y, and actual width and height of the
1643 * widget.
1644 */
1645
1646 doubleBw = 2 * Tk_Changes(slavePtr->tkwin)->border_width;
1647 slaveWidth = (slavePtr->width > 0 ? slavePtr->width :
1648 Tk_ReqWidth(slavePtr->tkwin) + doubleBw);
1649 slaveHeight = (slavePtr->height > 0 ? slavePtr->height :
1650 Tk_ReqHeight(slavePtr->tkwin) + doubleBw);
1651
1652 if (pwPtr->orient == ORIENT_HORIZONTAL) {
1653 paneWidth = slavePtr->paneWidth;
1654 if (i == pwPtr->numSlaves - 1 && Tk_IsMapped(pwPtr->tkwin)) {
1655 if (Tk_Width(pwPtr->tkwin) != Tk_ReqWidth(pwPtr->tkwin)) {
1656 paneWidth += Tk_Width(pwPtr->tkwin) -
1657 Tk_ReqWidth(pwPtr->tkwin);
1658 if (paneWidth < 0) {
1659 paneWidth = 0;
1660 }
1661 }
1662 }
1663 paneHeight = Tk_Height(pwPtr->tkwin) - (2 * slavePtr->pady) -
1664 (2 * Tk_InternalBorderWidth(pwPtr->tkwin));
1665 } else {
1666 paneHeight = slavePtr->paneHeight;
1667 if (i == pwPtr->numSlaves - 1 && Tk_IsMapped(pwPtr->tkwin)) {
1668 if (Tk_Height(pwPtr->tkwin) != Tk_ReqHeight(pwPtr->tkwin)) {
1669 paneHeight += Tk_Height(pwPtr->tkwin) -
1670 Tk_ReqHeight(pwPtr->tkwin);
1671 if (paneHeight < 0) {
1672 paneHeight = 0;
1673 }
1674 }
1675 }
1676 paneWidth = Tk_Width(pwPtr->tkwin) - (2 * slavePtr->padx) -
1677 (2 * Tk_InternalBorderWidth(pwPtr->tkwin));
1678 }
1679
1680 if (slaveWidth > paneWidth) {
1681 slaveWidth = paneWidth;
1682 }
1683 if (slaveHeight > paneHeight) {
1684 slaveHeight = paneHeight;
1685 }
1686
1687 slaveX = slavePtr->x;
1688 slaveY = slavePtr->y;
1689 AdjustForSticky(slavePtr->sticky, paneWidth, paneHeight,
1690 &slaveX, &slaveY, &slaveWidth, &slaveHeight);
1691
1692 slaveX += slavePtr->padx;
1693 slaveY += slavePtr->pady;
1694
1695 /*
1696 * Now put the window in the proper spot.
1697 */
1698 if ((slaveWidth <= 0) || (slaveHeight <= 0)) {
1699 Tk_UnmaintainGeometry(slavePtr->tkwin, pwPtr->tkwin);
1700 Tk_UnmapWindow(slavePtr->tkwin);
1701 } else {
1702 Tk_MaintainGeometry(slavePtr->tkwin, pwPtr->tkwin,
1703 slaveX, slaveY, slaveWidth, slaveHeight);
1704 }
1705 }
1706 Tcl_Release((ClientData) pwPtr);
1707 }
1708
1709 /*
1710 *----------------------------------------------------------------------
1711 *
1712 * Unlink --
1713 *
1714 * Remove a slave from a paned window.
1715 *
1716 * Results:
1717 * None.
1718 *
1719 * Side effects:
1720 * The paned window will be scheduled for re-arranging and redrawing.
1721 *
1722 *----------------------------------------------------------------------
1723 */
1724
1725 static void
1726 Unlink(slavePtr)
1727 register Slave *slavePtr; /* Window to unlink. */
1728 {
1729 register PanedWindow *masterPtr;
1730 int i, j;
1731
1732 masterPtr = slavePtr->masterPtr;
1733 if (masterPtr == NULL) {
1734 return;
1735 }
1736
1737 /*
1738 * Find the specified slave in the panedwindow's list of slaves, then
1739 * remove it from that list.
1740 */
1741
1742 for (i = 0; i < masterPtr->numSlaves; i++) {
1743 if (masterPtr->slaves[i] == slavePtr) {
1744 for (j = i; j < masterPtr->numSlaves - 1; j++) {
1745 masterPtr->slaves[j] = masterPtr->slaves[j + 1];
1746 }
1747 break;
1748 }
1749 }
1750
1751 masterPtr->flags |= REQUESTED_RELAYOUT;
1752 if (!(masterPtr->flags & REDRAW_PENDING)) {
1753 masterPtr->flags |= REDRAW_PENDING;
1754 Tcl_DoWhenIdle(DisplayPanedWindow, (ClientData) masterPtr);
1755 }
1756
1757 /*
1758 * Set the slave's masterPtr to NULL, so that we can tell that the
1759 * slave is no longer attached to any panedwindow.
1760 */
1761 slavePtr->masterPtr = NULL;
1762
1763 masterPtr->numSlaves--;
1764 }
1765
1766 /*
1767 *----------------------------------------------------------------------
1768 *
1769 * GetPane --
1770 *
1771 * Given a token to a Tk window, find the pane that corresponds to
1772 * that token in a given paned window.
1773 *
1774 * Results:
1775 * Pointer to the slave structure, or NULL if the window is not
1776 * managed by this paned window.
1777 *
1778 * Side effects:
1779 * None.
1780 *
1781 *----------------------------------------------------------------------
1782 */
1783
1784 static Slave *
1785 GetPane(pwPtr, tkwin)
1786 PanedWindow *pwPtr; /* Pointer to the paned window info. */
1787 Tk_Window tkwin; /* Window to search for. */
1788 {
1789 int i;
1790 for (i = 0; i < pwPtr->numSlaves; i++) {
1791 if (pwPtr->slaves[i]->tkwin == tkwin) {
1792 return pwPtr->slaves[i];
1793 }
1794 }
1795 return NULL;
1796 }
1797
1798 /*
1799 *--------------------------------------------------------------
1800 *
1801 * SlaveStructureProc --
1802 *
1803 * This procedure is invoked whenever StructureNotify events
1804 * occur for a window that's managed by a paned window. This
1805 * procedure's only purpose is to clean up when windows are
1806 * deleted.
1807 *
1808 * Results:
1809 * None.
1810 *
1811 * Side effects:
1812 * The paned window slave structure associated with the window
1813 * is freed, and the slave is disassociated from the paned
1814 * window which managed it.
1815 *
1816 *--------------------------------------------------------------
1817 */
1818
1819 static void
1820 SlaveStructureProc(clientData, eventPtr)
1821 ClientData clientData; /* Pointer to record describing window item. */
1822 XEvent *eventPtr; /* Describes what just happened. */
1823 {
1824 Slave *slavePtr = (Slave *) clientData;
1825 PanedWindow *pwPtr = slavePtr->masterPtr;
1826
1827 if (eventPtr->type == DestroyNotify) {
1828 Unlink(slavePtr);
1829 slavePtr->tkwin = NULL;
1830 ckfree((void *)slavePtr);
1831 ComputeGeometry(pwPtr);
1832 }
1833 }
1834
1835 /*
1836 *----------------------------------------------------------------------
1837 *
1838 * ComputeGeometry --
1839 *
1840 * Compute geometry for the paned window, including coordinates of
1841 * all slave windows and each sash.
1842 *
1843 * Results:
1844 * None.
1845 *
1846 * Side effects:
1847 * Recomputes geometry information for a paned window.
1848 *
1849 *----------------------------------------------------------------------
1850 */
1851
1852 static void
1853 ComputeGeometry(pwPtr)
1854 PanedWindow *pwPtr; /* Pointer to the Paned Window structure. */
1855 {
1856 int i, x, y, doubleBw, internalBw;
1857 int reqWidth, reqHeight, sashWidth, sxOff, syOff, hxOff, hyOff, dim;
1858 Slave *slavePtr;
1859
1860 pwPtr->flags |= REQUESTED_RELAYOUT;
1861
1862 x = y = internalBw = Tk_InternalBorderWidth(pwPtr->tkwin);
1863 reqWidth = reqHeight = 0;
1864
1865 /*
1866 * Sashes and handles share space on the display. To simplify
1867 * processing below, precompute the x and y offsets of the handles and
1868 * sashes within the space occupied by their combination; later, just add
1869 * those offsets blindly (avoiding the extra showHandle, etc, checks).
1870 */
1871 sxOff = syOff = hxOff = hyOff = 0;
1872 if (pwPtr->showHandle && pwPtr->handleSize > pwPtr->sashWidth) {
1873 sashWidth = pwPtr->handleSize;
1874 if (pwPtr->orient == ORIENT_HORIZONTAL) {
1875 sxOff = (pwPtr->handleSize - pwPtr->sashWidth) / 2;
1876 hyOff = pwPtr->handlePad;
1877 } else {
1878 syOff = (pwPtr->handleSize - pwPtr->sashWidth) / 2;
1879 hxOff = pwPtr->handlePad;
1880 }
1881 } else {
1882 sashWidth = pwPtr->sashWidth;
1883 if (pwPtr->orient == ORIENT_HORIZONTAL) {
1884 hxOff = (pwPtr->handleSize - pwPtr->sashWidth) / 2;
1885 hyOff = pwPtr->handlePad;
1886 } else {
1887 hyOff = (pwPtr->handleSize - pwPtr->sashWidth) / 2;
1888 hxOff = pwPtr->handlePad;
1889 }
1890 }
1891
1892 for (i = 0; i < pwPtr->numSlaves; i++) {
1893 slavePtr = pwPtr->slaves[i];
1894 /*
1895 * First set the coordinates for the top left corner of the slave's
1896 * parcel.
1897 */
1898 slavePtr->x = x;
1899 slavePtr->y = y;
1900
1901 /*
1902 * Make sure the pane's paned dimension is at least minsize.
1903 * This check may be redundant, since the only way to change a pane's
1904 * size is by moving a sash, and that code checks the minsize.
1905 */
1906 if (pwPtr->orient == ORIENT_HORIZONTAL) {
1907 if (slavePtr->paneWidth < slavePtr->minSize) {
1908 slavePtr->paneWidth = slavePtr->minSize;
1909 }
1910 } else {
1911 if (slavePtr->paneHeight < slavePtr->minSize) {
1912 slavePtr->paneHeight = slavePtr->minSize;
1913 }
1914 }
1915
1916 /*
1917 * Compute the location of the sash at the right or bottom of the
1918 * parcel.
1919 */
1920 if (pwPtr->orient == ORIENT_HORIZONTAL) {
1921 x += slavePtr->paneWidth + (2 * slavePtr->padx) + pwPtr->sashPad;
1922 } else {
1923 y += slavePtr->paneHeight + (2 * slavePtr->pady) + pwPtr->sashPad;
1924 }
1925 slavePtr->sashx = x + sxOff;
1926 slavePtr->sashy = y + syOff;
1927 slavePtr->handlex = x + hxOff;
1928 slavePtr->handley = y + hyOff;
1929
1930 /*
1931 * Compute the location of the next parcel.
1932 */
1933
1934 if (pwPtr->orient == ORIENT_HORIZONTAL) {
1935 x += sashWidth + pwPtr->sashPad;
1936 } else {
1937 y += sashWidth + pwPtr->sashPad;
1938 }
1939
1940 /*
1941 * Find the maximum height/width of the slaves, for computing the
1942 * requested height/width of the paned window.
1943 */
1944 if (pwPtr->orient == ORIENT_HORIZONTAL) {
1945 /*
1946 * If the slave has an explicit height set, use that; otherwise,
1947 * use the slave's requested height.
1948 */
1949 if (slavePtr->height > 0) {
1950 dim = slavePtr->height;
1951 } else {
1952 doubleBw = (2 * Tk_Changes(slavePtr->tkwin)->border_width);
1953 dim = Tk_ReqHeight(slavePtr->tkwin) + doubleBw;
1954 }
1955 dim += (2 * slavePtr->pady);
1956 if (dim > reqHeight) {
1957 reqHeight = dim;
1958 }
1959 } else {
1960 /*
1961 * If the slave has an explicit width set use that; otherwise,
1962 * use the slave's requested width.
1963 */
1964 if (slavePtr->width > 0) {
1965 dim = slavePtr->width;
1966 } else {
1967 doubleBw = (2 * Tk_Changes(slavePtr->tkwin)->border_width);
1968 dim = Tk_ReqWidth(slavePtr->tkwin) + doubleBw;
1969 }
1970 dim += (2 * slavePtr->padx);
1971 if (dim > reqWidth) {
1972 reqWidth = dim;
1973 }
1974 }
1975 }
1976
1977 /*
1978 * The loop above should have left x (or y) equal to the sum of the
1979 * widths (or heights) of the widgets, plus the size of one sash and
1980 * the sash padding for each widget, plus the width of the left (or top)
1981 * border of the paned window.
1982 *
1983 * The requested width (or height) is therefore x (or y) minus the size of
1984 * one sash and padding, plus the width of the right (or bottom) border
1985 * of the paned window.
1986 *
1987 * The height (or width) is equal to the maximum height (or width) of
1988 * the slaves, plus the width of the border of the top and bottom (or left
1989 * and right) of the paned window.
1990 */
1991 if (pwPtr->orient == ORIENT_HORIZONTAL) {
1992 reqWidth = x - (sashWidth + (2 * pwPtr->sashPad)) + internalBw;
1993 reqHeight += 2 * internalBw;
1994 } else {
1995 reqHeight = y - (sashWidth + (2 * pwPtr->sashPad)) + internalBw;
1996 reqWidth += 2 * internalBw;
1997 }
1998 if (pwPtr->width <= 0 && pwPtr->height <= 0) {
1999 Tk_GeometryRequest(pwPtr->tkwin, reqWidth, reqHeight);
2000 }
2001 if (Tk_IsMapped(pwPtr->tkwin) && !(pwPtr->flags & REDRAW_PENDING)) {
2002 pwPtr->flags |= REDRAW_PENDING;
2003 Tcl_DoWhenIdle(DisplayPanedWindow, (ClientData) pwPtr);
2004 }
2005 }
2006
2007 /*
2008 *----------------------------------------------------------------------
2009 *
2010 * DestroyOptionTables --
2011 *
2012 * This procedure is registered as an exit callback when the paned window
2013 * command is first called. It cleans up the OptionTables structure
2014 * allocated by that command.
2015 *
2016 * Results:
2017 * None.
2018 *
2019 * Side effects:
2020 * Frees memory.
2021 *
2022 *----------------------------------------------------------------------
2023 */
2024
2025 static void
2026 DestroyOptionTables(clientData, interp)
2027 ClientData clientData; /* Pointer to the OptionTables struct */
2028 Tcl_Interp *interp; /* Pointer to the calling interp */
2029 {
2030 ckfree((char *)clientData);
2031 return;
2032 }
2033
2034 /*
2035 *----------------------------------------------------------------------
2036 *
2037 * GetSticky -
2038 *
2039 * Converts an internal boolean combination of "sticky" bits into a
2040 * a Tcl string obj containing zero or mor of n, s, e, or w.
2041 *
2042 * Results:
2043 * Tcl_Obj containing the string representation of the sticky value.
2044 *
2045 * Side effects:
2046 * Creates a new Tcl_Obj.
2047 *
2048 *----------------------------------------------------------------------
2049 */
2050
2051 static Tcl_Obj *
2052 GetSticky(clientData, tkwin, recordPtr, internalOffset)
2053 ClientData clientData;
2054 Tk_Window tkwin;
2055 char *recordPtr; /* Pointer to widget record. */
2056 int internalOffset; /* Offset within *recordPtr containing the
2057 * sticky value. */
2058 {
2059 int sticky = *(int *)(recordPtr + internalOffset);
2060 static char buffer[5];
2061 int count = 0;
2062
2063 if (sticky & STICK_NORTH) {
2064 buffer[count++] = 'n';
2065 }
2066 if (sticky & STICK_EAST) {
2067 buffer[count++] = 'e';
2068 }
2069 if (sticky & STICK_SOUTH) {
2070 buffer[count++] = 's';
2071 }
2072 if (sticky & STICK_WEST) {
2073 buffer[count++] = 'w';
2074 }
2075 buffer[count] = '\0';
2076
2077 return Tcl_NewStringObj(buffer, -1);
2078 }
2079
2080 /*
2081 *----------------------------------------------------------------------
2082 *
2083 * SetSticky --
2084 *
2085 * Converts a Tcl_Obj representing a widgets stickyness into an
2086 * integer value.
2087 *
2088 * Results:
2089 * Standard Tcl result.
2090 *
2091 * Side effects:
2092 * May store the integer value into the internal representation
2093 * pointer. May change the pointer to the Tcl_Obj to NULL to indicate
2094 * that the specified string was empty and that is acceptable.
2095 *
2096 *----------------------------------------------------------------------
2097 */
2098
2099 static int
2100 SetSticky(clientData, interp, tkwin, value, recordPtr, internalOffset,
2101 oldInternalPtr, flags)
2102 ClientData clientData;
2103 Tcl_Interp *interp; /* Current interp; may be used for errors. */
2104 Tk_Window tkwin; /* Window for which option is being set. */
2105 Tcl_Obj **value; /* Pointer to the pointer to the value object.
2106 * We use a pointer to the pointer because
2107 * we may need to return a value (NULL). */
2108 char *recordPtr; /* Pointer to storage for the widget record. */
2109 int internalOffset; /* Offset within *recordPtr at which the
2110 internal value is to be stored. */
2111 char *oldInternalPtr; /* Pointer to storage for the old value. */
2112 int flags; /* Flags for the option, set Tk_SetOptions. */
2113 {
2114 int sticky = 0;
2115 char c, *string, *internalPtr;
2116
2117 internalPtr = ComputeSlotAddress(recordPtr, internalOffset);
2118
2119 if (flags & TK_OPTION_NULL_OK && ObjectIsEmpty(*value)) {
2120 *value = NULL;
2121 } else {
2122 /*
2123 * Convert the sticky specifier into an integer value.
2124 */
2125
2126 string = Tcl_GetString(*value);
2127
2128 while ((c = *string++) != '\0') {
2129 switch (c) {
2130 case 'n': case 'N': sticky |= STICK_NORTH; break;
2131 case 'e': case 'E': sticky |= STICK_EAST; break;
2132 case 's': case 'S': sticky |= STICK_SOUTH; break;
2133 case 'w': case 'W': sticky |= STICK_WEST; break;
2134 case ' ': case ',': case '\t': case '\r': case '\n': break;
2135 default: {
2136 Tcl_ResetResult(interp);
2137 Tcl_AppendResult(interp, "bad stickyness value \"",
2138 Tcl_GetString(*value), "\": must be a string ",
2139 "containing zero or more of n, e, s, and w",
2140 (char *)NULL);
2141 return TCL_ERROR;
2142 }
2143 }
2144 }
2145 }
2146
2147 if (internalPtr != NULL) {
2148 *((int *) oldInternalPtr) = *((int *) internalPtr);
2149 *((int *) internalPtr) = sticky;
2150 }
2151 return TCL_OK;
2152 }
2153
2154 /*
2155 *----------------------------------------------------------------------
2156 *
2157 * RestoreSticky --
2158 *
2159 * Restore a sticky option value from a saved value.
2160 *
2161 * Results:
2162 * None.
2163 *
2164 * Side effects:
2165 * Restores the old value.
2166 *
2167 *----------------------------------------------------------------------
2168 */
2169
2170 static void
2171 RestoreSticky(clientData, tkwin, internalPtr, oldInternalPtr)
2172 ClientData clientData;
2173 Tk_Window tkwin;
2174 char *internalPtr; /* Pointer to storage for value. */
2175 char *oldInternalPtr; /* Pointer to old value. */
2176 {
2177 *(int *)internalPtr = *(int *)oldInternalPtr;
2178 }
2179
2180 /*
2181 *----------------------------------------------------------------------
2182 *
2183 * AdjustForSticky --
2184 *
2185 * Given the x,y coords of the top-left corner of a pane, the
2186 * dimensions of that pane, and the dimensions of a slave, compute
2187 * the x,y coords and actual dimensions of the slave based on the slave's
2188 * sticky value.
2189 *
2190 * Results:
2191 * No direct return; sets the x, y, slaveWidth and slaveHeight to
2192 * correct values.
2193 *
2194 * Side effects:
2195 * None.
2196 *
2197 *----------------------------------------------------------------------
2198 */
2199
2200 static void
2201 AdjustForSticky(sticky, cavityWidth, cavityHeight, xPtr, yPtr,
2202 slaveWidthPtr, slaveHeightPtr)
2203 int sticky; /* Sticky value; see top of file for definition. */
2204 int cavityWidth; /* Width of the cavity. */
2205 int cavityHeight; /* Height of the cavity. */
2206 int *xPtr, *yPtr; /* Initially, coordinates of the top-left
2207 * corner of cavity; also return values for
2208 * actual x, y coords of slave. */
2209 int *slaveWidthPtr; /* Slave width. */
2210 int *slaveHeightPtr; /* Slave height. */
2211 {
2212 int diffx=0; /* Cavity width - slave width. */
2213 int diffy=0; /* Cavity hight - slave height. */
2214
2215 if (cavityWidth > *slaveWidthPtr) {
2216 diffx = cavityWidth - *slaveWidthPtr;
2217 }
2218
2219 if (cavityHeight > *slaveHeightPtr) {
2220 diffy = cavityHeight - *slaveHeightPtr;
2221 }
2222
2223 if ((sticky & STICK_EAST) && (sticky & STICK_WEST)) {
2224 *slaveWidthPtr += diffx;
2225 }
2226 if ((sticky & STICK_NORTH) && (sticky & STICK_SOUTH)) {
2227 *slaveHeightPtr += diffy;
2228 }
2229 if (!(sticky & STICK_WEST)) {
2230 *xPtr += (sticky & STICK_EAST) ? diffx : diffx/2;
2231 }
2232 if (!(sticky & STICK_NORTH)) {
2233 *yPtr += (sticky & STICK_SOUTH) ? diffy : diffy/2;
2234 }
2235 }
2236
2237 /*
2238 *----------------------------------------------------------------------
2239 *
2240 * MoveSash --
2241 *
2242 * Move the sash given by index the amount given.
2243 *
2244 * Results:
2245 * None.
2246 *
2247 * Side effects:
2248 * Recomputes the sizes of the panes in a panedwindow.
2249 *
2250 *----------------------------------------------------------------------
2251 */
2252
2253 static void
2254 MoveSash(pwPtr, sash, diff)
2255 PanedWindow *pwPtr;
2256 int sash;
2257 int diff;
2258 {
2259 int diffConsumed = 0, i, extra, maxCoord, currCoord;
2260 int *lengthPtr, newLength;
2261 Slave *slave;
2262
2263 if (diff > 0) {
2264 /*
2265 * Growing the pane, at the expense of panes to the right.
2266 */
2267
2268 /*
2269 * First check that moving the sash the requested distance will not
2270 * leave it off the screen. If necessary, clip the requested diff
2271 * to the maximum possible while remaining visible.
2272 */
2273 if (pwPtr->orient == ORIENT_HORIZONTAL) {
2274 if (Tk_IsMapped(pwPtr->tkwin)) {
2275 maxCoord = Tk_Width(pwPtr->tkwin);
2276 } else {
2277 maxCoord = Tk_ReqWidth(pwPtr->tkwin);
2278 }
2279 extra = Tk_Width(pwPtr->tkwin) - Tk_ReqWidth(pwPtr->tkwin);
2280 currCoord = pwPtr->slaves[sash]->sashx;
2281 } else {
2282 if (Tk_IsMapped(pwPtr->tkwin)) {
2283 maxCoord = Tk_Height(pwPtr->tkwin);
2284 } else {
2285 maxCoord = Tk_ReqHeight(pwPtr->tkwin);
2286 }
2287 extra = Tk_Height(pwPtr->tkwin) - Tk_ReqHeight(pwPtr->tkwin);
2288 currCoord = pwPtr->slaves[sash]->sashy;
2289 }
2290
2291 maxCoord -= (pwPtr->borderWidth + pwPtr->sashWidth + pwPtr->sashPad);
2292 if (currCoord + diff >= maxCoord) {
2293 diff = maxCoord - currCoord;
2294 }
2295
2296 for (i = sash + 1; i < pwPtr->numSlaves; i++) {
2297 if (diffConsumed == diff) {
2298 break;
2299 }
2300 slave = pwPtr->slaves[i];
2301
2302 if (pwPtr->orient == ORIENT_HORIZONTAL) {
2303 lengthPtr = &(slave->paneWidth);
2304 } else {
2305 lengthPtr = &(slave->paneHeight);
2306 }
2307
2308 /*
2309 * Remove as much space from this pane as possible (constrained
2310 * by the minsize value and the visible dimensions of the window).
2311 */
2312
2313 if (i == pwPtr->numSlaves - 1 && extra > 0) {
2314 /*
2315 * The last pane may have some additional "virtual" space,
2316 * if the width (or height) of the paned window is bigger
2317 * than the requested width (or height).
2318 *
2319 * That extra space is not included in the paneWidth
2320 * (or paneHeight) value, so we have to handle the last
2321 * pane specially.
2322 */
2323 newLength = (*lengthPtr + extra) - (diff - diffConsumed);
2324 if (newLength < slave->minSize) {
2325 newLength = slave->minSize;
2326 }
2327 if (newLength < 0) {
2328 newLength = 0;
2329 }
2330 diffConsumed += (*lengthPtr + extra) - newLength;
2331 if (newLength < *lengthPtr) {
2332 *lengthPtr = newLength;
2333 }
2334 } else {
2335 newLength = *lengthPtr - (diff - diffConsumed);
2336 if (newLength < slave->minSize) {
2337 newLength = slave->minSize;
2338 }
2339 if (newLength < 0) {
2340 newLength = 0;
2341 }
2342 diffConsumed += *lengthPtr - newLength;
2343 *lengthPtr = newLength;
2344 }
2345 }
2346 if (pwPtr->orient == ORIENT_HORIZONTAL) {
2347 pwPtr->slaves[sash]->paneWidth += diffConsumed;
2348 } else {
2349 pwPtr->slaves[sash]->paneHeight += diffConsumed;
2350 }
2351 } else if (diff < 0) {
2352 /*
2353 * Shrinking the pane; additional space is given to the pane to the
2354 * right.
2355 */
2356 for (i = sash; i >= 0; i--) {
2357 if (diffConsumed == diff) {
2358 break;
2359 }
2360 /*
2361 * Remove as much space from this pane as possible.
2362 */
2363 slave = pwPtr->slaves[i];
2364
2365 if (pwPtr->orient == ORIENT_HORIZONTAL) {
2366 lengthPtr = &(slave->paneWidth);
2367 } else {
2368 lengthPtr = &(slave->paneHeight);
2369 }
2370
2371 newLength = *lengthPtr + (diff - diffConsumed);
2372 if (newLength < slave->minSize) {
2373 newLength = slave->minSize;
2374 }
2375 if (newLength < 0) {
2376 newLength = 0;
2377 }
2378 diffConsumed -= *lengthPtr - newLength;
2379 *lengthPtr = newLength;
2380 }
2381 if (pwPtr->orient == ORIENT_HORIZONTAL) {
2382 pwPtr->slaves[sash + 1]->paneWidth -= diffConsumed;
2383 } else {
2384 pwPtr->slaves[sash + 1]->paneHeight -= diffConsumed;
2385 }
2386 }
2387
2388 }
2389
2390 /*
2391 *----------------------------------------------------------------------
2392 *
2393 * ProxyWindowEventProc --
2394 *
2395 * This procedure is invoked by the Tk dispatcher for various
2396 * events on paned window proxy windows.
2397 *
2398 * Results:
2399 * None.
2400 *
2401 * Side effects:
2402 * When the window gets deleted, internal structures get
2403 * cleaned up. When it gets exposed, it is redisplayed.
2404 *
2405 *--------------------------------------------------------------
2406 */
2407
2408 static void
2409 ProxyWindowEventProc(clientData, eventPtr)
2410 ClientData clientData; /* Information about window. */
2411 XEvent *eventPtr; /* Information about event. */
2412 {
2413 PanedWindow *pwPtr = (PanedWindow *) clientData;
2414
2415 if (eventPtr->type == Expose) {
2416 if (pwPtr->proxywin != NULL &&!(pwPtr->flags & PROXY_REDRAW_PENDING)) {
2417 Tcl_DoWhenIdle(DisplayProxyWindow, (ClientData) pwPtr);
2418 pwPtr->flags |= PROXY_REDRAW_PENDING;
2419 }
2420 }
2421 }
2422
2423 /*
2424 *--------------------------------------------------------------
2425 *
2426 * DisplayProxyWindow --
2427 *
2428 * This procedure redraws a paned window proxy window.
2429 * It is invoked as a do-when-idle handler, so it only runs
2430 * when there's nothing else for the application to do.
2431 *
2432 * Results:
2433 * None.
2434 *
2435 * Side effects:
2436 * Information appears on the screen.
2437 *
2438 *--------------------------------------------------------------
2439 */
2440
2441 static void
2442 DisplayProxyWindow(clientData)
2443 ClientData clientData; /* Information about window. */
2444 {
2445 PanedWindow *pwPtr = (PanedWindow *) clientData;
2446 Pixmap pixmap;
2447 Tk_Window tkwin = pwPtr->proxywin;
2448 pwPtr->flags &= ~PROXY_REDRAW_PENDING;
2449 if ((tkwin == NULL) || !Tk_IsMapped(tkwin)) {
2450 return;
2451 }
2452
2453 /*
2454 * Create a pixmap for double-buffering, if necessary.
2455 */
2456
2457 pixmap = Tk_GetPixmap(Tk_Display(tkwin), Tk_WindowId(tkwin),
2458 Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin));
2459
2460 /*
2461 * Redraw the widget's background and border.
2462 */
2463 Tk_Fill3DRectangle(tkwin, pixmap, pwPtr->background, 0, 0,
2464 Tk_Width(tkwin), Tk_Height(tkwin), 2, pwPtr->sashRelief);
2465
2466 /*
2467 * Copy the pixmap to the display.
2468 */
2469 XCopyArea(Tk_Display(tkwin), pixmap, Tk_WindowId(tkwin), pwPtr->gc,
2470 0, 0, (unsigned) Tk_Width(tkwin), (unsigned) Tk_Height(tkwin),
2471 0, 0);
2472 Tk_FreePixmap(Tk_Display(tkwin), pixmap);
2473 }
2474
2475 /*
2476 *----------------------------------------------------------------------
2477 *
2478 * PanedWindowProxyCommand --
2479 *
2480 * Handles the panedwindow proxy subcommand. See the user
2481 * documentation for details.
2482 *
2483 * Results:
2484 * Standard Tcl result.
2485 *
2486 * Side effects:
2487 * May map or unmap the proxy sash.
2488 *
2489 *----------------------------------------------------------------------
2490 */
2491
2492 static int
2493 PanedWindowProxyCommand(pwPtr, interp, objc, objv)
2494 PanedWindow *pwPtr; /* Pointer to paned window information. */
2495 Tcl_Interp *interp; /* Current interpreter. */
2496 int objc; /* Number of arguments. */
2497 Tcl_Obj * CONST objv[]; /* Argument objects. */
2498 {
2499 static CONST char *optionStrings[] = { "coord", "forget", "place",
2500 (char *) NULL };
2501 enum options { PROXY_COORD, PROXY_FORGET, PROXY_PLACE };
2502 int index, x, y, sashWidth, sashHeight;
2503 Tcl_Obj *coords[2];
2504
2505 if (objc < 3) {
2506 Tcl_WrongNumArgs(interp, 2, objv, "option ?arg ...?");
2507 return TCL_ERROR;
2508 }
2509
2510 if (Tcl_GetIndexFromObj(interp, objv[2], optionStrings, "option", 0,
2511 &index) != TCL_OK) {
2512 return TCL_ERROR;
2513 }
2514
2515 switch ((enum options) index) {
2516 case PROXY_COORD:
2517 if (objc != 3) {
2518 Tcl_WrongNumArgs(interp, 3, objv, NULL);
2519 return TCL_ERROR;
2520 }
2521
2522 coords[0] = Tcl_NewIntObj(pwPtr->proxyx);
2523 coords[1] = Tcl_NewIntObj(pwPtr->proxyy);
2524 Tcl_SetListObj(Tcl_GetObjResult(interp), 2, coords);
2525 break;
2526
2527 case PROXY_FORGET:
2528 if (objc != 3) {
2529 Tcl_WrongNumArgs(interp, 3, objv, NULL);
2530 return TCL_ERROR;
2531 }
2532 if (Tk_IsMapped(pwPtr->proxywin)) {
2533 Tk_UnmapWindow(pwPtr->proxywin);
2534 Tk_UnmaintainGeometry(pwPtr->proxywin, pwPtr->tkwin);
2535 }
2536 break;
2537
2538 case PROXY_PLACE: {
2539 if (objc != 5) {
2540 Tcl_WrongNumArgs(interp, 3, objv, "x y");
2541 return TCL_ERROR;
2542 }
2543
2544 if (Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK) {
2545 return TCL_ERROR;
2546 }
2547
2548 if (Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK) {
2549 return TCL_ERROR;
2550 }
2551
2552 if (pwPtr->orient == ORIENT_HORIZONTAL) {
2553 if (x < 0) {
2554 x = 0;
2555 }
2556 y = Tk_InternalBorderWidth(pwPtr->tkwin);
2557 sashWidth = pwPtr->sashWidth;
2558 sashHeight = Tk_Height(pwPtr->tkwin) -
2559 (2 * Tk_InternalBorderWidth(pwPtr->tkwin));
2560 } else {
2561 if (y < 0) {
2562 y = 0;
2563 }
2564 x = Tk_InternalBorderWidth(pwPtr->tkwin);
2565 sashHeight = pwPtr->sashWidth;
2566 sashWidth = Tk_Width(pwPtr->tkwin) -
2567 (2 * Tk_InternalBorderWidth(pwPtr->tkwin));
2568 }
2569
2570 /*
2571 * Stash the proxy coordinates for future "proxy coord" calls.
2572 */
2573
2574 pwPtr->proxyx = x;
2575 pwPtr->proxyy = y;
2576
2577 /*
2578 * Make sure the proxy window is higher in the stacking order
2579 * than the slaves, so that it will be visible when drawn.
2580 * It would be more correct to push the proxy window just high
2581 * enough to appear above the highest slave, but it's much easier
2582 * to just force it all the way to the top of the stacking order.
2583 */
2584
2585 Tk_RestackWindow(pwPtr->proxywin, Above, NULL);
2586
2587 /*
2588 * Let Tk_MaintainGeometry take care of placing the window at
2589 * the right coordinates.
2590 */
2591 Tk_MaintainGeometry(pwPtr->proxywin, pwPtr->tkwin,
2592 x, y, sashWidth, sashHeight);
2593 break;
2594 }
2595 }
2596
2597 return TCL_OK;
2598 }
2599
2600 /*
2601 *----------------------------------------------------------------------
2602 *
2603 * ObjectIsEmpty --
2604 *
2605 * This procedure tests whether the string value of an object is
2606 * empty.
2607 *
2608 * Results:
2609 * The return value is 1 if the string value of objPtr has length
2610 * zero, and 0 otherwise.
2611 *
2612 * Side effects:
2613 * May cause object shimmering, since this function can force a
2614 * conversion to a string object.
2615 *
2616 *----------------------------------------------------------------------
2617 */
2618
2619 static int
2620 ObjectIsEmpty(objPtr)
2621 Tcl_Obj *objPtr; /* Object to test. May be NULL. */
2622 {
2623 int length;
2624
2625 if (objPtr == NULL) {
2626 return 1;
2627 }
2628 #ifdef _LANG
2629 return LangNull(objPtr);
2630 #else
2631 if (objPtr->bytes != NULL) {
2632 return (objPtr->length == 0);
2633 }
2634
2635 Tcl_GetStringFromObj(objPtr, &length);
2636 #endif
2637 return (length == 0);
2638 }
2639
2640 /*
2641 *----------------------------------------------------------------------
2642 *
2643 * ComputeInternalPointer --
2644 *
2645 * Given a pointer to the start of a record and the offset of a slot
2646 * within that record, compute the address of that slot.
2647 *
2648 * Results:
2649 * If offset is non-negative, returns the computed address; else,
2650 * returns NULL.
2651 *
2652 * Side effects:
2653 * None.
2654 *
2655 *----------------------------------------------------------------------
2656 */
2657
2658 static char *
2659 ComputeSlotAddress(recordPtr, offset)
2660 char *recordPtr; /* Pointer to the start of a record. */
2661 int offset; /* Offset of a slot within that record; may be < 0. */
2662 {
2663 if (offset >= 0) {
2664 return recordPtr + offset;
2665 } else {
2666 return NULL;
2667 }
2668 }
2669
2670 /*
2671 *----------------------------------------------------------------------
2672 *
2673 * PanedWindowIdentifyCoords --
2674 *
2675 * Given a pair of x,y coordinates, identify the panedwindow component
2676 * at that point, if any.
2677 *
2678 * Results:
2679 * Standard Tcl result.
2680 *
2681 * Side effects:
2682 * Modifies the interpreter's result to contain either an empty list,
2683 * or a two element list of the form {sash n} or {handle n} to indicate
2684 * that the point lies within the n'th sash or handle.
2685 *
2686 *----------------------------------------------------------------------
2687 */
2688
2689 static int
2690 PanedWindowIdentifyCoords(pwPtr, interp, x, y)
2691 PanedWindow *pwPtr; /* Information about the widget. */
2692 Tcl_Interp *interp; /* Interpreter in which to store result. */
2693 int x, y; /* Coordinates of the point to identify. */
2694 {
2695 Tcl_Obj *list;
2696 int i, sashHeight, sashWidth, thisx, thisy;
2697 int found, isHandle, lpad, rpad, tpad, bpad;
2698 list = Tcl_NewObj();
2699
2700 if (pwPtr->orient == ORIENT_HORIZONTAL) {
2701 if (Tk_IsMapped(pwPtr->tkwin)) {
2702 sashHeight = Tk_Height(pwPtr->tkwin);
2703 } else {
2704 sashHeight = Tk_ReqHeight(pwPtr->tkwin);
2705 }
2706 sashHeight -= 2 * Tk_InternalBorderWidth(pwPtr->tkwin);
2707 if (pwPtr->showHandle && pwPtr->handleSize > pwPtr->sashWidth) {
2708 sashWidth = pwPtr->handleSize;
2709 lpad = (pwPtr->handleSize - pwPtr->sashWidth) / 2;
2710 rpad = pwPtr->handleSize - lpad;
2711 lpad += pwPtr->sashPad;
2712 rpad += pwPtr->sashPad;
2713 } else {
2714 sashWidth = pwPtr->sashWidth;
2715 lpad = rpad = pwPtr->sashPad;
2716 }
2717 tpad = bpad = 0;
2718 } else {
2719 if (pwPtr->showHandle && pwPtr->handleSize > pwPtr->sashWidth) {
2720 sashHeight = pwPtr->handleSize;
2721 tpad = (pwPtr->handleSize - pwPtr->sashWidth) / 2;
2722 bpad = pwPtr->handleSize - tpad;
2723 tpad += pwPtr->sashPad;
2724 bpad += pwPtr->sashPad;
2725 } else {
2726 sashHeight = pwPtr->sashWidth;
2727 tpad = bpad = pwPtr->sashPad;
2728 }
2729 if (Tk_IsMapped(pwPtr->tkwin)) {
2730 sashWidth = Tk_Width(pwPtr->tkwin);
2731 } else {
2732 sashWidth = Tk_ReqWidth(pwPtr->tkwin);
2733 }
2734 sashWidth -= 2 * Tk_InternalBorderWidth(pwPtr->tkwin);
2735 lpad = rpad = 0;
2736 }
2737
2738 isHandle = 0;
2739 found = -1;
2740 for (i = 0; i < pwPtr->numSlaves - 1; i++) {
2741 thisx = pwPtr->slaves[i]->sashx;
2742 thisy = pwPtr->slaves[i]->sashy;
2743
2744 if (((thisx - lpad) <= x && x <= (thisx + rpad + sashWidth)) &&
2745 ((thisy - tpad) <= y && y <= (thisy + bpad + sashHeight))) {
2746 found = i;
2747
2748 /*
2749 * Determine if the point is over the handle or the sash.
2750 */
2751 if (pwPtr->showHandle) {
2752 thisx = pwPtr->slaves[i]->handlex;
2753 thisy = pwPtr->slaves[i]->handley;
2754 if (pwPtr->orient == ORIENT_HORIZONTAL) {
2755 if (thisy <= y && y <= (thisy + pwPtr->handleSize)) {
2756 isHandle = 1;
2757 }
2758 } else {
2759 if (thisx <= x && x <= (thisx + pwPtr->handleSize)) {
2760 isHandle = 1;
2761 }
2762 }
2763 }
2764 break;
2765 }
2766 }
2767
2768 /*
2769 * Set results.
2770 */
2771 if (found != -1) {
2772 Tcl_ListObjAppendElement(interp, list, Tcl_NewIntObj(found));
2773 if (isHandle) {
2774 Tcl_ListObjAppendElement(interp, list,
2775 Tcl_NewStringObj("handle", -1));
2776 } else {
2777 Tcl_ListObjAppendElement(interp, list,
2778 Tcl_NewStringObj("sash", -1));
2779 }
2780 }
2781
2782 Tcl_SetObjResult(interp, list);
2783 return TCL_OK;
2784 }
2785