📄 alert.ecd.c
字号:
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_NO_IMAGE: if ((int)value == 1) alert->no_image = 1; break; case ALERT_IMAGE: alert->image_item = (struct pixrect *)value; image_attr_seen = 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; 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;#ifdef ecd.help case HELP_DATA: alert->help_data = value; break;#endif default: fprintf(stderr, "alert: attribute not allowed.\n"); break; } } if ((!image_attr_seen) && (!alert->no_image)) { /* use defaults */ alert->image_item = (struct pixrect *) (number_of_buttons_seen > 1) ? &alert_qmark_pr : &alert_bang_pr; } if (alert->image_item) { image_width = alert->image_item->pr_size.x; image_height = alert->image_item->pr_size.y; } else image_height = image_width = 0; 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; short_text_line = 0; x = 0; y = 0; /* start calculations out at zero, add margins later */ 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++; } x += max_width; y += (num_lines*mess_font->pf_defaultsize.y); } /* * Make sure that the text part is at least as high as the * height of the image */ if (y + row_gap > image_height) { y += row_gap; short_text_line = 0; } else { short_text_line = num_lines; y = image_height + top_marg; } 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 + image_width/2 + 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 IMAGE_OUTSIDE_BOX pixels that are outside of the * alert_box, but is regarded as alert_box-metro area */ x += left_marg + image_width + right_marg + (4*BORDER) + IMAGE_OUTSIDE_BOX; /* * discount the IMAGE_OUTSIDE_BOX pixels of the image 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 image outside of the box when centering */ left = calc_max(0, (alert_screen_rect.r_width - width - IMAGE_OUTSIDE_BOX)/2); top = calc_max(0, (alert_screen_rect.r_height - height)/2); } else { /* * Disregard the part of image outside of the box when centering */ left = calc_max(0, r.r_left + (r.r_width - width - IMAGE_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; 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; /* * image_offset is the number of pixels of the image that * is outside the alert_box. It changes when the image change */ int image_offset = IMAGE_OUTSIDE_BOX; x = rect->r_left + image_offset; y = rect->r_top + top_marg + BORDER; pw_lock(pw, &alert_screen_rect); if (alert->image_item) { pw_write(pw, x - alert->image_item->pr_size.x/2 - (2 * MENU_BORDER), y, alert->image_item->pr_size.x, alert->image_item->pr_size.y, PIX_SRC, alert->image_item, 0, 0); pr_replrop(pw->pw_clipdata->pwcd_prsingle, x + alert->image_item->pr_size.x/2 - (2 * MENU_BORDER), y + SHADOW, SHADOW, alert->image_item->pr_size.y, PIX_SRC, &alert_gray50_patch, x, y); pr_replrop(pw->pw_clipdata->pwcd_prsingle, x - (2 * MENU_BORDER), y + alert->image_item->pr_size.y, alert->image_item->pr_size.x/2 + SHADOW, SHADOW, PIX_SRC, &alert_gray50_patch, x, y); } x += image_width/2 + left_marg + BORDER; 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); 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 + image_offset + image_width/2 + left_marg + BORDER; if (short_text_line) y = rect->r_top + BORDER + top_marg*2 + image_height; else 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->no_image = 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;#ifdef ecd.help alert->help_data = "sunview:alert";#endif 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); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -