home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume11 / starchart / part17 < prev    next >
Text File  |  1990-03-25  |  33KB  |  1,033 lines

  1. Newsgroups: comp.sources.misc
  2. subject: v11i045: starchart 3.2 Part 17/32
  3. from: ccount@ATHENA.MIT.EDU
  4. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5.  
  6. Posting-number: Volume 11, Issue 45
  7. Submitted-by: ccount@ATHENA.MIT.EDU
  8. Archive-name: starchart/part17
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then unpack
  12. # it by saving it into a file and typing "sh file".  To overwrite existing
  13. # files, type "sh file -c".  You can also feed this as standard input via
  14. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  15. # will see the following message at the end:
  16. #        "End of archive 17 (of 32)."
  17. # Contents:  starchart/starXaw.c
  18. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  19. if test -f 'starchart/starXaw.c' -a "${1}" != "-c" ; then 
  20.   echo shar: Will not clobber existing file \"'starchart/starXaw.c'\"
  21. else
  22. echo shar: Extracting \"'starchart/starXaw.c'\" \(29848 characters\)
  23. sed "s/^X//" >'starchart/starXaw.c' <<'END_OF_FILE'
  24. X/*
  25. X * Driver creates X11 window and draws starchart information inside.
  26. X * Intially window size is variable, but it stays constant once it's
  27. X * mapped.  It handles expose events, even while it's drawing.
  28. X * Includes glyphs for variable stars.
  29. X *
  30. X * Rewritten from scratch July 1989
  31. X *
  32. X * Copyright (c) 1990 by Craig Counterman. All rights reserved.
  33. X *
  34. X * This software may be redistributed freely, not sold.
  35. X * This copyright notice and disclaimer of warranty must remain
  36. X *    unchanged. 
  37. X *
  38. X * No representation is made about the suitability of this
  39. X * software for any purpose.  It is provided "as is" without express or
  40. X * implied warranty, to the extent permitted by applicable law.
  41. X *
  42. X */
  43. X
  44. Xstatic char rcsid[]="$Header: starXaw.c,v 1.9 90/03/10 15:33:34 ccount Exp $";
  45. X
  46. X#include <stdio.h>
  47. X#include <math.h>
  48. X
  49. X#include "star3.h"
  50. X#include "starXaw.h"
  51. X
  52. X#ifndef SYSV
  53. X#include <strings.h>
  54. X#else
  55. X#include <string.h>
  56. X#endif
  57. X
  58. X#include <X11/cursorfont.h>
  59. X#include <X11/Intrinsic.h>
  60. X#include <X11/StringDefs.h>
  61. X#include <X11/Shell.h>
  62. X#ifdef X11R4
  63. X#include <X11/Xaw/Command.h>
  64. X#include <X11/Xaw/Form.h>
  65. X#include <X11/Xaw/Box.h>
  66. X#define ASCII_STRING
  67. X#define XAW_BC
  68. X#include <X11/Xaw/AsciiText.h>
  69. X#else
  70. X#include <X11/Command.h>
  71. X#include <X11/Form.h>
  72. X#include <X11/Box.h>
  73. X#include <X11/AsciiText.h>
  74. X#endif
  75. X
  76. Xchar *malloc();
  77. X
  78. X
  79. Xchar *prog="StarXaw";
  80. X#include "icon.h"
  81. X
  82. X
  83. X/* Externs */
  84. Xextern int g_argc;
  85. Xextern char **g_argv;
  86. X
  87. Xextern char *title;
  88. X
  89. Xextern int user_interact;
  90. X
  91. X
  92. X/* starX11 X items */
  93. Xextern Display *display;       /* connection to display server */
  94. Xextern Window root, window;       /* window to graphics in */
  95. Xextern Drawable draw_into;
  96. Xextern Colormap default_cmap;       /* colormap */
  97. Xextern GC default_GC;           /* graphics context */
  98. Xextern XFontStruct *default_font;  /* default font */
  99. Xextern XFontStruct *greek_font;       /* Greek font */
  100. Xextern Pixmap backup;           /* backup for expose events */
  101. Xextern Pixel black, white, foreground, background;
  102. Xextern Pixel *pixels;           /* color map cells */
  103. Xextern Pixel *star_pixels;         /* color map cells for super color stars */
  104. Xextern int ncolors, star_colors;
  105. Xextern XEvent event;           /* event structure */
  106. Xextern XGCValues values_GC;       /* modify GC */
  107. Xextern unsigned int width, height;
  108. X
  109. Xextern Boolean reverse;
  110. X
  111. Xextern Bool use_backup;
  112. Xextern Bool hide_drawing;
  113. Xextern Bool post_preview;
  114. Xextern Bool post_landscape;
  115. Xextern Bool use_x_dashes;
  116. Xextern Bool is_color;           /* Is it color? */
  117. Xextern Bool is_super_color;       /* Is it many color? */
  118. X
  119. Xextern int Xargc;
  120. Xextern char *Xargv[];
  121. X
  122. X
  123. X
  124. Xextern mapwindow fullpage, mainmap, thumbmap;
  125. X
  126. Xextern int htick_lim, htext_lim, htext_xoff, htext_yoff;
  127. Xextern int vtick_lim, vtext_lim, vtext_xoff, vtext_yoff;
  128. X
  129. X/* externs for labels */
  130. X
  131. Xextern int x_nameoffset, y_nameoffset, x_lbloffset, y_lbloffset, 
  132. X  x_magoffset, y_magoffset;
  133. X
  134. X/* externs for legend: variables of positioning are here */
  135. Xextern int l_til;
  136. Xextern int l_stil;
  137. X
  138. Xextern int l_lmar1;
  139. Xextern int l_lmar2;
  140. Xextern int l_ltext;
  141. Xextern int l_rmar1;
  142. Xextern int l_rmar2;
  143. Xextern int l_rtext;
  144. X
  145. Xextern int l_line1;
  146. Xextern int l_line2;
  147. Xextern int l_line3;
  148. Xextern int l_line4;
  149. Xextern int l_line5;
  150. Xextern int l_line6;
  151. X
  152. X/* Point sizes for font calls */
  153. Xextern int titlesize;
  154. Xextern int subtlsize;
  155. Xextern int namesize;
  156. Xextern int lblsize;
  157. Xextern int magsize;
  158. X
  159. X/* Fonts for font calls */
  160. Xextern int namefnt;
  161. Xextern int lblfnt;
  162. Xextern int magfnt;
  163. Xextern int titlefnt;
  164. Xextern int subtlfnt;
  165. X
  166. X/* Scale multiplier, minimum,
  167. X   mangitude change, maximum, for thumbnail,*/
  168. Xextern double th_smul;
  169. Xextern double th_smin;
  170. Xextern double th_madj;
  171. Xextern double th_mmax;
  172. X
  173. X#ifndef MAXPATHLEN
  174. X#define MAXPATHLEN 1025
  175. X#endif
  176. X#define MAX(a,b) ((a)>(b)?(a):(b))
  177. X#define MIN(a,b) ((a)<(b)?(a):(b))
  178. X
  179. X/* Font names */
  180. X#ifdef RELEASE3_FONTS
  181. Xstatic char *default_font_name = "*helvetica-medium-r-normal--10*";
  182. Xstatic char *greek_font_name = "*symbol-medium-r-normal--10*";
  183. Xstatic char *timesroman_font_name = "*times-medium-r-normal--";
  184. Xstatic char *timesbold_font_name = "*times-bold-r-normal--";
  185. Xstatic char *timesital_font_name = "*times-roman-i-normal--";
  186. Xstatic char *timesboldital_font_name = "*times-bold-i-normal--";
  187. Xstatic char *helv_font_name = "*helvetica-medium-r-normal--";
  188. Xstatic char *helvbold_font_name = "*helvetica-bold-r-normal--";
  189. Xstatic char *helvital_font_name = "*helvetica-medium-o-normal--";
  190. Xstatic char *helvboldital_font_name = "*helvetica-bold-o-normal--";
  191. Xstatic char *courier_font_name = "*courier-medium-r-normal--";
  192. Xstatic char *courital_font_name = "*courier-medium-i-normal--";
  193. Xstatic char *courbold_font_name = "*courier-bold-r-normal--";
  194. Xstatic char *couritalbold_font_name = "*courier-bold-o-normal--";
  195. X#else
  196. Xstatic char *default_font_name = "helvetica-medium10";
  197. Xstatic char *greek_font_name = "symbol-medium10";
  198. Xstatic char *timesroman_font_name = "times-roman";
  199. Xstatic char *timesbold_font_name = "times-bold";
  200. Xstatic char *timesital_font_name = "times-italic";
  201. Xstatic char *timesboldital_font_name = "times-bold-italic";
  202. Xstatic char *helv_font_name = "helvetica-medium";
  203. Xstatic char *helvbold_font_name = "helvetica-bold";
  204. Xstatic char *helvital_font_name = "helvetica-oblique";
  205. Xstatic char *helvboldital_font_name = "helvetica-boldoblique";
  206. Xstatic char *courier_font_name = "courier-medium";
  207. Xstatic char *courital_font_name = "courier-medium";
  208. Xstatic char *courbold_font_name = "courier-bold";
  209. Xstatic char *couritalbold_font_name = "courier-bold";
  210. X#endif /* RELEASE3_FONTS */
  211. X
  212. X
  213. X
  214. X
  215. X/* starXaw Local variables */
  216. XWidget interface, chart_shell, chart_widget;
  217. XWidget com_wid;
  218. XScreen *screen;
  219. XBool fixed_size = FALSE;
  220. Xint fixed_width = 500;
  221. Xint fixed_height = 500;
  222. X
  223. XBool fixed_win_coo = False;  /* use Fixed window coordinates,
  224. X                override X window settings in D_open*/
  225. X
  226. Xstatic int draw_chart;     /* set to TRUE when D_userinput should return TRUE */
  227. Xstatic int quit_program; /* set to TRUE when D_userinput should return FALSE */
  228. Xstatic int killed_window;/* set to TRUE when the user has closed the
  229. X                chart window during drawing */
  230. Xstatic int kill_the_window;/* set to TRUE if close_window should kill the
  231. X                  window immediately.
  232. X                  Otherwise lets D_break do it. */
  233. X
  234. X
  235. X/* main() parses the command line, and any input .starrc files
  236. Xcalls D_userinput() to finish setting the basic variables of the chart
  237. Xthen fix_mapwin, which may read a mapwin file, then D_mapwininput()
  238. Xto give the user final input of the detailed mapwin structure.
  239. XD_open then is called to begin the display.
  240. Xthe mapwin structure may be modified, based on the size of the window opened
  241. Xmain() will then write the mapwin file if so desired
  242. X
  243. XD_break is called periodically to give the user a chance to cancel input
  244. X
  245. XD_close is called at the end of plotting.
  246. X
  247. X
  248. XThis driver supplies:
  249. XD_userinput
  250. XD_mapwininput
  251. XD_open
  252. XD_close
  253. XD_break
  254. X
  255. XMuch other code is shared with starX11.c
  256. XD_comment is supplied to replace starX11's D_comment which writes to
  257. Xstandard output
  258. X*/
  259. X
  260. XD_open()
  261. X{
  262. X  int x, y;
  263. X  unsigned int border, depth, map_width;
  264. X  Pixmap icon;
  265. X  XSizeHints sizehints;
  266. X  double legend_spacing;
  267. X
  268. X
  269. X  Window shell_window;
  270. X  Widget closebox;
  271. X  
  272. X  void expose(), close_window();
  273. X  
  274. X  Arg shell_args[10];
  275. X  Arg widget_args[1];
  276. X  Cardinal nshell_args, nwidget_args;
  277. X  static Arg close_args[] = {
  278. X    {XtNx, (XtArgVal) 2},
  279. X    {XtNy, (XtArgVal) 2},
  280. X    {XtNwidth, (XtArgVal) 10},
  281. X    {XtNheight, (XtArgVal) 10},
  282. X    {XtNbackground, (XtArgVal) NULL},
  283. X    {XtNforeground, (XtArgVal) NULL},
  284. X  };
  285. X
  286. X  /* set user_interact so D_break will be called in starmain.c */
  287. X  user_interact = TRUE;
  288. X
  289. X  if (post_preview) {
  290. X    if (post_landscape) {
  291. X      XtSetArg(shell_args[0], XtNwidth, 768);
  292. X      XtSetArg(shell_args[1], XtNheight, 595);
  293. X    } else {
  294. X      XtSetArg(shell_args[0], XtNwidth, 595);
  295. X      XtSetArg(shell_args[1], XtNheight, 768);
  296. X    };
  297. X  } else {
  298. X    XtSetArg(shell_args[0], XtNwidth, 550);
  299. X    XtSetArg(shell_args[1], XtNheight, 550);
  300. X  }
  301. X  XtSetArg(shell_args[2], XtNtitle, (!title[0]) ? prog : title);
  302. X  XtSetArg(shell_args[3], XtNiconName, (!title[0]) ? prog : title);
  303. X  XtSetArg(shell_args[4], XtNborderColor, foreground);
  304. X  nshell_args = 5;
  305. X  if (fixed_size) {
  306. X    XtSetArg(shell_args[0], XtNwidth, fixed_width);
  307. X    XtSetArg(shell_args[1], XtNheight, fixed_height);
  308. X  };
  309. X
  310. X  XtSetArg(widget_args[0], XtNbackground, background);
  311. X  nwidget_args = 1;
  312. X
  313. X  XtSetArg(close_args[4], XtNbackground, foreground);
  314. X  XtSetArg(close_args[5], XtNforeground, background);
  315. X
  316. X  chart_shell =
  317. X    XtCreatePopupShell(prog, topLevelShellWidgetClass, interface,
  318. X               shell_args, nshell_args);
  319. X
  320. X  killed_window = FALSE;
  321. X  kill_the_window = FALSE;
  322. X  
  323. X  chart_widget = XtCreateManagedWidget(prog, compositeWidgetClass, chart_shell,
  324. X                       widget_args, nwidget_args);
  325. X  closebox = XtCreateManagedWidget("", simpleWidgetClass,
  326. X                   chart_widget, close_args,
  327. X                   XtNumber(close_args));
  328. X
  329. X  XtPopup(chart_shell, XtGrabNonexclusive);
  330. X  window = XtWindow(chart_widget);
  331. X  shell_window = XtWindow(chart_shell);
  332. X  
  333. X  if (post_preview) {
  334. X    sizehints.flags = PSize|PMinSize|PMaxSize;
  335. X    if (post_landscape) {
  336. X      sizehints.width = sizehints.min_width = sizehints.max_width = 792;
  337. X      sizehints.height = sizehints.min_height = sizehints.max_height = 576;
  338. X    } else {
  339. X      sizehints.width = sizehints.min_width = sizehints.max_width = 576;
  340. X      sizehints.height = sizehints.min_height = sizehints.max_height = 792;
  341. X    };
  342. X  } else if (fixed_size) {
  343. X    sizehints.flags = PSize|PMinSize|PMaxSize;
  344. X    sizehints.width = sizehints.min_width = sizehints.max_width
  345. X      = fixed_width;
  346. X    sizehints.height = sizehints.min_height = sizehints.max_height
  347. X      = fixed_height;
  348. X  } else {
  349. X    sizehints.flags = PMinSize;
  350. X    sizehints.min_width = 550; sizehints.min_height = 550;
  351. X  }
  352. X
  353. X  icon = XCreateBitmapFromData(display, window, icon_bits, 
  354. X                               icon_width, icon_height);
  355. X  Xargv[0] = g_argv[0];
  356. X  XSetStandardProperties(display, shell_window, prog, prog, icon,
  357. X             Xargv, Xargc, &sizehints);
  358. X  XDefineCursor(display, XtWindow(closebox), 
  359. X        XCreateFontCursor(display, XC_top_left_arrow));
  360. X  XDefineCursor(display, window, XCreateFontCursor(display, XC_crosshair));
  361. X  while (XtPending()) {
  362. X    XtNextEvent(&event);
  363. X    XtDispatchEvent(&event);
  364. X  }
  365. X  XSelectInput(display, window, StructureNotifyMask);
  366. X  XMapWindow(display, window);
  367. X  while(!XCheckTypedWindowEvent(display, shell_window, MapNotify, &event));
  368. X
  369. X  XGetGeometry(display, shell_window, &root, &x, &y, &width, &height, &border,
  370. X               &depth);
  371. X  sizehints.width = sizehints.max_width = sizehints.min_width = width;
  372. X  sizehints.height = sizehints.max_height = sizehints.min_height = height;
  373. X  XtSetArg(shell_args[0], XtNwidth, width);
  374. X  XtSetArg(shell_args[1], XtNheight, height);
  375. X  XtSetValues(chart_shell, shell_args, nshell_args);
  376. X
  377. X  map_width = width - 72;
  378. X
  379. X  if (!fixed_win_coo) {
  380. X    fullpage.width = map_width;
  381. X    fullpage.height = height - 72;
  382. X    fullpage.x_offset = 18;
  383. X    fullpage.y_offset = 36;
  384. X
  385. X    mainmap.width = map_width;
  386. X    mainmap.height = ((height -72)*7)/10;
  387. X    mainmap.x_offset = 18;
  388. X    mainmap.y_offset = 18 + ((height - 72)*2.5)/10;
  389. X
  390. X    thumbmap.width = map_width/2;
  391. X    thumbmap.height = ((height - 72)*2)/10;
  392. X    thumbmap.x_offset = 18 + map_width/2;
  393. X    thumbmap.y_offset = 18;
  394. X  };
  395. X
  396. X  /* Need to adjust label here */
  397. X  /* Want top of l_til to be at top of thumbmap */
  398. X  l_til = thumbmap.height + thumbmap.y_offset - titlesize;
  399. X  /* Space text in legends to fill space.  Leave 10 on bottom.
  400. X     Text totals 6*namesize+subtlsize. */
  401. X
  402. X  legend_spacing = (l_til - 10 - 6*namesize - subtlsize)/7;
  403. X  if (legend_spacing < 2) legend_spacing = 2;
  404. X
  405. X  l_stil = l_til - subtlsize - legend_spacing;
  406. X  l_line1 = l_stil - namesize - legend_spacing;
  407. X  l_line2 = l_line1 - namesize - legend_spacing;
  408. X  l_line3 = l_line2 - namesize - legend_spacing;
  409. X  l_line4 = l_line3 - namesize - legend_spacing;
  410. X  l_line5 = l_line4 - namesize - legend_spacing;
  411. X  l_line6 = l_line5 - namesize - legend_spacing;
  412. X
  413. X
  414. X  /* Actually, we left too much space above,
  415. X     for proper postscript simulation.
  416. X     We can make the maps higher */
  417. X  if ((!post_preview) && (!fixed_size)) {
  418. X    fullpage.height = height - fullpage.y_offset - 18;
  419. X    mainmap.height = height - mainmap.y_offset - 18;
  420. X  }
  421. X
  422. X  sizehints.flags = PSize|PMinSize|PMaxSize;
  423. X  XSetNormalHints(display, shell_window, &sizehints);
  424. X  XSetNormalHints(display, window, &sizehints);
  425. X
  426. X  if ((!is_color) && use_backup) {
  427. X    backup = XCreatePixmap(display, window, width, height, depth);
  428. X    XtAddEventHandler(chart_widget, ExposureMask, False,
  429. X              expose,(caddr_t) backup);
  430. X
  431. X  } else { /* Can't use backup pixmap on color: not enough memory */
  432. X    use_backup = FALSE;
  433. X    hide_drawing = FALSE;
  434. X  }
  435. X  draw_into = backup ? backup : window;
  436. X/* Should perhaps try and check for failure, and use some other
  437. X   way of selecting use of window vs. backup */
  438. X
  439. X  XtAddEventHandler(closebox, ButtonPressMask|ButtonReleaseMask,
  440. X            False, close_window, (caddr_t) chart_widget);
  441. X  
  442. X
  443. X  values_GC.foreground = background; values_GC.background = foreground;
  444. X  XChangeGC(display, default_GC, GCForeground|GCBackground, &values_GC);
  445. X  XFillRectangle(display, draw_into, default_GC, 0, 0, width, height);
  446. X  XSetForeground(display, default_GC, foreground);
  447. X  XSetBackground(display, default_GC, background);
  448. X
  449. X  return TRUE;                /* open successful */
  450. X}
  451. X
  452. X
  453. Xvoid pointer_input();
  454. X
  455. XD_close()
  456. X{
  457. X  if (is_killed()) {
  458. X    XtDestroyWidget(XtParent(chart_widget));
  459. X    if (use_backup) XFreePixmap(display, backup);
  460. X    un_help();
  461. X    D_comment("Closed");
  462. X    return;
  463. X  };
  464. X
  465. X  flushlines();
  466. X
  467. X  kill_the_window = TRUE;
  468. X
  469. X  XtAddEventHandler(chart_widget, ButtonPressMask,False,
  470. X            pointer_input,(caddr_t) chart_widget);
  471. X
  472. X  D_comment("Waiting for close of window or mouse button 1 or 3 input");
  473. X
  474. X  XtRemoveGrab(chart_shell);
  475. X  XtAddGrab(chart_shell, True, False);
  476. X  XtAddGrab(com_wid, False, False);
  477. X  pointer_help();
  478. X}
  479. X
  480. Xvoid pointer_input(widget, closure, event)
  481. X     Widget widget;
  482. X     caddr_t closure;        /* Widget */
  483. X     XEvent *event;
  484. X{
  485. X  int i;
  486. X  double lat, lon, tlat, tlon;
  487. X  char outstr[81];
  488. X  int ra_h, ra_m, ra_s;
  489. X  int de_d, de_m, de_s;
  490. X  char dsign;
  491. X  
  492. X  
  493. X  if ((i = invxform((int) event->xbutton.x,
  494. X            (int) height - event->xbutton.y,
  495. X            &lat, &lon)) >= 0) {
  496. X    if (lon < 0.0) lon += 360.0;
  497. X    tlon = lon / 15.0;
  498. X    
  499. X    ra_h = tlon;
  500. X    ra_m = (tlon - ra_h) * 60 + (0.5 / 60);
  501. X    ra_s = (((tlon - ra_h) * 60) - ra_m) * 60 + 0.5;
  502. X    
  503. X    if (ra_s >= 60) {ra_s -= 60; ra_m++;};
  504. X    if (ra_m >= 60) {ra_m -= 60; ra_h++;};
  505. X    
  506. X    
  507. X    if (lat < 0.0) {
  508. X      tlat = -lat;
  509. X      dsign = '-';
  510. X    } else {
  511. X      tlat = lat;
  512. X      dsign = '+';
  513. X    }
  514. X    
  515. X    de_d = tlat;
  516. X    de_m = (tlat - de_d) * 60 + (0.5 / 60);
  517. X    de_s = (((tlat - de_d) * 60) - de_m) * 60 + 0.5;
  518. X    
  519. X    if (de_s >= 60) {de_s -= 60; de_m++;};
  520. X    if (de_m >= 60) {de_m -= 60; de_d++;};
  521. X    
  522. X    
  523. X    sprintf(outstr, "RA: %2dh%2dm%2ds   dec: %c%2dd%2dm%2ds\n",
  524. X        ra_h, ra_m, ra_s, dsign, de_d, de_m, de_s);
  525. X    buffer_comment(outstr, TRUE);
  526. X    
  527. X    if (event->xbutton.button == Button3) {
  528. X      buffer_comment("", TRUE);
  529. X      dblookup(i, lat, lon, 10);
  530. X    };
  531. X  } else {
  532. X    /*      fprintf(stderr, "Returned -1\n");*/
  533. X  }
  534. X}
  535. X
  536. X
  537. X
  538. X/* Open the display connection and do much of the X initialization
  539. X   Display text output window, and buttons for dialog boxes.
  540. X   process dialog box input
  541. X   draw_chart becomes true when the draw chart button gets pressed
  542. X*/
  543. XD_userinput()
  544. X{
  545. X  static int initialized = FALSE;
  546. X
  547. X  if (!initialized) {
  548. X    start_X11();
  549. X    initialized = TRUE;
  550. X  }
  551. X
  552. X  draw_chart = FALSE;
  553. X  quit_program = FALSE;
  554. X  while (!draw_chart) {
  555. X    XtNextEvent(&event);
  556. X    XtDispatchEvent(&event);
  557. X    if (quit_program) return FALSE;
  558. X  };
  559. X
  560. X  /* User has done the input, now we are ready to begin the chart.*/
  561. X  return TRUE;
  562. X}
  563. X
  564. X/*
  565. X  D_mapwininput() is in starXawDlog.c for convenience in shared variables */
  566. X
  567. X
  568. X
  569. X
  570. X/* Put non-displayed comment in output.  Allowed in postscript, but
  571. X   few other drivers will be able to support this. */
  572. Xchar comment_buffer[MAX(MAXPATHLEN*2, 6000)];
  573. X/* Allow for lots of space */
  574. XD_comment(str)
  575. X     char *str;
  576. X{
  577. X  Arg args[3];
  578. X
  579. X  strcpy(comment_buffer, str);
  580. X  XtSetArg(args[0], XtNlabel, comment_buffer);
  581. X  XtSetArg(args[1], XtNinsertPosition, 0);
  582. X  XtSetValues(com_wid, args, (Cardinal)2);
  583. X  XtTextSetLastPos(com_wid, strlen(str));
  584. X}
  585. X
  586. X/* D_comment with several lines of buffer */
  587. Xbuffer_comment(str, reset)
  588. X     char *str;
  589. X     int reset;
  590. X{
  591. X  Arg args[2];
  592. X  static int ncalled = 0;
  593. X  int i,j;
  594. X  int len, had_newline;
  595. X
  596. X  if (reset) ncalled = 0;
  597. X  if (ncalled == 0) comment_buffer[0] = '\0';
  598. X  ncalled++;
  599. X
  600. X  /* Find last character to copy */
  601. X  len = strlen(str)-1;
  602. X  if (str[len] == '\n') {
  603. X    had_newline = TRUE;
  604. X    len--;            /* skip newline */
  605. X  } else {
  606. X    had_newline = FALSE;
  607. X  }
  608. X  while (str[len] == ' ') len--;    /* skip spaces */
  609. X
  610. X
  611. X  i = strlen(comment_buffer);
  612. X  if ((i > 0) && (comment_buffer[i] != '\n')) {
  613. X    comment_buffer[i++] = '\n';
  614. X    comment_buffer[i] = '\0';
  615. X  }
  616. X
  617. X  /* Now i is the terminating \0 */
  618. X  if ((i + strlen(str)) < sizeof(comment_buffer)) {
  619. X    /* Add string to comment_buffer up to last non space before '\n' */
  620. X    for (j = 0; j <= len;  j++)
  621. X      comment_buffer[i++] = str[j];
  622. X    if (had_newline)
  623. X      comment_buffer[i++] = '\n';
  624. X    comment_buffer[i] = '\0';
  625. X  } /* If buffer is full, ignore string */
  626. X
  627. X
  628. X  XtSetArg(args[0], XtNlabel, comment_buffer);
  629. X  XtSetArg(args[1], XtNinsertPosition, 0);
  630. X  XtSetValues(com_wid, args, (Cardinal)2);
  631. X  XtTextSetLastPos(com_wid, strlen(comment_buffer));
  632. X
  633. X  XFlush(display);
  634. X
  635. X  fprintf(stderr, "%s\n", str);
  636. X}
  637. X
  638. X
  639. Xint D_break()
  640. X{
  641. X  if (is_killed()) {
  642. X    XtDestroyWidget(XtParent(chart_widget));
  643. X    if (use_backup) XFreePixmap(display, backup);
  644. X    un_help();
  645. X    D_comment("Closed");
  646. X  };
  647. X
  648. X  return killed_window;
  649. X}
  650. X
  651. X/* Widget functions */
  652. Xvoid Destroyed(widget, closure, callData)
  653. X    Widget widget;
  654. X    caddr_t closure;        /* unused */
  655. X    caddr_t callData;        /* unused */
  656. X{
  657. X  quit_program = TRUE;
  658. X}
  659. X
  660. Xvoid Quit(widget,closure,callData)
  661. X    Widget widget;
  662. X    caddr_t closure;        /* Widget */
  663. X    caddr_t callData;
  664. X{
  665. X    XtDestroyWidget((Widget)closure);
  666. X}
  667. X
  668. X
  669. X
  670. X/* StarXaw X functions */
  671. Xextern char help_buffer[];
  672. Xextern Widget help_wid;
  673. X
  674. X/* Make the top level window, which contains buttons to
  675. X   bring up the dialog boxes and do the chart */  
  676. Xstart_X11()
  677. X{
  678. X  Widget outer;
  679. X  Arg Button_arg[10], Label_arg[10], Text_arg[10];
  680. X  static XtCallbackRec callback[2];
  681. X  Cardinal NButton_args, NLabel_args, nText_args;
  682. X
  683. X  static Arg shell_args[2];
  684. X  extern Button_set dlogbuttons[];
  685. X  int i;
  686. X  void Draw_chart(), Save_Load_file(), XHelp();
  687. X  Widget first_button;
  688. X  Widget new_w, old_w;
  689. X  Pixmap icon;
  690. X
  691. X  XtSetArg(Button_arg[0], XtNcallback, callback);
  692. X  XtSetArg(Button_arg[1], XtNborderWidth, 1);
  693. X  XtSetArg(Button_arg[2], XtNwidth, 150);
  694. X  XtSetArg(Button_arg[3], XtNheight, 20);
  695. X  NButton_args = 4;
  696. X
  697. X  /* Label_arg[0] is the text of the label */
  698. X  XtSetArg(Label_arg[1], XtNborderWidth, 0);
  699. X  XtSetArg(Label_arg[2], XtNjustify, XtJustifyLeft);
  700. X  XtSetArg(Label_arg[3], XtNheight, 20);
  701. X  NLabel_args = 4;
  702. X
  703. X
  704. X  Xargv[0] = g_argv[0];
  705. X  interface = XtInitialize(prog, applicationShellWidgetClass,
  706. X              NULL, 0, &Xargc, Xargv);
  707. X  display = XtDisplay(interface);
  708. X  screen = XtScreen(interface);
  709. X
  710. X  X_setdisplay();
  711. X
  712. X  icon = XCreateBitmapFromData(display, XtScreen(interface)->root, icon_bits, 
  713. X                               icon_width, icon_height);
  714. X
  715. X  XtSetArg(shell_args[0], XtNtitle, prog);
  716. X  XtSetArg(shell_args[1], XtNiconPixmap, icon);
  717. X  XtSetValues(interface, shell_args, (Cardinal) 2);
  718. X
  719. X
  720. X  set_translations();        /* Set translation tables for text widgets */
  721. X
  722. X  /* We have now created the interface widget, and set up the basics
  723. X     of the display */
  724. X
  725. X  /* Now we create the interface */
  726. X  /* Currently using the "form" widget, with some labels and
  727. X     command widgets (buttons) which will call the functions above */
  728. X
  729. X  outer = XtCreateManagedWidget("form", formWidgetClass, interface,
  730. X                NULL, (Cardinal)0);
  731. X  XtAddCallback(outer, XtNdestroyCallback, Destroyed, NULL);
  732. X
  733. X  callback[0].callback = Quit;
  734. X  callback[0].closure = (caddr_t)interface;
  735. X
  736. X  XtSetArg(Button_arg[4], XtNhorizDistance, 5);
  737. X  XtSetArg(Button_arg[5], XtNvertDistance, 5);
  738. X  NButton_args = 6;
  739. X  new_w = XtCreateManagedWidget("QUIT",
  740. X            commandWidgetClass, outer, Button_arg, NButton_args);
  741. X  first_button = new_w;
  742. X  old_w = new_w;
  743. X  XtSetArg(Label_arg[0], XtNlabel, "Controls:");
  744. X  XtSetArg(Label_arg[4], XtNfromVert, old_w);
  745. X  NLabel_args = 5;
  746. X  new_w = XtCreateManagedWidget("label", labelWidgetClass,
  747. X                  outer, Label_arg, NLabel_args);
  748. X
  749. X  /* Button */
  750. X  i = 0;
  751. X  while (dlogbuttons[i].blabel[0]) {
  752. X    old_w = new_w;
  753. X    XtSetArg(Button_arg[4], XtNfromVert, old_w);
  754. X
  755. X    callback[0].callback = *dlogbuttons[i].func;
  756. X    new_w = XtCreateManagedWidget(dlogbuttons[i].blabel,
  757. X              commandWidgetClass, outer, Button_arg, NButton_args);
  758. X    i++;
  759. X  };
  760. X
  761. X  /* Button */
  762. X  callback[0].callback = Save_Load_file;
  763. X  old_w = new_w;
  764. X  XtSetArg(Button_arg[4], XtNfromVert, old_w);
  765. X  new_w = XtCreateManagedWidget("Save / Load File",
  766. X            commandWidgetClass, outer, Button_arg, NButton_args);
  767. X
  768. X  /* Label */
  769. X  old_w = new_w;
  770. X  XtSetArg(Label_arg[0], XtNlabel, "Actions:");
  771. X  XtSetArg(Label_arg[4], XtNfromVert, old_w);
  772. X  new_w = XtCreateManagedWidget("label", labelWidgetClass,
  773. X            outer, Label_arg, NLabel_args);
  774. X
  775. X  /* Button */
  776. X  callback[0].callback = Draw_chart;
  777. X  old_w = new_w;
  778. X  XtSetArg(Button_arg[4], XtNfromVert, old_w);
  779. X  new_w = XtCreateManagedWidget("Draw Chart",
  780. X            commandWidgetClass, outer, Button_arg, NButton_args);
  781. X
  782. X
  783. X  /* Label */
  784. X  old_w = new_w;
  785. X  XtSetArg(Label_arg[0], XtNlabel, "Output:");
  786. X  XtSetArg(Label_arg[4], XtNfromVert, old_w);
  787. X  new_w = XtCreateManagedWidget("label", labelWidgetClass, outer, 
  788. X            Label_arg, NLabel_args);
  789. X
  790. X  /* Text */
  791. X  old_w = new_w;
  792. X  XtSetArg(Text_arg[0], XtNstring, comment_buffer);
  793. X  XtSetArg(Text_arg[1], XtNlength, MAXPATHLEN*2);
  794. X  XtSetArg(Text_arg[2], XtNwidth, 390);
  795. X  XtSetArg(Text_arg[3], XtNheight, 134);
  796. X  XtSetArg(Text_arg[4], XtNhorizDistance, 5);
  797. X  XtSetArg(Text_arg[5], XtNfromVert, old_w);
  798. X  XtSetArg(Text_arg[6], XtNtextOptions, wordBreak | scrollVertical);
  799. X  nText_args = 7;
  800. X  com_wid = XtCreateManagedWidget("",
  801. X              asciiStringWidgetClass, outer,
  802. X              Text_arg, nText_args);
  803. X
  804. X  i = start_help();
  805. X  XtSetArg(Text_arg[0], XtNstring, help_buffer);
  806. X  XtSetArg(Text_arg[1], XtNlength, i);
  807. X  XtSetArg(Text_arg[2], XtNwidth, 235);
  808. X  XtSetArg(Text_arg[3], XtNheight, 365);
  809. X  XtSetArg(Text_arg[4], XtNvertDistance, 5);
  810. X  XtSetArg(Text_arg[5], XtNhorizDistance, 160);
  811. X  nText_args = 6;
  812. X  help_wid = XtCreateManagedWidget("",
  813. X              asciiStringWidgetClass, outer,
  814. X              Text_arg, nText_args);
  815. X
  816. X  /* Button */
  817. X  callback[0].callback = XHelp;
  818. X  old_w = help_wid;
  819. X  XtSetArg(Button_arg[2], XtNwidth, 235);
  820. X  XtSetArg(Button_arg[4], XtNhorizDistance, 160);
  821. X  XtSetArg(Button_arg[5], XtNvertDistance, 377);
  822. X  new_w = XtCreateManagedWidget("Help",
  823. X            commandWidgetClass, outer, Button_arg, NButton_args);
  824. X  XtRealizeWidget(interface);
  825. X}
  826. X
  827. X
  828. Xvoid Draw_chart(widget,closure,callData)
  829. X    Widget widget;
  830. X    caddr_t closure;        /* Widget */
  831. X    caddr_t callData;
  832. X{
  833. X  draw_chart = TRUE;
  834. X}
  835. X
  836. Xvoid expose(widget,closure,event)
  837. X     Widget widget;
  838. X     caddr_t closure;        /* Widget */
  839. X     XEvent *event;
  840. X{
  841. X  XCopyArea(display, (Drawable) closure, XtWindow(widget), default_GC,
  842. X        event->xexpose.x, event->xexpose.y, 
  843. X        (unsigned) event->xexpose.width, (unsigned) event->xexpose.height,
  844. X        event->xexpose.x, event->xexpose.y);
  845. X}
  846. X
  847. Xvoid close_window(widget,closure,event)
  848. X     Widget widget;
  849. X     caddr_t closure;        /* Widget */
  850. X     XEvent *event;
  851. X{
  852. X  if (XtParent((Widget) closure) == chart_shell) {
  853. X    killed_window = TRUE;
  854. X    killlines();
  855. X  };
  856. X
  857. X  if (kill_the_window) {
  858. X    XtDestroyWidget(XtParent(chart_widget));
  859. X    if (use_backup) XFreePixmap(display, backup);
  860. X    un_help();
  861. X    D_comment("Closed");
  862. X  };
  863. X}
  864. X
  865. Xint is_killed()
  866. X{
  867. X  XEvent event;
  868. X
  869. X  while (XtPending()) {
  870. X    XtNextEvent(&event);
  871. X    XtDispatchEvent(&event);
  872. X  }
  873. X  return (killed_window);
  874. X}
  875. X
  876. X/* Setting translation tables */
  877. Xchar num_one_line_translations[] = "\
  878. X     Ctrl<Key>F:         forward-character() \n\
  879. X     Ctrl<Key>B:         backward-character() \n\
  880. X     Ctrl<Key>D:         delete-next-character() \n\
  881. X     Ctrl<Key>A:         beginning-of-line() \n\
  882. X     Ctrl<Key>E:         end-of-line() \n\
  883. X     Ctrl<Key>H:         delete-previous-character() \n\
  884. X     Ctrl<Key>K:         kill-to-end-of-line() \n\
  885. X     Ctrl<Key>J:         redraw-display() \n\
  886. X     Ctrl<Key>L:         redraw-display() \n\
  887. X     Ctrl<Key>M:         redraw-display() \n\
  888. X     Ctrl<Key>N:         redraw-display() \n\
  889. X     Ctrl<Key>O:         redraw-display() \n\
  890. X     Ctrl<Key>P:         redraw-display() \n\
  891. X     Ctrl<Key>V:         redraw-display() \n\
  892. X     Ctrl<Key>W:         kill-selection() \n\
  893. X     Ctrl<Key>Y:         unkill() \n\
  894. X     Ctrl<Key>Z:         redraw-display() \n\
  895. X     Meta<Key>F:         forward-word() \n\
  896. X     Meta<Key>B:         backward-word() \n\
  897. X     Meta<Key>Y:         stuff() \n\
  898. X     Meta<Key>Z:         redraw-display() \n\
  899. X     Meta<Key>I:         redraw-display() \n\
  900. X     Meta<Key>K:         redraw-display() \n\
  901. X     Meta<Key>V:         redraw-display() \n\
  902. X     :Meta<Key>d:        delete-next-word() \n\
  903. X     :Meta<Key>D:        kill-word() \n\
  904. X     :Meta<Key>h:        delete-previous-word() \n\
  905. X     :Meta<Key>H:        backward-kill-word() \n\
  906. X     :Meta<Key>\<:       redraw-display() \n\
  907. X     :Meta<Key>\>:       redraw-display() \n\
  908. X     :Meta<Key>]:        redraw-display() \n\
  909. X     :Meta<Key>[:        redraw-display() \n\
  910. X     ~Shift Meta<Key>Delete:delete-previous-word() \n\
  911. X      Shift Meta<Key>Delete:backward-kill-word() \n\
  912. X     ~Shift Meta<Key>BackSpace:delete-previous-word() \n\
  913. X      Shift Meta<Key>BackSpace:backward-kill-word() \n\
  914. X     <Key>Right:         forward-character() \n\
  915. X     <Key>Left:          backward-character() \n\
  916. X     <Key>Delete:        delete-previous-character() \n\
  917. X     <Key>BackSpace:     delete-previous-character() \n\
  918. X     <Key>Return:        redraw-display() \n\
  919. X     <Key>Linefeed:      redraw-display() \n\
  920. X     <Key>Down:          redraw-display() \n\
  921. X     <Key>Up:            redraw-display() \n\
  922. X     <Key>0:          insert-char() \n\
  923. X     <Key>1:          insert-char() \n\
  924. X     <Key>2:          insert-char() \n\
  925. X     <Key>3:          insert-char() \n\
  926. X     <Key>4:          insert-char() \n\
  927. X     <Key>5:          insert-char() \n\
  928. X     <Key>6:          insert-char() \n\
  929. X     <Key>7:          insert-char() \n\
  930. X     <Key>8:          insert-char() \n\
  931. X     <Key>9:          insert-char() \n\
  932. X     <Key>-:          insert-char() \n\
  933. X     Shift<Key>=:      insert-char() \n\
  934. X     <Key>.:          insert-char() \n\
  935. X     <FocusIn>:          focus-in() \n\
  936. X     <FocusOut>:         focus-out() \n\
  937. X     <Btn1Down>:         select-start() \n\
  938. X     <Btn1Motion>:       extend-adjust() \n\
  939. X     <Btn1Up>:           extend-end(PRIMARY, CUT_BUFFER0) \n\
  940. X     <Btn3Down>:         extend-start() \n\
  941. X     <Btn3Motion>:       extend-adjust() \n\
  942. X     <Btn3Up>:           extend-end(PRIMARY, CUT_BUFFER0)";
  943. X
  944. Xchar str_one_line_translations[] = "\
  945. X     Ctrl<Key>F:         forward-character() \n\
  946. X     Ctrl<Key>B:         backward-character() \n\
  947. X     Ctrl<Key>D:         delete-next-character() \n\
  948. X     Ctrl<Key>A:         beginning-of-line() \n\
  949. X     Ctrl<Key>E:         end-of-line() \n\
  950. X     Ctrl<Key>H:         delete-previous-character() \n\
  951. X     Ctrl<Key>K:         kill-to-end-of-line() \n\
  952. X     Ctrl<Key>J:         redraw-display() \n\
  953. X     Ctrl<Key>L:         redraw-display() \n\
  954. X     Ctrl<Key>M:         redraw-display() \n\
  955. X     Ctrl<Key>N:         redraw-display() \n\
  956. X     Ctrl<Key>O:         redraw-display() \n\
  957. X     Ctrl<Key>P:         redraw-display() \n\
  958. X     Ctrl<Key>V:         redraw-display() \n\
  959. X     Ctrl<Key>W:         kill-selection() \n\
  960. X     Ctrl<Key>Y:         unkill() \n\
  961. X     Ctrl<Key>Z:         redraw-display() \n\
  962. X     Meta<Key>F:         forward-word() \n\
  963. X     Meta<Key>B:         backward-word() \n\
  964. X     Meta<Key>Y:         stuff() \n\
  965. X     Meta<Key>Z:         redraw-display() \n\
  966. X     Meta<Key>I:         redraw-display() \n\
  967. X     Meta<Key>K:         redraw-display() \n\
  968. X     Meta<Key>V:         redraw-display() \n\
  969. X     :Meta<Key>d:        delete-next-word() \n\
  970. X     :Meta<Key>D:        kill-word() \n\
  971. X     :Meta<Key>h:        delete-previous-word() \n\
  972. X     :Meta<Key>H:        backward-kill-word() \n\
  973. X     :Meta<Key>\<:       redraw-display() \n\
  974. X     :Meta<Key>\>:       redraw-display() \n\
  975. X     :Meta<Key>]:        redraw-display() \n\
  976. X     :Meta<Key>[:        redraw-display() \n\
  977. X     ~Shift Meta<Key>Delete:delete-previous-word() \n\
  978. X      Shift Meta<Key>Delete:backward-kill-word() \n\
  979. X     ~Shift Meta<Key>BackSpace:delete-previous-word() \n\
  980. X      Shift Meta<Key>BackSpace:backward-kill-word() \n\
  981. X     <Key>Right:         forward-character() \n\
  982. X     <Key>Left:          backward-character() \n\
  983. X     <Key>Delete:        delete-previous-character() \n\
  984. X     <Key>BackSpace:     delete-previous-character() \n\
  985. X     <Key>Return:        redraw-display() \n\
  986. X     <Key>Linefeed:      redraw-display() \n\
  987. X     <Key>Down:          redraw-display() \n\
  988. X     <Key>Up:            redraw-display() \n\
  989. X     <Key>:          insert-char() \n\
  990. X     <FocusIn>:          focus-in() \n\
  991. X     <FocusOut>:         focus-out() \n\
  992. X     <Btn1Down>:         select-start() \n\
  993. X     <Btn1Motion>:       extend-adjust() \n\
  994. X     <Btn1Up>:           extend-end(PRIMARY, CUT_BUFFER0) \n\
  995. X     <Btn3Down>:         extend-start() \n\
  996. X     <Btn3Motion>:       extend-adjust() \n\
  997. X     <Btn3Up>:           extend-end(PRIMARY, CUT_BUFFER0)";
  998. X
  999. X/*     <Btn2Down>:         insert-selection(PRIMARY, CUT_BUFFER0) \n\*/
  1000. X
  1001. X
  1002. XXtTranslations numbers_oneline, string_oneline;
  1003. X
  1004. Xset_translations()
  1005. X{
  1006. X  numbers_oneline = XtParseTranslationTable(num_one_line_translations);
  1007. X  string_oneline = XtParseTranslationTable(str_one_line_translations);
  1008. X}
  1009. END_OF_FILE
  1010. if test 29848 -ne `wc -c <'starchart/starXaw.c'`; then
  1011.     echo shar: \"'starchart/starXaw.c'\" unpacked with wrong size!
  1012. fi
  1013. # end of 'starchart/starXaw.c'
  1014. fi
  1015. echo shar: End of archive 17 \(of 32\).
  1016. cp /dev/null ark17isdone
  1017. MISSING=""
  1018. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 ; do
  1019.     if test ! -f ark${I}isdone ; then
  1020.     MISSING="${MISSING} ${I}"
  1021.     fi
  1022. done
  1023. if test "${MISSING}" = "" ; then
  1024.     echo You have unpacked all 32 archives.
  1025.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1026. else
  1027.     echo You still need to unpack the following archives:
  1028.     echo "        " ${MISSING}
  1029. fi
  1030. ##  End of shell archive.
  1031. exit 0
  1032.  
  1033.