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

📄 alert.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
    int			x, y, width, height, i, j, remembered_x;    int			y_before_buttons, y_after_buttons;    int			alert_too_wide = 0;    int			alert_too_tall = 0;    button_handle	curr;    int			offset;    /*     * swoosh_offset is the number of pixels of the swoosh glyph that     * is outside the alert_box.  It changes when the glyphs change     */    int			swoosh_offset = SWOOSH_OUTSIDE_BOX;    x = rect->r_left;    y = rect->r_top;    pw_lock(pw, &alert_screen_rect);#ifdef OLD_ALERT_IMAGES    x = rect->r_left + left_marg + BORDER;    if (alert->image_item) {	pw_write(pw, x, y,	    alert->image_item->pr_size.x, alert->image_item->pr_size.y,	    PIX_SRC, alert->image_item, 0, 0);	x += alert->image_item->pr_size.x + left_marg;    }#else    pw_write(pw, x, y,	    ((struct pixrect *)&alert_leftswoosh_pr)->pr_size.x,	    ((struct pixrect *)&alert_leftswoosh_pr)->pr_size.y,	    PIX_SRC|PIX_DST, ((struct pixrect *)&alert_leftswoosh_pr), 0, 0);    /*      * even though we've drawn alert_leftswoosh_pr->pr_size.x pixels,      * we only increment the position pointer by     * (alert_leftswoosh_pr->pr_size.x pixels-SWOOSH_PIXRECTS_H_OFFSET) pixels     * because the arrow pr is layered on top of leftswoosh pr and offset     * by SWOOSH_PIXRECTS_H_OFFSET     */    x += (((struct pixrect *)&alert_leftswoosh_pr)->pr_size.x - SWOOSH_PIXRECTS_H_OFFSET);    y += SWOOSH_PIXRECTS_V_OFFSET;    pw_write(pw, x, y,	    ((struct pixrect *)&alert_arrow_right_pr)->pr_size.x, 	    ((struct pixrect *)&alert_arrow_right_pr)->pr_size.y,	    PIX_SRC|PIX_DST, ((struct pixrect *)&alert_arrow_right_pr), 0, 0);    x += ((struct pixrect *)&alert_arrow_right_pr)->pr_size.x + left_marg;#endif OLD_ALERT_IMAGES    if (alert->message_items) {	char	**strs;	int	num_lines;        Pixfont	*font = (alert->message_font) ? alert->message_font : defpf;        int	offset = alert_offset_from_baseline(font);	/*	 * if short_text is TRUE, then reposition the text	 * so that the arrow sort of points at the text.	 */	if (short_text_line) {	    y = rect->r_top +	    	(swoosh_height - top_marg - row_gap) / (short_text_line + 1);	} else {	    y = rect->r_top + top_marg + row_gap;	}	strs = (char **)alert->message_items;	while (*strs) {	    pw_text(pw, x, (offset >= 0) ? y + offset : y - offset,	        PIX_SRC, font, (char *)*strs);	    num_lines++;	    y += font->pf_defaultsize.y;	    strs++;	}    }    x = rect->r_left + left_marg + BORDER + swoosh_offset;    y = (short_text_line ? rect->r_top + swoosh_height + row_gap : y + row_gap);    if (alert->button_info && (alert->number_of_buttons==1)) {	x += button_gap;	alert_build_button(pw, rect,	    x, (alert->button_info->is_yes) ? y : y + (YES_BUTTON_Y_DIFF / 2),	    alert->button_info, alert->button_font);    } else if (alert->button_info && (alert->number_of_buttons>1)) {	for (curr = alert->button_info; curr != NULL; curr = curr->next) {	    alert_build_button(pw, rect, x,	    	(curr->is_yes) ? y : y + (YES_BUTTON_Y_DIFF / 2),	    	curr, alert->button_font);	    x += curr->button_rect.r_width + button_gap;	    i++;        }    }    pw_unlock(pw);}/* ------------------------------------------------------------------ *//* ----------------------   Misc Utilities   ------------------------ *//* ------------------------------------------------------------------ */static voidalert_default(alert)    alert_handle    alert;{    alert->beeps = default_beeps;     alert->default_input_code = '\0'; /* ASCII NULL */    alert->button_font = button_font;    alert->message_font = (Pixfont *) 0;    alert->position = (int)ALERT_CLIENT_CENTERED;    alert->client_offset_x = FALSE;    alert->client_offset_y = FALSE;    alert->dont_beep = FALSE;    alert->yes_button_exists = FALSE;    alert->no_button_exists = FALSE;    alert->is_optional = FALSE;    alert->event = (Event *) 0;    alert->button_info = (button_handle) 0;    alert->number_of_buttons = 0;    alert->help_data = "sunview:alert";    button_gap = 0;}/* ------------------------------------------------------------------ */static intcalc_max(a, b) /* calculate rather than macro */    int		a, b;{    return ((a>b) ? a : b);}/* ------------------------------------------------------------------ */static voidalert_add_button_to_list(alert, button)    register alert_handle	alert;    button_handle		button;{    button_handle	curr;    if (alert->button_info) {	for (curr = alert->button_info; curr; curr = curr->next)		if (curr->next == NULL) {		    curr->next = button;		    break;		}    } else	alert->button_info = button;    alert->number_of_buttons++;}/* ------------------------------------------------------------------ */static button_handlecreate_button_struct(){    button_handle	pi = NULL;    pi = (button_handle) calloc(1, sizeof(struct buttons));    if (!pi)	fprintf(stderr, "alert: Malloc failed in create_button_struct.\n");    return pi;}/* ------------------------------------------------------------------ */static voidfree_button_structs(first)    button_handle	first;{    button_handle	current;    button_handle	next;        if (!first)	return;    for (current=first; current != NULL; current=current->next) {	next = current->next;	free(current);    }}/* ------------------------------------------------------------------ *//* font char/pixel conversion routines                                *//* ------------------------------------------------------------------ */static intalert_offset_from_baseline(font)Pixfont *font;{    if (font == NULL)    	return (0);    return (font->pf_char[32].pc_home.y); /* space char */}static intalert_text_width(font, str)    Pixfont	*font;    char	*str;{    struct pr_size    size;    size = pf_textwidth(strlen(str), font, str);    return (size.x);} static intalert_button_width(font, button)    Pixfont		*font;    button_handle	button;{    int text_width = alert_text_width(font, button->string);    return (text_width + ((button->is_yes) ? 16 : 12));}static Pw_pixel_cache *alert_drawbox(pw, rectp, rectsavep, fs)	struct pixwin	   *pw;	struct	rect	   *rectp;	struct	rect	   *rectsavep;	struct	fullscreen *fs;{	struct rect	 temp_rect;	Pw_pixel_cache	*bitmap_under;	Pw_pixel_cache	*pw_save_pixels();	int		 swoosh_x_offset = 			 ((struct pixrect *)&alert_leftswoosh_pr)->pr_size.x - 4			 - (2 * MENU_BORDER);		struct	pixrect *pr;	struct rect	rect;	int	x,y;		/* XXX workaround */		temp_rect = *rectp;	rect = *rectp;	rect.r_width += SHADOW;	rect.r_height += SHADOW;	if ((bitmap_under = pw_save_pixels(pw, &rect)) == 0)		return(0);	*rectsavep = rect;	rect.r_width -= SHADOW;	rect.r_height -= SHADOW;	/*	 * In order to be able to see the swoosh that lies outside the	 * alert box, pw_preparesurface has to be done for each column	 * of the swoosh. Hence the numerous pw_preparesurface calls.	 */	rect_marginadjust(&temp_rect, - (2 * MENU_BORDER));	y =  temp_rect.r_top;	temp_rect.r_left += 18;	temp_rect.r_top = y + 6;	temp_rect.r_width = 1;	temp_rect.r_height = 11;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 10;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 13;	temp_rect.r_height = 12;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 15;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 17;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top =  y + 18;	temp_rect.r_height = 13;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top =  y + 19;	temp_rect.r_height = 14;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 20;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 21;	temp_rect.r_height = 15;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 22;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 23;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 23;	temp_rect.r_height = 17;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 24;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 25;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 25;	temp_rect.r_height = 18;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 26;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 27;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 27;	temp_rect.r_height = 19;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 28;	temp_rect.r_height = 18;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 28;	temp_rect.r_height = 19;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 29;	temp_rect.r_height = 20;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 29;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top =  y + 30;	temp_rect.r_height = 19;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 30;	temp_rect.r_height = 20;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 30;	temp_rect.r_height = 21;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 31;	temp_rect.r_height = 20;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 31;	temp_rect.r_height = 21;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 32;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 32;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 32;	temp_rect.r_height = 22;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 33;	temp_rect.r_height = 21;	pw_preparesurface_full(pw, &temp_rect, 1);	y += SWOOSH_PIXRECTS_V_OFFSET;	temp_rect.r_left += 1;	temp_rect.r_top = y + 17;	temp_rect.r_height = 22;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 17;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 17;	temp_rect.r_height = 23;	pw_preparesurface_full(pw, &temp_rect, 1);	temp_rect.r_left += 1;	temp_rect.r_top = y + 17;	temp_rect.r_height = 24;	pw_preparesurface_full(pw, &temp_rect, 1);        /*         * shrink the surface to be prepared by the number of pixels that         * are hanging outside of the "Big alert_box".  This way, the 	 * pw_preparesurface is called(clearing the underlying bits) only 	 * on the inner alert box.	 */	/* draw prompt box */	temp_rect = *rectp;	temp_rect.r_left += swoosh_x_offset;	temp_rect.r_width -= swoosh_x_offset;

⌨️ 快捷键说明

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