head	1.32;
access;
symbols
	core-8-5-9:1.21
	core-8-5-8:1.21
	macosx-cocoa-merge:1.29
	macosx-cocoa-premerge:1.29
	macosx-carbon-freeze:1.29
	core-8-5-7:1.21
	core-8-5-6:1.21
	core-8-6-b1:1.27
	core-8-6-a3:1.21
	core-8-5-5:1.21
	core-8-6-a2:1.21
	core-8-5-4:1.21
	core-8-5-3:1.21
	core-8-6-a1:1.21
	core-8-4-19:1.12.2.1
	core-8-5-branch:1.21.0.2
	core-8-5-2:1.21
	core-8-4-18:1.12.2.1
	core-8-5-1:1.21
	core-8-4-17:1.12.2.1
	core-8-5-0:1.21
	core-8-5-b3:1.20
	core-8-5-b2:1.20
	core-8-4-16:1.12.2.1
	core-8-5-b1:1.19
	core-stablilizer-merge:1.17
	core-stabilizer-branch:1.17.0.2
	core-stabilizer-merge:1.21
	core-8-4-15:1.12.2.1
	core-8-5-a6:1.17
	core-8-5-a5:1.14
	core-8-4-14:1.12.2.1
	core-8-5-a4:1.14
	core-8-4-13:1.12.2.1
	core-8-4-12:1.12.2.1
	core-8-4-11:1.12.2.1
	core-8-5-a3:1.12
	core-8-4-10:1.12.2.1
	core-8-4-9-branch:1.12.2.1.0.2
	core-8-5-a2:1.12
	core-8-4-9:1.12.2.1
	core-8-4-8:1.12.2.1
	core-8-4-7:1.12
	core-8-5-a1:1.12
	core-8-4-6:1.12
	core-8-4-5:1.12
	mistachkin-dev-branch:1.12.0.4
	core-8-4-4:1.12
	core-8-4-3:1.12
	core-8-4-branch:1.12.0.2
	core-8-4-2:1.12
	core-8-4-1:1.12
	core-8-3-5:1.9
	core-8-4-0:1.12
	macosx-8-4-merge-2002-08-31-trunk:1.12
	macosx-8-4-premerge-2002-08-31-branch:1.11.2.1
	macosx-8-4-premerge-2002-08-31-trunk:1.12
	macosx-8-4-merge-2002-08-30-branch:1.11.2.1
	macosx-8-4-merge-2002-08-30-trunk:1.12
	macosx-8-4-merge-2002-08-20-branch:1.11.2.1
	macosx-8-4-merge-2002-08-20-trunk:1.12
	core-8-4-b2:1.12
	core-8-4-b1:1.11
	macosx-premerge-6-9-02:1.11
	core-8-4-a4:1.11
	core-8-3-4:1.9
	macosx-8-4-branch:1.11.0.2
	macosx-8-4-branchpoint:1.11
	core-8-4-a3:1.9
	core-8-3-3:1.9
	dgp-privates-into-namespace:1.9.0.6
	tclpro-1-5-0:1.9
	core-8-4-win-speedup:1.9.0.4
	core-8-4-a2:1.9
	tclpro-1-4-1:1.9
	tclpro-1-4-0:1.9
	core-8-3-2:1.9
	ajuba-ajuba2-2-1-base:1.9
	ajuba-ajuba2-2-0:1.9
	core-8-4-a1:1.9
	core-8-3-1-branch:1.9.0.2
	core-8-3-1:1.9
	scriptics-sc-2-0-b5:1.7
	scriptics-sc-2-0-fixed:1.7
	scriptics-sc-2-0-b2:1.7
	scriptics-sc-2-0-b1:1.7
	core-8-3-0:1.7
	core-8-3-b2:1.7
	core-8-3-b1:1.7
	scriptics-sc-1-1:1.6
	scriptics-sc-1-1-b1:1.6
	core-8-2-3:1.6
	scriptics-sc-1-1-branch:1.6.0.8
	scriptics-sc-1-1-base:1.6
	scriptics-sc-1-0:1.6
	scriptics-sc-1-0-branch:1.6.0.6
	scriptics-sc-1-0-base:1.6
	core-8-2-2:1.6
	core-8-2-1:1.6
	scriptics-bc-1-0-b1:1.6
	core-8-2-1-branch:1.6.0.4
	scriptics-tclpro-1-3-0:1.6
	core-8-2-0:1.6
	core-8-2-b3-branch:1.6.0.2
	core-8-2-b3-base:1.6
	scriptics-tclpro-1-3-b4:1.5
	core-8-2-b2:1.5
	scriptics-tclpro-1-3-b3:1.5
	core-8-2-b1:1.5
	scriptics-tclpro-1-3-b2:1.5
	merge-to-mainline-5/21/99:1.5
	scriptics-tclpro-1-3-b2-branch:1.5.0.4
	core-8-1-1:1.5
	scriptics-tclpro-1-3-b1:1.5
	core-8-1-1-base:1.5
	core-8-1-0:1.5
	merge-to-mainline-4-29-99:1.5
	merge-to-mainline-4-23-99:1.5
	core-8-1-branch-old:1.1.0.4
	core-8-0-6-branch:1.2.0.6
	core-8-0-6-base:1.2
	core-8-0-5:1.2
	core-8-1-b3:1.1.4.3
	core-8-1-b2:1.1.4.3
	dev-8-1-stubs-branch:1.1.4.3.0.2
	dev-stubs-branch:1.2.0.4
	scriptics-tclpro-1-2:1.2
	scriptics-tclpro-1-2-b2:1.2
	core-8-1-merge-2/10/99:1.2
	core-8-0-5-branch:1.2.0.2
	core-8-0-5-base:1.2
	scriptics-tclpro-1-2-b1:1.2
	scriptics-tclpro-1-2-a1:1.2
	core-8-1-b1:1.1.4.2
	core-8-0-4:1.2
	core-8-1-a2:1.1.4.1
	core-8-0-2:1.1
	core-8-0-3:1.2;
locks; strict;
comment	@ * @;


1.32
date	2009.12.16.22.00.31;	author nijtmans;	state Exp;
branches;
next	1.31;

1.31
date	2009.11.21.17.24.42;	author dkf;	state Exp;
branches;
next	1.30;

1.30
date	2009.08.09.21.20.33;	author nijtmans;	state Exp;
branches;
next	1.29;

1.29
date	2009.04.10.16.00.12;	author das;	state Exp;
branches;
next	1.28;

1.28
date	2009.02.06.08.12.07;	author das;	state Exp;
branches;
next	1.27;

1.27
date	2008.12.10.05.02.51;	author das;	state Exp;
branches;
next	1.26;

1.26
date	2008.12.10.04.27.45;	author das;	state Exp;
branches;
next	1.25;

1.25
date	2008.12.10.00.34.51;	author das;	state Exp;
branches;
next	1.24;

1.24
date	2008.11.08.18.44.40;	author dkf;	state Exp;
branches;
next	1.23;

1.23
date	2008.10.30.21.39.16;	author nijtmans;	state Exp;
branches;
next	1.22;

1.22
date	2008.10.15.06.41.06;	author nijtmans;	state Exp;
branches;
next	1.21;

1.21
date	2007.12.13.15.24.21;	author dgp;	state Exp;
branches;
next	1.20;

1.20
date	2007.10.15.07.24.49;	author das;	state Exp;
branches;
next	1.19;

1.19
date	2007.09.08.16.01.20;	author dkf;	state Exp;
branches;
next	1.18;

1.18
date	2007.09.07.00.34.54;	author dgp;	state Exp;
branches;
next	1.17;

1.17
date	2007.02.25.04.30.30;	author pspjuth;	state Exp;
branches
	1.17.2.1;
next	1.16;

1.16
date	2007.01.19.06.29.20;	author das;	state Exp;
branches;
next	1.15;

1.15
date	2007.01.18.23.56.43;	author nijtmans;	state Exp;
branches;
next	1.14;

1.14
date	2005.11.13.20.42.54;	author dkf;	state Exp;
branches;
next	1.13;

1.13
date	2005.11.13.00.45.47;	author dkf;	state Exp;
branches;
next	1.12;

1.12
date	2002.08.05.04.30.40;	author dgp;	state Exp;
branches
	1.12.2.1;
next	1.11;

1.11
date	2001.09.26.20.25.17;	author pspjuth;	state Exp;
branches
	1.11.2.1;
next	1.10;

1.10
date	2001.08.15.15.44.36;	author dkf;	state Exp;
branches;
next	1.9;

1.9
date	2000.04.19.23.11.24;	author ericm;	state Exp;
branches
	1.9.4.1;
next	1.8;

1.8
date	2000.04.18.02.18.33;	author ericm;	state Exp;
branches;
next	1.7;

1.7
date	99.12.14.06.52.34;	author hobbs;	state Exp;
branches;
next	1.6;

1.6
date	99.08.10.05.10.52;	author jingham;	state Exp;
branches;
next	1.5;

1.5
date	99.04.21.21.53.28;	author rjohnson;	state Exp;
branches;
next	1.4;

1.4
date	99.04.16.18.30.28;	author surles;	state Exp;
branches;
next	1.3;

1.3
date	99.04.16.01.51.24;	author stanton;	state Exp;
branches
	1.3.2.1;
next	1.2;

1.2
date	98.09.14.18.23.20;	author stanton;	state Exp;
branches;
next	1.1;

1.1
date	98.04.01.09.52.06;	author rjohnson;	state Exp;
branches
	1.1.4.1;
next	;

1.1.4.1
date	98.09.29.00.25.28;	author stanton;	state Exp;
branches;
next	1.1.4.2;

1.1.4.2
date	98.09.30.02.17.27;	author stanton;	state Exp;
branches;
next	1.1.4.3;

1.1.4.3
date	99.02.16.11.39.34;	author lfb;	state Exp;
branches;
next	;

1.3.2.1
date	99.04.21.02.31.54;	author rjohnson;	state Exp;
branches;
next	;

1.9.4.1
date	2002.04.02.21.01.00;	author hobbs;	state Exp;
branches;
next	;

1.11.2.1
date	2002.08.20.20.27.09;	author das;	state Exp;
branches;
next	;

1.12.2.1
date	2004.10.27.00.37.38;	author davygrvy;	state Exp;
branches;
next	;

1.17.2.1
date	2007.09.07.01.25.36;	author dgp;	state Exp;
branches;
next	1.17.2.2;

1.17.2.2
date	2007.09.09.04.15.54;	author dgp;	state Exp;
branches;
next	1.17.2.3;

1.17.2.3
date	2007.10.15.18.38.33;	author dgp;	state Exp;
branches;
next	;


desc
@@


1.32
log
@CONSTify return values of TkKeysymToString,
TkFindStateString, TkpGetString, TkpGetChar,
which are all not supposed to be modified by
the caller. In tkUtil.c this gets rid of a
dangerous type cast.
@
text
@/*
 * tkUtil.c --
 *
 *	This file contains miscellaneous utility functions that are used by
 *	the rest of Tk, such as a function for drawing a focus highlight.
 *
 * 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.
 *
 * RCS: @@(#) $Id: tkUtil.c,v 1.31 2009/11/21 17:24:42 dkf Exp $
 */

#include "tkInt.h"

/*
 * The structure below defines the implementation of the "statekey" Tcl
 * object, used for quickly finding a mapping in a TkStateMap.
 */

const Tcl_ObjType tkStateKeyObjType = {
    "statekey",			/* name */
    NULL,			/* freeIntRepProc */
    NULL,			/* dupIntRepProc */
    NULL,			/* updateStringProc */
    NULL			/* setFromAnyProc */
};

/*
 *--------------------------------------------------------------
 *
 * TkStateParseProc --
 *
 *	This function is invoked during option processing to handle the
 *	"-state" and "-default" options.
 *
 * Results:
 *	A standard Tcl return value.
 *
 * Side effects:
 *	The state for a given item gets replaced by the state indicated in the
 *	value argument.
 *
 *--------------------------------------------------------------
 */

int
TkStateParseProc(
    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;
    int flags = PTR2INT(clientData);
    size_t length;

    register Tk_State *statePtr = (Tk_State *) (widgRec + offset);

    if (value == NULL || *value == 0) {
	*statePtr = TK_STATE_NULL;
	return TCL_OK;
    }

    c = value[0];
    length = strlen(value);

    if ((c == 'n') && (strncmp(value, "normal", length) == 0)) {
	*statePtr = TK_STATE_NORMAL;
	return TCL_OK;
    }
    if ((c == 'd') && (strncmp(value, "disabled", length) == 0)) {
	*statePtr = TK_STATE_DISABLED;
	return TCL_OK;
    }
    if ((c == 'a') && (flags&1) && (strncmp(value, "active", length) == 0)) {
	*statePtr = TK_STATE_ACTIVE;
	return TCL_OK;
    }
    if ((c == 'h') && (flags&2) && (strncmp(value, "hidden", length) == 0)) {
	*statePtr = TK_STATE_HIDDEN;
	return TCL_OK;
    }

    Tcl_AppendResult(interp, "bad ", (flags&4)?"-default" : "state",
	    " value \"", value, "\": must be normal", NULL);
    if (flags&1) {
	Tcl_AppendResult(interp, ", active", NULL);
    }
    if (flags&2) {
	Tcl_AppendResult(interp, ", hidden", NULL);
    }
    if (flags&3) {
	Tcl_AppendResult(interp, ",", NULL);
    }
    Tcl_AppendResult(interp, " or disabled", NULL);
    *statePtr = TK_STATE_NORMAL;
    return TCL_ERROR;
}

/*
 *--------------------------------------------------------------
 *
 * TkStatePrintProc --
 *
 *	This function is invoked by the Tk configuration code to produce a
 *	printable string for the "-state" configuration option.
 *
 * Results:
 *	The return value is a string describing the state 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.
 *
 *--------------------------------------------------------------
 */

const char *
TkStatePrintProc(
    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 Tk_State *statePtr = (Tk_State *) (widgRec + offset);

    switch (*statePtr) {
    case TK_STATE_NORMAL:
	return "normal";
    case TK_STATE_DISABLED:
	return "disabled";
    case TK_STATE_HIDDEN:
	return "hidden";
    case TK_STATE_ACTIVE:
	return "active";
    default:
	return "";
    }
}

/*
 *--------------------------------------------------------------
 *
 * TkOrientParseProc --
 *
 *	This function is invoked during option processing to handle the
 *	"-orient" option.
 *
 * Results:
 *	A standard Tcl return value.
 *
 * Side effects:
 *	The orientation for a given item gets replaced by the orientation
 *	indicated in the value argument.
 *
 *--------------------------------------------------------------
 */

int
TkOrientParseProc(
    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;

    register int *orientPtr = (int *) (widgRec + offset);

    if (value == NULL || *value == 0) {
	*orientPtr = 0;
	return TCL_OK;
    }

    c = value[0];
    length = strlen(value);

    if ((c == 'h') && (strncmp(value, "horizontal", length) == 0)) {
	*orientPtr = 0;
	return TCL_OK;
    }
    if ((c == 'v') && (strncmp(value, "vertical", length) == 0)) {
	*orientPtr = 1;
	return TCL_OK;
    }
    Tcl_AppendResult(interp, "bad orientation \"", value,
	    "\": must be vertical or horizontal", NULL);
    *orientPtr = 0;
    return TCL_ERROR;
}

/*
 *--------------------------------------------------------------
 *
 * TkOrientPrintProc --
 *
 *	This function is invoked by the Tk configuration code to produce a
 *	printable string for the "-orient" configuration option.
 *
 * Results:
 *	The return value is a string describing the orientation 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.
 *
 *--------------------------------------------------------------
 */

const char *
TkOrientPrintProc(
    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 int *statePtr = (int *) (widgRec + offset);

    if (*statePtr) {
	return "vertical";
    } else {
	return "horizontal";
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkOffsetParseProc --
 *
 *	Converts the offset of a stipple or tile into the Tk_TSOffset
 *	structure.
 *
 *----------------------------------------------------------------------
 */

int
TkOffsetParseProc(
    ClientData clientData,	/* not used */
    Tcl_Interp *interp,		/* Interpreter to send results back to */
    Tk_Window tkwin,		/* Window on same display as tile */
    const char *value,		/* Name of image */
    char *widgRec,		/* Widget structure record */
    int offset)			/* Offset of tile in record */
{
    Tk_TSOffset *offsetPtr = (Tk_TSOffset *) (widgRec + offset);
    Tk_TSOffset tsoffset;
    const char *q, *p;
    int result;

    if ((value == NULL) || (*value == 0)) {
	tsoffset.flags = TK_OFFSET_CENTER|TK_OFFSET_MIDDLE;
	goto goodTSOffset;
    }
    tsoffset.flags = 0;
    p = value;

    switch (value[0]) {
    case '#':
	if (PTR2INT(clientData) & TK_OFFSET_RELATIVE) {
	    tsoffset.flags = TK_OFFSET_RELATIVE;
	    p++;
	    break;
	}
	goto badTSOffset;
    case 'e':
	switch(value[1]) {
	case '\0':
	    tsoffset.flags = TK_OFFSET_RIGHT|TK_OFFSET_MIDDLE;
	    goto goodTSOffset;
	case 'n':
	    if (value[2]!='d' || value[3]!='\0') {
		goto badTSOffset;
	    }
	    tsoffset.flags = INT_MAX;
	    goto goodTSOffset;
	}
    case 'w':
	if (value[1] != '\0') {goto badTSOffset;}
	tsoffset.flags = TK_OFFSET_LEFT|TK_OFFSET_MIDDLE;
	goto goodTSOffset;
    case 'n':
	if ((value[1] != '\0') && (value[2] != '\0')) {
	    goto badTSOffset;
	}
	switch(value[1]) {
	case '\0':
	    tsoffset.flags = TK_OFFSET_CENTER|TK_OFFSET_TOP;
	    goto goodTSOffset;
	case 'w':
	    tsoffset.flags = TK_OFFSET_LEFT|TK_OFFSET_TOP;
	    goto goodTSOffset;
	case 'e':
	    tsoffset.flags = TK_OFFSET_RIGHT|TK_OFFSET_TOP;
	    goto goodTSOffset;
	}
	goto badTSOffset;
    case 's':
	if ((value[1] != '\0') && (value[2] != '\0')) {
	    goto badTSOffset;
	}
	switch(value[1]) {
	case '\0':
	    tsoffset.flags = TK_OFFSET_CENTER|TK_OFFSET_BOTTOM;
	    goto goodTSOffset;
	case 'w':
	    tsoffset.flags = TK_OFFSET_LEFT|TK_OFFSET_BOTTOM;
	    goto goodTSOffset;
	case 'e':
	    tsoffset.flags = TK_OFFSET_RIGHT|TK_OFFSET_BOTTOM;
	    goto goodTSOffset;
	}
	goto badTSOffset;
    case 'c':
	if (strncmp(value, "center", strlen(value)) != 0) {
	    goto badTSOffset;
	}
	tsoffset.flags = TK_OFFSET_CENTER|TK_OFFSET_MIDDLE;
	goto goodTSOffset;
    }

    /*
     * Check for an extra offset.
     */

    q = strchr(p, ',');
    if (q == NULL) {
	if (PTR2INT(clientData) & TK_OFFSET_INDEX) {
	    if (Tcl_GetInt(interp, (char *) p, &tsoffset.flags) != TCL_OK) {
		Tcl_ResetResult(interp);
		goto badTSOffset;
	    }
	    tsoffset.flags |= TK_OFFSET_INDEX;
	    goto goodTSOffset;
	}
	goto badTSOffset;
    }

    *((char *) q) = 0;
    result = Tk_GetPixels(interp, tkwin, (char *) p, &tsoffset.xoffset);
    *((char *) q) = ',';
    if (result != TCL_OK) {
	return TCL_ERROR;
    }
    if (Tk_GetPixels(interp, tkwin, (char*)q+1, &tsoffset.yoffset) != TCL_OK) {
	return TCL_ERROR;
    }

    /*
     * Below is a hack to allow the stipple/tile offset to be stored in the
     * internal tile structure. Most of the times, offsetPtr is a pointer to
     * an already existing tile structure. However if this structure is not
     * already created, we must do it with Tk_GetTile()!!!!
     */

  goodTSOffset:
    memcpy(offsetPtr, &tsoffset, sizeof(Tk_TSOffset));
    return TCL_OK;

  badTSOffset:
    Tcl_AppendResult(interp, "bad offset \"", value,
	    "\": expected \"x,y\"", NULL);
    if (PTR2INT(clientData) & TK_OFFSET_RELATIVE) {
	Tcl_AppendResult(interp, ", \"#x,y\"", NULL);
    }
    if (PTR2INT(clientData) & TK_OFFSET_INDEX) {
	Tcl_AppendResult(interp, ", <index>", NULL);
    }
    Tcl_AppendResult(interp, ", n, ne, e, se, s, sw, w, nw, or center", NULL);
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
 * TkOffsetPrintProc --
 *
 *	Returns the offset of the tile.
 *
 * Results:
 *	The offset of the tile is returned.
 *
 *----------------------------------------------------------------------
 */

const char *
TkOffsetPrintProc(
    ClientData clientData,	/* not used */
    Tk_Window tkwin,		/* not used */
    char *widgRec,		/* Widget structure record */
    int offset,			/* Offset of tile in record */
    Tcl_FreeProc **freeProcPtr)	/* not used */
{
    Tk_TSOffset *offsetPtr = (Tk_TSOffset *) (widgRec + offset);
    char *p, *q;

    if (offsetPtr->flags & TK_OFFSET_INDEX) {
	if (offsetPtr->flags >= INT_MAX) {
	    return "end";
	}
	p = ckalloc(32);
	sprintf(p, "%d", offsetPtr->flags & ~TK_OFFSET_INDEX);
	*freeProcPtr = TCL_DYNAMIC;
	return p;
    }
    if (offsetPtr->flags & TK_OFFSET_TOP) {
	if (offsetPtr->flags & TK_OFFSET_LEFT) {
	    return "nw";
	} else if (offsetPtr->flags & TK_OFFSET_CENTER) {
	    return "n";
	} else if (offsetPtr->flags & TK_OFFSET_RIGHT) {
	    return "ne";
	}
    } else if (offsetPtr->flags & TK_OFFSET_MIDDLE) {
	if (offsetPtr->flags & TK_OFFSET_LEFT) {
	    return "w";
	} else if (offsetPtr->flags & TK_OFFSET_CENTER) {
	    return "center";
	} else if (offsetPtr->flags & TK_OFFSET_RIGHT) {
	    return "e";
	}
    } else if (offsetPtr->flags & TK_OFFSET_BOTTOM) {
	if (offsetPtr->flags & TK_OFFSET_LEFT) {
	    return "sw";
	} else if (offsetPtr->flags & TK_OFFSET_CENTER) {
	    return "s";
	} else if (offsetPtr->flags & TK_OFFSET_RIGHT) {
	    return "se";
	}
    }
    q = p = ckalloc(32);
    if (offsetPtr->flags & TK_OFFSET_RELATIVE) {
	*q++ = '#';
    }
    sprintf(q, "%d,%d", offsetPtr->xoffset, offsetPtr->yoffset);
    *freeProcPtr = TCL_DYNAMIC;
    return p;
}

/*
 *----------------------------------------------------------------------
 *
 * TkPixelParseProc --
 *
 *	Converts the name of an image into a tile.
 *
 *----------------------------------------------------------------------
 */

int
TkPixelParseProc(
    ClientData clientData,	/* If non-NULL, negative values are allowed as
				 * well. */
    Tcl_Interp *interp,		/* Interpreter to send results back to */
    Tk_Window tkwin,		/* Window on same display as tile */
    const char *value,		/* Name of image */
    char *widgRec,		/* Widget structure record */
    int offset)			/* Offset of tile in record */
{
    double *doublePtr = (double *) (widgRec + offset);
    int result;

    result = TkGetDoublePixels(interp, tkwin, value, doublePtr);

    if ((result == TCL_OK) && (clientData == NULL) && (*doublePtr < 0.0)) {
	Tcl_AppendResult(interp, "bad screen distance \"", value, "\"", NULL);
	return TCL_ERROR;
    }
    return result;
}

/*
 *----------------------------------------------------------------------
 *
 * TkPixelPrintProc --
 *
 *	Returns the name of the tile.
 *
 * Results:
 *	The name of the tile is returned.
 *
 *----------------------------------------------------------------------
 */

const char *
TkPixelPrintProc(
    ClientData clientData,	/* not used */
    Tk_Window tkwin,		/* not used */
    char *widgRec,		/* Widget structure record */
    int offset,			/* Offset of tile in record */
    Tcl_FreeProc **freeProcPtr)	/* not used */
{
    double *doublePtr = (double *) (widgRec + offset);
    char *p = ckalloc(24);

    Tcl_PrintDouble(NULL, *doublePtr, p);
    *freeProcPtr = TCL_DYNAMIC;
    return p;
}

/*
 *----------------------------------------------------------------------
 *
 * TkDrawInsetFocusHighlight --
 *
 *	This function draws a rectangular ring around the outside of a widget
 *	to indicate that it has received the input focus. It takes an
 *	additional padding argument that specifies how much padding is present
 *	outside the widget.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	A rectangle "width" pixels wide is drawn in "drawable", corresponding
 *	to the outer area of "tkwin".
 *
 *----------------------------------------------------------------------
 */

void
TkDrawInsetFocusHighlight(
    Tk_Window tkwin,		/* Window whose focus highlight ring is to be
				 * drawn. */
    GC gc,			/* Graphics context to use for drawing the
				 * highlight ring. */
    int width,			/* Width of the highlight ring, in pixels. */
    Drawable drawable,		/* Where to draw the ring (typically a pixmap
				 * for double buffering). */
    int padding)		/* Width of padding outside of widget. */
{
    XRectangle rects[4];

    rects[0].x = padding;
    rects[0].y = padding;
    rects[0].width = Tk_Width(tkwin) - (2 * padding);
    rects[0].height = width;
    rects[1].x = padding;
    rects[1].y = Tk_Height(tkwin) - width - padding;
    rects[1].width = Tk_Width(tkwin) - (2 * padding);
    rects[1].height = width;
    rects[2].x = padding;
    rects[2].y = width + padding;
    rects[2].width = width;
    rects[2].height = Tk_Height(tkwin) - 2*width - 2*padding;
    rects[3].x = Tk_Width(tkwin) - width - padding;
    rects[3].y = rects[2].y;
    rects[3].width = width;
    rects[3].height = rects[2].height;
    XFillRectangles(Tk_Display(tkwin), drawable, gc, rects, 4);
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_DrawFocusHighlight --
 *
 *	This function draws a rectangular ring around the outside of a widget
 *	to indicate that it has received the input focus.
 *
 *	This function is now deprecated. Use TkpDrawHighlightBorder instead,
 *	since this function does not handle drawing the Focus ring properly on
 *	the Macintosh - you need to know the background GC as well as the
 *	foreground since the Mac focus ring separated from the widget by a 1
 *	pixel border.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	A rectangle "width" pixels wide is drawn in "drawable", corresponding
 *	to the outer area of "tkwin".
 *
 *----------------------------------------------------------------------
 */

void
Tk_DrawFocusHighlight(
    Tk_Window tkwin,		/* Window whose focus highlight ring is to be
				 * drawn. */
    GC gc,			/* Graphics context to use for drawing the
				 * highlight ring. */
    int width,			/* Width of the highlight ring, in pixels. */
    Drawable drawable)		/* Where to draw the ring (typically a pixmap
				 * for double buffering). */
{
    TkDrawInsetFocusHighlight(tkwin, gc, width, drawable, 0);
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_GetScrollInfo --
 *
 *	This function is invoked to parse "xview" and "yview" scrolling
 *	commands for widgets using the new scrolling command syntax ("moveto"
 *	or "scroll" options).
 *
 * Results:
 *	The return value is either TK_SCROLL_MOVETO, TK_SCROLL_PAGES,
 *	TK_SCROLL_UNITS, or TK_SCROLL_ERROR. This indicates whether the
 *	command was successfully parsed and what form the command took. If
 *	TK_SCROLL_MOVETO, *dblPtr is filled in with the desired position; if
 *	TK_SCROLL_PAGES or TK_SCROLL_UNITS, *intPtr is filled in with the
 *	number of lines to move (may be negative); if TK_SCROLL_ERROR, the
 *	interp's result contains an error message.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
Tk_GetScrollInfo(
    Tcl_Interp *interp,		/* Used for error reporting. */
    int argc,			/* # arguments for command. */
    const char **argv,		/* Arguments for command. */
    double *dblPtr,		/* Filled in with argument "moveto" option, if
				 * any. */
    int *intPtr)		/* Filled in with number of pages or lines to
				 * scroll, if any. */
{
    int c = argv[2][0];
    size_t length = strlen(argv[2]);

    if ((c == 'm') && (strncmp(argv[2], "moveto", length) == 0)) {
	if (argc != 4) {
	    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
		    " ", argv[1], " moveto fraction\"", NULL);
	    return TK_SCROLL_ERROR;
	}
	if (Tcl_GetDouble(interp, argv[3], dblPtr) != TCL_OK) {
	    return TK_SCROLL_ERROR;
	}
	return TK_SCROLL_MOVETO;
    } else if ((c == 's')
	    && (strncmp(argv[2], "scroll", length) == 0)) {
	if (argc != 5) {
	    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
		    " ", argv[1], " scroll number units|pages\"", NULL);
	    return TK_SCROLL_ERROR;
	}
	if (Tcl_GetInt(interp, argv[3], intPtr) != TCL_OK) {
	    return TK_SCROLL_ERROR;
	}
	length = strlen(argv[4]);
	c = argv[4][0];
	if ((c == 'p') && (strncmp(argv[4], "pages", length) == 0)) {
	    return TK_SCROLL_PAGES;
	} else if ((c == 'u') && (strncmp(argv[4], "units", length) == 0)) {
	    return TK_SCROLL_UNITS;
	}

	Tcl_AppendResult(interp, "bad argument \"", argv[4],
		"\": must be units or pages", NULL);
	return TK_SCROLL_ERROR;
    }
    Tcl_AppendResult(interp, "unknown option \"", argv[2],
	    "\": must be moveto or scroll", NULL);
    return TK_SCROLL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_GetScrollInfoObj --
 *
 *	This function is invoked to parse "xview" and "yview" scrolling
 *	commands for widgets using the new scrolling command syntax ("moveto"
 *	or "scroll" options).
 *
 * Results:
 *	The return value is either TK_SCROLL_MOVETO, TK_SCROLL_PAGES,
 *	TK_SCROLL_UNITS, or TK_SCROLL_ERROR. This indicates whether the
 *	command was successfully parsed and what form the command took. If
 *	TK_SCROLL_MOVETO, *dblPtr is filled in with the desired position; if
 *	TK_SCROLL_PAGES or TK_SCROLL_UNITS, *intPtr is filled in with the
 *	number of lines to move (may be negative); if TK_SCROLL_ERROR, the
 *	interp's result contains an error message.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
Tk_GetScrollInfoObj(
    Tcl_Interp *interp,		/* Used for error reporting. */
    int objc,			/* # arguments for command. */
    Tcl_Obj *const objv[],	/* Arguments for command. */
    double *dblPtr,		/* Filled in with argument "moveto" option, if
				 * any. */
    int *intPtr)		/* Filled in with number of pages or lines to
				 * scroll, if any. */
{
    int length;
    const char *arg = Tcl_GetStringFromObj(objv[2], &length);

#define ArgPfxEq(str) \
	((arg[0] == str[0]) && !strncmp(arg, str, (unsigned)length))

    if (ArgPfxEq("moveto")) {
	if (objc != 4) {
	    Tcl_WrongNumArgs(interp, 2, objv, "moveto fraction");
	    return TK_SCROLL_ERROR;
	}
	if (Tcl_GetDoubleFromObj(interp, objv[3], dblPtr) != TCL_OK) {
	    return TK_SCROLL_ERROR;
	}
	return TK_SCROLL_MOVETO;
    } else if (ArgPfxEq("scroll")) {
	if (objc != 5) {
	    Tcl_WrongNumArgs(interp, 2, objv, "scroll number units|pages");
	    return TK_SCROLL_ERROR;
	}
	if (Tcl_GetIntFromObj(interp, objv[3], intPtr) != TCL_OK) {
	    return TK_SCROLL_ERROR;
	}

	arg = Tcl_GetStringFromObj(objv[4], &length);
	if (ArgPfxEq("pages")) {
	    return TK_SCROLL_PAGES;
	} else if (ArgPfxEq("units")) {
	    return TK_SCROLL_UNITS;
	}

	Tcl_AppendResult(interp, "bad argument \"", arg,
		"\": must be units or pages", NULL);
	return TK_SCROLL_ERROR;
    }
    Tcl_AppendResult(interp, "unknown option \"", arg,
	    "\": must be moveto or scroll", NULL);
    return TK_SCROLL_ERROR;
}

/*
 *---------------------------------------------------------------------------
 *
 * TkComputeAnchor --
 *
 *	Determine where to place a rectangle so that it will be properly
 *	anchored with respect to the given window. Used by widgets to align a
 *	box of text inside a window. When anchoring with respect to one of the
 *	sides, the rectangle be placed inside of the internal border of the
 *	window.
 *
 * Results:
 *	*xPtr and *yPtr set to the upper-left corner of the rectangle anchored
 *	in the window.
 *
 * Side effects:
 *	None.
 *
 *---------------------------------------------------------------------------
 */

void
TkComputeAnchor(
    Tk_Anchor anchor,		/* Desired anchor. */
    Tk_Window tkwin,		/* Anchored with respect to this window. */
    int padX, int padY,		/* Use this extra padding inside window, in
				 * addition to the internal border. */
    int innerWidth, int innerHeight,
				/* Size of rectangle to anchor in window. */
    int *xPtr, int *yPtr)	/* Returns upper-left corner of anchored
				 * rectangle. */
{
    /*
     * Handle the horizontal parts.
     */

    switch (anchor) {
    case TK_ANCHOR_NW:
    case TK_ANCHOR_W:
    case TK_ANCHOR_SW:
	*xPtr = Tk_InternalBorderLeft(tkwin) + padX;
	break;

    case TK_ANCHOR_N:
    case TK_ANCHOR_CENTER:
    case TK_ANCHOR_S:
	*xPtr = (Tk_Width(tkwin) - innerWidth - Tk_InternalBorderLeft(tkwin) -
		Tk_InternalBorderRight(tkwin)) / 2 +
		Tk_InternalBorderLeft(tkwin);
	break;

    default:
	*xPtr = Tk_Width(tkwin) - Tk_InternalBorderRight(tkwin) - padX
		- innerWidth;
	break;
    }

    /*
     * Handle the vertical parts.
     */

    switch (anchor) {
    case TK_ANCHOR_NW:
    case TK_ANCHOR_N:
    case TK_ANCHOR_NE:
	*yPtr = Tk_InternalBorderTop(tkwin) + padY;
	break;

    case TK_ANCHOR_W:
    case TK_ANCHOR_CENTER:
    case TK_ANCHOR_E:
	*yPtr = (Tk_Height(tkwin) - innerHeight- Tk_InternalBorderTop(tkwin) -
		Tk_InternalBorderBottom(tkwin)) / 2 +
		Tk_InternalBorderTop(tkwin);
	break;

    default:
	*yPtr = Tk_Height(tkwin) - Tk_InternalBorderBottom(tkwin) - padY
		- innerHeight;
	break;
    }
}

/*
 *---------------------------------------------------------------------------
 *
 * TkFindStateString --
 *
 *	Given a lookup table, map a number to a string in the table.
 *
 * Results:
 *	If numKey was equal to the numeric key of one of the elements in the
 *	table, returns the string key of that element. Returns NULL if numKey
 *	was not equal to any of the numeric keys in the table.
 *
 * Side effects.
 *	None.
 *
 *---------------------------------------------------------------------------
 */

const char *
TkFindStateString(
    const TkStateMap *mapPtr,	/* The state table. */
    int numKey)			/* The key to try to find in the table. */
{
    for (; mapPtr->strKey!=NULL ; mapPtr++) {
	if (numKey == mapPtr->numKey) {
	    return mapPtr->strKey;
	}
    }
    return NULL;
}

/*
 *---------------------------------------------------------------------------
 *
 * TkFindStateNum, TkFindStateNumObj --
 *
 *	Given a lookup table, map a string to a number in the table.
 *
 * Results:
 *	If strKey was equal to the string keys of one of the elements in the
 *	table, returns the numeric key of that element. Returns the numKey
 *	associated with the last element (the NULL string one) in the table if
 *	strKey was not equal to any of the string keys in the table. In that
 *	case, an error message is also left in the interp's result (if interp
 *	is not NULL).
 *
 * Side effects.
 *	None.
 *
 *---------------------------------------------------------------------------
 */

int
TkFindStateNum(
    Tcl_Interp *interp,		/* Interp for error reporting. */
    const char *option,		/* String to use when constructing error. */
    const TkStateMap *mapPtr,	/* Lookup table. */
    const char *strKey)		/* String to try to find in lookup table. */
{
    const TkStateMap *mPtr;

    /*
     * See if the value is in the state map.
     */

    for (mPtr = mapPtr; mPtr->strKey != NULL; mPtr++) {
	if (strcmp(strKey, mPtr->strKey) == 0) {
	    return mPtr->numKey;
	}
    }

    /*
     * Not there. Generate an error message (if we can) and return the
     * default.
     */

    if (interp != NULL) {
	mPtr = mapPtr;
	Tcl_AppendResult(interp, "bad ", option, " value \"", strKey,
		"\": must be ", mPtr->strKey, NULL);
	for (mPtr++; mPtr->strKey != NULL; mPtr++) {
	    Tcl_AppendResult(interp,
		    ((mPtr[1].strKey != NULL) ? ", " : ", or "),
		    mPtr->strKey, NULL);
	}
    }
    return mPtr->numKey;
}

int
TkFindStateNumObj(
    Tcl_Interp *interp,		/* Interp for error reporting. */
    Tcl_Obj *optionPtr,		/* String to use when constructing error. */
    const TkStateMap *mapPtr,	/* Lookup table. */
    Tcl_Obj *keyPtr)		/* String key to find in lookup table. */
{
    const TkStateMap *mPtr;
    const char *key;
    const Tcl_ObjType *typePtr;

    /*
     * See if the value is in the object cache.
     */

    if ((keyPtr->typePtr == &tkStateKeyObjType)
	    && (keyPtr->internalRep.twoPtrValue.ptr1 == mapPtr)) {
	return PTR2INT(keyPtr->internalRep.twoPtrValue.ptr2);
    }

    /*
     * Not there. Look in the state map.
     */

    key = Tcl_GetStringFromObj(keyPtr, NULL);
    for (mPtr = mapPtr; mPtr->strKey != NULL; mPtr++) {
	if (strcmp(key, mPtr->strKey) == 0) {
	    typePtr = keyPtr->typePtr;
	    if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) {
		typePtr->freeIntRepProc(keyPtr);
	    }
	    keyPtr->internalRep.twoPtrValue.ptr1 = (void *) mapPtr;
	    keyPtr->internalRep.twoPtrValue.ptr2 = INT2PTR(mPtr->numKey);
	    keyPtr->typePtr = &tkStateKeyObjType;
	    return mPtr->numKey;
	}
    }

    /*
     * Not there either. Generate an error message (if we can) and return the
     * default.
     */

    if (interp != NULL) {
	mPtr = mapPtr;
	Tcl_AppendResult(interp, "bad ", Tcl_GetString(optionPtr),
		" value \"", key, "\": must be ", mPtr->strKey, NULL);
	for (mPtr++; mPtr->strKey != NULL; mPtr++) {
	    Tcl_AppendResult(interp,
		((mPtr[1].strKey != NULL) ? ", " : ", or "),
		mPtr->strKey, NULL);
	}
    }
    return mPtr->numKey;
}

/*
 * ----------------------------------------------------------------------
 *
 * TkBackgroundEvalObjv --
 *
 *	Evaluate a command while ensuring that we do not affect the
 *	interpreters state. This is important when evaluating script
 *	during background tasks.
 *
 * Results:
 *	A standard Tcl result code.
 *
 * Side Effects:
 *	The interpreters variables and code may be modified by the script
 *	but the result will not be modified.
 *
 * ----------------------------------------------------------------------
 */

int
TkBackgroundEvalObjv(
    Tcl_Interp *interp,
    int objc,
    Tcl_Obj *const *objv,
    int flags)
{
    Tcl_DString errorInfo, errorCode;
    Tcl_SavedResult state;
    int n, r = TCL_OK;

    Tcl_DStringInit(&errorInfo);
    Tcl_DStringInit(&errorCode);

    Tcl_Preserve(interp);

    /*
     * Record the state of the interpreter
     */

    Tcl_SaveResult(interp, &state);
    Tcl_DStringAppend(&errorInfo,
	Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY), -1);
    Tcl_DStringAppend(&errorCode,
	Tcl_GetVar(interp, "errorCode", TCL_GLOBAL_ONLY), -1);

    /*
     * Evaluate the command and handle any error.
     */

    for (n = 0; n < objc; ++n) {
	Tcl_IncrRefCount(objv[n]);
    }
    r = Tcl_EvalObjv(interp, objc, objv, flags);
    for (n = 0; n < objc; ++n) {
	Tcl_DecrRefCount(objv[n]);
    }
    if (r == TCL_ERROR) {
	Tcl_AddErrorInfo(interp, "\n    (background event handler)");
	Tcl_BackgroundException(interp, r);
    }

    Tcl_Release(interp);

    /*
     * Restore the state of the interpreter
     */

    Tcl_SetVar(interp, "errorInfo",
	Tcl_DStringValue(&errorInfo), TCL_GLOBAL_ONLY);
    Tcl_SetVar(interp, "errorCode",
	Tcl_DStringValue(&errorCode), TCL_GLOBAL_ONLY);
    Tcl_RestoreResult(interp, &state);

    /*
     * Clean up references.
     */

    Tcl_DStringFree(&errorInfo);
    Tcl_DStringFree(&errorCode);

    return r;
}

/*
 *----------------------------------------------------------------------
 *
 * TkMakeEnsemble --
 *
 *	Create an ensemble from a table of implementation commands. This may
 *	be called recursively to create sub-ensembles.
 *
 * Results:
 *	Handle for the ensemble, or NULL if creation of it fails.
 *
 *----------------------------------------------------------------------
 */

Tcl_Command
TkMakeEnsemble(
    Tcl_Interp *interp,
    const char *namespace,
    const char *name,
    ClientData clientData,
    const TkEnsemble map[])
{
    Tcl_Namespace *namespacePtr = NULL;
    Tcl_Command ensemble = NULL;
    Tcl_Obj *dictObj = NULL, *nameObj;
    Tcl_DString ds;
    int i;

    if (map == NULL) {
	return NULL;
    }

    Tcl_DStringInit(&ds);

    namespacePtr = Tcl_FindNamespace(interp, namespace, NULL, 0);
    if (namespacePtr == NULL) {
	namespacePtr = Tcl_CreateNamespace(interp, namespace, NULL, NULL);
	if (namespacePtr == NULL) {
	    Tcl_Panic("failed to create namespace \"%s\"", namespace);
	}
    }

    nameObj = Tcl_NewStringObj(name, -1);
    ensemble = Tcl_FindEnsemble(interp, nameObj, 0);
    Tcl_DecrRefCount(nameObj);
    if (ensemble == NULL) {
	ensemble = Tcl_CreateEnsemble(interp, name, namespacePtr,
		TCL_ENSEMBLE_PREFIX);
	if (ensemble == NULL) {
	    Tcl_Panic("failed to create ensemble \"%s\"", name);
	}
    }

    Tcl_DStringSetLength(&ds, 0);
    Tcl_DStringAppend(&ds, namespace, -1);
    if (!(strlen(namespace) == 2 && namespace[1] == ':')) {
	Tcl_DStringAppend(&ds, "::", -1);
    }
    Tcl_DStringAppend(&ds, name, -1);

    dictObj = Tcl_NewObj();
    for (i = 0; map[i].name != NULL ; ++i) {
	Tcl_Obj *nameObj, *fqdnObj;

	nameObj = Tcl_NewStringObj(map[i].name, -1);
	fqdnObj = Tcl_NewStringObj(Tcl_DStringValue(&ds),
		Tcl_DStringLength(&ds));
	Tcl_AppendStringsToObj(fqdnObj, "::", map[i].name, NULL);
	Tcl_DictObjPut(NULL, dictObj, nameObj, fqdnObj);
	if (map[i].proc) {
	    Tcl_CreateObjCommand(interp, Tcl_GetString(fqdnObj),
		    map[i].proc, clientData, NULL);
	} else if (map[i].subensemble) {
	    TkMakeEnsemble(interp, Tcl_DStringValue(&ds),
		    map[i].name, clientData, map[i].subensemble);
	}
    }

    if (ensemble) {
	Tcl_SetEnsembleMappingDict(interp, ensemble, dictObj);
    }

    Tcl_DStringFree(&ds);
    return ensemble;
}

/*
 *----------------------------------------------------------------------
 *
 * TkSendVirtualEvent --
 *
 * 	Send a virtual event notification to the specified target window.
 * 	Equivalent to "event generate $target <<$eventName>>"
 *
 * 	Note that we use Tk_QueueWindowEvent, not Tk_HandleEvent, so this
 * 	routine does not reenter the interpreter.
 *
 *----------------------------------------------------------------------
 */

void
TkSendVirtualEvent(
    Tk_Window target,
    const char *eventName)
{
    union {XEvent general; XVirtualEvent virtual;} event;

    memset(&event, 0, sizeof(event));
    event.general.xany.type = VirtualEvent;
    event.general.xany.serial = NextRequest(Tk_Display(target));
    event.general.xany.send_event = False;
    event.general.xany.window = Tk_WindowId(target);
    event.general.xany.display = Tk_Display(target);
    event.virtual.name = Tk_GetUid(eventName);

    Tk_QueueWindowEvent(&event.general, TCL_QUEUE_TAIL);
}
/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */
@


1.31
log
@[Tcl Bug 2857044]: Corrections following audit of Tcl_ObjType freeing
practises; the typePtr field is now cleared when an object ceases to be of
the type.
Also remove some anachronistic techniques (pointless casts, mixed assignments
and tests, etc.)
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.30 2009/08/09 21:20:33 nijtmans Exp $
d859 1
a859 1
char *
d866 1
a866 1
	    return (char *) mapPtr->strKey;
@


1.30
log
@Eliminate various gcc warnings
include <vssym32.h> only when available
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.29 2009/04/10 16:00:12 das Exp $
d64 1
a64 1
    if(value == NULL || *value == 0) {
d184 1
a184 1
    if(value == NULL || *value == 0) {
d278 1
a278 1
    switch(value[0]) {
d341 7
a347 1
    if ((q = strchr(p,',')) == NULL) {
d358 1
a368 1
  goodTSOffset:
d373 1
a373 1
     * already created, we must do it with Tk_GetTile()!!!!;
d376 1
d421 1
a421 1
	p = (char *) ckalloc(32);
d451 1
a451 1
    q = p = (char *) ckalloc(32);
d473 1
a473 1
				 * well */
d514 1
a514 1
    char *p = (char *) ckalloc(24);
d719 1
a719 3
    const char *arg;

    arg = Tcl_GetStringFromObj(objv[2], &length);
d721 2
a722 1
#define ArgPfxEq(str) ((arg[0]==str[0])&&!strncmp(arg,str,(unsigned)length))
d1043 2
a1044 2
        Tcl_AddErrorInfo(interp, "\n    (background event handler)");
        Tcl_BackgroundException(interp, r);
d1074 2
a1075 2
 *	Create an ensemble from a table of implementation commands.
 *	This may be called recursively to create sub-ensembles.
d1105 4
a1108 4
        namespacePtr = Tcl_CreateNamespace(interp, namespace, NULL, NULL);
        if (namespacePtr == NULL) {
            Tcl_Panic("failed to create namespace \"%s\"", namespace);
        }
d1115 5
a1119 5
        ensemble = Tcl_CreateEnsemble(interp, name,
	    namespacePtr, TCL_ENSEMBLE_PREFIX);
        if (ensemble == NULL) {
            Tcl_Panic("failed to create ensemble \"%s\"", name);
        }
d1135 1
a1135 1
	    Tcl_DStringLength(&ds));
d1140 1
a1140 1
		map[i].proc, clientData, NULL);
d1143 1
a1143 1
		map[i].name, clientData, map[i].subensemble);
d1163 2
a1164 2
 * 	Note that we use Tk_QueueWindowEvent, not Tk_HandleEvent,
 * 	so this routine does not reenter the interpreter.
d1170 3
a1172 1
TkSendVirtualEvent(Tk_Window target, const char *eventName)
@


1.29
log
@	* generic/tkUtil.c (TkBackgroundEvalObjv): use Tcl_BackgroundException.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.28 2009/02/06 08:12:07 das Exp $
d1166 1
a1166 1
    XEvent event;
d1169 6
a1174 6
    event.xany.type = VirtualEvent;
    event.xany.serial = NextRequest(Tk_Display(target));
    event.xany.send_event = False;
    event.xany.window = Tk_WindowId(target);
    event.xany.display = Tk_Display(target);
    ((XVirtualEvent *) &event)->name = Tk_GetUid(eventName);
d1176 1
a1176 1
    Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
@


1.28
log
@	* generic/tkImgPhInstance.c:	fix numerous leaks discovered with the
	* generic/tkMenu.c:		Mac OS X Instruments.app Leaks tool.
	* generic/tkText.c:
	* generic/tkTextImage.c:
	* generic/tkTextIndex.c:
	* generic/tkUndo.c:
	* generic/tkUtil.c:
	* generic/ttk/ttkFrame.c:
	* macosx/tkMacOSXWm.c:
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.27 2008/12/10 05:02:51 das Exp $
d1038 1
a1038 1
        Tcl_BackgroundError(interp);
@


1.27
log
@TIP #324 IMPLEMENTATION
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.26 2008/12/10 04:27:45 das Exp $
d1087 1
a1087 1
    Tcl_Obj *dictObj = NULL;
d1105 3
a1107 1
    ensemble = Tcl_FindEnsemble(interp, Tcl_NewStringObj(name,-1), 0);
@


1.26
log
@TkMakeEnsemble(): support for NULL subensemble
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.25 2008/12/10 00:34:51 das Exp $
d981 83
d1146 30
@


1.25
log
@	* generic/tkInt.h:	Turn [tk] into an ensemble (thoyts, steffen)
	* generic/tkBusy.c:
	* generic/tkCmds.c:
	* generic/tkWindow.c:
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.24 2008/11/08 18:44:40 dkf Exp $
d1050 1
a1050 1
	} else {
@


1.24
log
@Lots of small changes to make code more pretty and C89-like.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.23 2008/10/30 21:39:16 nijtmans Exp $
d981 83
@


1.23
log
@[Bug 2190619] Warnings due to Tk_SmoothMethod
name constness change.

Although dkf's solution (simply adding a type cast)
is correct as well, changing the return value (as das
suggested) has the advantage that
all Tk_OptionPrintProc implementations don't
need a type cast any more in its code. This
makes all those functions robust against
the -Wwrite-strings warning option.

Further on, the customPtr field of Tk_ConfigSpec
can be a constant, without any danger of
source incompatibility.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.22 2008/10/15 06:41:06 nijtmans Exp $
d953 1
a953 1
		(*typePtr->freeIntRepProc)(keyPtr);
@


1.22
log
@Add "const" to many internal
const tables, so those will be
put by the C-compiler in the
TEXT segment in stead of the
DATA segment. This makes those
table sharable in shared libraries.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.21 2007/12/13 15:24:21 dgp Exp $
d126 1
a126 1
char *
d227 1
a227 1
char *
d399 1
a399 1
char *
d498 1
a498 1
char *
@


1.21
log
@merge stable branch onto HEAD
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.17.2.3 2007/10/15 18:38:33 dgp Exp $
d23 1
a23 1
Tcl_ObjType tkStateKeyObjType = {
@


1.20
log
@	* generic/tkArgv.c:		Fix gcc warnings about 'cast to/from
	* generic/tkCanvUtil.c:		pointer from/to integer of different
	* generic/tkCanvas.c:		size' on 64-bit platforms by casting
	* generic/tkCursor.c:		to intermediate types
	* generic/tkInt.h:		intptr_t/uintptr_t via new PTR2INT(),
	* generic/tkListbox.c:		INT2PTR(), PTR2UINT() and UINT2PTR()
	* generic/tkObj.c:		macros.
	* generic/tkStyle.c:
	* generic/tkTextIndex.c:
	* generic/tkUtil.c:
	* generic/ttk/ttkTheme.h:
	* generic/ttk/ttkTreeview.c:
	* unix/tkUnixMenu.c:
	* unix/configure.in:

	* unix/configure:		autoconf-2.59
	* unix/tkConfig.h.in:		autoheader-2.59
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.19 2007/09/08 16:01:20 dkf Exp $
@


1.19
log
@Assorted minor cleanups.
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.18 2007/09/07 00:34:54 dgp Exp $
d59 1
a59 1
    int flags = (int)clientData;
d280 1
a280 1
	if (((int)clientData) & TK_OFFSET_RELATIVE) {
d342 1
a342 1
	if (((int)clientData) & TK_OFFSET_INDEX) {
d376 1
a376 1
    if (((int) clientData) & TK_OFFSET_RELATIVE) {
d379 1
a379 1
    if (((int) clientData) & TK_OFFSET_INDEX) {
d941 1
a941 1
	return (int) keyPtr->internalRep.twoPtrValue.ptr2;
d956 1
a956 1
	    keyPtr->internalRep.twoPtrValue.ptr2 = (void *) mPtr->numKey;
@


1.18
log
@header cleanup
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.17 2007/02/25 04:30:30 pspjuth Exp $
d138 2
a139 1
    if (*statePtr==TK_STATE_NORMAL) {
d141 1
a141 1
    } else if (*statePtr==TK_STATE_DISABLED) {
d143 1
a143 1
    } else if (*statePtr==TK_STATE_HIDDEN) {
d145 1
a145 1
    } else if (*statePtr==TK_STATE_ACTIVE) {
d147 1
a147 1
    } else {
d266 1
a266 1
    Tk_TSOffset *offsetPtr = (Tk_TSOffset *)(widgRec + offset);
d407 1
a407 1
    Tk_TSOffset *offsetPtr = (Tk_TSOffset *)(widgRec + offset);
d410 2
a411 2
    if ((offsetPtr->flags) & TK_OFFSET_INDEX) {
	if ((offsetPtr->flags) >= INT_MAX) {
d415 1
a415 1
	sprintf(p, "%d",(offsetPtr->flags & (~TK_OFFSET_INDEX)));
d419 2
a420 2
    if ((offsetPtr->flags) & TK_OFFSET_TOP) {
	if ((offsetPtr->flags) & TK_OFFSET_LEFT) {
d422 1
a422 1
	} else if ((offsetPtr->flags) & TK_OFFSET_CENTER) {
d424 1
a424 1
	} else if ((offsetPtr->flags) & TK_OFFSET_RIGHT) {
d427 2
a428 2
    } else if ((offsetPtr->flags) & TK_OFFSET_MIDDLE) {
	if ((offsetPtr->flags) & TK_OFFSET_LEFT) {
d430 1
a430 1
	} else if ((offsetPtr->flags) & TK_OFFSET_CENTER) {
d432 1
a432 1
	} else if ((offsetPtr->flags) & TK_OFFSET_RIGHT) {
d435 2
a436 2
    } else if ((offsetPtr->flags) & TK_OFFSET_BOTTOM) {
	if ((offsetPtr->flags) & TK_OFFSET_LEFT) {
d438 1
a438 1
	} else if ((offsetPtr->flags) & TK_OFFSET_CENTER) {
d440 1
a440 1
	} else if ((offsetPtr->flags) & TK_OFFSET_RIGHT) {
d445 1
a445 1
    if ((offsetPtr->flags) & TK_OFFSET_RELATIVE) {
d448 1
a448 1
    sprintf(q, "%d,%d",offsetPtr->xoffset, offsetPtr->yoffset);
d473 1
a473 1
    double *doublePtr = (double *)(widgRec + offset);
d506 2
a507 2
    double *doublePtr = (double *)(widgRec + offset);
    char *p;
a508 1
    p = (char *) ckalloc(24);
d574 5
a578 5
 *      This function is now deprecated. Use TkpDrawHighlightBorder instead,
 *      since this function does not handle drawing the Focus ring properly on
 *      the Macintosh - you need to know the background GC as well as the
 *      foreground since the Mac focus ring separated from the widget by a 1
 *      pixel border.
d637 2
a638 2
    int c;
    size_t length;
a639 2
    length = strlen(argv[2]);
    c = argv[2][0];
a665 4
	} else {
	    Tcl_AppendResult(interp, "bad argument \"", argv[4],
		    "\": must be units or pages", NULL);
	    return TK_SCROLL_ERROR;
d667 4
d711 6
a716 3
    int c;
    size_t length;
    char *arg2, *arg4;
d718 1
a718 4
    arg2 = Tcl_GetString(objv[2]);
    length = strlen(arg2);
    c = arg2[0];
    if ((c == 'm') && (strncmp(arg2, "moveto", length) == 0)) {
d727 1
a727 2
    } else if ((c == 's')
	    && (strncmp(arg2, "scroll", length) == 0)) {
d735 3
a737 4
	arg4 = Tcl_GetString(objv[4]);
	length = (strlen(arg4));
	c = arg4[0];
	if ((c == 'p') && (strncmp(arg4, "pages", length) == 0)) {
d739 1
a739 1
	} else if ((c == 'u') && (strncmp(arg4, "units", length) == 0)) {
a740 4
	} else {
	    Tcl_AppendResult(interp, "bad argument \"", arg4,
		    "\": must be units or pages", NULL);
	    return TK_SCROLL_ERROR;
d742 4
d747 1
a747 1
    Tcl_AppendResult(interp, "unknown option \"", arg2,
d784 4
d804 1
a804 1
	*xPtr = Tk_Width(tkwin) - (Tk_InternalBorderRight(tkwin) + padX)
d809 4
d858 1
a858 1
    for ( ; mapPtr->strKey != NULL; mapPtr++) {
d860 1
a860 1
	    return (char*)(mapPtr->strKey);
d869 1
a869 1
 * TkFindStateNum --
d896 4
d905 6
d935 4
d940 1
a940 1
	    && (keyPtr->internalRep.twoPtrValue.ptr1 == (VOID *) mapPtr)) {
d944 4
d955 2
a956 2
	    keyPtr->internalRep.twoPtrValue.ptr1 = (VOID *) mapPtr;
	    keyPtr->internalRep.twoPtrValue.ptr2 = (VOID *) mPtr->numKey;
d961 6
@


1.17
log
@Fixed grid anchor center problem in labelframes. [Bug 1545765]
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.16 2007/01/19 06:29:20 das Exp $
a16 1
#include "tkPort.h"
@


1.17.2.1
log
@merge updates from HEAD
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.17 2007/02/25 04:30:30 pspjuth Exp $
d17 1
@


1.17.2.2
log
@merge updates from HEAD
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.17.2.1 2007/09/07 01:25:36 dgp Exp $
d138 1
a138 2
    switch (*statePtr) {
    case TK_STATE_NORMAL:
d140 1
a140 1
    case TK_STATE_DISABLED:
d142 1
a142 1
    case TK_STATE_HIDDEN:
d144 1
a144 1
    case TK_STATE_ACTIVE:
d146 1
a146 1
    default:
d265 1
a265 1
    Tk_TSOffset *offsetPtr = (Tk_TSOffset *) (widgRec + offset);
d406 1
a406 1
    Tk_TSOffset *offsetPtr = (Tk_TSOffset *) (widgRec + offset);
d409 2
a410 2
    if (offsetPtr->flags & TK_OFFSET_INDEX) {
	if (offsetPtr->flags >= INT_MAX) {
d414 1
a414 1
	sprintf(p, "%d", offsetPtr->flags & ~TK_OFFSET_INDEX);
d418 2
a419 2
    if (offsetPtr->flags & TK_OFFSET_TOP) {
	if (offsetPtr->flags & TK_OFFSET_LEFT) {
d421 1
a421 1
	} else if (offsetPtr->flags & TK_OFFSET_CENTER) {
d423 1
a423 1
	} else if (offsetPtr->flags & TK_OFFSET_RIGHT) {
d426 2
a427 2
    } else if (offsetPtr->flags & TK_OFFSET_MIDDLE) {
	if (offsetPtr->flags & TK_OFFSET_LEFT) {
d429 1
a429 1
	} else if (offsetPtr->flags & TK_OFFSET_CENTER) {
d431 1
a431 1
	} else if (offsetPtr->flags & TK_OFFSET_RIGHT) {
d434 2
a435 2
    } else if (offsetPtr->flags & TK_OFFSET_BOTTOM) {
	if (offsetPtr->flags & TK_OFFSET_LEFT) {
d437 1
a437 1
	} else if (offsetPtr->flags & TK_OFFSET_CENTER) {
d439 1
a439 1
	} else if (offsetPtr->flags & TK_OFFSET_RIGHT) {
d444 1
a444 1
    if (offsetPtr->flags & TK_OFFSET_RELATIVE) {
d447 1
a447 1
    sprintf(q, "%d,%d", offsetPtr->xoffset, offsetPtr->yoffset);
d472 1
a472 1
    double *doublePtr = (double *) (widgRec + offset);
d505 2
a506 2
    double *doublePtr = (double *) (widgRec + offset);
    char *p = (char *) ckalloc(24);
d508 1
d574 5
a578 5
 *	This function is now deprecated. Use TkpDrawHighlightBorder instead,
 *	since this function does not handle drawing the Focus ring properly on
 *	the Macintosh - you need to know the background GC as well as the
 *	foreground since the Mac focus ring separated from the widget by a 1
 *	pixel border.
d637 2
a638 2
    int c = argv[2][0];
    size_t length = strlen(argv[2]);
d640 2
d668 4
a672 4

	Tcl_AppendResult(interp, "bad argument \"", argv[4],
		"\": must be units or pages", NULL);
	return TK_SCROLL_ERROR;
d713 3
a715 6
    int length;
    const char *arg;

    arg = Tcl_GetStringFromObj(objv[2], &length);

#define ArgPfxEq(str) ((arg[0]==str[0])&&!strncmp(arg,str,(unsigned)length))
d717 4
a720 1
    if (ArgPfxEq("moveto")) {
d729 2
a730 1
    } else if (ArgPfxEq("scroll")) {
d738 4
a741 3

	arg = Tcl_GetStringFromObj(objv[4], &length);
	if (ArgPfxEq("pages")) {
d743 1
a743 1
	} else if (ArgPfxEq("units")) {
d745 4
a749 4

	Tcl_AppendResult(interp, "bad argument \"", arg,
		"\": must be units or pages", NULL);
	return TK_SCROLL_ERROR;
d751 1
a751 1
    Tcl_AppendResult(interp, "unknown option \"", arg,
a787 4
    /*
     * Handle the horizontal parts.
     */

d804 1
a804 1
	*xPtr = Tk_Width(tkwin) - Tk_InternalBorderRight(tkwin) - padX
a808 4
    /*
     * Handle the vertical parts.
     */

d854 1
a854 1
    for (; mapPtr->strKey!=NULL ; mapPtr++) {
d856 1
a856 1
	    return (char *) mapPtr->strKey;
d865 1
a865 1
 * TkFindStateNum, TkFindStateNumObj --
a891 4
    /*
     * See if the value is in the state map.
     */

a896 6

    /*
     * Not there. Generate an error message (if we can) and return the
     * default.
     */

a920 4
    /*
     * See if the value is in the object cache.
     */

d922 1
a922 1
	    && (keyPtr->internalRep.twoPtrValue.ptr1 == mapPtr)) {
a925 4
    /*
     * Not there. Look in the state map.
     */

d933 2
a934 2
	    keyPtr->internalRep.twoPtrValue.ptr1 = (void *) mapPtr;
	    keyPtr->internalRep.twoPtrValue.ptr2 = (void *) mPtr->numKey;
a938 6

    /*
     * Not there either. Generate an error message (if we can) and return the
     * default.
     */

@


1.17.2.3
log
@merge updates from HEAD
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.17.2.2 2007/09/09 04:15:54 dgp Exp $
d59 1
a59 1
    int flags = PTR2INT(clientData);
d280 1
a280 1
	if (PTR2INT(clientData) & TK_OFFSET_RELATIVE) {
d342 1
a342 1
	if (PTR2INT(clientData) & TK_OFFSET_INDEX) {
d376 1
a376 1
    if (PTR2INT(clientData) & TK_OFFSET_RELATIVE) {
d379 1
a379 1
    if (PTR2INT(clientData) & TK_OFFSET_INDEX) {
d941 1
a941 1
	return PTR2INT(keyPtr->internalRep.twoPtrValue.ptr2);
d956 1
a956 1
	    keyPtr->internalRep.twoPtrValue.ptr2 = INT2PTR(mPtr->numKey);
@


1.16
log
@fix warning
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.15 2007/01/18 23:56:43 nijtmans Exp $
d799 3
a801 1
	*xPtr = (Tk_Width(tkwin) - innerWidth) / 2;
d820 3
a822 1
	*yPtr = (Tk_Height(tkwin) - innerHeight) / 2;
@


1.15
log
@various "const" additions, in line with TIP #27
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.14 2005/11/13 20:42:54 dkf Exp $
d853 1
a853 1
	    return mapPtr->strKey;
@


1.14
log
@Typo fix
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.13 2005/11/13 00:45:47 dkf Exp $
d55 1
a55 1
    CONST char *value,		/* Value of option. */
d175 1
a175 1
    CONST char *value,		/* Value of option. */
d262 1
a262 1
    CONST char *value,		/* Name of image */
d268 1
a268 1
    CONST char *q, *p;
d469 1
a469 1
    CONST char *value,		/* Name of image */
d632 1
a632 1
    CONST char **argv,		/* Arguments for command. */
d708 1
a708 1
    Tcl_Obj *CONST objv[],	/* Arguments for command. */
d848 1
a848 1
    CONST TkStateMap *mapPtr,	/* The state table. */
d883 3
a885 3
    CONST char *option,		/* String to use when constructing error. */
    CONST TkStateMap *mapPtr,	/* Lookup table. */
    CONST char *strKey)		/* String to try to find in lookup table. */
d887 1
a887 1
    CONST TkStateMap *mPtr;
d911 1
a911 1
    CONST TkStateMap *mapPtr,	/* Lookup table. */
d914 3
a916 3
    CONST TkStateMap *mPtr;
    CONST char *key;
    CONST Tcl_ObjType *typePtr;
@


1.13
log
@ANSIfy
@
text
@d13 1
a13 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.12 2002/08/05 04:30:40 dgp Exp $
d784 1
a784 1
    int innerWidth, int innerHeight;
@


1.12
log
@Applied companion patch for Tcl Patch 585105,
updating Tk to use Tcl 8.4's fully CONST-ified
interface, and fully CONSTifying Tk at the
same time.

This patch includes purging Tk of its last
direct access to interp->result.  [Bug 589853]

The substantial changes include copying
event sequence strings into Tcl_DStrings
in tkBind.c, and copying [text] indices into
Tcl_DStrings because parsing them involved
overwriting them.  If this causes performance
trouble, that can be resolved by further
converting them to Tcl_Obj's.

The #defines USE_NON_CONST and USE_COMPAT_CONST
have the same effect for Tk as they do for Tcl.
(They actually change tcl.h)
@
text
@d1 1
a1 1
/* 
d4 2
a5 3
 *	This file contains miscellaneous utility procedures that
 *	are used by the rest of Tk, such as a procedure for drawing
 *	a focus highlight.
d10 2
a11 2
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
d13 1
a13 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.11 2001/09/26 20:25:17 pspjuth Exp $
d20 2
a21 2
 * The structure below defines the implementation of the "statekey"
 * Tcl object, used for quickly finding a mapping in a TkStateMap.
d25 5
a29 5
    "statekey",				/* name */
    (Tcl_FreeInternalRepProc *) NULL,	/* freeIntRepProc */
    (Tcl_DupInternalRepProc *) NULL,	/* dupIntRepProc */
    (Tcl_UpdateStringProc *) NULL,	/* updateStringProc */
    (Tcl_SetFromAnyProc *) NULL		/* setFromAnyProc */
a30 1

d37 2
a38 2
 *	This procedure is invoked during option processing to handle
 *	the "-state" and "-default" options.
d44 2
a45 2
 *	The state for a given item gets replaced by the state
 *	indicated in the value argument.
d51 7
a57 7
TkStateParseProc(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. */
d91 1
a91 2
	    " value \"", value, "\": must be normal",
	    (char *) NULL);
d93 1
a93 1
	Tcl_AppendResult(interp, ", active",(char *) NULL);
d96 1
a96 1
	Tcl_AppendResult(interp, ", hidden",(char *) NULL);
d99 1
a99 1
	Tcl_AppendResult(interp, ",",(char *) NULL);
d101 1
a101 1
    Tcl_AppendResult(interp, " or disabled",(char *) NULL);
d111 2
a112 3
 *	This procedure is invoked by the Tk configuration code
 *	to produce a printable string for the "-state"
 *	configuration option.
d115 5
a119 5
 *	The return value is a string describing the state 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).
d128 8
a135 8
TkStatePrintProc(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. */
d157 2
a158 2
 *	This procedure is invoked during option processing to handle
 *	the "-orient" option.
d171 7
a177 7
TkOrientParseProc(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. */
d201 1
a201 2
	    "\": must be vertical or horizontal",
	    (char *) NULL);
d211 2
a212 3
 *	This procedure is invoked by the Tk configuration code
 *	to produce a printable string for the "-orient"
 *	configuration option.
d215 5
a219 5
 *	The return value is a string describing the orientation 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).
d228 8
a235 8
TkOrientPrintProc(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. */
d251 2
a252 1
 *	Converts the offset of a stipple or tile into the Tk_TSOffset structure.
d258 7
a264 7
TkOffsetParseProc(clientData, interp, tkwin, value, widgRec, offset)
    ClientData clientData;	/* not used */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Window on same display as tile */
    CONST char *value;		/* Name of image */
    char *widgRec;		/* Widget structure record */
    int offset;			/* Offset of tile in record */
d279 11
a289 19
	case '#':
	    if (((int)clientData) & TK_OFFSET_RELATIVE) {
		tsoffset.flags = TK_OFFSET_RELATIVE;
		p++; break;
	    }
	    goto badTSOffset;
	case 'e':
	    switch(value[1]) {
		case '\0':
		    tsoffset.flags = TK_OFFSET_RIGHT|TK_OFFSET_MIDDLE;
		    goto goodTSOffset;
		case 'n':
		    if (value[2]!='d' || value[3]!='\0') {goto badTSOffset;}
		    tsoffset.flags = INT_MAX;
		    goto goodTSOffset;
	    }
	case 'w':
	    if (value[1] != '\0') {goto badTSOffset;}
	    tsoffset.flags = TK_OFFSET_LEFT|TK_OFFSET_MIDDLE;
d292 1
a292 1
	    if ((value[1] != '\0') && (value[2] != '\0')) {
d295 9
a303 8
	    switch(value[1]) {
		case '\0': tsoffset.flags = TK_OFFSET_CENTER|TK_OFFSET_TOP;
			   goto goodTSOffset;
		case 'w': tsoffset.flags = TK_OFFSET_LEFT|TK_OFFSET_TOP;
			   goto goodTSOffset;
		case 'e': tsoffset.flags = TK_OFFSET_RIGHT|TK_OFFSET_TOP;
			   goto goodTSOffset;
	    }
d305 15
a319 12
	case 's':
	    if ((value[1] != '\0') && (value[2] != '\0')) {
		goto badTSOffset;
	    }
	    switch(value[1]) {
		case '\0': tsoffset.flags = TK_OFFSET_CENTER|TK_OFFSET_BOTTOM;
			   goto goodTSOffset;
		case 'w': tsoffset.flags = TK_OFFSET_LEFT|TK_OFFSET_BOTTOM;
			   goto goodTSOffset;
		case 'e': tsoffset.flags = TK_OFFSET_RIGHT|TK_OFFSET_BOTTOM;
			   goto goodTSOffset;
	    }
d321 10
a330 5
	case 'c':
	    if (strncmp(value, "center", strlen(value)) != 0) {
		goto badTSOffset;
	    }
	    tsoffset.flags = TK_OFFSET_CENTER|TK_OFFSET_MIDDLE;
d332 8
d358 1
a358 1
    if (Tk_GetPixels(interp, tkwin, (char *) q+1, &tsoffset.yoffset) != TCL_OK) {
d362 6
a367 7

goodTSOffset:
    /* below is a hack to allow the stipple/tile offset to be stored
     * in the internal tile structure. Most of the times, offsetPtr
     * is a pointer to an already existing tile structure. However
     * if this structure is not already created, we must do it
     * with Tk_GetTile()!!!!;
d370 1
a370 1
    memcpy(offsetPtr,&tsoffset, sizeof(Tk_TSOffset));
d373 1
a373 1
badTSOffset:
d375 1
a375 1
	    "\": expected \"x,y\"", (char *) NULL);
d377 1
a377 1
	Tcl_AppendResult(interp, ", \"#x,y\"", (char *) NULL);
d380 1
a380 1
	Tcl_AppendResult(interp, ", <index>", (char *) NULL);
d382 1
a382 2
    Tcl_AppendResult(interp, ", n, ne, e, se, s, sw, w, nw, or center",
	    (char *) NULL);
d400 6
a405 6
TkOffsetPrintProc(clientData, tkwin, widgRec, offset, freeProcPtr)
    ClientData clientData;	/* not used */
    Tk_Window tkwin;		/* not used */
    char *widgRec;		/* Widget structure record */
    int offset;			/* Offset of tile in record */
    Tcl_FreeProc **freeProcPtr;	/* not used */
d443 1
a443 1
    } 
a452 1

d464 8
a471 8
TkPixelParseProc(clientData, interp, tkwin, value, widgRec, offset)
    ClientData clientData;	/* if non-NULL, negative values are
				 * allowed as well */
    Tcl_Interp *interp;		/* Interpreter to send results back to */
    Tk_Window tkwin;		/* Window on same display as tile */
    CONST char *value;		/* Name of image */
    char *widgRec;		/* Widget structure record */
    int offset;			/* Offset of tile in record */
d479 1
a479 2
	Tcl_AppendResult(interp, "bad screen distance \"", value,
		"\"", (char *) NULL);
d499 6
a504 6
TkPixelPrintProc(clientData, tkwin, widgRec, offset, freeProcPtr)
    ClientData clientData;	/* not used */
    Tk_Window tkwin;		/* not used */
    char *widgRec;		/* Widget structure record */
    int offset;			/* Offset of tile in record */
    Tcl_FreeProc **freeProcPtr;	/* not used */
d510 1
a510 1
    Tcl_PrintDouble((Tcl_Interp *) NULL, *doublePtr, p);
d520 4
a523 4
 *	This procedure draws a rectangular ring around the outside of
 *	a widget to indicate that it has received the input focus.  It
 *	takes an additional padding argument that specifies how much
 *	padding is present outside th widget.
d529 2
a530 2
 *	A rectangle "width" pixels wide is drawn in "drawable",
 *	corresponding to the outer area of "tkwin".
d536 9
a544 9
TkDrawInsetFocusHighlight(tkwin, gc, width, drawable, padding)
    Tk_Window tkwin;		/* Window whose focus highlight ring is
				 * to be drawn. */
    GC gc;			/* Graphics context to use for drawing
				 * the highlight ring. */
    int width;			/* Width of the highlight ring, in pixels. */
    Drawable drawable;		/* Where to draw the ring (typically a
				 * pixmap for double buffering). */
    int padding;		/* Width of padding outside of widget. */
d572 2
a573 2
 *	This procedure draws a rectangular ring around the outside of
 *	a widget to indicate that it has received the input focus.
d575 5
a579 5
 *      This function is now deprecated.  Use TkpDrawHighlightBorder instead,
 *      since this function does not handle drawing the Focus ring properly
 *      on the Macintosh - you need to know the background GC as well 
 *      as the foreground since the Mac focus ring separated from the widget
 *      by a 1 pixel border.
d585 2
a586 2
 *	A rectangle "width" pixels wide is drawn in "drawable",
 *	corresponding to the outer area of "tkwin".
d592 8
a599 8
Tk_DrawFocusHighlight(tkwin, gc, width, drawable)
    Tk_Window tkwin;		/* Window whose focus highlight ring is
				 * to be drawn. */
    GC gc;			/* Graphics context to use for drawing
				 * the highlight ring. */
    int width;			/* Width of the highlight ring, in pixels. */
    Drawable drawable;		/* Where to draw the ring (typically a
				 * pixmap for double buffering). */
d609 3
a611 3
 *	This procedure is invoked to parse "xview" and "yview"
 *	scrolling commands for widgets using the new scrolling
 *	command syntax ("moveto" or "scroll" options).
d615 6
a620 7
 *	TK_SCROLL_UNITS, or TK_SCROLL_ERROR.  This indicates whether
 *	the command was successfully parsed and what form the command
 *	took.  If TK_SCROLL_MOVETO, *dblPtr is filled in with the
 *	desired position;  if TK_SCROLL_PAGES or TK_SCROLL_UNITS,
 *	*intPtr is filled in with the number of lines to move (may be
 *	negative);  if TK_SCROLL_ERROR, the interp's result contains an
 *	error message.
d629 8
a636 8
Tk_GetScrollInfo(interp, argc, argv, dblPtr, intPtr)
    Tcl_Interp *interp;			/* Used for error reporting. */
    int argc;				/* # arguments for command. */
    CONST char **argv;			/* Arguments for command. */
    double *dblPtr;			/* Filled in with argument "moveto"
					 * option, if any. */
    int *intPtr;			/* Filled in with number of pages
					 * or lines to scroll, if any. */
d645 2
a646 3
	    Tcl_AppendResult(interp, "wrong # args: should be \"",
		    argv[0], " ", argv[1], " moveto fraction\"",
		    (char *) NULL);
d656 2
a657 3
	    Tcl_AppendResult(interp, "wrong # args: should be \"",
		    argv[0], " ", argv[1], " scroll number units|pages\"",
		    (char *) NULL);
d667 1
a667 2
	} else if ((c == 'u')
		&& (strncmp(argv[4], "units", length) == 0)) {
d671 1
a671 1
		    "\": must be units or pages", (char *) NULL);
d676 1
a676 1
	    "\": must be moveto or scroll", (char *) NULL);
d685 3
a687 3
 *	This procedure is invoked to parse "xview" and "yview"
 *	scrolling commands for widgets using the new scrolling
 *	command syntax ("moveto" or "scroll" options).
d691 6
a696 7
 *	TK_SCROLL_UNITS, or TK_SCROLL_ERROR.  This indicates whether
 *	the command was successfully parsed and what form the command
 *	took.  If TK_SCROLL_MOVETO, *dblPtr is filled in with the
 *	desired position;  if TK_SCROLL_PAGES or TK_SCROLL_UNITS,
 *	*intPtr is filled in with the number of lines to move (may be
 *	negative);  if TK_SCROLL_ERROR, the interp's result contains an
 *	error message.
d705 8
a712 8
Tk_GetScrollInfoObj(interp, objc, objv, dblPtr, intPtr)
    Tcl_Interp *interp;			/* Used for error reporting. */
    int objc;				/* # arguments for command. */
    Tcl_Obj *CONST objv[];		/* Arguments for command. */
    double *dblPtr;			/* Filled in with argument "moveto"
					 * option, if any. */
    int *intPtr;			/* Filled in with number of pages
					 * or lines to scroll, if any. */
d744 1
a744 2
	} else if ((c == 'u')
		&& (strncmp(arg4, "units", length) == 0)) {
d748 1
a748 1
		    "\": must be units or pages", (char *) NULL);
d753 1
a753 1
	    "\": must be moveto or scroll", (char *) NULL);
d763 4
a766 4
 *	anchored with respect to the given window.  Used by widgets
 *	to align a box of text inside a window.  When anchoring with
 *	respect to one of the sides, the rectangle be placed inside of
 *	the internal border of the window.
d769 2
a770 2
 *	*xPtr and *yPtr set to the upper-left corner of the rectangle
 *	anchored in the window.
d777 1
d779 4
a782 4
TkComputeAnchor(anchor, tkwin, padX, padY, innerWidth, innerHeight, xPtr, yPtr)
    Tk_Anchor anchor;		/* Desired anchor. */
    Tk_Window tkwin;		/* Anchored with respect to this window. */
    int padX, padY;		/* Use this extra padding inside window, in
d784 3
a786 2
    int innerWidth, innerHeight;/* Size of rectangle to anchor in window. */
    int *xPtr, *yPtr;		/* Returns upper-left corner of anchored
d790 16
a805 16
	case TK_ANCHOR_NW:
	case TK_ANCHOR_W:
	case TK_ANCHOR_SW:
	    *xPtr = Tk_InternalBorderLeft(tkwin) + padX;
	    break;

	case TK_ANCHOR_N:
	case TK_ANCHOR_CENTER:
	case TK_ANCHOR_S:
	    *xPtr = (Tk_Width(tkwin) - innerWidth) / 2;
	    break;

	default:
	    *xPtr = Tk_Width(tkwin) - (Tk_InternalBorderRight(tkwin) + padX)
		    - innerWidth;
	    break;
d809 16
a824 16
	case TK_ANCHOR_NW:
	case TK_ANCHOR_N:
	case TK_ANCHOR_NE:
	    *yPtr = Tk_InternalBorderTop(tkwin) + padY;
	    break;

	case TK_ANCHOR_W:
	case TK_ANCHOR_CENTER:
	case TK_ANCHOR_E:
	    *yPtr = (Tk_Height(tkwin) - innerHeight) / 2;
	    break;

	default:
	    *yPtr = Tk_Height(tkwin) - Tk_InternalBorderBottom(tkwin) - padY
		    - innerHeight;
	    break;
d836 3
a838 4
 *	If numKey was equal to the numeric key of one of the elements
 *	in the table, returns the string key of that element.
 *	Returns NULL if numKey was not equal to any of the numeric keys
 *	in the table.
d847 3
a849 3
TkFindStateString(mapPtr, numKey)
    CONST TkStateMap *mapPtr;	/* The state table. */
    int numKey;			/* The key to try to find in the table. */
d867 6
a872 6
 *	If strKey was equal to the string keys of one of the elements
 *	in the table, returns the numeric key of that element.
 *	Returns the numKey associated with the last element (the NULL
 *	string one) in the table if strKey was not equal to any of the
 *	string keys in the table.  In that case, an error message is
 *	also left in the interp's result (if interp is not NULL).
d881 5
a885 5
TkFindStateNum(interp, option, mapPtr, strKey)
    Tcl_Interp *interp;		/* Interp for error reporting. */
    CONST char *option;		/* String to use when constructing error. */
    CONST TkStateMap *mapPtr;	/* Lookup table. */
    CONST char *strKey;		/* String to try to find in lookup table. */
d897 1
a897 1
		"\": must be ", mPtr->strKey, (char *) NULL);
d899 3
a901 3
	    Tcl_AppendResult(interp, 
		    ((mPtr[1].strKey != NULL) ? ", " : ", or "), 
		    mPtr->strKey, (char *) NULL);
d908 5
a912 5
TkFindStateNumObj(interp, optionPtr, mapPtr, keyPtr)
    Tcl_Interp *interp;		/* Interp for error reporting. */
    Tcl_Obj *optionPtr;		/* String to use when constructing error. */
    CONST TkStateMap *mapPtr;	/* Lookup table. */
    Tcl_Obj *keyPtr;		/* String key to find in lookup table. */
d932 1
a932 1
	    keyPtr->typePtr = &tkStateKeyObjType;	    
d938 2
a939 3
	Tcl_AppendResult(interp, "bad ",
		Tcl_GetStringFromObj(optionPtr, NULL), " value \"", key,
		"\": must be ", mPtr->strKey, (char *) NULL);
d941 3
a943 3
	    Tcl_AppendResult(interp, 
		((mPtr[1].strKey != NULL) ? ", " : ", or "), 
		mPtr->strKey, (char *) NULL);
d948 8
@


1.12.2.1
log
@* generic/tkInt.h:	Backport of shutdown safety mods from the HEAD
* generic/tkMenu.c:	dating from 2003-12-21
* generic/tkUtil.c:
* generic/tkWindow.c:
* mac/tkMacButton.c:
* unix/tkUnixEvent.c:
* win/tkWin32Dll.c:
* win/tkWinEmbed.c:
* win/tkWinMenu.c:
* win/tkWinX.c:
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.12 2002/08/05 04:30:40 dgp Exp $
a953 146

/*
 * For each exit handler created with a call to TkCreateExitHandler
 * there is a structure of the following type:
 */

typedef struct ExitHandler {
    Tcl_ExitProc *proc;		/* Procedure to call when process exits. */
    ClientData clientData;	/* One word of information to pass to proc. */
    struct ExitHandler *nextPtr;/* Next in list of all exit handlers for
				 * this application, or NULL for end of list. */
} ExitHandler;

/*
 * There is both per-process and per-thread exit handlers.
 * The first list is controlled by a mutex.  The other is in
 * thread local storage.
 */

static ExitHandler *firstExitPtr = NULL;
				/* First in list of all exit handlers for
				 * application. */
TCL_DECLARE_MUTEX(exitMutex)

/*
 *---------------------------------------------------------------------------
 *
 * TkCreateExitHandler --
 *
 *	Same as Tcl_CreateExitHandler, but private to Tk.
 *
 * Results:
 *	None.
 *
 * Side effects.
 *	Sets a handler with Tcl_CreateExitHandler if this is the first call.
 *
 *---------------------------------------------------------------------------
 */

void
TkCreateExitHandler (proc, clientData)
    Tcl_ExitProc *proc;		/* Procedure to invoke. */
    ClientData clientData;	/* Arbitrary value to pass to proc. */
{
    ExitHandler *exitPtr;

    exitPtr = (ExitHandler *) ckalloc(sizeof(ExitHandler));
    exitPtr->proc = proc;
    exitPtr->clientData = clientData;
    Tcl_MutexLock(&exitMutex);
    if (firstExitPtr == NULL) {
	Tcl_CreateExitHandler(TkFinalize, NULL);
    }
    exitPtr->nextPtr = firstExitPtr;
    firstExitPtr = exitPtr;
    Tcl_MutexUnlock(&exitMutex);
}

/*
 *---------------------------------------------------------------------------
 *
 * TkDeleteExitHandler --
 *
 *	Same as Tcl_DeleteExitHandler, but private to Tk.
 *
 * Results:
 *	None.
 *
 * Side effects.
 *	None.
 *
 *---------------------------------------------------------------------------
 */

void
TkDeleteExitHandler (proc, clientData)
    Tcl_ExitProc *proc;		/* Procedure that was previously registered. */
    ClientData clientData;	/* Arbitrary value to pass to proc. */
{
    ExitHandler *exitPtr, *prevPtr;

    Tcl_MutexLock(&exitMutex);
    for (prevPtr = NULL, exitPtr = firstExitPtr; exitPtr != NULL;
	    prevPtr = exitPtr, exitPtr = exitPtr->nextPtr) {
	if ((exitPtr->proc == proc)
		&& (exitPtr->clientData == clientData)) {
	    if (prevPtr == NULL) {
		firstExitPtr = exitPtr->nextPtr;
	    } else {
		prevPtr->nextPtr = exitPtr->nextPtr;
	    }
	    ckfree((char *) exitPtr);
	    break;
	}
    }
    Tcl_MutexUnlock(&exitMutex);
    return;
}

/*
 *---------------------------------------------------------------------------
 *
 * TkFinalize --
 *
 *	Runs our private exit handlers and removes itself from Tcl. This is
 *	benificial should we want to protect from dangling pointers should
 *	the Tk shared library be unloaded prior to Tcl which can happen on
 *	windows should the process be forcefully exiting from an exception
 *	handler.
 *
 * Results:
 *	None.
 *
 * Side effects.
 *	None.
 *
 *---------------------------------------------------------------------------
 */

void
TkFinalize (clientData)
    ClientData clientData;	/* Arbitrary value to pass to proc. */
{
    ExitHandler *exitPtr;

    Tcl_DeleteExitHandler(TkFinalize, NULL);

    Tcl_MutexLock(&exitMutex);
    for (exitPtr = firstExitPtr; exitPtr != NULL; exitPtr = firstExitPtr) {
	/*
	 * Be careful to remove the handler from the list before
	 * invoking its callback.  This protects us against
	 * double-freeing if the callback should call
	 * Tcl_DeleteExitHandler on itself.
	 */

	firstExitPtr = exitPtr->nextPtr;
	Tcl_MutexUnlock(&exitMutex);
	(*exitPtr->proc)(exitPtr->clientData);
	ckfree((char *) exitPtr);
	Tcl_MutexLock(&exitMutex);
    }    
    firstExitPtr = NULL;
    Tcl_MutexUnlock(&exitMutex);
}
@


1.11
log
@Geometry manager changes to support TIP#18.
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.10 2001/08/15 15:44:36 dkf Exp $
d633 1
a633 1
    char **argv;			/* Arguments for command. */
@


1.11.2.1
log
@merged with trunk at tag macosx-8-4-merge-2002-08-20-trunk
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id$
d633 1
a633 1
    CONST char **argv;			/* Arguments for command. */
@


1.10
log
@Register Tk's object types with Tcl (Tcl Bug 450545)
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.9 2000/04/19 23:11:24 ericm Exp $
d797 1
a797 1
	    *xPtr = Tk_InternalBorderWidth(tkwin) + padX;
d807 1
a807 1
	    *xPtr = Tk_Width(tkwin) - (Tk_InternalBorderWidth(tkwin) + padX)
d816 1
a816 1
	    *yPtr = Tk_InternalBorderWidth(tkwin) + padY;
d826 1
a826 1
	    *yPtr = Tk_Height(tkwin) - Tk_InternalBorderWidth(tkwin) - padY
@


1.9
log
@* doc/WinViewable.3:
* unix/mkLinks: Removed docs for Tk_IsViewable.

* win/tkWinDialog.c: Removed calls to Tk_IsViewable.

* generic/tkUtil.c:
* generic/tkStubInit.c:
* generic/tkDecls.h:
* generic/tkCmds.c:
* generic/tk.decls: Removed Tk_IsViewable function (it was not
actually needed).
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.8 2000/04/18 02:18:33 ericm Exp $
d25 1
a25 1
static Tcl_ObjType stateKeyType = {
d923 1
a923 1
    if ((keyPtr->typePtr == &stateKeyType)
d937 1
a937 1
	    keyPtr->typePtr = &stateKeyType;	    
@


1.9.4.1
log
@sync with head
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.11 2001/09/26 20:25:17 pspjuth Exp $
d25 1
a25 1
Tcl_ObjType tkStateKeyObjType = {
d797 1
a797 1
	    *xPtr = Tk_InternalBorderLeft(tkwin) + padX;
d807 1
a807 1
	    *xPtr = Tk_Width(tkwin) - (Tk_InternalBorderRight(tkwin) + padX)
d816 1
a816 1
	    *yPtr = Tk_InternalBorderTop(tkwin) + padY;
d826 1
a826 1
	    *yPtr = Tk_Height(tkwin) - Tk_InternalBorderBottom(tkwin) - padY
d923 1
a923 1
    if ((keyPtr->typePtr == &tkStateKeyObjType)
d937 1
a937 1
	    keyPtr->typePtr = &tkStateKeyObjType;	    
@


1.8
log
@* win/tkWinDialog.c: Added checks for visibility of parent window
before creating MessageBox and ChooseColor dialogs; this prevents
the application from locking when the parent is withdrawn and the
message box is created.  In these cases, the window will be
created without a parent.

* unix/mkLinks: Added WinViewable.3.

* tests/msgbox.test: Added tests for patch from [Bug: 4997].

* library/msgbox.tcl:
* library/dialog.tcl: Applied patch from [Bug: 4997]; detaches
dialog window from parent if parent is not viewable.

* library/bgerror.tcl: Removed workaround from [Bug: 4370]; this
is superceeded by patches to dialog.tcl.

* generic/tkCmds.c: Changed WinfoObjCmd to use Tk_IsViewable
function to determine visibility of windows instead of inlining
the code.

* generic/tkStubInit.c:
* generic/tkDecls.h:
* generic/tk.decls: Added Tk_IsViewable declaration.
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.7 1999/12/14 06:52:34 hobbs Exp $
a952 34
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_IsViewable --
 *
 *	Given a Tk_Window pointer, determine if that window is viewable.
 *
 * Results:
 *	1 if the window is viewable, 0 otherwise.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
Tk_IsViewable(tkwin)
    Tk_Window tkwin;		/* Pointer to the window to examine */
{
    TkWindow *winPtr = (TkWindow *)tkwin;
    int viewable = 0;
    for ( ; ; winPtr = winPtr->parentPtr) {
	if ((winPtr == NULL) || !(winPtr->flags & TK_MAPPED)) {
	    break;
	}
	if (winPtr->flags & TK_TOP_LEVEL) {
	    viewable = 1;
	    break;
	}
    }
    return viewable;
@


1.7
log
@	* generic/tkStubInit.c:
	* generic/tkDecls.h:
	* generic/tkIntXlibDecls.h:
	* generic/tkInt.decls: added XSetDashes and XWarpPointer
	* generic/tk.decls: added Tk_CreateSmoothMethod, and reserved
	two spots
	* generic/tk.h: added Tk_SmoothMethod struct,
	state item to canvas record, #defines for item state,
	support for using old char*-based canvas item C creation
	procedures with -DUSE_OLD_CANVAS,
	Tk_Dash, Tk_TSOffset (-offsets) & Tk_Outline structs and #defs,
	decls for dash, outline and postscript routines
	* generic/tkBind.c: added support for Quadruple clicks, and added
	the -warp option to 'event' with pointer warping routines
	* xlib/xgc.c:
	* generic/tkRectOval.c:
	* generic/tkCanvArc.c:
	* generic/tkCanvBmap.c:
	* generic/tkCanvImg.c:
	* generic/tkCanvLine.c:
	* generic/tkCanvPoly.c:
	* generic/tkCanvPs.c:
	* generic/tkCanvText.c:
	* generic/tkCanvUtil.c:
	* generic/tkCanvWind.c:
	* generic/tkCanvas.c:
	* generic/tkCanvas.h: Canvas and items received overhaul to with
	the addition of the dash patch (Nijtmans, et al)  This includes
	objectification of the 'canvas' command, as well as support for
	(where appropriate) dashes in items, extended stipple support,
	state for all items, and postscript generation of images and
	windows.  See the new canvas man page for related docs.
	* generic/tkEntry.c: added entry widget validation, see entry.n
	* generic/tkEvent.c: on simulated events, ButtonPress should
	be matched with ButtonRelease to be correct
	* generic/tkFont.c: corrected possible null reference
	* generic/tkFrame.c: made frame a Tcl_Obj based command
	* generic/tkGet.c: added TkGetDoublePixels
	* generic/tkImage.c: bug fixes from Img patch and new
	Tk_PostscriptImage and Tk_SetTSOrigin functions
	* generic/tkImgBmap.c: new ImgBmapPostscript function
	* generic/tkImgPhoto.c: new Tk_CreatePhotoOption, Tk_DitherPhoto
	* generic/tkInt.h: declarations for some new functions
	* generic/tkMessage.c: reworked relief drawing
	* generic/tkOldConfig.c: added TK_CONFIG_OBJS so old style
	ConfigureWidget calls can pass in Tcl_Obj arrays
	* generic/tkScrollbar.c:
	* generic/tkScrollbar.h: made -orient use an option table
	* generic/tkText.c:
	* generic/tkText.h: made -wrap and -state use option tables
	* generic/tkTextBTree.c:
	* generic/tkTextDisp.c:
	* generic/tkTextImage.c:
	* generic/tkTextMark.c:
	* generic/tkTextTag.c:
	* generic/tkTextWind.c: added support for -elide and -state hidden
	* generic/tkTrig.c: changed TkMakeBezierCurve to support returning
	the upper limit of points needed for spline
	* generic/tkUtil.c: new option table parsing routines
	* generic/tkWindow.c: init'ing of warp stuff, mouseButtonState
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.6 1999/08/10 05:10:52 jingham Exp $
d953 34
@


1.6
log
@Remove the #ifdef MAC_TCL from TkDrawInsetFocusHighlight, this knowledge is now properly in a "p" function, TkpDrawHighlightBorder.
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.5 1999/04/21 21:53:28 rjohnson Exp $
d33 481
@


1.5
log
@
Merged 8-1-0 into mainline.
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.4 1999/04/16 18:30:28 surles Exp $
a66 16
    /*
     * On the Macintosh the highlight ring needs to be "padded"
     * out by one pixel.  Unfortunantly, none of the Tk widgets
     * had a notion of padding between the focus ring and the
     * widget.  So we add this padding here.  This introduces
     * two things to worry about:
     *
     * 1) The widget must draw the background color covering
     *    the focus ring area before calling Tk_DrawFocusHighlight.
     * 2) It is impossible to draw a focus ring of width 1.
     *    (For the Macintosh Look & Feel use width of 3)
     */
#ifdef MAC_TCL
    width--;
#endif

d93 6
@


1.4
log
@fixed Tk comment errors
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.3 1999/04/16 01:51:24 stanton Exp $
@


1.3
log
@* Merged 8.1 branch into the main trunk
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id$
d75 1
a75 1
     *    the focus ring area before calling Tk_DrawFocus.
@


1.3.2.1
log
@
Merged with mainline.
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.4 1999/04/16 18:30:28 surles Exp $
d75 1
a75 1
     *    the focus ring area before calling Tk_DrawFocusHighlight.
@


1.2
log
@Replaced SCCS strings, fixed binary files
@
text
@d9 1
a9 1
 * Copyright (c) 1994-1995 Sun Microsystems, Inc.
d19 14
d149 1
a149 1
 *	negative);  if TK_SCROLL_ERROR, interp->result contains an
d214 79
d406 1
a406 1
 *	also left in interp->result (if interp is not NULL).
d415 1
a415 1
TkFindStateNum(interp, field, mapPtr, strKey)
d417 1
a417 1
    CONST char *field;		/* String to use when constructing error. */
d423 14
a436 2
    if (mapPtr->strKey == NULL) {
	panic("TkFindStateNum: no choices in lookup table");
d438 13
d452 6
d459 8
a466 1
	if (strcmp(strKey, mPtr->strKey) == 0) {
d472 2
a473 1
	Tcl_AppendResult(interp, "bad ", field, " value \"", strKey,
d476 3
a478 1
	    Tcl_AppendResult(interp, ", ", mPtr->strKey, (char *) NULL);
@


1.1
log
@Initial revision
@
text
@d14 1
a14 1
 * SCCS: @@(#) tkUtil.c 1.13 97/06/06 11:16:22
@


1.1.4.1
log
@initial tk8.1a2 version
@
text
@d9 1
a9 1
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
d14 1
a14 1
 * SCCS: @@(#) tkUtil.c 1.17 98/01/02 17:39:19
a18 14

/*
 * The structure below defines the implementation of the "statekey"
 * Tcl object, used for quickly finding a mapping in a TkStateMap.
 */

static Tcl_ObjType stateKeyType = {
    "statekey",				/* name */
    (Tcl_FreeInternalRepProc *) NULL,	/* freeIntRepProc */
    (Tcl_DupInternalRepProc *) NULL,	/* dupIntRepProc */
    (Tcl_UpdateStringProc *) NULL,	/* updateStringProc */
    (Tcl_SetFromAnyProc *) NULL		/* setFromAnyProc */
};

d135 1
a135 1
 *	negative);  if TK_SCROLL_ERROR, the interp's result contains an
d313 1
a313 1
 *	also left in the interp's result (if interp is not NULL).
d322 1
a322 1
TkFindStateNum(interp, option, mapPtr, strKey)
d324 1
a324 1
    CONST char *option;		/* String to use when constructing error. */
d330 2
a331 4
    for (mPtr = mapPtr; mPtr->strKey != NULL; mPtr++) {
	if (strcmp(strKey, mPtr->strKey) == 0) {
	    return mPtr->numKey;
	}
a332 23
    if (interp != NULL) {
	mPtr = mapPtr;
	Tcl_AppendResult(interp, "bad ", option, " value \"", strKey,
		"\": must be ", mPtr->strKey, (char *) NULL);
	for (mPtr++; mPtr->strKey != NULL; mPtr++) {
	    Tcl_AppendResult(interp, 
		    ((mPtr[1].strKey != NULL) ? ", " : ", or "), 
		    mPtr->strKey, (char *) NULL);
	}
    }
    return mPtr->numKey;
}

int
TkFindStateNumObj(interp, optionPtr, mapPtr, keyPtr)
    Tcl_Interp *interp;		/* Interp for error reporting. */
    Tcl_Obj *optionPtr;		/* String to use when constructing error. */
    CONST TkStateMap *mapPtr;	/* Lookup table. */
    Tcl_Obj *keyPtr;		/* String key to find in lookup table. */
{
    CONST TkStateMap *mPtr;
    CONST char *key;
    CONST Tcl_ObjType *typePtr;
a333 6
    if ((keyPtr->typePtr == &stateKeyType)
	    && (keyPtr->internalRep.twoPtrValue.ptr1 == (VOID *) mapPtr)) {
	return (int) keyPtr->internalRep.twoPtrValue.ptr2;
    }

    key = Tcl_GetStringFromObj(keyPtr, NULL);
d335 1
a335 8
	if (strcmp(key, mPtr->strKey) == 0) {
	    typePtr = keyPtr->typePtr;
	    if ((typePtr != NULL) && (typePtr->freeIntRepProc != NULL)) {
		(*typePtr->freeIntRepProc)(keyPtr);
	    }
	    keyPtr->internalRep.twoPtrValue.ptr1 = (VOID *) mapPtr;
	    keyPtr->internalRep.twoPtrValue.ptr2 = (VOID *) mPtr->numKey;
	    keyPtr->typePtr = &stateKeyType;	    
d341 1
a341 2
	Tcl_AppendResult(interp, "bad ",
		Tcl_GetStringFromObj(optionPtr, NULL), " value \"", key,
d344 1
a344 3
	    Tcl_AppendResult(interp, 
		((mPtr[1].strKey != NULL) ? ", " : ", or "), 
		mPtr->strKey, (char *) NULL);
@


1.1.4.2
log
@Merged 8.0.3 changes into 8.1
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.2 1998/09/14 18:23:20 stanton Exp $
@


1.1.4.3
log
@Eliminated last stronghold of static data in the Tk core...until the next one.
@
text
@d14 1
a14 1
 * RCS: @@(#) $Id: tkUtil.c,v 1.1.4.2 1998/09/30 02:17:27 stanton Exp $
a208 79
	    "\": must be moveto or scroll", (char *) NULL);
    return TK_SCROLL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_GetScrollInfoObj --
 *
 *	This procedure is invoked to parse "xview" and "yview"
 *	scrolling commands for widgets using the new scrolling
 *	command syntax ("moveto" or "scroll" options).
 *
 * Results:
 *	The return value is either TK_SCROLL_MOVETO, TK_SCROLL_PAGES,
 *	TK_SCROLL_UNITS, or TK_SCROLL_ERROR.  This indicates whether
 *	the command was successfully parsed and what form the command
 *	took.  If TK_SCROLL_MOVETO, *dblPtr is filled in with the
 *	desired position;  if TK_SCROLL_PAGES or TK_SCROLL_UNITS,
 *	*intPtr is filled in with the number of lines to move (may be
 *	negative);  if TK_SCROLL_ERROR, the interp's result contains an
 *	error message.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
Tk_GetScrollInfoObj(interp, objc, objv, dblPtr, intPtr)
    Tcl_Interp *interp;			/* Used for error reporting. */
    int objc;				/* # arguments for command. */
    Tcl_Obj *CONST objv[];		/* Arguments for command. */
    double *dblPtr;			/* Filled in with argument "moveto"
					 * option, if any. */
    int *intPtr;			/* Filled in with number of pages
					 * or lines to scroll, if any. */
{
    int c;
    size_t length;
    char *arg2, *arg4;

    arg2 = Tcl_GetString(objv[2]);
    length = strlen(arg2);
    c = arg2[0];
    if ((c == 'm') && (strncmp(arg2, "moveto", length) == 0)) {
	if (objc != 4) {
	    Tcl_WrongNumArgs(interp, 2, objv, "moveto fraction");
	    return TK_SCROLL_ERROR;
	}
	if (Tcl_GetDoubleFromObj(interp, objv[3], dblPtr) != TCL_OK) {
	    return TK_SCROLL_ERROR;
	}
	return TK_SCROLL_MOVETO;
    } else if ((c == 's')
	    && (strncmp(arg2, "scroll", length) == 0)) {
	if (objc != 5) {
	    Tcl_WrongNumArgs(interp, 2, objv, "scroll number units|pages");
	    return TK_SCROLL_ERROR;
	}
	if (Tcl_GetIntFromObj(interp, objv[3], intPtr) != TCL_OK) {
	    return TK_SCROLL_ERROR;
	}
	arg4 = Tcl_GetString(objv[4]);
	length = (strlen(arg4));
	c = arg4[0];
	if ((c == 'p') && (strncmp(arg4, "pages", length) == 0)) {
	    return TK_SCROLL_PAGES;
	} else if ((c == 'u')
		&& (strncmp(arg4, "units", length) == 0)) {
	    return TK_SCROLL_UNITS;
	} else {
	    Tcl_AppendResult(interp, "bad argument \"", arg4,
		    "\": must be units or pages", (char *) NULL);
	    return TK_SCROLL_ERROR;
	}
    }
    Tcl_AppendResult(interp, "unknown option \"", arg2,
@


