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.

385 lines
10 KiB

  1. /************************************************************/
  2. /* Windows Write, Copyright 1985-1992 Microsoft Corporation */
  3. /************************************************************/
  4. #define NOCLIPBOARD
  5. #define NOGDICAPMASKS
  6. #define NOCTLMGR
  7. #define NOVIRTUALKEYCODES
  8. #define NOWINMESSAGES
  9. #define NOKEYSTATE
  10. #define NOSYSCOMMANDS
  11. #define NOICON
  12. #define NOATOM
  13. #define NOFONT
  14. #define NOBRUSH
  15. #define NOCLIPBOARD
  16. #define NOCREATESTRUCT
  17. #define NODRAWTEXT
  18. #define NOMB
  19. #define NOMETAFILE
  20. #define NOOPENFILE
  21. #define NOPEN
  22. #define NOREGION
  23. #define NOSOUND
  24. #define NOWH
  25. #define NOWNDCLASS
  26. #define NOCOMM
  27. #define NOFONT
  28. #define NOBRUSH
  29. #include <windows.h>
  30. #include "mw.h"
  31. #define NOUAC
  32. #include "cmddefs.h"
  33. #include "wwdefs.h"
  34. #include "dispdefs.h"
  35. #include "fmtdefs.h"
  36. extern long ropErase;
  37. extern struct WWD *pwwdCur;
  38. extern struct WWD rgwwd[];
  39. extern int wwCur;
  40. extern int docCur;
  41. extern typeCP cpMacCur;
  42. extern struct FLI vfli;
  43. int NEAR FOnScreenRect(RECT *);
  44. /* P U T C P I N W W H Z */
  45. PutCpInWwHz(cp)
  46. typeCP cp;
  47. /* Ensure that cp is in wwCur */
  48. /* Make sure it's not off to left or right, too. */
  49. { /* Just check for horizontal bounding; vertical is done
  50. by call to CpBeginLine below. */
  51. int dxpRoom, xp, xpMin;
  52. int dlT;
  53. typeCP cpBegin;
  54. UpdateWw(wwCur, false);
  55. cpBegin = CpBeginLine(&dlT, cp);
  56. FormatLine(docCur, cpBegin, (**(pwwdCur->hdndl))[dlT].ichCpMin, cpMacCur, flmSandMode);
  57. /* xpMin is a dummy here */
  58. xp = DxpDiff(0, (int)(cp - vfli.cpMin), &xpMin) + vfli.xpLeft;
  59. xpMin = pwwdCur->xpMin;
  60. /* we have: xp = desired position, xpMin = amount of horizontal scroll */
  61. /* width of space in window for text */
  62. dxpRoom = (pwwdCur->xpMac - xpSelBar);
  63. if (xp < xpMin )
  64. { /* cp is left of screen */
  65. AdjWwHoriz(max(0, xp - min(dxpRoom - 1, cxpAuto)) - xpMin);
  66. }
  67. else if (xp >= xpMin + dxpRoom)
  68. { /* cp is right of screen */
  69. register int dxpRoomT = min(xpRightMax, xp + min(dxpRoom - 1, cxpAuto))
  70. - dxpRoom + 1;
  71. AdjWwHoriz(max(0, dxpRoomT) - xpMin);
  72. }
  73. }
  74. /* A D J W W H O R I Z */
  75. AdjWwHoriz(dxpScroll)
  76. int dxpScroll;
  77. {
  78. /* Scroll a window horizontally */
  79. if (dxpScroll != 0)
  80. {
  81. RECT rc;
  82. /* Reset the value of the horizontal scroll bar */
  83. SetScrollPos( pwwdCur->hHScrBar,
  84. pwwdCur->sbHbar,
  85. pwwdCur->xpMin + dxpScroll,
  86. TRUE);
  87. #ifdef ENABLE /* HideSel() */
  88. HideSel();
  89. #endif /* ENABLE */
  90. ClearInsertLine();
  91. SetRect( (LPRECT)&rc, xpSelBar, 0, pwwdCur->xpMac, pwwdCur->ypMac );
  92. ScrollCurWw( &rc, -dxpScroll, 0 );
  93. TrashWw(wwCur);
  94. pwwdCur->xpMin += dxpScroll;
  95. if (pwwdCur->fRuler)
  96. {
  97. UpdateRuler();
  98. }
  99. }
  100. }
  101. /* Scroll specified subrectangle of current window by specified amount */
  102. #include <stdlib.h>
  103. ScrollCurWw( prc, dxp, dyp )
  104. register RECT *prc;
  105. int dxp,dyp;
  106. {
  107. extern int vfScrollInval;
  108. RECT rcClear;
  109. if (dxp && dyp)
  110. return; /* Scroll in both dimensions is an illegal case */
  111. if (!(dxp || dyp))
  112. return; /* no scrolling to do */
  113. #if 1
  114. /**
  115. The previous old, old code was getting flaky. (7.14.91) v-dougk
  116. **/
  117. if (ScrollDC(pwwdCur->hDC,dxp,dyp,(LPRECT)prc,(LPRECT)prc,NULL,&rcClear))
  118. {
  119. PatBlt( pwwdCur->hDC, rcClear.left, rcClear.top,
  120. rcClear.right-rcClear.left+1, rcClear.bottom-rcClear.top+1, ropErase );
  121. if (dxp)
  122. vfScrollInval = FALSE;
  123. else
  124. vfScrollInval = (rcClear.bottom-rcClear.top+1) > abs(dyp);
  125. if (vfScrollInval)
  126. {
  127. InvalidateRect(pwwdCur->wwptr,&rcClear,FALSE);
  128. UpdateInvalid();
  129. }
  130. }
  131. else
  132. vfScrollInval = FALSE;
  133. return;
  134. #else
  135. int FCheckPopupRect( HWND, LPRECT );
  136. extern int vfScrollInval;
  137. HDC hDC;
  138. int dxpAbs = (dxp < 0) ? -dxp : dxp;
  139. int dypAbs = (dyp < 0) ? -dyp : dyp;
  140. struct RS { int left, top, cxp, cyp; }
  141. rsSource, rsDest, rsClear;
  142. /* Set rsSource, rsDest, rsClear == prc */
  143. if ((rsSource.cxp = imin( prc->right, pwwdCur->xpMac ) -
  144. (rsSource.left = imax( 0, prc->left ))) <= 0)
  145. /* Rectangle is null or illegal in X-dimension */
  146. return;
  147. if ((rsSource.cyp = imin( prc->bottom, pwwdCur->ypMac ) -
  148. (rsSource.top = imax( pwwdCur->ypMin, prc->top ))) <= 0)
  149. /* Rectangle is null or illegal in Y-dimension */
  150. return;
  151. bltbyte( &rsSource, &rsDest, sizeof (struct RS ));
  152. bltbyte( &rsSource, &rsClear, sizeof (struct RS ));
  153. hDC = pwwdCur->hDC;
  154. if ((dxpAbs < rsSource.cxp) && (dypAbs < rsSource.cyp))
  155. { /* A Real scroll, not the bogus case when we just clear exposed area */
  156. /* NOTE: We do not bother to compute rsSource.cxp or rsSource.cyp,
  157. as they are not needed by BitBlt or PatBlt */
  158. /* If there are PopUp windows, use ScrollWindow to avoid getting
  159. bogus bits from some popup. Since this is slow, only do it if there
  160. is some popup that overlaps the scroll rect */
  161. if ( AnyPopup() )
  162. {
  163. extern HANDLE hMmwModInstance;
  164. static FARPROC lpFCheckPopupRect = (FARPROC)NULL;
  165. /* First time through, inz ptr to thunk */
  166. if (lpFCheckPopupRect == NULL)
  167. lpFCheckPopupRect = MakeProcInstance( (FARPROC) FCheckPopupRect,
  168. hMmwModInstance );
  169. EnumWindows( lpFCheckPopupRect, (LONG) (LPRECT) prc );
  170. }
  171. /* Under windows 2.0, must also check for any part of the scroll
  172. rectangle being off the screen (not possible in tiling environment).
  173. If so, use ScrollWindow to avoid getting bogus bits from outside
  174. the screen. */
  175. if (!FOnScreenRect( prc ))
  176. vfScrollInval = TRUE;
  177. if (vfScrollInval)
  178. { /* vfScrollInval also tells UpdateWw that invalid region
  179. may have changed */
  180. extern BOOL vfEraseWw;
  181. ScrollWindow( pwwdCur->wwptr, dxp, dyp, (LPRECT)prc, (LPRECT)prc );
  182. vfEraseWw = TRUE;
  183. UpdateInvalid(); /* Marks repaint area as invalid in our
  184. structures so we don't think bits grabbed
  185. from a popup are valid */
  186. vfEraseWw = FALSE;
  187. return;
  188. }
  189. if (dxp != 0)
  190. rsDest.cxp -= (rsClear.cxp = dxpAbs);
  191. else
  192. /* dxp==dyp==0 case is caught below */
  193. rsDest.cyp -= (rsClear.cyp = dypAbs);
  194. if (dxp < 0)
  195. {
  196. rsSource.left += dxpAbs;
  197. rsClear.left += rsDest.cxp;
  198. }
  199. else if (dxp > 0)
  200. {
  201. rsDest.left += dxpAbs;
  202. }
  203. else if (dyp < 0)
  204. {
  205. rsSource.top += dypAbs;
  206. rsClear.top += rsDest.cyp;
  207. }
  208. else if (dyp > 0)
  209. {
  210. rsDest.top += dypAbs;
  211. }
  212. else
  213. return;
  214. BitBlt( hDC,
  215. rsDest.left, rsDest.top,
  216. rsDest.cxp, rsDest.cyp,
  217. hDC,
  218. rsSource.left, rsSource.top,
  219. SRCCOPY );
  220. }
  221. #ifdef SMFONT
  222. /* Vertical refresh will be so bindingly fast, that we do not need to erase the
  223. old text. */
  224. if (dxp != 0)
  225. {
  226. PatBlt(hDC, rsClear.left, rsClear.top, rsClear.cxp, rsClear.cyp, ropErase);
  227. }
  228. #else /* not SMFONT */
  229. PatBlt( hDC, rsClear.left, rsClear.top, rsClear.cxp, rsClear.cyp, ropErase );
  230. #endif /* SMFONT */
  231. #endif
  232. }
  233. int FCheckPopupRect( hwnd, lprc )
  234. HWND hwnd;
  235. LPRECT lprc;
  236. { /* If the passed window is not a popup, return TRUE;
  237. If the passed window is a popup, and its coordinates overlap
  238. those of the passed rect, set vfScrollInval to TRUE and return FALSE.
  239. Otherwise, return TRUE.
  240. This is a window enumeration function: a return of TRUE means
  241. continue enumerating windows, a return of FALSE means
  242. stop the enumeration */
  243. extern int vfScrollInval;
  244. RECT rc;
  245. POINT ptTopLeft, ptBottomRight;
  246. RECT rcResult;
  247. if ( !(GetWindowLong( hwnd, GWL_STYLE ) & WS_POPUP) )
  248. /* Window is not a popup */
  249. return TRUE;
  250. /* Get popup rectangle in screen coordinates */
  251. GetWindowRect( hwnd, (LPRECT) &rc );
  252. /* Convert rc from screen coordinates to current document window coordinates */
  253. ptTopLeft.x = rc.left;
  254. ptTopLeft.y = rc.top;
  255. ptBottomRight.x = rc.right;
  256. ptBottomRight.y = rc.bottom;
  257. ScreenToClient( pwwdCur->wwptr, (LPPOINT) &ptTopLeft );
  258. ScreenToClient( pwwdCur->wwptr, (LPPOINT) &ptBottomRight );
  259. rc.left = ptTopLeft.x;
  260. rc.top = ptTopLeft.y;
  261. rc.right = ptBottomRight.x;
  262. rc.bottom = ptBottomRight.y;
  263. IntersectRect( (LPRECT) &rcResult, (LPRECT) &rc, (LPRECT)lprc );
  264. if ( !IsRectEmpty( (LPRECT) &rcResult ) )
  265. { /* Popup overlaps passed rectangle */
  266. vfScrollInval = TRUE;
  267. return FALSE;
  268. }
  269. return TRUE;
  270. }
  271. /* S C R O L L L E F T */
  272. ScrollLeft(dxp)
  273. int dxp;
  274. { /* Scroll current window left dxp pixels */
  275. if ((dxp = min(xpRightLim - pwwdCur->xpMin, dxp)) >0)
  276. AdjWwHoriz(dxp);
  277. else
  278. _beep();
  279. }
  280. /* S C R O L L R I G H T */
  281. ScrollRight(dxp)
  282. int dxp;
  283. {
  284. if ((dxp = min(pwwdCur->xpMin, dxp)) > 0)
  285. AdjWwHoriz(-dxp);
  286. else
  287. _beep();
  288. }
  289. /* F O N S C R E E N R E C T
  290. Returns TRUE iff the rectangle is entirely within the screen
  291. boundaries.
  292. Assumes the rectangle belongs to the current window.
  293. */
  294. int NEAR
  295. FOnScreenRect(prc)
  296. register RECT *prc;
  297. {
  298. POINT ptTopLeft, ptBottomRight;
  299. int cxScreen = GetSystemMetrics( SM_CXSCREEN );
  300. int cyScreen = GetSystemMetrics( SM_CYSCREEN );
  301. ptTopLeft.x = prc->left;
  302. ptTopLeft.y = prc->top;
  303. ptBottomRight.x = prc->right;
  304. ptBottomRight.y = prc->bottom;
  305. ClientToScreen( pwwdCur->wwptr, (LPPOINT) &ptTopLeft );
  306. ClientToScreen( pwwdCur->wwptr, (LPPOINT) &ptBottomRight );
  307. if ((ptTopLeft.x <= 0) || (ptTopLeft.y <= 0) ||
  308. (ptBottomRight.x >= cxScreen) || (ptBottomRight.y >= cyScreen))
  309. return FALSE;
  310. return TRUE;
  311. }
  312.