Tk

 view release on metacpan or  search on metacpan

pTk/mTk/generic/tkOption.c  view on Meta::CPAN

	}
    }
}

/*
 *--------------------------------------------------------------
 *
 * Tk_GetOption --
 *
 *	Retrieve an option from the option database.
 *
 * Results:
 *	The return value is the value specified in the option
 *	database for the given name and class on the given
 *	window.  If there is nothing specified in the database
 *	for that option, then NULL is returned.
 *
 * Side effects:
 *	The internal caches used to speed up option mapping
 *	may be modified, if this tkwin is different from the
 *	last tkwin used for option retrieval.
 *
 *--------------------------------------------------------------
 */

Tk_Uid
Tk_GetOption(tkwin, name, className)
    Tk_Window tkwin;		/* Token for window that option is
				 * associated with. */
    CONST char *name;		/* Name of option. */
    CONST char *className;	/* Class of option.  NULL means there
				 * is no class for this option:  just
				 * check for name. */
{
    Tk_Uid nameId, classId = NULL;
    char *masqName;
    register Element *elPtr, *bestPtr;
    register int count;
    StackLevel *levelPtr;
    int stackDepth[NUM_STACKS];
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    /*
     * Note:  no need to call OptionInit here:  it will be done by
     * the SetupStacks call below (squeeze out those nanoseconds).
     */

    if (tkwin != (Tk_Window) tsdPtr->cachedWindow) {
	SetupStacks((TkWindow *) tkwin, 1);
    }

    /*
     * Get a default "best" match.
     */

    bestPtr = &tsdPtr->defaultMatch;

    /*
     * For megawidget support, we want to have some widget options masquerade
     * as options for other widgets.  For example, a combobox has a button in
     * it; this button ought to pick up the *Button.background, etc., options.
     * But because the class of the widget is Combobox, our normal search
     * won't get that option.
     *
     * To work around this, the option name field syntax was extended to allow
     * for a "." in the name; if this character occurs in the name, then it
     * indicates that this name contains a new window class and an option name,
     * ie, "Button.foreground".  If we see this form in the name field, we
     * query the option database directly (since the option stacks will not
     * have the information we need).
     */

    masqName = strchr(name, (int)'.');
    if (masqName != NULL) {
	/*
	 * This option is masquerading with a different window class.
	 * Search the stack to the depth it was before the current window's
	 * information was pushed (the value for which is stored in the bases
	 * field).
	 */
	levelPtr = &tsdPtr->levels[tsdPtr->curLevel];
	nameId = Tk_GetUid(masqName+1);
	for (count = 0; count < NUM_STACKS; count++) {
	    stackDepth[count] = levelPtr->bases[count];
	}
    } else {
	/*
	 * No option masquerading here.  Just use the current level to get the
	 * stack depths.
	 */
	nameId = Tk_GetUid(name);
	for (count = 0; count < NUM_STACKS; count++) {
	    stackDepth[count] = tsdPtr->stacks[count]->numUsed;
	}
    }

    /*
     * Probe the stacks for matches.
     */

    for (elPtr = tsdPtr->stacks[EXACT_LEAF_NAME]->els,
	     count = stackDepth[EXACT_LEAF_NAME]; count > 0;
	 elPtr++, count--) {
	if ((elPtr->nameUid == nameId)
		&& (elPtr->priority > bestPtr->priority)) {
	    bestPtr = elPtr;
	}
    }
    for (elPtr = tsdPtr->stacks[WILDCARD_LEAF_NAME]->els,
	     count = stackDepth[WILDCARD_LEAF_NAME]; count > 0;
	 elPtr++, count--) {
	if ((elPtr->nameUid == nameId)
		&& (elPtr->priority > bestPtr->priority)) {
	    bestPtr = elPtr;
	}
    }

    if (className != NULL) {
	classId = Tk_GetUid(className);
	for (elPtr = tsdPtr->stacks[EXACT_LEAF_CLASS]->els,



( run in 1.288 second using v1.01-cache-2.11-cpan-2398b32b56e )