📄 panel_menu.c
字号:
#ifndef lint#ifdef sccsstatic char sccsid[] = "@(#)panel_menu.c 1.1 92/07/30 Copyr 1984 Sun Micro";#endif#endif/*****************************************************************************//* panel_menu.c *//* Copyright (c) 1985 by Sun Microsystems, Inc. *//*****************************************************************************/#include <suntool/panel_impl.h>#include <suntool/walkmenu.h>#include "sunwindow/sv_malloc.h"/*****************************************************************************//* type indication symbols panel menu titles *//*****************************************************************************/static short bs_data[] = {#include <images/panel_button.pr>};mpr_static(panel_button_pr, 16, 16, 1, bs_data);static short cs_data[] = {#include <images/panel_choose_one.pr>};mpr_static(panel_choose_one_pr, 16, 16, 1, cs_data);static short ms_data[] = {#include <images/panel_choose_many.pr>};mpr_static(panel_choose_many_pr, 16, 16, 1, ms_data);static short ss_data[] = {#include <images/panel_switch.pr>};mpr_static(panel_switch_pr, 16, 16, 1, ss_data);static short ts_data[] = {#include <images/panel_text.pr>};mpr_static(panel_text_pr, 16, 16, 1, ts_data);static Pixrect *panel_pf_string();#define MARK_XOFFSET 3 /* # of pixels to leave after a menu mark */struct menuitem *panel_menu_display(ip, event)register panel_item_handle ip;register Event *event;{ Menu menu; struct menuitem *mi; register int i; if (!ip->menu) return NULL; /* unadjust the event so the menu comes up in the right place */ (void) panel_window_event((Panel) ip->panel, event); /* create and display the walking menu */ menu = menu_create(0); for (i = 0; i < ip->menu->m_itemcount; i++) (void)menu_set(menu, MENU_IMAGE_ITEM, ip->menu->m_items[i].mi_imagedata, &ip->menu->m_items[i], 0); mi = (struct menuitem *) LINT_CAST(menu_show_using_fd(menu, ip->panel->windowfd, event)); menu_destroy(menu); return mi;}panel_free_menu(ip)register panel_item_handle ip;{ /* free the menu storage */ if (ip->menu) { if (ip->menu->m_imagedata) (void)prs_destroy((Pixrect *) LINT_CAST(ip->menu->m_imagedata)); panel_free_menu_items(ip->menu); free((char *) ip->menu); ip->menu = NULL; }; /* free other menu info */ if (is_string(&ip->menu_title)) { free((char *) image_string(&ip->menu_title)); } (void)panel_free_choices(ip->menu_choices, 0, ip->menu_last); ip->menu_choices = NULL; if (ip->menu_values) { free((char *) ip->menu_values); ip->menu_values = NULL; }}static panel_free_menu_items(menu)register struct menu *menu;{ register int i; /* counter */ if (!menu || !menu->m_items) return; for (i = 0; i < menu->m_itemcount; i++) (void)prs_destroy((Pixrect *) LINT_CAST(menu->m_items[i].mi_imagedata)); free((char *) menu->m_items);} /* panel_free_menu_items *//* Syncronize the menu title * with the item's label. */voidpanel_sync_menu_title(ip)register panel_item_handle ip;{ if (ip->menu_status.title_dirty && !ip->menu_status.title_set) { panel_copy_menu_title(ip, &ip->label); ip->menu_status.title_dirty = FALSE; }}/* Free the old menu title and copy * new_title. */voidpanel_copy_menu_title(ip, new_title)register panel_item_handle ip;register panel_image_handle new_title;{ if (is_string(&ip->menu_title)) free((char *) image_string(&ip->menu_title)); ip->menu_title = *new_title; if (is_string(new_title)) image_string(&ip->menu_title) = panel_strsave(image_string(new_title)); (void) re_create_menu_title(ip);}/* Free the old menu choices and copy those * in choices[0..last]. */voidpanel_copy_menu_choices(ip, choices, last)register panel_item_handle ip;panel_image_handle choices;int last;{ register int i; register panel_image_handle mp, cp; (void)panel_free_choices(ip->menu_choices, 0, ip->menu_last); ip->menu_choices = (panel_image_handle) LINT_CAST(sv_calloc((u_int) (last + 1), sizeof(struct panel_image))); ip->menu_last = last; for (i = 0, mp = ip->menu_choices, cp = choices; i <= last; i++, mp++, cp++) { *mp = *cp; if (is_string(cp)) image_string(mp) = panel_strsave(image_string(cp)); } (void) re_create_menu_items(ip);}intpanel_set_menu(ip, avlist)register panel_item_handle ip;Attr_avlist avlist;{ register Panel_attribute attr; /* each attribute */ int choices_type = -1; /* IM_STRING or IM_PIXRECT */ caddr_t *choices; /* choices array */ Pixfont **choices_fonts = NULL; /* choices fonts */ short choices_changed = FALSE; int title_type = -1; caddr_t title_data; short title_changed = FALSE; Pixfont *title_font = is_string(&ip->label) ? image_font(&ip->label) : ip->panel->font; int type_pr_set = FALSE; /* non zero if type_pr is set */ register int which_choice, which_arg; switch (ip->item_type) { case PANEL_BUTTON_ITEM: case PANEL_TEXT_ITEM: case PANEL_CHOICE_ITEM: case PANEL_TOGGLE_ITEM: break; default: return 1; } while (attr = (Panel_attribute) *avlist++) { switch (attr) { case PANEL_MENU_TITLE_STRING: case PANEL_MENU_TITLE_IMAGE: title_type = attr == PANEL_MENU_TITLE_STRING ? IM_STRING : IM_PIXRECT; title_data = *avlist++; ip->menu_status.title_set = TRUE; break; case PANEL_MENU_TITLE_FONT: title_font = (Pixfont *) LINT_CAST(*avlist++); ip->menu_status.title_font_set = TRUE; if (is_string(&ip->menu_title)) { image_set_font(&ip->menu_title, title_font); title_changed = TRUE; } break; case PANEL_MENU_CHOICE_STRINGS: case PANEL_MENU_CHOICE_IMAGES: choices_type = attr == PANEL_MENU_CHOICE_STRINGS ? IM_STRING : IM_PIXRECT; choices = avlist; /* base of the array */ ip->menu_status.choices_set = TRUE; while (*avlist++); /* skip past the list */ break; case PANEL_MENU_CHOICE_FONTS: choices_fonts = (Pixfont **)avlist; ip->menu_status.choice_fonts_set = TRUE; while (*avlist++); /* skip past the list */ break; case PANEL_SHOW_MENU_MARK: if((int) *avlist++) ip->flags |= SHOW_MENU_MARK; else ip->flags &= ~SHOW_MENU_MARK; break; case PANEL_MENU_CHOICE_VALUES: if (!*avlist) ip->menu_values = NULL; else { /* free the old value array */ if (ip->menu_values) free((char *) ip->menu_values); /* count & allocate the new array */ for (which_choice = 0; avlist[which_choice]; which_choice++); ip->menu_values = (caddr_t *) LINT_CAST(sv_calloc((u_int) which_choice, sizeof(caddr_t))); /* copy the values */ for (which_choice = 0; avlist[which_choice]; which_choice++) ip->menu_values[which_choice] = avlist[which_choice]; } while (*avlist++); choices_changed = TRUE; break; case PANEL_MENU_MARK_IMAGE: ip->menu_mark_on = (*avlist ? (Pixrect *) LINT_CAST(*avlist) : &panel_empty_pr); avlist++; ip->menu_mark_width = MARK_XOFFSET + max(ip->menu_mark_on->pr_width, ip->menu_mark_off->pr_width); ip->menu_mark_height = max(ip->menu_mark_on->pr_height, ip->menu_mark_off->pr_height); choices_changed = TRUE; break; case PANEL_MENU_NOMARK_IMAGE: ip->menu_mark_off = (*avlist ? (Pixrect *) LINT_CAST(*avlist) : &panel_empty_pr); avlist++; ip->menu_mark_width = MARK_XOFFSET + max(ip->menu_mark_on->pr_width, ip->menu_mark_off->pr_width); ip->menu_mark_height = max(ip->menu_mark_on->pr_height, ip->menu_mark_off->pr_height); choices_changed = TRUE; break; case PANEL_TYPE_IMAGE: ip->menu_type_pr = (*avlist ? (Pixrect *) LINT_CAST(*avlist) : &panel_empty_pr); avlist++; type_pr_set = TRUE; title_changed = TRUE; break; default: /* skip past what we don't care about */ avlist = attr_skip(attr, avlist); break; } } /* free old title, allocate new */ if (set(title_type)) { char *old_string = is_string(&ip->menu_title) ? image_string(&ip->menu_title) : NULL; (void) panel_make_image(title_font, &ip->menu_title, title_type, title_data, TRUE, FALSE); title_changed = TRUE; /* now free the old string */ if (old_string) free((char *) old_string);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -