summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjenglish <jenglish@flightlab.com>2007-10-25 22:52:41 (GMT)
committerjenglish <jenglish@flightlab.com>2007-10-25 22:52:41 (GMT)
commit2cd3d962db7f314e1251de41c7b4c100e64768d5 (patch)
tree0259777da74c40461c81c39da638bcf127999148
parent74c0382ad182c608bc1418a8da6bbc6a368cf801 (diff)
downloadtk-2cd3d962db7f314e1251de41c7b4c100e64768d5.zip
tk-2cd3d962db7f314e1251de41c7b4c100e64768d5.tar.gz
tk-2cd3d962db7f314e1251de41c7b4c100e64768d5.tar.bz2
ttk::notebook: reworked [$nb insert] logic (fixes multiple bugs; see #1817596)
-rw-r--r--ChangeLog4
-rw-r--r--generic/ttk/ttkNotebook.c66
-rw-r--r--tests/ttk/notebook.test31
3 files changed, 67 insertions, 34 deletions
diff --git a/ChangeLog b/ChangeLog
index 0bcb683..4bd610e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2007-10-25 Joe English <jenglish@users.sourceforge.net>
+
+ * generic/ttk/ttkNotebook.c: [Bug 1817596].
+
2007-10-25 Jeff Hobbs <jeffh@ActiveState.com>
* doc/getOpenFile.n: TIP#242 implementation of -typevariable to
diff --git a/generic/ttk/ttkNotebook.c b/generic/ttk/ttkNotebook.c
index a90f465..2304774 100644
--- a/generic/ttk/ttkNotebook.c
+++ b/generic/ttk/ttkNotebook.c
@@ -1,4 +1,4 @@
-/* $Id: ttkNotebook.c,v 1.9 2007/06/09 21:45:44 jenglish Exp $
+/* $Id: ttkNotebook.c,v 1.10 2007/10/25 22:52:41 jenglish Exp $
* Copyright (c) 2004, Joe English
*
* NOTE-ACTIVE: activeTabIndex is not always correct (it's
@@ -688,7 +688,9 @@ static void TabRemoved(Ttk_Manager *mgr, int index)
TtkRedisplayWidget(&nb->core);
}
-
+/* AddTab --
+ * Add new tab at specified index.
+ */
static int AddTab(
Tcl_Interp *interp, Notebook *nb,
int destIndex, Tk_Window slaveWindow,
@@ -717,6 +719,15 @@ static int AddTab(
}
Ttk_InsertSlave(nb->notebook.mgr, destIndex, slaveWindow, tab);
+
+ /* Adjust indices and/or autoselect first tab:
+ */
+ if (nb->notebook.currentIndex < 0) {
+ SelectTab(nb, destIndex);
+ } else if (nb->notebook.currentIndex >= destIndex) {
+ ++nb->notebook.currentIndex;
+ }
+
return TCL_OK;
}
@@ -859,13 +870,6 @@ static int NotebookAddCommand(
return TCL_ERROR;
}
- /* If no tab is currently selected (or if this is the first tab),
- * select this one:
- */
- if (nb->notebook.currentIndex < 0) {
- SelectTab(nb, index);
- }
-
TtkResizeWidget(&nb->core);
return TCL_OK;
@@ -881,7 +885,6 @@ static int NotebookInsertCommand(
int current = nb->notebook.currentIndex;
int nSlaves = Ttk_NumberSlaves(nb->notebook.mgr);
int srcIndex, destIndex;
- int status = TCL_OK;
if (objc < 4) {
Tcl_WrongNumArgs(interp, 2,objv, "index slave ?options...?");
@@ -895,29 +898,35 @@ static int NotebookInsertCommand(
return TCL_ERROR;
}
- if (TCL_OK != Ttk_GetSlaveIndexFromObj(
- interp, nb->notebook.mgr, objv[3], &srcIndex))
- {
- /* Try adding new slave:
+ if (Tcl_GetString(objv[3])[0] == '.') {
+ /* Window name -- could be new or existing slave.
*/
Tk_Window slaveWindow =
Tk_NameToWindow(interp,Tcl_GetString(objv[3]),nb->core.tkwin);
- /* Check validity.
- */
if (!slaveWindow) {
return TCL_ERROR;
}
- if (TCL_OK != AddTab(interp,nb,destIndex,slaveWindow,objc-4,objv+4)) {
- return TCL_ERROR;
- }
- if (nb->notebook.currentIndex >= destIndex) {
- ++nb->notebook.currentIndex;
+
+ srcIndex = Ttk_SlaveIndex(nb->notebook.mgr, slaveWindow);
+ if (srcIndex < 0) { /* New slave */
+ return AddTab(interp, nb, destIndex, slaveWindow, objc-4,objv+4);
}
- return TCL_OK;
+ } else if (Ttk_GetSlaveIndexFromObj(
+ interp, nb->notebook.mgr, objv[3], &srcIndex) != TCL_OK)
+ {
+ return TCL_ERROR;
}
- /* else - move existing slave: */
+ /* Move existing slave:
+ */
+ if (ConfigureTab(interp, nb,
+ Ttk_SlaveData(nb->notebook.mgr,srcIndex),
+ Ttk_SlaveWindow(nb->notebook.mgr,srcIndex),
+ objc-4,objv+4) != TCL_OK)
+ {
+ return TCL_ERROR;
+ }
if (destIndex >= nSlaves) {
destIndex = nSlaves - 1;
@@ -935,16 +944,9 @@ static int NotebookInsertCommand(
--nb->notebook.currentIndex;
}
- if (objc > 4) {
- status = ConfigureTab(interp, nb,
- Ttk_SlaveData(nb->notebook.mgr,destIndex),
- Ttk_SlaveWindow(nb->notebook.mgr,destIndex),
- objc-4,objv+4);
- }
-
TtkRedisplayWidget(&nb->core);
- return status;
+ return TCL_OK;
}
/* $nb forget $item --
@@ -1300,7 +1302,7 @@ static WidgetSpec NotebookWidgetSpec =
NotebookInitialize, /* initializeProc */
NotebookCleanup, /* cleanupProc */
NotebookConfigure, /* configureProc */
- TtkNullPostConfigure, /* postConfigureProc */
+ TtkNullPostConfigure, /* postConfigureProc */
NotebookGetLayout, /* getLayoutProc */
NotebookSize, /* geometryProc */
NotebookDoLayout, /* layoutProc */
diff --git a/tests/ttk/notebook.test b/tests/ttk/notebook.test
index d4c5e4c..b07ed30 100644
--- a/tests/ttk/notebook.test
+++ b/tests/ttk/notebook.test
@@ -1,5 +1,5 @@
#
-# $Id: notebook.test,v 1.2 2007/06/09 21:45:45 jenglish Exp $
+# $Id: notebook.test,v 1.3 2007/10/25 22:52:42 jenglish Exp $
#
package require Tk 8.5
@@ -312,7 +312,6 @@ test notebook-6.11 "Hide a non-current tab > current" -setup {
lappend result [$nb index current] [winfo ismapped $nb.f2]
} -result [list 1 1 1 1]
-
#
# Insert:
#
@@ -427,4 +426,32 @@ test notebook-7.end "insert - cleanup" -body {
destroy .nb
}
+test notebook-1817596-1 "insert should autoselect first tab" -body {
+ pack [ttk::notebook .nb]
+ list \
+ [.nb insert end [ttk::label .nb.l1 -text One] -text One] \
+ [.nb select] \
+ ;
+} -result [list "" .nb.l1] -cleanup { destroy .nb }
+
+test notebook-1817596-2 "error in insert should have no effect" -body {
+ pack [ttk::notebook .nb]
+ .nb insert end [ttk::label .nb.l1]
+ .nb insert end [ttk::label .nb.l2]
+ list \
+ [catch { .nb insert .l2 0 -badoption badvalue } err] \
+ [.nb tabs] \
+} -result [list 1 [list .nb.l1 .nb.l2]] -cleanup { destroy .nb }
+
+test notebook-1817596-3 "insert/configure" -body {
+ pack [ttk::notebook .nb]
+ .nb insert end [ttk::label .nb.l0] -text "L0"
+ .nb insert end [ttk::label .nb.l1] -text "L1"
+ .nb insert end [ttk::label .nb.l2] -text "XX"
+ .nb insert 0 2 -text "L2"
+
+ list [.nb tabs] [.nb tab 0 -text] [.nb tab 1 -text] [.nb tab 2 -text]
+
+} -result [list [list .nb.l2 .nb.l0 .nb.l1] L2 L0 L1] -cleanup { destroy .nb }
+
tcltest::cleanupTests