home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume8 / chaos / part02 < prev    next >
Internet Message Format  |  1990-08-20  |  56KB

  1. Path: uunet!cs.utexas.edu!sun-barr!newstop!sun!uunet.UU.NET
  2. From: balr!panasun!ken@uunet.UU.NET (Ken Marks (x2425))
  3. Newsgroups: comp.sources.x
  4. Subject: v08i078: chaos, Part02/10
  5. Message-ID: <140956@sun.Eng.Sun.COM>
  6. Date: 20 Aug 90 18:03:21 GMT
  7. Sender: news@sun.Eng.Sun.COM
  8. Lines: 2183
  9. Approved: argv@sun.com
  10.  
  11. Submitted-by: balr!panasun!ken@uunet.UU.NET (Ken Marks (x2425))
  12. Posting-number: Volume 8, Issue 78
  13. Archive-name: chaos/part02
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then unpack
  17. # it by saving it into a file and typing "sh file".  To overwrite existing
  18. # files, type "sh file -c".  You can also feed this as standard input via
  19. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  20. # will see the following message at the end:
  21. #        "End of archive 2 (of 10)."
  22. # Contents:  common/showEvent.c gencmap/Imakefile gencmap/gencmap.c
  23. #   widgets/List.c
  24. # Wrapped by ken@panasun on Mon Jul 30 14:59:47 1990
  25. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  26. if test -f 'common/showEvent.c' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'common/showEvent.c'\"
  28. else
  29. echo shar: Extracting \"'common/showEvent.c'\" \(23550 characters\)
  30. sed "s/^X//" >'common/showEvent.c' <<'END_OF_FILE'
  31. X/*
  32. X * Copyright (c) Ken W. Marks 1989, 1990.
  33. X */
  34. X
  35. X#include <stdio.h>
  36. X#include <X11/Intrinsic.h>
  37. X#include <X11/Xproto.h>
  38. X#include <Chaos.h>
  39. X
  40. XBoolean use_separate_lines = True;
  41. Xstatic char *sep;
  42. X
  43. X/******************************************************************************/
  44. X/**** Miscellaneous routines to convert values to their string equivalents ****/
  45. X/******************************************************************************/
  46. X
  47. X/* Returns the string equivalent of a boolean parameter */
  48. Xstatic char *TorF(bool)
  49. Xint bool;
  50. X{
  51. X    switch (bool)
  52. X    {
  53. X    case True:
  54. X    return ("True");
  55. X
  56. X    case False:
  57. X    return ("False");
  58. X
  59. X    default:
  60. X    return ("?");
  61. X    }
  62. X}
  63. X
  64. X/* Returns the string equivalent of a property notify state */
  65. Xstatic char *PropertyState(state)
  66. Xint state;
  67. X{
  68. X    switch (state)
  69. X    {
  70. X    case PropertyNewValue:
  71. X    return ("PropertyNewValue");
  72. X
  73. X    case PropertyDelete:
  74. X    return ("PropertyDelete");
  75. X
  76. X    default:
  77. X    return ("?");
  78. X    }
  79. X}
  80. X
  81. X/* Returns the string equivalent of a visibility notify state */
  82. Xstatic char *VisibilityState(state)
  83. Xint state;
  84. X{
  85. X    switch (state)
  86. X    {
  87. X    case VisibilityUnobscured:
  88. X    return ("VisibilityUnobscured");
  89. X
  90. X    case VisibilityPartiallyObscured:
  91. X    return ("VisibilityPartiallyObscured");
  92. X
  93. X    case VisibilityFullyObscured:
  94. X    return ("VisibilityFullyObscured");
  95. X
  96. X    default:
  97. X    return ("?");
  98. X    }
  99. X}
  100. X
  101. X/* Returns the string equivalent of a timestamp */
  102. Xstatic char *ServerTime(time)
  103. XTime time;
  104. X{
  105. X    unsigned long msec;
  106. X    unsigned long sec;
  107. X    unsigned long min;
  108. X    unsigned long hr;
  109. X    unsigned long day;
  110. X    static char buffer[32];
  111. X
  112. X    msec = time % 1000;
  113. X    time /= 1000;
  114. X    sec = time % 60;
  115. X    time /= 60;
  116. X    min = time % 60;
  117. X    time /= 60;
  118. X    hr = time % 24;
  119. X    time /= 24;
  120. X    day = time;
  121. X
  122. X    (void) sprintf(buffer, "%d day%s %02d:%02d:%02d.%03d",
  123. X      day, day == 1 ? "" : "(s)", hr, min, sec, msec);
  124. X    return (buffer);
  125. X}
  126. X
  127. X/* Simple structure to ease the interpretation of masks */
  128. Xtypedef struct _MaskType
  129. X{
  130. X    unsigned int value;
  131. X    char *string;
  132. X} MaskType;
  133. X
  134. X/* Returns the string equivalent of a mask of buttons and modifier keys */
  135. Xstatic char *ButtonOrModifierState(state)
  136. Xunsigned int state;
  137. X{
  138. X    static char buffer[256];
  139. X    static MaskType masks[] = {
  140. X    {ShiftMask, "ShiftMask"},
  141. X    {LockMask, "LockMask"},
  142. X    {ControlMask, "ControlMask"},
  143. X    {Mod1Mask, "Mod1Mask"},
  144. X    {Mod2Mask, "Mod2Mask"},
  145. X    {Mod3Mask, "Mod3Mask"},
  146. X    {Mod4Mask, "Mod4Mask"},
  147. X    {Mod5Mask, "Mod5Mask"},
  148. X    {Button1Mask, "Button1Mask"},
  149. X    {Button2Mask, "Button2Mask"},
  150. X    {Button3Mask, "Button3Mask"},
  151. X    {Button4Mask, "Button4Mask"},
  152. X    {Button5Mask, "Button5Mask"},
  153. X    };
  154. X    int num_masks = sizeof(masks) / sizeof(MaskType);
  155. X    int ii;
  156. X    Boolean first = True;
  157. X
  158. X    buffer[0] = NULL;
  159. X
  160. X    if (state == 0)
  161. X    return (buffer);
  162. X
  163. X    for (ii = 0; ii < num_masks; ii++)
  164. X    if (state & masks[ii].value)
  165. X        if (first)
  166. X        {
  167. X        first = False;
  168. X        (void) strcat(buffer, masks[ii].string);
  169. X        }
  170. X        else
  171. X        {
  172. X        (void) strcat(buffer, " | ");
  173. X        (void) strcat(buffer, masks[ii].string);
  174. X        }
  175. X    return (buffer);
  176. X}
  177. X
  178. X/* Returns the string equivalent of a mask of configure window values */
  179. Xstatic char *ConfigureValueMask(valuemask)
  180. Xunsigned long valuemask;
  181. X{
  182. X    static char buffer[256];
  183. X    static MaskType masks[] = {
  184. X    {CWX, "CWX"},
  185. X    {CWY, "CWY"},
  186. X    {CWWidth, "CWWidth"},
  187. X    {CWHeight, "CWHeight"},
  188. X    {CWBorderWidth, "CWBorderWidth"},
  189. X    {CWSibling, "CWSibling"},
  190. X    {CWStackMode, "CWStackMode"},
  191. X    };
  192. X    int num_masks = sizeof(masks) / sizeof(MaskType);
  193. X    int ii;
  194. X    Boolean first = True;
  195. X
  196. X    buffer[0] = NULL;
  197. X
  198. X    if (valuemask == 0)
  199. X    return (buffer);
  200. X
  201. X    for (ii = 0; ii < num_masks; ii++)
  202. X    if (valuemask & masks[ii].value)
  203. X        if (first)
  204. X        {
  205. X        first = False;
  206. X        (void) strcat(buffer, masks[ii].string);
  207. X        }
  208. X        else
  209. X        {
  210. X        (void) strcat(buffer, " | ");
  211. X        (void) strcat(buffer, masks[ii].string);
  212. X        }
  213. X
  214. X    return (buffer);
  215. X}
  216. X
  217. X/* Returns the string equivalent of a motion hint */
  218. Xstatic char *IsHint(is_hint)
  219. Xchar is_hint;
  220. X{
  221. X    switch (is_hint)
  222. X    {
  223. X    case NotifyNormal:
  224. X    return ("NotifyNormal");
  225. X
  226. X    case NotifyHint:
  227. X    return ("NotifyHint");
  228. X
  229. X    default:
  230. X    return ("?");
  231. X    }
  232. X}
  233. X
  234. X/* Returns the string equivalent of an id or the value "None" */
  235. Xstatic char *MaybeNone(value)
  236. Xint value;
  237. X{
  238. X    static char buffer[16];
  239. X
  240. X    if (value == None)
  241. X    return ("None");
  242. X    else
  243. X    {
  244. X    (void) sprintf(buffer, "0x%x", value);
  245. X    return (buffer);
  246. X    }
  247. X}
  248. X
  249. X/* Returns the string equivalent of a colormap state */
  250. Xstatic char *ColormapState(state)
  251. Xint state;
  252. X{
  253. X    switch (state)
  254. X    {
  255. X    case ColormapInstalled:
  256. X    return ("ColormapInstalled");
  257. X
  258. X    case ColormapUninstalled:
  259. X    return ("ColormapUninstalled");
  260. X
  261. X    default:
  262. X    return ("?");
  263. X    }
  264. X}
  265. X
  266. X/* Returns the string equivalent of a crossing detail */
  267. Xstatic char *CrossingDetail(detail)
  268. Xint detail;
  269. X{
  270. X    switch (detail)
  271. X    {
  272. X    case NotifyAncestor:
  273. X    return ("NotifyAncestor");
  274. X
  275. X    case NotifyInferior:
  276. X    return ("NotifyInferior");
  277. X
  278. X    case NotifyVirtual:
  279. X    return ("NotifyVirtual");
  280. X
  281. X    case NotifyNonlinear:
  282. X    return ("NotifyNonlinear");
  283. X
  284. X    case NotifyNonlinearVirtual:
  285. X    return ("NotifyNonlinearVirtual");
  286. X
  287. X    default:
  288. X    return ("?");
  289. X    }
  290. X}
  291. X
  292. X/* Returns the string equivalent of a focus change detail */
  293. Xstatic char *FocusChangeDetail(detail)
  294. Xint detail;
  295. X{
  296. X    switch (detail)
  297. X    {
  298. X    case NotifyAncestor:
  299. X    return ("NotifyAncestor");
  300. X
  301. X    case NotifyInferior:
  302. X    return ("NotifyInferior");
  303. X
  304. X    case NotifyVirtual:
  305. X    return ("NotifyVirtual");
  306. X
  307. X    case NotifyNonlinear:
  308. X    return ("NotifyNonlinear");
  309. X
  310. X    case NotifyNonlinearVirtual:
  311. X    return ("NotifyNonlinearVirtual");
  312. X
  313. X    case NotifyPointer:
  314. X    return ("NotifyPointer");
  315. X
  316. X    case NotifyPointerRoot:
  317. X    return ("NotifyPointerRoot");
  318. X
  319. X    case NotifyDetailNone:
  320. X    return ("NotifyDetailNone");
  321. X
  322. X    default:
  323. X    return ("?");
  324. X    }
  325. X}
  326. X
  327. X/* Returns the string equivalent of a configure detail */
  328. Xstatic char *ConfigureDetail(detail)
  329. Xint detail;
  330. X{
  331. X    switch (detail)
  332. X    {
  333. X    case Above:
  334. X    return ("Above");
  335. X
  336. X    case Below:
  337. X    return ("Below");
  338. X
  339. X    case TopIf:
  340. X    return ("TopIf");
  341. X
  342. X    case BottomIf:
  343. X    return ("BottomIf");
  344. X
  345. X    case Opposite:
  346. X    return ("Opposite");
  347. X
  348. X    default:
  349. X    return ("?");
  350. X    }
  351. X}
  352. X
  353. X/* Returns the string equivalent of a grab mode */
  354. Xstatic char *GrabMode(mode)
  355. Xint mode;
  356. X{
  357. X    switch (mode)
  358. X    {
  359. X    case NotifyNormal:
  360. X    return ("NotifyNormal");
  361. X
  362. X    case NotifyGrab:
  363. X    return ("NotifyGrab");
  364. X
  365. X    case NotifyUngrab:
  366. X    return ("NotifyUngrab");
  367. X
  368. X    case NotifyWhileGrabbed:
  369. X    return ("NotifyWhileGrabbed");
  370. X
  371. X    default:
  372. X    return ("?");
  373. X    }
  374. X}
  375. X
  376. X/* Returns the string equivalent of a mapping request */
  377. Xstatic char *MappingRequest(request)
  378. Xint request;
  379. X{
  380. X    switch (request)
  381. X    {
  382. X    case MappingModifier:
  383. X    return ("MappingModifier");
  384. X
  385. X    case MappingKeyboard:
  386. X    return ("MappingKeyboard");
  387. X
  388. X    case MappingPointer:
  389. X    return ("MappingPointer");
  390. X
  391. X    default:
  392. X    return ("?");
  393. X    }
  394. X}
  395. X
  396. X/* Returns the string equivalent of a stacking order place */
  397. Xstatic char *Place(place)
  398. Xint place;
  399. X{
  400. X    switch (place)
  401. X    {
  402. X    case PlaceOnTop:
  403. X    return ("PlaceOnTop");
  404. X
  405. X    case PlaceOnBottom:
  406. X    return ("PlaceOnBottom");
  407. X
  408. X    default:
  409. X    return ("?");
  410. X    }
  411. X}
  412. X
  413. X/* Returns the string equivalent of a major code */
  414. Xstatic char *MajorCode(code)
  415. Xint code;
  416. X{
  417. X    static char buffer[32];
  418. X
  419. X    switch (code)
  420. X    {
  421. X    case X_CopyArea:
  422. X    return ("X_CopyArea");
  423. X
  424. X    case X_CopyPlane:
  425. X    return ("X_CopyPlane");
  426. X
  427. X    default:
  428. X    (void) sprintf(buffer, "0x%x", code);
  429. X    return (buffer);
  430. X    }
  431. X}
  432. X
  433. X/* Returns the string equivalent the keycode contained in the key event */
  434. Xstatic char *Keycode(ev)
  435. XXKeyEvent *ev;
  436. X{
  437. X    static char buffer[256];
  438. X    KeySym keysym_str;
  439. X    char *keysym_name;
  440. X    char string[256];
  441. X
  442. X    XLookupString(ev, string, 64, &keysym_str, NULL);
  443. X
  444. X    if (keysym_str == NoSymbol)
  445. X    keysym_name = "NoSymbol";
  446. X    else if (!(keysym_name = XKeysymToString(keysym_str)))
  447. X    keysym_name = "(no name)";
  448. X    (void) sprintf(buffer, "%u (keysym 0x%x \"%s\")",
  449. X      ev->keycode, keysym_str, keysym_name);
  450. X    return (buffer);
  451. X}
  452. X
  453. X/* Returns the string equivalent of an atom or "None"*/
  454. Xstatic char *AtomName(dpy, atom)
  455. XDisplay *dpy;
  456. XAtom atom;
  457. X{
  458. X    static char buffer[256];
  459. X    char *atom_name;
  460. X
  461. X    if (atom == None)
  462. X    return ("None");
  463. X
  464. X    atom_name = XGetAtomName(dpy, atom);
  465. X    (void) strncpy(buffer, atom_name, 256);
  466. X    free(atom_name);
  467. X
  468. X    return (buffer);
  469. X}
  470. X
  471. X/******************************************************************************/
  472. X/**** Routines to print out readable values for the field of various events ***/
  473. X/******************************************************************************/
  474. X
  475. Xstatic void VerbMotion(ev)
  476. XXMotionEvent *ev;
  477. X{
  478. X    (void) printf("window = 0x%x%s", ev->window, sep);
  479. X    (void) printf("root = 0x%x%s", ev->root, sep);
  480. X    (void) printf("subwindow = 0x%x%s", ev->subwindow, sep);
  481. X    (void) printf("time = %s%s", ServerTime(ev->time), sep);
  482. X    (void) printf("x = %d  y = %d%s", ev->x, ev->y, sep);
  483. X    (void) printf("x_root = %d  y_root = %d%s", ev->x_root, ev->y_root, sep);
  484. X    (void) printf("state = %s%s", ButtonOrModifierState(ev->state), sep);
  485. X    (void) printf("is_hint = %s%s", IsHint(ev->is_hint), sep);
  486. X    (void) printf("same_screen = %s\n", TorF(ev->same_screen));
  487. X}
  488. X
  489. Xstatic void VerbButton(ev)
  490. XXButtonEvent *ev;
  491. X{
  492. X    (void) printf("window = 0x%x%s", ev->window, sep);
  493. X    (void) printf("root = 0x%x%s", ev->root, sep);
  494. X    (void) printf("subwindow = 0x%x%s", ev->subwindow, sep);
  495. X    (void) printf("time = %s%s", ServerTime(ev->time), sep);
  496. X    (void) printf("x = %d  y = %d%s", ev->x, ev->y, sep);
  497. X    (void) printf("x_root = %d  y_root = %d%s", ev->x_root, ev->y_root, sep);
  498. X    (void) printf("state = %s%s", ButtonOrModifierState(ev->state), sep);
  499. X    (void) printf("button = Button%d%s", ev->button, sep);
  500. X    (void) printf("same_screen = %s\n", TorF(ev->same_screen));
  501. X}
  502. X
  503. Xstatic void VerbColormap(ev)
  504. XXColormapEvent *ev;
  505. X{
  506. X    (void) printf("window = 0x%x%s", ev->window, sep);
  507. X    (void) printf("colormap = %s%s", MaybeNone((int) (ev->colormap)), sep);
  508. X    (void) printf("new = %s%s", TorF(ev->new), sep);
  509. X    (void) printf("state = %s\n", ColormapState(ev->state));
  510. X}
  511. X
  512. Xstatic void VerbCrossing(ev)
  513. XXCrossingEvent *ev;
  514. X{
  515. X    (void) printf("window = 0x%x%s", ev->window, sep);
  516. X    (void) printf("root = 0x%x%s", ev->root, sep);
  517. X    (void) printf("subwindow = 0x%x%s", ev->subwindow, sep);
  518. X    (void) printf("time = %s%s", ServerTime(ev->time), sep);
  519. X    (void) printf("x = %d  y = %d%s", ev->x, ev->y, sep);
  520. X    (void) printf("x_root = %d  y_root = %d%s", ev->x_root, ev->y_root, sep);
  521. X    (void) printf("mode = %s%s", GrabMode(ev->mode), sep);
  522. X    (void) printf("detail = %s%s", CrossingDetail(ev->detail), sep);
  523. X    (void) printf("same_screen = %s%s", TorF(ev->same_screen), sep);
  524. X    (void) printf("focus = %s%s", TorF(ev->focus), sep);
  525. X    (void) printf("state = %s\n", ButtonOrModifierState(ev->state));
  526. X}
  527. X
  528. Xstatic void VerbExpose(ev)
  529. XXExposeEvent *ev;
  530. X{
  531. X    (void) printf("window = 0x%x%s", ev->window, sep);
  532. X    (void) printf("x = %d  y = %d%s", ev->x, ev->y, sep);
  533. X    (void) printf("width = %d height = %d%s", ev->width, ev->height, sep);
  534. X    (void) printf("count = %d\n", ev->count);
  535. X}
  536. X
  537. Xstatic void VerbGraphicsExpose(ev)
  538. XXGraphicsExposeEvent *ev;
  539. X{
  540. X    (void) printf("drawable = 0x%x%s", ev->drawable, sep);
  541. X    (void) printf("x = %d  y = %d%s", ev->x, ev->y, sep);
  542. X    (void) printf("width = %d height = %d%s", ev->width, ev->height, sep);
  543. X    (void) printf("major_code = %s%s", MajorCode(ev->major_code), sep);
  544. X    (void) printf("minor_code = %d\n", ev->minor_code);
  545. X}
  546. X
  547. Xstatic void VerbNoExpose(ev)
  548. XXNoExposeEvent *ev;
  549. X{
  550. X    (void) printf("drawable = 0x%x%s", ev->drawable, sep);
  551. X    (void) printf("major_code = %s%s", MajorCode(ev->major_code), sep);
  552. X    (void) printf("minor_code = %d\n", ev->minor_code);
  553. X}
  554. X
  555. Xstatic void VerbFocus(ev)
  556. XXFocusChangeEvent *ev;
  557. X{
  558. X    (void) printf("window = 0x%x%s", ev->window, sep);
  559. X    (void) printf("mode = %s%s", GrabMode(ev->mode), sep);
  560. X    (void) printf("detail = %s\n", FocusChangeDetail(ev->detail));
  561. X}
  562. X
  563. Xstatic void VerbKeymap(ev)
  564. XXKeymapEvent *ev;
  565. X{
  566. X    int ii;
  567. X
  568. X    (void) printf("window = 0x%x%s", ev->window, sep);
  569. X    (void) printf("key_vector = ");
  570. X    for (ii = 0; ii < 32; ii++)
  571. X    (void) printf("%02x", ev->key_vector[ii]);
  572. X    (void) printf("\n");
  573. X}
  574. X
  575. Xstatic void VerbKey(ev)
  576. XXKeyEvent *ev;
  577. X{
  578. X    (void) printf("window = 0x%x%s", ev->window, sep);
  579. X    (void) printf("root = 0x%x%s", ev->root, sep);
  580. X    (void) printf("subwindow = 0x%x%s", ev->subwindow, sep);
  581. X    (void) printf("time = %s%s", ServerTime(ev->time), sep);
  582. X    (void) printf("x = %d  y = %d%s", ev->x, ev->y, sep);
  583. X    (void) printf("x_root = %d  y_root = %d%s", ev->x_root, ev->y_root, sep);
  584. X    (void) printf("state = %s%s", ButtonOrModifierState(ev->state), sep);
  585. X    (void) printf("keycode = %s%s", Keycode(ev), sep);
  586. X    (void) printf("same_screen = %s\n", TorF(ev->same_screen));
  587. X}
  588. X
  589. Xstatic void VerbProperty(ev)
  590. XXPropertyEvent *ev;
  591. X{
  592. X    (void) printf("window = 0x%x%s", ev->window, sep);
  593. X    (void) printf("atom = %s%s", AtomName(ev->display, ev->atom), sep);
  594. X    (void) printf("time = %s%s", ServerTime(ev->time), sep);
  595. X    (void) printf("state = %s\n", PropertyState(ev->state));
  596. X}
  597. X
  598. Xstatic void VerbResizeRequest(ev)
  599. XXResizeRequestEvent *ev;
  600. X{
  601. X    (void) printf("window = 0x%x%s", ev->window, sep);
  602. X    (void) printf("width = %d height = %d\n", ev->width, ev->height);
  603. X}
  604. X
  605. Xstatic void VerbCirculate(ev)
  606. XXCirculateEvent *ev;
  607. X{
  608. X    (void) printf("event = 0x%x%s", ev->event, sep);
  609. X    (void) printf("window = 0x%x%s", ev->window, sep);
  610. X    (void) printf("place = %s\n", Place(ev->place));
  611. X}
  612. X
  613. Xstatic void VerbConfigure(ev)
  614. XXConfigureEvent *ev;
  615. X{
  616. X    (void) printf("event = 0x%x%s", ev->event, sep);
  617. X    (void) printf("window = 0x%x%s", ev->window, sep);
  618. X    (void) printf("x = %d  y = %d%s", ev->x, ev->y, sep);
  619. X    (void) printf("width = %d height = %d%s", ev->width, ev->height, sep);
  620. X    (void) printf("border_width = %d%s", ev->border_width, sep);
  621. X    (void) printf("above = %s%s", MaybeNone((int) (ev->above)), sep);
  622. X    (void) printf("override_redirect = %s\n", TorF(ev->override_redirect));
  623. X}
  624. X
  625. Xstatic void VerbCreateWindow(ev)
  626. XXCreateWindowEvent *ev;
  627. X{
  628. X    (void) printf("parent = 0x%x%s", ev->parent, sep);
  629. X    (void) printf("window = 0x%x%s", ev->window, sep);
  630. X    (void) printf("x = %d  y = %d%s", ev->x, ev->y, sep);
  631. X    (void) printf("width = %d height = %d%s", ev->width, ev->height, sep);
  632. X    (void) printf("border_width = %d%s", ev->border_width, sep);
  633. X    (void) printf("override_redirect = %s\n", TorF(ev->override_redirect));
  634. X}
  635. X
  636. Xstatic void VerbDestroyWindow(ev)
  637. XXDestroyWindowEvent *ev;
  638. X{
  639. X    (void) printf("event = 0x%x%s", ev->event, sep);
  640. X    (void) printf("window = 0x%x\n", ev->window);
  641. X}
  642. X
  643. Xstatic void VerbGravity(ev)
  644. XXGravityEvent *ev;
  645. X{
  646. X    (void) printf("event = 0x%x%s", ev->event, sep);
  647. X    (void) printf("window = 0x%x%s", ev->window, sep);
  648. X    (void) printf("x = %d  y = %d\n", ev->x, ev->y);
  649. X}
  650. X
  651. Xstatic void VerbMap(ev)
  652. XXMapEvent *ev;
  653. X{
  654. X    (void) printf("event = 0x%x%s", ev->event, sep);
  655. X    (void) printf("window = 0x%x%s", ev->window, sep);
  656. X    (void) printf("override_redirect = %s\n", TorF(ev->override_redirect));
  657. X}
  658. X
  659. Xstatic void VerbReparent(ev)
  660. XXReparentEvent *ev;
  661. X{
  662. X    (void) printf("event = 0x%x%s", ev->event, sep);
  663. X    (void) printf("window = 0x%x%s", ev->window, sep);
  664. X    (void) printf("parent = 0x%x%s", ev->parent, sep);
  665. X    (void) printf("x = %d  y = %d%s", ev->x, ev->y, sep);
  666. X    (void) printf("override_redirect = %s\n", TorF(ev->override_redirect));
  667. X}
  668. X
  669. Xstatic void VerbUnmap(ev)
  670. XXUnmapEvent *ev;
  671. X{
  672. X    (void) printf("event = 0x%x%s", ev->event, sep);
  673. X    (void) printf("window = 0x%x%s", ev->window, sep);
  674. X    (void) printf("from_configure = %s\n", TorF(ev->from_configure));
  675. X}
  676. X
  677. Xstatic void VerbCirculateRequest(ev)
  678. XXCirculateRequestEvent *ev;
  679. X{
  680. X    (void) printf("parent = 0x%x%s", ev->parent, sep);
  681. X    (void) printf("window = 0x%x%s", ev->window, sep);
  682. X    (void) printf("place = %s\n", Place(ev->place));
  683. X}
  684. X
  685. Xstatic void VerbConfigureRequest(ev)
  686. XXConfigureRequestEvent *ev;
  687. X{
  688. X    (void) printf("parent = 0x%x%s", ev->parent, sep);
  689. X    (void) printf("window = 0x%x%s", ev->window, sep);
  690. X    (void) printf("x = %d  y = %d%s", ev->x, ev->y, sep);
  691. X    (void) printf("width = %d height = %d%s", ev->width, ev->height, sep);
  692. X    (void) printf("border_width = %d%s", ev->border_width, sep);
  693. X    (void) printf("above = %s%s", MaybeNone((int) (ev->above)), sep);
  694. X    (void) printf("detail = 0x%x%s", ConfigureDetail(ev->detail), sep);
  695. X    (void) printf("value_mask = %s\n", ConfigureValueMask(ev->value_mask));
  696. X}
  697. X
  698. Xstatic void VerbMapRequest(ev)
  699. XXMapRequestEvent *ev;
  700. X{
  701. X    (void) printf("parent = 0x%x%s", ev->parent, sep);
  702. X    (void) printf("window = 0x%x\n", ev->window);
  703. X}
  704. X
  705. Xstatic void VerbClient(ev)
  706. XXClientMessageEvent *ev;
  707. X{
  708. X    int ii;
  709. X
  710. X    (void) printf("window = 0x%x%s", ev->window, sep);
  711. X    (void) printf("message_type = %s%s", AtomName(ev->display,
  712. X    ev->message_type), sep);
  713. X    (void) printf("format = %d\n", ev->format);
  714. X    (void) printf("data (shown as longs) = ");
  715. X    for (ii = 0; ii < 5; ii++)
  716. X    (void) printf(" 0x%08x", ev->data.l[ii]);
  717. X    (void) printf("\n");
  718. X}
  719. X
  720. Xstatic void VerbMapping(ev)
  721. XXMappingEvent *ev;
  722. X{
  723. X    (void) printf("window = 0x%x%s", ev->window, sep);
  724. X    (void) printf("request = 0x%x%s", MappingRequest(ev->request), sep);
  725. X    (void) printf("first_keycode = 0x%x%s", ev->first_keycode, sep);
  726. X    (void) printf("count = 0x%x\n", ev->count);
  727. X}
  728. X
  729. Xstatic void VerbSelectionClear(ev)
  730. XXSelectionClearEvent *ev;
  731. X{
  732. X    (void) printf("window = 0x%x%s", ev->window, sep);
  733. X    (void) printf("selection = %s%s", AtomName(ev->display, ev->selection),
  734. X      sep);
  735. X    (void) printf("time = %s\n", ServerTime(ev->time));
  736. X}
  737. X
  738. Xstatic void VerbSelection(ev)
  739. XXSelectionEvent *ev;
  740. X{
  741. X    (void) printf("requestor = 0x%x%s", ev->requestor, sep);
  742. X    (void) printf("selection = %s%s", AtomName(ev->display, ev->selection),
  743. X      sep);
  744. X    (void) printf("target = %s%s", AtomName(ev->display, ev->target), sep);
  745. X    (void) printf("property = %s%s", AtomName(ev->display, ev->property), sep);
  746. X    (void) printf("time = %s\n", ServerTime(ev->time));
  747. X}
  748. X
  749. Xstatic void VerbSelectionRequest(ev)
  750. XXSelectionRequestEvent *ev;
  751. X{
  752. X    (void) printf("owner = 0x%x%s", ev->owner, sep);
  753. X    (void) printf("requestor = 0x%x%s", ev->requestor, sep);
  754. X    (void) printf("selection = %s%s", AtomName(ev->display, ev->selection),
  755. X      sep);
  756. X    (void) printf("target = %s%s", AtomName(ev->display, ev->target), sep);
  757. X    (void) printf("property = %s%s", AtomName(ev->display, ev->property), sep);
  758. X    (void) printf("time = %s\n", ServerTime(ev->time));
  759. X}
  760. X
  761. Xstatic void VerbVisibility(ev)
  762. XXVisibilityEvent *ev;
  763. X{
  764. X    (void) printf("window = 0x%x%s", ev->window, sep);
  765. X    (void) printf("state = %s\n", VisibilityState(ev->state));
  766. X}
  767. X
  768. X/******************************************************************************/
  769. X/************ Return the string representation for type of an event ***********/
  770. X/******************************************************************************/
  771. X
  772. Xchar *GetEventType(ev)
  773. XXEvent *ev;
  774. X{
  775. X    switch (ev->type)
  776. X    {
  777. X    case KeyPress:
  778. X    return ("KeyPress");
  779. X    case KeyRelease:
  780. X    return ("KeyRelease");
  781. X    case ButtonPress:
  782. X    return ("ButtonPress");
  783. X    case ButtonRelease:
  784. X    return ("ButtonRelease");
  785. X    case MotionNotify:
  786. X    return ("MotionNotify");
  787. X    case EnterNotify:
  788. X    return ("EnterNotify");
  789. X    case LeaveNotify:
  790. X    return ("LeaveNotify");
  791. X    case FocusIn:
  792. X    return ("FocusIn");
  793. X    case FocusOut:
  794. X    return ("FocusOut");
  795. X    case KeymapNotify:
  796. X    return ("KeymapNotify");
  797. X    case Expose:
  798. X    return ("Expose");
  799. X    case GraphicsExpose:
  800. X    return ("GraphicsExpose");
  801. X    case NoExpose:
  802. X    return ("NoExpose");
  803. X    case VisibilityNotify:
  804. X    return ("VisibilityNotify");
  805. X    case CreateNotify:
  806. X    return ("CreateNotify");
  807. X    case DestroyNotify:
  808. X    return ("DestroyNotify");
  809. X    case UnmapNotify:
  810. X    return ("UnmapNotify");
  811. X    case MapNotify:
  812. X    return ("MapNotify");
  813. X    case MapRequest:
  814. X    return ("MapRequest");
  815. X    case ReparentNotify:
  816. X    return ("ReparentNotify");
  817. X    case ConfigureNotify:
  818. X    return ("ConfigureNotify");
  819. X    case ConfigureRequest:
  820. X    return ("ConfigureRequest");
  821. X    case GravityNotify:
  822. X    return ("GravityNotify");
  823. X    case ResizeRequest:
  824. X    return ("ResizeRequest");
  825. X    case CirculateNotify:
  826. X    return ("CirculateNotify");
  827. X    case CirculateRequest:
  828. X    return ("CirculateRequest");
  829. X    case PropertyNotify:
  830. X    return ("PropertyNotify");
  831. X    case SelectionClear:
  832. X    return ("SelectionClear");
  833. X    case SelectionRequest:
  834. X    return ("SelectionRequest");
  835. X    case SelectionNotify:
  836. X    return ("SelectionNotify");
  837. X    case ColormapNotify:
  838. X    return ("ColormapNotify");
  839. X    case ClientMessage:
  840. X    return ("ClientMessage");
  841. X    case MappingNotify:
  842. X    return ("MappingNotify");
  843. X    }
  844. X    return (NULL);        /* this makes lint happy */
  845. X}
  846. X
  847. X/******************************************************************************/
  848. X/**************** Print the values of all fields for any event ****************/
  849. X/******************************************************************************/
  850. X
  851. Xvoid ShowEvent(ev)
  852. XXAnyEvent *ev;
  853. X{
  854. X    /* determine which field separator to use */
  855. X    if (use_separate_lines)
  856. X    sep = "\n";
  857. X    else
  858. X    sep = " ";
  859. X
  860. X    (void) printf("type = %s%s", GetEventType((XEvent *) ev), sep);
  861. X    (void) printf("serial = %d%s", ev->serial, sep);
  862. X    (void) printf("send_event = %s%s", TorF(ev->send_event), sep);
  863. X    (void) printf("display = 0x%x%s", ev->display, sep);
  864. X
  865. X    switch (ev->type)
  866. X    {
  867. X    case MotionNotify:
  868. X    VerbMotion((XMotionEvent *) ev);
  869. X    break;
  870. X
  871. X    case ButtonPress:
  872. X    case ButtonRelease:
  873. X    VerbButton((XButtonEvent *) ev);
  874. X    break;
  875. X
  876. X    case ColormapNotify:
  877. X    VerbColormap((XColormapEvent *) ev);
  878. X    break;
  879. X
  880. X    case EnterNotify:
  881. X    case LeaveNotify:
  882. X    VerbCrossing((XCrossingEvent *) ev);
  883. X    break;
  884. X
  885. X    case Expose:
  886. X    VerbExpose((XExposeEvent *) ev);
  887. X    break;
  888. X
  889. X    case GraphicsExpose:
  890. X    VerbGraphicsExpose((XGraphicsExposeEvent *) ev);
  891. X    break;
  892. X
  893. X    case NoExpose:
  894. X    VerbNoExpose((XNoExposeEvent *) ev);
  895. X    break;
  896. X
  897. X    case FocusIn:
  898. X    case FocusOut:
  899. X    VerbFocus((XFocusChangeEvent *) ev);
  900. X    break;
  901. X
  902. X    case KeymapNotify:
  903. X    VerbKeymap((XKeymapEvent *) ev);
  904. X    break;
  905. X
  906. X    case KeyPress:
  907. X    case KeyRelease:
  908. X    VerbKey((XKeyEvent *) ev);
  909. X    break;
  910. X
  911. X    case PropertyNotify:
  912. X    VerbProperty((XPropertyEvent *) ev);
  913. X    break;
  914. X
  915. X    case ResizeRequest:
  916. X    VerbResizeRequest((XResizeRequestEvent *) ev);
  917. X    break;
  918. X
  919. X    case CirculateNotify:
  920. X    VerbCirculate((XCirculateEvent *) ev);
  921. X    break;
  922. X
  923. X    case ConfigureNotify:
  924. X    VerbConfigure((XConfigureEvent *) ev);
  925. X    break;
  926. X
  927. X    case CreateNotify:
  928. X    VerbCreateWindow((XCreateWindowEvent *) ev);
  929. X    break;
  930. X
  931. X    case DestroyNotify:
  932. X    VerbDestroyWindow((XDestroyWindowEvent *) ev);
  933. X    break;
  934. X
  935. X    case GravityNotify:
  936. X    VerbGravity((XGravityEvent *) ev);
  937. X    break;
  938. X
  939. X    case MapNotify:
  940. X    VerbMap((XMapEvent *) ev);
  941. X    break;
  942. X
  943. X    case ReparentNotify:
  944. X    VerbReparent((XReparentEvent *) ev);
  945. X    break;
  946. X
  947. X    case UnmapNotify:
  948. X    VerbUnmap((XUnmapEvent *) ev);
  949. X    break;
  950. X
  951. X    case CirculateRequest:
  952. X    VerbCirculateRequest((XCirculateRequestEvent *) ev);
  953. X    break;
  954. X
  955. X    case ConfigureRequest:
  956. X    VerbConfigureRequest((XConfigureRequestEvent *) ev);
  957. X    break;
  958. X
  959. X    case MapRequest:
  960. X    VerbMapRequest((XMapRequestEvent *) ev);
  961. X    break;
  962. X
  963. X    case ClientMessage:
  964. X    VerbClient((XClientMessageEvent *) ev);
  965. X    break;
  966. X
  967. X    case MappingNotify:
  968. X    VerbMapping((XMappingEvent *) ev);
  969. X    break;
  970. X
  971. X    case SelectionClear:
  972. X    VerbSelectionClear((XSelectionClearEvent *) ev);
  973. X    break;
  974. X
  975. X    case SelectionNotify:
  976. X    VerbSelection((XSelectionEvent *) ev);
  977. X    break;
  978. X
  979. X    case SelectionRequest:
  980. X    VerbSelectionRequest((XSelectionRequestEvent *) ev);
  981. X    break;
  982. X
  983. X    case VisibilityNotify:
  984. X    VerbVisibility((XVisibilityEvent *) ev);
  985. X    break;
  986. X
  987. X    }
  988. X}
  989. END_OF_FILE
  990. if test 23550 -ne `wc -c <'common/showEvent.c'`; then
  991.     echo shar: \"'common/showEvent.c'\" unpacked with wrong size!
  992. fi
  993. # end of 'common/showEvent.c'
  994. fi
  995. if test -f 'gencmap/Imakefile' -a "${1}" != "-c" ; then 
  996.   echo shar: Will not clobber existing file \"'gencmap/Imakefile'\"
  997. else
  998. echo shar: Extracting \"'gencmap/Imakefile'\" \(394 characters\)
  999. sed "s/^X//" >'gencmap/Imakefile' <<'END_OF_FILE'
  1000. X       INCLUDES = -I../headers
  1001. X      COMMONLIB = ../common/libcommon.a
  1002. X        DEPLIBS = $(COMMONLIB) $(DEPXLIB)
  1003. X  SYS_LIBRARIES = -lm
  1004. X
  1005. X#ifdef UltrixArchitecture
  1006. XLOCAL_LIBRARIES = $(DEPLIBS)
  1007. X#else
  1008. XLOCAL_LIBRARIES = $(COMMONLIB) $(XLIB)
  1009. X#endif
  1010. X
  1011. XSRCS = \
  1012. X    gencmap.c
  1013. X
  1014. XOBJS = \
  1015. X    gencmap.o
  1016. X
  1017. XComplexProgramTarget(gencmap)
  1018. X
  1019. Xsaber_src:
  1020. X    #cd ../common
  1021. X    #make saber
  1022. X    #cd ../gencmap
  1023. X    #make saber_gencmap
  1024. X
  1025. END_OF_FILE
  1026. if test 394 -ne `wc -c <'gencmap/Imakefile'`; then
  1027.     echo shar: \"'gencmap/Imakefile'\" unpacked with wrong size!
  1028. fi
  1029. # end of 'gencmap/Imakefile'
  1030. fi
  1031. if test -f 'gencmap/gencmap.c' -a "${1}" != "-c" ; then 
  1032.   echo shar: Will not clobber existing file \"'gencmap/gencmap.c'\"
  1033. else
  1034. echo shar: Extracting \"'gencmap/gencmap.c'\" \(3267 characters\)
  1035. sed "s/^X//" >'gencmap/gencmap.c' <<'END_OF_FILE'
  1036. X/*
  1037. X * Copyright (c) Ken W. Marks 1989, 1990.
  1038. X */
  1039. X
  1040. X#include <stdio.h>
  1041. X#include <ctype.h>
  1042. X#include <math.h>
  1043. X#include <values.h>
  1044. X#include <X11/Intrinsic.h>
  1045. X#include <Colormap.h>
  1046. X
  1047. X#ifndef M_PI
  1048. X#define M_PI    3.14159265358979323846
  1049. X#endif
  1050. X
  1051. Xchar *map_dir = ".";
  1052. X
  1053. X
  1054. Xvoid SineFunc(n, red, green, blue, closure)
  1055. Xint n;
  1056. Xunsigned char *red;
  1057. Xunsigned char *green;
  1058. Xunsigned char *blue;
  1059. Xcaddr_t closure;
  1060. X{
  1061. X    double radians;
  1062. X    int reps = (int) closure;
  1063. X
  1064. X    radians = (double) (n - NUM_RESERVED) / (double) (NUM_COLORS -
  1065. X      NUM_RESERVED) * 2.0 * M_PI * (double) reps;
  1066. X
  1067. X    *red = (unsigned char) (fabs(sin(radians)) *
  1068. X      (double) MAX_INTENSITY);
  1069. X
  1070. X    *green = (unsigned char) (fabs(sin(radians + 2.0 / 3.0 * M_PI)) *
  1071. X      (double) MAX_INTENSITY);
  1072. X
  1073. X    *blue = (unsigned char) (fabs(sin(radians + 4.0 / 3.0 * M_PI)) *
  1074. X      (double) MAX_INTENSITY);
  1075. X}
  1076. X
  1077. X
  1078. Xvoid ZebraFunc(n, red, green, blue)
  1079. Xint n;
  1080. Xunsigned char *red;
  1081. Xunsigned char *green;
  1082. Xunsigned char *blue;
  1083. X{
  1084. X    double radians;
  1085. X    double hue, sat, bright;
  1086. X    double r, g, b;
  1087. X
  1088. X    radians = (double) (n - NUM_RESERVED) / (double) (NUM_COLORS -
  1089. X      NUM_RESERVED) * 2.0 * M_PI;
  1090. X
  1091. X    *red = (unsigned char) (fabs(sin(radians)) *
  1092. X      (double) MAX_INTENSITY);
  1093. X
  1094. X    *green = (unsigned char) (fabs(sin(radians + 2.0 / 3.0 * M_PI)) *
  1095. X      (double) MAX_INTENSITY);
  1096. X
  1097. X    *blue = (unsigned char) (fabs(sin(radians + 4.0 / 3.0 * M_PI)) *
  1098. X      (double) MAX_INTENSITY);
  1099. X
  1100. X    RGB2HSB((double) *red / 255.0, (double) *green / 255.0,
  1101. X      (double) *blue / 255.0, &hue, &sat, &bright);
  1102. X
  1103. X    switch (n % 4)
  1104. X    {
  1105. X    case 0:
  1106. X    bright *= 0.70;
  1107. X    break;
  1108. X
  1109. X    case 1:
  1110. X    bright *= 0.90;
  1111. X    break;
  1112. X
  1113. X    case 2:
  1114. X    bright *= 0.80;
  1115. X    break;
  1116. X
  1117. X    case 3:
  1118. X    bright *= 1.00;
  1119. X    break;
  1120. X    }
  1121. X
  1122. X
  1123. X    HSB2RGB(hue, sat, bright, &r, &g, &b);
  1124. X
  1125. X    *red = (unsigned char) (r * 255.0);
  1126. X    *green = (unsigned char) (g * 255.0);
  1127. X    *blue = (unsigned char) (b * 255.0);
  1128. X}
  1129. X
  1130. X
  1131. Xusage(cmd)
  1132. Xchar *cmd;
  1133. X{
  1134. X    (void) fprintf(stderr, "usage: %s [ -ghorstz ] filename\n", cmd);
  1135. X    exit(1);
  1136. X}
  1137. X
  1138. X
  1139. Xmain(argc, argv)
  1140. Xint argc;
  1141. Xchar *argv[];
  1142. X{
  1143. X    char *cmd = argv[0];
  1144. X    char *value;
  1145. X    int reps;
  1146. X    extern char *getenv();
  1147. X
  1148. X    if (argc != 3)
  1149. X    usage(cmd);
  1150. X
  1151. X    if (value = getenv("MAPDIR"))
  1152. X    map_dir = value;
  1153. X
  1154. X    if (strncmp(argv[1], "-g", 2) == 0)
  1155. X    {
  1156. X    /* Store gray-scale colormap */
  1157. X    reps = (int) (isdigit(argv[1][2]) ? argv[1][2] - '0' : 1);
  1158. X    StoreGray(reps);
  1159. X    }
  1160. X    else if (strncmp(argv[1], "-h", 2) == 0)
  1161. X    {
  1162. X    /* Store Hue-Saturation-Brightness colormap */
  1163. X    reps = (int) (isdigit(argv[1][2]) ? argv[1][2] - '0' : 1);
  1164. X    StoreHSB(reps);
  1165. X    }
  1166. X    else if (strncmp(argv[1], "-o", 2) == 0)
  1167. X    {
  1168. X    /* Store 8 color (octo) colormap */
  1169. X    StoreOctoColor();
  1170. X    }
  1171. X    else if (strncmp(argv[1], "-r", 2) == 0)
  1172. X    {
  1173. X    /* Store random colormap */
  1174. X    StoreRandom();
  1175. X    }
  1176. X    else if (strncmp(argv[1], "-s", 2) == 0)
  1177. X    {
  1178. X    /* Store sine colormap */
  1179. X    reps = (int) (isdigit(argv[1][2]) ? argv[1][2] - '0' : 1);
  1180. X    StoreColors(SineFunc, (caddr_t) reps);
  1181. X    }
  1182. X    else if (strncmp(argv[1], "-t", 2) == 0)
  1183. X    {
  1184. X    /* Store 3 color (RGB) colormap */
  1185. X    StoreTriColor();
  1186. X    }
  1187. X    else if (strncmp(argv[1], "-z", 2) == 0)
  1188. X    {
  1189. X    /* Store funky zebra colormap */
  1190. X    StoreColors(ZebraFunc, (caddr_t) NULL);
  1191. X    }
  1192. X    else
  1193. X    usage(cmd);
  1194. X
  1195. X    (void) WriteColors(".", argv[2]);
  1196. X    exit(0);
  1197. X}
  1198. END_OF_FILE
  1199. if test 3267 -ne `wc -c <'gencmap/gencmap.c'`; then
  1200.     echo shar: \"'gencmap/gencmap.c'\" unpacked with wrong size!
  1201. fi
  1202. # end of 'gencmap/gencmap.c'
  1203. fi
  1204. if test -f 'widgets/List.c' -a "${1}" != "-c" ; then 
  1205.   echo shar: Will not clobber existing file \"'widgets/List.c'\"
  1206. else
  1207. echo shar: Extracting \"'widgets/List.c'\" \(23630 characters\)
  1208. sed "s/^X//" >'widgets/List.c' <<'END_OF_FILE'
  1209. X/*
  1210. X * Copyright (c) Ken W. Marks 1989, 1990.
  1211. X */
  1212. X
  1213. X#include <stdio.h>
  1214. X#include <X11/IntrinsicP.h>
  1215. X#include <X11/StringDefs.h>
  1216. X#include <Chaos.h>
  1217. X#include <LocalDefs.h>
  1218. X#include <ListP.h>
  1219. X#include <Colormap.h>
  1220. X#include <DlgShell.h>
  1221. X
  1222. X#define IN_UP_ARROW(w, x, y)    (((x) >= (w)->list.item_width && \
  1223. X                (x) < (w)->core.width && \
  1224. X                (y) >= 0 && \
  1225. X                (y) < (w)->list.char_height) ? True : False)
  1226. X
  1227. X#define IN_DOWN_ARROW(w, x, y)    (((x) >= (w)->list.item_width && \
  1228. X                (x) < (w)->core.width && \
  1229. X                (y) > (w)->core.height - (w)->list.char_height \
  1230. X                && (y) < (w)->core.height) ? True : False)
  1231. X
  1232. X#define IN_SCROLLBAR(w, x, y)    (((x) >= (w)->list.item_width && \
  1233. X                (x) < (w)->core.width && \
  1234. X                (y) >= (w)->list.char_height && \
  1235. X                (y) <= (w)->core.height - \
  1236. X                (w)->list.char_height) ? True : False)
  1237. X
  1238. X#define GET_ITEM(w, x, y)    (((x) >= (w)->list.item_width || \
  1239. X                (x) < 0 || \
  1240. X                (y) < 0 || \
  1241. X                (y) >= (w)->core.height) ? NO_ITEM : \
  1242. X                (y) / (w)->list.item_height + \
  1243. X                (w)->list.first_visible_item)
  1244. X
  1245. X#define NEAREST_ITEM(w, y)    (((y) - (w)->list.char_height) * \
  1246. X                (w)->list.num_stops / (w)->list.bar_height)
  1247. X
  1248. X#define ITEM_POS(w, item)    ((short) (item * (w)->list.bar_height / \
  1249. X                (w)->list.num_stops + 3 * \
  1250. X                (w)->list.char_height / 2))
  1251. X
  1252. X#define BEFORE_VIEW(w, item)    ((item < (w)->list.first_visible_item) ? \
  1253. X                True : False)
  1254. X
  1255. X#define AFTER_VIEW(w, item)    ((item >= (w)->list.first_visible_item + \
  1256. X                (w)->list.num_visible) ? True : False)
  1257. X
  1258. X/* internal padding for items in list buttons */
  1259. X#define VERTICAL_PAD        2
  1260. X#define HORIZONTAL_PAD        2
  1261. X
  1262. X/* default number of items visible */
  1263. X#define DEFAULT_VISIBLE        5
  1264. X
  1265. X#define UP_ARROW_STRING        "\016\017"
  1266. X#define DOWN_ARROW_STRING    "\020\021"
  1267. X#define SLOT_STRING        "\022\023"
  1268. X#define KNOB_STRING        "\024\025"
  1269. X
  1270. X#define ARROW            '\037'
  1271. X#define BLANK            '\036'
  1272. X
  1273. Xstatic void ListInitialize();
  1274. Xstatic void ListRealize();
  1275. Xstatic void ListRedisplay();
  1276. Xstatic void ListDestroy();
  1277. Xstatic void ListDrawItem();
  1278. Xstatic void ListDrawItems();
  1279. Xstatic void ListDrawBar();
  1280. Xstatic void ListDrawAll();
  1281. Xstatic void ListMoveKnob();
  1282. Xstatic void ListUnselectIfUnseen();
  1283. Xstatic void ListScrollBackward();
  1284. Xstatic void ListScrollForward();
  1285. Xstatic void ListNotify();
  1286. Xstatic void ListMark();
  1287. Xstatic void ListGoto();
  1288. Xstatic void ListFocusIn();
  1289. Xstatic void ListFocusOut();
  1290. Xstatic void ListBtnUp();
  1291. Xstatic void ListMotion();
  1292. X
  1293. X#define offset(field) XtOffset(ListWidget, list.field)
  1294. X#define goffset(field) XtOffset(Widget,core.field)
  1295. X
  1296. Xstatic XtResource list_resources[] = {
  1297. X    {XtNlistDefault, XtCDefault, XtRInt, sizeof(int),
  1298. X    offset(selected_item), XtRImmediate, (caddr_t) 0},
  1299. X    {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
  1300. X    offset(foreground), XtRString, "Black"},
  1301. X    {XtNbackground, XtCBackground, XtRPixel, sizeof(Pixel),
  1302. X    goffset(background_pixel), XtRString, "White"},
  1303. X    {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
  1304. X    offset(font), XtRString, "chaos-bold"},
  1305. X    {XtNlistItems, XtCList, XtRPointer, sizeof(char **),
  1306. X    offset(list_items), XtRString, NULL},
  1307. X    {XtNhorizPad, XtCMargin, XtRDimension, sizeof(Dimension),
  1308. X    offset(h_pad), XtRImmediate, (caddr_t) HORIZONTAL_PAD},
  1309. X    {XtNvertPad, XtCMargin, XtRDimension, sizeof(Dimension),
  1310. X    offset(v_pad), XtRImmediate, (caddr_t) VERTICAL_PAD},
  1311. X    {XtNcallback, XtCCallback, XtRCallback, sizeof(caddr_t),
  1312. X    offset(callbacks), XtRCallback, (caddr_t) NULL},
  1313. X    {XtNdialogbox, XtCWidget, XtRWidget, sizeof(Widget),
  1314. X    offset(dialogbox), XtRWidget, (caddr_t) NULL},
  1315. X    {XtNnumberVisible, XtCDefault, XtRInt, sizeof(int),
  1316. X    offset(num_visible), XtRImmediate, (caddr_t) DEFAULT_VISIBLE},
  1317. X    {XtNcharsWide, XtCDefault, XtRInt, sizeof(int),
  1318. X    offset(chars_wide), XtRImmediate, (caddr_t) 0},
  1319. X};
  1320. X
  1321. Xstatic XtActionsRec list_actions[] =
  1322. X{
  1323. X    {"notify", ListNotify},
  1324. X    {"mark", ListMark},
  1325. X    {"goto", ListGoto},
  1326. X    {"focus_in", ListFocusIn},
  1327. X    {"focus_out", ListFocusOut},
  1328. X    {"release", ListBtnUp},
  1329. X    {"move", ListMotion},
  1330. X};
  1331. X
  1332. Xstatic char list_translations[] =
  1333. X"<BtnDown>:        mark(BUTTON) notify(BUTTON)\n\
  1334. X <BtnUp>:        release()\n\
  1335. X <Motion>:        move()\n\
  1336. X <Key>Return:        notify(KEY)\n\
  1337. X <Key>Up:        mark(PREV)\n\
  1338. X <Key>Down:        mark(NEXT)\n\
  1339. X Shift<Key>Tab:        goto(PREV)\n\
  1340. X <Key>Tab:        goto(NEXT)\n\
  1341. X <FocusIn>:        focus_in()\n\
  1342. X <FocusOut>:        focus_out()\n\
  1343. X";
  1344. X
  1345. X#define superclass        (&simpleClassRec)
  1346. X
  1347. XListClassRec listClassRec = {
  1348. X    {
  1349. X    /* core fields          */
  1350. X     /* superclass         */ (WidgetClass) superclass,
  1351. X     /* class_name         */ "List",
  1352. X     /* widget_size         */ sizeof(ListRec),
  1353. X     /* class_initialize     */ NULL,
  1354. X     /* class_part_initialize */ NULL,
  1355. X     /* class_inited     */ FALSE,
  1356. X     /* initialize         */ ListInitialize,
  1357. X     /* initialize_hook     */ NULL,
  1358. X     /* realize         */ ListRealize,
  1359. X     /* actions         */ list_actions,
  1360. X     /* num_actions         */ XtNumber(list_actions),
  1361. X     /* resources         */ list_resources,
  1362. X     /* resource_count     */ XtNumber(list_resources),
  1363. X     /* xrm_class         */ NULLQUARK,
  1364. X     /* compress_motion     */ TRUE,
  1365. X     /* compress_exposure     */ TRUE,
  1366. X     /* compress_enterleave     */ TRUE,
  1367. X     /* visible_interest     */ FALSE,
  1368. X     /* destroy         */ ListDestroy,
  1369. X     /* resize         */ NULL,
  1370. X     /* expose         */ ListRedisplay,
  1371. X     /* set_values         */ NULL,
  1372. X     /* set_values_hook     */ NULL,
  1373. X     /* set_values_almost     */ XtInheritSetValuesAlmost,
  1374. X     /* get_values_hook     */ NULL,
  1375. X     /* accept_focus     */ NULL,
  1376. X     /* version         */ XtVersion,
  1377. X     /* callback_private     */ NULL,
  1378. X     /* tm_table         */ list_translations,
  1379. X     /* query_geometry       */ NULL,
  1380. X     /* display_accelerator     */ XtInheritDisplayAccelerator,
  1381. X     /* extension         */ NULL
  1382. X    },
  1383. X    {
  1384. X    /* Simple class fields initialization */
  1385. X     /* change_sensitive     */ XtInheritChangeSensitive
  1386. X    }
  1387. X};
  1388. X
  1389. X
  1390. XWidgetClass listWidgetClass = (WidgetClass) & listClassRec;
  1391. X
  1392. X
  1393. X/************************************************************/
  1394. X/******************** Private Procedures ********************/
  1395. X/************************************************************/
  1396. X
  1397. X
  1398. Xstatic void ListCopyItems(w)
  1399. XListWidget w;
  1400. X{
  1401. X    int ii;
  1402. X    char *label;
  1403. X
  1404. X    if (w->list.list_items == NULL)
  1405. X    {
  1406. X    w->list.list_items = (ListItem *) malloc(sizeof(ListItem));
  1407. X    w->list.list_items[0].label = NULL;
  1408. X    w->list.num_items = 0;
  1409. X    return;
  1410. X    }
  1411. X
  1412. X    /* SUPPRESS 530 */
  1413. X    for (ii = 0; w->list.list_items[ii].label != NULL; ++ii);
  1414. X
  1415. X    w->list.num_items = ii;
  1416. X
  1417. X    /* Allocate a private copy of the list structure so that it doesn't change
  1418. X     * from under us. */
  1419. X
  1420. X    w->list.list_items = (ListItem *) COPY(w->list.list_items, (ii + 1) *
  1421. X      sizeof(ListItem));
  1422. X
  1423. X    /* And don't forget to make private copies of all the labels in the
  1424. X     * structures (with space for 1 special leading char). */
  1425. X
  1426. X    while (--ii >= 0)
  1427. X    {
  1428. X    label = w->list.list_items[ii].label;
  1429. X    w->list.list_items[ii].label = malloc((unsigned) (strlen(label) + 2));
  1430. X    w->list.list_items[ii].label[0] = BLANK;
  1431. X    (void) strcpy(&(w->list.list_items[ii].label[1]), label);
  1432. X    }
  1433. X}
  1434. X
  1435. X
  1436. Xstatic void ListFreeItems(w)
  1437. XListWidget w;
  1438. X{
  1439. X    ListItem *ptr = w->list.list_items;
  1440. X
  1441. X    while (ptr->label != NULL)
  1442. X    {
  1443. X    free(ptr->label);
  1444. X    ++ptr;
  1445. X    }
  1446. X    free((char *) w->list.list_items);
  1447. X}
  1448. X
  1449. X
  1450. Xstatic void ListGetGC(w)
  1451. XListWidget w;
  1452. X{
  1453. X    XGCValues values;
  1454. X
  1455. X    values.foreground = w->list.foreground;
  1456. X    values.background = w->core.background_pixel;
  1457. X    values.font = w->list.font->fid;
  1458. X
  1459. X    w->list.normal_gc = XtGetGC((Widget) w, (unsigned) GCForeground |
  1460. X      GCBackground | GCFont, &values);
  1461. X
  1462. X    values.foreground = w->core.background_pixel;
  1463. X    values.background = w->list.foreground;
  1464. X
  1465. X    w->list.reverse_gc = XtGetGC((Widget) w, (unsigned) GCForeground |
  1466. X      GCBackground | GCFont, &values);
  1467. X}
  1468. X
  1469. X
  1470. Xstatic void ListSetSize(w)
  1471. XListWidget w;
  1472. X{
  1473. X    XtWidgetGeometry my_request;
  1474. X    XFontStruct *fs = w->list.font;
  1475. X    ListItem *item;
  1476. X    Cardinal height = fs->max_bounds.ascent + fs->max_bounds.descent;
  1477. X    Cardinal width = fs->max_bounds.width;
  1478. X    Cardinal label_width;
  1479. X    char *label;
  1480. X    int ii;
  1481. X
  1482. X    item = w->list.list_items;
  1483. X    for (ii = 0; ii < w->list.num_items; ++ii)
  1484. X    {
  1485. X    label = item->label;
  1486. X    label_width = STRLEN(label);
  1487. X    if (label == NULL)
  1488. X        break;
  1489. X    w->list.chars_wide = MAX(w->list.chars_wide, label_width);
  1490. X    ++item;
  1491. X    }
  1492. X
  1493. X    w->list.item_width = w->list.chars_wide * width + 2 * w->list.h_pad;
  1494. X    w->list.baseline = fs->max_bounds.ascent;
  1495. X    w->list.baseline_to_center = height / 2 - w->list.baseline;
  1496. X    w->list.char_width = width;
  1497. X    w->list.char_height = height;
  1498. X    w->list.item_height = height + 2 * w->list.v_pad;
  1499. X
  1500. X    my_request.request_mode = CWWidth | CWHeight | CWBorderWidth;
  1501. X    my_request.width = w->list.item_width + 2 * width;
  1502. X    my_request.height = w->list.item_height * w->list.num_visible;
  1503. X    my_request.border_width = 1;
  1504. X
  1505. X    XtMakeGeometryRequest((Widget) w, &my_request, NULL);
  1506. X
  1507. X    w->list.bar_min_y = height + fs->max_bounds.ascent;
  1508. X    w->list.bar_max_y = w->core.height - (height + fs->max_bounds.descent);
  1509. X}
  1510. X
  1511. X
  1512. X/*ARGSUSED*/
  1513. Xstatic void ListInitialize(request, new)
  1514. XWidget request;            /* unused */
  1515. XWidget new;
  1516. X{
  1517. X    ListWidget w = (ListWidget) new;
  1518. X
  1519. X    if (w->list.dialogbox == NULL)
  1520. X    {
  1521. X    eprintf("XtNdialogbox not set\n");
  1522. X    abort();
  1523. X    }
  1524. X
  1525. X    if (w->list.num_visible < DEFAULT_VISIBLE)
  1526. X    {
  1527. X    eprintf("XtNnumberVisible must be at least %d\n", DEFAULT_VISIBLE);
  1528. X    abort();
  1529. X    }
  1530. X    ListGetGC(w);
  1531. X    ListCopyItems(w);
  1532. X    ListSetSize(w);
  1533. X
  1534. X    w->list.active_item = NO_ITEM;
  1535. X    w->list.first_visible_item = 0;
  1536. X    w->list.num_stops = w->list.num_items - w->list.num_visible + 1;
  1537. X    if (w->list.num_stops < 1)
  1538. X    w->list.num_stops = 1;
  1539. X    w->list.bar_height = w->core.height - 2 * w->list.char_height;
  1540. X    w->list.bar_offset = w->list.char_height + w->list.baseline +
  1541. X      w->list.baseline_to_center;
  1542. X    w->list.knob_y = w->list.bar_min_y;
  1543. X    w->list.scrolling = False;
  1544. X}
  1545. X
  1546. X
  1547. Xstatic void ListRealize(widget, valueMask, attrs)
  1548. XWidget widget;
  1549. XXtValueMask *valueMask;
  1550. XXSetWindowAttributes *attrs;
  1551. X{
  1552. X    ListWidget w = (ListWidget) widget;
  1553. X    Display *dpy = XtDisplay(w);
  1554. X    Window window;
  1555. X    Position y;
  1556. X
  1557. X    XtCreateWindow(widget, InputOutput, (Visual *) CopyFromParent,
  1558. X      *valueMask, attrs);
  1559. X
  1560. X    window = XtWindow(w);
  1561. X
  1562. X    w->list.pixmap = XCreatePixmap(dpy, window, w->list.char_width * 2,
  1563. X      w->core.height, w->core.depth);
  1564. X
  1565. X    if (!w->list.pixmap)
  1566. X    {
  1567. X    eprintf("Insufficient space for pixmap\n");
  1568. X    abort();
  1569. X    }
  1570. X
  1571. X    y = w->list.baseline;
  1572. X    XDrawImageString(dpy, w->list.pixmap, w->list.normal_gc, 0, y,
  1573. X      UP_ARROW_STRING, 2);
  1574. X
  1575. X    for (y = w->list.char_height + w->list.baseline;
  1576. X      y < w->core.height - w->list.char_height + w->list.baseline;
  1577. X      y += w->list.char_height)
  1578. X    XDrawImageString(dpy, w->list.pixmap, w->list.normal_gc, 0, y,
  1579. X      SLOT_STRING, 2);
  1580. X
  1581. X    y = w->core.height - w->list.char_height + w->list.baseline;
  1582. X    XDrawImageString(dpy, w->list.pixmap, w->list.normal_gc, 0, y,
  1583. X      DOWN_ARROW_STRING, 2);
  1584. X
  1585. X    XDrawImageString(dpy, w->list.pixmap, w->list.normal_gc, 0, w->list.knob_y,
  1586. X      KNOB_STRING, 2);
  1587. X}
  1588. X
  1589. X
  1590. X/*ARGSUSED*/
  1591. Xstatic void ListRedisplay(widget, event, region)
  1592. XWidget widget;
  1593. XXEvent *event;            /* unused */
  1594. XRegion region;            /* unused */
  1595. X{
  1596. X    if (XtIsRealized(widget) == False)
  1597. X    return;
  1598. X
  1599. X    ListDrawAll(widget);
  1600. X}
  1601. X
  1602. X
  1603. Xstatic void ListDestroy(widget)
  1604. XWidget widget;
  1605. X{
  1606. X    ListWidget w = (ListWidget) widget;
  1607. X
  1608. X    XtReleaseGC(widget, w->list.normal_gc);
  1609. X    XtReleaseGC(widget, w->list.reverse_gc);
  1610. X}
  1611. X
  1612. X
  1613. Xstatic void ListDrawItem(widget, item)
  1614. XWidget widget;
  1615. Xint item;
  1616. X{
  1617. X    ListWidget w = (ListWidget) widget;
  1618. X    Display *dpy = XtDisplay(w);
  1619. X    Window window = XtWindow(w);
  1620. X    int absolute_item;
  1621. X    char *label;
  1622. X    Position x, y;
  1623. X    int label_len;
  1624. X    GC fill_gc;
  1625. X    GC draw_gc;
  1626. X
  1627. X    if (item <= NO_ITEM || item > w->list.num_visible)
  1628. X    return;
  1629. X
  1630. X    absolute_item = item + w->list.first_visible_item;
  1631. X
  1632. X    if (absolute_item >= w->list.num_items)
  1633. X    label = NULL;
  1634. X    else
  1635. X    {
  1636. X    label = w->list.list_items[absolute_item].label;
  1637. X
  1638. X    if (absolute_item == w->list.active_item)
  1639. X        label[0] = ARROW;
  1640. X    else
  1641. X        label[0] = BLANK;
  1642. X    }
  1643. X
  1644. X    x = (Position) w->list.h_pad;
  1645. X    y = (Position) w->list.item_height * item + w->list.v_pad +
  1646. X      w->list.baseline;
  1647. X
  1648. X    if (XtIsRealized(widget))
  1649. X    {
  1650. X
  1651. X    if (absolute_item == w->list.selected_item)
  1652. X    {
  1653. X        fill_gc = w->list.normal_gc;
  1654. X        draw_gc = w->list.reverse_gc;
  1655. X    }
  1656. X    else
  1657. X    {
  1658. X        fill_gc = w->list.reverse_gc;
  1659. X        draw_gc = w->list.normal_gc;
  1660. X    }
  1661. X
  1662. X    label_len = STRLEN(label);
  1663. X
  1664. X    if (label_len != 0)
  1665. X        XDrawImageString(dpy, window, draw_gc, x, y, label, label_len);
  1666. X
  1667. X    XFillRectangle(dpy, window, fill_gc, x + label_len *
  1668. X      w->list.char_width, y - w->list.baseline, (w->list.chars_wide -
  1669. X        label_len) * w->list.char_width, w->list.char_height);
  1670. X    }
  1671. X}
  1672. X
  1673. X
  1674. Xstatic void ListDrawItems(widget)
  1675. XWidget widget;
  1676. X{
  1677. X    ListWidget w = (ListWidget) widget;
  1678. X    int ii;
  1679. X
  1680. X    for (ii = 0; ii < w->list.num_visible; ++ii)
  1681. X    ListDrawItem(widget, ii);
  1682. X}
  1683. X
  1684. X
  1685. Xstatic void ListDrawBar(widget)
  1686. XWidget widget;
  1687. X{
  1688. X    ListWidget w = (ListWidget) widget;
  1689. X    Display *dpy = XtDisplay(w);
  1690. X    Window window = XtWindow(w);
  1691. X
  1692. X    if (XtIsRealized(widget))
  1693. X    XCopyArea(dpy, w->list.pixmap, window, w->list.normal_gc,
  1694. X      0, 0, w->list.char_width * 2, w->core.height, w->list.item_width, 0);
  1695. X}
  1696. X
  1697. X
  1698. Xstatic void ListDrawAll(widget)
  1699. XWidget widget;
  1700. X{
  1701. X    ListDrawItems(widget);
  1702. X    ListDrawBar(widget);
  1703. X}
  1704. X
  1705. X
  1706. Xstatic void ListMoveKnob(widget, y)
  1707. XWidget widget;
  1708. XPosition y;
  1709. X{
  1710. X    ListWidget w = (ListWidget) widget;
  1711. X    Display *dpy = XtDisplay(w);
  1712. X
  1713. X    y -= w->list.baseline_to_center;
  1714. X
  1715. X    if (y < w->list.bar_min_y)
  1716. X    y = w->list.bar_min_y;
  1717. X    else if (y > w->list.bar_max_y)
  1718. X    y = w->list.bar_max_y;
  1719. X
  1720. X    if (y == w->list.knob_y)
  1721. X    return;
  1722. X
  1723. X    /* Erase the old knob */
  1724. X    XDrawImageString(dpy, w->list.pixmap, w->list.normal_gc, 0, w->list.knob_y,
  1725. X      SLOT_STRING, 2);
  1726. X
  1727. X    w->list.knob_y = y;
  1728. X
  1729. X    /* Draw new knob */
  1730. X    XDrawImageString(dpy, w->list.pixmap, w->list.normal_gc, 0, w->list.knob_y,
  1731. X      KNOB_STRING, 2);
  1732. X
  1733. X    ListDrawBar(widget);
  1734. X}
  1735. X
  1736. X
  1737. Xstatic void ListUnselectIfUnseen(widget)
  1738. XWidget widget;
  1739. X{
  1740. X    ListWidget w = (ListWidget) widget;
  1741. X
  1742. X    if (BEFORE_VIEW(w, w->list.selected_item) ||
  1743. X      AFTER_VIEW(w, w->list.selected_item))
  1744. X    w->list.selected_item = NO_ITEM;
  1745. X}
  1746. X
  1747. X
  1748. Xstatic void ListScrollBackward(widget)
  1749. XWidget widget;
  1750. X{
  1751. X    ListWidget w = (ListWidget) widget;
  1752. X
  1753. X    if (w->list.first_visible_item == 0)
  1754. X    return;
  1755. X
  1756. X    --w->list.first_visible_item;
  1757. X
  1758. X    if (AFTER_VIEW(w, w->list.active_item))
  1759. X    --w->list.active_item;
  1760. X
  1761. X    /* If the selected item becomes unseen, unselect it */
  1762. X    ListUnselectIfUnseen(widget);
  1763. X    ListDrawItems(widget);
  1764. X    ListMoveKnob(widget, ITEM_POS(w, w->list.first_visible_item));
  1765. X}
  1766. X
  1767. X
  1768. Xstatic void ListScrollForward(widget)
  1769. XWidget widget;
  1770. X{
  1771. X    ListWidget w = (ListWidget) widget;
  1772. X
  1773. X    if (w->list.first_visible_item >= w->list.num_stops - 1)
  1774. X    return;
  1775. X
  1776. X    ++w->list.first_visible_item;
  1777. X
  1778. X    if (BEFORE_VIEW(w, w->list.active_item))
  1779. X    ++w->list.active_item;
  1780. X
  1781. X    /* If the selected item becomes unseen, unselect it */
  1782. X    ListUnselectIfUnseen(widget);
  1783. X    ListDrawItems(widget);
  1784. X    ListMoveKnob(widget, ITEM_POS(w, w->list.first_visible_item));
  1785. X}
  1786. X
  1787. X
  1788. Xstatic void ListScrollTo(widget, y)
  1789. XWidget widget;
  1790. Xint y;
  1791. X{
  1792. X    ListWidget w = (ListWidget) widget;
  1793. X    int item;
  1794. X
  1795. X    ListMoveKnob(widget, y);
  1796. X
  1797. X    item = NEAREST_ITEM(w, y);
  1798. X    if (item == w->list.first_visible_item)
  1799. X    return;
  1800. X
  1801. X    w->list.first_visible_item = item;
  1802. X
  1803. X    if (BEFORE_VIEW(w, w->list.active_item) ||
  1804. X      AFTER_VIEW(w, w->list.active_item))
  1805. X    w->list.active_item = w->list.first_visible_item;
  1806. X
  1807. X    /* If the selected item becomes unseen, unselect it */
  1808. X    ListUnselectIfUnseen(widget);
  1809. X    ListDrawItems(widget);
  1810. X}
  1811. X
  1812. X
  1813. Xstatic void ListStartScroll(widget, y)
  1814. XWidget widget;
  1815. Xint y;
  1816. X{
  1817. X    ListWidget w = (ListWidget) widget;
  1818. X
  1819. X    w->list.scrolling = True;
  1820. X
  1821. X    ListScrollTo(widget, y);
  1822. X}
  1823. X
  1824. X
  1825. X/***********************************************************/
  1826. X/******************** Action Procedures ********************/
  1827. X/***********************************************************/
  1828. X
  1829. X
  1830. X/*ARGSUSED*/
  1831. Xstatic void ListFocusIn(widget, event, params, num_params)
  1832. XWidget widget;
  1833. XXEvent *event;
  1834. XString *params;
  1835. XCardinal *num_params;        /* unused */
  1836. X{
  1837. X    ListWidget w = (ListWidget) widget;
  1838. X    XFocusInEvent *ev = (XFocusInEvent *) & event->xfocus;
  1839. X
  1840. X    if (ev->mode != NotifyGrab)
  1841. X        return;
  1842. X
  1843. X    if (w->list.active_item == NO_ITEM)
  1844. X    w->list.active_item = w->list.first_visible_item;
  1845. X
  1846. X    ListDrawAll(widget);
  1847. X}
  1848. X
  1849. X
  1850. X/*ARGSUSED*/
  1851. Xstatic void ListFocusOut(widget, event, params, num_params)
  1852. XWidget widget;
  1853. XXEvent *event;
  1854. XString *params;
  1855. XCardinal *num_params;        /* unused */
  1856. X{
  1857. X    ListWidget w = (ListWidget) widget;
  1858. X    int last_active_item = w->list.active_item;
  1859. X    XFocusOutEvent *ev = (XFocusOutEvent *) & event->xfocus;
  1860. X
  1861. X    if (ev->mode != NotifyUngrab)
  1862. X        return;
  1863. X
  1864. X    if (w->list.active_item != NO_ITEM)
  1865. X    {
  1866. X    w->list.active_item = NO_ITEM;
  1867. X    ListDrawItem(widget, last_active_item - w->list.first_visible_item);
  1868. X    }
  1869. X}
  1870. X
  1871. X
  1872. X/*ARGSUSED*/
  1873. Xstatic void ListNotify(widget, event, params, num_params)
  1874. XWidget widget;
  1875. XXEvent *event;
  1876. XString *params;
  1877. XCardinal *num_params;        /* unused */
  1878. X{
  1879. X    ListWidget w = (ListWidget) widget;
  1880. X    XButtonEvent *ev = (XButtonEvent *) & event->xbutton;
  1881. X    int item;
  1882. X    int last_selected_item;
  1883. X
  1884. X    if (params[0][0] == 'B')
  1885. X    item = GET_ITEM(w, ev->x, ev->y);
  1886. X    else
  1887. X    item = w->list.active_item;
  1888. X
  1889. X    if (item == NO_ITEM)
  1890. X    return;
  1891. X
  1892. X    last_selected_item = w->list.selected_item;
  1893. X    w->list.selected_item = item;
  1894. X
  1895. X    ListDrawItem(widget, last_selected_item - w->list.first_visible_item);
  1896. X
  1897. X    ListDrawItem(widget, item - w->list.first_visible_item);
  1898. X
  1899. X    XtCallCallbacks(widget, XtNcallback, (XtPointer) item);
  1900. X}
  1901. X
  1902. X
  1903. X/*ARGSUSED*/
  1904. Xstatic void ListMark(widget, event, params, num_params)
  1905. XWidget widget;
  1906. XXEvent *event;
  1907. XString *params;            /* unused */
  1908. XCardinal *num_params;        /* unused */
  1909. X{
  1910. X    ListWidget w = (ListWidget) widget;
  1911. X    XButtonEvent *ev = (XButtonEvent *) & event->xbutton;
  1912. X    int item;
  1913. X    int last_item = w->list.active_item;
  1914. X
  1915. X    switch (params[0][0])
  1916. X    {
  1917. X    case 'B':
  1918. X    item = GET_ITEM(w, ev->x, ev->y);
  1919. X    if (item != NO_ITEM)
  1920. X    {
  1921. X        DialogSetNewFocus(w->list.dialogbox, widget);
  1922. X        w->list.active_item = item;
  1923. X        break;
  1924. X    }
  1925. X    if (IN_UP_ARROW(w, ev->x, ev->y))
  1926. X    {
  1927. X        if (w->list.active_item == NO_ITEM)
  1928. X        {
  1929. X        DialogSetNewFocus(w->list.dialogbox, widget);
  1930. X        w->list.active_item = w->list.first_visible_item - 1;
  1931. X        }
  1932. X        ListScrollBackward(widget);
  1933. X    }
  1934. X    else if (IN_DOWN_ARROW(w, ev->x, ev->y))
  1935. X    {
  1936. X        if (w->list.active_item == NO_ITEM)
  1937. X        {
  1938. X        DialogSetNewFocus(w->list.dialogbox, widget);
  1939. X        w->list.active_item = w->list.first_visible_item;
  1940. X        }
  1941. X        ListScrollForward(widget);
  1942. X    }
  1943. X    else if (IN_SCROLLBAR(w, ev->x, ev->y))
  1944. X    {
  1945. X        if (w->list.active_item == NO_ITEM)
  1946. X        {
  1947. X        DialogSetNewFocus(w->list.dialogbox, widget);
  1948. X        w->list.active_item = w->list.first_visible_item;
  1949. X        }
  1950. X        ListStartScroll(widget, ev->y);
  1951. X    }
  1952. X    break;
  1953. X
  1954. X    case 'P':
  1955. X    item = w->list.active_item - 1;
  1956. X    if (item < 0)
  1957. X        item = 0;
  1958. X    w->list.active_item = item;
  1959. X    if (BEFORE_VIEW(w, item))
  1960. X    {
  1961. X        ListScrollBackward(widget);
  1962. X        return;
  1963. X    }
  1964. X    break;
  1965. X
  1966. X    case 'N':
  1967. X    item = w->list.active_item + 1;
  1968. X    if (item >= w->list.num_items)
  1969. X        item = w->list.num_items - 1;
  1970. X    w->list.active_item = item;
  1971. X    if (AFTER_VIEW(w, item))
  1972. X    {
  1973. X        ListScrollForward(widget);
  1974. X        return;
  1975. X    }
  1976. X    break;
  1977. X    }
  1978. X
  1979. X    ListDrawItem(widget, last_item - w->list.first_visible_item);
  1980. X    ListDrawItem(widget, item - w->list.first_visible_item);
  1981. X}
  1982. X
  1983. X
  1984. X/*ARGSUSED*/
  1985. Xstatic void ListGoto(widget, event, params, num_params)
  1986. XWidget widget;
  1987. XXEvent *event;            /* unused */
  1988. XString *params;            /* unused */
  1989. XCardinal *num_params;        /* unused */
  1990. X{
  1991. X    ListWidget w = (ListWidget) widget;
  1992. X    int item = w->list.active_item - w->list.first_visible_item;
  1993. X
  1994. X    w->list.active_item = NO_ITEM;
  1995. X    ListDrawItem(widget, item);
  1996. X
  1997. X    switch (params[0][0])
  1998. X    {
  1999. X    case 'P':
  2000. X    DialogSetPrevFocus(w->list.dialogbox);
  2001. X    break;
  2002. X
  2003. X    case 'N':
  2004. X    DialogSetNextFocus(w->list.dialogbox);
  2005. X    break;
  2006. X    }
  2007. X}
  2008. X
  2009. X
  2010. X/*ARGSUSED*/
  2011. Xstatic void ListBtnUp(widget, event, params, num_params)
  2012. XWidget widget;
  2013. XXEvent *event;
  2014. XString *params;            /* unused */
  2015. XCardinal *num_params;        /* unused */
  2016. X{
  2017. X    ListWidget w = (ListWidget) widget;
  2018. X    XButtonEvent *ev = (XButtonEvent *) & event->xbutton;
  2019. X
  2020. X    if (w->list.scrolling == False)
  2021. X    return;
  2022. X
  2023. X    w->list.scrolling = False;
  2024. X
  2025. X    if (ev->x <= w->list.item_width || ev->x >= w->core.width ||
  2026. X      ev->y < w->list.char_height ||
  2027. X      ev->y >= w->core.height - w->list.char_height)
  2028. X    return;
  2029. X
  2030. X    ListScrollTo(widget, ev->y);
  2031. X}
  2032. X
  2033. X
  2034. X/*ARGSUSED*/
  2035. Xstatic void ListMotion(widget, event, params, num_params)
  2036. XWidget widget;
  2037. XXEvent *event;
  2038. XString *params;            /* unused */
  2039. XCardinal *num_params;        /* unused */
  2040. X{
  2041. X    ListWidget w = (ListWidget) widget;
  2042. X    XMotionEvent *ev = (XMotionEvent *) & event->xmotion;
  2043. X
  2044. X    if (w->list.scrolling == False)
  2045. X    return;
  2046. X
  2047. X    if (ev->x <= w->list.item_width || ev->x >= w->core.width ||
  2048. X      ev->y < w->list.char_height ||
  2049. X      ev->y >= w->core.height - w->list.char_height)
  2050. X    return;
  2051. X
  2052. X    ListScrollTo(widget, ev->y);
  2053. X}
  2054. X
  2055. X
  2056. X/***********************************************************/
  2057. X/******************** Public Procedures ********************/
  2058. X/***********************************************************/
  2059. X
  2060. X
  2061. XBoolean ListChangeLabel(widget, item, label)
  2062. XWidget widget;
  2063. XCardinal item;
  2064. XString label;
  2065. X{
  2066. X    ListWidget w = (ListWidget) widget;
  2067. X    ListItem *list_item;
  2068. X
  2069. X    if (item >= w->list.num_items || label == NULL)
  2070. X    return (False);
  2071. X
  2072. X    list_item = &(w->list.list_items[item]);
  2073. X    if (strcmp(&(list_item->label[1]), label) == SAME)
  2074. X    return (True);
  2075. X    free(list_item->label);
  2076. X    list_item->label = malloc((unsigned) (strlen(label) + 2));
  2077. X    (void) strcpy(&(list_item->label[1]), label);
  2078. X
  2079. X    ListDrawItem(widget, (int) (item - w->list.first_visible_item));
  2080. X    return (True);
  2081. X}
  2082. X
  2083. X
  2084. XBoolean ListChangeSelected(widget, item)
  2085. XWidget widget;
  2086. Xint item;
  2087. X{
  2088. X    ListWidget w = (ListWidget) widget;
  2089. X    int last_item = w->list.selected_item;
  2090. X
  2091. X    if (item >= (int) w->list.num_items)
  2092. X    return (False);
  2093. X
  2094. X    if (item == last_item)
  2095. X    return (True);
  2096. X
  2097. X    w->list.selected_item = item;
  2098. X
  2099. X    if (item == NO_ITEM)
  2100. X    {
  2101. X    /* Scroll viewport to start */
  2102. X    w->list.first_visible_item = 0;
  2103. X    ListMoveKnob(widget, 0);
  2104. X    ListDrawAll(widget);
  2105. X    return (True);
  2106. X    }
  2107. X
  2108. X    if (BEFORE_VIEW(w, item))
  2109. X    {
  2110. X    /* Scroll viewport down so item is just visible */
  2111. X    w->list.first_visible_item = item;
  2112. X    ListMoveKnob(widget, ITEM_POS(w, w->list.first_visible_item));
  2113. X    ListDrawAll(widget);
  2114. X    }
  2115. X    else if (AFTER_VIEW(w, item))
  2116. X    {
  2117. X    /* Scroll viewport up so item is just visible */
  2118. X    w->list.first_visible_item = item - w->list.num_visible + 1;
  2119. X    ListMoveKnob(widget, ITEM_POS(w, w->list.first_visible_item));
  2120. X    ListDrawAll(widget);
  2121. X    }
  2122. X    else
  2123. X    {
  2124. X    /* Item was previously visible - just change selection */
  2125. X    ListDrawItem(widget, last_item - w->list.first_visible_item);
  2126. X    ListDrawItem(widget, (int) (item - w->list.first_visible_item));
  2127. X    }
  2128. X
  2129. X    return (True);
  2130. X}
  2131. X
  2132. X
  2133. XBoolean ListChangeItems(widget, new_items)
  2134. XWidget widget;
  2135. XListItem *new_items;
  2136. X{
  2137. X    ListWidget w = (ListWidget) widget;
  2138. X    int ii = 0;
  2139. X
  2140. X    while (w->list.list_items[ii].label != NULL && new_items[ii].label != NULL)
  2141. X    {
  2142. X    if (strcmp(&w->list.list_items[ii].label[1], new_items[ii].label)
  2143. X      != SAME)
  2144. X        break;
  2145. X    ++ii;
  2146. X    }
  2147. X
  2148. X    /* just return if the list has not changed */
  2149. X    if (w->list.list_items[ii].label == NULL && new_items[ii].label == NULL)
  2150. X    return (True);
  2151. X
  2152. X    ListFreeItems(w);
  2153. X
  2154. X    w->list.list_items = new_items;
  2155. X    ListCopyItems(w);
  2156. X
  2157. X    w->list.selected_item = NO_ITEM;
  2158. X    w->list.first_visible_item = 0;
  2159. X    w->list.num_stops = w->list.num_items - w->list.num_visible + 1;
  2160. X    if (w->list.num_stops < 1)
  2161. X    w->list.num_stops = 1;
  2162. X    ListDrawItems(widget);
  2163. X    ListMoveKnob(widget, 0);
  2164. X    return (True);
  2165. X}
  2166. END_OF_FILE
  2167. if test 23630 -ne `wc -c <'widgets/List.c'`; then
  2168.     echo shar: \"'widgets/List.c'\" unpacked with wrong size!
  2169. fi
  2170. # end of 'widgets/List.c'
  2171. fi
  2172. echo shar: End of archive 2 \(of 10\).
  2173. cp /dev/null ark2isdone
  2174. MISSING=""
  2175. for I in 1 2 3 4 5 6 7 8 9 10 ; do
  2176.     if test ! -f ark${I}isdone ; then
  2177.     MISSING="${MISSING} ${I}"
  2178.     fi
  2179. done
  2180. if test "${MISSING}" = "" ; then
  2181.     echo You have unpacked all 10 archives.
  2182.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2183. else
  2184.     echo You still need to unpack the following archives:
  2185.     echo "        " ${MISSING}
  2186. fi
  2187. ##  End of shell archive.
  2188. exit 0
  2189.  
  2190. dan
  2191. ----------------------------------------------------
  2192. O'Reilly && Associates   argv@sun.com / argv@ora.com
  2193. Opinions expressed reflect those of the author only.
  2194.