📄 xbbox.c
字号:
else { /* skip submenus beyond level 2 */ submenu = (menudata *) subdata->submenu; if (submenu->label) Fprintf(stderr, "exv_bbox: submenu \"%s\" beyond level 2, ignored.\n", submenu->label); else Fprintf(stderr, "exv_bbox: submenu beyond level 2 ignored.\n"); } subdata = subdata->next; } /* menu finished, create title button and attach menu */ if (n_item) { menu_button = xv_create(*bpanel, PANEL_BUTTON, 0); xv_set(button_menu, MENU_CLIENT_DATA, menu_button, 0); xv_set(menu_button, PANEL_LABEL_STRING, smenu->label, PANEL_NOTIFY_PROC, menu_but_selected, PANEL_ITEM_MENU, button_menu, 0); } return(menu_button);}static Panel_itemadd_panel_list(params, bpanel, smenu)bbox_par *params;Panel *bpanel;menudata *smenu;{/* This function adds to the panel (bpanel) a panel list; * The set of string items used derives from an olwm menu file. * This function is called from add_menu_file_buttons in the case of a * submenu when panel lists are specified. */ Panel_item pchoice = NULL; char *exec_str[1024]; /* assume no more than 1024 menu items! */ buttondata *subdata; menudata *submenu; char *label = (char *) malloc(strlen(smenu->label) + 2); int n_item, i; sprintf(label, "%s:", smenu->label); pchoice = xv_create(*bpanel, PANEL_CHOICE, PANEL_LAYOUT, (params->choice_horizontal ? PANEL_HORIZONTAL : PANEL_VERTICAL), PANEL_LABEL_STRING, label, PANEL_NOTIFY_PROC, choice_item_sel, PANEL_CHOOSE_ONE, TRUE, PANEL_CHOOSE_NONE, TRUE, PANEL_VALUE, -1, XV_KEY_DATA, LAST_VAL_KEY, -1, 0); subdata = smenu->bfirst; n_item = 0; while(subdata != NULL) { if (subdata->submenu == NULL) { if ((subdata->name != NULL) && (subdata->exec != NULL)) { xv_set(pchoice, PANEL_CHOICE_STRING, n_item, subdata->name, NULL); exec_str[n_item] = subdata->exec; if (subdata->isDefault) { xv_set(pchoice, PANEL_VALUE, n_item, 0); xv_set(pchoice, XV_KEY_DATA, LAST_VAL_KEY, n_item, 0); } n_item++; } else { Fprintf(stderr, "exv_bbox: skipped button with (nil) name or exec function\n"); } } else { /* skip submenus beyond level 2 */ submenu = (menudata *) subdata->submenu; if (submenu->label) Fprintf(stderr, "exv_bbox: submenu \"%s\" beyond level 2, ignored.\n", submenu->label); else Fprintf(stderr, "exv_bbox: submenu beyond level 2 ignored.\n"); } subdata = subdata->next; } /* Create list of exec commands and attach as client data. */ if (n_item) { char **new_exec_str = (char **) malloc(n_item * sizeof(char *)); for (i = 0; i < n_item; i++) new_exec_str[i] = savestring(exec_str[i]); xv_set(pchoice, PANEL_CLIENT_DATA, new_exec_str, NULL); } return(pchoice);}static intnew_row(params)bbox_par *params;{/* Returns 1 if a new row of buttons is being started, else 0; * This function makes use of the globals: * * tot_buttons: cumulative button number * last_row: when this changes, a new row has started */ int j; /* actual button number in this row */ int cols; /* number of desired buttons per row */ cols = params->n_per_row; /*set button number (don't count optional quit button)*/ j = tot_buttons; /* special case for first button (forces new row after optional quit but)*/ if (j == 0) { tot_buttons++; return 1; } /* general case thereafter */ if ((j/cols) == last_row) { tot_buttons++; return 0; } else { tot_buttons++; last_row++; return 1; }}static bbox_par*bbox_defaults(){/* This function allocates space for exv_bbox a parameter structure * and fills it in with default values. */ bbox_par *def = (bbox_par*) malloc(sizeof(bbox_par)); if (debug_level > 1) Fprintf(stderr, "bbox_defaults: generating defaults for exv_bbox\n"); def->quit_button = 0; def->quit_label = "QUIT"; def->quit_data = NULL; def->quit_data_proc = exec_data; def->show = 1; def->n_per_row = 10; def->title = EXV_WINDOW_TITLE; def->icon_title = EXV_ICON_TITLE; def->but_data_proc = exec_data; def->owner = (Frame) NULL; def->but_labels = def->but_data = (char **) NULL; def->menu_file = (char *) NULL; def->button_choice = 0; /* use menu buttons */ def->choice_horizontal = 0; /* if choices, do vertical */ /* default positioning leaves it up to window manager */ def->x_pos = -1; def->y_pos = -1; return(def);}static intcheck_par(but_def)bbox_par *but_def;{/* * This function performs some rudimentary consistency checks of * exv_bbox parameters. */ if (but_def->title == NULL) but_def->title = EXV_WINDOW_TITLE; if (but_def->icon_title == NULL) but_def->icon_title = EXV_ICON_TITLE; if ((but_def->menu_file == NULL) && ((but_def->but_labels == NULL) || (but_def->but_data == NULL) || (but_def->but_labels[0] == NULL) || (but_def->but_data[0] == NULL))) return(0); else if (but_def->but_data_proc == NULL) return(0); else return(1);}#define P_PRINT(a,b) (void) fprintf(stderr,"a = b\n", but_def->a)voidprint_bbox_par(but_def)bbox_par *but_def;{/* prints the contents of an exv_bbox parameter structure */ int i; P_PRINT(show, %d); P_PRINT(n_per_row, %d); P_PRINT(quit_button, %d); P_PRINT(x_pos, %d); P_PRINT(y_pos, %d); P_PRINT(title, %s); i = 0; if ((but_def->but_labels != NULL) && (but_def->but_data != NULL)) { while ((but_def->but_labels[i] != NULL) && (but_def->but_data[i] !=NULL)) { Fprintf(stderr, "but_labels[%d] = %s\n", i, but_def->but_labels[i]); Fprintf(stderr, "but_data[%d] = %s\n", i, but_def->but_data[i]); i++; } } if (but_def->menu_file != NULL) P_PRINT(menu_file, %s);}static voidquit_proc(item)Panel_item item;{ Frame frame = (Frame)xv_get(item, PANEL_CLIENT_DATA); if (bbox_params->quit_data) bbox_params->quit_data_proc(bbox_params->quit_data, item); xv_destroy_safe(frame);}static voidbut_selected(item)Panel_item item;{/* This function is called when any simple (non-menu) button is pressed. * It retrieves the data string associated with the button and invokes * the button execution function. */ char *panel_label, *panel_data; void (*button_data_proc)(); panel_label = (char *) xv_get(item, PANEL_LABEL_STRING); panel_data = (char *) xv_get(item, PANEL_CLIENT_DATA); if (debug_level > 1) { Fprintf(stderr, "exv_bbox: panel button %s selected\n", panel_label); Fprintf(stderr, "\tdata string is: %s\n", panel_data); } button_data_proc = (void (*)()) xv_get(xv_get(item, XV_OWNER), XV_KEY_DATA, EXVK_BUT_DATA_PROC); button_data_proc(panel_data, item);}static intmenu_but_selected(item, event)Panel_item item;{/* This is called when a menu button is pressed. It doesn't really * do anything. */ if (debug_level > 1) Fprintf(stderr, "Menu button %s selected\n", (char *) xv_get(item, PANEL_LABEL_STRING)); return XV_OK;}static voidmenu_item_sel(menu, menu_item)Menu menu;Menu_item menu_item;{/* This function is called when the button is released over a menu * item. The data string is attached to the menu item via MENU_CLIENT_DATA. * A handle to the button that was pushed to get the menu is obtained * via MENU_CLIENT_DATA from the menu. These two items are then passed * to the data procedure (passed by user, or default is exec) */ char *menu_label, *menu_data; Panel_item button; void (*button_data_proc)(); menu_label = (char *) xv_get(menu_item, MENU_STRING); menu_data = (char *) xv_get(menu_item, MENU_CLIENT_DATA); button = (Panel_item) xv_get(menu, MENU_CLIENT_DATA); if (debug_level > 1) { Fprintf(stderr, "exv_bbox: Menu item %s selected,\n", menu_label); Fprintf(stderr, "\tdata string is: %s\n", menu_data); } button_data_proc = (void (*)()) xv_get(xv_get(button, XV_OWNER), XV_KEY_DATA, EXVK_BUT_DATA_PROC); button_data_proc(menu_data, button);}static void choice_item_sel(item, value, event)Panel_item item;int value;Event *event;{ void (*button_data_proc)(); int last_value; char **exec_str = (char **) xv_get(item, PANEL_CLIENT_DATA); char *name = (char *) xv_get(item, PANEL_LABEL_STRING); if (value == -1) { if (debug_level > 1) Fprintf(stderr, "exv_bbox: same choice selected again.\n"); last_value = xv_get(item, XV_KEY_DATA, LAST_VAL_KEY); xv_set(item, PANEL_VALUE, last_value, NULL); value = last_value; } xv_set(item, XV_KEY_DATA, LAST_VAL_KEY, value, NULL); if (debug_level > 1) { Fprintf(stderr, "exv_bbox: Choice item %s selected, value %d,\n", name, value); Fprintf(stderr, "\tdata string is: %s\n", exec_str[value]); } button_data_proc = (void (*)()) xv_get(xv_get(item, XV_OWNER), XV_KEY_DATA, EXVK_BUT_DATA_PROC); button_data_proc(exec_str[value], item);}static voidexec_data(data_string, button)char *data_string;Panel_item button;{/* This is the default button execution function - it just execs the * data string associated with the button (or menu item). */ if (debug_level) Fprintf(stderr, "exv_bbox: using default but_data_proc; will exec this command:\n %s\n", data_string); exec_command(data_string);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -