📄 xpromptpar.c
字号:
Panel par_panel; /* handle for CHECK_CHOICE */ char *prompt_string; /* prompt string for paramter */ char *ext_prompt_string = NULL;/* prompt_string + ":" */ int i,j; /* loop indices */ int nrows, ncols; /* number of PANEL_CHOICE rows and cols */ Scrollbar vert_scrollbar, horiz_scrollbar; /* panel scrollbars */ spsassert(frame != NULL, "create_param_panels: null frame"); spsassert(outfile != NULL, "create_param_panels: null param_list"); DEBUG(2) (stderr, "Entered create_param_panels\n"); /* create parameter control panel*/ con_panel = (Panel)xv_create(frame, SCROLLABLE_PANEL, OPENWIN_SHOW_BORDERS, TRUE, XV_X, 0, NULL); vert_scrollbar = xv_create(con_panel, SCROLLBAR, SCROLLBAR_DIRECTION, SCROLLBAR_VERTICAL, SCROLLBAR_SPLITTABLE, TRUE, NULL); horiz_scrollbar = xv_create(con_panel, SCROLLBAR, SCROLLBAR_DIRECTION, SCROLLBAR_HORIZONTAL, SCROLLBAR_PIXELS_PER_UNIT, 30, NULL);/* if (do_color) { e_cms = exv_init_colors(con_panel); xv_set(con_panel, WIN_BACKGROUND_COLOR, CMS_CONTROL_COLORS + EC_LIGHT_YELLOW, WIN_FOREGROUND_COLOR, CMS_CONTROL_COLORS + EC_BLACK, NULL); }*/ /*create panel items*/ i = 0; while ((param = param_list[i]) != NULL) { /* create ":" terminated prompt string if parameter has a prompt string*/ if ((prompt_string = symprompt(param)) != NULL) { if (ext_prompt_string != NULL) free(ext_prompt_string); ext_prompt_string = malloc((unsigned) strlen(prompt_string) + 2); ext_prompt_string = strcat(strcpy(ext_prompt_string, prompt_string), ":"); } if ((choices = symchoices(param, &nchoices)) != NULL) { if (prompt_string) par_panel = (Panel) xv_create(con_panel, PANEL_MESSAGE, PANEL_NEXT_ROW, -1, PANEL_LABEL_STRING, ext_prompt_string, NULL); get_nrows_ncols(choices, nchoices, &nrows, &ncols); par_panel = (Panel) xv_create(con_panel, PANEL_CHOICE, PANEL_NEXT_ROW, -1, PANEL_CHOICE_NROWS, nrows, PANEL_CHOICE_NCOLS, ncols, PANEL_CHOOSE_ONE, TRUE, PANEL_LABEL_STRING, param, PANEL_CLIENT_DATA, outfile, PANEL_NOTIFY_PROC, write_param, NULL); for (j = 0; j < nchoices; j++) xv_set(par_panel, PANEL_CHOICE_STRING, j, choices[j], NULL); } else { /*parameter does not have discrete choices*/ /* XV doesn't have float item so use strings for everything else*/ if (prompt_string) par_panel = (Panel) xv_create(con_panel, PANEL_MESSAGE, PANEL_NEXT_ROW, -1, PANEL_LABEL_STRING, ext_prompt_string, NULL); par_panel = (Panel) xv_create(con_panel, PANEL_TEXT, PANEL_NEXT_ROW, -1, /*set WIDTH to normalize largest*/ PANEL_VALUE_DISPLAY_LENGTH, 15, PANEL_LABEL_STRING, param, PANEL_CLIENT_DATA, outfile, PANEL_NOTIFY_PROC, write_param, NULL); } /*set default*/ set_default_item(par_panel); i++; } window_fit(con_panel); return(con_panel);}staticvoidset_defaults(item, event) Panel_item item; Event *event;{ Panel panel = (Panel) xv_get(item, PANEL_CLIENT_DATA, NULL); if (debug_level > 1) Fprintf(stderr, "set_defaults: setting all params to defaults\n"); PANEL_EACH_ITEM(panel, item) /*skip any prompt strings*/ if (((Panel_item_type) xv_get(item, PANEL_ITEM_CLASS, NULL)) != PANEL_MESSAGE_ITEM) set_default_item(item); PANEL_END_EACH return;}static voidset_default_item(item)Panel_item item;{ /* set default value for specific panel item */ char *param; /* parameter name */ char **choices; /* (optional) choices for param*/ char *def_val_string; /* default value in string representation */ /* the label string is the parameter name*/ param = (char *) xv_get(item, PANEL_LABEL_STRING, NULL); def_val_string = getsymdef_string(param); if ((choices = symchoices(param, (int *)NULL)) == NULL) /*string used*/ xv_set(item, PANEL_VALUE, def_val_string, NULL); else /*choice item*/ xv_set(item, PANEL_VALUE, lin_search(choices, def_val_string), NULL);}staticintwrite_param(item, event) Panel_item item; /* parameter panel item */ Event *event; /* input event */{ /* update parameter when changed in panel (assume that parameter names are the labels used in the panel? may not be possible, since might want to use the parameter prompt string); use client_data or key_data to attach info such as type or name; just do a putsym have different routine for choices and non-choices so that non-choices handles string conversions and also checks ranges(later) */ /*if limits, check them*/ /*if out of bounds, change to min or max and pop message*/ /*otherwise write the symbol*/ /*have function that checks format, checks limits, and writes -- if doesn't write (and returns various error codes) if either format is wrong or limits are violated -- have calling routine handle the two kinds of errors or just return if all is ok; this could be used also for straight prompting when ESPS_XWIN == no.*/ char **choices; /* parameter value choices */ char *param_strval; /* param value (as string) to be stored */ char *newval; /* param override value when error */ char *paramfile; /* name of parmeter file */ short write_ok = 1; /* was write OK? */ /*parameter name is the item label*/ char *param = (char *) xv_get(item, PANEL_LABEL_STRING, NULL); /* item_class distinguishes choice items, etc. */ Panel_item_type item_class = (Panel_item_type) xv_get(item, PANEL_ITEM_CLASS, NULL); /* hardwire the parameter file name for now*/ paramfile = (char *) xv_get(item, PANEL_CLIENT_DATA, NULL); if (debug_level > 1) Fprintf(stderr, "write_param: new value for %s\n", param); if (item_class == PANEL_CHOICE_ITEM) { choices = symchoices(param, (int *) NULL); param_strval = choices[(int) xv_get(item, PANEL_VALUE, NULL)]; } else /*these are all string items*/ param_strval = (char *) xv_get(item, PANEL_VALUE, NULL); if (debug_level > 1) Fprintf(stderr, "write_param: check and write value %s\n", param_strval); switch (param_checkwrite(param, param_strval, &newval, paramfile)) { case PARAM_MAX: xv_set(item, PANEL_VALUE, newval, NULL); write_ok = 0; raise_param_notice(param, PARAM_MAX, newval, item, event); break; case PARAM_MIN: xv_set(item, PANEL_VALUE, newval, NULL); write_ok = 0; raise_param_notice(param, PARAM_MIN, newval, item, event); break; case PARAM_FORMAT: set_default_item(item); write_ok = 0; newval = (char *) xv_get(item, PANEL_VALUE, NULL); raise_param_notice(param, PARAM_FORMAT, newval, item, event); break; case PARAM_NO_WRITE: write_ok = 0; break; case PARAM_OK: break; } if (write_ok) return(0); else return(-1);}/* xread_params; identical to read_params but with extra arg for progname (check old notes on param file changes) - if environment variable X_PROMT is set, a command panel is popped up for all "?=" parameters; a revised param file is then processed via read_params; (this routine uses the ones described above); try to do it in such a way that one binary distribution can suffice for all (i.e., X_PROMPT has no effect if X not available); also with ifdef on XVIEW*/staticvoidraise_param_notice(param, type, newstrval, item, event)char *param; /* name of parameter */int type; /* type of parameter error */char *newstrval; /* string giving value changed to */Panel_item item; /* item for which error was made */Event *event; /* event pointer for input */{ /*raises an XV notice warning of the type of parameter entry error and the value that was chosen as the replacement*/ Panel owner; /* parameter panel */ char notice_message[100]; /* the actual text of the notice */ int x = 0, y = 0; /* get the parameter panel */ owner = (Panel) xv_get(item, XV_OWNER, NULL); /*get coordinates of the value string*/ x = (int) xv_get(item, PANEL_VALUE_X, NULL); y = (int) xv_get(item, PANEL_VALUE_Y, NULL); if (debug_level > 2) Fprintf(stderr, "\tx = %d, y = %d\n", x, y); switch(type) { case PARAM_MAX: sprintf(notice_message, "Value for %s is too large; reset to %s", param, newstrval); break; case PARAM_MIN: sprintf(notice_message, "Value for %s is too small; reset to %s", param, newstrval); break; case PARAM_FORMAT: sprintf(notice_message, "Format error for %s; reset to default: %s", param, newstrval); break; default: Fprintf(stderr, "raise_param_notice: unsupported notice type\n"); return; } (void)notice_prompt(owner, NULL, NOTICE_MESSAGE_STRINGS, notice_message, NULL, NOTICE_FOCUS_XY, x, y, NOTICE_BUTTON_YES, "Continue", NULL);}staticvoiddone(item, event) Panel_item item; Event *event;{ /*This function gets called when the user is done; first we write out all the parameters (in case people didn't RETURN in the panel); then we destroy the main window, causing the termination of the notifier loop; */ Frame frame; /* main frame */ Panel param_panel; /* the panel with all the parameter settings */ short all_ok = 1; /* did all writes go ok? */ param_panel = (Panel) xv_get(item, PANEL_CLIENT_DATA, NULL); frame = xv_get(param_panel, XV_OWNER); if (debug_level > 1) Fprintf(stderr, "done: writing all params\n"); PANEL_EACH_ITEM(param_panel, item) /*skip any prompt strings*/ if (((Panel_item_type) xv_get(item, PANEL_ITEM_CLASS, NULL)) != PANEL_MESSAGE_ITEM) { if (write_param(item, event) != 0) all_ok = 0; } PANEL_END_EACH if (all_ok) /*set global indicating good output parameter file*/ frame_exit_status = DONE_OK; else frame_exit_status = DONE_NOT_OK; xv_destroy_safe(frame); return;}/* use some heuristics to provide the number of rows and columns for PANEL_CHOICEs*/#define TOT_CHAR_LIM 70voidget_nrows_ncols(choices, nchoices, rows, cols) char **choices; /* NULL terminated array of strings */ int nchoices; int *rows, *cols; /* to be computed here */{ int tot_char = 0; int i; int max_len = 0; /* longest choice string */ int len; for (i = 0; i < nchoices; i++) { len = strlen(choices[i]); tot_char += 2 + len; if (len > max_len) max_len = len; } if (tot_char <= TOT_CHAR_LIM) { *rows = 1; *cols = nchoices; } else { /* should make this smarter; so that we avoid the last row being much shorter than the others */ *cols = (int) TOT_CHAR_LIM / (max_len + 2); *rows = (int) nchoices / *cols; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -