?? alert.c
字號:
#ifndef lint#ifdef sccsstatic char sccsid[] = "@(#)alert.c 1.1 92/07/30";#endif#endif#ifndef ecd.alert/* * Copyright (c) 1986, 1987 by Sun Microsystems, Inc. */#include <stdio.h>#include <ctype.h>#include <varargs.h>#include <sys/file.h>#include <sys/types.h>#include <sys/time.h>#include <sys/ioctl.h>#include <sundev/kbd.h>#include <sundev/kbio.h>#include <sunwindow/sun.h>#include <sunwindow/defaults.h>#include <sunwindow/window_hs.h>#include <sunwindow/win_enum.h>#include <sunwindow/win_ioctl.h> /* for journaling */#include <suntool/fullscreen.h>#include <suntool/sunview.h>#include <suntool/tool_struct.h>#include <suntool/panel.h>#include <suntool/help.h>#include <suntool/alert.h>#include <suntool/alert_impl.h>/* ------------------------------------------------------------------ *//* --------------------------- Globals ------------------------------ *//* ------------------------------------------------------------------ */static alert_handle saved_alert;static struct pixfont *button_font;static int default_beeps;static int alert_use_audible_bell;static int alert_jump_cursor;static int alert_ignore_optional;static int alert_fd;static Rect alert_screen_rect;static struct rect irect, orect;static short alert_arrow_right[] = {#include <images/rightswoosh.icon>};mpr_static(alert_arrow_right_pr, 64, 64, 1, alert_arrow_right);static short alert_leftswoosh[] = {#include <images/leftswoosh.icon>};mpr_static(alert_leftswoosh_pr, 64, 64, 1, alert_leftswoosh);static short alert_bang[] = {#include <images/alert_bang32.pr>};mpr_static(alert_bang_pr, 32, 32, 1, alert_bang);static short alert_qmark[] = {#include <images/alert_qmark32.pr>};mpr_static(alert_qmark_pr, 32, 32, 1, alert_qmark);static short alert_gray50_data[] = {#include <images/square_50.pr>};mpr_static(alert_gray50_patch, 16, 16, 1, alert_gray50_data);/* ------------------------------------------------------------------ *//* --------------------------- DISPLAY PROCS ------------------------ *//* ------------------------------------------------------------------ */static int alert_show(); /* display alert */static void alert_get_alert_size(); /* determine rect */static Pw_pixel_cache *alert_drawbox(); /* draw outline & shadow */static void alert_layout(); /* draw items */static void alert_build_button(); /* compute button pr */static void alert_outline_button(); /* draw std button */static void alert_yes_outline_button(); /* draw YES button *//* ------------------------------------------------------------------ *//* --------------------------- UTILITY PROCS ------------------------ *//* ------------------------------------------------------------------ */static void alert_select_button();static void alert_unselect_button();static void alert_preview_message_font();static void alert_preview_button_font();static void alert_set_avlist();static void alert_default();static void alert_add_button_to_list();static int alert_text_width();static int alert_button_width();static int alert_get_fd();static button_handle alert_button_for_event();static int alert_offset_from_baseline();static int calc_max();static button_handle create_button_struct();static void free_button_structs();static void alert_copy_event();static void alert_do_bell();static void alert_blocking_wait();/* ------------------------------------------------------------------ *//* --------------------------- STATICS ------------------------------ *//* ------------------------------------------------------------------ */static int left_marg = 5;static int right_marg = 5;static int top_marg = 5;static int bottom_marg = 10;static int row_gap = 4;static int button_gap;static int min_button_gap = 4;/* * In the case that the height of the swoosh is larger than the height of * the total text, short_text_line is the number of the lines in the text. * Otherwise, it's 0. */static int short_text_line;static struct pixfont *defpf;static int swoosh_height;#define BORDER 3 /* white space surounding text */#define SHADOW 6 /* thickness of shadow */#define BUTTON_HEIGHT_EXTRA 8 /* max extra needed for yes button */#define YES_BUTTON_Y_DIFF 4 /* height diff between yes and no */#define ALERT_ACTION_DO_IT '\015' /* simple return */#define SWOOSH_PIXRECTS_H_OFFSET 16#define SWOOSH_PIXRECTS_V_OFFSET 16#define MENU_BORDER 2/* * Number of pixels of the swoosh that is hanging outside the alert_box */#define SWOOSH_OUTSIDE_BOX 52/* * journaling */extern int sv_journal;extern void win_sync();/* ------------------------------------------------------------------ *//* ----------------------- Public Interface ------------------------- *//* ------------------------------------------------------------------ */intalert_init(){ if (!saved_alert) { char *font_name; int my_fd; saved_alert = (struct alert *)calloc(1, sizeof(struct alert)); if (!saved_alert) { (void)printf(stderr, "Alert ERROR: malloc failed."); return (1); } alert_use_audible_bell = (int)defaults_get_boolean( "/SunView/Audible_Bell", (Bool)TRUE, (int *)NULL); alert_jump_cursor = (int)defaults_get_boolean( "/SunView/Alert_Jump_Cursor", (Bool)TRUE, (int *)NULL); alert_ignore_optional = (int)defaults_get_boolean( "/SunView/Ignore_Optional_Alerts", (Bool)FALSE , (int *)NULL); font_name = defaults_get_string( "/Menu/Font", "/usr/lib/fonts/fixedwidthfonts/screen.b.14", (int *)0); button_font = pf_open(font_name); default_beeps = defaults_get_integer( "/SunView/Alert_Bell", 1, (int *)NULL); defpf = pw_pfsysopen(); if (!button_font) button_font = defpf; /* * assuming that the swoosh from the top of the alert_box proper, then * swoosh_height is the number of pixels from the top of the alert_box to * lowest point of the swoosh glyph. */ swoosh_height = alert_leftswoosh_pr.pr_size.x + SWOOSH_PIXRECTS_V_OFFSET + (alert_arrow_right_pr.pr_size.x - alert_leftswoosh_pr.pr_size.x); } if (alert_fd) { win_getrect(alert_fd, &irect); win_getsavedrect(alert_fd, &orect); } else { if (alert_get_fd(&saved_alert->fd_for_fullscreen) == 0) { return (1); } } return (0);}/* VARARGS */intalert_prompt(client_frame, event, va_alist) Frame client_frame; Event *event; va_dcl{ va_list valist; int result; for (;;) { va_start(valist); result = alert_show(client_frame, event, valist); va_end(valist); if (result != ALERT_HELP) break; help_request(client_frame, saved_alert->help_data, event); } win_setrect(alert_fd, &irect); win_setsavedrect(alert_fd, &orect); return (result);}/* ------------------------------------------------------------------ *//* ----------------------PRIVATE PROCS------------------------------- *//* ------------------------------------------------------------------ */static intalert_show(client_frame, event, valist) Frame client_frame; Event *event; va_list valist;{ Event ie; Alert_attribute avlist[ATTR_STANDARD_SIZE]; register alert_handle alert; int result, fd; Pw_pixel_cache *bitmap_under; struct rect rectsaved, rect; struct fullscreen *fs; button_handle button; button_handle current_button = NULL; int is_highlighted = FALSE; int old_mousex, old_mousey; unsigned short this_event; if (alert_init()) return (ALERT_FAILED); alert = saved_alert; fd = alert->fd_for_fullscreen; (void) alert_default(alert); alert->event = (Event *)event; alert->client_frame = client_frame; attr_make (avlist, ATTR_STANDARD_SIZE, valist); (void)alert_set_avlist (alert, avlist, FALSE); /* only if ALERT_OPTIONAL && ALERT_BUTTON_YES && default option */ if (alert->is_optional && alert->yes_button_exists && (alert_ignore_optional == TRUE)) return (ALERT_YES); alert_do_bell(alert, fd); fs = fullscreen_init(fd); /* go fullscreen first */ if (fs == 0) { return (ALERT_FAILED); /* probably out of fds */ } /* * should get FULLSCREEN from <sunwindow/cursor_impl.h> * but "fullscreen" macro conflicts with the use of * "fullscreen" struct in <suntool/fullscreen.h> */#define FULLSCREEN 0x10 fs->fs_cachedcursor.flags = FULLSCREEN; (void)win_setcursor(fs->fs_windowfd, &fs->fs_cachedcursor); /* now determine the size of the alert */ (void)alert_get_alert_size(alert, &rect, fs->fs_windowfd); if ((bitmap_under = alert_drawbox( /* then draw empty box */ fs->fs_pixwin, &rect, &rectsaved, fs)) == NULL) goto RestoreState; /* now fill in the box with the image, text, buttons etc */ (void)alert_layout(alert, &rect, fs->fs_pixwin); if (alert_jump_cursor && alert->yes_button_exists) { button_handle curr; old_mousex = win_get_vuid_value(fd, LOC_X_ABSOLUTE); old_mousey = win_get_vuid_value(fd, LOC_Y_ABSOLUTE); for (curr = alert->button_info; curr != NULL; curr = curr->next) if (curr->is_yes) win_setmouseposition(fd, curr->button_rect.r_left + curr->button_rect.r_width / 2, curr->button_rect.r_top + curr->button_rect.r_height / 2 ); } /* * if journaling, send sync point. */ if (sv_journal) win_sync(WIN_SYNC_ALERT, fd); /* * Change the owner of the windowfd(WMGR_ENV_PLACEHOLDER) so that * when we go into the loop to read event, we will be able to do so. * Otherwise the events will go to the original owner of the window, * which is sunview. */ win_setowner(fs->fs_windowfd, getpid()); /* Stay in fullscreen until a button is pressed, or trigger used */ for (;;) { unsigned short trigger = alert->default_input_code; if (input_readevent(fs->fs_windowfd, &ie) == -1) break; this_event = event_action(&ie); /* get encoded event */ button = alert_button_for_event(alert, &ie); if ((this_event == trigger) && ((trigger == (int)MS_LEFT) ? (event_is_up(&ie) && (current_button == NULL)) : 1)) { /* catch UP mouse left */ alert->result = ALERT_TRIGGERED; (void) alert_copy_event(alert, &ie); goto Done; } else if (((this_event == ACTION_STOP) || (this_event == WIN_STOP)) && saved_alert->no_button_exists) { alert->result = ALERT_NO; (void) alert_copy_event(alert, &ie); goto Done; } else if ((this_event == ACTION_DO_IT || this_event == ALERT_ACTION_DO_IT) && saved_alert->yes_button_exists) { alert->result = ALERT_YES; (void) alert_copy_event(alert, &ie); goto Done; } else if ((this_event == MS_LEFT) && (alert->button_info)) { if (event_is_down(&ie) && (button != NULL)) { alert_select_button(fs->fs_pixwin, button); current_button = button; is_highlighted = TRUE; } else if (event_is_up(&ie)) { if ((current_button && is_highlighted) && (button != NULL) && (button == current_button)) { alert->result = button->value; (void) alert_copy_event(alert, &ie); goto Done; } else if ((current_button && is_highlighted) && (button != NULL) && (button != current_button)) { alert->result = button->value; (void) alert_copy_event(alert, &ie); goto Done; } } } else if (this_event == ACTION_HELP) { if (event_is_down(&ie)) { alert->result = ALERT_HELP; (void) alert_copy_event(alert, &ie); goto Done; } } else if (this_event == LOC_DRAG) {/* mouse moved w/MS down */ if (((current_button != NULL) && is_highlighted) && ((button == NULL)) && (button != current_button)) { alert_unselect_button(fs->fs_pixwin, current_button); current_button = NULL; is_highlighted = FALSE; } if ((button != current_button) && (is_highlighted == FALSE)) { alert_select_button(fs->fs_pixwin, button); current_button = button; is_highlighted = TRUE; } } }Done: pw_restore_pixels(fs->fs_pixwin, bitmap_under);RestoreState: if (alert_jump_cursor && alert->yes_button_exists) win_setmouseposition(fd, old_mousex, old_mousey); fullscreen_destroy(fs); free_button_structs(alert->button_info); result = alert->result; return (result);}static voidalert_copy_event(alert, event) register alert_handle alert; Event *event;{ if (saved_alert->event == (Event *) 0) { return; } else { saved_alert->event->ie_code = event->ie_code; saved_alert->event->ie_flags = event->ie_flags; saved_alert->event->ie_shiftmask = event->ie_shiftmask; saved_alert->event->ie_locx = event->ie_locx; saved_alert->event->ie_locy = event->ie_locy; saved_alert->event->ie_time.tv_sec = event->ie_time.tv_sec; saved_alert->event->ie_time.tv_usec = event->ie_time.tv_usec; }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -