summaryrefslogtreecommitdiffstats
path: root/generic/ttk
diff options
context:
space:
mode:
Diffstat (limited to 'generic/ttk')
-rw-r--r--generic/ttk/ttkFrame.c15
-rw-r--r--generic/ttk/ttkManager.c18
-rw-r--r--generic/ttk/ttkManager.h8
-rw-r--r--generic/ttk/ttkNotebook.c103
-rw-r--r--generic/ttk/ttkPanedwindow.c37
5 files changed, 116 insertions, 65 deletions
diff --git a/generic/ttk/ttkFrame.c b/generic/ttk/ttkFrame.c
index 58a114f..1bb0c98 100644
--- a/generic/ttk/ttkFrame.c
+++ b/generic/ttk/ttkFrame.c
@@ -1,4 +1,4 @@
-/* $Id: ttkFrame.c,v 1.9 2007/11/19 01:49:07 jenglish Exp $
+/* $Id: ttkFrame.c,v 1.10 2007/11/25 18:11:12 jenglish Exp $
* Copyright (c) 2004, Joe English
*
* ttk::frame and ttk::labelframe widgets.
@@ -482,6 +482,11 @@ static void LabelframePlaceSlaves(void *recordPtr)
}
}
+static int LabelRequest(void *managerData, int index, int width, int height)
+{
+ return 1;
+}
+
/* LabelRemoved --
* Unset the -labelwidget option.
*
@@ -489,17 +494,17 @@ static void LabelframePlaceSlaves(void *recordPtr)
* This routine is also called when the widget voluntarily forgets
* the slave in LabelframeConfigure.
*/
-static void LabelRemoved(Ttk_Manager *mgr, int slaveIndex)
+static void LabelRemoved(void *managerData, int slaveIndex)
{
- Labelframe *lframe = Ttk_ManagerData(mgr);
+ Labelframe *lframe = managerData;
lframe->label.labelWidget = 0;
}
-static Ttk_ManagerSpec LabelframeManagerSpec =
-{
+static Ttk_ManagerSpec LabelframeManagerSpec = {
{ "labelframe", Ttk_GeometryRequestProc, Ttk_LostSlaveProc },
LabelframeSize,
LabelframePlaceSlaves,
+ LabelRequest,
LabelRemoved
};
diff --git a/generic/ttk/ttkManager.c b/generic/ttk/ttkManager.c
index 3c9d51c..0df6a89 100644
--- a/generic/ttk/ttkManager.c
+++ b/generic/ttk/ttkManager.c
@@ -1,4 +1,4 @@
-/* $Id: ttkManager.c,v 1.4 2007/06/09 21:45:44 jenglish Exp $
+/* $Id: ttkManager.c,v 1.5 2007/11/25 18:11:12 jenglish Exp $
*
* Copyright 2005, Joe English. Freely redistributable.
*
@@ -287,7 +287,7 @@ static void RemoveSlave(Ttk_Manager *mgr, int index)
/* Notify manager:
*/
- mgr->managerSpec->SlaveRemoved(mgr, index);
+ mgr->managerSpec->SlaveRemoved(mgr->managerData, index);
/* Remove from array:
*/
@@ -317,7 +317,15 @@ static void RemoveSlave(Ttk_Manager *mgr, int index)
void Ttk_GeometryRequestProc(ClientData clientData, Tk_Window slaveWindow)
{
Ttk_Manager *mgr = clientData;
- ScheduleUpdate(mgr, MGR_RESIZE_REQUIRED);
+ int slaveIndex = Ttk_SlaveIndex(mgr, slaveWindow);
+ int reqWidth = Tk_ReqWidth(slaveWindow);
+ int reqHeight= Tk_ReqHeight(slaveWindow);
+
+ if (mgr->managerSpec->SlaveRequest(
+ mgr->managerData, slaveIndex, reqWidth, reqHeight))
+ {
+ ScheduleUpdate(mgr, MGR_RESIZE_REQUIRED);
+ }
}
void Ttk_LostSlaveProc(ClientData clientData, Tk_Window slaveWindow)
@@ -404,10 +412,6 @@ int Ttk_NumberSlaves(Ttk_Manager *mgr)
{
return mgr->nSlaves;
}
-void *Ttk_ManagerData(Ttk_Manager *mgr)
-{
- return mgr->managerData;
-}
void *Ttk_SlaveData(Ttk_Manager *mgr, int slaveIndex)
{
return mgr->slaves[slaveIndex]->slaveData;
diff --git a/generic/ttk/ttkManager.h b/generic/ttk/ttkManager.h
index 550fe62..7d3ac6e 100644
--- a/generic/ttk/ttkManager.h
+++ b/generic/ttk/ttkManager.h
@@ -1,4 +1,4 @@
-/* $Id: ttkManager.h,v 1.6 2007/06/09 21:45:44 jenglish Exp $
+/* $Id: ttkManager.h,v 1.7 2007/11/25 18:11:12 jenglish Exp $
*
* Copyright (c) 2005, Joe English. Freely redistributable.
*
@@ -23,13 +23,17 @@ typedef struct TtkManager_ Ttk_Manager;
* SlaveRemoved() is called immediately before a slave is removed.
* NB: the associated slave window may have been destroyed when this
* routine is called.
+ *
+ * SlaveRequest() is called when a slave requests a size change.
+ * It should return 1 if the request should propagate, 0 otherwise.
*/
typedef struct { /* Manager hooks */
Tk_GeomMgr tkGeomMgr; /* "real" Tk Geometry Manager */
int (*RequestedSize)(void *managerData, int *widthPtr, int *heightPtr);
void (*PlaceSlaves)(void *managerData);
- void (*SlaveRemoved)(Ttk_Manager *, int slaveIndex);
+ int (*SlaveRequest)(void *managerData, int slaveIndex, int w, int h);
+ void (*SlaveRemoved)(void *managerData, int slaveIndex);
} Ttk_ManagerSpec;
/*
diff --git a/generic/ttk/ttkNotebook.c b/generic/ttk/ttkNotebook.c
index 2304774..c97c30e 100644
--- a/generic/ttk/ttkNotebook.c
+++ b/generic/ttk/ttkNotebook.c
@@ -1,8 +1,5 @@
-/* $Id: ttkNotebook.c,v 1.10 2007/10/25 22:52:41 jenglish Exp $
+/* $Id: ttkNotebook.c,v 1.11 2007/11/25 18:11:12 jenglish Exp $
* Copyright (c) 2004, Joe English
- *
- * NOTE-ACTIVE: activeTabIndex is not always correct (it's
- * more trouble than it's worth to track this 100%)
*/
#include <string.h>
@@ -645,35 +642,36 @@ static int NextTab(Notebook *nb, int index)
/* SelectNearestTab --
* Handles the case where the current tab is forgotten, hidden,
- * or destroyed. Select the next available tab; or, if there is none,
- * leaves all tabs unselected.
+ * or destroyed.
+ *
+ * Unmap the current tab and schedule the next available one
+ * to be mapped at the next GM update.
*/
static void SelectNearestTab(Notebook *nb)
{
- int nextIndex = NextTab(nb, nb->notebook.currentIndex);
+ int currentIndex = nb->notebook.currentIndex;
+ int nextIndex = NextTab(nb, currentIndex);
- if (nextIndex >= 0) {
- SelectTab(nb, nextIndex);
- } else {
- /* No available tabs -- unmap current one.
- * ASSERT: this is safe to do even when the slave is being destroyed.
- */
- if (nb->notebook.currentIndex >= 0) {
- Ttk_UnmapSlave(nb->notebook.mgr, nb->notebook.currentIndex);
- TtkSendVirtualEvent(nb->core.tkwin, "NotebookTabChanged");
- }
- nb->notebook.currentIndex = -1;
+ if (currentIndex >= 0) {
+ Ttk_UnmapSlave(nb->notebook.mgr, currentIndex);
+ }
+ if (currentIndex != nextIndex) {
+ TtkSendVirtualEvent(nb->core.tkwin, "NotebookTabChanged");
}
+
+ nb->notebook.currentIndex = nextIndex;
+ Ttk_ManagerLayoutChanged(nb->notebook.mgr);
+ TtkRedisplayWidget(&nb->core);
}
/* TabRemoved -- GM SlaveRemoved hook.
* Select the next tab if the current one is being removed.
* Adjust currentIndex to account for removed slave.
*/
-static void TabRemoved(Ttk_Manager *mgr, int index)
+static void TabRemoved(void *managerData, int index)
{
- Notebook *nb = Ttk_ManagerData(mgr);
- Tab *tab = Ttk_SlaveData(mgr, index);
+ Notebook *nb = managerData;
+ Tab *tab = Ttk_SlaveData(nb->notebook.mgr, index);
if (index == nb->notebook.currentIndex) {
SelectNearestTab(nb);
@@ -688,6 +686,11 @@ static void TabRemoved(Ttk_Manager *mgr, int index)
TtkRedisplayWidget(&nb->core);
}
+static int TabRequest(void *managerData, int index, int width, int height)
+{
+ return 1;
+}
+
/* AddTab --
* Add new tab at specified index.
*/
@@ -700,12 +703,14 @@ static int AddTab(
if (!Ttk_Maintainable(interp, slaveWindow, nb->core.tkwin)) {
return TCL_ERROR;
}
+#if 0 /* can't happen */
if (Ttk_SlaveIndex(nb->notebook.mgr, slaveWindow) >= 0) {
Tcl_AppendResult(interp,
Tk_PathName(slaveWindow), " already added",
NULL);
return TCL_ERROR;
}
+#endif
/* Create and insert tab.
*/
@@ -731,12 +736,12 @@ static int AddTab(
return TCL_OK;
}
-static Ttk_ManagerSpec NotebookManagerSpec =
-{
+static Ttk_ManagerSpec NotebookManagerSpec = {
{ "notebook", Ttk_GeometryRequestProc, Ttk_LostSlaveProc },
NotebookSize,
NotebookPlaceSlaves,
- TabRemoved,
+ TabRequest,
+ TabRemoved
};
/*------------------------------------------------------------------------
@@ -853,6 +858,8 @@ static int NotebookAddCommand(
Notebook *nb = recordPtr;
int index = Ttk_NumberSlaves(nb->notebook.mgr);
Tk_Window slaveWindow;
+ int slaveIndex;
+ Tab *tab;
if (objc <= 2 || objc % 2 != 1) {
Tcl_WrongNumArgs(interp, 2, objv, "window ?options...?");
@@ -863,14 +870,21 @@ static int NotebookAddCommand(
if (!slaveWindow) {
return TCL_ERROR;
}
+ slaveIndex = Ttk_SlaveIndex(nb->notebook.mgr, slaveWindow);
- /* Create and initialize new tab:
- */
- if (AddTab(interp, nb, index, slaveWindow, objc-3,objv+3) != TCL_OK) {
+ if (slaveIndex < 0) { /* New tab */
+ return AddTab(interp, nb, index, slaveWindow, objc-3,objv+3);
+ }
+
+ tab = Ttk_SlaveData(nb->notebook.mgr, slaveIndex);
+ if (tab->state == TAB_STATE_HIDDEN) {
+ tab->state = TAB_STATE_NORMAL;
+ }
+ if (ConfigureTab(interp, nb, tab, slaveWindow, objc-4,objv+4) != TCL_OK) {
return TCL_ERROR;
}
- TtkResizeWidget(&nb->core);
+ TtkRedisplayWidget(&nb->core);
return TCL_OK;
}
@@ -949,8 +963,8 @@ static int NotebookInsertCommand(
return TCL_OK;
}
-/* $nb forget $item --
- * Removes the selected tab.
+/* $nb forget $tab --
+ * Removes the specified tab.
*/
static int NotebookForgetCommand(
Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], void *recordPtr)
@@ -972,6 +986,34 @@ static int NotebookForgetCommand(
return TCL_OK;
}
+/* $nb hide $tab --
+ * Hides the specified tab.
+ */
+static int NotebookHideCommand(
+ Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], void *recordPtr)
+{
+ Notebook *nb = recordPtr;
+ int index;
+ Tab *tab;
+
+ if (objc != 3) {
+ Tcl_WrongNumArgs(interp, 2, objv, "tab");
+ return TCL_ERROR;
+ }
+
+ if (GetTabIndex(interp, nb, objv[2], &index) != TCL_OK) {
+ return TCL_ERROR;
+ }
+
+ tab = Ttk_SlaveData(nb->notebook.mgr, index);
+ tab->state = TAB_STATE_HIDDEN;
+ if (index == nb->notebook.currentIndex) {
+ SelectNearestTab(nb);
+ }
+
+ return TCL_OK;
+}
+
/* $nb identify $x $y --
* Returns name of tab element at $x,$y; empty string if none.
*/
@@ -1153,6 +1195,7 @@ static WidgetCommandSpec NotebookCommands[] =
{ "configure", TtkWidgetConfigureCommand },
{ "cget", TtkWidgetCgetCommand },
{ "forget", NotebookForgetCommand },
+ { "hide", NotebookHideCommand },
{ "identify", NotebookIdentifyCommand },
{ "index", NotebookIndexCommand },
{ "insert", NotebookInsertCommand },
diff --git a/generic/ttk/ttkPanedwindow.c b/generic/ttk/ttkPanedwindow.c
index e961815..c9086f5 100644
--- a/generic/ttk/ttkPanedwindow.c
+++ b/generic/ttk/ttkPanedwindow.c
@@ -1,4 +1,4 @@
-/* $Id: ttkPanedwindow.c,v 1.11 2007/06/10 03:25:32 jenglish Exp $
+/* $Id: ttkPanedwindow.c,v 1.12 2007/11/25 18:11:12 jenglish Exp $
*
* Copyright (c) 2005, Joe English. Freely redistributable.
*
@@ -404,10 +404,10 @@ static void PanedPlaceSlaves(void *managerData)
PlacePanes(pw);
}
-static void PaneRemoved(Ttk_Manager *mgr, int index)
+static void PaneRemoved(void *managerData, int index)
{
- Paned *pw = Ttk_ManagerData(mgr);
- Pane *pane = Ttk_SlaveData(mgr, index);
+ Paned *pw = managerData;
+ Pane *pane = Ttk_SlaveData(pw->paned.mgr, index);
DestroyPane(pw, pane);
}
@@ -440,35 +440,30 @@ static int AddPane(
return TCL_OK;
}
-/* PanedGeometryRequestProc --
- * Update pane request size, but only if slave is currently unmapped.
- * Geometry requests from mapped slaves are not directly honored,
+/* PaneRequest --
+ * Only update pane request size if slave is currently unmapped.
+ * Geometry requests from mapped slaves are not directly honored
* in order to avoid unexpected pane resizes (esp. while the
* user is dragging a sash [#1325286]).
*/
-static void PanedGeometryRequestProc(
- ClientData clientData, Tk_Window slaveWindow)
+static int PaneRequest(void *managerData, int index, int width, int height)
{
- Ttk_Manager *mgr = clientData;
- Paned *pw = Ttk_ManagerData(mgr);
+ Paned *pw = managerData;
+ Pane *pane = Ttk_SlaveData(pw->paned.mgr, index);
+ Tk_Window slaveWindow = Ttk_SlaveWindow(pw->paned.mgr, index);
+ int horizontal = pw->paned.orient == TTK_ORIENT_HORIZONTAL;
if (!Tk_IsMapped(slaveWindow)) {
- int slaveIndex = Ttk_SlaveIndex(mgr, slaveWindow); /* ASSERT: != -1 */
- Pane *pane = Ttk_SlaveData(mgr, slaveIndex);
- pane->reqSize
- = pw->paned.orient == TTK_ORIENT_HORIZONTAL
- ? Tk_ReqWidth(slaveWindow) : Tk_ReqHeight(slaveWindow);
+ pane->reqSize = horizontal ? width : height;
}
-
- /* Continue with default GeometryRequestProc:
- */
- Ttk_GeometryRequestProc(clientData, slaveWindow);
+ return 1;
}
static Ttk_ManagerSpec PanedManagerSpec = {
- { "panedwindow", PanedGeometryRequestProc, Ttk_LostSlaveProc },
+ { "panedwindow", Ttk_GeometryRequestProc, Ttk_LostSlaveProc },
PanedSize,
PanedPlaceSlaves,
+ PaneRequest,
PaneRemoved
};