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

📄 alert.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
/*    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:	    alert->client_offset_x = (int)value;	    break;	case WIN_Y:	    alert->client_offset_y = (int)value;	    break;	case ALERT_POSITION: 	    if ((int)value == (int)ALERT_SCREEN_CENTERED ||		(int)value == (int)ALERT_CLIENT_CENTERED ||		(int)value == (int)ALERT_CLIENT_OFFSET)		alert->position = (int)value;	    break;	case ALERT_OPTIONAL:	    alert->is_optional = ((int)value == 1) ? 1 : 0;	    break;	case ALERT_NO_BEEPING:	    if ((int)value == 1) alert->dont_beep = 1;	    break;	case ALERT_TRIGGER:	    alert->default_input_code = (int)avlist[1];	    trigger_set = 1;	    break;	case ALERT_MESSAGE_STRINGS_ARRAY_PTR: 	    alert->message_items = (char **)value;	    break;	case ALERT_MESSAGE_STRINGS:	    alert->message_items = (char **)&avlist[1];	    break;	/* 	 * ALERT_NO_IMAGE and ALERT_IMAGE are obsolete attributes.	 */	case ALERT_NO_IMAGE:	case ALERT_IMAGE:	    break;	case ALERT_BUTTON_YES: {	    struct pixrect	*image;	    button_handle	button;	    if (!yes_button_seen) {		yes_button_seen = TRUE;	    } else {	        fprintf(		    stderr,		    "alert: Only one ALERT_BUTTON_YES allowed. Attr ignored.\n");		break;	    }	    button = (button_handle)create_button_struct();	    button->string = (char *)avlist[1];	    button->is_yes = TRUE;	    button->value = ALERT_YES;	    alert->yes_button_exists = TRUE;	    number_of_buttons_seen++;	    (void) alert_add_button_to_list(alert, button);	    break;	}	case ALERT_BUTTON_NO: {	    struct pixrect	*image;	    button_handle	button;	    if (!no_button_seen){		no_button_seen = TRUE;	    } else {	        fprintf(		    stderr,		    "alert: Only one ALERT_BUTTON_NO allowed. Attr ignored.\n");		break;	    }	    button = (button_handle)create_button_struct();	    button->string = (char *)avlist[1];	    button->is_no = TRUE;	    button->value = ALERT_NO;	    alert->no_button_exists = TRUE;	    number_of_buttons_seen++;	    (void) alert_add_button_to_list(alert, button);	    break;	}	case ALERT_BUTTON: { 	    button_handle	button;	    button = (button_handle)create_button_struct();	    button->string = (char *)avlist[1];	    button->value = (int)avlist[2];	    (void) alert_add_button_to_list(alert, button);	    number_of_buttons_seen++;	    break;	}	case ALERT_BUTTON_FONT:	case ALERT_MESSAGE_FONT:	    /* already previewed above */	    break;	case HELP_DATA:	    alert->help_data = value;	    break;	default:	    fprintf(stderr, "alert: attribute not allowed.\n");	    break;	}    }    if ((number_of_buttons_seen == 0) && (trigger_set == 0)) 	alert->default_input_code = (int)ACTION_STOP;}/* ------------------------------------------------------------------ */static voidalert_get_alert_size(alert, rect, fd)    register alert_handle	alert;    struct rect			*rect;    int				fd;{    Rect		r;    int			x, y, height, width, i, left, top, num_lines = 0;    int			swoosh_offset =     			    ((struct pixrect *)&alert_arrow_right_pr)->pr_size.x - 4;    short_text_line = 0;    x = 0;  y = 0; /* start calculations out at zero, add margins later */#ifdef OLD_ALERT_IMAGES    if (alert->image_item) 	x += alert->image_item->pr_size.x + left_marg; #else/*    x += ((struct pixrect *)&alert_arrow_right_pr)->pr_size.x +          ((struct pixrect *)&alert_leftswoosh_pr)->pr_size.x; */#endif OLD_ALERT_IMAGES    if (alert->message_items) {	char	**strs;	char	**tmp_strings;	int	max_width = 0;	int	str_width = 0;        Pixfont	*mess_font = (alert->message_font) ?				alert->message_font : defpf;	strs = (char **)alert->message_items;	tmp_strings = (char **)alert->message_items;	while (*strs) {	    str_width = alert_text_width(mess_font, (char *)*strs);	    max_width = calc_max(str_width, max_width);	    num_lines++;	    strs++;	}	/*	 * The two pixrects are layed out such that the right arrow pixrect	 * is layered 16 pixels both to the right and down of the swoosh pixrect.	 * The assumption is that the arrow comes in pointing pretty much	 * at the text.  The pixrect of the arrow is 64 pixels wide, but	 * only 60 of them are in the border of the alert box.	 * The layout is such that the text is 60 pixels plus the left	 * margin inside of the alert_box on the left and is 60 pixels plus	 * the right margin inside of the alert_box on the right.  The	 * buttons are layed out such that the first button is "left_margin"	 * pixels inside the alert_box and the last is "right_margin" pixels	 * inside the alert_box.	 */	x += max_width + swoosh_offset * 2;	y += (num_lines*mess_font->pf_defaultsize.y);    }    /*     * Make sure that the text part is at least as high as the     * height of the swoosh glyph     */    if (y + row_gap + top_marg > swoosh_height)  {	y += row_gap;	short_text_line = 0;    } else {        short_text_line = num_lines;	y = swoosh_height;    }    i = 0;    if (alert->button_info) {	int  		max_buttons_width = 0;	int		width = 0;	int		total = 0;        button_handle	curr;        struct pixfont *font = alert->button_font;	for (curr = alert->button_info; curr != NULL; curr = curr->next) {	    width = alert_button_width(font, curr);	    max_buttons_width += width;	    i++; 	    }	y += font->pf_defaultsize.y + BUTTON_HEIGHT_EXTRA;	/*	 * figure out the total pixels needed to fit buttons and text, which	 * ever is longer.  This is just for the actual buttons and/or text,	 * and not including the margins	 */	x = calc_max(max_buttons_width, x);	total = x + left_marg + right_marg + (4*BORDER);	if (total >= alert_screen_rect.r_width) {   	  /* if buttons too wide, then they clip just like the text will.  	   * this is not very nice, but TOO BAD!! it's a rough job attempting  	   * to handle their wraping.  	   */	    button_gap = 0;	} else {	    if (i==1) {		button_gap = calc_max(0, (x - max_buttons_width)/2);	    } else { /* >1 */		button_gap = calc_max(0, (x - max_buttons_width)/(i-1));	    }	    if (i>1 && button_gap == 0 && (((i-1)*min_button_gap) < total)) {	    	button_gap = min_button_gap;	    	x += (i-1) * min_button_gap;	    }	}    }    y += top_marg + bottom_marg + (2*BORDER);    /*      * add in the borders and the SWOOSH_OUTSIDE_BOX pixels that are outside of the      * alert_box, but is regarded as alert_box-metro area     */    x += left_marg + right_marg + (4*BORDER) + SWOOSH_OUTSIDE_BOX;    /*     * discount the SWOOSH_OUTSIDE_BOX pixels of the swoosh for centering purpose     */    width = x;    height = y;    /*      * now try and position the alert and make it pretty      *//*  if ((alert->client_frame == (Frame)0) 	    || (window_get(alert->client_frame, FRAME_CLOSED)))	alert->position = (int)ALERT_SCREEN_CENTERED;*/    if (alert->client_frame == (Frame)0)	alert->position = (int)ALERT_SCREEN_CENTERED;    if (alert->client_frame != (Frame)0)	window_getrelrect(0, window_fd(alert->client_frame), &r);    if ((alert->position == (int)ALERT_SCREEN_CENTERED)	    || (alert->client_frame == (Frame)0)) {	/*	 * Disregard the part of swoosh outside of the box when centering	 */	left = calc_max(0, (alert_screen_rect.r_width  - width - SWOOSH_OUTSIDE_BOX)/2);	top = calc_max(0, (alert_screen_rect.r_height - height)/2);    } else {	/*	 * Disregard the part of swoosh outside of the box when centering	 */	left = calc_max(0, r.r_left + (r.r_width  - width - SWOOSH_OUTSIDE_BOX)/2);	top = calc_max(0, r.r_top + (r.r_height - height)/2);	if (alert->position == (int)ALERT_CLIENT_OFFSET) {	    left = alert->client_offset_x + r.r_left-(calc_max(0, width/2));	    top = alert->client_offset_y + r.r_top-(calc_max(0, height/2));	}/* try to reposition alert near frame for aesthetics, if near boarder */	if ((left <= (r.r_left)) && (width >= r.r_width)) {	    if ((left == 0)		&& ((r.r_left + (r.r_width/2)) <= alert_screen_rect.r_width)) {		left += (r.r_width/2);	    }	    if ((left < r.r_left) && ((left + width + 	      (BORDER + SHADOW)) >= alert_screen_rect.r_width)) {		left -= (r.r_width/2);		if ((left + width + (BORDER + SHADOW)) >= 			alert_screen_rect.r_width) { /* still overflows */		    left = alert_screen_rect.r_width - width - 			(BORDER + SHADOW);		    if ((left - (r.r_width/2)) >= 0)			left -= (r.r_width/2);		}	    }	}	if ((top <= (r.r_top)) && (height >= r.r_height)) {	    if ((top == 0)		&& ((r.r_top + (r.r_height/2)) <= alert_screen_rect.r_height)) {		top += (r.r_height/2);	    }	    if ((top < r.r_top) && ((top + height + 	      (BORDER + SHADOW)) > alert_screen_rect.r_height)) {		top -= (r.r_height/2);		if ((top + height + (BORDER + SHADOW)) >= 			alert_screen_rect.r_height) { /* still overflows */		    top = alert_screen_rect.r_height - height - 			(BORDER + SHADOW);		    if ((top - (r.r_height/2)) >= 0)			top -= (r.r_height/2);		}	    }	}    }    if (width > alert_screen_rect.r_width) left = 0;    if (height > alert_screen_rect.r_height) top = 0;    rect->r_top = top;    rect->r_left = left;    rect->r_width = x;    rect->r_height = y;}static voidalert_layout(alert, rect, pw)    register alert_handle	alert;    struct rect			*rect;    struct pixwin		*pw;{    Rect		r;

⌨️ 快捷键说明

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