diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2005-11-04 15:23:05 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2005-11-04 15:23:05 (GMT) |
commit | 5a7ebb1e1c5d20b44b554a170872eafaabaf0cae (patch) | |
tree | bbfefe8e3a1da78eb57ba0c66ea9dcf6bbcb6552 /generic | |
parent | 1a7fe73d9dd7662dc54d12ef4efa9a8cd9a24e7b (diff) | |
download | tk-5a7ebb1e1c5d20b44b554a170872eafaabaf0cae.zip tk-5a7ebb1e1c5d20b44b554a170872eafaabaf0cae.tar.gz tk-5a7ebb1e1c5d20b44b554a170872eafaabaf0cae.tar.bz2 |
ANSIfy
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tk3d.h | 76 | ||||
-rw-r--r-- | generic/tkButton.h | 223 | ||||
-rw-r--r-- | generic/tkCanvBmap.c | 519 | ||||
-rw-r--r-- | generic/tkCanvImg.c | 521 | ||||
-rw-r--r-- | generic/tkCanvLine.c | 1012 | ||||
-rw-r--r-- | generic/tkCanvPoly.c | 907 | ||||
-rw-r--r-- | generic/tkCanvPs.c | 1499 | ||||
-rw-r--r-- | generic/tkCanvText.c | 671 | ||||
-rw-r--r-- | generic/tkCanvUtil.c | 104 | ||||
-rw-r--r-- | generic/tkCanvWind.c | 623 | ||||
-rw-r--r-- | generic/tkCanvas.h | 240 |
11 files changed, 3137 insertions, 3258 deletions
diff --git a/generic/tk3d.h b/generic/tk3d.h index 03ce97e..100908b 100644 --- a/generic/tk3d.h +++ b/generic/tk3d.h @@ -1,15 +1,14 @@ /* * tk3d.h -- * - * Declarations of types and functions shared by the 3d border - * module. + * Declarations of types and functions shared by the 3d border module. * * Copyright (c) 1996-1997 by Sun Microsystems, Inc. * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tk3d.h,v 1.5 1999/04/16 01:51:10 stanton Exp $ + * RCS: @(#) $Id: tk3d.h,v 1.6 2005/11/04 15:23:05 dkf Exp $ */ #ifndef _TK3D @@ -24,9 +23,8 @@ /* * One of the following data structures is allocated for each 3-D border - * currently in use. Structures of this type are indexed by - * borderTable, so that a single structure can be shared for several - * uses. + * currently in use. Structures of this type are indexed by borderTable, so + * that a single structure can be shared for several uses. */ typedef struct TkBorder { @@ -40,18 +38,17 @@ typedef struct TkBorder { int resourceRefCount; /* Number of active uses of this color (each * active use corresponds to a call to * Tk_Alloc3DBorderFromObj or Tk_Get3DBorder). - * If this count is 0, then this structure - * is no longer valid and it isn't present - * in borderTable: it is being kept around - * only because there are objects referring - * to it. The structure is freed when - * resourceRefCount and objRefCount are - * both 0. */ + * If this count is 0, then this structure is + * no longer valid and it isn't present in + * borderTable: it is being kept around only + * because there are objects referring to it. + * The structure is freed when + * resourceRefCount and objRefCount are both + * 0. */ int objRefCount; /* The number of Tcl objects that reference * this structure. */ - XColor *bgColorPtr; /* Background color (intensity - * between lightColorPtr and - * darkColorPtr). */ + XColor *bgColorPtr; /* Background color (intensity between + * lightColorPtr and darkColorPtr). */ XColor *darkColorPtr; /* Color for darker areas (must free when * deleting structure). NULL means shadows * haven't been allocated yet.*/ @@ -59,28 +56,26 @@ typedef struct TkBorder { * (must free this when deleting structure). * NULL means shadows haven't been allocated * yet. */ - Pixmap shadow; /* Stipple pattern to use for drawing - * shadows areas. Used for displays with - * <= 64 colors or where colormap has filled - * up. */ - GC bgGC; /* Used (if necessary) to draw areas in - * the background color. */ - GC darkGC; /* Used to draw darker parts of the - * border. None means the shadow colors - * haven't been allocated yet.*/ - GC lightGC; /* Used to draw lighter parts of - * the border. None means the shadow colors - * haven't been allocated yet. */ - Tcl_HashEntry *hashPtr; /* Entry in borderTable (needed in - * order to delete structure). */ + Pixmap shadow; /* Stipple pattern to use for drawing shadows + * areas. Used for displays with <= 64 colors + * or where colormap has filled up. */ + GC bgGC; /* Used (if necessary) to draw areas in the + * background color. */ + GC darkGC; /* Used to draw darker parts of the border. + * None means the shadow colors haven't been + * allocated yet.*/ + GC lightGC; /* Used to draw lighter parts of the border. + * None means the shadow colors haven't been + * allocated yet. */ + Tcl_HashEntry *hashPtr; /* Entry in borderTable (needed in order to + * delete structure). */ struct TkBorder *nextPtr; /* Points to the next TkBorder structure with - * the same color name. Borders with the - * same name but different screens or - * colormaps are chained together off a - * single entry in borderTable. */ + * the same color name. Borders with the same + * name but different screens or colormaps are + * chained together off a single entry in + * borderTable. */ } TkBorder; - /* * Maximum intensity for a color: */ @@ -91,10 +86,9 @@ typedef struct TkBorder { * Declarations for platform specific interfaces used by this module. */ -EXTERN TkBorder * TkpGetBorder _ANSI_ARGS_((void)); -EXTERN void TkpGetShadows _ANSI_ARGS_((TkBorder *borderPtr, - Tk_Window tkwin)); -EXTERN void TkpFreeBorder _ANSI_ARGS_((TkBorder *borderPtr)); +EXTERN TkBorder * TkpGetBorder(void); +EXTERN void TkpGetShadows(TkBorder *borderPtr, Tk_Window tkwin); +EXTERN void TkpFreeBorder(TkBorder *borderPtr); # undef TCL_STORAGE_CLASS # define TCL_STORAGE_CLASS DLLIMPORT diff --git a/generic/tkButton.h b/generic/tkButton.h index 78e0765..01a30e8 100644 --- a/generic/tkButton.h +++ b/generic/tkButton.h @@ -1,15 +1,15 @@ /* * tkButton.h -- * - * Declarations of types and functions used to implement - * button-like widgets. + * Declarations of types and functions used to implement button-like + * widgets. * * Copyright (c) 1996-1998 by Sun Microsystems, Inc. * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkButton.h,v 1.11 2004/02/18 00:40:24 hobbs Exp $ + * RCS: @(#) $Id: tkButton.h,v 1.12 2005/11/04 15:23:05 dkf Exp $ */ #ifndef _TKBUTTON @@ -50,20 +50,20 @@ enum defaultState { }; /* - * A data structure of the following type is kept for each - * widget managed by this file: + * A data structure of the following type is kept for each widget managed by + * this file: */ typedef struct { - Tk_Window tkwin; /* Window that embodies the button. NULL - * means that the window has been destroyed. */ - Display *display; /* Display containing widget. Needed to - * free up resources after tkwin is gone. */ + Tk_Window tkwin; /* Window that embodies the button. NULL means + * that the window has been destroyed. */ + Display *display; /* Display containing widget. Needed to free + * up resources after tkwin is gone. */ Tcl_Interp *interp; /* Interpreter associated with button. */ Tcl_Command widgetCmd; /* Token for button's widget command. */ int type; /* Type of widget, such as TYPE_LABEL: * restricts operations that may be performed - * on widget. See below for legal values. */ + * on widget. See below for legal values. */ Tk_OptionTable optionTable; /* Table that defines configuration options * available for this widget. */ @@ -73,64 +73,65 @@ typedef struct { Tcl_Obj *textPtr; /* Value of -text option: specifies text to * display in button. */ - int underline; /* Value of -underline option: specifies - * index of character to underline. < 0 means - * don't underline anything. */ + int underline; /* Value of -underline option: specifies index + * of character to underline. < 0 means don't + * underline anything. */ Tcl_Obj *textVarNamePtr; /* Value of -textvariable option: specifies - * name of variable or NULL. If non-NULL, + * name of variable or NULL. If non-NULL, * button displays the contents of this * variable. */ - Pixmap bitmap; /* Value of -bitmap option. If not None, + Pixmap bitmap; /* Value of -bitmap option. If not None, * specifies bitmap to display and text and * textVar are ignored. */ - Tcl_Obj *imagePtr; /* Value of -image option: specifies image - * to display in window, or NULL if none. - * If non-NULL, bitmap, text, and textVarName - * are ignored.*/ + Tcl_Obj *imagePtr; /* Value of -image option: specifies image to + * display in window, or NULL if none. If + * non-NULL, bitmap, text, and textVarName are + * ignored.*/ Tk_Image image; /* Derived from imagePtr by calling - * Tk_GetImage, or NULL if imagePtr is NULL. */ + * Tk_GetImage, or NULL if imagePtr is + * NULL. */ Tcl_Obj *selectImagePtr; /* Value of -selectimage option: specifies * image to display in window when selected, - * or NULL if none. Ignored if imagePtr is + * or NULL if none. Ignored if imagePtr is * NULL. */ Tk_Image selectImage; /* Derived from selectImagePtr by calling - * Tk_GetImage, or NULL if selectImagePtr - * is NULL. */ + * Tk_GetImage, or NULL if selectImagePtr is + * NULL. */ Tcl_Obj *tristateImagePtr; /* Value of -tristateimage option: specifies * image to display in window when selected, - * or NULL if none. Ignored if imagePtr is + * or NULL if none. Ignored if imagePtr is * NULL. */ Tk_Image tristateImage; /* Derived from tristateImagePtr by calling - * Tk_GetImage, or NULL if tristateImagePtr - * is NULL. */ + * Tk_GetImage, or NULL if tristateImagePtr is + * NULL. */ /* * Information used when displaying widget: */ - enum state state; /* Value of -state option: specifies - * state of button for display purposes.*/ + enum state state; /* Value of -state option: specifies state of + * button for display purposes.*/ Tk_3DBorder normalBorder; /* Value of -background option: specifies * color for background (and border) when * window isn't active. */ - Tk_3DBorder activeBorder; /* Value of -activebackground option: - * this is the color used to draw 3-D border - * and background when widget is active. */ + Tk_3DBorder activeBorder; /* Value of -activebackground option: this is + * the color used to draw 3-D border and + * background when widget is active. */ Tcl_Obj *borderWidthPtr; /* Value of -borderWidth option: specifies * width of border in pixels. */ int borderWidth; /* Integer value corresponding to - * borderWidthPtr. Always >= 0. */ + * borderWidthPtr. Always >= 0. */ int relief; /* Value of -relief option: specifies 3-d * effect for border, such as * TK_RELIEF_RAISED. */ - int overRelief; /* Value of -overrelief option: specifies a 3-d - * effect for the border, such as + int overRelief; /* Value of -overrelief option: specifies a + * 3-d effect for the border, such as * TK_RELIEF_RAISED, to be used when the mouse * is over the button. */ int offRelief; /* Value of -offrelief option: specifies a 3-d * effect for the border, such as * TK_RELIEF_RAISED, to be used when a - * checkbutton or radiobutton without + * checkbutton or radiobutton without * indicator is off */ Tcl_Obj *highlightWidthPtr; /* Value of -highlightthickness option: * specifies width in pixels of highlight to @@ -142,25 +143,23 @@ typedef struct { * specifies background with which to draw 3-D * default ring and focus highlight area when * highlight is off. */ - XColor *highlightColorPtr; /* Value of -highlightcolor option: - * specifies color for drawing traversal - * highlight. */ + XColor *highlightColorPtr; /* Value of -highlightcolor option: specifies + * color for drawing traversal highlight. */ int inset; /* Total width of all borders, including * traversal highlight and 3-D border. - * Indicates how much interior stuff must - * be offset from outside edges to leave - * room for borders. */ - Tk_Font tkfont; /* Value of -font option: specifies font - * to use for display text. */ + * Indicates how much interior stuff must be + * offset from outside edges to leave room for + * borders. */ + Tk_Font tkfont; /* Value of -font option: specifies font to + * use for display text. */ XColor *normalFg; /* Value of -font option: specifies foreground * color in normal mode. */ XColor *activeFg; /* Value of -activeforeground option: - * foreground color in active mode. NULL - * means use -foreground instead. */ + * foreground color in active mode. NULL means + * use -foreground instead. */ XColor *disabledFg; /* Value of -disabledforeground option: - * foreground color when disabled. NULL - * means use normalFg with a 50% stipple - * instead. */ + * foreground color when disabled. NULL means + * use normalFg with a 50% stipple instead. */ GC normalTextGC; /* GC for drawing text in normal mode. Also * used to copy from off-screen pixmap onto * screen. */ @@ -168,8 +167,8 @@ typedef struct { * means use normalTextGC). */ GC disabledGC; /* Used to produce disabled effect for text * and check/radio marks. */ - GC stippleGC; /* Used to produce disabled stipple effect - * for images when disabled. */ + GC stippleGC; /* Used to produce disabled stipple effect for + * images when disabled. */ Pixmap gray; /* Pixmap for displaying disabled text if * disabledFg is NULL. */ GC copyGC; /* Used for copying information from an @@ -178,33 +177,33 @@ typedef struct { int width; /* Integer value corresponding to widthPtr. */ Tcl_Obj *heightPtr; /* Value of -height option. */ int height; /* Integer value corresponding to heightPtr. */ - Tcl_Obj *wrapLengthPtr; /* Value of -wraplength option: specifies - * line length (in pixels) at which to wrap - * onto next line. <= 0 means don't wrap - * except at newlines. */ + Tcl_Obj *wrapLengthPtr; /* Value of -wraplength option: specifies line + * length (in pixels) at which to wrap onto + * next line. <= 0 means don't wrap except at + * newlines. */ int wrapLength; /* Integer value corresponding to * wrapLengthPtr. */ Tcl_Obj *padXPtr; /* Value of -padx option: specifies how many * pixels of extra space to leave on left and - * right of text. Ignored for bitmaps and + * right of text. Ignored for bitmaps and * images. */ int padX; /* Integer value corresponding to padXPtr. */ Tcl_Obj *padYPtr; /* Value of -padx option: specifies how many * pixels of extra space to leave above and - * below text. Ignored for bitmaps and + * below text. Ignored for bitmaps and * images. */ int padY; /* Integer value corresponding to padYPtr. */ Tk_Anchor anchor; /* Value of -anchor option: specifies where * text/bitmap should be displayed inside * button region. */ - Tk_Justify justify; /* Value of -justify option: specifies how - * to align lines of multi-line text. */ - int indicatorOn; /* Value of -indicatoron option: 1 means - * draw indicator in checkbuttons and - * radiobuttons, 0 means don't draw it. */ + Tk_Justify justify; /* Value of -justify option: specifies how to + * align lines of multi-line text. */ + int indicatorOn; /* Value of -indicatoron option: 1 means draw + * indicator in checkbuttons and radiobuttons, + * 0 means don't draw it. */ Tk_3DBorder selectBorder; /* Value of -selectcolor option: specifies * color for drawing indicator background, or - * perhaps widget background, when selected. */ + * perhaps widget background, when selected */ int textWidth; /* Width needed to display text as requested, * in pixels. */ int textHeight; /* Height needed to display text as requested, @@ -215,30 +214,28 @@ typedef struct { int indicatorDiameter; /* Diameter of indicator, in pixels. */ enum defaultState defaultState; /* Value of -default option, such as - * DEFAULT_NORMAL: specifies state - * of default ring for buttons (normal, - * active, or disabled). NULL for other - * classes. */ + * DEFAULT_NORMAL: specifies state of default + * ring for buttons (normal, active, or + * disabled). NULL for other classes. */ /* - * For check and radio buttons, the fields below are used - * to manage the variable indicating the button's state. + * For check and radio buttons, the fields below are used to manage the + * variable indicating the button's state. */ Tcl_Obj *selVarNamePtr; /* Value of -variable option: specifies name - * of variable used to control selected - * state of button. */ + * of variable used to control selected state + * of button. */ Tcl_Obj *onValuePtr; /* Value of -offvalue option: specifies value * to store in variable when this button is * selected. */ Tcl_Obj *offValuePtr; /* Value of -offvalue option: specifies value - * to store in variable when this button - * isn't selected. Used only by - * checkbuttons. */ - Tcl_Obj *tristateValuePtr; /* Value of -tristatevalue option: specifies value - * to display Tristate or Multivalue mode when - * variable matches this value. Used by check- - * buttons. */ + * to store in variable when this button isn't + * selected. Used only by checkbuttons. */ + Tcl_Obj *tristateValuePtr; /* Value of -tristatevalue option: specifies + * value to display Tristate or Multivalue + * mode when variable matches this value. + * Used by check- buttons. */ /* * Miscellaneous information: @@ -246,31 +243,30 @@ typedef struct { Tk_Cursor cursor; /* Value of -cursor option: if not None, * specifies current cursor for window. */ - Tcl_Obj *takeFocusPtr; /* Value of -takefocus option; not used in - * the C code, but used by keyboard traversal + Tcl_Obj *takeFocusPtr; /* Value of -takefocus option; not used in the + * C code, but used by keyboard traversal * scripts. */ - Tcl_Obj *commandPtr; /* Value of -command option: specifies script - * to execute when button is invoked. If - * widget is label or has no command, this - * is NULL. */ - int compound; /* Value of -compound option; specifies whether - * the button should show both an image and - * text, and, if so, how. */ - int repeatDelay; /* Value of -repeatdelay option; specifies - * the number of ms after which the button will + Tcl_Obj *commandPtr; /* Value of -command option: specifies script + * to execute when button is invoked. If + * widget is label or has no command, this is + * NULL. */ + int compound; /* Value of -compound option; specifies + * whether the button should show both an + * image and text, and, if so, how. */ + int repeatDelay; /* Value of -repeatdelay option; specifies the + * number of ms after which the button will * start to auto-repeat its command. */ int repeatInterval; /* Value of -repeatinterval option; specifies * the number of ms between auto-repeat * invocataions of the button command. */ - int flags; /* Various flags; see below for + int flags; /* Various flags; see below for * definitions. */ } TkButton; /* - * Possible "type" values for buttons. These are the kinds of - * widgets supported by this file. The ordering of the type - * numbers is significant: greater means more features and is - * used in the code. + * Possible "type" values for buttons. These are the kinds of widgets + * supported by this file. The ordering of the type numbers is significant: + * greater means more features and is used in the code. */ #define TYPE_LABEL 0 @@ -281,16 +277,14 @@ typedef struct { /* * Flag bits for buttons: * - * REDRAW_PENDING: Non-zero means a DoWhenIdle handler - * has already been queued to redraw - * this window. - * SELECTED: Non-zero means this button is selected, - * so special highlight should be drawn. - * GOT_FOCUS: Non-zero means this button currently - * has the input focus. + * REDRAW_PENDING: Non-zero means a DoWhenIdle handler has + * already been queued to redraw this window. + * SELECTED: Non-zero means this button is selected, so + * special highlight should be drawn. + * GOT_FOCUS: Non-zero means this button currently has the + * input focus. * BUTTON_DELETED: Non-zero needs that this button has been - * deleted, or is in the process of being - * deleted. + * deleted, or is in the process of being deleted */ #define REDRAW_PENDING (1 << 0) @@ -298,6 +292,7 @@ typedef struct { #define GOT_FOCUS (1 << 2) #define BUTTON_DELETED (1 << 3) #define TRISTATED (1 << 4) + /* * Declaration of variables shared between the files in the button module. */ @@ -305,26 +300,22 @@ typedef struct { extern Tk_ClassProcs tkpButtonProcs; /* - * Declaration of procedures used in the implementation of the button - * widget. + * Declaration of functions used in the implementation of the button widget. */ #ifndef TkpButtonSetDefaults -EXTERN void TkpButtonSetDefaults _ANSI_ARGS_(( - Tk_OptionSpec *specPtr)); +EXTERN void TkpButtonSetDefaults(Tk_OptionSpec *specPtr); #endif -EXTERN void TkButtonWorldChanged _ANSI_ARGS_(( - ClientData instanceData)); -EXTERN void TkpComputeButtonGeometry _ANSI_ARGS_(( - TkButton *butPtr)); -EXTERN TkButton * TkpCreateButton _ANSI_ARGS_((Tk_Window tkwin)); +EXTERN void TkButtonWorldChanged(ClientData instanceData); +EXTERN void TkpComputeButtonGeometry(TkButton *butPtr); +EXTERN TkButton * TkpCreateButton(Tk_Window tkwin); #ifndef TkpDestroyButton -EXTERN void TkpDestroyButton _ANSI_ARGS_((TkButton *butPtr)); +EXTERN void TkpDestroyButton(TkButton *butPtr); #endif #ifndef TkpDisplayButton -EXTERN void TkpDisplayButton _ANSI_ARGS_((ClientData clientData)); +EXTERN void TkpDisplayButton(ClientData clientData); #endif -EXTERN int TkInvokeButton _ANSI_ARGS_((TkButton *butPtr)); +EXTERN int TkInvokeButton(TkButton *butPtr); # undef TCL_STORAGE_CLASS # define TCL_STORAGE_CLASS DLLIMPORT diff --git a/generic/tkCanvBmap.c b/generic/tkCanvBmap.c index cfef9b2..ad0b9cd 100644 --- a/generic/tkCanvBmap.c +++ b/generic/tkCanvBmap.c @@ -1,4 +1,4 @@ -/* +/* * tkCanvBmap.c -- * * This file implements bitmap items for canvas widgets. @@ -6,10 +6,10 @@ * Copyright (c) 1992-1994 The Regents of the University of California. * Copyright (c) 1994-1997 Sun Microsystems, Inc. * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkCanvBmap.c,v 1.11 2005/02/11 19:30:09 hobbs Exp $ + * RCS: @(#) $Id: tkCanvBmap.c,v 1.12 2005/11/04 15:23:05 dkf Exp $ */ #include <stdio.h> @@ -23,11 +23,10 @@ typedef struct BitmapItem { Tk_Item header; /* Generic stuff that's the same for all - * types. MUST BE FIRST IN STRUCTURE. */ + * types. MUST BE FIRST IN STRUCTURE. */ double x, y; /* Coordinates of positioning point for * bitmap. */ - Tk_Anchor anchor; /* Where to anchor bitmap relative to - * (x,y). */ + Tk_Anchor anchor; /* Where to anchor bitmap relative to (x,y) */ Pixmap bitmap; /* Bitmap to display in window. */ Pixmap activeBitmap; /* Bitmap to display in window. */ Pixmap disabledBitmap; /* Bitmap to display in window. */ @@ -37,8 +36,8 @@ typedef struct BitmapItem { XColor *bgColor; /* Background color to use for bitmap. */ XColor *activeBgColor; /* Background color to use for bitmap. */ XColor *disabledBgColor; /* Background color to use for bitmap. */ - GC gc; /* Graphics context to use for drawing - * bitmap on screen. */ + GC gc; /* Graphics context to use for drawing bitmap + * on screen. */ } BitmapItem; /* @@ -55,96 +54,95 @@ static Tk_CustomOption tagsOption = { }; static Tk_ConfigSpec configSpecs[] = { - {TK_CONFIG_COLOR, "-activebackground", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(BitmapItem, activeBgColor), TK_CONFIG_NULL_OK}, - {TK_CONFIG_BITMAP, "-activebitmap", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(BitmapItem, activeBitmap), TK_CONFIG_NULL_OK}, - {TK_CONFIG_COLOR, "-activeforeground", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(BitmapItem, activeFgColor), TK_CONFIG_NULL_OK}, - {TK_CONFIG_ANCHOR, "-anchor", (char *) NULL, (char *) NULL, + {TK_CONFIG_COLOR, "-activebackground", NULL, NULL, + NULL, Tk_Offset(BitmapItem, activeBgColor), TK_CONFIG_NULL_OK}, + {TK_CONFIG_BITMAP, "-activebitmap", NULL, NULL, + NULL, Tk_Offset(BitmapItem, activeBitmap), TK_CONFIG_NULL_OK}, + {TK_CONFIG_COLOR, "-activeforeground", NULL, NULL, + NULL, Tk_Offset(BitmapItem, activeFgColor), TK_CONFIG_NULL_OK}, + {TK_CONFIG_ANCHOR, "-anchor", NULL, NULL, "center", Tk_Offset(BitmapItem, anchor), TK_CONFIG_DONT_SET_DEFAULT}, - {TK_CONFIG_COLOR, "-background", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(BitmapItem, bgColor), TK_CONFIG_NULL_OK}, - {TK_CONFIG_BITMAP, "-bitmap", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(BitmapItem, bitmap), TK_CONFIG_NULL_OK}, - {TK_CONFIG_COLOR, "-disabledbackground", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(BitmapItem, disabledBgColor), + {TK_CONFIG_COLOR, "-background", NULL, NULL, + NULL, Tk_Offset(BitmapItem, bgColor), TK_CONFIG_NULL_OK}, + {TK_CONFIG_BITMAP, "-bitmap", NULL, NULL, + NULL, Tk_Offset(BitmapItem, bitmap), TK_CONFIG_NULL_OK}, + {TK_CONFIG_COLOR, "-disabledbackground", NULL, NULL, + NULL, Tk_Offset(BitmapItem, disabledBgColor), TK_CONFIG_NULL_OK}, - {TK_CONFIG_BITMAP, "-disabledbitmap", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(BitmapItem, disabledBitmap), + {TK_CONFIG_BITMAP, "-disabledbitmap", NULL, NULL, + NULL, Tk_Offset(BitmapItem, disabledBitmap), TK_CONFIG_NULL_OK}, - {TK_CONFIG_COLOR, "-disabledforeground", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(BitmapItem, disabledFgColor), + {TK_CONFIG_COLOR, "-disabledforeground", NULL, NULL, + NULL, Tk_Offset(BitmapItem, disabledFgColor), TK_CONFIG_NULL_OK}, - {TK_CONFIG_COLOR, "-foreground", (char *) NULL, (char *) NULL, + {TK_CONFIG_COLOR, "-foreground", NULL, NULL, "black", Tk_Offset(BitmapItem, fgColor), 0}, - {TK_CONFIG_CUSTOM, "-state", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(Tk_Item, state), TK_CONFIG_NULL_OK, + {TK_CONFIG_CUSTOM, "-state", NULL, NULL, + NULL, Tk_Offset(Tk_Item, state), TK_CONFIG_NULL_OK, &stateOption}, - {TK_CONFIG_CUSTOM, "-tags", (char *) NULL, (char *) NULL, - (char *) NULL, 0, TK_CONFIG_NULL_OK, &tagsOption}, - {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL, - (char *) NULL, 0, 0} + {TK_CONFIG_CUSTOM, "-tags", NULL, NULL, + NULL, 0, TK_CONFIG_NULL_OK, &tagsOption}, + {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0} }; /* - * Prototypes for procedures defined in this file: + * Prototypes for functions defined in this file: */ -static int BitmapCoords _ANSI_ARGS_((Tcl_Interp *interp, +static int BitmapCoords(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int objc, - Tcl_Obj *CONST objv[])); -static int BitmapToArea _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, double *rectPtr)); -static double BitmapToPoint _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, double *coordPtr)); -static int BitmapToPostscript _ANSI_ARGS_((Tcl_Interp *interp, - Tk_Canvas canvas, Tk_Item *itemPtr, int prepass)); -static void ComputeBitmapBbox _ANSI_ARGS_((Tk_Canvas canvas, - BitmapItem *bmapPtr)); -static int ConfigureBitmap _ANSI_ARGS_((Tcl_Interp *interp, + Tcl_Obj *CONST objv[]); +static int BitmapToArea(Tk_Canvas canvas, + Tk_Item *itemPtr, double *rectPtr); +static double BitmapToPoint(Tk_Canvas canvas, + Tk_Item *itemPtr, double *coordPtr); +static int BitmapToPostscript(Tcl_Interp *interp, + Tk_Canvas canvas, Tk_Item *itemPtr, int prepass); +static void ComputeBitmapBbox(Tk_Canvas canvas, + BitmapItem *bmapPtr); +static int ConfigureBitmap(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int objc, - Tcl_Obj *CONST objv[], int flags)); -static int TkcCreateBitmap _ANSI_ARGS_((Tcl_Interp *interp, + Tcl_Obj *CONST objv[], int flags); +static int TkcCreateBitmap(Tcl_Interp *interp, Tk_Canvas canvas, struct Tk_Item *itemPtr, - int objc, Tcl_Obj *CONST objv[])); -static void DeleteBitmap _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, Display *display)); -static void DisplayBitmap _ANSI_ARGS_((Tk_Canvas canvas, + int objc, Tcl_Obj *CONST objv[]); +static void DeleteBitmap(Tk_Canvas canvas, + Tk_Item *itemPtr, Display *display); +static void DisplayBitmap(Tk_Canvas canvas, Tk_Item *itemPtr, Display *display, Drawable dst, - int x, int y, int width, int height)); -static void ScaleBitmap _ANSI_ARGS_((Tk_Canvas canvas, + int x, int y, int width, int height); +static void ScaleBitmap(Tk_Canvas canvas, Tk_Item *itemPtr, double originX, double originY, - double scaleX, double scaleY)); -static void TranslateBitmap _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, double deltaX, double deltaY)); + double scaleX, double scaleY); +static void TranslateBitmap(Tk_Canvas canvas, Tk_Item *itemPtr, + double deltaX, double deltaY); /* - * The structures below defines the bitmap item type in terms of - * procedures that can be invoked by generic item code. + * The structures below defines the bitmap item type in terms of functions + * that can be invoked by generic item code. */ Tk_ItemType tkBitmapType = { - "bitmap", /* name */ - sizeof(BitmapItem), /* itemSize */ - TkcCreateBitmap, /* createProc */ - configSpecs, /* configSpecs */ - ConfigureBitmap, /* configureProc */ - BitmapCoords, /* coordProc */ - DeleteBitmap, /* deleteProc */ - DisplayBitmap, /* displayProc */ - TK_CONFIG_OBJS, /* flags */ - BitmapToPoint, /* pointProc */ - BitmapToArea, /* areaProc */ - BitmapToPostscript, /* postscriptProc */ - ScaleBitmap, /* scaleProc */ - TranslateBitmap, /* translateProc */ - (Tk_ItemIndexProc *) NULL, /* indexProc */ - (Tk_ItemCursorProc *) NULL, /* icursorProc */ - (Tk_ItemSelectionProc *) NULL, /* selectionProc */ - (Tk_ItemInsertProc *) NULL, /* insertProc */ - (Tk_ItemDCharsProc *) NULL, /* dTextProc */ - (Tk_ItemType *) NULL, /* nextPtr */ + "bitmap", /* name */ + sizeof(BitmapItem), /* itemSize */ + TkcCreateBitmap, /* createProc */ + configSpecs, /* configSpecs */ + ConfigureBitmap, /* configureProc */ + BitmapCoords, /* coordProc */ + DeleteBitmap, /* deleteProc */ + DisplayBitmap, /* displayProc */ + TK_CONFIG_OBJS, /* flags */ + BitmapToPoint, /* pointProc */ + BitmapToArea, /* areaProc */ + BitmapToPostscript, /* postscriptProc */ + ScaleBitmap, /* scaleProc */ + TranslateBitmap, /* translateProc */ + NULL, /* indexProc */ + NULL, /* icursorProc */ + NULL, /* selectionProc */ + NULL, /* insertProc */ + NULL, /* dTextProc */ + NULL, /* nextPtr */ }; /* @@ -152,14 +150,13 @@ Tk_ItemType tkBitmapType = { * * TkcCreateBitmap -- * - * This procedure is invoked to create a new bitmap - * item in a canvas. + * This function is invoked to create a new bitmap item in a canvas. * * Results: - * A standard Tcl return value. If an error occurred in - * creating the item, then an error message is left in - * the interp's result; in this case itemPtr is left uninitialized, - * so it can be safely freed by the caller. + * A standard Tcl return value. If an error occurred in creating the + * item, then an error message is left in the interp's result; in this + * case itemPtr is left uninitialized, so it can be safely freed by the + * caller. * * Side effects: * A new bitmap item is created. @@ -168,13 +165,13 @@ Tk_ItemType tkBitmapType = { */ static int -TkcCreateBitmap(interp, canvas, itemPtr, objc, objv) - Tcl_Interp *interp; /* Interpreter for error reporting. */ - Tk_Canvas canvas; /* Canvas to hold new item. */ - 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 rectangle. */ +TkcCreateBitmap( + Tcl_Interp *interp, /* Interpreter for error reporting. */ + Tk_Canvas canvas, /* Canvas to hold new item. */ + 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 rectangle. */ { BitmapItem *bmapPtr = (BitmapItem *) itemPtr; int i; @@ -200,8 +197,8 @@ TkcCreateBitmap(interp, canvas, itemPtr, objc, objv) bmapPtr->gc = None; /* - * Process the arguments to fill in the item record. - * Only 1 (list) or 2 (x y) coords are allowed. + * Process the arguments to fill in the item record. Only 1 (list) or 2 (x + * y) coords are allowed. */ if (objc == 1) { @@ -221,7 +218,7 @@ TkcCreateBitmap(interp, canvas, itemPtr, objc, objv) return TCL_OK; } - error: + error: DeleteBitmap(canvas, itemPtr, Tk_Display(Tk_CanvasTkwin(canvas))); return TCL_ERROR; } @@ -231,9 +228,8 @@ TkcCreateBitmap(interp, canvas, itemPtr, objc, objv) * * BitmapCoords -- * - * This procedure is invoked to process the "coords" widget - * command on bitmap items. See the user documentation for - * details on what it does. + * This function is invoked to process the "coords" widget command on + * bitmap items. See the user documentation for details on what it does. * * Results: * Returns TCL_OK or TCL_ERROR, and sets the interp's result. @@ -245,20 +241,19 @@ TkcCreateBitmap(interp, canvas, itemPtr, objc, objv) */ static int -BitmapCoords(interp, canvas, itemPtr, objc, objv) - Tcl_Interp *interp; /* Used for error reporting. */ - Tk_Canvas canvas; /* Canvas containing item. */ - 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, ... */ +BitmapCoords( + Tcl_Interp *interp, /* Used for error reporting. */ + Tk_Canvas canvas, /* Canvas containing item. */ + 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, ... */ { BitmapItem *bmapPtr = (BitmapItem *) itemPtr; if (objc == 0) { Tcl_Obj *obj = Tcl_NewObj(); + Tcl_Obj *subobj = Tcl_NewDoubleObj(bmapPtr->x); Tcl_ListObjAppendElement(interp, obj, subobj); subobj = Tcl_NewDoubleObj(bmapPtr->y); @@ -299,12 +294,12 @@ BitmapCoords(interp, canvas, itemPtr, objc, objv) * * ConfigureBitmap -- * - * This procedure is invoked to configure various aspects - * of a bitmap item, such as its anchor position. + * This function is invoked to configure various aspects of a bitmap + * item, such as its anchor position. * * Results: - * A standard Tcl result code. If an error occurs, then - * an error message is left in the interp's result. + * A standard Tcl result code. If an error occurs, then an error message + * is left in the interp's result. * * Side effects: * Configuration information may be set for itemPtr. @@ -313,13 +308,13 @@ BitmapCoords(interp, canvas, itemPtr, objc, objv) */ static int -ConfigureBitmap(interp, canvas, itemPtr, objc, objv, flags) - Tcl_Interp *interp; /* Used for error reporting. */ - Tk_Canvas canvas; /* Canvas containing itemPtr. */ - Tk_Item *itemPtr; /* Bitmap item to reconfigure. */ - int objc; /* Number of elements in objv. */ - Tcl_Obj *CONST objv[]; /* Arguments describing things to configure. */ - int flags; /* Flags to pass to Tk_ConfigureWidget. */ +ConfigureBitmap( + Tcl_Interp *interp, /* Used for error reporting. */ + Tk_Canvas canvas, /* Canvas containing itemPtr. */ + Tk_Item *itemPtr, /* Bitmap item to reconfigure. */ + int objc, /* Number of elements in objv. */ + Tcl_Obj *CONST objv[], /* Arguments describing things to configure. */ + int flags) /* Flags to pass to Tk_ConfigureWidget. */ { BitmapItem *bmapPtr = (BitmapItem *) itemPtr; XGCValues gcValues; @@ -338,8 +333,8 @@ ConfigureBitmap(interp, canvas, itemPtr, objc, objv, flags) } /* - * A few of the options require additional processing, such as those - * that determine the graphics context. + * A few of the options require additional processing, such as those that + * determine the graphics context. */ state = itemPtr->state; @@ -412,8 +407,8 @@ ConfigureBitmap(interp, canvas, itemPtr, objc, objv, flags) * * DeleteBitmap -- * - * This procedure is called to clean up the data structure - * associated with a bitmap item. + * This function is called to clean up the data structure associated with + * a bitmap item. * * Results: * None. @@ -425,11 +420,10 @@ ConfigureBitmap(interp, canvas, itemPtr, objc, objv, flags) */ static void -DeleteBitmap(canvas, itemPtr, display) - Tk_Canvas canvas; /* Info about overall canvas widget. */ - Tk_Item *itemPtr; /* Item that is being deleted. */ - Display *display; /* Display containing window for - * canvas. */ +DeleteBitmap( + Tk_Canvas canvas, /* Info about overall canvas widget. */ + Tk_Item *itemPtr, /* Item that is being deleted. */ + Display *display) /* Display containing window for canvas. */ { BitmapItem *bmapPtr = (BitmapItem *) itemPtr; @@ -470,27 +464,24 @@ DeleteBitmap(canvas, itemPtr, display) * * ComputeBitmapBbox -- * - * This procedure is invoked to compute the bounding box of - * all the pixels that may be drawn as part of a bitmap item. - * This procedure is where the child bitmap's placement is - * computed. + * This function is invoked to compute the bounding box of all the pixels + * that may be drawn as part of a bitmap item. This function is where the + * child bitmap's placement is computed. * * Results: * None. * * Side effects: - * The fields x1, y1, x2, and y2 are updated in the header - * for itemPtr. + * The fields x1, y1, x2, and y2 are updated in the header for itemPtr. * *-------------------------------------------------------------- */ /* ARGSUSED */ static void -ComputeBitmapBbox(canvas, bmapPtr) - Tk_Canvas canvas; /* Canvas that contains item. */ - BitmapItem *bmapPtr; /* Item whose bbox is to be - * recomputed. */ +ComputeBitmapBbox( + Tk_Canvas canvas, /* Canvas that contains item. */ + BitmapItem *bmapPtr) /* Item whose bbox is to be recomputed. */ { int width, height; int x, y; @@ -527,36 +518,36 @@ ComputeBitmapBbox(canvas, bmapPtr) Tk_SizeOfBitmap(Tk_Display(Tk_CanvasTkwin(canvas)), bitmap, &width, &height); switch (bmapPtr->anchor) { - case TK_ANCHOR_N: - x -= width/2; - break; - case TK_ANCHOR_NE: - x -= width; - break; - case TK_ANCHOR_E: - x -= width; - y -= height/2; - break; - case TK_ANCHOR_SE: - x -= width; - y -= height; - break; - case TK_ANCHOR_S: - x -= width/2; - y -= height; - break; - case TK_ANCHOR_SW: - y -= height; - break; - case TK_ANCHOR_W: - y -= height/2; - break; - case TK_ANCHOR_NW: - break; - case TK_ANCHOR_CENTER: - x -= width/2; - y -= height/2; - break; + case TK_ANCHOR_N: + x -= width/2; + break; + case TK_ANCHOR_NE: + x -= width; + break; + case TK_ANCHOR_E: + x -= width; + y -= height/2; + break; + case TK_ANCHOR_SE: + x -= width; + y -= height; + break; + case TK_ANCHOR_S: + x -= width/2; + y -= height; + break; + case TK_ANCHOR_SW: + y -= height; + break; + case TK_ANCHOR_W: + y -= height/2; + break; + case TK_ANCHOR_NW: + break; + case TK_ANCHOR_CENTER: + x -= width/2; + y -= height/2; + break; } /* @@ -574,28 +565,27 @@ ComputeBitmapBbox(canvas, bmapPtr) * * DisplayBitmap -- * - * This procedure is invoked to draw a bitmap item in a given - * drawable. + * This function is invoked to draw a bitmap item in a given drawable. * * Results: * None. * * Side effects: - * ItemPtr is drawn in drawable using the transformation - * information in canvas. + * ItemPtr is drawn in drawable using the transformation information in + * canvas. * *-------------------------------------------------------------- */ static void -DisplayBitmap(canvas, itemPtr, display, drawable, x, y, width, height) - Tk_Canvas canvas; /* Canvas that contains item. */ - Tk_Item *itemPtr; /* Item to be displayed. */ - Display *display; /* Display on which to draw item. */ - Drawable drawable; /* Pixmap or window in which to draw - * item. */ - int x, y, width, height; /* Describes region of canvas that - * must be redisplayed (not used). */ +DisplayBitmap( + Tk_Canvas canvas, /* Canvas that contains item. */ + Tk_Item *itemPtr, /* Item to be displayed. */ + Display *display, /* Display on which to draw item. */ + Drawable drawable, /* Pixmap or window in which to draw item. */ + int x, int y, int width, int height) + /* Describes region of canvas that must be + * redisplayed (not used). */ { BitmapItem *bmapPtr = (BitmapItem *) itemPtr; int bmapX, bmapY, bmapWidth, bmapHeight; @@ -604,9 +594,8 @@ DisplayBitmap(canvas, itemPtr, display, drawable, x, y, width, height) Tk_State state = itemPtr->state; /* - * If the area being displayed doesn't cover the whole bitmap, - * then only redisplay the part of the bitmap that needs - * redisplay. + * If the area being displayed doesn't cover the whole bitmap, then only + * redisplay the part of the bitmap that needs redisplay. */ if (state == TK_STATE_NULL) { @@ -652,9 +641,9 @@ DisplayBitmap(canvas, itemPtr, display, drawable, x, y, width, height) &drawableX, &drawableY); /* - * Must modify the mask origin within the graphics context - * to line up with the bitmap's origin (in order to make - * bitmaps with "-background {}" work right). + * Must modify the mask origin within the graphics context to line up + * with the bitmap's origin (in order to make bitmaps with + * "-background {}" work right). */ XSetClipOrigin(display, bmapPtr->gc, drawableX - bmapX, @@ -671,14 +660,14 @@ DisplayBitmap(canvas, itemPtr, display, drawable, x, y, width, height) * * BitmapToPoint -- * - * Computes the distance from a given point to a given - * rectangle, in canvas units. + * Computes the distance from a given point to a given rectangle, in + * canvas units. * * Results: - * The return value is 0 if the point whose x and y coordinates - * are coordPtr[0] and coordPtr[1] is inside the bitmap. If the - * point isn't inside the bitmap then the return value is the - * distance from the point to the bitmap. + * The return value is 0 if the point whose x and y coordinates are + * coordPtr[0] and coordPtr[1] is inside the bitmap. If the point isn't + * inside the bitmap then the return value is the distance from the point + * to the bitmap. * * Side effects: * None. @@ -688,10 +677,10 @@ DisplayBitmap(canvas, itemPtr, display, drawable, x, y, width, height) /* ARGSUSED */ static double -BitmapToPoint(canvas, itemPtr, coordPtr) - Tk_Canvas canvas; /* Canvas containing item. */ - Tk_Item *itemPtr; /* Item to check against point. */ - double *coordPtr; /* Pointer to x and y coordinates. */ +BitmapToPoint( + Tk_Canvas canvas, /* Canvas containing item. */ + Tk_Item *itemPtr, /* Item to check against point. */ + double *coordPtr) /* Pointer to x and y coordinates. */ { BitmapItem *bmapPtr = (BitmapItem *) itemPtr; double x1, x2, y1, y2, xDiff, yDiff; @@ -729,14 +718,13 @@ BitmapToPoint(canvas, itemPtr, coordPtr) * * BitmapToArea -- * - * This procedure is called to determine whether an item - * lies entirely inside, entirely outside, or overlapping - * a given rectangle. + * This function is called to determine whether an item lies entirely + * inside, entirely outside, or overlapping a given rectangle. * * Results: - * -1 is returned if the item is entirely outside the area - * given by rectPtr, 0 if it overlaps, and 1 if it is entirely - * inside the given area. + * -1 is returned if the item is entirely outside the area given by + * rectPtr, 0 if it overlaps, and 1 if it is entirely inside the given + * area. * * Side effects: * None. @@ -746,12 +734,12 @@ BitmapToPoint(canvas, itemPtr, coordPtr) /* ARGSUSED */ static int -BitmapToArea(canvas, itemPtr, rectPtr) - Tk_Canvas canvas; /* Canvas containing item. */ - Tk_Item *itemPtr; /* Item to check against rectangle. */ - double *rectPtr; /* Pointer to array of four coordinates - * (x1, y1, x2, y2) describing rectangular - * area. */ +BitmapToArea( + Tk_Canvas canvas, /* Canvas containing item. */ + Tk_Item *itemPtr, /* Item to check against rectangle. */ + double *rectPtr) /* Pointer to array of four coordinates + * (x1,y1,x2,y2) describing rectangular + * area. */ { BitmapItem *bmapPtr = (BitmapItem *) itemPtr; @@ -775,16 +763,16 @@ BitmapToArea(canvas, itemPtr, rectPtr) * * ScaleBitmap -- * - * This procedure is invoked to rescale a bitmap item in a - * canvas. It is one of the standard item procedures for - * bitmap items, and is invoked by the generic canvas code. + * This function is invoked to rescale a bitmap item in a canvas. It is + * one of the standard item functions for bitmap items, and is invoked by + * the generic canvas code. * * Results: * None. * * Side effects: - * The item referred to by itemPtr is rescaled so that the - * following transformation is applied to all point coordinates: + * The item referred to by itemPtr is rescaled so that the following + * transformation is applied to all point coordinates: * x' = originX + scaleX*(x-originX) * y' = originY + scaleY*(y-originY) * @@ -792,12 +780,13 @@ BitmapToArea(canvas, itemPtr, rectPtr) */ static void -ScaleBitmap(canvas, itemPtr, originX, originY, scaleX, scaleY) - Tk_Canvas canvas; /* Canvas containing rectangle. */ - Tk_Item *itemPtr; /* Rectangle to be scaled. */ - double originX, originY; /* Origin about which to scale item. */ - double scaleX; /* Amount to scale in X direction. */ - double scaleY; /* Amount to scale in Y direction. */ +ScaleBitmap( + Tk_Canvas canvas, /* Canvas containing rectangle. */ + Tk_Item *itemPtr, /* Rectangle to be scaled. */ + double originX, double originY, + /* Origin about which to scale item. */ + double scaleX, /* Amount to scale in X direction. */ + double scaleY) /* Amount to scale in Y direction. */ { BitmapItem *bmapPtr = (BitmapItem *) itemPtr; @@ -811,25 +800,24 @@ ScaleBitmap(canvas, itemPtr, originX, originY, scaleX, scaleY) * * TranslateBitmap -- * - * This procedure is called to move an item by a given amount. + * This function is called to move an item by a given amount. * * Results: * None. * * Side effects: - * The position of the item is offset by (xDelta, yDelta), and - * the bounding box is updated in the generic part of the item - * structure. + * The position of the item is offset by (xDelta, yDelta), and the + * bounding box is updated in the generic part of the item structure. * *-------------------------------------------------------------- */ static void -TranslateBitmap(canvas, itemPtr, deltaX, deltaY) - Tk_Canvas canvas; /* Canvas containing item. */ - Tk_Item *itemPtr; /* Item that is being moved. */ - double deltaX, deltaY; /* Amount by which item is to be - * moved. */ +TranslateBitmap( + Tk_Canvas canvas, /* Canvas containing item. */ + Tk_Item *itemPtr, /* Item that is being moved. */ + double deltaX, double deltaY) + /* Amount by which item is to be moved. */ { BitmapItem *bmapPtr = (BitmapItem *) itemPtr; @@ -843,15 +831,13 @@ TranslateBitmap(canvas, itemPtr, deltaX, deltaY) * * BitmapToPostscript -- * - * This procedure is called to generate Postscript for - * bitmap items. + * This function is called to generate Postscript for bitmap items. * * Results: - * The return value is a standard Tcl result. If an error - * occurs in generating Postscript then an error message is - * left in the interp's result, replacing whatever used to be there. - * If no error occurs, then Postscript for the item is appended - * to the result. + * The return value is a standard Tcl result. If an error occurs in + * generating Postscript then an error message is left in the interp's + * result, replacing whatever used to be there. If no error occurs, then + * Postscript for the item is appended to the result. * * Side effects: * None. @@ -860,15 +846,13 @@ TranslateBitmap(canvas, itemPtr, deltaX, deltaY) */ static int -BitmapToPostscript(interp, canvas, itemPtr, prepass) - Tcl_Interp *interp; /* Leave Postscript or error message - * here. */ - Tk_Canvas canvas; /* Information about overall canvas. */ - Tk_Item *itemPtr; /* Item for which Postscript is - * wanted. */ - int prepass; /* 1 means this is a prepass to - * collect font information; 0 means - * final Postscript is being created. */ +BitmapToPostscript( + Tcl_Interp *interp, /* Leave Postscript or error message here. */ + Tk_Canvas canvas, /* Information about overall canvas. */ + Tk_Item *itemPtr, /* Item for which Postscript is wanted. */ + int prepass) /* 1 means this is a prepass to collect font + * information; 0 means final Postscript is + * being created. */ { BitmapItem *bmapPtr = (BitmapItem *) itemPtr; double x, y; @@ -913,8 +897,8 @@ BitmapToPostscript(interp, canvas, itemPtr, prepass) } /* - * Compute the coordinates of the lower-left corner of the bitmap, - * taking into account the anchor position for the bitmp. + * Compute the coordinates of the lower-left corner of the bitmap, taking + * into account the anchor position for the bitmp. */ x = bmapPtr->x; @@ -922,15 +906,15 @@ BitmapToPostscript(interp, canvas, itemPtr, prepass) Tk_SizeOfBitmap(Tk_Display(Tk_CanvasTkwin(canvas)), bitmap, &width, &height); switch (bmapPtr->anchor) { - case TK_ANCHOR_NW: y -= height; break; - case TK_ANCHOR_N: x -= width/2.0; y -= height; break; - case TK_ANCHOR_NE: x -= width; y -= height; break; - case TK_ANCHOR_E: x -= width; y -= height/2.0; break; - case TK_ANCHOR_SE: x -= width; break; - case TK_ANCHOR_S: x -= width/2.0; break; - case TK_ANCHOR_SW: break; - case TK_ANCHOR_W: y -= height/2.0; break; - case TK_ANCHOR_CENTER: x -= width/2.0; y -= height/2.0; break; + case TK_ANCHOR_NW: y -= height; break; + case TK_ANCHOR_N: x -= width/2.0; y -= height; break; + case TK_ANCHOR_NE: x -= width; y -= height; break; + case TK_ANCHOR_E: x -= width; y -= height/2.0; break; + case TK_ANCHOR_SE: x -= width; break; + case TK_ANCHOR_S: x -= width/2.0; break; + case TK_ANCHOR_SW: break; + case TK_ANCHOR_W: y -= height/2.0; break; + case TK_ANCHOR_CENTER: x -= width/2.0; y -= height/2.0; break; } /* @@ -941,18 +925,18 @@ BitmapToPostscript(interp, canvas, itemPtr, prepass) sprintf(buffer, "%.15g %.15g moveto %d 0 rlineto 0 %d rlineto %d %s\n", x, y, width, height, -width, "0 rlineto closepath"); - Tcl_AppendResult(interp, buffer, (char *) NULL); + Tcl_AppendResult(interp, buffer, NULL); if (Tk_CanvasPsColor(interp, canvas, bgColor) != TCL_OK) { return TCL_ERROR; } - Tcl_AppendResult(interp, "fill\n", (char *) NULL); + Tcl_AppendResult(interp, "fill\n", NULL); } /* - * Draw the bitmap, if there is a foreground color. If the bitmap - * is very large, then chop it up into multiple bitmaps, each - * consisting of one or more rows. This is needed because Postscript - * can't handle single strings longer than 64 KBytes long. + * Draw the bitmap, if there is a foreground color. If the bitmap is very + * large, then chop it up into multiple bitmaps, each consisting of one or + * more rows. This is needed because Postscript can't handle single + * strings longer than 64 KBytes long. */ if (fgColor != NULL) { @@ -962,8 +946,7 @@ BitmapToPostscript(interp, canvas, itemPtr, prepass) if (width > 60000) { Tcl_ResetResult(interp); Tcl_AppendResult(interp, "can't generate Postscript", - " for bitmaps more than 60000 pixels wide", - (char *) NULL); + " for bitmaps more than 60000 pixels wide", NULL); return TCL_ERROR; } rowsAtOnce = 60000/width; @@ -971,7 +954,7 @@ BitmapToPostscript(interp, canvas, itemPtr, prepass) rowsAtOnce = 1; } sprintf(buffer, "%.15g %.15g translate\n", x, y+height); - Tcl_AppendResult(interp, buffer, (char *) NULL); + Tcl_AppendResult(interp, buffer, NULL); for (curRow = 0; curRow < height; curRow += rowsAtOnce) { rowsThisTime = rowsAtOnce; if (rowsThisTime > (height - curRow)) { @@ -979,13 +962,21 @@ BitmapToPostscript(interp, canvas, itemPtr, prepass) } sprintf(buffer, "0 -%.15g translate\n%d %d true matrix {\n", (double) rowsThisTime, width, rowsThisTime); - Tcl_AppendResult(interp, buffer, (char *) NULL); + Tcl_AppendResult(interp, buffer, NULL); if (Tk_CanvasPsBitmap(interp, canvas, bitmap, 0, curRow, width, rowsThisTime) != TCL_OK) { return TCL_ERROR; } - Tcl_AppendResult(interp, "\n} imagemask\n", (char *) NULL); + Tcl_AppendResult(interp, "\n} imagemask\n", NULL); } } return TCL_OK; } + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ diff --git a/generic/tkCanvImg.c b/generic/tkCanvImg.c index eed7bb4..d4c4486 100644 --- a/generic/tkCanvImg.c +++ b/generic/tkCanvImg.c @@ -1,4 +1,4 @@ -/* +/* * tkCanvImg.c -- * * This file implements image items for canvas widgets. @@ -6,10 +6,10 @@ * Copyright (c) 1994 The Regents of the University of California. * Copyright (c) 1994-1997 Sun Microsystems, Inc. * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkCanvImg.c,v 1.8 2004/11/17 22:17:11 hobbs Exp $ + * RCS: @(#) $Id: tkCanvImg.c,v 1.9 2005/11/04 15:23:05 dkf Exp $ */ #include <stdio.h> @@ -23,24 +23,24 @@ typedef struct ImageItem { Tk_Item header; /* Generic stuff that's the same for all - * types. MUST BE FIRST IN STRUCTURE. */ + * types. MUST BE FIRST IN STRUCTURE. */ Tk_Canvas canvas; /* Canvas containing the image. */ double x, y; /* Coordinates of positioning point for * image. */ - Tk_Anchor anchor; /* Where to anchor image relative to - * (x,y). */ - char *imageString; /* String describing -image option (malloc-ed). - * NULL means no image right now. */ + Tk_Anchor anchor; /* Where to anchor image relative to (x,y). */ + char *imageString; /* String describing -image option + * (malloc-ed). NULL means no image right + * now. */ char *activeImageString; /* String describing -activeimage option. * NULL means no image right now. */ char *disabledImageString; /* String describing -disabledimage option. * NULL means no image right now. */ - Tk_Image image; /* Image to display in window, or NULL if - * no image at present. */ - Tk_Image activeImage; /* Image to display in window, or NULL if - * no image at present. */ - Tk_Image disabledImage; /* Image to display in window, or NULL if - * no image at present. */ + Tk_Image image; /* Image to display in window, or NULL if no + * image at present. */ + Tk_Image activeImage; /* Image to display in window, or NULL if no + * image at present. */ + Tk_Image disabledImage; /* Image to display in window, or NULL if no + * image at present. */ } ImageItem; /* @@ -57,86 +57,81 @@ static Tk_CustomOption tagsOption = { }; static Tk_ConfigSpec configSpecs[] = { - {TK_CONFIG_STRING, "-activeimage", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(ImageItem, activeImageString), - TK_CONFIG_NULL_OK}, - {TK_CONFIG_ANCHOR, "-anchor", (char *) NULL, (char *) NULL, + {TK_CONFIG_STRING, "-activeimage", NULL, NULL, + NULL, Tk_Offset(ImageItem, activeImageString), TK_CONFIG_NULL_OK}, + {TK_CONFIG_ANCHOR, "-anchor", NULL, NULL, "center", Tk_Offset(ImageItem, anchor), TK_CONFIG_DONT_SET_DEFAULT}, - {TK_CONFIG_STRING, "-disabledimage", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(ImageItem, disabledImageString), - TK_CONFIG_NULL_OK}, - {TK_CONFIG_STRING, "-image", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(ImageItem, imageString), TK_CONFIG_NULL_OK}, - {TK_CONFIG_CUSTOM, "-state", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(Tk_Item, state), TK_CONFIG_NULL_OK, - &stateOption}, - {TK_CONFIG_CUSTOM, "-tags", (char *) NULL, (char *) NULL, - (char *) NULL, 0, TK_CONFIG_NULL_OK, &tagsOption}, - {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL, - (char *) NULL, 0, 0} + {TK_CONFIG_STRING, "-disabledimage", NULL, NULL, + NULL, Tk_Offset(ImageItem, disabledImageString), TK_CONFIG_NULL_OK}, + {TK_CONFIG_STRING, "-image", NULL, NULL, + NULL, Tk_Offset(ImageItem, imageString), TK_CONFIG_NULL_OK}, + {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_END, NULL, NULL, NULL, NULL, 0, 0} }; /* - * Prototypes for procedures defined in this file: + * Prototypes for functions defined in this file: */ -static void ImageChangedProc _ANSI_ARGS_((ClientData clientData, +static void ImageChangedProc(ClientData clientData, int x, int y, int width, int height, int imgWidth, - int imgHeight)); -static int ImageCoords _ANSI_ARGS_((Tcl_Interp *interp, + int imgHeight); +static int ImageCoords(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int argc, - Tcl_Obj *CONST argv[])); -static int ImageToArea _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, double *rectPtr)); -static double ImageToPoint _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, double *coordPtr)); -static int ImageToPostscript _ANSI_ARGS_((Tcl_Interp *interp, - Tk_Canvas canvas, Tk_Item *itemPtr, int prepass)); -static void ComputeImageBbox _ANSI_ARGS_((Tk_Canvas canvas, - ImageItem *imgPtr)); -static int ConfigureImage _ANSI_ARGS_((Tcl_Interp *interp, + Tcl_Obj *CONST argv[]); +static int ImageToArea(Tk_Canvas canvas, + Tk_Item *itemPtr, double *rectPtr); +static double ImageToPoint(Tk_Canvas canvas, + Tk_Item *itemPtr, double *coordPtr); +static int ImageToPostscript(Tcl_Interp *interp, + Tk_Canvas canvas, Tk_Item *itemPtr, int prepass); +static void ComputeImageBbox(Tk_Canvas canvas, ImageItem *imgPtr); +static int ConfigureImage(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int argc, - Tcl_Obj *CONST argv[], int flags)); -static int CreateImage _ANSI_ARGS_((Tcl_Interp *interp, + Tcl_Obj *CONST argv[], int flags); +static int CreateImage(Tcl_Interp *interp, Tk_Canvas canvas, struct Tk_Item *itemPtr, - int argc, Tcl_Obj *CONST argv[])); -static void DeleteImage _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, Display *display)); -static void DisplayImage _ANSI_ARGS_((Tk_Canvas canvas, + int argc, Tcl_Obj *CONST argv[]); +static void DeleteImage(Tk_Canvas canvas, + Tk_Item *itemPtr, Display *display); +static void DisplayImage(Tk_Canvas canvas, Tk_Item *itemPtr, Display *display, Drawable dst, - int x, int y, int width, int height)); -static void ScaleImage _ANSI_ARGS_((Tk_Canvas canvas, + int x, int y, int width, int height); +static void ScaleImage(Tk_Canvas canvas, Tk_Item *itemPtr, double originX, double originY, - double scaleX, double scaleY)); -static void TranslateImage _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, double deltaX, double deltaY)); + double scaleX, double scaleY); +static void TranslateImage(Tk_Canvas canvas, + Tk_Item *itemPtr, double deltaX, double deltaY); /* - * The structures below defines the image item type in terms of - * procedures that can be invoked by generic item code. + * The structures below defines the image item type in terms of functions that + * can be invoked by generic item code. */ Tk_ItemType tkImageType = { - "image", /* name */ - sizeof(ImageItem), /* itemSize */ - CreateImage, /* createProc */ - configSpecs, /* configSpecs */ - ConfigureImage, /* configureProc */ - ImageCoords, /* coordProc */ - DeleteImage, /* deleteProc */ - DisplayImage, /* displayProc */ - TK_CONFIG_OBJS, /* flags */ - ImageToPoint, /* pointProc */ - ImageToArea, /* areaProc */ - ImageToPostscript, /* postscriptProc */ - ScaleImage, /* scaleProc */ - TranslateImage, /* translateProc */ - (Tk_ItemIndexProc *) NULL, /* indexProc */ - (Tk_ItemCursorProc *) NULL, /* icursorProc */ - (Tk_ItemSelectionProc *) NULL, /* selectionProc */ - (Tk_ItemInsertProc *) NULL, /* insertProc */ - (Tk_ItemDCharsProc *) NULL, /* dTextProc */ - (Tk_ItemType *) NULL, /* nextPtr */ + "image", /* name */ + sizeof(ImageItem), /* itemSize */ + CreateImage, /* createProc */ + configSpecs, /* configSpecs */ + ConfigureImage, /* configureProc */ + ImageCoords, /* coordProc */ + DeleteImage, /* deleteProc */ + DisplayImage, /* displayProc */ + TK_CONFIG_OBJS, /* flags */ + ImageToPoint, /* pointProc */ + ImageToArea, /* areaProc */ + ImageToPostscript, /* postscriptProc */ + ScaleImage, /* scaleProc */ + TranslateImage, /* translateProc */ + NULL, /* indexProc */ + NULL, /* icursorProc */ + NULL, /* selectionProc */ + NULL, /* insertProc */ + NULL, /* dTextProc */ + NULL, /* nextPtr */ }; /* @@ -144,14 +139,13 @@ Tk_ItemType tkImageType = { * * CreateImage -- * - * This procedure is invoked to create a new image - * item in a canvas. + * This function is invoked to create a new image item in a canvas. * * Results: - * A standard Tcl return value. If an error occurred in - * creating the item, then an error message is left in - * the interp's result; in this case itemPtr is left uninitialized, - * so it can be safely freed by the caller. + * A standard Tcl return value. If an error occurred in creating the + * item, then an error message is left in the interp's result; in this + * case itemPtr is left uninitialized, so it can be safely freed by the + * caller. * * Side effects: * A new image item is created. @@ -160,13 +154,13 @@ Tk_ItemType tkImageType = { */ static int -CreateImage(interp, canvas, itemPtr, objc, objv) - Tcl_Interp *interp; /* Interpreter for error reporting. */ - Tk_Canvas canvas; /* Canvas to hold new item. */ - 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 rectangle. */ +CreateImage( + Tcl_Interp *interp, /* Interpreter for error reporting. */ + Tk_Canvas canvas, /* Canvas to hold new item. */ + 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 rectangle. */ { ImageItem *imgPtr = (ImageItem *) itemPtr; int i; @@ -189,8 +183,8 @@ CreateImage(interp, canvas, itemPtr, objc, objv) imgPtr->disabledImage = NULL; /* - * Process the arguments to fill in the item record. - * Only 1 (list) or 2 (x y) coords are allowed. + * Process the arguments to fill in the item record. Only 1 (list) or 2 (x + * y) coords are allowed. */ if (objc == 1) { @@ -209,7 +203,7 @@ CreateImage(interp, canvas, itemPtr, objc, objv) return TCL_OK; } - error: + error: DeleteImage(canvas, itemPtr, Tk_Display(Tk_CanvasTkwin(canvas))); return TCL_ERROR; } @@ -219,9 +213,8 @@ CreateImage(interp, canvas, itemPtr, objc, objv) * * ImageCoords -- * - * This procedure is invoked to process the "coords" widget - * command on image items. See the user documentation for - * details on what it does. + * This function is invoked to process the "coords" widget command on + * image items. See the user documentation for details on what it does. * * Results: * Returns TCL_OK or TCL_ERROR, and sets the interp's result. @@ -233,20 +226,19 @@ CreateImage(interp, canvas, itemPtr, objc, objv) */ static int -ImageCoords(interp, canvas, itemPtr, objc, objv) - Tcl_Interp *interp; /* Used for error reporting. */ - Tk_Canvas canvas; /* Canvas containing item. */ - 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, ... */ +ImageCoords( + Tcl_Interp *interp, /* Used for error reporting. */ + Tk_Canvas canvas, /* Canvas containing item. */ + 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, ... */ { ImageItem *imgPtr = (ImageItem *) itemPtr; if (objc == 0) { Tcl_Obj *obj = Tcl_NewObj(); + Tcl_Obj *subobj = Tcl_NewDoubleObj(imgPtr->x); Tcl_ListObjAppendElement(interp, obj, subobj); subobj = Tcl_NewDoubleObj(imgPtr->y); @@ -273,7 +265,7 @@ ImageCoords(interp, canvas, itemPtr, objc, objv) ComputeImageBbox(canvas, imgPtr); } else { char buf[64]; - + sprintf(buf, "wrong # coordinates: expected 0 or 2, got %d", objc); Tcl_SetResult(interp, buf, TCL_VOLATILE); return TCL_ERROR; @@ -286,12 +278,12 @@ ImageCoords(interp, canvas, itemPtr, objc, objv) * * ConfigureImage -- * - * This procedure is invoked to configure various aspects - * of an image item, such as its anchor position. + * This function is invoked to configure various aspects of an image + * item, such as its anchor position. * * Results: - * A standard Tcl result code. If an error occurs, then - * an error message is left in the interp's result. + * A standard Tcl result code. If an error occurs, then an error message + * is left in the interp's result. * * Side effects: * Configuration information may be set for itemPtr. @@ -300,13 +292,13 @@ ImageCoords(interp, canvas, itemPtr, objc, objv) */ static int -ConfigureImage(interp, canvas, itemPtr, objc, objv, flags) - Tcl_Interp *interp; /* Used for error reporting. */ - Tk_Canvas canvas; /* Canvas containing itemPtr. */ - Tk_Item *itemPtr; /* Image item to reconfigure. */ - int objc; /* Number of elements in objv. */ - Tcl_Obj *CONST objv[]; /* Arguments describing things to configure. */ - int flags; /* Flags to pass to Tk_ConfigureWidget. */ +ConfigureImage( + Tcl_Interp *interp, /* Used for error reporting. */ + Tk_Canvas canvas, /* Canvas containing itemPtr. */ + Tk_Item *itemPtr, /* Image item to reconfigure. */ + int objc, /* Number of elements in objv. */ + Tcl_Obj *CONST objv[], /* Arguments describing things to configure. */ + int flags) /* Flags to pass to Tk_ConfigureWidget. */ { ImageItem *imgPtr = (ImageItem *) itemPtr; Tk_Window tkwin; @@ -319,10 +311,10 @@ ConfigureImage(interp, canvas, itemPtr, objc, objv, flags) } /* - * Create the image. Save the old image around and don't free it - * until after the new one is allocated. This keeps the reference - * count from going to zero so the image doesn't have to be recreated - * if it hasn't changed. + * Create the image. Save the old image around and don't free it until + * after the new one is allocated. This keeps the reference count from + * going to zero so the image doesn't have to be recreated if it hasn't + * changed. */ if (imgPtr->activeImageString != NULL) { @@ -378,8 +370,8 @@ ConfigureImage(interp, canvas, itemPtr, objc, objv, flags) * * DeleteImage -- * - * This procedure is called to clean up the data structure - * associated with a image item. + * This function is called to clean up the data structure associated with + * a image item. * * Results: * None. @@ -391,11 +383,10 @@ ConfigureImage(interp, canvas, itemPtr, objc, objv, flags) */ static void -DeleteImage(canvas, itemPtr, display) - Tk_Canvas canvas; /* Info about overall canvas widget. */ - Tk_Item *itemPtr; /* Item that is being deleted. */ - Display *display; /* Display containing window for - * canvas. */ +DeleteImage( + Tk_Canvas canvas, /* Info about overall canvas widget. */ + Tk_Item *itemPtr, /* Item that is being deleted. */ + Display *display) /* Display containing window for canvas. */ { ImageItem *imgPtr = (ImageItem *) itemPtr; @@ -424,27 +415,24 @@ DeleteImage(canvas, itemPtr, display) * * ComputeImageBbox -- * - * This procedure is invoked to compute the bounding box of - * all the pixels that may be drawn as part of a image item. - * This procedure is where the child image's placement is - * computed. + * This function is invoked to compute the bounding box of all the pixels + * that may be drawn as part of a image item. This function is where the + * child image's placement is computed. * * Results: * None. * * Side effects: - * The fields x1, y1, x2, and y2 are updated in the header - * for itemPtr. + * The fields x1, y1, x2, and y2 are updated in the header for itemPtr. * *-------------------------------------------------------------- */ /* ARGSUSED */ static void -ComputeImageBbox(canvas, imgPtr) - Tk_Canvas canvas; /* Canvas that contains item. */ - ImageItem *imgPtr; /* Item whose bbox is to be - * recomputed. */ +ComputeImageBbox( + Tk_Canvas canvas, /* Canvas that contains item. */ + ImageItem *imgPtr) /* Item whose bbox is to be recomputed. */ { int width, height; int x, y; @@ -480,36 +468,36 @@ ComputeImageBbox(canvas, imgPtr) Tk_SizeOfImage(image, &width, &height); switch (imgPtr->anchor) { - case TK_ANCHOR_N: - x -= width/2; - break; - case TK_ANCHOR_NE: - x -= width; - break; - case TK_ANCHOR_E: - x -= width; - y -= height/2; - break; - case TK_ANCHOR_SE: - x -= width; - y -= height; - break; - case TK_ANCHOR_S: - x -= width/2; - y -= height; - break; - case TK_ANCHOR_SW: - y -= height; - break; - case TK_ANCHOR_W: - y -= height/2; - break; - case TK_ANCHOR_NW: - break; - case TK_ANCHOR_CENTER: - x -= width/2; - y -= height/2; - break; + case TK_ANCHOR_N: + x -= width/2; + break; + case TK_ANCHOR_NE: + x -= width; + break; + case TK_ANCHOR_E: + x -= width; + y -= height/2; + break; + case TK_ANCHOR_SE: + x -= width; + y -= height; + break; + case TK_ANCHOR_S: + x -= width/2; + y -= height; + break; + case TK_ANCHOR_SW: + y -= height; + break; + case TK_ANCHOR_W: + y -= height/2; + break; + case TK_ANCHOR_NW: + break; + case TK_ANCHOR_CENTER: + x -= width/2; + y -= height/2; + break; } /* @@ -527,35 +515,34 @@ ComputeImageBbox(canvas, imgPtr) * * DisplayImage -- * - * This procedure is invoked to draw a image item in a given - * drawable. + * This function is invoked to draw a image item in a given drawable. * * Results: * None. * * Side effects: - * ItemPtr is drawn in drawable using the transformation - * information in canvas. + * ItemPtr is drawn in drawable using the transformation information in + * canvas. * *-------------------------------------------------------------- */ static void -DisplayImage(canvas, itemPtr, display, drawable, x, y, width, height) - Tk_Canvas canvas; /* Canvas that contains item. */ - Tk_Item *itemPtr; /* Item to be displayed. */ - Display *display; /* Display on which to draw item. */ - Drawable drawable; /* Pixmap or window in which to draw - * item. */ - int x, y, width, height; /* Describes region of canvas that - * must be redisplayed (not used). */ +DisplayImage( + Tk_Canvas canvas, /* Canvas that contains item. */ + Tk_Item *itemPtr, /* Item to be displayed. */ + Display *display, /* Display on which to draw item. */ + Drawable drawable, /* Pixmap or window in which to draw item. */ + int x, int y, int width, int height) + /* Describes region of canvas that must be + * redisplayed (not used). */ { ImageItem *imgPtr = (ImageItem *) itemPtr; short drawableX, drawableY; Tk_Image image; Tk_State state = itemPtr->state; - if(state == TK_STATE_NULL) { + if (state == TK_STATE_NULL) { state = ((TkCanvas *)canvas)->canvas_state; } @@ -589,14 +576,14 @@ DisplayImage(canvas, itemPtr, display, drawable, x, y, width, height) * * ImageToPoint -- * - * Computes the distance from a given point to a given - * rectangle, in canvas units. + * Computes the distance from a given point to a given rectangle, in + * canvas units. * * Results: - * The return value is 0 if the point whose x and y coordinates - * are coordPtr[0] and coordPtr[1] is inside the image. If the - * point isn't inside the image then the return value is the - * distance from the point to the image. + * The return value is 0 if the point whose x and y coordinates are + * coordPtr[0] and coordPtr[1] is inside the image. If the point isn't + * inside the image then the return value is the distance from the point + * to the image. * * Side effects: * None. @@ -605,10 +592,10 @@ DisplayImage(canvas, itemPtr, display, drawable, x, y, width, height) */ static double -ImageToPoint(canvas, itemPtr, coordPtr) - Tk_Canvas canvas; /* Canvas containing item. */ - Tk_Item *itemPtr; /* Item to check against point. */ - double *coordPtr; /* Pointer to x and y coordinates. */ +ImageToPoint( + Tk_Canvas canvas, /* Canvas containing item. */ + Tk_Item *itemPtr, /* Item to check against point. */ + double *coordPtr) /* Pointer to x and y coordinates. */ { ImageItem *imgPtr = (ImageItem *) itemPtr; double x1, x2, y1, y2, xDiff, yDiff; @@ -646,14 +633,13 @@ ImageToPoint(canvas, itemPtr, coordPtr) * * ImageToArea -- * - * This procedure is called to determine whether an item - * lies entirely inside, entirely outside, or overlapping - * a given rectangle. + * This function is called to determine whether an item lies entirely + * inside, entirely outside, or overlapping a given rectangle. * * Results: - * -1 is returned if the item is entirely outside the area - * given by rectPtr, 0 if it overlaps, and 1 if it is entirely - * inside the given area. + * -1 is returned if the item is entirely outside the area given by + * rectPtr, 0 if it overlaps, and 1 if it is entirely inside the given + * area. * * Side effects: * None. @@ -662,12 +648,12 @@ ImageToPoint(canvas, itemPtr, coordPtr) */ static int -ImageToArea(canvas, itemPtr, rectPtr) - Tk_Canvas canvas; /* Canvas containing item. */ - Tk_Item *itemPtr; /* Item to check against rectangle. */ - double *rectPtr; /* Pointer to array of four coordinates - * (x1, y1, x2, y2) describing rectangular - * area. */ +ImageToArea( + Tk_Canvas canvas, /* Canvas containing item. */ + Tk_Item *itemPtr, /* Item to check against rectangle. */ + double *rectPtr) /* Pointer to array of four coordinates + * (x1,y1,x2,y2) describing rectangular + * area. */ { ImageItem *imgPtr = (ImageItem *) itemPtr; @@ -691,15 +677,13 @@ ImageToArea(canvas, itemPtr, rectPtr) * * ImageToPostscript -- * - * This procedure is called to generate Postscript for - * image items. + * This function is called to generate Postscript for image items. * * Results: - * The return value is a standard Tcl result. If an error - * occurs in generating Postscript then an error message is - * left in interp->result, replacing whatever used to be there. - * If no error occurs, then Postscript for the item is appended - * to the result. + * The return value is a standard Tcl result. If an error occurs in + * generating Postscript then an error message is left in interp->result, + * replacing whatever used to be there. If no error occurs, then + * Postscript for the item is appended to the result. * * Side effects: * None. @@ -708,15 +692,13 @@ ImageToArea(canvas, itemPtr, rectPtr) */ static int -ImageToPostscript(interp, canvas, itemPtr, prepass) - Tcl_Interp *interp; /* Leave Postscript or error message - * here. */ - Tk_Canvas canvas; /* Information about overall canvas. */ - Tk_Item *itemPtr; /* Item for which Postscript is - * wanted. */ - int prepass; /* 1 means this is a prepass to - * collect font information; 0 means - * final Postscript is being created.*/ +ImageToPostscript( + Tcl_Interp *interp, /* Leave Postscript or error message here. */ + Tk_Canvas canvas, /* Information about overall canvas. */ + Tk_Item *itemPtr, /* Item for which Postscript is wanted. */ + int prepass) /* 1 means this is a prepass to collect font + * information; 0 means final Postscript is + * being created.*/ { ImageItem *imgPtr = (ImageItem *)itemPtr; Tk_Window canvasWin = Tk_CanvasTkwin(canvas); @@ -745,33 +727,34 @@ ImageToPostscript(interp, canvas, itemPtr, prepass) /* * Image item without actual image specified. */ + return TCL_OK; } Tk_SizeOfImage(image, &width, &height); /* - * Compute the coordinates of the lower-left corner of the image, - * taking into account the anchor position for the image. + * Compute the coordinates of the lower-left corner of the image, taking + * into account the anchor position for the image. */ x = imgPtr->x; y = Tk_CanvasPsY(canvas, imgPtr->y); switch (imgPtr->anchor) { - case TK_ANCHOR_NW: y -= height; break; - case TK_ANCHOR_N: x -= width/2.0; y -= height; break; - case TK_ANCHOR_NE: x -= width; y -= height; break; - case TK_ANCHOR_E: x -= width; y -= height/2.0; break; - case TK_ANCHOR_SE: x -= width; break; - case TK_ANCHOR_S: x -= width/2.0; break; - case TK_ANCHOR_SW: break; - case TK_ANCHOR_W: y -= height/2.0; break; - case TK_ANCHOR_CENTER: x -= width/2.0; y -= height/2.0; break; + case TK_ANCHOR_NW: y -= height; break; + case TK_ANCHOR_N: x -= width/2.0; y -= height; break; + case TK_ANCHOR_NE: x -= width; y -= height; break; + case TK_ANCHOR_E: x -= width; y -= height/2.0; break; + case TK_ANCHOR_SE: x -= width; break; + case TK_ANCHOR_S: x -= width/2.0; break; + case TK_ANCHOR_SW: break; + case TK_ANCHOR_W: y -= height/2.0; break; + case TK_ANCHOR_CENTER: x -= width/2.0; y -= height/2.0; break; } if (!prepass) { sprintf(buffer, "%.15g %.15g", x, y); - Tcl_AppendResult(interp, buffer, " translate\n", (char *) NULL); + Tcl_AppendResult(interp, buffer, " translate\n", NULL); } return Tk_PostscriptImage(image, interp, canvasWin, @@ -783,14 +766,14 @@ ImageToPostscript(interp, canvas, itemPtr, prepass) * * ScaleImage -- * - * This procedure is invoked to rescale an item. + * This function is invoked to rescale an item. * * Results: * None. * * Side effects: - * The item referred to by itemPtr is rescaled so that the - * following transformation is applied to all point coordinates: + * The item referred to by itemPtr is rescaled so that the following + * transformation is applied to all point coordinates: * x' = originX + scaleX*(x-originX) * y' = originY + scaleY*(y-originY) * @@ -798,12 +781,13 @@ ImageToPostscript(interp, canvas, itemPtr, prepass) */ static void -ScaleImage(canvas, itemPtr, originX, originY, scaleX, scaleY) - Tk_Canvas canvas; /* Canvas containing rectangle. */ - Tk_Item *itemPtr; /* Rectangle to be scaled. */ - double originX, originY; /* Origin about which to scale rect. */ - double scaleX; /* Amount to scale in X direction. */ - double scaleY; /* Amount to scale in Y direction. */ +ScaleImage( + Tk_Canvas canvas, /* Canvas containing rectangle. */ + Tk_Item *itemPtr, /* Rectangle to be scaled. */ + double originX, double originY, + /* Origin about which to scale rect. */ + double scaleX, /* Amount to scale in X direction. */ + double scaleY) /* Amount to scale in Y direction. */ { ImageItem *imgPtr = (ImageItem *) itemPtr; @@ -817,25 +801,24 @@ ScaleImage(canvas, itemPtr, originX, originY, scaleX, scaleY) * * TranslateImage -- * - * This procedure is called to move an item by a given amount. + * This function is called to move an item by a given amount. * * Results: * None. * * Side effects: - * The position of the item is offset by (xDelta, yDelta), and - * the bounding box is updated in the generic part of the item - * structure. + * The position of the item is offset by (xDelta, yDelta), and the + * bounding box is updated in the generic part of the item structure. * *-------------------------------------------------------------- */ static void -TranslateImage(canvas, itemPtr, deltaX, deltaY) - Tk_Canvas canvas; /* Canvas containing item. */ - Tk_Item *itemPtr; /* Item that is being moved. */ - double deltaX, deltaY; /* Amount by which item is to be - * moved. */ +TranslateImage( + Tk_Canvas canvas, /* Canvas containing item. */ + Tk_Item *itemPtr, /* Item that is being moved. */ + double deltaX, double deltaY) + /* Amount by which item is to be moved. */ { ImageItem *imgPtr = (ImageItem *) itemPtr; @@ -849,9 +832,9 @@ TranslateImage(canvas, itemPtr, deltaX, deltaY) * * ImageChangedProc -- * - * This procedure is invoked by the image code whenever the manager - * for an image does something that affects the image's size or - * how it is displayed. + * This function is invoked by the image code whenever the manager for an + * image does something that affects the image's size or how it is + * displayed. * * Results: * None. @@ -863,21 +846,21 @@ TranslateImage(canvas, itemPtr, deltaX, deltaY) */ static void -ImageChangedProc(clientData, x, y, width, height, imgWidth, imgHeight) - ClientData clientData; /* Pointer to canvas item for image. */ - int x, y; /* Upper left pixel (within image) - * that must be redisplayed. */ - int width, height; /* Dimensions of area to redisplay - * (may be <= 0). */ - int imgWidth, imgHeight; /* New dimensions of image. */ +ImageChangedProc( + ClientData clientData, /* Pointer to canvas item for image. */ + int x, int y, /* Upper left pixel (within image) that must + * be redisplayed. */ + int width, int height, /* Dimensions of area to redisplay (may be <= + * 0). */ + int imgWidth, int imgHeight)/* New dimensions of image. */ { ImageItem *imgPtr = (ImageItem *) clientData; /* - * If the image's size changed and it's not anchored at its - * northwest corner then just redisplay the entire area of the - * image. This is a bit over-conservative, but we need to do - * something because a size change also means a position change. + * If the image's size changed and it's not anchored at its northwest + * corner then just redisplay the entire area of the image. This is a bit + * over-conservative, but we need to do something because a size change + * also means a position change. */ if (((imgPtr->header.x2 - imgPtr->header.x1) != imgWidth) @@ -887,9 +870,17 @@ ImageChangedProc(clientData, x, y, width, height, imgWidth, imgHeight) height = imgHeight; Tk_CanvasEventuallyRedraw(imgPtr->canvas, imgPtr->header.x1, imgPtr->header.y1, imgPtr->header.x2, imgPtr->header.y2); - } + } ComputeImageBbox(imgPtr->canvas, imgPtr); Tk_CanvasEventuallyRedraw(imgPtr->canvas, imgPtr->header.x1 + x, imgPtr->header.y1 + y, (int) (imgPtr->header.x1 + x + width), (int) (imgPtr->header.y1 + y + height)); } + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ diff --git a/generic/tkCanvLine.c b/generic/tkCanvLine.c index a219b63..cd02c18 100644 --- a/generic/tkCanvLine.c +++ b/generic/tkCanvLine.c @@ -1,4 +1,4 @@ -/* +/* * tkCanvLine.c -- * * This file implements line items for canvas widgets. @@ -7,10 +7,10 @@ * Copyright (c) 1994-1997 Sun Microsystems, Inc. * Copyright (c) 1998-1999 by Scriptics Corporation. * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkCanvLine.c,v 1.16 2005/08/10 22:02:22 dkf Exp $ + * RCS: @(#) $Id: tkCanvLine.c,v 1.17 2005/11/04 15:23:05 dkf Exp $ */ #include <stdio.h> @@ -28,21 +28,21 @@ typedef enum { typedef struct LineItem { Tk_Item header; /* Generic stuff that's the same for all - * types. MUST BE FIRST IN STRUCTURE. */ + * types. MUST BE FIRST IN STRUCTURE. */ Tk_Outline outline; /* Outline structure */ - Tk_Canvas canvas; /* Canvas containing item. Needed for - * parsing arrow shapes. */ + Tk_Canvas canvas; /* Canvas containing item. Needed for parsing + * arrow shapes. */ int numPoints; /* Number of points in line (always >= 0). */ - double *coordPtr; /* Pointer to malloc-ed array containing - * x- and y-coords of all points in line. + double *coordPtr; /* Pointer to malloc-ed array containing x- + * and y-coords of all points in line. * X-coords are even-valued indices, y-coords * are corresponding odd-valued indices. If - * the line has arrowheads then the first - * and last points have been adjusted to refer - * to the necks of the arrowheads rather than - * their tips. The actual endpoints are - * stored in the *firstArrowPtr and - * *lastArrowPtr, if they exist. */ + * the line has arrowheads then the first and + * last points have been adjusted to refer to + * the necks of the arrowheads rather than + * their tips. The actual endpoints are stored + * in the *firstArrowPtr and *lastArrowPtr, if + * they exist. */ int capStyle; /* Cap style for line. */ int joinStyle; /* Join style for line. */ GC arrowGC; /* Graphics context for drawing arrowheads. */ @@ -55,13 +55,13 @@ typedef struct LineItem { * edge of shaft. */ double *firstArrowPtr; /* Points to array of PTS_IN_ARROW points * describing polygon for arrowhead at first - * point in line. First point of arrowhead - * is tip. Malloc'ed. NULL means no arrowhead - * at first point. */ + * point in line. First point of arrowhead is + * tip. Malloc'ed. NULL means no arrowhead at + * first point. */ double *lastArrowPtr; /* Points to polygon for arrowhead at last * point in line (PTS_IN_ARROW points, first - * of which is tip). Malloc'ed. NULL means - * no arrowhead at last point. */ + * of which is tip). Malloc'ed. NULL means no + * arrowhead at last point. */ Tk_SmoothMethod *smooth; /* Non-zero means draw line smoothed (i.e. * with Bezier splines). */ int splineSteps; /* Number of steps in each spline segment. */ @@ -74,65 +74,63 @@ typedef struct LineItem { #define PTS_IN_ARROW 6 /* - * Prototypes for procedures defined in this file: + * Prototypes for functions defined in this file: */ -static int ArrowheadPostscript _ANSI_ARGS_((Tcl_Interp *interp, +static int ArrowheadPostscript(Tcl_Interp *interp, Tk_Canvas canvas, LineItem *linePtr, - double *arrowPtr)); -static void ComputeLineBbox _ANSI_ARGS_((Tk_Canvas canvas, - LineItem *linePtr)); -static int ConfigureLine _ANSI_ARGS_((Tcl_Interp *interp, + double *arrowPtr); +static void ComputeLineBbox(Tk_Canvas canvas, LineItem *linePtr); +static int ConfigureLine(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int objc, - Tcl_Obj *CONST objv[], int flags)); -static int ConfigureArrows _ANSI_ARGS_((Tk_Canvas canvas, - LineItem *linePtr)); -static int CreateLine _ANSI_ARGS_((Tcl_Interp *interp, + Tcl_Obj *CONST objv[], int flags); +static int ConfigureArrows(Tk_Canvas canvas, LineItem *linePtr); +static int CreateLine(Tcl_Interp *interp, Tk_Canvas canvas, struct Tk_Item *itemPtr, - int objc, Tcl_Obj *CONST objv[])); -static void DeleteLine _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, Display *display)); -static void DisplayLine _ANSI_ARGS_((Tk_Canvas canvas, + int objc, Tcl_Obj *CONST objv[]); +static void DeleteLine(Tk_Canvas canvas, + Tk_Item *itemPtr, Display *display); +static void DisplayLine(Tk_Canvas canvas, Tk_Item *itemPtr, Display *display, Drawable dst, - int x, int y, int width, int height)); -static int GetLineIndex _ANSI_ARGS_((Tcl_Interp *interp, + int x, int y, int width, int height); +static int GetLineIndex(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, - Tcl_Obj *obj, int *indexPtr)); -static int LineCoords _ANSI_ARGS_((Tcl_Interp *interp, + Tcl_Obj *obj, int *indexPtr); +static int LineCoords(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, - int objc, Tcl_Obj *CONST objv[])); -static void LineDeleteCoords _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, int first, int last)); -static void LineInsert _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, int beforeThis, Tcl_Obj *obj)); -static int LineToArea _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, double *rectPtr)); -static double LineToPoint _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, double *coordPtr)); -static int LineToPostscript _ANSI_ARGS_((Tcl_Interp *interp, - Tk_Canvas canvas, Tk_Item *itemPtr, int prepass)); -static int ArrowParseProc _ANSI_ARGS_((ClientData clientData, + int objc, Tcl_Obj *CONST objv[]); +static void LineDeleteCoords(Tk_Canvas canvas, + Tk_Item *itemPtr, int first, int last); +static void LineInsert(Tk_Canvas canvas, + Tk_Item *itemPtr, int beforeThis, Tcl_Obj *obj); +static int LineToArea(Tk_Canvas canvas, + Tk_Item *itemPtr, double *rectPtr); +static double LineToPoint(Tk_Canvas canvas, + Tk_Item *itemPtr, double *coordPtr); +static int LineToPostscript(Tcl_Interp *interp, + Tk_Canvas canvas, Tk_Item *itemPtr, int prepass); +static int ArrowParseProc(ClientData clientData, Tcl_Interp *interp, Tk_Window tkwin, - CONST char *value, char *recordPtr, int offset)); -static char * ArrowPrintProc _ANSI_ARGS_((ClientData clientData, + CONST char *value, char *recordPtr, int offset); +static char * ArrowPrintProc(ClientData clientData, Tk_Window tkwin, char *recordPtr, int offset, - Tcl_FreeProc **freeProcPtr)); -static int ParseArrowShape _ANSI_ARGS_((ClientData clientData, + Tcl_FreeProc **freeProcPtr); +static int ParseArrowShape(ClientData clientData, Tcl_Interp *interp, Tk_Window tkwin, - CONST char *value, char *recordPtr, int offset)); -static char * PrintArrowShape _ANSI_ARGS_((ClientData clientData, + CONST char *value, char *recordPtr, int offset); +static char * PrintArrowShape(ClientData clientData, Tk_Window tkwin, char *recordPtr, int offset, - Tcl_FreeProc **freeProcPtr)); -static void ScaleLine _ANSI_ARGS_((Tk_Canvas canvas, + Tcl_FreeProc **freeProcPtr); +static void ScaleLine(Tk_Canvas canvas, Tk_Item *itemPtr, double originX, double originY, - double scaleX, double scaleY)); -static void TranslateLine _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, double deltaX, double deltaY)); + double scaleX, double scaleY); +static void TranslateLine(Tk_Canvas canvas, + Tk_Item *itemPtr, double deltaX, double deltaY); /* - * Information used for parsing configuration specs. If you change any - * of the default strings, be sure to change the corresponding default - * values in CreateLine. + * Information used for parsing configuration specs. If you change any of the + * default strings, be sure to change the corresponding default values in + * CreateLine. */ static Tk_CustomOption arrowShapeOption = { @@ -170,73 +168,65 @@ static Tk_CustomOption pixelOption = { }; static Tk_ConfigSpec configSpecs[] = { - {TK_CONFIG_CUSTOM, "-activedash", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(LineItem, outline.activeDash), + {TK_CONFIG_CUSTOM, "-activedash", NULL, NULL, + NULL, Tk_Offset(LineItem, outline.activeDash), TK_CONFIG_NULL_OK, &dashOption}, - {TK_CONFIG_COLOR, "-activefill", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(LineItem, outline.activeColor), - TK_CONFIG_NULL_OK}, - {TK_CONFIG_BITMAP, "-activestipple", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(LineItem, outline.activeStipple), - TK_CONFIG_NULL_OK}, - {TK_CONFIG_CUSTOM, "-activewidth", (char *) NULL, (char *) NULL, + {TK_CONFIG_COLOR, "-activefill", NULL, NULL, + NULL, Tk_Offset(LineItem, outline.activeColor), TK_CONFIG_NULL_OK}, + {TK_CONFIG_BITMAP, "-activestipple", NULL, NULL, + NULL, Tk_Offset(LineItem, outline.activeStipple), TK_CONFIG_NULL_OK}, + {TK_CONFIG_CUSTOM, "-activewidth", NULL, NULL, "0.0", Tk_Offset(LineItem, outline.activeWidth), TK_CONFIG_DONT_SET_DEFAULT, &pixelOption}, - {TK_CONFIG_CUSTOM, "-arrow", (char *) NULL, (char *) NULL, + {TK_CONFIG_CUSTOM, "-arrow", NULL, NULL, "none", Tk_Offset(LineItem, arrow), TK_CONFIG_DONT_SET_DEFAULT, &arrowOption}, - {TK_CONFIG_CUSTOM, "-arrowshape", (char *) NULL, (char *) NULL, + {TK_CONFIG_CUSTOM, "-arrowshape", NULL, NULL, "8 10 3", Tk_Offset(LineItem, arrowShapeA), TK_CONFIG_DONT_SET_DEFAULT, &arrowShapeOption}, - {TK_CONFIG_CAP_STYLE, "-capstyle", (char *) NULL, (char *) NULL, + {TK_CONFIG_CAP_STYLE, "-capstyle", NULL, NULL, "butt", Tk_Offset(LineItem, capStyle), TK_CONFIG_DONT_SET_DEFAULT}, - {TK_CONFIG_COLOR, "-fill", (char *) NULL, (char *) NULL, + {TK_CONFIG_COLOR, "-fill", NULL, NULL, "black", Tk_Offset(LineItem, outline.color), TK_CONFIG_NULL_OK}, - {TK_CONFIG_CUSTOM, "-dash", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(LineItem, outline.dash), + {TK_CONFIG_CUSTOM, "-dash", NULL, NULL, + NULL, Tk_Offset(LineItem, outline.dash), TK_CONFIG_NULL_OK, &dashOption}, - {TK_CONFIG_PIXELS, "-dashoffset", (char *) NULL, (char *) NULL, - "0", Tk_Offset(LineItem, outline.offset), - TK_CONFIG_DONT_SET_DEFAULT}, - {TK_CONFIG_CUSTOM, "-disableddash", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(LineItem, outline.disabledDash), + {TK_CONFIG_PIXELS, "-dashoffset", NULL, NULL, + "0", Tk_Offset(LineItem, outline.offset), TK_CONFIG_DONT_SET_DEFAULT}, + {TK_CONFIG_CUSTOM, "-disableddash", NULL, NULL, + NULL, Tk_Offset(LineItem, outline.disabledDash), TK_CONFIG_NULL_OK, &dashOption}, - {TK_CONFIG_COLOR, "-disabledfill", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(LineItem, outline.disabledColor), - TK_CONFIG_NULL_OK}, - {TK_CONFIG_BITMAP, "-disabledstipple", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(LineItem, outline.disabledStipple), - TK_CONFIG_NULL_OK}, - {TK_CONFIG_CUSTOM, "-disabledwidth", (char *) NULL, (char *) NULL, + {TK_CONFIG_COLOR, "-disabledfill", NULL, NULL, + NULL, Tk_Offset(LineItem, outline.disabledColor), TK_CONFIG_NULL_OK}, + {TK_CONFIG_BITMAP, "-disabledstipple", NULL, NULL, + NULL, Tk_Offset(LineItem, outline.disabledStipple), TK_CONFIG_NULL_OK}, + {TK_CONFIG_CUSTOM, "-disabledwidth", NULL, NULL, "0.0", Tk_Offset(LineItem, outline.disabledWidth), TK_CONFIG_DONT_SET_DEFAULT, &pixelOption}, - {TK_CONFIG_JOIN_STYLE, "-joinstyle", (char *) NULL, (char *) NULL, + {TK_CONFIG_JOIN_STYLE, "-joinstyle", NULL, NULL, "round", Tk_Offset(LineItem, joinStyle), TK_CONFIG_DONT_SET_DEFAULT}, - {TK_CONFIG_CUSTOM, "-offset", (char *) NULL, (char *) NULL, + {TK_CONFIG_CUSTOM, "-offset", NULL, NULL, "0,0", Tk_Offset(LineItem, outline.tsoffset), TK_CONFIG_DONT_SET_DEFAULT, &offsetOption}, - {TK_CONFIG_CUSTOM, "-smooth", (char *) NULL, (char *) NULL, + {TK_CONFIG_CUSTOM, "-smooth", NULL, NULL, "0", Tk_Offset(LineItem, smooth), TK_CONFIG_DONT_SET_DEFAULT, &smoothOption}, - {TK_CONFIG_INT, "-splinesteps", (char *) NULL, (char *) NULL, + {TK_CONFIG_INT, "-splinesteps", NULL, NULL, "12", Tk_Offset(LineItem, splineSteps), TK_CONFIG_DONT_SET_DEFAULT}, - {TK_CONFIG_CUSTOM, "-state", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(Tk_Item, state), TK_CONFIG_NULL_OK, - &stateOption}, - {TK_CONFIG_BITMAP, "-stipple", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(LineItem, outline.stipple), - TK_CONFIG_NULL_OK}, - {TK_CONFIG_CUSTOM, "-tags", (char *) NULL, (char *) NULL, - (char *) NULL, 0, TK_CONFIG_NULL_OK, &tagsOption}, - {TK_CONFIG_CUSTOM, "-width", (char *) NULL, (char *) NULL, + {TK_CONFIG_CUSTOM, "-state", NULL, NULL, + NULL, Tk_Offset(Tk_Item, state), TK_CONFIG_NULL_OK, &stateOption}, + {TK_CONFIG_BITMAP, "-stipple", NULL, NULL, + NULL, Tk_Offset(LineItem, outline.stipple), TK_CONFIG_NULL_OK}, + {TK_CONFIG_CUSTOM, "-tags", NULL, NULL, + NULL, 0, TK_CONFIG_NULL_OK, &tagsOption}, + {TK_CONFIG_CUSTOM, "-width", NULL, NULL, "1.0", Tk_Offset(LineItem, outline.width), TK_CONFIG_DONT_SET_DEFAULT, &pixelOption}, - {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL, - (char *) NULL, 0, 0} + {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0} }; /* - * The structures below defines the line item type by means - * of procedures that can be invoked by generic item code. + * The structures below defines the line item type by means of functions that + * can be invoked by generic item code. */ Tk_ItemType tkLineType = { @@ -255,17 +245,17 @@ Tk_ItemType tkLineType = { ScaleLine, /* scaleProc */ TranslateLine, /* translateProc */ (Tk_ItemIndexProc *) GetLineIndex, /* indexProc */ - (Tk_ItemCursorProc *) NULL, /* icursorProc */ - (Tk_ItemSelectionProc *) NULL, /* selectionProc */ + NULL, /* icursorProc */ + NULL, /* selectionProc */ (Tk_ItemInsertProc *) LineInsert, /* insertProc */ LineDeleteCoords, /* dTextProc */ - (Tk_ItemType *) NULL, /* nextPtr */ + NULL, /* nextPtr */ }; /* - * The definition below determines how large are static arrays - * used to hold spline points (splines larger than this have to - * have their arrays malloc-ed). + * The definition below determines how large are static arrays used to hold + * spline points (splines larger than this have to have their arrays + * malloc-ed). */ #define MAX_STATIC_POINTS 200 @@ -275,14 +265,13 @@ Tk_ItemType tkLineType = { * * CreateLine -- * - * This procedure is invoked to create a new line item in - * a canvas. + * This function is invoked to create a new line item in a canvas. * * Results: - * A standard Tcl return value. If an error occurred in - * creating the item, then an error message is left in - * the interp's result; in this case itemPtr is left uninitialized, - * so it can be safely freed by the caller. + * A standard Tcl return value. If an error occurred in creating the + * item, then an error message is left in the interp's result; in this + * case itemPtr is left uninitialized, so it can be safely freed by the + * caller. * * Side effects: * A new line item is created. @@ -291,13 +280,13 @@ Tk_ItemType tkLineType = { */ static int -CreateLine(interp, canvas, itemPtr, objc, objv) - Tcl_Interp *interp; /* Interpreter for error reporting. */ - Tk_Canvas canvas; /* Canvas to hold new item. */ - 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 line. */ +CreateLine( + Tcl_Interp *interp, /* Interpreter for error reporting. */ + Tk_Canvas canvas, /* Canvas to hold new item. */ + 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 line. */ { LineItem *linePtr = (LineItem *) itemPtr; int i; @@ -307,9 +296,8 @@ CreateLine(interp, canvas, itemPtr, objc, objv) } /* - * Carry out initialization that is needed to set defaults and to - * allow proper cleanup after errors during the the remainder of - * this procedure. + * Carry out initialization that is needed to set defaults and to allow + * proper cleanup after errors during the the remainder of this function. */ Tk_CreateOutline(&(linePtr->outline)); @@ -325,17 +313,18 @@ CreateLine(interp, canvas, itemPtr, objc, objv) linePtr->arrowShapeC = (float)3.0; linePtr->firstArrowPtr = NULL; linePtr->lastArrowPtr = NULL; - linePtr->smooth = (Tk_SmoothMethod *) NULL; + linePtr->smooth = NULL; linePtr->splineSteps = 12; /* - * Count the number of points and then parse them into a point - * array. Leading arguments are assumed to be points if they - * start with a digit or a minus sign followed by a digit. + * Count the number of points and then parse them into a point array. + * Leading arguments are assumed to be points if they start with a digit + * or a minus sign followed by a digit. */ for (i = 1; i < objc; i++) { char *arg = Tcl_GetString(objv[i]); + if ((arg[0] == '-') && (arg[1] >= 'a') && (arg[1] <= 'z')) { break; } @@ -347,7 +336,7 @@ CreateLine(interp, canvas, itemPtr, objc, objv) return TCL_OK; } - error: + error: DeleteLine(canvas, itemPtr, Tk_Display(Tk_CanvasTkwin(canvas))); return TCL_ERROR; } @@ -357,9 +346,8 @@ CreateLine(interp, canvas, itemPtr, objc, objv) * * LineCoords -- * - * This procedure is invoked to process the "coords" widget - * command on lines. See the user documentation for details - * on what it does. + * This function is invoked to process the "coords" widget command on + * lines. See the user documentation for details on what it does. * * Results: * Returns TCL_OK or TCL_ERROR, and sets the interp's result. @@ -371,15 +359,13 @@ CreateLine(interp, canvas, itemPtr, objc, objv) */ static int -LineCoords(interp, canvas, itemPtr, objc, objv) - Tcl_Interp *interp; /* Used for error reporting. */ - Tk_Canvas canvas; /* Canvas containing item. */ - 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, ... */ +LineCoords( + Tcl_Interp *interp, /* Used for error reporting. */ + Tk_Canvas canvas, /* Canvas containing item. */ + 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, ... */ { LineItem *linePtr = (LineItem *) itemPtr; int i, numPoints; @@ -416,20 +402,22 @@ LineCoords(interp, canvas, itemPtr, objc, objv) } if (objc & 1) { char buf[64 + TCL_INTEGER_SPACE]; + sprintf(buf, "wrong # coordinates: expected an even number, got %d", objc); Tcl_SetResult(interp, buf, TCL_VOLATILE); return TCL_ERROR; } else if (objc < 4) { char buf[64 + TCL_INTEGER_SPACE]; + sprintf(buf, "wrong # coordinates: expected at least 4, got %d", objc); Tcl_SetResult(interp, buf, TCL_VOLATILE); return TCL_ERROR; } else { numPoints = objc/2; if (linePtr->numPoints != numPoints) { - coordPtr = (double *) ckalloc((unsigned) - (sizeof(double) * objc)); + coordPtr = (double *) + ckalloc((unsigned) (sizeof(double) * objc)); if (linePtr->coordPtr != NULL) { ckfree((char *) linePtr->coordPtr); } @@ -470,28 +458,28 @@ LineCoords(interp, canvas, itemPtr, objc, objv) * * ConfigureLine -- * - * This procedure is invoked to configure various aspects - * of a line item such as its background color. + * This function is invoked to configure various aspects of a line item + * such as its background color. * * Results: - * A standard Tcl result code. If an error occurs, then - * an error message is left in the interp's result. + * A standard Tcl result code. If an error occurs, then an error message + * is left in the interp's result. * * Side effects: - * Configuration information, such as colors and stipple - * patterns, may be set for itemPtr. + * Configuration information, such as colors and stipple patterns, may be + * set for itemPtr. * *-------------------------------------------------------------- */ static int -ConfigureLine(interp, canvas, itemPtr, objc, objv, flags) - Tcl_Interp *interp; /* Used for error reporting. */ - Tk_Canvas canvas; /* Canvas containing itemPtr. */ - Tk_Item *itemPtr; /* Line item to reconfigure. */ - int objc; /* Number of elements in objv. */ - Tcl_Obj *CONST objv[]; /* Arguments describing things to configure. */ - int flags; /* Flags to pass to Tk_ConfigureWidget. */ +ConfigureLine( + Tcl_Interp *interp, /* Used for error reporting. */ + Tk_Canvas canvas, /* Canvas containing itemPtr. */ + Tk_Item *itemPtr, /* Line item to reconfigure. */ + int objc, /* Number of elements in objv. */ + Tcl_Obj *CONST objv[], /* Arguments describing things to configure. */ + int flags) /* Flags to pass to Tk_ConfigureWidget. */ { LineItem *linePtr = (LineItem *) itemPtr; XGCValues gcValues; @@ -507,8 +495,8 @@ ConfigureLine(interp, canvas, itemPtr, objc, objv, flags) } /* - * A few of the options require additional processing, such as - * graphics contexts. + * A few of the options require additional processing, such as graphics + * contexts. */ state = itemPtr->state; @@ -565,9 +553,8 @@ ConfigureLine(interp, canvas, itemPtr, objc, objv, flags) } /* - * Setup arrowheads, if needed. If arrowheads are turned off, - * restore the line's endpoints (they were shortened when the - * arrowheads were added). + * Setup arrowheads, if needed. If arrowheads are turned off, restore the + * line's endpoints (they were shortened when the arrowheads were added). */ if ((linePtr->firstArrowPtr != NULL) && (linePtr->arrow != ARROWS_FIRST) @@ -605,8 +592,8 @@ ConfigureLine(interp, canvas, itemPtr, objc, objv, flags) * * DeleteLine -- * - * This procedure is called to clean up the data structure - * associated with a line item. + * This function is called to clean up the data structure associated with + * a line item. * * Results: * None. @@ -618,11 +605,10 @@ ConfigureLine(interp, canvas, itemPtr, objc, objv, flags) */ static void -DeleteLine(canvas, itemPtr, display) - Tk_Canvas canvas; /* Info about overall canvas widget. */ - Tk_Item *itemPtr; /* Item that is being deleted. */ - Display *display; /* Display containing window for - * canvas. */ +DeleteLine( + Tk_Canvas canvas, /* Info about overall canvas widget. */ + Tk_Item *itemPtr, /* Item that is being deleted. */ + Display *display) /* Display containing window for canvas. */ { LineItem *linePtr = (LineItem *) itemPtr; @@ -646,24 +632,22 @@ DeleteLine(canvas, itemPtr, display) * * ComputeLineBbox -- * - * This procedure is invoked to compute the bounding box of - * all the pixels that may be drawn as part of a line. + * This function is invoked to compute the bounding box of all the pixels + * that may be drawn as part of a line. * * Results: * None. * * Side effects: - * The fields x1, y1, x2, and y2 are updated in the header - * for itemPtr. + * The fields x1, y1, x2, and y2 are updated in the header for itemPtr. * *-------------------------------------------------------------- */ static void -ComputeLineBbox(canvas, linePtr) - Tk_Canvas canvas; /* Canvas that contains item. */ - LineItem *linePtr; /* Item whose bbos is to be - * recomputed. */ +ComputeLineBbox( + Tk_Canvas canvas, /* Canvas that contains item. */ + LineItem *linePtr) /* Item whose bbos is to be recomputed. */ { double *coordPtr; int i, intWidth; @@ -699,13 +683,12 @@ ComputeLineBbox(canvas, linePtr) linePtr->header.y1 = linePtr->header.y2 = (int) coordPtr[1]; /* - * Compute the bounding box of all the points in the line, - * then expand in all directions by the line's width to take - * care of butting or rounded corners and projecting or - * rounded caps. This expansion is an overestimate (worst-case - * is square root of two over two) but it's simple. Don't do - * anything special for curves. This causes an additional - * overestimate in the bounding box, but is faster. + * Compute the bounding box of all the points in the line, then expand in + * all directions by the line's width to take care of butting or rounded + * corners and projecting or rounded caps. This expansion is an + * overestimate (worst-case is square root of two over two) but it's + * simple. eDon't do anything special for curves. This causes an + * additional overestimate in the bounding box, but is faster. */ for (i = 1, coordPtr = linePtr->coordPtr+2; i < linePtr->numPoints; @@ -774,9 +757,9 @@ ComputeLineBbox(canvas, linePtr) } /* - * For mitered lines, make a second pass through all the points. - * Compute the locations of the two miter vertex points and add - * those into the bounding box. + * For mitered lines, make a second pass through all the points. Compute + * the locations of the two miter vertex points and add those into the + * bounding box. */ if (linePtr->joinStyle == JoinMiter) { @@ -784,7 +767,7 @@ ComputeLineBbox(canvas, linePtr) i--, coordPtr += 2) { double miter[4]; int j; - + if (TkGetMiterPoints(coordPtr, coordPtr+2, coordPtr+4, width, miter, miter+2)) { for (j = 0; j < 4; j += 2) { @@ -814,8 +797,8 @@ ComputeLineBbox(canvas, linePtr) } /* - * Add one more pixel of fudge factor just to be safe (e.g. - * X may round differently than we do). + * Add one more pixel of fudge factor just to be safe (e.g. X may round + * differently than we do). */ linePtr->header.x1 -= 1; @@ -829,28 +812,27 @@ ComputeLineBbox(canvas, linePtr) * * DisplayLine -- * - * This procedure is invoked to draw a line item in a given - * drawable. + * This function is invoked to draw a line item in a given drawable. * * Results: * None. * * Side effects: - * ItemPtr is drawn in drawable using the transformation - * information in canvas. + * ItemPtr is drawn in drawable using the transformation information in + * canvas. * *-------------------------------------------------------------- */ static void -DisplayLine(canvas, itemPtr, display, drawable, x, y, width, height) - Tk_Canvas canvas; /* Canvas that contains item. */ - Tk_Item *itemPtr; /* Item to be displayed. */ - Display *display; /* Display on which to draw item. */ - Drawable drawable; /* Pixmap or window in which to draw - * item. */ - int x, y, width, height; /* Describes region of canvas that - * must be redisplayed (not used). */ +DisplayLine( + Tk_Canvas canvas, /* Canvas that contains item. */ + Tk_Item *itemPtr, /* Item to be displayed. */ + Display *display, /* Display on which to draw item. */ + Drawable drawable, /* Pixmap or window in which to draw item. */ + int x, int y, int width, int height) + /* Describes region of canvas that must be + * redisplayed (not used). */ { LineItem *linePtr = (LineItem *) itemPtr; XPoint staticPoints[MAX_STATIC_POINTS*3]; @@ -877,16 +859,15 @@ DisplayLine(canvas, itemPtr, display, drawable, x, y, width, height) } } /* - * Build up an array of points in screen coordinates. Use a - * static array unless the line has an enormous number of points; - * in this case, dynamically allocate an array. For smoothed lines, - * generate the curve points on each redisplay. + * Build up an array of points in screen coordinates. Use a static array + * unless the line has an enormous number of points; in this case, + * dynamically allocate an array. For smoothed lines, generate the curve + * points on each redisplay. */ if ((linePtr->smooth) && (linePtr->numPoints > 2)) { - numPoints = linePtr->smooth->coordProc(canvas, (double *) NULL, - linePtr->numPoints, linePtr->splineSteps, (XPoint *) NULL, - (double *) NULL); + numPoints = linePtr->smooth->coordProc(canvas, NULL, + linePtr->numPoints, linePtr->splineSteps, NULL, NULL); } else { numPoints = linePtr->numPoints; } @@ -899,18 +880,17 @@ DisplayLine(canvas, itemPtr, display, drawable, x, y, width, height) if ((linePtr->smooth) && (linePtr->numPoints > 2)) { numPoints = linePtr->smooth->coordProc(canvas, linePtr->coordPtr, - linePtr->numPoints, linePtr->splineSteps, pointPtr, - (double *) NULL); + linePtr->numPoints, linePtr->splineSteps, pointPtr, NULL); } else { numPoints = TkCanvTranslatePath((TkCanvas*)canvas, numPoints, linePtr->coordPtr, 0, pointPtr); } /* - * Display line, the free up line storage if it was dynamically - * allocated. If we're stippling, then modify the stipple offset - * in the GC. Be sure to reset the offset when done, since the - * GC is supposed to be read-only. + * Display line, the free up line storage if it was dynamically allocated. + * If we're stippling, then modify the stipple offset in the GC. Be sure + * to reset the offset when done, since the GC is supposed to be + * read-only. */ if (Tk_ChangeOutlineGC(canvas, itemPtr, &(linePtr->outline))) { @@ -966,12 +946,12 @@ DisplayLine(canvas, itemPtr, display, drawable, x, y, width, height) */ static void -LineInsert(canvas, itemPtr, beforeThis, obj) - Tk_Canvas canvas; /* Canvas containing text item. */ - Tk_Item *itemPtr; /* Line item to be modified. */ - int beforeThis; /* Index before which new coordinates - * are to be inserted. */ - Tcl_Obj *obj; /* New coordinates to be inserted. */ +LineInsert( + Tk_Canvas canvas, /* Canvas containing text item. */ + Tk_Item *itemPtr, /* Line item to be modified. */ + int beforeThis, /* Index before which new coordinates are to + * be inserted. */ + Tcl_Obj *obj) /* New coordinates to be inserted. */ { LineItem *linePtr = (LineItem *) itemPtr; int length, objc, i; @@ -983,7 +963,7 @@ LineInsert(canvas, itemPtr, beforeThis, obj) state = ((TkCanvas *)canvas)->canvas_state; } - if (!obj || (Tcl_ListObjGetElements((Tcl_Interp *) NULL, obj, &objc, &objv) != TCL_OK) + if (!obj || (Tcl_ListObjGetElements(NULL, obj, &objc, &objv) != TCL_OK) || !objc || objc&1) { return; } @@ -1007,7 +987,7 @@ LineInsert(canvas, itemPtr, beforeThis, obj) new[i] = linePtr->coordPtr[i]; } for(i=0; i<objc; i++) { - if (Tcl_GetDoubleFromObj((Tcl_Interp *) NULL,objv[i], + if (Tcl_GetDoubleFromObj(NULL,objv[i], new+(i+beforeThis))!=TCL_OK) { Tcl_ResetResult(((TkCanvas *)canvas)->interp); ckfree((char *) new); @@ -1024,13 +1004,14 @@ LineInsert(canvas, itemPtr, beforeThis, obj) if ((length>3) && (state != TK_STATE_HIDDEN)) { /* - * This is some optimizing code that will result that only the part - * of the polygon that changed (and the objects that are overlapping - * with that part) need to be redrawn. A special flag is set that - * instructs the general canvas code not to redraw the whole - * object. If this flag is not set, the canvas will do the redrawing, - * otherwise I have to do it here. + * This is some optimizing code that will result that only the part of + * the polygon that changed (and the objects that are overlapping with + * that part) need to be redrawn. A special flag is set that instructs + * the general canvas code not to redraw the whole object. If this + * flag is not set, the canvas will do the redrawing, otherwise I have + * to do it here. */ + itemPtr->redraw_flags |= TK_ITEM_DONT_REDRAW; if (beforeThis>0) {beforeThis -= 2; objc+=2; } @@ -1046,14 +1027,20 @@ LineInsert(canvas, itemPtr, beforeThis, obj) itemPtr->x1 = itemPtr->x2 = (int) linePtr->coordPtr[beforeThis]; itemPtr->y1 = itemPtr->y2 = (int) linePtr->coordPtr[beforeThis+1]; if ((linePtr->firstArrowPtr != NULL) && (beforeThis<1)) { - /* include old first arrow */ + /* + * Include old first arrow. + */ + for (i = 0, coordPtr = linePtr->firstArrowPtr; i < PTS_IN_ARROW; i++, coordPtr += 2) { TkIncludePoint(itemPtr, coordPtr); } } if ((linePtr->lastArrowPtr != NULL) && ((beforeThis+objc)>=length)) { - /* include old last arrow */ + /* + * Include old last arrow. + */ + for (i = 0, coordPtr = linePtr->lastArrowPtr; i < PTS_IN_ARROW; i++, coordPtr += 2) { TkIncludePoint(itemPtr, coordPtr); @@ -1081,14 +1068,20 @@ LineInsert(canvas, itemPtr, beforeThis, obj) double width; int intWidth; if ((linePtr->firstArrowPtr != NULL) && (beforeThis>2)) { - /* include new first arrow */ + /* + * Include new first arrow. + */ + for (i = 0, coordPtr = linePtr->firstArrowPtr; i < PTS_IN_ARROW; i++, coordPtr += 2) { TkIncludePoint(itemPtr, coordPtr); } } - if ((linePtr->lastArrowPtr != NULL) && ((beforeThis+objc)<(length-2))) { - /* include new right arrow */ + if ((linePtr->lastArrowPtr != NULL) && (beforeThis+objc < length-2)) { + /* + * Include new right arrow. + */ + for (i = 0, coordPtr = linePtr->lastArrowPtr; i < PTS_IN_ARROW; i++, coordPtr += 2) { TkIncludePoint(itemPtr, coordPtr); @@ -1096,13 +1089,13 @@ LineInsert(canvas, itemPtr, beforeThis, obj) } width = linePtr->outline.width; if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) { - if (linePtr->outline.activeWidth>width) { - width = linePtr->outline.activeWidth; - } + if (linePtr->outline.activeWidth>width) { + width = linePtr->outline.activeWidth; + } } else if (state==TK_STATE_DISABLED) { - if (linePtr->outline.disabledWidth>0) { - width = linePtr->outline.disabledWidth; - } + if (linePtr->outline.disabledWidth>0) { + width = linePtr->outline.disabledWidth; + } } intWidth = (int) (width + 0.5); if (intWidth < 1) { @@ -1128,18 +1121,18 @@ LineInsert(canvas, itemPtr, beforeThis, obj) * None. * * Side effects: - * Characters between "first" and "last", inclusive, get - * deleted from itemPtr. + * Characters between "first" and "last", inclusive, get deleted from + * itemPtr. * *-------------------------------------------------------------- */ static void -LineDeleteCoords(canvas, itemPtr, first, last) - Tk_Canvas canvas; /* Canvas containing itemPtr. */ - Tk_Item *itemPtr; /* Item in which to delete characters. */ - int first; /* Index of first character to delete. */ - int last; /* Index of last character to delete. */ +LineDeleteCoords( + Tk_Canvas canvas, /* Canvas containing itemPtr. */ + Tk_Item *itemPtr, /* Item in which to delete characters. */ + int first, /* Index of first character to delete. */ + int last) /* Index of last character to delete. */ { LineItem *linePtr = (LineItem *) itemPtr; int count, i, first1, last1; @@ -1181,26 +1174,32 @@ LineDeleteCoords(canvas, itemPtr, first, last) if((first1<2) && (last1 >= length-2)) { /* - * This is some optimizing code that will result that only the part - * of the line that changed (and the objects that are overlapping - * with that part) need to be redrawn. A special flag is set that - * instructs the general canvas code not to redraw the whole - * object. If this flag is set, the redrawing has to be done here, - * otherwise the general Canvas code will take care of it. + * This is some optimizing code that will result that only the part of + * the line that changed (and the objects that are overlapping with + * that part) need to be redrawn. A special flag is set that instructs + * the general canvas code not to redraw the whole object. If this + * flag is set, the redrawing has to be done here, otherwise the + * general Canvas code will take care of it. */ itemPtr->redraw_flags |= TK_ITEM_DONT_REDRAW; itemPtr->x1 = itemPtr->x2 = (int) linePtr->coordPtr[first1]; itemPtr->y1 = itemPtr->y2 = (int) linePtr->coordPtr[first1+1]; if ((linePtr->firstArrowPtr != NULL) && (first1<2)) { - /* include old first arrow */ + /* + * Include old first arrow. + */ + for (i = 0, coordPtr = linePtr->firstArrowPtr; i < PTS_IN_ARROW; i++, coordPtr += 2) { TkIncludePoint(itemPtr, coordPtr); } } if ((linePtr->lastArrowPtr != NULL) && (last1>=length-2)) { - /* include old last arrow */ + /* + * Include old last arrow. + */ + for (i = 0, coordPtr = linePtr->lastArrowPtr; i < PTS_IN_ARROW; i++, coordPtr += 2) { TkIncludePoint(itemPtr, coordPtr); @@ -1232,15 +1231,22 @@ LineDeleteCoords(canvas, itemPtr, first, last) if(itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW) { double width; int intWidth; + if ((linePtr->firstArrowPtr != NULL) && (first1<4)) { - /* include new first arrow */ + /* + * Include new first arrow. + */ + for (i = 0, coordPtr = linePtr->firstArrowPtr; i < PTS_IN_ARROW; i++, coordPtr += 2) { TkIncludePoint(itemPtr, coordPtr); } } if ((linePtr->lastArrowPtr != NULL) && (last1>(length-4))) { - /* include new right arrow */ + /* + * Include new right arrow. + */ + for (i = 0, coordPtr = linePtr->lastArrowPtr; i < PTS_IN_ARROW; i++, coordPtr += 2) { TkIncludePoint(itemPtr, coordPtr); @@ -1273,14 +1279,14 @@ LineDeleteCoords(canvas, itemPtr, first, last) * * LineToPoint -- * - * Computes the distance from a given point to a given - * line, in canvas units. + * Computes the distance from a given point to a given line, in canvas + * units. * * Results: - * The return value is 0 if the point whose x and y coordinates - * are pointPtr[0] and pointPtr[1] is inside the line. If the - * point isn't inside the line then the return value is the - * distance from the point to the line. + * The return value is 0 if the point whose x and y coordinates are + * pointPtr[0] and pointPtr[1] is inside the line. If the point isn't + * inside the line then the return value is the distance from the point + * to the line. * * Side effects: * None. @@ -1302,15 +1308,15 @@ LineToPoint(canvas, itemPtr, pointPtr) double poly[10]; double bestDist, dist, width; int numPoints, count; - int changedMiterToBevel; /* Non-zero means that a mitered corner - * had to be treated as beveled after all - * because the angle was < 11 degrees. */ + int changedMiterToBevel; /* Non-zero means that a mitered corner had to + * be treated as beveled after all because the + * angle was < 11 degrees. */ bestDist = 1.0e36; /* - * Handle smoothed lines by generating an expanded set of points - * against which to do the check. + * Handle smoothed lines by generating an expanded set of points against + * which to do the check. */ if(state == TK_STATE_NULL) { @@ -1329,9 +1335,8 @@ LineToPoint(canvas, itemPtr, pointPtr) } if ((linePtr->smooth) && (linePtr->numPoints > 2)) { - numPoints = linePtr->smooth->coordProc(canvas, (double *) NULL, - linePtr->numPoints, linePtr->splineSteps, (XPoint *) NULL, - (double *) NULL); + numPoints = linePtr->smooth->coordProc(canvas, NULL, + linePtr->numPoints, linePtr->splineSteps, NULL, NULL); if (numPoints <= MAX_STATIC_POINTS) { linePoints = staticSpace; } else { @@ -1339,8 +1344,7 @@ LineToPoint(canvas, itemPtr, pointPtr) (2*numPoints*sizeof(double))); } numPoints = linePtr->smooth->coordProc(canvas, linePtr->coordPtr, - linePtr->numPoints, linePtr->splineSteps, (XPoint *) NULL, - linePoints); + linePtr->numPoints, linePtr->splineSteps, NULL, linePoints); } else { numPoints = linePtr->numPoints; linePoints = linePtr->coordPtr; @@ -1353,26 +1357,25 @@ LineToPoint(canvas, itemPtr, pointPtr) if (!numPoints || itemPtr->state==TK_STATE_HIDDEN) { return bestDist; } else if (numPoints == 1) { - bestDist = hypot(linePoints[0] - pointPtr[0], linePoints[1] - pointPtr[1]) - - width/2.0; + bestDist = hypot(linePoints[0]-pointPtr[0], linePoints[1]-pointPtr[1]) + - width/2.0; if (bestDist < 0) bestDist = 0; return bestDist; } /* - * The overall idea is to iterate through all of the edges of - * the line, computing a polygon for each edge and testing the - * point against that polygon. In addition, there are additional - * tests to deal with rounded joints and caps. + * The overall idea is to iterate through all of the edges of the line, + * computing a polygon for each edge and testing the point against that + * polygon. In addition, there are additional tests to deal with rounded + * joints and caps. */ changedMiterToBevel = 0; for (count = numPoints, coordPtr = linePoints; count >= 2; count--, coordPtr += 2) { - /* - * If rounding is done around the first point then compute - * the distance between the point and the point. + * If rounding is done around the first point then compute the + * distance between the point and the point. */ if (((linePtr->capStyle == CapRound) && (count == numPoints)) @@ -1389,9 +1392,9 @@ LineToPoint(canvas, itemPtr, pointPtr) } /* - * Compute the polygonal shape corresponding to this edge, - * consisting of two points for the first point of the edge - * and two points for the last point of the edge. + * Compute the polygonal shape corresponding to this edge, consisting + * of two points for the first point of the edge and two points for + * the last point of the edge. */ if (count == numPoints) { @@ -1403,14 +1406,13 @@ LineToPoint(canvas, itemPtr, pointPtr) poly[2] = poly[4]; poly[3] = poly[5]; } else { - TkGetButtPoints(coordPtr+2, coordPtr, width, 0, - poly, poly+2); + TkGetButtPoints(coordPtr+2, coordPtr, width, 0, poly, poly+2); /* - * If this line uses beveled joints, then check the distance - * to a polygon comprising the last two points of the previous - * polygon and the first two from this polygon; this checks - * the wedges that fill the mitered joint. + * If this line uses beveled joints, then check the distance to a + * polygon comprising the last two points of the previous polygon + * and the first two from this polygon; this checks the wedges + * that fill the mitered joint. */ if ((linePtr->joinStyle == JoinBevel) || changedMiterToBevel) { @@ -1433,8 +1435,8 @@ LineToPoint(canvas, itemPtr, pointPtr) if (TkGetMiterPoints(coordPtr, coordPtr+2, coordPtr+4, width, poly+4, poly+6) == 0) { changedMiterToBevel = 1; - TkGetButtPoints(coordPtr, coordPtr+2, width, - 0, poly+4, poly+6); + TkGetButtPoints(coordPtr, coordPtr+2, width, 0, + poly+4, poly+6); } } else { TkGetButtPoints(coordPtr, coordPtr+2, width, 0, @@ -1452,8 +1454,8 @@ LineToPoint(canvas, itemPtr, pointPtr) } /* - * If caps are rounded, check the distance to the cap around the - * final end point of the line. + * If caps are rounded, check the distance to the cap around the final end + * point of the line. */ if (linePtr->capStyle == CapRound) { @@ -1494,7 +1496,7 @@ LineToPoint(canvas, itemPtr, pointPtr) } } - done: + done: if ((linePoints != staticSpace) && (linePoints != linePtr->coordPtr)) { ckfree((char *) linePoints); } @@ -1506,14 +1508,12 @@ LineToPoint(canvas, itemPtr, pointPtr) * * LineToArea -- * - * This procedure is called to determine whether an item - * lies entirely inside, entirely outside, or overlapping - * a given rectangular area. + * This function is called to determine whether an item lies entirely + * inside, entirely outside, or overlapping a given rectangular area. * * Results: - * -1 is returned if the item is entirely outside the - * area, 0 if it overlaps, and 1 if it is entirely - * inside the given area. + * -1 is returned if the item is entirely outside the area, 0 if it + * overlaps, and 1 if it is entirely inside the given area. * * Side effects: * None. @@ -1523,10 +1523,10 @@ LineToPoint(canvas, itemPtr, pointPtr) /* ARGSUSED */ static int -LineToArea(canvas, itemPtr, rectPtr) - Tk_Canvas canvas; /* Canvas containing item. */ - Tk_Item *itemPtr; /* Item to check against line. */ - double *rectPtr; +LineToArea( + Tk_Canvas canvas, /* Canvas containing item. */ + Tk_Item *itemPtr, /* Item to check against line. */ + double *rectPtr) { LineItem *linePtr = (LineItem *) itemPtr; double staticSpace[2*MAX_STATIC_POINTS]; @@ -1555,6 +1555,7 @@ LineToArea(canvas, itemPtr, rectPtr) return -1; } else if (linePtr->numPoints == 1) { double oval[4]; + oval[0] = linePtr->coordPtr[0]-radius; oval[1] = linePtr->coordPtr[1]-radius; oval[2] = linePtr->coordPtr[0]+radius; @@ -1563,14 +1564,13 @@ LineToArea(canvas, itemPtr, rectPtr) } /* - * Handle smoothed lines by generating an expanded set of points - * against which to do the check. + * Handle smoothed lines by generating an expanded set of points against + * which to do the check. */ if ((linePtr->smooth) && (linePtr->numPoints > 2)) { - numPoints = linePtr->smooth->coordProc(canvas, (double *) NULL, - linePtr->numPoints, linePtr->splineSteps, (XPoint *) NULL, - (double *) NULL); + numPoints = linePtr->smooth->coordProc(canvas, NULL, + linePtr->numPoints, linePtr->splineSteps, NULL, NULL); if (numPoints <= MAX_STATIC_POINTS) { linePoints = staticSpace; } else { @@ -1578,8 +1578,7 @@ LineToArea(canvas, itemPtr, rectPtr) (2*numPoints*sizeof(double))); } numPoints = linePtr->smooth->coordProc(canvas, linePtr->coordPtr, - linePtr->numPoints, linePtr->splineSteps, (XPoint *) NULL, - linePoints); + linePtr->numPoints, linePtr->splineSteps, NULL, linePoints); } else { numPoints = linePtr->numPoints; linePoints = linePtr->coordPtr; @@ -1593,7 +1592,7 @@ LineToArea(canvas, itemPtr, rectPtr) width = 1.0; } - result = TkThickPolyLineToArea(linePoints, numPoints, + result = TkThickPolyLineToArea(linePoints, numPoints, width, linePtr->capStyle, linePtr->joinStyle, rectPtr); if (result == 0) { @@ -1621,7 +1620,7 @@ LineToArea(canvas, itemPtr, rectPtr) } } - done: + done: if ((linePoints != staticSpace) && (linePoints != linePtr->coordPtr)) { ckfree((char *) linePoints); } @@ -1633,15 +1632,14 @@ LineToArea(canvas, itemPtr, rectPtr) * * ScaleLine -- * - * This procedure is invoked to rescale a line item. + * This function is invoked to rescale a line item. * * Results: * None. * * Side effects: - * The line referred to by itemPtr is rescaled so that the - * following transformation is applied to all point - * coordinates: + * The line referred to by itemPtr is rescaled so that the following + * transformation is applied to all point coordinates: * x' = originX + scaleX*(x-originX) * y' = originY + scaleY*(y-originY) * @@ -1649,20 +1647,21 @@ LineToArea(canvas, itemPtr, rectPtr) */ static void -ScaleLine(canvas, itemPtr, originX, originY, scaleX, scaleY) - Tk_Canvas canvas; /* Canvas containing line. */ - Tk_Item *itemPtr; /* Line to be scaled. */ - double originX, originY; /* Origin about which to scale rect. */ - double scaleX; /* Amount to scale in X direction. */ - double scaleY; /* Amount to scale in Y direction. */ +ScaleLine( + Tk_Canvas canvas, /* Canvas containing line. */ + Tk_Item *itemPtr, /* Line to be scaled. */ + double originX, double originY, + /* Origin about which to scale rect. */ + double scaleX, /* Amount to scale in X direction. */ + double scaleY) /* Amount to scale in Y direction. */ { LineItem *linePtr = (LineItem *) itemPtr; double *coordPtr; int i; /* - * Delete any arrowheads before scaling all the points (so that - * the end-points of the line get restored). + * Delete any arrowheads before scaling all the points (so that the + * end-points of the line get restored). */ if (linePtr->firstArrowPtr != NULL) { @@ -1696,14 +1695,13 @@ ScaleLine(canvas, itemPtr, originX, originY, scaleX, scaleY) * * GetLineIndex -- * - * Parse an index into a line item and return either its value - * or an error. + * Parse an index into a line item and return either its value or an + * error. * * Results: - * A standard Tcl result. If all went well, then *indexPtr is - * filled in with the index (into itemPtr) corresponding to - * string. Otherwise an error message is left in - * interp->result. + * A standard Tcl result. If all went well, then *indexPtr is filled in + * with the index (into itemPtr) corresponding to string. Otherwise an + * error message is left in interp->result. * * Side effects: * None. @@ -1712,14 +1710,14 @@ ScaleLine(canvas, itemPtr, originX, originY, scaleX, scaleY) */ static int -GetLineIndex(interp, canvas, itemPtr, obj, indexPtr) - Tcl_Interp *interp; /* Used for error reporting. */ - Tk_Canvas canvas; /* Canvas containing item. */ - Tk_Item *itemPtr; /* Item for which the index is being +GetLineIndex( + Tcl_Interp *interp, /* Used for error reporting. */ + Tk_Canvas canvas, /* Canvas containing item. */ + Tk_Item *itemPtr, /* Item for which the index is being * specified. */ - Tcl_Obj *obj; /* Specification of a particular coord - * in itemPtr's line. */ - int *indexPtr; /* Where to store converted index. */ + Tcl_Obj *obj, /* Specification of a particular coord in + * itemPtr's line. */ + int *indexPtr) /* Where to store converted index. */ { LineItem *linePtr = (LineItem *) itemPtr; int length; @@ -1729,16 +1727,14 @@ GetLineIndex(interp, canvas, itemPtr, obj, indexPtr) if (strncmp(string, "end", (unsigned) length) == 0) { *indexPtr = 2*linePtr->numPoints; } else { - badIndex: - /* - * Some of the paths here leave messages in interp->result, - * so we have to clear it out before storing our own message. + * Some of the paths here leave messages in interp->result, so we + * have to clear it out before storing our own message. */ - Tcl_SetResult(interp, (char *) NULL, TCL_STATIC); - Tcl_AppendResult(interp, "bad index \"", string, "\"", - (char *) NULL); + badIndex: + Tcl_SetResult(interp, NULL, TCL_STATIC); + Tcl_AppendResult(interp, "bad index \"", string, "\"", NULL); return TCL_ERROR; } } else if (string[0] == '@') { @@ -1771,7 +1767,7 @@ GetLineIndex(interp, canvas, itemPtr, obj, indexPtr) if (Tcl_GetIntFromObj(interp, obj, indexPtr) != TCL_OK) { goto badIndex; } - *indexPtr &= -2; /* if index is odd, make it even */ + *indexPtr &= -2; /* if index is odd, make it even */ if (*indexPtr < 0){ *indexPtr = 0; } else if (*indexPtr > (2*linePtr->numPoints)) { @@ -1786,25 +1782,24 @@ GetLineIndex(interp, canvas, itemPtr, obj, indexPtr) * * TranslateLine -- * - * This procedure is called to move a line by a given amount. + * This function is called to move a line by a given amount. * * Results: * None. * * Side effects: - * The position of the line is offset by (xDelta, yDelta), and - * the bounding box is updated in the generic part of the item - * structure. + * The position of the line is offset by (xDelta, yDelta), and the + * bounding box is updated in the generic part of the item structure. * *-------------------------------------------------------------- */ static void -TranslateLine(canvas, itemPtr, deltaX, deltaY) - Tk_Canvas canvas; /* Canvas containing item. */ - Tk_Item *itemPtr; /* Item that is being moved. */ - double deltaX, deltaY; /* Amount by which item is to be - * moved. */ +TranslateLine( + Tk_Canvas canvas, /* Canvas containing item. */ + Tk_Item *itemPtr, /* Item that is being moved. */ + double deltaX, double deltaY) + /* Amount by which item is to be moved. */ { LineItem *linePtr = (LineItem *) itemPtr; double *coordPtr; @@ -1837,13 +1832,13 @@ TranslateLine(canvas, itemPtr, deltaX, deltaY) * * ParseArrowShape -- * - * This procedure is called back during option parsing to - * parse arrow shape information. + * This function is called back during option parsing to parse arrow + * shape information. * * Results: - * The return value is a standard Tcl result: TCL_OK means - * that the arrow shape information was parsed ok, and - * TCL_ERROR means it couldn't be parsed. + * The return value is a standard Tcl result: TCL_OK means that the arrow + * shape information was parsed ok, and TCL_ERROR means it couldn't be + * parsed. * * Side effects: * Arrow information in recordPtr is updated. @@ -1853,14 +1848,14 @@ TranslateLine(canvas, itemPtr, deltaX, deltaY) /* ARGSUSED */ static int -ParseArrowShape(clientData, interp, tkwin, value, recordPtr, offset) - ClientData clientData; /* Not used. */ - Tcl_Interp *interp; /* Used for error reporting. */ - Tk_Window tkwin; /* Not used. */ - CONST char *value; /* Textual specification of arrow shape. */ - char *recordPtr; /* Pointer to item record in which to - * store arrow information. */ - int offset; /* Offset of shape information in widget +ParseArrowShape( + ClientData clientData, /* Not used. */ + Tcl_Interp *interp, /* Used for error reporting. */ + Tk_Window tkwin, /* Not used. */ + CONST char *value, /* Textual specification of arrow shape. */ + char *recordPtr, /* Pointer to item record in which to store + * arrow information. */ + int offset) /* Offset of shape information in widget * record. */ { LineItem *linePtr = (LineItem *) recordPtr; @@ -1876,7 +1871,7 @@ ParseArrowShape(clientData, interp, tkwin, value, recordPtr, offset) syntaxError: Tcl_ResetResult(interp); Tcl_AppendResult(interp, "bad arrow shape \"", value, - "\": must be list with three numbers", (char *) NULL); + "\": must be list with three numbers", NULL); if (argv != NULL) { ckfree((char *) argv); } @@ -1904,8 +1899,8 @@ ParseArrowShape(clientData, interp, tkwin, value, recordPtr, offset) * * PrintArrowShape -- * - * This procedure is a callback invoked by the configuration - * code to return a printable value describing an arrow shape. + * This function is a callback invoked by the configuration code to + * return a printable value describing an arrow shape. * * Results: * None. @@ -1918,14 +1913,14 @@ ParseArrowShape(clientData, interp, tkwin, value, recordPtr, offset) /* ARGSUSED */ static char * -PrintArrowShape(clientData, tkwin, recordPtr, offset, freeProcPtr) - ClientData clientData; /* Not used. */ - Tk_Window tkwin; /* Window associated with linePtr's widget. */ - char *recordPtr; /* Pointer to item record containing current +PrintArrowShape( + ClientData clientData, /* Not used. */ + Tk_Window tkwin, /* Window associated with linePtr's widget. */ + char *recordPtr, /* Pointer to item record containing current * shape information. */ - int offset; /* Offset of arrow information in record. */ - Tcl_FreeProc **freeProcPtr; /* Store address of procedure to call to - * free string here. */ + int offset, /* Offset of arrow information in record. */ + Tcl_FreeProc **freeProcPtr) /* Store address of function to call to free + * string here. */ { LineItem *linePtr = (LineItem *) recordPtr; char *buffer; @@ -1943,27 +1938,27 @@ PrintArrowShape(clientData, tkwin, recordPtr, offset, freeProcPtr) * * ArrowParseProc -- * - * This procedure is invoked during option processing to handle - * the "-arrow" option. + * This function is invoked during option processing to handle the + * "-arrow" option. * * Results: * A standard Tcl return value. * * Side effects: - * The arrow for a given item gets replaced by the arrow - * indicated in the value argument. + * The arrow for a given item gets replaced by the arrow indicated in the + * value argument. * *-------------------------------------------------------------- */ static int -ArrowParseProc(clientData, interp, tkwin, value, widgRec, offset) - ClientData clientData; /* some flags.*/ - Tcl_Interp *interp; /* Used for reporting errors. */ - Tk_Window tkwin; /* Window containing canvas widget. */ - CONST char *value; /* Value of option. */ - char *widgRec; /* Pointer to record for item. */ - int offset; /* Offset into item. */ +ArrowParseProc( + ClientData clientData, /* some flags.*/ + Tcl_Interp *interp, /* Used for reporting errors. */ + Tk_Window tkwin, /* Window containing canvas widget. */ + CONST char *value, /* Value of option. */ + char *widgRec, /* Pointer to record for item. */ + int offset) /* Offset into item. */ { int c; size_t length; @@ -1995,9 +1990,8 @@ ArrowParseProc(clientData, interp, tkwin, value, widgRec, offset) return TCL_OK; } - Tcl_AppendResult(interp, "bad arrow spec \"", value, - "\": must be none, first, last, or both", - (char *) NULL); + Tcl_AppendResult(interp, "bad arrow spec \"", value, + "\": must be none, first, last, or both", NULL); *arrowPtr = ARROWS_NONE; return TCL_ERROR; } @@ -2007,16 +2001,15 @@ ArrowParseProc(clientData, interp, tkwin, value, widgRec, offset) * * ArrowPrintProc -- * - * This procedure is invoked by the Tk configuration code - * to produce a printable string for the "-arrow" - * configuration option. + * This function is invoked by the Tk configuration code to produce a + * printable string for the "-arrow" configuration option. * * Results: - * The return value is a string describing the arrows for - * the item referred to by "widgRec". In addition, *freeProcPtr - * is filled in with the address of a procedure to call to free - * the result string when it's no longer needed (or NULL to - * indicate that the string doesn't need to be freed). + * The return value is a string describing the arrows for the item + * referred to by "widgRec". In addition, *freeProcPtr is filled in with + * the address of a function to call to free the result string when it's + * no longer needed (or NULL to indicate that the string doesn't need to + * be freed). * * Side effects: * None. @@ -2025,25 +2018,25 @@ ArrowParseProc(clientData, interp, tkwin, value, widgRec, offset) */ static char * -ArrowPrintProc(clientData, tkwin, widgRec, offset, freeProcPtr) - ClientData clientData; /* Ignored. */ - Tk_Window tkwin; /* Window containing canvas widget. */ - char *widgRec; /* Pointer to record for item. */ - int offset; /* Offset into item. */ - Tcl_FreeProc **freeProcPtr; /* Pointer to variable to fill in with - * information about how to reclaim - * storage for return string. */ +ArrowPrintProc( + ClientData clientData, /* Ignored. */ + Tk_Window tkwin, /* Window containing canvas widget. */ + char *widgRec, /* Pointer to record for item. */ + int offset, /* Offset into item. */ + Tcl_FreeProc **freeProcPtr) /* Pointer to variable to fill in with + * information about how to reclaim storage + * for return string. */ { register Arrows *arrowPtr = (Arrows *) (widgRec + offset); switch (*arrowPtr) { - case ARROWS_FIRST: + case ARROWS_FIRST: return "first"; - case ARROWS_LAST: + case ARROWS_LAST: return "last"; - case ARROWS_BOTH: + case ARROWS_BOTH: return "both"; - default: + default: return "none"; } } @@ -2053,40 +2046,38 @@ ArrowPrintProc(clientData, tkwin, widgRec, offset, freeProcPtr) * * ConfigureArrows -- * - * If arrowheads have been requested for a line, this - * procedure makes arrangements for the arrowheads. + * If arrowheads have been requested for a line, this function makes + * arrangements for the arrowheads. * * Results: * Always returns TCL_OK. * * Side effects: - * Information in linePtr is set up for one or two arrowheads. - * the firstArrowPtr and lastArrowPtr polygons are allocated - * and initialized, if need be, and the end points of the line - * are adjusted so that a thick line doesn't stick out past - * the arrowheads. + * Information in linePtr is set up for one or two arrowheads. The + * firstArrowPtr and lastArrowPtr polygons are allocated and initialized, + * if need be, and the end points of the line are adjusted so that a + * thick line doesn't stick out past the arrowheads. * *-------------------------------------------------------------- */ /* ARGSUSED */ static int -ConfigureArrows(canvas, linePtr) - Tk_Canvas canvas; /* Canvas in which arrows will be - * displayed (interp and tkwin - * fields are needed). */ - LineItem *linePtr; /* Item to configure for arrows. */ +ConfigureArrows( + Tk_Canvas canvas, /* Canvas in which arrows will be displayed + * (interp and tkwin fields are needed). */ + LineItem *linePtr) /* Item to configure for arrows. */ { double *poly, *coordPtr; double dx, dy, length, sinTheta, cosTheta, temp; - double fracHeight; /* Line width as fraction of - * arrowhead width. */ - double backup; /* Distance to backup end points - * so the line ends in the middle - * of the arrowhead. */ - double vertX, vertY; /* Position of arrowhead vertex. */ - double shapeA, shapeB, shapeC; /* Adjusted coordinates (see - * explanation below). */ + double fracHeight; /* Line width as fraction of arrowhead + * width. */ + double backup; /* Distance to backup end points so the line + * ends in the middle of the arrowhead. */ + double vertX, vertY; /* Position of arrowhead vertex. */ + double shapeA, shapeB, shapeC; + /* Adjusted coordinates (see explanation + * below). */ double width; Tk_State state = linePtr->header.state; @@ -2110,10 +2101,10 @@ ConfigureArrows(canvas, linePtr) } /* - * The code below makes a tiny increase in the shape parameters - * for the line. This is a bit of a hack, but it seems to result - * in displays that more closely approximate the specified parameters. - * Without the adjustment, the arrows come out smaller than expected. + * The code below makes a tiny increase in the shape parameters for the + * line. This is a bit of a hack, but it seems to result in displays that + * more closely approximate the specified parameters. Without the + * adjustment, the arrows come out smaller than expected. */ shapeA = linePtr->arrowShapeA + 0.001; @@ -2121,9 +2112,9 @@ ConfigureArrows(canvas, linePtr) shapeC = linePtr->arrowShapeC + width/2.0 + 0.001; /* - * If there's an arrowhead on the first point of the line, compute - * its polygon and adjust the first point of the line so that the - * line doesn't stick out past the leading edge of the arrowhead. + * If there's an arrowhead on the first point of the line, compute its + * polygon and adjust the first point of the line so that the line doesn't + * stick out past the leading edge of the arrowhead. */ fracHeight = (width/2.0)/shapeC; @@ -2160,9 +2151,8 @@ ConfigureArrows(canvas, linePtr) poly[7] = poly[9]*fracHeight + vertY*(1.0-fracHeight); /* - * Polygon done. Now move the first point towards the second so - * that the corners at the end of the line are inside the - * arrowhead. + * Polygon done. Now move the first point towards the second so that + * the corners at the end of the line are inside the arrowhead. */ linePtr->coordPtr[0] = poly[0] - backup*cosTheta; @@ -2177,8 +2167,8 @@ ConfigureArrows(canvas, linePtr) coordPtr = linePtr->coordPtr + 2*(linePtr->numPoints-2); poly = linePtr->lastArrowPtr; if (poly == NULL) { - poly = (double *) ckalloc((unsigned) - (2*PTS_IN_ARROW*sizeof(double))); + poly = (double *) + ckalloc((unsigned) (2*PTS_IN_ARROW*sizeof(double))); poly[0] = poly[10] = coordPtr[2]; poly[1] = poly[11] = coordPtr[3]; linePtr->lastArrowPtr = poly; @@ -2194,10 +2184,10 @@ ConfigureArrows(canvas, linePtr) } vertX = poly[0] - shapeA*cosTheta; vertY = poly[1] - shapeA*sinTheta; - temp = shapeC*sinTheta; + temp = shapeC * sinTheta; poly[2] = poly[0] - shapeB*cosTheta + temp; poly[8] = poly[2] - 2*temp; - temp = shapeC*cosTheta; + temp = shapeC * cosTheta; poly[3] = poly[1] - shapeB*sinTheta - temp; poly[9] = poly[3] + 2*temp; poly[4] = poly[2]*fracHeight + vertX*(1.0-fracHeight); @@ -2216,15 +2206,13 @@ ConfigureArrows(canvas, linePtr) * * LineToPostscript -- * - * This procedure is called to generate Postscript for - * line items. + * This function is called to generate Postscript for line items. * * Results: - * The return value is a standard Tcl result. If an error - * occurs in generating Postscript then an error message is - * left in the interp's result, replacing whatever used - * to be there. If no error occurs, then Postscript for the - * item is appended to the result. + * The return value is a standard Tcl result. If an error occurs in + * generating Postscript then an error message is left in the interp's + * result, replacing whatever used to be there. If no error occurs, then + * Postscript for the item is appended to the result. * * Side effects: * None. @@ -2233,15 +2221,13 @@ ConfigureArrows(canvas, linePtr) */ static int -LineToPostscript(interp, canvas, itemPtr, prepass) - Tcl_Interp *interp; /* Leave Postscript or error message - * here. */ - Tk_Canvas canvas; /* Information about overall canvas. */ - Tk_Item *itemPtr; /* Item for which Postscript is - * wanted. */ - int prepass; /* 1 means this is a prepass to - * collect font information; 0 means - * final Postscript is being created. */ +LineToPostscript( + Tcl_Interp *interp, /* Leave Postscript or error message here. */ + Tk_Canvas canvas, /* Information about overall canvas. */ + Tk_Item *itemPtr, /* Item for which Postscript is wanted. */ + int prepass) /* 1 means this is a prepass to collect font + * information; 0 means final Postscript is + * being created. */ { LineItem *linePtr = (LineItem *) itemPtr; char buffer[64 + TCL_INTEGER_SPACE]; @@ -2290,24 +2276,23 @@ LineToPostscript(interp, canvas, itemPtr, prepass) linePtr->coordPtr[0], Tk_CanvasPsY(canvas, linePtr->coordPtr[1]), width/2.0, width/2.0); Tcl_AppendResult(interp, "matrix currentmatrix\n",buffer, - " scale 1 0 moveto 0 0 1 0 360 arc\nsetmatrix\n", (char *) NULL); - if (Tk_CanvasPsColor(interp, canvas, color) - != TCL_OK) { + " scale 1 0 moveto 0 0 1 0 360 arc\nsetmatrix\n", NULL); + if (Tk_CanvasPsColor(interp, canvas, color) != TCL_OK) { return TCL_ERROR; } if (stipple != None) { - Tcl_AppendResult(interp, "clip ", (char *) NULL); + Tcl_AppendResult(interp, "clip ", NULL); if (Tk_CanvasPsStipple(interp, canvas, stipple) != TCL_OK) { return TCL_ERROR; } } else { - Tcl_AppendResult(interp, "fill\n", (char *) NULL); + Tcl_AppendResult(interp, "fill\n", NULL); } return TCL_OK; } /* - * Generate a path for the line's center-line (do this differently - * for straight lines and smoothed lines). + * Generate a path for the line's center-line (do this differently for + * straight lines and smoothed lines). */ if ((!linePtr->smooth) || (linePtr->numPoints < 3)) { @@ -2318,29 +2303,27 @@ LineToPostscript(interp, canvas, itemPtr, prepass) linePtr->coordPtr, linePtr->numPoints, linePtr->splineSteps); } else { /* - * Special hack: Postscript printers don't appear to be able - * to turn a path drawn with "curveto"s into a clipping path - * without exceeding resource limits, so TkMakeBezierPostscript - * won't work for stippled curves. Instead, generate all of - * the intermediate points here and output them into the - * Postscript file with "lineto"s instead. + * Special hack: Postscript printers don't appear to be able to + * turn a path drawn with "curveto"s into a clipping path without + * exceeding resource limits, so TkMakeBezierPostscript won't work + * for stippled curves. Instead, generate all of the intermediate + * points here and output them into the Postscript file with + * "lineto"s instead. */ double staticPoints[2*MAX_STATIC_POINTS]; double *pointPtr; int numPoints; - numPoints = linePtr->smooth->coordProc(canvas, (double *) NULL, - linePtr->numPoints, linePtr->splineSteps, (XPoint *) NULL, - (double *) NULL); + numPoints = linePtr->smooth->coordProc(canvas, NULL, + linePtr->numPoints, linePtr->splineSteps, NULL, NULL); pointPtr = staticPoints; if (numPoints > MAX_STATIC_POINTS) { pointPtr = (double *) ckalloc((unsigned) (numPoints * 2 * sizeof(double))); } numPoints = linePtr->smooth->coordProc(canvas, linePtr->coordPtr, - linePtr->numPoints, linePtr->splineSteps, (XPoint *) NULL, - pointPtr); + linePtr->numPoints, linePtr->splineSteps, NULL, pointPtr); Tk_CanvasPsPath(interp, canvas, pointPtr, numPoints); if (pointPtr != staticPoints) { ckfree((char *) pointPtr); @@ -2358,17 +2341,16 @@ LineToPostscript(interp, canvas, itemPtr, prepass) } else if (linePtr->capStyle == CapProjecting) { style = "2 setlinecap\n"; } - Tcl_AppendResult(interp, style, (char *) NULL); + Tcl_AppendResult(interp, style, NULL); style = "0 setlinejoin\n"; if (linePtr->joinStyle == JoinRound) { style = "1 setlinejoin\n"; } else if (linePtr->joinStyle == JoinBevel) { style = "2 setlinejoin\n"; } - Tcl_AppendResult(interp, style, (char *) NULL); + Tcl_AppendResult(interp, style, NULL); - if (Tk_CanvasPsOutline(canvas, itemPtr, - &(linePtr->outline)) != TCL_OK) { + if (Tk_CanvasPsOutline(canvas, itemPtr, &(linePtr->outline)) != TCL_OK) { return TCL_ERROR; } @@ -2378,8 +2360,7 @@ LineToPostscript(interp, canvas, itemPtr, prepass) if (linePtr->firstArrowPtr != NULL) { if (stipple != None) { - Tcl_AppendResult(interp, "grestore gsave\n", - (char *) NULL); + Tcl_AppendResult(interp, "grestore gsave\n", NULL); } if (ArrowheadPostscript(interp, canvas, linePtr, linePtr->firstArrowPtr) != TCL_OK) { @@ -2388,7 +2369,7 @@ LineToPostscript(interp, canvas, itemPtr, prepass) } if (linePtr->lastArrowPtr != NULL) { if (stipple != None) { - Tcl_AppendResult(interp, "grestore gsave\n", (char *) NULL); + Tcl_AppendResult(interp, "grestore gsave\n", NULL); } if (ArrowheadPostscript(interp, canvas, linePtr, linePtr->lastArrowPtr) != TCL_OK) { @@ -2403,15 +2384,14 @@ LineToPostscript(interp, canvas, itemPtr, prepass) * * ArrowheadPostscript -- * - * This procedure is called to generate Postscript for - * an arrowhead for a line item. + * This function is called to generate Postscript for an arrowhead for a + * line item. * * Results: - * The return value is a standard Tcl result. If an error - * occurs in generating Postscript then an error message is - * left in the interp's result, replacing whatever used - * to be there. If no error occurs, then Postscript for the - * arrowhead is appended to the result. + * The return value is a standard Tcl result. If an error occurs in + * generating Postscript then an error message is left in the interp's + * result, replacing whatever used to be there. If no error occurs, then + * Postscript for the arrowhead is appended to the result. * * Side effects: * None. @@ -2420,14 +2400,13 @@ LineToPostscript(interp, canvas, itemPtr, prepass) */ static int -ArrowheadPostscript(interp, canvas, linePtr, arrowPtr) - Tcl_Interp *interp; /* Leave Postscript or error message - * here. */ - Tk_Canvas canvas; /* Information about overall canvas. */ - LineItem *linePtr; /* Line item for which Postscript is - * being generated. */ - double *arrowPtr; /* Pointer to first of five points - * describing arrowhead polygon. */ +ArrowheadPostscript( + Tcl_Interp *interp, /* Leave Postscript or error message here. */ + Tk_Canvas canvas, /* Information about overall canvas. */ + LineItem *linePtr, /* Line item for which Postscript is being + * generated. */ + double *arrowPtr) /* Pointer to first of five points describing + * arrowhead polygon. */ { Pixmap stipple; Tk_State state = linePtr->header.state; @@ -2449,13 +2428,20 @@ ArrowheadPostscript(interp, canvas, linePtr, arrowPtr) Tk_CanvasPsPath(interp, canvas, arrowPtr, PTS_IN_ARROW); if (stipple != None) { - Tcl_AppendResult(interp, "clip ", (char *) NULL); - if (Tk_CanvasPsStipple(interp, canvas, stipple) - != TCL_OK) { + Tcl_AppendResult(interp, "clip ", NULL); + if (Tk_CanvasPsStipple(interp, canvas, stipple) != TCL_OK) { return TCL_ERROR; } } else { - Tcl_AppendResult(interp, "fill\n", (char *) NULL); + Tcl_AppendResult(interp, "fill\n", NULL); } return TCL_OK; } + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ diff --git a/generic/tkCanvPoly.c b/generic/tkCanvPoly.c index 060044e..031b0a3 100644 --- a/generic/tkCanvPoly.c +++ b/generic/tkCanvPoly.c @@ -1,4 +1,4 @@ -/* +/* * tkCanvPoly.c -- * * This file implements polygon items for canvas widgets. @@ -7,10 +7,10 @@ * Copyright (c) 1994-1997 Sun Microsystems, Inc. * Copyright (c) 1998-2000 Ajuba Solutions. * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkCanvPoly.c,v 1.13 2005/08/10 22:02:22 dkf Exp $ + * RCS: @(#) $Id: tkCanvPoly.c,v 1.14 2005/11/04 15:23:05 dkf Exp $ */ #include <stdio.h> @@ -24,24 +24,28 @@ typedef struct PolygonItem { Tk_Item header; /* Generic stuff that's the same for all - * types. MUST BE FIRST IN STRUCTURE. */ + * types. MUST BE FIRST IN STRUCTURE. */ Tk_Outline outline; /* Outline structure */ - int numPoints; /* Number of points in polygon. - * Polygon is always closed. */ + int numPoints; /* Number of points in polygon. Polygon is + * always closed. */ int pointsAllocated; /* Number of points for which space is * allocated at *coordPtr. */ - double *coordPtr; /* Pointer to malloc-ed array containing - * x- and y-coords of all points in polygon. + double *coordPtr; /* Pointer to malloc-ed array containing x- + * and y-coords of all points in polygon. * X-coords are even-valued indices, y-coords * are corresponding odd-valued indices. */ int joinStyle; /* Join style for outline */ Tk_TSOffset tsoffset; XColor *fillColor; /* Foreground color for polygon. */ - XColor *activeFillColor; /* Foreground color for polygon if state is active. */ - XColor *disabledFillColor; /* Foreground color for polygon if state is disabled. */ + XColor *activeFillColor; /* Foreground color for polygon if state is + * active. */ + XColor *disabledFillColor; /* Foreground color for polygon if state is + * disabled. */ Pixmap fillStipple; /* Stipple bitmap for filling polygon. */ - Pixmap activeFillStipple; /* Stipple bitmap for filling polygon if state is active. */ - Pixmap disabledFillStipple; /* Stipple bitmap for filling polygon if state is disabled. */ + Pixmap activeFillStipple; /* Stipple bitmap for filling polygon if state + * is active. */ + Pixmap disabledFillStipple; /* Stipple bitmap for filling polygon if state + * is disabled. */ GC fillGC; /* Graphics context for filling polygon. */ Tk_SmoothMethod *smooth; /* Non-zero means draw shape smoothed (i.e. * with Bezier splines). */ @@ -81,125 +85,116 @@ static Tk_CustomOption pixelOption = { }; static Tk_ConfigSpec configSpecs[] = { - {TK_CONFIG_CUSTOM, "-activedash", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, outline.activeDash), + {TK_CONFIG_CUSTOM, "-activedash", NULL, NULL, + NULL, Tk_Offset(PolygonItem, outline.activeDash), TK_CONFIG_NULL_OK, &dashOption}, - {TK_CONFIG_COLOR, "-activefill", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, activeFillColor), - TK_CONFIG_NULL_OK}, - {TK_CONFIG_COLOR, "-activeoutline", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, outline.activeColor), - TK_CONFIG_NULL_OK}, - {TK_CONFIG_BITMAP, "-activeoutlinestipple", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, outline.activeStipple), + {TK_CONFIG_COLOR, "-activefill", NULL, NULL, + NULL, Tk_Offset(PolygonItem, activeFillColor), TK_CONFIG_NULL_OK}, + {TK_CONFIG_COLOR, "-activeoutline", NULL, NULL, + NULL, Tk_Offset(PolygonItem, outline.activeColor), TK_CONFIG_NULL_OK}, + {TK_CONFIG_BITMAP, "-activeoutlinestipple", NULL, NULL, + NULL, Tk_Offset(PolygonItem, outline.activeStipple), TK_CONFIG_NULL_OK}, - {TK_CONFIG_BITMAP, "-activestipple", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, activeFillStipple), - TK_CONFIG_NULL_OK}, - {TK_CONFIG_CUSTOM, "-activewidth", (char *) NULL, (char *) NULL, + {TK_CONFIG_BITMAP, "-activestipple", NULL, NULL, + NULL, Tk_Offset(PolygonItem, activeFillStipple), TK_CONFIG_NULL_OK}, + {TK_CONFIG_CUSTOM, "-activewidth", NULL, NULL, "0.0", Tk_Offset(PolygonItem, outline.activeWidth), TK_CONFIG_DONT_SET_DEFAULT, &pixelOption}, - {TK_CONFIG_CUSTOM, "-dash", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, outline.dash), + {TK_CONFIG_CUSTOM, "-dash", NULL, NULL, + NULL, Tk_Offset(PolygonItem, outline.dash), TK_CONFIG_NULL_OK, &dashOption}, - {TK_CONFIG_PIXELS, "-dashoffset", (char *) NULL, (char *) NULL, + {TK_CONFIG_PIXELS, "-dashoffset", NULL, NULL, "0", Tk_Offset(PolygonItem, outline.offset), TK_CONFIG_DONT_SET_DEFAULT}, - {TK_CONFIG_CUSTOM, "-disableddash", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, outline.disabledDash), + {TK_CONFIG_CUSTOM, "-disableddash", NULL, NULL, + NULL, Tk_Offset(PolygonItem, outline.disabledDash), TK_CONFIG_NULL_OK, &dashOption}, - {TK_CONFIG_COLOR, "-disabledfill", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, disabledFillColor), - TK_CONFIG_NULL_OK}, - {TK_CONFIG_COLOR, "-disabledoutline", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, outline.disabledColor), + {TK_CONFIG_COLOR, "-disabledfill", NULL, NULL, + NULL, Tk_Offset(PolygonItem, disabledFillColor), TK_CONFIG_NULL_OK}, + {TK_CONFIG_COLOR, "-disabledoutline", NULL, NULL, + NULL, Tk_Offset(PolygonItem, outline.disabledColor), TK_CONFIG_NULL_OK}, - {TK_CONFIG_BITMAP, "-disabledoutlinestipple", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, outline.disabledStipple), + {TK_CONFIG_BITMAP, "-disabledoutlinestipple", NULL, NULL, + NULL, Tk_Offset(PolygonItem, outline.disabledStipple), TK_CONFIG_NULL_OK}, - {TK_CONFIG_BITMAP, "-disabledstipple", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, disabledFillStipple), - TK_CONFIG_NULL_OK}, - {TK_CONFIG_CUSTOM, "-disabledwidth", (char *) NULL, (char *) NULL, + {TK_CONFIG_BITMAP, "-disabledstipple", NULL, NULL, + NULL, Tk_Offset(PolygonItem, disabledFillStipple), TK_CONFIG_NULL_OK}, + {TK_CONFIG_CUSTOM, "-disabledwidth", NULL, NULL, "0.0", Tk_Offset(PolygonItem, outline.disabledWidth), TK_CONFIG_DONT_SET_DEFAULT, &pixelOption}, - {TK_CONFIG_COLOR, "-fill", (char *) NULL, (char *) NULL, + {TK_CONFIG_COLOR, "-fill", NULL, NULL, "black", Tk_Offset(PolygonItem, fillColor), TK_CONFIG_NULL_OK}, - {TK_CONFIG_JOIN_STYLE, "-joinstyle", (char *) NULL, (char *) NULL, + {TK_CONFIG_JOIN_STYLE, "-joinstyle", NULL, NULL, "round", Tk_Offset(PolygonItem, joinStyle), TK_CONFIG_DONT_SET_DEFAULT}, - {TK_CONFIG_CUSTOM, "-offset", (char *) NULL, (char *) NULL, + {TK_CONFIG_CUSTOM, "-offset", NULL, NULL, "0,0", Tk_Offset(PolygonItem, tsoffset), TK_CONFIG_NULL_OK, &offsetOption}, - {TK_CONFIG_COLOR, "-outline", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, outline.color), - TK_CONFIG_NULL_OK}, - {TK_CONFIG_CUSTOM, "-outlineoffset", (char *) NULL, (char *) NULL, + {TK_CONFIG_COLOR, "-outline", NULL, NULL, + NULL, Tk_Offset(PolygonItem, outline.color), TK_CONFIG_NULL_OK}, + {TK_CONFIG_CUSTOM, "-outlineoffset", NULL, NULL, "0,0", Tk_Offset(PolygonItem, outline.tsoffset), TK_CONFIG_NULL_OK, &offsetOption}, - {TK_CONFIG_BITMAP, "-outlinestipple", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, outline.stipple), - TK_CONFIG_NULL_OK}, - {TK_CONFIG_CUSTOM, "-smooth", (char *) NULL, (char *) NULL, + {TK_CONFIG_BITMAP, "-outlinestipple", NULL, NULL, + NULL, Tk_Offset(PolygonItem, outline.stipple), TK_CONFIG_NULL_OK}, + {TK_CONFIG_CUSTOM, "-smooth", NULL, NULL, "0", Tk_Offset(PolygonItem, smooth), TK_CONFIG_DONT_SET_DEFAULT, &smoothOption}, - {TK_CONFIG_INT, "-splinesteps", (char *) NULL, (char *) NULL, + {TK_CONFIG_INT, "-splinesteps", NULL, NULL, "12", Tk_Offset(PolygonItem, splineSteps), TK_CONFIG_DONT_SET_DEFAULT}, - {TK_CONFIG_CUSTOM, "-state", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(Tk_Item, state), TK_CONFIG_NULL_OK, - &stateOption}, - {TK_CONFIG_BITMAP, "-stipple", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(PolygonItem, fillStipple), TK_CONFIG_NULL_OK}, - {TK_CONFIG_CUSTOM, "-tags", (char *) NULL, (char *) NULL, - (char *) NULL, 0, TK_CONFIG_NULL_OK, &tagsOption}, - {TK_CONFIG_CUSTOM, "-width", (char *) NULL, (char *) NULL, + {TK_CONFIG_CUSTOM, "-state", NULL, NULL, + NULL, Tk_Offset(Tk_Item, state), TK_CONFIG_NULL_OK, &stateOption}, + {TK_CONFIG_BITMAP, "-stipple", NULL, NULL, + NULL, Tk_Offset(PolygonItem, fillStipple), TK_CONFIG_NULL_OK}, + {TK_CONFIG_CUSTOM, "-tags", NULL, NULL, + NULL, 0, TK_CONFIG_NULL_OK, &tagsOption}, + {TK_CONFIG_CUSTOM, "-width", NULL, NULL, "1.0", Tk_Offset(PolygonItem, outline.width), TK_CONFIG_DONT_SET_DEFAULT, &pixelOption}, - {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL, - (char *) NULL, 0, 0} + {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0} }; /* - * Prototypes for procedures defined in this file: + * Prototypes for functions defined in this file: */ -static void ComputePolygonBbox _ANSI_ARGS_((Tk_Canvas canvas, - PolygonItem *polyPtr)); -static int ConfigurePolygon _ANSI_ARGS_((Tcl_Interp *interp, +static void ComputePolygonBbox(Tk_Canvas canvas, + PolygonItem *polyPtr); +static int ConfigurePolygon(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int objc, - Tcl_Obj *CONST objv[], int flags)); -static int CreatePolygon _ANSI_ARGS_((Tcl_Interp *interp, + Tcl_Obj *CONST objv[], int flags); +static int CreatePolygon(Tcl_Interp *interp, Tk_Canvas canvas, struct Tk_Item *itemPtr, - int objc, Tcl_Obj *CONST objv[])); -static void DeletePolygon _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, Display *display)); -static void DisplayPolygon _ANSI_ARGS_((Tk_Canvas canvas, + int objc, Tcl_Obj *CONST objv[]); +static void DeletePolygon(Tk_Canvas canvas, + Tk_Item *itemPtr, Display *display); +static void DisplayPolygon(Tk_Canvas canvas, Tk_Item *itemPtr, Display *display, Drawable dst, - int x, int y, int width, int height)); -static int GetPolygonIndex _ANSI_ARGS_((Tcl_Interp *interp, + int x, int y, int width, int height); +static int GetPolygonIndex(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, - Tcl_Obj *obj, int *indexPtr)); -static int PolygonCoords _ANSI_ARGS_((Tcl_Interp *interp, + Tcl_Obj *obj, int *indexPtr); +static int PolygonCoords(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, - int objc, Tcl_Obj *CONST objv[])); -static void PolygonDeleteCoords _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, int first, int last)); -static void PolygonInsert _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, int beforeThis, Tcl_Obj *obj)); -static int PolygonToArea _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, double *rectPtr)); -static double PolygonToPoint _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, double *pointPtr)); -static int PolygonToPostscript _ANSI_ARGS_((Tcl_Interp *interp, - Tk_Canvas canvas, Tk_Item *itemPtr, int prepass)); -static void ScalePolygon _ANSI_ARGS_((Tk_Canvas canvas, + int objc, Tcl_Obj *CONST objv[]); +static void PolygonDeleteCoords(Tk_Canvas canvas, + Tk_Item *itemPtr, int first, int last); +static void PolygonInsert(Tk_Canvas canvas, + Tk_Item *itemPtr, int beforeThis, Tcl_Obj *obj); +static int PolygonToArea(Tk_Canvas canvas, + Tk_Item *itemPtr, double *rectPtr); +static double PolygonToPoint(Tk_Canvas canvas, + Tk_Item *itemPtr, double *pointPtr); +static int PolygonToPostscript(Tcl_Interp *interp, + Tk_Canvas canvas, Tk_Item *itemPtr, int prepass); +static void ScalePolygon(Tk_Canvas canvas, Tk_Item *itemPtr, double originX, double originY, - double scaleX, double scaleY)); -static void TranslatePolygon _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, double deltaX, double deltaY)); + double scaleX, double scaleY); +static void TranslatePolygon(Tk_Canvas canvas, + Tk_Item *itemPtr, double deltaX, double deltaY); /* - * The structures below defines the polygon item type by means - * of procedures that can be invoked by generic item code. + * The structures below defines the polygon item type by means of functions + * that can be invoked by generic item code. */ Tk_ItemType tkPolygonType = { @@ -218,17 +213,17 @@ Tk_ItemType tkPolygonType = { ScalePolygon, /* scaleProc */ TranslatePolygon, /* translateProc */ (Tk_ItemIndexProc *) GetPolygonIndex,/* indexProc */ - (Tk_ItemCursorProc *) NULL, /* icursorProc */ - (Tk_ItemSelectionProc *) NULL, /* selectionProc */ + NULL, /* icursorProc */ + NULL, /* selectionProc */ (Tk_ItemInsertProc *) PolygonInsert,/* insertProc */ PolygonDeleteCoords, /* dTextProc */ - (Tk_ItemType *) NULL, /* nextPtr */ + NULL, /* nextPtr */ }; /* - * The definition below determines how large are static arrays - * used to hold spline points (splines larger than this have to - * have their arrays malloc-ed). + * The definition below determines how large are static arrays used to hold + * spline points (splines larger than this have to have their arrays + * malloc-ed). */ #define MAX_STATIC_POINTS 200 @@ -238,14 +233,12 @@ Tk_ItemType tkPolygonType = { * * CreatePolygon -- * - * This procedure is invoked to create a new polygon item in - * a canvas. + * This function is invoked to create a new polygon item in a canvas. * * Results: - * A standard Tcl return value. If an error occurred in - * creating the item, then an error message is left in - * the interp's result; in this case itemPtr is - * left uninitialized, so it can be safely freed by the + * A standard Tcl return value. If an error occurred in creating the + * item, then an error message is left in the interp's result; in this + * case itemPtr is left uninitialized, so it can be safely freed by the * caller. * * Side effects: @@ -255,13 +248,13 @@ Tk_ItemType tkPolygonType = { */ static int -CreatePolygon(interp, canvas, itemPtr, objc, objv) - Tcl_Interp *interp; /* Interpreter for error reporting. */ - Tk_Canvas canvas; /* Canvas to hold new item. */ - 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 polygon. */ +CreatePolygon( + Tcl_Interp *interp, /* Interpreter for error reporting. */ + Tk_Canvas canvas, /* Canvas to hold new item. */ + 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 polygon. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; int i; @@ -271,8 +264,8 @@ CreatePolygon(interp, canvas, itemPtr, objc, objv) } /* - * Carry out initialization that is needed in order to clean - * up after errors during the the remainder of this procedure. + * Carry out initialization that is needed in order to clean up after + * errors during the the remainder of this function. */ Tk_CreateOutline(&(polyPtr->outline)); @@ -290,14 +283,14 @@ CreatePolygon(interp, canvas, itemPtr, objc, objv) polyPtr->activeFillStipple = None; polyPtr->disabledFillStipple = None; polyPtr->fillGC = None; - polyPtr->smooth = (Tk_SmoothMethod *) NULL; + polyPtr->smooth = NULL; polyPtr->splineSteps = 12; polyPtr->autoClosed = 0; /* - * Count the number of points and then parse them into a point - * array. Leading arguments are assumed to be points if they - * start with a digit or a minus sign followed by a digit. + * Count the number of points and then parse them into a point array. + * Leading arguments are assumed to be points if they start with a digit + * or a minus sign followed by a digit. */ for (i = 0; i < objc; i++) { @@ -315,7 +308,7 @@ CreatePolygon(interp, canvas, itemPtr, objc, objv) return TCL_OK; } - error: + error: DeletePolygon(canvas, itemPtr, Tk_Display(Tk_CanvasTkwin(canvas))); return TCL_ERROR; } @@ -325,9 +318,8 @@ CreatePolygon(interp, canvas, itemPtr, objc, objv) * * PolygonCoords -- * - * This procedure is invoked to process the "coords" widget - * command on polygons. See the user documentation for details - * on what it does. + * This function is invoked to process the "coords" widget command on + * polygons. See the user documentation for details on what it does. * * Results: * Returns TCL_OK or TCL_ERROR, and sets the interp's result. @@ -339,25 +331,25 @@ CreatePolygon(interp, canvas, itemPtr, objc, objv) */ static int -PolygonCoords(interp, canvas, itemPtr, objc, objv) - Tcl_Interp *interp; /* Used for error reporting. */ - Tk_Canvas canvas; /* Canvas containing item. */ - 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, ... */ +PolygonCoords( + Tcl_Interp *interp, /* Used for error reporting. */ + Tk_Canvas canvas, /* Canvas containing item. */ + 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, ... */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; int i, numPoints; if (objc == 0) { /* - * Print the coords used to create the polygon. If we auto - * closed the polygon then we don't report the last point. + * Print the coords used to create the polygon. If we auto closed the + * polygon then we don't report the last point. */ + Tcl_Obj *subobj, *obj = Tcl_NewObj(); + for (i = 0; i < 2*(polyPtr->numPoints - polyPtr->autoClosed); i++) { subobj = Tcl_NewDoubleObj(polyPtr->coordPtr[i]); Tcl_ListObjAppendElement(interp, obj, subobj); @@ -373,6 +365,7 @@ PolygonCoords(interp, canvas, itemPtr, objc, objv) } if (objc & 1) { char buf[64 + TCL_INTEGER_SPACE]; + sprintf(buf, "wrong # coordinates: expected an even number, got %d", objc); Tcl_SetResult(interp, buf, TCL_VOLATILE); @@ -385,8 +378,8 @@ PolygonCoords(interp, canvas, itemPtr, objc, objv) } /* - * One extra point gets allocated here, because we always - * add another point to close the polygon. + * One extra point gets allocated here, because we always add + * another point to close the polygon. */ polyPtr->coordPtr = (double *) ckalloc((unsigned) @@ -405,7 +398,7 @@ PolygonCoords(interp, canvas, itemPtr, objc, objv) /* * Close the polygon if it isn't already closed. */ - + if (objc>2 && ((polyPtr->coordPtr[objc-2] != polyPtr->coordPtr[0]) || (polyPtr->coordPtr[objc-1] != polyPtr->coordPtr[1]))) { polyPtr->autoClosed = 1; @@ -423,28 +416,28 @@ PolygonCoords(interp, canvas, itemPtr, objc, objv) * * ConfigurePolygon -- * - * This procedure is invoked to configure various aspects - * of a polygon item such as its background color. + * This function is invoked to configure various aspects of a polygon + * item such as its background color. * * Results: - * A standard Tcl result code. If an error occurs, then - * an error message is left in the interp's result. + * A standard Tcl result code. If an error occurs, then an error message + * is left in the interp's result. * * Side effects: - * Configuration information, such as colors and stipple - * patterns, may be set for itemPtr. + * Configuration information, such as colors and stipple patterns, may be + * set for itemPtr. * *-------------------------------------------------------------- */ static int -ConfigurePolygon(interp, canvas, itemPtr, objc, objv, flags) - Tcl_Interp *interp; /* Interpreter for error reporting. */ - Tk_Canvas canvas; /* Canvas containing itemPtr. */ - Tk_Item *itemPtr; /* Polygon item to reconfigure. */ - int objc; /* Number of elements in objv. */ - Tcl_Obj *CONST objv[]; /* Arguments describing things to configure. */ - int flags; /* Flags to pass to Tk_ConfigureWidget. */ +ConfigurePolygon( + Tcl_Interp *interp, /* Interpreter for error reporting. */ + Tk_Canvas canvas, /* Canvas containing itemPtr. */ + Tk_Item *itemPtr, /* Polygon item to reconfigure. */ + int objc, /* Number of elements in objv. */ + Tcl_Obj *CONST objv[], /* Arguments describing things to configure. */ + int flags) /* Flags to pass to Tk_ConfigureWidget. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; XGCValues gcValues; @@ -462,8 +455,8 @@ ConfigurePolygon(interp, canvas, itemPtr, objc, objv, flags) } /* - * A few of the options require additional processing, such as - * graphics contexts. + * A few of the options require additional processing, such as graphics + * contexts. */ state = itemPtr->state; @@ -555,8 +548,8 @@ ConfigurePolygon(interp, canvas, itemPtr, objc, objv, flags) * * DeletePolygon -- * - * This procedure is called to clean up the data structure - * associated with a polygon item. + * This function is called to clean up the data structure associated with + * a polygon item. * * Results: * None. @@ -568,11 +561,10 @@ ConfigurePolygon(interp, canvas, itemPtr, objc, objv, flags) */ static void -DeletePolygon(canvas, itemPtr, display) - Tk_Canvas canvas; /* Info about overall canvas widget. */ - Tk_Item *itemPtr; /* Item that is being deleted. */ - Display *display; /* Display containing window for - * canvas. */ +DeletePolygon( + Tk_Canvas canvas, /* Info about overall canvas widget. */ + Tk_Item *itemPtr, /* Item that is being deleted. */ + Display *display) /* Display containing window for canvas. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; @@ -608,24 +600,22 @@ DeletePolygon(canvas, itemPtr, display) * * ComputePolygonBbox -- * - * This procedure is invoked to compute the bounding box of - * all the pixels that may be drawn as part of a polygon. + * This function is invoked to compute the bounding box of all the pixels + * that may be drawn as part of a polygon. * * Results: * None. * * Side effects: - * The fields x1, y1, x2, and y2 are updated in the header - * for itemPtr. + * The fields x1, y1, x2, and y2 are updated in the header for itemPtr. * *-------------------------------------------------------------- */ static void -ComputePolygonBbox(canvas, polyPtr) - Tk_Canvas canvas; /* Canvas that contains item. */ - PolygonItem *polyPtr; /* Item whose bbox is to be - * recomputed. */ +ComputePolygonBbox( + Tk_Canvas canvas, /* Canvas that contains item. */ + PolygonItem *polyPtr) /* Item whose bbox is to be recomputed. */ { double *coordPtr; int i; @@ -657,12 +647,11 @@ ComputePolygonBbox(canvas, polyPtr) polyPtr->header.y1 = polyPtr->header.y2 = (int) coordPtr[1]; /* - * Compute the bounding box of all the points in the polygon, - * then expand in all directions by the outline's width to take - * care of butting or rounded corners and projecting or - * rounded caps. This expansion is an overestimate (worst-case - * is square root of two over two) but it's simple. Don't do - * anything special for curves. This causes an additional + * Compute the bounding box of all the points in the polygon, then expand + * in all directions by the outline's width to take care of butting or + * rounded corners and projecting or rounded caps. This expansion is an + * overestimate (worst-case is square root of two over two) but it's + * simple. Don't do anything special for curves. This causes an additional * overestimate in the bounding box, but is faster. */ @@ -708,6 +697,7 @@ ComputePolygonBbox(canvas, polyPtr) if (tsoffset) { if (tsoffset->flags & TK_OFFSET_INDEX) { int index = tsoffset->flags & ~TK_OFFSET_INDEX; + if (tsoffset->flags == INT_MAX) { index = (polyPtr->numPoints - 1) * 2; } @@ -743,13 +733,14 @@ ComputePolygonBbox(canvas, polyPtr) /* * For mitered lines, make a second pass through all the points. - * Compute the locations of the two miter vertex points and add - * those into the bounding box. + * Compute the locations of the two miter vertex points and add those + * into the bounding box. */ if (polyPtr->joinStyle == JoinMiter) { double miter[4]; int j; + coordPtr = polyPtr->coordPtr; if (polyPtr->numPoints>3) { if (TkGetMiterPoints(coordPtr+2*(polyPtr->numPoints-2), @@ -760,9 +751,8 @@ ComputePolygonBbox(canvas, polyPtr) } } } - for (i = polyPtr->numPoints ; i >= 3; - i--, coordPtr += 2) { - + for (i = polyPtr->numPoints ; i >= 3; i--, coordPtr += 2) { + if (TkGetMiterPoints(coordPtr, coordPtr+2, coordPtr+4, width, miter, miter+2)) { for (j = 0; j < 4; j += 2) { @@ -774,8 +764,8 @@ ComputePolygonBbox(canvas, polyPtr) } /* - * Add one more pixel of fudge factor just to be safe (e.g. - * X may round differently than we do). + * Add one more pixel of fudge factor just to be safe (e.g. X may round + * differently than we do). */ polyPtr->header.x1 -= 1; @@ -789,34 +779,33 @@ ComputePolygonBbox(canvas, polyPtr) * * TkFillPolygon -- * - * This procedure is invoked to convert a polygon to screen - * coordinates and display it using a particular GC. + * This function is invoked to convert a polygon to screen coordinates + * and display it using a particular GC. * * Results: * None. * * Side effects: - * ItemPtr is drawn in drawable using the transformation - * information in canvas. + * ItemPtr is drawn in drawable using the transformation information in + * canvas. * *-------------------------------------------------------------- */ void -TkFillPolygon(canvas, coordPtr, numPoints, display, drawable, gc, outlineGC) - Tk_Canvas canvas; /* Canvas whose coordinate system - * is to be used for drawing. */ - double *coordPtr; /* Array of coordinates for polygon: - * x1, y1, x2, y2, .... */ - int numPoints; /* Twice this many coordinates are - * present at *coordPtr. */ - Display *display; /* Display on which to draw polygon. */ - Drawable drawable; /* Pixmap or window in which to draw - * polygon. */ - GC gc; /* Graphics context for drawing. */ - GC outlineGC; /* If not None, use this to draw an - * outline around the polygon after - * filling it. */ +TkFillPolygon( + Tk_Canvas canvas, /* Canvas whose coordinate system is to be + * used for drawing. */ + double *coordPtr, /* Array of coordinates for polygon: x1, y1, + * x2, y2, .... */ + int numPoints, /* Twice this many coordinates are present at + * *coordPtr. */ + Display *display, /* Display on which to draw polygon. */ + Drawable drawable, /* Pixmap or window in which to draw + * polygon. */ + GC gc, /* Graphics context for drawing. */ + GC outlineGC) /* If not None, use this to draw an outline + * around the polygon after filling it. */ { XPoint staticPoints[MAX_STATIC_POINTS]; XPoint *pointPtr; @@ -824,9 +813,9 @@ TkFillPolygon(canvas, coordPtr, numPoints, display, drawable, gc, outlineGC) int i; /* - * Build up an array of points in screen coordinates. Use a - * static array unless the polygon has an enormous number of points; - * in this case, dynamically allocate an array. + * Build up an array of points in screen coordinates. Use a static array + * unless the polygon has an enormous number of points; in this case, + * dynamically allocate an array. */ if (numPoints <= MAX_STATIC_POINTS) { @@ -835,7 +824,7 @@ TkFillPolygon(canvas, coordPtr, numPoints, display, drawable, gc, outlineGC) pointPtr = (XPoint *) ckalloc((unsigned) (numPoints * sizeof(XPoint))); } - for (i = 0, pPtr = pointPtr; i < numPoints; i += 1, coordPtr += 2, pPtr++) { + for (i=0, pPtr=pointPtr ; i<numPoints; i+=1, coordPtr+=2, pPtr++) { Tk_CanvasDrawableCoords(canvas, coordPtr[0], coordPtr[1], &pPtr->x, &pPtr->y); } @@ -863,28 +852,27 @@ TkFillPolygon(canvas, coordPtr, numPoints, display, drawable, gc, outlineGC) * * DisplayPolygon -- * - * This procedure is invoked to draw a polygon item in a given - * drawable. + * This function is invoked to draw a polygon item in a given drawable. * * Results: * None. * * Side effects: - * ItemPtr is drawn in drawable using the transformation - * information in canvas. + * ItemPtr is drawn in drawable using the transformation information in + * canvas. * *-------------------------------------------------------------- */ static void -DisplayPolygon(canvas, itemPtr, display, drawable, x, y, width, height) - Tk_Canvas canvas; /* Canvas that contains item. */ - Tk_Item *itemPtr; /* Item to be displayed. */ - Display *display; /* Display on which to draw item. */ - Drawable drawable; /* Pixmap or window in which to draw - * item. */ - int x, y, width, height; /* Describes region of canvas that - * must be redisplayed (not used). */ +DisplayPolygon( + Tk_Canvas canvas, /* Canvas that contains item. */ + Tk_Item *itemPtr, /* Item to be displayed. */ + Display *display, /* Display on which to draw item. */ + Drawable drawable, /* Pixmap or window in which to draw item. */ + int x, int y, int width, int height) + /* Describes region of canvas that must be + * redisplayed (not used). */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; Tk_State state = itemPtr->state; @@ -897,7 +885,7 @@ DisplayPolygon(canvas, itemPtr, display, drawable, x, y, width, height) return; } - if(state == TK_STATE_NULL) { + if (state == TK_STATE_NULL) { state = ((TkCanvas *)canvas)->canvas_state; } if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) { @@ -915,16 +903,17 @@ DisplayPolygon(canvas, itemPtr, display, drawable, x, y, width, height) stipple = polyPtr->disabledFillStipple; } } + /* - * If we're stippling then modify the stipple offset in the GC. Be - * sure to reset the offset when done, since the GC is supposed to be - * read-only. + * If we're stippling then modify the stipple offset in the GC. Be sure to + * reset the offset when done, since the GC is supposed to be read-only. */ if ((stipple != None) && (polyPtr->fillGC != None)) { Tk_TSOffset *tsoffset = &polyPtr->tsoffset; int w=0; int h=0; int flags = tsoffset->flags; + if (!(flags & TK_OFFSET_INDEX) && (flags & (TK_OFFSET_CENTER|TK_OFFSET_MIDDLE))) { Tk_SizeOfBitmap(display, stipple, &w, &h); if (flags & TK_OFFSET_CENTER) { @@ -949,6 +938,7 @@ DisplayPolygon(canvas, itemPtr, display, drawable, x, y, width, height) if(polyPtr->numPoints < 3) { short x,y; int intLineWidth = (int) (linewidth + 0.5); + if (intLineWidth < 1) { intLineWidth = 1; } @@ -967,13 +957,12 @@ DisplayPolygon(canvas, itemPtr, display, drawable, x, y, width, height) XPoint *pointPtr; /* - * This is a smoothed polygon. Display using a set of generated - * spline points rather than the original points. + * This is a smoothed polygon. Display using a set of generated spline + * points rather than the original points. */ - numPoints = polyPtr->smooth->coordProc(canvas, (double *) NULL, - polyPtr->numPoints, polyPtr->splineSteps, (XPoint *) NULL, - (double *) NULL); + numPoints = polyPtr->smooth->coordProc(canvas, NULL, + polyPtr->numPoints, polyPtr->splineSteps, NULL, NULL); if (numPoints <= MAX_STATIC_POINTS) { pointPtr = staticPoints; } else { @@ -981,8 +970,7 @@ DisplayPolygon(canvas, itemPtr, display, drawable, x, y, width, height) (numPoints * sizeof(XPoint))); } numPoints = polyPtr->smooth->coordProc(canvas, polyPtr->coordPtr, - polyPtr->numPoints, polyPtr->splineSteps, pointPtr, - (double *) NULL); + polyPtr->numPoints, polyPtr->splineSteps, pointPtr, NULL); if (polyPtr->fillGC != None) { XFillPolygon(display, drawable, polyPtr->fillGC, pointPtr, numPoints, Complex, CoordModeOrigin); @@ -1018,12 +1006,12 @@ DisplayPolygon(canvas, itemPtr, display, drawable, x, y, width, height) */ static void -PolygonInsert(canvas, itemPtr, beforeThis, obj) - Tk_Canvas canvas; /* Canvas containing text item. */ - Tk_Item *itemPtr; /* Line item to be modified. */ - int beforeThis; /* Index before which new coordinates - * are to be inserted. */ - Tcl_Obj *obj; /* New coordinates to be inserted. */ +PolygonInsert( + Tk_Canvas canvas, /* Canvas containing text item. */ + Tk_Item *itemPtr, /* Line item to be modified. */ + int beforeThis, /* Index before which new coordinates are to + * be inserted. */ + Tcl_Obj *obj) /* New coordinates to be inserted. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; int length, objc, i; @@ -1035,36 +1023,41 @@ PolygonInsert(canvas, itemPtr, beforeThis, obj) state = ((TkCanvas *)canvas)->canvas_state; } - if (!obj || (Tcl_ListObjGetElements((Tcl_Interp *) NULL, obj, &objc, &objv) != TCL_OK) + if (!obj || (Tcl_ListObjGetElements(NULL, obj, &objc, &objv) != TCL_OK) || !objc || objc&1) { return; } length = 2*(polyPtr->numPoints - polyPtr->autoClosed); - while(beforeThis>length) beforeThis-=length; - while(beforeThis<0) beforeThis+=length; + while (beforeThis>length) { + beforeThis -= length; + } + while (beforeThis<0) { + beforeThis += length; + } new = (double *) ckalloc((unsigned)(sizeof(double) * (length + 2 + objc))); for (i=0; i<beforeThis; i++) { new[i] = polyPtr->coordPtr[i]; } for (i=0; i<objc; i++) { - if (Tcl_GetDoubleFromObj((Tcl_Interp *) NULL,objv[i], - new+(i+beforeThis))!=TCL_OK) { + if (Tcl_GetDoubleFromObj(NULL, objv[i], new+(i+beforeThis)) != TCL_OK){ ckfree((char *) new); return; } } - for(i=beforeThis; i<length; i++) { + for (i=beforeThis; i<length; i++) { new[i+objc] = polyPtr->coordPtr[i]; } - if(polyPtr->coordPtr) ckfree((char *) polyPtr->coordPtr); - length+=objc; + if (polyPtr->coordPtr) { + ckfree((char *) polyPtr->coordPtr); + } + length += objc; polyPtr->coordPtr = new; polyPtr->numPoints = (length/2) + polyPtr->autoClosed; /* - * Close the polygon if it isn't already closed, or remove autoclosing - * if the user's coordinates are now closed. + * Close the polygon if it isn't already closed, or remove autoclosing if + * the user's coordinates are now closed. */ if (polyPtr->autoClosed) { @@ -1072,8 +1065,7 @@ PolygonInsert(canvas, itemPtr, beforeThis, obj) polyPtr->autoClosed = 0; polyPtr->numPoints--; } - } - else { + } else { if ((new[length-2] != new[0]) || (new[length-1] != new[1])) { polyPtr->autoClosed = 1; polyPtr->numPoints++; @@ -1084,52 +1076,60 @@ PolygonInsert(canvas, itemPtr, beforeThis, obj) new[length+1] = new[1]; if (((length-objc)>3) && (state != TK_STATE_HIDDEN)) { /* - * This is some optimizing code that will result that only the part - * of the polygon that changed (and the objects that are overlapping - * with that part) need to be redrawn. A special flag is set that - * instructs the general canvas code not to redraw the whole - * object. If this flag is not set, the canvas will do the redrawing, - * otherwise I have to do it here. + * This is some optimizing code that will result that only the part of + * the polygon that changed (and the objects that are overlapping with + * that part) need to be redrawn. A special flag is set that instructs + * the general canvas code not to redraw the whole object. If this + * flag is not set, the canvas will do the redrawing, otherwise I have + * to do it here. */ + double width; int j; itemPtr->redraw_flags |= TK_ITEM_DONT_REDRAW; /* - * The header elements that normally are used for the - * bounding box, are now used to calculate the bounding - * box for only the part that has to be redrawn. That - * doesn't matter, because afterwards the bounding - * box has to be re-calculated anyway. + * The header elements that normally are used for the bounding box, + * are now used to calculate the bounding box for only the part that + * has to be redrawn. That doesn't matter, because afterwards the + * bounding box has to be re-calculated anyway. */ itemPtr->x1 = itemPtr->x2 = (int) polyPtr->coordPtr[beforeThis]; itemPtr->y1 = itemPtr->y2 = (int) polyPtr->coordPtr[beforeThis+1]; beforeThis-=2; objc+=4; - if(polyPtr->smooth) { - beforeThis-=2; objc+=4; - } /* be carefull; beforeThis could now be negative */ - for(i=beforeThis; i<beforeThis+objc; i+=2) { - j=i; - if(j<0) j+=length; - if(j>=length) j-=length; - TkIncludePoint(itemPtr, polyPtr->coordPtr+j); + if (polyPtr->smooth) { + beforeThis-=2; + objc+=4; + } + + /* + * Be careful; beforeThis could now be negative + */ + + for (i=beforeThis; i<beforeThis+objc; i+=2) { + j = i; + if (j<0) { + j += length; + } else if (j>=length) { + j -= length; + } + TkIncludePoint(itemPtr, polyPtr->coordPtr+j); } width = polyPtr->outline.width; if (((TkCanvas *)canvas)->currentItemPtr == itemPtr) { - if (polyPtr->outline.activeWidth>width) { - width = polyPtr->outline.activeWidth; - } + if (polyPtr->outline.activeWidth > width) { + width = polyPtr->outline.activeWidth; + } } else if (state==TK_STATE_DISABLED) { - if (polyPtr->outline.disabledWidth>0.0) { - width = polyPtr->outline.disabledWidth; - } + if (polyPtr->outline.disabledWidth > 0.0) { + width = polyPtr->outline.disabledWidth; + } } itemPtr->x1 -= (int) width; itemPtr->y1 -= (int) width; itemPtr->x2 += (int) width; itemPtr->y2 += (int) width; Tk_CanvasEventuallyRedraw(canvas, - itemPtr->x1, itemPtr->y1, - itemPtr->x2, itemPtr->y2); + itemPtr->x1, itemPtr->y1, itemPtr->x2, itemPtr->y2); } ComputePolygonBbox(canvas, polyPtr); @@ -1146,44 +1146,54 @@ PolygonInsert(canvas, itemPtr, beforeThis, obj) * None. * * Side effects: - * Characters between "first" and "last", inclusive, get - * deleted from itemPtr. + * Characters between "first" and "last", inclusive, get deleted from + * itemPtr. * *-------------------------------------------------------------- */ static void -PolygonDeleteCoords(canvas, itemPtr, first, last) - Tk_Canvas canvas; /* Canvas containing itemPtr. */ - Tk_Item *itemPtr; /* Item in which to delete characters. */ - int first; /* Index of first character to delete. */ - int last; /* Index of last character to delete. */ +PolygonDeleteCoords( + Tk_Canvas canvas, /* Canvas containing itemPtr. */ + Tk_Item *itemPtr, /* Item in which to delete characters. */ + int first, /* Index of first character to delete. */ + int last) /* Index of last character to delete. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; int count, i; int length = 2*(polyPtr->numPoints - polyPtr->autoClosed); - while(first>=length) first-=length; - while(first<0) first+=length; - while(last>=length) last-=length; - while(last<0) last+=length; + while (first>=length) { + first -= length; + } + while (first<0) { + first += length; + } + while (last>=length) { + last -= length; + } + while (last<0) { + last += length; + } first &= -2; last &= -2; count = last + 2 - first; - if(count<=0) count +=length; + if (count<=0) { + count += length; + } - if(count >= length) { + if (count >= length) { polyPtr->numPoints = 0; - if(polyPtr->coordPtr != NULL) { + if (polyPtr->coordPtr != NULL) { ckfree((char *) polyPtr->coordPtr); } ComputePolygonBbox(canvas, polyPtr); return; } - if(last>=first) { + if (last>=first) { for(i=last+2; i<length; i++) { polyPtr->coordPtr[i-count] = polyPtr->coordPtr[i]; } @@ -1203,14 +1213,14 @@ PolygonDeleteCoords(canvas, itemPtr, first, last) * * PolygonToPoint -- * - * Computes the distance from a given point to a given - * polygon, in canvas units. + * Computes the distance from a given point to a given polygon, in canvas + * units. * * Results: - * The return value is 0 if the point whose x and y coordinates - * are pointPtr[0] and pointPtr[1] is inside the polygon. If the - * point isn't inside the polygon then the return value is the - * distance from the point to the polygon. + * The return value is 0 if the point whose x and y coordinates are + * pointPtr[0] and pointPtr[1] is inside the polygon. If the point isn't + * inside the polygon then the return value is the distance from the + * point to the polygon. * * Side effects: * None. @@ -1220,10 +1230,10 @@ PolygonDeleteCoords(canvas, itemPtr, first, last) /* ARGSUSED */ static double -PolygonToPoint(canvas, itemPtr, pointPtr) - Tk_Canvas canvas; /* Canvas containing item. */ - Tk_Item *itemPtr; /* Item to check against point. */ - double *pointPtr; /* Pointer to x and y coordinates. */ +PolygonToPoint( + Tk_Canvas canvas, /* Canvas containing item. */ + Tk_Item *itemPtr, /* Item to check against point. */ + double *pointPtr) /* Pointer to x and y coordinates. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; double *coordPtr, *polyPoints; @@ -1232,15 +1242,15 @@ PolygonToPoint(canvas, itemPtr, pointPtr) double radius; double bestDist, dist; int numPoints, count; - int changedMiterToBevel; /* Non-zero means that a mitered corner - * had to be treated as beveled after all - * because the angle was < 11 degrees. */ + int changedMiterToBevel; /* Non-zero means that a mitered corner had to + * be treated as beveled after all because the + * angle was < 11 degrees. */ double width; Tk_State state = itemPtr->state; bestDist = 1.0e36; - if(state == TK_STATE_NULL) { + if (state == TK_STATE_NULL) { state = ((TkCanvas *)canvas)->canvas_state; } width = polyPtr->outline.width; @@ -1261,9 +1271,9 @@ PolygonToPoint(canvas, itemPtr, pointPtr) */ if ((polyPtr->smooth) && (polyPtr->numPoints>2)) { - numPoints = polyPtr->smooth->coordProc(canvas, (double *) NULL, - polyPtr->numPoints, polyPtr->splineSteps, (XPoint *) NULL, - (double *) NULL); + numPoints = polyPtr->smooth->coordProc(canvas, NULL, + polyPtr->numPoints, polyPtr->splineSteps, NULL, + NULL); if (numPoints <= MAX_STATIC_POINTS) { polyPoints = staticSpace; } else { @@ -1271,7 +1281,7 @@ PolygonToPoint(canvas, itemPtr, pointPtr) (2*numPoints*sizeof(double))); } numPoints = polyPtr->smooth->coordProc(canvas, polyPtr->coordPtr, - polyPtr->numPoints, polyPtr->splineSteps, (XPoint *) NULL, + polyPtr->numPoints, polyPtr->splineSteps, NULL, polyPoints); } else { numPoints = polyPtr->numPoints; @@ -1292,22 +1302,23 @@ PolygonToPoint(canvas, itemPtr, pointPtr) } } - if ((polyPtr->outline.gc == None) || (width <= 1)) goto donepoint; + if ((polyPtr->outline.gc == None) || (width <= 1)) { + goto donepoint; + } /* - * The overall idea is to iterate through all of the edges of - * the line, computing a polygon for each edge and testing the - * point against that polygon. In addition, there are additional - * tests to deal with rounded joints and caps. + * The overall idea is to iterate through all of the edges of the line, + * computing a polygon for each edge and testing the point against that + * polygon. In addition, there are additional tests to deal with rounded + * joints and caps. */ changedMiterToBevel = 0; for (count = numPoints, coordPtr = polyPoints; count >= 2; count--, coordPtr += 2) { - /* - * If rounding is done around the first point then compute - * the distance between the point and the point. + * If rounding is done around the first point then compute the + * distance between the point and the point. */ if (polyPtr->joinStyle == JoinRound) { @@ -1322,9 +1333,9 @@ PolygonToPoint(canvas, itemPtr, pointPtr) } /* - * Compute the polygonal shape corresponding to this edge, - * consisting of two points for the first point of the edge - * and two points for the last point of the edge. + * Compute the polygonal shape corresponding to this edge, consisting + * of two points for the first point of the edge and two points for + * the last point of the edge. */ if (count == numPoints) { @@ -1340,10 +1351,10 @@ PolygonToPoint(canvas, itemPtr, pointPtr) poly, poly+2); /* - * If this line uses beveled joints, then check the distance - * to a polygon comprising the last two points of the previous - * polygon and the first two from this polygon; this checks - * the wedges that fill the mitered joint. + * If this line uses beveled joints, then check the distance to a + * polygon comprising the last two points of the previous polygon + * and the first two from this polygon; this checks the wedges + * that fill the mitered joint. */ if ((polyPtr->joinStyle == JoinBevel) || changedMiterToBevel) { @@ -1366,8 +1377,8 @@ PolygonToPoint(canvas, itemPtr, pointPtr) if (TkGetMiterPoints(coordPtr, coordPtr+2, coordPtr+4, (double) width, poly+4, poly+6) == 0) { changedMiterToBevel = 1; - TkGetButtPoints(coordPtr, coordPtr+2, (double) width, - 0, poly+4, poly+6); + TkGetButtPoints(coordPtr, coordPtr+2, (double) width, 0, + poly+4, poly+6); } } else { TkGetButtPoints(coordPtr, coordPtr+2, (double) width, 0, @@ -1384,7 +1395,7 @@ PolygonToPoint(canvas, itemPtr, pointPtr) } } - donepoint: + donepoint: if ((polyPoints != staticSpace) && polyPoints != polyPtr->coordPtr) { ckfree((char *) polyPoints); } @@ -1396,14 +1407,13 @@ PolygonToPoint(canvas, itemPtr, pointPtr) * * PolygonToArea -- * - * This procedure is called to determine whether an item - * lies entirely inside, entirely outside, or overlapping - * a given rectangular area. + * This function is called to determine whether an item lies entirely + * inside, entirely outside, or overlapping a given rectangular area. * * Results: - * -1 is returned if the item is entirely outside the area - * given by rectPtr, 0 if it overlaps, and 1 if it is entirely - * inside the given area. + * -1 is returned if the item is entirely outside the area given by + * rectPtr, 0 if it overlaps, and 1 if it is entirely inside the given + * area. * * Side effects: * None. @@ -1413,12 +1423,12 @@ PolygonToPoint(canvas, itemPtr, pointPtr) /* ARGSUSED */ static int -PolygonToArea(canvas, itemPtr, rectPtr) - Tk_Canvas canvas; /* Canvas containing item. */ - Tk_Item *itemPtr; /* Item to check against polygon. */ - double *rectPtr; /* Pointer to array of four coordinates - * (x1, y1, x2, y2) describing rectangular - * area. */ +PolygonToArea( + Tk_Canvas canvas, /* Canvas containing item. */ + Tk_Item *itemPtr, /* Item to check against polygon. */ + double *rectPtr) /* Pointer to array of four coordinates + * (x1,y1,x2,y2) describing rectangular + * area. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; double *coordPtr; @@ -1426,19 +1436,18 @@ PolygonToArea(canvas, itemPtr, rectPtr) double *polyPoints, poly[10]; double radius; int numPoints, count; - int changedMiterToBevel; /* Non-zero means that a mitered corner - * had to be treated as beveled after all - * because the angle was < 11 degrees. */ - int inside; /* Tentative guess about what to return, - * based on all points seen so far: one - * means everything seen so far was - * inside the area; -1 means everything - * was outside the area. 0 means overlap - * has been found. */ + int changedMiterToBevel; /* Non-zero means that a mitered corner had to + * be treated as beveled after all because the + * angle was < 11 degrees. */ + int inside; /* Tentative guess about what to return, based + * on all points seen so far: one means + * everything seen so far was inside the area; + * -1 means everything was outside the area. 0 + * means overlap has been found. */ double width; Tk_State state = itemPtr->state; - if(state == TK_STATE_NULL) { + if (state == TK_STATE_NULL) { state = ((TkCanvas *)canvas)->canvas_state; } @@ -1460,60 +1469,62 @@ PolygonToArea(canvas, itemPtr, rectPtr) return -1; } else if (polyPtr->numPoints <3) { double oval[4]; + oval[0] = polyPtr->coordPtr[0]-radius; oval[1] = polyPtr->coordPtr[1]-radius; oval[2] = polyPtr->coordPtr[0]+radius; oval[3] = polyPtr->coordPtr[1]+radius; return TkOvalToArea(oval, rectPtr); } + /* * Handle smoothed polygons by generating an expanded set of points * against which to do the check. */ if (polyPtr->smooth) { - numPoints = polyPtr->smooth->coordProc(canvas, (double *) NULL, - polyPtr->numPoints, polyPtr->splineSteps, (XPoint *) NULL, - (double *) NULL); + numPoints = polyPtr->smooth->coordProc(canvas, NULL, + polyPtr->numPoints, polyPtr->splineSteps, NULL, NULL); if (numPoints <= MAX_STATIC_POINTS) { polyPoints = staticSpace; } else { - polyPoints = (double *) ckalloc((unsigned) - (2*numPoints*sizeof(double))); + polyPoints = (double *) + ckalloc((unsigned) (2*numPoints*sizeof(double))); } numPoints = polyPtr->smooth->coordProc(canvas, polyPtr->coordPtr, - polyPtr->numPoints, polyPtr->splineSteps, (XPoint *) NULL, - polyPoints); + polyPtr->numPoints, polyPtr->splineSteps, NULL, polyPoints); } else { numPoints = polyPtr->numPoints; polyPoints = polyPtr->coordPtr; } /* - * Simple test to see if we are in the polygon. Polygons are - * different from othe canvas items in that they register points - * being inside even if it isn't filled. + * Simple test to see if we are in the polygon. Polygons are different + * from othe canvas items in that they register points being inside even + * if it isn't filled. */ + inside = TkPolygonToArea(polyPoints, numPoints, rectPtr); - if (inside==0) goto donearea; + if (inside==0) { + goto donearea; + } - if (polyPtr->outline.gc == None) goto donearea ; + if (polyPtr->outline.gc == None) { + goto donearea; + } /* - * Iterate through all of the edges of the line, computing a polygon - * for each edge and testing the area against that polygon. In - * addition, there are additional tests to deal with rounded joints - * and caps. + * Iterate through all of the edges of the line, computing a polygon for + * each edge and testing the area against that polygon. In addition, there + * are additional tests to deal with rounded joints and caps. */ changedMiterToBevel = 0; for (count = numPoints, coordPtr = polyPoints; count >= 2; count--, coordPtr += 2) { - /* - * If rounding is done around the first point of the edge - * then test a circular region around the point with the - * area. + * If rounding is done around the first point of the edge then test a + * circular region around the point with the area. */ if (polyPtr->joinStyle == JoinRound) { @@ -1528,28 +1539,26 @@ PolygonToArea(canvas, itemPtr, rectPtr) } /* - * Compute the polygonal shape corresponding to this edge, - * consisting of two points for the first point of the edge - * and two points for the last point of the edge. + * Compute the polygonal shape corresponding to this edge, consisting + * of two points for the first point of the edge and two points for + * the last point of the edge. */ if (count == numPoints) { - TkGetButtPoints(coordPtr+2, coordPtr, width, - 0, poly, poly+2); + TkGetButtPoints(coordPtr+2, coordPtr, width, 0, poly, poly+2); } else if ((polyPtr->joinStyle == JoinMiter) && !changedMiterToBevel) { poly[0] = poly[6]; poly[1] = poly[7]; poly[2] = poly[4]; poly[3] = poly[5]; } else { - TkGetButtPoints(coordPtr+2, coordPtr, width, 0, - poly, poly+2); + TkGetButtPoints(coordPtr+2, coordPtr, width, 0, poly, poly+2); /* - * If the last joint was beveled, then also check a - * polygon comprising the last two points of the previous - * polygon and the first two from this polygon; this checks - * the wedges that fill the beveled joint. + * If the last joint was beveled, then also check a polygon + * comprising the last two points of the previous polygon and the + * first two from this polygon; this checks the wedges that fill + * the beveled joint. */ if ((polyPtr->joinStyle == JoinBevel) || changedMiterToBevel) { @@ -1563,18 +1572,15 @@ PolygonToArea(canvas, itemPtr, rectPtr) } } if (count == 2) { - TkGetButtPoints(coordPtr, coordPtr+2, width, - 0, poly+4, poly+6); + TkGetButtPoints(coordPtr, coordPtr+2, width, 0, poly+4, poly+6); } else if (polyPtr->joinStyle == JoinMiter) { if (TkGetMiterPoints(coordPtr, coordPtr+2, coordPtr+4, width, poly+4, poly+6) == 0) { changedMiterToBevel = 1; - TkGetButtPoints(coordPtr, coordPtr+2, width, - 0, poly+4, poly+6); + TkGetButtPoints(coordPtr, coordPtr+2, width,0, poly+4, poly+6); } } else { - TkGetButtPoints(coordPtr, coordPtr+2, width, 0, - poly+4, poly+6); + TkGetButtPoints(coordPtr, coordPtr+2, width, 0, poly+4, poly+6); } poly[8] = poly[0]; poly[9] = poly[1]; @@ -1584,7 +1590,7 @@ PolygonToArea(canvas, itemPtr, rectPtr) } } - donearea: + donearea: if ((polyPoints != staticSpace) && (polyPoints != polyPtr->coordPtr)) { ckfree((char *) polyPoints); } @@ -1596,15 +1602,14 @@ PolygonToArea(canvas, itemPtr, rectPtr) * * ScalePolygon -- * - * This procedure is invoked to rescale a polygon item. + * This function is invoked to rescale a polygon item. * * Results: * None. * * Side effects: - * The polygon referred to by itemPtr is rescaled so that the - * following transformation is applied to all point - * coordinates: + * The polygon referred to by itemPtr is rescaled so that the following + * transformation is applied to all point coordinates: * x' = originX + scaleX*(x-originX) * y' = originY + scaleY*(y-originY) * @@ -1612,12 +1617,13 @@ PolygonToArea(canvas, itemPtr, rectPtr) */ static void -ScalePolygon(canvas, itemPtr, originX, originY, scaleX, scaleY) - Tk_Canvas canvas; /* Canvas containing polygon. */ - Tk_Item *itemPtr; /* Polygon to be scaled. */ - double originX, originY; /* Origin about which to scale rect. */ - double scaleX; /* Amount to scale in X direction. */ - double scaleY; /* Amount to scale in Y direction. */ +ScalePolygon( + Tk_Canvas canvas, /* Canvas containing polygon. */ + Tk_Item *itemPtr, /* Polygon to be scaled. */ + double originX, double originY, + /* Origin about which to scale rect. */ + double scaleX, /* Amount to scale in X direction. */ + double scaleY) /* Amount to scale in Y direction. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; double *coordPtr; @@ -1636,14 +1642,13 @@ ScalePolygon(canvas, itemPtr, originX, originY, scaleX, scaleY) * * GetPolygonIndex -- * - * Parse an index into a polygon item and return either its value - * or an error. + * Parse an index into a polygon item and return either its value or an + * error. * * Results: - * A standard Tcl result. If all went well, then *indexPtr is - * filled in with the index (into itemPtr) corresponding to - * string. Otherwise an error message is left in - * interp->result. + * A standard Tcl result. If all went well, then *indexPtr is filled in + * with the index (into itemPtr) corresponding to string. Otherwise an + * error message is left in interp->result. * * Side effects: * None. @@ -1652,14 +1657,14 @@ ScalePolygon(canvas, itemPtr, originX, originY, scaleX, scaleY) */ static int -GetPolygonIndex(interp, canvas, itemPtr, obj, indexPtr) - Tcl_Interp *interp; /* Used for error reporting. */ - Tk_Canvas canvas; /* Canvas containing item. */ - Tk_Item *itemPtr; /* Item for which the index is being +GetPolygonIndex( + Tcl_Interp *interp, /* Used for error reporting. */ + Tk_Canvas canvas, /* Canvas containing item. */ + Tk_Item *itemPtr, /* Item for which the index is being * specified. */ - Tcl_Obj *obj; /* Specification of a particular coord - * in itemPtr's line. */ - int *indexPtr; /* Where to store converted index. */ + Tcl_Obj *obj, /* Specification of a particular coord in + * itemPtr's line. */ + int *indexPtr) /* Where to store converted index. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; int length; @@ -1669,16 +1674,14 @@ GetPolygonIndex(interp, canvas, itemPtr, obj, indexPtr) if (strncmp(string, "end", (unsigned)length) == 0) { *indexPtr = 2*(polyPtr->numPoints - polyPtr->autoClosed); } else { - badIndex: - /* - * Some of the paths here leave messages in interp->result, - * so we have to clear it out before storing our own message. + * Some of the paths here leave messages in interp->result, so we + * have to clear it out before storing our own message. */ - Tcl_SetResult(interp, (char *) NULL, TCL_STATIC); - Tcl_AppendResult(interp, "bad index \"", string, "\"", - (char *) NULL); + badIndex: + Tcl_SetResult(interp, NULL, TCL_STATIC); + Tcl_AppendResult(interp, "bad index \"", string, "\"", NULL); return TCL_ERROR; } } else if (string[0] == '@') { @@ -1709,6 +1712,7 @@ GetPolygonIndex(interp, canvas, itemPtr, obj, indexPtr) } } else { int count = 2*(polyPtr->numPoints - polyPtr->autoClosed); + if (Tcl_GetIntFromObj(interp, obj, indexPtr) != TCL_OK) { goto badIndex; } @@ -1731,26 +1735,24 @@ GetPolygonIndex(interp, canvas, itemPtr, obj, indexPtr) * * TranslatePolygon -- * - * This procedure is called to move a polygon by a given - * amount. + * This function is called to move a polygon by a given amount. * * Results: * None. * * Side effects: - * The position of the polygon is offset by (xDelta, yDelta), - * and the bounding box is updated in the generic part of the - * item structure. + * The position of the polygon is offset by (xDelta, yDelta), and the + * bounding box is updated in the generic part of the item structure. * *-------------------------------------------------------------- */ static void -TranslatePolygon(canvas, itemPtr, deltaX, deltaY) - Tk_Canvas canvas; /* Canvas containing item. */ - Tk_Item *itemPtr; /* Item that is being moved. */ - double deltaX, deltaY; /* Amount by which item is to be - * moved. */ +TranslatePolygon( + Tk_Canvas canvas, /* Canvas containing item. */ + Tk_Item *itemPtr, /* Item that is being moved. */ + double deltaX, double deltaY) + /* Amount by which item is to be moved. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; double *coordPtr; @@ -1769,15 +1771,13 @@ TranslatePolygon(canvas, itemPtr, deltaX, deltaY) * * PolygonToPostscript -- * - * This procedure is called to generate Postscript for - * polygon items. + * This function is called to generate Postscript for polygon items. * * Results: - * The return value is a standard Tcl result. If an error - * occurs in generating Postscript then an error message is - * left in the interp's result, replacing whatever used - * to be there. If no error occurs, then Postscript for the - * item is appended to the result. + * The return value is a standard Tcl result. If an error occurs in + * generating Postscript then an error message is left in the interp's + * result, replacing whatever used to be there. If no error occurs, then + * Postscript for the item is appended to the result. * * Side effects: * None. @@ -1786,15 +1786,13 @@ TranslatePolygon(canvas, itemPtr, deltaX, deltaY) */ static int -PolygonToPostscript(interp, canvas, itemPtr, prepass) - Tcl_Interp *interp; /* Leave Postscript or error message - * here. */ - Tk_Canvas canvas; /* Information about overall canvas. */ - Tk_Item *itemPtr; /* Item for which Postscript is - * wanted. */ - int prepass; /* 1 means this is a prepass to - * collect font information; 0 means - * final Postscript is being created. */ +PolygonToPostscript( + Tcl_Interp *interp, /* Leave Postscript or error message here. */ + Tk_Canvas canvas, /* Information about overall canvas. */ + Tk_Item *itemPtr, /* Item for which Postscript is wanted. */ + int prepass) /* 1 means this is a prepass to collect font + * information; 0 means final Postscript is + * being created. */ { PolygonItem *polyPtr = (PolygonItem *) itemPtr; char *style; @@ -1860,17 +1858,17 @@ PolygonToPostscript(interp, canvas, itemPtr, prepass) polyPtr->coordPtr[0], Tk_CanvasPsY(canvas, polyPtr->coordPtr[1]), width/2.0, width/2.0); Tcl_AppendResult(interp, "matrix currentmatrix\n",string, - " scale 1 0 moveto 0 0 1 0 360 arc\nsetmatrix\n", (char *) NULL); + " scale 1 0 moveto 0 0 1 0 360 arc\nsetmatrix\n", NULL); if (Tk_CanvasPsColor(interp, canvas, color) != TCL_OK) { return TCL_ERROR; } if (stipple != None) { - Tcl_AppendResult(interp, "clip ", (char *) NULL); + Tcl_AppendResult(interp, "clip ", NULL); if (Tk_CanvasPsStipple(interp, canvas, stipple) != TCL_OK) { return TCL_ERROR; } } else { - Tcl_AppendResult(interp, "fill\n", (char *) NULL); + Tcl_AppendResult(interp, "fill\n", NULL); } return TCL_OK; } @@ -1891,16 +1889,15 @@ PolygonToPostscript(interp, canvas, itemPtr, prepass) return TCL_ERROR; } if (fillStipple != None) { - Tcl_AppendResult(interp, "eoclip ", (char *) NULL); - if (Tk_CanvasPsStipple(interp, canvas, fillStipple) - != TCL_OK) { + Tcl_AppendResult(interp, "eoclip ", NULL); + if (Tk_CanvasPsStipple(interp, canvas, fillStipple) != TCL_OK) { return TCL_ERROR; } if (color != NULL) { - Tcl_AppendResult(interp, "grestore gsave\n", (char *) NULL); + Tcl_AppendResult(interp, "grestore gsave\n", NULL); } } else { - Tcl_AppendResult(interp, "eofill\n", (char *) NULL); + Tcl_AppendResult(interp, "eofill\n", NULL); } } @@ -1909,13 +1906,12 @@ PolygonToPostscript(interp, canvas, itemPtr, prepass) */ if (color != NULL) { - if (!polyPtr->smooth || !polyPtr->smooth->postscriptProc) { Tk_CanvasPsPath(interp, canvas, polyPtr->coordPtr, - polyPtr->numPoints); + polyPtr->numPoints); } else { polyPtr->smooth->postscriptProc(interp, canvas, polyPtr->coordPtr, - polyPtr->numPoints, polyPtr->splineSteps); + polyPtr->numPoints, polyPtr->splineSteps); } if (polyPtr->joinStyle == JoinRound) { @@ -1925,8 +1921,7 @@ PolygonToPostscript(interp, canvas, itemPtr, prepass) } else { style = "0"; } - Tcl_AppendResult(interp, style," setlinejoin 1 setlinecap\n", - (char *) NULL); + Tcl_AppendResult(interp, style," setlinejoin 1 setlinecap\n", NULL); if (Tk_CanvasPsOutline(canvas, itemPtr, &(polyPtr->outline)) != TCL_OK) { return TCL_ERROR; @@ -1934,3 +1929,11 @@ PolygonToPostscript(interp, canvas, itemPtr, prepass) } return TCL_OK; } + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ diff --git a/generic/tkCanvPs.c b/generic/tkCanvPs.c index 866433f..5fcdd15 100644 --- a/generic/tkCanvPs.c +++ b/generic/tkCanvPs.c @@ -1,17 +1,17 @@ -/* +/* * tkCanvPs.c -- * - * This module provides Postscript output support for canvases, - * including the "postscript" widget command plus a few utility - * procedures used for generating Postscript. + * This module provides Postscript output support for canvases, including + * the "postscript" widget command plus a few utility functions used for + * generating Postscript. * * Copyright (c) 1991-1994 The Regents of the University of California. * Copyright (c) 1994-1997 Sun Microsystems, Inc. * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkCanvPs.c,v 1.15 2004/02/23 10:48:11 das Exp $ + * RCS: @(#) $Id: tkCanvPs.c,v 1.16 2005/11/04 15:23:05 dkf Exp $ */ #include "tkInt.h" @@ -23,8 +23,8 @@ */ /* - * The following definition is used in generating postscript for images - * and windows. + * The following definition is used in generating postscript for images and + * windows. */ typedef struct TkColormapData { /* Hold color information for a window */ @@ -38,8 +38,8 @@ typedef struct TkColormapData { /* Hold color information for a window */ /* * One of the following structures is created to keep track of Postscript - * output being generated. It consists mostly of information provided on - * the widget command line. + * output being generated. It consists mostly of information provided on the + * widget command line. */ typedef struct TkPostscriptInfo { @@ -57,93 +57,90 @@ typedef struct TkPostscriptInfo { double scale; /* Scale factor for conversion: each pixel * maps into this many points. */ Tk_Anchor pageAnchor; /* How to anchor bbox on Postscript page. */ - int rotate; /* Non-zero means output should be rotated - * on page (landscape mode). */ + int rotate; /* Non-zero means output should be rotated on + * page (landscape mode). */ char *fontVar; /* If non-NULL, gives name of global variable * containing font mapping information. * Malloc'ed. */ char *colorVar; /* If non-NULL, give name of global variable * containing color mapping information. * Malloc'ed. */ - char *colorMode; /* Mode for handling colors: "monochrome", + char *colorMode; /* Mode for handling colors: "monochrome", * "gray", or "color". Malloc'ed. */ - int colorLevel; /* Numeric value corresponding to colorMode: - * 0 for mono, 1 for gray, 2 for color. */ + int colorLevel; /* Numeric value corresponding to colorMode: 0 + * for mono, 1 for gray, 2 for color. */ char *fileName; /* Name of file in which to write Postscript; * NULL means return Postscript info as * result. Malloc'ed. */ - char *channelName; /* If -channel is specified, the name of - * the channel to use. */ + char *channelName; /* If -channel is specified, the name of the + * channel to use. */ Tcl_Channel chan; /* Open channel corresponding to fileName. */ Tcl_HashTable fontTable; /* Hash table containing names of all font - * families used in output. The hash table + * families used in output. The hash table * values are not used. */ - int prepass; /* Non-zero means that we're currently in - * the pre-pass that collects font information, - * so the Postscript generated isn't - * relevant. */ - int prolog; /* Non-zero means output should contain - the file prolog.ps in the header. */ + int prepass; /* Non-zero means that we're currently in the + * pre-pass that collects font information, so + * the Postscript generated isn't relevant. */ + int prolog; /* Non-zero means output should contain the + * file prolog.ps in the header. */ } TkPostscriptInfo; /* - * The table below provides a template that's used to process arguments - * to the canvas "postscript" command and fill in TkPostscriptInfo - * structures. + * The table below provides a template that's used to process arguments to the + * canvas "postscript" command and fill in TkPostscriptInfo structures. */ static Tk_ConfigSpec configSpecs[] = { - {TK_CONFIG_STRING, "-colormap", (char *) NULL, (char *) NULL, + {TK_CONFIG_STRING, "-colormap", NULL, NULL, "", Tk_Offset(TkPostscriptInfo, colorVar), 0}, - {TK_CONFIG_STRING, "-colormode", (char *) NULL, (char *) NULL, + {TK_CONFIG_STRING, "-colormode", NULL, NULL, "", Tk_Offset(TkPostscriptInfo, colorMode), 0}, - {TK_CONFIG_STRING, "-file", (char *) NULL, (char *) NULL, + {TK_CONFIG_STRING, "-file", NULL, NULL, "", Tk_Offset(TkPostscriptInfo, fileName), 0}, - {TK_CONFIG_STRING, "-channel", (char *) NULL, (char *) NULL, + {TK_CONFIG_STRING, "-channel", NULL, NULL, "", Tk_Offset(TkPostscriptInfo, channelName), 0}, - {TK_CONFIG_STRING, "-fontmap", (char *) NULL, (char *) NULL, + {TK_CONFIG_STRING, "-fontmap", NULL, NULL, "", Tk_Offset(TkPostscriptInfo, fontVar), 0}, - {TK_CONFIG_PIXELS, "-height", (char *) NULL, (char *) NULL, + {TK_CONFIG_PIXELS, "-height", NULL, NULL, "", Tk_Offset(TkPostscriptInfo, height), 0}, - {TK_CONFIG_ANCHOR, "-pageanchor", (char *) NULL, (char *) NULL, + {TK_CONFIG_ANCHOR, "-pageanchor", NULL, NULL, "", Tk_Offset(TkPostscriptInfo, pageAnchor), 0}, - {TK_CONFIG_STRING, "-pageheight", (char *) NULL, (char *) NULL, + {TK_CONFIG_STRING, "-pageheight", NULL, NULL, "", Tk_Offset(TkPostscriptInfo, pageHeightString), 0}, - {TK_CONFIG_STRING, "-pagewidth", (char *) NULL, (char *) NULL, + {TK_CONFIG_STRING, "-pagewidth", NULL, NULL, "", Tk_Offset(TkPostscriptInfo, pageWidthString), 0}, - {TK_CONFIG_STRING, "-pagex", (char *) NULL, (char *) NULL, + {TK_CONFIG_STRING, "-pagex", NULL, NULL, "", Tk_Offset(TkPostscriptInfo, pageXString), 0}, - {TK_CONFIG_STRING, "-pagey", (char *) NULL, (char *) NULL, + {TK_CONFIG_STRING, "-pagey", NULL, NULL, "", Tk_Offset(TkPostscriptInfo, pageYString), 0}, - {TK_CONFIG_BOOLEAN, "-prolog", (char *) NULL, (char *) NULL, + {TK_CONFIG_BOOLEAN, "-prolog", NULL, NULL, "", Tk_Offset(TkPostscriptInfo, prolog), 0}, - {TK_CONFIG_BOOLEAN, "-rotate", (char *) NULL, (char *) NULL, + {TK_CONFIG_BOOLEAN, "-rotate", NULL, NULL, "", Tk_Offset(TkPostscriptInfo, rotate), 0}, - {TK_CONFIG_PIXELS, "-width", (char *) NULL, (char *) NULL, + {TK_CONFIG_PIXELS, "-width", NULL, NULL, "", Tk_Offset(TkPostscriptInfo, width), 0}, - {TK_CONFIG_PIXELS, "-x", (char *) NULL, (char *) NULL, + {TK_CONFIG_PIXELS, "-x", NULL, NULL, "", Tk_Offset(TkPostscriptInfo, x), 0}, - {TK_CONFIG_PIXELS, "-y", (char *) NULL, (char *) NULL, + {TK_CONFIG_PIXELS, "-y", NULL, NULL, "", Tk_Offset(TkPostscriptInfo, y), 0}, - {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL, - (char *) NULL, 0, 0} + {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0} }; /* - * Forward declarations for procedures defined later in this file: + * Forward declarations for functions defined later in this file: */ -static int GetPostscriptPoints _ANSI_ARGS_((Tcl_Interp *interp, - char *string, double *doublePtr)); +static int GetPostscriptPoints(Tcl_Interp *interp, + char *string, double *doublePtr); /* *-------------------------------------------------------------- * * TkCanvPostscriptCmd -- * - * This procedure is invoked to process the "postscript" options - * of the widget command for canvas widgets. See the user - * documentation for details on what it does. + * This function is invoked to process the "postscript" options of the + * widget command for canvas widgets. See the user documentation for + * details on what it does. * * Results: * A standard Tcl result. @@ -156,14 +153,13 @@ static int GetPostscriptPoints _ANSI_ARGS_((Tcl_Interp *interp, /* ARGSUSED */ int -TkCanvPostscriptCmd(canvasPtr, interp, argc, argv) - TkCanvas *canvasPtr; /* Information about canvas widget. */ - Tcl_Interp *interp; /* Current interpreter. */ - int argc; /* Number of arguments. */ - CONST char **argv; /* Argument strings. Caller has - * already parsed this command enough - * to know that argv[1] is - * "postscript". */ +TkCanvPostscriptCmd( + TkCanvas *canvasPtr, /* Information about canvas widget. */ + Tcl_Interp *interp, /* Current interpreter. */ + int argc, /* Number of arguments. */ + CONST char **argv) /* Argument strings. Caller has already parsed + * this command enough to know that argv[1] is + * "postscript". */ { TkPostscriptInfo psInfo; Tk_PostscriptInfo oldInfoPtr; @@ -175,24 +171,21 @@ TkCanvPostscriptCmd(canvasPtr, interp, argc, argv) time_t now; size_t length; Tk_Window tkwin = canvasPtr->tkwin; - int deltaX = 0, deltaY = 0; /* Offset of lower-left corner of - * area to be marked up, measured - * in canvas units from the positioning - * point on the page (reflects - * anchor position). Initial values - * needed only to stop compiler - * warnings. */ Tcl_HashSearch search; Tcl_HashEntry *hPtr; Tcl_DString buffer; - char psenccmd[]="::tk::ensure_psenc_is_loaded"; + char psenccmd[] = "::tk::ensure_psenc_is_loaded"; + int deltaX = 0, deltaY = 0; /* Offset of lower-left corner of area to be + * marked up, measured in canvas units from + * the positioning point on the page (reflects + * anchor position). Initial values needed + * only to stop compiler warnings. */ /* - *---------------------------------------------------------------- - * Initialize the data structure describing Postscript generation, - * then process all the arguments to fill the data structure in. - *---------------------------------------------------------------- + * Initialize the data structure describing Postscript generation, then + * process all the arguments to fill the data structure in. */ + result = Tcl_EvalEx(interp,psenccmd,-1,TCL_EVAL_GLOBAL); if (result != TCL_OK) { return result; @@ -222,9 +215,8 @@ TkCanvPostscriptCmd(canvasPtr, interp, argc, argv) psInfo.prepass = 0; psInfo.prolog = 1; Tcl_InitHashTable(&psInfo.fontTable, TCL_STRING_KEYS); - result = Tk_ConfigureWidget(interp, tkwin, - configSpecs, argc-2, argv+2, (char *) &psInfo, - TK_CONFIG_ARGV_ONLY); + result = Tk_ConfigureWidget(interp, tkwin, configSpecs, argc-2, argv+2, + (char *) &psInfo, TK_CONFIG_ARGV_ONLY); if (result != TCL_OK) { goto cleanup; } @@ -267,38 +259,38 @@ TkCanvPostscriptCmd(canvasPtr, interp, argc, argv) psInfo.scale /= WidthOfScreen(Tk_Screen(tkwin)); } switch (psInfo.pageAnchor) { - case TK_ANCHOR_NW: - case TK_ANCHOR_W: - case TK_ANCHOR_SW: - deltaX = 0; - break; - case TK_ANCHOR_N: - case TK_ANCHOR_CENTER: - case TK_ANCHOR_S: - deltaX = -psInfo.width/2; - break; - case TK_ANCHOR_NE: - case TK_ANCHOR_E: - case TK_ANCHOR_SE: - deltaX = -psInfo.width; - break; + case TK_ANCHOR_NW: + case TK_ANCHOR_W: + case TK_ANCHOR_SW: + deltaX = 0; + break; + case TK_ANCHOR_N: + case TK_ANCHOR_CENTER: + case TK_ANCHOR_S: + deltaX = -psInfo.width/2; + break; + case TK_ANCHOR_NE: + case TK_ANCHOR_E: + case TK_ANCHOR_SE: + deltaX = -psInfo.width; + break; } switch (psInfo.pageAnchor) { - case TK_ANCHOR_NW: - case TK_ANCHOR_N: - case TK_ANCHOR_NE: - deltaY = - psInfo.height; - break; - case TK_ANCHOR_W: - case TK_ANCHOR_CENTER: - case TK_ANCHOR_E: - deltaY = -psInfo.height/2; - break; - case TK_ANCHOR_SW: - case TK_ANCHOR_S: - case TK_ANCHOR_SE: - deltaY = 0; - break; + case TK_ANCHOR_NW: + case TK_ANCHOR_N: + case TK_ANCHOR_NE: + deltaY = - psInfo.height; + break; + case TK_ANCHOR_W: + case TK_ANCHOR_CENTER: + case TK_ANCHOR_E: + deltaY = -psInfo.height/2; + break; + case TK_ANCHOR_SW: + case TK_ANCHOR_S: + case TK_ANCHOR_SE: + deltaY = 0; + break; } if (psInfo.colorMode == NULL) { @@ -312,22 +304,20 @@ TkCanvPostscriptCmd(canvasPtr, interp, argc, argv) } else if (strncmp(psInfo.colorMode, "color", length) == 0) { psInfo.colorLevel = 2; } else { - Tcl_AppendResult(interp, "bad color mode \"", - psInfo.colorMode, "\": must be monochrome, ", - "gray, or color", (char *) NULL); + Tcl_AppendResult(interp, "bad color mode \"", psInfo.colorMode, + "\": must be monochrome, gray, or color", NULL); goto cleanup; } } if (psInfo.fileName != NULL) { - /* * Check that -file and -channel are not both specified. */ if (psInfo.channelName != NULL) { Tcl_AppendResult(interp, "can't specify both -file", - " and -channel", (char *) NULL); + " and -channel", NULL); result = TCL_ERROR; goto cleanup; } @@ -339,11 +329,11 @@ TkCanvPostscriptCmd(canvasPtr, interp, argc, argv) if (Tcl_IsSafe(interp)) { Tcl_AppendResult(interp, "can't specify -file in a", - " safe interpreter", (char *) NULL); + " safe interpreter", NULL); result = TCL_ERROR; goto cleanup; } - + p = Tcl_TranslateFileName(interp, psInfo.fileName, &buffer); if (p == NULL) { goto cleanup; @@ -357,35 +347,31 @@ TkCanvPostscriptCmd(canvasPtr, interp, argc, argv) if (psInfo.channelName != NULL) { int mode; - + /* - * Check that the channel is found in this interpreter and that it - * is open for writing. + * Check that the channel is found in this interpreter and that it is + * open for writing. */ - psInfo.chan = Tcl_GetChannel(interp, psInfo.channelName, - &mode); + psInfo.chan = Tcl_GetChannel(interp, psInfo.channelName, &mode); if (psInfo.chan == (Tcl_Channel) NULL) { result = TCL_ERROR; goto cleanup; } if ((mode & TCL_WRITABLE) == 0) { - Tcl_AppendResult(interp, "channel \"", - psInfo.channelName, "\" wasn't opened for writing", - (char *) NULL); + Tcl_AppendResult(interp, "channel \"", psInfo.channelName, + "\" wasn't opened for writing", NULL); result = TCL_ERROR; goto cleanup; } } - + /* - *-------------------------------------------------------- - * Make a pre-pass over all of the items, generating Postscript - * and then throwing it away. The purpose of this pass is just - * to collect information about all the fonts in use, so that - * we can output font information in the proper form required - * by the Document Structuring Conventions. - *-------------------------------------------------------- + * Make a pre-pass over all of the items, generating Postscript and then + * throwing it away. The purpose of this pass is just to collect + * information about all the fonts in use, so that we can output font + * information in the proper form required by the Document Structuring + * Conventions. */ psInfo.prepass = 1; @@ -403,11 +389,10 @@ TkCanvPostscriptCmd(canvasPtr, interp, argc, argv) Tcl_ResetResult(interp); if (result != TCL_OK) { /* - * An error just occurred. Just skip out of this loop. - * There's no need to report the error now; it can be - * reported later (errors can happen later that don't - * happen now, so we still have to check for errors later - * anyway). + * An error just occurred. Just skip out of this loop. There's no + * need to report the error now; it can be reported later (errors + * can happen later that don't happen now, so we still have to + * check for errors later anyway). */ break; } @@ -415,117 +400,109 @@ TkCanvPostscriptCmd(canvasPtr, interp, argc, argv) psInfo.prepass = 0; /* - *-------------------------------------------------------- * Generate the header and prolog for the Postscript. - *-------------------------------------------------------- */ if (psInfo.prolog) { - Tcl_AppendResult(interp, "%!PS-Adobe-3.0 EPSF-3.0\n", - "%%Creator: Tk Canvas Widget\n", (char *) NULL); + Tcl_AppendResult(interp, "%!PS-Adobe-3.0 EPSF-3.0\n", + "%%Creator: Tk Canvas Widget\n", NULL); #ifdef HAVE_PW_GECOS - if (!Tcl_IsSafe(interp)) { - struct passwd *pwPtr = getpwuid(getuid()); /* INTL: Native. */ - Tcl_AppendResult(interp, "%%For: ", - (pwPtr != NULL) ? pwPtr->pw_gecos : "Unknown", "\n", - (char *) NULL); - endpwent(); - } + if (!Tcl_IsSafe(interp)) { + struct passwd *pwPtr = getpwuid(getuid()); /* INTL: Native. */ + + Tcl_AppendResult(interp, "%%For: ", + (pwPtr != NULL) ? pwPtr->pw_gecos : "Unknown", "\n", NULL); + endpwent(); + } #endif /* HAVE_PW_GECOS */ - Tcl_AppendResult(interp, "%%Title: Window ", - Tk_PathName(tkwin), "\n", (char *) NULL); - time(&now); - Tcl_AppendResult(interp, "%%CreationDate: ", - ctime(&now), (char *) NULL); /* INTL: Native. */ - if (!psInfo.rotate) { - sprintf(string, "%d %d %d %d", - (int) (psInfo.pageX + psInfo.scale*deltaX), - (int) (psInfo.pageY + psInfo.scale*deltaY), - (int) (psInfo.pageX + psInfo.scale*(deltaX + psInfo.width) - + 1.0), - (int) (psInfo.pageY + psInfo.scale*(deltaY + psInfo.height) - + 1.0)); - } else { - sprintf(string, "%d %d %d %d", - (int) (psInfo.pageX - psInfo.scale*(deltaY + psInfo.height)), - (int) (psInfo.pageY + psInfo.scale*deltaX), - (int) (psInfo.pageX - psInfo.scale*deltaY + 1.0), - (int) (psInfo.pageY + psInfo.scale*(deltaX + psInfo.width) - + 1.0)); - } - Tcl_AppendResult(interp, "%%BoundingBox: ", string, - "\n", (char *) NULL); - Tcl_AppendResult(interp, "%%Pages: 1\n", - "%%DocumentData: Clean7Bit\n", (char *) NULL); - Tcl_AppendResult(interp, "%%Orientation: ", - psInfo.rotate ? "Landscape\n" : "Portrait\n", (char *) NULL); - p = "%%DocumentNeededResources: font "; - for (hPtr = Tcl_FirstHashEntry(&psInfo.fontTable, &search); - hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) { - Tcl_AppendResult(interp, p, - Tcl_GetHashKey(&psInfo.fontTable, hPtr), - "\n", (char *) NULL); - p = "%%+ font "; - } - Tcl_AppendResult(interp, "%%EndComments\n\n", (char *) NULL); + Tcl_AppendResult(interp, "%%Title: Window ", Tk_PathName(tkwin), "\n", + NULL); + time(&now); + Tcl_AppendResult(interp, "%%CreationDate: ", + ctime(&now), NULL); /* INTL: Native. */ + if (!psInfo.rotate) { + sprintf(string, "%d %d %d %d", + (int) (psInfo.pageX + psInfo.scale*deltaX), + (int) (psInfo.pageY + psInfo.scale*deltaY), + (int) (psInfo.pageX + psInfo.scale*(deltaX + psInfo.width) + + 1.0), + (int) (psInfo.pageY + psInfo.scale*(deltaY + psInfo.height) + + 1.0)); + } else { + sprintf(string, "%d %d %d %d", + (int) (psInfo.pageX - psInfo.scale*(deltaY+psInfo.height)), + (int) (psInfo.pageY + psInfo.scale*deltaX), + (int) (psInfo.pageX - psInfo.scale*deltaY + 1.0), + (int) (psInfo.pageY + psInfo.scale*(deltaX + psInfo.width) + + 1.0)); + } + Tcl_AppendResult(interp, "%%BoundingBox: ", string, "\n", NULL); + Tcl_AppendResult(interp, "%%Pages: 1\n", + "%%DocumentData: Clean7Bit\n", NULL); + Tcl_AppendResult(interp, "%%Orientation: ", + psInfo.rotate ? "Landscape\n" : "Portrait\n", NULL); + p = "%%DocumentNeededResources: font "; + for (hPtr = Tcl_FirstHashEntry(&psInfo.fontTable, &search); + hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) { + Tcl_AppendResult(interp, p, + Tcl_GetHashKey(&psInfo.fontTable, hPtr), "\n", NULL); + p = "%%+ font "; + } + Tcl_AppendResult(interp, "%%EndComments\n\n", NULL); - /* - * Insert the prolog - */ - Tcl_AppendResult(interp, Tcl_GetVar(interp,"::tk::ps_preamable", - TCL_GLOBAL_ONLY), (char *) NULL); + /* + * Insert the prolog + */ - if (psInfo.chan != NULL) { - Tcl_Write(psInfo.chan, Tcl_GetStringResult(interp), -1); - Tcl_ResetResult(canvasPtr->interp); - } + Tcl_AppendResult(interp, Tcl_GetVar(interp,"::tk::ps_preamable", + TCL_GLOBAL_ONLY), NULL); - /* - *----------------------------------------------------------- - * Document setup: set the color level and include fonts. - *----------------------------------------------------------- - */ + if (psInfo.chan != NULL) { + Tcl_Write(psInfo.chan, Tcl_GetStringResult(interp), -1); + Tcl_ResetResult(canvasPtr->interp); + } - sprintf(string, "/CL %d def\n", psInfo.colorLevel); - Tcl_AppendResult(interp, "%%BeginSetup\n", string, - (char *) NULL); - for (hPtr = Tcl_FirstHashEntry(&psInfo.fontTable, &search); - hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) { - Tcl_AppendResult(interp, "%%IncludeResource: font ", - Tcl_GetHashKey(&psInfo.fontTable, hPtr), "\n", (char *) NULL); - } - Tcl_AppendResult(interp, "%%EndSetup\n\n", (char *) NULL); + /* + * Document setup: set the color level and include fonts. + */ - /* - *----------------------------------------------------------- - * Page setup: move to page positioning point, rotate if - * needed, set scale factor, offset for proper anchor position, - * and set clip region. - *----------------------------------------------------------- - */ + sprintf(string, "/CL %d def\n", psInfo.colorLevel); + Tcl_AppendResult(interp, "%%BeginSetup\n", string, NULL); + for (hPtr = Tcl_FirstHashEntry(&psInfo.fontTable, &search); + hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) { + Tcl_AppendResult(interp, "%%IncludeResource: font ", + Tcl_GetHashKey(&psInfo.fontTable, hPtr), "\n", NULL); + } + Tcl_AppendResult(interp, "%%EndSetup\n\n", NULL); - Tcl_AppendResult(interp, "%%Page: 1 1\n", "save\n", - (char *) NULL); - sprintf(string, "%.1f %.1f translate\n", psInfo.pageX, psInfo.pageY); - Tcl_AppendResult(interp, string, (char *) NULL); - if (psInfo.rotate) { - Tcl_AppendResult(interp, "90 rotate\n", (char *) NULL); - } - sprintf(string, "%.4g %.4g scale\n", psInfo.scale, psInfo.scale); - Tcl_AppendResult(interp, string, (char *) NULL); - sprintf(string, "%d %d translate\n", deltaX - psInfo.x, deltaY); - Tcl_AppendResult(interp, string, (char *) NULL); - sprintf(string, "%d %.15g moveto %d %.15g lineto %d %.15g lineto %d %.15g", - psInfo.x, - Tk_PostscriptY((double) psInfo.y, (Tk_PostscriptInfo) &psInfo), - psInfo.x2, - Tk_PostscriptY((double) psInfo.y, (Tk_PostscriptInfo) &psInfo), - psInfo.x2, - Tk_PostscriptY((double) psInfo.y2, (Tk_PostscriptInfo) &psInfo), - psInfo.x, - Tk_PostscriptY((double) psInfo.y2, (Tk_PostscriptInfo) &psInfo)); - Tcl_AppendResult(interp, string, - " lineto closepath clip newpath\n", (char *) NULL); + /* + * Page setup: move to page positioning point, rotate if needed, set + * scale factor, offset for proper anchor position, and set clip + * region. + */ + + Tcl_AppendResult(interp, "%%Page: 1 1\n", "save\n", NULL); + sprintf(string, "%.1f %.1f translate\n", psInfo.pageX, psInfo.pageY); + Tcl_AppendResult(interp, string, NULL); + if (psInfo.rotate) { + Tcl_AppendResult(interp, "90 rotate\n", NULL); + } + sprintf(string, "%.4g %.4g scale\n", psInfo.scale, psInfo.scale); + Tcl_AppendResult(interp, string, NULL); + sprintf(string, "%d %d translate\n", deltaX - psInfo.x, deltaY); + Tcl_AppendResult(interp, string, NULL); + sprintf(string, + "%d %.15g moveto %d %.15g lineto %d %.15g lineto %d %.15g", + psInfo.x, + Tk_PostscriptY((double)psInfo.y, (Tk_PostscriptInfo)&psInfo), + psInfo.x2, + Tk_PostscriptY((double)psInfo.y, (Tk_PostscriptInfo)&psInfo), + psInfo.x2, + Tk_PostscriptY((double)psInfo.y2, (Tk_PostscriptInfo)&psInfo), + psInfo.x, + Tk_PostscriptY((double)psInfo.y2, (Tk_PostscriptInfo)&psInfo)); + Tcl_AppendResult(interp, string, + " lineto closepath clip newpath\n", NULL); } if (psInfo.chan != NULL) { Tcl_Write(psInfo.chan, Tcl_GetStringResult(interp), -1); @@ -533,10 +510,8 @@ TkCanvPostscriptCmd(canvasPtr, interp, argc, argv) } /* - *--------------------------------------------------------------------- * Iterate through all the items, having each relevant one draw itself. * Quit if any of the items returns an error. - *--------------------------------------------------------------------- */ result = TCL_OK; @@ -552,7 +527,7 @@ TkCanvPostscriptCmd(canvasPtr, interp, argc, argv) if (itemPtr->state == TK_STATE_HIDDEN) { continue; } - Tcl_AppendResult(interp, "gsave\n", (char *) NULL); + Tcl_AppendResult(interp, "gsave\n", NULL); result = (*itemPtr->typePtr->postscriptProc)(interp, (Tk_Canvas) canvasPtr, itemPtr, 0); if (result != TCL_OK) { @@ -563,7 +538,7 @@ TkCanvPostscriptCmd(canvasPtr, interp, argc, argv) Tcl_AddErrorInfo(interp, msg); goto cleanup; } - Tcl_AppendResult(interp, "grestore\n", (char *) NULL); + Tcl_AppendResult(interp, "grestore\n", NULL); if (psInfo.chan != NULL) { Tcl_Write(psInfo.chan, Tcl_GetStringResult(interp), -1); Tcl_ResetResult(interp); @@ -571,15 +546,13 @@ TkCanvPostscriptCmd(canvasPtr, interp, argc, argv) } /* - *--------------------------------------------------------------------- - * Output page-end information, such as commands to print the page - * and document trailer stuff. - *--------------------------------------------------------------------- + * Output page-end information, such as commands to print the page and + * document trailer stuff. */ if (psInfo.prolog) { - Tcl_AppendResult(interp, "restore showpage\n\n", - "%%Trailer\nend\n%%EOF\n", (char *) NULL); + Tcl_AppendResult(interp, "restore showpage\n\n", + "%%Trailer\nend\n%%EOF\n", NULL); } if (psInfo.chan != NULL) { Tcl_Write(psInfo.chan, Tcl_GetStringResult(interp), -1); @@ -590,7 +563,7 @@ TkCanvPostscriptCmd(canvasPtr, interp, argc, argv) * Clean up psInfo to release malloc'ed stuff. */ - cleanup: + cleanup: if (psInfo.pageXString != NULL) { ckfree(psInfo.pageXString); } @@ -631,16 +604,15 @@ TkCanvPostscriptCmd(canvasPtr, interp, argc, argv) * * Tk_PostscriptColor -- * - * This procedure is called by individual canvas items when - * they want to set a color value for output. Given information - * about an X color, this procedure will generate Postscript - * commands to set up an appropriate color in Postscript. + * This function is called by individual canvas items when they want to + * set a color value for output. Given information about an X color, this + * function will generate Postscript commands to set up an appropriate + * color in Postscript. * * Results: - * Returns a standard Tcl return value. If an error occurs - * then an error message will be left in the interp's result. - * If no error occurs, then additional Postscript will be - * appended to the interp's result. + * Returns a standard Tcl return value. If an error occurs then an error + * message will be left in the interp's result. If no error occurs, then + * additional Postscript will be appended to the interp's result. * * Side effects: * None. @@ -649,10 +621,10 @@ TkCanvPostscriptCmd(canvasPtr, interp, argc, argv) */ int -Tk_PostscriptColor(interp, psInfo, colorPtr) - Tcl_Interp *interp; - Tk_PostscriptInfo psInfo; /* Postscript info. */ - XColor *colorPtr; /* Information about color. */ +Tk_PostscriptColor( + Tcl_Interp *interp, + Tk_PostscriptInfo psInfo, /* Postscript info. */ + XColor *colorPtr) /* Information about color. */ { TkPostscriptInfo *psInfoPtr = (TkPostscriptInfo *) psInfo; int tmp; @@ -664,9 +636,8 @@ Tk_PostscriptColor(interp, psInfo, colorPtr) } /* - * If there is a color map defined, then look up the color's name - * in the map and use the Postscript commands found there, if there - * are any. + * If there is a color map defined, then look up the color's name in the + * map and use the Postscript commands found there, if there are any. */ if (psInfoPtr->colorVar != NULL) { @@ -675,22 +646,21 @@ Tk_PostscriptColor(interp, psInfo, colorPtr) cmdString = Tcl_GetVar2(interp, psInfoPtr->colorVar, Tk_NameOfColor(colorPtr), 0); if (cmdString != NULL) { - Tcl_AppendResult(interp, cmdString, "\n", (char *) NULL); + Tcl_AppendResult(interp, cmdString, "\n", NULL); return TCL_OK; } } /* - * No color map entry for this color. Grab the color's intensities - * and output Postscript commands for them. Special note: X uses - * a range of 0-65535 for intensities, but most displays only use - * a range of 0-255, which maps to (0, 256, 512, ... 65280) in the - * X scale. This means that there's no way to get perfect white, - * since the highest intensity is only 65280 out of 65535. To - * work around this problem, rescale the X intensity to a 0-255 - * scale and use that as the basis for the Postscript colors. This - * scheme still won't work if the display only uses 4 bits per color, - * but most diplays use at least 8 bits. + * No color map entry for this color. Grab the color's intensities and + * output Postscript commands for them. Special note: X uses a range of + * 0-65535 for intensities, but most displays only use a range of 0-255, + * which maps to (0, 256, 512, ... 65280) in the X scale. This means that + * there's no way to get perfect white, since the highest intensity is + * only 65280 out of 65535. To work around this problem, rescale the X + * intensity to a 0-255 scale and use that as the basis for the Postscript + * colors. This scheme still won't work if the display only uses 4 bits + * per color, but most diplays use at least 8 bits. */ tmp = colorPtr->red; @@ -701,7 +671,7 @@ Tk_PostscriptColor(interp, psInfo, colorPtr) blue = ((double) (tmp >> 8))/255.0; sprintf(string, "%.3f %.3f %.3f setrgbcolor AdjustColor\n", red, green, blue); - Tcl_AppendResult(interp, string, (char *) NULL); + Tcl_AppendResult(interp, string, NULL); return TCL_OK; } @@ -710,30 +680,29 @@ Tk_PostscriptColor(interp, psInfo, colorPtr) * * Tk_PostscriptFont -- * - * This procedure is called by individual canvas items when - * they want to output text. Given information about an X - * font, this procedure will generate Postscript commands - * to set up an appropriate font in Postscript. + * This function is called by individual canvas items when they want to + * output text. Given information about an X font, this function will + * generate Postscript commands to set up an appropriate font in + * Postscript. * * Results: - * Returns a standard Tcl return value. If an error occurs - * then an error message will be left in the interp's result. - * If no error occurs, then additional Postscript will be - * appended to the interp's result. + * Returns a standard Tcl return value. If an error occurs then an error + * message will be left in the interp's result. If no error occurs, then + * additional Postscript will be appended to the interp's result. * * Side effects: - * The Postscript font name is entered into psInfoPtr->fontTable - * if it wasn't already there. + * The Postscript font name is entered into psInfoPtr->fontTable if it + * wasn't already there. * *-------------------------------------------------------------- */ int -Tk_PostscriptFont(interp, psInfo, tkfont) - Tcl_Interp *interp; - Tk_PostscriptInfo psInfo; /* Postscript Info. */ - Tk_Font tkfont; /* Information about font in which text - * is to be printed. */ +Tk_PostscriptFont( + Tcl_Interp *interp, + Tk_PostscriptInfo psInfo, /* Postscript Info. */ + Tk_Font tkfont) /* Information about font in which text is to + * be printed. */ { TkPostscriptInfo *psInfoPtr = (TkPostscriptInfo *) psInfo; char pointString[TCL_INTEGER_SPACE]; @@ -741,9 +710,9 @@ Tk_PostscriptFont(interp, psInfo, tkfont) int i, points; /* - * First, look up the font's name in the font map, if there is one. - * If there is an entry for this font, it consists of a list - * containing font name and size. Use this information. + * First, look up the font's name in the font map, if there is one. If + * there is an entry for this font, it consists of a list containing font + * name and size. Use this information. */ if (psInfoPtr->fontVar != NULL) { @@ -755,6 +724,7 @@ Tk_PostscriptFont(interp, psInfo, tkfont) if (list != NULL) { CONST char *fontname; + if (Tcl_ListObjGetElements(interp, list, &objc, &objv) != TCL_OK || objc != 2 || Tcl_GetString(objv[0])[0]=='\0' @@ -762,7 +732,7 @@ Tk_PostscriptFont(interp, psInfo, tkfont) || size <= 0) { Tcl_ResetResult(interp); Tcl_AppendResult(interp, "bad font map entry for \"", name, - "\": \"", Tcl_GetString(list), "\"", (char *) NULL); + "\": \"", Tcl_GetString(list), "\"", NULL); return TCL_ERROR; } @@ -772,23 +742,27 @@ Tk_PostscriptFont(interp, psInfo, tkfont) Tcl_AppendResult(interp, "/", fontname, " findfont ", pointString, " scalefont ", NULL); if (strncasecmp(fontname, "Symbol", 7) != 0) { - Tcl_AppendResult(interp, "ISOEncode ", (char *) NULL); + Tcl_AppendResult(interp, "ISOEncode ", NULL); } - Tcl_AppendResult(interp, "setfont\n", (char *) NULL); + Tcl_AppendResult(interp, "setfont\n", NULL); Tcl_CreateHashEntry(&psInfoPtr->fontTable, fontname, &i); return TCL_OK; } - } + } + + /* + * Nothing in the font map, so fall back to the old guessing technique. + */ Tcl_DStringInit(&ds); points = Tk_PostscriptFontName(tkfont, &ds); sprintf(pointString, "%d", points); Tcl_AppendResult(interp, "/", Tcl_DStringValue(&ds), " findfont ", - pointString, " scalefont ", (char *) NULL); + pointString, " scalefont ", NULL); if (strncasecmp(Tcl_DStringValue(&ds), "Symbol", 7) != 0) { - Tcl_AppendResult(interp, "ISOEncode ", (char *) NULL); + Tcl_AppendResult(interp, "ISOEncode ", NULL); } - Tcl_AppendResult(interp, "setfont\n", (char *) NULL); + Tcl_AppendResult(interp, "setfont\n", NULL); Tcl_CreateHashEntry(&psInfoPtr->fontTable, Tcl_DStringValue(&ds), &i); Tcl_DStringFree(&ds); @@ -800,16 +774,14 @@ Tk_PostscriptFont(interp, psInfo, tkfont) * * Tk_PostscriptBitmap -- * - * This procedure is called to output the contents of a - * sub-region of a bitmap in proper image data format for - * Postscript (i.e. data between angle brackets, one bit - * per pixel). + * This function is called to output the contents of a sub-region of a + * bitmap in proper image data format for Postscript (i.e. data between + * angle brackets, one bit per pixel). * * Results: - * Returns a standard Tcl return value. If an error occurs - * then an error message will be left in the interp's result. - * If no error occurs, then additional Postscript will be - * appended to the interp's result. + * Returns a standard Tcl return value. If an error occurs then an error + * message will be left in the interp's result. If no error occurs, then + * additional Postscript will be appended to the interp's result. * * Side effects: * None. @@ -818,16 +790,14 @@ Tk_PostscriptFont(interp, psInfo, tkfont) */ int -Tk_PostscriptBitmap(interp, tkwin, psInfo, bitmap, startX, startY, width, - height) - Tcl_Interp *interp; - Tk_Window tkwin; - Tk_PostscriptInfo psInfo; /* Postscript info. */ - Pixmap bitmap; /* Bitmap for which to generate - * Postscript. */ - int startX, startY; /* Coordinates of upper-left corner - * of rectangular region to output. */ - int width, height; /* Height of rectangular region. */ +Tk_PostscriptBitmap( + Tcl_Interp *interp, + Tk_Window tkwin, + Tk_PostscriptInfo psInfo, /* Postscript info. */ + Pixmap bitmap, /* Bitmap for which to generate Postscript. */ + int startX, int startY, /* Coordinates of upper-left corner of + * rectangular region to output. */ + int width, int height) /* Height of rectangular region. */ { TkPostscriptInfo *psInfoPtr = (TkPostscriptInfo *) psInfo; XImage *imagePtr; @@ -844,10 +814,10 @@ Tk_PostscriptBitmap(interp, tkwin, psInfo, bitmap, startX, startY, width, /* * The following call should probably be a call to Tk_SizeOfBitmap - * instead, but it seems that we are occasionally invoked by custom - * item types that create their own bitmaps without registering them - * with Tk. XGetGeometry is a bit slower than Tk_SizeOfBitmap, but - * it shouldn't matter here. + * instead, but it seems that we are occasionally invoked by custom item + * types that create their own bitmaps without registering them with Tk. + * XGetGeometry is a bit slower than Tk_SizeOfBitmap, but it shouldn't + * matter here. */ XGetGeometry(Tk_Display(tkwin), bitmap, &dummyRoot, @@ -855,7 +825,7 @@ Tk_PostscriptBitmap(interp, tkwin, psInfo, bitmap, startX, startY, width, (unsigned int *) &totalHeight, &dummyBorderwidth, &dummyDepth); imagePtr = XGetImage(Tk_Display(tkwin), bitmap, 0, 0, totalWidth, totalHeight, 1, XYPixmap); - Tcl_AppendResult(interp, "<", (char *) NULL); + Tcl_AppendResult(interp, "<", NULL); mask = 0x80; value = 0; charsInLine = 0; @@ -869,25 +839,25 @@ Tk_PostscriptBitmap(interp, tkwin, psInfo, bitmap, startX, startY, width, mask >>= 1; if (mask == 0) { sprintf(string, "%02x", value); - Tcl_AppendResult(interp, string, (char *) NULL); + Tcl_AppendResult(interp, string, NULL); mask = 0x80; value = 0; charsInLine += 2; if (charsInLine >= 60) { - Tcl_AppendResult(interp, "\n", (char *) NULL); + Tcl_AppendResult(interp, "\n", NULL); charsInLine = 0; } } } if (mask != 0x80) { sprintf(string, "%02x", value); - Tcl_AppendResult(interp, string, (char *) NULL); + Tcl_AppendResult(interp, string, NULL); mask = 0x80; value = 0; charsInLine += 2; } } - Tcl_AppendResult(interp, ">", (char *) NULL); + Tcl_AppendResult(interp, ">", NULL); XDestroyImage(imagePtr); return TCL_OK; } @@ -897,18 +867,16 @@ Tk_PostscriptBitmap(interp, tkwin, psInfo, bitmap, startX, startY, width, * * Tk_PostscriptStipple -- * - * This procedure is called by individual canvas items when - * they have created a path that they'd like to be filled with - * a stipple pattern. Given information about an X bitmap, - * this procedure will generate Postscript commands to fill - * the current clip region using a stipple pattern defined by the - * bitmap. + * This function is called by individual canvas items when they have + * created a path that they'd like to be filled with a stipple pattern. + * Given information about an X bitmap, this function will generate + * Postscript commands to fill the current clip region using a stipple + * pattern defined by the bitmap. * * Results: - * Returns a standard Tcl return value. If an error occurs - * then an error message will be left in the interp's result. - * If no error occurs, then additional Postscript will be - * appended to the interp's result. + * Returns a standard Tcl return value. If an error occurs then an error + * message will be left in the interp's result. If no error occurs, then + * additional Postscript will be appended to the interp's result. * * Side effects: * None. @@ -917,12 +885,12 @@ Tk_PostscriptBitmap(interp, tkwin, psInfo, bitmap, startX, startY, width, */ int -Tk_PostscriptStipple(interp, tkwin, psInfo, bitmap) - Tcl_Interp *interp; - Tk_Window tkwin; - Tk_PostscriptInfo psInfo; /* Interpreter for returning Postscript - * or error message. */ - Pixmap bitmap; /* Bitmap to use for stippling. */ +Tk_PostscriptStipple( + Tcl_Interp *interp, + Tk_Window tkwin, + Tk_PostscriptInfo psInfo, /* Interpreter for returning Postscript or + * error message. */ + Pixmap bitmap) /* Bitmap to use for stippling. */ { TkPostscriptInfo *psInfoPtr = (TkPostscriptInfo *) psInfo; int width, height; @@ -937,22 +905,22 @@ Tk_PostscriptStipple(interp, tkwin, psInfo, bitmap) /* * The following call should probably be a call to Tk_SizeOfBitmap - * instead, but it seems that we are occasionally invoked by custom - * item types that create their own bitmaps without registering them - * with Tk. XGetGeometry is a bit slower than Tk_SizeOfBitmap, but - * it shouldn't matter here. + * instead, but it seems that we are occasionally invoked by custom item + * types that create their own bitmaps without registering them with Tk. + * XGetGeometry is a bit slower than Tk_SizeOfBitmap, but it shouldn't + * matter here. */ XGetGeometry(Tk_Display(tkwin), bitmap, &dummyRoot, (int *) &dummyX, (int *) &dummyY, (unsigned *) &width, (unsigned *) &height, &dummyBorderwidth, &dummyDepth); sprintf(string, "%d %d ", width, height); - Tcl_AppendResult(interp, string, (char *) NULL); + Tcl_AppendResult(interp, string, NULL); if (Tk_PostscriptBitmap(interp, tkwin, psInfo, bitmap, 0, 0, width, height) != TCL_OK) { return TCL_ERROR; } - Tcl_AppendResult(interp, " StippleFill\n", (char *) NULL); + Tcl_AppendResult(interp, " StippleFill\n", NULL); return TCL_OK; } @@ -961,12 +929,13 @@ Tk_PostscriptStipple(interp, tkwin, psInfo, bitmap) * * Tk_PostscriptY -- * - * Given a y-coordinate in local coordinates, this procedure - * returns a y-coordinate to use for Postscript output. + * Given a y-coordinate in local coordinates, this function returns a + * y-coordinate to use for Postscript output. Required because canvases + * have their origin in the top-left, but postscript pages have their + * origin in the bottom left. * * Results: - * Returns the Postscript coordinate that corresponds to - * "y". + * Returns the Postscript coordinate that corresponds to "y". * * Side effects: * None. @@ -975,9 +944,9 @@ Tk_PostscriptStipple(interp, tkwin, psInfo, bitmap) */ double -Tk_PostscriptY(y, psInfo) - double y; /* Y-coordinate in canvas coords. */ - Tk_PostscriptInfo psInfo; /* Postscript info */ +Tk_PostscriptY( + double y, /* Y-coordinate in canvas coords. */ + Tk_PostscriptInfo psInfo) /* Postscript info */ { TkPostscriptInfo *psInfoPtr = (TkPostscriptInfo *) psInfo; @@ -989,8 +958,8 @@ Tk_PostscriptY(y, psInfo) * * Tk_PostscriptPath -- * - * Given an array of points for a path, generate Postscript - * commands to create the path. + * Given an array of points for a path, generate Postscript commands to + * create the path. * * Results: * Postscript commands get appended to what's in the interp's result. @@ -1002,14 +971,13 @@ Tk_PostscriptY(y, psInfo) */ void -Tk_PostscriptPath(interp, psInfo, coordPtr, numPoints) - Tcl_Interp *interp; - Tk_PostscriptInfo psInfo; /* Canvas on whose behalf Postscript - * is being generated. */ - double *coordPtr; /* Pointer to first in array of - * 2*numPoints coordinates giving - * points for path. */ - int numPoints; /* Number of points at *coordPtr. */ +Tk_PostscriptPath( + Tcl_Interp *interp, + Tk_PostscriptInfo psInfo, /* Canvas on whose behalf Postscript is being + * generated. */ + double *coordPtr, /* Pointer to first in array of 2*numPoints + * coordinates giving points for path. */ + int numPoints) /* Number of points at *coordPtr. */ { TkPostscriptInfo *psInfoPtr = (TkPostscriptInfo *) psInfo; char buffer[200]; @@ -1019,12 +987,12 @@ Tk_PostscriptPath(interp, psInfo, coordPtr, numPoints) } sprintf(buffer, "%.15g %.15g moveto\n", coordPtr[0], Tk_PostscriptY(coordPtr[1], psInfo)); - Tcl_AppendResult(interp, buffer, (char *) NULL); + Tcl_AppendResult(interp, buffer, NULL); for (numPoints--, coordPtr += 2; numPoints > 0; numPoints--, coordPtr += 2) { sprintf(buffer, "%.15g %.15g lineto\n", coordPtr[0], Tk_PostscriptY(coordPtr[1], psInfo)); - Tcl_AppendResult(interp, buffer, (char *) NULL); + Tcl_AppendResult(interp, buffer, NULL); } } @@ -1033,15 +1001,14 @@ Tk_PostscriptPath(interp, psInfo, coordPtr, numPoints) * * GetPostscriptPoints -- * - * Given a string, returns the number of Postscript points - * corresponding to that string. + * Given a string, returns the number of Postscript points corresponding + * to that string. * * Results: - * The return value is a standard Tcl return result. If - * TCL_OK is returned, then everything went well and the - * screen distance is stored at *doublePtr; otherwise - * TCL_ERROR is returned and an error message is left in - * the interp's result. + * The return value is a standard Tcl return result. If TCL_OK is + * returned, then everything went well and the screen distance is stored + * at *doublePtr; otherwise TCL_ERROR is returned and an error message is + * left in the interp's result. * * Side effects: * None. @@ -1050,44 +1017,41 @@ Tk_PostscriptPath(interp, psInfo, coordPtr, numPoints) */ static int -GetPostscriptPoints(interp, string, doublePtr) - Tcl_Interp *interp; /* Use this for error reporting. */ - char *string; /* String describing a screen distance. */ - double *doublePtr; /* Place to store converted result. */ +GetPostscriptPoints( + Tcl_Interp *interp, /* Use this for error reporting. */ + char *string, /* String describing a screen distance. */ + double *doublePtr) /* Place to store converted result. */ { char *end; double d; d = strtod(string, &end); if (end == string) { - error: - Tcl_AppendResult(interp, "bad distance \"", string, - "\"", (char *) NULL); - return TCL_ERROR; + goto error; } while ((*end != '\0') && isspace(UCHAR(*end))) { end++; } switch (*end) { - case 'c': - d *= 72.0/2.54; - end++; - break; - case 'i': - d *= 72.0; - end++; - break; - case 'm': - d *= 72.0/25.4; - end++; - break; - case 0: - break; - case 'p': - end++; - break; - default: - goto error; + case 'c': + d *= 72.0/2.54; + end++; + break; + case 'i': + d *= 72.0; + end++; + break; + case 'm': + d *= 72.0/25.4; + end++; + break; + case 0: + break; + case 'p': + end++; + break; + default: + goto error; } while ((*end != '\0') && isspace(UCHAR(*end))) { end++; @@ -1097,34 +1061,37 @@ GetPostscriptPoints(interp, string, doublePtr) } *doublePtr = d; return TCL_OK; -} + error: + Tcl_AppendResult(interp, "bad distance \"", string, "\"", NULL); + return TCL_ERROR; +} + /* *-------------------------------------------------------------- * * TkImageGetColor -- * - * This procedure converts a pixel value to three floating - * point numbers, representing the amount of red, green, and - * blue in that pixel on the screen. It makes use of colormap - * data passed as an argument, and should work for all Visual - * types. + * This function converts a pixel value to three floating point numbers, + * representing the amount of red, green, and blue in that pixel on the + * screen. It makes use of colormap data passed as an argument, and + * should work for all Visual types. * - * This implementation is bogus on Windows because the colormap - * data is never filled in. Instead all postscript generated - * data coming through here is expected to be RGB color data. - * To handle lower bit-depth images properly, XQueryColors - * must be implemented for Windows. + * This implementation is bogus on Windows because the colormap data is + * never filled in. Instead all postscript generated data coming through + * here is expected to be RGB color data. To handle lower bit-depth + * images properly, XQueryColors must be implemented for Windows. * * Results: - * Returns red, green, and blue color values in the range - * 0 to 1. There are no error returns. + * Returns red, green, and blue color values in the range 0 to 1. There + * are no error returns. * * Side effects: * None. * *-------------------------------------------------------------- */ + #ifdef WIN32 #include <windows.h> @@ -1133,35 +1100,41 @@ GetPostscriptPoints(interp, string, doublePtr) #define GetRValue(rgb) ((BYTE)(rgb)) #define GetGValue(rgb) ((BYTE)(((WORD)(rgb)) >> 8)) #define GetBValue(rgb) ((BYTE)((rgb)>>16)) -*/ -#else + */ + +#else /* !WIN32 */ + #define GetRValue(rgb) ((rgb & cdata->red_mask) >> cdata->red_shift) #define GetGValue(rgb) ((rgb & cdata->green_mask) >> cdata->green_shift) #define GetBValue(rgb) ((rgb & cdata->blue_mask) >> cdata->blue_shift) -#endif + +#endif /* WIN32 */ #if defined(WIN32) || defined(MAC_OSX_TK) static void -TkImageGetColor(cdata, pixel, red, green, blue) - TkColormapData *cdata; /* Colormap data */ - unsigned long pixel; /* Pixel value to look up */ - double *red, *green, *blue; /* Color data to return */ +TkImageGetColor( + TkColormapData *cdata, /* Colormap data */ + unsigned long pixel, /* Pixel value to look up */ + double *red, double *green, double *blue) + /* Color data to return */ { *red = (double) GetRValue(pixel) / 255.0; *green = (double) GetGValue(pixel) / 255.0; *blue = (double) GetBValue(pixel) / 255.0; } -#else +#else /* ! (WIN32 || MAC_OSX_TK) */ static void -TkImageGetColor(cdata, pixel, red, green, blue) - TkColormapData *cdata; /* Colormap data */ - unsigned long pixel; /* Pixel value to look up */ - double *red, *green, *blue; /* Color data to return */ +TkImageGetColor( + TkColormapData *cdata, /* Colormap data */ + unsigned long pixel, /* Pixel value to look up */ + double *red, double *green, double *blue) + /* Color data to return */ { if (cdata->separated) { int r = GetRValue(pixel); int g = GetGValue(pixel); int b = GetBValue(pixel); + *red = cdata->colors[r].red / 65535.0; *green = cdata->colors[g].green / 65535.0; *blue = cdata->colors[b].blue / 65535.0; @@ -1171,24 +1144,22 @@ TkImageGetColor(cdata, pixel, red, green, blue) *blue = cdata->colors[pixel].blue / 65535.0; } } -#endif - +#endif /* WIN32 || MAC_OSX_TK */ + /* *-------------------------------------------------------------- * * TkPostscriptImage -- * - * This procedure is called to output the contents of an - * image in Postscript, using a format appropriate for the - * current color mode (i.e. one bit per pixel in monochrome, - * one byte per pixel in gray, and three bytes per pixel in - * color). + * This function is called to output the contents of an image in + * Postscript, using a format appropriate for the current color mode + * (i.e. one bit per pixel in monochrome, one byte per pixel in gray, and + * three bytes per pixel in color). * * Results: - * Returns a standard Tcl return value. If an error occurs - * then an error message will be left in interp->result. - * If no error occurs, then additional Postscript will be - * appended to interp->result. + * Returns a standard Tcl return value. If an error occurs then an error + * message will be left in interp->result. If no error occurs, then + * additional Postscript will be appended to interp->result. * * Side effects: * None. @@ -1197,13 +1168,13 @@ TkImageGetColor(cdata, pixel, red, green, blue) */ int -TkPostscriptImage(interp, tkwin, psInfo, ximage, x, y, width, height) - Tcl_Interp *interp; - Tk_Window tkwin; - Tk_PostscriptInfo psInfo; /* postscript info */ - XImage *ximage; /* Image to draw */ - int x, y; /* First pixel to output */ - int width, height; /* Width and height of area */ +TkPostscriptImage( + Tcl_Interp *interp, + Tk_Window tkwin, + Tk_PostscriptInfo psInfo, /* postscript info */ + XImage *ximage, /* Image to draw */ + int x, int y, /* First pixel to output */ + int width, int height) /* Width and height of area */ { TkPostscriptInfo *psInfoPtr = (TkPostscriptInfo *) psInfo; char buffer[256]; @@ -1224,9 +1195,8 @@ TkPostscriptImage(interp, tkwin, psInfo, ximage, x, y, width, height) visual = Tk_Visual(tkwin); /* - * Obtain information about the colormap, ie the mapping between - * pixel values and RGB values. The code below should work - * for all Visual types. + * Obtain information about the colormap, ie the mapping between pixel + * values and RGB values. The code below should work for all Visual types. */ ncolors = visual->map_entries; @@ -1241,33 +1211,42 @@ TkPostscriptImage(interp, tkwin, psInfo, ximage, x, y, width, height) cdata.red_shift = 0; cdata.green_shift = 0; cdata.blue_shift = 0; - while ((0x0001 & (cdata.red_mask >> cdata.red_shift)) == 0) + + while ((0x0001 & (cdata.red_mask >> cdata.red_shift)) == 0) { cdata.red_shift ++; - while ((0x0001 & (cdata.green_mask >> cdata.green_shift)) == 0) + } + while ((0x0001 & (cdata.green_mask >> cdata.green_shift)) == 0) { cdata.green_shift ++; - while ((0x0001 & (cdata.blue_mask >> cdata.blue_shift)) == 0) + } + while ((0x0001 & (cdata.blue_mask >> cdata.blue_shift)) == 0) { cdata.blue_shift ++; - for (i = 0; i < ncolors; i ++) + } + + for (i = 0; i < ncolors; i ++) { cdata.colors[i].pixel = - ((i << cdata.red_shift) & cdata.red_mask) | - ((i << cdata.green_shift) & cdata.green_mask) | - ((i << cdata.blue_shift) & cdata.blue_mask); + ((i << cdata.red_shift) & cdata.red_mask) | + ((i << cdata.green_shift) & cdata.green_mask) | + ((i << cdata.blue_shift) & cdata.blue_mask); + } } else { cdata.separated=0; - for (i = 0; i < ncolors; i ++) + for (i = 0; i < ncolors; i ++) { cdata.colors[i].pixel = i; + } } - if (visual->class == StaticGray || visual->class == GrayScale) + + if (visual->class == StaticGray || visual->class == GrayScale) { cdata.color = 0; - else + } else { cdata.color = 1; + } XQueryColors(Tk_Display(tkwin), cmap, cdata.colors, ncolors); /* - * Figure out which color level to use (possibly lower than the - * one specified by the user). For example, if the user specifies - * color with monochrome screen, use gray or monochrome mode instead. + * Figure out which color level to use (possibly lower than the one + * specified by the user). For example, if the user specifies color with + * monochrome screen, use gray or monochrome mode instead. */ if (!cdata.color && level == 2) { @@ -1279,15 +1258,15 @@ TkPostscriptImage(interp, tkwin, psInfo, ximage, x, y, width, height) } /* - * Check that at least one row of the image can be represented - * with a string less than 64 KB long (this is a limit in the - * Postscript interpreter). + * Check that at least one row of the image can be represented with a + * string less than 64 KB long (this is a limit in the Postscript + * interpreter). */ switch (level) { - case 0: bytesPerLine = (width + 7) / 8; maxWidth = 240000; break; - case 1: bytesPerLine = width; maxWidth = 60000; break; - case 2: bytesPerLine = 3 * width; maxWidth = 20000; break; + case 0: bytesPerLine = (width + 7) / 8; maxWidth = 240000; break; + case 1: bytesPerLine = width; maxWidth = 60000; break; + case 2: bytesPerLine = 3 * width; maxWidth = 20000; break; } if (bytesPerLine > 60000) { @@ -1295,7 +1274,7 @@ TkPostscriptImage(interp, tkwin, psInfo, ximage, x, y, width, height) sprintf(buffer, "Can't generate Postscript for images more than %d pixels wide", maxWidth); - Tcl_AppendResult(interp, buffer, (char *) NULL); + Tcl_AppendResult(interp, buffer, NULL); ckfree((char *) cdata.colors); return TCL_ERROR; } @@ -1305,107 +1284,110 @@ TkPostscriptImage(interp, tkwin, psInfo, ximage, x, y, width, height) for (band = height-1; band >= 0; band -= maxRows) { int rows = (band >= maxRows) ? maxRows : band + 1; int lineLen = 0; + switch (level) { - case 0: - sprintf(buffer, "%d %d 1 matrix {\n<", width, rows); - Tcl_AppendResult(interp, buffer, (char *) NULL); - break; - case 1: - sprintf(buffer, "%d %d 8 matrix {\n<", width, rows); - Tcl_AppendResult(interp, buffer, (char *) NULL); - break; - case 2: - sprintf(buffer, "%d %d 8 matrix {\n<", - width, rows); - Tcl_AppendResult(interp, buffer, (char *) NULL); - break; + case 0: + sprintf(buffer, "%d %d 1 matrix {\n<", width, rows); + Tcl_AppendResult(interp, buffer, NULL); + break; + case 1: + sprintf(buffer, "%d %d 8 matrix {\n<", width, rows); + Tcl_AppendResult(interp, buffer, NULL); + break; + case 2: + sprintf(buffer, "%d %d 8 matrix {\n<", width, rows); + Tcl_AppendResult(interp, buffer, NULL); + break; } for (yy = band; yy > band - rows; yy--) { switch (level) { - case 0: { - /* - * Generate data for image in monochrome mode. - * No attempt at dithering is made--instead, just - * set a threshold. - */ - unsigned char mask=0x80; - unsigned char data=0x00; - for (xx = x; xx< x+width; xx++) { - TkImageGetColor(&cdata, XGetPixel(ximage, xx, yy), - &red, &green, &blue); - if (0.30 * red + 0.59 * green + 0.11 * blue > 0.5) - data |= mask; - mask >>= 1; - if (mask == 0) { - sprintf(buffer, "%02X", data); - Tcl_AppendResult(interp, buffer, (char *) NULL); - lineLen += 2; - if (lineLen > 60) { - lineLen = 0; - Tcl_AppendResult(interp, "\n", (char *) NULL); - } - mask=0x80; - data=0x00; - } - } - if ((width % 8) != 0) { - sprintf(buffer, "%02X", data); - Tcl_AppendResult(interp, buffer, (char *) NULL); - mask=0x80; - data=0x00; + case 0: { + /* + * Generate data for image in monochrome mode. No attempt at + * dithering is made--instead, just set a threshold. + */ + + unsigned char mask = 0x80; + unsigned char data = 0x00; + + for (xx = x; xx< x+width; xx++) { + TkImageGetColor(&cdata, XGetPixel(ximage, xx, yy), + &red, &green, &blue); + if (0.30 * red + 0.59 * green + 0.11 * blue > 0.5) { + data |= mask; } - break; - } - case 1: { - /* - * Generate data in gray mode--in this case, take a - * weighted sum of the red, green, and blue values. - */ - for (xx = x; xx < x+width; xx ++) { - TkImageGetColor(&cdata, XGetPixel(ximage, xx, yy), - &red, &green, &blue); - sprintf(buffer, "%02X", (int) floor(0.5 + 255.0 * - (0.30 * red + 0.59 * green + 0.11 * blue))); - Tcl_AppendResult(interp, buffer, (char *) NULL); + mask >>= 1; + if (mask == 0) { + sprintf(buffer, "%02X", data); + Tcl_AppendResult(interp, buffer, NULL); lineLen += 2; if (lineLen > 60) { lineLen = 0; - Tcl_AppendResult(interp, "\n", (char *) NULL); + Tcl_AppendResult(interp, "\n", NULL); } + mask=0x80; + data=0x00; } - break; } - case 2: { - /* - * Finally, color mode. Here, just output the red, green, - * and blue values directly. - */ - for (xx = x; xx < x+width; xx++) { - TkImageGetColor(&cdata, XGetPixel(ximage, xx, yy), - &red, &green, &blue); - sprintf(buffer, "%02X%02X%02X", - (int) floor(0.5 + 255.0 * red), - (int) floor(0.5 + 255.0 * green), - (int) floor(0.5 + 255.0 * blue)); - Tcl_AppendResult(interp, buffer, (char *) NULL); - lineLen += 6; - if (lineLen > 60) { - lineLen = 0; - Tcl_AppendResult(interp, "\n", (char *) NULL); - } + if ((width % 8) != 0) { + sprintf(buffer, "%02X", data); + Tcl_AppendResult(interp, buffer, NULL); + mask=0x80; + data=0x00; + } + break; + } + case 1: + /* + * Generate data in gray mode; in this case, take a weighted + * sum of the red, green, and blue values. + */ + + for (xx = x; xx < x+width; xx ++) { + TkImageGetColor(&cdata, XGetPixel(ximage, xx, yy), + &red, &green, &blue); + sprintf(buffer, "%02X", (int) floor(0.5 + 255.0 * + (0.30 * red + 0.59 * green + 0.11 * blue))); + Tcl_AppendResult(interp, buffer, NULL); + lineLen += 2; + if (lineLen > 60) { + lineLen = 0; + Tcl_AppendResult(interp, "\n", NULL); } - break; } + break; + case 2: + /* + * Finally, color mode. Here, just output the red, green, and + * blue values directly. + */ + + for (xx = x; xx < x+width; xx++) { + TkImageGetColor(&cdata, XGetPixel(ximage, xx, yy), + &red, &green, &blue); + sprintf(buffer, "%02X%02X%02X", + (int) floor(0.5 + 255.0 * red), + (int) floor(0.5 + 255.0 * green), + (int) floor(0.5 + 255.0 * blue)); + Tcl_AppendResult(interp, buffer, NULL); + lineLen += 6; + if (lineLen > 60) { + lineLen = 0; + Tcl_AppendResult(interp, "\n", NULL); + } + } + break; } } switch (level) { - case 0: sprintf(buffer, ">\n} image\n"); break; - case 1: sprintf(buffer, ">\n} image\n"); break; - case 2: sprintf(buffer, ">\n} false 3 colorimage\n"); break; + case 0: case 1: + sprintf(buffer, ">\n} image\n"); break; + case 2: + sprintf(buffer, ">\n} false 3 colorimage\n"); break; } - Tcl_AppendResult(interp, buffer, (char *) NULL); + Tcl_AppendResult(interp, buffer, NULL); sprintf(buffer, "0 %d translate\n", rows); - Tcl_AppendResult(interp, buffer, (char *) NULL); + Tcl_AppendResult(interp, buffer, NULL); } ckfree((char *) cdata.colors); return TCL_OK; @@ -1416,28 +1398,28 @@ TkPostscriptImage(interp, tkwin, psInfo, ximage, x, y, width, height) * * Tk_PostscriptPhoto -- * - * This procedure is called to output the contents of a - * photo image in Postscript, using a format appropriate for - * the requested postscript color mode (i.e. one byte per pixel - * in gray, and three bytes per pixel in color). + * This function is called to output the contents of a photo image in + * Postscript, using a format appropriate for the requested postscript + * color mode (i.e. one byte per pixel in gray, and three bytes per pixel + * in color). * * Results: - * Returns a standard Tcl return value. If an error occurs - * then an error message will be left in interp->result. - * If no error occurs, then additional Postscript will be - * appended to the interpreter's result. + * Returns a standard Tcl return value. If an error occurs then an error + * message will be left in interp->result. If no error occurs, then + * additional Postscript will be appended to the interpreter's result. * * Side effects: * None. * *-------------------------------------------------------------- */ + int -Tk_PostscriptPhoto(interp, blockPtr, psInfo, width, height) - Tcl_Interp *interp; - Tk_PhotoImageBlock *blockPtr; - Tk_PostscriptInfo psInfo; - int width, height; +Tk_PostscriptPhoto( + Tcl_Interp *interp, + Tk_PhotoImageBlock *blockPtr, + Tk_PostscriptInfo psInfo, + int width, int height) { TkPostscriptInfo *psInfoPtr = (TkPostscriptInfo *) psInfo; int colorLevel = psInfoPtr->colorLevel; @@ -1461,20 +1443,20 @@ Tk_PostscriptPhoto(interp, blockPtr, psInfo, width, height) } /* - * Define the "TkPhoto" function, which is a modified version - * of the original "transparentimage" function posted - * by ian@five-d.com (Ian Kemmish) to comp.lang.postscript. - * For a monochrome colorLevel this is a slightly different - * version that uses the imagemask command instead of image. + * Define the "TkPhoto" function, which is a modified version of the + * original "transparentimage" function posted by ian@five-d.com (Ian + * Kemmish) to comp.lang.postscript. For a monochrome colorLevel this is a + * slightly different version that uses the imagemask command instead of + * image. */ - if( !codeIncluded && (colorLevel != 0) ) { + if (!codeIncluded && (colorLevel != 0)) { /* * Color and gray-scale code. */ codeIncluded = !0; - Tcl_AppendResult( interp, + Tcl_AppendResult(interp, "/TkPhoto { \n", " gsave \n", " 32 dict begin \n", @@ -1543,14 +1525,14 @@ Tk_PostscriptPhoto(interp, blockPtr, psInfo, width, height) " } for \n", " end \n", " grestore \n", - "} bind def \n\n\n", (char *) NULL); - } else if( !codeIncluded && (colorLevel == 0) ) { + "} bind def \n\n\n", NULL); + } else if (!codeIncluded && (colorLevel == 0)) { /* * Monochrome-only code */ codeIncluded = !0; - Tcl_AppendResult( interp, + Tcl_AppendResult(interp, "/TkPhoto { \n", " gsave \n", " 32 dict begin \n", @@ -1587,27 +1569,26 @@ Tk_PostscriptPhoto(interp, blockPtr, psInfo, width, height) " } for \n", " end \n", " grestore \n", - "} bind def \n\n\n", (char *) NULL); + "} bind def \n\n\n", NULL); } /* - * Check that at least one row of the image can be represented - * with a string less than 64 KB long (this is a limit in the - * Postscript interpreter). + * Check that at least one row of the image can be represented with a + * string less than 64 KB long (this is a limit in the Postscript + * interpreter). */ - switch (colorLevel) - { - case 0: bytesPerLine = (width + 7) / 8; maxWidth = 240000; break; - case 1: bytesPerLine = width; maxWidth = 60000; break; - case 2: bytesPerLine = 3 * width; maxWidth = 20000; break; - } + switch (colorLevel) { + case 0: bytesPerLine = (width + 7) / 8; maxWidth = 240000; break; + case 1: bytesPerLine = width; maxWidth = 60000; break; + case 2: bytesPerLine = 3 * width; maxWidth = 20000; break; + } if (bytesPerLine > 60000) { Tcl_ResetResult(interp); sprintf(buffer, "Can't generate Postscript for images more than %d pixels wide", maxWidth); - Tcl_AppendResult(interp, buffer, (char *) NULL); + Tcl_AppendResult(interp, buffer, NULL); return TCL_ERROR; } @@ -1616,45 +1597,37 @@ Tk_PostscriptPhoto(interp, blockPtr, psInfo, width, height) */ switch (colorLevel) { - case 0: - strcpy( cspace, "/DeviceGray"); - strcpy( decode, "[1 0]"); - bpc = 1; - break; - case 1: - strcpy( cspace, "/DeviceGray"); - strcpy( decode, "[0 1]"); - bpc = 8; - break; - default: - strcpy( cspace, "/DeviceRGB"); - strcpy( decode, "[0 1 0 1 0 1]"); - bpc = 8; - break; + case 0: + strcpy(cspace, "/DeviceGray"); + strcpy(decode, "[1 0]"); + bpc = 1; + break; + case 1: + strcpy(cspace, "/DeviceGray"); + strcpy(decode, "[0 1]"); + bpc = 8; + break; + default: + strcpy(cspace, "/DeviceRGB"); + strcpy(decode, "[0 1 0 1 0 1]"); + bpc = 8; + break; } - Tcl_AppendResult(interp, - cspace, " setcolorspace\n\n", (char *) NULL); + Tcl_AppendResult(interp, cspace, " setcolorspace\n\n", NULL); - sprintf(buffer, - " /Width %d\n /Height %d\n /BitsPerComponent %d\n", + sprintf(buffer, " /Width %d\n /Height %d\n /BitsPerComponent %d\n", width, height, bpc); - Tcl_AppendResult(interp, - "<<\n /ImageType 1\n", buffer, - " /DataSource currentfile", - " /ASCIIHexDecode filter\n", (char *) NULL); - - - sprintf(buffer, - " /ImageMatrix [1 0 0 -1 0 %d]\n", height); - Tcl_AppendResult(interp, buffer, - " /Decode ", decode, "\n>>\n1 TkPhoto\n", (char *) NULL); + Tcl_AppendResult(interp, "<<\n /ImageType 1\n", buffer, + " /DataSource currentfile /ASCIIHexDecode filter\n", NULL); + sprintf(buffer, " /ImageMatrix [1 0 0 -1 0 %d]\n", height); + Tcl_AppendResult(interp, buffer, " /Decode ", decode, + "\n>>\n1 TkPhoto\n", NULL); /* - * Check the PhotoImageBlock information. - * We assume that: + * Check the PhotoImageBlock information. We assume that: * if pixelSize is 1,2 or 4, the image is R,G,B,A; * if pixelSize is 3, the image is R,G,B and offset[3] is bogus. */ @@ -1677,198 +1650,192 @@ Tk_PostscriptPhoto(interp, blockPtr, psInfo, width, height) alphaOffset = blockPtr->offset[3]; } - for (yy = 0, lineLen=0; yy < height; yy++) { switch (colorLevel) { - case 0: { - /* - * Generate data for image in monochrome mode. - * No attempt at dithering is made--instead, just - * set a threshold. - * To handle transparecies we need to output two lines: - * one for the black pixels, one for the white ones. - */ + case 0: { + /* + * Generate data for image in monochrome mode. No attempt at + * dithering is made--instead, just set a threshold. To handle + * transparecies we need to output two lines: one for the black + * pixels, one for the white ones. + */ - unsigned char mask=0x80; - unsigned char data=0x00; - for (xx = 0; xx< width; xx ++) { - pixelPtr = blockPtr->pixelPtr - + (yy * blockPtr->pitch) + unsigned char mask = 0x80; + unsigned char data = 0x00; + + for (xx = 0; xx< width; xx ++) { + pixelPtr = blockPtr->pixelPtr + (yy * blockPtr->pitch) + (xx *blockPtr->pixelSize); - red = pixelPtr[blockPtr->offset[0]]; - green = pixelPtr[blockPtr->offset[1]]; - blue = pixelPtr[blockPtr->offset[2]]; + red = pixelPtr[blockPtr->offset[0]]; + green = pixelPtr[blockPtr->offset[1]]; + blue = pixelPtr[blockPtr->offset[2]]; - alpha = *(alphaPtr + (yy * alphaPitch) - + (xx * alphaIncr) + alphaOffset); + alpha = *(alphaPtr + (yy * alphaPitch) + + (xx * alphaIncr) + alphaOffset); - /* - * If pixel is less than threshold, then it is black. - */ + /* + * If pixel is less than threshold, then it is black. + */ - if ((alpha != 0) && - ( 0.3086 * red - + 0.6094 * green - + 0.082 * blue < 128)) { - data |= mask; - } - mask >>= 1; - if (mask == 0) { - sprintf(buffer, "%02X", data); - Tcl_AppendResult(interp, buffer, (char *) NULL); - lineLen += 2; - if (lineLen >= 60) { - lineLen = 0; - Tcl_AppendResult(interp, "\n", (char *) NULL); - } - mask=0x80; - data=0x00; - } + if ((alpha != 0) && + (0.3086*red + 0.6094*green + 0.082*blue < 128)) { + data |= mask; } - if ((width % 8) != 0) { + mask >>= 1; + if (mask == 0) { sprintf(buffer, "%02X", data); - Tcl_AppendResult(interp, buffer, (char *) NULL); - mask=0x80; - data=0x00; + Tcl_AppendResult(interp, buffer, NULL); + lineLen += 2; + if (lineLen >= 60) { + lineLen = 0; + Tcl_AppendResult(interp, "\n", NULL); + } + mask = 0x80; + data = 0x00; } + } + if ((width % 8) != 0) { + sprintf(buffer, "%02X", data); + Tcl_AppendResult(interp, buffer, NULL); + mask = 0x80; + data = 0x00; + } - mask=0x80; - data=0x00; - for (xx = 0; xx< width; xx ++) { - pixelPtr = blockPtr->pixelPtr - + (yy * blockPtr->pitch) + mask = 0x80; + data = 0x00; + for (xx=0 ; xx<width ; xx++) { + pixelPtr = blockPtr->pixelPtr + (yy * blockPtr->pitch) + (xx *blockPtr->pixelSize); - red = pixelPtr[blockPtr->offset[0]]; - green = pixelPtr[blockPtr->offset[1]]; - blue = pixelPtr[blockPtr->offset[2]]; - - alpha = *(alphaPtr + (yy * alphaPitch) - + (xx * alphaIncr) + alphaOffset); - - /* - * If pixel is greater than threshold, then it is white. - */ - - if ((alpha != 0) && - ( 0.3086 * red - + 0.6094 * green - + 0.082 * blue >= 128)) { - data |= mask; - } - mask >>= 1; - if (mask == 0) { - sprintf(buffer, "%02X", data); - Tcl_AppendResult(interp, buffer, (char *) NULL); - lineLen += 2; - if (lineLen >= 60) { - lineLen = 0; - Tcl_AppendResult(interp, "\n", (char *) NULL); - } - mask=0x80; - data=0x00; - } - } - if ((width % 8) != 0) { - sprintf(buffer, "%02X", data); - Tcl_AppendResult(interp, buffer, (char *) NULL); - mask=0x80; - data=0x00; - } - break; - } - case 1: { + red = pixelPtr[blockPtr->offset[0]]; + green = pixelPtr[blockPtr->offset[1]]; + blue = pixelPtr[blockPtr->offset[2]]; + + alpha = *(alphaPtr + (yy * alphaPitch) + + (xx * alphaIncr) + alphaOffset); + /* - * Generate transparency data. - * We must prevent a transparent value of 0 - * because of a bug in some HP printers. + * If pixel is greater than threshold, then it is white. */ - for (xx = 0; xx < width; xx ++) { - alpha = *(alphaPtr + (yy * alphaPitch) - + (xx * alphaIncr) + alphaOffset); - sprintf(buffer, "%02X", alpha | 0x01); - Tcl_AppendResult(interp, buffer, (char *) NULL); + if ((alpha != 0) && + (0.3086*red + 0.6094*green + 0.082*blue >= 128)) { + data |= mask; + } + mask >>= 1; + if (mask == 0) { + sprintf(buffer, "%02X", data); + Tcl_AppendResult(interp, buffer, NULL); lineLen += 2; if (lineLen >= 60) { lineLen = 0; - Tcl_AppendResult(interp, "\n", (char *) NULL); + Tcl_AppendResult(interp, "\n", NULL); } + mask = 0x80; + data = 0x00; } + } + if ((width % 8) != 0) { + sprintf(buffer, "%02X", data); + Tcl_AppendResult(interp, buffer, NULL); + mask = 0x80; + data = 0x00; + } + break; + } + case 1: { + /* + * Generate transparency data. We must prevent a transparent value + * of 0 because of a bug in some HP printers. + */ + for (xx = 0; xx < width; xx ++) { + alpha = *(alphaPtr + (yy * alphaPitch) + + (xx * alphaIncr) + alphaOffset); + sprintf(buffer, "%02X", alpha | 0x01); + Tcl_AppendResult(interp, buffer, NULL); + lineLen += 2; + if (lineLen >= 60) { + lineLen = 0; + Tcl_AppendResult(interp, "\n", NULL); + } + } - /* - * Generate data in gray mode--in this case, take a - * weighted sum of the red, green, and blue values. - */ + /* + * Generate data in gray mode; in this case, take a weighted sum + * of the red, green, and blue values. + */ - for (xx = 0; xx < width; xx ++) { - pixelPtr = blockPtr->pixelPtr - + (yy * blockPtr->pitch) + for (xx = 0; xx < width; xx ++) { + pixelPtr = blockPtr->pixelPtr + (yy * blockPtr->pitch) + (xx *blockPtr->pixelSize); - red = pixelPtr[blockPtr->offset[0]]; - green = pixelPtr[blockPtr->offset[1]]; - blue = pixelPtr[blockPtr->offset[2]]; - - sprintf(buffer, "%02X", (int) floor(0.5 + - ( 0.3086 * red + 0.6094 * green + 0.0820 * blue))); - Tcl_AppendResult(interp, buffer, (char *) NULL); - lineLen += 2; - if (lineLen >= 60) { - lineLen = 0; - Tcl_AppendResult(interp, "\n", (char *) NULL); - } + red = pixelPtr[blockPtr->offset[0]]; + green = pixelPtr[blockPtr->offset[1]]; + blue = pixelPtr[blockPtr->offset[2]]; + + sprintf(buffer, "%02X", (int) floor(0.5 + + ( 0.3086 * red + 0.6094 * green + 0.0820 * blue))); + Tcl_AppendResult(interp, buffer, NULL); + lineLen += 2; + if (lineLen >= 60) { + lineLen = 0; + Tcl_AppendResult(interp, "\n", NULL); } - break; } - default: { - /* - * Generate transparency data. - * We must prevent a transparent value of 0 - * because of a bug in some HP printers. - */ + break; + } + default: + /* + * Generate transparency data. We must prevent a transparent value + * of 0 because of a bug in some HP printers. + */ - for (xx = 0; xx < width; xx ++) { - alpha = *(alphaPtr + (yy * alphaPitch) - + (xx * alphaIncr) + alphaOffset); - sprintf(buffer, "%02X", alpha | 0x01); - Tcl_AppendResult(interp, buffer, (char *) NULL); - lineLen += 2; - if (lineLen >= 60) { - lineLen = 0; - Tcl_AppendResult(interp, "\n", (char *) NULL); - } + for (xx = 0; xx < width; xx ++) { + alpha = *(alphaPtr + (yy * alphaPitch) + + (xx * alphaIncr) + alphaOffset); + sprintf(buffer, "%02X", alpha | 0x01); + Tcl_AppendResult(interp, buffer, NULL); + lineLen += 2; + if (lineLen >= 60) { + lineLen = 0; + Tcl_AppendResult(interp, "\n", NULL); } + } + /* + * Finally, color mode. Here, just output the red, green, and blue + * values directly. + */ - /* - * Finally, color mode. Here, just output the red, green, - * and blue values directly. - */ - - for (xx = 0; xx < width; xx ++) { - pixelPtr = blockPtr->pixelPtr - + (yy * blockPtr->pitch) - + (xx *blockPtr->pixelSize); - - sprintf(buffer, "%02X%02X%02X", - pixelPtr[blockPtr->offset[0]], - pixelPtr[blockPtr->offset[1]], - pixelPtr[blockPtr->offset[2]]); - Tcl_AppendResult(interp, buffer, (char *) NULL); - lineLen += 6; - if (lineLen >= 60) { - lineLen = 0; - Tcl_AppendResult(interp, "\n", (char *) NULL); - } + for (xx = 0; xx < width; xx ++) { + pixelPtr = blockPtr->pixelPtr + (yy * blockPtr->pitch) + + (xx * blockPtr->pixelSize); + + sprintf(buffer, "%02X%02X%02X", + pixelPtr[blockPtr->offset[0]], + pixelPtr[blockPtr->offset[1]], + pixelPtr[blockPtr->offset[2]]); + Tcl_AppendResult(interp, buffer, NULL); + lineLen += 6; + if (lineLen >= 60) { + lineLen = 0; + Tcl_AppendResult(interp, "\n", NULL); } - break; } + break; } } - Tcl_AppendResult(interp, ">\n", (char *) NULL); + Tcl_AppendResult(interp, ">\n", NULL); return TCL_OK; } + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ diff --git a/generic/tkCanvText.c b/generic/tkCanvText.c index 8cd3a4e..05ff604 100644 --- a/generic/tkCanvText.c +++ b/generic/tkCanvText.c @@ -1,4 +1,4 @@ -/* +/* * tkCanvText.c -- * * This file implements text items for canvas widgets. @@ -6,10 +6,10 @@ * Copyright (c) 1991-1994 The Regents of the University of California. * Copyright (c) 1994-1997 Sun Microsystems, Inc. * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkCanvText.c,v 1.18 2005/08/10 22:02:22 dkf Exp $ + * RCS: @(#) $Id: tkCanvText.c,v 1.19 2005/11/04 15:23:05 dkf Exp $ */ #include <stdio.h> @@ -24,17 +24,17 @@ typedef struct TextItem { Tk_Item header; /* Generic stuff that's the same for all - * types. MUST BE FIRST IN STRUCTURE. */ + * types. MUST BE FIRST IN STRUCTURE. */ Tk_CanvasTextInfo *textInfoPtr; /* Pointer to a structure containing * information about the selection and - * insertion cursor. The structure is owned - * by (and shared with) the generic canvas + * insertion cursor. The structure is owned by + * (and shared with) the generic canvas * code. */ /* * Fields that are set by widget commands other than "configure". */ - + double x, y; /* Positioning point for text. */ int insertPos; /* Character index of character just before * which the insertion cursor is displayed. */ @@ -54,8 +54,8 @@ typedef struct TextItem { Pixmap activeStipple; /* Stipple bitmap for text, or None. */ Pixmap disabledStipple; /* Stipple bitmap for text, or None. */ char *text; /* Text for item (malloc-ed). */ - int width; /* Width of lines for word-wrap, pixels. - * Zero means no word-wrap. */ + int width; /* Width of lines for word-wrap, pixels. Zero + * means no word-wrap. */ /* * Fields whose values are derived from the current values of the @@ -65,17 +65,17 @@ typedef struct TextItem { int numChars; /* Length of text in characters. */ int numBytes; /* Length of text in bytes. */ Tk_TextLayout textLayout; /* Cached text layout information. */ - int leftEdge; /* Pixel location of the left edge of the - * text item; where the left border of the - * text layout is drawn. */ - int rightEdge; /* Pixel just to right of right edge of - * area of text item. Used for selecting up - * to end of line. */ + int leftEdge; /* Pixel location of the left edge of the text + * item; where the left border of the text + * layout is drawn. */ + int rightEdge; /* Pixel just to right of right edge of area + * of text item. Used for selecting up to end + * of line. */ GC gc; /* Graphics context for drawing text. */ GC selTextGC; /* Graphics context for selected text. */ GC cursorOffGC; /* If not None, this gives a graphics context * to use to draw the insertion cursor when - * it's off. Used if the selection and + * it's off. Used if the selection and * insertion cursor colors are the same. */ } TextItem; @@ -97,89 +97,84 @@ static Tk_CustomOption offsetOption = { }; static Tk_ConfigSpec configSpecs[] = { - {TK_CONFIG_COLOR, "-activefill", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(TextItem, activeColor), TK_CONFIG_NULL_OK}, - {TK_CONFIG_BITMAP, "-activestipple", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(TextItem, activeStipple), TK_CONFIG_NULL_OK}, - {TK_CONFIG_ANCHOR, "-anchor", (char *) NULL, (char *) NULL, - "center", Tk_Offset(TextItem, anchor), - TK_CONFIG_DONT_SET_DEFAULT}, - {TK_CONFIG_COLOR, "-disabledfill", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(TextItem, disabledColor), TK_CONFIG_NULL_OK}, - {TK_CONFIG_BITMAP, "-disabledstipple", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(TextItem, disabledStipple), TK_CONFIG_NULL_OK}, - {TK_CONFIG_COLOR, "-fill", (char *) NULL, (char *) NULL, + {TK_CONFIG_COLOR, "-activefill", NULL, NULL, + NULL, Tk_Offset(TextItem, activeColor), TK_CONFIG_NULL_OK}, + {TK_CONFIG_BITMAP, "-activestipple", NULL, NULL, + NULL, Tk_Offset(TextItem, activeStipple), TK_CONFIG_NULL_OK}, + {TK_CONFIG_ANCHOR, "-anchor", NULL, NULL, + "center", Tk_Offset(TextItem, anchor), TK_CONFIG_DONT_SET_DEFAULT}, + {TK_CONFIG_COLOR, "-disabledfill", NULL, NULL, + NULL, Tk_Offset(TextItem, disabledColor), TK_CONFIG_NULL_OK}, + {TK_CONFIG_BITMAP, "-disabledstipple", NULL, NULL, + NULL, Tk_Offset(TextItem, disabledStipple), TK_CONFIG_NULL_OK}, + {TK_CONFIG_COLOR, "-fill", NULL, NULL, "black", Tk_Offset(TextItem, color), TK_CONFIG_NULL_OK}, - {TK_CONFIG_FONT, "-font", (char *) NULL, (char *) NULL, + {TK_CONFIG_FONT, "-font", NULL, NULL, DEF_CANVTEXT_FONT, Tk_Offset(TextItem, tkfont), 0}, - {TK_CONFIG_JUSTIFY, "-justify", (char *) NULL, (char *) NULL, - "left", Tk_Offset(TextItem, justify), - TK_CONFIG_DONT_SET_DEFAULT}, - {TK_CONFIG_CUSTOM, "-offset", (char *) NULL, (char *) NULL, + {TK_CONFIG_JUSTIFY, "-justify", NULL, NULL, + "left", Tk_Offset(TextItem, justify), TK_CONFIG_DONT_SET_DEFAULT}, + {TK_CONFIG_CUSTOM, "-offset", NULL, NULL, "0,0", Tk_Offset(TextItem, tsoffset), TK_CONFIG_DONT_SET_DEFAULT, &offsetOption}, - {TK_CONFIG_CUSTOM, "-state", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(Tk_Item, state), TK_CONFIG_NULL_OK, - &stateOption}, - {TK_CONFIG_BITMAP, "-stipple", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(TextItem, stipple), TK_CONFIG_NULL_OK}, - {TK_CONFIG_CUSTOM, "-tags", (char *) NULL, (char *) NULL, - (char *) NULL, 0, TK_CONFIG_NULL_OK, &tagsOption}, - {TK_CONFIG_STRING, "-text", (char *) NULL, (char *) NULL, + {TK_CONFIG_CUSTOM, "-state", NULL, NULL, + NULL, Tk_Offset(Tk_Item, state), TK_CONFIG_NULL_OK, &stateOption}, + {TK_CONFIG_BITMAP, "-stipple", NULL, NULL, + NULL, Tk_Offset(TextItem, stipple), TK_CONFIG_NULL_OK}, + {TK_CONFIG_CUSTOM, "-tags", NULL, NULL, + NULL, 0, TK_CONFIG_NULL_OK, &tagsOption}, + {TK_CONFIG_STRING, "-text", NULL, NULL, "", Tk_Offset(TextItem, text), 0}, - {TK_CONFIG_PIXELS, "-width", (char *) NULL, (char *) NULL, + {TK_CONFIG_PIXELS, "-width", NULL, NULL, "0", Tk_Offset(TextItem, width), TK_CONFIG_DONT_SET_DEFAULT}, - {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL, - (char *) NULL, 0, 0} + {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0} }; /* - * Prototypes for procedures defined in this file: + * Prototypes for functions defined in this file: */ -static void ComputeTextBbox _ANSI_ARGS_((Tk_Canvas canvas, - TextItem *textPtr)); -static int ConfigureText _ANSI_ARGS_((Tcl_Interp *interp, +static void ComputeTextBbox(Tk_Canvas canvas, TextItem *textPtr); +static int ConfigureText(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, int argc, - Tcl_Obj *CONST objv[], int flags)); -static int CreateText _ANSI_ARGS_((Tcl_Interp *interp, + Tcl_Obj *CONST objv[], int flags); +static int CreateText(Tcl_Interp *interp, Tk_Canvas canvas, struct Tk_Item *itemPtr, - int argc, Tcl_Obj *CONST objv[])); -static void DeleteText _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, Display *display)); -static void DisplayCanvText _ANSI_ARGS_((Tk_Canvas canvas, + int argc, Tcl_Obj *CONST objv[]); +static void DeleteText(Tk_Canvas canvas, + Tk_Item *itemPtr, Display *display); +static void DisplayCanvText(Tk_Canvas canvas, Tk_Item *itemPtr, Display *display, Drawable dst, - int x, int y, int width, int height)); -static int GetSelText _ANSI_ARGS_((Tk_Canvas canvas, + int x, int y, int width, int height); +static int GetSelText(Tk_Canvas canvas, Tk_Item *itemPtr, int offset, char *buffer, - int maxBytes)); -static int GetTextIndex _ANSI_ARGS_((Tcl_Interp *interp, + int maxBytes); +static int GetTextIndex(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, - Tcl_Obj *obj, int *indexPtr)); -static void ScaleText _ANSI_ARGS_((Tk_Canvas canvas, + Tcl_Obj *obj, int *indexPtr); +static void ScaleText(Tk_Canvas canvas, Tk_Item *itemPtr, double originX, double originY, - double scaleX, double scaleY)); -static void SetTextCursor _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, int index)); -static int TextCoords _ANSI_ARGS_((Tcl_Interp *interp, + double scaleX, double scaleY); +static void SetTextCursor(Tk_Canvas canvas, + Tk_Item *itemPtr, int index); +static int TextCoords(Tcl_Interp *interp, Tk_Canvas canvas, Tk_Item *itemPtr, - int argc, Tcl_Obj *CONST objv[])); -static void TextDeleteChars _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, int first, int last)); -static void TextInsert _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, int beforeThis, char *string)); -static int TextToArea _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, double *rectPtr)); -static double TextToPoint _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, double *pointPtr)); -static int TextToPostscript _ANSI_ARGS_((Tcl_Interp *interp, - Tk_Canvas canvas, Tk_Item *itemPtr, int prepass)); -static void TranslateText _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, double deltaX, double deltaY)); + int argc, Tcl_Obj *CONST objv[]); +static void TextDeleteChars(Tk_Canvas canvas, + Tk_Item *itemPtr, int first, int last); +static void TextInsert(Tk_Canvas canvas, + Tk_Item *itemPtr, int beforeThis, char *string); +static int TextToArea(Tk_Canvas canvas, + Tk_Item *itemPtr, double *rectPtr); +static double TextToPoint(Tk_Canvas canvas, + Tk_Item *itemPtr, double *pointPtr); +static int TextToPostscript(Tcl_Interp *interp, + Tk_Canvas canvas, Tk_Item *itemPtr, int prepass); +static void TranslateText(Tk_Canvas canvas, + Tk_Item *itemPtr, double deltaX, double deltaY); /* - * The structures below defines the rectangle and oval item types - * by means of procedures that can be invoked by generic item code. + * The structures below defines the rectangle and oval item types by means of + * functions that can be invoked by generic item code. */ Tk_ItemType tkTextType = { @@ -202,7 +197,7 @@ Tk_ItemType tkTextType = { GetSelText, /* selectionProc */ TextInsert, /* insertProc */ TextDeleteChars, /* dTextProc */ - (Tk_ItemType *) NULL, /* nextPtr */ + NULL, /* nextPtr */ }; /* @@ -210,14 +205,12 @@ Tk_ItemType tkTextType = { * * CreateText -- * - * This procedure is invoked to create a new text item - * in a canvas. + * This function is invoked to create a new text item in a canvas. * * Results: - * A standard Tcl return value. If an error occurred in - * creating the item then an error message is left in - * the interp's result; in this case itemPtr is left uninitialized - * so it can be safely freed by the caller. + * A standard Tcl return value. If an error occurred in creating the item + * then an error message is left in the interp's result; in this case + * itemPtr is left uninitialized so it can be safely freed by the caller. * * Side effects: * A new text item is created. @@ -226,13 +219,13 @@ Tk_ItemType tkTextType = { */ static int -CreateText(interp, canvas, itemPtr, objc, objv) - Tcl_Interp *interp; /* Interpreter for error reporting. */ - Tk_Canvas canvas; /* Canvas to hold new item. */ - Tk_Item *itemPtr; /* Record to hold new item; header has been +CreateText( + Tcl_Interp *interp, /* Interpreter for error reporting. */ + Tk_Canvas canvas, /* Canvas to hold new item. */ + 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 rectangle. */ + int objc, /* Number of arguments in objv. */ + Tcl_Obj *CONST objv[]) /* Arguments describing rectangle. */ { TextItem *textPtr = (TextItem *) itemPtr; int i; @@ -243,7 +236,7 @@ CreateText(interp, canvas, itemPtr, objc, objv) /* * Carry out initialization that is needed in order to clean up after - * errors during the the remainder of this procedure. + * errors during the the remainder of this function. */ textPtr->textInfoPtr = Tk_CanvasGetTextInfo(canvas); @@ -275,8 +268,8 @@ CreateText(interp, canvas, itemPtr, objc, objv) textPtr->cursorOffGC = None; /* - * Process the arguments to fill in the item record. - * Only 1 (list) or 2 (x y) coords are allowed. + * Process the arguments to fill in the item record. Only 1 (list) or 2 (x + * y) coords are allowed. */ if (objc == 1) { @@ -295,7 +288,7 @@ CreateText(interp, canvas, itemPtr, objc, objv) return TCL_OK; } - error: + error: DeleteText(canvas, itemPtr, Tk_Display(Tk_CanvasTkwin(canvas))); return TCL_ERROR; } @@ -305,9 +298,8 @@ CreateText(interp, canvas, itemPtr, objc, objv) * * TextCoords -- * - * This procedure is invoked to process the "coords" widget - * command on text items. See the user documentation for - * details on what it does. + * This function is invoked to process the "coords" widget command on + * text items. See the user documentation for details on what it does. * * Results: * Returns TCL_OK or TCL_ERROR, and sets the interp's result. @@ -319,18 +311,19 @@ CreateText(interp, canvas, itemPtr, objc, objv) */ static int -TextCoords(interp, canvas, itemPtr, objc, objv) - Tcl_Interp *interp; /* Used for error reporting. */ - Tk_Canvas canvas; /* Canvas containing item. */ - Tk_Item *itemPtr; /* Item whose coordinates are to be read or +TextCoords( + Tcl_Interp *interp, /* Used for error reporting. */ + Tk_Canvas canvas, /* Canvas containing item. */ + 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, ... */ + int objc, /* Number of coordinates supplied in objv. */ + Tcl_Obj *CONST objv[]) /* Array of coordinates: x1, y1, x2, y2, ... */ { TextItem *textPtr = (TextItem *) itemPtr; if (objc == 0) { Tcl_Obj *obj = Tcl_NewObj(); + Tcl_Obj *subobj = Tcl_NewDoubleObj(textPtr->x); Tcl_ListObjAppendElement(interp, obj, subobj); subobj = Tcl_NewDoubleObj(textPtr->y); @@ -357,7 +350,7 @@ TextCoords(interp, canvas, itemPtr, objc, objv) ComputeTextBbox(canvas, textPtr); } else { 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; @@ -370,28 +363,28 @@ TextCoords(interp, canvas, itemPtr, objc, objv) * * ConfigureText -- * - * This procedure is invoked to configure various aspects - * of a text item, such as its border and background colors. + * This function is invoked to configure various aspects of a text item, + * such as its border and background colors. * * Results: - * A standard Tcl result code. If an error occurs, then - * an error message is left in the interp's result. + * A standard Tcl result code. If an error occurs, then an error message + * is left in the interp's result. * * Side effects: - * Configuration information, such as colors and stipple - * patterns, may be set for itemPtr. + * Configuration information, such as colors and stipple patterns, may be + * set for itemPtr. * *-------------------------------------------------------------- */ static int -ConfigureText(interp, canvas, itemPtr, objc, objv, flags) - Tcl_Interp *interp; /* Interpreter for error reporting. */ - Tk_Canvas canvas; /* Canvas containing itemPtr. */ - Tk_Item *itemPtr; /* Rectangle item to reconfigure. */ - int objc; /* Number of elements in objv. */ - Tcl_Obj *CONST objv[]; /* Arguments describing things to configure. */ - int flags; /* Flags to pass to Tk_ConfigureWidget. */ +ConfigureText( + Tcl_Interp *interp, /* Interpreter for error reporting. */ + Tk_Canvas canvas, /* Canvas containing itemPtr. */ + Tk_Item *itemPtr, /* Rectangle item to reconfigure. */ + int objc, /* Number of elements in objv. */ + Tcl_Obj *CONST objv[], /* Arguments describing things to configure. */ + int flags) /* Flags to pass to Tk_ConfigureWidget. */ { TextItem *textPtr = (TextItem *) itemPtr; XGCValues gcValues; @@ -411,8 +404,8 @@ ConfigureText(interp, canvas, itemPtr, objc, objv, flags) } /* - * A few of the options require additional processing, such as - * graphics contexts. + * A few of the options require additional processing, such as graphics + * contexts. */ state = itemPtr->state; @@ -497,14 +490,14 @@ ConfigureText(interp, canvas, itemPtr, objc, objv, flags) /* - * If the text was changed, move the selection and insertion indices - * to keep them inside the item. + * If the text was changed, move the selection and insertion indices to + * keep them inside the item. */ textPtr->numBytes = strlen(textPtr->text); textPtr->numChars = Tcl_NumUtfChars(textPtr->text, textPtr->numBytes); if (textInfoPtr->selItemPtr == itemPtr) { - + if (textInfoPtr->selectFirst >= textPtr->numChars) { textInfoPtr->selItemPtr = NULL; } else { @@ -530,8 +523,8 @@ ConfigureText(interp, canvas, itemPtr, objc, objv, flags) * * DeleteText -- * - * This procedure is called to clean up the data structure - * associated with a text item. + * This function is called to clean up the data structure associated with + * a text item. * * Results: * None. @@ -543,10 +536,10 @@ ConfigureText(interp, canvas, itemPtr, objc, objv, flags) */ static void -DeleteText(canvas, itemPtr, display) - Tk_Canvas canvas; /* Info about overall canvas widget. */ - Tk_Item *itemPtr; /* Item that is being deleted. */ - Display *display; /* Display containing window for canvas. */ +DeleteText( + Tk_Canvas canvas, /* Info about overall canvas widget. */ + Tk_Item *itemPtr, /* Item that is being deleted. */ + Display *display) /* Display containing window for canvas. */ { TextItem *textPtr = (TextItem *) itemPtr; @@ -590,26 +583,25 @@ DeleteText(canvas, itemPtr, display) * * ComputeTextBbox -- * - * This procedure is invoked to compute the bounding box of - * all the pixels that may be drawn as part of a text item. - * In addition, it recomputes all of the geometry information - * used to display a text item or check for mouse hits. + * This function is invoked to compute the bounding box of all the pixels + * that may be drawn as part of a text item. In addition, it recomputes + * all of the geometry information used to display a text item or check + * for mouse hits. * * Results: * None. * * Side effects: - * The fields x1, y1, x2, and y2 are updated in the header - * for itemPtr, and the linePtr structure is regenerated - * for itemPtr. + * The fields x1, y1, x2, and y2 are updated in the header for itemPtr, + * and the linePtr structure is regenerated for itemPtr. * *-------------------------------------------------------------- */ static void -ComputeTextBbox(canvas, textPtr) - Tk_Canvas canvas; /* Canvas that contains item. */ - TextItem *textPtr; /* Item whose bbox is to be recomputed. */ +ComputeTextBbox( + Tk_Canvas canvas, /* Canvas that contains item. */ + TextItem *textPtr) /* Item whose bbox is to be recomputed. */ { Tk_CanvasTextInfo *textInfoPtr; int leftX, topY, width, height, fudge; @@ -629,57 +621,56 @@ ComputeTextBbox(canvas, textPtr) } /* - * Use overall geometry information to compute the top-left corner - * of the bounding box for the text item. + * Use overall geometry information to compute the top-left corner of the + * bounding box for the text item. */ leftX = (int) floor(textPtr->x + 0.5); topY = (int) floor(textPtr->y + 0.5); switch (textPtr->anchor) { - case TK_ANCHOR_NW: - case TK_ANCHOR_N: - case TK_ANCHOR_NE: - break; - - case TK_ANCHOR_W: - case TK_ANCHOR_CENTER: - case TK_ANCHOR_E: - topY -= height / 2; - break; - - case TK_ANCHOR_SW: - case TK_ANCHOR_S: - case TK_ANCHOR_SE: - topY -= height; - break; + case TK_ANCHOR_NW: + case TK_ANCHOR_N: + case TK_ANCHOR_NE: + break; + + case TK_ANCHOR_W: + case TK_ANCHOR_CENTER: + case TK_ANCHOR_E: + topY -= height / 2; + break; + + case TK_ANCHOR_SW: + case TK_ANCHOR_S: + case TK_ANCHOR_SE: + topY -= height; + break; } switch (textPtr->anchor) { - case TK_ANCHOR_NW: - case TK_ANCHOR_W: - case TK_ANCHOR_SW: - break; + case TK_ANCHOR_NW: + case TK_ANCHOR_W: + case TK_ANCHOR_SW: + break; - case TK_ANCHOR_N: - case TK_ANCHOR_CENTER: - case TK_ANCHOR_S: - leftX -= width / 2; - break; + case TK_ANCHOR_N: + case TK_ANCHOR_CENTER: + case TK_ANCHOR_S: + leftX -= width / 2; + break; - case TK_ANCHOR_NE: - case TK_ANCHOR_E: - case TK_ANCHOR_SE: - leftX -= width; - break; + case TK_ANCHOR_NE: + case TK_ANCHOR_E: + case TK_ANCHOR_SE: + leftX -= width; + break; } textPtr->leftEdge = leftX; textPtr->rightEdge = leftX + width; /* - * Last of all, update the bounding box for the item. The item's - * bounding box includes the bounding box of all its lines, plus - * an extra fudge factor for the cursor border (which could - * potentially be quite large). + * Last of all, update the bounding box for the item. The item's bounding + * box includes the bounding box of all its lines, plus an extra fudge + * factor for the cursor border (which could potentially be quite large). */ textInfoPtr = textPtr->textInfoPtr; @@ -698,26 +689,26 @@ ComputeTextBbox(canvas, textPtr) * * DisplayCanvText -- * - * This procedure is invoked to draw a text item in a given - * drawable. + * This function is invoked to draw a text item in a given drawable. * * Results: * None. * * Side effects: - * ItemPtr is drawn in drawable using the transformation - * information in canvas. + * ItemPtr is drawn in drawable using the transformation information in + * canvas. * *-------------------------------------------------------------- */ static void -DisplayCanvText(canvas, itemPtr, display, drawable, x, y, width, height) - Tk_Canvas canvas; /* Canvas that contains item. */ - Tk_Item *itemPtr; /* Item to be displayed. */ - Display *display; /* Display on which to draw item. */ - Drawable drawable; /* Pixmap or window in which to draw item. */ - int x, y, width, height; /* Describes region of canvas that must be +DisplayCanvText( + Tk_Canvas canvas, /* Canvas that contains item. */ + Tk_Item *itemPtr, /* Item to be displayed. */ + Display *display, /* Display on which to draw item. */ + Drawable drawable, /* Pixmap or window in which to draw item. */ + int x, int y, int width, int height) + /* Describes region of canvas that must be * redisplayed (not used). */ { TextItem *textPtr; @@ -749,8 +740,8 @@ DisplayCanvText(canvas, itemPtr, display, drawable, x, y, width, height) } /* - * If we're stippling, then modify the stipple offset in the GC. Be - * sure to reset the offset when done, since the GC is supposed to be + * If we're stippling, then modify the stipple offset in the GC. Be sure + * to reset the offset when done, since the GC is supposed to be * read-only. */ @@ -792,7 +783,7 @@ DisplayCanvText(canvas, itemPtr, display, drawable, x, y, width, height) for (y = yFirst ; y <= yLast; y += height) { if (y == yLast) { width = xLast + wLast - x; - } else { + } else { width = textPtr->rightEdge - textPtr->leftEdge - x; } Tk_CanvasDrawableCoords(canvas, @@ -811,11 +802,11 @@ DisplayCanvText(canvas, itemPtr, display, drawable, x, y, width, height) /* * If the insertion point should be displayed, then draw a special - * background for the cursor before drawing the text. Note: if - * we're the cursor item but the cursor is turned off, then redraw - * background over the area of the cursor. This guarantees that - * the selection won't make the cursor invisible on mono displays, - * where both are drawn in the same color. + * background for the cursor before drawing the text. Note: if we're the + * cursor item but the cursor is turned off, then redraw background over + * the area of the cursor. This guarantees that the selection won't make + * the cursor invisible on mono displays, where both are drawn in the same + * color. */ if ((textInfoPtr->focusItemPtr == itemPtr) && (textInfoPtr->gotFocus)) { @@ -836,11 +827,10 @@ DisplayCanvText(canvas, itemPtr, display, drawable, x, y, width, height) textInfoPtr->insertBorderWidth, TK_RELIEF_RAISED); } else if (textPtr->cursorOffGC != None) { /* - * Redraw the background over the area of the cursor, - * even though the cursor is turned off. This - * guarantees that the selection won't make the cursor - * invisible on mono displays, where both may be drawn - * in the same color. + * Redraw the background over the area of the cursor, even + * though the cursor is turned off. This guarantees that the + * selection won't make the cursor invisible on mono displays, + * where both may be drawn in the same color. */ XFillRectangle(display, drawable, textPtr->cursorOffGC, @@ -851,16 +841,14 @@ DisplayCanvText(canvas, itemPtr, display, drawable, x, y, width, height) } } - /* - * If there is no selected text or the selected text foreground - * is the same as the regular text foreground, then draw one - * text string. If there is selected text and the foregrounds - * differ, draw the regular text up to the selection, draw - * the selection, then draw the rest of the regular text. - * Drawing the regular text and then the selected text over - * it would causes problems with anti-aliased text because the - * two anti-aliasing colors would blend together. + * If there is no selected text or the selected text foreground is the + * same as the regular text foreground, then draw one text string. If + * there is selected text and the foregrounds differ, draw the regular + * text up to the selection, draw the selection, then draw the rest of the + * regular text. Drawing the regular text and then the selected text over + * it would causes problems with anti-aliased text because the two + * anti-aliasing colors would blend together. */ Tk_CanvasDrawableCoords(canvas, (double) textPtr->leftEdge, @@ -895,20 +883,19 @@ DisplayCanvText(canvas, itemPtr, display, drawable, x, y, width, height) * None. * * Side effects: - * The text in the given item is modified. The cursor and - * selection positions are also modified to reflect the - * insertion. + * The text in the given item is modified. The cursor and selection + * positions are also modified to reflect the insertion. * *-------------------------------------------------------------- */ static void -TextInsert(canvas, itemPtr, index, string) - Tk_Canvas canvas; /* Canvas containing text item. */ - Tk_Item *itemPtr; /* Text item to be modified. */ - int index; /* Character index before which string is - * to be inserted. */ - char *string; /* New characters to be inserted. */ +TextInsert( + Tk_Canvas canvas, /* Canvas containing text item. */ + Tk_Item *itemPtr, /* Text item to be modified. */ + int index, /* Character index before which string is to + * be inserted. */ + char *string) /* New characters to be inserted. */ { TextItem *textPtr = (TextItem *) itemPtr; int byteIndex, byteCount, charsAdded; @@ -944,7 +931,7 @@ TextInsert(canvas, itemPtr, index, string) /* * Inserting characters invalidates indices such as those for the - * selection and cursor. Update the indices appropriately. + * selection and cursor. Update the indices appropriately. */ if (textInfoPtr->selItemPtr == itemPtr) { @@ -976,21 +963,20 @@ TextInsert(canvas, itemPtr, index, string) * None. * * Side effects: - * Characters between "first" and "last", inclusive, get - * deleted from itemPtr, and things like the selection - * position get updated. + * Characters between "first" and "last", inclusive, get deleted from + * itemPtr, and things like the selection position get updated. * *-------------------------------------------------------------- */ static void -TextDeleteChars(canvas, itemPtr, first, last) - Tk_Canvas canvas; /* Canvas containing itemPtr. */ - Tk_Item *itemPtr; /* Item in which to delete characters. */ - int first; /* Character index of first character to +TextDeleteChars( + Tk_Canvas canvas, /* Canvas containing itemPtr. */ + Tk_Item *itemPtr, /* Item in which to delete characters. */ + int first, /* Character index of first character to * delete. */ - int last; /* Character index of last character to - * delete (inclusive). */ + int last) /* Character index of last character to delete + * (inclusive). */ { TextItem *textPtr = (TextItem *) itemPtr; int byteIndex, byteCount, charsRemoved; @@ -1012,7 +998,7 @@ TextDeleteChars(canvas, itemPtr, first, last) byteIndex = Tcl_UtfAtIndex(text, first) - text; byteCount = Tcl_UtfAtIndex(text + byteIndex, charsRemoved) - (text + byteIndex); - + new = (char *) ckalloc((unsigned) (textPtr->numBytes + 1 - byteCount)); memcpy(new, text, (size_t) byteIndex); strcpy(new + byteIndex, text + byteIndex + byteCount); @@ -1023,8 +1009,8 @@ TextDeleteChars(canvas, itemPtr, first, last) textPtr->numBytes -= byteCount; /* - * Update indexes for the selection and cursor to reflect the - * renumbering of the remaining characters. + * Update indexes for the selection and cursor to reflect the renumbering + * of the remaining characters. */ if (textInfoPtr->selItemPtr == itemPtr) { @@ -1066,14 +1052,14 @@ TextDeleteChars(canvas, itemPtr, first, last) * * TextToPoint -- * - * Computes the distance from a given point to a given - * text item, in canvas units. + * Computes the distance from a given point to a given text item, in + * canvas units. * * Results: - * The return value is 0 if the point whose x and y coordinates - * are pointPtr[0] and pointPtr[1] is inside the text item. If - * the point isn't inside the text item then the return value - * is the distance from the point to the text item. + * The return value is 0 if the point whose x and y coordinates are + * pointPtr[0] and pointPtr[1] is inside the text item. If the point + * isn't inside the text item then the return value is the distance from + * the point to the text item. * * Side effects: * None. @@ -1082,10 +1068,10 @@ TextDeleteChars(canvas, itemPtr, first, last) */ static double -TextToPoint(canvas, itemPtr, pointPtr) - Tk_Canvas canvas; /* Canvas containing itemPtr. */ - Tk_Item *itemPtr; /* Item to check against point. */ - double *pointPtr; /* Pointer to x and y coordinates. */ +TextToPoint( + Tk_Canvas canvas, /* Canvas containing itemPtr. */ + Tk_Item *itemPtr, /* Item to check against point. */ + double *pointPtr) /* Pointer to x and y coordinates. */ { TextItem *textPtr; Tk_State state = itemPtr->state; @@ -1111,14 +1097,13 @@ TextToPoint(canvas, itemPtr, pointPtr) * * TextToArea -- * - * This procedure is called to determine whether an item - * lies entirely inside, entirely outside, or overlapping - * a given rectangle. + * This function is called to determine whether an item lies entirely + * inside, entirely outside, or overlapping a given rectangle. * * Results: - * -1 is returned if the item is entirely outside the area - * given by rectPtr, 0 if it overlaps, and 1 if it is entirely - * inside the given area. + * -1 is returned if the item is entirely outside the area given by + * rectPtr, 0 if it overlaps, and 1 if it is entirely inside the given + * area. * * Side effects: * None. @@ -1127,11 +1112,11 @@ TextToPoint(canvas, itemPtr, pointPtr) */ static int -TextToArea(canvas, itemPtr, rectPtr) - Tk_Canvas canvas; /* Canvas containing itemPtr. */ - Tk_Item *itemPtr; /* Item to check against rectangle. */ - double *rectPtr; /* Pointer to array of four coordinates - * (x1, y1, x2, y2) describing rectangular +TextToArea( + Tk_Canvas canvas, /* Canvas containing itemPtr. */ + Tk_Item *itemPtr, /* Item to check against rectangle. */ + double *rectPtr) /* Pointer to array of four coordinates + * (x1,y1,x2,y2) describing rectangular * area. */ { TextItem *textPtr; @@ -1154,26 +1139,27 @@ TextToArea(canvas, itemPtr, rectPtr) * * ScaleText -- * - * This procedure is invoked to rescale a text item. + * This function is invoked to rescale a text item. * * Results: * None. * * Side effects: - * Scales the position of the text, but not the size - * of the font for the text. + * Scales the position of the text, but not the size of the font for the + * text. * *-------------------------------------------------------------- */ /* ARGSUSED */ static void -ScaleText(canvas, itemPtr, originX, originY, scaleX, scaleY) - Tk_Canvas canvas; /* Canvas containing rectangle. */ - Tk_Item *itemPtr; /* Rectangle to be scaled. */ - double originX, originY; /* Origin about which to scale rect. */ - double scaleX; /* Amount to scale in X direction. */ - double scaleY; /* Amount to scale in Y direction. */ +ScaleText( + Tk_Canvas canvas, /* Canvas containing rectangle. */ + Tk_Item *itemPtr, /* Rectangle to be scaled. */ + double originX, double originY, + /* Origin about which to scale rect. */ + double scaleX, /* Amount to scale in X direction. */ + double scaleY) /* Amount to scale in Y direction. */ { TextItem *textPtr = (TextItem *) itemPtr; @@ -1188,25 +1174,24 @@ ScaleText(canvas, itemPtr, originX, originY, scaleX, scaleY) * * TranslateText -- * - * This procedure is called to move a text item by a - * given amount. + * This function is called to move a text item by a given amount. * * Results: * None. * * Side effects: - * The position of the text item is offset by (xDelta, yDelta), - * and the bounding box is updated in the generic part of the - * item structure. + * The position of the text item is offset by (xDelta, yDelta), and the + * bounding box is updated in the generic part of the item structure. * *-------------------------------------------------------------- */ static void -TranslateText(canvas, itemPtr, deltaX, deltaY) - Tk_Canvas canvas; /* Canvas containing item. */ - Tk_Item *itemPtr; /* Item that is being moved. */ - double deltaX, deltaY; /* Amount by which item is to be moved. */ +TranslateText( + Tk_Canvas canvas, /* Canvas containing item. */ + Tk_Item *itemPtr, /* Item that is being moved. */ + double deltaX, double deltaY) + /* Amount by which item is to be moved. */ { TextItem *textPtr = (TextItem *) itemPtr; @@ -1220,14 +1205,13 @@ TranslateText(canvas, itemPtr, deltaX, deltaY) * * GetTextIndex -- * - * Parse an index into a text item and return either its value - * or an error. + * Parse an index into a text item and return either its value or an + * error. * * Results: - * A standard Tcl result. If all went well, then *indexPtr is - * filled in with the index (into itemPtr) corresponding to - * string. Otherwise an error message is left in - * the interp's result. + * A standard Tcl result. If all went well, then *indexPtr is filled in + * with the index (into itemPtr) corresponding to string. Otherwise an + * error message is left in the interp's result. * * Side effects: * None. @@ -1236,14 +1220,14 @@ TranslateText(canvas, itemPtr, deltaX, deltaY) */ static int -GetTextIndex(interp, canvas, itemPtr, obj, indexPtr) - Tcl_Interp *interp; /* Used for error reporting. */ - Tk_Canvas canvas; /* Canvas containing item. */ - Tk_Item *itemPtr; /* Item for which the index is being +GetTextIndex( + Tcl_Interp *interp, /* Used for error reporting. */ + Tk_Canvas canvas, /* Canvas containing item. */ + Tk_Item *itemPtr, /* Item for which the index is being * specified. */ - Tcl_Obj *obj; /* Specification of a particular character - * in itemPtr's text. */ - int *indexPtr; /* Where to store converted character + Tcl_Obj *obj, /* Specification of a particular character in + * itemPtr's text. */ + int *indexPtr) /* Where to store converted character * index. */ { TextItem *textPtr = (TextItem *) itemPtr; @@ -1294,7 +1278,7 @@ GetTextIndex(interp, canvas, itemPtr, obj, indexPtr) *indexPtr = Tk_PointToChar(textPtr->textLayout, x + canvasPtr->scrollX1 - textPtr->leftEdge, y + canvasPtr->scrollY1 - textPtr->header.y1); - } else if (Tcl_GetIntFromObj((Tcl_Interp *)NULL, obj, indexPtr) == TCL_OK) { + } else if (Tcl_GetIntFromObj(NULL, obj, indexPtr) == TCL_OK) { if (*indexPtr < 0){ *indexPtr = 0; } else if (*indexPtr > textPtr->numChars) { @@ -1302,14 +1286,13 @@ GetTextIndex(interp, canvas, itemPtr, obj, indexPtr) } } else { /* - * Some of the paths here leave messages in the interp's result, - * so we have to clear it out before storing our own message. + * Some of the paths here leave messages in the interp's result, so we + * have to clear it out before storing our own message. */ - badIndex: - Tcl_SetResult(interp, (char *) NULL, TCL_STATIC); - Tcl_AppendResult(interp, "bad index \"", string, "\"", - (char *) NULL); + badIndex: + Tcl_SetResult(interp, NULL, TCL_STATIC); + Tcl_AppendResult(interp, "bad index \"", string, "\"", NULL); return TCL_ERROR; } return TCL_OK; @@ -1333,11 +1316,11 @@ GetTextIndex(interp, canvas, itemPtr, obj, indexPtr) /* ARGSUSED */ static void -SetTextCursor(canvas, itemPtr, index) - Tk_Canvas canvas; /* Record describing canvas widget. */ - Tk_Item *itemPtr; /* Text item in which cursor position is to - * be set. */ - int index; /* Character index of character just before +SetTextCursor( + Tk_Canvas canvas, /* Record describing canvas widget. */ + Tk_Item *itemPtr, /* Text item in which cursor position is to be + * set. */ + int index) /* Character index of character just before * which cursor is to be positioned. */ { TextItem *textPtr = (TextItem *) itemPtr; @@ -1356,15 +1339,14 @@ SetTextCursor(canvas, itemPtr, index) * * GetSelText -- * - * This procedure is invoked to return the selected portion - * of a text item. It is only called when this item has - * the selection. + * This function is invoked to return the selected portion of a text + * item. It is only called when this item has the selection. * * Results: - * The return value is the number of non-NULL bytes stored - * at buffer. Buffer is filled (or partially filled) with a - * NULL-terminated string containing part or all of the selection, - * as given by offset and maxBytes. + * The return value is the number of non-NULL bytes stored at buffer. + * Buffer is filled (or partially filled) with a NULL-terminated string + * containing part or all of the selection, as given by offset and + * maxBytes. * * Side effects: * None. @@ -1373,18 +1355,18 @@ SetTextCursor(canvas, itemPtr, index) */ static int -GetSelText(canvas, itemPtr, offset, buffer, maxBytes) - Tk_Canvas canvas; /* Canvas containing selection. */ - Tk_Item *itemPtr; /* Text item containing selection. */ - int offset; /* Byte offset within selection of first +GetSelText( + Tk_Canvas canvas, /* Canvas containing selection. */ + Tk_Item *itemPtr, /* Text item containing selection. */ + int offset, /* Byte offset within selection of first * character to be returned. */ - char *buffer; /* Location in which to place selection. */ - int maxBytes; /* Maximum number of bytes to place at - * buffer, not including terminating NULL + char *buffer, /* Location in which to place selection. */ + int maxBytes) /* Maximum number of bytes to place at buffer, + * not including terminating NULL * character. */ { TextItem *textPtr = (TextItem *) itemPtr; - int byteCount; + int byteCount; char *text; CONST char *selStart, *selEnd; Tk_CanvasTextInfo *textInfoPtr = textPtr->textInfoPtr; @@ -1414,15 +1396,13 @@ GetSelText(canvas, itemPtr, offset, buffer, maxBytes) * * TextToPostscript -- * - * This procedure is called to generate Postscript for - * text items. + * This function is called to generate Postscript for text items. * * Results: - * The return value is a standard Tcl result. If an error - * occurs in generating Postscript then an error message is - * left in the interp's result, replacing whatever used - * to be there. If no error occurs, then Postscript for the - * item is appended to the result. + * The return value is a standard Tcl result. If an error occurs in + * generating Postscript then an error message is left in the interp's + * result, replacing whatever used to be there. If no error occurs, then + * Postscript for the item is appended to the result. * * Side effects: * None. @@ -1431,13 +1411,13 @@ GetSelText(canvas, itemPtr, offset, buffer, maxBytes) */ static int -TextToPostscript(interp, canvas, itemPtr, prepass) - Tcl_Interp *interp; /* Leave Postscript or error message here. */ - Tk_Canvas canvas; /* Information about overall canvas. */ - Tk_Item *itemPtr; /* Item for which Postscript is wanted. */ - int prepass; /* 1 means this is a prepass to collect - * font information; 0 means final Postscript - * is being created. */ +TextToPostscript( + Tcl_Interp *interp, /* Leave Postscript or error message here. */ + Tk_Canvas canvas, /* Information about overall canvas. */ + Tk_Item *itemPtr, /* Item for which Postscript is wanted. */ + int prepass) /* 1 means this is a prepass to collect font + * information; 0 means final Postscript is + * being created. */ { TextItem *textPtr = (TextItem *) itemPtr; int x, y; @@ -1448,7 +1428,7 @@ TextToPostscript(interp, canvas, itemPtr, prepass) Pixmap stipple; Tk_State state = itemPtr->state; - if(state == TK_STATE_NULL) { + if (state == TK_STATE_NULL) { state = ((TkCanvas *)canvas)->canvas_state; } color = textPtr->color; @@ -1482,41 +1462,48 @@ TextToPostscript(interp, canvas, itemPtr, prepass) return TCL_ERROR; } if (stipple != None) { - Tcl_AppendResult(interp, "/StippleText {\n ", - (char *) NULL); + Tcl_AppendResult(interp, "/StippleText {\n ", NULL); Tk_CanvasPsStipple(interp, canvas, stipple); - Tcl_AppendResult(interp, "} bind def\n", (char *) NULL); + Tcl_AppendResult(interp, "} bind def\n", NULL); } sprintf(buffer, "%.15g %.15g [\n", textPtr->x, Tk_CanvasPsY(canvas, textPtr->y)); - Tcl_AppendResult(interp, buffer, (char *) NULL); + Tcl_AppendResult(interp, buffer, NULL); Tk_TextLayoutToPostscript(interp, textPtr->textLayout); x = 0; y = 0; justify = NULL; /* lint. */ switch (textPtr->anchor) { - case TK_ANCHOR_NW: x = 0; y = 0; break; - case TK_ANCHOR_N: x = 1; y = 0; break; - case TK_ANCHOR_NE: x = 2; y = 0; break; - case TK_ANCHOR_E: x = 2; y = 1; break; - case TK_ANCHOR_SE: x = 2; y = 2; break; - case TK_ANCHOR_S: x = 1; y = 2; break; - case TK_ANCHOR_SW: x = 0; y = 2; break; - case TK_ANCHOR_W: x = 0; y = 1; break; - case TK_ANCHOR_CENTER: x = 1; y = 1; break; + case TK_ANCHOR_NW: x = 0; y = 0; break; + case TK_ANCHOR_N: x = 1; y = 0; break; + case TK_ANCHOR_NE: x = 2; y = 0; break; + case TK_ANCHOR_E: x = 2; y = 1; break; + case TK_ANCHOR_SE: x = 2; y = 2; break; + case TK_ANCHOR_S: x = 1; y = 2; break; + case TK_ANCHOR_SW: x = 0; y = 2; break; + case TK_ANCHOR_W: x = 0; y = 1; break; + case TK_ANCHOR_CENTER: x = 1; y = 1; break; } switch (textPtr->justify) { - case TK_JUSTIFY_LEFT: justify = "0"; break; - case TK_JUSTIFY_CENTER: justify = "0.5";break; - case TK_JUSTIFY_RIGHT: justify = "1"; break; + case TK_JUSTIFY_LEFT: justify = "0"; break; + case TK_JUSTIFY_CENTER: justify = "0.5"; break; + case TK_JUSTIFY_RIGHT: justify = "1"; break; } Tk_GetFontMetrics(textPtr->tkfont, &fm); sprintf(buffer, "] %d %g %g %s %s DrawText\n", fm.linespace, x / -2.0, y / 2.0, justify, ((stipple == None) ? "false" : "true")); - Tcl_AppendResult(interp, buffer, (char *) NULL); + Tcl_AppendResult(interp, buffer, NULL); return TCL_OK; } + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ diff --git a/generic/tkCanvUtil.c b/generic/tkCanvUtil.c index c249243..8cad646 100644 --- a/generic/tkCanvUtil.c +++ b/generic/tkCanvUtil.c @@ -1,7 +1,7 @@ /* * tkCanvUtil.c -- * - * This procedure contains a collection of utility procedures used by the + * This file contains a collection of utility functions used by the * implementations of various canvas item types. * * Copyright (c) 1994 Sun Microsystems, Inc. @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkCanvUtil.c,v 1.13 2005/10/17 20:23:29 dkf Exp $ + * RCS: @(#) $Id: tkCanvUtil.c,v 1.14 2005/11/04 15:23:05 dkf Exp $ */ #include "tkInt.h" @@ -60,7 +60,7 @@ static void TranslateAndAppendCoords(TkCanvas *canvPtr, * * Tk_CanvasTkwin -- * - * Given a token for a canvas, this procedure returns the widget that + * Given a token for a canvas, this function returns the widget that * represents the canvas. * * Results: @@ -85,7 +85,7 @@ Tk_CanvasTkwin( * * Tk_CanvasDrawableCoords -- * - * Given an (x,y) coordinate pair within a canvas, this procedure + * Given an (x,y) coordinate pair within a canvas, this function * returns the corresponding coordinates at which the point should * be drawn in the drawable used for display. * @@ -146,7 +146,7 @@ Tk_CanvasDrawableCoords( * * Tk_CanvasWindowCoords -- * - * Given an (x,y) coordinate pair within a canvas, this procedure returns + * Given an (x,y) coordinate pair within a canvas, this function returns * the corresponding coordinates in the canvas's window. * * Results: @@ -282,7 +282,7 @@ Tk_CanvasGetCoordFromObj( * * Tk_CanvasSetStippleOrigin -- * - * This procedure sets the stipple origin in a graphics context so that + * This function sets the stipple origin in a graphics context so that * stipples drawn with the GC will line up with other stipples previously * drawn in the canvas. * @@ -313,7 +313,7 @@ Tk_CanvasSetStippleOrigin( * * Tk_CanvasSetOffset-- * - * This procedure sets the stipple offset in a graphics context so that + * This function sets the stipple offset in a graphics context so that * stipples drawn with the GC will line up with other stipples with the * same offset. * @@ -357,7 +357,7 @@ Tk_CanvasSetOffset( * * Tk_CanvasGetTextInfo -- * - * This procedure returns a pointer to a structure containing information + * This function returns a pointer to a structure containing information * about the selection and insertion cursor for a canvas widget. Items * such as text items save the pointer and use it to share access to the * information with the generic canvas code. @@ -386,7 +386,7 @@ Tk_CanvasGetTextInfo( * * Tk_CanvasTagsParseProc -- * - * This procedure is invoked during option processing to handle "-tags" + * This function is invoked during option processing to handle "-tags" * options for canvas items. * * Results: @@ -449,14 +449,14 @@ Tk_CanvasTagsParseProc( * * Tk_CanvasTagsPrintProc -- * - * This procedure is invoked by the Tk configuration code to produce a + * This function is invoked by the Tk configuration code to produce a * printable string for the "-tags" configuration option for canvas * items. * * Results: * The return value is a string describing all the tags for the item * referred to by "widgRec". In addition, *freeProcPtr is filled in with - * the address of a procedure to call to free the result string when it's + * the address of a function to call to free the result string when it's * no longer needed (or NULL to indicate that the string doesn't need to * be freed). * @@ -479,11 +479,11 @@ Tk_CanvasTagsPrintProc( register Tk_Item *itemPtr = (Tk_Item *) widgRec; if (itemPtr->numTags == 0) { - *freeProcPtr = (Tcl_FreeProc *) NULL; + *freeProcPtr = NULL; return ""; } if (itemPtr->numTags == 1) { - *freeProcPtr = (Tcl_FreeProc *) NULL; + *freeProcPtr = NULL; return (char *) itemPtr->tagPtr[0]; } *freeProcPtr = TCL_DYNAMIC; @@ -495,7 +495,7 @@ Tk_CanvasTagsPrintProc( * * TkCanvasDashParseProc -- * - * This procedure is invoked during option processing to handle "-dash", + * This function is invoked during option processing to handle "-dash", * "-activedash" and "-disableddash" options for canvas objects. * * Results: @@ -525,14 +525,14 @@ TkCanvasDashParseProc( * * TkCanvasDashPrintProc -- * - * This procedure is invoked by the Tk configuration code to produce a + * This function is invoked by the Tk configuration code to produce a * printable string for the "-dash", "-activedash" and "-disableddash" * configuration options for canvas items. * * Results: * The return value is a string describing all the dash list for the item * referred to by "widgRec"and "offset". In addition, *freeProcPtr is - * filled in with the address of a procedure to call to free the result + * filled in with the address of a function to call to free the result * string when it's no longer needed (or NULL to indicate that the string * doesn't need to be freed). * @@ -566,7 +566,7 @@ TkCanvasDashPrintProc( buffer[i] = 0; return buffer; } else if (!i) { - *freeProcPtr = (Tcl_FreeProc *) NULL; + *freeProcPtr = NULL; return ""; } buffer = (char *)ckalloc((unsigned int) (4*i)); @@ -585,7 +585,7 @@ TkCanvasDashPrintProc( * * InitSmoothMethods -- * - * This procedure is invoked to set up the initial state of the list of + * This function is invoked to set up the initial state of the list of * "-smooth" methods. It should only be called when the list installed * in the interpreter is NULL. * @@ -628,7 +628,7 @@ InitSmoothMethods( * * Tk_CreateSmoothMethod -- * - * This procedure is invoked to add additional values for the "-smooth" + * This function is invoked to add additional values for the "-smooth" * option to the list. * * Results: @@ -648,7 +648,7 @@ Tk_CreateSmoothMethod( { SmoothAssocData *methods, *typePtr2, *prevPtr, *ptr; methods = (SmoothAssocData *) Tcl_GetAssocData(interp, "smoothMethod", - (Tcl_InterpDeleteProc **) NULL); + NULL); /* * Initialize if we were not previously initialized. @@ -687,7 +687,7 @@ Tk_CreateSmoothMethod( * * SmoothMethodCleanupProc -- * - * This procedure is invoked whenever an interpreter is deleted to + * This function is invoked whenever an interpreter is deleted to * cleanup the smooth methods. * * Results: @@ -717,7 +717,7 @@ SmoothMethodCleanupProc( * * TkSmoothParseProc -- * - * This procedure is invoked during option processing to handle the + * This function is invoked during option processing to handle the * "-smooth" option. * * Results: @@ -747,12 +747,12 @@ TkSmoothParseProc( SmoothAssocData *methods; if (value == NULL || *value == 0) { - *smoothPtr = (Tk_SmoothMethod *) NULL; + *smoothPtr = NULL; return TCL_OK; } length = strlen(value); methods = (SmoothAssocData *) Tcl_GetAssocData(interp, "smoothMethod", - (Tcl_InterpDeleteProc **) NULL); + NULL); /* * Not initialized yet; fix that now. @@ -774,11 +774,11 @@ TkSmoothParseProc( * Search the list of installed smooth methods. */ - while (methods != (SmoothAssocData *) NULL) { + while (methods != NULL) { if (strncmp(value, methods->smooth.name, length) == 0) { - if (smooth != (Tk_SmoothMethod *) NULL) { + if (smooth != NULL) { Tcl_AppendResult(interp, "ambiguous smooth method \"", value, - "\"", (char *) NULL); + "\"", NULL); return TCL_ERROR; } smooth = &methods->smooth; @@ -797,7 +797,7 @@ TkSmoothParseProc( if (Tcl_GetBoolean(interp, (char *) value, &b) != TCL_OK) { return TCL_ERROR; } - *smoothPtr = b ? &tkBezierSmoothMethod : (Tk_SmoothMethod*) NULL; + *smoothPtr = b ? &tkBezierSmoothMethod : NULL; return TCL_OK; } /* @@ -805,13 +805,13 @@ TkSmoothParseProc( * * TkSmoothPrintProc -- * - * This procedure is invoked by the Tk configuration code to produce a + * This function is invoked by the Tk configuration code to produce a * printable string for the "-smooth" configuration option. * * Results: * The return value is a string describing the smooth option for the item * referred to by "widgRec". In addition, *freeProcPtr is filled in with - * the address of a procedure to call to free the result string when it's + * the address of a function to call to free the result string when it's * no longer needed (or NULL to indicate that the string doesn't need to * be freed). * @@ -841,7 +841,7 @@ TkSmoothPrintProc( * * Tk_GetDash * - * This procedure is used to parse a string, assuming it is dash + * This function is used to parse a string, assuming it is dash * information. * * Results: @@ -865,7 +865,7 @@ Tk_GetDash( CONST char **largv, **argv = NULL; char *pt; - if ((value==(char *) NULL) || (*value==0) ) { + if ((value==NULL) || (*value==0) ) { dash->number = 0; return TCL_OK; } @@ -876,7 +876,7 @@ Tk_GetDash( switch (*value) { case '.': case ',': case '-': case '_': - i = DashConvert((char *) NULL, value, -1, 0.0); + i = DashConvert(NULL, value, -1, 0.0); if (i>0) { i = strlen(value); } else { @@ -913,7 +913,7 @@ Tk_GetDash( Tcl_ResetResult(interp); Tcl_AppendResult(interp, "expected integer in the range 1..255 but got \"", - *largv, "\"", (char *) NULL); + *largv, "\"", NULL); goto syntaxError; } *pt++ = i; @@ -933,7 +933,7 @@ Tk_GetDash( badDashList: Tcl_AppendResult(interp, "bad dash list \"", value, "\": must be a list of integers or a format like \"-..\"", - (char *) NULL); + NULL); syntaxError: if (argv != NULL) { ckfree((char *) argv); @@ -950,7 +950,7 @@ Tk_GetDash( * * Tk_CreateOutline * - * This procedure initializes the Tk_Outline structure with default + * This function initializes the Tk_Outline structure with default * values. * * Results: @@ -990,7 +990,7 @@ Tk_CreateOutline( * * Tk_DeleteOutline * - * This procedure frees all memory that might be allocated and referenced + * This function frees all memory that might be allocated and referenced * in the Tk_Outline structure. * * Results: @@ -1044,7 +1044,7 @@ Tk_DeleteOutline( * * Tk_ConfigOutlineGC * - * This procedure should be called in the canvas object during the + * This function should be called in the canvas object during the * configure command. The graphics context description in gcValues is * updated according to the information in the dash structure, as far as * possible. @@ -1437,7 +1437,7 @@ Tk_CanvasPsOutline( } } sprintf(string, "%.15g setlinewidth\n", width); - Tcl_AppendResult(interp, string, (char *) NULL); + Tcl_AppendResult(interp, string, NULL); if (dash->number > 10) { str = (char *)ckalloc((unsigned int) (1 + 4*dash->number)); @@ -1455,12 +1455,12 @@ Tk_CanvasPsOutline( while (i--) { sprintf(str+strlen(str), " %d", *ptr++ & 0xff); } - Tcl_AppendResult(interp, str, (char *)NULL); + Tcl_AppendResult(interp, str, NULL); if (dash->number&1) { - Tcl_AppendResult(interp, " ", str+1, (char *)NULL); + Tcl_AppendResult(interp, " ", str+1, NULL); } sprintf(str, "] %d setdash\n", outline->offset); - Tcl_AppendResult(interp, str, (char *)NULL); + Tcl_AppendResult(interp, str, NULL); ptr = ptr0; } else if (dash->number < 0) { if ((i = DashConvert(lptr, ptr, -dash->number, width)) != 0) { @@ -1470,15 +1470,15 @@ Tk_CanvasPsOutline( while (--i) { sprintf(str+strlen(str), " %d", *lptr++ & 0xff); } - Tcl_AppendResult(interp, str, (char *)NULL); + Tcl_AppendResult(interp, str, NULL); sprintf(str, "] %d setdash\n", outline->offset); - Tcl_AppendResult(interp, str, (char *)NULL); + Tcl_AppendResult(interp, str, NULL); lptr = lptr0; } else { - Tcl_AppendResult(interp, "[] 0 setdash\n", (char *)NULL); + Tcl_AppendResult(interp, "[] 0 setdash\n", NULL); } } else { - Tcl_AppendResult(interp, "[] 0 setdash\n", (char *)NULL); + Tcl_AppendResult(interp, "[] 0 setdash\n", NULL); } if (str != string) { ckfree(str); @@ -1490,12 +1490,12 @@ Tk_CanvasPsOutline( return TCL_ERROR; } if (stipple != None) { - Tcl_AppendResult(interp, "StrokeClip ", (char *) NULL); + Tcl_AppendResult(interp, "StrokeClip ", NULL); if (Tk_CanvasPsStipple(interp, canvas, stipple) != TCL_OK) { return TCL_ERROR; } } else { - Tcl_AppendResult(interp, "stroke\n", (char *) NULL); + Tcl_AppendResult(interp, "stroke\n", NULL); } return TCL_OK; @@ -1579,10 +1579,10 @@ DashConvert( * * This is a helper routine for TkCanvTranslatePath() below. * - * Given an (x,y) coordinate pair within a canvas, this procedure - * computes the corresponding coordinates at which the point should be - * drawn in the drawable used for display. Those coordinates are then - * written into outArr[numOut*2] and outArr[numOut*2+1]. + * Given an (x,y) coordinate pair within a canvas, this function computes + * the corresponding coordinates at which the point should be drawn in + * the drawable used for display. Those coordinates are then written into + * outArr[numOut*2] and outArr[numOut*2+1]. * * Results: * There is no return value. diff --git a/generic/tkCanvWind.c b/generic/tkCanvWind.c index a5e05c6..5950f32 100644 --- a/generic/tkCanvWind.c +++ b/generic/tkCanvWind.c @@ -1,4 +1,4 @@ -/* +/* * tkCanvWind.c -- * * This file implements window items for canvas widgets. @@ -6,10 +6,10 @@ * Copyright (c) 1992-1994 The Regents of the University of California. * Copyright (c) 1994-1997 Sun Microsystems, Inc. * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkCanvWind.c,v 1.11 2004/11/17 22:46:12 hobbs Exp $ + * RCS: @(#) $Id: tkCanvWind.c,v 1.12 2005/11/04 15:23:05 dkf Exp $ */ #include <stdio.h> @@ -51,100 +51,96 @@ static Tk_CustomOption tagsOption = { }; static Tk_ConfigSpec configSpecs[] = { - {TK_CONFIG_ANCHOR, "-anchor", (char *) NULL, (char *) NULL, + {TK_CONFIG_ANCHOR, "-anchor", NULL, NULL, "center", Tk_Offset(WindowItem, anchor), TK_CONFIG_DONT_SET_DEFAULT}, - {TK_CONFIG_PIXELS, "-height", (char *) NULL, (char *) NULL, + {TK_CONFIG_PIXELS, "-height", NULL, NULL, "0", Tk_Offset(WindowItem, height), TK_CONFIG_DONT_SET_DEFAULT}, - {TK_CONFIG_CUSTOM, "-state", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(Tk_Item, state), TK_CONFIG_NULL_OK, - &stateOption}, - {TK_CONFIG_CUSTOM, "-tags", (char *) NULL, (char *) NULL, - (char *) NULL, 0, TK_CONFIG_NULL_OK, &tagsOption}, - {TK_CONFIG_PIXELS, "-width", (char *) NULL, (char *) NULL, + {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}, - {TK_CONFIG_WINDOW, "-window", (char *) NULL, (char *) NULL, - (char *) NULL, Tk_Offset(WindowItem, tkwin), TK_CONFIG_NULL_OK}, - {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL, - (char *) NULL, 0, 0} + {TK_CONFIG_WINDOW, "-window", NULL, NULL, + NULL, Tk_Offset(WindowItem, tkwin), TK_CONFIG_NULL_OK}, + {TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0} }; /* - * Prototypes for procedures defined in this file: + * Prototypes for functions defined in this file: */ -static void ComputeWindowBbox _ANSI_ARGS_((Tk_Canvas canvas, - WindowItem *winItemPtr)); -static int ConfigureWinItem _ANSI_ARGS_((Tcl_Interp *interp, +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)); -static int CreateWinItem _ANSI_ARGS_((Tcl_Interp *interp, + 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[])); -static void DeleteWinItem _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, Display *display)); -static void DisplayWinItem _ANSI_ARGS_((Tk_Canvas canvas, + int objc, Tcl_Obj *CONST objv[]); +static void DeleteWinItem(Tk_Canvas canvas, + Tk_Item *itemPtr, Display *display); +static void DisplayWinItem(Tk_Canvas canvas, Tk_Item *itemPtr, Display *display, Drawable dst, - int x, int y, int width, int height)); -static void ScaleWinItem _ANSI_ARGS_((Tk_Canvas canvas, + int x, int y, int width, int height); +static void ScaleWinItem(Tk_Canvas canvas, Tk_Item *itemPtr, double originX, double originY, - double scaleX, double scaleY)); -static void TranslateWinItem _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, double deltaX, double deltaY)); -static int WinItemCoords _ANSI_ARGS_((Tcl_Interp *interp, + double scaleX, double scaleY); +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[])); -static void WinItemLostSlaveProc _ANSI_ARGS_(( - ClientData clientData, Tk_Window tkwin)); -static void WinItemRequestProc _ANSI_ARGS_((ClientData clientData, - Tk_Window tkwin)); -static void WinItemStructureProc _ANSI_ARGS_(( - ClientData clientData, XEvent *eventPtr)); -static int WinItemToArea _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, double *rectPtr)); -static int WinItemToPostscript _ANSI_ARGS_((Tcl_Interp *interp, - Tk_Canvas canvas, Tk_Item *itemPtr, int prepass)); -static double WinItemToPoint _ANSI_ARGS_((Tk_Canvas canvas, - Tk_Item *itemPtr, double *pointPtr)); + Tcl_Obj *CONST objv[]); +static void WinItemLostSlaveProc(ClientData clientData, + Tk_Window tkwin); +static void WinItemRequestProc(ClientData clientData, + Tk_Window tkwin); +static void WinItemStructureProc(ClientData clientData, + XEvent *eventPtr); +static int WinItemToArea(Tk_Canvas canvas, + Tk_Item *itemPtr, double *rectPtr); +static int WinItemToPostscript(Tcl_Interp *interp, + Tk_Canvas canvas, Tk_Item *itemPtr, int prepass); +static double WinItemToPoint(Tk_Canvas canvas, + Tk_Item *itemPtr, double *pointPtr); #ifdef X_GetImage -static int xerrorhandler _ANSI_ARGS_((ClientData clientData, - XErrorEvent *e)); +static int xerrorhandler(ClientData clientData, XErrorEvent *e); #endif -static int CanvasPsWindow _ANSI_ARGS_((Tcl_Interp *interp, +static int CanvasPsWindow(Tcl_Interp *interp, Tk_Window tkwin, Tk_Canvas canvas, double x, - double y, int width, int height)); + double y, int width, int height); /* - * The structure below defines the window item type by means of procedures + * The structure below defines the window item type by means of functions * that can be invoked by generic item code. */ Tk_ItemType tkWindowType = { - "window", /* name */ - sizeof(WindowItem), /* itemSize */ - CreateWinItem, /* createProc */ - configSpecs, /* configSpecs */ - ConfigureWinItem, /* configureProc */ - WinItemCoords, /* coordProc */ - DeleteWinItem, /* deleteProc */ - DisplayWinItem, /* displayProc */ - 1|TK_CONFIG_OBJS, /* flags */ - WinItemToPoint, /* pointProc */ - WinItemToArea, /* areaProc */ - WinItemToPostscript, /* postscriptProc */ - ScaleWinItem, /* scaleProc */ - TranslateWinItem, /* translateProc */ - (Tk_ItemIndexProc *) NULL, /* indexProc */ - (Tk_ItemCursorProc *) NULL, /* cursorProc */ - (Tk_ItemSelectionProc *) NULL, /* selectionProc */ - (Tk_ItemInsertProc *) NULL, /* insertProc */ - (Tk_ItemDCharsProc *) NULL, /* dTextProc */ - (Tk_ItemType *) NULL, /* nextPtr */ + "window", /* name */ + sizeof(WindowItem), /* itemSize */ + CreateWinItem, /* createProc */ + configSpecs, /* configSpecs */ + ConfigureWinItem, /* configureProc */ + WinItemCoords, /* coordProc */ + DeleteWinItem, /* deleteProc */ + DisplayWinItem, /* displayProc */ + 1|TK_CONFIG_OBJS, /* flags */ + WinItemToPoint, /* pointProc */ + WinItemToArea, /* areaProc */ + WinItemToPostscript, /* postscriptProc */ + ScaleWinItem, /* scaleProc */ + TranslateWinItem, /* translateProc */ + NULL, /* indexProc */ + NULL, /* cursorProc */ + NULL, /* selectionProc */ + NULL, /* insertProc */ + NULL, /* dTextProc */ + NULL, /* nextPtr */ }; - /* - * The structure below defines the official type record for the - * placer: + * The structure below defines the official type record for the canvas (as + * geometry manager): */ static Tk_GeomMgr canvasGeomType = { @@ -158,14 +154,12 @@ static Tk_GeomMgr canvasGeomType = { * * CreateWinItem -- * - * This procedure is invoked to create a new window - * item in a canvas. + * This function is invoked to create a new window item in a canvas. * * Results: - * A standard Tcl return value. If an error occurred in - * creating the item, then an error message is left in - * the interp's result; in this case itemPtr is - * left uninitialized, so it can be safely freed by the + * A standard Tcl return value. If an error occurred in creating the + * item, then an error message is left in the interp's result; in this + * case itemPtr is left uninitialized, so it can be safely freed by the * caller. * * Side effects: @@ -175,13 +169,13 @@ static Tk_GeomMgr canvasGeomType = { */ static int -CreateWinItem(interp, canvas, itemPtr, objc, objv) - Tcl_Interp *interp; /* Interpreter for error reporting. */ - Tk_Canvas canvas; /* Canvas to hold new item. */ - 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. */ +CreateWinItem( + Tcl_Interp *interp, /* Interpreter for error reporting. */ + Tk_Canvas canvas, /* Canvas to hold new item. */ + 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. */ { WindowItem *winItemPtr = (WindowItem *) itemPtr; int i; @@ -201,8 +195,8 @@ CreateWinItem(interp, canvas, itemPtr, objc, objv) winItemPtr->canvas = canvas; /* - * Process the arguments to fill in the item record. - * Only 1 (list) or 2 (x y) coords are allowed. + * Process the arguments to fill in the item record. Only 1 (list) or 2 (x + * y) coords are allowed. */ if (objc == 1) { @@ -222,7 +216,7 @@ CreateWinItem(interp, canvas, itemPtr, objc, objv) return TCL_OK; } - error: + error: DeleteWinItem(canvas, itemPtr, Tk_Display(Tk_CanvasTkwin(canvas))); return TCL_ERROR; } @@ -232,9 +226,8 @@ CreateWinItem(interp, canvas, itemPtr, objc, objv) * * WinItemCoords -- * - * This procedure is invoked to process the "coords" widget - * command on window items. See the user documentation for - * details on what it does. + * This function is invoked to process the "coords" widget command on + * window items. See the user documentation for details on what it does. * * Results: * Returns TCL_OK or TCL_ERROR, and sets the interp's result. @@ -246,15 +239,13 @@ CreateWinItem(interp, canvas, itemPtr, objc, objv) */ static int -WinItemCoords(interp, canvas, itemPtr, objc, objv) - Tcl_Interp *interp; /* Used for error reporting. */ - Tk_Canvas canvas; /* Canvas containing item. */ - 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, ... */ +WinItemCoords( + Tcl_Interp *interp, /* Used for error reporting. */ + Tk_Canvas canvas, /* Canvas containing item. */ + 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, ... */ { WindowItem *winItemPtr = (WindowItem *) itemPtr; @@ -299,12 +290,12 @@ WinItemCoords(interp, canvas, itemPtr, objc, objv) * * ConfigureWinItem -- * - * This procedure is invoked to configure various aspects - * of a window item, such as its anchor position. + * This function is invoked to configure various aspects of a window + * item, such as its anchor position. * * Results: - * A standard Tcl result code. If an error occurs, then - * an error message is left in the interp's result. + * A standard Tcl result code. If an error occurs, then an error message + * is left in the interp's result. * * Side effects: * Configuration information may be set for itemPtr. @@ -313,13 +304,13 @@ WinItemCoords(interp, canvas, itemPtr, objc, objv) */ static int -ConfigureWinItem(interp, canvas, itemPtr, objc, objv, flags) - Tcl_Interp *interp; /* Used for error reporting. */ - 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. */ - int flags; /* Flags to pass to Tk_ConfigureWidget. */ +ConfigureWinItem( + Tcl_Interp *interp, /* Used for error reporting. */ + 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. */ + int flags) /* Flags to pass to Tk_ConfigureWidget. */ { WindowItem *winItemPtr = (WindowItem *) itemPtr; Tk_Window oldWindow; @@ -340,8 +331,7 @@ ConfigureWinItem(interp, canvas, itemPtr, objc, objv, flags) if (oldWindow != NULL) { Tk_DeleteEventHandler(oldWindow, StructureNotifyMask, WinItemStructureProc, (ClientData) winItemPtr); - Tk_ManageGeometry(oldWindow, (Tk_GeomMgr *) NULL, - (ClientData) NULL); + Tk_ManageGeometry(oldWindow, NULL, (ClientData) NULL); Tk_UnmaintainGeometry(oldWindow, canvasTkwin); Tk_UnmapWindow(oldWindow); } @@ -349,10 +339,10 @@ ConfigureWinItem(interp, canvas, itemPtr, objc, objv, flags) Tk_Window ancestor, parent; /* - * Make sure that the canvas is either the parent of the - * window associated with the item or a descendant of that - * parent. Also, don't allow a top-of-hierarchy window to be - * managed inside a canvas. + * Make sure that the canvas is either the parent of the window + * associated with the item or a descendant of that parent. Also, + * don't allow a top-of-hierarchy window to be managed inside a + * canvas. */ parent = Tk_Parent(winItemPtr->tkwin); @@ -362,10 +352,10 @@ ConfigureWinItem(interp, canvas, itemPtr, objc, objv, flags) break; } if (((Tk_FakeWin *) (ancestor))->flags & TK_TOP_HIERARCHY) { - badWindow: + badWindow: Tcl_AppendResult(interp, "can't use ", Tk_PathName(winItemPtr->tkwin), - " in a window item of this canvas", (char *) NULL); + " in a window item of this canvas", NULL); winItemPtr->tkwin = NULL; return TCL_ERROR; } @@ -401,8 +391,8 @@ ConfigureWinItem(interp, canvas, itemPtr, objc, objv, flags) * * DeleteWinItem -- * - * This procedure is called to clean up the data structure - * associated with a window item. + * This function is called to clean up the data structure associated with + * a window item. * * Results: * None. @@ -414,11 +404,10 @@ ConfigureWinItem(interp, canvas, itemPtr, objc, objv, flags) */ static void -DeleteWinItem(canvas, itemPtr, display) - Tk_Canvas canvas; /* Overall info about widget. */ - Tk_Item *itemPtr; /* Item that is being deleted. */ - Display *display; /* Display containing window for - * canvas. */ +DeleteWinItem( + Tk_Canvas canvas, /* Overall info about widget. */ + Tk_Item *itemPtr, /* Item that is being deleted. */ + Display *display) /* Display containing window for canvas. */ { WindowItem *winItemPtr = (WindowItem *) itemPtr; Tk_Window canvasTkwin = Tk_CanvasTkwin(canvas); @@ -426,7 +415,7 @@ DeleteWinItem(canvas, itemPtr, display) if (winItemPtr->tkwin != NULL) { Tk_DeleteEventHandler(winItemPtr->tkwin, StructureNotifyMask, WinItemStructureProc, (ClientData) winItemPtr); - Tk_ManageGeometry(winItemPtr->tkwin, (Tk_GeomMgr *) NULL, + Tk_ManageGeometry(winItemPtr->tkwin, NULL, (ClientData) NULL); if (canvasTkwin != Tk_Parent(winItemPtr->tkwin)) { Tk_UnmaintainGeometry(winItemPtr->tkwin, canvasTkwin); @@ -440,26 +429,23 @@ DeleteWinItem(canvas, itemPtr, display) * * ComputeWindowBbox -- * - * This procedure is invoked to compute the bounding box of - * all the pixels that may be drawn as part of a window item. - * This procedure is where the child window's placement is - * computed. + * This function is invoked to compute the bounding box of all the pixels + * that may be drawn as part of a window item. This function is where the + * child window's placement is computed. * * Results: * None. * * Side effects: - * The fields x1, y1, x2, and y2 are updated in the header - * for itemPtr. + * The fields x1, y1, x2, and y2 are updated in the header for itemPtr. * *-------------------------------------------------------------- */ static void -ComputeWindowBbox(canvas, winItemPtr) - Tk_Canvas canvas; /* Canvas that contains item. */ - WindowItem *winItemPtr; /* Item whose bbox is to be - * recomputed. */ +ComputeWindowBbox( + Tk_Canvas canvas, /* Canvas that contains item. */ + WindowItem *winItemPtr) /* Item whose bbox is to be recomputed. */ { int width, height, x, y; Tk_State state = winItemPtr->header.state; @@ -472,10 +458,10 @@ ComputeWindowBbox(canvas, winItemPtr) } if ((winItemPtr->tkwin == NULL) || (state == TK_STATE_HIDDEN)) { /* - * There is no window for this item yet. Just give it a 1x1 - * bounding box. Don't give it a 0x0 bounding box; there are - * strange cases where this bounding box might be used as the - * dimensions of the window, and 0x0 causes problems under X. + * There is no window for this item yet. Just give it a 1x1 bounding + * box. Don't give it a 0x0 bounding box; there are strange cases + * where this bounding box might be used as the dimensions of the + * window, and 0x0 causes problems under X. */ winItemPtr->header.x1 = x; @@ -509,36 +495,36 @@ ComputeWindowBbox(canvas, winItemPtr) */ switch (winItemPtr->anchor) { - case TK_ANCHOR_N: - x -= width/2; - break; - case TK_ANCHOR_NE: - x -= width; - break; - case TK_ANCHOR_E: - x -= width; - y -= height/2; - break; - case TK_ANCHOR_SE: - x -= width; - y -= height; - break; - case TK_ANCHOR_S: - x -= width/2; - y -= height; - break; - case TK_ANCHOR_SW: - y -= height; - break; - case TK_ANCHOR_W: - y -= height/2; - break; - case TK_ANCHOR_NW: - break; - case TK_ANCHOR_CENTER: - x -= width/2; - y -= height/2; - break; + case TK_ANCHOR_N: + x -= width/2; + break; + case TK_ANCHOR_NE: + x -= width; + break; + case TK_ANCHOR_E: + x -= width; + y -= height/2; + break; + case TK_ANCHOR_SE: + x -= width; + y -= height; + break; + case TK_ANCHOR_S: + x -= width/2; + y -= height; + break; + case TK_ANCHOR_SW: + y -= height; + break; + case TK_ANCHOR_W: + y -= height/2; + break; + case TK_ANCHOR_NW: + break; + case TK_ANCHOR_CENTER: + x -= width/2; + y -= height/2; + break; } /* @@ -556,36 +542,32 @@ ComputeWindowBbox(canvas, winItemPtr) * * DisplayWinItem -- * - * This procedure is invoked to "draw" a window item in a given - * drawable. Since the window draws itself, we needn't do any - * actual redisplay here. However, this procedure takes care - * of actually repositioning the child window so that it occupies - * the correct screen position. + * This function is invoked to "draw" a window item in a given drawable. + * Since the window draws itself, we needn't do any actual redisplay + * here. However, this function takes care of actually repositioning the + * child window so that it occupies the correct screen position. * * Results: * None. * * Side effects: - * The child window's position may get changed. Note: this - * procedure gets called both when a window needs to be displayed - * and when it ceases to be visible on the screen (e.g. it was - * scrolled or moved off-screen or the enclosing canvas is - * unmapped). + * The child window's position may get changed. Note: this function gets + * called both when a window needs to be displayed and when it ceases to + * be visible on the screen (e.g. it was scrolled or moved off-screen or + * the enclosing canvas is unmapped). * *-------------------------------------------------------------- */ static void -DisplayWinItem(canvas, itemPtr, display, drawable, regionX, regionY, - regionWidth, regionHeight) - Tk_Canvas canvas; /* Canvas that contains item. */ - Tk_Item *itemPtr; /* Item to be displayed. */ - Display *display; /* Display on which to draw item. */ - Drawable drawable; /* Pixmap or window in which to draw - * item. */ - int regionX, regionY, regionWidth, regionHeight; - /* Describes region of canvas that - * must be redisplayed (not used). */ +DisplayWinItem( + Tk_Canvas canvas, /* Canvas that contains item. */ + Tk_Item *itemPtr, /* Item to be displayed. */ + Display *display, /* Display on which to draw item. */ + Drawable drawable, /* Pixmap or window in which to draw item. */ + int regionX, int regionY, int regionWidth, int regionHeight) + /* Describes region of canvas that must be + * redisplayed (not used). */ { WindowItem *winItemPtr = (WindowItem *) itemPtr; int width, height; @@ -613,16 +595,16 @@ DisplayWinItem(canvas, itemPtr, display, drawable, regionX, regionY, height = winItemPtr->header.y2 - winItemPtr->header.y1; /* - * If the window is completely out of the visible area of the canvas - * then unmap it. This code used not to be present (why unmap the - * window if it isn't visible anyway?) but this could cause the - * window to suddenly reappear if the canvas window got resized. + * If the window is completely out of the visible area of the canvas then + * unmap it. This code used not to be present (why unmap the window if it + * isn't visible anyway?) but this could cause the window to suddenly + * reappear if the canvas window got resized. */ if (((x + width) <= 0) || ((y + height) <= 0) || (x >= Tk_Width(canvasTkwin)) || (y >= Tk_Height(canvasTkwin))) { if (canvasTkwin == Tk_Parent(winItemPtr->tkwin)) { - Tk_UnmapWindow(winItemPtr->tkwin); + Tk_UnmapWindow(winItemPtr->tkwin); } else { Tk_UnmaintainGeometry(winItemPtr->tkwin, canvasTkwin); } @@ -630,8 +612,8 @@ DisplayWinItem(canvas, itemPtr, display, drawable, regionX, regionY, } /* - * Reposition and map the window (but in different ways depending - * on whether the canvas is the window's parent). + * Reposition and map the window (but in different ways depending on + * whether the canvas is the window's parent). */ if (canvasTkwin == Tk_Parent(winItemPtr->tkwin)) { @@ -652,14 +634,14 @@ DisplayWinItem(canvas, itemPtr, display, drawable, regionX, regionY, * * WinItemToPoint -- * - * Computes the distance from a given point to a given - * window, in canvas units. + * Computes the distance from a given point to a given window, in canvas + * units. * * Results: - * The return value is 0 if the point whose x and y coordinates - * are coordPtr[0] and coordPtr[1] is inside the window. If the - * point isn't inside the window then the return value is the - * distance from the point to the window. + * The return value is 0 if the point whose x and y coordinates are + * coordPtr[0] and coordPtr[1] is inside the window. If the point isn't + * inside the window then the return value is the distance from the point + * to the window. * * Side effects: * None. @@ -668,10 +650,10 @@ DisplayWinItem(canvas, itemPtr, display, drawable, regionX, regionY, */ static double -WinItemToPoint(canvas, itemPtr, pointPtr) - Tk_Canvas canvas; /* Canvas containing item. */ - Tk_Item *itemPtr; /* Item to check against point. */ - double *pointPtr; /* Pointer to x and y coordinates. */ +WinItemToPoint( + Tk_Canvas canvas, /* Canvas containing item. */ + Tk_Item *itemPtr, /* Item to check against point. */ + double *pointPtr) /* Pointer to x and y coordinates. */ { WindowItem *winItemPtr = (WindowItem *) itemPtr; double x1, x2, y1, y2, xDiff, yDiff; @@ -709,14 +691,13 @@ WinItemToPoint(canvas, itemPtr, pointPtr) * * WinItemToArea -- * - * This procedure is called to determine whether an item - * lies entirely inside, entirely outside, or overlapping - * a given rectangle. + * This function is called to determine whether an item lies entirely + * inside, entirely outside, or overlapping a given rectangle. * * Results: - * -1 is returned if the item is entirely outside the area - * given by rectPtr, 0 if it overlaps, and 1 if it is entirely - * inside the given area. + * -1 is returned if the item is entirely outside the area given by + * rectPtr, 0 if it overlaps, and 1 if it is entirely inside the given + * area. * * Side effects: * None. @@ -725,11 +706,11 @@ WinItemToPoint(canvas, itemPtr, pointPtr) */ static int -WinItemToArea(canvas, itemPtr, rectPtr) - Tk_Canvas canvas; /* Canvas containing item. */ - Tk_Item *itemPtr; /* Item to check against rectangle. */ - double *rectPtr; /* Pointer to array of four coordinates - * (x1, y1, x2, y2) describing rectangular +WinItemToArea( + Tk_Canvas canvas, /* Canvas containing item. */ + Tk_Item *itemPtr, /* Item to check against rectangle. */ + double *rectPtr) /* Pointer to array of four coordinates + * (x1,y1,x2,y2) describing rectangular * area. */ { WindowItem *winItemPtr = (WindowItem *) itemPtr; @@ -754,8 +735,8 @@ WinItemToArea(canvas, itemPtr, rectPtr) * * xerrorhandler -- * - * This is a dummy function to catch X11 errors during an - * attempt to print a canvas window. + * This is a dummy function to catch X11 errors during an attempt to + * print a canvas window. * * Results: * None. @@ -768,11 +749,11 @@ WinItemToArea(canvas, itemPtr, rectPtr) #ifdef X_GetImage static int -xerrorhandler(clientData, e) - ClientData clientData; - XErrorEvent *e; +xerrorhandler( + ClientData clientData, + XErrorEvent *e) { - return 0; + return 0; } #endif @@ -782,15 +763,13 @@ xerrorhandler(clientData, e) * * WinItemToPostscript -- * - * This procedure is called to generate Postscript for - * window items. + * This function is called to generate Postscript for window items. * * Results: - * The return value is a standard Tcl result. If an error - * occurs in generating Postscript then an error message is - * left in interp->result, replacing whatever used to be there. - * If no error occurs, then Postscript for the item is appended - * to the result. + * The return value is a standard Tcl result. If an error occurs in + * generating Postscript then an error message is left in interp->result, + * replacing whatever used to be there. If no error occurs, then + * Postscript for the item is appended to the result. * * Side effects: * None. @@ -799,15 +778,13 @@ xerrorhandler(clientData, e) */ static int -WinItemToPostscript(interp, canvas, itemPtr, prepass) - Tcl_Interp *interp; /* Leave Postscript or error message - * here. */ - Tk_Canvas canvas; /* Information about overall canvas. */ - Tk_Item *itemPtr; /* Item for which Postscript is - * wanted. */ - int prepass; /* 1 means this is a prepass to - * collect font information; 0 means - * final Postscript is being created.*/ +WinItemToPostscript( + Tcl_Interp *interp, /* Leave Postscript or error message here. */ + Tk_Canvas canvas, /* Information about overall canvas. */ + Tk_Item *itemPtr, /* Item for which Postscript is wanted. */ + int prepass) /* 1 means this is a prepass to collect font + * information; 0 means final Postscript is + * being created. */ { WindowItem *winItemPtr = (WindowItem *)itemPtr; @@ -818,80 +795,75 @@ WinItemToPostscript(interp, canvas, itemPtr, prepass) if (prepass || winItemPtr->tkwin == NULL) { return TCL_OK; } - + width = Tk_Width(tkwin); height = Tk_Height(tkwin); /* - * Compute the coordinates of the lower-left corner of the window, - * taking into account the anchor position for the window. + * Compute the coordinates of the lower-left corner of the window, taking + * into account the anchor position for the window. */ x = winItemPtr->x; y = Tk_CanvasPsY(canvas, winItemPtr->y); - + switch (winItemPtr->anchor) { - case TK_ANCHOR_NW: y -= height; break; - case TK_ANCHOR_N: x -= width/2.0; y -= height; break; - case TK_ANCHOR_NE: x -= width; y -= height; break; - case TK_ANCHOR_E: x -= width; y -= height/2.0; break; - case TK_ANCHOR_SE: x -= width; break; - case TK_ANCHOR_S: x -= width/2.0; break; - case TK_ANCHOR_SW: break; - case TK_ANCHOR_W: y -= height/2.0; break; - case TK_ANCHOR_CENTER: x -= width/2.0; y -= height/2.0; break; + case TK_ANCHOR_NW: y -= height; break; + case TK_ANCHOR_N: x -= width/2.0; y -= height; break; + case TK_ANCHOR_NE: x -= width; y -= height; break; + case TK_ANCHOR_E: x -= width; y -= height/2.0; break; + case TK_ANCHOR_SE: x -= width; break; + case TK_ANCHOR_S: x -= width/2.0; break; + case TK_ANCHOR_SW: break; + case TK_ANCHOR_W: y -= height/2.0; break; + case TK_ANCHOR_CENTER: x -= width/2.0; y -= height/2.0; break; } return CanvasPsWindow(interp, tkwin, canvas, x, y, width, height); } - + static int -CanvasPsWindow(interp, tkwin, canvas, x, y, width, height) - Tcl_Interp *interp; /* Leave Postscript or error message - * here. */ - Tk_Window tkwin; /* window to be printed */ - Tk_Canvas canvas; /* Information about overall canvas. */ - double x, y; /* origin of window. */ - int width, height; /* width/height of window. */ +CanvasPsWindow( + Tcl_Interp *interp, /* Leave Postscript or error message here. */ + Tk_Window tkwin, /* window to be printed */ + Tk_Canvas canvas, /* Information about overall canvas. */ + 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; + Tk_ErrorHandler handle; #endif 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, (char *) NULL); + 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. + /* + * 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_DStringInit(&buffer1); Tcl_DStringInit(&buffer2); Tcl_DStringGetResult(interp, &buffer2); - sprintf (buffer, "%s postscript -prolog 0\n", Tk_PathName(tkwin)); + 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_AppendResult(interp, - "50 dict begin\nsave\ngsave\n", - (char *) NULL); - sprintf (buffer, - "0 %d moveto %d 0 rlineto 0 -%d rlineto -%d", + 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_AppendResult(interp, buffer, (char *) NULL); + 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", - (char *) NULL); + Tcl_DStringValue(&buffer1), "\nrestore\nend\n\n\n", NULL); Tcl_DStringFree(&buffer1); return result; @@ -899,17 +871,18 @@ CanvasPsWindow(interp, tkwin, canvas, x, y, width, height) Tcl_DStringFree(&buffer1); /* - * If the window is off the screen it will generate an BadMatch/XError - * We catch any BadMatch errors here + * If the window is off the screen it will generate a BadMatch/XError. We + * catch any BadMatch errors here */ + #ifdef X_GetImage handle = Tk_CreateErrorHandler(Tk_Display(tkwin), BadMatch, X_GetImage, -1, xerrorhandler, (ClientData) tkwin); #endif /* - * Generate an XImage from the window. We can then read pixel - * values out of the XImage. + * Generate an XImage from the window. We can then read pixel values out + * of the XImage. */ ximage = XGetImage(Tk_Display(tkwin), Tk_WindowId(tkwin), 0, 0, @@ -919,7 +892,7 @@ CanvasPsWindow(interp, tkwin, canvas, x, y, width, height) Tk_DeleteErrorHandler(handle); #endif - if (ximage == (XImage*) NULL) { + if (ximage == NULL) { return TCL_OK; } @@ -935,15 +908,14 @@ CanvasPsWindow(interp, tkwin, canvas, x, y, width, height) * * ScaleWinItem -- * - * This procedure is invoked to rescale a window item. + * This function is invoked to rescale a window item. * * Results: * None. * * Side effects: - * The window referred to by itemPtr is rescaled - * so that the following transformation is applied to all - * point coordinates: + * The window referred to by itemPtr is rescaled so that the following + * transformation is applied to all point coordinates: * x' = originX + scaleX*(x-originX) * y' = originY + scaleY*(y-originY) * @@ -951,12 +923,13 @@ CanvasPsWindow(interp, tkwin, canvas, x, y, width, height) */ static void -ScaleWinItem(canvas, itemPtr, originX, originY, scaleX, scaleY) - Tk_Canvas canvas; /* Canvas containing window. */ - Tk_Item *itemPtr; /* Window to be scaled. */ - double originX, originY; /* Origin about which to scale window. */ - double scaleX; /* Amount to scale in X direction. */ - double scaleY; /* Amount to scale in Y direction. */ +ScaleWinItem( + Tk_Canvas canvas, /* Canvas containing window. */ + Tk_Item *itemPtr, /* Window to be scaled. */ + double originX, double originY, + /* Origin about which to scale window. */ + double scaleX, /* Amount to scale in X direction. */ + double scaleY) /* Amount to scale in Y direction. */ { WindowItem *winItemPtr = (WindowItem *) itemPtr; @@ -976,25 +949,24 @@ ScaleWinItem(canvas, itemPtr, originX, originY, scaleX, scaleY) * * TranslateWinItem -- * - * This procedure is called to move a window by a given amount. + * This function is called to move a window by a given amount. * * Results: * None. * * Side effects: - * The position of the window is offset by (xDelta, yDelta), - * and the bounding box is updated in the generic part of the - * item structure. + * The position of the window is offset by (xDelta, yDelta), and the + * bounding box is updated in the generic part of the item structure. * *-------------------------------------------------------------- */ static void -TranslateWinItem(canvas, itemPtr, deltaX, deltaY) - Tk_Canvas canvas; /* Canvas containing item. */ - Tk_Item *itemPtr; /* Item that is being moved. */ - double deltaX, deltaY; /* Amount by which item is to be - * moved. */ +TranslateWinItem( + Tk_Canvas canvas, /* Canvas containing item. */ + Tk_Item *itemPtr, /* Item that is being moved. */ + double deltaX, double deltaY) + /* Amount by which item is to be moved. */ { WindowItem *winItemPtr = (WindowItem *) itemPtr; @@ -1008,25 +980,23 @@ TranslateWinItem(canvas, itemPtr, deltaX, deltaY) * * WinItemStructureProc -- * - * This procedure is invoked whenever StructureNotify events - * occur for a window that's managed as part of a canvas window - * item. This procudure's only purpose is to clean up when - * windows are deleted. + * This function is invoked whenever StructureNotify events occur for a + * window that's managed as part of a canvas window item. This function's + * only purpose is to clean up when windows are deleted. * * Results: * None. * * Side effects: - * The window is disassociated from the window item when it is - * deleted. + * The window is disassociated from the window item when it is deleted. * *-------------------------------------------------------------- */ static void -WinItemStructureProc(clientData, eventPtr) - ClientData clientData; /* Pointer to record describing window item. */ - XEvent *eventPtr; /* Describes what just happened. */ +WinItemStructureProc( + ClientData clientData, /* Pointer to record describing window item. */ + XEvent *eventPtr) /* Describes what just happened. */ { WindowItem *winItemPtr = (WindowItem *) clientData; @@ -1040,8 +1010,8 @@ WinItemStructureProc(clientData, eventPtr) * * WinItemRequestProc -- * - * This procedure is invoked whenever a window that's associated - * with a window canvas item changes its requested dimensions. + * This function is invoked whenever a window that's associated with a + * window canvas item changes its requested dimensions. * * Results: * None. @@ -1054,16 +1024,15 @@ WinItemStructureProc(clientData, eventPtr) */ static void -WinItemRequestProc(clientData, tkwin) - ClientData clientData; /* Pointer to record for window item. */ - Tk_Window tkwin; /* Window that changed its desired - * size. */ +WinItemRequestProc( + ClientData clientData, /* Pointer to record for window item. */ + Tk_Window tkwin) /* Window that changed its desired size. */ { WindowItem *winItemPtr = (WindowItem *) clientData; ComputeWindowBbox(winItemPtr->canvas, winItemPtr); - DisplayWinItem(winItemPtr->canvas, (Tk_Item *) winItemPtr, - (Display *) NULL, (Drawable) None, 0, 0, 0, 0); + DisplayWinItem(winItemPtr->canvas, (Tk_Item *) winItemPtr, NULL, + (Drawable) None, 0, 0, 0, 0); } /* @@ -1071,8 +1040,8 @@ WinItemRequestProc(clientData, tkwin) * * WinItemLostSlaveProc -- * - * This procedure is invoked by Tk whenever some other geometry - * claims control over a slave that used to be managed by us. + * This function is invoked by Tk whenever some other geometry claims + * control over a slave that used to be managed by us. * * Results: * None. @@ -1085,10 +1054,10 @@ WinItemRequestProc(clientData, tkwin) /* ARGSUSED */ static void -WinItemLostSlaveProc(clientData, tkwin) - ClientData clientData; /* WindowItem structure for slave window that +WinItemLostSlaveProc( + ClientData clientData, /* WindowItem structure for slave window that * was stolen away. */ - Tk_Window tkwin; /* Tk's handle for the slave window. */ + Tk_Window tkwin) /* Tk's handle for the slave window. */ { WindowItem *winItemPtr = (WindowItem *) clientData; Tk_Window canvasTkwin = Tk_CanvasTkwin(winItemPtr->canvas); @@ -1101,3 +1070,11 @@ WinItemLostSlaveProc(clientData, tkwin) Tk_UnmapWindow(winItemPtr->tkwin); winItemPtr->tkwin = NULL; } + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ diff --git a/generic/tkCanvas.h b/generic/tkCanvas.h index 402eaa1..5e27558 100644 --- a/generic/tkCanvas.h +++ b/generic/tkCanvas.h @@ -1,17 +1,16 @@ /* * tkCanvas.h -- * - * Declarations shared among all the files that implement - * canvas widgets. + * Declarations shared among all the files that implement canvas widgets. * * Copyright (c) 1991-1994 The Regents of the University of California. * Copyright (c) 1994-1995 Sun Microsystems, Inc. * Copyright (c) 1998 by Scriptics Corporation. * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkCanvas.h,v 1.7 2003/01/08 23:02:33 drh Exp $ + * RCS: @(#) $Id: tkCanvas.h,v 1.8 2005/11/04 15:30:59 dkf Exp $ */ #ifndef _TKCANVAS @@ -25,7 +24,8 @@ typedef struct TagSearchExpr_s TagSearchExpr; struct TagSearchExpr_s { - TagSearchExpr *next; /* for linked lists of expressions - used in bindings */ + TagSearchExpr *next; /* for linked lists of expressions - used in + * bindings */ Tk_Uid uid; /* the uid of the whole expression */ Tk_Uid *uids; /* expresion compiled to an array of uids */ int allocated; /* available space for array of uids */ @@ -36,25 +36,25 @@ struct TagSearchExpr_s { #endif /* not USE_OLD_TAG_SEARCH */ /* - * The record below describes a canvas widget. It is made available - * to the item procedures so they can access certain shared fields such - * as the overall displacement and scale factor for the canvas. + * The record below describes a canvas widget. It is made available to the + * item functions so they can access certain shared fields such as the overall + * displacement and scale factor for the canvas. */ typedef struct TkCanvas { - Tk_Window tkwin; /* Window that embodies the canvas. NULL - * means that the window has been destroyed - * but the data structures haven't yet been - * cleaned up.*/ - Display *display; /* Display containing widget; needed, among + Tk_Window tkwin; /* Window that embodies the canvas. NULL means + * that the window has been destroyed but the + * data structures haven't yet been cleaned + * up.*/ + Display *display; /* Display containing widget; needed, among * other things, to release resources after * tkwin has already gone away. */ Tcl_Interp *interp; /* Interpreter associated with canvas. */ Tcl_Command widgetCmd; /* Token for canvas's widget command. */ - Tk_Item *firstItemPtr; /* First in list of all items in canvas, - * or NULL if canvas empty. */ - Tk_Item *lastItemPtr; /* Last in list of all items in canvas, - * or NULL if canvas empty. */ + Tk_Item *firstItemPtr; /* First in list of all items in canvas, or + * NULL if canvas empty. */ + Tk_Item *lastItemPtr; /* Last in list of all items in canvas, or + * NULL if canvas empty. */ /* * Information used when displaying widget: @@ -64,39 +64,39 @@ typedef struct TkCanvas { Tk_3DBorder bgBorder; /* Used for canvas background. */ int relief; /* Indicates whether window as a whole is * raised, sunken, or flat. */ - int highlightWidth; /* Width in pixels of highlight to draw - * around widget when it has the focus. - * <= 0 means don't draw a highlight. */ + int highlightWidth; /* Width in pixels of highlight to draw around + * widget when it has the focus. <= 0 means + * don't draw a highlight. */ XColor *highlightBgColorPtr; - /* Color for drawing traversal highlight - * area when highlight is off. */ + /* Color for drawing traversal highlight area + * when highlight is off. */ XColor *highlightColorPtr; /* Color for drawing traversal highlight. */ int inset; /* Total width of all borders, including * traversal highlight and 3-D border. - * Indicates how much interior stuff must - * be offset from outside edges to leave - * room for borders. */ + * Indicates how much interior stuff must be + * offset from outside edges to leave room for + * borders. */ GC pixmapGC; /* Used to copy bits from a pixmap to the * screen and also to clear the pixmap. */ int width, height; /* Dimensions to request for canvas window, * specified in pixels. */ - int redrawX1, redrawY1; /* Upper left corner of area to redraw, - * in pixel coordinates. Border pixels - * are included. Only valid if - * REDRAW_PENDING flag is set. */ - int redrawX2, redrawY2; /* Lower right corner of area to redraw, - * in integer canvas coordinates. Border - * pixels will *not* be redrawn. */ - int confine; /* Non-zero means constrain view to keep - * as much of canvas visible as possible. */ + int redrawX1, redrawY1; /* Upper left corner of area to redraw, in + * pixel coordinates. Border pixels are + * included. Only valid if REDRAW_PENDING flag + * is set. */ + int redrawX2, redrawY2; /* Lower right corner of area to redraw, in + * integer canvas coordinates. Border pixels + * will *not* be redrawn. */ + int confine; /* Non-zero means constrain view to keep as + * much of canvas visible as possible. */ /* * Information used to manage the selection and insertion cursor: */ - Tk_CanvasTextInfo textInfo; /* Contains lots of fields; see tk.h for - * details. This structure is shared with - * the code that implements individual items. */ + Tk_CanvasTextInfo textInfo; /* Contains lots of fields; see tk.h for + * details. This structure is shared with the + * code that implements individual items. */ int insertOnTime; /* Number of milliseconds cursor should spend * in "on" state for each blink. */ int insertOffTime; /* Number of milliseconds cursor should spend @@ -106,7 +106,7 @@ typedef struct TkCanvas { * off. */ /* - * Transformation applied to canvas as a whole: to compute screen + * Transformation applied to canvas as a whole: to compute screen * coordinates (X,Y) from canvas coordinates (x,y), do the following: * * X = x - xOrigin; @@ -118,65 +118,63 @@ typedef struct TkCanvas { * canvas pixel units. */ int drawableXOrigin, drawableYOrigin; /* During redisplay, these fields give the - * canvas coordinates corresponding to - * the upper-left corner of the drawable - * where items are actually being drawn - * (typically a pixmap smaller than the - * whole window). */ + * canvas coordinates corresponding to the + * upper-left corner of the drawable where + * items are actually being drawn (typically a + * pixmap smaller than the whole window). */ /* * Information used for event bindings associated with items. */ Tk_BindingTable bindingTable; - /* Table of all bindings currently defined - * for this canvas. NULL means that no - * bindings exist, so the table hasn't been - * created. Each "object" used for this - * table is either a Tk_Uid for a tag or - * the address of an item named by id. */ + /* Table of all bindings currently defined for + * this canvas. NULL means that no bindings + * exist, so the table hasn't been created. + * Each "object" used for this table is either + * a Tk_Uid for a tag or the address of an + * item named by id. */ Tk_Item *currentItemPtr; /* The item currently containing the mouse * pointer, or NULL if none. */ Tk_Item *newCurrentPtr; /* The item that is about to become the - * current one, or NULL. This field is - * used to detect deletions of the new - * current item pointer that occur during - * Leave processing of the previous current - * item. */ - double closeEnough; /* The mouse is assumed to be inside an - * item if it is this close to it. */ - XEvent pickEvent; /* The event upon which the current choice - * of currentItem is based. Must be saved - * so that if the currentItem is deleted, - * can pick another. */ - int state; /* Last known modifier state. Used to - * defer picking a new current object - * while buttons are down. */ + * current one, or NULL. This field is used to + * detect deletions of the new current item + * pointer that occur during Leave processing + * of the previous current item. */ + double closeEnough; /* The mouse is assumed to be inside an item + * if it is this close to it. */ + XEvent pickEvent; /* The event upon which the current choice of + * currentItem is based. Must be saved so that + * if the currentItem is deleted, can pick + * another. */ + int state; /* Last known modifier state. Used to defer + * picking a new current object while buttons + * are down. */ /* * Information used for managing scrollbars: */ char *xScrollCmd; /* Command prefix for communicating with - * horizontal scrollbar. NULL means no - * horizontal scrollbar. Malloc'ed*/ + * horizontal scrollbar. NULL means no + * horizontal scrollbar. Malloc'ed*/ char *yScrollCmd; /* Command prefix for communicating with - * vertical scrollbar. NULL means no - * vertical scrollbar. Malloc'ed*/ + * vertical scrollbar. NULL means no vertical + * scrollbar. Malloc'ed*/ int scrollX1, scrollY1, scrollX2, scrollY2; /* These four coordinates define the region * that is the 100% area for scrolling (i.e. * these numbers determine the size and * location of the sliders on scrollbars). * Units are pixels in canvas coords. */ - char *regionString; /* The option string from which scrollX1 - * etc. are derived. Malloc'ed. */ + char *regionString; /* The option string from which scrollX1 etc. + * are derived. Malloc'ed. */ int xScrollIncrement; /* If >0, defines a grid for horizontal - * scrolling. This is the size of the "unit", + * scrolling. This is the size of the "unit", * and the left edge of the screen will always * lie on an even unit boundary. */ int yScrollIncrement; /* If >0, defines a grid for horizontal - * scrolling. This is the size of the "unit", + * scrolling. This is the size of the "unit", * and the left edge of the screen will always * lie on an even unit boundary. */ @@ -197,11 +195,11 @@ typedef struct TkCanvas { */ Tk_Item *hotPtr; /* Pointer to "hot" item (one that's been - * recently used. NULL means there's no - * hot item. */ + * recently used. NULL means there's no hot + * item. */ Tk_Item *hotPrevPtr; /* Pointer to predecessor to hotPtr (NULL - * means item is first in list). This is - * only a hint and may not really be hotPtr's + * means item is first in list). This is only + * a hint and may not really be hotPtr's * predecessor. */ /* @@ -209,61 +207,61 @@ typedef struct TkCanvas { */ Tk_Cursor cursor; /* Current cursor for window, or None. */ - char *takeFocus; /* Value of -takefocus option; not used in - * the C code, but used by keyboard traversal - * scripts. Malloc'ed, but may be NULL. */ - double pixelsPerMM; /* Scale factor between MM and pixels; - * used when converting coordinates. */ - int flags; /* Various flags; see below for + char *takeFocus; /* Value of -takefocus option; not used in the + * C code, but used by keyboard traversal + * scripts. Malloc'ed, but may be NULL. */ + double pixelsPerMM; /* Scale factor between MM and pixels; used + * when converting coordinates. */ + int flags; /* Various flags; see below for * definitions. */ - int nextId; /* Number to use as id for next item - * created in widget. */ - Tk_PostscriptInfo psInfo; - /* Pointer to information used for generating - * Postscript for the canvas. NULL means - * no Postscript is currently being - * generated. */ + int nextId; /* Number to use as id for next item created + * in widget. */ + Tk_PostscriptInfo psInfo; /* Pointer to information used for generating + * Postscript for the canvas. NULL means no + * Postscript is currently being generated. */ Tcl_HashTable idTable; /* Table of integer indices. */ + /* * Additional information, added by the 'dash'-patch */ - VOID *reserved1; + + void *reserved1; Tk_State canvas_state; /* state of canvas */ - VOID *reserved2; - VOID *reserved3; + void *reserved2; + void *reserved3; Tk_TSOffset tsoffset; #ifndef USE_OLD_TAG_SEARCH - TagSearchExpr *bindTagExprs; /* linked list of tag expressions used in bindings */ + TagSearchExpr *bindTagExprs; /* Linked list of tag expressions used in + * bindings. */ #endif } TkCanvas; /* * Flag bits for canvases: * - * REDRAW_PENDING - 1 means a DoWhenIdle handler has already - * been created to redraw some or all of the - * canvas. + * REDRAW_PENDING - 1 means a DoWhenIdle handler has already been + * created to redraw some or all of the canvas. * REDRAW_BORDERS - 1 means that the borders need to be redrawn * during the next redisplay operation. * REPICK_NEEDED - 1 means DisplayCanvas should pick a new * current item before redrawing the canvas. - * GOT_FOCUS - 1 means the focus is currently in this - * widget, so should draw the insertion cursor - * and traversal highlight. + * GOT_FOCUS - 1 means the focus is currently in this widget, + * so should draw the insertion cursor and + * traversal highlight. * CURSOR_ON - 1 means the insertion cursor is in the "on" - * phase of its blink cycle. 0 means either - * we don't have the focus or the cursor is in - * the "off" phase of its cycle. - * UPDATE_SCROLLBARS - 1 means the scrollbars should get updated - * as part of the next display operation. - * LEFT_GRABBED_ITEM - 1 means that the mouse left the current - * item while a grab was in effect, so we - * didn't change canvasPtr->currentItemPtr. + * phase of its blink cycle. 0 means either we + * don't have the focus or the cursor is in the + * "off" phase of its cycle. + * UPDATE_SCROLLBARS - 1 means the scrollbars should get updated as + * part of the next display operation. + * LEFT_GRABBED_ITEM - 1 means that the mouse left the current item + * while a grab was in effect, so we didn't + * change canvasPtr->currentItemPtr. * REPICK_IN_PROGRESS - 1 means PickCurrentItem is currently - * executing. If it should be called recursively, + * executing. If it should be called recursively, * it should simply return immediately. - * BBOX_NOT_EMPTY - 1 means that the bounding box of the area - * that should be redrawn is not empty. + * BBOX_NOT_EMPTY - 1 means that the bounding box of the area that + * should be redrawn is not empty. */ #define REDRAW_PENDING 1 @@ -279,8 +277,8 @@ typedef struct TkCanvas { /* * Flag bits for canvas items (redraw_flags): * - * FORCE_REDRAW - 1 means that the new coordinates of some - * item are not yet registered using + * FORCE_REDRAW - 1 means that the new coordinates of some item + * are not yet registered using * Tk_CanvasEventuallyRedraw(). It should still * be done by the general canvas code. */ @@ -288,20 +286,14 @@ typedef struct TkCanvas { #define FORCE_REDRAW 8 /* - * Canvas-related procedures that are shared among Tk modules but not - * exported to the outside world: - */ - -extern int TkCanvPostscriptCmd _ANSI_ARGS_((TkCanvas *canvasPtr, - Tcl_Interp *interp, int argc, CONST char **argv)); - -/* - * Other procedures that are shared among Tk canvas modules but not exported + * Canvas-related functions that are shared among Tk modules but not exported * to the outside world: */ -extern int TkCanvTranslatePath _ANSI_ARGS_((TkCanvas *canvPtr, - int numVertex, double *coordPtr, int closed, - XPoint *outPtr)); +extern int TkCanvPostscriptCmd(TkCanvas *canvasPtr, + Tcl_Interp *interp, int argc, CONST char **argv); +extern int TkCanvTranslatePath(TkCanvas *canvPtr, + int numVertex, double *coordPtr, int closed, + XPoint *outPtr); #endif /* _TKCANVAS */ |