static void InitWidgetSpec( StyledWidgetSpec *widgetSpecPtr, /* Points to an uninitialized widget spec. */ StyledElement *elementPtr, /* Styled element descriptor. */ Tk_OptionTable optionTable) /* The widget's option table. */ { int i, nbOptions; Tk_ElementOptionSpec *elementOptionPtr; const Tk_OptionSpec *widgetOptionPtr; widgetSpecPtr->elementPtr = elementPtr; widgetSpecPtr->optionTable = optionTable; /* * Count the number of options. */ for (nbOptions = 0, elementOptionPtr = elementPtr->specPtr->options; elementOptionPtr->name != NULL; nbOptions++, elementOptionPtr++) { /* empty body */ } /* * Build the widget option list. */ widgetSpecPtr->optionsPtr = ckalloc(sizeof(Tk_OptionSpec *) * nbOptions); for (i = 0, elementOptionPtr = elementPtr->specPtr->options; i < nbOptions; i++, elementOptionPtr++) { widgetOptionPtr = TkGetOptionSpec(elementOptionPtr->name, optionTable); /* * Check that the widget option type is compatible with one of the * element's required types. */ if (elementOptionPtr->type == TK_OPTION_END || elementOptionPtr->type == widgetOptionPtr->type) { widgetSpecPtr->optionsPtr[i] = widgetOptionPtr; } else { widgetSpecPtr->optionsPtr[i] = NULL; } } }
/* TTKGetOptionSpec -- * Look up a Tk_OptionSpec by name from a Tk_OptionTable, * and verify that it's compatible with the specified Tk_OptionType, * along with other constraints (see below). */ static const Tk_OptionSpec *TTKGetOptionSpec( const char *optionName, Tk_OptionTable optionTable, Tk_OptionType optionType) { const Tk_OptionSpec *optionSpec = TkGetOptionSpec(optionName, optionTable); if (!optionSpec) return 0; /* Make sure widget option has a Tcl_Obj* entry: */ if (optionSpec->objOffset < 0) { return 0; } /* Grrr. Ignore accidental mismatches caused by prefix-matching: */ if (strcmp(optionSpec->optionName, optionName)) { return 0; } /* Ensure that the widget option type is compatible with * the element option type. * * TK_OPTION_STRING element options are compatible with anything. * As a workaround for the workaround for Bug #967209, * TK_OPTION_STRING widget options are also compatible with anything * (see <<NOTE-NULLOPTIONS>>). */ if ( optionType != TK_OPTION_STRING && optionSpec->type != TK_OPTION_STRING && optionType != optionSpec->type) { return 0; } return optionSpec; }