Tk Source Code

Changes On Branch bug-308940fff
Login

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

Changes In Branch bug-308940fff Excluding Merge-Ins

This is equivalent to a diff from d3ce513d to ff3ef4b1

2017-05-02
18:24
Change floor() back to casting to int() in fixing [6020ee2d03]. check-in: 14f7b095 user: fvogel tags: core-8-6-branch
18:22
Revert the previous commit since it has drawbacks (see [6020ee2d03]). Closed-Leaf check-in: ff3ef4b1 user: fvogel tags: bug-308940fff
2017-04-06
20:01
Slightly better fix anonymously proposed in [6020ee2d03]. Use floor() instead of casting to an int. check-in: 6cfe2c0c user: fvogel tags: bug-308940fff
16:08
[db8c541b6b] Prevent access of freed memory in warp pointer callbacks. check-in: da2440fd user: dgp tags: core-8-6-branch
2017-04-03
21:27
Fix [d6fd19e4e5]: Documentation of ttk::notebook 'tabs' widget command clarification Closed-Leaf check-in: 854c6a8f user: fvogel tags: bug-d6fd19e4e5
06:29
Fix [2912962fff]: Notebook does not set TTK_STATE_USER1. Patch from Jos Decoster. check-in: 2c14ebc8 user: fvogel tags: bug-2912962fff
2017-03-31
21:27
Fix [3089640fff], [6020ee2d03], [e016579efb] and [6bf197edbf]: ttk::notebook tabs can disappear (tab width incorrectly calculated). Patch from Koen Danckaert. check-in: 81b87266 user: fvogel tags: bug-308940fff
13:11
merge 8.6 check-in: eeaae4c4 user: dgp tags: core-8-6-7-rc
11:39
merge core-8-6-branch check-in: 8fc8b92e user: jan.nijtmans tags: androwish
2017-03-29
20:02
Fix [28a3c366e6]: memory leak in the text widget. Patch contributed anonymously check-in: 0e08f18d user: fvogel tags: trunk
20:02
Fix [28a3c366e6]: memory leak in the text widget. Patch contributed anonymously check-in: d3ce513d user: fvogel tags: core-8-6-branch
2017-03-26
15:25
merge mark check-in: 6ee41e1b user: fvogel tags: core-8-6-branch
08:59
Fix [28a3c366e6]: memory leak in the text widget. Patch contributed anonymously Closed-Leaf check-in: f3f5eeb9 user: fvogel tags: bug-28a3c366e6

Changes to generic/ttk/ttkNotebook.c.

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
/*------------------------------------------------------------------------
 * +++ Geometry management - size computation.
 */

/* TabrowSize --
 *	Compute max height and total width of all tabs (horizontal layouts)
 *	or total height and max width (vertical layouts).


 *
 * Side effects:
 * 	Sets width and height fields for all tabs.
 *
 * Notes:
 * 	Hidden tabs are included in the perpendicular computation
 * 	(max height/width) but not parallel (total width/height).
 */
static void TabrowSize(
    Notebook *nb, Ttk_Orient orient, int *widthPtr, int *heightPtr)
{
    Ttk_Layout tabLayout = nb->notebook.tabLayout;
    int tabrowWidth = 0, tabrowHeight = 0;
    int i;

    for (i = 0; i < Ttk_NumberSlaves(nb->notebook.mgr); ++i) {
	Tab *tab = Ttk_SlaveData(nb->notebook.mgr, i);
	Ttk_State tabState = TabState(nb,i);

	Ttk_RebindSublayout(tabLayout, tab);
	Ttk_LayoutSize(tabLayout,tabState,&tab->width,&tab->height);


	if (orient == TTK_ORIENT_HORIZONTAL) {
	    tabrowHeight = MAX(tabrowHeight, tab->height);
	    if (tab->state != TAB_STATE_HIDDEN) { tabrowWidth += tab->width; }
	} else {
	    tabrowWidth = MAX(tabrowWidth, tab->width);
	    if (tab->state != TAB_STATE_HIDDEN) { tabrowHeight += tab->height; }







>
>









|











>







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
/*------------------------------------------------------------------------
 * +++ Geometry management - size computation.
 */

/* TabrowSize --
 *	Compute max height and total width of all tabs (horizontal layouts)
 *	or total height and max width (vertical layouts).
 *	The -mintabwidth style option is taken into account (for the width
 *	only).
 *
 * Side effects:
 * 	Sets width and height fields for all tabs.
 *
 * Notes:
 * 	Hidden tabs are included in the perpendicular computation
 * 	(max height/width) but not parallel (total width/height).
 */
static void TabrowSize(
    Notebook *nb, Ttk_Orient orient, int minTabWidth, int *widthPtr, int *heightPtr)
{
    Ttk_Layout tabLayout = nb->notebook.tabLayout;
    int tabrowWidth = 0, tabrowHeight = 0;
    int i;

    for (i = 0; i < Ttk_NumberSlaves(nb->notebook.mgr); ++i) {
	Tab *tab = Ttk_SlaveData(nb->notebook.mgr, i);
	Ttk_State tabState = TabState(nb,i);

	Ttk_RebindSublayout(tabLayout, tab);
	Ttk_LayoutSize(tabLayout,tabState,&tab->width,&tab->height);
        tab->width = MAX(tab->width, minTabWidth);

	if (orient == TTK_ORIENT_HORIZONTAL) {
	    tabrowHeight = MAX(tabrowHeight, tab->height);
	    if (tab->state != TAB_STATE_HIDDEN) { tabrowWidth += tab->width; }
	} else {
	    tabrowWidth = MAX(tabrowWidth, tab->width);
	    if (tab->state != TAB_STATE_HIDDEN) { tabrowHeight += tab->height; }
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
    if (reqWidth > 0)
	clientWidth = reqWidth;
    if (reqHeight > 0)
	clientHeight = reqHeight;

    /* Tab row:
     */
    TabrowSize(nb, nbstyle.tabOrient, &tabrowWidth, &tabrowHeight);
    tabrowHeight += Ttk_PaddingHeight(nbstyle.tabMargins);
    tabrowWidth += Ttk_PaddingWidth(nbstyle.tabMargins);

    /* Account for exterior and interior padding:
     */
    padding = nbstyle.padding;
    if (clientNode) {







|







405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
    if (reqWidth > 0)
	clientWidth = reqWidth;
    if (reqHeight > 0)
	clientHeight = reqHeight;

    /* Tab row:
     */
    TabrowSize(nb, nbstyle.tabOrient, nbstyle.minTabWidth, &tabrowWidth, &tabrowHeight);
    tabrowHeight += Ttk_PaddingHeight(nbstyle.tabMargins);
    tabrowWidth += Ttk_PaddingWidth(nbstyle.tabMargins);

    /* Account for exterior and interior padding:
     */
    padding = nbstyle.padding;
    if (clientNode) {
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

/*------------------------------------------------------------------------
 * +++ Geometry management - layout.
 */

/* SqueezeTabs --
 *	Squeeze or stretch tabs to fit within the tab area parcel.

 *
 *	All tabs are adjusted by an equal amount, but will not be made
 *	smaller than the minimum width.  (If all the tabs still do
 *	not fit in the available space, the rightmost ones will
 *	be further squozen by PlaceTabs()).
 *
 *	The algorithm does not always yield an optimal layout, but does
 *	have the important property that decreasing the available width
 *	by one pixel will cause at most one tab to shrink by one pixel;
 *	this means that tabs resize "smoothly" when the window shrinks
 *	and grows.
 *
 * @@@ <<NOTE-TABPOSITION>> bug: only works for horizontal orientations
 * @@@ <<NOTE-SQUEEZE-HIDDEN>> does not account for hidden tabs.
 */

static void SqueezeTabs(
    Notebook *nb, int needed, int available, int minTabWidth)
{
    int nTabs = Ttk_NumberSlaves(nb->notebook.mgr);

    if (nTabs > 0) {
	int difference = available - needed,
	    delta = difference / nTabs,
	    remainder = difference % nTabs,
	    slack = 0;
	int i;

	if (remainder < 0) { remainder += nTabs; --delta; }

	for (i = 0; i < nTabs; ++i) {
	    Tab *tab = Ttk_SlaveData(nb->notebook.mgr,i);
	    int adj = delta + (i < remainder) + slack;

	    if (tab->width + adj >= minTabWidth) {
		tab->width += adj;
		slack = 0;
	    } else {
		slack = adj - (minTabWidth - tab->width);
		tab->width = minTabWidth;
	    }
	}
    }
}

/* PlaceTabs --
 * 	Compute all tab parcels.
 */







>

|
<
<
<
<
<
<
<
<
<






|




|
|
<
|


<
<


<
|
<
|
|
<
<
<
<







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

/*------------------------------------------------------------------------
 * +++ Geometry management - layout.
 */

/* SqueezeTabs --
 *	Squeeze or stretch tabs to fit within the tab area parcel.
 *	This happens independently of the -mintabwidth style option.
 *
 *	All tabs are adjusted by an equal amount.









 *
 * @@@ <<NOTE-TABPOSITION>> bug: only works for horizontal orientations
 * @@@ <<NOTE-SQUEEZE-HIDDEN>> does not account for hidden tabs.
 */

static void SqueezeTabs(
    Notebook *nb, int needed, int available)
{
    int nTabs = Ttk_NumberSlaves(nb->notebook.mgr);

    if (nTabs > 0) {
	int difference = available - needed;
	double delta = (double)difference / needed;

	double slack = 0;
	int i;



	for (i = 0; i < nTabs; ++i) {
	    Tab *tab = Ttk_SlaveData(nb->notebook.mgr,i);

	    double ad = slack + tab->width * delta;

	    tab->width += (int)ad;
	    slack = ad - (int)ad;




	}
    }
}

/* PlaceTabs --
 * 	Compute all tab parcels.
 */
535
536
537
538
539
540
541





542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
    cavity = Ttk_PadBox(cavity, nbstyle.padding);

    /* Layout for notebook background (base layout):
     */
    Ttk_PlaceLayout(nb->core.layout, nb->core.state, Ttk_WinBox(nbwin));

    /* Place tabs:





     */
    TabrowSize(nb, nbstyle.tabOrient, &tabrowWidth, &tabrowHeight);
    tabrowBox = Ttk_PadBox(
		    Ttk_PositionBox(&cavity,
			tabrowWidth + Ttk_PaddingWidth(nbstyle.tabMargins),
			tabrowHeight + Ttk_PaddingHeight(nbstyle.tabMargins),
			nbstyle.tabPosition),
		    nbstyle.tabMargins);

    SqueezeTabs(nb, tabrowWidth, tabrowBox.width, nbstyle.minTabWidth);
    PlaceTabs(nb, tabrowBox, nbstyle.tabPlacement);

    /* Layout for client area frame:
     */
    if (clientNode) {
	Ttk_PlaceElement(nb->core.layout, clientNode, cavity);
	cavity = Ttk_LayoutNodeInternalParcel(nb->core.layout, clientNode);







>
>
>
>
>

|







|







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
    cavity = Ttk_PadBox(cavity, nbstyle.padding);

    /* Layout for notebook background (base layout):
     */
    Ttk_PlaceLayout(nb->core.layout, nb->core.state, Ttk_WinBox(nbwin));

    /* Place tabs:
     * Note: TabrowSize() takes into account -mintabwidth, but the tabs will
     * actually have this minimum size when displayed only if there is enough
     * space to draw the tabs with this width. Otherwise some of the tabs can
     * be squeezed to a size smaller than -mintabwidth because we prefer
     * displaying all tabs than than honoring -mintabwidth for all of them.
     */
    TabrowSize(nb, nbstyle.tabOrient, nbstyle.minTabWidth, &tabrowWidth, &tabrowHeight);
    tabrowBox = Ttk_PadBox(
		    Ttk_PositionBox(&cavity,
			tabrowWidth + Ttk_PaddingWidth(nbstyle.tabMargins),
			tabrowHeight + Ttk_PaddingHeight(nbstyle.tabMargins),
			nbstyle.tabPosition),
		    nbstyle.tabMargins);

    SqueezeTabs(nb, tabrowWidth, tabrowBox.width);
    PlaceTabs(nb, tabrowBox, nbstyle.tabPlacement);

    /* Layout for client area frame:
     */
    if (clientNode) {
	Ttk_PlaceElement(nb->core.layout, clientNode, cavity);
	cavity = Ttk_LayoutNodeInternalParcel(nb->core.layout, clientNode);