diff options
Diffstat (limited to 'generic/tkCanvWind.c')
-rw-r--r-- | generic/tkCanvWind.c | 193 |
1 files changed, 93 insertions, 100 deletions
diff --git a/generic/tkCanvWind.c b/generic/tkCanvWind.c index f73546f..b62859c 100644 --- a/generic/tkCanvWind.c +++ b/generic/tkCanvWind.c @@ -10,6 +10,7 @@ * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ +#include <stdio.h> #include "tkInt.h" #include "tkCanvas.h" @@ -37,27 +38,29 @@ typedef struct WindowItem { * Information used for parsing configuration specs: */ -static const Tk_CustomOption stateOption = { - TkStateParseProc, TkStatePrintProc, INT2PTR(2) +static Tk_CustomOption stateOption = { + (Tk_OptionParseProc *) TkStateParseProc, + TkStatePrintProc, (ClientData) 2 }; -static const Tk_CustomOption tagsOption = { - Tk_CanvasTagsParseProc, Tk_CanvasTagsPrintProc, NULL +static Tk_CustomOption tagsOption = { + (Tk_OptionParseProc *) Tk_CanvasTagsParseProc, + Tk_CanvasTagsPrintProc, (ClientData) NULL }; -static const Tk_ConfigSpec configSpecs[] = { +static Tk_ConfigSpec configSpecs[] = { {TK_CONFIG_ANCHOR, "-anchor", NULL, NULL, - "center", Tk_Offset(WindowItem, anchor), TK_CONFIG_DONT_SET_DEFAULT, NULL}, + "center", Tk_Offset(WindowItem, anchor), TK_CONFIG_DONT_SET_DEFAULT}, {TK_CONFIG_PIXELS, "-height", NULL, NULL, - "0", Tk_Offset(WindowItem, height), TK_CONFIG_DONT_SET_DEFAULT, NULL}, + "0", Tk_Offset(WindowItem, height), TK_CONFIG_DONT_SET_DEFAULT}, {TK_CONFIG_CUSTOM, "-state", NULL, NULL, NULL, Tk_Offset(Tk_Item, state), TK_CONFIG_NULL_OK, &stateOption}, {TK_CONFIG_CUSTOM, "-tags", NULL, NULL, NULL, 0, TK_CONFIG_NULL_OK, &tagsOption}, {TK_CONFIG_PIXELS, "-width", NULL, NULL, - "0", Tk_Offset(WindowItem, width), TK_CONFIG_DONT_SET_DEFAULT, NULL}, + "0", Tk_Offset(WindowItem, width), TK_CONFIG_DONT_SET_DEFAULT}, {TK_CONFIG_WINDOW, "-window", NULL, NULL, - NULL, Tk_Offset(WindowItem, tkwin), TK_CONFIG_NULL_OK, NULL}, - {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0, NULL} + NULL, Tk_Offset(WindowItem, tkwin), TK_CONFIG_NULL_OK}, + {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0} }; /* @@ -68,10 +71,10 @@ static void ComputeWindowBbox(Tk_Canvas canvas, WindowItem *winItemPtr); static int ConfigureWinItem(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int objc, - Tcl_Obj *const objv[], int flags); + Tcl_Obj *CONST objv[], int flags); static int CreateWinItem(Tcl_Interp *interp, Tk_Canvas canvas, struct Tk_Item *itemPtr, - int objc, Tcl_Obj *const objv[]); + int objc, Tcl_Obj *CONST objv[]); static void DeleteWinItem(Tk_Canvas canvas, Tk_Item *itemPtr, Display *display); static void DisplayWinItem(Tk_Canvas canvas, @@ -84,7 +87,7 @@ static void TranslateWinItem(Tk_Canvas canvas, Tk_Item *itemPtr, double deltaX, double deltaY); static int WinItemCoords(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int objc, - Tcl_Obj *const objv[]); + Tcl_Obj *CONST objv[]); static void WinItemLostSlaveProc(ClientData clientData, Tk_Window tkwin); static void WinItemRequestProc(ClientData clientData, @@ -130,7 +133,6 @@ Tk_ItemType tkWindowType = { NULL, /* insertProc */ NULL, /* dTextProc */ NULL, /* nextPtr */ - NULL, 0, NULL, NULL }; /* @@ -170,13 +172,13 @@ CreateWinItem( Tk_Item *itemPtr, /* Record to hold new item; header has been * initialized by caller. */ int objc, /* Number of arguments in objv. */ - Tcl_Obj *const objv[]) /* Arguments describing window. */ + Tcl_Obj *CONST objv[]) /* Arguments describing window. */ { WindowItem *winItemPtr = (WindowItem *) itemPtr; int i; if (objc == 0) { - Tcl_Panic("canvas did not pass any coords"); + Tcl_Panic("canvas did not pass any coords\n"); } /* @@ -197,8 +199,7 @@ CreateWinItem( if (objc == 1) { i = 1; } else { - const char *arg = Tcl_GetString(objv[1]); - + char *arg = Tcl_GetString(objv[1]); i = 2; if ((arg[0] == '-') && (arg[1] >= 'a') && (arg[1] <= 'z')) { i = 1; @@ -241,26 +242,27 @@ WinItemCoords( Tk_Item *itemPtr, /* Item whose coordinates are to be read or * modified. */ int objc, /* Number of coordinates supplied in objv. */ - Tcl_Obj *const objv[]) /* Array of coordinates: x1, y1, x2, y2, ... */ + Tcl_Obj *CONST objv[]) /* Array of coordinates: x1, y1, x2, y2, ... */ { WindowItem *winItemPtr = (WindowItem *) itemPtr; if (objc == 0) { - Tcl_Obj *objs[2]; - - objs[0] = Tcl_NewDoubleObj(winItemPtr->x); - objs[1] = Tcl_NewDoubleObj(winItemPtr->y); - Tcl_SetObjResult(interp, Tcl_NewListObj(2, objs)); + Tcl_Obj *obj = Tcl_NewObj(); + Tcl_Obj *subobj = Tcl_NewDoubleObj(winItemPtr->x); + Tcl_ListObjAppendElement(interp, obj, subobj); + subobj = Tcl_NewDoubleObj(winItemPtr->y); + Tcl_ListObjAppendElement(interp, obj, subobj); + Tcl_SetObjResult(interp, obj); } else if (objc < 3) { if (objc==1) { if (Tcl_ListObjGetElements(interp, objv[0], &objc, (Tcl_Obj ***) &objv) != TCL_OK) { return TCL_ERROR; } else if (objc != 2) { - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "wrong # coordinates: expected 2, got %d", objc)); - Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "WINDOW", - NULL); + char buf[64 + TCL_INTEGER_SPACE]; + + sprintf(buf, "wrong # coordinates: expected 2, got %d", objc); + Tcl_SetResult(interp, buf, TCL_VOLATILE); return TCL_ERROR; } } @@ -271,9 +273,10 @@ WinItemCoords( } ComputeWindowBbox(canvas, winItemPtr); } else { - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "wrong # coordinates: expected 0 or 2, got %d", objc)); - Tcl_SetErrorCode(interp, "TK", "CANVAS", "COORDS", "WINDOW", NULL); + char buf[64 + TCL_INTEGER_SPACE]; + + sprintf(buf, "wrong # coordinates: expected 0 or 2, got %d", objc); + Tcl_SetResult(interp, buf, TCL_VOLATILE); return TCL_ERROR; } return TCL_OK; @@ -303,7 +306,7 @@ ConfigureWinItem( Tk_Canvas canvas, /* Canvas containing itemPtr. */ Tk_Item *itemPtr, /* Window item to reconfigure. */ int objc, /* Number of elements in objv. */ - Tcl_Obj *const objv[], /* Arguments describing things to configure. */ + Tcl_Obj *CONST objv[], /* Arguments describing things to configure. */ int flags) /* Flags to pass to Tk_ConfigureWidget. */ { WindowItem *winItemPtr = (WindowItem *) itemPtr; @@ -313,7 +316,7 @@ ConfigureWinItem( oldWindow = winItemPtr->tkwin; canvasTkwin = Tk_CanvasTkwin(canvas); if (TCL_OK != Tk_ConfigureWidget(interp, canvasTkwin, configSpecs, objc, - (const char **) objv, (char *) winItemPtr, flags|TK_CONFIG_OBJS)) { + (CONST char **) objv, (char *) winItemPtr, flags|TK_CONFIG_OBJS)) { return TCL_ERROR; } @@ -324,8 +327,8 @@ ConfigureWinItem( if (oldWindow != winItemPtr->tkwin) { if (oldWindow != NULL) { Tk_DeleteEventHandler(oldWindow, StructureNotifyMask, - WinItemStructureProc, winItemPtr); - Tk_ManageGeometry(oldWindow, NULL, NULL); + WinItemStructureProc, (ClientData) winItemPtr); + Tk_ManageGeometry(oldWindow, NULL, (ClientData) NULL); Tk_UnmaintainGeometry(oldWindow, canvasTkwin); Tk_UnmapWindow(oldWindow); } @@ -340,23 +343,30 @@ ConfigureWinItem( */ parent = Tk_Parent(winItemPtr->tkwin); - for (ancestor = canvasTkwin ;; ancestor = Tk_Parent(ancestor)) { + for (ancestor = canvasTkwin; ; + ancestor = Tk_Parent(ancestor)) { if (ancestor == parent) { break; } - if (((Tk_FakeWin *) ancestor)->flags & TK_TOP_HIERARCHY) { - goto badWindow; + if (((Tk_FakeWin *) (ancestor))->flags & TK_TOP_HIERARCHY) { + badWindow: + Tcl_AppendResult(interp, "can't use ", + Tk_PathName(winItemPtr->tkwin), + " in a window item of this canvas", NULL); + winItemPtr->tkwin = NULL; + return TCL_ERROR; } } - if (((Tk_FakeWin *) winItemPtr->tkwin)->flags & TK_TOP_HIERARCHY){ + if (((Tk_FakeWin *) (winItemPtr->tkwin))->flags & TK_TOP_HIERARCHY) { goto badWindow; } if (winItemPtr->tkwin == canvasTkwin) { goto badWindow; } Tk_CreateEventHandler(winItemPtr->tkwin, StructureNotifyMask, - WinItemStructureProc, winItemPtr); - Tk_ManageGeometry(winItemPtr->tkwin, &canvasGeomType, winItemPtr); + WinItemStructureProc, (ClientData) winItemPtr); + Tk_ManageGeometry(winItemPtr->tkwin, &canvasGeomType, + (ClientData) winItemPtr); } } if ((winItemPtr->tkwin != NULL) @@ -369,15 +379,8 @@ ConfigureWinItem( } ComputeWindowBbox(canvas, winItemPtr); - return TCL_OK; - badWindow: - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "can't use %s in a window item of this canvas", - Tk_PathName(winItemPtr->tkwin))); - Tcl_SetErrorCode(interp, "TK", "GEOMETRY", "HIERARCHY", NULL); - winItemPtr->tkwin = NULL; - return TCL_ERROR; + return TCL_OK; } /* @@ -408,8 +411,9 @@ DeleteWinItem( if (winItemPtr->tkwin != NULL) { Tk_DeleteEventHandler(winItemPtr->tkwin, StructureNotifyMask, - WinItemStructureProc, winItemPtr); - Tk_ManageGeometry(winItemPtr->tkwin, NULL, NULL); + WinItemStructureProc, (ClientData) winItemPtr); + Tk_ManageGeometry(winItemPtr->tkwin, NULL, + (ClientData) NULL); if (canvasTkwin != Tk_Parent(winItemPtr->tkwin)) { Tk_UnmaintainGeometry(winItemPtr->tkwin, canvasTkwin); } @@ -447,7 +451,7 @@ ComputeWindowBbox( y = (int) (winItemPtr->y + ((winItemPtr->y >= 0) ? 0.5 : - 0.5)); if (state == TK_STATE_NULL) { - state = Canvas(canvas)->canvas_state; + state = ((TkCanvas *)canvas)->canvas_state; } if ((winItemPtr->tkwin == NULL) || (state == TK_STATE_HIDDEN)) { /* @@ -572,7 +576,7 @@ DisplayWinItem( return; } if (state == TK_STATE_NULL) { - state = Canvas(canvas)->canvas_state; + state = ((TkCanvas *)canvas)->canvas_state; } /* @@ -753,7 +757,8 @@ xerrorhandler( { return 0; } -#endif /* X_GetImage */ +#endif + /* *-------------------------------------------------------------- @@ -783,7 +788,8 @@ WinItemToPostscript( * information; 0 means final Postscript is * being created. */ { - WindowItem *winItemPtr = (WindowItem *) itemPtr; + WindowItem *winItemPtr = (WindowItem *)itemPtr; + double x, y; int width, height; Tk_Window tkwin = winItemPtr->tkwin; @@ -826,44 +832,45 @@ CanvasPsWindow( double x, double y, /* origin of window. */ int width, int height) /* width/height of window. */ { + char buffer[256]; XImage *ximage; int result; + Tcl_DString buffer1, buffer2; #ifdef X_GetImage Tk_ErrorHandler handle; #endif - Tcl_Obj *cmdObj, *psObj; - Tcl_InterpState interpState = Tcl_SaveInterpState(interp, TCL_OK); - /* - * Locate the subwindow within the wider window. - */ - - psObj = Tcl_ObjPrintf( - "\n%%%% %s item (%s, %d x %d)\n" /* Comment */ - "%.15g %.15g translate\n", /* Position */ + sprintf(buffer, "\n%%%% %s item (%s, %d x %d)\n%.15g %.15g translate\n", Tk_Class(tkwin), Tk_PathName(tkwin), width, height, x, y); + Tcl_AppendResult(interp, buffer, NULL); /* * First try if the widget has its own "postscript" command. If it exists, * this will produce much better postscript than when a pixmap is used. */ - Tcl_ResetResult(interp); - cmdObj = Tcl_ObjPrintf("%s postscript -prolog 0", Tk_PathName(tkwin)); - Tcl_IncrRefCount(cmdObj); - result = Tcl_EvalObjEx(interp, cmdObj, 0); - Tcl_DecrRefCount(cmdObj); + Tcl_DStringInit(&buffer1); + Tcl_DStringInit(&buffer2); + Tcl_DStringGetResult(interp, &buffer2); + sprintf(buffer, "%s postscript -prolog 0\n", Tk_PathName(tkwin)); + result = Tcl_Eval(interp, buffer); + Tcl_DStringGetResult(interp, &buffer1); + Tcl_DStringResult(interp, &buffer2); + Tcl_DStringFree(&buffer2); if (result == TCL_OK) { - Tcl_AppendPrintfToObj(psObj, - "50 dict begin\nsave\ngsave\n" - "0 %d moveto %d 0 rlineto 0 -%d rlineto -%d 0 rlineto closepath\n" - "1.000 1.000 1.000 setrgbcolor AdjustColor\nfill\ngrestore\n", + Tcl_AppendResult(interp, "50 dict begin\nsave\ngsave\n", NULL); + sprintf(buffer, "0 %d moveto %d 0 rlineto 0 -%d rlineto -%d", height, width, height, width); - Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp)); - Tcl_AppendToObj(psObj, "\nrestore\nend\n\n\n", -1); - goto done; + Tcl_AppendResult(interp, buffer, NULL); + Tcl_AppendResult(interp, " 0 rlineto closepath\n", + "1.000 1.000 1.000 setrgbcolor AdjustColor\nfill\ngrestore\n", + Tcl_DStringValue(&buffer1), "\nrestore\nend\n\n\n", NULL); + Tcl_DStringFree(&buffer1); + + return result; } + Tcl_DStringFree(&buffer1); /* * If the window is off the screen it will generate a BadMatch/XError. We @@ -872,7 +879,7 @@ CanvasPsWindow( #ifdef X_GetImage handle = Tk_CreateErrorHandler(Tk_Display(tkwin), BadMatch, - X_GetImage, -1, xerrorhandler, tkwin); + X_GetImage, -1, xerrorhandler, (ClientData) tkwin); #endif /* @@ -881,34 +888,20 @@ CanvasPsWindow( */ ximage = XGetImage(Tk_Display(tkwin), Tk_WindowId(tkwin), 0, 0, - (unsigned) width, (unsigned) height, AllPlanes, ZPixmap); + (unsigned int)width, (unsigned int)height, AllPlanes, ZPixmap); #ifdef X_GetImage Tk_DeleteErrorHandler(handle); #endif if (ximage == NULL) { - result = TCL_OK; - } else { - Tcl_ResetResult(interp); - result = TkPostscriptImage(interp, tkwin, Canvas(canvas)->psInfo, - ximage, 0, 0, width, height); - Tcl_AppendObjToObj(psObj, Tcl_GetObjResult(interp)); - XDestroyImage(ximage); + return TCL_OK; } - /* - * Plug the accumulated postscript back into the result. - */ + result = TkPostscriptImage(interp, tkwin, + ((TkCanvas *)canvas)->psInfo, ximage, 0, 0, width, height); - done: - if (result == TCL_OK) { - (void) Tcl_RestoreInterpState(interp, interpState); - Tcl_AppendObjToObj(Tcl_GetObjResult(interp), psObj); - } else { - Tcl_DiscardInterpState(interpState); - } - Tcl_DecrRefCount(psObj); + XDestroyImage(ximage); return result; } @@ -1007,7 +1000,7 @@ WinItemStructureProc( ClientData clientData, /* Pointer to record describing window item. */ XEvent *eventPtr) /* Describes what just happened. */ { - WindowItem *winItemPtr = clientData; + WindowItem *winItemPtr = (WindowItem *) clientData; if (eventPtr->type == DestroyNotify) { winItemPtr->tkwin = NULL; @@ -1037,7 +1030,7 @@ WinItemRequestProc( ClientData clientData, /* Pointer to record for window item. */ Tk_Window tkwin) /* Window that changed its desired size. */ { - WindowItem *winItemPtr = clientData; + WindowItem *winItemPtr = (WindowItem *) clientData; ComputeWindowBbox(winItemPtr->canvas, winItemPtr); @@ -1074,11 +1067,11 @@ WinItemLostSlaveProc( * was stolen away. */ Tk_Window tkwin) /* Tk's handle for the slave window. */ { - WindowItem *winItemPtr = clientData; + WindowItem *winItemPtr = (WindowItem *) clientData; Tk_Window canvasTkwin = Tk_CanvasTkwin(winItemPtr->canvas); Tk_DeleteEventHandler(winItemPtr->tkwin, StructureNotifyMask, - WinItemStructureProc, winItemPtr); + WinItemStructureProc, (ClientData) winItemPtr); if (canvasTkwin != Tk_Parent(winItemPtr->tkwin)) { Tk_UnmaintainGeometry(winItemPtr->tkwin, canvasTkwin); } |