diff options
Diffstat (limited to 'generic/ttk/ttkManager.c')
-rw-r--r-- | generic/ttk/ttkManager.c | 179 |
1 files changed, 62 insertions, 117 deletions
diff --git a/generic/ttk/ttkManager.c b/generic/ttk/ttkManager.c index 319e465..3c9d51c 100644 --- a/generic/ttk/ttkManager.c +++ b/generic/ttk/ttkManager.c @@ -1,8 +1,8 @@ -/* $Id: ttkManager.c,v 1.3 2007/01/11 19:59:26 jenglish Exp $ +/* $Id: ttkManager.c,v 1.4 2007/06/09 21:45:44 jenglish Exp $ * * Copyright 2005, Joe English. Freely redistributable. * - * Ttk widget set: support routines for geometry managers. + * Support routines for geometry managers. */ #include <string.h> @@ -41,19 +41,38 @@ * in this case Tk does _not_ call the LostSlaveProc (documented behavior). * Tk doesn't handle case (3) either; to account for that we * register an event handler on the slave widget to track <Destroy> events. - * */ -/* ++ manager->flags bits: +/* ++ Data structures. */ -#define MGR_UPDATE_PENDING 0x1 -#define MGR_RESIZE_REQUIRED 0x2 -#define MGR_RELAYOUT_REQUIRED 0x4 +typedef struct +{ + Tk_Window slaveWindow; + Ttk_Manager *manager; + void *slaveData; + unsigned flags; +} Ttk_Slave; -/* ++ slave->flags bits: +/* slave->flags bits: */ #define SLAVE_MAPPED 0x1 /* slave to be mapped when master is */ +struct TtkManager_ +{ + Ttk_ManagerSpec *managerSpec; + void *managerData; + Tk_Window masterWindow; + unsigned flags; + int nSlaves; + Ttk_Slave **slaves; +}; + +/* manager->flags bits: + */ +#define MGR_UPDATE_PENDING 0x1 +#define MGR_RESIZE_REQUIRED 0x2 +#define MGR_RELAYOUT_REQUIRED 0x4 + static void ManagerIdleProc(void *); /* forward */ /* ++ ScheduleUpdate -- @@ -103,7 +122,7 @@ static void ManagerIdleProc(ClientData clientData) if (mgr->flags & MGR_RESIZE_REQUIRED) { RecomputeSize(mgr); - } + } if (mgr->flags & MGR_RELAYOUT_REQUIRED) { if (mgr->flags & MGR_UPDATE_PENDING) { /* RecomputeSize has scheduled another update; relayout later */ @@ -127,7 +146,7 @@ static void ManagerEventHandler(ClientData clientData, XEvent *eventPtr) Ttk_Manager *mgr = clientData; int i; - switch (eventPtr->type) + switch (eventPtr->type) { case ConfigureNotify: RecomputeLayout(mgr); @@ -159,7 +178,7 @@ static void SlaveEventHandler(ClientData clientData, XEvent *eventPtr) Ttk_Slave *slave = clientData; if (eventPtr->type == DestroyNotify) { slave->manager->managerSpec->tkGeomMgr.lostSlaveProc( - clientData, slave->slaveWindow); + slave->manager, slave->slaveWindow); } } @@ -167,40 +186,21 @@ static void SlaveEventHandler(ClientData clientData, XEvent *eventPtr) * +++ Slave initialization and cleanup. */ -static Ttk_Slave *CreateSlave( - Tcl_Interp *interp, Ttk_Manager *mgr, Tk_Window slaveWindow) +static Ttk_Slave *NewSlave( + Ttk_Manager *mgr, Tk_Window slaveWindow, void *slaveData) { Ttk_Slave *slave = (Ttk_Slave*)ckalloc(sizeof(*slave)); - int status; slave->slaveWindow = slaveWindow; slave->manager = mgr; slave->flags = 0; - slave->slaveData = ckalloc(mgr->managerSpec->slaveSize); - memset(slave->slaveData, 0, mgr->managerSpec->slaveSize); - - if (!mgr->slaveOptionTable) { - mgr->slaveOptionTable = - Tk_CreateOptionTable(interp, mgr->managerSpec->slaveOptionSpecs); - } - - status = Tk_InitOptions( - interp, slave->slaveData, mgr->slaveOptionTable, slaveWindow); - - if (status != TCL_OK) { - ckfree((ClientData)slave->slaveData); - ckfree((ClientData)slave); - return NULL; - } + slave->slaveData = slaveData; return slave; } static void DeleteSlave(Ttk_Slave *slave) { - Tk_FreeConfigOptions( - slave->slaveData, slave->manager->slaveOptionTable, slave->slaveWindow); - ckfree((ClientData)slave->slaveData); ckfree((ClientData)slave); } @@ -216,7 +216,6 @@ Ttk_Manager *Ttk_CreateManager( mgr->managerSpec = managerSpec; mgr->managerData = managerData; mgr->masterWindow = masterWindow; - mgr->slaveOptionTable= 0; mgr->nSlaves = 0; mgr->slaves = NULL; mgr->flags = 0; @@ -238,9 +237,6 @@ void Ttk_DeleteManager(Ttk_Manager *mgr) if (mgr->slaves) { ckfree((ClientData)mgr->slaves); } - if (mgr->slaveOptionTable) { - Tk_DeleteOptionTable(mgr->slaveOptionTable); - } Tk_CancelIdleCall(ManagerIdleProc, mgr); @@ -268,7 +264,7 @@ static void InsertSlave(Ttk_Manager *mgr, Ttk_Slave *slave, int index) mgr->slaves[index] = slave; Tk_ManageGeometry(slave->slaveWindow, - &mgr->managerSpec->tkGeomMgr, (ClientData)slave); + &mgr->managerSpec->tkGeomMgr, (ClientData)mgr); Tk_CreateEventHandler(slave->slaveWindow, SlaveEventMask, SlaveEventHandler, (ClientData)slave); @@ -281,7 +277,7 @@ static void InsertSlave(Ttk_Manager *mgr, Ttk_Slave *slave, int index) * * NOTES/ASSUMPTIONS: * - * [1] It's safe to call Tk_UnmapWindow / Tk_UnmaintainGeometry even if this + * [1] It's safe to call Tk_UnmapWindow / Tk_UnmaintainGeometry even if this * routine is called from the slave's DestroyNotify event handler. */ static void RemoveSlave(Ttk_Manager *mgr, int index) @@ -320,85 +316,31 @@ static void RemoveSlave(Ttk_Manager *mgr, int index) void Ttk_GeometryRequestProc(ClientData clientData, Tk_Window slaveWindow) { - Ttk_Slave *slave = clientData; - ScheduleUpdate(slave->manager, MGR_RESIZE_REQUIRED); + Ttk_Manager *mgr = clientData; + ScheduleUpdate(mgr, MGR_RESIZE_REQUIRED); } void Ttk_LostSlaveProc(ClientData clientData, Tk_Window slaveWindow) { - Ttk_Slave *slave = clientData; - int index = Ttk_SlaveIndex(slave->manager, slave->slaveWindow); + Ttk_Manager *mgr = clientData; + int index = Ttk_SlaveIndex(mgr, slaveWindow); /* ASSERT: index >= 0 */ - RemoveSlave(slave->manager, index); + RemoveSlave(mgr, index); } /*------------------------------------------------------------------------ * +++ Public API. */ -/* ++ Ttk_AddSlave -- - * Create and configure new slave window, insert at specified index. - * - * Returns: - * TCL_OK or TCL_ERROR; in the case of TCL_ERROR, the slave - * is not added and an error message is left in interp. +/* ++ Ttk_InsertSlave -- + * Add a new slave window at the specified index. */ -int Ttk_AddSlave( - Tcl_Interp *interp, Ttk_Manager *mgr, Tk_Window slaveWindow, - int index, int objc, Tcl_Obj *CONST objv[]) +void Ttk_InsertSlave( + Ttk_Manager *mgr, int index, Tk_Window tkwin, void *slaveData) { - Ttk_Slave *slave; - - /* Sanity-checks: - */ - if (!Ttk_Maintainable(interp, slaveWindow, mgr->masterWindow)) { - return TCL_ERROR; - } - if (Ttk_SlaveIndex(mgr, slaveWindow) >= 0) { - Tcl_AppendResult(interp, - Tk_PathName(slaveWindow), " already added", - NULL); - return TCL_ERROR; - } - - /* Create, configure, and insert slave: - */ - slave = CreateSlave(interp, mgr, slaveWindow); - if (Ttk_ConfigureSlave(interp, mgr, slave, objc, objv) != TCL_OK) { - DeleteSlave(slave); - return TCL_ERROR; - } + Ttk_Slave *slave = NewSlave(mgr, tkwin, slaveData); InsertSlave(mgr, slave, index); - mgr->managerSpec->SlaveAdded(mgr, index); - return TCL_OK; -} - -/* ++ Ttk_ConfigureSlave -- - */ -int Ttk_ConfigureSlave( - Tcl_Interp *interp, Ttk_Manager *mgr, Ttk_Slave *slave, - int objc, Tcl_Obj *CONST objv[]) -{ - Tk_SavedOptions savedOptions; - int mask = 0; - - /* ASSERT: mgr->slaveOptionTable != NULL */ - - if (Tk_SetOptions(interp, slave->slaveData, mgr->slaveOptionTable, - objc, objv, slave->slaveWindow, &savedOptions, &mask) != TCL_OK) - { - return TCL_ERROR; - } - - if (mgr->managerSpec->SlaveConfigured(interp,mgr,slave,mask) != TCL_OK) { - Tk_RestoreSavedOptions(&savedOptions); - return TCL_ERROR; - } - - Tk_FreeSavedOptions(&savedOptions); - ScheduleUpdate(mgr, MGR_RELAYOUT_REQUIRED); - return TCL_OK; } /* ++ Ttk_ForgetSlave -- @@ -437,7 +379,7 @@ void Ttk_UnmapSlave(Ttk_Manager *mgr, int slaveIndex) Ttk_Slave *slave = mgr->slaves[slaveIndex]; Tk_UnmaintainGeometry(slave->slaveWindow, mgr->masterWindow); slave->flags &= ~SLAVE_MAPPED; - /* Contrary to documentation, Tk_UnmaintainGeometry doesn't always + /* Contrary to documentation, Tk_UnmaintainGeometry doesn't always * unmap the slave: */ Tk_UnmapWindow(slave->slaveWindow); @@ -458,9 +400,13 @@ void Ttk_ManagerSizeChanged(Ttk_Manager *mgr) /* +++ Accessors. */ -int Ttk_NumberSlaves(Ttk_Manager *mgr) +int Ttk_NumberSlaves(Ttk_Manager *mgr) { - return mgr->nSlaves; + return mgr->nSlaves; +} +void *Ttk_ManagerData(Ttk_Manager *mgr) +{ + return mgr->managerData; } void *Ttk_SlaveData(Ttk_Manager *mgr, int slaveIndex) { @@ -487,17 +433,16 @@ int Ttk_SlaveIndex(Ttk_Manager *mgr, Tk_Window slaveWindow) return -1; } -/* ++ Ttk_GetSlaveFromObj(interp, mgr, objPtr, indexPtr) -- +/* ++ Ttk_GetSlaveIndexFromObj(interp, mgr, objPtr, indexPtr) -- * Return the index of the slave specified by objPtr. * Slaves may be specified as an integer index or * as the name of the managed window. * * Returns: - * Pointer to slave; stores slave index in *indexPtr. - * On error, returns NULL and leaves an error message in interp. + * Standard Tcl completion code. Leaves an error message in case of error. */ -Ttk_Slave *Ttk_GetSlaveFromObj( +int Ttk_GetSlaveIndexFromObj( Tcl_Interp *interp, Ttk_Manager *mgr, Tcl_Obj *objPtr, int *indexPtr) { const char *string = Tcl_GetString(objPtr); @@ -512,10 +457,10 @@ Ttk_Slave *Ttk_GetSlaveFromObj( Tcl_AppendResult(interp, "Slave index ", Tcl_GetString(objPtr), " out of bounds", NULL); - return NULL; + return TCL_ERROR; } *indexPtr = slaveIndex; - return mgr->slaves[slaveIndex]; + return TCL_OK; } /* Try interpreting as a slave window name; @@ -529,15 +474,15 @@ Ttk_Slave *Ttk_GetSlaveFromObj( Tcl_AppendResult(interp, string, " is not managed by ", Tk_PathName(mgr->masterWindow), NULL); - return NULL; + return TCL_ERROR; } *indexPtr = slaveIndex; - return mgr->slaves[slaveIndex]; + return TCL_OK; } Tcl_ResetResult(interp); Tcl_AppendResult(interp, "Invalid slave specification ", string, NULL); - return NULL; + return TCL_ERROR; } /* ++ Ttk_ReorderSlave(mgr, fromIndex, toIndex) -- @@ -569,7 +514,7 @@ void Ttk_ReorderSlave(Ttk_Manager *mgr, int fromIndex, int toIndex) /* ++ Ttk_Maintainable(interp, slave, master) -- * Utility routine. Verifies that 'master' may be used to maintain * the geometry of 'slave' via Tk_MaintainGeometry: - * + * * + 'master' is either 'slave's parent -OR- * + 'master is a descendant of 'slave's parent. * + 'slave' is not a toplevel window @@ -596,7 +541,7 @@ int Ttk_Maintainable(Tcl_Interp *interp, Tk_Window slave, Tk_Window master) return 1; badWindow: - Tcl_AppendResult(interp, + Tcl_AppendResult(interp, "can't add ", Tk_PathName(slave), " as slave of ", Tk_PathName(master), NULL); |