diff options
Diffstat (limited to 'generic/tkPlace.c')
-rw-r--r-- | generic/tkPlace.c | 112 |
1 files changed, 55 insertions, 57 deletions
diff --git a/generic/tkPlace.c b/generic/tkPlace.c index 951cd8f..c7f3a89 100644 --- a/generic/tkPlace.c +++ b/generic/tkPlace.c @@ -24,7 +24,7 @@ * actual window size. */ -static char *borderModeStrings[] = { +static const char *const borderModeStrings[] = { "inside", "outside", "ignore", NULL }; @@ -172,7 +172,7 @@ static void SlaveStructureProc(ClientData clientData, XEvent *eventPtr); static int ConfigureSlave(Tcl_Interp *interp, Tk_Window tkwin, Tk_OptionTable table, int objc, - Tcl_Obj *CONST objv[]); + Tcl_Obj *const objv[]); static int PlaceInfoCommand(Tcl_Interp *interp, Tk_Window tkwin); static Slave * CreateSlave(Tk_Window tkwin, Tk_OptionTable table); static void FreeSlave(Slave *slavePtr); @@ -203,17 +203,17 @@ static void UnlinkSlave(Slave *slavePtr); int Tk_PlaceObjCmd( - ClientData clientData, /* NULL. */ + ClientData clientData, /* Interpreter main window. */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ - Tcl_Obj *CONST objv[]) /* Argument objects. */ + Tcl_Obj *const objv[]) /* Argument objects. */ { + Tk_Window main_win = clientData; Tk_Window tkwin; Slave *slavePtr; - char *string; TkDisplay *dispPtr; Tk_OptionTable optionTable; - static CONST char *optionStrings[] = { + static const char *const optionStrings[] = { "configure", "forget", "info", "slaves", NULL }; enum options { PLACE_CONFIGURE, PLACE_FORGET, PLACE_INFO, PLACE_SLAVES }; @@ -235,10 +235,9 @@ Tk_PlaceObjCmd( * Handle special shortcut where window name is first argument. */ - string = Tcl_GetString(objv[1]); - if (string[0] == '.') { - tkwin = Tk_NameToWindow(interp, string, Tk_MainWindow(interp)); - if (tkwin == NULL) { + if (Tcl_GetString(objv[1])[0] == '.') { + if (TkGetWindowFromObj(interp, main_win, objv[1], + &tkwin) != TCL_OK) { return TCL_ERROR; } @@ -261,9 +260,8 @@ Tk_PlaceObjCmd( * possible additional arguments. */ - tkwin = Tk_NameToWindow(interp, Tcl_GetString(objv[2]), - Tk_MainWindow(interp)); - if (tkwin == NULL) { + if (TkGetWindowFromObj(interp, main_win, objv[2], + &tkwin) != TCL_OK) { return TCL_ERROR; } @@ -319,8 +317,8 @@ Tk_PlaceObjCmd( Tcl_DeleteHashEntry(Tcl_FindHashEntry(&dispPtr->slaveTable, (char *) tkwin)); Tk_DeleteEventHandler(tkwin, StructureNotifyMask, SlaveStructureProc, - (ClientData) slavePtr); - Tk_ManageGeometry(tkwin, NULL, (ClientData) NULL); + slavePtr); + Tk_ManageGeometry(tkwin, NULL, NULL); Tk_UnmapWindow(tkwin); FreeSlave(slavePtr); break; @@ -346,7 +344,7 @@ Tk_PlaceObjCmd( for (slavePtr = masterPtr->slavePtr; slavePtr != NULL; slavePtr = slavePtr->nextPtr) { Tcl_ListObjAppendElement(interp, listPtr, - Tcl_NewStringObj(Tk_PathName(slavePtr->tkwin),-1)); + TkNewWindowObj(slavePtr->tkwin)); } Tcl_SetObjResult(interp, listPtr); } @@ -386,7 +384,7 @@ CreateSlave( hPtr = Tcl_CreateHashEntry(&dispPtr->slaveTable, (char *) tkwin, &isNew); if (!isNew) { - return (Slave *) Tcl_GetHashValue(hPtr); + return Tcl_GetHashValue(hPtr); } /* @@ -394,7 +392,7 @@ CreateSlave( * populate it with some default values. */ - slavePtr = (Slave *) ckalloc(sizeof(Slave)); + slavePtr = ckalloc(sizeof(Slave)); memset(slavePtr, 0, sizeof(Slave)); slavePtr->tkwin = tkwin; slavePtr->inTkwin = None; @@ -403,7 +401,7 @@ CreateSlave( slavePtr->optionTable = table; Tcl_SetHashValue(hPtr, slavePtr); Tk_CreateEventHandler(tkwin, StructureNotifyMask, SlaveStructureProc, - (ClientData) slavePtr); + slavePtr); return slavePtr; } @@ -429,7 +427,7 @@ FreeSlave( { Tk_FreeConfigOptions((char *) slavePtr, slavePtr->optionTable, slavePtr->tkwin); - ckfree((char *) slavePtr); + ckfree(slavePtr); } /* @@ -454,16 +452,14 @@ static Slave * FindSlave( Tk_Window tkwin) /* Token for desired slave. */ { - Tcl_HashEntry *hPtr; - register Slave *slavePtr; + register Tcl_HashEntry *hPtr; TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr; hPtr = Tcl_FindHashEntry(&dispPtr->slaveTable, (char *) tkwin); if (hPtr == NULL) { return NULL; } - slavePtr = (Slave *) Tcl_GetHashValue(hPtr); - return slavePtr; + return Tcl_GetHashValue(hPtr); } /* @@ -507,7 +503,7 @@ UnlinkSlave( } } } - + if (masterPtr->abortPtr != NULL) { *masterPtr->abortPtr = 1; } @@ -542,16 +538,16 @@ CreateMaster( hPtr = Tcl_CreateHashEntry(&dispPtr->masterTable, (char *) tkwin, &isNew); if (isNew) { - masterPtr = (Master *) ckalloc(sizeof(Master)); + masterPtr = ckalloc(sizeof(Master)); masterPtr->tkwin = tkwin; masterPtr->slavePtr = NULL; masterPtr->abortPtr = NULL; masterPtr->flags = 0; Tcl_SetHashValue(hPtr, masterPtr); Tk_CreateEventHandler(masterPtr->tkwin, StructureNotifyMask, - MasterStructureProc, (ClientData) masterPtr); + MasterStructureProc, masterPtr); } else { - masterPtr = (Master *) Tcl_GetHashValue(hPtr); + masterPtr = Tcl_GetHashValue(hPtr); } return masterPtr; } @@ -579,16 +575,14 @@ static Master * FindMaster( Tk_Window tkwin) /* Token for desired master. */ { - Tcl_HashEntry *hPtr; - register Master *masterPtr; + register Tcl_HashEntry *hPtr; TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr; hPtr = Tcl_FindHashEntry(&dispPtr->masterTable, (char *) tkwin); if (hPtr == NULL) { return NULL; } - masterPtr = (Master *) Tcl_GetHashValue(hPtr); - return masterPtr; + return Tcl_GetHashValue(hPtr); } /* @@ -616,7 +610,7 @@ ConfigureSlave( Tk_Window tkwin, /* Token for the window to manipulate. */ Tk_OptionTable table, /* Token for option table. */ int objc, /* Number of config arguments. */ - Tcl_Obj *CONST objv[]) /* Object values for arguments. */ + Tcl_Obj *const objv[]) /* Object values for arguments. */ { register Master *masterPtr; Tk_SavedOptions savedOptions; @@ -730,7 +724,7 @@ ConfigureSlave( slavePtr->masterPtr = masterPtr; slavePtr->nextPtr = masterPtr->slavePtr; masterPtr->slavePtr = slavePtr; - Tk_ManageGeometry(slavePtr->tkwin, &placerType, (ClientData) slavePtr); + Tk_ManageGeometry(slavePtr->tkwin, &placerType, slavePtr); /* * Arrange for the master to be re-arranged at the first idle moment. @@ -741,7 +735,7 @@ ConfigureSlave( if (!(masterPtr->flags & PARENT_RECONFIG_PENDING)) { masterPtr->flags |= PARENT_RECONFIG_PENDING; - Tcl_DoWhenIdle(RecomputePlacement, (ClientData) masterPtr); + Tcl_DoWhenIdle(RecomputePlacement, masterPtr); } return TCL_OK; @@ -849,21 +843,20 @@ static void RecomputePlacement( ClientData clientData) /* Pointer to Master record. */ { - register Master *masterPtr = (Master *) clientData; + register Master *masterPtr = clientData; register Slave *slavePtr; int x, y, width, height, tmp; int masterWidth, masterHeight, masterX, masterY; double x1, y1, x2, y2; - int abort; /* May get set to non-zero to abort this * placement operation. */ masterPtr->flags &= ~PARENT_RECONFIG_PENDING; - + /* * Abort any nested call to RecomputePlacement for this window, since - * we'll do everything necessary here, and set up so this call - * can be aborted if necessary. + * we'll do everything necessary here, and set up so this call can be + * aborted if necessary. */ if (masterPtr->abortPtr != NULL) { @@ -871,13 +864,13 @@ RecomputePlacement( } masterPtr->abortPtr = &abort; abort = 0; - Tcl_Preserve((ClientData) masterPtr); + Tcl_Preserve(masterPtr); /* * Iterate over all the slaves for the master. Each slave's geometry can * be computed independently of the other slaves. Changes to the window's * structure could cause almost anything to happen, including deleting the - * parent or child. If this happens, we'll be told to abort. + * parent or child. If this happens, we'll be told to abort. */ for (slavePtr = masterPtr->slavePtr; slavePtr != NULL && !abort; @@ -1044,7 +1037,7 @@ RecomputePlacement( } masterPtr->abortPtr = NULL; - Tcl_Release((ClientData) masterPtr); + Tcl_Release(masterPtr); } /* @@ -1071,17 +1064,19 @@ MasterStructureProc( * referred to by eventPtr. */ XEvent *eventPtr) /* Describes what just happened. */ { - register Master *masterPtr = (Master *) clientData; + register Master *masterPtr = clientData; register Slave *slavePtr, *nextPtr; TkDisplay *dispPtr = ((TkWindow *) masterPtr->tkwin)->dispPtr; - if (eventPtr->type == ConfigureNotify) { + switch (eventPtr->type) { + case ConfigureNotify: if ((masterPtr->slavePtr != NULL) && !(masterPtr->flags & PARENT_RECONFIG_PENDING)) { masterPtr->flags |= PARENT_RECONFIG_PENDING; - Tcl_DoWhenIdle(RecomputePlacement, (ClientData) masterPtr); + Tcl_DoWhenIdle(RecomputePlacement, masterPtr); } - } else if (eventPtr->type == DestroyNotify) { + return; + case DestroyNotify: for (slavePtr = masterPtr->slavePtr; slavePtr != NULL; slavePtr = nextPtr) { slavePtr->masterPtr = NULL; @@ -1091,14 +1086,15 @@ MasterStructureProc( Tcl_DeleteHashEntry(Tcl_FindHashEntry(&dispPtr->masterTable, (char *) masterPtr->tkwin)); if (masterPtr->flags & PARENT_RECONFIG_PENDING) { - Tcl_CancelIdleCall(RecomputePlacement, (ClientData) masterPtr); + Tcl_CancelIdleCall(RecomputePlacement, masterPtr); } masterPtr->tkwin = NULL; if (masterPtr->abortPtr != NULL) { *masterPtr->abortPtr = 1; } - Tcl_EventuallyFree((ClientData) masterPtr, TCL_DYNAMIC); - } else if (eventPtr->type == MapNotify) { + Tcl_EventuallyFree(masterPtr, TCL_DYNAMIC); + return; + case MapNotify: /* * When a master gets mapped, must redo the geometry computation so * that all of its slaves get remapped. @@ -1107,9 +1103,10 @@ MasterStructureProc( if ((masterPtr->slavePtr != NULL) && !(masterPtr->flags & PARENT_RECONFIG_PENDING)) { masterPtr->flags |= PARENT_RECONFIG_PENDING; - Tcl_DoWhenIdle(RecomputePlacement, (ClientData) masterPtr); + Tcl_DoWhenIdle(RecomputePlacement, masterPtr); } - } else if (eventPtr->type == UnmapNotify) { + return; + case UnmapNotify: /* * Unmap all of the slaves when the master gets unmapped, so that they * don't keep redisplaying themselves. @@ -1119,6 +1116,7 @@ MasterStructureProc( slavePtr = slavePtr->nextPtr) { Tk_UnmapWindow(slavePtr->tkwin); } + return; } } @@ -1145,7 +1143,7 @@ SlaveStructureProc( * referred to by eventPtr. */ XEvent *eventPtr) /* Describes what just happened. */ { - register Slave *slavePtr = (Slave *) clientData; + register Slave *slavePtr = clientData; TkDisplay *dispPtr = ((TkWindow *) slavePtr->tkwin)->dispPtr; if (eventPtr->type == DestroyNotify) { @@ -1182,7 +1180,7 @@ PlaceRequestProc( ClientData clientData, /* Pointer to our record for slave. */ Tk_Window tkwin) /* Window that changed its desired size. */ { - Slave *slavePtr = (Slave *) clientData; + Slave *slavePtr = clientData; Master *masterPtr; if (((slavePtr->flags & (CHILD_WIDTH|CHILD_REL_WIDTH)) != 0) @@ -1195,7 +1193,7 @@ PlaceRequestProc( } if (!(masterPtr->flags & PARENT_RECONFIG_PENDING)) { masterPtr->flags |= PARENT_RECONFIG_PENDING; - Tcl_DoWhenIdle(RecomputePlacement, (ClientData) masterPtr); + Tcl_DoWhenIdle(RecomputePlacement, masterPtr); } } @@ -1223,7 +1221,7 @@ PlaceLostSlaveProc( * stolen away. */ Tk_Window tkwin) /* Tk's handle for the slave window. */ { - register Slave *slavePtr = (Slave *) clientData; + register Slave *slavePtr = clientData; TkDisplay *dispPtr = ((TkWindow *) slavePtr->tkwin)->dispPtr; if (slavePtr->masterPtr->tkwin != Tk_Parent(slavePtr->tkwin)) { @@ -1234,7 +1232,7 @@ PlaceLostSlaveProc( Tcl_DeleteHashEntry(Tcl_FindHashEntry(&dispPtr->slaveTable, (char *) tkwin)); Tk_DeleteEventHandler(tkwin, StructureNotifyMask, SlaveStructureProc, - (ClientData) slavePtr); + slavePtr); FreeSlave(slavePtr); } |