Leaked source code of windows server 2003
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.

463 lines
10 KiB

  1. /* File: D:\WACKER\emu\emu_scr.c (Created: 08-Dec-1993)
  2. *
  3. * Copyright 1994 by Hilgraeve Inc. -- Monroe, MI
  4. * All rights reserved
  5. *
  6. * $Revision: 5 $
  7. * $Date: 3/26/02 5:07p $
  8. */
  9. #include <windows.h>
  10. #pragma hdrstop
  11. #include <tdll\stdtyp.h>
  12. #include <tdll\tdll.h>
  13. #include <tdll\cloop.h>
  14. #include <tdll\assert.h>
  15. #include <tdll\capture.h>
  16. #include <tdll\session.h>
  17. #include <tdll\backscrl.h>
  18. #include <tdll\print.h>
  19. #include <tdll\update.h>
  20. #include <tdll\htchar.h>
  21. #include "tdll\misc.h"
  22. #include "emu.h"
  23. #include "emu.hh"
  24. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  25. * backspace
  26. *
  27. * DESCRIPTION:
  28. *
  29. * ARGUMENTS:
  30. *
  31. * RETURNS:
  32. *
  33. */
  34. void backspace(const HHEMU hhEmu)
  35. {
  36. INT bWide = 1;
  37. INT iRow = row_index(hhEmu, hhEmu->emu_currow);
  38. INT iCol;
  39. // Move the cursor back.
  40. //
  41. if (hhEmu->emu_curcol > 0)
  42. {
  43. bWide = hhEmu->emu_apAttr[iRow][hhEmu->emu_curcol - 1].wirt ? 2 : 1;
  44. bWide = hhEmu->emu_apAttr[iRow][hhEmu->emu_curcol].wirt ? 0 : bWide;
  45. (*hhEmu->emu_setcurpos)(hhEmu,
  46. hhEmu->emu_currow,
  47. hhEmu->emu_curcol - bWide);
  48. }
  49. // Now see if we need to get rid of the character.
  50. //
  51. if ((hhEmu->stUserSettings.nEmuId == EMU_TTY &&
  52. hhEmu->stUserSettings.fDestructiveBk) || (bWide == 0))
  53. {
  54. if (bWide == 0)
  55. iCol = hhEmu->emu_curcol - 1;
  56. else
  57. iCol = hhEmu->emu_curcol; // account for wide chars this way
  58. hhEmu->emu_code = ETEXT(' ');
  59. (*hhEmu->emu_graphic)(hhEmu);
  60. (*hhEmu->emu_setcurpos)(hhEmu,
  61. hhEmu->emu_currow,
  62. iCol); //MPT:12-8-97 hhEmu->emu_curcol - 1);
  63. }
  64. }
  65. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  66. * FUNCTION:
  67. *
  68. * DESCRIPTION:
  69. *
  70. * ARGUMENTS:
  71. *
  72. * RETURNS:
  73. *
  74. */
  75. void carriagereturn(const HHEMU hhEmu)
  76. {
  77. (*hhEmu->emu_setcurpos)(hhEmu, hhEmu->emu_currow, 0);
  78. }
  79. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  80. * FUNCTION:
  81. *
  82. * DESCRIPTION:
  83. *
  84. * ARGUMENTS:
  85. * iRow -- the row to clear
  86. * Note: Since this function calls row_index() with iRow, DO NOT call this
  87. * function with a row number that was returned by a call to row_index().
  88. * You'll clear the wrong row.
  89. *
  90. * RETURNS:
  91. *
  92. */
  93. void clear_imgrow(const HHEMU hhEmu, int iRow)
  94. {
  95. register int i;
  96. PSTATTR pstAttr;
  97. iRow = row_index(hhEmu, iRow);
  98. ECHAR_Fill(hhEmu->emu_apText[iRow], EMU_BLANK_CHAR, (size_t)MAX_EMUCOLS);
  99. for (i = 0, pstAttr = hhEmu->emu_apAttr[iRow] ; i <= MAX_EMUCOLS ; ++i)
  100. pstAttr[i] = hhEmu->emu_clearattr;
  101. hhEmu->emu_aiEnd[iRow] = EMU_BLANK_LINE;
  102. }
  103. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  104. * FUNCTION:
  105. *
  106. * DESCRIPTION:
  107. *
  108. * ARGUMENTS:
  109. *
  110. * RETURNS:
  111. *
  112. */
  113. void emuLineFeed(const HHEMU hhEmu)
  114. {
  115. ECHAR aechBuf[10];
  116. int iRow = row_index(hhEmu, hhEmu->emu_currow);
  117. if (hhEmu->print_echo)
  118. {
  119. printEchoLine(hhEmu->hPrintEcho,
  120. hhEmu->emu_apText[row_index(hhEmu, hhEmu->emu_currow)],
  121. emuRowLen(hhEmu, iRow));
  122. if (hhEmu->emu_code == ETEXT('\f'))
  123. {
  124. CnvrtMBCStoECHAR(aechBuf, sizeof(aechBuf), TEXT("\f"), StrCharGetByteCount(TEXT("\f")));
  125. printEchoLine(hhEmu->hPrintEcho, aechBuf, sizeof(ECHAR));
  126. }
  127. }
  128. if (hhEmu->mode_LNM)
  129. ANSI_CNL(hhEmu, 1);
  130. else
  131. ANSI_IND(hhEmu);
  132. }
  133. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  134. * emu_print
  135. *
  136. * DESCRIPTION:
  137. * Prints the specified bufr. Opens a print channel if one is not
  138. * already open
  139. *
  140. * ARGUMENTS:
  141. * bufr -- address of bufr to print
  142. * length -- number of chars to print from bufr
  143. *
  144. * RETURNS:
  145. * nothing
  146. */
  147. void emuPrintChars(const HHEMU hhEmu, ECHAR *bufr, int nLen)
  148. {
  149. int nIndex;
  150. ECHAR *tChar;
  151. if (nLen == 0 || bufr == 0)
  152. return;
  153. for (nIndex = 0; nIndex < nLen; nIndex++)
  154. {
  155. tChar = bufr + nIndex;
  156. printEchoChar(hhEmu->hPrintHost, *tChar);
  157. }
  158. return;
  159. }
  160. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  161. * FUNCTION:
  162. *
  163. * DESCRIPTION:
  164. *
  165. * ARGUMENTS:
  166. *
  167. * RETURNS:
  168. *
  169. */
  170. void scrolldown(const HHEMU hhEmu, int nlines)
  171. {
  172. register int row, nrows;
  173. int toprow, botmrow;
  174. int nScrlInc;
  175. if (nlines <= 0)
  176. return;
  177. hhEmu->scr_scrollcnt -= nlines;
  178. nScrlInc = nlines;
  179. toprow = hhEmu->top_margin;
  180. botmrow = hhEmu->bottom_margin;
  181. if (hhEmu->top_margin == 0 && hhEmu->bottom_margin == hhEmu->emu_maxrow)
  182. {
  183. hhEmu->emu_imgtop = row_index(hhEmu, -nlines);
  184. }
  185. else if (nlines < hhEmu->bottom_margin - hhEmu->top_margin + 1)
  186. {
  187. nrows = hhEmu->bottom_margin - hhEmu->top_margin + 1 - nlines;
  188. for (row = hhEmu->bottom_margin; nrows > 0; --nrows, --row)
  189. {
  190. int c;
  191. PSTATTR pstAttr, pstAttr2;
  192. memmove(hhEmu->emu_apText[row_index(hhEmu, row)],
  193. hhEmu->emu_apText[row_index(hhEmu, row - nlines)],
  194. (size_t)(hhEmu->emu_maxcol+2));
  195. hhEmu->emu_aiEnd[row_index(hhEmu, row - nlines)] =
  196. hhEmu->emu_aiEnd[row_index(hhEmu, row)];
  197. pstAttr = hhEmu->emu_apAttr[row_index(hhEmu, row)];
  198. pstAttr2 = hhEmu->emu_apAttr[row_index(hhEmu, row - nlines)];
  199. for (c = 0 ; c <= hhEmu->emu_maxcol ; ++c)
  200. pstAttr[c] = pstAttr2[c];
  201. }
  202. }
  203. for (row = hhEmu->top_margin; nlines > 0; --nlines, ++row)
  204. clear_imgrow(hhEmu, row);
  205. hhEmu->emu_imgrow = row_index(hhEmu, hhEmu->emu_currow);
  206. updateScroll(sessQueryUpdateHdl(hhEmu->hSession),
  207. toprow, botmrow, -nScrlInc, hhEmu->emu_imgtop, TRUE);
  208. }
  209. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  210. * FUNCTION:
  211. *
  212. * DESCRIPTION:
  213. *
  214. * ARGUMENTS:
  215. *
  216. * RETURNS:
  217. *
  218. */
  219. void scrollup(const HHEMU hhEmu, int nlines)
  220. {
  221. register INT row;
  222. INT nrows, iLen, iThisRow;
  223. ECHAR *lp; /* line pointer */
  224. ECHAR aechBuf[10];
  225. INT nScrlInc; /* needed for call to Vid routine at bottom of func */
  226. HBACKSCRL hBackscrl = sessQueryBackscrlHdl(hhEmu->hSession);
  227. HCAPTUREFILE hCapture = sessQueryCaptureFileHdl(hhEmu->hSession);
  228. if (nlines <= 0)
  229. return;
  230. hhEmu->scr_scrollcnt += nlines;
  231. nScrlInc = nlines = min(nlines,
  232. hhEmu->bottom_margin - hhEmu->top_margin + 1);
  233. for (row = hhEmu->top_margin; row < (hhEmu->top_margin + nlines); ++row)
  234. {
  235. iThisRow = row_index(hhEmu, row);
  236. lp = hhEmu->emu_apText[iThisRow];
  237. iLen = emuRowLen(hhEmu, iThisRow);
  238. backscrlAdd(hBackscrl, lp, iLen);
  239. CaptureLine(hCapture, CF_CAP_SCREENS, lp, iLen);
  240. printEchoScreen(hhEmu->hPrintEcho, lp, iLen);
  241. CnvrtMBCStoECHAR(aechBuf, sizeof(aechBuf), TEXT("\r\n"), StrCharGetByteCount(TEXT("\r\n")));
  242. printEchoScreen(hhEmu->hPrintEcho, aechBuf, sizeof(ECHAR) * 2);
  243. clear_imgrow(hhEmu, row);
  244. }
  245. if (hhEmu->top_margin == 0 && hhEmu->bottom_margin == hhEmu->emu_maxrow)
  246. {
  247. hhEmu->emu_imgtop = row_index(hhEmu, nlines);
  248. }
  249. else if (nlines < (hhEmu->bottom_margin - hhEmu->top_margin + 1))
  250. {
  251. nrows = hhEmu->bottom_margin - hhEmu->top_margin + 1 - nlines;
  252. for (row = hhEmu->top_margin; nrows > 0; --nrows, ++row)
  253. {
  254. INT c;
  255. PSTATTR pstAttr, pstAttr2;
  256. memmove(hhEmu->emu_apText[row_index(hhEmu, row)],
  257. hhEmu->emu_apText[row_index(hhEmu, row + nlines)],
  258. (size_t)hhEmu->emu_maxcol + 2);
  259. hhEmu->emu_aiEnd[row_index(hhEmu, row + nlines)] =
  260. hhEmu->emu_aiEnd[row_index(hhEmu, row)];
  261. pstAttr = hhEmu->emu_apAttr[row_index(hhEmu, row)];
  262. pstAttr2 = hhEmu->emu_apAttr[row_index(hhEmu, row + nlines)];
  263. for (c = 0 ; c <= hhEmu->emu_maxcol ; ++c)
  264. pstAttr[c] = pstAttr2[c];
  265. }
  266. for (row = hhEmu->bottom_margin; nlines > 0; --nlines, --row)
  267. clear_imgrow(hhEmu, row);
  268. }
  269. hhEmu->emu_imgrow = row_index(hhEmu, hhEmu->emu_currow);
  270. updateScroll(sessQueryUpdateHdl(hhEmu->hSession),
  271. hhEmu->top_margin,
  272. hhEmu->bottom_margin,
  273. nScrlInc,
  274. hhEmu->emu_imgtop,
  275. TRUE);
  276. return;
  277. }
  278. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  279. * FUNCTION:
  280. *
  281. * DESCRIPTION:
  282. *
  283. * ARGUMENTS:
  284. *
  285. * RETURNS:
  286. *
  287. */
  288. void tab(const HHEMU hhEmu)
  289. {
  290. int col;
  291. col = hhEmu->emu_curcol;
  292. while (col <= hhEmu->emu_maxcol)
  293. if (hhEmu->tab_stop[++col])
  294. break;
  295. (*hhEmu->emu_setcurpos)(hhEmu, hhEmu->emu_currow, col);
  296. }
  297. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  298. * FUNCTION:
  299. *
  300. * DESCRIPTION:
  301. *
  302. * ARGUMENTS:
  303. *
  304. * RETURNS:
  305. *
  306. */
  307. void backtab(const HHEMU hhEmu)
  308. {
  309. int col;
  310. col = hhEmu->emu_curcol;
  311. while (col > 0)
  312. {
  313. if (hhEmu->tab_stop[--col])
  314. {
  315. break;
  316. }
  317. }
  318. (*hhEmu->emu_setcurpos)(hhEmu, hhEmu->emu_currow, col);
  319. }
  320. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  321. * FUNCTION:
  322. *
  323. * DESCRIPTION:
  324. *
  325. * ARGUMENTS:
  326. *
  327. * RETURNS:
  328. *
  329. */
  330. void tabn(const HHEMU hhEmu)
  331. {
  332. int iCol;
  333. int iTabSize;
  334. iCol = hhEmu->emu_curcol;
  335. iTabSize = CLoopGetTabSizeIn(sessQueryCLoopHdl(hhEmu->hSession));
  336. while (iCol <= hhEmu->emu_maxcol)
  337. {
  338. if (++iCol % iTabSize == 0)
  339. break;
  340. }
  341. (*hhEmu->emu_setcurpos)(hhEmu, hhEmu->emu_currow, iCol);
  342. }
  343. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  344. * emu_bell
  345. *
  346. * DESCRIPTION:
  347. * Displays the bell code.
  348. *
  349. * ARGUMENTS:
  350. * none
  351. *
  352. * RETURNS:
  353. * nothing
  354. */
  355. void emu_bell(const HHEMU hhEmu)
  356. {
  357. mscMessageBeep(-1); // Standard Beep
  358. }
  359. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  360. * emu_clearword
  361. *
  362. * DESCRIPTION:
  363. * Clears a part of current line.
  364. *
  365. * ARGUMENTS:
  366. * fromcol -- virtual image column of 1st character to be cleared
  367. * tocol -- virtual image column of last character to be cleared
  368. *
  369. * RETURNS:
  370. * nothing
  371. */
  372. void emu_clearword(const HHEMU hhEmu, int fromcol, int tocol)
  373. {
  374. int c;
  375. STATTR stAttr;
  376. int old_mode_IRM;
  377. (*hhEmu->emu_setcurpos)(hhEmu, hhEmu->emu_currow, fromcol);
  378. old_mode_IRM = hhEmu->mode_IRM;
  379. hhEmu->mode_IRM = RESET; /* overwrite, not insert */
  380. stAttr = hhEmu->attrState[CSCLEAR_STATE];
  381. for (c = fromcol; c <= tocol; ++c)
  382. {
  383. hhEmu->emu_code = ETEXT(' ');
  384. (*hhEmu->emu_graphic)(hhEmu);
  385. }
  386. hhEmu->attrState[CSCLEAR_STATE] = stAttr;
  387. hhEmu->mode_IRM = old_mode_IRM;
  388. (*hhEmu->emu_setcurpos)(hhEmu, hhEmu->emu_currow, fromcol);
  389. }