OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [insight/] [tk/] [generic/] [tkConfig.c] - Diff between revs 579 and 1765

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 579 Rev 1765
/*
/*
 * tkConfig.c --
 * tkConfig.c --
 *
 *
 *      This file contains the Tk_ConfigureWidget procedure.
 *      This file contains the Tk_ConfigureWidget procedure.
 *
 *
 * Copyright (c) 1990-1994 The Regents of the University of California.
 * Copyright (c) 1990-1994 The Regents of the University of California.
 * Copyright (c) 1994-1995 Sun Microsystems, Inc.
 * Copyright (c) 1994-1995 Sun Microsystems, Inc.
 *
 *
 * See the file "license.terms" for information on usage and redistribution
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 *
 * RCS: @(#) $Id: tkConfig.c,v 1.1.1.1 2002-01-16 10:25:51 markom Exp $
 * RCS: @(#) $Id: tkConfig.c,v 1.1.1.1 2002-01-16 10:25:51 markom Exp $
 */
 */
 
 
#include "tkPort.h"
#include "tkPort.h"
#include "tk.h"
#include "tk.h"
 
 
/*
/*
 * Values for "flags" field of Tk_ConfigSpec structures.  Be sure
 * Values for "flags" field of Tk_ConfigSpec structures.  Be sure
 * to coordinate these values with those defined in tk.h
 * to coordinate these values with those defined in tk.h
 * (TK_CONFIG_COLOR_ONLY, etc.).  There must not be overlap!
 * (TK_CONFIG_COLOR_ONLY, etc.).  There must not be overlap!
 *
 *
 * INIT -               Non-zero means (char *) things have been
 * INIT -               Non-zero means (char *) things have been
 *                      converted to Tk_Uid's.
 *                      converted to Tk_Uid's.
 */
 */
 
 
#define INIT            0x20
#define INIT            0x20
 
 
/*
/*
 * Forward declarations for procedures defined later in this file:
 * Forward declarations for procedures defined later in this file:
 */
 */
 
 
static int              DoConfig _ANSI_ARGS_((Tcl_Interp *interp,
static int              DoConfig _ANSI_ARGS_((Tcl_Interp *interp,
                            Tk_Window tkwin, Tk_ConfigSpec *specPtr,
                            Tk_Window tkwin, Tk_ConfigSpec *specPtr,
                            Tk_Uid value, int valueIsUid, char *widgRec));
                            Tk_Uid value, int valueIsUid, char *widgRec));
static Tk_ConfigSpec *  FindConfigSpec _ANSI_ARGS_((Tcl_Interp *interp,
static Tk_ConfigSpec *  FindConfigSpec _ANSI_ARGS_((Tcl_Interp *interp,
                            Tk_ConfigSpec *specs, char *argvName,
                            Tk_ConfigSpec *specs, char *argvName,
                            int needFlags, int hateFlags));
                            int needFlags, int hateFlags));
static char *           FormatConfigInfo _ANSI_ARGS_((Tcl_Interp *interp,
static char *           FormatConfigInfo _ANSI_ARGS_((Tcl_Interp *interp,
                            Tk_Window tkwin, Tk_ConfigSpec *specPtr,
                            Tk_Window tkwin, Tk_ConfigSpec *specPtr,
                            char *widgRec));
                            char *widgRec));
static char *           FormatConfigValue _ANSI_ARGS_((Tcl_Interp *interp,
static char *           FormatConfigValue _ANSI_ARGS_((Tcl_Interp *interp,
                            Tk_Window tkwin, Tk_ConfigSpec *specPtr,
                            Tk_Window tkwin, Tk_ConfigSpec *specPtr,
                            char *widgRec, char *buffer,
                            char *widgRec, char *buffer,
                            Tcl_FreeProc **freeProcPtr));
                            Tcl_FreeProc **freeProcPtr));


/*
/*
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 *
 *
 * Tk_ConfigureWidget --
 * Tk_ConfigureWidget --
 *
 *
 *      Process command-line options and database options to
 *      Process command-line options and database options to
 *      fill in fields of a widget record with resources and
 *      fill in fields of a widget record with resources and
 *      other parameters.
 *      other parameters.
 *
 *
 * Results:
 * Results:
 *      A standard Tcl return value.  In case of an error,
 *      A standard Tcl return value.  In case of an error,
 *      interp->result will hold an error message.
 *      interp->result will hold an error message.
 *
 *
 * Side effects:
 * Side effects:
 *      The fields of widgRec get filled in with information
 *      The fields of widgRec get filled in with information
 *      from argc/argv and the option database.  Old information
 *      from argc/argv and the option database.  Old information
 *      in widgRec's fields gets recycled.
 *      in widgRec's fields gets recycled.
 *
 *
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 */
 */
 
 
int
int
Tk_ConfigureWidget(interp, tkwin, specs, argc, argv, widgRec, flags)
Tk_ConfigureWidget(interp, tkwin, specs, argc, argv, widgRec, flags)
    Tcl_Interp *interp;         /* Interpreter for error reporting. */
    Tcl_Interp *interp;         /* Interpreter for error reporting. */
    Tk_Window tkwin;            /* Window containing widget (needed to
    Tk_Window tkwin;            /* Window containing widget (needed to
                                 * set up X resources). */
                                 * set up X resources). */
    Tk_ConfigSpec *specs;       /* Describes legal options. */
    Tk_ConfigSpec *specs;       /* Describes legal options. */
    int argc;                   /* Number of elements in argv. */
    int argc;                   /* Number of elements in argv. */
    char **argv;                /* Command-line options. */
    char **argv;                /* Command-line options. */
    char *widgRec;              /* Record whose fields are to be
    char *widgRec;              /* Record whose fields are to be
                                 * modified.  Values must be properly
                                 * modified.  Values must be properly
                                 * initialized. */
                                 * initialized. */
    int flags;                  /* Used to specify additional flags
    int flags;                  /* Used to specify additional flags
                                 * that must be present in config specs
                                 * that must be present in config specs
                                 * for them to be considered.  Also,
                                 * for them to be considered.  Also,
                                 * may have TK_CONFIG_ARGV_ONLY set. */
                                 * may have TK_CONFIG_ARGV_ONLY set. */
{
{
    register Tk_ConfigSpec *specPtr;
    register Tk_ConfigSpec *specPtr;
    Tk_Uid value;               /* Value of option from database. */
    Tk_Uid value;               /* Value of option from database. */
    int needFlags;              /* Specs must contain this set of flags
    int needFlags;              /* Specs must contain this set of flags
                                 * or else they are not considered. */
                                 * or else they are not considered. */
    int hateFlags;              /* If a spec contains any bits here, it's
    int hateFlags;              /* If a spec contains any bits here, it's
                                 * not considered. */
                                 * not considered. */
 
 
    needFlags = flags & ~(TK_CONFIG_USER_BIT - 1);
    needFlags = flags & ~(TK_CONFIG_USER_BIT - 1);
    if (Tk_Depth(tkwin) <= 1) {
    if (Tk_Depth(tkwin) <= 1) {
        hateFlags = TK_CONFIG_COLOR_ONLY;
        hateFlags = TK_CONFIG_COLOR_ONLY;
    } else {
    } else {
        hateFlags = TK_CONFIG_MONO_ONLY;
        hateFlags = TK_CONFIG_MONO_ONLY;
    }
    }
 
 
    /*
    /*
     * Pass one:  scan through all the option specs, replacing strings
     * Pass one:  scan through all the option specs, replacing strings
     * with Tk_Uids (if this hasn't been done already) and clearing
     * with Tk_Uids (if this hasn't been done already) and clearing
     * the TK_CONFIG_OPTION_SPECIFIED flags.
     * the TK_CONFIG_OPTION_SPECIFIED flags.
     */
     */
 
 
    for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) {
    for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) {
        if (!(specPtr->specFlags & INIT) && (specPtr->argvName != NULL)) {
        if (!(specPtr->specFlags & INIT) && (specPtr->argvName != NULL)) {
            if (specPtr->dbName != NULL) {
            if (specPtr->dbName != NULL) {
                specPtr->dbName = Tk_GetUid(specPtr->dbName);
                specPtr->dbName = Tk_GetUid(specPtr->dbName);
            }
            }
            if (specPtr->dbClass != NULL) {
            if (specPtr->dbClass != NULL) {
                specPtr->dbClass = Tk_GetUid(specPtr->dbClass);
                specPtr->dbClass = Tk_GetUid(specPtr->dbClass);
            }
            }
            if (specPtr->defValue != NULL) {
            if (specPtr->defValue != NULL) {
                specPtr->defValue = Tk_GetUid(specPtr->defValue);
                specPtr->defValue = Tk_GetUid(specPtr->defValue);
            }
            }
        }
        }
        specPtr->specFlags = (specPtr->specFlags & ~TK_CONFIG_OPTION_SPECIFIED)
        specPtr->specFlags = (specPtr->specFlags & ~TK_CONFIG_OPTION_SPECIFIED)
                | INIT;
                | INIT;
    }
    }
 
 
    /*
    /*
     * Pass two:  scan through all of the arguments, processing those
     * Pass two:  scan through all of the arguments, processing those
     * that match entries in the specs.
     * that match entries in the specs.
     */
     */
 
 
    for ( ; argc > 0; argc -= 2, argv += 2) {
    for ( ; argc > 0; argc -= 2, argv += 2) {
        specPtr = FindConfigSpec(interp, specs, *argv, needFlags, hateFlags);
        specPtr = FindConfigSpec(interp, specs, *argv, needFlags, hateFlags);
        if (specPtr == NULL) {
        if (specPtr == NULL) {
            return TCL_ERROR;
            return TCL_ERROR;
        }
        }
 
 
        /*
        /*
         * Process the entry.
         * Process the entry.
         */
         */
 
 
        if (argc < 2) {
        if (argc < 2) {
            Tcl_AppendResult(interp, "value for \"", *argv,
            Tcl_AppendResult(interp, "value for \"", *argv,
                    "\" missing", (char *) NULL);
                    "\" missing", (char *) NULL);
            return TCL_ERROR;
            return TCL_ERROR;
        }
        }
        if (DoConfig(interp, tkwin, specPtr, argv[1], 0, widgRec) != TCL_OK) {
        if (DoConfig(interp, tkwin, specPtr, argv[1], 0, widgRec) != TCL_OK) {
            char msg[100];
            char msg[100];
 
 
            sprintf(msg, "\n    (processing \"%.40s\" option)",
            sprintf(msg, "\n    (processing \"%.40s\" option)",
                    specPtr->argvName);
                    specPtr->argvName);
            Tcl_AddErrorInfo(interp, msg);
            Tcl_AddErrorInfo(interp, msg);
            return TCL_ERROR;
            return TCL_ERROR;
        }
        }
        specPtr->specFlags |= TK_CONFIG_OPTION_SPECIFIED;
        specPtr->specFlags |= TK_CONFIG_OPTION_SPECIFIED;
    }
    }
 
 
    /*
    /*
     * Pass three:  scan through all of the specs again;  if no
     * Pass three:  scan through all of the specs again;  if no
     * command-line argument matched a spec, then check for info
     * command-line argument matched a spec, then check for info
     * in the option database.  If there was nothing in the
     * in the option database.  If there was nothing in the
     * database, then use the default.
     * database, then use the default.
     */
     */
 
 
    if (!(flags & TK_CONFIG_ARGV_ONLY)) {
    if (!(flags & TK_CONFIG_ARGV_ONLY)) {
        for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) {
        for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) {
            if ((specPtr->specFlags & TK_CONFIG_OPTION_SPECIFIED)
            if ((specPtr->specFlags & TK_CONFIG_OPTION_SPECIFIED)
                    || (specPtr->argvName == NULL)
                    || (specPtr->argvName == NULL)
                    || (specPtr->type == TK_CONFIG_SYNONYM)) {
                    || (specPtr->type == TK_CONFIG_SYNONYM)) {
                continue;
                continue;
            }
            }
            if (((specPtr->specFlags & needFlags) != needFlags)
            if (((specPtr->specFlags & needFlags) != needFlags)
                    || (specPtr->specFlags & hateFlags)) {
                    || (specPtr->specFlags & hateFlags)) {
                continue;
                continue;
            }
            }
            value = NULL;
            value = NULL;
            if (specPtr->dbName != NULL) {
            if (specPtr->dbName != NULL) {
                value = Tk_GetOption(tkwin, specPtr->dbName, specPtr->dbClass);
                value = Tk_GetOption(tkwin, specPtr->dbName, specPtr->dbClass);
            }
            }
            if (value != NULL) {
            if (value != NULL) {
                if (DoConfig(interp, tkwin, specPtr, value, 1, widgRec) !=
                if (DoConfig(interp, tkwin, specPtr, value, 1, widgRec) !=
                        TCL_OK) {
                        TCL_OK) {
                    char msg[200];
                    char msg[200];
 
 
                    sprintf(msg, "\n    (%s \"%.50s\" in widget \"%.50s\")",
                    sprintf(msg, "\n    (%s \"%.50s\" in widget \"%.50s\")",
                            "database entry for",
                            "database entry for",
                            specPtr->dbName, Tk_PathName(tkwin));
                            specPtr->dbName, Tk_PathName(tkwin));
                    Tcl_AddErrorInfo(interp, msg);
                    Tcl_AddErrorInfo(interp, msg);
                    return TCL_ERROR;
                    return TCL_ERROR;
                }
                }
            } else {
            } else {
                value = specPtr->defValue;
                value = specPtr->defValue;
                if ((value != NULL) && !(specPtr->specFlags
                if ((value != NULL) && !(specPtr->specFlags
                        & TK_CONFIG_DONT_SET_DEFAULT)) {
                        & TK_CONFIG_DONT_SET_DEFAULT)) {
                    if (DoConfig(interp, tkwin, specPtr, value, 1, widgRec) !=
                    if (DoConfig(interp, tkwin, specPtr, value, 1, widgRec) !=
                            TCL_OK) {
                            TCL_OK) {
                        char msg[200];
                        char msg[200];
 
 
                        sprintf(msg,
                        sprintf(msg,
                                "\n    (%s \"%.50s\" in widget \"%.50s\")",
                                "\n    (%s \"%.50s\" in widget \"%.50s\")",
                                "default value for",
                                "default value for",
                                specPtr->dbName, Tk_PathName(tkwin));
                                specPtr->dbName, Tk_PathName(tkwin));
                        Tcl_AddErrorInfo(interp, msg);
                        Tcl_AddErrorInfo(interp, msg);
                        return TCL_ERROR;
                        return TCL_ERROR;
                    }
                    }
                }
                }
            }
            }
        }
        }
    }
    }
 
 
    return TCL_OK;
    return TCL_OK;
}
}


/*
/*
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 *
 *
 * FindConfigSpec --
 * FindConfigSpec --
 *
 *
 *      Search through a table of configuration specs, looking for
 *      Search through a table of configuration specs, looking for
 *      one that matches a given argvName.
 *      one that matches a given argvName.
 *
 *
 * Results:
 * Results:
 *      The return value is a pointer to the matching entry, or NULL
 *      The return value is a pointer to the matching entry, or NULL
 *      if nothing matched.  In that case an error message is left
 *      if nothing matched.  In that case an error message is left
 *      in interp->result.
 *      in interp->result.
 *
 *
 * Side effects:
 * Side effects:
 *      None.
 *      None.
 *
 *
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 */
 */
 
 
static Tk_ConfigSpec *
static Tk_ConfigSpec *
FindConfigSpec(interp, specs, argvName, needFlags, hateFlags)
FindConfigSpec(interp, specs, argvName, needFlags, hateFlags)
    Tcl_Interp *interp;         /* Used for reporting errors. */
    Tcl_Interp *interp;         /* Used for reporting errors. */
    Tk_ConfigSpec *specs;       /* Pointer to table of configuration
    Tk_ConfigSpec *specs;       /* Pointer to table of configuration
                                 * specifications for a widget. */
                                 * specifications for a widget. */
    char *argvName;             /* Name (suitable for use in a "config"
    char *argvName;             /* Name (suitable for use in a "config"
                                 * command) identifying particular option. */
                                 * command) identifying particular option. */
    int needFlags;              /* Flags that must be present in matching
    int needFlags;              /* Flags that must be present in matching
                                 * entry. */
                                 * entry. */
    int hateFlags;              /* Flags that must NOT be present in
    int hateFlags;              /* Flags that must NOT be present in
                                 * matching entry. */
                                 * matching entry. */
{
{
    register Tk_ConfigSpec *specPtr;
    register Tk_ConfigSpec *specPtr;
    register char c;            /* First character of current argument. */
    register char c;            /* First character of current argument. */
    Tk_ConfigSpec *matchPtr;    /* Matching spec, or NULL. */
    Tk_ConfigSpec *matchPtr;    /* Matching spec, or NULL. */
    size_t length;
    size_t length;
 
 
    c = argvName[1];
    c = argvName[1];
    length = strlen(argvName);
    length = strlen(argvName);
    matchPtr = NULL;
    matchPtr = NULL;
    for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) {
    for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) {
        if (specPtr->argvName == NULL) {
        if (specPtr->argvName == NULL) {
            continue;
            continue;
        }
        }
        if ((specPtr->argvName[1] != c)
        if ((specPtr->argvName[1] != c)
                || (strncmp(specPtr->argvName, argvName, length) != 0)) {
                || (strncmp(specPtr->argvName, argvName, length) != 0)) {
            continue;
            continue;
        }
        }
        if (((specPtr->specFlags & needFlags) != needFlags)
        if (((specPtr->specFlags & needFlags) != needFlags)
                || (specPtr->specFlags & hateFlags)) {
                || (specPtr->specFlags & hateFlags)) {
            continue;
            continue;
        }
        }
        if (specPtr->argvName[length] == 0) {
        if (specPtr->argvName[length] == 0) {
            matchPtr = specPtr;
            matchPtr = specPtr;
            goto gotMatch;
            goto gotMatch;
        }
        }
        if (matchPtr != NULL) {
        if (matchPtr != NULL) {
            Tcl_AppendResult(interp, "ambiguous option \"", argvName,
            Tcl_AppendResult(interp, "ambiguous option \"", argvName,
                    "\"", (char *) NULL);
                    "\"", (char *) NULL);
            return (Tk_ConfigSpec *) NULL;
            return (Tk_ConfigSpec *) NULL;
        }
        }
        matchPtr = specPtr;
        matchPtr = specPtr;
    }
    }
 
 
    if (matchPtr == NULL) {
    if (matchPtr == NULL) {
        Tcl_AppendResult(interp, "unknown option \"", argvName,
        Tcl_AppendResult(interp, "unknown option \"", argvName,
                "\"", (char *) NULL);
                "\"", (char *) NULL);
        return (Tk_ConfigSpec *) NULL;
        return (Tk_ConfigSpec *) NULL;
    }
    }
 
 
    /*
    /*
     * Found a matching entry.  If it's a synonym, then find the
     * Found a matching entry.  If it's a synonym, then find the
     * entry that it's a synonym for.
     * entry that it's a synonym for.
     */
     */
 
 
    gotMatch:
    gotMatch:
    specPtr = matchPtr;
    specPtr = matchPtr;
    if (specPtr->type == TK_CONFIG_SYNONYM) {
    if (specPtr->type == TK_CONFIG_SYNONYM) {
        for (specPtr = specs; ; specPtr++) {
        for (specPtr = specs; ; specPtr++) {
            if (specPtr->type == TK_CONFIG_END) {
            if (specPtr->type == TK_CONFIG_END) {
                Tcl_AppendResult(interp,
                Tcl_AppendResult(interp,
                        "couldn't find synonym for option \"",
                        "couldn't find synonym for option \"",
                        argvName, "\"", (char *) NULL);
                        argvName, "\"", (char *) NULL);
                return (Tk_ConfigSpec *) NULL;
                return (Tk_ConfigSpec *) NULL;
            }
            }
            if ((specPtr->dbName == matchPtr->dbName)
            if ((specPtr->dbName == matchPtr->dbName)
                    && (specPtr->type != TK_CONFIG_SYNONYM)
                    && (specPtr->type != TK_CONFIG_SYNONYM)
                    && ((specPtr->specFlags & needFlags) == needFlags)
                    && ((specPtr->specFlags & needFlags) == needFlags)
                    && !(specPtr->specFlags & hateFlags)) {
                    && !(specPtr->specFlags & hateFlags)) {
                break;
                break;
            }
            }
        }
        }
    }
    }
    return specPtr;
    return specPtr;
}
}


/*
/*
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 *
 *
 * DoConfig --
 * DoConfig --
 *
 *
 *      This procedure applies a single configuration option
 *      This procedure applies a single configuration option
 *      to a widget record.
 *      to a widget record.
 *
 *
 * Results:
 * Results:
 *      A standard Tcl return value.
 *      A standard Tcl return value.
 *
 *
 * Side effects:
 * Side effects:
 *      WidgRec is modified as indicated by specPtr and value.
 *      WidgRec is modified as indicated by specPtr and value.
 *      The old value is recycled, if that is appropriate for
 *      The old value is recycled, if that is appropriate for
 *      the value type.
 *      the value type.
 *
 *
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 */
 */
 
 
static int
static int
DoConfig(interp, tkwin, specPtr, value, valueIsUid, widgRec)
DoConfig(interp, tkwin, specPtr, value, valueIsUid, widgRec)
    Tcl_Interp *interp;         /* Interpreter for error reporting. */
    Tcl_Interp *interp;         /* Interpreter for error reporting. */
    Tk_Window tkwin;            /* Window containing widget (needed to
    Tk_Window tkwin;            /* Window containing widget (needed to
                                 * set up X resources). */
                                 * set up X resources). */
    Tk_ConfigSpec *specPtr;     /* Specifier to apply. */
    Tk_ConfigSpec *specPtr;     /* Specifier to apply. */
    char *value;                /* Value to use to fill in widgRec. */
    char *value;                /* Value to use to fill in widgRec. */
    int valueIsUid;             /* Non-zero means value is a Tk_Uid;
    int valueIsUid;             /* Non-zero means value is a Tk_Uid;
                                 * zero means it's an ordinary string. */
                                 * zero means it's an ordinary string. */
    char *widgRec;              /* Record whose fields are to be
    char *widgRec;              /* Record whose fields are to be
                                 * modified.  Values must be properly
                                 * modified.  Values must be properly
                                 * initialized. */
                                 * initialized. */
{
{
    char *ptr;
    char *ptr;
    Tk_Uid uid;
    Tk_Uid uid;
    int nullValue;
    int nullValue;
 
 
    nullValue = 0;
    nullValue = 0;
    if ((*value == 0) && (specPtr->specFlags & TK_CONFIG_NULL_OK)) {
    if ((*value == 0) && (specPtr->specFlags & TK_CONFIG_NULL_OK)) {
        nullValue = 1;
        nullValue = 1;
    }
    }
 
 
    do {
    do {
        ptr = widgRec + specPtr->offset;
        ptr = widgRec + specPtr->offset;
        switch (specPtr->type) {
        switch (specPtr->type) {
            case TK_CONFIG_BOOLEAN:
            case TK_CONFIG_BOOLEAN:
                if (Tcl_GetBoolean(interp, value, (int *) ptr) != TCL_OK) {
                if (Tcl_GetBoolean(interp, value, (int *) ptr) != TCL_OK) {
                    return TCL_ERROR;
                    return TCL_ERROR;
                }
                }
                break;
                break;
            case TK_CONFIG_INT:
            case TK_CONFIG_INT:
                if (Tcl_GetInt(interp, value, (int *) ptr) != TCL_OK) {
                if (Tcl_GetInt(interp, value, (int *) ptr) != TCL_OK) {
                    return TCL_ERROR;
                    return TCL_ERROR;
                }
                }
                break;
                break;
            case TK_CONFIG_DOUBLE:
            case TK_CONFIG_DOUBLE:
                if (Tcl_GetDouble(interp, value, (double *) ptr) != TCL_OK) {
                if (Tcl_GetDouble(interp, value, (double *) ptr) != TCL_OK) {
                    return TCL_ERROR;
                    return TCL_ERROR;
                }
                }
                break;
                break;
            case TK_CONFIG_STRING: {
            case TK_CONFIG_STRING: {
                char *old, *new;
                char *old, *new;
 
 
                if (nullValue) {
                if (nullValue) {
                    new = NULL;
                    new = NULL;
                } else {
                } else {
                    new = (char *) ckalloc((unsigned) (strlen(value) + 1));
                    new = (char *) ckalloc((unsigned) (strlen(value) + 1));
                    strcpy(new, value);
                    strcpy(new, value);
                }
                }
                old = *((char **) ptr);
                old = *((char **) ptr);
                if (old != NULL) {
                if (old != NULL) {
                    ckfree(old);
                    ckfree(old);
                }
                }
                *((char **) ptr) = new;
                *((char **) ptr) = new;
                break;
                break;
            }
            }
            case TK_CONFIG_UID:
            case TK_CONFIG_UID:
                if (nullValue) {
                if (nullValue) {
                    *((Tk_Uid *) ptr) = NULL;
                    *((Tk_Uid *) ptr) = NULL;
                } else {
                } else {
                    uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
                    uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
                    *((Tk_Uid *) ptr) = uid;
                    *((Tk_Uid *) ptr) = uid;
                }
                }
                break;
                break;
            case TK_CONFIG_COLOR: {
            case TK_CONFIG_COLOR: {
                XColor *newPtr, *oldPtr;
                XColor *newPtr, *oldPtr;
 
 
                if (nullValue) {
                if (nullValue) {
                    newPtr = NULL;
                    newPtr = NULL;
                } else {
                } else {
                    uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
                    uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
                    newPtr = Tk_GetColor(interp, tkwin, uid);
                    newPtr = Tk_GetColor(interp, tkwin, uid);
                    if (newPtr == NULL) {
                    if (newPtr == NULL) {
                        return TCL_ERROR;
                        return TCL_ERROR;
                    }
                    }
                }
                }
                oldPtr = *((XColor **) ptr);
                oldPtr = *((XColor **) ptr);
                if (oldPtr != NULL) {
                if (oldPtr != NULL) {
                    Tk_FreeColor(oldPtr);
                    Tk_FreeColor(oldPtr);
                }
                }
                *((XColor **) ptr) = newPtr;
                *((XColor **) ptr) = newPtr;
                break;
                break;
            }
            }
            case TK_CONFIG_FONT: {
            case TK_CONFIG_FONT: {
                Tk_Font new;
                Tk_Font new;
 
 
                if (nullValue) {
                if (nullValue) {
                    new = NULL;
                    new = NULL;
                } else {
                } else {
                    new = Tk_GetFont(interp, tkwin, value);
                    new = Tk_GetFont(interp, tkwin, value);
                    if (new == NULL) {
                    if (new == NULL) {
                        return TCL_ERROR;
                        return TCL_ERROR;
                    }
                    }
                }
                }
                Tk_FreeFont(*((Tk_Font *) ptr));
                Tk_FreeFont(*((Tk_Font *) ptr));
                *((Tk_Font *) ptr) = new;
                *((Tk_Font *) ptr) = new;
                break;
                break;
            }
            }
            case TK_CONFIG_BITMAP: {
            case TK_CONFIG_BITMAP: {
                Pixmap new, old;
                Pixmap new, old;
 
 
                if (nullValue) {
                if (nullValue) {
                    new = None;
                    new = None;
                } else {
                } else {
                    uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
                    uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
                    new = Tk_GetBitmap(interp, tkwin, uid);
                    new = Tk_GetBitmap(interp, tkwin, uid);
                    if (new == None) {
                    if (new == None) {
                        return TCL_ERROR;
                        return TCL_ERROR;
                    }
                    }
                }
                }
                old = *((Pixmap *) ptr);
                old = *((Pixmap *) ptr);
                if (old != None) {
                if (old != None) {
                    Tk_FreeBitmap(Tk_Display(tkwin), old);
                    Tk_FreeBitmap(Tk_Display(tkwin), old);
                }
                }
                *((Pixmap *) ptr) = new;
                *((Pixmap *) ptr) = new;
                break;
                break;
            }
            }
            case TK_CONFIG_BORDER: {
            case TK_CONFIG_BORDER: {
                Tk_3DBorder new, old;
                Tk_3DBorder new, old;
 
 
                if (nullValue) {
                if (nullValue) {
                    new = NULL;
                    new = NULL;
                } else {
                } else {
                    uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
                    uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
                    new = Tk_Get3DBorder(interp, tkwin, uid);
                    new = Tk_Get3DBorder(interp, tkwin, uid);
                    if (new == NULL) {
                    if (new == NULL) {
                        return TCL_ERROR;
                        return TCL_ERROR;
                    }
                    }
                }
                }
                old = *((Tk_3DBorder *) ptr);
                old = *((Tk_3DBorder *) ptr);
                if (old != NULL) {
                if (old != NULL) {
                    Tk_Free3DBorder(old);
                    Tk_Free3DBorder(old);
                }
                }
                *((Tk_3DBorder *) ptr) = new;
                *((Tk_3DBorder *) ptr) = new;
                break;
                break;
            }
            }
            case TK_CONFIG_RELIEF:
            case TK_CONFIG_RELIEF:
                uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
                uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
                if (Tk_GetRelief(interp, uid, (int *) ptr) != TCL_OK) {
                if (Tk_GetRelief(interp, uid, (int *) ptr) != TCL_OK) {
                    return TCL_ERROR;
                    return TCL_ERROR;
                }
                }
                break;
                break;
            case TK_CONFIG_CURSOR:
            case TK_CONFIG_CURSOR:
            case TK_CONFIG_ACTIVE_CURSOR: {
            case TK_CONFIG_ACTIVE_CURSOR: {
                Tk_Cursor new, old;
                Tk_Cursor new, old;
 
 
                if (nullValue) {
                if (nullValue) {
                    new = None;
                    new = None;
                } else {
                } else {
                    uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
                    uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
                    new = Tk_GetCursor(interp, tkwin, uid);
                    new = Tk_GetCursor(interp, tkwin, uid);
                    if (new == None) {
                    if (new == None) {
                        return TCL_ERROR;
                        return TCL_ERROR;
                    }
                    }
                }
                }
                old = *((Tk_Cursor *) ptr);
                old = *((Tk_Cursor *) ptr);
                if (old != None) {
                if (old != None) {
                    Tk_FreeCursor(Tk_Display(tkwin), old);
                    Tk_FreeCursor(Tk_Display(tkwin), old);
                }
                }
                *((Tk_Cursor *) ptr) = new;
                *((Tk_Cursor *) ptr) = new;
                if (specPtr->type == TK_CONFIG_ACTIVE_CURSOR) {
                if (specPtr->type == TK_CONFIG_ACTIVE_CURSOR) {
                    Tk_DefineCursor(tkwin, new);
                    Tk_DefineCursor(tkwin, new);
                }
                }
                break;
                break;
            }
            }
            case TK_CONFIG_JUSTIFY:
            case TK_CONFIG_JUSTIFY:
                uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
                uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
                if (Tk_GetJustify(interp, uid, (Tk_Justify *) ptr) != TCL_OK) {
                if (Tk_GetJustify(interp, uid, (Tk_Justify *) ptr) != TCL_OK) {
                    return TCL_ERROR;
                    return TCL_ERROR;
                }
                }
                break;
                break;
            case TK_CONFIG_ANCHOR:
            case TK_CONFIG_ANCHOR:
                uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
                uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
                if (Tk_GetAnchor(interp, uid, (Tk_Anchor *) ptr) != TCL_OK) {
                if (Tk_GetAnchor(interp, uid, (Tk_Anchor *) ptr) != TCL_OK) {
                    return TCL_ERROR;
                    return TCL_ERROR;
                }
                }
                break;
                break;
            case TK_CONFIG_CAP_STYLE:
            case TK_CONFIG_CAP_STYLE:
                uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
                uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
                if (Tk_GetCapStyle(interp, uid, (int *) ptr) != TCL_OK) {
                if (Tk_GetCapStyle(interp, uid, (int *) ptr) != TCL_OK) {
                    return TCL_ERROR;
                    return TCL_ERROR;
                }
                }
                break;
                break;
            case TK_CONFIG_JOIN_STYLE:
            case TK_CONFIG_JOIN_STYLE:
                uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
                uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
                if (Tk_GetJoinStyle(interp, uid, (int *) ptr) != TCL_OK) {
                if (Tk_GetJoinStyle(interp, uid, (int *) ptr) != TCL_OK) {
                    return TCL_ERROR;
                    return TCL_ERROR;
                }
                }
                break;
                break;
            case TK_CONFIG_PIXELS:
            case TK_CONFIG_PIXELS:
                if (Tk_GetPixels(interp, tkwin, value, (int *) ptr)
                if (Tk_GetPixels(interp, tkwin, value, (int *) ptr)
                        != TCL_OK) {
                        != TCL_OK) {
                    return TCL_ERROR;
                    return TCL_ERROR;
                }
                }
                break;
                break;
            case TK_CONFIG_MM:
            case TK_CONFIG_MM:
                if (Tk_GetScreenMM(interp, tkwin, value, (double *) ptr)
                if (Tk_GetScreenMM(interp, tkwin, value, (double *) ptr)
                        != TCL_OK) {
                        != TCL_OK) {
                    return TCL_ERROR;
                    return TCL_ERROR;
                }
                }
                break;
                break;
            case TK_CONFIG_WINDOW: {
            case TK_CONFIG_WINDOW: {
                Tk_Window tkwin2;
                Tk_Window tkwin2;
 
 
                if (nullValue) {
                if (nullValue) {
                    tkwin2 = NULL;
                    tkwin2 = NULL;
                } else {
                } else {
                    tkwin2 = Tk_NameToWindow(interp, value, tkwin);
                    tkwin2 = Tk_NameToWindow(interp, value, tkwin);
                    if (tkwin2 == NULL) {
                    if (tkwin2 == NULL) {
                        return TCL_ERROR;
                        return TCL_ERROR;
                    }
                    }
                }
                }
                *((Tk_Window *) ptr) = tkwin2;
                *((Tk_Window *) ptr) = tkwin2;
                break;
                break;
            }
            }
            case TK_CONFIG_CUSTOM:
            case TK_CONFIG_CUSTOM:
                if ((*specPtr->customPtr->parseProc)(
                if ((*specPtr->customPtr->parseProc)(
                        specPtr->customPtr->clientData, interp, tkwin,
                        specPtr->customPtr->clientData, interp, tkwin,
                        value, widgRec, specPtr->offset) != TCL_OK) {
                        value, widgRec, specPtr->offset) != TCL_OK) {
                    return TCL_ERROR;
                    return TCL_ERROR;
                }
                }
                break;
                break;
            default: {
            default: {
                sprintf(interp->result, "bad config table: unknown type %d",
                sprintf(interp->result, "bad config table: unknown type %d",
                        specPtr->type);
                        specPtr->type);
                return TCL_ERROR;
                return TCL_ERROR;
            }
            }
        }
        }
        specPtr++;
        specPtr++;
    } while ((specPtr->argvName == NULL) && (specPtr->type != TK_CONFIG_END));
    } while ((specPtr->argvName == NULL) && (specPtr->type != TK_CONFIG_END));
    return TCL_OK;
    return TCL_OK;
}
}


/*
/*
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 *
 *
 * Tk_ConfigureInfo --
 * Tk_ConfigureInfo --
 *
 *
 *      Return information about the configuration options
 *      Return information about the configuration options
 *      for a window, and their current values.
 *      for a window, and their current values.
 *
 *
 * Results:
 * Results:
 *      Always returns TCL_OK.  Interp->result will be modified
 *      Always returns TCL_OK.  Interp->result will be modified
 *      hold a description of either a single configuration option
 *      hold a description of either a single configuration option
 *      available for "widgRec" via "specs", or all the configuration
 *      available for "widgRec" via "specs", or all the configuration
 *      options available.  In the "all" case, the result will
 *      options available.  In the "all" case, the result will
 *      available for "widgRec" via "specs".  The result will
 *      available for "widgRec" via "specs".  The result will
 *      be a list, each of whose entries describes one option.
 *      be a list, each of whose entries describes one option.
 *      Each entry will itself be a list containing the option's
 *      Each entry will itself be a list containing the option's
 *      name for use on command lines, database name, database
 *      name for use on command lines, database name, database
 *      class, default value, and current value (empty string
 *      class, default value, and current value (empty string
 *      if none).  For options that are synonyms, the list will
 *      if none).  For options that are synonyms, the list will
 *      contain only two values:  name and synonym name.  If the
 *      contain only two values:  name and synonym name.  If the
 *      "name" argument is non-NULL, then the only information
 *      "name" argument is non-NULL, then the only information
 *      returned is that for the named argument (i.e. the corresponding
 *      returned is that for the named argument (i.e. the corresponding
 *      entry in the overall list is returned).
 *      entry in the overall list is returned).
 *
 *
 * Side effects:
 * Side effects:
 *      None.
 *      None.
 *
 *
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 */
 */
 
 
int
int
Tk_ConfigureInfo(interp, tkwin, specs, widgRec, argvName, flags)
Tk_ConfigureInfo(interp, tkwin, specs, widgRec, argvName, flags)
    Tcl_Interp *interp;         /* Interpreter for error reporting. */
    Tcl_Interp *interp;         /* Interpreter for error reporting. */
    Tk_Window tkwin;            /* Window corresponding to widgRec. */
    Tk_Window tkwin;            /* Window corresponding to widgRec. */
    Tk_ConfigSpec *specs;       /* Describes legal options. */
    Tk_ConfigSpec *specs;       /* Describes legal options. */
    char *widgRec;              /* Record whose fields contain current
    char *widgRec;              /* Record whose fields contain current
                                 * values for options. */
                                 * values for options. */
    char *argvName;             /* If non-NULL, indicates a single option
    char *argvName;             /* If non-NULL, indicates a single option
                                 * whose info is to be returned.  Otherwise
                                 * whose info is to be returned.  Otherwise
                                 * info is returned for all options. */
                                 * info is returned for all options. */
    int flags;                  /* Used to specify additional flags
    int flags;                  /* Used to specify additional flags
                                 * that must be present in config specs
                                 * that must be present in config specs
                                 * for them to be considered. */
                                 * for them to be considered. */
{
{
    register Tk_ConfigSpec *specPtr;
    register Tk_ConfigSpec *specPtr;
    int needFlags, hateFlags;
    int needFlags, hateFlags;
    char *list;
    char *list;
    char *leader = "{";
    char *leader = "{";
 
 
    needFlags = flags & ~(TK_CONFIG_USER_BIT - 1);
    needFlags = flags & ~(TK_CONFIG_USER_BIT - 1);
    if (Tk_Depth(tkwin) <= 1) {
    if (Tk_Depth(tkwin) <= 1) {
        hateFlags = TK_CONFIG_COLOR_ONLY;
        hateFlags = TK_CONFIG_COLOR_ONLY;
    } else {
    } else {
        hateFlags = TK_CONFIG_MONO_ONLY;
        hateFlags = TK_CONFIG_MONO_ONLY;
    }
    }
 
 
    /*
    /*
     * If information is only wanted for a single configuration
     * If information is only wanted for a single configuration
     * spec, then handle that one spec specially.
     * spec, then handle that one spec specially.
     */
     */
 
 
    Tcl_SetResult(interp, (char *) NULL, TCL_STATIC);
    Tcl_SetResult(interp, (char *) NULL, TCL_STATIC);
    if (argvName != NULL) {
    if (argvName != NULL) {
        specPtr = FindConfigSpec(interp, specs, argvName, needFlags,
        specPtr = FindConfigSpec(interp, specs, argvName, needFlags,
                hateFlags);
                hateFlags);
        if (specPtr == NULL) {
        if (specPtr == NULL) {
            return TCL_ERROR;
            return TCL_ERROR;
        }
        }
        interp->result = FormatConfigInfo(interp, tkwin, specPtr, widgRec);
        interp->result = FormatConfigInfo(interp, tkwin, specPtr, widgRec);
        interp->freeProc = TCL_DYNAMIC;
        interp->freeProc = TCL_DYNAMIC;
        return TCL_OK;
        return TCL_OK;
    }
    }
 
 
    /*
    /*
     * Loop through all the specs, creating a big list with all
     * Loop through all the specs, creating a big list with all
     * their information.
     * their information.
     */
     */
 
 
    for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) {
    for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) {
        if ((argvName != NULL) && (specPtr->argvName != argvName)) {
        if ((argvName != NULL) && (specPtr->argvName != argvName)) {
            continue;
            continue;
        }
        }
        if (((specPtr->specFlags & needFlags) != needFlags)
        if (((specPtr->specFlags & needFlags) != needFlags)
                || (specPtr->specFlags & hateFlags)) {
                || (specPtr->specFlags & hateFlags)) {
            continue;
            continue;
        }
        }
        if (specPtr->argvName == NULL) {
        if (specPtr->argvName == NULL) {
            continue;
            continue;
        }
        }
        list = FormatConfigInfo(interp, tkwin, specPtr, widgRec);
        list = FormatConfigInfo(interp, tkwin, specPtr, widgRec);
        Tcl_AppendResult(interp, leader, list, "}", (char *) NULL);
        Tcl_AppendResult(interp, leader, list, "}", (char *) NULL);
        ckfree(list);
        ckfree(list);
        leader = " {";
        leader = " {";
    }
    }
    return TCL_OK;
    return TCL_OK;
}
}


/*
/*
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 *
 *
 * FormatConfigInfo --
 * FormatConfigInfo --
 *
 *
 *      Create a valid Tcl list holding the configuration information
 *      Create a valid Tcl list holding the configuration information
 *      for a single configuration option.
 *      for a single configuration option.
 *
 *
 * Results:
 * Results:
 *      A Tcl list, dynamically allocated.  The caller is expected to
 *      A Tcl list, dynamically allocated.  The caller is expected to
 *      arrange for this list to be freed eventually.
 *      arrange for this list to be freed eventually.
 *
 *
 * Side effects:
 * Side effects:
 *      Memory is allocated.
 *      Memory is allocated.
 *
 *
 *--------------------------------------------------------------
 *--------------------------------------------------------------
 */
 */
 
 
static char *
static char *
FormatConfigInfo(interp, tkwin, specPtr, widgRec)
FormatConfigInfo(interp, tkwin, specPtr, widgRec)
    Tcl_Interp *interp;                 /* Interpreter to use for things
    Tcl_Interp *interp;                 /* Interpreter to use for things
                                         * like floating-point precision. */
                                         * like floating-point precision. */
    Tk_Window tkwin;                    /* Window corresponding to widget. */
    Tk_Window tkwin;                    /* Window corresponding to widget. */
    register Tk_ConfigSpec *specPtr;    /* Pointer to information describing
    register Tk_ConfigSpec *specPtr;    /* Pointer to information describing
                                         * option. */
                                         * option. */
    char *widgRec;                      /* Pointer to record holding current
    char *widgRec;                      /* Pointer to record holding current
                                         * values of info for widget. */
                                         * values of info for widget. */
{
{
    char *argv[6], *result;
    char *argv[6], *result;
    char buffer[200];
    char buffer[200];
    Tcl_FreeProc *freeProc = (Tcl_FreeProc *) NULL;
    Tcl_FreeProc *freeProc = (Tcl_FreeProc *) NULL;
 
 
    argv[0] = specPtr->argvName;
    argv[0] = specPtr->argvName;
    argv[1] = specPtr->dbName;
    argv[1] = specPtr->dbName;
    argv[2] = specPtr->dbClass;
    argv[2] = specPtr->dbClass;
    argv[3] = specPtr->defValue;
    argv[3] = specPtr->defValue;
    if (specPtr->type == TK_CONFIG_SYNONYM) {
    if (specPtr->type == TK_CONFIG_SYNONYM) {
        return Tcl_Merge(2, argv);
        return Tcl_Merge(2, argv);
    }
    }
    argv[4] = FormatConfigValue(interp, tkwin, specPtr, widgRec, buffer,
    argv[4] = FormatConfigValue(interp, tkwin, specPtr, widgRec, buffer,
            &freeProc);
            &freeProc);
    if (argv[1] == NULL) {
    if (argv[1] == NULL) {
        argv[1] = "";
        argv[1] = "";
    }
    }
    if (argv[2] == NULL) {
    if (argv[2] == NULL) {
        argv[2] = "";
        argv[2] = "";
    }
    }
    if (argv[3] == NULL) {
    if (argv[3] == NULL) {
        argv[3] = "";
        argv[3] = "";
    }
    }
    if (argv[4] == NULL) {
    if (argv[4] == NULL) {
        argv[4] = "";
        argv[4] = "";
    }
    }
    result = Tcl_Merge(5, argv);
    result = Tcl_Merge(5, argv);
    if (freeProc != NULL) {
    if (freeProc != NULL) {
        if ((freeProc == TCL_DYNAMIC) || (freeProc == (Tcl_FreeProc *) free)) {
        if ((freeProc == TCL_DYNAMIC) || (freeProc == (Tcl_FreeProc *) free)) {
            ckfree(argv[4]);
            ckfree(argv[4]);
        } else {
        } else {
            (*freeProc)(argv[4]);
            (*freeProc)(argv[4]);
        }
        }
    }
    }
    return result;
    return result;
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * FormatConfigValue --
 * FormatConfigValue --
 *
 *
 *      This procedure formats the current value of a configuration
 *      This procedure formats the current value of a configuration
 *      option.
 *      option.
 *
 *
 * Results:
 * Results:
 *      The return value is the formatted value of the option given
 *      The return value is the formatted value of the option given
 *      by specPtr and widgRec.  If the value is static, so that it
 *      by specPtr and widgRec.  If the value is static, so that it
 *      need not be freed, *freeProcPtr will be set to NULL;  otherwise
 *      need not be freed, *freeProcPtr will be set to NULL;  otherwise
 *      *freeProcPtr will be set to the address of a procedure to
 *      *freeProcPtr will be set to the address of a procedure to
 *      free the result, and the caller must invoke this procedure
 *      free the result, and the caller must invoke this procedure
 *      when it is finished with the result.
 *      when it is finished with the result.
 *
 *
 * Side effects:
 * Side effects:
 *      None.
 *      None.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
static char *
static char *
FormatConfigValue(interp, tkwin, specPtr, widgRec, buffer, freeProcPtr)
FormatConfigValue(interp, tkwin, specPtr, widgRec, buffer, freeProcPtr)
    Tcl_Interp *interp;         /* Interpreter for use in real conversions. */
    Tcl_Interp *interp;         /* Interpreter for use in real conversions. */
    Tk_Window tkwin;            /* Window corresponding to widget. */
    Tk_Window tkwin;            /* Window corresponding to widget. */
    Tk_ConfigSpec *specPtr;     /* Pointer to information describing option.
    Tk_ConfigSpec *specPtr;     /* Pointer to information describing option.
                                 * Must not point to a synonym option. */
                                 * Must not point to a synonym option. */
    char *widgRec;              /* Pointer to record holding current
    char *widgRec;              /* Pointer to record holding current
                                 * values of info for widget. */
                                 * values of info for widget. */
    char *buffer;               /* Static buffer to use for small values.
    char *buffer;               /* Static buffer to use for small values.
                                 * Must have at least 200 bytes of storage. */
                                 * Must have at least 200 bytes of storage. */
    Tcl_FreeProc **freeProcPtr; /* Pointer to word to fill in with address
    Tcl_FreeProc **freeProcPtr; /* Pointer to word to fill in with address
                                 * of procedure to free the result, or NULL
                                 * of procedure to free the result, or NULL
                                 * if result is static. */
                                 * if result is static. */
{
{
    char *ptr, *result;
    char *ptr, *result;
 
 
    *freeProcPtr = NULL;
    *freeProcPtr = NULL;
    ptr = widgRec + specPtr->offset;
    ptr = widgRec + specPtr->offset;
    result = "";
    result = "";
    switch (specPtr->type) {
    switch (specPtr->type) {
        case TK_CONFIG_BOOLEAN:
        case TK_CONFIG_BOOLEAN:
            if (*((int *) ptr) == 0) {
            if (*((int *) ptr) == 0) {
                result = "0";
                result = "0";
            } else {
            } else {
                result = "1";
                result = "1";
            }
            }
            break;
            break;
        case TK_CONFIG_INT:
        case TK_CONFIG_INT:
            sprintf(buffer, "%d", *((int *) ptr));
            sprintf(buffer, "%d", *((int *) ptr));
            result = buffer;
            result = buffer;
            break;
            break;
        case TK_CONFIG_DOUBLE:
        case TK_CONFIG_DOUBLE:
            Tcl_PrintDouble(interp, *((double *) ptr), buffer);
            Tcl_PrintDouble(interp, *((double *) ptr), buffer);
            result = buffer;
            result = buffer;
            break;
            break;
        case TK_CONFIG_STRING:
        case TK_CONFIG_STRING:
            result = (*(char **) ptr);
            result = (*(char **) ptr);
            if (result == NULL) {
            if (result == NULL) {
                result = "";
                result = "";
            }
            }
            break;
            break;
        case TK_CONFIG_UID: {
        case TK_CONFIG_UID: {
            Tk_Uid uid = *((Tk_Uid *) ptr);
            Tk_Uid uid = *((Tk_Uid *) ptr);
            if (uid != NULL) {
            if (uid != NULL) {
                result = uid;
                result = uid;
            }
            }
            break;
            break;
        }
        }
        case TK_CONFIG_COLOR: {
        case TK_CONFIG_COLOR: {
            XColor *colorPtr = *((XColor **) ptr);
            XColor *colorPtr = *((XColor **) ptr);
            if (colorPtr != NULL) {
            if (colorPtr != NULL) {
                result = Tk_NameOfColor(colorPtr);
                result = Tk_NameOfColor(colorPtr);
            }
            }
            break;
            break;
        }
        }
        case TK_CONFIG_FONT: {
        case TK_CONFIG_FONT: {
            Tk_Font tkfont = *((Tk_Font *) ptr);
            Tk_Font tkfont = *((Tk_Font *) ptr);
            if (tkfont != NULL) {
            if (tkfont != NULL) {
                result = Tk_NameOfFont(tkfont);
                result = Tk_NameOfFont(tkfont);
            }
            }
            break;
            break;
        }
        }
        case TK_CONFIG_BITMAP: {
        case TK_CONFIG_BITMAP: {
            Pixmap pixmap = *((Pixmap *) ptr);
            Pixmap pixmap = *((Pixmap *) ptr);
            if (pixmap != None) {
            if (pixmap != None) {
                result = Tk_NameOfBitmap(Tk_Display(tkwin), pixmap);
                result = Tk_NameOfBitmap(Tk_Display(tkwin), pixmap);
            }
            }
            break;
            break;
        }
        }
        case TK_CONFIG_BORDER: {
        case TK_CONFIG_BORDER: {
            Tk_3DBorder border = *((Tk_3DBorder *) ptr);
            Tk_3DBorder border = *((Tk_3DBorder *) ptr);
            if (border != NULL) {
            if (border != NULL) {
                result = Tk_NameOf3DBorder(border);
                result = Tk_NameOf3DBorder(border);
            }
            }
            break;
            break;
        }
        }
        case TK_CONFIG_RELIEF:
        case TK_CONFIG_RELIEF:
            result = Tk_NameOfRelief(*((int *) ptr));
            result = Tk_NameOfRelief(*((int *) ptr));
            break;
            break;
        case TK_CONFIG_CURSOR:
        case TK_CONFIG_CURSOR:
        case TK_CONFIG_ACTIVE_CURSOR: {
        case TK_CONFIG_ACTIVE_CURSOR: {
            Tk_Cursor cursor = *((Tk_Cursor *) ptr);
            Tk_Cursor cursor = *((Tk_Cursor *) ptr);
            if (cursor != None) {
            if (cursor != None) {
                result = Tk_NameOfCursor(Tk_Display(tkwin), cursor);
                result = Tk_NameOfCursor(Tk_Display(tkwin), cursor);
            }
            }
            break;
            break;
        }
        }
        case TK_CONFIG_JUSTIFY:
        case TK_CONFIG_JUSTIFY:
            result = Tk_NameOfJustify(*((Tk_Justify *) ptr));
            result = Tk_NameOfJustify(*((Tk_Justify *) ptr));
            break;
            break;
        case TK_CONFIG_ANCHOR:
        case TK_CONFIG_ANCHOR:
            result = Tk_NameOfAnchor(*((Tk_Anchor *) ptr));
            result = Tk_NameOfAnchor(*((Tk_Anchor *) ptr));
            break;
            break;
        case TK_CONFIG_CAP_STYLE:
        case TK_CONFIG_CAP_STYLE:
            result = Tk_NameOfCapStyle(*((int *) ptr));
            result = Tk_NameOfCapStyle(*((int *) ptr));
            break;
            break;
        case TK_CONFIG_JOIN_STYLE:
        case TK_CONFIG_JOIN_STYLE:
            result = Tk_NameOfJoinStyle(*((int *) ptr));
            result = Tk_NameOfJoinStyle(*((int *) ptr));
            break;
            break;
        case TK_CONFIG_PIXELS:
        case TK_CONFIG_PIXELS:
            sprintf(buffer, "%d", *((int *) ptr));
            sprintf(buffer, "%d", *((int *) ptr));
            result = buffer;
            result = buffer;
            break;
            break;
        case TK_CONFIG_MM:
        case TK_CONFIG_MM:
            Tcl_PrintDouble(interp, *((double *) ptr), buffer);
            Tcl_PrintDouble(interp, *((double *) ptr), buffer);
            result = buffer;
            result = buffer;
            break;
            break;
        case TK_CONFIG_WINDOW: {
        case TK_CONFIG_WINDOW: {
            Tk_Window tkwin;
            Tk_Window tkwin;
 
 
            tkwin = *((Tk_Window *) ptr);
            tkwin = *((Tk_Window *) ptr);
            if (tkwin != NULL) {
            if (tkwin != NULL) {
                result = Tk_PathName(tkwin);
                result = Tk_PathName(tkwin);
            }
            }
            break;
            break;
        }
        }
        case TK_CONFIG_CUSTOM:
        case TK_CONFIG_CUSTOM:
            result = (*specPtr->customPtr->printProc)(
            result = (*specPtr->customPtr->printProc)(
                    specPtr->customPtr->clientData, tkwin, widgRec,
                    specPtr->customPtr->clientData, tkwin, widgRec,
                    specPtr->offset, freeProcPtr);
                    specPtr->offset, freeProcPtr);
            break;
            break;
        default:
        default:
            result = "?? unknown type ??";
            result = "?? unknown type ??";
    }
    }
    return result;
    return result;
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * Tk_ConfigureValue --
 * Tk_ConfigureValue --
 *
 *
 *      This procedure returns the current value of a configuration
 *      This procedure returns the current value of a configuration
 *      option for a widget.
 *      option for a widget.
 *
 *
 * Results:
 * Results:
 *      The return value is a standard Tcl completion code (TCL_OK or
 *      The return value is a standard Tcl completion code (TCL_OK or
 *      TCL_ERROR).  Interp->result will be set to hold either the value
 *      TCL_ERROR).  Interp->result will be set to hold either the value
 *      of the option given by argvName (if TCL_OK is returned) or
 *      of the option given by argvName (if TCL_OK is returned) or
 *      an error message (if TCL_ERROR is returned).
 *      an error message (if TCL_ERROR is returned).
 *
 *
 * Side effects:
 * Side effects:
 *      None.
 *      None.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
int
int
Tk_ConfigureValue(interp, tkwin, specs, widgRec, argvName, flags)
Tk_ConfigureValue(interp, tkwin, specs, widgRec, argvName, flags)
    Tcl_Interp *interp;         /* Interpreter for error reporting. */
    Tcl_Interp *interp;         /* Interpreter for error reporting. */
    Tk_Window tkwin;            /* Window corresponding to widgRec. */
    Tk_Window tkwin;            /* Window corresponding to widgRec. */
    Tk_ConfigSpec *specs;       /* Describes legal options. */
    Tk_ConfigSpec *specs;       /* Describes legal options. */
    char *widgRec;              /* Record whose fields contain current
    char *widgRec;              /* Record whose fields contain current
                                 * values for options. */
                                 * values for options. */
    char *argvName;             /* Gives the command-line name for the
    char *argvName;             /* Gives the command-line name for the
                                 * option whose value is to be returned. */
                                 * option whose value is to be returned. */
    int flags;                  /* Used to specify additional flags
    int flags;                  /* Used to specify additional flags
                                 * that must be present in config specs
                                 * that must be present in config specs
                                 * for them to be considered. */
                                 * for them to be considered. */
{
{
    Tk_ConfigSpec *specPtr;
    Tk_ConfigSpec *specPtr;
    int needFlags, hateFlags;
    int needFlags, hateFlags;
 
 
    needFlags = flags & ~(TK_CONFIG_USER_BIT - 1);
    needFlags = flags & ~(TK_CONFIG_USER_BIT - 1);
    if (Tk_Depth(tkwin) <= 1) {
    if (Tk_Depth(tkwin) <= 1) {
        hateFlags = TK_CONFIG_COLOR_ONLY;
        hateFlags = TK_CONFIG_COLOR_ONLY;
    } else {
    } else {
        hateFlags = TK_CONFIG_MONO_ONLY;
        hateFlags = TK_CONFIG_MONO_ONLY;
    }
    }
    specPtr = FindConfigSpec(interp, specs, argvName, needFlags, hateFlags);
    specPtr = FindConfigSpec(interp, specs, argvName, needFlags, hateFlags);
    if (specPtr == NULL) {
    if (specPtr == NULL) {
        return TCL_ERROR;
        return TCL_ERROR;
    }
    }
    interp->result = FormatConfigValue(interp, tkwin, specPtr, widgRec,
    interp->result = FormatConfigValue(interp, tkwin, specPtr, widgRec,
            interp->result, &interp->freeProc);
            interp->result, &interp->freeProc);
    return TCL_OK;
    return TCL_OK;
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * Tk_FreeOptions --
 * Tk_FreeOptions --
 *
 *
 *      Free up all resources associated with configuration options.
 *      Free up all resources associated with configuration options.
 *
 *
 * Results:
 * Results:
 *      None.
 *      None.
 *
 *
 * Side effects:
 * Side effects:
 *      Any resource in widgRec that is controlled by a configuration
 *      Any resource in widgRec that is controlled by a configuration
 *      option (e.g. a Tk_3DBorder or XColor) is freed in the appropriate
 *      option (e.g. a Tk_3DBorder or XColor) is freed in the appropriate
 *      fashion.
 *      fashion.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
        /* ARGSUSED */
        /* ARGSUSED */
void
void
Tk_FreeOptions(specs, widgRec, display, needFlags)
Tk_FreeOptions(specs, widgRec, display, needFlags)
    Tk_ConfigSpec *specs;       /* Describes legal options. */
    Tk_ConfigSpec *specs;       /* Describes legal options. */
    char *widgRec;              /* Record whose fields contain current
    char *widgRec;              /* Record whose fields contain current
                                 * values for options. */
                                 * values for options. */
    Display *display;           /* X display; needed for freeing some
    Display *display;           /* X display; needed for freeing some
                                 * resources. */
                                 * resources. */
    int needFlags;              /* Used to specify additional flags
    int needFlags;              /* Used to specify additional flags
                                 * that must be present in config specs
                                 * that must be present in config specs
                                 * for them to be considered. */
                                 * for them to be considered. */
{
{
    register Tk_ConfigSpec *specPtr;
    register Tk_ConfigSpec *specPtr;
    char *ptr;
    char *ptr;
 
 
    for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) {
    for (specPtr = specs; specPtr->type != TK_CONFIG_END; specPtr++) {
        if ((specPtr->specFlags & needFlags) != needFlags) {
        if ((specPtr->specFlags & needFlags) != needFlags) {
            continue;
            continue;
        }
        }
        ptr = widgRec + specPtr->offset;
        ptr = widgRec + specPtr->offset;
        switch (specPtr->type) {
        switch (specPtr->type) {
            case TK_CONFIG_STRING:
            case TK_CONFIG_STRING:
                if (*((char **) ptr) != NULL) {
                if (*((char **) ptr) != NULL) {
                    ckfree(*((char **) ptr));
                    ckfree(*((char **) ptr));
                    *((char **) ptr) = NULL;
                    *((char **) ptr) = NULL;
                }
                }
                break;
                break;
            case TK_CONFIG_COLOR:
            case TK_CONFIG_COLOR:
                if (*((XColor **) ptr) != NULL) {
                if (*((XColor **) ptr) != NULL) {
                    Tk_FreeColor(*((XColor **) ptr));
                    Tk_FreeColor(*((XColor **) ptr));
                    *((XColor **) ptr) = NULL;
                    *((XColor **) ptr) = NULL;
                }
                }
                break;
                break;
            case TK_CONFIG_FONT:
            case TK_CONFIG_FONT:
                Tk_FreeFont(*((Tk_Font *) ptr));
                Tk_FreeFont(*((Tk_Font *) ptr));
                *((Tk_Font *) ptr) = NULL;
                *((Tk_Font *) ptr) = NULL;
                break;
                break;
            case TK_CONFIG_BITMAP:
            case TK_CONFIG_BITMAP:
                if (*((Pixmap *) ptr) != None) {
                if (*((Pixmap *) ptr) != None) {
                    Tk_FreeBitmap(display, *((Pixmap *) ptr));
                    Tk_FreeBitmap(display, *((Pixmap *) ptr));
                    *((Pixmap *) ptr) = None;
                    *((Pixmap *) ptr) = None;
                }
                }
                break;
                break;
            case TK_CONFIG_BORDER:
            case TK_CONFIG_BORDER:
                if (*((Tk_3DBorder *) ptr) != NULL) {
                if (*((Tk_3DBorder *) ptr) != NULL) {
                    Tk_Free3DBorder(*((Tk_3DBorder *) ptr));
                    Tk_Free3DBorder(*((Tk_3DBorder *) ptr));
                    *((Tk_3DBorder *) ptr) = NULL;
                    *((Tk_3DBorder *) ptr) = NULL;
                }
                }
                break;
                break;
            case TK_CONFIG_CURSOR:
            case TK_CONFIG_CURSOR:
            case TK_CONFIG_ACTIVE_CURSOR:
            case TK_CONFIG_ACTIVE_CURSOR:
                if (*((Tk_Cursor *) ptr) != None) {
                if (*((Tk_Cursor *) ptr) != None) {
                    Tk_FreeCursor(display, *((Tk_Cursor *) ptr));
                    Tk_FreeCursor(display, *((Tk_Cursor *) ptr));
                    *((Tk_Cursor *) ptr) = None;
                    *((Tk_Cursor *) ptr) = None;
                }
                }
        }
        }
    }
    }
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.