diff options
-rw-r--r-- | generic/ttk/ttkLayout.c | 7 | ||||
-rw-r--r-- | generic/ttk/ttkNotebook.c | 44 | ||||
-rw-r--r-- | generic/ttk/ttkThemeInt.h | 2 | ||||
-rw-r--r-- | tests/ttk/notebook.test | 14 |
4 files changed, 48 insertions, 19 deletions
diff --git a/generic/ttk/ttkLayout.c b/generic/ttk/ttkLayout.c index 226dd6c..d4c14f3 100644 --- a/generic/ttk/ttkLayout.c +++ b/generic/ttk/ttkLayout.c @@ -31,6 +31,13 @@ Ttk_BoxContains(Ttk_Box box, int x, int y) && box.y <= y && y < box.y + box.height; } +int +TtkBoxEqual(Ttk_Box box1, Ttk_Box box2) +{ + return box1.x == box2.x && box1.y == box2.y + && box1.width == box2.width && box1.height == box2.height; +} + Tcl_Obj * Ttk_NewBoxObj(Ttk_Box box) { diff --git a/generic/ttk/ttkNotebook.c b/generic/ttk/ttkNotebook.c index 71cbadd..cdbeeef 100644 --- a/generic/ttk/ttkNotebook.c +++ b/generic/ttk/ttkNotebook.c @@ -4,7 +4,7 @@ #include "tkInt.h" -#include "ttkTheme.h" +#include "ttkThemeInt.h" #include "ttkWidget.h" #include "ttkManager.h" @@ -510,6 +510,23 @@ static void PlaceTabs( } } +/* + * NotebookPlaceContent -- + * Set the position and size of a child widget + * based on the current client area and content window options: + */ +static void NotebookPlaceContent(Notebook* nb, int index) +{ + Tab* tab = (Tab*)Ttk_ContentData(nb->notebook.mgr, index); + Tk_Window window = Ttk_ContentWindow(nb->notebook.mgr, index); + Ttk_Box box = + Ttk_StickBox(Ttk_PadBox(nb->notebook.clientArea, tab->padding), + Tk_ReqWidth(window), Tk_ReqHeight(window), tab->sticky); + + Ttk_PlaceContent(nb->notebook.mgr, index, + box.x, box.y, box.width, box.height); +} + /* NotebookDoLayout -- * Computes notebook layout and places tabs. * @@ -525,6 +542,7 @@ static void NotebookDoLayout(void *recordPtr) Ttk_Element clientNode = Ttk_FindElement(nb->core.layout, "client"); Ttk_Box tabrowBox; NotebookStyle nbstyle; + int currentIndex = nb->notebook.currentIndex; NotebookStyleOptions(nb, &nbstyle); @@ -564,24 +582,12 @@ static void NotebookDoLayout(void *recordPtr) if (cavity.height <= 0) cavity.height = 1; if (cavity.width <= 0) cavity.width = 1; - nb->notebook.clientArea = cavity; -} - -/* - * NotebookPlaceContent -- - * Set the position and size of a child widget - * based on the current client area and content window options: - */ -static void NotebookPlaceContent(Notebook *nb, int index) -{ - Tab *tab = (Tab *)Ttk_ContentData(nb->notebook.mgr, index); - Tk_Window window = Ttk_ContentWindow(nb->notebook.mgr, index); - Ttk_Box box = - Ttk_StickBox(Ttk_PadBox(nb->notebook.clientArea, tab->padding), - Tk_ReqWidth(window), Tk_ReqHeight(window),tab->sticky); - - Ttk_PlaceContent(nb->notebook.mgr, index, - box.x, box.y, box.width, box.height); + if (!TtkBoxEqual(nb->notebook.clientArea, cavity)) { + nb->notebook.clientArea = cavity; + if (currentIndex >= 0) { + NotebookPlaceContent(nb, currentIndex); + } + } } /* NotebookPlaceContents -- diff --git a/generic/ttk/ttkThemeInt.h b/generic/ttk/ttkThemeInt.h index 3aaada8..cd95ebe 100644 --- a/generic/ttk/ttkThemeInt.h +++ b/generic/ttk/ttkThemeInt.h @@ -39,4 +39,6 @@ MODULE_SCOPE Ttk_LayoutTemplate Ttk_FindLayoutTemplate( MODULE_SCOPE const char *Ttk_StyleName(Ttk_Style); +MODULE_SCOPE int TtkBoxEqual(Ttk_Box, Ttk_Box); + #endif /* _TTKTHEMEINT */ diff --git a/tests/ttk/notebook.test b/tests/ttk/notebook.test index eae7612..8b03314 100644 --- a/tests/ttk/notebook.test +++ b/tests/ttk/notebook.test @@ -524,4 +524,18 @@ test notebook-1343984-2 "don't autoselect on destroy" -body { set ::history } -result [list DESTROY .nb.frame1 DESTROY .nb.frame2 DESTROY .nb.frame3] +test notebook-198376af5a {moving tab position to a different edge} -body { + destroy .nb + ttk::notebook .nb -width 200 -height 100 -padding 0 + ttk::frame .nb.f1 + ttk::frame .nb.f2 + .nb add .nb.f1 -text "One" + .nb add .nb.f2 -text "Two" + pack .nb + update + ttk::style configure TNotebook -tabposition s + update + expr {[winfo y .nb.f1] < 10} +} -result 1 + tcltest::cleanupTests |