home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3470 < prev    next >
Internet Message Format  |  1991-06-07  |  56KB

  1. From: guido@cwi.nl (Guido van Rossum)
  2. Newsgroups: alt.sources
  3. Subject: STDWIN 0.9.6 patches, part 2/5
  4. Message-ID: <3648@charon.cwi.nl>
  5. Date: 7 Jun 91 13:32:00 GMT
  6.  
  7. Archive-name: stdwin0.9.6/patch2
  8.  
  9. *** 0.9.5/Packs/textedit/editwin.c    Mon Oct 22 13:36:35 1990
  10. --- stdwin/Packs/textedit/editwin.c    Tue May 28 22:57:27 1991
  11. ***************
  12. *** 63,73 ****
  13. --- 63,77 ----
  14.   {
  15.       EDITWIN *ew= ALLOC(EDITWIN);
  16.       int width, height;
  17. +     int hbar, vbar;
  18.       int i;
  19.       
  20.       if (ew == NULL)
  21.           return NULL;
  22. +     wgetdefscrollbars(&hbar, &vbar);
  23. +     wsetdefscrollbars(0, 1);
  24.       ew->win= wopen(filename==NULL ? "Untitled" : filename, ewdrawproc);
  25. +     wsetdefscrollbars(hbar, vbar);
  26.       if (ew->win == NULL) {
  27.           FREE(ew);
  28.           return NULL;
  29. ***************
  30. *** 335,340 ****
  31. --- 339,348 ----
  32.           }
  33.           break;
  34.           
  35. +     case WE_CLOSE:
  36. +         closed= ewclose(ew);
  37. +         break;
  38.       case WE_COMMAND:
  39.           if (e->u.command == WC_CLOSE) {
  40.               closed= ewclose(ew);
  41. ***************
  42. *** 345,351 ****
  43.               e->u.command == WC_TAB ||
  44.               e->u.command == WC_BACKSPACE)
  45.               change= TRUE;
  46. !             goto def;
  47.       
  48.       case WE_MOUSE_DOWN:
  49.           /* Edit the coordinates slightly so teevent always
  50. --- 353,359 ----
  51.               e->u.command == WC_TAB ||
  52.               e->u.command == WC_BACKSPACE)
  53.               change= TRUE;
  54. !         goto def; /* Go pass it on to teevent */
  55.       
  56.       case WE_MOUSE_DOWN:
  57.           /* Edit the coordinates slightly so teevent always
  58. *** 0.9.5/Packs/textedit/text.h    Thu Oct 18 14:00:07 1990
  59. --- stdwin/Packs/textedit/text.h    Tue May 28 22:57:58 1991
  60. ***************
  61. *** 22,28 ****
  62.   struct _textedit {
  63.       /* Drawing environment */
  64.       WINDOW *win;
  65. !     coord left, top, right, bottom;
  66.       hcoord width;    /* == right-left */
  67.       TEXTATTR attr;    /* Text attributes */
  68.       vcoord vspace;    /* Vertical spacing (line height) */
  69. --- 22,28 ----
  70.   struct _textedit {
  71.       /* Drawing environment */
  72.       WINDOW *win;
  73. !     coord left, top, right, bottom;        /* Text area */
  74.       hcoord width;    /* == right-left */
  75.       TEXTATTR attr;    /* Text attributes */
  76.       vcoord vspace;    /* Vertical spacing (line height) */
  77. ***************
  78. *** 55,61 ****
  79.       coord opt_h, opt_v;    /* Caret position in window */
  80.       hcoord opt_avail;    /* White pixels at end of line */
  81.       hcoord opt_end;        /* End of line or next tab stop */
  82. !     
  83.       /* NB: aim, opt_h, opt_v are in window coordinates,
  84.              i.e., tp->left or tp->top has already been added */
  85.   };
  86. --- 55,65 ----
  87.       coord opt_h, opt_v;    /* Caret position in window */
  88.       hcoord opt_avail;    /* White pixels at end of line */
  89.       hcoord opt_end;        /* End of line or next tab stop */
  90. !     /* View restriction */
  91. !     coord vleft, vtop, vright, vbottom;    /* View area */
  92. !     tbool viewing;                /* TRUE to enable view */
  93.       /* NB: aim, opt_h, opt_v are in window coordinates,
  94.              i.e., tp->left or tp->top has already been added */
  95.   };
  96. *** 0.9.5/Packs/textedit/textedit.c    Thu Feb 21 10:53:57 1991
  97. --- stdwin/Packs/textedit/textedit.c    Tue May 28 23:18:47 1991
  98. ***************
  99. *** 30,35 ****
  100. --- 30,67 ----
  101.       teinsert(tp, cbuf, 1);
  102.   }
  103.   
  104. + /* Interfaces for wchange and wscroll that clip to the viewing rectangle */
  105. + static void
  106. + techange(tp, left, top, right, bottom)
  107. +     TEXTEDIT *tp;
  108. +     int left, top, right, bottom;
  109. + {
  110. +     if (tp->viewing) {
  111. +         CLIPMIN(left, tp->vleft);
  112. +         CLIPMIN(top, tp->vtop);
  113. +         CLIPMAX(right, tp->vright);
  114. +         CLIPMAX(bottom, tp->vbottom);
  115. +     }
  116. +     wchange(tp->win, left, top, right, bottom);
  117. + }
  118. + static void
  119. + tescroll(tp, left, top, right, bottom, dh, dv)
  120. +     TEXTEDIT *tp;
  121. +     int left, top, right, bottom;
  122. +     int dh, dv;
  123. + {
  124. +     if (tp->viewing) {
  125. +         CLIPMIN(left, tp->vleft);
  126. +         CLIPMIN(top, tp->vtop);
  127. +         CLIPMAX(right, tp->vright);
  128. +         CLIPMAX(bottom, tp->vbottom);
  129. +     }
  130. +     wscroll(tp->win, left, top, right, bottom, dh, dv);
  131. +     /* XXX Should call wchange for bits scrolled in from outside view? */
  132. + }
  133.   /* Optimization for the common case insert char.
  134.      Assumes text measurement is additive. */
  135.   
  136. ***************
  137. *** 110,128 ****
  138.       tp->opt_avail -= w;
  139.       if (tp->active)
  140.           wnocaret(tp->win);
  141. !     wscroll(tp->win,
  142.           tp->opt_h, tp->opt_v,
  143.           tp->opt_end, tp->opt_v + tp->vspace,
  144.           w, 0);
  145.       wbegindrawing(tp->win);
  146.       wdrawchar(tp->opt_h, tp->opt_v, c);
  147.       wenddrawing(tp->win);
  148.       tp->opt_h += w;
  149.       if (tp->active) {
  150. !         wsetcaret(tp->win, tp->opt_h, tp->opt_v);
  151. !         wshow(tp->win,
  152. !             tp->opt_h, tp->opt_v,
  153. !             tp->opt_h, tp->opt_v + tp->vspace);
  154.       }
  155.       tp->aim= tp->opt_h;
  156.       
  157. --- 142,170 ----
  158.       tp->opt_avail -= w;
  159.       if (tp->active)
  160.           wnocaret(tp->win);
  161. !     tescroll(tp,
  162.           tp->opt_h, tp->opt_v,
  163.           tp->opt_end, tp->opt_v + tp->vspace,
  164.           w, 0);
  165.       wbegindrawing(tp->win);
  166. +     if (tp->viewing)
  167. +         wcliprect(tp->vleft, tp->vtop, tp->vright, tp->vbottom);
  168.       wdrawchar(tp->opt_h, tp->opt_v, c);
  169.       wenddrawing(tp->win);
  170.       tp->opt_h += w;
  171.       if (tp->active) {
  172. !         if (!tp->viewing ||
  173. !             tp->vleft <= tp->opt_h &&
  174. !             tp->opt_h <= tp->vright &&
  175. !             tp->vtop <= tp->opt_v &&
  176. !             tp->opt_v + tp->vspace <= tp->vbottom) {
  177. !             wsetcaret(tp->win, tp->opt_h, tp->opt_v);
  178. !             wshow(tp->win,
  179. !                   tp->opt_h, tp->opt_v,
  180. !                   tp->opt_h, tp->opt_v + tp->vspace);
  181. !         }
  182. !         else
  183. !             wnocaret(tp->win);
  184.       }
  185.       tp->aim= tp->opt_h;
  186.       
  187. ***************
  188. *** 205,217 ****
  189.               lineno k= chlast;
  190.               if (shift > 0)
  191.                   k -= shift;
  192. !             wscroll(tp->win,
  193.                   tp->left, tp->top + k*tp->vspace,
  194.                   tp->right, tp->top + tp->nlines*tp->vspace,
  195.                   0, shift*tp->vspace);
  196.           }
  197.           
  198. !         wchange(tp->win,
  199.               tp->left, tp->top + chfirst*tp->vspace,
  200.               tp->right, tp->top + chlast*tp->vspace);
  201.       }
  202. --- 247,259 ----
  203.               lineno k= chlast;
  204.               if (shift > 0)
  205.                   k -= shift;
  206. !             tescroll(tp,
  207.                   tp->left, tp->top + k*tp->vspace,
  208.                   tp->right, tp->top + tp->nlines*tp->vspace,
  209.                   0, shift*tp->vspace);
  210.           }
  211.           
  212. !         techange(tp,
  213.               tp->left, tp->top + chfirst*tp->vspace,
  214.               tp->right, tp->top + chlast*tp->vspace);
  215.       }
  216. ***************
  217. *** 219,225 ****
  218.       tp->nlines= i+1;
  219.       newbottom= tp->top + tp->vspace*tp->nlines;
  220.       if (newbottom < tp->bottom)
  221. !         wchange(tp->win,
  222.               tp->left, newbottom, tp->right, tp->bottom);
  223.       tp->bottom= newbottom;
  224.       tp->aim= UNDEF;
  225. --- 261,267 ----
  226.       tp->nlines= i+1;
  227.       newbottom= tp->top + tp->vspace*tp->nlines;
  228.       if (newbottom < tp->bottom)
  229. !         techange(tp,
  230.               tp->left, newbottom, tp->right, tp->bottom);
  231.       tp->bottom= newbottom;
  232.       tp->aim= UNDEF;
  233. ***************
  234. *** 367,379 ****
  235.       case WE_MOUSE_DOWN:
  236.           {
  237.               int h= e->u.where.h, v= e->u.where.v;
  238. !             if (h >= tp->left && h <= tp->right &&
  239. !                     v >= tp->top && v <= tp->bottom)
  240. !                 teclicknew(tp, h, v,
  241. !                     e->u.where.button == 2,
  242. !                     e->u.where.clicks > 1);
  243. !             else
  244. !                 return FALSE;
  245.           }
  246.           break;
  247.       
  248. --- 409,428 ----
  249.       case WE_MOUSE_DOWN:
  250.           {
  251.               int h= e->u.where.h, v= e->u.where.v;
  252. !             if (tp->viewing) {
  253. !                 if (h < tp->vleft || h > tp->vright ||
  254. !                     v < tp->vtop || v > tp->vbottom)
  255. !                     return FALSE;
  256. !             }
  257. !             else {
  258. !                 if (h < tp->left || h > tp->right ||
  259. !                     v < tp->top || v > tp->bottom)
  260. !                     return FALSE;
  261. !             }
  262. !             teclicknew(tp, h, v,
  263. !                    e->u.where.button == 3 ||
  264. !                    (e->u.where.mask & WM_SHIFT),
  265. !                    e->u.where.clicks > 1);
  266.           }
  267.           break;
  268.       
  269. ***************
  270. *** 644,649 ****
  271. --- 693,717 ----
  272.   }
  273.   
  274.   void
  275. + tesetview(tp, left, top, right, bottom)
  276. +     TEXTEDIT *tp;
  277. +     int left, top, right, bottom;
  278. + {
  279. +     tp->viewing= TRUE;
  280. +     tp->vleft= left;
  281. +     tp->vtop= top;
  282. +     tp->vright= right;
  283. +     tp->vbottom= bottom;
  284. + }
  285. + void
  286. + tenoview(tp)
  287. +     TEXTEDIT *tp;
  288. + {
  289. +     tp->viewing= FALSE;
  290. + }
  291. + void
  292.   tesetfocus(tp, foc1, foc2)
  293.       TEXTEDIT *tp;
  294.       focpos foc1, foc2;
  295. ***************
  296. *** 712,718 ****
  297.       if (buf == NULL || buflen < 0)
  298.           return;
  299.       if (drawing)
  300. !         wchange(tp->win, tp->left, tp->top, tp->right, tp->bottom);
  301.       free(tp->buf);
  302.       tp->buf= buf;
  303.       tp->buflen= buflen;
  304. --- 780,786 ----
  305.       if (buf == NULL || buflen < 0)
  306.           return;
  307.       if (drawing)
  308. !         techange(tp, tp->left, tp->top, tp->right, tp->bottom);
  309.       free(tp->buf);
  310.       tp->buf= buf;
  311.       tp->buflen= buflen;
  312. ***************
  313. *** 721,727 ****
  314.       terecompute(tp, 0, tp->buflen);
  315.       if (drawing) {
  316.           tp->drawing= TRUE;
  317. !         wchange(tp->win, tp->left, tp->top, tp->right, tp->bottom);
  318.       }
  319.   }
  320.   
  321. --- 789,795 ----
  322.       terecompute(tp, 0, tp->buflen);
  323.       if (drawing) {
  324.           tp->drawing= TRUE;
  325. !         techange(tp, tp->left, tp->top, tp->right, tp->bottom);
  326.       }
  327.   }
  328.   
  329. *** 0.9.5/Packs/textedit/textlow.c    Mon Oct 22 13:37:36 1990
  330. --- stdwin/Packs/textedit/textlow.c    Tue May 28 23:19:12 1991
  331. ***************
  332. *** 1,5 ****
  333. --- 1,7 ----
  334.   /* Text Edit, low-level routines */
  335.   
  336. + /* XXX Should make return-less functions void */
  337.   /* CONVENTION:
  338.       routines beginning with te... have a first parameter 'tp';
  339.       routines beginning with z... don't, or are macros that
  340. ***************
  341. *** 199,204 ****
  342. --- 201,208 ----
  343.       tp->top= top;
  344.       tp->right= right;
  345.       tp->width= right-left;
  346. +     tp->viewing= FALSE;
  347.       
  348.       wgettextattr(&saveattr);
  349.       if (win != NULL) {
  350. ***************
  351. *** 247,253 ****
  352.   tedestroy(tp)
  353.       register TEXTEDIT *tp;
  354.   {
  355. !     wchange(tp->win, tp->left, tp->top, tp->right, tp->bottom);
  356.       tefree(tp);
  357.   }
  358.   
  359. --- 251,260 ----
  360.   tedestroy(tp)
  361.       register TEXTEDIT *tp;
  362.   {
  363. !     if (tp->viewing)
  364. !         wchange(tp->win, tp->vleft, tp->vtop, tp->vright, tp->vbottom);
  365. !     else
  366. !         wchange(tp->win, tp->left, tp->top, tp->right, tp->bottom);
  367.       tefree(tp);
  368.   }
  369.   
  370. ***************
  371. *** 294,299 ****
  372. --- 301,308 ----
  373.   {
  374.       if (tp->active && !tp->hilite && tp->foclen > 0) {
  375.           wbegindrawing(tp->win);
  376. +         if (tp->viewing)
  377. +             wcliprect(tp->vleft, tp->vtop, tp->vright, tp->vbottom);
  378.           teinvertfocus(tp);
  379.           wenddrawing(tp->win);
  380.           tp->hilite= TRUE;
  381. ***************
  382. *** 305,310 ****
  383. --- 314,321 ----
  384.   {
  385.       if (tp->hilite) {
  386.           wbegindrawing(tp->win);
  387. +         if (tp->viewing)
  388. +             wcliprect(tp->vleft, tp->vtop, tp->vright, tp->vbottom);
  389.           teinvertfocus(tp);
  390.           wenddrawing(tp->win);
  391.           tp->hilite= FALSE;
  392. ***************
  393. *** 327,332 ****
  394. --- 338,345 ----
  395.   {
  396.       if (tp->hilite) {
  397.           wbegindrawing(tp->win);
  398. +         if (tp->viewing)
  399. +             wcliprect(tp->vleft, tp->vtop, tp->vright, tp->vbottom);
  400.           if (f1 == tp->foc)
  401.               teinvert(tp, zfocend, f2);
  402.           else if (f2 == zfocend)
  403. ***************
  404. *** 379,385 ****
  405.       tedrawnew(tp, tp->left, tp->top, tp->right, tp->bottom);
  406.   }
  407.   
  408. - /*ARGSUSED*/
  409.   void
  410.   tedrawnew(tp, left, top, right, bottom)
  411.       register TEXTEDIT *tp;
  412. --- 392,397 ----
  413. ***************
  414. *** 386,392 ****
  415. --- 398,415 ----
  416.       coord left, top, right, bottom;
  417.   {
  418.       lineno ifirst, ilast, i;
  419. +     /* Clip given area to view */
  420. +     if (tp->viewing) {
  421. +         CLIPMIN(left, tp->vleft);
  422. +         CLIPMIN(top, tp->vtop);
  423. +         CLIPMAX(right, tp->vright);
  424. +         CLIPMAX(bottom, tp->vbottom);
  425. +     }
  426.       
  427. +     /* Restrict drawing to intersection of view and given area */
  428. +     wcliprect(left, top, right, bottom);
  429. +     
  430.       /* Compute first, last line to be drawn */
  431.       ifirst= (top - tp->top)/tp->vspace;
  432.       if (ifirst < 0)
  433. ***************
  434. *** 408,413 ****
  435. --- 431,439 ----
  436.       }
  437.       if (tp->hilite)
  438.           teinvertfocus(tp);
  439. +     
  440. +     /* Reset the clip rectangle */
  441. +     wnoclip();
  442.   }
  443.   
  444.   /* Move the gap to a new position */
  445. ***************
  446. *** 522,527 ****
  447. --- 548,569 ----
  448.           tp->start[i]= zgapend;
  449.   }
  450.   
  451. + /* Interface for wshow that clips to the viewing rectangle */
  452. + static void
  453. + teshow(tp, left, top, right, bottom)
  454. +     TEXTEDIT *tp;
  455. +     int left, top, right, bottom;
  456. + {
  457. +     if (tp->viewing) {
  458. +         CLIPMIN(left, tp->vleft);
  459. +         CLIPMIN(top, tp->vtop);
  460. +         CLIPMAX(right, tp->vright);
  461. +         CLIPMAX(bottom, tp->vbottom);
  462. +     }
  463. +     wshow(tp->win, left, top, right, bottom);
  464. + }
  465.   /* Set the caret at the new focus position,
  466.      or display the focus highlighting, if applicable.
  467.      Also call wshow() of the focus.
  468. ***************
  469. *** 539,545 ****
  470.       tewhichpoint(tp, tp->foc, &h, &v);
  471.       
  472.       if (tp->foclen == 0) {
  473. !         wsetcaret(tp->win, h, v);
  474.           hlast= h;
  475.           vlast= v;
  476.       }
  477. --- 581,594 ----
  478.       tewhichpoint(tp, tp->foc, &h, &v);
  479.       
  480.       if (tp->foclen == 0) {
  481. !         if (!tp->viewing ||
  482. !             tp->vleft <= h && h <= tp->vright &&
  483. !             tp->vtop <= v && v + tp->vspace <= tp->vbottom) {
  484. !             wsetcaret(tp->win, h, v);
  485. !         }
  486. !         else {
  487. !             wnocaret(tp->win);
  488. !         }
  489.           hlast= h;
  490.           vlast= v;
  491.       }
  492. ***************
  493. *** 548,554 ****
  494.           wnocaret(tp->win);
  495.           teshowfocus(tp);
  496.       }
  497. !     wshow(tp->win, h, v, hlast, vlast + tp->vspace);
  498.   }
  499.   
  500.   /* Coordinate transformations.
  501. --- 597,603 ----
  502.           wnocaret(tp->win);
  503.           teshowfocus(tp);
  504.       }
  505. !     teshow(tp, h, v, hlast, vlast + tp->vspace);
  506.   }
  507.   
  508.   /* Coordinate transformations.
  509. *** 0.9.5/Packs/vt/vt.c    Mon Oct 22 15:06:06 1990
  510. --- stdwin/Packs/vt/vt.c    Tue May 14 13:16:40 1991
  511. ***************
  512. *** 15,20 ****
  513. --- 15,21 ----
  514.                   int left, int top, int right, int bottom));
  515.   STATIC void vtdraw _ARGS((VT *vt, int r1, int c1, int r2, int c2));
  516.   STATIC void vtchrange _ARGS((VT *vt, int r1, int c1, int r2, int c2));
  517. + STATIC bool slowcirculate _ARGS((VT *vt, int r1, int r2, int n));
  518.   
  519.   /* Administration for vtfind */
  520.   
  521. *** 0.9.5/Packs/vt/vtvtrm.c    Mon Oct 22 15:46:08 1990
  522. --- stdwin/Packs/vt/vtvtrm.c    Tue May 14 13:17:29 1991
  523. ***************
  524. *** 7,12 ****
  525. --- 7,13 ----
  526.      One other thing: you'll have to call wdone() when you really exit. */
  527.   
  528.   /* XXX This has never been tested... */
  529. + /* XXX The interfaces to trmputdata and trmsense should change !!! */
  530.   
  531.   #include "vtimpl.h"
  532.   #include "vtrm.h"
  533. ***************
  534. *** 30,36 ****
  535.       *rows_return= 24;
  536.       *cols_return= 80;
  537.       *flags_return=
  538. !         HAS_STANDOUT | CAN_SCROLL | CAN_SENSE;
  539.       return TE_OK;
  540.   }
  541.   
  542. --- 31,37 ----
  543.       *rows_return= 24;
  544.       *cols_return= 80;
  545.       *flags_return=
  546. !         HAS_STANDOUT | CAN_SCROLL;
  547.       return TE_OK;
  548.   }
  549.   
  550. ***************
  551. *** 39,44 ****
  552. --- 40,46 ----
  553.       active= FALSE;
  554.   }
  555.   
  556. + /* XXX Need interface change */
  557.   trmputdata(row, col, data)
  558.       int row, col;
  559.       char *data;
  560. ***************
  561. *** 130,135 ****
  562. --- 132,138 ----
  563.       }
  564.   }
  565.   
  566. + /* XXX Need interface change */
  567.   int
  568.   trmsense(row_return, col_return)
  569.       int *row_return, *col_return;
  570. *** 0.9.5/Ports/alfa/draw.c    Tue Jan  8 13:03:32 1991
  571. --- stdwin/Ports/alfa/draw.c    Sun May 12 13:54:10 1991
  572. ***************
  573. *** 3,8 ****
  574. --- 3,9 ----
  575.   #include "alfa.h"
  576.   
  577.   static char *textline[MAXLINES];
  578. + static char *modeline[MAXLINES];
  579.   static short textlen[MAXLINES];
  580.   static char texttouched[MAXLINES];
  581.   
  582. ***************
  583. *** 112,117 ****
  584. --- 113,119 ----
  585.       for (i= top; i < bottom; ++i)
  586.           uptodate[i] = FALSE;
  587.   #else
  588. +     /* XXX This code was never fixed to update the mode array */
  589.       char *p;
  590.   
  591.       if(dv==0)
  592. ***************
  593. *** 238,255 ****
  594.   wbegindrawing(win)
  595.       WINDOW *win;
  596.   {
  597. !     int i;
  598.       
  599.       if (draw_win != NULL)
  600.           wenddrawing(draw_win); /* Finish previous job */
  601.       
  602. !     /* Auto-initialization of the textline array.
  603.          The other arrays needn't be initialized,
  604.          since they are preset to zero. */
  605.       for (i= win->top; i < win->bottom; ++i) {
  606.           if (textline[i] == NULL)
  607.               textline[i]= malloc((unsigned) (columns+1));
  608. !             /*uptodate[i]= FALSE;*/
  609.       }
  610.       
  611.       draw_saveattr= wattr;
  612. --- 240,262 ----
  613.   wbegindrawing(win)
  614.       WINDOW *win;
  615.   {
  616. !     int i, j;
  617.       
  618.       if (draw_win != NULL)
  619.           wenddrawing(draw_win); /* Finish previous job */
  620.       
  621. !     /* Auto-initialization of the textline and modeline array.
  622.          The other arrays needn't be initialized,
  623.          since they are preset to zero. */
  624. +     /* XXX Crash if malloc() fails! */
  625.       for (i= win->top; i < win->bottom; ++i) {
  626.           if (textline[i] == NULL)
  627.               textline[i]= malloc((unsigned) (columns+1));
  628. !         if (modeline[i] == NULL) {
  629. !             modeline[i]= malloc((unsigned) columns);
  630. !             for (j = 0; j < columns; j++)
  631. !                 modeline[i][j] = PLAIN;
  632. !         }
  633.       }
  634.       
  635.       draw_saveattr= wattr;
  636. ***************
  637. *** 271,277 ****
  638.           if (texttouched[i]) {
  639.               texttouched[i]= FALSE;
  640.               textline[i][textlen[i]]= EOS;
  641. !             trmputdata(i, i, 0, textline[i]);
  642.           }
  643.       }
  644.       
  645. --- 278,284 ----
  646.           if (texttouched[i]) {
  647.               texttouched[i]= FALSE;
  648.               textline[i][textlen[i]]= EOS;
  649. !             trmputdata(i, i, 0, textline[i], modeline[i]);
  650.           }
  651.       }
  652.       
  653. ***************
  654. *** 292,307 ****
  655.       int k;
  656.       
  657.       for (k= 0; k < space/2 - 1; ++k)
  658. !         buf[k]= '-'|mask;
  659. !     buf[k++]= ' '|mask;
  660.       while (k < columns && *title != EOS)
  661. !         buf[k++]= *title++|mask;
  662.       if (k < columns)
  663. !         buf[k++]= ' '|mask;
  664.       while (k < columns)
  665. !         buf[k++]= '-'|mask;
  666.       buf[k]= EOS;
  667. !     trmputdata(titline, titline, 0, buf);
  668.       uptodate[titline]= TRUE;
  669.   }
  670.   
  671. --- 299,323 ----
  672.       int k;
  673.       
  674.       for (k= 0; k < space/2 - 1; ++k)
  675. !         buf[k]= '-';
  676. !     buf[k++]= ' ';
  677.       while (k < columns && *title != EOS)
  678. !         buf[k++]= *title++;
  679.       if (k < columns)
  680. !         buf[k++]= ' ';
  681.       while (k < columns)
  682. !         buf[k++]= '-';
  683.       buf[k]= EOS;
  684. !     if (win == front) {
  685. !         char mode[256];
  686. !         int i;
  687. !         for (i = 0; i < k; i++)
  688. !             mode[i] = STANDOUT;
  689. !         trmputdata(titline, titline, 0, buf, mode);
  690. !     }
  691. !     else {
  692. !         trmputdata(titline, titline, 0, buf, (char *)0);
  693. !     }
  694.       uptodate[titline]= TRUE;
  695.   }
  696.   
  697. ***************
  698. *** 312,319 ****
  699.       int len;
  700.   {
  701.       int k;
  702. !     int mask= (wattr.style == 0) ? 0 : 0200;
  703.       char *text;
  704.       WINDOW *win= draw_win;
  705.       
  706.       if (len < 0)
  707. --- 328,336 ----
  708.       int len;
  709.   {
  710.       int k;
  711. !     int flag= (wattr.style == 0) ? PLAIN : STANDOUT;
  712.       char *text;
  713. +     char *mode;
  714.       WINDOW *win= draw_win;
  715.       
  716.       if (len < 0)
  717. ***************
  718. *** 322,333 ****
  719.       if (v < win->top || v >= win->bottom || h >= columns || len == 0)
  720.           return;
  721.       text= textline[v];
  722.       k= textlen[v];
  723. !     while (k < h)
  724. !         text[k++]= ' ';
  725.       while (len > 0) {
  726.   #define APPC(c) \
  727. !     if (h >= 0) text[h]= (c) | mask; if (++h >= columns) break
  728.           unsigned char c= *str++;
  729.           --len;
  730.           if (c < ' ') {
  731. --- 339,353 ----
  732.       if (v < win->top || v >= win->bottom || h >= columns || len == 0)
  733.           return;
  734.       text= textline[v];
  735. +     mode= modeline[v];
  736.       k= textlen[v];
  737. !     for (; k < h; k++) {
  738. !         text[k]= ' ';
  739. !         mode[k]= PLAIN;
  740. !     }
  741.       while (len > 0) {
  742.   #define APPC(c) \
  743. !     if (h >= 0) {text[h]= (c); mode[h]= flag;} if (++h >= columns) break
  744.           unsigned char c= *str++;
  745.           --len;
  746.           if (c < ' ') {
  747. ***************
  748. *** 407,412 ****
  749. --- 427,448 ----
  750.   
  751.   /*ARGSUSED*/
  752.   void
  753. + wfillcircle(h, v, radius)
  754. +     int h, v;
  755. +     int radius;
  756. + {
  757. + }
  758. + /*ARGSUSED*/
  759. + void
  760. + wxorcircle(h, v, radius)
  761. +     int h, v;
  762. +     int radius;
  763. + {
  764. + }
  765. + /*ARGSUSED*/
  766. + void
  767.   wdrawelarc(h, v, radh, radv, ang1, ang2)
  768.       int h, v;
  769.       int radh, radv;
  770. ***************
  771. *** 416,421 ****
  772. --- 452,475 ----
  773.   
  774.   /*ARGSUSED*/
  775.   void
  776. + wfillelarc(h, v, radh, radv, ang1, ang2)
  777. +     int h, v;
  778. +     int radh, radv;
  779. +     int ang1, ang2;
  780. + {
  781. + }
  782. + /*ARGSUSED*/
  783. + void
  784. + wxorelarc(h, v, radh, radv, ang1, ang2)
  785. +     int h, v;
  786. +     int radh, radv;
  787. +     int ang1, ang2;
  788. + {
  789. + }
  790. + /*ARGSUSED*/
  791. + void
  792.   wdrawbox(left, top, right, bottom)
  793.       int left, top, right, bottom;
  794.   {
  795. ***************
  796. *** 459,472 ****
  797.       for (v= top; v < bottom; ++v) {
  798.           int k= textlen[v];
  799.           char *text= textline[v];
  800.           if (k < right) {
  801.               do {
  802. !                 text[k++]= ' ';
  803.               } while (k < right);
  804.               textlen[v]= k;
  805.           }
  806. !         for (k= left; k < right; ++k)
  807. !             text[k] ^= 0200;
  808.           texttouched[v]= TRUE;
  809.       }
  810.   }
  811. --- 513,533 ----
  812.       for (v= top; v < bottom; ++v) {
  813.           int k= textlen[v];
  814.           char *text= textline[v];
  815. +         char *mode= modeline[v];
  816.           if (k < right) {
  817.               do {
  818. !                 text[k]= ' ';
  819. !                 mode[k]= PLAIN;
  820. !                 k++;
  821.               } while (k < right);
  822.               textlen[v]= k;
  823.           }
  824. !         for (k= left; k < right; ++k) {
  825. !             if (mode[k] != PLAIN)
  826. !                 mode[k]= PLAIN;
  827. !             else
  828. !                 mode[k]= STANDOUT;
  829. !         }
  830.           texttouched[v]= TRUE;
  831.       }
  832.   }
  833. ***************
  834. *** 494,503 ****
  835.       for (v= top; v < bottom; ++v) {
  836.           int k= textlen[v];
  837.           char *text= textline[v];
  838.           if (k > right)
  839.               k= right;
  840. !         while (--k >= left)
  841.               text[k]= ' ';
  842.           texttouched[v]= TRUE;
  843.       }
  844.   }
  845. --- 555,567 ----
  846.       for (v= top; v < bottom; ++v) {
  847.           int k= textlen[v];
  848.           char *text= textline[v];
  849. +         char *mode= modeline[v];
  850.           if (k > right)
  851.               k= right;
  852. !         while (--k >= left) {
  853.               text[k]= ' ';
  854. +             mode[k]= PLAIN;
  855. +         }
  856.           texttouched[v]= TRUE;
  857.       }
  858.   }
  859. ***************
  860. *** 504,509 ****
  861. --- 568,597 ----
  862.   
  863.   /*ARGSUSED*/
  864.   void
  865. + wdrawpoly(n, points)
  866. +     int n;
  867. +     POINT *points;
  868. + {
  869. + }
  870. + /*ARGSUSED*/
  871. + void
  872. + wfillpoly(n, points)
  873. +     int n;
  874. +     POINT *points;
  875. + {
  876. + }
  877. + /*ARGSUSED*/
  878. + void
  879. + wxorpoly(n, points)
  880. +     int n;
  881. +     POINT *points;
  882. + {
  883. + }
  884. + /*ARGSUSED*/
  885. + void
  886.   wcliprect(left, top, right, bottom)
  887.       int left, top, right, bottom;
  888.   {
  889. ***************
  890. *** 515,518 ****
  891. --- 603,654 ----
  892.   wnoclip()
  893.   {
  894.       /* XXX not implemented */
  895. + }
  896. + /*ARGSUSED*/
  897. + void
  898. + wsetfont(fontname)
  899. +     char *fontname;
  900. + {
  901. + }
  902. + /*ARGSUSED*/
  903. + void
  904. + wsetsize(size)
  905. +     int size;
  906. + {
  907. + }
  908. + /*ARGSUSED*/
  909. + COLOR
  910. + wfetchcolor(colorname)
  911. +     char *colorname;
  912. + {
  913. +     return 0;
  914. + }
  915. + /*ARGSUSED*/
  916. + void
  917. + wsetfgcolor(color)
  918. +     COLOR color;
  919. + {
  920. + }
  921. + COLOR
  922. + wgetfgcolor()
  923. + {
  924. +     return 0;
  925. + }
  926. + /*ARGSUSED*/
  927. + void
  928. + wsetbgcolor(color)
  929. +     COLOR color;
  930. + {
  931. + }
  932. + COLOR
  933. + wgetbgcolor()
  934. + {
  935. +     return 0;
  936.   }
  937. *** 0.9.5/Ports/alfa/event.c    Thu Oct 18 13:58:28 1990
  938. --- stdwin/Ports/alfa/event.c    Tue May 28 18:35:41 1991
  939. ***************
  940. *** 223,228 ****
  941. --- 223,230 ----
  942.       }
  943.       if (ep->window == NULL && front != syswin)
  944.           ep->window= front;
  945. +     if (ep->type == WE_COMMAND && ep->u.command == WC_CLOSE)
  946. +         ep->type= WE_CLOSE; /* Too hard to do earlier... */
  947.       lasttype= ep->type;
  948.       return ep->type != WE_NULL;
  949.   }
  950. *** 0.9.5/Ports/alfa/menu.c    Mon Oct 29 09:58:17 1990
  951. --- stdwin/Ports/alfa/menu.c    Tue Apr 16 16:20:02 1991
  952. ***************
  953. *** 497,503 ****
  954.           if (lowest < lines)
  955.               uptodate[lowest]= FALSE;
  956.       }
  957. !     trmputdata(i+1, lowest, 0, "");
  958.       leftblank= left;
  959.       trmsync(curitem+1, mp->left);
  960.   }
  961. --- 497,503 ----
  962.           if (lowest < lines)
  963.               uptodate[lowest]= FALSE;
  964.       }
  965. !     trmputdata(i+1, lowest, 0, "", (char *)0);
  966.       leftblank= left;
  967.       trmsync(curitem+1, mp->left);
  968.   }
  969. ***************
  970. *** 559,566 ****
  971.          items on the first menu (after the sysmenu) weren't removed
  972.          from the screen.  I haven't tried to fix this in a more
  973.          efficient manner. */
  974. !     trmputdata(line, line, 0, "");
  975. !     trmputdata(line, line, leftblank, buf);
  976.       uptodate[line]= FALSE;
  977.   }
  978.   
  979. --- 559,566 ----
  980.          items on the first menu (after the sysmenu) weren't removed
  981.          from the screen.  I haven't tried to fix this in a more
  982.          efficient manner. */
  983. !     trmputdata(line, line, 0, "", (char *)0);
  984. !     trmputdata(line, line, leftblank, buf, (char *)0);
  985.       uptodate[line]= FALSE;
  986.   }
  987.   
  988. *** 0.9.5/Ports/alfa/stdwin.c    Sun Oct 21 12:51:10 1990
  989. --- stdwin/Ports/alfa/stdwin.c    Tue Apr 16 16:21:10 1991
  990. ***************
  991. *** 16,37 ****
  992.   
  993.   int lines, columns;
  994.   
  995. ! /* Initialization call.
  996. !    Should be called only once, before any others.
  997. !    Will exit when the initialization fails. */
  998.   void
  999. ! winit()
  1000.   {
  1001. !     winitargs((int*)NULL, (char***)NULL);
  1002.   }
  1003.   
  1004.   /*ARGSUSED*/
  1005.   void
  1006. ! winitargs(pargc, pargv)
  1007.       int *pargc;
  1008.       char ***pargv;
  1009.   {
  1010.       int flags;
  1011.       int err;
  1012.       
  1013. --- 16,46 ----
  1014.   
  1015.   int lines, columns;
  1016.   
  1017. ! /*ARGSUSED*/
  1018.   void
  1019. ! winitargs(pargc, pargv)
  1020. !     int *pargc;
  1021. !     char ***pargv;
  1022.   {
  1023. !     wargs(pargc, pargv);
  1024. !     winit();
  1025.   }
  1026.   
  1027.   /*ARGSUSED*/
  1028.   void
  1029. ! wargs(pargc, pargv)
  1030.       int *pargc;
  1031.       char ***pargv;
  1032.   {
  1033. + }
  1034. + /* Initialization call.
  1035. +    Should be called only once, before any others.
  1036. +    Will exit when the initialization fails. */
  1037. + void
  1038. + winit()
  1039. + {
  1040.       int flags;
  1041.       int err;
  1042.       
  1043. ***************
  1044. *** 59,65 ****
  1045.       gettckeydefs();
  1046.       if (lines > MAXLINES)
  1047.           lines= MAXLINES;
  1048. !     trmputdata(0, lines-1, 0, "");
  1049.       initsyswin();
  1050.       _winitmenus();
  1051.   }
  1052. --- 68,74 ----
  1053.       gettckeydefs();
  1054.       if (lines > MAXLINES)
  1055.           lines= MAXLINES;
  1056. !     trmputdata(0, lines-1, 0, "", (char *)0);
  1057.       initsyswin();
  1058.       _winitmenus();
  1059.   }
  1060. ***************
  1061. *** 73,79 ****
  1062.   {
  1063.       if (lines > 0) {
  1064.           /* Move cursor to last screen line. */
  1065. !         trmputdata(lines-1, lines-1, 0, "");
  1066.           trmsync(lines-1, 0);
  1067.       }
  1068.       lines= 0;
  1069. --- 82,88 ----
  1070.   {
  1071.       if (lines > 0) {
  1072.           /* Move cursor to last screen line. */
  1073. !         trmputdata(lines-1, lines-1, 0, "", (char *)0);
  1074.           trmsync(lines-1, 0);
  1075.       }
  1076.       lines= 0;
  1077. ***************
  1078. *** 292,297 ****
  1079. --- 301,334 ----
  1080.   {
  1081.   }
  1082.   
  1083. + /*ARGSUSED*/
  1084. + void
  1085. + wsetdefscrollbars(width, height)
  1086. +     int width, height;
  1087. + {
  1088. + }
  1089. + void
  1090. + wgetdefwinpos(ph, pv)
  1091. +     int *ph, *pv;
  1092. + {
  1093. +     *ph = *pv = 0;
  1094. + }
  1095. + void
  1096. + wgetdefwinsize(ph, pv)
  1097. +     int *ph, *pv;
  1098. + {
  1099. +     *ph = *pv = 0;
  1100. + }
  1101. + void
  1102. + wgetdefscrollbars(ph, pv)
  1103. +     int *ph, *pv;
  1104. + {
  1105. +     *ph = *pv = 0;
  1106. + }
  1107.   /* Make a window the active window. */
  1108.   
  1109.   void
  1110. ***************
  1111. *** 362,368 ****
  1112.           uptodate[i]= FALSE;
  1113.       _wreshuffle();
  1114.       trmundefined();
  1115. !     trmputdata(0, lines-1, 0, "");
  1116.   }
  1117.   
  1118.   /* Temporarily restore cooked tty mode. */
  1119. --- 399,405 ----
  1120.           uptodate[i]= FALSE;
  1121.       _wreshuffle();
  1122.       trmundefined();
  1123. !     trmputdata(0, lines-1, 0, "", (char *)0);
  1124.   }
  1125.   
  1126.   /* Temporarily restore cooked tty mode. */
  1127. ***************
  1128. *** 369,375 ****
  1129.   
  1130.   _wcooked()
  1131.   {
  1132. !     trmputdata(lines-1, lines-1, 0, "");
  1133.       trmsync(lines-1, 0);
  1134.       trmend();
  1135.   }
  1136. --- 406,412 ----
  1137.   
  1138.   _wcooked()
  1139.   {
  1140. !     trmputdata(lines-1, lines-1, 0, "", (char *)0);
  1141.       trmsync(lines-1, 0);
  1142.       trmend();
  1143.   }
  1144. *** 0.9.5/Ports/alfa/syswin.c    Thu Oct 18 13:58:31 1990
  1145. --- stdwin/Ports/alfa/syswin.c    Tue Apr 16 16:21:35 1991
  1146. ***************
  1147. *** 346,355 ****
  1148.       while(Butt[y-1]) {
  1149.           if(y==Curr) sprintf(buf, "%c %s", META('o'), Butt[y-1]); 
  1150.           else sprintf(buf, "o %s", Butt[y-1]);
  1151. !         trmputdata(y, y, 0, buf);
  1152.           ++y;
  1153.       }
  1154. !     trmputdata(y,y,0,"");
  1155.   }
  1156.   
  1157.   /* additional EuroMath WM routine, called after returning from an
  1158. --- 346,355 ----
  1159.       while(Butt[y-1]) {
  1160.           if(y==Curr) sprintf(buf, "%c %s", META('o'), Butt[y-1]); 
  1161.           else sprintf(buf, "o %s", Butt[y-1]);
  1162. !         trmputdata(y, y, 0, buf, (char *)0);
  1163.           ++y;
  1164.       }
  1165. !     trmputdata(y,y,0,"",(char *)0);
  1166.   }
  1167.   
  1168.   /* additional EuroMath WM routine, called after returning from an
  1169. *** 0.9.5/Ports/mac/about.c    Thu Feb 28 12:48:31 1991
  1170. --- stdwin/Ports/mac/about.c    Tue Mar 26 11:08:03 1991
  1171. ***************
  1172. *** 16,23 ****
  1173.      Also see your THINK C licence.
  1174.   */
  1175.   char *about_message=
  1176. !     "STDWIN version 0.9.5 (using THINK C 4.0)\r\r\
  1177. ! Copyright \251 1988, 1989, 1990 Stichting Mathematisch Centrum, \
  1178.   Amsterdam\r\
  1179.   Written by Guido van Rossum (guido@cwi.nl)\r\
  1180.   CWI, dept. AA, P.O.B. 4079\r1009 AB  Amsterdam, The Netherlands\r\r\
  1181. --- 16,23 ----
  1182.      Also see your THINK C licence.
  1183.   */
  1184.   char *about_message=
  1185. !     "STDWIN version 0.9.5a (using THINK C 4.0)\r\r\
  1186. ! Copyright \251 1988, 1989, 1990, 1991 Stichting Mathematisch Centrum, \
  1187.   Amsterdam\r\
  1188.   Written by Guido van Rossum (guido@cwi.nl)\r\
  1189.   CWI, dept. AA, P.O.B. 4079\r1009 AB  Amsterdam, The Netherlands\r\r\
  1190. *** /dev/null    Fri Jun  7 14:31:40 1991
  1191. --- stdwin/Ports/mac/color.c    Tue Apr  9 20:01:40 1991
  1192. ***************
  1193. *** 0 ****
  1194. --- 1,44 ----
  1195. + /* MAC STDWIN -- COLOR HANDLING. */
  1196. + #include "macwin.h"
  1197. + /* Provisional color encoding:
  1198. +    - low 16 bits: a color as specified in <QuickDraw.h>
  1199. +    - high 16 bits: a shade factor, 0 -> full, 128 -> 50%
  1200. +    See also draw.c
  1201. + */
  1202. + static struct colorentry {
  1203. +     char *name;
  1204. +     long color;
  1205. + } colorlist[] = {
  1206. +     {"black",    blackColor},
  1207. +     {"white",    whiteColor},
  1208. +     {"red",        redColor},
  1209. +     {"green",    greenColor},
  1210. +     {"blue",    blueColor},
  1211. +     {"cyan",    cyanColor},
  1212. +     {"magenta",    magentaColor},
  1213. +     {"yellow",    yellowColor},
  1214. +     {"gray25",    blackColor + (192L << 16)},
  1215. +     {"gray50",    blackColor + (128L << 16)},
  1216. +     {"gray75",    blackColor + (64L << 16)},
  1217. +     {"foreground",    blackColor},
  1218. +     {"background",    whiteColor},
  1219. +     {NULL,        0}    /* Sentinel */
  1220. + };
  1221. + long
  1222. + wfetchcolor(colorname)
  1223. +     char *colorname;
  1224. + {
  1225. +     struct colorentry *p;
  1226. +     
  1227. +     for (p = colorlist; p->name != NULL; p++) {
  1228. +         if (strcmp(p->name, colorname) == 0)
  1229. +             return p->color;
  1230. +     }
  1231. +     
  1232. +     dprintf("wmakecolor: unknown color '%s'", colorname);
  1233. +     return blackColor;
  1234. + }
  1235. *** 0.9.5/Ports/mac/cursor.c    Tue Feb 19 10:46:44 1991
  1236. --- stdwin/Ports/mac/cursor.c    Tue Mar 26 10:37:15 1991
  1237. ***************
  1238. *** 31,43 ****
  1239.               h = GetCursor(plusCursor);
  1240.           else if (strcmp(name, "watch") == 0)
  1241.               h = GetCursor(watchCursor);
  1242.           else if (strcmp(name, "arrow") == 0) {
  1243. !             /* The arrow is not a resource but a quickdraw global.
  1244. !                Fake a handle with a static variable. */
  1245.               static CursPtr arrowptr;
  1246.               arrowptr = &QD(arrow);
  1247.               h = &arrowptr;
  1248.           }
  1249.           else if (strcmp(name, "hand") == 0) {
  1250.               /* The hand is hardcoded below */
  1251.               h = &handcursorptr;
  1252. --- 31,46 ----
  1253.               h = GetCursor(plusCursor);
  1254.           else if (strcmp(name, "watch") == 0)
  1255.               h = GetCursor(watchCursor);
  1256. + #if 0
  1257.           else if (strcmp(name, "arrow") == 0) {
  1258. !             /* The arrow is only a quickdraw global,
  1259. !                which we can't use.
  1260. !                Should have it as a static variable... */
  1261.               static CursPtr arrowptr;
  1262.               arrowptr = &QD(arrow);
  1263.               h = &arrowptr;
  1264.           }
  1265. + #endif
  1266.           else if (strcmp(name, "hand") == 0) {
  1267.               /* The hand is hardcoded below */
  1268.               h = &handcursorptr;
  1269. ***************
  1270. *** 63,69 ****
  1271.   void
  1272.   set_arrow()
  1273.   {
  1274. - /*XXX    SetCursor(&QD(arrow)); */
  1275.       InitCursor();
  1276.   }
  1277.   
  1278. --- 66,71 ----
  1279. *** 0.9.5/Ports/mac/dialog.c    Wed Nov  7 23:35:19 1990
  1280. --- stdwin/Ports/mac/dialog.c    Tue Mar 26 11:09:12 1991
  1281. ***************
  1282. *** 60,65 ****
  1283. --- 60,69 ----
  1284.               def= buf;
  1285.           SFPutFile(PASSPOINT corner, PSTRING(prompt),
  1286.   #ifdef THINK_C /* XXX ??? */
  1287. + /* XXX I think PSTRING returns a pointer to a static buffer
  1288. +    so there can be only one call to PSTRING in an arg list.
  1289. +    Maybe I forgot that when I found this code didn't work.
  1290. +    Should fix it better! */
  1291.               CtoPstr(def),
  1292.   #else
  1293.               PSTRING(def),
  1294. *** 0.9.5/Ports/mac/draw.c    Tue Feb 19 10:46:48 1991
  1295. --- stdwin/Ports/mac/draw.c    Sun Apr  7 16:56:25 1991
  1296. ***************
  1297. *** 8,14 ****
  1298.      text measuring;
  1299.      text drawing;
  1300.      coordinate conversion tools;
  1301. !    ordinary drawing.
  1302.      
  1303.      XXX Should be split, only things used between w{begin,end}drawing
  1304.      belong here.
  1305. --- 8,15 ----
  1306.      text measuring;
  1307.      text drawing;
  1308.      coordinate conversion tools;
  1309. !    ordinary drawing;
  1310. !    color stuff.
  1311.      
  1312.      XXX Should be split, only things used between w{begin,end}drawing
  1313.      belong here.
  1314. ***************
  1315. *** 33,38 ****
  1316. --- 34,43 ----
  1317.   #include <Fonts.h>
  1318.   #endif
  1319.   
  1320. + COLOR _w_fgcolor = blackColor;
  1321. + COLOR _w_bgcolor = whiteColor;
  1322. + static COLOR save_fgcolor, save_bgcolor;
  1323.   static WINDOW *drawing;
  1324.   static TEXTATTR drawsaveattr;
  1325.   static int baseline;
  1326. ***************
  1327. *** 44,49 ****
  1328. --- 49,62 ----
  1329.   STATIC void setwattr _ARGS((TEXTATTR *attr));
  1330.   STATIC void getfinfo _ARGS((void));
  1331.   
  1332. + /* Patterns -- can't use the QuickDraw globals (sigh) */
  1333. + static Pattern pat0   = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  1334. + static Pattern pat25  = {0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44};
  1335. + static Pattern pat50  = {0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa};
  1336. + static Pattern pat75  = {0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd};
  1337. + static Pattern pat100 = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  1338.   void
  1339.   wchange(win, left, top, right, bottom)
  1340.       WINDOW *win;
  1341. ***************
  1342. *** 110,116 ****
  1343. --- 123,135 ----
  1344.           DisposeRgn(ur);
  1345.       }
  1346.       
  1347. +     /* ScrollRect seems to work only in normal mode */
  1348. +     ForeColor(blackColor);
  1349. +     BackColor(whiteColor);
  1350.       ScrollRect(pr, dh, dv, rgn);
  1351. +     ForeColor((short)win->fgcolor);
  1352. +     BackColor((short)win->bgcolor);
  1353. +     
  1354.       InvalRgn(rgn);
  1355.       
  1356.       DisposeRgn(rgn);
  1357. ***************
  1358. *** 131,137 ****
  1359.       rmcaret(win);
  1360.       BeginUpdate(win->w);
  1361.       EraseRect(&win->w->portRect);
  1362. !     DrawGrowIcon(win->w);
  1363.       DrawControls(win->w);
  1364.       getwinrect(win, pr);
  1365.       RectRgn(rgn, pr);
  1366. --- 150,156 ----
  1367.       rmcaret(win);
  1368.       BeginUpdate(win->w);
  1369.       EraseRect(&win->w->portRect);
  1370. !     _wgrowicon(win);
  1371.       DrawControls(win->w);
  1372.       getwinrect(win, pr);
  1373.       RectRgn(rgn, pr);
  1374. ***************
  1375. *** 184,189 ****
  1376. --- 203,215 ----
  1377.       PenNormal();
  1378.       wgettextattr(&drawsaveattr);
  1379.       wsettextattr(&win->attr);
  1380. +     
  1381. +     save_fgcolor = _w_fgcolor;
  1382. +     save_bgcolor = _w_bgcolor;
  1383. +     _w_fgcolor = win->fgcolor;
  1384. +     _w_bgcolor = win->bgcolor;
  1385. +     _w_usefgcolor(_w_fgcolor);
  1386. +     _w_usebgcolor(_w_bgcolor);
  1387.   }
  1388.   
  1389.   void
  1390. ***************
  1391. *** 200,205 ****
  1392. --- 226,237 ----
  1393.           dprintf("warning: wenddrawing ignored for wrong window");
  1394.           return;
  1395.       }
  1396. +     
  1397. +     _w_fgcolor = save_fgcolor;
  1398. +     _w_bgcolor = save_bgcolor;
  1399. +     _w_usefgcolor(win->fgcolor);
  1400. +     _w_usebgcolor(win->bgcolor);
  1401. +     
  1402.       SetOrigin(0, 0);
  1403.       SetRect(&r, -32000, -32000, 32000, 32000);
  1404.       ClipRect(&r);
  1405. ***************
  1406. *** 509,516 ****
  1407.       Rect *pr;
  1408.   {
  1409.       *pr= win->w->portRect;
  1410. !     pr->right -= BAR;
  1411. !     pr->bottom -= BAR;
  1412.   }
  1413.   
  1414.   /* ACTUAL DRAW ROUTINES. */
  1415. --- 541,550 ----
  1416.       Rect *pr;
  1417.   {
  1418.       *pr= win->w->portRect;
  1419. !     if (win->vbar != NULL)
  1420. !         pr->right -= BAR;
  1421. !     if (win->hbar != NULL)
  1422. !         pr->bottom -= BAR;
  1423.   }
  1424.   
  1425.   /* ACTUAL DRAW ROUTINES. */
  1426. ***************
  1427. *** 568,574 ****
  1428.       Rect r;
  1429.       
  1430.       SetRect(&r, left, top, right, bottom);
  1431. !     FillRect(&r, QD(black));
  1432.   }
  1433.   
  1434.   void
  1435. --- 602,608 ----
  1436.       Rect r;
  1437.       
  1438.       SetRect(&r, left, top, right, bottom);
  1439. !     FillRect(&r, drawing->w->pnPat);
  1440.   }
  1441.   
  1442.   void
  1443. ***************
  1444. *** 577,593 ****
  1445.       int perc;
  1446.   {
  1447.       Rect r;
  1448. !     unsigned char *p; /* really Pattern * or PatPtr */
  1449.       
  1450.       perc= (perc + 12)/25;
  1451.       CLIPMIN(perc, 0);
  1452.       
  1453.       switch (perc) {
  1454. !     case 0:    p= &QD(white)[0];    break;
  1455. !     case 1: p= &QD(ltGray)[0];    break;
  1456. !     case 2: p= &QD(gray)[0];     break;
  1457. !     case 3: p= &QD(dkGray)[0];    break;
  1458. !     default: p= &QD(black)[0];    break;
  1459.       }
  1460.       
  1461.       SetRect(&r, left, top, right, bottom);
  1462. --- 611,627 ----
  1463.       int perc;
  1464.   {
  1465.       Rect r;
  1466. !     PatPtr p;
  1467.       
  1468.       perc= (perc + 12)/25;
  1469.       CLIPMIN(perc, 0);
  1470.       
  1471.       switch (perc) {
  1472. !     case 0:    p = &pat0;    break;
  1473. !     case 1: p = &pat25;    break;
  1474. !     case 2: p = &pat50;     break;
  1475. !     case 3: p = &pat75;    break;
  1476. !     default: p = &pat100;    break;
  1477.       }
  1478.       
  1479.       SetRect(&r, left, top, right, bottom);
  1480. ***************
  1481. *** 602,608 ****
  1482.   {
  1483.       Rect r;
  1484.       
  1485. -     /* XXX Isn't there an off-by-one error here? */
  1486.       SetRect(&r, h-radius, v-radius, h+radius, v+radius);
  1487.       FrameOval(&r);
  1488.   }
  1489. --- 636,641 ----
  1490. ***************
  1491. *** 615,623 ****
  1492.   wdrawelarc(h, v, hrad, vrad, ang1, ang2)
  1493.   {
  1494.       Rect r;
  1495. -     /* XXX Does this work? No off-by-one errors? */
  1496.       SetRect(&r, h-hrad, v-vrad, h+hrad, v+vrad);
  1497. !     FrameArc(&r, 90-ang1, ang1-ang2); /* ??? */
  1498.   }
  1499.   
  1500.   /* CLIPPING */
  1501. --- 648,655 ----
  1502.   wdrawelarc(h, v, hrad, vrad, ang1, ang2)
  1503.   {
  1504.       Rect r;
  1505.       SetRect(&r, h-hrad, v-vrad, h+hrad, v+vrad);
  1506. !     FrameArc(&r, 90-ang1, ang1-ang2);
  1507.   }
  1508.   
  1509.   /* CLIPPING */
  1510. ***************
  1511. *** 640,643 ****
  1512. --- 672,738 ----
  1513.       Rect r;
  1514.       getwinrect(drawing, &r);
  1515.       ClipRect(&r);
  1516. + }
  1517. + /* COLOR */
  1518. + COLOR
  1519. + wgetfgcolor()
  1520. + {
  1521. +     return _w_fgcolor;
  1522. + }
  1523. + COLOR
  1524. + wgetbgcolor()
  1525. + {
  1526. +     return _w_bgcolor;
  1527. + }
  1528. + void
  1529. + wsetfgcolor(color)
  1530. +     COLOR color;
  1531. + {
  1532. +     _w_fgcolor = color;
  1533. +     if (drawing)
  1534. +         _w_usefgcolor(color);
  1535. + }
  1536. + void
  1537. + wsetbgcolor(color)
  1538. +     COLOR color;
  1539. + {
  1540. +     _w_bgcolor = color;
  1541. +     if (drawing)
  1542. +         _w_usebgcolor(color);
  1543. + }
  1544. + void
  1545. + _w_usefgcolor(color)
  1546. +     COLOR color;
  1547. + {
  1548. +     ForeColor((short)color);
  1549. +     switch (((color >> 16) + 32) / 64) {
  1550. +     case 0:
  1551. +         PenPat(pat100);
  1552. +         break;
  1553. +     case 1:
  1554. +         PenPat(pat75);
  1555. +         break;
  1556. +     case 2:
  1557. +         PenPat(pat50);
  1558. +         break;
  1559. +     case 3:
  1560. +         PenPat(pat25);
  1561. +         break;
  1562. +     case 4:
  1563. +         PenPat(pat0);
  1564. +         break;
  1565. +     }
  1566. + }
  1567. + void
  1568. + _w_usebgcolor(color)
  1569. +     COLOR color;
  1570. + {
  1571. +     BackColor((short)color);
  1572.   }
  1573. *** 0.9.5/Ports/mac/event.c    Tue Feb 19 10:46:53 1991
  1574. --- stdwin/Ports/mac/event.c    Tue May 28 22:23:56 1991
  1575. ***************
  1576. *** 9,15 ****
  1577. --- 9,18 ----
  1578.   #endif
  1579.   #ifdef THINK_C
  1580.   #include <EventMgr.h>
  1581. + #ifndef THINK_C_3_0
  1582. + #include <console.h> /* See do_update */
  1583.   #endif
  1584. + #endif
  1585.   
  1586.   void (*_w_idle_proc)();    /* Function to call in idle loop */
  1587.   
  1588. ***************
  1589. *** 83,88 ****
  1590. --- 86,99 ----
  1591.       
  1592.       if (active == NULL)
  1593.           set_arrow();
  1594. +     else if (active->w != FrontWindow()) {
  1595. +         /* Somehow we missed a deactivation event.
  1596. +            Fake one now. */
  1597. +         ep->type= WE_DEACTIVATE;
  1598. +         ep->window= active;
  1599. +         deactivate();
  1600. +         return;
  1601. +     }
  1602.       
  1603.       ep->type= WE_NULL;
  1604.       ep->window= NULL;
  1605. ***************
  1606. *** 206,212 ****
  1607.       
  1608.       win= whichwin((WindowPtr) e.message);
  1609.       if (win == NULL) {
  1610. !         /* dprintf("update evt for alien window"); */
  1611.           return;
  1612.       }
  1613.       _wupdate(win, &r);
  1614. --- 217,239 ----
  1615.       
  1616.       win= whichwin((WindowPtr) e.message);
  1617.       if (win == NULL) {
  1618. !         /* Update event for a window not created by STDWIN
  1619. !            (not a Desk Accessory -- these are taken care of
  1620. !            by GetNextEvent or at some other secret place.)
  1621. !            This is is problem: if we ignore it, it will come
  1622. !            back forever, so we'll never be idle again. */
  1623. ! #ifdef THINK_C
  1624. ! #ifndef THINK_C_3_0
  1625. !         /* Most likely, under THINK C 4.0, it is the console
  1626. !            window.  We can force the window to repaint itself
  1627. !            by calling any console function.  A rather harmless
  1628. !            one is cgetxy.  Use stderr as the one least likely
  1629. !            to be redirected. */
  1630. !         int x, y;
  1631. !         if (stderr->window)
  1632. !             cgetxy(&x, &y, stderr);
  1633. ! #endif
  1634. ! #endif
  1635.           return;
  1636.       }
  1637.       _wupdate(win, &r);
  1638. ***************
  1639. *** 227,239 ****
  1640.       WindowPtr w;
  1641.       int code= FindWindow(PASSPOINT e.where, &w);
  1642.       
  1643. -     /* XXX This doesn't look incredibly necessary:
  1644. -     if (active != NULL) {
  1645. -         SetPort(active->win);
  1646. -         rmcaret(active);
  1647. -     }
  1648. -     */
  1649. -     
  1650.       if (code != inContent && code != inSysWindow)
  1651.           set_arrow();
  1652.       switch (code) {
  1653. --- 254,259 ----
  1654. ***************
  1655. *** 273,289 ****
  1656.   do_key(ep)
  1657.       EVENT *ep;
  1658.   {
  1659. !     char c= e.message & charCodeMask;
  1660.       
  1661. -     /* XXX shouldn't mess at all with non-stdwin windows */
  1662. -     
  1663.       if (e.modifiers & cmdKey) {
  1664.           if (c == '.') {
  1665.               ep->type= WE_COMMAND;
  1666.               ep->u.command= WC_CANCEL;
  1667.           }
  1668. !         else
  1669. !             _wdo_menu(ep, MenuKey(c));
  1670.       }
  1671.       else {
  1672.           ep->type= WE_COMMAND;
  1673. --- 293,317 ----
  1674.   do_key(ep)
  1675.       EVENT *ep;
  1676.   {
  1677. !     int c= e.message & charCodeMask;
  1678.       
  1679.       if (e.modifiers & cmdKey) {
  1680.           if (c == '.') {
  1681.               ep->type= WE_COMMAND;
  1682.               ep->u.command= WC_CANCEL;
  1683.           }
  1684. !         else {
  1685. !             long menu_item= MenuKey(c);
  1686. !             if (HiWord(menu_item) != 0) {
  1687. !                 _wdo_menu(ep, menu_item);
  1688. !             }
  1689. !             else {
  1690. !                 ep->type= WE_KEY;
  1691. !                 ep->u.key.code= c;
  1692. !                 ep->u.key.mask= WM_META;
  1693. !                 /* Should filter out arrow keys? */
  1694. !             }
  1695. !         }
  1696.       }
  1697.       else {
  1698.           ep->type= WE_COMMAND;
  1699. ***************
  1700. *** 350,356 ****
  1701.                   return;
  1702.               /* If we get here we've missed a
  1703.                  deactivate event... */
  1704. !             dprintf("activate without deactivate");
  1705.   #endif
  1706.           }
  1707.           activate(win);
  1708. --- 378,384 ----
  1709.                   return;
  1710.               /* If we get here we've missed a
  1711.                  deactivate event... */
  1712. !             /* dprintf("activate without deactivate"); */
  1713.   #endif
  1714.           }
  1715.           activate(win);
  1716. ***************
  1717. *** 381,387 ****
  1718.       rmcaret(active);
  1719.       hidescrollbars(active);
  1720.       rmlocalmenus(active);
  1721. !     DrawGrowIcon(active->w);
  1722.       active= NULL;
  1723.       set_arrow();
  1724.   }
  1725. --- 409,415 ----
  1726.       rmcaret(active);
  1727.       hidescrollbars(active);
  1728.       rmlocalmenus(active);
  1729. !     _wgrowicon(active);
  1730.       active= NULL;
  1731.       set_arrow();
  1732.   }
  1733. ***************
  1734. *** 492,524 ****
  1735.   {
  1736.       Rect r;
  1737.       long reply;
  1738.       
  1739. !     /* XXX shouldn't mess at all with non-stdwin windows */
  1740.       
  1741. !     /* Set minimal window size */
  1742. !     r.left= LSLOP + MIN_WIDTH + RSLOP + BAR;
  1743. !     r.top= MIN_HEIGHT + BAR;
  1744.       
  1745. !     /* The max size is derived from the document size.
  1746. !        If there is no document size, it is unlimited.
  1747. !        (There is nothing wrong with windows larger than
  1748. !        the screen, really.) */
  1749. !     r.right = r.bottom = 0x7fff;
  1750. !     {
  1751. !         /* Max size restriction based on doc size, if specified */
  1752. !         WINDOW *win = whichwin(w);
  1753. !         int docwidth = win->docwidth;
  1754. !         int docheight = win->docheight;
  1755. !         if (win->docwidth > 0) {
  1756. !             CLIPMIN(docwidth, MIN_WIDTH);
  1757. !             r.right = LSLOP + docwidth + RSLOP + BAR + 1;
  1758. !         }
  1759. !         if (win->docheight > 0) {
  1760. !             CLIPMIN(docheight, MIN_HEIGHT);
  1761. !             r.bottom = docheight + BAR + 1;
  1762. !         }
  1763. !         /* For some reason 1 has to be added.  Sigh. */
  1764. !     }
  1765.       
  1766.       reply= GrowWindow(w, PASSPOINT e.where, &r);
  1767.       if (reply != 0) {
  1768. --- 520,548 ----
  1769.   {
  1770.       Rect r;
  1771.       long reply;
  1772. +     WINDOW *win = whichwin(w);
  1773.       
  1774. !     /* Don't mess at all with non-stdwin windows */
  1775. !     if (win == NULL)
  1776. !         return;
  1777.       
  1778. !     /* Set minimal window size --
  1779. !       1x1 at least, plus space needed for scroll bars */
  1780. !     r.left = LSLOP + 1 + RSLOP;
  1781. !     r.top = 1;
  1782. !     if (win->hbar != NULL)
  1783. !         r.left = 3*BAR;
  1784. !     if (win->vbar != NULL)
  1785. !         r.top = 3*BAR;
  1786. !     if (win->vbar != NULL)
  1787. !         r.left += BAR;
  1788. !     if (win->hbar != NULL)
  1789. !         r.top += BAR;
  1790.       
  1791. !     /* Windows may become as large as the user can get them,
  1792. !        within reason -- the limit 0x7000 should avoid integer
  1793. !        overflow in QuickDraw. */
  1794. !     r.right = r.bottom = 0x7000;
  1795.       
  1796.       reply= GrowWindow(w, PASSPOINT e.where, &r);
  1797.       if (reply != 0) {
  1798. ***************
  1799. *** 537,545 ****
  1800.       /* XXX shouldn't mess at all with non-stdwin windows */
  1801.       
  1802.       if (TrackGoAway(w, PASSPOINT e.where)) {
  1803. !         ep->type= WE_COMMAND;
  1804.           ep->window= whichwin(w);
  1805. -         ep->u.command= WC_CLOSE;
  1806.       }
  1807.   }
  1808.   
  1809. --- 561,568 ----
  1810.       /* XXX shouldn't mess at all with non-stdwin windows */
  1811.       
  1812.       if (TrackGoAway(w, PASSPOINT e.where)) {
  1813. !         ep->type= WE_CLOSE;
  1814.           ep->window= whichwin(w);
  1815.       }
  1816.   }
  1817.   
  1818. ***************
  1819. *** 596,608 ****
  1820.       WindowPtr w;
  1821.   {
  1822.       Rect r;
  1823.       
  1824. !     r= w->portRect;
  1825. !     r.left= r.right - BAR;
  1826. !     InvalRect(&r);
  1827. !     r= w->portRect;
  1828. !     r.top= r.bottom - BAR;
  1829. !     InvalRect(&r);
  1830.   }
  1831.   
  1832.   void
  1833. --- 619,636 ----
  1834.       WindowPtr w;
  1835.   {
  1836.       Rect r;
  1837. +     WINDOW *win = whichwin(w);
  1838.       
  1839. !     if (win->vbar != NULL) {
  1840. !         r = w->portRect;
  1841. !         r.left = r.right - BAR;
  1842. !         InvalRect(&r);
  1843. !     }
  1844. !     if (win->hbar != NULL) {
  1845. !         r = w->portRect;
  1846. !         r.top = r.bottom - BAR;
  1847. !         InvalRect(&r);
  1848. !     }
  1849.   }
  1850.   
  1851.   void
  1852. ***************
  1853. *** 610,622 ****
  1854.       WindowPtr w;
  1855.   {
  1856.       Rect r;
  1857.       
  1858. !     r= w->portRect;
  1859. !     r.left= r.right - BAR;
  1860. !     ValidRect(&r);
  1861. !     r= w->portRect;
  1862. !     r.top= r.bottom - BAR;
  1863. !     ValidRect(&r);
  1864.   }
  1865.   
  1866.   /* Variables needed in click and move detection. */
  1867. --- 638,655 ----
  1868.       WindowPtr w;
  1869.   {
  1870.       Rect r;
  1871. +     WINDOW *win = whichwin(w);
  1872.       
  1873. !     if (win->vbar != NULL) {
  1874. !         r = w->portRect;
  1875. !         r.left = r.right - BAR;
  1876. !         ValidRect(&r);
  1877. !     }
  1878. !     if (win->hbar != NULL) {
  1879. !         r = w->portRect;
  1880. !         r.top = r.bottom - BAR;
  1881. !         ValidRect(&r);
  1882. !     }
  1883.   }
  1884.   
  1885.   /* Variables needed in click and move detection. */
  1886. ***************
  1887. *** 624,631 ****
  1888.   static int m_h, m_v;        /* Doc. coord. of last mouse evt. */
  1889.   static long m_when;        /* TickCount of last mouse evt. */
  1890.   static int m_clicks;        /* N-fold click stage */
  1891. - static int m_button;        /* Which 'button';
  1892. -                    1=normal, 2=shift, 3=command. */
  1893.   
  1894.   static void
  1895.   make_mouse_event(ep, pwhere)
  1896. --- 657,662 ----
  1897. ***************
  1898. *** 637,644 ****
  1899.       int v= pwhere->v + win->orgv;
  1900.       int dh= h - m_h;
  1901.       int dv= v - m_v;
  1902.       
  1903. !     if (dh*dh + dv*dv > CLICK_DIST*CLICK_DIST)
  1904.           m_clicks= 0;    /* Moved too much for a click */
  1905.       
  1906.       if (e.what == mouseDown) {
  1907. --- 668,676 ----
  1908.       int v= pwhere->v + win->orgv;
  1909.       int dh= h - m_h;
  1910.       int dv= v - m_v;
  1911. +     int mask;
  1912.       
  1913. !     if (m_clicks != 0 && dh*dh + dv*dv > CLICK_DIST*CLICK_DIST)
  1914.           m_clicks= 0;    /* Moved too much for a click */
  1915.       
  1916.       if (e.what == mouseDown) {
  1917. ***************
  1918. *** 648,657 ****
  1919.               ++m_clicks;
  1920.           ep->type= WE_MOUSE_DOWN;
  1921.           _wm_down= TRUE;
  1922. -         /* XXX Should swap buttons 2 & 3 (also in textedit)
  1923. -            since X11 (e.g., xterm) uses button 3 for extend */
  1924. -         m_button= (e.modifiers & cmdKey) ? 3 :
  1925. -             (e.modifiers & shiftKey) ? 2 : 1;
  1926.       }
  1927.       else if (e.what == mouseUp) {
  1928.           if (!_wm_down)
  1929. --- 680,685 ----
  1930. ***************
  1931. *** 664,674 ****
  1932.               return;
  1933.           ep->type= WE_MOUSE_MOVE;
  1934.       }
  1935.       ep->u.where.h= m_h= h;
  1936.       ep->u.where.v= m_v= v;
  1937.       ep->u.where.clicks= m_clicks;
  1938. !     ep->u.where.button= m_button;
  1939. !     ep->u.where.mask= (ep->type == WE_MOUSE_UP) ? 0 : 1;
  1940.       ep->window= win;
  1941.       m_when= e.when;
  1942.   }
  1943. --- 692,713 ----
  1944.               return;
  1945.           ep->type= WE_MOUSE_MOVE;
  1946.       }
  1947. +     mask= (ep->type == WE_MOUSE_UP) ? 0 : WM_BUTTON1;
  1948. +     if (e.modifiers & cmdKey)
  1949. +         mask |= WM_META;
  1950. +     if (e.modifiers & shiftKey)
  1951. +         mask |= WM_SHIFT;
  1952. +     if (e.modifiers & alphaLock)
  1953. +         mask |= WM_LOCK;
  1954. +     if (e.modifiers & optionKey)
  1955. +         mask |= WM_OPTION;
  1956. +     if (e.modifiers & controlKey)
  1957. +         mask |= WM_CONTROL;
  1958.       ep->u.where.h= m_h= h;
  1959.       ep->u.where.v= m_v= v;
  1960.       ep->u.where.clicks= m_clicks;
  1961. !     ep->u.where.button= 1;
  1962. !     ep->u.where.mask= mask;
  1963.       ep->window= win;
  1964.       m_when= e.when;
  1965.   }
  1966. ***************
  1967. *** 680,683 ****
  1968. --- 719,735 ----
  1969.   _wresetmouse()
  1970.   {
  1971.       _wm_down= FALSE;
  1972. + }
  1973. + void
  1974. + wsetactive(win)
  1975. +     WINDOW *win;
  1976. + {
  1977. +     SelectWindow(win->w);
  1978. + }
  1979. + WINDOW *
  1980. + wgetactive()
  1981. + {
  1982. +     return whichwin(FrontWindow());
  1983.   }
  1984. *** 0.9.5/Ports/mac/macwin.h    Tue Feb 19 10:46:57 1991
  1985. --- stdwin/Ports/mac/macwin.h    Sun Apr  7 16:55:08 1991
  1986. ***************
  1987. *** 65,70 ****
  1988. --- 65,71 ----
  1989.   #define c2pstr CtoPstr    /* XXX actually, used nowhere */
  1990.   
  1991.   /* Quickdraw globals are real globals in THINK C */
  1992. + /* But don't use them, the console library breaks this!!! */
  1993.   #define QD(var) (var)
  1994.   
  1995.   /* THINK C can't declare forward functions as static */
  1996. ***************
  1997. *** 108,113 ****
  1998. --- 109,115 ----
  1999.       struct menubar mbar;    /* List of attached local menus */
  2000.       unsigned long timer;    /* Tick count for timer event */
  2001.       CURSOR *cursor;        /* Cursor if not default */
  2002. +     COLOR fgcolor, bgcolor;    /* Default colors for this window */
  2003.   };
  2004.   
  2005.   extern TEXTATTR wattr;        /* Current text attributes */
  2006. ***************
  2007. *** 135,150 ****
  2008.   
  2009.   #define CLICK_DIST    5    /* Max mouse move within a click */
  2010.   
  2011. - /* Parameters for top left corner choice algorithm: */
  2012. - #define LEFT    20    /* Initial left */
  2013. - #define TOP    40    /* Initial top */
  2014. - #define HINCR    20    /* Increment for left */
  2015. - #define VINCR    16    /* Increment for top */
  2016. - /* Minimal window size (determined by room for scroll bars only): */
  2017. - #define MIN_WIDTH    (2*BAR)
  2018. - #define MIN_HEIGHT    (2*BAR)
  2019.   /* Text drawn in the very left or right margin doesn't look nice.
  2020.      Therefore, we have a little margin on each side.
  2021.      Its width is determined here: */
  2022. --- 137,142 ----
  2023. ***************
  2024. *** 156,161 ****
  2025. --- 148,155 ----
  2026.   extern WINDOW *active;        /* Active window, if any */
  2027.   extern bool _wmenuhilite;    /* Set if menu item highlighted */
  2028.   extern bool _wm_down;        /* Set if mouse down (in appl. area) */
  2029. + extern COLOR _w_fgcolor;    /* Current foreground color */
  2030. + extern COLOR _w_bgcolor;    /* Current background color */
  2031.   
  2032.   /* Function prototypes: */
  2033.   
  2034. ***************
  2035. *** 175,184 ****
  2036.   void set_ibeam _ARGS((void));
  2037.   void set_hand _ARGS((void));
  2038.   
  2039. ! void makescrollbars _ARGS((WINDOW *win));
  2040.   void movescrollbars _ARGS((WINDOW *win));
  2041.   void hidescrollbars _ARGS((WINDOW *win));
  2042.   void showscrollbars _ARGS((WINDOW *win));
  2043.   
  2044.   void scrollby _ARGS((WINDOW *win, Rect *pr, int dh, int dv));
  2045.   void do_scroll _ARGS((Point *pwhere,
  2046. --- 169,180 ----
  2047.   void set_ibeam _ARGS((void));
  2048.   void set_hand _ARGS((void));
  2049.   
  2050. ! void makescrollbars _ARGS((WINDOW *win, /*bool*/int hor, /*bool*/int ver));
  2051.   void movescrollbars _ARGS((WINDOW *win));
  2052.   void hidescrollbars _ARGS((WINDOW *win));
  2053.   void showscrollbars _ARGS((WINDOW *win));
  2054. + void _wgrowicon _ARGS((WINDOW *win));
  2055. + void _wfixorigin _ARGS((WINDOW *));
  2056.   
  2057.   void scrollby _ARGS((WINDOW *win, Rect *pr, int dh, int dv));
  2058.   void do_scroll _ARGS((Point *pwhere,
  2059. ***************
  2060. *** 211,216 ****
  2061. --- 207,215 ----
  2062.   bool checktimer _ARGS((EVENT *ep));
  2063.   void autoscroll _ARGS((WINDOW *active, int h, int v));
  2064.   void _wdo_menu _ARGS((EVENT *ep, long menu_item));
  2065. + void _w_usefgcolor _ARGS((COLOR color));
  2066. + void _w_usebgcolor _ARGS((COLOR color));
  2067.   
  2068.   /* SetRect is much faster this way... */
  2069.   #define SetRect(pr, l, t, r, b) ((pr)->left = (l), (pr)->top = (t), \
  2070. *** 0.9.5/Ports/mac/pstring.c    Wed Nov  7 23:31:34 1990
  2071. --- stdwin/Ports/mac/pstring.c    Tue Mar 26 11:11:41 1991
  2072. ***************
  2073. *** 18,24 ****
  2074.       dst = &buf[1];
  2075.       while ((*dst++ = *src++) != '\0' && dst < &buf[256])
  2076.           ;
  2077. !     buf[0] = dst - &buf[1];
  2078.       return buf;
  2079.   }
  2080.   
  2081. --- 18,24 ----
  2082.       dst = &buf[1];
  2083.       while ((*dst++ = *src++) != '\0' && dst < &buf[256])
  2084.           ;
  2085. !     buf[0] = dst - &buf[1] - 1; /* XXX Recent bugfix! */
  2086.       return buf;
  2087.   }
  2088.   
  2089. *** 0.9.5/Ports/mac/scroll.c    Wed Nov  7 23:37:48 1990
  2090. --- stdwin/Ports/mac/scroll.c    Tue Mar 26 11:15:02 1991
  2091. ***************
  2092. *** 1,3 ****
  2093. --- 1,9 ----
  2094. + /*
  2095. + This code is somehow broken.
  2096. + If I click a few times on an arrow of the scroll bar the cursor freezes.
  2097. + Other forms of scrolling don't have this problem.  WHAT'S WRONG?!?!?!
  2098. + */
  2099.   /* MAC STDWIN -- SCROLLING. */
  2100.   
  2101.   /* All non-public functions here assume the current grafport is set */
  2102. ***************
  2103. *** 25,30 ****
  2104. --- 31,37 ----
  2105.   STATIC void setscrollbarvalues _ARGS((WINDOW *win));
  2106.   STATIC void usescrollbarvalues _ARGS((WINDOW *win));
  2107.   STATIC void sizescrollbars _ARGS((WINDOW *win));
  2108. + STATIC int calcneworigin _ARGS((int, int, int, int, int));
  2109.   STATIC void calcbar _ARGS((ControlHandle bar,
  2110.       int org, int size, int begin, int end));
  2111.   STATIC void setbar _ARGS((ControlHandle bar, int winsize, int val, int max));
  2112. ***************
  2113. *** 33,38 ****
  2114. --- 40,46 ----
  2115.   STATIC void hidebar _ARGS((ControlHandle bar));
  2116.   STATIC void movebar _ARGS((ControlHandle bar,
  2117.       int left, int top, int right, int bottom));
  2118. + void _wfixorigin _ARGS((WINDOW *));
  2119.   
  2120.   void
  2121.   wsetorigin(win, orgh, orgv)
  2122. ***************
  2123. *** 187,211 ****
  2124.               *((WindowPeek)(win->w))->dataHandle;
  2125.           if (data != NULL) {
  2126.               if (docwidth > 0) {
  2127. -                 CLIPMIN(docwidth, MIN_WIDTH);
  2128.                   data->stdState.right =
  2129.                       data->stdState.left
  2130. !                     + LSLOP + docwidth + RSLOP + BAR;
  2131.               }
  2132.               else
  2133.                   data->stdState.right = 0x7fff;
  2134.               CLIPMAX(data->stdState.right,
  2135.                   screen->portRect.right-3);
  2136.               if (docheight > 0) {
  2137. -                 CLIPMIN(docheight, MIN_HEIGHT);
  2138.                   data->stdState.bottom =
  2139. !                     data->stdState.top
  2140. !                     + docheight + BAR;
  2141.               }
  2142.               else
  2143.                   data->stdState.bottom = 0x7fff;
  2144.               CLIPMAX(data->stdState.bottom,
  2145.                   screen->portRect.bottom-3);
  2146.           }
  2147.       }
  2148.   }
  2149. --- 195,226 ----
  2150.               *((WindowPeek)(win->w))->dataHandle;
  2151.           if (data != NULL) {
  2152.               if (docwidth > 0) {
  2153.                   data->stdState.right =
  2154.                       data->stdState.left
  2155. !                     + LSLOP + docwidth + RSLOP;
  2156. !                 if (win->vbar != NULL)
  2157. !                     data->stdState.right += BAR;
  2158.               }
  2159.               else
  2160.                   data->stdState.right = 0x7fff;
  2161.               CLIPMAX(data->stdState.right,
  2162.                   screen->portRect.right-3);
  2163. +             if (win->hbar != NULL) {
  2164. +                 CLIPMIN(data->stdState.right, 5*BAR);
  2165. +             }
  2166.               if (docheight > 0) {
  2167.                   data->stdState.bottom =
  2168. !                     data->stdState.top + docheight;
  2169. !                 if (win->hbar != NULL)
  2170. !                     data->stdState.bottom += BAR;
  2171.               }
  2172.               else
  2173.                   data->stdState.bottom = 0x7fff;
  2174.               CLIPMAX(data->stdState.bottom,
  2175.                   screen->portRect.bottom-3);
  2176. +             if (win->vbar != NULL) {
  2177. +                 CLIPMIN(data->stdState.bottom, 5*BAR);
  2178. +             }
  2179.           }
  2180.       }
  2181.   }
  2182. ***************
  2183. *** 222,227 ****
  2184. --- 237,243 ----
  2185.   /* Fix the window's origin after a document or window resize.
  2186.      (Also used from do_size() in event.c) */
  2187.   
  2188. + void
  2189.   _wfixorigin(win)
  2190.       WINDOW *win;
  2191.   {
  2192. ***************
  2193. *** 267,272 ****
  2194. --- 283,291 ----
  2195.       ProcPtr action;
  2196.       int width, height;
  2197.       
  2198. +     if (bar == NULL)
  2199. +         return;
  2200. +     
  2201.       wgetwinsize(win, &width, &height);
  2202.       
  2203.       if (bar == win->hbar) {
  2204. ***************
  2205. *** 306,311 ****
  2206. --- 325,332 ----
  2207.       deadline= 0;
  2208.       if (TrackControl(bar, PASSPOINT *pwhere, action) == inThumb)
  2209.           usescrollbarvalues(win);
  2210. +     
  2211. +     SetPort(win->w); /*  THIS IS NEEDED!!! */
  2212.   }
  2213.   
  2214.   static pascal
  2215. ***************
  2216. *** 315,321 ****
  2217.   {
  2218.       long now= TickCount();
  2219.       if (now >= deadline && pcode != 0) {
  2220. !         deltabar(bar, scrollstep);
  2221.           usescrollbarvalues(scrollwin);
  2222.           wupdate(scrollwin);
  2223.           if (deadline == 0 && KeyThresh > KeyRepThresh)
  2224. --- 336,342 ----
  2225.   {
  2226.       long now= TickCount();
  2227.       if (now >= deadline && pcode != 0) {
  2228. !          deltabar(bar, scrollstep);
  2229.           usescrollbarvalues(scrollwin);
  2230.           wupdate(scrollwin);
  2231.           if (deadline == 0 && KeyThresh > KeyRepThresh)
  2232. ***************
  2233. *** 391,399 ****
  2234.       }
  2235.   }
  2236.   
  2237.   void
  2238. ! makescrollbars(win)
  2239.       WINDOW *win;
  2240.   {
  2241.       Rect r;
  2242.       int id= scrollBarProc;
  2243. --- 412,431 ----
  2244.       }
  2245.   }
  2246.   
  2247. + #ifdef JURJENBARPROC
  2248. + static int cdefexists _ARGS((int));
  2249. + static int
  2250. + cdefexists(id)
  2251. +     int id;
  2252. + {
  2253. +     return GetResource('CDEF', id/16) != NULL;
  2254. + }
  2255. + #endif
  2256.   void
  2257. ! makescrollbars(win, hor, ver)
  2258.       WINDOW *win;
  2259. +     /*bool*/int hor, ver;
  2260.   {
  2261.       Rect r;
  2262.       int id= scrollBarProc;
  2263. ***************
  2264. *** 412,438 ****
  2265.   #endif JURJENBARPROC
  2266.   
  2267.       SetRect(&r, 0, 0, 1, 1); /* Dummy rectangle */
  2268. !     win->hbar= NewControl(win->w,
  2269. !         &r, "", false, 0, 0, 0, scrollBarProc, 0L);
  2270. !     win->vbar= NewControl(win->w,
  2271. !         &r, "", false, 0, 0, 0, id, 0L);
  2272.       sizescrollbars(win);
  2273.   }
  2274.   
  2275. - #ifdef JURJENBARPROC
  2276. - static int
  2277. - cdefexists(id)
  2278. -     int id;
  2279. - {
  2280. -     return GetResource('CDEF', id/16) != NULL;
  2281. - }
  2282. - #endif
  2283.   void
  2284.   showscrollbars(win)
  2285.       WINDOW *win;
  2286.   {
  2287. !     DrawGrowIcon(win->w);
  2288.       showbar(win->hbar);
  2289.       showbar(win->vbar);
  2290.   }
  2291. --- 444,463 ----
  2292.   #endif JURJENBARPROC
  2293.   
  2294.       SetRect(&r, 0, 0, 1, 1); /* Dummy rectangle */
  2295. !     if (hor)
  2296. !         win->hbar= NewControl(win->w,
  2297. !             &r, "", false, 0, 0, 0, scrollBarProc, 0L);
  2298. !     if (ver)
  2299. !         win->vbar= NewControl(win->w,
  2300. !             &r, "", false, 0, 0, 0, id, 0L);
  2301.       sizescrollbars(win);
  2302.   }
  2303.   
  2304.   void
  2305.   showscrollbars(win)
  2306.       WINDOW *win;
  2307.   {
  2308. !     _wgrowicon(win);
  2309.       showbar(win->hbar);
  2310.       showbar(win->vbar);
  2311.   }
  2312. ***************
  2313. *** 460,472 ****
  2314.   {
  2315.       Rect r;
  2316.       
  2317. !     /* This should be done while the scroll bars are invisible. */
  2318.       
  2319. !     r= win->w->portRect;
  2320. !     movebar(win->vbar, r.right - BAR, r.top - 1,
  2321. !         r.right + 1, r.bottom - BAR + 1);
  2322. !     movebar(win->hbar, r.left - 1, r.bottom - BAR,
  2323. !         r.right - BAR + 1, r.bottom + 1);
  2324.       setscrollbarvalues(win);
  2325.   }
  2326.   
  2327. --- 485,506 ----
  2328.   {
  2329.       Rect r;
  2330.       
  2331. !     /* This must only be called while the scroll bars are invisible. */
  2332.       
  2333. !     r = win->w->portRect;
  2334. !     r.left = r.right - BAR;
  2335. !     r.top--;
  2336. !     r.bottom -= BAR-1;
  2337. !     r.right++;
  2338. !     movebar(win->vbar, r.left, r.top, r.right, r.bottom);
  2339. !     
  2340. !     r = win->w->portRect;
  2341. !     r.left--;
  2342. !     r.top = r.bottom - BAR;
  2343. !     r.right -= BAR-1;
  2344. !     r.bottom++;
  2345. !     movebar(win->hbar, r.left, r.top, r.right, r.bottom);
  2346. !     
  2347.       setscrollbarvalues(win);
  2348.   }
  2349.   
  2350. ***************
  2351. *** 511,516 ****
  2352. --- 545,554 ----
  2353.       int begin, end;
  2354.   {
  2355.       int range;
  2356. +     
  2357. +     if (bar == NULL)
  2358. +         return;
  2359. +     
  2360.       /* For the caller it's easier to remember to pass win->org{h,v};
  2361.          but for our calculations it's easier to have the sign reversed! */
  2362.       org= -org;
  2363. ***************
  2364. *** 526,534 ****
  2365.   usescrollbarvalues(win)
  2366.       WINDOW *win;
  2367.   {
  2368. !     wsetorigin(win,
  2369. !         GetCtlValue(win->hbar) - GetCtlMin(win->hbar),
  2370. !         GetCtlValue(win->vbar) - GetCtlMin(win->vbar));
  2371.       /* Implies setscrollbarvalues! */
  2372.   }
  2373.   
  2374. --- 564,576 ----
  2375.   usescrollbarvalues(win)
  2376.       WINDOW *win;
  2377.   {
  2378. !     int orgh = 0;
  2379. !     int orgv = 0;
  2380. !     if (win->hbar != NULL)
  2381. !         orgh = GetCtlValue(win->hbar) - GetCtlMin(win->hbar);
  2382. !     if (win->vbar != NULL)
  2383. !         orgv = GetCtlValue(win->vbar) - GetCtlMin(win->vbar);
  2384. !     wsetorigin(win, orgh, orgv);
  2385.       /* Implies setscrollbarvalues! */
  2386.   }
  2387.   
  2388. ***************
  2389. *** 557,567 ****
  2390.       ControlHandle bar;
  2391.       int delta;
  2392.   {
  2393. !     int min= GetCtlMin(bar);
  2394. !     int val= GetCtlValue(bar);
  2395. !     int max= GetCtlMax(bar);
  2396. !     int newval= val + delta;
  2397.       
  2398.       if (newval > max)
  2399.           newval= max;
  2400.       if (newval < min)
  2401. --- 599,613 ----
  2402.       ControlHandle bar;
  2403.       int delta;
  2404.   {
  2405. !     int min, val, max, newval;
  2406.       
  2407. +     if (bar == NULL)
  2408. +         return;
  2409. +     min = GetCtlMin(bar);
  2410. +     val = GetCtlValue(bar);
  2411. +     max = GetCtlMax(bar);
  2412. +     newval = val + delta;
  2413. +     
  2414.       if (newval > max)
  2415.           newval= max;
  2416.       if (newval < min)
  2417. ***************
  2418. *** 596,599 ****
  2419. --- 642,676 ----
  2420.           MoveControl(bar, left, top);
  2421.           SizeControl(bar, right-left, bottom-top);
  2422.       }
  2423. + }
  2424. + void
  2425. + _wgrowicon(win)
  2426. +     WINDOW *win;
  2427. + {
  2428. +     Rect r;
  2429. +     
  2430. +     /* If there are no scroll bars, there is no room to draw the
  2431. +        grow icon; the entire window belongs to the application.
  2432. +        However, clicks in the bottom right corner will still be
  2433. +        intercepted by the window manager. */
  2434. +     
  2435. +     if (win->hbar == NULL && win->vbar == NULL)
  2436. +         return;
  2437. +     
  2438. +     /* Clip the drawing of DrawGrowIcon to the scroll bars present. */
  2439. +     
  2440. +     r= win->w->portRect;
  2441. +     if (win->hbar == NULL)
  2442. +         r.left = r.right - BAR;
  2443. +     if (win->vbar == NULL)
  2444. +         r.top = r.bottom - BAR;
  2445. +     ClipRect(&r);
  2446. +     
  2447. +     DrawGrowIcon(win->w);
  2448. +     
  2449. +     /* Reset clipping */
  2450. +     
  2451. +     SetRect(&r, -32000, -32000, 32000, 32000);
  2452. +     ClipRect(&r);
  2453.   }
  2454.