alert.c
来自「操作系统SunOS 4.1.3版本的源码」· C语言 代码 · 共 1,684 行 · 第 1/4 页
C
1,684 行
pw_preparesurface_full(pw, &temp_rect, 1); /* draw shadow of prompt box */ temp_rect.r_left += SHADOW; temp_rect.r_top += SHADOW; pw_preparesurface_full(pw, &temp_rect, 1); temp_rect.r_left -= SHADOW; temp_rect.r_top -= SHADOW; pw_lock(pw, &alert_screen_rect); /* protect underling pr */ /* restore stuff bitmap_under shadow */ pr = pw_primary_cached_mpr(fs->fs_pixwin, bitmap_under); pw_write(pw, rect.r_left+rect.r_width, rect.r_top + SHADOW, SHADOW, rect.r_height, PIX_SRC, pr, rect.r_width, SHADOW); pw_write(pw, rect.r_left+swoosh_x_offset+SHADOW, rect.r_top + rect.r_height, rect.r_width-swoosh_x_offset, SHADOW, PIX_SRC, pr, SHADOW, rect.r_height); /* * XXX Workaround for pw_replrop bug. Get pixwin by hand instead */ /* pw_replrop(pw, rect.r_left + SHADOW, rect.r_top + SHADOW, rect.r_width, rect.r_height, PIX_SRC|PIX_DST, &alert_gray50_patch, 0, 0); */ /* draw drop shadow as source instead of OR (|PIX_DST) */ x = pw->pw_clipdata->pwcd_clipping.rl_bound.r_left; y = pw->pw_clipdata->pwcd_clipping.rl_bound.r_top; /* this rect includes a left-offset for the swoosh image */ pr_replrop(pw->pw_clipdata->pwcd_prsingle, rect.r_left + rect.r_width - x, rect.r_top + SHADOW - y, SHADOW, rect.r_height, PIX_SRC, &alert_gray50_patch, rect.r_left + rect.r_width - x + swoosh_x_offset, rect.r_top + SHADOW - y); pr_replrop(pw->pw_clipdata->pwcd_prsingle, rect.r_left + SHADOW - x + swoosh_x_offset, rect.r_top + rect.r_height - y, rect.r_width - SHADOW - swoosh_x_offset, SHADOW, PIX_SRC, &alert_gray50_patch, rect.r_left + SHADOW - x + swoosh_x_offset, rect.r_top + rect.r_height - y); /* draw border of prompt box */ pw_writebackground(pw, rect.r_left + swoosh_x_offset, rect.r_top, rect.r_width - swoosh_x_offset, rect.r_height, PIX_SET); rect_marginadjust(&rect, - (2 * MENU_BORDER)); pw_writebackground(pw, rect.r_left + swoosh_x_offset, rect.r_top, rect.r_width - swoosh_x_offset, rect.r_height, PIX_CLR); pw_unlock(pw); *rectp = rect; return(bitmap_under);}static voidalert_build_button(pw, rect, x, y, button, font) struct pixwin *pw; struct rect *rect; int x, y; button_handle button; struct pixfont *font;{ struct pr_prpos where; /* where to write the string */ struct pr_size size; /* size of the pixrect */ int width, height; char *string = button->string; int special = button->is_yes; size = pf_textwidth(strlen(string), font, string); width = size.x; where.pr = (special) ? mem_create(width + 16, size.y + 8, 1) : mem_create(width + 12, size.y + 4, 1); if (!where.pr) return; where.pos.x = (special) ? 8 + (width - size.x) / 2 : 6 + (width - size.x) / 2; where.pos.y = (special) ? 4 + panel_fonthome(font) : 2 + panel_fonthome(font); (void)pf_text(where, PIX_SRC, font, string); if (special) { alert_yes_outline_button(where.pr); } else alert_outline_button(where.pr); width += ((special) ? 16 : 12); height = size.y + ((special) ? 8 : 4); button->button_rect.r_top = y; button->button_rect.r_left = x; button->button_rect.r_width = width; button->button_rect.r_height = height; pw_write(pw, x, y, width, height, PIX_SRC, where.pr, 0, 0);}/* returns 0 if fails to open fd */static intalert_get_fd(fd) int *fd;{ int windowfd, result, parentlink, parentfd; Inputmask new_kbd_mask, new_pick_mask; char name[WIN_NAMESIZE]; char *filename; extern char *getenv(); /* Open WMGR_ENV_PLACEHOLDER to get an fd for input_readevent; * this fd is kept open for the duration of the application, its * closing is left to be taken care of by the death of the application. * Saving the placeholder icon rect and open rect here, and restoring * them in alert_prompt. */ if ((filename = getenv("WMGR_ENV_PLACEHOLDER")) == (char *) NULL) { (void)fprintf(stderr, "No placeholder name in environment?\n"); return 0; } if ((windowfd = open(filename, O_RDWR, 0)) == -1) { perror("Couldn't open placeholder for alert.\n"); return 0; } win_getrect(windowfd, &irect); win_getsavedrect(windowfd, &orect); if (windowfd < 0) return(0); if (we_getparentwindow(name)) return(0); if ((parentfd = open(name, O_RDONLY, 0)) < 0) return(0); parentlink = win_nametonumber(name); (void)win_setlink(windowfd, WL_PARENT, parentlink); (void)win_getrect(parentfd, &alert_screen_rect); close(parentfd); (void)win_setrect(windowfd, &alert_screen_rect); (void)input_imnull(&new_kbd_mask); new_kbd_mask.im_flags |= IM_ASCII | IM_META | IM_NEGMETA | IM_NEGEVENT; (void)win_setinputcodebit(&new_kbd_mask, WIN_STOP); (void)win_keymap_set_smask(windowfd, ACTION_HELP); win_keymap_set_imask_from_std_bind(&new_kbd_mask, ACTION_HELP); (void)win_set_kbd_mask(windowfd, &new_kbd_mask); (void)input_imnull(&new_pick_mask); new_pick_mask.im_flags |= IM_NEGEVENT; (void)win_setinputcodebit(&new_pick_mask, WIN_STOP); (void)win_setinputcodebit(&new_pick_mask, MS_LEFT); (void)win_setinputcodebit(&new_pick_mask, MS_MIDDLE); (void)win_setinputcodebit(&new_pick_mask, MS_RIGHT);; (void)win_setinputcodebit(&new_pick_mask, LOC_DRAG);; (void)win_set_pick_mask(windowfd, &new_pick_mask); /* * Need to open and close a pixwin on the window once to initialize * the window before using it to do fullscreen access. Don't know * why, but this is the only place that a window is being used to * go directly to fullscreen access instead of being used for screen * rendering (bug number 1010749). */ pw_close(pw_open_monochrome(windowfd)); *fd = windowfd; alert_fd = windowfd; return (1);}static voidalert_outline_button(pr)register Pixrect *pr;/* outline_button draws an outline of a button in pr.*/{ int x_left = 0; int x_right = pr->pr_size.x - 1; int y_top = 0; int y_bottom = pr->pr_size.y - 1; int x1 = 3; int x2 = x_right - 3; int y1 = 3; int y2 = y_bottom - 3; /* horizontal lines */ (void)pr_vector(pr, x1, y_top, x2, y_top, PIX_SRC, 1); (void)pr_vector(pr, x1, y_top + 1, x2, y_top + 1, PIX_SRC, 1); (void)pr_vector(pr, x1, y_bottom, x2, y_bottom, PIX_SRC, 1); (void)pr_vector(pr, x1, y_bottom - 1, x2, y_bottom - 1, PIX_SRC, 1); /* vertical lines */ (void)pr_vector(pr, x_left, y1, x_left, y2, PIX_SRC, 1); (void)pr_vector(pr, x_left + 1, y1, x_left + 1, y2, PIX_SRC, 1); (void)pr_vector(pr, x_right, y1, x_right, y2, PIX_SRC, 1); (void)pr_vector(pr, x_right - 1, y1, x_right - 1, y2, PIX_SRC, 1); /* left corners */ (void)pr_vector(pr, x_left, y1, x1, y_top, PIX_SRC, 1); (void)pr_vector(pr, x_left + 1, y1, x1 + 1, y_top, PIX_SRC, 1); (void)pr_vector(pr, x_left + 1, y1 + 1, x1 + 2, y_top, PIX_SRC, 1); (void)pr_vector(pr, x_left, y2, x1, y_bottom, PIX_SRC, 1); (void)pr_vector(pr, x_left + 1, y2, x1 + 1, y_bottom, PIX_SRC, 1); (void)pr_vector(pr, x_left + 1, y2 - 1, x1 + 2, y_bottom, PIX_SRC, 1); /* right corners */ (void)pr_vector(pr, x_right, y1, x2, y_top, PIX_SRC, 1); (void)pr_vector(pr, x_right - 1, y1, x2 - 1, y_top, PIX_SRC, 1); (void)pr_vector(pr, x_right - 1, y1 + 1, x2 - 2, y_top, PIX_SRC, 1); (void)pr_vector(pr, x_right, y2, x2, y_bottom, PIX_SRC, 1); (void)pr_vector(pr, x_right - 1, y2, x2 - 1, y_bottom, PIX_SRC, 1); (void)pr_vector(pr, x_right - 1, y2 - 1, x2 - 2, y_bottom, PIX_SRC, 1);}/* below draws a double, then single outlined button image */static voidalert_yes_outline_button(pr)register Pixrect *pr;{ int x_left = 0; int x_right = pr->pr_size.x - 1; int y_top = 0; int y_bottom = pr->pr_size.y - 1; int x1 = 3; int x2 = x_right - 3; int y1 = 3; int y2 = y_bottom - 3; /* top horizontal lines */ (void)pr_vector( pr, x1, y_top, x2, y_top, PIX_SRC, 1); /*top, single*/ (void)pr_vector( pr, x1, y_top+1, x2, y_top+1, PIX_SRC, 1); /*no blank line*/ (void)pr_vector( pr, x1+1, y_top + 2, x2-1, y_top + 2, PIX_SRC, 1);/*1st dbl line*/ (void)pr_vector( pr, x1+1, y_top + 3, x2-1, y_top + 3, PIX_SRC, 1);/*2nd dbl line*/ /* bottom horizontal lines */ (void)pr_vector( pr, x1, y_bottom, x2, y_bottom, PIX_SRC, 1); /*bottom single*/ (void)pr_vector( pr, x1, y_bottom - 1, x2, y_bottom - 1, PIX_SRC, 1); /*no blank line*/ (void)pr_vector( pr, x1+1, y_bottom - 2, x2-1, y_bottom - 2, PIX_SRC, 1);/*1st above*/ (void)pr_vector( pr, x1+1, y_bottom - 3, x2-1, y_bottom - 3, PIX_SRC, 1);/*2nd above*/ /* left vertical lines (left to right)*/ (void)pr_vector(pr, x_left, y1, x_left, y2, PIX_SRC, 1); (void)pr_vector(pr, x_left+1, y1, x_left+1, y2, PIX_SRC, 1); (void)pr_vector(pr, x_left + 2, y1+1, x_left + 2, y2-1, PIX_SRC, 1); (void)pr_vector(pr, x_left + 3, y1+1, x_left + 3, y2-1, PIX_SRC, 1); /* right vertical lines (right to left)*/ (void)pr_vector(pr, x_right, y1, x_right, y2, PIX_SRC, 1); (void)pr_vector(pr, x_right - 1, y1, x_right - 1, y2, PIX_SRC, 1); (void)pr_vector(pr, x_right - 2, y1+1, x_right - 2, y2-1, PIX_SRC, 1); (void)pr_vector(pr, x_right - 3, y1+1, x_right - 3, y2-1, PIX_SRC, 1); /* left top corners */ (void)pr_vector(pr, x_left, y1, x1, y_top, PIX_SRC, 1); /*single */ (void)pr_vector(pr, x_left+1, y1, x1, y_top+1, PIX_SRC, 1); (void)pr_vector(pr, x_left+1, y1+1, x1+1, y_top+1, PIX_SRC, 1); (void)pr_vector(pr, x_left+2, y1+1, x1+1, y_top+2, PIX_SRC, 1); (void)pr_vector(pr, x_left+3, y1+1, x1+2, y_top+2, PIX_SRC, 1); (void)pr_vector(pr, x_left+3, y1+2, x1+3, y_top+2, PIX_SRC, 1); /* left bottom corners */ (void)pr_vector(pr, x_left, y2, x1, y_bottom, PIX_SRC, 1); /*single */ (void)pr_vector(pr, x_left+1, y2, x1, y_bottom-1, PIX_SRC, 1); (void)pr_vector(pr, x_left+1, y2-1, x1+1, y_bottom-1, PIX_SRC, 1); (void)pr_vector(pr, x_left+2, y2-1, x1+1, y_bottom-2, PIX_SRC, 1); (void)pr_vector(pr, x_left+3, y2-1, x1+2, y_bottom-2, PIX_SRC, 1); (void)pr_vector(pr, x_left+3, y2-2, x1+3, y_bottom-2, PIX_SRC, 1); /* right top corners */ (void)pr_vector(pr, x_right, y1, x2, y_top, PIX_SRC, 1); /*single */ (void)pr_vector(pr, x_right-1, y1, x2, y_top+1, PIX_SRC, 1); (void)pr_vector(pr, x_right-1, y1+1, x2-1, y_top+1, PIX_SRC, 1); (void)pr_vector(pr, x_right-2, y1+1, x2-1, y_top+2, PIX_SRC, 1); (void)pr_vector(pr, x_right-3, y1+1, x2-2, y_top+2, PIX_SRC, 1); (void)pr_vector(pr, x_right-3, y1+2, x2-3, y_top+2, PIX_SRC, 1); /* right bottom corners */ (void)pr_vector(pr, x_right, y2, x2, y_bottom, PIX_SRC, 1); /*single */ (void)pr_vector(pr, x_right-1, y2, x2, y_bottom-1, PIX_SRC, 1); (void)pr_vector(pr, x_right-1, y2-1, x2-1, y_bottom-1, PIX_SRC, 1); (void)pr_vector(pr, x_right-2, y2-1, x2-1, y_bottom-2, PIX_SRC, 1); (void)pr_vector(pr, x_right-3, y2-1, x2-2, y_bottom-2, PIX_SRC, 1); (void)pr_vector(pr, x_right-3, y2-2, x2-3, y_bottom-2, PIX_SRC, 1);}static voidalert_select_button(pw, button) struct pixwin *pw; button_handle button;{ if (!button) return; /* just in case this sneaked by above */ pw_writebackground(pw, button->button_rect.r_left, button->button_rect.r_top, button->button_rect.r_width, button->button_rect.r_height, PIX_NOT(PIX_DST)); /* invert button rectangle */}static voidalert_unselect_button(pw, button) struct pixwin *pw; button_handle button;{ (void)alert_select_button(pw, button);}static button_handlealert_button_for_event(alert, event) register alert_handle alert; Event *event;{ button_handle curr; int x, y; int action = event_action(event); if (alert->button_info == NULL) return (NULL); if ((action != MS_LEFT) && (action != LOC_DRAG)) return (NULL); x = event->ie_locx; y = event->ie_locy; for (curr = alert->button_info; curr; curr = curr->next) { if ( (x >= curr->button_rect.r_left) && (x <= (curr->button_rect.r_left + curr->button_rect.r_width)) && (y >= curr->button_rect.r_top) && (y <= (curr->button_rect.r_top + curr->button_rect.r_height)) ) { return (curr); } } return ((button_handle) 0);}static voidalert_do_bell(alert, fd) alert_handle alert; int fd;{ struct timeval wait; if (!alert_use_audible_bell) return; wait.tv_sec = 0; wait.tv_usec = 100000; if (!alert->dont_beep && (alert->beeps > 0)) { int i = alert->beeps; int cmd, kbdfd; struct screen screen; (void)win_screenget(fd, &screen); if ((kbdfd = open(screen.scr_kbdname, O_RDWR, 0)) < 0) return; while (i--) { cmd = KBD_CMD_BELL; (void) ioctl(kbdfd, KIOCCMD, &cmd); (void)alert_blocking_wait(wait); cmd = KBD_CMD_NOBELL; (void) ioctl(kbdfd, KIOCCMD, &cmd); } (void)close(kbdfd); }}/* below stolen from win_bell */static voidalert_blocking_wait(wait_tv) struct timeval wait_tv;{ extern struct timeval ndet_tv_subt(); /* From notifier code */ struct timeval start_tv, now_tv, waited_tv; int bits; /* Get starting time */ (void)gettimeofday(&start_tv, (struct timezone *)0); /* Wait */ while (timerisset(&wait_tv)) { /* Wait for awhile in select */ bits = 0; (void) select(0, &bits, &bits, &bits, &wait_tv); /* Get current time */ (void)gettimeofday(&now_tv, (struct timezone *)0); /* Compute how long waited */ waited_tv = ndet_tv_subt(now_tv, start_tv); /* Subtract time waited from time left to wait */ wait_tv = ndet_tv_subt(wait_tv, waited_tv); }}#endif ecd.alert
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?