?? alert.ecd.c
字號:
/* ------------------------------------------------------------------ *//* 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 image_x_offset = IMAGE_OUTSIDE_BOX - (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; /* * shrink the surface to be prepared by the number of pixels that * are hanging outside of the alert_box. This way, the pw_preparesurface * is called(clearing the underlying bits), some bits underneath the * "Big alert_box"(defined by the bounding rect that includes the * image don't simply get cleared. */ temp_rect.r_left += image_x_offset; temp_rect.r_width -= image_x_offset; /* draw shadow of prompt box */ pw_preparesurface(pw, &temp_rect); rect.r_left += SHADOW; rect.r_top += SHADOW; pw_preparesurface(pw, &temp_rect); rect.r_left -= SHADOW; 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+SHADOW, rect.r_top + rect.r_height, rect.r_width, 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 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 + image_x_offset, rect.r_top + SHADOW - y); pr_replrop(pw->pw_clipdata->pwcd_prsingle, rect.r_left + SHADOW - x + image_x_offset, rect.r_top + rect.r_height - y, rect.r_width - SHADOW - image_x_offset, SHADOW, PIX_SRC, &alert_gray50_patch, rect.r_left + SHADOW - x + image_x_offset, rect.r_top + rect.r_height - y); /* draw border of prompt box */ pw_writebackground(pw, rect.r_left + image_x_offset, rect.r_top, rect.r_width - image_x_offset, rect.r_height, PIX_SET); rect_marginadjust(&rect, - (2 * MENU_BORDER)); pw_writebackground(pw, rect.r_left + image_x_offset, rect.r_top, rect.r_width - image_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]; if (alert_fd) { *fd = alert_fd; return(1); } windowfd = win_getnewwindow(); 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; win_setinputcodebit(&new_kbd_mask, WIN_STOP);#ifdef ecd.help (void)win_keymap_set_smask(windowfd, ACTION_HELP); win_keymap_set_imask_from_std_bind(&new_kbd_mask, ACTION_HELP);#endif (void)win_set_kbd_mask(windowfd, &new_kbd_mask); (void)input_imnull(&new_pick_mask); new_pick_mask.im_flags |= IM_NEGEVENT; win_setinputcodebit(&new_pick_mask, WIN_STOP); win_setinputcodebit(&new_pick_mask, MS_LEFT); win_setinputcodebit(&new_pick_mask, MS_MIDDLE); win_setinputcodebit(&new_pick_mask, MS_RIGHT);; win_setinputcodebit(&new_pick_mask, LOC_DRAG);; (void)win_set_pick_mask(windowfd, &new_pick_mask); *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.panel
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -