Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

387 lines
12 KiB

  1. /*===========================================================================*/
  2. /* Copyright (c) 1987 - 1988, Future Soft Engineering, Inc. */
  3. /* Houston, Texas */
  4. /*===========================================================================*/
  5. #define NOLSTRING TRUE /* jtf win3 mod */
  6. #include <windows.h>
  7. #include <port1632.h>
  8. #include "dcrc.h"
  9. #include "dynacomm.h"
  10. #include "video.h"
  11. /*---------------------------------------------------------------------------*/
  12. /* eraseColorRect() - use current attribute to erase area [jtf] */
  13. /*---------------------------------------------------------------------------*/
  14. VOID eraseColorRect(HDC hDC, LPRECT rect, BYTE cAttr)
  15. {
  16. HBRUSH hTmpBrush;
  17. hTmpBrush = CreateSolidBrush(RGB(vidAttr[cAttr & AMASK].bkgd[VID_RED],
  18. vidAttr[cAttr & AMASK].bkgd[VID_GREEN],
  19. vidAttr[cAttr & AMASK].bkgd[VID_BLUE]));
  20. FillRect(hDC, (LPRECT) rect, (HBRUSH) hTmpBrush);
  21. DeleteObject((HBRUSH) hTmpBrush);
  22. }
  23. /*---------------------------------------------------------------------------*/
  24. /* reDrawTermScreen() - [mbb] */
  25. /*---------------------------------------------------------------------------*/
  26. VOID reDrawTermScreen(INT nStart, INT nCount, INT nOffset)
  27. {
  28. while(nStart < nCount)
  29. reDrawTermLine((nStart++) + nOffset, 0, maxChars);
  30. }
  31. /*---------------------------------------------------------------------------*/
  32. /* reDrawTermLine() - Reslap some lines back up on the terminal. [scf] */
  33. /*---------------------------------------------------------------------------*/
  34. VOID reDrawTermLine(INT lin, INT col, INT len)
  35. {
  36. LPBYTE lpText;
  37. if(lin < 0)
  38. {
  39. getPort();
  40. hideTermCursor();
  41. if((lpText = GlobalLock(hTE.hText)) != NULL)
  42. {
  43. drawTermLine(lpText + ((savTopLine + lin) * (maxChars + 2)) + col,
  44. len, lin, col + len, LNORMAL, 0);
  45. GlobalUnlock(hTE.hText);
  46. }
  47. showTermCursor();
  48. releasePort();
  49. }
  50. else if(lin <= (maxScreenLine+1)) /* mbbx 2.00.06: jtf disp2 */
  51. {
  52. attrib[lin][LFLAGS] = (LCLEAR | LDIRTY);
  53. updateLine(lin);
  54. }
  55. }
  56. /*---------------------------------------------------------------------------*/
  57. /* updateLine() - */
  58. /*---------------------------------------------------------------------------*/
  59. VOID updateLine(INT line)
  60. {
  61. BOOL bStatusLine; /* mbbx 2.00.06: jtf disp2 */
  62. LPBYTE txt;
  63. BYTE *attr;
  64. INT col1, col2, len, txtLen; // sdj: unref variable was- bottom;
  65. BYTE cAttr;
  66. BOOL anyway;
  67. /* mbbx 2.00.06: dont overwrite xferCtrls... */
  68. if((bStatusLine = (line == maxScreenLine+1)) && (xferFlag > XFRNONE))
  69. return;
  70. getPort();
  71. hideTermCursor();
  72. if(!bStatusLine)
  73. {
  74. clipRect(&hTE.viewRect); /* jtf 3.Final */
  75. txt = (LPBYTE)GlobalLock(hTE.hText) + (savTopLine + line) * (maxChars + 2);
  76. }
  77. else
  78. {
  79. clipRect(&statusRect); /* rjs bugs 019 */
  80. txt = (LPBYTE) line25;
  81. }
  82. attr = attrib[line];
  83. anyway = (attr[LFLAGS] == (LCLEAR | LDIRTY));
  84. for(col1 = 0; col1 < maxChars; col1 = col2)
  85. {
  86. cAttr = attr[col1];
  87. for (col2 = col1+1; col2 < maxChars; col2++)
  88. {
  89. attr[col2-1] &= ~ADIRTY;
  90. if (cAttr != attr[col2])
  91. break;
  92. }
  93. len = col2 - col1;
  94. txtLen = len;
  95. if((cAttr & ADIRTY) || anyway)
  96. drawTermLine(txt, txtLen, line, col1 + txtLen, attr[LATTRIB], cAttr);
  97. txt += len;
  98. }
  99. attr[col2-1] &= ~ADIRTY;
  100. attr[LFLAGS] = 0;
  101. if(!bStatusLine)
  102. GlobalUnlock(hTE.hText);
  103. showTermCursor();
  104. releasePort();
  105. }
  106. /*---------------------------------------------------------------------------*/
  107. /* drawTermLine() - */
  108. /*---------------------------------------------------------------------------*/
  109. VOID drawTermLine(LPBYTE txtPtr, INT len, INT lin, INT col, BYTE lAttr, BYTE cAttr)
  110. {
  111. BOOL bStatusLine;
  112. HDC savePort;
  113. HBITMAP hBitMap;
  114. RECT srcRect, dstRect, tmpRect;
  115. INT ndx;
  116. BYTE grSave[132], grChar[132];
  117. HPEN newPen, oldPen;
  118. INT grLeft, grWidth2, grHeight2;
  119. BOOL bhBitMapValid;
  120. bhBitMapValid = FALSE; //sdj: there is a chance that hbitmap maynot
  121. //sdj: be valid and still deleteobject(hbitmap)
  122. //sdj: is called, and this may delete some random
  123. //sdj: object, who knows, so lets delete it only
  124. //sdj: if you create one
  125. if(!(bStatusLine = (lin == maxScreenLine+1)))
  126. {
  127. if(((lin += (savTopLine - curTopLine)) < 0) || (lin > visScreenLine))
  128. return;
  129. }
  130. if(lAttr != LNORMAL)
  131. {
  132. thePort = CreateCompatibleDC(savePort = thePort);
  133. hBitMap = CreateCompatibleBitmap(thePort, chrWidth * maxChars, chrHeight);
  134. bhBitMapValid = TRUE;
  135. SelectObject(thePort, hBitMap);
  136. SelectObject(thePort, hTE.hFont);
  137. /* srcRect : rect to draw chars in (memory DC) */
  138. srcRect.left = 0;
  139. srcRect.right = len * chrWidth;
  140. srcRect.top = 0;
  141. srcRect.bottom = chrHeight;
  142. /* dstRect : rect to copy bits to (stretchBlt) */
  143. dstRect.right = col*chrWidth*2 - curLeftCol*chrWidth;
  144. dstRect.left = dstRect.right - len*chrWidth*2;
  145. dstRect.top = lin * chrHeight;
  146. if(lAttr == LHIGHBOTTOM)
  147. dstRect.top -= chrHeight;
  148. if((dstRect.bottom = dstRect.top + chrHeight) >= statusRect.top)
  149. dstRect.bottom = statusRect.top-1; /* mbbx 2.00.06: wont this look FUNKY ??? */
  150. if(lAttr != LWIDE)
  151. dstRect.bottom += chrHeight;
  152. tmpRect = dstRect;
  153. eraseColorRect((HDC) thePort, (LPRECT) &tmpRect, (BYTE) cAttr);
  154. }
  155. else
  156. {
  157. srcRect.right = (col - curLeftCol) * chrWidth;
  158. srcRect.left = srcRect.right - (len * chrWidth);
  159. /* mbbx 2.00.06: jtf disp2... */
  160. srcRect.top = !bStatusLine ? (lin * chrHeight) : statusRect.top + (STATUSRECTBORDER / 2);
  161. srcRect.bottom = srcRect.top + chrHeight;
  162. }
  163. if(cAttr & AGRAPHICS)
  164. {
  165. lmovmem(txtPtr, (LPSTR) grSave, len); /* mbbx 2.00.06: save actual buffer data */
  166. for(ndx = 0; ndx < len; ndx += 1)
  167. {
  168. if((txtPtr[ndx] >= 0x40) && (txtPtr[ndx] <= 0x7F))
  169. {
  170. grChar[ndx] = vidGraphChars[txtPtr[ndx] - 0x40].display;
  171. txtPtr[ndx] = vidGraphChars[txtPtr[ndx] - 0x40].buffer;
  172. }
  173. else
  174. grChar[ndx] = 0;
  175. }
  176. }
  177. ndx = 0;
  178. if(!(vidAttr[cAttr & AMASK].flags & VID_UNDERLINE) && !bStatusLine) /* mbbx 2.00.06: jtf disp2... */
  179. {
  180. while((txtPtr[ndx] == ' ') && (ndx < len))
  181. ndx += 1;
  182. }
  183. if(ndx > 0)
  184. {
  185. CopyRect((LPRECT) &tmpRect, (LPRECT) &srcRect);
  186. tmpRect.right = tmpRect.left + (ndx * chrWidth);
  187. if(tmpRect.bottom >= statusRect.top) /* mbbx 2.00.06: jtf disp2 - dont overwrite statusRect... */
  188. tmpRect.bottom = statusRect.top-1;
  189. eraseColorRect((HDC) thePort, (LPRECT) &tmpRect, (BYTE) cAttr);
  190. }
  191. if((len - ndx) > 0)
  192. {
  193. setAttrib(cAttr);
  194. ExtTextOut(thePort, srcRect.left + (ndx * chrWidth), srcRect.top, ETO_CLIPPED, (LPRECT) &srcRect,
  195. (LPSTR) &txtPtr[ndx], len-ndx, (LPINT) vidCharWidths);
  196. }
  197. if(cAttr & AGRAPHICS)
  198. {
  199. newPen = CreatePen(0, 1, RGB(vidAttr[cAttr & AMASK].text[VID_RED],
  200. vidAttr[cAttr & AMASK].text[VID_GREEN],
  201. vidAttr[cAttr & AMASK].text[VID_BLUE]));
  202. oldPen = SelectObject(thePort, (HPEN) newPen);
  203. grLeft = srcRect.left;
  204. grWidth2 = chrWidth / 2;
  205. grHeight2 = chrHeight / 2;
  206. for(ndx = 0; ndx < len; ndx += 1)
  207. {
  208. if(grChar[ndx] & VID_DRAW_LEFT)
  209. {
  210. MMoveTo(thePort, grLeft, srcRect.top + grHeight2);
  211. LineTo(thePort, grLeft + grWidth2, srcRect.top + grHeight2);
  212. }
  213. if(grChar[ndx] & VID_DRAW_RIGHT)
  214. {
  215. MMoveTo(thePort, grLeft + grWidth2, srcRect.top + grHeight2);
  216. LineTo(thePort, grLeft + chrWidth, srcRect.top + grHeight2);
  217. }
  218. if(grChar[ndx] & VID_DRAW_TOP)
  219. {
  220. MMoveTo(thePort, grLeft + grWidth2, srcRect.top);
  221. LineTo(thePort, grLeft + grWidth2, srcRect.top + grHeight2);
  222. }
  223. if(grChar[ndx] & VID_DRAW_BOTTOM)
  224. {
  225. MMoveTo(thePort, grLeft + grWidth2, srcRect.top + grHeight2);
  226. LineTo(thePort, grLeft + grWidth2, srcRect.top + chrHeight);
  227. }
  228. if(grChar[ndx] & VID_DRAW_SCAN1)
  229. {
  230. MMoveTo(thePort, grLeft, srcRect.top);
  231. LineTo(thePort, grLeft + chrWidth, srcRect.top);
  232. }
  233. if(grChar[ndx] & VID_DRAW_SCAN3)
  234. {
  235. MMoveTo(thePort, grLeft, srcRect.top + (chrHeight / 4));
  236. LineTo(thePort, grLeft + chrWidth, srcRect.top + (chrHeight/4));
  237. }
  238. if(grChar[ndx] & VID_DRAW_SCAN7)
  239. {
  240. MMoveTo(thePort, grLeft, srcRect.top + (3 * (chrHeight / 4)));
  241. LineTo(thePort, grLeft + chrWidth, srcRect.top + (3 * (chrHeight/4)));
  242. }
  243. if(grChar[ndx] & VID_DRAW_SCAN9)
  244. {
  245. MMoveTo(thePort, grLeft, srcRect.top + (chrHeight-1));
  246. LineTo(thePort, grLeft + chrWidth, srcRect.top + (chrHeight-1));
  247. }
  248. grLeft += chrWidth;
  249. }
  250. SelectObject(thePort, (HPEN) oldPen);
  251. DeleteObject((HPEN) newPen);
  252. lmovmem((LPSTR) grSave, txtPtr, len); /* mbbx 2.00.06: restore actual buffer data */
  253. }
  254. if(vidAttr[cAttr & AMASK].flags & VID_REVERSE)
  255. InvertRect(thePort, (LPRECT) &srcRect);
  256. if(lAttr != LNORMAL)
  257. {
  258. /* mbbx 2.00: font selection... */
  259. StretchBlt(savePort, dstRect.left, dstRect.top,
  260. dstRect.right - dstRect.left, dstRect.bottom - dstRect.top,
  261. thePort, srcRect.left, srcRect.top,
  262. srcRect.right - srcRect.left, chrHeight, SRCCOPY);
  263. DeleteDC(thePort);
  264. if (bhBitMapValid) //sdj: check if valid, only then call delete
  265. DeleteObject(hBitMap);
  266. thePort = savePort;
  267. }
  268. if(vidAttr[cAttr & AMASK].flags & (VID_BOLD | VID_ITALIC | VID_UNDERLINE | VID_STRIKEOUT))
  269. SelectObject(thePort, hTE.hFont);
  270. }
  271. /*--------------------------------------------------------------------------*/
  272. /* setAttrib() - [jtf] */
  273. /*--------------------------------------------------------------------------*/
  274. VOID setAttrib(BYTE cAttr)
  275. {
  276. INT ndx;
  277. LOGFONT logFont;
  278. HFONT hFont;
  279. cAttr &= AMASK;
  280. SetTextColor(thePort, RGB(vidAttr[cAttr].text[VID_RED],
  281. vidAttr[cAttr].text[VID_GREEN], vidAttr[cAttr].text[VID_BLUE]));
  282. SetBkColor(thePort, RGB(vidAttr[cAttr].bkgd[VID_RED],
  283. vidAttr[cAttr].bkgd[VID_GREEN], vidAttr[cAttr].bkgd[VID_BLUE]));
  284. if(vidAttr[cAttr].flags & (VID_BOLD | VID_ITALIC | VID_UNDERLINE | VID_STRIKEOUT))
  285. {
  286. for(ndx = 0; ndx < VID_MAXFONTCACHE; ndx += 1)
  287. {
  288. if(vidFontCache[ndx].hFont == NULL)
  289. break;
  290. if(vidFontCache[ndx].flags == (vidAttr[cAttr].flags & VID_MASK))
  291. {
  292. SelectObject(thePort, vidFontCache[ndx].hFont);
  293. return;
  294. }
  295. }
  296. GetObject(hTE.hFont, sizeof(LOGFONT), (LPSTR) &logFont);
  297. if(vidAttr[cAttr].flags & VID_BOLD)
  298. logFont.lfWeight = 700;
  299. logFont.lfUnderline = (vidAttr[cAttr].flags & VID_UNDERLINE) ? TRUE : FALSE;
  300. logFont.lfStrikeOut = (vidAttr[cAttr].flags & VID_STRIKEOUT) ? TRUE : FALSE;
  301. logFont.lfItalic = (vidAttr[cAttr].flags & VID_ITALIC) ? TRUE : FALSE;
  302. hFont = CreateFontIndirect((LPLOGFONT) &logFont);
  303. if(ndx == VID_MAXFONTCACHE)
  304. {
  305. DeleteObject(vidFontCache[0].hFont);
  306. for(ndx = 0; ndx < VID_MAXFONTCACHE-1; ndx += 1)
  307. {
  308. vidFontCache[ndx].hFont = vidFontCache[ndx+1].hFont;
  309. vidFontCache[ndx].flags = vidFontCache[ndx+1].flags;
  310. }
  311. }
  312. vidFontCache[ndx].hFont = hFont;
  313. vidFontCache[ndx].flags = (vidAttr[cAttr].flags & VID_MASK);
  314. SelectObject(thePort, hFont);
  315. }
  316. }