home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2972 < prev    next >
Internet Message Format  |  1991-03-04  |  56KB

  1. From: guido@cwi.nl (Guido van Rossum)
  2. Newsgroups: alt.sources
  3. Subject: STDWIN 0.9.5, Part 11/19
  4. Message-ID: <3075@charon.cwi.nl>
  5. Date: 4 Mar 91 11:58:09 GMT
  6.  
  7. Archive-name: stdwin/part11
  8.  
  9. #! /bin/sh
  10. # This is a shell archive.  Remove anything before this line, then unpack
  11. # it by saving it into a file and typing "sh file".  To overwrite existing
  12. # files, type "sh file -c".  You can also feed this as standard input via
  13. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  14. # will see the following message at the end:
  15. #        "End of archive 11 (of 19)."
  16. # Contents:  Appls/bed/mouse.c Doc/man/x11stdwin.man H/stdwin.h
  17. #   Packs/textedit/editwin.c Ports/mac/about.c Ports/mac/dialog.c
  18. #   Ports/x11/draw.c
  19. # Wrapped by guido@voorn.cwi.nl on Mon Mar  4 12:37:29 1991
  20. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  21. if test -f 'Appls/bed/mouse.c' -a "${1}" != "-c" ; then 
  22.   echo shar: Will not clobber existing file \"'Appls/bed/mouse.c'\"
  23. else
  24. echo shar: Extracting \"'Appls/bed/mouse.c'\" \(7752 characters\)
  25. sed "s/^X//" >'Appls/bed/mouse.c' <<'END_OF_FILE'
  26. X#include "bed.h"
  27. X#include "menu.h"
  28. X
  29. X#ifndef ABS
  30. X#define ABS(var)    ((var) >= 0 ? (var) : -(var))
  31. X#endif
  32. X
  33. Xextern int    sqrsize ;
  34. X
  35. Xextern int    map_width ;
  36. Xextern int    map_height ;
  37. X
  38. Xextern char    *raster ;
  39. Xextern int    raster_lenght ;
  40. Xextern int    stride ;
  41. X
  42. Xextern WINDOW    *win ;
  43. X
  44. Xextern bool    changed ;
  45. X
  46. Xextern int    state ;
  47. X
  48. Xbool    drawline = FALSE ;
  49. Xint    beg_h ;
  50. Xint    beg_v ;
  51. Xint    end_h ;
  52. Xint    end_v ;
  53. X
  54. Xbool    drawcircle = FALSE ;
  55. Xint    cent_h ;
  56. Xint    cent_v ;
  57. Xint    c_dh ;
  58. Xint    c_dv ;
  59. X
  60. Xbool    selrect = FALSE ;
  61. Xint    sr_left ;
  62. Xint    sr_top ;
  63. Xint    sr_right ;
  64. Xint    sr_bottom ;
  65. X
  66. Xvoid
  67. Xwxorrect (left, top, right, bottom)
  68. X    int    left ;
  69. X    int    top ;
  70. X    int    right ;
  71. X    int    bottom ;
  72. X{
  73. X    wxorline (left, top, right - 1, top) ;
  74. X    wxorline (right - 1, top, right -1, bottom - 1) ;
  75. X    wxorline (left, bottom - 1, right -1, bottom - 1) ;
  76. X    wxorline (left, top, left, bottom - 1) ;
  77. X
  78. X    if (right - left <= bottom - top) {
  79. X        wxorline (left, top, right - 1, top + (right - left) - 1) ;
  80. X        wxorline (right - 1, top, left, top + (right - left) - 1) ;
  81. X    }
  82. X    else {
  83. X        wxorline (left, top, left + (bottom - top) - 1, bottom - 1) ;
  84. X        wxorline (right - 1, top, right - (bottom - top) - 1, bottom -1) ;
  85. X    }
  86. X}
  87. X    
  88. Xvoid
  89. Xdrawselrect ()
  90. X{
  91. X    int    l = sr_left * sqrsize ;
  92. X    int    t = sr_top * sqrsize ;
  93. X    int    r = sr_right * sqrsize ;
  94. X    int    b = sr_bottom * sqrsize ;
  95. X
  96. X    wbegindrawing (win) ;
  97. X
  98. X    wxorrect (l, t, r, b) ;
  99. X
  100. X    wenddrawing (win) ;
  101. X}
  102. X
  103. Xint
  104. Xgetbit(col, row)
  105. X{
  106. X    char    *byte ;
  107. X    int    rc ;
  108. X
  109. X    if (row >= 0 && row < map_height && col >= 0 && col < map_width) {
  110. X        byte = raster + (row * stride) + (col / 8) ;
  111. X        rc = (*byte & (1 << (col % 8))) ? 1 : 0 ;
  112. X    }
  113. X    else
  114. X        rc = 0 ;
  115. X
  116. X    return (rc) ;
  117. X}
  118. X
  119. Xvoid
  120. Xsetbit(col, row, value)
  121. X{
  122. X    char    *byte ;
  123. X
  124. X    if (row >= 0 && row < map_height && col >= 0 && col < map_width) {
  125. X        changed = 1 ;
  126. X        byte = raster + (row * stride) + (col / 8) ;
  127. X        *byte = (*byte & ~(1 << (col %8))) | (value << (col % 8)) ;
  128. X        wchange (win, col * sqrsize, row * sqrsize,
  129. X            (col+1) * sqrsize, (row+1) * sqrsize);
  130. X    }
  131. X}
  132. X
  133. Xvoid
  134. Xdo_pencil (ep)
  135. X    EVENT    *ep ;
  136. X{
  137. X    static int    value ;
  138. X
  139. X    if (ep->type == WE_MOUSE_DOWN)
  140. X        value = !getbit (ep->u.where.h / sqrsize,
  141. X                 ep->u.where.v / sqrsize) ;
  142. X    setbit (ep->u.where.h / sqrsize,
  143. X        ep->u.where.v / sqrsize, value) ;
  144. X}
  145. X
  146. Xvoid
  147. Xinvertbit (h, v, value)
  148. X    int    h ;
  149. X    int    v ;
  150. X    bool    value ;
  151. X{
  152. X    if (h < 0 || v < 0 || h >= map_width || v >= map_height)
  153. X        return ;
  154. X
  155. X    winvert (h * sqrsize, v * sqrsize,
  156. X                    (h + 1) * sqrsize, (v + 1) * sqrsize) ;
  157. X}
  158. X
  159. Xvoid
  160. Xplotline (fp, value)
  161. X    void    (*fp) () ;
  162. X    bool    value ;
  163. X{
  164. X    int    d_h = end_h - beg_h ;
  165. X    int    d_v = end_v - beg_v ;
  166. X    int    e ;
  167. X    int    h = 0 ;
  168. X    int    v = 0 ;
  169. X    int    hsign = 1 ;
  170. X    int    vsign = 1 ;
  171. X    int    i ;
  172. X
  173. X    if (d_h < 0) {
  174. X        d_h = -d_h ;
  175. X        hsign = -1 ;
  176. X    }
  177. X
  178. X    if (d_v < 0) {
  179. X        d_v = -d_v ;
  180. X        vsign = -1 ;
  181. X    }
  182. X
  183. X    wbegindrawing (win) ;
  184. X
  185. X    if (d_v <= d_h) {
  186. X        for (i = 0, e = 2 * d_v - d_h ; i <= d_h ; ++i) {
  187. X            (*fp) (beg_h + (hsign * h), beg_v + (vsign * v), value) ;
  188. X
  189. X            if (e > 0) {
  190. X                ++v ;
  191. X                e -= (2 * d_h) ;
  192. X            }
  193. X
  194. X            e += (2 * d_v) ;
  195. X            ++h ;
  196. X        }
  197. X    }
  198. X    else {
  199. X        for (i = 0, e = 2 * d_h - d_v ; i <= d_v ; ++i) {
  200. X            (*fp) (beg_h + (hsign * h), beg_v + (vsign * v), value) ;
  201. X
  202. X            if (e > 0) {
  203. X                ++h ;
  204. X                e -= (2 * d_v) ;
  205. X            }
  206. X
  207. X            e += (2 * d_h) ;
  208. X            ++v ;
  209. X        }
  210. X    }
  211. X
  212. X    wenddrawing (win) ;
  213. X}
  214. X
  215. Xvoid
  216. Xplotcircle (fp, value)
  217. X    void    (*fp) () ;
  218. X    bool    value ;
  219. X{
  220. X    long    h_sqr = c_dh * c_dh ;
  221. X    long    v_sqr = c_dv * c_dv ;
  222. X    long    r_sqr = h_sqr * v_sqr ;
  223. X    long    prev_r = r_sqr ;
  224. X    long    min_h ;
  225. X    long    min_v ;
  226. X    long    min_hv ;
  227. X    int    h = c_dh ;
  228. X    int    v = 0 ;
  229. X
  230. X    wbegindrawing (win) ;
  231. X
  232. X    while (h >= 0 && v <= c_dv) {
  233. X        (*fp) (cent_h + h, cent_v + v, value) ;
  234. X        if (v)
  235. X            (*fp) (cent_h + h, cent_v - v, value) ;
  236. X        if (h)
  237. X            (*fp) (cent_h - h, cent_v + v, value) ;
  238. X        if (h && v)
  239. X            (*fp) (cent_h - h, cent_v - v, value) ;
  240. X
  241. X        min_h = (long) (2 * h - 1) * v_sqr ;
  242. X        min_v = (long) (2 * v + 1) * -h_sqr ;
  243. X        min_hv = min_h + min_v ;
  244. X
  245. X        if (ABS (r_sqr - (prev_r - min_h)) <=
  246. X                    ABS (r_sqr - (prev_r - min_v))) {
  247. X            if (ABS (r_sqr - (prev_r - min_hv)) <=
  248. X                    ABS (r_sqr - (prev_r - min_h))) {
  249. X                prev_r = prev_r - min_hv ;
  250. X                --h ;
  251. X                ++v ;
  252. X            }
  253. X            else {
  254. X                prev_r = prev_r - min_h ;
  255. X                --h ;
  256. X            }
  257. X        }
  258. X        else {
  259. X            if (ABS (r_sqr - (prev_r - min_hv)) <=
  260. X                    ABS (r_sqr - (prev_r - min_v))) {
  261. X                prev_r = prev_r - min_hv ;
  262. X                --h ;
  263. X                ++v ;
  264. X            }
  265. X            else {
  266. X                prev_r = prev_r - min_v ;
  267. X                ++v ;
  268. X            }
  269. X        }
  270. X    }
  271. X
  272. X    wenddrawing (win) ;
  273. X}
  274. X
  275. Xvoid
  276. Xdo_line (ep)
  277. X    EVENT    *ep ;
  278. X{
  279. X    int    curr_h = ep->u.where.h / sqrsize ;
  280. X    int    curr_v = ep->u.where.v / sqrsize ;
  281. X
  282. X    if (curr_h > map_height - 1)
  283. X        curr_h = map_height - 1 ;
  284. X    if (curr_v > map_width - 1)
  285. X        curr_v = map_width - 1 ;
  286. X
  287. X    switch (ep->type) {
  288. X    case WE_MOUSE_DOWN :
  289. X        if (drawline) {
  290. X            plotline (invertbit, FALSE) ;
  291. X            drawline = FALSE ;
  292. X        }
  293. X
  294. X        drawline = TRUE ;
  295. X
  296. X        beg_h = end_h = curr_h ;
  297. X        beg_v = end_v = curr_v ;
  298. X
  299. X        plotline (invertbit, TRUE) ;
  300. X        break ;
  301. X    case WE_MOUSE_MOVE :
  302. X        if (drawline) {
  303. X            if (curr_h == end_h && curr_v == end_v)
  304. X                return ;
  305. X
  306. X            plotline (invertbit, FALSE) ;
  307. X
  308. X            end_h = curr_h ;
  309. X            end_v = curr_v ;
  310. X
  311. X            plotline (invertbit, TRUE) ;
  312. X        }
  313. X        break ;
  314. X    case WE_MOUSE_UP :
  315. X        if (drawline) {
  316. X            if (curr_h != end_h || curr_v != end_v) {
  317. X                plotline (invertbit, FALSE) ;
  318. X
  319. X                end_h = curr_h ;
  320. X                end_v = curr_v ;
  321. X
  322. X                plotline (invertbit, TRUE) ;
  323. X            }
  324. X
  325. X            plotline (setbit, TRUE) ;
  326. X
  327. X            drawline = FALSE ;
  328. X        }
  329. X        break ;
  330. X    }
  331. X}
  332. X
  333. Xvoid
  334. Xdo_circle (ep)
  335. X    EVENT    *ep ;
  336. X{
  337. X    int    curr_h = ep->u.where.h / sqrsize ;
  338. X    int    curr_v = ep->u.where.v / sqrsize ;
  339. X
  340. X    if (curr_h > map_height - 1)
  341. X        curr_h = map_height - 1 ;
  342. X    if (curr_v > map_width - 1)
  343. X        curr_v = map_width - 1 ;
  344. X
  345. X    switch (ep->type) {
  346. X    case WE_MOUSE_DOWN :
  347. X        if (drawcircle) {
  348. X            plotcircle (invertbit, FALSE) ;
  349. X            drawcircle = FALSE ;
  350. X        }
  351. X
  352. X        drawcircle = TRUE ;
  353. X
  354. X        cent_h = curr_h ;
  355. X        cent_v = curr_v ;
  356. X        c_dh = c_dv = 0 ;
  357. X
  358. X        plotcircle (invertbit, TRUE) ;
  359. X        break ;
  360. X    case WE_MOUSE_MOVE :
  361. X        if (drawcircle) {
  362. X            if (ABS ((curr_h - cent_h) + 1) == c_dh &&
  363. X                    ABS ((curr_v - cent_v) + 1) == c_dv)
  364. X                return ;
  365. X
  366. X            plotcircle (invertbit, FALSE) ;
  367. X
  368. X            c_dh = ABS (curr_h - cent_h) ;
  369. X            c_dv = ABS (curr_v - cent_v) ;
  370. X
  371. X            plotcircle (invertbit, TRUE) ;
  372. X        }
  373. X        break ;
  374. X    case WE_MOUSE_UP :
  375. X        if (drawcircle) {
  376. X            if (ABS ((curr_h - cent_h) + 1) != c_dh ||
  377. X                    ABS ((curr_v - cent_v) + 1) != c_dv) {
  378. X                plotcircle (invertbit, FALSE) ;
  379. X
  380. X                c_dh = ABS (curr_h - cent_h) ;
  381. X                c_dv = ABS (curr_v - cent_v) ;
  382. X
  383. X                plotcircle (invertbit, TRUE) ;
  384. X            }
  385. X
  386. X            plotcircle (setbit, TRUE) ;
  387. X
  388. X            drawcircle = FALSE ;
  389. X        }
  390. X        break ;
  391. X    }
  392. X}
  393. X
  394. Xvoid
  395. Xdo_select (ep)
  396. X    EVENT    *ep ;
  397. X{
  398. X    static int    sr_h ;    /* coord. of mouse down */
  399. X    static int    sr_v ;
  400. X    int    curr_h = ep->u.where.h / sqrsize ;
  401. X    int    curr_v = ep->u.where.v / sqrsize ;
  402. X
  403. X    switch (ep->type) {
  404. X    case WE_MOUSE_DOWN :
  405. X        if (selrect) {
  406. X            drawselrect () ;
  407. X            selrect = FALSE ;
  408. X        }
  409. X
  410. X        if (curr_h >= map_width || curr_v >= map_height)
  411. X            return ;
  412. X
  413. X        selrect = TRUE ;
  414. X        sr_h = curr_h ;
  415. X        sr_v = curr_v ;
  416. X
  417. X        sr_left = curr_h ;
  418. X        sr_top = curr_v ;
  419. X        sr_right = sr_left + 1 ;
  420. X        sr_bottom = sr_top + 1 ;
  421. X
  422. X        drawselrect () ;
  423. X        break ;
  424. X    case WE_MOUSE_MOVE :
  425. X        if (selrect) {
  426. X            if (curr_h >= map_width)
  427. X                curr_h = map_width - 1 ;
  428. X            if (curr_v >= map_height)
  429. X                curr_v = map_height - 1 ;
  430. X
  431. X            if (curr_h < 0)
  432. X                curr_h = 0 ;
  433. X            if (curr_v < 0)
  434. X                curr_v = 0 ;
  435. X
  436. X            drawselrect () ;
  437. X
  438. X            if (curr_h < sr_h) {
  439. X                sr_left = curr_h ;
  440. X                sr_right = sr_h + 1 ;
  441. X            }
  442. X            else {
  443. X                sr_left = sr_h ;
  444. X                sr_right = curr_h + 1 ;
  445. X            }
  446. X
  447. X            if (curr_v < sr_v) {
  448. X                sr_top = curr_v ;
  449. X                sr_bottom = sr_v + 1 ;
  450. X            }
  451. X            else {
  452. X                sr_top = sr_v ;
  453. X                sr_bottom = curr_v + 1 ;
  454. X            }
  455. X
  456. X            drawselrect () ;
  457. X        }
  458. X        break ;
  459. X    case WE_MOUSE_UP :
  460. X            break ;
  461. X    }
  462. X}
  463. X
  464. Xvoid
  465. Xdo_mouse (ep)
  466. X    EVENT    *ep ;
  467. X{
  468. X    switch (state) {
  469. X    case PENCIL_ITEM :
  470. X        do_pencil (ep) ;
  471. X        break ;
  472. X    case LINE_ITEM :
  473. X        do_line (ep) ;
  474. X        break ;
  475. X    case CIRCLE_ITEM :
  476. X        do_circle (ep) ;
  477. X        break ;
  478. X    case SELECT_ITEM :
  479. X        do_select (ep) ;
  480. X        break ;    
  481. X    }
  482. X}
  483. END_OF_FILE
  484. if test 7752 -ne `wc -c <'Appls/bed/mouse.c'`; then
  485.     echo shar: \"'Appls/bed/mouse.c'\" unpacked with wrong size!
  486. fi
  487. # end of 'Appls/bed/mouse.c'
  488. fi
  489. if test -f 'Doc/man/x11stdwin.man' -a "${1}" != "-c" ; then 
  490.   echo shar: Will not clobber existing file \"'Doc/man/x11stdwin.man'\"
  491. else
  492. echo shar: Extracting \"'Doc/man/x11stdwin.man'\" \(8317 characters\)
  493. sed "s/^X//" >'Doc/man/x11stdwin.man' <<'END_OF_FILE'
  494. X.TH X11-STDWIN 1
  495. X.SH NAME
  496. XX11-STDWIN \- a Standard Window System Interface, X11 version
  497. X.SH SYNOPSIS
  498. X.I application
  499. X[
  500. X.B \-display
  501. X.I display-name
  502. X]
  503. X[
  504. X.B \-name
  505. X.I program-name
  506. X]
  507. X[
  508. X.B \-geometry
  509. X.I geometry-spec
  510. X]
  511. X [
  512. X.B \-font
  513. X.I font-name
  514. X]
  515. X[
  516. X.B \-menufont
  517. X.I font-name
  518. X]
  519. X[
  520. X.B \-iconic
  521. X]
  522. X[
  523. X.B \-icongeometry
  524. X.I geometry-spec
  525. X]
  526. X [
  527. X.B \-foreground
  528. X.I color-spec
  529. X]
  530. X[
  531. X.B \-background
  532. X.I color-spec
  533. X]
  534. X [
  535. X.B \-menuforeground
  536. X.I color-spec
  537. X]
  538. X[
  539. X.B \-menubackground
  540. X.I color-spec
  541. X]
  542. X [
  543. X.B \-reverse
  544. X]
  545. X[
  546. X.B \-xrm
  547. X.I string
  548. X]
  549. X[
  550. X.B \-debuglevel
  551. X.I number
  552. X]
  553. X[
  554. X.B \-synchronous
  555. X]
  556. X[
  557. X.I option
  558. X] ...
  559. X.SH DESCRIPTION
  560. X.I STDWIN
  561. Xis a standard interface available for several window systems.
  562. XThis man page describes the common aspects of applications written using
  563. XSTDWIN when run under MIT's X Window System, Version 11.
  564. X.SH COMMAND LINE OPTIONS
  565. XMost applications (to be precise, those that use the
  566. X.I winitnew
  567. Xcall to initialize STDWIN) will accept all options shown in the
  568. Xsynopsis.
  569. XFor most options there can also be a corresponding
  570. X.I resource
  571. X(option string stored in the X server or in ~/.Xdefaults).
  572. XCommand line options override resources; resources override defaults
  573. Xbuilt in the application; application defaults override library defaults.
  574. XUnless otherwise stated, the resources have the same name as the command
  575. Xline options (all in lower case), prefixed with ``.stdwin''.
  576. XFor example, the full name of the resource corresponding to the
  577. X``\-font'' option is named
  578. X.IR program .stdwin.font.
  579. XSince most options have a standard meaning for most X applications, they
  580. Xare not explained in great length here.
  581. XOptions with a specific meaning for STDWIN are:
  582. X.TP
  583. X.BI \-font " font-name"
  584. XSpecifies the font to be used by default in text drawn by the
  585. Xapplication.
  586. XBoth proportional and fixed-width fonts are acceptable
  587. X(except that some old applications look nicer with a fixed-width font).
  588. XThe library default is to use the X server's default (usually 8x13).
  589. X.TP
  590. X.BI \-menufont " font-name"
  591. XSpecifies the font to be used in menus and dialog boxes.
  592. XThe library default is to use the same font as for normal text.
  593. X.TP
  594. X.BI \-foreground " color-spec, " \-background " color-spec"
  595. XSpecify the colors to be used in the application's part of the window.
  596. XThe defaults are black and white.
  597. X.TP
  598. X.BI \-menuforeground " color-spec, " \-menubackground " color-spec"
  599. XSpecify the colors to be used in the menu bar, the scroll bars,
  600. Xdialog boxes and for the window border (the foreground color).
  601. XBy default the same values are used as for
  602. X.B \-foreground
  603. Xand
  604. X.BR \-background .
  605. X.TP
  606. X.B \-reverse
  607. XReverses the uses of foreground and background colors.
  608. X.TP
  609. X.BI \-debuglevel " number"
  610. XSpecifies the amount of debugging output you want; the higher the
  611. Xnumber, the more output you have to wade through.
  612. XThe library default is wisely 0.
  613. X.TP
  614. X.B \-synchronous
  615. XSpecifies that you want the connection with the X server to be
  616. Xmaintained in synchronous mode (each request immediately sent and a
  617. Xreply waited for).
  618. XThis is sometimes useful while debugging.
  619. XNote that synchronous mode can tremendously reduce drawing efficiency.
  620. XSynchronous mode is not set automatically when the debugging level is
  621. Xnonzero, since some bugs go away when it is turned on!
  622. XThis option has no corresponding resource.
  623. X.SH SCROLL BARS
  624. XAll STDWIN applications have two scroll bars (which may be inactive),
  625. Xone to the left of the window and one at the bottom.
  626. XOperation and interpretation of the scroll bars is intended to be
  627. Xidentical to the scroll bars of applications using the X toolkit
  628. X(e.g., xterm).
  629. XSummarizing:
  630. Xthe left button click scrolls forward, the amount varying with
  631. Xthe position of the click in the bar (for the vertical bar, remember
  632. X``line to top'');
  633. Xthe right button similarly scrolls back (``top to line'');
  634. Xthe middle button moves the beginning of the position indicator
  635. X(the gray block) to the position where the button is pressed.
  636. X.SH MENUS
  637. XAll STDWIN applications display one or more menu titles in a
  638. X``menu bar'' at the top of the window.
  639. XPressing and holding a mouse button in a menu title ``pulls down'' a
  640. Xmenu containing text items.
  641. XSliding the mouse cursor over the text items
  642. Xinverts (highlights) the item over which the cursor is currently;
  643. Xreleasing the mouse button when an item is highlighted causes the
  644. Xcorresponding command th be executed by the application.
  645. XReleasing the mouse button outside the menu selects no item.
  646. XSliding the mouse horizontally over the menu titles pulls down the other
  647. Xmenus; at most one menu will be visible at any time.
  648. X.PP
  649. XOne menu, labeled
  650. X.BR X ,
  651. Xis present in all windows.
  652. XIts only item, named
  653. X.BR Close ,
  654. Xis the standard way to close the window; for single-window applications,
  655. Xselecting this also quits the application.
  656. XThe application is free to refuse closing its window, or to ask
  657. Xconfirmation first, or to do whatever when this item is selected; it is
  658. Xmerely a hint that you would like the window to go away, not a request.
  659. X.PP
  660. XMenu items may be marked (``checked'') with a `*' in the left margin; this
  661. Xan indicator that the function selected by the menu item is currently
  662. X``active''.
  663. XThe check mark can be set and cleared by the application for each menu
  664. Xitem; the use should be apparent from the application's documentation.
  665. XMenu items may be inactive (``disabled''); such items cannot be selected
  666. Xand will not be highlighted.
  667. XDisabled items are currently indicated by a `\-' in the left margin.
  668. X.PP
  669. XMenu items may be selectable via a keyboard shortcut.
  670. XThe existence of a keyboard shortcut is shown in the menu item by the
  671. Xpresence of the string
  672. X.RI ``M- c ''
  673. Xin the right margin, where
  674. X.I c
  675. Xcan be any character.
  676. XThe M stands for ``Meta''.
  677. XHolding a ``Meta'' key (possibly labeled Alt, Command, Compose, Left or
  678. Xsome such name on your keyboard, but definitely not Control or Shift)
  679. Xwhile typing a character, usually a letter, will be
  680. Xequivalent to selecting the corresponding menu item with the mouse.
  681. XShortcuts are defined by the application.
  682. XSome shortcuts are conventional in many applications:
  683. XM-Q for Quit, M-S for Save, M-O for Open.
  684. XAlso M-Z for Undo, M-X for Cut, M-C for Copy and M-V for Paste
  685. X(reminiscent of the Macintosh commands).
  686. XUpper and lower case characters are equivalent, unless the application
  687. Xuses the same letter in lower and upper case as shortcuts for
  688. Xdifferent menu items.
  689. X.\"SH DIALOG BOXES
  690. X.\"SH TEXT EDITING
  691. X.\" selecting, button-2 selecting, double-click, cut/paste, delete, arrows.
  692. X.SH EXAMPLE
  693. XHere are some lines you could put in your resource input file:
  694. X
  695. X    *stdwin*font:courier12f
  696. X.br
  697. X    dpv*geometry:700x850
  698. X.br
  699. X    klok*geometry:-1+1
  700. X
  701. XThis sets the font for all STDWIN applications, the initial size for
  702. X.I dpv
  703. Xand the initial position for
  704. X.I klok.
  705. XNote the use of `*' for separators; extra levels of names may be
  706. Xinserted in the future.
  707. X.SH DIAGNOSTICS
  708. X.I STDWIN
  709. Xcan issue complaints about various error conditions, e.g., font not found;
  710. Xthese are intended to be self-explanatory.
  711. XSome messages indicate STDWIN has found an inconsistency in
  712. Xitself or in the X server.
  713. XThese should be reported to the author if the cause isn't obvious.
  714. X.\"SH FILES
  715. X.SH SEE ALSO
  716. XThe X documentation (especially the chapters on command line arguments
  717. Xand resources).
  718. X.br
  719. XSTDWIN \- A Standard Window System Interface, by Guido van Rossum
  720. X(CWI Report number CS-R8817, April 1988).
  721. X.SH AUTHOR
  722. XGuido van Rossum
  723. X.SH BUGS
  724. XI could be sued by Apple for stealing the ``look and feel'' of some
  725. Xaspects of the Macintosh. :-)
  726. X.br
  727. XThe
  728. X.B \-reverse
  729. Xoption doesn't affect the use of colors in dialog boxes.
  730. X.br
  731. XLike so many other window systems, X11 limits the size of windows to
  732. X64Kx64K.
  733. X.br
  734. XSince a STDWIN document is represented as an X11 window (scrolled inside
  735. Xanother X11 window), applications that create really big windows (~32K
  736. Xpixels wide or high) may crash due to a server bug.
  737. X.br
  738. XWhen an application does no window output for some time after a menu
  739. Xitem has been selected, the menu stays visible in its pulled-down state.
  740. X.br
  741. XThe conventional shortcuts for Undo, Cut and Paste aren't very mnemonic.
  742. X(But Apple never thought that was a problem.)
  743. X.br
  744. XThe standard X-STDWIN command line options are best given before all
  745. Xapplication-specific options.
  746. X.br
  747. XIf you are running an application in the background and have
  748. X.I "stty tostop"
  749. Xturned on, warnings or errors from STDWIN may cause the program to
  750. Xblock.
  751. END_OF_FILE
  752. if test 8317 -ne `wc -c <'Doc/man/x11stdwin.man'`; then
  753.     echo shar: \"'Doc/man/x11stdwin.man'\" unpacked with wrong size!
  754. fi
  755. # end of 'Doc/man/x11stdwin.man'
  756. fi
  757. if test -f 'H/stdwin.h' -a "${1}" != "-c" ; then 
  758.   echo shar: Will not clobber existing file \"'H/stdwin.h'\"
  759. else
  760. echo shar: Extracting \"'H/stdwin.h'\" \(8311 characters\)
  761. sed "s/^X//" >'H/stdwin.h' <<'END_OF_FILE'
  762. X/* STDWIN INTERFACE */
  763. X
  764. X#ifndef __STDWIN_H__    /* Guard against multiple inclusion */
  765. X#define __STDWIN_H__
  766. X
  767. X#include "_ARGS.h"    /* Definition of _ARGS() macro */
  768. X
  769. X
  770. X/***********************************/
  771. X/* Section 1.  Types and constants */
  772. X/***********************************/
  773. X
  774. X
  775. X/* These structs are implementation-dependent, the user only sees
  776. X   pointers to them */
  777. X
  778. X#define WINDOW struct _window
  779. X#define MENU struct _menu
  780. X#define CURSOR struct _cursor
  781. X
  782. X
  783. X/* Fake window type used by the wgettag() and wsettag() macros */
  784. X
  785. Xstruct _fakewindow {
  786. X    short tag;
  787. X};
  788. X
  789. X#define _FAKEWINDOW struct _fakewindow
  790. X
  791. X
  792. X/* EVENT struct */
  793. X
  794. Xstruct _event {
  795. X    int type;
  796. X    WINDOW *window;
  797. X    union {
  798. X    /* case WE_CHAR: */
  799. X        int character;
  800. X    /* case WE_COMMAND: */
  801. X        int command;
  802. X    /* case WE_MENU: */
  803. X        struct { int id; int item; } m;
  804. X    /* case WE_DRAW: */
  805. X        struct { int left, top, right, bottom; } area;
  806. X    /* case WE_MOUSE_DOWN, WE_MOUSE_MOVE, WE_MOUSE_UP: */
  807. X        struct {
  808. X            int h;
  809. X            int v;
  810. X            int clicks;
  811. X            int button;
  812. X            int mask;
  813. X        } where;
  814. X    /* case WE_LOST_SEL: */
  815. X        int sel;
  816. X    } u;
  817. X};
  818. X
  819. X#define EVENT struct _event
  820. X
  821. X
  822. X/* Event types */
  823. X/* XXX Should be reordered */
  824. X
  825. X#define WE_NULL        0    /* (Used internally) */
  826. X#define WE_ACTIVATE    1    /* Window became active */
  827. X#define WE_CHAR        2    /* Character typed at keyboard */
  828. X#define WE_COMMAND    3    /* Special command, function key etc. */
  829. X#define WE_MOUSE_DOWN    4    /* Mouse button pressed */
  830. X#define WE_MOUSE_MOVE    5    /* Mouse moved with button down */
  831. X#define WE_MOUSE_UP    6    /* Mouse button released */
  832. X#define WE_MENU        7    /* Menu item selected */
  833. X#define WE_SIZE        8    /* Window size changed */
  834. X#define WE_MOVE        9    /* Window moved (reserved) */
  835. X#define WE_DRAW        10    /* Request to redraw part of window */
  836. X#define WE_TIMER    11    /* Window's timer went off */
  837. X#define WE_DEACTIVATE    12    /* Window became inactive */
  838. X#define WE_EXTERN    13    /* Externally generated event (Amoeba) */
  839. X#define WE_KEY        14    /* Low-level key event (reserved) */
  840. X#define WE_LOST_SEL    15    /* Lost selection */
  841. X#define WE_CLOSE    16    /* User wants to close window */
  842. X
  843. X
  844. X/* Special keys reported by WE_COMMAND */
  845. X/* XXX Should become key events */
  846. X
  847. X#define WC_CLOSE    1    /* Now a separate event! */
  848. X/* The following four are arrow keys */
  849. X#define WC_LEFT        2
  850. X#define WC_RIGHT    3
  851. X#define WC_UP        4
  852. X#define WC_DOWN        5
  853. X/* ASCII keys */
  854. X#define WC_CANCEL    6
  855. X#define WC_BACKSPACE    7
  856. X#define WC_TAB        8
  857. X#define WC_RETURN    9
  858. X/* IBM-PC keys -- not in all implementations */
  859. X/* XXX Should be done differently */
  860. X#define WC_HOME        10
  861. X#define WC_END        11
  862. X#define WC_CLEAR    12
  863. X#define WC_INS        13
  864. X#define WC_DEL        14
  865. X#define WC_PAGE_UP    15
  866. X#define WC_PAGE_DOWN    16
  867. X#define WC_META_LEFT    17
  868. X#define WC_META_RIGHT    18
  869. X#define WC_META_HOME    19
  870. X#define WC_META_END    20
  871. X#define WC_META_PAGE_UP    21
  872. X#define WC_META_PAGE_DOWN    22
  873. X/* XXX Should have entries for Alt-letter and F1-F10 etc. ? */
  874. X
  875. X
  876. X/* Codes for selections (e.u.sel for WE_LOST_SEL) */
  877. X
  878. X#define WS_CLIPBOARD    0
  879. X#define WS_PRIMARY    1
  880. X#define WS_SECONDARY    2
  881. X
  882. X
  883. X/* TEXTATTR struct */
  884. X
  885. X/* The contents of a text attributes struct are disclosed here because
  886. X   the interface allows the programmer to declare objects of this type.
  887. X   (I'm not so sure anymore that this is the right thing to do!) */
  888. X
  889. Xstruct _textattr {
  890. X    short font;
  891. X    unsigned char size;
  892. X    unsigned char style;
  893. X};
  894. X
  895. X#define TEXTATTR struct _textattr
  896. X
  897. X
  898. X/*************************************/
  899. X/* Section 2.  Function declarations */
  900. X/*************************************/
  901. X
  902. X
  903. Xvoid wargs _ARGS((int *pargc, char ***pargv));
  904. Xvoid winit _ARGS((void));
  905. Xvoid winitargs _ARGS((int *pargc, char ***pargv));
  906. Xvoid wdone _ARGS((void));
  907. X
  908. Xvoid wgetscrsize _ARGS((int *pwidth, int *pheight));
  909. Xvoid wgetscrmm _ARGS((int *pmmwidth, int *pmmheight));
  910. X
  911. Xvoid wsetmaxwinsize _ARGS((int width, int height));
  912. Xvoid wsetdefwinsize _ARGS((int width, int height));
  913. Xvoid wsetdefwinpos _ARGS((int h, int v));
  914. Xvoid wgetdefwinsize _ARGS((int *pwidth, int *pheight));
  915. Xvoid wgetdefwinpos _ARGS((int *ph, int *pv));
  916. X
  917. XWINDOW *wopen _ARGS((char *title,
  918. X        void (*drawproc)(/*WINDOW *win,
  919. X                int left, int top, int right, int bottom*/)));
  920. Xvoid wclose _ARGS((WINDOW *win));
  921. X#define wgettag(win) (((_FAKEWINDOW *)(win)) -> tag)
  922. X#define wsettag(win, newtag) (((_FAKEWINDOW *)(win)) -> tag = (newtag))
  923. Xvoid wsetactive _ARGS((WINDOW *win));
  924. XWINDOW *wgetactive _ARGS((void));
  925. Xvoid wgetwinsize _ARGS((WINDOW *win, int *width, int *height));
  926. Xvoid wsetdocsize _ARGS((WINDOW *win, int width, int height));
  927. Xvoid wgetdocsize _ARGS((WINDOW *win, int *width, int *height));
  928. Xvoid wsettitle _ARGS((WINDOW *win, char *title));
  929. Xchar *wgettitle _ARGS((WINDOW *win)); /* Returns pointer to static data */
  930. X
  931. Xvoid wsetorigin _ARGS((WINDOW *win, int h, int v));
  932. Xvoid wgetorigin _ARGS((WINDOW *win, int *h, int *v));
  933. Xvoid wshow _ARGS((WINDOW *win, int left, int top, int right, int bottom));
  934. Xvoid wchange _ARGS((WINDOW *win, int left, int top, int right, int bottom));
  935. Xvoid wscroll _ARGS((WINDOW *win, int left, int top, int right, int bottom,
  936. X    int dh, int dv));
  937. X
  938. Xvoid wfleep _ARGS((void));
  939. Xvoid wmessage _ARGS((char *str));
  940. Xvoid wperror _ARGS((char *name));
  941. X/*bool*/int waskstr _ARGS((char *prompt, char *buf, int buflen));
  942. Xint waskync _ARGS((char *question, int dflt));
  943. X/*bool*/int waskfile _ARGS((char *prompt, char *buf, int buflen,
  944. X                        /*bool*/int newfile));
  945. X
  946. Xvoid wsetcaret _ARGS((WINDOW *win, int h, int v));
  947. Xvoid wnocaret _ARGS((WINDOW *win));
  948. X
  949. Xvoid wsettimer _ARGS((WINDOW *win, int deciseconds));
  950. X
  951. XMENU *wmenucreate _ARGS((int id, char *title));
  952. Xvoid wmenudelete _ARGS((MENU *mp));
  953. Xint wmenuadditem _ARGS((MENU *mp, char *text, int shortcut));
  954. Xvoid wmenusetitem _ARGS((MENU *mp, int i, char *text));
  955. Xvoid wmenusetdeflocal _ARGS((/*bool*/int local));
  956. Xvoid wmenuattach _ARGS((WINDOW *win, MENU *mp));
  957. Xvoid wmenudetach _ARGS((WINDOW *win, MENU *mp));
  958. Xvoid wmenuenable _ARGS((MENU *mp, int item, int flag));
  959. Xvoid wmenucheck _ARGS((MENU *mp, int item, int flag));
  960. X
  961. X/* The following is only available in termcap stdwin: */
  962. Xvoid wsetshortcut _ARGS((int id, int item, char *keys));
  963. X
  964. Xvoid wgetevent _ARGS((EVENT *ep));
  965. X/*bool*/int wpollevent _ARGS((EVENT *ep));
  966. Xvoid wungetevent _ARGS((EVENT *ep));
  967. Xvoid wupdate _ARGS((WINDOW *win));
  968. Xvoid wbegindrawing _ARGS((WINDOW *win));
  969. Xvoid wenddrawing _ARGS((WINDOW *win));
  970. Xvoid wflush _ARGS((void));
  971. X
  972. Xvoid wdrawline _ARGS((int h1, int v1, int h2, int v2));
  973. Xvoid wxorline _ARGS((int h1, int v1, int h2, int v2));
  974. Xvoid wdrawcircle _ARGS((int h, int v, int radius));
  975. Xvoid wdrawelarc _ARGS((int h, int v, int hrad, int vrad, int ang1, int ang2));
  976. Xvoid wdrawbox _ARGS((int left, int top, int right, int bottom));
  977. Xvoid werase _ARGS((int left, int top, int right, int bottom));
  978. Xvoid wpaint _ARGS((int left, int top, int right, int bottom));
  979. Xvoid winvert _ARGS((int left, int top, int right, int bottom));
  980. Xvoid wshade _ARGS((int left, int top, int right, int bottom, int percent));
  981. X
  982. Xvoid wcliprect _ARGS((int left, int top, int right, int bottom));
  983. Xvoid wnoclip _ARGS((void));
  984. X
  985. Xvoid wdrawtext _ARGS((int h, int v, char *str, int len));
  986. Xvoid wdrawchar _ARGS((int h, int v, int c));
  987. Xint wlineheight _ARGS((void));
  988. Xint wbaseline _ARGS((void));
  989. Xint wtextwidth _ARGS((char *str, int len));
  990. Xint wcharwidth _ARGS((int c));
  991. Xint wtextbreak _ARGS((char *str, int len, int width));
  992. X
  993. Xvoid wgettextattr _ARGS((TEXTATTR *attr));
  994. Xvoid wsettextattr _ARGS((TEXTATTR *attr));
  995. Xvoid wgetwintextattr _ARGS((WINDOW *win, TEXTATTR *attr));
  996. Xvoid wsetwintextattr _ARGS((WINDOW *win, TEXTATTR *attr));
  997. X
  998. Xvoid wsetplain _ARGS((void));
  999. Xvoid wsethilite _ARGS((void));
  1000. Xvoid wsetinverse _ARGS((void));
  1001. Xvoid wsetitalic _ARGS((void));
  1002. Xvoid wsetbold _ARGS((void));
  1003. Xvoid wsetbolditalic _ARGS((void));
  1004. Xvoid wsetunderline _ARGS((void));
  1005. X
  1006. Xvoid wsetfont _ARGS((char *fontname));
  1007. Xvoid wsetsize _ARGS((int pointsize));
  1008. X
  1009. X/* Setting the mouse cursor for a window */
  1010. XCURSOR *wfetchcursor _ARGS((char *name));
  1011. Xvoid wsetwincursor _ARGS((WINDOW *win, CURSOR *cursor));
  1012. X
  1013. X/* X11 Selection interface */
  1014. X/*bool*/int wsetselection _ARGS((WINDOW *, int, char *, int));
  1015. Xvoid wresetselection _ARGS((int));
  1016. Xchar *wgetselection _ARGS((int, int *));
  1017. X
  1018. X/* Cut buffer interface */
  1019. Xvoid wsetcutbuffer _ARGS((int, char *, int));
  1020. Xchar *wgetcutbuffer _ARGS((int, int *));
  1021. Xvoid wrotatecutbuffers _ARGS((int));
  1022. Xvoid wsetclip _ARGS((char *, int));
  1023. Xchar *wgetclip _ARGS((void));
  1024. X
  1025. X
  1026. X/* Pull in definitions for TEXTEDIT package */
  1027. X
  1028. X#include "stdwtext.h"
  1029. X
  1030. X#endif /* __STDWIN_H__ */
  1031. END_OF_FILE
  1032. if test 8311 -ne `wc -c <'H/stdwin.h'`; then
  1033.     echo shar: \"'H/stdwin.h'\" unpacked with wrong size!
  1034. fi
  1035. # end of 'H/stdwin.h'
  1036. fi
  1037. if test -f 'Packs/textedit/editwin.c' -a "${1}" != "-c" ; then 
  1038.   echo shar: Will not clobber existing file \"'Packs/textedit/editwin.c'\"
  1039. else
  1040. echo shar: Extracting \"'Packs/textedit/editwin.c'\" \(7562 characters\)
  1041. sed "s/^X//" >'Packs/textedit/editwin.c' <<'END_OF_FILE'
  1042. X/* Edit Windows */
  1043. X
  1044. X/* The data structure exported by this module is intended to
  1045. X   be accessible to the caller;
  1046. X   the routines provided here don't duplicate operations that
  1047. X   can be done by calling text-edit or window routines directly.
  1048. X   Exception: ewreplace is like tereplace, but also clears
  1049. X   the 'saved' flag and sets the document size */
  1050. X
  1051. X#include "stdwin.h"
  1052. X#include "tools.h"
  1053. X#include "editwin.h"
  1054. X
  1055. Xextern long ftell _ARGS((FILE *));
  1056. X
  1057. X#define MAXFN 256 /* File name length */
  1058. X
  1059. Xstatic int ewnum;
  1060. Xstatic EDITWIN **ewlist;
  1061. X
  1062. XEDITWIN *
  1063. Xewfind(win)
  1064. X    WINDOW *win;
  1065. X{
  1066. X    int i;
  1067. X
  1068. X    if (win == NULL)
  1069. X        return NULL;
  1070. X
  1071. X    i= wgettag(win);
  1072. X    
  1073. X    if (i >= 0 && i < ewnum &&
  1074. X            ewlist[i] != NULL && ewlist[i]->win == win)
  1075. X        return ewlist[i];
  1076. X    else
  1077. X        return NULL;
  1078. X}
  1079. X
  1080. Xint
  1081. Xewcount()
  1082. X{
  1083. X    int count= 0;
  1084. X    int i;
  1085. X    for (i= 0; i < ewnum; ++i) {
  1086. X        if (ewlist[i] != NULL)
  1087. X            ++count;
  1088. X    }
  1089. X    return count;
  1090. X}
  1091. X
  1092. Xstatic void
  1093. Xewdrawproc(win, left, top, right, bottom)
  1094. X    WINDOW *win;
  1095. X{
  1096. X    EDITWIN *ew= ewfind(win);
  1097. X    if (ew != NULL)
  1098. X        tedrawnew(ew->tp, left, top, right, bottom);
  1099. X}
  1100. X
  1101. XEDITWIN *
  1102. Xewcreate(filename)
  1103. X    char *filename;
  1104. X{
  1105. X    EDITWIN *ew= ALLOC(EDITWIN);
  1106. X    int width, height;
  1107. X    int i;
  1108. X    
  1109. X    if (ew == NULL)
  1110. X        return NULL;
  1111. X    ew->win= wopen(filename==NULL ? "Untitled" : filename, ewdrawproc);
  1112. X    if (ew->win == NULL) {
  1113. X        FREE(ew);
  1114. X        return NULL;
  1115. X    }
  1116. X    wsetwincursor(ew->win, wfetchcursor("ibeam"));
  1117. X    wgetwinsize(ew->win, &width, &height);
  1118. X    ew->tp= tecreate(ew->win, 0, 0, width, height);
  1119. X    if (ew->tp == NULL) {
  1120. X        wclose(ew->win);
  1121. X        FREE(ew);
  1122. X        return NULL;
  1123. X    }
  1124. X    if (filename != NULL) {
  1125. X        if (!ewreadfile(ew, filename)) {
  1126. X            tefree(ew->tp);
  1127. X            wclose(ew->win);
  1128. X            FREE(ew);
  1129. X            return NULL;
  1130. X        }
  1131. X    }
  1132. X    ew->filename= strdup(filename);
  1133. X    ew->saved= TRUE;
  1134. X    for (i= 0; i < ewnum; ++i) {
  1135. X        if (ewlist[i] == NULL)
  1136. X            break;
  1137. X    }
  1138. X    wsettag(ew->win, i);
  1139. X    if (i >= ewnum) {
  1140. X        L_APPEND(ewnum, ewlist, EDITWIN*, NULL);
  1141. X    }
  1142. X    ewlist[i]= ew;
  1143. X    return ew;
  1144. X}
  1145. X
  1146. XEDITWIN *
  1147. Xewnew()
  1148. X{
  1149. X    return ewcreate((char*)NULL);
  1150. X}
  1151. X
  1152. XEDITWIN *
  1153. Xewopen()
  1154. X{
  1155. X    char filename[MAXFN];
  1156. X    
  1157. X    filename[0]= EOS;
  1158. X    if (waskfile("Open file:", filename, sizeof filename, FALSE))
  1159. X        return ewcreate(filename);
  1160. X    else
  1161. X        return NULL;
  1162. X}
  1163. X
  1164. Xbool
  1165. Xewclose(ew)
  1166. X    EDITWIN *ew;
  1167. X{
  1168. X    int i;
  1169. X    
  1170. X    if (!ew->saved) {
  1171. X        char buf[MAXFN+25];
  1172. X        sprintf(buf, "Save changes to \"%s\" before closing?",
  1173. X            ew->filename==NULL ? "Untitled" : ew->filename);
  1174. X        switch (waskync(buf, 1)) {
  1175. X        case -1:
  1176. X            return FALSE;
  1177. X        case 0:
  1178. X            break;
  1179. X        case 1:
  1180. X            if (!ewsave(ew))
  1181. X                return FALSE;
  1182. X            break;
  1183. X        }
  1184. X    }
  1185. X    i= wgettag(ew->win);
  1186. X    if (i >= 0 && i < ewnum && ewlist[i] == ew)
  1187. X        ewlist[i]= NULL;
  1188. X    tefree(ew->tp);
  1189. X    wclose(ew->win);
  1190. X    FREE(ew->filename);
  1191. X    FREE(ew);
  1192. X    return TRUE;
  1193. X}
  1194. X
  1195. Xbool
  1196. Xewsave(ew)
  1197. X    EDITWIN *ew;
  1198. X{
  1199. X    if (ew->saved)
  1200. X        return TRUE;
  1201. X    if (!ew->filename)
  1202. X        return ewsaveas(ew);
  1203. X    return ew->saved= ewwritefile(ew, ew->filename);
  1204. X}
  1205. X
  1206. Xbool
  1207. Xewsaveas(ew)
  1208. X    EDITWIN *ew;
  1209. X{
  1210. X    return ewsaveprompt(ew, "Save as:", TRUE);
  1211. X}
  1212. X
  1213. Xbool
  1214. Xewsavecopy(ew)
  1215. X    EDITWIN *ew;
  1216. X{
  1217. X    return ewsaveprompt(ew, "Save a copy as:", FALSE);
  1218. X}
  1219. X
  1220. Xbool
  1221. Xewsaveprompt(ew, prompt, changefile)
  1222. X    EDITWIN *ew;
  1223. X    char *prompt;
  1224. X    bool changefile;
  1225. X{
  1226. X    char filename[MAXFN];
  1227. X    
  1228. X    filename[0]= EOS;
  1229. X    if (ew->filename != NULL) {
  1230. X        strncpy(filename, ew->filename, MAXFN);
  1231. X        filename[MAXFN-1]= EOS;
  1232. X    }
  1233. X    if (!waskfile(prompt, filename, sizeof filename, TRUE))
  1234. X        return FALSE;
  1235. X    if (!ewwritefile(ew, filename))
  1236. X        return FALSE;
  1237. X    if (changefile) {
  1238. X        FREE(ew->filename);
  1239. X        ew->filename= strdup(filename);
  1240. X        wsettitle(ew->win, filename);
  1241. X        ew->saved= TRUE;
  1242. X    }
  1243. X    return TRUE;
  1244. X}
  1245. X
  1246. Xbool
  1247. Xewrevert(ew)
  1248. X    EDITWIN *ew;
  1249. X{
  1250. X    char buf[MAXFN+50];
  1251. X    
  1252. X    if (ew->saved)
  1253. X        return TRUE;
  1254. X    if (ew->filename == NULL) {
  1255. X        wmessage("Not saved yet");
  1256. X        return FALSE;
  1257. X    }
  1258. X    sprintf(buf, "Discard changes since last save to \"%s\" ?",
  1259. X        ew->filename);
  1260. X    if (waskync(buf, 1) < 1)
  1261. X        return FALSE;
  1262. X    return ewreadfile(ew, ew->filename);
  1263. X}
  1264. X
  1265. Xbool
  1266. Xewreadfile(ew, filename)
  1267. X    EDITWIN *ew;
  1268. X    char *filename;
  1269. X{
  1270. X    FILE *fp= fopen(filename, "r");
  1271. X    long size;
  1272. X    char *buf;
  1273. X    
  1274. X    if (fp == NULL) {
  1275. X        wperror(filename);
  1276. X        return FALSE;
  1277. X    }
  1278. X    if (fseek(fp, 0L, 2) == -1) {
  1279. X        wperror (filename);
  1280. X        fclose (fp);
  1281. X        return FALSE;
  1282. X    }
  1283. X    size= ftell(fp);
  1284. X    if (size >= 1L<<15) {
  1285. X        char mbuf[MAXFN + 50];
  1286. X        sprintf(mbuf, "File \"%s\" is big (%d K).  Still edit?",
  1287. X            filename, (int) ((size+1023)/1024));
  1288. X        if (waskync(mbuf, 1) < 1) {
  1289. X            fclose(fp);
  1290. X            return FALSE;
  1291. X        }
  1292. X    }
  1293. X    buf= malloc((unsigned)size);
  1294. X    if (buf == NULL) {
  1295. X        wmessage("Can't get memory for buffer");
  1296. X        fclose(fp);
  1297. X        return FALSE;
  1298. X    }
  1299. X    if (fseek(fp, 0L, 0) == -1) {
  1300. X        wperror (filename);
  1301. X        fclose (fp);
  1302. X        return FALSE;
  1303. X    }
  1304. X    if ((size = fread(buf, 1, (int) size, fp)) == -1) {
  1305. X        wmessage("Read error");
  1306. X        fclose(fp);
  1307. X        return FALSE;
  1308. X    }
  1309. X    fclose(fp);
  1310. X    tesetbuf(ew->tp, buf, (int) size); /* Gives the buffer away! */
  1311. X    ew->saved= TRUE;
  1312. X    ewsetdimensions(ew);
  1313. X    return TRUE;
  1314. X}
  1315. X
  1316. Xvoid
  1317. Xewsetdimensions(ew)
  1318. X    EDITWIN *ew;
  1319. X{
  1320. X    wsetdocsize(ew->win, 0, tegetbottom(ew->tp));
  1321. X}
  1322. X
  1323. Xbool
  1324. Xewwritefile(ew, filename)
  1325. X    EDITWIN *ew;
  1326. X    char *filename;
  1327. X{
  1328. X    FILE *fp= fopen(filename, "w");
  1329. X    char *buf;
  1330. X    int len, nwritten;
  1331. X    
  1332. X    if (fp == NULL) {
  1333. X        wperror(filename);
  1334. X        return FALSE;
  1335. X    }
  1336. X    buf= tegettext(ew->tp);
  1337. X    len= strlen(buf);
  1338. X    nwritten= fwrite(buf, 1, len, fp);
  1339. X    fclose(fp);
  1340. X    if (nwritten != len) {
  1341. X        wmessage("Write error");
  1342. X        return FALSE;
  1343. X    }
  1344. X    /* Can't set saved to TRUE, because of 'save a copy' */
  1345. X    return TRUE;
  1346. X}
  1347. X
  1348. Xbool
  1349. Xewevent(ew, e, closed_return)
  1350. X    EDITWIN *ew;
  1351. X    EVENT *e;
  1352. X    bool *closed_return;
  1353. X{
  1354. X    bool closed= FALSE;
  1355. X    bool change= FALSE;
  1356. X    
  1357. X    if (ew == NULL) {
  1358. X        ew= ewfind(e->window);
  1359. X        if (ew == NULL)
  1360. X            return FALSE;
  1361. X    }
  1362. X    else if (e->window != ew->win)
  1363. X        return FALSE;
  1364. X    
  1365. X    switch (e->type) {
  1366. X    
  1367. X    case WE_ACTIVATE:
  1368. X        break;
  1369. X        
  1370. X    case WE_SIZE:
  1371. X        {
  1372. X            int width, height;
  1373. X            wgetwinsize(ew->win, &width, &height);
  1374. X            temovenew(ew->tp, 0, 0, width, height);
  1375. X            ewsetdimensions(ew);
  1376. X        }
  1377. X        break;
  1378. X        
  1379. X    case WE_COMMAND:
  1380. X        if (e->u.command == WC_CLOSE) {
  1381. X            closed= ewclose(ew);
  1382. X            break;
  1383. X        }
  1384. X        /* Else, fall through */
  1385. X        if (e->u.command == WC_RETURN ||
  1386. X            e->u.command == WC_TAB ||
  1387. X            e->u.command == WC_BACKSPACE)
  1388. X            change= TRUE;
  1389. X            goto def;
  1390. X    
  1391. X    case WE_MOUSE_DOWN:
  1392. X        /* Edit the coordinates slightly so teevent always
  1393. X           believes it is in the rect */
  1394. X        {
  1395. X            int left= tegetleft(ew->tp);
  1396. X            int right= tegetright(ew->tp);
  1397. X            int top= tegettop(ew->tp);
  1398. X            int bottom= tegetbottom(ew->tp);
  1399. X            CLIPMIN(e->u.where.h, left);
  1400. X            CLIPMAX(e->u.where.h, right);
  1401. X            CLIPMIN(e->u.where.v, top);
  1402. X            if (e->u.where.v >= bottom) {
  1403. X                e->u.where.v= bottom;
  1404. X                e->u.where.h= right;
  1405. X            }
  1406. X        }
  1407. X        /* Fall through */
  1408. X    default:
  1409. X    def:
  1410. X        if (!teevent(ew->tp, e))
  1411. X            return FALSE;
  1412. X        if (e->type == WE_CHAR)
  1413. X            change= TRUE;
  1414. X        if (change) {
  1415. X            ew->saved= FALSE;
  1416. X            ewsetdimensions(ew);
  1417. X        }
  1418. X        break;
  1419. X        
  1420. X    }
  1421. X    
  1422. X    if (closed_return != NULL)
  1423. X        *closed_return= closed;
  1424. X    return TRUE;
  1425. X}
  1426. X
  1427. Xbool
  1428. Xewsaveall()
  1429. X{
  1430. X    int i;
  1431. X    
  1432. X    for (i= 0; i < ewnum; ++i) {
  1433. X        if (ewlist[i] != NULL && !ewsave(ewlist[i]))
  1434. X            return FALSE;
  1435. X    }
  1436. X    return TRUE;
  1437. X}
  1438. X
  1439. Xbool
  1440. Xewcloseall()
  1441. X{
  1442. X    int i;
  1443. X    
  1444. X    for (i= 0; i < ewnum; ++i) {
  1445. X        if (ewlist[i] != NULL && !ewclose(ewlist[i]))
  1446. X            return FALSE;
  1447. X    }
  1448. X    return TRUE;
  1449. X}
  1450. X
  1451. Xvoid
  1452. Xewreplace(ew, str)
  1453. X    EDITWIN *ew;
  1454. X    char *str;
  1455. X{
  1456. X    if (*str == EOS && tegetfoc1(ew->tp) == tegetfoc2(ew->tp))
  1457. X        return;
  1458. X    tereplace(ew->tp, str);
  1459. X    ew->saved= FALSE;
  1460. X    ewsetdimensions(ew);
  1461. X}
  1462. X
  1463. X/*ARGSUSED*/
  1464. Xvoid
  1465. Xewundo(ew)
  1466. X    EDITWIN *ew;
  1467. X{
  1468. X    wfleep();
  1469. X}
  1470. X
  1471. Xvoid
  1472. Xewcopy(ew)
  1473. X    EDITWIN *ew;
  1474. X{
  1475. X    int f1= tegetfoc1(ew->tp);
  1476. X    int f2= tegetfoc2(ew->tp);
  1477. X    char *text;
  1478. X    if (f1 == f2)
  1479. X        wfleep();
  1480. X    else {
  1481. X        text= tegettext(ew->tp);
  1482. X        wsetclip(text+f1, f2-f1);
  1483. X    }
  1484. X        
  1485. X}
  1486. X
  1487. Xvoid
  1488. Xewpaste(ew)
  1489. X    EDITWIN *ew;
  1490. X{
  1491. X    char *text= wgetclip();
  1492. X    if (text == NULL)
  1493. X        wfleep();
  1494. X    else
  1495. X        ewreplace(ew, text);
  1496. X}
  1497. END_OF_FILE
  1498. if test 7562 -ne `wc -c <'Packs/textedit/editwin.c'`; then
  1499.     echo shar: \"'Packs/textedit/editwin.c'\" unpacked with wrong size!
  1500. fi
  1501. # end of 'Packs/textedit/editwin.c'
  1502. fi
  1503. if test -f 'Ports/mac/about.c' -a "${1}" != "-c" ; then 
  1504.   echo shar: Will not clobber existing file \"'Ports/mac/about.c'\"
  1505. else
  1506. echo shar: Extracting \"'Ports/mac/about.c'\" \(1563 characters\)
  1507. sed "s/^X//" >'Ports/mac/about.c' <<'END_OF_FILE'
  1508. X/* MAC STDWIN -- "ABOUT STDWIN" MESSAGE. */
  1509. X
  1510. X#include "macwin.h"
  1511. X#ifdef MPW
  1512. X#include <Events.h>
  1513. X#include <TextEdit.h>
  1514. X#endif
  1515. X#ifdef THINK_C
  1516. X#include <EventMgr.h>
  1517. X#include <TextEdit.h>
  1518. X#endif
  1519. X
  1520. X/* Default About... message; applications may assign to this.
  1521. X   You may also assign to about_item in "menu.c", *before*
  1522. X   calling winit() or winitargs().
  1523. X   Also see your THINK C licence.
  1524. X*/
  1525. Xchar *about_message=
  1526. X    "STDWIN version 0.9.5 (using THINK C 4.0)\r\r\
  1527. XCopyright \251 1988, 1989, 1990 Stichting Mathematisch Centrum, \
  1528. XAmsterdam\r\
  1529. XWritten by Guido van Rossum (guido@cwi.nl)\r\
  1530. XCWI, dept. AA, P.O.B. 4079\r1009 AB  Amsterdam, The Netherlands\r\r\
  1531. X[Option-click in window scrolls as in MacPaint,\r\
  1532. XOption-click in title sends behind]";
  1533. X    /* \251 is the (c) Copyright symbol.
  1534. X       I don't want non-ASCII characters in my source. */
  1535. X
  1536. X
  1537. X/* "About ..." procedure.
  1538. X   This is self-contained -- if you have a better idea, change it.
  1539. X*/
  1540. X
  1541. Xvoid
  1542. Xdo_about()
  1543. X{
  1544. X    Rect r;
  1545. X    WindowPtr w;
  1546. X    EventRecord e;
  1547. X    
  1548. X    SetRect(&r, 0, 0, 340, 180); /* XXX Shouldn't be hardcoded */
  1549. X    OffsetRect(&r, (screen->portRect.right - r.right)/2, 40);
  1550. X    
  1551. X    w = NewWindow(
  1552. X        (Ptr) NULL,    /* No storage */
  1553. X        &r,        /* Bounds rect */
  1554. X        "",        /* No title */
  1555. X        true,         /* Visible */
  1556. X        altDBoxProc,    /* Plain box with shadow */
  1557. X        (WindowPtr) -1,    /* In front position */
  1558. X        false,        /* No go-away box */
  1559. X        0L);        /* RefCon */
  1560. X    SetPort(w);
  1561. X    r = w->portRect;
  1562. X    InsetRect(&r, 10, 10);
  1563. X    TextBox(about_message, strlen(about_message), &r, teJustCenter);
  1564. X    while (!GetNextEvent(mDownMask|keyDownMask, &e))
  1565. X        ;
  1566. X    DisposeWindow(w);
  1567. X}
  1568. END_OF_FILE
  1569. if test 1563 -ne `wc -c <'Ports/mac/about.c'`; then
  1570.     echo shar: \"'Ports/mac/about.c'\" unpacked with wrong size!
  1571. fi
  1572. # end of 'Ports/mac/about.c'
  1573. fi
  1574. if test -f 'Ports/mac/dialog.c' -a "${1}" != "-c" ; then 
  1575.   echo shar: Will not clobber existing file \"'Ports/mac/dialog.c'\"
  1576. else
  1577. echo shar: Extracting \"'Ports/mac/dialog.c'\" \(7879 characters\)
  1578. sed "s/^X//" >'Ports/mac/dialog.c' <<'END_OF_FILE'
  1579. X/* MAC STDWIN -- DIALOGS. */
  1580. X
  1581. X/* XXX These dialogs are distinctly ugly.
  1582. X   Maybe we should fix their size based on the amount of text
  1583. X   and the number of buttons. */
  1584. X
  1585. X#include "macwin.h"
  1586. X#ifdef MPW
  1587. X#include <Dialogs.h>
  1588. X#include <Packages.h>
  1589. X#endif
  1590. X#ifdef THINK_C
  1591. X#include <DialogMgr.h>
  1592. X#include <StdFilePkg.h>
  1593. X#endif
  1594. X
  1595. X/* Function prototypes */
  1596. X
  1597. XSTATIC struct itemlist **mkitemlist _ARGS((void));
  1598. XSTATIC struct item *finditem _ARGS((struct itemlist **h, int i));
  1599. XSTATIC void additem _ARGS((struct itemlist **h,
  1600. X    long stuff, Rect *ppos, int type, int size, char *data));
  1601. XSTATIC struct itemlist **ynclist _ARGS((char *prompt));
  1602. XSTATIC struct itemlist **oklist _ARGS((char *prompt));
  1603. XSTATIC struct itemlist **editlist _ARGS((char *prompt));
  1604. XSTATIC int do_dialog _ARGS((struct itemlist **h,
  1605. X    int emphasis, int lastbutton, char *buf));
  1606. X
  1607. X/* Mac-specific interface for applications that need different
  1608. X   file types */
  1609. X
  1610. Xextern OSType std_type;
  1611. X
  1612. X#ifdef THINK_C
  1613. XOSType std_type= 'TEXT';
  1614. X#endif
  1615. X
  1616. XOSType *wasktypelist= &std_type;
  1617. Xint waskntypes= 1;
  1618. X
  1619. X/* Standard File interface routine */
  1620. X
  1621. Xbool
  1622. Xwaskfile(prompt, buf, len, new)
  1623. X    char *prompt;
  1624. X    char *buf;
  1625. X    int len;
  1626. X    bool new;
  1627. X{
  1628. X    static Point corner= {80, 60};
  1629. X    SFReply reply;
  1630. X    
  1631. X    if (active != NULL)
  1632. X        rmcaret(active);
  1633. X    if (new) {
  1634. X        char *def= strrchr(buf, ':');
  1635. X        if (def != NULL)
  1636. X            ++def;
  1637. X        else
  1638. X            def= buf;
  1639. X        SFPutFile(PASSPOINT corner, PSTRING(prompt),
  1640. X#ifdef THINK_C /* XXX ??? */
  1641. X            CtoPstr(def),
  1642. X#else
  1643. X            PSTRING(def),
  1644. X#endif
  1645. X            (ProcPtr)NULL, &reply);
  1646. X    }
  1647. X    else {
  1648. X        SFGetFile(PASSPOINT corner, (char*)NULL, (ProcPtr)NULL,
  1649. X            waskntypes, wasktypelist, (ProcPtr)NULL, &reply);
  1650. X    }
  1651. X    set_watch();
  1652. X    if (!reply.good)
  1653. X        return FALSE;
  1654. X    fullpath(buf, reply.vRefNum, p2cstr((char*)&reply.fName));
  1655. X    return TRUE;
  1656. X}
  1657. X
  1658. X/* Data definitions for dialog item lists (from Inside Mac). */
  1659. X
  1660. Xstruct item {
  1661. X    long stuff;        /* Handle or proc pointer */
  1662. X    Rect pos;        /* Position (local coord.) */
  1663. X    char type;        /* Item type */
  1664. X    char size;        /* Length of data; must be even */
  1665. X    char data[256];     /* The data; variable length */
  1666. X};
  1667. X
  1668. Xstruct itemlist {
  1669. X    short count;        /* Number of items minus one */
  1670. X    struct item data;    /* First item */
  1671. X    /* NB: items are variable length. */
  1672. X};
  1673. X
  1674. X#define ROUND_EVEN(x) (((x) + 1) & ~1) /* Round up to even */
  1675. X
  1676. X#define FIXED_SIZE 14        /* Size of struct item w/o data */
  1677. X
  1678. X/* Routines to manipulate Dialog item lists. */
  1679. X
  1680. X/* Create an empty item list. */
  1681. X
  1682. Xstatic struct itemlist **
  1683. Xmkitemlist()
  1684. X{
  1685. X    struct itemlist **h= (struct itemlist **) NewHandle(2);
  1686. X    
  1687. X    (*h)->count= -1;
  1688. X    return h;
  1689. X}
  1690. X
  1691. X/* Find the i'th item, starting to count from 0.
  1692. X   It may be asked for the non-existing item just beyond the last,
  1693. X   but not beyond that. */
  1694. X
  1695. Xstatic struct item *
  1696. Xfinditem(h, i)
  1697. X    struct itemlist **h;
  1698. X    int i;
  1699. X{
  1700. X    int count= (*h)->count;
  1701. X    struct item *it= &(*h)->data;
  1702. X    int k;
  1703. X    
  1704. X    if (i < 0 || i > count+1) {
  1705. X        return NULL;
  1706. X    }
  1707. X    for (k= 0; k < i; ++k) {
  1708. X        /* I don't trust two casts in one expression: */
  1709. X        char *p= (char *) it;
  1710. X        int size= ROUND_EVEN(it->size);
  1711. X        p += FIXED_SIZE + size;
  1712. X        it= (struct item *) p;
  1713. X    }
  1714. X    return it;
  1715. X}
  1716. X
  1717. X/* Add an item to the list. */
  1718. X
  1719. Xstatic void
  1720. Xadditem(h, stuff, ppos, type, size, data)
  1721. X    struct itemlist **h;
  1722. X    long stuff;
  1723. X    Rect *ppos;
  1724. X    int type;
  1725. X    int size;
  1726. X    char *data;
  1727. X{
  1728. X    struct item *it;
  1729. X    long totalsize;
  1730. X    
  1731. X    if (size < 0)
  1732. X        size= strlen(data);
  1733. X    it= finditem(h, (*h)->count + 1);
  1734. X    totalsize= (char *)it - (char *)(*h);
  1735. X    SetHandleSize(h, totalsize + FIXED_SIZE + ROUND_EVEN(size));
  1736. X    it= finditem(h, (*h)->count + 1);
  1737. X    it->stuff= stuff;
  1738. X    it->pos= *ppos;
  1739. X    it->type= type;
  1740. X    it->size= size;
  1741. X    BlockMove(data, it->data, size);
  1742. X    ++(*h)->count;
  1743. X}
  1744. X
  1745. X/* Construct item list for question w/ Yes/No/Cancel response.
  1746. X   Note: the statText item is first, so we can distinguish between a
  1747. X   press on Return or Enter (when ModalDialog returns 1) and any
  1748. X   of the three buttons. */
  1749. X
  1750. Xstatic struct itemlist **
  1751. Xynclist(prompt)
  1752. X    char *prompt;
  1753. X{
  1754. X    struct itemlist **h= mkitemlist();
  1755. X    Rect pos;
  1756. X    
  1757. X    SetRect(&pos, 20, 20, 280, 70);
  1758. X    additem(h, 0L, &pos, statText|itemDisable, -1, prompt);
  1759. X    SetRect(&pos, 20, 80, 80, 100);
  1760. X    additem(h, 0L, &pos, ctrlItem|btnCtrl, -1, "Yes");
  1761. X    OffsetRect(&pos, 0, 30);
  1762. X    additem(h, 0L, &pos, ctrlItem|btnCtrl, -1, "No");
  1763. X    OffsetRect(&pos, 200, 0);
  1764. X    additem(h, 0L, &pos, ctrlItem|btnCtrl, -1, "Cancel");
  1765. X    return h;
  1766. X}
  1767. X
  1768. X/* Construct item list for message w/ OK button. */
  1769. X
  1770. Xstatic struct itemlist **
  1771. Xoklist(prompt)
  1772. X    char *prompt;
  1773. X{
  1774. X    struct itemlist **h= mkitemlist();
  1775. X    Rect pos;
  1776. X    
  1777. X    SetRect(&pos, 20, 20, 280, 100);
  1778. X    additem(h, 0L, &pos, statText|itemDisable, -1, prompt);
  1779. X    SetRect(&pos, 20, 110, 80, 130);
  1780. X    additem(h, 0L, &pos, ctrlItem|btnCtrl, -1, "OK");
  1781. X    return h;
  1782. X}
  1783. X
  1784. X/* Construct item list for dialog w/ edit-text, OK and Cancel button. */
  1785. X
  1786. Xstatic struct itemlist **
  1787. Xeditlist(prompt)
  1788. X    char *prompt;
  1789. X{
  1790. X    struct itemlist **h= mkitemlist();
  1791. X    Rect pos;
  1792. X    
  1793. X    SetRect(&pos, 20, 20, 280, 70);
  1794. X    additem(h, 0L, &pos, statText|itemDisable, -1, prompt);
  1795. X    SetRect(&pos, 20, 110, 80, 130);
  1796. X    additem(h, 0L, &pos, ctrlItem|btnCtrl, -1, "OK");
  1797. X    OffsetRect(&pos, 200, 0);
  1798. X    additem(h, 0L, &pos, ctrlItem|btnCtrl, -1, "Cancel");
  1799. X    SetRect(&pos, 20, 80, 280, 96);
  1800. X    additem(h, 0L, &pos, editText, 0, (char *) NULL);
  1801. X    return h;
  1802. X}
  1803. X
  1804. X/* Perform an entire dialog.
  1805. X   It stops when an item <= lastbutton is hit, and returns the item number.
  1806. X   When buf is non-NULL, the next item is assumed to be an edit-text
  1807. X   item and its contents are transferred to buf. */
  1808. X
  1809. Xstatic int
  1810. Xdo_dialog(h, emphasis, lastbutton, buf)
  1811. X    struct itemlist **h;
  1812. X    int emphasis;
  1813. X    int lastbutton;
  1814. X    char *buf;
  1815. X{
  1816. X    Rect box;
  1817. X    DialogPtr d;
  1818. X    short hit;
  1819. X    short type;
  1820. X    Handle item;
  1821. X    
  1822. X    _wresetmouse(); /* Clean up mouse down status */
  1823. X    if (active != NULL)
  1824. X        rmcaret(active);
  1825. X    
  1826. X    /* Create a box of convenient size, centered horizontally,
  1827. X       somewhat below the top of the screen. */
  1828. X    SetRect(&box, 0, 0, 300, 140);
  1829. X    OffsetRect(&box, (screen->portRect.right - box.right)/2, 60);
  1830. X    
  1831. X    d= NewDialog(
  1832. X        (Ptr)NULL,
  1833. X        &box,
  1834. X        "",
  1835. X        true,
  1836. X        dBoxProc,
  1837. X        (WindowPtr)(-1),
  1838. X        false,
  1839. X        0L,
  1840. X        h);
  1841. X    
  1842. X    if (emphasis > 0) { /* Emphasize default button */
  1843. X        GetDItem(d, emphasis, &type, &item, &box);
  1844. X        SetPort(d);
  1845. X        InsetRect(&box, -4, -4);
  1846. X        PenSize(3, 3);
  1847. X        FrameRoundRect(&box, 16, 16);
  1848. X    }
  1849. X    
  1850. X    if (buf != NULL) { /* Set edit text and focus on entire text */
  1851. X        GetDItem(d, lastbutton+1, &type, &item, &box);
  1852. X        SetIText(item, PSTRING(buf));
  1853. X        SelIText(d, lastbutton+1, 0, 32000);
  1854. X    }
  1855. X    
  1856. X    set_arrow();
  1857. X    
  1858. X    /* XXX Should support Cmd-period as shortcut for Cancel;
  1859. X       perhaps other shortcuts as well? */
  1860. X    
  1861. X    do {
  1862. X        ModalDialog((ProcPtr)NULL, &hit);
  1863. X    } while (hit > lastbutton);
  1864. X    
  1865. X    set_watch();
  1866. X    
  1867. X    if (hit == 1 && emphasis > 0) {
  1868. X        /* Pressed Return or Enter; flash default button. */
  1869. X        GetDItem(d, emphasis, &type, &item, &box);
  1870. X        HiliteControl((ControlHandle)item, inButton);
  1871. X    }
  1872. X    
  1873. X    if (buf != NULL) {
  1874. X        GetDItem(d, lastbutton+1, &type, &item, &box);
  1875. X        GetIText(item, buf);
  1876. X#ifndef CLEVERGLUE
  1877. X        PtoCstr(buf);
  1878. X#endif
  1879. X    }
  1880. X    DisposDialog(d);
  1881. X    return hit;
  1882. X}
  1883. X
  1884. Xvoid
  1885. Xwmessage(prompt)
  1886. X    char *prompt;
  1887. X{
  1888. X    do_dialog(oklist(prompt), 2, 2, (char *)NULL);
  1889. X}
  1890. X
  1891. Xint
  1892. Xwaskync(prompt, def)
  1893. X    char *prompt;
  1894. X{
  1895. X    int emphasis;
  1896. X    int hit;
  1897. X    
  1898. X    switch (def) {
  1899. X    case 1:
  1900. X        emphasis= 2;
  1901. X        break;
  1902. X    case 0:
  1903. X        emphasis= 3;
  1904. X        break;
  1905. X    default:
  1906. X        emphasis= 4;
  1907. X        break;
  1908. X    }
  1909. X    
  1910. X    hit= do_dialog(ynclist(prompt), emphasis, 4, (char *) NULL);
  1911. X    
  1912. X    switch (hit) {
  1913. X    default: /* case 1: Return or Enter pressed */
  1914. X        return def;
  1915. X    case 2: /* Yes button */
  1916. X        return 1;
  1917. X    case 3: /* No button */
  1918. X        return 0;
  1919. X    case 4: /* Cancel button */
  1920. X        return -1;
  1921. X    }
  1922. X}
  1923. X
  1924. Xbool
  1925. Xwaskstr(prompt, buf, len)
  1926. X    char *prompt;
  1927. X    char *buf;
  1928. X    int len;
  1929. X{
  1930. X    /* This code assumes 'buf' is at least 256 bytes long! */
  1931. X    return do_dialog(editlist(prompt), 2, 3, buf) <= 2;
  1932. X}
  1933. X
  1934. Xvoid
  1935. Xwperror(name)
  1936. X    char *name;
  1937. X{
  1938. X    char buf[256];
  1939. X    char *p= buf;
  1940. X    
  1941. X    if (name != NULL) {
  1942. X        strcpy(p, name);
  1943. X        strcat(p, ": ");
  1944. X        p += strlen(p);
  1945. X    }
  1946. X    strcat(p, "I/O error");
  1947. X    p += strlen(p);
  1948. X    sprintf(p, " %d", errno);
  1949. X    wmessage(buf);
  1950. X}
  1951. END_OF_FILE
  1952. if test 7879 -ne `wc -c <'Ports/mac/dialog.c'`; then
  1953.     echo shar: \"'Ports/mac/dialog.c'\" unpacked with wrong size!
  1954. fi
  1955. # end of 'Ports/mac/dialog.c'
  1956. fi
  1957. if test -f 'Ports/x11/draw.c' -a "${1}" != "-c" ; then 
  1958.   echo shar: Will not clobber existing file \"'Ports/x11/draw.c'\"
  1959. else
  1960. echo shar: Extracting \"'Ports/x11/draw.c'\" \(7803 characters\)
  1961. sed "s/^X//" >'Ports/x11/draw.c' <<'END_OF_FILE'
  1962. X/* X11 STDWIN -- Drawing operations */
  1963. X
  1964. X#include "x11.h"
  1965. X
  1966. X/* Window ID and Graphics Context used implicitly by all drawing operations */
  1967. X
  1968. Xstatic Window wid;
  1969. Xstatic GC gc;
  1970. Xstatic unsigned long fg, bg;
  1971. X
  1972. X/* Start using the given Window ID, GC, fg and bg.
  1973. X   (I had hoped to use this from the Dialog and Menu modules,
  1974. X   but this hope didn't come true.) */
  1975. X
  1976. Xstatic void
  1977. X_wusewgc(awid, agc, afg, abg)
  1978. X    Window awid;
  1979. X    GC agc;
  1980. X    unsigned long afg, abg;
  1981. X{
  1982. X    wid= awid;
  1983. X    gc= agc;
  1984. X    fg= afg;
  1985. X    bg= abg;
  1986. X}
  1987. X
  1988. X/* Put the current font's ID in the current GC, if non-null.
  1989. X   Called by _wfontswitch. */
  1990. X
  1991. X_wgcfontswitch()
  1992. X{
  1993. X    if (gc != 0) {
  1994. X        if (_wf->fid == 0)
  1995. X            XCopyGC(_wd, DefaultGCOfScreen(_ws), GCFont, gc);
  1996. X        else
  1997. X            XSetFont(_wd, gc, _wf->fid);
  1998. X    }
  1999. X}
  2000. X
  2001. X/* Begin drawing in the given window.
  2002. X   All drawing must be executed bewteen a call to wbegindrawing
  2003. X   and one to wenddrawing; in between, no other calls to wbegindrawing
  2004. X   should occur. */
  2005. X
  2006. Xstatic TEXTATTR saveattr;
  2007. X
  2008. Xvoid
  2009. Xwbegindrawing(win)
  2010. X    WINDOW *win;
  2011. X{
  2012. X    _wtrace(4, "wbegindrawing(win = 0x%lx)", (long)win);
  2013. X    if (wid != 0)
  2014. X        _werror("recursive wbegindrawing");
  2015. X    _wusewgc(win->wa.wid, win->gca, win->fga, win->bga);
  2016. X    saveattr= wattr;
  2017. X    wsettextattr(&win->attr);
  2018. X    if (win->caretshown)
  2019. X        _winvertcaret(win); /* Hide caret temporarily */
  2020. X}
  2021. X
  2022. X/* End drawing in the given window */
  2023. X
  2024. Xvoid
  2025. Xwenddrawing(win)
  2026. X    WINDOW *win;
  2027. X{
  2028. X    _wtrace(4, "wenddrawing(win = 0x%lx)", (long)win);
  2029. X    if (wid != win->wa.wid)
  2030. X        _werror("wrong call to enddrawing");
  2031. X    else {
  2032. X        if (win->caretshown)
  2033. X            _winvertcaret(win); /* Put it back on */
  2034. X        _wusewgc((Window)0, (GC)0, 0L, 0L); /* Clear all */
  2035. X        wsettextattr(&saveattr);
  2036. X        XFlush(_wd);
  2037. X    }
  2038. X}
  2039. X
  2040. X
  2041. X/* Text measurement functions */
  2042. X
  2043. X
  2044. X/* Compute the space taken by a string when drawn in the current font */
  2045. X
  2046. Xint
  2047. Xwtextwidth(str, len)
  2048. X    char *str;
  2049. X    int len;
  2050. X{
  2051. X    if (len < 0)
  2052. X        len= strlen(str);
  2053. X    len= XTextWidth(_wf, str, len);
  2054. X    _wtrace(7, "wtextwidth: width=%d", len);
  2055. X    return len;
  2056. X}
  2057. X
  2058. X/* Compute a character's width */
  2059. X
  2060. Xint
  2061. Xwcharwidth(c)
  2062. X    int c;
  2063. X{
  2064. X    char buf[2];
  2065. X    
  2066. X    buf[0]= c;
  2067. X    return wtextwidth(buf, 1);
  2068. X}
  2069. X
  2070. X/* Compute the right vertical spacing for the current font */
  2071. X
  2072. Xint
  2073. Xwlineheight()
  2074. X{
  2075. X    return _wf->ascent + _wf->descent;
  2076. X}
  2077. X
  2078. X/* Compute how much the baseline of the characters drawn lies below
  2079. X   the v coordinate passed to wdrawtext or wdrawchar */
  2080. X
  2081. Xint
  2082. Xwbaseline()
  2083. X{
  2084. X    return _wf->ascent;
  2085. X}
  2086. X
  2087. X
  2088. X/* Text drawing functions */
  2089. X
  2090. X
  2091. X/* Draw a text string */
  2092. X
  2093. Xvoid
  2094. Xwdrawtext(h, v, str, len)
  2095. X    int h, v;
  2096. X    char *str;
  2097. X    int len;
  2098. X{
  2099. X    int right;
  2100. X    int bottom= v + wlineheight();
  2101. X    
  2102. X    if (len < 0)
  2103. X        len= strlen(str);
  2104. X    _wtrace(5, "wdrawtext(%d, %d, \"%.*s%s\", %d)",
  2105. X        h, v, len>20 ? 17 : len, len>20 ? "..." : "", str, len);
  2106. X    if (wattr.style & (INVERSE|HILITE|UNDERLINE))
  2107. X        right = h + wtextwidth(str, len);
  2108. X    if (wattr.style & (INVERSE|HILITE))
  2109. X        werase(h, v, right, bottom);
  2110. X    XDrawString(_wd, wid, gc, h, v + _wf->ascent, str, len);
  2111. X    if (wattr.style & UNDERLINE) {
  2112. X        unsigned long ulpos, ulthick;
  2113. X        if (!XGetFontProperty(_wf, XA_UNDERLINE_POSITION, &ulpos))
  2114. X            ulpos= _wf->descent/2;
  2115. X        if (!XGetFontProperty(_wf, XA_UNDERLINE_THICKNESS, &ulthick)) {
  2116. X            ulthick= _wf->descent/3;
  2117. X            CLIPMIN(ulthick, 1);
  2118. X        }
  2119. X        ulpos += v + _wf->ascent;
  2120. X        winvert(h, (int)ulpos, right, (int)(ulpos + ulthick));
  2121. X    }
  2122. X    if (wattr.style & (INVERSE|HILITE))
  2123. X        winvert(h, v, right, bottom);
  2124. X}
  2125. X
  2126. Xvoid
  2127. Xwdrawchar(h, v, c)
  2128. X    int h, v;
  2129. X    int c;
  2130. X{
  2131. X    char ch= c;
  2132. X    
  2133. X    if ((wattr.style & (INVERSE|HILITE|UNDERLINE)) == 0) {
  2134. X#ifdef __GNUC__
  2135. X        /* Work-around for GCC bug (1.31 or some such):
  2136. X           without the _wtrace, XdrawString is never called. */
  2137. X        _wtrace(5, "wdrawchar(%d, %d, '\\%03o')", h, v, c&0377);
  2138. X#endif
  2139. X        /* Optimize plain characters */
  2140. X        XDrawString(_wd, wid, gc, h, v + _wf->ascent, &ch, 1);
  2141. X    }
  2142. X    else {
  2143. X        /* Use wdrawtext for complicated cases */
  2144. X        wdrawtext(h, v, &ch, 1);
  2145. X    }
  2146. X}
  2147. X
  2148. X
  2149. X/* Manipulate text attribute structs */
  2150. X
  2151. X
  2152. X/* Get a window's text attributes */
  2153. X
  2154. Xvoid
  2155. Xwgetwintextattr(win, pattr)
  2156. X    WINDOW *win;
  2157. X    TEXTATTR *pattr;
  2158. X{
  2159. X    *pattr= win->attr;
  2160. X}
  2161. X
  2162. X/* Change a window's text attributes */
  2163. X
  2164. Xvoid
  2165. Xwsetwintextattr(win, pattr)
  2166. X    WINDOW *win;
  2167. X    TEXTATTR *pattr;
  2168. X{
  2169. X    win->attr= *pattr;
  2170. X}
  2171. X
  2172. X
  2173. X/* Non-text drawing primitives */
  2174. X
  2175. X
  2176. X/* Draw a straight line */
  2177. X
  2178. Xvoid
  2179. Xwdrawline(h1, v1, h2, v2)
  2180. X{
  2181. X    _wtrace(7, "wdrawline((h1,v1)=(%d,%d), (h2,v2)=(%d,%d))",
  2182. X        h1, v1, h2, v2);
  2183. X    XDrawLine(_wd, wid, gc, h1, v1, h2, v2);
  2184. X}
  2185. X
  2186. X/* Draw a straight line in XOR mode */
  2187. X
  2188. Xvoid
  2189. Xwxorline(h1, v1, h2, v2)
  2190. X{
  2191. X    _wtrace(7, "wxorline((h1,v1)=(%d,%d), (h2,v2)=(%d,%d))",
  2192. X        h1, v1, h2, v2);
  2193. X    XSetFunction(_wd, gc, GXinvert);
  2194. X    XDrawLine(_wd, wid, gc, h1, v1, h2, v2);
  2195. X    XSetFunction(_wd, gc, GXcopy);
  2196. X}
  2197. X
  2198. X/* Draw a rectangle *inside* the given coordinate box */
  2199. X
  2200. Xvoid
  2201. Xwdrawbox(left, top, right, bottom)
  2202. X{
  2203. X    _wtrace(7, "wdrawbox(left=%d, top=%d, right=%d, bottom=%d)",
  2204. X        left, top, right, bottom);
  2205. X    XDrawRectangle(_wd, wid, gc, left, top, right-left-1, bottom-top-1);
  2206. X}
  2207. X
  2208. X/* Erase the given rectangle */
  2209. X
  2210. Xvoid
  2211. Xwerase(left, top, right, bottom)
  2212. X{
  2213. X    _wtrace(7, "werase(left=%d, top=%d, right=%d, bottom=%d)",
  2214. X        left, top, right, bottom);
  2215. X    
  2216. X    if (left >= right || top >= bottom)
  2217. X        return;
  2218. X    
  2219. X    /* Can't use XClearArea here because it ignores the clipping region.
  2220. X       Can't set function to GXclear because it doesn't work
  2221. X       with color.  So we fill with the background color. */
  2222. X    
  2223. X    XSetForeground(_wd, gc, bg);
  2224. X    XFillRectangle(_wd, wid, gc, left, top, right-left, bottom-top);
  2225. X    XSetForeground(_wd, gc, fg);
  2226. X}
  2227. X
  2228. X/* Invert the bits in the given rectangle.
  2229. X   (This uses _winvert because this function is often used internally.) */
  2230. X
  2231. Xvoid
  2232. Xwinvert(left, top, right, bottom)
  2233. X{
  2234. X    _wtrace(7, "winvert(left=%d, top=%d, right=%d, bottom=%d)",
  2235. X        left, top, right, bottom);
  2236. X    
  2237. X    if (left >= right || top >= bottom)
  2238. X        return;
  2239. X    
  2240. X    _winvert(wid, gc, left, top, right-left, bottom-top);
  2241. X}
  2242. X
  2243. X/* Paint a given rectangle black */
  2244. X
  2245. Xvoid
  2246. Xwpaint(left, top, right, bottom)
  2247. X{
  2248. X    _wtrace(7, "wpaint(left=%d, top=%d, right=%d, bottom=%d)",
  2249. X        left, top, right, bottom);
  2250. X    
  2251. X    if (left >= right || top >= bottom)
  2252. X        return;
  2253. X    
  2254. X    XFillRectangle(_wd, wid, gc, left, top, right-left, bottom-top);
  2255. X}
  2256. X
  2257. X/* Shade a given area; this should add a lighter or darker raster
  2258. X   depending on the darkness percentage (0 = no raster, 100 = black) */
  2259. X
  2260. Xvoid
  2261. Xwshade(left, top, right, bottom, percent)
  2262. X{
  2263. X    _wtrace(7, "wshade(left=%d, top=%d, right=%d, bottom=%d, percent=%d)",
  2264. X        left, top, right, bottom, percent);
  2265. X    
  2266. X    if (left >= right || top >= bottom)
  2267. X        return;
  2268. X    
  2269. X    /* For now, implement this as wpaint for shade percentages > 0 */
  2270. X    if (percent > 0)
  2271. X        wpaint(left, top, right, bottom);
  2272. X}
  2273. X
  2274. X/* Draw a circle with given center and radius */
  2275. X
  2276. Xvoid
  2277. Xwdrawcircle(h, v, radius)
  2278. X    int h, v;
  2279. X    int radius;
  2280. X{
  2281. X    _wtrace(7, "wdrawcircle(h=%d, v=%d, radius=%d)", h, v, radius);
  2282. X    XDrawArc(_wd, wid, gc, h-radius, v-radius, 2*radius, 2*radius,
  2283. X        0, 360*64);
  2284. X}
  2285. X
  2286. X/* Draw an elliptical arc.
  2287. X   The begin and end angles are specified in degrees (I'm not sure this
  2288. X   is a good idea, but I don't like X's degrees*64 either...).
  2289. X   The arc is drawn counter-clockwise; 0 degrees is 3 o'clock.
  2290. X   wdrawcircle is equivalent to wdrawarc(h, v, radius, radius, 0, 360). */
  2291. X
  2292. Xvoid
  2293. Xwdrawelarc(h, v, hhalf, vhalf, angle1, angle2)
  2294. X    int h, v;        /* Center */
  2295. X    int hhalf, vhalf;    /* Half axes */
  2296. X    int angle1, angle2;    /* Begin, end angle */
  2297. X{
  2298. X    _wtrace(7, "wdrawelarc(%d, %d, %d, %d, %d, %d)",
  2299. X        h, v, hhalf, vhalf, angle1, angle2);
  2300. X    XDrawArc(_wd, wid, gc, h-hhalf, v-vhalf, 2*hhalf, 2*vhalf,
  2301. X        angle1*64, angle2*64);
  2302. X}
  2303. X
  2304. X/* Clip drawing output to a rectangle. */
  2305. X
  2306. Xvoid
  2307. Xwcliprect(left, top, right, bottom)
  2308. X    int left, top, right, bottom;
  2309. X{
  2310. X    XRectangle clip;
  2311. X    
  2312. X    _wtrace(7, "wcliprect(%d, %d, %d, %d)", left, top, right, bottom);
  2313. X    clip.x = left;
  2314. X    clip.y = top;
  2315. X    clip.width = right-left;
  2316. X    clip.height = bottom-top;
  2317. X    XSetClipRectangles(_wd, gc, 0, 0, &clip, 1, Unsorted);
  2318. X}
  2319. X
  2320. X/* Cancel any clipping in effect. */
  2321. X
  2322. Xvoid
  2323. Xwnoclip()
  2324. X{
  2325. X    XSetClipMask(_wd, gc, None);
  2326. X}
  2327. END_OF_FILE
  2328. if test 7803 -ne `wc -c <'Ports/x11/draw.c'`; then
  2329.     echo shar: \"'Ports/x11/draw.c'\" unpacked with wrong size!
  2330. fi
  2331. # end of 'Ports/x11/draw.c'
  2332. fi
  2333. echo shar: End of archive 11 \(of 19\).
  2334. cp /dev/null ark11isdone
  2335. MISSING=""
  2336. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ; do
  2337.     if test ! -f ark${I}isdone ; then
  2338.     MISSING="${MISSING} ${I}"
  2339.     fi
  2340. done
  2341. if test "${MISSING}" = "" ; then
  2342.     echo You have unpacked all 19 archives.
  2343.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2344. else
  2345.     echo You still need to unpack the following archives:
  2346.     echo "        " ${MISSING}
  2347. fi
  2348. ##  End of shell archive.
  2349. exit 0
  2350.