home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / vmsnet / vmstrek / part47 < prev    next >
Encoding:
Text File  |  1992-11-20  |  11.1 KB  |  412 lines

  1. Newsgroups: vmsnet.sources.games
  2. Path: uunet!zaphod.mps.ohio-state.edu!rpi!usenet.coe.montana.edu!news.u.washington.edu!raven.alaska.edu!acad2.alaska.edu!asdmf
  3. From: asdmf@acad2.alaska.edu
  4. Subject: Vmsnetrek 47/47 <- FINALLY!
  5. Message-ID: <1992Nov20.211158.1@acad2.alaska.edu>
  6. Lines: 399
  7. Sender: news@raven.alaska.edu (USENET News System)
  8. Nntp-Posting-Host: acad2.alaska.edu
  9. Organization: University of Alaska
  10. Date: Sat, 21 Nov 1992 01:11:58 GMT
  11. Xref: uunet vmsnet.sources.games:547
  12.  
  13. -+-+-+-+-+-+-+-+ START OF PART 47 -+-+-+-+-+-+-+-+
  14. X    Window wparent;
  15. X    XSetWindowAttributes attrs;
  16. X
  17. X#ifdef DEBUG
  18. X    printf("New window...\n");
  19. X#endif
  20. X    checkGeometry(name, &x, &y, &width, &height);
  21. X    checkParent(name, &parent);
  22. X    wparent=W_Void2Window(parent)->window;
  23. X    attrs.override_redirect=False;
  24. X    attrs.border_pixel=colortable`091W_White`093.pixelValue;
  25. X    attrs.event_mask=ResizeRedirectMask`124ExposureMask;
  26. X    attrs.background_pixel=colortable`091W_Black`093.pixelValue;
  27. X    attrs.do_not_propagate_mask=ResizeRedirectMask`124ExposureMask;
  28. X    newwin=newWindow(
  29. X`009XCreateWindow(W_Display, wparent, x, y,
  30. X            width*W_Textwidth+WIN_EDGE*2, MENU_PAD*2+height*W_Textheight,`03
  31. V2
  32. X`009    border, CopyFromParent, InputOutput, CopyFromParent,
  33. X`009    CWBackPixel`124CWEventMask`124
  34. X`009    CWOverrideRedirect`124CWBorderPixel,`032
  35. X`009    &attrs),
  36. X        WIN_SCROLL);
  37. X    XSetClassHint(W_Display, newwin->window, &class_hint);
  38. X    XSetWMHints(W_Display, newwin->window, &wm_hint);
  39. X    newwin->name=strdup(name);
  40. X    newwin->data=NULL;
  41. X    newwin->width=width;
  42. X    newwin->height=height;
  43. X    if (checkMapped(name)) W_MapWindow(W_Window2Void(newwin));
  44. X#ifdef DEBUG
  45. X    printf("New scroll window %d, child of %d\n", newwin, parent);
  46. X#endif
  47. X    return(W_Window2Void(newwin));
  48. X`125
  49. X
  50. X/* Add a string to the string list of the scrolling window.`032
  51. X */
  52. XAddToScrolling(win, color, str, len)
  53. Xstruct window *win;
  54. XW_Color color;
  55. Xchar *str;
  56. Xint len;
  57. X`123
  58. X    struct stringList **strings;
  59. X    char *newstring;
  60. X    int count;
  61. X
  62. X    strings= (struct stringList **) &(win->data);
  63. X    count=0;
  64. X    while ((*strings)!=NULL) `123
  65. X`009count++;
  66. X`009strings= &((*strings)->next);
  67. X    `125
  68. X    (*strings)=(struct stringList *) malloc(sizeof(struct stringList));
  69. X    (*strings)->next=NULL;
  70. X    (*strings)->color=color;
  71. X    newstring=(char *) malloc(len+1);
  72. X    strncpy(newstring, str, len);
  73. X    newstring`091len`093=0;
  74. X    (*strings)->string=newstring;
  75. X    if (count >= 100) `123`009`009/* Arbitrary large size. */
  76. X`009struct stringList *temp;
  77. X
  78. X`009temp=(struct stringList *) win->data;
  79. X`009free(temp->string);
  80. X`009temp=temp->next;
  81. X`009free((char *) win->data);
  82. X`009win->data=(char *) temp;
  83. X    `125
  84. X`125
  85. X
  86. XredrawScrolling(win)
  87. Xstruct window *win;
  88. X`123
  89. X    int count;
  90. X    struct stringList *list;
  91. X    int y;
  92. X
  93. X    XClearWindow(W_Display, win->window);
  94. X    count=0;
  95. X    list = (struct stringList *) win->data;
  96. X    while (list != NULL) `123
  97. X`009list=list->next;
  98. X`009count++;
  99. X    `125
  100. X    list = (struct stringList *) win->data;
  101. X    while (count > win->height) `123
  102. X`009list=list->next;
  103. X`009count--;
  104. X    `125
  105. X    y=(win->height-count)*W_Textheight+fonts`0911`093.baseline;
  106. X    if (count==0) return;
  107. X    while (list != NULL) `123
  108. X`009XDrawImageString(W_Display, win->window,`032
  109. X`009    colortable`091list->color`093.contexts`0911`093,
  110. X`009    WIN_EDGE, MENU_PAD+y, list->string, strlen(list->string));
  111. X`009list=list->next;
  112. X`009y=y+W_Textheight;
  113. X    `125
  114. X`125
  115. X
  116. XresizeScrolling(win, width, height)
  117. Xstruct window *win;
  118. Xint width, height;
  119. X`123
  120. X    win->height=(height - MENU_PAD*2)/W_Textheight;
  121. X    win->width=(width - WIN_EDGE*2)/W_Textwidth;
  122. X    XResizeWindow(W_Display, win->window, win->width*W_Textwidth+WIN_EDGE*2,
  123. X`009win->height*W_Textheight+MENU_PAD*2);
  124. X`125
  125. X
  126. XW_Window W_MakeMenu(name,x,y,width,height,parent,border)
  127. Xchar *name;
  128. Xint x,y,width,height;
  129. XW_Window parent;
  130. Xint border;
  131. X`123
  132. X    struct window *newwin;
  133. X    struct menuItem *items;
  134. X    Window wparent;
  135. X    int i;
  136. X    XSetWindowAttributes attrs;
  137. X
  138. X#ifdef DEBUG
  139. X    printf("New window...\n");
  140. X#endif
  141. X    checkGeometry(name, &x, &y, &width, &height);
  142. X    checkParent(name, &parent);
  143. X    wparent=W_Void2Window(parent)->window;
  144. X    attrs.override_redirect=False;
  145. X    attrs.border_pixel=colortable`091W_White`093.pixelValue;
  146. X    attrs.event_mask=KeyPressMask`124ButtonPressMask`124ExposureMask;
  147. X    attrs.background_pixel=colortable`091W_Black`093.pixelValue;
  148. X    attrs.do_not_propagate_mask=KeyPressMask`124ButtonPressMask`124ExposureM
  149. Vask;
  150. X    newwin=newWindow(
  151. X`009XCreateWindow(W_Display, wparent, x, y,
  152. X`009    width*W_Textwidth+WIN_EDGE*2,
  153. X`009    height*(W_Textheight+MENU_PAD*2)+(height-1)*MENU_BAR, border,
  154. X`009    CopyFromParent, InputOutput, CopyFromParent,
  155. X`009    CWBackPixel`124CWEventMask`124
  156. X`009    CWOverrideRedirect`124CWBorderPixel,`032
  157. X`009    &attrs),
  158. X        WIN_MENU);
  159. X    XSetClassHint(W_Display, newwin->window, &class_hint);
  160. X    XSetWMHints(W_Display, newwin->window, &wm_hint);
  161. X    newwin->name=strdup(name);
  162. X    items=(struct menuItem *) malloc(height*sizeof(struct menuItem));
  163. X    for (i=0; i<height; i++) `123
  164. X`009items`091i`093.string=NULL;
  165. X`009items`091i`093.color=W_White;
  166. X    `125
  167. X    newwin->data=(char *) items;
  168. X    newwin->width=width;
  169. X    newwin->height=height;
  170. X    if (checkMapped(name)) W_MapWindow(W_Window2Void(newwin));
  171. X#ifdef DEBUG
  172. X    printf("New menu window %d, child of %d\n", newwin, parent);
  173. X#endif
  174. X    return(W_Window2Void(newwin));
  175. X`125
  176. X
  177. XredrawMenu(win)
  178. Xstruct window *win;
  179. X`123
  180. X    int count;
  181. X
  182. X    for (count=1; count<win->height; count++) `123
  183. X`009XFillRectangle(W_Display, win->window,`032
  184. X`009    colortable`091W_White`093.contexts`0910`093,`032
  185. X`009    0, count*(W_Textheight+MENU_PAD*2)+(count-1)*MENU_BAR,
  186. X`009    win->width*W_Textwidth+WIN_EDGE*2, MENU_BAR);
  187. X    `125
  188. X    for (count=0; count<win->height; count++) `123
  189. X`009redrawMenuItem(win,count);
  190. X    `125
  191. X`125
  192. X
  193. XredrawMenuItem(win, n)
  194. Xstruct window *win;
  195. Xint n;
  196. X`123
  197. X    struct menuItem *items;
  198. X
  199. X    items=(struct menuItem *) win->data;
  200. X    XFillRectangle(W_Display, win->window,
  201. X`009colortable`091W_Black`093.contexts`0910`093,
  202. X`009WIN_EDGE, n*(W_Textheight+MENU_PAD*2+MENU_BAR)+MENU_PAD,
  203. X`009win->width*W_Textwidth,W_Textheight);
  204. X    if (items`091n`093.string) `123
  205. X`009XDrawImageString(W_Display, win->window,`032
  206. X`009    colortable`091items`091n`093.color`093.contexts`0911`093,
  207. X`009    WIN_EDGE, `009
  208. X`009    n*(W_Textheight+MENU_PAD*2+MENU_BAR)+MENU_PAD+fonts`0911`093.baselin
  209. Ve,
  210. X`009    items`091n`093.string, strlen(items`091n`093.string));
  211. X    `125
  212. X`125
  213. X
  214. XchangeMenuItem(win, n, str, len, color)
  215. Xstruct window *win;
  216. Xint n;
  217. Xchar *str;
  218. Xint len;
  219. XW_Color color;
  220. X`123
  221. X    struct menuItem *items;
  222. X    char *news;
  223. X
  224. X    items=(struct menuItem *) win->data;
  225. X    if (items`091n`093.string) `123
  226. X`009free(items`091n`093.string);
  227. X    `125
  228. X    news=malloc(len+1);
  229. X    strncpy(news,str,len);
  230. X    news`091len`093=0;
  231. X    items`091n`093.string=news;
  232. X    items`091n`093.color=color;
  233. X    redrawMenuItem(win, n);
  234. X`125
  235. X
  236. Xvoid W_DefineCursor(window,width,height,bits,mask,xhot,yhot)
  237. XW_Window window;
  238. Xint width, height, xhot, yhot;
  239. Xunsigned char *bits, *mask;
  240. X`123
  241. X    static unsigned char *oldbits=NULL;
  242. X    static Cursor curs;
  243. X    Pixmap cursbits;
  244. X    Pixmap cursmask;
  245. X    short *curdata;
  246. X    short *maskdata;
  247. X    struct window *win;
  248. X    XColor whiteCol, blackCol;
  249. X
  250. X#ifdef DEBUG
  251. X    printf("Defining cursor for %d\n", window);
  252. X#endif
  253. X    win=W_Void2Window(window);
  254. X    whiteCol.pixel=colortable`091W_White`093.pixelValue;
  255. X    XQueryColor(W_Display, W_Colormap, &whiteCol);
  256. X    blackCol.pixel=colortable`091W_Black`093.pixelValue;
  257. X    XQueryColor(W_Display, W_Colormap, &blackCol);
  258. X    if (!oldbits `124`124 oldbits!=bits) `123
  259. X`009cursbits=XCreateBitmapFromData(W_Display, win->window,
  260. X`009    bits, width, height);
  261. X`009cursmask=XCreateBitmapFromData(W_Display, win->window,
  262. X`009    mask, width, height);
  263. X`009oldbits=bits;
  264. X`009curs=XCreatePixmapCursor(W_Display, cursbits, cursmask,`032
  265. X`009    &whiteCol, &blackCol, xhot, yhot);
  266. X`009XFreePixmap(W_Display, cursbits);
  267. X`009XFreePixmap(W_Display, cursmask);
  268. X    `125
  269. X    XDefineCursor(W_Display, win->window, curs);
  270. X`125
  271. X
  272. Xvoid W_Beep()
  273. X`123
  274. X    XBell(W_Display, 0);
  275. X`125
  276. X
  277. Xint W_WindowWidth(window)
  278. XW_Window window;
  279. X`123
  280. X    return(W_Void2Window(window)->width);
  281. X`125
  282. X
  283. Xint W_WindowHeight(window)
  284. XW_Window window;
  285. X`123
  286. X    return(W_Void2Window(window)->height);
  287. X`125
  288. X
  289. Xint W_Socket()
  290. X`123
  291. X    return(ConnectionNumber(W_Display));
  292. X`125
  293. X
  294. Xvoid W_DestroyWindow(window)
  295. XW_Window window;
  296. X`123
  297. X    struct window *win;
  298. X
  299. X#ifdef DEBUG
  300. X    printf("Destroying %d\n", window);
  301. X#endif
  302. X    win=W_Void2Window(window);
  303. X    deleteWindow(win);
  304. X    XDestroyWindow(W_Display, win->window);
  305. X    free((char *) win);
  306. X`125
  307. X
  308. XdeleteWindow(window)
  309. Xstruct window *window;
  310. X`123
  311. X    struct windowlist **rm;
  312. X    struct windowlist *temp;
  313. X
  314. X    rm= &hashtable`091hash(window->window)`093;
  315. X    while (*rm != NULL && (*rm)->window!=window) `123
  316. X`009rm= &((*rm)->next);
  317. X    `125
  318. X    if (*rm==NULL) `123
  319. X`009printf("Attempt to delete non-existent window!\n");
  320. X`009return;
  321. X    `125
  322. X    temp= *rm;
  323. X    *rm=temp->next;
  324. X    free((char *) temp);
  325. X`125
  326. X
  327. Xvoid W_SetIconWindow(main, icon)
  328. XW_Window main;
  329. XW_Window icon;
  330. X`123
  331. X    XWMHints hints;
  332. X
  333. X    hints.flags=IconWindowHint;
  334. X    hints.icon_window=W_Void2Window(icon)->window;
  335. X    XSetWMHints(W_Display, W_Void2Window(main)->window, &hints);
  336. X`125
  337. X
  338. XcheckGeometry(name, x, y, width, height)
  339. Xchar *name;
  340. Xint *x, *y, *width, *height;
  341. X`123
  342. X    char *adefault;
  343. X    char buf`091100`093;
  344. X    char *s;
  345. X
  346. X    sprintf(buf, "%s.geometry", name);
  347. X    adefault=getdefault(buf);
  348. X    if (adefault==NULL) return;
  349. X    /* geometry should be of the form 502x885+1+1, 502x885, or +1+1 */
  350. X    s=adefault;
  351. X    if (*s!='+') `123
  352. X`009while (*s!='x' && *s!=0) s++;
  353. X`009*width = atoi(adefault);
  354. X`009if (*s==0) return;
  355. X`009s++;
  356. X`009adefault=s;
  357. X`009while (*s!='+' && *s!=0) s++;
  358. X`009*height = atoi(adefault);
  359. X`009if (*s==0) return;
  360. X    `125
  361. X    s++;
  362. X    adefault=s;
  363. X    while (*s!='+' && *s!=0) s++;
  364. X    *x = atoi(adefault);
  365. X    if (*s==0) return;
  366. X    s++;
  367. X    adefault=s;
  368. X    *y = atoi(adefault);
  369. X    return;
  370. X`125
  371. X
  372. XcheckParent(name, parent)
  373. Xchar *name;
  374. XW_Window *parent;
  375. X`123
  376. X    char *adefault;
  377. X    char buf`091100`093;
  378. X    int i;
  379. X    struct windowlist *windows;
  380. X
  381. X    sprintf(buf, "%s.parent", name);
  382. X    adefault=getdefault(buf);
  383. X    if (adefault==NULL) return;
  384. X    /* parent must be name of other window or "root" */
  385. X    if (strcmpi(adefault, "root")==0) `123
  386. X`009*parent=W_Window2Void(&myroot);
  387. X`009return;
  388. X    `125
  389. X    for (i=0; i<HASHSIZE; i++) `123
  390. X`009windows=hashtable`091i`093;
  391. X`009while (windows != NULL) `123
  392. X`009    if (strcmpi(adefault, windows->window->name)==0) `123
  393. X`009`009*parent=W_Window2Void(windows->window);
  394. X`009`009return;
  395. X`009    `125
  396. X`009    windows=windows->next;
  397. X`009`125
  398. X    `125
  399. X`125
  400. X
  401. XcheckMapped(name)
  402. Xchar *name;
  403. X`123
  404. X    char *adefault;
  405. X    char buf`091100`093;
  406. X
  407. X    sprintf(buf, "%s.mapped", name);
  408. X    return(booleanDefault(buf, 0));
  409. X`125
  410. $ CALL UNPACK X11WINDOW.C;1 1281524238
  411. $ EXIT
  412.