diff options
author | csaba <csaba> | 2023-11-13 17:26:02 (GMT) |
---|---|---|
committer | csaba <csaba> | 2023-11-13 17:26:02 (GMT) |
commit | 77f93393c12a891b1f70d1d192302b41fe82a5a8 (patch) | |
tree | 7c672348a4da7d496f528531d22f1b48118c0f72 /generic | |
parent | fd0dfa4ae8595298c7d5222326eccb81e7512d3c (diff) | |
download | tk-77f93393c12a891b1f70d1d192302b41fe82a5a8.zip tk-77f93393c12a891b1f70d1d192302b41fe82a5a8.tar.gz tk-77f93393c12a891b1f70d1d192302b41fe82a5a8.tar.bz2 |
Using the application's TkMainInfo struct for sharing the nbTabsStickBit in a thread-safe manner. Thanks Christian W.!
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tkInt.h | 2 | ||||
-rw-r--r-- | generic/ttk/ttkClamTheme.c | 16 | ||||
-rw-r--r-- | generic/ttk/ttkElements.c | 15 | ||||
-rw-r--r-- | generic/ttk/ttkNotebook.c | 21 |
4 files changed, 39 insertions, 15 deletions
diff --git a/generic/tkInt.h b/generic/tkInt.h index e31bc1b..0742563 100644 --- a/generic/tkInt.h +++ b/generic/tkInt.h @@ -693,6 +693,8 @@ typedef struct TkMainInfo { /* Saved Tcl [update] command, used to restore * Tcl's version of [update] after Tk is shut * down */ + unsigned int ttkNbTabsStickBit; + /* Information used by ttk::notebook. */ } TkMainInfo; /* diff --git a/generic/ttk/ttkClamTheme.c b/generic/ttk/ttkClamTheme.c index 9042770..1081c4b 100644 --- a/generic/ttk/ttkClamTheme.c +++ b/generic/ttk/ttkClamTheme.c @@ -850,12 +850,12 @@ static Ttk_ElementOptionSpec NotebookElementOptions[] = { { NULL, TK_OPTION_BOOLEAN, 0, NULL } }; -extern Ttk_PositionSpec nbTabsStickBit; /* see ttkNotebook.c */ - static void TabElementSize( void *dummy, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { + Ttk_PositionSpec nbTabsStickBit = TTK_STICK_S; + TkMainInfo *mainInfoPtr = ((TkWindow *) tkwin)->mainPtr; int borderWidth = 2; (void)dummy; (void)elementRecord; @@ -863,6 +863,10 @@ static void TabElementSize( (void)widthPtr; (void)heightPtr; + if (mainInfoPtr != NULL) { + nbTabsStickBit = (Ttk_PositionSpec) mainInfoPtr->ttkNbTabsStickBit; + } + *paddingPtr = Ttk_UniformPadding((short)borderWidth); switch (nbTabsStickBit) { default: @@ -885,15 +889,21 @@ static void TabElementDraw( void *dummy, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { + Ttk_PositionSpec nbTabsStickBit = TTK_STICK_S; + TkMainInfo *mainInfoPtr = ((TkWindow *) tkwin)->mainPtr; + int borderWidth = 2, delta = 0; NotebookElement *tab = (NotebookElement *)elementRecord; Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, tab->backgroundObj); Display *display = Tk_Display(tkwin); - int borderWidth = 2, delta = 0; int x1, y1, x2, y2; GC gc; const int w = WIN32_XDRAWLINE_HACK; (void)dummy; + if (mainInfoPtr != NULL) { + nbTabsStickBit = (Ttk_PositionSpec) mainInfoPtr->ttkNbTabsStickBit; + } + if (state & TTK_STATE_SELECTED) { delta = borderWidth; } diff --git a/generic/ttk/ttkElements.c b/generic/ttk/ttkElements.c index 61b73ce..2520ced 100644 --- a/generic/ttk/ttkElements.c +++ b/generic/ttk/ttkElements.c @@ -1106,17 +1106,22 @@ static Ttk_ElementOptionSpec TabElementOptions[] = { {0,0,0,0} }; -extern Ttk_PositionSpec nbTabsStickBit; /* see ttkNotebook.c */ - static void TabElementSize( void *clientData, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { TabElement *tab = (TabElement *)elementRecord; int borderWidth = 1; + Ttk_PositionSpec nbTabsStickBit = TTK_STICK_S; + TkMainInfo *mainInfoPtr = ((TkWindow *) tkwin)->mainPtr; Tk_GetPixelsFromObj(0, tkwin, tab->borderWidthObj, &borderWidth); *paddingPtr = Ttk_UniformPadding((short)borderWidth); + + if (mainInfoPtr != NULL) { + nbTabsStickBit = (Ttk_PositionSpec) mainInfoPtr->ttkNbTabsStickBit; + } + switch (nbTabsStickBit) { default: case TTK_STICK_S: @@ -1138,6 +1143,8 @@ static void TabElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { + Ttk_PositionSpec nbTabsStickBit = TTK_STICK_S; + TkMainInfo *mainInfoPtr = ((TkWindow *) tkwin)->mainPtr; TabElement *tab = (TabElement *)elementRecord; Tk_3DBorder border = Tk_Get3DBorderFromObj(tkwin, tab->backgroundObj); XPoint pts[6]; @@ -1145,6 +1152,10 @@ static void TabElementDraw( Display *disp = Tk_Display(tkwin); int borderWidth = 1; + if (mainInfoPtr != NULL) { + nbTabsStickBit = (Ttk_PositionSpec) mainInfoPtr->ttkNbTabsStickBit; + } + if (state & TTK_STATE_SELECTED) { /* * Draw slightly outside of the allocated parcel, diff --git a/generic/ttk/ttkNotebook.c b/generic/ttk/ttkNotebook.c index 02a5546..600eca9 100644 --- a/generic/ttk/ttkNotebook.c +++ b/generic/ttk/ttkNotebook.c @@ -136,14 +136,11 @@ typedef struct Ttk_Padding padding; /* External padding */ } NotebookStyle; -/* Global variable to be set from within NotebookStyleOptions() to one - * of the values TTK_STICK_S, TTK_STICK_N, TTK_STICK_E, or TTK_STICK_W: - */ -Ttk_PositionSpec nbTabsStickBit; - -static void NotebookStyleOptions(Notebook *nb, NotebookStyle *nbstyle) +static void NotebookStyleOptions( + Notebook *nb, NotebookStyle *nbstyle, Tk_Window tkwin) { Tcl_Obj *objPtr; + TkMainInfo *mainInfoPtr = ((TkWindow *) tkwin)->mainPtr; nbstyle->tabPosition = TTK_PACK_TOP | TTK_STICK_W; if ((objPtr = Ttk_QueryOption(nb->core.layout, "-tabposition", 0)) != 0) { @@ -165,9 +162,12 @@ static void NotebookStyleOptions(Notebook *nb, NotebookStyle *nbstyle) TtkGetLabelAnchorFromObj(NULL, objPtr, &nbstyle->tabPlacement); } - /* Save the stick bit in the global variable nbTabsStickBit + /* Save the stick bit for later. One of the values + * TTK_STICK_S, TTK_STICK_N, TTK_STICK_E, or TTK_STICK_W: */ - nbTabsStickBit = (nbstyle->tabPlacement & 0x0f); + if (mainInfoPtr != NULL) { + mainInfoPtr->ttkNbTabsStickBit = (nbstyle->tabPlacement & 0x0f); + } /* Compute tabOrient as function of tabPlacement: */ @@ -395,6 +395,7 @@ static void TabrowSize( static int NotebookSize(void *clientData, int *widthPtr, int *heightPtr) { Notebook *nb = (Notebook *)clientData; + Tk_Window nbwin = nb->core.tkwin; NotebookStyle nbstyle; Ttk_Padding padding; Ttk_Element clientNode = Ttk_FindElement(nb->core.layout, "client"); @@ -403,7 +404,7 @@ static int NotebookSize(void *clientData, int *widthPtr, int *heightPtr) tabrowWidth = 0, tabrowHeight = 0; int i; - NotebookStyleOptions(nb, &nbstyle); + NotebookStyleOptions(nb, &nbstyle, nbwin); /* Compute max requested size of all content windows: */ @@ -553,7 +554,7 @@ static void NotebookDoLayout(void *recordPtr) NotebookStyle nbstyle; int currentIndex = nb->notebook.currentIndex; - NotebookStyleOptions(nb, &nbstyle); + NotebookStyleOptions(nb, &nbstyle, nbwin); /* Notebook internal padding: */ |