home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3516 < prev    next >
Internet Message Format  |  1991-06-19  |  31KB

  1. From: gunnar@falcon.ericsson.se (Was a Sunny day)
  2. Newsgroups: alt.sources
  3. Subject: Scantool part 5(5)  (shar)
  4. Message-ID: <1991Jun18.125048.11369@ericsson.se>
  5. Date: 18 Jun 91 12:50:48 GMT
  6.  
  7. #!/bin/sh
  8. # this is scan.05 (part 5 of a multipart archive)
  9. # do not concatenate these parts, unpack them in order with /bin/sh
  10. # file sunview.c continued
  11. #
  12. if test ! -r _shar_seq_.tmp; then
  13.     echo 'Please unpack part 1 first!'
  14.     exit 1
  15. fi
  16. (read Scheck
  17.  if test "$Scheck" != 5; then
  18.     echo Please unpack part "$Scheck" next!
  19.     exit 1
  20.  else
  21.     exit 0
  22.  fi
  23. ) < _shar_seq_.tmp || exit 1
  24. if test ! -f _shar_wnt_.tmp; then
  25.     echo 'x - still skipping sunview.c'
  26. else
  27. echo 'x - continuing file sunview.c'
  28. sed 's/^X//' << 'SHAR_EOF' >> 'sunview.c' &&
  29. Frame frame ;
  30. Event *event ;
  31. Notify_arg arg ;
  32. Notify_event_type type ;
  33. {
  34. X  Notify_value value ;
  35. X  Rect *r ;
  36. X
  37. X  value = notify_next_event_func(frame, (Notify_event) event, arg, type) ;
  38. X  if (event_id(event) == WIN_RESIZE)
  39. X    if (firsttime)
  40. X      {
  41. X        init_width = (int) window_get(base_frame, WIN_WIDTH) ;
  42. X        init_height = (int) window_get(base_frame, WIN_HEIGHT) ;
  43. X        firsttime = 0 ;
  44. X      }
  45. X    else
  46. X      {
  47. X        r = (Rect *) LINT_CAST(window_get(frame, WIN_RECT)) ;
  48. X        r->r_width  = init_width ;
  49. X        r->r_height = init_height ;
  50. X        WINDOW_SET(frame, FRAME_OPEN_RECT, r, 0) ;
  51. X        do_repaint() ;
  52. X      }   
  53. X  return(value) ;
  54. }
  55. X
  56. init_fonts()
  57. {
  58. X  font[(int) NFONT] = open_font(NORMAL_FONT) ;
  59. X  font_width = font[(int) NFONT]->pf_defaultsize.x ;
  60. X  font[(int) BFONT] = open_font(BOLD_FONT) ;
  61. }
  62. X
  63. init_ws_type()
  64. {
  65. X  ops[(int) GSET] = PIX_SET ;
  66. X  ops[(int) GCLR] = PIX_CLR ;
  67. X  ops[(int) GXOR] = PIX_SRC ^ PIX_DST ;
  68. X  ops[(int) GSRC] = PIX_SRC ;
  69. X  ops[(int) GOR]  = PIX_SRC | PIX_DST ;
  70. X  ops[(int) GNOT] = PIX_NOT(PIX_DST) ;
  71. X
  72. X  firsttime = 1 ;
  73. }
  74. X
  75. make_frames(argc, argv)
  76. int argc ;
  77. char *argv[] ;
  78. {
  79. X  scantool_icon = icon_create(ICON_IMAGE, &icon_pr, 0) ;
  80. X  base_frame = window_create((Window) 0,           FRAME,
  81. X                             FRAME_ICON,           scantool_icon,
  82. X                             FRAME_LABEL,          " MICROTEK MSF-300A Image Scanner",
  83. X                             FRAME_EMBOLDEN_LABEL, TRUE,
  84. X                             FRAME_ARGS,           argc,argv,
  85. X                             0) ;
  86. X
  87. X  show_frame = window_create(base_frame,       FRAME,
  88. X                             FRAME_SHOW_LABEL, TRUE,
  89. X                             WIN_WIDTH,        650,
  90. X                             WIN_HEIGHT,       900,
  91. X                             WIN_X,            0,
  92. X                             WIN_Y,            0,
  93. X                             WIN_SHOW,         FALSE,
  94. X                             0) ;
  95. X  NOTIFY_INTERPOSE_EVENT_FUNC(base_frame, handle_resize, NOTIFY_SAFE) ;
  96. }
  97. X
  98. make_subframes()
  99. {
  100. X  cursor[(int) FRAME_CUR] = cursor_create(CURSOR_IMAGE, &frame_cursor_pr,
  101. X                                          CURSOR_XHOT,  7,
  102. X                                          CURSOR_YHOT,  7,
  103. X                                          0) ;
  104. X  cursor[(int) HELP_CUR]  = cursor_create(CURSOR_IMAGE, &help_cursor_pr, 0) ;
  105. X  cursor[(int) HOUR_CUR]  = cursor_create(CURSOR_IMAGE, &hour_cursor_pr, 0) ;
  106. X  cursor[(int) MAIN_CUR]  = cursor_create(CURSOR_IMAGE, &main_cursor_pr, 0) ;
  107. X  canvas = window_create(base_frame, CANVAS,
  108. X                         WIN_EVENT_PROC,      canvas_proc,
  109. X                         WIN_CURSOR,          cursor[(int) MAIN_CUR],
  110. X                         WIN_WIDTH,           SCAN_WIDTH,
  111. X                         WIN_HEIGHT,          SCAN_HEIGHT,
  112. X                         CANVAS_RETAINED,     FALSE,
  113. X                         CANVAS_FIXED_IMAGE,  FALSE,
  114. X                         0) ;
  115. X  WINDOW_SET(canvas, WIN_CONSUME_KBD_EVENTS, WIN_ASCII_EVENTS,
  116. X                     WIN_UP_EVENTS, 0, 0) ;
  117. X  WINDOW_SET(canvas, WIN_CONSUME_PICK_EVENTS, LOC_DRAG, LOC_MOVE, 0, 0) ;
  118. X  wpw = canvas_pixwin(canvas) ;
  119. X
  120. X  show_canvas = window_create(show_frame, CANVAS,
  121. X                              CANVAS_REPAINT_PROC, repaint_show_canvas,
  122. X                              0) ;
  123. X  spw = canvas_pixwin(show_canvas) ;
  124. X  spr = NULL ;
  125. X
  126. X  images[(int) B_NORMAL]      = &button_normal_pr ;
  127. X  images[(int) B_INVERT]      = &button_invert_pr ;
  128. X  images[(int) S_NORMAL]      = &switch_normal_pr ;
  129. X  images[(int) S_INVERT]      = &switch_invert_pr ;
  130. X  images[(int) EXCLAIM_IMAGE] = &exclaim_pr ;
  131. }
  132. X
  133. Pixfont *
  134. open_font(fontname)
  135. char *fontname ;
  136. {
  137. X  Pixfont *f ;
  138. X
  139. X  if ((f = pf_open(fontname)) == NULL)
  140. X    if ((f = pf_default()) == NULL)
  141. X      {
  142. X        perror("couldn't get the default font.") ;
  143. X        exit(1) ;
  144. X      }
  145. X  return(f) ;
  146. }
  147. X
  148. /*ARGSUSED*/
  149. void
  150. repaint_show_canvas(canvas, pw, repaint_area)     /* Show current picture. */
  151. Canvas canvas ;
  152. Pixwin *pw ;
  153. Rectlist *repaint_area ;
  154. {
  155. X  PW_ROP(pw, 0, 0, hdr.ras_width, hdr.ras_height, PIX_SRC, spr, 0, 0) ;
  156. }
  157. X
  158. set_cursor(ctype)
  159. enum cur_type ctype ;
  160. {
  161. X  WINDOW_SET(canvas, WIN_CURSOR, cursor[(int) ctype], 0) ;
  162. }
  163. X
  164. show()      /* Display scanned image. */
  165. {
  166. X  Rect *temprect ;
  167. X  char errmes[MAXLINE] ;
  168. X  int fd ;
  169. X
  170. X  showing = 1 ;
  171. X  make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+100, "Show", B_INVERT) ;
  172. X  if (spr) PR_DESTROY(spr) ;
  173. X  if ((fd = open(picname, O_RDONLY | O_NDELAY, 0644)) == -1)
  174. X    {
  175. X      SPRINTF(errmes, "Cannot open %s.", picname) ;
  176. X      make_display(errmes) ;
  177. X    }
  178. X  else
  179. X    { 
  180. X      READ(fd, (char *) &hdr, sizeof(struct rasterfile)) ;
  181. X      if (hdr.ras_maplength)
  182. X        {
  183. X          make_display("Color rasterfiles currently not supported.") ;
  184. X          return ;
  185. X        }
  186. X      spr = mem_create(hdr.ras_width, hdr.ras_height, hdr.ras_depth) ;
  187. X      READ(fd, (char *) (mpr_d(spr)->md_image),
  188. X           hdr.ras_width * hdr.ras_height) ;
  189. X      CLOSE(fd) ;
  190. X      temprect = (Rect *) LINT_CAST(window_get(show_frame, FRAME_OPEN_RECT)) ;
  191. X      temprect->r_left = temprect->r_top = 0 ;
  192. X      temprect->r_height = hdr.ras_height ;
  193. X      temprect->r_width = hdr.ras_width ;
  194. X      WINDOW_SET(show_frame, FRAME_OPEN_RECT, temprect, 0) ;
  195. X      WINDOW_SET(show_frame, FRAME_LABEL, picname, 0) ;
  196. X      WINDOW_SET(show_frame, WIN_SHOW, TRUE, 0) ;
  197. X    }
  198. X  make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+100, "Show", B_NORMAL) ;
  199. X  showing = 0 ;
  200. }
  201. X
  202. start_tool()
  203. {
  204. X  window_fit(base_frame) ;
  205. X  NOTIFY_INTERPOSE_DESTROY_FUNC(base_frame, destroy) ;
  206. X  window_main_loop(base_frame) ;
  207. }
  208. X
  209. /*ARGSUSED*/
  210. Notify_value
  211. wait_child(frame, pid, status, rusage)
  212. Window frame ;
  213. int pid ;
  214. union wait *status ;
  215. struct rusage *rusage ;
  216. {
  217. X  char output[MAXLINE] ;
  218. X  int high, low ;
  219. X
  220. X  if (WIFSTOPPED(*status)) return (NOTIFY_IGNORED) ;
  221. X
  222. X  high = (status->w_status & 0xFF00) >> 8 ;
  223. X  low = status->w_status & 0xFF ;
  224. X  if (low) SPRINTF(output, "Scan: terminated with signal %1d", (low & 0x3F)) ;
  225. X  else
  226. X    {
  227. X      switch (high)
  228. X        {
  229. X          case 0  : SPRINTF(output, "Scan: successful. %s saved",
  230. X                                     picname) ;
  231. X                    break ;
  232. X          case 1  : SPRINTF(output, "Scan: cannot open tty port %c",
  233. X                                     switches[SERIAL_PORT] + 'A') ;
  234. X                    break ;
  235. X          case 2  : SPRINTF(output, "Scan: cannot open temporary image file") ;
  236. X                    break ;
  237. X          case 3  : SPRINTF(output, "Scan: cannot open raster header file") ;
  238. X                    break ;
  239. X          case 4  : SPRINTF(output, "Scan: scanner not responding; aborting") ;
  240. X                    break ;
  241. X          case 5  : SPRINTF(output, "Scan: invalid command line argument") ;
  242. X                    break ;
  243. X          default : if (high >= 100 && high < 200)
  244. X                      SPRINTF(output, "Scan: scanner error %1d; aborting",
  245. X                                       high - 100) ;
  246. X                    else
  247. X                      SPRINTF(output, "Scan: terminated with signal %1d",
  248. X                                       high - 200) ;
  249. X        }
  250. X    }
  251. X  make_display(output) ;
  252. X  make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+20, "Scan",   B_NORMAL) ;
  253. X  make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+60, "Cancel", B_NORMAL) ;
  254. X  scanning = 0 ;
  255. X  return (NOTIFY_DONE) ;
  256. }
  257. X
  258. wait_on_child(pid)      /* Wait on child scan process. */
  259. int pid ;
  260. {
  261. X  NOTIFY_SET_WAIT3_FUNC(base_frame, wait_child, pid) ;
  262. }
  263. SHAR_EOF
  264. echo 'File sunview.c is complete' &&
  265. chmod 0644 sunview.c ||
  266. echo 'restore of sunview.c failed'
  267. Wc_c="`wc -c < 'sunview.c'`"
  268. test 13894 -eq "$Wc_c" ||
  269.     echo 'sunview.c: original size 13894, current size' "$Wc_c"
  270. rm -f _shar_wnt_.tmp
  271. fi
  272. # ============= switch.invert.cursor ==============
  273. if test -f 'switch.invert.cursor' -a X"$1" != X"-c"; then
  274.     echo 'x - skipping switch.invert.cursor (File already exists)'
  275.     rm -f _shar_wnt_.tmp
  276. else
  277. > _shar_wnt_.tmp
  278. echo 'x - extracting switch.invert.cursor (Text)'
  279. sed 's/^X//' << 'SHAR_EOF' > 'switch.invert.cursor' &&
  280. /* Format_version=1, Width=16, Height=16, Depth=1, Valid_bits_per_item=16
  281. X */
  282. X    0x0000,0x0000,0x0000,0x0002,0x0007,0x000E,0xFFFC,0x8038,
  283. X    0x8070,0x80E0,0xB1E0,0xBBA0,0x9F20,0x8E20,0x8420,0xFFE0
  284. SHAR_EOF
  285. chmod 0644 switch.invert.cursor ||
  286. echo 'restore of switch.invert.cursor failed'
  287. Wc_c="`wc -c < 'switch.invert.cursor'`"
  288. test 193 -eq "$Wc_c" ||
  289.     echo 'switch.invert.cursor: original size 193, current size' "$Wc_c"
  290. rm -f _shar_wnt_.tmp
  291. fi
  292. # ============= switch.normal.cursor ==============
  293. if test -f 'switch.normal.cursor' -a X"$1" != X"-c"; then
  294.     echo 'x - skipping switch.normal.cursor (File already exists)'
  295.     rm -f _shar_wnt_.tmp
  296. else
  297. > _shar_wnt_.tmp
  298. echo 'x - extracting switch.normal.cursor (Text)'
  299. sed 's/^X//' << 'SHAR_EOF' > 'switch.normal.cursor' &&
  300. /* Format_version=1, Width=16, Height=16, Depth=1, Valid_bits_per_item=16
  301. X */
  302. X    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0xFFE0,0x8020,
  303. X    0x8020,0x8020,0x8020,0x8020,0x8020,0x8020,0x8020,0xFFE0
  304. SHAR_EOF
  305. chmod 0644 switch.normal.cursor ||
  306. echo 'restore of switch.normal.cursor failed'
  307. Wc_c="`wc -c < 'switch.normal.cursor'`"
  308. test 193 -eq "$Wc_c" ||
  309.     echo 'switch.normal.cursor: original size 193, current size' "$Wc_c"
  310. rm -f _shar_wnt_.tmp
  311. fi
  312. # ============= white.codes ==============
  313. if test -f 'white.codes' -a X"$1" != X"-c"; then
  314.     echo 'x - skipping white.codes (File already exists)'
  315.     rm -f _shar_wnt_.tmp
  316. else
  317. > _shar_wnt_.tmp
  318. echo 'x - extracting white.codes (Text)'
  319. sed 's/^X//' << 'SHAR_EOF' > 'white.codes' &&
  320. X    0      00110101
  321. X    1        000111
  322. X    2          0111
  323. X    3          1000
  324. X    4          1011
  325. X    5          1100
  326. X    6          1110
  327. X    7          1111
  328. X    8         10011
  329. X    9         10100
  330. X   10         00111
  331. X   11         01000
  332. X   12        001000
  333. X   13        000011
  334. X   14        110100
  335. X   15        110101
  336. X   16        101010
  337. X   17        101011
  338. X   18       0100111
  339. X   19       0001100
  340. X   20       0001000
  341. X   21       0010111
  342. X   22       0000011
  343. X   23       0000100
  344. X   24       0101000
  345. X   25       0101011
  346. X   26       0010011
  347. X   27       0100100
  348. X   28       0011000
  349. X   29      00000010
  350. X   30      00000011
  351. X   31      00011010
  352. X   32      00011011
  353. X   33      00010010
  354. X   34      00010011
  355. X   35      00010100
  356. X   36      00010101
  357. X   37      00010110
  358. X   38      00010111
  359. X   39      00101000
  360. X   40      00101001
  361. X   41      00101010
  362. X   42      00101011
  363. X   43      00101100
  364. X   44      00101101
  365. X   45      00000100
  366. X   46      00000101
  367. X   47      00001010
  368. X   48      00001011
  369. X   49      01010010
  370. X   50      01010011
  371. X   51      01010100
  372. X   52      01010101
  373. X   53      00100100
  374. X   54      00100101
  375. X   55      01011000
  376. X   56      01011001
  377. X   57      01011010
  378. X   58      01011011
  379. X   59      01001010
  380. X   60      01001011
  381. X   61      00110010
  382. X   62      00110011
  383. X   63      00110100
  384. X   64         11011
  385. X  128         10010
  386. X  192        010111
  387. X  256       0110111
  388. X  320      00110110
  389. X  384      00110111
  390. X  448      01100100
  391. X  512      01100101
  392. X  576      01101000
  393. X  640      01100111
  394. X  704     011001100
  395. X  768     011001101
  396. X  832     011010010
  397. X  896     011010011
  398. X  960     011010100
  399. X 1024     011010101
  400. X 1088     011010110
  401. X 1152     011010111
  402. X 1216     011011000
  403. X 1280     011011001
  404. X 1344     011011010
  405. X 1408     011011011
  406. X 1472     010011000
  407. X 1536     010011001
  408. X 1600     010011010
  409. X 1664        011000
  410. X 1728     010011011
  411. X 1792   00000001000
  412. X 1856   00000001100
  413. X 1920   00000001101
  414. X 1984  000000010010
  415. X 2048  000000010011
  416. X 2112  000000010100
  417. X 2176  000000010101
  418. X 2240  000000010110
  419. X 2304  000000010111
  420. X 2368  000000011100
  421. X 2432  000000011101
  422. X 2496  000000011110
  423. X   -1  000000000001
  424. SHAR_EOF
  425. chmod 0644 white.codes ||
  426. echo 'restore of white.codes failed'
  427. Wc_c="`wc -c < 'white.codes'`"
  428. test 2080 -eq "$Wc_c" ||
  429.     echo 'white.codes: original size 2080, current size' "$Wc_c"
  430. rm -f _shar_wnt_.tmp
  431. fi
  432. # ============= xview.c ==============
  433. if test -f 'xview.c' -a X"$1" != X"-c"; then
  434.     echo 'x - skipping xview.c (File already exists)'
  435.     rm -f _shar_wnt_.tmp
  436. else
  437. > _shar_wnt_.tmp
  438. echo 'x - extracting xview.c (Text)'
  439. sed 's/^X//' << 'SHAR_EOF' > 'xview.c' &&
  440. X
  441. /*  @(#)xview.c 1.5 90/04/10
  442. X *
  443. X *  XView dependent graphics routines used by scantool.
  444. X *
  445. X *  Copyright (c) Rich Burridge.
  446. X *                Sun Microsystems, Australia - All rights reserved.
  447. X *
  448. X *  Permission is given to distribute these sources, as long as the
  449. X *  copyright messages are not removed, and no monies are exchanged.
  450. X *
  451. X *  No responsibility is taken for any errors or inaccuracies inherent
  452. X *  either to the comments or the code of this program, but if
  453. X *  reported to me, then an attempt will be made to fix them.
  454. X */
  455. X
  456. #include <stdio.h>
  457. #include <sys/fcntl.h>
  458. #include <sys/wait.h>
  459. #include <sys/time.h>
  460. #include <sys/resource.h>
  461. #include "scantool.h"
  462. #include "scantool_extern.h"
  463. #include "images.h"
  464. #include <rasterfile.h>
  465. #include <xview/xview.h>
  466. #include <xview/canvas.h>
  467. #include <xview/font.h>"
  468. #include <xview/fullscreen.h>
  469. #include <xview/cursor.h>
  470. #include <xview/svrimage.h>
  471. #include <X11/Xlib.h>
  472. #define  NOTIFY_INTERPOSE_DESTROY_FUNC  (void) notify_interpose_destroy_func
  473. #define  NOTIFY_SET_SIGNAL_FUNC         (void) notify_set_signal_func
  474. #define  NOTIFY_SET_WAIT3_FUNC          (void) notify_set_wait3_func
  475. #define  PR_DESTROY                     (void) pr_destroy
  476. #define  PW_WRITE                       (void) pw_write
  477. #define  XV_INPUT_READEVENT             (void) xv_input_readevent
  478. #define  XV_SET                         (void) xv_set
  479. X
  480. #define  BOLDFONT    "lucidasanstypewriter-bold-12"
  481. #define  DEFFONT     "fixed"
  482. #define  NORMALFONT  "lucidasanstypewriter-12"
  483. #define NULL 0
  484. int menu_proc() ;
  485. void repaint_show_canvas() ;
  486. X
  487. Canvas canvas, show_canvas ;
  488. Canvas_paint_window spw, wpw ;
  489. Event *cur_event ;
  490. Frame base_frame, show_frame ;
  491. Fullscreen fs ;
  492. Icon scantool_icon ;
  493. Menu menus[MAXMENUS] ;
  494. Notify_value destroy() ;
  495. Pixrect *spr ;
  496. Server_image frame_cursor_pr, help_cursor_pr, hour_cursor_pr, main_cursor_pr ;
  497. Server_image make_server_image() ;
  498. X
  499. XXv_cursor cursor[MAXCURSORS] ;
  500. X
  501. Display *dpy ;                  /* Display id of scantool frame. */
  502. Drawable xid ;                  /* Xid for scantool canvas. */
  503. Drawable grey_pr ;
  504. Drawable images[MAXIMAGES] ;    /* Xids for various graphical images. */
  505. GC backgc ;                     /* Graphics context for pw_writebackground. */
  506. GC gc ;                         /* Graphics context for text and lines. */
  507. GC ropgc ;                      /* Graphics context for rops. */
  508. Window root ;
  509. XXFontStruct *font[MAXFONTS] ;   /* Xlib handles to the fonts. */
  510. XXGCValues gc_val ;              /* Used to setup graphics context values. */
  511. int gc_flags ;                  /* Used to set up graphics context flags. */
  512. int screen ;                    /* Default graphics display screen. */
  513. unsigned long backgnd ;         /* Default background color. */
  514. unsigned long foregnd ;         /* Default foreground color. */
  515. unsigned long gc_mask ;         /* Mask for setting graphic context values. */
  516. X
  517. enum menu_type cur_menu ;     /* Current menu type being processed. */
  518. X
  519. int init_height ;             /* Initial height of the scantool window. */
  520. int init_width ;              /* Initial width of the scantool window. */
  521. int started ;                 /* Kludge to correct handle repaints. */
  522. X
  523. struct rasterfile hdr ;
  524. X
  525. mpr_static(icon_pr, 64, 64, 1, icon_image) ;
  526. X
  527. /*ARGSUSED*/
  528. void
  529. canvas_proc(canvas, event)
  530. Canvas canvas ;
  531. Event *event ;
  532. {
  533. X  if (!started) return ;
  534. X  cur_event = event ;
  535. X  handle_event() ;       /* Determine what kind of event it is. */
  536. X  process_event() ;      /* And process it. */
  537. }
  538. X
  539. create_menu(mtype, title, values)    /* Create popup menus for cycle items. */
  540. enum menu_type mtype ;
  541. char *title, *values[] ;
  542. {
  543. X  int i = 0 ;
  544. X  int more = 1 ;   /* Cleared when current menu is complete.*/
  545. X
  546. X  menus[(int) mtype] = xv_create(XV_NULL,          MENU_COMMAND_MENU,
  547. X                                 MENU_NOTIFY_PROC, menu_proc,
  548. X                                 MENU_TITLE_ITEM,  title,
  549. X                                 0) ;
  550. X  do
  551. X    {
  552. X      if (values[i] != NULL)
  553. X        XV_SET(menus[(int) mtype], MENU_STRING_ITEM, values[i], i+1, 0) ;
  554. X      else more = 0 ;
  555. X      i++ ;
  556. X    }
  557. X  while (more) ;
  558. }
  559. X
  560. Notify_value
  561. destroy(client, status)
  562. Notify_client client ;
  563. Destroy_status status ;
  564. {
  565. X  stop_scan() ;        /* Stop the current scan (if there is one). */
  566. X  exit(0) ;
  567. }
  568. X
  569. display_menu(menuno)
  570. enum menu_type menuno ;
  571. {
  572. X  cur_menu = menuno ;
  573. X  menu_show(menus[(int) menuno], canvas, cur_event, 0) ;
  574. X  return(0) ;
  575. }
  576. X
  577. draw_area(x, y, width, height, op)
  578. int x, y, width, height ;
  579. enum op_type op ;
  580. {
  581. X  if (op == GNOT)
  582. X    {
  583. X      XSetFunction(dpy, gc, GXcopyInverted) ;
  584. X      XCopyArea(dpy, xid, xid, gc, x, y, width, height, x, y) ;
  585. X    }
  586. X  else
  587. X    {
  588. X      XSetFunction(dpy, backgc, ops[(int) op]) ;
  589. X      XFillRectangle(dpy, xid, backgc, x, y, width, height) ;
  590. X    }
  591. }
  592. X
  593. draw_image(x, y, width, height, image)
  594. int x, y, width, height ;
  595. enum image_type image ;
  596. {
  597. X  gc_mask = GCStipple | GCTileStipXOrigin | GCTileStipYOrigin ;
  598. X  gc_val.stipple = images[(int) image] ;
  599. X  gc_val.ts_x_origin = x ;
  600. X  gc_val.ts_y_origin = y ;
  601. X  XChangeGC(dpy, ropgc, gc_mask, &gc_val) ;
  602. X  XFillRectangle(dpy, xid, ropgc, x, y, width, height) ;
  603. }
  604. X
  605. draw_line(x1, y1, x2, y2, op)
  606. int x1, y1, x2, y2 ;
  607. enum op_type op ;
  608. {
  609. X  gc_val.foreground = foregnd ;
  610. X  gc_val.function = ops[(int) op] ;
  611. X  XChangeGC(dpy, gc, GCForeground | GCFunction, &gc_val) ;
  612. X  XDrawLine(dpy, xid, gc, x1, y1, x2, y2) ;
  613. }
  614. X
  615. /*ARGSUSED*/
  616. draw_text(x, y, stencil, ftype, str)
  617. int x, y ;
  618. enum sten_type stencil ;
  619. enum font_type ftype ;
  620. char *str ;
  621. {
  622. X  gc_val.foreground = foregnd ;
  623. X  gc_val.font = font[(int) ftype]->fid ;
  624. X  if (stencil == STEN_INV) gc_val.function = GXcopyInverted ;
  625. X  else                     gc_val.function = GXcopy ;
  626. X  XChangeGC(dpy, gc, GCFont | GCForeground | GCFunction, &gc_val) ;
  627. X  XDrawString(dpy, xid, gc, x, y, str, strlen(str)) ;
  628. }
  629. X
  630. get_event()       /* Get the next XView event. */
  631. {
  632. X  XV_INPUT_READEVENT(wpw, cur_event, 1, 0, NULL) ;
  633. X  if (event_is_button(cur_event))
  634. X    if (event_is_down(cur_event))
  635. X      fs = xv_create(wpw, FULLSCREEN,
  636. X                     WIN_CONSUME_EVENTS,
  637. X                       WIN_MOUSE_BUTTONS, LOC_DRAG, 0,
  638. X                     0) ;
  639. X    else if (event_is_up(cur_event)) xv_destroy(fs) ;
  640. }
  641. X
  642. XXFontStruct *
  643. get_font(name)
  644. char *name ;
  645. {
  646. X  XFontStruct *f ;
  647. X  if (!(f = XLoadQueryFont(dpy, name)))
  648. X    if (!(f = XLoadQueryFont(dpy, DEFFONT)))
  649. X      {
  650. X        FPRINTF(stderr, "%s: couldn't get the default font.", progname) ;
  651. X        exit(1) ;
  652. X      }
  653. X  return(f) ;
  654. }
  655. X
  656. get_strwidth(ftype, str)    /* Get width in pixels of string value. */
  657. enum font_type ftype ;
  658. char *str ;
  659. {
  660. X  return(XTextWidth(font[(int) ftype], str, strlen(str))) ;
  661. }
  662. X
  663. grey_area(x, y, width, height)
  664. {
  665. X  gc_mask = GCStipple | GCTileStipXOrigin | GCTileStipYOrigin ;
  666. X  gc_val.stipple = grey_pr ;
  667. X  gc_val.ts_x_origin = x % 16 ;
  668. X  gc_val.ts_y_origin = y % 16 ;
  669. X  XChangeGC(dpy, ropgc, gc_mask, &gc_val) ;
  670. X  XFillRectangle(dpy, xid, ropgc, x, y, width, height) ;
  671. }
  672. X
  673. handle_event()        /* Work out what kind of event this is. */
  674. {
  675. X  curx = event_x(cur_event) ;
  676. X  cury = event_y(cur_event) ;
  677. X  cur_ch = event_id(cur_event) ;
  678. X
  679. X       if (cur_ch == LOC_WINENTER)   win_set_kbd_focus(canvas, xid) ;
  680. X  else if (cur_ch == WIN_REPAINT)    type = REPAINT ;
  681. X  else if (cur_ch == LOC_MOVE)       type = MOUSE_MOVE ;
  682. X  else if (cur_ch == LOC_DRAG)       type = MOUSE_DRAG ;
  683. X  else if (event_is_button(cur_event) && event_is_down(cur_event))
  684. X    {
  685. X           if (cur_ch == MS_LEFT)    type = LEFT_DOWN ;
  686. X      else if (cur_ch == MS_MIDDLE)  type = MIDDLE_DOWN ;
  687. X      else if (cur_ch == MS_RIGHT)   type = RIGHT_DOWN ;
  688. X    }
  689. X  else if (event_is_button(cur_event) && event_is_up(cur_event))
  690. X    {
  691. X           if (cur_ch == MS_LEFT)    type = LEFT_UP ;
  692. X      else if (cur_ch == MS_MIDDLE)  type = MIDDLE_UP ;
  693. X      else if (cur_ch == MS_RIGHT)   type = RIGHT_UP ;
  694. X    }
  695. X  else if (event_is_ascii(cur_event) &&
  696. X           event_is_down(cur_event)) type = KEYBOARD ;
  697. X  else                               type = IGNORE ;
  698. }
  699. X
  700. init_fonts()
  701. {
  702. X  font[(int) NFONT] = get_font(NORMALFONT) ;
  703. X  font_width = font[(int) NFONT]->max_bounds.rbearing -
  704. X               font[(int) NFONT]->min_bounds.lbearing ;
  705. X  font[(int) BFONT] = get_font(BOLDFONT) ;
  706. }
  707. X
  708. init_ws_type()
  709. {
  710. X  ops[(int) GSET] = GXset ;
  711. X  ops[(int) GCLR] = GXclear ;
  712. X  ops[(int) GXOR] = GXxor ;
  713. X  ops[(int) GSRC] = GXcopy ;
  714. X  ops[(int) GOR]  = GXor ;
  715. X  ops[(int) GNOT] = GXcopyInverted ;
  716. X
  717. X  started = 0 ;      /* Kludge to correctly handle repaints. */
  718. }
  719. X
  720. make_frames(argc, argv)
  721. int argc ;
  722. char *argv[] ;
  723. {
  724. X  xv_init(XV_INIT_ARGS, argc, argv, 0) ;
  725. X  scantool_icon = xv_create(XV_NULL, ICON,
  726. X                            ICON_IMAGE, &icon_pr,
  727. X                            0) ;
  728. X  base_frame = xv_create(XV_NULL,                     FRAME,
  729. X                         FRAME_ICON,                  scantool_icon,
  730. X                         FRAME_LABEL,                 progname,
  731. X                         FRAME_SHOW_RESIZE_CORNER,    FALSE,
  732. X                         0) ;
  733. X
  734. X  show_frame = xv_create(base_frame, FRAME,
  735. X                         FRAME_SHOW_LABEL, TRUE,
  736. X                         XV_WIDTH,         650,
  737. X                         XV_HEIGHT,        900,
  738. X                         XV_X,             0,
  739. X                         XV_Y,             0,
  740. X                         XV_SHOW,          FALSE,
  741. X                         0) ;
  742. }
  743. X
  744. make_subframes()
  745. {
  746. X  canvas = xv_create(base_frame,         CANVAS,
  747. X                     CANVAS_RETAINED,    FALSE,
  748. X                     OPENWIN_AUTO_CLEAR, FALSE,
  749. X                     XV_WIDTH,           SCAN_WIDTH,
  750. X                     XV_HEIGHT,          SCAN_HEIGHT,
  751. X                     CANVAS_PAINTWINDOW_ATTRS,
  752. X                       WIN_CONSUME_EVENTS,
  753. X                         MS_LEFT, MS_MIDDLE, MS_RIGHT,
  754. X                         WIN_ASCII_EVENTS, KBD_USE, KBD_DONE,
  755. X                         LOC_WINENTER, LOC_WINEXIT, LOC_DRAG, LOC_MOVE,
  756. X                         WIN_LEFT_KEYS, WIN_TOP_KEYS, WIN_RIGHT_KEYS,
  757. X                         WIN_REPAINT,
  758. X                       0,
  759. X                       WIN_EVENT_PROC,   canvas_proc,
  760. X                       0,
  761. X                     0) ;
  762. X  wpw = canvas_paint_window(canvas) ;
  763. X  dpy = (Display *) xv_get(base_frame, XV_DISPLAY) ;
  764. X  xid = (Drawable) xv_get(wpw, XV_XID) ;
  765. X  screen = DefaultScreen(dpy) ;
  766. X  root = RootWindow(dpy, screen) ;
  767. X  foregnd = BlackPixel(dpy, screen) ;
  768. X  backgnd = WhitePixel(dpy, screen) ;
  769. X  gc_mask = GCForeground | GCBackground | GCGraphicsExposures ;
  770. X  gc_val.foreground = foregnd ;
  771. X  gc_val.background = backgnd ;
  772. X  gc_val.graphics_exposures = False ;
  773. X  gc = XCreateGC(dpy, root, gc_mask, &gc_val) ;
  774. X
  775. X  backgc = XCreateGC(dpy, root, gc_mask, &gc_val) ;
  776. X  XSetForeground(dpy, backgc, gc_val.background) ;
  777. X
  778. X  ropgc = XCreateGC(dpy, root, gc_mask, &gc_val) ;
  779. X  gc_val.function = GXcopy ;
  780. X  gc_val.fill_style = FillOpaqueStippled ;
  781. X  XChangeGC(dpy, ropgc, GCFunction | GCFillStyle, &gc_val) ;
  782. X
  783. X  grey_pr = (Drawable) xv_get(make_server_image(grey_image, 16, 16), XV_XID) ;
  784. X  frame_cursor_pr = make_server_image(frame_cursor_array, 16, 16) ;
  785. X  help_cursor_pr  = make_server_image(help_cursor_array,  16, 16) ;
  786. X  hour_cursor_pr  = make_server_image(hour_cursor_array,  16, 16) ;
  787. X  main_cursor_pr  = make_server_image(main_cursor_array,  16, 16) ;
  788. X  images[(int) B_NORMAL] = (Drawable)
  789. X               xv_get(make_server_image(button_normal_image, 64, 64), XV_XID) ;
  790. X  images[(int) B_INVERT] = (Drawable)
  791. X               xv_get(make_server_image(button_invert_image, 64, 64), XV_XID) ;
  792. X  images[(int) S_NORMAL] = (Drawable)
  793. X               xv_get(make_server_image(switch_normal_image, 16, 16), XV_XID) ;
  794. X  images[(int) S_INVERT] = (Drawable)
  795. X               xv_get(make_server_image(switch_invert_image, 16, 16), XV_XID) ;
  796. X  images[(int) EXCLAIM_IMAGE] = (Drawable)
  797. X               xv_get(make_server_image(exclaim_image, 64, 64), XV_XID) ;
  798. X
  799. X  cursor[(int) FRAME_CUR] = xv_create(XV_NULL,      CURSOR,
  800. X                                      CURSOR_IMAGE, frame_cursor_pr,
  801. X                                      CURSOR_XHOT,  7,
  802. X                                      CURSOR_YHOT,  7,
  803. X                                      0) ;
  804. X  cursor[(int) HELP_CUR] = xv_create(XV_NULL,      CURSOR,
  805. X                                     CURSOR_IMAGE, help_cursor_pr,
  806. X                                     0) ;
  807. X  cursor[(int) HOUR_CUR] = xv_create(XV_NULL,      CURSOR,
  808. X                                     CURSOR_IMAGE, hour_cursor_pr,
  809. X                                     0) ;
  810. X  cursor[(int) MAIN_CUR] = xv_create(XV_NULL,      CURSOR,
  811. X                                     CURSOR_IMAGE, main_cursor_pr,
  812. X                                     0) ;
  813. X
  814. X  show_canvas = xv_create(show_frame, CANVAS,
  815. X                          CANVAS_REPAINT_PROC, repaint_show_canvas,
  816. X                          0) ;
  817. X  spw = canvas_paint_window(show_canvas) ;
  818. X  spr = NULL ;
  819. X
  820. X  XV_SET(canvas, WIN_CURSOR, cursor[(int) MAIN_CUR]) ;
  821. }
  822. X
  823. menu_proc(menu, menu_item)
  824. Menu menu ;
  825. Menu_item menu_item ;
  826. {
  827. X  int choice ;
  828. X
  829. X  choice = (int) menu_get(menu_item, MENU_VALUE) ;
  830. X  if (choice) process_menu(cur_menu, choice) ;
  831. }
  832. X
  833. Server_image
  834. make_server_image(image, width, height)
  835. unsigned short image[] ;
  836. int width, height ;
  837. {
  838. X  return(xv_create(XV_NULL,           SERVER_IMAGE,
  839. X                   XV_WIDTH,          width,
  840. X                   XV_HEIGHT,         height,
  841. X                   SERVER_IMAGE_BITS, image,
  842. X                   0)) ;
  843. }
  844. X
  845. /*ARGSUSED*/
  846. void
  847. repaint_show_canvas(canvas, pw, repaint_area)     /* Show current picture. */
  848. Canvas canvas ;
  849. Pixwin *pw ;
  850. Rectlist *repaint_area ;
  851. {
  852. X  PW_WRITE(pw, 0, 0, hdr.ras_width, hdr.ras_height, PIX_SRC, spr, 0, 0) ;
  853. }
  854. X
  855. set_cursor(ctype)
  856. enum cur_type ctype ;
  857. {
  858. X  XV_SET(wpw, WIN_CURSOR, cursor[(int) ctype], 0) ;
  859. }
  860. X
  861. show()      /* Display scanned image. */
  862. {
  863. X  Rect *temprect ;
  864. X  char errmes[MAXLINE] ;
  865. X  int fd ;
  866. X
  867. X  showing = 1 ;
  868. X  make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+100, "Show", B_INVERT) ;
  869. X  if (spr) PR_DESTROY(spr) ;
  870. X  if ((fd = open(picname, O_RDONLY | O_NDELAY, 0644)) == -1)
  871. X    {
  872. X      SPRINTF(errmes, "Cannot open %s.", picname) ;
  873. X      make_display(errmes) ;
  874. X    }
  875. X  else
  876. X    { 
  877. X      READ(fd, (char *) &hdr, sizeof(struct rasterfile)) ;
  878. X      if (hdr.ras_maplength)
  879. X        {
  880. X          make_display("Color rasterfiles currently not supported.") ;
  881. X          return ;
  882. X        }
  883. X      spr = mem_create(hdr.ras_width, hdr.ras_height, hdr.ras_depth) ;
  884. X      READ(fd, (char *) (mpr_d(spr)->md_image),
  885. X           hdr.ras_width * hdr.ras_height) ;
  886. X      CLOSE(fd) ;
  887. X      temprect = (Rect *) xv_get(show_frame, FRAME_OPEN_RECT) ;
  888. X      temprect->r_left = temprect->r_top = 0 ;
  889. X      temprect->r_height = hdr.ras_height ;
  890. X      temprect->r_width = hdr.ras_width ;
  891. X      XV_SET(show_frame, FRAME_OPEN_RECT, temprect, 0) ;
  892. X      XV_SET(show_frame, FRAME_LABEL, picname, 0) ;
  893. X      XV_SET(show_frame, XV_SHOW, TRUE, 0) ;
  894. X    }
  895. X  make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+100, "Show", B_NORMAL) ;
  896. X  showing = 0 ;
  897. }
  898. X
  899. start_tool()
  900. {
  901. X  window_fit(base_frame) ;
  902. X  NOTIFY_INTERPOSE_DESTROY_FUNC(base_frame, destroy) ;
  903. X  started = 1 ;
  904. X  window_main_loop(base_frame) ;
  905. }
  906. X
  907. /*ARGSUSED*/
  908. Notify_value
  909. wait_child(frame, pid, status, rusage)
  910. Window frame ;
  911. int pid ;
  912. union wait *status ;
  913. struct rusage *rusage ;
  914. {
  915. X  char output[MAXLINE] ;
  916. X  int high, low ;
  917. X
  918. X  if (WIFSTOPPED(*status)) return (NOTIFY_IGNORED) ;
  919. X       
  920. X  high = (status->w_status & 0xFF00) >> 8 ;
  921. X  low = status->w_status & 0xFF ;
  922. X  if (low) SPRINTF(output, "Scan: terminated with signal %1d", (low & 0x3F)) ;
  923. X  else 
  924. X    {
  925. X      switch (high)
  926. X        {
  927. X          case 0  : SPRINTF(output, "Scan: successful. %s saved",
  928. X                                     picname) ;
  929. X                    break ;
  930. X          case 1  : SPRINTF(output, "Scan: cannot open tty port %c",
  931. X                                     switches[SERIAL_PORT] + 'A') ;
  932. X                    break ;
  933. X          case 2  : SPRINTF(output, "Scan: cannot open temporary image file") ;
  934. X                    break ;
  935. X          case 3  : SPRINTF(output, "Scan: cannot open raster header file") ;
  936. X                    break ;
  937. X          case 4  : SPRINTF(output, "Scan: scanner not responding; aborting") ;
  938. X                    break ;
  939. X          case 5  : SPRINTF(output, "Scan: invalid command line argument") ;
  940. X                    break ;
  941. X          default : if (high >= 100 && high < 200)
  942. X                      SPRINTF(output, "Scan: scanner error %1d; aborting",
  943. X                                       high - 100) ;
  944. X                    else
  945. X                      SPRINTF(output, "Scan: terminated with signal %1d",
  946. X                                       high - 200) ;
  947. X        }
  948. X    }    
  949. X  make_display(output) ;
  950. X  make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+20, "Scan",   B_NORMAL) ;
  951. X  make_button(SCAN_WIDTH-150, 4*SWITCH_HEIGHT+60, "Cancel", B_NORMAL) ;
  952. X  scanning = 0 ;
  953. X  return (NOTIFY_DONE) ;
  954. }
  955. X
  956. wait_on_child(pid)      /* Wait on child scan process. */
  957. int pid ;
  958. {
  959. X  NOTIFY_SET_WAIT3_FUNC(base_frame, wait_child, pid) ;
  960. }
  961. SHAR_EOF
  962. chmod 0644 xview.c ||
  963. echo 'restore of xview.c failed'
  964. Wc_c="`wc -c < 'xview.c'`"
  965. test 16935 -eq "$Wc_c" ||
  966.     echo 'xview.c: original size 16935, current size' "$Wc_c"
  967. rm -f _shar_wnt_.tmp
  968. fi
  969. rm -f _shar_seq_.tmp
  970. echo You have unpacked the last part
  971. exit 0
  972.