diff options
Diffstat (limited to 'generic/tkGeometry.c')
-rw-r--r-- | generic/tkGeometry.c | 117 |
1 files changed, 98 insertions, 19 deletions
diff --git a/generic/tkGeometry.c b/generic/tkGeometry.c index f6f5150..bcfdcf5 100644 --- a/generic/tkGeometry.c +++ b/generic/tkGeometry.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkGeometry.c,v 1.12 2007/12/13 15:24:14 dgp Exp $ + * RCS: @(#) $Id: tkGeometry.c,v 1.16 2010/11/19 14:48:00 nijtmans Exp $ */ #include "tkInt.h" @@ -86,7 +86,7 @@ void Tk_ManageGeometry( Tk_Window tkwin, /* Window whose geometry is to be managed by * proc. */ - CONST Tk_GeomMgr *mgrPtr, /* Static structure describing the geometry + const Tk_GeomMgr *mgrPtr, /* Static structure describing the geometry * manager. This structure must never go * away. */ ClientData clientData) /* Arbitrary one-word argument to pass to @@ -98,7 +98,7 @@ Tk_ManageGeometry( && ((winPtr->geomMgrPtr != mgrPtr) || (winPtr->geomData != clientData)) && (winPtr->geomMgrPtr->lostSlaveProc != NULL)) { - (*winPtr->geomMgrPtr->lostSlaveProc)(winPtr->geomData, tkwin); + winPtr->geomMgrPtr->lostSlaveProc(winPtr->geomData, tkwin); } winPtr->geomMgrPtr = mgrPtr; @@ -154,7 +154,7 @@ Tk_GeometryRequest( winPtr->reqHeight = reqHeight; if ((winPtr->geomMgrPtr != NULL) && (winPtr->geomMgrPtr->requestProc != NULL)) { - (*winPtr->geomMgrPtr->requestProc)(winPtr->geomData, tkwin); + winPtr->geomMgrPtr->requestProc(winPtr->geomData, tkwin); } } @@ -306,6 +306,85 @@ Tk_SetMinimumRequestSize( /* *---------------------------------------------------------------------- * + * TkSetGeometryMaster -- + * + * Set a geometry master for this window. Only one master may own + * a window at any time. + * + * Results: + * A standard Tcl result. + * + * Side effects: + * The geometry master is recorded for the window. + * + *---------------------------------------------------------------------- + */ + +int +TkSetGeometryMaster( + Tcl_Interp *interp, /* Current interpreter, for error. */ + Tk_Window tkwin, /* Window that will have geometry master set. */ + const char *master) /* The master identity. */ +{ + register TkWindow *winPtr = (TkWindow *) tkwin; + + if (winPtr->geometryMaster != NULL && + strcmp(winPtr->geometryMaster, master) == 0) { + return TCL_OK; + } + if (winPtr->geometryMaster != NULL) { + if (interp != NULL) { + Tcl_AppendResult(interp, "cannot use geometry manager ", master, + " inside ", Tk_PathName(tkwin), + " which already has slaves managed by ", + winPtr->geometryMaster, NULL); + } + return TCL_ERROR; + } + + winPtr->geometryMaster = ckalloc(strlen(master) + 1); + strcpy(winPtr->geometryMaster, master); + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * + * TkFreeGeometryMaster -- + * + * Remove a geometry master for this window. Only one master may own + * a window at any time. + * + * Results: + * None. + * + * Side effects: + * The geometry master is cleared for the window. + * + *---------------------------------------------------------------------- + */ + +void +TkFreeGeometryMaster( + Tk_Window tkwin, /* Window that will have geometry master cleared. */ + const char *master) /* The master identity. */ +{ + register TkWindow *winPtr = (TkWindow *) tkwin; + + if (winPtr->geometryMaster != NULL && + strcmp(winPtr->geometryMaster, master) != 0) { + Tcl_Panic("Trying to free %s from geometry manager %s", + winPtr->geometryMaster, master); + } + if (winPtr->geometryMaster != NULL) { + ckfree(winPtr->geometryMaster); + winPtr->geometryMaster = NULL; + } +} + +/* + *---------------------------------------------------------------------- + * * Tk_MaintainGeometry -- * * This procedure is invoked by geometry managers to handle slaves whose @@ -381,9 +460,9 @@ Tk_MaintainGeometry( hPtr = Tcl_CreateHashEntry(&dispPtr->maintainHashTable, (char *) master, &isNew); if (!isNew) { - masterPtr = (MaintainMaster *) Tcl_GetHashValue(hPtr); + masterPtr = Tcl_GetHashValue(hPtr); } else { - masterPtr = (MaintainMaster *) ckalloc(sizeof(MaintainMaster)); + masterPtr = ckalloc(sizeof(MaintainMaster)); masterPtr->ancestor = master; masterPtr->checkScheduled = 0; masterPtr->slavePtr = NULL; @@ -401,13 +480,13 @@ Tk_MaintainGeometry( goto gotSlave; } } - slavePtr = (MaintainSlave *) ckalloc(sizeof(MaintainSlave)); + slavePtr = ckalloc(sizeof(MaintainSlave)); slavePtr->slave = slave; slavePtr->master = master; slavePtr->nextPtr = masterPtr->slavePtr; masterPtr->slavePtr = slavePtr; Tk_CreateEventHandler(slave, StructureNotifyMask, MaintainSlaveProc, - (ClientData) slavePtr); + slavePtr); /* * Make sure that there are event handlers registered for all the windows @@ -420,7 +499,7 @@ Tk_MaintainGeometry( ancestor = Tk_Parent(ancestor)) { if (ancestor == masterPtr->ancestor) { Tk_CreateEventHandler(ancestor, StructureNotifyMask, - MaintainMasterProc, (ClientData) masterPtr); + MaintainMasterProc, masterPtr); masterPtr->ancestor = Tk_Parent(ancestor); } } @@ -511,7 +590,7 @@ Tk_UnmaintainGeometry( if (hPtr == NULL) { return; } - masterPtr = (MaintainMaster *) Tcl_GetHashValue(hPtr); + masterPtr = Tcl_GetHashValue(hPtr); slavePtr = masterPtr->slavePtr; if (slavePtr->slave == slave) { masterPtr->slavePtr = slavePtr->nextPtr; @@ -528,23 +607,23 @@ Tk_UnmaintainGeometry( } } Tk_DeleteEventHandler(slavePtr->slave, StructureNotifyMask, - MaintainSlaveProc, (ClientData) slavePtr); - ckfree((char *) slavePtr); + MaintainSlaveProc, slavePtr); + ckfree(slavePtr); if (masterPtr->slavePtr == NULL) { if (masterPtr->ancestor != NULL) { for (ancestor = master; ; ancestor = Tk_Parent(ancestor)) { Tk_DeleteEventHandler(ancestor, StructureNotifyMask, - MaintainMasterProc, (ClientData) masterPtr); + MaintainMasterProc, masterPtr); if (ancestor == masterPtr->ancestor) { break; } } } if (masterPtr->checkScheduled) { - Tcl_CancelIdleCall(MaintainCheckProc, (ClientData) masterPtr); + Tcl_CancelIdleCall(MaintainCheckProc, masterPtr); } Tcl_DeleteHashEntry(hPtr); - ckfree((char *) masterPtr); + ckfree(masterPtr); } } @@ -575,7 +654,7 @@ MaintainMasterProc( * master window. */ XEvent *eventPtr) /* Describes what just happened. */ { - MaintainMaster *masterPtr = (MaintainMaster *) clientData; + MaintainMaster *masterPtr = clientData; MaintainSlave *slavePtr; int done; @@ -584,7 +663,7 @@ MaintainMasterProc( || (eventPtr->type == UnmapNotify)) { if (!masterPtr->checkScheduled) { masterPtr->checkScheduled = 1; - Tcl_DoWhenIdle(MaintainCheckProc, (ClientData) masterPtr); + Tcl_DoWhenIdle(MaintainCheckProc, masterPtr); } } else if (eventPtr->type == DestroyNotify) { /* @@ -629,7 +708,7 @@ MaintainSlaveProc( * master-slave pair. */ XEvent *eventPtr) /* Describes what just happened. */ { - MaintainSlave *slavePtr = (MaintainSlave *) clientData; + MaintainSlave *slavePtr = clientData; if (eventPtr->type == DestroyNotify) { Tk_UnmaintainGeometry(slavePtr->slave, slavePtr->master); @@ -661,7 +740,7 @@ MaintainCheckProc( ClientData clientData) /* Pointer to MaintainMaster structure for the * master window. */ { - MaintainMaster *masterPtr = (MaintainMaster *) clientData; + MaintainMaster *masterPtr = clientData; MaintainSlave *slavePtr; Tk_Window ancestor, parent; int x, y, map; |