Path: utzoo!utgpu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!ucbvax!bloom-beacon!eru!hagbard!sunic!ericom!news From: gunnar@falcon.ericsson.se (Was a Sunny day) Newsgroups: alt.sources Subject: Scantool part 5(5) (shar) Message-ID: <1991Jun18.125048.11369@ericsson.se> Date: 18 Jun 91 12:50:48 GMT Sender: news@ericsson.se Organization: The greatest Phone Company around Lines: 970 Nntp-Posting-Host: falcon.ericsson.se #!/bin/sh # this is scan.05 (part 5 of a multipart archive) # do not concatenate these parts, unpack them in order with /bin/sh # file sunview.c continued # if test ! -r _shar_seq_.tmp; then echo 'Please unpack part 1 first!' exit 1 fi (read Scheck if test "$Scheck" != 5; then echo Please unpack part "$Scheck" next! exit 1 else exit 0 fi ) < _shar_seq_.tmp || exit 1 if test ! -f _shar_wnt_.tmp; then echo 'x - still skipping sunview.c' else echo 'x - continuing file sunview.c' sed 's/^X//' << 'SHAR_EOF' >> 'sunview.c' && Frame frame ; Event *event ; Notify_arg arg ; Notify_event_type type ; { X Notify_value value ; X Rect *r ; X X value = notify_next_event_func(frame, (Notify_event) event, arg, type) ; X if (event_id(event) == WIN_RESIZE) X if (firsttime) X { X init_width = (int) window_get(base_frame, WIN_WIDTH) ; X init_height = (int) window_get(base_frame, WIN_HEIGHT) ; X firsttime = 0 ; X } X else X { X r = (Rect *) LINT_CAST(window_get(frame, WIN_RECT)) ; X r->r_width = init_width ; X r->r_height = init_height ; X WINDOW_SET(frame, FRAME_OPEN_RECT, r, 0) ; X do_repaint() ; X } X return(value) ; } X init_fonts() { X font[(int) NFONT] = open_font(NORMAL_FONT) ; X font_width = font[(int) NFONT]->pf_defaultsize.x ; X font[(int) BFONT] = open_font(BOLD_FONT) ; } X init_ws_type() { X ops[(int) GSET] = PIX_SET ; X ops[(int) GCLR] = PIX_CLR ; X ops[(int) GXOR] = PIX_SRC ^ PIX_DST ; X ops[(int) GSRC] = PIX_SRC ; X ops[(int) GOR] = PIX_SRC | PIX_DST ; X ops[(int) GNOT] = PIX_NOT(PIX_DST) ; X X firsttime = 1 ; } X make_frames(argc, argv) int argc ; char *argv[] ; { X scantool_icon = icon_create(ICON_IMAGE, &icon_pr, 0) ; X base_frame = window_create((Window) 0, FRAME, X FRAME_ICON, scantool_icon, X FRAME_LABEL, " MICROTEK MSF-300A Image Scanner", X FRAME_EMBOLDEN_LABEL, TRUE, X FRAME_ARGS, argc,argv, X 0) ; X X show_frame = window_create(base_frame, FRAME, X FRAME_SHOW_LABEL, TRUE, X WIN_WIDTH, 650, X WIN_HEIGHT, 900, X WIN_X, 0, X WIN_Y, 0, X WIN_SHOW, FALSE, X 0) ; X NOTIFY_INTERPOSE_EVENT_FUNC(base_frame, handle_resize, NOTIFY_SAFE) ; } X make_subframes() { X cursor[(int) FRAME_CUR] = cursor_create(CURSOR_IMAGE, &frame_cursor_pr, X CURSOR_XHOT, 7, X CURSOR_YHOT, 7, X 0) ; X cursor[(int) HELP_CUR] = cursor_create(CURSOR_IMAGE, &help_cursor_pr, 0) ; X cursor[(int) HOUR_CUR] = cursor_create(CURSOR_IMAGE, &hour_cursor_pr, 0) ; X cursor[(int) MAIN_CUR] = cursor_create(CURSOR_IMAGE, &main_cursor_pr, 0) ; X X canvas = window_create(base_frame, CANVAS, X WIN_EVENT_PROC, canvas_proc, X WIN_CURSOR, cursor[(int) MAIN_CUR], X WIN_WIDTH, SCAN_WIDTH, X WIN_HEIGHT, SCAN_HEIGHT, X CANVAS_RETAINED, FALSE, X CANVAS_FIXED_IMAGE, FALSE, X 0) ; X WINDOW_SET(canvas, WIN_CONSUME_KBD_EVENTS, WIN_ASCII_EVENTS, X WIN_UP_EVENTS, 0, 0) ; X WINDOW_SET(canvas, WIN_CONSUME_PICK_EVENTS, LOC_DRAG, LOC_MOVE, 0, 0) ; X wpw = canvas_pixwin(canvas) ; X X show_canvas = window_create(show_frame, CANVAS, X CANVAS_REPAINT_PROC, repaint_show_canvas, X 0) ; X spw = canvas_pixwin(show_canvas) ; X spr = NULL ; X X images[(int) B_NORMAL] = &button_normal_pr ; X images[(int) B_INVERT] = &button_invert_pr ; X images[(int) S_NORMAL] = &switch_normal_pr ; X images[(int) S_INVERT] = &switch_invert_pr ; X images[(int) EXCLAIM_IMAGE] = &exclaim_pr ; } X Pixfont * open_font(fontname) char *fontname ; { X Pixfont *f ; X X if ((f = pf_open(fontname)) == NULL) X if ((f = pf_default()) == NULL) X { X perror("couldn't get the default font.") ; X exit(1) ; X } X return(f) ; } X /*ARGSUSED*/ void repaint_show_canvas(canvas, pw, repaint_area) /* Show current picture. */ Canvas canvas ; Pixwin *pw ; Rectlist *repaint_area ; { X PW_ROP(pw, 0, 0, hdr.ras_width, hdr.ras_height, PIX_SRC, spr, 0, 0) ; } X set_cursor(ctype) enum cur_type ctype ; { X WINDOW_SET(canvas, WIN_CURSOR, cursor[(int) ctype], 0) ; } X show() /* Display scanned image. */ { X Rect *temprect ; X char errmes[MAXLINE] ; X int fd ; X X showing = 1 ; X make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+100, "Show", B_INVERT) ; X if (spr) PR_DESTROY(spr) ; X if ((fd = open(picname, O_RDONLY | O_NDELAY, 0644)) == -1) X { X SPRINTF(errmes, "Cannot open %s.", picname) ; X make_display(errmes) ; X } X else X { X READ(fd, (char *) &hdr, sizeof(struct rasterfile)) ; X if (hdr.ras_maplength) X { X make_display("Color rasterfiles currently not supported.") ; X return ; X } X spr = mem_create(hdr.ras_width, hdr.ras_height, hdr.ras_depth) ; X READ(fd, (char *) (mpr_d(spr)->md_image), X hdr.ras_width * hdr.ras_height) ; X CLOSE(fd) ; X temprect = (Rect *) LINT_CAST(window_get(show_frame, FRAME_OPEN_RECT)) ; X temprect->r_left = temprect->r_top = 0 ; X temprect->r_height = hdr.ras_height ; X temprect->r_width = hdr.ras_width ; X WINDOW_SET(show_frame, FRAME_OPEN_RECT, temprect, 0) ; X WINDOW_SET(show_frame, FRAME_LABEL, picname, 0) ; X WINDOW_SET(show_frame, WIN_SHOW, TRUE, 0) ; X } X make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+100, "Show", B_NORMAL) ; X showing = 0 ; } X start_tool() { X window_fit(base_frame) ; X NOTIFY_INTERPOSE_DESTROY_FUNC(base_frame, destroy) ; X window_main_loop(base_frame) ; } X /*ARGSUSED*/ Notify_value wait_child(frame, pid, status, rusage) Window frame ; int pid ; union wait *status ; struct rusage *rusage ; { X char output[MAXLINE] ; X int high, low ; X X if (WIFSTOPPED(*status)) return (NOTIFY_IGNORED) ; X X high = (status->w_status & 0xFF00) >> 8 ; X low = status->w_status & 0xFF ; X if (low) SPRINTF(output, "Scan: terminated with signal %1d", (low & 0x3F)) ; X else X { X switch (high) X { X case 0 : SPRINTF(output, "Scan: successful. %s saved", X picname) ; X break ; X case 1 : SPRINTF(output, "Scan: cannot open tty port %c", X switches[SERIAL_PORT] + 'A') ; X break ; X case 2 : SPRINTF(output, "Scan: cannot open temporary image file") ; X break ; X case 3 : SPRINTF(output, "Scan: cannot open raster header file") ; X break ; X case 4 : SPRINTF(output, "Scan: scanner not responding; aborting") ; X break ; X case 5 : SPRINTF(output, "Scan: invalid command line argument") ; X break ; X default : if (high >= 100 && high < 200) X SPRINTF(output, "Scan: scanner error %1d; aborting", X high - 100) ; X else X SPRINTF(output, "Scan: terminated with signal %1d", X high - 200) ; X } X } X make_display(output) ; X make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+20, "Scan", B_NORMAL) ; X make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+60, "Cancel", B_NORMAL) ; X scanning = 0 ; X return (NOTIFY_DONE) ; } X wait_on_child(pid) /* Wait on child scan process. */ int pid ; { X NOTIFY_SET_WAIT3_FUNC(base_frame, wait_child, pid) ; } SHAR_EOF echo 'File sunview.c is complete' && chmod 0644 sunview.c || echo 'restore of sunview.c failed' Wc_c="`wc -c < 'sunview.c'`" test 13894 -eq "$Wc_c" || echo 'sunview.c: original size 13894, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi # ============= switch.invert.cursor ============== if test -f 'switch.invert.cursor' -a X"$1" != X"-c"; then echo 'x - skipping switch.invert.cursor (File already exists)' rm -f _shar_wnt_.tmp else > _shar_wnt_.tmp echo 'x - extracting switch.invert.cursor (Text)' sed 's/^X//' << 'SHAR_EOF' > 'switch.invert.cursor' && /* Format_version=1, Width=16, Height=16, Depth=1, Valid_bits_per_item=16 X */ X 0x0000,0x0000,0x0000,0x0002,0x0007,0x000E,0xFFFC,0x8038, X 0x8070,0x80E0,0xB1E0,0xBBA0,0x9F20,0x8E20,0x8420,0xFFE0 SHAR_EOF chmod 0644 switch.invert.cursor || echo 'restore of switch.invert.cursor failed' Wc_c="`wc -c < 'switch.invert.cursor'`" test 193 -eq "$Wc_c" || echo 'switch.invert.cursor: original size 193, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi # ============= switch.normal.cursor ============== if test -f 'switch.normal.cursor' -a X"$1" != X"-c"; then echo 'x - skipping switch.normal.cursor (File already exists)' rm -f _shar_wnt_.tmp else > _shar_wnt_.tmp echo 'x - extracting switch.normal.cursor (Text)' sed 's/^X//' << 'SHAR_EOF' > 'switch.normal.cursor' && /* Format_version=1, Width=16, Height=16, Depth=1, Valid_bits_per_item=16 X */ X 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xFFE0,0x8020, X 0x8020,0x8020,0x8020,0x8020,0x8020,0x8020,0x8020,0xFFE0 SHAR_EOF chmod 0644 switch.normal.cursor || echo 'restore of switch.normal.cursor failed' Wc_c="`wc -c < 'switch.normal.cursor'`" test 193 -eq "$Wc_c" || echo 'switch.normal.cursor: original size 193, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi # ============= white.codes ============== if test -f 'white.codes' -a X"$1" != X"-c"; then echo 'x - skipping white.codes (File already exists)' rm -f _shar_wnt_.tmp else > _shar_wnt_.tmp echo 'x - extracting white.codes (Text)' sed 's/^X//' << 'SHAR_EOF' > 'white.codes' && X 0 00110101 X 1 000111 X 2 0111 X 3 1000 X 4 1011 X 5 1100 X 6 1110 X 7 1111 X 8 10011 X 9 10100 X 10 00111 X 11 01000 X 12 001000 X 13 000011 X 14 110100 X 15 110101 X 16 101010 X 17 101011 X 18 0100111 X 19 0001100 X 20 0001000 X 21 0010111 X 22 0000011 X 23 0000100 X 24 0101000 X 25 0101011 X 26 0010011 X 27 0100100 X 28 0011000 X 29 00000010 X 30 00000011 X 31 00011010 X 32 00011011 X 33 00010010 X 34 00010011 X 35 00010100 X 36 00010101 X 37 00010110 X 38 00010111 X 39 00101000 X 40 00101001 X 41 00101010 X 42 00101011 X 43 00101100 X 44 00101101 X 45 00000100 X 46 00000101 X 47 00001010 X 48 00001011 X 49 01010010 X 50 01010011 X 51 01010100 X 52 01010101 X 53 00100100 X 54 00100101 X 55 01011000 X 56 01011001 X 57 01011010 X 58 01011011 X 59 01001010 X 60 01001011 X 61 00110010 X 62 00110011 X 63 00110100 X 64 11011 X 128 10010 X 192 010111 X 256 0110111 X 320 00110110 X 384 00110111 X 448 01100100 X 512 01100101 X 576 01101000 X 640 01100111 X 704 011001100 X 768 011001101 X 832 011010010 X 896 011010011 X 960 011010100 X 1024 011010101 X 1088 011010110 X 1152 011010111 X 1216 011011000 X 1280 011011001 X 1344 011011010 X 1408 011011011 X 1472 010011000 X 1536 010011001 X 1600 010011010 X 1664 011000 X 1728 010011011 X 1792 00000001000 X 1856 00000001100 X 1920 00000001101 X 1984 000000010010 X 2048 000000010011 X 2112 000000010100 X 2176 000000010101 X 2240 000000010110 X 2304 000000010111 X 2368 000000011100 X 2432 000000011101 X 2496 000000011110 X -1 000000000001 SHAR_EOF chmod 0644 white.codes || echo 'restore of white.codes failed' Wc_c="`wc -c < 'white.codes'`" test 2080 -eq "$Wc_c" || echo 'white.codes: original size 2080, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi # ============= xview.c ============== if test -f 'xview.c' -a X"$1" != X"-c"; then echo 'x - skipping xview.c (File already exists)' rm -f _shar_wnt_.tmp else > _shar_wnt_.tmp echo 'x - extracting xview.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'xview.c' && X /* @(#)xview.c 1.5 90/04/10 X * X * XView dependent graphics routines used by scantool. X * X * Copyright (c) Rich Burridge. X * Sun Microsystems, Australia - All rights reserved. X * X * Permission is given to distribute these sources, as long as the X * copyright messages are not removed, and no monies are exchanged. X * X * No responsibility is taken for any errors or inaccuracies inherent X * either to the comments or the code of this program, but if X * reported to me, then an attempt will be made to fix them. X */ X #include #include #include #include #include #include "scantool.h" #include "scantool_extern.h" #include "images.h" #include #include #include #include " #include #include #include #include #define NOTIFY_INTERPOSE_DESTROY_FUNC (void) notify_interpose_destroy_func #define NOTIFY_SET_SIGNAL_FUNC (void) notify_set_signal_func #define NOTIFY_SET_WAIT3_FUNC (void) notify_set_wait3_func #define PR_DESTROY (void) pr_destroy #define PW_WRITE (void) pw_write #define XV_INPUT_READEVENT (void) xv_input_readevent #define XV_SET (void) xv_set X #define BOLDFONT "lucidasanstypewriter-bold-12" #define DEFFONT "fixed" #define NORMALFONT "lucidasanstypewriter-12" #define NULL 0 int menu_proc() ; void repaint_show_canvas() ; X Canvas canvas, show_canvas ; Canvas_paint_window spw, wpw ; Event *cur_event ; Frame base_frame, show_frame ; Fullscreen fs ; Icon scantool_icon ; Menu menus[MAXMENUS] ; Notify_value destroy() ; Pixrect *spr ; Server_image frame_cursor_pr, help_cursor_pr, hour_cursor_pr, main_cursor_pr ; Server_image make_server_image() ; X XXv_cursor cursor[MAXCURSORS] ; X Display *dpy ; /* Display id of scantool frame. */ Drawable xid ; /* Xid for scantool canvas. */ Drawable grey_pr ; Drawable images[MAXIMAGES] ; /* Xids for various graphical images. */ GC backgc ; /* Graphics context for pw_writebackground. */ GC gc ; /* Graphics context for text and lines. */ GC ropgc ; /* Graphics context for rops. */ Window root ; XXFontStruct *font[MAXFONTS] ; /* Xlib handles to the fonts. */ XXGCValues gc_val ; /* Used to setup graphics context values. */ int gc_flags ; /* Used to set up graphics context flags. */ int screen ; /* Default graphics display screen. */ unsigned long backgnd ; /* Default background color. */ unsigned long foregnd ; /* Default foreground color. */ unsigned long gc_mask ; /* Mask for setting graphic context values. */ X enum menu_type cur_menu ; /* Current menu type being processed. */ X int init_height ; /* Initial height of the scantool window. */ int init_width ; /* Initial width of the scantool window. */ int started ; /* Kludge to correct handle repaints. */ X struct rasterfile hdr ; X mpr_static(icon_pr, 64, 64, 1, icon_image) ; X /*ARGSUSED*/ void canvas_proc(canvas, event) Canvas canvas ; Event *event ; { X if (!started) return ; X cur_event = event ; X handle_event() ; /* Determine what kind of event it is. */ X process_event() ; /* And process it. */ } X create_menu(mtype, title, values) /* Create popup menus for cycle items. */ enum menu_type mtype ; char *title, *values[] ; { X int i = 0 ; X int more = 1 ; /* Cleared when current menu is complete.*/ X X menus[(int) mtype] = xv_create(XV_NULL, MENU_COMMAND_MENU, X MENU_NOTIFY_PROC, menu_proc, X MENU_TITLE_ITEM, title, X 0) ; X do X { X if (values[i] != NULL) X XV_SET(menus[(int) mtype], MENU_STRING_ITEM, values[i], i+1, 0) ; X else more = 0 ; X i++ ; X } X while (more) ; } X Notify_value destroy(client, status) Notify_client client ; Destroy_status status ; { X stop_scan() ; /* Stop the current scan (if there is one). */ X exit(0) ; } X display_menu(menuno) enum menu_type menuno ; { X cur_menu = menuno ; X menu_show(menus[(int) menuno], canvas, cur_event, 0) ; X return(0) ; } X draw_area(x, y, width, height, op) int x, y, width, height ; enum op_type op ; { X if (op == GNOT) X { X XSetFunction(dpy, gc, GXcopyInverted) ; X XCopyArea(dpy, xid, xid, gc, x, y, width, height, x, y) ; X } X else X { X XSetFunction(dpy, backgc, ops[(int) op]) ; X XFillRectangle(dpy, xid, backgc, x, y, width, height) ; X } } X draw_image(x, y, width, height, image) int x, y, width, height ; enum image_type image ; { X gc_mask = GCStipple | GCTileStipXOrigin | GCTileStipYOrigin ; X gc_val.stipple = images[(int) image] ; X gc_val.ts_x_origin = x ; X gc_val.ts_y_origin = y ; X XChangeGC(dpy, ropgc, gc_mask, &gc_val) ; X XFillRectangle(dpy, xid, ropgc, x, y, width, height) ; } X draw_line(x1, y1, x2, y2, op) int x1, y1, x2, y2 ; enum op_type op ; { X gc_val.foreground = foregnd ; X gc_val.function = ops[(int) op] ; X XChangeGC(dpy, gc, GCForeground | GCFunction, &gc_val) ; X XDrawLine(dpy, xid, gc, x1, y1, x2, y2) ; } X /*ARGSUSED*/ draw_text(x, y, stencil, ftype, str) int x, y ; enum sten_type stencil ; enum font_type ftype ; char *str ; { X gc_val.foreground = foregnd ; X gc_val.font = font[(int) ftype]->fid ; X if (stencil == STEN_INV) gc_val.function = GXcopyInverted ; X else gc_val.function = GXcopy ; X XChangeGC(dpy, gc, GCFont | GCForeground | GCFunction, &gc_val) ; X XDrawString(dpy, xid, gc, x, y, str, strlen(str)) ; } X get_event() /* Get the next XView event. */ { X XV_INPUT_READEVENT(wpw, cur_event, 1, 0, NULL) ; X if (event_is_button(cur_event)) X if (event_is_down(cur_event)) X fs = xv_create(wpw, FULLSCREEN, X WIN_CONSUME_EVENTS, X WIN_MOUSE_BUTTONS, LOC_DRAG, 0, X 0) ; X else if (event_is_up(cur_event)) xv_destroy(fs) ; } X XXFontStruct * get_font(name) char *name ; { X XFontStruct *f ; X X if (!(f = XLoadQueryFont(dpy, name))) X if (!(f = XLoadQueryFont(dpy, DEFFONT))) X { X FPRINTF(stderr, "%s: couldn't get the default font.", progname) ; X exit(1) ; X } X return(f) ; } X get_strwidth(ftype, str) /* Get width in pixels of string value. */ enum font_type ftype ; char *str ; { X return(XTextWidth(font[(int) ftype], str, strlen(str))) ; } X grey_area(x, y, width, height) { X gc_mask = GCStipple | GCTileStipXOrigin | GCTileStipYOrigin ; X gc_val.stipple = grey_pr ; X gc_val.ts_x_origin = x % 16 ; X gc_val.ts_y_origin = y % 16 ; X XChangeGC(dpy, ropgc, gc_mask, &gc_val) ; X XFillRectangle(dpy, xid, ropgc, x, y, width, height) ; } X handle_event() /* Work out what kind of event this is. */ { X curx = event_x(cur_event) ; X cury = event_y(cur_event) ; X cur_ch = event_id(cur_event) ; X X if (cur_ch == LOC_WINENTER) win_set_kbd_focus(canvas, xid) ; X else if (cur_ch == WIN_REPAINT) type = REPAINT ; X else if (cur_ch == LOC_MOVE) type = MOUSE_MOVE ; X else if (cur_ch == LOC_DRAG) type = MOUSE_DRAG ; X else if (event_is_button(cur_event) && event_is_down(cur_event)) X { X if (cur_ch == MS_LEFT) type = LEFT_DOWN ; X else if (cur_ch == MS_MIDDLE) type = MIDDLE_DOWN ; X else if (cur_ch == MS_RIGHT) type = RIGHT_DOWN ; X } X else if (event_is_button(cur_event) && event_is_up(cur_event)) X { X if (cur_ch == MS_LEFT) type = LEFT_UP ; X else if (cur_ch == MS_MIDDLE) type = MIDDLE_UP ; X else if (cur_ch == MS_RIGHT) type = RIGHT_UP ; X } X else if (event_is_ascii(cur_event) && X event_is_down(cur_event)) type = KEYBOARD ; X else type = IGNORE ; } X init_fonts() { X font[(int) NFONT] = get_font(NORMALFONT) ; X font_width = font[(int) NFONT]->max_bounds.rbearing - X font[(int) NFONT]->min_bounds.lbearing ; X font[(int) BFONT] = get_font(BOLDFONT) ; } X init_ws_type() { X ops[(int) GSET] = GXset ; X ops[(int) GCLR] = GXclear ; X ops[(int) GXOR] = GXxor ; X ops[(int) GSRC] = GXcopy ; X ops[(int) GOR] = GXor ; X ops[(int) GNOT] = GXcopyInverted ; X X started = 0 ; /* Kludge to correctly handle repaints. */ } X make_frames(argc, argv) int argc ; char *argv[] ; { X xv_init(XV_INIT_ARGS, argc, argv, 0) ; X scantool_icon = xv_create(XV_NULL, ICON, X ICON_IMAGE, &icon_pr, X 0) ; X base_frame = xv_create(XV_NULL, FRAME, X FRAME_ICON, scantool_icon, X FRAME_LABEL, progname, X FRAME_SHOW_RESIZE_CORNER, FALSE, X 0) ; X X show_frame = xv_create(base_frame, FRAME, X FRAME_SHOW_LABEL, TRUE, X XV_WIDTH, 650, X XV_HEIGHT, 900, X XV_X, 0, X XV_Y, 0, X XV_SHOW, FALSE, X 0) ; } X make_subframes() { X canvas = xv_create(base_frame, CANVAS, X CANVAS_RETAINED, FALSE, X OPENWIN_AUTO_CLEAR, FALSE, X XV_WIDTH, SCAN_WIDTH, X XV_HEIGHT, SCAN_HEIGHT, X CANVAS_PAINTWINDOW_ATTRS, X WIN_CONSUME_EVENTS, X MS_LEFT, MS_MIDDLE, MS_RIGHT, X WIN_ASCII_EVENTS, KBD_USE, KBD_DONE, X LOC_WINENTER, LOC_WINEXIT, LOC_DRAG, LOC_MOVE, X WIN_LEFT_KEYS, WIN_TOP_KEYS, WIN_RIGHT_KEYS, X WIN_REPAINT, X 0, X WIN_EVENT_PROC, canvas_proc, X 0, X 0) ; X wpw = canvas_paint_window(canvas) ; X X dpy = (Display *) xv_get(base_frame, XV_DISPLAY) ; X xid = (Drawable) xv_get(wpw, XV_XID) ; X X screen = DefaultScreen(dpy) ; X root = RootWindow(dpy, screen) ; X foregnd = BlackPixel(dpy, screen) ; X backgnd = WhitePixel(dpy, screen) ; X X gc_mask = GCForeground | GCBackground | GCGraphicsExposures ; X gc_val.foreground = foregnd ; X gc_val.background = backgnd ; X gc_val.graphics_exposures = False ; X gc = XCreateGC(dpy, root, gc_mask, &gc_val) ; X X backgc = XCreateGC(dpy, root, gc_mask, &gc_val) ; X XSetForeground(dpy, backgc, gc_val.background) ; X X ropgc = XCreateGC(dpy, root, gc_mask, &gc_val) ; X gc_val.function = GXcopy ; X gc_val.fill_style = FillOpaqueStippled ; X XChangeGC(dpy, ropgc, GCFunction | GCFillStyle, &gc_val) ; X X grey_pr = (Drawable) xv_get(make_server_image(grey_image, 16, 16), XV_XID) ; X frame_cursor_pr = make_server_image(frame_cursor_array, 16, 16) ; X help_cursor_pr = make_server_image(help_cursor_array, 16, 16) ; X hour_cursor_pr = make_server_image(hour_cursor_array, 16, 16) ; X main_cursor_pr = make_server_image(main_cursor_array, 16, 16) ; X images[(int) B_NORMAL] = (Drawable) X xv_get(make_server_image(button_normal_image, 64, 64), XV_XID) ; X images[(int) B_INVERT] = (Drawable) X xv_get(make_server_image(button_invert_image, 64, 64), XV_XID) ; X images[(int) S_NORMAL] = (Drawable) X xv_get(make_server_image(switch_normal_image, 16, 16), XV_XID) ; X images[(int) S_INVERT] = (Drawable) X xv_get(make_server_image(switch_invert_image, 16, 16), XV_XID) ; X images[(int) EXCLAIM_IMAGE] = (Drawable) X xv_get(make_server_image(exclaim_image, 64, 64), XV_XID) ; X X cursor[(int) FRAME_CUR] = xv_create(XV_NULL, CURSOR, X CURSOR_IMAGE, frame_cursor_pr, X CURSOR_XHOT, 7, X CURSOR_YHOT, 7, X 0) ; X cursor[(int) HELP_CUR] = xv_create(XV_NULL, CURSOR, X CURSOR_IMAGE, help_cursor_pr, X 0) ; X cursor[(int) HOUR_CUR] = xv_create(XV_NULL, CURSOR, X CURSOR_IMAGE, hour_cursor_pr, X 0) ; X cursor[(int) MAIN_CUR] = xv_create(XV_NULL, CURSOR, X CURSOR_IMAGE, main_cursor_pr, X 0) ; X X show_canvas = xv_create(show_frame, CANVAS, X CANVAS_REPAINT_PROC, repaint_show_canvas, X 0) ; X spw = canvas_paint_window(show_canvas) ; X spr = NULL ; X X XV_SET(canvas, WIN_CURSOR, cursor[(int) MAIN_CUR]) ; } X menu_proc(menu, menu_item) Menu menu ; Menu_item menu_item ; { X int choice ; X X choice = (int) menu_get(menu_item, MENU_VALUE) ; X if (choice) process_menu(cur_menu, choice) ; } X Server_image make_server_image(image, width, height) unsigned short image[] ; int width, height ; { X return(xv_create(XV_NULL, SERVER_IMAGE, X XV_WIDTH, width, X XV_HEIGHT, height, X SERVER_IMAGE_BITS, image, X 0)) ; } X /*ARGSUSED*/ void repaint_show_canvas(canvas, pw, repaint_area) /* Show current picture. */ Canvas canvas ; Pixwin *pw ; Rectlist *repaint_area ; { X PW_WRITE(pw, 0, 0, hdr.ras_width, hdr.ras_height, PIX_SRC, spr, 0, 0) ; } X set_cursor(ctype) enum cur_type ctype ; { X XV_SET(wpw, WIN_CURSOR, cursor[(int) ctype], 0) ; } X show() /* Display scanned image. */ { X Rect *temprect ; X char errmes[MAXLINE] ; X int fd ; X X showing = 1 ; X make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+100, "Show", B_INVERT) ; X if (spr) PR_DESTROY(spr) ; X if ((fd = open(picname, O_RDONLY | O_NDELAY, 0644)) == -1) X { X SPRINTF(errmes, "Cannot open %s.", picname) ; X make_display(errmes) ; X } X else X { X READ(fd, (char *) &hdr, sizeof(struct rasterfile)) ; X if (hdr.ras_maplength) X { X make_display("Color rasterfiles currently not supported.") ; X return ; X } X spr = mem_create(hdr.ras_width, hdr.ras_height, hdr.ras_depth) ; X READ(fd, (char *) (mpr_d(spr)->md_image), X hdr.ras_width * hdr.ras_height) ; X CLOSE(fd) ; X temprect = (Rect *) xv_get(show_frame, FRAME_OPEN_RECT) ; X temprect->r_left = temprect->r_top = 0 ; X temprect->r_height = hdr.ras_height ; X temprect->r_width = hdr.ras_width ; X XV_SET(show_frame, FRAME_OPEN_RECT, temprect, 0) ; X XV_SET(show_frame, FRAME_LABEL, picname, 0) ; X XV_SET(show_frame, XV_SHOW, TRUE, 0) ; X } X make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+100, "Show", B_NORMAL) ; X showing = 0 ; } X start_tool() { X window_fit(base_frame) ; X NOTIFY_INTERPOSE_DESTROY_FUNC(base_frame, destroy) ; X started = 1 ; X window_main_loop(base_frame) ; } X /*ARGSUSED*/ Notify_value wait_child(frame, pid, status, rusage) Window frame ; int pid ; union wait *status ; struct rusage *rusage ; { X char output[MAXLINE] ; X int high, low ; X X if (WIFSTOPPED(*status)) return (NOTIFY_IGNORED) ; X X high = (status->w_status & 0xFF00) >> 8 ; X low = status->w_status & 0xFF ; X if (low) SPRINTF(output, "Scan: terminated with signal %1d", (low & 0x3F)) ; X else X { X switch (high) X { X case 0 : SPRINTF(output, "Scan: successful. %s saved", X picname) ; X break ; X case 1 : SPRINTF(output, "Scan: cannot open tty port %c", X switches[SERIAL_PORT] + 'A') ; X break ; X case 2 : SPRINTF(output, "Scan: cannot open temporary image file") ; X break ; X case 3 : SPRINTF(output, "Scan: cannot open raster header file") ; X break ; X case 4 : SPRINTF(output, "Scan: scanner not responding; aborting") ; X break ; X case 5 : SPRINTF(output, "Scan: invalid command line argument") ; X break ; X default : if (high >= 100 && high < 200) X SPRINTF(output, "Scan: scanner error %1d; aborting", X high - 100) ; X else X SPRINTF(output, "Scan: terminated with signal %1d", X high - 200) ; X } X } X make_display(output) ; X make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+20, "Scan", B_NORMAL) ; X make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+60, "Cancel", B_NORMAL) ; X scanning = 0 ; X return (NOTIFY_DONE) ; } X wait_on_child(pid) /* Wait on child scan process. */ int pid ; { X NOTIFY_SET_WAIT3_FUNC(base_frame, wait_child, pid) ; } SHAR_EOF chmod 0644 xview.c || echo 'restore of xview.c failed' Wc_c="`wc -c < 'xview.c'`" test 16935 -eq "$Wc_c" || echo 'xview.c: original size 16935, current size' "$Wc_c" rm -f _shar_wnt_.tmp fi rm -f _shar_seq_.tmp echo You have unpacked the last part exit 0