home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / games / volume14 / umoria4 / part17 < prev    next >
Internet Message Format  |  1992-08-31  |  59KB

  1. Path: uunet!zephyr.ens.tek.com!master!saab!billr
  2. From: billr@saab.CNA.TEK.COM (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v14i049:  umoria4 - single player dungeon simulation (ver. 5.5), Part17/39
  5. Message-ID: <3407@master.CNA.TEK.COM>
  6. Date: 20 Aug 92 18:05:32 GMT
  7. Sender: news@master.CNA.TEK.COM
  8. Lines: 2353
  9. Approved: billr@saab.CNA.TEK.COM
  10.  
  11. Submitted-by: grabiner@math.harvard.edu (David Grabiner)
  12. Posting-number: Volume 14, Issue 49
  13. Archive-name: umoria4/Part17
  14. Supersedes: umoria3: Volume 9, Issue 55-97; Volume 10, Issue 15-17
  15. Environment: Curses, Unix, Mac, MS-DOS, Atari-ST, Amiga, VMS
  16.  
  17.  
  18.  
  19. #! /bin/sh
  20. # This is a shell archive.  Remove anything before this line, then unpack
  21. # it by saving it into a file and typing "sh file".  To overwrite existing
  22. # files, type "sh file -c".  You can also feed this as standard input via
  23. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  24. # will see the following message at the end:
  25. #        "End of archive 17 (of 39)."
  26. # Contents:  mac/scrnmgr/ScrnMgr.c.2 mac/scrnmgr/ScrnMgr.doc
  27. #   util/scores/README
  28. # Wrapped by billr@saab on Thu Aug 20 09:11:30 1992
  29. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  30. if test -f 'mac/scrnmgr/ScrnMgr.c.2' -a "${1}" != "-c" ; then 
  31.   echo shar: Will not clobber existing file \"'mac/scrnmgr/ScrnMgr.c.2'\"
  32. else
  33. echo shar: Extracting \"'mac/scrnmgr/ScrnMgr.c.2'\" \(31691 characters\)
  34. sed "s/^X//" >'mac/scrnmgr/ScrnMgr.c.2' <<'END_OF_FILE'
  35. X                    }
  36. X                }
  37. X                else {
  38. X                    if (PtInRect(mouse, &charCell)) {
  39. X                        XSetScreenCharAttr(false, c, ar, h, v);
  40. X                        UpdateScreen();
  41. X                        reversed = true;
  42. X                    }
  43. X                }
  44. X            }
  45. X
  46. X            if (reversed) {
  47. X
  48. X                XSetScreenCharAttr(false, c, an, h, v);
  49. X                UpdateScreen();
  50. X                reversed = false;
  51. X
  52. X                PushQueue(0, modifiers, 0, h, v);
  53. X
  54. X            }
  55. X
  56. X        }
  57. X
  58. X    }
  59. X
  60. X    return;
  61. X}
  62. X
  63. Xstatic void DoContentClick(whichWindow, cursorLoc)
  64. XWindowPtr whichWindow;
  65. XPoint *cursorLoc;
  66. X
  67. X{
  68. X    short thePart;
  69. X    ControlHandle theControl;
  70. X    Point localCursor;
  71. X
  72. X    if (whichWindow == theScreen.window) {
  73. X        localCursor = *cursorLoc;
  74. X        GlobalToLocal(&localCursor);
  75. X        if (thePart = FindControl(localCursor, whichWindow, &theControl)) {
  76. X            if (theControl == theScreen.hScrollHandle)
  77. X                DoHScroll(&localCursor, thePart);
  78. X            else if (theControl == theScreen.vScrollHandle)
  79. X                DoVScroll(&localCursor, thePart);
  80. X        }
  81. X        else
  82. X            if (theScreen.mouseFlag) DoCharClick();
  83. X    }
  84. X
  85. X    return;
  86. X}
  87. X
  88. Xstatic void DoMouseDown(cursorLoc)
  89. XPoint *cursorLoc;
  90. X
  91. X{
  92. X    long part;
  93. X    WindowPtr whichWindow;
  94. X
  95. X    switch (part = FindWindow(*cursorLoc, &whichWindow)) {
  96. X
  97. X        case inMenuBar:        DoMenuItem(MenuSelect(*cursorLoc));
  98. X                            break;
  99. X
  100. X        case inDrag:        DoDrag(whichWindow, cursorLoc);
  101. X                            break;
  102. X
  103. X        case inGrow:        DoGrow(whichWindow, cursorLoc);
  104. X                            break;
  105. X
  106. X        case inSysWindow:    SystemClick(&theScreen.event, whichWindow);
  107. X                            break;
  108. X
  109. X        case inContent:        if (whichWindow != FrontWindow())
  110. X                                SelectWindow(whichWindow);
  111. X                            else
  112. X                                DoContentClick(whichWindow, cursorLoc);
  113. X                            break;
  114. X
  115. X        case inZoomIn:
  116. X        case inZoomOut:        if (whichWindow == theScreen.window)
  117. X                                if (TrackBox(whichWindow, *cursorLoc, part))
  118. X                                    DoZoom(whichWindow, part);
  119. X                            break;
  120. X
  121. X        case inGoAway:        if (whichWindow == theScreen.window)
  122. X                                if (TrackGoAway(whichWindow, *cursorLoc)) {
  123. X                                    if (theScreen.fileMenuProc != NULL)
  124. X                                        (*theScreen.fileMenuProc)(closeBoxItem);
  125. X                                    else
  126. X                                        DoFileMenu(closeBoxItem);
  127. X                                }
  128. X                            break;
  129. X
  130. X    }
  131. X
  132. X    return;
  133. X}
  134. X
  135. Xstatic void DoKeyDown(cmdFlag)
  136. Xint cmdFlag;
  137. X
  138. X{
  139. X    char keycode, modifiers, ascii;
  140. X    char upper;
  141. X
  142. X    if ( (theScreen.event.when > theScreen.keyFlush)        &&
  143. X            (theScreen.window == FrontWindow())        &&
  144. X            (((WindowPeek) theScreen.window)->visible) ) {
  145. X
  146. X        ObscureCursor();
  147. X
  148. X        keycode = (char) ((theScreen.event.message & keyCodeMask) >> 8);
  149. X
  150. X        modifiers = (char) ((theScreen.event.modifiers & 0xFF00) >> 8);
  151. X        modifiers &= ~maskModMouse;
  152. X
  153. X        ascii = (char) (theScreen.event.message & charCodeMask);
  154. X        if (theScreen.escMapFlag) {
  155. X            if (ascii == BACKQUOTE) ascii = ESC;
  156. X        }
  157. X        if (cmdFlag) {
  158. X            upper = ascii;
  159. X            if ( (upper >= 'a') && (upper <= 'z') )
  160. X                upper = 'A' + (upper - 'a');
  161. X            if ( (upper >= '@') && (upper <= '_') )
  162. X                ascii = upper - '@';
  163. X        }
  164. X
  165. X        PushQueue(keycode, modifiers, ascii, 0, 0);
  166. X
  167. X    }
  168. X
  169. X    return;
  170. X}
  171. X
  172. Xstatic void DoUpdate(whichWindow)
  173. XWindowPtr whichWindow;
  174. X
  175. X{
  176. X    if (whichWindow == theScreen.window) {
  177. X        UpdateScreen();
  178. X    }
  179. X
  180. X    return;
  181. X}
  182. X
  183. Xstatic void DoActivate(whichWindow, activated)
  184. XWindowPtr whichWindow;
  185. XBoolean activated;
  186. X
  187. X{
  188. X    MenuHandle menu;
  189. X
  190. X    menu = GetMHandle(theScreen.cmdKeyFlag ? editID1 : editID2);
  191. X
  192. X    if (whichWindow == theScreen.window) {
  193. X
  194. X        if (activated) {
  195. X            DisableItem(menu, undoItem);
  196. X            DisableItem(menu, cutItem);
  197. X            DisableItem(menu, copyItem);
  198. X            DisableItem(menu, pasteItem);
  199. X            DisableItem(menu, clearItem);
  200. X            ShowControl(theScreen.vScrollHandle);
  201. X            ShowControl(theScreen.hScrollHandle);
  202. X            DrawGrowIcon(whichWindow);
  203. X        }
  204. X        else {
  205. X            EnableItem(menu, undoItem);
  206. X            EnableItem(menu, cutItem);
  207. X            EnableItem(menu, copyItem);
  208. X            EnableItem(menu, pasteItem);
  209. X            EnableItem(menu, clearItem);
  210. X            HideControl(theScreen.vScrollHandle);
  211. X            HideControl(theScreen.hScrollHandle);
  212. X            DrawGrowIcon(whichWindow);
  213. X        }
  214. X    }
  215. X
  216. X    return;
  217. X}
  218. X
  219. Xstatic void InvalScreenRect(d, r)
  220. Xint d;
  221. XRect *r;
  222. X
  223. X{
  224. X    register long v;
  225. X    register short *left, *right;
  226. X    short rl, rt, rr, rb;
  227. X
  228. X    if (d) {
  229. X
  230. X        rl = r->left;
  231. X        rt = r->top;
  232. X        rr = r->right;
  233. X        rb = r->bottom;
  234. X
  235. X        left = *theScreen.updLeft + rt;
  236. X        right = *theScreen.updRight + rt;
  237. X
  238. X        for (v = rt; v < rb; v++, left++, right++) {
  239. X            if (rl < *left) *left = rl;
  240. X            if (rr > *right) *right = rr;
  241. X        }
  242. X
  243. X    }
  244. X
  245. X    else {
  246. X
  247. X        r->left *= theScreen.charPDims.h;
  248. X        r->right *= theScreen.charPDims.h;
  249. X        r->top *= theScreen.charPDims.v;
  250. X        r->bottom *= theScreen.charPDims.v;
  251. X
  252. X        SetOrigin(theScreen.origin.h, theScreen.origin.v);
  253. X        InvalRect(r);
  254. X        SetOrigin(0, 0);
  255. X
  256. X    }
  257. X
  258. X    return;
  259. X}
  260. X
  261. Xstatic void InvalCursor(d)
  262. Xint d;
  263. X
  264. X{
  265. X    Rect curs;
  266. X
  267. X    curs.left = curs.right = theScreen.cursor.h;
  268. X    curs.top = curs.bottom = theScreen.cursor.v;
  269. X    curs.right += 1;
  270. X    curs.bottom += 1;
  271. X
  272. X    if (d)
  273. X        InvalScreenRect(d, &curs);
  274. X
  275. X    else {
  276. X
  277. X        curs.left *= theScreen.charPDims.h;
  278. X        curs.right *= theScreen.charPDims.h;
  279. X        curs.top = curs.bottom = curs.bottom * theScreen.charPDims.v;
  280. X        curs.top -= theScreen.cursorLines;
  281. X
  282. X        SetOrigin(theScreen.origin.h, theScreen.origin.v);
  283. X        InvalRect(&curs);
  284. X        SetOrigin(0, 0);
  285. X
  286. X    }
  287. X
  288. X    return;
  289. X}
  290. X
  291. Xvoid XSetScreenChar(d, c, h, v)
  292. Xint d;
  293. Xchar c;
  294. Xlong h, v;
  295. X
  296. X{
  297. X    long loc;
  298. X    Rect area;
  299. X    Point pos;
  300. X
  301. X    pos.h = h;
  302. X    pos.v = v;
  303. X
  304. X    if (PtInRect(pos, &theScreen.scrnCRect)) {
  305. X
  306. X        loc = v * theScreen.scrnCDims.h + h;
  307. X        (*theScreen.chars)[loc] = c;
  308. X
  309. X        area.left = area.right = h;
  310. X        area.right += 1;
  311. X        area.top = area.bottom = v;
  312. X        area.bottom += 1;
  313. X
  314. X        InvalScreenRect(d, &area);
  315. X
  316. X    }
  317. X
  318. X    return;
  319. X}
  320. X
  321. Xvoid XSetScreenBuffer(d, c, row, bounds, h, v)
  322. Xint d;
  323. Xchar *c;
  324. Xlong row;
  325. XRect *bounds;
  326. Xlong h, v;
  327. X
  328. X{
  329. X    long i;
  330. X    long wid;
  331. X    long srcLoc, dstLoc;
  332. X    char *srcC, *dstC;
  333. X    Rect temp, area;
  334. X
  335. X    temp.right = temp.left = h;
  336. X    temp.right += bounds->right - bounds->left;
  337. X    temp.bottom = temp.top = v;
  338. X    temp.bottom += bounds->bottom - bounds->top;
  339. X
  340. X    if (SectRect(&temp, &theScreen.scrnCRect, &area)) {
  341. X
  342. X        srcLoc = (area.top + bounds->top - v) * row +
  343. X             (area.left + bounds->left - h);
  344. X        dstLoc = area.top * theScreen.scrnCDims.h + area.left;
  345. X
  346. X        srcC = c + srcLoc;
  347. X        dstC = *theScreen.chars + dstLoc;
  348. X
  349. X        wid = area.right - area.left;
  350. X
  351. X        if ( (wid == row) && (wid == theScreen.scrnCDims.h) ) {
  352. X            wid *= (area.bottom - area.top);
  353. X            memcpy(dstC, srcC, wid);
  354. X        }
  355. X
  356. X        else {
  357. X
  358. X            for (i = area.top; i < area.bottom; i++) {
  359. X                memcpy(dstC, srcC, wid);
  360. X                srcC += row;
  361. X                dstC += theScreen.scrnCDims.h;
  362. X            }
  363. X
  364. X        }
  365. X
  366. X        InvalScreenRect(d, &area);
  367. X
  368. X    }
  369. X
  370. X    return;
  371. X}
  372. X
  373. Xvoid XSetScreenString(d, s, h, v)
  374. Xint d;
  375. Xchar *s;
  376. Xlong h, v;
  377. X
  378. X{
  379. X    Rect bounds;
  380. X
  381. X    bounds.left = 0;
  382. X    bounds.right = strlen(s);
  383. X    bounds.top = 0;
  384. X    bounds.bottom = 1;
  385. X
  386. X    XSetScreenBuffer(d, s, bounds.right, &bounds, h, v);
  387. X
  388. X    return;
  389. X}
  390. X
  391. Xvoid XSetScreenCharAttr(d, c, a, h, v)
  392. Xint d;
  393. Xchar c;
  394. Xchar a;
  395. Xlong h, v;
  396. X
  397. X{
  398. X    long loc;
  399. X    Rect area;
  400. X    Point pos;
  401. X
  402. X    pos.h = h;
  403. X    pos.v = v;
  404. X
  405. X    if (PtInRect(pos, &theScreen.scrnCRect)) {
  406. X
  407. X        loc = v * theScreen.scrnCDims.h + h;
  408. X        (*theScreen.chars)[loc] = c;
  409. X        (*theScreen.attrs)[loc] = a;
  410. X
  411. X        area.left = area.right = h;
  412. X        area.right += 1;
  413. X        area.top = area.bottom = v;
  414. X        area.bottom += 1;
  415. X
  416. X        InvalScreenRect(d, &area);
  417. X
  418. X    }
  419. X
  420. X    return;
  421. X}
  422. X
  423. Xvoid XSetScreenBufferAttr(d, c, a, row, bounds, h, v)
  424. Xint d;
  425. Xchar *c;
  426. Xchar a;
  427. Xlong row;
  428. XRect *bounds;
  429. Xlong h, v;
  430. X
  431. X{
  432. X    long i;
  433. X    long wid;
  434. X    long srcLoc, dstLoc;
  435. X    char *srcC, *dstC;
  436. X    char *dstA;
  437. X    Rect temp, area;
  438. X
  439. X    temp.right = temp.left = h;
  440. X    temp.right += bounds->right - bounds->left;
  441. X    temp.bottom = temp.top = v;
  442. X    temp.bottom += bounds->bottom - bounds->top;
  443. X
  444. X    if (SectRect(&temp, &theScreen.scrnCRect, &area)) {
  445. X
  446. X        srcLoc = (area.top + bounds->top - v) * row +
  447. X             (area.left + bounds->left - h);
  448. X        dstLoc = area.top * theScreen.scrnCDims.h + area.left;
  449. X
  450. X        srcC = c + srcLoc;
  451. X        dstC = *theScreen.chars + dstLoc;
  452. X
  453. X        dstA = *theScreen.attrs + dstLoc;
  454. X
  455. X        wid = area.right - area.left;
  456. X
  457. X        if ( (wid == row) && (wid == theScreen.scrnCDims.h) ) {
  458. X            wid *= (area.bottom - area.top);
  459. X            memcpy(dstC, srcC, wid);
  460. X            memset(dstA, a, wid);
  461. X        }
  462. X
  463. X        else {
  464. X
  465. X            for (i = area.top; i < area.bottom; i++) {
  466. X                memcpy(dstC, srcC, wid);
  467. X                memset(dstA, a, wid);
  468. X                srcC += row;
  469. X                dstC += theScreen.scrnCDims.h;
  470. X                dstA += theScreen.scrnCDims.h;
  471. X            }
  472. X
  473. X        }
  474. X
  475. X        InvalScreenRect(d, &area);
  476. X
  477. X    }
  478. X
  479. X    return;
  480. X}
  481. X
  482. Xvoid XSetScreenStringAttr(d, s, a, h, v)
  483. Xint d;
  484. Xchar *s;
  485. Xchar a;
  486. Xlong h, v;
  487. X
  488. X{
  489. X    Rect bounds;
  490. X
  491. X    bounds.left = 0;
  492. X    bounds.right = strlen(s);
  493. X    bounds.top = 0;
  494. X    bounds.bottom = 1;
  495. X
  496. X    XSetScreenBufferAttr(d, s, a, bounds.right, &bounds, h, v);
  497. X
  498. X    return;
  499. X}
  500. X
  501. Xvoid XSetScreenImage(d, c, a, row, bounds, h, v)
  502. Xint d;
  503. Xchar *c;
  504. Xchar *a;
  505. Xlong row;
  506. XRect *bounds;
  507. Xlong h, v;
  508. X
  509. X{
  510. X    long i;
  511. X    long wid;
  512. X    long srcLoc, dstLoc;
  513. X    char *srcC, *dstC;
  514. X    char *srcA, *dstA;
  515. X    Rect temp, area;
  516. X
  517. X    temp.right = temp.left = h;
  518. X    temp.right += bounds->right - bounds->left;
  519. X    temp.bottom = temp.top = v;
  520. X    temp.bottom += bounds->bottom - bounds->top;
  521. X
  522. X    if (SectRect(&temp, &theScreen.scrnCRect, &area)) {
  523. X
  524. X        srcLoc = (area.top + bounds->top - v) * row +
  525. X             (area.left + bounds->left - h);
  526. X        dstLoc = area.top * theScreen.scrnCDims.h + area.left;
  527. X
  528. X        srcC = c + srcLoc;
  529. X        dstC = *theScreen.chars + dstLoc;
  530. X
  531. X        srcA = a + srcLoc;
  532. X        dstA = *theScreen.attrs + dstLoc;
  533. X
  534. X        wid = area.right - area.left;
  535. X
  536. X        if ( (wid == row) && (wid == theScreen.scrnCDims.h) ) {
  537. X            wid *= (area.bottom - area.top);
  538. X            memcpy(dstC, srcC, wid);
  539. X            memcpy(dstA, srcA, wid);
  540. X        }
  541. X
  542. X        else {
  543. X
  544. X            for (i = area.top; i < area.bottom; i++) {
  545. X                memcpy(dstC, srcC, wid);
  546. X                memcpy(dstA, srcA, wid);
  547. X                srcC += row;
  548. X                srcA += row;
  549. X                dstC += theScreen.scrnCDims.h;
  550. X                dstA += theScreen.scrnCDims.h;
  551. X            }
  552. X
  553. X        }
  554. X
  555. X        InvalScreenRect(d, &area);
  556. X
  557. X    }
  558. X
  559. X    return;
  560. X}
  561. X
  562. Xvoid XWriteScreenChar(d, c)
  563. Xint d;
  564. Xchar c;
  565. X
  566. X{
  567. X    InvalCursor(d);
  568. X
  569. X    XSetScreenChar(d, c, theScreen.cursor.h, theScreen.cursor.v);
  570. X    theScreen.cursor.h++;
  571. X
  572. X    InvalCursor(d);
  573. X
  574. X    return;
  575. X}
  576. X
  577. Xvoid XWriteScreenBuffer(d, c, row, bounds)
  578. Xint d;
  579. Xchar *c;
  580. Xlong row;
  581. XRect *bounds;
  582. X
  583. X{
  584. X    XSetScreenBuffer(d, c, row, bounds, theScreen.cursor.h,
  585. X             theScreen.cursor.v);
  586. X    theScreen.cursor.h += bounds->right - bounds->left;
  587. X    theScreen.cursor.v += bounds->bottom - bounds->top;
  588. X
  589. X    InvalCursor(d);
  590. X
  591. X    return;
  592. X}
  593. X
  594. Xvoid XWriteScreenString(d, s)
  595. Xint d;
  596. Xchar *s;
  597. X
  598. X{
  599. X    XSetScreenString(d, s, theScreen.cursor.h, theScreen.cursor.v);
  600. X    theScreen.cursor.h += strlen(s);
  601. X
  602. X    InvalCursor(d);
  603. X
  604. X    return;
  605. X}
  606. X
  607. Xvoid XWriteScreenCharAttr(d, c, a)
  608. Xint d;
  609. Xchar c;
  610. Xchar a;
  611. X
  612. X{
  613. X    XSetScreenCharAttr(d, c, a, theScreen.cursor.h, theScreen.cursor.v);
  614. X    theScreen.cursor.h++;
  615. X
  616. X    InvalCursor(d);
  617. X
  618. X    return;
  619. X}
  620. X
  621. Xvoid XWriteScreenBufferAttr(d, c, a, row, bounds)
  622. Xint d;
  623. Xchar *c;
  624. Xchar a;
  625. Xlong row;
  626. XRect *bounds;
  627. X
  628. X{
  629. X    XSetScreenBufferAttr(d, c, a, row, bounds, theScreen.cursor.h,
  630. X             theScreen.cursor.v);
  631. X    theScreen.cursor.h += bounds->right - bounds->left;
  632. X    theScreen.cursor.v += bounds->bottom - bounds->top;
  633. X
  634. X    InvalCursor(d);
  635. X
  636. X    return;
  637. X}
  638. X
  639. Xvoid XWriteScreenStringAttr(d, s, a)
  640. Xint d;
  641. Xchar *s;
  642. Xchar a;
  643. X
  644. X{
  645. X    XSetScreenStringAttr(d, s, a, theScreen.cursor.h, theScreen.cursor.v);
  646. X    theScreen.cursor.h += strlen(s);
  647. X
  648. X    InvalCursor(d);
  649. X
  650. X    return;
  651. X}
  652. X
  653. Xvoid XWriteScreenImage(d, c, a, row, bounds)
  654. Xint d;
  655. Xchar *c;
  656. Xchar *a;
  657. Xlong row;
  658. XRect *bounds;
  659. X
  660. X{
  661. X    XSetScreenImage(d, c, a, row, bounds, theScreen.cursor.h,
  662. X            theScreen.cursor.v);
  663. X    theScreen.cursor.h += bounds->right - bounds->left;
  664. X    theScreen.cursor.v += bounds->bottom - bounds->top;
  665. X
  666. X    InvalCursor(d);
  667. X
  668. X    return;
  669. X}
  670. X
  671. Xvoid XFillScreen(d, c, a, bounds)
  672. Xint d;
  673. Xchar c;
  674. Xchar a;
  675. XRect *bounds;
  676. X
  677. X{
  678. X    long i;
  679. X    long wid;
  680. X    long dstLoc;
  681. X    char *dstC;
  682. X    char *dstA;
  683. X    Rect area;
  684. X
  685. X    if (SectRect(bounds, &theScreen.scrnCRect, &area)) {
  686. X
  687. X        dstLoc = area.top * theScreen.scrnCDims.h + area.left;
  688. X
  689. X        dstC = *theScreen.chars + dstLoc;
  690. X
  691. X        dstA = *theScreen.attrs + dstLoc;
  692. X
  693. X        wid = area.right - area.left;
  694. X
  695. X        if (wid == theScreen.scrnCDims.h) {
  696. X            wid *= (area.bottom - area.top);
  697. X            memset(dstC, c, wid);
  698. X            memset(dstA, a, wid);
  699. X        }
  700. X
  701. X        else {
  702. X
  703. X            for (i = area.top; i < area.bottom; i++) {
  704. X                memset(dstC, c, wid);
  705. X                memset(dstA, a, wid);
  706. X                dstC += theScreen.scrnCDims.h;
  707. X                dstA += theScreen.scrnCDims.h;
  708. X            }
  709. X
  710. X        }
  711. X
  712. X        InvalScreenRect(d, &area);
  713. X
  714. X    }
  715. X
  716. X    return;
  717. X}
  718. X
  719. Xvoid XEraseScreen(d, bounds)
  720. Xint d;
  721. XRect *bounds;
  722. X
  723. X{
  724. X    XFillScreen(d, ' ', attrNormal, bounds);
  725. X    return;
  726. X}
  727. X
  728. Xstatic void ScrollScreenPositive(area, offset, factor)
  729. XRect *area;
  730. Xlong offset;
  731. Xshort factor;
  732. X
  733. X{
  734. X    register short i, j;
  735. X    short loc;        /* Index of initial destination.  */
  736. X    short nxt;        /* Amount to skip going from one row to the next.  */
  737. X    register char *srcc, *dstc;
  738. X    register char *srca, *dsta;
  739. X
  740. X    loc = (area->bottom - 1) * theScreen.scrnCDims.h + area->right - 1;
  741. X
  742. X    dstc = *theScreen.chars + loc;
  743. X    srcc = dstc - offset * factor;
  744. X
  745. X    dsta = *theScreen.attrs + loc;
  746. X    srca = dsta - offset * factor;
  747. X
  748. X    nxt = theScreen.scrnCDims.h - (area->right - area->left);
  749. X
  750. X    for (j = area->bottom; j > area->top; j--) {
  751. X        for (i = area->right; i > area->left; i--) {
  752. X            *dstc-- = *srcc--;
  753. X            *dsta-- = *srca--;
  754. X        }
  755. X        srcc -= nxt;
  756. X        dstc -= nxt;
  757. X        srca -= nxt;
  758. X        dsta -= nxt;
  759. X    }
  760. X
  761. X    return;
  762. X}
  763. X
  764. Xstatic void ScrollScreenNegative(area, offset, factor)
  765. XRect *area;
  766. Xlong offset;
  767. Xshort factor;
  768. X
  769. X{
  770. X    register short i, j;
  771. X    short loc;
  772. X    short nxt;
  773. X    register char *srcc, *dstc;
  774. X    register char *srca, *dsta;
  775. X
  776. X    loc = area->top * theScreen.scrnCDims.h + area->left;
  777. X
  778. X    dstc = *theScreen.chars + loc;
  779. X    srcc = dstc - offset * factor;    /* Offset is negative!  */
  780. X
  781. X    dsta = *theScreen.attrs + loc;
  782. X    srca = dsta - offset * factor;
  783. X
  784. X    nxt = theScreen.scrnCDims.h - (area->right - area->left);
  785. X
  786. X    for (j = area->top; j < area->bottom; j++) {
  787. X        for (i = area->left; i < area->right; i++) {
  788. X            *dstc++ = *srcc++;
  789. X            *dsta++ = *srca++;
  790. X        }
  791. X        srcc += nxt;
  792. X        dstc += nxt;
  793. X        srca += nxt;
  794. X        dsta += nxt;
  795. X    }
  796. X
  797. X    return;
  798. X}
  799. X
  800. Xvoid XScrollScreen(d, dh, dv, bounds, attr)
  801. Xint d;
  802. Xlong dh, dv;
  803. XRect *bounds;
  804. Xchar attr;
  805. X
  806. X{
  807. X    long wid, dep;
  808. X    Rect area, clear;
  809. X
  810. X    if (!dh && !dv) return;
  811. X
  812. X    if (SectRect(bounds, &theScreen.scrnCRect, &area)) {
  813. X
  814. X        wid = area.right - area.left;
  815. X        dep = area.bottom - area.top;
  816. X
  817. X        if ( (ABS(dh) >= wid) || (ABS(dv) >= dep) )
  818. X
  819. X            XFillScreen(d, ' ', attr, &area);
  820. X
  821. X        else {
  822. X
  823. X            if (dv > 0) {
  824. X                clear = area;
  825. X                clear.bottom = area.top += dv;
  826. X                ScrollScreenPositive(&area, dv, (short)theScreen.scrnCDims.h);
  827. X                XFillScreen(d, ' ', attr, &clear);
  828. X            }
  829. X
  830. X            else if (dv < 0) {
  831. X                clear = area;
  832. X                clear.top = area.bottom += dv;
  833. X                ScrollScreenNegative(&area, dv, (short)theScreen.scrnCDims.h);
  834. X                XFillScreen(d, ' ', attr, &clear);
  835. X            }
  836. X
  837. X            if (dh > 0) {
  838. X                clear = area;
  839. X                clear.right = area.left += dh;
  840. X                ScrollScreenPositive(&area, dh, (short)1);
  841. X                XFillScreen(d, ' ', attr, &clear);
  842. X            }
  843. X
  844. X            else if (dh < 0) {
  845. X                clear = area;
  846. X                clear.left = area.right += dh;
  847. X                ScrollScreenNegative(&area, dh, (short)1);
  848. X                XFillScreen(d, ' ', attr, &clear);
  849. X            }
  850. X
  851. X            InvalScreenRect(d, &area);
  852. X
  853. X        }
  854. X
  855. X    }
  856. X
  857. X    return;
  858. X}
  859. X
  860. Xvoid GetScreenCharAttr(c, a, h, v)
  861. Xchar *c;
  862. Xchar *a;
  863. Xlong h, v;
  864. X
  865. X{
  866. X    long loc;
  867. X    Point pos;
  868. X
  869. X    pos.h = h;
  870. X    pos.v = v;
  871. X
  872. X    if (PtInRect(pos, &theScreen.scrnCRect)) {
  873. X
  874. X        loc = v * theScreen.scrnCDims.h + h;
  875. X        *c = (*theScreen.chars)[loc];
  876. X        *a = (*theScreen.attrs)[loc];
  877. X
  878. X    }
  879. X
  880. X    return;
  881. X}
  882. X
  883. Xvoid GetScreenImage(c, a, row, bounds, h, v)
  884. Xchar *c;
  885. Xchar *a;
  886. Xlong row;
  887. XRect *bounds;
  888. Xlong h, v;
  889. X
  890. X{
  891. X    long i;
  892. X    long wid;
  893. X    long srcLoc, dstLoc;
  894. X    char *srcC, *dstC;
  895. X    char *srcA, *dstA;
  896. X    Rect temp, area;
  897. X
  898. X    temp.right = temp.left = h;
  899. X    temp.right += bounds->right - bounds->left;
  900. X    temp.bottom = temp.top = v;
  901. X    temp.bottom += bounds->bottom - bounds->top;
  902. X
  903. X    if (SectRect(&temp, &theScreen.scrnCRect, &area)) {
  904. X
  905. X        dstLoc = (area.top + bounds->top - v) * row +
  906. X             (area.left + bounds->left - h);
  907. X        srcLoc = area.top * theScreen.scrnCDims.h + area.left;
  908. X
  909. X        dstC = c + dstLoc;
  910. X        srcC = *theScreen.chars + srcLoc;
  911. X
  912. X        dstA = a + dstLoc;
  913. X        srcA = *theScreen.attrs + srcLoc;
  914. X
  915. X        wid = area.right - area.left;
  916. X
  917. X        if ( (wid == row) && (wid == theScreen.scrnCDims.h) ) {
  918. X            wid *= (area.bottom - area.top);
  919. X            memcpy(dstC, srcC, wid);
  920. X            memcpy(dstA, srcA, wid);
  921. X        }
  922. X
  923. X        else {
  924. X
  925. X            for (i = area.top; i < area.bottom; i++) {
  926. X                memcpy(dstC, srcC, wid);
  927. X                memcpy(dstA, srcA, wid);
  928. X                dstC += row;
  929. X                dstA += row;
  930. X                srcC += theScreen.scrnCDims.h;
  931. X                srcA += theScreen.scrnCDims.h;
  932. X            }
  933. X
  934. X        }
  935. X
  936. X    }
  937. X
  938. X    return;
  939. X}
  940. X
  941. Xvoid XMoveScreenCursor(d, h, v)
  942. Xint d;
  943. Xlong h, v;
  944. X
  945. X{
  946. X    InvalCursor(d);
  947. X
  948. X    theScreen.cursor.h += h;
  949. X    theScreen.cursor.v += v;
  950. X
  951. X    InvalCursor(d);
  952. X
  953. X    return;
  954. X}
  955. X
  956. Xvoid XSetScreenCursor(d, h, v)
  957. Xint d;
  958. Xlong h, v;
  959. X
  960. X{
  961. X    InvalCursor(d);
  962. X
  963. X    theScreen.cursor.h = h;
  964. X    theScreen.cursor.v = v;
  965. X
  966. X    InvalCursor(d);
  967. X
  968. X    return;
  969. X}
  970. X
  971. Xvoid GetScreenCursor(h, v)
  972. Xlong *h, *v;
  973. X{
  974. X    *h = theScreen.cursor.h;
  975. X    *v = theScreen.cursor.v;
  976. X    return;
  977. X}
  978. X
  979. Xstatic long CheckCursorStatus()
  980. X
  981. X{
  982. X    long oldStatus;
  983. X    long changed;
  984. X
  985. X    oldStatus = theScreen.cursorStatus;
  986. X
  987. X    if (theScreen.cursorLevel <= 0)
  988. X        theScreen.cursorStatus = 0;
  989. X    else if (!theScreen.cursorBlink)
  990. X        theScreen.cursorStatus = 1;
  991. X    else if (theScreen.cursorChangeTick <= TickCount())
  992. X        theScreen.cursorStatus = !oldStatus;
  993. X
  994. X    changed = theScreen.cursorStatus != oldStatus;
  995. X
  996. X    if (changed) {
  997. X        theScreen.cursorChangeTick = TickCount() + theScreen.cursorBlink;
  998. X        InvalCursor(0);
  999. X    }
  1000. X
  1001. X    return(changed);
  1002. X}
  1003. X
  1004. Xstatic void InvalDelayed()
  1005. X
  1006. X{
  1007. X    long v;
  1008. X    short *left, *right;
  1009. X    Rect inval;
  1010. X
  1011. X    v = 0;
  1012. X    left = *theScreen.updLeft;
  1013. X    right = *theScreen.updRight;
  1014. X
  1015. X    while (v < theScreen.scrnCDims.v) {
  1016. X
  1017. X        if (!*right) {
  1018. X
  1019. X            v++;
  1020. X            left++;
  1021. X            right++;
  1022. X
  1023. X        }
  1024. X
  1025. X        else {
  1026. X
  1027. X            inval.top = v;
  1028. X            inval.left = *left;
  1029. X            inval.right = *right;
  1030. X
  1031. X            do {
  1032. X                v++;
  1033. X                *left++ = theScreen.scrnCDims.h;
  1034. X                *right++ = 0;
  1035. X            } while ( (v < theScreen.scrnCDims.v) &&
  1036. X                      (*left == inval.left)         &&
  1037. X                      (*right == inval.right)        );
  1038. X
  1039. X            inval.bottom = v;
  1040. X
  1041. X            InvalScreenRect(0, &inval);
  1042. X
  1043. X            left = *theScreen.updLeft + v;
  1044. X            right = *theScreen.updRight + v;
  1045. X
  1046. X        }
  1047. X
  1048. X    }
  1049. X
  1050. X    return;
  1051. X
  1052. X}
  1053. X
  1054. Xstatic void UpdateScreenLine(area, c, a, len)
  1055. XRect *area;
  1056. Xchar *c;
  1057. Xchar *a;
  1058. Xlong len;
  1059. X
  1060. X{
  1061. X    long count;
  1062. X    char attr;
  1063. X    char *last, *prev;
  1064. X    short face;
  1065. X    Rect temp;
  1066. X
  1067. X    temp = *area;
  1068. X
  1069. X    last = a + len;
  1070. X
  1071. X    while (a < last) {
  1072. X
  1073. X        attr = *a;
  1074. X
  1075. X        prev = a;
  1076. X        while ( (a < last) && (*a == attr) ) a++;
  1077. X        count = a - prev;
  1078. X
  1079. X        temp.right = temp.left + count * theScreen.charPDims.h;
  1080. X
  1081. X        face = normal;
  1082. X        if (attr & attrUnderlined) face |= underline;
  1083. X        if (attr & attrItalicized) face |= italic;
  1084. X        TextFace(face);
  1085. X
  1086. X        if (theScreen.colorFlag) {
  1087. X            ForeColor(colors[AttrFore(attr)]);
  1088. X            BackColor(colors[AttrBack(attr)]);
  1089. X        }
  1090. X        else {
  1091. X            ForeColor(
  1092. X                colors[
  1093. X                    (AttrFore(attr) == attrColorBack) ?
  1094. X                        theScreen.colorStdBack : theScreen.colorStdFore]);
  1095. X            BackColor(
  1096. X                colors[
  1097. X                    (AttrBack(attr) == attrColorBack) ?
  1098. X                        theScreen.colorStdBack : theScreen.colorStdFore]);
  1099. X        }
  1100. X
  1101. X        EraseRect(&temp);
  1102. X
  1103. X        DrawText(c, 0, count);
  1104. X
  1105. X        temp.left = temp.right;
  1106. X
  1107. X        c += count;
  1108. X
  1109. X    }
  1110. X
  1111. X    return;
  1112. X}
  1113. X
  1114. Xvoid UpdateScreen()
  1115. X
  1116. X{
  1117. X    long j;
  1118. X    long top, dep, left, wid;
  1119. X    Rect clear, area, curs;
  1120. X    RgnHandle vis;
  1121. X    char *c, *a;
  1122. X    long cursorLoc;
  1123. X
  1124. X    InvalDelayed();
  1125. X
  1126. X    BeginUpdate(theScreen.window);
  1127. X
  1128. X    SetOrigin(theScreen.origin.h, theScreen.origin.v);
  1129. X
  1130. X    ClipRect(&theScreen.picLRect);
  1131. X
  1132. X    if (!theScreen.colorFlag)
  1133. X        BackColor(colors[theScreen.colorStdBack]);
  1134. X
  1135. X    if (theScreen.picLRect.top < theScreen.scrnLRect.top) {
  1136. X        clear = theScreen.picLRect;
  1137. X        clear.bottom = theScreen.scrnLRect.top;
  1138. X        EraseRect(&clear);
  1139. X    }
  1140. X
  1141. X    if (theScreen.picLRect.left < theScreen.scrnLRect.left) {
  1142. X        clear = theScreen.picLRect;
  1143. X        clear.right = theScreen.scrnLRect.left;
  1144. X        EraseRect(&clear);
  1145. X    }
  1146. X
  1147. X    if (theScreen.picLRect.right > theScreen.scrnLRect.right) {
  1148. X        clear = theScreen.picLRect;
  1149. X        clear.left = theScreen.scrnLRect.right;
  1150. X        EraseRect(&clear);
  1151. X    }
  1152. X
  1153. X    if (theScreen.picLRect.bottom > theScreen.scrnLRect.bottom) {
  1154. X        clear = theScreen.picLRect;
  1155. X        clear.top = theScreen.scrnLRect.bottom;
  1156. X        EraseRect(&clear);
  1157. X    }
  1158. X
  1159. X    ClipRect(&theScreen.drawLRect);
  1160. X
  1161. X    vis = theScreen.window->visRgn;
  1162. X
  1163. X    top = theScreen.drawXCRect.top;
  1164. X    dep = theScreen.drawXCRect.bottom - top;
  1165. X
  1166. X    left = theScreen.drawXCRect.left;
  1167. X    wid = theScreen.drawXCRect.right - left;
  1168. X
  1169. X    HLock((Handle) theScreen.chars);
  1170. X    HLock((Handle) theScreen.attrs);
  1171. X
  1172. X    c = *theScreen.chars + top * theScreen.scrnCDims.h + left;
  1173. X    a = *theScreen.attrs + top * theScreen.scrnCDims.h + left;
  1174. X
  1175. X    area = theScreen.drawXLRect;
  1176. X    area.bottom = area.top + theScreen.charPDims.v;
  1177. X
  1178. X    for (j = 0; j < dep; j++) {
  1179. X
  1180. X        if (RectInRgn(&area, vis)) {
  1181. X            MoveTo(area.left, area.top + theScreen.info.ascent);
  1182. X            UpdateScreenLine(&area, c, a, wid);
  1183. X        }
  1184. X
  1185. X        area.top = area.bottom;
  1186. X        area.bottom += theScreen.charPDims.v;
  1187. X
  1188. X        c += theScreen.scrnCDims.h;
  1189. X        a += theScreen.scrnCDims.h;
  1190. X
  1191. X    }
  1192. X
  1193. X    HUnlock((Handle) theScreen.chars);
  1194. X    HUnlock((Handle) theScreen.attrs);
  1195. X
  1196. X    if (theScreen.cursorStatus) {
  1197. X        curs.left = curs.right = theScreen.cursor.h * theScreen.charPDims.h;
  1198. X        curs.right += theScreen.charPDims.h;
  1199. X        curs.bottom = curs.top = (theScreen.cursor.v + 1) * theScreen.charPDims.v;
  1200. X        if (theScreen.cursorLines <= theScreen.charPDims.v)
  1201. X            curs.top -= theScreen.cursorLines;
  1202. X        else
  1203. X            curs.top -= theScreen.charPDims.v;
  1204. X        if (theScreen.colorFlag)
  1205. X            BackColor(colors[theScreen.cursorColor]);
  1206. X        else {
  1207. X            cursorLoc = theScreen.cursor.v * theScreen.scrnCDims.h
  1208. X              + theScreen.cursor.h;
  1209. X            BackColor(
  1210. X                colors[
  1211. X                    (AttrFore((*theScreen.attrs)[cursorLoc]) == attrColorBack) ?
  1212. X                        theScreen.colorStdBack : theScreen.colorStdFore]);
  1213. X        }
  1214. X        EraseRect(&curs);
  1215. X    }
  1216. X
  1217. X    SetOrigin(0, 0);
  1218. X
  1219. X    TextFace(normal);
  1220. X
  1221. X    ForeColor(blackColor);
  1222. X    BackColor(whiteColor);
  1223. X
  1224. X    MoveTo(0, 0);
  1225. X
  1226. X    ClipRect(&theScreen.window->portRect);
  1227. X
  1228. X    UpdtControl(theScreen.window, theScreen.window->visRgn);
  1229. X    DrawGrowIcon(theScreen.window);
  1230. X
  1231. X    EndUpdate(theScreen.window);
  1232. X
  1233. X    return;
  1234. X}
  1235. X
  1236. Xvoid IdleScreenMgr()
  1237. X
  1238. X{
  1239. X    long more;
  1240. X    short mask;
  1241. X
  1242. X    do {
  1243. X
  1244. X        mask = everyEvent;
  1245. X        if (theScreen.waitFlag) {
  1246. X            mask -= mDownMask;
  1247. X            mask -= keyDownMask;
  1248. X            mask -= autoKeyMask;
  1249. X        }
  1250. X
  1251. X        if ( (!theScreen.backgrounding) && (theScreen.window == FrontWindow()) )
  1252. X            CheckCursorStatus();
  1253. X
  1254. X        if (theScreen.wneImplemented) {
  1255. X            more = WaitNextEvent(mask, &theScreen.event, 0, NULL);
  1256. X        }
  1257. X        else {
  1258. X            SystemTask();
  1259. X            more = GetNextEvent(mask, &theScreen.event);
  1260. X        }
  1261. X
  1262. X        if (more)
  1263. X            switch (theScreen.event.what) {
  1264. X
  1265. X                case mouseDown:        DoMouseDown(&theScreen.event.where);
  1266. X                                    break;
  1267. X
  1268. X                case autoKey:
  1269. X                case keyDown:        if (theScreen.event.modifiers & cmdKey) {
  1270. X                                        if (theScreen.cmdKeyFlag) {
  1271. X                                            if (theScreen.event.what != autoKey)
  1272. X                                                DoMenuItem(MenuKey(theScreen.event.message & charCodeMask));
  1273. X                                        }
  1274. X                                        else
  1275. X                                            DoKeyDown(true);
  1276. X                                    }
  1277. X                                    else
  1278. X                                        DoKeyDown(false);
  1279. X                                    break;
  1280. X
  1281. X                case updateEvt:        DoUpdate((WindowPtr) theScreen.event.message);
  1282. X                                    break;
  1283. X
  1284. X                case activateEvt:    DoActivate((WindowPtr) theScreen.event.message,
  1285. X                                               theScreen.event.modifiers & activeFlag);
  1286. X                                    break;
  1287. X
  1288. X                case osEvent:        if ((theScreen.event.message >> 24)
  1289. X                                == suspendResumeMessage) {
  1290. X                                        if (theScreen.event.message & resumeMask) {
  1291. X                                            theScreen.backgrounding = false;
  1292. X                                            DoActivate((WindowPtr) FrontWindow(), true);
  1293. X                                        }
  1294. X                                        else {
  1295. X                                            theScreen.backgrounding = true;
  1296. X                                            DoActivate((WindowPtr) FrontWindow(), false);
  1297. X                                        }
  1298. X                                    }
  1299. X
  1300. X            }
  1301. X
  1302. X    } while (more);
  1303. X
  1304. X    return;
  1305. X}
  1306. X
  1307. Xvoid FlushScreenKeys()
  1308. X
  1309. X{
  1310. X    theScreen.keyFlush = theScreen.mouseFlush = TickCount();
  1311. X    FlushQueue();
  1312. X    return;
  1313. X}
  1314. X
  1315. Xlong CountScreenKeys()
  1316. X
  1317. X{
  1318. X    return(LenQueue());
  1319. X}
  1320. X
  1321. Xint GetScreenKeys(keycode, modifiers, ascii, h, v)
  1322. Xchar *keycode;
  1323. Xchar *modifiers;
  1324. Xchar *ascii;
  1325. Xshort *h;
  1326. Xshort *v;
  1327. X
  1328. X{
  1329. X    short flag;
  1330. X    short th, tv;
  1331. X
  1332. X    if (flag = PopQueue(keycode, modifiers, ascii, &th, &tv)) {
  1333. X        if (h != NULL) *h = th;
  1334. X        if (v != NULL) *v = tv;
  1335. X    }
  1336. X
  1337. X    return(flag);
  1338. X}
  1339. X
  1340. Xvoid EnableScreenMouse(flag)
  1341. Xlong flag;
  1342. X
  1343. X{
  1344. X    if ( (flag) && (!theScreen.mouseFlag) ) theScreen.mouseFlush = TickCount();
  1345. X    theScreen.mouseFlag = flag;
  1346. X    return;
  1347. X}
  1348. X
  1349. Xvoid ClipScreenMouse(area)
  1350. XRect *area;
  1351. X
  1352. X{
  1353. X    theScreen.mouseLRect = theScreen.mouseCRect = *area;
  1354. X    theScreen.mouseLRect.left *= theScreen.charPDims.h;
  1355. X    theScreen.mouseLRect.top *= theScreen.charPDims.v;
  1356. X    theScreen.mouseLRect.right *= theScreen.charPDims.h;
  1357. X    theScreen.mouseLRect.bottom *= theScreen.charPDims.v;
  1358. X
  1359. X    return;
  1360. X}
  1361. X
  1362. Xvoid DefineScreenCursor(color, lines, blinkRate)
  1363. Xlong color;
  1364. Xlong lines;
  1365. Xlong blinkRate;
  1366. X
  1367. X{
  1368. X    theScreen.cursorColor = color;
  1369. X    theScreen.cursorLines = lines;
  1370. X    theScreen.cursorBlink = blinkRate;
  1371. X
  1372. X    InvalCursor(0);
  1373. X
  1374. X    return;
  1375. X}
  1376. X
  1377. Xvoid HideScreenCursor()
  1378. X
  1379. X{
  1380. X    theScreen.cursorLevel--;
  1381. X    CheckCursorStatus();
  1382. X    return;
  1383. X}
  1384. X
  1385. Xvoid ShowScreenCursor()
  1386. X
  1387. X{
  1388. X    theScreen.cursorLevel++;
  1389. X    CheckCursorStatus();
  1390. X    return;
  1391. X}
  1392. X
  1393. Xvoid SetScreenAboutProc(procPtr)
  1394. Xvoid (*procPtr)();
  1395. X
  1396. X{
  1397. X    theScreen.aboutProc = procPtr;
  1398. X    return;
  1399. X}
  1400. X
  1401. Xvoid SetScreenQuitProc(procPtr, flag)
  1402. Xvoid (*procPtr)();
  1403. Xlong flag;
  1404. X
  1405. X{
  1406. X    theScreen.quitProc = procPtr;
  1407. X    theScreen.quitReturns = flag;
  1408. X    return;
  1409. X}
  1410. X
  1411. Xlong YesOrNo(text)
  1412. Xchar *text;
  1413. X
  1414. X{
  1415. X    DialogPtr theDialog;
  1416. X    short itemHit;
  1417. X    short itsType;
  1418. X    Handle itsHandle;
  1419. X    Rect itsRect;
  1420. X    Str255 ptext;
  1421. X    long h, v;
  1422. X
  1423. X    theDialog = GetNewDialog(yesOrNoDlgID, nil, (WindowPtr) -1);
  1424. X
  1425. X    CenterScreenDLOG(yesOrNoDlgID, fixHalf, fixThird, &h, &v);
  1426. X    MoveWindow((WindowPtr) theDialog, (short) h, (short) v, false);
  1427. X
  1428. X    GetDItem(theDialog, ok, &itsType, &itsHandle, &itsRect);
  1429. X    InsetRect(&itsRect, -4, -4);
  1430. X
  1431. X    SetDItem(theDialog, yesOrNoDfltBorder, userItem,
  1432. X         (Handle) DrawDefaultBorder, &itsRect);
  1433. X
  1434. X    if (text != NULL) {
  1435. X        strncpy((char *)ptext, text, 255);
  1436. X        ptext[255] = '\0';
  1437. X        c2pstr((char *)ptext);
  1438. X        GetDItem(theDialog, yesOrNoText, &itsType, &itsHandle, &itsRect);
  1439. X        SetIText(itsHandle, ptext);
  1440. X    }
  1441. X
  1442. X    ShowWindow((WindowPtr) theDialog);
  1443. X
  1444. X    do {
  1445. X        ModalDialog(nil, &itemHit);
  1446. X    } while ( (itemHit != ok) && (itemHit != cancel) );
  1447. X
  1448. X    DisposDialog(theDialog);
  1449. X
  1450. X    return(itemHit == ok);
  1451. X}
  1452. X
  1453. Xvoid ShowScreen(visible)
  1454. Xlong visible;
  1455. X
  1456. X{
  1457. X    if (visible)
  1458. X        ShowWindow(theScreen.window);
  1459. X    else
  1460. X        HideWindow(theScreen.window);
  1461. X
  1462. X    return;
  1463. X}
  1464. X
  1465. Xvoid GetScreenBounds(bounds)
  1466. XRect *bounds;
  1467. X
  1468. X{
  1469. X
  1470. X#ifdef THINK_C
  1471. X
  1472. X    *bounds = screenBits.bounds;
  1473. X    bounds->top += GetMBarHeight();
  1474. X
  1475. X#else            /* I think we can live without this. -- BS  */
  1476. X
  1477. X    Point mouse;
  1478. X    GDHandle gdh;
  1479. X
  1480. X    if (!theScreen.env.hasColorQD) {
  1481. X        *bounds = qd.screenBits.bounds;
  1482. X        bounds->top += GetMBarHeight();
  1483. X    }
  1484. X
  1485. X    else {
  1486. X
  1487. X        *bounds = (*GetMainDevice())->gdRect;
  1488. X
  1489. X        GetMouse(&mouse);
  1490. X        LocalToGlobal(&mouse);
  1491. X
  1492. X        gdh = GetDeviceList();
  1493. X
  1494. X        while (gdh != NULL) {
  1495. X
  1496. X            if (PtInRect(mouse, &(*gdh)->gdRect)) {
  1497. X                *bounds = (*gdh)->gdRect;
  1498. X                if (gdh == GetMainDevice()) bounds->top += GetMBarHeight();
  1499. X                gdh = NULL;
  1500. X            }
  1501. X
  1502. X            else
  1503. X                gdh = GetNextDevice(gdh);
  1504. X
  1505. X        }
  1506. X
  1507. X    }
  1508. X#endif
  1509. X
  1510. X    return;
  1511. X}
  1512. X
  1513. X
  1514. Xvoid CenterScreenDLOG(id, hRatio, vRatio, h, v)
  1515. Xlong id;
  1516. XFixed hRatio, vRatio;
  1517. Xlong *h, *v;
  1518. X
  1519. X{
  1520. X    long wid, hgt;
  1521. X    DialogTHndl d;
  1522. X    Rect bounds;
  1523. X
  1524. X    d = (DialogTHndl) GetResource('DLOG', (short) id);
  1525. X
  1526. X    if (d != NULL) {
  1527. X
  1528. X        wid = (*d)->boundsRect.right - (*d)->boundsRect.left;
  1529. X        hgt = (*d)->boundsRect.bottom - (*d)->boundsRect.top;
  1530. X
  1531. X        GetScreenBounds(&bounds);
  1532. X
  1533. X        wid = (bounds.right - bounds.left) - wid;
  1534. X        hgt = (bounds.bottom - bounds.top) - hgt;
  1535. X
  1536. X        *h = bounds.left + FixRound(hRatio * wid);
  1537. X        *v = bounds.top + FixRound(vRatio * hgt);
  1538. X
  1539. X    }
  1540. X
  1541. X    return;
  1542. X}
  1543. X
  1544. Xlong DoScreenALRT(id, kind, hRatio, vRatio)
  1545. Xlong id;
  1546. Xlong kind;
  1547. XFixed hRatio, vRatio;
  1548. X
  1549. X{
  1550. X    long wid, hgt, h, v;
  1551. X    long item;
  1552. X    AlertTHndl a;
  1553. X    Rect bounds;
  1554. X
  1555. X    a = (AlertTHndl) GetResource('ALRT', (short) id);
  1556. X
  1557. X    if (a != NULL) {
  1558. X
  1559. X        wid = (*a)->boundsRect.right - (*a)->boundsRect.left;
  1560. X        hgt = (*a)->boundsRect.bottom - (*a)->boundsRect.top;
  1561. X
  1562. X        GetScreenBounds(&bounds);
  1563. X
  1564. X        wid = (bounds.right - bounds.left) - wid;
  1565. X        hgt = (bounds.bottom - bounds.top) - hgt;
  1566. X
  1567. X        h = bounds.left + FixRound(hRatio * wid) - (*a)->boundsRect.left;
  1568. X        v = bounds.top + FixRound(vRatio * hgt) - (*a)->boundsRect.top;
  1569. X
  1570. X        OffsetRect(&(*a)->boundsRect, (short) h, (short) v);
  1571. X
  1572. X        MoveHHi((Handle) a);
  1573. X        HLock((Handle) a);
  1574. X
  1575. X        switch (kind) {
  1576. X            case akNormal:        item = Alert((short) id, NULL);            break;
  1577. X            case akStop:        item = StopAlert((short) id, NULL);        break;
  1578. X            case akNote:        item = NoteAlert((short) id, NULL);        break;
  1579. X            case akCaution:        item = CautionAlert((short) id, NULL);    break;
  1580. X        }
  1581. X
  1582. X        HUnlock((Handle) a);
  1583. X
  1584. X    }
  1585. X
  1586. X    else
  1587. X
  1588. X        item = -1;
  1589. X
  1590. X    return(item);
  1591. X}
  1592. X
  1593. Xvoid ConfigScreenMgr(force, theType, theID, ConfigProc)
  1594. Xlong force;
  1595. XResType theType;
  1596. Xlong theID;
  1597. Xlong (*ConfigProc)(Handle theData);
  1598. X
  1599. X{
  1600. X    short saveResFile, homeResFile;
  1601. X    short attrs;
  1602. X    short itsID;
  1603. X    ResType itsType;
  1604. X    Str255 itsName;
  1605. X    Handle theData;
  1606. X
  1607. X    saveResFile = CurResFile();
  1608. X    UseResFile(theScreen.infoResFile);
  1609. X
  1610. X    theData = GetResource(theType, (short) theID);
  1611. X
  1612. X    if (theData != NULL) {
  1613. X
  1614. X        homeResFile = HomeResFile(theData);
  1615. X
  1616. X        if ( (theScreen.reconfigFlag) ||
  1617. X                (force) ||
  1618. X                (homeResFile != theScreen.infoResFile) ) {
  1619. X
  1620. X            if ((*ConfigProc)(theData)) {
  1621. X
  1622. X                if (homeResFile != theScreen.infoResFile) {
  1623. X                    GetResInfo(theData, &itsID, &itsType, itsName);
  1624. X                    attrs = GetResAttrs(theData);
  1625. X                    attrs |= resChanged;
  1626. X                    DetachResource(theData);
  1627. X                    AddResource(theData, itsType, itsID, itsName);
  1628. X                    SetResAttrs(theData, attrs);
  1629. X                }
  1630. X                else
  1631. X                    ChangedResource(theData);
  1632. X
  1633. X                WriteResource(theData);
  1634. X
  1635. X            }
  1636. X
  1637. X        }
  1638. X
  1639. X    }
  1640. X
  1641. X    UseResFile(saveResFile);
  1642. X
  1643. X    return;
  1644. X}
  1645. X
  1646. Xstatic pascal void AnimateCursor()
  1647. X
  1648. X{
  1649. X    short next;
  1650. X    long oldA5;
  1651. X
  1652. X    oldA5 = SetCurrentA5();
  1653. X
  1654. X    next = (*theScreen.acur)->next + 1;
  1655. X    if (next >= (*theScreen.acur)->frames) next = 0;
  1656. X    SetCursor(*((*theScreen.acur)->table[next].cursHandle));
  1657. X    (*theScreen.acur)->next = next;
  1658. X
  1659. X    theScreen.vbl.vblCount = (short) theScreen.waitRate;
  1660. X
  1661. X    (void) SetA5(oldA5);
  1662. X
  1663. X    return;
  1664. X}
  1665. X
  1666. Xvoid BeginScreenWait(rate)
  1667. Xlong rate;
  1668. X
  1669. X{
  1670. X    if (!theScreen.waitFlag) {
  1671. X
  1672. X        (*theScreen.acur)->next = 0;
  1673. X
  1674. X        SetCursor(*((*theScreen.acur)->table[0].cursHandle));
  1675. X        ShowCursor();
  1676. X
  1677. X        theScreen.waitFlag = true;
  1678. X        theScreen.waitRate = rate;
  1679. X
  1680. X        theScreen.vbl.qType = vType;
  1681. X#ifdef THINK_C
  1682. X        theScreen.vbl.vblAddr = (int (*)())AnimateCursor;
  1683. X#else
  1684. X        theScreen.vbl.vblAddr = AnimateCursor;
  1685. X#endif
  1686. X        theScreen.vbl.vblCount = (short) theScreen.waitRate;
  1687. X        theScreen.vbl.vblPhase = 0;
  1688. X
  1689. X        (void) VInstall((QElemPtr) &theScreen.vbl);
  1690. X
  1691. X    }
  1692. X
  1693. X    return;
  1694. X}
  1695. X
  1696. Xvoid EndScreenWait()
  1697. X
  1698. X{
  1699. X    if (theScreen.waitFlag) {
  1700. X
  1701. X        (void) VRemove((QElemPtr) &theScreen.vbl);
  1702. X
  1703. X        theScreen.waitFlag = false;
  1704. X
  1705. X        InitCursor();
  1706. X
  1707. X    }
  1708. X
  1709. X    return;
  1710. X}
  1711. X
  1712. XHandle GetFileMHandle()
  1713. X
  1714. X{
  1715. X    return((Handle) GetMHandle(theScreen.cmdKeyFlag ? fileID1 : fileID2));
  1716. X}
  1717. X
  1718. XHandle GetAppMHandle()
  1719. X
  1720. X{
  1721. X    return((Handle) GetMHandle(theScreen.cmdKeyFlag ? appID1 : appID2));
  1722. X}
  1723. X
  1724. Xlong PushScreen()
  1725. X
  1726. X{
  1727. X    long errcode;
  1728. X    char **chars, **attrs;
  1729. X    SaveScreenHandle next;
  1730. X    OSErr oops;
  1731. X
  1732. X    next = (SaveScreenHandle) NewHandle(sizeof(SaveScreenRec));
  1733. X
  1734. X    if (next != NULL) {
  1735. X
  1736. X        chars = theScreen.chars;
  1737. X        oops = HandToHand((Handle *) &chars);
  1738. X
  1739. X        if (oops == noErr) {
  1740. X
  1741. X            attrs = theScreen.attrs;
  1742. X            oops = HandToHand((Handle *) &attrs);
  1743. X
  1744. X            if (oops == noErr) {
  1745. X
  1746. X                (*next)->link = theScreen.stack;
  1747. X                (*next)->chars = chars;
  1748. X                (*next)->attrs = attrs;
  1749. X                (*next)->cursor = theScreen.cursor;
  1750. X
  1751. X                theScreen.stack = next;
  1752. X
  1753. X                errcode = scrnErrOk;
  1754. X
  1755. X            }
  1756. X
  1757. X            else {
  1758. X
  1759. X                DisposHandle((Handle) chars);
  1760. X                DisposHandle((Handle) next);
  1761. X
  1762. X                errcode = scrnErrNoMem;
  1763. X
  1764. X            }
  1765. X
  1766. X        }
  1767. X
  1768. X        else {
  1769. X
  1770. X            DisposHandle((Handle) next);
  1771. X
  1772. X            errcode = scrnErrNoMem;
  1773. X
  1774. X        }
  1775. X
  1776. X    }
  1777. X
  1778. X    else {
  1779. X
  1780. X        errcode = scrnErrNoMem;
  1781. X
  1782. X    }
  1783. X
  1784. X    return(errcode);
  1785. X}
  1786. X
  1787. Xvoid PopScreen()
  1788. X
  1789. X{
  1790. X    if (theScreen.stack != NULL) {
  1791. X
  1792. X        HLock((Handle) (*theScreen.stack)->chars);
  1793. X        HLock((Handle) (*theScreen.stack)->attrs);
  1794. X
  1795. X        XSetScreenImage(0,
  1796. X            *(*theScreen.stack)->chars,
  1797. X            *(*theScreen.stack)->attrs,
  1798. X            theScreen.scrnCDims.h,
  1799. X            &theScreen.scrnCRect,
  1800. X            0, 0);
  1801. X
  1802. X        XSetScreenCursor(0, (*theScreen.stack)->cursor.h,
  1803. X                 (*theScreen.stack)->cursor.v);
  1804. X
  1805. X        DisposeStackTop();
  1806. X
  1807. X        UpdateScreen();
  1808. X
  1809. X    }
  1810. X
  1811. X    return;
  1812. X}
  1813. END_OF_FILE
  1814. if test 31691 -ne `wc -c <'mac/scrnmgr/ScrnMgr.c.2'`; then
  1815.     echo shar: \"'mac/scrnmgr/ScrnMgr.c.2'\" unpacked with wrong size!
  1816. fi
  1817. # end of 'mac/scrnmgr/ScrnMgr.c.2'
  1818. fi
  1819. if test -f 'mac/scrnmgr/ScrnMgr.doc' -a "${1}" != "-c" ; then 
  1820.   echo shar: Will not clobber existing file \"'mac/scrnmgr/ScrnMgr.doc'\"
  1821. else
  1822. echo shar: Extracting \"'mac/scrnmgr/ScrnMgr.doc'\" \(20461 characters\)
  1823. sed "s/^X//" >'mac/scrnmgr/ScrnMgr.doc' <<'END_OF_FILE'
  1824. XCopyright (c) 1989-1991 Curtis McCauley, James E. Wilson
  1825. X
  1826. XYou may copy this subroutine package freely, modify it as you desire,
  1827. Xand distribute it at will, as long as the copyright notice in the
  1828. Xsource material is not disturbed, excepting that no one may use this
  1829. Xpackage or any part of it for commercial purposes of any kind without
  1830. Xthe express written consent of its author.
  1831. X
  1832. XThis document describes a package of subroutines I have decided to
  1833. Xcall the Screen Manager.
  1834. X
  1835. XEnclosed files:
  1836. X
  1837. XScrnMgr.doc        What you are reading
  1838. X
  1839. XScrnMgr.c        The source for the subroutine package
  1840. XScrnMgr.r        Resources used by the subroutines
  1841. XScrnMgr.h        Include file for applications
  1842. X
  1843. XScrnMgr.rsrc    The Rez output from ScrnMgr.r (if you do not have Rez)
  1844. X
  1845. XScrnTest.c        A test application
  1846. XScrnTest.r        Resources used by the test application
  1847. X
  1848. XMakeFile        What the name implies
  1849. X
  1850. XThe package is pretty heavily built around MPW.  It is specifically
  1851. Xtailored for version 3.0, but should work with 2.0.2.  The only thing
  1852. XI think you would have to modify for the older version is the SIZE
  1853. Xresource.  Porting the package to other environments is not something
  1854. XI would recommend.
  1855. X
  1856. XThe make file recognizes two primary targets: ScrnTest - which will
  1857. Xbuild the test application along with the subroutine package object
  1858. Xfile, and Install - which will copy the object files to appropriate
  1859. Xdirectories.  If you have a non-standard MPW directory structure, you
  1860. Xwill want to modify the rules for Install.
  1861. X
  1862. XI initially built the subroutine package around a model of the IBM PC
  1863. Xscreen BIOS calls.  The idea was to take a public domain curses
  1864. Xpackage for the PC and replace all the BIOS calls with calls to my
  1865. Xpackage.  Since my ultimate goal was to port the UNIX moria program
  1866. Xwhich relied on curses, and the only copy of curses I had was the PC
  1867. Xversion, this strategy initially seemed to make sense.  Moria, as it
  1868. Xturns out, only calls a few of the curses routines, so I never had to
  1869. Xactually port the whole PC curses package.  It was a lot easier to
  1870. Xjust replace the curses calls in moria with direct calls to my
  1871. Xsubroutine package.  By reducing the number of software layers I
  1872. Xachieved better performance, anyway.
  1873. X
  1874. XStill, the internal structure of the package resembles the PC BIOS.  I
  1875. Xkeep two large byte arrays to hold the entire screen, one with the
  1876. Xcharacters, the other with the attributes.  The attributes are
  1877. Xforeground and background color (the eight original quickdraw colors),
  1878. Xunderlined, and italicized.  The bulk of the package, at least in
  1879. Xnumber of functions, is taken up with routines to manipulate these
  1880. Xbuffers, either to put data in or take data out.  Whenever the
  1881. Xcontents of the buffers are changed, the window is not immediately
  1882. Xupdated to reflect the change.  Instead, I "invalidate" the portion of
  1883. Xthe window changed.  This is done by using InvalRect(), which causes
  1884. Xthe area to be accumulated in the update region of the window, or by
  1885. Xadding the area to an internal representation of the dirty area of the
  1886. Xscreen.  This internal representation is less precise than the region
  1887. Xwhich is kept by quickdraw calls to InvalRect().  It consists of the
  1888. Xbeginning and ending dirty area on each screen line.  The latter
  1889. Xmethod is faster, but the screen changes will only be noticed when a
  1890. Xcall to update the screen is explicitly made, as opposed to the idle
  1891. Xroutine (see below) catching an update event.  There are two sets of
  1892. Xroutines, then, to change the screen buffers.  The ones prefixed with
  1893. Xa 'D' (for delayed update) use the later method.
  1894. X
  1895. XA program which uses this package, at a minimum, has to call
  1896. XInitScreenMgr() at the beginning to open the window, call
  1897. XIdleScreenMgr() frequently in the middle to handle all the standard
  1898. Xmac events (mouse and keyboard events, especially, but also the
  1899. XMultiFinder stuff as well), and call CloseScreenMgr() at the end.  The
  1900. Xbest time to call the idle routine is whenever your program is waiting
  1901. Xfor a keystroke.  Another good time is at regular intervals in a heavy
  1902. Xcompute loop.  If you do this, you can actually get your program to
  1903. Xrun in the background, but all the idle calls will, of course, slow
  1904. Xthings down some.  In heavy compute passages, then, you might instead
  1905. Xwant to bracket the code with calls to BeginScreenWait() and
  1906. XEndScreenWait() to change the mouse cursor to a spinning watch.
  1907. X
  1908. XA description of each routine in the package follows --
  1909. X
  1910. Xint InitScreenMgr(int h, int v, char *title,
  1911. X    char *resFile, OSType rfCreator, OSType rfType,
  1912. X    void (*fileMenuProc)(int item),
  1913. X    void (*appMenuProc)(int item),
  1914. X    int multiColorFlag);
  1915. X
  1916. XThis routine initializes the package, allocates buffers, and puts the
  1917. Xwindow on the monitor.  H and v are the dimensions of the screen in
  1918. Xcharacters.  Title is the window title.  ResFile, rfCreator, and
  1919. XrfType describe the file to contain the configuration information.
  1920. XThis file will be maintained in the system folder.  It remembers the
  1921. Xposition and size of the window, the font size selected, and, if the
  1922. Xscreen is only two colors, the user's choices for foreground and
  1923. Xbackground color.  FileMenuProc points to a routine to be called when
  1924. Xa selection from the file menu is made.  A click in the window's close
  1925. Xbox is considered like a selection from the menu, resulting in a call
  1926. Xto fileMenuProc with the item number equal to the constant
  1927. XcloseBoxItem.  AppMenuProc points to a routine to be called when a
  1928. Xselection from the application menu is made.  Both can be NULL, in
  1929. Xwhich case the subroutine package will handle them as best it can.
  1930. XMultiColorFlag is non-zero when more than two colors will be displayed
  1931. Xon the screen.
  1932. X
  1933. Xvoid IdleScreenMgr(void);
  1934. X
  1935. XThis routine handles the macintosh event queue.  It must be called
  1936. Xfrequently, or the user will not be able to select from menus, switch
  1937. Xto another program or desk accessory, etc.  It also blinks the screen
  1938. Xcursor.
  1939. X
  1940. Xvoid ShowScreen(int visible);
  1941. X
  1942. XShows or hides the screen window, depending upon the visible flag.
  1943. X
  1944. Xvoid CloseScreenMgr(void);
  1945. X
  1946. XCloses the window, deallocates buffers.
  1947. X
  1948. Xvoid SetScreenQuitProc(void (*quitProc)(void), int willReturnFlag);
  1949. X
  1950. XTells the package what routine to call when quit is chosen.  If the
  1951. Xroutine pointed to by quitProc will always return (as opposed to doing
  1952. Xsomething like ExitToShell()), willReturnFlag should be non-zero.
  1953. X
  1954. Xvoid SetScreenAboutProc(void (*aboutProc)(void));
  1955. X
  1956. XAllows the standard about box to be overridden.  AboutProc points to a
  1957. Xroutine which should be called when the about item is chosen from the
  1958. Xapple menu.
  1959. X
  1960. XThe following routines all manipulate the screen buffers.  Calls
  1961. Xbeginning with 'Set' do not move the screen cursor and need to be told
  1962. Xwhere to begin the operation.  Calls beginning with 'Write' move the
  1963. Xcursor and begin the operation at the current cursor location.  All of
  1964. Xthese routines can be prefixed with a 'D' to make changes to the
  1965. Xinternal dirty area instead of calling InvalRect().  The internal
  1966. Xdirty area is updated only when a call to UpdateScreen() is made or
  1967. Xsome external update event is generated and caught by the idle
  1968. Xroutine.
  1969. X
  1970. XThe screen cells are indicated by column (h) and row (v) numbers which
  1971. Xincrease from left to right and top to bottom.  Hence the upper left
  1972. Xof the screen is (0, 0) and the bottom right is (h, v) as set by the
  1973. Xcall to InitScreenMgr().
  1974. X
  1975. Xvoid SetScreenChar(char c, int h, int v);
  1976. X
  1977. Xvoid SetScreenCharAttr(char c, char a, int h, int v);
  1978. X
  1979. Xvoid WriteScreenChar(char c);
  1980. X
  1981. Xvoid WriteScreenCharAttr(char c, char a);
  1982. X
  1983. XSets the character at (h, v) to c and the attribute to a.
  1984. X
  1985. Xvoid SetScreenBuffer(char *buffer, int rowBytes,
  1986. X    Rect *area, int h, int v);
  1987. X
  1988. Xvoid SetScreenBufferAttr(char *buffer, char a,
  1989. X    int rowBytes, Rect *area, int h, int v);
  1990. X
  1991. Xvoid WriteScreenBuffer(char *buffer, int rowBytes, Rect *area);
  1992. X
  1993. Xvoid WriteScreenBufferAttr(char *buffer, char a,
  1994. X    int rowBytes, Rect *area);
  1995. X
  1996. XSets the block of characters at (h, v) to the contents of buffer and
  1997. Xall the attributes to a.  RowBytes indicates the number of bytes in a
  1998. Xrow in buffer.  Area indicates the block of characters to copy,
  1999. Xassuming that the first byte in buffer is at (0, 0).  Note: This means
  2000. Xthat the area rectangle is in buffer coordinates, not screen
  2001. Xcoordinates.
  2002. X
  2003. Xvoid SetScreenString(char *str, int h, int v);
  2004. X
  2005. Xvoid SetScreenStringAttr(char *str, char a, int h, int v);
  2006. X
  2007. Xvoid WriteScreenString(char *str);
  2008. X
  2009. Xvoid WriteScreenStringAttr(char *str, char a);
  2010. X
  2011. XSets the characters at (h, v) and following to the contents of string
  2012. Xand all the attributes to a.
  2013. X
  2014. Xvoid SetScreenImage(char *c, char *a, int rowBytes,
  2015. X    Rect *area, int h, int v);
  2016. X
  2017. Xvoid WriteScreenImage(char *c, char *a,
  2018. X    int rowBytes, Rect *area);
  2019. X
  2020. XSets the block of characters at (h, v) to the contents of c and the
  2021. Xattributes to the contents of a.  RowBytes indicates the number of
  2022. Xbytes in a row in the c and a buffers.  Area indicates the block of
  2023. Xbytes to copy, assuming that the first byte in the buffers is at (0,
  2024. X0).  Note: This means that the area rectangle is in buffer
  2025. Xcoordinates, not screen coordinates.
  2026. X
  2027. Xvoid FillScreen(char c, char a, Rect *area);
  2028. X
  2029. XFills the part of the screen indicated by area with the character c
  2030. Xand the attribute a.  Area is in screen coordinates.
  2031. X
  2032. Xvoid EraseScreen(Rect *area);
  2033. X
  2034. XFills the part of the screen indicated by area with the blank
  2035. Xcharacter (0x20) and the normal attribute (attrNormal).  Area is in
  2036. Xscreen coordinates.
  2037. X
  2038. Xvoid ScrollScreen(int dh, int dv, Rect *area, char a);
  2039. X
  2040. XScrolls the part of the screen indicated by area the distance
  2041. Xindicated by dh and dv (which may be negative).  The leftover space is
  2042. Xfilled with the blank character (0x20) and the normal attribute
  2043. X(attrNormal).  Area is in screen coordinates.
  2044. X
  2045. Xvoid MoveScreenCursor(int dh, int dv);
  2046. X
  2047. XMoves the screen cursor by the number of character cells indicated by
  2048. Xdh and dv (which may be negative).
  2049. X
  2050. Xvoid SetScreenCursor(int h, int v);
  2051. X
  2052. XPositions the screen cursor at the character cell indicated by h and v.
  2053. X
  2054. Xvoid DefineScreenCursor(int color, int lines, int blinkRate);
  2055. X
  2056. XDefines the screen cursor.  Color indicates what you would expect,
  2057. Xlines indicates the height of the cursor in pixels (up to the height
  2058. Xof the character cell, so lines = 32767 will probably give you a block
  2059. Xcursor), and blinkRate indicates the number of clock ticks between
  2060. Xcursor blinks or zero for a non-blinking cursor (a really friendly
  2061. Xprogram will use GetCaretTime() to set this).  The default cursor uses
  2062. Xblack, 2 lines, and no blinks.  It is initially hidden.
  2063. X
  2064. Xvoid HideScreenCursor(void);
  2065. X
  2066. Xvoid ShowScreenCursor(void);
  2067. X
  2068. XAn internal counter is used to keep track of whether the cursor is to
  2069. Xbe shown on the screen.  When it is less than or equal to zero, the
  2070. Xcursor is hidden.  Otherwise it is shown.  The hide routine decrements
  2071. Xthis counter.  Show increments it.
  2072. X
  2073. Xvoid UpdateScreen(void);
  2074. X
  2075. XImmediately draws the dirty portion of the screen.  The dirty portion
  2076. Xincludes the update region of the window and the internal dirty area
  2077. Xmaintained by the 'D' buffer manipulation routines.
  2078. X
  2079. XIn addition to the macintosh event queue, this package maintains a
  2080. Xbuffer of keystrokes and mouse clicks.  Whenever the idle routine is
  2081. Xcalled, the events are pulled out of the macintosh queue and put into
  2082. Xthe internal buffer.
  2083. X
  2084. Xvoid FlushScreenKeys(void);
  2085. X
  2086. XFlushes the internal buffer of keystrokes and the macintosh event queue.
  2087. X
  2088. Xint CountScreenKeys(void);
  2089. X
  2090. XCounts the number of entries in the internal keystroke buffer.
  2091. X
  2092. Xint GetScreenKeys(char *keyCode, char *modifiers, char *ascii,
  2093. X    int *h, int *v);
  2094. X
  2095. XPulls the top element off the internal buffer.  KeyCode contains the
  2096. Xkeycode as described in the IM Event Manager documentation.  Modifiers
  2097. Xcontains bits which indicate the state of the control keys (command,
  2098. Xshift, caps lock, option, and control) and whether the event is a
  2099. Xmouse click.  There are masks defined in ScrnMgr.h that indicate the
  2100. Xexact bit for each.  In the case of a mouse click, h and v will be
  2101. Xset.  If you are not interested in mouse clicks, you can pass NULLs
  2102. Xfor both.  Ascii will get the ascii code of the key hit.  If the
  2103. Xkeyboard in use has a control key, the ascii value is taken right from
  2104. Xthe event which will contain the appropriate control code.  If the
  2105. Xkeyboard does not have a control key, a test is made to see if the
  2106. Xcommand modifier key is down. If so, the ascii value is converted to
  2107. Xthe appropriate control code.  See the discussion on MENU resources
  2108. Xbelow to see how command key equivalents work on machines without a
  2109. Xcontrol key.
  2110. X
  2111. Xvoid EnableScreenMouse(int flag);
  2112. X
  2113. XEnables or disables the queuing of mouse clicks in the internal
  2114. Xbuffer, according to flag.  Initially, mouse clicks are disabled.
  2115. X
  2116. Xvoid ClipScreenMouse(Rect *clip);
  2117. X
  2118. XLimits the detection of mouse clicks to the area indicated by clip,
  2119. Xmeasured in character cells on the screen.
  2120. X
  2121. Xvoid GetScreenCharAttr(char *c, char *a, int h, int v);
  2122. X
  2123. XReturns in c and a the character and attribute at (h, v).
  2124. X
  2125. Xvoid GetScreenImage(char *c, char *a, int rowBytes,
  2126. X    Rect *area, int h, int v);
  2127. X
  2128. XReturns in c and a the block of characters and attributes beginning at
  2129. X(h, v).  RowBytes indicates the number of bytes in a row in the c and
  2130. Xa buffers.  Area indicates the block of bytes to copy, assuming that
  2131. Xthe first byte in the buffers is at (0, 0).  Note: This means that the
  2132. Xarea rectangle is in buffer coordinates, not screen coordinates.
  2133. X
  2134. Xvoid GetScreenCursor(int *h, int *v);
  2135. X
  2136. XReturns the screen coordinates of the cursor.
  2137. X
  2138. XThe next few routines help with dialogs.  They are designed to work
  2139. Xwith multi-monitor systems.  On such systems, the active monitor is
  2140. Xchosen by the current mouse location, arguably not a good choice, but
  2141. Xprobably a choice as good as any other.
  2142. X
  2143. Xint YesOrNo(char *question);
  2144. X
  2145. XPuts up a dialog box with the string pointed to by question, a button
  2146. Xfor yes (the default), and a button for no.  Returns true if yes is
  2147. Xselected.  The box will be centered horizontally on the active
  2148. Xmonitor, one-third of the way from the top.
  2149. X
  2150. Xint DoScreenALRT(int id, int kind, Fixed hRatio, Fixed vRatio);
  2151. X
  2152. XPuts up the alert indicated by id.  Kind specifies the type of alert
  2153. X(normal, stop, note, or caution).  There are constants defined in
  2154. XScrnMgr.h for each of these kinds.  The alert will be centered hRatio
  2155. Xof the way from the left and vRatio of the way from the top of the
  2156. Xactive monitor.  (I.e., if hRatio = vRatio = .5, the alert will be
  2157. Xexactly in the middle of the screen.)  ScrnMgr.h contains fixed
  2158. Xconstants for common ratios.  See IM for a general discussion of fixed
  2159. Xnumbers.  Returns the item number of the button pressed.
  2160. X
  2161. Xvoid CenterScreenDLOG(int id, Fixed hRatio, Fixed vRatio,
  2162. X    int *h, int *v);
  2163. X
  2164. XGiven a DLOG, which does not have to be currently shown on the screen,
  2165. Xindicated by id, and hRatio and vRatio, returns where to position its
  2166. Xtop left corner in h and v.  See DoScreenALRT for an explanation of
  2167. XhRatio and vRatio.  This routine is generally used prior to calling
  2168. XGetNewDialog().  You should declare your DLOG to be invisible, call
  2169. XMoveWindow() using h and v to center it, and then call ShowWindow().
  2170. X
  2171. Xvoid GetScreenBounds(Rect *bounds);
  2172. X
  2173. XReturns the bounds in global coordinates of the active monitor, less
  2174. Xthe menu bar if it is on this monitor.
  2175. X
  2176. Xpascal void DrawDefaultBorder();
  2177. X
  2178. Xpascal void DrawGroupRect();
  2179. X
  2180. XTwo handy routines for installing in dialog userItems.
  2181. X
  2182. Xvoid ConfigScreenMgr(int force, ResType theType, int theID,
  2183. X    int (*configProc)(Handle theData));
  2184. X
  2185. XA routine to manipulate resources in the configuration file.  Checks
  2186. Xfor the presence of the resource indicated by theType and theID.  If
  2187. Xthis resource is not found, it does nothing.  If the resource is found
  2188. Xsomewhere other than in the configuration file (see InitScreenMgr()),
  2189. Xthis routine assumes that some action needs to be taken.  The usual
  2190. Xplace other the the configuration file to find this kind of resource
  2191. Xis in the program file itself and logically represents default values.
  2192. XIf some action needs to be taken or force is non-zero, the routine
  2193. Xpointed to by configProc is called.  TheData contains a handle to the
  2194. Xresource found as described above.  ConfigProc should generally put up
  2195. Xa dialog box to change the data in theHandle.  If it does change the
  2196. Xdata, configProc should return true.  Otherwise, false.  If configProc
  2197. Xreturns true, the handle is marked changed so that it is added to the
  2198. Xconfiguration file.  A nice time to call this routine is at the start
  2199. Xof your program with force false, so that initial configuration
  2200. Xinformation can be obtained from the user.  Then provide a menu item
  2201. Xin the application menu to allow the user to change it later, calling
  2202. Xthis routine with force true.
  2203. X
  2204. Xvoid BeginScreenWait(int rate);
  2205. X
  2206. XChanges the cursor to a spinning wristwatch.  Rate indicates the
  2207. Xnumber of ticks between each spin.
  2208. X
  2209. Xvoid EndScreenWait(void);
  2210. X
  2211. XReturns the cursor to the standard arrow.
  2212. X
  2213. XHandle GetFileMHandle(void);
  2214. X
  2215. XHandle GetAppMHandle(void);
  2216. X
  2217. XReturns a handle to the file or application menu.
  2218. X
  2219. Xint PushScreen();
  2220. X
  2221. XSaves the current screen buffer (characters, attributes, and cursor
  2222. Xlocation) on a stack.  Allocates a significant amount of memory.
  2223. XReturns 0 if successful.
  2224. X
  2225. Xvoid PopScreen()
  2226. X
  2227. XSets the screen contents to the last screen saved by PushScreen().  If
  2228. Xthere are no saved screens on the stack, does nothing.
  2229. X
  2230. XYou should include in your application all the resources found in the
  2231. Xfile ScrnMgr.rsrc.  This file is produced from ScrnMgr.r by the MPW
  2232. Xtool Rez.  The best way to do this, assuming you have Rez, is to
  2233. Xinclude at the beginning of your program's .r file, the line 'include
  2234. X"ScrnMgr.rsrc";'
  2235. X
  2236. XThis package assumes that your program will have 4 or 5 menus: the
  2237. XApple, File, Edit, Screen (FontSize), and optionally an "application"
  2238. Xmenu.  You can override the standard file menu, if you provide a
  2239. XfileMenuProc in the InitScreenMgr() call.  If you do override, you
  2240. Xshould provide two menu resources to replace the default ones in
  2241. XScrnMgr.rsrc.  The first must be MENU(129).  The second, MENU(229),
  2242. Xmust be a copy of the first, except for not having any command key
  2243. Xequivalents.  It will be used on machines without a control key.  In
  2244. Xother words, machines without a control key on the keyboard cannot use
  2245. Xcommand key equivalents.  If you want to implement an application
  2246. Xmenu, you must provide an appMenuProc to the initialization routine,
  2247. Xalong with MENU(133) and MENU(233).  The first menu is the application
  2248. Xmenu with command key equivalents, the second without.
  2249. X
  2250. XYou will probably want to override the STR(128) resource which
  2251. Xcontains the title of the first item in the apple menu (i.e, the about
  2252. Xitem).  If you override the DLOG(128) and DITL(128) resources, you can
  2253. Xrely on the package to put up your customized about box.  Otherwise,
  2254. Xyou can call SetScreenAboutProc() to really customize things.  The
  2255. Xdefault about box mentions the version of this package and its
  2256. Xprogrammer.
  2257. X
  2258. XThe STR(129) resource contains the name of the font the package should
  2259. Xuse.  Any true monospaced font should work.  Be forewarned that very
  2260. Xfew fonts are completely monospaced.  Many have a few odd characters
  2261. Xwhose width is not the same as most others.  Since this package relies
  2262. Xon GetFontInfo() and the returned widMax to setup the screen, even the
  2263. Xpresence of one extra wide character in the font will cause funny
  2264. Xthings to happen.
  2265. X
  2266. XYou will probably want to override the INFO(1) resource.  This
  2267. Xresource contains the window size, position, font size, and colors.  A
  2268. Xcopy of it is made the first time your program is run in the
  2269. Xconfiguration file and is thereafter kept up to date.  Hence, the copy
  2270. Xyou keep in you application file should contain the default initial
  2271. Xvalues.  The window size and position are indicated by a rectangle in
  2272. Xglobal coordinates.  Since ResEdit does not provide a template for
  2273. Xthis kind of resource, you will have to at least look at the ScrnMgr.r
  2274. Xfile to see the format of the resource if you want to use ResEdit to
  2275. Xmodify it.
  2276. X
  2277. XFinally, you will want to supply a SIZE resource to make your program
  2278. XMultiFinder friendly.
  2279. X
  2280. XI am somewhat ambivalent about releasing this package to the public.
  2281. XI do not think that it is particularly well-written.  And I certainly
  2282. Xdo not think that it does justice to what the mac is all about.  It is
  2283. Xprobably full of bugs.  The only real testing that it has had is in
  2284. Xthe moria port, which doesn't call all of the routines available.
  2285. XHence, I do not provide an express or implied warranty of any kind.
  2286. XYou use the package at your own risk.  If you have any questions, I
  2287. Xcan be reached at 73230.224@compuserve.com or at 73230,224 on CIS.
  2288. X
  2289. XCurtis McCauley
  2290. X22 July 1989
  2291. END_OF_FILE
  2292. if test 20461 -ne `wc -c <'mac/scrnmgr/ScrnMgr.doc'`; then
  2293.     echo shar: \"'mac/scrnmgr/ScrnMgr.doc'\" unpacked with wrong size!
  2294. fi
  2295. # end of 'mac/scrnmgr/ScrnMgr.doc'
  2296. fi
  2297. if test -f 'util/scores/README' -a "${1}" != "-c" ; then 
  2298.   echo shar: Will not clobber existing file \"'util/scores/README'\"
  2299. else
  2300. echo shar: Extracting \"'util/scores/README'\" \(1838 characters\)
  2301. sed "s/^X//" >'util/scores/README' <<'END_OF_FILE'
  2302. XThis directory contains two simple utilities for dealing with score files.
  2303. X
  2304. XThe first, prscore, will simply print a list of every score in the given
  2305. Xscorefile to standard output.  The second, delscore, will send a copy of the
  2306. Xscorefile to standard output, except that the nth entry will be deleted.
  2307. X
  2308. XIf you wish to delete an entry from your scorefile, use them as follows.
  2309. XRun "prscore scorefile" to see every entry in the scorefile.  Note the index
  2310. X(i.e. rank) of the entry you want to delete.  Then run "delscore scorefile
  2311. Xn > tmp.score" where 'n' is the number of the entry you want to delete.
  2312. XThen run "prscore tmp.score" to ensure that the scorefile is OK.  You
  2313. Xcan then copy the tmp.score file over your current scorefile.
  2314. X
  2315. XNote: do not try to run "delscore scorefile n > scorefile".  You will lose
  2316. Xyour scorefile if you do this.
  2317. X
  2318. XERRORS:
  2319. X1) This has not been well tested.  It may not work for everyone.  It probably
  2320. X   won't compile on every machine that umoria currently supports without
  2321. X   a few changes.
  2322. X
  2323. X2) If people are playing umoria while you use these utilties to edit the
  2324. X   scorefile, you may lose an entry when copying the new scorefile over the
  2325. X   old.  These utilities really should lock the scorefile, and then do their
  2326. X   work inplace.  Meanwhile, to be safe, only do this when no one is playing
  2327. X   (you can use the hours file to force this), or else do this really really
  2328. X   fast.
  2329. X
  2330. X3) It includes parts of save.c to make compilation easier.  This may cause
  2331. X   this to fail if save.c is modified and these programs aren't.  It really
  2332. X   should be linked with save.o.
  2333. X
  2334. X4) It should prompt for the output file name, and then verify that the output
  2335. X   file and the input file are different, to prevent people from accidently
  2336. X   destroying their scorefile.  (Or, this can also be fixed by doing all work
  2337. X   in place.)
  2338. X
  2339. X
  2340. END_OF_FILE
  2341. if test 1838 -ne `wc -c <'util/scores/README'`; then
  2342.     echo shar: \"'util/scores/README'\" unpacked with wrong size!
  2343. fi
  2344. # end of 'util/scores/README'
  2345. fi
  2346. echo shar: End of archive 17 \(of 39\).
  2347. cp /dev/null ark17isdone
  2348. MISSING=""
  2349. 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 33 34 35 36 37 38 39 ; do
  2350.     if test ! -f ark${I}isdone ; then
  2351.     MISSING="${MISSING} ${I}"
  2352.     fi
  2353. done
  2354. if test "${MISSING}" = "" ; then
  2355.     echo You have unpacked all 39 archives.
  2356.     echo "Now run "bldfiles.sh" to build split files"
  2357.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2358. else
  2359.     echo You still need to unpack the following archives:
  2360.     echo "        " ${MISSING}
  2361. fi
  2362. ##  End of shell archive.
  2363. exit 0
  2364.