home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / games / xmille.zip / XMILLE4.4 < prev   
Text File  |  1987-07-05  |  43KB  |  1,815 lines

  1. Article 46 of comp.sources.games:
  2. Path: ncrcce!rd1632!ncrlnk!ncrcae!ece-csc!mcnc!seismo!rochester!cornell!uw-beaver!tektronix!tekgen!tekred!games-request
  3. From: games-request@tekred.TEK.COM
  4. Newsgroups: comp.sources.games
  5. Subject: v01i072:  xmille - mille bournes game for X-windows, Part04/04
  6. Message-ID: <1365@tekred.TEK.COM>
  7. Date: 2 Jul 87 17:21:38 GMT
  8. Sender: billr@tekred.TEK.COM
  9. Lines: 1801
  10. Approved: billr@tekred.TEK.COM
  11.  
  12. Submitted by: keithp@copper.TEK.COM (Keith Packard)
  13. Comp.sources.games: Volume 1, Issue 72
  14. Archive-name: xmille/Part04
  15.  
  16.     [I slipped up and somehow missed the contents of the control
  17.      sub-directory, so here is Part 4 of 3 :-) of xmille.
  18.      On another note, I errored r.e. the Expires: line (that's
  19.      what I get for not reading the man page myself) - it has
  20.      been removed.  Sorry for any inconvenience.    -br]
  21.  
  22. #! /bin/sh
  23. # This is a shell archive.  Remove anything before this line, then unpack
  24. # it by saving it into a file and typing "sh file".  To overwrite existing
  25. # files, type "sh file -c".  You can also feed this as standard input via
  26. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  27. # will see the following message at the end:
  28. #        "End of archive 4 (of 4)."
  29. # Contents:  control control/Makefile control/affirm.c control/button.c
  30. #   control/co_class.h control/control.h control/dispatch.c
  31. #   control/init.c control/prompted.c control/scrollbar.c
  32. #   control/test.c
  33. # Wrapped by billr@tekred on Thu Jul  2 10:16:22 1987
  34. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  35. if test ! -d control ; then
  36.     echo shar: Creating directory \"control\"
  37.     mkdir control
  38. fi
  39. if test -f control/Makefile -a "${1}" != "-c" ; then 
  40.   echo shar: Will not over-write existing file \"control/Makefile\"
  41. else
  42. echo shar: Extracting \"control/Makefile\" \(324 characters\)
  43. sed "s/^X//" >control/Makefile <<'END_OF_control/Makefile'
  44. XHDRS =    control.h co_class.h
  45. X
  46. XOFILES =    button.o scrollbar.o init.o affirm.o dispatch.o prompted.o
  47. X
  48. XSRCCOMMON =    button.c scrollbar.c init.c affirm.c dispatch.c prompted.c
  49. X
  50. Xcontrol.a : $(OFILES)
  51. X    ar cr $@ $?
  52. X    ranlib $@
  53. X
  54. Xtest: test.o $(OFILES)
  55. X    $(CC) -o $@ test.o $(OFILES) -lX
  56. X
  57. Xcontrol.o : $(OFILES)
  58. X    $(LD) -r -o $@ $(OFILES)
  59. X
  60. END_OF_control/Makefile
  61. if test 324 -ne `wc -c <control/Makefile`; then
  62.     echo shar: \"control/Makefile\" unpacked with wrong size!
  63. fi
  64. # end of overwriting check
  65. fi
  66. if test -f control/affirm.c -a "${1}" != "-c" ; then 
  67.   echo shar: Will not over-write existing file \"control/affirm.c\"
  68. else
  69. echo shar: Extracting \"control/affirm.c\" \(2535 characters\)
  70. sed "s/^X//" >control/affirm.c <<'END_OF_control/affirm.c'
  71. X/*
  72. X * affirm.c
  73. X *
  74. X * affirm an action (yes/no)
  75. X */
  76. X
  77. X# include    <X/Xlib.h>
  78. X# include    "control.h"
  79. X# include    "co_class.h"
  80. X# include    <sys/time.h>
  81. X# include    <assert.h>
  82. X
  83. X/*
  84. X *    affirm window on screen
  85. X */
  86. X
  87. X# define AFFIRM_Y    350
  88. X# define AFFIRM_X    200
  89. X# define AFFIRM_HP    50    /* padding */
  90. X# define MIN_AFFIRM_W    (CANCEL_X + 80)
  91. X# define LABEL_Y    25
  92. X
  93. X# define OK_X        (10)
  94. X# define OK_Y        (AFFIRM_HP)
  95. X# define CANCEL_X    (OK_X + 100)
  96. X# define CANCEL_Y    (OK_Y)
  97. X
  98. X# define TEXT_OFF    5
  99. X
  100. Xextern int    co_inited;
  101. Xstatic char    *label;
  102. Xstatic int    affirm_h, affirm_w, label_x;
  103. Xstatic Window    affirm, ok, cancel;
  104. X
  105. Xstatic int    OKstate, CANCELstate;
  106. X
  107. Xint
  108. Xco_affirm(title)
  109. Xchar *title;
  110. X{
  111. X    XEvent        rep;
  112. X    int        state, affirm_x;
  113. X    int        label_w;
  114. X    int        co_OKstate (), co_CANCELstate (), co_affirmEvent (), CmanageButton ();
  115. X    int        mask;
  116. X
  117. X    if (!co_inited)
  118. X        co_init();
  119. X    label = title;
  120. X    label_w = XQueryWidth(label, co_font->id);
  121. X
  122. X    if (MIN_AFFIRM_W+10 >= label_w)
  123. X        affirm_w = MIN_AFFIRM_W+10;
  124. X    else
  125. X        affirm_w = label_w + 10;
  126. X
  127. X    OKstate = 0;
  128. X    CANCELstate = 0;
  129. X    label_x = affirm_w / 2 - label_w / 2;
  130. X    affirm_h = CANCEL_Y + 60;
  131. X    affirm_x = AFFIRM_X - affirm_w/2;
  132. X    affirm = XCreateWindow (RootWindow, affirm_x, AFFIRM_Y,
  133. X            affirm_w, affirm_h, 1, co_border, co_background);
  134. X    ok = CmapButton (affirm, OK_X, OK_Y, co_OK, co_OKstate);
  135. X    cancel = CmapButton (affirm, CANCEL_X, CANCEL_Y, co_CANCEL, co_CANCELstate);
  136. X    bindEvent (affirm, ExposeWindow, co_affirmEvent);
  137. X    bindEvent (ok, ExposeWindow|ButtonPressed|ButtonReleased|
  138. X            LeftDownMotion|RightDownMotion|MiddleDownMotion|LeaveWindow,
  139. X            CmanageButton);
  140. X    bindEvent (cancel, ExposeWindow|ButtonPressed|ButtonReleased|
  141. X            LeftDownMotion|RightDownMotion|MiddleDownMotion|LeaveWindow,
  142. X            CmanageButton);
  143. X    XMapWindow (affirm);
  144. X
  145. X    while (!OKstate && !CANCELstate) {
  146. X        dispatch ();
  147. X    }
  148. X
  149. X    unbindEvent (affirm, ExposeWindow);
  150. X    unbindEvent (ok, ExposeWindow|ButtonPressed|ButtonReleased|
  151. X            LeftDownMotion|RightDownMotion|MiddleDownMotion|LeaveWindow);
  152. X    unbindEvent (cancel, ExposeWindow|ButtonPressed|ButtonReleased|
  153. X            LeftDownMotion|RightDownMotion|MiddleDownMotion|LeaveWindow);
  154. X    XUnmapWindow (affirm);
  155. X    CunmapButton (cancel);
  156. X    CunmapButton (ok);
  157. X    XDestroyWindow (affirm);
  158. X    if (CANCELstate)
  159. X        return 0;
  160. X    if (OKstate)
  161. X        return 1;
  162. X}
  163. X
  164. Xco_affirmEvent (rep)
  165. XXEvent    *rep;
  166. X{
  167. X    switch (rep->type) {
  168. X    case ExposeWindow:
  169. X        redisplayLabel ();
  170. X    }
  171. X}
  172. X
  173. Xco_OKstate (n)
  174. X{
  175. X    OKstate = 1;
  176. X}
  177. X
  178. Xco_CANCELstate (n)
  179. X{
  180. X    CANCELstate = 1;
  181. X}
  182. X
  183. Xstatic
  184. XredisplayLabel ()
  185. X{
  186. X    XText (affirm, label_x, LABEL_Y, label, strlen (label), co_font->id,
  187. X         co_fore, co_back);
  188. X    XFlush ();
  189. X}
  190. END_OF_control/affirm.c
  191. if test 2535 -ne `wc -c <control/affirm.c`; then
  192.     echo shar: \"control/affirm.c\" unpacked with wrong size!
  193. fi
  194. # end of overwriting check
  195. fi
  196. if test -f control/button.c -a "${1}" != "-c" ; then 
  197.   echo shar: Will not over-write existing file \"control/button.c\"
  198. else
  199. echo shar: Extracting \"control/button.c\" \(4619 characters\)
  200. sed "s/^X//" >control/button.c <<'END_OF_control/button.c'
  201. X/*
  202. X *    button.c
  203. X */
  204. X
  205. X# include    <X/Xlib.h>
  206. X# include    "control.h"
  207. X
  208. Xstruct button {
  209. X    Button    button;
  210. X    int    width, height;
  211. X    int    x, y;
  212. X    int    font;
  213. X    int    forecolor, backcolor;
  214. X    Pixmap    background;
  215. X    int    borderwidth;
  216. X    int    vcount;
  217. X    Vertex    *vlist;
  218. X    char    *text;
  219. X};
  220. X
  221. Xstruct perwindow {
  222. X    struct button    *b;
  223. X    Window        wd;
  224. X    int        (*notify)();
  225. X    int        state;
  226. X};
  227. X
  228. Xstatic XAssocTable    *assocTable;
  229. Xstatic XAssocTable    *perwindowTable;
  230. Xextern XAssocTable    *XCreateAssocTable();
  231. Xextern char        *XLookUpAssoc();
  232. Xstatic int        nextButton;
  233. X
  234. XButton
  235. XCcreateButton (font, text, width, forecolor, backcolor, borderwidth)
  236. XFontInfo    *font;
  237. Xchar        *text;
  238. Xint        forecolor, backcolor;
  239. X{
  240. X    char        *malloc ();
  241. X    struct button    *b;
  242. X    int        round, off;
  243. X    int        hround;
  244. X    int        twidth;
  245. X    
  246. X    if (!assocTable)
  247. X        assocTable = XCreateAssocTable (64);
  248. X    b = (struct button *) malloc (sizeof (struct button));
  249. X    b->button = nextButton;
  250. X    XMakeAssoc (assocTable, nextButton++, (char *) b);
  251. X    twidth = XQueryWidth (text, font->id);
  252. X    if (width <= 0)
  253. X        b->width = twidth + font->width * 2;
  254. X    else
  255. X        b->width = width;
  256. X    b->height = font->height * 2;
  257. X    b->x = b->width / 2 - twidth / 2;
  258. X    b->y = font->height/2;
  259. X    b->font = font->id;
  260. X    b->text = text;
  261. X    b->forecolor = forecolor;
  262. X    b->backcolor = backcolor;
  263. X    b->background = XMakeTile (backcolor);
  264. X    b->borderwidth = borderwidth;
  265. X    b->vcount = 9;
  266. X    b->vlist = (Vertex *) malloc (sizeof (Vertex) * 9);
  267. X
  268. X    round = b->height / 8;
  269. X    off = borderwidth;
  270. X
  271. X    b->vlist[0].x = round;
  272. X    b->vlist[0].y = 0;
  273. X    b->vlist[0].flags = 0;
  274. X
  275. X    b->vlist[1].x = (b->width - off) - round;
  276. X    b->vlist[1].y = 0;
  277. X    b->vlist[1].flags = 0;
  278. X
  279. X    b->vlist[2].x = (b->width - off);
  280. X    b->vlist[2].y = round;
  281. X    b->vlist[2].flags = 0;
  282. X
  283. X    b->vlist[3].x = (b->width - off);
  284. X    b->vlist[3].y = (b->height - off) - round;
  285. X    b->vlist[3].flags = 0;
  286. X
  287. X    b->vlist[4].x = (b->width - off) - round;
  288. X    b->vlist[4].y = (b->height - off);
  289. X    b->vlist[4].flags = 0;
  290. X
  291. X    b->vlist[5].x = round;
  292. X    b->vlist[5].y = (b->height - off);
  293. X    b->vlist[5].flags = 0;
  294. X
  295. X    b->vlist[6].x = 0;
  296. X    b->vlist[6].y = (b->height - off) - round;
  297. X    b->vlist[6].flags = 0;
  298. X
  299. X    b->vlist[7].x = 0;
  300. X    b->vlist[7].y = round;
  301. X    b->vlist[7].flags = 0;
  302. X
  303. X    b->vlist[8].x = round;
  304. X    b->vlist[8].y = 0;
  305. X    b->vlist[8].flags = 0;
  306. X
  307. X    return b->button;
  308. X}
  309. X
  310. XWindow
  311. XCmapButton (parent, x, y, button, notify)
  312. XWindow    parent;
  313. Xint    x, y;
  314. XButton    button;
  315. Xint    (*notify)();
  316. X{
  317. X    struct button        *b;
  318. X    struct perwindow    *p;
  319. X    Window            w;
  320. X
  321. X    b = (struct button *) XLookUpAssoc (assocTable, button);
  322. X    if (!b)
  323. X        return 0;
  324. X    w = XCreateWindow (parent, x, y, b->width, b->height,
  325. X        0, 0, b->background);
  326. X    if (!w)
  327. X        return 0;
  328. X    XMapWindow (w);
  329. X    if (!perwindowTable)
  330. X        perwindowTable = XCreateAssocTable (64);
  331. X    p = (struct perwindow *) malloc (sizeof (struct perwindow));
  332. X    XMakeAssoc (perwindowTable, w, (char *) p);
  333. X    p->b = b;
  334. X    p->wd = w;
  335. X    p->notify = notify;
  336. X    p->state = 0;
  337. X    buttonOff (w, b, p);
  338. X    return w;
  339. X}
  340. X
  341. XCunmapButton (w)
  342. XWindow    w;
  343. X{
  344. X    struct button    *b;
  345. X    struct perwindow    *p;
  346. X
  347. X    p = (struct perwindow *) XLookUpAssoc (perwindowTable, w);
  348. X    if (!p)
  349. X        return 0;
  350. X    XDeleteAssoc (perwindowTable, w);
  351. X    free (p);
  352. X    XDestroyWindow (w);
  353. X    return 1;
  354. X}
  355. X
  356. XCmanageButton (rep)
  357. XXEvent    *rep;
  358. X{
  359. X    struct perwindow    *p;
  360. X    struct button        *b;
  361. X    XMouseMovedEvent    *me;
  362. X    Window            w;
  363. X
  364. X    w = rep->window;
  365. X    p = (struct perwindow *) XLookUpAssoc (perwindowTable, w);
  366. X    if (!p)
  367. X        return 0;
  368. X    b = p->b;
  369. X    switch (rep->type) {
  370. X    case ExposeWindow:
  371. X        if (p->state)
  372. X            buttonOn (w, b, p);
  373. X        else
  374. X            buttonOff (w, b, p);
  375. X        break;
  376. X    case ButtonPressed:
  377. X        buttonOn (w, b, p);
  378. X        p->state = 1;
  379. X        break;
  380. X    case ButtonReleased:
  381. X        if (p->state)
  382. X            p->notify (w);
  383. X        p->state = 0;
  384. X        break;
  385. X    case MouseMoved:
  386. X        me = (XMouseMovedEvent *) rep;
  387. X        if (me->x < 0 || me->x > b->width ||
  388. X            me->y < 0 || me->y > b->height)
  389. X        if (p->state) {
  390. X            buttonOff (w, b, p);
  391. X            p->state = 0;
  392. X        }
  393. X        break;
  394. X    case LeaveWindow:
  395. X        if (p->state) {
  396. X            buttonOff (w, b, p);
  397. X            p->state = 0;
  398. X        }
  399. X        break;
  400. X    }
  401. X}
  402. X
  403. XCredrawButton (w)
  404. XWindow        w;
  405. X{
  406. X    struct perwindow    *p;
  407. X    struct button        *b;
  408. X
  409. X    p = (struct perwindow *) XLookUpAssoc (perwindowTable, w);
  410. X    if (!p)
  411. X        return 0;
  412. X    b = p->b;
  413. X    buttonOff (w, b, p);
  414. X}
  415. X
  416. Xstatic
  417. XbuttonOn (w, b)
  418. XWindow    w;
  419. Xstruct button    *b;
  420. X{
  421. X    XDrawFilled (w, b->vlist, b->vcount, b->forecolor, GXcopy, AllPlanes);
  422. X    buttonText (w, b, b->backcolor, b->forecolor);
  423. X}
  424. X    
  425. Xstatic
  426. XbuttonOff (w, b)
  427. XWindow    w;
  428. Xstruct button    *b;
  429. X{
  430. X    XPixSet (w, 0, 0, b->width, b->height, b->backcolor);
  431. X    XDraw (w, b->vlist, b->vcount, b->borderwidth, b->borderwidth,
  432. X        b->forecolor, GXcopy, AllPlanes);
  433. X    buttonText (w, b, b->forecolor, b->backcolor);
  434. X}
  435. X
  436. Xstatic
  437. XbuttonText (w, b, fore, back)
  438. XWindow    w;
  439. Xstruct button    *b;
  440. Xint    fore, back;
  441. X{
  442. X    XText (w, b->x, b->y, b->text, strlen (b->text), b->font, fore, back);
  443. X}
  444. END_OF_control/button.c
  445. if test 4619 -ne `wc -c <control/button.c`; then
  446.     echo shar: \"control/button.c\" unpacked with wrong size!
  447. fi
  448. # end of overwriting check
  449. fi
  450. if test -f control/co_class.h -a "${1}" != "-c" ; then 
  451.   echo shar: Will not over-write existing file \"control/co_class.h\"
  452. else
  453. echo shar: Extracting \"control/co_class.h\" \(282 characters\)
  454. sed "s/^X//" >control/co_class.h <<'END_OF_control/co_class.h'
  455. X/*
  456. X *    object classes used by co routines - private to co!
  457. X */
  458. X
  459. Xextern Button        co_OK, co_CANCEL, co_NEW;
  460. Xextern Scrollbar    co_SCROLL_LEFT_GUI, co_SCROLL_BOTTOM_GUI, co_SCROLL_LEFT_MENU;
  461. Xextern FontInfo        *co_font;
  462. Xextern int        co_fore, co_back;
  463. Xextern Pixmap        co_background, co_border;
  464. END_OF_control/co_class.h
  465. if test 282 -ne `wc -c <control/co_class.h`; then
  466.     echo shar: \"control/co_class.h\" unpacked with wrong size!
  467. fi
  468. # end of overwriting check
  469. fi
  470. if test -f control/control.h -a "${1}" != "-c" ; then 
  471.   echo shar: Will not over-write existing file \"control/control.h\"
  472. else
  473. echo shar: Extracting \"control/control.h\" \(849 characters\)
  474. sed "s/^X//" >control/control.h <<'END_OF_control/control.h'
  475. X/*
  476. X *    control.h
  477. X *
  478. X *    defines for control manager
  479. X */
  480. X
  481. X# define CONTROL_BUTTON    0        /* named button */
  482. X# define CONTROL_SCROLL    1        /* scroll bar */
  483. X# define CONTROL_RADIO    2        /* radio buttons */
  484. X# define CONTROL_CHECK    3        /* check boxes */
  485. X# define CONTROL_SIZE    4        /* resize box */
  486. X# define CONTROL_EDIT    5        /* text edit box */
  487. X
  488. Xtypedef int    Button;
  489. X
  490. Xtypedef int    Check;
  491. X
  492. Xtypedef int    Editbox;
  493. X
  494. X# define EDIT_VOID    0
  495. X# define EDIT_RETURN    1
  496. X
  497. Xtypedef int    Scrollbar;
  498. X
  499. X# define SCROLL_LEFT    0
  500. X# define SCROLL_TOP    1
  501. X# define SCROLL_RIGHT    2
  502. X# define SCROLL_BOTTOM    3
  503. X
  504. X# define SCROLLWIDTH    25
  505. X
  506. X# define SCROLL_UP_BUTTON    -1
  507. X# define SCROLL_DOWN_BUTTON    -2
  508. X# define SCROLL_UP_AREA        -3
  509. X# define SCROLL_DOWN_AREA    -4
  510. X# define SCROLL_BUTTON_RELEASE    -5
  511. X
  512. X# define SCROLL_EVENTS    (ButtonPressed|ButtonReleased|ExposeWindow| \
  513. X             RightDownMotion|LeftDownMotion|MiddleDownMotion)
  514. END_OF_control/control.h
  515. if test 849 -ne `wc -c <control/control.h`; then
  516.     echo shar: \"control/control.h\" unpacked with wrong size!
  517. fi
  518. # end of overwriting check
  519. fi
  520. if test -f control/dispatch.c -a "${1}" != "-c" ; then 
  521.   echo shar: Will not over-write existing file \"control/dispatch.c\"
  522. else
  523. echo shar: Extracting \"control/dispatch.c\" \(1615 characters\)
  524. sed "s/^X//" >control/dispatch.c <<'END_OF_control/dispatch.c'
  525. X/*
  526. X * dispatch.c
  527. X *
  528. X * pass out X events to appropriate recipiants
  529. X */
  530. X
  531. X# include    <X/Xlib.h>
  532. X
  533. Xstruct eventGroup {
  534. X    struct eventGroup    *prev;
  535. X    Window            w;
  536. X    unsigned long        e;
  537. X    int            (*f)();
  538. X};
  539. X
  540. Xstruct eventGroup    *eventStack, *allocGroup();
  541. X
  542. XbindEvent (window, eventMask, func)
  543. XWindow        window;
  544. Xunsigned long    eventMask;
  545. Xint        (*func)();
  546. X{
  547. X    struct eventGroup    *g;
  548. X    unsigned long        allEvents;
  549. X
  550. X    g = allocGroup ();
  551. X    g->w = window;
  552. X    g->e = eventMask;
  553. X    g->f = func;
  554. X    g->prev = eventStack;
  555. X    eventStack = g;
  556. X    allEvents = 0;
  557. X    for (g = eventStack; g; g = g->prev)
  558. X        if (g->w == window)
  559. X            allEvents |= g->e;
  560. X    XSelectInput (window, allEvents);
  561. X}
  562. X
  563. XunbindEvent (window, eventMask)
  564. XWindow        window;
  565. Xunsigned long    eventMask;
  566. X{
  567. X    struct eventGroup    *g, *n, *p;
  568. X    unsigned long        t;
  569. X    unsigned long        remainingEvents;
  570. X
  571. X    n = 0;
  572. X    remainingEvents = 0;
  573. X    for (g = eventStack; g; g = p) {
  574. X        p = g->prev;
  575. X        if (g->w == window) {
  576. X             if (g->e & eventMask) {
  577. X                t = eventMask;
  578. X                eventMask &= ~g->e;
  579. X                g->e &= ~t;
  580. X            }
  581. X            remainingEvents |= g->e;
  582. X            if (g->e == 0) {
  583. X                if (n)
  584. X                    n->prev = p;
  585. X                else
  586. X                    eventStack = p;
  587. X                freeGroup (g);
  588. X            }
  589. X        }
  590. X    }
  591. X    XSelectInput (window, remainingEvents);
  592. X}
  593. X
  594. XsendEvent (rep)
  595. XXEvent    *rep;
  596. X{
  597. X    struct eventGroup    *g;
  598. X
  599. X    for (g = eventStack; g; g = g->prev) {
  600. X        if (rep->window == g->w && (rep->type & g->e)) {
  601. X            g->f (rep);
  602. X            return;
  603. X        }
  604. X    }
  605. X}
  606. X
  607. Xdispatch ()
  608. X{
  609. X    XEvent    event;
  610. X
  611. X    XNextEvent (&event);
  612. X    sendEvent (&event);
  613. X}
  614. X
  615. Xstatic struct eventGroup *
  616. XallocGroup ()
  617. X{
  618. X    char    *malloc ();
  619. X
  620. X    return (struct eventGroup *) malloc (sizeof (struct eventGroup));
  621. X}
  622. X
  623. XfreeGroup (g)
  624. Xstruct eventGroup    *g;
  625. X{
  626. X    free ((char *) g);
  627. X}
  628. END_OF_control/dispatch.c
  629. if test 1615 -ne `wc -c <control/dispatch.c`; then
  630.     echo shar: \"control/dispatch.c\" unpacked with wrong size!
  631. fi
  632. # end of overwriting check
  633. fi
  634. if test -f control/init.c -a "${1}" != "-c" ; then 
  635.   echo shar: Will not over-write existing file \"control/init.c\"
  636. else
  637. echo shar: Extracting \"control/init.c\" \(1076 characters\)
  638. sed "s/^X//" >control/init.c <<'END_OF_control/init.c'
  639. X/*
  640. X * init.c
  641. X */
  642. X
  643. X# include    <X/Xlib.h>
  644. X# include    "control.h"
  645. X# include    <assert.h>
  646. X# include    "co_class.h"
  647. X# include    <stdio.h>
  648. X
  649. XButton        co_OK, co_CANCEL, co_NEW;
  650. XButton        co_QUIT, co_SAVE;
  651. XScrollbar    co_SCROLL_LEFT_MENU, co_SCROLL_BOTTOM_MENU;
  652. XFontInfo    *co_font;
  653. Xint        co_fore, co_back;
  654. XPixmap        co_background, co_border;
  655. Xint        co_inited;
  656. X
  657. Xco_init ()
  658. X{
  659. X    Color    hard_def, exact_def;
  660. X/*    ui_getcolors (&co_fore, &co_back, &co_fore, &co_back); */
  661. X    XGetColor ("black", &hard_def, &exact_def);
  662. X    co_fore = hard_def.pixel;
  663. X    XGetColor ("white", &hard_def, &exact_def);
  664. X    co_back = hard_def.pixel;
  665. X
  666. X    co_background = XMakeTile (co_back);
  667. X    co_border = XMakeTile (co_fore);
  668. X    co_font = XOpenFont ("timrom12b");
  669. X    assert (co_font);
  670. X
  671. X    co_OK = CcreateButton (co_font, "OK", 75, co_fore, co_back, 1);
  672. X    co_CANCEL = CcreateButton (co_font, "NO", 75, co_fore, co_back, 1);
  673. X    co_NEW = CcreateButton (co_font, "NEW", 75, co_fore, co_back, 1);
  674. X    co_QUIT = CcreateButton (co_font, "QUIT", 75, co_fore, co_back, 1);
  675. X    co_SAVE = CcreateButton (co_font, "SAVE", 75, co_fore, co_back, 1);
  676. X    co_inited = 1;
  677. X    return 0;
  678. X}
  679. END_OF_control/init.c
  680. if test 1076 -ne `wc -c <control/init.c`; then
  681.     echo shar: \"control/init.c\" unpacked with wrong size!
  682. fi
  683. # end of overwriting check
  684. fi
  685. if test -f control/prompted.c -a "${1}" != "-c" ; then 
  686.   echo shar: Will not over-write existing file \"control/prompted.c\"
  687. else
  688. echo shar: Extracting \"control/prompted.c\" \(4097 characters\)
  689. sed "s/^X//" >control/prompted.c <<'END_OF_control/prompted.c'
  690. X/*
  691. X * prompted.c
  692. X *
  693. X * get a string of text
  694. X */
  695. X
  696. X# include    <X/Xlib.h>
  697. X# include    "control.h"
  698. X# include    "co_class.h"
  699. X# include    <sys/time.h>
  700. X# include    <assert.h>
  701. X
  702. X/*
  703. X *    prompted window on screen
  704. X */
  705. X
  706. X# define PROMPTED_Y    350
  707. X# define PROMPTED_HP    50    /* padding */
  708. X# define MIN_PROMPTED_W    (TEXTBOX_X + TEXTBOX_W + 20)
  709. X# define TEXTBOX_X    (10)
  710. X# define TEXTBOX_Y    (PROMPTED_HP)
  711. X# define TEXTBOX_W    150
  712. X# define TEXTBOX_VP    (10)
  713. X# define LABEL_Y    25
  714. X
  715. X# define OK_X        (10)
  716. X# define OK_Y        (PROMPTED_HP * 2)
  717. X
  718. X# define TEXT_OFF    5
  719. X
  720. Xextern int    co_inited;
  721. Xstatic char    *label;
  722. Xstatic int    prompted_h, prompted_w, label_x;
  723. Xstatic Window    prompted, textbox, ok;
  724. Xstatic char    returnbuffer[256];
  725. Xstatic char    *retpointer;
  726. X
  727. Xstatic int    prompted_done;
  728. X
  729. Xchar *
  730. Xco_prompted(title)
  731. Xchar *title;
  732. X{
  733. X    XEvent        rep;
  734. X    int        state, prompted_x;
  735. X    int        label_w;
  736. X    int        co_OKstate (), co_promptedEvent (), CmanageButton (), textbox_event ();
  737. X    int        mask;
  738. X
  739. X    if (!co_inited)
  740. X        co_init();
  741. X    if (!co_font->widths)
  742. X        co_font->widths = XFontWidths (co_font->id);
  743. X    label = title;
  744. X    label_w = XQueryWidth(label, co_font->id);
  745. X
  746. X    if (MIN_PROMPTED_W+10 >= label_w)
  747. X        prompted_w = MIN_PROMPTED_W+10;
  748. X    else
  749. X        prompted_w = label_w + 10;
  750. X
  751. X    label_x = prompted_w / 2 - label_w / 2;
  752. X    prompted_h = OK_Y + 60;
  753. X    prompted_x = 512 - prompted_w/2;
  754. X    prompted = XCreateWindow (RootWindow, prompted_x, PROMPTED_Y,
  755. X            prompted_w, prompted_h, 1, co_border, co_background);
  756. X    ok = CmapButton (prompted, OK_X, OK_Y, co_OK, co_OKstate);
  757. X    textbox = XCreateWindow (prompted, TEXTBOX_X, TEXTBOX_Y,
  758. X            TEXTBOX_W, co_font->height + TEXTBOX_VP * 2, 1, co_border, co_background);
  759. X    bindEvent (prompted, ExposeWindow, co_promptedEvent);
  760. X    bindEvent (ok, ExposeWindow|ButtonPressed|ButtonReleased|
  761. X            LeftDownMotion|RightDownMotion|MiddleDownMotion|LeaveWindow,
  762. X            CmanageButton);
  763. X    bindEvent (textbox, ExposeWindow|KeyPressed, textbox_event);
  764. X    bindEvent (prompted, KeyPressed, textbox_event);
  765. X    XMapWindow (textbox);
  766. X    XMapWindow (prompted);
  767. X
  768. X    prompted_done = 0;
  769. X    retpointer = returnbuffer;
  770. X    *retpointer = '\0';
  771. X    while (!prompted_done) {
  772. X        dispatch ();
  773. X    }
  774. X
  775. X    unbindEvent (prompted, ExposeWindow);
  776. X    unbindEvent (textbox, ExposeWindow|KeyPressed);
  777. X    unbindEvent (prompted, KeyPressed);
  778. X    unbindEvent (ok, ExposeWindow|ButtonPressed|ButtonReleased|
  779. X            LeftDownMotion|RightDownMotion|MiddleDownMotion|LeaveWindow);
  780. X    XUnmapWindow (prompted);
  781. X    CunmapButton (ok);
  782. X    XDestroyWindow (textbox);
  783. X    XDestroyWindow (prompted);
  784. X    *retpointer = '\0';
  785. X    return returnbuffer;
  786. X}
  787. X
  788. Xstatic
  789. Xco_promptedEvent (rep)
  790. XXEvent    *rep;
  791. X{
  792. X    switch (rep->type) {
  793. X    case ExposeWindow:
  794. X        redisplayLabel ();
  795. X    }
  796. X}
  797. X
  798. Xstatic
  799. Xco_OKstate (n)
  800. X{
  801. X    prompted_done = 1;
  802. X}
  803. X
  804. Xstatic
  805. XredisplayLabel ()
  806. X{
  807. X    XText (prompted, label_x, LABEL_Y, label, strlen (label), co_font->id,
  808. X         co_fore, co_back);
  809. X    XFlush ();
  810. X}
  811. X
  812. Xstatic
  813. Xtextbox_event (rep)
  814. XXEvent    *rep;
  815. X{
  816. X    char    *buffer;
  817. X    int    count;
  818. X
  819. X    switch (rep->type) {
  820. X    case ExposeWindow:
  821. X        redisplayText ();
  822. X        break;
  823. X    case KeyPressed:
  824. X        buffer = XLookupMapping (rep, &count);
  825. X        while (!prompted_done && count--) {
  826. X            handle_char (*buffer++);
  827. X        }
  828. X        break;
  829. X    }
  830. X}
  831. X
  832. Xstatic
  833. Xhandle_char (c)
  834. X{
  835. X    switch (c) {
  836. X    case '\n':
  837. X    case '\r':
  838. X        *retpointer = '\0';
  839. X        prompted_done = 1;
  840. X        break;
  841. X    case '\b':
  842. X    case '\0177':
  843. X        if (retpointer > returnbuffer) {
  844. X            c = *--retpointer;
  845. X            *retpointer = '\0';
  846. X            draw_char (compute_width (returnbuffer), c, 0);
  847. X        }
  848. X        break;
  849. X    case '\030':
  850. X    case '\025':
  851. X        draw_string (returnbuffer, 0);
  852. X        retpointer = returnbuffer;
  853. X        *retpointer = '\0';
  854. X        break;
  855. X    default:
  856. X        *retpointer = '\0';
  857. X        draw_char (compute_width (returnbuffer), c, 1);
  858. X        *retpointer++ = c;
  859. X        *retpointer = '\0';
  860. X        break;
  861. X    }
  862. X}
  863. X
  864. Xstatic
  865. Xcompute_width (string)
  866. Xchar    *string;
  867. X{
  868. X    if (co_font->widths)
  869. X        return XStringWidth (string, co_font, 0, 0);
  870. X    else
  871. X        return XQueryWidth (string, co_font->id);
  872. X}
  873. X
  874. Xstatic
  875. Xdraw_char (pos, ch, on)
  876. X{
  877. X    XText (textbox, pos, TEXTBOX_VP, &ch, 1, co_font->id,
  878. X        on ? co_fore : co_back, co_back);
  879. X}
  880. X
  881. Xstatic
  882. Xdraw_string (string, on)
  883. Xchar    *string;
  884. X{
  885. X    XText (textbox, 0, TEXTBOX_VP, string, strlen(string), co_font->id,
  886. X        on ? co_fore : co_back, co_back);
  887. X}
  888. X
  889. Xstatic
  890. XredisplayText ()
  891. X{
  892. X    draw_string (returnbuffer, 1);
  893. X}
  894. END_OF_control/prompted.c
  895. if test 4097 -ne `wc -c <control/prompted.c`; then
  896.     echo shar: \"control/prompted.c\" unpacked with wrong size!
  897. fi
  898. # end of overwriting check
  899. fi
  900. if test -f control/scrollbar.c -a "${1}" != "-c" ; then 
  901.   echo shar: Will not over-write existing file \"control/scrollbar.c\"
  902. else
  903. echo shar: Extracting \"control/scrollbar.c\" \(17486 characters\)
  904. sed "s/^X//" >control/scrollbar.c <<'END_OF_control/scrollbar.c'
  905. X/*
  906. X *    scrollbar.c
  907. X */
  908. X
  909. X# include    <X/Xlib.h>
  910. X# include    "control.h"
  911. X
  912. Xstruct scrollbar {
  913. X    Scrollbar    scrollbar;
  914. X    int        forecolor, backcolor;
  915. X    int        orientation;
  916. X    int        borderwidth;
  917. X    Pixmap        border;
  918. X    Pixmap        background;
  919. X};
  920. X
  921. Xstruct perwindow {
  922. X    int            length;
  923. X    Window            parent;
  924. X    int            locatorpos;
  925. X    int            locatormille;
  926. X    int            locatormax;
  927. X    int            locatormaxmille;
  928. X    int            state;
  929. X    struct scrollbar    *class;
  930. X    int            (*notify)();
  931. X    int            (*onetrip)();
  932. X};
  933. X
  934. X/*
  935. X *    possible values of ->state
  936. X */    
  937. X
  938. X# define GENERAL        0
  939. X# define DRAGGING_LOCATOR    1
  940. X# define DOWN            2
  941. X# define DOWN_IN_DOWN_BOX    3
  942. X# define DOWN_IN_UP_BOX        4
  943. X
  944. Xstatic XAssocTable    *perwindowTable;
  945. X
  946. Xstatic XAssocTable    *assocTable;
  947. Xextern XAssocTable    *XCreateAssocTable();
  948. Xextern char        *XLookUpAssoc();
  949. Xstatic int        nextScrollbar;
  950. X
  951. X# define minpos(p)        (0)
  952. X# define maxpos(p)        ((p)->length - 2 * ARROWWIDTH)
  953. X# define milletopos(m,p)    ((m) * maxpos(p) / 1000)
  954. X# define postomille(l,p)    ((l) * 1000 / maxpos (p))
  955. X# define postoloc(l)        ((l) + ARROWWIDTH)
  956. X# define loctopos(l)        ((l) - ARROWWIDTH)
  957. X
  958. X# define ARROWHEIGHT    SCROLLWIDTH
  959. X# define ARROWWIDTH    SCROLLWIDTH
  960. X# define LOCATORWIDTH    SCROLLWIDTH / 3
  961. X
  962. Xstatic short arrowDownOff[50] = {
  963. X    0xffff, 0x01ff,
  964. X    0x0000, 0x0000,
  965. X    0x0000, 0x0000,
  966. X    0xff80, 0x0003,
  967. X    0x0080, 0x0002,
  968. X    0x0080, 0x0002,
  969. X    0x0080, 0x0002,
  970. X    0x0080, 0x0002,
  971. X    0x0080, 0x0002,
  972. X    0x0080, 0x0002,
  973. X    0x0080, 0x0002,
  974. X    0x00f8, 0x003e,
  975. X    0x0010, 0x0010,
  976. X    0x0020, 0x0008,
  977. X    0x0040, 0x0004,
  978. X    0x0080, 0x0002,
  979. X    0x0100, 0x0001,
  980. X    0x8200, 0x0000,
  981. X    0x4400, 0x0000,
  982. X    0x2800, 0x0000,
  983. X    0x1000, 0x0000,
  984. X    0x0000, 0x0000,
  985. X    0x0000, 0x0000,
  986. X    0x0000, 0x0000,
  987. X    0x0000, 0x0000,
  988. X};
  989. X
  990. Xstatic short arrowDownOn[50] = {
  991. X    0xffff, 0x01ff,
  992. X    0x0000, 0x0000,
  993. X    0x0000, 0x0000,
  994. X    0xff80, 0x0003,
  995. X    0xff80, 0x0003,
  996. X    0xff80, 0x0003,
  997. X    0xff80, 0x0003,
  998. X    0xff80, 0x0003,
  999. X    0xff80, 0x0003,
  1000. X    0xff80, 0x0003,
  1001. X    0xff80, 0x0003,
  1002. X    0xfff8, 0x003f,
  1003. X    0xfff0, 0x001f,
  1004. X    0xffe0, 0x000f,
  1005. X    0xffc0, 0x0007,
  1006. X    0xff80, 0x0003,
  1007. X    0xff00, 0x0001,
  1008. X    0xfe00, 0x0000,
  1009. X    0x7c00, 0x0000,
  1010. X    0x3800, 0x0000,
  1011. X    0x1000, 0x0000,
  1012. X    0x0000, 0x0000,
  1013. X    0x0000, 0x0000,
  1014. X    0x0000, 0x0000,
  1015. X    0x0000, 0x0000,
  1016. X};
  1017. X
  1018. Xstatic short arrowUpOff [50], arrowRightOff [50], arrowLeftOff [50];
  1019. Xstatic short arrowUpOn  [50], arrowRightOn  [50], arrowLeftOn  [50];
  1020. X
  1021. Xstatic Cursor    dragCursor;
  1022. Xstatic short    dragBits[16];
  1023. X
  1024. Xstatic int arrowsSet;
  1025. X
  1026. XScrollbar
  1027. XCcreateScrollbar (orientation, forecolor, backcolor,
  1028. X     borderwidth, border, background)
  1029. Xint    orientation;
  1030. Xint    forecolor, backcolor;
  1031. Xint    borderwidth;
  1032. XPixmap    border;
  1033. XPixmap    background;
  1034. X{
  1035. X    char            *malloc ();
  1036. X    struct scrollbar    *s;
  1037. X    
  1038. X    if (!assocTable)
  1039. X        assocTable = XCreateAssocTable (8);
  1040. X    if (!arrowsSet) {
  1041. X        setArrows();
  1042. X        arrowsSet = 1;
  1043. X    }
  1044. X    s = (struct scrollbar *) malloc (sizeof (struct scrollbar));
  1045. X    nextScrollbar++;
  1046. X    s->scrollbar = nextScrollbar;
  1047. X    XMakeAssoc (assocTable, nextScrollbar, (char *) s);
  1048. X    s->forecolor = forecolor;
  1049. X    s->backcolor = backcolor;
  1050. X    s->orientation = orientation;
  1051. X    s->borderwidth = borderwidth;
  1052. X    s->border = border;
  1053. X    s->background = background;
  1054. X    return s->scrollbar;
  1055. X}
  1056. X
  1057. XWindow
  1058. XCmapScrollbar (parent, scrollbar, notify, onetrip)
  1059. XWindow        parent;
  1060. XScrollbar    scrollbar;
  1061. Xint        (*notify)(), (*onetrip)();
  1062. X{
  1063. X    struct scrollbar    *s;
  1064. X    struct perwindow    *p;
  1065. X    Window            w;
  1066. X    int            x, y, width, height;
  1067. X    Window            grandParent;
  1068. X    Window            *siblings;
  1069. X    int            nsiblings;
  1070. X    
  1071. X    s = (struct scrollbar *) XLookUpAssoc (assocTable, scrollbar);
  1072. X    if (!s) {
  1073. X        printf ("scroll bar %d doesn't exist\n", scrollbar);
  1074. X        return 0;
  1075. X    }
  1076. X    if (!XQueryTree (parent, &grandParent, &nsiblings, &siblings)) {
  1077. X        printf ("can't get tree\n");
  1078. X        return 0;
  1079. X    }
  1080. X    if (siblings)
  1081. X        free (siblings);
  1082. X    if (!computePosition (parent, s, &x, &y, &width, &height))
  1083. X        return 0;
  1084. X    w = XCreateWindow (grandParent, x, y, width, height, s->borderwidth,
  1085. X        s->border, s->background);
  1086. X    XMapWindow (w);
  1087. X    if (!perwindowTable)
  1088. X        perwindowTable = XCreateAssocTable (64);
  1089. X    p = (struct perwindow *) malloc (sizeof (struct perwindow));
  1090. X    switch (s->orientation) {
  1091. X    case SCROLL_TOP:
  1092. X    case SCROLL_BOTTOM:
  1093. X        p->length = width;
  1094. X        break;
  1095. X    case SCROLL_RIGHT:
  1096. X    case SCROLL_LEFT:
  1097. X        p->length = height;
  1098. X        break;
  1099. X    }
  1100. X    p->state = GENERAL;
  1101. X    p->parent = parent;
  1102. X    p->class = s;
  1103. X    p->locatorpos = -1;
  1104. X    p->notify = notify;
  1105. X    p->onetrip = onetrip;
  1106. X    XMakeAssoc (perwindowTable, w, p);
  1107. X    drawArrows (w, s, p);
  1108. X    return w;
  1109. X}
  1110. X
  1111. XCunmapScrollbar (w)
  1112. XWindow        w;
  1113. X{
  1114. X    struct perwindow    *p;
  1115. X
  1116. X    p = (struct perwindow *) XLookUpAssoc (perwindowTable, w);
  1117. X    if (!p)
  1118. X        return 0;
  1119. X    XDeleteAssoc (perwindowTable, w);
  1120. X    free (p);
  1121. X    XDestroyWindow (w);
  1122. X    return 1;
  1123. X}
  1124. X
  1125. XCresizeScrollbar (w)
  1126. XWindow        w;
  1127. X{
  1128. X    struct perwindow    *p;
  1129. X    struct scrollbar    *s;
  1130. X    int            x, y, width, height;
  1131. X
  1132. X    p = (struct perwindow *) XLookUpAssoc (perwindowTable, w);
  1133. X    if (!p)
  1134. X        return 0;
  1135. X    s = p->class;
  1136. X    if (!computePosition (p->parent, s, &x, &y, &width, &height))
  1137. X        return 0;
  1138. X    XConfigureWindow (w, x, y, width, height);
  1139. X    switch (s->orientation) {
  1140. X    case SCROLL_TOP:
  1141. X    case SCROLL_BOTTOM:
  1142. X        p->length = width;
  1143. X        break;
  1144. X    case SCROLL_RIGHT:
  1145. X    case SCROLL_LEFT:
  1146. X        p->length = height;
  1147. X        break;
  1148. X    }
  1149. X    if (p->locatorpos >= 0)
  1150. X        p->locatorpos = milletopos (p->locatormille, p);
  1151. X    if (p->locatormax >= 0)
  1152. X        p->locatormax = milletopos (p->locatormaxmille, p);
  1153. X    return 1;
  1154. X}
  1155. X
  1156. XWindow
  1157. XCgetScrollbarParent (w)
  1158. XScrollbar    w;
  1159. X{
  1160. X    struct perwindow    *p;
  1161. X    p = (struct perwindow *) XLookUpAssoc (perwindowTable, w);
  1162. X    if (!p)
  1163. X        return 0;
  1164. X    return p->parent;
  1165. X}
  1166. X
  1167. XCredrawScrollbar (w)
  1168. XWindow        w;
  1169. X{
  1170. X    struct scrollbar    *s;
  1171. X    struct perwindow    *p;
  1172. X
  1173. X    p = (struct perwindow *) XLookUpAssoc (perwindowTable, w);
  1174. X    if (!p)
  1175. X        return 0;
  1176. X    s = p->class;
  1177. X    drawArrows (w, s, p);
  1178. X    moveLocator (w, s, p, p->locatorpos, p->locatormax);
  1179. X    return 1;
  1180. X}
  1181. X
  1182. XCsetScrollbarLocator (w, permillemin, permillemax)
  1183. XWindow        w;
  1184. Xint        permillemin, permillemax;
  1185. X{
  1186. X    struct perwindow    *p;
  1187. X    struct scrollbar    *s;
  1188. X
  1189. X    p = (struct perwindow *) XLookUpAssoc (perwindowTable, w);
  1190. X    if (!p)
  1191. X        return 0;
  1192. X    s = p->class;
  1193. X    if (permillemin < 0)
  1194. X        permillemin = 0;
  1195. X    if (permillemax > 1000)
  1196. X        permillemax = 1000;
  1197. X    moveLocator (w, s, p,
  1198. X        milletopos (permillemin, p),
  1199. X         milletopos (permillemax, p));
  1200. X    return 1;
  1201. X}
  1202. X
  1203. X# define NOWHERE        0
  1204. X# define IN_UP_BOX        1
  1205. X# define IN_DOWN_BOX        2
  1206. X# define IN_UP_AREA        3
  1207. X# define IN_DOWN_AREA        4
  1208. X# define IN_LOCATOR        5
  1209. X
  1210. X/*
  1211. X * used for dragging the locator around
  1212. X */
  1213. X
  1214. Xstatic int    downmouse;    /* mouse position at down click */
  1215. Xstatic int    downloc;    /* locator position at down click */
  1216. X
  1217. XCmanageScrollbar (rep)
  1218. XXEvent        *rep;
  1219. X{
  1220. X    struct perwindow    *p;
  1221. X    struct scrollbar    *s;
  1222. X    int            inwindow;
  1223. X    int            region;
  1224. X    XButtonEvent        *bevent;
  1225. X    XMouseMovedEvent    *mevent;
  1226. X    int            permille;
  1227. X    Window            w;
  1228. X
  1229. X    w = rep->window;
  1230. X    p = (struct perwindow *) XLookUpAssoc (perwindowTable, w);
  1231. X    if (!p)
  1232. X        return 0;
  1233. X    s = p->class;
  1234. X    switch (rep->type) {
  1235. X    case ExposeWindow:
  1236. X        CredrawScrollbar (w);
  1237. X        break;
  1238. X    case ButtonPressed:
  1239. X        switch (p->state) {
  1240. X        case GENERAL:
  1241. X            bevent = (XButtonEvent *) rep;
  1242. X            region = findRegion (s, p, bevent->x, bevent->y);
  1243. X            switch (region) {
  1244. X            case IN_LOCATOR:
  1245. X                p->state = DRAGGING_LOCATOR;
  1246. X                downloc = p->locatorpos;
  1247. X                switch (s->orientation) {
  1248. X                case SCROLL_TOP:
  1249. X                case SCROLL_BOTTOM:
  1250. X                    downmouse = bevent->x;
  1251. X                    break;
  1252. X                case SCROLL_LEFT:
  1253. X                case SCROLL_RIGHT:
  1254. X                    downmouse = bevent->y;
  1255. X                    break;
  1256. X                }
  1257. X                break;
  1258. X            case IN_UP_BOX:
  1259. X                p->state = DOWN_IN_UP_BOX;
  1260. X                highlightBox (w, s, p, p->state);
  1261. X                spinbutton (w, s, p, IN_UP_BOX);
  1262. X                break;
  1263. X            case IN_DOWN_BOX:
  1264. X                p->state = DOWN_IN_DOWN_BOX;
  1265. X                highlightBox (w, s, p, p->state);
  1266. X                spinbutton (w, s, p, IN_DOWN_BOX);
  1267. X                break;
  1268. X            case IN_DOWN_AREA:
  1269. X            case IN_UP_AREA:
  1270. X                p->state = DOWN;
  1271. X                switch (region) {
  1272. X                case IN_DOWN_AREA:
  1273. X                    p->notify (p->parent, SCROLL_DOWN_AREA);
  1274. X                    break;
  1275. X                case IN_UP_AREA:
  1276. X                    p->notify (p->parent, SCROLL_UP_AREA);
  1277. X                    break;
  1278. X                }
  1279. X            }
  1280. X        }
  1281. X        break;
  1282. X    case ButtonReleased:
  1283. X        switch (p->state) {        
  1284. X        case DRAGGING_LOCATOR:
  1285. X            p->state = GENERAL;
  1286. X            break;
  1287. X        case DOWN_IN_DOWN_BOX:
  1288. X        case DOWN_IN_UP_BOX:
  1289. X            unhighlightBox (w, s, p, p->state);
  1290. X        case DOWN:
  1291. X            p->state = GENERAL;
  1292. X            break;
  1293. X        }
  1294. X    case MouseMoved:
  1295. X        switch (p->state) {
  1296. X        case DRAGGING_LOCATOR:
  1297. X            p->notify (p->parent, updateLocator (w, s, p));
  1298. X            p->onetrip (p->parent);
  1299. X            break;
  1300. X        }
  1301. X        break;
  1302. X    }
  1303. X}
  1304. X
  1305. Xstatic
  1306. Xspinbutton (w, s, p, region)
  1307. XWindow            w;
  1308. Xstruct scrollbar    *s;
  1309. Xstruct perwindow    *p;
  1310. Xint            region;
  1311. X{
  1312. X    int    r;
  1313. X
  1314. X    r = region;
  1315. X    for (;;) {
  1316. X        switch (p->state) {
  1317. X        case DOWN_IN_UP_BOX:
  1318. X        case DOWN_IN_DOWN_BOX:
  1319. X            if (r != region) {
  1320. X                unhighlightBox (w, s, p, p->state);
  1321. X                p->state = GENERAL;
  1322. X                return;
  1323. X            }
  1324. X            switch (region) {
  1325. X            case IN_UP_BOX:
  1326. X                p->notify (p->parent, SCROLL_UP_BUTTON);
  1327. X                p->onetrip (p->parent);
  1328. X                break;
  1329. X            case IN_DOWN_BOX:
  1330. X                p->notify (p->parent, SCROLL_DOWN_BUTTON);
  1331. X                p->onetrip (p->parent);
  1332. X                break;
  1333. X            }
  1334. X            break;
  1335. X        default:
  1336. X            return;
  1337. X        }
  1338. X        r = checkMouseRegion (w, s, p);
  1339. X    }
  1340. X}
  1341. X
  1342. Xstatic
  1343. XfindRegion (s, p, x, y)
  1344. Xstruct scrollbar    *s;
  1345. Xstruct perwindow    *p;
  1346. Xint            x,y;
  1347. X{
  1348. X    int    loc;
  1349. X    switch (s->orientation) {
  1350. X    case SCROLL_TOP:
  1351. X    case SCROLL_BOTTOM:
  1352. X        if (y < 0 || SCROLLWIDTH <= y)
  1353. X            return NOWHERE;
  1354. X        loc = x;
  1355. X        break;
  1356. X    case SCROLL_LEFT:
  1357. X    case SCROLL_RIGHT:
  1358. X        if (x < 0 || SCROLLWIDTH <= x)
  1359. X            return NOWHERE;
  1360. X        loc = y;
  1361. X        break;
  1362. X    }
  1363. X    if (loc < 0 || loc >= p->length)
  1364. X        return NOWHERE;
  1365. X    if (loc <= ARROWWIDTH)
  1366. X        return IN_UP_BOX;
  1367. X    if (loc >= p->length - ARROWWIDTH)
  1368. X        return IN_DOWN_BOX;
  1369. X    if (loc < postoloc (p->locatorpos))
  1370. X        return IN_UP_AREA;
  1371. X    if (loc > postoloc (p->locatormax))
  1372. X        return IN_DOWN_AREA;
  1373. X    return IN_LOCATOR;
  1374. X}
  1375. X
  1376. Xstatic
  1377. XupdateLocator (w, s, p)
  1378. XWindow            w;
  1379. Xstruct scrollbar    *s;
  1380. Xstruct perwindow    *p;
  1381. X{
  1382. X    int    pos, loc;
  1383. X    int    subw, x, y;
  1384. X    int    len;
  1385. X
  1386. X    XUpdateMouse (w, &x, &y, &subw);
  1387. X    switch (s->orientation) {
  1388. X    case SCROLL_TOP:
  1389. X    case SCROLL_BOTTOM:
  1390. X        loc = x;
  1391. X        break;
  1392. X    case SCROLL_LEFT:
  1393. X    case SCROLL_RIGHT:
  1394. X        loc = y;
  1395. X        break;
  1396. X    }
  1397. X    pos = loctopos (postoloc (downloc) + loc - downmouse);
  1398. X    if (pos < minpos(p))
  1399. X        pos = minpos(p);
  1400. X    if (pos > maxpos(p))
  1401. X        pos = maxpos (p);
  1402. X    return postomille (pos, p);
  1403. X}
  1404. X
  1405. Xstatic
  1406. XcheckMouseRegion (w, s, p)
  1407. XWindow            w;
  1408. Xstruct scrollbar    *s;
  1409. Xstruct perwindow    *p;
  1410. X{
  1411. X    int    x, y, subw, state;
  1412. X    int    region;
  1413. X    
  1414. X    XQueryMouseButtons (w, &x, &y, &subw, &state);
  1415. X
  1416. X    /*
  1417. X     * Note that if we are playing back a recording then the button
  1418. X     * state will not be as it was during the recording (pressed),
  1419. X     * so we short circuit it.
  1420. X     */
  1421. X
  1422. X    region = findRegion (s, p, x, y);
  1423. X    if (region == IN_UP_BOX && p->state == DOWN_IN_UP_BOX)
  1424. X        return IN_UP_BOX;
  1425. X    if (region == IN_DOWN_BOX && p->state == DOWN_IN_DOWN_BOX)
  1426. X        return IN_DOWN_BOX;
  1427. X    return NOWHERE;
  1428. X}
  1429. X
  1430. Xstatic
  1431. XcomputePosition (parent, s, xp, yp, wp, hp)
  1432. XWindow            parent;
  1433. Xstruct scrollbar    *s;
  1434. Xint            *xp, *yp, *wp, *hp;
  1435. X{
  1436. X    WindowInfo    parentInfo;
  1437. X
  1438. X    /* make sure the server has the most recent parent info */
  1439. X    XSync (0);
  1440. X    if (!XQueryWindow (parent, &parentInfo)) {
  1441. X        printf ("can't get window info for %d\n", parent);
  1442. X        return 0;
  1443. X    }
  1444. X    switch (s->orientation) {
  1445. X    case SCROLL_TOP:
  1446. X        *xp = 0;
  1447. X        *yp = -SCROLLWIDTH - parentInfo.bdrwidth;
  1448. X        *wp = parentInfo.width;
  1449. X        *hp = SCROLLWIDTH;
  1450. X        break;
  1451. X    case SCROLL_BOTTOM:
  1452. X        *xp = 0;
  1453. X        *yp = parentInfo.height + parentInfo.bdrwidth; 
  1454. X        *wp = parentInfo.width;
  1455. X        *hp = SCROLLWIDTH;
  1456. X        break;
  1457. X    case SCROLL_LEFT:
  1458. X        *xp = -SCROLLWIDTH - parentInfo.bdrwidth;
  1459. X        *yp = 0;
  1460. X        *wp = SCROLLWIDTH;
  1461. X        *hp = parentInfo.height;
  1462. X        break;
  1463. X    case SCROLL_RIGHT:
  1464. X        *xp = parentInfo.width + parentInfo.bdrwidth;
  1465. X        *yp = 0;
  1466. X        *wp = SCROLLWIDTH;
  1467. X        *hp = parentInfo.height;
  1468. X        break;
  1469. X    }
  1470. X    *xp += parentInfo.x;
  1471. X    *yp += parentInfo.y;
  1472. X    return 1;
  1473. X}
  1474. X
  1475. Xstatic
  1476. XdrawArrows (w, s, p)
  1477. XWindow            w;
  1478. Xstruct scrollbar    *s;
  1479. Xstruct perwindow    *p;
  1480. X{
  1481. X    int    x, y;
  1482. X    short    *up, *down;
  1483. X    
  1484. X    switch (s->orientation) {
  1485. X    case SCROLL_TOP:
  1486. X    case SCROLL_BOTTOM:
  1487. X        up = arrowLeftOff;
  1488. X        down = arrowRightOff;
  1489. X        x = p->length - ARROWWIDTH;
  1490. X        y = 0;
  1491. X        switch (p->state) {
  1492. X        case DOWN_IN_DOWN_BOX:
  1493. X            down = arrowRightOn;
  1494. X            break;
  1495. X        case DOWN_IN_UP_BOX:
  1496. X            up = arrowLeftOn;
  1497. X            break;
  1498. X        }
  1499. X        break;
  1500. X    case SCROLL_LEFT:
  1501. X    case SCROLL_RIGHT:
  1502. X        up = arrowUpOff;
  1503. X        down = arrowDownOff;
  1504. X        x = 0;
  1505. X        y = p->length - ARROWWIDTH;
  1506. X        switch (p->state) {
  1507. X        case DOWN_IN_DOWN_BOX:
  1508. X            down = arrowDownOn;
  1509. X            break;
  1510. X        case DOWN_IN_UP_BOX:
  1511. X            up = arrowUpOn;
  1512. X            break;
  1513. X        }
  1514. X        break;
  1515. X    }
  1516. X    XBitmapBitsPut (w, 0, 0,
  1517. X        ARROWWIDTH, ARROWHEIGHT,
  1518. X        up, s->forecolor, s->backcolor,
  1519. X        0, GXcopy, AllPlanes);
  1520. X    XBitmapBitsPut (w, x, y,
  1521. X        ARROWWIDTH, ARROWHEIGHT,
  1522. X        down, s->forecolor, s->backcolor,
  1523. X        0, GXcopy, AllPlanes);
  1524. X}
  1525. X
  1526. Xstatic
  1527. XhighlightBox (w, s, p, state)
  1528. XWindow            w;
  1529. Xstruct scrollbar    *s;
  1530. Xstruct perwindow    *p;
  1531. Xint            state;
  1532. X{
  1533. X    drawoneArrow (w, s, p, state, 1);
  1534. X}
  1535. X
  1536. Xstatic
  1537. XunhighlightBox (w, s, p, state)
  1538. XWindow            w;
  1539. Xstruct scrollbar    *s;
  1540. Xstruct perwindow    *p;
  1541. Xint            state;
  1542. X{
  1543. X    drawoneArrow (w, s, p, state, 0);
  1544. X}
  1545. X
  1546. Xstatic
  1547. XdrawoneArrow (w, s, p, state, on)
  1548. XWindow            w;
  1549. Xstruct scrollbar    *s;
  1550. Xstruct perwindow    *p;
  1551. Xint            state;
  1552. Xint            on;
  1553. X{
  1554. X    int    x, y;
  1555. X    short    *bitsup, *bitsdown, *bits;
  1556. X    switch (s->orientation) {
  1557. X    case SCROLL_TOP:
  1558. X    case SCROLL_BOTTOM:
  1559. X        x = p->length - ARROWWIDTH;
  1560. X        y = 0;
  1561. X        if (on) {
  1562. X            bitsup = arrowLeftOn;
  1563. X            bitsdown = arrowRightOn;
  1564. X        } else {
  1565. X            bitsup = arrowLeftOff;
  1566. X            bitsdown = arrowRightOff;
  1567. X        }
  1568. X        break;
  1569. X    case SCROLL_LEFT:
  1570. X    case SCROLL_RIGHT:
  1571. X        x = 0;
  1572. X        y = p->length - ARROWWIDTH;
  1573. X        if (on) {
  1574. X            bitsup = arrowUpOn;
  1575. X            bitsdown = arrowDownOn;
  1576. X        } else {
  1577. X            bitsup = arrowUpOff;
  1578. X            bitsdown = arrowDownOff;
  1579. X        }
  1580. X        break;
  1581. X    }
  1582. X    switch (state) {
  1583. X    case DOWN_IN_UP_BOX:
  1584. X        x = 0;
  1585. X        y = 0;
  1586. X        bits = bitsup;
  1587. X        break;
  1588. X    case DOWN_IN_DOWN_BOX:
  1589. X        bits = bitsdown;
  1590. X        break;
  1591. X    default:
  1592. X        return;
  1593. X    }
  1594. X    XBitmapBitsPut (w, x, y, ARROWWIDTH, ARROWHEIGHT,
  1595. X        bits, s->forecolor, s->backcolor,
  1596. X        0, GXcopy, AllPlanes);
  1597. X}
  1598. X
  1599. Xstatic
  1600. XmoveLocator (w, s, p, pos, max)
  1601. XWindow            w;
  1602. Xstruct scrollbar    *s;
  1603. Xstruct perwindow    *p;
  1604. Xint            pos, max;
  1605. X{
  1606. X    int    x, y, lw, lh;
  1607. X    int    x0, y0, w0, h0;
  1608. X    int    x1, y1, w1, h1;
  1609. X    int    oldpos, oldmax, oldlen;
  1610. X
  1611. X    if (max > maxpos (p))
  1612. X        max = maxpos (p);
  1613. X    if (max < 0)
  1614. X        max = 0;
  1615. X    if (pos > maxpos (p))
  1616. X        pos = maxpos (p);
  1617. X    if (pos < 0)
  1618. X        pos = 0;
  1619. X    oldpos = p->locatorpos;
  1620. X    oldmax = p->locatormax;
  1621. X    oldlen = oldmax - oldpos;
  1622. X    w0 = h0 = w1 = h1 = 0;
  1623. X    switch (s->orientation) {
  1624. X    case SCROLL_TOP:
  1625. X    case SCROLL_BOTTOM:
  1626. X        x = postoloc (pos);
  1627. X        y = SCROLLWIDTH / 2 - LOCATORWIDTH / 2;
  1628. X        y0 = y;
  1629. X        y1 = y;
  1630. X        lh = LOCATORWIDTH;
  1631. X        lw = max - pos;
  1632. X        h0 = lh;
  1633. X        h1 = lh;
  1634. X        if (pos < 0) {
  1635. X            /*
  1636. X             * erase the whole thing
  1637. X             */
  1638. X            x0 = postoloc (oldpos);
  1639. X            w0 = oldlen;
  1640. X        } else if (p->locatorpos < 0) {
  1641. X            ;
  1642. X        } else {
  1643. X            if (pos > oldpos) {
  1644. X                /*
  1645. X                 * erase before portion
  1646. X                 */
  1647. X                x0 = postoloc (oldpos);
  1648. X                w0 = pos - oldpos;
  1649. X            }
  1650. X            if (max < oldmax) {
  1651. X                /* 
  1652. X                 * erase after portion
  1653. X                 */
  1654. X                x1 = postoloc (max);
  1655. X                w1 = oldmax - max;
  1656. X            }
  1657. X        }
  1658. X        break;
  1659. X    case SCROLL_LEFT:
  1660. X    case SCROLL_RIGHT:
  1661. X        x = SCROLLWIDTH / 2 - LOCATORWIDTH / 2;
  1662. X        y = postoloc (pos);
  1663. X        x0 = x;
  1664. X        x1 = x;
  1665. X        lw = LOCATORWIDTH;
  1666. X        lh = max - pos;
  1667. X        w0 = lw;
  1668. X        w1 = lw;
  1669. X        if (pos < 0) {
  1670. X            /*
  1671. X             * erase the whole thing
  1672. X             */
  1673. X            y0 = postoloc (oldpos);
  1674. X            h0 = oldlen;
  1675. X        } else if (p->locatorpos < 0) {
  1676. X            ;
  1677. X        } else {
  1678. X            if (pos > oldpos) {
  1679. X                /*
  1680. X                 * erase before portion
  1681. X                 */
  1682. X                y0 = postoloc (oldpos);
  1683. X                h0 = pos - oldpos;
  1684. X            }
  1685. X            if (max < oldmax) {
  1686. X                /*
  1687. X                 * erase after portion
  1688. X                 */
  1689. X                y1 = postoloc (max);
  1690. X                h1 = oldmax - max;
  1691. X            }
  1692. X        }
  1693. X        break;
  1694. X    }
  1695. X    if (pos >= 0) {
  1696. X        Vertex v[5];
  1697. X
  1698. X        v[0].x = x;    v[0].y = y;    v[0].flags = 0;
  1699. X        v[1].x = lw-1;    v[1].y = 0;    v[1].flags = VertexRelative;
  1700. X        v[2].x = 0;    v[2].y = lh-1;    v[2].flags = VertexRelative;
  1701. X        v[3].x = 1-lw;    v[3].y = 0;    v[3].flags = VertexRelative;
  1702. X        v[4].x = 0;    v[4].y = 1-lh;    v[4].flags = VertexRelative;
  1703. X        XDraw (w, v, 5, 1, 1, s->forecolor, GXcopy, AllPlanes);
  1704. X        XPixSet (w, x+1, y+1, lw-2, lh-2, s->backcolor);
  1705. X    }
  1706. X    if (oldpos >= 0) {
  1707. X        if (w0 != 0 && h0 != 0)
  1708. X            XTileSet (w, x0, y0, w0, h0, s->background);
  1709. X        if (w1 != 0 && h1 != 0)
  1710. X            XTileSet (w, x1, y1, w1, h1, s->background);
  1711. X    }
  1712. X    p->locatorpos = pos;
  1713. X    p->locatormax = max;
  1714. X    p->locatormille = postomille (p->locatorpos, p);
  1715. X    p->locatormaxmille = postomille (p->locatormax, p);
  1716. X}
  1717. X
  1718. X# define getbit(array, bit, word) ((word < 0 || word >= 50) ? 0 : ((array[word] >> bit) & 01))
  1719. X
  1720. Xstatic
  1721. XsetArrows ()
  1722. X{
  1723. X    int    i;
  1724. X    int    word, bit;
  1725. X    unsigned short    tempLeftOn[2], tempRightOn[2];
  1726. X    unsigned short    tempLeftOff[2], tempRightOff[2];
  1727. X    int    on, off;
  1728. X    Bitmap    dragmap;
  1729. X    int    k;
  1730. X    
  1731. X    for (i = 0; i < ARROWHEIGHT; i++)
  1732. X        for (k = 0; k < 2; k++) {
  1733. X            arrowUpOff[i*2+k] = arrowDownOff[(ARROWHEIGHT-1-i)*2 + k];
  1734. X            arrowUpOn[i*2+k] = arrowDownOn[(ARROWHEIGHT-1-i)*2 + k];
  1735. X        }
  1736. X    for (i = 0; i < ARROWHEIGHT; i++) {
  1737. X        for (k = 0; k < 2; k++) {
  1738. X            tempLeftOn[k] = tempLeftOff[k] = 0;
  1739. X            tempRightOn[k] = tempRightOff[k] = 0;
  1740. X        }
  1741. X        for (k = 0; k < 2; k++) {
  1742. X            for (bit = 0; bit < 16; bit++) {
  1743. X                off = getbit (arrowDownOff,
  1744. X                    i % 16, ((15-bit) + (1-k) * 16) * 2 + i/16);
  1745. X                on = getbit (arrowDownOn,
  1746. X                    i % 16, ((15-bit) + (1-k) * 16) * 2 + i/16);
  1747. X                if (off)
  1748. X                    tempRightOff[1-k] |= (1 << (15 - bit));
  1749. X                if (on)
  1750. X                    tempRightOn[1-k] |= (1 << (15 - bit));
  1751. X                off = getbit (arrowUpOff,
  1752. X                    i % 16, ((15-bit) + (1-k) * 16) * 2 + i/16);
  1753. X                on = getbit (arrowUpOn,
  1754. X                    i % 16, ((15-bit) + (1-k) * 16) * 2 + i/16);
  1755. X                if (off)
  1756. X                    tempLeftOff[1-k] |= (1 << (15 - bit));
  1757. X                if (on)
  1758. X                    tempLeftOn[1-k] |= (1 << (15 - bit));
  1759. X            }
  1760. X        }
  1761. X        arrowLeftOn[i*2] = tempLeftOn[0];
  1762. X        arrowLeftOn[i*2+1] = tempLeftOn[1];
  1763. X        arrowLeftOff[i*2] = tempLeftOff[0];
  1764. X        arrowLeftOff[i*2+1] = tempLeftOff[1];
  1765. X        arrowRightOn[i*2] = tempRightOn[0];
  1766. X        arrowRightOn[i*2+1] = tempRightOn[1];
  1767. X        arrowRightOff[i*2] = tempRightOff[0];
  1768. X        arrowRightOff[i*2+1] = tempRightOff[1];
  1769. X    }
  1770. X    dragmap = XStoreBitmap (16, 16, dragBits);
  1771. X    dragCursor = XStoreCursor (dragmap, dragmap, 8, 8, 1, 0, GXnoop);
  1772. X}
  1773. END_OF_control/scrollbar.c
  1774. if test 17486 -ne `wc -c <control/scrollbar.c`; then
  1775.     echo shar: \"control/scrollbar.c\" unpacked with wrong size!
  1776. fi
  1777. # end of overwriting check
  1778. fi
  1779. if test -f control/test.c -a "${1}" != "-c" ; then 
  1780.   echo shar: Will not over-write existing file \"control/test.c\"
  1781. else
  1782. echo shar: Extracting \"control/test.c\" \(82 characters\)
  1783. sed "s/^X//" >control/test.c <<'END_OF_control/test.c'
  1784. Xmain ()
  1785. X{
  1786. X    XOpenDisplay ("");
  1787. X    while (!co_affirm ("Do you want to leave?"))
  1788. X        ;
  1789. X}
  1790. END_OF_control/test.c
  1791. if test 82 -ne `wc -c <control/test.c`; then
  1792.     echo shar: \"control/test.c\" unpacked with wrong size!
  1793. fi
  1794. # end of overwriting check
  1795. fi
  1796. echo shar: End of archive 4 \(of 4\).
  1797. cp /dev/null ark4isdone
  1798. MISSING=""
  1799. for I in 1 2 3 4 ; do
  1800.     if test ! -f ark${I}isdone ; then
  1801.     MISSING="${MISSING} ${I}"
  1802.     fi
  1803. done
  1804. if test "${MISSING}" = "" ; then
  1805.     echo You have unpacked all 4 archives.
  1806.     rm -f ark[1-9]isdone
  1807. else
  1808.     echo You still need to unpack the following archives:
  1809.     echo "        " ${MISSING}
  1810. fi
  1811. ##  End of shell archive.
  1812. exit 0
  1813.  
  1814.  
  1815.