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.

372 lines
11 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 NOWINSTYLES
  10. #define NOSYSMETRICS
  11. #define NOMENUS
  12. #include <windows.h>
  13. #include "mw.h"
  14. #include "cmddefs.h"
  15. #include "dispdefs.h"
  16. #include "wwdefs.h"
  17. #include "docdefs.h"
  18. #include "propdefs.h"
  19. #include "fmtdefs.h"
  20. #include "printdef.h" /* printdefs.h */
  21. /* E X T E R N A L S */
  22. extern int wwCur;
  23. extern struct WWD rgwwd[];
  24. extern struct DOD (**hpdocdod)[];
  25. extern struct SEL selCur;
  26. extern int docCur;
  27. extern int vdocPageCache;
  28. extern typeCP vcpMinPageCache;
  29. extern typeCP vcpMacPageCache;
  30. extern int vipgd;
  31. extern struct WWD *pwwdCur;
  32. extern typeCP cpMinCur;
  33. extern typeCP cpMacCur;
  34. extern int docMode;
  35. extern int vfPictSel;
  36. extern int vfSizeMode;
  37. extern struct PAP vpapAbs;
  38. extern typeCP vcpLimParaCache;
  39. extern struct CHP vchpFetch;
  40. extern struct CHP vchpSel;
  41. extern struct FLI vfli;
  42. extern int ichpMacFormat;
  43. extern struct CHP (**vhgchpFormat)[];
  44. extern int wwMac;
  45. extern int docScrap;
  46. extern int docUndo;
  47. extern CHAR (**vhrgbSave)[];
  48. /* N E W C U R W W */
  49. NewCurWw(ww, fHighlight)
  50. int ww, fHighlight;
  51. {
  52. extern HWND vhWnd;
  53. struct PGTB **hpgtb;
  54. Assert( (ww >= 0) && (ww < wwMac) );
  55. if ( wwCur != wwNil )
  56. { /* Clean up from old window */
  57. /* Discard the screen fonts. */
  58. FreeFonts( TRUE, FALSE );
  59. pwwdCur->sel = selCur;
  60. }
  61. if (ww >= 0)
  62. {
  63. docCur = (pwwdCur = &rgwwd[wwCur = ww])->doc;
  64. vhWnd = pwwdCur->wwptr;
  65. /* If the new current document has no page table or has no page descriptors */
  66. /* in its page table, all text in the document is considered to be on */
  67. /* page 1 of the document. In this case, preload the cache used by */
  68. /* procedure CachePage. */
  69. hpgtb = (**hpdocdod)[docCur].hpgtb;
  70. if (hpgtb == 0 || (**hpgtb).cpgd == 0)
  71. {
  72. vdocPageCache = docCur;
  73. vcpMinPageCache = cp0;
  74. vcpMacPageCache = cpMax;
  75. vipgd = -1;
  76. }
  77. #ifdef ENABLE /* we now do if in ChangeWwDoc where it is more appropriate */
  78. /* Since we are changing windows, ensure that we don't use parameters
  79. set by a search in a previous window by setting flag false */
  80. vfDidSearch = false;
  81. cpWall = selCur.cpLim;
  82. #endif
  83. /* active bit is valid only in upper panes. Means when window is active
  84. upper pane is active. False means lower pane is active */
  85. #ifdef SPLITTERS
  86. if (pwwdCur->fLower)
  87. rgwwd[pwwdCur->ww].fActive = fFalse;
  88. else
  89. #endif
  90. pwwdCur->fActive = fTrue;
  91. selCur = pwwdCur->sel;
  92. #ifdef ENABLE
  93. if (pwwdCur->fFtn)
  94. { /* It's a footnote window */
  95. cpMinCur = pwwdCur->cpMin;
  96. cpMacCur = pwwdCur->cpMac;
  97. if (fHighlight &&
  98. ((selCur.cpFirst < cpMinCur) ||
  99. (selCur.cpLim > cpMacCur)))
  100. {
  101. Select(cpMinCur, CpLastStyChar(cpMinCur));
  102. }
  103. }
  104. else
  105. #endif
  106. #ifdef ONLINEHELP
  107. if (ww == wwHelp)
  108. { /* It's the help document window */
  109. /* Limit cp range to the current help topic */
  110. cpMinCur = pwwdCur->cpMin;
  111. cpMacCur = pwwdCur->cpMac;
  112. }
  113. else
  114. #endif
  115. if (ww == wwClipboard)
  116. { /* Displaying the clipboard contents */
  117. cpMinCur = cp0;
  118. cpMacCur = CpMacText( docScrap );
  119. Assert( docCur == docScrap );
  120. goto SetWwCps;
  121. }
  122. else
  123. { /* Normal window -- editing document, header, or footer */
  124. Assert( !(pwwdCur->fEditFooter && pwwdCur->fEditHeader) );
  125. ValidateHeaderFooter( docCur );
  126. if (pwwdCur->fEditHeader)
  127. {
  128. extern typeCP cpMinHeader, cpMacHeader;
  129. cpMinCur = cpMinHeader;
  130. cpMacCur = cpMacHeader - ccpEol;
  131. }
  132. else if (pwwdCur->fEditFooter)
  133. {
  134. extern typeCP cpMinFooter, cpMacFooter;
  135. cpMinCur = cpMinFooter;
  136. cpMacCur = cpMacFooter - ccpEol;
  137. }
  138. else
  139. { /* Editing document */
  140. extern typeCP cpMinDocument;
  141. cpMinCur = cpMinDocument;
  142. cpMacCur = CpMacText( docCur );
  143. }
  144. SetWwCps:
  145. cpMacCur = CpMax( cpMacCur, cpMinCur );
  146. pwwdCur->cpMin = cpMinCur;
  147. pwwdCur->cpMac = cpMacCur;
  148. }
  149. }
  150. #ifdef ENABLE /* wwCur change is sensed in CtrBackTrs so we don't
  151. trash the cache until we really have to */
  152. TrashCache(); /* Cache valid for wwCur only */
  153. #endif
  154. #ifdef ENABLE /* We only switch among doc, clipbrd, help - no need */
  155. docMode = docNil; /* Invalidate page display */
  156. #endif
  157. vfSizeMode = false;
  158. if (selCur.cpFirst >= cp0)
  159. {
  160. if ((selCur.cpFirst == selCur.cpLim) && (docCur != docScrap) )
  161. GetInsPtProps(selCur.cpFirst);
  162. CachePara(docCur, selCur.cpFirst);
  163. vfPictSel = vpapAbs.fGraphics &&
  164. (selCur.cpLim == vcpLimParaCache);
  165. }
  166. #ifdef ENABLE
  167. if (fHighlight)
  168. { /* Shrink heap blocks for FormatLine. Call this when it's
  169. possible that the contents of the screen have gotten less complex */
  170. if (ichpMacFormat > 2 * ichpMacInitFormat)
  171. { /* If it's not that big, don't worry about it */
  172. vfli.doc = docNil;
  173. ichpMacFormat = ichpMacInitFormat;
  174. FChngSizeH(vhgchpFormat, ichpMacInitFormat * cwCHP, true);
  175. }
  176. }
  177. #endif /* ENABLE */
  178. }
  179. WwAlloc( hWnd, doc )
  180. HWND hWnd;
  181. int doc;
  182. { /* Allocate a new ww entry. This is used in MEMO for the clipboard
  183. and for the HELP document window. Some of the code is specific
  184. to these windows (e.g. "style" scroll bars used instead of controls)
  185. WARNING: The caller must set the scroll bar range 0-drMax;
  186. MEMO does NOT use the windows default values and we don't set them
  187. here because of the clipboard */
  188. #define dlMaxGuess 10
  189. extern int wwMac;
  190. extern int wwCur;
  191. extern struct WWD rgwwd[];
  192. extern struct WWD *pwwdCur;
  193. extern int docScrap;
  194. int ww;
  195. register struct WWD *pwwd;
  196. if (wwMac >= wwMax)
  197. {
  198. Assert( FALSE );
  199. return wwNil;
  200. }
  201. pwwd = &rgwwd[ ww = wwMac ];
  202. /* Start with all fields == 0 */
  203. bltc( pwwd, 0, cwWWDclr );
  204. pwwd->doc = doc;
  205. /* Set the remaining fields as in [CREATEWW] WwNew */
  206. if (FNoHeap( pwwd->hdndl=(struct EDL (**)[])HAllocate(dlMaxGuess * cwEDL) ))
  207. return wwNil;
  208. bltc( *(pwwd->hdndl), 0, dlMaxGuess * cwEDL );
  209. pwwd->dlMac = pwwd->dlMax = dlMaxGuess;
  210. pwwd->hHScrBar = pwwd->hVScrBar = pwwd->wwptr = hWnd;
  211. pwwd->sbHbar = SB_HORZ;
  212. pwwd->sbVbar = SB_VERT;
  213. pwwd->fDirty = TRUE;
  214. pwwd->fActive = TRUE;
  215. pwwd->sel.fForward = TRUE;
  216. pwwd->cpMac = CpMacText( pwwd->doc );
  217. pwwd->ypFirstInval = ypMaxAll; /* See WwNew() */
  218. wwMac++;
  219. return ww;
  220. }
  221. FreeWw( ww )
  222. register int ww;
  223. { /* Free the wwd entry for the clipboard or help window. Close up
  224. rgwwd & null out wwClipboard or wwHelp, as appropriate */
  225. if (ww == wwDocument)
  226. {
  227. Assert( FALSE );
  228. return;
  229. }
  230. FreeH( rgwwd [ww].hdndl );
  231. if (ww == wwClipboard)
  232. wwClipboard = wwNil;
  233. #ifdef ONLINEHELP
  234. else if (ww == wwHelp)
  235. wwHelp = wwNil;
  236. #endif
  237. else
  238. Assert( FALSE );
  239. if (ww < --wwMac)
  240. { /* Left hole in wwd structure, close it up */
  241. bltbyte( &rgwwd[ ww + 1], &rgwwd[ ww ],
  242. sizeof( struct WWD ) * (wwMac - ww) );
  243. if (wwClipboard > ww)
  244. wwClipboard--;
  245. #ifdef ONLINEHELP
  246. else if (wwHelp > ww)
  247. wwHelp--;
  248. #endif
  249. else
  250. Assert( FALSE );
  251. }
  252. }
  253. #ifdef CASHMERE
  254. /* C L O S E W W */
  255. CloseWw(ww)
  256. int ww;
  257. { /* Close a window */
  258. struct WWD *pwwd, *pwwdT;
  259. int wwCurNew = wwCur;
  260. int wwT;
  261. int cdl;
  262. /* note ww and wwCur are not necessarily the same because of the scrap */
  263. if (wwCur > 0)
  264. blt(&selCur, &(rgwwd[wwCur].sel), cwSEL);
  265. pwwd = &rgwwd[ww];
  266. --wwMac;
  267. if (!pwwd->fLower && !pwwd->fSplit)
  268. {
  269. KillDoc(pwwd->doc);
  270. if (wwCurNew >= wwMac)
  271. wwCurNew = wwMac - 1;
  272. }
  273. else
  274. { /* split or lower */
  275. wwCurNew = pwwd->ww;
  276. }
  277. /* Free up the space that was used by this window */
  278. FreeH(pwwd->hdndl);
  279. /* Deallocate part of the emergency space reserved for save operations
  280. since we now have one less window and thus one less potential
  281. save to do. */
  282. FChngSizeH(vhrgbSave, max((cwSaveAlloc+(wwMac-1)*cwHeapMinPerWindow),
  283. cwSaveAlloc), true);
  284. /* Close up the gap in wwd's */
  285. if (ww != wwMac && wwMac > 0)
  286. blt(pwwd + 1, pwwd, cwWWD * (wwMac - ww));
  287. else
  288. rgwwd[wwMac].wwptr = 0l;
  289. if (wwCurNew > ww)
  290. --wwCurNew;
  291. /* Update links to windows above the closure */
  292. for (pwwd = &rgwwd[0], wwT = 0; wwT < wwMac; pwwd++, wwT++)
  293. {
  294. if ((pwwd->fSplit || pwwd->fLower) && pwwd->ww > ww)
  295. pwwd->ww--;
  296. }
  297. /* Don't make the Clipboard window into the current window */
  298. if (wwCurNew >= 0)
  299. {
  300. if (rgwwd[wwCurNew].doc == docScrap)
  301. {
  302. if (wwCurNew > 0) /* Try the one before this */
  303. wwCurNew--;
  304. else if (wwMac > 1) /* 0 is scrap, try higher one */
  305. wwCurNew++;
  306. else
  307. goto NoWw;
  308. }
  309. NewCurWw(wwCurNew, true);
  310. }
  311. else
  312. {
  313. NoWw: wwCur = -1;
  314. }
  315. /* Really stomp this! */
  316. ClobberDoc(docUndo, docNil, cp0, cp0);
  317. NoUndo();
  318. }
  319. #endif /* CASHMERE */
  320.