home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume21 / xvig / part10 < prev    next >
Encoding:
Text File  |  1993-11-23  |  28.9 KB  |  891 lines

  1. Newsgroups: comp.sources.x
  2. From: demaree@imec.be (Antoon Demaree)
  3. Subject: v21i057:  xvig - XviG Graphics Library, Part10/10
  4. Message-ID: <1993Nov23.172908.17535@sparky.sterling.com>
  5. X-Md4-Signature: 8bb1da5c347903eb94872f7bd2b7be8b
  6. Sender: chris@sparky.sterling.com (Chris Olson)
  7. Organization: Sterling Software
  8. Date: Tue, 23 Nov 1993 17:29:08 GMT
  9. Approved: chris@sterling.com
  10.  
  11. Submitted-by: demaree@imec.be (Antoon Demaree)
  12. Posting-number: Volume 21, Issue 57
  13. Archive-name: xvig/part10
  14. Environment: X11
  15.  
  16. #! /bin/sh
  17. # This is a shell archive.  Remove anything before this line, then feed it
  18. # into a shell via "sh file" or similar.  To overwrite existing files,
  19. # type "sh file -c".
  20. # Contents:  version_1.1/src/xvig.c
  21. # Wrapped by chris@sparky on Tue Nov 23 11:18:00 1993
  22. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  23. echo If this archive is complete, you will see the following message:
  24. echo '          "shar: End of archive 10 (of 10)."'
  25. if test -f 'version_1.1/src/xvig.c' -a "${1}" != "-c" ; then 
  26.   echo shar: Will not clobber existing file \"'version_1.1/src/xvig.c'\"
  27. else
  28.   echo shar: Extracting \"'version_1.1/src/xvig.c'\" \(26491 characters\)
  29.   sed "s/^X//" >'version_1.1/src/xvig.c' <<'END_OF_FILE'
  30. X/* File>>> xvig.c
  31. X--
  32. X-- %M% -- version %I% (IMEC)            last updated: %E%
  33. X--
  34. X-- Copyright (c) 1993
  35. X-- IMEC vzw
  36. X-- Kapeldreef 75
  37. X-- B-3001 LEUVEN
  38. X-- BELGIUM
  39. X--
  40. X-- Author   : A. Demaree
  41. X--
  42. X-- Date     : February 1, 1993
  43. X--
  44. X-- Function : The client program for the `XviG' system that opens the
  45. X--            graphics window, and processes the events.
  46. X--
  47. X-- Usage    : xvig <version> <win_name> <win_id> <x> <y> <width> <height>
  48. X--
  49. X-- Comment  : version   = a string to identify the version
  50. X--            win_name  = the name of the window
  51. X--            win_id    = the dummy window X-identifier from the parent process
  52. X--            x         = the initial x-position of the window
  53. X--            y         = the initial y-position of the window
  54. X--            width     = the initial width of the window
  55. X--            height    = the initial height of the window
  56. X--
  57. X--            If the x-position value and/or the y-position value are negative,
  58. X--            then the placement of the window is left to the window manager.
  59. X--
  60. X-- Review   :
  61. X--
  62. X*/
  63. X
  64. X
  65. X/*------------------------------------------------------------------------------
  66. X-- Global include files
  67. X------------------------------------------------------------------------------*/
  68. X
  69. X#include <stdlib.h>
  70. X#include <stdio.h>
  71. X#include <string.h>
  72. X#include <X11/Xlib.h>
  73. X#include <X11/Xutil.h>
  74. X#include <X11/Xatom.h>
  75. X#include <X11/cursorfont.h>
  76. X
  77. X#define XK_MISCELLANY
  78. X#include <X11/keysymdef.h>
  79. X
  80. X/*------------------------------------------------------------------------------
  81. X-- Local include files
  82. X------------------------------------------------------------------------------*/
  83. X
  84. X#include "commondata.h"
  85. X#include "xvig.xbm"
  86. X#include "empty.xbm"
  87. X
  88. X/*------------------------------------------------------------------------------
  89. X-- Some general macro definitions
  90. X------------------------------------------------------------------------------*/
  91. X
  92. X#define ABS(n)    ((n) < 0 ? -(n) : (n))
  93. X#define MAX(a,b)  ((a) > (b) ? (a) : (b))
  94. X#define MIN(a,b)  ((a) < (b) ? (a) : (b))
  95. X
  96. X/*------------------------------------------------------------------------------
  97. X-- Static variable declarations
  98. X------------------------------------------------------------------------------*/
  99. X
  100. Xstatic Display *display;
  101. Xstatic int screen_nr;
  102. Xstatic Window dummy_window, window;
  103. Xstatic Cursor arrow_cursor, empty_cursor;
  104. Xstatic Pixmap pixmap, border_select, border_noselect, icon_pixmap;
  105. Xstatic GC gc;
  106. Xstatic XEvent event;
  107. Xstatic unsigned int window_width, window_height;
  108. Xstatic Atom wm_protocols_atom, wm_delete_window_atom;
  109. X
  110. X/*
  111. X-- The Atoms for the ClientMessage events
  112. X*/
  113. X
  114. Xstatic Atom MESSAGE_INIT_atom,
  115. X            MESSAGE_KEY_atom,
  116. X            MESSAGE_BUTTON_atom,
  117. X            MESSAGE_KEY_BUTTON_atom,
  118. X            MESSAGE_SIZE_atom,
  119. X            MESSAGE_SENSEKBD_ON_atom,
  120. X            MESSAGE_SENSEKBD_OFF_atom,
  121. X            MESSAGE_SENSEKBD_atom,
  122. X            MESSAGE_CURSOR_atom,
  123. X            MESSAGE_QUIT_atom;
  124. X
  125. X/*------------------------------------------------------------------------------
  126. X-- Local function declarations
  127. X------------------------------------------------------------------------------*/
  128. X
  129. Xstatic void Parse_Commandline(int argc,
  130. X                              char *argv[],
  131. X                              int *x,
  132. X                              int *y,
  133. X                              unsigned int *width,
  134. X                              unsigned int *height);
  135. Xstatic void Set_WMproperties(char *window_name,
  136. X                             int x,
  137. X                             int y,
  138. X                             unsigned int width,
  139. X                             unsigned int height);
  140. Xstatic void Create_Cursors(void);
  141. Xstatic Pixmap New_Pixmap(unsigned int width,
  142. X                         unsigned int height,
  143. X                         unsigned int depth);
  144. Xstatic void Border_Pixmaps(unsigned int depth);
  145. Xstatic void Refresh_Screen(void);
  146. Xstatic void Window_Size(void);
  147. Xstatic void Cleanup(void);
  148. X
  149. X/*------------------------------------------------------------------------------
  150. X--
  151. X--
  152. X--
  153. X------------------------------------------------------------------------------*/
  154. X
  155. Xmain(int argc, char *argv[])
  156. X{
  157. X  int init_x, init_y;
  158. X  unsigned int init_width, init_height;
  159. X  Window root_rtn;
  160. X  int x_rtn, y_rtn;
  161. X  unsigned int width_rtn, height_rtn, bwidth_rtn, depth_rtn;
  162. X  KeySym keysym;
  163. X  Bool sense_kbd_set = False,
  164. X       sense_kbd_save = False,
  165. X       sense_kbd = False;
  166. X  char sense_char, tmpstr[8];
  167. X  long cursor_type = DATA_CURSOR_ARROW;
  168. X  Bool cursor_on, cursor_drawn;
  169. X  unsigned int cursor_width, cursor_height;
  170. X  int cursor_hot_x, cursor_hot_y;
  171. X  int prev_cursor_x, prev_cursor_y;
  172. X  unsigned long xhair_color;
  173. X  unsigned int xhair_width, xhair_height;
  174. X  Bool do_event_loop = True;
  175. X
  176. X  /*
  177. X  -- Parsing the command line options
  178. X  */
  179. X
  180. X  Parse_Commandline(argc, argv, &init_x, &init_y, &init_width, &init_height);
  181. X
  182. X  /*
  183. X  -- Open the display
  184. X  */
  185. X
  186. X  if (!(display = XOpenDisplay(NULL)))
  187. X  {
  188. X    char *dname;
  189. X
  190. X    if (!(dname = getenv("DISPLAY")))
  191. X      fprintf(stderr,
  192. X       "ERROR (XviG) : Environment variable 'DISPLAY' has not been defined.\n");
  193. X    else
  194. X      fprintf(stderr,
  195. X              "ERROR (XviG) : Cannot open display '%s'.\n", dname);
  196. X    exit(1);
  197. X  }
  198. X
  199. X  screen_nr = DefaultScreen(display);
  200. X
  201. X  /*
  202. X  -- Take the default Graphic Context and set the GraphicsExposures off
  203. X  */
  204. X
  205. X  gc = DefaultGC(display, screen_nr);
  206. X  XSetGraphicsExposures(display, gc, False);
  207. X
  208. X  /*
  209. X  -- Create the real window, and set the 'Window Manager' properties
  210. X  */
  211. X
  212. X  if (!(window = XCreateSimpleWindow(display, RootWindow(display, screen_nr),
  213. X                                     init_x < 0 ? 0 : init_x,
  214. X                                     init_y < 0 ? 0 : init_y,
  215. X                                     init_width, init_height, BORDER_WIDTH,
  216. X                                     WhitePixel(display, screen_nr),
  217. X                                     BlackPixel(display, screen_nr))))
  218. X  {
  219. X    fprintf(stderr, "ERROR (XviG) : Cannot create window.\n");
  220. X    XCloseDisplay(display);
  221. X    exit(1);
  222. X  }
  223. X
  224. X  Set_WMproperties(argv[2], init_x, init_y, init_width, init_height);
  225. X
  226. X  /*
  227. X  -- Map the window and wait for the event that it is
  228. X  -- actually mapped (e.g. by the window manager),
  229. X  -- taking care of the appropriate event mask
  230. X  */
  231. X
  232. X  XSelectInput(display, window, ExposureMask | StructureNotifyMask);
  233. X
  234. X  XMapWindow(display, window);
  235. X
  236. X  while (1)
  237. X  {
  238. X    XNextEvent(display, &event);
  239. X
  240. X    if (event.type == MapNotify)
  241. X      break;
  242. X  }
  243. X
  244. X  XSelectInput(display, window, ExposureMask);
  245. X
  246. X  /*
  247. X  -- Set the default cursor for the window to an arrow
  248. X  -- and create an empty cursor
  249. X  */
  250. X
  251. X  Create_Cursors();
  252. X
  253. X  /*
  254. X  -- Create a pixmap with the same size as the window
  255. X  -- and set the Xhair cursor size
  256. X  */
  257. X
  258. X  if (XGetGeometry(display, window, &root_rtn, &x_rtn, &y_rtn,
  259. X                   &width_rtn, &height_rtn, &bwidth_rtn, &depth_rtn))
  260. X  {
  261. X    pixmap = New_Pixmap(width_rtn, height_rtn, depth_rtn);
  262. X    window_width  = xhair_width  = width_rtn;
  263. X    window_height = xhair_height = height_rtn;
  264. X  }
  265. X  else
  266. X  {
  267. X    printf("WARNING (XviG) : Cannot get size of initial window.\n");
  268. X
  269. X    pixmap = New_Pixmap(1, 1, DefaultDepth(display, screen_nr));
  270. X    window_width  = xhair_width  = 1;
  271. X    window_height = xhair_height = 1;
  272. X  }
  273. X
  274. X  /*
  275. X  -- Create the border pixmaps and set the window border to 'no cursor input'
  276. X  */
  277. X
  278. X  Border_Pixmaps(DefaultDepth(display, screen_nr));
  279. X
  280. X  XSetWindowBorderPixmap(display, window, border_noselect);
  281. X
  282. X  /*
  283. X  -- Create the Atoms (unique numbers) for the ClientMessage events
  284. X  */
  285. X
  286. X  MESSAGE_INIT_atom = XInternAtom(display, MESSAGE_INIT, False);
  287. X  MESSAGE_KEY_atom = XInternAtom(display, MESSAGE_KEY, False);
  288. X  MESSAGE_BUTTON_atom = XInternAtom(display, MESSAGE_BUTTON, False);
  289. X  MESSAGE_KEY_BUTTON_atom = XInternAtom(display, MESSAGE_KEY_BUTTON, False);
  290. X  MESSAGE_SIZE_atom = XInternAtom(display, MESSAGE_SIZE, False);
  291. X  MESSAGE_SENSEKBD_ON_atom = XInternAtom(display, MESSAGE_SENSEKBD_ON, False);
  292. X  MESSAGE_SENSEKBD_OFF_atom = XInternAtom(display, MESSAGE_SENSEKBD_OFF, False);
  293. X  MESSAGE_SENSEKBD_atom = XInternAtom(display, MESSAGE_SENSEKBD, False);
  294. X  MESSAGE_CURSOR_atom = XInternAtom(display, MESSAGE_CURSOR, False);
  295. X  MESSAGE_QUIT_atom = XInternAtom(display, MESSAGE_QUIT, False);
  296. X
  297. X  /*
  298. X  -- Send a ClientMessage to the dummy window with
  299. X  -- the real window ID, the pixmap ID and the window size
  300. X  */
  301. X
  302. X  event.xclient.message_type = MESSAGE_INIT_atom;
  303. X  event.xclient.window = window;
  304. X  event.xclient.format = 32;
  305. X  event.xclient.data.l[0] = (long) pixmap;
  306. X  event.xclient.data.l[1] = (long) window_width;
  307. X  event.xclient.data.l[2] = (long) window_height;
  308. X  event.type = ClientMessage;
  309. X
  310. X  if (!XSendEvent(display, dummy_window, False, NoEventMask, &event))
  311. X    fprintf(stderr, "ERROR (XviG) : Cannot send ClientMessage 'init'.\n");
  312. X
  313. X  /*
  314. X  -- Event loop for a keypress or a buttonpress
  315. X  */
  316. X
  317. X  while (do_event_loop)
  318. X  {
  319. X    XNextEvent(display, &event);
  320. X
  321. X    switch (event.type)
  322. X    {
  323. X      case KeyPress:
  324. X          /* printf("INFO (XviG) : KeyPress event ...\n"); */
  325. X          keysym = XLookupKeysym(&event.xkey, 0);
  326. X          if (IsModifierKey(keysym) == True)
  327. X            continue;
  328. X          if (sense_kbd_set)
  329. X          {
  330. X            if (XLookupString(&event.xkey, tmpstr, 8,
  331. X                              (KeySym *) NULL, (XComposeStatus *) NULL) == 1)
  332. X              if (tmpstr[0] == sense_char)
  333. X                sense_kbd = True;
  334. X            break;
  335. X          }
  336. X      case ButtonPress:
  337. X          /* printf("INFO (XviG) : ButtonPress event ...\n"); */
  338. X          if (cursor_on)
  339. X          {
  340. X            if (cursor_drawn)
  341. X            {
  342. X              XSetFunction(display, gc, GXxor);
  343. X              if (cursor_type == DATA_CURSOR_XHAIR)
  344. X              {
  345. X                XSetForeground(display, gc, xhair_color);
  346. X                XDrawLine(display, window, gc,
  347. X                          prev_cursor_x, 0, prev_cursor_x, (int) xhair_height);
  348. X                XDrawLine(display, window, gc,
  349. X                          0, prev_cursor_y, (int) xhair_width, prev_cursor_y);
  350. X              }
  351. X              else
  352. X              if (cursor_type != DATA_CURSOR_ARROW)
  353. X              {
  354. X                XCopyArea(display, (Pixmap) cursor_type, window, gc,
  355. X                          0, 0, cursor_width, cursor_height,
  356. X                          prev_cursor_x, prev_cursor_y);
  357. X              }
  358. X              cursor_drawn = False;
  359. X            }
  360. X            cursor_on = False;
  361. X            XDefineCursor(display, window, arrow_cursor);
  362. X          }
  363. X          if (!XSendEvent(display, dummy_window, False, NoEventMask, &event))
  364. X            fprintf(stderr,
  365. X                 "ERROR (XviG) : Cannot send KeyPress or ButtonPress event.\n");
  366. X          XSetWindowBorderPixmap(display, window, border_noselect);
  367. X          if (sense_kbd_save)
  368. X          {
  369. X            sense_kbd_set = True;
  370. X            XSelectInput(display, window, KeyPressMask | ExposureMask);
  371. X            sense_kbd = False;
  372. X          }
  373. X          else
  374. X            XSelectInput(display, window, ExposureMask);
  375. X          break;
  376. X      case MotionNotify:
  377. X          /* printf("INFO (XviG) : MotionNotify event ...\n"); */
  378. X          while (XCheckMaskEvent(display, PointerMotionMask, &event));
  379. X          if (cursor_on)
  380. X          {
  381. X            XSetFunction(display, gc, GXxor);
  382. X            if (cursor_type == DATA_CURSOR_XHAIR)
  383. X            {
  384. X              XSetForeground(display, gc, xhair_color);
  385. X              if (cursor_drawn)
  386. X              {
  387. X                XDrawLine(display, window, gc,
  388. X                          prev_cursor_x, 0, prev_cursor_x, (int) xhair_height);
  389. X                XDrawLine(display, window, gc,
  390. X                          0, prev_cursor_y, (int) xhair_width, prev_cursor_y);
  391. X              }
  392. X              prev_cursor_x = event.xmotion.x;
  393. X              prev_cursor_y = event.xmotion.y;
  394. X              XDrawLine(display, window, gc,
  395. X                        prev_cursor_x, 0, prev_cursor_x, (int) xhair_height);
  396. X              XDrawLine(display, window, gc,
  397. X                        0, prev_cursor_y, (int) xhair_width, prev_cursor_y);
  398. X            }
  399. X            else
  400. X            if (cursor_type != DATA_CURSOR_ARROW)
  401. X            {
  402. X              if (cursor_drawn)
  403. X              {
  404. X                XCopyArea(display, (Pixmap) cursor_type, window, gc,
  405. X                          0, 0, cursor_width, cursor_height,
  406. X                          prev_cursor_x, prev_cursor_y);
  407. X              }
  408. X              prev_cursor_x = event.xmotion.x - cursor_hot_x;
  409. X              prev_cursor_y = event.xmotion.y - cursor_hot_y;
  410. X              XCopyArea(display, (Pixmap) cursor_type, window, gc,
  411. X                        0, 0, cursor_width, cursor_height,
  412. X                        prev_cursor_x, prev_cursor_y);
  413. X            }
  414. X            cursor_drawn = True;
  415. X          }
  416. X          break;
  417. X      case Expose:
  418. X          /* printf("INFO (XviG) : Expose event ...\n"); */
  419. X          if (event.xexpose.count == 0)
  420. X          {
  421. X            Refresh_Screen();
  422. X            cursor_drawn = False;
  423. X            XGetGeometry(display, window, &root_rtn, &x_rtn, &y_rtn,
  424. X                         &xhair_width, &xhair_height, &bwidth_rtn, &depth_rtn);
  425. X          }
  426. X          break;
  427. X      case ClientMessage:
  428. X          /* printf("INFO (XviG) : ClientMessage event ...\n"); */
  429. X          if (event.xclient.message_type == MESSAGE_KEY_atom)
  430. X          {
  431. X            XSetWindowBorderPixmap(display, window, border_select);
  432. X            if (cursor_type)
  433. X            {
  434. X              XSelectInput(display, window,
  435. X                           KeyPressMask | PointerMotionMask | ExposureMask);
  436. X              XDefineCursor(display, window, empty_cursor);
  437. X              cursor_on = True;
  438. X            }
  439. X            else
  440. X            {
  441. X              XSelectInput(display, window, KeyPressMask | ExposureMask);
  442. X              cursor_on = False;
  443. X            }
  444. X            cursor_drawn = False;
  445. X            sense_kbd_set = False;
  446. X            break;
  447. X          }
  448. X          if (event.xclient.message_type == MESSAGE_BUTTON_atom)
  449. X          {
  450. X            XSetWindowBorderPixmap(display, window, border_select);
  451. X            if (cursor_type)
  452. X            {
  453. X              XSelectInput(display, window,
  454. X                           ButtonPressMask | PointerMotionMask | ExposureMask);
  455. X              XDefineCursor(display, window, empty_cursor);
  456. X              cursor_on = True;
  457. X            }
  458. X            else
  459. X            {
  460. X              XSelectInput(display, window, ButtonPressMask | ExposureMask);
  461. X              cursor_on = False;
  462. X            }
  463. X            cursor_drawn = False;
  464. X            break;
  465. X          }
  466. X          if (event.xclient.message_type == MESSAGE_KEY_BUTTON_atom)
  467. X          {
  468. X            XSetWindowBorderPixmap(display, window, border_select);
  469. X            if (cursor_type)
  470. X            {
  471. X              XSelectInput(display, window,
  472. X                           KeyPressMask | ButtonPressMask |
  473. X                           PointerMotionMask | ExposureMask);
  474. X              XDefineCursor(display, window, empty_cursor);
  475. X              cursor_on = True;
  476. X            }
  477. X            else
  478. X            {
  479. X              XSelectInput(display, window,
  480. X                           KeyPressMask | ButtonPressMask | ExposureMask);
  481. X              cursor_on = False;
  482. X            }
  483. X            cursor_drawn = False;
  484. X            sense_kbd_set = False;
  485. X            break;
  486. X          }
  487. X          if (event.xclient.message_type == MESSAGE_SIZE_atom)
  488. X          {
  489. X            Window_Size();
  490. X            break;
  491. X          }
  492. X          if (event.xclient.message_type == MESSAGE_SENSEKBD_ON_atom)
  493. X          {
  494. X            sense_kbd_set = sense_kbd_save = True;
  495. X            sense_char = event.xclient.data.b[0];
  496. X            XSelectInput(display, window, KeyPressMask | ExposureMask);
  497. X            sense_kbd = False;
  498. X            break;
  499. X          }
  500. X          if (event.xclient.message_type == MESSAGE_SENSEKBD_OFF_atom)
  501. X          {
  502. X            sense_kbd_set = sense_kbd_save = False;
  503. X            XSelectInput(display, window, ExposureMask);
  504. X            sense_kbd = False;
  505. X            break;
  506. X          }
  507. X          if (event.xclient.message_type == MESSAGE_SENSEKBD_atom)
  508. X          {
  509. X            event.xclient.message_type = MESSAGE_SENSEKBD_atom;
  510. X            event.xclient.format = 8;
  511. X            event.xclient.data.b[0] = sense_kbd ? DATA_SENSEKBD_YES
  512. X                                                : DATA_SENSEKBD_NO;
  513. X            event.type = ClientMessage;
  514. X            if (!XSendEvent(display, dummy_window, False, NoEventMask, &event))
  515. X              fprintf(stderr,
  516. X                     "ERROR (XviG) : Cannot send ClientMessage 'sense_kbd'.\n");
  517. X            sense_kbd = False;
  518. X            break;
  519. X          }
  520. X          if (event.xclient.message_type == MESSAGE_CURSOR_atom)
  521. X          {
  522. X            cursor_type = event.xclient.data.l[0];
  523. X            if (cursor_type == DATA_CURSOR_XHAIR)
  524. X              xhair_color = (unsigned long) event.xclient.data.l[1];
  525. X            else
  526. X            if (cursor_type != DATA_CURSOR_ARROW)
  527. X            {
  528. X              cursor_width = (unsigned int) event.xclient.data.l[1];
  529. X              cursor_height = (unsigned int) event.xclient.data.l[2];
  530. X              cursor_hot_x = (int) event.xclient.data.l[3];
  531. X              cursor_hot_y = (int) event.xclient.data.l[4];
  532. X            }
  533. X            break;
  534. X          }
  535. X          if (event.xclient.message_type == MESSAGE_QUIT_atom)
  536. X          {
  537. X            do_event_loop = False;
  538. X            break;
  539. X          }
  540. X          if (event.xclient.message_type == wm_protocols_atom)
  541. X          {
  542. X            if ((Atom) event.xclient.data.l[0] != wm_delete_window_atom)
  543. X              printf("WARNING (XviG) : Unknown Protocols message received.\n");
  544. X            /*
  545. X            else
  546. X              printf("INFO (XviG) : WM_DELETE_WINDOW received.\n");
  547. X            */
  548. X            break;
  549. X          }
  550. X          /*
  551. X          printf("WARNING (XviG) : Unknown ClientMessage received .....\n");
  552. X          */
  553. X          break;
  554. X      default: ;
  555. X    }
  556. X  }
  557. X
  558. X  /*
  559. X  -- Quit .....
  560. X  */
  561. X
  562. X  Cleanup();
  563. X
  564. X  return 0;
  565. X}
  566. X
  567. X/*------------------------------------------------------------------------------
  568. X--
  569. X--
  570. X--
  571. X------------------------------------------------------------------------------*/
  572. X
  573. Xstatic void Parse_Commandline(int argc,
  574. X                              char *argv[],
  575. X                              int *x,
  576. X                              int *y,
  577. X                              unsigned int *width,
  578. X                              unsigned int *height)
  579. X{
  580. X  long nr;
  581. X  char *endptr;
  582. X
  583. X  if (argc != 8)
  584. X  {
  585. X    fprintf(stderr, "ERROR (XviG) : Wrong number of arguments.\n");
  586. X    exit(1);
  587. X  }
  588. X
  589. X  if (strcmp(argv[1], XviG_VERSION))
  590. X  {
  591. X    fprintf(stderr, "ERROR (XviG) : Wrong version of XviG.\n");
  592. X    fprintf(stderr, "               Please relink with the correct version.\n");
  593. X    exit(1);
  594. X  }
  595. X
  596. X  nr = strtol(argv[3], &endptr, 10);
  597. X  if ((*endptr != '\0') || (nr <= 0))
  598. X  {
  599. X    fprintf(stderr, "ERROR (XviG) : Invalid window number.\n");
  600. X    exit(1);
  601. X  }
  602. X  dummy_window = (Window) nr;
  603. X
  604. X  *x = (int) strtol(argv[4], &endptr, 10);
  605. X  if (*endptr != '\0')
  606. X  {
  607. X    printf("WARNING (XviG) : Invalid x-position, assuming not specified.\n");
  608. X    *x = -1;
  609. X  }
  610. X
  611. X  *y = (int) strtol(argv[5], &endptr, 10);
  612. X  if (*endptr != '\0')
  613. X  {
  614. X    printf("WARNING (XviG) : Invalid y-position, assuming not specified.\n");
  615. X    *y = -1;
  616. X  }
  617. X
  618. X  *width = (int) strtol(argv[6], &endptr, 10);
  619. X  if ((*endptr != '\0') || (*width <= 0))
  620. X  {
  621. X    printf("WARNING (XviG) : Invalid initial window width, setting to 300.\n");
  622. X    *width = 300;
  623. X  }
  624. X
  625. X  *height = (int) strtol(argv[7], &endptr, 10);
  626. X  if ((*endptr != '\0') || (*height <= 0))
  627. X  {
  628. X    printf("WARNING (XviG) : Invalid initial window height, setting to 300.\n");
  629. X    *height = 300;
  630. X  }
  631. X}
  632. X
  633. X/*------------------------------------------------------------------------------
  634. X--
  635. X--
  636. X--
  637. X------------------------------------------------------------------------------*/
  638. X
  639. Xstatic void Set_WMproperties(char *window_name,
  640. X                             int x,
  641. X                             int y,
  642. X                             unsigned int width,
  643. X                             unsigned int height)
  644. X{
  645. X  XTextProperty text_prop;
  646. X  XSizeHints size_hints;
  647. X  XWMHints wm_hints;
  648. X
  649. X  text_prop.value = (unsigned char *) window_name;
  650. X  text_prop.encoding = XA_STRING;
  651. X  text_prop.format = 8;
  652. X  text_prop.nitems = strlen(window_name);
  653. X  XSetWMName(display, window, &text_prop);
  654. X
  655. X  text_prop.value = (unsigned char *) window_name;
  656. X  text_prop.encoding = XA_STRING;
  657. X  text_prop.format = 8;
  658. X  text_prop.nitems = strlen(window_name);
  659. X  XSetWMIconName(display, window, &text_prop);
  660. X
  661. X  wm_hints.flags = IconPixmapHint;
  662. X  wm_hints.icon_pixmap = icon_pixmap
  663. X                       = XCreateBitmapFromData(display, window,
  664. X                                (char *) xvig_bits, xvig_width, xvig_height);
  665. X  XSetWMHints(display, window, &wm_hints);
  666. X
  667. X  if (!((x < 0) || (y < 0)))
  668. X  {
  669. X    size_hints.flags = USPosition | USSize;
  670. X    size_hints.x = x;
  671. X    size_hints.y = y;
  672. X    size_hints.width = width;
  673. X    size_hints.height = height;
  674. X    XSetWMNormalHints(display, window, &size_hints);
  675. X  }
  676. X
  677. X  /*
  678. X  -- Set the WM_PROTOCOLS property to catch an accidental close of the window
  679. X  */
  680. X
  681. X  wm_protocols_atom = XInternAtom(display, "WM_PROTOCOLS", False);
  682. X  wm_delete_window_atom = XInternAtom(display, "WM_DELETE_WINDOW", False);
  683. X  if (XSetWMProtocols(display, window, &wm_delete_window_atom, 1) == 0)
  684. X    printf("WARNING (XviG) : Cannot set WM_DELETE_WINDOW protocol.\n");
  685. X}
  686. X
  687. X/*------------------------------------------------------------------------------
  688. X--
  689. X--
  690. X--
  691. X------------------------------------------------------------------------------*/
  692. X
  693. Xstatic void Create_Cursors(void)
  694. X{
  695. X  Pixmap bitmap;
  696. X  XColor color;
  697. X
  698. X  if (!(arrow_cursor = XCreateFontCursor(display, XC_arrow)))
  699. X    printf("WARNING (XviG) : Cannot create arrow cursor.\n");
  700. X  else
  701. X    XDefineCursor(display, window, arrow_cursor);
  702. X
  703. X  if (!(bitmap = XCreateBitmapFromData(display, window,
  704. X                                       empty_bits, empty_width, empty_height)))
  705. X  {
  706. X    printf("WARNING (XviG) : Cannot create empty bitmap.\n");
  707. X    empty_cursor = None;
  708. X    return;
  709. X  }
  710. X
  711. X  if (!(empty_cursor = XCreatePixmapCursor(display, bitmap, bitmap,
  712. X                                           &color, &color, 0, 0)))
  713. X    printf("WARNING (XviG) : Cannot create empty cursor.\n");
  714. X
  715. X  XFreePixmap(display, bitmap);
  716. X}
  717. X
  718. X/*------------------------------------------------------------------------------
  719. X--
  720. X--
  721. X--
  722. X------------------------------------------------------------------------------*/
  723. X
  724. Xstatic Pixmap New_Pixmap(unsigned int width,
  725. X                         unsigned int height,
  726. X                         unsigned int depth)
  727. X{
  728. X  Pixmap pixmap;
  729. X
  730. X  pixmap = XCreatePixmap(display, window, width, height, depth);
  731. X  XSetForeground(display, gc, BlackPixel(display, screen_nr));
  732. X  XSetFillStyle(display, gc, FillSolid);
  733. X  XSetFunction(display, gc, GXcopy);
  734. X  XFillRectangle(display, pixmap, gc, 0, 0, width, height);
  735. X
  736. X  return pixmap;
  737. X}
  738. X
  739. X/*------------------------------------------------------------------------------
  740. X--
  741. X--
  742. X--
  743. X------------------------------------------------------------------------------*/
  744. X
  745. Xstatic void Border_Pixmaps(unsigned int depth)
  746. X{
  747. X  border_select = XCreatePixmap(display, window, 4, 4, depth);
  748. X  XSetForeground(display, gc, WhitePixel(display, screen_nr));
  749. X  XFillRectangle(display, border_select, gc, 0, 0, 4, 4);
  750. X
  751. X  border_noselect = XCreatePixmap(display, window, 4, 4, depth);
  752. X  XSetForeground(display, gc, BlackPixel(display, screen_nr));
  753. X  XFillRectangle(display, border_noselect, gc, 0, 0, 4, 4);
  754. X  XSetForeground(display, gc, WhitePixel(display, screen_nr));
  755. X  XDrawPoint(display, border_noselect, gc, 0, 0);
  756. X  XDrawPoint(display, border_noselect, gc, 2, 0);
  757. X  XDrawPoint(display, border_noselect, gc, 1, 1);
  758. X  XDrawPoint(display, border_noselect, gc, 3, 1);
  759. X  XDrawPoint(display, border_noselect, gc, 0, 2);
  760. X  XDrawPoint(display, border_noselect, gc, 2, 2);
  761. X  XDrawPoint(display, border_noselect, gc, 1, 3);
  762. X  XDrawPoint(display, border_noselect, gc, 3, 3);
  763. X}
  764. X
  765. X/*------------------------------------------------------------------------------
  766. X--
  767. X--
  768. X--
  769. X------------------------------------------------------------------------------*/
  770. X
  771. Xstatic void Refresh_Screen(void)
  772. X{
  773. X  /*
  774. X  -- To avoid that any 'rubbish' remains on the window
  775. X  -- (e.g. from a cursor), we clear the window first
  776. X  */
  777. X
  778. X  XClearWindow(display, window);
  779. X
  780. X  XSetFunction(display, gc, GXcopy);
  781. X  XCopyArea(display, pixmap, window, gc,
  782. X            0, 0, window_width, window_height, 0, 0);
  783. X}
  784. X
  785. X/*------------------------------------------------------------------------------
  786. X--
  787. X--
  788. X--
  789. X------------------------------------------------------------------------------*/
  790. X
  791. Xstatic void Window_Size(void)
  792. X{
  793. X  Window root_rtn;
  794. X  int x_rtn, y_rtn;
  795. X  unsigned int width_rtn, height_rtn, bwidth_rtn, depth_rtn;
  796. X  Pixmap new_pixmap;
  797. X
  798. X  event.xclient.message_type = MESSAGE_SIZE_atom;
  799. X  event.xclient.format = 32;
  800. X  event.type = ClientMessage;
  801. X
  802. X  if (XGetGeometry(display, window, &root_rtn, &x_rtn, &y_rtn,
  803. X                   &width_rtn, &height_rtn, &bwidth_rtn, &depth_rtn))
  804. X  {
  805. X    event.xclient.data.l[0] = (long) width_rtn;
  806. X    event.xclient.data.l[1] = (long) height_rtn;
  807. X
  808. X    if ((width_rtn != window_width) || (height_rtn != window_height))
  809. X    {
  810. X      new_pixmap = New_Pixmap(width_rtn, height_rtn, depth_rtn);
  811. X
  812. X      XCopyArea(display, pixmap, new_pixmap, gc,
  813. X                0, 0,
  814. X                MIN(width_rtn, window_width), MIN(height_rtn, window_height),
  815. X                0, 0);
  816. X
  817. X      XFreePixmap(display, pixmap);
  818. X      pixmap = new_pixmap;
  819. X      window_width = width_rtn;
  820. X      window_height = height_rtn;
  821. X    }
  822. X  }
  823. X  else
  824. X  {
  825. X    printf("WARNING (XviG) : Cannot get size of window.\n");
  826. X    event.xclient.data.l[0] = (long) window_width;
  827. X    event.xclient.data.l[1] = (long) window_height;
  828. X  }
  829. X
  830. X  event.xclient.data.l[2] = (long) pixmap;
  831. X
  832. X  if (!XSendEvent(display, dummy_window, False, NoEventMask, &event))
  833. X    fprintf(stderr, "ERROR (XviG) : Cannot send ClientMessage 'size'.\n");
  834. X}
  835. X
  836. X/*------------------------------------------------------------------------------
  837. X--
  838. X--
  839. X--
  840. X------------------------------------------------------------------------------*/
  841. X
  842. Xstatic void Cleanup(void)
  843. X{
  844. X  if (arrow_cursor)
  845. X    XFreeCursor(display, arrow_cursor);
  846. X  if (empty_cursor)
  847. X    XFreeCursor(display, empty_cursor);
  848. X
  849. X  XFreePixmap(display, pixmap);
  850. X  XFreePixmap(display, border_select);
  851. X  XFreePixmap(display, border_noselect);
  852. X
  853. X  if (icon_pixmap)
  854. X    XFreePixmap(display, icon_pixmap);
  855. X
  856. X  XDestroyWindow(display, window);
  857. X  XCloseDisplay(display);
  858. X}
  859. END_OF_FILE
  860.   if test 26491 -ne `wc -c <'version_1.1/src/xvig.c'`; then
  861.     echo shar: \"'version_1.1/src/xvig.c'\" unpacked with wrong size!
  862.   fi
  863.   # end of 'version_1.1/src/xvig.c'
  864. fi
  865. echo shar: End of archive 10 \(of 10\).
  866. cp /dev/null ark10isdone
  867. MISSING=""
  868. for I in 1 2 3 4 5 6 7 8 9 10 ; do
  869.     if test ! -f ark${I}isdone ; then
  870.     MISSING="${MISSING} ${I}"
  871.     fi
  872. done
  873. if test "${MISSING}" = "" ; then
  874.     echo You have unpacked all 10 archives.
  875.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  876.     echo "Merging xvig.ps parts... "
  877.     cat version_1.1/man/xvig.ps.? > version_1.1/man/xvig.ps
  878.     rm version_1.1/man/xvig.ps.?
  879.     echo "Done."
  880. else
  881.     echo You still must unpack the following archives:
  882.     echo "        " ${MISSING}
  883. fi
  884. exit 0
  885. exit 0 # Just in case...
  886. -- 
  887.   // chris@Sterling.COM           | Send comp.sources.x submissions to:
  888. \X/  Amiga - The only way to fly! |    sources-x@sterling.com
  889.  "It's intuitively obvious to the |
  890.   most casual observer..."        | GCS d+/-- p+ c++ l+ m+ s++/+ g+ w+ t+ r+ x+
  891.