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.

514 lines
17 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. /* offCursor() - Turn off terminal emulation cursor. [scf] */
  13. /*---------------------------------------------------------------------------*/
  14. VOID offCursor ()
  15. {
  16. if (activTerm)
  17. {
  18. cursorOn--;
  19. if (cursorOn == 0)
  20. {
  21. if (cursBlinkOn)
  22. toggleCursor(&cursorRect);
  23. }
  24. else
  25. if(cursorOn < 0)
  26. cursorOn = 0;
  27. }
  28. }
  29. /*---------------------------------------------------------------------------*/
  30. /* onCursor() - Turn on the terminal emulation cursor. [scf] */
  31. /*---------------------------------------------------------------------------*/
  32. VOID onCursor ()
  33. {
  34. if (activTerm)
  35. {
  36. cursorOn++;
  37. if (cursorOn == 1)
  38. {
  39. cursorTick = 1;
  40. rectCursor (&cursorRect);
  41. cursBlinkOn = FALSE;
  42. toggleCursor (&cursorRect);
  43. }
  44. else
  45. if (cursorOn > 1)
  46. cursorOn = 1;
  47. }
  48. }
  49. /*---------------------------------------------------------------------------*/
  50. /* rectCursor() - Set the terminal cursor rectangle. [scf] */
  51. /*---------------------------------------------------------------------------*/
  52. VOID rectCursor(RECT *theRect)
  53. {
  54. if(activCursor > 0)
  55. {
  56. if(statusLine)
  57. theRect->top = statusRect.top + (STATUSRECTBORDER / 2);
  58. else
  59. theRect->top = (savTopLine - curTopLine + curLin) * chrHeight;
  60. theRect->bottom = theRect->top + chrHeight;
  61. if(trmParams.termCursor != ITMBLKCURSOR)
  62. theRect->top += ((3 * chrHeight) / 4);
  63. else
  64. theRect->top++; /* jtf terminal changed to make cursor smaller */
  65. if(statusLine || (attrib[curLin][LATTRIB] == LNORMAL))
  66. {
  67. theRect->left = (curCol - curLeftCol) * chrWidth;
  68. theRect->right = theRect->left + chrWidth;
  69. }
  70. else
  71. {
  72. theRect->left = curCol * chrWidth * 2 - curLeftCol * chrWidth;
  73. theRect->right = theRect->left + chrWidth * 2;
  74. }
  75. }
  76. }
  77. /*---------------------------------------------------------------------------*/
  78. /* toggleCursor() - Toggle the terminal emulation cursor visible or not */
  79. /*---------------------------------------------------------------------------*/
  80. VOID toggleCursor(RECT *theRect)
  81. {
  82. RECT clientRect;
  83. if(activCursor > 0)
  84. {
  85. getPort();
  86. cursBlinkOn = !cursBlinkOn;
  87. /* mbbx 1.04: for lack of a better method... */
  88. if(theRect->top == statusRect.top + (STATUSRECTBORDER / 2))
  89. clipRect(&statusRect);
  90. else
  91. clipRect(&hTE.viewRect);
  92. InvertRect(thePort, theRect);
  93. releasePort();
  94. }
  95. }
  96. /*---------------------------------------------------------------------------*/
  97. /* hideTermCursor */
  98. /*---------------------------------------------------------------------------*/
  99. VOID hideTermCursor ()
  100. {
  101. if (activCursor == 1)
  102. offCursor ();
  103. activCursor--;
  104. }
  105. /*---------------------------------------------------------------------------*/
  106. /* showTermCursor */
  107. /*---------------------------------------------------------------------------*/
  108. VOID showTermCursor ()
  109. {
  110. activCursor++;
  111. if (activCursor == 1)
  112. onCursor ();
  113. }
  114. /*---------------------------------------------------------------------------*/
  115. /* stripBlanks() - Purge unecessary CHFILL's for text file. [scf] */
  116. /*---------------------------------------------------------------------------*/
  117. VOID stripBlanks (LPBYTE ptr, DWORD *len)
  118. {
  119. register INT src;
  120. register INT dst;
  121. INT deltaLen;
  122. ptr[*len] = 0; /* Terminate for 'C' */
  123. for (src = (INT) *len; src > 0; src = dst - 1)
  124. {
  125. while ( (src > 0) && (ptr[src] != CR) ) /* jtf 3.11 fixed segmentation error */
  126. src--;
  127. dst = src - 1;
  128. while ((dst > 0) && (ptr[dst] == CHFILL) ) /* jtf 3.11 fixed segmentation error */
  129. dst--;
  130. dst++;
  131. deltaLen = src - dst;
  132. lmovmem (&ptr[src], &ptr[dst], (DWORD) (*len - src));
  133. *len -= (DWORD) deltaLen;
  134. }
  135. ptr[*len] = 0;
  136. }
  137. /*---------------------------------------------------------------------------*/
  138. /* loadTermFont() - [mbb] */
  139. /*---------------------------------------------------------------------------*/
  140. VOID loadTermFont(LOGFONT *logFont)
  141. {
  142. HFONT hOldFont;
  143. TEXTMETRIC fontMetrics;
  144. INT ndx;
  145. hOldFont = hTE.hFont;
  146. if((hTE.hFont = CreateFontIndirect(logFont)) != hOldFont)
  147. {
  148. getPort();
  149. SelectObject(thePort, hTE.hFont);
  150. GetTextMetrics(thePort, &fontMetrics);
  151. releasePort();
  152. stdChrHeight = chrHeight = fontMetrics.tmHeight;
  153. stdChrWidth = chrWidth = fontMetrics.tmMaxCharWidth;
  154. for(ndx = 0; ndx < 256; ndx += 1)
  155. vidCharWidths[ndx] = chrWidth;
  156. if(hOldFont != NULL)
  157. {
  158. DeleteObject(hOldFont);
  159. clearFontCache();
  160. resetEmul();
  161. if(!IsIconic(hItWnd)) /* rjs bugs 015 */
  162. sizeTerm(0L);
  163. }
  164. }
  165. }
  166. /*---------------------------------------------------------------------------*/
  167. /* nextFontSize() - [mbb] */
  168. /*---------------------------------------------------------------------------*/
  169. INT APIENTRY nextFontSize(const LOGFONT *lpLogFont, const TEXTMETRIC *lpTextMetrics,
  170. DWORD FontType, LPARAM lpParam)
  171. {
  172. LPSTR lpData = (LPSTR)lpParam;
  173. INT ndx, ndx2;
  174. if(*lpData != 0)
  175. {
  176. if (FontType & RASTER_FONTTYPE)
  177. {
  178. for(ndx = 1; ndx <= 5; ndx += 1)
  179. {
  180. if((ndx2 = lpLogFont->lfHeight * ndx) > *lpData)
  181. break;
  182. lpData[ndx2] = (char)lpLogFont->lfHeight;
  183. if(lpLogFont->lfQuality == PROOF_QUALITY) /* no scaling... */
  184. break;
  185. }
  186. }
  187. else /* vector font... */
  188. lsetmem(lpData+1, lpLogFont->lfHeight, *lpData);
  189. }
  190. else if(lpLogFont->lfHeight == lpData[1])
  191. {
  192. lmovmem(lpLogFont, lpData, sizeof(LOGFONT));
  193. return(FALSE);
  194. }
  195. return(TRUE); /* continue... */
  196. }
  197. /*---------------------------------------------------------------------------*/
  198. /* listFontSizes() - [mbb] */
  199. /*---------------------------------------------------------------------------*/
  200. VOID listFontSizes(BYTE *faceName, BYTE *sizeList, INT maxSize)
  201. {
  202. memset(sizeList+1, 0, *sizeList = (BYTE)maxSize);
  203. getPort();
  204. EnumFonts(thePort, faceName, nextFontSize, (LPARAM) sizeList);
  205. releasePort();
  206. }
  207. /*---------------------------------------------------------------------------*/
  208. /* buildTermFont() - [mbb] */
  209. /*---------------------------------------------------------------------------*/
  210. VOID buildTermFont() /* mbbx 2.00: font selection... */
  211. {
  212. BYTE sizeList[64];
  213. LOGFONT logFont;
  214. if((hTE.hFont != NULL) && (trmParams.fontSize > 0))
  215. {
  216. strcpy(sizeList, trmParams.fontFace);
  217. AnsiUpper((LPSTR)sizeList);
  218. if(!strcmp(sizeList, "SYSTEM"))
  219. LoadString(hInst, STR_INI_FONTFACE, trmParams.fontFace, LF_FACESIZE);
  220. listFontSizes(trmParams.fontFace, sizeList, 64-1);
  221. if((logFont.lfHeight = (sizeList[trmParams.fontSize] * 256)) != 0)
  222. {
  223. getPort();
  224. EnumFonts(thePort, trmParams.fontFace, nextFontSize, (LPARAM) &logFont);
  225. releasePort();
  226. }
  227. }
  228. else
  229. logFont.lfHeight = 0;
  230. if(LOBYTE(logFont.lfHeight) == 0)
  231. {
  232. logFont.lfEscapement = 0;
  233. logFont.lfOrientation = 0;
  234. logFont.lfWeight = 0; /* rjs bugs 017 -> 0 to 200 */
  235. logFont.lfItalic = FALSE;
  236. logFont.lfUnderline = FALSE;
  237. logFont.lfStrikeOut = FALSE;
  238. logFont.lfCharSet = ANSI_CHARSET;
  239. logFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
  240. logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  241. logFont.lfQuality = DEFAULT_QUALITY;
  242. logFont.lfPitchAndFamily = FF_DONTCARE;
  243. strcpy(logFont.lfFaceName, trmParams.fontFace);
  244. }
  245. logFont.lfHeight = trmParams.fontSize;
  246. logFont.lfWidth = 0;
  247. loadTermFont(&logFont);
  248. }
  249. /*---------------------------------------------------------------------------*/
  250. /* clearFontCache() - [mbb] */
  251. /*---------------------------------------------------------------------------*/
  252. VOID clearFontCache() /* mbbx 1.10 ... */
  253. {
  254. INT ndx;
  255. for(ndx = 0; ndx < VID_MAXFONTCACHE; ndx += 1)
  256. {
  257. if(vidFontCache[ndx].hFont != NULL)
  258. {
  259. DeleteObject(vidFontCache[ndx].hFont);
  260. vidFontCache[ndx].hFont = NULL;
  261. vidFontCache[ndx].flags = 0;
  262. }
  263. }
  264. }
  265. /*---------------------------------------------------------------------------*/
  266. /* calcDefaultAttrib() - [jtf] */
  267. /*---------------------------------------------------------------------------*/
  268. VOID calcDefaultAttrib() /* mbbx 1.03 ... */
  269. {
  270. INT ndx;
  271. for(ndx = 3; ndx < 32; ndx += 1) /* skip NORMAL, BOLD, REVERSE */
  272. {
  273. if((ndx == ABLINK) || (ndx == AUNDERLINE) || (ndx == APROTECT))
  274. continue;
  275. if(vidAttr[ndx].flags & VID_CALCTEXT)
  276. {
  277. vidAttr[ndx].text[VID_RED] = 0;
  278. vidAttr[ndx].text[VID_GREEN] = 0;
  279. vidAttr[ndx].text[VID_BLUE] = 0;
  280. }
  281. if(vidAttr[ndx].flags & VID_CALCBKGD)
  282. {
  283. vidAttr[ndx].bkgd[VID_RED] = 0;
  284. vidAttr[ndx].bkgd[VID_GREEN] = 0;
  285. vidAttr[ndx].bkgd[VID_BLUE] = 0;
  286. }
  287. if(vidAttr[ndx].flags & VID_CALCATTR)
  288. vidAttr[ndx].flags &= (VID_CALCTEXT | VID_CALCBKGD | VID_CALCATTR);
  289. if(ndx & ABOLD)
  290. {
  291. if(vidAttr[ndx].flags & VID_CALCTEXT)
  292. {
  293. vidAttr[ndx].text[VID_RED] = min(vidAttr[ndx].text[VID_RED] + vidAttr[ABOLD].text[VID_RED], 255);
  294. vidAttr[ndx].text[VID_GREEN] = min(vidAttr[ndx].text[VID_GREEN] + vidAttr[ABOLD].text[VID_GREEN], 255);
  295. vidAttr[ndx].text[VID_BLUE] = min(vidAttr[ndx].text[VID_BLUE] + vidAttr[ABOLD].text[VID_BLUE], 255);
  296. }
  297. if(vidAttr[ndx].flags & VID_CALCBKGD)
  298. {
  299. vidAttr[ndx].bkgd[VID_RED] = min(vidAttr[ndx].bkgd[VID_RED] + vidAttr[ABOLD].bkgd[VID_RED], 255);
  300. vidAttr[ndx].bkgd[VID_GREEN] = min(vidAttr[ndx].bkgd[VID_GREEN] + vidAttr[ABOLD].bkgd[VID_GREEN], 255);
  301. vidAttr[ndx].bkgd[VID_BLUE] = min(vidAttr[ndx].bkgd[VID_BLUE] + vidAttr[ABOLD].bkgd[VID_BLUE], 255);
  302. }
  303. if(vidAttr[ndx].flags & VID_CALCATTR)
  304. vidAttr[ndx].flags |= (vidAttr[ABOLD].flags & VID_MASK);
  305. }
  306. if(ndx & AREVERSE)
  307. {
  308. if(vidAttr[ndx].flags & VID_CALCTEXT)
  309. {
  310. vidAttr[ndx].text[VID_RED] = min(vidAttr[ndx].text[VID_RED] + vidAttr[AREVERSE].text[VID_RED], 255);
  311. vidAttr[ndx].text[VID_GREEN] = min(vidAttr[ndx].text[VID_GREEN] + vidAttr[AREVERSE].text[VID_GREEN], 255);
  312. vidAttr[ndx].text[VID_BLUE] = min(vidAttr[ndx].text[VID_BLUE] + vidAttr[AREVERSE].text[VID_BLUE], 255);
  313. }
  314. if(vidAttr[ndx].flags & VID_CALCBKGD)
  315. {
  316. vidAttr[ndx].bkgd[VID_RED] = min(vidAttr[ndx].bkgd[VID_RED] + vidAttr[AREVERSE].bkgd[VID_RED], 255);
  317. vidAttr[ndx].bkgd[VID_GREEN] = min(vidAttr[ndx].bkgd[VID_GREEN] + vidAttr[AREVERSE].bkgd[VID_GREEN], 255);
  318. vidAttr[ndx].bkgd[VID_BLUE] = min(vidAttr[ndx].bkgd[VID_BLUE] + vidAttr[AREVERSE].bkgd[VID_BLUE], 255);
  319. }
  320. if(vidAttr[ndx].flags & VID_CALCATTR)
  321. vidAttr[ndx].flags |= (vidAttr[AREVERSE].flags & VID_MASK);
  322. }
  323. if(ndx & ABLINK)
  324. {
  325. if(vidAttr[ndx].flags & VID_CALCTEXT)
  326. {
  327. vidAttr[ndx].text[VID_RED] = min(vidAttr[ndx].text[VID_RED] + vidAttr[ABLINK].text[VID_RED], 255);
  328. vidAttr[ndx].text[VID_GREEN] = min(vidAttr[ndx].text[VID_GREEN] + vidAttr[ABLINK].text[VID_GREEN], 255);
  329. vidAttr[ndx].text[VID_BLUE] = min(vidAttr[ndx].text[VID_BLUE] + vidAttr[ABLINK].text[VID_BLUE], 255);
  330. }
  331. if(vidAttr[ndx].flags & VID_CALCBKGD)
  332. {
  333. vidAttr[ndx].bkgd[VID_RED] = min(vidAttr[ndx].bkgd[VID_RED] + vidAttr[ABLINK].bkgd[VID_RED], 255);
  334. vidAttr[ndx].bkgd[VID_GREEN] = min(vidAttr[ndx].bkgd[VID_GREEN] + vidAttr[ABLINK].bkgd[VID_GREEN], 255);
  335. vidAttr[ndx].bkgd[VID_BLUE] = min(vidAttr[ndx].bkgd[VID_BLUE] + vidAttr[ABLINK].bkgd[VID_BLUE], 255);
  336. }
  337. if(vidAttr[ndx].flags & VID_CALCATTR)
  338. vidAttr[ndx].flags |= (vidAttr[ABLINK].flags & VID_MASK);
  339. }
  340. if(ndx & AUNDERLINE)
  341. {
  342. if(vidAttr[ndx].flags & VID_CALCTEXT)
  343. {
  344. vidAttr[ndx].text[VID_RED] = min(vidAttr[ndx].text[VID_RED] + vidAttr[AUNDERLINE].text[VID_RED], 255);
  345. vidAttr[ndx].text[VID_GREEN] = min(vidAttr[ndx].text[VID_GREEN] + vidAttr[AUNDERLINE].text[VID_GREEN], 255);
  346. vidAttr[ndx].text[VID_BLUE] = min(vidAttr[ndx].text[VID_BLUE] + vidAttr[AUNDERLINE].text[VID_BLUE], 255);
  347. }
  348. if(vidAttr[ndx].flags & VID_CALCBKGD)
  349. {
  350. vidAttr[ndx].bkgd[VID_RED] = min(vidAttr[ndx].bkgd[VID_RED] + vidAttr[AUNDERLINE].bkgd[VID_RED], 255);
  351. vidAttr[ndx].bkgd[VID_GREEN] = min(vidAttr[ndx].bkgd[VID_GREEN] + vidAttr[AUNDERLINE].bkgd[VID_GREEN], 255);
  352. vidAttr[ndx].bkgd[VID_BLUE] = min(vidAttr[ndx].bkgd[VID_BLUE] + vidAttr[AUNDERLINE].bkgd[VID_BLUE], 255);
  353. }
  354. if(vidAttr[ndx].flags & VID_CALCATTR)
  355. vidAttr[ndx].flags |= (vidAttr[AUNDERLINE].flags & VID_MASK);
  356. }
  357. if(ndx & APROTECT)
  358. {
  359. if(vidAttr[ndx].flags & VID_CALCTEXT)
  360. {
  361. vidAttr[ndx].text[VID_RED] = min(vidAttr[ndx].text[VID_RED] + vidAttr[APROTECT].text[VID_RED], 255);
  362. vidAttr[ndx].text[VID_GREEN] = min(vidAttr[ndx].text[VID_GREEN] + vidAttr[APROTECT].text[VID_GREEN], 255);
  363. vidAttr[ndx].text[VID_BLUE] = min(vidAttr[ndx].text[VID_BLUE] + vidAttr[APROTECT].text[VID_BLUE], 255);
  364. }
  365. if(vidAttr[ndx].flags & VID_CALCBKGD)
  366. {
  367. vidAttr[ndx].bkgd[VID_RED] = min(vidAttr[ndx].bkgd[VID_RED] + vidAttr[APROTECT].bkgd[VID_RED], 255);
  368. vidAttr[ndx].bkgd[VID_GREEN] = min(vidAttr[ndx].bkgd[VID_GREEN] + vidAttr[APROTECT].bkgd[VID_GREEN], 255);
  369. vidAttr[ndx].bkgd[VID_BLUE] = min(vidAttr[ndx].bkgd[VID_BLUE] + vidAttr[APROTECT].bkgd[VID_BLUE], 255);
  370. }
  371. if(vidAttr[ndx].flags & VID_CALCATTR)
  372. vidAttr[ndx].flags |= (vidAttr[APROTECT].flags & VID_MASK);
  373. }
  374. }
  375. }
  376. /*---------------------------------------------------------------------------*/
  377. /* setDefaultAttrib() - [jtf] */
  378. /*---------------------------------------------------------------------------*/
  379. VOID setDefaultAttrib(BOOL bLoad)
  380. {
  381. BYTE szSection[MINRESSTR], szKeyWord[MINRESSTR], szDefault[MINRESSTR];
  382. BYTE work[16];
  383. #ifdef ORGCODE
  384. INT text[3], bkgd[3];
  385. #else
  386. DWORD text[3], bkgd[3]; // -sdj 10/8/91 bug#3279
  387. #endif
  388. INT ndx;
  389. clearFontCache();
  390. LoadString(hInst, STR_INI_COLORS, szSection, MINRESSTR);
  391. LoadString(hInst, STR_INI_WINDOWTEXT, szKeyWord, MINRESSTR);
  392. LoadString(hInst, STR_INI_TEXTCOLOR, szDefault, MINRESSTR);
  393. GetProfileString(szSection, szKeyWord, szDefault, work, 16-1);
  394. sscanf(work, "%d %d %d", text+0, text+1, text+2);
  395. LoadString(hInst, STR_INI_WINDOW, szKeyWord, MINRESSTR);
  396. LoadString(hInst, STR_INI_BKGDCOLOR, szDefault, MINRESSTR);
  397. GetProfileString(szSection, szKeyWord, szDefault, work, 16-1);
  398. sscanf(work, "%d %d %d", bkgd+0, bkgd+1, bkgd+2);
  399. for(ndx = 0; ndx < 32; ndx += 1)
  400. {
  401. // -sdj 10/8/91 bug#3279 remove the hardcoded color stuff, new crt libs are in
  402. vidAttr[ndx].text[VID_RED] = (BYTE)text[VID_RED];
  403. vidAttr[ndx].text[VID_GREEN] = (BYTE)text[VID_GREEN];
  404. vidAttr[ndx].text[VID_BLUE] = (BYTE)text[VID_BLUE];
  405. vidAttr[ndx].bkgd[VID_RED] = (BYTE)bkgd[VID_RED];
  406. vidAttr[ndx].bkgd[VID_GREEN] = (BYTE)bkgd[VID_GREEN];
  407. vidAttr[ndx].bkgd[VID_BLUE] = (BYTE)bkgd[VID_BLUE];
  408. vidAttr[ndx].flags = VID_CALCATTR | VID_CALCBKGD | VID_CALCTEXT;
  409. }
  410. vidAttr[ANORMAL].flags = 0;
  411. vidAttr[ABOLD].flags = VID_BOLD;
  412. vidAttr[AREVERSE].flags = VID_REVERSE;
  413. vidAttr[ABLINK].flags = VID_BOLD;
  414. vidAttr[AUNDERLINE].flags = VID_UNDERLINE;
  415. vidAttr[APROTECT].flags = VID_REVERSE;
  416. calcDefaultAttrib();
  417. }