Skip to content

Commit

Permalink
Fix [527cb3cd5d]: Documentation of ttk states. user1/user2 are no lon…
Browse files Browse the repository at this point in the history
…ger misused for other (internal) purposes
  • Loading branch information
jan.nijtmans committed May 20, 2024
2 parents ab2d4c3 + d04cb1f commit 64d47b4
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 37 deletions.
10 changes: 5 additions & 5 deletions generic/ttk/ttkClamTheme.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

#include "tkInt.h"
#include "ttkTheme.h"
#include "ttkThemeInt.h"

/*
* Under windows, the Tk-provided XDrawLine and XDrawArc have an
Expand Down Expand Up @@ -1035,7 +1035,7 @@ static void TabElementDraw(
switch (nbTabsStickBit) {
default:
case TTK_STICK_S:
if (state & TTK_STATE_USER2) { /* rightmost tab */
if (state & TTK_STATE_LAST) { /* rightmost tab */
--b.width;
}

Expand All @@ -1057,7 +1057,7 @@ static void TabElementDraw(
break;

case TTK_STICK_N:
if (state & TTK_STATE_USER2) { /* rightmost tab */
if (state & TTK_STATE_LAST) { /* rightmost tab */
--b.width;
}

Expand All @@ -1079,7 +1079,7 @@ static void TabElementDraw(
break;

case TTK_STICK_E:
if (state & TTK_STATE_USER2) { /* bottommost tab */
if (state & TTK_STATE_LAST) { /* bottommost tab */
--b.height;
}

Expand All @@ -1101,7 +1101,7 @@ static void TabElementDraw(
break;

case TTK_STICK_W:
if (state & TTK_STATE_USER2) { /* bottommost tab */
if (state & TTK_STATE_LAST) { /* bottommost tab */
--b.height;
}

Expand Down
3 changes: 0 additions & 3 deletions generic/ttk/ttkDefaultTheme.c
Original file line number Diff line number Diff line change
Expand Up @@ -1208,9 +1208,6 @@ static const Ttk_ElementSpec SliderElementSpec = {
* +++ Tree indicator element.
*/

#define TTK_STATE_OPEN TTK_STATE_USER1 /* XREF: treeview.c */
#define TTK_STATE_LEAF TTK_STATE_USER2

typedef struct {
Tcl_Obj *colorObj;
Tcl_Obj *marginObj;
Expand Down
4 changes: 2 additions & 2 deletions generic/ttk/ttkNotebook.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ static Ttk_State TabState(Notebook *nb, Tcl_Size index)
continue;
}
if (index == i) {
state |= TTK_STATE_USER1;
state |= TTK_STATE_FIRST;
}
break;
}
Expand All @@ -327,7 +327,7 @@ static Ttk_State TabState(Notebook *nb, Tcl_Size index)
continue;
}
if (index == i) {
state |= TTK_STATE_USER2;
state |= TTK_STATE_LAST;
}
break;
}
Expand Down
9 changes: 9 additions & 0 deletions generic/ttk/ttkThemeInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@

#include "ttkTheme.h"

/*------------------------------------------------------------------------
* +++ Widget states (internal).
*/

#define TTK_STATE_OPEN (1<<16)
#define TTK_STATE_LEAF (1<<17)
#define TTK_STATE_FIRST (1<<18)
#define TTK_STATE_LAST (1<<19)

typedef struct Ttk_TemplateNode_ Ttk_TemplateNode, *Ttk_LayoutTemplate;

MODULE_SCOPE Ttk_ElementClass *Ttk_GetElement(Ttk_Theme, const char *name);
Expand Down
3 changes: 0 additions & 3 deletions generic/ttk/ttkTreeview.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ static const Tk_Anchor DEFAULT_IMAGEANCHOR = TK_ANCHOR_W;
static const int DEFAULT_INDENT = 20;
static const int HALO = 4; /* heading separator */

#define TTK_STATE_OPEN TTK_STATE_USER1
#define TTK_STATE_LEAF TTK_STATE_USER2

#define STATE_CHANGED (0x100) /* item state option changed */

#define MAX(a,b) (((a) > (b)) ? (a) : (b))
Expand Down
34 changes: 16 additions & 18 deletions macosx/ttkMacOSXTheme.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/

#include "tkMacOSXPrivate.h"
#include "ttk/ttkTheme.h"
#include "ttk/ttkThemeInt.h"
#include "ttkMacOSXTheme.h"
#include "tkColor.h"
#include <math.h>
Expand Down Expand Up @@ -1488,11 +1488,11 @@ DrawTab(

CGContextClipToRect(context, bounds);
if (OSVersion < 110000 || !(state & TTK_STATE_SELECTED)) {
if (!(state & TTK_STATE_FIRST_TAB)) {
if (!(state & TTK_STATE_FIRST)) {
bounds.origin.x -= 10;
bounds.size.width += 10;
}
if (!(state & TTK_STATE_LAST_TAB)) {
if (!(state & TTK_STATE_LAST)) {
bounds.size.width += 10;
}
}
Expand All @@ -1510,7 +1510,7 @@ DrawTab(
* not first.
*/

if (!(state & TTK_STATE_FIRST_TAB)) {
if (!(state & TTK_STATE_FIRST)) {
CGContextSaveGState(context);
strokeColor = CGColorFromGray(darkTabSeparator);
CGContextSetStrokeColorWithColor(context, strokeColor);
Expand All @@ -1530,7 +1530,7 @@ DrawTab(
* (The selected tab is always drawn last.)
*/

if ((state & TTK_STATE_FIRST_TAB) && !(state & TTK_STATE_LAST_TAB)) {
if ((state & TTK_STATE_FIRST) && !(state & TTK_STATE_LAST)) {
bounds.size.width += 1;
}
if (!(state & TTK_STATE_BACKGROUND)) {
Expand Down Expand Up @@ -1559,12 +1559,12 @@ DrawTab11(
* rounded rectangle behind the entire tab bar.
*/

if (!(state & TTK_STATE_FIRST_TAB)) {
if (!(state & TTK_STATE_FIRST)) {
clipRect.origin.x -= 5;
bounds.origin.x -= 5;
bounds.size.width += 5;
}
if (!(state & TTK_STATE_LAST_TAB)) {
if (!(state & TTK_STATE_LAST)) {
clipRect.size.width += 5;
bounds.size.width += 5;
}
Expand Down Expand Up @@ -1874,15 +1874,15 @@ static const Ttk_StateTable TabStyleTable[] = {
{kThemeTabNonFront, 0, 0}
};
static const Ttk_StateTable TabAdornmentTable[] = {
{kHIThemeTabAdornmentNone, TTK_STATE_FIRST_TAB | TTK_STATE_LAST_TAB, 0},
{kHIThemeTabAdornmentTrailingSeparator, TTK_STATE_FIRST_TAB, 0},
{kHIThemeTabAdornmentNone, TTK_STATE_LAST_TAB, 0},
{kHIThemeTabAdornmentNone, TTK_STATE_FIRST | TTK_STATE_LAST, 0},
{kHIThemeTabAdornmentTrailingSeparator, TTK_STATE_FIRST, 0},
{kHIThemeTabAdornmentNone, TTK_STATE_LAST, 0},
{kHIThemeTabAdornmentTrailingSeparator, 0, 0},
};
static const Ttk_StateTable TabPositionTable[] = {
{kHIThemeTabPositionOnly, TTK_STATE_FIRST_TAB | TTK_STATE_LAST_TAB, 0},
{kHIThemeTabPositionFirst, TTK_STATE_FIRST_TAB, 0},
{kHIThemeTabPositionLast, TTK_STATE_LAST_TAB, 0},
{kHIThemeTabPositionOnly, TTK_STATE_FIRST | TTK_STATE_LAST, 0},
{kHIThemeTabPositionFirst, TTK_STATE_FIRST, 0},
{kHIThemeTabPositionLast, TTK_STATE_LAST, 0},
{kHIThemeTabPositionMiddle, 0, 0},
};

Expand Down Expand Up @@ -3321,10 +3321,8 @@ static Ttk_ElementSpec TreeHeaderElementSpec = {
* +++ Disclosure triangles --
*/

#define TTK_TREEVIEW_STATE_OPEN TTK_STATE_USER1
#define TTK_TREEVIEW_STATE_LEAF TTK_STATE_USER2
static const Ttk_StateTable DisclosureValueTable[] = {
{kThemeDisclosureDown, TTK_TREEVIEW_STATE_OPEN, 0},
{kThemeDisclosureDown, TTK_STATE_OPEN, 0},
{kThemeDisclosureRight, 0, 0},
};
static void DisclosureElementSize(
Expand All @@ -3351,7 +3349,7 @@ static void DisclosureElementDraw(
Ttk_Box b,
Ttk_State state)
{
if (!(state & TTK_TREEVIEW_STATE_LEAF)) {
if (!(state & TTK_STATE_LEAF)) {
int triangleState = TkMacOSXInDarkMode(tkwin) ?
kThemeStateInactive : kThemeStateActive;
CGRect bounds = BoxToRect(d, b);
Expand All @@ -3370,7 +3368,7 @@ static void DisclosureElementDraw(
NSColor *stroke = [[NSColor textColor]
colorUsingColorSpace: deviceRGB];
[stroke getComponents: rgba];
if (state & TTK_TREEVIEW_STATE_OPEN) {
if (state & TTK_STATE_OPEN) {
DrawOpenDisclosure(dc.context, bounds, 2, 8, rgba);
} else {
DrawClosedDisclosure(dc.context, bounds, 2, 12, rgba);
Expand Down
2 changes: 0 additions & 2 deletions macosx/ttkMacOSXTheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
* Meanings of Ttk states represented by User1 and User2.
*/

#define TTK_STATE_FIRST_TAB TTK_STATE_USER1
#define TTK_STATE_LAST_TAB TTK_STATE_USER2
#define TTK_STATE_IS_ACCENTED TTK_STATE_USER2
#define TTK_TREEVIEW_STATE_SORTARROW TTK_STATE_USER1

Expand Down
5 changes: 1 addition & 4 deletions win/ttkWinXPTheme.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <windows.h>
#include <uxtheme.h>
#include <vssym32.h>
#include "ttk/ttkTheme.h"
#include "ttk/ttkThemeInt.h"

typedef HTHEME (STDAPICALLTYPE OpenThemeDataProc)(HWND hwnd,
LPCWSTR pszClassList);
Expand Down Expand Up @@ -866,9 +866,6 @@ static const Ttk_ElementSpec TabElementSpec =
* Generic element, but don't display at all if TTK_STATE_LEAF (=USER2) set
*/

#define TTK_STATE_OPEN TTK_STATE_USER1
#define TTK_STATE_LEAF TTK_STATE_USER2

static const Ttk_StateTable header_statemap[] =
{
{ HIS_PRESSED, TTK_STATE_PRESSED, 0 },
Expand Down

0 comments on commit 64d47b4

Please sign in to comment.