diff options
Diffstat (limited to 'generic/ttk/ttkManager.c')
-rw-r--r-- | generic/ttk/ttkManager.c | 93 |
1 files changed, 51 insertions, 42 deletions
diff --git a/generic/ttk/ttkManager.c b/generic/ttk/ttkManager.c index 9c02a54..1ea5f54 100644 --- a/generic/ttk/ttkManager.c +++ b/generic/ttk/ttkManager.c @@ -34,9 +34,9 @@ * (2) Manager voluntarily relinquishes control * (3) Content window is destroyed * - * In case (1), Tk calls the manager's lostSlaveProc. + * In case (1), Tk calls the manager's lostContentProc. * Case (2) is performed by calling Tk_ManageGeometry(window,NULL,0); - * in this case Tk does _not_ call the lostSlaveProc (documented behavior). + * in this case Tk does _not_ call the lostContentProc (documented behavior). * Tk doesn't handle case (3) either; to account for that we * register an event handler on the content window to track <Destroy> events. */ @@ -57,11 +57,11 @@ typedef struct struct TtkManager_ { - Ttk_ManagerSpec *managerSpec; + const Ttk_ManagerSpec *managerSpec; void *managerData; Tk_Window window; unsigned flags; - int nContent; + Tcl_Size nContent; Ttk_Content **content; }; @@ -106,14 +106,14 @@ static void RecomputeSize(Ttk_Manager *mgr) */ static void RecomputeLayout(Ttk_Manager *mgr) { - mgr->managerSpec->PlaceSlaves(mgr->managerData); + mgr->managerSpec->PlaceContent(mgr->managerData); mgr->flags &= ~MGR_RELAYOUT_REQUIRED; } /* ++ ManagerIdleProc -- * DoWhenIdle procedure for deferred updates. */ -static void ManagerIdleProc(ClientData clientData) +static void ManagerIdleProc(void *clientData) { Ttk_Manager *mgr = (Ttk_Manager *)clientData; mgr->flags &= ~MGR_UPDATE_PENDING; @@ -139,10 +139,10 @@ static void ManagerIdleProc(ClientData clientData) * Keep the content's map state in sync with the container's. */ static const int ManagerEventMask = StructureNotifyMask; -static void ManagerEventHandler(ClientData clientData, XEvent *eventPtr) +static void ManagerEventHandler(void *clientData, XEvent *eventPtr) { Ttk_Manager *mgr = (Ttk_Manager *)clientData; - int i; + Tcl_Size i; switch (eventPtr->type) { @@ -174,7 +174,7 @@ static void ContentLostEventHandler(void *clientData, XEvent *eventPtr) { Ttk_Content *content = (Ttk_Content *)clientData; if (eventPtr->type == DestroyNotify) { - content->manager->managerSpec->tkGeomMgr.lostSlaveProc( + content->manager->managerSpec->tkGeomMgr.lostContentProc( content->manager, content->window); } } @@ -206,7 +206,7 @@ static void DeleteContent(Ttk_Content *content) */ Ttk_Manager *Ttk_CreateManager( - Ttk_ManagerSpec *managerSpec, void *managerData, Tk_Window window) + const Ttk_ManagerSpec *managerSpec, void *managerData, Tk_Window window) { Ttk_Manager *mgr = (Ttk_Manager *)ckalloc(sizeof(*mgr)); @@ -247,9 +247,9 @@ void Ttk_DeleteManager(Ttk_Manager *mgr) /* ++ InsertContent -- * Adds content to the list of managed windows. */ -static void InsertContent(Ttk_Manager *mgr, Ttk_Content *content, int index) +static void InsertContent(Ttk_Manager *mgr, Ttk_Content *content, Tcl_Size index) { - int endIndex = mgr->nContent++; + Tcl_Size endIndex = mgr->nContent++; mgr->content = (Ttk_Content **)ckrealloc(mgr->content, mgr->nContent * sizeof(Ttk_Content *)); while (endIndex > index) { @@ -276,14 +276,14 @@ static void InsertContent(Ttk_Manager *mgr, Ttk_Content *content, int index) * [1] It's safe to call Tk_UnmapWindow / Tk_UnmaintainGeometry even if this * routine is called from the content window's DestroyNotify event handler. */ -static void RemoveContent(Ttk_Manager *mgr, int index) +static void RemoveContent(Ttk_Manager *mgr, Tcl_Size index) { Ttk_Content *content = mgr->content[index]; - int i; + Tcl_Size i; /* Notify manager: */ - mgr->managerSpec->SlaveRemoved(mgr->managerData, index); + mgr->managerSpec->ContentRemoved(mgr->managerData, index); /* Remove from array: */ @@ -310,25 +310,25 @@ static void RemoveContent(Ttk_Manager *mgr, int index) * +++ Tk_GeomMgr hooks. */ -void Ttk_GeometryRequestProc(ClientData clientData, Tk_Window window) +void Ttk_GeometryRequestProc(void *clientData, Tk_Window window) { Ttk_Manager *mgr = (Ttk_Manager *)clientData; - int index = Ttk_ContentIndex(mgr, window); + Tcl_Size index = Ttk_ContentIndex(mgr, window); if (index >= 0) { int reqWidth = Tk_ReqWidth(window); int reqHeight= Tk_ReqHeight(window); - if (mgr->managerSpec->SlaveRequest( + if (mgr->managerSpec->ContentRequest( mgr->managerData, index, reqWidth, reqHeight)) { ScheduleUpdate(mgr, MGR_RESIZE_REQUIRED); } } } -void Ttk_LostContentProc(ClientData clientData, Tk_Window window) +void Ttk_LostContentProc(void *clientData, Tk_Window window) { Ttk_Manager *mgr = (Ttk_Manager *)clientData; - int index = Ttk_ContentIndex(mgr, window); + Tcl_Size index = Ttk_ContentIndex(mgr, window); /* ASSERT: index >= 0 */ RemoveContent(mgr, index); @@ -342,7 +342,7 @@ void Ttk_LostContentProc(ClientData clientData, Tk_Window window) * Add a new content window at the specified index. */ void Ttk_InsertContent( - Ttk_Manager *mgr, int index, Tk_Window tkwin, void *data) + Ttk_Manager *mgr, Tcl_Size index, Tk_Window tkwin, void *data) { Ttk_Content *content = NewContent(mgr, tkwin, data); InsertContent(mgr, content, index); @@ -351,7 +351,7 @@ void Ttk_InsertContent( /* ++ Ttk_ForgetContent -- * Unmanage the specified content window. */ -void Ttk_ForgetContent(Ttk_Manager *mgr, int index) +void Ttk_ForgetContent(Ttk_Manager *mgr, Tcl_Size index) { Tk_Window window = mgr->content[index]->window; RemoveContent(mgr, index); @@ -366,7 +366,7 @@ void Ttk_ForgetContent(Ttk_Manager *mgr, int index) * map the content window. */ void Ttk_PlaceContent( - Ttk_Manager *mgr, int index, int x, int y, int width, int height) + Ttk_Manager *mgr, Tcl_Size index, int x, int y, int width, int height) { Ttk_Content *content = mgr->content[index]; Tk_MaintainGeometry(content->window,mgr->window,x,y,width,height); @@ -379,7 +379,7 @@ void Ttk_PlaceContent( /* ++ Ttk_UnmapContent -- * Unmap the specified content window, but leave it managed. */ -void Ttk_UnmapContent(Ttk_Manager *mgr, int index) +void Ttk_UnmapContent(Ttk_Manager *mgr, Tcl_Size index) { Ttk_Content *content = mgr->content[index]; Tk_UnmaintainGeometry(content->window, mgr->window); @@ -405,15 +405,15 @@ void Ttk_ManagerSizeChanged(Ttk_Manager *mgr) /* +++ Accessors. */ -int Ttk_NumberContent(Ttk_Manager *mgr) +Tcl_Size Ttk_NumberContent(Ttk_Manager *mgr) { return mgr->nContent; } -void *Ttk_ContentData(Ttk_Manager *mgr, int index) +void *Ttk_ContentData(Ttk_Manager *mgr, Tcl_Size index) { return mgr->content[index]->data; } -Tk_Window Ttk_ContentWindow(Ttk_Manager *mgr, int index) +Tk_Window Ttk_ContentWindow(Ttk_Manager *mgr, Tcl_Size index) { return mgr->content[index]->window; } @@ -423,40 +423,49 @@ Tk_Window Ttk_ContentWindow(Ttk_Manager *mgr, int index) */ /* ++ Ttk_ContentIndex -- - * Returns the index of specified content window, -1 if not found. + * Returns the index of specified content window, TCL_INDEX_NONE if not found. */ -int Ttk_ContentIndex(Ttk_Manager *mgr, Tk_Window window) +Tcl_Size Ttk_ContentIndex(Ttk_Manager *mgr, Tk_Window window) { - int index; + Tcl_Size index; for (index = 0; index < mgr->nContent; ++index) if (mgr->content[index]->window == window) return index; return -1; } -/* ++ Ttk_GetContentIndexFromObj(interp, mgr, objPtr, indexPtr) -- +/* ++ Ttk_GetContentIndexFromObj(interp, mgr, objPtr, lastOK, indexPtr) -- * Return the index of the content window specified by objPtr. * Content windows may be specified as an integer index or * as the name of the managed window. * + * The parameter lastOK should be non-0 if the resolved index can be equal to + * the current size (i.e. one more than the current highest index) and 0 + * otherwise. + * * Returns: * Standard Tcl completion code. Leaves an error message in case of error. */ int Ttk_GetContentIndexFromObj( - Tcl_Interp *interp, Ttk_Manager *mgr, Tcl_Obj *objPtr, int *indexPtr) + Tcl_Interp *interp, Ttk_Manager *mgr, Tcl_Obj *objPtr, int lastOK, Tcl_Size *indexPtr) { const char *string = Tcl_GetString(objPtr); - int index = 0; + Tcl_Size index = 0; Tk_Window tkwin; /* Try interpreting as an integer first: */ - if (Tcl_GetIntFromObj(NULL, objPtr, &index) == TCL_OK) { - if (index < 0 || index >= mgr->nContent) { + if (TkGetIntForIndex(objPtr, mgr->nContent - 1, lastOK, &index) == TCL_OK) { + /* + * Note despite passing lastOK above, we still need to check here + * as well as TkGetIntForIndex only uses lastOK for end-relative indices, + * not integers. + */ + if (index < 0 || (index - !!lastOK) >= mgr->nContent) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "Slave index %d out of bounds", index)); - Tcl_SetErrorCode(interp, "TTK", "SLAVE", "INDEX", NULL); + "Managed window index \"%s\" out of bounds", Tcl_GetString(objPtr))); + Tcl_SetErrorCode(interp, "TTK", "MANAGED", "INDEX", NULL); return TCL_ERROR; } *indexPtr = index; @@ -472,7 +481,7 @@ int Ttk_GetContentIndexFromObj( Tcl_SetObjResult(interp, Tcl_ObjPrintf( "%s is not managed by %s", string, Tk_PathName(mgr->window))); - Tcl_SetErrorCode(interp, "TTK", "SLAVE", "MANAGER", NULL); + Tcl_SetErrorCode(interp, "TTK", "MANAGED", "MANAGER", NULL); return TCL_ERROR; } *indexPtr = index; @@ -480,15 +489,15 @@ int Ttk_GetContentIndexFromObj( } Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "Invalid slave specification %s", string)); - Tcl_SetErrorCode(interp, "TTK", "SLAVE", "SPEC", NULL); + "Invalid managed window specification %s", string)); + Tcl_SetErrorCode(interp, "TTK", "MANAGED", "SPEC", NULL); return TCL_ERROR; } /* ++ Ttk_ReorderContent(mgr, fromIndex, toIndex) -- * Change content window order. */ -void Ttk_ReorderContent(Ttk_Manager *mgr, int fromIndex, int toIndex) +void Ttk_ReorderContent(Ttk_Manager *mgr, Tcl_Size fromIndex, Tcl_Size toIndex) { Ttk_Content *moved = mgr->content[fromIndex]; @@ -540,7 +549,7 @@ int Ttk_Maintainable(Tcl_Interp *interp, Tk_Window window, Tk_Window container) return 1; badWindow: - Tcl_SetObjResult(interp, Tcl_ObjPrintf("can't add %s as slave of %s", + Tcl_SetObjResult(interp, Tcl_ObjPrintf("can't add %s as content of %s", Tk_PathName(window), Tk_PathName(container))); Tcl_SetErrorCode(interp, "TTK", "GEOMETRY", "MAINTAINABLE", NULL); return 0; |