Skip to content

Commit bf3e7a3

Browse files
author
csaba
committed
Fix for [0115338117]: Flip ttk::notebook tab states "first" and "last" for "-tabplacement e*|s*.
2 parents ac1e47e + b1d94d5 commit bf3e7a3

12 files changed

Lines changed: 391 additions & 88 deletions

File tree

doc/ttk_notebook.n

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,22 @@ the tab position. The default position is \fBn\fP for the \fBaqua\fP
260260
theme and \fBnw\fP for all the other built-in themes.
261261
.RE
262262
.br
263+
\fB\-tabplacement\fP \fIplacement\fP
264+
.RS
265+
Specifies the placement (anchor) of the tabs within the tab row or column
266+
as a string of length 1 or 2. The first character indicates the side as
267+
\fBw\fP, \fBe\fP, \fBn\fP, or \fBs\fP, while the second character (if
268+
present) is the sticky bit (specified as \fBs\fP, \fBn\fP, \fBe\fP, or
269+
\fBw\fP) within the tab placement. For example, the tab placement \fBws\fP
270+
means: attach the west (left) side of each tab to the previous one and
271+
align the south (bottom) edges with each other. Similarly, the tab
272+
placement \fBse\fP specifies to attach the south (bottom) side of each tab
273+
to the previous one and align the east (right) edges with each other. The
274+
default placement depends on the first character of the tab position:
275+
\fBws\fP for \fBn*\fP, \fBwn\fP for \fBs*\fP, \fBne\fP for \fBw*\fP, and
276+
\fBnw\fP for \fBe*\fP.
277+
.RE
278+
.br
263279
.PP
264280
\fBTNotebook.Tab\fP styling options configurable with \fBttk::style\fP
265281
are:

generic/tkInt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ typedef struct TkMainInfo {
691691
/* Saved Tcl [update] command, used to restore
692692
* Tcl's version of [update] after Tk is shut
693693
* down. For Tcl 9.1+ */
694-
unsigned int ttkNbTabsStickBit;
694+
unsigned int nbTabPosition, nbTabPlacement;
695695
/* Information used by ttk::notebook. */
696696
int troughInnerX, troughInnerY, troughInnerWidth, troughInnerHeight;
697697
/* Information used by ttk::scale. */

generic/ttk/ttkClamTheme.c

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -980,16 +980,17 @@ static void TabElementSize(
980980
TCL_UNUSED(int *), /* heightPtr */
981981
Ttk_Padding *paddingPtr)
982982
{
983-
Ttk_PositionSpec nbTabsStickBit = TTK_STICK_S;
983+
Ttk_PositionSpec nbTabPlacementStickBit = TTK_STICK_S;
984984
TkMainInfo *mainInfoPtr = ((TkWindow *) tkwin)->mainPtr;
985985
int borderWidth = 2;
986986

987987
if (mainInfoPtr != NULL) {
988-
nbTabsStickBit = (Ttk_PositionSpec) mainInfoPtr->ttkNbTabsStickBit;
988+
nbTabPlacementStickBit =
989+
(Ttk_PositionSpec) (mainInfoPtr->nbTabPlacement & 0x0f);
989990
}
990991

991992
*paddingPtr = Ttk_UniformPadding((short)borderWidth);
992-
switch (nbTabsStickBit) {
993+
switch (nbTabPlacementStickBit) {
993994
default:
994995
case TTK_STICK_S:
995996
paddingPtr->bottom = 0;
@@ -1014,7 +1015,8 @@ static void TabElementDraw(
10141015
Ttk_Box b,
10151016
Ttk_State state)
10161017
{
1017-
Ttk_PositionSpec nbTabsStickBit = TTK_STICK_S;
1018+
Ttk_PositionSpec nbTabPosStickBit = TTK_STICK_W;
1019+
Ttk_PositionSpec nbTabPlcStickBit = TTK_STICK_S;
10181020
TkMainInfo *mainInfoPtr = ((TkWindow *) tkwin)->mainPtr;
10191021
int borderWidth = 2, delta = 0;
10201022
NotebookElement *tab = (NotebookElement *)elementRecord;
@@ -1025,14 +1027,17 @@ static void TabElementDraw(
10251027
const int w = WIN32_XDRAWLINE_HACK;
10261028

10271029
if (mainInfoPtr != NULL) {
1028-
nbTabsStickBit = (Ttk_PositionSpec) mainInfoPtr->ttkNbTabsStickBit;
1030+
nbTabPosStickBit =
1031+
(Ttk_PositionSpec) (mainInfoPtr->nbTabPosition & 0x0f);
1032+
nbTabPlcStickBit =
1033+
(Ttk_PositionSpec) (mainInfoPtr->nbTabPlacement & 0x0f);
10291034
}
10301035

10311036
if (state & TTK_STATE_SELECTED) {
10321037
delta = borderWidth;
10331038
}
10341039

1035-
switch (nbTabsStickBit) {
1040+
switch (nbTabPlcStickBit) {
10361041
default:
10371042
case TTK_STICK_S:
10381043
if (state & TTK_STATE_LAST) { /* rightmost tab */
@@ -1048,9 +1053,14 @@ static void TabElementDraw(
10481053

10491054
gc = Ttk_GCForColor(tkwin, tab->borderColorObj, d);
10501055
XDrawLine(display, d, gc, x1, y1+1, x1, y2+1+w);
1051-
XDrawLine(display, d, gc, x2, y1+1, x2, y2+1+w);
10521056
XDrawLine(display, d, gc, x1+1, y1, x2-1+w, y1);
10531057

1058+
if ((state & TTK_STATE_LAST) && nbTabPosStickBit == TTK_STICK_E) {
1059+
XDrawLine(display, d, gc, x2, y1+1, x2, y2+2+w);
1060+
} else {
1061+
XDrawLine(display, d, gc, x2, y1+1, x2, y2+1+w);
1062+
}
1063+
10541064
gc = Ttk_GCForColor(tkwin, tab->lightColorObj, d);
10551065
XDrawLine(display, d, gc, x1+1, y1+1, x1+1, y2+delta+w);
10561066
XDrawLine(display, d, gc, x1+1, y1+1, x2-1+w, y1+1);
@@ -1070,9 +1080,14 @@ static void TabElementDraw(
10701080

10711081
gc = Ttk_GCForColor(tkwin, tab->borderColorObj, d);
10721082
XDrawLine(display, d, gc, x1, y1-1, x1, y2-1-w);
1073-
XDrawLine(display, d, gc, x2, y1-1, x2, y2-1-w);
10741083
XDrawLine(display, d, gc, x1+1, y1, x2-1+w, y1);
10751084

1085+
if ((state & TTK_STATE_LAST) && nbTabPosStickBit == TTK_STICK_E) {
1086+
XDrawLine(display, d, gc, x2, y1-1, x2, y2-2-w);
1087+
} else {
1088+
XDrawLine(display, d, gc, x2, y1-1, x2, y2-1-w);
1089+
}
1090+
10761091
gc = Ttk_GCForColor(tkwin, tab->lightColorObj, d);
10771092
XDrawLine(display, d, gc, x1+1, y1-1, x1+1, y2-delta-w);
10781093
XDrawLine(display, d, gc, x1+1, y1-1, x2-1+w, y1-1);
@@ -1093,7 +1108,12 @@ static void TabElementDraw(
10931108
gc = Ttk_GCForColor(tkwin, tab->borderColorObj, d);
10941109
XDrawLine(display, d, gc, x1, y1+1, x1, y2-1+w);
10951110
XDrawLine(display, d, gc, x1+1, y1, x2+1+w, y1);
1096-
XDrawLine(display, d, gc, x1+1, y2, x2+1+w, y2);
1111+
1112+
if ((state & TTK_STATE_LAST) && nbTabPosStickBit == TTK_STICK_S) {
1113+
XDrawLine(display, d, gc, x1+1, y2, x2+2+w, y2);
1114+
} else {
1115+
XDrawLine(display, d, gc, x1+1, y2, x2+1+w, y2);
1116+
}
10971117

10981118
gc = Ttk_GCForColor(tkwin, tab->lightColorObj, d);
10991119
XDrawLine(display, d, gc, x1+1, y1+1, x1+1, y2-1+w);
@@ -1115,7 +1135,12 @@ static void TabElementDraw(
11151135
gc = Ttk_GCForColor(tkwin, tab->borderColorObj, d);
11161136
XDrawLine(display, d, gc, x1, y1+1, x1, y2-1+w);
11171137
XDrawLine(display, d, gc, x1-1, y1, x2-1-w, y1);
1118-
XDrawLine(display, d, gc, x1-1, y2, x2-1-w, y2);
1138+
1139+
if ((state & TTK_STATE_LAST) && nbTabPosStickBit == TTK_STICK_S) {
1140+
XDrawLine(display, d, gc, x1-1, y2, x2-2-w, y2);
1141+
} else {
1142+
XDrawLine(display, d, gc, x1-1, y2, x2-1-w, y2);
1143+
}
11191144

11201145
gc = Ttk_GCForColor(tkwin, tab->lightColorObj, d);
11211146
XDrawLine(display, d, gc, x1-1, y1+1, x1-1, y2-1+w);

generic/ttk/ttkElements.c

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,17 +1736,18 @@ static void TabElementSize(
17361736
{
17371737
TabElement *tab = (TabElement *)elementRecord;
17381738
int borderWidth = 1;
1739-
Ttk_PositionSpec nbTabsStickBit = TTK_STICK_S;
1739+
Ttk_PositionSpec nbTabPlcStickBit = TTK_STICK_S;
17401740
TkMainInfo *mainInfoPtr = ((TkWindow *) tkwin)->mainPtr;
17411741

17421742
Tk_GetPixelsFromObj(0, tkwin, tab->borderWidthObj, &borderWidth);
17431743
*paddingPtr = Ttk_UniformPadding((short)borderWidth);
17441744

17451745
if (mainInfoPtr != NULL) {
1746-
nbTabsStickBit = (Ttk_PositionSpec) mainInfoPtr->ttkNbTabsStickBit;
1746+
nbTabPlcStickBit =
1747+
(Ttk_PositionSpec) (mainInfoPtr->nbTabPlacement & 0x0f);
17471748
}
17481749

1749-
switch (nbTabsStickBit) {
1750+
switch (nbTabPlcStickBit) {
17501751
default:
17511752
case TTK_STICK_S:
17521753
paddingPtr->bottom = 0;
@@ -1768,7 +1769,7 @@ static void TabElementDraw(
17681769
void *elementRecord, Tk_Window tkwin,
17691770
Drawable d, Ttk_Box b, Ttk_State state)
17701771
{
1771-
Ttk_PositionSpec nbTabsStickBit = TTK_STICK_S;
1772+
Ttk_PositionSpec nbTabPlcStickBit = TTK_STICK_S;
17721773
TkMainInfo *mainInfoPtr = ((TkWindow *) tkwin)->mainPtr;
17731774
TabElement *tab = (TabElement *)elementRecord;
17741775
Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, tab->backgroundObj);
@@ -1781,15 +1782,16 @@ static void TabElementDraw(
17811782
int borderWidth = 1;
17821783

17831784
if (mainInfoPtr != NULL) {
1784-
nbTabsStickBit = (Ttk_PositionSpec) mainInfoPtr->ttkNbTabsStickBit;
1785+
nbTabPlcStickBit =
1786+
(Ttk_PositionSpec) (mainInfoPtr->nbTabPlacement & 0x0f);
17851787
}
17861788

17871789
if (state & TTK_STATE_SELECTED) {
17881790
/*
17891791
* Draw slightly outside of the allocated parcel,
17901792
* to overwrite the client area border.
17911793
*/
1792-
switch (nbTabsStickBit) {
1794+
switch (nbTabPlcStickBit) {
17931795
default:
17941796
case TTK_STICK_S:
17951797
b.height += 1;
@@ -1811,7 +1813,7 @@ static void TabElementDraw(
18111813
}
18121814
}
18131815

1814-
switch (nbTabsStickBit) {
1816+
switch (nbTabPlcStickBit) {
18151817
default:
18161818
case TTK_STICK_S:
18171819
pts[0].x = b.x; pts[0].y = b.y + b.height-1;
@@ -1850,7 +1852,7 @@ static void TabElementDraw(
18501852
XFillPolygon(disp, d, Tk_3DBorderGC(tkwin, border, TK_3D_FLAT_GC),
18511853
pts, 6, Convex, CoordModeOrigin);
18521854

1853-
switch (nbTabsStickBit) {
1855+
switch (nbTabPlcStickBit) {
18541856
default:
18551857
case TTK_STICK_S:
18561858
pts[5].y -= 1 - WIN32_XDRAWLINE_HACK;
@@ -1868,12 +1870,29 @@ static void TabElementDraw(
18681870

18691871
Tk_GetPixelsFromObj(NULL, tkwin, tab->borderWidthObj, &borderWidth);
18701872
while (borderWidth--) {
1871-
XDrawLines(disp, d, Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC),
1872-
pts, 4, CoordModeOrigin);
1873-
XDrawLines(disp, d, Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC),
1874-
pts+3, 3, CoordModeOrigin);
1873+
switch (nbTabPlcStickBit) {
1874+
default:
1875+
case TTK_STICK_S:
1876+
case TTK_STICK_E:
1877+
XDrawLines(disp, d,
1878+
Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC),
1879+
pts, 4, CoordModeOrigin);
1880+
XDrawLines(disp, d,
1881+
Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC),
1882+
pts+3, 3, CoordModeOrigin);
1883+
break;
1884+
case TTK_STICK_N:
1885+
case TTK_STICK_W:
1886+
XDrawLines(disp, d,
1887+
Tk_3DBorderGC(tkwin, border, TK_3D_LIGHT_GC),
1888+
pts, 2, CoordModeOrigin);
1889+
XDrawLines(disp, d,
1890+
Tk_3DBorderGC(tkwin, border, TK_3D_DARK_GC),
1891+
pts+1, 5, CoordModeOrigin);
1892+
break;
1893+
}
18751894

1876-
switch (nbTabsStickBit) {
1895+
switch (nbTabPlcStickBit) {
18771896
default:
18781897
case TTK_STICK_S:
18791898
++pts[0].x; ++pts[1].x; ++pts[2].y;
@@ -1895,7 +1914,7 @@ static void TabElementDraw(
18951914
}
18961915

18971916
if (highlight) {
1898-
switch (nbTabsStickBit) {
1917+
switch (nbTabPlcStickBit) {
18991918
default:
19001919
case TTK_STICK_S:
19011920
if (b.width >= 2*cut) {

0 commit comments

Comments
 (0)