Debian Codegraph @

pTk/mTk/tixGeneric/tixForm.c

raw symbols SCIP
1
2 /* $Id: tixForm.c,v 1.1.1.1 2000/05/17 11:08:41 idiscovery Exp $ */
3
4 /*
5 * tixForm.c --
6 *
7 * Implements the tixForm geometry manager, which has similar
8 * capability as the Motif Form geometry manager. Please
9 * refer to the documentation for the use of tixForm.
10 *
11 * This file implements the basic algorithm of tixForm.
12 *
13 * Copyright (c) 1996, Expert Interface Technologies
14 *
15 * See the file "license.terms" for information on usage and redistribution
16 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
17 *
18 */
19
20 /*
21 *
22 * ToDo:
23 *
24 * (1) Delete the master structure when there is no more client to manage
25 *
26 * Possible bugs:
27 * (1) a client is deleted but the master doesn't know
28 * (clientPtr->tkwin == NULL)
29 * (2) Whan a client S is deleted or detached from the master, all other
30 * clients attached to S must delete their reference to S
31 */
32 #define DEBUG 0
33 #if DEBUG
34 #define NEED_REAL_STDIO
35 #endif
36
37 #include <tkInt.h>
38 #include "tixPort.h"
39 #include "tix.h"
40 #include "tixForm.h"
41
42
43 typedef struct SpringLink {
44 struct SpringLink * next;
45 FormInfo *clientPtr;
46 } SpringLink;
47
48
49 typedef struct SpringList {
50 SpringLink * head, * tail;
51 int num;
52 } SpringList;
53
54
55 /*
56 * SubCommands of the tixForm command.
57 */
58 static TIX_DECLARE_SUBCMD(TixFm_SetGrid);
59 static TIX_DECLARE_SUBCMD(TixFm_SetClient);
60 static TIX_DECLARE_SUBCMD(TixFm_Check);
61 static TIX_DECLARE_SUBCMD(TixFm_Forget);
62 EXTERN TIX_DECLARE_SUBCMD(TixFm_Info);
63 static TIX_DECLARE_SUBCMD(TixFm_Slaves);
64 static TIX_DECLARE_SUBCMD(TixFm_Spring);
65
66 static void ArrangeGeometry _ANSI_ARGS_((ClientData clientData));
67 static void ArrangeWhenIdle _ANSI_ARGS_((MasterInfo * masterPtr));
68 static void CancelArrangeWhenIdle _ANSI_ARGS_((
69 MasterInfo * masterPtr));
70 static void CalculateMasterSize _ANSI_ARGS_((MasterInfo *master));
71 static void CheckIntergrity _ANSI_ARGS_((FormInfo * clientPtr));
72 static MasterInfo * GetMasterInfo _ANSI_ARGS_((Tk_Window tkwin,
73 int create));
74 static void MasterStructureProc _ANSI_ARGS_((ClientData clientData,
75 XEvent * eventPtr));
76 static int PinnClient _ANSI_ARGS_((FormInfo *clientPtr));
77 static int PinnClientSide _ANSI_ARGS_((FormInfo *clientPtr,
78 int axis, int which, int isSelf));
79 static int PlaceClientSide _ANSI_ARGS_((FormInfo *clientPtr,
80 int axis, int which, int isSelf));
81 static int TestAndArrange _ANSI_ARGS_((MasterInfo *masterPtr));
82 static int TixFm_CheckArgv _ANSI_ARGS_((ClientData clientData,
83 Tcl_Interp *interp, int argc, char ** argv));
84 static void TixFm_LostSlaveProc _ANSI_ARGS_((
85 ClientData clientData, Tk_Window tkwin));
86 static void TixFm_ReqProc _ANSI_ARGS_((ClientData clientData,
87 Tk_Window tkwin));
88 static int PlaceAllClients _ANSI_ARGS_((MasterInfo *masterPtr));
89 static int PlaceClient _ANSI_ARGS_((FormInfo *clientPtr));
90 static int PlaceSide_AttOpposite _ANSI_ARGS_((
91 FormInfo *clientPtr, int axis, int which));
92 static int PlaceSide_AttAbsolute _ANSI_ARGS_((
93 FormInfo *clientPtr, int axis, int which));
94 static int PlaceSide_AttNone _ANSI_ARGS_((
95 FormInfo *clientPtr, int axis, int which));
96 static int PlaceSide_AttParallel _ANSI_ARGS_((FormInfo *clientPtr,
97 int axis, int which));
98 static int PlaceSimpleCase _ANSI_ARGS_((
99 FormInfo *clientPtr, int axis, int which));
100 static int PlaceWithSpring _ANSI_ARGS_((
101 FormInfo *clientPtr, int axis, int which));
102 static int ReqSize _ANSI_ARGS_((Tk_Window tkwin,
103 int axis));
104 static void UnmapClient _ANSI_ARGS_((FormInfo *clientPtr));
105 static void MapClient _ANSI_ARGS_((FormInfo *clientPtr,
106 int x, int y, int width, int height));
107 static int PinnSide_AttNone _ANSI_ARGS_((FormInfo *clientPtr,
108 int axis, int which));
109 static int PinnSide_AttPercent _ANSI_ARGS_((FormInfo *clientPtr,
110 int axis, int which));
111 static int PinnSide_AttOpposite _ANSI_ARGS_((FormInfo *clientPtr,
112 int axis, int which));
113 static int PinnSide_AttParallel _ANSI_ARGS_((FormInfo *clientPtr,
114 int axis, int which));
115 static SpringLink * AllocSpringLink _ANSI_ARGS_((void));
116 static void FreeSpringLink _ANSI_ARGS_((SpringLink * link));
117 static void FreeSpringList _ANSI_ARGS_((SpringList * listPtr));
118 static void AddRightSprings _ANSI_ARGS_((SpringList * listPtr,
119 FormInfo *clientPtr));
120 static void AddLeftSprings _ANSI_ARGS_((SpringList * listPtr,
121 FormInfo *clientPtr));
122
123 /*
124 * A macro used to simplify the "pinn client" code
125 */
126 #define PINN_CLIENT_SIDE(client, axis, which, isSelf) \
127 if (PinnClientSide(client, axis, which, isSelf) == TCL_ERROR) { \
128 return TCL_ERROR; \
129 }
130 /*
131 * A macro used to simplify the "place client" code
132 */
133 #define PLACE_CLIENT_SIDE(client, axis, which, isSelf) \
134 if (PlaceClientSide(client, axis, which, isSelf) == TCL_ERROR) { \
135 return TCL_ERROR; \
136 }
137
138 /*
139 * Information about the Form geometry manager.
140 */
141 static Tk_GeomMgr formType = {
142 "tixForm", /* name */
143 TixFm_ReqProc, /* requestProc */
144 TixFm_LostSlaveProc, /* lostSlaveProc */
145 };
146
147 /*
148 * Hash table used to map from Tk_Window tokens to corresponding
149 * FormInfo structures:
150 */
151 static Tcl_HashTable formInfoHashTable;
152 static Tcl_HashTable masterInfoHashTable;
153
154 /*
155 * Have static variables in this module been initialized?
156 */
157 static int initialized = 0;
158
159 static int ReqSize(tkwin, axis)
160 Tk_Window tkwin;
161 int axis;
162 {
163 if (axis == AXIS_X) {
164 return Tk_ReqWidth(tkwin);
165 } else {
166 return Tk_ReqHeight(tkwin);
167 }
168 }
169
170 /*
171 *--------------------------------------------------------------
172 *
173 * Tix_FormCmd --
174 *
175 * This procedure is invoked to process the "tixForm" Tcl command.
176 * See the user documentation for details on what it does.
177 *
178 * Results:
179 * A standard Tcl result.
180 *
181 * Side effects:
182 * See the user documentation.
183 *
184 *--------------------------------------------------------------
185 */
186 int
187 Tix_FormCmd(clientData, interp, argc, argv)
188 ClientData clientData; /* Main window associated with
189 * interpreter. */
190 Tcl_Interp *interp; /* Current interpreter. */
191 int argc; /* Number of arguments. */
192 char **argv; /* Argument strings. */
193 {
194 static Tix_SubCmdInfo subCmdInfo[] = {
195 {TIX_DEFAULT_LEN, "check", 1, 1, TixFm_Check,
196 "master",},
197 {TIX_DEFAULT_LEN, "configure", 1, TIX_VAR_ARGS, TixFm_SetClient,
198 "slave ?-flag value ...?",},
199 {TIX_DEFAULT_LEN, "forget", 1, TIX_VAR_ARGS, TixFm_Forget,
200 "slave ?slave ...?",},
201 {TIX_DEFAULT_LEN, "grid", 1, TIX_VAR_ARGS, TixFm_SetGrid,
202 "master ?x_grids y_grids?"},
203 {TIX_DEFAULT_LEN, "info", 1, 2, TixFm_Info,
204 "slave ?-flag?",},
205 {TIX_DEFAULT_LEN, "slaves", 1, 1, TixFm_Slaves,
206 "master",},
207 {TIX_DEFAULT_LEN, "spring", 3, 3, TixFm_Spring,
208 "slave side strength",},
209 {TIX_DEFAULT_LEN, TIX_DEFAULT_SUBCMD, 0, 0, TixFm_SetClient, 0,
210 TixFm_CheckArgv,}
211 };
212
213 static Tix_CmdInfo cmdInfo = {
214 Tix_ArraySize(subCmdInfo), 1, TIX_VAR_ARGS, "?option? arg ?arg ...?",
215 };
216
217 return Tix_HandleSubCmds(&cmdInfo, subCmdInfo, clientData,
218 interp, argc, argv);
219 }
220
221 /*----------------------------------------------------------------------
222 *
223 * TixFm_SetGrid --
224 *
225 * Sets some defaults for the master window
226 *
227 *----------------------------------------------------------------------
228 */
229 static int TixFm_SetGrid(clientData, interp, argc, argv)
230 ClientData clientData; /* Main window associated with
231 * interpreter. */
232 Tcl_Interp *interp; /* Current interpreter. */
233 int argc; /* Number of arguments. */
234 char **argv; /* Argument strings. */
235 {
236 char buff[100];
237 Tk_Window topLevel = (Tk_Window) clientData;
238 Tk_Window master;
239 MasterInfo* masterPtr;
240
241 master = Tk_NameToWindow(interp, argv[0], topLevel);
242
243 if (master == NULL) {
244 return TCL_ERROR;
245 } else {
246 masterPtr = GetMasterInfo(master, 1);
247 }
248
249 if (argc != 1 && argc != 3) {
250 Tcl_AppendResult(interp, "Wrong # of arguments, should be ",
251 "tixForm grid master ?x_grids y_grids?", NULL);
252 return TCL_ERROR;
253 }
254
255 if (argc == 1) {
256 Tcl_IntResults(interp, 2, 0, masterPtr->grids[0], masterPtr->grids[1]);
257 }
258 else {
259 int x, y;
260 if (Tcl_GetIntFromObj(interp, argv[1], &x) != TCL_OK) {
261 return TCL_ERROR;
262 }
263 if (Tcl_GetIntFromObj(interp, argv[2], &y) != TCL_OK) {
264 return TCL_ERROR;
265 }
266
267 if (x <=0 || y <=0) {
268 Tcl_AppendResult(interp, "Grid sizes must be positive integers",
269 NULL);
270 return TCL_ERROR;
271 }
272 masterPtr->grids[0] = x;
273 masterPtr->grids[1] = y;
274
275 ArrangeWhenIdle(masterPtr);
276 }
277
278 return TCL_OK;
279 }
280 /*----------------------------------------------------------------------
281 *
282 * TixFm_Forget --
283 *
284 * Sets some defaults for the master window
285 *
286 *----------------------------------------------------------------------
287 */
288 static int TixFm_Forget(clientData, interp, argc, argv)
289 ClientData clientData; /* Main window associated with
290 * interpreter. */
291 Tcl_Interp *interp; /* Current interpreter. */
292 int argc; /* Number of arguments. */
293 char **argv; /* Argument strings. */
294 {
295 FormInfo * clientPtr;
296 Tk_Window topLevel = (Tk_Window) clientData;
297 int i;
298
299 for (i=0; i<argc; i++) {
300 clientPtr = TixFm_FindClientPtrByName(interp, argv[i], topLevel);
301 if (clientPtr == NULL) {
302 return TCL_ERROR;
303 }
304 else {
305 TixFm_ForgetOneClient(clientPtr);
306 }
307 }
308
309 return TCL_OK;
310 }
311
312 void TixFm_ForgetOneClient(clientPtr)
313 FormInfo * clientPtr;
314 {
315 if (clientPtr != NULL) {
316 Tk_DeleteEventHandler(clientPtr->tkwin, StructureNotifyMask,
317 TixFm_StructureProc, (ClientData) clientPtr);
318 Tk_ManageGeometry(clientPtr->tkwin, (Tk_GeomMgr *) NULL,
319 (ClientData) NULL);
320 if (clientPtr->master->tkwin != Tk_Parent(clientPtr->tkwin)) {
321 Tk_UnmaintainGeometry(clientPtr->tkwin,
322 clientPtr->master->tkwin);
323 }
324 Tk_UnmapWindow(clientPtr->tkwin);
325 TixFm_Unlink(clientPtr);
326 }
327 }
328
329 /*----------------------------------------------------------------------
330 *
331 * TixFm_Slaves --
332 *
333 * retuen the pathnames of the clients of a master window
334 *
335 *----------------------------------------------------------------------
336 */
337 static int TixFm_Slaves(clientData, interp, argc, argv)
338 ClientData clientData; /* Main window associated with
339 * interpreter. */
340 Tcl_Interp *interp; /* Current interpreter. */
341 int argc; /* Number of arguments. */
342 char **argv; /* Argument strings. */
343 {
344 Tk_Window topLevel = (Tk_Window) clientData;
345 Tk_Window master;
346 MasterInfo* masterPtr;
347 FormInfo * clientPtr;
348
349 master = Tk_NameToWindow(interp, argv[0], topLevel);
350
351 if (master == NULL) {
352 return TCL_ERROR;
353 } else {
354 masterPtr = GetMasterInfo(master, 0);
355 }
356
357 if (masterPtr == 0) {
358 Tcl_AppendResult(interp, "Window \"", argv[0],
359 "\" is not a tixForm master window", NULL);
360 return TCL_ERROR;
361 }
362
363 for (clientPtr = masterPtr->client; clientPtr; clientPtr=clientPtr->next) {
364 /*Tcl_AppendElement(interp, Tk_PathName(clientPtr->tkwin));*/
365 Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),
366 LangWidgetObj(interp,clientPtr->tkwin));
367 }
368 return TCL_OK;
369 }
370 /*----------------------------------------------------------------------
371 *
372 * TixFm_Spring --
373 *
374 * Sets the spring strength of a slave's attachment sides
375 *
376 *----------------------------------------------------------------------
377 */
378 static int TixFm_Spring(clientData, interp, argc, argv)
379 ClientData clientData; /* Main window associated with
380 * interpreter. */
381 Tcl_Interp *interp; /* Current interpreter. */
382 int argc; /* Number of arguments. */
383 char **argv; /* Argument strings. */
384 {
385 Tk_Window topLevel = (Tk_Window) clientData;
386 Tk_Window tkwin;
387 FormInfo * clientPtr;
388 int strength;
389 int i, j;
390 size_t len;
391
392 if ((tkwin = Tk_NameToWindow(interp, argv[0], topLevel)) == NULL) {
393 return TCL_ERROR;
394 }
395
396 if ((clientPtr = TixFm_GetFormInfo(tkwin, 0)) == NULL) {
397 Tcl_AppendResult(interp, "Window \"", argv[0],
398 "\" is not managed by the tixForm manager", NULL);
399 return TCL_ERROR;
400 }
401
402 if (Tcl_GetIntFromObj(interp, argv[2], &strength) != TCL_OK) {
403 return TCL_ERROR;
404 }
405
406 len = strlen(argv[1]);
407 if (strncmp(argv[1], "-top", len) == 0) {
408 i = 1; j = 0;
409 }
410 else if (strncmp(argv[1], "-bottom", len) == 0) {
411 i = 1; j = 1;
412 }
413 else if (strncmp(argv[1], "-left", len) == 0) {
414 i = 0; j = 0;
415 }
416 else if (strncmp(argv[1], "-right", len) == 0) {
417 i = 0; j = 1;
418 }
419 else {
420 Tcl_AppendResult(interp, "Unknown option \"", argv[1],
421 "\"", NULL);
422 return TCL_ERROR;
423 }
424
425 clientPtr->spring[i][j] = strength;
426
427 if (clientPtr->attType[i][j] == ATT_OPPOSITE) {
428 FormInfo * oppo;
429
430 oppo = clientPtr->att[i][j].widget;
431 oppo->spring[i][!j] = strength;
432
433 if (strength != 0 && clientPtr->strWidget[i][j] == NULL) {
434 clientPtr->strWidget[i][j] = oppo;
435
436 if (oppo->strWidget[i][!j] != clientPtr) {
437 if (oppo->strWidget[i][!j] != NULL) {
438 oppo->strWidget[i][!j]->strWidget[i][j] = NULL;
439 oppo->strWidget[i][!j]->spring[i][j] = 0;
440 }
441 }
442 oppo->strWidget[i][!j] = clientPtr;
443 }
444 }
445
446 ArrangeWhenIdle(clientPtr->master);
447
448 return TCL_OK;
449 }
450
451 /*----------------------------------------------------------------------
452 *
453 * TixFm_Check --
454 *
455 * Tests whether the master has circular reference.
456 *
457 *----------------------------------------------------------------------
458 */
459 static int TixFm_Check(clientData, interp, argc, argv)
460 ClientData clientData; /* Main window associated with
461 * interpreter. */
462 Tcl_Interp *interp; /* Current interpreter. */
463 int argc; /* Number of arguments. */
464 char **argv; /* Argument strings. */
465 {
466 MasterInfo * masterPtr;
467 Tk_Window topLevel = (Tk_Window) clientData;
468 Tk_Window master;
469
470 master = Tk_NameToWindow(interp, argv[0], topLevel);
471 if (master == NULL) {
472 return TCL_ERROR;
473 }
474
475 masterPtr = GetMasterInfo(master, 1);
476
477 if (TestAndArrange(masterPtr) == TCL_OK) {
478 /* OK: no circular dependency */
479 Tcl_AppendResult(interp, "0", NULL);
480 } else {
481 /* Bad: circular dependency */
482 Tcl_AppendResult(interp, "1", NULL);
483 }
484 return TCL_OK;
485 }
486
487 /* Check the arguments to the default subcommand: TixFm_SetClient()
488 */
489 static int TixFm_CheckArgv(clientData, interp, argc, argv)
490 ClientData clientData; /* Main window associated with
491 * interpreter. */
492 Tcl_Interp *interp; /* Current interpreter. */
493 int argc; /* Number of arguments. */
494 char **argv; /* Argument strings. */
495 {
496 if ((argc >=1) && (argv[0][0] != '.')) {
497 return 0; /* sorry, we expect a window name */
498 } else {
499 return 1;
500 }
501 }
502
503
504 static int TixFm_SetClient(clientData, interp, argc, argv)
505 ClientData clientData; /* Main window associated with
506 * interpreter. */
507 Tcl_Interp *interp; /* Current interpreter. */
508 int argc; /* Number of arguments. */
509 char **argv; /* Argument strings. */
510 {
511 Tk_Window topLevel = (Tk_Window) clientData;
512 Tk_Window client, master;
513 FormInfo * clientPtr;
514 MasterInfo * masterPtr;
515 char *pathName; /* path name of the client window */
516
517 if (argc < 1 || (((argc-1) %2) != 0)) {
518 Tcl_AppendResult(interp, "Wrong # of arguments, should be ",
519 "tixForm configure slave ?-flag value ...?", NULL);
520 return TCL_ERROR;
521 }
522 pathName = argv[0];
523 argc -=1;
524 argv +=1;
525
526 client = Tk_NameToWindow(interp, pathName, topLevel);
527
528 if (client == NULL) {
529 return TCL_ERROR;
530 } else if (Tk_IsTopLevel(client)) {
531 Tcl_AppendResult(interp, "can't put \"", pathName,
532 "\"in a form: it's a top-level window", (char *) NULL);
533 return TCL_ERROR;
534 } else {
535 clientPtr = TixFm_GetFormInfo(client, 1);
536 }
537
538 /* Check if the first argument is "-in". If so,
539 * reset the master of this client
540 */
541 if (argc >= 2 && strcmp(argv[0], "-in")==0) {
542 if ((master=Tk_NameToWindow(interp, argv[1], topLevel)) == NULL) {
543 return TCL_ERROR;
544 }
545 argc -= 2;
546 argv += 2;
547 masterPtr = GetMasterInfo(master, 1);
548 }
549 else if (clientPtr->master == NULL) {
550 if ((master = Tk_Parent(client))==NULL) {
551 return TCL_ERROR;
552 }
553 masterPtr = GetMasterInfo(master, 1);
554 }
555 else {
556 masterPtr =clientPtr->master;
557 }
558
559 if (clientPtr->master != masterPtr) {
560 if (clientPtr->master != NULL) {
561 /* Take clientPtr from old master */
562 Tk_ManageGeometry(clientPtr->tkwin, (Tk_GeomMgr *) NULL,
563 (ClientData) NULL);
564 if (clientPtr->master->tkwin != Tk_Parent(clientPtr->tkwin)) {
565 Tk_UnmaintainGeometry(clientPtr->tkwin,
566 clientPtr->master->tkwin);
567 }
568 TixFm_UnlinkFromMaster(clientPtr);
569 }
570
571 /* attach the client to the master */
572 TixFm_AddToMaster(masterPtr, clientPtr);
573 }
574
575 if (argc > 0) {
576 if (TixFm_Configure(clientPtr, topLevel, interp, argc,
577 argv)==TCL_ERROR){
578 return TCL_ERROR;
579 }
580 }
581
582 ArrangeWhenIdle(clientPtr->master);
583
584 return TCL_OK;
585 }
586
587
588 /* The caller of this function needs to find out a pointer to a client
589 * that is already managed by tixForm.
590 */
591 FormInfo * TixFm_FindClientPtrByName(interp, name, topLevel)
592 Tcl_Interp * interp;
593 char * name;
594 Tk_Window topLevel;
595 {
596 Tk_Window tkwin;
597 FormInfo * clientPtr;
598
599 if ((tkwin = Tk_NameToWindow(interp, name, topLevel)) == NULL) {
600 return NULL;
601 }
602
603 if ((clientPtr = TixFm_GetFormInfo(tkwin, 0)) == NULL) {
604 Tcl_AppendResult(interp, "Window \"", name,
605 "\" is not managed by the tixForm manager", NULL);
606 return NULL;
607 }
608 return clientPtr;
609 }
610
611
612 static int TestAndArrange(masterPtr)
613 MasterInfo *masterPtr;
614 {
615 FormInfo *clientPtr;
616 int i,j;
617
618 /*
619 * First mark all clients as unpinned, and clean the opposite flags,
620 * Check the attachment intergrity
621 */
622 for (clientPtr = masterPtr->client; clientPtr; clientPtr=clientPtr->next) {
623 if (clientPtr->tkwin != NULL) {
624 for (i=0; i<2; i++) {
625 for (j=0; j<2; j++) {
626 clientPtr->side[i][j].pcnt = 0;
627 clientPtr->side[i][j].disp = 0;
628 }
629 /* clear all flags */
630 clientPtr->sideFlags[i] = 0;
631 }
632 clientPtr->depend = 0;
633 CheckIntergrity(clientPtr);
634 }
635 }
636
637 /*
638 * Try to determine all the client's geometry
639 */
640 for (clientPtr = masterPtr->client; clientPtr; clientPtr=clientPtr->next) {
641 if (clientPtr->tkwin == NULL) { /* it was deleted */
642 continue;
643 }
644 for (i=0; i<2; i++) {
645 if ((clientPtr->sideFlags[i] & PINNED_ALL) != PINNED_ALL) {
646 if (PinnClient(clientPtr) == TCL_ERROR) {
647 /*
648 * Detected circular dependency
649 */
650 return TCL_ERROR;
651 }
652 break;
653 }
654 }
655 }
656
657 return TCL_OK;
658 }
659
660 /*----------------------------------------------------------------------
661 * UnmapClient
662 *
663 * Unmap the client from the screen, using different methods according to
664 * the relationship between the client and slave.
665 */
666 static void UnmapClient(clientPtr)
667 FormInfo *clientPtr;
668 {
669 if (clientPtr->master->tkwin == Tk_Parent(clientPtr->tkwin)) {
670 Tk_UnmapWindow(clientPtr->tkwin);
671 }
672 else {
673 Tk_UnmaintainGeometry(clientPtr->tkwin, clientPtr->master->tkwin);
674 Tk_UnmapWindow(clientPtr->tkwin);
675 }
676 }
677
678 /*----------------------------------------------------------------------
679 * MapClient
680 *
681 * Map the client to the screen, using different methods according to
682 * the relationship between the client and slave.
683 */
684 static void MapClient(clientPtr, x, y, width, height)
685 FormInfo *clientPtr;
686 int x;
687 int y;
688 int width;
689 int height;
690 {
691 if (clientPtr->master->tkwin == Tk_Parent(clientPtr->tkwin)) {
692 Tk_MoveResizeWindow(clientPtr->tkwin, x, y, width, height);
693 Tk_MapWindow(clientPtr->tkwin);
694 }
695 else {
696 Tk_MaintainGeometry(clientPtr->tkwin, clientPtr->master->tkwin,
697 x, y, width, height);
698 Tk_MapWindow(clientPtr->tkwin);
699 }
700 }
701
702 static void ArrangeWhenIdle(masterPtr)
703 MasterInfo * masterPtr;
704 {
705 if (!(masterPtr->flags.repackPending || masterPtr->flags.isDeleted)) {
706 masterPtr->flags.repackPending = 1;
707 Tcl_DoWhenIdle(ArrangeGeometry, (ClientData) masterPtr);
708 }
709 }
710
711 static void
712 CancelArrangeWhenIdle(masterPtr)
713 MasterInfo * masterPtr;
714 {
715 if (masterPtr->flags.repackPending) {
716 Tcl_CancelIdleCall(ArrangeGeometry, (ClientData) masterPtr);
717 masterPtr->flags.repackPending = 0;
718 }
719 }
720
721 /*----------------------------------------------------------------------
722 * ArrangeGeometry --
723 *
724 * The heart of the Form geometry manager: calculates the sizes of
725 * the clients and the master, then arrange the clients inside the
726 * master according to their attachments.
727 */
728 static void ArrangeGeometry(clientData)
729 ClientData clientData; /* Structure describing parent whose clients
730 * are to be re-layed out. */
731 {
732 MasterInfo *masterPtr;
733 FormInfo *clientPtr;
734 int i, j, coord[2][2];
735 int mSize[2]; /* Size of master */
736 int cSize[2]; /* Size of client */
737 int intBWidth; /* internal borderWidth of master */
738
739 TkWindow* winPtr;
740 masterPtr = (MasterInfo *) clientData;
741 winPtr = (TkWindow*)masterPtr->tkwin;
742
743 if (winPtr->flags & TK_ALREADY_DEAD) {
744 masterPtr->flags.repackPending = 0;
745 return;
746 }
747
748 if (masterPtr->flags.isDeleted) {
749 return;
750 }
751
752 if (masterPtr->numClients == 0) {
753 masterPtr->flags.repackPending = 0;
754 return;
755 }
756
757 if (TestAndArrange(masterPtr)) { /* Detected circular dependency */
758 #if DEBUG
759 fprintf(stderr, "circular dependency.\n");
760 #endif
761 masterPtr->flags.repackPending = 0;
762 return;
763 }
764
765 /*
766 * Try to determine the required size of the master
767 */
768 CalculateMasterSize(masterPtr);
769
770 /*
771 * If the requested size is not equal to the actual size of the master,
772 * we might have to ask TK to change the master's geometry
773 */
774
775 if ((masterPtr->reqSize[0] != Tk_ReqWidth(masterPtr->tkwin))
776 || (masterPtr->reqSize[1] != Tk_ReqHeight(masterPtr->tkwin))) {
777
778 if (masterPtr->numRequests++ > 50) {
779 #if DEBUG
780 fprintf(stderr,
781 "(TixForm) Error:Trying to use more than one geometry\n\
782 manager for the same master window.\n\
783 Giving up after 50 iterations.\n");
784 #endif
785 } else {
786 masterPtr->flags.repackPending = 0;
787 Tk_GeometryRequest(masterPtr->tkwin,
788 masterPtr->reqSize[0], masterPtr->reqSize[1]);
789
790 ArrangeWhenIdle(masterPtr);
791 return;
792 }
793 }
794
795 masterPtr->numRequests = 0;
796
797 if (!Tk_IsMapped(masterPtr->tkwin)) {
798 goto done;
799 }
800
801 intBWidth = Tk_InternalBorderWidth(masterPtr->tkwin);
802 mSize[0] = Tk_Width(masterPtr->tkwin) - 2*intBWidth;
803 mSize[1] = Tk_Height(masterPtr->tkwin) - 2*intBWidth;
804
805 if (mSize[0] < 1 || mSize[1] <1) {
806 /* Master is not visible. Don't bother to place the clients
807 */
808 masterPtr->flags.repackPending = 0;
809 return;
810 }
811
812 /*
813 * Now set all the client's geometry
814 */
815 if (PlaceAllClients(masterPtr) != TCL_OK) {
816 panic("circular dependency");
817 }
818
819 for (clientPtr = masterPtr->client; clientPtr; clientPtr=clientPtr->next) {
820 if (clientPtr->tkwin == NULL) {
821 continue;
822 }
823 for (i=0; i<2; i++) {
824 for (j=0; j<2; j++) {
825 coord[i][j] = clientPtr->posn[i][j];
826 if (j == 1) {
827 coord[i][j] -= 1;
828 }
829 }
830 cSize[i] = coord[i][1] - coord[i][0]
831 - clientPtr->pad[i][0] - clientPtr->pad[i][1] + 1;
832 }
833
834 if ((cSize[0] <= 0) || (cSize[1] <= 0)) {
835 /*
836 * Window is too small, don't even bother to map
837 */
838 UnmapClient(clientPtr);
839 } else if ((coord[0][1] < 0) || (coord[1][1] < 0)) {
840 /*
841 * Window is outside of the master (left or top)
842 */
843 UnmapClient(clientPtr);
844 } else if ((coord[0][0] > mSize[0]) || (coord[1][0] > mSize[1])) {
845 /*
846 * Window is outside of the master (bottom or right)
847 */
848 UnmapClient(clientPtr);
849 } else {
850 /*
851 * Window is visible, then map it
852 */
853 MapClient(clientPtr,
854 coord[0][0] + clientPtr->pad[0][0] + intBWidth,
855 coord[1][0] + clientPtr->pad[1][0] + intBWidth,
856 cSize[0], cSize[1]);
857 }
858 }
859
860 done:
861 masterPtr->flags.repackPending = 0;
862 }
863
864 static int
865 PinnSide_AttNone(clientPtr, axis, which)
866 FormInfo *clientPtr; /* The client to pinn down */
867 int axis; /* 0 = x axis, 1 = yaxis */
868 int which; /* 0 = min side, 1= max side */
869 {
870 int reqSize;
871
872 if (clientPtr->attType[axis][NEXT_SIDE(which)] == ATT_NONE) {
873 if (which == SIDE0) {
874 clientPtr->side[axis][which].pcnt = 0;
875 clientPtr->side[axis][which].disp = 0;
876 return TCL_OK;
877 }
878 }
879
880 reqSize = ReqSize(clientPtr->tkwin, axis) +
881 clientPtr->pad[axis][0] + clientPtr->pad[axis][1];
882
883 PINN_CLIENT_SIDE(clientPtr, axis, NEXT_SIDE(which), 1);
884
885 clientPtr->side[axis][which].pcnt =
886 clientPtr->side[axis][NEXT_SIDE(which)].pcnt;
887
888 switch (which) {
889 case SIDE0:
890 clientPtr->side[axis][which].disp =
891 clientPtr->side[axis][NEXT_SIDE(which)].disp - reqSize;
892 break;
893
894 case SIDE1:
895 clientPtr->side[axis][which].disp =
896 clientPtr->side[axis][NEXT_SIDE(which)].disp + reqSize;
897 break;
898 }
899
900 return TCL_OK;
901 }
902
903 static int
904 PinnSide_AttPercent(clientPtr, axis, which)
905 FormInfo *clientPtr; /* The client to pinn down */
906 int axis; /* 0 = x axis, 1 = yaxis */
907 int which; /* 0 = min side, 1= max side */
908 {
909 clientPtr->side[axis][which].pcnt = clientPtr->att[axis][which].grid;
910 clientPtr->side[axis][which].disp = clientPtr->off[axis][which];
911
912 return TCL_OK;
913 }
914
915 static int
916 PinnSide_AttOpposite(clientPtr, axis, which)
917 FormInfo *clientPtr; /* The client to pinn down */
918 int axis; /* 0 = x axis, 1 = yaxis */
919 int which; /* 0 = min side, 1= max side */
920 {
921 FormInfo * attachPtr;
922
923 attachPtr = clientPtr->att[axis][which].widget;
924
925 PINN_CLIENT_SIDE(attachPtr, axis, NEXT_SIDE(which), 0);
926
927 clientPtr->side[axis][which].pcnt =
928 attachPtr->side[axis][NEXT_SIDE(which)].pcnt;
929 clientPtr->side[axis][which].disp =
930 attachPtr->side[axis][NEXT_SIDE(which)].disp +
931 clientPtr->off[axis][which];
932
933 return TCL_OK;
934 }
935
936 static int
937 PinnSide_AttParallel(clientPtr, axis, which)
938 FormInfo *clientPtr; /* The client to pinn down */
939 int axis; /* 0 = x axis, 1 = yaxis */
940 int which; /* 0 = min side, 1= max side */
941 {
942 FormInfo * attachPtr;
943
944 attachPtr = clientPtr->att[axis][which].widget;
945
946 PINN_CLIENT_SIDE(attachPtr, axis, which, 0);
947
948 clientPtr->side[axis][which].pcnt =
949 attachPtr->side[axis][which].pcnt;
950 clientPtr->side[axis][which].disp =
951 attachPtr->side[axis][which].disp +
952 clientPtr->off[axis][which];
953
954 return TCL_OK;
955 }
956
957
958 static int PinnClientSide(clientPtr, axis, which, isSelf)
959 FormInfo *clientPtr; /* The client to pinn down */
960 int axis; /* 0 = x axis, 1 = yaxis */
961 int which; /* 0 = min side, 1= max side */
962 int isSelf;
963 {
964 if ((which == SIDE0) && (clientPtr->sideFlags[axis] & PINNED_SIDE0)) {
965 /* already pinned */
966 return TCL_OK;
967 }
968 if ((which == SIDE1) && (clientPtr->sideFlags[axis] & PINNED_SIDE1)) {
969 /* already pinned */
970 return TCL_OK;
971 }
972
973 if ((clientPtr->depend > 0) && !isSelf) {
974 /*
975 * circular dependency detected
976 */
977 return TCL_ERROR;
978 }
979 clientPtr->depend ++;
980
981 switch (clientPtr->attType[axis][which]) {
982 case ATT_NONE:
983 if (PinnSide_AttNone(clientPtr, axis, which) == TCL_ERROR) {
984 return TCL_ERROR;
985 }
986 break;
987
988 case ATT_OPPOSITE:
989 if (PinnSide_AttOpposite(clientPtr, axis, which) == TCL_ERROR) {
990 return TCL_ERROR;
991 }
992 break;
993
994 case ATT_PARALLEL:
995 if (PinnSide_AttParallel(clientPtr, axis, which) == TCL_ERROR) {
996 return TCL_ERROR;
997 }
998 break;
999
1000 case ATT_GRID:
1001 if (PinnSide_AttPercent(clientPtr, axis, which) == TCL_ERROR) {
1002 return TCL_ERROR;
1003 }
1004 break;
1005 }
1006
1007 if (which == SIDE0) {
1008 clientPtr->sideFlags[axis] |= PINNED_SIDE0;
1009 } else {
1010 clientPtr->sideFlags[axis] |= PINNED_SIDE1;
1011 }
1012 clientPtr->depend --;
1013
1014 return TCL_OK;
1015 }
1016
1017 static int PinnClient(clientPtr)
1018 FormInfo *clientPtr;
1019 {
1020 int i;
1021
1022 for (i=0; i<2; i++) {
1023 if (!(clientPtr->sideFlags[i] & PINNED_SIDE0)) {
1024 PINN_CLIENT_SIDE(clientPtr, i, SIDE0, 0);
1025 }
1026 if (!(clientPtr->sideFlags[i] & PINNED_SIDE1)) {
1027 PINN_CLIENT_SIDE(clientPtr, i, SIDE1, 0);
1028 }
1029 }
1030
1031 return TCL_OK;
1032 }
1033
1034 /*
1035 *--------------------------------------------------------------
1036 *
1037 * CalculateMasterSize --
1038 *
1039 * This internal procedure is used to find out the required
1040 * size of a master window.
1041 *
1042 * Results:
1043 * The return value is a pointer to the FormInfo structure
1044 * corresponding to tkwin.
1045 *
1046 * Side effects:
1047 * the reqSize[2] values in masterPtr is updated.
1048 *
1049 *--------------------------------------------------------------
1050 */
1051 static void CalculateMasterSize(masterPtr)
1052 MasterInfo *masterPtr;
1053 {
1054 FormInfo *clientPtr;
1055 int i, cSize[2];
1056 int req[2];
1057 int intBWidth;
1058
1059 /* Information about the master window */
1060 intBWidth = Tk_InternalBorderWidth(masterPtr->tkwin);
1061 req[0] = req[1] = 2*intBWidth;
1062
1063 for (clientPtr = masterPtr->client; clientPtr; clientPtr=clientPtr->next) {
1064 if (clientPtr->tkwin == NULL) {
1065 continue;
1066 }
1067 cSize[0] = Tk_ReqWidth(clientPtr->tkwin);
1068 cSize[1] = Tk_ReqHeight(clientPtr->tkwin);
1069 cSize[0] += clientPtr->pad[0][0]+clientPtr->pad[0][1];
1070 cSize[1] += clientPtr->pad[1][0]+clientPtr->pad[1][1];
1071
1072 for (i=0; i<2; i++) {
1073 /* The required size of the master depends on
1074 * (1) natural sizes of the clients
1075 * (2) perc anchor points of the clients
1076 * Ideally, the master must include as much visible parts
1077 * of the clients as possible. It should also have a size
1078 * big enough so that all the clients' requested (natural)
1079 * sizes are satisfied. The algorithm is fairly simple, but
1080 * it took me quite a while to figure out and it quite difficult
1081 * to explain here. Please look at the following in-line
1082 * examples.
1083 */
1084 int p0 = clientPtr->side[i][0].pcnt;
1085 int p1 = clientPtr->side[i][1].pcnt;
1086 int d0 = clientPtr->side[i][0].disp;
1087 int d1 = clientPtr->side[i][1].disp;
1088
1089 int req0 = 0;
1090 int req1 = 0;
1091 int reqx = 0;
1092
1093 if (d0 < 0 && p0 != 0) {
1094 req0 = -d0 * masterPtr->grids[i] / p0;
1095 }
1096 if (d1 > 0 && p1 != masterPtr->grids[i]) {
1097 req1 = d1 * masterPtr->grids[i] / (masterPtr->grids[i] - p1);
1098 }
1099
1100 if (p0 == p1) {
1101 /* case 1 */
1102 /* Example: p0 = p1 = 10%; d0 = -10, d1 = 10
1103 * then mSize should at least be 100 pixels so that
1104 * side 0 can be visible. They are calculated in the
1105 * previous two if statements
1106 * result:
1107 * size = 100
1108 * side0 = 0;
1109 * side1 = 20;
1110 */
1111
1112 /* Two sides are attached to the same perc anchor point */
1113 if (d0 >= d1) {
1114 /* widget invisible */
1115 req0 = req1 = 0;
1116 }
1117 }
1118 else if (p0 < p1) {
1119 /* case 2 */
1120 /* Example: p0 10%, p2 = 20%; cSize = 35, d0 = -5, d1 = 0
1121 * then mSize should at least be 300 pixels so that
1122 * cSize can be satisfied.
1123 * result:
1124 * size = 300
1125 * side0 = 25;
1126 * side1 = 60;
1127 */
1128 int x = cSize[i];
1129 if (p0 != 0 || d0 > 0) {
1130 x += d0;
1131 }
1132 if (p1 != masterPtr->grids[i] || d1 < 0) {
1133 x += -d1;
1134 }
1135 if (x > 0) {
1136 reqx = x * masterPtr->grids[i] / (p1 - p0);
1137 }
1138 }
1139 else {
1140 /* case 2 */
1141 /* This is very similar to case 1, except there are more cases
1142 * in which the widget becomes invisible
1143 */
1144 if (d0 >=0 || d1 <=0) {
1145 /* widget invisible */
1146 req0 = req1 = 0;
1147 }
1148 }
1149
1150 if (req[i] < req0) {
1151 req[i] = req0;
1152 }
1153 if (req[i] < req1) {
1154 req[i] = req1;
1155 }
1156 if (req[i] < reqx) {
1157 req[i] = reqx;
1158 }
1159 }
1160 }
1161
1162 req[0] += 2*intBWidth;
1163 req[1] += 2*intBWidth;
1164
1165 masterPtr->reqSize[0] = (req[0] > 0) ? req[0] : 1;
1166 masterPtr->reqSize[1] = (req[1] > 0) ? req[1] : 1;
1167 }
1168
1169 /*
1170 *----------------------------------------------------------------------
1171 *
1172 * TixFm_StructureProc --
1173 *
1174 * This procedure is invoked by the Tk event dispatcher in response
1175 * to StructureNotify events.
1176 *
1177 * Results:
1178 * None.
1179 *
1180 * Side effects:
1181 * If a window was just deleted, clean up all its packer-related
1182 * information. If it was just resized, repack its clients, if
1183 * any.
1184 *
1185 *----------------------------------------------------------------------
1186 */
1187
1188 void
1189 TixFm_StructureProc(clientData, eventPtr)
1190 ClientData clientData; /* Our information about window
1191 * referred to by eventPtr. */
1192 XEvent *eventPtr; /* Describes what just happened. */
1193 {
1194 FormInfo *clientPtr = (FormInfo *) clientData;
1195
1196 switch (eventPtr->type) {
1197 case ConfigureNotify:
1198 ArrangeWhenIdle(clientPtr->master);
1199 break;
1200
1201 case DestroyNotify:
1202 if (clientPtr->master) {
1203 TixFm_Unlink(clientPtr);
1204 }
1205 break;
1206
1207 case MapNotify:
1208 break;
1209
1210 case UnmapNotify:
1211 break;
1212 }
1213 }
1214
1215 static void
1216 TixFm_ReqProc(clientData, tkwin)
1217 ClientData clientData; /* TixForm's information about
1218 * window that got new preferred
1219 * geometry. */
1220 Tk_Window tkwin; /* Other Tk-related information
1221 * about the window. */
1222 {
1223 FormInfo *clientPtr = (FormInfo *) clientData;
1224
1225 if (clientPtr) {
1226 ArrangeWhenIdle(clientPtr->master);
1227 }
1228 }
1229
1230 static void
1231 MasterStructureProc(clientData, eventPtr)
1232 ClientData clientData; /* Our information about window
1233 * referred to by eventPtr. */
1234 XEvent *eventPtr; /* Describes what just happened. */
1235 {
1236 MasterInfo *masterPtr = (MasterInfo *) clientData;
1237
1238 switch (eventPtr->type) {
1239 case ConfigureNotify:
1240 if (masterPtr->numClients > 0) {
1241 ArrangeWhenIdle(masterPtr);
1242 }
1243 break;
1244
1245 case DestroyNotify:
1246 TixFm_DeleteMaster(masterPtr);
1247 break;
1248
1249 case MapNotify:
1250 break;
1251
1252 case UnmapNotify:
1253 break;
1254 }
1255 }
1256
1257 /*
1258 *--------------------------------------------------------------
1259 *
1260 * TixFm_LostSlaveProc --
1261 *
1262 * This procedure is invoked by Tk whenever some other geometry
1263 * claims control over a slave that used to be managed by us.
1264 *
1265 * Results:
1266 * None.
1267 *
1268 * Side effects:
1269 * Forgets all packer-related information about the slave.
1270 *
1271 *--------------------------------------------------------------
1272 */
1273 static void
1274 TixFm_LostSlaveProc(clientData, tkwin)
1275 ClientData clientData; /* Form structure for slave window that
1276 * was stolen away. */
1277 Tk_Window tkwin; /* Tk's handle for the slave window. */
1278 {
1279 FormInfo *clientPtr = (FormInfo *) clientData;
1280
1281 Tk_DeleteEventHandler(clientPtr->tkwin, StructureNotifyMask,
1282 TixFm_StructureProc, (ClientData) clientPtr);
1283 if (clientPtr->master->tkwin != Tk_Parent(clientPtr->tkwin)) {
1284 Tk_UnmaintainGeometry(clientPtr->tkwin, clientPtr->master->tkwin);
1285 }
1286 Tk_UnmapWindow(clientPtr->tkwin);
1287 TixFm_Unlink(clientPtr);
1288 }
1289
1290 /*
1291 * Do some basic integrity checking
1292 * --> right, left cannot both attach to none
1293 * --> top, bottom cannot both attach to none.
1294 * Otherwise, top or left is always set to attach at {pixel 0}
1295 */
1296 static void CheckIntergrity(clientPtr)
1297 FormInfo * clientPtr;
1298 {
1299 #if 0
1300 /* Check the X axis */
1301 if ((clientPtr->attType[0][0] == ATT_NONE)
1302 &&(clientPtr->attType[0][1] == ATT_NONE)) {
1303 clientPtr->attType[0][0] = ATT_DEFAULT_PIXEL;
1304 clientPtr->att[0][0].grid = 0;
1305 }
1306
1307 /* Check the Y axis */
1308 if ((clientPtr->attType[1][0] == ATT_NONE)
1309 &&(clientPtr->attType[1][1] == ATT_NONE)) {
1310 clientPtr->attType[1][0] = ATT_DEFAULT_PIXEL;
1311 clientPtr->att[1][0].grid = 0;
1312 }
1313 #endif
1314 }
1315
1316 /*----------------------------------------------------------------------
1317 * Memory management routines
1318 *
1319 *----------------------------------------------------------------------
1320 */
1321 void TixFm_AddToMaster(masterPtr, clientPtr)
1322 MasterInfo *masterPtr;
1323 FormInfo *clientPtr;
1324 {
1325 if (clientPtr->master == masterPtr) {
1326 /* already in master */
1327 return;
1328 }
1329
1330 if (clientPtr->master != NULL) {
1331 /* We have to migrate the widget to a different parent*/
1332 }
1333
1334 clientPtr->master = masterPtr;
1335
1336 if (masterPtr->client == NULL) {
1337 masterPtr->client = clientPtr;
1338 masterPtr->client_tail = clientPtr;
1339 } else {
1340 masterPtr->client_tail->next = clientPtr;
1341 }
1342 clientPtr->next = NULL;
1343 masterPtr->client_tail = clientPtr;
1344
1345 ++ masterPtr->numClients;
1346
1347 /* Manage its geometry using my proc */
1348 Tk_ManageGeometry(clientPtr->tkwin, &formType, (ClientData)clientPtr);
1349 }
1350
1351 void TixFm_UnlinkFromMaster(clientPtr)
1352 FormInfo *clientPtr;
1353 {
1354 MasterInfo *masterPtr;
1355 FormInfo *ptr, *prev;
1356
1357 #if DEBUG
1358 fprintf(stderr, "unlinking %s\n", Tk_PathName(clientPtr->tkwin));
1359 #endif
1360
1361 masterPtr = clientPtr->master;
1362
1363 /* First: get rid of the reference of this widget from other clients */
1364 for (ptr=masterPtr->client; ptr; ptr=ptr->next) {
1365 if (ptr != clientPtr) {
1366 int i, j;
1367 for (i=0; i<2; i++) {
1368 for (j=0; j<2; j++) {
1369 switch (ptr->attType[i][j]) {
1370 case ATT_OPPOSITE:
1371 case ATT_PARALLEL:
1372 if (ptr->att[i][j].widget == clientPtr) {
1373 ptr->attType[i][j] = ATT_GRID;
1374 ptr->att[i][j].grid = 0;
1375 ptr->off[i][j] = ptr->posn[i][j];
1376 }
1377 break;
1378 }
1379 }
1380 if (ptr->strWidget[i][j] == clientPtr) {
1381 ptr->strWidget[i][j] = 0;
1382 }
1383 }
1384 }
1385 }
1386
1387 /* Second: delete this client from the list */
1388 for (prev=ptr=masterPtr->client; ptr; prev=ptr,ptr=ptr->next) {
1389 if (ptr == clientPtr) {
1390 if (prev==ptr) {
1391 if (masterPtr->numClients == 1) {
1392 masterPtr->client_tail = NULL;
1393 }
1394 masterPtr->client = ptr->next;
1395 }
1396 else {
1397 if (ptr->next == NULL) {
1398 masterPtr->client_tail = prev;
1399 }
1400 prev->next = ptr->next;
1401 }
1402 break;
1403 }
1404 }
1405 -- masterPtr->numClients;
1406 }
1407
1408 void
1409 TixFm_FreeMasterInfo(clientData)
1410 char *clientData;
1411 {
1412 MasterInfo *masterPtr = (MasterInfo *)clientData;
1413 ckfree((char*)masterPtr);
1414 }
1415
1416 void TixFm_DeleteMaster(masterPtr)
1417 MasterInfo *masterPtr;
1418 {
1419 Tcl_HashEntry *hPtr;
1420 FormInfo *clientPtr, * toFree;
1421
1422 if (masterPtr->flags.isDeleted) {
1423 return;
1424 }
1425
1426 Tk_DeleteEventHandler(masterPtr->tkwin, StructureNotifyMask,
1427 MasterStructureProc, (ClientData) masterPtr);
1428
1429 clientPtr=masterPtr->client;
1430 while(clientPtr) {
1431 toFree = clientPtr;
1432 clientPtr = clientPtr->next;
1433 TixFm_ForgetOneClient(toFree);
1434 }
1435
1436 hPtr = Tcl_FindHashEntry(&masterInfoHashTable,(char*)masterPtr->tkwin);
1437 if (hPtr) {
1438 Tcl_DeleteHashEntry(hPtr);
1439 }
1440 CancelArrangeWhenIdle(masterPtr);
1441 masterPtr->flags.isDeleted = 1;
1442 Tcl_EventuallyFree((ClientData)masterPtr, TixFm_FreeMasterInfo);
1443 }
1444
1445
1446 void TixFm_Unlink(clientPtr)
1447 FormInfo *clientPtr;
1448 {
1449 Tcl_HashEntry *hPtr;
1450 MasterInfo *masterPtr;
1451
1452 /* Delete this clientPtr from the master's list */
1453 TixFm_UnlinkFromMaster(clientPtr);
1454
1455 /* Eventually free this clientPtr structure */
1456 hPtr = Tcl_FindHashEntry(&formInfoHashTable,(char*)clientPtr->tkwin);
1457 if (hPtr != NULL) {
1458 Tcl_DeleteHashEntry(hPtr);
1459 }
1460 clientPtr->tkwin = NULL;
1461 masterPtr = clientPtr->master;
1462 ckfree((char*)clientPtr);
1463
1464 ArrangeWhenIdle(masterPtr);
1465 }
1466
1467
1468 /*
1469 *--------------------------------------------------------------
1470 *
1471 * TixFm_GetFormInfo --
1472 *
1473 * This internal procedure is used to locate a FormInfo
1474 * structure for a given window, creating one if one
1475 * doesn't exist already.
1476 *
1477 * Results:
1478 * The return value is a pointer to the FormInfo structure
1479 * corresponding to tkwin.
1480 *
1481 * Side effects:
1482 * A new FormInfo structure may be created. If so, then
1483 * a callback is set up to clean things up when the
1484 * window is deleted.
1485 *
1486 *--------------------------------------------------------------
1487 */
1488 FormInfo *
1489 TixFm_GetFormInfo(tkwin, create)
1490 Tk_Window tkwin; /* Token for window for which
1491 * FormInfo structure is desired. */
1492 int create;
1493 {
1494 FormInfo *clientPtr;
1495 Tcl_HashEntry *hPtr;
1496 int isNew;
1497 int i,j;
1498
1499 if (!initialized) {
1500 initialized = 1;
1501 Tcl_InitHashTable(&formInfoHashTable, TCL_ONE_WORD_KEYS);
1502 Tcl_InitHashTable(&masterInfoHashTable, TCL_ONE_WORD_KEYS);
1503 }
1504
1505 /*
1506 * See if there's already FormInfo for this window. If not,
1507 * then create a new one.
1508 */
1509 if (!create) {
1510 hPtr = Tcl_FindHashEntry(&formInfoHashTable, (char *)tkwin);
1511 if (!hPtr) {
1512 return NULL;
1513 } else {
1514 return (FormInfo *) Tcl_GetHashValue(hPtr);
1515 }
1516 } else {
1517 hPtr = Tcl_CreateHashEntry(&formInfoHashTable, (char *) tkwin, &isNew);
1518 if (!isNew) {
1519 return (FormInfo *) Tcl_GetHashValue(hPtr);
1520 } else {
1521 clientPtr = (FormInfo *) ckalloc(sizeof(FormInfo));
1522 clientPtr->tkwin = tkwin;
1523 clientPtr->master = NULL;
1524 clientPtr->next = NULL;
1525
1526 for (i=0; i< 2; i++) {
1527 for (j=0; j< 2; j++) {
1528 clientPtr->attType[i][j] = ATT_NONE;
1529 clientPtr->att[i][j].grid = 0;
1530 clientPtr->att[i][j].widget = NULL;
1531 clientPtr->off[i][j] = 0;
1532
1533 clientPtr->pad[i][j] = 0;
1534 clientPtr->side[i][j].pcnt = 0;
1535 clientPtr->side[i][j].disp = 0;
1536
1537 clientPtr->spring[i][j] = -1;
1538 clientPtr->strWidget[i][j] = 0;
1539 }
1540 clientPtr->springFail[i] = 0;
1541 clientPtr->fill[i] = 0;
1542 }
1543
1544 Tcl_SetHashValue(hPtr, clientPtr);
1545
1546 Tk_CreateEventHandler(tkwin, StructureNotifyMask,
1547 TixFm_StructureProc, (ClientData) clientPtr);
1548
1549 return clientPtr;
1550 }
1551 }
1552 }
1553
1554 static MasterInfo *
1555 GetMasterInfo(tkwin, create)
1556 Tk_Window tkwin; /* Token for window for which
1557 * FormInfo structure is desired. */
1558 int create; /* Should I create the MasterInfo if it
1559 * does not exist? */
1560 {
1561 MasterInfo *masterPtr;
1562 Tcl_HashEntry *hPtr;
1563 int isNew;
1564
1565 if (!initialized) {
1566 initialized = 1;
1567 Tcl_InitHashTable(&formInfoHashTable, TCL_ONE_WORD_KEYS);
1568 Tcl_InitHashTable(&masterInfoHashTable, TCL_ONE_WORD_KEYS);
1569 }
1570
1571 /*
1572 * See if there's already FormInfo for this window. If not,
1573 * then create a new one.
1574 */
1575 if (!create) {
1576 hPtr = Tcl_FindHashEntry(&masterInfoHashTable, (char *)tkwin);
1577 if (!hPtr) {
1578 return NULL;
1579 } else {
1580 return (MasterInfo *) Tcl_GetHashValue(hPtr);
1581 }
1582 } else {
1583 hPtr = Tcl_CreateHashEntry(&masterInfoHashTable, (char *)tkwin,
1584 &isNew);
1585 if (!isNew) {
1586 masterPtr = (MasterInfo *) Tcl_GetHashValue(hPtr);
1587 }
1588 else {
1589 masterPtr = (MasterInfo *) ckalloc(sizeof(MasterInfo));
1590 masterPtr->tkwin = tkwin;
1591 masterPtr->client = NULL;
1592 masterPtr->client_tail = NULL;
1593 masterPtr->flags.repackPending = 0;
1594 masterPtr->flags.isDeleted = 0;
1595 masterPtr->numClients = 0;
1596 masterPtr->numRequests = 0;
1597 masterPtr->grids[0] = 100;
1598 masterPtr->grids[1] = 100;
1599
1600 Tcl_SetHashValue(hPtr, masterPtr);
1601 }
1602 }
1603
1604 /* TK BUG:
1605 *
1606 * It seems like if you destroy some slaves TK will delete the event
1607 * handler. So for sure we just create it every time a slave is created.
1608 *
1609 * Note: calling Tk_CreateEventHandler with same arguments twice won't
1610 * create two instances of the same event handler: Thus safe to call
1611 * blindly.
1612 */
1613 Tk_CreateEventHandler(tkwin, StructureNotifyMask,
1614 MasterStructureProc, (ClientData) masterPtr);
1615 #if 0
1616 Tk_ManageGeometry(tkwin, (Tk_GeomMgr *)&masterType,
1617 (ClientData) masterPtr);
1618 #endif
1619 return masterPtr;
1620 }
1621
1622 /*----------------------------------------------------------------------
1623 * PLace the clients
1624 *----------------------------------------------------------------------
1625 */
1626 static int PlaceSide_AttNone(clientPtr, axis, which)
1627 FormInfo *clientPtr; /* The client to Place down */
1628 int axis; /* 0 = x axis, 1 = yaxis */
1629 int which; /* 0 = min side, 1= max side */
1630 {
1631 int reqSize;
1632
1633 if (clientPtr->attType[axis][NEXT_SIDE(which)] == ATT_NONE) {
1634 if (which == SIDE0) {
1635 clientPtr->posn[axis][which] = 0;
1636 return TCL_OK;
1637 }
1638 }
1639
1640 reqSize = ReqSize(clientPtr->tkwin, axis) +
1641 clientPtr->pad[axis][0] + clientPtr->pad[axis][1];
1642
1643
1644 PLACE_CLIENT_SIDE(clientPtr, axis, NEXT_SIDE(which), 1);
1645
1646 switch (which) {
1647 case SIDE0:
1648 clientPtr->posn[axis][which] =
1649 clientPtr->posn[axis][NEXT_SIDE(which)] - reqSize;
1650 break;
1651
1652 case SIDE1:
1653 clientPtr->posn[axis][which] =
1654 clientPtr->posn[axis][NEXT_SIDE(which)] + reqSize;
1655 break;
1656 }
1657
1658 return TCL_OK;
1659 }
1660
1661 static int PlaceSide_AttAbsolute(clientPtr, axis, which)
1662 FormInfo *clientPtr; /* The client to Place down */
1663 int axis; /* 0 = x axis, 1 = yaxis */
1664 int which; /* 0 = min side, 1= max side */
1665 {
1666 int mSize[2];
1667 MasterInfo * masterPtr = clientPtr->master;
1668 int intBWidth = Tk_InternalBorderWidth(masterPtr->tkwin);
1669 mSize[0] = Tk_Width(masterPtr->tkwin) - 2*intBWidth;
1670 mSize[1] = Tk_Height(masterPtr->tkwin) - 2*intBWidth;
1671
1672 clientPtr->posn[axis][which] =
1673 mSize[axis] * clientPtr->side[axis][which].pcnt/masterPtr->grids[axis] +
1674 clientPtr->side[axis][which].disp;
1675
1676 return TCL_OK;
1677 }
1678
1679 static int PlaceSide_AttOpposite(clientPtr, axis, which)
1680 FormInfo *clientPtr; /* The client to Place down */
1681 int axis; /* 0 = x axis, 1 = yaxis */
1682 int which; /* 0 = min side, 1= max side */
1683 {
1684 FormInfo * attachPtr;
1685
1686 attachPtr = clientPtr->att[axis][which].widget;
1687
1688 PLACE_CLIENT_SIDE(attachPtr, axis, NEXT_SIDE(which), 0);
1689
1690 clientPtr->posn[axis][which] = attachPtr->posn[axis][NEXT_SIDE(which)];
1691 clientPtr->posn[axis][which] += clientPtr->off[axis][which];
1692 return TCL_OK;
1693 }
1694
1695 static int PlaceSide_AttParallel(clientPtr, axis, which)
1696 FormInfo *clientPtr; /* The client to Place down */
1697 int axis; /* 0 = x axis, 1 = yaxis */
1698 int which; /* 0 = min side, 1= max side */
1699 {
1700 FormInfo * attachPtr;
1701
1702 attachPtr = clientPtr->att[axis][which].widget;
1703
1704 PLACE_CLIENT_SIDE(attachPtr, axis, NEXT_SIDE(which), 0);
1705
1706 clientPtr->posn[axis][which] = attachPtr->posn[axis][which];
1707 clientPtr->posn[axis][which] += clientPtr->off[axis][which];
1708
1709 return TCL_OK;
1710 }
1711
1712
1713 static int PlaceSimpleCase(clientPtr, axis, which)
1714 FormInfo *clientPtr; /* The client to Place down */
1715 int axis; /* 0 = x axis, 1 = yaxis */
1716 int which; /* 0 = min side, 1= max side */
1717 {
1718 clientPtr->depend ++;
1719
1720 switch (clientPtr->attType[axis][which]) {
1721 case ATT_NONE:
1722 if (PlaceSide_AttNone(clientPtr, axis, which) == TCL_ERROR) {
1723 return TCL_ERROR;
1724 }
1725 break;
1726
1727 case ATT_GRID:
1728 if (PlaceSide_AttAbsolute(clientPtr, axis, which) == TCL_ERROR) {
1729 return TCL_ERROR;
1730 }
1731 break;
1732
1733 case ATT_OPPOSITE:
1734 if (PlaceSide_AttOpposite(clientPtr, axis, which) == TCL_ERROR) {
1735 return TCL_ERROR;
1736 }
1737 break;
1738 case ATT_PARALLEL:
1739 if (PlaceSide_AttParallel(clientPtr, axis, which) == TCL_ERROR) {
1740 return TCL_ERROR;
1741 }
1742 break;
1743 }
1744
1745 if (which == SIDE0) {
1746 clientPtr->sideFlags[axis] |= PINNED_SIDE0;
1747 } else {
1748 clientPtr->sideFlags[axis] |= PINNED_SIDE1;
1749 }
1750 clientPtr->depend --;
1751
1752 return TCL_OK;
1753 }
1754
1755 /* ToDo: I'll make this more efficient by pre-allocating some links */
1756 static SpringLink *
1757 AllocSpringLink()
1758 {
1759 return (SpringLink *) ckalloc(sizeof(SpringLink));
1760 }
1761
1762 static void
1763 FreeSpringLink(link)
1764 SpringLink * link;
1765 {
1766 ckfree((char*)link);
1767 }
1768
1769 static void FreeSpringList(listPtr)
1770 SpringList * listPtr;
1771 {
1772 SpringLink * link, * toFree;
1773
1774 for (link=listPtr->head; link; ) {
1775 toFree = link;
1776 link=link->next;
1777 FreeSpringLink(toFree);
1778 }
1779 }
1780
1781 static void
1782 AddRightSprings(listPtr, clientPtr)
1783 SpringList * listPtr;
1784 FormInfo *clientPtr;
1785 {
1786 SpringLink * link = AllocSpringLink();
1787
1788 link->next = NULL;
1789 link->clientPtr = clientPtr;
1790
1791 if (listPtr->head == NULL) {
1792 listPtr->head = listPtr->tail = link;
1793 } else {
1794 listPtr->tail->next = link;
1795 listPtr->tail = link;
1796 }
1797 ++ listPtr->num;
1798 }
1799
1800 static void
1801 AddLeftSprings(listPtr,clientPtr)
1802 SpringList * listPtr;
1803 FormInfo *clientPtr;
1804 {
1805 SpringLink * link = AllocSpringLink();
1806
1807 link->next = listPtr->head;
1808 link->clientPtr = clientPtr;
1809
1810 listPtr->head = link;
1811 ++ listPtr->num;
1812 }
1813
1814 static int
1815 PlaceWithSpring(clientPtr, axis, which)
1816 FormInfo *clientPtr; /* The client to Place down */
1817 int axis; /* 0 = x axis, 1 = yaxis */
1818 int which; /* 0 = min side, 1= max side */
1819 {
1820 SpringList springs;
1821 SpringLink * link;
1822 FormInfo *ptr;
1823 float boundary[2];
1824 float totalSize, totalStrength;
1825 int mSize[2];
1826 float gap, disp;
1827 MasterInfo * masterPtr = clientPtr->master;
1828 int intBWidth = Tk_InternalBorderWidth(masterPtr->tkwin);
1829
1830 springs.head = (SpringLink *)0;
1831 springs.tail = (SpringLink *)0;
1832 springs.num = 0;
1833
1834 mSize[0] = Tk_Width(masterPtr->tkwin) - 2*intBWidth;
1835 mSize[1] = Tk_Height(masterPtr->tkwin) - 2*intBWidth;
1836
1837 /* Expand the right side of the spring list */
1838 ptr = clientPtr;
1839 while (1) {
1840 switch (ptr->attType[axis][1]) {
1841 case ATT_OPPOSITE:
1842 case ATT_NONE:
1843 /* Some attachments */
1844 AddRightSprings(&springs, ptr);
1845
1846 if ((ptr = ptr->strWidget[axis][1]) == 0) {
1847 goto done1;
1848 }
1849
1850 switch (ptr->attType[axis][0]) {
1851 case ATT_GRID:
1852 case ATT_PARALLEL:
1853 goto done1;
1854 }
1855 break;
1856
1857 case ATT_GRID:
1858 case ATT_PARALLEL:
1859 AddRightSprings(&springs, ptr);
1860 goto done1;
1861 }
1862 }
1863
1864 done1:
1865 /* Expand the left side of the spring list */
1866
1867 ptr = clientPtr;
1868 while (2) {
1869 switch (ptr->attType[axis][0]) {
1870 case ATT_OPPOSITE:
1871 case ATT_NONE:
1872 /* Some attachments */
1873 if (ptr != clientPtr) {
1874 AddLeftSprings(&springs, ptr);
1875 }
1876
1877 if ((ptr = ptr->strWidget[axis][0]) == 0) {
1878 goto done2;
1879 }
1880
1881 switch (ptr->attType[axis][1]) {
1882 case ATT_PARALLEL:
1883 goto done2;
1884 }
1885 break;
1886
1887 case ATT_GRID:
1888 case ATT_PARALLEL:
1889 if (ptr != clientPtr) {
1890 AddLeftSprings(&springs, ptr);
1891 }
1892
1893 goto done2;
1894 }
1895 }
1896
1897 done2:
1898
1899 /* Make sure this is a good list (neither ends are none) */
1900 if (springs.head == NULL) {
1901 /* this should never happen, just to make sure */
1902 goto fail;
1903 }
1904 if (springs.head->clientPtr->attType[axis][0] == ATT_NONE) {
1905 goto fail;
1906 }
1907 if (springs.tail->clientPtr->attType[axis][1] == ATT_NONE) {
1908 goto fail;
1909 }
1910
1911 /*
1912 * Now calculate the total requested sizes of the spring group
1913 */
1914 totalSize = (float)(0.0);
1915 totalStrength = (float)(0.0);
1916 for (link=springs.head; link; link=link->next) {
1917 int size = ReqSize(link->clientPtr->tkwin, axis);
1918
1919 totalSize += size + link->clientPtr->pad[axis][0] +
1920 link->clientPtr->pad[axis][1];
1921
1922 if (link->clientPtr->spring[axis][0] > 0) {
1923 totalStrength += link->clientPtr->spring[axis][0];
1924 }
1925 }
1926 if (springs.tail->clientPtr->spring[axis][1] > 0) {
1927 totalStrength += springs.tail->clientPtr->spring[axis][1];
1928 }
1929
1930 boundary[0] = (float) mSize[axis] *
1931 (float) springs.head->clientPtr->side[axis][0].pcnt /
1932 (float) masterPtr->grids[axis] +
1933 (float) springs.head->clientPtr->side[axis][0].disp;
1934 boundary[1] = (float) mSize[axis] *
1935 (float) springs.tail->clientPtr->side[axis][1].pcnt /
1936 (float) masterPtr->grids[axis] +
1937 (float) springs.tail->clientPtr->side[axis][1].disp;
1938
1939 /* (4) Now spread the sizes to the members of this list */
1940 gap = (float)(boundary[1] - boundary[0]) - totalSize;
1941 if (gap < 0) {
1942 goto fail;
1943 }
1944
1945 disp = boundary[0];
1946 if (totalStrength <= 0.0) {
1947 totalStrength = (float)(1.0);
1948 }
1949 for (link=springs.head; link; link=link->next) {
1950 float spring0, spring1;
1951 int gap0, gap1;
1952 int adjust; /* to overcome round-off errors */
1953
1954 spring0 = (float)link->clientPtr->spring[axis][0];
1955 spring1 = (float)link->clientPtr->spring[axis][1];
1956
1957 if (spring0 < (float)(0.0)) {
1958 spring0 = (float)(0.0);
1959 }
1960 if (spring1 < (float)(0.0)) {
1961 spring1 = (float)(0.0);
1962 }
1963
1964 /* Divide by two: because two consecutive clients share the same
1965 * spring; so each of them get a half.
1966 */
1967 adjust = 0;
1968 if (link !=springs.head) {
1969 if (spring0 > 0 && link->clientPtr->spring[axis][0] % 2 == 1) {
1970 adjust = 1;
1971 }
1972 spring0 /= (float)(2.0);
1973 }
1974 if (link !=springs.tail) {
1975 spring1 /= (float)(2.0);
1976 }
1977
1978 gap0 = (int)(gap * spring0 / totalStrength) + adjust;
1979 gap1 = (int)(gap * spring1 / totalStrength);
1980
1981 if (link->clientPtr->fill[axis]) {
1982 link->clientPtr->posn[axis][0] = (int)disp;
1983 disp += gap0;
1984 disp += gap1;
1985 disp += ReqSize(link->clientPtr->tkwin, axis);
1986
1987 /* Somehow there may be a round-off right at the end of the
1988 * list --> kludge*/
1989 if (link->next == NULL) {
1990 disp = boundary[1];
1991 }
1992 link->clientPtr->posn[axis][1] = (int)disp;
1993 } else {
1994 disp += gap0;
1995 link->clientPtr->posn[axis][0] = (int)disp;
1996 disp += ReqSize(link->clientPtr->tkwin, axis);
1997 link->clientPtr->posn[axis][1] = (int)disp;
1998 disp += gap1;
1999
2000 /*
2001 * Somehow there may be a round-off right at the end of the
2002 * list --> kludge
2003 */
2004 if (link->next == NULL && gap1 < 0.001) {
2005 link->clientPtr->posn[axis][1] = (int)boundary[1];
2006 }
2007 }
2008
2009 link->clientPtr->sideFlags[axis] |= PINNED_SIDE0;
2010 link->clientPtr->sideFlags[axis] |= PINNED_SIDE1;
2011 }
2012
2013 FreeSpringList(&springs);
2014 return TCL_OK;
2015
2016 fail:
2017 for (link=springs.head; link; link=link->next) {
2018 link->clientPtr->springFail[axis] = 1;
2019 }
2020 FreeSpringList(&springs);
2021 return TCL_ERROR;
2022 }
2023
2024 static int PlaceClientSide(clientPtr, axis, which, isSelf)
2025 FormInfo *clientPtr; /* The client to Place down */
2026 int axis; /* 0 = x axis, 1 = yaxis */
2027 int which; /* 0 = min side, 1= max side */
2028 int isSelf;
2029 {
2030 if ((which == SIDE0) && (clientPtr->sideFlags[axis] & PINNED_SIDE0)) {
2031 /* already Placeed */
2032 return TCL_OK;
2033 }
2034 if ((which == SIDE1) && (clientPtr->sideFlags[axis] & PINNED_SIDE1)) {
2035 /* already Placeed */
2036 return TCL_OK;
2037 }
2038
2039 if ((clientPtr->depend > 0) && !isSelf) {
2040 /*
2041 * circular dependency detected
2042 */
2043 return TCL_ERROR;
2044 }
2045
2046 /* No spring : we just do a "simple case"
2047 * The condition is ( (x || x) && (x || x) )
2048 */
2049 if ((clientPtr->spring[axis][0] < 0 ||
2050 (clientPtr->sideFlags[axis] & PINNED_SIDE0)) &&
2051 (clientPtr->spring[axis][1] < 0 ||
2052 (clientPtr->sideFlags[axis] & PINNED_SIDE1))) {
2053 return PlaceSimpleCase(clientPtr, axis, which);
2054 }
2055 if (clientPtr->springFail[axis]) {
2056 return PlaceSimpleCase(clientPtr, axis, which);
2057 }
2058
2059 if (PlaceWithSpring(clientPtr, axis, which) != TCL_OK) {
2060 /* if comes to here : (1) Not enough space for the spring expansion
2061 * (2) Not both end-sides are spring-attached */
2062 return PlaceSimpleCase(clientPtr, axis, which);
2063 } else {
2064 return TCL_OK;
2065 }
2066 }
2067
2068 static int PlaceClient(clientPtr)
2069 FormInfo *clientPtr;
2070 {
2071 int i;
2072
2073 for (i=0; i<2; i++) {
2074 if (!(clientPtr->sideFlags[i] & PINNED_SIDE0)) {
2075 PLACE_CLIENT_SIDE(clientPtr, i, SIDE0, 0);
2076 }
2077 if (!(clientPtr->sideFlags[i] & PINNED_SIDE1)) {
2078 PLACE_CLIENT_SIDE(clientPtr, i, SIDE1, 0);
2079 }
2080 }
2081
2082 return TCL_OK;
2083 }
2084
2085 static int PlaceAllClients(masterPtr)
2086 MasterInfo * masterPtr;
2087 {
2088 FormInfo *clientPtr;
2089 int i;
2090
2091 /*
2092 * First mark all clients as unpinned, and clean the opposite flags,
2093 */
2094 for (clientPtr = masterPtr->client; clientPtr; clientPtr=clientPtr->next) {
2095 if (clientPtr->tkwin != NULL) {
2096 for (i=0; i<2; i++) {
2097 /* clear all flags */
2098 clientPtr->sideFlags[i] = 0;
2099 clientPtr->springFail[i] = 0;
2100 }
2101 clientPtr->depend = 0;
2102 }
2103 }
2104
2105 /*
2106 * Now calculate their actual positions on the master
2107 */
2108 for (clientPtr = masterPtr->client; clientPtr; clientPtr=clientPtr->next) {
2109 if (clientPtr->tkwin == NULL) { /* it was deleted */
2110 continue;
2111 }
2112 for (i=0; i<2; i++) {
2113 if ((clientPtr->sideFlags[i] & PINNED_ALL) != PINNED_ALL) {
2114 if (PlaceClient(clientPtr) == TCL_ERROR) {
2115 /*
2116 * Detected circular dependency
2117 */
2118 return TCL_ERROR;
2119 }
2120 break;
2121 }
2122 }
2123 }
2124 return TCL_OK;
2125 }