⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alert.ecd.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
#ifndef lint#ifdef sccsstatic char	sccsid[] = "@(#)alert.ecd.c 1.1 92/07/30";#endif#endif#ifdef ecd.alert/* * Copyright (c) 1986, 1987 by Sun Microsystems, Inc. */#include <stdio.h>#include <ctype.h>#include <varargs.h>#include <sys/file.h>#include <sys/types.h>#include <sys/time.h>#include <sys/ioctl.h>#include <sundev/kbd.h>#include <sundev/kbio.h>#include <sunwindow/sun.h>#include <sunwindow/defaults.h>#include <sunwindow/window_hs.h>#include <sunwindow/win_enum.h>#include <suntool/fullscreen.h>#include <suntool/sunview.h>#include <suntool/tool_struct.h>#include <suntool/panel.h>#ifdef ecd.help#include <suntool/help.h>#endif#include <suntool/alert.h>#include <suntool/alert_impl.h>/* ------------------------------------------------------------------ *//* --------------------------- Globals ------------------------------ *//* ------------------------------------------------------------------ */static alert_handle		saved_alert;static struct pixfont		*button_font;static int			default_beeps;static int			alert_use_audible_bell;static int			alert_jump_cursor;static int			alert_ignore_optional;static int			alert_fd;static Rect			alert_screen_rect;static short alert_bang[] = {#include <images/alert_bang64.pr>};mpr_static(alert_bang_pr, 64, 64, 1, alert_bang);static short alert_qmark[] = {#include <images/alert_qmark64.pr>};mpr_static(alert_qmark_pr, 64, 64, 1, alert_qmark);static short alert_gray50_data[] = {#include <images/square_50.pr>};mpr_static(alert_gray50_patch, 16, 16, 1, alert_gray50_data);/* ------------------------------------------------------------------ *//* --------------------------- DISPLAY PROCS ------------------------ *//* ------------------------------------------------------------------ */static int		alert_show();		/* display alert	 */static void		alert_get_alert_size(); /* determine rect        */static Pw_pixel_cache  *alert_drawbox();        /* draw outline & shadow */static void		alert_layout();		/* draw items            */static void		alert_build_button();	/* compute button pr     */static void		alert_outline_button(); /* draw std button       */static void		alert_yes_outline_button();  /* draw YES button  *//* ------------------------------------------------------------------ *//* --------------------------- UTILITY PROCS ------------------------ *//* ------------------------------------------------------------------ */static void		alert_select_button();static void		alert_unselect_button();static void		alert_preview_message_font();static void		alert_preview_button_font();static void 		alert_set_avlist();static void		alert_default();static void		alert_add_button_to_list();static int		alert_text_width();static int		alert_button_width();static int		alert_get_fd();static button_handle	alert_button_for_event();static int		alert_offset_from_baseline();static int		calc_max();static button_handle	create_button_struct();static void		free_button_structs();static void		alert_copy_event();static void		alert_do_bell();static void		alert_blocking_wait();/* ------------------------------------------------------------------ *//* --------------------------- STATICS ------------------------------ *//* ------------------------------------------------------------------ */static int		left_marg = 9;static int 		right_marg = 9;static int		top_marg = 19;static int		bottom_marg = 13;static int		row_gap = 4;static int		button_gap;static int		min_button_gap = 12;/* * In the case that the height of the image is larger than the height of  * the total text, short_text_line is the number of the lines in the text. * Otherwise, it's 0. */static int		 short_text_line;static struct pixfont	*defpf;static int		 image_height;static int		 image_width;#define BORDER			3	/* white space surounding text */#define SHADOW			6	/* thickness of shadow */#define BUTTON_HEIGHT_EXTRA	8  	/* max extra needed for yes button */#define YES_BUTTON_Y_DIFF	4	/* height diff between yes and no  */#define ALERT_ACTION_DO_IT	'\015'  /* simple return */#define MENU_BORDER		2/* * Number of pixels of the image that is hanging outside the alert_box */#define IMAGE_OUTSIDE_BOX		32/* ------------------------------------------------------------------ *//* ----------------------- Public Interface ------------------------- *//* ------------------------------------------------------------------ *//* VARARGS */intalert_prompt(client_frame, event, va_alist)    Frame	 client_frame;    Event	*event;    va_dcl{    va_list			valist;    int 			result;#ifdef ecd.help    for (;;) {	va_start(valist);	result = alert_show(client_frame, event, valist);	va_end(valist);	if (result != ALERT_HELP)	    break;	help_request(client_frame, saved_alert->help_data, event);    }#else    va_start(valist);    result = alert_show(client_frame, event, valist);    va_end(valist);#endif    return (result);}/* ------------------------------------------------------------------ *//* ----------------------PRIVATE PROCS------------------------------- *//* ------------------------------------------------------------------ */static intalert_show(client_frame, event, valist)    Frame	 client_frame;    Event	*event;    va_list	valist;{    Event			ie;    Alert_attribute		avlist[ATTR_STANDARD_SIZE];    register alert_handle	alert;    int				result, fd, opened;    Pw_pixel_cache		*bitmap_under;    struct rect 		rectsaved, rect;    struct fullscreen 		*fs;    button_handle	button;    button_handle	current_button = NULL;    int			is_highlighted = FALSE;    int			old_mousex, old_mousey;    unsigned short	this_event;        /*     * assuming that the image from the top of the alert_box proper, then     * image_height is the number of pixels from the top of the alert_box to     * lowest point of the image glyph.     */    if (!saved_alert)  {	char	*font_name;	int	my_fd;	saved_alert = (struct alert *)calloc(1, sizeof(struct alert));	if (!saved_alert) {	    (void)printf(stderr, "Alert ERROR: malloc failed.");	    return (ALERT_FAILED);	}	alert_use_audible_bell = (int)defaults_get_boolean(	    "/SunView/Audible_Bell", (Bool)TRUE, (int *)NULL);	alert_jump_cursor = (int)defaults_get_boolean(	    "/SunView/Alert_Jump_Cursor", (Bool)TRUE, (int *)NULL);	alert_ignore_optional = (int)defaults_get_boolean(	    "/SunView/Ignore_Optional_Alerts", (Bool)FALSE , (int *)NULL);	font_name = defaults_get_string(	    "/Menu/Font",		    "/usr/lib/fonts/fixedwidthfonts/screen.b.14", 		    (int *)0);	button_font = pf_open(font_name);	default_beeps = defaults_get_integer(		"/SunView/Alert_Bell", 1, (int *)NULL);	defpf = pw_pfsysopen();        if (!button_font)            button_font = defpf;    }    alert = saved_alert;    if ((opened = alert_get_fd(&alert->fd_for_fullscreen)) == 0) {	return (ALERT_FAILED);    }    fd = alert->fd_for_fullscreen;    (void) alert_default(alert);    alert->event = (Event *)event;    alert->client_frame = client_frame;    attr_make (avlist, ATTR_STANDARD_SIZE, valist);    (void)alert_set_avlist (alert, avlist, FALSE);        /* only if ALERT_OPTIONAL && ALERT_BUTTON_YES && default option */    if (alert->is_optional &&		alert->yes_button_exists &&		(alert_ignore_optional == TRUE))        return (ALERT_YES);    alert_do_bell(alert, fd);    fs = fullscreen_init(fd); /* go fullscreen first */    if (fs == 0) {	return (ALERT_FAILED);  /* probably out of fds */    }    /* now determine the size of the alert */    (void)alert_get_alert_size(alert, &rect, fs->fs_windowfd);    if ((bitmap_under = alert_drawbox( /* then draw empty box */		fs->fs_pixwin, &rect, &rectsaved, fs)) == NULL)	goto RestoreState;    /* now fill in the box with the image, text, buttons etc */    (void)alert_layout(alert, &rect, fs->fs_pixwin);    if (alert_jump_cursor && alert->yes_button_exists) {	button_handle	curr;      	old_mousex = win_get_vuid_value(fd, LOC_X_ABSOLUTE);    	old_mousey = win_get_vuid_value(fd, LOC_Y_ABSOLUTE);	for (curr = alert->button_info; curr != NULL; curr = curr->next) 	    if (curr->is_yes)	    	win_setmouseposition(fd,	    	    curr->button_rect.r_left + curr->button_rect.r_width / 2,	    	    curr->button_rect.r_top + curr->button_rect.r_height / 2	    	    );    }    /* Stay in fullscreen until a button is pressed, or trigger used */    for (;;) {	unsigned short	trigger = alert->default_input_code;    	if (input_readevent(fs->fs_windowfd, &ie) == -1)	    break;	this_event = event_action(&ie); /* get encoded event */		button = alert_button_for_event(alert, &ie);	if ((this_event == trigger) && ((trigger == (int)MS_LEFT) ? 	    (event_is_up(&ie) && (current_button == NULL)) : 1)) { 	    /* catch UP mouse left */	    alert->result = ALERT_TRIGGERED;	    (void) alert_copy_event(alert, &ie);	    goto Done;	} else if (((this_event == ACTION_STOP) || (this_event == WIN_STOP))	        && saved_alert->no_button_exists) {	    alert->result = ALERT_NO;	    (void) alert_copy_event(alert, &ie);	    goto Done;        } else if ((this_event == ACTION_DO_IT	         || this_event == ALERT_ACTION_DO_IT)		    && saved_alert->yes_button_exists) {	    alert->result = ALERT_YES;	    (void) alert_copy_event(alert, &ie);	    goto Done;	} else if ((this_event == MS_LEFT) && (alert->button_info)) {	    if (event_is_down(&ie) && (button != NULL)) {		alert_select_button(fs->fs_pixwin, button);		current_button = button;		is_highlighted = TRUE;	    } else if (event_is_up(&ie)) {		if ((current_button && is_highlighted)			&& (button != NULL)	                && (button == current_button)) {		    alert->result = button->value;		    (void) alert_copy_event(alert, &ie);		    goto Done;		} else if ((current_button && is_highlighted)		        && (button != NULL)	                && (button != current_button)) {		    alert->result = button->value;		    (void) alert_copy_event(alert, &ie);		    goto Done;		}	    }#ifdef ecd.help	} else if (this_event == ACTION_HELP) {	    if (event_is_down(&ie)) {		alert->result = ALERT_HELP;		(void) alert_copy_event(alert, &ie);		goto Done;	    }#endif	} else if (this_event == LOC_DRAG) {/* mouse moved w/MS down */	    if (((current_button != NULL) && is_highlighted)		    && ((button == NULL))		    &&  (button != current_button)) {		alert_unselect_button(fs->fs_pixwin, current_button);		current_button = NULL;		is_highlighted = FALSE;	    }	    if ((button != current_button) && (is_highlighted == FALSE)) {		alert_select_button(fs->fs_pixwin, button);		current_button = button;		is_highlighted = TRUE;	    }	}    }Done:    pw_restore_pixels(fs->fs_pixwin, bitmap_under);RestoreState:    if (alert_jump_cursor && alert->yes_button_exists) 	    win_setmouseposition(fd, old_mousex, old_mousey);    fullscreen_destroy(fs);    free_button_structs(alert->button_info);    result = alert->result;    return (result);}static voidalert_copy_event(alert, event)    register alert_handle alert;    Event		 *event;{    if (saved_alert->event == (Event *) 0) {	return;    } else {	saved_alert->event->ie_code = event->ie_code;	saved_alert->event->ie_flags = event->ie_flags;	saved_alert->event->ie_shiftmask = event->ie_shiftmask;	saved_alert->event->ie_locx = event->ie_locx;	saved_alert->event->ie_locy = event->ie_locy;	saved_alert->event->ie_time.tv_sec = event->ie_time.tv_sec;	saved_alert->event->ie_time.tv_usec = event->ie_time.tv_usec;    }/*    saved_alert->event->ie_locx = (event_x(event) < 0) ?	    (saved_alert->position_x - abs(event_x(event))) :	    (saved_alert->position_x + event_x(event));    saved_alert->event->ie_locy = (event_y(event) < 0) ? 	    (saved_alert->position_y - abs(event_y(event))) :	    (saved_alert->position_y + event_y(event));*/    if (saved_alert->client_frame) { /* make event client relative */	Rect	client_frame_place;	window_getrelrect(0,	    window_fd(saved_alert->client_frame), &client_frame_place);        saved_alert->event->ie_locx -= client_frame_place.r_left;        saved_alert->event->ie_locy -= client_frame_place.r_top;    }}/* ------------------------------------------------------------------ *//* --------------------------- Statics ------------------------------ *//* ------------------------------------------------------------------ */static intalert_preview_avlist_for_int_value(attr, avlist, default_if_not_present)    Alert_attribute		attr;    register Alert_attribute	*avlist;    int				default_if_not_present;{    Alert_attribute	current_attr;    int			value = default_if_not_present;    for (; *avlist; avlist = alert_attr_next(avlist)) {	current_attr = avlist[0];	if (attr == current_attr) value = (int)avlist[1];    }    return (int)value;}static voidalert_preview_button_font(alert, avlist)    register alert_handle	alert;    register Alert_attribute	*avlist;{    Alert_attribute	attr;    caddr_t		value;    for (; *avlist; avlist = alert_attr_next(avlist)) {        attr = avlist[0]; value = (caddr_t)avlist[1];	switch (attr) {	  case ALERT_BUTTON_FONT:	    alert->button_font = (struct pixfont *) value;	    break;	  default:	    break;	}    }}static voidalert_preview_message_font(alert, avlist)    register alert_handle	alert;    register Alert_attribute	*avlist;{    Alert_attribute	attr;    caddr_t		value;    for (; *avlist; avlist = alert_attr_next(avlist)) {        attr = avlist[0]; value = (caddr_t)avlist[1];	switch (attr) {	  case ALERT_MESSAGE_FONT:	    alert->message_font = (struct pixfont *) value;	    break;	  default:	    break;	}    }}static voidalert_set_avlist(alert, avlist, caller_external)    register alert_handle	alert;    register Alert_attribute	*avlist;    int				caller_external;{    int			i;    int			yes_button_seen = FALSE;    int			no_button_seen = FALSE;    int			number_of_buttons_seen = 0;    int			trigger_set = 0;    Alert_attribute	attr;    caddr_t		value;    int			image_attr_seen = 0; /* use default if haven't */        alert_preview_button_font(alert, avlist);    alert_preview_message_font(alert, avlist);    for (; *avlist; avlist = alert_attr_next(avlist)) {        attr = avlist[0]; value = (caddr_t)avlist[1];	switch (attr) {	case WIN_X:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -