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.

511 lines
14 KiB

  1. /* Copyright (c) 1987 - 1988, Future Soft Engineering, Inc. */
  2. /* Houston, Texas */
  3. /*===========================================================================*/
  4. #define NOLSTRING TRUE /* jtf win3 mod */
  5. #include <windows.h>
  6. #include "port1632.h"
  7. #include "dcrc.h"
  8. #include "dynacomm.h"
  9. /*---------------------------------------------------------------------------*/
  10. BOOL insertionPoint;
  11. LONG anchorNdx, lastNdx;
  12. /*---------------------------------------------------------------------------*/
  13. /* pointToLong() - Convert coordinates (pt.x, pt.y) relative to the */
  14. /* current display to an absolute buffer index. */
  15. /*---------------------------------------------------------------------------*/
  16. VOID pointToLong(POINT pt, LONG *l)
  17. {
  18. INT row, col;
  19. if((col = ((pt.x + (chrWidth / 2) - 1) / chrWidth) + curLeftCol) < 0)
  20. col = 0;
  21. else if(col > maxChars)
  22. col = maxChars;
  23. if((row = (pt.y / chrHeight) + curTopLine) < 0)
  24. row = 0;
  25. else if(row > maxLines)
  26. {
  27. row = maxLines;
  28. col = 0;
  29. }
  30. *l = (row * (maxChars + 2)) + col;
  31. }
  32. /*---------------------------------------------------------------------------*/
  33. /* rcToPoint () - Convert absolute rc.row, rc.col to coordinates (GDI) */
  34. /* relative to the currently displayed portion of the buffer. */
  35. /*---------------------------------------------------------------------------*/
  36. VOID rcToPoint (ROWCOL rc, POINT *pt, INT bottom)
  37. {
  38. pt->y = hTE.viewRect.top + (rc.row - curTopLine) * chrHeight + bottom;
  39. pt->x = hTE.viewRect.left + (rc.col - curLeftCol) * chrWidth;
  40. }
  41. /*---------------------------------------------------------------------------*/
  42. /* rcToPointS () - Convert absolute rc.row, rc.col to coordinates (GDI) */
  43. /* relative to the currently displayed portion of the buffer. */
  44. /*---------------------------------------------------------------------------*/
  45. #ifdef NOMORE
  46. VOID rcToPointS (ROWCOL rc, POINT *pt, INT bottom)
  47. {
  48. pt->y = hTE.viewRect.top + (rc.row - curTopLine) * chrHeight + bottom;
  49. pt->x = hTE.viewRect.left + (rc.col - curLeftCol) * chrWidth;
  50. }
  51. #endif
  52. /*---------------------------------------------------------------------------*/
  53. /* longToPoint () - Convert selection to coordinates relative */
  54. /* to the currently displayed portion of the buffer. */
  55. /*---------------------------------------------------------------------------*/
  56. VOID longToPoint(LONG sel, POINT *pt)
  57. {
  58. ROWCOL rc;
  59. rc.row = sel / (maxChars + 2);
  60. if((rc.col = sel % (maxChars + 2)) > maxChars)
  61. rc.col = maxChars;
  62. rcToPoint(rc, pt, 0);
  63. }
  64. /*---------------------------------------------------------------------------*/
  65. /* hiliteSelect() - */
  66. /*---------------------------------------------------------------------------*/
  67. VOID NEAR invertSelectRect(NPRECT pRect)
  68. {
  69. INT viewRectEnd, offset;
  70. viewRectEnd = hTE.viewRect.bottom;
  71. if((offset = (curTopLine + visScreenLine) - (savTopLine + maxScreenLine)) > 0)
  72. viewRectEnd -= (offset * chrHeight);
  73. if(pRect->top > viewRectEnd)
  74. pRect->top = viewRectEnd;
  75. if(pRect->bottom > viewRectEnd)
  76. pRect->bottom = viewRectEnd;
  77. InvertRect(thePort, (LPRECT) pRect);
  78. }
  79. VOID hiliteSelect(LONG lSelStart, LONG lSelEnd)
  80. {
  81. ROWCOL selStart, selEnd;
  82. RECT hiliteRect;
  83. getPort();
  84. selStart.row = lSelStart / (maxChars + 2);
  85. selStart.col = lSelStart % (maxChars + 2);
  86. selEnd.row = lSelEnd / (maxChars + 2);
  87. selEnd.col = lSelEnd % (maxChars + 2);
  88. if(lSelEnd > lSelStart)
  89. {
  90. if(selStart.row == selEnd.row)
  91. {
  92. rcToPoint(selStart, (PPOINT) &hiliteRect.left, 0);
  93. rcToPoint(selEnd, (PPOINT) &hiliteRect.right, chrHeight);
  94. invertSelectRect(&hiliteRect);
  95. }
  96. else
  97. {
  98. rcToPoint(selStart, (PPOINT) &hiliteRect.left, 0);
  99. selStart.col = maxChars;
  100. rcToPoint(selStart, (PPOINT) &hiliteRect.right, chrHeight);
  101. invertSelectRect(&hiliteRect);
  102. selStart.row += 1;
  103. selStart.col = 0;
  104. if(selEnd.row > selStart.row)
  105. {
  106. rcToPoint(selStart, (PPOINT) &hiliteRect.left, 0);
  107. selStart.row = selEnd.row - 1;
  108. selStart.col = maxChars;
  109. rcToPoint(selStart, (PPOINT) &hiliteRect.right, chrHeight);
  110. invertSelectRect(&hiliteRect);
  111. selStart.col = 0;
  112. }
  113. if(selStart.col != selEnd.col)
  114. {
  115. selStart.row = selEnd.row;
  116. rcToPoint(selStart, (PPOINT) &hiliteRect.left, 0);
  117. rcToPoint(selEnd, (PPOINT) &hiliteRect.right, chrHeight);
  118. invertSelectRect(&hiliteRect);
  119. }
  120. }
  121. }
  122. else if((lSelEnd == lSelStart) && insertionPoint)
  123. {
  124. rcToPoint(selStart, (PPOINT) &hiliteRect.left, 0);
  125. rcToPoint(selEnd, (PPOINT) &hiliteRect.right, chrHeight);
  126. hiliteRect.right += GetSystemMetrics(SM_CXBORDER);
  127. invertSelectRect(&hiliteRect);
  128. }
  129. releasePort();
  130. }
  131. /*---------------------------------------------------------------------------*/
  132. /* termActivate() - */
  133. /*---------------------------------------------------------------------------*/
  134. VOID termActivate (tEHandle *hTE)
  135. {
  136. if (!hTE->active)
  137. {
  138. hiliteSelect (hTE->selStart, hTE->selEnd);
  139. hTE->active = TRUE;
  140. }
  141. }
  142. /*---------------------------------------------------------------------------*/
  143. /* termDeactivate() - */
  144. /*---------------------------------------------------------------------------*/
  145. VOID termDeactivate (tEHandle *hTE)
  146. {
  147. if (hTE->active)
  148. {
  149. hiliteSelect (hTE->selStart, hTE->selEnd);
  150. hTE->active = FALSE;
  151. }
  152. }
  153. /*---------------------------------------------------------------------------*/
  154. /* termSetSelect() - */
  155. /*---------------------------------------------------------------------------*/
  156. VOID termSetSelect (LONG selStart, LONG selEnd)
  157. {
  158. LONG eob;
  159. eob = maxLines * (maxChars + 2);
  160. if (selStart > eob)
  161. selStart = eob;
  162. if (selEnd > eob)
  163. selEnd = eob;
  164. if (hTE.active)
  165. {
  166. hiliteSelect (hTE.selStart, hTE.selEnd);
  167. hiliteSelect (selStart, selEnd);
  168. }
  169. hTE.selStart = selStart;
  170. hTE.selEnd = selEnd;
  171. }
  172. /*---------------------------------------------------------------------------*/
  173. /* extendSelect () - */
  174. /*---------------------------------------------------------------------------*/
  175. VOID extendSelect (LONG anchorRc, LONG lastRc)
  176. {
  177. if (lastRc < hTE.selStart)
  178. {
  179. if (anchorRc == hTE.selStart)
  180. termSetSelect (lastRc, anchorRc);
  181. else
  182. {
  183. hiliteSelect (lastRc, hTE.selStart);
  184. hTE.selStart = lastRc;
  185. }
  186. }
  187. else if (lastRc > hTE.selEnd)
  188. {
  189. if (anchorRc == hTE.selEnd)
  190. termSetSelect (anchorRc, lastRc);
  191. else
  192. {
  193. hiliteSelect (hTE.selEnd, lastRc);
  194. hTE.selEnd = lastRc;
  195. }
  196. }
  197. else
  198. {
  199. if (anchorRc == hTE.selStart)
  200. {
  201. hiliteSelect (lastRc, hTE.selEnd);
  202. hTE.selEnd = lastRc;
  203. }
  204. else
  205. {
  206. hiliteSelect (hTE.selStart, lastRc);
  207. hTE.selStart = lastRc;
  208. }
  209. }
  210. }
  211. /*---------------------------------------------------------------------------*/
  212. /* keyBoardToMouse() - */
  213. /*---------------------------------------------------------------------------*/
  214. VOID keyBoardToMouse(INT partCode) /* mbbx 2.01.185 ... */
  215. {
  216. DEBOUT("keyBoardToMouse(): %s\n","TAKE CARE OF LastPoint MPOIN/POINT");
  217. switch(partCode)
  218. {
  219. case VK_LEFT:
  220. if((lastPoint.x > 0) || (curLeftCol > 0))
  221. {
  222. lastPoint.x -= chrWidth;
  223. break;
  224. }
  225. /* else fall thru... */
  226. case VK_UP:
  227. if((lastPoint.y > 0) || (curTopLine > 0))
  228. {
  229. lastPoint.y -= chrHeight;
  230. if(partCode == VK_LEFT)
  231. lastPoint.x = (maxChars * chrWidth);
  232. }
  233. else
  234. MessageBeep(0);
  235. break;
  236. case VK_RIGHT:
  237. case VK_DOWN:
  238. if(lastPoint.y <= (((savTopLine + maxScreenLine) - curTopLine) * chrHeight))
  239. {
  240. if((partCode == VK_RIGHT) &&
  241. (lastPoint.x < ((maxChars - curLeftCol) * chrWidth)))
  242. {
  243. lastPoint.x += chrWidth;
  244. }
  245. else if(((lastPoint.y += chrHeight) > (((savTopLine + maxScreenLine) -
  246. curTopLine) * chrHeight)) || (partCode == VK_RIGHT))
  247. {
  248. lastPoint.x = -((curLeftCol + 1) * chrWidth);
  249. }
  250. }
  251. else
  252. MessageBeep(0);
  253. break;
  254. }
  255. }
  256. /*---------------------------------------------------------------------------*/
  257. /* termClick() - Handles mouse & keyboard for selection ranges. */
  258. /*---------------------------------------------------------------------------*/
  259. VOID hideInsertionPoint()
  260. {
  261. if(hTE.selStart == hTE.selEnd)
  262. hiliteSelect(hTE.selStart, hTE.selEnd);
  263. insertionPoint = FALSE;
  264. }
  265. /*---------------------------------------------------------------------------*/
  266. BOOL stillDown(BOOL keyboard)
  267. {
  268. MSG msg;
  269. BOOL result;
  270. result = TRUE;
  271. if (!keyboard)
  272. {
  273. if (PeekMessage(&msg, hTermWnd, WM_MOUSEFIRST, WM_MOUSELAST, TRUE))
  274. {
  275. switch (msg.message)
  276. {
  277. case WM_LBUTTONUP:
  278. result = FALSE;
  279. break;
  280. case WM_MOUSEMOVE:
  281. // lastPoint = MAKEMPOINT(msg.lParam);
  282. lastPoint.x = (LONG)LOWORD(msg.lParam);
  283. lastPoint.y = (LONG)HIWORD(msg.lParam);
  284. break;
  285. }
  286. }
  287. }
  288. else
  289. result = FALSE;
  290. return result;
  291. }
  292. /*---------------------------------------------------------------------------*/
  293. VOID showInsertionPoint()
  294. {
  295. insertionPoint = TRUE;
  296. if(hTE.selStart == hTE.selEnd)
  297. hiliteSelect(hTE.selStart, hTE.selEnd);
  298. }
  299. /*---------------------------------------------------------------------------*/
  300. VOID termClick(POINT anchorPt, BOOL extend, INT partCode)
  301. {
  302. BOOL keyboard;
  303. if (scrapSeq || ((xferFlag != XFRNONE) && (xferFlag != XFRRCV)) )
  304. return;
  305. hideInsertionPoint();
  306. if(keyboard = (partCode != 0))
  307. {
  308. if((hTE.selStart == hTE.selEnd) && !extend)
  309. {
  310. if(anchorPt.y < 0)
  311. anchorPt.y = 0;
  312. else if(anchorPt.y > ((visScreenLine + 1) * chrHeight))
  313. anchorPt.y = ((visScreenLine + 1) * chrHeight);
  314. lastPoint = anchorPt;
  315. pointToLong(anchorPt, &anchorNdx);
  316. termSetSelect(anchorNdx, anchorNdx);
  317. }
  318. else
  319. {
  320. longToPoint(lastNdx, &lastPoint);
  321. if(lastNdx == hTE.selStart)
  322. anchorNdx = hTE.selEnd;
  323. else
  324. anchorNdx = hTE.selStart;
  325. }
  326. keyBoardToMouse(partCode);
  327. }
  328. else
  329. {
  330. SetCapture(hTermWnd);
  331. lastPoint = anchorPt;
  332. pointToLong(anchorPt, &anchorNdx);
  333. if(extend)
  334. {
  335. if(anchorNdx >= hTE.selStart)
  336. anchorNdx = hTE.selStart;
  337. else
  338. anchorNdx = hTE.selEnd;
  339. }
  340. else
  341. termSetSelect(anchorNdx, anchorNdx);
  342. }
  343. repeat
  344. {
  345. pointToLong(lastPoint, &lastNdx);
  346. pasClikLoop();
  347. if(keyboard && !extend)
  348. {
  349. anchorNdx = lastNdx;
  350. termSetSelect(lastNdx, lastNdx);
  351. }
  352. else
  353. extendSelect(anchorNdx, lastNdx);
  354. }
  355. until(!stillDown(keyboard));
  356. if(!keyboard)
  357. ReleaseCapture();
  358. showInsertionPoint();
  359. }
  360. /*---------------------------------------------------------------------------*/
  361. /* getPort() - */
  362. /*---------------------------------------------------------------------------*/
  363. HDC getPort ()
  364. {
  365. if (thePort == 0)
  366. {
  367. thePort = GetDC (hTermWnd);
  368. SelectObject (thePort, hTE.hFont);
  369. portLocks = 1;
  370. }
  371. else
  372. portLocks++;
  373. return thePort;
  374. }
  375. /*---------------------------------------------------------------------------*/
  376. /* releasePort() - */
  377. /*---------------------------------------------------------------------------*/
  378. VOID releasePort ()
  379. {
  380. if (--portLocks <= 0)
  381. {
  382. ReleaseDC (hTermWnd,thePort);
  383. thePort = 0;
  384. }
  385. }
  386. /*---------------------------------------------------------------------------*/
  387. /* pasClickLoop() - */
  388. /*---------------------------------------------------------------------------*/
  389. BOOL APIENTRY pasClikLoop() /* mbbx 2.01.185 ... */
  390. {
  391. INT ndx;
  392. POINT PointL;
  393. if (lastPoint.y < hTE.viewRect.top - chrHeight)
  394. lastPoint.y = hTE.viewRect.top - chrHeight; /* jtf 3.21 */
  395. if (lastPoint.y > hTE.viewRect.bottom)
  396. lastPoint.y = hTE.viewRect.bottom; /* jtf 3.21 */
  397. /* changed &hTE.viewRect to &(hTE.viewRect) to see if error goes -sdj */
  398. /* Actual error was due to lastPoint being MPOINT ie POINTS, changed type -sdj */
  399. /* changed lastPoint back to MPOINT and taking care of conversion here -sdj*/
  400. if(!PtInRect((LPRECT) &(hTE.viewRect), lastPoint))
  401. {
  402. for(ndx = lastPoint.y; ndx < hTE.viewRect.top; ndx += chrHeight)
  403. trackScroll(SB_VERT, SB_LINEUP);
  404. while(ndx >= hTE.viewRect.bottom)
  405. {
  406. trackScroll(SB_VERT, SB_LINEDOWN);
  407. ndx -= chrHeight;
  408. }
  409. for(ndx = lastPoint.x; ndx < hTE.viewRect.left; ndx += chrWidth)
  410. trackScroll(SB_HORZ, SB_LINEUP);
  411. while(ndx >= hTE.viewRect.right)
  412. {
  413. trackScroll(SB_HORZ, SB_LINEDOWN);
  414. ndx -= chrWidth;
  415. }
  416. scrollBits();
  417. }
  418. return(TRUE);
  419. }