Tk Source Code

Changes On Branch spjuth-gridpeer
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch spjuth-gridpeer Excluding Merge-Ins

This is equivalent to a diff from 2a868d77ab to 9065bb83fd

2015-03-02
08:56
Deleted Win95/98-specific documentation as those platforms have long been unsupported. check-in: e4a9133b19 user: ashok tags: trunk
2015-03-01
13:57
Merge from trunk Leaf check-in: 9e988ea8e5 user: pspjuth tags: spjuth-cleanpack
13:45
Merge from trunk Leaf check-in: 3798a95cb6 user: pspjuth tags: spjuth-gridscroll
13:43
Merge from trunk Leaf check-in: 9065bb83fd user: pspjuth tags: spjuth-gridpeer
13:43
Merge from trunk check-in: d87cb7b905 user: pspjuth tags: spjuth-gridpeer
2015-02-28
03:17
merge mark check-in: 2a868d77ab user: kevin_walzer tags: trunk
02:59
Fix for 5824a992df, images not displaying in Cocoa in label with sunken relief check-in: c4051e7ad3 user: kevin_walzer tags: core-8-5-branch
02:59
Fix for 5824a992df, images not displaying in Cocoa in label with sunken relief check-in: 2f9e63f890 user: kevin_walzer tags: trunk

Changes to generic/tkGrid.c.

140
141
142
143
144
145
146











147
148
149
150
151
152
153
    				 * row constraints. */
    int startX;			/* Pixel offset of this layout within its
    				 * master. */
    int startY;			/* Pixel offset of this layout within its
    				 * master. */
    Tk_Anchor anchor;		/* Value of anchor option: specifies where a
				 * grid without weight should be placed. */











} GridMaster;

/*
 * For each window that the grid cares about (either because the window is
 * managed by the grid or because the window has slaves that are managed by
 * the grid), there is a structure of the following type:
 */







>
>
>
>
>
>
>
>
>
>
>







140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
    				 * row constraints. */
    int startX;			/* Pixel offset of this layout within its
    				 * master. */
    int startY;			/* Pixel offset of this layout within its
    				 * master. */
    Tk_Anchor anchor;		/* Value of anchor option: specifies where a
				 * grid without weight should be placed. */
    char *xScrollCmd;		/* Command prefix for communicating with
				 * horizontal scrollbar.  NULL means no
				 * horizontal scrollbar.  Malloc'ed*/
    char *yScrollCmd;		/* Command prefix for communicating with
				 * vertical scrollbar.  NULL means no
				 * vertical scrollbar.  Malloc'ed*/
    struct Gridder *nextColPeerPtr;
    struct Gridder *nextRowPeerPtr;
    int xOrigin, yOrigin;
    int xUsed, yUsed;
    Tcl_Interp *interp;
} GridMaster;

/*
 * For each window that the grid cares about (either because the window is
 * managed by the grid or because the window has slaves that are managed by
 * the grid), there is a structure of the following type:
 */
260
261
262
263
264
265
266




267
268
269
270
271
272
273
274
275
276
277
278
279
280






281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297

298
299
300
301
302
303
304
305
306

307
308
309
310
311
312




























































313
314
315
316
317
318
319
static void		ArrangeGrid(ClientData clientData);
static int		CheckSlotData(Gridder *masterPtr, int slot,
			    int slotType, int checkOnly);
static int		ConfigureSlaves(Tcl_Interp *interp, Tk_Window tkwin,
			    int objc, Tcl_Obj *const objv[]);
static void		DestroyGrid(void *memPtr);
static Gridder *	GetGrid(Tk_Window tkwin);




static int		GridAnchorCommand(Tk_Window tkwin, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const objv[]);
static int		GridBboxCommand(Tk_Window tkwin, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const objv[]);
static int		GridForgetRemoveCommand(Tk_Window tkwin,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		GridInfoCommand(Tk_Window tkwin, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const objv[]);
static int		GridLocationCommand(Tk_Window tkwin,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		GridPropagateCommand(Tk_Window tkwin,
			    Tcl_Interp *interp, int objc,






			    Tcl_Obj *const objv[]);
static int		GridRowColumnConfigureCommand(Tk_Window tkwin,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		GridSizeCommand(Tk_Window tkwin, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const objv[]);
static int		GridSlavesCommand(Tk_Window tkwin, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const objv[]);
static void		GridStructureProc(ClientData clientData,
			    XEvent *eventPtr);
static void		GridLostSlaveProc(ClientData clientData,
			    Tk_Window tkwin);
static void		GridReqProc(ClientData clientData, Tk_Window tkwin);
static void		InitMasterData(Gridder *masterPtr);
static Tcl_Obj *	NewPairObj(int, int);
static Tcl_Obj *	NewQuadObj(int, int, int, int);
static int		ResolveConstraints(Gridder *gridPtr, int rowOrColumn,

			    int maxOffset);
static void		SetGridSize(Gridder *gridPtr);
static int		SetSlaveColumn(Tcl_Interp *interp, Gridder *slavePtr,
			    int column, int numCols);
static int		SetSlaveRow(Tcl_Interp *interp, Gridder *slavePtr,
			    int row, int numRows);
static Tcl_Obj *	StickyToObj(int flags);
static int		StringToSticky(const char *string);
static void		Unlink(Gridder *gridPtr);


static const Tk_GeomMgr gridMgrType = {
    "grid",			/* name */
    GridReqProc,		/* requestProc */
    GridLostSlaveProc,		/* lostSlaveProc */
};





























































/*
 *----------------------------------------------------------------------
 *
 * Tk_GridCmd --
 *
 *	This procedure is invoked to process the "grid" Tcl command. See the







>
>
>
>














>
>
>
>
>
>
















|
>
|








>






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
static void		ArrangeGrid(ClientData clientData);
static int		CheckSlotData(Gridder *masterPtr, int slot,
			    int slotType, int checkOnly);
static int		ConfigureSlaves(Tcl_Interp *interp, Tk_Window tkwin,
			    int objc, Tcl_Obj *const objv[]);
static void		DestroyGrid(void *memPtr);
static Gridder *	GetGrid(Tk_Window tkwin);
static int	        GridXYScrollcommandCommand(Tk_Window tkwin,
			    Tcl_Interp *interp, int y, int objc,
			    Tcl_Obj *CONST objv[]);
static void		GridUpdateScrollbars(Gridder *masterPtr);
static int		GridAnchorCommand(Tk_Window tkwin, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const objv[]);
static int		GridBboxCommand(Tk_Window tkwin, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const objv[]);
static int		GridForgetRemoveCommand(Tk_Window tkwin,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		GridInfoCommand(Tk_Window tkwin, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const objv[]);
static int		GridLocationCommand(Tk_Window tkwin,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		GridPropagateCommand(Tk_Window tkwin,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		GridColumnpeerCommand(Tk_Window tkwin,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		GridRowpeerCommand(Tk_Window tkwin,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		GridRowColumnConfigureCommand(Tk_Window tkwin,
			    Tcl_Interp *interp, int objc,
			    Tcl_Obj *const objv[]);
static int		GridSizeCommand(Tk_Window tkwin, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const objv[]);
static int		GridSlavesCommand(Tk_Window tkwin, Tcl_Interp *interp,
			    int objc, Tcl_Obj *const objv[]);
static void		GridStructureProc(ClientData clientData,
			    XEvent *eventPtr);
static void		GridLostSlaveProc(ClientData clientData,
			    Tk_Window tkwin);
static void		GridReqProc(ClientData clientData, Tk_Window tkwin);
static void		InitMasterData(Gridder *masterPtr);
static Tcl_Obj *	NewPairObj(int, int);
static Tcl_Obj *	NewQuadObj(int, int, int, int);
static int		ResolveConstraints(Gridder *gridPtr, int rowOrColumn);
static Tcl_Obj *	ScrollFractions(int screen1, int screen2, int object1,
			    int object2);
static void		SetGridSize(Gridder *gridPtr);
static int		SetSlaveColumn(Tcl_Interp *interp, Gridder *slavePtr,
			    int column, int numCols);
static int		SetSlaveRow(Tcl_Interp *interp, Gridder *slavePtr,
			    int row, int numRows);
static Tcl_Obj *	StickyToObj(int flags);
static int		StringToSticky(const char *string);
static void		Unlink(Gridder *gridPtr);
static void		UnlinkPeer(Gridder *masterPtr, int rowOrColumn);

static const Tk_GeomMgr gridMgrType = {
    "grid",			/* name */
    GridReqProc,		/* requestProc */
    GridLostSlaveProc,		/* lostSlaveProc */
};

static CONST char **
TkGetStringsFromObjs(argc, objv)
    int argc;
    Tcl_Obj *CONST objv[];
{
    register int i;
    CONST char **argv;
    if (argc <= 0) {
	return NULL;
    }
    argv = (CONST char **) ckalloc((argc+1) * sizeof(char *));
    for (i = 0; i < argc; i++) {
	argv[i]=Tcl_GetStringFromObj(objv[i], (int *) NULL);
    }
    argv[argc] = 0;
    return argv;
}

static void
GridSetOrigin(masterPtr, xOrigin, yOrigin)
    Gridder *masterPtr;		/* Information about master. */
    int xOrigin;		/* New X origin. */
    int yOrigin;		/* New Y origin. */
{
    GridMaster *gridPtr = masterPtr->masterDataPtr;
    int xUsed, yUsed, viewX, viewY;

    if ((xOrigin == gridPtr->xOrigin) && (yOrigin == gridPtr->yOrigin)) {
	return;
    }

    gridPtr->xOrigin = xOrigin;
    gridPtr->yOrigin = yOrigin;

    /* Check range */
    xUsed   = gridPtr->xUsed;
    yUsed   = gridPtr->yUsed;
    viewX = Tk_Width(masterPtr->tkwin) -
	    Tk_InternalBorderLeft(masterPtr->tkwin) -
	    Tk_InternalBorderRight(masterPtr->tkwin);
    viewY = Tk_Height(masterPtr->tkwin) -
	    Tk_InternalBorderTop(masterPtr->tkwin) -
	    Tk_InternalBorderBottom(masterPtr->tkwin);
    if (xOrigin < 0) {
	gridPtr->xOrigin = 0;
    } else if (xOrigin > (xUsed - viewX)) {
	gridPtr->xOrigin = (xUsed - viewX);
    }
    if (yOrigin < 0) {
	gridPtr->yOrigin = 0;
    } else if (yOrigin > (yUsed - viewY)) {
	gridPtr->yOrigin = (yUsed - viewY);
    }

    if (!(masterPtr->flags & REQUESTED_RELAYOUT)) {
	masterPtr->flags |= REQUESTED_RELAYOUT;
	Tcl_DoWhenIdle(ArrangeGrid, (ClientData) masterPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_GridCmd --
 *
 *	This procedure is invoked to process the "grid" Tcl command. See the
333
334
335
336
337
338
339

340
341

342
343
344

345
346

347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369





































































































370
371
372
373
374
375
376
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = clientData;
    static const char *const optionStrings[] = {

	"anchor", "bbox", "columnconfigure", "configure",
	"forget", "info", "location", "propagate", "remove",

	"rowconfigure", "size",	"slaves", NULL
    };
    enum options {

	GRID_ANCHOR, GRID_BBOX, GRID_COLUMNCONFIGURE, GRID_CONFIGURE,
	GRID_FORGET, GRID_INFO, GRID_LOCATION, GRID_PROPAGATE, GRID_REMOVE,

	GRID_ROWCONFIGURE, GRID_SIZE, GRID_SLAVES
    };
    int index;

    if (objc >= 2) {
	const char *argv1 = Tcl_GetString(objv[1]);

	if ((argv1[0] == '.') || (argv1[0] == REL_SKIP) ||
    		(argv1[0] == REL_VERT)) {
	    return ConfigureSlaves(interp, tkwin, objc-1, objv+1);
	}
    }
    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 1, objv, "option arg ?arg ...?");
	return TCL_ERROR;
    }

    if (Tcl_GetIndexFromObjStruct(interp, objv[1], optionStrings,
	    sizeof(char *), "option", 0, &index) != TCL_OK) {
	return TCL_ERROR;
    }

    switch ((enum options) index) {





































































































    case GRID_ANCHOR:
	return GridAnchorCommand(tkwin, interp, objc, objv);
    case GRID_BBOX:
	return GridBboxCommand(tkwin, interp, objc, objv);
    case GRID_CONFIGURE:
	return ConfigureSlaves(interp, tkwin, objc-2, objv+2);
    case GRID_FORGET:







>


>



>


>







|















>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
    ClientData clientData,	/* Main window associated with interpreter. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *const objv[])	/* Argument objects. */
{
    Tk_Window tkwin = clientData;
    static const char *const optionStrings[] = {
	"xscrollcommand", "yscrollcommand", "xview", "yview",
	"anchor", "bbox", "columnconfigure", "configure",
	"forget", "info", "location", "propagate", "remove",
	"columnpeer", "rowpeer",
	"rowconfigure", "size",	"slaves", NULL
    };
    enum options {
	GRID_XSCROLLCOMMAND, GRID_YSCROLLCOMMAND, GRID_XVIEW, GRID_YVIEW,
	GRID_ANCHOR, GRID_BBOX, GRID_COLUMNCONFIGURE, GRID_CONFIGURE,
	GRID_FORGET, GRID_INFO, GRID_LOCATION, GRID_PROPAGATE, GRID_REMOVE,
	GRID_COLUMNPEER, GRID_ROWPEER,
	GRID_ROWCONFIGURE, GRID_SIZE, GRID_SLAVES
    };
    int index;

    if (objc >= 2) {
	const char *argv1 = Tcl_GetString(objv[1]);

	if ((argv1[0] == '.') || (argv1[0] == REL_SKIP && argv1[1] == 0) ||
    		(argv1[0] == REL_VERT)) {
	    return ConfigureSlaves(interp, tkwin, objc-1, objv+1);
	}
    }
    if (objc < 3) {
	Tcl_WrongNumArgs(interp, 1, objv, "option arg ?arg ...?");
	return TCL_ERROR;
    }

    if (Tcl_GetIndexFromObjStruct(interp, objv[1], optionStrings,
	    sizeof(char *), "option", 0, &index) != TCL_OK) {
	return TCL_ERROR;
    }

    switch ((enum options) index) {
      case GRID_XSCROLLCOMMAND:
        return GridXYScrollcommandCommand(tkwin, interp, 0, objc, objv);
      case GRID_YSCROLLCOMMAND:
        return GridXYScrollcommandCommand(tkwin, interp, 1, objc, objv);
      case GRID_XVIEW: {
	int count, type;
	int newX = 0;		/* Initialization needed only to prevent
				 * gcc warnings. */
	double fraction;
	int viewX;
	Tk_Window master;
	Gridder *masterPtr;
	GridMaster *gridPtr;
	if (TkGetWindowFromObj(interp, tkwin, objv[2], &master) != TCL_OK) {
	    return TCL_ERROR;
	}
	masterPtr = GetGrid(master);
	gridPtr = masterPtr->masterDataPtr;
	viewX = Tk_Width(masterPtr->tkwin) -
		Tk_InternalBorderLeft(masterPtr->tkwin) -
		Tk_InternalBorderRight(masterPtr->tkwin);
	if (objc < 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "window ?scroll?");
	    return TCL_ERROR;
	}
	if (objc == 3) {
	    Tcl_SetObjResult(interp, ScrollFractions(
		    gridPtr->xOrigin, gridPtr->xOrigin + viewX,
		    0, gridPtr->xUsed));
	} else {
	    CONST char **args = TkGetStringsFromObjs(objc-1, &objv[1]);
	    type = Tk_GetScrollInfo(interp, objc-1, args, &fraction, &count);
	    if (args) ckfree((char *) args);
	    switch (type) {
		case TK_SCROLL_ERROR:
		    return TCL_ERROR;
		case TK_SCROLL_MOVETO:
		    newX = (int) ((fraction * gridPtr->xUsed) + 0.5);
		    break;
		case TK_SCROLL_PAGES:
		    newX = (int) (gridPtr->xOrigin + count * .9 * viewX);
		    break;
		case TK_SCROLL_UNITS:
		    newX = (int) (gridPtr->xOrigin + count * .1 * viewX);
		    break;
	    }
	    GridSetOrigin(masterPtr, newX, gridPtr->yOrigin);
	}
	return TCL_OK;
      }
      case GRID_YVIEW: {
	int count, type;
	int newY = 0;		/* Initialization needed only to prevent
				 * gcc warnings. */
	double fraction;
	int viewY;
	Tk_Window master;
	Gridder *masterPtr;
	GridMaster *gridPtr;
	if (TkGetWindowFromObj(interp, tkwin, objv[2], &master) != TCL_OK) {
	    return TCL_ERROR;
	}
	masterPtr = GetGrid(master);
	gridPtr = masterPtr->masterDataPtr;
	viewY = Tk_Height(masterPtr->tkwin) -
		Tk_InternalBorderTop(masterPtr->tkwin) -
		Tk_InternalBorderBottom(masterPtr->tkwin);
	if (objc < 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "window ?scroll?");
	    return TCL_ERROR;
	}
	if (objc == 3) {
	    Tcl_SetObjResult(interp, ScrollFractions(
		    gridPtr->yOrigin, gridPtr->yOrigin + viewY,
		    0, gridPtr->yUsed));
	} else {
	    CONST char **args = TkGetStringsFromObjs(objc-1, &objv[1]);
	    type = Tk_GetScrollInfo(interp, objc-1, args, &fraction, &count);
	    if (args) ckfree((char *) args);
	    switch (type) {
		case TK_SCROLL_ERROR:
		    return TCL_ERROR;
		case TK_SCROLL_MOVETO:
		    newY = (int) ((fraction * gridPtr->yUsed) + 0.5);
		    break;
		case TK_SCROLL_PAGES:
		    newY = (int) (gridPtr->yOrigin + count * .9 * viewY);
		    break;
		case TK_SCROLL_UNITS:
		    newY = (int) (gridPtr->yOrigin + count * .1 * viewY);
		    break;
	    }
	    GridSetOrigin(masterPtr, gridPtr->xOrigin, newY);
	}
	GridUpdateScrollbars(masterPtr);
	return TCL_OK;
      }
    case GRID_COLUMNPEER:
        return GridColumnpeerCommand(tkwin, interp, objc, objv);
    case GRID_ROWPEER:
        return GridRowpeerCommand(tkwin, interp, objc, objv);
    case GRID_ANCHOR:
	return GridAnchorCommand(tkwin, interp, objc, objv);
    case GRID_BBOX:
	return GridBboxCommand(tkwin, interp, objc, objv);
    case GRID_CONFIGURE:
	return ConfigureSlaves(interp, tkwin, objc-2, objv+2);
    case GRID_FORGET:
402
403
404
405
406
407
408






































































































































































409
410
411
412
413
414
415
    }

    /* This should not happen */
    Tcl_SetObjResult(interp, Tcl_NewStringObj("internal error in grid", -1));
    Tcl_SetErrorCode(interp, "TK", "API_ABUSE", NULL);
    return TCL_ERROR;
}







































































































































































/*
 *----------------------------------------------------------------------
 *
 * GridAnchorCommand --
 *
 *	Implementation of the [grid anchor] subcommand. See the user







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
    }

    /* This should not happen */
    Tcl_SetObjResult(interp, Tcl_NewStringObj("internal error in grid", -1));
    Tcl_SetErrorCode(interp, "TK", "API_ABUSE", NULL);
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
 * ScrollFractions --
 *
 *	Given the range that's visible in the window and the "100%
 *	range" for what's in the canvas, return a list of two
 *	doubles representing the scroll fractions.  This procedure
 *	is used for both x and y scrolling.
 *
 * Results:
 *	The memory pointed to by string is modified to hold
 *	two real numbers containing the scroll fractions (between
 *	0 and 1) corresponding to the other arguments.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static Tcl_Obj *
ScrollFractions(
    int screen1,		/* Lowest coordinate visible in the window. */
    int screen2,		/* Highest coordinate visible in the window. */
    int object1,		/* Lowest coordinate in the object. */
    int object2)		/* Highest coordinate in the object. */
{
    double range, f1, f2;
    char buffer[2*TCL_DOUBLE_SPACE+2];

    range = object2 - object1;
    if (range <= 0) {
	f1 = 0;
	f2 = 1.0;
    } else {
	f1 = (screen1 - object1)/range;
	if (f1 < 0) {
	    f1 = 0.0;
	}
	f2 = (screen2 - object1)/range;
	if (f2 > 1.0) {
	    f2 = 1.0;
	}
	if (f2 < f1) {
	    f2 = f1;
	}
    }
    sprintf(buffer, "%g %g", f1, f2);
    return Tcl_NewStringObj(buffer, -1);
}

static void
GridUpdateScrollbars(masterPtr)
    Gridder *masterPtr;		/* Information about grid. */
{
    int result;
    int xOrigin, yOrigin, xUsed, yUsed, viewX, viewY;
    char *xScrollCmd, *yScrollCmd;
    GridMaster *gridPtr = masterPtr->masterDataPtr;	
    Tcl_Interp *interp = gridPtr->interp;

    /*
     * Save all the relevant values from the canvasPtr, because it might be
     * deleted as part of either of the two calls to Tcl_VarEval below.
     */
    
    Tcl_Preserve((ClientData) interp);
    xScrollCmd = gridPtr->xScrollCmd;
    if (xScrollCmd != (char *) NULL) {
        Tcl_Preserve((ClientData) xScrollCmd);
    }
    yScrollCmd = gridPtr->yScrollCmd;
    if (yScrollCmd != (char *) NULL) {
        Tcl_Preserve((ClientData) yScrollCmd);
    }
    xOrigin = gridPtr->xOrigin;
    yOrigin = gridPtr->yOrigin;
    xUsed   = gridPtr->xUsed;
    yUsed   = gridPtr->yUsed;
    viewX = Tk_Width(masterPtr->tkwin) -
	    Tk_InternalBorderLeft(masterPtr->tkwin) -
	    Tk_InternalBorderRight(masterPtr->tkwin);
    viewY = Tk_Height(masterPtr->tkwin) -
	    Tk_InternalBorderTop(masterPtr->tkwin) -
	    Tk_InternalBorderBottom(masterPtr->tkwin);

    if (xScrollCmd != NULL) {
	Tcl_Obj *fractions = ScrollFractions(
		    gridPtr->xOrigin, gridPtr->xOrigin + viewX,
		    0, gridPtr->xUsed);
	result = Tcl_VarEval(interp, xScrollCmd, " ", 
		Tcl_GetString(fractions), (char *) NULL);
	Tcl_DecrRefCount(fractions);
	if (result != TCL_OK) {
	    Tcl_BackgroundError(interp);
	}
	Tcl_ResetResult(interp);
        Tcl_Release((ClientData) xScrollCmd);
    }

    if (yScrollCmd != NULL) {
	Tcl_Obj *fractions = ScrollFractions(
		    gridPtr->yOrigin, gridPtr->yOrigin + viewY,
		    0, gridPtr->yUsed);
	result = Tcl_VarEval(interp, yScrollCmd, " ", 
		Tcl_GetString(fractions), (char *) NULL);
	Tcl_DecrRefCount(fractions);
	if (result != TCL_OK) {
	    Tcl_BackgroundError(interp);
	}
	Tcl_ResetResult(interp);
        Tcl_Release((ClientData) yScrollCmd);
    }
    Tcl_Release((ClientData) interp);
}

static int
GridXYScrollcommandCommand(tkwin, interp, y, objc, objv)
    Tk_Window tkwin;		/* Main window of the application. */
    Tcl_Interp *interp;		/* Current interpreter. */
    int y;                      /* True if y, false if x. */
    int objc;			/* Number of arguments. */
    Tcl_Obj *CONST objv[];	/* Argument objects. */
{
    Tk_Window master;
    Gridder *masterPtr;
    GridMaster *gridPtr;
    int length;
    char *value, **cmdPtr;

    if (objc > 4) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?command?");
	return TCL_ERROR;
    }

    if (TkGetWindowFromObj(interp, tkwin, objv[2], &master) != TCL_OK) {
	return TCL_ERROR;
    }
    masterPtr = GetGrid(master);

    if (objc == 3) {
        gridPtr = masterPtr->masterDataPtr;
	cmdPtr = y ? &gridPtr->yScrollCmd : &gridPtr->xScrollCmd;
        Tcl_SetResult(interp, *cmdPtr == NULL ? "" : *cmdPtr, TCL_VOLATILE);
        return TCL_OK;
    }

    InitMasterData(masterPtr);
    gridPtr = masterPtr->masterDataPtr;
    gridPtr->interp = interp;
    cmdPtr = y ? &gridPtr->yScrollCmd : &gridPtr->xScrollCmd;

    if (*cmdPtr != NULL) {
	ckfree(*cmdPtr);
    }
    value = Tcl_GetStringFromObj(objv[3], &length);
    if (length == 0) {
	*cmdPtr = NULL;
    } else {
	*cmdPtr = ckalloc((unsigned) (length + 1));
	strcpy(*cmdPtr, value);
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * GridAnchorCommand --
 *
 *	Implementation of the [grid anchor] subcommand. See the user
472
473
474
475
476
477
478































































































































































































479
480
481
482
483
484
485
	if (!(masterPtr->flags & REQUESTED_RELAYOUT)) {
	    masterPtr->flags |= REQUESTED_RELAYOUT;
	    Tcl_DoWhenIdle(ArrangeGrid, masterPtr);
	}
    }
    return TCL_OK;
}
































































































































































































/*
 *----------------------------------------------------------------------
 *
 * GridBboxCommand --
 *
 *	Implementation of the [grid bbox] subcommand.







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
	if (!(masterPtr->flags & REQUESTED_RELAYOUT)) {
	    masterPtr->flags |= REQUESTED_RELAYOUT;
	    Tcl_DoWhenIdle(ArrangeGrid, masterPtr);
	}
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * GridColumnpeerCommand --
 *
 *	Implementation of the [grid columnpeer] subcommand. See the user
 *	documentation for details on what it does.
 *
 * Results:
 *	Standard Tcl result.
 *
 * Side effects:
 *	May recompute grid geometry.
 *
 *----------------------------------------------------------------------
 */

static int
GridColumnpeerCommand(
    Tk_Window tkwin,		/* Main window of the application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *CONST objv[])	/* Argument objects. */
{
    Tk_Window master, newpeer;
    Gridder *masterPtr, *peerPtr, *newpeerPtr;
    GridMaster *gridPtr;

    if (objc > 4) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?peer?");
	return TCL_ERROR;
    }

    if (TkGetWindowFromObj(interp, tkwin, objv[2], &master) != TCL_OK) {
	return TCL_ERROR;
    }
    masterPtr = GetGrid(master);
    InitMasterData(masterPtr);

    if (objc == 3) {
	Tcl_Obj *resultPtr = Tcl_NewListObj(0, NULL);
	peerPtr = masterPtr->masterDataPtr->nextColPeerPtr;
	while (peerPtr != masterPtr) {
	    /* Add this master to result */
	    Tcl_ListObjAppendElement(interp, resultPtr, Tcl_NewStringObj(Tk_PathName(peerPtr->tkwin), -1));
	    peerPtr = peerPtr->masterDataPtr->nextColPeerPtr;
	}
	Tcl_SetObjResult(interp, resultPtr);
	return TCL_OK;
    }

    gridPtr = masterPtr->masterDataPtr;

    if (TkGetWindowFromObj(interp, tkwin, objv[3], &newpeer) != TCL_OK) {
	return TCL_ERROR;
    }
    newpeerPtr = GetGrid(newpeer);
    InitMasterData(newpeerPtr);

    /*
     * Check peer list if it is already present.
     */

    peerPtr =  masterPtr->masterDataPtr->nextColPeerPtr;
    while (peerPtr != masterPtr) {
	if (peerPtr == newpeerPtr) {
	    return TCL_OK;
	}
	InitMasterData(peerPtr);
	peerPtr = peerPtr->masterDataPtr->nextColPeerPtr;
    }

    /*
     * Add peer to list.
     */
    newpeerPtr->masterDataPtr->nextColPeerPtr =
	    masterPtr->masterDataPtr->nextColPeerPtr;
    masterPtr->masterDataPtr->nextColPeerPtr = newpeerPtr;


    /*
     * Request relayout of all peers.
     */

    peerPtr =  masterPtr->masterDataPtr->nextColPeerPtr;
    while (peerPtr != NULL && peerPtr != masterPtr) {
	if (!(peerPtr->flags & REQUESTED_RELAYOUT)) {
	    peerPtr->flags |= REQUESTED_RELAYOUT;
	    Tcl_DoWhenIdle(ArrangeGrid, (ClientData) peerPtr);
	}
	gridPtr = peerPtr->masterDataPtr;
	peerPtr = gridPtr->nextColPeerPtr;
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * GridRowpeerCommand --
 *
 *	Implementation of the [grid rowpeer] subcommand. See the user
 *	documentation for details on what it does.
 *
 * Results:
 *	Standard Tcl result.
 *
 * Side effects:
 *	May recompute grid geometry.
 *
 *----------------------------------------------------------------------
 */

static int
GridRowpeerCommand(
    Tk_Window tkwin,		/* Main window of the application. */
    Tcl_Interp *interp,		/* Current interpreter. */
    int objc,			/* Number of arguments. */
    Tcl_Obj *CONST objv[])	/* Argument objects. */
{
    Tk_Window master, newpeer;
    Gridder *masterPtr, *peerPtr, *newpeerPtr;
    GridMaster *gridPtr;

    if (objc > 4) {
	Tcl_WrongNumArgs(interp, 2, objv, "window ?peer?");
	return TCL_ERROR;
    }

    if (TkGetWindowFromObj(interp, tkwin, objv[2], &master) != TCL_OK) {
	return TCL_ERROR;
    }
    masterPtr = GetGrid(master);
    InitMasterData(masterPtr);

    if (objc == 3) {
	Tcl_Obj *resultPtr = Tcl_NewListObj(0, NULL);
	peerPtr = masterPtr->masterDataPtr->nextRowPeerPtr;
	while (peerPtr != masterPtr) {
	    /* Add this master to result */
	    Tcl_ListObjAppendElement(interp, resultPtr, Tcl_NewStringObj(Tk_PathName(peerPtr->tkwin), -1));
	    peerPtr = peerPtr->masterDataPtr->nextRowPeerPtr;
	}
	Tcl_SetObjResult(interp, resultPtr);
	return TCL_OK;
    }

    gridPtr = masterPtr->masterDataPtr;

    if (TkGetWindowFromObj(interp, tkwin, objv[3], &newpeer) != TCL_OK) {
	return TCL_ERROR;
    }
    newpeerPtr = GetGrid(newpeer);
    InitMasterData(newpeerPtr);

    /*
     * Check peer list if it is already present.
     */

    peerPtr =  masterPtr->masterDataPtr->nextRowPeerPtr;
    while (peerPtr != masterPtr) {
	if (peerPtr == newpeerPtr) {
	    return TCL_OK;
	}
	InitMasterData(peerPtr);
	peerPtr = peerPtr->masterDataPtr->nextRowPeerPtr;
    }

    /*
     * Add peer to list.
     */
    newpeerPtr->masterDataPtr->nextRowPeerPtr =
	    masterPtr->masterDataPtr->nextRowPeerPtr;
    masterPtr->masterDataPtr->nextRowPeerPtr = newpeerPtr;

    /*
     * Request relayout of all peers.
     */

    peerPtr =  masterPtr->masterDataPtr->nextRowPeerPtr;
    while (peerPtr != NULL && peerPtr != masterPtr) {
	if (!(peerPtr->flags & REQUESTED_RELAYOUT)) {
	    peerPtr->flags |= REQUESTED_RELAYOUT;
	    Tcl_DoWhenIdle(ArrangeGrid, (ClientData) peerPtr);
	}
	gridPtr = peerPtr->masterDataPtr;
	peerPtr = gridPtr->nextRowPeerPtr;
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * GridBboxCommand --
 *
 *	Implementation of the [grid bbox] subcommand.
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
    Tcl_Preserve(masterPtr);

    /*
     * Call the constraint engine to fill in the row and column offsets.
     */

    SetGridSize(masterPtr);
    width = ResolveConstraints(masterPtr, COLUMN, 0);
    height = ResolveConstraints(masterPtr, ROW, 0);
    width += Tk_InternalBorderLeft(masterPtr->tkwin) +
	    Tk_InternalBorderRight(masterPtr->tkwin);
    height += Tk_InternalBorderTop(masterPtr->tkwin) +
	    Tk_InternalBorderBottom(masterPtr->tkwin);

    if (width < Tk_MinReqWidth(masterPtr->tkwin)) {
	width = Tk_MinReqWidth(masterPtr->tkwin);







|
|







2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
    Tcl_Preserve(masterPtr);

    /*
     * Call the constraint engine to fill in the row and column offsets.
     */

    SetGridSize(masterPtr);
    width = ResolveConstraints(masterPtr, COLUMN);
    height = ResolveConstraints(masterPtr, ROW);
    width += Tk_InternalBorderLeft(masterPtr->tkwin) +
	    Tk_InternalBorderRight(masterPtr->tkwin);
    height += Tk_InternalBorderTop(masterPtr->tkwin) +
	    Tk_InternalBorderBottom(masterPtr->tkwin);

    if (width < Tk_MinReqWidth(masterPtr->tkwin)) {
	width = Tk_MinReqWidth(masterPtr->tkwin);
1806
1807
1808
1809
1810
1811
1812




















1813
1814
1815
1816
1817
1818
1819
	    Tk_InternalBorderBottom(masterPtr->tkwin);
    usedX = AdjustOffsets(realWidth,
	    MAX(slotPtr->columnEnd, slotPtr->columnMax), slotPtr->columnPtr);
    usedY = AdjustOffsets(realHeight, MAX(slotPtr->rowEnd, slotPtr->rowMax),
	    slotPtr->rowPtr);
    TkComputeAnchor(masterPtr->masterDataPtr->anchor, masterPtr->tkwin,
	    0, 0, usedX, usedY, &slotPtr->startX, &slotPtr->startY);





















    /*
     * Now adjust the actual size of the slave to its cavity by computing the
     * cavity size, and adjusting the widget according to its stickyness.
     */

    for (slavePtr = masterPtr->slavePtr; slavePtr != NULL && !abort;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
	    Tk_InternalBorderBottom(masterPtr->tkwin);
    usedX = AdjustOffsets(realWidth,
	    MAX(slotPtr->columnEnd, slotPtr->columnMax), slotPtr->columnPtr);
    usedY = AdjustOffsets(realHeight, MAX(slotPtr->rowEnd, slotPtr->rowMax),
	    slotPtr->rowPtr);
    TkComputeAnchor(masterPtr->masterDataPtr->anchor, masterPtr->tkwin,
	    0, 0, usedX, usedY, &slotPtr->startX, &slotPtr->startY);

    /* Scrolling */
    /* FIXA: Does anchor or scroll takes priority if scrollcmd is not set? */
//    if ((slotPtr->xScrollCmd != NULL) || (slotPtr->yScrollCmd != NULL)) {
	if (usedX > realWidth) {
	    slotPtr->startX = -slotPtr->xOrigin;
	    slotPtr->xUsed  = usedX;
	} else {
	    slotPtr->xOrigin = 0;
	    slotPtr->xUsed   = realWidth;
	}
	if (usedY > realHeight) {
	    slotPtr->startY = -slotPtr->yOrigin;
	    slotPtr->yUsed  = usedY;
	} else {
	    slotPtr->yOrigin = 0;
	    slotPtr->yUsed   = realHeight;
	}
	GridUpdateScrollbars(masterPtr);
//    }

    /*
     * Now adjust the actual size of the slave to its cavity by computing the
     * cavity size, and adjusting the widget according to its stickyness.
     */

    for (slavePtr = masterPtr->slavePtr; slavePtr != NULL && !abort;
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
 *
 *----------------------------------------------------------------------
 */

static int
ResolveConstraints(
    Gridder *masterPtr,		/* The geometry master for this grid. */
    int slotType,		/* Either ROW or COLUMN. */
    int maxOffset)		/* The actual maximum size of this layout in
				 * pixels, or 0 (not currently used). */
{
    register SlotInfo *slotPtr;	/* Pointer to row/col constraints. */
    register Gridder *slavePtr;	/* List of slave windows in this grid. */
    int constraintCount;	/* Count of rows or columns that have
				 * constraints. */
    int slotCount;		/* Last occupied row or column. */
    int gridCount;		/* The larger of slotCount and







|
<
<







2460
2461
2462
2463
2464
2465
2466
2467


2468
2469
2470
2471
2472
2473
2474
 *
 *----------------------------------------------------------------------
 */

static int
ResolveConstraints(
    Gridder *masterPtr,		/* The geometry master for this grid. */
    int slotType)		/* Either ROW or COLUMN. */


{
    register SlotInfo *slotPtr;	/* Pointer to row/col constraints. */
    register Gridder *slavePtr;	/* List of slave windows in this grid. */
    int constraintCount;	/* Count of rows or columns that have
				 * constraints. */
    int slotCount;		/* Last occupied row or column. */
    int gridCount;		/* The larger of slotCount and
1928
1929
1930
1931
1932
1933
1934

1935
1936
1937
1938
1939
1940
1941
    UniformGroup *uniformGroupPtr;
				/* Uniform groups data. */
    int uniformGroups;		/* Number of currently used uniform groups. */
    int uniformGroupsAlloced;	/* Size of allocated space for uniform
				 * groups. */
    int weight, minSize;
    int prevGrow, accWeight, grow;


    /*
     * For typical sized tables, we'll use stack space for the layout data to
     * avoid the overhead of a malloc and free for every layout.
     */

    GridLayout layoutData[TYPICAL_SIZE + 1];







>







2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
    UniformGroup *uniformGroupPtr;
				/* Uniform groups data. */
    int uniformGroups;		/* Number of currently used uniform groups. */
    int uniformGroupsAlloced;	/* Size of allocated space for uniform
				 * groups. */
    int weight, minSize;
    int prevGrow, accWeight, grow;
    Gridder *peerPtr;

    /*
     * For typical sized tables, we'll use stack space for the layout data to
     * avoid the overhead of a malloc and free for every layout.
     */

    GridLayout layoutData[TYPICAL_SIZE + 1];
2003
2004
2005
2006
2007
2008
2009


2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028

2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047

2048
2049

2050
2051
2052
2053
2054
2055
2056
     * their size exceeds the the sizes of the slots they span.
     *
     * Bin all slaves whose spans are > 1 by their right edges. This allows
     * the computation on minimum and maximum possible layout sizes at each
     * slot boundary, without the need to re-sort the slaves.
     */



    switch (slotType) {
    case COLUMN:
	for (slavePtr = masterPtr->slavePtr; slavePtr != NULL;
		slavePtr = slavePtr->nextPtr) {
	    int rightEdge = slavePtr->column + slavePtr->numCols - 1;

	    slavePtr->size = Tk_ReqWidth(slavePtr->tkwin) + slavePtr->padX
		    + slavePtr->iPadX + slavePtr->doubleBw;
	    if (slavePtr->numCols > 1) {
		slavePtr->binNextPtr = layoutPtr[rightEdge].binNextPtr;
		layoutPtr[rightEdge].binNextPtr = slavePtr;
	    } else if (rightEdge >= 0) {
		int size = slavePtr->size + layoutPtr[rightEdge].pad;

		if (size > layoutPtr[rightEdge].minSize) {
		    layoutPtr[rightEdge].minSize = size;
		}
	    }
	}

	break;
    case ROW:
	for (slavePtr = masterPtr->slavePtr; slavePtr != NULL;
		slavePtr = slavePtr->nextPtr) {
	    int rightEdge = slavePtr->row + slavePtr->numRows - 1;

	    slavePtr->size = Tk_ReqHeight(slavePtr->tkwin) + slavePtr->padY
		    + slavePtr->iPadY + slavePtr->doubleBw;
	    if (slavePtr->numRows > 1) {
		slavePtr->binNextPtr = layoutPtr[rightEdge].binNextPtr;
		layoutPtr[rightEdge].binNextPtr = slavePtr;
	    } else if (rightEdge >= 0) {
		int size = slavePtr->size + layoutPtr[rightEdge].pad;

		if (size > layoutPtr[rightEdge].minSize) {
		    layoutPtr[rightEdge].minSize = size;
		}
	    }
	}

	break;
    }


    /*
     * Step 2b.
     * Consider demands on uniform sizes.
     */

    uniformGroupPtr = uniformPre;







>
>
|
|
|
|
|

|
|
|
|
|
|
|

|
|
|
|
|
>
|
|
|
|
|

|
|
|
|
|
|
|

|
|
|
|
|
>
|
|
>







2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
     * their size exceeds the the sizes of the slots they span.
     *
     * Bin all slaves whose spans are > 1 by their right edges. This allows
     * the computation on minimum and maximum possible layout sizes at each
     * slot boundary, without the need to re-sort the slaves.
     */

    peerPtr = masterPtr;
    do {
	switch (slotType) {
	case COLUMN:
	    for (slavePtr = peerPtr->slavePtr; slavePtr != NULL;
		 slavePtr = slavePtr->nextPtr) {
		int rightEdge = slavePtr->column + slavePtr->numCols - 1;

		slavePtr->size = Tk_ReqWidth(slavePtr->tkwin) + slavePtr->padX
			+ slavePtr->iPadX + slavePtr->doubleBw;
		if (slavePtr->numCols > 1) {
		    slavePtr->binNextPtr = layoutPtr[rightEdge].binNextPtr;
		    layoutPtr[rightEdge].binNextPtr = slavePtr;
	        } else if (rightEdge >= 0) {
		    int size = slavePtr->size + layoutPtr[rightEdge].pad;

		    if (size > layoutPtr[rightEdge].minSize) {
			layoutPtr[rightEdge].minSize = size;
		    }
		}
	    }
	    peerPtr = peerPtr->masterDataPtr->nextColPeerPtr;
	    break;
	case ROW:
	    for (slavePtr = peerPtr->slavePtr; slavePtr != NULL;
		 slavePtr = slavePtr->nextPtr) {
		int rightEdge = slavePtr->row + slavePtr->numRows - 1;

		slavePtr->size = Tk_ReqHeight(slavePtr->tkwin) + slavePtr->padY
			+ slavePtr->iPadY + slavePtr->doubleBw;
		if (slavePtr->numRows > 1) {
		    slavePtr->binNextPtr = layoutPtr[rightEdge].binNextPtr;
		    layoutPtr[rightEdge].binNextPtr = slavePtr;
	        } else if (rightEdge >= 0) {
		    int size = slavePtr->size + layoutPtr[rightEdge].pad;

		    if (size > layoutPtr[rightEdge].minSize) {
			layoutPtr[rightEdge].minSize = size;
		    }
		}
	    }
	    peerPtr = peerPtr->masterDataPtr->nextRowPeerPtr;
	    break;
	}
    } while (peerPtr != masterPtr);

    /*
     * Step 2b.
     * Consider demands on uniform sizes.
     */

    uniformGroupPtr = uniformPre;
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
	    }
	}
	offset = layoutPtr[slot].minOffset;
    }

    /*
     * At this point, we know the minimum required size of the entire layout.
     * It might be prudent to stop here if our "master" will resize itself to
     * this size.
     */

    requiredSize = offset;
    if (maxOffset > offset) {
	offset=maxOffset;
    }

    /*
     * Step 4.
     * Determine the minimum slot offsets going from right to left, bounding
     * the pixel range of each slot boundary. Pre-fill all of the right
     * offsets with the actual size of the table; they will be reduced as
     * required.







<
<



<
<
<







2714
2715
2716
2717
2718
2719
2720


2721
2722
2723



2724
2725
2726
2727
2728
2729
2730
	    }
	}
	offset = layoutPtr[slot].minOffset;
    }

    /*
     * At this point, we know the minimum required size of the entire layout.


     */

    requiredSize = offset;




    /*
     * Step 4.
     * Determine the minimum slot offsets going from right to left, bounding
     * the pixel range of each slot boundary. Pre-fill all of the right
     * offsets with the actual size of the table; they will be reduced as
     * required.
2492
2493
2494
2495
2496
2497
2498

2499
2500
2501
2502
2503
2504
2505

















2506
2507
2508
2509
2510
2511
2512
 */

static void
SetGridSize(
    Gridder *masterPtr)		/* The geometry master for this grid. */
{
    register Gridder *slavePtr;	/* Current slave window. */

    int maxX = 0, maxY = 0;

    for (slavePtr = masterPtr->slavePtr; slavePtr != NULL;
	    slavePtr = slavePtr->nextPtr) {
	maxX = MAX(maxX, slavePtr->numCols + slavePtr->column);
	maxY = MAX(maxY, slavePtr->numRows + slavePtr->row);
    }

















    masterPtr->masterDataPtr->columnEnd = maxX;
    masterPtr->masterDataPtr->rowEnd = maxY;
    CheckSlotData(masterPtr, maxX, COLUMN, CHECK_SPACE);
    CheckSlotData(masterPtr, maxY, ROW, CHECK_SPACE);
}

/*







>



|



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
 */

static void
SetGridSize(
    Gridder *masterPtr)		/* The geometry master for this grid. */
{
    register Gridder *slavePtr;	/* Current slave window. */
    Gridder *peerPtr;
    int maxX = 0, maxY = 0;

    for (slavePtr = masterPtr->slavePtr; slavePtr != NULL;
	 slavePtr = slavePtr->nextPtr) {
	maxX = MAX(maxX, slavePtr->numCols + slavePtr->column);
	maxY = MAX(maxY, slavePtr->numRows + slavePtr->row);
    }
    peerPtr = masterPtr->masterDataPtr->nextColPeerPtr;
    while (peerPtr != masterPtr) {
	for (slavePtr = peerPtr->slavePtr; slavePtr != NULL;
	     slavePtr = slavePtr->nextPtr) {
	    maxX = MAX(maxX, slavePtr->numCols + slavePtr->column);
	}
	peerPtr = peerPtr->masterDataPtr->nextColPeerPtr;
    }
    peerPtr = masterPtr->masterDataPtr->nextRowPeerPtr;
    while (peerPtr != masterPtr) {
	for (slavePtr = peerPtr->slavePtr; slavePtr != NULL;
	     slavePtr = slavePtr->nextPtr) {
	    maxY = MAX(maxY, slavePtr->numRows + slavePtr->row);
	}
	peerPtr = peerPtr->masterDataPtr->nextRowPeerPtr;
    }

    masterPtr->masterDataPtr->columnEnd = maxX;
    masterPtr->masterDataPtr->rowEnd = maxY;
    CheckSlotData(masterPtr, maxX, COLUMN, CHECK_SPACE);
    CheckSlotData(masterPtr, maxY, ROW, CHECK_SPACE);
}

/*
2712
2713
2714
2715
2716
2717
2718









2719
2720
2721
2722
2723
2724
2725
	gridPtr->rowEnd = 0;
	gridPtr->rowMax = 0;
	gridPtr->rowPtr = ckalloc(size);
	gridPtr->rowSpace = TYPICAL_SIZE;
	gridPtr->startX = 0;
	gridPtr->startY = 0;
	gridPtr->anchor = GRID_DEFAULT_ANCHOR;










	memset(gridPtr->columnPtr, 0, size);
	memset(gridPtr->rowPtr, 0, size);
    }
}

/*







>
>
>
>
>
>
>
>
>







3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
	gridPtr->rowEnd = 0;
	gridPtr->rowMax = 0;
	gridPtr->rowPtr = ckalloc(size);
	gridPtr->rowSpace = TYPICAL_SIZE;
	gridPtr->startX = 0;
	gridPtr->startY = 0;
	gridPtr->anchor = GRID_DEFAULT_ANCHOR;
	gridPtr->xScrollCmd = NULL;
	gridPtr->yScrollCmd = NULL;
	gridPtr->nextColPeerPtr = masterPtr;
	gridPtr->nextRowPeerPtr = masterPtr;
	gridPtr->xOrigin = 0;
	gridPtr->yOrigin = 0;
	gridPtr->xUsed = 0;
	gridPtr->yUsed = 0;
	gridPtr->interp = NULL;

	memset(gridPtr->columnPtr, 0, size);
	memset(gridPtr->rowPtr, 0, size);
    }
}

/*
2781
2782
2783
2784
2785
2786
2787















































2788
2789
2790
2791
2792
2793
2794

    if ((masterPtr->slavePtr == NULL) && (masterPtr->flags & ALLOCED_MASTER)) {
	TkFreeGeometryMaster(masterPtr->tkwin, "grid");
	masterPtr->flags &= ~ALLOCED_MASTER;
    }
}
















































/*
 *----------------------------------------------------------------------
 *
 * DestroyGrid --
 *
 *	This procedure is invoked by Tcl_EventuallyFree or Tcl_Release to
 *	clean up the internal structure of a grid at a safe time (when no-one







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432

    if ((masterPtr->slavePtr == NULL) && (masterPtr->flags & ALLOCED_MASTER)) {
	TkFreeGeometryMaster(masterPtr->tkwin, "grid");
	masterPtr->flags &= ~ALLOCED_MASTER;
    }
}

/* Unlink from peer list. */
static void
UnlinkPeer(Gridder *masterPtr, int rowOrColumn)
{
    Gridder *prevPeerPtr, *nextPeerPtr;
    Gridder *peerPtr;

    if (rowOrColumn == ROW) {
	nextPeerPtr = masterPtr->masterDataPtr->nextRowPeerPtr;
	masterPtr->masterDataPtr->nextRowPeerPtr = masterPtr;
    } else {
	nextPeerPtr = masterPtr->masterDataPtr->nextColPeerPtr;
	masterPtr->masterDataPtr->nextColPeerPtr = masterPtr;
    }
    if (nextPeerPtr == masterPtr) {
	/*
	 * No peers
	 */

	return;
    }

    /*
     * Loop through peers, request relayout and locate last among then.
     */

    peerPtr = nextPeerPtr;
    do {
	if (!(peerPtr->flags & REQUESTED_RELAYOUT)) {
	    peerPtr->flags |= REQUESTED_RELAYOUT;
	    Tcl_DoWhenIdle(ArrangeGrid, (ClientData) peerPtr);
	}
	prevPeerPtr = peerPtr;
	if (rowOrColumn == ROW) {
	    peerPtr = peerPtr->masterDataPtr->nextRowPeerPtr;
	} else {
	    peerPtr = peerPtr->masterDataPtr->nextColPeerPtr;
	}
    } while (peerPtr != masterPtr);

    if (rowOrColumn == ROW) {
	prevPeerPtr->masterDataPtr->nextRowPeerPtr = nextPeerPtr;
    } else {
	prevPeerPtr->masterDataPtr->nextColPeerPtr = nextPeerPtr;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * DestroyGrid --
 *
 *	This procedure is invoked by Tcl_EventuallyFree or Tcl_Release to
 *	clean up the internal structure of a grid at a safe time (when no-one
2868
2869
2870
2871
2872
2873
2874





2875
2876
2877
2878
2879
2880
2881
	    }
	}
    } else if (eventPtr->type == DestroyNotify) {
	register Gridder *gridPtr2, *nextPtr;

	if (gridPtr->masterPtr != NULL) {
	    Unlink(gridPtr);





	}
	for (gridPtr2 = gridPtr->slavePtr; gridPtr2 != NULL;
		gridPtr2 = nextPtr) {
	    Tk_UnmapWindow(gridPtr2->tkwin);
	    gridPtr2->masterPtr = NULL;
	    nextPtr = gridPtr2->nextPtr;
	    gridPtr2->nextPtr = NULL;







>
>
>
>
>







3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
	    }
	}
    } else if (eventPtr->type == DestroyNotify) {
	register Gridder *gridPtr2, *nextPtr;

	if (gridPtr->masterPtr != NULL) {
	    Unlink(gridPtr);
	}
	if (gridPtr->masterDataPtr != NULL) {
	    /* Unlink peer list. */
	    UnlinkPeer(gridPtr, ROW);
	    UnlinkPeer(gridPtr, COLUMN);
	}
	for (gridPtr2 = gridPtr->slavePtr; gridPtr2 != NULL;
		gridPtr2 = nextPtr) {
	    Tk_UnmapWindow(gridPtr2->tkwin);
	    gridPtr2->masterPtr = NULL;
	    nextPtr = gridPtr2->nextPtr;
	    gridPtr2->nextPtr = NULL;

Added gs.tcl.



























































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
set rows 40
set cols 40
set head 2

frame .ft
frame .fl
frame .fr
frame .fb
frame .fc

for {set row 0} {$row < $head} {incr row} {
    for {set col 0} {$col < $cols} {incr col} {
        set w .ft.l$row,$col
        label $w -text "tt$col,$row"
        grid $w -row $row -column $col -sticky we
        if {($row + $col) & 1} {
            $w configure -background green
        }
    }
}

for {set row 0} {$row < $rows} {incr row} {
    for {set col 0} {$col < $head} {incr col} {
        set w .fl.l$row,$col
        label $w -text "ll$col,$row"
        grid $w -row $row -column $col -sticky we
        if {($row + $col) & 1} {
            $w configure -background green
        }
    }
}

for {set row 0} {$row < $rows} {incr row} {
    for {set col 0} {$col < $head} {incr col} {
        set w .fr.l$row,$col
        label $w -text "rr$col,$row"
        grid $w -row $row -column $col -sticky we
        if {($row + $col) & 1} {
            $w configure -background green
        }
    }
}

for {set row 0} {$row < $head} {incr row} {
    for {set col 0} {$col < $cols} {incr col} {
        set w .fb.l$row,$col
        label $w -text "bb$col,$row"
        grid $w -row $row -column $col -sticky we
        if {($row + $col) & 1} {
            $w configure -background green
        }
    }
}

for {set row 0} {$row < $rows} {incr row} {
    for {set col 0} {$col < $cols} {incr col} {
        set w .fc.l$row,$col
        label $w -text "$col,$row"
        grid $w -row $row -column $col -sticky we
        if {($row + $col) & 1} {
            $w configure -background green
        }
    }
}

proc MyXView {wlist args} {
    foreach w $wlist {
        eval grid xview \$w $args
    }
}

proc MyYView {wlist args} {
    foreach w $wlist {
        eval grid yview \$w $args
    }
}

scrollbar .sbx -orient horizontal -command "MyXView {.ft .fc .fb}"
scrollbar .sby -orient vertical   -command "MyYView {.fl .fc .fr}"
grid xscrollcommand .fc ".sbx set"
grid yscrollcommand .fc ".sby set"

ttk::separator .st -orient horizontal
ttk::separator .sb -orient horizontal
ttk::separator .sl -orient vertical
ttk::separator .sr -orient vertical

grid x   .sl .ft  .sr x   x    -sticky news
grid .st -   -    -   -   -    -sticky news
grid .fl x   .fc  x   .fr .sby -sticky news
grid .sb -   -    -   -   -    -sticky news
grid x   x   .fb  x   x   x    -sticky news
grid x   x   .sbx x   x   x    -sticky news

grid .sl .sr -rowspan 6
grid columnconfigure . .fc -weight 1
grid rowconfigure    . .fc -weight 1

grid columnpeer .fc .ft
grid columnpeer .fc .fb
grid rowpeer .fc .fl
grid rowpeer .fc .fr
puts [grid columnpeer .fc]
puts [grid rowpeer .fc]
puts [grid size .ft]
puts [grid size .fc]
# Possible way to do it:
#grid masterconfigure .f -xscrollcommand ".sbx set"
#grid masterconfigure .f -yscrollcommand ".sby set"