MCPcopy Create free account
hub / github.com/NetHack/NetHack / create_widget

Function create_widget

win/X11/winstat.c:2176–2242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2174}
2175
2176static void
2177create_widget(Widget parent, struct X_status_value *sv, int sv_index)
2178{
2179 Arg args[4];
2180 Cardinal num_args;
2181
2182 switch (sv->type) {
2183 case SV_VALUE:
2184 sv->w = create_value(parent, sv->name);
2185 set_value(sv->w, width_string(sv_index));
2186 break;
2187 case SV_LABEL:
2188 /* Labels get their own buffer. */
2189 sv->name = (char *) alloc(BUFSZ);
2190 /* we need to cast away 'const' when assigning a value */
2191 *(char *) (sv->name) = '\0';
2192
2193 num_args = 0;
2194 XtSetArg(args[num_args], XtNborderWidth, 0); num_args++;
2195 XtSetArg(args[num_args], XtNinternalHeight, 0); num_args++;
2196 sv->w = XtCreateManagedWidget((sv_index == F_NAME)
2197 ? "name"
2198 : "dlevel",
2199 labelWidgetClass, parent,
2200 args, num_args);
2201 break;
2202 case SV_NAME: {
2203 char buf[BUFSZ];
2204 const char *txt;
2205 const struct f_overload *fo = ff_ovld_from_indx(sv_index);
2206 int baseindx = fo ? fo->conds[0].ff : sv_index;
2207
2208 if (sv_index != baseindx) {
2209 /* this code isn't actually executed; only the base condition
2210 is in one of the fancy status columns and only the fields
2211 in those columns are passed to this routine; the real
2212 initialization--this same assignment--for overloaded
2213 conditions takes place at the end of create_fancy_status() */
2214 sv->w = shown_stats[baseindx].w;
2215 break;
2216 }
2217 txt = width_string(sv_index); /* for conditions, it's just sv->name */
2218 if (fo) {
2219 int i, ff, altln, ln = (int) strlen(txt);
2220
2221 /* make the initial value have the width of the longest of
2222 these overloaded conditions; used for widget sizing, not for
2223 display, and ultimately only matters if one of the overloads
2224 happens to be the longest string in its whole column */
2225 for (i = 1; i < NUM_OVLD && (ff = fo->conds[i].ff) > 0; ++i)
2226 if ((altln = (int) strlen(width_string(ff))) > ln)
2227 ln = altln;
2228 Sprintf(buf, "%*s", ln, txt);
2229 txt = buf;
2230 }
2231 num_args = 0;
2232 XtSetArg(args[0], XtNlabel, txt); num_args++;
2233 XtSetArg(args[num_args], XtNborderWidth, 0); num_args++;

Callers 2

init_columnFunction · 0.85
init_info_formFunction · 0.85

Calls 6

create_valueFunction · 0.85
set_valueFunction · 0.85
width_stringFunction · 0.85
ff_ovld_from_indxFunction · 0.85
allocFunction · 0.50
panicFunction · 0.50

Tested by

no test coverage detected