📄 walkmenu_public.c
字号:
#ifndef lint#ifdef sccsstatic char sccsid[] = "@(#)walkmenu_public.c 1.1 92/07/30 Copyright 1985 Sun Micro";#endif#endif/* * Copyright (c) 1985 by Sun Microsystems, Inc. *//*- WALKING MENU PACKAGE walkmenu_public.c, Sun Jun 30 15:38:39 1985 Craig Taylor, Sun Microsystems *//* ------------------------------------------------------------------------- */#include <sys/types.h>#include <sys/time.h>#include <stdio.h>#include <fcntl.h>#include <varargs.h>#include <pixrect/pixrect.h>#include <pixrect/pixfont.h>#include <pixrect/pr_util.h>#include <pixrect/memvar.h>#include <sunwindow/rect.h>#include <sunwindow/rectlist.h>#include <sunwindow/cms.h>#include <sunwindow/pixwin.h>#include <sunwindow/win_input.h>#include <sunwindow/win_cursor.h>#include <sunwindow/win_struct.h>#include <sunwindow/defaults.h>#include "sunwindow/sv_malloc.h"#include <suntool/fullscreen.h>#include <suntool/window.h>#include <suntool/walkmenu_impl.h>/* * win_ioctl.h is dependent on: * sys/{time,ioctl}.h, sunwindow/{rect,rectlist,win_screen,win_input}.h * some of which was already included before we added the ioctl */#include <sys/ioctl.h>#include <sunwindow/win_screen.h>#include <sunwindow/win_ioctl.h>/* ------------------------------------------------------------------------- *//* * Public */extern struct cursor *walkmenu_cursor;/* Pending display cursor for sticky menus *//* /usr/view/2.0/usr/src/sun/usr.bin/suntool/images/menu_pending.cursor */extern struct cursor walkmenu_cursor_pending;/* Define 3 shades of gray for shadow replrop */extern struct pixrect menu_gray25_pr;extern struct pixrect menu_gray50_pr;extern struct pixrect menu_gray75_pr;Menu menu_create();Menu_item menu_create_item();caddr_t menu_get();int menu_set();void menu_destroy();void menu_destroy_with_proc();caddr_t menu_show();caddr_t menu_show_using_fd();Menu_item menu_find();caddr_t menu_pullright_return_result();caddr_t menu_return_value();caddr_t menu_return_item();caddr_t menu_return_no_value();caddr_t menu_return_no_item();/* * Package private */Pkg_extern int menu_curitem();Pkg_extern int menu_render();Pkg_private struct menu_item *menu_create_item_avlist();/* Ops vectors for menus and menu_items */Pkg_extern caddr_t menu_gets(), menu_item_gets();Pkg_extern void menu_sets(), menu_item_sets();Pkg_private void menu_destroys(), menu_item_destroys();Pkg_private struct menu_ops_vector menu_ops ={ menu_gets, menu_sets, menu_destroys};Pkg_private struct menu_ops_vector menu_item_ops ={ menu_item_gets, menu_item_sets, menu_item_destroys};Pkg_private struct fullscreen *menu_fs; /* fullscreen object *//* * Private */Private caddr_t menu_return_result();Private accelerated_selection();Private Defaults_pairs defaults_shadow_enum[] = { "25_percent_gray", (int)&menu_gray25_pr, "50_percent_gray", (int)&menu_gray50_pr, "75_percent_gray", (int)&menu_gray75_pr, NULL, (int)NULL};Private Defaults_pairs defaults_selection_enum[] = { "Default", (int)MENU_DEFAULT_ITEM, "Last_Selection", (int)MENU_SELECTED_ITEM, NULL, (int)NULL};/* * Private defs */#define MENU_DEFAULT_MARGIN 1#define MENU_DEFAULT_LEFT_MARGIN 16#define MENU_DEFAULT_RIGHT_MARGIN 6/* ------------------------------------------------------------------------- *//* * Display the menu, get the menu item, and call notify proc. * Default proc returns a pointer to the item selected or NULL. *//* VARARGS3 */caddr_tmenu_show(menu, win, iep, va_alist) Menu menu; Window win; struct inputevent *iep; va_dcl{ Menu_attribute avlist[ATTR_STANDARD_SIZE]; va_list valist; Menu_attribute *attrs; int fd; fd = window_fd(win); va_start(valist); (void) attr_make((char **)LINT_CAST(avlist), ATTR_STANDARD_SIZE, valist); va_end(valist); for (attrs = avlist; *attrs; attrs = menu_attr_next(attrs)) { switch (attrs[0]) { case MENU_BUTTON: event_set_id(iep, (int)attrs[1]); break; case MENU_FD: /* Remove this someday */ fd = (int)attrs[1]; break; case MENU_POS: iep->ie_locx = (int)attrs[1], iep->ie_locy = (int)attrs[2]; break; case MENU_NOP: break; default: if (ATTR_PKG_MENU == ATTR_PKG(attrs[0])) (void) fprintf(stderr, "menu_show: Menu attribute not allowed.\n%s\n", attr_sprint((caddr_t)NULL, (u_int)attrs[0])); break; } } return(menu_show_using_fd(menu, fd, iep));}caddr_tmenu_show_using_fd(menu, fd, iep) Menu menu; int fd; struct inputevent *iep;{ struct inputevent ie; struct inputmask im; struct menu_info info; struct menu *m = (struct menu *)LINT_CAST(menu); if (!m || m->ops != &menu_ops) return MENU_NO_VALUE; /* * Grab all input and disable anybody but windowfd from writing * to screen while we are violating window overlapping. */ menu_fs = fullscreen_init(fd); if (!menu_fs) return menu_return_no_value(menu, (Menu_item)0); /* * menu fullscreen operations are different from bounding boxes, * window moves, etc. so we want to truely know all plane groups * available. */ (void) ioctl(menu_fs->fs_windowfd, WINGETAVAILPLANEGROUPS, menu_fs->fs_pixwin->pw_clipdata->pwcd_plane_groups_available); /* * Make sure input mask allows menu package to track cursor motion */ /* Keymap debugging function; remove after debugging complete */ /* win_keymap_debug_start_blockio(); */ im = menu_fs->fs_cachedim; im.im_flags |= IM_NEGEVENT; im.im_flags |= IM_ASCII|IM_META|IM_NEGMETA; win_keymap_set_smask(menu_fs->fs_windowfd, ACTION_HELP); win_setinputcodebit(&im, LOC_MOVE); win_setinputcodebit(&im, LOC_STILL); win_setinputcodebit(&im, iep->ie_code); (void) win_setinputmask(menu_fs->fs_windowfd, &im, (struct inputmask *)NULL, WIN_NULLLINK);# ifdef needs_work if (m->allow_accelerated_selection) accelerated_selection(m, menu_fs->fs_windowfd, iep->ie_code);# endif needs_work info.first_iep = iep, info.last_iep = &ie; info.depth = 0; info.help = (caddr_t)0; { /* FIXME: When accelerated selection works make conditional(?) */ ie = *iep; if (m->stay_up) { /* Sticky menus (double click) */ (void)win_setcursor(menu_fs->fs_windowfd, &walkmenu_cursor_pending); do { if (input_readevent(menu_fs->fs_windowfd, &ie) == -1) { (void) fprintf(stderr, "menu_show: failed to track cursor.\n"); perror("menu_show"); return MENU_NO_VALUE; } } while (!(iep->ie_code == ie.ie_code && win_inputnegevent(&ie))); } (void)win_setcursor(menu_fs->fs_windowfd, walkmenu_cursor); (void)menu_render(m, &info, (struct menu_item *)0, RECTNODE_NULL, FALSE,fd); /*** Here we go ***/ } (void)fullscreen_destroy(menu_fs); /* Keymap debugging function; remove after debugging complete */ /* win_keymap_debug_stop_blockio(); */ if (info.depth && m->jump_after_selection || !info.depth && m->jump_after_no_selection) (void) win_setmouseposition(fd, iep->ie_locx, iep->ie_locy); /* * If help was requested, do it. */ if (info.depth == 0 && info.help) help_request((caddr_t)0, info.help, info.last_iep); /* * release event lock before calling notify proc * to allow other window processes to receive input * events while notify proc is executing. */ win_release_event_lock(fd); /* * Call notify_proc. Should handle special case of selection = 0 */ info.notify_proc = m->notify_proc; if (!info.notify_proc) info.notify_proc = MENU_DEFAULT_NOTIFY_PROC; return info.depth > 0 ? menu_return_result(m, &info, (struct menu_item *)0) : menu_return_no_value(menu, (Menu_item)0);}/* Cache the standard menu data obtained from the defaults database */static struct menu *m_cache;/* VARARGS */Menumenu_create(va_alist) va_dcl{ Menu_attribute avlist[ATTR_STANDARD_SIZE]; va_list valist; register struct menu *m = (struct menu *)LINT_CAST(sv_calloc(1, sizeof(struct menu))); char *font_name;#define Null_status (int *)0 if (!m_cache) { m_cache = (struct menu *)LINT_CAST(sv_calloc(1, sizeof(struct menu))); m_cache->default_image.margin = defaults_get_integer_check("/Menu/Margin", MENU_DEFAULT_MARGIN, 1, 100, Null_status); m_cache->default_image.left_margin = defaults_get_integer_check("/Menu/Left_margin", MENU_DEFAULT_LEFT_MARGIN, 1, 100,Null_status); m_cache->default_image.right_margin = defaults_get_integer_check("/Menu/Right_margin", MENU_DEFAULT_RIGHT_MARGIN, 1, 100, Null_status); m_cache->default_image.boxed = (int)defaults_get_boolean("/Menu/Box_all_items", False, Null_status); m_cache->default_image.center = (int)defaults_get_boolean( "/Menu/Center_string_items", False, Null_status); font_name = defaults_get_string("/Menu/Font", "", Null_status); if (*font_name != NULL) m_cache->default_image.font = pf_open(font_name); m_cache->column_major = (int)defaults_get_boolean("/Menu/Items_in_column_major", False, Null_status); m_cache->shadow_pr = (struct pixrect *) defaults_lookup(defaults_get_string("/Menu/Shadow", "50_percent_gray", Null_status), defaults_shadow_enum); m_cache->pullright_delta = defaults_get_integer_check("/Menu/Pullright_delta", MENU_DEFAULT_PULLRIGHT_DELTA, 1, 9999, Null_status); m_cache->jump_after_selection = (int)defaults_get_boolean("/Menu/Restore_cursor_after_selection", False, Null_status); m_cache->jump_after_no_selection = (int)defaults_get_boolean("/Menu/Restore_cursor_after_no_selection", False, Null_status); m_cache->initial_selection = (Menu_attribute) defaults_lookup(defaults_get_string("/Menu/Initial_selection", "Default", Null_status), defaults_selection_enum); m_cache->help_data = "sunview:menu"; m_cache->stand_off = !defaults_get_boolean("/Menu/Initial_selection_selected", False, Null_status); m_cache->display_one_level = !defaults_get_boolean("/Menu/Initial_selection_expanded", True, Null_status); m_cache->default_selection = (Menu_attribute) defaults_lookup(defaults_get_string("/Menu/Default_selection", "Default", Null_status), defaults_selection_enum); m_cache->stay_up = (int)defaults_get_boolean("/Menu/Stay_up", False, Null_status);/* FIXME: Not very useful unless there is instance specific defaults. m_cache->default_position = defaults_get_integer_check("/Menu/Default", 1, 1, 9999, NULL); */ } bcopy((caddr_t)m_cache, (caddr_t)m, sizeof(struct menu)); /* * Malloc the menu storage and create the item list */ m->ops = &menu_ops; m->nitems = 0, m->max_nitems = 2 * MENU_FILLER; m->item_list = (struct menu_item **) LINT_CAST(malloc(sizeof(struct menu_item *) * 2 * MENU_FILLER)); if (!m->item_list) { (void) fprintf(stderr, "menu_create: Malloc failed to allocate an item list.\n"); return NULL; } va_start(valist); (void) attr_make((char **)LINT_CAST(avlist), ATTR_STANDARD_SIZE, valist); va_end(valist); menu_sets(m, avlist); if (!m->notify_proc) m->notify_proc = MENU_DEFAULT_NOTIFY_PROC; return (Menu)m;}/* VARARGS */Menu_itemmenu_create_item(va_alist) va_dcl{ Menu_attribute avlist[ATTR_STANDARD_SIZE]; va_list valist; va_start(valist); (void) attr_make((char **)LINT_CAST(avlist), ATTR_STANDARD_SIZE, valist); va_end(valist); return (Menu_item)menu_create_item_avlist(avlist);}Pkg_private struct menu_item *menu_create_item_avlist(avlist) Menu_attribute *avlist;{ struct menu_item *mi; mi = (struct menu_item *)LINT_CAST(sv_calloc(1, sizeof(struct menu_item))); mi->image = (struct image *)LINT_CAST(image_create( LINT_CAST(IMAGE_RELEASE), 0)); mi->ops = &menu_item_ops; menu_item_sets(mi, avlist); return mi;}/* VARARGS1 */intmenu_set(m, va_alist) caddr_t m; va_dcl{ Menu_attribute avlist[ATTR_STANDARD_SIZE];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -